| 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" | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 29 | #ifdef CONFIG_I40E_VXLAN | 
 | 30 | #include <net/vxlan.h> | 
 | 31 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 32 |  | 
 | 33 | const char i40e_driver_name[] = "i40e"; | 
 | 34 | static const char i40e_driver_string[] = | 
 | 35 | 			"Intel(R) Ethernet Connection XL710 Network Driver"; | 
 | 36 |  | 
 | 37 | #define DRV_KERN "-k" | 
 | 38 |  | 
 | 39 | #define DRV_VERSION_MAJOR 0 | 
 | 40 | #define DRV_VERSION_MINOR 3 | 
| Catherine Sullivan | 7f61d1f | 2013-11-28 06:42:42 +0000 | [diff] [blame] | 41 | #define DRV_VERSION_BUILD 25 | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 42 | #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ | 
 | 43 | 	     __stringify(DRV_VERSION_MINOR) "." \ | 
 | 44 | 	     __stringify(DRV_VERSION_BUILD)    DRV_KERN | 
 | 45 | const char i40e_driver_version_str[] = DRV_VERSION; | 
 | 46 | static const char i40e_copyright[] = "Copyright (c) 2013 Intel Corporation."; | 
 | 47 |  | 
 | 48 | /* a bit of forward declarations */ | 
 | 49 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi); | 
 | 50 | static void i40e_handle_reset_warning(struct i40e_pf *pf); | 
 | 51 | static int i40e_add_vsi(struct i40e_vsi *vsi); | 
 | 52 | 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] | 53 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 54 | static int i40e_setup_misc_vector(struct i40e_pf *pf); | 
 | 55 | static void i40e_determine_queue_usage(struct i40e_pf *pf); | 
 | 56 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf); | 
 | 57 |  | 
 | 58 | /* i40e_pci_tbl - PCI Device ID Table | 
 | 59 |  * | 
 | 60 |  * Last entry must be all 0s | 
 | 61 |  * | 
 | 62 |  * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, | 
 | 63 |  *   Class, Class Mask, private data (not used) } | 
 | 64 |  */ | 
 | 65 | static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = { | 
 | 66 | 	{PCI_VDEVICE(INTEL, I40E_SFP_XL710_DEVICE_ID), 0}, | 
 | 67 | 	{PCI_VDEVICE(INTEL, I40E_SFP_X710_DEVICE_ID), 0}, | 
 | 68 | 	{PCI_VDEVICE(INTEL, I40E_QEMU_DEVICE_ID), 0}, | 
 | 69 | 	{PCI_VDEVICE(INTEL, I40E_KX_A_DEVICE_ID), 0}, | 
 | 70 | 	{PCI_VDEVICE(INTEL, I40E_KX_B_DEVICE_ID), 0}, | 
 | 71 | 	{PCI_VDEVICE(INTEL, I40E_KX_C_DEVICE_ID), 0}, | 
 | 72 | 	{PCI_VDEVICE(INTEL, I40E_KX_D_DEVICE_ID), 0}, | 
 | 73 | 	{PCI_VDEVICE(INTEL, I40E_QSFP_A_DEVICE_ID), 0}, | 
 | 74 | 	{PCI_VDEVICE(INTEL, I40E_QSFP_B_DEVICE_ID), 0}, | 
 | 75 | 	{PCI_VDEVICE(INTEL, I40E_QSFP_C_DEVICE_ID), 0}, | 
 | 76 | 	/* required last entry */ | 
 | 77 | 	{0, } | 
 | 78 | }; | 
 | 79 | MODULE_DEVICE_TABLE(pci, i40e_pci_tbl); | 
 | 80 |  | 
 | 81 | #define I40E_MAX_VF_COUNT 128 | 
 | 82 | static int debug = -1; | 
 | 83 | module_param(debug, int, 0); | 
 | 84 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); | 
 | 85 |  | 
 | 86 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); | 
 | 87 | MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver"); | 
 | 88 | MODULE_LICENSE("GPL"); | 
 | 89 | MODULE_VERSION(DRV_VERSION); | 
 | 90 |  | 
 | 91 | /** | 
 | 92 |  * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code | 
 | 93 |  * @hw:   pointer to the HW structure | 
 | 94 |  * @mem:  ptr to mem struct to fill out | 
 | 95 |  * @size: size of memory requested | 
 | 96 |  * @alignment: what to align the allocation to | 
 | 97 |  **/ | 
 | 98 | int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem, | 
 | 99 | 			    u64 size, u32 alignment) | 
 | 100 | { | 
 | 101 | 	struct i40e_pf *pf = (struct i40e_pf *)hw->back; | 
 | 102 |  | 
 | 103 | 	mem->size = ALIGN(size, alignment); | 
 | 104 | 	mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size, | 
 | 105 | 				      &mem->pa, GFP_KERNEL); | 
| Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 106 | 	if (!mem->va) | 
 | 107 | 		return -ENOMEM; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 108 |  | 
| Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 109 | 	return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 110 | } | 
 | 111 |  | 
 | 112 | /** | 
 | 113 |  * i40e_free_dma_mem_d - OS specific memory free for shared code | 
 | 114 |  * @hw:   pointer to the HW structure | 
 | 115 |  * @mem:  ptr to mem struct to free | 
 | 116 |  **/ | 
 | 117 | int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem) | 
 | 118 | { | 
 | 119 | 	struct i40e_pf *pf = (struct i40e_pf *)hw->back; | 
 | 120 |  | 
 | 121 | 	dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa); | 
 | 122 | 	mem->va = NULL; | 
 | 123 | 	mem->pa = 0; | 
 | 124 | 	mem->size = 0; | 
 | 125 |  | 
 | 126 | 	return 0; | 
 | 127 | } | 
 | 128 |  | 
 | 129 | /** | 
 | 130 |  * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code | 
 | 131 |  * @hw:   pointer to the HW structure | 
 | 132 |  * @mem:  ptr to mem struct to fill out | 
 | 133 |  * @size: size of memory requested | 
 | 134 |  **/ | 
 | 135 | int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem, | 
 | 136 | 			     u32 size) | 
 | 137 | { | 
 | 138 | 	mem->size = size; | 
 | 139 | 	mem->va = kzalloc(size, GFP_KERNEL); | 
 | 140 |  | 
| Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 141 | 	if (!mem->va) | 
 | 142 | 		return -ENOMEM; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 143 |  | 
| Jesse Brandeburg | 93bc73b | 2013-09-13 08:23:18 +0000 | [diff] [blame] | 144 | 	return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 145 | } | 
 | 146 |  | 
 | 147 | /** | 
 | 148 |  * i40e_free_virt_mem_d - OS specific memory free for shared code | 
 | 149 |  * @hw:   pointer to the HW structure | 
 | 150 |  * @mem:  ptr to mem struct to free | 
 | 151 |  **/ | 
 | 152 | int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem) | 
 | 153 | { | 
 | 154 | 	/* it's ok to kfree a NULL pointer */ | 
 | 155 | 	kfree(mem->va); | 
 | 156 | 	mem->va = NULL; | 
 | 157 | 	mem->size = 0; | 
 | 158 |  | 
 | 159 | 	return 0; | 
 | 160 | } | 
 | 161 |  | 
 | 162 | /** | 
 | 163 |  * i40e_get_lump - find a lump of free generic resource | 
 | 164 |  * @pf: board private structure | 
 | 165 |  * @pile: the pile of resource to search | 
 | 166 |  * @needed: the number of items needed | 
 | 167 |  * @id: an owner id to stick on the items assigned | 
 | 168 |  * | 
 | 169 |  * Returns the base item index of the lump, or negative for error | 
 | 170 |  * | 
 | 171 |  * The search_hint trick and lack of advanced fit-finding only work | 
 | 172 |  * because we're highly likely to have all the same size lump requests. | 
 | 173 |  * Linear search time and any fragmentation should be minimal. | 
 | 174 |  **/ | 
 | 175 | static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile, | 
 | 176 | 			 u16 needed, u16 id) | 
 | 177 | { | 
 | 178 | 	int ret = -ENOMEM; | 
| Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 179 | 	int i, j; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 180 |  | 
 | 181 | 	if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) { | 
 | 182 | 		dev_info(&pf->pdev->dev, | 
 | 183 | 			 "param err: pile=%p needed=%d id=0x%04x\n", | 
 | 184 | 			 pile, needed, id); | 
 | 185 | 		return -EINVAL; | 
 | 186 | 	} | 
 | 187 |  | 
 | 188 | 	/* start the linear search with an imperfect hint */ | 
 | 189 | 	i = pile->search_hint; | 
| Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 190 | 	while (i < pile->num_entries) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 191 | 		/* skip already allocated entries */ | 
 | 192 | 		if (pile->list[i] & I40E_PILE_VALID_BIT) { | 
 | 193 | 			i++; | 
 | 194 | 			continue; | 
 | 195 | 		} | 
 | 196 |  | 
 | 197 | 		/* do we have enough in this lump? */ | 
 | 198 | 		for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) { | 
 | 199 | 			if (pile->list[i+j] & I40E_PILE_VALID_BIT) | 
 | 200 | 				break; | 
 | 201 | 		} | 
 | 202 |  | 
 | 203 | 		if (j == needed) { | 
 | 204 | 			/* there was enough, so assign it to the requestor */ | 
 | 205 | 			for (j = 0; j < needed; j++) | 
 | 206 | 				pile->list[i+j] = id | I40E_PILE_VALID_BIT; | 
 | 207 | 			ret = i; | 
 | 208 | 			pile->search_hint = i + j; | 
| Jesse Brandeburg | ddf434a | 2013-09-13 08:23:19 +0000 | [diff] [blame] | 209 | 			break; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 210 | 		} else { | 
 | 211 | 			/* not enough, so skip over it and continue looking */ | 
 | 212 | 			i += j; | 
 | 213 | 		} | 
 | 214 | 	} | 
 | 215 |  | 
 | 216 | 	return ret; | 
 | 217 | } | 
 | 218 |  | 
 | 219 | /** | 
 | 220 |  * i40e_put_lump - return a lump of generic resource | 
 | 221 |  * @pile: the pile of resource to search | 
 | 222 |  * @index: the base item index | 
 | 223 |  * @id: the owner id of the items assigned | 
 | 224 |  * | 
 | 225 |  * Returns the count of items in the lump | 
 | 226 |  **/ | 
 | 227 | static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id) | 
 | 228 | { | 
 | 229 | 	int valid_id = (id | I40E_PILE_VALID_BIT); | 
 | 230 | 	int count = 0; | 
 | 231 | 	int i; | 
 | 232 |  | 
 | 233 | 	if (!pile || index >= pile->num_entries) | 
 | 234 | 		return -EINVAL; | 
 | 235 |  | 
 | 236 | 	for (i = index; | 
 | 237 | 	     i < pile->num_entries && pile->list[i] == valid_id; | 
 | 238 | 	     i++) { | 
 | 239 | 		pile->list[i] = 0; | 
 | 240 | 		count++; | 
 | 241 | 	} | 
 | 242 |  | 
 | 243 | 	if (count && index < pile->search_hint) | 
 | 244 | 		pile->search_hint = index; | 
 | 245 |  | 
 | 246 | 	return count; | 
 | 247 | } | 
 | 248 |  | 
 | 249 | /** | 
 | 250 |  * i40e_service_event_schedule - Schedule the service task to wake up | 
 | 251 |  * @pf: board private structure | 
 | 252 |  * | 
 | 253 |  * If not already scheduled, this puts the task into the work queue | 
 | 254 |  **/ | 
 | 255 | static void i40e_service_event_schedule(struct i40e_pf *pf) | 
 | 256 | { | 
 | 257 | 	if (!test_bit(__I40E_DOWN, &pf->state) && | 
 | 258 | 	    !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) && | 
 | 259 | 	    !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state)) | 
 | 260 | 		schedule_work(&pf->service_task); | 
 | 261 | } | 
 | 262 |  | 
 | 263 | /** | 
 | 264 |  * i40e_tx_timeout - Respond to a Tx Hang | 
 | 265 |  * @netdev: network interface device structure | 
 | 266 |  * | 
 | 267 |  * If any port has noticed a Tx timeout, it is likely that the whole | 
 | 268 |  * device is munged, not just the one netdev port, so go for the full | 
 | 269 |  * reset. | 
 | 270 |  **/ | 
 | 271 | static void i40e_tx_timeout(struct net_device *netdev) | 
 | 272 | { | 
 | 273 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 274 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 275 | 	struct i40e_pf *pf = vsi->back; | 
 | 276 |  | 
 | 277 | 	pf->tx_timeout_count++; | 
 | 278 |  | 
 | 279 | 	if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20))) | 
 | 280 | 		pf->tx_timeout_recovery_level = 0; | 
 | 281 | 	pf->tx_timeout_last_recovery = jiffies; | 
 | 282 | 	netdev_info(netdev, "tx_timeout recovery level %d\n", | 
 | 283 | 		    pf->tx_timeout_recovery_level); | 
 | 284 |  | 
 | 285 | 	switch (pf->tx_timeout_recovery_level) { | 
 | 286 | 	case 0: | 
 | 287 | 		/* disable and re-enable queues for the VSI */ | 
 | 288 | 		if (in_interrupt()) { | 
 | 289 | 			set_bit(__I40E_REINIT_REQUESTED, &pf->state); | 
 | 290 | 			set_bit(__I40E_REINIT_REQUESTED, &vsi->state); | 
 | 291 | 		} else { | 
 | 292 | 			i40e_vsi_reinit_locked(vsi); | 
 | 293 | 		} | 
 | 294 | 		break; | 
 | 295 | 	case 1: | 
 | 296 | 		set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | 
 | 297 | 		break; | 
 | 298 | 	case 2: | 
 | 299 | 		set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); | 
 | 300 | 		break; | 
 | 301 | 	case 3: | 
 | 302 | 		set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); | 
 | 303 | 		break; | 
 | 304 | 	default: | 
 | 305 | 		netdev_err(netdev, "tx_timeout recovery unsuccessful\n"); | 
 | 306 | 		i40e_down(vsi); | 
 | 307 | 		break; | 
 | 308 | 	} | 
 | 309 | 	i40e_service_event_schedule(pf); | 
 | 310 | 	pf->tx_timeout_recovery_level++; | 
 | 311 | } | 
 | 312 |  | 
 | 313 | /** | 
 | 314 |  * i40e_release_rx_desc - Store the new tail and head values | 
 | 315 |  * @rx_ring: ring to bump | 
 | 316 |  * @val: new head index | 
 | 317 |  **/ | 
 | 318 | static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val) | 
 | 319 | { | 
 | 320 | 	rx_ring->next_to_use = val; | 
 | 321 |  | 
 | 322 | 	/* Force memory writes to complete before letting h/w | 
 | 323 | 	 * know there are new descriptors to fetch.  (Only | 
 | 324 | 	 * applicable for weak-ordered memory model archs, | 
 | 325 | 	 * such as IA-64). | 
 | 326 | 	 */ | 
 | 327 | 	wmb(); | 
 | 328 | 	writel(val, rx_ring->tail); | 
 | 329 | } | 
 | 330 |  | 
 | 331 | /** | 
 | 332 |  * i40e_get_vsi_stats_struct - Get System Network Statistics | 
 | 333 |  * @vsi: the VSI we care about | 
 | 334 |  * | 
 | 335 |  * Returns the address of the device statistics structure. | 
 | 336 |  * The statistics are actually updated from the service task. | 
 | 337 |  **/ | 
 | 338 | struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi) | 
 | 339 | { | 
 | 340 | 	return &vsi->net_stats; | 
 | 341 | } | 
 | 342 |  | 
 | 343 | /** | 
 | 344 |  * i40e_get_netdev_stats_struct - Get statistics for netdev interface | 
 | 345 |  * @netdev: network interface device structure | 
 | 346 |  * | 
 | 347 |  * Returns the address of the device statistics structure. | 
 | 348 |  * The statistics are actually updated from the service task. | 
 | 349 |  **/ | 
 | 350 | static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct( | 
 | 351 | 					     struct net_device *netdev, | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 352 | 					     struct rtnl_link_stats64 *stats) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 353 | { | 
 | 354 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 355 | 	struct i40e_vsi *vsi = np->vsi; | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 356 | 	struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi); | 
 | 357 | 	int i; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 358 |  | 
| David S. Miller | 143c905 | 2013-12-18 16:42:06 -0500 | [diff] [blame] | 359 |  | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 360 | 	if (test_bit(__I40E_DOWN, &vsi->state)) | 
 | 361 | 		return stats; | 
 | 362 |  | 
| Jesse Brandeburg | 3c325ce | 2013-12-14 03:26:45 -0800 | [diff] [blame] | 363 | 	if (!vsi->tx_rings) | 
 | 364 | 		return stats; | 
 | 365 |  | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 366 | 	rcu_read_lock(); | 
 | 367 | 	for (i = 0; i < vsi->num_queue_pairs; i++) { | 
 | 368 | 		struct i40e_ring *tx_ring, *rx_ring; | 
 | 369 | 		u64 bytes, packets; | 
 | 370 | 		unsigned int start; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 371 |  | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 372 | 		tx_ring = ACCESS_ONCE(vsi->tx_rings[i]); | 
 | 373 | 		if (!tx_ring) | 
 | 374 | 			continue; | 
 | 375 |  | 
 | 376 | 		do { | 
 | 377 | 			start = u64_stats_fetch_begin_bh(&tx_ring->syncp); | 
 | 378 | 			packets = tx_ring->stats.packets; | 
 | 379 | 			bytes   = tx_ring->stats.bytes; | 
 | 380 | 		} while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start)); | 
 | 381 |  | 
 | 382 | 		stats->tx_packets += packets; | 
 | 383 | 		stats->tx_bytes   += bytes; | 
 | 384 | 		rx_ring = &tx_ring[1]; | 
 | 385 |  | 
 | 386 | 		do { | 
 | 387 | 			start = u64_stats_fetch_begin_bh(&rx_ring->syncp); | 
 | 388 | 			packets = rx_ring->stats.packets; | 
 | 389 | 			bytes   = rx_ring->stats.bytes; | 
 | 390 | 		} while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start)); | 
 | 391 |  | 
 | 392 | 		stats->rx_packets += packets; | 
 | 393 | 		stats->rx_bytes   += bytes; | 
 | 394 | 	} | 
 | 395 | 	rcu_read_unlock(); | 
 | 396 |  | 
 | 397 | 	/* following stats updated by ixgbe_watchdog_task() */ | 
 | 398 | 	stats->multicast	= vsi_stats->multicast; | 
 | 399 | 	stats->tx_errors	= vsi_stats->tx_errors; | 
 | 400 | 	stats->tx_dropped	= vsi_stats->tx_dropped; | 
 | 401 | 	stats->rx_errors	= vsi_stats->rx_errors; | 
 | 402 | 	stats->rx_crc_errors	= vsi_stats->rx_crc_errors; | 
 | 403 | 	stats->rx_length_errors	= vsi_stats->rx_length_errors; | 
 | 404 |  | 
 | 405 | 	return stats; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 406 | } | 
 | 407 |  | 
 | 408 | /** | 
 | 409 |  * i40e_vsi_reset_stats - Resets all stats of the given vsi | 
 | 410 |  * @vsi: the VSI to have its stats reset | 
 | 411 |  **/ | 
 | 412 | void i40e_vsi_reset_stats(struct i40e_vsi *vsi) | 
 | 413 | { | 
 | 414 | 	struct rtnl_link_stats64 *ns; | 
 | 415 | 	int i; | 
 | 416 |  | 
 | 417 | 	if (!vsi) | 
 | 418 | 		return; | 
 | 419 |  | 
 | 420 | 	ns = i40e_get_vsi_stats_struct(vsi); | 
 | 421 | 	memset(ns, 0, sizeof(*ns)); | 
 | 422 | 	memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets)); | 
 | 423 | 	memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats)); | 
 | 424 | 	memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets)); | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 425 | 	if (vsi->rx_rings && vsi->rx_rings[0]) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 426 | 		for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 427 | 			memset(&vsi->rx_rings[i]->stats, 0 , | 
 | 428 | 			       sizeof(vsi->rx_rings[i]->stats)); | 
 | 429 | 			memset(&vsi->rx_rings[i]->rx_stats, 0 , | 
 | 430 | 			       sizeof(vsi->rx_rings[i]->rx_stats)); | 
 | 431 | 			memset(&vsi->tx_rings[i]->stats, 0 , | 
 | 432 | 			       sizeof(vsi->tx_rings[i]->stats)); | 
 | 433 | 			memset(&vsi->tx_rings[i]->tx_stats, 0, | 
 | 434 | 			       sizeof(vsi->tx_rings[i]->tx_stats)); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 435 | 		} | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 436 | 	} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 437 | 	vsi->stat_offsets_loaded = false; | 
 | 438 | } | 
 | 439 |  | 
 | 440 | /** | 
 | 441 |  * i40e_pf_reset_stats - Reset all of the stats for the given pf | 
 | 442 |  * @pf: the PF to be reset | 
 | 443 |  **/ | 
 | 444 | void i40e_pf_reset_stats(struct i40e_pf *pf) | 
 | 445 | { | 
 | 446 | 	memset(&pf->stats, 0, sizeof(pf->stats)); | 
 | 447 | 	memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets)); | 
 | 448 | 	pf->stat_offsets_loaded = false; | 
 | 449 | } | 
 | 450 |  | 
 | 451 | /** | 
 | 452 |  * i40e_stat_update48 - read and update a 48 bit stat from the chip | 
 | 453 |  * @hw: ptr to the hardware info | 
 | 454 |  * @hireg: the high 32 bit reg to read | 
 | 455 |  * @loreg: the low 32 bit reg to read | 
 | 456 |  * @offset_loaded: has the initial offset been loaded yet | 
 | 457 |  * @offset: ptr to current offset value | 
 | 458 |  * @stat: ptr to the stat | 
 | 459 |  * | 
 | 460 |  * Since the device stats are not reset at PFReset, they likely will not | 
 | 461 |  * be zeroed when the driver starts.  We'll save the first values read | 
 | 462 |  * and use them as offsets to be subtracted from the raw values in order | 
 | 463 |  * to report stats that count from zero.  In the process, we also manage | 
 | 464 |  * the potential roll-over. | 
 | 465 |  **/ | 
 | 466 | static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg, | 
 | 467 | 			       bool offset_loaded, u64 *offset, u64 *stat) | 
 | 468 | { | 
 | 469 | 	u64 new_data; | 
 | 470 |  | 
 | 471 | 	if (hw->device_id == I40E_QEMU_DEVICE_ID) { | 
 | 472 | 		new_data = rd32(hw, loreg); | 
 | 473 | 		new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32; | 
 | 474 | 	} else { | 
 | 475 | 		new_data = rd64(hw, loreg); | 
 | 476 | 	} | 
 | 477 | 	if (!offset_loaded) | 
 | 478 | 		*offset = new_data; | 
 | 479 | 	if (likely(new_data >= *offset)) | 
 | 480 | 		*stat = new_data - *offset; | 
 | 481 | 	else | 
 | 482 | 		*stat = (new_data + ((u64)1 << 48)) - *offset; | 
 | 483 | 	*stat &= 0xFFFFFFFFFFFFULL; | 
 | 484 | } | 
 | 485 |  | 
 | 486 | /** | 
 | 487 |  * i40e_stat_update32 - read and update a 32 bit stat from the chip | 
 | 488 |  * @hw: ptr to the hardware info | 
 | 489 |  * @reg: the hw reg to read | 
 | 490 |  * @offset_loaded: has the initial offset been loaded yet | 
 | 491 |  * @offset: ptr to current offset value | 
 | 492 |  * @stat: ptr to the stat | 
 | 493 |  **/ | 
 | 494 | static void i40e_stat_update32(struct i40e_hw *hw, u32 reg, | 
 | 495 | 			       bool offset_loaded, u64 *offset, u64 *stat) | 
 | 496 | { | 
 | 497 | 	u32 new_data; | 
 | 498 |  | 
 | 499 | 	new_data = rd32(hw, reg); | 
 | 500 | 	if (!offset_loaded) | 
 | 501 | 		*offset = new_data; | 
 | 502 | 	if (likely(new_data >= *offset)) | 
 | 503 | 		*stat = (u32)(new_data - *offset); | 
 | 504 | 	else | 
 | 505 | 		*stat = (u32)((new_data + ((u64)1 << 32)) - *offset); | 
 | 506 | } | 
 | 507 |  | 
 | 508 | /** | 
 | 509 |  * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters. | 
 | 510 |  * @vsi: the VSI to be updated | 
 | 511 |  **/ | 
 | 512 | void i40e_update_eth_stats(struct i40e_vsi *vsi) | 
 | 513 | { | 
 | 514 | 	int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx); | 
 | 515 | 	struct i40e_pf *pf = vsi->back; | 
 | 516 | 	struct i40e_hw *hw = &pf->hw; | 
 | 517 | 	struct i40e_eth_stats *oes; | 
 | 518 | 	struct i40e_eth_stats *es;     /* device's eth stats */ | 
 | 519 |  | 
 | 520 | 	es = &vsi->eth_stats; | 
 | 521 | 	oes = &vsi->eth_stats_offsets; | 
 | 522 |  | 
 | 523 | 	/* Gather up the stats that the hw collects */ | 
 | 524 | 	i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx), | 
 | 525 | 			   vsi->stat_offsets_loaded, | 
 | 526 | 			   &oes->tx_errors, &es->tx_errors); | 
 | 527 | 	i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx), | 
 | 528 | 			   vsi->stat_offsets_loaded, | 
 | 529 | 			   &oes->rx_discards, &es->rx_discards); | 
 | 530 |  | 
 | 531 | 	i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx), | 
 | 532 | 			   I40E_GLV_GORCL(stat_idx), | 
 | 533 | 			   vsi->stat_offsets_loaded, | 
 | 534 | 			   &oes->rx_bytes, &es->rx_bytes); | 
 | 535 | 	i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx), | 
 | 536 | 			   I40E_GLV_UPRCL(stat_idx), | 
 | 537 | 			   vsi->stat_offsets_loaded, | 
 | 538 | 			   &oes->rx_unicast, &es->rx_unicast); | 
 | 539 | 	i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx), | 
 | 540 | 			   I40E_GLV_MPRCL(stat_idx), | 
 | 541 | 			   vsi->stat_offsets_loaded, | 
 | 542 | 			   &oes->rx_multicast, &es->rx_multicast); | 
 | 543 | 	i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx), | 
 | 544 | 			   I40E_GLV_BPRCL(stat_idx), | 
 | 545 | 			   vsi->stat_offsets_loaded, | 
 | 546 | 			   &oes->rx_broadcast, &es->rx_broadcast); | 
 | 547 |  | 
 | 548 | 	i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx), | 
 | 549 | 			   I40E_GLV_GOTCL(stat_idx), | 
 | 550 | 			   vsi->stat_offsets_loaded, | 
 | 551 | 			   &oes->tx_bytes, &es->tx_bytes); | 
 | 552 | 	i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx), | 
 | 553 | 			   I40E_GLV_UPTCL(stat_idx), | 
 | 554 | 			   vsi->stat_offsets_loaded, | 
 | 555 | 			   &oes->tx_unicast, &es->tx_unicast); | 
 | 556 | 	i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx), | 
 | 557 | 			   I40E_GLV_MPTCL(stat_idx), | 
 | 558 | 			   vsi->stat_offsets_loaded, | 
 | 559 | 			   &oes->tx_multicast, &es->tx_multicast); | 
 | 560 | 	i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx), | 
 | 561 | 			   I40E_GLV_BPTCL(stat_idx), | 
 | 562 | 			   vsi->stat_offsets_loaded, | 
 | 563 | 			   &oes->tx_broadcast, &es->tx_broadcast); | 
 | 564 | 	vsi->stat_offsets_loaded = true; | 
 | 565 | } | 
 | 566 |  | 
 | 567 | /** | 
 | 568 |  * i40e_update_veb_stats - Update Switch component statistics | 
 | 569 |  * @veb: the VEB being updated | 
 | 570 |  **/ | 
 | 571 | static void i40e_update_veb_stats(struct i40e_veb *veb) | 
 | 572 | { | 
 | 573 | 	struct i40e_pf *pf = veb->pf; | 
 | 574 | 	struct i40e_hw *hw = &pf->hw; | 
 | 575 | 	struct i40e_eth_stats *oes; | 
 | 576 | 	struct i40e_eth_stats *es;     /* device's eth stats */ | 
 | 577 | 	int idx = 0; | 
 | 578 |  | 
 | 579 | 	idx = veb->stats_idx; | 
 | 580 | 	es = &veb->stats; | 
 | 581 | 	oes = &veb->stats_offsets; | 
 | 582 |  | 
 | 583 | 	/* Gather up the stats that the hw collects */ | 
 | 584 | 	i40e_stat_update32(hw, I40E_GLSW_TDPC(idx), | 
 | 585 | 			   veb->stat_offsets_loaded, | 
 | 586 | 			   &oes->tx_discards, &es->tx_discards); | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 587 | 	if (hw->revision_id > 0) | 
 | 588 | 		i40e_stat_update32(hw, I40E_GLSW_RUPP(idx), | 
 | 589 | 				   veb->stat_offsets_loaded, | 
 | 590 | 				   &oes->rx_unknown_protocol, | 
 | 591 | 				   &es->rx_unknown_protocol); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 592 | 	i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx), | 
 | 593 | 			   veb->stat_offsets_loaded, | 
 | 594 | 			   &oes->rx_bytes, &es->rx_bytes); | 
 | 595 | 	i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx), | 
 | 596 | 			   veb->stat_offsets_loaded, | 
 | 597 | 			   &oes->rx_unicast, &es->rx_unicast); | 
 | 598 | 	i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx), | 
 | 599 | 			   veb->stat_offsets_loaded, | 
 | 600 | 			   &oes->rx_multicast, &es->rx_multicast); | 
 | 601 | 	i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx), | 
 | 602 | 			   veb->stat_offsets_loaded, | 
 | 603 | 			   &oes->rx_broadcast, &es->rx_broadcast); | 
 | 604 |  | 
 | 605 | 	i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx), | 
 | 606 | 			   veb->stat_offsets_loaded, | 
 | 607 | 			   &oes->tx_bytes, &es->tx_bytes); | 
 | 608 | 	i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx), | 
 | 609 | 			   veb->stat_offsets_loaded, | 
 | 610 | 			   &oes->tx_unicast, &es->tx_unicast); | 
 | 611 | 	i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx), | 
 | 612 | 			   veb->stat_offsets_loaded, | 
 | 613 | 			   &oes->tx_multicast, &es->tx_multicast); | 
 | 614 | 	i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx), | 
 | 615 | 			   veb->stat_offsets_loaded, | 
 | 616 | 			   &oes->tx_broadcast, &es->tx_broadcast); | 
 | 617 | 	veb->stat_offsets_loaded = true; | 
 | 618 | } | 
 | 619 |  | 
 | 620 | /** | 
 | 621 |  * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode | 
 | 622 |  * @pf: the corresponding PF | 
 | 623 |  * | 
 | 624 |  * Update the Rx XOFF counter (PAUSE frames) in link flow control mode | 
 | 625 |  **/ | 
 | 626 | static void i40e_update_link_xoff_rx(struct i40e_pf *pf) | 
 | 627 | { | 
 | 628 | 	struct i40e_hw_port_stats *osd = &pf->stats_offsets; | 
 | 629 | 	struct i40e_hw_port_stats *nsd = &pf->stats; | 
 | 630 | 	struct i40e_hw *hw = &pf->hw; | 
 | 631 | 	u64 xoff = 0; | 
 | 632 | 	u16 i, v; | 
 | 633 |  | 
 | 634 | 	if ((hw->fc.current_mode != I40E_FC_FULL) && | 
 | 635 | 	    (hw->fc.current_mode != I40E_FC_RX_PAUSE)) | 
 | 636 | 		return; | 
 | 637 |  | 
 | 638 | 	xoff = nsd->link_xoff_rx; | 
 | 639 | 	i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port), | 
 | 640 | 			   pf->stat_offsets_loaded, | 
 | 641 | 			   &osd->link_xoff_rx, &nsd->link_xoff_rx); | 
 | 642 |  | 
 | 643 | 	/* No new LFC xoff rx */ | 
 | 644 | 	if (!(nsd->link_xoff_rx - xoff)) | 
 | 645 | 		return; | 
 | 646 |  | 
 | 647 | 	/* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */ | 
 | 648 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 649 | 		struct i40e_vsi *vsi = pf->vsi[v]; | 
 | 650 |  | 
 | 651 | 		if (!vsi) | 
 | 652 | 			continue; | 
 | 653 |  | 
 | 654 | 		for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 655 | 			struct i40e_ring *ring = vsi->tx_rings[i]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 656 | 			clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); | 
 | 657 | 		} | 
 | 658 | 	} | 
 | 659 | } | 
 | 660 |  | 
 | 661 | /** | 
 | 662 |  * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode | 
 | 663 |  * @pf: the corresponding PF | 
 | 664 |  * | 
 | 665 |  * Update the Rx XOFF counter (PAUSE frames) in PFC mode | 
 | 666 |  **/ | 
 | 667 | static void i40e_update_prio_xoff_rx(struct i40e_pf *pf) | 
 | 668 | { | 
 | 669 | 	struct i40e_hw_port_stats *osd = &pf->stats_offsets; | 
 | 670 | 	struct i40e_hw_port_stats *nsd = &pf->stats; | 
 | 671 | 	bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false}; | 
 | 672 | 	struct i40e_dcbx_config *dcb_cfg; | 
 | 673 | 	struct i40e_hw *hw = &pf->hw; | 
 | 674 | 	u16 i, v; | 
 | 675 | 	u8 tc; | 
 | 676 |  | 
 | 677 | 	dcb_cfg = &hw->local_dcbx_config; | 
 | 678 |  | 
 | 679 | 	/* See if DCB enabled with PFC TC */ | 
 | 680 | 	if (!(pf->flags & I40E_FLAG_DCB_ENABLED) || | 
 | 681 | 	    !(dcb_cfg->pfc.pfcenable)) { | 
 | 682 | 		i40e_update_link_xoff_rx(pf); | 
 | 683 | 		return; | 
 | 684 | 	} | 
 | 685 |  | 
 | 686 | 	for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | 
 | 687 | 		u64 prio_xoff = nsd->priority_xoff_rx[i]; | 
 | 688 | 		i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i), | 
 | 689 | 				   pf->stat_offsets_loaded, | 
 | 690 | 				   &osd->priority_xoff_rx[i], | 
 | 691 | 				   &nsd->priority_xoff_rx[i]); | 
 | 692 |  | 
 | 693 | 		/* No new PFC xoff rx */ | 
 | 694 | 		if (!(nsd->priority_xoff_rx[i] - prio_xoff)) | 
 | 695 | 			continue; | 
 | 696 | 		/* Get the TC for given priority */ | 
 | 697 | 		tc = dcb_cfg->etscfg.prioritytable[i]; | 
 | 698 | 		xoff[tc] = true; | 
 | 699 | 	} | 
 | 700 |  | 
 | 701 | 	/* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */ | 
 | 702 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 703 | 		struct i40e_vsi *vsi = pf->vsi[v]; | 
 | 704 |  | 
 | 705 | 		if (!vsi) | 
 | 706 | 			continue; | 
 | 707 |  | 
 | 708 | 		for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 709 | 			struct i40e_ring *ring = vsi->tx_rings[i]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 710 |  | 
 | 711 | 			tc = ring->dcb_tc; | 
 | 712 | 			if (xoff[tc]) | 
 | 713 | 				clear_bit(__I40E_HANG_CHECK_ARMED, | 
 | 714 | 					  &ring->state); | 
 | 715 | 		} | 
 | 716 | 	} | 
 | 717 | } | 
 | 718 |  | 
 | 719 | /** | 
 | 720 |  * i40e_update_stats - Update the board statistics counters. | 
 | 721 |  * @vsi: the VSI to be updated | 
 | 722 |  * | 
 | 723 |  * There are a few instances where we store the same stat in a | 
 | 724 |  * couple of different structs.  This is partly because we have | 
 | 725 |  * the netdev stats that need to be filled out, which is slightly | 
 | 726 |  * different from the "eth_stats" defined by the chip and used in | 
 | 727 |  * VF communications.  We sort it all out here in a central place. | 
 | 728 |  **/ | 
 | 729 | void i40e_update_stats(struct i40e_vsi *vsi) | 
 | 730 | { | 
 | 731 | 	struct i40e_pf *pf = vsi->back; | 
 | 732 | 	struct i40e_hw *hw = &pf->hw; | 
 | 733 | 	struct rtnl_link_stats64 *ons; | 
 | 734 | 	struct rtnl_link_stats64 *ns;   /* netdev stats */ | 
 | 735 | 	struct i40e_eth_stats *oes; | 
 | 736 | 	struct i40e_eth_stats *es;     /* device's eth stats */ | 
 | 737 | 	u32 tx_restart, tx_busy; | 
 | 738 | 	u32 rx_page, rx_buf; | 
 | 739 | 	u64 rx_p, rx_b; | 
 | 740 | 	u64 tx_p, tx_b; | 
 | 741 | 	int i; | 
 | 742 | 	u16 q; | 
 | 743 |  | 
 | 744 | 	if (test_bit(__I40E_DOWN, &vsi->state) || | 
 | 745 | 	    test_bit(__I40E_CONFIG_BUSY, &pf->state)) | 
 | 746 | 		return; | 
 | 747 |  | 
 | 748 | 	ns = i40e_get_vsi_stats_struct(vsi); | 
 | 749 | 	ons = &vsi->net_stats_offsets; | 
 | 750 | 	es = &vsi->eth_stats; | 
 | 751 | 	oes = &vsi->eth_stats_offsets; | 
 | 752 |  | 
 | 753 | 	/* Gather up the netdev and vsi stats that the driver collects | 
 | 754 | 	 * on the fly during packet processing | 
 | 755 | 	 */ | 
 | 756 | 	rx_b = rx_p = 0; | 
 | 757 | 	tx_b = tx_p = 0; | 
 | 758 | 	tx_restart = tx_busy = 0; | 
 | 759 | 	rx_page = 0; | 
 | 760 | 	rx_buf = 0; | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 761 | 	rcu_read_lock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 762 | 	for (q = 0; q < vsi->num_queue_pairs; q++) { | 
 | 763 | 		struct i40e_ring *p; | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 764 | 		u64 bytes, packets; | 
 | 765 | 		unsigned int start; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 766 |  | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 767 | 		/* locate Tx ring */ | 
 | 768 | 		p = ACCESS_ONCE(vsi->tx_rings[q]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 769 |  | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 770 | 		do { | 
 | 771 | 			start = u64_stats_fetch_begin_bh(&p->syncp); | 
 | 772 | 			packets = p->stats.packets; | 
 | 773 | 			bytes = p->stats.bytes; | 
 | 774 | 		} while (u64_stats_fetch_retry_bh(&p->syncp, start)); | 
 | 775 | 		tx_b += bytes; | 
 | 776 | 		tx_p += packets; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 777 | 		tx_restart += p->tx_stats.restart_queue; | 
 | 778 | 		tx_busy += p->tx_stats.tx_busy; | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 779 |  | 
 | 780 | 		/* Rx queue is part of the same block as Tx queue */ | 
 | 781 | 		p = &p[1]; | 
 | 782 | 		do { | 
 | 783 | 			start = u64_stats_fetch_begin_bh(&p->syncp); | 
 | 784 | 			packets = p->stats.packets; | 
 | 785 | 			bytes = p->stats.bytes; | 
 | 786 | 		} while (u64_stats_fetch_retry_bh(&p->syncp, start)); | 
 | 787 | 		rx_b += bytes; | 
 | 788 | 		rx_p += packets; | 
 | 789 | 		rx_buf += p->rx_stats.alloc_rx_buff_failed; | 
 | 790 | 		rx_page += p->rx_stats.alloc_rx_page_failed; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 791 | 	} | 
| Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 792 | 	rcu_read_unlock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 793 | 	vsi->tx_restart = tx_restart; | 
 | 794 | 	vsi->tx_busy = tx_busy; | 
 | 795 | 	vsi->rx_page_failed = rx_page; | 
 | 796 | 	vsi->rx_buf_failed = rx_buf; | 
 | 797 |  | 
 | 798 | 	ns->rx_packets = rx_p; | 
 | 799 | 	ns->rx_bytes = rx_b; | 
 | 800 | 	ns->tx_packets = tx_p; | 
 | 801 | 	ns->tx_bytes = tx_b; | 
 | 802 |  | 
 | 803 | 	i40e_update_eth_stats(vsi); | 
 | 804 | 	/* update netdev stats from eth stats */ | 
 | 805 | 	ons->rx_errors = oes->rx_errors; | 
 | 806 | 	ns->rx_errors = es->rx_errors; | 
 | 807 | 	ons->tx_errors = oes->tx_errors; | 
 | 808 | 	ns->tx_errors = es->tx_errors; | 
 | 809 | 	ons->multicast = oes->rx_multicast; | 
 | 810 | 	ns->multicast = es->rx_multicast; | 
 | 811 | 	ons->tx_dropped = oes->tx_discards; | 
 | 812 | 	ns->tx_dropped = es->tx_discards; | 
 | 813 |  | 
 | 814 | 	/* Get the port data only if this is the main PF VSI */ | 
 | 815 | 	if (vsi == pf->vsi[pf->lan_vsi]) { | 
 | 816 | 		struct i40e_hw_port_stats *nsd = &pf->stats; | 
 | 817 | 		struct i40e_hw_port_stats *osd = &pf->stats_offsets; | 
 | 818 |  | 
 | 819 | 		i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port), | 
 | 820 | 				   I40E_GLPRT_GORCL(hw->port), | 
 | 821 | 				   pf->stat_offsets_loaded, | 
 | 822 | 				   &osd->eth.rx_bytes, &nsd->eth.rx_bytes); | 
 | 823 | 		i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port), | 
 | 824 | 				   I40E_GLPRT_GOTCL(hw->port), | 
 | 825 | 				   pf->stat_offsets_loaded, | 
 | 826 | 				   &osd->eth.tx_bytes, &nsd->eth.tx_bytes); | 
 | 827 | 		i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port), | 
 | 828 | 				   pf->stat_offsets_loaded, | 
 | 829 | 				   &osd->eth.rx_discards, | 
 | 830 | 				   &nsd->eth.rx_discards); | 
 | 831 | 		i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port), | 
 | 832 | 				   pf->stat_offsets_loaded, | 
 | 833 | 				   &osd->eth.tx_discards, | 
 | 834 | 				   &nsd->eth.tx_discards); | 
 | 835 | 		i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port), | 
 | 836 | 				   I40E_GLPRT_MPRCL(hw->port), | 
 | 837 | 				   pf->stat_offsets_loaded, | 
 | 838 | 				   &osd->eth.rx_multicast, | 
 | 839 | 				   &nsd->eth.rx_multicast); | 
 | 840 |  | 
 | 841 | 		i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port), | 
 | 842 | 				   pf->stat_offsets_loaded, | 
 | 843 | 				   &osd->tx_dropped_link_down, | 
 | 844 | 				   &nsd->tx_dropped_link_down); | 
 | 845 |  | 
 | 846 | 		i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port), | 
 | 847 | 				   pf->stat_offsets_loaded, | 
 | 848 | 				   &osd->crc_errors, &nsd->crc_errors); | 
 | 849 | 		ns->rx_crc_errors = nsd->crc_errors; | 
 | 850 |  | 
 | 851 | 		i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port), | 
 | 852 | 				   pf->stat_offsets_loaded, | 
 | 853 | 				   &osd->illegal_bytes, &nsd->illegal_bytes); | 
 | 854 | 		ns->rx_errors = nsd->crc_errors | 
 | 855 | 				+ nsd->illegal_bytes; | 
 | 856 |  | 
 | 857 | 		i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port), | 
 | 858 | 				   pf->stat_offsets_loaded, | 
 | 859 | 				   &osd->mac_local_faults, | 
 | 860 | 				   &nsd->mac_local_faults); | 
 | 861 | 		i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port), | 
 | 862 | 				   pf->stat_offsets_loaded, | 
 | 863 | 				   &osd->mac_remote_faults, | 
 | 864 | 				   &nsd->mac_remote_faults); | 
 | 865 |  | 
 | 866 | 		i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port), | 
 | 867 | 				   pf->stat_offsets_loaded, | 
 | 868 | 				   &osd->rx_length_errors, | 
 | 869 | 				   &nsd->rx_length_errors); | 
 | 870 | 		ns->rx_length_errors = nsd->rx_length_errors; | 
 | 871 |  | 
 | 872 | 		i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port), | 
 | 873 | 				   pf->stat_offsets_loaded, | 
 | 874 | 				   &osd->link_xon_rx, &nsd->link_xon_rx); | 
 | 875 | 		i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port), | 
 | 876 | 				   pf->stat_offsets_loaded, | 
 | 877 | 				   &osd->link_xon_tx, &nsd->link_xon_tx); | 
 | 878 | 		i40e_update_prio_xoff_rx(pf);  /* handles I40E_GLPRT_LXOFFRXC */ | 
 | 879 | 		i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port), | 
 | 880 | 				   pf->stat_offsets_loaded, | 
 | 881 | 				   &osd->link_xoff_tx, &nsd->link_xoff_tx); | 
 | 882 |  | 
 | 883 | 		for (i = 0; i < 8; i++) { | 
 | 884 | 			i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i), | 
 | 885 | 					   pf->stat_offsets_loaded, | 
 | 886 | 					   &osd->priority_xon_rx[i], | 
 | 887 | 					   &nsd->priority_xon_rx[i]); | 
 | 888 | 			i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i), | 
 | 889 | 					   pf->stat_offsets_loaded, | 
 | 890 | 					   &osd->priority_xon_tx[i], | 
 | 891 | 					   &nsd->priority_xon_tx[i]); | 
 | 892 | 			i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i), | 
 | 893 | 					   pf->stat_offsets_loaded, | 
 | 894 | 					   &osd->priority_xoff_tx[i], | 
 | 895 | 					   &nsd->priority_xoff_tx[i]); | 
 | 896 | 			i40e_stat_update32(hw, | 
 | 897 | 					   I40E_GLPRT_RXON2OFFCNT(hw->port, i), | 
 | 898 | 					   pf->stat_offsets_loaded, | 
 | 899 | 					   &osd->priority_xon_2_xoff[i], | 
 | 900 | 					   &nsd->priority_xon_2_xoff[i]); | 
 | 901 | 		} | 
 | 902 |  | 
 | 903 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port), | 
 | 904 | 				   I40E_GLPRT_PRC64L(hw->port), | 
 | 905 | 				   pf->stat_offsets_loaded, | 
 | 906 | 				   &osd->rx_size_64, &nsd->rx_size_64); | 
 | 907 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port), | 
 | 908 | 				   I40E_GLPRT_PRC127L(hw->port), | 
 | 909 | 				   pf->stat_offsets_loaded, | 
 | 910 | 				   &osd->rx_size_127, &nsd->rx_size_127); | 
 | 911 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port), | 
 | 912 | 				   I40E_GLPRT_PRC255L(hw->port), | 
 | 913 | 				   pf->stat_offsets_loaded, | 
 | 914 | 				   &osd->rx_size_255, &nsd->rx_size_255); | 
 | 915 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port), | 
 | 916 | 				   I40E_GLPRT_PRC511L(hw->port), | 
 | 917 | 				   pf->stat_offsets_loaded, | 
 | 918 | 				   &osd->rx_size_511, &nsd->rx_size_511); | 
 | 919 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port), | 
 | 920 | 				   I40E_GLPRT_PRC1023L(hw->port), | 
 | 921 | 				   pf->stat_offsets_loaded, | 
 | 922 | 				   &osd->rx_size_1023, &nsd->rx_size_1023); | 
 | 923 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port), | 
 | 924 | 				   I40E_GLPRT_PRC1522L(hw->port), | 
 | 925 | 				   pf->stat_offsets_loaded, | 
 | 926 | 				   &osd->rx_size_1522, &nsd->rx_size_1522); | 
 | 927 | 		i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port), | 
 | 928 | 				   I40E_GLPRT_PRC9522L(hw->port), | 
 | 929 | 				   pf->stat_offsets_loaded, | 
 | 930 | 				   &osd->rx_size_big, &nsd->rx_size_big); | 
 | 931 |  | 
 | 932 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port), | 
 | 933 | 				   I40E_GLPRT_PTC64L(hw->port), | 
 | 934 | 				   pf->stat_offsets_loaded, | 
 | 935 | 				   &osd->tx_size_64, &nsd->tx_size_64); | 
 | 936 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port), | 
 | 937 | 				   I40E_GLPRT_PTC127L(hw->port), | 
 | 938 | 				   pf->stat_offsets_loaded, | 
 | 939 | 				   &osd->tx_size_127, &nsd->tx_size_127); | 
 | 940 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port), | 
 | 941 | 				   I40E_GLPRT_PTC255L(hw->port), | 
 | 942 | 				   pf->stat_offsets_loaded, | 
 | 943 | 				   &osd->tx_size_255, &nsd->tx_size_255); | 
 | 944 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port), | 
 | 945 | 				   I40E_GLPRT_PTC511L(hw->port), | 
 | 946 | 				   pf->stat_offsets_loaded, | 
 | 947 | 				   &osd->tx_size_511, &nsd->tx_size_511); | 
 | 948 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port), | 
 | 949 | 				   I40E_GLPRT_PTC1023L(hw->port), | 
 | 950 | 				   pf->stat_offsets_loaded, | 
 | 951 | 				   &osd->tx_size_1023, &nsd->tx_size_1023); | 
 | 952 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port), | 
 | 953 | 				   I40E_GLPRT_PTC1522L(hw->port), | 
 | 954 | 				   pf->stat_offsets_loaded, | 
 | 955 | 				   &osd->tx_size_1522, &nsd->tx_size_1522); | 
 | 956 | 		i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port), | 
 | 957 | 				   I40E_GLPRT_PTC9522L(hw->port), | 
 | 958 | 				   pf->stat_offsets_loaded, | 
 | 959 | 				   &osd->tx_size_big, &nsd->tx_size_big); | 
 | 960 |  | 
 | 961 | 		i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port), | 
 | 962 | 				   pf->stat_offsets_loaded, | 
 | 963 | 				   &osd->rx_undersize, &nsd->rx_undersize); | 
 | 964 | 		i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port), | 
 | 965 | 				   pf->stat_offsets_loaded, | 
 | 966 | 				   &osd->rx_fragments, &nsd->rx_fragments); | 
 | 967 | 		i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port), | 
 | 968 | 				   pf->stat_offsets_loaded, | 
 | 969 | 				   &osd->rx_oversize, &nsd->rx_oversize); | 
 | 970 | 		i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port), | 
 | 971 | 				   pf->stat_offsets_loaded, | 
 | 972 | 				   &osd->rx_jabber, &nsd->rx_jabber); | 
 | 973 | 	} | 
 | 974 |  | 
 | 975 | 	pf->stat_offsets_loaded = true; | 
 | 976 | } | 
 | 977 |  | 
 | 978 | /** | 
 | 979 |  * i40e_find_filter - Search VSI filter list for specific mac/vlan filter | 
 | 980 |  * @vsi: the VSI to be searched | 
 | 981 |  * @macaddr: the MAC address | 
 | 982 |  * @vlan: the vlan | 
 | 983 |  * @is_vf: make sure its a vf filter, else doesn't matter | 
 | 984 |  * @is_netdev: make sure its a netdev filter, else doesn't matter | 
 | 985 |  * | 
 | 986 |  * Returns ptr to the filter object or NULL | 
 | 987 |  **/ | 
 | 988 | static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi, | 
 | 989 | 						u8 *macaddr, s16 vlan, | 
 | 990 | 						bool is_vf, bool is_netdev) | 
 | 991 | { | 
 | 992 | 	struct i40e_mac_filter *f; | 
 | 993 |  | 
 | 994 | 	if (!vsi || !macaddr) | 
 | 995 | 		return NULL; | 
 | 996 |  | 
 | 997 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 998 | 		if ((ether_addr_equal(macaddr, f->macaddr)) && | 
 | 999 | 		    (vlan == f->vlan)    && | 
 | 1000 | 		    (!is_vf || f->is_vf) && | 
 | 1001 | 		    (!is_netdev || f->is_netdev)) | 
 | 1002 | 			return f; | 
 | 1003 | 	} | 
 | 1004 | 	return NULL; | 
 | 1005 | } | 
 | 1006 |  | 
 | 1007 | /** | 
 | 1008 |  * i40e_find_mac - Find a mac addr in the macvlan filters list | 
 | 1009 |  * @vsi: the VSI to be searched | 
 | 1010 |  * @macaddr: the MAC address we are searching for | 
 | 1011 |  * @is_vf: make sure its a vf filter, else doesn't matter | 
 | 1012 |  * @is_netdev: make sure its a netdev filter, else doesn't matter | 
 | 1013 |  * | 
 | 1014 |  * Returns the first filter with the provided MAC address or NULL if | 
 | 1015 |  * MAC address was not found | 
 | 1016 |  **/ | 
 | 1017 | struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr, | 
 | 1018 | 				      bool is_vf, bool is_netdev) | 
 | 1019 | { | 
 | 1020 | 	struct i40e_mac_filter *f; | 
 | 1021 |  | 
 | 1022 | 	if (!vsi || !macaddr) | 
 | 1023 | 		return NULL; | 
 | 1024 |  | 
 | 1025 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1026 | 		if ((ether_addr_equal(macaddr, f->macaddr)) && | 
 | 1027 | 		    (!is_vf || f->is_vf) && | 
 | 1028 | 		    (!is_netdev || f->is_netdev)) | 
 | 1029 | 			return f; | 
 | 1030 | 	} | 
 | 1031 | 	return NULL; | 
 | 1032 | } | 
 | 1033 |  | 
 | 1034 | /** | 
 | 1035 |  * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode | 
 | 1036 |  * @vsi: the VSI to be searched | 
 | 1037 |  * | 
 | 1038 |  * Returns true if VSI is in vlan mode or false otherwise | 
 | 1039 |  **/ | 
 | 1040 | bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi) | 
 | 1041 | { | 
 | 1042 | 	struct i40e_mac_filter *f; | 
 | 1043 |  | 
 | 1044 | 	/* Only -1 for all the filters denotes not in vlan mode | 
 | 1045 | 	 * so we have to go through all the list in order to make sure | 
 | 1046 | 	 */ | 
 | 1047 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1048 | 		if (f->vlan >= 0) | 
 | 1049 | 			return true; | 
 | 1050 | 	} | 
 | 1051 |  | 
 | 1052 | 	return false; | 
 | 1053 | } | 
 | 1054 |  | 
 | 1055 | /** | 
 | 1056 |  * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans | 
 | 1057 |  * @vsi: the VSI to be searched | 
 | 1058 |  * @macaddr: the mac address to be filtered | 
 | 1059 |  * @is_vf: true if it is a vf | 
 | 1060 |  * @is_netdev: true if it is a netdev | 
 | 1061 |  * | 
 | 1062 |  * Goes through all the macvlan filters and adds a | 
 | 1063 |  * macvlan filter for each unique vlan that already exists | 
 | 1064 |  * | 
 | 1065 |  * Returns first filter found on success, else NULL | 
 | 1066 |  **/ | 
 | 1067 | struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr, | 
 | 1068 | 					     bool is_vf, bool is_netdev) | 
 | 1069 | { | 
 | 1070 | 	struct i40e_mac_filter *f; | 
 | 1071 |  | 
 | 1072 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1073 | 		if (!i40e_find_filter(vsi, macaddr, f->vlan, | 
 | 1074 | 				      is_vf, is_netdev)) { | 
 | 1075 | 			if (!i40e_add_filter(vsi, macaddr, f->vlan, | 
 | 1076 | 						is_vf, is_netdev)) | 
 | 1077 | 				return NULL; | 
 | 1078 | 		} | 
 | 1079 | 	} | 
 | 1080 |  | 
 | 1081 | 	return list_first_entry_or_null(&vsi->mac_filter_list, | 
 | 1082 | 					struct i40e_mac_filter, list); | 
 | 1083 | } | 
 | 1084 |  | 
 | 1085 | /** | 
 | 1086 |  * i40e_add_filter - Add a mac/vlan filter to the VSI | 
 | 1087 |  * @vsi: the VSI to be searched | 
 | 1088 |  * @macaddr: the MAC address | 
 | 1089 |  * @vlan: the vlan | 
 | 1090 |  * @is_vf: make sure its a vf filter, else doesn't matter | 
 | 1091 |  * @is_netdev: make sure its a netdev filter, else doesn't matter | 
 | 1092 |  * | 
 | 1093 |  * Returns ptr to the filter object or NULL when no memory available. | 
 | 1094 |  **/ | 
 | 1095 | struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi, | 
 | 1096 | 					u8 *macaddr, s16 vlan, | 
 | 1097 | 					bool is_vf, bool is_netdev) | 
 | 1098 | { | 
 | 1099 | 	struct i40e_mac_filter *f; | 
 | 1100 |  | 
 | 1101 | 	if (!vsi || !macaddr) | 
 | 1102 | 		return NULL; | 
 | 1103 |  | 
 | 1104 | 	f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); | 
 | 1105 | 	if (!f) { | 
 | 1106 | 		f = kzalloc(sizeof(*f), GFP_ATOMIC); | 
 | 1107 | 		if (!f) | 
 | 1108 | 			goto add_filter_out; | 
 | 1109 |  | 
 | 1110 | 		memcpy(f->macaddr, macaddr, ETH_ALEN); | 
 | 1111 | 		f->vlan = vlan; | 
 | 1112 | 		f->changed = true; | 
 | 1113 |  | 
 | 1114 | 		INIT_LIST_HEAD(&f->list); | 
 | 1115 | 		list_add(&f->list, &vsi->mac_filter_list); | 
 | 1116 | 	} | 
 | 1117 |  | 
 | 1118 | 	/* increment counter and add a new flag if needed */ | 
 | 1119 | 	if (is_vf) { | 
 | 1120 | 		if (!f->is_vf) { | 
 | 1121 | 			f->is_vf = true; | 
 | 1122 | 			f->counter++; | 
 | 1123 | 		} | 
 | 1124 | 	} else if (is_netdev) { | 
 | 1125 | 		if (!f->is_netdev) { | 
 | 1126 | 			f->is_netdev = true; | 
 | 1127 | 			f->counter++; | 
 | 1128 | 		} | 
 | 1129 | 	} else { | 
 | 1130 | 		f->counter++; | 
 | 1131 | 	} | 
 | 1132 |  | 
 | 1133 | 	/* changed tells sync_filters_subtask to | 
 | 1134 | 	 * push the filter down to the firmware | 
 | 1135 | 	 */ | 
 | 1136 | 	if (f->changed) { | 
 | 1137 | 		vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | 
 | 1138 | 		vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | 
 | 1139 | 	} | 
 | 1140 |  | 
 | 1141 | add_filter_out: | 
 | 1142 | 	return f; | 
 | 1143 | } | 
 | 1144 |  | 
 | 1145 | /** | 
 | 1146 |  * i40e_del_filter - Remove a mac/vlan filter from the VSI | 
 | 1147 |  * @vsi: the VSI to be searched | 
 | 1148 |  * @macaddr: the MAC address | 
 | 1149 |  * @vlan: the vlan | 
 | 1150 |  * @is_vf: make sure it's a vf filter, else doesn't matter | 
 | 1151 |  * @is_netdev: make sure it's a netdev filter, else doesn't matter | 
 | 1152 |  **/ | 
 | 1153 | void i40e_del_filter(struct i40e_vsi *vsi, | 
 | 1154 | 		     u8 *macaddr, s16 vlan, | 
 | 1155 | 		     bool is_vf, bool is_netdev) | 
 | 1156 | { | 
 | 1157 | 	struct i40e_mac_filter *f; | 
 | 1158 |  | 
 | 1159 | 	if (!vsi || !macaddr) | 
 | 1160 | 		return; | 
 | 1161 |  | 
 | 1162 | 	f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev); | 
 | 1163 | 	if (!f || f->counter == 0) | 
 | 1164 | 		return; | 
 | 1165 |  | 
 | 1166 | 	if (is_vf) { | 
 | 1167 | 		if (f->is_vf) { | 
 | 1168 | 			f->is_vf = false; | 
 | 1169 | 			f->counter--; | 
 | 1170 | 		} | 
 | 1171 | 	} else if (is_netdev) { | 
 | 1172 | 		if (f->is_netdev) { | 
 | 1173 | 			f->is_netdev = false; | 
 | 1174 | 			f->counter--; | 
 | 1175 | 		} | 
 | 1176 | 	} else { | 
 | 1177 | 		/* make sure we don't remove a filter in use by vf or netdev */ | 
 | 1178 | 		int min_f = 0; | 
 | 1179 | 		min_f += (f->is_vf ? 1 : 0); | 
 | 1180 | 		min_f += (f->is_netdev ? 1 : 0); | 
 | 1181 |  | 
 | 1182 | 		if (f->counter > min_f) | 
 | 1183 | 			f->counter--; | 
 | 1184 | 	} | 
 | 1185 |  | 
 | 1186 | 	/* counter == 0 tells sync_filters_subtask to | 
 | 1187 | 	 * remove the filter from the firmware's list | 
 | 1188 | 	 */ | 
 | 1189 | 	if (f->counter == 0) { | 
 | 1190 | 		f->changed = true; | 
 | 1191 | 		vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | 
 | 1192 | 		vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | 
 | 1193 | 	} | 
 | 1194 | } | 
 | 1195 |  | 
 | 1196 | /** | 
 | 1197 |  * i40e_set_mac - NDO callback to set mac address | 
 | 1198 |  * @netdev: network interface device structure | 
 | 1199 |  * @p: pointer to an address structure | 
 | 1200 |  * | 
 | 1201 |  * Returns 0 on success, negative on failure | 
 | 1202 |  **/ | 
 | 1203 | static int i40e_set_mac(struct net_device *netdev, void *p) | 
 | 1204 | { | 
 | 1205 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1206 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 1207 | 	struct sockaddr *addr = p; | 
 | 1208 | 	struct i40e_mac_filter *f; | 
 | 1209 |  | 
 | 1210 | 	if (!is_valid_ether_addr(addr->sa_data)) | 
 | 1211 | 		return -EADDRNOTAVAIL; | 
 | 1212 |  | 
 | 1213 | 	netdev_info(netdev, "set mac address=%pM\n", addr->sa_data); | 
 | 1214 |  | 
 | 1215 | 	if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) | 
 | 1216 | 		return 0; | 
 | 1217 |  | 
| Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1218 | 	if (test_bit(__I40E_DOWN, &vsi->back->state) || | 
 | 1219 | 	    test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | 
 | 1220 | 		return -EADDRNOTAVAIL; | 
 | 1221 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1222 | 	if (vsi->type == I40E_VSI_MAIN) { | 
 | 1223 | 		i40e_status ret; | 
 | 1224 | 		ret = i40e_aq_mac_address_write(&vsi->back->hw, | 
 | 1225 | 						I40E_AQC_WRITE_TYPE_LAA_ONLY, | 
 | 1226 | 						addr->sa_data, NULL); | 
 | 1227 | 		if (ret) { | 
 | 1228 | 			netdev_info(netdev, | 
 | 1229 | 				    "Addr change for Main VSI failed: %d\n", | 
 | 1230 | 				    ret); | 
 | 1231 | 			return -EADDRNOTAVAIL; | 
 | 1232 | 		} | 
 | 1233 |  | 
 | 1234 | 		memcpy(vsi->back->hw.mac.addr, addr->sa_data, netdev->addr_len); | 
 | 1235 | 	} | 
 | 1236 |  | 
 | 1237 | 	/* In order to be sure to not drop any packets, add the new address | 
 | 1238 | 	 * then delete the old one. | 
 | 1239 | 	 */ | 
 | 1240 | 	f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false); | 
 | 1241 | 	if (!f) | 
 | 1242 | 		return -ENOMEM; | 
 | 1243 |  | 
 | 1244 | 	i40e_sync_vsi_filters(vsi); | 
 | 1245 | 	i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false); | 
 | 1246 | 	i40e_sync_vsi_filters(vsi); | 
 | 1247 |  | 
 | 1248 | 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); | 
 | 1249 |  | 
 | 1250 | 	return 0; | 
 | 1251 | } | 
 | 1252 |  | 
 | 1253 | /** | 
 | 1254 |  * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc | 
 | 1255 |  * @vsi: the VSI being setup | 
 | 1256 |  * @ctxt: VSI context structure | 
 | 1257 |  * @enabled_tc: Enabled TCs bitmap | 
 | 1258 |  * @is_add: True if called before Add VSI | 
 | 1259 |  * | 
 | 1260 |  * Setup VSI queue mapping for enabled traffic classes. | 
 | 1261 |  **/ | 
 | 1262 | static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi, | 
 | 1263 | 				     struct i40e_vsi_context *ctxt, | 
 | 1264 | 				     u8 enabled_tc, | 
 | 1265 | 				     bool is_add) | 
 | 1266 | { | 
 | 1267 | 	struct i40e_pf *pf = vsi->back; | 
 | 1268 | 	u16 sections = 0; | 
 | 1269 | 	u8 netdev_tc = 0; | 
 | 1270 | 	u16 numtc = 0; | 
 | 1271 | 	u16 qcount; | 
 | 1272 | 	u8 offset; | 
 | 1273 | 	u16 qmap; | 
 | 1274 | 	int i; | 
 | 1275 |  | 
 | 1276 | 	sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID; | 
 | 1277 | 	offset = 0; | 
 | 1278 |  | 
 | 1279 | 	if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 1280 | 		/* Find numtc from enabled TC bitmap */ | 
 | 1281 | 		for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 1282 | 			if (enabled_tc & (1 << i)) /* TC is enabled */ | 
 | 1283 | 				numtc++; | 
 | 1284 | 		} | 
 | 1285 | 		if (!numtc) { | 
 | 1286 | 			dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n"); | 
 | 1287 | 			numtc = 1; | 
 | 1288 | 		} | 
 | 1289 | 	} else { | 
 | 1290 | 		/* At least TC0 is enabled in case of non-DCB case */ | 
 | 1291 | 		numtc = 1; | 
 | 1292 | 	} | 
 | 1293 |  | 
 | 1294 | 	vsi->tc_config.numtc = numtc; | 
 | 1295 | 	vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1; | 
 | 1296 |  | 
 | 1297 | 	/* Setup queue offset/count for all TCs for given VSI */ | 
 | 1298 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 1299 | 		/* See if the given TC is enabled for the given VSI */ | 
 | 1300 | 		if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */ | 
 | 1301 | 			int pow, num_qps; | 
 | 1302 |  | 
 | 1303 | 			vsi->tc_config.tc_info[i].qoffset = offset; | 
 | 1304 | 			switch (vsi->type) { | 
 | 1305 | 			case I40E_VSI_MAIN: | 
 | 1306 | 				if (i == 0) | 
 | 1307 | 					qcount = pf->rss_size; | 
 | 1308 | 				else | 
 | 1309 | 					qcount = pf->num_tc_qps; | 
 | 1310 | 				vsi->tc_config.tc_info[i].qcount = qcount; | 
 | 1311 | 				break; | 
 | 1312 | 			case I40E_VSI_FDIR: | 
 | 1313 | 			case I40E_VSI_SRIOV: | 
 | 1314 | 			case I40E_VSI_VMDQ2: | 
 | 1315 | 			default: | 
 | 1316 | 				qcount = vsi->alloc_queue_pairs; | 
 | 1317 | 				vsi->tc_config.tc_info[i].qcount = qcount; | 
 | 1318 | 				WARN_ON(i != 0); | 
 | 1319 | 				break; | 
 | 1320 | 			} | 
 | 1321 |  | 
 | 1322 | 			/* find the power-of-2 of the number of queue pairs */ | 
 | 1323 | 			num_qps = vsi->tc_config.tc_info[i].qcount; | 
 | 1324 | 			pow = 0; | 
 | 1325 | 			while (num_qps && | 
 | 1326 | 			      ((1 << pow) < vsi->tc_config.tc_info[i].qcount)) { | 
 | 1327 | 				pow++; | 
 | 1328 | 				num_qps >>= 1; | 
 | 1329 | 			} | 
 | 1330 |  | 
 | 1331 | 			vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++; | 
 | 1332 | 			qmap = | 
 | 1333 | 			    (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) | | 
 | 1334 | 			    (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT); | 
 | 1335 |  | 
 | 1336 | 			offset += vsi->tc_config.tc_info[i].qcount; | 
 | 1337 | 		} else { | 
 | 1338 | 			/* TC is not enabled so set the offset to | 
 | 1339 | 			 * default queue and allocate one queue | 
 | 1340 | 			 * for the given TC. | 
 | 1341 | 			 */ | 
 | 1342 | 			vsi->tc_config.tc_info[i].qoffset = 0; | 
 | 1343 | 			vsi->tc_config.tc_info[i].qcount = 1; | 
 | 1344 | 			vsi->tc_config.tc_info[i].netdev_tc = 0; | 
 | 1345 |  | 
 | 1346 | 			qmap = 0; | 
 | 1347 | 		} | 
 | 1348 | 		ctxt->info.tc_mapping[i] = cpu_to_le16(qmap); | 
 | 1349 | 	} | 
 | 1350 |  | 
 | 1351 | 	/* Set actual Tx/Rx queue pairs */ | 
 | 1352 | 	vsi->num_queue_pairs = offset; | 
 | 1353 |  | 
 | 1354 | 	/* Scheduler section valid can only be set for ADD VSI */ | 
 | 1355 | 	if (is_add) { | 
 | 1356 | 		sections |= I40E_AQ_VSI_PROP_SCHED_VALID; | 
 | 1357 |  | 
 | 1358 | 		ctxt->info.up_enable_bits = enabled_tc; | 
 | 1359 | 	} | 
 | 1360 | 	if (vsi->type == I40E_VSI_SRIOV) { | 
 | 1361 | 		ctxt->info.mapping_flags |= | 
 | 1362 | 				     cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG); | 
 | 1363 | 		for (i = 0; i < vsi->num_queue_pairs; i++) | 
 | 1364 | 			ctxt->info.queue_mapping[i] = | 
 | 1365 | 					       cpu_to_le16(vsi->base_queue + i); | 
 | 1366 | 	} else { | 
 | 1367 | 		ctxt->info.mapping_flags |= | 
 | 1368 | 					cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG); | 
 | 1369 | 		ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue); | 
 | 1370 | 	} | 
 | 1371 | 	ctxt->info.valid_sections |= cpu_to_le16(sections); | 
 | 1372 | } | 
 | 1373 |  | 
 | 1374 | /** | 
 | 1375 |  * i40e_set_rx_mode - NDO callback to set the netdev filters | 
 | 1376 |  * @netdev: network interface device structure | 
 | 1377 |  **/ | 
 | 1378 | static void i40e_set_rx_mode(struct net_device *netdev) | 
 | 1379 | { | 
 | 1380 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1381 | 	struct i40e_mac_filter *f, *ftmp; | 
 | 1382 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 1383 | 	struct netdev_hw_addr *uca; | 
 | 1384 | 	struct netdev_hw_addr *mca; | 
 | 1385 | 	struct netdev_hw_addr *ha; | 
 | 1386 |  | 
 | 1387 | 	/* add addr if not already in the filter list */ | 
 | 1388 | 	netdev_for_each_uc_addr(uca, netdev) { | 
 | 1389 | 		if (!i40e_find_mac(vsi, uca->addr, false, true)) { | 
 | 1390 | 			if (i40e_is_vsi_in_vlan(vsi)) | 
 | 1391 | 				i40e_put_mac_in_vlan(vsi, uca->addr, | 
 | 1392 | 						     false, true); | 
 | 1393 | 			else | 
 | 1394 | 				i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY, | 
 | 1395 | 						false, true); | 
 | 1396 | 		} | 
 | 1397 | 	} | 
 | 1398 |  | 
 | 1399 | 	netdev_for_each_mc_addr(mca, netdev) { | 
 | 1400 | 		if (!i40e_find_mac(vsi, mca->addr, false, true)) { | 
 | 1401 | 			if (i40e_is_vsi_in_vlan(vsi)) | 
 | 1402 | 				i40e_put_mac_in_vlan(vsi, mca->addr, | 
 | 1403 | 						     false, true); | 
 | 1404 | 			else | 
 | 1405 | 				i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY, | 
 | 1406 | 						false, true); | 
 | 1407 | 		} | 
 | 1408 | 	} | 
 | 1409 |  | 
 | 1410 | 	/* remove filter if not in netdev list */ | 
 | 1411 | 	list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | 
 | 1412 | 		bool found = false; | 
 | 1413 |  | 
 | 1414 | 		if (!f->is_netdev) | 
 | 1415 | 			continue; | 
 | 1416 |  | 
 | 1417 | 		if (is_multicast_ether_addr(f->macaddr)) { | 
 | 1418 | 			netdev_for_each_mc_addr(mca, netdev) { | 
 | 1419 | 				if (ether_addr_equal(mca->addr, f->macaddr)) { | 
 | 1420 | 					found = true; | 
 | 1421 | 					break; | 
 | 1422 | 				} | 
 | 1423 | 			} | 
 | 1424 | 		} else { | 
 | 1425 | 			netdev_for_each_uc_addr(uca, netdev) { | 
 | 1426 | 				if (ether_addr_equal(uca->addr, f->macaddr)) { | 
 | 1427 | 					found = true; | 
 | 1428 | 					break; | 
 | 1429 | 				} | 
 | 1430 | 			} | 
 | 1431 |  | 
 | 1432 | 			for_each_dev_addr(netdev, ha) { | 
 | 1433 | 				if (ether_addr_equal(ha->addr, f->macaddr)) { | 
 | 1434 | 					found = true; | 
 | 1435 | 					break; | 
 | 1436 | 				} | 
 | 1437 | 			} | 
 | 1438 | 		} | 
 | 1439 | 		if (!found) | 
 | 1440 | 			i40e_del_filter( | 
 | 1441 | 			   vsi, f->macaddr, I40E_VLAN_ANY, false, true); | 
 | 1442 | 	} | 
 | 1443 |  | 
 | 1444 | 	/* check for other flag changes */ | 
 | 1445 | 	if (vsi->current_netdev_flags != vsi->netdev->flags) { | 
 | 1446 | 		vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | 
 | 1447 | 		vsi->back->flags |= I40E_FLAG_FILTER_SYNC; | 
 | 1448 | 	} | 
 | 1449 | } | 
 | 1450 |  | 
 | 1451 | /** | 
 | 1452 |  * i40e_sync_vsi_filters - Update the VSI filter list to the HW | 
 | 1453 |  * @vsi: ptr to the VSI | 
 | 1454 |  * | 
 | 1455 |  * Push any outstanding VSI filter changes through the AdminQ. | 
 | 1456 |  * | 
 | 1457 |  * Returns 0 or error value | 
 | 1458 |  **/ | 
 | 1459 | int i40e_sync_vsi_filters(struct i40e_vsi *vsi) | 
 | 1460 | { | 
 | 1461 | 	struct i40e_mac_filter *f, *ftmp; | 
 | 1462 | 	bool promisc_forced_on = false; | 
 | 1463 | 	bool add_happened = false; | 
 | 1464 | 	int filter_list_len = 0; | 
 | 1465 | 	u32 changed_flags = 0; | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1466 | 	i40e_status aq_ret = 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1467 | 	struct i40e_pf *pf; | 
 | 1468 | 	int num_add = 0; | 
 | 1469 | 	int num_del = 0; | 
 | 1470 | 	u16 cmd_flags; | 
 | 1471 |  | 
 | 1472 | 	/* empty array typed pointers, kcalloc later */ | 
 | 1473 | 	struct i40e_aqc_add_macvlan_element_data *add_list; | 
 | 1474 | 	struct i40e_aqc_remove_macvlan_element_data *del_list; | 
 | 1475 |  | 
 | 1476 | 	while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state)) | 
 | 1477 | 		usleep_range(1000, 2000); | 
 | 1478 | 	pf = vsi->back; | 
 | 1479 |  | 
 | 1480 | 	if (vsi->netdev) { | 
 | 1481 | 		changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; | 
 | 1482 | 		vsi->current_netdev_flags = vsi->netdev->flags; | 
 | 1483 | 	} | 
 | 1484 |  | 
 | 1485 | 	if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) { | 
 | 1486 | 		vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED; | 
 | 1487 |  | 
 | 1488 | 		filter_list_len = pf->hw.aq.asq_buf_size / | 
 | 1489 | 			    sizeof(struct i40e_aqc_remove_macvlan_element_data); | 
 | 1490 | 		del_list = kcalloc(filter_list_len, | 
 | 1491 | 			    sizeof(struct i40e_aqc_remove_macvlan_element_data), | 
 | 1492 | 			    GFP_KERNEL); | 
 | 1493 | 		if (!del_list) | 
 | 1494 | 			return -ENOMEM; | 
 | 1495 |  | 
 | 1496 | 		list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | 
 | 1497 | 			if (!f->changed) | 
 | 1498 | 				continue; | 
 | 1499 |  | 
 | 1500 | 			if (f->counter != 0) | 
 | 1501 | 				continue; | 
 | 1502 | 			f->changed = false; | 
 | 1503 | 			cmd_flags = 0; | 
 | 1504 |  | 
 | 1505 | 			/* add to delete list */ | 
 | 1506 | 			memcpy(del_list[num_del].mac_addr, | 
 | 1507 | 			       f->macaddr, ETH_ALEN); | 
 | 1508 | 			del_list[num_del].vlan_tag = | 
 | 1509 | 				cpu_to_le16((u16)(f->vlan == | 
 | 1510 | 					    I40E_VLAN_ANY ? 0 : f->vlan)); | 
 | 1511 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1512 | 			cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH; | 
 | 1513 | 			del_list[num_del].flags = cmd_flags; | 
 | 1514 | 			num_del++; | 
 | 1515 |  | 
 | 1516 | 			/* unlink from filter list */ | 
 | 1517 | 			list_del(&f->list); | 
 | 1518 | 			kfree(f); | 
 | 1519 |  | 
 | 1520 | 			/* flush a full buffer */ | 
 | 1521 | 			if (num_del == filter_list_len) { | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1522 | 				aq_ret = i40e_aq_remove_macvlan(&pf->hw, | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1523 | 					    vsi->seid, del_list, num_del, | 
 | 1524 | 					    NULL); | 
 | 1525 | 				num_del = 0; | 
 | 1526 | 				memset(del_list, 0, sizeof(*del_list)); | 
 | 1527 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1528 | 				if (aq_ret) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1529 | 					dev_info(&pf->pdev->dev, | 
 | 1530 | 						 "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] | 1531 | 						 aq_ret, | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1532 | 						 pf->hw.aq.asq_last_status); | 
 | 1533 | 			} | 
 | 1534 | 		} | 
 | 1535 | 		if (num_del) { | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1536 | 			aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1537 | 						     del_list, num_del, NULL); | 
 | 1538 | 			num_del = 0; | 
 | 1539 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1540 | 			if (aq_ret) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1541 | 				dev_info(&pf->pdev->dev, | 
 | 1542 | 					 "ignoring delete macvlan error, err %d, aq_err %d\n", | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1543 | 					 aq_ret, pf->hw.aq.asq_last_status); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1544 | 		} | 
 | 1545 |  | 
 | 1546 | 		kfree(del_list); | 
 | 1547 | 		del_list = NULL; | 
 | 1548 |  | 
 | 1549 | 		/* do all the adds now */ | 
 | 1550 | 		filter_list_len = pf->hw.aq.asq_buf_size / | 
 | 1551 | 			       sizeof(struct i40e_aqc_add_macvlan_element_data), | 
 | 1552 | 		add_list = kcalloc(filter_list_len, | 
 | 1553 | 			       sizeof(struct i40e_aqc_add_macvlan_element_data), | 
 | 1554 | 			       GFP_KERNEL); | 
 | 1555 | 		if (!add_list) | 
 | 1556 | 			return -ENOMEM; | 
 | 1557 |  | 
 | 1558 | 		list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | 
 | 1559 | 			if (!f->changed) | 
 | 1560 | 				continue; | 
 | 1561 |  | 
 | 1562 | 			if (f->counter == 0) | 
 | 1563 | 				continue; | 
 | 1564 | 			f->changed = false; | 
 | 1565 | 			add_happened = true; | 
 | 1566 | 			cmd_flags = 0; | 
 | 1567 |  | 
 | 1568 | 			/* add to add array */ | 
 | 1569 | 			memcpy(add_list[num_add].mac_addr, | 
 | 1570 | 			       f->macaddr, ETH_ALEN); | 
 | 1571 | 			add_list[num_add].vlan_tag = | 
 | 1572 | 				cpu_to_le16( | 
 | 1573 | 				 (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan)); | 
 | 1574 | 			add_list[num_add].queue_number = 0; | 
 | 1575 |  | 
 | 1576 | 			cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1577 | 			add_list[num_add].flags = cpu_to_le16(cmd_flags); | 
 | 1578 | 			num_add++; | 
 | 1579 |  | 
 | 1580 | 			/* flush a full buffer */ | 
 | 1581 | 			if (num_add == filter_list_len) { | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1582 | 				aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, | 
 | 1583 | 							     add_list, num_add, | 
 | 1584 | 							     NULL); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1585 | 				num_add = 0; | 
 | 1586 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1587 | 				if (aq_ret) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1588 | 					break; | 
 | 1589 | 				memset(add_list, 0, sizeof(*add_list)); | 
 | 1590 | 			} | 
 | 1591 | 		} | 
 | 1592 | 		if (num_add) { | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1593 | 			aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid, | 
 | 1594 | 						     add_list, num_add, NULL); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1595 | 			num_add = 0; | 
 | 1596 | 		} | 
 | 1597 | 		kfree(add_list); | 
 | 1598 | 		add_list = NULL; | 
 | 1599 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1600 | 		if (add_happened && (!aq_ret)) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1601 | 			/* do nothing */; | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1602 | 		} else if (add_happened && (aq_ret)) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1603 | 			dev_info(&pf->pdev->dev, | 
 | 1604 | 				 "add filter failed, err %d, aq_err %d\n", | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1605 | 				 aq_ret, pf->hw.aq.asq_last_status); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1606 | 			if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) && | 
 | 1607 | 			    !test_bit(__I40E_FILTER_OVERFLOW_PROMISC, | 
 | 1608 | 				      &vsi->state)) { | 
 | 1609 | 				promisc_forced_on = true; | 
 | 1610 | 				set_bit(__I40E_FILTER_OVERFLOW_PROMISC, | 
 | 1611 | 					&vsi->state); | 
 | 1612 | 				dev_info(&pf->pdev->dev, "promiscuous mode forced on\n"); | 
 | 1613 | 			} | 
 | 1614 | 		} | 
 | 1615 | 	} | 
 | 1616 |  | 
 | 1617 | 	/* check for changes in promiscuous modes */ | 
 | 1618 | 	if (changed_flags & IFF_ALLMULTI) { | 
 | 1619 | 		bool cur_multipromisc; | 
 | 1620 | 		cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI); | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1621 | 		aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw, | 
 | 1622 | 							       vsi->seid, | 
 | 1623 | 							       cur_multipromisc, | 
 | 1624 | 							       NULL); | 
 | 1625 | 		if (aq_ret) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1626 | 			dev_info(&pf->pdev->dev, | 
 | 1627 | 				 "set multi promisc failed, err %d, aq_err %d\n", | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1628 | 				 aq_ret, pf->hw.aq.asq_last_status); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1629 | 	} | 
 | 1630 | 	if ((changed_flags & IFF_PROMISC) || promisc_forced_on) { | 
 | 1631 | 		bool cur_promisc; | 
 | 1632 | 		cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || | 
 | 1633 | 			       test_bit(__I40E_FILTER_OVERFLOW_PROMISC, | 
 | 1634 | 					&vsi->state)); | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1635 | 		aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw, | 
 | 1636 | 							     vsi->seid, | 
 | 1637 | 							     cur_promisc, NULL); | 
 | 1638 | 		if (aq_ret) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1639 | 			dev_info(&pf->pdev->dev, | 
 | 1640 | 				 "set uni promisc failed, err %d, aq_err %d\n", | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 1641 | 				 aq_ret, pf->hw.aq.asq_last_status); | 
| Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 1642 | 		aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw, | 
 | 1643 | 						   vsi->seid, | 
 | 1644 | 						   cur_promisc, NULL); | 
 | 1645 | 		if (aq_ret) | 
 | 1646 | 			dev_info(&pf->pdev->dev, | 
 | 1647 | 				 "set brdcast promisc failed, err %d, aq_err %d\n", | 
 | 1648 | 				 aq_ret, pf->hw.aq.asq_last_status); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1649 | 	} | 
 | 1650 |  | 
 | 1651 | 	clear_bit(__I40E_CONFIG_BUSY, &vsi->state); | 
 | 1652 | 	return 0; | 
 | 1653 | } | 
 | 1654 |  | 
 | 1655 | /** | 
 | 1656 |  * i40e_sync_filters_subtask - Sync the VSI filter list with HW | 
 | 1657 |  * @pf: board private structure | 
 | 1658 |  **/ | 
 | 1659 | static void i40e_sync_filters_subtask(struct i40e_pf *pf) | 
 | 1660 | { | 
 | 1661 | 	int v; | 
 | 1662 |  | 
 | 1663 | 	if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC)) | 
 | 1664 | 		return; | 
 | 1665 | 	pf->flags &= ~I40E_FLAG_FILTER_SYNC; | 
 | 1666 |  | 
 | 1667 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 1668 | 		if (pf->vsi[v] && | 
 | 1669 | 		    (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) | 
 | 1670 | 			i40e_sync_vsi_filters(pf->vsi[v]); | 
 | 1671 | 	} | 
 | 1672 | } | 
 | 1673 |  | 
 | 1674 | /** | 
 | 1675 |  * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit | 
 | 1676 |  * @netdev: network interface device structure | 
 | 1677 |  * @new_mtu: new value for maximum frame size | 
 | 1678 |  * | 
 | 1679 |  * Returns 0 on success, negative on failure | 
 | 1680 |  **/ | 
 | 1681 | static int i40e_change_mtu(struct net_device *netdev, int new_mtu) | 
 | 1682 | { | 
 | 1683 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1684 | 	int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | 
 | 1685 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 1686 |  | 
 | 1687 | 	/* MTU < 68 is an error and causes problems on some kernels */ | 
 | 1688 | 	if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER)) | 
 | 1689 | 		return -EINVAL; | 
 | 1690 |  | 
 | 1691 | 	netdev_info(netdev, "changing MTU from %d to %d\n", | 
 | 1692 | 		    netdev->mtu, new_mtu); | 
 | 1693 | 	netdev->mtu = new_mtu; | 
 | 1694 | 	if (netif_running(netdev)) | 
 | 1695 | 		i40e_vsi_reinit_locked(vsi); | 
 | 1696 |  | 
 | 1697 | 	return 0; | 
 | 1698 | } | 
 | 1699 |  | 
 | 1700 | /** | 
 | 1701 |  * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI | 
 | 1702 |  * @vsi: the vsi being adjusted | 
 | 1703 |  **/ | 
 | 1704 | void i40e_vlan_stripping_enable(struct i40e_vsi *vsi) | 
 | 1705 | { | 
 | 1706 | 	struct i40e_vsi_context ctxt; | 
 | 1707 | 	i40e_status ret; | 
 | 1708 |  | 
 | 1709 | 	if ((vsi->info.valid_sections & | 
 | 1710 | 	     cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | 
 | 1711 | 	    ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0)) | 
 | 1712 | 		return;  /* already enabled */ | 
 | 1713 |  | 
 | 1714 | 	vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | 
 | 1715 | 	vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | 
 | 1716 | 				    I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH; | 
 | 1717 |  | 
 | 1718 | 	ctxt.seid = vsi->seid; | 
 | 1719 | 	memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | 
 | 1720 | 	ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | 
 | 1721 | 	if (ret) { | 
 | 1722 | 		dev_info(&vsi->back->pdev->dev, | 
 | 1723 | 			 "%s: update vsi failed, aq_err=%d\n", | 
 | 1724 | 			 __func__, vsi->back->hw.aq.asq_last_status); | 
 | 1725 | 	} | 
 | 1726 | } | 
 | 1727 |  | 
 | 1728 | /** | 
 | 1729 |  * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI | 
 | 1730 |  * @vsi: the vsi being adjusted | 
 | 1731 |  **/ | 
 | 1732 | void i40e_vlan_stripping_disable(struct i40e_vsi *vsi) | 
 | 1733 | { | 
 | 1734 | 	struct i40e_vsi_context ctxt; | 
 | 1735 | 	i40e_status ret; | 
 | 1736 |  | 
 | 1737 | 	if ((vsi->info.valid_sections & | 
 | 1738 | 	     cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) && | 
 | 1739 | 	    ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) == | 
 | 1740 | 	     I40E_AQ_VSI_PVLAN_EMOD_MASK)) | 
 | 1741 | 		return;  /* already disabled */ | 
 | 1742 |  | 
 | 1743 | 	vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | 
 | 1744 | 	vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL | | 
 | 1745 | 				    I40E_AQ_VSI_PVLAN_EMOD_NOTHING; | 
 | 1746 |  | 
 | 1747 | 	ctxt.seid = vsi->seid; | 
 | 1748 | 	memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | 
 | 1749 | 	ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | 
 | 1750 | 	if (ret) { | 
 | 1751 | 		dev_info(&vsi->back->pdev->dev, | 
 | 1752 | 			 "%s: update vsi failed, aq_err=%d\n", | 
 | 1753 | 			 __func__, vsi->back->hw.aq.asq_last_status); | 
 | 1754 | 	} | 
 | 1755 | } | 
 | 1756 |  | 
 | 1757 | /** | 
 | 1758 |  * i40e_vlan_rx_register - Setup or shutdown vlan offload | 
 | 1759 |  * @netdev: network interface to be adjusted | 
 | 1760 |  * @features: netdev features to test if VLAN offload is enabled or not | 
 | 1761 |  **/ | 
 | 1762 | static void i40e_vlan_rx_register(struct net_device *netdev, u32 features) | 
 | 1763 | { | 
 | 1764 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1765 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 1766 |  | 
 | 1767 | 	if (features & NETIF_F_HW_VLAN_CTAG_RX) | 
 | 1768 | 		i40e_vlan_stripping_enable(vsi); | 
 | 1769 | 	else | 
 | 1770 | 		i40e_vlan_stripping_disable(vsi); | 
 | 1771 | } | 
 | 1772 |  | 
 | 1773 | /** | 
 | 1774 |  * i40e_vsi_add_vlan - Add vsi membership for given vlan | 
 | 1775 |  * @vsi: the vsi being configured | 
 | 1776 |  * @vid: vlan id to be added (0 = untagged only , -1 = any) | 
 | 1777 |  **/ | 
 | 1778 | int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid) | 
 | 1779 | { | 
 | 1780 | 	struct i40e_mac_filter *f, *add_f; | 
 | 1781 | 	bool is_netdev, is_vf; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1782 |  | 
 | 1783 | 	is_vf = (vsi->type == I40E_VSI_SRIOV); | 
 | 1784 | 	is_netdev = !!(vsi->netdev); | 
 | 1785 |  | 
 | 1786 | 	if (is_netdev) { | 
 | 1787 | 		add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid, | 
 | 1788 | 					is_vf, is_netdev); | 
 | 1789 | 		if (!add_f) { | 
 | 1790 | 			dev_info(&vsi->back->pdev->dev, | 
 | 1791 | 				 "Could not add vlan filter %d for %pM\n", | 
 | 1792 | 				 vid, vsi->netdev->dev_addr); | 
 | 1793 | 			return -ENOMEM; | 
 | 1794 | 		} | 
 | 1795 | 	} | 
 | 1796 |  | 
 | 1797 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1798 | 		add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev); | 
 | 1799 | 		if (!add_f) { | 
 | 1800 | 			dev_info(&vsi->back->pdev->dev, | 
 | 1801 | 				 "Could not add vlan filter %d for %pM\n", | 
 | 1802 | 				 vid, f->macaddr); | 
 | 1803 | 			return -ENOMEM; | 
 | 1804 | 		} | 
 | 1805 | 	} | 
 | 1806 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1807 | 	/* Now if we add a vlan tag, make sure to check if it is the first | 
 | 1808 | 	 * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag" | 
 | 1809 | 	 * with 0, so we now accept untagged and specified tagged traffic | 
 | 1810 | 	 * (and not any taged and untagged) | 
 | 1811 | 	 */ | 
 | 1812 | 	if (vid > 0) { | 
 | 1813 | 		if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr, | 
 | 1814 | 						  I40E_VLAN_ANY, | 
 | 1815 | 						  is_vf, is_netdev)) { | 
 | 1816 | 			i40e_del_filter(vsi, vsi->netdev->dev_addr, | 
 | 1817 | 					I40E_VLAN_ANY, is_vf, is_netdev); | 
 | 1818 | 			add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0, | 
 | 1819 | 						is_vf, is_netdev); | 
 | 1820 | 			if (!add_f) { | 
 | 1821 | 				dev_info(&vsi->back->pdev->dev, | 
 | 1822 | 					 "Could not add filter 0 for %pM\n", | 
 | 1823 | 					 vsi->netdev->dev_addr); | 
 | 1824 | 				return -ENOMEM; | 
 | 1825 | 			} | 
 | 1826 | 		} | 
 | 1827 |  | 
 | 1828 | 		list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1829 | 			if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY, | 
 | 1830 | 					     is_vf, is_netdev)) { | 
 | 1831 | 				i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, | 
 | 1832 | 						is_vf, is_netdev); | 
 | 1833 | 				add_f = i40e_add_filter(vsi, f->macaddr, | 
 | 1834 | 							0, is_vf, is_netdev); | 
 | 1835 | 				if (!add_f) { | 
 | 1836 | 					dev_info(&vsi->back->pdev->dev, | 
 | 1837 | 						 "Could not add filter 0 for %pM\n", | 
 | 1838 | 						 f->macaddr); | 
 | 1839 | 					return -ENOMEM; | 
 | 1840 | 				} | 
 | 1841 | 			} | 
 | 1842 | 		} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1843 | 	} | 
 | 1844 |  | 
| Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1845 | 	if (test_bit(__I40E_DOWN, &vsi->back->state) || | 
 | 1846 | 	    test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | 
 | 1847 | 		return 0; | 
 | 1848 |  | 
 | 1849 | 	return i40e_sync_vsi_filters(vsi); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1850 | } | 
 | 1851 |  | 
 | 1852 | /** | 
 | 1853 |  * i40e_vsi_kill_vlan - Remove vsi membership for given vlan | 
 | 1854 |  * @vsi: the vsi being configured | 
 | 1855 |  * @vid: vlan id to be removed (0 = untagged only , -1 = any) | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1856 |  * | 
 | 1857 |  * Return: 0 on success or negative otherwise | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1858 |  **/ | 
 | 1859 | int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid) | 
 | 1860 | { | 
 | 1861 | 	struct net_device *netdev = vsi->netdev; | 
 | 1862 | 	struct i40e_mac_filter *f, *add_f; | 
 | 1863 | 	bool is_vf, is_netdev; | 
 | 1864 | 	int filter_count = 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1865 |  | 
 | 1866 | 	is_vf = (vsi->type == I40E_VSI_SRIOV); | 
 | 1867 | 	is_netdev = !!(netdev); | 
 | 1868 |  | 
 | 1869 | 	if (is_netdev) | 
 | 1870 | 		i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev); | 
 | 1871 |  | 
 | 1872 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) | 
 | 1873 | 		i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev); | 
 | 1874 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1875 | 	/* go through all the filters for this VSI and if there is only | 
 | 1876 | 	 * vid == 0 it means there are no other filters, so vid 0 must | 
 | 1877 | 	 * be replaced with -1. This signifies that we should from now | 
 | 1878 | 	 * on accept any traffic (with any tag present, or untagged) | 
 | 1879 | 	 */ | 
 | 1880 | 	list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1881 | 		if (is_netdev) { | 
 | 1882 | 			if (f->vlan && | 
 | 1883 | 			    ether_addr_equal(netdev->dev_addr, f->macaddr)) | 
 | 1884 | 				filter_count++; | 
 | 1885 | 		} | 
 | 1886 |  | 
 | 1887 | 		if (f->vlan) | 
 | 1888 | 			filter_count++; | 
 | 1889 | 	} | 
 | 1890 |  | 
 | 1891 | 	if (!filter_count && is_netdev) { | 
 | 1892 | 		i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev); | 
 | 1893 | 		f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, | 
 | 1894 | 				    is_vf, is_netdev); | 
 | 1895 | 		if (!f) { | 
 | 1896 | 			dev_info(&vsi->back->pdev->dev, | 
 | 1897 | 				 "Could not add filter %d for %pM\n", | 
 | 1898 | 				 I40E_VLAN_ANY, netdev->dev_addr); | 
 | 1899 | 			return -ENOMEM; | 
 | 1900 | 		} | 
 | 1901 | 	} | 
 | 1902 |  | 
 | 1903 | 	if (!filter_count) { | 
 | 1904 | 		list_for_each_entry(f, &vsi->mac_filter_list, list) { | 
 | 1905 | 			i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev); | 
 | 1906 | 			add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY, | 
 | 1907 | 					    is_vf, is_netdev); | 
 | 1908 | 			if (!add_f) { | 
 | 1909 | 				dev_info(&vsi->back->pdev->dev, | 
 | 1910 | 					 "Could not add filter %d for %pM\n", | 
 | 1911 | 					 I40E_VLAN_ANY, f->macaddr); | 
 | 1912 | 				return -ENOMEM; | 
 | 1913 | 			} | 
 | 1914 | 		} | 
 | 1915 | 	} | 
 | 1916 |  | 
| Anjali Singhai Jain | 80f6428 | 2013-11-28 06:39:47 +0000 | [diff] [blame] | 1917 | 	if (test_bit(__I40E_DOWN, &vsi->back->state) || | 
 | 1918 | 	    test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state)) | 
 | 1919 | 		return 0; | 
 | 1920 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1921 | 	return i40e_sync_vsi_filters(vsi); | 
 | 1922 | } | 
 | 1923 |  | 
 | 1924 | /** | 
 | 1925 |  * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload | 
 | 1926 |  * @netdev: network interface to be adjusted | 
 | 1927 |  * @vid: vlan id to be added | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1928 |  * | 
 | 1929 |  * net_device_ops implementation for adding vlan ids | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1930 |  **/ | 
 | 1931 | static int i40e_vlan_rx_add_vid(struct net_device *netdev, | 
 | 1932 | 				__always_unused __be16 proto, u16 vid) | 
 | 1933 | { | 
 | 1934 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1935 | 	struct i40e_vsi *vsi = np->vsi; | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1936 | 	int ret = 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1937 |  | 
 | 1938 | 	if (vid > 4095) | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1939 | 		return -EINVAL; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1940 |  | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1941 | 	netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid); | 
 | 1942 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1943 | 	/* If the network stack called us with vid = 0, we should | 
 | 1944 | 	 * indicate to i40e_vsi_add_vlan() that we want to receive | 
 | 1945 | 	 * any traffic (i.e. with any vlan tag, or untagged) | 
 | 1946 | 	 */ | 
 | 1947 | 	ret = i40e_vsi_add_vlan(vsi, vid ? vid : I40E_VLAN_ANY); | 
 | 1948 |  | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1949 | 	if (!ret && (vid < VLAN_N_VID)) | 
 | 1950 | 		set_bit(vid, vsi->active_vlans); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1951 |  | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1952 | 	return ret; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1953 | } | 
 | 1954 |  | 
 | 1955 | /** | 
 | 1956 |  * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload | 
 | 1957 |  * @netdev: network interface to be adjusted | 
 | 1958 |  * @vid: vlan id to be removed | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1959 |  * | 
 | 1960 |  * net_device_ops implementation for adding vlan ids | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1961 |  **/ | 
 | 1962 | static int i40e_vlan_rx_kill_vid(struct net_device *netdev, | 
 | 1963 | 				 __always_unused __be16 proto, u16 vid) | 
 | 1964 | { | 
 | 1965 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 1966 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 1967 |  | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1968 | 	netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid); | 
 | 1969 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1970 | 	/* return code is ignored as there is nothing a user | 
 | 1971 | 	 * can do about failure to remove and a log message was | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1972 | 	 * already printed from the other function | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1973 | 	 */ | 
 | 1974 | 	i40e_vsi_kill_vlan(vsi, vid); | 
 | 1975 |  | 
 | 1976 | 	clear_bit(vid, vsi->active_vlans); | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 1977 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 1978 | 	return 0; | 
 | 1979 | } | 
 | 1980 |  | 
 | 1981 | /** | 
 | 1982 |  * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up | 
 | 1983 |  * @vsi: the vsi being brought back up | 
 | 1984 |  **/ | 
 | 1985 | static void i40e_restore_vlan(struct i40e_vsi *vsi) | 
 | 1986 | { | 
 | 1987 | 	u16 vid; | 
 | 1988 |  | 
 | 1989 | 	if (!vsi->netdev) | 
 | 1990 | 		return; | 
 | 1991 |  | 
 | 1992 | 	i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features); | 
 | 1993 |  | 
 | 1994 | 	for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) | 
 | 1995 | 		i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), | 
 | 1996 | 				     vid); | 
 | 1997 | } | 
 | 1998 |  | 
 | 1999 | /** | 
 | 2000 |  * i40e_vsi_add_pvid - Add pvid for the VSI | 
 | 2001 |  * @vsi: the vsi being adjusted | 
 | 2002 |  * @vid: the vlan id to set as a PVID | 
 | 2003 |  **/ | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2004 | int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2005 | { | 
 | 2006 | 	struct i40e_vsi_context ctxt; | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2007 | 	i40e_status aq_ret; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2008 |  | 
 | 2009 | 	vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | 
 | 2010 | 	vsi->info.pvid = cpu_to_le16(vid); | 
| Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2011 | 	vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED | | 
 | 2012 | 				    I40E_AQ_VSI_PVLAN_INSERT_PVID | | 
| Greg Rose | b774c7d | 2013-11-28 06:39:44 +0000 | [diff] [blame] | 2013 | 				    I40E_AQ_VSI_PVLAN_EMOD_STR; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2014 |  | 
 | 2015 | 	ctxt.seid = vsi->seid; | 
 | 2016 | 	memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2017 | 	aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | 
 | 2018 | 	if (aq_ret) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2019 | 		dev_info(&vsi->back->pdev->dev, | 
 | 2020 | 			 "%s: update vsi failed, aq_err=%d\n", | 
 | 2021 | 			 __func__, vsi->back->hw.aq.asq_last_status); | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2022 | 		return -ENOENT; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2023 | 	} | 
 | 2024 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 2025 | 	return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2026 | } | 
 | 2027 |  | 
 | 2028 | /** | 
 | 2029 |  * i40e_vsi_remove_pvid - Remove the pvid from the VSI | 
 | 2030 |  * @vsi: the vsi being adjusted | 
 | 2031 |  * | 
 | 2032 |  * Just use the vlan_rx_register() service to put it back to normal | 
 | 2033 |  **/ | 
 | 2034 | void i40e_vsi_remove_pvid(struct i40e_vsi *vsi) | 
 | 2035 | { | 
| Greg Rose | 6c12fcb | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 2036 | 	i40e_vlan_stripping_disable(vsi); | 
 | 2037 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2038 | 	vsi->info.pvid = 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2039 | } | 
 | 2040 |  | 
 | 2041 | /** | 
 | 2042 |  * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources | 
 | 2043 |  * @vsi: ptr to the VSI | 
 | 2044 |  * | 
 | 2045 |  * If this function returns with an error, then it's possible one or | 
 | 2046 |  * more of the rings is populated (while the rest are not).  It is the | 
 | 2047 |  * callers duty to clean those orphaned rings. | 
 | 2048 |  * | 
 | 2049 |  * Return 0 on success, negative on failure | 
 | 2050 |  **/ | 
 | 2051 | static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi) | 
 | 2052 | { | 
 | 2053 | 	int i, err = 0; | 
 | 2054 |  | 
 | 2055 | 	for (i = 0; i < vsi->num_queue_pairs && !err; i++) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2056 | 		err = i40e_setup_tx_descriptors(vsi->tx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2057 |  | 
 | 2058 | 	return err; | 
 | 2059 | } | 
 | 2060 |  | 
 | 2061 | /** | 
 | 2062 |  * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues | 
 | 2063 |  * @vsi: ptr to the VSI | 
 | 2064 |  * | 
 | 2065 |  * Free VSI's transmit software resources | 
 | 2066 |  **/ | 
 | 2067 | static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi) | 
 | 2068 | { | 
 | 2069 | 	int i; | 
 | 2070 |  | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2071 | 	if (!vsi->tx_rings) | 
 | 2072 | 		return; | 
 | 2073 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2074 | 	for (i = 0; i < vsi->num_queue_pairs; i++) | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2075 | 		if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2076 | 			i40e_free_tx_resources(vsi->tx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2077 | } | 
 | 2078 |  | 
 | 2079 | /** | 
 | 2080 |  * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources | 
 | 2081 |  * @vsi: ptr to the VSI | 
 | 2082 |  * | 
 | 2083 |  * If this function returns with an error, then it's possible one or | 
 | 2084 |  * more of the rings is populated (while the rest are not).  It is the | 
 | 2085 |  * callers duty to clean those orphaned rings. | 
 | 2086 |  * | 
 | 2087 |  * Return 0 on success, negative on failure | 
 | 2088 |  **/ | 
 | 2089 | static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi) | 
 | 2090 | { | 
 | 2091 | 	int i, err = 0; | 
 | 2092 |  | 
 | 2093 | 	for (i = 0; i < vsi->num_queue_pairs && !err; i++) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2094 | 		err = i40e_setup_rx_descriptors(vsi->rx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2095 | 	return err; | 
 | 2096 | } | 
 | 2097 |  | 
 | 2098 | /** | 
 | 2099 |  * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues | 
 | 2100 |  * @vsi: ptr to the VSI | 
 | 2101 |  * | 
 | 2102 |  * Free all receive software resources | 
 | 2103 |  **/ | 
 | 2104 | static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi) | 
 | 2105 | { | 
 | 2106 | 	int i; | 
 | 2107 |  | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2108 | 	if (!vsi->rx_rings) | 
 | 2109 | 		return; | 
 | 2110 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2111 | 	for (i = 0; i < vsi->num_queue_pairs; i++) | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 2112 | 		if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2113 | 			i40e_free_rx_resources(vsi->rx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2114 | } | 
 | 2115 |  | 
 | 2116 | /** | 
 | 2117 |  * i40e_configure_tx_ring - Configure a transmit ring context and rest | 
 | 2118 |  * @ring: The Tx ring to configure | 
 | 2119 |  * | 
 | 2120 |  * Configure the Tx descriptor ring in the HMC context. | 
 | 2121 |  **/ | 
 | 2122 | static int i40e_configure_tx_ring(struct i40e_ring *ring) | 
 | 2123 | { | 
 | 2124 | 	struct i40e_vsi *vsi = ring->vsi; | 
 | 2125 | 	u16 pf_q = vsi->base_queue + ring->queue_index; | 
 | 2126 | 	struct i40e_hw *hw = &vsi->back->hw; | 
 | 2127 | 	struct i40e_hmc_obj_txq tx_ctx; | 
 | 2128 | 	i40e_status err = 0; | 
 | 2129 | 	u32 qtx_ctl = 0; | 
 | 2130 |  | 
 | 2131 | 	/* some ATR related tx ring init */ | 
 | 2132 | 	if (vsi->back->flags & I40E_FLAG_FDIR_ATR_ENABLED) { | 
 | 2133 | 		ring->atr_sample_rate = vsi->back->atr_sample_rate; | 
 | 2134 | 		ring->atr_count = 0; | 
 | 2135 | 	} else { | 
 | 2136 | 		ring->atr_sample_rate = 0; | 
 | 2137 | 	} | 
 | 2138 |  | 
 | 2139 | 	/* initialize XPS */ | 
 | 2140 | 	if (ring->q_vector && ring->netdev && | 
 | 2141 | 	    !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state)) | 
 | 2142 | 		netif_set_xps_queue(ring->netdev, | 
 | 2143 | 				    &ring->q_vector->affinity_mask, | 
 | 2144 | 				    ring->queue_index); | 
 | 2145 |  | 
 | 2146 | 	/* clear the context structure first */ | 
 | 2147 | 	memset(&tx_ctx, 0, sizeof(tx_ctx)); | 
 | 2148 |  | 
 | 2149 | 	tx_ctx.new_context = 1; | 
 | 2150 | 	tx_ctx.base = (ring->dma / 128); | 
 | 2151 | 	tx_ctx.qlen = ring->count; | 
 | 2152 | 	tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FDIR_ENABLED | | 
 | 2153 | 			I40E_FLAG_FDIR_ATR_ENABLED)); | 
 | 2154 |  | 
 | 2155 | 	/* As part of VSI creation/update, FW allocates certain | 
 | 2156 | 	 * Tx arbitration queue sets for each TC enabled for | 
 | 2157 | 	 * the VSI. The FW returns the handles to these queue | 
 | 2158 | 	 * sets as part of the response buffer to Add VSI, | 
 | 2159 | 	 * Update VSI, etc. AQ commands. It is expected that | 
 | 2160 | 	 * these queue set handles be associated with the Tx | 
 | 2161 | 	 * queues by the driver as part of the TX queue context | 
 | 2162 | 	 * initialization. This has to be done regardless of | 
 | 2163 | 	 * DCB as by default everything is mapped to TC0. | 
 | 2164 | 	 */ | 
 | 2165 | 	tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]); | 
 | 2166 | 	tx_ctx.rdylist_act = 0; | 
 | 2167 |  | 
 | 2168 | 	/* clear the context in the HMC */ | 
 | 2169 | 	err = i40e_clear_lan_tx_queue_context(hw, pf_q); | 
 | 2170 | 	if (err) { | 
 | 2171 | 		dev_info(&vsi->back->pdev->dev, | 
 | 2172 | 			 "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n", | 
 | 2173 | 			 ring->queue_index, pf_q, err); | 
 | 2174 | 		return -ENOMEM; | 
 | 2175 | 	} | 
 | 2176 |  | 
 | 2177 | 	/* set the context in the HMC */ | 
 | 2178 | 	err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx); | 
 | 2179 | 	if (err) { | 
 | 2180 | 		dev_info(&vsi->back->pdev->dev, | 
 | 2181 | 			 "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n", | 
 | 2182 | 			 ring->queue_index, pf_q, err); | 
 | 2183 | 		return -ENOMEM; | 
 | 2184 | 	} | 
 | 2185 |  | 
 | 2186 | 	/* Now associate this queue with this PCI function */ | 
 | 2187 | 	qtx_ctl = I40E_QTX_CTL_PF_QUEUE; | 
| Shannon Nelson | 13fd977 | 2013-09-28 07:14:19 +0000 | [diff] [blame] | 2188 | 	qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) & | 
 | 2189 | 		    I40E_QTX_CTL_PF_INDX_MASK); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2190 | 	wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl); | 
 | 2191 | 	i40e_flush(hw); | 
 | 2192 |  | 
 | 2193 | 	clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state); | 
 | 2194 |  | 
 | 2195 | 	/* cache tail off for easier writes later */ | 
 | 2196 | 	ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q); | 
 | 2197 |  | 
 | 2198 | 	return 0; | 
 | 2199 | } | 
 | 2200 |  | 
 | 2201 | /** | 
 | 2202 |  * i40e_configure_rx_ring - Configure a receive ring context | 
 | 2203 |  * @ring: The Rx ring to configure | 
 | 2204 |  * | 
 | 2205 |  * Configure the Rx descriptor ring in the HMC context. | 
 | 2206 |  **/ | 
 | 2207 | static int i40e_configure_rx_ring(struct i40e_ring *ring) | 
 | 2208 | { | 
 | 2209 | 	struct i40e_vsi *vsi = ring->vsi; | 
 | 2210 | 	u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len; | 
 | 2211 | 	u16 pf_q = vsi->base_queue + ring->queue_index; | 
 | 2212 | 	struct i40e_hw *hw = &vsi->back->hw; | 
 | 2213 | 	struct i40e_hmc_obj_rxq rx_ctx; | 
 | 2214 | 	i40e_status err = 0; | 
 | 2215 |  | 
 | 2216 | 	ring->state = 0; | 
 | 2217 |  | 
 | 2218 | 	/* clear the context structure first */ | 
 | 2219 | 	memset(&rx_ctx, 0, sizeof(rx_ctx)); | 
 | 2220 |  | 
 | 2221 | 	ring->rx_buf_len = vsi->rx_buf_len; | 
 | 2222 | 	ring->rx_hdr_len = vsi->rx_hdr_len; | 
 | 2223 |  | 
 | 2224 | 	rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT; | 
 | 2225 | 	rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT; | 
 | 2226 |  | 
 | 2227 | 	rx_ctx.base = (ring->dma / 128); | 
 | 2228 | 	rx_ctx.qlen = ring->count; | 
 | 2229 |  | 
 | 2230 | 	if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) { | 
 | 2231 | 		set_ring_16byte_desc_enabled(ring); | 
 | 2232 | 		rx_ctx.dsize = 0; | 
 | 2233 | 	} else { | 
 | 2234 | 		rx_ctx.dsize = 1; | 
 | 2235 | 	} | 
 | 2236 |  | 
 | 2237 | 	rx_ctx.dtype = vsi->dtype; | 
 | 2238 | 	if (vsi->dtype) { | 
 | 2239 | 		set_ring_ps_enabled(ring); | 
 | 2240 | 		rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2      | | 
 | 2241 | 				  I40E_RX_SPLIT_IP      | | 
 | 2242 | 				  I40E_RX_SPLIT_TCP_UDP | | 
 | 2243 | 				  I40E_RX_SPLIT_SCTP; | 
 | 2244 | 	} else { | 
 | 2245 | 		rx_ctx.hsplit_0 = 0; | 
 | 2246 | 	} | 
 | 2247 |  | 
 | 2248 | 	rx_ctx.rxmax = min_t(u16, vsi->max_frame, | 
 | 2249 | 				  (chain_len * ring->rx_buf_len)); | 
 | 2250 | 	rx_ctx.tphrdesc_ena = 1; | 
 | 2251 | 	rx_ctx.tphwdesc_ena = 1; | 
 | 2252 | 	rx_ctx.tphdata_ena = 1; | 
 | 2253 | 	rx_ctx.tphhead_ena = 1; | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 2254 | 	if (hw->revision_id == 0) | 
 | 2255 | 		rx_ctx.lrxqthresh = 0; | 
 | 2256 | 	else | 
 | 2257 | 		rx_ctx.lrxqthresh = 2; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2258 | 	rx_ctx.crcstrip = 1; | 
 | 2259 | 	rx_ctx.l2tsel = 1; | 
 | 2260 | 	rx_ctx.showiv = 1; | 
 | 2261 |  | 
 | 2262 | 	/* clear the context in the HMC */ | 
 | 2263 | 	err = i40e_clear_lan_rx_queue_context(hw, pf_q); | 
 | 2264 | 	if (err) { | 
 | 2265 | 		dev_info(&vsi->back->pdev->dev, | 
 | 2266 | 			 "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | 
 | 2267 | 			 ring->queue_index, pf_q, err); | 
 | 2268 | 		return -ENOMEM; | 
 | 2269 | 	} | 
 | 2270 |  | 
 | 2271 | 	/* set the context in the HMC */ | 
 | 2272 | 	err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx); | 
 | 2273 | 	if (err) { | 
 | 2274 | 		dev_info(&vsi->back->pdev->dev, | 
 | 2275 | 			 "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n", | 
 | 2276 | 			 ring->queue_index, pf_q, err); | 
 | 2277 | 		return -ENOMEM; | 
 | 2278 | 	} | 
 | 2279 |  | 
 | 2280 | 	/* cache tail for quicker writes, and clear the reg before use */ | 
 | 2281 | 	ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q); | 
 | 2282 | 	writel(0, ring->tail); | 
 | 2283 |  | 
 | 2284 | 	i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring)); | 
 | 2285 |  | 
 | 2286 | 	return 0; | 
 | 2287 | } | 
 | 2288 |  | 
 | 2289 | /** | 
 | 2290 |  * i40e_vsi_configure_tx - Configure the VSI for Tx | 
 | 2291 |  * @vsi: VSI structure describing this set of rings and resources | 
 | 2292 |  * | 
 | 2293 |  * Configure the Tx VSI for operation. | 
 | 2294 |  **/ | 
 | 2295 | static int i40e_vsi_configure_tx(struct i40e_vsi *vsi) | 
 | 2296 | { | 
 | 2297 | 	int err = 0; | 
 | 2298 | 	u16 i; | 
 | 2299 |  | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2300 | 	for (i = 0; (i < vsi->num_queue_pairs) && !err; i++) | 
 | 2301 | 		err = i40e_configure_tx_ring(vsi->tx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2302 |  | 
 | 2303 | 	return err; | 
 | 2304 | } | 
 | 2305 |  | 
 | 2306 | /** | 
 | 2307 |  * i40e_vsi_configure_rx - Configure the VSI for Rx | 
 | 2308 |  * @vsi: the VSI being configured | 
 | 2309 |  * | 
 | 2310 |  * Configure the Rx VSI for operation. | 
 | 2311 |  **/ | 
 | 2312 | static int i40e_vsi_configure_rx(struct i40e_vsi *vsi) | 
 | 2313 | { | 
 | 2314 | 	int err = 0; | 
 | 2315 | 	u16 i; | 
 | 2316 |  | 
 | 2317 | 	if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN)) | 
 | 2318 | 		vsi->max_frame = vsi->netdev->mtu + ETH_HLEN | 
 | 2319 | 			       + ETH_FCS_LEN + VLAN_HLEN; | 
 | 2320 | 	else | 
 | 2321 | 		vsi->max_frame = I40E_RXBUFFER_2048; | 
 | 2322 |  | 
 | 2323 | 	/* figure out correct receive buffer length */ | 
 | 2324 | 	switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED | | 
 | 2325 | 				    I40E_FLAG_RX_PS_ENABLED)) { | 
 | 2326 | 	case I40E_FLAG_RX_1BUF_ENABLED: | 
 | 2327 | 		vsi->rx_hdr_len = 0; | 
 | 2328 | 		vsi->rx_buf_len = vsi->max_frame; | 
 | 2329 | 		vsi->dtype = I40E_RX_DTYPE_NO_SPLIT; | 
 | 2330 | 		break; | 
 | 2331 | 	case I40E_FLAG_RX_PS_ENABLED: | 
 | 2332 | 		vsi->rx_hdr_len = I40E_RX_HDR_SIZE; | 
 | 2333 | 		vsi->rx_buf_len = I40E_RXBUFFER_2048; | 
 | 2334 | 		vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT; | 
 | 2335 | 		break; | 
 | 2336 | 	default: | 
 | 2337 | 		vsi->rx_hdr_len = I40E_RX_HDR_SIZE; | 
 | 2338 | 		vsi->rx_buf_len = I40E_RXBUFFER_2048; | 
 | 2339 | 		vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS; | 
 | 2340 | 		break; | 
 | 2341 | 	} | 
 | 2342 |  | 
 | 2343 | 	/* round up for the chip's needs */ | 
 | 2344 | 	vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len, | 
 | 2345 | 				(1 << I40E_RXQ_CTX_HBUFF_SHIFT)); | 
 | 2346 | 	vsi->rx_buf_len = ALIGN(vsi->rx_buf_len, | 
 | 2347 | 				(1 << I40E_RXQ_CTX_DBUFF_SHIFT)); | 
 | 2348 |  | 
 | 2349 | 	/* set up individual rings */ | 
 | 2350 | 	for (i = 0; i < vsi->num_queue_pairs && !err; i++) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2351 | 		err = i40e_configure_rx_ring(vsi->rx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2352 |  | 
 | 2353 | 	return err; | 
 | 2354 | } | 
 | 2355 |  | 
 | 2356 | /** | 
 | 2357 |  * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC | 
 | 2358 |  * @vsi: ptr to the VSI | 
 | 2359 |  **/ | 
 | 2360 | static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi) | 
 | 2361 | { | 
 | 2362 | 	u16 qoffset, qcount; | 
 | 2363 | 	int i, n; | 
 | 2364 |  | 
 | 2365 | 	if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) | 
 | 2366 | 		return; | 
 | 2367 |  | 
 | 2368 | 	for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) { | 
 | 2369 | 		if (!(vsi->tc_config.enabled_tc & (1 << n))) | 
 | 2370 | 			continue; | 
 | 2371 |  | 
 | 2372 | 		qoffset = vsi->tc_config.tc_info[n].qoffset; | 
 | 2373 | 		qcount = vsi->tc_config.tc_info[n].qcount; | 
 | 2374 | 		for (i = qoffset; i < (qoffset + qcount); i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2375 | 			struct i40e_ring *rx_ring = vsi->rx_rings[i]; | 
 | 2376 | 			struct i40e_ring *tx_ring = vsi->tx_rings[i]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2377 | 			rx_ring->dcb_tc = n; | 
 | 2378 | 			tx_ring->dcb_tc = n; | 
 | 2379 | 		} | 
 | 2380 | 	} | 
 | 2381 | } | 
 | 2382 |  | 
 | 2383 | /** | 
 | 2384 |  * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI | 
 | 2385 |  * @vsi: ptr to the VSI | 
 | 2386 |  **/ | 
 | 2387 | static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi) | 
 | 2388 | { | 
 | 2389 | 	if (vsi->netdev) | 
 | 2390 | 		i40e_set_rx_mode(vsi->netdev); | 
 | 2391 | } | 
 | 2392 |  | 
 | 2393 | /** | 
 | 2394 |  * i40e_vsi_configure - Set up the VSI for action | 
 | 2395 |  * @vsi: the VSI being configured | 
 | 2396 |  **/ | 
 | 2397 | static int i40e_vsi_configure(struct i40e_vsi *vsi) | 
 | 2398 | { | 
 | 2399 | 	int err; | 
 | 2400 |  | 
 | 2401 | 	i40e_set_vsi_rx_mode(vsi); | 
 | 2402 | 	i40e_restore_vlan(vsi); | 
 | 2403 | 	i40e_vsi_config_dcb_rings(vsi); | 
 | 2404 | 	err = i40e_vsi_configure_tx(vsi); | 
 | 2405 | 	if (!err) | 
 | 2406 | 		err = i40e_vsi_configure_rx(vsi); | 
 | 2407 |  | 
 | 2408 | 	return err; | 
 | 2409 | } | 
 | 2410 |  | 
 | 2411 | /** | 
 | 2412 |  * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW | 
 | 2413 |  * @vsi: the VSI being configured | 
 | 2414 |  **/ | 
 | 2415 | static void i40e_vsi_configure_msix(struct i40e_vsi *vsi) | 
 | 2416 | { | 
 | 2417 | 	struct i40e_pf *pf = vsi->back; | 
 | 2418 | 	struct i40e_q_vector *q_vector; | 
 | 2419 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2420 | 	u16 vector; | 
 | 2421 | 	int i, q; | 
 | 2422 | 	u32 val; | 
 | 2423 | 	u32 qp; | 
 | 2424 |  | 
 | 2425 | 	/* The interrupt indexing is offset by 1 in the PFINT_ITRn | 
 | 2426 | 	 * and PFINT_LNKLSTn registers, e.g.: | 
 | 2427 | 	 *   PFINT_ITRn[0..n-1] gets msix-1..msix-n  (qpair interrupts) | 
 | 2428 | 	 */ | 
 | 2429 | 	qp = vsi->base_queue; | 
 | 2430 | 	vector = vsi->base_vector; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2431 | 	for (i = 0; i < vsi->num_q_vectors; i++, vector++) { | 
 | 2432 | 		q_vector = vsi->q_vectors[i]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2433 | 		q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); | 
 | 2434 | 		q_vector->rx.latency_range = I40E_LOW_LATENCY; | 
 | 2435 | 		wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), | 
 | 2436 | 		     q_vector->rx.itr); | 
 | 2437 | 		q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); | 
 | 2438 | 		q_vector->tx.latency_range = I40E_LOW_LATENCY; | 
 | 2439 | 		wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), | 
 | 2440 | 		     q_vector->tx.itr); | 
 | 2441 |  | 
 | 2442 | 		/* Linked list for the queuepairs assigned to this vector */ | 
 | 2443 | 		wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp); | 
 | 2444 | 		for (q = 0; q < q_vector->num_ringpairs; q++) { | 
 | 2445 | 			val = I40E_QINT_RQCTL_CAUSE_ENA_MASK | | 
 | 2446 | 			      (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT)  | | 
 | 2447 | 			      (vector      << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) | | 
 | 2448 | 			      (qp          << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)| | 
 | 2449 | 			      (I40E_QUEUE_TYPE_TX | 
 | 2450 | 				      << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT); | 
 | 2451 |  | 
 | 2452 | 			wr32(hw, I40E_QINT_RQCTL(qp), val); | 
 | 2453 |  | 
 | 2454 | 			val = I40E_QINT_TQCTL_CAUSE_ENA_MASK | | 
 | 2455 | 			      (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT)  | | 
 | 2456 | 			      (vector      << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) | | 
 | 2457 | 			      ((qp+1)      << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)| | 
 | 2458 | 			      (I40E_QUEUE_TYPE_RX | 
 | 2459 | 				      << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | 
 | 2460 |  | 
 | 2461 | 			/* Terminate the linked list */ | 
 | 2462 | 			if (q == (q_vector->num_ringpairs - 1)) | 
 | 2463 | 				val |= (I40E_QUEUE_END_OF_LIST | 
 | 2464 | 					   << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | 
 | 2465 |  | 
 | 2466 | 			wr32(hw, I40E_QINT_TQCTL(qp), val); | 
 | 2467 | 			qp++; | 
 | 2468 | 		} | 
 | 2469 | 	} | 
 | 2470 |  | 
 | 2471 | 	i40e_flush(hw); | 
 | 2472 | } | 
 | 2473 |  | 
 | 2474 | /** | 
 | 2475 |  * i40e_enable_misc_int_causes - enable the non-queue interrupts | 
 | 2476 |  * @hw: ptr to the hardware info | 
 | 2477 |  **/ | 
 | 2478 | static void i40e_enable_misc_int_causes(struct i40e_hw *hw) | 
 | 2479 | { | 
 | 2480 | 	u32 val; | 
 | 2481 |  | 
 | 2482 | 	/* clear things first */ | 
 | 2483 | 	wr32(hw, I40E_PFINT_ICR0_ENA, 0);  /* disable all */ | 
 | 2484 | 	rd32(hw, I40E_PFINT_ICR0);         /* read to clear */ | 
 | 2485 |  | 
 | 2486 | 	val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK       | | 
 | 2487 | 	      I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK    | | 
 | 2488 | 	      I40E_PFINT_ICR0_ENA_GRST_MASK          | | 
 | 2489 | 	      I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | | 
 | 2490 | 	      I40E_PFINT_ICR0_ENA_GPIO_MASK          | | 
 | 2491 | 	      I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK  | | 
 | 2492 | 	      I40E_PFINT_ICR0_ENA_HMC_ERR_MASK       | | 
 | 2493 | 	      I40E_PFINT_ICR0_ENA_VFLR_MASK          | | 
 | 2494 | 	      I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | 
 | 2495 |  | 
 | 2496 | 	wr32(hw, I40E_PFINT_ICR0_ENA, val); | 
 | 2497 |  | 
 | 2498 | 	/* SW_ITR_IDX = 0, but don't change INTENA */ | 
| Anjali Singhai Jain | 84ed40e | 2013-11-26 10:49:32 +0000 | [diff] [blame] | 2499 | 	wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK | | 
 | 2500 | 					I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2501 |  | 
 | 2502 | 	/* OTHER_ITR_IDX = 0 */ | 
 | 2503 | 	wr32(hw, I40E_PFINT_STAT_CTL0, 0); | 
 | 2504 | } | 
 | 2505 |  | 
 | 2506 | /** | 
 | 2507 |  * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW | 
 | 2508 |  * @vsi: the VSI being configured | 
 | 2509 |  **/ | 
 | 2510 | static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi) | 
 | 2511 | { | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2512 | 	struct i40e_q_vector *q_vector = vsi->q_vectors[0]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2513 | 	struct i40e_pf *pf = vsi->back; | 
 | 2514 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2515 | 	u32 val; | 
 | 2516 |  | 
 | 2517 | 	/* set the ITR configuration */ | 
 | 2518 | 	q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); | 
 | 2519 | 	q_vector->rx.latency_range = I40E_LOW_LATENCY; | 
 | 2520 | 	wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr); | 
 | 2521 | 	q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); | 
 | 2522 | 	q_vector->tx.latency_range = I40E_LOW_LATENCY; | 
 | 2523 | 	wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr); | 
 | 2524 |  | 
 | 2525 | 	i40e_enable_misc_int_causes(hw); | 
 | 2526 |  | 
 | 2527 | 	/* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */ | 
 | 2528 | 	wr32(hw, I40E_PFINT_LNKLST0, 0); | 
 | 2529 |  | 
 | 2530 | 	/* Associate the queue pair to the vector and enable the q int */ | 
 | 2531 | 	val = I40E_QINT_RQCTL_CAUSE_ENA_MASK		      | | 
 | 2532 | 	      (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) | | 
 | 2533 | 	      (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT); | 
 | 2534 |  | 
 | 2535 | 	wr32(hw, I40E_QINT_RQCTL(0), val); | 
 | 2536 |  | 
 | 2537 | 	val = I40E_QINT_TQCTL_CAUSE_ENA_MASK		      | | 
 | 2538 | 	      (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) | | 
 | 2539 | 	      (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT); | 
 | 2540 |  | 
 | 2541 | 	wr32(hw, I40E_QINT_TQCTL(0), val); | 
 | 2542 | 	i40e_flush(hw); | 
 | 2543 | } | 
 | 2544 |  | 
 | 2545 | /** | 
| Mitch Williams | 2ef28cf | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 2546 |  * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0 | 
 | 2547 |  * @pf: board private structure | 
 | 2548 |  **/ | 
 | 2549 | void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf) | 
 | 2550 | { | 
 | 2551 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2552 |  | 
 | 2553 | 	wr32(hw, I40E_PFINT_DYN_CTL0, | 
 | 2554 | 	     I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); | 
 | 2555 | 	i40e_flush(hw); | 
 | 2556 | } | 
 | 2557 |  | 
 | 2558 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2559 |  * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0 | 
 | 2560 |  * @pf: board private structure | 
 | 2561 |  **/ | 
| Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2562 | void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2563 | { | 
 | 2564 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2565 | 	u32 val; | 
 | 2566 |  | 
 | 2567 | 	val = I40E_PFINT_DYN_CTL0_INTENA_MASK   | | 
 | 2568 | 	      I40E_PFINT_DYN_CTL0_CLEARPBA_MASK | | 
 | 2569 | 	      (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT); | 
 | 2570 |  | 
 | 2571 | 	wr32(hw, I40E_PFINT_DYN_CTL0, val); | 
 | 2572 | 	i40e_flush(hw); | 
 | 2573 | } | 
 | 2574 |  | 
 | 2575 | /** | 
 | 2576 |  * i40e_irq_dynamic_enable - Enable default interrupt generation settings | 
 | 2577 |  * @vsi: pointer to a vsi | 
 | 2578 |  * @vector: enable a particular Hw Interrupt vector | 
 | 2579 |  **/ | 
 | 2580 | void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector) | 
 | 2581 | { | 
 | 2582 | 	struct i40e_pf *pf = vsi->back; | 
 | 2583 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2584 | 	u32 val; | 
 | 2585 |  | 
 | 2586 | 	val = I40E_PFINT_DYN_CTLN_INTENA_MASK | | 
 | 2587 | 	      I40E_PFINT_DYN_CTLN_CLEARPBA_MASK | | 
 | 2588 | 	      (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT); | 
 | 2589 | 	wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val); | 
| Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2590 | 	/* skip the flush */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2591 | } | 
 | 2592 |  | 
 | 2593 | /** | 
 | 2594 |  * i40e_msix_clean_rings - MSIX mode Interrupt Handler | 
 | 2595 |  * @irq: interrupt number | 
 | 2596 |  * @data: pointer to a q_vector | 
 | 2597 |  **/ | 
 | 2598 | static irqreturn_t i40e_msix_clean_rings(int irq, void *data) | 
 | 2599 | { | 
 | 2600 | 	struct i40e_q_vector *q_vector = data; | 
 | 2601 |  | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2602 | 	if (!q_vector->tx.ring && !q_vector->rx.ring) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2603 | 		return IRQ_HANDLED; | 
 | 2604 |  | 
 | 2605 | 	napi_schedule(&q_vector->napi); | 
 | 2606 |  | 
 | 2607 | 	return IRQ_HANDLED; | 
 | 2608 | } | 
 | 2609 |  | 
 | 2610 | /** | 
 | 2611 |  * i40e_fdir_clean_rings - Interrupt Handler for FDIR rings | 
 | 2612 |  * @irq: interrupt number | 
 | 2613 |  * @data: pointer to a q_vector | 
 | 2614 |  **/ | 
 | 2615 | static irqreturn_t i40e_fdir_clean_rings(int irq, void *data) | 
 | 2616 | { | 
 | 2617 | 	struct i40e_q_vector *q_vector = data; | 
 | 2618 |  | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2619 | 	if (!q_vector->tx.ring && !q_vector->rx.ring) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2620 | 		return IRQ_HANDLED; | 
 | 2621 |  | 
 | 2622 | 	pr_info("fdir ring cleaning needed\n"); | 
 | 2623 |  | 
 | 2624 | 	return IRQ_HANDLED; | 
 | 2625 | } | 
 | 2626 |  | 
 | 2627 | /** | 
 | 2628 |  * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts | 
 | 2629 |  * @vsi: the VSI being configured | 
 | 2630 |  * @basename: name for the vector | 
 | 2631 |  * | 
 | 2632 |  * Allocates MSI-X vectors and requests interrupts from the kernel. | 
 | 2633 |  **/ | 
 | 2634 | static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename) | 
 | 2635 | { | 
 | 2636 | 	int q_vectors = vsi->num_q_vectors; | 
 | 2637 | 	struct i40e_pf *pf = vsi->back; | 
 | 2638 | 	int base = vsi->base_vector; | 
 | 2639 | 	int rx_int_idx = 0; | 
 | 2640 | 	int tx_int_idx = 0; | 
 | 2641 | 	int vector, err; | 
 | 2642 |  | 
 | 2643 | 	for (vector = 0; vector < q_vectors; vector++) { | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2644 | 		struct i40e_q_vector *q_vector = vsi->q_vectors[vector]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2645 |  | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2646 | 		if (q_vector->tx.ring && q_vector->rx.ring) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2647 | 			snprintf(q_vector->name, sizeof(q_vector->name) - 1, | 
 | 2648 | 				 "%s-%s-%d", basename, "TxRx", rx_int_idx++); | 
 | 2649 | 			tx_int_idx++; | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2650 | 		} else if (q_vector->rx.ring) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2651 | 			snprintf(q_vector->name, sizeof(q_vector->name) - 1, | 
 | 2652 | 				 "%s-%s-%d", basename, "rx", rx_int_idx++); | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2653 | 		} else if (q_vector->tx.ring) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2654 | 			snprintf(q_vector->name, sizeof(q_vector->name) - 1, | 
 | 2655 | 				 "%s-%s-%d", basename, "tx", tx_int_idx++); | 
 | 2656 | 		} else { | 
 | 2657 | 			/* skip this unused q_vector */ | 
 | 2658 | 			continue; | 
 | 2659 | 		} | 
 | 2660 | 		err = request_irq(pf->msix_entries[base + vector].vector, | 
 | 2661 | 				  vsi->irq_handler, | 
 | 2662 | 				  0, | 
 | 2663 | 				  q_vector->name, | 
 | 2664 | 				  q_vector); | 
 | 2665 | 		if (err) { | 
 | 2666 | 			dev_info(&pf->pdev->dev, | 
 | 2667 | 				 "%s: request_irq failed, error: %d\n", | 
 | 2668 | 				 __func__, err); | 
 | 2669 | 			goto free_queue_irqs; | 
 | 2670 | 		} | 
 | 2671 | 		/* assign the mask for this irq */ | 
 | 2672 | 		irq_set_affinity_hint(pf->msix_entries[base + vector].vector, | 
 | 2673 | 				      &q_vector->affinity_mask); | 
 | 2674 | 	} | 
 | 2675 |  | 
 | 2676 | 	return 0; | 
 | 2677 |  | 
 | 2678 | free_queue_irqs: | 
 | 2679 | 	while (vector) { | 
 | 2680 | 		vector--; | 
 | 2681 | 		irq_set_affinity_hint(pf->msix_entries[base + vector].vector, | 
 | 2682 | 				      NULL); | 
 | 2683 | 		free_irq(pf->msix_entries[base + vector].vector, | 
 | 2684 | 			 &(vsi->q_vectors[vector])); | 
 | 2685 | 	} | 
 | 2686 | 	return err; | 
 | 2687 | } | 
 | 2688 |  | 
 | 2689 | /** | 
 | 2690 |  * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI | 
 | 2691 |  * @vsi: the VSI being un-configured | 
 | 2692 |  **/ | 
 | 2693 | static void i40e_vsi_disable_irq(struct i40e_vsi *vsi) | 
 | 2694 | { | 
 | 2695 | 	struct i40e_pf *pf = vsi->back; | 
 | 2696 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2697 | 	int base = vsi->base_vector; | 
 | 2698 | 	int i; | 
 | 2699 |  | 
 | 2700 | 	for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2701 | 		wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0); | 
 | 2702 | 		wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2703 | 	} | 
 | 2704 |  | 
 | 2705 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 2706 | 		for (i = vsi->base_vector; | 
 | 2707 | 		     i < (vsi->num_q_vectors + vsi->base_vector); i++) | 
 | 2708 | 			wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0); | 
 | 2709 |  | 
 | 2710 | 		i40e_flush(hw); | 
 | 2711 | 		for (i = 0; i < vsi->num_q_vectors; i++) | 
 | 2712 | 			synchronize_irq(pf->msix_entries[i + base].vector); | 
 | 2713 | 	} else { | 
 | 2714 | 		/* Legacy and MSI mode - this stops all interrupt handling */ | 
 | 2715 | 		wr32(hw, I40E_PFINT_ICR0_ENA, 0); | 
 | 2716 | 		wr32(hw, I40E_PFINT_DYN_CTL0, 0); | 
 | 2717 | 		i40e_flush(hw); | 
 | 2718 | 		synchronize_irq(pf->pdev->irq); | 
 | 2719 | 	} | 
 | 2720 | } | 
 | 2721 |  | 
 | 2722 | /** | 
 | 2723 |  * i40e_vsi_enable_irq - Enable IRQ for the given VSI | 
 | 2724 |  * @vsi: the VSI being configured | 
 | 2725 |  **/ | 
 | 2726 | static int i40e_vsi_enable_irq(struct i40e_vsi *vsi) | 
 | 2727 | { | 
 | 2728 | 	struct i40e_pf *pf = vsi->back; | 
 | 2729 | 	int i; | 
 | 2730 |  | 
 | 2731 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 2732 | 		for (i = vsi->base_vector; | 
 | 2733 | 		     i < (vsi->num_q_vectors + vsi->base_vector); i++) | 
 | 2734 | 			i40e_irq_dynamic_enable(vsi, i); | 
 | 2735 | 	} else { | 
 | 2736 | 		i40e_irq_dynamic_enable_icr0(pf); | 
 | 2737 | 	} | 
 | 2738 |  | 
| Jesse Brandeburg | 1022cb6 | 2013-09-28 07:13:08 +0000 | [diff] [blame] | 2739 | 	i40e_flush(&pf->hw); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2740 | 	return 0; | 
 | 2741 | } | 
 | 2742 |  | 
 | 2743 | /** | 
 | 2744 |  * i40e_stop_misc_vector - Stop the vector that handles non-queue events | 
 | 2745 |  * @pf: board private structure | 
 | 2746 |  **/ | 
 | 2747 | static void i40e_stop_misc_vector(struct i40e_pf *pf) | 
 | 2748 | { | 
 | 2749 | 	/* Disable ICR 0 */ | 
 | 2750 | 	wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0); | 
 | 2751 | 	i40e_flush(&pf->hw); | 
 | 2752 | } | 
 | 2753 |  | 
 | 2754 | /** | 
 | 2755 |  * i40e_intr - MSI/Legacy and non-queue interrupt handler | 
 | 2756 |  * @irq: interrupt number | 
 | 2757 |  * @data: pointer to a q_vector | 
 | 2758 |  * | 
 | 2759 |  * This is the handler used for all MSI/Legacy interrupts, and deals | 
 | 2760 |  * with both queue and non-queue interrupts.  This is also used in | 
 | 2761 |  * MSIX mode to handle the non-queue interrupts. | 
 | 2762 |  **/ | 
 | 2763 | static irqreturn_t i40e_intr(int irq, void *data) | 
 | 2764 | { | 
 | 2765 | 	struct i40e_pf *pf = (struct i40e_pf *)data; | 
 | 2766 | 	struct i40e_hw *hw = &pf->hw; | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2767 | 	irqreturn_t ret = IRQ_NONE; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2768 | 	u32 icr0, icr0_remaining; | 
 | 2769 | 	u32 val, ena_mask; | 
 | 2770 |  | 
 | 2771 | 	icr0 = rd32(hw, I40E_PFINT_ICR0); | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2772 | 	ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2773 |  | 
| Shannon Nelson | 116a57d | 2013-09-28 07:13:59 +0000 | [diff] [blame] | 2774 | 	/* if sharing a legacy IRQ, we might get called w/o an intr pending */ | 
 | 2775 | 	if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0) | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2776 | 		goto enable_intr; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2777 |  | 
| Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 2778 | 	/* if interrupt but no bits showing, must be SWINT */ | 
 | 2779 | 	if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) || | 
 | 2780 | 	    (icr0 & I40E_PFINT_ICR0_SWINT_MASK)) | 
 | 2781 | 		pf->sw_int_count++; | 
 | 2782 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2783 | 	/* only q0 is used in MSI/Legacy mode, and none are used in MSIX */ | 
 | 2784 | 	if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) { | 
 | 2785 |  | 
 | 2786 | 		/* temporarily disable queue cause for NAPI processing */ | 
 | 2787 | 		u32 qval = rd32(hw, I40E_QINT_RQCTL(0)); | 
 | 2788 | 		qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK; | 
 | 2789 | 		wr32(hw, I40E_QINT_RQCTL(0), qval); | 
 | 2790 |  | 
 | 2791 | 		qval = rd32(hw, I40E_QINT_TQCTL(0)); | 
 | 2792 | 		qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK; | 
 | 2793 | 		wr32(hw, I40E_QINT_TQCTL(0), qval); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2794 |  | 
 | 2795 | 		if (!test_bit(__I40E_DOWN, &pf->state)) | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2796 | 			napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2797 | 	} | 
 | 2798 |  | 
 | 2799 | 	if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) { | 
 | 2800 | 		ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | 
 | 2801 | 		set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | 
 | 2802 | 	} | 
 | 2803 |  | 
 | 2804 | 	if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) { | 
 | 2805 | 		ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | 
 | 2806 | 		set_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | 
 | 2807 | 	} | 
 | 2808 |  | 
 | 2809 | 	if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) { | 
 | 2810 | 		ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK; | 
 | 2811 | 		set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state); | 
 | 2812 | 	} | 
 | 2813 |  | 
 | 2814 | 	if (icr0 & I40E_PFINT_ICR0_GRST_MASK) { | 
 | 2815 | 		if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | 
 | 2816 | 			set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | 
 | 2817 | 		ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK; | 
 | 2818 | 		val = rd32(hw, I40E_GLGEN_RSTAT); | 
 | 2819 | 		val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK) | 
 | 2820 | 		       >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT; | 
| Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2821 | 		if (val == I40E_RESET_CORER) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2822 | 			pf->corer_count++; | 
| Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2823 | 		else if (val == I40E_RESET_GLOBR) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2824 | 			pf->globr_count++; | 
| Shannon Nelson | d52cf0a | 2013-11-16 10:00:39 +0000 | [diff] [blame] | 2825 | 		else if (val == I40E_RESET_EMPR) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2826 | 			pf->empr_count++; | 
 | 2827 | 	} | 
 | 2828 |  | 
| Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2829 | 	if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) { | 
 | 2830 | 		icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK; | 
 | 2831 | 		dev_info(&pf->pdev->dev, "HMC error interrupt\n"); | 
 | 2832 | 	} | 
 | 2833 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2834 | 	/* If a critical error is pending we have no choice but to reset the | 
 | 2835 | 	 * device. | 
 | 2836 | 	 * Report and mask out any remaining unexpected interrupts. | 
 | 2837 | 	 */ | 
 | 2838 | 	icr0_remaining = icr0 & ena_mask; | 
 | 2839 | 	if (icr0_remaining) { | 
 | 2840 | 		dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n", | 
 | 2841 | 			 icr0_remaining); | 
| Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2842 | 		if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) || | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2843 | 		    (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) || | 
 | 2844 | 		    (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK) || | 
 | 2845 | 		    (icr0_remaining & I40E_PFINT_ICR0_MAL_DETECT_MASK)) { | 
| Anjali Singhai Jain | 9c010ee | 2013-11-28 06:39:20 +0000 | [diff] [blame] | 2846 | 			dev_info(&pf->pdev->dev, "device will be reset\n"); | 
 | 2847 | 			set_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | 
 | 2848 | 			i40e_service_event_schedule(pf); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2849 | 		} | 
 | 2850 | 		ena_mask &= ~icr0_remaining; | 
 | 2851 | 	} | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2852 | 	ret = IRQ_HANDLED; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2853 |  | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2854 | enable_intr: | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2855 | 	/* re-enable interrupt causes */ | 
 | 2856 | 	wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2857 | 	if (!test_bit(__I40E_DOWN, &pf->state)) { | 
 | 2858 | 		i40e_service_event_schedule(pf); | 
 | 2859 | 		i40e_irq_dynamic_enable_icr0(pf); | 
 | 2860 | 	} | 
 | 2861 |  | 
| Anjali Singhai Jain | 5e82306 | 2013-12-18 13:45:49 +0000 | [diff] [blame] | 2862 | 	return ret; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2863 | } | 
 | 2864 |  | 
 | 2865 | /** | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2866 |  * i40e_map_vector_to_qp - Assigns the queue pair to the vector | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2867 |  * @vsi: the VSI being configured | 
 | 2868 |  * @v_idx: vector index | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2869 |  * @qp_idx: queue pair index | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2870 |  **/ | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2871 | 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] | 2872 | { | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2873 | 	struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 2874 | 	struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx]; | 
 | 2875 | 	struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2876 |  | 
 | 2877 | 	tx_ring->q_vector = q_vector; | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2878 | 	tx_ring->next = q_vector->tx.ring; | 
 | 2879 | 	q_vector->tx.ring = tx_ring; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2880 | 	q_vector->tx.count++; | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2881 |  | 
 | 2882 | 	rx_ring->q_vector = q_vector; | 
 | 2883 | 	rx_ring->next = q_vector->rx.ring; | 
 | 2884 | 	q_vector->rx.ring = rx_ring; | 
 | 2885 | 	q_vector->rx.count++; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2886 | } | 
 | 2887 |  | 
 | 2888 | /** | 
 | 2889 |  * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors | 
 | 2890 |  * @vsi: the VSI being configured | 
 | 2891 |  * | 
 | 2892 |  * This function maps descriptor rings to the queue-specific vectors | 
 | 2893 |  * we were allotted through the MSI-X enabling code.  Ideally, we'd have | 
 | 2894 |  * one vector per queue pair, but on a constrained vector budget, we | 
 | 2895 |  * group the queue pairs as "efficiently" as possible. | 
 | 2896 |  **/ | 
 | 2897 | static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi) | 
 | 2898 | { | 
 | 2899 | 	int qp_remaining = vsi->num_queue_pairs; | 
 | 2900 | 	int q_vectors = vsi->num_q_vectors; | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2901 | 	int num_ringpairs; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2902 | 	int v_start = 0; | 
 | 2903 | 	int qp_idx = 0; | 
 | 2904 |  | 
 | 2905 | 	/* If we don't have enough vectors for a 1-to-1 mapping, we'll have to | 
 | 2906 | 	 * group them so there are multiple queues per vector. | 
 | 2907 | 	 */ | 
 | 2908 | 	for (; v_start < q_vectors && qp_remaining; v_start++) { | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 2909 | 		struct i40e_q_vector *q_vector = vsi->q_vectors[v_start]; | 
 | 2910 |  | 
 | 2911 | 		num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start); | 
 | 2912 |  | 
 | 2913 | 		q_vector->num_ringpairs = num_ringpairs; | 
 | 2914 |  | 
 | 2915 | 		q_vector->rx.count = 0; | 
 | 2916 | 		q_vector->tx.count = 0; | 
 | 2917 | 		q_vector->rx.ring = NULL; | 
 | 2918 | 		q_vector->tx.ring = NULL; | 
 | 2919 |  | 
 | 2920 | 		while (num_ringpairs--) { | 
 | 2921 | 			map_vector_to_qp(vsi, v_start, qp_idx); | 
 | 2922 | 			qp_idx++; | 
 | 2923 | 			qp_remaining--; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2924 | 		} | 
 | 2925 | 	} | 
 | 2926 | } | 
 | 2927 |  | 
 | 2928 | /** | 
 | 2929 |  * i40e_vsi_request_irq - Request IRQ from the OS | 
 | 2930 |  * @vsi: the VSI being configured | 
 | 2931 |  * @basename: name for the vector | 
 | 2932 |  **/ | 
 | 2933 | static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename) | 
 | 2934 | { | 
 | 2935 | 	struct i40e_pf *pf = vsi->back; | 
 | 2936 | 	int err; | 
 | 2937 |  | 
 | 2938 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) | 
 | 2939 | 		err = i40e_vsi_request_irq_msix(vsi, basename); | 
 | 2940 | 	else if (pf->flags & I40E_FLAG_MSI_ENABLED) | 
 | 2941 | 		err = request_irq(pf->pdev->irq, i40e_intr, 0, | 
 | 2942 | 				  pf->misc_int_name, pf); | 
 | 2943 | 	else | 
 | 2944 | 		err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED, | 
 | 2945 | 				  pf->misc_int_name, pf); | 
 | 2946 |  | 
 | 2947 | 	if (err) | 
 | 2948 | 		dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err); | 
 | 2949 |  | 
 | 2950 | 	return err; | 
 | 2951 | } | 
 | 2952 |  | 
 | 2953 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
 | 2954 | /** | 
 | 2955 |  * i40e_netpoll - A Polling 'interrupt'handler | 
 | 2956 |  * @netdev: network interface device structure | 
 | 2957 |  * | 
 | 2958 |  * This is used by netconsole to send skbs without having to re-enable | 
 | 2959 |  * interrupts.  It's not called while the normal interrupt routine is executing. | 
 | 2960 |  **/ | 
 | 2961 | static void i40e_netpoll(struct net_device *netdev) | 
 | 2962 | { | 
 | 2963 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 2964 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 2965 | 	struct i40e_pf *pf = vsi->back; | 
 | 2966 | 	int i; | 
 | 2967 |  | 
 | 2968 | 	/* if interface is down do nothing */ | 
 | 2969 | 	if (test_bit(__I40E_DOWN, &vsi->state)) | 
 | 2970 | 		return; | 
 | 2971 |  | 
 | 2972 | 	pf->flags |= I40E_FLAG_IN_NETPOLL; | 
 | 2973 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 2974 | 		for (i = 0; i < vsi->num_q_vectors; i++) | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 2975 | 			i40e_msix_clean_rings(0, vsi->q_vectors[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 2976 | 	} else { | 
 | 2977 | 		i40e_intr(pf->pdev->irq, netdev); | 
 | 2978 | 	} | 
 | 2979 | 	pf->flags &= ~I40E_FLAG_IN_NETPOLL; | 
 | 2980 | } | 
 | 2981 | #endif | 
 | 2982 |  | 
 | 2983 | /** | 
 | 2984 |  * i40e_vsi_control_tx - Start or stop a VSI's rings | 
 | 2985 |  * @vsi: the VSI being configured | 
 | 2986 |  * @enable: start or stop the rings | 
 | 2987 |  **/ | 
 | 2988 | static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable) | 
 | 2989 | { | 
 | 2990 | 	struct i40e_pf *pf = vsi->back; | 
 | 2991 | 	struct i40e_hw *hw = &pf->hw; | 
 | 2992 | 	int i, j, pf_q; | 
 | 2993 | 	u32 tx_reg; | 
 | 2994 |  | 
 | 2995 | 	pf_q = vsi->base_queue; | 
 | 2996 | 	for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | 
 | 2997 | 		j = 1000; | 
 | 2998 | 		do { | 
 | 2999 | 			usleep_range(1000, 2000); | 
 | 3000 | 			tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); | 
 | 3001 | 		} while (j-- && ((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) | 
 | 3002 | 			       ^ (tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)) & 1); | 
 | 3003 |  | 
| Mitch Williams | fda972f | 2013-11-28 06:39:29 +0000 | [diff] [blame] | 3004 | 		/* Skip if the queue is already in the requested state */ | 
 | 3005 | 		if (enable && (tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | 
 | 3006 | 			continue; | 
 | 3007 | 		if (!enable && !(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | 
 | 3008 | 			continue; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3009 |  | 
 | 3010 | 		/* turn on/off the queue */ | 
 | 3011 | 		if (enable) | 
 | 3012 | 			tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK | | 
 | 3013 | 				  I40E_QTX_ENA_QENA_STAT_MASK; | 
 | 3014 | 		else | 
 | 3015 | 			tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK; | 
 | 3016 |  | 
 | 3017 | 		wr32(hw, I40E_QTX_ENA(pf_q), tx_reg); | 
 | 3018 |  | 
 | 3019 | 		/* wait for the change to finish */ | 
 | 3020 | 		for (j = 0; j < 10; j++) { | 
 | 3021 | 			tx_reg = rd32(hw, I40E_QTX_ENA(pf_q)); | 
 | 3022 | 			if (enable) { | 
 | 3023 | 				if ((tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | 
 | 3024 | 					break; | 
 | 3025 | 			} else { | 
 | 3026 | 				if (!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK)) | 
 | 3027 | 					break; | 
 | 3028 | 			} | 
 | 3029 |  | 
 | 3030 | 			udelay(10); | 
 | 3031 | 		} | 
 | 3032 | 		if (j >= 10) { | 
 | 3033 | 			dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n", | 
 | 3034 | 				 pf_q, (enable ? "en" : "dis")); | 
 | 3035 | 			return -ETIMEDOUT; | 
 | 3036 | 		} | 
 | 3037 | 	} | 
 | 3038 |  | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 3039 | 	if (hw->revision_id == 0) | 
 | 3040 | 		mdelay(50); | 
 | 3041 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3042 | 	return 0; | 
 | 3043 | } | 
 | 3044 |  | 
 | 3045 | /** | 
 | 3046 |  * i40e_vsi_control_rx - Start or stop a VSI's rings | 
 | 3047 |  * @vsi: the VSI being configured | 
 | 3048 |  * @enable: start or stop the rings | 
 | 3049 |  **/ | 
 | 3050 | static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable) | 
 | 3051 | { | 
 | 3052 | 	struct i40e_pf *pf = vsi->back; | 
 | 3053 | 	struct i40e_hw *hw = &pf->hw; | 
 | 3054 | 	int i, j, pf_q; | 
 | 3055 | 	u32 rx_reg; | 
 | 3056 |  | 
 | 3057 | 	pf_q = vsi->base_queue; | 
 | 3058 | 	for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) { | 
 | 3059 | 		j = 1000; | 
 | 3060 | 		do { | 
 | 3061 | 			usleep_range(1000, 2000); | 
 | 3062 | 			rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); | 
 | 3063 | 		} while (j-- && ((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) | 
 | 3064 | 			       ^ (rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT)) & 1); | 
 | 3065 |  | 
 | 3066 | 		if (enable) { | 
 | 3067 | 			/* is STAT set ? */ | 
 | 3068 | 			if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | 
 | 3069 | 				continue; | 
 | 3070 | 		} else { | 
 | 3071 | 			/* is !STAT set ? */ | 
 | 3072 | 			if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | 
 | 3073 | 				continue; | 
 | 3074 | 		} | 
 | 3075 |  | 
 | 3076 | 		/* turn on/off the queue */ | 
 | 3077 | 		if (enable) | 
 | 3078 | 			rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK | | 
 | 3079 | 				  I40E_QRX_ENA_QENA_STAT_MASK; | 
 | 3080 | 		else | 
 | 3081 | 			rx_reg &= ~(I40E_QRX_ENA_QENA_REQ_MASK | | 
 | 3082 | 				  I40E_QRX_ENA_QENA_STAT_MASK); | 
 | 3083 | 		wr32(hw, I40E_QRX_ENA(pf_q), rx_reg); | 
 | 3084 |  | 
 | 3085 | 		/* wait for the change to finish */ | 
 | 3086 | 		for (j = 0; j < 10; j++) { | 
 | 3087 | 			rx_reg = rd32(hw, I40E_QRX_ENA(pf_q)); | 
 | 3088 |  | 
 | 3089 | 			if (enable) { | 
 | 3090 | 				if ((rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | 
 | 3091 | 					break; | 
 | 3092 | 			} else { | 
 | 3093 | 				if (!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK)) | 
 | 3094 | 					break; | 
 | 3095 | 			} | 
 | 3096 |  | 
 | 3097 | 			udelay(10); | 
 | 3098 | 		} | 
 | 3099 | 		if (j >= 10) { | 
 | 3100 | 			dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n", | 
 | 3101 | 				 pf_q, (enable ? "en" : "dis")); | 
 | 3102 | 			return -ETIMEDOUT; | 
 | 3103 | 		} | 
 | 3104 | 	} | 
 | 3105 |  | 
 | 3106 | 	return 0; | 
 | 3107 | } | 
 | 3108 |  | 
 | 3109 | /** | 
 | 3110 |  * i40e_vsi_control_rings - Start or stop a VSI's rings | 
 | 3111 |  * @vsi: the VSI being configured | 
 | 3112 |  * @enable: start or stop the rings | 
 | 3113 |  **/ | 
| Mitch Williams | fc18eaa | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 3114 | int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3115 | { | 
 | 3116 | 	int ret; | 
 | 3117 |  | 
 | 3118 | 	/* do rx first for enable and last for disable */ | 
 | 3119 | 	if (request) { | 
 | 3120 | 		ret = i40e_vsi_control_rx(vsi, request); | 
 | 3121 | 		if (ret) | 
 | 3122 | 			return ret; | 
 | 3123 | 		ret = i40e_vsi_control_tx(vsi, request); | 
 | 3124 | 	} else { | 
 | 3125 | 		ret = i40e_vsi_control_tx(vsi, request); | 
 | 3126 | 		if (ret) | 
 | 3127 | 			return ret; | 
 | 3128 | 		ret = i40e_vsi_control_rx(vsi, request); | 
 | 3129 | 	} | 
 | 3130 |  | 
 | 3131 | 	return ret; | 
 | 3132 | } | 
 | 3133 |  | 
 | 3134 | /** | 
 | 3135 |  * i40e_vsi_free_irq - Free the irq association with the OS | 
 | 3136 |  * @vsi: the VSI being configured | 
 | 3137 |  **/ | 
 | 3138 | static void i40e_vsi_free_irq(struct i40e_vsi *vsi) | 
 | 3139 | { | 
 | 3140 | 	struct i40e_pf *pf = vsi->back; | 
 | 3141 | 	struct i40e_hw *hw = &pf->hw; | 
 | 3142 | 	int base = vsi->base_vector; | 
 | 3143 | 	u32 val, qp; | 
 | 3144 | 	int i; | 
 | 3145 |  | 
 | 3146 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 3147 | 		if (!vsi->q_vectors) | 
 | 3148 | 			return; | 
 | 3149 |  | 
 | 3150 | 		for (i = 0; i < vsi->num_q_vectors; i++) { | 
 | 3151 | 			u16 vector = i + base; | 
 | 3152 |  | 
 | 3153 | 			/* free only the irqs that were actually requested */ | 
| Shannon Nelson | 78681b1 | 2013-11-28 06:39:36 +0000 | [diff] [blame] | 3154 | 			if (!vsi->q_vectors[i] || | 
 | 3155 | 			    !vsi->q_vectors[i]->num_ringpairs) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3156 | 				continue; | 
 | 3157 |  | 
 | 3158 | 			/* clear the affinity_mask in the IRQ descriptor */ | 
 | 3159 | 			irq_set_affinity_hint(pf->msix_entries[vector].vector, | 
 | 3160 | 					      NULL); | 
 | 3161 | 			free_irq(pf->msix_entries[vector].vector, | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3162 | 				 vsi->q_vectors[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3163 |  | 
 | 3164 | 			/* Tear down the interrupt queue link list | 
 | 3165 | 			 * | 
 | 3166 | 			 * We know that they come in pairs and always | 
 | 3167 | 			 * the Rx first, then the Tx.  To clear the | 
 | 3168 | 			 * link list, stick the EOL value into the | 
 | 3169 | 			 * next_q field of the registers. | 
 | 3170 | 			 */ | 
 | 3171 | 			val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1)); | 
 | 3172 | 			qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | 
 | 3173 | 				>> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | 
 | 3174 | 			val |= I40E_QUEUE_END_OF_LIST | 
 | 3175 | 				<< I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | 
 | 3176 | 			wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val); | 
 | 3177 |  | 
 | 3178 | 			while (qp != I40E_QUEUE_END_OF_LIST) { | 
 | 3179 | 				u32 next; | 
 | 3180 |  | 
 | 3181 | 				val = rd32(hw, I40E_QINT_RQCTL(qp)); | 
 | 3182 |  | 
 | 3183 | 				val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK  | | 
 | 3184 | 					 I40E_QINT_RQCTL_MSIX0_INDX_MASK | | 
 | 3185 | 					 I40E_QINT_RQCTL_CAUSE_ENA_MASK  | | 
 | 3186 | 					 I40E_QINT_RQCTL_INTEVENT_MASK); | 
 | 3187 |  | 
 | 3188 | 				val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | 
 | 3189 | 					 I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | 
 | 3190 |  | 
 | 3191 | 				wr32(hw, I40E_QINT_RQCTL(qp), val); | 
 | 3192 |  | 
 | 3193 | 				val = rd32(hw, I40E_QINT_TQCTL(qp)); | 
 | 3194 |  | 
 | 3195 | 				next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK) | 
 | 3196 | 					>> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT; | 
 | 3197 |  | 
 | 3198 | 				val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK  | | 
 | 3199 | 					 I40E_QINT_TQCTL_MSIX0_INDX_MASK | | 
 | 3200 | 					 I40E_QINT_TQCTL_CAUSE_ENA_MASK  | | 
 | 3201 | 					 I40E_QINT_TQCTL_INTEVENT_MASK); | 
 | 3202 |  | 
 | 3203 | 				val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | 
 | 3204 | 					 I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | 
 | 3205 |  | 
 | 3206 | 				wr32(hw, I40E_QINT_TQCTL(qp), val); | 
 | 3207 | 				qp = next; | 
 | 3208 | 			} | 
 | 3209 | 		} | 
 | 3210 | 	} else { | 
 | 3211 | 		free_irq(pf->pdev->irq, pf); | 
 | 3212 |  | 
 | 3213 | 		val = rd32(hw, I40E_PFINT_LNKLST0); | 
 | 3214 | 		qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK) | 
 | 3215 | 			>> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT; | 
 | 3216 | 		val |= I40E_QUEUE_END_OF_LIST | 
 | 3217 | 			<< I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT; | 
 | 3218 | 		wr32(hw, I40E_PFINT_LNKLST0, val); | 
 | 3219 |  | 
 | 3220 | 		val = rd32(hw, I40E_QINT_RQCTL(qp)); | 
 | 3221 | 		val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK  | | 
 | 3222 | 			 I40E_QINT_RQCTL_MSIX0_INDX_MASK | | 
 | 3223 | 			 I40E_QINT_RQCTL_CAUSE_ENA_MASK  | | 
 | 3224 | 			 I40E_QINT_RQCTL_INTEVENT_MASK); | 
 | 3225 |  | 
 | 3226 | 		val |= (I40E_QINT_RQCTL_ITR_INDX_MASK | | 
 | 3227 | 			I40E_QINT_RQCTL_NEXTQ_INDX_MASK); | 
 | 3228 |  | 
 | 3229 | 		wr32(hw, I40E_QINT_RQCTL(qp), val); | 
 | 3230 |  | 
 | 3231 | 		val = rd32(hw, I40E_QINT_TQCTL(qp)); | 
 | 3232 |  | 
 | 3233 | 		val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK  | | 
 | 3234 | 			 I40E_QINT_TQCTL_MSIX0_INDX_MASK | | 
 | 3235 | 			 I40E_QINT_TQCTL_CAUSE_ENA_MASK  | | 
 | 3236 | 			 I40E_QINT_TQCTL_INTEVENT_MASK); | 
 | 3237 |  | 
 | 3238 | 		val |= (I40E_QINT_TQCTL_ITR_INDX_MASK | | 
 | 3239 | 			I40E_QINT_TQCTL_NEXTQ_INDX_MASK); | 
 | 3240 |  | 
 | 3241 | 		wr32(hw, I40E_QINT_TQCTL(qp), val); | 
 | 3242 | 	} | 
 | 3243 | } | 
 | 3244 |  | 
 | 3245 | /** | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3246 |  * i40e_free_q_vector - Free memory allocated for specific interrupt vector | 
 | 3247 |  * @vsi: the VSI being configured | 
 | 3248 |  * @v_idx: Index of vector to be freed | 
 | 3249 |  * | 
 | 3250 |  * This function frees the memory allocated to the q_vector.  In addition if | 
 | 3251 |  * NAPI is enabled it will delete any references to the NAPI struct prior | 
 | 3252 |  * to freeing the q_vector. | 
 | 3253 |  **/ | 
 | 3254 | static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx) | 
 | 3255 | { | 
 | 3256 | 	struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx]; | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3257 | 	struct i40e_ring *ring; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3258 |  | 
 | 3259 | 	if (!q_vector) | 
 | 3260 | 		return; | 
 | 3261 |  | 
 | 3262 | 	/* disassociate q_vector from rings */ | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 3263 | 	i40e_for_each_ring(ring, q_vector->tx) | 
 | 3264 | 		ring->q_vector = NULL; | 
 | 3265 |  | 
 | 3266 | 	i40e_for_each_ring(ring, q_vector->rx) | 
 | 3267 | 		ring->q_vector = NULL; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3268 |  | 
 | 3269 | 	/* only VSI w/ an associated netdev is set up w/ NAPI */ | 
 | 3270 | 	if (vsi->netdev) | 
 | 3271 | 		netif_napi_del(&q_vector->napi); | 
 | 3272 |  | 
 | 3273 | 	vsi->q_vectors[v_idx] = NULL; | 
 | 3274 |  | 
 | 3275 | 	kfree_rcu(q_vector, rcu); | 
 | 3276 | } | 
 | 3277 |  | 
 | 3278 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3279 |  * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors | 
 | 3280 |  * @vsi: the VSI being un-configured | 
 | 3281 |  * | 
 | 3282 |  * This frees the memory allocated to the q_vectors and | 
 | 3283 |  * deletes references to the NAPI struct. | 
 | 3284 |  **/ | 
 | 3285 | static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi) | 
 | 3286 | { | 
 | 3287 | 	int v_idx; | 
 | 3288 |  | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3289 | 	for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) | 
 | 3290 | 		i40e_free_q_vector(vsi, v_idx); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3291 | } | 
 | 3292 |  | 
 | 3293 | /** | 
 | 3294 |  * i40e_reset_interrupt_capability - Disable interrupt setup in OS | 
 | 3295 |  * @pf: board private structure | 
 | 3296 |  **/ | 
 | 3297 | static void i40e_reset_interrupt_capability(struct i40e_pf *pf) | 
 | 3298 | { | 
 | 3299 | 	/* If we're in Legacy mode, the interrupt was cleaned in vsi_close */ | 
 | 3300 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 3301 | 		pci_disable_msix(pf->pdev); | 
 | 3302 | 		kfree(pf->msix_entries); | 
 | 3303 | 		pf->msix_entries = NULL; | 
 | 3304 | 	} else if (pf->flags & I40E_FLAG_MSI_ENABLED) { | 
 | 3305 | 		pci_disable_msi(pf->pdev); | 
 | 3306 | 	} | 
 | 3307 | 	pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED); | 
 | 3308 | } | 
 | 3309 |  | 
 | 3310 | /** | 
 | 3311 |  * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings | 
 | 3312 |  * @pf: board private structure | 
 | 3313 |  * | 
 | 3314 |  * We go through and clear interrupt specific resources and reset the structure | 
 | 3315 |  * to pre-load conditions | 
 | 3316 |  **/ | 
 | 3317 | static void i40e_clear_interrupt_scheme(struct i40e_pf *pf) | 
 | 3318 | { | 
 | 3319 | 	int i; | 
 | 3320 |  | 
 | 3321 | 	i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1); | 
 | 3322 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | 
 | 3323 | 		if (pf->vsi[i]) | 
 | 3324 | 			i40e_vsi_free_q_vectors(pf->vsi[i]); | 
 | 3325 | 	i40e_reset_interrupt_capability(pf); | 
 | 3326 | } | 
 | 3327 |  | 
 | 3328 | /** | 
 | 3329 |  * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI | 
 | 3330 |  * @vsi: the VSI being configured | 
 | 3331 |  **/ | 
 | 3332 | static void i40e_napi_enable_all(struct i40e_vsi *vsi) | 
 | 3333 | { | 
 | 3334 | 	int q_idx; | 
 | 3335 |  | 
 | 3336 | 	if (!vsi->netdev) | 
 | 3337 | 		return; | 
 | 3338 |  | 
 | 3339 | 	for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3340 | 		napi_enable(&vsi->q_vectors[q_idx]->napi); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3341 | } | 
 | 3342 |  | 
 | 3343 | /** | 
 | 3344 |  * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI | 
 | 3345 |  * @vsi: the VSI being configured | 
 | 3346 |  **/ | 
 | 3347 | static void i40e_napi_disable_all(struct i40e_vsi *vsi) | 
 | 3348 | { | 
 | 3349 | 	int q_idx; | 
 | 3350 |  | 
 | 3351 | 	if (!vsi->netdev) | 
 | 3352 | 		return; | 
 | 3353 |  | 
 | 3354 | 	for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 3355 | 		napi_disable(&vsi->q_vectors[q_idx]->napi); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3356 | } | 
 | 3357 |  | 
 | 3358 | /** | 
 | 3359 |  * i40e_quiesce_vsi - Pause a given VSI | 
 | 3360 |  * @vsi: the VSI being paused | 
 | 3361 |  **/ | 
 | 3362 | static void i40e_quiesce_vsi(struct i40e_vsi *vsi) | 
 | 3363 | { | 
 | 3364 | 	if (test_bit(__I40E_DOWN, &vsi->state)) | 
 | 3365 | 		return; | 
 | 3366 |  | 
 | 3367 | 	set_bit(__I40E_NEEDS_RESTART, &vsi->state); | 
 | 3368 | 	if (vsi->netdev && netif_running(vsi->netdev)) { | 
 | 3369 | 		vsi->netdev->netdev_ops->ndo_stop(vsi->netdev); | 
 | 3370 | 	} else { | 
 | 3371 | 		set_bit(__I40E_DOWN, &vsi->state); | 
 | 3372 | 		i40e_down(vsi); | 
 | 3373 | 	} | 
 | 3374 | } | 
 | 3375 |  | 
 | 3376 | /** | 
 | 3377 |  * i40e_unquiesce_vsi - Resume a given VSI | 
 | 3378 |  * @vsi: the VSI being resumed | 
 | 3379 |  **/ | 
 | 3380 | static void i40e_unquiesce_vsi(struct i40e_vsi *vsi) | 
 | 3381 | { | 
 | 3382 | 	if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state)) | 
 | 3383 | 		return; | 
 | 3384 |  | 
 | 3385 | 	clear_bit(__I40E_NEEDS_RESTART, &vsi->state); | 
 | 3386 | 	if (vsi->netdev && netif_running(vsi->netdev)) | 
 | 3387 | 		vsi->netdev->netdev_ops->ndo_open(vsi->netdev); | 
 | 3388 | 	else | 
 | 3389 | 		i40e_up(vsi);   /* this clears the DOWN bit */ | 
 | 3390 | } | 
 | 3391 |  | 
 | 3392 | /** | 
 | 3393 |  * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF | 
 | 3394 |  * @pf: the PF | 
 | 3395 |  **/ | 
 | 3396 | static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf) | 
 | 3397 | { | 
 | 3398 | 	int v; | 
 | 3399 |  | 
 | 3400 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 3401 | 		if (pf->vsi[v]) | 
 | 3402 | 			i40e_quiesce_vsi(pf->vsi[v]); | 
 | 3403 | 	} | 
 | 3404 | } | 
 | 3405 |  | 
 | 3406 | /** | 
 | 3407 |  * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF | 
 | 3408 |  * @pf: the PF | 
 | 3409 |  **/ | 
 | 3410 | static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf) | 
 | 3411 | { | 
 | 3412 | 	int v; | 
 | 3413 |  | 
 | 3414 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 3415 | 		if (pf->vsi[v]) | 
 | 3416 | 			i40e_unquiesce_vsi(pf->vsi[v]); | 
 | 3417 | 	} | 
 | 3418 | } | 
 | 3419 |  | 
 | 3420 | /** | 
 | 3421 |  * i40e_dcb_get_num_tc -  Get the number of TCs from DCBx config | 
 | 3422 |  * @dcbcfg: the corresponding DCBx configuration structure | 
 | 3423 |  * | 
 | 3424 |  * Return the number of TCs from given DCBx configuration | 
 | 3425 |  **/ | 
 | 3426 | static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg) | 
 | 3427 | { | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3428 | 	u8 num_tc = 0; | 
 | 3429 | 	int i; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3430 |  | 
 | 3431 | 	/* Scan the ETS Config Priority Table to find | 
 | 3432 | 	 * traffic class enabled for a given priority | 
 | 3433 | 	 * and use the traffic class index to get the | 
 | 3434 | 	 * number of traffic classes enabled | 
 | 3435 | 	 */ | 
 | 3436 | 	for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | 
 | 3437 | 		if (dcbcfg->etscfg.prioritytable[i] > num_tc) | 
 | 3438 | 			num_tc = dcbcfg->etscfg.prioritytable[i]; | 
 | 3439 | 	} | 
 | 3440 |  | 
 | 3441 | 	/* Traffic class index starts from zero so | 
 | 3442 | 	 * increment to return the actual count | 
 | 3443 | 	 */ | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3444 | 	return num_tc + 1; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3445 | } | 
 | 3446 |  | 
 | 3447 | /** | 
 | 3448 |  * i40e_dcb_get_enabled_tc - Get enabled traffic classes | 
 | 3449 |  * @dcbcfg: the corresponding DCBx configuration structure | 
 | 3450 |  * | 
 | 3451 |  * Query the current DCB configuration and return the number of | 
 | 3452 |  * traffic classes enabled from the given DCBX config | 
 | 3453 |  **/ | 
 | 3454 | static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg) | 
 | 3455 | { | 
 | 3456 | 	u8 num_tc = i40e_dcb_get_num_tc(dcbcfg); | 
 | 3457 | 	u8 enabled_tc = 1; | 
 | 3458 | 	u8 i; | 
 | 3459 |  | 
 | 3460 | 	for (i = 0; i < num_tc; i++) | 
 | 3461 | 		enabled_tc |= 1 << i; | 
 | 3462 |  | 
 | 3463 | 	return enabled_tc; | 
 | 3464 | } | 
 | 3465 |  | 
 | 3466 | /** | 
 | 3467 |  * i40e_pf_get_num_tc - Get enabled traffic classes for PF | 
 | 3468 |  * @pf: PF being queried | 
 | 3469 |  * | 
 | 3470 |  * Return number of traffic classes enabled for the given PF | 
 | 3471 |  **/ | 
 | 3472 | static u8 i40e_pf_get_num_tc(struct i40e_pf *pf) | 
 | 3473 | { | 
 | 3474 | 	struct i40e_hw *hw = &pf->hw; | 
 | 3475 | 	u8 i, enabled_tc; | 
 | 3476 | 	u8 num_tc = 0; | 
 | 3477 | 	struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | 
 | 3478 |  | 
 | 3479 | 	/* If DCB is not enabled then always in single TC */ | 
 | 3480 | 	if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | 
 | 3481 | 		return 1; | 
 | 3482 |  | 
 | 3483 | 	/* MFP mode return count of enabled TCs for this PF */ | 
 | 3484 | 	if (pf->flags & I40E_FLAG_MFP_ENABLED) { | 
 | 3485 | 		enabled_tc = pf->hw.func_caps.enabled_tcmap; | 
 | 3486 | 		for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 3487 | 			if (enabled_tc & (1 << i)) | 
 | 3488 | 				num_tc++; | 
 | 3489 | 		} | 
 | 3490 | 		return num_tc; | 
 | 3491 | 	} | 
 | 3492 |  | 
 | 3493 | 	/* SFP mode will be enabled for all TCs on port */ | 
 | 3494 | 	return i40e_dcb_get_num_tc(dcbcfg); | 
 | 3495 | } | 
 | 3496 |  | 
 | 3497 | /** | 
 | 3498 |  * i40e_pf_get_default_tc - Get bitmap for first enabled TC | 
 | 3499 |  * @pf: PF being queried | 
 | 3500 |  * | 
 | 3501 |  * Return a bitmap for first enabled traffic class for this PF. | 
 | 3502 |  **/ | 
 | 3503 | static u8 i40e_pf_get_default_tc(struct i40e_pf *pf) | 
 | 3504 | { | 
 | 3505 | 	u8 enabled_tc = pf->hw.func_caps.enabled_tcmap; | 
 | 3506 | 	u8 i = 0; | 
 | 3507 |  | 
 | 3508 | 	if (!enabled_tc) | 
 | 3509 | 		return 0x1; /* TC0 */ | 
 | 3510 |  | 
 | 3511 | 	/* Find the first enabled TC */ | 
 | 3512 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 3513 | 		if (enabled_tc & (1 << i)) | 
 | 3514 | 			break; | 
 | 3515 | 	} | 
 | 3516 |  | 
 | 3517 | 	return 1 << i; | 
 | 3518 | } | 
 | 3519 |  | 
 | 3520 | /** | 
 | 3521 |  * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes | 
 | 3522 |  * @pf: PF being queried | 
 | 3523 |  * | 
 | 3524 |  * Return a bitmap for enabled traffic classes for this PF. | 
 | 3525 |  **/ | 
 | 3526 | static u8 i40e_pf_get_tc_map(struct i40e_pf *pf) | 
 | 3527 | { | 
 | 3528 | 	/* If DCB is not enabled for this PF then just return default TC */ | 
 | 3529 | 	if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) | 
 | 3530 | 		return i40e_pf_get_default_tc(pf); | 
 | 3531 |  | 
 | 3532 | 	/* MFP mode will have enabled TCs set by FW */ | 
 | 3533 | 	if (pf->flags & I40E_FLAG_MFP_ENABLED) | 
 | 3534 | 		return pf->hw.func_caps.enabled_tcmap; | 
 | 3535 |  | 
 | 3536 | 	/* SFP mode we want PF to be enabled for all TCs */ | 
 | 3537 | 	return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config); | 
 | 3538 | } | 
 | 3539 |  | 
 | 3540 | /** | 
 | 3541 |  * i40e_vsi_get_bw_info - Query VSI BW Information | 
 | 3542 |  * @vsi: the VSI being queried | 
 | 3543 |  * | 
 | 3544 |  * Returns 0 on success, negative value on failure | 
 | 3545 |  **/ | 
 | 3546 | static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi) | 
 | 3547 | { | 
 | 3548 | 	struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0}; | 
 | 3549 | 	struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0}; | 
 | 3550 | 	struct i40e_pf *pf = vsi->back; | 
 | 3551 | 	struct i40e_hw *hw = &pf->hw; | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3552 | 	i40e_status aq_ret; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3553 | 	u32 tc_bw_max; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3554 | 	int i; | 
 | 3555 |  | 
 | 3556 | 	/* Get the VSI level BW configuration */ | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3557 | 	aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL); | 
 | 3558 | 	if (aq_ret) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3559 | 		dev_info(&pf->pdev->dev, | 
 | 3560 | 			 "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] | 3561 | 			 aq_ret, pf->hw.aq.asq_last_status); | 
 | 3562 | 		return -EINVAL; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3563 | 	} | 
 | 3564 |  | 
 | 3565 | 	/* Get the VSI level BW configuration per TC */ | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3566 | 	aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config, | 
 | 3567 | 					          NULL); | 
 | 3568 | 	if (aq_ret) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3569 | 		dev_info(&pf->pdev->dev, | 
 | 3570 | 			 "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] | 3571 | 			 aq_ret, pf->hw.aq.asq_last_status); | 
 | 3572 | 		return -EINVAL; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3573 | 	} | 
 | 3574 |  | 
 | 3575 | 	if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) { | 
 | 3576 | 		dev_info(&pf->pdev->dev, | 
 | 3577 | 			 "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n", | 
 | 3578 | 			 bw_config.tc_valid_bits, | 
 | 3579 | 			 bw_ets_config.tc_valid_bits); | 
 | 3580 | 		/* Still continuing */ | 
 | 3581 | 	} | 
 | 3582 |  | 
 | 3583 | 	vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit); | 
 | 3584 | 	vsi->bw_max_quanta = bw_config.max_bw; | 
 | 3585 | 	tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) | | 
 | 3586 | 		    (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16); | 
 | 3587 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 3588 | 		vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i]; | 
 | 3589 | 		vsi->bw_ets_limit_credits[i] = | 
 | 3590 | 					le16_to_cpu(bw_ets_config.credits[i]); | 
 | 3591 | 		/* 3 bits out of 4 for each TC */ | 
 | 3592 | 		vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7); | 
 | 3593 | 	} | 
| Jesse Brandeburg | 078b587 | 2013-09-25 23:41:14 +0000 | [diff] [blame] | 3594 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3595 | 	return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3596 | } | 
 | 3597 |  | 
 | 3598 | /** | 
 | 3599 |  * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC | 
 | 3600 |  * @vsi: the VSI being configured | 
 | 3601 |  * @enabled_tc: TC bitmap | 
 | 3602 |  * @bw_credits: BW shared credits per TC | 
 | 3603 |  * | 
 | 3604 |  * Returns 0 on success, negative value on failure | 
 | 3605 |  **/ | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3606 | 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] | 3607 | 				       u8 *bw_share) | 
 | 3608 | { | 
 | 3609 | 	struct i40e_aqc_configure_vsi_tc_bw_data bw_data; | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3610 | 	i40e_status aq_ret; | 
 | 3611 | 	int i; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3612 |  | 
 | 3613 | 	bw_data.tc_valid_bits = enabled_tc; | 
 | 3614 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | 
 | 3615 | 		bw_data.tc_bw_credits[i] = bw_share[i]; | 
 | 3616 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3617 | 	aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data, | 
 | 3618 | 					  NULL); | 
 | 3619 | 	if (aq_ret) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3620 | 		dev_info(&vsi->back->pdev->dev, | 
 | 3621 | 			 "%s: AQ command Config VSI BW allocation per TC failed = %d\n", | 
 | 3622 | 			 __func__, vsi->back->hw.aq.asq_last_status); | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3623 | 		return -EINVAL; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3624 | 	} | 
 | 3625 |  | 
 | 3626 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) | 
 | 3627 | 		vsi->info.qs_handle[i] = bw_data.qs_handles[i]; | 
 | 3628 |  | 
| Jesse Brandeburg | dcae29b | 2013-09-13 08:23:20 +0000 | [diff] [blame] | 3629 | 	return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3630 | } | 
 | 3631 |  | 
 | 3632 | /** | 
 | 3633 |  * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration | 
 | 3634 |  * @vsi: the VSI being configured | 
 | 3635 |  * @enabled_tc: TC map to be enabled | 
 | 3636 |  * | 
 | 3637 |  **/ | 
 | 3638 | static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc) | 
 | 3639 | { | 
 | 3640 | 	struct net_device *netdev = vsi->netdev; | 
 | 3641 | 	struct i40e_pf *pf = vsi->back; | 
 | 3642 | 	struct i40e_hw *hw = &pf->hw; | 
 | 3643 | 	u8 netdev_tc = 0; | 
 | 3644 | 	int i; | 
 | 3645 | 	struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config; | 
 | 3646 |  | 
 | 3647 | 	if (!netdev) | 
 | 3648 | 		return; | 
 | 3649 |  | 
 | 3650 | 	if (!enabled_tc) { | 
 | 3651 | 		netdev_reset_tc(netdev); | 
 | 3652 | 		return; | 
 | 3653 | 	} | 
 | 3654 |  | 
 | 3655 | 	/* Set up actual enabled TCs on the VSI */ | 
 | 3656 | 	if (netdev_set_num_tc(netdev, vsi->tc_config.numtc)) | 
 | 3657 | 		return; | 
 | 3658 |  | 
 | 3659 | 	/* set per TC queues for the VSI */ | 
 | 3660 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 3661 | 		/* Only set TC queues for enabled tcs | 
 | 3662 | 		 * | 
 | 3663 | 		 * e.g. For a VSI that has TC0 and TC3 enabled the | 
 | 3664 | 		 * enabled_tc bitmap would be 0x00001001; the driver | 
 | 3665 | 		 * will set the numtc for netdev as 2 that will be | 
 | 3666 | 		 * referenced by the netdev layer as TC 0 and 1. | 
 | 3667 | 		 */ | 
 | 3668 | 		if (vsi->tc_config.enabled_tc & (1 << i)) | 
 | 3669 | 			netdev_set_tc_queue(netdev, | 
 | 3670 | 					vsi->tc_config.tc_info[i].netdev_tc, | 
 | 3671 | 					vsi->tc_config.tc_info[i].qcount, | 
 | 3672 | 					vsi->tc_config.tc_info[i].qoffset); | 
 | 3673 | 	} | 
 | 3674 |  | 
 | 3675 | 	/* Assign UP2TC map for the VSI */ | 
 | 3676 | 	for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | 
 | 3677 | 		/* Get the actual TC# for the UP */ | 
 | 3678 | 		u8 ets_tc = dcbcfg->etscfg.prioritytable[i]; | 
 | 3679 | 		/* Get the mapped netdev TC# for the UP */ | 
 | 3680 | 		netdev_tc =  vsi->tc_config.tc_info[ets_tc].netdev_tc; | 
 | 3681 | 		netdev_set_prio_tc_map(netdev, i, netdev_tc); | 
 | 3682 | 	} | 
 | 3683 | } | 
 | 3684 |  | 
 | 3685 | /** | 
 | 3686 |  * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map | 
 | 3687 |  * @vsi: the VSI being configured | 
 | 3688 |  * @ctxt: the ctxt buffer returned from AQ VSI update param command | 
 | 3689 |  **/ | 
 | 3690 | static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi, | 
 | 3691 | 				      struct i40e_vsi_context *ctxt) | 
 | 3692 | { | 
 | 3693 | 	/* copy just the sections touched not the entire info | 
 | 3694 | 	 * since not all sections are valid as returned by | 
 | 3695 | 	 * update vsi params | 
 | 3696 | 	 */ | 
 | 3697 | 	vsi->info.mapping_flags = ctxt->info.mapping_flags; | 
 | 3698 | 	memcpy(&vsi->info.queue_mapping, | 
 | 3699 | 	       &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping)); | 
 | 3700 | 	memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping, | 
 | 3701 | 	       sizeof(vsi->info.tc_mapping)); | 
 | 3702 | } | 
 | 3703 |  | 
 | 3704 | /** | 
 | 3705 |  * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map | 
 | 3706 |  * @vsi: VSI to be configured | 
 | 3707 |  * @enabled_tc: TC bitmap | 
 | 3708 |  * | 
 | 3709 |  * This configures a particular VSI for TCs that are mapped to the | 
 | 3710 |  * given TC bitmap. It uses default bandwidth share for TCs across | 
 | 3711 |  * VSIs to configure TC for a particular VSI. | 
 | 3712 |  * | 
 | 3713 |  * NOTE: | 
 | 3714 |  * It is expected that the VSI queues have been quisced before calling | 
 | 3715 |  * this function. | 
 | 3716 |  **/ | 
 | 3717 | static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc) | 
 | 3718 | { | 
 | 3719 | 	u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0}; | 
 | 3720 | 	struct i40e_vsi_context ctxt; | 
 | 3721 | 	int ret = 0; | 
 | 3722 | 	int i; | 
 | 3723 |  | 
 | 3724 | 	/* Check if enabled_tc is same as existing or new TCs */ | 
 | 3725 | 	if (vsi->tc_config.enabled_tc == enabled_tc) | 
 | 3726 | 		return ret; | 
 | 3727 |  | 
 | 3728 | 	/* Enable ETS TCs with equal BW Share for now across all VSIs */ | 
 | 3729 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 3730 | 		if (enabled_tc & (1 << i)) | 
 | 3731 | 			bw_share[i] = 1; | 
 | 3732 | 	} | 
 | 3733 |  | 
 | 3734 | 	ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share); | 
 | 3735 | 	if (ret) { | 
 | 3736 | 		dev_info(&vsi->back->pdev->dev, | 
 | 3737 | 			 "Failed configuring TC map %d for VSI %d\n", | 
 | 3738 | 			 enabled_tc, vsi->seid); | 
 | 3739 | 		goto out; | 
 | 3740 | 	} | 
 | 3741 |  | 
 | 3742 | 	/* Update Queue Pairs Mapping for currently enabled UPs */ | 
 | 3743 | 	ctxt.seid = vsi->seid; | 
 | 3744 | 	ctxt.pf_num = vsi->back->hw.pf_id; | 
 | 3745 | 	ctxt.vf_num = 0; | 
 | 3746 | 	ctxt.uplink_seid = vsi->uplink_seid; | 
 | 3747 | 	memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info)); | 
 | 3748 | 	i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); | 
 | 3749 |  | 
 | 3750 | 	/* Update the VSI after updating the VSI queue-mapping information */ | 
 | 3751 | 	ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL); | 
 | 3752 | 	if (ret) { | 
 | 3753 | 		dev_info(&vsi->back->pdev->dev, | 
 | 3754 | 			 "update vsi failed, aq_err=%d\n", | 
 | 3755 | 			 vsi->back->hw.aq.asq_last_status); | 
 | 3756 | 		goto out; | 
 | 3757 | 	} | 
 | 3758 | 	/* update the local VSI info with updated queue map */ | 
 | 3759 | 	i40e_vsi_update_queue_map(vsi, &ctxt); | 
 | 3760 | 	vsi->info.valid_sections = 0; | 
 | 3761 |  | 
 | 3762 | 	/* Update current VSI BW information */ | 
 | 3763 | 	ret = i40e_vsi_get_bw_info(vsi); | 
 | 3764 | 	if (ret) { | 
 | 3765 | 		dev_info(&vsi->back->pdev->dev, | 
 | 3766 | 			 "Failed updating vsi bw info, aq_err=%d\n", | 
 | 3767 | 			 vsi->back->hw.aq.asq_last_status); | 
 | 3768 | 		goto out; | 
 | 3769 | 	} | 
 | 3770 |  | 
 | 3771 | 	/* Update the netdev TC setup */ | 
 | 3772 | 	i40e_vsi_config_netdev_tc(vsi, enabled_tc); | 
 | 3773 | out: | 
 | 3774 | 	return ret; | 
 | 3775 | } | 
 | 3776 |  | 
 | 3777 | /** | 
 | 3778 |  * i40e_up_complete - Finish the last steps of bringing up a connection | 
 | 3779 |  * @vsi: the VSI being configured | 
 | 3780 |  **/ | 
 | 3781 | static int i40e_up_complete(struct i40e_vsi *vsi) | 
 | 3782 | { | 
 | 3783 | 	struct i40e_pf *pf = vsi->back; | 
 | 3784 | 	int err; | 
 | 3785 |  | 
 | 3786 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) | 
 | 3787 | 		i40e_vsi_configure_msix(vsi); | 
 | 3788 | 	else | 
 | 3789 | 		i40e_configure_msi_and_legacy(vsi); | 
 | 3790 |  | 
 | 3791 | 	/* start rings */ | 
 | 3792 | 	err = i40e_vsi_control_rings(vsi, true); | 
 | 3793 | 	if (err) | 
 | 3794 | 		return err; | 
 | 3795 |  | 
 | 3796 | 	clear_bit(__I40E_DOWN, &vsi->state); | 
 | 3797 | 	i40e_napi_enable_all(vsi); | 
 | 3798 | 	i40e_vsi_enable_irq(vsi); | 
 | 3799 |  | 
 | 3800 | 	if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) && | 
 | 3801 | 	    (vsi->netdev)) { | 
| Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 3802 | 		netdev_info(vsi->netdev, "NIC Link is Up\n"); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3803 | 		netif_tx_start_all_queues(vsi->netdev); | 
 | 3804 | 		netif_carrier_on(vsi->netdev); | 
| Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 3805 | 	} else if (vsi->netdev) { | 
 | 3806 | 		netdev_info(vsi->netdev, "NIC Link is Down\n"); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3807 | 	} | 
 | 3808 | 	i40e_service_event_schedule(pf); | 
 | 3809 |  | 
 | 3810 | 	return 0; | 
 | 3811 | } | 
 | 3812 |  | 
 | 3813 | /** | 
 | 3814 |  * i40e_vsi_reinit_locked - Reset the VSI | 
 | 3815 |  * @vsi: the VSI being configured | 
 | 3816 |  * | 
 | 3817 |  * Rebuild the ring structs after some configuration | 
 | 3818 |  * has changed, e.g. MTU size. | 
 | 3819 |  **/ | 
 | 3820 | static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi) | 
 | 3821 | { | 
 | 3822 | 	struct i40e_pf *pf = vsi->back; | 
 | 3823 |  | 
 | 3824 | 	WARN_ON(in_interrupt()); | 
 | 3825 | 	while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) | 
 | 3826 | 		usleep_range(1000, 2000); | 
 | 3827 | 	i40e_down(vsi); | 
 | 3828 |  | 
 | 3829 | 	/* Give a VF some time to respond to the reset.  The | 
 | 3830 | 	 * two second wait is based upon the watchdog cycle in | 
 | 3831 | 	 * the VF driver. | 
 | 3832 | 	 */ | 
 | 3833 | 	if (vsi->type == I40E_VSI_SRIOV) | 
 | 3834 | 		msleep(2000); | 
 | 3835 | 	i40e_up(vsi); | 
 | 3836 | 	clear_bit(__I40E_CONFIG_BUSY, &pf->state); | 
 | 3837 | } | 
 | 3838 |  | 
 | 3839 | /** | 
 | 3840 |  * i40e_up - Bring the connection back up after being down | 
 | 3841 |  * @vsi: the VSI being configured | 
 | 3842 |  **/ | 
 | 3843 | int i40e_up(struct i40e_vsi *vsi) | 
 | 3844 | { | 
 | 3845 | 	int err; | 
 | 3846 |  | 
 | 3847 | 	err = i40e_vsi_configure(vsi); | 
 | 3848 | 	if (!err) | 
 | 3849 | 		err = i40e_up_complete(vsi); | 
 | 3850 |  | 
 | 3851 | 	return err; | 
 | 3852 | } | 
 | 3853 |  | 
 | 3854 | /** | 
 | 3855 |  * i40e_down - Shutdown the connection processing | 
 | 3856 |  * @vsi: the VSI being stopped | 
 | 3857 |  **/ | 
 | 3858 | void i40e_down(struct i40e_vsi *vsi) | 
 | 3859 | { | 
 | 3860 | 	int i; | 
 | 3861 |  | 
 | 3862 | 	/* It is assumed that the caller of this function | 
 | 3863 | 	 * sets the vsi->state __I40E_DOWN bit. | 
 | 3864 | 	 */ | 
 | 3865 | 	if (vsi->netdev) { | 
 | 3866 | 		netif_carrier_off(vsi->netdev); | 
 | 3867 | 		netif_tx_disable(vsi->netdev); | 
 | 3868 | 	} | 
 | 3869 | 	i40e_vsi_disable_irq(vsi); | 
 | 3870 | 	i40e_vsi_control_rings(vsi, false); | 
 | 3871 | 	i40e_napi_disable_all(vsi); | 
 | 3872 |  | 
 | 3873 | 	for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 3874 | 		i40e_clean_tx_ring(vsi->tx_rings[i]); | 
 | 3875 | 		i40e_clean_rx_ring(vsi->rx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3876 | 	} | 
 | 3877 | } | 
 | 3878 |  | 
 | 3879 | /** | 
 | 3880 |  * i40e_setup_tc - configure multiple traffic classes | 
 | 3881 |  * @netdev: net device to configure | 
 | 3882 |  * @tc: number of traffic classes to enable | 
 | 3883 |  **/ | 
 | 3884 | static int i40e_setup_tc(struct net_device *netdev, u8 tc) | 
 | 3885 | { | 
 | 3886 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 3887 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 3888 | 	struct i40e_pf *pf = vsi->back; | 
 | 3889 | 	u8 enabled_tc = 0; | 
 | 3890 | 	int ret = -EINVAL; | 
 | 3891 | 	int i; | 
 | 3892 |  | 
 | 3893 | 	/* Check if DCB enabled to continue */ | 
 | 3894 | 	if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 3895 | 		netdev_info(netdev, "DCB is not enabled for adapter\n"); | 
 | 3896 | 		goto exit; | 
 | 3897 | 	} | 
 | 3898 |  | 
 | 3899 | 	/* Check if MFP enabled */ | 
 | 3900 | 	if (pf->flags & I40E_FLAG_MFP_ENABLED) { | 
 | 3901 | 		netdev_info(netdev, "Configuring TC not supported in MFP mode\n"); | 
 | 3902 | 		goto exit; | 
 | 3903 | 	} | 
 | 3904 |  | 
 | 3905 | 	/* Check whether tc count is within enabled limit */ | 
 | 3906 | 	if (tc > i40e_pf_get_num_tc(pf)) { | 
 | 3907 | 		netdev_info(netdev, "TC count greater than enabled on link for adapter\n"); | 
 | 3908 | 		goto exit; | 
 | 3909 | 	} | 
 | 3910 |  | 
 | 3911 | 	/* Generate TC map for number of tc requested */ | 
 | 3912 | 	for (i = 0; i < tc; i++) | 
 | 3913 | 		enabled_tc |= (1 << i); | 
 | 3914 |  | 
 | 3915 | 	/* Requesting same TC configuration as already enabled */ | 
 | 3916 | 	if (enabled_tc == vsi->tc_config.enabled_tc) | 
 | 3917 | 		return 0; | 
 | 3918 |  | 
 | 3919 | 	/* Quiesce VSI queues */ | 
 | 3920 | 	i40e_quiesce_vsi(vsi); | 
 | 3921 |  | 
 | 3922 | 	/* Configure VSI for enabled TCs */ | 
 | 3923 | 	ret = i40e_vsi_config_tc(vsi, enabled_tc); | 
 | 3924 | 	if (ret) { | 
 | 3925 | 		netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n", | 
 | 3926 | 			    vsi->seid); | 
 | 3927 | 		goto exit; | 
 | 3928 | 	} | 
 | 3929 |  | 
 | 3930 | 	/* Unquiesce VSI */ | 
 | 3931 | 	i40e_unquiesce_vsi(vsi); | 
 | 3932 |  | 
 | 3933 | exit: | 
 | 3934 | 	return ret; | 
 | 3935 | } | 
 | 3936 |  | 
 | 3937 | /** | 
 | 3938 |  * i40e_open - Called when a network interface is made active | 
 | 3939 |  * @netdev: network interface device structure | 
 | 3940 |  * | 
 | 3941 |  * The open entry point is called when a network interface is made | 
 | 3942 |  * active by the system (IFF_UP).  At this point all resources needed | 
 | 3943 |  * for transmit and receive operations are allocated, the interrupt | 
 | 3944 |  * handler is registered with the OS, the netdev watchdog subtask is | 
 | 3945 |  * enabled, and the stack is notified that the interface is ready. | 
 | 3946 |  * | 
 | 3947 |  * Returns 0 on success, negative value on failure | 
 | 3948 |  **/ | 
 | 3949 | static int i40e_open(struct net_device *netdev) | 
 | 3950 | { | 
 | 3951 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 3952 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 3953 | 	struct i40e_pf *pf = vsi->back; | 
 | 3954 | 	char int_name[IFNAMSIZ]; | 
 | 3955 | 	int err; | 
 | 3956 |  | 
 | 3957 | 	/* disallow open during test */ | 
 | 3958 | 	if (test_bit(__I40E_TESTING, &pf->state)) | 
 | 3959 | 		return -EBUSY; | 
 | 3960 |  | 
 | 3961 | 	netif_carrier_off(netdev); | 
 | 3962 |  | 
 | 3963 | 	/* allocate descriptors */ | 
 | 3964 | 	err = i40e_vsi_setup_tx_resources(vsi); | 
 | 3965 | 	if (err) | 
 | 3966 | 		goto err_setup_tx; | 
 | 3967 | 	err = i40e_vsi_setup_rx_resources(vsi); | 
 | 3968 | 	if (err) | 
 | 3969 | 		goto err_setup_rx; | 
 | 3970 |  | 
 | 3971 | 	err = i40e_vsi_configure(vsi); | 
 | 3972 | 	if (err) | 
 | 3973 | 		goto err_setup_rx; | 
 | 3974 |  | 
 | 3975 | 	snprintf(int_name, sizeof(int_name) - 1, "%s-%s", | 
 | 3976 | 		 dev_driver_string(&pf->pdev->dev), netdev->name); | 
 | 3977 | 	err = i40e_vsi_request_irq(vsi, int_name); | 
 | 3978 | 	if (err) | 
 | 3979 | 		goto err_setup_rx; | 
 | 3980 |  | 
| Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 3981 | 	/* Notify the stack of the actual queue counts. */ | 
| Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 3982 | 	err = netif_set_real_num_tx_queues(netdev, vsi->num_queue_pairs); | 
| Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 3983 | 	if (err) | 
 | 3984 | 		goto err_set_queues; | 
 | 3985 |  | 
| Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 3986 | 	err = netif_set_real_num_rx_queues(netdev, vsi->num_queue_pairs); | 
| Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 3987 | 	if (err) | 
 | 3988 | 		goto err_set_queues; | 
 | 3989 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3990 | 	err = i40e_up_complete(vsi); | 
 | 3991 | 	if (err) | 
 | 3992 | 		goto err_up_complete; | 
 | 3993 |  | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 3994 | #ifdef CONFIG_I40E_VXLAN | 
 | 3995 | 	vxlan_get_rx_port(netdev); | 
 | 3996 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 3997 |  | 
 | 3998 | 	return 0; | 
 | 3999 |  | 
 | 4000 | err_up_complete: | 
 | 4001 | 	i40e_down(vsi); | 
| Anjali Singhai Jain | 25946dd | 2013-11-26 10:49:14 +0000 | [diff] [blame] | 4002 | err_set_queues: | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4003 | 	i40e_vsi_free_irq(vsi); | 
 | 4004 | err_setup_rx: | 
 | 4005 | 	i40e_vsi_free_rx_resources(vsi); | 
 | 4006 | err_setup_tx: | 
 | 4007 | 	i40e_vsi_free_tx_resources(vsi); | 
 | 4008 | 	if (vsi == pf->vsi[pf->lan_vsi]) | 
 | 4009 | 		i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); | 
 | 4010 |  | 
 | 4011 | 	return err; | 
 | 4012 | } | 
 | 4013 |  | 
 | 4014 | /** | 
 | 4015 |  * i40e_close - Disables a network interface | 
 | 4016 |  * @netdev: network interface device structure | 
 | 4017 |  * | 
 | 4018 |  * The close entry point is called when an interface is de-activated | 
 | 4019 |  * by the OS.  The hardware is still under the driver's control, but | 
 | 4020 |  * this netdev interface is disabled. | 
 | 4021 |  * | 
 | 4022 |  * Returns 0, this is not allowed to fail | 
 | 4023 |  **/ | 
 | 4024 | static int i40e_close(struct net_device *netdev) | 
 | 4025 | { | 
 | 4026 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 4027 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 4028 |  | 
 | 4029 | 	if (test_and_set_bit(__I40E_DOWN, &vsi->state)) | 
 | 4030 | 		return 0; | 
 | 4031 |  | 
 | 4032 | 	i40e_down(vsi); | 
 | 4033 | 	i40e_vsi_free_irq(vsi); | 
 | 4034 |  | 
 | 4035 | 	i40e_vsi_free_tx_resources(vsi); | 
 | 4036 | 	i40e_vsi_free_rx_resources(vsi); | 
 | 4037 |  | 
 | 4038 | 	return 0; | 
 | 4039 | } | 
 | 4040 |  | 
 | 4041 | /** | 
 | 4042 |  * i40e_do_reset - Start a PF or Core Reset sequence | 
 | 4043 |  * @pf: board private structure | 
 | 4044 |  * @reset_flags: which reset is requested | 
 | 4045 |  * | 
 | 4046 |  * The essential difference in resets is that the PF Reset | 
 | 4047 |  * doesn't clear the packet buffers, doesn't reset the PE | 
 | 4048 |  * firmware, and doesn't bother the other PFs on the chip. | 
 | 4049 |  **/ | 
 | 4050 | void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags) | 
 | 4051 | { | 
 | 4052 | 	u32 val; | 
 | 4053 |  | 
 | 4054 | 	WARN_ON(in_interrupt()); | 
 | 4055 |  | 
 | 4056 | 	/* do the biggest reset indicated */ | 
 | 4057 | 	if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) { | 
 | 4058 |  | 
 | 4059 | 		/* Request a Global Reset | 
 | 4060 | 		 * | 
 | 4061 | 		 * This will start the chip's countdown to the actual full | 
 | 4062 | 		 * chip reset event, and a warning interrupt to be sent | 
 | 4063 | 		 * to all PFs, including the requestor.  Our handler | 
 | 4064 | 		 * for the warning interrupt will deal with the shutdown | 
 | 4065 | 		 * and recovery of the switch setup. | 
 | 4066 | 		 */ | 
 | 4067 | 		dev_info(&pf->pdev->dev, "GlobalR requested\n"); | 
 | 4068 | 		val = rd32(&pf->hw, I40E_GLGEN_RTRIG); | 
 | 4069 | 		val |= I40E_GLGEN_RTRIG_GLOBR_MASK; | 
 | 4070 | 		wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | 
 | 4071 |  | 
 | 4072 | 	} else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) { | 
 | 4073 |  | 
 | 4074 | 		/* Request a Core Reset | 
 | 4075 | 		 * | 
 | 4076 | 		 * Same as Global Reset, except does *not* include the MAC/PHY | 
 | 4077 | 		 */ | 
 | 4078 | 		dev_info(&pf->pdev->dev, "CoreR requested\n"); | 
 | 4079 | 		val = rd32(&pf->hw, I40E_GLGEN_RTRIG); | 
 | 4080 | 		val |= I40E_GLGEN_RTRIG_CORER_MASK; | 
 | 4081 | 		wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | 
 | 4082 | 		i40e_flush(&pf->hw); | 
 | 4083 |  | 
| Shannon Nelson | 7823fe3 | 2013-11-16 10:00:45 +0000 | [diff] [blame] | 4084 | 	} else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) { | 
 | 4085 |  | 
 | 4086 | 		/* Request a Firmware Reset | 
 | 4087 | 		 * | 
 | 4088 | 		 * Same as Global reset, plus restarting the | 
 | 4089 | 		 * embedded firmware engine. | 
 | 4090 | 		 */ | 
 | 4091 | 		/* enable EMP Reset */ | 
 | 4092 | 		val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP); | 
 | 4093 | 		val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK; | 
 | 4094 | 		wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val); | 
 | 4095 |  | 
 | 4096 | 		/* force the reset */ | 
 | 4097 | 		val = rd32(&pf->hw, I40E_GLGEN_RTRIG); | 
 | 4098 | 		val |= I40E_GLGEN_RTRIG_EMPFWR_MASK; | 
 | 4099 | 		wr32(&pf->hw, I40E_GLGEN_RTRIG, val); | 
 | 4100 | 		i40e_flush(&pf->hw); | 
 | 4101 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4102 | 	} else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) { | 
 | 4103 |  | 
 | 4104 | 		/* Request a PF Reset | 
 | 4105 | 		 * | 
 | 4106 | 		 * Resets only the PF-specific registers | 
 | 4107 | 		 * | 
 | 4108 | 		 * This goes directly to the tear-down and rebuild of | 
 | 4109 | 		 * the switch, since we need to do all the recovery as | 
 | 4110 | 		 * for the Core Reset. | 
 | 4111 | 		 */ | 
 | 4112 | 		dev_info(&pf->pdev->dev, "PFR requested\n"); | 
 | 4113 | 		i40e_handle_reset_warning(pf); | 
 | 4114 |  | 
 | 4115 | 	} else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) { | 
 | 4116 | 		int v; | 
 | 4117 |  | 
 | 4118 | 		/* Find the VSI(s) that requested a re-init */ | 
 | 4119 | 		dev_info(&pf->pdev->dev, | 
 | 4120 | 			 "VSI reinit requested\n"); | 
 | 4121 | 		for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 4122 | 			struct i40e_vsi *vsi = pf->vsi[v]; | 
 | 4123 | 			if (vsi != NULL && | 
 | 4124 | 			    test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) { | 
 | 4125 | 				i40e_vsi_reinit_locked(pf->vsi[v]); | 
 | 4126 | 				clear_bit(__I40E_REINIT_REQUESTED, &vsi->state); | 
 | 4127 | 			} | 
 | 4128 | 		} | 
 | 4129 |  | 
 | 4130 | 		/* no further action needed, so return now */ | 
 | 4131 | 		return; | 
 | 4132 | 	} else { | 
 | 4133 | 		dev_info(&pf->pdev->dev, | 
 | 4134 | 			 "bad reset request 0x%08x\n", reset_flags); | 
 | 4135 | 		return; | 
 | 4136 | 	} | 
 | 4137 | } | 
 | 4138 |  | 
 | 4139 | /** | 
| Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 4140 |  * i40e_do_reset_safe - Protected reset path for userland calls. | 
 | 4141 |  * @pf: board private structure | 
 | 4142 |  * @reset_flags: which reset is requested | 
 | 4143 |  * | 
 | 4144 |  **/ | 
 | 4145 | void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags) | 
 | 4146 | { | 
 | 4147 | 	rtnl_lock(); | 
 | 4148 | 	i40e_do_reset(pf, reset_flags); | 
 | 4149 | 	rtnl_unlock(); | 
 | 4150 | } | 
 | 4151 |  | 
 | 4152 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4153 |  * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event | 
 | 4154 |  * @pf: board private structure | 
 | 4155 |  * @e: event info posted on ARQ | 
 | 4156 |  * | 
 | 4157 |  * Handler for LAN Queue Overflow Event generated by the firmware for PF | 
 | 4158 |  * and VF queues | 
 | 4159 |  **/ | 
 | 4160 | static void i40e_handle_lan_overflow_event(struct i40e_pf *pf, | 
 | 4161 | 					   struct i40e_arq_event_info *e) | 
 | 4162 | { | 
 | 4163 | 	struct i40e_aqc_lan_overflow *data = | 
 | 4164 | 		(struct i40e_aqc_lan_overflow *)&e->desc.params.raw; | 
 | 4165 | 	u32 queue = le32_to_cpu(data->prtdcb_rupto); | 
 | 4166 | 	u32 qtx_ctl = le32_to_cpu(data->otx_ctl); | 
 | 4167 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4168 | 	struct i40e_vf *vf; | 
 | 4169 | 	u16 vf_id; | 
 | 4170 |  | 
 | 4171 | 	dev_info(&pf->pdev->dev, "%s: Rx Queue Number = %d QTX_CTL=0x%08x\n", | 
 | 4172 | 		 __func__, queue, qtx_ctl); | 
 | 4173 |  | 
 | 4174 | 	/* Queue belongs to VF, find the VF and issue VF reset */ | 
 | 4175 | 	if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK) | 
 | 4176 | 	    >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) { | 
 | 4177 | 		vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK) | 
 | 4178 | 			 >> I40E_QTX_CTL_VFVM_INDX_SHIFT); | 
 | 4179 | 		vf_id -= hw->func_caps.vf_base_id; | 
 | 4180 | 		vf = &pf->vf[vf_id]; | 
 | 4181 | 		i40e_vc_notify_vf_reset(vf); | 
 | 4182 | 		/* Allow VF to process pending reset notification */ | 
 | 4183 | 		msleep(20); | 
 | 4184 | 		i40e_reset_vf(vf, false); | 
 | 4185 | 	} | 
 | 4186 | } | 
 | 4187 |  | 
 | 4188 | /** | 
 | 4189 |  * i40e_service_event_complete - Finish up the service event | 
 | 4190 |  * @pf: board private structure | 
 | 4191 |  **/ | 
 | 4192 | static void i40e_service_event_complete(struct i40e_pf *pf) | 
 | 4193 | { | 
 | 4194 | 	BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state)); | 
 | 4195 |  | 
 | 4196 | 	/* flush memory to make sure state is correct before next watchog */ | 
 | 4197 | 	smp_mb__before_clear_bit(); | 
 | 4198 | 	clear_bit(__I40E_SERVICE_SCHED, &pf->state); | 
 | 4199 | } | 
 | 4200 |  | 
 | 4201 | /** | 
 | 4202 |  * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table | 
 | 4203 |  * @pf: board private structure | 
 | 4204 |  **/ | 
 | 4205 | static void i40e_fdir_reinit_subtask(struct i40e_pf *pf) | 
 | 4206 | { | 
 | 4207 | 	if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT)) | 
 | 4208 | 		return; | 
 | 4209 |  | 
 | 4210 | 	pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT; | 
 | 4211 |  | 
 | 4212 | 	/* if interface is down do nothing */ | 
 | 4213 | 	if (test_bit(__I40E_DOWN, &pf->state)) | 
 | 4214 | 		return; | 
 | 4215 | } | 
 | 4216 |  | 
 | 4217 | /** | 
 | 4218 |  * i40e_vsi_link_event - notify VSI of a link event | 
 | 4219 |  * @vsi: vsi to be notified | 
 | 4220 |  * @link_up: link up or down | 
 | 4221 |  **/ | 
 | 4222 | static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up) | 
 | 4223 | { | 
 | 4224 | 	if (!vsi) | 
 | 4225 | 		return; | 
 | 4226 |  | 
 | 4227 | 	switch (vsi->type) { | 
 | 4228 | 	case I40E_VSI_MAIN: | 
 | 4229 | 		if (!vsi->netdev || !vsi->netdev_registered) | 
 | 4230 | 			break; | 
 | 4231 |  | 
 | 4232 | 		if (link_up) { | 
 | 4233 | 			netif_carrier_on(vsi->netdev); | 
 | 4234 | 			netif_tx_wake_all_queues(vsi->netdev); | 
 | 4235 | 		} else { | 
 | 4236 | 			netif_carrier_off(vsi->netdev); | 
 | 4237 | 			netif_tx_stop_all_queues(vsi->netdev); | 
 | 4238 | 		} | 
 | 4239 | 		break; | 
 | 4240 |  | 
 | 4241 | 	case I40E_VSI_SRIOV: | 
 | 4242 | 		break; | 
 | 4243 |  | 
 | 4244 | 	case I40E_VSI_VMDQ2: | 
 | 4245 | 	case I40E_VSI_CTRL: | 
 | 4246 | 	case I40E_VSI_MIRROR: | 
 | 4247 | 	default: | 
 | 4248 | 		/* there is no notification for other VSIs */ | 
 | 4249 | 		break; | 
 | 4250 | 	} | 
 | 4251 | } | 
 | 4252 |  | 
 | 4253 | /** | 
 | 4254 |  * i40e_veb_link_event - notify elements on the veb of a link event | 
 | 4255 |  * @veb: veb to be notified | 
 | 4256 |  * @link_up: link up or down | 
 | 4257 |  **/ | 
 | 4258 | static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up) | 
 | 4259 | { | 
 | 4260 | 	struct i40e_pf *pf; | 
 | 4261 | 	int i; | 
 | 4262 |  | 
 | 4263 | 	if (!veb || !veb->pf) | 
 | 4264 | 		return; | 
 | 4265 | 	pf = veb->pf; | 
 | 4266 |  | 
 | 4267 | 	/* depth first... */ | 
 | 4268 | 	for (i = 0; i < I40E_MAX_VEB; i++) | 
 | 4269 | 		if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid)) | 
 | 4270 | 			i40e_veb_link_event(pf->veb[i], link_up); | 
 | 4271 |  | 
 | 4272 | 	/* ... now the local VSIs */ | 
 | 4273 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | 
 | 4274 | 		if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid)) | 
 | 4275 | 			i40e_vsi_link_event(pf->vsi[i], link_up); | 
 | 4276 | } | 
 | 4277 |  | 
 | 4278 | /** | 
 | 4279 |  * i40e_link_event - Update netif_carrier status | 
 | 4280 |  * @pf: board private structure | 
 | 4281 |  **/ | 
 | 4282 | static void i40e_link_event(struct i40e_pf *pf) | 
 | 4283 | { | 
 | 4284 | 	bool new_link, old_link; | 
 | 4285 |  | 
 | 4286 | 	new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP); | 
 | 4287 | 	old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP); | 
 | 4288 |  | 
 | 4289 | 	if (new_link == old_link) | 
 | 4290 | 		return; | 
 | 4291 |  | 
| Anjali Singhai | 6d779b4 | 2013-09-28 06:00:02 +0000 | [diff] [blame] | 4292 | 	if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state)) | 
 | 4293 | 		netdev_info(pf->vsi[pf->lan_vsi]->netdev, | 
 | 4294 | 			    "NIC Link is %s\n", (new_link ? "Up" : "Down")); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4295 |  | 
 | 4296 | 	/* Notify the base of the switch tree connected to | 
 | 4297 | 	 * the link.  Floating VEBs are not notified. | 
 | 4298 | 	 */ | 
 | 4299 | 	if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | 
 | 4300 | 		i40e_veb_link_event(pf->veb[pf->lan_veb], new_link); | 
 | 4301 | 	else | 
 | 4302 | 		i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link); | 
 | 4303 |  | 
 | 4304 | 	if (pf->vf) | 
 | 4305 | 		i40e_vc_notify_link_state(pf); | 
 | 4306 | } | 
 | 4307 |  | 
 | 4308 | /** | 
 | 4309 |  * i40e_check_hang_subtask - Check for hung queues and dropped interrupts | 
 | 4310 |  * @pf: board private structure | 
 | 4311 |  * | 
 | 4312 |  * Set the per-queue flags to request a check for stuck queues in the irq | 
 | 4313 |  * clean functions, then force interrupts to be sure the irq clean is called. | 
 | 4314 |  **/ | 
 | 4315 | static void i40e_check_hang_subtask(struct i40e_pf *pf) | 
 | 4316 | { | 
 | 4317 | 	int i, v; | 
 | 4318 |  | 
 | 4319 | 	/* If we're down or resetting, just bail */ | 
 | 4320 | 	if (test_bit(__I40E_CONFIG_BUSY, &pf->state)) | 
 | 4321 | 		return; | 
 | 4322 |  | 
 | 4323 | 	/* for each VSI/netdev | 
 | 4324 | 	 *     for each Tx queue | 
 | 4325 | 	 *         set the check flag | 
 | 4326 | 	 *     for each q_vector | 
 | 4327 | 	 *         force an interrupt | 
 | 4328 | 	 */ | 
 | 4329 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 4330 | 		struct i40e_vsi *vsi = pf->vsi[v]; | 
 | 4331 | 		int armed = 0; | 
 | 4332 |  | 
 | 4333 | 		if (!pf->vsi[v] || | 
 | 4334 | 		    test_bit(__I40E_DOWN, &vsi->state) || | 
 | 4335 | 		    (vsi->netdev && !netif_carrier_ok(vsi->netdev))) | 
 | 4336 | 			continue; | 
 | 4337 |  | 
 | 4338 | 		for (i = 0; i < vsi->num_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4339 | 			set_check_for_tx_hang(vsi->tx_rings[i]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4340 | 			if (test_bit(__I40E_HANG_CHECK_ARMED, | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 4341 | 				     &vsi->tx_rings[i]->state)) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4342 | 				armed++; | 
 | 4343 | 		} | 
 | 4344 |  | 
 | 4345 | 		if (armed) { | 
 | 4346 | 			if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) { | 
 | 4347 | 				wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0, | 
 | 4348 | 				     (I40E_PFINT_DYN_CTL0_INTENA_MASK | | 
 | 4349 | 				      I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); | 
 | 4350 | 			} else { | 
 | 4351 | 				u16 vec = vsi->base_vector - 1; | 
 | 4352 | 				u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK | | 
 | 4353 | 					   I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK); | 
 | 4354 | 				for (i = 0; i < vsi->num_q_vectors; i++, vec++) | 
 | 4355 | 					wr32(&vsi->back->hw, | 
 | 4356 | 					     I40E_PFINT_DYN_CTLN(vec), val); | 
 | 4357 | 			} | 
 | 4358 | 			i40e_flush(&vsi->back->hw); | 
 | 4359 | 		} | 
 | 4360 | 	} | 
 | 4361 | } | 
 | 4362 |  | 
 | 4363 | /** | 
 | 4364 |  * i40e_watchdog_subtask - Check and bring link up | 
 | 4365 |  * @pf: board private structure | 
 | 4366 |  **/ | 
 | 4367 | static void i40e_watchdog_subtask(struct i40e_pf *pf) | 
 | 4368 | { | 
 | 4369 | 	int i; | 
 | 4370 |  | 
 | 4371 | 	/* if interface is down do nothing */ | 
 | 4372 | 	if (test_bit(__I40E_DOWN, &pf->state) || | 
 | 4373 | 	    test_bit(__I40E_CONFIG_BUSY, &pf->state)) | 
 | 4374 | 		return; | 
 | 4375 |  | 
 | 4376 | 	/* Update the stats for active netdevs so the network stack | 
 | 4377 | 	 * can look at updated numbers whenever it cares to | 
 | 4378 | 	 */ | 
 | 4379 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | 
 | 4380 | 		if (pf->vsi[i] && pf->vsi[i]->netdev) | 
 | 4381 | 			i40e_update_stats(pf->vsi[i]); | 
 | 4382 |  | 
 | 4383 | 	/* Update the stats for the active switching components */ | 
 | 4384 | 	for (i = 0; i < I40E_MAX_VEB; i++) | 
 | 4385 | 		if (pf->veb[i]) | 
 | 4386 | 			i40e_update_veb_stats(pf->veb[i]); | 
 | 4387 | } | 
 | 4388 |  | 
 | 4389 | /** | 
 | 4390 |  * i40e_reset_subtask - Set up for resetting the device and driver | 
 | 4391 |  * @pf: board private structure | 
 | 4392 |  **/ | 
 | 4393 | static void i40e_reset_subtask(struct i40e_pf *pf) | 
 | 4394 | { | 
 | 4395 | 	u32 reset_flags = 0; | 
 | 4396 |  | 
| Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 4397 | 	rtnl_lock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4398 | 	if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) { | 
 | 4399 | 		reset_flags |= (1 << __I40E_REINIT_REQUESTED); | 
 | 4400 | 		clear_bit(__I40E_REINIT_REQUESTED, &pf->state); | 
 | 4401 | 	} | 
 | 4402 | 	if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) { | 
 | 4403 | 		reset_flags |= (1 << __I40E_PF_RESET_REQUESTED); | 
 | 4404 | 		clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state); | 
 | 4405 | 	} | 
 | 4406 | 	if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) { | 
 | 4407 | 		reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED); | 
 | 4408 | 		clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state); | 
 | 4409 | 	} | 
 | 4410 | 	if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) { | 
 | 4411 | 		reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED); | 
 | 4412 | 		clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state); | 
 | 4413 | 	} | 
 | 4414 |  | 
 | 4415 | 	/* If there's a recovery already waiting, it takes | 
 | 4416 | 	 * precedence before starting a new reset sequence. | 
 | 4417 | 	 */ | 
 | 4418 | 	if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) { | 
 | 4419 | 		i40e_handle_reset_warning(pf); | 
| Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 4420 | 		goto unlock; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4421 | 	} | 
 | 4422 |  | 
 | 4423 | 	/* If we're already down or resetting, just bail */ | 
 | 4424 | 	if (reset_flags && | 
 | 4425 | 	    !test_bit(__I40E_DOWN, &pf->state) && | 
 | 4426 | 	    !test_bit(__I40E_CONFIG_BUSY, &pf->state)) | 
 | 4427 | 		i40e_do_reset(pf, reset_flags); | 
| Anjali Singhai Jain | 23326186 | 2013-11-26 10:49:22 +0000 | [diff] [blame] | 4428 |  | 
 | 4429 | unlock: | 
 | 4430 | 	rtnl_unlock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4431 | } | 
 | 4432 |  | 
 | 4433 | /** | 
 | 4434 |  * i40e_handle_link_event - Handle link event | 
 | 4435 |  * @pf: board private structure | 
 | 4436 |  * @e: event info posted on ARQ | 
 | 4437 |  **/ | 
 | 4438 | static void i40e_handle_link_event(struct i40e_pf *pf, | 
 | 4439 | 				   struct i40e_arq_event_info *e) | 
 | 4440 | { | 
 | 4441 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4442 | 	struct i40e_aqc_get_link_status *status = | 
 | 4443 | 		(struct i40e_aqc_get_link_status *)&e->desc.params.raw; | 
 | 4444 | 	struct i40e_link_status *hw_link_info = &hw->phy.link_info; | 
 | 4445 |  | 
 | 4446 | 	/* save off old link status information */ | 
 | 4447 | 	memcpy(&pf->hw.phy.link_info_old, hw_link_info, | 
 | 4448 | 	       sizeof(pf->hw.phy.link_info_old)); | 
 | 4449 |  | 
 | 4450 | 	/* update link status */ | 
 | 4451 | 	hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type; | 
 | 4452 | 	hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed; | 
 | 4453 | 	hw_link_info->link_info = status->link_info; | 
 | 4454 | 	hw_link_info->an_info = status->an_info; | 
 | 4455 | 	hw_link_info->ext_info = status->ext_info; | 
 | 4456 | 	hw_link_info->lse_enable = | 
 | 4457 | 		le16_to_cpu(status->command_flags) & | 
 | 4458 | 			    I40E_AQ_LSE_ENABLE; | 
 | 4459 |  | 
 | 4460 | 	/* process the event */ | 
 | 4461 | 	i40e_link_event(pf); | 
 | 4462 |  | 
 | 4463 | 	/* Do a new status request to re-enable LSE reporting | 
 | 4464 | 	 * and load new status information into the hw struct, | 
 | 4465 | 	 * then see if the status changed while processing the | 
 | 4466 | 	 * initial event. | 
 | 4467 | 	 */ | 
 | 4468 | 	i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); | 
 | 4469 | 	i40e_link_event(pf); | 
 | 4470 | } | 
 | 4471 |  | 
 | 4472 | /** | 
 | 4473 |  * i40e_clean_adminq_subtask - Clean the AdminQ rings | 
 | 4474 |  * @pf: board private structure | 
 | 4475 |  **/ | 
 | 4476 | static void i40e_clean_adminq_subtask(struct i40e_pf *pf) | 
 | 4477 | { | 
 | 4478 | 	struct i40e_arq_event_info event; | 
 | 4479 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4480 | 	u16 pending, i = 0; | 
 | 4481 | 	i40e_status ret; | 
 | 4482 | 	u16 opcode; | 
 | 4483 | 	u32 val; | 
 | 4484 |  | 
 | 4485 | 	if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)) | 
 | 4486 | 		return; | 
 | 4487 |  | 
| Mitch Williams | 3197ce2 | 2013-11-28 06:39:39 +0000 | [diff] [blame] | 4488 | 	event.msg_size = I40E_MAX_AQ_BUF_SIZE; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4489 | 	event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); | 
 | 4490 | 	if (!event.msg_buf) | 
 | 4491 | 		return; | 
 | 4492 |  | 
 | 4493 | 	do { | 
| Mitch Williams | 2f01912 | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 4494 | 		event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4495 | 		ret = i40e_clean_arq_element(hw, &event, &pending); | 
 | 4496 | 		if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) { | 
 | 4497 | 			dev_info(&pf->pdev->dev, "No ARQ event found\n"); | 
 | 4498 | 			break; | 
 | 4499 | 		} else if (ret) { | 
 | 4500 | 			dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret); | 
 | 4501 | 			break; | 
 | 4502 | 		} | 
 | 4503 |  | 
 | 4504 | 		opcode = le16_to_cpu(event.desc.opcode); | 
 | 4505 | 		switch (opcode) { | 
 | 4506 |  | 
 | 4507 | 		case i40e_aqc_opc_get_link_status: | 
 | 4508 | 			i40e_handle_link_event(pf, &event); | 
 | 4509 | 			break; | 
 | 4510 | 		case i40e_aqc_opc_send_msg_to_pf: | 
 | 4511 | 			ret = i40e_vc_process_vf_msg(pf, | 
 | 4512 | 					le16_to_cpu(event.desc.retval), | 
 | 4513 | 					le32_to_cpu(event.desc.cookie_high), | 
 | 4514 | 					le32_to_cpu(event.desc.cookie_low), | 
 | 4515 | 					event.msg_buf, | 
 | 4516 | 					event.msg_size); | 
 | 4517 | 			break; | 
 | 4518 | 		case i40e_aqc_opc_lldp_update_mib: | 
 | 4519 | 			dev_info(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n"); | 
 | 4520 | 			break; | 
 | 4521 | 		case i40e_aqc_opc_event_lan_overflow: | 
 | 4522 | 			dev_info(&pf->pdev->dev, "ARQ LAN queue overflow event received\n"); | 
 | 4523 | 			i40e_handle_lan_overflow_event(pf, &event); | 
 | 4524 | 			break; | 
 | 4525 | 		default: | 
 | 4526 | 			dev_info(&pf->pdev->dev, | 
 | 4527 | 				 "ARQ Error: Unknown event %d received\n", | 
 | 4528 | 				 event.desc.opcode); | 
 | 4529 | 			break; | 
 | 4530 | 		} | 
 | 4531 | 	} while (pending && (i++ < pf->adminq_work_limit)); | 
 | 4532 |  | 
 | 4533 | 	clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state); | 
 | 4534 | 	/* re-enable Admin queue interrupt cause */ | 
 | 4535 | 	val = rd32(hw, I40E_PFINT_ICR0_ENA); | 
 | 4536 | 	val |=  I40E_PFINT_ICR0_ENA_ADMINQ_MASK; | 
 | 4537 | 	wr32(hw, I40E_PFINT_ICR0_ENA, val); | 
 | 4538 | 	i40e_flush(hw); | 
 | 4539 |  | 
 | 4540 | 	kfree(event.msg_buf); | 
 | 4541 | } | 
 | 4542 |  | 
 | 4543 | /** | 
 | 4544 |  * i40e_reconstitute_veb - rebuild the VEB and anything connected to it | 
 | 4545 |  * @veb: pointer to the VEB instance | 
 | 4546 |  * | 
 | 4547 |  * This is a recursive function that first builds the attached VSIs then | 
 | 4548 |  * recurses in to build the next layer of VEB.  We track the connections | 
 | 4549 |  * through our own index numbers because the seid's from the HW could | 
 | 4550 |  * change across the reset. | 
 | 4551 |  **/ | 
 | 4552 | static int i40e_reconstitute_veb(struct i40e_veb *veb) | 
 | 4553 | { | 
 | 4554 | 	struct i40e_vsi *ctl_vsi = NULL; | 
 | 4555 | 	struct i40e_pf *pf = veb->pf; | 
 | 4556 | 	int v, veb_idx; | 
 | 4557 | 	int ret; | 
 | 4558 |  | 
 | 4559 | 	/* build VSI that owns this VEB, temporarily attached to base VEB */ | 
 | 4560 | 	for (v = 0; v < pf->hw.func_caps.num_vsis && !ctl_vsi; v++) { | 
 | 4561 | 		if (pf->vsi[v] && | 
 | 4562 | 		    pf->vsi[v]->veb_idx == veb->idx && | 
 | 4563 | 		    pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) { | 
 | 4564 | 			ctl_vsi = pf->vsi[v]; | 
 | 4565 | 			break; | 
 | 4566 | 		} | 
 | 4567 | 	} | 
 | 4568 | 	if (!ctl_vsi) { | 
 | 4569 | 		dev_info(&pf->pdev->dev, | 
 | 4570 | 			 "missing owner VSI for veb_idx %d\n", veb->idx); | 
 | 4571 | 		ret = -ENOENT; | 
 | 4572 | 		goto end_reconstitute; | 
 | 4573 | 	} | 
 | 4574 | 	if (ctl_vsi != pf->vsi[pf->lan_vsi]) | 
 | 4575 | 		ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | 
 | 4576 | 	ret = i40e_add_vsi(ctl_vsi); | 
 | 4577 | 	if (ret) { | 
 | 4578 | 		dev_info(&pf->pdev->dev, | 
 | 4579 | 			 "rebuild of owner VSI failed: %d\n", ret); | 
 | 4580 | 		goto end_reconstitute; | 
 | 4581 | 	} | 
 | 4582 | 	i40e_vsi_reset_stats(ctl_vsi); | 
 | 4583 |  | 
 | 4584 | 	/* create the VEB in the switch and move the VSI onto the VEB */ | 
 | 4585 | 	ret = i40e_add_veb(veb, ctl_vsi); | 
 | 4586 | 	if (ret) | 
 | 4587 | 		goto end_reconstitute; | 
 | 4588 |  | 
 | 4589 | 	/* create the remaining VSIs attached to this VEB */ | 
 | 4590 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 4591 | 		if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi) | 
 | 4592 | 			continue; | 
 | 4593 |  | 
 | 4594 | 		if (pf->vsi[v]->veb_idx == veb->idx) { | 
 | 4595 | 			struct i40e_vsi *vsi = pf->vsi[v]; | 
 | 4596 | 			vsi->uplink_seid = veb->seid; | 
 | 4597 | 			ret = i40e_add_vsi(vsi); | 
 | 4598 | 			if (ret) { | 
 | 4599 | 				dev_info(&pf->pdev->dev, | 
 | 4600 | 					 "rebuild of vsi_idx %d failed: %d\n", | 
 | 4601 | 					 v, ret); | 
 | 4602 | 				goto end_reconstitute; | 
 | 4603 | 			} | 
 | 4604 | 			i40e_vsi_reset_stats(vsi); | 
 | 4605 | 		} | 
 | 4606 | 	} | 
 | 4607 |  | 
 | 4608 | 	/* create any VEBs attached to this VEB - RECURSION */ | 
 | 4609 | 	for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | 
 | 4610 | 		if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) { | 
 | 4611 | 			pf->veb[veb_idx]->uplink_seid = veb->seid; | 
 | 4612 | 			ret = i40e_reconstitute_veb(pf->veb[veb_idx]); | 
 | 4613 | 			if (ret) | 
 | 4614 | 				break; | 
 | 4615 | 		} | 
 | 4616 | 	} | 
 | 4617 |  | 
 | 4618 | end_reconstitute: | 
 | 4619 | 	return ret; | 
 | 4620 | } | 
 | 4621 |  | 
 | 4622 | /** | 
 | 4623 |  * i40e_get_capabilities - get info about the HW | 
 | 4624 |  * @pf: the PF struct | 
 | 4625 |  **/ | 
 | 4626 | static int i40e_get_capabilities(struct i40e_pf *pf) | 
 | 4627 | { | 
 | 4628 | 	struct i40e_aqc_list_capabilities_element_resp *cap_buf; | 
 | 4629 | 	u16 data_size; | 
 | 4630 | 	int buf_len; | 
 | 4631 | 	int err; | 
 | 4632 |  | 
 | 4633 | 	buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp); | 
 | 4634 | 	do { | 
 | 4635 | 		cap_buf = kzalloc(buf_len, GFP_KERNEL); | 
 | 4636 | 		if (!cap_buf) | 
 | 4637 | 			return -ENOMEM; | 
 | 4638 |  | 
 | 4639 | 		/* this loads the data into the hw struct for us */ | 
 | 4640 | 		err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len, | 
 | 4641 | 					    &data_size, | 
 | 4642 | 					    i40e_aqc_opc_list_func_capabilities, | 
 | 4643 | 					    NULL); | 
 | 4644 | 		/* data loaded, buffer no longer needed */ | 
 | 4645 | 		kfree(cap_buf); | 
 | 4646 |  | 
 | 4647 | 		if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) { | 
 | 4648 | 			/* retry with a larger buffer */ | 
 | 4649 | 			buf_len = data_size; | 
 | 4650 | 		} else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) { | 
 | 4651 | 			dev_info(&pf->pdev->dev, | 
 | 4652 | 				 "capability discovery failed: aq=%d\n", | 
 | 4653 | 				 pf->hw.aq.asq_last_status); | 
 | 4654 | 			return -ENODEV; | 
 | 4655 | 		} | 
 | 4656 | 	} while (err); | 
 | 4657 |  | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4658 | 	if (pf->hw.revision_id == 0 && pf->hw.func_caps.npar_enable) { | 
 | 4659 | 		pf->hw.func_caps.num_msix_vectors += 1; | 
 | 4660 | 		pf->hw.func_caps.num_tx_qp = | 
 | 4661 | 			min_t(int, pf->hw.func_caps.num_tx_qp, | 
 | 4662 | 			      I40E_MAX_NPAR_QPS); | 
 | 4663 | 	} | 
 | 4664 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4665 | 	if (pf->hw.debug_mask & I40E_DEBUG_USER) | 
 | 4666 | 		dev_info(&pf->pdev->dev, | 
 | 4667 | 			 "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", | 
 | 4668 | 			 pf->hw.pf_id, pf->hw.func_caps.num_vfs, | 
 | 4669 | 			 pf->hw.func_caps.num_msix_vectors, | 
 | 4670 | 			 pf->hw.func_caps.num_msix_vectors_vf, | 
 | 4671 | 			 pf->hw.func_caps.fd_filters_guaranteed, | 
 | 4672 | 			 pf->hw.func_caps.fd_filters_best_effort, | 
 | 4673 | 			 pf->hw.func_caps.num_tx_qp, | 
 | 4674 | 			 pf->hw.func_caps.num_vsis); | 
 | 4675 |  | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 4676 | #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \ | 
 | 4677 | 		       + pf->hw.func_caps.num_vfs) | 
 | 4678 | 	if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) { | 
 | 4679 | 		dev_info(&pf->pdev->dev, | 
 | 4680 | 			 "got num_vsis %d, setting num_vsis to %d\n", | 
 | 4681 | 			 pf->hw.func_caps.num_vsis, DEF_NUM_VSI); | 
 | 4682 | 		pf->hw.func_caps.num_vsis = DEF_NUM_VSI; | 
 | 4683 | 	} | 
 | 4684 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4685 | 	return 0; | 
 | 4686 | } | 
 | 4687 |  | 
 | 4688 | /** | 
 | 4689 |  * i40e_fdir_setup - initialize the Flow Director resources | 
 | 4690 |  * @pf: board private structure | 
 | 4691 |  **/ | 
 | 4692 | static void i40e_fdir_setup(struct i40e_pf *pf) | 
 | 4693 | { | 
 | 4694 | 	struct i40e_vsi *vsi; | 
 | 4695 | 	bool new_vsi = false; | 
 | 4696 | 	int err, i; | 
 | 4697 |  | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 4698 | 	if (!(pf->flags & (I40E_FLAG_FDIR_ENABLED | | 
 | 4699 | 			   I40E_FLAG_FDIR_ATR_ENABLED))) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4700 | 		return; | 
 | 4701 |  | 
 | 4702 | 	pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE; | 
 | 4703 |  | 
 | 4704 | 	/* find existing or make new FDIR VSI */ | 
 | 4705 | 	vsi = NULL; | 
 | 4706 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) | 
 | 4707 | 		if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) | 
 | 4708 | 			vsi = pf->vsi[i]; | 
 | 4709 | 	if (!vsi) { | 
 | 4710 | 		vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR, pf->mac_seid, 0); | 
 | 4711 | 		if (!vsi) { | 
 | 4712 | 			dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n"); | 
 | 4713 | 			pf->flags &= ~I40E_FLAG_FDIR_ENABLED; | 
 | 4714 | 			return; | 
 | 4715 | 		} | 
 | 4716 | 		new_vsi = true; | 
 | 4717 | 	} | 
 | 4718 | 	WARN_ON(vsi->base_queue != I40E_FDIR_RING); | 
 | 4719 | 	i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_rings); | 
 | 4720 |  | 
 | 4721 | 	err = i40e_vsi_setup_tx_resources(vsi); | 
 | 4722 | 	if (!err) | 
 | 4723 | 		err = i40e_vsi_setup_rx_resources(vsi); | 
 | 4724 | 	if (!err) | 
 | 4725 | 		err = i40e_vsi_configure(vsi); | 
 | 4726 | 	if (!err && new_vsi) { | 
 | 4727 | 		char int_name[IFNAMSIZ + 9]; | 
 | 4728 | 		snprintf(int_name, sizeof(int_name) - 1, "%s-fdir", | 
 | 4729 | 			 dev_driver_string(&pf->pdev->dev)); | 
 | 4730 | 		err = i40e_vsi_request_irq(vsi, int_name); | 
 | 4731 | 	} | 
 | 4732 | 	if (!err) | 
 | 4733 | 		err = i40e_up_complete(vsi); | 
 | 4734 |  | 
 | 4735 | 	clear_bit(__I40E_NEEDS_RESTART, &vsi->state); | 
 | 4736 | } | 
 | 4737 |  | 
 | 4738 | /** | 
 | 4739 |  * i40e_fdir_teardown - release the Flow Director resources | 
 | 4740 |  * @pf: board private structure | 
 | 4741 |  **/ | 
 | 4742 | static void i40e_fdir_teardown(struct i40e_pf *pf) | 
 | 4743 | { | 
 | 4744 | 	int i; | 
 | 4745 |  | 
 | 4746 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 4747 | 		if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) { | 
 | 4748 | 			i40e_vsi_release(pf->vsi[i]); | 
 | 4749 | 			break; | 
 | 4750 | 		} | 
 | 4751 | 	} | 
 | 4752 | } | 
 | 4753 |  | 
 | 4754 | /** | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4755 |  * i40e_prep_for_reset - prep for the core to reset | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4756 |  * @pf: board private structure | 
 | 4757 |  * | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4758 |  * Close up the VFs and other things in prep for pf Reset. | 
 | 4759 |   **/ | 
 | 4760 | static int i40e_prep_for_reset(struct i40e_pf *pf) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4761 | { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4762 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4763 | 	i40e_status ret; | 
 | 4764 | 	u32 v; | 
 | 4765 |  | 
 | 4766 | 	clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state); | 
 | 4767 | 	if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4768 | 		return 0; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4769 |  | 
 | 4770 | 	dev_info(&pf->pdev->dev, "Tearing down internal switch for reset\n"); | 
 | 4771 |  | 
| Anjali Singhai Jain | 37f0be6 | 2013-11-28 06:39:46 +0000 | [diff] [blame] | 4772 | 	if (i40e_check_asq_alive(hw)) | 
 | 4773 | 		i40e_vc_notify_reset(pf); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4774 |  | 
 | 4775 | 	/* quiesce the VSIs and their queues that are not already DOWN */ | 
 | 4776 | 	i40e_pf_quiesce_all_vsi(pf); | 
 | 4777 |  | 
 | 4778 | 	for (v = 0; v < pf->hw.func_caps.num_vsis; v++) { | 
 | 4779 | 		if (pf->vsi[v]) | 
 | 4780 | 			pf->vsi[v]->seid = 0; | 
 | 4781 | 	} | 
 | 4782 |  | 
 | 4783 | 	i40e_shutdown_adminq(&pf->hw); | 
 | 4784 |  | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4785 | 	/* call shutdown HMC */ | 
 | 4786 | 	ret = i40e_shutdown_lan_hmc(hw); | 
 | 4787 | 	if (ret) { | 
 | 4788 | 		dev_info(&pf->pdev->dev, "shutdown_lan_hmc failed: %d\n", ret); | 
 | 4789 | 		clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); | 
 | 4790 | 	} | 
 | 4791 | 	return ret; | 
 | 4792 | } | 
 | 4793 |  | 
 | 4794 | /** | 
 | 4795 |  * i40e_reset_and_rebuild - reset and rebuid using a saved config | 
 | 4796 |  * @pf: board private structure | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4797 |  * @reinit: if the Main VSI needs to re-initialized. | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4798 |  **/ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4799 | 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] | 4800 | { | 
 | 4801 | 	struct i40e_driver_version dv; | 
 | 4802 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4803 | 	i40e_status ret; | 
 | 4804 | 	u32 v; | 
 | 4805 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4806 | 	/* Now we wait for GRST to settle out. | 
 | 4807 | 	 * We don't have to delete the VEBs or VSIs from the hw switch | 
 | 4808 | 	 * because the reset will make them disappear. | 
 | 4809 | 	 */ | 
 | 4810 | 	ret = i40e_pf_reset(hw); | 
 | 4811 | 	if (ret) | 
 | 4812 | 		dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret); | 
 | 4813 | 	pf->pfr_count++; | 
 | 4814 |  | 
 | 4815 | 	if (test_bit(__I40E_DOWN, &pf->state)) | 
 | 4816 | 		goto end_core_reset; | 
 | 4817 | 	dev_info(&pf->pdev->dev, "Rebuilding internal switch\n"); | 
 | 4818 |  | 
 | 4819 | 	/* rebuild the basics for the AdminQ, HMC, and initial HW switch */ | 
 | 4820 | 	ret = i40e_init_adminq(&pf->hw); | 
 | 4821 | 	if (ret) { | 
 | 4822 | 		dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret); | 
 | 4823 | 		goto end_core_reset; | 
 | 4824 | 	} | 
 | 4825 |  | 
 | 4826 | 	ret = i40e_get_capabilities(pf); | 
 | 4827 | 	if (ret) { | 
 | 4828 | 		dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n", | 
 | 4829 | 			 ret); | 
 | 4830 | 		goto end_core_reset; | 
 | 4831 | 	} | 
 | 4832 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4833 | 	ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | 
 | 4834 | 				hw->func_caps.num_rx_qp, | 
 | 4835 | 				pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); | 
 | 4836 | 	if (ret) { | 
 | 4837 | 		dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret); | 
 | 4838 | 		goto end_core_reset; | 
 | 4839 | 	} | 
 | 4840 | 	ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | 
 | 4841 | 	if (ret) { | 
 | 4842 | 		dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret); | 
 | 4843 | 		goto end_core_reset; | 
 | 4844 | 	} | 
 | 4845 |  | 
 | 4846 | 	/* do basic switch setup */ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4847 | 	ret = i40e_setup_pf_switch(pf, reinit); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4848 | 	if (ret) | 
 | 4849 | 		goto end_core_reset; | 
 | 4850 |  | 
 | 4851 | 	/* Rebuild the VSIs and VEBs that existed before reset. | 
 | 4852 | 	 * They are still in our local switch element arrays, so only | 
 | 4853 | 	 * need to rebuild the switch model in the HW. | 
 | 4854 | 	 * | 
 | 4855 | 	 * If there were VEBs but the reconstitution failed, we'll try | 
 | 4856 | 	 * try to recover minimal use by getting the basic PF VSI working. | 
 | 4857 | 	 */ | 
 | 4858 | 	if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) { | 
 | 4859 | 		dev_info(&pf->pdev->dev, "attempting to rebuild switch\n"); | 
 | 4860 | 		/* find the one VEB connected to the MAC, and find orphans */ | 
 | 4861 | 		for (v = 0; v < I40E_MAX_VEB; v++) { | 
 | 4862 | 			if (!pf->veb[v]) | 
 | 4863 | 				continue; | 
 | 4864 |  | 
 | 4865 | 			if (pf->veb[v]->uplink_seid == pf->mac_seid || | 
 | 4866 | 			    pf->veb[v]->uplink_seid == 0) { | 
 | 4867 | 				ret = i40e_reconstitute_veb(pf->veb[v]); | 
 | 4868 |  | 
 | 4869 | 				if (!ret) | 
 | 4870 | 					continue; | 
 | 4871 |  | 
 | 4872 | 				/* If Main VEB failed, we're in deep doodoo, | 
 | 4873 | 				 * so give up rebuilding the switch and set up | 
 | 4874 | 				 * for minimal rebuild of PF VSI. | 
 | 4875 | 				 * If orphan failed, we'll report the error | 
 | 4876 | 				 * but try to keep going. | 
 | 4877 | 				 */ | 
 | 4878 | 				if (pf->veb[v]->uplink_seid == pf->mac_seid) { | 
 | 4879 | 					dev_info(&pf->pdev->dev, | 
 | 4880 | 						 "rebuild of switch failed: %d, will try to set up simple PF connection\n", | 
 | 4881 | 						 ret); | 
 | 4882 | 					pf->vsi[pf->lan_vsi]->uplink_seid | 
 | 4883 | 								= pf->mac_seid; | 
 | 4884 | 					break; | 
 | 4885 | 				} else if (pf->veb[v]->uplink_seid == 0) { | 
 | 4886 | 					dev_info(&pf->pdev->dev, | 
 | 4887 | 						 "rebuild of orphan VEB failed: %d\n", | 
 | 4888 | 						 ret); | 
 | 4889 | 				} | 
 | 4890 | 			} | 
 | 4891 | 		} | 
 | 4892 | 	} | 
 | 4893 |  | 
 | 4894 | 	if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) { | 
 | 4895 | 		dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n"); | 
 | 4896 | 		/* no VEB, so rebuild only the Main VSI */ | 
 | 4897 | 		ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]); | 
 | 4898 | 		if (ret) { | 
 | 4899 | 			dev_info(&pf->pdev->dev, | 
 | 4900 | 				 "rebuild of Main VSI failed: %d\n", ret); | 
 | 4901 | 			goto end_core_reset; | 
 | 4902 | 		} | 
 | 4903 | 	} | 
 | 4904 |  | 
 | 4905 | 	/* reinit the misc interrupt */ | 
 | 4906 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) | 
 | 4907 | 		ret = i40e_setup_misc_vector(pf); | 
 | 4908 |  | 
 | 4909 | 	/* restart the VSIs that were rebuilt and running before the reset */ | 
 | 4910 | 	i40e_pf_unquiesce_all_vsi(pf); | 
 | 4911 |  | 
 | 4912 | 	/* tell the firmware that we're starting */ | 
 | 4913 | 	dv.major_version = DRV_VERSION_MAJOR; | 
 | 4914 | 	dv.minor_version = DRV_VERSION_MINOR; | 
 | 4915 | 	dv.build_version = DRV_VERSION_BUILD; | 
 | 4916 | 	dv.subbuild_version = 0; | 
 | 4917 | 	i40e_aq_send_driver_version(&pf->hw, &dv, NULL); | 
 | 4918 |  | 
 | 4919 | 	dev_info(&pf->pdev->dev, "PF reset done\n"); | 
 | 4920 |  | 
 | 4921 | end_core_reset: | 
 | 4922 | 	clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state); | 
 | 4923 | } | 
 | 4924 |  | 
 | 4925 | /** | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4926 |  * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild | 
 | 4927 |  * @pf: board private structure | 
 | 4928 |  * | 
 | 4929 |  * Close up the VFs and other things in prep for a Core Reset, | 
 | 4930 |  * then get ready to rebuild the world. | 
 | 4931 |  **/ | 
 | 4932 | static void i40e_handle_reset_warning(struct i40e_pf *pf) | 
 | 4933 | { | 
 | 4934 | 	i40e_status ret; | 
 | 4935 |  | 
 | 4936 | 	ret = i40e_prep_for_reset(pf); | 
 | 4937 | 	if (!ret) | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 4938 | 		i40e_reset_and_rebuild(pf, false); | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 4939 | } | 
 | 4940 |  | 
 | 4941 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 4942 |  * i40e_handle_mdd_event | 
 | 4943 |  * @pf: pointer to the pf structure | 
 | 4944 |  * | 
 | 4945 |  * Called from the MDD irq handler to identify possibly malicious vfs | 
 | 4946 |  **/ | 
 | 4947 | static void i40e_handle_mdd_event(struct i40e_pf *pf) | 
 | 4948 | { | 
 | 4949 | 	struct i40e_hw *hw = &pf->hw; | 
 | 4950 | 	bool mdd_detected = false; | 
 | 4951 | 	struct i40e_vf *vf; | 
 | 4952 | 	u32 reg; | 
 | 4953 | 	int i; | 
 | 4954 |  | 
 | 4955 | 	if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)) | 
 | 4956 | 		return; | 
 | 4957 |  | 
 | 4958 | 	/* find what triggered the MDD event */ | 
 | 4959 | 	reg = rd32(hw, I40E_GL_MDET_TX); | 
 | 4960 | 	if (reg & I40E_GL_MDET_TX_VALID_MASK) { | 
 | 4961 | 		u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK) | 
 | 4962 | 				>> I40E_GL_MDET_TX_FUNCTION_SHIFT; | 
 | 4963 | 		u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT) | 
 | 4964 | 				>> I40E_GL_MDET_TX_EVENT_SHIFT; | 
 | 4965 | 		u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK) | 
 | 4966 | 				>> I40E_GL_MDET_TX_QUEUE_SHIFT; | 
 | 4967 | 		dev_info(&pf->pdev->dev, | 
 | 4968 | 			 "Malicious Driver Detection TX event 0x%02x on q %d of function 0x%02x\n", | 
 | 4969 | 			 event, queue, func); | 
 | 4970 | 		wr32(hw, I40E_GL_MDET_TX, 0xffffffff); | 
 | 4971 | 		mdd_detected = true; | 
 | 4972 | 	} | 
 | 4973 | 	reg = rd32(hw, I40E_GL_MDET_RX); | 
 | 4974 | 	if (reg & I40E_GL_MDET_RX_VALID_MASK) { | 
 | 4975 | 		u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) | 
 | 4976 | 				>> I40E_GL_MDET_RX_FUNCTION_SHIFT; | 
 | 4977 | 		u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT) | 
 | 4978 | 				>> I40E_GL_MDET_RX_EVENT_SHIFT; | 
 | 4979 | 		u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK) | 
 | 4980 | 				>> I40E_GL_MDET_RX_QUEUE_SHIFT; | 
 | 4981 | 		dev_info(&pf->pdev->dev, | 
 | 4982 | 			 "Malicious Driver Detection RX event 0x%02x on q %d of function 0x%02x\n", | 
 | 4983 | 			 event, queue, func); | 
 | 4984 | 		wr32(hw, I40E_GL_MDET_RX, 0xffffffff); | 
 | 4985 | 		mdd_detected = true; | 
 | 4986 | 	} | 
 | 4987 |  | 
 | 4988 | 	/* see if one of the VFs needs its hand slapped */ | 
 | 4989 | 	for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) { | 
 | 4990 | 		vf = &(pf->vf[i]); | 
 | 4991 | 		reg = rd32(hw, I40E_VP_MDET_TX(i)); | 
 | 4992 | 		if (reg & I40E_VP_MDET_TX_VALID_MASK) { | 
 | 4993 | 			wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF); | 
 | 4994 | 			vf->num_mdd_events++; | 
 | 4995 | 			dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i); | 
 | 4996 | 		} | 
 | 4997 |  | 
 | 4998 | 		reg = rd32(hw, I40E_VP_MDET_RX(i)); | 
 | 4999 | 		if (reg & I40E_VP_MDET_RX_VALID_MASK) { | 
 | 5000 | 			wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF); | 
 | 5001 | 			vf->num_mdd_events++; | 
 | 5002 | 			dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i); | 
 | 5003 | 		} | 
 | 5004 |  | 
 | 5005 | 		if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) { | 
 | 5006 | 			dev_info(&pf->pdev->dev, | 
 | 5007 | 				 "Too many MDD events on VF %d, disabled\n", i); | 
 | 5008 | 			dev_info(&pf->pdev->dev, | 
 | 5009 | 				 "Use PF Control I/F to re-enable the VF\n"); | 
 | 5010 | 			set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states); | 
 | 5011 | 		} | 
 | 5012 | 	} | 
 | 5013 |  | 
 | 5014 | 	/* re-enable mdd interrupt cause */ | 
 | 5015 | 	clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state); | 
 | 5016 | 	reg = rd32(hw, I40E_PFINT_ICR0_ENA); | 
 | 5017 | 	reg |=  I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK; | 
 | 5018 | 	wr32(hw, I40E_PFINT_ICR0_ENA, reg); | 
 | 5019 | 	i40e_flush(hw); | 
 | 5020 | } | 
 | 5021 |  | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5022 | #ifdef CONFIG_I40E_VXLAN | 
 | 5023 | /** | 
 | 5024 |  * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW | 
 | 5025 |  * @pf: board private structure | 
 | 5026 |  **/ | 
 | 5027 | static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf) | 
 | 5028 | { | 
 | 5029 | 	const int vxlan_hdr_qwords = 4; | 
 | 5030 | 	struct i40e_hw *hw = &pf->hw; | 
 | 5031 | 	i40e_status ret; | 
 | 5032 | 	u8 filter_index; | 
 | 5033 | 	__be16 port; | 
 | 5034 | 	int i; | 
 | 5035 |  | 
 | 5036 | 	if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC)) | 
 | 5037 | 		return; | 
 | 5038 |  | 
 | 5039 | 	pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC; | 
 | 5040 |  | 
 | 5041 | 	for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | 
 | 5042 | 		if (pf->pending_vxlan_bitmap & (1 << i)) { | 
 | 5043 | 			pf->pending_vxlan_bitmap &= ~(1 << i); | 
 | 5044 | 			port = pf->vxlan_ports[i]; | 
 | 5045 | 			ret = port ? | 
 | 5046 | 			      i40e_aq_add_udp_tunnel(hw, ntohs(port), | 
 | 5047 | 						     vxlan_hdr_qwords, | 
 | 5048 | 						     I40E_AQC_TUNNEL_TYPE_VXLAN, | 
 | 5049 | 						     &filter_index, NULL) | 
 | 5050 | 			      : i40e_aq_del_udp_tunnel(hw, i, NULL); | 
 | 5051 |  | 
 | 5052 | 			if (ret) { | 
 | 5053 | 				dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n", | 
 | 5054 | 					 port ? "adding" : "deleting", | 
 | 5055 | 					 ntohs(port), port ? i : i); | 
 | 5056 |  | 
 | 5057 | 				pf->vxlan_ports[i] = 0; | 
 | 5058 | 			} else { | 
 | 5059 | 				dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n", | 
 | 5060 | 					 port ? "Added" : "Deleted", | 
 | 5061 | 					 ntohs(port), port ? i : filter_index); | 
 | 5062 | 			} | 
 | 5063 | 		} | 
 | 5064 | 	} | 
 | 5065 | } | 
 | 5066 |  | 
 | 5067 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5068 | /** | 
 | 5069 |  * i40e_service_task - Run the driver's async subtasks | 
 | 5070 |  * @work: pointer to work_struct containing our data | 
 | 5071 |  **/ | 
 | 5072 | static void i40e_service_task(struct work_struct *work) | 
 | 5073 | { | 
 | 5074 | 	struct i40e_pf *pf = container_of(work, | 
 | 5075 | 					  struct i40e_pf, | 
 | 5076 | 					  service_task); | 
 | 5077 | 	unsigned long start_time = jiffies; | 
 | 5078 |  | 
 | 5079 | 	i40e_reset_subtask(pf); | 
 | 5080 | 	i40e_handle_mdd_event(pf); | 
 | 5081 | 	i40e_vc_process_vflr_event(pf); | 
 | 5082 | 	i40e_watchdog_subtask(pf); | 
 | 5083 | 	i40e_fdir_reinit_subtask(pf); | 
 | 5084 | 	i40e_check_hang_subtask(pf); | 
 | 5085 | 	i40e_sync_filters_subtask(pf); | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5086 | #ifdef CONFIG_I40E_VXLAN | 
 | 5087 | 	i40e_sync_vxlan_filters_subtask(pf); | 
 | 5088 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5089 | 	i40e_clean_adminq_subtask(pf); | 
 | 5090 |  | 
 | 5091 | 	i40e_service_event_complete(pf); | 
 | 5092 |  | 
 | 5093 | 	/* If the tasks have taken longer than one timer cycle or there | 
 | 5094 | 	 * is more work to be done, reschedule the service task now | 
 | 5095 | 	 * rather than wait for the timer to tick again. | 
 | 5096 | 	 */ | 
 | 5097 | 	if (time_after(jiffies, (start_time + pf->service_timer_period)) || | 
 | 5098 | 	    test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state)		 || | 
 | 5099 | 	    test_bit(__I40E_MDD_EVENT_PENDING, &pf->state)		 || | 
 | 5100 | 	    test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state)) | 
 | 5101 | 		i40e_service_event_schedule(pf); | 
 | 5102 | } | 
 | 5103 |  | 
 | 5104 | /** | 
 | 5105 |  * i40e_service_timer - timer callback | 
 | 5106 |  * @data: pointer to PF struct | 
 | 5107 |  **/ | 
 | 5108 | static void i40e_service_timer(unsigned long data) | 
 | 5109 | { | 
 | 5110 | 	struct i40e_pf *pf = (struct i40e_pf *)data; | 
 | 5111 |  | 
 | 5112 | 	mod_timer(&pf->service_timer, | 
 | 5113 | 		  round_jiffies(jiffies + pf->service_timer_period)); | 
 | 5114 | 	i40e_service_event_schedule(pf); | 
 | 5115 | } | 
 | 5116 |  | 
 | 5117 | /** | 
 | 5118 |  * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI | 
 | 5119 |  * @vsi: the VSI being configured | 
 | 5120 |  **/ | 
 | 5121 | static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi) | 
 | 5122 | { | 
 | 5123 | 	struct i40e_pf *pf = vsi->back; | 
 | 5124 |  | 
 | 5125 | 	switch (vsi->type) { | 
 | 5126 | 	case I40E_VSI_MAIN: | 
 | 5127 | 		vsi->alloc_queue_pairs = pf->num_lan_qps; | 
 | 5128 | 		vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | 
 | 5129 | 				      I40E_REQ_DESCRIPTOR_MULTIPLE); | 
 | 5130 | 		if (pf->flags & I40E_FLAG_MSIX_ENABLED) | 
 | 5131 | 			vsi->num_q_vectors = pf->num_lan_msix; | 
 | 5132 | 		else | 
 | 5133 | 			vsi->num_q_vectors = 1; | 
 | 5134 |  | 
 | 5135 | 		break; | 
 | 5136 |  | 
 | 5137 | 	case I40E_VSI_FDIR: | 
 | 5138 | 		vsi->alloc_queue_pairs = 1; | 
 | 5139 | 		vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT, | 
 | 5140 | 				      I40E_REQ_DESCRIPTOR_MULTIPLE); | 
 | 5141 | 		vsi->num_q_vectors = 1; | 
 | 5142 | 		break; | 
 | 5143 |  | 
 | 5144 | 	case I40E_VSI_VMDQ2: | 
 | 5145 | 		vsi->alloc_queue_pairs = pf->num_vmdq_qps; | 
 | 5146 | 		vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | 
 | 5147 | 				      I40E_REQ_DESCRIPTOR_MULTIPLE); | 
 | 5148 | 		vsi->num_q_vectors = pf->num_vmdq_msix; | 
 | 5149 | 		break; | 
 | 5150 |  | 
 | 5151 | 	case I40E_VSI_SRIOV: | 
 | 5152 | 		vsi->alloc_queue_pairs = pf->num_vf_qps; | 
 | 5153 | 		vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS, | 
 | 5154 | 				      I40E_REQ_DESCRIPTOR_MULTIPLE); | 
 | 5155 | 		break; | 
 | 5156 |  | 
 | 5157 | 	default: | 
 | 5158 | 		WARN_ON(1); | 
 | 5159 | 		return -ENODATA; | 
 | 5160 | 	} | 
 | 5161 |  | 
 | 5162 | 	return 0; | 
 | 5163 | } | 
 | 5164 |  | 
 | 5165 | /** | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5166 |  * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi | 
 | 5167 |  * @type: VSI pointer | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5168 |  * @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] | 5169 |  * | 
 | 5170 |  * On error: returns error code (negative) | 
 | 5171 |  * On success: returns 0 | 
 | 5172 |  **/ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5173 | 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] | 5174 | { | 
 | 5175 | 	int size; | 
 | 5176 | 	int ret = 0; | 
 | 5177 |  | 
| Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5178 | 	/* allocate memory for both Tx and Rx ring pointers */ | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5179 | 	size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2; | 
 | 5180 | 	vsi->tx_rings = kzalloc(size, GFP_KERNEL); | 
 | 5181 | 	if (!vsi->tx_rings) | 
 | 5182 | 		return -ENOMEM; | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5183 | 	vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs]; | 
 | 5184 |  | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5185 | 	if (alloc_qvectors) { | 
 | 5186 | 		/* allocate memory for q_vector pointers */ | 
 | 5187 | 		size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors; | 
 | 5188 | 		vsi->q_vectors = kzalloc(size, GFP_KERNEL); | 
 | 5189 | 		if (!vsi->q_vectors) { | 
 | 5190 | 			ret = -ENOMEM; | 
 | 5191 | 			goto err_vectors; | 
 | 5192 | 		} | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5193 | 	} | 
 | 5194 | 	return ret; | 
 | 5195 |  | 
 | 5196 | err_vectors: | 
 | 5197 | 	kfree(vsi->tx_rings); | 
 | 5198 | 	return ret; | 
 | 5199 | } | 
 | 5200 |  | 
 | 5201 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5202 |  * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF | 
 | 5203 |  * @pf: board private structure | 
 | 5204 |  * @type: type of VSI | 
 | 5205 |  * | 
 | 5206 |  * On error: returns error code (negative) | 
 | 5207 |  * On success: returns vsi index in PF (positive) | 
 | 5208 |  **/ | 
 | 5209 | static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type) | 
 | 5210 | { | 
 | 5211 | 	int ret = -ENODEV; | 
 | 5212 | 	struct i40e_vsi *vsi; | 
 | 5213 | 	int vsi_idx; | 
 | 5214 | 	int i; | 
 | 5215 |  | 
 | 5216 | 	/* Need to protect the allocation of the VSIs at the PF level */ | 
 | 5217 | 	mutex_lock(&pf->switch_mutex); | 
 | 5218 |  | 
 | 5219 | 	/* VSI list may be fragmented if VSI creation/destruction has | 
 | 5220 | 	 * been happening.  We can afford to do a quick scan to look | 
 | 5221 | 	 * for any free VSIs in the list. | 
 | 5222 | 	 * | 
 | 5223 | 	 * find next empty vsi slot, looping back around if necessary | 
 | 5224 | 	 */ | 
 | 5225 | 	i = pf->next_vsi; | 
 | 5226 | 	while (i < pf->hw.func_caps.num_vsis && pf->vsi[i]) | 
 | 5227 | 		i++; | 
 | 5228 | 	if (i >= pf->hw.func_caps.num_vsis) { | 
 | 5229 | 		i = 0; | 
 | 5230 | 		while (i < pf->next_vsi && pf->vsi[i]) | 
 | 5231 | 			i++; | 
 | 5232 | 	} | 
 | 5233 |  | 
 | 5234 | 	if (i < pf->hw.func_caps.num_vsis && !pf->vsi[i]) { | 
 | 5235 | 		vsi_idx = i;             /* Found one! */ | 
 | 5236 | 	} else { | 
 | 5237 | 		ret = -ENODEV; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5238 | 		goto unlock_pf;  /* out of VSI slots! */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5239 | 	} | 
 | 5240 | 	pf->next_vsi = ++i; | 
 | 5241 |  | 
 | 5242 | 	vsi = kzalloc(sizeof(*vsi), GFP_KERNEL); | 
 | 5243 | 	if (!vsi) { | 
 | 5244 | 		ret = -ENOMEM; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5245 | 		goto unlock_pf; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5246 | 	} | 
 | 5247 | 	vsi->type = type; | 
 | 5248 | 	vsi->back = pf; | 
 | 5249 | 	set_bit(__I40E_DOWN, &vsi->state); | 
 | 5250 | 	vsi->flags = 0; | 
 | 5251 | 	vsi->idx = vsi_idx; | 
 | 5252 | 	vsi->rx_itr_setting = pf->rx_itr_default; | 
 | 5253 | 	vsi->tx_itr_setting = pf->tx_itr_default; | 
 | 5254 | 	vsi->netdev_registered = false; | 
 | 5255 | 	vsi->work_limit = I40E_DEFAULT_IRQ_WORK; | 
 | 5256 | 	INIT_LIST_HEAD(&vsi->mac_filter_list); | 
 | 5257 |  | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5258 | 	ret = i40e_set_num_rings_in_vsi(vsi); | 
 | 5259 | 	if (ret) | 
 | 5260 | 		goto err_rings; | 
 | 5261 |  | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5262 | 	ret = i40e_vsi_alloc_arrays(vsi, true); | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5263 | 	if (ret) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5264 | 		goto err_rings; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5265 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5266 | 	/* Setup default MSIX irq handler for VSI */ | 
 | 5267 | 	i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings); | 
 | 5268 |  | 
 | 5269 | 	pf->vsi[vsi_idx] = vsi; | 
 | 5270 | 	ret = vsi_idx; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5271 | 	goto unlock_pf; | 
 | 5272 |  | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5273 | err_rings: | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5274 | 	pf->next_vsi = i - 1; | 
 | 5275 | 	kfree(vsi); | 
 | 5276 | unlock_pf: | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5277 | 	mutex_unlock(&pf->switch_mutex); | 
 | 5278 | 	return ret; | 
 | 5279 | } | 
 | 5280 |  | 
 | 5281 | /** | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5282 |  * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI | 
 | 5283 |  * @type: VSI pointer | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5284 |  * @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] | 5285 |  * | 
 | 5286 |  * On error: returns error code (negative) | 
 | 5287 |  * On success: returns 0 | 
 | 5288 |  **/ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5289 | 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] | 5290 | { | 
 | 5291 | 	/* free the ring and vector containers */ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5292 | 	if (free_qvectors) { | 
 | 5293 | 		kfree(vsi->q_vectors); | 
 | 5294 | 		vsi->q_vectors = NULL; | 
 | 5295 | 	} | 
| Anjali Singhai Jain | f650a38 | 2013-11-20 10:02:55 +0000 | [diff] [blame] | 5296 | 	kfree(vsi->tx_rings); | 
 | 5297 | 	vsi->tx_rings = NULL; | 
 | 5298 | 	vsi->rx_rings = NULL; | 
 | 5299 | } | 
 | 5300 |  | 
 | 5301 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5302 |  * i40e_vsi_clear - Deallocate the VSI provided | 
 | 5303 |  * @vsi: the VSI being un-configured | 
 | 5304 |  **/ | 
 | 5305 | static int i40e_vsi_clear(struct i40e_vsi *vsi) | 
 | 5306 | { | 
 | 5307 | 	struct i40e_pf *pf; | 
 | 5308 |  | 
 | 5309 | 	if (!vsi) | 
 | 5310 | 		return 0; | 
 | 5311 |  | 
 | 5312 | 	if (!vsi->back) | 
 | 5313 | 		goto free_vsi; | 
 | 5314 | 	pf = vsi->back; | 
 | 5315 |  | 
 | 5316 | 	mutex_lock(&pf->switch_mutex); | 
 | 5317 | 	if (!pf->vsi[vsi->idx]) { | 
 | 5318 | 		dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n", | 
 | 5319 | 			vsi->idx, vsi->idx, vsi, vsi->type); | 
 | 5320 | 		goto unlock_vsi; | 
 | 5321 | 	} | 
 | 5322 |  | 
 | 5323 | 	if (pf->vsi[vsi->idx] != vsi) { | 
 | 5324 | 		dev_err(&pf->pdev->dev, | 
 | 5325 | 			"pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n", | 
 | 5326 | 			pf->vsi[vsi->idx]->idx, | 
 | 5327 | 			pf->vsi[vsi->idx], | 
 | 5328 | 			pf->vsi[vsi->idx]->type, | 
 | 5329 | 			vsi->idx, vsi, vsi->type); | 
 | 5330 | 		goto unlock_vsi; | 
 | 5331 | 	} | 
 | 5332 |  | 
 | 5333 | 	/* updates the pf for this cleared vsi */ | 
 | 5334 | 	i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); | 
 | 5335 | 	i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx); | 
 | 5336 |  | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 5337 | 	i40e_vsi_free_arrays(vsi, true); | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5338 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5339 | 	pf->vsi[vsi->idx] = NULL; | 
 | 5340 | 	if (vsi->idx < pf->next_vsi) | 
 | 5341 | 		pf->next_vsi = vsi->idx; | 
 | 5342 |  | 
 | 5343 | unlock_vsi: | 
 | 5344 | 	mutex_unlock(&pf->switch_mutex); | 
 | 5345 | free_vsi: | 
 | 5346 | 	kfree(vsi); | 
 | 5347 |  | 
 | 5348 | 	return 0; | 
 | 5349 | } | 
 | 5350 |  | 
 | 5351 | /** | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5352 |  * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI | 
 | 5353 |  * @vsi: the VSI being cleaned | 
 | 5354 |  **/ | 
| Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 5355 | static void i40e_vsi_clear_rings(struct i40e_vsi *vsi) | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5356 | { | 
 | 5357 | 	int i; | 
 | 5358 |  | 
| Greg Rose | 8e9dca5 | 2013-12-18 13:45:53 +0000 | [diff] [blame] | 5359 | 	if (vsi->tx_rings && vsi->tx_rings[0]) { | 
| Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 5360 | 		for (i = 0; i < vsi->alloc_queue_pairs; i++) { | 
| Mitch Williams | 00403f0 | 2013-09-28 07:13:13 +0000 | [diff] [blame] | 5361 | 			kfree_rcu(vsi->tx_rings[i], rcu); | 
 | 5362 | 			vsi->tx_rings[i] = NULL; | 
 | 5363 | 			vsi->rx_rings[i] = NULL; | 
 | 5364 | 		} | 
| Shannon Nelson | be1d5ee | 2013-11-28 06:39:23 +0000 | [diff] [blame] | 5365 | 	} | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5366 | } | 
 | 5367 |  | 
 | 5368 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5369 |  * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI | 
 | 5370 |  * @vsi: the VSI being configured | 
 | 5371 |  **/ | 
 | 5372 | static int i40e_alloc_rings(struct i40e_vsi *vsi) | 
 | 5373 | { | 
 | 5374 | 	struct i40e_pf *pf = vsi->back; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5375 | 	int i; | 
 | 5376 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5377 | 	/* Set basic values in the rings to be used later during open() */ | 
| Neerav Parikh | d739764 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 5378 | 	for (i = 0; i < vsi->alloc_queue_pairs; i++) { | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5379 | 		struct i40e_ring *tx_ring; | 
 | 5380 | 		struct i40e_ring *rx_ring; | 
 | 5381 |  | 
| Shannon Nelson | ac6c5e3 | 2013-11-20 10:02:57 +0000 | [diff] [blame] | 5382 | 		/* allocate space for both Tx and Rx in one shot */ | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5383 | 		tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL); | 
 | 5384 | 		if (!tx_ring) | 
 | 5385 | 			goto err_out; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5386 |  | 
 | 5387 | 		tx_ring->queue_index = i; | 
 | 5388 | 		tx_ring->reg_idx = vsi->base_queue + i; | 
 | 5389 | 		tx_ring->ring_active = false; | 
 | 5390 | 		tx_ring->vsi = vsi; | 
 | 5391 | 		tx_ring->netdev = vsi->netdev; | 
 | 5392 | 		tx_ring->dev = &pf->pdev->dev; | 
 | 5393 | 		tx_ring->count = vsi->num_desc; | 
 | 5394 | 		tx_ring->size = 0; | 
 | 5395 | 		tx_ring->dcb_tc = 0; | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5396 | 		vsi->tx_rings[i] = tx_ring; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5397 |  | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5398 | 		rx_ring = &tx_ring[1]; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5399 | 		rx_ring->queue_index = i; | 
 | 5400 | 		rx_ring->reg_idx = vsi->base_queue + i; | 
 | 5401 | 		rx_ring->ring_active = false; | 
 | 5402 | 		rx_ring->vsi = vsi; | 
 | 5403 | 		rx_ring->netdev = vsi->netdev; | 
 | 5404 | 		rx_ring->dev = &pf->pdev->dev; | 
 | 5405 | 		rx_ring->count = vsi->num_desc; | 
 | 5406 | 		rx_ring->size = 0; | 
 | 5407 | 		rx_ring->dcb_tc = 0; | 
 | 5408 | 		if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) | 
 | 5409 | 			set_ring_16byte_desc_enabled(rx_ring); | 
 | 5410 | 		else | 
 | 5411 | 			clear_ring_16byte_desc_enabled(rx_ring); | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5412 | 		vsi->rx_rings[i] = rx_ring; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5413 | 	} | 
 | 5414 |  | 
 | 5415 | 	return 0; | 
| Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 5416 |  | 
 | 5417 | err_out: | 
 | 5418 | 	i40e_vsi_clear_rings(vsi); | 
 | 5419 | 	return -ENOMEM; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5420 | } | 
 | 5421 |  | 
 | 5422 | /** | 
 | 5423 |  * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel | 
 | 5424 |  * @pf: board private structure | 
 | 5425 |  * @vectors: the number of MSI-X vectors to request | 
 | 5426 |  * | 
 | 5427 |  * Returns the number of vectors reserved, or error | 
 | 5428 |  **/ | 
 | 5429 | static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors) | 
 | 5430 | { | 
 | 5431 | 	int err = 0; | 
 | 5432 |  | 
 | 5433 | 	pf->num_msix_entries = 0; | 
 | 5434 | 	while (vectors >= I40E_MIN_MSIX) { | 
 | 5435 | 		err = pci_enable_msix(pf->pdev, pf->msix_entries, vectors); | 
 | 5436 | 		if (err == 0) { | 
 | 5437 | 			/* good to go */ | 
 | 5438 | 			pf->num_msix_entries = vectors; | 
 | 5439 | 			break; | 
 | 5440 | 		} else if (err < 0) { | 
 | 5441 | 			/* total failure */ | 
 | 5442 | 			dev_info(&pf->pdev->dev, | 
 | 5443 | 				 "MSI-X vector reservation failed: %d\n", err); | 
 | 5444 | 			vectors = 0; | 
 | 5445 | 			break; | 
 | 5446 | 		} else { | 
 | 5447 | 			/* err > 0 is the hint for retry */ | 
 | 5448 | 			dev_info(&pf->pdev->dev, | 
 | 5449 | 				 "MSI-X vectors wanted %d, retrying with %d\n", | 
 | 5450 | 				 vectors, err); | 
 | 5451 | 			vectors = err; | 
 | 5452 | 		} | 
 | 5453 | 	} | 
 | 5454 |  | 
 | 5455 | 	if (vectors > 0 && vectors < I40E_MIN_MSIX) { | 
 | 5456 | 		dev_info(&pf->pdev->dev, | 
 | 5457 | 			 "Couldn't get enough vectors, only %d available\n", | 
 | 5458 | 			 vectors); | 
 | 5459 | 		vectors = 0; | 
 | 5460 | 	} | 
 | 5461 |  | 
 | 5462 | 	return vectors; | 
 | 5463 | } | 
 | 5464 |  | 
 | 5465 | /** | 
 | 5466 |  * i40e_init_msix - Setup the MSIX capability | 
 | 5467 |  * @pf: board private structure | 
 | 5468 |  * | 
 | 5469 |  * Work with the OS to set up the MSIX vectors needed. | 
 | 5470 |  * | 
 | 5471 |  * Returns 0 on success, negative on failure | 
 | 5472 |  **/ | 
 | 5473 | static int i40e_init_msix(struct i40e_pf *pf) | 
 | 5474 | { | 
 | 5475 | 	i40e_status err = 0; | 
 | 5476 | 	struct i40e_hw *hw = &pf->hw; | 
 | 5477 | 	int v_budget, i; | 
 | 5478 | 	int vec; | 
 | 5479 |  | 
 | 5480 | 	if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) | 
 | 5481 | 		return -ENODEV; | 
 | 5482 |  | 
 | 5483 | 	/* The number of vectors we'll request will be comprised of: | 
 | 5484 | 	 *   - Add 1 for "other" cause for Admin Queue events, etc. | 
 | 5485 | 	 *   - The number of LAN queue pairs | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5486 | 	 *	- Queues being used for RSS. | 
 | 5487 | 	 *		We don't need as many as max_rss_size vectors. | 
 | 5488 | 	 *		use rss_size instead in the calculation since that | 
 | 5489 | 	 *		is governed by number of cpus in the system. | 
 | 5490 | 	 *	- assumes symmetric Tx/Rx pairing | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5491 | 	 *   - The number of VMDq pairs | 
 | 5492 | 	 * Once we count this up, try the request. | 
 | 5493 | 	 * | 
 | 5494 | 	 * If we can't get what we want, we'll simplify to nearly nothing | 
 | 5495 | 	 * and try again.  If that still fails, we punt. | 
 | 5496 | 	 */ | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5497 | 	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] | 5498 | 	pf->num_vmdq_msix = pf->num_vmdq_qps; | 
 | 5499 | 	v_budget = 1 + pf->num_lan_msix; | 
 | 5500 | 	v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix); | 
 | 5501 | 	if (pf->flags & I40E_FLAG_FDIR_ENABLED) | 
 | 5502 | 		v_budget++; | 
 | 5503 |  | 
 | 5504 | 	/* Scale down if necessary, and the rings will share vectors */ | 
 | 5505 | 	v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors); | 
 | 5506 |  | 
 | 5507 | 	pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry), | 
 | 5508 | 				   GFP_KERNEL); | 
 | 5509 | 	if (!pf->msix_entries) | 
 | 5510 | 		return -ENOMEM; | 
 | 5511 |  | 
 | 5512 | 	for (i = 0; i < v_budget; i++) | 
 | 5513 | 		pf->msix_entries[i].entry = i; | 
 | 5514 | 	vec = i40e_reserve_msix_vectors(pf, v_budget); | 
 | 5515 | 	if (vec < I40E_MIN_MSIX) { | 
 | 5516 | 		pf->flags &= ~I40E_FLAG_MSIX_ENABLED; | 
 | 5517 | 		kfree(pf->msix_entries); | 
 | 5518 | 		pf->msix_entries = NULL; | 
 | 5519 | 		return -ENODEV; | 
 | 5520 |  | 
 | 5521 | 	} else if (vec == I40E_MIN_MSIX) { | 
 | 5522 | 		/* Adjust for minimal MSIX use */ | 
 | 5523 | 		dev_info(&pf->pdev->dev, "Features disabled, not enough MSIX vectors\n"); | 
 | 5524 | 		pf->flags &= ~I40E_FLAG_VMDQ_ENABLED; | 
 | 5525 | 		pf->num_vmdq_vsis = 0; | 
 | 5526 | 		pf->num_vmdq_qps = 0; | 
 | 5527 | 		pf->num_vmdq_msix = 0; | 
 | 5528 | 		pf->num_lan_qps = 1; | 
 | 5529 | 		pf->num_lan_msix = 1; | 
 | 5530 |  | 
 | 5531 | 	} else if (vec != v_budget) { | 
 | 5532 | 		/* Scale vector usage down */ | 
 | 5533 | 		pf->num_vmdq_msix = 1;    /* force VMDqs to only one vector */ | 
 | 5534 | 		vec--;                    /* reserve the misc vector */ | 
 | 5535 |  | 
 | 5536 | 		/* partition out the remaining vectors */ | 
 | 5537 | 		switch (vec) { | 
 | 5538 | 		case 2: | 
 | 5539 | 			pf->num_vmdq_vsis = 1; | 
 | 5540 | 			pf->num_lan_msix = 1; | 
 | 5541 | 			break; | 
 | 5542 | 		case 3: | 
 | 5543 | 			pf->num_vmdq_vsis = 1; | 
 | 5544 | 			pf->num_lan_msix = 2; | 
 | 5545 | 			break; | 
 | 5546 | 		default: | 
 | 5547 | 			pf->num_lan_msix = min_t(int, (vec / 2), | 
 | 5548 | 						 pf->num_lan_qps); | 
 | 5549 | 			pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix), | 
 | 5550 | 						  I40E_DEFAULT_NUM_VMDQ_VSI); | 
 | 5551 | 			break; | 
 | 5552 | 		} | 
 | 5553 | 	} | 
 | 5554 |  | 
 | 5555 | 	return err; | 
 | 5556 | } | 
 | 5557 |  | 
 | 5558 | /** | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5559 |  * i40e_alloc_q_vector - Allocate memory for a single interrupt vector | 
 | 5560 |  * @vsi: the VSI being configured | 
 | 5561 |  * @v_idx: index of the vector in the vsi struct | 
 | 5562 |  * | 
 | 5563 |  * We allocate one q_vector.  If allocation fails we return -ENOMEM. | 
 | 5564 |  **/ | 
 | 5565 | static int i40e_alloc_q_vector(struct i40e_vsi *vsi, int v_idx) | 
 | 5566 | { | 
 | 5567 | 	struct i40e_q_vector *q_vector; | 
 | 5568 |  | 
 | 5569 | 	/* allocate q_vector */ | 
 | 5570 | 	q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL); | 
 | 5571 | 	if (!q_vector) | 
 | 5572 | 		return -ENOMEM; | 
 | 5573 |  | 
 | 5574 | 	q_vector->vsi = vsi; | 
 | 5575 | 	q_vector->v_idx = v_idx; | 
 | 5576 | 	cpumask_set_cpu(v_idx, &q_vector->affinity_mask); | 
 | 5577 | 	if (vsi->netdev) | 
 | 5578 | 		netif_napi_add(vsi->netdev, &q_vector->napi, | 
 | 5579 | 			       i40e_napi_poll, vsi->work_limit); | 
 | 5580 |  | 
| Alexander Duyck | cd0b6fa | 2013-09-28 06:00:53 +0000 | [diff] [blame] | 5581 | 	q_vector->rx.latency_range = I40E_LOW_LATENCY; | 
 | 5582 | 	q_vector->tx.latency_range = I40E_LOW_LATENCY; | 
 | 5583 |  | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5584 | 	/* tie q_vector and vsi together */ | 
 | 5585 | 	vsi->q_vectors[v_idx] = q_vector; | 
 | 5586 |  | 
 | 5587 | 	return 0; | 
 | 5588 | } | 
 | 5589 |  | 
 | 5590 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5591 |  * i40e_alloc_q_vectors - Allocate memory for interrupt vectors | 
 | 5592 |  * @vsi: the VSI being configured | 
 | 5593 |  * | 
 | 5594 |  * We allocate one q_vector per queue interrupt.  If allocation fails we | 
 | 5595 |  * return -ENOMEM. | 
 | 5596 |  **/ | 
 | 5597 | static int i40e_alloc_q_vectors(struct i40e_vsi *vsi) | 
 | 5598 | { | 
 | 5599 | 	struct i40e_pf *pf = vsi->back; | 
 | 5600 | 	int v_idx, num_q_vectors; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5601 | 	int err; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5602 |  | 
 | 5603 | 	/* if not MSIX, give the one vector only to the LAN VSI */ | 
 | 5604 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) | 
 | 5605 | 		num_q_vectors = vsi->num_q_vectors; | 
 | 5606 | 	else if (vsi == pf->vsi[pf->lan_vsi]) | 
 | 5607 | 		num_q_vectors = 1; | 
 | 5608 | 	else | 
 | 5609 | 		return -EINVAL; | 
 | 5610 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5611 | 	for (v_idx = 0; v_idx < num_q_vectors; v_idx++) { | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5612 | 		err = i40e_alloc_q_vector(vsi, v_idx); | 
 | 5613 | 		if (err) | 
 | 5614 | 			goto err_out; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5615 | 	} | 
 | 5616 |  | 
 | 5617 | 	return 0; | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 5618 |  | 
 | 5619 | err_out: | 
 | 5620 | 	while (v_idx--) | 
 | 5621 | 		i40e_free_q_vector(vsi, v_idx); | 
 | 5622 |  | 
 | 5623 | 	return err; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5624 | } | 
 | 5625 |  | 
 | 5626 | /** | 
 | 5627 |  * i40e_init_interrupt_scheme - Determine proper interrupt scheme | 
 | 5628 |  * @pf: board private structure to initialize | 
 | 5629 |  **/ | 
 | 5630 | static void i40e_init_interrupt_scheme(struct i40e_pf *pf) | 
 | 5631 | { | 
 | 5632 | 	int err = 0; | 
 | 5633 |  | 
 | 5634 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 5635 | 		err = i40e_init_msix(pf); | 
 | 5636 | 		if (err) { | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5637 | 			pf->flags &= ~(I40E_FLAG_MSIX_ENABLED	   | | 
 | 5638 | 					I40E_FLAG_RSS_ENABLED	   | | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5639 | 					I40E_FLAG_DCB_ENABLED	   | | 
 | 5640 | 					I40E_FLAG_SRIOV_ENABLED	   | | 
 | 5641 | 					I40E_FLAG_FDIR_ENABLED	   | | 
 | 5642 | 					I40E_FLAG_FDIR_ATR_ENABLED | | 
 | 5643 | 					I40E_FLAG_VMDQ_ENABLED); | 
 | 5644 |  | 
 | 5645 | 			/* rework the queue expectations without MSIX */ | 
 | 5646 | 			i40e_determine_queue_usage(pf); | 
 | 5647 | 		} | 
 | 5648 | 	} | 
 | 5649 |  | 
 | 5650 | 	if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) && | 
 | 5651 | 	    (pf->flags & I40E_FLAG_MSI_ENABLED)) { | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5652 | 		dev_info(&pf->pdev->dev, "MSIX not available, trying MSI\n"); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5653 | 		err = pci_enable_msi(pf->pdev); | 
 | 5654 | 		if (err) { | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5655 | 			dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5656 | 			pf->flags &= ~I40E_FLAG_MSI_ENABLED; | 
 | 5657 | 		} | 
 | 5658 | 	} | 
 | 5659 |  | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 5660 | 	if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED))) | 
 | 5661 | 		dev_info(&pf->pdev->dev, "MSIX and MSI not available, falling back to Legacy IRQ\n"); | 
 | 5662 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5663 | 	/* track first vector for misc interrupts */ | 
 | 5664 | 	err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1); | 
 | 5665 | } | 
 | 5666 |  | 
 | 5667 | /** | 
 | 5668 |  * i40e_setup_misc_vector - Setup the misc vector to handle non queue events | 
 | 5669 |  * @pf: board private structure | 
 | 5670 |  * | 
 | 5671 |  * This sets up the handler for MSIX 0, which is used to manage the | 
 | 5672 |  * non-queue interrupts, e.g. AdminQ and errors.  This is not used | 
 | 5673 |  * when in MSI or Legacy interrupt mode. | 
 | 5674 |  **/ | 
 | 5675 | static int i40e_setup_misc_vector(struct i40e_pf *pf) | 
 | 5676 | { | 
 | 5677 | 	struct i40e_hw *hw = &pf->hw; | 
 | 5678 | 	int err = 0; | 
 | 5679 |  | 
 | 5680 | 	/* Only request the irq if this is the first time through, and | 
 | 5681 | 	 * not when we're rebuilding after a Reset | 
 | 5682 | 	 */ | 
 | 5683 | 	if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) { | 
 | 5684 | 		err = request_irq(pf->msix_entries[0].vector, | 
 | 5685 | 				  i40e_intr, 0, pf->misc_int_name, pf); | 
 | 5686 | 		if (err) { | 
 | 5687 | 			dev_info(&pf->pdev->dev, | 
 | 5688 | 				 "request_irq for msix_misc failed: %d\n", err); | 
 | 5689 | 			return -EFAULT; | 
 | 5690 | 		} | 
 | 5691 | 	} | 
 | 5692 |  | 
 | 5693 | 	i40e_enable_misc_int_causes(hw); | 
 | 5694 |  | 
 | 5695 | 	/* associate no queues to the misc vector */ | 
 | 5696 | 	wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST); | 
 | 5697 | 	wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K); | 
 | 5698 |  | 
 | 5699 | 	i40e_flush(hw); | 
 | 5700 |  | 
 | 5701 | 	i40e_irq_dynamic_enable_icr0(pf); | 
 | 5702 |  | 
 | 5703 | 	return err; | 
 | 5704 | } | 
 | 5705 |  | 
 | 5706 | /** | 
 | 5707 |  * i40e_config_rss - Prepare for RSS if used | 
 | 5708 |  * @pf: board private structure | 
 | 5709 |  **/ | 
 | 5710 | static int i40e_config_rss(struct i40e_pf *pf) | 
 | 5711 | { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5712 | 	/* Set of random keys generated using kernel random number generator */ | 
 | 5713 | 	static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687, | 
 | 5714 | 				0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377, | 
 | 5715 | 				0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d, | 
 | 5716 | 				0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be}; | 
| Anjali Singhai Jain | 4617e8c | 2013-11-20 10:02:56 +0000 | [diff] [blame] | 5717 | 	struct i40e_hw *hw = &pf->hw; | 
 | 5718 | 	u32 lut = 0; | 
 | 5719 | 	int i, j; | 
 | 5720 | 	u64 hena; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5721 |  | 
 | 5722 | 	/* Fill out hash function seed */ | 
 | 5723 | 	for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) | 
 | 5724 | 		wr32(hw, I40E_PFQF_HKEY(i), seed[i]); | 
 | 5725 |  | 
 | 5726 | 	/* By default we enable TCP/UDP with IPv4/IPv6 ptypes */ | 
 | 5727 | 	hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | | 
 | 5728 | 		((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); | 
| Mitch Williams | 12dc4fe | 2013-11-28 06:39:32 +0000 | [diff] [blame] | 5729 | 	hena |= I40E_DEFAULT_RSS_HENA; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5730 | 	wr32(hw, I40E_PFQF_HENA(0), (u32)hena); | 
 | 5731 | 	wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); | 
 | 5732 |  | 
 | 5733 | 	/* Populate the LUT with max no. of queues in round robin fashion */ | 
 | 5734 | 	for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) { | 
 | 5735 |  | 
 | 5736 | 		/* The assumption is that lan qp count will be the highest | 
 | 5737 | 		 * qp count for any PF VSI that needs RSS. | 
 | 5738 | 		 * If multiple VSIs need RSS support, all the qp counts | 
 | 5739 | 		 * for those VSIs should be a power of 2 for RSS to work. | 
 | 5740 | 		 * If LAN VSI is the only consumer for RSS then this requirement | 
 | 5741 | 		 * is not necessary. | 
 | 5742 | 		 */ | 
 | 5743 | 		if (j == pf->rss_size) | 
 | 5744 | 			j = 0; | 
 | 5745 | 		/* lut = 4-byte sliding window of 4 lut entries */ | 
 | 5746 | 		lut = (lut << 8) | (j & | 
 | 5747 | 			 ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1)); | 
 | 5748 | 		/* On i = 3, we have 4 entries in lut; write to the register */ | 
 | 5749 | 		if ((i & 3) == 3) | 
 | 5750 | 			wr32(hw, I40E_PFQF_HLUT(i >> 2), lut); | 
 | 5751 | 	} | 
 | 5752 | 	i40e_flush(hw); | 
 | 5753 |  | 
 | 5754 | 	return 0; | 
 | 5755 | } | 
 | 5756 |  | 
 | 5757 | /** | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5758 |  * i40e_reconfig_rss_queues - change number of queues for rss and rebuild | 
 | 5759 |  * @pf: board private structure | 
 | 5760 |  * @queue_count: the requested queue count for rss. | 
 | 5761 |  * | 
 | 5762 |  * returns 0 if rss is not enabled, if enabled returns the final rss queue | 
 | 5763 |  * count which may be different from the requested queue count. | 
 | 5764 |  **/ | 
 | 5765 | int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count) | 
 | 5766 | { | 
 | 5767 | 	if (!(pf->flags & I40E_FLAG_RSS_ENABLED)) | 
 | 5768 | 		return 0; | 
 | 5769 |  | 
 | 5770 | 	queue_count = min_t(int, queue_count, pf->rss_size_max); | 
 | 5771 | 	queue_count = rounddown_pow_of_two(queue_count); | 
 | 5772 |  | 
 | 5773 | 	if (queue_count != pf->rss_size) { | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5774 | 		i40e_prep_for_reset(pf); | 
 | 5775 |  | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 5776 | 		pf->rss_size = queue_count; | 
 | 5777 |  | 
 | 5778 | 		i40e_reset_and_rebuild(pf, true); | 
 | 5779 | 		i40e_config_rss(pf); | 
 | 5780 | 	} | 
 | 5781 | 	dev_info(&pf->pdev->dev, "RSS count:  %d\n", pf->rss_size); | 
 | 5782 | 	return pf->rss_size; | 
 | 5783 | } | 
 | 5784 |  | 
 | 5785 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5786 |  * i40e_sw_init - Initialize general software structures (struct i40e_pf) | 
 | 5787 |  * @pf: board private structure to initialize | 
 | 5788 |  * | 
 | 5789 |  * i40e_sw_init initializes the Adapter private data structure. | 
 | 5790 |  * Fields are initialized based on PCI device information and | 
 | 5791 |  * OS network device settings (MTU size). | 
 | 5792 |  **/ | 
 | 5793 | static int i40e_sw_init(struct i40e_pf *pf) | 
 | 5794 | { | 
 | 5795 | 	int err = 0; | 
 | 5796 | 	int size; | 
 | 5797 |  | 
 | 5798 | 	pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE, | 
 | 5799 | 				(NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)); | 
| Shannon Nelson | 2759997 | 2013-11-16 10:00:43 +0000 | [diff] [blame] | 5800 | 	pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5801 | 	if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) { | 
 | 5802 | 		if (I40E_DEBUG_USER & debug) | 
 | 5803 | 			pf->hw.debug_mask = debug; | 
 | 5804 | 		pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER), | 
 | 5805 | 						I40E_DEFAULT_MSG_ENABLE); | 
 | 5806 | 	} | 
 | 5807 |  | 
 | 5808 | 	/* Set default capability flags */ | 
 | 5809 | 	pf->flags = I40E_FLAG_RX_CSUM_ENABLED | | 
 | 5810 | 		    I40E_FLAG_MSI_ENABLED     | | 
 | 5811 | 		    I40E_FLAG_MSIX_ENABLED    | | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5812 | 		    I40E_FLAG_RX_1BUF_ENABLED; | 
 | 5813 |  | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 5814 | 	/* Depending on PF configurations, it is possible that the RSS | 
 | 5815 | 	 * maximum might end up larger than the available queues | 
 | 5816 | 	 */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5817 | 	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] | 5818 | 	pf->rss_size_max = min_t(int, pf->rss_size_max, | 
 | 5819 | 				 pf->hw.func_caps.num_tx_qp); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5820 | 	if (pf->hw.func_caps.rss) { | 
 | 5821 | 		pf->flags |= I40E_FLAG_RSS_ENABLED; | 
| Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 5822 | 		pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus()); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5823 | 	} else { | 
 | 5824 | 		pf->rss_size = 1; | 
 | 5825 | 	} | 
 | 5826 |  | 
 | 5827 | 	if (pf->hw.func_caps.dcb) | 
 | 5828 | 		pf->num_tc_qps = I40E_DEFAULT_QUEUES_PER_TC; | 
 | 5829 | 	else | 
 | 5830 | 		pf->num_tc_qps = 0; | 
 | 5831 |  | 
 | 5832 | 	if (pf->hw.func_caps.fd) { | 
 | 5833 | 		/* FW/NVM is not yet fixed in this regard */ | 
 | 5834 | 		if ((pf->hw.func_caps.fd_filters_guaranteed > 0) || | 
 | 5835 | 		    (pf->hw.func_caps.fd_filters_best_effort > 0)) { | 
 | 5836 | 			pf->flags |= I40E_FLAG_FDIR_ATR_ENABLED; | 
 | 5837 | 			dev_info(&pf->pdev->dev, | 
 | 5838 | 				 "Flow Director ATR mode Enabled\n"); | 
 | 5839 | 			pf->flags |= I40E_FLAG_FDIR_ENABLED; | 
 | 5840 | 			dev_info(&pf->pdev->dev, | 
 | 5841 | 				 "Flow Director Side Band mode Enabled\n"); | 
 | 5842 | 			pf->fdir_pf_filter_count = | 
 | 5843 | 					 pf->hw.func_caps.fd_filters_guaranteed; | 
 | 5844 | 		} | 
 | 5845 | 	} else { | 
 | 5846 | 		pf->fdir_pf_filter_count = 0; | 
 | 5847 | 	} | 
 | 5848 |  | 
 | 5849 | 	if (pf->hw.func_caps.vmdq) { | 
 | 5850 | 		pf->flags |= I40E_FLAG_VMDQ_ENABLED; | 
 | 5851 | 		pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI; | 
 | 5852 | 		pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ; | 
 | 5853 | 	} | 
 | 5854 |  | 
 | 5855 | 	/* MFP mode enabled */ | 
 | 5856 | 	if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) { | 
 | 5857 | 		pf->flags |= I40E_FLAG_MFP_ENABLED; | 
 | 5858 | 		dev_info(&pf->pdev->dev, "MFP mode Enabled\n"); | 
 | 5859 | 	} | 
 | 5860 |  | 
 | 5861 | #ifdef CONFIG_PCI_IOV | 
 | 5862 | 	if (pf->hw.func_caps.num_vfs) { | 
 | 5863 | 		pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF; | 
 | 5864 | 		pf->flags |= I40E_FLAG_SRIOV_ENABLED; | 
 | 5865 | 		pf->num_req_vfs = min_t(int, | 
 | 5866 | 					pf->hw.func_caps.num_vfs, | 
 | 5867 | 					I40E_MAX_VF_COUNT); | 
| Anjali Singhai Jain | 4a38d09 | 2013-11-20 10:03:00 +0000 | [diff] [blame] | 5868 | 		dev_info(&pf->pdev->dev, | 
 | 5869 | 			 "Number of VFs being requested for PF[%d] = %d\n", | 
 | 5870 | 			 pf->hw.pf_id, pf->num_req_vfs); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 5871 | 	} | 
 | 5872 | #endif /* CONFIG_PCI_IOV */ | 
 | 5873 | 	pf->eeprom_version = 0xDEAD; | 
 | 5874 | 	pf->lan_veb = I40E_NO_VEB; | 
 | 5875 | 	pf->lan_vsi = I40E_NO_VSI; | 
 | 5876 |  | 
 | 5877 | 	/* set up queue assignment tracking */ | 
 | 5878 | 	size = sizeof(struct i40e_lump_tracking) | 
 | 5879 | 		+ (sizeof(u16) * pf->hw.func_caps.num_tx_qp); | 
 | 5880 | 	pf->qp_pile = kzalloc(size, GFP_KERNEL); | 
 | 5881 | 	if (!pf->qp_pile) { | 
 | 5882 | 		err = -ENOMEM; | 
 | 5883 | 		goto sw_init_done; | 
 | 5884 | 	} | 
 | 5885 | 	pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp; | 
 | 5886 | 	pf->qp_pile->search_hint = 0; | 
 | 5887 |  | 
 | 5888 | 	/* set up vector assignment tracking */ | 
 | 5889 | 	size = sizeof(struct i40e_lump_tracking) | 
 | 5890 | 		+ (sizeof(u16) * pf->hw.func_caps.num_msix_vectors); | 
 | 5891 | 	pf->irq_pile = kzalloc(size, GFP_KERNEL); | 
 | 5892 | 	if (!pf->irq_pile) { | 
 | 5893 | 		kfree(pf->qp_pile); | 
 | 5894 | 		err = -ENOMEM; | 
 | 5895 | 		goto sw_init_done; | 
 | 5896 | 	} | 
 | 5897 | 	pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors; | 
 | 5898 | 	pf->irq_pile->search_hint = 0; | 
 | 5899 |  | 
 | 5900 | 	mutex_init(&pf->switch_mutex); | 
 | 5901 |  | 
 | 5902 | sw_init_done: | 
 | 5903 | 	return err; | 
 | 5904 | } | 
 | 5905 |  | 
 | 5906 | /** | 
 | 5907 |  * i40e_set_features - set the netdev feature flags | 
 | 5908 |  * @netdev: ptr to the netdev being adjusted | 
 | 5909 |  * @features: the feature set that the stack is suggesting | 
 | 5910 |  **/ | 
 | 5911 | static int i40e_set_features(struct net_device *netdev, | 
 | 5912 | 			     netdev_features_t features) | 
 | 5913 | { | 
 | 5914 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 5915 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 5916 |  | 
 | 5917 | 	if (features & NETIF_F_HW_VLAN_CTAG_RX) | 
 | 5918 | 		i40e_vlan_stripping_enable(vsi); | 
 | 5919 | 	else | 
 | 5920 | 		i40e_vlan_stripping_disable(vsi); | 
 | 5921 |  | 
 | 5922 | 	return 0; | 
 | 5923 | } | 
 | 5924 |  | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 5925 | #ifdef CONFIG_I40E_VXLAN | 
 | 5926 | /** | 
 | 5927 |  * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port | 
 | 5928 |  * @pf: board private structure | 
 | 5929 |  * @port: The UDP port to look up | 
 | 5930 |  * | 
 | 5931 |  * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found | 
 | 5932 |  **/ | 
 | 5933 | static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port) | 
 | 5934 | { | 
 | 5935 | 	u8 i; | 
 | 5936 |  | 
 | 5937 | 	for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) { | 
 | 5938 | 		if (pf->vxlan_ports[i] == port) | 
 | 5939 | 			return i; | 
 | 5940 | 	} | 
 | 5941 |  | 
 | 5942 | 	return i; | 
 | 5943 | } | 
 | 5944 |  | 
 | 5945 | /** | 
 | 5946 |  * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up | 
 | 5947 |  * @netdev: This physical port's netdev | 
 | 5948 |  * @sa_family: Socket Family that VXLAN is notifying us about | 
 | 5949 |  * @port: New UDP port number that VXLAN started listening to | 
 | 5950 |  **/ | 
 | 5951 | static void i40e_add_vxlan_port(struct net_device *netdev, | 
 | 5952 | 				sa_family_t sa_family, __be16 port) | 
 | 5953 | { | 
 | 5954 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 5955 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 5956 | 	struct i40e_pf *pf = vsi->back; | 
 | 5957 | 	u8 next_idx; | 
 | 5958 | 	u8 idx; | 
 | 5959 |  | 
 | 5960 | 	if (sa_family == AF_INET6) | 
 | 5961 | 		return; | 
 | 5962 |  | 
 | 5963 | 	idx = i40e_get_vxlan_port_idx(pf, port); | 
 | 5964 |  | 
 | 5965 | 	/* Check if port already exists */ | 
 | 5966 | 	if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | 
 | 5967 | 		netdev_info(netdev, "Port %d already offloaded\n", ntohs(port)); | 
 | 5968 | 		return; | 
 | 5969 | 	} | 
 | 5970 |  | 
 | 5971 | 	/* Now check if there is space to add the new port */ | 
 | 5972 | 	next_idx = i40e_get_vxlan_port_idx(pf, 0); | 
 | 5973 |  | 
 | 5974 | 	if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | 
 | 5975 | 		netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n", | 
 | 5976 | 			    ntohs(port)); | 
 | 5977 | 		return; | 
 | 5978 | 	} | 
 | 5979 |  | 
 | 5980 | 	/* New port: add it and mark its index in the bitmap */ | 
 | 5981 | 	pf->vxlan_ports[next_idx] = port; | 
 | 5982 | 	pf->pending_vxlan_bitmap |= (1 << next_idx); | 
 | 5983 |  | 
 | 5984 | 	pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; | 
 | 5985 | } | 
 | 5986 |  | 
 | 5987 | /** | 
 | 5988 |  * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away | 
 | 5989 |  * @netdev: This physical port's netdev | 
 | 5990 |  * @sa_family: Socket Family that VXLAN is notifying us about | 
 | 5991 |  * @port: UDP port number that VXLAN stopped listening to | 
 | 5992 |  **/ | 
 | 5993 | static void i40e_del_vxlan_port(struct net_device *netdev, | 
 | 5994 | 				sa_family_t sa_family, __be16 port) | 
 | 5995 | { | 
 | 5996 | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 
 | 5997 | 	struct i40e_vsi *vsi = np->vsi; | 
 | 5998 | 	struct i40e_pf *pf = vsi->back; | 
 | 5999 | 	u8 idx; | 
 | 6000 |  | 
 | 6001 | 	if (sa_family == AF_INET6) | 
 | 6002 | 		return; | 
 | 6003 |  | 
 | 6004 | 	idx = i40e_get_vxlan_port_idx(pf, port); | 
 | 6005 |  | 
 | 6006 | 	/* Check if port already exists */ | 
 | 6007 | 	if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) { | 
 | 6008 | 		/* if port exists, set it to 0 (mark for deletion) | 
 | 6009 | 		 * and make it pending | 
 | 6010 | 		 */ | 
 | 6011 | 		pf->vxlan_ports[idx] = 0; | 
 | 6012 |  | 
 | 6013 | 		pf->pending_vxlan_bitmap |= (1 << idx); | 
 | 6014 |  | 
 | 6015 | 		pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC; | 
 | 6016 | 	} else { | 
 | 6017 | 		netdev_warn(netdev, "Port %d was not found, not deleting\n", | 
 | 6018 | 			    ntohs(port)); | 
 | 6019 | 	} | 
 | 6020 | } | 
 | 6021 |  | 
 | 6022 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6023 | static const struct net_device_ops i40e_netdev_ops = { | 
 | 6024 | 	.ndo_open		= i40e_open, | 
 | 6025 | 	.ndo_stop		= i40e_close, | 
 | 6026 | 	.ndo_start_xmit		= i40e_lan_xmit_frame, | 
 | 6027 | 	.ndo_get_stats64	= i40e_get_netdev_stats_struct, | 
 | 6028 | 	.ndo_set_rx_mode	= i40e_set_rx_mode, | 
 | 6029 | 	.ndo_validate_addr	= eth_validate_addr, | 
 | 6030 | 	.ndo_set_mac_address	= i40e_set_mac, | 
 | 6031 | 	.ndo_change_mtu		= i40e_change_mtu, | 
 | 6032 | 	.ndo_tx_timeout		= i40e_tx_timeout, | 
 | 6033 | 	.ndo_vlan_rx_add_vid	= i40e_vlan_rx_add_vid, | 
 | 6034 | 	.ndo_vlan_rx_kill_vid	= i40e_vlan_rx_kill_vid, | 
 | 6035 | #ifdef CONFIG_NET_POLL_CONTROLLER | 
 | 6036 | 	.ndo_poll_controller	= i40e_netpoll, | 
 | 6037 | #endif | 
 | 6038 | 	.ndo_setup_tc		= i40e_setup_tc, | 
 | 6039 | 	.ndo_set_features	= i40e_set_features, | 
 | 6040 | 	.ndo_set_vf_mac		= i40e_ndo_set_vf_mac, | 
 | 6041 | 	.ndo_set_vf_vlan	= i40e_ndo_set_vf_port_vlan, | 
 | 6042 | 	.ndo_set_vf_tx_rate	= i40e_ndo_set_vf_bw, | 
 | 6043 | 	.ndo_get_vf_config	= i40e_ndo_get_vf_config, | 
| Jeff Kirsher | a1c9a9d | 2013-12-28 07:32:18 +0000 | [diff] [blame] | 6044 | #ifdef CONFIG_I40E_VXLAN | 
 | 6045 | 	.ndo_add_vxlan_port	= i40e_add_vxlan_port, | 
 | 6046 | 	.ndo_del_vxlan_port	= i40e_del_vxlan_port, | 
 | 6047 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6048 | }; | 
 | 6049 |  | 
 | 6050 | /** | 
 | 6051 |  * i40e_config_netdev - Setup the netdev flags | 
 | 6052 |  * @vsi: the VSI being configured | 
 | 6053 |  * | 
 | 6054 |  * Returns 0 on success, negative value on failure | 
 | 6055 |  **/ | 
 | 6056 | static int i40e_config_netdev(struct i40e_vsi *vsi) | 
 | 6057 | { | 
| Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 6058 | 	u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6059 | 	struct i40e_pf *pf = vsi->back; | 
 | 6060 | 	struct i40e_hw *hw = &pf->hw; | 
 | 6061 | 	struct i40e_netdev_priv *np; | 
 | 6062 | 	struct net_device *netdev; | 
 | 6063 | 	u8 mac_addr[ETH_ALEN]; | 
 | 6064 | 	int etherdev_size; | 
 | 6065 |  | 
 | 6066 | 	etherdev_size = sizeof(struct i40e_netdev_priv); | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 6067 | 	netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6068 | 	if (!netdev) | 
 | 6069 | 		return -ENOMEM; | 
 | 6070 |  | 
 | 6071 | 	vsi->netdev = netdev; | 
 | 6072 | 	np = netdev_priv(netdev); | 
 | 6073 | 	np->vsi = vsi; | 
 | 6074 |  | 
 | 6075 | 	netdev->hw_enc_features = NETIF_F_IP_CSUM	 | | 
 | 6076 | 				  NETIF_F_GSO_UDP_TUNNEL | | 
 | 6077 | 				  NETIF_F_TSO		 | | 
 | 6078 | 				  NETIF_F_SG; | 
 | 6079 |  | 
 | 6080 | 	netdev->features = NETIF_F_SG		       | | 
 | 6081 | 			   NETIF_F_IP_CSUM	       | | 
 | 6082 | 			   NETIF_F_SCTP_CSUM	       | | 
 | 6083 | 			   NETIF_F_HIGHDMA	       | | 
 | 6084 | 			   NETIF_F_GSO_UDP_TUNNEL      | | 
 | 6085 | 			   NETIF_F_HW_VLAN_CTAG_TX     | | 
 | 6086 | 			   NETIF_F_HW_VLAN_CTAG_RX     | | 
 | 6087 | 			   NETIF_F_HW_VLAN_CTAG_FILTER | | 
 | 6088 | 			   NETIF_F_IPV6_CSUM	       | | 
 | 6089 | 			   NETIF_F_TSO		       | | 
 | 6090 | 			   NETIF_F_TSO6		       | | 
 | 6091 | 			   NETIF_F_RXCSUM	       | | 
 | 6092 | 			   NETIF_F_RXHASH	       | | 
 | 6093 | 			   0; | 
 | 6094 |  | 
 | 6095 | 	/* copy netdev features into list of user selectable features */ | 
 | 6096 | 	netdev->hw_features |= netdev->features; | 
 | 6097 |  | 
 | 6098 | 	if (vsi->type == I40E_VSI_MAIN) { | 
 | 6099 | 		SET_NETDEV_DEV(netdev, &pf->pdev->dev); | 
 | 6100 | 		memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); | 
 | 6101 | 	} else { | 
 | 6102 | 		/* relate the VSI_VMDQ name to the VSI_MAIN name */ | 
 | 6103 | 		snprintf(netdev->name, IFNAMSIZ, "%sv%%d", | 
 | 6104 | 			 pf->vsi[pf->lan_vsi]->netdev->name); | 
 | 6105 | 		random_ether_addr(mac_addr); | 
 | 6106 | 		i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false); | 
 | 6107 | 	} | 
| Greg Rose | 1a10370 | 2013-11-28 06:42:39 +0000 | [diff] [blame] | 6108 | 	i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6109 |  | 
 | 6110 | 	memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); | 
 | 6111 | 	memcpy(netdev->perm_addr, mac_addr, ETH_ALEN); | 
 | 6112 | 	/* vlan gets same features (except vlan offload) | 
 | 6113 | 	 * after any tweaks for specific VSI types | 
 | 6114 | 	 */ | 
 | 6115 | 	netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX | | 
 | 6116 | 						     NETIF_F_HW_VLAN_CTAG_RX | | 
 | 6117 | 						   NETIF_F_HW_VLAN_CTAG_FILTER); | 
 | 6118 | 	netdev->priv_flags |= IFF_UNICAST_FLT; | 
 | 6119 | 	netdev->priv_flags |= IFF_SUPP_NOFCS; | 
 | 6120 | 	/* Setup netdev TC information */ | 
 | 6121 | 	i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc); | 
 | 6122 |  | 
 | 6123 | 	netdev->netdev_ops = &i40e_netdev_ops; | 
 | 6124 | 	netdev->watchdog_timeo = 5 * HZ; | 
 | 6125 | 	i40e_set_ethtool_ops(netdev); | 
 | 6126 |  | 
 | 6127 | 	return 0; | 
 | 6128 | } | 
 | 6129 |  | 
 | 6130 | /** | 
 | 6131 |  * i40e_vsi_delete - Delete a VSI from the switch | 
 | 6132 |  * @vsi: the VSI being removed | 
 | 6133 |  * | 
 | 6134 |  * Returns 0 on success, negative value on failure | 
 | 6135 |  **/ | 
 | 6136 | static void i40e_vsi_delete(struct i40e_vsi *vsi) | 
 | 6137 | { | 
 | 6138 | 	/* remove default VSI is not allowed */ | 
 | 6139 | 	if (vsi == vsi->back->vsi[vsi->back->lan_vsi]) | 
 | 6140 | 		return; | 
 | 6141 |  | 
 | 6142 | 	/* there is no HW VSI for FDIR */ | 
 | 6143 | 	if (vsi->type == I40E_VSI_FDIR) | 
 | 6144 | 		return; | 
 | 6145 |  | 
 | 6146 | 	i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL); | 
 | 6147 | 	return; | 
 | 6148 | } | 
 | 6149 |  | 
 | 6150 | /** | 
 | 6151 |  * i40e_add_vsi - Add a VSI to the switch | 
 | 6152 |  * @vsi: the VSI being configured | 
 | 6153 |  * | 
 | 6154 |  * This initializes a VSI context depending on the VSI type to be added and | 
 | 6155 |  * passes it down to the add_vsi aq command. | 
 | 6156 |  **/ | 
 | 6157 | static int i40e_add_vsi(struct i40e_vsi *vsi) | 
 | 6158 | { | 
 | 6159 | 	int ret = -ENODEV; | 
 | 6160 | 	struct i40e_mac_filter *f, *ftmp; | 
 | 6161 | 	struct i40e_pf *pf = vsi->back; | 
 | 6162 | 	struct i40e_hw *hw = &pf->hw; | 
 | 6163 | 	struct i40e_vsi_context ctxt; | 
 | 6164 | 	u8 enabled_tc = 0x1; /* TC0 enabled */ | 
 | 6165 | 	int f_count = 0; | 
 | 6166 |  | 
 | 6167 | 	memset(&ctxt, 0, sizeof(ctxt)); | 
 | 6168 | 	switch (vsi->type) { | 
 | 6169 | 	case I40E_VSI_MAIN: | 
 | 6170 | 		/* The PF's main VSI is already setup as part of the | 
 | 6171 | 		 * device initialization, so we'll not bother with | 
 | 6172 | 		 * the add_vsi call, but we will retrieve the current | 
 | 6173 | 		 * VSI context. | 
 | 6174 | 		 */ | 
 | 6175 | 		ctxt.seid = pf->main_vsi_seid; | 
 | 6176 | 		ctxt.pf_num = pf->hw.pf_id; | 
 | 6177 | 		ctxt.vf_num = 0; | 
 | 6178 | 		ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL); | 
 | 6179 | 		ctxt.flags = I40E_AQ_VSI_TYPE_PF; | 
 | 6180 | 		if (ret) { | 
 | 6181 | 			dev_info(&pf->pdev->dev, | 
 | 6182 | 				 "couldn't get pf vsi config, err %d, aq_err %d\n", | 
 | 6183 | 				 ret, pf->hw.aq.asq_last_status); | 
 | 6184 | 			return -ENOENT; | 
 | 6185 | 		} | 
 | 6186 | 		memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); | 
 | 6187 | 		vsi->info.valid_sections = 0; | 
 | 6188 |  | 
 | 6189 | 		vsi->seid = ctxt.seid; | 
 | 6190 | 		vsi->id = ctxt.vsi_number; | 
 | 6191 |  | 
 | 6192 | 		enabled_tc = i40e_pf_get_tc_map(pf); | 
 | 6193 |  | 
 | 6194 | 		/* MFP mode setup queue map and update VSI */ | 
 | 6195 | 		if (pf->flags & I40E_FLAG_MFP_ENABLED) { | 
 | 6196 | 			memset(&ctxt, 0, sizeof(ctxt)); | 
 | 6197 | 			ctxt.seid = pf->main_vsi_seid; | 
 | 6198 | 			ctxt.pf_num = pf->hw.pf_id; | 
 | 6199 | 			ctxt.vf_num = 0; | 
 | 6200 | 			i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false); | 
 | 6201 | 			ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); | 
 | 6202 | 			if (ret) { | 
 | 6203 | 				dev_info(&pf->pdev->dev, | 
 | 6204 | 					 "update vsi failed, aq_err=%d\n", | 
 | 6205 | 					 pf->hw.aq.asq_last_status); | 
 | 6206 | 				ret = -ENOENT; | 
 | 6207 | 				goto err; | 
 | 6208 | 			} | 
 | 6209 | 			/* update the local VSI info queue map */ | 
 | 6210 | 			i40e_vsi_update_queue_map(vsi, &ctxt); | 
 | 6211 | 			vsi->info.valid_sections = 0; | 
 | 6212 | 		} else { | 
 | 6213 | 			/* Default/Main VSI is only enabled for TC0 | 
 | 6214 | 			 * reconfigure it to enable all TCs that are | 
 | 6215 | 			 * available on the port in SFP mode. | 
 | 6216 | 			 */ | 
 | 6217 | 			ret = i40e_vsi_config_tc(vsi, enabled_tc); | 
 | 6218 | 			if (ret) { | 
 | 6219 | 				dev_info(&pf->pdev->dev, | 
 | 6220 | 					 "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n", | 
 | 6221 | 					 enabled_tc, ret, | 
 | 6222 | 					 pf->hw.aq.asq_last_status); | 
 | 6223 | 				ret = -ENOENT; | 
 | 6224 | 			} | 
 | 6225 | 		} | 
 | 6226 | 		break; | 
 | 6227 |  | 
 | 6228 | 	case I40E_VSI_FDIR: | 
 | 6229 | 		/* no queue mapping or actual HW VSI needed */ | 
 | 6230 | 		vsi->info.valid_sections = 0; | 
 | 6231 | 		vsi->seid = 0; | 
 | 6232 | 		vsi->id = 0; | 
 | 6233 | 		i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | 
 | 6234 | 		return 0; | 
 | 6235 | 		break; | 
 | 6236 |  | 
 | 6237 | 	case I40E_VSI_VMDQ2: | 
 | 6238 | 		ctxt.pf_num = hw->pf_id; | 
 | 6239 | 		ctxt.vf_num = 0; | 
 | 6240 | 		ctxt.uplink_seid = vsi->uplink_seid; | 
 | 6241 | 		ctxt.connection_type = 0x1;     /* regular data port */ | 
 | 6242 | 		ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2; | 
 | 6243 |  | 
 | 6244 | 		ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | 
 | 6245 |  | 
 | 6246 | 		/* This VSI is connected to VEB so the switch_id | 
 | 6247 | 		 * should be set to zero by default. | 
 | 6248 | 		 */ | 
 | 6249 | 		ctxt.info.switch_id = 0; | 
 | 6250 | 		ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB); | 
 | 6251 | 		ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | 
 | 6252 |  | 
 | 6253 | 		/* Setup the VSI tx/rx queue map for TC0 only for now */ | 
 | 6254 | 		i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | 
 | 6255 | 		break; | 
 | 6256 |  | 
 | 6257 | 	case I40E_VSI_SRIOV: | 
 | 6258 | 		ctxt.pf_num = hw->pf_id; | 
 | 6259 | 		ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id; | 
 | 6260 | 		ctxt.uplink_seid = vsi->uplink_seid; | 
 | 6261 | 		ctxt.connection_type = 0x1;     /* regular data port */ | 
 | 6262 | 		ctxt.flags = I40E_AQ_VSI_TYPE_VF; | 
 | 6263 |  | 
 | 6264 | 		ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID); | 
 | 6265 |  | 
 | 6266 | 		/* This VSI is connected to VEB so the switch_id | 
 | 6267 | 		 * should be set to zero by default. | 
 | 6268 | 		 */ | 
 | 6269 | 		ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB); | 
 | 6270 |  | 
 | 6271 | 		ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID); | 
 | 6272 | 		ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL; | 
 | 6273 | 		/* Setup the VSI tx/rx queue map for TC0 only for now */ | 
 | 6274 | 		i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true); | 
 | 6275 | 		break; | 
 | 6276 |  | 
 | 6277 | 	default: | 
 | 6278 | 		return -ENODEV; | 
 | 6279 | 	} | 
 | 6280 |  | 
 | 6281 | 	if (vsi->type != I40E_VSI_MAIN) { | 
 | 6282 | 		ret = i40e_aq_add_vsi(hw, &ctxt, NULL); | 
 | 6283 | 		if (ret) { | 
 | 6284 | 			dev_info(&vsi->back->pdev->dev, | 
 | 6285 | 				 "add vsi failed, aq_err=%d\n", | 
 | 6286 | 				 vsi->back->hw.aq.asq_last_status); | 
 | 6287 | 			ret = -ENOENT; | 
 | 6288 | 			goto err; | 
 | 6289 | 		} | 
 | 6290 | 		memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info)); | 
 | 6291 | 		vsi->info.valid_sections = 0; | 
 | 6292 | 		vsi->seid = ctxt.seid; | 
 | 6293 | 		vsi->id = ctxt.vsi_number; | 
 | 6294 | 	} | 
 | 6295 |  | 
 | 6296 | 	/* If macvlan filters already exist, force them to get loaded */ | 
 | 6297 | 	list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) { | 
 | 6298 | 		f->changed = true; | 
 | 6299 | 		f_count++; | 
 | 6300 | 	} | 
 | 6301 | 	if (f_count) { | 
 | 6302 | 		vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED; | 
 | 6303 | 		pf->flags |= I40E_FLAG_FILTER_SYNC; | 
 | 6304 | 	} | 
 | 6305 |  | 
 | 6306 | 	/* Update VSI BW information */ | 
 | 6307 | 	ret = i40e_vsi_get_bw_info(vsi); | 
 | 6308 | 	if (ret) { | 
 | 6309 | 		dev_info(&pf->pdev->dev, | 
 | 6310 | 			 "couldn't get vsi bw info, err %d, aq_err %d\n", | 
 | 6311 | 			 ret, pf->hw.aq.asq_last_status); | 
 | 6312 | 		/* VSI is already added so not tearing that up */ | 
 | 6313 | 		ret = 0; | 
 | 6314 | 	} | 
 | 6315 |  | 
 | 6316 | err: | 
 | 6317 | 	return ret; | 
 | 6318 | } | 
 | 6319 |  | 
 | 6320 | /** | 
 | 6321 |  * i40e_vsi_release - Delete a VSI and free its resources | 
 | 6322 |  * @vsi: the VSI being removed | 
 | 6323 |  * | 
 | 6324 |  * Returns 0 on success or < 0 on error | 
 | 6325 |  **/ | 
 | 6326 | int i40e_vsi_release(struct i40e_vsi *vsi) | 
 | 6327 | { | 
 | 6328 | 	struct i40e_mac_filter *f, *ftmp; | 
 | 6329 | 	struct i40e_veb *veb = NULL; | 
 | 6330 | 	struct i40e_pf *pf; | 
 | 6331 | 	u16 uplink_seid; | 
 | 6332 | 	int i, n; | 
 | 6333 |  | 
 | 6334 | 	pf = vsi->back; | 
 | 6335 |  | 
 | 6336 | 	/* release of a VEB-owner or last VSI is not allowed */ | 
 | 6337 | 	if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) { | 
 | 6338 | 		dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n", | 
 | 6339 | 			 vsi->seid, vsi->uplink_seid); | 
 | 6340 | 		return -ENODEV; | 
 | 6341 | 	} | 
 | 6342 | 	if (vsi == pf->vsi[pf->lan_vsi] && | 
 | 6343 | 	    !test_bit(__I40E_DOWN, &pf->state)) { | 
 | 6344 | 		dev_info(&pf->pdev->dev, "Can't remove PF VSI\n"); | 
 | 6345 | 		return -ENODEV; | 
 | 6346 | 	} | 
 | 6347 |  | 
 | 6348 | 	uplink_seid = vsi->uplink_seid; | 
 | 6349 | 	if (vsi->type != I40E_VSI_SRIOV) { | 
 | 6350 | 		if (vsi->netdev_registered) { | 
 | 6351 | 			vsi->netdev_registered = false; | 
 | 6352 | 			if (vsi->netdev) { | 
 | 6353 | 				/* results in a call to i40e_close() */ | 
 | 6354 | 				unregister_netdev(vsi->netdev); | 
 | 6355 | 				free_netdev(vsi->netdev); | 
 | 6356 | 				vsi->netdev = NULL; | 
 | 6357 | 			} | 
 | 6358 | 		} else { | 
 | 6359 | 			if (!test_and_set_bit(__I40E_DOWN, &vsi->state)) | 
 | 6360 | 				i40e_down(vsi); | 
 | 6361 | 			i40e_vsi_free_irq(vsi); | 
 | 6362 | 			i40e_vsi_free_tx_resources(vsi); | 
 | 6363 | 			i40e_vsi_free_rx_resources(vsi); | 
 | 6364 | 		} | 
 | 6365 | 		i40e_vsi_disable_irq(vsi); | 
 | 6366 | 	} | 
 | 6367 |  | 
 | 6368 | 	list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) | 
 | 6369 | 		i40e_del_filter(vsi, f->macaddr, f->vlan, | 
 | 6370 | 				f->is_vf, f->is_netdev); | 
 | 6371 | 	i40e_sync_vsi_filters(vsi); | 
 | 6372 |  | 
 | 6373 | 	i40e_vsi_delete(vsi); | 
 | 6374 | 	i40e_vsi_free_q_vectors(vsi); | 
 | 6375 | 	i40e_vsi_clear_rings(vsi); | 
 | 6376 | 	i40e_vsi_clear(vsi); | 
 | 6377 |  | 
 | 6378 | 	/* If this was the last thing on the VEB, except for the | 
 | 6379 | 	 * controlling VSI, remove the VEB, which puts the controlling | 
 | 6380 | 	 * VSI onto the next level down in the switch. | 
 | 6381 | 	 * | 
 | 6382 | 	 * Well, okay, there's one more exception here: don't remove | 
 | 6383 | 	 * the orphan VEBs yet.  We'll wait for an explicit remove request | 
 | 6384 | 	 * from up the network stack. | 
 | 6385 | 	 */ | 
 | 6386 | 	for (n = 0, i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 6387 | 		if (pf->vsi[i] && | 
 | 6388 | 		    pf->vsi[i]->uplink_seid == uplink_seid && | 
 | 6389 | 		    (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | 
 | 6390 | 			n++;      /* count the VSIs */ | 
 | 6391 | 		} | 
 | 6392 | 	} | 
 | 6393 | 	for (i = 0; i < I40E_MAX_VEB; i++) { | 
 | 6394 | 		if (!pf->veb[i]) | 
 | 6395 | 			continue; | 
 | 6396 | 		if (pf->veb[i]->uplink_seid == uplink_seid) | 
 | 6397 | 			n++;     /* count the VEBs */ | 
 | 6398 | 		if (pf->veb[i]->seid == uplink_seid) | 
 | 6399 | 			veb = pf->veb[i]; | 
 | 6400 | 	} | 
 | 6401 | 	if (n == 0 && veb && veb->uplink_seid != 0) | 
 | 6402 | 		i40e_veb_release(veb); | 
 | 6403 |  | 
 | 6404 | 	return 0; | 
 | 6405 | } | 
 | 6406 |  | 
 | 6407 | /** | 
 | 6408 |  * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI | 
 | 6409 |  * @vsi: ptr to the VSI | 
 | 6410 |  * | 
 | 6411 |  * This should only be called after i40e_vsi_mem_alloc() which allocates the | 
 | 6412 |  * corresponding SW VSI structure and initializes num_queue_pairs for the | 
 | 6413 |  * newly allocated VSI. | 
 | 6414 |  * | 
 | 6415 |  * Returns 0 on success or negative on failure | 
 | 6416 |  **/ | 
 | 6417 | static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi) | 
 | 6418 | { | 
 | 6419 | 	int ret = -ENOENT; | 
 | 6420 | 	struct i40e_pf *pf = vsi->back; | 
 | 6421 |  | 
| Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 6422 | 	if (vsi->q_vectors[0]) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6423 | 		dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n", | 
 | 6424 | 			 vsi->seid); | 
 | 6425 | 		return -EEXIST; | 
 | 6426 | 	} | 
 | 6427 |  | 
 | 6428 | 	if (vsi->base_vector) { | 
 | 6429 | 		dev_info(&pf->pdev->dev, | 
 | 6430 | 			 "VSI %d has non-zero base vector %d\n", | 
 | 6431 | 			 vsi->seid, vsi->base_vector); | 
 | 6432 | 		return -EEXIST; | 
 | 6433 | 	} | 
 | 6434 |  | 
 | 6435 | 	ret = i40e_alloc_q_vectors(vsi); | 
 | 6436 | 	if (ret) { | 
 | 6437 | 		dev_info(&pf->pdev->dev, | 
 | 6438 | 			 "failed to allocate %d q_vector for VSI %d, ret=%d\n", | 
 | 6439 | 			 vsi->num_q_vectors, vsi->seid, ret); | 
 | 6440 | 		vsi->num_q_vectors = 0; | 
 | 6441 | 		goto vector_setup_out; | 
 | 6442 | 	} | 
 | 6443 |  | 
| Shannon Nelson | 958a3e3 | 2013-09-28 07:13:28 +0000 | [diff] [blame] | 6444 | 	if (vsi->num_q_vectors) | 
 | 6445 | 		vsi->base_vector = i40e_get_lump(pf, pf->irq_pile, | 
 | 6446 | 						 vsi->num_q_vectors, vsi->idx); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6447 | 	if (vsi->base_vector < 0) { | 
 | 6448 | 		dev_info(&pf->pdev->dev, | 
 | 6449 | 			 "failed to get q tracking for VSI %d, err=%d\n", | 
 | 6450 | 			 vsi->seid, vsi->base_vector); | 
 | 6451 | 		i40e_vsi_free_q_vectors(vsi); | 
 | 6452 | 		ret = -ENOENT; | 
 | 6453 | 		goto vector_setup_out; | 
 | 6454 | 	} | 
 | 6455 |  | 
 | 6456 | vector_setup_out: | 
 | 6457 | 	return ret; | 
 | 6458 | } | 
 | 6459 |  | 
 | 6460 | /** | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 6461 |  * i40e_vsi_reinit_setup - return and reallocate resources for a VSI | 
 | 6462 |  * @vsi: pointer to the vsi. | 
 | 6463 |  * | 
 | 6464 |  * This re-allocates a vsi's queue resources. | 
 | 6465 |  * | 
 | 6466 |  * Returns pointer to the successfully allocated and configured VSI sw struct | 
 | 6467 |  * on success, otherwise returns NULL on failure. | 
 | 6468 |  **/ | 
 | 6469 | static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi) | 
 | 6470 | { | 
 | 6471 | 	struct i40e_pf *pf = vsi->back; | 
 | 6472 | 	u8 enabled_tc; | 
 | 6473 | 	int ret; | 
 | 6474 |  | 
 | 6475 | 	i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx); | 
 | 6476 | 	i40e_vsi_clear_rings(vsi); | 
 | 6477 |  | 
 | 6478 | 	i40e_vsi_free_arrays(vsi, false); | 
 | 6479 | 	i40e_set_num_rings_in_vsi(vsi); | 
 | 6480 | 	ret = i40e_vsi_alloc_arrays(vsi, false); | 
 | 6481 | 	if (ret) | 
 | 6482 | 		goto err_vsi; | 
 | 6483 |  | 
 | 6484 | 	ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); | 
 | 6485 | 	if (ret < 0) { | 
 | 6486 | 		dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", | 
 | 6487 | 			 vsi->seid, ret); | 
 | 6488 | 		goto err_vsi; | 
 | 6489 | 	} | 
 | 6490 | 	vsi->base_queue = ret; | 
 | 6491 |  | 
 | 6492 | 	/* Update the FW view of the VSI. Force a reset of TC and queue | 
 | 6493 | 	 * layout configurations. | 
 | 6494 | 	 */ | 
 | 6495 | 	enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | 
 | 6496 | 	pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; | 
 | 6497 | 	pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | 
 | 6498 | 	i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | 
 | 6499 |  | 
 | 6500 | 	/* assign it some queues */ | 
 | 6501 | 	ret = i40e_alloc_rings(vsi); | 
 | 6502 | 	if (ret) | 
 | 6503 | 		goto err_rings; | 
 | 6504 |  | 
 | 6505 | 	/* map all of the rings to the q_vectors */ | 
 | 6506 | 	i40e_vsi_map_rings_to_vectors(vsi); | 
 | 6507 | 	return vsi; | 
 | 6508 |  | 
 | 6509 | err_rings: | 
 | 6510 | 	i40e_vsi_free_q_vectors(vsi); | 
 | 6511 | 	if (vsi->netdev_registered) { | 
 | 6512 | 		vsi->netdev_registered = false; | 
 | 6513 | 		unregister_netdev(vsi->netdev); | 
 | 6514 | 		free_netdev(vsi->netdev); | 
 | 6515 | 		vsi->netdev = NULL; | 
 | 6516 | 	} | 
 | 6517 | 	i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | 
 | 6518 | err_vsi: | 
 | 6519 | 	i40e_vsi_clear(vsi); | 
 | 6520 | 	return NULL; | 
 | 6521 | } | 
 | 6522 |  | 
 | 6523 | /** | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6524 |  * i40e_vsi_setup - Set up a VSI by a given type | 
 | 6525 |  * @pf: board private structure | 
 | 6526 |  * @type: VSI type | 
 | 6527 |  * @uplink_seid: the switch element to link to | 
 | 6528 |  * @param1: usage depends upon VSI type. For VF types, indicates VF id | 
 | 6529 |  * | 
 | 6530 |  * This allocates the sw VSI structure and its queue resources, then add a VSI | 
 | 6531 |  * to the identified VEB. | 
 | 6532 |  * | 
 | 6533 |  * Returns pointer to the successfully allocated and configure VSI sw struct on | 
 | 6534 |  * success, otherwise returns NULL on failure. | 
 | 6535 |  **/ | 
 | 6536 | struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, | 
 | 6537 | 				u16 uplink_seid, u32 param1) | 
 | 6538 | { | 
 | 6539 | 	struct i40e_vsi *vsi = NULL; | 
 | 6540 | 	struct i40e_veb *veb = NULL; | 
 | 6541 | 	int ret, i; | 
 | 6542 | 	int v_idx; | 
 | 6543 |  | 
 | 6544 | 	/* The requested uplink_seid must be either | 
 | 6545 | 	 *     - the PF's port seid | 
 | 6546 | 	 *              no VEB is needed because this is the PF | 
 | 6547 | 	 *              or this is a Flow Director special case VSI | 
 | 6548 | 	 *     - seid of an existing VEB | 
 | 6549 | 	 *     - seid of a VSI that owns an existing VEB | 
 | 6550 | 	 *     - seid of a VSI that doesn't own a VEB | 
 | 6551 | 	 *              a new VEB is created and the VSI becomes the owner | 
 | 6552 | 	 *     - seid of the PF VSI, which is what creates the first VEB | 
 | 6553 | 	 *              this is a special case of the previous | 
 | 6554 | 	 * | 
 | 6555 | 	 * Find which uplink_seid we were given and create a new VEB if needed | 
 | 6556 | 	 */ | 
 | 6557 | 	for (i = 0; i < I40E_MAX_VEB; i++) { | 
 | 6558 | 		if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) { | 
 | 6559 | 			veb = pf->veb[i]; | 
 | 6560 | 			break; | 
 | 6561 | 		} | 
 | 6562 | 	} | 
 | 6563 |  | 
 | 6564 | 	if (!veb && uplink_seid != pf->mac_seid) { | 
 | 6565 |  | 
 | 6566 | 		for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 6567 | 			if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) { | 
 | 6568 | 				vsi = pf->vsi[i]; | 
 | 6569 | 				break; | 
 | 6570 | 			} | 
 | 6571 | 		} | 
 | 6572 | 		if (!vsi) { | 
 | 6573 | 			dev_info(&pf->pdev->dev, "no such uplink_seid %d\n", | 
 | 6574 | 				 uplink_seid); | 
 | 6575 | 			return NULL; | 
 | 6576 | 		} | 
 | 6577 |  | 
 | 6578 | 		if (vsi->uplink_seid == pf->mac_seid) | 
 | 6579 | 			veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid, | 
 | 6580 | 					     vsi->tc_config.enabled_tc); | 
 | 6581 | 		else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) | 
 | 6582 | 			veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid, | 
 | 6583 | 					     vsi->tc_config.enabled_tc); | 
 | 6584 |  | 
 | 6585 | 		for (i = 0; i < I40E_MAX_VEB && !veb; i++) { | 
 | 6586 | 			if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid) | 
 | 6587 | 				veb = pf->veb[i]; | 
 | 6588 | 		} | 
 | 6589 | 		if (!veb) { | 
 | 6590 | 			dev_info(&pf->pdev->dev, "couldn't add VEB\n"); | 
 | 6591 | 			return NULL; | 
 | 6592 | 		} | 
 | 6593 |  | 
 | 6594 | 		vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | 
 | 6595 | 		uplink_seid = veb->seid; | 
 | 6596 | 	} | 
 | 6597 |  | 
 | 6598 | 	/* get vsi sw struct */ | 
 | 6599 | 	v_idx = i40e_vsi_mem_alloc(pf, type); | 
 | 6600 | 	if (v_idx < 0) | 
 | 6601 | 		goto err_alloc; | 
 | 6602 | 	vsi = pf->vsi[v_idx]; | 
 | 6603 | 	vsi->type = type; | 
 | 6604 | 	vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB); | 
 | 6605 |  | 
 | 6606 | 	if (type == I40E_VSI_MAIN) | 
 | 6607 | 		pf->lan_vsi = v_idx; | 
 | 6608 | 	else if (type == I40E_VSI_SRIOV) | 
 | 6609 | 		vsi->vf_id = param1; | 
 | 6610 | 	/* assign it some queues */ | 
 | 6611 | 	ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx); | 
 | 6612 | 	if (ret < 0) { | 
 | 6613 | 		dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n", | 
 | 6614 | 			 vsi->seid, ret); | 
 | 6615 | 		goto err_vsi; | 
 | 6616 | 	} | 
 | 6617 | 	vsi->base_queue = ret; | 
 | 6618 |  | 
 | 6619 | 	/* get a VSI from the hardware */ | 
 | 6620 | 	vsi->uplink_seid = uplink_seid; | 
 | 6621 | 	ret = i40e_add_vsi(vsi); | 
 | 6622 | 	if (ret) | 
 | 6623 | 		goto err_vsi; | 
 | 6624 |  | 
 | 6625 | 	switch (vsi->type) { | 
 | 6626 | 	/* setup the netdev if needed */ | 
 | 6627 | 	case I40E_VSI_MAIN: | 
 | 6628 | 	case I40E_VSI_VMDQ2: | 
 | 6629 | 		ret = i40e_config_netdev(vsi); | 
 | 6630 | 		if (ret) | 
 | 6631 | 			goto err_netdev; | 
 | 6632 | 		ret = register_netdev(vsi->netdev); | 
 | 6633 | 		if (ret) | 
 | 6634 | 			goto err_netdev; | 
 | 6635 | 		vsi->netdev_registered = true; | 
 | 6636 | 		netif_carrier_off(vsi->netdev); | 
 | 6637 | 		/* fall through */ | 
 | 6638 |  | 
 | 6639 | 	case I40E_VSI_FDIR: | 
 | 6640 | 		/* set up vectors and rings if needed */ | 
 | 6641 | 		ret = i40e_vsi_setup_vectors(vsi); | 
 | 6642 | 		if (ret) | 
 | 6643 | 			goto err_msix; | 
 | 6644 |  | 
 | 6645 | 		ret = i40e_alloc_rings(vsi); | 
 | 6646 | 		if (ret) | 
 | 6647 | 			goto err_rings; | 
 | 6648 |  | 
 | 6649 | 		/* map all of the rings to the q_vectors */ | 
 | 6650 | 		i40e_vsi_map_rings_to_vectors(vsi); | 
 | 6651 |  | 
 | 6652 | 		i40e_vsi_reset_stats(vsi); | 
 | 6653 | 		break; | 
 | 6654 |  | 
 | 6655 | 	default: | 
 | 6656 | 		/* no netdev or rings for the other VSI types */ | 
 | 6657 | 		break; | 
 | 6658 | 	} | 
 | 6659 |  | 
 | 6660 | 	return vsi; | 
 | 6661 |  | 
 | 6662 | err_rings: | 
 | 6663 | 	i40e_vsi_free_q_vectors(vsi); | 
 | 6664 | err_msix: | 
 | 6665 | 	if (vsi->netdev_registered) { | 
 | 6666 | 		vsi->netdev_registered = false; | 
 | 6667 | 		unregister_netdev(vsi->netdev); | 
 | 6668 | 		free_netdev(vsi->netdev); | 
 | 6669 | 		vsi->netdev = NULL; | 
 | 6670 | 	} | 
 | 6671 | err_netdev: | 
 | 6672 | 	i40e_aq_delete_element(&pf->hw, vsi->seid, NULL); | 
 | 6673 | err_vsi: | 
 | 6674 | 	i40e_vsi_clear(vsi); | 
 | 6675 | err_alloc: | 
 | 6676 | 	return NULL; | 
 | 6677 | } | 
 | 6678 |  | 
 | 6679 | /** | 
 | 6680 |  * i40e_veb_get_bw_info - Query VEB BW information | 
 | 6681 |  * @veb: the veb to query | 
 | 6682 |  * | 
 | 6683 |  * Query the Tx scheduler BW configuration data for given VEB | 
 | 6684 |  **/ | 
 | 6685 | static int i40e_veb_get_bw_info(struct i40e_veb *veb) | 
 | 6686 | { | 
 | 6687 | 	struct i40e_aqc_query_switching_comp_ets_config_resp ets_data; | 
 | 6688 | 	struct i40e_aqc_query_switching_comp_bw_config_resp bw_data; | 
 | 6689 | 	struct i40e_pf *pf = veb->pf; | 
 | 6690 | 	struct i40e_hw *hw = &pf->hw; | 
 | 6691 | 	u32 tc_bw_max; | 
 | 6692 | 	int ret = 0; | 
 | 6693 | 	int i; | 
 | 6694 |  | 
 | 6695 | 	ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid, | 
 | 6696 | 						  &bw_data, NULL); | 
 | 6697 | 	if (ret) { | 
 | 6698 | 		dev_info(&pf->pdev->dev, | 
 | 6699 | 			 "query veb bw config failed, aq_err=%d\n", | 
 | 6700 | 			 hw->aq.asq_last_status); | 
 | 6701 | 		goto out; | 
 | 6702 | 	} | 
 | 6703 |  | 
 | 6704 | 	ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid, | 
 | 6705 | 						   &ets_data, NULL); | 
 | 6706 | 	if (ret) { | 
 | 6707 | 		dev_info(&pf->pdev->dev, | 
 | 6708 | 			 "query veb bw ets config failed, aq_err=%d\n", | 
 | 6709 | 			 hw->aq.asq_last_status); | 
 | 6710 | 		goto out; | 
 | 6711 | 	} | 
 | 6712 |  | 
 | 6713 | 	veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit); | 
 | 6714 | 	veb->bw_max_quanta = ets_data.tc_bw_max; | 
 | 6715 | 	veb->is_abs_credits = bw_data.absolute_credits_enable; | 
 | 6716 | 	tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) | | 
 | 6717 | 		    (le16_to_cpu(bw_data.tc_bw_max[1]) << 16); | 
 | 6718 | 	for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { | 
 | 6719 | 		veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i]; | 
 | 6720 | 		veb->bw_tc_limit_credits[i] = | 
 | 6721 | 					le16_to_cpu(bw_data.tc_bw_limits[i]); | 
 | 6722 | 		veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7); | 
 | 6723 | 	} | 
 | 6724 |  | 
 | 6725 | out: | 
 | 6726 | 	return ret; | 
 | 6727 | } | 
 | 6728 |  | 
 | 6729 | /** | 
 | 6730 |  * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF | 
 | 6731 |  * @pf: board private structure | 
 | 6732 |  * | 
 | 6733 |  * On error: returns error code (negative) | 
 | 6734 |  * On success: returns vsi index in PF (positive) | 
 | 6735 |  **/ | 
 | 6736 | static int i40e_veb_mem_alloc(struct i40e_pf *pf) | 
 | 6737 | { | 
 | 6738 | 	int ret = -ENOENT; | 
 | 6739 | 	struct i40e_veb *veb; | 
 | 6740 | 	int i; | 
 | 6741 |  | 
 | 6742 | 	/* Need to protect the allocation of switch elements at the PF level */ | 
 | 6743 | 	mutex_lock(&pf->switch_mutex); | 
 | 6744 |  | 
 | 6745 | 	/* VEB list may be fragmented if VEB creation/destruction has | 
 | 6746 | 	 * been happening.  We can afford to do a quick scan to look | 
 | 6747 | 	 * for any free slots in the list. | 
 | 6748 | 	 * | 
 | 6749 | 	 * find next empty veb slot, looping back around if necessary | 
 | 6750 | 	 */ | 
 | 6751 | 	i = 0; | 
 | 6752 | 	while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL)) | 
 | 6753 | 		i++; | 
 | 6754 | 	if (i >= I40E_MAX_VEB) { | 
 | 6755 | 		ret = -ENOMEM; | 
 | 6756 | 		goto err_alloc_veb;  /* out of VEB slots! */ | 
 | 6757 | 	} | 
 | 6758 |  | 
 | 6759 | 	veb = kzalloc(sizeof(*veb), GFP_KERNEL); | 
 | 6760 | 	if (!veb) { | 
 | 6761 | 		ret = -ENOMEM; | 
 | 6762 | 		goto err_alloc_veb; | 
 | 6763 | 	} | 
 | 6764 | 	veb->pf = pf; | 
 | 6765 | 	veb->idx = i; | 
 | 6766 | 	veb->enabled_tc = 1; | 
 | 6767 |  | 
 | 6768 | 	pf->veb[i] = veb; | 
 | 6769 | 	ret = i; | 
 | 6770 | err_alloc_veb: | 
 | 6771 | 	mutex_unlock(&pf->switch_mutex); | 
 | 6772 | 	return ret; | 
 | 6773 | } | 
 | 6774 |  | 
 | 6775 | /** | 
 | 6776 |  * i40e_switch_branch_release - Delete a branch of the switch tree | 
 | 6777 |  * @branch: where to start deleting | 
 | 6778 |  * | 
 | 6779 |  * This uses recursion to find the tips of the branch to be | 
 | 6780 |  * removed, deleting until we get back to and can delete this VEB. | 
 | 6781 |  **/ | 
 | 6782 | static void i40e_switch_branch_release(struct i40e_veb *branch) | 
 | 6783 | { | 
 | 6784 | 	struct i40e_pf *pf = branch->pf; | 
 | 6785 | 	u16 branch_seid = branch->seid; | 
 | 6786 | 	u16 veb_idx = branch->idx; | 
 | 6787 | 	int i; | 
 | 6788 |  | 
 | 6789 | 	/* release any VEBs on this VEB - RECURSION */ | 
 | 6790 | 	for (i = 0; i < I40E_MAX_VEB; i++) { | 
 | 6791 | 		if (!pf->veb[i]) | 
 | 6792 | 			continue; | 
 | 6793 | 		if (pf->veb[i]->uplink_seid == branch->seid) | 
 | 6794 | 			i40e_switch_branch_release(pf->veb[i]); | 
 | 6795 | 	} | 
 | 6796 |  | 
 | 6797 | 	/* Release the VSIs on this VEB, but not the owner VSI. | 
 | 6798 | 	 * | 
 | 6799 | 	 * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing | 
 | 6800 | 	 *       the VEB itself, so don't use (*branch) after this loop. | 
 | 6801 | 	 */ | 
 | 6802 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 6803 | 		if (!pf->vsi[i]) | 
 | 6804 | 			continue; | 
 | 6805 | 		if (pf->vsi[i]->uplink_seid == branch_seid && | 
 | 6806 | 		   (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) { | 
 | 6807 | 			i40e_vsi_release(pf->vsi[i]); | 
 | 6808 | 		} | 
 | 6809 | 	} | 
 | 6810 |  | 
 | 6811 | 	/* There's one corner case where the VEB might not have been | 
 | 6812 | 	 * removed, so double check it here and remove it if needed. | 
 | 6813 | 	 * This case happens if the veb was created from the debugfs | 
 | 6814 | 	 * commands and no VSIs were added to it. | 
 | 6815 | 	 */ | 
 | 6816 | 	if (pf->veb[veb_idx]) | 
 | 6817 | 		i40e_veb_release(pf->veb[veb_idx]); | 
 | 6818 | } | 
 | 6819 |  | 
 | 6820 | /** | 
 | 6821 |  * i40e_veb_clear - remove veb struct | 
 | 6822 |  * @veb: the veb to remove | 
 | 6823 |  **/ | 
 | 6824 | static void i40e_veb_clear(struct i40e_veb *veb) | 
 | 6825 | { | 
 | 6826 | 	if (!veb) | 
 | 6827 | 		return; | 
 | 6828 |  | 
 | 6829 | 	if (veb->pf) { | 
 | 6830 | 		struct i40e_pf *pf = veb->pf; | 
 | 6831 |  | 
 | 6832 | 		mutex_lock(&pf->switch_mutex); | 
 | 6833 | 		if (pf->veb[veb->idx] == veb) | 
 | 6834 | 			pf->veb[veb->idx] = NULL; | 
 | 6835 | 		mutex_unlock(&pf->switch_mutex); | 
 | 6836 | 	} | 
 | 6837 |  | 
 | 6838 | 	kfree(veb); | 
 | 6839 | } | 
 | 6840 |  | 
 | 6841 | /** | 
 | 6842 |  * i40e_veb_release - Delete a VEB and free its resources | 
 | 6843 |  * @veb: the VEB being removed | 
 | 6844 |  **/ | 
 | 6845 | void i40e_veb_release(struct i40e_veb *veb) | 
 | 6846 | { | 
 | 6847 | 	struct i40e_vsi *vsi = NULL; | 
 | 6848 | 	struct i40e_pf *pf; | 
 | 6849 | 	int i, n = 0; | 
 | 6850 |  | 
 | 6851 | 	pf = veb->pf; | 
 | 6852 |  | 
 | 6853 | 	/* find the remaining VSI and check for extras */ | 
 | 6854 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 6855 | 		if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) { | 
 | 6856 | 			n++; | 
 | 6857 | 			vsi = pf->vsi[i]; | 
 | 6858 | 		} | 
 | 6859 | 	} | 
 | 6860 | 	if (n != 1) { | 
 | 6861 | 		dev_info(&pf->pdev->dev, | 
 | 6862 | 			 "can't remove VEB %d with %d VSIs left\n", | 
 | 6863 | 			 veb->seid, n); | 
 | 6864 | 		return; | 
 | 6865 | 	} | 
 | 6866 |  | 
 | 6867 | 	/* move the remaining VSI to uplink veb */ | 
 | 6868 | 	vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER; | 
 | 6869 | 	if (veb->uplink_seid) { | 
 | 6870 | 		vsi->uplink_seid = veb->uplink_seid; | 
 | 6871 | 		if (veb->uplink_seid == pf->mac_seid) | 
 | 6872 | 			vsi->veb_idx = I40E_NO_VEB; | 
 | 6873 | 		else | 
 | 6874 | 			vsi->veb_idx = veb->veb_idx; | 
 | 6875 | 	} else { | 
 | 6876 | 		/* floating VEB */ | 
 | 6877 | 		vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid; | 
 | 6878 | 		vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx; | 
 | 6879 | 	} | 
 | 6880 |  | 
 | 6881 | 	i40e_aq_delete_element(&pf->hw, veb->seid, NULL); | 
 | 6882 | 	i40e_veb_clear(veb); | 
 | 6883 |  | 
 | 6884 | 	return; | 
 | 6885 | } | 
 | 6886 |  | 
 | 6887 | /** | 
 | 6888 |  * i40e_add_veb - create the VEB in the switch | 
 | 6889 |  * @veb: the VEB to be instantiated | 
 | 6890 |  * @vsi: the controlling VSI | 
 | 6891 |  **/ | 
 | 6892 | static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi) | 
 | 6893 | { | 
| Greg Rose | 5674726 | 2013-11-28 06:39:37 +0000 | [diff] [blame] | 6894 | 	bool is_default = false; | 
| Kevin Scott | e1c51b95 | 2013-11-20 10:02:51 +0000 | [diff] [blame] | 6895 | 	bool is_cloud = false; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6896 | 	int ret; | 
 | 6897 |  | 
 | 6898 | 	/* get a VEB from the hardware */ | 
 | 6899 | 	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] | 6900 | 			      veb->enabled_tc, is_default, | 
 | 6901 | 			      is_cloud, &veb->seid, NULL); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 6902 | 	if (ret) { | 
 | 6903 | 		dev_info(&veb->pf->pdev->dev, | 
 | 6904 | 			 "couldn't add VEB, err %d, aq_err %d\n", | 
 | 6905 | 			 ret, veb->pf->hw.aq.asq_last_status); | 
 | 6906 | 		return -EPERM; | 
 | 6907 | 	} | 
 | 6908 |  | 
 | 6909 | 	/* get statistics counter */ | 
 | 6910 | 	ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL, | 
 | 6911 | 					 &veb->stats_idx, NULL, NULL, NULL); | 
 | 6912 | 	if (ret) { | 
 | 6913 | 		dev_info(&veb->pf->pdev->dev, | 
 | 6914 | 			 "couldn't get VEB statistics idx, err %d, aq_err %d\n", | 
 | 6915 | 			 ret, veb->pf->hw.aq.asq_last_status); | 
 | 6916 | 		return -EPERM; | 
 | 6917 | 	} | 
 | 6918 | 	ret = i40e_veb_get_bw_info(veb); | 
 | 6919 | 	if (ret) { | 
 | 6920 | 		dev_info(&veb->pf->pdev->dev, | 
 | 6921 | 			 "couldn't get VEB bw info, err %d, aq_err %d\n", | 
 | 6922 | 			 ret, veb->pf->hw.aq.asq_last_status); | 
 | 6923 | 		i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL); | 
 | 6924 | 		return -ENOENT; | 
 | 6925 | 	} | 
 | 6926 |  | 
 | 6927 | 	vsi->uplink_seid = veb->seid; | 
 | 6928 | 	vsi->veb_idx = veb->idx; | 
 | 6929 | 	vsi->flags |= I40E_VSI_FLAG_VEB_OWNER; | 
 | 6930 |  | 
 | 6931 | 	return 0; | 
 | 6932 | } | 
 | 6933 |  | 
 | 6934 | /** | 
 | 6935 |  * i40e_veb_setup - Set up a VEB | 
 | 6936 |  * @pf: board private structure | 
 | 6937 |  * @flags: VEB setup flags | 
 | 6938 |  * @uplink_seid: the switch element to link to | 
 | 6939 |  * @vsi_seid: the initial VSI seid | 
 | 6940 |  * @enabled_tc: Enabled TC bit-map | 
 | 6941 |  * | 
 | 6942 |  * This allocates the sw VEB structure and links it into the switch | 
 | 6943 |  * It is possible and legal for this to be a duplicate of an already | 
 | 6944 |  * existing VEB.  It is also possible for both uplink and vsi seids | 
 | 6945 |  * to be zero, in order to create a floating VEB. | 
 | 6946 |  * | 
 | 6947 |  * Returns pointer to the successfully allocated VEB sw struct on | 
 | 6948 |  * success, otherwise returns NULL on failure. | 
 | 6949 |  **/ | 
 | 6950 | struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, | 
 | 6951 | 				u16 uplink_seid, u16 vsi_seid, | 
 | 6952 | 				u8 enabled_tc) | 
 | 6953 | { | 
 | 6954 | 	struct i40e_veb *veb, *uplink_veb = NULL; | 
 | 6955 | 	int vsi_idx, veb_idx; | 
 | 6956 | 	int ret; | 
 | 6957 |  | 
 | 6958 | 	/* if one seid is 0, the other must be 0 to create a floating relay */ | 
 | 6959 | 	if ((uplink_seid == 0 || vsi_seid == 0) && | 
 | 6960 | 	    (uplink_seid + vsi_seid != 0)) { | 
 | 6961 | 		dev_info(&pf->pdev->dev, | 
 | 6962 | 			 "one, not both seid's are 0: uplink=%d vsi=%d\n", | 
 | 6963 | 			 uplink_seid, vsi_seid); | 
 | 6964 | 		return NULL; | 
 | 6965 | 	} | 
 | 6966 |  | 
 | 6967 | 	/* make sure there is such a vsi and uplink */ | 
 | 6968 | 	for (vsi_idx = 0; vsi_idx < pf->hw.func_caps.num_vsis; vsi_idx++) | 
 | 6969 | 		if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid) | 
 | 6970 | 			break; | 
 | 6971 | 	if (vsi_idx >= pf->hw.func_caps.num_vsis && vsi_seid != 0) { | 
 | 6972 | 		dev_info(&pf->pdev->dev, "vsi seid %d not found\n", | 
 | 6973 | 			 vsi_seid); | 
 | 6974 | 		return NULL; | 
 | 6975 | 	} | 
 | 6976 |  | 
 | 6977 | 	if (uplink_seid && uplink_seid != pf->mac_seid) { | 
 | 6978 | 		for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) { | 
 | 6979 | 			if (pf->veb[veb_idx] && | 
 | 6980 | 			    pf->veb[veb_idx]->seid == uplink_seid) { | 
 | 6981 | 				uplink_veb = pf->veb[veb_idx]; | 
 | 6982 | 				break; | 
 | 6983 | 			} | 
 | 6984 | 		} | 
 | 6985 | 		if (!uplink_veb) { | 
 | 6986 | 			dev_info(&pf->pdev->dev, | 
 | 6987 | 				 "uplink seid %d not found\n", uplink_seid); | 
 | 6988 | 			return NULL; | 
 | 6989 | 		} | 
 | 6990 | 	} | 
 | 6991 |  | 
 | 6992 | 	/* get veb sw struct */ | 
 | 6993 | 	veb_idx = i40e_veb_mem_alloc(pf); | 
 | 6994 | 	if (veb_idx < 0) | 
 | 6995 | 		goto err_alloc; | 
 | 6996 | 	veb = pf->veb[veb_idx]; | 
 | 6997 | 	veb->flags = flags; | 
 | 6998 | 	veb->uplink_seid = uplink_seid; | 
 | 6999 | 	veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB); | 
 | 7000 | 	veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1); | 
 | 7001 |  | 
 | 7002 | 	/* create the VEB in the switch */ | 
 | 7003 | 	ret = i40e_add_veb(veb, pf->vsi[vsi_idx]); | 
 | 7004 | 	if (ret) | 
 | 7005 | 		goto err_veb; | 
 | 7006 |  | 
 | 7007 | 	return veb; | 
 | 7008 |  | 
 | 7009 | err_veb: | 
 | 7010 | 	i40e_veb_clear(veb); | 
 | 7011 | err_alloc: | 
 | 7012 | 	return NULL; | 
 | 7013 | } | 
 | 7014 |  | 
 | 7015 | /** | 
 | 7016 |  * i40e_setup_pf_switch_element - set pf vars based on switch type | 
 | 7017 |  * @pf: board private structure | 
 | 7018 |  * @ele: element we are building info from | 
 | 7019 |  * @num_reported: total number of elements | 
 | 7020 |  * @printconfig: should we print the contents | 
 | 7021 |  * | 
 | 7022 |  * helper function to assist in extracting a few useful SEID values. | 
 | 7023 |  **/ | 
 | 7024 | static void i40e_setup_pf_switch_element(struct i40e_pf *pf, | 
 | 7025 | 				struct i40e_aqc_switch_config_element_resp *ele, | 
 | 7026 | 				u16 num_reported, bool printconfig) | 
 | 7027 | { | 
 | 7028 | 	u16 downlink_seid = le16_to_cpu(ele->downlink_seid); | 
 | 7029 | 	u16 uplink_seid = le16_to_cpu(ele->uplink_seid); | 
 | 7030 | 	u8 element_type = ele->element_type; | 
 | 7031 | 	u16 seid = le16_to_cpu(ele->seid); | 
 | 7032 |  | 
 | 7033 | 	if (printconfig) | 
 | 7034 | 		dev_info(&pf->pdev->dev, | 
 | 7035 | 			 "type=%d seid=%d uplink=%d downlink=%d\n", | 
 | 7036 | 			 element_type, seid, uplink_seid, downlink_seid); | 
 | 7037 |  | 
 | 7038 | 	switch (element_type) { | 
 | 7039 | 	case I40E_SWITCH_ELEMENT_TYPE_MAC: | 
 | 7040 | 		pf->mac_seid = seid; | 
 | 7041 | 		break; | 
 | 7042 | 	case I40E_SWITCH_ELEMENT_TYPE_VEB: | 
 | 7043 | 		/* Main VEB? */ | 
 | 7044 | 		if (uplink_seid != pf->mac_seid) | 
 | 7045 | 			break; | 
 | 7046 | 		if (pf->lan_veb == I40E_NO_VEB) { | 
 | 7047 | 			int v; | 
 | 7048 |  | 
 | 7049 | 			/* find existing or else empty VEB */ | 
 | 7050 | 			for (v = 0; v < I40E_MAX_VEB; v++) { | 
 | 7051 | 				if (pf->veb[v] && (pf->veb[v]->seid == seid)) { | 
 | 7052 | 					pf->lan_veb = v; | 
 | 7053 | 					break; | 
 | 7054 | 				} | 
 | 7055 | 			} | 
 | 7056 | 			if (pf->lan_veb == I40E_NO_VEB) { | 
 | 7057 | 				v = i40e_veb_mem_alloc(pf); | 
 | 7058 | 				if (v < 0) | 
 | 7059 | 					break; | 
 | 7060 | 				pf->lan_veb = v; | 
 | 7061 | 			} | 
 | 7062 | 		} | 
 | 7063 |  | 
 | 7064 | 		pf->veb[pf->lan_veb]->seid = seid; | 
 | 7065 | 		pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid; | 
 | 7066 | 		pf->veb[pf->lan_veb]->pf = pf; | 
 | 7067 | 		pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB; | 
 | 7068 | 		break; | 
 | 7069 | 	case I40E_SWITCH_ELEMENT_TYPE_VSI: | 
 | 7070 | 		if (num_reported != 1) | 
 | 7071 | 			break; | 
 | 7072 | 		/* This is immediately after a reset so we can assume this is | 
 | 7073 | 		 * the PF's VSI | 
 | 7074 | 		 */ | 
 | 7075 | 		pf->mac_seid = uplink_seid; | 
 | 7076 | 		pf->pf_seid = downlink_seid; | 
 | 7077 | 		pf->main_vsi_seid = seid; | 
 | 7078 | 		if (printconfig) | 
 | 7079 | 			dev_info(&pf->pdev->dev, | 
 | 7080 | 				 "pf_seid=%d main_vsi_seid=%d\n", | 
 | 7081 | 				 pf->pf_seid, pf->main_vsi_seid); | 
 | 7082 | 		break; | 
 | 7083 | 	case I40E_SWITCH_ELEMENT_TYPE_PF: | 
 | 7084 | 	case I40E_SWITCH_ELEMENT_TYPE_VF: | 
 | 7085 | 	case I40E_SWITCH_ELEMENT_TYPE_EMP: | 
 | 7086 | 	case I40E_SWITCH_ELEMENT_TYPE_BMC: | 
 | 7087 | 	case I40E_SWITCH_ELEMENT_TYPE_PE: | 
 | 7088 | 	case I40E_SWITCH_ELEMENT_TYPE_PA: | 
 | 7089 | 		/* ignore these for now */ | 
 | 7090 | 		break; | 
 | 7091 | 	default: | 
 | 7092 | 		dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n", | 
 | 7093 | 			 element_type, seid); | 
 | 7094 | 		break; | 
 | 7095 | 	} | 
 | 7096 | } | 
 | 7097 |  | 
 | 7098 | /** | 
 | 7099 |  * i40e_fetch_switch_configuration - Get switch config from firmware | 
 | 7100 |  * @pf: board private structure | 
 | 7101 |  * @printconfig: should we print the contents | 
 | 7102 |  * | 
 | 7103 |  * Get the current switch configuration from the device and | 
 | 7104 |  * extract a few useful SEID values. | 
 | 7105 |  **/ | 
 | 7106 | int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig) | 
 | 7107 | { | 
 | 7108 | 	struct i40e_aqc_get_switch_config_resp *sw_config; | 
 | 7109 | 	u16 next_seid = 0; | 
 | 7110 | 	int ret = 0; | 
 | 7111 | 	u8 *aq_buf; | 
 | 7112 | 	int i; | 
 | 7113 |  | 
 | 7114 | 	aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL); | 
 | 7115 | 	if (!aq_buf) | 
 | 7116 | 		return -ENOMEM; | 
 | 7117 |  | 
 | 7118 | 	sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf; | 
 | 7119 | 	do { | 
 | 7120 | 		u16 num_reported, num_total; | 
 | 7121 |  | 
 | 7122 | 		ret = i40e_aq_get_switch_config(&pf->hw, sw_config, | 
 | 7123 | 						I40E_AQ_LARGE_BUF, | 
 | 7124 | 						&next_seid, NULL); | 
 | 7125 | 		if (ret) { | 
 | 7126 | 			dev_info(&pf->pdev->dev, | 
 | 7127 | 				 "get switch config failed %d aq_err=%x\n", | 
 | 7128 | 				 ret, pf->hw.aq.asq_last_status); | 
 | 7129 | 			kfree(aq_buf); | 
 | 7130 | 			return -ENOENT; | 
 | 7131 | 		} | 
 | 7132 |  | 
 | 7133 | 		num_reported = le16_to_cpu(sw_config->header.num_reported); | 
 | 7134 | 		num_total = le16_to_cpu(sw_config->header.num_total); | 
 | 7135 |  | 
 | 7136 | 		if (printconfig) | 
 | 7137 | 			dev_info(&pf->pdev->dev, | 
 | 7138 | 				 "header: %d reported %d total\n", | 
 | 7139 | 				 num_reported, num_total); | 
 | 7140 |  | 
 | 7141 | 		if (num_reported) { | 
 | 7142 | 			int sz = sizeof(*sw_config) * num_reported; | 
 | 7143 |  | 
 | 7144 | 			kfree(pf->sw_config); | 
 | 7145 | 			pf->sw_config = kzalloc(sz, GFP_KERNEL); | 
 | 7146 | 			if (pf->sw_config) | 
 | 7147 | 				memcpy(pf->sw_config, sw_config, sz); | 
 | 7148 | 		} | 
 | 7149 |  | 
 | 7150 | 		for (i = 0; i < num_reported; i++) { | 
 | 7151 | 			struct i40e_aqc_switch_config_element_resp *ele = | 
 | 7152 | 				&sw_config->element[i]; | 
 | 7153 |  | 
 | 7154 | 			i40e_setup_pf_switch_element(pf, ele, num_reported, | 
 | 7155 | 						     printconfig); | 
 | 7156 | 		} | 
 | 7157 | 	} while (next_seid != 0); | 
 | 7158 |  | 
 | 7159 | 	kfree(aq_buf); | 
 | 7160 | 	return ret; | 
 | 7161 | } | 
 | 7162 |  | 
 | 7163 | /** | 
 | 7164 |  * i40e_setup_pf_switch - Setup the HW switch on startup or after reset | 
 | 7165 |  * @pf: board private structure | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7166 |  * @reinit: if the Main VSI needs to re-initialized. | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7167 |  * | 
 | 7168 |  * Returns 0 on success, negative value on failure | 
 | 7169 |  **/ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7170 | static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7171 | { | 
| Jesse Brandeburg | 895106a | 2013-11-26 10:49:16 +0000 | [diff] [blame] | 7172 | 	u32 rxfc = 0, txfc = 0, rxfc_reg; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7173 | 	int ret; | 
 | 7174 |  | 
 | 7175 | 	/* find out what's out there already */ | 
 | 7176 | 	ret = i40e_fetch_switch_configuration(pf, false); | 
 | 7177 | 	if (ret) { | 
 | 7178 | 		dev_info(&pf->pdev->dev, | 
 | 7179 | 			 "couldn't fetch switch config, err %d, aq_err %d\n", | 
 | 7180 | 			 ret, pf->hw.aq.asq_last_status); | 
 | 7181 | 		return ret; | 
 | 7182 | 	} | 
 | 7183 | 	i40e_pf_reset_stats(pf); | 
 | 7184 |  | 
 | 7185 | 	/* fdir VSI must happen first to be sure it gets queue 0, but only | 
 | 7186 | 	 * if there is enough room for the fdir VSI | 
 | 7187 | 	 */ | 
 | 7188 | 	if (pf->num_lan_qps > 1) | 
 | 7189 | 		i40e_fdir_setup(pf); | 
 | 7190 |  | 
 | 7191 | 	/* first time setup */ | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7192 | 	if (pf->lan_vsi == I40E_NO_VSI || reinit) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7193 | 		struct i40e_vsi *vsi = NULL; | 
 | 7194 | 		u16 uplink_seid; | 
 | 7195 |  | 
 | 7196 | 		/* Set up the PF VSI associated with the PF's main VSI | 
 | 7197 | 		 * that is already in the HW switch | 
 | 7198 | 		 */ | 
 | 7199 | 		if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb]) | 
 | 7200 | 			uplink_seid = pf->veb[pf->lan_veb]->seid; | 
 | 7201 | 		else | 
 | 7202 | 			uplink_seid = pf->mac_seid; | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7203 | 		if (pf->lan_vsi == I40E_NO_VSI) | 
 | 7204 | 			vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0); | 
 | 7205 | 		else if (reinit) | 
 | 7206 | 			vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7207 | 		if (!vsi) { | 
 | 7208 | 			dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n"); | 
 | 7209 | 			i40e_fdir_teardown(pf); | 
 | 7210 | 			return -EAGAIN; | 
 | 7211 | 		} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7212 | 	} else { | 
 | 7213 | 		/* force a reset of TC and queue layout configurations */ | 
 | 7214 | 		u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc; | 
 | 7215 | 		pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0; | 
 | 7216 | 		pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid; | 
 | 7217 | 		i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc); | 
 | 7218 | 	} | 
 | 7219 | 	i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]); | 
 | 7220 |  | 
 | 7221 | 	/* Setup static PF queue filter control settings */ | 
 | 7222 | 	ret = i40e_setup_pf_filter_control(pf); | 
 | 7223 | 	if (ret) { | 
 | 7224 | 		dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n", | 
 | 7225 | 			 ret); | 
 | 7226 | 		/* Failure here should not stop continuing other steps */ | 
 | 7227 | 	} | 
 | 7228 |  | 
 | 7229 | 	/* enable RSS in the HW, even for only one queue, as the stack can use | 
 | 7230 | 	 * the hash | 
 | 7231 | 	 */ | 
 | 7232 | 	if ((pf->flags & I40E_FLAG_RSS_ENABLED)) | 
 | 7233 | 		i40e_config_rss(pf); | 
 | 7234 |  | 
 | 7235 | 	/* fill in link information and enable LSE reporting */ | 
 | 7236 | 	i40e_aq_get_link_info(&pf->hw, true, NULL, NULL); | 
 | 7237 | 	i40e_link_event(pf); | 
 | 7238 |  | 
| Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7239 | 	/* Initialize user-specific link properties */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7240 | 	pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info & | 
 | 7241 | 				  I40E_AQ_AN_COMPLETED) ? true : false); | 
| Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7242 | 	/* requested_mode is set in probe or by ethtool */ | 
 | 7243 | 	if (!pf->fc_autoneg_status) | 
 | 7244 | 		goto no_autoneg; | 
 | 7245 |  | 
 | 7246 | 	if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) && | 
 | 7247 | 	    (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)) | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7248 | 		pf->hw.fc.current_mode = I40E_FC_FULL; | 
 | 7249 | 	else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) | 
 | 7250 | 		pf->hw.fc.current_mode = I40E_FC_TX_PAUSE; | 
 | 7251 | 	else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX) | 
 | 7252 | 		pf->hw.fc.current_mode = I40E_FC_RX_PAUSE; | 
 | 7253 | 	else | 
| Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7254 | 		pf->hw.fc.current_mode = I40E_FC_NONE; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7255 |  | 
| Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7256 | 	/* sync the flow control settings with the auto-neg values */ | 
 | 7257 | 	switch (pf->hw.fc.current_mode) { | 
 | 7258 | 	case I40E_FC_FULL: | 
 | 7259 | 		txfc = 1; | 
 | 7260 | 		rxfc = 1; | 
 | 7261 | 		break; | 
 | 7262 | 	case I40E_FC_TX_PAUSE: | 
 | 7263 | 		txfc = 1; | 
 | 7264 | 		rxfc = 0; | 
 | 7265 | 		break; | 
 | 7266 | 	case I40E_FC_RX_PAUSE: | 
 | 7267 | 		txfc = 0; | 
 | 7268 | 		rxfc = 1; | 
 | 7269 | 		break; | 
 | 7270 | 	case I40E_FC_NONE: | 
 | 7271 | 	case I40E_FC_DEFAULT: | 
 | 7272 | 		txfc = 0; | 
 | 7273 | 		rxfc = 0; | 
 | 7274 | 		break; | 
 | 7275 | 	case I40E_FC_PFC: | 
 | 7276 | 		/* TBD */ | 
 | 7277 | 		break; | 
 | 7278 | 	/* no default case, we have to handle all possibilities here */ | 
 | 7279 | 	} | 
 | 7280 |  | 
 | 7281 | 	wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT); | 
 | 7282 |  | 
 | 7283 | 	rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) & | 
 | 7284 | 		   ~I40E_PRTDCB_MFLCN_RFCE_MASK; | 
 | 7285 | 	rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT); | 
 | 7286 |  | 
 | 7287 | 	wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg); | 
 | 7288 |  | 
 | 7289 | 	goto fc_complete; | 
 | 7290 |  | 
 | 7291 | no_autoneg: | 
 | 7292 | 	/* disable L2 flow control, user can turn it on if they wish */ | 
 | 7293 | 	wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0); | 
 | 7294 | 	wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) & | 
 | 7295 | 					 ~I40E_PRTDCB_MFLCN_RFCE_MASK); | 
 | 7296 |  | 
 | 7297 | fc_complete: | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7298 | 	return ret; | 
 | 7299 | } | 
 | 7300 |  | 
 | 7301 | /** | 
 | 7302 |  * i40e_set_rss_size - helper to set rss_size | 
 | 7303 |  * @pf: board private structure | 
 | 7304 |  * @queues_left: how many queues | 
 | 7305 |  */ | 
 | 7306 | static u16 i40e_set_rss_size(struct i40e_pf *pf, int queues_left) | 
 | 7307 | { | 
 | 7308 | 	int num_tc0; | 
 | 7309 |  | 
 | 7310 | 	num_tc0 = min_t(int, queues_left, pf->rss_size_max); | 
| Jesse Brandeburg | bf051a3 | 2013-11-26 10:49:17 +0000 | [diff] [blame] | 7311 | 	num_tc0 = min_t(int, num_tc0, num_online_cpus()); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7312 | 	num_tc0 = rounddown_pow_of_two(num_tc0); | 
 | 7313 |  | 
 | 7314 | 	return num_tc0; | 
 | 7315 | } | 
 | 7316 |  | 
 | 7317 | /** | 
 | 7318 |  * i40e_determine_queue_usage - Work out queue distribution | 
 | 7319 |  * @pf: board private structure | 
 | 7320 |  **/ | 
 | 7321 | static void i40e_determine_queue_usage(struct i40e_pf *pf) | 
 | 7322 | { | 
 | 7323 | 	int accum_tc_size; | 
 | 7324 | 	int queues_left; | 
 | 7325 |  | 
 | 7326 | 	pf->num_lan_qps = 0; | 
 | 7327 | 	pf->num_tc_qps = rounddown_pow_of_two(pf->num_tc_qps); | 
 | 7328 | 	accum_tc_size = (I40E_MAX_TRAFFIC_CLASS - 1) * pf->num_tc_qps; | 
 | 7329 |  | 
 | 7330 | 	/* Find the max queues to be put into basic use.  We'll always be | 
 | 7331 | 	 * using TC0, whether or not DCB is running, and TC0 will get the | 
 | 7332 | 	 * big RSS set. | 
 | 7333 | 	 */ | 
 | 7334 | 	queues_left = pf->hw.func_caps.num_tx_qp; | 
 | 7335 |  | 
| Neerav Parikh | 9f52987 | 2013-11-28 06:39:38 +0000 | [diff] [blame] | 7336 | 	if   (!(pf->flags & I40E_FLAG_MSIX_ENABLED) || | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7337 | 		!(pf->flags & (I40E_FLAG_RSS_ENABLED | | 
 | 7338 | 		I40E_FLAG_FDIR_ENABLED | I40E_FLAG_DCB_ENABLED)) || | 
 | 7339 | 		(queues_left == 1)) { | 
 | 7340 |  | 
 | 7341 | 		/* one qp for PF, no queues for anything else */ | 
 | 7342 | 		queues_left = 0; | 
 | 7343 | 		pf->rss_size = pf->num_lan_qps = 1; | 
 | 7344 |  | 
 | 7345 | 		/* make sure all the fancies are disabled */ | 
 | 7346 | 		pf->flags &= ~(I40E_FLAG_RSS_ENABLED       | | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7347 | 				I40E_FLAG_FDIR_ENABLED	   | | 
 | 7348 | 				I40E_FLAG_FDIR_ATR_ENABLED | | 
 | 7349 | 				I40E_FLAG_DCB_ENABLED	   | | 
 | 7350 | 				I40E_FLAG_SRIOV_ENABLED	   | | 
 | 7351 | 				I40E_FLAG_VMDQ_ENABLED); | 
 | 7352 |  | 
 | 7353 | 	} else if (pf->flags & I40E_FLAG_RSS_ENABLED	  && | 
 | 7354 | 		   !(pf->flags & I40E_FLAG_FDIR_ENABLED)  && | 
 | 7355 | 		   !(pf->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 7356 |  | 
 | 7357 | 		pf->rss_size = i40e_set_rss_size(pf, queues_left); | 
 | 7358 |  | 
 | 7359 | 		queues_left -= pf->rss_size; | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7360 | 		pf->num_lan_qps = pf->rss_size_max; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7361 |  | 
 | 7362 | 	} else if (pf->flags & I40E_FLAG_RSS_ENABLED	  && | 
 | 7363 | 		   !(pf->flags & I40E_FLAG_FDIR_ENABLED)  && | 
 | 7364 | 		   (pf->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 7365 |  | 
 | 7366 | 		/* save num_tc_qps queues for TCs 1 thru 7 and the rest | 
 | 7367 | 		 * are set up for RSS in TC0 | 
 | 7368 | 		 */ | 
 | 7369 | 		queues_left -= accum_tc_size; | 
 | 7370 |  | 
 | 7371 | 		pf->rss_size = i40e_set_rss_size(pf, queues_left); | 
 | 7372 |  | 
 | 7373 | 		queues_left -= pf->rss_size; | 
 | 7374 | 		if (queues_left < 0) { | 
 | 7375 | 			dev_info(&pf->pdev->dev, "not enough queues for DCB\n"); | 
 | 7376 | 			return; | 
 | 7377 | 		} | 
 | 7378 |  | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7379 | 		pf->num_lan_qps = pf->rss_size_max + accum_tc_size; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7380 |  | 
 | 7381 | 	} else if (pf->flags & I40E_FLAG_RSS_ENABLED   && | 
 | 7382 | 		  (pf->flags & I40E_FLAG_FDIR_ENABLED) && | 
 | 7383 | 		  !(pf->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 7384 |  | 
 | 7385 | 		queues_left -= 1; /* save 1 queue for FD */ | 
 | 7386 |  | 
 | 7387 | 		pf->rss_size = i40e_set_rss_size(pf, queues_left); | 
 | 7388 |  | 
 | 7389 | 		queues_left -= pf->rss_size; | 
 | 7390 | 		if (queues_left < 0) { | 
 | 7391 | 			dev_info(&pf->pdev->dev, "not enough queues for Flow Director\n"); | 
 | 7392 | 			return; | 
 | 7393 | 		} | 
 | 7394 |  | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7395 | 		pf->num_lan_qps = pf->rss_size_max; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7396 |  | 
 | 7397 | 	} else if (pf->flags & I40E_FLAG_RSS_ENABLED   && | 
 | 7398 | 		  (pf->flags & I40E_FLAG_FDIR_ENABLED) && | 
 | 7399 | 		  (pf->flags & I40E_FLAG_DCB_ENABLED)) { | 
 | 7400 |  | 
 | 7401 | 		/* save 1 queue for TCs 1 thru 7, | 
 | 7402 | 		 * 1 queue for flow director, | 
 | 7403 | 		 * and the rest are set up for RSS in TC0 | 
 | 7404 | 		 */ | 
 | 7405 | 		queues_left -= 1; | 
 | 7406 | 		queues_left -= accum_tc_size; | 
 | 7407 |  | 
 | 7408 | 		pf->rss_size = i40e_set_rss_size(pf, queues_left); | 
 | 7409 | 		queues_left -= pf->rss_size; | 
 | 7410 | 		if (queues_left < 0) { | 
 | 7411 | 			dev_info(&pf->pdev->dev, "not enough queues for DCB and Flow Director\n"); | 
 | 7412 | 			return; | 
 | 7413 | 		} | 
 | 7414 |  | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7415 | 		pf->num_lan_qps = pf->rss_size_max + accum_tc_size; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7416 |  | 
 | 7417 | 	} else { | 
 | 7418 | 		dev_info(&pf->pdev->dev, | 
 | 7419 | 			 "Invalid configuration, flags=0x%08llx\n", pf->flags); | 
 | 7420 | 		return; | 
 | 7421 | 	} | 
 | 7422 |  | 
 | 7423 | 	if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | 
 | 7424 | 	    pf->num_vf_qps && pf->num_req_vfs && queues_left) { | 
 | 7425 | 		pf->num_req_vfs = min_t(int, pf->num_req_vfs, (queues_left / | 
 | 7426 | 							       pf->num_vf_qps)); | 
 | 7427 | 		queues_left -= (pf->num_req_vfs * pf->num_vf_qps); | 
 | 7428 | 	} | 
 | 7429 |  | 
 | 7430 | 	if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) && | 
 | 7431 | 	    pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) { | 
 | 7432 | 		pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis, | 
 | 7433 | 					  (queues_left / pf->num_vmdq_qps)); | 
 | 7434 | 		queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps); | 
 | 7435 | 	} | 
 | 7436 |  | 
| Anjali Singhai Jain | f8ff146 | 2013-11-26 10:49:19 +0000 | [diff] [blame] | 7437 | 	pf->queues_left = queues_left; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7438 | 	return; | 
 | 7439 | } | 
 | 7440 |  | 
 | 7441 | /** | 
 | 7442 |  * i40e_setup_pf_filter_control - Setup PF static filter control | 
 | 7443 |  * @pf: PF to be setup | 
 | 7444 |  * | 
 | 7445 |  * i40e_setup_pf_filter_control sets up a pf's initial filter control | 
 | 7446 |  * settings. If PE/FCoE are enabled then it will also set the per PF | 
 | 7447 |  * based filter sizes required for them. It also enables Flow director, | 
 | 7448 |  * ethertype and macvlan type filter settings for the pf. | 
 | 7449 |  * | 
 | 7450 |  * Returns 0 on success, negative on failure | 
 | 7451 |  **/ | 
 | 7452 | static int i40e_setup_pf_filter_control(struct i40e_pf *pf) | 
 | 7453 | { | 
 | 7454 | 	struct i40e_filter_control_settings *settings = &pf->filter_settings; | 
 | 7455 |  | 
 | 7456 | 	settings->hash_lut_size = I40E_HASH_LUT_SIZE_128; | 
 | 7457 |  | 
 | 7458 | 	/* Flow Director is enabled */ | 
 | 7459 | 	if (pf->flags & (I40E_FLAG_FDIR_ENABLED | I40E_FLAG_FDIR_ATR_ENABLED)) | 
 | 7460 | 		settings->enable_fdir = true; | 
 | 7461 |  | 
 | 7462 | 	/* Ethtype and MACVLAN filters enabled for PF */ | 
 | 7463 | 	settings->enable_ethtype = true; | 
 | 7464 | 	settings->enable_macvlan = true; | 
 | 7465 |  | 
 | 7466 | 	if (i40e_set_filter_control(&pf->hw, settings)) | 
 | 7467 | 		return -ENOENT; | 
 | 7468 |  | 
 | 7469 | 	return 0; | 
 | 7470 | } | 
 | 7471 |  | 
 | 7472 | /** | 
 | 7473 |  * i40e_probe - Device initialization routine | 
 | 7474 |  * @pdev: PCI device information struct | 
 | 7475 |  * @ent: entry in i40e_pci_tbl | 
 | 7476 |  * | 
 | 7477 |  * i40e_probe initializes a pf identified by a pci_dev structure. | 
 | 7478 |  * The OS initialization, configuring of the pf private structure, | 
 | 7479 |  * and a hardware reset occur. | 
 | 7480 |  * | 
 | 7481 |  * Returns 0 on success, negative on failure | 
 | 7482 |  **/ | 
 | 7483 | static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | 
 | 7484 | { | 
 | 7485 | 	struct i40e_driver_version dv; | 
 | 7486 | 	struct i40e_pf *pf; | 
 | 7487 | 	struct i40e_hw *hw; | 
| Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7488 | 	static u16 pfs_found; | 
| Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 7489 | 	u16 link_status; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7490 | 	int err = 0; | 
 | 7491 | 	u32 len; | 
 | 7492 |  | 
 | 7493 | 	err = pci_enable_device_mem(pdev); | 
 | 7494 | 	if (err) | 
 | 7495 | 		return err; | 
 | 7496 |  | 
 | 7497 | 	/* set up for high or low dma */ | 
 | 7498 | 	if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { | 
 | 7499 | 		/* coherent mask for the same size will always succeed if | 
 | 7500 | 		 * dma_set_mask does | 
 | 7501 | 		 */ | 
 | 7502 | 		dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); | 
 | 7503 | 	} else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { | 
 | 7504 | 		dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | 
 | 7505 | 	} else { | 
 | 7506 | 		dev_err(&pdev->dev, "DMA configuration failed: %d\n", err); | 
 | 7507 | 		err = -EIO; | 
 | 7508 | 		goto err_dma; | 
 | 7509 | 	} | 
 | 7510 |  | 
 | 7511 | 	/* set up pci connections */ | 
 | 7512 | 	err = pci_request_selected_regions(pdev, pci_select_bars(pdev, | 
 | 7513 | 					   IORESOURCE_MEM), i40e_driver_name); | 
 | 7514 | 	if (err) { | 
 | 7515 | 		dev_info(&pdev->dev, | 
 | 7516 | 			 "pci_request_selected_regions failed %d\n", err); | 
 | 7517 | 		goto err_pci_reg; | 
 | 7518 | 	} | 
 | 7519 |  | 
 | 7520 | 	pci_enable_pcie_error_reporting(pdev); | 
 | 7521 | 	pci_set_master(pdev); | 
 | 7522 |  | 
 | 7523 | 	/* Now that we have a PCI connection, we need to do the | 
 | 7524 | 	 * low level device setup.  This is primarily setting up | 
 | 7525 | 	 * the Admin Queue structures and then querying for the | 
 | 7526 | 	 * device's current profile information. | 
 | 7527 | 	 */ | 
 | 7528 | 	pf = kzalloc(sizeof(*pf), GFP_KERNEL); | 
 | 7529 | 	if (!pf) { | 
 | 7530 | 		err = -ENOMEM; | 
 | 7531 | 		goto err_pf_alloc; | 
 | 7532 | 	} | 
 | 7533 | 	pf->next_vsi = 0; | 
 | 7534 | 	pf->pdev = pdev; | 
 | 7535 | 	set_bit(__I40E_DOWN, &pf->state); | 
 | 7536 |  | 
 | 7537 | 	hw = &pf->hw; | 
 | 7538 | 	hw->back = pf; | 
 | 7539 | 	hw->hw_addr = ioremap(pci_resource_start(pdev, 0), | 
 | 7540 | 			      pci_resource_len(pdev, 0)); | 
 | 7541 | 	if (!hw->hw_addr) { | 
 | 7542 | 		err = -EIO; | 
 | 7543 | 		dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n", | 
 | 7544 | 			 (unsigned int)pci_resource_start(pdev, 0), | 
 | 7545 | 			 (unsigned int)pci_resource_len(pdev, 0), err); | 
 | 7546 | 		goto err_ioremap; | 
 | 7547 | 	} | 
 | 7548 | 	hw->vendor_id = pdev->vendor; | 
 | 7549 | 	hw->device_id = pdev->device; | 
 | 7550 | 	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); | 
 | 7551 | 	hw->subsystem_vendor_id = pdev->subsystem_vendor; | 
 | 7552 | 	hw->subsystem_device_id = pdev->subsystem_device; | 
 | 7553 | 	hw->bus.device = PCI_SLOT(pdev->devfn); | 
 | 7554 | 	hw->bus.func = PCI_FUNC(pdev->devfn); | 
| Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7555 | 	pf->instance = pfs_found; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7556 |  | 
| Jesse Brandeburg | 7134f9c | 2013-11-26 08:56:05 +0000 | [diff] [blame] | 7557 | 	/* do a special CORER for clearing PXE mode once at init */ | 
 | 7558 | 	if (hw->revision_id == 0 && | 
 | 7559 | 	    (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) { | 
 | 7560 | 		wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK); | 
 | 7561 | 		i40e_flush(hw); | 
 | 7562 | 		msleep(200); | 
 | 7563 | 		pf->corer_count++; | 
 | 7564 |  | 
 | 7565 | 		i40e_clear_pxe_mode(hw); | 
 | 7566 | 	} | 
 | 7567 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7568 | 	/* Reset here to make sure all is clean and to define PF 'n' */ | 
 | 7569 | 	err = i40e_pf_reset(hw); | 
 | 7570 | 	if (err) { | 
 | 7571 | 		dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err); | 
 | 7572 | 		goto err_pf_reset; | 
 | 7573 | 	} | 
 | 7574 | 	pf->pfr_count++; | 
 | 7575 |  | 
 | 7576 | 	hw->aq.num_arq_entries = I40E_AQ_LEN; | 
 | 7577 | 	hw->aq.num_asq_entries = I40E_AQ_LEN; | 
 | 7578 | 	hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE; | 
 | 7579 | 	hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE; | 
 | 7580 | 	pf->adminq_work_limit = I40E_AQ_WORK_LIMIT; | 
 | 7581 | 	snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1, | 
 | 7582 | 		 "%s-pf%d:misc", | 
 | 7583 | 		 dev_driver_string(&pf->pdev->dev), pf->hw.pf_id); | 
 | 7584 |  | 
 | 7585 | 	err = i40e_init_shared_code(hw); | 
 | 7586 | 	if (err) { | 
 | 7587 | 		dev_info(&pdev->dev, "init_shared_code failed: %d\n", err); | 
 | 7588 | 		goto err_pf_reset; | 
 | 7589 | 	} | 
 | 7590 |  | 
| Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 7591 | 	/* set up a default setting for link flow control */ | 
 | 7592 | 	pf->hw.fc.requested_mode = I40E_FC_NONE; | 
 | 7593 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7594 | 	err = i40e_init_adminq(hw); | 
 | 7595 | 	dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw)); | 
| Anjali Singhai jain | fe31070 | 2013-11-16 10:00:37 +0000 | [diff] [blame] | 7596 | 	if (((hw->nvm.version & I40E_NVM_VERSION_HI_MASK) | 
 | 7597 | 		 >> I40E_NVM_VERSION_HI_SHIFT) != I40E_CURRENT_NVM_VERSION_HI) { | 
 | 7598 | 		dev_info(&pdev->dev, | 
 | 7599 | 			 "warning: NVM version not supported, supported version: %02x.%02x\n", | 
 | 7600 | 			 I40E_CURRENT_NVM_VERSION_HI, | 
 | 7601 | 			 I40E_CURRENT_NVM_VERSION_LO); | 
 | 7602 | 	} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7603 | 	if (err) { | 
 | 7604 | 		dev_info(&pdev->dev, | 
 | 7605 | 			 "init_adminq failed: %d expecting API %02x.%02x\n", | 
 | 7606 | 			 err, | 
 | 7607 | 			 I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR); | 
 | 7608 | 		goto err_pf_reset; | 
 | 7609 | 	} | 
 | 7610 |  | 
 | 7611 | 	err = i40e_get_capabilities(pf); | 
 | 7612 | 	if (err) | 
 | 7613 | 		goto err_adminq_setup; | 
 | 7614 |  | 
 | 7615 | 	err = i40e_sw_init(pf); | 
 | 7616 | 	if (err) { | 
 | 7617 | 		dev_info(&pdev->dev, "sw_init failed: %d\n", err); | 
 | 7618 | 		goto err_sw_init; | 
 | 7619 | 	} | 
 | 7620 |  | 
 | 7621 | 	err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp, | 
 | 7622 | 				hw->func_caps.num_rx_qp, | 
 | 7623 | 				pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num); | 
 | 7624 | 	if (err) { | 
 | 7625 | 		dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err); | 
 | 7626 | 		goto err_init_lan_hmc; | 
 | 7627 | 	} | 
 | 7628 |  | 
 | 7629 | 	err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY); | 
 | 7630 | 	if (err) { | 
 | 7631 | 		dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err); | 
 | 7632 | 		err = -ENOENT; | 
 | 7633 | 		goto err_configure_lan_hmc; | 
 | 7634 | 	} | 
 | 7635 |  | 
 | 7636 | 	i40e_get_mac_addr(hw, hw->mac.addr); | 
| Jesse Brandeburg | f62b506 | 2013-11-28 06:39:27 +0000 | [diff] [blame] | 7637 | 	if (!is_valid_ether_addr(hw->mac.addr)) { | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7638 | 		dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); | 
 | 7639 | 		err = -EIO; | 
 | 7640 | 		goto err_mac_addr; | 
 | 7641 | 	} | 
 | 7642 | 	dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr); | 
 | 7643 | 	memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN); | 
 | 7644 |  | 
 | 7645 | 	pci_set_drvdata(pdev, pf); | 
 | 7646 | 	pci_save_state(pdev); | 
 | 7647 |  | 
 | 7648 | 	/* set up periodic task facility */ | 
 | 7649 | 	setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf); | 
 | 7650 | 	pf->service_timer_period = HZ; | 
 | 7651 |  | 
 | 7652 | 	INIT_WORK(&pf->service_task, i40e_service_task); | 
 | 7653 | 	clear_bit(__I40E_SERVICE_SCHED, &pf->state); | 
 | 7654 | 	pf->flags |= I40E_FLAG_NEED_LINK_UPDATE; | 
 | 7655 | 	pf->link_check_timeout = jiffies; | 
 | 7656 |  | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 7657 | 	/* WoL defaults to disabled */ | 
 | 7658 | 	pf->wol_en = false; | 
 | 7659 | 	device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); | 
 | 7660 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7661 | 	/* set up the main switch operations */ | 
 | 7662 | 	i40e_determine_queue_usage(pf); | 
 | 7663 | 	i40e_init_interrupt_scheme(pf); | 
 | 7664 |  | 
 | 7665 | 	/* Set up the *vsi struct based on the number of VSIs in the HW, | 
 | 7666 | 	 * and set up our local tracking of the MAIN PF vsi. | 
 | 7667 | 	 */ | 
 | 7668 | 	len = sizeof(struct i40e_vsi *) * pf->hw.func_caps.num_vsis; | 
 | 7669 | 	pf->vsi = kzalloc(len, GFP_KERNEL); | 
| Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7670 | 	if (!pf->vsi) { | 
 | 7671 | 		err = -ENOMEM; | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7672 | 		goto err_switch_setup; | 
| Wei Yongjun | ed87ac0 | 2013-09-24 05:17:25 +0000 | [diff] [blame] | 7673 | 	} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7674 |  | 
| Anjali Singhai Jain | bc7d338 | 2013-11-26 10:49:18 +0000 | [diff] [blame] | 7675 | 	err = i40e_setup_pf_switch(pf, false); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7676 | 	if (err) { | 
 | 7677 | 		dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err); | 
 | 7678 | 		goto err_vsis; | 
 | 7679 | 	} | 
 | 7680 |  | 
 | 7681 | 	/* The main driver is (mostly) up and happy. We need to set this state | 
 | 7682 | 	 * before setting up the misc vector or we get a race and the vector | 
 | 7683 | 	 * ends up disabled forever. | 
 | 7684 | 	 */ | 
 | 7685 | 	clear_bit(__I40E_DOWN, &pf->state); | 
 | 7686 |  | 
 | 7687 | 	/* In case of MSIX we are going to setup the misc vector right here | 
 | 7688 | 	 * to handle admin queue events etc. In case of legacy and MSI | 
 | 7689 | 	 * the misc functionality and queue processing is combined in | 
 | 7690 | 	 * the same vector and that gets setup at open. | 
 | 7691 | 	 */ | 
 | 7692 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 7693 | 		err = i40e_setup_misc_vector(pf); | 
 | 7694 | 		if (err) { | 
 | 7695 | 			dev_info(&pdev->dev, | 
 | 7696 | 				 "setup of misc vector failed: %d\n", err); | 
 | 7697 | 			goto err_vsis; | 
 | 7698 | 		} | 
 | 7699 | 	} | 
 | 7700 |  | 
 | 7701 | 	/* prep for VF support */ | 
 | 7702 | 	if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) && | 
 | 7703 | 	    (pf->flags & I40E_FLAG_MSIX_ENABLED)) { | 
 | 7704 | 		u32 val; | 
 | 7705 |  | 
 | 7706 | 		/* disable link interrupts for VFs */ | 
 | 7707 | 		val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM); | 
 | 7708 | 		val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK; | 
 | 7709 | 		wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val); | 
 | 7710 | 		i40e_flush(hw); | 
 | 7711 | 	} | 
 | 7712 |  | 
| Anjali Singhai Jain | 93cd765 | 2013-11-20 10:03:01 +0000 | [diff] [blame] | 7713 | 	pfs_found++; | 
 | 7714 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7715 | 	i40e_dbg_pf_init(pf); | 
 | 7716 |  | 
 | 7717 | 	/* tell the firmware that we're starting */ | 
 | 7718 | 	dv.major_version = DRV_VERSION_MAJOR; | 
 | 7719 | 	dv.minor_version = DRV_VERSION_MINOR; | 
 | 7720 | 	dv.build_version = DRV_VERSION_BUILD; | 
 | 7721 | 	dv.subbuild_version = 0; | 
 | 7722 | 	i40e_aq_send_driver_version(&pf->hw, &dv, NULL); | 
 | 7723 |  | 
 | 7724 | 	/* since everything's happy, start the service_task timer */ | 
 | 7725 | 	mod_timer(&pf->service_timer, | 
 | 7726 | 		  round_jiffies(jiffies + pf->service_timer_period)); | 
 | 7727 |  | 
| Catherine Sullivan | d4dfb81 | 2013-11-28 06:39:21 +0000 | [diff] [blame] | 7728 | 	/* Get the negotiated link width and speed from PCI config space */ | 
 | 7729 | 	pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status); | 
 | 7730 |  | 
 | 7731 | 	i40e_set_pci_config_data(hw, link_status); | 
 | 7732 |  | 
 | 7733 | 	dev_info(&pdev->dev, "PCI Express: %s %s\n", | 
 | 7734 | 		(hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" : | 
 | 7735 | 		 hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" : | 
 | 7736 | 		 hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" : | 
 | 7737 | 		 "Unknown"), | 
 | 7738 | 		(hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" : | 
 | 7739 | 		 hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" : | 
 | 7740 | 		 hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" : | 
 | 7741 | 		 hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" : | 
 | 7742 | 		 "Unknown")); | 
 | 7743 |  | 
 | 7744 | 	if (hw->bus.width < i40e_bus_width_pcie_x8 || | 
 | 7745 | 	    hw->bus.speed < i40e_bus_speed_8000) { | 
 | 7746 | 		dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n"); | 
 | 7747 | 		dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n"); | 
 | 7748 | 	} | 
 | 7749 |  | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7750 | 	return 0; | 
 | 7751 |  | 
 | 7752 | 	/* Unwind what we've done if something failed in the setup */ | 
 | 7753 | err_vsis: | 
 | 7754 | 	set_bit(__I40E_DOWN, &pf->state); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7755 | 	i40e_clear_interrupt_scheme(pf); | 
 | 7756 | 	kfree(pf->vsi); | 
| Shannon Nelson | 04b0301 | 2013-11-28 06:39:34 +0000 | [diff] [blame] | 7757 | err_switch_setup: | 
 | 7758 | 	i40e_reset_interrupt_capability(pf); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7759 | 	del_timer_sync(&pf->service_timer); | 
 | 7760 | err_mac_addr: | 
 | 7761 | err_configure_lan_hmc: | 
 | 7762 | 	(void)i40e_shutdown_lan_hmc(hw); | 
 | 7763 | err_init_lan_hmc: | 
 | 7764 | 	kfree(pf->qp_pile); | 
 | 7765 | 	kfree(pf->irq_pile); | 
 | 7766 | err_sw_init: | 
 | 7767 | err_adminq_setup: | 
 | 7768 | 	(void)i40e_shutdown_adminq(hw); | 
 | 7769 | err_pf_reset: | 
 | 7770 | 	iounmap(hw->hw_addr); | 
 | 7771 | err_ioremap: | 
 | 7772 | 	kfree(pf); | 
 | 7773 | err_pf_alloc: | 
 | 7774 | 	pci_disable_pcie_error_reporting(pdev); | 
 | 7775 | 	pci_release_selected_regions(pdev, | 
 | 7776 | 				     pci_select_bars(pdev, IORESOURCE_MEM)); | 
 | 7777 | err_pci_reg: | 
 | 7778 | err_dma: | 
 | 7779 | 	pci_disable_device(pdev); | 
 | 7780 | 	return err; | 
 | 7781 | } | 
 | 7782 |  | 
 | 7783 | /** | 
 | 7784 |  * i40e_remove - Device removal routine | 
 | 7785 |  * @pdev: PCI device information struct | 
 | 7786 |  * | 
 | 7787 |  * i40e_remove is called by the PCI subsystem to alert the driver | 
 | 7788 |  * that is should release a PCI device.  This could be caused by a | 
 | 7789 |  * Hot-Plug event, or because the driver is going to be removed from | 
 | 7790 |  * memory. | 
 | 7791 |  **/ | 
 | 7792 | static void i40e_remove(struct pci_dev *pdev) | 
 | 7793 | { | 
 | 7794 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
 | 7795 | 	i40e_status ret_code; | 
 | 7796 | 	u32 reg; | 
 | 7797 | 	int i; | 
 | 7798 |  | 
 | 7799 | 	i40e_dbg_pf_exit(pf); | 
 | 7800 |  | 
 | 7801 | 	if (pf->flags & I40E_FLAG_SRIOV_ENABLED) { | 
 | 7802 | 		i40e_free_vfs(pf); | 
 | 7803 | 		pf->flags &= ~I40E_FLAG_SRIOV_ENABLED; | 
 | 7804 | 	} | 
 | 7805 |  | 
 | 7806 | 	/* no more scheduling of any task */ | 
 | 7807 | 	set_bit(__I40E_DOWN, &pf->state); | 
 | 7808 | 	del_timer_sync(&pf->service_timer); | 
 | 7809 | 	cancel_work_sync(&pf->service_task); | 
 | 7810 |  | 
 | 7811 | 	i40e_fdir_teardown(pf); | 
 | 7812 |  | 
 | 7813 | 	/* If there is a switch structure or any orphans, remove them. | 
 | 7814 | 	 * This will leave only the PF's VSI remaining. | 
 | 7815 | 	 */ | 
 | 7816 | 	for (i = 0; i < I40E_MAX_VEB; i++) { | 
 | 7817 | 		if (!pf->veb[i]) | 
 | 7818 | 			continue; | 
 | 7819 |  | 
 | 7820 | 		if (pf->veb[i]->uplink_seid == pf->mac_seid || | 
 | 7821 | 		    pf->veb[i]->uplink_seid == 0) | 
 | 7822 | 			i40e_switch_branch_release(pf->veb[i]); | 
 | 7823 | 	} | 
 | 7824 |  | 
 | 7825 | 	/* Now we can shutdown the PF's VSI, just before we kill | 
 | 7826 | 	 * adminq and hmc. | 
 | 7827 | 	 */ | 
 | 7828 | 	if (pf->vsi[pf->lan_vsi]) | 
 | 7829 | 		i40e_vsi_release(pf->vsi[pf->lan_vsi]); | 
 | 7830 |  | 
 | 7831 | 	i40e_stop_misc_vector(pf); | 
 | 7832 | 	if (pf->flags & I40E_FLAG_MSIX_ENABLED) { | 
 | 7833 | 		synchronize_irq(pf->msix_entries[0].vector); | 
 | 7834 | 		free_irq(pf->msix_entries[0].vector, pf); | 
 | 7835 | 	} | 
 | 7836 |  | 
 | 7837 | 	/* shutdown and destroy the HMC */ | 
 | 7838 | 	ret_code = i40e_shutdown_lan_hmc(&pf->hw); | 
 | 7839 | 	if (ret_code) | 
 | 7840 | 		dev_warn(&pdev->dev, | 
 | 7841 | 			 "Failed to destroy the HMC resources: %d\n", ret_code); | 
 | 7842 |  | 
 | 7843 | 	/* shutdown the adminq */ | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7844 | 	ret_code = i40e_shutdown_adminq(&pf->hw); | 
 | 7845 | 	if (ret_code) | 
 | 7846 | 		dev_warn(&pdev->dev, | 
 | 7847 | 			 "Failed to destroy the Admin Queue resources: %d\n", | 
 | 7848 | 			 ret_code); | 
 | 7849 |  | 
 | 7850 | 	/* Clear all dynamic memory lists of rings, q_vectors, and VSIs */ | 
 | 7851 | 	i40e_clear_interrupt_scheme(pf); | 
 | 7852 | 	for (i = 0; i < pf->hw.func_caps.num_vsis; i++) { | 
 | 7853 | 		if (pf->vsi[i]) { | 
 | 7854 | 			i40e_vsi_clear_rings(pf->vsi[i]); | 
 | 7855 | 			i40e_vsi_clear(pf->vsi[i]); | 
 | 7856 | 			pf->vsi[i] = NULL; | 
 | 7857 | 		} | 
 | 7858 | 	} | 
 | 7859 |  | 
 | 7860 | 	for (i = 0; i < I40E_MAX_VEB; i++) { | 
 | 7861 | 		kfree(pf->veb[i]); | 
 | 7862 | 		pf->veb[i] = NULL; | 
 | 7863 | 	} | 
 | 7864 |  | 
 | 7865 | 	kfree(pf->qp_pile); | 
 | 7866 | 	kfree(pf->irq_pile); | 
 | 7867 | 	kfree(pf->sw_config); | 
 | 7868 | 	kfree(pf->vsi); | 
 | 7869 |  | 
 | 7870 | 	/* force a PF reset to clean anything leftover */ | 
 | 7871 | 	reg = rd32(&pf->hw, I40E_PFGEN_CTRL); | 
 | 7872 | 	wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK)); | 
 | 7873 | 	i40e_flush(&pf->hw); | 
 | 7874 |  | 
 | 7875 | 	iounmap(pf->hw.hw_addr); | 
 | 7876 | 	kfree(pf); | 
 | 7877 | 	pci_release_selected_regions(pdev, | 
 | 7878 | 				     pci_select_bars(pdev, IORESOURCE_MEM)); | 
 | 7879 |  | 
 | 7880 | 	pci_disable_pcie_error_reporting(pdev); | 
 | 7881 | 	pci_disable_device(pdev); | 
 | 7882 | } | 
 | 7883 |  | 
 | 7884 | /** | 
 | 7885 |  * i40e_pci_error_detected - warning that something funky happened in PCI land | 
 | 7886 |  * @pdev: PCI device information struct | 
 | 7887 |  * | 
 | 7888 |  * Called to warn that something happened and the error handling steps | 
 | 7889 |  * are in progress.  Allows the driver to quiesce things, be ready for | 
 | 7890 |  * remediation. | 
 | 7891 |  **/ | 
 | 7892 | static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev, | 
 | 7893 | 						enum pci_channel_state error) | 
 | 7894 | { | 
 | 7895 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
 | 7896 |  | 
 | 7897 | 	dev_info(&pdev->dev, "%s: error %d\n", __func__, error); | 
 | 7898 |  | 
 | 7899 | 	/* shutdown all operations */ | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7900 | 	if (!test_bit(__I40E_SUSPENDED, &pf->state)) { | 
 | 7901 | 		rtnl_lock(); | 
 | 7902 | 		i40e_prep_for_reset(pf); | 
 | 7903 | 		rtnl_unlock(); | 
 | 7904 | 	} | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7905 |  | 
 | 7906 | 	/* Request a slot reset */ | 
 | 7907 | 	return PCI_ERS_RESULT_NEED_RESET; | 
 | 7908 | } | 
 | 7909 |  | 
 | 7910 | /** | 
 | 7911 |  * i40e_pci_error_slot_reset - a PCI slot reset just happened | 
 | 7912 |  * @pdev: PCI device information struct | 
 | 7913 |  * | 
 | 7914 |  * Called to find if the driver can work with the device now that | 
 | 7915 |  * the pci slot has been reset.  If a basic connection seems good | 
 | 7916 |  * (registers are readable and have sane content) then return a | 
 | 7917 |  * happy little PCI_ERS_RESULT_xxx. | 
 | 7918 |  **/ | 
 | 7919 | static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev) | 
 | 7920 | { | 
 | 7921 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
 | 7922 | 	pci_ers_result_t result; | 
 | 7923 | 	int err; | 
 | 7924 | 	u32 reg; | 
 | 7925 |  | 
 | 7926 | 	dev_info(&pdev->dev, "%s\n", __func__); | 
 | 7927 | 	if (pci_enable_device_mem(pdev)) { | 
 | 7928 | 		dev_info(&pdev->dev, | 
 | 7929 | 			 "Cannot re-enable PCI device after reset.\n"); | 
 | 7930 | 		result = PCI_ERS_RESULT_DISCONNECT; | 
 | 7931 | 	} else { | 
 | 7932 | 		pci_set_master(pdev); | 
 | 7933 | 		pci_restore_state(pdev); | 
 | 7934 | 		pci_save_state(pdev); | 
 | 7935 | 		pci_wake_from_d3(pdev, false); | 
 | 7936 |  | 
 | 7937 | 		reg = rd32(&pf->hw, I40E_GLGEN_RTRIG); | 
 | 7938 | 		if (reg == 0) | 
 | 7939 | 			result = PCI_ERS_RESULT_RECOVERED; | 
 | 7940 | 		else | 
 | 7941 | 			result = PCI_ERS_RESULT_DISCONNECT; | 
 | 7942 | 	} | 
 | 7943 |  | 
 | 7944 | 	err = pci_cleanup_aer_uncorrect_error_status(pdev); | 
 | 7945 | 	if (err) { | 
 | 7946 | 		dev_info(&pdev->dev, | 
 | 7947 | 			 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", | 
 | 7948 | 			 err); | 
 | 7949 | 		/* non-fatal, continue */ | 
 | 7950 | 	} | 
 | 7951 |  | 
 | 7952 | 	return result; | 
 | 7953 | } | 
 | 7954 |  | 
 | 7955 | /** | 
 | 7956 |  * i40e_pci_error_resume - restart operations after PCI error recovery | 
 | 7957 |  * @pdev: PCI device information struct | 
 | 7958 |  * | 
 | 7959 |  * Called to allow the driver to bring things back up after PCI error | 
 | 7960 |  * and/or reset recovery has finished. | 
 | 7961 |  **/ | 
 | 7962 | static void i40e_pci_error_resume(struct pci_dev *pdev) | 
 | 7963 | { | 
 | 7964 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
 | 7965 |  | 
 | 7966 | 	dev_info(&pdev->dev, "%s\n", __func__); | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7967 | 	if (test_bit(__I40E_SUSPENDED, &pf->state)) | 
 | 7968 | 		return; | 
 | 7969 |  | 
 | 7970 | 	rtnl_lock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7971 | 	i40e_handle_reset_warning(pf); | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7972 | 	rtnl_lock(); | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 7973 | } | 
 | 7974 |  | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7975 | /** | 
 | 7976 |  * i40e_shutdown - PCI callback for shutting down | 
 | 7977 |  * @pdev: PCI device information struct | 
 | 7978 |  **/ | 
 | 7979 | static void i40e_shutdown(struct pci_dev *pdev) | 
 | 7980 | { | 
 | 7981 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 7982 | 	struct i40e_hw *hw = &pf->hw; | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7983 |  | 
 | 7984 | 	set_bit(__I40E_SUSPENDED, &pf->state); | 
 | 7985 | 	set_bit(__I40E_DOWN, &pf->state); | 
 | 7986 | 	rtnl_lock(); | 
 | 7987 | 	i40e_prep_for_reset(pf); | 
 | 7988 | 	rtnl_unlock(); | 
 | 7989 |  | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 7990 | 	wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); | 
 | 7991 | 	wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | 
 | 7992 |  | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7993 | 	if (system_state == SYSTEM_POWER_OFF) { | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 7994 | 		pci_wake_from_d3(pdev, pf->wol_en); | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 7995 | 		pci_set_power_state(pdev, PCI_D3hot); | 
 | 7996 | 	} | 
 | 7997 | } | 
 | 7998 |  | 
 | 7999 | #ifdef CONFIG_PM | 
 | 8000 | /** | 
 | 8001 |  * i40e_suspend - PCI callback for moving to D3 | 
 | 8002 |  * @pdev: PCI device information struct | 
 | 8003 |  **/ | 
 | 8004 | static int i40e_suspend(struct pci_dev *pdev, pm_message_t state) | 
 | 8005 | { | 
 | 8006 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8007 | 	struct i40e_hw *hw = &pf->hw; | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8008 |  | 
 | 8009 | 	set_bit(__I40E_SUSPENDED, &pf->state); | 
 | 8010 | 	set_bit(__I40E_DOWN, &pf->state); | 
 | 8011 | 	rtnl_lock(); | 
 | 8012 | 	i40e_prep_for_reset(pf); | 
 | 8013 | 	rtnl_unlock(); | 
 | 8014 |  | 
| Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 8015 | 	wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0)); | 
 | 8016 | 	wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0)); | 
 | 8017 |  | 
 | 8018 | 	pci_wake_from_d3(pdev, pf->wol_en); | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8019 | 	pci_set_power_state(pdev, PCI_D3hot); | 
 | 8020 |  | 
 | 8021 | 	return 0; | 
 | 8022 | } | 
 | 8023 |  | 
 | 8024 | /** | 
 | 8025 |  * i40e_resume - PCI callback for waking up from D3 | 
 | 8026 |  * @pdev: PCI device information struct | 
 | 8027 |  **/ | 
 | 8028 | static int i40e_resume(struct pci_dev *pdev) | 
 | 8029 | { | 
 | 8030 | 	struct i40e_pf *pf = pci_get_drvdata(pdev); | 
 | 8031 | 	u32 err; | 
 | 8032 |  | 
 | 8033 | 	pci_set_power_state(pdev, PCI_D0); | 
 | 8034 | 	pci_restore_state(pdev); | 
 | 8035 | 	/* pci_restore_state() clears dev->state_saves, so | 
 | 8036 | 	 * call pci_save_state() again to restore it. | 
 | 8037 | 	 */ | 
 | 8038 | 	pci_save_state(pdev); | 
 | 8039 |  | 
 | 8040 | 	err = pci_enable_device_mem(pdev); | 
 | 8041 | 	if (err) { | 
 | 8042 | 		dev_err(&pdev->dev, | 
 | 8043 | 			"%s: Cannot enable PCI device from suspend\n", | 
 | 8044 | 			__func__); | 
 | 8045 | 		return err; | 
 | 8046 | 	} | 
 | 8047 | 	pci_set_master(pdev); | 
 | 8048 |  | 
 | 8049 | 	/* no wakeup events while running */ | 
 | 8050 | 	pci_wake_from_d3(pdev, false); | 
 | 8051 |  | 
 | 8052 | 	/* handling the reset will rebuild the device state */ | 
 | 8053 | 	if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) { | 
 | 8054 | 		clear_bit(__I40E_DOWN, &pf->state); | 
 | 8055 | 		rtnl_lock(); | 
 | 8056 | 		i40e_reset_and_rebuild(pf, false); | 
 | 8057 | 		rtnl_unlock(); | 
 | 8058 | 	} | 
 | 8059 |  | 
 | 8060 | 	return 0; | 
 | 8061 | } | 
 | 8062 |  | 
 | 8063 | #endif | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8064 | static const struct pci_error_handlers i40e_err_handler = { | 
 | 8065 | 	.error_detected = i40e_pci_error_detected, | 
 | 8066 | 	.slot_reset = i40e_pci_error_slot_reset, | 
 | 8067 | 	.resume = i40e_pci_error_resume, | 
 | 8068 | }; | 
 | 8069 |  | 
 | 8070 | static struct pci_driver i40e_driver = { | 
 | 8071 | 	.name     = i40e_driver_name, | 
 | 8072 | 	.id_table = i40e_pci_tbl, | 
 | 8073 | 	.probe    = i40e_probe, | 
 | 8074 | 	.remove   = i40e_remove, | 
| Shannon Nelson | 9007bcc | 2013-11-26 10:49:23 +0000 | [diff] [blame] | 8075 | #ifdef CONFIG_PM | 
 | 8076 | 	.suspend  = i40e_suspend, | 
 | 8077 | 	.resume   = i40e_resume, | 
 | 8078 | #endif | 
 | 8079 | 	.shutdown = i40e_shutdown, | 
| Jesse Brandeburg | 41c445f | 2013-09-11 08:39:46 +0000 | [diff] [blame] | 8080 | 	.err_handler = &i40e_err_handler, | 
 | 8081 | 	.sriov_configure = i40e_pci_sriov_configure, | 
 | 8082 | }; | 
 | 8083 |  | 
 | 8084 | /** | 
 | 8085 |  * i40e_init_module - Driver registration routine | 
 | 8086 |  * | 
 | 8087 |  * i40e_init_module is the first routine called when the driver is | 
 | 8088 |  * loaded. All it does is register with the PCI subsystem. | 
 | 8089 |  **/ | 
 | 8090 | static int __init i40e_init_module(void) | 
 | 8091 | { | 
 | 8092 | 	pr_info("%s: %s - version %s\n", i40e_driver_name, | 
 | 8093 | 		i40e_driver_string, i40e_driver_version_str); | 
 | 8094 | 	pr_info("%s: %s\n", i40e_driver_name, i40e_copyright); | 
 | 8095 | 	i40e_dbg_init(); | 
 | 8096 | 	return pci_register_driver(&i40e_driver); | 
 | 8097 | } | 
 | 8098 | module_init(i40e_init_module); | 
 | 8099 |  | 
 | 8100 | /** | 
 | 8101 |  * i40e_exit_module - Driver exit cleanup routine | 
 | 8102 |  * | 
 | 8103 |  * i40e_exit_module is called just before the driver is removed | 
 | 8104 |  * from memory. | 
 | 8105 |  **/ | 
 | 8106 | static void __exit i40e_exit_module(void) | 
 | 8107 | { | 
 | 8108 | 	pci_unregister_driver(&i40e_driver); | 
 | 8109 | 	i40e_dbg_exit(); | 
 | 8110 | } | 
 | 8111 | module_exit(i40e_exit_module); |