1b6fec18fSAlexander Duyck /* Intel Ethernet Switch Host Interface Driver 29d4955b4SJacob Keller * Copyright(c) 2013 - 2015 Intel Corporation. 3b6fec18fSAlexander Duyck * 4b6fec18fSAlexander Duyck * This program is free software; you can redistribute it and/or modify it 5b6fec18fSAlexander Duyck * under the terms and conditions of the GNU General Public License, 6b6fec18fSAlexander Duyck * version 2, as published by the Free Software Foundation. 7b6fec18fSAlexander Duyck * 8b6fec18fSAlexander Duyck * This program is distributed in the hope it will be useful, but WITHOUT 9b6fec18fSAlexander Duyck * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10b6fec18fSAlexander Duyck * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11b6fec18fSAlexander Duyck * more details. 12b6fec18fSAlexander Duyck * 13b6fec18fSAlexander Duyck * The full GNU General Public License is included in this distribution in 14b6fec18fSAlexander Duyck * the file called "COPYING". 15b6fec18fSAlexander Duyck * 16b6fec18fSAlexander Duyck * Contact Information: 17b6fec18fSAlexander Duyck * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 18b6fec18fSAlexander Duyck * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 19b6fec18fSAlexander Duyck */ 20b6fec18fSAlexander Duyck 21b6fec18fSAlexander Duyck #include "fm10k_pf.h" 22c2653865SAlexander Duyck #include "fm10k_vf.h" 23b6fec18fSAlexander Duyck 24b6fec18fSAlexander Duyck /** 25b6fec18fSAlexander Duyck * fm10k_reset_hw_pf - PF hardware reset 26b6fec18fSAlexander Duyck * @hw: pointer to hardware structure 27b6fec18fSAlexander Duyck * 28b6fec18fSAlexander Duyck * This function should return the hardware to a state similar to the 29b6fec18fSAlexander Duyck * one it is in after being powered on. 30b6fec18fSAlexander Duyck **/ 31b6fec18fSAlexander Duyck static s32 fm10k_reset_hw_pf(struct fm10k_hw *hw) 32b6fec18fSAlexander Duyck { 33b6fec18fSAlexander Duyck s32 err; 34b6fec18fSAlexander Duyck u32 reg; 35b6fec18fSAlexander Duyck u16 i; 36b6fec18fSAlexander Duyck 37b6fec18fSAlexander Duyck /* Disable interrupts */ 38b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(ALL)); 39b6fec18fSAlexander Duyck 40b6fec18fSAlexander Duyck /* Lock ITR2 reg 0 into itself and disable interrupt moderation */ 41b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), 0); 42b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_INT_CTRL, 0); 43b6fec18fSAlexander Duyck 44b6fec18fSAlexander Duyck /* We assume here Tx and Rx queue 0 are owned by the PF */ 45b6fec18fSAlexander Duyck 46b6fec18fSAlexander Duyck /* Shut off VF access to their queues forcing them to queue 0 */ 47b6fec18fSAlexander Duyck for (i = 0; i < FM10K_TQMAP_TABLE_SIZE; i++) { 48b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(i), 0); 49b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(i), 0); 50b6fec18fSAlexander Duyck } 51b6fec18fSAlexander Duyck 52b6fec18fSAlexander Duyck /* shut down all rings */ 53b6fec18fSAlexander Duyck err = fm10k_disable_queues_generic(hw, FM10K_MAX_QUEUES); 54b6fec18fSAlexander Duyck if (err) 55b6fec18fSAlexander Duyck return err; 56b6fec18fSAlexander Duyck 57b6fec18fSAlexander Duyck /* Verify that DMA is no longer active */ 58b6fec18fSAlexander Duyck reg = fm10k_read_reg(hw, FM10K_DMA_CTRL); 59b6fec18fSAlexander Duyck if (reg & (FM10K_DMA_CTRL_TX_ACTIVE | FM10K_DMA_CTRL_RX_ACTIVE)) 60b6fec18fSAlexander Duyck return FM10K_ERR_DMA_PENDING; 61b6fec18fSAlexander Duyck 62ac981003SAlexander Duyck /* verify the switch is ready for reset */ 63ac981003SAlexander Duyck reg = fm10k_read_reg(hw, FM10K_DMA_CTRL2); 64ac981003SAlexander Duyck if (!(reg & FM10K_DMA_CTRL2_SWITCH_READY)) 65ac981003SAlexander Duyck goto out; 66ac981003SAlexander Duyck 67b6fec18fSAlexander Duyck /* Inititate data path reset */ 68b6fec18fSAlexander Duyck reg |= FM10K_DMA_CTRL_DATAPATH_RESET; 69b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DMA_CTRL, reg); 70b6fec18fSAlexander Duyck 71b6fec18fSAlexander Duyck /* Flush write and allow 100us for reset to complete */ 72b6fec18fSAlexander Duyck fm10k_write_flush(hw); 73b6fec18fSAlexander Duyck udelay(FM10K_RESET_TIMEOUT); 74b6fec18fSAlexander Duyck 75b6fec18fSAlexander Duyck /* Verify we made it out of reset */ 76b6fec18fSAlexander Duyck reg = fm10k_read_reg(hw, FM10K_IP); 77b6fec18fSAlexander Duyck if (!(reg & FM10K_IP_NOTINRESET)) 78b6fec18fSAlexander Duyck err = FM10K_ERR_RESET_FAILED; 79b6fec18fSAlexander Duyck 80ac981003SAlexander Duyck out: 81b6fec18fSAlexander Duyck return err; 82b6fec18fSAlexander Duyck } 83b6fec18fSAlexander Duyck 84b6fec18fSAlexander Duyck /** 85c2653865SAlexander Duyck * fm10k_is_ari_hierarchy_pf - Indicate ARI hierarchy support 86c2653865SAlexander Duyck * @hw: pointer to hardware structure 87c2653865SAlexander Duyck * 88c2653865SAlexander Duyck * Looks at the ARI hierarchy bit to determine whether ARI is supported or not. 89c2653865SAlexander Duyck **/ 90c2653865SAlexander Duyck static bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw *hw) 91c2653865SAlexander Duyck { 92c2653865SAlexander Duyck u16 sriov_ctrl = fm10k_read_pci_cfg_word(hw, FM10K_PCIE_SRIOV_CTRL); 93c2653865SAlexander Duyck 94c2653865SAlexander Duyck return !!(sriov_ctrl & FM10K_PCIE_SRIOV_CTRL_VFARI); 95c2653865SAlexander Duyck } 96c2653865SAlexander Duyck 97c2653865SAlexander Duyck /** 98b6fec18fSAlexander Duyck * fm10k_init_hw_pf - PF hardware initialization 99b6fec18fSAlexander Duyck * @hw: pointer to hardware structure 100b6fec18fSAlexander Duyck * 101b6fec18fSAlexander Duyck **/ 102b6fec18fSAlexander Duyck static s32 fm10k_init_hw_pf(struct fm10k_hw *hw) 103b6fec18fSAlexander Duyck { 104b6fec18fSAlexander Duyck u32 dma_ctrl, txqctl; 105b6fec18fSAlexander Duyck u16 i; 106b6fec18fSAlexander Duyck 107b6fec18fSAlexander Duyck /* Establish default VSI as valid */ 108b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DGLORTDEC(fm10k_dglort_default), 0); 109b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DGLORTMAP(fm10k_dglort_default), 110b6fec18fSAlexander Duyck FM10K_DGLORTMAP_ANY); 111b6fec18fSAlexander Duyck 112b6fec18fSAlexander Duyck /* Invalidate all other GLORT entries */ 113b6fec18fSAlexander Duyck for (i = 1; i < FM10K_DGLORT_COUNT; i++) 114b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DGLORTMAP(i), FM10K_DGLORTMAP_NONE); 115b6fec18fSAlexander Duyck 116b6fec18fSAlexander Duyck /* reset ITR2(0) to point to itself */ 117b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), 0); 118b6fec18fSAlexander Duyck 119b6fec18fSAlexander Duyck /* reset VF ITR2(0) to point to 0 avoid PF registers */ 120b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), 0); 121b6fec18fSAlexander Duyck 122b6fec18fSAlexander Duyck /* loop through all PF ITR2 registers pointing them to the previous */ 123b6fec18fSAlexander Duyck for (i = 1; i < FM10K_ITR_REG_COUNT_PF; i++) 124b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(i), i - 1); 125b6fec18fSAlexander Duyck 126b6fec18fSAlexander Duyck /* Enable interrupt moderator if not already enabled */ 127b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR); 128b6fec18fSAlexander Duyck 129b6fec18fSAlexander Duyck /* compute the default txqctl configuration */ 130b6fec18fSAlexander Duyck txqctl = FM10K_TXQCTL_PF | FM10K_TXQCTL_UNLIMITED_BW | 131b6fec18fSAlexander Duyck (hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT); 132b6fec18fSAlexander Duyck 133b6fec18fSAlexander Duyck for (i = 0; i < FM10K_MAX_QUEUES; i++) { 134b6fec18fSAlexander Duyck /* configure rings for 256 Queue / 32 Descriptor cache mode */ 135b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_TQDLOC(i), 136b6fec18fSAlexander Duyck (i * FM10K_TQDLOC_BASE_32_DESC) | 137b6fec18fSAlexander Duyck FM10K_TQDLOC_SIZE_32_DESC); 138b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl); 139b6fec18fSAlexander Duyck 140b6fec18fSAlexander Duyck /* configure rings to provide TPH processing hints */ 141b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_TPH_TXCTRL(i), 142b6fec18fSAlexander Duyck FM10K_TPH_TXCTRL_DESC_TPHEN | 143b6fec18fSAlexander Duyck FM10K_TPH_TXCTRL_DESC_RROEN | 144b6fec18fSAlexander Duyck FM10K_TPH_TXCTRL_DESC_WROEN | 145b6fec18fSAlexander Duyck FM10K_TPH_TXCTRL_DATA_RROEN); 146b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_TPH_RXCTRL(i), 147b6fec18fSAlexander Duyck FM10K_TPH_RXCTRL_DESC_TPHEN | 148b6fec18fSAlexander Duyck FM10K_TPH_RXCTRL_DESC_RROEN | 149b6fec18fSAlexander Duyck FM10K_TPH_RXCTRL_DATA_WROEN | 150b6fec18fSAlexander Duyck FM10K_TPH_RXCTRL_HDR_WROEN); 151b6fec18fSAlexander Duyck } 152b6fec18fSAlexander Duyck 15320076fa1SJacob Keller /* set max hold interval to align with 1.024 usec in all modes and 15420076fa1SJacob Keller * store ITR scale 15520076fa1SJacob Keller */ 156b6fec18fSAlexander Duyck switch (hw->bus.speed) { 157b6fec18fSAlexander Duyck case fm10k_bus_speed_2500: 158b6fec18fSAlexander Duyck dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1; 15920076fa1SJacob Keller hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN1; 160b6fec18fSAlexander Duyck break; 161b6fec18fSAlexander Duyck case fm10k_bus_speed_5000: 162b6fec18fSAlexander Duyck dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2; 16320076fa1SJacob Keller hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN2; 164b6fec18fSAlexander Duyck break; 165b6fec18fSAlexander Duyck case fm10k_bus_speed_8000: 166b6fec18fSAlexander Duyck dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3; 16720076fa1SJacob Keller hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3; 168b6fec18fSAlexander Duyck break; 169b6fec18fSAlexander Duyck default: 170b6fec18fSAlexander Duyck dma_ctrl = 0; 17120076fa1SJacob Keller /* just in case, assume Gen3 ITR scale */ 17220076fa1SJacob Keller hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3; 173b6fec18fSAlexander Duyck break; 174b6fec18fSAlexander Duyck } 175b6fec18fSAlexander Duyck 176b6fec18fSAlexander Duyck /* Configure TSO flags */ 177b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DTXTCPFLGL, FM10K_TSO_FLAGS_LOW); 178b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DTXTCPFLGH, FM10K_TSO_FLAGS_HI); 179b6fec18fSAlexander Duyck 180b6fec18fSAlexander Duyck /* Enable DMA engine 181b6fec18fSAlexander Duyck * Set Rx Descriptor size to 32 182b6fec18fSAlexander Duyck * Set Minimum MSS to 64 183b6fec18fSAlexander Duyck * Set Maximum number of Rx queues to 256 / 32 Descriptor 184b6fec18fSAlexander Duyck */ 185b6fec18fSAlexander Duyck dma_ctrl |= FM10K_DMA_CTRL_TX_ENABLE | FM10K_DMA_CTRL_RX_ENABLE | 186b6fec18fSAlexander Duyck FM10K_DMA_CTRL_RX_DESC_SIZE | FM10K_DMA_CTRL_MINMSS_64 | 187b6fec18fSAlexander Duyck FM10K_DMA_CTRL_32_DESC; 188b6fec18fSAlexander Duyck 189b6fec18fSAlexander Duyck fm10k_write_reg(hw, FM10K_DMA_CTRL, dma_ctrl); 190b6fec18fSAlexander Duyck 191b6fec18fSAlexander Duyck /* record maximum queue count, we limit ourselves to 128 */ 192b6fec18fSAlexander Duyck hw->mac.max_queues = FM10K_MAX_QUEUES_PF; 193b6fec18fSAlexander Duyck 194c2653865SAlexander Duyck /* We support either 64 VFs or 7 VFs depending on if we have ARI */ 195c2653865SAlexander Duyck hw->iov.total_vfs = fm10k_is_ari_hierarchy_pf(hw) ? 64 : 7; 196c2653865SAlexander Duyck 197b6fec18fSAlexander Duyck return 0; 198b6fec18fSAlexander Duyck } 199b6fec18fSAlexander Duyck 200b6fec18fSAlexander Duyck /** 201401b5383SAlexander Duyck * fm10k_update_vlan_pf - Update status of VLAN ID in VLAN filter table 202401b5383SAlexander Duyck * @hw: pointer to hardware structure 203401b5383SAlexander Duyck * @vid: VLAN ID to add to table 204401b5383SAlexander Duyck * @vsi: Index indicating VF ID or PF ID in table 205401b5383SAlexander Duyck * @set: Indicates if this is a set or clear operation 206401b5383SAlexander Duyck * 207401b5383SAlexander Duyck * This function adds or removes the corresponding VLAN ID from the VLAN 208401b5383SAlexander Duyck * filter table for the corresponding function. In addition to the 209401b5383SAlexander Duyck * standard set/clear that supports one bit a multi-bit write is 210401b5383SAlexander Duyck * supported to set 64 bits at a time. 211401b5383SAlexander Duyck **/ 212401b5383SAlexander Duyck static s32 fm10k_update_vlan_pf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set) 213401b5383SAlexander Duyck { 214401b5383SAlexander Duyck u32 vlan_table, reg, mask, bit, len; 215401b5383SAlexander Duyck 216401b5383SAlexander Duyck /* verify the VSI index is valid */ 217401b5383SAlexander Duyck if (vsi > FM10K_VLAN_TABLE_VSI_MAX) 218401b5383SAlexander Duyck return FM10K_ERR_PARAM; 219401b5383SAlexander Duyck 220401b5383SAlexander Duyck /* VLAN multi-bit write: 221401b5383SAlexander Duyck * The multi-bit write has several parts to it. 222401b5383SAlexander Duyck * 3 2 1 0 223401b5383SAlexander Duyck * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 224401b5383SAlexander Duyck * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 225401b5383SAlexander Duyck * | RSVD0 | Length |C|RSVD0| VLAN ID | 226401b5383SAlexander Duyck * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 227401b5383SAlexander Duyck * 228401b5383SAlexander Duyck * VLAN ID: Vlan Starting value 229401b5383SAlexander Duyck * RSVD0: Reserved section, must be 0 230401b5383SAlexander Duyck * C: Flag field, 0 is set, 1 is clear (Used in VF VLAN message) 231401b5383SAlexander Duyck * Length: Number of times to repeat the bit being set 232401b5383SAlexander Duyck */ 233401b5383SAlexander Duyck len = vid >> 16; 234401b5383SAlexander Duyck vid = (vid << 17) >> 17; 235401b5383SAlexander Duyck 236401b5383SAlexander Duyck /* verify the reserved 0 fields are 0 */ 237eca32047SMatthew Vick if (len >= FM10K_VLAN_TABLE_VID_MAX || vid >= FM10K_VLAN_TABLE_VID_MAX) 238401b5383SAlexander Duyck return FM10K_ERR_PARAM; 239401b5383SAlexander Duyck 240401b5383SAlexander Duyck /* Loop through the table updating all required VLANs */ 241401b5383SAlexander Duyck for (reg = FM10K_VLAN_TABLE(vsi, vid / 32), bit = vid % 32; 242401b5383SAlexander Duyck len < FM10K_VLAN_TABLE_VID_MAX; 243401b5383SAlexander Duyck len -= 32 - bit, reg++, bit = 0) { 244401b5383SAlexander Duyck /* record the initial state of the register */ 245401b5383SAlexander Duyck vlan_table = fm10k_read_reg(hw, reg); 246401b5383SAlexander Duyck 247401b5383SAlexander Duyck /* truncate mask if we are at the start or end of the run */ 248401b5383SAlexander Duyck mask = (~(u32)0 >> ((len < 31) ? 31 - len : 0)) << bit; 249401b5383SAlexander Duyck 250401b5383SAlexander Duyck /* make necessary modifications to the register */ 251401b5383SAlexander Duyck mask &= set ? ~vlan_table : vlan_table; 252401b5383SAlexander Duyck if (mask) 253401b5383SAlexander Duyck fm10k_write_reg(hw, reg, vlan_table ^ mask); 254401b5383SAlexander Duyck } 255401b5383SAlexander Duyck 256401b5383SAlexander Duyck return 0; 257401b5383SAlexander Duyck } 258401b5383SAlexander Duyck 259401b5383SAlexander Duyck /** 260b6fec18fSAlexander Duyck * fm10k_read_mac_addr_pf - Read device MAC address 261b6fec18fSAlexander Duyck * @hw: pointer to the HW structure 262b6fec18fSAlexander Duyck * 263b6fec18fSAlexander Duyck * Reads the device MAC address from the SM_AREA and stores the value. 264b6fec18fSAlexander Duyck **/ 265b6fec18fSAlexander Duyck static s32 fm10k_read_mac_addr_pf(struct fm10k_hw *hw) 266b6fec18fSAlexander Duyck { 267b6fec18fSAlexander Duyck u8 perm_addr[ETH_ALEN]; 268b6fec18fSAlexander Duyck u32 serial_num; 269b6fec18fSAlexander Duyck 270b6fec18fSAlexander Duyck serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(1)); 271b6fec18fSAlexander Duyck 272b6fec18fSAlexander Duyck /* last byte should be all 1's */ 273b6fec18fSAlexander Duyck if ((~serial_num) << 24) 274b6fec18fSAlexander Duyck return FM10K_ERR_INVALID_MAC_ADDR; 275b6fec18fSAlexander Duyck 276b6fec18fSAlexander Duyck perm_addr[0] = (u8)(serial_num >> 24); 277b6fec18fSAlexander Duyck perm_addr[1] = (u8)(serial_num >> 16); 278b6fec18fSAlexander Duyck perm_addr[2] = (u8)(serial_num >> 8); 279b6fec18fSAlexander Duyck 280b6fec18fSAlexander Duyck serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(0)); 281b6fec18fSAlexander Duyck 282b6fec18fSAlexander Duyck /* first byte should be all 1's */ 283b6fec18fSAlexander Duyck if ((~serial_num) >> 24) 284b6fec18fSAlexander Duyck return FM10K_ERR_INVALID_MAC_ADDR; 285b6fec18fSAlexander Duyck 286b6fec18fSAlexander Duyck perm_addr[3] = (u8)(serial_num >> 16); 287b6fec18fSAlexander Duyck perm_addr[4] = (u8)(serial_num >> 8); 288b6fec18fSAlexander Duyck perm_addr[5] = (u8)(serial_num); 289b6fec18fSAlexander Duyck 290f0cf5c98SJacob Keller ether_addr_copy(hw->mac.perm_addr, perm_addr); 291f0cf5c98SJacob Keller ether_addr_copy(hw->mac.addr, perm_addr); 292b6fec18fSAlexander Duyck 293b6fec18fSAlexander Duyck return 0; 294b6fec18fSAlexander Duyck } 295b6fec18fSAlexander Duyck 296b6fec18fSAlexander Duyck /** 297401b5383SAlexander Duyck * fm10k_glort_valid_pf - Validate that the provided glort is valid 298401b5383SAlexander Duyck * @hw: pointer to the HW structure 299401b5383SAlexander Duyck * @glort: base glort to be validated 300401b5383SAlexander Duyck * 301401b5383SAlexander Duyck * This function will return an error if the provided glort is invalid 302401b5383SAlexander Duyck **/ 303401b5383SAlexander Duyck bool fm10k_glort_valid_pf(struct fm10k_hw *hw, u16 glort) 304401b5383SAlexander Duyck { 305401b5383SAlexander Duyck glort &= hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT; 306401b5383SAlexander Duyck 307401b5383SAlexander Duyck return glort == (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE); 308401b5383SAlexander Duyck } 309401b5383SAlexander Duyck 310401b5383SAlexander Duyck /** 311eca32047SMatthew Vick * fm10k_update_xc_addr_pf - Update device addresses 312401b5383SAlexander Duyck * @hw: pointer to the HW structure 313401b5383SAlexander Duyck * @glort: base resource tag for this request 314401b5383SAlexander Duyck * @mac: MAC address to add/remove from table 315401b5383SAlexander Duyck * @vid: VLAN ID to add/remove from table 316401b5383SAlexander Duyck * @add: Indicates if this is an add or remove operation 317401b5383SAlexander Duyck * @flags: flags field to indicate add and secure 318401b5383SAlexander Duyck * 319401b5383SAlexander Duyck * This function generates a message to the Switch API requesting 320401b5383SAlexander Duyck * that the given logical port add/remove the given L2 MAC/VLAN address. 321401b5383SAlexander Duyck **/ 322401b5383SAlexander Duyck static s32 fm10k_update_xc_addr_pf(struct fm10k_hw *hw, u16 glort, 323401b5383SAlexander Duyck const u8 *mac, u16 vid, bool add, u8 flags) 324401b5383SAlexander Duyck { 325401b5383SAlexander Duyck struct fm10k_mbx_info *mbx = &hw->mbx; 326401b5383SAlexander Duyck struct fm10k_mac_update mac_update; 327401b5383SAlexander Duyck u32 msg[5]; 328401b5383SAlexander Duyck 329b32d15b9SJeff Kirsher /* clear set bit from VLAN ID */ 330b32d15b9SJeff Kirsher vid &= ~FM10K_VLAN_CLEAR; 331b32d15b9SJeff Kirsher 332aa502b4aSJacob Keller /* if glort or VLAN are not valid return error */ 33333a44c28SMatthew Vick if (!fm10k_glort_valid_pf(hw, glort) || vid >= FM10K_VLAN_TABLE_VID_MAX) 334401b5383SAlexander Duyck return FM10K_ERR_PARAM; 335401b5383SAlexander Duyck 336401b5383SAlexander Duyck /* record fields */ 337401b5383SAlexander Duyck mac_update.mac_lower = cpu_to_le32(((u32)mac[2] << 24) | 338401b5383SAlexander Duyck ((u32)mac[3] << 16) | 339401b5383SAlexander Duyck ((u32)mac[4] << 8) | 340401b5383SAlexander Duyck ((u32)mac[5])); 3419d4955b4SJacob Keller mac_update.mac_upper = cpu_to_le16(((u16)mac[0] << 8) | 3429d4955b4SJacob Keller ((u16)mac[1])); 343401b5383SAlexander Duyck mac_update.vlan = cpu_to_le16(vid); 344401b5383SAlexander Duyck mac_update.glort = cpu_to_le16(glort); 345401b5383SAlexander Duyck mac_update.action = add ? 0 : 1; 346401b5383SAlexander Duyck mac_update.flags = flags; 347401b5383SAlexander Duyck 348401b5383SAlexander Duyck /* populate mac_update fields */ 349401b5383SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE); 350401b5383SAlexander Duyck fm10k_tlv_attr_put_le_struct(msg, FM10K_PF_ATTR_ID_MAC_UPDATE, 351401b5383SAlexander Duyck &mac_update, sizeof(mac_update)); 352401b5383SAlexander Duyck 353401b5383SAlexander Duyck /* load onto outgoing mailbox */ 354401b5383SAlexander Duyck return mbx->ops.enqueue_tx(hw, mbx, msg); 355401b5383SAlexander Duyck } 356401b5383SAlexander Duyck 357401b5383SAlexander Duyck /** 358eca32047SMatthew Vick * fm10k_update_uc_addr_pf - Update device unicast addresses 359401b5383SAlexander Duyck * @hw: pointer to the HW structure 360401b5383SAlexander Duyck * @glort: base resource tag for this request 361401b5383SAlexander Duyck * @mac: MAC address to add/remove from table 362401b5383SAlexander Duyck * @vid: VLAN ID to add/remove from table 363401b5383SAlexander Duyck * @add: Indicates if this is an add or remove operation 364401b5383SAlexander Duyck * @flags: flags field to indicate add and secure 365401b5383SAlexander Duyck * 366401b5383SAlexander Duyck * This function is used to add or remove unicast addresses for 367401b5383SAlexander Duyck * the PF. 368401b5383SAlexander Duyck **/ 369401b5383SAlexander Duyck static s32 fm10k_update_uc_addr_pf(struct fm10k_hw *hw, u16 glort, 370401b5383SAlexander Duyck const u8 *mac, u16 vid, bool add, u8 flags) 371401b5383SAlexander Duyck { 372401b5383SAlexander Duyck /* verify MAC address is valid */ 373401b5383SAlexander Duyck if (!is_valid_ether_addr(mac)) 374401b5383SAlexander Duyck return FM10K_ERR_PARAM; 375401b5383SAlexander Duyck 376401b5383SAlexander Duyck return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, flags); 377401b5383SAlexander Duyck } 378401b5383SAlexander Duyck 379401b5383SAlexander Duyck /** 380401b5383SAlexander Duyck * fm10k_update_mc_addr_pf - Update device multicast addresses 381401b5383SAlexander Duyck * @hw: pointer to the HW structure 382401b5383SAlexander Duyck * @glort: base resource tag for this request 383401b5383SAlexander Duyck * @mac: MAC address to add/remove from table 384401b5383SAlexander Duyck * @vid: VLAN ID to add/remove from table 385401b5383SAlexander Duyck * @add: Indicates if this is an add or remove operation 386401b5383SAlexander Duyck * 387401b5383SAlexander Duyck * This function is used to add or remove multicast MAC addresses for 388401b5383SAlexander Duyck * the PF. 389401b5383SAlexander Duyck **/ 390401b5383SAlexander Duyck static s32 fm10k_update_mc_addr_pf(struct fm10k_hw *hw, u16 glort, 391401b5383SAlexander Duyck const u8 *mac, u16 vid, bool add) 392401b5383SAlexander Duyck { 393401b5383SAlexander Duyck /* verify multicast address is valid */ 394401b5383SAlexander Duyck if (!is_multicast_ether_addr(mac)) 395401b5383SAlexander Duyck return FM10K_ERR_PARAM; 396401b5383SAlexander Duyck 397401b5383SAlexander Duyck return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, 0); 398401b5383SAlexander Duyck } 399401b5383SAlexander Duyck 400401b5383SAlexander Duyck /** 401401b5383SAlexander Duyck * fm10k_update_xcast_mode_pf - Request update of multicast mode 402401b5383SAlexander Duyck * @hw: pointer to hardware structure 403401b5383SAlexander Duyck * @glort: base resource tag for this request 404401b5383SAlexander Duyck * @mode: integer value indicating mode being requested 405401b5383SAlexander Duyck * 406401b5383SAlexander Duyck * This function will attempt to request a higher mode for the port 407401b5383SAlexander Duyck * so that it can enable either multicast, multicast promiscuous, or 408401b5383SAlexander Duyck * promiscuous mode of operation. 409401b5383SAlexander Duyck **/ 410401b5383SAlexander Duyck static s32 fm10k_update_xcast_mode_pf(struct fm10k_hw *hw, u16 glort, u8 mode) 411401b5383SAlexander Duyck { 412401b5383SAlexander Duyck struct fm10k_mbx_info *mbx = &hw->mbx; 413401b5383SAlexander Duyck u32 msg[3], xcast_mode; 414401b5383SAlexander Duyck 415401b5383SAlexander Duyck if (mode > FM10K_XCAST_MODE_NONE) 416401b5383SAlexander Duyck return FM10K_ERR_PARAM; 417401b5383SAlexander Duyck /* if glort is not valid return error */ 418401b5383SAlexander Duyck if (!fm10k_glort_valid_pf(hw, glort)) 419401b5383SAlexander Duyck return FM10K_ERR_PARAM; 420401b5383SAlexander Duyck 421401b5383SAlexander Duyck /* write xcast mode as a single u32 value, 422401b5383SAlexander Duyck * lower 16 bits: glort 423401b5383SAlexander Duyck * upper 16 bits: mode 424401b5383SAlexander Duyck */ 425401b5383SAlexander Duyck xcast_mode = ((u32)mode << 16) | glort; 426401b5383SAlexander Duyck 427401b5383SAlexander Duyck /* generate message requesting to change xcast mode */ 428401b5383SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_XCAST_MODES); 429401b5383SAlexander Duyck fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_XCAST_MODE, xcast_mode); 430401b5383SAlexander Duyck 431401b5383SAlexander Duyck /* load onto outgoing mailbox */ 432401b5383SAlexander Duyck return mbx->ops.enqueue_tx(hw, mbx, msg); 433401b5383SAlexander Duyck } 434401b5383SAlexander Duyck 435401b5383SAlexander Duyck /** 436401b5383SAlexander Duyck * fm10k_update_int_moderator_pf - Update interrupt moderator linked list 437401b5383SAlexander Duyck * @hw: pointer to hardware structure 438401b5383SAlexander Duyck * 439401b5383SAlexander Duyck * This function walks through the MSI-X vector table to determine the 440401b5383SAlexander Duyck * number of active interrupts and based on that information updates the 441401b5383SAlexander Duyck * interrupt moderator linked list. 442401b5383SAlexander Duyck **/ 443401b5383SAlexander Duyck static void fm10k_update_int_moderator_pf(struct fm10k_hw *hw) 444401b5383SAlexander Duyck { 445401b5383SAlexander Duyck u32 i; 446401b5383SAlexander Duyck 447401b5383SAlexander Duyck /* Disable interrupt moderator */ 448401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_INT_CTRL, 0); 449401b5383SAlexander Duyck 450401b5383SAlexander Duyck /* loop through PF from last to first looking enabled vectors */ 451401b5383SAlexander Duyck for (i = FM10K_ITR_REG_COUNT_PF - 1; i; i--) { 452401b5383SAlexander Duyck if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i))) 453401b5383SAlexander Duyck break; 454401b5383SAlexander Duyck } 455401b5383SAlexander Duyck 456401b5383SAlexander Duyck /* always reset VFITR2[0] to point to last enabled PF vector */ 457401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), i); 458401b5383SAlexander Duyck 459401b5383SAlexander Duyck /* reset ITR2[0] to point to last enabled PF vector */ 460c2653865SAlexander Duyck if (!hw->iov.num_vfs) 461401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), i); 462401b5383SAlexander Duyck 463401b5383SAlexander Duyck /* Enable interrupt moderator */ 464401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR); 465401b5383SAlexander Duyck } 466401b5383SAlexander Duyck 467401b5383SAlexander Duyck /** 468401b5383SAlexander Duyck * fm10k_update_lport_state_pf - Notify the switch of a change in port state 469401b5383SAlexander Duyck * @hw: pointer to the HW structure 470401b5383SAlexander Duyck * @glort: base resource tag for this request 471401b5383SAlexander Duyck * @count: number of logical ports being updated 472401b5383SAlexander Duyck * @enable: boolean value indicating enable or disable 473401b5383SAlexander Duyck * 474401b5383SAlexander Duyck * This function is used to add/remove a logical port from the switch. 475401b5383SAlexander Duyck **/ 476401b5383SAlexander Duyck static s32 fm10k_update_lport_state_pf(struct fm10k_hw *hw, u16 glort, 477401b5383SAlexander Duyck u16 count, bool enable) 478401b5383SAlexander Duyck { 479401b5383SAlexander Duyck struct fm10k_mbx_info *mbx = &hw->mbx; 480401b5383SAlexander Duyck u32 msg[3], lport_msg; 481401b5383SAlexander Duyck 482401b5383SAlexander Duyck /* do nothing if we are being asked to create or destroy 0 ports */ 483401b5383SAlexander Duyck if (!count) 484401b5383SAlexander Duyck return 0; 485401b5383SAlexander Duyck 486401b5383SAlexander Duyck /* if glort is not valid return error */ 487401b5383SAlexander Duyck if (!fm10k_glort_valid_pf(hw, glort)) 488401b5383SAlexander Duyck return FM10K_ERR_PARAM; 489401b5383SAlexander Duyck 490401b5383SAlexander Duyck /* construct the lport message from the 2 pieces of data we have */ 491401b5383SAlexander Duyck lport_msg = ((u32)count << 16) | glort; 492401b5383SAlexander Duyck 493401b5383SAlexander Duyck /* generate lport create/delete message */ 494401b5383SAlexander Duyck fm10k_tlv_msg_init(msg, enable ? FM10K_PF_MSG_ID_LPORT_CREATE : 495401b5383SAlexander Duyck FM10K_PF_MSG_ID_LPORT_DELETE); 496401b5383SAlexander Duyck fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_PORT, lport_msg); 497401b5383SAlexander Duyck 498401b5383SAlexander Duyck /* load onto outgoing mailbox */ 499401b5383SAlexander Duyck return mbx->ops.enqueue_tx(hw, mbx, msg); 500401b5383SAlexander Duyck } 501401b5383SAlexander Duyck 502401b5383SAlexander Duyck /** 503401b5383SAlexander Duyck * fm10k_configure_dglort_map_pf - Configures GLORT entry and queues 504401b5383SAlexander Duyck * @hw: pointer to hardware structure 505401b5383SAlexander Duyck * @dglort: pointer to dglort configuration structure 506401b5383SAlexander Duyck * 507401b5383SAlexander Duyck * Reads the configuration structure contained in dglort_cfg and uses 508401b5383SAlexander Duyck * that information to then populate a DGLORTMAP/DEC entry and the queues 509401b5383SAlexander Duyck * to which it has been assigned. 510401b5383SAlexander Duyck **/ 511401b5383SAlexander Duyck static s32 fm10k_configure_dglort_map_pf(struct fm10k_hw *hw, 512401b5383SAlexander Duyck struct fm10k_dglort_cfg *dglort) 513401b5383SAlexander Duyck { 514401b5383SAlexander Duyck u16 glort, queue_count, vsi_count, pc_count; 515401b5383SAlexander Duyck u16 vsi, queue, pc, q_idx; 516401b5383SAlexander Duyck u32 txqctl, dglortdec, dglortmap; 517401b5383SAlexander Duyck 518401b5383SAlexander Duyck /* verify the dglort pointer */ 519401b5383SAlexander Duyck if (!dglort) 520401b5383SAlexander Duyck return FM10K_ERR_PARAM; 521401b5383SAlexander Duyck 522401b5383SAlexander Duyck /* verify the dglort values */ 523401b5383SAlexander Duyck if ((dglort->idx > 7) || (dglort->rss_l > 7) || (dglort->pc_l > 3) || 524401b5383SAlexander Duyck (dglort->vsi_l > 6) || (dglort->vsi_b > 64) || 525401b5383SAlexander Duyck (dglort->queue_l > 8) || (dglort->queue_b >= 256)) 526401b5383SAlexander Duyck return FM10K_ERR_PARAM; 527401b5383SAlexander Duyck 528401b5383SAlexander Duyck /* determine count of VSIs and queues */ 529401b5383SAlexander Duyck queue_count = 1 << (dglort->rss_l + dglort->pc_l); 530401b5383SAlexander Duyck vsi_count = 1 << (dglort->vsi_l + dglort->queue_l); 531401b5383SAlexander Duyck glort = dglort->glort; 532401b5383SAlexander Duyck q_idx = dglort->queue_b; 533401b5383SAlexander Duyck 534401b5383SAlexander Duyck /* configure SGLORT for queues */ 535401b5383SAlexander Duyck for (vsi = 0; vsi < vsi_count; vsi++, glort++) { 536401b5383SAlexander Duyck for (queue = 0; queue < queue_count; queue++, q_idx++) { 537401b5383SAlexander Duyck if (q_idx >= FM10K_MAX_QUEUES) 538401b5383SAlexander Duyck break; 539401b5383SAlexander Duyck 540401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_TX_SGLORT(q_idx), glort); 541401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_RX_SGLORT(q_idx), glort); 542401b5383SAlexander Duyck } 543401b5383SAlexander Duyck } 544401b5383SAlexander Duyck 545401b5383SAlexander Duyck /* determine count of PCs and queues */ 546401b5383SAlexander Duyck queue_count = 1 << (dglort->queue_l + dglort->rss_l + dglort->vsi_l); 547401b5383SAlexander Duyck pc_count = 1 << dglort->pc_l; 548401b5383SAlexander Duyck 549401b5383SAlexander Duyck /* configure PC for Tx queues */ 550401b5383SAlexander Duyck for (pc = 0; pc < pc_count; pc++) { 551401b5383SAlexander Duyck q_idx = pc + dglort->queue_b; 552401b5383SAlexander Duyck for (queue = 0; queue < queue_count; queue++) { 553401b5383SAlexander Duyck if (q_idx >= FM10K_MAX_QUEUES) 554401b5383SAlexander Duyck break; 555401b5383SAlexander Duyck 556401b5383SAlexander Duyck txqctl = fm10k_read_reg(hw, FM10K_TXQCTL(q_idx)); 557401b5383SAlexander Duyck txqctl &= ~FM10K_TXQCTL_PC_MASK; 558401b5383SAlexander Duyck txqctl |= pc << FM10K_TXQCTL_PC_SHIFT; 559401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_TXQCTL(q_idx), txqctl); 560401b5383SAlexander Duyck 561401b5383SAlexander Duyck q_idx += pc_count; 562401b5383SAlexander Duyck } 563401b5383SAlexander Duyck } 564401b5383SAlexander Duyck 565401b5383SAlexander Duyck /* configure DGLORTDEC */ 566401b5383SAlexander Duyck dglortdec = ((u32)(dglort->rss_l) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) | 567401b5383SAlexander Duyck ((u32)(dglort->queue_b) << FM10K_DGLORTDEC_QBASE_SHIFT) | 568401b5383SAlexander Duyck ((u32)(dglort->pc_l) << FM10K_DGLORTDEC_PCLENGTH_SHIFT) | 569401b5383SAlexander Duyck ((u32)(dglort->vsi_b) << FM10K_DGLORTDEC_VSIBASE_SHIFT) | 570401b5383SAlexander Duyck ((u32)(dglort->vsi_l) << FM10K_DGLORTDEC_VSILENGTH_SHIFT) | 571401b5383SAlexander Duyck ((u32)(dglort->queue_l)); 572401b5383SAlexander Duyck if (dglort->inner_rss) 573401b5383SAlexander Duyck dglortdec |= FM10K_DGLORTDEC_INNERRSS_ENABLE; 574401b5383SAlexander Duyck 575401b5383SAlexander Duyck /* configure DGLORTMAP */ 576401b5383SAlexander Duyck dglortmap = (dglort->idx == fm10k_dglort_default) ? 577401b5383SAlexander Duyck FM10K_DGLORTMAP_ANY : FM10K_DGLORTMAP_ZERO; 578401b5383SAlexander Duyck dglortmap <<= dglort->vsi_l + dglort->queue_l + dglort->shared_l; 579401b5383SAlexander Duyck dglortmap |= dglort->glort; 580401b5383SAlexander Duyck 581401b5383SAlexander Duyck /* write values to hardware */ 582401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_DGLORTDEC(dglort->idx), dglortdec); 583401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_DGLORTMAP(dglort->idx), dglortmap); 584401b5383SAlexander Duyck 585401b5383SAlexander Duyck return 0; 586401b5383SAlexander Duyck } 587401b5383SAlexander Duyck 588c2653865SAlexander Duyck u16 fm10k_queues_per_pool(struct fm10k_hw *hw) 589c2653865SAlexander Duyck { 590c2653865SAlexander Duyck u16 num_pools = hw->iov.num_pools; 591c2653865SAlexander Duyck 592c2653865SAlexander Duyck return (num_pools > 32) ? 2 : (num_pools > 16) ? 4 : (num_pools > 8) ? 593c2653865SAlexander Duyck 8 : FM10K_MAX_QUEUES_POOL; 594c2653865SAlexander Duyck } 595c2653865SAlexander Duyck 596c2653865SAlexander Duyck u16 fm10k_vf_queue_index(struct fm10k_hw *hw, u16 vf_idx) 597c2653865SAlexander Duyck { 598c2653865SAlexander Duyck u16 num_vfs = hw->iov.num_vfs; 599c2653865SAlexander Duyck u16 vf_q_idx = FM10K_MAX_QUEUES; 600c2653865SAlexander Duyck 601c2653865SAlexander Duyck vf_q_idx -= fm10k_queues_per_pool(hw) * (num_vfs - vf_idx); 602c2653865SAlexander Duyck 603c2653865SAlexander Duyck return vf_q_idx; 604c2653865SAlexander Duyck } 605c2653865SAlexander Duyck 606c2653865SAlexander Duyck static u16 fm10k_vectors_per_pool(struct fm10k_hw *hw) 607c2653865SAlexander Duyck { 608c2653865SAlexander Duyck u16 num_pools = hw->iov.num_pools; 609c2653865SAlexander Duyck 610c2653865SAlexander Duyck return (num_pools > 32) ? 8 : (num_pools > 16) ? 16 : 611c2653865SAlexander Duyck FM10K_MAX_VECTORS_POOL; 612c2653865SAlexander Duyck } 613c2653865SAlexander Duyck 614c2653865SAlexander Duyck static u16 fm10k_vf_vector_index(struct fm10k_hw *hw, u16 vf_idx) 615c2653865SAlexander Duyck { 616c2653865SAlexander Duyck u16 vf_v_idx = FM10K_MAX_VECTORS_PF; 617c2653865SAlexander Duyck 618c2653865SAlexander Duyck vf_v_idx += fm10k_vectors_per_pool(hw) * vf_idx; 619c2653865SAlexander Duyck 620c2653865SAlexander Duyck return vf_v_idx; 621c2653865SAlexander Duyck } 622c2653865SAlexander Duyck 623c2653865SAlexander Duyck /** 624c2653865SAlexander Duyck * fm10k_iov_assign_resources_pf - Assign pool resources for virtualization 625c2653865SAlexander Duyck * @hw: pointer to the HW structure 626c2653865SAlexander Duyck * @num_vfs: number of VFs to be allocated 627c2653865SAlexander Duyck * @num_pools: number of virtualization pools to be allocated 628c2653865SAlexander Duyck * 629c2653865SAlexander Duyck * Allocates queues and traffic classes to virtualization entities to prepare 630c2653865SAlexander Duyck * the PF for SR-IOV and VMDq 631c2653865SAlexander Duyck **/ 632c2653865SAlexander Duyck static s32 fm10k_iov_assign_resources_pf(struct fm10k_hw *hw, u16 num_vfs, 633c2653865SAlexander Duyck u16 num_pools) 634c2653865SAlexander Duyck { 635c2653865SAlexander Duyck u16 qmap_stride, qpp, vpp, vf_q_idx, vf_q_idx0, qmap_idx; 636c2653865SAlexander Duyck u32 vid = hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT; 637c2653865SAlexander Duyck int i, j; 638c2653865SAlexander Duyck 639c2653865SAlexander Duyck /* hardware only supports up to 64 pools */ 640c2653865SAlexander Duyck if (num_pools > 64) 641c2653865SAlexander Duyck return FM10K_ERR_PARAM; 642c2653865SAlexander Duyck 643c2653865SAlexander Duyck /* the number of VFs cannot exceed the number of pools */ 644c2653865SAlexander Duyck if ((num_vfs > num_pools) || (num_vfs > hw->iov.total_vfs)) 645c2653865SAlexander Duyck return FM10K_ERR_PARAM; 646c2653865SAlexander Duyck 647c2653865SAlexander Duyck /* record number of virtualization entities */ 648c2653865SAlexander Duyck hw->iov.num_vfs = num_vfs; 649c2653865SAlexander Duyck hw->iov.num_pools = num_pools; 650c2653865SAlexander Duyck 651c2653865SAlexander Duyck /* determine qmap offsets and counts */ 652c2653865SAlexander Duyck qmap_stride = (num_vfs > 8) ? 32 : 256; 653c2653865SAlexander Duyck qpp = fm10k_queues_per_pool(hw); 654c2653865SAlexander Duyck vpp = fm10k_vectors_per_pool(hw); 655c2653865SAlexander Duyck 656c2653865SAlexander Duyck /* calculate starting index for queues */ 657c2653865SAlexander Duyck vf_q_idx = fm10k_vf_queue_index(hw, 0); 658c2653865SAlexander Duyck qmap_idx = 0; 659c2653865SAlexander Duyck 660c2653865SAlexander Duyck /* establish TCs with -1 credits and no quanta to prevent transmit */ 661c2653865SAlexander Duyck for (i = 0; i < num_vfs; i++) { 662c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(i), 0); 663c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_RATE(i), 0); 664c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_CREDIT(i), 665c2653865SAlexander Duyck FM10K_TC_CREDIT_CREDIT_MASK); 666c2653865SAlexander Duyck } 667c2653865SAlexander Duyck 668c2653865SAlexander Duyck /* zero out all mbmem registers */ 669c2653865SAlexander Duyck for (i = FM10K_VFMBMEM_LEN * num_vfs; i--;) 670c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_MBMEM(i), 0); 671c2653865SAlexander Duyck 672c2653865SAlexander Duyck /* clear event notification of VF FLR */ 673c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_PFVFLREC(0), ~0); 674c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_PFVFLREC(1), ~0); 675c2653865SAlexander Duyck 676c2653865SAlexander Duyck /* loop through unallocated rings assigning them back to PF */ 677c2653865SAlexander Duyck for (i = FM10K_MAX_QUEUES_PF; i < vf_q_idx; i++) { 678c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXDCTL(i), 0); 679ded8b20dSJeff Kirsher fm10k_write_reg(hw, FM10K_TXQCTL(i), FM10K_TXQCTL_PF | 680ded8b20dSJeff Kirsher FM10K_TXQCTL_UNLIMITED_BW | vid); 681c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RXQCTL(i), FM10K_RXQCTL_PF); 682c2653865SAlexander Duyck } 683c2653865SAlexander Duyck 684c2653865SAlexander Duyck /* PF should have already updated VFITR2[0] */ 685c2653865SAlexander Duyck 686c2653865SAlexander Duyck /* update all ITR registers to flow to VFITR2[0] */ 687c2653865SAlexander Duyck for (i = FM10K_ITR_REG_COUNT_PF + 1; i < FM10K_ITR_REG_COUNT; i++) { 688c2653865SAlexander Duyck if (!(i & (vpp - 1))) 689c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(i), i - vpp); 690c2653865SAlexander Duyck else 691c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(i), i - 1); 692c2653865SAlexander Duyck } 693c2653865SAlexander Duyck 694c2653865SAlexander Duyck /* update PF ITR2[0] to reference the last vector */ 695c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), 696c2653865SAlexander Duyck fm10k_vf_vector_index(hw, num_vfs - 1)); 697c2653865SAlexander Duyck 698c2653865SAlexander Duyck /* loop through rings populating rings and TCs */ 699c2653865SAlexander Duyck for (i = 0; i < num_vfs; i++) { 700c2653865SAlexander Duyck /* record index for VF queue 0 for use in end of loop */ 701c2653865SAlexander Duyck vf_q_idx0 = vf_q_idx; 702c2653865SAlexander Duyck 703c2653865SAlexander Duyck for (j = 0; j < qpp; j++, qmap_idx++, vf_q_idx++) { 704c2653865SAlexander Duyck /* assign VF and locked TC to queues */ 705c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0); 706c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx), 707c2653865SAlexander Duyck (i << FM10K_TXQCTL_TC_SHIFT) | i | 708c2653865SAlexander Duyck FM10K_TXQCTL_VF | vid); 709c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RXDCTL(vf_q_idx), 710c2653865SAlexander Duyck FM10K_RXDCTL_WRITE_BACK_MIN_DELAY | 711c2653865SAlexander Duyck FM10K_RXDCTL_DROP_ON_EMPTY); 712c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RXQCTL(vf_q_idx), 713c2653865SAlexander Duyck FM10K_RXQCTL_VF | 714c2653865SAlexander Duyck (i << FM10K_RXQCTL_VF_SHIFT)); 715c2653865SAlexander Duyck 716c2653865SAlexander Duyck /* map queue pair to VF */ 717c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx); 718c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx); 719c2653865SAlexander Duyck } 720c2653865SAlexander Duyck 721c2653865SAlexander Duyck /* repeat the first ring for all of the remaining VF rings */ 722c2653865SAlexander Duyck for (; j < qmap_stride; j++, qmap_idx++) { 723c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx0); 724c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx0); 725c2653865SAlexander Duyck } 726c2653865SAlexander Duyck } 727c2653865SAlexander Duyck 728c2653865SAlexander Duyck /* loop through remaining indexes assigning all to queue 0 */ 729c2653865SAlexander Duyck while (qmap_idx < FM10K_TQMAP_TABLE_SIZE) { 730c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0); 731c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), 0); 732c2653865SAlexander Duyck qmap_idx++; 733c2653865SAlexander Duyck } 734c2653865SAlexander Duyck 735c2653865SAlexander Duyck return 0; 736c2653865SAlexander Duyck } 737c2653865SAlexander Duyck 738c2653865SAlexander Duyck /** 739c2653865SAlexander Duyck * fm10k_iov_configure_tc_pf - Configure the shaping group for VF 740c2653865SAlexander Duyck * @hw: pointer to the HW structure 741c2653865SAlexander Duyck * @vf_idx: index of VF receiving GLORT 742c2653865SAlexander Duyck * @rate: Rate indicated in Mb/s 743c2653865SAlexander Duyck * 744c2653865SAlexander Duyck * Configured the TC for a given VF to allow only up to a given number 745c2653865SAlexander Duyck * of Mb/s of outgoing Tx throughput. 746c2653865SAlexander Duyck **/ 747c2653865SAlexander Duyck static s32 fm10k_iov_configure_tc_pf(struct fm10k_hw *hw, u16 vf_idx, int rate) 748c2653865SAlexander Duyck { 749c2653865SAlexander Duyck /* configure defaults */ 750c2653865SAlexander Duyck u32 interval = FM10K_TC_RATE_INTERVAL_4US_GEN3; 751c2653865SAlexander Duyck u32 tc_rate = FM10K_TC_RATE_QUANTA_MASK; 752c2653865SAlexander Duyck 753c2653865SAlexander Duyck /* verify vf is in range */ 754c2653865SAlexander Duyck if (vf_idx >= hw->iov.num_vfs) 755c2653865SAlexander Duyck return FM10K_ERR_PARAM; 756c2653865SAlexander Duyck 757c2653865SAlexander Duyck /* set interval to align with 4.096 usec in all modes */ 758c2653865SAlexander Duyck switch (hw->bus.speed) { 759c2653865SAlexander Duyck case fm10k_bus_speed_2500: 760c2653865SAlexander Duyck interval = FM10K_TC_RATE_INTERVAL_4US_GEN1; 761c2653865SAlexander Duyck break; 762c2653865SAlexander Duyck case fm10k_bus_speed_5000: 763c2653865SAlexander Duyck interval = FM10K_TC_RATE_INTERVAL_4US_GEN2; 764c2653865SAlexander Duyck break; 765c2653865SAlexander Duyck default: 766c2653865SAlexander Duyck break; 767c2653865SAlexander Duyck } 768c2653865SAlexander Duyck 769c2653865SAlexander Duyck if (rate) { 770c2653865SAlexander Duyck if (rate > FM10K_VF_TC_MAX || rate < FM10K_VF_TC_MIN) 771c2653865SAlexander Duyck return FM10K_ERR_PARAM; 772c2653865SAlexander Duyck 773c2653865SAlexander Duyck /* The quanta is measured in Bytes per 4.096 or 8.192 usec 774c2653865SAlexander Duyck * The rate is provided in Mbits per second 775c2653865SAlexander Duyck * To tralslate from rate to quanta we need to multiply the 776c2653865SAlexander Duyck * rate by 8.192 usec and divide by 8 bits/byte. To avoid 777c2653865SAlexander Duyck * dealing with floating point we can round the values up 778c2653865SAlexander Duyck * to the nearest whole number ratio which gives us 128 / 125. 779c2653865SAlexander Duyck */ 780c2653865SAlexander Duyck tc_rate = (rate * 128) / 125; 781c2653865SAlexander Duyck 782c2653865SAlexander Duyck /* try to keep the rate limiting accurate by increasing 783c2653865SAlexander Duyck * the number of credits and interval for rates less than 4Gb/s 784c2653865SAlexander Duyck */ 785c2653865SAlexander Duyck if (rate < 4000) 786c2653865SAlexander Duyck interval <<= 1; 787c2653865SAlexander Duyck else 788c2653865SAlexander Duyck tc_rate >>= 1; 789c2653865SAlexander Duyck } 790c2653865SAlexander Duyck 791c2653865SAlexander Duyck /* update rate limiter with new values */ 792c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), tc_rate | interval); 793c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K); 794c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K); 795c2653865SAlexander Duyck 796c2653865SAlexander Duyck return 0; 797c2653865SAlexander Duyck } 798c2653865SAlexander Duyck 799c2653865SAlexander Duyck /** 800c2653865SAlexander Duyck * fm10k_iov_assign_int_moderator_pf - Add VF interrupts to moderator list 801c2653865SAlexander Duyck * @hw: pointer to the HW structure 802c2653865SAlexander Duyck * @vf_idx: index of VF receiving GLORT 803c2653865SAlexander Duyck * 804c2653865SAlexander Duyck * Update the interrupt moderator linked list to include any MSI-X 805c2653865SAlexander Duyck * interrupts which the VF has enabled in the MSI-X vector table. 806c2653865SAlexander Duyck **/ 807c2653865SAlexander Duyck static s32 fm10k_iov_assign_int_moderator_pf(struct fm10k_hw *hw, u16 vf_idx) 808c2653865SAlexander Duyck { 809c2653865SAlexander Duyck u16 vf_v_idx, vf_v_limit, i; 810c2653865SAlexander Duyck 811c2653865SAlexander Duyck /* verify vf is in range */ 812c2653865SAlexander Duyck if (vf_idx >= hw->iov.num_vfs) 813c2653865SAlexander Duyck return FM10K_ERR_PARAM; 814c2653865SAlexander Duyck 815c2653865SAlexander Duyck /* determine vector offset and count */ 816c2653865SAlexander Duyck vf_v_idx = fm10k_vf_vector_index(hw, vf_idx); 817c2653865SAlexander Duyck vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw); 818c2653865SAlexander Duyck 819c2653865SAlexander Duyck /* search for first vector that is not masked */ 820c2653865SAlexander Duyck for (i = vf_v_limit - 1; i > vf_v_idx; i--) { 821c2653865SAlexander Duyck if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i))) 822c2653865SAlexander Duyck break; 823c2653865SAlexander Duyck } 824c2653865SAlexander Duyck 825c2653865SAlexander Duyck /* reset linked list so it now includes our active vectors */ 826c2653865SAlexander Duyck if (vf_idx == (hw->iov.num_vfs - 1)) 827c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), i); 828c2653865SAlexander Duyck else 829c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), i); 830c2653865SAlexander Duyck 831c2653865SAlexander Duyck return 0; 832c2653865SAlexander Duyck } 833c2653865SAlexander Duyck 834c2653865SAlexander Duyck /** 835c2653865SAlexander Duyck * fm10k_iov_assign_default_mac_vlan_pf - Assign a MAC and VLAN to VF 836c2653865SAlexander Duyck * @hw: pointer to the HW structure 837c2653865SAlexander Duyck * @vf_info: pointer to VF information structure 838c2653865SAlexander Duyck * 839c2653865SAlexander Duyck * Assign a MAC address and default VLAN to a VF and notify it of the update 840c2653865SAlexander Duyck **/ 841c2653865SAlexander Duyck static s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw, 842c2653865SAlexander Duyck struct fm10k_vf_info *vf_info) 843c2653865SAlexander Duyck { 844c2653865SAlexander Duyck u16 qmap_stride, queues_per_pool, vf_q_idx, timeout, qmap_idx, i; 845c2653865SAlexander Duyck u32 msg[4], txdctl, txqctl, tdbal = 0, tdbah = 0; 846c2653865SAlexander Duyck s32 err = 0; 847c2653865SAlexander Duyck u16 vf_idx, vf_vid; 848c2653865SAlexander Duyck 849c2653865SAlexander Duyck /* verify vf is in range */ 850c2653865SAlexander Duyck if (!vf_info || vf_info->vf_idx >= hw->iov.num_vfs) 851c2653865SAlexander Duyck return FM10K_ERR_PARAM; 852c2653865SAlexander Duyck 853c2653865SAlexander Duyck /* determine qmap offsets and counts */ 854c2653865SAlexander Duyck qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256; 855c2653865SAlexander Duyck queues_per_pool = fm10k_queues_per_pool(hw); 856c2653865SAlexander Duyck 857c2653865SAlexander Duyck /* calculate starting index for queues */ 858c2653865SAlexander Duyck vf_idx = vf_info->vf_idx; 859c2653865SAlexander Duyck vf_q_idx = fm10k_vf_queue_index(hw, vf_idx); 860c2653865SAlexander Duyck qmap_idx = qmap_stride * vf_idx; 861c2653865SAlexander Duyck 862c2653865SAlexander Duyck /* MAP Tx queue back to 0 temporarily, and disable it */ 863c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0); 864c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0); 865c2653865SAlexander Duyck 866c2653865SAlexander Duyck /* determine correct default VLAN ID */ 867c2653865SAlexander Duyck if (vf_info->pf_vid) 868c2653865SAlexander Duyck vf_vid = vf_info->pf_vid | FM10K_VLAN_CLEAR; 869c2653865SAlexander Duyck else 870c2653865SAlexander Duyck vf_vid = vf_info->sw_vid; 871c2653865SAlexander Duyck 872c2653865SAlexander Duyck /* generate MAC_ADDR request */ 873c2653865SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN); 874c2653865SAlexander Duyck fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_DEFAULT_MAC, 875c2653865SAlexander Duyck vf_info->mac, vf_vid); 876c2653865SAlexander Duyck 877c2653865SAlexander Duyck /* load onto outgoing mailbox, ignore any errors on enqueue */ 878c2653865SAlexander Duyck if (vf_info->mbx.ops.enqueue_tx) 879c2653865SAlexander Duyck vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg); 880c2653865SAlexander Duyck 881c2653865SAlexander Duyck /* verify ring has disabled before modifying base address registers */ 882c2653865SAlexander Duyck txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx)); 883c2653865SAlexander Duyck for (timeout = 0; txdctl & FM10K_TXDCTL_ENABLE; timeout++) { 884c2653865SAlexander Duyck /* limit ourselves to a 1ms timeout */ 885c2653865SAlexander Duyck if (timeout == 10) { 886c2653865SAlexander Duyck err = FM10K_ERR_DMA_PENDING; 887c2653865SAlexander Duyck goto err_out; 888c2653865SAlexander Duyck } 889c2653865SAlexander Duyck 890c2653865SAlexander Duyck usleep_range(100, 200); 891c2653865SAlexander Duyck txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx)); 892c2653865SAlexander Duyck } 893c2653865SAlexander Duyck 894c2653865SAlexander Duyck /* Update base address registers to contain MAC address */ 895c2653865SAlexander Duyck if (is_valid_ether_addr(vf_info->mac)) { 896c2653865SAlexander Duyck tdbal = (((u32)vf_info->mac[3]) << 24) | 897c2653865SAlexander Duyck (((u32)vf_info->mac[4]) << 16) | 898c2653865SAlexander Duyck (((u32)vf_info->mac[5]) << 8); 899c2653865SAlexander Duyck 900c2653865SAlexander Duyck tdbah = (((u32)0xFF) << 24) | 901c2653865SAlexander Duyck (((u32)vf_info->mac[0]) << 16) | 902c2653865SAlexander Duyck (((u32)vf_info->mac[1]) << 8) | 903c2653865SAlexander Duyck ((u32)vf_info->mac[2]); 904c2653865SAlexander Duyck } 905c2653865SAlexander Duyck 906c2653865SAlexander Duyck /* Record the base address into queue 0 */ 907c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx), tdbal); 908c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx), tdbah); 909c2653865SAlexander Duyck 91020076fa1SJacob Keller /* Provide the VF the ITR scale, using software-defined fields in TDLEN 91120076fa1SJacob Keller * to pass the information during VF initialization. See definition of 91220076fa1SJacob Keller * FM10K_TDLEN_ITR_SCALE_SHIFT for more details. 91320076fa1SJacob Keller */ 91420076fa1SJacob Keller fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx), hw->mac.itr_scale << 91520076fa1SJacob Keller FM10K_TDLEN_ITR_SCALE_SHIFT); 91620076fa1SJacob Keller 917c2653865SAlexander Duyck err_out: 918c2653865SAlexander Duyck /* configure Queue control register */ 919c2653865SAlexander Duyck txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) & 920c2653865SAlexander Duyck FM10K_TXQCTL_VID_MASK; 921c2653865SAlexander Duyck txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) | 922c2653865SAlexander Duyck FM10K_TXQCTL_VF | vf_idx; 923c2653865SAlexander Duyck 924aa502b4aSJacob Keller /* assign VLAN ID */ 925c2653865SAlexander Duyck for (i = 0; i < queues_per_pool; i++) 926c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx + i), txqctl); 927c2653865SAlexander Duyck 928c2653865SAlexander Duyck /* restore the queue back to VF ownership */ 929c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx); 930c2653865SAlexander Duyck return err; 931c2653865SAlexander Duyck } 932c2653865SAlexander Duyck 933c2653865SAlexander Duyck /** 934c2653865SAlexander Duyck * fm10k_iov_reset_resources_pf - Reassign queues and interrupts to a VF 935c2653865SAlexander Duyck * @hw: pointer to the HW structure 936c2653865SAlexander Duyck * @vf_info: pointer to VF information structure 937c2653865SAlexander Duyck * 938c2653865SAlexander Duyck * Reassign the interrupts and queues to a VF following an FLR 939c2653865SAlexander Duyck **/ 940c2653865SAlexander Duyck static s32 fm10k_iov_reset_resources_pf(struct fm10k_hw *hw, 941c2653865SAlexander Duyck struct fm10k_vf_info *vf_info) 942c2653865SAlexander Duyck { 943c2653865SAlexander Duyck u16 qmap_stride, queues_per_pool, vf_q_idx, qmap_idx; 944c2653865SAlexander Duyck u32 tdbal = 0, tdbah = 0, txqctl, rxqctl; 945c2653865SAlexander Duyck u16 vf_v_idx, vf_v_limit, vf_vid; 946c2653865SAlexander Duyck u8 vf_idx = vf_info->vf_idx; 947c2653865SAlexander Duyck int i; 948c2653865SAlexander Duyck 949c2653865SAlexander Duyck /* verify vf is in range */ 950c2653865SAlexander Duyck if (vf_idx >= hw->iov.num_vfs) 951c2653865SAlexander Duyck return FM10K_ERR_PARAM; 952c2653865SAlexander Duyck 953c2653865SAlexander Duyck /* clear event notification of VF FLR */ 954c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_PFVFLREC(vf_idx / 32), 1 << (vf_idx % 32)); 955c2653865SAlexander Duyck 956c2653865SAlexander Duyck /* force timeout and then disconnect the mailbox */ 957c2653865SAlexander Duyck vf_info->mbx.timeout = 0; 958c2653865SAlexander Duyck if (vf_info->mbx.ops.disconnect) 959c2653865SAlexander Duyck vf_info->mbx.ops.disconnect(hw, &vf_info->mbx); 960c2653865SAlexander Duyck 961c2653865SAlexander Duyck /* determine vector offset and count */ 962c2653865SAlexander Duyck vf_v_idx = fm10k_vf_vector_index(hw, vf_idx); 963c2653865SAlexander Duyck vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw); 964c2653865SAlexander Duyck 965c2653865SAlexander Duyck /* determine qmap offsets and counts */ 966c2653865SAlexander Duyck qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256; 967c2653865SAlexander Duyck queues_per_pool = fm10k_queues_per_pool(hw); 968c2653865SAlexander Duyck qmap_idx = qmap_stride * vf_idx; 969c2653865SAlexander Duyck 970c2653865SAlexander Duyck /* make all the queues inaccessible to the VF */ 971c2653865SAlexander Duyck for (i = qmap_idx; i < (qmap_idx + qmap_stride); i++) { 972c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(i), 0); 973c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(i), 0); 974c2653865SAlexander Duyck } 975c2653865SAlexander Duyck 976c2653865SAlexander Duyck /* calculate starting index for queues */ 977c2653865SAlexander Duyck vf_q_idx = fm10k_vf_queue_index(hw, vf_idx); 978c2653865SAlexander Duyck 979c2653865SAlexander Duyck /* determine correct default VLAN ID */ 980c2653865SAlexander Duyck if (vf_info->pf_vid) 981c2653865SAlexander Duyck vf_vid = vf_info->pf_vid; 982c2653865SAlexander Duyck else 983c2653865SAlexander Duyck vf_vid = vf_info->sw_vid; 984c2653865SAlexander Duyck 985c2653865SAlexander Duyck /* configure Queue control register */ 986c2653865SAlexander Duyck txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) | 987c2653865SAlexander Duyck (vf_idx << FM10K_TXQCTL_TC_SHIFT) | 988c2653865SAlexander Duyck FM10K_TXQCTL_VF | vf_idx; 989c2653865SAlexander Duyck rxqctl = FM10K_RXQCTL_VF | (vf_idx << FM10K_RXQCTL_VF_SHIFT); 990c2653865SAlexander Duyck 991c2653865SAlexander Duyck /* stop further DMA and reset queue ownership back to VF */ 992c2653865SAlexander Duyck for (i = vf_q_idx; i < (queues_per_pool + vf_q_idx); i++) { 993c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXDCTL(i), 0); 994c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl); 995c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RXDCTL(i), 996c2653865SAlexander Duyck FM10K_RXDCTL_WRITE_BACK_MIN_DELAY | 997c2653865SAlexander Duyck FM10K_RXDCTL_DROP_ON_EMPTY); 998c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RXQCTL(i), rxqctl); 999c2653865SAlexander Duyck } 1000c2653865SAlexander Duyck 1001c2653865SAlexander Duyck /* reset TC with -1 credits and no quanta to prevent transmit */ 1002c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), 0); 1003c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), 0); 1004c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx), 1005c2653865SAlexander Duyck FM10K_TC_CREDIT_CREDIT_MASK); 1006c2653865SAlexander Duyck 1007c2653865SAlexander Duyck /* update our first entry in the table based on previous VF */ 1008c2653865SAlexander Duyck if (!vf_idx) 1009c2653865SAlexander Duyck hw->mac.ops.update_int_moderator(hw); 1010c2653865SAlexander Duyck else 1011c2653865SAlexander Duyck hw->iov.ops.assign_int_moderator(hw, vf_idx - 1); 1012c2653865SAlexander Duyck 1013c2653865SAlexander Duyck /* reset linked list so it now includes our active vectors */ 1014c2653865SAlexander Duyck if (vf_idx == (hw->iov.num_vfs - 1)) 1015c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(0), vf_v_idx); 1016c2653865SAlexander Duyck else 1017c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), vf_v_idx); 1018c2653865SAlexander Duyck 1019c2653865SAlexander Duyck /* link remaining vectors so that next points to previous */ 1020c2653865SAlexander Duyck for (vf_v_idx++; vf_v_idx < vf_v_limit; vf_v_idx++) 1021c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_ITR2(vf_v_idx), vf_v_idx - 1); 1022c2653865SAlexander Duyck 1023c2653865SAlexander Duyck /* zero out MBMEM, VLAN_TABLE, RETA, RSSRK, and MRQC registers */ 1024c2653865SAlexander Duyck for (i = FM10K_VFMBMEM_LEN; i--;) 1025c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_MBMEM_VF(vf_idx, i), 0); 1026c2653865SAlexander Duyck for (i = FM10K_VLAN_TABLE_SIZE; i--;) 1027c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_VLAN_TABLE(vf_info->vsi, i), 0); 1028c2653865SAlexander Duyck for (i = FM10K_RETA_SIZE; i--;) 1029c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RETA(vf_info->vsi, i), 0); 1030c2653865SAlexander Duyck for (i = FM10K_RSSRK_SIZE; i--;) 1031c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RSSRK(vf_info->vsi, i), 0); 1032c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_MRQC(vf_info->vsi), 0); 1033c2653865SAlexander Duyck 1034c2653865SAlexander Duyck /* Update base address registers to contain MAC address */ 1035c2653865SAlexander Duyck if (is_valid_ether_addr(vf_info->mac)) { 1036c2653865SAlexander Duyck tdbal = (((u32)vf_info->mac[3]) << 24) | 1037c2653865SAlexander Duyck (((u32)vf_info->mac[4]) << 16) | 1038c2653865SAlexander Duyck (((u32)vf_info->mac[5]) << 8); 1039c2653865SAlexander Duyck tdbah = (((u32)0xFF) << 24) | 1040c2653865SAlexander Duyck (((u32)vf_info->mac[0]) << 16) | 1041c2653865SAlexander Duyck (((u32)vf_info->mac[1]) << 8) | 1042c2653865SAlexander Duyck ((u32)vf_info->mac[2]); 1043c2653865SAlexander Duyck } 1044c2653865SAlexander Duyck 1045c2653865SAlexander Duyck /* map queue pairs back to VF from last to first */ 1046c2653865SAlexander Duyck for (i = queues_per_pool; i--;) { 1047c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx + i), tdbal); 1048c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx + i), tdbah); 104920076fa1SJacob Keller /* See definition of FM10K_TDLEN_ITR_SCALE_SHIFT for an 105020076fa1SJacob Keller * explanation of how TDLEN is used. 105120076fa1SJacob Keller */ 105220076fa1SJacob Keller fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx + i), 105320076fa1SJacob Keller hw->mac.itr_scale << 105420076fa1SJacob Keller FM10K_TDLEN_ITR_SCALE_SHIFT); 1055c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx + i); 1056c2653865SAlexander Duyck fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx + i); 1057c2653865SAlexander Duyck } 1058c2653865SAlexander Duyck 1059fba341d5SJacob Keller /* repeat the first ring for all the remaining VF rings */ 1060fba341d5SJacob Keller for (i = queues_per_pool; i < qmap_stride; i++) { 1061fba341d5SJacob Keller fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx); 1062fba341d5SJacob Keller fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx); 1063fba341d5SJacob Keller } 1064fba341d5SJacob Keller 1065c2653865SAlexander Duyck return 0; 1066c2653865SAlexander Duyck } 1067c2653865SAlexander Duyck 1068c2653865SAlexander Duyck /** 1069c2653865SAlexander Duyck * fm10k_iov_set_lport_pf - Assign and enable a logical port for a given VF 1070c2653865SAlexander Duyck * @hw: pointer to hardware structure 1071c2653865SAlexander Duyck * @vf_info: pointer to VF information structure 1072c2653865SAlexander Duyck * @lport_idx: Logical port offset from the hardware glort 1073c2653865SAlexander Duyck * @flags: Set of capability flags to extend port beyond basic functionality 1074c2653865SAlexander Duyck * 1075c2653865SAlexander Duyck * This function allows enabling a VF port by assigning it a GLORT and 1076c2653865SAlexander Duyck * setting the flags so that it can enable an Rx mode. 1077c2653865SAlexander Duyck **/ 1078c2653865SAlexander Duyck static s32 fm10k_iov_set_lport_pf(struct fm10k_hw *hw, 1079c2653865SAlexander Duyck struct fm10k_vf_info *vf_info, 1080c2653865SAlexander Duyck u16 lport_idx, u8 flags) 1081c2653865SAlexander Duyck { 1082c2653865SAlexander Duyck u16 glort = (hw->mac.dglort_map + lport_idx) & FM10K_DGLORTMAP_NONE; 1083c2653865SAlexander Duyck 1084c2653865SAlexander Duyck /* if glort is not valid return error */ 1085c2653865SAlexander Duyck if (!fm10k_glort_valid_pf(hw, glort)) 1086c2653865SAlexander Duyck return FM10K_ERR_PARAM; 1087c2653865SAlexander Duyck 1088c2653865SAlexander Duyck vf_info->vf_flags = flags | FM10K_VF_FLAG_NONE_CAPABLE; 1089c2653865SAlexander Duyck vf_info->glort = glort; 1090c2653865SAlexander Duyck 1091c2653865SAlexander Duyck return 0; 1092c2653865SAlexander Duyck } 1093c2653865SAlexander Duyck 1094c2653865SAlexander Duyck /** 1095c2653865SAlexander Duyck * fm10k_iov_reset_lport_pf - Disable a logical port for a given VF 1096c2653865SAlexander Duyck * @hw: pointer to hardware structure 1097c2653865SAlexander Duyck * @vf_info: pointer to VF information structure 1098c2653865SAlexander Duyck * 1099c2653865SAlexander Duyck * This function disables a VF port by stripping it of a GLORT and 1100c2653865SAlexander Duyck * setting the flags so that it cannot enable any Rx mode. 1101c2653865SAlexander Duyck **/ 1102c2653865SAlexander Duyck static void fm10k_iov_reset_lport_pf(struct fm10k_hw *hw, 1103c2653865SAlexander Duyck struct fm10k_vf_info *vf_info) 1104c2653865SAlexander Duyck { 1105c2653865SAlexander Duyck u32 msg[1]; 1106c2653865SAlexander Duyck 1107c2653865SAlexander Duyck /* need to disable the port if it is already enabled */ 1108c2653865SAlexander Duyck if (FM10K_VF_FLAG_ENABLED(vf_info)) { 1109c2653865SAlexander Duyck /* notify switch that this port has been disabled */ 1110c2653865SAlexander Duyck fm10k_update_lport_state_pf(hw, vf_info->glort, 1, false); 1111c2653865SAlexander Duyck 1112c2653865SAlexander Duyck /* generate port state response to notify VF it is not ready */ 1113c2653865SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE); 1114c2653865SAlexander Duyck vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg); 1115c2653865SAlexander Duyck } 1116c2653865SAlexander Duyck 1117c2653865SAlexander Duyck /* clear flags and glort if it exists */ 1118c2653865SAlexander Duyck vf_info->vf_flags = 0; 1119c2653865SAlexander Duyck vf_info->glort = 0; 1120c2653865SAlexander Duyck } 1121c2653865SAlexander Duyck 1122c2653865SAlexander Duyck /** 1123c2653865SAlexander Duyck * fm10k_iov_update_stats_pf - Updates hardware related statistics for VFs 1124c2653865SAlexander Duyck * @hw: pointer to hardware structure 1125c2653865SAlexander Duyck * @q: stats for all queues of a VF 1126c2653865SAlexander Duyck * @vf_idx: index of VF 1127c2653865SAlexander Duyck * 1128c2653865SAlexander Duyck * This function collects queue stats for VFs. 1129c2653865SAlexander Duyck **/ 1130c2653865SAlexander Duyck static void fm10k_iov_update_stats_pf(struct fm10k_hw *hw, 1131c2653865SAlexander Duyck struct fm10k_hw_stats_q *q, 1132c2653865SAlexander Duyck u16 vf_idx) 1133c2653865SAlexander Duyck { 1134c2653865SAlexander Duyck u32 idx, qpp; 1135c2653865SAlexander Duyck 1136c2653865SAlexander Duyck /* get stats for all of the queues */ 1137c2653865SAlexander Duyck qpp = fm10k_queues_per_pool(hw); 1138c2653865SAlexander Duyck idx = fm10k_vf_queue_index(hw, vf_idx); 1139c2653865SAlexander Duyck fm10k_update_hw_stats_q(hw, q, idx, qpp); 1140c2653865SAlexander Duyck } 1141c2653865SAlexander Duyck 11425f226ddbSAlexander Duyck static s32 fm10k_iov_report_timestamp_pf(struct fm10k_hw *hw, 11435f226ddbSAlexander Duyck struct fm10k_vf_info *vf_info, 11445f226ddbSAlexander Duyck u64 timestamp) 11455f226ddbSAlexander Duyck { 11465f226ddbSAlexander Duyck u32 msg[4]; 11475f226ddbSAlexander Duyck 11485f226ddbSAlexander Duyck /* generate port state response to notify VF it is not ready */ 11495f226ddbSAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_1588); 11505f226ddbSAlexander Duyck fm10k_tlv_attr_put_u64(msg, FM10K_1588_MSG_TIMESTAMP, timestamp); 11515f226ddbSAlexander Duyck 11525f226ddbSAlexander Duyck return vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg); 11535f226ddbSAlexander Duyck } 11545f226ddbSAlexander Duyck 1155c2653865SAlexander Duyck /** 1156c2653865SAlexander Duyck * fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF 1157c2653865SAlexander Duyck * @hw: Pointer to hardware structure 1158c2653865SAlexander Duyck * @results: Pointer array to message, results[0] is pointer to message 1159c2653865SAlexander Duyck * @mbx: Pointer to mailbox information structure 1160c2653865SAlexander Duyck * 1161c2653865SAlexander Duyck * This function is a default handler for MSI-X requests from the VF. The 1162c2653865SAlexander Duyck * assumption is that in this case it is acceptable to just directly 1163eca32047SMatthew Vick * hand off the message from the VF to the underlying shared code. 1164c2653865SAlexander Duyck **/ 1165c2653865SAlexander Duyck s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results, 1166c2653865SAlexander Duyck struct fm10k_mbx_info *mbx) 1167c2653865SAlexander Duyck { 1168c2653865SAlexander Duyck struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx; 1169c2653865SAlexander Duyck u8 vf_idx = vf_info->vf_idx; 1170c2653865SAlexander Duyck 1171c2653865SAlexander Duyck return hw->iov.ops.assign_int_moderator(hw, vf_idx); 1172c2653865SAlexander Duyck } 1173c2653865SAlexander Duyck 1174c2653865SAlexander Duyck /** 1175aa502b4aSJacob Keller * fm10k_iov_select_vid - Select correct default VLAN ID 11769adbac59SJacob Keller * @hw: Pointer to hardware structure 1177aa502b4aSJacob Keller * @vid: VLAN ID to correct 11789adbac59SJacob Keller * 1179aa502b4aSJacob Keller * Will report an error if the VLAN ID is out of range. For VID = 0, it will 1180aa502b4aSJacob Keller * return either the pf_vid or sw_vid depending on which one is set. 11819adbac59SJacob Keller */ 1182e214d85bSBruce Allan static s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid) 11839adbac59SJacob Keller { 11849adbac59SJacob Keller if (!vid) 11859adbac59SJacob Keller return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid; 11869adbac59SJacob Keller else if (vf_info->pf_vid && vid != vf_info->pf_vid) 11879adbac59SJacob Keller return FM10K_ERR_PARAM; 11889adbac59SJacob Keller else 11899adbac59SJacob Keller return vid; 11909adbac59SJacob Keller } 11919adbac59SJacob Keller 11929adbac59SJacob Keller /** 1193c2653865SAlexander Duyck * fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF 1194c2653865SAlexander Duyck * @hw: Pointer to hardware structure 1195c2653865SAlexander Duyck * @results: Pointer array to message, results[0] is pointer to message 1196c2653865SAlexander Duyck * @mbx: Pointer to mailbox information structure 1197c2653865SAlexander Duyck * 1198c2653865SAlexander Duyck * This function is a default handler for MAC/VLAN requests from the VF. 1199c2653865SAlexander Duyck * The assumption is that in this case it is acceptable to just directly 1200eca32047SMatthew Vick * hand off the message from the VF to the underlying shared code. 1201c2653865SAlexander Duyck **/ 1202c2653865SAlexander Duyck s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results, 1203c2653865SAlexander Duyck struct fm10k_mbx_info *mbx) 1204c2653865SAlexander Duyck { 1205c2653865SAlexander Duyck struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx; 1206c2653865SAlexander Duyck u8 mac[ETH_ALEN]; 1207c2653865SAlexander Duyck u32 *result; 12089adbac59SJacob Keller int err = 0; 12099adbac59SJacob Keller bool set; 1210c2653865SAlexander Duyck u16 vlan; 1211c2653865SAlexander Duyck u32 vid; 1212c2653865SAlexander Duyck 1213c2653865SAlexander Duyck /* we shouldn't be updating rules on a disabled interface */ 1214c2653865SAlexander Duyck if (!FM10K_VF_FLAG_ENABLED(vf_info)) 1215c2653865SAlexander Duyck err = FM10K_ERR_PARAM; 1216c2653865SAlexander Duyck 1217c2653865SAlexander Duyck if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) { 1218c2653865SAlexander Duyck result = results[FM10K_MAC_VLAN_MSG_VLAN]; 1219c2653865SAlexander Duyck 1220c2653865SAlexander Duyck /* record VLAN id requested */ 1221c2653865SAlexander Duyck err = fm10k_tlv_attr_get_u32(result, &vid); 1222c2653865SAlexander Duyck if (err) 1223c2653865SAlexander Duyck return err; 1224c2653865SAlexander Duyck 12259adbac59SJacob Keller /* verify upper 16 bits are zero */ 12269adbac59SJacob Keller if (vid >> 16) 1227c2653865SAlexander Duyck return FM10K_ERR_PARAM; 12289adbac59SJacob Keller 12299adbac59SJacob Keller set = !(vid & FM10K_VLAN_CLEAR); 12309adbac59SJacob Keller vid &= ~FM10K_VLAN_CLEAR; 12319adbac59SJacob Keller 1232cdf32c94SJacob Keller err = fm10k_iov_select_vid(vf_info, (u16)vid); 12339adbac59SJacob Keller if (err < 0) 12349adbac59SJacob Keller return err; 12354ab0f79bSJacob Keller 12369adbac59SJacob Keller vid = err; 1237c2653865SAlexander Duyck 1238c2653865SAlexander Duyck /* update VSI info for VF in regards to VLAN table */ 12399adbac59SJacob Keller err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set); 1240c2653865SAlexander Duyck } 1241c2653865SAlexander Duyck 1242c2653865SAlexander Duyck if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) { 1243c2653865SAlexander Duyck result = results[FM10K_MAC_VLAN_MSG_MAC]; 1244c2653865SAlexander Duyck 1245c2653865SAlexander Duyck /* record unicast MAC address requested */ 1246c2653865SAlexander Duyck err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan); 1247c2653865SAlexander Duyck if (err) 1248c2653865SAlexander Duyck return err; 1249c2653865SAlexander Duyck 1250c2653865SAlexander Duyck /* block attempts to set MAC for a locked device */ 1251c2653865SAlexander Duyck if (is_valid_ether_addr(vf_info->mac) && 1252c2653865SAlexander Duyck memcmp(mac, vf_info->mac, ETH_ALEN)) 1253c2653865SAlexander Duyck return FM10K_ERR_PARAM; 1254c2653865SAlexander Duyck 12559adbac59SJacob Keller set = !(vlan & FM10K_VLAN_CLEAR); 12569adbac59SJacob Keller vlan &= ~FM10K_VLAN_CLEAR; 12579adbac59SJacob Keller 12589adbac59SJacob Keller err = fm10k_iov_select_vid(vf_info, vlan); 12599adbac59SJacob Keller if (err < 0) 12609adbac59SJacob Keller return err; 12614ab0f79bSJacob Keller 1262cdf32c94SJacob Keller vlan = (u16)err; 1263c2653865SAlexander Duyck 1264c2653865SAlexander Duyck /* notify switch of request for new unicast address */ 12659adbac59SJacob Keller err = hw->mac.ops.update_uc_addr(hw, vf_info->glort, 12669adbac59SJacob Keller mac, vlan, set, 0); 1267c2653865SAlexander Duyck } 1268c2653865SAlexander Duyck 1269c2653865SAlexander Duyck if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) { 1270c2653865SAlexander Duyck result = results[FM10K_MAC_VLAN_MSG_MULTICAST]; 1271c2653865SAlexander Duyck 1272c2653865SAlexander Duyck /* record multicast MAC address requested */ 1273c2653865SAlexander Duyck err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan); 1274c2653865SAlexander Duyck if (err) 1275c2653865SAlexander Duyck return err; 1276c2653865SAlexander Duyck 1277c2653865SAlexander Duyck /* verify that the VF is allowed to request multicast */ 1278c2653865SAlexander Duyck if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED)) 1279c2653865SAlexander Duyck return FM10K_ERR_PARAM; 1280c2653865SAlexander Duyck 12819adbac59SJacob Keller set = !(vlan & FM10K_VLAN_CLEAR); 12829adbac59SJacob Keller vlan &= ~FM10K_VLAN_CLEAR; 12839adbac59SJacob Keller 12849adbac59SJacob Keller err = fm10k_iov_select_vid(vf_info, vlan); 12859adbac59SJacob Keller if (err < 0) 12869adbac59SJacob Keller return err; 12874ab0f79bSJacob Keller 1288cdf32c94SJacob Keller vlan = (u16)err; 1289c2653865SAlexander Duyck 1290c2653865SAlexander Duyck /* notify switch of request for new multicast address */ 12919adbac59SJacob Keller err = hw->mac.ops.update_mc_addr(hw, vf_info->glort, 12929adbac59SJacob Keller mac, vlan, set); 1293c2653865SAlexander Duyck } 1294c2653865SAlexander Duyck 1295c2653865SAlexander Duyck return err; 1296c2653865SAlexander Duyck } 1297c2653865SAlexander Duyck 1298c2653865SAlexander Duyck /** 1299c2653865SAlexander Duyck * fm10k_iov_supported_xcast_mode_pf - Determine best match for xcast mode 1300c2653865SAlexander Duyck * @vf_info: VF info structure containing capability flags 1301c2653865SAlexander Duyck * @mode: Requested xcast mode 1302c2653865SAlexander Duyck * 1303c2653865SAlexander Duyck * This function outputs the mode that most closely matches the requested 1304c2653865SAlexander Duyck * mode. If not modes match it will request we disable the port 1305c2653865SAlexander Duyck **/ 1306c2653865SAlexander Duyck static u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info, 1307c2653865SAlexander Duyck u8 mode) 1308c2653865SAlexander Duyck { 1309c2653865SAlexander Duyck u8 vf_flags = vf_info->vf_flags; 1310c2653865SAlexander Duyck 1311c2653865SAlexander Duyck /* match up mode to capabilities as best as possible */ 1312c2653865SAlexander Duyck switch (mode) { 1313c2653865SAlexander Duyck case FM10K_XCAST_MODE_PROMISC: 1314c2653865SAlexander Duyck if (vf_flags & FM10K_VF_FLAG_PROMISC_CAPABLE) 1315c2653865SAlexander Duyck return FM10K_XCAST_MODE_PROMISC; 1316c2653865SAlexander Duyck /* fallthough */ 1317c2653865SAlexander Duyck case FM10K_XCAST_MODE_ALLMULTI: 1318c2653865SAlexander Duyck if (vf_flags & FM10K_VF_FLAG_ALLMULTI_CAPABLE) 1319c2653865SAlexander Duyck return FM10K_XCAST_MODE_ALLMULTI; 1320c2653865SAlexander Duyck /* fallthough */ 1321c2653865SAlexander Duyck case FM10K_XCAST_MODE_MULTI: 1322c2653865SAlexander Duyck if (vf_flags & FM10K_VF_FLAG_MULTI_CAPABLE) 1323c2653865SAlexander Duyck return FM10K_XCAST_MODE_MULTI; 1324c2653865SAlexander Duyck /* fallthough */ 1325c2653865SAlexander Duyck case FM10K_XCAST_MODE_NONE: 1326c2653865SAlexander Duyck if (vf_flags & FM10K_VF_FLAG_NONE_CAPABLE) 1327c2653865SAlexander Duyck return FM10K_XCAST_MODE_NONE; 1328c2653865SAlexander Duyck /* fallthough */ 1329c2653865SAlexander Duyck default: 1330c2653865SAlexander Duyck break; 1331c2653865SAlexander Duyck } 1332c2653865SAlexander Duyck 1333c2653865SAlexander Duyck /* disable interface as it should not be able to request any */ 1334c2653865SAlexander Duyck return FM10K_XCAST_MODE_DISABLE; 1335c2653865SAlexander Duyck } 1336c2653865SAlexander Duyck 1337c2653865SAlexander Duyck /** 1338c2653865SAlexander Duyck * fm10k_iov_msg_lport_state_pf - Message handler for port state requests 1339c2653865SAlexander Duyck * @hw: Pointer to hardware structure 1340c2653865SAlexander Duyck * @results: Pointer array to message, results[0] is pointer to message 1341c2653865SAlexander Duyck * @mbx: Pointer to mailbox information structure 1342c2653865SAlexander Duyck * 1343c2653865SAlexander Duyck * This function is a default handler for port state requests. The port 1344c2653865SAlexander Duyck * state requests for now are basic and consist of enabling or disabling 1345c2653865SAlexander Duyck * the port. 1346c2653865SAlexander Duyck **/ 1347c2653865SAlexander Duyck s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results, 1348c2653865SAlexander Duyck struct fm10k_mbx_info *mbx) 1349c2653865SAlexander Duyck { 1350c2653865SAlexander Duyck struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx; 1351c2653865SAlexander Duyck u32 *result; 1352c2653865SAlexander Duyck s32 err = 0; 1353c2653865SAlexander Duyck u32 msg[2]; 1354c2653865SAlexander Duyck u8 mode = 0; 1355c2653865SAlexander Duyck 1356c2653865SAlexander Duyck /* verify VF is allowed to enable even minimal mode */ 1357c2653865SAlexander Duyck if (!(vf_info->vf_flags & FM10K_VF_FLAG_NONE_CAPABLE)) 1358c2653865SAlexander Duyck return FM10K_ERR_PARAM; 1359c2653865SAlexander Duyck 1360c2653865SAlexander Duyck if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) { 1361c2653865SAlexander Duyck result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE]; 1362c2653865SAlexander Duyck 1363c2653865SAlexander Duyck /* XCAST mode update requested */ 1364c2653865SAlexander Duyck err = fm10k_tlv_attr_get_u8(result, &mode); 1365c2653865SAlexander Duyck if (err) 1366c2653865SAlexander Duyck return FM10K_ERR_PARAM; 1367c2653865SAlexander Duyck 1368c2653865SAlexander Duyck /* prep for possible demotion depending on capabilities */ 1369c2653865SAlexander Duyck mode = fm10k_iov_supported_xcast_mode_pf(vf_info, mode); 1370c2653865SAlexander Duyck 1371c2653865SAlexander Duyck /* if mode is not currently enabled, enable it */ 1372c2653865SAlexander Duyck if (!(FM10K_VF_FLAG_ENABLED(vf_info) & (1 << mode))) 1373c2653865SAlexander Duyck fm10k_update_xcast_mode_pf(hw, vf_info->glort, mode); 1374c2653865SAlexander Duyck 1375c2653865SAlexander Duyck /* swap mode back to a bit flag */ 1376c2653865SAlexander Duyck mode = FM10K_VF_FLAG_SET_MODE(mode); 1377c2653865SAlexander Duyck } else if (!results[FM10K_LPORT_STATE_MSG_DISABLE]) { 1378c2653865SAlexander Duyck /* need to disable the port if it is already enabled */ 1379c2653865SAlexander Duyck if (FM10K_VF_FLAG_ENABLED(vf_info)) 1380c2653865SAlexander Duyck err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1381c2653865SAlexander Duyck 1, false); 1382c2653865SAlexander Duyck 1383ee4373e7SJacob Keller /* we need to clear VF_FLAG_ENABLED flags in order to ensure 1384ee4373e7SJacob Keller * that we actually re-enable the LPORT state below. Note that 1385ee4373e7SJacob Keller * this has no impact if the VF is already disabled, as the 1386ee4373e7SJacob Keller * flags are already cleared. 1387ee4373e7SJacob Keller */ 1388ee4373e7SJacob Keller if (!err) 1389ee4373e7SJacob Keller vf_info->vf_flags = FM10K_VF_FLAG_CAPABLE(vf_info); 1390ee4373e7SJacob Keller 1391c2653865SAlexander Duyck /* when enabling the port we should reset the rate limiters */ 1392c2653865SAlexander Duyck hw->iov.ops.configure_tc(hw, vf_info->vf_idx, vf_info->rate); 1393c2653865SAlexander Duyck 1394c2653865SAlexander Duyck /* set mode for minimal functionality */ 1395c2653865SAlexander Duyck mode = FM10K_VF_FLAG_SET_MODE_NONE; 1396c2653865SAlexander Duyck 1397c2653865SAlexander Duyck /* generate port state response to notify VF it is ready */ 1398c2653865SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE); 1399c2653865SAlexander Duyck fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_READY); 1400c2653865SAlexander Duyck mbx->ops.enqueue_tx(hw, mbx, msg); 1401c2653865SAlexander Duyck } 1402c2653865SAlexander Duyck 1403c2653865SAlexander Duyck /* if enable state toggled note the update */ 1404c2653865SAlexander Duyck if (!err && (!FM10K_VF_FLAG_ENABLED(vf_info) != !mode)) 1405c2653865SAlexander Duyck err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1, 1406c2653865SAlexander Duyck !!mode); 1407c2653865SAlexander Duyck 1408c2653865SAlexander Duyck /* if state change succeeded, then update our stored state */ 1409c2653865SAlexander Duyck mode |= FM10K_VF_FLAG_CAPABLE(vf_info); 1410c2653865SAlexander Duyck if (!err) 1411c2653865SAlexander Duyck vf_info->vf_flags = mode; 1412c2653865SAlexander Duyck 1413c2653865SAlexander Duyck return err; 1414c2653865SAlexander Duyck } 1415c2653865SAlexander Duyck 1416401b5383SAlexander Duyck /** 1417b6fec18fSAlexander Duyck * fm10k_update_stats_hw_pf - Updates hardware related statistics of PF 1418b6fec18fSAlexander Duyck * @hw: pointer to hardware structure 1419b6fec18fSAlexander Duyck * @stats: pointer to the stats structure to update 1420b6fec18fSAlexander Duyck * 1421b6fec18fSAlexander Duyck * This function collects and aggregates global and per queue hardware 1422b6fec18fSAlexander Duyck * statistics. 1423b6fec18fSAlexander Duyck **/ 1424b6fec18fSAlexander Duyck static void fm10k_update_hw_stats_pf(struct fm10k_hw *hw, 1425b6fec18fSAlexander Duyck struct fm10k_hw_stats *stats) 1426b6fec18fSAlexander Duyck { 1427b6fec18fSAlexander Duyck u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop; 1428b6fec18fSAlexander Duyck u32 id, id_prev; 1429b6fec18fSAlexander Duyck 1430b6fec18fSAlexander Duyck /* Use Tx queue 0 as a canary to detect a reset */ 1431b6fec18fSAlexander Duyck id = fm10k_read_reg(hw, FM10K_TXQCTL(0)); 1432b6fec18fSAlexander Duyck 1433b6fec18fSAlexander Duyck /* Read Global Statistics */ 1434b6fec18fSAlexander Duyck do { 1435b6fec18fSAlexander Duyck timeout = fm10k_read_hw_stats_32b(hw, FM10K_STATS_TIMEOUT, 1436b6fec18fSAlexander Duyck &stats->timeout); 1437b6fec18fSAlexander Duyck ur = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UR, &stats->ur); 1438b6fec18fSAlexander Duyck ca = fm10k_read_hw_stats_32b(hw, FM10K_STATS_CA, &stats->ca); 1439b6fec18fSAlexander Duyck um = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UM, &stats->um); 1440b6fec18fSAlexander Duyck xec = fm10k_read_hw_stats_32b(hw, FM10K_STATS_XEC, &stats->xec); 1441b6fec18fSAlexander Duyck vlan_drop = fm10k_read_hw_stats_32b(hw, FM10K_STATS_VLAN_DROP, 1442b6fec18fSAlexander Duyck &stats->vlan_drop); 1443b6fec18fSAlexander Duyck loopback_drop = fm10k_read_hw_stats_32b(hw, 1444b6fec18fSAlexander Duyck FM10K_STATS_LOOPBACK_DROP, 1445b6fec18fSAlexander Duyck &stats->loopback_drop); 1446b6fec18fSAlexander Duyck nodesc_drop = fm10k_read_hw_stats_32b(hw, 1447b6fec18fSAlexander Duyck FM10K_STATS_NODESC_DROP, 1448b6fec18fSAlexander Duyck &stats->nodesc_drop); 1449b6fec18fSAlexander Duyck 1450b6fec18fSAlexander Duyck /* if value has not changed then we have consistent data */ 1451b6fec18fSAlexander Duyck id_prev = id; 1452b6fec18fSAlexander Duyck id = fm10k_read_reg(hw, FM10K_TXQCTL(0)); 1453b6fec18fSAlexander Duyck } while ((id ^ id_prev) & FM10K_TXQCTL_ID_MASK); 1454b6fec18fSAlexander Duyck 1455b6fec18fSAlexander Duyck /* drop non-ID bits and set VALID ID bit */ 1456b6fec18fSAlexander Duyck id &= FM10K_TXQCTL_ID_MASK; 1457b6fec18fSAlexander Duyck id |= FM10K_STAT_VALID; 1458b6fec18fSAlexander Duyck 1459b6fec18fSAlexander Duyck /* Update Global Statistics */ 1460b6fec18fSAlexander Duyck if (stats->stats_idx == id) { 1461b6fec18fSAlexander Duyck stats->timeout.count += timeout; 1462b6fec18fSAlexander Duyck stats->ur.count += ur; 1463b6fec18fSAlexander Duyck stats->ca.count += ca; 1464b6fec18fSAlexander Duyck stats->um.count += um; 1465b6fec18fSAlexander Duyck stats->xec.count += xec; 1466b6fec18fSAlexander Duyck stats->vlan_drop.count += vlan_drop; 1467b6fec18fSAlexander Duyck stats->loopback_drop.count += loopback_drop; 1468b6fec18fSAlexander Duyck stats->nodesc_drop.count += nodesc_drop; 1469b6fec18fSAlexander Duyck } 1470b6fec18fSAlexander Duyck 1471b6fec18fSAlexander Duyck /* Update bases and record current PF id */ 1472b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->timeout, timeout); 1473b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->ur, ur); 1474b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->ca, ca); 1475b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->um, um); 1476b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->xec, xec); 1477b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->vlan_drop, vlan_drop); 1478b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->loopback_drop, loopback_drop); 1479b6fec18fSAlexander Duyck fm10k_update_hw_base_32b(&stats->nodesc_drop, nodesc_drop); 1480b6fec18fSAlexander Duyck stats->stats_idx = id; 1481b6fec18fSAlexander Duyck 1482b6fec18fSAlexander Duyck /* Update Queue Statistics */ 1483b6fec18fSAlexander Duyck fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues); 1484b6fec18fSAlexander Duyck } 1485b6fec18fSAlexander Duyck 1486b6fec18fSAlexander Duyck /** 1487b6fec18fSAlexander Duyck * fm10k_rebind_hw_stats_pf - Resets base for hardware statistics of PF 1488b6fec18fSAlexander Duyck * @hw: pointer to hardware structure 1489b6fec18fSAlexander Duyck * @stats: pointer to the stats structure to update 1490b6fec18fSAlexander Duyck * 1491b6fec18fSAlexander Duyck * This function resets the base for global and per queue hardware 1492b6fec18fSAlexander Duyck * statistics. 1493b6fec18fSAlexander Duyck **/ 1494b6fec18fSAlexander Duyck static void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw, 1495b6fec18fSAlexander Duyck struct fm10k_hw_stats *stats) 1496b6fec18fSAlexander Duyck { 1497b6fec18fSAlexander Duyck /* Unbind Global Statistics */ 1498b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->timeout); 1499b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->ur); 1500b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->ca); 1501b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->um); 1502b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->xec); 1503b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->vlan_drop); 1504b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->loopback_drop); 1505b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_32b(&stats->nodesc_drop); 1506b6fec18fSAlexander Duyck 1507b6fec18fSAlexander Duyck /* Unbind Queue Statistics */ 1508b6fec18fSAlexander Duyck fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues); 1509b6fec18fSAlexander Duyck 1510b6fec18fSAlexander Duyck /* Reinitialize bases for all stats */ 1511b6fec18fSAlexander Duyck fm10k_update_hw_stats_pf(hw, stats); 1512b6fec18fSAlexander Duyck } 1513b6fec18fSAlexander Duyck 1514b6fec18fSAlexander Duyck /** 1515401b5383SAlexander Duyck * fm10k_set_dma_mask_pf - Configures PhyAddrSpace to limit DMA to system 1516401b5383SAlexander Duyck * @hw: pointer to hardware structure 1517401b5383SAlexander Duyck * @dma_mask: 64 bit DMA mask required for platform 1518401b5383SAlexander Duyck * 1519401b5383SAlexander Duyck * This function sets the PHYADDR.PhyAddrSpace bits for the endpoint in order 1520401b5383SAlexander Duyck * to limit the access to memory beyond what is physically in the system. 1521401b5383SAlexander Duyck **/ 1522401b5383SAlexander Duyck static void fm10k_set_dma_mask_pf(struct fm10k_hw *hw, u64 dma_mask) 1523401b5383SAlexander Duyck { 1524401b5383SAlexander Duyck /* we need to write the upper 32 bits of DMA mask to PhyAddrSpace */ 1525401b5383SAlexander Duyck u32 phyaddr = (u32)(dma_mask >> 32); 1526401b5383SAlexander Duyck 1527401b5383SAlexander Duyck fm10k_write_reg(hw, FM10K_PHYADDR, phyaddr); 1528401b5383SAlexander Duyck } 1529401b5383SAlexander Duyck 1530401b5383SAlexander Duyck /** 1531b6fec18fSAlexander Duyck * fm10k_get_fault_pf - Record a fault in one of the interface units 1532b6fec18fSAlexander Duyck * @hw: pointer to hardware structure 1533b6fec18fSAlexander Duyck * @type: pointer to fault type register offset 1534b6fec18fSAlexander Duyck * @fault: pointer to memory location to record the fault 1535b6fec18fSAlexander Duyck * 1536b6fec18fSAlexander Duyck * Record the fault register contents to the fault data structure and 1537b6fec18fSAlexander Duyck * clear the entry from the register. 1538b6fec18fSAlexander Duyck * 1539b6fec18fSAlexander Duyck * Returns ERR_PARAM if invalid register is specified or no error is present. 1540b6fec18fSAlexander Duyck **/ 1541b6fec18fSAlexander Duyck static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type, 1542b6fec18fSAlexander Duyck struct fm10k_fault *fault) 1543b6fec18fSAlexander Duyck { 1544b6fec18fSAlexander Duyck u32 func; 1545b6fec18fSAlexander Duyck 1546b6fec18fSAlexander Duyck /* verify the fault register is in range and is aligned */ 1547b6fec18fSAlexander Duyck switch (type) { 1548b6fec18fSAlexander Duyck case FM10K_PCA_FAULT: 1549b6fec18fSAlexander Duyck case FM10K_THI_FAULT: 1550b6fec18fSAlexander Duyck case FM10K_FUM_FAULT: 1551b6fec18fSAlexander Duyck break; 1552b6fec18fSAlexander Duyck default: 1553b6fec18fSAlexander Duyck return FM10K_ERR_PARAM; 1554b6fec18fSAlexander Duyck } 1555b6fec18fSAlexander Duyck 1556b6fec18fSAlexander Duyck /* only service faults that are valid */ 1557b6fec18fSAlexander Duyck func = fm10k_read_reg(hw, type + FM10K_FAULT_FUNC); 1558b6fec18fSAlexander Duyck if (!(func & FM10K_FAULT_FUNC_VALID)) 1559b6fec18fSAlexander Duyck return FM10K_ERR_PARAM; 1560b6fec18fSAlexander Duyck 1561b6fec18fSAlexander Duyck /* read remaining fields */ 1562b6fec18fSAlexander Duyck fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_HI); 1563b6fec18fSAlexander Duyck fault->address <<= 32; 1564b6fec18fSAlexander Duyck fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO); 1565b6fec18fSAlexander Duyck fault->specinfo = fm10k_read_reg(hw, type + FM10K_FAULT_SPECINFO); 1566b6fec18fSAlexander Duyck 1567b6fec18fSAlexander Duyck /* clear valid bit to allow for next error */ 1568b6fec18fSAlexander Duyck fm10k_write_reg(hw, type + FM10K_FAULT_FUNC, FM10K_FAULT_FUNC_VALID); 1569b6fec18fSAlexander Duyck 1570b6fec18fSAlexander Duyck /* Record which function triggered the error */ 1571b6fec18fSAlexander Duyck if (func & FM10K_FAULT_FUNC_PF) 1572b6fec18fSAlexander Duyck fault->func = 0; 1573b6fec18fSAlexander Duyck else 1574b6fec18fSAlexander Duyck fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >> 1575b6fec18fSAlexander Duyck FM10K_FAULT_FUNC_VF_SHIFT); 1576b6fec18fSAlexander Duyck 1577b6fec18fSAlexander Duyck /* record fault type */ 1578b6fec18fSAlexander Duyck fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK; 1579b6fec18fSAlexander Duyck 1580b6fec18fSAlexander Duyck return 0; 1581b6fec18fSAlexander Duyck } 1582b6fec18fSAlexander Duyck 1583401b5383SAlexander Duyck /** 1584401b5383SAlexander Duyck * fm10k_request_lport_map_pf - Request LPORT map from the switch API 1585401b5383SAlexander Duyck * @hw: pointer to hardware structure 1586401b5383SAlexander Duyck * 1587401b5383SAlexander Duyck **/ 1588401b5383SAlexander Duyck static s32 fm10k_request_lport_map_pf(struct fm10k_hw *hw) 1589401b5383SAlexander Duyck { 1590401b5383SAlexander Duyck struct fm10k_mbx_info *mbx = &hw->mbx; 1591401b5383SAlexander Duyck u32 msg[1]; 1592401b5383SAlexander Duyck 1593401b5383SAlexander Duyck /* issue request asking for LPORT map */ 1594401b5383SAlexander Duyck fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_LPORT_MAP); 1595401b5383SAlexander Duyck 1596401b5383SAlexander Duyck /* load onto outgoing mailbox */ 1597401b5383SAlexander Duyck return mbx->ops.enqueue_tx(hw, mbx, msg); 1598401b5383SAlexander Duyck } 1599401b5383SAlexander Duyck 1600401b5383SAlexander Duyck /** 1601401b5383SAlexander Duyck * fm10k_get_host_state_pf - Returns the state of the switch and mailbox 1602401b5383SAlexander Duyck * @hw: pointer to hardware structure 1603401b5383SAlexander Duyck * @switch_ready: pointer to boolean value that will record switch state 1604401b5383SAlexander Duyck * 1605401b5383SAlexander Duyck * This funciton will check the DMA_CTRL2 register and mailbox in order 1606401b5383SAlexander Duyck * to determine if the switch is ready for the PF to begin requesting 1607401b5383SAlexander Duyck * addresses and mapping traffic to the local interface. 1608401b5383SAlexander Duyck **/ 1609401b5383SAlexander Duyck static s32 fm10k_get_host_state_pf(struct fm10k_hw *hw, bool *switch_ready) 1610401b5383SAlexander Duyck { 1611401b5383SAlexander Duyck s32 ret_val = 0; 1612401b5383SAlexander Duyck u32 dma_ctrl2; 1613401b5383SAlexander Duyck 1614eca32047SMatthew Vick /* verify the switch is ready for interaction */ 1615401b5383SAlexander Duyck dma_ctrl2 = fm10k_read_reg(hw, FM10K_DMA_CTRL2); 1616401b5383SAlexander Duyck if (!(dma_ctrl2 & FM10K_DMA_CTRL2_SWITCH_READY)) 1617401b5383SAlexander Duyck goto out; 1618401b5383SAlexander Duyck 1619401b5383SAlexander Duyck /* retrieve generic host state info */ 1620401b5383SAlexander Duyck ret_val = fm10k_get_host_state_generic(hw, switch_ready); 1621401b5383SAlexander Duyck if (ret_val) 1622401b5383SAlexander Duyck goto out; 1623401b5383SAlexander Duyck 1624401b5383SAlexander Duyck /* interface cannot receive traffic without logical ports */ 1625401b5383SAlexander Duyck if (hw->mac.dglort_map == FM10K_DGLORTMAP_NONE) 1626401b5383SAlexander Duyck ret_val = fm10k_request_lport_map_pf(hw); 1627401b5383SAlexander Duyck 1628401b5383SAlexander Duyck out: 1629401b5383SAlexander Duyck return ret_val; 1630401b5383SAlexander Duyck } 1631401b5383SAlexander Duyck 1632401b5383SAlexander Duyck /* This structure defines the attibutes to be parsed below */ 1633401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = { 1634401b5383SAlexander Duyck FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP), 1635401b5383SAlexander Duyck FM10K_TLV_ATTR_LAST 1636401b5383SAlexander Duyck }; 1637401b5383SAlexander Duyck 1638401b5383SAlexander Duyck /** 1639401b5383SAlexander Duyck * fm10k_msg_lport_map_pf - Message handler for lport_map message from SM 1640401b5383SAlexander Duyck * @hw: Pointer to hardware structure 1641401b5383SAlexander Duyck * @results: pointer array containing parsed data 1642401b5383SAlexander Duyck * @mbx: Pointer to mailbox information structure 1643401b5383SAlexander Duyck * 1644401b5383SAlexander Duyck * This handler configures the lport mapping based on the reply from the 1645401b5383SAlexander Duyck * switch API. 1646401b5383SAlexander Duyck **/ 1647401b5383SAlexander Duyck s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results, 1648401b5383SAlexander Duyck struct fm10k_mbx_info *mbx) 1649401b5383SAlexander Duyck { 1650401b5383SAlexander Duyck u16 glort, mask; 1651401b5383SAlexander Duyck u32 dglort_map; 1652401b5383SAlexander Duyck s32 err; 1653401b5383SAlexander Duyck 1654401b5383SAlexander Duyck err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_LPORT_MAP], 1655401b5383SAlexander Duyck &dglort_map); 1656401b5383SAlexander Duyck if (err) 1657401b5383SAlexander Duyck return err; 1658401b5383SAlexander Duyck 1659401b5383SAlexander Duyck /* extract values out of the header */ 1660401b5383SAlexander Duyck glort = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_GLORT); 1661401b5383SAlexander Duyck mask = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_MASK); 1662401b5383SAlexander Duyck 1663401b5383SAlexander Duyck /* verify mask is set and none of the masked bits in glort are set */ 1664401b5383SAlexander Duyck if (!mask || (glort & ~mask)) 1665401b5383SAlexander Duyck return FM10K_ERR_PARAM; 1666401b5383SAlexander Duyck 1667401b5383SAlexander Duyck /* verify the mask is contiguous, and that it is 1's followed by 0's */ 1668401b5383SAlexander Duyck if (((~(mask - 1) & mask) + mask) & FM10K_DGLORTMAP_NONE) 1669401b5383SAlexander Duyck return FM10K_ERR_PARAM; 1670401b5383SAlexander Duyck 1671401b5383SAlexander Duyck /* record the glort, mask, and port count */ 1672401b5383SAlexander Duyck hw->mac.dglort_map = dglort_map; 1673401b5383SAlexander Duyck 1674401b5383SAlexander Duyck return 0; 1675401b5383SAlexander Duyck } 1676401b5383SAlexander Duyck 1677401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = { 1678401b5383SAlexander Duyck FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID), 1679401b5383SAlexander Duyck FM10K_TLV_ATTR_LAST 1680401b5383SAlexander Duyck }; 1681401b5383SAlexander Duyck 1682401b5383SAlexander Duyck /** 1683401b5383SAlexander Duyck * fm10k_msg_update_pvid_pf - Message handler for port VLAN message from SM 1684401b5383SAlexander Duyck * @hw: Pointer to hardware structure 1685401b5383SAlexander Duyck * @results: pointer array containing parsed data 1686401b5383SAlexander Duyck * @mbx: Pointer to mailbox information structure 1687401b5383SAlexander Duyck * 1688401b5383SAlexander Duyck * This handler configures the default VLAN for the PF 1689401b5383SAlexander Duyck **/ 1690401b5383SAlexander Duyck s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results, 1691401b5383SAlexander Duyck struct fm10k_mbx_info *mbx) 1692401b5383SAlexander Duyck { 1693401b5383SAlexander Duyck u16 glort, pvid; 1694401b5383SAlexander Duyck u32 pvid_update; 1695401b5383SAlexander Duyck s32 err; 1696401b5383SAlexander Duyck 1697401b5383SAlexander Duyck err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID], 1698401b5383SAlexander Duyck &pvid_update); 1699401b5383SAlexander Duyck if (err) 1700401b5383SAlexander Duyck return err; 1701401b5383SAlexander Duyck 1702401b5383SAlexander Duyck /* extract values from the pvid update */ 1703401b5383SAlexander Duyck glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT); 1704401b5383SAlexander Duyck pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID); 1705401b5383SAlexander Duyck 1706401b5383SAlexander Duyck /* if glort is not valid return error */ 1707401b5383SAlexander Duyck if (!fm10k_glort_valid_pf(hw, glort)) 1708401b5383SAlexander Duyck return FM10K_ERR_PARAM; 1709401b5383SAlexander Duyck 1710aa502b4aSJacob Keller /* verify VLAN ID is valid */ 1711401b5383SAlexander Duyck if (pvid >= FM10K_VLAN_TABLE_VID_MAX) 1712401b5383SAlexander Duyck return FM10K_ERR_PARAM; 1713401b5383SAlexander Duyck 1714401b5383SAlexander Duyck /* record the port VLAN ID value */ 1715401b5383SAlexander Duyck hw->mac.default_vid = pvid; 1716401b5383SAlexander Duyck 1717401b5383SAlexander Duyck return 0; 1718401b5383SAlexander Duyck } 1719401b5383SAlexander Duyck 1720401b5383SAlexander Duyck /** 1721401b5383SAlexander Duyck * fm10k_record_global_table_data - Move global table data to swapi table info 1722401b5383SAlexander Duyck * @from: pointer to source table data structure 1723401b5383SAlexander Duyck * @to: pointer to destination table info structure 1724401b5383SAlexander Duyck * 1725401b5383SAlexander Duyck * This function is will copy table_data to the table_info contained in 1726401b5383SAlexander Duyck * the hw struct. 1727401b5383SAlexander Duyck **/ 1728401b5383SAlexander Duyck static void fm10k_record_global_table_data(struct fm10k_global_table_data *from, 1729401b5383SAlexander Duyck struct fm10k_swapi_table_info *to) 1730401b5383SAlexander Duyck { 1731401b5383SAlexander Duyck /* convert from le32 struct to CPU byte ordered values */ 1732401b5383SAlexander Duyck to->used = le32_to_cpu(from->used); 1733401b5383SAlexander Duyck to->avail = le32_to_cpu(from->avail); 1734401b5383SAlexander Duyck } 1735401b5383SAlexander Duyck 1736401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_err_msg_attr[] = { 1737401b5383SAlexander Duyck FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR, 1738401b5383SAlexander Duyck sizeof(struct fm10k_swapi_error)), 1739401b5383SAlexander Duyck FM10K_TLV_ATTR_LAST 1740401b5383SAlexander Duyck }; 1741401b5383SAlexander Duyck 1742401b5383SAlexander Duyck /** 1743401b5383SAlexander Duyck * fm10k_msg_err_pf - Message handler for error reply 1744401b5383SAlexander Duyck * @hw: Pointer to hardware structure 1745401b5383SAlexander Duyck * @results: pointer array containing parsed data 1746401b5383SAlexander Duyck * @mbx: Pointer to mailbox information structure 1747401b5383SAlexander Duyck * 1748401b5383SAlexander Duyck * This handler will capture the data for any error replies to previous 1749401b5383SAlexander Duyck * messages that the PF has sent. 1750401b5383SAlexander Duyck **/ 1751401b5383SAlexander Duyck s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results, 1752401b5383SAlexander Duyck struct fm10k_mbx_info *mbx) 1753401b5383SAlexander Duyck { 1754401b5383SAlexander Duyck struct fm10k_swapi_error err_msg; 1755401b5383SAlexander Duyck s32 err; 1756401b5383SAlexander Duyck 1757401b5383SAlexander Duyck /* extract structure from message */ 1758401b5383SAlexander Duyck err = fm10k_tlv_attr_get_le_struct(results[FM10K_PF_ATTR_ID_ERR], 1759401b5383SAlexander Duyck &err_msg, sizeof(err_msg)); 1760401b5383SAlexander Duyck if (err) 1761401b5383SAlexander Duyck return err; 1762401b5383SAlexander Duyck 1763401b5383SAlexander Duyck /* record table status */ 1764401b5383SAlexander Duyck fm10k_record_global_table_data(&err_msg.mac, &hw->swapi.mac); 1765401b5383SAlexander Duyck fm10k_record_global_table_data(&err_msg.nexthop, &hw->swapi.nexthop); 1766401b5383SAlexander Duyck fm10k_record_global_table_data(&err_msg.ffu, &hw->swapi.ffu); 1767401b5383SAlexander Duyck 1768401b5383SAlexander Duyck /* record SW API status value */ 1769401b5383SAlexander Duyck hw->swapi.status = le32_to_cpu(err_msg.status); 1770401b5383SAlexander Duyck 1771401b5383SAlexander Duyck return 0; 1772401b5383SAlexander Duyck } 1773401b5383SAlexander Duyck 17745f226ddbSAlexander Duyck const struct fm10k_tlv_attr fm10k_1588_timestamp_msg_attr[] = { 17755f226ddbSAlexander Duyck FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_TIMESTAMP, 17765f226ddbSAlexander Duyck sizeof(struct fm10k_swapi_1588_timestamp)), 17775f226ddbSAlexander Duyck FM10K_TLV_ATTR_LAST 17785f226ddbSAlexander Duyck }; 17795f226ddbSAlexander Duyck 17805f226ddbSAlexander Duyck /* currently there is no shared 1588 timestamp handler */ 17815f226ddbSAlexander Duyck 17825f226ddbSAlexander Duyck /** 17835f226ddbSAlexander Duyck * fm10k_adjust_systime_pf - Adjust systime frequency 17845f226ddbSAlexander Duyck * @hw: pointer to hardware structure 17855f226ddbSAlexander Duyck * @ppb: adjustment rate in parts per billion 17865f226ddbSAlexander Duyck * 17875f226ddbSAlexander Duyck * This function will adjust the SYSTIME_CFG register contained in BAR 4 17885f226ddbSAlexander Duyck * if this function is supported for BAR 4 access. The adjustment amount 17895f226ddbSAlexander Duyck * is based on the parts per billion value provided and adjusted to a 17905f226ddbSAlexander Duyck * value based on parts per 2^48 clock cycles. 17915f226ddbSAlexander Duyck * 17925f226ddbSAlexander Duyck * If adjustment is not supported or the requested value is too large 17935f226ddbSAlexander Duyck * we will return an error. 17945f226ddbSAlexander Duyck **/ 17955f226ddbSAlexander Duyck static s32 fm10k_adjust_systime_pf(struct fm10k_hw *hw, s32 ppb) 17965f226ddbSAlexander Duyck { 17975f226ddbSAlexander Duyck u64 systime_adjust; 17985f226ddbSAlexander Duyck 17995f226ddbSAlexander Duyck /* if sw_addr is not set we don't have switch register access */ 18005f226ddbSAlexander Duyck if (!hw->sw_addr) 18015f226ddbSAlexander Duyck return ppb ? FM10K_ERR_PARAM : 0; 18025f226ddbSAlexander Duyck 18035f226ddbSAlexander Duyck /* we must convert the value from parts per billion to parts per 18045f226ddbSAlexander Duyck * 2^48 cycles. In addition I have opted to only use the 30 most 18055f226ddbSAlexander Duyck * significant bits of the adjustment value as the 8 least 18065f226ddbSAlexander Duyck * significant bits are located in another register and represent 18075f226ddbSAlexander Duyck * a value significantly less than a part per billion, the result 18085f226ddbSAlexander Duyck * of dropping the 8 least significant bits is that the adjustment 18095f226ddbSAlexander Duyck * value is effectively multiplied by 2^8 when we write it. 18105f226ddbSAlexander Duyck * 18115f226ddbSAlexander Duyck * As a result of all this the math for this breaks down as follows: 18125f226ddbSAlexander Duyck * ppb / 10^9 == adjust * 2^8 / 2^48 18135f226ddbSAlexander Duyck * If we solve this for adjust, and simplify it comes out as: 18145f226ddbSAlexander Duyck * ppb * 2^31 / 5^9 == adjust 18155f226ddbSAlexander Duyck */ 18165f226ddbSAlexander Duyck systime_adjust = (ppb < 0) ? -ppb : ppb; 18175f226ddbSAlexander Duyck systime_adjust <<= 31; 18185f226ddbSAlexander Duyck do_div(systime_adjust, 1953125); 18195f226ddbSAlexander Duyck 18205f226ddbSAlexander Duyck /* verify the requested adjustment value is in range */ 18215f226ddbSAlexander Duyck if (systime_adjust > FM10K_SW_SYSTIME_ADJUST_MASK) 18225f226ddbSAlexander Duyck return FM10K_ERR_PARAM; 18235f226ddbSAlexander Duyck 1824646725a7SJacob Keller if (ppb > 0) 1825646725a7SJacob Keller systime_adjust |= FM10K_SW_SYSTIME_ADJUST_DIR_POSITIVE; 18265f226ddbSAlexander Duyck 18275f226ddbSAlexander Duyck fm10k_write_sw_reg(hw, FM10K_SW_SYSTIME_ADJUST, (u32)systime_adjust); 18285f226ddbSAlexander Duyck 18295f226ddbSAlexander Duyck return 0; 18305f226ddbSAlexander Duyck } 18315f226ddbSAlexander Duyck 18325f226ddbSAlexander Duyck /** 18335f226ddbSAlexander Duyck * fm10k_read_systime_pf - Reads value of systime registers 18345f226ddbSAlexander Duyck * @hw: pointer to the hardware structure 18355f226ddbSAlexander Duyck * 18365f226ddbSAlexander Duyck * Function reads the content of 2 registers, combined to represent a 64 bit 18375f226ddbSAlexander Duyck * value measured in nanosecods. In order to guarantee the value is accurate 18385f226ddbSAlexander Duyck * we check the 32 most significant bits both before and after reading the 18395f226ddbSAlexander Duyck * 32 least significant bits to verify they didn't change as we were reading 18405f226ddbSAlexander Duyck * the registers. 18415f226ddbSAlexander Duyck **/ 18425f226ddbSAlexander Duyck static u64 fm10k_read_systime_pf(struct fm10k_hw *hw) 18435f226ddbSAlexander Duyck { 18445f226ddbSAlexander Duyck u32 systime_l, systime_h, systime_tmp; 18455f226ddbSAlexander Duyck 18465f226ddbSAlexander Duyck systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1); 18475f226ddbSAlexander Duyck 18485f226ddbSAlexander Duyck do { 18495f226ddbSAlexander Duyck systime_tmp = systime_h; 18505f226ddbSAlexander Duyck systime_l = fm10k_read_reg(hw, FM10K_SYSTIME); 18515f226ddbSAlexander Duyck systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1); 18525f226ddbSAlexander Duyck } while (systime_tmp != systime_h); 18535f226ddbSAlexander Duyck 18545f226ddbSAlexander Duyck return ((u64)systime_h << 32) | systime_l; 18555f226ddbSAlexander Duyck } 18565f226ddbSAlexander Duyck 1857401b5383SAlexander Duyck static const struct fm10k_msg_data fm10k_msg_data_pf[] = { 1858401b5383SAlexander Duyck FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf), 1859401b5383SAlexander Duyck FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf), 1860401b5383SAlexander Duyck FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf), 1861401b5383SAlexander Duyck FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf), 1862401b5383SAlexander Duyck FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf), 1863401b5383SAlexander Duyck FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf), 1864401b5383SAlexander Duyck FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error), 1865401b5383SAlexander Duyck }; 1866401b5383SAlexander Duyck 1867b6fec18fSAlexander Duyck static struct fm10k_mac_ops mac_ops_pf = { 1868b6fec18fSAlexander Duyck .get_bus_info = &fm10k_get_bus_info_generic, 1869b6fec18fSAlexander Duyck .reset_hw = &fm10k_reset_hw_pf, 1870b6fec18fSAlexander Duyck .init_hw = &fm10k_init_hw_pf, 1871b6fec18fSAlexander Duyck .start_hw = &fm10k_start_hw_generic, 1872b6fec18fSAlexander Duyck .stop_hw = &fm10k_stop_hw_generic, 1873401b5383SAlexander Duyck .update_vlan = &fm10k_update_vlan_pf, 1874b6fec18fSAlexander Duyck .read_mac_addr = &fm10k_read_mac_addr_pf, 1875401b5383SAlexander Duyck .update_uc_addr = &fm10k_update_uc_addr_pf, 1876401b5383SAlexander Duyck .update_mc_addr = &fm10k_update_mc_addr_pf, 1877401b5383SAlexander Duyck .update_xcast_mode = &fm10k_update_xcast_mode_pf, 1878401b5383SAlexander Duyck .update_int_moderator = &fm10k_update_int_moderator_pf, 1879401b5383SAlexander Duyck .update_lport_state = &fm10k_update_lport_state_pf, 1880b6fec18fSAlexander Duyck .update_hw_stats = &fm10k_update_hw_stats_pf, 1881b6fec18fSAlexander Duyck .rebind_hw_stats = &fm10k_rebind_hw_stats_pf, 1882401b5383SAlexander Duyck .configure_dglort_map = &fm10k_configure_dglort_map_pf, 1883401b5383SAlexander Duyck .set_dma_mask = &fm10k_set_dma_mask_pf, 1884b6fec18fSAlexander Duyck .get_fault = &fm10k_get_fault_pf, 1885401b5383SAlexander Duyck .get_host_state = &fm10k_get_host_state_pf, 18865f226ddbSAlexander Duyck .adjust_systime = &fm10k_adjust_systime_pf, 18875f226ddbSAlexander Duyck .read_systime = &fm10k_read_systime_pf, 1888b6fec18fSAlexander Duyck }; 1889b6fec18fSAlexander Duyck 1890c2653865SAlexander Duyck static struct fm10k_iov_ops iov_ops_pf = { 1891c2653865SAlexander Duyck .assign_resources = &fm10k_iov_assign_resources_pf, 1892c2653865SAlexander Duyck .configure_tc = &fm10k_iov_configure_tc_pf, 1893c2653865SAlexander Duyck .assign_int_moderator = &fm10k_iov_assign_int_moderator_pf, 1894c2653865SAlexander Duyck .assign_default_mac_vlan = fm10k_iov_assign_default_mac_vlan_pf, 1895c2653865SAlexander Duyck .reset_resources = &fm10k_iov_reset_resources_pf, 1896c2653865SAlexander Duyck .set_lport = &fm10k_iov_set_lport_pf, 1897c2653865SAlexander Duyck .reset_lport = &fm10k_iov_reset_lport_pf, 1898c2653865SAlexander Duyck .update_stats = &fm10k_iov_update_stats_pf, 18995f226ddbSAlexander Duyck .report_timestamp = &fm10k_iov_report_timestamp_pf, 1900c2653865SAlexander Duyck }; 1901c2653865SAlexander Duyck 1902401b5383SAlexander Duyck static s32 fm10k_get_invariants_pf(struct fm10k_hw *hw) 1903401b5383SAlexander Duyck { 1904401b5383SAlexander Duyck fm10k_get_invariants_generic(hw); 1905401b5383SAlexander Duyck 1906401b5383SAlexander Duyck return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf); 1907401b5383SAlexander Duyck } 1908401b5383SAlexander Duyck 1909b6fec18fSAlexander Duyck struct fm10k_info fm10k_pf_info = { 1910b6fec18fSAlexander Duyck .mac = fm10k_mac_pf, 1911401b5383SAlexander Duyck .get_invariants = &fm10k_get_invariants_pf, 1912b6fec18fSAlexander Duyck .mac_ops = &mac_ops_pf, 1913c2653865SAlexander Duyck .iov_ops = &iov_ops_pf, 1914b6fec18fSAlexander Duyck }; 1915