Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [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 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | /* Local includes */ |
| 28 | #include "i40e.h" |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 29 | #include "i40e_diag.h" |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_I40E_VXLAN |
| 31 | #include <net/vxlan.h> |
| 32 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 33 | |
| 34 | const char i40e_driver_name[] = "i40e"; |
| 35 | static const char i40e_driver_string[] = |
| 36 | "Intel(R) Ethernet Connection XL710 Network Driver"; |
| 37 | |
| 38 | #define DRV_KERN "-k" |
| 39 | |
| 40 | #define DRV_VERSION_MAJOR 0 |
| 41 | #define DRV_VERSION_MINOR 3 |
Catherine Sullivan | ded7b9a | 2014-04-01 07:11:57 +0000 | [diff] [blame] | 42 | #define DRV_VERSION_BUILD 46 |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 43 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ |
| 44 | __stringify(DRV_VERSION_MINOR) "." \ |
| 45 | __stringify(DRV_VERSION_BUILD) DRV_KERN |
| 46 | const char i40e_driver_version_str[] = DRV_VERSION; |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 47 | static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation."; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 48 | |
| 49 | /* a bit of forward declarations */ |
| 50 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); |
| 51 | static void i40e_handle_reset_warning(struct i40e_pf *pf); |
| 52 | static int i40e_add_vsi(struct i40e_vsi *vsi); |
| 53 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi); |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 54 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 55 | static int i40e_setup_misc_vector(struct i40e_pf *pf); |
| 56 | static void i40e_determine_queue_usage(struct i40e_pf *pf); |
| 57 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 58 | static void i40e_fdir_sb_setup(struct i40e_pf *pf); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 59 | static int i40e_veb_get_bw_info(struct i40e_veb *veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 60 | |
| 61 | /* i40e_pci_tbl - PCI Device ID Table |
| 62 | * |
| 63 | * Last entry must be all 0s |
| 64 | * |
| 65 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 66 | * Class, Class Mask, private data (not used) } |
| 67 | */ |
| 68 | static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = { |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 69 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0}, |
| 70 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X710), 0}, |
| 71 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0}, |
| 72 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0}, |
| 73 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0}, |
| 74 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0}, |
| 75 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_D), 0}, |
| 76 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0}, |
| 77 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0}, |
| 78 | {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0}, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 79 | /* required last entry */ |
| 80 | {0, } |
| 81 | }; |
| 82 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); |
| 83 | |
| 84 | #define I40E_MAX_VF_COUNT 128 |
| 85 | static int debug = -1; |
| 86 | module_param(debug, int, 0); |
| 87 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 88 | |
| 89 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 90 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); |
| 91 | MODULE_LICENSE("GPL"); |
| 92 | MODULE_VERSION(DRV_VERSION); |
| 93 | |
| 94 | /** |
| 95 | * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code |
| 96 | * @hw: pointer to the HW structure |
| 97 | * @mem: ptr to mem struct to fill out |
| 98 | * @size: size of memory requested |
| 99 | * @alignment: what to align the allocation to |
| 100 | **/ |
| 101 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, |
| 102 | u64 size, u32 alignment) |
| 103 | { |
| 104 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 105 | |
| 106 | mem->size = ALIGN(size, alignment); |
| 107 | mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, |
| 108 | &mem->pa, GFP_KERNEL); |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 109 | if (!mem->va) |
| 110 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 111 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 112 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * i40e_free_dma_mem_d - OS specific memory free for shared code |
| 117 | * @hw: pointer to the HW structure |
| 118 | * @mem: ptr to mem struct to free |
| 119 | **/ |
| 120 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) |
| 121 | { |
| 122 | struct i40e_pf *pf = (struct i40e_pf *)hw->back; |
| 123 | |
| 124 | dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); |
| 125 | mem->va = NULL; |
| 126 | mem->pa = 0; |
| 127 | mem->size = 0; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code |
| 134 | * @hw: pointer to the HW structure |
| 135 | * @mem: ptr to mem struct to fill out |
| 136 | * @size: size of memory requested |
| 137 | **/ |
| 138 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, |
| 139 | u32 size) |
| 140 | { |
| 141 | mem->size = size; |
| 142 | mem->va = kzalloc(size, GFP_KERNEL); |
| 143 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 144 | if (!mem->va) |
| 145 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 146 | |
Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 147 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * i40e_free_virt_mem_d - OS specific memory free for shared code |
| 152 | * @hw: pointer to the HW structure |
| 153 | * @mem: ptr to mem struct to free |
| 154 | **/ |
| 155 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) |
| 156 | { |
| 157 | /* it's ok to kfree a NULL pointer */ |
| 158 | kfree(mem->va); |
| 159 | mem->va = NULL; |
| 160 | mem->size = 0; |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * i40e_get_lump - find a lump of free generic resource |
| 167 | * @pf: board private structure |
| 168 | * @pile: the pile of resource to search |
| 169 | * @needed: the number of items needed |
| 170 | * @id: an owner id to stick on the items assigned |
| 171 | * |
| 172 | * Returns the base item index of the lump, or negative for error |
| 173 | * |
| 174 | * The search_hint trick and lack of advanced fit-finding only work |
| 175 | * because we're highly likely to have all the same size lump requests. |
| 176 | * Linear search time and any fragmentation should be minimal. |
| 177 | **/ |
| 178 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, |
| 179 | u16 needed, u16 id) |
| 180 | { |
| 181 | int ret = -ENOMEM; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 182 | int i, j; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 183 | |
| 184 | if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { |
| 185 | dev_info(&pf->pdev->dev, |
| 186 | "param err: pile=%p needed=%d id=0x%04x\n", |
| 187 | pile, needed, id); |
| 188 | return -EINVAL; |
| 189 | } |
| 190 | |
| 191 | /* start the linear search with an imperfect hint */ |
| 192 | i = pile->search_hint; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 193 | while (i < pile->num_entries) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 194 | /* skip already allocated entries */ |
| 195 | if (pile->list[i] & I40E_PILE_VALID_BIT) { |
| 196 | i++; |
| 197 | continue; |
| 198 | } |
| 199 | |
| 200 | /* do we have enough in this lump? */ |
| 201 | for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { |
| 202 | if (pile->list[i+j] & I40E_PILE_VALID_BIT) |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | if (j == needed) { |
| 207 | /* there was enough, so assign it to the requestor */ |
| 208 | for (j = 0; j < needed; j++) |
| 209 | pile->list[i+j] = id | I40E_PILE_VALID_BIT; |
| 210 | ret = i; |
| 211 | pile->search_hint = i + j; |
Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 212 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 213 | } else { |
| 214 | /* not enough, so skip over it and continue looking */ |
| 215 | i += j; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * i40e_put_lump - return a lump of generic resource |
| 224 | * @pile: the pile of resource to search |
| 225 | * @index: the base item index |
| 226 | * @id: the owner id of the items assigned |
| 227 | * |
| 228 | * Returns the count of items in the lump |
| 229 | **/ |
| 230 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) |
| 231 | { |
| 232 | int valid_id = (id | I40E_PILE_VALID_BIT); |
| 233 | int count = 0; |
| 234 | int i; |
| 235 | |
| 236 | if (!pile || index >= pile->num_entries) |
| 237 | return -EINVAL; |
| 238 | |
| 239 | for (i = index; |
| 240 | i < pile->num_entries && pile->list[i] == valid_id; |
| 241 | i++) { |
| 242 | pile->list[i] = 0; |
| 243 | count++; |
| 244 | } |
| 245 | |
| 246 | if (count && index < pile->search_hint) |
| 247 | pile->search_hint = index; |
| 248 | |
| 249 | return count; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * i40e_service_event_schedule - Schedule the service task to wake up |
| 254 | * @pf: board private structure |
| 255 | * |
| 256 | * If not already scheduled, this puts the task into the work queue |
| 257 | **/ |
| 258 | static void i40e_service_event_schedule(struct i40e_pf *pf) |
| 259 | { |
| 260 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 261 | !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && |
| 262 | !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) |
| 263 | schedule_work(&pf->service_task); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * i40e_tx_timeout - Respond to a Tx Hang |
| 268 | * @netdev: network interface device structure |
| 269 | * |
| 270 | * If any port has noticed a Tx timeout, it is likely that the whole |
| 271 | * device is munged, not just the one netdev port, so go for the full |
| 272 | * reset. |
| 273 | **/ |
| 274 | static void i40e_tx_timeout(struct net_device *netdev) |
| 275 | { |
| 276 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 277 | struct i40e_vsi *vsi = np->vsi; |
| 278 | struct i40e_pf *pf = vsi->back; |
| 279 | |
| 280 | pf->tx_timeout_count++; |
| 281 | |
| 282 | if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) |
| 283 | pf->tx_timeout_recovery_level = 0; |
| 284 | pf->tx_timeout_last_recovery = jiffies; |
| 285 | netdev_info(netdev, "tx_timeout recovery level %d\n", |
| 286 | pf->tx_timeout_recovery_level); |
| 287 | |
| 288 | switch (pf->tx_timeout_recovery_level) { |
| 289 | case 0: |
| 290 | /* disable and re-enable queues for the VSI */ |
| 291 | if (in_interrupt()) { |
| 292 | set_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 293 | set_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 294 | } else { |
| 295 | i40e_vsi_reinit_locked(vsi); |
| 296 | } |
| 297 | break; |
| 298 | case 1: |
| 299 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 300 | break; |
| 301 | case 2: |
| 302 | set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 303 | break; |
| 304 | case 3: |
| 305 | set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 306 | break; |
| 307 | default: |
| 308 | netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); |
Akeem G Abodunrin | e108b0e | 2014-02-13 03:48:43 -0800 | [diff] [blame] | 309 | set_bit(__I40E_DOWN, &vsi->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 310 | i40e_down(vsi); |
| 311 | break; |
| 312 | } |
| 313 | i40e_service_event_schedule(pf); |
| 314 | pf->tx_timeout_recovery_level++; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * i40e_release_rx_desc - Store the new tail and head values |
| 319 | * @rx_ring: ring to bump |
| 320 | * @val: new head index |
| 321 | **/ |
| 322 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) |
| 323 | { |
| 324 | rx_ring->next_to_use = val; |
| 325 | |
| 326 | /* Force memory writes to complete before letting h/w |
| 327 | * know there are new descriptors to fetch. (Only |
| 328 | * applicable for weak-ordered memory model archs, |
| 329 | * such as IA-64). |
| 330 | */ |
| 331 | wmb(); |
| 332 | writel(val, rx_ring->tail); |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * i40e_get_vsi_stats_struct - Get System Network Statistics |
| 337 | * @vsi: the VSI we care about |
| 338 | * |
| 339 | * Returns the address of the device statistics structure. |
| 340 | * The statistics are actually updated from the service task. |
| 341 | **/ |
| 342 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) |
| 343 | { |
| 344 | return &vsi->net_stats; |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * i40e_get_netdev_stats_struct - Get statistics for netdev interface |
| 349 | * @netdev: network interface device structure |
| 350 | * |
| 351 | * Returns the address of the device statistics structure. |
| 352 | * The statistics are actually updated from the service task. |
| 353 | **/ |
| 354 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( |
| 355 | struct net_device *netdev, |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 356 | struct rtnl_link_stats64 *stats) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 357 | { |
| 358 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 359 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 360 | struct i40e_vsi *vsi = np->vsi; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 361 | struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); |
| 362 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 363 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 364 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 365 | return stats; |
| 366 | |
Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 367 | if (!vsi->tx_rings) |
| 368 | return stats; |
| 369 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 370 | rcu_read_lock(); |
| 371 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 372 | u64 bytes, packets; |
| 373 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 374 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 375 | tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); |
| 376 | if (!tx_ring) |
| 377 | continue; |
| 378 | |
| 379 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 380 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 381 | packets = tx_ring->stats.packets; |
| 382 | bytes = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 383 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 384 | |
| 385 | stats->tx_packets += packets; |
| 386 | stats->tx_bytes += bytes; |
| 387 | rx_ring = &tx_ring[1]; |
| 388 | |
| 389 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 390 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 391 | packets = rx_ring->stats.packets; |
| 392 | bytes = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 393 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 394 | |
| 395 | stats->rx_packets += packets; |
| 396 | stats->rx_bytes += bytes; |
| 397 | } |
| 398 | rcu_read_unlock(); |
| 399 | |
| 400 | /* following stats updated by ixgbe_watchdog_task() */ |
| 401 | stats->multicast = vsi_stats->multicast; |
| 402 | stats->tx_errors = vsi_stats->tx_errors; |
| 403 | stats->tx_dropped = vsi_stats->tx_dropped; |
| 404 | stats->rx_errors = vsi_stats->rx_errors; |
| 405 | stats->rx_crc_errors = vsi_stats->rx_crc_errors; |
| 406 | stats->rx_length_errors = vsi_stats->rx_length_errors; |
| 407 | |
| 408 | return stats; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /** |
| 412 | * i40e_vsi_reset_stats - Resets all stats of the given vsi |
| 413 | * @vsi: the VSI to have its stats reset |
| 414 | **/ |
| 415 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) |
| 416 | { |
| 417 | struct rtnl_link_stats64 *ns; |
| 418 | int i; |
| 419 | |
| 420 | if (!vsi) |
| 421 | return; |
| 422 | |
| 423 | ns = i40e_get_vsi_stats_struct(vsi); |
| 424 | memset(ns, 0, sizeof(*ns)); |
| 425 | memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); |
| 426 | memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); |
| 427 | memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 428 | if (vsi->rx_rings && vsi->rx_rings[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 429 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 430 | memset(&vsi->rx_rings[i]->stats, 0 , |
| 431 | sizeof(vsi->rx_rings[i]->stats)); |
| 432 | memset(&vsi->rx_rings[i]->rx_stats, 0 , |
| 433 | sizeof(vsi->rx_rings[i]->rx_stats)); |
| 434 | memset(&vsi->tx_rings[i]->stats, 0 , |
| 435 | sizeof(vsi->tx_rings[i]->stats)); |
| 436 | memset(&vsi->tx_rings[i]->tx_stats, 0, |
| 437 | sizeof(vsi->tx_rings[i]->tx_stats)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 438 | } |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 439 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 440 | vsi->stat_offsets_loaded = false; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * i40e_pf_reset_stats - Reset all of the stats for the given pf |
| 445 | * @pf: the PF to be reset |
| 446 | **/ |
| 447 | void i40e_pf_reset_stats(struct i40e_pf *pf) |
| 448 | { |
| 449 | memset(&pf->stats, 0, sizeof(pf->stats)); |
| 450 | memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); |
| 451 | pf->stat_offsets_loaded = false; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * i40e_stat_update48 - read and update a 48 bit stat from the chip |
| 456 | * @hw: ptr to the hardware info |
| 457 | * @hireg: the high 32 bit reg to read |
| 458 | * @loreg: the low 32 bit reg to read |
| 459 | * @offset_loaded: has the initial offset been loaded yet |
| 460 | * @offset: ptr to current offset value |
| 461 | * @stat: ptr to the stat |
| 462 | * |
| 463 | * Since the device stats are not reset at PFReset, they likely will not |
| 464 | * be zeroed when the driver starts. We'll save the first values read |
| 465 | * and use them as offsets to be subtracted from the raw values in order |
| 466 | * to report stats that count from zero. In the process, we also manage |
| 467 | * the potential roll-over. |
| 468 | **/ |
| 469 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, |
| 470 | bool offset_loaded, u64 *offset, u64 *stat) |
| 471 | { |
| 472 | u64 new_data; |
| 473 | |
Shannon Nelson | ab60085 | 2014-01-17 15:36:39 -0800 | [diff] [blame] | 474 | if (hw->device_id == I40E_DEV_ID_QEMU) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 475 | new_data = rd32(hw, loreg); |
| 476 | new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; |
| 477 | } else { |
| 478 | new_data = rd64(hw, loreg); |
| 479 | } |
| 480 | if (!offset_loaded) |
| 481 | *offset = new_data; |
| 482 | if (likely(new_data >= *offset)) |
| 483 | *stat = new_data - *offset; |
| 484 | else |
| 485 | *stat = (new_data + ((u64)1 << 48)) - *offset; |
| 486 | *stat &= 0xFFFFFFFFFFFFULL; |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * i40e_stat_update32 - read and update a 32 bit stat from the chip |
| 491 | * @hw: ptr to the hardware info |
| 492 | * @reg: the hw reg to read |
| 493 | * @offset_loaded: has the initial offset been loaded yet |
| 494 | * @offset: ptr to current offset value |
| 495 | * @stat: ptr to the stat |
| 496 | **/ |
| 497 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, |
| 498 | bool offset_loaded, u64 *offset, u64 *stat) |
| 499 | { |
| 500 | u32 new_data; |
| 501 | |
| 502 | new_data = rd32(hw, reg); |
| 503 | if (!offset_loaded) |
| 504 | *offset = new_data; |
| 505 | if (likely(new_data >= *offset)) |
| 506 | *stat = (u32)(new_data - *offset); |
| 507 | else |
| 508 | *stat = (u32)((new_data + ((u64)1 << 32)) - *offset); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. |
| 513 | * @vsi: the VSI to be updated |
| 514 | **/ |
| 515 | void i40e_update_eth_stats(struct i40e_vsi *vsi) |
| 516 | { |
| 517 | int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); |
| 518 | struct i40e_pf *pf = vsi->back; |
| 519 | struct i40e_hw *hw = &pf->hw; |
| 520 | struct i40e_eth_stats *oes; |
| 521 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 522 | |
| 523 | es = &vsi->eth_stats; |
| 524 | oes = &vsi->eth_stats_offsets; |
| 525 | |
| 526 | /* Gather up the stats that the hw collects */ |
| 527 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 528 | vsi->stat_offsets_loaded, |
| 529 | &oes->tx_errors, &es->tx_errors); |
| 530 | i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), |
| 531 | vsi->stat_offsets_loaded, |
| 532 | &oes->rx_discards, &es->rx_discards); |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 533 | i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx), |
| 534 | vsi->stat_offsets_loaded, |
| 535 | &oes->rx_unknown_protocol, &es->rx_unknown_protocol); |
| 536 | i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), |
| 537 | vsi->stat_offsets_loaded, |
| 538 | &oes->tx_errors, &es->tx_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 539 | |
| 540 | i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), |
| 541 | I40E_GLV_GORCL(stat_idx), |
| 542 | vsi->stat_offsets_loaded, |
| 543 | &oes->rx_bytes, &es->rx_bytes); |
| 544 | i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), |
| 545 | I40E_GLV_UPRCL(stat_idx), |
| 546 | vsi->stat_offsets_loaded, |
| 547 | &oes->rx_unicast, &es->rx_unicast); |
| 548 | i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), |
| 549 | I40E_GLV_MPRCL(stat_idx), |
| 550 | vsi->stat_offsets_loaded, |
| 551 | &oes->rx_multicast, &es->rx_multicast); |
| 552 | i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), |
| 553 | I40E_GLV_BPRCL(stat_idx), |
| 554 | vsi->stat_offsets_loaded, |
| 555 | &oes->rx_broadcast, &es->rx_broadcast); |
| 556 | |
| 557 | i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), |
| 558 | I40E_GLV_GOTCL(stat_idx), |
| 559 | vsi->stat_offsets_loaded, |
| 560 | &oes->tx_bytes, &es->tx_bytes); |
| 561 | i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), |
| 562 | I40E_GLV_UPTCL(stat_idx), |
| 563 | vsi->stat_offsets_loaded, |
| 564 | &oes->tx_unicast, &es->tx_unicast); |
| 565 | i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), |
| 566 | I40E_GLV_MPTCL(stat_idx), |
| 567 | vsi->stat_offsets_loaded, |
| 568 | &oes->tx_multicast, &es->tx_multicast); |
| 569 | i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), |
| 570 | I40E_GLV_BPTCL(stat_idx), |
| 571 | vsi->stat_offsets_loaded, |
| 572 | &oes->tx_broadcast, &es->tx_broadcast); |
| 573 | vsi->stat_offsets_loaded = true; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * i40e_update_veb_stats - Update Switch component statistics |
| 578 | * @veb: the VEB being updated |
| 579 | **/ |
| 580 | static void i40e_update_veb_stats(struct i40e_veb *veb) |
| 581 | { |
| 582 | struct i40e_pf *pf = veb->pf; |
| 583 | struct i40e_hw *hw = &pf->hw; |
| 584 | struct i40e_eth_stats *oes; |
| 585 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 586 | int idx = 0; |
| 587 | |
| 588 | idx = veb->stats_idx; |
| 589 | es = &veb->stats; |
| 590 | oes = &veb->stats_offsets; |
| 591 | |
| 592 | /* Gather up the stats that the hw collects */ |
| 593 | i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), |
| 594 | veb->stat_offsets_loaded, |
| 595 | &oes->tx_discards, &es->tx_discards); |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 596 | if (hw->revision_id > 0) |
| 597 | i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), |
| 598 | veb->stat_offsets_loaded, |
| 599 | &oes->rx_unknown_protocol, |
| 600 | &es->rx_unknown_protocol); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 601 | i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), |
| 602 | veb->stat_offsets_loaded, |
| 603 | &oes->rx_bytes, &es->rx_bytes); |
| 604 | i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), |
| 605 | veb->stat_offsets_loaded, |
| 606 | &oes->rx_unicast, &es->rx_unicast); |
| 607 | i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), |
| 608 | veb->stat_offsets_loaded, |
| 609 | &oes->rx_multicast, &es->rx_multicast); |
| 610 | i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), |
| 611 | veb->stat_offsets_loaded, |
| 612 | &oes->rx_broadcast, &es->rx_broadcast); |
| 613 | |
| 614 | i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), |
| 615 | veb->stat_offsets_loaded, |
| 616 | &oes->tx_bytes, &es->tx_bytes); |
| 617 | i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), |
| 618 | veb->stat_offsets_loaded, |
| 619 | &oes->tx_unicast, &es->tx_unicast); |
| 620 | i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), |
| 621 | veb->stat_offsets_loaded, |
| 622 | &oes->tx_multicast, &es->tx_multicast); |
| 623 | i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), |
| 624 | veb->stat_offsets_loaded, |
| 625 | &oes->tx_broadcast, &es->tx_broadcast); |
| 626 | veb->stat_offsets_loaded = true; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode |
| 631 | * @pf: the corresponding PF |
| 632 | * |
| 633 | * Update the Rx XOFF counter (PAUSE frames) in link flow control mode |
| 634 | **/ |
| 635 | static void i40e_update_link_xoff_rx(struct i40e_pf *pf) |
| 636 | { |
| 637 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 638 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 639 | struct i40e_hw *hw = &pf->hw; |
| 640 | u64 xoff = 0; |
| 641 | u16 i, v; |
| 642 | |
| 643 | if ((hw->fc.current_mode != I40E_FC_FULL) && |
| 644 | (hw->fc.current_mode != I40E_FC_RX_PAUSE)) |
| 645 | return; |
| 646 | |
| 647 | xoff = nsd->link_xoff_rx; |
| 648 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), |
| 649 | pf->stat_offsets_loaded, |
| 650 | &osd->link_xoff_rx, &nsd->link_xoff_rx); |
| 651 | |
| 652 | /* No new LFC xoff rx */ |
| 653 | if (!(nsd->link_xoff_rx - xoff)) |
| 654 | return; |
| 655 | |
| 656 | /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */ |
| 657 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 658 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 659 | |
| 660 | if (!vsi) |
| 661 | continue; |
| 662 | |
| 663 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 664 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 665 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode |
| 672 | * @pf: the corresponding PF |
| 673 | * |
| 674 | * Update the Rx XOFF counter (PAUSE frames) in PFC mode |
| 675 | **/ |
| 676 | static void i40e_update_prio_xoff_rx(struct i40e_pf *pf) |
| 677 | { |
| 678 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 679 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 680 | bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false}; |
| 681 | struct i40e_dcbx_config *dcb_cfg; |
| 682 | struct i40e_hw *hw = &pf->hw; |
| 683 | u16 i, v; |
| 684 | u8 tc; |
| 685 | |
| 686 | dcb_cfg = &hw->local_dcbx_config; |
| 687 | |
| 688 | /* See if DCB enabled with PFC TC */ |
| 689 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED) || |
| 690 | !(dcb_cfg->pfc.pfcenable)) { |
| 691 | i40e_update_link_xoff_rx(pf); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 696 | u64 prio_xoff = nsd->priority_xoff_rx[i]; |
| 697 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), |
| 698 | pf->stat_offsets_loaded, |
| 699 | &osd->priority_xoff_rx[i], |
| 700 | &nsd->priority_xoff_rx[i]); |
| 701 | |
| 702 | /* No new PFC xoff rx */ |
| 703 | if (!(nsd->priority_xoff_rx[i] - prio_xoff)) |
| 704 | continue; |
| 705 | /* Get the TC for given priority */ |
| 706 | tc = dcb_cfg->etscfg.prioritytable[i]; |
| 707 | xoff[tc] = true; |
| 708 | } |
| 709 | |
| 710 | /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */ |
| 711 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 712 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 713 | |
| 714 | if (!vsi) |
| 715 | continue; |
| 716 | |
| 717 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 718 | struct i40e_ring *ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 719 | |
| 720 | tc = ring->dcb_tc; |
| 721 | if (xoff[tc]) |
| 722 | clear_bit(__I40E_HANG_CHECK_ARMED, |
| 723 | &ring->state); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 729 | * i40e_update_vsi_stats - Update the vsi statistics counters. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 730 | * @vsi: the VSI to be updated |
| 731 | * |
| 732 | * There are a few instances where we store the same stat in a |
| 733 | * couple of different structs. This is partly because we have |
| 734 | * the netdev stats that need to be filled out, which is slightly |
| 735 | * different from the "eth_stats" defined by the chip and used in |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 736 | * VF communications. We sort it out here. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 737 | **/ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 738 | static void i40e_update_vsi_stats(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 739 | { |
| 740 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 741 | struct rtnl_link_stats64 *ons; |
| 742 | struct rtnl_link_stats64 *ns; /* netdev stats */ |
| 743 | struct i40e_eth_stats *oes; |
| 744 | struct i40e_eth_stats *es; /* device's eth stats */ |
| 745 | u32 tx_restart, tx_busy; |
| 746 | u32 rx_page, rx_buf; |
| 747 | u64 rx_p, rx_b; |
| 748 | u64 tx_p, tx_b; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 749 | u16 q; |
| 750 | |
| 751 | if (test_bit(__I40E_DOWN, &vsi->state) || |
| 752 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 753 | return; |
| 754 | |
| 755 | ns = i40e_get_vsi_stats_struct(vsi); |
| 756 | ons = &vsi->net_stats_offsets; |
| 757 | es = &vsi->eth_stats; |
| 758 | oes = &vsi->eth_stats_offsets; |
| 759 | |
| 760 | /* Gather up the netdev and vsi stats that the driver collects |
| 761 | * on the fly during packet processing |
| 762 | */ |
| 763 | rx_b = rx_p = 0; |
| 764 | tx_b = tx_p = 0; |
| 765 | tx_restart = tx_busy = 0; |
| 766 | rx_page = 0; |
| 767 | rx_buf = 0; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 768 | rcu_read_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 769 | for (q = 0; q < vsi->num_queue_pairs; q++) { |
| 770 | struct i40e_ring *p; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 771 | u64 bytes, packets; |
| 772 | unsigned int start; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 773 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 774 | /* locate Tx ring */ |
| 775 | p = ACCESS_ONCE(vsi->tx_rings[q]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 776 | |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 777 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 778 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 779 | packets = p->stats.packets; |
| 780 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 781 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 782 | tx_b += bytes; |
| 783 | tx_p += packets; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 784 | tx_restart += p->tx_stats.restart_queue; |
| 785 | tx_busy += p->tx_stats.tx_busy; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 786 | |
| 787 | /* Rx queue is part of the same block as Tx queue */ |
| 788 | p = &p[1]; |
| 789 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 790 | start = u64_stats_fetch_begin_irq(&p->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 791 | packets = p->stats.packets; |
| 792 | bytes = p->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 793 | } while (u64_stats_fetch_retry_irq(&p->syncp, start)); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 794 | rx_b += bytes; |
| 795 | rx_p += packets; |
Mitch Williams | 420136c | 2013-12-18 13:45:59 +0000 | [diff] [blame] | 796 | rx_buf += p->rx_stats.alloc_buff_failed; |
| 797 | rx_page += p->rx_stats.alloc_page_failed; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 798 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 799 | rcu_read_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 800 | vsi->tx_restart = tx_restart; |
| 801 | vsi->tx_busy = tx_busy; |
| 802 | vsi->rx_page_failed = rx_page; |
| 803 | vsi->rx_buf_failed = rx_buf; |
| 804 | |
| 805 | ns->rx_packets = rx_p; |
| 806 | ns->rx_bytes = rx_b; |
| 807 | ns->tx_packets = tx_p; |
| 808 | ns->tx_bytes = tx_b; |
| 809 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 810 | /* update netdev stats from eth stats */ |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 811 | i40e_update_eth_stats(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 812 | ons->tx_errors = oes->tx_errors; |
| 813 | ns->tx_errors = es->tx_errors; |
| 814 | ons->multicast = oes->rx_multicast; |
| 815 | ns->multicast = es->rx_multicast; |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 816 | ons->rx_dropped = oes->rx_discards; |
| 817 | ns->rx_dropped = es->rx_discards; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 818 | ons->tx_dropped = oes->tx_discards; |
| 819 | ns->tx_dropped = es->tx_discards; |
| 820 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 821 | /* pull in a couple PF stats if this is the main vsi */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 822 | if (vsi == pf->vsi[pf->lan_vsi]) { |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 823 | ns->rx_crc_errors = pf->stats.crc_errors; |
| 824 | ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes; |
| 825 | ns->rx_length_errors = pf->stats.rx_length_errors; |
| 826 | } |
| 827 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 828 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 829 | /** |
| 830 | * i40e_update_pf_stats - Update the pf statistics counters. |
| 831 | * @pf: the PF to be updated |
| 832 | **/ |
| 833 | static void i40e_update_pf_stats(struct i40e_pf *pf) |
| 834 | { |
| 835 | struct i40e_hw_port_stats *osd = &pf->stats_offsets; |
| 836 | struct i40e_hw_port_stats *nsd = &pf->stats; |
| 837 | struct i40e_hw *hw = &pf->hw; |
| 838 | u32 val; |
| 839 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 840 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 841 | i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), |
| 842 | I40E_GLPRT_GORCL(hw->port), |
| 843 | pf->stat_offsets_loaded, |
| 844 | &osd->eth.rx_bytes, &nsd->eth.rx_bytes); |
| 845 | i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), |
| 846 | I40E_GLPRT_GOTCL(hw->port), |
| 847 | pf->stat_offsets_loaded, |
| 848 | &osd->eth.tx_bytes, &nsd->eth.tx_bytes); |
| 849 | i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), |
| 850 | pf->stat_offsets_loaded, |
| 851 | &osd->eth.rx_discards, |
| 852 | &nsd->eth.rx_discards); |
| 853 | i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port), |
| 854 | pf->stat_offsets_loaded, |
| 855 | &osd->eth.tx_discards, |
| 856 | &nsd->eth.tx_discards); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 857 | |
| 858 | i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port), |
| 859 | I40E_GLPRT_UPRCL(hw->port), |
| 860 | pf->stat_offsets_loaded, |
| 861 | &osd->eth.rx_unicast, |
| 862 | &nsd->eth.rx_unicast); |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 863 | i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), |
| 864 | I40E_GLPRT_MPRCL(hw->port), |
| 865 | pf->stat_offsets_loaded, |
| 866 | &osd->eth.rx_multicast, |
| 867 | &nsd->eth.rx_multicast); |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 868 | i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port), |
| 869 | I40E_GLPRT_BPRCL(hw->port), |
| 870 | pf->stat_offsets_loaded, |
| 871 | &osd->eth.rx_broadcast, |
| 872 | &nsd->eth.rx_broadcast); |
| 873 | i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port), |
| 874 | I40E_GLPRT_UPTCL(hw->port), |
| 875 | pf->stat_offsets_loaded, |
| 876 | &osd->eth.tx_unicast, |
| 877 | &nsd->eth.tx_unicast); |
| 878 | i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port), |
| 879 | I40E_GLPRT_MPTCL(hw->port), |
| 880 | pf->stat_offsets_loaded, |
| 881 | &osd->eth.tx_multicast, |
| 882 | &nsd->eth.tx_multicast); |
| 883 | i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port), |
| 884 | I40E_GLPRT_BPTCL(hw->port), |
| 885 | pf->stat_offsets_loaded, |
| 886 | &osd->eth.tx_broadcast, |
| 887 | &nsd->eth.tx_broadcast); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 888 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 889 | i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), |
| 890 | pf->stat_offsets_loaded, |
| 891 | &osd->tx_dropped_link_down, |
| 892 | &nsd->tx_dropped_link_down); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 893 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 894 | i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), |
| 895 | pf->stat_offsets_loaded, |
| 896 | &osd->crc_errors, &nsd->crc_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 897 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 898 | i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), |
| 899 | pf->stat_offsets_loaded, |
| 900 | &osd->illegal_bytes, &nsd->illegal_bytes); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 901 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 902 | i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), |
| 903 | pf->stat_offsets_loaded, |
| 904 | &osd->mac_local_faults, |
| 905 | &nsd->mac_local_faults); |
| 906 | i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), |
| 907 | pf->stat_offsets_loaded, |
| 908 | &osd->mac_remote_faults, |
| 909 | &nsd->mac_remote_faults); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 910 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 911 | i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), |
| 912 | pf->stat_offsets_loaded, |
| 913 | &osd->rx_length_errors, |
| 914 | &nsd->rx_length_errors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 915 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 916 | i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), |
| 917 | pf->stat_offsets_loaded, |
| 918 | &osd->link_xon_rx, &nsd->link_xon_rx); |
| 919 | i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), |
| 920 | pf->stat_offsets_loaded, |
| 921 | &osd->link_xon_tx, &nsd->link_xon_tx); |
| 922 | i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */ |
| 923 | i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), |
| 924 | pf->stat_offsets_loaded, |
| 925 | &osd->link_xoff_tx, &nsd->link_xoff_tx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 926 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 927 | for (i = 0; i < 8; i++) { |
| 928 | i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 929 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 930 | &osd->priority_xon_rx[i], |
| 931 | &nsd->priority_xon_rx[i]); |
| 932 | i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 933 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 934 | &osd->priority_xon_tx[i], |
| 935 | &nsd->priority_xon_tx[i]); |
| 936 | i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 937 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 938 | &osd->priority_xoff_tx[i], |
| 939 | &nsd->priority_xoff_tx[i]); |
| 940 | i40e_stat_update32(hw, |
| 941 | I40E_GLPRT_RXON2OFFCNT(hw->port, i), |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 942 | pf->stat_offsets_loaded, |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 943 | &osd->priority_xon_2_xoff[i], |
| 944 | &nsd->priority_xon_2_xoff[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 947 | i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), |
| 948 | I40E_GLPRT_PRC64L(hw->port), |
| 949 | pf->stat_offsets_loaded, |
| 950 | &osd->rx_size_64, &nsd->rx_size_64); |
| 951 | i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), |
| 952 | I40E_GLPRT_PRC127L(hw->port), |
| 953 | pf->stat_offsets_loaded, |
| 954 | &osd->rx_size_127, &nsd->rx_size_127); |
| 955 | i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), |
| 956 | I40E_GLPRT_PRC255L(hw->port), |
| 957 | pf->stat_offsets_loaded, |
| 958 | &osd->rx_size_255, &nsd->rx_size_255); |
| 959 | i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), |
| 960 | I40E_GLPRT_PRC511L(hw->port), |
| 961 | pf->stat_offsets_loaded, |
| 962 | &osd->rx_size_511, &nsd->rx_size_511); |
| 963 | i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), |
| 964 | I40E_GLPRT_PRC1023L(hw->port), |
| 965 | pf->stat_offsets_loaded, |
| 966 | &osd->rx_size_1023, &nsd->rx_size_1023); |
| 967 | i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), |
| 968 | I40E_GLPRT_PRC1522L(hw->port), |
| 969 | pf->stat_offsets_loaded, |
| 970 | &osd->rx_size_1522, &nsd->rx_size_1522); |
| 971 | i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), |
| 972 | I40E_GLPRT_PRC9522L(hw->port), |
| 973 | pf->stat_offsets_loaded, |
| 974 | &osd->rx_size_big, &nsd->rx_size_big); |
| 975 | |
| 976 | i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), |
| 977 | I40E_GLPRT_PTC64L(hw->port), |
| 978 | pf->stat_offsets_loaded, |
| 979 | &osd->tx_size_64, &nsd->tx_size_64); |
| 980 | i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), |
| 981 | I40E_GLPRT_PTC127L(hw->port), |
| 982 | pf->stat_offsets_loaded, |
| 983 | &osd->tx_size_127, &nsd->tx_size_127); |
| 984 | i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), |
| 985 | I40E_GLPRT_PTC255L(hw->port), |
| 986 | pf->stat_offsets_loaded, |
| 987 | &osd->tx_size_255, &nsd->tx_size_255); |
| 988 | i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), |
| 989 | I40E_GLPRT_PTC511L(hw->port), |
| 990 | pf->stat_offsets_loaded, |
| 991 | &osd->tx_size_511, &nsd->tx_size_511); |
| 992 | i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), |
| 993 | I40E_GLPRT_PTC1023L(hw->port), |
| 994 | pf->stat_offsets_loaded, |
| 995 | &osd->tx_size_1023, &nsd->tx_size_1023); |
| 996 | i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), |
| 997 | I40E_GLPRT_PTC1522L(hw->port), |
| 998 | pf->stat_offsets_loaded, |
| 999 | &osd->tx_size_1522, &nsd->tx_size_1522); |
| 1000 | i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), |
| 1001 | I40E_GLPRT_PTC9522L(hw->port), |
| 1002 | pf->stat_offsets_loaded, |
| 1003 | &osd->tx_size_big, &nsd->tx_size_big); |
| 1004 | |
| 1005 | i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), |
| 1006 | pf->stat_offsets_loaded, |
| 1007 | &osd->rx_undersize, &nsd->rx_undersize); |
| 1008 | i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), |
| 1009 | pf->stat_offsets_loaded, |
| 1010 | &osd->rx_fragments, &nsd->rx_fragments); |
| 1011 | i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), |
| 1012 | pf->stat_offsets_loaded, |
| 1013 | &osd->rx_oversize, &nsd->rx_oversize); |
| 1014 | i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), |
| 1015 | pf->stat_offsets_loaded, |
| 1016 | &osd->rx_jabber, &nsd->rx_jabber); |
| 1017 | |
| 1018 | val = rd32(hw, I40E_PRTPM_EEE_STAT); |
| 1019 | nsd->tx_lpi_status = |
| 1020 | (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >> |
| 1021 | I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT; |
| 1022 | nsd->rx_lpi_status = |
| 1023 | (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >> |
| 1024 | I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT; |
| 1025 | i40e_stat_update32(hw, I40E_PRTPM_TLPIC, |
| 1026 | pf->stat_offsets_loaded, |
| 1027 | &osd->tx_lpi_count, &nsd->tx_lpi_count); |
| 1028 | i40e_stat_update32(hw, I40E_PRTPM_RLPIC, |
| 1029 | pf->stat_offsets_loaded, |
| 1030 | &osd->rx_lpi_count, &nsd->rx_lpi_count); |
| 1031 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1032 | pf->stat_offsets_loaded = true; |
| 1033 | } |
| 1034 | |
| 1035 | /** |
Shannon Nelson | 7812fdd | 2014-04-23 04:50:18 +0000 | [diff] [blame] | 1036 | * i40e_update_stats - Update the various statistics counters. |
| 1037 | * @vsi: the VSI to be updated |
| 1038 | * |
| 1039 | * Update the various stats for this VSI and its related entities. |
| 1040 | **/ |
| 1041 | void i40e_update_stats(struct i40e_vsi *vsi) |
| 1042 | { |
| 1043 | struct i40e_pf *pf = vsi->back; |
| 1044 | |
| 1045 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 1046 | i40e_update_pf_stats(pf); |
| 1047 | |
| 1048 | i40e_update_vsi_stats(vsi); |
| 1049 | } |
| 1050 | |
| 1051 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1052 | * i40e_find_filter - Search VSI filter list for specific mac/vlan filter |
| 1053 | * @vsi: the VSI to be searched |
| 1054 | * @macaddr: the MAC address |
| 1055 | * @vlan: the vlan |
| 1056 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 1057 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1058 | * |
| 1059 | * Returns ptr to the filter object or NULL |
| 1060 | **/ |
| 1061 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, |
| 1062 | u8 *macaddr, s16 vlan, |
| 1063 | bool is_vf, bool is_netdev) |
| 1064 | { |
| 1065 | struct i40e_mac_filter *f; |
| 1066 | |
| 1067 | if (!vsi || !macaddr) |
| 1068 | return NULL; |
| 1069 | |
| 1070 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1071 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1072 | (vlan == f->vlan) && |
| 1073 | (!is_vf || f->is_vf) && |
| 1074 | (!is_netdev || f->is_netdev)) |
| 1075 | return f; |
| 1076 | } |
| 1077 | return NULL; |
| 1078 | } |
| 1079 | |
| 1080 | /** |
| 1081 | * i40e_find_mac - Find a mac addr in the macvlan filters list |
| 1082 | * @vsi: the VSI to be searched |
| 1083 | * @macaddr: the MAC address we are searching for |
| 1084 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 1085 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1086 | * |
| 1087 | * Returns the first filter with the provided MAC address or NULL if |
| 1088 | * MAC address was not found |
| 1089 | **/ |
| 1090 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, |
| 1091 | bool is_vf, bool is_netdev) |
| 1092 | { |
| 1093 | struct i40e_mac_filter *f; |
| 1094 | |
| 1095 | if (!vsi || !macaddr) |
| 1096 | return NULL; |
| 1097 | |
| 1098 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1099 | if ((ether_addr_equal(macaddr, f->macaddr)) && |
| 1100 | (!is_vf || f->is_vf) && |
| 1101 | (!is_netdev || f->is_netdev)) |
| 1102 | return f; |
| 1103 | } |
| 1104 | return NULL; |
| 1105 | } |
| 1106 | |
| 1107 | /** |
| 1108 | * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode |
| 1109 | * @vsi: the VSI to be searched |
| 1110 | * |
| 1111 | * Returns true if VSI is in vlan mode or false otherwise |
| 1112 | **/ |
| 1113 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) |
| 1114 | { |
| 1115 | struct i40e_mac_filter *f; |
| 1116 | |
| 1117 | /* Only -1 for all the filters denotes not in vlan mode |
| 1118 | * so we have to go through all the list in order to make sure |
| 1119 | */ |
| 1120 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1121 | if (f->vlan >= 0) |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
| 1125 | return false; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans |
| 1130 | * @vsi: the VSI to be searched |
| 1131 | * @macaddr: the mac address to be filtered |
| 1132 | * @is_vf: true if it is a vf |
| 1133 | * @is_netdev: true if it is a netdev |
| 1134 | * |
| 1135 | * Goes through all the macvlan filters and adds a |
| 1136 | * macvlan filter for each unique vlan that already exists |
| 1137 | * |
| 1138 | * Returns first filter found on success, else NULL |
| 1139 | **/ |
| 1140 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, |
| 1141 | bool is_vf, bool is_netdev) |
| 1142 | { |
| 1143 | struct i40e_mac_filter *f; |
| 1144 | |
| 1145 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1146 | if (!i40e_find_filter(vsi, macaddr, f->vlan, |
| 1147 | is_vf, is_netdev)) { |
| 1148 | if (!i40e_add_filter(vsi, macaddr, f->vlan, |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1149 | is_vf, is_netdev)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1150 | return NULL; |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | return list_first_entry_or_null(&vsi->mac_filter_list, |
| 1155 | struct i40e_mac_filter, list); |
| 1156 | } |
| 1157 | |
| 1158 | /** |
| 1159 | * i40e_add_filter - Add a mac/vlan filter to the VSI |
| 1160 | * @vsi: the VSI to be searched |
| 1161 | * @macaddr: the MAC address |
| 1162 | * @vlan: the vlan |
| 1163 | * @is_vf: make sure its a vf filter, else doesn't matter |
| 1164 | * @is_netdev: make sure its a netdev filter, else doesn't matter |
| 1165 | * |
| 1166 | * Returns ptr to the filter object or NULL when no memory available. |
| 1167 | **/ |
| 1168 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, |
| 1169 | u8 *macaddr, s16 vlan, |
| 1170 | bool is_vf, bool is_netdev) |
| 1171 | { |
| 1172 | struct i40e_mac_filter *f; |
| 1173 | |
| 1174 | if (!vsi || !macaddr) |
| 1175 | return NULL; |
| 1176 | |
| 1177 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1178 | if (!f) { |
| 1179 | f = kzalloc(sizeof(*f), GFP_ATOMIC); |
| 1180 | if (!f) |
| 1181 | goto add_filter_out; |
| 1182 | |
| 1183 | memcpy(f->macaddr, macaddr, ETH_ALEN); |
| 1184 | f->vlan = vlan; |
| 1185 | f->changed = true; |
| 1186 | |
| 1187 | INIT_LIST_HEAD(&f->list); |
| 1188 | list_add(&f->list, &vsi->mac_filter_list); |
| 1189 | } |
| 1190 | |
| 1191 | /* increment counter and add a new flag if needed */ |
| 1192 | if (is_vf) { |
| 1193 | if (!f->is_vf) { |
| 1194 | f->is_vf = true; |
| 1195 | f->counter++; |
| 1196 | } |
| 1197 | } else if (is_netdev) { |
| 1198 | if (!f->is_netdev) { |
| 1199 | f->is_netdev = true; |
| 1200 | f->counter++; |
| 1201 | } |
| 1202 | } else { |
| 1203 | f->counter++; |
| 1204 | } |
| 1205 | |
| 1206 | /* changed tells sync_filters_subtask to |
| 1207 | * push the filter down to the firmware |
| 1208 | */ |
| 1209 | if (f->changed) { |
| 1210 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1211 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1212 | } |
| 1213 | |
| 1214 | add_filter_out: |
| 1215 | return f; |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * i40e_del_filter - Remove a mac/vlan filter from the VSI |
| 1220 | * @vsi: the VSI to be searched |
| 1221 | * @macaddr: the MAC address |
| 1222 | * @vlan: the vlan |
| 1223 | * @is_vf: make sure it's a vf filter, else doesn't matter |
| 1224 | * @is_netdev: make sure it's a netdev filter, else doesn't matter |
| 1225 | **/ |
| 1226 | void i40e_del_filter(struct i40e_vsi *vsi, |
| 1227 | u8 *macaddr, s16 vlan, |
| 1228 | bool is_vf, bool is_netdev) |
| 1229 | { |
| 1230 | struct i40e_mac_filter *f; |
| 1231 | |
| 1232 | if (!vsi || !macaddr) |
| 1233 | return; |
| 1234 | |
| 1235 | f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); |
| 1236 | if (!f || f->counter == 0) |
| 1237 | return; |
| 1238 | |
| 1239 | if (is_vf) { |
| 1240 | if (f->is_vf) { |
| 1241 | f->is_vf = false; |
| 1242 | f->counter--; |
| 1243 | } |
| 1244 | } else if (is_netdev) { |
| 1245 | if (f->is_netdev) { |
| 1246 | f->is_netdev = false; |
| 1247 | f->counter--; |
| 1248 | } |
| 1249 | } else { |
| 1250 | /* make sure we don't remove a filter in use by vf or netdev */ |
| 1251 | int min_f = 0; |
| 1252 | min_f += (f->is_vf ? 1 : 0); |
| 1253 | min_f += (f->is_netdev ? 1 : 0); |
| 1254 | |
| 1255 | if (f->counter > min_f) |
| 1256 | f->counter--; |
| 1257 | } |
| 1258 | |
| 1259 | /* counter == 0 tells sync_filters_subtask to |
| 1260 | * remove the filter from the firmware's list |
| 1261 | */ |
| 1262 | if (f->counter == 0) { |
| 1263 | f->changed = true; |
| 1264 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1265 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /** |
| 1270 | * i40e_set_mac - NDO callback to set mac address |
| 1271 | * @netdev: network interface device structure |
| 1272 | * @p: pointer to an address structure |
| 1273 | * |
| 1274 | * Returns 0 on success, negative on failure |
| 1275 | **/ |
| 1276 | static int i40e_set_mac(struct net_device *netdev, void *p) |
| 1277 | { |
| 1278 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1279 | struct i40e_vsi *vsi = np->vsi; |
| 1280 | struct sockaddr *addr = p; |
| 1281 | struct i40e_mac_filter *f; |
| 1282 | |
| 1283 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1284 | return -EADDRNOTAVAIL; |
| 1285 | |
| 1286 | netdev_info(netdev, "set mac address=%pM\n", addr->sa_data); |
| 1287 | |
| 1288 | if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) |
| 1289 | return 0; |
| 1290 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1291 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1292 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1293 | return -EADDRNOTAVAIL; |
| 1294 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1295 | if (vsi->type == I40E_VSI_MAIN) { |
| 1296 | i40e_status ret; |
| 1297 | ret = i40e_aq_mac_address_write(&vsi->back->hw, |
| 1298 | I40E_AQC_WRITE_TYPE_LAA_ONLY, |
| 1299 | addr->sa_data, NULL); |
| 1300 | if (ret) { |
| 1301 | netdev_info(netdev, |
| 1302 | "Addr change for Main VSI failed: %d\n", |
| 1303 | ret); |
| 1304 | return -EADDRNOTAVAIL; |
| 1305 | } |
| 1306 | |
| 1307 | memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len); |
| 1308 | } |
| 1309 | |
| 1310 | /* In order to be sure to not drop any packets, add the new address |
| 1311 | * then delete the old one. |
| 1312 | */ |
| 1313 | f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false); |
| 1314 | if (!f) |
| 1315 | return -ENOMEM; |
| 1316 | |
| 1317 | i40e_sync_vsi_filters(vsi); |
| 1318 | i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false); |
| 1319 | i40e_sync_vsi_filters(vsi); |
| 1320 | |
| 1321 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc |
| 1328 | * @vsi: the VSI being setup |
| 1329 | * @ctxt: VSI context structure |
| 1330 | * @enabled_tc: Enabled TCs bitmap |
| 1331 | * @is_add: True if called before Add VSI |
| 1332 | * |
| 1333 | * Setup VSI queue mapping for enabled traffic classes. |
| 1334 | **/ |
| 1335 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, |
| 1336 | struct i40e_vsi_context *ctxt, |
| 1337 | u8 enabled_tc, |
| 1338 | bool is_add) |
| 1339 | { |
| 1340 | struct i40e_pf *pf = vsi->back; |
| 1341 | u16 sections = 0; |
| 1342 | u8 netdev_tc = 0; |
| 1343 | u16 numtc = 0; |
| 1344 | u16 qcount; |
| 1345 | u8 offset; |
| 1346 | u16 qmap; |
| 1347 | int i; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1348 | u16 num_tc_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1349 | |
| 1350 | sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; |
| 1351 | offset = 0; |
| 1352 | |
| 1353 | if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { |
| 1354 | /* Find numtc from enabled TC bitmap */ |
| 1355 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1356 | if (enabled_tc & (1 << i)) /* TC is enabled */ |
| 1357 | numtc++; |
| 1358 | } |
| 1359 | if (!numtc) { |
| 1360 | dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); |
| 1361 | numtc = 1; |
| 1362 | } |
| 1363 | } else { |
| 1364 | /* At least TC0 is enabled in case of non-DCB case */ |
| 1365 | numtc = 1; |
| 1366 | } |
| 1367 | |
| 1368 | vsi->tc_config.numtc = numtc; |
| 1369 | vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1370 | /* Number of queues per enabled TC */ |
| 1371 | num_tc_qps = rounddown_pow_of_two(vsi->alloc_queue_pairs/numtc); |
| 1372 | num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1373 | |
| 1374 | /* Setup queue offset/count for all TCs for given VSI */ |
| 1375 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1376 | /* See if the given TC is enabled for the given VSI */ |
| 1377 | if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */ |
| 1378 | int pow, num_qps; |
| 1379 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1380 | switch (vsi->type) { |
| 1381 | case I40E_VSI_MAIN: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1382 | qcount = min_t(int, pf->rss_size, num_tc_qps); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1383 | break; |
| 1384 | case I40E_VSI_FDIR: |
| 1385 | case I40E_VSI_SRIOV: |
| 1386 | case I40E_VSI_VMDQ2: |
| 1387 | default: |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1388 | qcount = num_tc_qps; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1389 | WARN_ON(i != 0); |
| 1390 | break; |
| 1391 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1392 | vsi->tc_config.tc_info[i].qoffset = offset; |
| 1393 | vsi->tc_config.tc_info[i].qcount = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1394 | |
| 1395 | /* find the power-of-2 of the number of queue pairs */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1396 | num_qps = qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1397 | pow = 0; |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1398 | while (num_qps && ((1 << pow) < qcount)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1399 | pow++; |
| 1400 | num_qps >>= 1; |
| 1401 | } |
| 1402 | |
| 1403 | vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; |
| 1404 | qmap = |
| 1405 | (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | |
| 1406 | (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); |
| 1407 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 1408 | offset += qcount; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1409 | } else { |
| 1410 | /* TC is not enabled so set the offset to |
| 1411 | * default queue and allocate one queue |
| 1412 | * for the given TC. |
| 1413 | */ |
| 1414 | vsi->tc_config.tc_info[i].qoffset = 0; |
| 1415 | vsi->tc_config.tc_info[i].qcount = 1; |
| 1416 | vsi->tc_config.tc_info[i].netdev_tc = 0; |
| 1417 | |
| 1418 | qmap = 0; |
| 1419 | } |
| 1420 | ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); |
| 1421 | } |
| 1422 | |
| 1423 | /* Set actual Tx/Rx queue pairs */ |
| 1424 | vsi->num_queue_pairs = offset; |
| 1425 | |
| 1426 | /* Scheduler section valid can only be set for ADD VSI */ |
| 1427 | if (is_add) { |
| 1428 | sections |= I40E_AQ_VSI_PROP_SCHED_VALID; |
| 1429 | |
| 1430 | ctxt->info.up_enable_bits = enabled_tc; |
| 1431 | } |
| 1432 | if (vsi->type == I40E_VSI_SRIOV) { |
| 1433 | ctxt->info.mapping_flags |= |
| 1434 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); |
| 1435 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1436 | ctxt->info.queue_mapping[i] = |
| 1437 | cpu_to_le16(vsi->base_queue + i); |
| 1438 | } else { |
| 1439 | ctxt->info.mapping_flags |= |
| 1440 | cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); |
| 1441 | ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); |
| 1442 | } |
| 1443 | ctxt->info.valid_sections |= cpu_to_le16(sections); |
| 1444 | } |
| 1445 | |
| 1446 | /** |
| 1447 | * i40e_set_rx_mode - NDO callback to set the netdev filters |
| 1448 | * @netdev: network interface device structure |
| 1449 | **/ |
| 1450 | static void i40e_set_rx_mode(struct net_device *netdev) |
| 1451 | { |
| 1452 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1453 | struct i40e_mac_filter *f, *ftmp; |
| 1454 | struct i40e_vsi *vsi = np->vsi; |
| 1455 | struct netdev_hw_addr *uca; |
| 1456 | struct netdev_hw_addr *mca; |
| 1457 | struct netdev_hw_addr *ha; |
| 1458 | |
| 1459 | /* add addr if not already in the filter list */ |
| 1460 | netdev_for_each_uc_addr(uca, netdev) { |
| 1461 | if (!i40e_find_mac(vsi, uca->addr, false, true)) { |
| 1462 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1463 | i40e_put_mac_in_vlan(vsi, uca->addr, |
| 1464 | false, true); |
| 1465 | else |
| 1466 | i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, |
| 1467 | false, true); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | netdev_for_each_mc_addr(mca, netdev) { |
| 1472 | if (!i40e_find_mac(vsi, mca->addr, false, true)) { |
| 1473 | if (i40e_is_vsi_in_vlan(vsi)) |
| 1474 | i40e_put_mac_in_vlan(vsi, mca->addr, |
| 1475 | false, true); |
| 1476 | else |
| 1477 | i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, |
| 1478 | false, true); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | /* remove filter if not in netdev list */ |
| 1483 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1484 | bool found = false; |
| 1485 | |
| 1486 | if (!f->is_netdev) |
| 1487 | continue; |
| 1488 | |
| 1489 | if (is_multicast_ether_addr(f->macaddr)) { |
| 1490 | netdev_for_each_mc_addr(mca, netdev) { |
| 1491 | if (ether_addr_equal(mca->addr, f->macaddr)) { |
| 1492 | found = true; |
| 1493 | break; |
| 1494 | } |
| 1495 | } |
| 1496 | } else { |
| 1497 | netdev_for_each_uc_addr(uca, netdev) { |
| 1498 | if (ether_addr_equal(uca->addr, f->macaddr)) { |
| 1499 | found = true; |
| 1500 | break; |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | for_each_dev_addr(netdev, ha) { |
| 1505 | if (ether_addr_equal(ha->addr, f->macaddr)) { |
| 1506 | found = true; |
| 1507 | break; |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | if (!found) |
| 1512 | i40e_del_filter( |
| 1513 | vsi, f->macaddr, I40E_VLAN_ANY, false, true); |
| 1514 | } |
| 1515 | |
| 1516 | /* check for other flag changes */ |
| 1517 | if (vsi->current_netdev_flags != vsi->netdev->flags) { |
| 1518 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 1519 | vsi->back->flags |= I40E_FLAG_FILTER_SYNC; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * i40e_sync_vsi_filters - Update the VSI filter list to the HW |
| 1525 | * @vsi: ptr to the VSI |
| 1526 | * |
| 1527 | * Push any outstanding VSI filter changes through the AdminQ. |
| 1528 | * |
| 1529 | * Returns 0 or error value |
| 1530 | **/ |
| 1531 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) |
| 1532 | { |
| 1533 | struct i40e_mac_filter *f, *ftmp; |
| 1534 | bool promisc_forced_on = false; |
| 1535 | bool add_happened = false; |
| 1536 | int filter_list_len = 0; |
| 1537 | u32 changed_flags = 0; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1538 | i40e_status aq_ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1539 | struct i40e_pf *pf; |
| 1540 | int num_add = 0; |
| 1541 | int num_del = 0; |
| 1542 | u16 cmd_flags; |
| 1543 | |
| 1544 | /* empty array typed pointers, kcalloc later */ |
| 1545 | struct i40e_aqc_add_macvlan_element_data *add_list; |
| 1546 | struct i40e_aqc_remove_macvlan_element_data *del_list; |
| 1547 | |
| 1548 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 1549 | usleep_range(1000, 2000); |
| 1550 | pf = vsi->back; |
| 1551 | |
| 1552 | if (vsi->netdev) { |
| 1553 | changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| 1554 | vsi->current_netdev_flags = vsi->netdev->flags; |
| 1555 | } |
| 1556 | |
| 1557 | if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { |
| 1558 | vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; |
| 1559 | |
| 1560 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1561 | sizeof(struct i40e_aqc_remove_macvlan_element_data); |
| 1562 | del_list = kcalloc(filter_list_len, |
| 1563 | sizeof(struct i40e_aqc_remove_macvlan_element_data), |
| 1564 | GFP_KERNEL); |
| 1565 | if (!del_list) |
| 1566 | return -ENOMEM; |
| 1567 | |
| 1568 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1569 | if (!f->changed) |
| 1570 | continue; |
| 1571 | |
| 1572 | if (f->counter != 0) |
| 1573 | continue; |
| 1574 | f->changed = false; |
| 1575 | cmd_flags = 0; |
| 1576 | |
| 1577 | /* add to delete list */ |
| 1578 | memcpy(del_list[num_del].mac_addr, |
| 1579 | f->macaddr, ETH_ALEN); |
| 1580 | del_list[num_del].vlan_tag = |
| 1581 | cpu_to_le16((u16)(f->vlan == |
| 1582 | I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1583 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1584 | cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; |
| 1585 | del_list[num_del].flags = cmd_flags; |
| 1586 | num_del++; |
| 1587 | |
| 1588 | /* unlink from filter list */ |
| 1589 | list_del(&f->list); |
| 1590 | kfree(f); |
| 1591 | |
| 1592 | /* flush a full buffer */ |
| 1593 | if (num_del == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1594 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1595 | vsi->seid, del_list, num_del, |
| 1596 | NULL); |
| 1597 | num_del = 0; |
| 1598 | memset(del_list, 0, sizeof(*del_list)); |
| 1599 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1600 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1601 | dev_info(&pf->pdev->dev, |
| 1602 | "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1603 | aq_ret, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1604 | pf->hw.aq.asq_last_status); |
| 1605 | } |
| 1606 | } |
| 1607 | if (num_del) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1608 | aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1609 | del_list, num_del, NULL); |
| 1610 | num_del = 0; |
| 1611 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1612 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1613 | dev_info(&pf->pdev->dev, |
| 1614 | "ignoring delete macvlan error, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1615 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | kfree(del_list); |
| 1619 | del_list = NULL; |
| 1620 | |
| 1621 | /* do all the adds now */ |
| 1622 | filter_list_len = pf->hw.aq.asq_buf_size / |
| 1623 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1624 | add_list = kcalloc(filter_list_len, |
| 1625 | sizeof(struct i40e_aqc_add_macvlan_element_data), |
| 1626 | GFP_KERNEL); |
| 1627 | if (!add_list) |
| 1628 | return -ENOMEM; |
| 1629 | |
| 1630 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 1631 | if (!f->changed) |
| 1632 | continue; |
| 1633 | |
| 1634 | if (f->counter == 0) |
| 1635 | continue; |
| 1636 | f->changed = false; |
| 1637 | add_happened = true; |
| 1638 | cmd_flags = 0; |
| 1639 | |
| 1640 | /* add to add array */ |
| 1641 | memcpy(add_list[num_add].mac_addr, |
| 1642 | f->macaddr, ETH_ALEN); |
| 1643 | add_list[num_add].vlan_tag = |
| 1644 | cpu_to_le16( |
| 1645 | (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); |
| 1646 | add_list[num_add].queue_number = 0; |
| 1647 | |
| 1648 | cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1649 | add_list[num_add].flags = cpu_to_le16(cmd_flags); |
| 1650 | num_add++; |
| 1651 | |
| 1652 | /* flush a full buffer */ |
| 1653 | if (num_add == filter_list_len) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1654 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1655 | add_list, num_add, |
| 1656 | NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1657 | num_add = 0; |
| 1658 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1659 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1660 | break; |
| 1661 | memset(add_list, 0, sizeof(*add_list)); |
| 1662 | } |
| 1663 | } |
| 1664 | if (num_add) { |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1665 | aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, |
| 1666 | add_list, num_add, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1667 | num_add = 0; |
| 1668 | } |
| 1669 | kfree(add_list); |
| 1670 | add_list = NULL; |
| 1671 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1672 | if (add_happened && (!aq_ret)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1673 | /* do nothing */; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1674 | } else if (add_happened && (aq_ret)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1675 | dev_info(&pf->pdev->dev, |
| 1676 | "add filter failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1677 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1678 | if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && |
| 1679 | !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1680 | &vsi->state)) { |
| 1681 | promisc_forced_on = true; |
| 1682 | set_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1683 | &vsi->state); |
| 1684 | dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | /* check for changes in promiscuous modes */ |
| 1690 | if (changed_flags & IFF_ALLMULTI) { |
| 1691 | bool cur_multipromisc; |
| 1692 | cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1693 | aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, |
| 1694 | vsi->seid, |
| 1695 | cur_multipromisc, |
| 1696 | NULL); |
| 1697 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1698 | dev_info(&pf->pdev->dev, |
| 1699 | "set multi promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1700 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1701 | } |
| 1702 | if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { |
| 1703 | bool cur_promisc; |
| 1704 | cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || |
| 1705 | test_bit(__I40E_FILTER_OVERFLOW_PROMISC, |
| 1706 | &vsi->state)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1707 | aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw, |
| 1708 | vsi->seid, |
| 1709 | cur_promisc, NULL); |
| 1710 | if (aq_ret) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1711 | dev_info(&pf->pdev->dev, |
| 1712 | "set uni promisc failed, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1713 | aq_ret, pf->hw.aq.asq_last_status); |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 1714 | aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, |
| 1715 | vsi->seid, |
| 1716 | cur_promisc, NULL); |
| 1717 | if (aq_ret) |
| 1718 | dev_info(&pf->pdev->dev, |
| 1719 | "set brdcast promisc failed, err %d, aq_err %d\n", |
| 1720 | aq_ret, pf->hw.aq.asq_last_status); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | clear_bit(__I40E_CONFIG_BUSY, &vsi->state); |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | /** |
| 1728 | * i40e_sync_filters_subtask - Sync the VSI filter list with HW |
| 1729 | * @pf: board private structure |
| 1730 | **/ |
| 1731 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) |
| 1732 | { |
| 1733 | int v; |
| 1734 | |
| 1735 | if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) |
| 1736 | return; |
| 1737 | pf->flags &= ~I40E_FLAG_FILTER_SYNC; |
| 1738 | |
| 1739 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 1740 | if (pf->vsi[v] && |
| 1741 | (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) |
| 1742 | i40e_sync_vsi_filters(pf->vsi[v]); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit |
| 1748 | * @netdev: network interface device structure |
| 1749 | * @new_mtu: new value for maximum frame size |
| 1750 | * |
| 1751 | * Returns 0 on success, negative on failure |
| 1752 | **/ |
| 1753 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) |
| 1754 | { |
| 1755 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jesse Brandeburg | 61a46a4 | 2014-04-23 04:50:05 +0000 | [diff] [blame] | 1756 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1757 | struct i40e_vsi *vsi = np->vsi; |
| 1758 | |
| 1759 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 1760 | if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) |
| 1761 | return -EINVAL; |
| 1762 | |
| 1763 | netdev_info(netdev, "changing MTU from %d to %d\n", |
| 1764 | netdev->mtu, new_mtu); |
| 1765 | netdev->mtu = new_mtu; |
| 1766 | if (netif_running(netdev)) |
| 1767 | i40e_vsi_reinit_locked(vsi); |
| 1768 | |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | /** |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1773 | * i40e_ioctl - Access the hwtstamp interface |
| 1774 | * @netdev: network interface device structure |
| 1775 | * @ifr: interface request data |
| 1776 | * @cmd: ioctl command |
| 1777 | **/ |
| 1778 | int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 1779 | { |
| 1780 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1781 | struct i40e_pf *pf = np->vsi->back; |
| 1782 | |
| 1783 | switch (cmd) { |
| 1784 | case SIOCGHWTSTAMP: |
| 1785 | return i40e_ptp_get_ts_config(pf, ifr); |
| 1786 | case SIOCSHWTSTAMP: |
| 1787 | return i40e_ptp_set_ts_config(pf, ifr); |
| 1788 | default: |
| 1789 | return -EOPNOTSUPP; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1794 | * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI |
| 1795 | * @vsi: the vsi being adjusted |
| 1796 | **/ |
| 1797 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) |
| 1798 | { |
| 1799 | struct i40e_vsi_context ctxt; |
| 1800 | i40e_status ret; |
| 1801 | |
| 1802 | if ((vsi->info.valid_sections & |
| 1803 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 1804 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) |
| 1805 | return; /* already enabled */ |
| 1806 | |
| 1807 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 1808 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 1809 | I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; |
| 1810 | |
| 1811 | ctxt.seid = vsi->seid; |
| 1812 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 1813 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 1814 | if (ret) { |
| 1815 | dev_info(&vsi->back->pdev->dev, |
| 1816 | "%s: update vsi failed, aq_err=%d\n", |
| 1817 | __func__, vsi->back->hw.aq.asq_last_status); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI |
| 1823 | * @vsi: the vsi being adjusted |
| 1824 | **/ |
| 1825 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) |
| 1826 | { |
| 1827 | struct i40e_vsi_context ctxt; |
| 1828 | i40e_status ret; |
| 1829 | |
| 1830 | if ((vsi->info.valid_sections & |
| 1831 | cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && |
| 1832 | ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == |
| 1833 | I40E_AQ_VSI_PVLAN_EMOD_MASK)) |
| 1834 | return; /* already disabled */ |
| 1835 | |
| 1836 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 1837 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | |
| 1838 | I40E_AQ_VSI_PVLAN_EMOD_NOTHING; |
| 1839 | |
| 1840 | ctxt.seid = vsi->seid; |
| 1841 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 1842 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 1843 | if (ret) { |
| 1844 | dev_info(&vsi->back->pdev->dev, |
| 1845 | "%s: update vsi failed, aq_err=%d\n", |
| 1846 | __func__, vsi->back->hw.aq.asq_last_status); |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * i40e_vlan_rx_register - Setup or shutdown vlan offload |
| 1852 | * @netdev: network interface to be adjusted |
| 1853 | * @features: netdev features to test if VLAN offload is enabled or not |
| 1854 | **/ |
| 1855 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) |
| 1856 | { |
| 1857 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1858 | struct i40e_vsi *vsi = np->vsi; |
| 1859 | |
| 1860 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1861 | i40e_vlan_stripping_enable(vsi); |
| 1862 | else |
| 1863 | i40e_vlan_stripping_disable(vsi); |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * i40e_vsi_add_vlan - Add vsi membership for given vlan |
| 1868 | * @vsi: the vsi being configured |
| 1869 | * @vid: vlan id to be added (0 = untagged only , -1 = any) |
| 1870 | **/ |
| 1871 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) |
| 1872 | { |
| 1873 | struct i40e_mac_filter *f, *add_f; |
| 1874 | bool is_netdev, is_vf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1875 | |
| 1876 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 1877 | is_netdev = !!(vsi->netdev); |
| 1878 | |
| 1879 | if (is_netdev) { |
| 1880 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, |
| 1881 | is_vf, is_netdev); |
| 1882 | if (!add_f) { |
| 1883 | dev_info(&vsi->back->pdev->dev, |
| 1884 | "Could not add vlan filter %d for %pM\n", |
| 1885 | vid, vsi->netdev->dev_addr); |
| 1886 | return -ENOMEM; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1891 | add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 1892 | if (!add_f) { |
| 1893 | dev_info(&vsi->back->pdev->dev, |
| 1894 | "Could not add vlan filter %d for %pM\n", |
| 1895 | vid, f->macaddr); |
| 1896 | return -ENOMEM; |
| 1897 | } |
| 1898 | } |
| 1899 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1900 | /* Now if we add a vlan tag, make sure to check if it is the first |
| 1901 | * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" |
| 1902 | * with 0, so we now accept untagged and specified tagged traffic |
| 1903 | * (and not any taged and untagged) |
| 1904 | */ |
| 1905 | if (vid > 0) { |
| 1906 | if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, |
| 1907 | I40E_VLAN_ANY, |
| 1908 | is_vf, is_netdev)) { |
| 1909 | i40e_del_filter(vsi, vsi->netdev->dev_addr, |
| 1910 | I40E_VLAN_ANY, is_vf, is_netdev); |
| 1911 | add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, |
| 1912 | is_vf, is_netdev); |
| 1913 | if (!add_f) { |
| 1914 | dev_info(&vsi->back->pdev->dev, |
| 1915 | "Could not add filter 0 for %pM\n", |
| 1916 | vsi->netdev->dev_addr); |
| 1917 | return -ENOMEM; |
| 1918 | } |
| 1919 | } |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 1920 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1921 | |
Greg Rose | 8d82a7c | 2014-01-13 16:13:04 -0800 | [diff] [blame] | 1922 | /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */ |
| 1923 | if (vid > 0 && !vsi->info.pvid) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1924 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1925 | if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 1926 | is_vf, is_netdev)) { |
| 1927 | i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 1928 | is_vf, is_netdev); |
| 1929 | add_f = i40e_add_filter(vsi, f->macaddr, |
| 1930 | 0, is_vf, is_netdev); |
| 1931 | if (!add_f) { |
| 1932 | dev_info(&vsi->back->pdev->dev, |
| 1933 | "Could not add filter 0 for %pM\n", |
| 1934 | f->macaddr); |
| 1935 | return -ENOMEM; |
| 1936 | } |
| 1937 | } |
| 1938 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1941 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 1942 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 1943 | return 0; |
| 1944 | |
| 1945 | return i40e_sync_vsi_filters(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * i40e_vsi_kill_vlan - Remove vsi membership for given vlan |
| 1950 | * @vsi: the vsi being configured |
| 1951 | * @vid: vlan id to be removed (0 = untagged only , -1 = any) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1952 | * |
| 1953 | * Return: 0 on success or negative otherwise |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1954 | **/ |
| 1955 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) |
| 1956 | { |
| 1957 | struct net_device *netdev = vsi->netdev; |
| 1958 | struct i40e_mac_filter *f, *add_f; |
| 1959 | bool is_vf, is_netdev; |
| 1960 | int filter_count = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1961 | |
| 1962 | is_vf = (vsi->type == I40E_VSI_SRIOV); |
| 1963 | is_netdev = !!(netdev); |
| 1964 | |
| 1965 | if (is_netdev) |
| 1966 | i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); |
| 1967 | |
| 1968 | list_for_each_entry(f, &vsi->mac_filter_list, list) |
| 1969 | i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); |
| 1970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1971 | /* go through all the filters for this VSI and if there is only |
| 1972 | * vid == 0 it means there are no other filters, so vid 0 must |
| 1973 | * be replaced with -1. This signifies that we should from now |
| 1974 | * on accept any traffic (with any tag present, or untagged) |
| 1975 | */ |
| 1976 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 1977 | if (is_netdev) { |
| 1978 | if (f->vlan && |
| 1979 | ether_addr_equal(netdev->dev_addr, f->macaddr)) |
| 1980 | filter_count++; |
| 1981 | } |
| 1982 | |
| 1983 | if (f->vlan) |
| 1984 | filter_count++; |
| 1985 | } |
| 1986 | |
| 1987 | if (!filter_count && is_netdev) { |
| 1988 | i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); |
| 1989 | f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, |
| 1990 | is_vf, is_netdev); |
| 1991 | if (!f) { |
| 1992 | dev_info(&vsi->back->pdev->dev, |
| 1993 | "Could not add filter %d for %pM\n", |
| 1994 | I40E_VLAN_ANY, netdev->dev_addr); |
| 1995 | return -ENOMEM; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | if (!filter_count) { |
| 2000 | list_for_each_entry(f, &vsi->mac_filter_list, list) { |
| 2001 | i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); |
| 2002 | add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, |
| 2003 | is_vf, is_netdev); |
| 2004 | if (!add_f) { |
| 2005 | dev_info(&vsi->back->pdev->dev, |
| 2006 | "Could not add filter %d for %pM\n", |
| 2007 | I40E_VLAN_ANY, f->macaddr); |
| 2008 | return -ENOMEM; |
| 2009 | } |
| 2010 | } |
| 2011 | } |
| 2012 | |
Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 2013 | if (test_bit(__I40E_DOWN, &vsi->back->state) || |
| 2014 | test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) |
| 2015 | return 0; |
| 2016 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2017 | return i40e_sync_vsi_filters(vsi); |
| 2018 | } |
| 2019 | |
| 2020 | /** |
| 2021 | * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload |
| 2022 | * @netdev: network interface to be adjusted |
| 2023 | * @vid: vlan id to be added |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2024 | * |
| 2025 | * net_device_ops implementation for adding vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2026 | **/ |
| 2027 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, |
| 2028 | __always_unused __be16 proto, u16 vid) |
| 2029 | { |
| 2030 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2031 | struct i40e_vsi *vsi = np->vsi; |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2032 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2033 | |
| 2034 | if (vid > 4095) |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2035 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2036 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2037 | netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); |
| 2038 | |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2039 | /* If the network stack called us with vid = 0 then |
| 2040 | * it is asking to receive priority tagged packets with |
| 2041 | * vlan id 0. Our HW receives them by default when configured |
| 2042 | * to receive untagged packets so there is no need to add an |
| 2043 | * extra filter for vlan 0 tagged packets. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2044 | */ |
Anjali Singhai Jain | 6982d42 | 2014-02-06 05:51:10 +0000 | [diff] [blame] | 2045 | if (vid) |
| 2046 | ret = i40e_vsi_add_vlan(vsi, vid); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2047 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2048 | if (!ret && (vid < VLAN_N_VID)) |
| 2049 | set_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2050 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2051 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload |
| 2056 | * @netdev: network interface to be adjusted |
| 2057 | * @vid: vlan id to be removed |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2058 | * |
Akeem G Abodunrin | fdfd943 | 2014-02-11 08:24:15 +0000 | [diff] [blame] | 2059 | * net_device_ops implementation for removing vlan ids |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2060 | **/ |
| 2061 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, |
| 2062 | __always_unused __be16 proto, u16 vid) |
| 2063 | { |
| 2064 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2065 | struct i40e_vsi *vsi = np->vsi; |
| 2066 | |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2067 | netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); |
| 2068 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2069 | /* return code is ignored as there is nothing a user |
| 2070 | * can do about failure to remove and a log message was |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2071 | * already printed from the other function |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2072 | */ |
| 2073 | i40e_vsi_kill_vlan(vsi, vid); |
| 2074 | |
| 2075 | clear_bit(vid, vsi->active_vlans); |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 2076 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2077 | return 0; |
| 2078 | } |
| 2079 | |
| 2080 | /** |
| 2081 | * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up |
| 2082 | * @vsi: the vsi being brought back up |
| 2083 | **/ |
| 2084 | static void i40e_restore_vlan(struct i40e_vsi *vsi) |
| 2085 | { |
| 2086 | u16 vid; |
| 2087 | |
| 2088 | if (!vsi->netdev) |
| 2089 | return; |
| 2090 | |
| 2091 | i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); |
| 2092 | |
| 2093 | for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) |
| 2094 | i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), |
| 2095 | vid); |
| 2096 | } |
| 2097 | |
| 2098 | /** |
| 2099 | * i40e_vsi_add_pvid - Add pvid for the VSI |
| 2100 | * @vsi: the vsi being adjusted |
| 2101 | * @vid: the vlan id to set as a PVID |
| 2102 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2103 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2104 | { |
| 2105 | struct i40e_vsi_context ctxt; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2106 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2107 | |
| 2108 | vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 2109 | vsi->info.pvid = cpu_to_le16(vid); |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2110 | vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | |
| 2111 | I40E_AQ_VSI_PVLAN_INSERT_PVID | |
Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2112 | I40E_AQ_VSI_PVLAN_EMOD_STR; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2113 | |
| 2114 | ctxt.seid = vsi->seid; |
| 2115 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2116 | aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 2117 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2118 | dev_info(&vsi->back->pdev->dev, |
| 2119 | "%s: update vsi failed, aq_err=%d\n", |
| 2120 | __func__, vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2121 | return -ENOENT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2124 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * i40e_vsi_remove_pvid - Remove the pvid from the VSI |
| 2129 | * @vsi: the vsi being adjusted |
| 2130 | * |
| 2131 | * Just use the vlan_rx_register() service to put it back to normal |
| 2132 | **/ |
| 2133 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) |
| 2134 | { |
Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2135 | i40e_vlan_stripping_disable(vsi); |
| 2136 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2137 | vsi->info.pvid = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources |
| 2142 | * @vsi: ptr to the VSI |
| 2143 | * |
| 2144 | * If this function returns with an error, then it's possible one or |
| 2145 | * more of the rings is populated (while the rest are not). It is the |
| 2146 | * callers duty to clean those orphaned rings. |
| 2147 | * |
| 2148 | * Return 0 on success, negative on failure |
| 2149 | **/ |
| 2150 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) |
| 2151 | { |
| 2152 | int i, err = 0; |
| 2153 | |
| 2154 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2155 | err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2156 | |
| 2157 | return err; |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues |
| 2162 | * @vsi: ptr to the VSI |
| 2163 | * |
| 2164 | * Free VSI's transmit software resources |
| 2165 | **/ |
| 2166 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) |
| 2167 | { |
| 2168 | int i; |
| 2169 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2170 | if (!vsi->tx_rings) |
| 2171 | return; |
| 2172 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2173 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2174 | if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2175 | i40e_free_tx_resources(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources |
| 2180 | * @vsi: ptr to the VSI |
| 2181 | * |
| 2182 | * If this function returns with an error, then it's possible one or |
| 2183 | * more of the rings is populated (while the rest are not). It is the |
| 2184 | * callers duty to clean those orphaned rings. |
| 2185 | * |
| 2186 | * Return 0 on success, negative on failure |
| 2187 | **/ |
| 2188 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) |
| 2189 | { |
| 2190 | int i, err = 0; |
| 2191 | |
| 2192 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2193 | err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2194 | return err; |
| 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues |
| 2199 | * @vsi: ptr to the VSI |
| 2200 | * |
| 2201 | * Free all receive software resources |
| 2202 | **/ |
| 2203 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) |
| 2204 | { |
| 2205 | int i; |
| 2206 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2207 | if (!vsi->rx_rings) |
| 2208 | return; |
| 2209 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2210 | for (i = 0; i < vsi->num_queue_pairs; i++) |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2211 | if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2212 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | /** |
| 2216 | * i40e_configure_tx_ring - Configure a transmit ring context and rest |
| 2217 | * @ring: The Tx ring to configure |
| 2218 | * |
| 2219 | * Configure the Tx descriptor ring in the HMC context. |
| 2220 | **/ |
| 2221 | static int i40e_configure_tx_ring(struct i40e_ring *ring) |
| 2222 | { |
| 2223 | struct i40e_vsi *vsi = ring->vsi; |
| 2224 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2225 | struct i40e_hw *hw = &vsi->back->hw; |
| 2226 | struct i40e_hmc_obj_txq tx_ctx; |
| 2227 | i40e_status err = 0; |
| 2228 | u32 qtx_ctl = 0; |
| 2229 | |
| 2230 | /* some ATR related tx ring init */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2231 | if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2232 | ring->atr_sample_rate = vsi->back->atr_sample_rate; |
| 2233 | ring->atr_count = 0; |
| 2234 | } else { |
| 2235 | ring->atr_sample_rate = 0; |
| 2236 | } |
| 2237 | |
| 2238 | /* initialize XPS */ |
| 2239 | if (ring->q_vector && ring->netdev && |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 2240 | vsi->tc_config.numtc <= 1 && |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2241 | !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) |
| 2242 | netif_set_xps_queue(ring->netdev, |
| 2243 | &ring->q_vector->affinity_mask, |
| 2244 | ring->queue_index); |
| 2245 | |
| 2246 | /* clear the context structure first */ |
| 2247 | memset(&tx_ctx, 0, sizeof(tx_ctx)); |
| 2248 | |
| 2249 | tx_ctx.new_context = 1; |
| 2250 | tx_ctx.base = (ring->dma / 128); |
| 2251 | tx_ctx.qlen = ring->count; |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2252 | tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED | |
| 2253 | I40E_FLAG_FD_ATR_ENABLED)); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2254 | tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP); |
Jesse Brandeburg | 1943d8b | 2014-02-14 02:14:40 +0000 | [diff] [blame] | 2255 | /* FDIR VSI tx ring can still use RS bit and writebacks */ |
| 2256 | if (vsi->type != I40E_VSI_FDIR) |
| 2257 | tx_ctx.head_wb_ena = 1; |
| 2258 | tx_ctx.head_wb_addr = ring->dma + |
| 2259 | (ring->count * sizeof(struct i40e_tx_desc)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2260 | |
| 2261 | /* As part of VSI creation/update, FW allocates certain |
| 2262 | * Tx arbitration queue sets for each TC enabled for |
| 2263 | * the VSI. The FW returns the handles to these queue |
| 2264 | * sets as part of the response buffer to Add VSI, |
| 2265 | * Update VSI, etc. AQ commands. It is expected that |
| 2266 | * these queue set handles be associated with the Tx |
| 2267 | * queues by the driver as part of the TX queue context |
| 2268 | * initialization. This has to be done regardless of |
| 2269 | * DCB as by default everything is mapped to TC0. |
| 2270 | */ |
| 2271 | tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); |
| 2272 | tx_ctx.rdylist_act = 0; |
| 2273 | |
| 2274 | /* clear the context in the HMC */ |
| 2275 | err = i40e_clear_lan_tx_queue_context(hw, pf_q); |
| 2276 | if (err) { |
| 2277 | dev_info(&vsi->back->pdev->dev, |
| 2278 | "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", |
| 2279 | ring->queue_index, pf_q, err); |
| 2280 | return -ENOMEM; |
| 2281 | } |
| 2282 | |
| 2283 | /* set the context in the HMC */ |
| 2284 | err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); |
| 2285 | if (err) { |
| 2286 | dev_info(&vsi->back->pdev->dev, |
| 2287 | "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", |
| 2288 | ring->queue_index, pf_q, err); |
| 2289 | return -ENOMEM; |
| 2290 | } |
| 2291 | |
| 2292 | /* Now associate this queue with this PCI function */ |
Shannon Nelson | 9d8bf54 | 2014-01-14 00:49:50 -0800 | [diff] [blame] | 2293 | if (vsi->type == I40E_VSI_VMDQ2) |
| 2294 | qtx_ctl = I40E_QTX_CTL_VM_QUEUE; |
| 2295 | else |
| 2296 | qtx_ctl = I40E_QTX_CTL_PF_QUEUE; |
Shannon Nelson | 13fd97749 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2297 | qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & |
| 2298 | I40E_QTX_CTL_PF_INDX_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2299 | wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); |
| 2300 | i40e_flush(hw); |
| 2301 | |
| 2302 | clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); |
| 2303 | |
| 2304 | /* cache tail off for easier writes later */ |
| 2305 | ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); |
| 2306 | |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * i40e_configure_rx_ring - Configure a receive ring context |
| 2312 | * @ring: The Rx ring to configure |
| 2313 | * |
| 2314 | * Configure the Rx descriptor ring in the HMC context. |
| 2315 | **/ |
| 2316 | static int i40e_configure_rx_ring(struct i40e_ring *ring) |
| 2317 | { |
| 2318 | struct i40e_vsi *vsi = ring->vsi; |
| 2319 | u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; |
| 2320 | u16 pf_q = vsi->base_queue + ring->queue_index; |
| 2321 | struct i40e_hw *hw = &vsi->back->hw; |
| 2322 | struct i40e_hmc_obj_rxq rx_ctx; |
| 2323 | i40e_status err = 0; |
| 2324 | |
| 2325 | ring->state = 0; |
| 2326 | |
| 2327 | /* clear the context structure first */ |
| 2328 | memset(&rx_ctx, 0, sizeof(rx_ctx)); |
| 2329 | |
| 2330 | ring->rx_buf_len = vsi->rx_buf_len; |
| 2331 | ring->rx_hdr_len = vsi->rx_hdr_len; |
| 2332 | |
| 2333 | rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; |
| 2334 | rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; |
| 2335 | |
| 2336 | rx_ctx.base = (ring->dma / 128); |
| 2337 | rx_ctx.qlen = ring->count; |
| 2338 | |
| 2339 | if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { |
| 2340 | set_ring_16byte_desc_enabled(ring); |
| 2341 | rx_ctx.dsize = 0; |
| 2342 | } else { |
| 2343 | rx_ctx.dsize = 1; |
| 2344 | } |
| 2345 | |
| 2346 | rx_ctx.dtype = vsi->dtype; |
| 2347 | if (vsi->dtype) { |
| 2348 | set_ring_ps_enabled(ring); |
| 2349 | rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 | |
| 2350 | I40E_RX_SPLIT_IP | |
| 2351 | I40E_RX_SPLIT_TCP_UDP | |
| 2352 | I40E_RX_SPLIT_SCTP; |
| 2353 | } else { |
| 2354 | rx_ctx.hsplit_0 = 0; |
| 2355 | } |
| 2356 | |
| 2357 | rx_ctx.rxmax = min_t(u16, vsi->max_frame, |
| 2358 | (chain_len * ring->rx_buf_len)); |
| 2359 | rx_ctx.tphrdesc_ena = 1; |
| 2360 | rx_ctx.tphwdesc_ena = 1; |
| 2361 | rx_ctx.tphdata_ena = 1; |
| 2362 | rx_ctx.tphhead_ena = 1; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2363 | if (hw->revision_id == 0) |
| 2364 | rx_ctx.lrxqthresh = 0; |
| 2365 | else |
| 2366 | rx_ctx.lrxqthresh = 2; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2367 | rx_ctx.crcstrip = 1; |
| 2368 | rx_ctx.l2tsel = 1; |
| 2369 | rx_ctx.showiv = 1; |
Catherine Sullivan | acb3676 | 2014-03-06 09:02:30 +0000 | [diff] [blame] | 2370 | /* set the prefena field to 1 because the manual says to */ |
| 2371 | rx_ctx.prefena = 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2372 | |
| 2373 | /* clear the context in the HMC */ |
| 2374 | err = i40e_clear_lan_rx_queue_context(hw, pf_q); |
| 2375 | if (err) { |
| 2376 | dev_info(&vsi->back->pdev->dev, |
| 2377 | "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2378 | ring->queue_index, pf_q, err); |
| 2379 | return -ENOMEM; |
| 2380 | } |
| 2381 | |
| 2382 | /* set the context in the HMC */ |
| 2383 | err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); |
| 2384 | if (err) { |
| 2385 | dev_info(&vsi->back->pdev->dev, |
| 2386 | "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", |
| 2387 | ring->queue_index, pf_q, err); |
| 2388 | return -ENOMEM; |
| 2389 | } |
| 2390 | |
| 2391 | /* cache tail for quicker writes, and clear the reg before use */ |
| 2392 | ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); |
| 2393 | writel(0, ring->tail); |
| 2394 | |
| 2395 | i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); |
| 2396 | |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * i40e_vsi_configure_tx - Configure the VSI for Tx |
| 2402 | * @vsi: VSI structure describing this set of rings and resources |
| 2403 | * |
| 2404 | * Configure the Tx VSI for operation. |
| 2405 | **/ |
| 2406 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) |
| 2407 | { |
| 2408 | int err = 0; |
| 2409 | u16 i; |
| 2410 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2411 | for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) |
| 2412 | err = i40e_configure_tx_ring(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2413 | |
| 2414 | return err; |
| 2415 | } |
| 2416 | |
| 2417 | /** |
| 2418 | * i40e_vsi_configure_rx - Configure the VSI for Rx |
| 2419 | * @vsi: the VSI being configured |
| 2420 | * |
| 2421 | * Configure the Rx VSI for operation. |
| 2422 | **/ |
| 2423 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) |
| 2424 | { |
| 2425 | int err = 0; |
| 2426 | u16 i; |
| 2427 | |
| 2428 | if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) |
| 2429 | vsi->max_frame = vsi->netdev->mtu + ETH_HLEN |
| 2430 | + ETH_FCS_LEN + VLAN_HLEN; |
| 2431 | else |
| 2432 | vsi->max_frame = I40E_RXBUFFER_2048; |
| 2433 | |
| 2434 | /* figure out correct receive buffer length */ |
| 2435 | switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | |
| 2436 | I40E_FLAG_RX_PS_ENABLED)) { |
| 2437 | case I40E_FLAG_RX_1BUF_ENABLED: |
| 2438 | vsi->rx_hdr_len = 0; |
| 2439 | vsi->rx_buf_len = vsi->max_frame; |
| 2440 | vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; |
| 2441 | break; |
| 2442 | case I40E_FLAG_RX_PS_ENABLED: |
| 2443 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2444 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2445 | vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; |
| 2446 | break; |
| 2447 | default: |
| 2448 | vsi->rx_hdr_len = I40E_RX_HDR_SIZE; |
| 2449 | vsi->rx_buf_len = I40E_RXBUFFER_2048; |
| 2450 | vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; |
| 2451 | break; |
| 2452 | } |
| 2453 | |
| 2454 | /* round up for the chip's needs */ |
| 2455 | vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, |
| 2456 | (1 << I40E_RXQ_CTX_HBUFF_SHIFT)); |
| 2457 | vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, |
| 2458 | (1 << I40E_RXQ_CTX_DBUFF_SHIFT)); |
| 2459 | |
| 2460 | /* set up individual rings */ |
| 2461 | for (i = 0; i < vsi->num_queue_pairs && !err; i++) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2462 | err = i40e_configure_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2463 | |
| 2464 | return err; |
| 2465 | } |
| 2466 | |
| 2467 | /** |
| 2468 | * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC |
| 2469 | * @vsi: ptr to the VSI |
| 2470 | **/ |
| 2471 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) |
| 2472 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2473 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2474 | u16 qoffset, qcount; |
| 2475 | int i, n; |
| 2476 | |
| 2477 | if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) |
| 2478 | return; |
| 2479 | |
| 2480 | for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { |
| 2481 | if (!(vsi->tc_config.enabled_tc & (1 << n))) |
| 2482 | continue; |
| 2483 | |
| 2484 | qoffset = vsi->tc_config.tc_info[n].qoffset; |
| 2485 | qcount = vsi->tc_config.tc_info[n].qcount; |
| 2486 | for (i = qoffset; i < (qoffset + qcount); i++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 2487 | rx_ring = vsi->rx_rings[i]; |
| 2488 | tx_ring = vsi->tx_rings[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2489 | rx_ring->dcb_tc = n; |
| 2490 | tx_ring->dcb_tc = n; |
| 2491 | } |
| 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | /** |
| 2496 | * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI |
| 2497 | * @vsi: ptr to the VSI |
| 2498 | **/ |
| 2499 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) |
| 2500 | { |
| 2501 | if (vsi->netdev) |
| 2502 | i40e_set_rx_mode(vsi->netdev); |
| 2503 | } |
| 2504 | |
| 2505 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2506 | * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters |
| 2507 | * @vsi: Pointer to the targeted VSI |
| 2508 | * |
| 2509 | * This function replays the hlist on the hw where all the SB Flow Director |
| 2510 | * filters were saved. |
| 2511 | **/ |
| 2512 | static void i40e_fdir_filter_restore(struct i40e_vsi *vsi) |
| 2513 | { |
| 2514 | struct i40e_fdir_filter *filter; |
| 2515 | struct i40e_pf *pf = vsi->back; |
| 2516 | struct hlist_node *node; |
| 2517 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2518 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 2519 | return; |
| 2520 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2521 | hlist_for_each_entry_safe(filter, node, |
| 2522 | &pf->fdir_filter_list, fdir_node) { |
| 2523 | i40e_add_del_fdir(vsi, filter, true); |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2528 | * i40e_vsi_configure - Set up the VSI for action |
| 2529 | * @vsi: the VSI being configured |
| 2530 | **/ |
| 2531 | static int i40e_vsi_configure(struct i40e_vsi *vsi) |
| 2532 | { |
| 2533 | int err; |
| 2534 | |
| 2535 | i40e_set_vsi_rx_mode(vsi); |
| 2536 | i40e_restore_vlan(vsi); |
| 2537 | i40e_vsi_config_dcb_rings(vsi); |
| 2538 | err = i40e_vsi_configure_tx(vsi); |
| 2539 | if (!err) |
| 2540 | err = i40e_vsi_configure_rx(vsi); |
| 2541 | |
| 2542 | return err; |
| 2543 | } |
| 2544 | |
| 2545 | /** |
| 2546 | * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW |
| 2547 | * @vsi: the VSI being configured |
| 2548 | **/ |
| 2549 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) |
| 2550 | { |
| 2551 | struct i40e_pf *pf = vsi->back; |
| 2552 | struct i40e_q_vector *q_vector; |
| 2553 | struct i40e_hw *hw = &pf->hw; |
| 2554 | u16 vector; |
| 2555 | int i, q; |
| 2556 | u32 val; |
| 2557 | u32 qp; |
| 2558 | |
| 2559 | /* The interrupt indexing is offset by 1 in the PFINT_ITRn |
| 2560 | * and PFINT_LNKLSTn registers, e.g.: |
| 2561 | * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts) |
| 2562 | */ |
| 2563 | qp = vsi->base_queue; |
| 2564 | vector = vsi->base_vector; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2565 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
| 2566 | q_vector = vsi->q_vectors[i]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2567 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2568 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2569 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), |
| 2570 | q_vector->rx.itr); |
| 2571 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2572 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2573 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), |
| 2574 | q_vector->tx.itr); |
| 2575 | |
| 2576 | /* Linked list for the queuepairs assigned to this vector */ |
| 2577 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); |
| 2578 | for (q = 0; q < q_vector->num_ringpairs; q++) { |
| 2579 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2580 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2581 | (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | |
| 2582 | (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| |
| 2583 | (I40E_QUEUE_TYPE_TX |
| 2584 | << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); |
| 2585 | |
| 2586 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 2587 | |
| 2588 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2589 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2590 | (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | |
| 2591 | ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| |
| 2592 | (I40E_QUEUE_TYPE_RX |
| 2593 | << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2594 | |
| 2595 | /* Terminate the linked list */ |
| 2596 | if (q == (q_vector->num_ringpairs - 1)) |
| 2597 | val |= (I40E_QUEUE_END_OF_LIST |
| 2598 | << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2599 | |
| 2600 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 2601 | qp++; |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | i40e_flush(hw); |
| 2606 | } |
| 2607 | |
| 2608 | /** |
| 2609 | * i40e_enable_misc_int_causes - enable the non-queue interrupts |
| 2610 | * @hw: ptr to the hardware info |
| 2611 | **/ |
| 2612 | static void i40e_enable_misc_int_causes(struct i40e_hw *hw) |
| 2613 | { |
| 2614 | u32 val; |
| 2615 | |
| 2616 | /* clear things first */ |
| 2617 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */ |
| 2618 | rd32(hw, I40E_PFINT_ICR0); /* read to clear */ |
| 2619 | |
| 2620 | val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | |
| 2621 | I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | |
| 2622 | I40E_PFINT_ICR0_ENA_GRST_MASK | |
| 2623 | I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | |
| 2624 | I40E_PFINT_ICR0_ENA_GPIO_MASK | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2625 | I40E_PFINT_ICR0_ENA_TIMESYNC_MASK | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2626 | I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | |
| 2627 | I40E_PFINT_ICR0_ENA_VFLR_MASK | |
| 2628 | I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 2629 | |
| 2630 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 2631 | |
| 2632 | /* SW_ITR_IDX = 0, but don't change INTENA */ |
Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 2633 | wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | |
| 2634 | I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2635 | |
| 2636 | /* OTHER_ITR_IDX = 0 */ |
| 2637 | wr32(hw, I40E_PFINT_STAT_CTL0, 0); |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW |
| 2642 | * @vsi: the VSI being configured |
| 2643 | **/ |
| 2644 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) |
| 2645 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2646 | struct i40e_q_vector *q_vector = vsi->q_vectors[0]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2647 | struct i40e_pf *pf = vsi->back; |
| 2648 | struct i40e_hw *hw = &pf->hw; |
| 2649 | u32 val; |
| 2650 | |
| 2651 | /* set the ITR configuration */ |
| 2652 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 2653 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 2654 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); |
| 2655 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 2656 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 2657 | wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); |
| 2658 | |
| 2659 | i40e_enable_misc_int_causes(hw); |
| 2660 | |
| 2661 | /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ |
| 2662 | wr32(hw, I40E_PFINT_LNKLST0, 0); |
| 2663 | |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 2664 | /* Associate the queue pair to the vector and enable the queue int */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2665 | val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 2666 | (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | |
| 2667 | (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); |
| 2668 | |
| 2669 | wr32(hw, I40E_QINT_RQCTL(0), val); |
| 2670 | |
| 2671 | val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 2672 | (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | |
| 2673 | (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); |
| 2674 | |
| 2675 | wr32(hw, I40E_QINT_TQCTL(0), val); |
| 2676 | i40e_flush(hw); |
| 2677 | } |
| 2678 | |
| 2679 | /** |
Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 2680 | * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 |
| 2681 | * @pf: board private structure |
| 2682 | **/ |
| 2683 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) |
| 2684 | { |
| 2685 | struct i40e_hw *hw = &pf->hw; |
| 2686 | |
| 2687 | wr32(hw, I40E_PFINT_DYN_CTL0, |
| 2688 | I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 2689 | i40e_flush(hw); |
| 2690 | } |
| 2691 | |
| 2692 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2693 | * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 |
| 2694 | * @pf: board private structure |
| 2695 | **/ |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2696 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2697 | { |
| 2698 | struct i40e_hw *hw = &pf->hw; |
| 2699 | u32 val; |
| 2700 | |
| 2701 | val = I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 2702 | I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | |
| 2703 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); |
| 2704 | |
| 2705 | wr32(hw, I40E_PFINT_DYN_CTL0, val); |
| 2706 | i40e_flush(hw); |
| 2707 | } |
| 2708 | |
| 2709 | /** |
| 2710 | * i40e_irq_dynamic_enable - Enable default interrupt generation settings |
| 2711 | * @vsi: pointer to a vsi |
| 2712 | * @vector: enable a particular Hw Interrupt vector |
| 2713 | **/ |
| 2714 | void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector) |
| 2715 | { |
| 2716 | struct i40e_pf *pf = vsi->back; |
| 2717 | struct i40e_hw *hw = &pf->hw; |
| 2718 | u32 val; |
| 2719 | |
| 2720 | val = I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 2721 | I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | |
| 2722 | (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); |
| 2723 | wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2724 | /* skip the flush */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | /** |
| 2728 | * i40e_msix_clean_rings - MSIX mode Interrupt Handler |
| 2729 | * @irq: interrupt number |
| 2730 | * @data: pointer to a q_vector |
| 2731 | **/ |
| 2732 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) |
| 2733 | { |
| 2734 | struct i40e_q_vector *q_vector = data; |
| 2735 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2736 | if (!q_vector->tx.ring && !q_vector->rx.ring) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2737 | return IRQ_HANDLED; |
| 2738 | |
| 2739 | napi_schedule(&q_vector->napi); |
| 2740 | |
| 2741 | return IRQ_HANDLED; |
| 2742 | } |
| 2743 | |
| 2744 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2745 | * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts |
| 2746 | * @vsi: the VSI being configured |
| 2747 | * @basename: name for the vector |
| 2748 | * |
| 2749 | * Allocates MSI-X vectors and requests interrupts from the kernel. |
| 2750 | **/ |
| 2751 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) |
| 2752 | { |
| 2753 | int q_vectors = vsi->num_q_vectors; |
| 2754 | struct i40e_pf *pf = vsi->back; |
| 2755 | int base = vsi->base_vector; |
| 2756 | int rx_int_idx = 0; |
| 2757 | int tx_int_idx = 0; |
| 2758 | int vector, err; |
| 2759 | |
| 2760 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2761 | struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2762 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2763 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2764 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2765 | "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| 2766 | tx_int_idx++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2767 | } else if (q_vector->rx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2768 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2769 | "%s-%s-%d", basename, "rx", rx_int_idx++); |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2770 | } else if (q_vector->tx.ring) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2771 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2772 | "%s-%s-%d", basename, "tx", tx_int_idx++); |
| 2773 | } else { |
| 2774 | /* skip this unused q_vector */ |
| 2775 | continue; |
| 2776 | } |
| 2777 | err = request_irq(pf->msix_entries[base + vector].vector, |
| 2778 | vsi->irq_handler, |
| 2779 | 0, |
| 2780 | q_vector->name, |
| 2781 | q_vector); |
| 2782 | if (err) { |
| 2783 | dev_info(&pf->pdev->dev, |
| 2784 | "%s: request_irq failed, error: %d\n", |
| 2785 | __func__, err); |
| 2786 | goto free_queue_irqs; |
| 2787 | } |
| 2788 | /* assign the mask for this irq */ |
| 2789 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 2790 | &q_vector->affinity_mask); |
| 2791 | } |
| 2792 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame^] | 2793 | vsi->irqs_ready = true; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2794 | return 0; |
| 2795 | |
| 2796 | free_queue_irqs: |
| 2797 | while (vector) { |
| 2798 | vector--; |
| 2799 | irq_set_affinity_hint(pf->msix_entries[base + vector].vector, |
| 2800 | NULL); |
| 2801 | free_irq(pf->msix_entries[base + vector].vector, |
| 2802 | &(vsi->q_vectors[vector])); |
| 2803 | } |
| 2804 | return err; |
| 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI |
| 2809 | * @vsi: the VSI being un-configured |
| 2810 | **/ |
| 2811 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) |
| 2812 | { |
| 2813 | struct i40e_pf *pf = vsi->back; |
| 2814 | struct i40e_hw *hw = &pf->hw; |
| 2815 | int base = vsi->base_vector; |
| 2816 | int i; |
| 2817 | |
| 2818 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2819 | wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); |
| 2820 | wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 2824 | for (i = vsi->base_vector; |
| 2825 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 2826 | wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); |
| 2827 | |
| 2828 | i40e_flush(hw); |
| 2829 | for (i = 0; i < vsi->num_q_vectors; i++) |
| 2830 | synchronize_irq(pf->msix_entries[i + base].vector); |
| 2831 | } else { |
| 2832 | /* Legacy and MSI mode - this stops all interrupt handling */ |
| 2833 | wr32(hw, I40E_PFINT_ICR0_ENA, 0); |
| 2834 | wr32(hw, I40E_PFINT_DYN_CTL0, 0); |
| 2835 | i40e_flush(hw); |
| 2836 | synchronize_irq(pf->pdev->irq); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * i40e_vsi_enable_irq - Enable IRQ for the given VSI |
| 2842 | * @vsi: the VSI being configured |
| 2843 | **/ |
| 2844 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) |
| 2845 | { |
| 2846 | struct i40e_pf *pf = vsi->back; |
| 2847 | int i; |
| 2848 | |
| 2849 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 2850 | for (i = vsi->base_vector; |
| 2851 | i < (vsi->num_q_vectors + vsi->base_vector); i++) |
| 2852 | i40e_irq_dynamic_enable(vsi, i); |
| 2853 | } else { |
| 2854 | i40e_irq_dynamic_enable_icr0(pf); |
| 2855 | } |
| 2856 | |
Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2857 | i40e_flush(&pf->hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2858 | return 0; |
| 2859 | } |
| 2860 | |
| 2861 | /** |
| 2862 | * i40e_stop_misc_vector - Stop the vector that handles non-queue events |
| 2863 | * @pf: board private structure |
| 2864 | **/ |
| 2865 | static void i40e_stop_misc_vector(struct i40e_pf *pf) |
| 2866 | { |
| 2867 | /* Disable ICR 0 */ |
| 2868 | wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); |
| 2869 | i40e_flush(&pf->hw); |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * i40e_intr - MSI/Legacy and non-queue interrupt handler |
| 2874 | * @irq: interrupt number |
| 2875 | * @data: pointer to a q_vector |
| 2876 | * |
| 2877 | * This is the handler used for all MSI/Legacy interrupts, and deals |
| 2878 | * with both queue and non-queue interrupts. This is also used in |
| 2879 | * MSIX mode to handle the non-queue interrupts. |
| 2880 | **/ |
| 2881 | static irqreturn_t i40e_intr(int irq, void *data) |
| 2882 | { |
| 2883 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 2884 | struct i40e_hw *hw = &pf->hw; |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2885 | irqreturn_t ret = IRQ_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2886 | u32 icr0, icr0_remaining; |
| 2887 | u32 val, ena_mask; |
| 2888 | |
| 2889 | icr0 = rd32(hw, I40E_PFINT_ICR0); |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2890 | ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2891 | |
Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2892 | /* if sharing a legacy IRQ, we might get called w/o an intr pending */ |
| 2893 | if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2894 | goto enable_intr; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2895 | |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 2896 | /* if interrupt but no bits showing, must be SWINT */ |
| 2897 | if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || |
| 2898 | (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) |
| 2899 | pf->sw_int_count++; |
| 2900 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2901 | /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ |
| 2902 | if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { |
| 2903 | |
| 2904 | /* temporarily disable queue cause for NAPI processing */ |
| 2905 | u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); |
| 2906 | qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; |
| 2907 | wr32(hw, I40E_QINT_RQCTL(0), qval); |
| 2908 | |
| 2909 | qval = rd32(hw, I40E_QINT_TQCTL(0)); |
| 2910 | qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; |
| 2911 | wr32(hw, I40E_QINT_TQCTL(0), qval); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2912 | |
| 2913 | if (!test_bit(__I40E_DOWN, &pf->state)) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2914 | napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { |
| 2918 | ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 2919 | set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 2920 | } |
| 2921 | |
| 2922 | if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { |
| 2923 | ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 2924 | set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 2925 | } |
| 2926 | |
| 2927 | if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { |
| 2928 | ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; |
| 2929 | set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); |
| 2930 | } |
| 2931 | |
| 2932 | if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { |
| 2933 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
| 2934 | set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 2935 | ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; |
| 2936 | val = rd32(hw, I40E_GLGEN_RSTAT); |
| 2937 | val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) |
| 2938 | >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 2939 | if (val == I40E_RESET_CORER) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2940 | pf->corer_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 2941 | } else if (val == I40E_RESET_GLOBR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2942 | pf->globr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 2943 | } else if (val == I40E_RESET_EMPR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2944 | pf->empr_count++; |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 2945 | set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state); |
| 2946 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2949 | if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { |
| 2950 | icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; |
| 2951 | dev_info(&pf->pdev->dev, "HMC error interrupt\n"); |
| 2952 | } |
| 2953 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2954 | if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) { |
| 2955 | u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0); |
| 2956 | |
| 2957 | if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) { |
Jacob Keller | cafa1fc | 2014-04-24 18:05:03 -0700 | [diff] [blame] | 2958 | icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK; |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2959 | i40e_ptp_tx_hwtstamp(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2960 | } |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2963 | /* If a critical error is pending we have no choice but to reset the |
| 2964 | * device. |
| 2965 | * Report and mask out any remaining unexpected interrupts. |
| 2966 | */ |
| 2967 | icr0_remaining = icr0 & ena_mask; |
| 2968 | if (icr0_remaining) { |
| 2969 | dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", |
| 2970 | icr0_remaining); |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2971 | if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2972 | (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || |
Anjali Singhai Jain | c0c2897 | 2014-02-12 01:45:34 +0000 | [diff] [blame] | 2973 | (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) { |
Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2974 | dev_info(&pf->pdev->dev, "device will be reset\n"); |
| 2975 | set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 2976 | i40e_service_event_schedule(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2977 | } |
| 2978 | ena_mask &= ~icr0_remaining; |
| 2979 | } |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2980 | ret = IRQ_HANDLED; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2981 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2982 | enable_intr: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2983 | /* re-enable interrupt causes */ |
| 2984 | wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2985 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 2986 | i40e_service_event_schedule(pf); |
| 2987 | i40e_irq_dynamic_enable_icr0(pf); |
| 2988 | } |
| 2989 | |
Anjali Singhai Jain | 5e823066 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2990 | return ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 2994 | * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes |
| 2995 | * @tx_ring: tx ring to clean |
| 2996 | * @budget: how many cleans we're allowed |
| 2997 | * |
| 2998 | * Returns true if there's any budget left (e.g. the clean is finished) |
| 2999 | **/ |
| 3000 | static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget) |
| 3001 | { |
| 3002 | struct i40e_vsi *vsi = tx_ring->vsi; |
| 3003 | u16 i = tx_ring->next_to_clean; |
| 3004 | struct i40e_tx_buffer *tx_buf; |
| 3005 | struct i40e_tx_desc *tx_desc; |
| 3006 | |
| 3007 | tx_buf = &tx_ring->tx_bi[i]; |
| 3008 | tx_desc = I40E_TX_DESC(tx_ring, i); |
| 3009 | i -= tx_ring->count; |
| 3010 | |
| 3011 | do { |
| 3012 | struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch; |
| 3013 | |
| 3014 | /* if next_to_watch is not set then there is no work pending */ |
| 3015 | if (!eop_desc) |
| 3016 | break; |
| 3017 | |
| 3018 | /* prevent any other reads prior to eop_desc */ |
| 3019 | read_barrier_depends(); |
| 3020 | |
| 3021 | /* if the descriptor isn't done, no work yet to do */ |
| 3022 | if (!(eop_desc->cmd_type_offset_bsz & |
| 3023 | cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE))) |
| 3024 | break; |
| 3025 | |
| 3026 | /* clear next_to_watch to prevent false hangs */ |
| 3027 | tx_buf->next_to_watch = NULL; |
| 3028 | |
| 3029 | /* unmap skb header data */ |
| 3030 | dma_unmap_single(tx_ring->dev, |
| 3031 | dma_unmap_addr(tx_buf, dma), |
| 3032 | dma_unmap_len(tx_buf, len), |
| 3033 | DMA_TO_DEVICE); |
| 3034 | |
| 3035 | dma_unmap_len_set(tx_buf, len, 0); |
| 3036 | |
| 3037 | |
| 3038 | /* move to the next desc and buffer to clean */ |
| 3039 | tx_buf++; |
| 3040 | tx_desc++; |
| 3041 | i++; |
| 3042 | if (unlikely(!i)) { |
| 3043 | i -= tx_ring->count; |
| 3044 | tx_buf = tx_ring->tx_bi; |
| 3045 | tx_desc = I40E_TX_DESC(tx_ring, 0); |
| 3046 | } |
| 3047 | |
| 3048 | /* update budget accounting */ |
| 3049 | budget--; |
| 3050 | } while (likely(budget)); |
| 3051 | |
| 3052 | i += tx_ring->count; |
| 3053 | tx_ring->next_to_clean = i; |
| 3054 | |
| 3055 | if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3056 | i40e_irq_dynamic_enable(vsi, |
| 3057 | tx_ring->q_vector->v_idx + vsi->base_vector); |
| 3058 | } |
| 3059 | return budget > 0; |
| 3060 | } |
| 3061 | |
| 3062 | /** |
| 3063 | * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring |
| 3064 | * @irq: interrupt number |
| 3065 | * @data: pointer to a q_vector |
| 3066 | **/ |
| 3067 | static irqreturn_t i40e_fdir_clean_ring(int irq, void *data) |
| 3068 | { |
| 3069 | struct i40e_q_vector *q_vector = data; |
| 3070 | struct i40e_vsi *vsi; |
| 3071 | |
| 3072 | if (!q_vector->tx.ring) |
| 3073 | return IRQ_HANDLED; |
| 3074 | |
| 3075 | vsi = q_vector->tx.ring->vsi; |
| 3076 | i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit); |
| 3077 | |
| 3078 | return IRQ_HANDLED; |
| 3079 | } |
| 3080 | |
| 3081 | /** |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3082 | * i40e_map_vector_to_qp - Assigns the queue pair to the vector |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3083 | * @vsi: the VSI being configured |
| 3084 | * @v_idx: vector index |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3085 | * @qp_idx: queue pair index |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3086 | **/ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3087 | static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3088 | { |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3089 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3090 | struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; |
| 3091 | struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3092 | |
| 3093 | tx_ring->q_vector = q_vector; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3094 | tx_ring->next = q_vector->tx.ring; |
| 3095 | q_vector->tx.ring = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3096 | q_vector->tx.count++; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3097 | |
| 3098 | rx_ring->q_vector = q_vector; |
| 3099 | rx_ring->next = q_vector->rx.ring; |
| 3100 | q_vector->rx.ring = rx_ring; |
| 3101 | q_vector->rx.count++; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | /** |
| 3105 | * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors |
| 3106 | * @vsi: the VSI being configured |
| 3107 | * |
| 3108 | * This function maps descriptor rings to the queue-specific vectors |
| 3109 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 3110 | * one vector per queue pair, but on a constrained vector budget, we |
| 3111 | * group the queue pairs as "efficiently" as possible. |
| 3112 | **/ |
| 3113 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) |
| 3114 | { |
| 3115 | int qp_remaining = vsi->num_queue_pairs; |
| 3116 | int q_vectors = vsi->num_q_vectors; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3117 | int num_ringpairs; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3118 | int v_start = 0; |
| 3119 | int qp_idx = 0; |
| 3120 | |
| 3121 | /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to |
| 3122 | * group them so there are multiple queues per vector. |
| 3123 | */ |
| 3124 | for (; v_start < q_vectors && qp_remaining; v_start++) { |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3125 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; |
| 3126 | |
| 3127 | num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); |
| 3128 | |
| 3129 | q_vector->num_ringpairs = num_ringpairs; |
| 3130 | |
| 3131 | q_vector->rx.count = 0; |
| 3132 | q_vector->tx.count = 0; |
| 3133 | q_vector->rx.ring = NULL; |
| 3134 | q_vector->tx.ring = NULL; |
| 3135 | |
| 3136 | while (num_ringpairs--) { |
| 3137 | map_vector_to_qp(vsi, v_start, qp_idx); |
| 3138 | qp_idx++; |
| 3139 | qp_remaining--; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3140 | } |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * i40e_vsi_request_irq - Request IRQ from the OS |
| 3146 | * @vsi: the VSI being configured |
| 3147 | * @basename: name for the vector |
| 3148 | **/ |
| 3149 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) |
| 3150 | { |
| 3151 | struct i40e_pf *pf = vsi->back; |
| 3152 | int err; |
| 3153 | |
| 3154 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 3155 | err = i40e_vsi_request_irq_msix(vsi, basename); |
| 3156 | else if (pf->flags & I40E_FLAG_MSI_ENABLED) |
| 3157 | err = request_irq(pf->pdev->irq, i40e_intr, 0, |
| 3158 | pf->misc_int_name, pf); |
| 3159 | else |
| 3160 | err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, |
| 3161 | pf->misc_int_name, pf); |
| 3162 | |
| 3163 | if (err) |
| 3164 | dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); |
| 3165 | |
| 3166 | return err; |
| 3167 | } |
| 3168 | |
| 3169 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3170 | /** |
| 3171 | * i40e_netpoll - A Polling 'interrupt'handler |
| 3172 | * @netdev: network interface device structure |
| 3173 | * |
| 3174 | * This is used by netconsole to send skbs without having to re-enable |
| 3175 | * interrupts. It's not called while the normal interrupt routine is executing. |
| 3176 | **/ |
| 3177 | static void i40e_netpoll(struct net_device *netdev) |
| 3178 | { |
| 3179 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3180 | struct i40e_vsi *vsi = np->vsi; |
| 3181 | struct i40e_pf *pf = vsi->back; |
| 3182 | int i; |
| 3183 | |
| 3184 | /* if interface is down do nothing */ |
| 3185 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3186 | return; |
| 3187 | |
| 3188 | pf->flags |= I40E_FLAG_IN_NETPOLL; |
| 3189 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3190 | for (i = 0; i < vsi->num_q_vectors; i++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3191 | i40e_msix_clean_rings(0, vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3192 | } else { |
| 3193 | i40e_intr(pf->pdev->irq, netdev); |
| 3194 | } |
| 3195 | pf->flags &= ~I40E_FLAG_IN_NETPOLL; |
| 3196 | } |
| 3197 | #endif |
| 3198 | |
| 3199 | /** |
| 3200 | * i40e_vsi_control_tx - Start or stop a VSI's rings |
| 3201 | * @vsi: the VSI being configured |
| 3202 | * @enable: start or stop the rings |
| 3203 | **/ |
| 3204 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) |
| 3205 | { |
| 3206 | struct i40e_pf *pf = vsi->back; |
| 3207 | struct i40e_hw *hw = &pf->hw; |
| 3208 | int i, j, pf_q; |
| 3209 | u32 tx_reg; |
| 3210 | |
| 3211 | pf_q = vsi->base_queue; |
| 3212 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Matt Jared | 351499ab | 2014-04-23 04:50:03 +0000 | [diff] [blame] | 3213 | |
| 3214 | /* warn the TX unit of coming changes */ |
| 3215 | i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable); |
| 3216 | if (!enable) |
| 3217 | udelay(10); |
| 3218 | |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3219 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3220 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3221 | if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3222 | ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3223 | break; |
| 3224 | usleep_range(1000, 2000); |
| 3225 | } |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3226 | /* Skip if the queue is already in the requested state */ |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3227 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3228 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3229 | |
| 3230 | /* turn on/off the queue */ |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3231 | if (enable) { |
| 3232 | wr32(hw, I40E_QTX_HEAD(pf_q), 0); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3233 | tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3234 | } else { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3235 | tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; |
Shannon Nelson | c5c9eb9 | 2013-12-21 05:44:48 +0000 | [diff] [blame] | 3236 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3237 | |
| 3238 | wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); |
| 3239 | |
| 3240 | /* wait for the change to finish */ |
| 3241 | for (j = 0; j < 10; j++) { |
| 3242 | tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3243 | if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) |
| 3244 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3245 | |
| 3246 | udelay(10); |
| 3247 | } |
| 3248 | if (j >= 10) { |
| 3249 | dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n", |
| 3250 | pf_q, (enable ? "en" : "dis")); |
| 3251 | return -ETIMEDOUT; |
| 3252 | } |
| 3253 | } |
| 3254 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3255 | if (hw->revision_id == 0) |
| 3256 | mdelay(50); |
| 3257 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3258 | return 0; |
| 3259 | } |
| 3260 | |
| 3261 | /** |
| 3262 | * i40e_vsi_control_rx - Start or stop a VSI's rings |
| 3263 | * @vsi: the VSI being configured |
| 3264 | * @enable: start or stop the rings |
| 3265 | **/ |
| 3266 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) |
| 3267 | { |
| 3268 | struct i40e_pf *pf = vsi->back; |
| 3269 | struct i40e_hw *hw = &pf->hw; |
| 3270 | int i, j, pf_q; |
| 3271 | u32 rx_reg; |
| 3272 | |
| 3273 | pf_q = vsi->base_queue; |
| 3274 | for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3275 | for (j = 0; j < 50; j++) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3276 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3277 | if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) == |
| 3278 | ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1)) |
| 3279 | break; |
| 3280 | usleep_range(1000, 2000); |
| 3281 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3282 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3283 | /* Skip if the queue is already in the requested state */ |
| 3284 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3285 | continue; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3286 | |
| 3287 | /* turn on/off the queue */ |
| 3288 | if (enable) |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3289 | rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3290 | else |
Mitch Williams | 6c5ef62 | 2014-02-20 19:29:16 -0800 | [diff] [blame] | 3291 | rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3292 | wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); |
| 3293 | |
| 3294 | /* wait for the change to finish */ |
| 3295 | for (j = 0; j < 10; j++) { |
| 3296 | rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); |
| 3297 | |
Catherine Sullivan | 7c122007 | 2014-03-14 07:32:29 +0000 | [diff] [blame] | 3298 | if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) |
| 3299 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3300 | |
| 3301 | udelay(10); |
| 3302 | } |
| 3303 | if (j >= 10) { |
| 3304 | dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n", |
| 3305 | pf_q, (enable ? "en" : "dis")); |
| 3306 | return -ETIMEDOUT; |
| 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | return 0; |
| 3311 | } |
| 3312 | |
| 3313 | /** |
| 3314 | * i40e_vsi_control_rings - Start or stop a VSI's rings |
| 3315 | * @vsi: the VSI being configured |
| 3316 | * @enable: start or stop the rings |
| 3317 | **/ |
Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3318 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3319 | { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3320 | int ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3321 | |
| 3322 | /* do rx first for enable and last for disable */ |
| 3323 | if (request) { |
| 3324 | ret = i40e_vsi_control_rx(vsi, request); |
| 3325 | if (ret) |
| 3326 | return ret; |
| 3327 | ret = i40e_vsi_control_tx(vsi, request); |
| 3328 | } else { |
Anjali Singhai Jain | 3b867b2 | 2013-12-21 05:44:44 +0000 | [diff] [blame] | 3329 | /* Ignore return value, we need to shutdown whatever we can */ |
| 3330 | i40e_vsi_control_tx(vsi, request); |
| 3331 | i40e_vsi_control_rx(vsi, request); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | return ret; |
| 3335 | } |
| 3336 | |
| 3337 | /** |
| 3338 | * i40e_vsi_free_irq - Free the irq association with the OS |
| 3339 | * @vsi: the VSI being configured |
| 3340 | **/ |
| 3341 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) |
| 3342 | { |
| 3343 | struct i40e_pf *pf = vsi->back; |
| 3344 | struct i40e_hw *hw = &pf->hw; |
| 3345 | int base = vsi->base_vector; |
| 3346 | u32 val, qp; |
| 3347 | int i; |
| 3348 | |
| 3349 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3350 | if (!vsi->q_vectors) |
| 3351 | return; |
| 3352 | |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame^] | 3353 | if (!vsi->irqs_ready) |
| 3354 | return; |
| 3355 | |
| 3356 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3357 | for (i = 0; i < vsi->num_q_vectors; i++) { |
| 3358 | u16 vector = i + base; |
| 3359 | |
| 3360 | /* free only the irqs that were actually requested */ |
Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3361 | if (!vsi->q_vectors[i] || |
| 3362 | !vsi->q_vectors[i]->num_ringpairs) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3363 | continue; |
| 3364 | |
| 3365 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3366 | irq_set_affinity_hint(pf->msix_entries[vector].vector, |
| 3367 | NULL); |
| 3368 | free_irq(pf->msix_entries[vector].vector, |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3369 | vsi->q_vectors[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3370 | |
| 3371 | /* Tear down the interrupt queue link list |
| 3372 | * |
| 3373 | * We know that they come in pairs and always |
| 3374 | * the Rx first, then the Tx. To clear the |
| 3375 | * link list, stick the EOL value into the |
| 3376 | * next_q field of the registers. |
| 3377 | */ |
| 3378 | val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); |
| 3379 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3380 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3381 | val |= I40E_QUEUE_END_OF_LIST |
| 3382 | << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3383 | wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); |
| 3384 | |
| 3385 | while (qp != I40E_QUEUE_END_OF_LIST) { |
| 3386 | u32 next; |
| 3387 | |
| 3388 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3389 | |
| 3390 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3391 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3392 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3393 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3394 | |
| 3395 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3396 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3397 | |
| 3398 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3399 | |
| 3400 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3401 | |
| 3402 | next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) |
| 3403 | >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; |
| 3404 | |
| 3405 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3406 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3407 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3408 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3409 | |
| 3410 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3411 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3412 | |
| 3413 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3414 | qp = next; |
| 3415 | } |
| 3416 | } |
| 3417 | } else { |
| 3418 | free_irq(pf->pdev->irq, pf); |
| 3419 | |
| 3420 | val = rd32(hw, I40E_PFINT_LNKLST0); |
| 3421 | qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) |
| 3422 | >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; |
| 3423 | val |= I40E_QUEUE_END_OF_LIST |
| 3424 | << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; |
| 3425 | wr32(hw, I40E_PFINT_LNKLST0, val); |
| 3426 | |
| 3427 | val = rd32(hw, I40E_QINT_RQCTL(qp)); |
| 3428 | val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK | |
| 3429 | I40E_QINT_RQCTL_MSIX0_INDX_MASK | |
| 3430 | I40E_QINT_RQCTL_CAUSE_ENA_MASK | |
| 3431 | I40E_QINT_RQCTL_INTEVENT_MASK); |
| 3432 | |
| 3433 | val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | |
| 3434 | I40E_QINT_RQCTL_NEXTQ_INDX_MASK); |
| 3435 | |
| 3436 | wr32(hw, I40E_QINT_RQCTL(qp), val); |
| 3437 | |
| 3438 | val = rd32(hw, I40E_QINT_TQCTL(qp)); |
| 3439 | |
| 3440 | val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK | |
| 3441 | I40E_QINT_TQCTL_MSIX0_INDX_MASK | |
| 3442 | I40E_QINT_TQCTL_CAUSE_ENA_MASK | |
| 3443 | I40E_QINT_TQCTL_INTEVENT_MASK); |
| 3444 | |
| 3445 | val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | |
| 3446 | I40E_QINT_TQCTL_NEXTQ_INDX_MASK); |
| 3447 | |
| 3448 | wr32(hw, I40E_QINT_TQCTL(qp), val); |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | /** |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3453 | * i40e_free_q_vector - Free memory allocated for specific interrupt vector |
| 3454 | * @vsi: the VSI being configured |
| 3455 | * @v_idx: Index of vector to be freed |
| 3456 | * |
| 3457 | * This function frees the memory allocated to the q_vector. In addition if |
| 3458 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3459 | * to freeing the q_vector. |
| 3460 | **/ |
| 3461 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) |
| 3462 | { |
| 3463 | struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3464 | struct i40e_ring *ring; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3465 | |
| 3466 | if (!q_vector) |
| 3467 | return; |
| 3468 | |
| 3469 | /* disassociate q_vector from rings */ |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3470 | i40e_for_each_ring(ring, q_vector->tx) |
| 3471 | ring->q_vector = NULL; |
| 3472 | |
| 3473 | i40e_for_each_ring(ring, q_vector->rx) |
| 3474 | ring->q_vector = NULL; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3475 | |
| 3476 | /* only VSI w/ an associated netdev is set up w/ NAPI */ |
| 3477 | if (vsi->netdev) |
| 3478 | netif_napi_del(&q_vector->napi); |
| 3479 | |
| 3480 | vsi->q_vectors[v_idx] = NULL; |
| 3481 | |
| 3482 | kfree_rcu(q_vector, rcu); |
| 3483 | } |
| 3484 | |
| 3485 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3486 | * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors |
| 3487 | * @vsi: the VSI being un-configured |
| 3488 | * |
| 3489 | * This frees the memory allocated to the q_vectors and |
| 3490 | * deletes references to the NAPI struct. |
| 3491 | **/ |
| 3492 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) |
| 3493 | { |
| 3494 | int v_idx; |
| 3495 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3496 | for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) |
| 3497 | i40e_free_q_vector(vsi, v_idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | /** |
| 3501 | * i40e_reset_interrupt_capability - Disable interrupt setup in OS |
| 3502 | * @pf: board private structure |
| 3503 | **/ |
| 3504 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) |
| 3505 | { |
| 3506 | /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ |
| 3507 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 3508 | pci_disable_msix(pf->pdev); |
| 3509 | kfree(pf->msix_entries); |
| 3510 | pf->msix_entries = NULL; |
| 3511 | } else if (pf->flags & I40E_FLAG_MSI_ENABLED) { |
| 3512 | pci_disable_msi(pf->pdev); |
| 3513 | } |
| 3514 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); |
| 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3519 | * @pf: board private structure |
| 3520 | * |
| 3521 | * We go through and clear interrupt specific resources and reset the structure |
| 3522 | * to pre-load conditions |
| 3523 | **/ |
| 3524 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) |
| 3525 | { |
| 3526 | int i; |
| 3527 | |
| 3528 | i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); |
| 3529 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 3530 | if (pf->vsi[i]) |
| 3531 | i40e_vsi_free_q_vectors(pf->vsi[i]); |
| 3532 | i40e_reset_interrupt_capability(pf); |
| 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI |
| 3537 | * @vsi: the VSI being configured |
| 3538 | **/ |
| 3539 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) |
| 3540 | { |
| 3541 | int q_idx; |
| 3542 | |
| 3543 | if (!vsi->netdev) |
| 3544 | return; |
| 3545 | |
| 3546 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3547 | napi_enable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI |
| 3552 | * @vsi: the VSI being configured |
| 3553 | **/ |
| 3554 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) |
| 3555 | { |
| 3556 | int q_idx; |
| 3557 | |
| 3558 | if (!vsi->netdev) |
| 3559 | return; |
| 3560 | |
| 3561 | for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3562 | napi_disable(&vsi->q_vectors[q_idx]->napi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 3566 | * i40e_vsi_close - Shut down a VSI |
| 3567 | * @vsi: the vsi to be quelled |
| 3568 | **/ |
| 3569 | static void i40e_vsi_close(struct i40e_vsi *vsi) |
| 3570 | { |
| 3571 | if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) |
| 3572 | i40e_down(vsi); |
| 3573 | i40e_vsi_free_irq(vsi); |
| 3574 | i40e_vsi_free_tx_resources(vsi); |
| 3575 | i40e_vsi_free_rx_resources(vsi); |
| 3576 | } |
| 3577 | |
| 3578 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3579 | * i40e_quiesce_vsi - Pause a given VSI |
| 3580 | * @vsi: the VSI being paused |
| 3581 | **/ |
| 3582 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) |
| 3583 | { |
| 3584 | if (test_bit(__I40E_DOWN, &vsi->state)) |
| 3585 | return; |
| 3586 | |
| 3587 | set_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3588 | if (vsi->netdev && netif_running(vsi->netdev)) { |
| 3589 | vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); |
| 3590 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 3591 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | /** |
| 3596 | * i40e_unquiesce_vsi - Resume a given VSI |
| 3597 | * @vsi: the VSI being resumed |
| 3598 | **/ |
| 3599 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) |
| 3600 | { |
| 3601 | if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) |
| 3602 | return; |
| 3603 | |
| 3604 | clear_bit(__I40E_NEEDS_RESTART, &vsi->state); |
| 3605 | if (vsi->netdev && netif_running(vsi->netdev)) |
| 3606 | vsi->netdev->netdev_ops->ndo_open(vsi->netdev); |
| 3607 | else |
Shannon Nelson | 8276f75 | 2014-03-14 07:32:27 +0000 | [diff] [blame] | 3608 | i40e_vsi_open(vsi); /* this clears the DOWN bit */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF |
| 3613 | * @pf: the PF |
| 3614 | **/ |
| 3615 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) |
| 3616 | { |
| 3617 | int v; |
| 3618 | |
| 3619 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 3620 | if (pf->vsi[v]) |
| 3621 | i40e_quiesce_vsi(pf->vsi[v]); |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | /** |
| 3626 | * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF |
| 3627 | * @pf: the PF |
| 3628 | **/ |
| 3629 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) |
| 3630 | { |
| 3631 | int v; |
| 3632 | |
| 3633 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 3634 | if (pf->vsi[v]) |
| 3635 | i40e_unquiesce_vsi(pf->vsi[v]); |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | /** |
| 3640 | * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config |
| 3641 | * @dcbcfg: the corresponding DCBx configuration structure |
| 3642 | * |
| 3643 | * Return the number of TCs from given DCBx configuration |
| 3644 | **/ |
| 3645 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) |
| 3646 | { |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3647 | u8 num_tc = 0; |
| 3648 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3649 | |
| 3650 | /* Scan the ETS Config Priority Table to find |
| 3651 | * traffic class enabled for a given priority |
| 3652 | * and use the traffic class index to get the |
| 3653 | * number of traffic classes enabled |
| 3654 | */ |
| 3655 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 3656 | if (dcbcfg->etscfg.prioritytable[i] > num_tc) |
| 3657 | num_tc = dcbcfg->etscfg.prioritytable[i]; |
| 3658 | } |
| 3659 | |
| 3660 | /* Traffic class index starts from zero so |
| 3661 | * increment to return the actual count |
| 3662 | */ |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3663 | return num_tc + 1; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | /** |
| 3667 | * i40e_dcb_get_enabled_tc - Get enabled traffic classes |
| 3668 | * @dcbcfg: the corresponding DCBx configuration structure |
| 3669 | * |
| 3670 | * Query the current DCB configuration and return the number of |
| 3671 | * traffic classes enabled from the given DCBX config |
| 3672 | **/ |
| 3673 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) |
| 3674 | { |
| 3675 | u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); |
| 3676 | u8 enabled_tc = 1; |
| 3677 | u8 i; |
| 3678 | |
| 3679 | for (i = 0; i < num_tc; i++) |
| 3680 | enabled_tc |= 1 << i; |
| 3681 | |
| 3682 | return enabled_tc; |
| 3683 | } |
| 3684 | |
| 3685 | /** |
| 3686 | * i40e_pf_get_num_tc - Get enabled traffic classes for PF |
| 3687 | * @pf: PF being queried |
| 3688 | * |
| 3689 | * Return number of traffic classes enabled for the given PF |
| 3690 | **/ |
| 3691 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) |
| 3692 | { |
| 3693 | struct i40e_hw *hw = &pf->hw; |
| 3694 | u8 i, enabled_tc; |
| 3695 | u8 num_tc = 0; |
| 3696 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 3697 | |
| 3698 | /* If DCB is not enabled then always in single TC */ |
| 3699 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 3700 | return 1; |
| 3701 | |
| 3702 | /* MFP mode return count of enabled TCs for this PF */ |
| 3703 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 3704 | enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 3705 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3706 | if (enabled_tc & (1 << i)) |
| 3707 | num_tc++; |
| 3708 | } |
| 3709 | return num_tc; |
| 3710 | } |
| 3711 | |
| 3712 | /* SFP mode will be enabled for all TCs on port */ |
| 3713 | return i40e_dcb_get_num_tc(dcbcfg); |
| 3714 | } |
| 3715 | |
| 3716 | /** |
| 3717 | * i40e_pf_get_default_tc - Get bitmap for first enabled TC |
| 3718 | * @pf: PF being queried |
| 3719 | * |
| 3720 | * Return a bitmap for first enabled traffic class for this PF. |
| 3721 | **/ |
| 3722 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) |
| 3723 | { |
| 3724 | u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; |
| 3725 | u8 i = 0; |
| 3726 | |
| 3727 | if (!enabled_tc) |
| 3728 | return 0x1; /* TC0 */ |
| 3729 | |
| 3730 | /* Find the first enabled TC */ |
| 3731 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3732 | if (enabled_tc & (1 << i)) |
| 3733 | break; |
| 3734 | } |
| 3735 | |
| 3736 | return 1 << i; |
| 3737 | } |
| 3738 | |
| 3739 | /** |
| 3740 | * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes |
| 3741 | * @pf: PF being queried |
| 3742 | * |
| 3743 | * Return a bitmap for enabled traffic classes for this PF. |
| 3744 | **/ |
| 3745 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) |
| 3746 | { |
| 3747 | /* If DCB is not enabled for this PF then just return default TC */ |
| 3748 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) |
| 3749 | return i40e_pf_get_default_tc(pf); |
| 3750 | |
| 3751 | /* MFP mode will have enabled TCs set by FW */ |
| 3752 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 3753 | return pf->hw.func_caps.enabled_tcmap; |
| 3754 | |
| 3755 | /* SFP mode we want PF to be enabled for all TCs */ |
| 3756 | return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); |
| 3757 | } |
| 3758 | |
| 3759 | /** |
| 3760 | * i40e_vsi_get_bw_info - Query VSI BW Information |
| 3761 | * @vsi: the VSI being queried |
| 3762 | * |
| 3763 | * Returns 0 on success, negative value on failure |
| 3764 | **/ |
| 3765 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) |
| 3766 | { |
| 3767 | struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; |
| 3768 | struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; |
| 3769 | struct i40e_pf *pf = vsi->back; |
| 3770 | struct i40e_hw *hw = &pf->hw; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3771 | i40e_status aq_ret; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3772 | u32 tc_bw_max; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3773 | int i; |
| 3774 | |
| 3775 | /* Get the VSI level BW configuration */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3776 | aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); |
| 3777 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3778 | dev_info(&pf->pdev->dev, |
| 3779 | "couldn't get pf vsi bw config, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3780 | aq_ret, pf->hw.aq.asq_last_status); |
| 3781 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | /* Get the VSI level BW configuration per TC */ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3785 | aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, |
Jesse Brandeburg | 6838b53 | 2014-01-14 00:49:52 -0800 | [diff] [blame] | 3786 | NULL); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3787 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3788 | dev_info(&pf->pdev->dev, |
| 3789 | "couldn't get pf vsi ets bw config, err %d, aq_err %d\n", |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3790 | aq_ret, pf->hw.aq.asq_last_status); |
| 3791 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { |
| 3795 | dev_info(&pf->pdev->dev, |
| 3796 | "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", |
| 3797 | bw_config.tc_valid_bits, |
| 3798 | bw_ets_config.tc_valid_bits); |
| 3799 | /* Still continuing */ |
| 3800 | } |
| 3801 | |
| 3802 | vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); |
| 3803 | vsi->bw_max_quanta = bw_config.max_bw; |
| 3804 | tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | |
| 3805 | (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); |
| 3806 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3807 | vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; |
| 3808 | vsi->bw_ets_limit_credits[i] = |
| 3809 | le16_to_cpu(bw_ets_config.credits[i]); |
| 3810 | /* 3 bits out of 4 for each TC */ |
| 3811 | vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); |
| 3812 | } |
Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3813 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3814 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC |
| 3819 | * @vsi: the VSI being configured |
| 3820 | * @enabled_tc: TC bitmap |
| 3821 | * @bw_credits: BW shared credits per TC |
| 3822 | * |
| 3823 | * Returns 0 on success, negative value on failure |
| 3824 | **/ |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3825 | static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3826 | u8 *bw_share) |
| 3827 | { |
| 3828 | struct i40e_aqc_configure_vsi_tc_bw_data bw_data; |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3829 | i40e_status aq_ret; |
| 3830 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3831 | |
| 3832 | bw_data.tc_valid_bits = enabled_tc; |
| 3833 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 3834 | bw_data.tc_bw_credits[i] = bw_share[i]; |
| 3835 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3836 | aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, |
| 3837 | NULL); |
| 3838 | if (aq_ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3839 | dev_info(&vsi->back->pdev->dev, |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 3840 | "AQ command Config VSI BW allocation per TC failed = %d\n", |
| 3841 | vsi->back->hw.aq.asq_last_status); |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3842 | return -EINVAL; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) |
| 3846 | vsi->info.qs_handle[i] = bw_data.qs_handles[i]; |
| 3847 | |
Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3848 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration |
| 3853 | * @vsi: the VSI being configured |
| 3854 | * @enabled_tc: TC map to be enabled |
| 3855 | * |
| 3856 | **/ |
| 3857 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 3858 | { |
| 3859 | struct net_device *netdev = vsi->netdev; |
| 3860 | struct i40e_pf *pf = vsi->back; |
| 3861 | struct i40e_hw *hw = &pf->hw; |
| 3862 | u8 netdev_tc = 0; |
| 3863 | int i; |
| 3864 | struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; |
| 3865 | |
| 3866 | if (!netdev) |
| 3867 | return; |
| 3868 | |
| 3869 | if (!enabled_tc) { |
| 3870 | netdev_reset_tc(netdev); |
| 3871 | return; |
| 3872 | } |
| 3873 | |
| 3874 | /* Set up actual enabled TCs on the VSI */ |
| 3875 | if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) |
| 3876 | return; |
| 3877 | |
| 3878 | /* set per TC queues for the VSI */ |
| 3879 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3880 | /* Only set TC queues for enabled tcs |
| 3881 | * |
| 3882 | * e.g. For a VSI that has TC0 and TC3 enabled the |
| 3883 | * enabled_tc bitmap would be 0x00001001; the driver |
| 3884 | * will set the numtc for netdev as 2 that will be |
| 3885 | * referenced by the netdev layer as TC 0 and 1. |
| 3886 | */ |
| 3887 | if (vsi->tc_config.enabled_tc & (1 << i)) |
| 3888 | netdev_set_tc_queue(netdev, |
| 3889 | vsi->tc_config.tc_info[i].netdev_tc, |
| 3890 | vsi->tc_config.tc_info[i].qcount, |
| 3891 | vsi->tc_config.tc_info[i].qoffset); |
| 3892 | } |
| 3893 | |
| 3894 | /* Assign UP2TC map for the VSI */ |
| 3895 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 3896 | /* Get the actual TC# for the UP */ |
| 3897 | u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; |
| 3898 | /* Get the mapped netdev TC# for the UP */ |
| 3899 | netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc; |
| 3900 | netdev_set_prio_tc_map(netdev, i, netdev_tc); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map |
| 3906 | * @vsi: the VSI being configured |
| 3907 | * @ctxt: the ctxt buffer returned from AQ VSI update param command |
| 3908 | **/ |
| 3909 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, |
| 3910 | struct i40e_vsi_context *ctxt) |
| 3911 | { |
| 3912 | /* copy just the sections touched not the entire info |
| 3913 | * since not all sections are valid as returned by |
| 3914 | * update vsi params |
| 3915 | */ |
| 3916 | vsi->info.mapping_flags = ctxt->info.mapping_flags; |
| 3917 | memcpy(&vsi->info.queue_mapping, |
| 3918 | &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); |
| 3919 | memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, |
| 3920 | sizeof(vsi->info.tc_mapping)); |
| 3921 | } |
| 3922 | |
| 3923 | /** |
| 3924 | * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map |
| 3925 | * @vsi: VSI to be configured |
| 3926 | * @enabled_tc: TC bitmap |
| 3927 | * |
| 3928 | * This configures a particular VSI for TCs that are mapped to the |
| 3929 | * given TC bitmap. It uses default bandwidth share for TCs across |
| 3930 | * VSIs to configure TC for a particular VSI. |
| 3931 | * |
| 3932 | * NOTE: |
| 3933 | * It is expected that the VSI queues have been quisced before calling |
| 3934 | * this function. |
| 3935 | **/ |
| 3936 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) |
| 3937 | { |
| 3938 | u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; |
| 3939 | struct i40e_vsi_context ctxt; |
| 3940 | int ret = 0; |
| 3941 | int i; |
| 3942 | |
| 3943 | /* Check if enabled_tc is same as existing or new TCs */ |
| 3944 | if (vsi->tc_config.enabled_tc == enabled_tc) |
| 3945 | return ret; |
| 3946 | |
| 3947 | /* Enable ETS TCs with equal BW Share for now across all VSIs */ |
| 3948 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 3949 | if (enabled_tc & (1 << i)) |
| 3950 | bw_share[i] = 1; |
| 3951 | } |
| 3952 | |
| 3953 | ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); |
| 3954 | if (ret) { |
| 3955 | dev_info(&vsi->back->pdev->dev, |
| 3956 | "Failed configuring TC map %d for VSI %d\n", |
| 3957 | enabled_tc, vsi->seid); |
| 3958 | goto out; |
| 3959 | } |
| 3960 | |
| 3961 | /* Update Queue Pairs Mapping for currently enabled UPs */ |
| 3962 | ctxt.seid = vsi->seid; |
| 3963 | ctxt.pf_num = vsi->back->hw.pf_id; |
| 3964 | ctxt.vf_num = 0; |
| 3965 | ctxt.uplink_seid = vsi->uplink_seid; |
| 3966 | memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); |
| 3967 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 3968 | |
| 3969 | /* Update the VSI after updating the VSI queue-mapping information */ |
| 3970 | ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); |
| 3971 | if (ret) { |
| 3972 | dev_info(&vsi->back->pdev->dev, |
| 3973 | "update vsi failed, aq_err=%d\n", |
| 3974 | vsi->back->hw.aq.asq_last_status); |
| 3975 | goto out; |
| 3976 | } |
| 3977 | /* update the local VSI info with updated queue map */ |
| 3978 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 3979 | vsi->info.valid_sections = 0; |
| 3980 | |
| 3981 | /* Update current VSI BW information */ |
| 3982 | ret = i40e_vsi_get_bw_info(vsi); |
| 3983 | if (ret) { |
| 3984 | dev_info(&vsi->back->pdev->dev, |
| 3985 | "Failed updating vsi bw info, aq_err=%d\n", |
| 3986 | vsi->back->hw.aq.asq_last_status); |
| 3987 | goto out; |
| 3988 | } |
| 3989 | |
| 3990 | /* Update the netdev TC setup */ |
| 3991 | i40e_vsi_config_netdev_tc(vsi, enabled_tc); |
| 3992 | out: |
| 3993 | return ret; |
| 3994 | } |
| 3995 | |
| 3996 | /** |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 3997 | * i40e_veb_config_tc - Configure TCs for given VEB |
| 3998 | * @veb: given VEB |
| 3999 | * @enabled_tc: TC bitmap |
| 4000 | * |
| 4001 | * Configures given TC bitmap for VEB (switching) element |
| 4002 | **/ |
| 4003 | int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc) |
| 4004 | { |
| 4005 | struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0}; |
| 4006 | struct i40e_pf *pf = veb->pf; |
| 4007 | int ret = 0; |
| 4008 | int i; |
| 4009 | |
| 4010 | /* No TCs or already enabled TCs just return */ |
| 4011 | if (!enabled_tc || veb->enabled_tc == enabled_tc) |
| 4012 | return ret; |
| 4013 | |
| 4014 | bw_data.tc_valid_bits = enabled_tc; |
| 4015 | /* bw_data.absolute_credits is not set (relative) */ |
| 4016 | |
| 4017 | /* Enable ETS TCs with equal BW Share for now */ |
| 4018 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 4019 | if (enabled_tc & (1 << i)) |
| 4020 | bw_data.tc_bw_share_credits[i] = 1; |
| 4021 | } |
| 4022 | |
| 4023 | ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid, |
| 4024 | &bw_data, NULL); |
| 4025 | if (ret) { |
| 4026 | dev_info(&pf->pdev->dev, |
| 4027 | "veb bw config failed, aq_err=%d\n", |
| 4028 | pf->hw.aq.asq_last_status); |
| 4029 | goto out; |
| 4030 | } |
| 4031 | |
| 4032 | /* Update the BW information */ |
| 4033 | ret = i40e_veb_get_bw_info(veb); |
| 4034 | if (ret) { |
| 4035 | dev_info(&pf->pdev->dev, |
| 4036 | "Failed getting veb bw config, aq_err=%d\n", |
| 4037 | pf->hw.aq.asq_last_status); |
| 4038 | } |
| 4039 | |
| 4040 | out: |
| 4041 | return ret; |
| 4042 | } |
| 4043 | |
| 4044 | #ifdef CONFIG_I40E_DCB |
| 4045 | /** |
| 4046 | * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs |
| 4047 | * @pf: PF struct |
| 4048 | * |
| 4049 | * Reconfigure VEB/VSIs on a given PF; it is assumed that |
| 4050 | * the caller would've quiesce all the VSIs before calling |
| 4051 | * this function |
| 4052 | **/ |
| 4053 | static void i40e_dcb_reconfigure(struct i40e_pf *pf) |
| 4054 | { |
| 4055 | u8 tc_map = 0; |
| 4056 | int ret; |
| 4057 | u8 v; |
| 4058 | |
| 4059 | /* Enable the TCs available on PF to all VEBs */ |
| 4060 | tc_map = i40e_pf_get_tc_map(pf); |
| 4061 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 4062 | if (!pf->veb[v]) |
| 4063 | continue; |
| 4064 | ret = i40e_veb_config_tc(pf->veb[v], tc_map); |
| 4065 | if (ret) { |
| 4066 | dev_info(&pf->pdev->dev, |
| 4067 | "Failed configuring TC for VEB seid=%d\n", |
| 4068 | pf->veb[v]->seid); |
| 4069 | /* Will try to configure as many components */ |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | /* Update each VSI */ |
| 4074 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4075 | if (!pf->vsi[v]) |
| 4076 | continue; |
| 4077 | |
| 4078 | /* - Enable all TCs for the LAN VSI |
| 4079 | * - For all others keep them at TC0 for now |
| 4080 | */ |
| 4081 | if (v == pf->lan_vsi) |
| 4082 | tc_map = i40e_pf_get_tc_map(pf); |
| 4083 | else |
| 4084 | tc_map = i40e_pf_get_default_tc(pf); |
| 4085 | |
| 4086 | ret = i40e_vsi_config_tc(pf->vsi[v], tc_map); |
| 4087 | if (ret) { |
| 4088 | dev_info(&pf->pdev->dev, |
| 4089 | "Failed configuring TC for VSI seid=%d\n", |
| 4090 | pf->vsi[v]->seid); |
| 4091 | /* Will try to configure as many components */ |
| 4092 | } else { |
Neerav Parikh | 0672a09 | 2014-04-01 07:11:47 +0000 | [diff] [blame] | 4093 | /* Re-configure VSI vectors based on updated TC map */ |
| 4094 | i40e_vsi_map_rings_to_vectors(pf->vsi[v]); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4095 | if (pf->vsi[v]->netdev) |
| 4096 | i40e_dcbnl_set_all(pf->vsi[v]); |
| 4097 | } |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * i40e_init_pf_dcb - Initialize DCB configuration |
| 4103 | * @pf: PF being configured |
| 4104 | * |
| 4105 | * Query the current DCB configuration and cache it |
| 4106 | * in the hardware structure |
| 4107 | **/ |
| 4108 | static int i40e_init_pf_dcb(struct i40e_pf *pf) |
| 4109 | { |
| 4110 | struct i40e_hw *hw = &pf->hw; |
| 4111 | int err = 0; |
| 4112 | |
| 4113 | if (pf->hw.func_caps.npar_enable) |
| 4114 | goto out; |
| 4115 | |
| 4116 | /* Get the initial DCB configuration */ |
| 4117 | err = i40e_init_dcb(hw); |
| 4118 | if (!err) { |
| 4119 | /* Device/Function is not DCBX capable */ |
| 4120 | if ((!hw->func_caps.dcb) || |
| 4121 | (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) { |
| 4122 | dev_info(&pf->pdev->dev, |
| 4123 | "DCBX offload is not supported or is disabled for this PF.\n"); |
| 4124 | |
| 4125 | if (pf->flags & I40E_FLAG_MFP_ENABLED) |
| 4126 | goto out; |
| 4127 | |
| 4128 | } else { |
| 4129 | /* When status is not DISABLED then DCBX in FW */ |
| 4130 | pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED | |
| 4131 | DCB_CAP_DCBX_VER_IEEE; |
| 4132 | pf->flags |= I40E_FLAG_DCB_ENABLED; |
| 4133 | } |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 4134 | } else { |
| 4135 | dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n", |
| 4136 | pf->hw.aq.asq_last_status); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | out: |
| 4140 | return err; |
| 4141 | } |
| 4142 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4143 | #define SPEED_SIZE 14 |
| 4144 | #define FC_SIZE 8 |
| 4145 | /** |
| 4146 | * i40e_print_link_message - print link up or down |
| 4147 | * @vsi: the VSI for which link needs a message |
| 4148 | */ |
| 4149 | static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup) |
| 4150 | { |
| 4151 | char speed[SPEED_SIZE] = "Unknown"; |
| 4152 | char fc[FC_SIZE] = "RX/TX"; |
| 4153 | |
| 4154 | if (!isup) { |
| 4155 | netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| 4156 | return; |
| 4157 | } |
| 4158 | |
| 4159 | switch (vsi->back->hw.phy.link_info.link_speed) { |
| 4160 | case I40E_LINK_SPEED_40GB: |
| 4161 | strncpy(speed, "40 Gbps", SPEED_SIZE); |
| 4162 | break; |
| 4163 | case I40E_LINK_SPEED_10GB: |
| 4164 | strncpy(speed, "10 Gbps", SPEED_SIZE); |
| 4165 | break; |
| 4166 | case I40E_LINK_SPEED_1GB: |
| 4167 | strncpy(speed, "1000 Mbps", SPEED_SIZE); |
| 4168 | break; |
| 4169 | default: |
| 4170 | break; |
| 4171 | } |
| 4172 | |
| 4173 | switch (vsi->back->hw.fc.current_mode) { |
| 4174 | case I40E_FC_FULL: |
| 4175 | strncpy(fc, "RX/TX", FC_SIZE); |
| 4176 | break; |
| 4177 | case I40E_FC_TX_PAUSE: |
| 4178 | strncpy(fc, "TX", FC_SIZE); |
| 4179 | break; |
| 4180 | case I40E_FC_RX_PAUSE: |
| 4181 | strncpy(fc, "RX", FC_SIZE); |
| 4182 | break; |
| 4183 | default: |
| 4184 | strncpy(fc, "None", FC_SIZE); |
| 4185 | break; |
| 4186 | } |
| 4187 | |
| 4188 | netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n", |
| 4189 | speed, fc); |
| 4190 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4191 | |
| 4192 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4193 | * i40e_up_complete - Finish the last steps of bringing up a connection |
| 4194 | * @vsi: the VSI being configured |
| 4195 | **/ |
| 4196 | static int i40e_up_complete(struct i40e_vsi *vsi) |
| 4197 | { |
| 4198 | struct i40e_pf *pf = vsi->back; |
| 4199 | int err; |
| 4200 | |
| 4201 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 4202 | i40e_vsi_configure_msix(vsi); |
| 4203 | else |
| 4204 | i40e_configure_msi_and_legacy(vsi); |
| 4205 | |
| 4206 | /* start rings */ |
| 4207 | err = i40e_vsi_control_rings(vsi, true); |
| 4208 | if (err) |
| 4209 | return err; |
| 4210 | |
| 4211 | clear_bit(__I40E_DOWN, &vsi->state); |
| 4212 | i40e_napi_enable_all(vsi); |
| 4213 | i40e_vsi_enable_irq(vsi); |
| 4214 | |
| 4215 | if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && |
| 4216 | (vsi->netdev)) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4217 | i40e_print_link_message(vsi, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4218 | netif_tx_start_all_queues(vsi->netdev); |
| 4219 | netif_carrier_on(vsi->netdev); |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4220 | } else if (vsi->netdev) { |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4221 | i40e_print_link_message(vsi, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4222 | } |
Anjali Singhai Jain | ca64fa4 | 2014-02-11 08:26:30 +0000 | [diff] [blame] | 4223 | |
| 4224 | /* replay FDIR SB filters */ |
| 4225 | if (vsi->type == I40E_VSI_FDIR) |
| 4226 | i40e_fdir_filter_restore(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4227 | i40e_service_event_schedule(pf); |
| 4228 | |
| 4229 | return 0; |
| 4230 | } |
| 4231 | |
| 4232 | /** |
| 4233 | * i40e_vsi_reinit_locked - Reset the VSI |
| 4234 | * @vsi: the VSI being configured |
| 4235 | * |
| 4236 | * Rebuild the ring structs after some configuration |
| 4237 | * has changed, e.g. MTU size. |
| 4238 | **/ |
| 4239 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) |
| 4240 | { |
| 4241 | struct i40e_pf *pf = vsi->back; |
| 4242 | |
| 4243 | WARN_ON(in_interrupt()); |
| 4244 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4245 | usleep_range(1000, 2000); |
| 4246 | i40e_down(vsi); |
| 4247 | |
| 4248 | /* Give a VF some time to respond to the reset. The |
| 4249 | * two second wait is based upon the watchdog cycle in |
| 4250 | * the VF driver. |
| 4251 | */ |
| 4252 | if (vsi->type == I40E_VSI_SRIOV) |
| 4253 | msleep(2000); |
| 4254 | i40e_up(vsi); |
| 4255 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 4256 | } |
| 4257 | |
| 4258 | /** |
| 4259 | * i40e_up - Bring the connection back up after being down |
| 4260 | * @vsi: the VSI being configured |
| 4261 | **/ |
| 4262 | int i40e_up(struct i40e_vsi *vsi) |
| 4263 | { |
| 4264 | int err; |
| 4265 | |
| 4266 | err = i40e_vsi_configure(vsi); |
| 4267 | if (!err) |
| 4268 | err = i40e_up_complete(vsi); |
| 4269 | |
| 4270 | return err; |
| 4271 | } |
| 4272 | |
| 4273 | /** |
| 4274 | * i40e_down - Shutdown the connection processing |
| 4275 | * @vsi: the VSI being stopped |
| 4276 | **/ |
| 4277 | void i40e_down(struct i40e_vsi *vsi) |
| 4278 | { |
| 4279 | int i; |
| 4280 | |
| 4281 | /* It is assumed that the caller of this function |
| 4282 | * sets the vsi->state __I40E_DOWN bit. |
| 4283 | */ |
| 4284 | if (vsi->netdev) { |
| 4285 | netif_carrier_off(vsi->netdev); |
| 4286 | netif_tx_disable(vsi->netdev); |
| 4287 | } |
| 4288 | i40e_vsi_disable_irq(vsi); |
| 4289 | i40e_vsi_control_rings(vsi, false); |
| 4290 | i40e_napi_disable_all(vsi); |
| 4291 | |
| 4292 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4293 | i40e_clean_tx_ring(vsi->tx_rings[i]); |
| 4294 | i40e_clean_rx_ring(vsi->rx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | /** |
| 4299 | * i40e_setup_tc - configure multiple traffic classes |
| 4300 | * @netdev: net device to configure |
| 4301 | * @tc: number of traffic classes to enable |
| 4302 | **/ |
| 4303 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) |
| 4304 | { |
| 4305 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4306 | struct i40e_vsi *vsi = np->vsi; |
| 4307 | struct i40e_pf *pf = vsi->back; |
| 4308 | u8 enabled_tc = 0; |
| 4309 | int ret = -EINVAL; |
| 4310 | int i; |
| 4311 | |
| 4312 | /* Check if DCB enabled to continue */ |
| 4313 | if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { |
| 4314 | netdev_info(netdev, "DCB is not enabled for adapter\n"); |
| 4315 | goto exit; |
| 4316 | } |
| 4317 | |
| 4318 | /* Check if MFP enabled */ |
| 4319 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 4320 | netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); |
| 4321 | goto exit; |
| 4322 | } |
| 4323 | |
| 4324 | /* Check whether tc count is within enabled limit */ |
| 4325 | if (tc > i40e_pf_get_num_tc(pf)) { |
| 4326 | netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); |
| 4327 | goto exit; |
| 4328 | } |
| 4329 | |
| 4330 | /* Generate TC map for number of tc requested */ |
| 4331 | for (i = 0; i < tc; i++) |
| 4332 | enabled_tc |= (1 << i); |
| 4333 | |
| 4334 | /* Requesting same TC configuration as already enabled */ |
| 4335 | if (enabled_tc == vsi->tc_config.enabled_tc) |
| 4336 | return 0; |
| 4337 | |
| 4338 | /* Quiesce VSI queues */ |
| 4339 | i40e_quiesce_vsi(vsi); |
| 4340 | |
| 4341 | /* Configure VSI for enabled TCs */ |
| 4342 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 4343 | if (ret) { |
| 4344 | netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", |
| 4345 | vsi->seid); |
| 4346 | goto exit; |
| 4347 | } |
| 4348 | |
| 4349 | /* Unquiesce VSI */ |
| 4350 | i40e_unquiesce_vsi(vsi); |
| 4351 | |
| 4352 | exit: |
| 4353 | return ret; |
| 4354 | } |
| 4355 | |
| 4356 | /** |
| 4357 | * i40e_open - Called when a network interface is made active |
| 4358 | * @netdev: network interface device structure |
| 4359 | * |
| 4360 | * The open entry point is called when a network interface is made |
| 4361 | * active by the system (IFF_UP). At this point all resources needed |
| 4362 | * for transmit and receive operations are allocated, the interrupt |
| 4363 | * handler is registered with the OS, the netdev watchdog subtask is |
| 4364 | * enabled, and the stack is notified that the interface is ready. |
| 4365 | * |
| 4366 | * Returns 0 on success, negative value on failure |
| 4367 | **/ |
| 4368 | static int i40e_open(struct net_device *netdev) |
| 4369 | { |
| 4370 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4371 | struct i40e_vsi *vsi = np->vsi; |
| 4372 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4373 | int err; |
| 4374 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 4375 | /* disallow open during test or if eeprom is broken */ |
| 4376 | if (test_bit(__I40E_TESTING, &pf->state) || |
| 4377 | test_bit(__I40E_BAD_EEPROM, &pf->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4378 | return -EBUSY; |
| 4379 | |
| 4380 | netif_carrier_off(netdev); |
| 4381 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4382 | err = i40e_vsi_open(vsi); |
| 4383 | if (err) |
| 4384 | return err; |
| 4385 | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 4386 | /* configure global TSO hardware offload settings */ |
| 4387 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH | |
| 4388 | TCP_FLAG_FIN) >> 16); |
| 4389 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH | |
| 4390 | TCP_FLAG_FIN | |
| 4391 | TCP_FLAG_CWR) >> 16); |
| 4392 | wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16); |
| 4393 | |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4394 | #ifdef CONFIG_I40E_VXLAN |
| 4395 | vxlan_get_rx_port(netdev); |
| 4396 | #endif |
| 4397 | |
| 4398 | return 0; |
| 4399 | } |
| 4400 | |
| 4401 | /** |
| 4402 | * i40e_vsi_open - |
| 4403 | * @vsi: the VSI to open |
| 4404 | * |
| 4405 | * Finish initialization of the VSI. |
| 4406 | * |
| 4407 | * Returns 0 on success, negative value on failure |
| 4408 | **/ |
| 4409 | int i40e_vsi_open(struct i40e_vsi *vsi) |
| 4410 | { |
| 4411 | struct i40e_pf *pf = vsi->back; |
| 4412 | char int_name[IFNAMSIZ]; |
| 4413 | int err; |
| 4414 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4415 | /* allocate descriptors */ |
| 4416 | err = i40e_vsi_setup_tx_resources(vsi); |
| 4417 | if (err) |
| 4418 | goto err_setup_tx; |
| 4419 | err = i40e_vsi_setup_rx_resources(vsi); |
| 4420 | if (err) |
| 4421 | goto err_setup_rx; |
| 4422 | |
| 4423 | err = i40e_vsi_configure(vsi); |
| 4424 | if (err) |
| 4425 | goto err_setup_rx; |
| 4426 | |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 4427 | if (vsi->netdev) { |
| 4428 | snprintf(int_name, sizeof(int_name) - 1, "%s-%s", |
| 4429 | dev_driver_string(&pf->pdev->dev), vsi->netdev->name); |
| 4430 | err = i40e_vsi_request_irq(vsi, int_name); |
| 4431 | if (err) |
| 4432 | goto err_setup_rx; |
| 4433 | |
| 4434 | /* Notify the stack of the actual queue counts. */ |
| 4435 | err = netif_set_real_num_tx_queues(vsi->netdev, |
| 4436 | vsi->num_queue_pairs); |
| 4437 | if (err) |
| 4438 | goto err_set_queues; |
| 4439 | |
| 4440 | err = netif_set_real_num_rx_queues(vsi->netdev, |
| 4441 | vsi->num_queue_pairs); |
| 4442 | if (err) |
| 4443 | goto err_set_queues; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 4444 | |
| 4445 | } else if (vsi->type == I40E_VSI_FDIR) { |
| 4446 | snprintf(int_name, sizeof(int_name) - 1, "%s-fdir", |
| 4447 | dev_driver_string(&pf->pdev->dev)); |
| 4448 | err = i40e_vsi_request_irq(vsi, int_name); |
Shannon Nelson | c22e3c6 | 2014-03-14 07:32:25 +0000 | [diff] [blame] | 4449 | } else { |
Jean Sacren | ce9ccb1 | 2014-05-01 14:31:18 +0000 | [diff] [blame] | 4450 | err = -EINVAL; |
Elizabeth Kappler | 6c167f5 | 2014-02-15 07:41:38 +0000 | [diff] [blame] | 4451 | goto err_setup_rx; |
| 4452 | } |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 4453 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4454 | err = i40e_up_complete(vsi); |
| 4455 | if (err) |
| 4456 | goto err_up_complete; |
| 4457 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4458 | return 0; |
| 4459 | |
| 4460 | err_up_complete: |
| 4461 | i40e_down(vsi); |
Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 4462 | err_set_queues: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4463 | i40e_vsi_free_irq(vsi); |
| 4464 | err_setup_rx: |
| 4465 | i40e_vsi_free_rx_resources(vsi); |
| 4466 | err_setup_tx: |
| 4467 | i40e_vsi_free_tx_resources(vsi); |
| 4468 | if (vsi == pf->vsi[pf->lan_vsi]) |
| 4469 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
| 4470 | |
| 4471 | return err; |
| 4472 | } |
| 4473 | |
| 4474 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 4475 | * i40e_fdir_filter_exit - Cleans up the Flow Director accounting |
| 4476 | * @pf: Pointer to pf |
| 4477 | * |
| 4478 | * This function destroys the hlist where all the Flow Director |
| 4479 | * filters were saved. |
| 4480 | **/ |
| 4481 | static void i40e_fdir_filter_exit(struct i40e_pf *pf) |
| 4482 | { |
| 4483 | struct i40e_fdir_filter *filter; |
| 4484 | struct hlist_node *node2; |
| 4485 | |
| 4486 | hlist_for_each_entry_safe(filter, node2, |
| 4487 | &pf->fdir_filter_list, fdir_node) { |
| 4488 | hlist_del(&filter->fdir_node); |
| 4489 | kfree(filter); |
| 4490 | } |
| 4491 | pf->fdir_pf_active_filters = 0; |
| 4492 | } |
| 4493 | |
| 4494 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4495 | * i40e_close - Disables a network interface |
| 4496 | * @netdev: network interface device structure |
| 4497 | * |
| 4498 | * The close entry point is called when an interface is de-activated |
| 4499 | * by the OS. The hardware is still under the driver's control, but |
| 4500 | * this netdev interface is disabled. |
| 4501 | * |
| 4502 | * Returns 0, this is not allowed to fail |
| 4503 | **/ |
| 4504 | static int i40e_close(struct net_device *netdev) |
| 4505 | { |
| 4506 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 4507 | struct i40e_vsi *vsi = np->vsi; |
| 4508 | |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 4509 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4510 | |
| 4511 | return 0; |
| 4512 | } |
| 4513 | |
| 4514 | /** |
| 4515 | * i40e_do_reset - Start a PF or Core Reset sequence |
| 4516 | * @pf: board private structure |
| 4517 | * @reset_flags: which reset is requested |
| 4518 | * |
| 4519 | * The essential difference in resets is that the PF Reset |
| 4520 | * doesn't clear the packet buffers, doesn't reset the PE |
| 4521 | * firmware, and doesn't bother the other PFs on the chip. |
| 4522 | **/ |
| 4523 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) |
| 4524 | { |
| 4525 | u32 val; |
| 4526 | |
| 4527 | WARN_ON(in_interrupt()); |
| 4528 | |
Mitch Williams | 263fc48 | 2014-04-23 04:50:11 +0000 | [diff] [blame] | 4529 | if (i40e_check_asq_alive(&pf->hw)) |
| 4530 | i40e_vc_notify_reset(pf); |
| 4531 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4532 | /* do the biggest reset indicated */ |
| 4533 | if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) { |
| 4534 | |
| 4535 | /* Request a Global Reset |
| 4536 | * |
| 4537 | * This will start the chip's countdown to the actual full |
| 4538 | * chip reset event, and a warning interrupt to be sent |
| 4539 | * to all PFs, including the requestor. Our handler |
| 4540 | * for the warning interrupt will deal with the shutdown |
| 4541 | * and recovery of the switch setup. |
| 4542 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4543 | dev_dbg(&pf->pdev->dev, "GlobalR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4544 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4545 | val |= I40E_GLGEN_RTRIG_GLOBR_MASK; |
| 4546 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4547 | |
| 4548 | } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) { |
| 4549 | |
| 4550 | /* Request a Core Reset |
| 4551 | * |
| 4552 | * Same as Global Reset, except does *not* include the MAC/PHY |
| 4553 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4554 | dev_dbg(&pf->pdev->dev, "CoreR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4555 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4556 | val |= I40E_GLGEN_RTRIG_CORER_MASK; |
| 4557 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4558 | i40e_flush(&pf->hw); |
| 4559 | |
Shannon Nelson | 7823fe3 | 2013-11-16 10:00:45 +0000 | [diff] [blame] | 4560 | } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) { |
| 4561 | |
| 4562 | /* Request a Firmware Reset |
| 4563 | * |
| 4564 | * Same as Global reset, plus restarting the |
| 4565 | * embedded firmware engine. |
| 4566 | */ |
| 4567 | /* enable EMP Reset */ |
| 4568 | val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP); |
| 4569 | val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK; |
| 4570 | wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val); |
| 4571 | |
| 4572 | /* force the reset */ |
| 4573 | val = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 4574 | val |= I40E_GLGEN_RTRIG_EMPFWR_MASK; |
| 4575 | wr32(&pf->hw, I40E_GLGEN_RTRIG, val); |
| 4576 | i40e_flush(&pf->hw); |
| 4577 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4578 | } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) { |
| 4579 | |
| 4580 | /* Request a PF Reset |
| 4581 | * |
| 4582 | * Resets only the PF-specific registers |
| 4583 | * |
| 4584 | * This goes directly to the tear-down and rebuild of |
| 4585 | * the switch, since we need to do all the recovery as |
| 4586 | * for the Core Reset. |
| 4587 | */ |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4588 | dev_dbg(&pf->pdev->dev, "PFR requested\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4589 | i40e_handle_reset_warning(pf); |
| 4590 | |
| 4591 | } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) { |
| 4592 | int v; |
| 4593 | |
| 4594 | /* Find the VSI(s) that requested a re-init */ |
| 4595 | dev_info(&pf->pdev->dev, |
| 4596 | "VSI reinit requested\n"); |
| 4597 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4598 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4599 | if (vsi != NULL && |
| 4600 | test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { |
| 4601 | i40e_vsi_reinit_locked(pf->vsi[v]); |
| 4602 | clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | /* no further action needed, so return now */ |
| 4607 | return; |
| 4608 | } else { |
| 4609 | dev_info(&pf->pdev->dev, |
| 4610 | "bad reset request 0x%08x\n", reset_flags); |
| 4611 | return; |
| 4612 | } |
| 4613 | } |
| 4614 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4615 | #ifdef CONFIG_I40E_DCB |
| 4616 | /** |
| 4617 | * i40e_dcb_need_reconfig - Check if DCB needs reconfig |
| 4618 | * @pf: board private structure |
| 4619 | * @old_cfg: current DCB config |
| 4620 | * @new_cfg: new DCB config |
| 4621 | **/ |
| 4622 | bool i40e_dcb_need_reconfig(struct i40e_pf *pf, |
| 4623 | struct i40e_dcbx_config *old_cfg, |
| 4624 | struct i40e_dcbx_config *new_cfg) |
| 4625 | { |
| 4626 | bool need_reconfig = false; |
| 4627 | |
| 4628 | /* Check if ETS configuration has changed */ |
| 4629 | if (memcmp(&new_cfg->etscfg, |
| 4630 | &old_cfg->etscfg, |
| 4631 | sizeof(new_cfg->etscfg))) { |
| 4632 | /* If Priority Table has changed reconfig is needed */ |
| 4633 | if (memcmp(&new_cfg->etscfg.prioritytable, |
| 4634 | &old_cfg->etscfg.prioritytable, |
| 4635 | sizeof(new_cfg->etscfg.prioritytable))) { |
| 4636 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4637 | dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | if (memcmp(&new_cfg->etscfg.tcbwtable, |
| 4641 | &old_cfg->etscfg.tcbwtable, |
| 4642 | sizeof(new_cfg->etscfg.tcbwtable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4643 | dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4644 | |
| 4645 | if (memcmp(&new_cfg->etscfg.tsatable, |
| 4646 | &old_cfg->etscfg.tsatable, |
| 4647 | sizeof(new_cfg->etscfg.tsatable))) |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4648 | dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | /* Check if PFC configuration has changed */ |
| 4652 | if (memcmp(&new_cfg->pfc, |
| 4653 | &old_cfg->pfc, |
| 4654 | sizeof(new_cfg->pfc))) { |
| 4655 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4656 | dev_dbg(&pf->pdev->dev, "PFC config change detected.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | /* Check if APP Table has changed */ |
| 4660 | if (memcmp(&new_cfg->app, |
| 4661 | &old_cfg->app, |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 4662 | sizeof(new_cfg->app))) { |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4663 | need_reconfig = true; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4664 | dev_dbg(&pf->pdev->dev, "APP Table change detected.\n"); |
Dave Jones | 3d9667a | 2014-01-27 23:11:09 -0500 | [diff] [blame] | 4665 | } |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4666 | |
| 4667 | return need_reconfig; |
| 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * i40e_handle_lldp_event - Handle LLDP Change MIB event |
| 4672 | * @pf: board private structure |
| 4673 | * @e: event info posted on ARQ |
| 4674 | **/ |
| 4675 | static int i40e_handle_lldp_event(struct i40e_pf *pf, |
| 4676 | struct i40e_arq_event_info *e) |
| 4677 | { |
| 4678 | struct i40e_aqc_lldp_get_mib *mib = |
| 4679 | (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw; |
| 4680 | struct i40e_hw *hw = &pf->hw; |
| 4681 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; |
| 4682 | struct i40e_dcbx_config tmp_dcbx_cfg; |
| 4683 | bool need_reconfig = false; |
| 4684 | int ret = 0; |
| 4685 | u8 type; |
| 4686 | |
| 4687 | /* Ignore if event is not for Nearest Bridge */ |
| 4688 | type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) |
| 4689 | & I40E_AQ_LLDP_BRIDGE_TYPE_MASK); |
| 4690 | if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE) |
| 4691 | return ret; |
| 4692 | |
| 4693 | /* Check MIB Type and return if event for Remote MIB update */ |
| 4694 | type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK; |
| 4695 | if (type == I40E_AQ_LLDP_MIB_REMOTE) { |
| 4696 | /* Update the remote cached instance and return */ |
| 4697 | ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE, |
| 4698 | I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE, |
| 4699 | &hw->remote_dcbx_config); |
| 4700 | goto exit; |
| 4701 | } |
| 4702 | |
| 4703 | /* Convert/store the DCBX data from LLDPDU temporarily */ |
| 4704 | memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg)); |
| 4705 | ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg); |
| 4706 | if (ret) { |
| 4707 | /* Error in LLDPDU parsing return */ |
| 4708 | dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n"); |
| 4709 | goto exit; |
| 4710 | } |
| 4711 | |
| 4712 | /* No change detected in DCBX configs */ |
| 4713 | if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4714 | dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 4715 | goto exit; |
| 4716 | } |
| 4717 | |
| 4718 | need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg); |
| 4719 | |
| 4720 | i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg); |
| 4721 | |
| 4722 | /* Overwrite the new configuration */ |
| 4723 | *dcbx_cfg = tmp_dcbx_cfg; |
| 4724 | |
| 4725 | if (!need_reconfig) |
| 4726 | goto exit; |
| 4727 | |
| 4728 | /* Reconfiguration needed quiesce all VSIs */ |
| 4729 | i40e_pf_quiesce_all_vsi(pf); |
| 4730 | |
| 4731 | /* Changes in configuration update VEB/VSI */ |
| 4732 | i40e_dcb_reconfigure(pf); |
| 4733 | |
| 4734 | i40e_pf_unquiesce_all_vsi(pf); |
| 4735 | exit: |
| 4736 | return ret; |
| 4737 | } |
| 4738 | #endif /* CONFIG_I40E_DCB */ |
| 4739 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4740 | /** |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 4741 | * i40e_do_reset_safe - Protected reset path for userland calls. |
| 4742 | * @pf: board private structure |
| 4743 | * @reset_flags: which reset is requested |
| 4744 | * |
| 4745 | **/ |
| 4746 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) |
| 4747 | { |
| 4748 | rtnl_lock(); |
| 4749 | i40e_do_reset(pf, reset_flags); |
| 4750 | rtnl_unlock(); |
| 4751 | } |
| 4752 | |
| 4753 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4754 | * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event |
| 4755 | * @pf: board private structure |
| 4756 | * @e: event info posted on ARQ |
| 4757 | * |
| 4758 | * Handler for LAN Queue Overflow Event generated by the firmware for PF |
| 4759 | * and VF queues |
| 4760 | **/ |
| 4761 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, |
| 4762 | struct i40e_arq_event_info *e) |
| 4763 | { |
| 4764 | struct i40e_aqc_lan_overflow *data = |
| 4765 | (struct i40e_aqc_lan_overflow *)&e->desc.params.raw; |
| 4766 | u32 queue = le32_to_cpu(data->prtdcb_rupto); |
| 4767 | u32 qtx_ctl = le32_to_cpu(data->otx_ctl); |
| 4768 | struct i40e_hw *hw = &pf->hw; |
| 4769 | struct i40e_vf *vf; |
| 4770 | u16 vf_id; |
| 4771 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 4772 | dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n", |
| 4773 | queue, qtx_ctl); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4774 | |
| 4775 | /* Queue belongs to VF, find the VF and issue VF reset */ |
| 4776 | if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) |
| 4777 | >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { |
| 4778 | vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) |
| 4779 | >> I40E_QTX_CTL_VFVM_INDX_SHIFT); |
| 4780 | vf_id -= hw->func_caps.vf_base_id; |
| 4781 | vf = &pf->vf[vf_id]; |
| 4782 | i40e_vc_notify_vf_reset(vf); |
| 4783 | /* Allow VF to process pending reset notification */ |
| 4784 | msleep(20); |
| 4785 | i40e_reset_vf(vf, false); |
| 4786 | } |
| 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * i40e_service_event_complete - Finish up the service event |
| 4791 | * @pf: board private structure |
| 4792 | **/ |
| 4793 | static void i40e_service_event_complete(struct i40e_pf *pf) |
| 4794 | { |
| 4795 | BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); |
| 4796 | |
| 4797 | /* flush memory to make sure state is correct before next watchog */ |
| 4798 | smp_mb__before_clear_bit(); |
| 4799 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 4800 | } |
| 4801 | |
| 4802 | /** |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 4803 | * i40e_get_current_fd_count - Get the count of FD filters programmed in the HW |
| 4804 | * @pf: board private structure |
| 4805 | **/ |
| 4806 | int i40e_get_current_fd_count(struct i40e_pf *pf) |
| 4807 | { |
| 4808 | int val, fcnt_prog; |
| 4809 | val = rd32(&pf->hw, I40E_PFQF_FDSTAT); |
| 4810 | fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) + |
| 4811 | ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >> |
| 4812 | I40E_PFQF_FDSTAT_BEST_CNT_SHIFT); |
| 4813 | return fcnt_prog; |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled |
| 4818 | * @pf: board private structure |
| 4819 | **/ |
| 4820 | void i40e_fdir_check_and_reenable(struct i40e_pf *pf) |
| 4821 | { |
| 4822 | u32 fcnt_prog, fcnt_avail; |
| 4823 | |
| 4824 | /* Check if, FD SB or ATR was auto disabled and if there is enough room |
| 4825 | * to re-enable |
| 4826 | */ |
| 4827 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 4828 | (pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 4829 | return; |
| 4830 | fcnt_prog = i40e_get_current_fd_count(pf); |
Anjali Singhai Jain | 8913278 | 2014-04-09 05:59:01 +0000 | [diff] [blame] | 4831 | fcnt_avail = i40e_get_fd_cnt_all(pf); |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 4832 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) { |
| 4833 | if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) && |
| 4834 | (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) { |
| 4835 | pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 4836 | dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n"); |
| 4837 | } |
| 4838 | } |
| 4839 | /* Wait for some more space to be available to turn on ATR */ |
| 4840 | if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) { |
| 4841 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 4842 | (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) { |
| 4843 | pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
| 4844 | dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n"); |
| 4845 | } |
| 4846 | } |
| 4847 | } |
| 4848 | |
| 4849 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4850 | * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table |
| 4851 | * @pf: board private structure |
| 4852 | **/ |
| 4853 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) |
| 4854 | { |
| 4855 | if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT)) |
| 4856 | return; |
| 4857 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4858 | /* if interface is down do nothing */ |
| 4859 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 4860 | return; |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 4861 | i40e_fdir_check_and_reenable(pf); |
| 4862 | |
| 4863 | if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) && |
| 4864 | (pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 4865 | pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | /** |
| 4869 | * i40e_vsi_link_event - notify VSI of a link event |
| 4870 | * @vsi: vsi to be notified |
| 4871 | * @link_up: link up or down |
| 4872 | **/ |
| 4873 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) |
| 4874 | { |
| 4875 | if (!vsi) |
| 4876 | return; |
| 4877 | |
| 4878 | switch (vsi->type) { |
| 4879 | case I40E_VSI_MAIN: |
| 4880 | if (!vsi->netdev || !vsi->netdev_registered) |
| 4881 | break; |
| 4882 | |
| 4883 | if (link_up) { |
| 4884 | netif_carrier_on(vsi->netdev); |
| 4885 | netif_tx_wake_all_queues(vsi->netdev); |
| 4886 | } else { |
| 4887 | netif_carrier_off(vsi->netdev); |
| 4888 | netif_tx_stop_all_queues(vsi->netdev); |
| 4889 | } |
| 4890 | break; |
| 4891 | |
| 4892 | case I40E_VSI_SRIOV: |
| 4893 | break; |
| 4894 | |
| 4895 | case I40E_VSI_VMDQ2: |
| 4896 | case I40E_VSI_CTRL: |
| 4897 | case I40E_VSI_MIRROR: |
| 4898 | default: |
| 4899 | /* there is no notification for other VSIs */ |
| 4900 | break; |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | /** |
| 4905 | * i40e_veb_link_event - notify elements on the veb of a link event |
| 4906 | * @veb: veb to be notified |
| 4907 | * @link_up: link up or down |
| 4908 | **/ |
| 4909 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) |
| 4910 | { |
| 4911 | struct i40e_pf *pf; |
| 4912 | int i; |
| 4913 | |
| 4914 | if (!veb || !veb->pf) |
| 4915 | return; |
| 4916 | pf = veb->pf; |
| 4917 | |
| 4918 | /* depth first... */ |
| 4919 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 4920 | if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) |
| 4921 | i40e_veb_link_event(pf->veb[i], link_up); |
| 4922 | |
| 4923 | /* ... now the local VSIs */ |
| 4924 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 4925 | if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) |
| 4926 | i40e_vsi_link_event(pf->vsi[i], link_up); |
| 4927 | } |
| 4928 | |
| 4929 | /** |
| 4930 | * i40e_link_event - Update netif_carrier status |
| 4931 | * @pf: board private structure |
| 4932 | **/ |
| 4933 | static void i40e_link_event(struct i40e_pf *pf) |
| 4934 | { |
| 4935 | bool new_link, old_link; |
| 4936 | |
| 4937 | new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP); |
| 4938 | old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); |
| 4939 | |
| 4940 | if (new_link == old_link) |
| 4941 | return; |
Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4942 | if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state)) |
Jesse Brandeburg | cf05ed0 | 2014-04-23 04:50:12 +0000 | [diff] [blame] | 4943 | i40e_print_link_message(pf->vsi[pf->lan_vsi], new_link); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4944 | |
| 4945 | /* Notify the base of the switch tree connected to |
| 4946 | * the link. Floating VEBs are not notified. |
| 4947 | */ |
| 4948 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 4949 | i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); |
| 4950 | else |
| 4951 | i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link); |
| 4952 | |
| 4953 | if (pf->vf) |
| 4954 | i40e_vc_notify_link_state(pf); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 4955 | |
| 4956 | if (pf->flags & I40E_FLAG_PTP) |
| 4957 | i40e_ptp_set_increment(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | /** |
| 4961 | * i40e_check_hang_subtask - Check for hung queues and dropped interrupts |
| 4962 | * @pf: board private structure |
| 4963 | * |
| 4964 | * Set the per-queue flags to request a check for stuck queues in the irq |
| 4965 | * clean functions, then force interrupts to be sure the irq clean is called. |
| 4966 | **/ |
| 4967 | static void i40e_check_hang_subtask(struct i40e_pf *pf) |
| 4968 | { |
| 4969 | int i, v; |
| 4970 | |
| 4971 | /* If we're down or resetting, just bail */ |
| 4972 | if (test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 4973 | return; |
| 4974 | |
| 4975 | /* for each VSI/netdev |
| 4976 | * for each Tx queue |
| 4977 | * set the check flag |
| 4978 | * for each q_vector |
| 4979 | * force an interrupt |
| 4980 | */ |
| 4981 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 4982 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 4983 | int armed = 0; |
| 4984 | |
| 4985 | if (!pf->vsi[v] || |
| 4986 | test_bit(__I40E_DOWN, &vsi->state) || |
| 4987 | (vsi->netdev && !netif_carrier_ok(vsi->netdev))) |
| 4988 | continue; |
| 4989 | |
| 4990 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4991 | set_check_for_tx_hang(vsi->tx_rings[i]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4992 | if (test_bit(__I40E_HANG_CHECK_ARMED, |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4993 | &vsi->tx_rings[i]->state)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4994 | armed++; |
| 4995 | } |
| 4996 | |
| 4997 | if (armed) { |
| 4998 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { |
| 4999 | wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, |
| 5000 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 5001 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); |
| 5002 | } else { |
| 5003 | u16 vec = vsi->base_vector - 1; |
| 5004 | u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | |
| 5005 | I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); |
| 5006 | for (i = 0; i < vsi->num_q_vectors; i++, vec++) |
| 5007 | wr32(&vsi->back->hw, |
| 5008 | I40E_PFINT_DYN_CTLN(vec), val); |
| 5009 | } |
| 5010 | i40e_flush(&vsi->back->hw); |
| 5011 | } |
| 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | /** |
| 5016 | * i40e_watchdog_subtask - Check and bring link up |
| 5017 | * @pf: board private structure |
| 5018 | **/ |
| 5019 | static void i40e_watchdog_subtask(struct i40e_pf *pf) |
| 5020 | { |
| 5021 | int i; |
| 5022 | |
| 5023 | /* if interface is down do nothing */ |
| 5024 | if (test_bit(__I40E_DOWN, &pf->state) || |
| 5025 | test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5026 | return; |
| 5027 | |
| 5028 | /* Update the stats for active netdevs so the network stack |
| 5029 | * can look at updated numbers whenever it cares to |
| 5030 | */ |
| 5031 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) |
| 5032 | if (pf->vsi[i] && pf->vsi[i]->netdev) |
| 5033 | i40e_update_stats(pf->vsi[i]); |
| 5034 | |
| 5035 | /* Update the stats for the active switching components */ |
| 5036 | for (i = 0; i < I40E_MAX_VEB; i++) |
| 5037 | if (pf->veb[i]) |
| 5038 | i40e_update_veb_stats(pf->veb[i]); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 5039 | |
| 5040 | i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5041 | } |
| 5042 | |
| 5043 | /** |
| 5044 | * i40e_reset_subtask - Set up for resetting the device and driver |
| 5045 | * @pf: board private structure |
| 5046 | **/ |
| 5047 | static void i40e_reset_subtask(struct i40e_pf *pf) |
| 5048 | { |
| 5049 | u32 reset_flags = 0; |
| 5050 | |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5051 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5052 | if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { |
| 5053 | reset_flags |= (1 << __I40E_REINIT_REQUESTED); |
| 5054 | clear_bit(__I40E_REINIT_REQUESTED, &pf->state); |
| 5055 | } |
| 5056 | if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { |
| 5057 | reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); |
| 5058 | clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); |
| 5059 | } |
| 5060 | if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { |
| 5061 | reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); |
| 5062 | clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); |
| 5063 | } |
| 5064 | if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { |
| 5065 | reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); |
| 5066 | clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); |
| 5067 | } |
| 5068 | |
| 5069 | /* If there's a recovery already waiting, it takes |
| 5070 | * precedence before starting a new reset sequence. |
| 5071 | */ |
| 5072 | if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { |
| 5073 | i40e_handle_reset_warning(pf); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5074 | goto unlock; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | /* If we're already down or resetting, just bail */ |
| 5078 | if (reset_flags && |
| 5079 | !test_bit(__I40E_DOWN, &pf->state) && |
| 5080 | !test_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 5081 | i40e_do_reset(pf, reset_flags); |
Anjali Singhai Jain | 2332618 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 5082 | |
| 5083 | unlock: |
| 5084 | rtnl_unlock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | /** |
| 5088 | * i40e_handle_link_event - Handle link event |
| 5089 | * @pf: board private structure |
| 5090 | * @e: event info posted on ARQ |
| 5091 | **/ |
| 5092 | static void i40e_handle_link_event(struct i40e_pf *pf, |
| 5093 | struct i40e_arq_event_info *e) |
| 5094 | { |
| 5095 | struct i40e_hw *hw = &pf->hw; |
| 5096 | struct i40e_aqc_get_link_status *status = |
| 5097 | (struct i40e_aqc_get_link_status *)&e->desc.params.raw; |
| 5098 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 5099 | |
| 5100 | /* save off old link status information */ |
| 5101 | memcpy(&pf->hw.phy.link_info_old, hw_link_info, |
| 5102 | sizeof(pf->hw.phy.link_info_old)); |
| 5103 | |
| 5104 | /* update link status */ |
| 5105 | hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type; |
| 5106 | hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed; |
| 5107 | hw_link_info->link_info = status->link_info; |
| 5108 | hw_link_info->an_info = status->an_info; |
| 5109 | hw_link_info->ext_info = status->ext_info; |
| 5110 | hw_link_info->lse_enable = |
| 5111 | le16_to_cpu(status->command_flags) & |
| 5112 | I40E_AQ_LSE_ENABLE; |
| 5113 | |
| 5114 | /* process the event */ |
| 5115 | i40e_link_event(pf); |
| 5116 | |
| 5117 | /* Do a new status request to re-enable LSE reporting |
| 5118 | * and load new status information into the hw struct, |
| 5119 | * then see if the status changed while processing the |
| 5120 | * initial event. |
| 5121 | */ |
| 5122 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 5123 | i40e_link_event(pf); |
| 5124 | } |
| 5125 | |
| 5126 | /** |
| 5127 | * i40e_clean_adminq_subtask - Clean the AdminQ rings |
| 5128 | * @pf: board private structure |
| 5129 | **/ |
| 5130 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) |
| 5131 | { |
| 5132 | struct i40e_arq_event_info event; |
| 5133 | struct i40e_hw *hw = &pf->hw; |
| 5134 | u16 pending, i = 0; |
| 5135 | i40e_status ret; |
| 5136 | u16 opcode; |
| 5137 | u32 val; |
| 5138 | |
| 5139 | if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)) |
| 5140 | return; |
| 5141 | |
Mitch Williams | 3197ce2 | 2013-11-28 06:39:39 +0000 | [diff] [blame] | 5142 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5143 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); |
| 5144 | if (!event.msg_buf) |
| 5145 | return; |
| 5146 | |
| 5147 | do { |
Mitch Williams | 2f01912 | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 5148 | event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5149 | ret = i40e_clean_arq_element(hw, &event, &pending); |
| 5150 | if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) { |
| 5151 | dev_info(&pf->pdev->dev, "No ARQ event found\n"); |
| 5152 | break; |
| 5153 | } else if (ret) { |
| 5154 | dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); |
| 5155 | break; |
| 5156 | } |
| 5157 | |
| 5158 | opcode = le16_to_cpu(event.desc.opcode); |
| 5159 | switch (opcode) { |
| 5160 | |
| 5161 | case i40e_aqc_opc_get_link_status: |
| 5162 | i40e_handle_link_event(pf, &event); |
| 5163 | break; |
| 5164 | case i40e_aqc_opc_send_msg_to_pf: |
| 5165 | ret = i40e_vc_process_vf_msg(pf, |
| 5166 | le16_to_cpu(event.desc.retval), |
| 5167 | le32_to_cpu(event.desc.cookie_high), |
| 5168 | le32_to_cpu(event.desc.cookie_low), |
| 5169 | event.msg_buf, |
| 5170 | event.msg_size); |
| 5171 | break; |
| 5172 | case i40e_aqc_opc_lldp_update_mib: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5173 | dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5174 | #ifdef CONFIG_I40E_DCB |
| 5175 | rtnl_lock(); |
| 5176 | ret = i40e_handle_lldp_event(pf, &event); |
| 5177 | rtnl_unlock(); |
| 5178 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5179 | break; |
| 5180 | case i40e_aqc_opc_event_lan_overflow: |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5181 | dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5182 | i40e_handle_lan_overflow_event(pf, &event); |
| 5183 | break; |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 5184 | case i40e_aqc_opc_send_msg_to_peer: |
| 5185 | dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n"); |
| 5186 | break; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5187 | default: |
| 5188 | dev_info(&pf->pdev->dev, |
Shannon Nelson | 0467bc9 | 2013-12-18 13:45:58 +0000 | [diff] [blame] | 5189 | "ARQ Error: Unknown event 0x%04x received\n", |
| 5190 | opcode); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5191 | break; |
| 5192 | } |
| 5193 | } while (pending && (i++ < pf->adminq_work_limit)); |
| 5194 | |
| 5195 | clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); |
| 5196 | /* re-enable Admin queue interrupt cause */ |
| 5197 | val = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 5198 | val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK; |
| 5199 | wr32(hw, I40E_PFINT_ICR0_ENA, val); |
| 5200 | i40e_flush(hw); |
| 5201 | |
| 5202 | kfree(event.msg_buf); |
| 5203 | } |
| 5204 | |
| 5205 | /** |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5206 | * i40e_verify_eeprom - make sure eeprom is good to use |
| 5207 | * @pf: board private structure |
| 5208 | **/ |
| 5209 | static void i40e_verify_eeprom(struct i40e_pf *pf) |
| 5210 | { |
| 5211 | int err; |
| 5212 | |
| 5213 | err = i40e_diag_eeprom_test(&pf->hw); |
| 5214 | if (err) { |
| 5215 | /* retry in case of garbage read */ |
| 5216 | err = i40e_diag_eeprom_test(&pf->hw); |
| 5217 | if (err) { |
| 5218 | dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n", |
| 5219 | err); |
| 5220 | set_bit(__I40E_BAD_EEPROM, &pf->state); |
| 5221 | } |
| 5222 | } |
| 5223 | |
| 5224 | if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
| 5225 | dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n"); |
| 5226 | clear_bit(__I40E_BAD_EEPROM, &pf->state); |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5231 | * i40e_reconstitute_veb - rebuild the VEB and anything connected to it |
| 5232 | * @veb: pointer to the VEB instance |
| 5233 | * |
| 5234 | * This is a recursive function that first builds the attached VSIs then |
| 5235 | * recurses in to build the next layer of VEB. We track the connections |
| 5236 | * through our own index numbers because the seid's from the HW could |
| 5237 | * change across the reset. |
| 5238 | **/ |
| 5239 | static int i40e_reconstitute_veb(struct i40e_veb *veb) |
| 5240 | { |
| 5241 | struct i40e_vsi *ctl_vsi = NULL; |
| 5242 | struct i40e_pf *pf = veb->pf; |
| 5243 | int v, veb_idx; |
| 5244 | int ret; |
| 5245 | |
| 5246 | /* build VSI that owns this VEB, temporarily attached to base VEB */ |
| 5247 | for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) { |
| 5248 | if (pf->vsi[v] && |
| 5249 | pf->vsi[v]->veb_idx == veb->idx && |
| 5250 | pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 5251 | ctl_vsi = pf->vsi[v]; |
| 5252 | break; |
| 5253 | } |
| 5254 | } |
| 5255 | if (!ctl_vsi) { |
| 5256 | dev_info(&pf->pdev->dev, |
| 5257 | "missing owner VSI for veb_idx %d\n", veb->idx); |
| 5258 | ret = -ENOENT; |
| 5259 | goto end_reconstitute; |
| 5260 | } |
| 5261 | if (ctl_vsi != pf->vsi[pf->lan_vsi]) |
| 5262 | ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 5263 | ret = i40e_add_vsi(ctl_vsi); |
| 5264 | if (ret) { |
| 5265 | dev_info(&pf->pdev->dev, |
| 5266 | "rebuild of owner VSI failed: %d\n", ret); |
| 5267 | goto end_reconstitute; |
| 5268 | } |
| 5269 | i40e_vsi_reset_stats(ctl_vsi); |
| 5270 | |
| 5271 | /* create the VEB in the switch and move the VSI onto the VEB */ |
| 5272 | ret = i40e_add_veb(veb, ctl_vsi); |
| 5273 | if (ret) |
| 5274 | goto end_reconstitute; |
| 5275 | |
| 5276 | /* create the remaining VSIs attached to this VEB */ |
| 5277 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 5278 | if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) |
| 5279 | continue; |
| 5280 | |
| 5281 | if (pf->vsi[v]->veb_idx == veb->idx) { |
| 5282 | struct i40e_vsi *vsi = pf->vsi[v]; |
| 5283 | vsi->uplink_seid = veb->seid; |
| 5284 | ret = i40e_add_vsi(vsi); |
| 5285 | if (ret) { |
| 5286 | dev_info(&pf->pdev->dev, |
| 5287 | "rebuild of vsi_idx %d failed: %d\n", |
| 5288 | v, ret); |
| 5289 | goto end_reconstitute; |
| 5290 | } |
| 5291 | i40e_vsi_reset_stats(vsi); |
| 5292 | } |
| 5293 | } |
| 5294 | |
| 5295 | /* create any VEBs attached to this VEB - RECURSION */ |
| 5296 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 5297 | if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { |
| 5298 | pf->veb[veb_idx]->uplink_seid = veb->seid; |
| 5299 | ret = i40e_reconstitute_veb(pf->veb[veb_idx]); |
| 5300 | if (ret) |
| 5301 | break; |
| 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | end_reconstitute: |
| 5306 | return ret; |
| 5307 | } |
| 5308 | |
| 5309 | /** |
| 5310 | * i40e_get_capabilities - get info about the HW |
| 5311 | * @pf: the PF struct |
| 5312 | **/ |
| 5313 | static int i40e_get_capabilities(struct i40e_pf *pf) |
| 5314 | { |
| 5315 | struct i40e_aqc_list_capabilities_element_resp *cap_buf; |
| 5316 | u16 data_size; |
| 5317 | int buf_len; |
| 5318 | int err; |
| 5319 | |
| 5320 | buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); |
| 5321 | do { |
| 5322 | cap_buf = kzalloc(buf_len, GFP_KERNEL); |
| 5323 | if (!cap_buf) |
| 5324 | return -ENOMEM; |
| 5325 | |
| 5326 | /* this loads the data into the hw struct for us */ |
| 5327 | err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, |
| 5328 | &data_size, |
| 5329 | i40e_aqc_opc_list_func_capabilities, |
| 5330 | NULL); |
| 5331 | /* data loaded, buffer no longer needed */ |
| 5332 | kfree(cap_buf); |
| 5333 | |
| 5334 | if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { |
| 5335 | /* retry with a larger buffer */ |
| 5336 | buf_len = data_size; |
| 5337 | } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { |
| 5338 | dev_info(&pf->pdev->dev, |
| 5339 | "capability discovery failed: aq=%d\n", |
| 5340 | pf->hw.aq.asq_last_status); |
| 5341 | return -ENODEV; |
| 5342 | } |
| 5343 | } while (err); |
| 5344 | |
Anjali Singhai Jain | ac71b7b | 2014-02-06 05:51:08 +0000 | [diff] [blame] | 5345 | if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) || |
| 5346 | (pf->hw.aq.fw_maj_ver < 2)) { |
| 5347 | pf->hw.func_caps.num_msix_vectors++; |
| 5348 | pf->hw.func_caps.num_msix_vectors_vf++; |
| 5349 | } |
| 5350 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5351 | if (pf->hw.debug_mask & I40E_DEBUG_USER) |
| 5352 | dev_info(&pf->pdev->dev, |
| 5353 | "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n", |
| 5354 | pf->hw.pf_id, pf->hw.func_caps.num_vfs, |
| 5355 | pf->hw.func_caps.num_msix_vectors, |
| 5356 | pf->hw.func_caps.num_msix_vectors_vf, |
| 5357 | pf->hw.func_caps.fd_filters_guaranteed, |
| 5358 | pf->hw.func_caps.fd_filters_best_effort, |
| 5359 | pf->hw.func_caps.num_tx_qp, |
| 5360 | pf->hw.func_caps.num_vsis); |
| 5361 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 5362 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ |
| 5363 | + pf->hw.func_caps.num_vfs) |
| 5364 | if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { |
| 5365 | dev_info(&pf->pdev->dev, |
| 5366 | "got num_vsis %d, setting num_vsis to %d\n", |
| 5367 | pf->hw.func_caps.num_vsis, DEF_NUM_VSI); |
| 5368 | pf->hw.func_caps.num_vsis = DEF_NUM_VSI; |
| 5369 | } |
| 5370 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5371 | return 0; |
| 5372 | } |
| 5373 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5374 | static int i40e_vsi_clear(struct i40e_vsi *vsi); |
| 5375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5376 | /** |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5377 | * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5378 | * @pf: board private structure |
| 5379 | **/ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5380 | static void i40e_fdir_sb_setup(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5381 | { |
| 5382 | struct i40e_vsi *vsi; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5383 | int i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5384 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5385 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5386 | return; |
| 5387 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5388 | /* find existing VSI and see if it needs configuring */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5389 | vsi = NULL; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5390 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 5391 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5392 | vsi = pf->vsi[i]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5393 | break; |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | /* create a new VSI if none exists */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5398 | if (!vsi) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5399 | vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, |
| 5400 | pf->vsi[pf->lan_vsi]->seid, 0); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5401 | if (!vsi) { |
| 5402 | dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5403 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 5404 | return; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5405 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5406 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 5407 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 5408 | i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | /** |
| 5412 | * i40e_fdir_teardown - release the Flow Director resources |
| 5413 | * @pf: board private structure |
| 5414 | **/ |
| 5415 | static void i40e_fdir_teardown(struct i40e_pf *pf) |
| 5416 | { |
| 5417 | int i; |
| 5418 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 5419 | i40e_fdir_filter_exit(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5420 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 5421 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 5422 | i40e_vsi_release(pf->vsi[i]); |
| 5423 | break; |
| 5424 | } |
| 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5429 | * i40e_prep_for_reset - prep for the core to reset |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5430 | * @pf: board private structure |
| 5431 | * |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5432 | * Close up the VFs and other things in prep for pf Reset. |
| 5433 | **/ |
| 5434 | static int i40e_prep_for_reset(struct i40e_pf *pf) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5435 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5436 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 5437 | i40e_status ret = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5438 | u32 v; |
| 5439 | |
| 5440 | clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); |
| 5441 | if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5442 | return 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5443 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5444 | dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5445 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5446 | /* quiesce the VSIs and their queues that are not already DOWN */ |
| 5447 | i40e_pf_quiesce_all_vsi(pf); |
| 5448 | |
| 5449 | for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { |
| 5450 | if (pf->vsi[v]) |
| 5451 | pf->vsi[v]->seid = 0; |
| 5452 | } |
| 5453 | |
| 5454 | i40e_shutdown_adminq(&pf->hw); |
| 5455 | |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5456 | /* call shutdown HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 5457 | if (hw->hmc.hmc_obj) { |
| 5458 | ret = i40e_shutdown_lan_hmc(hw); |
| 5459 | if (ret) { |
| 5460 | dev_warn(&pf->pdev->dev, |
| 5461 | "shutdown_lan_hmc failed: %d\n", ret); |
| 5462 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 5463 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5464 | } |
| 5465 | return ret; |
| 5466 | } |
| 5467 | |
| 5468 | /** |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 5469 | * i40e_send_version - update firmware with driver version |
| 5470 | * @pf: PF struct |
| 5471 | */ |
| 5472 | static void i40e_send_version(struct i40e_pf *pf) |
| 5473 | { |
| 5474 | struct i40e_driver_version dv; |
| 5475 | |
| 5476 | dv.major_version = DRV_VERSION_MAJOR; |
| 5477 | dv.minor_version = DRV_VERSION_MINOR; |
| 5478 | dv.build_version = DRV_VERSION_BUILD; |
| 5479 | dv.subbuild_version = 0; |
| 5480 | strncpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string)); |
| 5481 | i40e_aq_send_driver_version(&pf->hw, &dv, NULL); |
| 5482 | } |
| 5483 | |
| 5484 | /** |
Jesse Brandeburg | 4dda12e | 2013-12-18 13:46:01 +0000 | [diff] [blame] | 5485 | * i40e_reset_and_rebuild - reset and rebuild using a saved config |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5486 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5487 | * @reinit: if the Main VSI needs to re-initialized. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5488 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5489 | static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5490 | { |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5491 | struct i40e_hw *hw = &pf->hw; |
| 5492 | i40e_status ret; |
| 5493 | u32 v; |
| 5494 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5495 | /* Now we wait for GRST to settle out. |
| 5496 | * We don't have to delete the VEBs or VSIs from the hw switch |
| 5497 | * because the reset will make them disappear. |
| 5498 | */ |
| 5499 | ret = i40e_pf_reset(hw); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 5500 | if (ret) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5501 | dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); |
Akeem G Abodunrin | b556540 | 2014-04-09 05:59:04 +0000 | [diff] [blame] | 5502 | goto end_core_reset; |
| 5503 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5504 | pf->pfr_count++; |
| 5505 | |
| 5506 | if (test_bit(__I40E_DOWN, &pf->state)) |
| 5507 | goto end_core_reset; |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5508 | dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5509 | |
| 5510 | /* rebuild the basics for the AdminQ, HMC, and initial HW switch */ |
| 5511 | ret = i40e_init_adminq(&pf->hw); |
| 5512 | if (ret) { |
| 5513 | dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); |
| 5514 | goto end_core_reset; |
| 5515 | } |
| 5516 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 5517 | /* re-verify the eeprom if we just had an EMP reset */ |
| 5518 | if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) { |
| 5519 | clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state); |
| 5520 | i40e_verify_eeprom(pf); |
| 5521 | } |
| 5522 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5523 | ret = i40e_get_capabilities(pf); |
| 5524 | if (ret) { |
| 5525 | dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", |
| 5526 | ret); |
| 5527 | goto end_core_reset; |
| 5528 | } |
| 5529 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5530 | ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 5531 | hw->func_caps.num_rx_qp, |
| 5532 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 5533 | if (ret) { |
| 5534 | dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); |
| 5535 | goto end_core_reset; |
| 5536 | } |
| 5537 | ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 5538 | if (ret) { |
| 5539 | dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); |
| 5540 | goto end_core_reset; |
| 5541 | } |
| 5542 | |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 5543 | #ifdef CONFIG_I40E_DCB |
| 5544 | ret = i40e_init_pf_dcb(pf); |
| 5545 | if (ret) { |
| 5546 | dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret); |
| 5547 | goto end_core_reset; |
| 5548 | } |
| 5549 | #endif /* CONFIG_I40E_DCB */ |
| 5550 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5551 | /* do basic switch setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5552 | ret = i40e_setup_pf_switch(pf, reinit); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5553 | if (ret) |
| 5554 | goto end_core_reset; |
| 5555 | |
| 5556 | /* Rebuild the VSIs and VEBs that existed before reset. |
| 5557 | * They are still in our local switch element arrays, so only |
| 5558 | * need to rebuild the switch model in the HW. |
| 5559 | * |
| 5560 | * If there were VEBs but the reconstitution failed, we'll try |
| 5561 | * try to recover minimal use by getting the basic PF VSI working. |
| 5562 | */ |
| 5563 | if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5564 | dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5565 | /* find the one VEB connected to the MAC, and find orphans */ |
| 5566 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 5567 | if (!pf->veb[v]) |
| 5568 | continue; |
| 5569 | |
| 5570 | if (pf->veb[v]->uplink_seid == pf->mac_seid || |
| 5571 | pf->veb[v]->uplink_seid == 0) { |
| 5572 | ret = i40e_reconstitute_veb(pf->veb[v]); |
| 5573 | |
| 5574 | if (!ret) |
| 5575 | continue; |
| 5576 | |
| 5577 | /* If Main VEB failed, we're in deep doodoo, |
| 5578 | * so give up rebuilding the switch and set up |
| 5579 | * for minimal rebuild of PF VSI. |
| 5580 | * If orphan failed, we'll report the error |
| 5581 | * but try to keep going. |
| 5582 | */ |
| 5583 | if (pf->veb[v]->uplink_seid == pf->mac_seid) { |
| 5584 | dev_info(&pf->pdev->dev, |
| 5585 | "rebuild of switch failed: %d, will try to set up simple PF connection\n", |
| 5586 | ret); |
| 5587 | pf->vsi[pf->lan_vsi]->uplink_seid |
| 5588 | = pf->mac_seid; |
| 5589 | break; |
| 5590 | } else if (pf->veb[v]->uplink_seid == 0) { |
| 5591 | dev_info(&pf->pdev->dev, |
| 5592 | "rebuild of orphan VEB failed: %d\n", |
| 5593 | ret); |
| 5594 | } |
| 5595 | } |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { |
| 5600 | dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); |
| 5601 | /* no VEB, so rebuild only the Main VSI */ |
| 5602 | ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); |
| 5603 | if (ret) { |
| 5604 | dev_info(&pf->pdev->dev, |
| 5605 | "rebuild of Main VSI failed: %d\n", ret); |
| 5606 | goto end_core_reset; |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /* reinit the misc interrupt */ |
| 5611 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5612 | ret = i40e_setup_misc_vector(pf); |
| 5613 | |
| 5614 | /* restart the VSIs that were rebuilt and running before the reset */ |
| 5615 | i40e_pf_unquiesce_all_vsi(pf); |
| 5616 | |
Mitch Williams | 69f64b2 | 2014-02-13 03:48:46 -0800 | [diff] [blame] | 5617 | if (pf->num_alloc_vfs) { |
| 5618 | for (v = 0; v < pf->num_alloc_vfs; v++) |
| 5619 | i40e_reset_vf(&pf->vf[v], true); |
| 5620 | } |
| 5621 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5622 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 5623 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5624 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 5625 | dev_info(&pf->pdev->dev, "reset complete\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5626 | |
| 5627 | end_core_reset: |
| 5628 | clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); |
| 5629 | } |
| 5630 | |
| 5631 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5632 | * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild |
| 5633 | * @pf: board private structure |
| 5634 | * |
| 5635 | * Close up the VFs and other things in prep for a Core Reset, |
| 5636 | * then get ready to rebuild the world. |
| 5637 | **/ |
| 5638 | static void i40e_handle_reset_warning(struct i40e_pf *pf) |
| 5639 | { |
| 5640 | i40e_status ret; |
| 5641 | |
| 5642 | ret = i40e_prep_for_reset(pf); |
| 5643 | if (!ret) |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5644 | i40e_reset_and_rebuild(pf, false); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5648 | * i40e_handle_mdd_event |
| 5649 | * @pf: pointer to the pf structure |
| 5650 | * |
| 5651 | * Called from the MDD irq handler to identify possibly malicious vfs |
| 5652 | **/ |
| 5653 | static void i40e_handle_mdd_event(struct i40e_pf *pf) |
| 5654 | { |
| 5655 | struct i40e_hw *hw = &pf->hw; |
| 5656 | bool mdd_detected = false; |
| 5657 | struct i40e_vf *vf; |
| 5658 | u32 reg; |
| 5659 | int i; |
| 5660 | |
| 5661 | if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) |
| 5662 | return; |
| 5663 | |
| 5664 | /* find what triggered the MDD event */ |
| 5665 | reg = rd32(hw, I40E_GL_MDET_TX); |
| 5666 | if (reg & I40E_GL_MDET_TX_VALID_MASK) { |
| 5667 | u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK) |
| 5668 | >> I40E_GL_MDET_TX_FUNCTION_SHIFT; |
| 5669 | u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) |
| 5670 | >> I40E_GL_MDET_TX_EVENT_SHIFT; |
| 5671 | u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) |
| 5672 | >> I40E_GL_MDET_TX_QUEUE_SHIFT; |
| 5673 | dev_info(&pf->pdev->dev, |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 5674 | "Malicious Driver Detection event 0x%02x on TX queue %d of function 0x%02x\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5675 | event, queue, func); |
| 5676 | wr32(hw, I40E_GL_MDET_TX, 0xffffffff); |
| 5677 | mdd_detected = true; |
| 5678 | } |
| 5679 | reg = rd32(hw, I40E_GL_MDET_RX); |
| 5680 | if (reg & I40E_GL_MDET_RX_VALID_MASK) { |
| 5681 | u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) |
| 5682 | >> I40E_GL_MDET_RX_FUNCTION_SHIFT; |
| 5683 | u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) |
| 5684 | >> I40E_GL_MDET_RX_EVENT_SHIFT; |
| 5685 | u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) |
| 5686 | >> I40E_GL_MDET_RX_QUEUE_SHIFT; |
| 5687 | dev_info(&pf->pdev->dev, |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 5688 | "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5689 | event, queue, func); |
| 5690 | wr32(hw, I40E_GL_MDET_RX, 0xffffffff); |
| 5691 | mdd_detected = true; |
| 5692 | } |
| 5693 | |
| 5694 | /* see if one of the VFs needs its hand slapped */ |
| 5695 | for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { |
| 5696 | vf = &(pf->vf[i]); |
| 5697 | reg = rd32(hw, I40E_VP_MDET_TX(i)); |
| 5698 | if (reg & I40E_VP_MDET_TX_VALID_MASK) { |
| 5699 | wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); |
| 5700 | vf->num_mdd_events++; |
| 5701 | dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i); |
| 5702 | } |
| 5703 | |
| 5704 | reg = rd32(hw, I40E_VP_MDET_RX(i)); |
| 5705 | if (reg & I40E_VP_MDET_RX_VALID_MASK) { |
| 5706 | wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); |
| 5707 | vf->num_mdd_events++; |
| 5708 | dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i); |
| 5709 | } |
| 5710 | |
| 5711 | if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { |
| 5712 | dev_info(&pf->pdev->dev, |
| 5713 | "Too many MDD events on VF %d, disabled\n", i); |
| 5714 | dev_info(&pf->pdev->dev, |
| 5715 | "Use PF Control I/F to re-enable the VF\n"); |
| 5716 | set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); |
| 5717 | } |
| 5718 | } |
| 5719 | |
| 5720 | /* re-enable mdd interrupt cause */ |
| 5721 | clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); |
| 5722 | reg = rd32(hw, I40E_PFINT_ICR0_ENA); |
| 5723 | reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; |
| 5724 | wr32(hw, I40E_PFINT_ICR0_ENA, reg); |
| 5725 | i40e_flush(hw); |
| 5726 | } |
| 5727 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5728 | #ifdef CONFIG_I40E_VXLAN |
| 5729 | /** |
| 5730 | * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW |
| 5731 | * @pf: board private structure |
| 5732 | **/ |
| 5733 | static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf) |
| 5734 | { |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5735 | struct i40e_hw *hw = &pf->hw; |
| 5736 | i40e_status ret; |
| 5737 | u8 filter_index; |
| 5738 | __be16 port; |
| 5739 | int i; |
| 5740 | |
| 5741 | if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC)) |
| 5742 | return; |
| 5743 | |
| 5744 | pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC; |
| 5745 | |
| 5746 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 5747 | if (pf->pending_vxlan_bitmap & (1 << i)) { |
| 5748 | pf->pending_vxlan_bitmap &= ~(1 << i); |
| 5749 | port = pf->vxlan_ports[i]; |
| 5750 | ret = port ? |
| 5751 | i40e_aq_add_udp_tunnel(hw, ntohs(port), |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5752 | I40E_AQC_TUNNEL_TYPE_VXLAN, |
| 5753 | &filter_index, NULL) |
| 5754 | : i40e_aq_del_udp_tunnel(hw, i, NULL); |
| 5755 | |
| 5756 | if (ret) { |
| 5757 | dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n", |
| 5758 | port ? "adding" : "deleting", |
| 5759 | ntohs(port), port ? i : i); |
| 5760 | |
| 5761 | pf->vxlan_ports[i] = 0; |
| 5762 | } else { |
| 5763 | dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n", |
| 5764 | port ? "Added" : "Deleted", |
| 5765 | ntohs(port), port ? i : filter_index); |
| 5766 | } |
| 5767 | } |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5772 | /** |
| 5773 | * i40e_service_task - Run the driver's async subtasks |
| 5774 | * @work: pointer to work_struct containing our data |
| 5775 | **/ |
| 5776 | static void i40e_service_task(struct work_struct *work) |
| 5777 | { |
| 5778 | struct i40e_pf *pf = container_of(work, |
| 5779 | struct i40e_pf, |
| 5780 | service_task); |
| 5781 | unsigned long start_time = jiffies; |
| 5782 | |
| 5783 | i40e_reset_subtask(pf); |
| 5784 | i40e_handle_mdd_event(pf); |
| 5785 | i40e_vc_process_vflr_event(pf); |
| 5786 | i40e_watchdog_subtask(pf); |
| 5787 | i40e_fdir_reinit_subtask(pf); |
| 5788 | i40e_check_hang_subtask(pf); |
| 5789 | i40e_sync_filters_subtask(pf); |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5790 | #ifdef CONFIG_I40E_VXLAN |
| 5791 | i40e_sync_vxlan_filters_subtask(pf); |
| 5792 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5793 | i40e_clean_adminq_subtask(pf); |
| 5794 | |
| 5795 | i40e_service_event_complete(pf); |
| 5796 | |
| 5797 | /* If the tasks have taken longer than one timer cycle or there |
| 5798 | * is more work to be done, reschedule the service task now |
| 5799 | * rather than wait for the timer to tick again. |
| 5800 | */ |
| 5801 | if (time_after(jiffies, (start_time + pf->service_timer_period)) || |
| 5802 | test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) || |
| 5803 | test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) || |
| 5804 | test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) |
| 5805 | i40e_service_event_schedule(pf); |
| 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * i40e_service_timer - timer callback |
| 5810 | * @data: pointer to PF struct |
| 5811 | **/ |
| 5812 | static void i40e_service_timer(unsigned long data) |
| 5813 | { |
| 5814 | struct i40e_pf *pf = (struct i40e_pf *)data; |
| 5815 | |
| 5816 | mod_timer(&pf->service_timer, |
| 5817 | round_jiffies(jiffies + pf->service_timer_period)); |
| 5818 | i40e_service_event_schedule(pf); |
| 5819 | } |
| 5820 | |
| 5821 | /** |
| 5822 | * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI |
| 5823 | * @vsi: the VSI being configured |
| 5824 | **/ |
| 5825 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) |
| 5826 | { |
| 5827 | struct i40e_pf *pf = vsi->back; |
| 5828 | |
| 5829 | switch (vsi->type) { |
| 5830 | case I40E_VSI_MAIN: |
| 5831 | vsi->alloc_queue_pairs = pf->num_lan_qps; |
| 5832 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5833 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5834 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 5835 | vsi->num_q_vectors = pf->num_lan_msix; |
| 5836 | else |
| 5837 | vsi->num_q_vectors = 1; |
| 5838 | |
| 5839 | break; |
| 5840 | |
| 5841 | case I40E_VSI_FDIR: |
| 5842 | vsi->alloc_queue_pairs = 1; |
| 5843 | vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, |
| 5844 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5845 | vsi->num_q_vectors = 1; |
| 5846 | break; |
| 5847 | |
| 5848 | case I40E_VSI_VMDQ2: |
| 5849 | vsi->alloc_queue_pairs = pf->num_vmdq_qps; |
| 5850 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5851 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5852 | vsi->num_q_vectors = pf->num_vmdq_msix; |
| 5853 | break; |
| 5854 | |
| 5855 | case I40E_VSI_SRIOV: |
| 5856 | vsi->alloc_queue_pairs = pf->num_vf_qps; |
| 5857 | vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, |
| 5858 | I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 5859 | break; |
| 5860 | |
| 5861 | default: |
| 5862 | WARN_ON(1); |
| 5863 | return -ENODATA; |
| 5864 | } |
| 5865 | |
| 5866 | return 0; |
| 5867 | } |
| 5868 | |
| 5869 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5870 | * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi |
| 5871 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5872 | * @alloc_qvectors: a bool to specify if q_vectors need to be allocated. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5873 | * |
| 5874 | * On error: returns error code (negative) |
| 5875 | * On success: returns 0 |
| 5876 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5877 | static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5878 | { |
| 5879 | int size; |
| 5880 | int ret = 0; |
| 5881 | |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5882 | /* allocate memory for both Tx and Rx ring pointers */ |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5883 | size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; |
| 5884 | vsi->tx_rings = kzalloc(size, GFP_KERNEL); |
| 5885 | if (!vsi->tx_rings) |
| 5886 | return -ENOMEM; |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5887 | vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; |
| 5888 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5889 | if (alloc_qvectors) { |
| 5890 | /* allocate memory for q_vector pointers */ |
| 5891 | size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors; |
| 5892 | vsi->q_vectors = kzalloc(size, GFP_KERNEL); |
| 5893 | if (!vsi->q_vectors) { |
| 5894 | ret = -ENOMEM; |
| 5895 | goto err_vectors; |
| 5896 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5897 | } |
| 5898 | return ret; |
| 5899 | |
| 5900 | err_vectors: |
| 5901 | kfree(vsi->tx_rings); |
| 5902 | return ret; |
| 5903 | } |
| 5904 | |
| 5905 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5906 | * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF |
| 5907 | * @pf: board private structure |
| 5908 | * @type: type of VSI |
| 5909 | * |
| 5910 | * On error: returns error code (negative) |
| 5911 | * On success: returns vsi index in PF (positive) |
| 5912 | **/ |
| 5913 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) |
| 5914 | { |
| 5915 | int ret = -ENODEV; |
| 5916 | struct i40e_vsi *vsi; |
| 5917 | int vsi_idx; |
| 5918 | int i; |
| 5919 | |
| 5920 | /* Need to protect the allocation of the VSIs at the PF level */ |
| 5921 | mutex_lock(&pf->switch_mutex); |
| 5922 | |
| 5923 | /* VSI list may be fragmented if VSI creation/destruction has |
| 5924 | * been happening. We can afford to do a quick scan to look |
| 5925 | * for any free VSIs in the list. |
| 5926 | * |
| 5927 | * find next empty vsi slot, looping back around if necessary |
| 5928 | */ |
| 5929 | i = pf->next_vsi; |
| 5930 | while (i < pf->hw.func_caps.num_vsis && pf->vsi[i]) |
| 5931 | i++; |
| 5932 | if (i >= pf->hw.func_caps.num_vsis) { |
| 5933 | i = 0; |
| 5934 | while (i < pf->next_vsi && pf->vsi[i]) |
| 5935 | i++; |
| 5936 | } |
| 5937 | |
| 5938 | if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) { |
| 5939 | vsi_idx = i; /* Found one! */ |
| 5940 | } else { |
| 5941 | ret = -ENODEV; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5942 | goto unlock_pf; /* out of VSI slots! */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5943 | } |
| 5944 | pf->next_vsi = ++i; |
| 5945 | |
| 5946 | vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); |
| 5947 | if (!vsi) { |
| 5948 | ret = -ENOMEM; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5949 | goto unlock_pf; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5950 | } |
| 5951 | vsi->type = type; |
| 5952 | vsi->back = pf; |
| 5953 | set_bit(__I40E_DOWN, &vsi->state); |
| 5954 | vsi->flags = 0; |
| 5955 | vsi->idx = vsi_idx; |
| 5956 | vsi->rx_itr_setting = pf->rx_itr_default; |
| 5957 | vsi->tx_itr_setting = pf->tx_itr_default; |
| 5958 | vsi->netdev_registered = false; |
| 5959 | vsi->work_limit = I40E_DEFAULT_IRQ_WORK; |
| 5960 | INIT_LIST_HEAD(&vsi->mac_filter_list); |
Shannon Nelson | 6374184 | 2014-04-23 04:50:16 +0000 | [diff] [blame^] | 5961 | vsi->irqs_ready = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5962 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5963 | ret = i40e_set_num_rings_in_vsi(vsi); |
| 5964 | if (ret) |
| 5965 | goto err_rings; |
| 5966 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5967 | ret = i40e_vsi_alloc_arrays(vsi, true); |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5968 | if (ret) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5969 | goto err_rings; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5970 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5971 | /* Setup default MSIX irq handler for VSI */ |
| 5972 | i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); |
| 5973 | |
| 5974 | pf->vsi[vsi_idx] = vsi; |
| 5975 | ret = vsi_idx; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5976 | goto unlock_pf; |
| 5977 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5978 | err_rings: |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5979 | pf->next_vsi = i - 1; |
| 5980 | kfree(vsi); |
| 5981 | unlock_pf: |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5982 | mutex_unlock(&pf->switch_mutex); |
| 5983 | return ret; |
| 5984 | } |
| 5985 | |
| 5986 | /** |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5987 | * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI |
| 5988 | * @type: VSI pointer |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5989 | * @free_qvectors: a bool to specify if q_vectors need to be freed. |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5990 | * |
| 5991 | * On error: returns error code (negative) |
| 5992 | * On success: returns 0 |
| 5993 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5994 | static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors) |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5995 | { |
| 5996 | /* free the ring and vector containers */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5997 | if (free_qvectors) { |
| 5998 | kfree(vsi->q_vectors); |
| 5999 | vsi->q_vectors = NULL; |
| 6000 | } |
Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 6001 | kfree(vsi->tx_rings); |
| 6002 | vsi->tx_rings = NULL; |
| 6003 | vsi->rx_rings = NULL; |
| 6004 | } |
| 6005 | |
| 6006 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6007 | * i40e_vsi_clear - Deallocate the VSI provided |
| 6008 | * @vsi: the VSI being un-configured |
| 6009 | **/ |
| 6010 | static int i40e_vsi_clear(struct i40e_vsi *vsi) |
| 6011 | { |
| 6012 | struct i40e_pf *pf; |
| 6013 | |
| 6014 | if (!vsi) |
| 6015 | return 0; |
| 6016 | |
| 6017 | if (!vsi->back) |
| 6018 | goto free_vsi; |
| 6019 | pf = vsi->back; |
| 6020 | |
| 6021 | mutex_lock(&pf->switch_mutex); |
| 6022 | if (!pf->vsi[vsi->idx]) { |
| 6023 | dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", |
| 6024 | vsi->idx, vsi->idx, vsi, vsi->type); |
| 6025 | goto unlock_vsi; |
| 6026 | } |
| 6027 | |
| 6028 | if (pf->vsi[vsi->idx] != vsi) { |
| 6029 | dev_err(&pf->pdev->dev, |
| 6030 | "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", |
| 6031 | pf->vsi[vsi->idx]->idx, |
| 6032 | pf->vsi[vsi->idx], |
| 6033 | pf->vsi[vsi->idx]->type, |
| 6034 | vsi->idx, vsi, vsi->type); |
| 6035 | goto unlock_vsi; |
| 6036 | } |
| 6037 | |
| 6038 | /* updates the pf for this cleared vsi */ |
| 6039 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 6040 | i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); |
| 6041 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6042 | i40e_vsi_free_arrays(vsi, true); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6043 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6044 | pf->vsi[vsi->idx] = NULL; |
| 6045 | if (vsi->idx < pf->next_vsi) |
| 6046 | pf->next_vsi = vsi->idx; |
| 6047 | |
| 6048 | unlock_vsi: |
| 6049 | mutex_unlock(&pf->switch_mutex); |
| 6050 | free_vsi: |
| 6051 | kfree(vsi); |
| 6052 | |
| 6053 | return 0; |
| 6054 | } |
| 6055 | |
| 6056 | /** |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6057 | * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI |
| 6058 | * @vsi: the VSI being cleaned |
| 6059 | **/ |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 6060 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6061 | { |
| 6062 | int i; |
| 6063 | |
Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 6064 | if (vsi->tx_rings && vsi->tx_rings[0]) { |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 6065 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 6066 | kfree_rcu(vsi->tx_rings[i], rcu); |
| 6067 | vsi->tx_rings[i] = NULL; |
| 6068 | vsi->rx_rings[i] = NULL; |
| 6069 | } |
Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 6070 | } |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6071 | } |
| 6072 | |
| 6073 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6074 | * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI |
| 6075 | * @vsi: the VSI being configured |
| 6076 | **/ |
| 6077 | static int i40e_alloc_rings(struct i40e_vsi *vsi) |
| 6078 | { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 6079 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6080 | struct i40e_pf *pf = vsi->back; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6081 | int i; |
| 6082 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6083 | /* Set basic values in the rings to be used later during open() */ |
Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 6084 | for (i = 0; i < vsi->alloc_queue_pairs; i++) { |
Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 6085 | /* allocate space for both Tx and Rx in one shot */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6086 | tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); |
| 6087 | if (!tx_ring) |
| 6088 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6089 | |
| 6090 | tx_ring->queue_index = i; |
| 6091 | tx_ring->reg_idx = vsi->base_queue + i; |
| 6092 | tx_ring->ring_active = false; |
| 6093 | tx_ring->vsi = vsi; |
| 6094 | tx_ring->netdev = vsi->netdev; |
| 6095 | tx_ring->dev = &pf->pdev->dev; |
| 6096 | tx_ring->count = vsi->num_desc; |
| 6097 | tx_ring->size = 0; |
| 6098 | tx_ring->dcb_tc = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6099 | vsi->tx_rings[i] = tx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6100 | |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6101 | rx_ring = &tx_ring[1]; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6102 | rx_ring->queue_index = i; |
| 6103 | rx_ring->reg_idx = vsi->base_queue + i; |
| 6104 | rx_ring->ring_active = false; |
| 6105 | rx_ring->vsi = vsi; |
| 6106 | rx_ring->netdev = vsi->netdev; |
| 6107 | rx_ring->dev = &pf->pdev->dev; |
| 6108 | rx_ring->count = vsi->num_desc; |
| 6109 | rx_ring->size = 0; |
| 6110 | rx_ring->dcb_tc = 0; |
| 6111 | if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) |
| 6112 | set_ring_16byte_desc_enabled(rx_ring); |
| 6113 | else |
| 6114 | clear_ring_16byte_desc_enabled(rx_ring); |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6115 | vsi->rx_rings[i] = rx_ring; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | return 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 6119 | |
| 6120 | err_out: |
| 6121 | i40e_vsi_clear_rings(vsi); |
| 6122 | return -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | /** |
| 6126 | * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel |
| 6127 | * @pf: board private structure |
| 6128 | * @vectors: the number of MSI-X vectors to request |
| 6129 | * |
| 6130 | * Returns the number of vectors reserved, or error |
| 6131 | **/ |
| 6132 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) |
| 6133 | { |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 6134 | vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries, |
| 6135 | I40E_MIN_MSIX, vectors); |
| 6136 | if (vectors < 0) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6137 | dev_info(&pf->pdev->dev, |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 6138 | "MSI-X vector reservation failed: %d\n", vectors); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6139 | vectors = 0; |
| 6140 | } |
| 6141 | |
Alexander Gordeev | 7b37f37 | 2014-02-18 11:11:42 +0100 | [diff] [blame] | 6142 | pf->num_msix_entries = vectors; |
| 6143 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6144 | return vectors; |
| 6145 | } |
| 6146 | |
| 6147 | /** |
| 6148 | * i40e_init_msix - Setup the MSIX capability |
| 6149 | * @pf: board private structure |
| 6150 | * |
| 6151 | * Work with the OS to set up the MSIX vectors needed. |
| 6152 | * |
| 6153 | * Returns 0 on success, negative on failure |
| 6154 | **/ |
| 6155 | static int i40e_init_msix(struct i40e_pf *pf) |
| 6156 | { |
| 6157 | i40e_status err = 0; |
| 6158 | struct i40e_hw *hw = &pf->hw; |
| 6159 | int v_budget, i; |
| 6160 | int vec; |
| 6161 | |
| 6162 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) |
| 6163 | return -ENODEV; |
| 6164 | |
| 6165 | /* The number of vectors we'll request will be comprised of: |
| 6166 | * - Add 1 for "other" cause for Admin Queue events, etc. |
| 6167 | * - The number of LAN queue pairs |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6168 | * - Queues being used for RSS. |
| 6169 | * We don't need as many as max_rss_size vectors. |
| 6170 | * use rss_size instead in the calculation since that |
| 6171 | * is governed by number of cpus in the system. |
| 6172 | * - assumes symmetric Tx/Rx pairing |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6173 | * - The number of VMDq pairs |
| 6174 | * Once we count this up, try the request. |
| 6175 | * |
| 6176 | * If we can't get what we want, we'll simplify to nearly nothing |
| 6177 | * and try again. If that still fails, we punt. |
| 6178 | */ |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6179 | pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6180 | pf->num_vmdq_msix = pf->num_vmdq_qps; |
| 6181 | v_budget = 1 + pf->num_lan_msix; |
| 6182 | v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix); |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 6183 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6184 | v_budget++; |
| 6185 | |
| 6186 | /* Scale down if necessary, and the rings will share vectors */ |
| 6187 | v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors); |
| 6188 | |
| 6189 | pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), |
| 6190 | GFP_KERNEL); |
| 6191 | if (!pf->msix_entries) |
| 6192 | return -ENOMEM; |
| 6193 | |
| 6194 | for (i = 0; i < v_budget; i++) |
| 6195 | pf->msix_entries[i].entry = i; |
| 6196 | vec = i40e_reserve_msix_vectors(pf, v_budget); |
| 6197 | if (vec < I40E_MIN_MSIX) { |
| 6198 | pf->flags &= ~I40E_FLAG_MSIX_ENABLED; |
| 6199 | kfree(pf->msix_entries); |
| 6200 | pf->msix_entries = NULL; |
| 6201 | return -ENODEV; |
| 6202 | |
| 6203 | } else if (vec == I40E_MIN_MSIX) { |
| 6204 | /* Adjust for minimal MSIX use */ |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 6205 | dev_info(&pf->pdev->dev, "Features disabled, not enough MSI-X vectors\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6206 | pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; |
| 6207 | pf->num_vmdq_vsis = 0; |
| 6208 | pf->num_vmdq_qps = 0; |
| 6209 | pf->num_vmdq_msix = 0; |
| 6210 | pf->num_lan_qps = 1; |
| 6211 | pf->num_lan_msix = 1; |
| 6212 | |
| 6213 | } else if (vec != v_budget) { |
| 6214 | /* Scale vector usage down */ |
| 6215 | pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */ |
| 6216 | vec--; /* reserve the misc vector */ |
| 6217 | |
| 6218 | /* partition out the remaining vectors */ |
| 6219 | switch (vec) { |
| 6220 | case 2: |
| 6221 | pf->num_vmdq_vsis = 1; |
| 6222 | pf->num_lan_msix = 1; |
| 6223 | break; |
| 6224 | case 3: |
| 6225 | pf->num_vmdq_vsis = 1; |
| 6226 | pf->num_lan_msix = 2; |
| 6227 | break; |
| 6228 | default: |
| 6229 | pf->num_lan_msix = min_t(int, (vec / 2), |
| 6230 | pf->num_lan_qps); |
| 6231 | pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix), |
| 6232 | I40E_DEFAULT_NUM_VMDQ_VSI); |
| 6233 | break; |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | return err; |
| 6238 | } |
| 6239 | |
| 6240 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 6241 | * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6242 | * @vsi: the VSI being configured |
| 6243 | * @v_idx: index of the vector in the vsi struct |
| 6244 | * |
| 6245 | * We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 6246 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 6247 | static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6248 | { |
| 6249 | struct i40e_q_vector *q_vector; |
| 6250 | |
| 6251 | /* allocate q_vector */ |
| 6252 | q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); |
| 6253 | if (!q_vector) |
| 6254 | return -ENOMEM; |
| 6255 | |
| 6256 | q_vector->vsi = vsi; |
| 6257 | q_vector->v_idx = v_idx; |
| 6258 | cpumask_set_cpu(v_idx, &q_vector->affinity_mask); |
| 6259 | if (vsi->netdev) |
| 6260 | netif_napi_add(vsi->netdev, &q_vector->napi, |
| 6261 | i40e_napi_poll, vsi->work_limit); |
| 6262 | |
Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 6263 | q_vector->rx.latency_range = I40E_LOW_LATENCY; |
| 6264 | q_vector->tx.latency_range = I40E_LOW_LATENCY; |
| 6265 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6266 | /* tie q_vector and vsi together */ |
| 6267 | vsi->q_vectors[v_idx] = q_vector; |
| 6268 | |
| 6269 | return 0; |
| 6270 | } |
| 6271 | |
| 6272 | /** |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 6273 | * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6274 | * @vsi: the VSI being configured |
| 6275 | * |
| 6276 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 6277 | * return -ENOMEM. |
| 6278 | **/ |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 6279 | static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6280 | { |
| 6281 | struct i40e_pf *pf = vsi->back; |
| 6282 | int v_idx, num_q_vectors; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6283 | int err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6284 | |
| 6285 | /* if not MSIX, give the one vector only to the LAN VSI */ |
| 6286 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) |
| 6287 | num_q_vectors = vsi->num_q_vectors; |
| 6288 | else if (vsi == pf->vsi[pf->lan_vsi]) |
| 6289 | num_q_vectors = 1; |
| 6290 | else |
| 6291 | return -EINVAL; |
| 6292 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6293 | for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 6294 | err = i40e_vsi_alloc_q_vector(vsi, v_idx); |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6295 | if (err) |
| 6296 | goto err_out; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | return 0; |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6300 | |
| 6301 | err_out: |
| 6302 | while (v_idx--) |
| 6303 | i40e_free_q_vector(vsi, v_idx); |
| 6304 | |
| 6305 | return err; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6306 | } |
| 6307 | |
| 6308 | /** |
| 6309 | * i40e_init_interrupt_scheme - Determine proper interrupt scheme |
| 6310 | * @pf: board private structure to initialize |
| 6311 | **/ |
| 6312 | static void i40e_init_interrupt_scheme(struct i40e_pf *pf) |
| 6313 | { |
| 6314 | int err = 0; |
| 6315 | |
| 6316 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 6317 | err = i40e_init_msix(pf); |
| 6318 | if (err) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 6319 | pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | |
| 6320 | I40E_FLAG_RSS_ENABLED | |
| 6321 | I40E_FLAG_DCB_ENABLED | |
| 6322 | I40E_FLAG_SRIOV_ENABLED | |
| 6323 | I40E_FLAG_FD_SB_ENABLED | |
| 6324 | I40E_FLAG_FD_ATR_ENABLED | |
| 6325 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6326 | |
| 6327 | /* rework the queue expectations without MSIX */ |
| 6328 | i40e_determine_queue_usage(pf); |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 6333 | (pf->flags & I40E_FLAG_MSI_ENABLED)) { |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 6334 | dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6335 | err = pci_enable_msi(pf->pdev); |
| 6336 | if (err) { |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6337 | dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6338 | pf->flags &= ~I40E_FLAG_MSI_ENABLED; |
| 6339 | } |
| 6340 | } |
| 6341 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6342 | if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 6343 | dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n"); |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6344 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6345 | /* track first vector for misc interrupts */ |
| 6346 | err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1); |
| 6347 | } |
| 6348 | |
| 6349 | /** |
| 6350 | * i40e_setup_misc_vector - Setup the misc vector to handle non queue events |
| 6351 | * @pf: board private structure |
| 6352 | * |
| 6353 | * This sets up the handler for MSIX 0, which is used to manage the |
| 6354 | * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| 6355 | * when in MSI or Legacy interrupt mode. |
| 6356 | **/ |
| 6357 | static int i40e_setup_misc_vector(struct i40e_pf *pf) |
| 6358 | { |
| 6359 | struct i40e_hw *hw = &pf->hw; |
| 6360 | int err = 0; |
| 6361 | |
| 6362 | /* Only request the irq if this is the first time through, and |
| 6363 | * not when we're rebuilding after a Reset |
| 6364 | */ |
| 6365 | if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { |
| 6366 | err = request_irq(pf->msix_entries[0].vector, |
| 6367 | i40e_intr, 0, pf->misc_int_name, pf); |
| 6368 | if (err) { |
| 6369 | dev_info(&pf->pdev->dev, |
Catherine Sullivan | 77fa28b | 2014-02-20 19:29:17 -0800 | [diff] [blame] | 6370 | "request_irq for %s failed: %d\n", |
| 6371 | pf->misc_int_name, err); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6372 | return -EFAULT; |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | i40e_enable_misc_int_causes(hw); |
| 6377 | |
| 6378 | /* associate no queues to the misc vector */ |
| 6379 | wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); |
| 6380 | wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); |
| 6381 | |
| 6382 | i40e_flush(hw); |
| 6383 | |
| 6384 | i40e_irq_dynamic_enable_icr0(pf); |
| 6385 | |
| 6386 | return err; |
| 6387 | } |
| 6388 | |
| 6389 | /** |
| 6390 | * i40e_config_rss - Prepare for RSS if used |
| 6391 | * @pf: board private structure |
| 6392 | **/ |
| 6393 | static int i40e_config_rss(struct i40e_pf *pf) |
| 6394 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6395 | /* Set of random keys generated using kernel random number generator */ |
| 6396 | static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, |
| 6397 | 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, |
| 6398 | 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, |
| 6399 | 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; |
Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 6400 | struct i40e_hw *hw = &pf->hw; |
| 6401 | u32 lut = 0; |
| 6402 | int i, j; |
| 6403 | u64 hena; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6404 | |
| 6405 | /* Fill out hash function seed */ |
| 6406 | for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) |
| 6407 | wr32(hw, I40E_PFQF_HKEY(i), seed[i]); |
| 6408 | |
| 6409 | /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ |
| 6410 | hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 6411 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
Mitch Williams | 12dc4fe | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 6412 | hena |= I40E_DEFAULT_RSS_HENA; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6413 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 6414 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 6415 | |
| 6416 | /* Populate the LUT with max no. of queues in round robin fashion */ |
| 6417 | for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { |
| 6418 | |
| 6419 | /* The assumption is that lan qp count will be the highest |
| 6420 | * qp count for any PF VSI that needs RSS. |
| 6421 | * If multiple VSIs need RSS support, all the qp counts |
| 6422 | * for those VSIs should be a power of 2 for RSS to work. |
| 6423 | * If LAN VSI is the only consumer for RSS then this requirement |
| 6424 | * is not necessary. |
| 6425 | */ |
| 6426 | if (j == pf->rss_size) |
| 6427 | j = 0; |
| 6428 | /* lut = 4-byte sliding window of 4 lut entries */ |
| 6429 | lut = (lut << 8) | (j & |
| 6430 | ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); |
| 6431 | /* On i = 3, we have 4 entries in lut; write to the register */ |
| 6432 | if ((i & 3) == 3) |
| 6433 | wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); |
| 6434 | } |
| 6435 | i40e_flush(hw); |
| 6436 | |
| 6437 | return 0; |
| 6438 | } |
| 6439 | |
| 6440 | /** |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6441 | * i40e_reconfig_rss_queues - change number of queues for rss and rebuild |
| 6442 | * @pf: board private structure |
| 6443 | * @queue_count: the requested queue count for rss. |
| 6444 | * |
| 6445 | * returns 0 if rss is not enabled, if enabled returns the final rss queue |
| 6446 | * count which may be different from the requested queue count. |
| 6447 | **/ |
| 6448 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) |
| 6449 | { |
| 6450 | if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 6451 | return 0; |
| 6452 | |
| 6453 | queue_count = min_t(int, queue_count, pf->rss_size_max); |
| 6454 | queue_count = rounddown_pow_of_two(queue_count); |
| 6455 | |
| 6456 | if (queue_count != pf->rss_size) { |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6457 | i40e_prep_for_reset(pf); |
| 6458 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6459 | pf->rss_size = queue_count; |
| 6460 | |
| 6461 | i40e_reset_and_rebuild(pf, true); |
| 6462 | i40e_config_rss(pf); |
| 6463 | } |
| 6464 | dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size); |
| 6465 | return pf->rss_size; |
| 6466 | } |
| 6467 | |
| 6468 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6469 | * i40e_sw_init - Initialize general software structures (struct i40e_pf) |
| 6470 | * @pf: board private structure to initialize |
| 6471 | * |
| 6472 | * i40e_sw_init initializes the Adapter private data structure. |
| 6473 | * Fields are initialized based on PCI device information and |
| 6474 | * OS network device settings (MTU size). |
| 6475 | **/ |
| 6476 | static int i40e_sw_init(struct i40e_pf *pf) |
| 6477 | { |
| 6478 | int err = 0; |
| 6479 | int size; |
| 6480 | |
| 6481 | pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, |
| 6482 | (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); |
Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 6483 | pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6484 | if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { |
| 6485 | if (I40E_DEBUG_USER & debug) |
| 6486 | pf->hw.debug_mask = debug; |
| 6487 | pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), |
| 6488 | I40E_DEFAULT_MSG_ENABLE); |
| 6489 | } |
| 6490 | |
| 6491 | /* Set default capability flags */ |
| 6492 | pf->flags = I40E_FLAG_RX_CSUM_ENABLED | |
| 6493 | I40E_FLAG_MSI_ENABLED | |
| 6494 | I40E_FLAG_MSIX_ENABLED | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6495 | I40E_FLAG_RX_1BUF_ENABLED; |
| 6496 | |
Mitch Williams | ca99eb9 | 2014-04-04 04:43:07 +0000 | [diff] [blame] | 6497 | /* Set default ITR */ |
| 6498 | pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF; |
| 6499 | pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF; |
| 6500 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6501 | /* Depending on PF configurations, it is possible that the RSS |
| 6502 | * maximum might end up larger than the available queues |
| 6503 | */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6504 | pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width; |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 6505 | pf->rss_size_max = min_t(int, pf->rss_size_max, |
| 6506 | pf->hw.func_caps.num_tx_qp); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6507 | if (pf->hw.func_caps.rss) { |
| 6508 | pf->flags |= I40E_FLAG_RSS_ENABLED; |
Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 6509 | pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus()); |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6510 | pf->rss_size = rounddown_pow_of_two(pf->rss_size); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6511 | } else { |
| 6512 | pf->rss_size = 1; |
| 6513 | } |
| 6514 | |
Catherine Sullivan | 2050bc6 | 2013-12-18 13:46:03 +0000 | [diff] [blame] | 6515 | /* MFP mode enabled */ |
| 6516 | if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { |
| 6517 | pf->flags |= I40E_FLAG_MFP_ENABLED; |
| 6518 | dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); |
| 6519 | } |
| 6520 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6521 | /* FW/NVM is not yet fixed in this regard */ |
| 6522 | if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || |
| 6523 | (pf->hw.func_caps.fd_filters_best_effort > 0)) { |
| 6524 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 6525 | pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6526 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) { |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 6527 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6528 | } else { |
| 6529 | dev_info(&pf->pdev->dev, |
Anjali Singhai Jain | 0b67584 | 2014-03-06 08:59:51 +0000 | [diff] [blame] | 6530 | "Flow Director Sideband mode Disabled in MFP mode\n"); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6531 | } |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 6532 | pf->fdir_pf_filter_count = |
| 6533 | pf->hw.func_caps.fd_filters_guaranteed; |
| 6534 | pf->hw.fdir_shared_filter_count = |
| 6535 | pf->hw.func_caps.fd_filters_best_effort; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6536 | } |
| 6537 | |
| 6538 | if (pf->hw.func_caps.vmdq) { |
| 6539 | pf->flags |= I40E_FLAG_VMDQ_ENABLED; |
| 6540 | pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; |
| 6541 | pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; |
| 6542 | } |
| 6543 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6544 | #ifdef CONFIG_PCI_IOV |
| 6545 | if (pf->hw.func_caps.num_vfs) { |
| 6546 | pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; |
| 6547 | pf->flags |= I40E_FLAG_SRIOV_ENABLED; |
| 6548 | pf->num_req_vfs = min_t(int, |
| 6549 | pf->hw.func_caps.num_vfs, |
| 6550 | I40E_MAX_VF_COUNT); |
| 6551 | } |
| 6552 | #endif /* CONFIG_PCI_IOV */ |
| 6553 | pf->eeprom_version = 0xDEAD; |
| 6554 | pf->lan_veb = I40E_NO_VEB; |
| 6555 | pf->lan_vsi = I40E_NO_VSI; |
| 6556 | |
| 6557 | /* set up queue assignment tracking */ |
| 6558 | size = sizeof(struct i40e_lump_tracking) |
| 6559 | + (sizeof(u16) * pf->hw.func_caps.num_tx_qp); |
| 6560 | pf->qp_pile = kzalloc(size, GFP_KERNEL); |
| 6561 | if (!pf->qp_pile) { |
| 6562 | err = -ENOMEM; |
| 6563 | goto sw_init_done; |
| 6564 | } |
| 6565 | pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; |
| 6566 | pf->qp_pile->search_hint = 0; |
| 6567 | |
| 6568 | /* set up vector assignment tracking */ |
| 6569 | size = sizeof(struct i40e_lump_tracking) |
| 6570 | + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors); |
| 6571 | pf->irq_pile = kzalloc(size, GFP_KERNEL); |
| 6572 | if (!pf->irq_pile) { |
| 6573 | kfree(pf->qp_pile); |
| 6574 | err = -ENOMEM; |
| 6575 | goto sw_init_done; |
| 6576 | } |
| 6577 | pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors; |
| 6578 | pf->irq_pile->search_hint = 0; |
| 6579 | |
| 6580 | mutex_init(&pf->switch_mutex); |
| 6581 | |
| 6582 | sw_init_done: |
| 6583 | return err; |
| 6584 | } |
| 6585 | |
| 6586 | /** |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 6587 | * i40e_set_ntuple - set the ntuple feature flag and take action |
| 6588 | * @pf: board private structure to initialize |
| 6589 | * @features: the feature set that the stack is suggesting |
| 6590 | * |
| 6591 | * returns a bool to indicate if reset needs to happen |
| 6592 | **/ |
| 6593 | bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features) |
| 6594 | { |
| 6595 | bool need_reset = false; |
| 6596 | |
| 6597 | /* Check if Flow Director n-tuple support was enabled or disabled. If |
| 6598 | * the state changed, we need to reset. |
| 6599 | */ |
| 6600 | if (features & NETIF_F_NTUPLE) { |
| 6601 | /* Enable filters and mark for reset */ |
| 6602 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 6603 | need_reset = true; |
| 6604 | pf->flags |= I40E_FLAG_FD_SB_ENABLED; |
| 6605 | } else { |
| 6606 | /* turn off filters, mark for reset and clear SW filter list */ |
| 6607 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 6608 | need_reset = true; |
| 6609 | i40e_fdir_filter_exit(pf); |
| 6610 | } |
| 6611 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 6612 | /* if ATR was disabled it can be re-enabled. */ |
| 6613 | if (!(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) |
| 6614 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 6615 | } |
| 6616 | return need_reset; |
| 6617 | } |
| 6618 | |
| 6619 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6620 | * i40e_set_features - set the netdev feature flags |
| 6621 | * @netdev: ptr to the netdev being adjusted |
| 6622 | * @features: the feature set that the stack is suggesting |
| 6623 | **/ |
| 6624 | static int i40e_set_features(struct net_device *netdev, |
| 6625 | netdev_features_t features) |
| 6626 | { |
| 6627 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6628 | struct i40e_vsi *vsi = np->vsi; |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 6629 | struct i40e_pf *pf = vsi->back; |
| 6630 | bool need_reset; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6631 | |
| 6632 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 6633 | i40e_vlan_stripping_enable(vsi); |
| 6634 | else |
| 6635 | i40e_vlan_stripping_disable(vsi); |
| 6636 | |
Anjali Singhai Jain | 7c3c288 | 2014-02-14 02:14:38 +0000 | [diff] [blame] | 6637 | need_reset = i40e_set_ntuple(pf, features); |
| 6638 | |
| 6639 | if (need_reset) |
| 6640 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
| 6641 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6642 | return 0; |
| 6643 | } |
| 6644 | |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6645 | #ifdef CONFIG_I40E_VXLAN |
| 6646 | /** |
| 6647 | * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port |
| 6648 | * @pf: board private structure |
| 6649 | * @port: The UDP port to look up |
| 6650 | * |
| 6651 | * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found |
| 6652 | **/ |
| 6653 | static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port) |
| 6654 | { |
| 6655 | u8 i; |
| 6656 | |
| 6657 | for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { |
| 6658 | if (pf->vxlan_ports[i] == port) |
| 6659 | return i; |
| 6660 | } |
| 6661 | |
| 6662 | return i; |
| 6663 | } |
| 6664 | |
| 6665 | /** |
| 6666 | * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up |
| 6667 | * @netdev: This physical port's netdev |
| 6668 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 6669 | * @port: New UDP port number that VXLAN started listening to |
| 6670 | **/ |
| 6671 | static void i40e_add_vxlan_port(struct net_device *netdev, |
| 6672 | sa_family_t sa_family, __be16 port) |
| 6673 | { |
| 6674 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6675 | struct i40e_vsi *vsi = np->vsi; |
| 6676 | struct i40e_pf *pf = vsi->back; |
| 6677 | u8 next_idx; |
| 6678 | u8 idx; |
| 6679 | |
| 6680 | if (sa_family == AF_INET6) |
| 6681 | return; |
| 6682 | |
| 6683 | idx = i40e_get_vxlan_port_idx(pf, port); |
| 6684 | |
| 6685 | /* Check if port already exists */ |
| 6686 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 6687 | netdev_info(netdev, "Port %d already offloaded\n", ntohs(port)); |
| 6688 | return; |
| 6689 | } |
| 6690 | |
| 6691 | /* Now check if there is space to add the new port */ |
| 6692 | next_idx = i40e_get_vxlan_port_idx(pf, 0); |
| 6693 | |
| 6694 | if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 6695 | netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n", |
| 6696 | ntohs(port)); |
| 6697 | return; |
| 6698 | } |
| 6699 | |
| 6700 | /* New port: add it and mark its index in the bitmap */ |
| 6701 | pf->vxlan_ports[next_idx] = port; |
| 6702 | pf->pending_vxlan_bitmap |= (1 << next_idx); |
| 6703 | |
| 6704 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; |
| 6705 | } |
| 6706 | |
| 6707 | /** |
| 6708 | * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away |
| 6709 | * @netdev: This physical port's netdev |
| 6710 | * @sa_family: Socket Family that VXLAN is notifying us about |
| 6711 | * @port: UDP port number that VXLAN stopped listening to |
| 6712 | **/ |
| 6713 | static void i40e_del_vxlan_port(struct net_device *netdev, |
| 6714 | sa_family_t sa_family, __be16 port) |
| 6715 | { |
| 6716 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 6717 | struct i40e_vsi *vsi = np->vsi; |
| 6718 | struct i40e_pf *pf = vsi->back; |
| 6719 | u8 idx; |
| 6720 | |
| 6721 | if (sa_family == AF_INET6) |
| 6722 | return; |
| 6723 | |
| 6724 | idx = i40e_get_vxlan_port_idx(pf, port); |
| 6725 | |
| 6726 | /* Check if port already exists */ |
| 6727 | if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { |
| 6728 | /* if port exists, set it to 0 (mark for deletion) |
| 6729 | * and make it pending |
| 6730 | */ |
| 6731 | pf->vxlan_ports[idx] = 0; |
| 6732 | |
| 6733 | pf->pending_vxlan_bitmap |= (1 << idx); |
| 6734 | |
| 6735 | pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; |
| 6736 | } else { |
| 6737 | netdev_warn(netdev, "Port %d was not found, not deleting\n", |
| 6738 | ntohs(port)); |
| 6739 | } |
| 6740 | } |
| 6741 | |
| 6742 | #endif |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 6743 | #ifdef HAVE_FDB_OPS |
| 6744 | #ifdef USE_CONST_DEV_UC_CHAR |
| 6745 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 6746 | struct net_device *dev, |
| 6747 | const unsigned char *addr, |
| 6748 | u16 flags) |
| 6749 | #else |
| 6750 | static int i40e_ndo_fdb_add(struct ndmsg *ndm, |
| 6751 | struct net_device *dev, |
| 6752 | unsigned char *addr, |
| 6753 | u16 flags) |
| 6754 | #endif |
| 6755 | { |
| 6756 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 6757 | struct i40e_pf *pf = np->vsi->back; |
| 6758 | int err = 0; |
| 6759 | |
| 6760 | if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED)) |
| 6761 | return -EOPNOTSUPP; |
| 6762 | |
| 6763 | /* Hardware does not support aging addresses so if a |
| 6764 | * ndm_state is given only allow permanent addresses |
| 6765 | */ |
| 6766 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
| 6767 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 6768 | return -EINVAL; |
| 6769 | } |
| 6770 | |
| 6771 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) |
| 6772 | err = dev_uc_add_excl(dev, addr); |
| 6773 | else if (is_multicast_ether_addr(addr)) |
| 6774 | err = dev_mc_add_excl(dev, addr); |
| 6775 | else |
| 6776 | err = -EINVAL; |
| 6777 | |
| 6778 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 6779 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 6780 | err = 0; |
| 6781 | |
| 6782 | return err; |
| 6783 | } |
| 6784 | |
| 6785 | #ifndef USE_DEFAULT_FDB_DEL_DUMP |
| 6786 | #ifdef USE_CONST_DEV_UC_CHAR |
| 6787 | static int i40e_ndo_fdb_del(struct ndmsg *ndm, |
| 6788 | struct net_device *dev, |
| 6789 | const unsigned char *addr) |
| 6790 | #else |
| 6791 | static int i40e_ndo_fdb_del(struct ndmsg *ndm, |
| 6792 | struct net_device *dev, |
| 6793 | unsigned char *addr) |
| 6794 | #endif |
| 6795 | { |
| 6796 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 6797 | struct i40e_pf *pf = np->vsi->back; |
| 6798 | int err = -EOPNOTSUPP; |
| 6799 | |
| 6800 | if (ndm->ndm_state & NUD_PERMANENT) { |
| 6801 | netdev_info(dev, "FDB only supports static addresses\n"); |
| 6802 | return -EINVAL; |
| 6803 | } |
| 6804 | |
| 6805 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 6806 | if (is_unicast_ether_addr(addr)) |
| 6807 | err = dev_uc_del(dev, addr); |
| 6808 | else if (is_multicast_ether_addr(addr)) |
| 6809 | err = dev_mc_del(dev, addr); |
| 6810 | else |
| 6811 | err = -EINVAL; |
| 6812 | } |
| 6813 | |
| 6814 | return err; |
| 6815 | } |
| 6816 | |
| 6817 | static int i40e_ndo_fdb_dump(struct sk_buff *skb, |
| 6818 | struct netlink_callback *cb, |
| 6819 | struct net_device *dev, |
| 6820 | int idx) |
| 6821 | { |
| 6822 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 6823 | struct i40e_pf *pf = np->vsi->back; |
| 6824 | |
| 6825 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) |
| 6826 | idx = ndo_dflt_fdb_dump(skb, cb, dev, idx); |
| 6827 | |
| 6828 | return idx; |
| 6829 | } |
| 6830 | |
| 6831 | #endif /* USE_DEFAULT_FDB_DEL_DUMP */ |
| 6832 | #endif /* HAVE_FDB_OPS */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6833 | static const struct net_device_ops i40e_netdev_ops = { |
| 6834 | .ndo_open = i40e_open, |
| 6835 | .ndo_stop = i40e_close, |
| 6836 | .ndo_start_xmit = i40e_lan_xmit_frame, |
| 6837 | .ndo_get_stats64 = i40e_get_netdev_stats_struct, |
| 6838 | .ndo_set_rx_mode = i40e_set_rx_mode, |
| 6839 | .ndo_validate_addr = eth_validate_addr, |
| 6840 | .ndo_set_mac_address = i40e_set_mac, |
| 6841 | .ndo_change_mtu = i40e_change_mtu, |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 6842 | .ndo_do_ioctl = i40e_ioctl, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6843 | .ndo_tx_timeout = i40e_tx_timeout, |
| 6844 | .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid, |
| 6845 | .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid, |
| 6846 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6847 | .ndo_poll_controller = i40e_netpoll, |
| 6848 | #endif |
| 6849 | .ndo_setup_tc = i40e_setup_tc, |
| 6850 | .ndo_set_features = i40e_set_features, |
| 6851 | .ndo_set_vf_mac = i40e_ndo_set_vf_mac, |
| 6852 | .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 6853 | .ndo_set_vf_rate = i40e_ndo_set_vf_bw, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6854 | .ndo_get_vf_config = i40e_ndo_get_vf_config, |
Mitch Williams | 588aefa | 2014-02-11 08:27:49 +0000 | [diff] [blame] | 6855 | .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state, |
Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6856 | #ifdef CONFIG_I40E_VXLAN |
| 6857 | .ndo_add_vxlan_port = i40e_add_vxlan_port, |
| 6858 | .ndo_del_vxlan_port = i40e_del_vxlan_port, |
| 6859 | #endif |
Greg Rose | 4ba0dea | 2014-03-06 08:59:55 +0000 | [diff] [blame] | 6860 | #ifdef HAVE_FDB_OPS |
| 6861 | .ndo_fdb_add = i40e_ndo_fdb_add, |
| 6862 | #ifndef USE_DEFAULT_FDB_DEL_DUMP |
| 6863 | .ndo_fdb_del = i40e_ndo_fdb_del, |
| 6864 | .ndo_fdb_dump = i40e_ndo_fdb_dump, |
| 6865 | #endif |
| 6866 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6867 | }; |
| 6868 | |
| 6869 | /** |
| 6870 | * i40e_config_netdev - Setup the netdev flags |
| 6871 | * @vsi: the VSI being configured |
| 6872 | * |
| 6873 | * Returns 0 on success, negative value on failure |
| 6874 | **/ |
| 6875 | static int i40e_config_netdev(struct i40e_vsi *vsi) |
| 6876 | { |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 6877 | u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6878 | struct i40e_pf *pf = vsi->back; |
| 6879 | struct i40e_hw *hw = &pf->hw; |
| 6880 | struct i40e_netdev_priv *np; |
| 6881 | struct net_device *netdev; |
| 6882 | u8 mac_addr[ETH_ALEN]; |
| 6883 | int etherdev_size; |
| 6884 | |
| 6885 | etherdev_size = sizeof(struct i40e_netdev_priv); |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6886 | netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6887 | if (!netdev) |
| 6888 | return -ENOMEM; |
| 6889 | |
| 6890 | vsi->netdev = netdev; |
| 6891 | np = netdev_priv(netdev); |
| 6892 | np->vsi = vsi; |
| 6893 | |
Or Gerlitz | d70e941 | 2014-03-18 10:36:45 +0200 | [diff] [blame] | 6894 | netdev->hw_enc_features |= NETIF_F_IP_CSUM | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6895 | NETIF_F_GSO_UDP_TUNNEL | |
Or Gerlitz | d70e941 | 2014-03-18 10:36:45 +0200 | [diff] [blame] | 6896 | NETIF_F_TSO; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6897 | |
| 6898 | netdev->features = NETIF_F_SG | |
| 6899 | NETIF_F_IP_CSUM | |
| 6900 | NETIF_F_SCTP_CSUM | |
| 6901 | NETIF_F_HIGHDMA | |
| 6902 | NETIF_F_GSO_UDP_TUNNEL | |
| 6903 | NETIF_F_HW_VLAN_CTAG_TX | |
| 6904 | NETIF_F_HW_VLAN_CTAG_RX | |
| 6905 | NETIF_F_HW_VLAN_CTAG_FILTER | |
| 6906 | NETIF_F_IPV6_CSUM | |
| 6907 | NETIF_F_TSO | |
Jesse Brandeburg | 059dab6 | 2014-04-01 09:07:20 +0000 | [diff] [blame] | 6908 | NETIF_F_TSO_ECN | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6909 | NETIF_F_TSO6 | |
| 6910 | NETIF_F_RXCSUM | |
| 6911 | NETIF_F_RXHASH | |
| 6912 | 0; |
| 6913 | |
Anjali Singhai Jain | 2e86a0b | 2014-04-01 07:11:53 +0000 | [diff] [blame] | 6914 | if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) |
| 6915 | netdev->features |= NETIF_F_NTUPLE; |
| 6916 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6917 | /* copy netdev features into list of user selectable features */ |
| 6918 | netdev->hw_features |= netdev->features; |
| 6919 | |
| 6920 | if (vsi->type == I40E_VSI_MAIN) { |
| 6921 | SET_NETDEV_DEV(netdev, &pf->pdev->dev); |
| 6922 | memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); |
| 6923 | } else { |
| 6924 | /* relate the VSI_VMDQ name to the VSI_MAIN name */ |
| 6925 | snprintf(netdev->name, IFNAMSIZ, "%sv%%d", |
| 6926 | pf->vsi[pf->lan_vsi]->netdev->name); |
| 6927 | random_ether_addr(mac_addr); |
| 6928 | i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); |
| 6929 | } |
Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 6930 | i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6931 | |
| 6932 | memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); |
| 6933 | memcpy(netdev->perm_addr, mac_addr, ETH_ALEN); |
| 6934 | /* vlan gets same features (except vlan offload) |
| 6935 | * after any tweaks for specific VSI types |
| 6936 | */ |
| 6937 | netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 6938 | NETIF_F_HW_VLAN_CTAG_RX | |
| 6939 | NETIF_F_HW_VLAN_CTAG_FILTER); |
| 6940 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 6941 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
| 6942 | /* Setup netdev TC information */ |
| 6943 | i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); |
| 6944 | |
| 6945 | netdev->netdev_ops = &i40e_netdev_ops; |
| 6946 | netdev->watchdog_timeo = 5 * HZ; |
| 6947 | i40e_set_ethtool_ops(netdev); |
| 6948 | |
| 6949 | return 0; |
| 6950 | } |
| 6951 | |
| 6952 | /** |
| 6953 | * i40e_vsi_delete - Delete a VSI from the switch |
| 6954 | * @vsi: the VSI being removed |
| 6955 | * |
| 6956 | * Returns 0 on success, negative value on failure |
| 6957 | **/ |
| 6958 | static void i40e_vsi_delete(struct i40e_vsi *vsi) |
| 6959 | { |
| 6960 | /* remove default VSI is not allowed */ |
| 6961 | if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) |
| 6962 | return; |
| 6963 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6964 | i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | /** |
| 6968 | * i40e_add_vsi - Add a VSI to the switch |
| 6969 | * @vsi: the VSI being configured |
| 6970 | * |
| 6971 | * This initializes a VSI context depending on the VSI type to be added and |
| 6972 | * passes it down to the add_vsi aq command. |
| 6973 | **/ |
| 6974 | static int i40e_add_vsi(struct i40e_vsi *vsi) |
| 6975 | { |
| 6976 | int ret = -ENODEV; |
| 6977 | struct i40e_mac_filter *f, *ftmp; |
| 6978 | struct i40e_pf *pf = vsi->back; |
| 6979 | struct i40e_hw *hw = &pf->hw; |
| 6980 | struct i40e_vsi_context ctxt; |
| 6981 | u8 enabled_tc = 0x1; /* TC0 enabled */ |
| 6982 | int f_count = 0; |
| 6983 | |
| 6984 | memset(&ctxt, 0, sizeof(ctxt)); |
| 6985 | switch (vsi->type) { |
| 6986 | case I40E_VSI_MAIN: |
| 6987 | /* The PF's main VSI is already setup as part of the |
| 6988 | * device initialization, so we'll not bother with |
| 6989 | * the add_vsi call, but we will retrieve the current |
| 6990 | * VSI context. |
| 6991 | */ |
| 6992 | ctxt.seid = pf->main_vsi_seid; |
| 6993 | ctxt.pf_num = pf->hw.pf_id; |
| 6994 | ctxt.vf_num = 0; |
| 6995 | ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); |
| 6996 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
| 6997 | if (ret) { |
| 6998 | dev_info(&pf->pdev->dev, |
| 6999 | "couldn't get pf vsi config, err %d, aq_err %d\n", |
| 7000 | ret, pf->hw.aq.asq_last_status); |
| 7001 | return -ENOENT; |
| 7002 | } |
| 7003 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 7004 | vsi->info.valid_sections = 0; |
| 7005 | |
| 7006 | vsi->seid = ctxt.seid; |
| 7007 | vsi->id = ctxt.vsi_number; |
| 7008 | |
| 7009 | enabled_tc = i40e_pf_get_tc_map(pf); |
| 7010 | |
| 7011 | /* MFP mode setup queue map and update VSI */ |
| 7012 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 7013 | memset(&ctxt, 0, sizeof(ctxt)); |
| 7014 | ctxt.seid = pf->main_vsi_seid; |
| 7015 | ctxt.pf_num = pf->hw.pf_id; |
| 7016 | ctxt.vf_num = 0; |
| 7017 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); |
| 7018 | ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); |
| 7019 | if (ret) { |
| 7020 | dev_info(&pf->pdev->dev, |
| 7021 | "update vsi failed, aq_err=%d\n", |
| 7022 | pf->hw.aq.asq_last_status); |
| 7023 | ret = -ENOENT; |
| 7024 | goto err; |
| 7025 | } |
| 7026 | /* update the local VSI info queue map */ |
| 7027 | i40e_vsi_update_queue_map(vsi, &ctxt); |
| 7028 | vsi->info.valid_sections = 0; |
| 7029 | } else { |
| 7030 | /* Default/Main VSI is only enabled for TC0 |
| 7031 | * reconfigure it to enable all TCs that are |
| 7032 | * available on the port in SFP mode. |
| 7033 | */ |
| 7034 | ret = i40e_vsi_config_tc(vsi, enabled_tc); |
| 7035 | if (ret) { |
| 7036 | dev_info(&pf->pdev->dev, |
| 7037 | "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", |
| 7038 | enabled_tc, ret, |
| 7039 | pf->hw.aq.asq_last_status); |
| 7040 | ret = -ENOENT; |
| 7041 | } |
| 7042 | } |
| 7043 | break; |
| 7044 | |
| 7045 | case I40E_VSI_FDIR: |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7046 | ctxt.pf_num = hw->pf_id; |
| 7047 | ctxt.vf_num = 0; |
| 7048 | ctxt.uplink_seid = vsi->uplink_seid; |
| 7049 | ctxt.connection_type = 0x1; /* regular data port */ |
| 7050 | ctxt.flags = I40E_AQ_VSI_TYPE_PF; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7051 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7052 | break; |
| 7053 | |
| 7054 | case I40E_VSI_VMDQ2: |
| 7055 | ctxt.pf_num = hw->pf_id; |
| 7056 | ctxt.vf_num = 0; |
| 7057 | ctxt.uplink_seid = vsi->uplink_seid; |
| 7058 | ctxt.connection_type = 0x1; /* regular data port */ |
| 7059 | ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; |
| 7060 | |
| 7061 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 7062 | |
| 7063 | /* This VSI is connected to VEB so the switch_id |
| 7064 | * should be set to zero by default. |
| 7065 | */ |
| 7066 | ctxt.info.switch_id = 0; |
| 7067 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); |
| 7068 | ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 7069 | |
| 7070 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 7071 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 7072 | break; |
| 7073 | |
| 7074 | case I40E_VSI_SRIOV: |
| 7075 | ctxt.pf_num = hw->pf_id; |
| 7076 | ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; |
| 7077 | ctxt.uplink_seid = vsi->uplink_seid; |
| 7078 | ctxt.connection_type = 0x1; /* regular data port */ |
| 7079 | ctxt.flags = I40E_AQ_VSI_TYPE_VF; |
| 7080 | |
| 7081 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); |
| 7082 | |
| 7083 | /* This VSI is connected to VEB so the switch_id |
| 7084 | * should be set to zero by default. |
| 7085 | */ |
| 7086 | ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); |
| 7087 | |
| 7088 | ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); |
| 7089 | ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; |
| 7090 | /* Setup the VSI tx/rx queue map for TC0 only for now */ |
| 7091 | i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); |
| 7092 | break; |
| 7093 | |
| 7094 | default: |
| 7095 | return -ENODEV; |
| 7096 | } |
| 7097 | |
| 7098 | if (vsi->type != I40E_VSI_MAIN) { |
| 7099 | ret = i40e_aq_add_vsi(hw, &ctxt, NULL); |
| 7100 | if (ret) { |
| 7101 | dev_info(&vsi->back->pdev->dev, |
| 7102 | "add vsi failed, aq_err=%d\n", |
| 7103 | vsi->back->hw.aq.asq_last_status); |
| 7104 | ret = -ENOENT; |
| 7105 | goto err; |
| 7106 | } |
| 7107 | memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); |
| 7108 | vsi->info.valid_sections = 0; |
| 7109 | vsi->seid = ctxt.seid; |
| 7110 | vsi->id = ctxt.vsi_number; |
| 7111 | } |
| 7112 | |
| 7113 | /* If macvlan filters already exist, force them to get loaded */ |
| 7114 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { |
| 7115 | f->changed = true; |
| 7116 | f_count++; |
| 7117 | } |
| 7118 | if (f_count) { |
| 7119 | vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; |
| 7120 | pf->flags |= I40E_FLAG_FILTER_SYNC; |
| 7121 | } |
| 7122 | |
| 7123 | /* Update VSI BW information */ |
| 7124 | ret = i40e_vsi_get_bw_info(vsi); |
| 7125 | if (ret) { |
| 7126 | dev_info(&pf->pdev->dev, |
| 7127 | "couldn't get vsi bw info, err %d, aq_err %d\n", |
| 7128 | ret, pf->hw.aq.asq_last_status); |
| 7129 | /* VSI is already added so not tearing that up */ |
| 7130 | ret = 0; |
| 7131 | } |
| 7132 | |
| 7133 | err: |
| 7134 | return ret; |
| 7135 | } |
| 7136 | |
| 7137 | /** |
| 7138 | * i40e_vsi_release - Delete a VSI and free its resources |
| 7139 | * @vsi: the VSI being removed |
| 7140 | * |
| 7141 | * Returns 0 on success or < 0 on error |
| 7142 | **/ |
| 7143 | int i40e_vsi_release(struct i40e_vsi *vsi) |
| 7144 | { |
| 7145 | struct i40e_mac_filter *f, *ftmp; |
| 7146 | struct i40e_veb *veb = NULL; |
| 7147 | struct i40e_pf *pf; |
| 7148 | u16 uplink_seid; |
| 7149 | int i, n; |
| 7150 | |
| 7151 | pf = vsi->back; |
| 7152 | |
| 7153 | /* release of a VEB-owner or last VSI is not allowed */ |
| 7154 | if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { |
| 7155 | dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", |
| 7156 | vsi->seid, vsi->uplink_seid); |
| 7157 | return -ENODEV; |
| 7158 | } |
| 7159 | if (vsi == pf->vsi[pf->lan_vsi] && |
| 7160 | !test_bit(__I40E_DOWN, &pf->state)) { |
| 7161 | dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); |
| 7162 | return -ENODEV; |
| 7163 | } |
| 7164 | |
| 7165 | uplink_seid = vsi->uplink_seid; |
| 7166 | if (vsi->type != I40E_VSI_SRIOV) { |
| 7167 | if (vsi->netdev_registered) { |
| 7168 | vsi->netdev_registered = false; |
| 7169 | if (vsi->netdev) { |
| 7170 | /* results in a call to i40e_close() */ |
| 7171 | unregister_netdev(vsi->netdev); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7172 | } |
| 7173 | } else { |
Shannon Nelson | 90ef8d4 | 2014-03-14 07:32:26 +0000 | [diff] [blame] | 7174 | i40e_vsi_close(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7175 | } |
| 7176 | i40e_vsi_disable_irq(vsi); |
| 7177 | } |
| 7178 | |
| 7179 | list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) |
| 7180 | i40e_del_filter(vsi, f->macaddr, f->vlan, |
| 7181 | f->is_vf, f->is_netdev); |
| 7182 | i40e_sync_vsi_filters(vsi); |
| 7183 | |
| 7184 | i40e_vsi_delete(vsi); |
| 7185 | i40e_vsi_free_q_vectors(vsi); |
Shannon Nelson | a486659 | 2014-02-11 08:24:07 +0000 | [diff] [blame] | 7186 | if (vsi->netdev) { |
| 7187 | free_netdev(vsi->netdev); |
| 7188 | vsi->netdev = NULL; |
| 7189 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7190 | i40e_vsi_clear_rings(vsi); |
| 7191 | i40e_vsi_clear(vsi); |
| 7192 | |
| 7193 | /* If this was the last thing on the VEB, except for the |
| 7194 | * controlling VSI, remove the VEB, which puts the controlling |
| 7195 | * VSI onto the next level down in the switch. |
| 7196 | * |
| 7197 | * Well, okay, there's one more exception here: don't remove |
| 7198 | * the orphan VEBs yet. We'll wait for an explicit remove request |
| 7199 | * from up the network stack. |
| 7200 | */ |
| 7201 | for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7202 | if (pf->vsi[i] && |
| 7203 | pf->vsi[i]->uplink_seid == uplink_seid && |
| 7204 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 7205 | n++; /* count the VSIs */ |
| 7206 | } |
| 7207 | } |
| 7208 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7209 | if (!pf->veb[i]) |
| 7210 | continue; |
| 7211 | if (pf->veb[i]->uplink_seid == uplink_seid) |
| 7212 | n++; /* count the VEBs */ |
| 7213 | if (pf->veb[i]->seid == uplink_seid) |
| 7214 | veb = pf->veb[i]; |
| 7215 | } |
| 7216 | if (n == 0 && veb && veb->uplink_seid != 0) |
| 7217 | i40e_veb_release(veb); |
| 7218 | |
| 7219 | return 0; |
| 7220 | } |
| 7221 | |
| 7222 | /** |
| 7223 | * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI |
| 7224 | * @vsi: ptr to the VSI |
| 7225 | * |
| 7226 | * This should only be called after i40e_vsi_mem_alloc() which allocates the |
| 7227 | * corresponding SW VSI structure and initializes num_queue_pairs for the |
| 7228 | * newly allocated VSI. |
| 7229 | * |
| 7230 | * Returns 0 on success or negative on failure |
| 7231 | **/ |
| 7232 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) |
| 7233 | { |
| 7234 | int ret = -ENOENT; |
| 7235 | struct i40e_pf *pf = vsi->back; |
| 7236 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 7237 | if (vsi->q_vectors[0]) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7238 | dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", |
| 7239 | vsi->seid); |
| 7240 | return -EEXIST; |
| 7241 | } |
| 7242 | |
| 7243 | if (vsi->base_vector) { |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 7244 | dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7245 | vsi->seid, vsi->base_vector); |
| 7246 | return -EEXIST; |
| 7247 | } |
| 7248 | |
Greg Rose | 90e0407 | 2014-03-06 08:59:57 +0000 | [diff] [blame] | 7249 | ret = i40e_vsi_alloc_q_vectors(vsi); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7250 | if (ret) { |
| 7251 | dev_info(&pf->pdev->dev, |
| 7252 | "failed to allocate %d q_vector for VSI %d, ret=%d\n", |
| 7253 | vsi->num_q_vectors, vsi->seid, ret); |
| 7254 | vsi->num_q_vectors = 0; |
| 7255 | goto vector_setup_out; |
| 7256 | } |
| 7257 | |
Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 7258 | if (vsi->num_q_vectors) |
| 7259 | vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, |
| 7260 | vsi->num_q_vectors, vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7261 | if (vsi->base_vector < 0) { |
| 7262 | dev_info(&pf->pdev->dev, |
Jesse Brandeburg | f29eaa3 | 2014-02-11 08:24:12 +0000 | [diff] [blame] | 7263 | "failed to get queue tracking for VSI %d, err=%d\n", |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7264 | vsi->seid, vsi->base_vector); |
| 7265 | i40e_vsi_free_q_vectors(vsi); |
| 7266 | ret = -ENOENT; |
| 7267 | goto vector_setup_out; |
| 7268 | } |
| 7269 | |
| 7270 | vector_setup_out: |
| 7271 | return ret; |
| 7272 | } |
| 7273 | |
| 7274 | /** |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7275 | * i40e_vsi_reinit_setup - return and reallocate resources for a VSI |
| 7276 | * @vsi: pointer to the vsi. |
| 7277 | * |
| 7278 | * This re-allocates a vsi's queue resources. |
| 7279 | * |
| 7280 | * Returns pointer to the successfully allocated and configured VSI sw struct |
| 7281 | * on success, otherwise returns NULL on failure. |
| 7282 | **/ |
| 7283 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) |
| 7284 | { |
| 7285 | struct i40e_pf *pf = vsi->back; |
| 7286 | u8 enabled_tc; |
| 7287 | int ret; |
| 7288 | |
| 7289 | i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); |
| 7290 | i40e_vsi_clear_rings(vsi); |
| 7291 | |
| 7292 | i40e_vsi_free_arrays(vsi, false); |
| 7293 | i40e_set_num_rings_in_vsi(vsi); |
| 7294 | ret = i40e_vsi_alloc_arrays(vsi, false); |
| 7295 | if (ret) |
| 7296 | goto err_vsi; |
| 7297 | |
| 7298 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); |
| 7299 | if (ret < 0) { |
| 7300 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 7301 | vsi->seid, ret); |
| 7302 | goto err_vsi; |
| 7303 | } |
| 7304 | vsi->base_queue = ret; |
| 7305 | |
| 7306 | /* Update the FW view of the VSI. Force a reset of TC and queue |
| 7307 | * layout configurations. |
| 7308 | */ |
| 7309 | enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 7310 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 7311 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 7312 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 7313 | |
| 7314 | /* assign it some queues */ |
| 7315 | ret = i40e_alloc_rings(vsi); |
| 7316 | if (ret) |
| 7317 | goto err_rings; |
| 7318 | |
| 7319 | /* map all of the rings to the q_vectors */ |
| 7320 | i40e_vsi_map_rings_to_vectors(vsi); |
| 7321 | return vsi; |
| 7322 | |
| 7323 | err_rings: |
| 7324 | i40e_vsi_free_q_vectors(vsi); |
| 7325 | if (vsi->netdev_registered) { |
| 7326 | vsi->netdev_registered = false; |
| 7327 | unregister_netdev(vsi->netdev); |
| 7328 | free_netdev(vsi->netdev); |
| 7329 | vsi->netdev = NULL; |
| 7330 | } |
| 7331 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 7332 | err_vsi: |
| 7333 | i40e_vsi_clear(vsi); |
| 7334 | return NULL; |
| 7335 | } |
| 7336 | |
| 7337 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7338 | * i40e_vsi_setup - Set up a VSI by a given type |
| 7339 | * @pf: board private structure |
| 7340 | * @type: VSI type |
| 7341 | * @uplink_seid: the switch element to link to |
| 7342 | * @param1: usage depends upon VSI type. For VF types, indicates VF id |
| 7343 | * |
| 7344 | * This allocates the sw VSI structure and its queue resources, then add a VSI |
| 7345 | * to the identified VEB. |
| 7346 | * |
| 7347 | * Returns pointer to the successfully allocated and configure VSI sw struct on |
| 7348 | * success, otherwise returns NULL on failure. |
| 7349 | **/ |
| 7350 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, |
| 7351 | u16 uplink_seid, u32 param1) |
| 7352 | { |
| 7353 | struct i40e_vsi *vsi = NULL; |
| 7354 | struct i40e_veb *veb = NULL; |
| 7355 | int ret, i; |
| 7356 | int v_idx; |
| 7357 | |
| 7358 | /* The requested uplink_seid must be either |
| 7359 | * - the PF's port seid |
| 7360 | * no VEB is needed because this is the PF |
| 7361 | * or this is a Flow Director special case VSI |
| 7362 | * - seid of an existing VEB |
| 7363 | * - seid of a VSI that owns an existing VEB |
| 7364 | * - seid of a VSI that doesn't own a VEB |
| 7365 | * a new VEB is created and the VSI becomes the owner |
| 7366 | * - seid of the PF VSI, which is what creates the first VEB |
| 7367 | * this is a special case of the previous |
| 7368 | * |
| 7369 | * Find which uplink_seid we were given and create a new VEB if needed |
| 7370 | */ |
| 7371 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7372 | if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { |
| 7373 | veb = pf->veb[i]; |
| 7374 | break; |
| 7375 | } |
| 7376 | } |
| 7377 | |
| 7378 | if (!veb && uplink_seid != pf->mac_seid) { |
| 7379 | |
| 7380 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7381 | if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { |
| 7382 | vsi = pf->vsi[i]; |
| 7383 | break; |
| 7384 | } |
| 7385 | } |
| 7386 | if (!vsi) { |
| 7387 | dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", |
| 7388 | uplink_seid); |
| 7389 | return NULL; |
| 7390 | } |
| 7391 | |
| 7392 | if (vsi->uplink_seid == pf->mac_seid) |
| 7393 | veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, |
| 7394 | vsi->tc_config.enabled_tc); |
| 7395 | else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) |
| 7396 | veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, |
| 7397 | vsi->tc_config.enabled_tc); |
| 7398 | |
| 7399 | for (i = 0; i < I40E_MAX_VEB && !veb; i++) { |
| 7400 | if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) |
| 7401 | veb = pf->veb[i]; |
| 7402 | } |
| 7403 | if (!veb) { |
| 7404 | dev_info(&pf->pdev->dev, "couldn't add VEB\n"); |
| 7405 | return NULL; |
| 7406 | } |
| 7407 | |
| 7408 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 7409 | uplink_seid = veb->seid; |
| 7410 | } |
| 7411 | |
| 7412 | /* get vsi sw struct */ |
| 7413 | v_idx = i40e_vsi_mem_alloc(pf, type); |
| 7414 | if (v_idx < 0) |
| 7415 | goto err_alloc; |
| 7416 | vsi = pf->vsi[v_idx]; |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7417 | if (!vsi) |
| 7418 | goto err_alloc; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7419 | vsi->type = type; |
| 7420 | vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); |
| 7421 | |
| 7422 | if (type == I40E_VSI_MAIN) |
| 7423 | pf->lan_vsi = v_idx; |
| 7424 | else if (type == I40E_VSI_SRIOV) |
| 7425 | vsi->vf_id = param1; |
| 7426 | /* assign it some queues */ |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 7427 | ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, |
| 7428 | vsi->idx); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7429 | if (ret < 0) { |
| 7430 | dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", |
| 7431 | vsi->seid, ret); |
| 7432 | goto err_vsi; |
| 7433 | } |
| 7434 | vsi->base_queue = ret; |
| 7435 | |
| 7436 | /* get a VSI from the hardware */ |
| 7437 | vsi->uplink_seid = uplink_seid; |
| 7438 | ret = i40e_add_vsi(vsi); |
| 7439 | if (ret) |
| 7440 | goto err_vsi; |
| 7441 | |
| 7442 | switch (vsi->type) { |
| 7443 | /* setup the netdev if needed */ |
| 7444 | case I40E_VSI_MAIN: |
| 7445 | case I40E_VSI_VMDQ2: |
| 7446 | ret = i40e_config_netdev(vsi); |
| 7447 | if (ret) |
| 7448 | goto err_netdev; |
| 7449 | ret = register_netdev(vsi->netdev); |
| 7450 | if (ret) |
| 7451 | goto err_netdev; |
| 7452 | vsi->netdev_registered = true; |
| 7453 | netif_carrier_off(vsi->netdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 7454 | #ifdef CONFIG_I40E_DCB |
| 7455 | /* Setup DCB netlink interface */ |
| 7456 | i40e_dcbnl_setup(vsi); |
| 7457 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7458 | /* fall through */ |
| 7459 | |
| 7460 | case I40E_VSI_FDIR: |
| 7461 | /* set up vectors and rings if needed */ |
| 7462 | ret = i40e_vsi_setup_vectors(vsi); |
| 7463 | if (ret) |
| 7464 | goto err_msix; |
| 7465 | |
| 7466 | ret = i40e_alloc_rings(vsi); |
| 7467 | if (ret) |
| 7468 | goto err_rings; |
| 7469 | |
| 7470 | /* map all of the rings to the q_vectors */ |
| 7471 | i40e_vsi_map_rings_to_vectors(vsi); |
| 7472 | |
| 7473 | i40e_vsi_reset_stats(vsi); |
| 7474 | break; |
| 7475 | |
| 7476 | default: |
| 7477 | /* no netdev or rings for the other VSI types */ |
| 7478 | break; |
| 7479 | } |
| 7480 | |
| 7481 | return vsi; |
| 7482 | |
| 7483 | err_rings: |
| 7484 | i40e_vsi_free_q_vectors(vsi); |
| 7485 | err_msix: |
| 7486 | if (vsi->netdev_registered) { |
| 7487 | vsi->netdev_registered = false; |
| 7488 | unregister_netdev(vsi->netdev); |
| 7489 | free_netdev(vsi->netdev); |
| 7490 | vsi->netdev = NULL; |
| 7491 | } |
| 7492 | err_netdev: |
| 7493 | i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); |
| 7494 | err_vsi: |
| 7495 | i40e_vsi_clear(vsi); |
| 7496 | err_alloc: |
| 7497 | return NULL; |
| 7498 | } |
| 7499 | |
| 7500 | /** |
| 7501 | * i40e_veb_get_bw_info - Query VEB BW information |
| 7502 | * @veb: the veb to query |
| 7503 | * |
| 7504 | * Query the Tx scheduler BW configuration data for given VEB |
| 7505 | **/ |
| 7506 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) |
| 7507 | { |
| 7508 | struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; |
| 7509 | struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; |
| 7510 | struct i40e_pf *pf = veb->pf; |
| 7511 | struct i40e_hw *hw = &pf->hw; |
| 7512 | u32 tc_bw_max; |
| 7513 | int ret = 0; |
| 7514 | int i; |
| 7515 | |
| 7516 | ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, |
| 7517 | &bw_data, NULL); |
| 7518 | if (ret) { |
| 7519 | dev_info(&pf->pdev->dev, |
| 7520 | "query veb bw config failed, aq_err=%d\n", |
| 7521 | hw->aq.asq_last_status); |
| 7522 | goto out; |
| 7523 | } |
| 7524 | |
| 7525 | ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, |
| 7526 | &ets_data, NULL); |
| 7527 | if (ret) { |
| 7528 | dev_info(&pf->pdev->dev, |
| 7529 | "query veb bw ets config failed, aq_err=%d\n", |
| 7530 | hw->aq.asq_last_status); |
| 7531 | goto out; |
| 7532 | } |
| 7533 | |
| 7534 | veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); |
| 7535 | veb->bw_max_quanta = ets_data.tc_bw_max; |
| 7536 | veb->is_abs_credits = bw_data.absolute_credits_enable; |
| 7537 | tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | |
| 7538 | (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); |
| 7539 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 7540 | veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; |
| 7541 | veb->bw_tc_limit_credits[i] = |
| 7542 | le16_to_cpu(bw_data.tc_bw_limits[i]); |
| 7543 | veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); |
| 7544 | } |
| 7545 | |
| 7546 | out: |
| 7547 | return ret; |
| 7548 | } |
| 7549 | |
| 7550 | /** |
| 7551 | * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF |
| 7552 | * @pf: board private structure |
| 7553 | * |
| 7554 | * On error: returns error code (negative) |
| 7555 | * On success: returns vsi index in PF (positive) |
| 7556 | **/ |
| 7557 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) |
| 7558 | { |
| 7559 | int ret = -ENOENT; |
| 7560 | struct i40e_veb *veb; |
| 7561 | int i; |
| 7562 | |
| 7563 | /* Need to protect the allocation of switch elements at the PF level */ |
| 7564 | mutex_lock(&pf->switch_mutex); |
| 7565 | |
| 7566 | /* VEB list may be fragmented if VEB creation/destruction has |
| 7567 | * been happening. We can afford to do a quick scan to look |
| 7568 | * for any free slots in the list. |
| 7569 | * |
| 7570 | * find next empty veb slot, looping back around if necessary |
| 7571 | */ |
| 7572 | i = 0; |
| 7573 | while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) |
| 7574 | i++; |
| 7575 | if (i >= I40E_MAX_VEB) { |
| 7576 | ret = -ENOMEM; |
| 7577 | goto err_alloc_veb; /* out of VEB slots! */ |
| 7578 | } |
| 7579 | |
| 7580 | veb = kzalloc(sizeof(*veb), GFP_KERNEL); |
| 7581 | if (!veb) { |
| 7582 | ret = -ENOMEM; |
| 7583 | goto err_alloc_veb; |
| 7584 | } |
| 7585 | veb->pf = pf; |
| 7586 | veb->idx = i; |
| 7587 | veb->enabled_tc = 1; |
| 7588 | |
| 7589 | pf->veb[i] = veb; |
| 7590 | ret = i; |
| 7591 | err_alloc_veb: |
| 7592 | mutex_unlock(&pf->switch_mutex); |
| 7593 | return ret; |
| 7594 | } |
| 7595 | |
| 7596 | /** |
| 7597 | * i40e_switch_branch_release - Delete a branch of the switch tree |
| 7598 | * @branch: where to start deleting |
| 7599 | * |
| 7600 | * This uses recursion to find the tips of the branch to be |
| 7601 | * removed, deleting until we get back to and can delete this VEB. |
| 7602 | **/ |
| 7603 | static void i40e_switch_branch_release(struct i40e_veb *branch) |
| 7604 | { |
| 7605 | struct i40e_pf *pf = branch->pf; |
| 7606 | u16 branch_seid = branch->seid; |
| 7607 | u16 veb_idx = branch->idx; |
| 7608 | int i; |
| 7609 | |
| 7610 | /* release any VEBs on this VEB - RECURSION */ |
| 7611 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 7612 | if (!pf->veb[i]) |
| 7613 | continue; |
| 7614 | if (pf->veb[i]->uplink_seid == branch->seid) |
| 7615 | i40e_switch_branch_release(pf->veb[i]); |
| 7616 | } |
| 7617 | |
| 7618 | /* Release the VSIs on this VEB, but not the owner VSI. |
| 7619 | * |
| 7620 | * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing |
| 7621 | * the VEB itself, so don't use (*branch) after this loop. |
| 7622 | */ |
| 7623 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7624 | if (!pf->vsi[i]) |
| 7625 | continue; |
| 7626 | if (pf->vsi[i]->uplink_seid == branch_seid && |
| 7627 | (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { |
| 7628 | i40e_vsi_release(pf->vsi[i]); |
| 7629 | } |
| 7630 | } |
| 7631 | |
| 7632 | /* There's one corner case where the VEB might not have been |
| 7633 | * removed, so double check it here and remove it if needed. |
| 7634 | * This case happens if the veb was created from the debugfs |
| 7635 | * commands and no VSIs were added to it. |
| 7636 | */ |
| 7637 | if (pf->veb[veb_idx]) |
| 7638 | i40e_veb_release(pf->veb[veb_idx]); |
| 7639 | } |
| 7640 | |
| 7641 | /** |
| 7642 | * i40e_veb_clear - remove veb struct |
| 7643 | * @veb: the veb to remove |
| 7644 | **/ |
| 7645 | static void i40e_veb_clear(struct i40e_veb *veb) |
| 7646 | { |
| 7647 | if (!veb) |
| 7648 | return; |
| 7649 | |
| 7650 | if (veb->pf) { |
| 7651 | struct i40e_pf *pf = veb->pf; |
| 7652 | |
| 7653 | mutex_lock(&pf->switch_mutex); |
| 7654 | if (pf->veb[veb->idx] == veb) |
| 7655 | pf->veb[veb->idx] = NULL; |
| 7656 | mutex_unlock(&pf->switch_mutex); |
| 7657 | } |
| 7658 | |
| 7659 | kfree(veb); |
| 7660 | } |
| 7661 | |
| 7662 | /** |
| 7663 | * i40e_veb_release - Delete a VEB and free its resources |
| 7664 | * @veb: the VEB being removed |
| 7665 | **/ |
| 7666 | void i40e_veb_release(struct i40e_veb *veb) |
| 7667 | { |
| 7668 | struct i40e_vsi *vsi = NULL; |
| 7669 | struct i40e_pf *pf; |
| 7670 | int i, n = 0; |
| 7671 | |
| 7672 | pf = veb->pf; |
| 7673 | |
| 7674 | /* find the remaining VSI and check for extras */ |
| 7675 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 7676 | if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { |
| 7677 | n++; |
| 7678 | vsi = pf->vsi[i]; |
| 7679 | } |
| 7680 | } |
| 7681 | if (n != 1) { |
| 7682 | dev_info(&pf->pdev->dev, |
| 7683 | "can't remove VEB %d with %d VSIs left\n", |
| 7684 | veb->seid, n); |
| 7685 | return; |
| 7686 | } |
| 7687 | |
| 7688 | /* move the remaining VSI to uplink veb */ |
| 7689 | vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; |
| 7690 | if (veb->uplink_seid) { |
| 7691 | vsi->uplink_seid = veb->uplink_seid; |
| 7692 | if (veb->uplink_seid == pf->mac_seid) |
| 7693 | vsi->veb_idx = I40E_NO_VEB; |
| 7694 | else |
| 7695 | vsi->veb_idx = veb->veb_idx; |
| 7696 | } else { |
| 7697 | /* floating VEB */ |
| 7698 | vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; |
| 7699 | vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; |
| 7700 | } |
| 7701 | |
| 7702 | i40e_aq_delete_element(&pf->hw, veb->seid, NULL); |
| 7703 | i40e_veb_clear(veb); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7704 | } |
| 7705 | |
| 7706 | /** |
| 7707 | * i40e_add_veb - create the VEB in the switch |
| 7708 | * @veb: the VEB to be instantiated |
| 7709 | * @vsi: the controlling VSI |
| 7710 | **/ |
| 7711 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) |
| 7712 | { |
Greg Rose | 5674726 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 7713 | bool is_default = false; |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 7714 | bool is_cloud = false; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7715 | int ret; |
| 7716 | |
| 7717 | /* get a VEB from the hardware */ |
| 7718 | ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid, |
Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 7719 | veb->enabled_tc, is_default, |
| 7720 | is_cloud, &veb->seid, NULL); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7721 | if (ret) { |
| 7722 | dev_info(&veb->pf->pdev->dev, |
| 7723 | "couldn't add VEB, err %d, aq_err %d\n", |
| 7724 | ret, veb->pf->hw.aq.asq_last_status); |
| 7725 | return -EPERM; |
| 7726 | } |
| 7727 | |
| 7728 | /* get statistics counter */ |
| 7729 | ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, |
| 7730 | &veb->stats_idx, NULL, NULL, NULL); |
| 7731 | if (ret) { |
| 7732 | dev_info(&veb->pf->pdev->dev, |
| 7733 | "couldn't get VEB statistics idx, err %d, aq_err %d\n", |
| 7734 | ret, veb->pf->hw.aq.asq_last_status); |
| 7735 | return -EPERM; |
| 7736 | } |
| 7737 | ret = i40e_veb_get_bw_info(veb); |
| 7738 | if (ret) { |
| 7739 | dev_info(&veb->pf->pdev->dev, |
| 7740 | "couldn't get VEB bw info, err %d, aq_err %d\n", |
| 7741 | ret, veb->pf->hw.aq.asq_last_status); |
| 7742 | i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); |
| 7743 | return -ENOENT; |
| 7744 | } |
| 7745 | |
| 7746 | vsi->uplink_seid = veb->seid; |
| 7747 | vsi->veb_idx = veb->idx; |
| 7748 | vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; |
| 7749 | |
| 7750 | return 0; |
| 7751 | } |
| 7752 | |
| 7753 | /** |
| 7754 | * i40e_veb_setup - Set up a VEB |
| 7755 | * @pf: board private structure |
| 7756 | * @flags: VEB setup flags |
| 7757 | * @uplink_seid: the switch element to link to |
| 7758 | * @vsi_seid: the initial VSI seid |
| 7759 | * @enabled_tc: Enabled TC bit-map |
| 7760 | * |
| 7761 | * This allocates the sw VEB structure and links it into the switch |
| 7762 | * It is possible and legal for this to be a duplicate of an already |
| 7763 | * existing VEB. It is also possible for both uplink and vsi seids |
| 7764 | * to be zero, in order to create a floating VEB. |
| 7765 | * |
| 7766 | * Returns pointer to the successfully allocated VEB sw struct on |
| 7767 | * success, otherwise returns NULL on failure. |
| 7768 | **/ |
| 7769 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, |
| 7770 | u16 uplink_seid, u16 vsi_seid, |
| 7771 | u8 enabled_tc) |
| 7772 | { |
| 7773 | struct i40e_veb *veb, *uplink_veb = NULL; |
| 7774 | int vsi_idx, veb_idx; |
| 7775 | int ret; |
| 7776 | |
| 7777 | /* if one seid is 0, the other must be 0 to create a floating relay */ |
| 7778 | if ((uplink_seid == 0 || vsi_seid == 0) && |
| 7779 | (uplink_seid + vsi_seid != 0)) { |
| 7780 | dev_info(&pf->pdev->dev, |
| 7781 | "one, not both seid's are 0: uplink=%d vsi=%d\n", |
| 7782 | uplink_seid, vsi_seid); |
| 7783 | return NULL; |
| 7784 | } |
| 7785 | |
| 7786 | /* make sure there is such a vsi and uplink */ |
| 7787 | for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++) |
| 7788 | if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) |
| 7789 | break; |
| 7790 | if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) { |
| 7791 | dev_info(&pf->pdev->dev, "vsi seid %d not found\n", |
| 7792 | vsi_seid); |
| 7793 | return NULL; |
| 7794 | } |
| 7795 | |
| 7796 | if (uplink_seid && uplink_seid != pf->mac_seid) { |
| 7797 | for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { |
| 7798 | if (pf->veb[veb_idx] && |
| 7799 | pf->veb[veb_idx]->seid == uplink_seid) { |
| 7800 | uplink_veb = pf->veb[veb_idx]; |
| 7801 | break; |
| 7802 | } |
| 7803 | } |
| 7804 | if (!uplink_veb) { |
| 7805 | dev_info(&pf->pdev->dev, |
| 7806 | "uplink seid %d not found\n", uplink_seid); |
| 7807 | return NULL; |
| 7808 | } |
| 7809 | } |
| 7810 | |
| 7811 | /* get veb sw struct */ |
| 7812 | veb_idx = i40e_veb_mem_alloc(pf); |
| 7813 | if (veb_idx < 0) |
| 7814 | goto err_alloc; |
| 7815 | veb = pf->veb[veb_idx]; |
| 7816 | veb->flags = flags; |
| 7817 | veb->uplink_seid = uplink_seid; |
| 7818 | veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); |
| 7819 | veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); |
| 7820 | |
| 7821 | /* create the VEB in the switch */ |
| 7822 | ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); |
| 7823 | if (ret) |
| 7824 | goto err_veb; |
Shannon Nelson | 1bb8b93 | 2014-04-23 04:49:54 +0000 | [diff] [blame] | 7825 | if (vsi_idx == pf->lan_vsi) |
| 7826 | pf->lan_veb = veb->idx; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7827 | |
| 7828 | return veb; |
| 7829 | |
| 7830 | err_veb: |
| 7831 | i40e_veb_clear(veb); |
| 7832 | err_alloc: |
| 7833 | return NULL; |
| 7834 | } |
| 7835 | |
| 7836 | /** |
| 7837 | * i40e_setup_pf_switch_element - set pf vars based on switch type |
| 7838 | * @pf: board private structure |
| 7839 | * @ele: element we are building info from |
| 7840 | * @num_reported: total number of elements |
| 7841 | * @printconfig: should we print the contents |
| 7842 | * |
| 7843 | * helper function to assist in extracting a few useful SEID values. |
| 7844 | **/ |
| 7845 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, |
| 7846 | struct i40e_aqc_switch_config_element_resp *ele, |
| 7847 | u16 num_reported, bool printconfig) |
| 7848 | { |
| 7849 | u16 downlink_seid = le16_to_cpu(ele->downlink_seid); |
| 7850 | u16 uplink_seid = le16_to_cpu(ele->uplink_seid); |
| 7851 | u8 element_type = ele->element_type; |
| 7852 | u16 seid = le16_to_cpu(ele->seid); |
| 7853 | |
| 7854 | if (printconfig) |
| 7855 | dev_info(&pf->pdev->dev, |
| 7856 | "type=%d seid=%d uplink=%d downlink=%d\n", |
| 7857 | element_type, seid, uplink_seid, downlink_seid); |
| 7858 | |
| 7859 | switch (element_type) { |
| 7860 | case I40E_SWITCH_ELEMENT_TYPE_MAC: |
| 7861 | pf->mac_seid = seid; |
| 7862 | break; |
| 7863 | case I40E_SWITCH_ELEMENT_TYPE_VEB: |
| 7864 | /* Main VEB? */ |
| 7865 | if (uplink_seid != pf->mac_seid) |
| 7866 | break; |
| 7867 | if (pf->lan_veb == I40E_NO_VEB) { |
| 7868 | int v; |
| 7869 | |
| 7870 | /* find existing or else empty VEB */ |
| 7871 | for (v = 0; v < I40E_MAX_VEB; v++) { |
| 7872 | if (pf->veb[v] && (pf->veb[v]->seid == seid)) { |
| 7873 | pf->lan_veb = v; |
| 7874 | break; |
| 7875 | } |
| 7876 | } |
| 7877 | if (pf->lan_veb == I40E_NO_VEB) { |
| 7878 | v = i40e_veb_mem_alloc(pf); |
| 7879 | if (v < 0) |
| 7880 | break; |
| 7881 | pf->lan_veb = v; |
| 7882 | } |
| 7883 | } |
| 7884 | |
| 7885 | pf->veb[pf->lan_veb]->seid = seid; |
| 7886 | pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; |
| 7887 | pf->veb[pf->lan_veb]->pf = pf; |
| 7888 | pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; |
| 7889 | break; |
| 7890 | case I40E_SWITCH_ELEMENT_TYPE_VSI: |
| 7891 | if (num_reported != 1) |
| 7892 | break; |
| 7893 | /* This is immediately after a reset so we can assume this is |
| 7894 | * the PF's VSI |
| 7895 | */ |
| 7896 | pf->mac_seid = uplink_seid; |
| 7897 | pf->pf_seid = downlink_seid; |
| 7898 | pf->main_vsi_seid = seid; |
| 7899 | if (printconfig) |
| 7900 | dev_info(&pf->pdev->dev, |
| 7901 | "pf_seid=%d main_vsi_seid=%d\n", |
| 7902 | pf->pf_seid, pf->main_vsi_seid); |
| 7903 | break; |
| 7904 | case I40E_SWITCH_ELEMENT_TYPE_PF: |
| 7905 | case I40E_SWITCH_ELEMENT_TYPE_VF: |
| 7906 | case I40E_SWITCH_ELEMENT_TYPE_EMP: |
| 7907 | case I40E_SWITCH_ELEMENT_TYPE_BMC: |
| 7908 | case I40E_SWITCH_ELEMENT_TYPE_PE: |
| 7909 | case I40E_SWITCH_ELEMENT_TYPE_PA: |
| 7910 | /* ignore these for now */ |
| 7911 | break; |
| 7912 | default: |
| 7913 | dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", |
| 7914 | element_type, seid); |
| 7915 | break; |
| 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | /** |
| 7920 | * i40e_fetch_switch_configuration - Get switch config from firmware |
| 7921 | * @pf: board private structure |
| 7922 | * @printconfig: should we print the contents |
| 7923 | * |
| 7924 | * Get the current switch configuration from the device and |
| 7925 | * extract a few useful SEID values. |
| 7926 | **/ |
| 7927 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) |
| 7928 | { |
| 7929 | struct i40e_aqc_get_switch_config_resp *sw_config; |
| 7930 | u16 next_seid = 0; |
| 7931 | int ret = 0; |
| 7932 | u8 *aq_buf; |
| 7933 | int i; |
| 7934 | |
| 7935 | aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); |
| 7936 | if (!aq_buf) |
| 7937 | return -ENOMEM; |
| 7938 | |
| 7939 | sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; |
| 7940 | do { |
| 7941 | u16 num_reported, num_total; |
| 7942 | |
| 7943 | ret = i40e_aq_get_switch_config(&pf->hw, sw_config, |
| 7944 | I40E_AQ_LARGE_BUF, |
| 7945 | &next_seid, NULL); |
| 7946 | if (ret) { |
| 7947 | dev_info(&pf->pdev->dev, |
| 7948 | "get switch config failed %d aq_err=%x\n", |
| 7949 | ret, pf->hw.aq.asq_last_status); |
| 7950 | kfree(aq_buf); |
| 7951 | return -ENOENT; |
| 7952 | } |
| 7953 | |
| 7954 | num_reported = le16_to_cpu(sw_config->header.num_reported); |
| 7955 | num_total = le16_to_cpu(sw_config->header.num_total); |
| 7956 | |
| 7957 | if (printconfig) |
| 7958 | dev_info(&pf->pdev->dev, |
| 7959 | "header: %d reported %d total\n", |
| 7960 | num_reported, num_total); |
| 7961 | |
| 7962 | if (num_reported) { |
| 7963 | int sz = sizeof(*sw_config) * num_reported; |
| 7964 | |
| 7965 | kfree(pf->sw_config); |
| 7966 | pf->sw_config = kzalloc(sz, GFP_KERNEL); |
| 7967 | if (pf->sw_config) |
| 7968 | memcpy(pf->sw_config, sw_config, sz); |
| 7969 | } |
| 7970 | |
| 7971 | for (i = 0; i < num_reported; i++) { |
| 7972 | struct i40e_aqc_switch_config_element_resp *ele = |
| 7973 | &sw_config->element[i]; |
| 7974 | |
| 7975 | i40e_setup_pf_switch_element(pf, ele, num_reported, |
| 7976 | printconfig); |
| 7977 | } |
| 7978 | } while (next_seid != 0); |
| 7979 | |
| 7980 | kfree(aq_buf); |
| 7981 | return ret; |
| 7982 | } |
| 7983 | |
| 7984 | /** |
| 7985 | * i40e_setup_pf_switch - Setup the HW switch on startup or after reset |
| 7986 | * @pf: board private structure |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7987 | * @reinit: if the Main VSI needs to re-initialized. |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7988 | * |
| 7989 | * Returns 0 on success, negative value on failure |
| 7990 | **/ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7991 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7992 | { |
Jesse Brandeburg | 895106a | 2013-11-26 10:49:16 +0000 | [diff] [blame] | 7993 | u32 rxfc = 0, txfc = 0, rxfc_reg; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7994 | int ret; |
| 7995 | |
| 7996 | /* find out what's out there already */ |
| 7997 | ret = i40e_fetch_switch_configuration(pf, false); |
| 7998 | if (ret) { |
| 7999 | dev_info(&pf->pdev->dev, |
| 8000 | "couldn't fetch switch config, err %d, aq_err %d\n", |
| 8001 | ret, pf->hw.aq.asq_last_status); |
| 8002 | return ret; |
| 8003 | } |
| 8004 | i40e_pf_reset_stats(pf); |
| 8005 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8006 | /* first time setup */ |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8007 | if (pf->lan_vsi == I40E_NO_VSI || reinit) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8008 | struct i40e_vsi *vsi = NULL; |
| 8009 | u16 uplink_seid; |
| 8010 | |
| 8011 | /* Set up the PF VSI associated with the PF's main VSI |
| 8012 | * that is already in the HW switch |
| 8013 | */ |
| 8014 | if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) |
| 8015 | uplink_seid = pf->veb[pf->lan_veb]->seid; |
| 8016 | else |
| 8017 | uplink_seid = pf->mac_seid; |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8018 | if (pf->lan_vsi == I40E_NO_VSI) |
| 8019 | vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); |
| 8020 | else if (reinit) |
| 8021 | vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8022 | if (!vsi) { |
| 8023 | dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); |
| 8024 | i40e_fdir_teardown(pf); |
| 8025 | return -EAGAIN; |
| 8026 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8027 | } else { |
| 8028 | /* force a reset of TC and queue layout configurations */ |
| 8029 | u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; |
| 8030 | pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; |
| 8031 | pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; |
| 8032 | i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); |
| 8033 | } |
| 8034 | i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); |
| 8035 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8036 | i40e_fdir_sb_setup(pf); |
| 8037 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8038 | /* Setup static PF queue filter control settings */ |
| 8039 | ret = i40e_setup_pf_filter_control(pf); |
| 8040 | if (ret) { |
| 8041 | dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", |
| 8042 | ret); |
| 8043 | /* Failure here should not stop continuing other steps */ |
| 8044 | } |
| 8045 | |
| 8046 | /* enable RSS in the HW, even for only one queue, as the stack can use |
| 8047 | * the hash |
| 8048 | */ |
| 8049 | if ((pf->flags & I40E_FLAG_RSS_ENABLED)) |
| 8050 | i40e_config_rss(pf); |
| 8051 | |
| 8052 | /* fill in link information and enable LSE reporting */ |
| 8053 | i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); |
| 8054 | i40e_link_event(pf); |
| 8055 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 8056 | /* Initialize user-specific link properties */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8057 | pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & |
| 8058 | I40E_AQ_AN_COMPLETED) ? true : false); |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 8059 | /* requested_mode is set in probe or by ethtool */ |
| 8060 | if (!pf->fc_autoneg_status) |
| 8061 | goto no_autoneg; |
| 8062 | |
| 8063 | if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) && |
| 8064 | (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8065 | pf->hw.fc.current_mode = I40E_FC_FULL; |
| 8066 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) |
| 8067 | pf->hw.fc.current_mode = I40E_FC_TX_PAUSE; |
| 8068 | else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) |
| 8069 | pf->hw.fc.current_mode = I40E_FC_RX_PAUSE; |
| 8070 | else |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 8071 | pf->hw.fc.current_mode = I40E_FC_NONE; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8072 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 8073 | /* sync the flow control settings with the auto-neg values */ |
| 8074 | switch (pf->hw.fc.current_mode) { |
| 8075 | case I40E_FC_FULL: |
| 8076 | txfc = 1; |
| 8077 | rxfc = 1; |
| 8078 | break; |
| 8079 | case I40E_FC_TX_PAUSE: |
| 8080 | txfc = 1; |
| 8081 | rxfc = 0; |
| 8082 | break; |
| 8083 | case I40E_FC_RX_PAUSE: |
| 8084 | txfc = 0; |
| 8085 | rxfc = 1; |
| 8086 | break; |
| 8087 | case I40E_FC_NONE: |
| 8088 | case I40E_FC_DEFAULT: |
| 8089 | txfc = 0; |
| 8090 | rxfc = 0; |
| 8091 | break; |
| 8092 | case I40E_FC_PFC: |
| 8093 | /* TBD */ |
| 8094 | break; |
| 8095 | /* no default case, we have to handle all possibilities here */ |
| 8096 | } |
| 8097 | |
| 8098 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT); |
| 8099 | |
| 8100 | rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 8101 | ~I40E_PRTDCB_MFLCN_RFCE_MASK; |
| 8102 | rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT); |
| 8103 | |
| 8104 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg); |
| 8105 | |
| 8106 | goto fc_complete; |
| 8107 | |
| 8108 | no_autoneg: |
| 8109 | /* disable L2 flow control, user can turn it on if they wish */ |
| 8110 | wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0); |
| 8111 | wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) & |
| 8112 | ~I40E_PRTDCB_MFLCN_RFCE_MASK); |
| 8113 | |
| 8114 | fc_complete: |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8115 | i40e_ptp_init(pf); |
| 8116 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8117 | return ret; |
| 8118 | } |
| 8119 | |
| 8120 | /** |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8121 | * i40e_determine_queue_usage - Work out queue distribution |
| 8122 | * @pf: board private structure |
| 8123 | **/ |
| 8124 | static void i40e_determine_queue_usage(struct i40e_pf *pf) |
| 8125 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8126 | int queues_left; |
| 8127 | |
| 8128 | pf->num_lan_qps = 0; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8129 | |
| 8130 | /* Find the max queues to be put into basic use. We'll always be |
| 8131 | * using TC0, whether or not DCB is running, and TC0 will get the |
| 8132 | * big RSS set. |
| 8133 | */ |
| 8134 | queues_left = pf->hw.func_caps.num_tx_qp; |
| 8135 | |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8136 | if ((queues_left == 1) || |
| 8137 | !(pf->flags & I40E_FLAG_MSIX_ENABLED) || |
| 8138 | !(pf->flags & (I40E_FLAG_RSS_ENABLED | I40E_FLAG_FD_SB_ENABLED | |
| 8139 | I40E_FLAG_DCB_ENABLED))) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8140 | /* one qp for PF, no queues for anything else */ |
| 8141 | queues_left = 0; |
| 8142 | pf->rss_size = pf->num_lan_qps = 1; |
| 8143 | |
| 8144 | /* make sure all the fancies are disabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8145 | pf->flags &= ~(I40E_FLAG_RSS_ENABLED | |
| 8146 | I40E_FLAG_FD_SB_ENABLED | |
| 8147 | I40E_FLAG_FD_ATR_ENABLED | |
| 8148 | I40E_FLAG_DCB_ENABLED | |
| 8149 | I40E_FLAG_SRIOV_ENABLED | |
| 8150 | I40E_FLAG_VMDQ_ENABLED); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8151 | } else { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8152 | /* Not enough queues for all TCs */ |
| 8153 | if ((pf->flags & I40E_FLAG_DCB_ENABLED) && |
| 8154 | (queues_left < I40E_MAX_TRAFFIC_CLASS)) { |
| 8155 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
| 8156 | dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n"); |
| 8157 | } |
| 8158 | pf->num_lan_qps = pf->rss_size_max; |
| 8159 | queues_left -= pf->num_lan_qps; |
| 8160 | } |
| 8161 | |
| 8162 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) { |
| 8163 | if (queues_left > 1) { |
| 8164 | queues_left -= 1; /* save 1 queue for FD */ |
| 8165 | } else { |
| 8166 | pf->flags &= ~I40E_FLAG_FD_SB_ENABLED; |
| 8167 | dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n"); |
| 8168 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8169 | } |
| 8170 | |
| 8171 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
| 8172 | pf->num_vf_qps && pf->num_req_vfs && queues_left) { |
Anjali Singhai Jain | cbf6132 | 2014-01-17 15:36:35 -0800 | [diff] [blame] | 8173 | pf->num_req_vfs = min_t(int, pf->num_req_vfs, |
| 8174 | (queues_left / pf->num_vf_qps)); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8175 | queues_left -= (pf->num_req_vfs * pf->num_vf_qps); |
| 8176 | } |
| 8177 | |
| 8178 | if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && |
| 8179 | pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { |
| 8180 | pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, |
| 8181 | (queues_left / pf->num_vmdq_qps)); |
| 8182 | queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); |
| 8183 | } |
| 8184 | |
Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 8185 | pf->queues_left = queues_left; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8186 | } |
| 8187 | |
| 8188 | /** |
| 8189 | * i40e_setup_pf_filter_control - Setup PF static filter control |
| 8190 | * @pf: PF to be setup |
| 8191 | * |
| 8192 | * i40e_setup_pf_filter_control sets up a pf's initial filter control |
| 8193 | * settings. If PE/FCoE are enabled then it will also set the per PF |
| 8194 | * based filter sizes required for them. It also enables Flow director, |
| 8195 | * ethertype and macvlan type filter settings for the pf. |
| 8196 | * |
| 8197 | * Returns 0 on success, negative on failure |
| 8198 | **/ |
| 8199 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) |
| 8200 | { |
| 8201 | struct i40e_filter_control_settings *settings = &pf->filter_settings; |
| 8202 | |
| 8203 | settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; |
| 8204 | |
| 8205 | /* Flow Director is enabled */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 8206 | if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED)) |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8207 | settings->enable_fdir = true; |
| 8208 | |
| 8209 | /* Ethtype and MACVLAN filters enabled for PF */ |
| 8210 | settings->enable_ethtype = true; |
| 8211 | settings->enable_macvlan = true; |
| 8212 | |
| 8213 | if (i40e_set_filter_control(&pf->hw, settings)) |
| 8214 | return -ENOENT; |
| 8215 | |
| 8216 | return 0; |
| 8217 | } |
| 8218 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 8219 | #define INFO_STRING_LEN 255 |
| 8220 | static void i40e_print_features(struct i40e_pf *pf) |
| 8221 | { |
| 8222 | struct i40e_hw *hw = &pf->hw; |
| 8223 | char *buf, *string; |
| 8224 | |
| 8225 | string = kzalloc(INFO_STRING_LEN, GFP_KERNEL); |
| 8226 | if (!string) { |
| 8227 | dev_err(&pf->pdev->dev, "Features string allocation failed\n"); |
| 8228 | return; |
| 8229 | } |
| 8230 | |
| 8231 | buf = string; |
| 8232 | |
| 8233 | buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id); |
| 8234 | #ifdef CONFIG_PCI_IOV |
| 8235 | buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs); |
| 8236 | #endif |
| 8237 | buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis, |
| 8238 | pf->vsi[pf->lan_vsi]->num_queue_pairs); |
| 8239 | |
| 8240 | if (pf->flags & I40E_FLAG_RSS_ENABLED) |
| 8241 | buf += sprintf(buf, "RSS "); |
| 8242 | buf += sprintf(buf, "FDir "); |
| 8243 | if (pf->flags & I40E_FLAG_FD_ATR_ENABLED) |
| 8244 | buf += sprintf(buf, "ATR "); |
| 8245 | if (pf->flags & I40E_FLAG_FD_SB_ENABLED) |
| 8246 | buf += sprintf(buf, "NTUPLE "); |
| 8247 | if (pf->flags & I40E_FLAG_DCB_ENABLED) |
| 8248 | buf += sprintf(buf, "DCB "); |
| 8249 | if (pf->flags & I40E_FLAG_PTP) |
| 8250 | buf += sprintf(buf, "PTP "); |
| 8251 | |
| 8252 | BUG_ON(buf > (string + INFO_STRING_LEN)); |
| 8253 | dev_info(&pf->pdev->dev, "%s\n", string); |
| 8254 | kfree(string); |
| 8255 | } |
| 8256 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8257 | /** |
| 8258 | * i40e_probe - Device initialization routine |
| 8259 | * @pdev: PCI device information struct |
| 8260 | * @ent: entry in i40e_pci_tbl |
| 8261 | * |
| 8262 | * i40e_probe initializes a pf identified by a pci_dev structure. |
| 8263 | * The OS initialization, configuring of the pf private structure, |
| 8264 | * and a hardware reset occur. |
| 8265 | * |
| 8266 | * Returns 0 on success, negative on failure |
| 8267 | **/ |
| 8268 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 8269 | { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8270 | struct i40e_pf *pf; |
| 8271 | struct i40e_hw *hw; |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 8272 | static u16 pfs_found; |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 8273 | u16 link_status; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8274 | int err = 0; |
| 8275 | u32 len; |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 8276 | u32 i; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8277 | |
| 8278 | err = pci_enable_device_mem(pdev); |
| 8279 | if (err) |
| 8280 | return err; |
| 8281 | |
| 8282 | /* set up for high or low dma */ |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 8283 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
Mitch Williams | 6494294 | 2014-02-11 08:26:33 +0000 | [diff] [blame] | 8284 | if (err) { |
Jean Sacren | e3e3bfd | 2014-03-25 04:30:27 +0000 | [diff] [blame] | 8285 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 8286 | if (err) { |
| 8287 | dev_err(&pdev->dev, |
| 8288 | "DMA configuration failed: 0x%x\n", err); |
| 8289 | goto err_dma; |
| 8290 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8291 | } |
| 8292 | |
| 8293 | /* set up pci connections */ |
| 8294 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 8295 | IORESOURCE_MEM), i40e_driver_name); |
| 8296 | if (err) { |
| 8297 | dev_info(&pdev->dev, |
| 8298 | "pci_request_selected_regions failed %d\n", err); |
| 8299 | goto err_pci_reg; |
| 8300 | } |
| 8301 | |
| 8302 | pci_enable_pcie_error_reporting(pdev); |
| 8303 | pci_set_master(pdev); |
| 8304 | |
| 8305 | /* Now that we have a PCI connection, we need to do the |
| 8306 | * low level device setup. This is primarily setting up |
| 8307 | * the Admin Queue structures and then querying for the |
| 8308 | * device's current profile information. |
| 8309 | */ |
| 8310 | pf = kzalloc(sizeof(*pf), GFP_KERNEL); |
| 8311 | if (!pf) { |
| 8312 | err = -ENOMEM; |
| 8313 | goto err_pf_alloc; |
| 8314 | } |
| 8315 | pf->next_vsi = 0; |
| 8316 | pf->pdev = pdev; |
| 8317 | set_bit(__I40E_DOWN, &pf->state); |
| 8318 | |
| 8319 | hw = &pf->hw; |
| 8320 | hw->back = pf; |
| 8321 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 8322 | pci_resource_len(pdev, 0)); |
| 8323 | if (!hw->hw_addr) { |
| 8324 | err = -EIO; |
| 8325 | dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", |
| 8326 | (unsigned int)pci_resource_start(pdev, 0), |
| 8327 | (unsigned int)pci_resource_len(pdev, 0), err); |
| 8328 | goto err_ioremap; |
| 8329 | } |
| 8330 | hw->vendor_id = pdev->vendor; |
| 8331 | hw->device_id = pdev->device; |
| 8332 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 8333 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 8334 | hw->subsystem_device_id = pdev->subsystem_device; |
| 8335 | hw->bus.device = PCI_SLOT(pdev->devfn); |
| 8336 | hw->bus.func = PCI_FUNC(pdev->devfn); |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 8337 | pf->instance = pfs_found; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8338 | |
Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 8339 | /* do a special CORER for clearing PXE mode once at init */ |
| 8340 | if (hw->revision_id == 0 && |
| 8341 | (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { |
| 8342 | wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); |
| 8343 | i40e_flush(hw); |
| 8344 | msleep(200); |
| 8345 | pf->corer_count++; |
| 8346 | |
| 8347 | i40e_clear_pxe_mode(hw); |
| 8348 | } |
| 8349 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8350 | /* Reset here to make sure all is clean and to define PF 'n' */ |
| 8351 | err = i40e_pf_reset(hw); |
| 8352 | if (err) { |
| 8353 | dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); |
| 8354 | goto err_pf_reset; |
| 8355 | } |
| 8356 | pf->pfr_count++; |
| 8357 | |
| 8358 | hw->aq.num_arq_entries = I40E_AQ_LEN; |
| 8359 | hw->aq.num_asq_entries = I40E_AQ_LEN; |
| 8360 | hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 8361 | hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; |
| 8362 | pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; |
| 8363 | snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1, |
| 8364 | "%s-pf%d:misc", |
| 8365 | dev_driver_string(&pf->pdev->dev), pf->hw.pf_id); |
| 8366 | |
| 8367 | err = i40e_init_shared_code(hw); |
| 8368 | if (err) { |
| 8369 | dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); |
| 8370 | goto err_pf_reset; |
| 8371 | } |
| 8372 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 8373 | /* set up a default setting for link flow control */ |
| 8374 | pf->hw.fc.requested_mode = I40E_FC_NONE; |
| 8375 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8376 | err = i40e_init_adminq(hw); |
| 8377 | dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); |
| 8378 | if (err) { |
| 8379 | dev_info(&pdev->dev, |
| 8380 | "init_adminq failed: %d expecting API %02x.%02x\n", |
| 8381 | err, |
| 8382 | I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR); |
| 8383 | goto err_pf_reset; |
| 8384 | } |
| 8385 | |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 8386 | i40e_verify_eeprom(pf); |
| 8387 | |
Jesse Brandeburg | 2c5fe33 | 2014-04-23 04:49:57 +0000 | [diff] [blame] | 8388 | /* Rev 0 hardware was never productized */ |
| 8389 | if (hw->revision_id < 1) |
| 8390 | dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n"); |
| 8391 | |
Shannon Nelson | 6ff4ef8 | 2013-12-21 05:44:49 +0000 | [diff] [blame] | 8392 | i40e_clear_pxe_mode(hw); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8393 | err = i40e_get_capabilities(pf); |
| 8394 | if (err) |
| 8395 | goto err_adminq_setup; |
| 8396 | |
| 8397 | err = i40e_sw_init(pf); |
| 8398 | if (err) { |
| 8399 | dev_info(&pdev->dev, "sw_init failed: %d\n", err); |
| 8400 | goto err_sw_init; |
| 8401 | } |
| 8402 | |
| 8403 | err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, |
| 8404 | hw->func_caps.num_rx_qp, |
| 8405 | pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); |
| 8406 | if (err) { |
| 8407 | dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); |
| 8408 | goto err_init_lan_hmc; |
| 8409 | } |
| 8410 | |
| 8411 | err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); |
| 8412 | if (err) { |
| 8413 | dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); |
| 8414 | err = -ENOENT; |
| 8415 | goto err_configure_lan_hmc; |
| 8416 | } |
| 8417 | |
| 8418 | i40e_get_mac_addr(hw, hw->mac.addr); |
Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 8419 | if (!is_valid_ether_addr(hw->mac.addr)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8420 | dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); |
| 8421 | err = -EIO; |
| 8422 | goto err_mac_addr; |
| 8423 | } |
| 8424 | dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); |
| 8425 | memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN); |
| 8426 | |
| 8427 | pci_set_drvdata(pdev, pf); |
| 8428 | pci_save_state(pdev); |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 8429 | #ifdef CONFIG_I40E_DCB |
| 8430 | err = i40e_init_pf_dcb(pf); |
| 8431 | if (err) { |
| 8432 | dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err); |
| 8433 | pf->flags &= ~I40E_FLAG_DCB_ENABLED; |
Neerav Parikh | 014269f | 2014-04-01 07:11:48 +0000 | [diff] [blame] | 8434 | /* Continue without DCB enabled */ |
Neerav Parikh | 4e3b35b | 2014-01-17 15:36:37 -0800 | [diff] [blame] | 8435 | } |
| 8436 | #endif /* CONFIG_I40E_DCB */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8437 | |
| 8438 | /* set up periodic task facility */ |
| 8439 | setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); |
| 8440 | pf->service_timer_period = HZ; |
| 8441 | |
| 8442 | INIT_WORK(&pf->service_task, i40e_service_task); |
| 8443 | clear_bit(__I40E_SERVICE_SCHED, &pf->state); |
| 8444 | pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; |
| 8445 | pf->link_check_timeout = jiffies; |
| 8446 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8447 | /* WoL defaults to disabled */ |
| 8448 | pf->wol_en = false; |
| 8449 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 8450 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8451 | /* set up the main switch operations */ |
| 8452 | i40e_determine_queue_usage(pf); |
| 8453 | i40e_init_interrupt_scheme(pf); |
| 8454 | |
| 8455 | /* Set up the *vsi struct based on the number of VSIs in the HW, |
| 8456 | * and set up our local tracking of the MAIN PF vsi. |
| 8457 | */ |
| 8458 | len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis; |
| 8459 | pf->vsi = kzalloc(len, GFP_KERNEL); |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 8460 | if (!pf->vsi) { |
| 8461 | err = -ENOMEM; |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8462 | goto err_switch_setup; |
Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 8463 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8464 | |
Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 8465 | err = i40e_setup_pf_switch(pf, false); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8466 | if (err) { |
| 8467 | dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); |
| 8468 | goto err_vsis; |
| 8469 | } |
Shannon Nelson | 8a9eb7d | 2014-03-14 07:32:28 +0000 | [diff] [blame] | 8470 | /* if FDIR VSI was set up, start it now */ |
| 8471 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 8472 | if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { |
| 8473 | i40e_vsi_open(pf->vsi[i]); |
| 8474 | break; |
| 8475 | } |
| 8476 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8477 | |
| 8478 | /* The main driver is (mostly) up and happy. We need to set this state |
| 8479 | * before setting up the misc vector or we get a race and the vector |
| 8480 | * ends up disabled forever. |
| 8481 | */ |
| 8482 | clear_bit(__I40E_DOWN, &pf->state); |
| 8483 | |
| 8484 | /* In case of MSIX we are going to setup the misc vector right here |
| 8485 | * to handle admin queue events etc. In case of legacy and MSI |
| 8486 | * the misc functionality and queue processing is combined in |
| 8487 | * the same vector and that gets setup at open. |
| 8488 | */ |
| 8489 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 8490 | err = i40e_setup_misc_vector(pf); |
| 8491 | if (err) { |
| 8492 | dev_info(&pdev->dev, |
| 8493 | "setup of misc vector failed: %d\n", err); |
| 8494 | goto err_vsis; |
| 8495 | } |
| 8496 | } |
| 8497 | |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 8498 | #ifdef CONFIG_PCI_IOV |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8499 | /* prep for VF support */ |
| 8500 | if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && |
Shannon Nelson | 4eb3f76 | 2014-03-06 08:59:58 +0000 | [diff] [blame] | 8501 | (pf->flags & I40E_FLAG_MSIX_ENABLED) && |
| 8502 | !test_bit(__I40E_BAD_EEPROM, &pf->state)) { |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8503 | u32 val; |
| 8504 | |
| 8505 | /* disable link interrupts for VFs */ |
| 8506 | val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); |
| 8507 | val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; |
| 8508 | wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); |
| 8509 | i40e_flush(hw); |
Mitch Williams | 4aeec01 | 2014-02-13 03:48:47 -0800 | [diff] [blame] | 8510 | |
| 8511 | if (pci_num_vf(pdev)) { |
| 8512 | dev_info(&pdev->dev, |
| 8513 | "Active VFs found, allocating resources.\n"); |
| 8514 | err = i40e_alloc_vfs(pf, pci_num_vf(pdev)); |
| 8515 | if (err) |
| 8516 | dev_info(&pdev->dev, |
| 8517 | "Error %d allocating resources for existing VFs\n", |
| 8518 | err); |
| 8519 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8520 | } |
Greg Rose | df805f6 | 2014-04-04 04:43:16 +0000 | [diff] [blame] | 8521 | #endif /* CONFIG_PCI_IOV */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8522 | |
Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 8523 | pfs_found++; |
| 8524 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8525 | i40e_dbg_pf_init(pf); |
| 8526 | |
| 8527 | /* tell the firmware that we're starting */ |
Jesse Brandeburg | 44033fa | 2014-04-23 04:50:15 +0000 | [diff] [blame] | 8528 | i40e_send_version(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8529 | |
| 8530 | /* since everything's happy, start the service_task timer */ |
| 8531 | mod_timer(&pf->service_timer, |
| 8532 | round_jiffies(jiffies + pf->service_timer_period)); |
| 8533 | |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 8534 | /* Get the negotiated link width and speed from PCI config space */ |
| 8535 | pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status); |
| 8536 | |
| 8537 | i40e_set_pci_config_data(hw, link_status); |
| 8538 | |
Jesse Brandeburg | 69bfb11 | 2014-02-11 08:24:13 +0000 | [diff] [blame] | 8539 | dev_info(&pdev->dev, "PCI-Express: %s %s\n", |
Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 8540 | (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" : |
| 8541 | hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" : |
| 8542 | hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" : |
| 8543 | "Unknown"), |
| 8544 | (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" : |
| 8545 | hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" : |
| 8546 | hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" : |
| 8547 | hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" : |
| 8548 | "Unknown")); |
| 8549 | |
| 8550 | if (hw->bus.width < i40e_bus_width_pcie_x8 || |
| 8551 | hw->bus.speed < i40e_bus_speed_8000) { |
| 8552 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); |
| 8553 | dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); |
| 8554 | } |
| 8555 | |
Jesse Brandeburg | 0c22b3d | 2014-02-11 08:24:14 +0000 | [diff] [blame] | 8556 | /* print a string summarizing features */ |
| 8557 | i40e_print_features(pf); |
| 8558 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8559 | return 0; |
| 8560 | |
| 8561 | /* Unwind what we've done if something failed in the setup */ |
| 8562 | err_vsis: |
| 8563 | set_bit(__I40E_DOWN, &pf->state); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8564 | i40e_clear_interrupt_scheme(pf); |
| 8565 | kfree(pf->vsi); |
Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 8566 | err_switch_setup: |
| 8567 | i40e_reset_interrupt_capability(pf); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8568 | del_timer_sync(&pf->service_timer); |
| 8569 | err_mac_addr: |
| 8570 | err_configure_lan_hmc: |
| 8571 | (void)i40e_shutdown_lan_hmc(hw); |
| 8572 | err_init_lan_hmc: |
| 8573 | kfree(pf->qp_pile); |
| 8574 | kfree(pf->irq_pile); |
| 8575 | err_sw_init: |
| 8576 | err_adminq_setup: |
| 8577 | (void)i40e_shutdown_adminq(hw); |
| 8578 | err_pf_reset: |
| 8579 | iounmap(hw->hw_addr); |
| 8580 | err_ioremap: |
| 8581 | kfree(pf); |
| 8582 | err_pf_alloc: |
| 8583 | pci_disable_pcie_error_reporting(pdev); |
| 8584 | pci_release_selected_regions(pdev, |
| 8585 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 8586 | err_pci_reg: |
| 8587 | err_dma: |
| 8588 | pci_disable_device(pdev); |
| 8589 | return err; |
| 8590 | } |
| 8591 | |
| 8592 | /** |
| 8593 | * i40e_remove - Device removal routine |
| 8594 | * @pdev: PCI device information struct |
| 8595 | * |
| 8596 | * i40e_remove is called by the PCI subsystem to alert the driver |
| 8597 | * that is should release a PCI device. This could be caused by a |
| 8598 | * Hot-Plug event, or because the driver is going to be removed from |
| 8599 | * memory. |
| 8600 | **/ |
| 8601 | static void i40e_remove(struct pci_dev *pdev) |
| 8602 | { |
| 8603 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 8604 | i40e_status ret_code; |
| 8605 | u32 reg; |
| 8606 | int i; |
| 8607 | |
| 8608 | i40e_dbg_pf_exit(pf); |
| 8609 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 8610 | i40e_ptp_stop(pf); |
| 8611 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8612 | /* no more scheduling of any task */ |
| 8613 | set_bit(__I40E_DOWN, &pf->state); |
| 8614 | del_timer_sync(&pf->service_timer); |
| 8615 | cancel_work_sync(&pf->service_task); |
| 8616 | |
Mitch Williams | eb2d80b | 2014-02-13 03:48:48 -0800 | [diff] [blame] | 8617 | if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { |
| 8618 | i40e_free_vfs(pf); |
| 8619 | pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; |
| 8620 | } |
| 8621 | |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8622 | i40e_fdir_teardown(pf); |
| 8623 | |
| 8624 | /* If there is a switch structure or any orphans, remove them. |
| 8625 | * This will leave only the PF's VSI remaining. |
| 8626 | */ |
| 8627 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 8628 | if (!pf->veb[i]) |
| 8629 | continue; |
| 8630 | |
| 8631 | if (pf->veb[i]->uplink_seid == pf->mac_seid || |
| 8632 | pf->veb[i]->uplink_seid == 0) |
| 8633 | i40e_switch_branch_release(pf->veb[i]); |
| 8634 | } |
| 8635 | |
| 8636 | /* Now we can shutdown the PF's VSI, just before we kill |
| 8637 | * adminq and hmc. |
| 8638 | */ |
| 8639 | if (pf->vsi[pf->lan_vsi]) |
| 8640 | i40e_vsi_release(pf->vsi[pf->lan_vsi]); |
| 8641 | |
| 8642 | i40e_stop_misc_vector(pf); |
| 8643 | if (pf->flags & I40E_FLAG_MSIX_ENABLED) { |
| 8644 | synchronize_irq(pf->msix_entries[0].vector); |
| 8645 | free_irq(pf->msix_entries[0].vector, pf); |
| 8646 | } |
| 8647 | |
| 8648 | /* shutdown and destroy the HMC */ |
Shannon Nelson | 60442de | 2014-04-23 04:50:13 +0000 | [diff] [blame] | 8649 | if (pf->hw.hmc.hmc_obj) { |
| 8650 | ret_code = i40e_shutdown_lan_hmc(&pf->hw); |
| 8651 | if (ret_code) |
| 8652 | dev_warn(&pdev->dev, |
| 8653 | "Failed to destroy the HMC resources: %d\n", |
| 8654 | ret_code); |
| 8655 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8656 | |
| 8657 | /* shutdown the adminq */ |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8658 | ret_code = i40e_shutdown_adminq(&pf->hw); |
| 8659 | if (ret_code) |
| 8660 | dev_warn(&pdev->dev, |
| 8661 | "Failed to destroy the Admin Queue resources: %d\n", |
| 8662 | ret_code); |
| 8663 | |
| 8664 | /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ |
| 8665 | i40e_clear_interrupt_scheme(pf); |
| 8666 | for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { |
| 8667 | if (pf->vsi[i]) { |
| 8668 | i40e_vsi_clear_rings(pf->vsi[i]); |
| 8669 | i40e_vsi_clear(pf->vsi[i]); |
| 8670 | pf->vsi[i] = NULL; |
| 8671 | } |
| 8672 | } |
| 8673 | |
| 8674 | for (i = 0; i < I40E_MAX_VEB; i++) { |
| 8675 | kfree(pf->veb[i]); |
| 8676 | pf->veb[i] = NULL; |
| 8677 | } |
| 8678 | |
| 8679 | kfree(pf->qp_pile); |
| 8680 | kfree(pf->irq_pile); |
| 8681 | kfree(pf->sw_config); |
| 8682 | kfree(pf->vsi); |
| 8683 | |
| 8684 | /* force a PF reset to clean anything leftover */ |
| 8685 | reg = rd32(&pf->hw, I40E_PFGEN_CTRL); |
| 8686 | wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK)); |
| 8687 | i40e_flush(&pf->hw); |
| 8688 | |
| 8689 | iounmap(pf->hw.hw_addr); |
| 8690 | kfree(pf); |
| 8691 | pci_release_selected_regions(pdev, |
| 8692 | pci_select_bars(pdev, IORESOURCE_MEM)); |
| 8693 | |
| 8694 | pci_disable_pcie_error_reporting(pdev); |
| 8695 | pci_disable_device(pdev); |
| 8696 | } |
| 8697 | |
| 8698 | /** |
| 8699 | * i40e_pci_error_detected - warning that something funky happened in PCI land |
| 8700 | * @pdev: PCI device information struct |
| 8701 | * |
| 8702 | * Called to warn that something happened and the error handling steps |
| 8703 | * are in progress. Allows the driver to quiesce things, be ready for |
| 8704 | * remediation. |
| 8705 | **/ |
| 8706 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, |
| 8707 | enum pci_channel_state error) |
| 8708 | { |
| 8709 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 8710 | |
| 8711 | dev_info(&pdev->dev, "%s: error %d\n", __func__, error); |
| 8712 | |
| 8713 | /* shutdown all operations */ |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8714 | if (!test_bit(__I40E_SUSPENDED, &pf->state)) { |
| 8715 | rtnl_lock(); |
| 8716 | i40e_prep_for_reset(pf); |
| 8717 | rtnl_unlock(); |
| 8718 | } |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8719 | |
| 8720 | /* Request a slot reset */ |
| 8721 | return PCI_ERS_RESULT_NEED_RESET; |
| 8722 | } |
| 8723 | |
| 8724 | /** |
| 8725 | * i40e_pci_error_slot_reset - a PCI slot reset just happened |
| 8726 | * @pdev: PCI device information struct |
| 8727 | * |
| 8728 | * Called to find if the driver can work with the device now that |
| 8729 | * the pci slot has been reset. If a basic connection seems good |
| 8730 | * (registers are readable and have sane content) then return a |
| 8731 | * happy little PCI_ERS_RESULT_xxx. |
| 8732 | **/ |
| 8733 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) |
| 8734 | { |
| 8735 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 8736 | pci_ers_result_t result; |
| 8737 | int err; |
| 8738 | u32 reg; |
| 8739 | |
| 8740 | dev_info(&pdev->dev, "%s\n", __func__); |
| 8741 | if (pci_enable_device_mem(pdev)) { |
| 8742 | dev_info(&pdev->dev, |
| 8743 | "Cannot re-enable PCI device after reset.\n"); |
| 8744 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8745 | } else { |
| 8746 | pci_set_master(pdev); |
| 8747 | pci_restore_state(pdev); |
| 8748 | pci_save_state(pdev); |
| 8749 | pci_wake_from_d3(pdev, false); |
| 8750 | |
| 8751 | reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); |
| 8752 | if (reg == 0) |
| 8753 | result = PCI_ERS_RESULT_RECOVERED; |
| 8754 | else |
| 8755 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8756 | } |
| 8757 | |
| 8758 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8759 | if (err) { |
| 8760 | dev_info(&pdev->dev, |
| 8761 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 8762 | err); |
| 8763 | /* non-fatal, continue */ |
| 8764 | } |
| 8765 | |
| 8766 | return result; |
| 8767 | } |
| 8768 | |
| 8769 | /** |
| 8770 | * i40e_pci_error_resume - restart operations after PCI error recovery |
| 8771 | * @pdev: PCI device information struct |
| 8772 | * |
| 8773 | * Called to allow the driver to bring things back up after PCI error |
| 8774 | * and/or reset recovery has finished. |
| 8775 | **/ |
| 8776 | static void i40e_pci_error_resume(struct pci_dev *pdev) |
| 8777 | { |
| 8778 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 8779 | |
| 8780 | dev_info(&pdev->dev, "%s\n", __func__); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8781 | if (test_bit(__I40E_SUSPENDED, &pf->state)) |
| 8782 | return; |
| 8783 | |
| 8784 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8785 | i40e_handle_reset_warning(pf); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8786 | rtnl_lock(); |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8787 | } |
| 8788 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8789 | /** |
| 8790 | * i40e_shutdown - PCI callback for shutting down |
| 8791 | * @pdev: PCI device information struct |
| 8792 | **/ |
| 8793 | static void i40e_shutdown(struct pci_dev *pdev) |
| 8794 | { |
| 8795 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8796 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8797 | |
| 8798 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 8799 | set_bit(__I40E_DOWN, &pf->state); |
| 8800 | rtnl_lock(); |
| 8801 | i40e_prep_for_reset(pf); |
| 8802 | rtnl_unlock(); |
| 8803 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8804 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 8805 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 8806 | |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8807 | if (system_state == SYSTEM_POWER_OFF) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8808 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8809 | pci_set_power_state(pdev, PCI_D3hot); |
| 8810 | } |
| 8811 | } |
| 8812 | |
| 8813 | #ifdef CONFIG_PM |
| 8814 | /** |
| 8815 | * i40e_suspend - PCI callback for moving to D3 |
| 8816 | * @pdev: PCI device information struct |
| 8817 | **/ |
| 8818 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) |
| 8819 | { |
| 8820 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8821 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8822 | |
| 8823 | set_bit(__I40E_SUSPENDED, &pf->state); |
| 8824 | set_bit(__I40E_DOWN, &pf->state); |
| 8825 | rtnl_lock(); |
| 8826 | i40e_prep_for_reset(pf); |
| 8827 | rtnl_unlock(); |
| 8828 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8829 | wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); |
| 8830 | wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); |
| 8831 | |
| 8832 | pci_wake_from_d3(pdev, pf->wol_en); |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8833 | pci_set_power_state(pdev, PCI_D3hot); |
| 8834 | |
| 8835 | return 0; |
| 8836 | } |
| 8837 | |
| 8838 | /** |
| 8839 | * i40e_resume - PCI callback for waking up from D3 |
| 8840 | * @pdev: PCI device information struct |
| 8841 | **/ |
| 8842 | static int i40e_resume(struct pci_dev *pdev) |
| 8843 | { |
| 8844 | struct i40e_pf *pf = pci_get_drvdata(pdev); |
| 8845 | u32 err; |
| 8846 | |
| 8847 | pci_set_power_state(pdev, PCI_D0); |
| 8848 | pci_restore_state(pdev); |
| 8849 | /* pci_restore_state() clears dev->state_saves, so |
| 8850 | * call pci_save_state() again to restore it. |
| 8851 | */ |
| 8852 | pci_save_state(pdev); |
| 8853 | |
| 8854 | err = pci_enable_device_mem(pdev); |
| 8855 | if (err) { |
| 8856 | dev_err(&pdev->dev, |
| 8857 | "%s: Cannot enable PCI device from suspend\n", |
| 8858 | __func__); |
| 8859 | return err; |
| 8860 | } |
| 8861 | pci_set_master(pdev); |
| 8862 | |
| 8863 | /* no wakeup events while running */ |
| 8864 | pci_wake_from_d3(pdev, false); |
| 8865 | |
| 8866 | /* handling the reset will rebuild the device state */ |
| 8867 | if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { |
| 8868 | clear_bit(__I40E_DOWN, &pf->state); |
| 8869 | rtnl_lock(); |
| 8870 | i40e_reset_and_rebuild(pf, false); |
| 8871 | rtnl_unlock(); |
| 8872 | } |
| 8873 | |
| 8874 | return 0; |
| 8875 | } |
| 8876 | |
| 8877 | #endif |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8878 | static const struct pci_error_handlers i40e_err_handler = { |
| 8879 | .error_detected = i40e_pci_error_detected, |
| 8880 | .slot_reset = i40e_pci_error_slot_reset, |
| 8881 | .resume = i40e_pci_error_resume, |
| 8882 | }; |
| 8883 | |
| 8884 | static struct pci_driver i40e_driver = { |
| 8885 | .name = i40e_driver_name, |
| 8886 | .id_table = i40e_pci_tbl, |
| 8887 | .probe = i40e_probe, |
| 8888 | .remove = i40e_remove, |
Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8889 | #ifdef CONFIG_PM |
| 8890 | .suspend = i40e_suspend, |
| 8891 | .resume = i40e_resume, |
| 8892 | #endif |
| 8893 | .shutdown = i40e_shutdown, |
Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8894 | .err_handler = &i40e_err_handler, |
| 8895 | .sriov_configure = i40e_pci_sriov_configure, |
| 8896 | }; |
| 8897 | |
| 8898 | /** |
| 8899 | * i40e_init_module - Driver registration routine |
| 8900 | * |
| 8901 | * i40e_init_module is the first routine called when the driver is |
| 8902 | * loaded. All it does is register with the PCI subsystem. |
| 8903 | **/ |
| 8904 | static int __init i40e_init_module(void) |
| 8905 | { |
| 8906 | pr_info("%s: %s - version %s\n", i40e_driver_name, |
| 8907 | i40e_driver_string, i40e_driver_version_str); |
| 8908 | pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); |
| 8909 | i40e_dbg_init(); |
| 8910 | return pci_register_driver(&i40e_driver); |
| 8911 | } |
| 8912 | module_init(i40e_init_module); |
| 8913 | |
| 8914 | /** |
| 8915 | * i40e_exit_module - Driver exit cleanup routine |
| 8916 | * |
| 8917 | * i40e_exit_module is called just before the driver is removed |
| 8918 | * from memory. |
| 8919 | **/ |
| 8920 | static void __exit i40e_exit_module(void) |
| 8921 | { |
| 8922 | pci_unregister_driver(&i40e_driver); |
| 8923 | i40e_dbg_exit(); |
| 8924 | } |
| 8925 | module_exit(i40e_exit_module); |