1b6fec18fSAlexander Duyck /* Intel Ethernet Switch Host Interface Driver
2b6fec18fSAlexander Duyck  * Copyright(c) 2013 - 2014 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 
62b6fec18fSAlexander Duyck 	/* Inititate data path reset */
63b6fec18fSAlexander Duyck 	reg |= FM10K_DMA_CTRL_DATAPATH_RESET;
64b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DMA_CTRL, reg);
65b6fec18fSAlexander Duyck 
66b6fec18fSAlexander Duyck 	/* Flush write and allow 100us for reset to complete */
67b6fec18fSAlexander Duyck 	fm10k_write_flush(hw);
68b6fec18fSAlexander Duyck 	udelay(FM10K_RESET_TIMEOUT);
69b6fec18fSAlexander Duyck 
70b6fec18fSAlexander Duyck 	/* Verify we made it out of reset */
71b6fec18fSAlexander Duyck 	reg = fm10k_read_reg(hw, FM10K_IP);
72b6fec18fSAlexander Duyck 	if (!(reg & FM10K_IP_NOTINRESET))
73b6fec18fSAlexander Duyck 		err = FM10K_ERR_RESET_FAILED;
74b6fec18fSAlexander Duyck 
75b6fec18fSAlexander Duyck 	return err;
76b6fec18fSAlexander Duyck }
77b6fec18fSAlexander Duyck 
78b6fec18fSAlexander Duyck /**
79c2653865SAlexander Duyck  *  fm10k_is_ari_hierarchy_pf - Indicate ARI hierarchy support
80c2653865SAlexander Duyck  *  @hw: pointer to hardware structure
81c2653865SAlexander Duyck  *
82c2653865SAlexander Duyck  *  Looks at the ARI hierarchy bit to determine whether ARI is supported or not.
83c2653865SAlexander Duyck  **/
84c2653865SAlexander Duyck static bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw *hw)
85c2653865SAlexander Duyck {
86c2653865SAlexander Duyck 	u16 sriov_ctrl = fm10k_read_pci_cfg_word(hw, FM10K_PCIE_SRIOV_CTRL);
87c2653865SAlexander Duyck 
88c2653865SAlexander Duyck 	return !!(sriov_ctrl & FM10K_PCIE_SRIOV_CTRL_VFARI);
89c2653865SAlexander Duyck }
90c2653865SAlexander Duyck 
91c2653865SAlexander Duyck /**
92b6fec18fSAlexander Duyck  *  fm10k_init_hw_pf - PF hardware initialization
93b6fec18fSAlexander Duyck  *  @hw: pointer to hardware structure
94b6fec18fSAlexander Duyck  *
95b6fec18fSAlexander Duyck  **/
96b6fec18fSAlexander Duyck static s32 fm10k_init_hw_pf(struct fm10k_hw *hw)
97b6fec18fSAlexander Duyck {
98b6fec18fSAlexander Duyck 	u32 dma_ctrl, txqctl;
99b6fec18fSAlexander Duyck 	u16 i;
100b6fec18fSAlexander Duyck 
101b6fec18fSAlexander Duyck 	/* Establish default VSI as valid */
102b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DGLORTDEC(fm10k_dglort_default), 0);
103b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DGLORTMAP(fm10k_dglort_default),
104b6fec18fSAlexander Duyck 			FM10K_DGLORTMAP_ANY);
105b6fec18fSAlexander Duyck 
106b6fec18fSAlexander Duyck 	/* Invalidate all other GLORT entries */
107b6fec18fSAlexander Duyck 	for (i = 1; i < FM10K_DGLORT_COUNT; i++)
108b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_DGLORTMAP(i), FM10K_DGLORTMAP_NONE);
109b6fec18fSAlexander Duyck 
110b6fec18fSAlexander Duyck 	/* reset ITR2(0) to point to itself */
111b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_ITR2(0), 0);
112b6fec18fSAlexander Duyck 
113b6fec18fSAlexander Duyck 	/* reset VF ITR2(0) to point to 0 avoid PF registers */
114b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), 0);
115b6fec18fSAlexander Duyck 
116b6fec18fSAlexander Duyck 	/* loop through all PF ITR2 registers pointing them to the previous */
117b6fec18fSAlexander Duyck 	for (i = 1; i < FM10K_ITR_REG_COUNT_PF; i++)
118b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
119b6fec18fSAlexander Duyck 
120b6fec18fSAlexander Duyck 	/* Enable interrupt moderator if not already enabled */
121b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
122b6fec18fSAlexander Duyck 
123b6fec18fSAlexander Duyck 	/* compute the default txqctl configuration */
124b6fec18fSAlexander Duyck 	txqctl = FM10K_TXQCTL_PF | FM10K_TXQCTL_UNLIMITED_BW |
125b6fec18fSAlexander Duyck 		 (hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT);
126b6fec18fSAlexander Duyck 
127b6fec18fSAlexander Duyck 	for (i = 0; i < FM10K_MAX_QUEUES; i++) {
128b6fec18fSAlexander Duyck 		/* configure rings for 256 Queue / 32 Descriptor cache mode */
129b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_TQDLOC(i),
130b6fec18fSAlexander Duyck 				(i * FM10K_TQDLOC_BASE_32_DESC) |
131b6fec18fSAlexander Duyck 				FM10K_TQDLOC_SIZE_32_DESC);
132b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
133b6fec18fSAlexander Duyck 
134b6fec18fSAlexander Duyck 		/* configure rings to provide TPH processing hints */
135b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_TPH_TXCTRL(i),
136b6fec18fSAlexander Duyck 				FM10K_TPH_TXCTRL_DESC_TPHEN |
137b6fec18fSAlexander Duyck 				FM10K_TPH_TXCTRL_DESC_RROEN |
138b6fec18fSAlexander Duyck 				FM10K_TPH_TXCTRL_DESC_WROEN |
139b6fec18fSAlexander Duyck 				FM10K_TPH_TXCTRL_DATA_RROEN);
140b6fec18fSAlexander Duyck 		fm10k_write_reg(hw, FM10K_TPH_RXCTRL(i),
141b6fec18fSAlexander Duyck 				FM10K_TPH_RXCTRL_DESC_TPHEN |
142b6fec18fSAlexander Duyck 				FM10K_TPH_RXCTRL_DESC_RROEN |
143b6fec18fSAlexander Duyck 				FM10K_TPH_RXCTRL_DATA_WROEN |
144b6fec18fSAlexander Duyck 				FM10K_TPH_RXCTRL_HDR_WROEN);
145b6fec18fSAlexander Duyck 	}
146b6fec18fSAlexander Duyck 
147b6fec18fSAlexander Duyck 	/* set max hold interval to align with 1.024 usec in all modes */
148b6fec18fSAlexander Duyck 	switch (hw->bus.speed) {
149b6fec18fSAlexander Duyck 	case fm10k_bus_speed_2500:
150b6fec18fSAlexander Duyck 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1;
151b6fec18fSAlexander Duyck 		break;
152b6fec18fSAlexander Duyck 	case fm10k_bus_speed_5000:
153b6fec18fSAlexander Duyck 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2;
154b6fec18fSAlexander Duyck 		break;
155b6fec18fSAlexander Duyck 	case fm10k_bus_speed_8000:
156b6fec18fSAlexander Duyck 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3;
157b6fec18fSAlexander Duyck 		break;
158b6fec18fSAlexander Duyck 	default:
159b6fec18fSAlexander Duyck 		dma_ctrl = 0;
160b6fec18fSAlexander Duyck 		break;
161b6fec18fSAlexander Duyck 	}
162b6fec18fSAlexander Duyck 
163b6fec18fSAlexander Duyck 	/* Configure TSO flags */
164b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DTXTCPFLGL, FM10K_TSO_FLAGS_LOW);
165b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DTXTCPFLGH, FM10K_TSO_FLAGS_HI);
166b6fec18fSAlexander Duyck 
167b6fec18fSAlexander Duyck 	/* Enable DMA engine
168b6fec18fSAlexander Duyck 	 * Set Rx Descriptor size to 32
169b6fec18fSAlexander Duyck 	 * Set Minimum MSS to 64
170b6fec18fSAlexander Duyck 	 * Set Maximum number of Rx queues to 256 / 32 Descriptor
171b6fec18fSAlexander Duyck 	 */
172b6fec18fSAlexander Duyck 	dma_ctrl |= FM10K_DMA_CTRL_TX_ENABLE | FM10K_DMA_CTRL_RX_ENABLE |
173b6fec18fSAlexander Duyck 		    FM10K_DMA_CTRL_RX_DESC_SIZE | FM10K_DMA_CTRL_MINMSS_64 |
174b6fec18fSAlexander Duyck 		    FM10K_DMA_CTRL_32_DESC;
175b6fec18fSAlexander Duyck 
176b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, FM10K_DMA_CTRL, dma_ctrl);
177b6fec18fSAlexander Duyck 
178b6fec18fSAlexander Duyck 	/* record maximum queue count, we limit ourselves to 128 */
179b6fec18fSAlexander Duyck 	hw->mac.max_queues = FM10K_MAX_QUEUES_PF;
180b6fec18fSAlexander Duyck 
181c2653865SAlexander Duyck 	/* We support either 64 VFs or 7 VFs depending on if we have ARI */
182c2653865SAlexander Duyck 	hw->iov.total_vfs = fm10k_is_ari_hierarchy_pf(hw) ? 64 : 7;
183c2653865SAlexander Duyck 
184b6fec18fSAlexander Duyck 	return 0;
185b6fec18fSAlexander Duyck }
186b6fec18fSAlexander Duyck 
187b6fec18fSAlexander Duyck /**
188b6fec18fSAlexander Duyck  *  fm10k_is_slot_appropriate_pf - Indicate appropriate slot for this SKU
189b6fec18fSAlexander Duyck  *  @hw: pointer to hardware structure
190b6fec18fSAlexander Duyck  *
191b6fec18fSAlexander Duyck  *  Looks at the PCIe bus info to confirm whether or not this slot can support
192b6fec18fSAlexander Duyck  *  the necessary bandwidth for this device.
193b6fec18fSAlexander Duyck  **/
194b6fec18fSAlexander Duyck static bool fm10k_is_slot_appropriate_pf(struct fm10k_hw *hw)
195b6fec18fSAlexander Duyck {
196b6fec18fSAlexander Duyck 	return (hw->bus.speed == hw->bus_caps.speed) &&
197b6fec18fSAlexander Duyck 	       (hw->bus.width == hw->bus_caps.width);
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 	int i;
270b6fec18fSAlexander Duyck 
271b6fec18fSAlexander Duyck 	serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(1));
272b6fec18fSAlexander Duyck 
273b6fec18fSAlexander Duyck 	/* last byte should be all 1's */
274b6fec18fSAlexander Duyck 	if ((~serial_num) << 24)
275b6fec18fSAlexander Duyck 		return  FM10K_ERR_INVALID_MAC_ADDR;
276b6fec18fSAlexander Duyck 
277b6fec18fSAlexander Duyck 	perm_addr[0] = (u8)(serial_num >> 24);
278b6fec18fSAlexander Duyck 	perm_addr[1] = (u8)(serial_num >> 16);
279b6fec18fSAlexander Duyck 	perm_addr[2] = (u8)(serial_num >> 8);
280b6fec18fSAlexander Duyck 
281b6fec18fSAlexander Duyck 	serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(0));
282b6fec18fSAlexander Duyck 
283b6fec18fSAlexander Duyck 	/* first byte should be all 1's */
284b6fec18fSAlexander Duyck 	if ((~serial_num) >> 24)
285b6fec18fSAlexander Duyck 		return  FM10K_ERR_INVALID_MAC_ADDR;
286b6fec18fSAlexander Duyck 
287b6fec18fSAlexander Duyck 	perm_addr[3] = (u8)(serial_num >> 16);
288b6fec18fSAlexander Duyck 	perm_addr[4] = (u8)(serial_num >> 8);
289b6fec18fSAlexander Duyck 	perm_addr[5] = (u8)(serial_num);
290b6fec18fSAlexander Duyck 
291b6fec18fSAlexander Duyck 	for (i = 0; i < ETH_ALEN; i++) {
292b6fec18fSAlexander Duyck 		hw->mac.perm_addr[i] = perm_addr[i];
293b6fec18fSAlexander Duyck 		hw->mac.addr[i] = perm_addr[i];
294b6fec18fSAlexander Duyck 	}
295b6fec18fSAlexander Duyck 
296b6fec18fSAlexander Duyck 	return 0;
297b6fec18fSAlexander Duyck }
298b6fec18fSAlexander Duyck 
299b6fec18fSAlexander Duyck /**
300401b5383SAlexander Duyck  *  fm10k_glort_valid_pf - Validate that the provided glort is valid
301401b5383SAlexander Duyck  *  @hw: pointer to the HW structure
302401b5383SAlexander Duyck  *  @glort: base glort to be validated
303401b5383SAlexander Duyck  *
304401b5383SAlexander Duyck  *  This function will return an error if the provided glort is invalid
305401b5383SAlexander Duyck  **/
306401b5383SAlexander Duyck bool fm10k_glort_valid_pf(struct fm10k_hw *hw, u16 glort)
307401b5383SAlexander Duyck {
308401b5383SAlexander Duyck 	glort &= hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT;
309401b5383SAlexander Duyck 
310401b5383SAlexander Duyck 	return glort == (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE);
311401b5383SAlexander Duyck }
312401b5383SAlexander Duyck 
313401b5383SAlexander Duyck /**
314eca32047SMatthew Vick  *  fm10k_update_xc_addr_pf - Update device addresses
315401b5383SAlexander Duyck  *  @hw: pointer to the HW structure
316401b5383SAlexander Duyck  *  @glort: base resource tag for this request
317401b5383SAlexander Duyck  *  @mac: MAC address to add/remove from table
318401b5383SAlexander Duyck  *  @vid: VLAN ID to add/remove from table
319401b5383SAlexander Duyck  *  @add: Indicates if this is an add or remove operation
320401b5383SAlexander Duyck  *  @flags: flags field to indicate add and secure
321401b5383SAlexander Duyck  *
322401b5383SAlexander Duyck  *  This function generates a message to the Switch API requesting
323401b5383SAlexander Duyck  *  that the given logical port add/remove the given L2 MAC/VLAN address.
324401b5383SAlexander Duyck  **/
325401b5383SAlexander Duyck static s32 fm10k_update_xc_addr_pf(struct fm10k_hw *hw, u16 glort,
326401b5383SAlexander Duyck 				   const u8 *mac, u16 vid, bool add, u8 flags)
327401b5383SAlexander Duyck {
328401b5383SAlexander Duyck 	struct fm10k_mbx_info *mbx = &hw->mbx;
329401b5383SAlexander Duyck 	struct fm10k_mac_update mac_update;
330401b5383SAlexander Duyck 	u32 msg[5];
331401b5383SAlexander Duyck 
332b32d15b9SJeff Kirsher 	/* clear set bit from VLAN ID */
333b32d15b9SJeff Kirsher 	vid &= ~FM10K_VLAN_CLEAR;
334b32d15b9SJeff Kirsher 
33533a44c28SMatthew Vick 	/* if glort or vlan are not valid return error */
33633a44c28SMatthew Vick 	if (!fm10k_glort_valid_pf(hw, glort) || vid >= FM10K_VLAN_TABLE_VID_MAX)
337401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
338401b5383SAlexander Duyck 
339401b5383SAlexander Duyck 	/* record fields */
340401b5383SAlexander Duyck 	mac_update.mac_lower = cpu_to_le32(((u32)mac[2] << 24) |
341401b5383SAlexander Duyck 						 ((u32)mac[3] << 16) |
342401b5383SAlexander Duyck 						 ((u32)mac[4] << 8) |
343401b5383SAlexander Duyck 						 ((u32)mac[5]));
344401b5383SAlexander Duyck 	mac_update.mac_upper = cpu_to_le16(((u32)mac[0] << 8) |
345401b5383SAlexander Duyck 						 ((u32)mac[1]));
346401b5383SAlexander Duyck 	mac_update.vlan = cpu_to_le16(vid);
347401b5383SAlexander Duyck 	mac_update.glort = cpu_to_le16(glort);
348401b5383SAlexander Duyck 	mac_update.action = add ? 0 : 1;
349401b5383SAlexander Duyck 	mac_update.flags = flags;
350401b5383SAlexander Duyck 
351401b5383SAlexander Duyck 	/* populate mac_update fields */
352401b5383SAlexander Duyck 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE);
353401b5383SAlexander Duyck 	fm10k_tlv_attr_put_le_struct(msg, FM10K_PF_ATTR_ID_MAC_UPDATE,
354401b5383SAlexander Duyck 				     &mac_update, sizeof(mac_update));
355401b5383SAlexander Duyck 
356401b5383SAlexander Duyck 	/* load onto outgoing mailbox */
357401b5383SAlexander Duyck 	return mbx->ops.enqueue_tx(hw, mbx, msg);
358401b5383SAlexander Duyck }
359401b5383SAlexander Duyck 
360401b5383SAlexander Duyck /**
361eca32047SMatthew Vick  *  fm10k_update_uc_addr_pf - Update device unicast addresses
362401b5383SAlexander Duyck  *  @hw: pointer to the HW structure
363401b5383SAlexander Duyck  *  @glort: base resource tag for this request
364401b5383SAlexander Duyck  *  @mac: MAC address to add/remove from table
365401b5383SAlexander Duyck  *  @vid: VLAN ID to add/remove from table
366401b5383SAlexander Duyck  *  @add: Indicates if this is an add or remove operation
367401b5383SAlexander Duyck  *  @flags: flags field to indicate add and secure
368401b5383SAlexander Duyck  *
369401b5383SAlexander Duyck  *  This function is used to add or remove unicast addresses for
370401b5383SAlexander Duyck  *  the PF.
371401b5383SAlexander Duyck  **/
372401b5383SAlexander Duyck static s32 fm10k_update_uc_addr_pf(struct fm10k_hw *hw, u16 glort,
373401b5383SAlexander Duyck 				   const u8 *mac, u16 vid, bool add, u8 flags)
374401b5383SAlexander Duyck {
375401b5383SAlexander Duyck 	/* verify MAC address is valid */
376401b5383SAlexander Duyck 	if (!is_valid_ether_addr(mac))
377401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
378401b5383SAlexander Duyck 
379401b5383SAlexander Duyck 	return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, flags);
380401b5383SAlexander Duyck }
381401b5383SAlexander Duyck 
382401b5383SAlexander Duyck /**
383401b5383SAlexander Duyck  *  fm10k_update_mc_addr_pf - Update device multicast addresses
384401b5383SAlexander Duyck  *  @hw: pointer to the HW structure
385401b5383SAlexander Duyck  *  @glort: base resource tag for this request
386401b5383SAlexander Duyck  *  @mac: MAC address to add/remove from table
387401b5383SAlexander Duyck  *  @vid: VLAN ID to add/remove from table
388401b5383SAlexander Duyck  *  @add: Indicates if this is an add or remove operation
389401b5383SAlexander Duyck  *
390401b5383SAlexander Duyck  *  This function is used to add or remove multicast MAC addresses for
391401b5383SAlexander Duyck  *  the PF.
392401b5383SAlexander Duyck  **/
393401b5383SAlexander Duyck static s32 fm10k_update_mc_addr_pf(struct fm10k_hw *hw, u16 glort,
394401b5383SAlexander Duyck 				   const u8 *mac, u16 vid, bool add)
395401b5383SAlexander Duyck {
396401b5383SAlexander Duyck 	/* verify multicast address is valid */
397401b5383SAlexander Duyck 	if (!is_multicast_ether_addr(mac))
398401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
399401b5383SAlexander Duyck 
400401b5383SAlexander Duyck 	return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, 0);
401401b5383SAlexander Duyck }
402401b5383SAlexander Duyck 
403401b5383SAlexander Duyck /**
404401b5383SAlexander Duyck  *  fm10k_update_xcast_mode_pf - Request update of multicast mode
405401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
406401b5383SAlexander Duyck  *  @glort: base resource tag for this request
407401b5383SAlexander Duyck  *  @mode: integer value indicating mode being requested
408401b5383SAlexander Duyck  *
409401b5383SAlexander Duyck  *  This function will attempt to request a higher mode for the port
410401b5383SAlexander Duyck  *  so that it can enable either multicast, multicast promiscuous, or
411401b5383SAlexander Duyck  *  promiscuous mode of operation.
412401b5383SAlexander Duyck  **/
413401b5383SAlexander Duyck static s32 fm10k_update_xcast_mode_pf(struct fm10k_hw *hw, u16 glort, u8 mode)
414401b5383SAlexander Duyck {
415401b5383SAlexander Duyck 	struct fm10k_mbx_info *mbx = &hw->mbx;
416401b5383SAlexander Duyck 	u32 msg[3], xcast_mode;
417401b5383SAlexander Duyck 
418401b5383SAlexander Duyck 	if (mode > FM10K_XCAST_MODE_NONE)
419401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
420401b5383SAlexander Duyck 	/* if glort is not valid return error */
421401b5383SAlexander Duyck 	if (!fm10k_glort_valid_pf(hw, glort))
422401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
423401b5383SAlexander Duyck 
424401b5383SAlexander Duyck 	/* write xcast mode as a single u32 value,
425401b5383SAlexander Duyck 	 * lower 16 bits: glort
426401b5383SAlexander Duyck 	 * upper 16 bits: mode
427401b5383SAlexander Duyck 	 */
428401b5383SAlexander Duyck 	xcast_mode = ((u32)mode << 16) | glort;
429401b5383SAlexander Duyck 
430401b5383SAlexander Duyck 	/* generate message requesting to change xcast mode */
431401b5383SAlexander Duyck 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_XCAST_MODES);
432401b5383SAlexander Duyck 	fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_XCAST_MODE, xcast_mode);
433401b5383SAlexander Duyck 
434401b5383SAlexander Duyck 	/* load onto outgoing mailbox */
435401b5383SAlexander Duyck 	return mbx->ops.enqueue_tx(hw, mbx, msg);
436401b5383SAlexander Duyck }
437401b5383SAlexander Duyck 
438401b5383SAlexander Duyck /**
439401b5383SAlexander Duyck  *  fm10k_update_int_moderator_pf - Update interrupt moderator linked list
440401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
441401b5383SAlexander Duyck  *
442401b5383SAlexander Duyck  *  This function walks through the MSI-X vector table to determine the
443401b5383SAlexander Duyck  *  number of active interrupts and based on that information updates the
444401b5383SAlexander Duyck  *  interrupt moderator linked list.
445401b5383SAlexander Duyck  **/
446401b5383SAlexander Duyck static void fm10k_update_int_moderator_pf(struct fm10k_hw *hw)
447401b5383SAlexander Duyck {
448401b5383SAlexander Duyck 	u32 i;
449401b5383SAlexander Duyck 
450401b5383SAlexander Duyck 	/* Disable interrupt moderator */
451401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_INT_CTRL, 0);
452401b5383SAlexander Duyck 
453401b5383SAlexander Duyck 	/* loop through PF from last to first looking enabled vectors */
454401b5383SAlexander Duyck 	for (i = FM10K_ITR_REG_COUNT_PF - 1; i; i--) {
455401b5383SAlexander Duyck 		if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
456401b5383SAlexander Duyck 			break;
457401b5383SAlexander Duyck 	}
458401b5383SAlexander Duyck 
459401b5383SAlexander Duyck 	/* always reset VFITR2[0] to point to last enabled PF vector */
460401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), i);
461401b5383SAlexander Duyck 
462401b5383SAlexander Duyck 	/* reset ITR2[0] to point to last enabled PF vector */
463c2653865SAlexander Duyck 	if (!hw->iov.num_vfs)
464401b5383SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(0), i);
465401b5383SAlexander Duyck 
466401b5383SAlexander Duyck 	/* Enable interrupt moderator */
467401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
468401b5383SAlexander Duyck }
469401b5383SAlexander Duyck 
470401b5383SAlexander Duyck /**
471401b5383SAlexander Duyck  *  fm10k_update_lport_state_pf - Notify the switch of a change in port state
472401b5383SAlexander Duyck  *  @hw: pointer to the HW structure
473401b5383SAlexander Duyck  *  @glort: base resource tag for this request
474401b5383SAlexander Duyck  *  @count: number of logical ports being updated
475401b5383SAlexander Duyck  *  @enable: boolean value indicating enable or disable
476401b5383SAlexander Duyck  *
477401b5383SAlexander Duyck  *  This function is used to add/remove a logical port from the switch.
478401b5383SAlexander Duyck  **/
479401b5383SAlexander Duyck static s32 fm10k_update_lport_state_pf(struct fm10k_hw *hw, u16 glort,
480401b5383SAlexander Duyck 				       u16 count, bool enable)
481401b5383SAlexander Duyck {
482401b5383SAlexander Duyck 	struct fm10k_mbx_info *mbx = &hw->mbx;
483401b5383SAlexander Duyck 	u32 msg[3], lport_msg;
484401b5383SAlexander Duyck 
485401b5383SAlexander Duyck 	/* do nothing if we are being asked to create or destroy 0 ports */
486401b5383SAlexander Duyck 	if (!count)
487401b5383SAlexander Duyck 		return 0;
488401b5383SAlexander Duyck 
489401b5383SAlexander Duyck 	/* if glort is not valid return error */
490401b5383SAlexander Duyck 	if (!fm10k_glort_valid_pf(hw, glort))
491401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
492401b5383SAlexander Duyck 
493401b5383SAlexander Duyck 	/* construct the lport message from the 2 pieces of data we have */
494401b5383SAlexander Duyck 	lport_msg = ((u32)count << 16) | glort;
495401b5383SAlexander Duyck 
496401b5383SAlexander Duyck 	/* generate lport create/delete message */
497401b5383SAlexander Duyck 	fm10k_tlv_msg_init(msg, enable ? FM10K_PF_MSG_ID_LPORT_CREATE :
498401b5383SAlexander Duyck 					 FM10K_PF_MSG_ID_LPORT_DELETE);
499401b5383SAlexander Duyck 	fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_PORT, lport_msg);
500401b5383SAlexander Duyck 
501401b5383SAlexander Duyck 	/* load onto outgoing mailbox */
502401b5383SAlexander Duyck 	return mbx->ops.enqueue_tx(hw, mbx, msg);
503401b5383SAlexander Duyck }
504401b5383SAlexander Duyck 
505401b5383SAlexander Duyck /**
506401b5383SAlexander Duyck  *  fm10k_configure_dglort_map_pf - Configures GLORT entry and queues
507401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
508401b5383SAlexander Duyck  *  @dglort: pointer to dglort configuration structure
509401b5383SAlexander Duyck  *
510401b5383SAlexander Duyck  *  Reads the configuration structure contained in dglort_cfg and uses
511401b5383SAlexander Duyck  *  that information to then populate a DGLORTMAP/DEC entry and the queues
512401b5383SAlexander Duyck  *  to which it has been assigned.
513401b5383SAlexander Duyck  **/
514401b5383SAlexander Duyck static s32 fm10k_configure_dglort_map_pf(struct fm10k_hw *hw,
515401b5383SAlexander Duyck 					 struct fm10k_dglort_cfg *dglort)
516401b5383SAlexander Duyck {
517401b5383SAlexander Duyck 	u16 glort, queue_count, vsi_count, pc_count;
518401b5383SAlexander Duyck 	u16 vsi, queue, pc, q_idx;
519401b5383SAlexander Duyck 	u32 txqctl, dglortdec, dglortmap;
520401b5383SAlexander Duyck 
521401b5383SAlexander Duyck 	/* verify the dglort pointer */
522401b5383SAlexander Duyck 	if (!dglort)
523401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
524401b5383SAlexander Duyck 
525401b5383SAlexander Duyck 	/* verify the dglort values */
526401b5383SAlexander Duyck 	if ((dglort->idx > 7) || (dglort->rss_l > 7) || (dglort->pc_l > 3) ||
527401b5383SAlexander Duyck 	    (dglort->vsi_l > 6) || (dglort->vsi_b > 64) ||
528401b5383SAlexander Duyck 	    (dglort->queue_l > 8) || (dglort->queue_b >= 256))
529401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
530401b5383SAlexander Duyck 
531401b5383SAlexander Duyck 	/* determine count of VSIs and queues */
532401b5383SAlexander Duyck 	queue_count = 1 << (dglort->rss_l + dglort->pc_l);
533401b5383SAlexander Duyck 	vsi_count = 1 << (dglort->vsi_l + dglort->queue_l);
534401b5383SAlexander Duyck 	glort = dglort->glort;
535401b5383SAlexander Duyck 	q_idx = dglort->queue_b;
536401b5383SAlexander Duyck 
537401b5383SAlexander Duyck 	/* configure SGLORT for queues */
538401b5383SAlexander Duyck 	for (vsi = 0; vsi < vsi_count; vsi++, glort++) {
539401b5383SAlexander Duyck 		for (queue = 0; queue < queue_count; queue++, q_idx++) {
540401b5383SAlexander Duyck 			if (q_idx >= FM10K_MAX_QUEUES)
541401b5383SAlexander Duyck 				break;
542401b5383SAlexander Duyck 
543401b5383SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TX_SGLORT(q_idx), glort);
544401b5383SAlexander Duyck 			fm10k_write_reg(hw, FM10K_RX_SGLORT(q_idx), glort);
545401b5383SAlexander Duyck 		}
546401b5383SAlexander Duyck 	}
547401b5383SAlexander Duyck 
548401b5383SAlexander Duyck 	/* determine count of PCs and queues */
549401b5383SAlexander Duyck 	queue_count = 1 << (dglort->queue_l + dglort->rss_l + dglort->vsi_l);
550401b5383SAlexander Duyck 	pc_count = 1 << dglort->pc_l;
551401b5383SAlexander Duyck 
552401b5383SAlexander Duyck 	/* configure PC for Tx queues */
553401b5383SAlexander Duyck 	for (pc = 0; pc < pc_count; pc++) {
554401b5383SAlexander Duyck 		q_idx = pc + dglort->queue_b;
555401b5383SAlexander Duyck 		for (queue = 0; queue < queue_count; queue++) {
556401b5383SAlexander Duyck 			if (q_idx >= FM10K_MAX_QUEUES)
557401b5383SAlexander Duyck 				break;
558401b5383SAlexander Duyck 
559401b5383SAlexander Duyck 			txqctl = fm10k_read_reg(hw, FM10K_TXQCTL(q_idx));
560401b5383SAlexander Duyck 			txqctl &= ~FM10K_TXQCTL_PC_MASK;
561401b5383SAlexander Duyck 			txqctl |= pc << FM10K_TXQCTL_PC_SHIFT;
562401b5383SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TXQCTL(q_idx), txqctl);
563401b5383SAlexander Duyck 
564401b5383SAlexander Duyck 			q_idx += pc_count;
565401b5383SAlexander Duyck 		}
566401b5383SAlexander Duyck 	}
567401b5383SAlexander Duyck 
568401b5383SAlexander Duyck 	/* configure DGLORTDEC */
569401b5383SAlexander Duyck 	dglortdec = ((u32)(dglort->rss_l) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) |
570401b5383SAlexander Duyck 		    ((u32)(dglort->queue_b) << FM10K_DGLORTDEC_QBASE_SHIFT) |
571401b5383SAlexander Duyck 		    ((u32)(dglort->pc_l) << FM10K_DGLORTDEC_PCLENGTH_SHIFT) |
572401b5383SAlexander Duyck 		    ((u32)(dglort->vsi_b) << FM10K_DGLORTDEC_VSIBASE_SHIFT) |
573401b5383SAlexander Duyck 		    ((u32)(dglort->vsi_l) << FM10K_DGLORTDEC_VSILENGTH_SHIFT) |
574401b5383SAlexander Duyck 		    ((u32)(dglort->queue_l));
575401b5383SAlexander Duyck 	if (dglort->inner_rss)
576401b5383SAlexander Duyck 		dglortdec |=  FM10K_DGLORTDEC_INNERRSS_ENABLE;
577401b5383SAlexander Duyck 
578401b5383SAlexander Duyck 	/* configure DGLORTMAP */
579401b5383SAlexander Duyck 	dglortmap = (dglort->idx == fm10k_dglort_default) ?
580401b5383SAlexander Duyck 			FM10K_DGLORTMAP_ANY : FM10K_DGLORTMAP_ZERO;
581401b5383SAlexander Duyck 	dglortmap <<= dglort->vsi_l + dglort->queue_l + dglort->shared_l;
582401b5383SAlexander Duyck 	dglortmap |= dglort->glort;
583401b5383SAlexander Duyck 
584401b5383SAlexander Duyck 	/* write values to hardware */
585401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_DGLORTDEC(dglort->idx), dglortdec);
586401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_DGLORTMAP(dglort->idx), dglortmap);
587401b5383SAlexander Duyck 
588401b5383SAlexander Duyck 	return 0;
589401b5383SAlexander Duyck }
590401b5383SAlexander Duyck 
591c2653865SAlexander Duyck u16 fm10k_queues_per_pool(struct fm10k_hw *hw)
592c2653865SAlexander Duyck {
593c2653865SAlexander Duyck 	u16 num_pools = hw->iov.num_pools;
594c2653865SAlexander Duyck 
595c2653865SAlexander Duyck 	return (num_pools > 32) ? 2 : (num_pools > 16) ? 4 : (num_pools > 8) ?
596c2653865SAlexander Duyck 	       8 : FM10K_MAX_QUEUES_POOL;
597c2653865SAlexander Duyck }
598c2653865SAlexander Duyck 
599c2653865SAlexander Duyck u16 fm10k_vf_queue_index(struct fm10k_hw *hw, u16 vf_idx)
600c2653865SAlexander Duyck {
601c2653865SAlexander Duyck 	u16 num_vfs = hw->iov.num_vfs;
602c2653865SAlexander Duyck 	u16 vf_q_idx = FM10K_MAX_QUEUES;
603c2653865SAlexander Duyck 
604c2653865SAlexander Duyck 	vf_q_idx -= fm10k_queues_per_pool(hw) * (num_vfs - vf_idx);
605c2653865SAlexander Duyck 
606c2653865SAlexander Duyck 	return vf_q_idx;
607c2653865SAlexander Duyck }
608c2653865SAlexander Duyck 
609c2653865SAlexander Duyck static u16 fm10k_vectors_per_pool(struct fm10k_hw *hw)
610c2653865SAlexander Duyck {
611c2653865SAlexander Duyck 	u16 num_pools = hw->iov.num_pools;
612c2653865SAlexander Duyck 
613c2653865SAlexander Duyck 	return (num_pools > 32) ? 8 : (num_pools > 16) ? 16 :
614c2653865SAlexander Duyck 	       FM10K_MAX_VECTORS_POOL;
615c2653865SAlexander Duyck }
616c2653865SAlexander Duyck 
617c2653865SAlexander Duyck static u16 fm10k_vf_vector_index(struct fm10k_hw *hw, u16 vf_idx)
618c2653865SAlexander Duyck {
619c2653865SAlexander Duyck 	u16 vf_v_idx = FM10K_MAX_VECTORS_PF;
620c2653865SAlexander Duyck 
621c2653865SAlexander Duyck 	vf_v_idx += fm10k_vectors_per_pool(hw) * vf_idx;
622c2653865SAlexander Duyck 
623c2653865SAlexander Duyck 	return vf_v_idx;
624c2653865SAlexander Duyck }
625c2653865SAlexander Duyck 
626c2653865SAlexander Duyck /**
627c2653865SAlexander Duyck  *  fm10k_iov_assign_resources_pf - Assign pool resources for virtualization
628c2653865SAlexander Duyck  *  @hw: pointer to the HW structure
629c2653865SAlexander Duyck  *  @num_vfs: number of VFs to be allocated
630c2653865SAlexander Duyck  *  @num_pools: number of virtualization pools to be allocated
631c2653865SAlexander Duyck  *
632c2653865SAlexander Duyck  *  Allocates queues and traffic classes to virtualization entities to prepare
633c2653865SAlexander Duyck  *  the PF for SR-IOV and VMDq
634c2653865SAlexander Duyck  **/
635c2653865SAlexander Duyck static s32 fm10k_iov_assign_resources_pf(struct fm10k_hw *hw, u16 num_vfs,
636c2653865SAlexander Duyck 					 u16 num_pools)
637c2653865SAlexander Duyck {
638c2653865SAlexander Duyck 	u16 qmap_stride, qpp, vpp, vf_q_idx, vf_q_idx0, qmap_idx;
639c2653865SAlexander Duyck 	u32 vid = hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT;
640c2653865SAlexander Duyck 	int i, j;
641c2653865SAlexander Duyck 
642c2653865SAlexander Duyck 	/* hardware only supports up to 64 pools */
643c2653865SAlexander Duyck 	if (num_pools > 64)
644c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
645c2653865SAlexander Duyck 
646c2653865SAlexander Duyck 	/* the number of VFs cannot exceed the number of pools */
647c2653865SAlexander Duyck 	if ((num_vfs > num_pools) || (num_vfs > hw->iov.total_vfs))
648c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
649c2653865SAlexander Duyck 
650c2653865SAlexander Duyck 	/* record number of virtualization entities */
651c2653865SAlexander Duyck 	hw->iov.num_vfs = num_vfs;
652c2653865SAlexander Duyck 	hw->iov.num_pools = num_pools;
653c2653865SAlexander Duyck 
654c2653865SAlexander Duyck 	/* determine qmap offsets and counts */
655c2653865SAlexander Duyck 	qmap_stride = (num_vfs > 8) ? 32 : 256;
656c2653865SAlexander Duyck 	qpp = fm10k_queues_per_pool(hw);
657c2653865SAlexander Duyck 	vpp = fm10k_vectors_per_pool(hw);
658c2653865SAlexander Duyck 
659c2653865SAlexander Duyck 	/* calculate starting index for queues */
660c2653865SAlexander Duyck 	vf_q_idx = fm10k_vf_queue_index(hw, 0);
661c2653865SAlexander Duyck 	qmap_idx = 0;
662c2653865SAlexander Duyck 
663c2653865SAlexander Duyck 	/* establish TCs with -1 credits and no quanta to prevent transmit */
664c2653865SAlexander Duyck 	for (i = 0; i < num_vfs; i++) {
665c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(i), 0);
666c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TC_RATE(i), 0);
667c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TC_CREDIT(i),
668c2653865SAlexander Duyck 				FM10K_TC_CREDIT_CREDIT_MASK);
669c2653865SAlexander Duyck 	}
670c2653865SAlexander Duyck 
671c2653865SAlexander Duyck 	/* zero out all mbmem registers */
672c2653865SAlexander Duyck 	for (i = FM10K_VFMBMEM_LEN * num_vfs; i--;)
673c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_MBMEM(i), 0);
674c2653865SAlexander Duyck 
675c2653865SAlexander Duyck 	/* clear event notification of VF FLR */
676c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_PFVFLREC(0), ~0);
677c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_PFVFLREC(1), ~0);
678c2653865SAlexander Duyck 
679c2653865SAlexander Duyck 	/* loop through unallocated rings assigning them back to PF */
680c2653865SAlexander Duyck 	for (i = FM10K_MAX_QUEUES_PF; i < vf_q_idx; i++) {
681c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
682ded8b20dSJeff Kirsher 		fm10k_write_reg(hw, FM10K_TXQCTL(i), FM10K_TXQCTL_PF |
683ded8b20dSJeff Kirsher 				FM10K_TXQCTL_UNLIMITED_BW | vid);
684c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RXQCTL(i), FM10K_RXQCTL_PF);
685c2653865SAlexander Duyck 	}
686c2653865SAlexander Duyck 
687c2653865SAlexander Duyck 	/* PF should have already updated VFITR2[0] */
688c2653865SAlexander Duyck 
689c2653865SAlexander Duyck 	/* update all ITR registers to flow to VFITR2[0] */
690c2653865SAlexander Duyck 	for (i = FM10K_ITR_REG_COUNT_PF + 1; i < FM10K_ITR_REG_COUNT; i++) {
691c2653865SAlexander Duyck 		if (!(i & (vpp - 1)))
692c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_ITR2(i), i - vpp);
693c2653865SAlexander Duyck 		else
694c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
695c2653865SAlexander Duyck 	}
696c2653865SAlexander Duyck 
697c2653865SAlexander Duyck 	/* update PF ITR2[0] to reference the last vector */
698c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_ITR2(0),
699c2653865SAlexander Duyck 			fm10k_vf_vector_index(hw, num_vfs - 1));
700c2653865SAlexander Duyck 
701c2653865SAlexander Duyck 	/* loop through rings populating rings and TCs */
702c2653865SAlexander Duyck 	for (i = 0; i < num_vfs; i++) {
703c2653865SAlexander Duyck 		/* record index for VF queue 0 for use in end of loop */
704c2653865SAlexander Duyck 		vf_q_idx0 = vf_q_idx;
705c2653865SAlexander Duyck 
706c2653865SAlexander Duyck 		for (j = 0; j < qpp; j++, qmap_idx++, vf_q_idx++) {
707c2653865SAlexander Duyck 			/* assign VF and locked TC to queues */
708c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
709c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx),
710c2653865SAlexander Duyck 					(i << FM10K_TXQCTL_TC_SHIFT) | i |
711c2653865SAlexander Duyck 					FM10K_TXQCTL_VF | vid);
712c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_RXDCTL(vf_q_idx),
713c2653865SAlexander Duyck 					FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
714c2653865SAlexander Duyck 					FM10K_RXDCTL_DROP_ON_EMPTY);
715c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_RXQCTL(vf_q_idx),
716c2653865SAlexander Duyck 					FM10K_RXQCTL_VF |
717c2653865SAlexander Duyck 					(i << FM10K_RXQCTL_VF_SHIFT));
718c2653865SAlexander Duyck 
719c2653865SAlexander Duyck 			/* map queue pair to VF */
720c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
721c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx);
722c2653865SAlexander Duyck 		}
723c2653865SAlexander Duyck 
724c2653865SAlexander Duyck 		/* repeat the first ring for all of the remaining VF rings */
725c2653865SAlexander Duyck 		for (; j < qmap_stride; j++, qmap_idx++) {
726c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx0);
727c2653865SAlexander Duyck 			fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx0);
728c2653865SAlexander Duyck 		}
729c2653865SAlexander Duyck 	}
730c2653865SAlexander Duyck 
731c2653865SAlexander Duyck 	/* loop through remaining indexes assigning all to queue 0 */
732c2653865SAlexander Duyck 	while (qmap_idx < FM10K_TQMAP_TABLE_SIZE) {
733c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
734c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), 0);
735c2653865SAlexander Duyck 		qmap_idx++;
736c2653865SAlexander Duyck 	}
737c2653865SAlexander Duyck 
738c2653865SAlexander Duyck 	return 0;
739c2653865SAlexander Duyck }
740c2653865SAlexander Duyck 
741c2653865SAlexander Duyck /**
742c2653865SAlexander Duyck  *  fm10k_iov_configure_tc_pf - Configure the shaping group for VF
743c2653865SAlexander Duyck  *  @hw: pointer to the HW structure
744c2653865SAlexander Duyck  *  @vf_idx: index of VF receiving GLORT
745c2653865SAlexander Duyck  *  @rate: Rate indicated in Mb/s
746c2653865SAlexander Duyck  *
747c2653865SAlexander Duyck  *  Configured the TC for a given VF to allow only up to a given number
748c2653865SAlexander Duyck  *  of Mb/s of outgoing Tx throughput.
749c2653865SAlexander Duyck  **/
750c2653865SAlexander Duyck static s32 fm10k_iov_configure_tc_pf(struct fm10k_hw *hw, u16 vf_idx, int rate)
751c2653865SAlexander Duyck {
752c2653865SAlexander Duyck 	/* configure defaults */
753c2653865SAlexander Duyck 	u32 interval = FM10K_TC_RATE_INTERVAL_4US_GEN3;
754c2653865SAlexander Duyck 	u32 tc_rate = FM10K_TC_RATE_QUANTA_MASK;
755c2653865SAlexander Duyck 
756c2653865SAlexander Duyck 	/* verify vf is in range */
757c2653865SAlexander Duyck 	if (vf_idx >= hw->iov.num_vfs)
758c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
759c2653865SAlexander Duyck 
760c2653865SAlexander Duyck 	/* set interval to align with 4.096 usec in all modes */
761c2653865SAlexander Duyck 	switch (hw->bus.speed) {
762c2653865SAlexander Duyck 	case fm10k_bus_speed_2500:
763c2653865SAlexander Duyck 		interval = FM10K_TC_RATE_INTERVAL_4US_GEN1;
764c2653865SAlexander Duyck 		break;
765c2653865SAlexander Duyck 	case fm10k_bus_speed_5000:
766c2653865SAlexander Duyck 		interval = FM10K_TC_RATE_INTERVAL_4US_GEN2;
767c2653865SAlexander Duyck 		break;
768c2653865SAlexander Duyck 	default:
769c2653865SAlexander Duyck 		break;
770c2653865SAlexander Duyck 	}
771c2653865SAlexander Duyck 
772c2653865SAlexander Duyck 	if (rate) {
773c2653865SAlexander Duyck 		if (rate > FM10K_VF_TC_MAX || rate < FM10K_VF_TC_MIN)
774c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
775c2653865SAlexander Duyck 
776c2653865SAlexander Duyck 		/* The quanta is measured in Bytes per 4.096 or 8.192 usec
777c2653865SAlexander Duyck 		 * The rate is provided in Mbits per second
778c2653865SAlexander Duyck 		 * To tralslate from rate to quanta we need to multiply the
779c2653865SAlexander Duyck 		 * rate by 8.192 usec and divide by 8 bits/byte.  To avoid
780c2653865SAlexander Duyck 		 * dealing with floating point we can round the values up
781c2653865SAlexander Duyck 		 * to the nearest whole number ratio which gives us 128 / 125.
782c2653865SAlexander Duyck 		 */
783c2653865SAlexander Duyck 		tc_rate = (rate * 128) / 125;
784c2653865SAlexander Duyck 
785c2653865SAlexander Duyck 		/* try to keep the rate limiting accurate by increasing
786c2653865SAlexander Duyck 		 * the number of credits and interval for rates less than 4Gb/s
787c2653865SAlexander Duyck 		 */
788c2653865SAlexander Duyck 		if (rate < 4000)
789c2653865SAlexander Duyck 			interval <<= 1;
790c2653865SAlexander Duyck 		else
791c2653865SAlexander Duyck 			tc_rate >>= 1;
792c2653865SAlexander Duyck 	}
793c2653865SAlexander Duyck 
794c2653865SAlexander Duyck 	/* update rate limiter with new values */
795c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), tc_rate | interval);
796c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
797c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
798c2653865SAlexander Duyck 
799c2653865SAlexander Duyck 	return 0;
800c2653865SAlexander Duyck }
801c2653865SAlexander Duyck 
802c2653865SAlexander Duyck /**
803c2653865SAlexander Duyck  *  fm10k_iov_assign_int_moderator_pf - Add VF interrupts to moderator list
804c2653865SAlexander Duyck  *  @hw: pointer to the HW structure
805c2653865SAlexander Duyck  *  @vf_idx: index of VF receiving GLORT
806c2653865SAlexander Duyck  *
807c2653865SAlexander Duyck  *  Update the interrupt moderator linked list to include any MSI-X
808c2653865SAlexander Duyck  *  interrupts which the VF has enabled in the MSI-X vector table.
809c2653865SAlexander Duyck  **/
810c2653865SAlexander Duyck static s32 fm10k_iov_assign_int_moderator_pf(struct fm10k_hw *hw, u16 vf_idx)
811c2653865SAlexander Duyck {
812c2653865SAlexander Duyck 	u16 vf_v_idx, vf_v_limit, i;
813c2653865SAlexander Duyck 
814c2653865SAlexander Duyck 	/* verify vf is in range */
815c2653865SAlexander Duyck 	if (vf_idx >= hw->iov.num_vfs)
816c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
817c2653865SAlexander Duyck 
818c2653865SAlexander Duyck 	/* determine vector offset and count */
819c2653865SAlexander Duyck 	vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
820c2653865SAlexander Duyck 	vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
821c2653865SAlexander Duyck 
822c2653865SAlexander Duyck 	/* search for first vector that is not masked */
823c2653865SAlexander Duyck 	for (i = vf_v_limit - 1; i > vf_v_idx; i--) {
824c2653865SAlexander Duyck 		if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
825c2653865SAlexander Duyck 			break;
826c2653865SAlexander Duyck 	}
827c2653865SAlexander Duyck 
828c2653865SAlexander Duyck 	/* reset linked list so it now includes our active vectors */
829c2653865SAlexander Duyck 	if (vf_idx == (hw->iov.num_vfs - 1))
830c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(0), i);
831c2653865SAlexander Duyck 	else
832c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), i);
833c2653865SAlexander Duyck 
834c2653865SAlexander Duyck 	return 0;
835c2653865SAlexander Duyck }
836c2653865SAlexander Duyck 
837c2653865SAlexander Duyck /**
838c2653865SAlexander Duyck  *  fm10k_iov_assign_default_mac_vlan_pf - Assign a MAC and VLAN to VF
839c2653865SAlexander Duyck  *  @hw: pointer to the HW structure
840c2653865SAlexander Duyck  *  @vf_info: pointer to VF information structure
841c2653865SAlexander Duyck  *
842c2653865SAlexander Duyck  *  Assign a MAC address and default VLAN to a VF and notify it of the update
843c2653865SAlexander Duyck  **/
844c2653865SAlexander Duyck static s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw,
845c2653865SAlexander Duyck 						struct fm10k_vf_info *vf_info)
846c2653865SAlexander Duyck {
847c2653865SAlexander Duyck 	u16 qmap_stride, queues_per_pool, vf_q_idx, timeout, qmap_idx, i;
848c2653865SAlexander Duyck 	u32 msg[4], txdctl, txqctl, tdbal = 0, tdbah = 0;
849c2653865SAlexander Duyck 	s32 err = 0;
850c2653865SAlexander Duyck 	u16 vf_idx, vf_vid;
851c2653865SAlexander Duyck 
852c2653865SAlexander Duyck 	/* verify vf is in range */
853c2653865SAlexander Duyck 	if (!vf_info || vf_info->vf_idx >= hw->iov.num_vfs)
854c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
855c2653865SAlexander Duyck 
856c2653865SAlexander Duyck 	/* determine qmap offsets and counts */
857c2653865SAlexander Duyck 	qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
858c2653865SAlexander Duyck 	queues_per_pool = fm10k_queues_per_pool(hw);
859c2653865SAlexander Duyck 
860c2653865SAlexander Duyck 	/* calculate starting index for queues */
861c2653865SAlexander Duyck 	vf_idx = vf_info->vf_idx;
862c2653865SAlexander Duyck 	vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
863c2653865SAlexander Duyck 	qmap_idx = qmap_stride * vf_idx;
864c2653865SAlexander Duyck 
865c2653865SAlexander Duyck 	/* MAP Tx queue back to 0 temporarily, and disable it */
866c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
867c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
868c2653865SAlexander Duyck 
869c2653865SAlexander Duyck 	/* determine correct default VLAN ID */
870c2653865SAlexander Duyck 	if (vf_info->pf_vid)
871c2653865SAlexander Duyck 		vf_vid = vf_info->pf_vid | FM10K_VLAN_CLEAR;
872c2653865SAlexander Duyck 	else
873c2653865SAlexander Duyck 		vf_vid = vf_info->sw_vid;
874c2653865SAlexander Duyck 
875c2653865SAlexander Duyck 	/* generate MAC_ADDR request */
876c2653865SAlexander Duyck 	fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
877c2653865SAlexander Duyck 	fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_DEFAULT_MAC,
878c2653865SAlexander Duyck 				    vf_info->mac, vf_vid);
879c2653865SAlexander Duyck 
880c2653865SAlexander Duyck 	/* load onto outgoing mailbox, ignore any errors on enqueue */
881c2653865SAlexander Duyck 	if (vf_info->mbx.ops.enqueue_tx)
882c2653865SAlexander Duyck 		vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
883c2653865SAlexander Duyck 
884c2653865SAlexander Duyck 	/* verify ring has disabled before modifying base address registers */
885c2653865SAlexander Duyck 	txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
886c2653865SAlexander Duyck 	for (timeout = 0; txdctl & FM10K_TXDCTL_ENABLE; timeout++) {
887c2653865SAlexander Duyck 		/* limit ourselves to a 1ms timeout */
888c2653865SAlexander Duyck 		if (timeout == 10) {
889c2653865SAlexander Duyck 			err = FM10K_ERR_DMA_PENDING;
890c2653865SAlexander Duyck 			goto err_out;
891c2653865SAlexander Duyck 		}
892c2653865SAlexander Duyck 
893c2653865SAlexander Duyck 		usleep_range(100, 200);
894c2653865SAlexander Duyck 		txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
895c2653865SAlexander Duyck 	}
896c2653865SAlexander Duyck 
897c2653865SAlexander Duyck 	/* Update base address registers to contain MAC address */
898c2653865SAlexander Duyck 	if (is_valid_ether_addr(vf_info->mac)) {
899c2653865SAlexander Duyck 		tdbal = (((u32)vf_info->mac[3]) << 24) |
900c2653865SAlexander Duyck 			(((u32)vf_info->mac[4]) << 16) |
901c2653865SAlexander Duyck 			(((u32)vf_info->mac[5]) << 8);
902c2653865SAlexander Duyck 
903c2653865SAlexander Duyck 		tdbah = (((u32)0xFF)	        << 24) |
904c2653865SAlexander Duyck 			(((u32)vf_info->mac[0]) << 16) |
905c2653865SAlexander Duyck 			(((u32)vf_info->mac[1]) << 8) |
906c2653865SAlexander Duyck 			((u32)vf_info->mac[2]);
907c2653865SAlexander Duyck 	}
908c2653865SAlexander Duyck 
909c2653865SAlexander Duyck 	/* Record the base address into queue 0 */
910c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx), tdbal);
911c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx), tdbah);
912c2653865SAlexander Duyck 
913c2653865SAlexander Duyck err_out:
914c2653865SAlexander Duyck 	/* configure Queue control register */
915c2653865SAlexander Duyck 	txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) &
916c2653865SAlexander Duyck 		 FM10K_TXQCTL_VID_MASK;
917c2653865SAlexander Duyck 	txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
918c2653865SAlexander Duyck 		  FM10K_TXQCTL_VF | vf_idx;
919c2653865SAlexander Duyck 
920c2653865SAlexander Duyck 	/* assign VID */
921c2653865SAlexander Duyck 	for (i = 0; i < queues_per_pool; i++)
922c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx + i), txqctl);
923c2653865SAlexander Duyck 
924c2653865SAlexander Duyck 	/* restore the queue back to VF ownership */
925c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
926c2653865SAlexander Duyck 	return err;
927c2653865SAlexander Duyck }
928c2653865SAlexander Duyck 
929c2653865SAlexander Duyck /**
930c2653865SAlexander Duyck  *  fm10k_iov_reset_resources_pf - Reassign queues and interrupts to a VF
931c2653865SAlexander Duyck  *  @hw: pointer to the HW structure
932c2653865SAlexander Duyck  *  @vf_info: pointer to VF information structure
933c2653865SAlexander Duyck  *
934c2653865SAlexander Duyck  *  Reassign the interrupts and queues to a VF following an FLR
935c2653865SAlexander Duyck  **/
936c2653865SAlexander Duyck static s32 fm10k_iov_reset_resources_pf(struct fm10k_hw *hw,
937c2653865SAlexander Duyck 					struct fm10k_vf_info *vf_info)
938c2653865SAlexander Duyck {
939c2653865SAlexander Duyck 	u16 qmap_stride, queues_per_pool, vf_q_idx, qmap_idx;
940c2653865SAlexander Duyck 	u32 tdbal = 0, tdbah = 0, txqctl, rxqctl;
941c2653865SAlexander Duyck 	u16 vf_v_idx, vf_v_limit, vf_vid;
942c2653865SAlexander Duyck 	u8 vf_idx = vf_info->vf_idx;
943c2653865SAlexander Duyck 	int i;
944c2653865SAlexander Duyck 
945c2653865SAlexander Duyck 	/* verify vf is in range */
946c2653865SAlexander Duyck 	if (vf_idx >= hw->iov.num_vfs)
947c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
948c2653865SAlexander Duyck 
949c2653865SAlexander Duyck 	/* clear event notification of VF FLR */
950c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_PFVFLREC(vf_idx / 32), 1 << (vf_idx % 32));
951c2653865SAlexander Duyck 
952c2653865SAlexander Duyck 	/* force timeout and then disconnect the mailbox */
953c2653865SAlexander Duyck 	vf_info->mbx.timeout = 0;
954c2653865SAlexander Duyck 	if (vf_info->mbx.ops.disconnect)
955c2653865SAlexander Duyck 		vf_info->mbx.ops.disconnect(hw, &vf_info->mbx);
956c2653865SAlexander Duyck 
957c2653865SAlexander Duyck 	/* determine vector offset and count */
958c2653865SAlexander Duyck 	vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
959c2653865SAlexander Duyck 	vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
960c2653865SAlexander Duyck 
961c2653865SAlexander Duyck 	/* determine qmap offsets and counts */
962c2653865SAlexander Duyck 	qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
963c2653865SAlexander Duyck 	queues_per_pool = fm10k_queues_per_pool(hw);
964c2653865SAlexander Duyck 	qmap_idx = qmap_stride * vf_idx;
965c2653865SAlexander Duyck 
966c2653865SAlexander Duyck 	/* make all the queues inaccessible to the VF */
967c2653865SAlexander Duyck 	for (i = qmap_idx; i < (qmap_idx + qmap_stride); i++) {
968c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TQMAP(i), 0);
969c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RQMAP(i), 0);
970c2653865SAlexander Duyck 	}
971c2653865SAlexander Duyck 
972c2653865SAlexander Duyck 	/* calculate starting index for queues */
973c2653865SAlexander Duyck 	vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
974c2653865SAlexander Duyck 
975c2653865SAlexander Duyck 	/* determine correct default VLAN ID */
976c2653865SAlexander Duyck 	if (vf_info->pf_vid)
977c2653865SAlexander Duyck 		vf_vid = vf_info->pf_vid;
978c2653865SAlexander Duyck 	else
979c2653865SAlexander Duyck 		vf_vid = vf_info->sw_vid;
980c2653865SAlexander Duyck 
981c2653865SAlexander Duyck 	/* configure Queue control register */
982c2653865SAlexander Duyck 	txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) |
983c2653865SAlexander Duyck 		 (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
984c2653865SAlexander Duyck 		 FM10K_TXQCTL_VF | vf_idx;
985c2653865SAlexander Duyck 	rxqctl = FM10K_RXQCTL_VF | (vf_idx << FM10K_RXQCTL_VF_SHIFT);
986c2653865SAlexander Duyck 
987c2653865SAlexander Duyck 	/* stop further DMA and reset queue ownership back to VF */
988c2653865SAlexander Duyck 	for (i = vf_q_idx; i < (queues_per_pool + vf_q_idx); i++) {
989c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
990c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
991c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RXDCTL(i),
992c2653865SAlexander Duyck 				FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
993c2653865SAlexander Duyck 				FM10K_RXDCTL_DROP_ON_EMPTY);
994c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RXQCTL(i), rxqctl);
995c2653865SAlexander Duyck 	}
996c2653865SAlexander Duyck 
997c2653865SAlexander Duyck 	/* reset TC with -1 credits and no quanta to prevent transmit */
998c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), 0);
999c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), 0);
1000c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx),
1001c2653865SAlexander Duyck 			FM10K_TC_CREDIT_CREDIT_MASK);
1002c2653865SAlexander Duyck 
1003c2653865SAlexander Duyck 	/* update our first entry in the table based on previous VF */
1004c2653865SAlexander Duyck 	if (!vf_idx)
1005c2653865SAlexander Duyck 		hw->mac.ops.update_int_moderator(hw);
1006c2653865SAlexander Duyck 	else
1007c2653865SAlexander Duyck 		hw->iov.ops.assign_int_moderator(hw, vf_idx - 1);
1008c2653865SAlexander Duyck 
1009c2653865SAlexander Duyck 	/* reset linked list so it now includes our active vectors */
1010c2653865SAlexander Duyck 	if (vf_idx == (hw->iov.num_vfs - 1))
1011c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(0), vf_v_idx);
1012c2653865SAlexander Duyck 	else
1013c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), vf_v_idx);
1014c2653865SAlexander Duyck 
1015c2653865SAlexander Duyck 	/* link remaining vectors so that next points to previous */
1016c2653865SAlexander Duyck 	for (vf_v_idx++; vf_v_idx < vf_v_limit; vf_v_idx++)
1017c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_idx), vf_v_idx - 1);
1018c2653865SAlexander Duyck 
1019c2653865SAlexander Duyck 	/* zero out MBMEM, VLAN_TABLE, RETA, RSSRK, and MRQC registers */
1020c2653865SAlexander Duyck 	for (i = FM10K_VFMBMEM_LEN; i--;)
1021c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_MBMEM_VF(vf_idx, i), 0);
1022c2653865SAlexander Duyck 	for (i = FM10K_VLAN_TABLE_SIZE; i--;)
1023c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_VLAN_TABLE(vf_info->vsi, i), 0);
1024c2653865SAlexander Duyck 	for (i = FM10K_RETA_SIZE; i--;)
1025c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RETA(vf_info->vsi, i), 0);
1026c2653865SAlexander Duyck 	for (i = FM10K_RSSRK_SIZE; i--;)
1027c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RSSRK(vf_info->vsi, i), 0);
1028c2653865SAlexander Duyck 	fm10k_write_reg(hw, FM10K_MRQC(vf_info->vsi), 0);
1029c2653865SAlexander Duyck 
1030c2653865SAlexander Duyck 	/* Update base address registers to contain MAC address */
1031c2653865SAlexander Duyck 	if (is_valid_ether_addr(vf_info->mac)) {
1032c2653865SAlexander Duyck 		tdbal = (((u32)vf_info->mac[3]) << 24) |
1033c2653865SAlexander Duyck 			(((u32)vf_info->mac[4]) << 16) |
1034c2653865SAlexander Duyck 			(((u32)vf_info->mac[5]) << 8);
1035c2653865SAlexander Duyck 		tdbah = (((u32)0xFF)	   << 24) |
1036c2653865SAlexander Duyck 			(((u32)vf_info->mac[0]) << 16) |
1037c2653865SAlexander Duyck 			(((u32)vf_info->mac[1]) << 8) |
1038c2653865SAlexander Duyck 			((u32)vf_info->mac[2]);
1039c2653865SAlexander Duyck 	}
1040c2653865SAlexander Duyck 
1041c2653865SAlexander Duyck 	/* map queue pairs back to VF from last to first */
1042c2653865SAlexander Duyck 	for (i = queues_per_pool; i--;) {
1043c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx + i), tdbal);
1044c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx + i), tdbah);
1045c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx + i);
1046c2653865SAlexander Duyck 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx + i);
1047c2653865SAlexander Duyck 	}
1048c2653865SAlexander Duyck 
1049fba341d5SJacob Keller 	/* repeat the first ring for all the remaining VF rings */
1050fba341d5SJacob Keller 	for (i = queues_per_pool; i < qmap_stride; i++) {
1051fba341d5SJacob Keller 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx);
1052fba341d5SJacob Keller 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx);
1053fba341d5SJacob Keller 	}
1054fba341d5SJacob Keller 
1055c2653865SAlexander Duyck 	return 0;
1056c2653865SAlexander Duyck }
1057c2653865SAlexander Duyck 
1058c2653865SAlexander Duyck /**
1059c2653865SAlexander Duyck  *  fm10k_iov_set_lport_pf - Assign and enable a logical port for a given VF
1060c2653865SAlexander Duyck  *  @hw: pointer to hardware structure
1061c2653865SAlexander Duyck  *  @vf_info: pointer to VF information structure
1062c2653865SAlexander Duyck  *  @lport_idx: Logical port offset from the hardware glort
1063c2653865SAlexander Duyck  *  @flags: Set of capability flags to extend port beyond basic functionality
1064c2653865SAlexander Duyck  *
1065c2653865SAlexander Duyck  *  This function allows enabling a VF port by assigning it a GLORT and
1066c2653865SAlexander Duyck  *  setting the flags so that it can enable an Rx mode.
1067c2653865SAlexander Duyck  **/
1068c2653865SAlexander Duyck static s32 fm10k_iov_set_lport_pf(struct fm10k_hw *hw,
1069c2653865SAlexander Duyck 				  struct fm10k_vf_info *vf_info,
1070c2653865SAlexander Duyck 				  u16 lport_idx, u8 flags)
1071c2653865SAlexander Duyck {
1072c2653865SAlexander Duyck 	u16 glort = (hw->mac.dglort_map + lport_idx) & FM10K_DGLORTMAP_NONE;
1073c2653865SAlexander Duyck 
1074c2653865SAlexander Duyck 	/* if glort is not valid return error */
1075c2653865SAlexander Duyck 	if (!fm10k_glort_valid_pf(hw, glort))
1076c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
1077c2653865SAlexander Duyck 
1078c2653865SAlexander Duyck 	vf_info->vf_flags = flags | FM10K_VF_FLAG_NONE_CAPABLE;
1079c2653865SAlexander Duyck 	vf_info->glort = glort;
1080c2653865SAlexander Duyck 
1081c2653865SAlexander Duyck 	return 0;
1082c2653865SAlexander Duyck }
1083c2653865SAlexander Duyck 
1084c2653865SAlexander Duyck /**
1085c2653865SAlexander Duyck  *  fm10k_iov_reset_lport_pf - Disable a logical port for a given VF
1086c2653865SAlexander Duyck  *  @hw: pointer to hardware structure
1087c2653865SAlexander Duyck  *  @vf_info: pointer to VF information structure
1088c2653865SAlexander Duyck  *
1089c2653865SAlexander Duyck  *  This function disables a VF port by stripping it of a GLORT and
1090c2653865SAlexander Duyck  *  setting the flags so that it cannot enable any Rx mode.
1091c2653865SAlexander Duyck  **/
1092c2653865SAlexander Duyck static void fm10k_iov_reset_lport_pf(struct fm10k_hw *hw,
1093c2653865SAlexander Duyck 				     struct fm10k_vf_info *vf_info)
1094c2653865SAlexander Duyck {
1095c2653865SAlexander Duyck 	u32 msg[1];
1096c2653865SAlexander Duyck 
1097c2653865SAlexander Duyck 	/* need to disable the port if it is already enabled */
1098c2653865SAlexander Duyck 	if (FM10K_VF_FLAG_ENABLED(vf_info)) {
1099c2653865SAlexander Duyck 		/* notify switch that this port has been disabled */
1100c2653865SAlexander Duyck 		fm10k_update_lport_state_pf(hw, vf_info->glort, 1, false);
1101c2653865SAlexander Duyck 
1102c2653865SAlexander Duyck 		/* generate port state response to notify VF it is not ready */
1103c2653865SAlexander Duyck 		fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1104c2653865SAlexander Duyck 		vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
1105c2653865SAlexander Duyck 	}
1106c2653865SAlexander Duyck 
1107c2653865SAlexander Duyck 	/* clear flags and glort if it exists */
1108c2653865SAlexander Duyck 	vf_info->vf_flags = 0;
1109c2653865SAlexander Duyck 	vf_info->glort = 0;
1110c2653865SAlexander Duyck }
1111c2653865SAlexander Duyck 
1112c2653865SAlexander Duyck /**
1113c2653865SAlexander Duyck  *  fm10k_iov_update_stats_pf - Updates hardware related statistics for VFs
1114c2653865SAlexander Duyck  *  @hw: pointer to hardware structure
1115c2653865SAlexander Duyck  *  @q: stats for all queues of a VF
1116c2653865SAlexander Duyck  *  @vf_idx: index of VF
1117c2653865SAlexander Duyck  *
1118c2653865SAlexander Duyck  *  This function collects queue stats for VFs.
1119c2653865SAlexander Duyck  **/
1120c2653865SAlexander Duyck static void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
1121c2653865SAlexander Duyck 				      struct fm10k_hw_stats_q *q,
1122c2653865SAlexander Duyck 				      u16 vf_idx)
1123c2653865SAlexander Duyck {
1124c2653865SAlexander Duyck 	u32 idx, qpp;
1125c2653865SAlexander Duyck 
1126c2653865SAlexander Duyck 	/* get stats for all of the queues */
1127c2653865SAlexander Duyck 	qpp = fm10k_queues_per_pool(hw);
1128c2653865SAlexander Duyck 	idx = fm10k_vf_queue_index(hw, vf_idx);
1129c2653865SAlexander Duyck 	fm10k_update_hw_stats_q(hw, q, idx, qpp);
1130c2653865SAlexander Duyck }
1131c2653865SAlexander Duyck 
11325f226ddbSAlexander Duyck static s32 fm10k_iov_report_timestamp_pf(struct fm10k_hw *hw,
11335f226ddbSAlexander Duyck 					 struct fm10k_vf_info *vf_info,
11345f226ddbSAlexander Duyck 					 u64 timestamp)
11355f226ddbSAlexander Duyck {
11365f226ddbSAlexander Duyck 	u32 msg[4];
11375f226ddbSAlexander Duyck 
11385f226ddbSAlexander Duyck 	/* generate port state response to notify VF it is not ready */
11395f226ddbSAlexander Duyck 	fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_1588);
11405f226ddbSAlexander Duyck 	fm10k_tlv_attr_put_u64(msg, FM10K_1588_MSG_TIMESTAMP, timestamp);
11415f226ddbSAlexander Duyck 
11425f226ddbSAlexander Duyck 	return vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
11435f226ddbSAlexander Duyck }
11445f226ddbSAlexander Duyck 
1145c2653865SAlexander Duyck /**
1146c2653865SAlexander Duyck  *  fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF
1147c2653865SAlexander Duyck  *  @hw: Pointer to hardware structure
1148c2653865SAlexander Duyck  *  @results: Pointer array to message, results[0] is pointer to message
1149c2653865SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1150c2653865SAlexander Duyck  *
1151c2653865SAlexander Duyck  *  This function is a default handler for MSI-X requests from the VF.  The
1152c2653865SAlexander Duyck  *  assumption is that in this case it is acceptable to just directly
1153eca32047SMatthew Vick  *  hand off the message from the VF to the underlying shared code.
1154c2653865SAlexander Duyck  **/
1155c2653865SAlexander Duyck s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 **results,
1156c2653865SAlexander Duyck 			  struct fm10k_mbx_info *mbx)
1157c2653865SAlexander Duyck {
1158c2653865SAlexander Duyck 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1159c2653865SAlexander Duyck 	u8 vf_idx = vf_info->vf_idx;
1160c2653865SAlexander Duyck 
1161c2653865SAlexander Duyck 	return hw->iov.ops.assign_int_moderator(hw, vf_idx);
1162c2653865SAlexander Duyck }
1163c2653865SAlexander Duyck 
1164c2653865SAlexander Duyck /**
1165c2653865SAlexander Duyck  *  fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
1166c2653865SAlexander Duyck  *  @hw: Pointer to hardware structure
1167c2653865SAlexander Duyck  *  @results: Pointer array to message, results[0] is pointer to message
1168c2653865SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1169c2653865SAlexander Duyck  *
1170c2653865SAlexander Duyck  *  This function is a default handler for MAC/VLAN requests from the VF.
1171c2653865SAlexander Duyck  *  The assumption is that in this case it is acceptable to just directly
1172eca32047SMatthew Vick  *  hand off the message from the VF to the underlying shared code.
1173c2653865SAlexander Duyck  **/
1174c2653865SAlexander Duyck s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
1175c2653865SAlexander Duyck 			      struct fm10k_mbx_info *mbx)
1176c2653865SAlexander Duyck {
1177c2653865SAlexander Duyck 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1178c2653865SAlexander Duyck 	int err = 0;
1179c2653865SAlexander Duyck 	u8 mac[ETH_ALEN];
1180c2653865SAlexander Duyck 	u32 *result;
1181c2653865SAlexander Duyck 	u16 vlan;
1182c2653865SAlexander Duyck 	u32 vid;
1183c2653865SAlexander Duyck 
1184c2653865SAlexander Duyck 	/* we shouldn't be updating rules on a disabled interface */
1185c2653865SAlexander Duyck 	if (!FM10K_VF_FLAG_ENABLED(vf_info))
1186c2653865SAlexander Duyck 		err = FM10K_ERR_PARAM;
1187c2653865SAlexander Duyck 
1188c2653865SAlexander Duyck 	if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) {
1189c2653865SAlexander Duyck 		result = results[FM10K_MAC_VLAN_MSG_VLAN];
1190c2653865SAlexander Duyck 
1191c2653865SAlexander Duyck 		/* record VLAN id requested */
1192c2653865SAlexander Duyck 		err = fm10k_tlv_attr_get_u32(result, &vid);
1193c2653865SAlexander Duyck 		if (err)
1194c2653865SAlexander Duyck 			return err;
1195c2653865SAlexander Duyck 
1196c2653865SAlexander Duyck 		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1197c2653865SAlexander Duyck 		if (!vid || (vid == FM10K_VLAN_CLEAR)) {
1198c2653865SAlexander Duyck 			if (vf_info->pf_vid)
1199c2653865SAlexander Duyck 				vid |= vf_info->pf_vid;
1200c2653865SAlexander Duyck 			else
1201c2653865SAlexander Duyck 				vid |= vf_info->sw_vid;
1202c2653865SAlexander Duyck 		} else if (vid != vf_info->pf_vid) {
1203c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1204c2653865SAlexander Duyck 		}
1205c2653865SAlexander Duyck 
1206c2653865SAlexander Duyck 		/* update VSI info for VF in regards to VLAN table */
1207c2653865SAlexander Duyck 		err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi,
1208c2653865SAlexander Duyck 					      !(vid & FM10K_VLAN_CLEAR));
1209c2653865SAlexander Duyck 	}
1210c2653865SAlexander Duyck 
1211c2653865SAlexander Duyck 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
1212c2653865SAlexander Duyck 		result = results[FM10K_MAC_VLAN_MSG_MAC];
1213c2653865SAlexander Duyck 
1214c2653865SAlexander Duyck 		/* record unicast MAC address requested */
1215c2653865SAlexander Duyck 		err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1216c2653865SAlexander Duyck 		if (err)
1217c2653865SAlexander Duyck 			return err;
1218c2653865SAlexander Duyck 
1219c2653865SAlexander Duyck 		/* block attempts to set MAC for a locked device */
1220c2653865SAlexander Duyck 		if (is_valid_ether_addr(vf_info->mac) &&
1221c2653865SAlexander Duyck 		    memcmp(mac, vf_info->mac, ETH_ALEN))
1222c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1223c2653865SAlexander Duyck 
1224c2653865SAlexander Duyck 		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1225c2653865SAlexander Duyck 		if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
1226c2653865SAlexander Duyck 			if (vf_info->pf_vid)
1227c2653865SAlexander Duyck 				vlan |= vf_info->pf_vid;
1228c2653865SAlexander Duyck 			else
1229c2653865SAlexander Duyck 				vlan |= vf_info->sw_vid;
1230c2653865SAlexander Duyck 		} else if (vf_info->pf_vid) {
1231c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1232c2653865SAlexander Duyck 		}
1233c2653865SAlexander Duyck 
1234c2653865SAlexander Duyck 		/* notify switch of request for new unicast address */
1235c2653865SAlexander Duyck 		err = hw->mac.ops.update_uc_addr(hw, vf_info->glort, mac, vlan,
1236c2653865SAlexander Duyck 						 !(vlan & FM10K_VLAN_CLEAR), 0);
1237c2653865SAlexander Duyck 	}
1238c2653865SAlexander Duyck 
1239c2653865SAlexander Duyck 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
1240c2653865SAlexander Duyck 		result = results[FM10K_MAC_VLAN_MSG_MULTICAST];
1241c2653865SAlexander Duyck 
1242c2653865SAlexander Duyck 		/* record multicast MAC address requested */
1243c2653865SAlexander Duyck 		err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1244c2653865SAlexander Duyck 		if (err)
1245c2653865SAlexander Duyck 			return err;
1246c2653865SAlexander Duyck 
1247c2653865SAlexander Duyck 		/* verify that the VF is allowed to request multicast */
1248c2653865SAlexander Duyck 		if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
1249c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1250c2653865SAlexander Duyck 
1251c2653865SAlexander Duyck 		/* if VLAN ID is 0, set the default VLAN ID instead of 0 */
1252c2653865SAlexander Duyck 		if (!vlan || (vlan == FM10K_VLAN_CLEAR)) {
1253c2653865SAlexander Duyck 			if (vf_info->pf_vid)
1254c2653865SAlexander Duyck 				vlan |= vf_info->pf_vid;
1255c2653865SAlexander Duyck 			else
1256c2653865SAlexander Duyck 				vlan |= vf_info->sw_vid;
1257c2653865SAlexander Duyck 		} else if (vf_info->pf_vid) {
1258c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1259c2653865SAlexander Duyck 		}
1260c2653865SAlexander Duyck 
1261c2653865SAlexander Duyck 		/* notify switch of request for new multicast address */
1262b32d15b9SJeff Kirsher 		err = hw->mac.ops.update_mc_addr(hw, vf_info->glort, mac, vlan,
1263b32d15b9SJeff Kirsher 						 !(vlan & FM10K_VLAN_CLEAR));
1264c2653865SAlexander Duyck 	}
1265c2653865SAlexander Duyck 
1266c2653865SAlexander Duyck 	return err;
1267c2653865SAlexander Duyck }
1268c2653865SAlexander Duyck 
1269c2653865SAlexander Duyck /**
1270c2653865SAlexander Duyck  *  fm10k_iov_supported_xcast_mode_pf - Determine best match for xcast mode
1271c2653865SAlexander Duyck  *  @vf_info: VF info structure containing capability flags
1272c2653865SAlexander Duyck  *  @mode: Requested xcast mode
1273c2653865SAlexander Duyck  *
1274c2653865SAlexander Duyck  *  This function outputs the mode that most closely matches the requested
1275c2653865SAlexander Duyck  *  mode.  If not modes match it will request we disable the port
1276c2653865SAlexander Duyck  **/
1277c2653865SAlexander Duyck static u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info,
1278c2653865SAlexander Duyck 					    u8 mode)
1279c2653865SAlexander Duyck {
1280c2653865SAlexander Duyck 	u8 vf_flags = vf_info->vf_flags;
1281c2653865SAlexander Duyck 
1282c2653865SAlexander Duyck 	/* match up mode to capabilities as best as possible */
1283c2653865SAlexander Duyck 	switch (mode) {
1284c2653865SAlexander Duyck 	case FM10K_XCAST_MODE_PROMISC:
1285c2653865SAlexander Duyck 		if (vf_flags & FM10K_VF_FLAG_PROMISC_CAPABLE)
1286c2653865SAlexander Duyck 			return FM10K_XCAST_MODE_PROMISC;
1287c2653865SAlexander Duyck 		/* fallthough */
1288c2653865SAlexander Duyck 	case FM10K_XCAST_MODE_ALLMULTI:
1289c2653865SAlexander Duyck 		if (vf_flags & FM10K_VF_FLAG_ALLMULTI_CAPABLE)
1290c2653865SAlexander Duyck 			return FM10K_XCAST_MODE_ALLMULTI;
1291c2653865SAlexander Duyck 		/* fallthough */
1292c2653865SAlexander Duyck 	case FM10K_XCAST_MODE_MULTI:
1293c2653865SAlexander Duyck 		if (vf_flags & FM10K_VF_FLAG_MULTI_CAPABLE)
1294c2653865SAlexander Duyck 			return FM10K_XCAST_MODE_MULTI;
1295c2653865SAlexander Duyck 		/* fallthough */
1296c2653865SAlexander Duyck 	case FM10K_XCAST_MODE_NONE:
1297c2653865SAlexander Duyck 		if (vf_flags & FM10K_VF_FLAG_NONE_CAPABLE)
1298c2653865SAlexander Duyck 			return FM10K_XCAST_MODE_NONE;
1299c2653865SAlexander Duyck 		/* fallthough */
1300c2653865SAlexander Duyck 	default:
1301c2653865SAlexander Duyck 		break;
1302c2653865SAlexander Duyck 	}
1303c2653865SAlexander Duyck 
1304c2653865SAlexander Duyck 	/* disable interface as it should not be able to request any */
1305c2653865SAlexander Duyck 	return FM10K_XCAST_MODE_DISABLE;
1306c2653865SAlexander Duyck }
1307c2653865SAlexander Duyck 
1308c2653865SAlexander Duyck /**
1309c2653865SAlexander Duyck  *  fm10k_iov_msg_lport_state_pf - Message handler for port state requests
1310c2653865SAlexander Duyck  *  @hw: Pointer to hardware structure
1311c2653865SAlexander Duyck  *  @results: Pointer array to message, results[0] is pointer to message
1312c2653865SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1313c2653865SAlexander Duyck  *
1314c2653865SAlexander Duyck  *  This function is a default handler for port state requests.  The port
1315c2653865SAlexander Duyck  *  state requests for now are basic and consist of enabling or disabling
1316c2653865SAlexander Duyck  *  the port.
1317c2653865SAlexander Duyck  **/
1318c2653865SAlexander Duyck s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
1319c2653865SAlexander Duyck 				 struct fm10k_mbx_info *mbx)
1320c2653865SAlexander Duyck {
1321c2653865SAlexander Duyck 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1322c2653865SAlexander Duyck 	u32 *result;
1323c2653865SAlexander Duyck 	s32 err = 0;
1324c2653865SAlexander Duyck 	u32 msg[2];
1325c2653865SAlexander Duyck 	u8 mode = 0;
1326c2653865SAlexander Duyck 
1327c2653865SAlexander Duyck 	/* verify VF is allowed to enable even minimal mode */
1328c2653865SAlexander Duyck 	if (!(vf_info->vf_flags & FM10K_VF_FLAG_NONE_CAPABLE))
1329c2653865SAlexander Duyck 		return FM10K_ERR_PARAM;
1330c2653865SAlexander Duyck 
1331c2653865SAlexander Duyck 	if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) {
1332c2653865SAlexander Duyck 		result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
1333c2653865SAlexander Duyck 
1334c2653865SAlexander Duyck 		/* XCAST mode update requested */
1335c2653865SAlexander Duyck 		err = fm10k_tlv_attr_get_u8(result, &mode);
1336c2653865SAlexander Duyck 		if (err)
1337c2653865SAlexander Duyck 			return FM10K_ERR_PARAM;
1338c2653865SAlexander Duyck 
1339c2653865SAlexander Duyck 		/* prep for possible demotion depending on capabilities */
1340c2653865SAlexander Duyck 		mode = fm10k_iov_supported_xcast_mode_pf(vf_info, mode);
1341c2653865SAlexander Duyck 
1342c2653865SAlexander Duyck 		/* if mode is not currently enabled, enable it */
1343c2653865SAlexander Duyck 		if (!(FM10K_VF_FLAG_ENABLED(vf_info) & (1 << mode)))
1344c2653865SAlexander Duyck 			fm10k_update_xcast_mode_pf(hw, vf_info->glort, mode);
1345c2653865SAlexander Duyck 
1346c2653865SAlexander Duyck 		/* swap mode back to a bit flag */
1347c2653865SAlexander Duyck 		mode = FM10K_VF_FLAG_SET_MODE(mode);
1348c2653865SAlexander Duyck 	} else if (!results[FM10K_LPORT_STATE_MSG_DISABLE]) {
1349c2653865SAlexander Duyck 		/* need to disable the port if it is already enabled */
1350c2653865SAlexander Duyck 		if (FM10K_VF_FLAG_ENABLED(vf_info))
1351c2653865SAlexander Duyck 			err = fm10k_update_lport_state_pf(hw, vf_info->glort,
1352c2653865SAlexander Duyck 							  1, false);
1353c2653865SAlexander Duyck 
1354c2653865SAlexander Duyck 		/* when enabling the port we should reset the rate limiters */
1355c2653865SAlexander Duyck 		hw->iov.ops.configure_tc(hw, vf_info->vf_idx, vf_info->rate);
1356c2653865SAlexander Duyck 
1357c2653865SAlexander Duyck 		/* set mode for minimal functionality */
1358c2653865SAlexander Duyck 		mode = FM10K_VF_FLAG_SET_MODE_NONE;
1359c2653865SAlexander Duyck 
1360c2653865SAlexander Duyck 		/* generate port state response to notify VF it is ready */
1361c2653865SAlexander Duyck 		fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1362c2653865SAlexander Duyck 		fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_READY);
1363c2653865SAlexander Duyck 		mbx->ops.enqueue_tx(hw, mbx, msg);
1364c2653865SAlexander Duyck 	}
1365c2653865SAlexander Duyck 
1366c2653865SAlexander Duyck 	/* if enable state toggled note the update */
1367c2653865SAlexander Duyck 	if (!err && (!FM10K_VF_FLAG_ENABLED(vf_info) != !mode))
1368c2653865SAlexander Duyck 		err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1,
1369c2653865SAlexander Duyck 						  !!mode);
1370c2653865SAlexander Duyck 
1371c2653865SAlexander Duyck 	/* if state change succeeded, then update our stored state */
1372c2653865SAlexander Duyck 	mode |= FM10K_VF_FLAG_CAPABLE(vf_info);
1373c2653865SAlexander Duyck 	if (!err)
1374c2653865SAlexander Duyck 		vf_info->vf_flags = mode;
1375c2653865SAlexander Duyck 
1376c2653865SAlexander Duyck 	return err;
1377c2653865SAlexander Duyck }
1378c2653865SAlexander Duyck 
1379c2653865SAlexander Duyck const struct fm10k_msg_data fm10k_iov_msg_data_pf[] = {
1380c2653865SAlexander Duyck 	FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
1381c2653865SAlexander Duyck 	FM10K_VF_MSG_MSIX_HANDLER(fm10k_iov_msg_msix_pf),
1382c2653865SAlexander Duyck 	FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_iov_msg_mac_vlan_pf),
1383c2653865SAlexander Duyck 	FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_iov_msg_lport_state_pf),
1384c2653865SAlexander Duyck 	FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1385c2653865SAlexander Duyck };
1386c2653865SAlexander Duyck 
1387401b5383SAlexander Duyck /**
1388b6fec18fSAlexander Duyck  *  fm10k_update_stats_hw_pf - Updates hardware related statistics of PF
1389b6fec18fSAlexander Duyck  *  @hw: pointer to hardware structure
1390b6fec18fSAlexander Duyck  *  @stats: pointer to the stats structure to update
1391b6fec18fSAlexander Duyck  *
1392b6fec18fSAlexander Duyck  *  This function collects and aggregates global and per queue hardware
1393b6fec18fSAlexander Duyck  *  statistics.
1394b6fec18fSAlexander Duyck  **/
1395b6fec18fSAlexander Duyck static void fm10k_update_hw_stats_pf(struct fm10k_hw *hw,
1396b6fec18fSAlexander Duyck 				     struct fm10k_hw_stats *stats)
1397b6fec18fSAlexander Duyck {
1398b6fec18fSAlexander Duyck 	u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop;
1399b6fec18fSAlexander Duyck 	u32 id, id_prev;
1400b6fec18fSAlexander Duyck 
1401b6fec18fSAlexander Duyck 	/* Use Tx queue 0 as a canary to detect a reset */
1402b6fec18fSAlexander Duyck 	id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1403b6fec18fSAlexander Duyck 
1404b6fec18fSAlexander Duyck 	/* Read Global Statistics */
1405b6fec18fSAlexander Duyck 	do {
1406b6fec18fSAlexander Duyck 		timeout = fm10k_read_hw_stats_32b(hw, FM10K_STATS_TIMEOUT,
1407b6fec18fSAlexander Duyck 						  &stats->timeout);
1408b6fec18fSAlexander Duyck 		ur = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UR, &stats->ur);
1409b6fec18fSAlexander Duyck 		ca = fm10k_read_hw_stats_32b(hw, FM10K_STATS_CA, &stats->ca);
1410b6fec18fSAlexander Duyck 		um = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UM, &stats->um);
1411b6fec18fSAlexander Duyck 		xec = fm10k_read_hw_stats_32b(hw, FM10K_STATS_XEC, &stats->xec);
1412b6fec18fSAlexander Duyck 		vlan_drop = fm10k_read_hw_stats_32b(hw, FM10K_STATS_VLAN_DROP,
1413b6fec18fSAlexander Duyck 						    &stats->vlan_drop);
1414b6fec18fSAlexander Duyck 		loopback_drop = fm10k_read_hw_stats_32b(hw,
1415b6fec18fSAlexander Duyck 							FM10K_STATS_LOOPBACK_DROP,
1416b6fec18fSAlexander Duyck 							&stats->loopback_drop);
1417b6fec18fSAlexander Duyck 		nodesc_drop = fm10k_read_hw_stats_32b(hw,
1418b6fec18fSAlexander Duyck 						      FM10K_STATS_NODESC_DROP,
1419b6fec18fSAlexander Duyck 						      &stats->nodesc_drop);
1420b6fec18fSAlexander Duyck 
1421b6fec18fSAlexander Duyck 		/* if value has not changed then we have consistent data */
1422b6fec18fSAlexander Duyck 		id_prev = id;
1423b6fec18fSAlexander Duyck 		id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1424b6fec18fSAlexander Duyck 	} while ((id ^ id_prev) & FM10K_TXQCTL_ID_MASK);
1425b6fec18fSAlexander Duyck 
1426b6fec18fSAlexander Duyck 	/* drop non-ID bits and set VALID ID bit */
1427b6fec18fSAlexander Duyck 	id &= FM10K_TXQCTL_ID_MASK;
1428b6fec18fSAlexander Duyck 	id |= FM10K_STAT_VALID;
1429b6fec18fSAlexander Duyck 
1430b6fec18fSAlexander Duyck 	/* Update Global Statistics */
1431b6fec18fSAlexander Duyck 	if (stats->stats_idx == id) {
1432b6fec18fSAlexander Duyck 		stats->timeout.count += timeout;
1433b6fec18fSAlexander Duyck 		stats->ur.count += ur;
1434b6fec18fSAlexander Duyck 		stats->ca.count += ca;
1435b6fec18fSAlexander Duyck 		stats->um.count += um;
1436b6fec18fSAlexander Duyck 		stats->xec.count += xec;
1437b6fec18fSAlexander Duyck 		stats->vlan_drop.count += vlan_drop;
1438b6fec18fSAlexander Duyck 		stats->loopback_drop.count += loopback_drop;
1439b6fec18fSAlexander Duyck 		stats->nodesc_drop.count += nodesc_drop;
1440b6fec18fSAlexander Duyck 	}
1441b6fec18fSAlexander Duyck 
1442b6fec18fSAlexander Duyck 	/* Update bases and record current PF id */
1443b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->timeout, timeout);
1444b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->ur, ur);
1445b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->ca, ca);
1446b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->um, um);
1447b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->xec, xec);
1448b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->vlan_drop, vlan_drop);
1449b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->loopback_drop, loopback_drop);
1450b6fec18fSAlexander Duyck 	fm10k_update_hw_base_32b(&stats->nodesc_drop, nodesc_drop);
1451b6fec18fSAlexander Duyck 	stats->stats_idx = id;
1452b6fec18fSAlexander Duyck 
1453b6fec18fSAlexander Duyck 	/* Update Queue Statistics */
1454b6fec18fSAlexander Duyck 	fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
1455b6fec18fSAlexander Duyck }
1456b6fec18fSAlexander Duyck 
1457b6fec18fSAlexander Duyck /**
1458b6fec18fSAlexander Duyck  *  fm10k_rebind_hw_stats_pf - Resets base for hardware statistics of PF
1459b6fec18fSAlexander Duyck  *  @hw: pointer to hardware structure
1460b6fec18fSAlexander Duyck  *  @stats: pointer to the stats structure to update
1461b6fec18fSAlexander Duyck  *
1462b6fec18fSAlexander Duyck  *  This function resets the base for global and per queue hardware
1463b6fec18fSAlexander Duyck  *  statistics.
1464b6fec18fSAlexander Duyck  **/
1465b6fec18fSAlexander Duyck static void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw,
1466b6fec18fSAlexander Duyck 				     struct fm10k_hw_stats *stats)
1467b6fec18fSAlexander Duyck {
1468b6fec18fSAlexander Duyck 	/* Unbind Global Statistics */
1469b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->timeout);
1470b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->ur);
1471b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->ca);
1472b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->um);
1473b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->xec);
1474b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->vlan_drop);
1475b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->loopback_drop);
1476b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_32b(&stats->nodesc_drop);
1477b6fec18fSAlexander Duyck 
1478b6fec18fSAlexander Duyck 	/* Unbind Queue Statistics */
1479b6fec18fSAlexander Duyck 	fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
1480b6fec18fSAlexander Duyck 
1481b6fec18fSAlexander Duyck 	/* Reinitialize bases for all stats */
1482b6fec18fSAlexander Duyck 	fm10k_update_hw_stats_pf(hw, stats);
1483b6fec18fSAlexander Duyck }
1484b6fec18fSAlexander Duyck 
1485b6fec18fSAlexander Duyck /**
1486401b5383SAlexander Duyck  *  fm10k_set_dma_mask_pf - Configures PhyAddrSpace to limit DMA to system
1487401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
1488401b5383SAlexander Duyck  *  @dma_mask: 64 bit DMA mask required for platform
1489401b5383SAlexander Duyck  *
1490401b5383SAlexander Duyck  *  This function sets the PHYADDR.PhyAddrSpace bits for the endpoint in order
1491401b5383SAlexander Duyck  *  to limit the access to memory beyond what is physically in the system.
1492401b5383SAlexander Duyck  **/
1493401b5383SAlexander Duyck static void fm10k_set_dma_mask_pf(struct fm10k_hw *hw, u64 dma_mask)
1494401b5383SAlexander Duyck {
1495401b5383SAlexander Duyck 	/* we need to write the upper 32 bits of DMA mask to PhyAddrSpace */
1496401b5383SAlexander Duyck 	u32 phyaddr = (u32)(dma_mask >> 32);
1497401b5383SAlexander Duyck 
1498401b5383SAlexander Duyck 	fm10k_write_reg(hw, FM10K_PHYADDR, phyaddr);
1499401b5383SAlexander Duyck }
1500401b5383SAlexander Duyck 
1501401b5383SAlexander Duyck /**
1502b6fec18fSAlexander Duyck  *  fm10k_get_fault_pf - Record a fault in one of the interface units
1503b6fec18fSAlexander Duyck  *  @hw: pointer to hardware structure
1504b6fec18fSAlexander Duyck  *  @type: pointer to fault type register offset
1505b6fec18fSAlexander Duyck  *  @fault: pointer to memory location to record the fault
1506b6fec18fSAlexander Duyck  *
1507b6fec18fSAlexander Duyck  *  Record the fault register contents to the fault data structure and
1508b6fec18fSAlexander Duyck  *  clear the entry from the register.
1509b6fec18fSAlexander Duyck  *
1510b6fec18fSAlexander Duyck  *  Returns ERR_PARAM if invalid register is specified or no error is present.
1511b6fec18fSAlexander Duyck  **/
1512b6fec18fSAlexander Duyck static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
1513b6fec18fSAlexander Duyck 			      struct fm10k_fault *fault)
1514b6fec18fSAlexander Duyck {
1515b6fec18fSAlexander Duyck 	u32 func;
1516b6fec18fSAlexander Duyck 
1517b6fec18fSAlexander Duyck 	/* verify the fault register is in range and is aligned */
1518b6fec18fSAlexander Duyck 	switch (type) {
1519b6fec18fSAlexander Duyck 	case FM10K_PCA_FAULT:
1520b6fec18fSAlexander Duyck 	case FM10K_THI_FAULT:
1521b6fec18fSAlexander Duyck 	case FM10K_FUM_FAULT:
1522b6fec18fSAlexander Duyck 		break;
1523b6fec18fSAlexander Duyck 	default:
1524b6fec18fSAlexander Duyck 		return FM10K_ERR_PARAM;
1525b6fec18fSAlexander Duyck 	}
1526b6fec18fSAlexander Duyck 
1527b6fec18fSAlexander Duyck 	/* only service faults that are valid */
1528b6fec18fSAlexander Duyck 	func = fm10k_read_reg(hw, type + FM10K_FAULT_FUNC);
1529b6fec18fSAlexander Duyck 	if (!(func & FM10K_FAULT_FUNC_VALID))
1530b6fec18fSAlexander Duyck 		return FM10K_ERR_PARAM;
1531b6fec18fSAlexander Duyck 
1532b6fec18fSAlexander Duyck 	/* read remaining fields */
1533b6fec18fSAlexander Duyck 	fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_HI);
1534b6fec18fSAlexander Duyck 	fault->address <<= 32;
1535b6fec18fSAlexander Duyck 	fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO);
1536b6fec18fSAlexander Duyck 	fault->specinfo = fm10k_read_reg(hw, type + FM10K_FAULT_SPECINFO);
1537b6fec18fSAlexander Duyck 
1538b6fec18fSAlexander Duyck 	/* clear valid bit to allow for next error */
1539b6fec18fSAlexander Duyck 	fm10k_write_reg(hw, type + FM10K_FAULT_FUNC, FM10K_FAULT_FUNC_VALID);
1540b6fec18fSAlexander Duyck 
1541b6fec18fSAlexander Duyck 	/* Record which function triggered the error */
1542b6fec18fSAlexander Duyck 	if (func & FM10K_FAULT_FUNC_PF)
1543b6fec18fSAlexander Duyck 		fault->func = 0;
1544b6fec18fSAlexander Duyck 	else
1545b6fec18fSAlexander Duyck 		fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
1546b6fec18fSAlexander Duyck 				   FM10K_FAULT_FUNC_VF_SHIFT);
1547b6fec18fSAlexander Duyck 
1548b6fec18fSAlexander Duyck 	/* record fault type */
1549b6fec18fSAlexander Duyck 	fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;
1550b6fec18fSAlexander Duyck 
1551b6fec18fSAlexander Duyck 	return 0;
1552b6fec18fSAlexander Duyck }
1553b6fec18fSAlexander Duyck 
1554401b5383SAlexander Duyck /**
1555401b5383SAlexander Duyck  *  fm10k_request_lport_map_pf - Request LPORT map from the switch API
1556401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
1557401b5383SAlexander Duyck  *
1558401b5383SAlexander Duyck  **/
1559401b5383SAlexander Duyck static s32 fm10k_request_lport_map_pf(struct fm10k_hw *hw)
1560401b5383SAlexander Duyck {
1561401b5383SAlexander Duyck 	struct fm10k_mbx_info *mbx = &hw->mbx;
1562401b5383SAlexander Duyck 	u32 msg[1];
1563401b5383SAlexander Duyck 
1564401b5383SAlexander Duyck 	/* issue request asking for LPORT map */
1565401b5383SAlexander Duyck 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_LPORT_MAP);
1566401b5383SAlexander Duyck 
1567401b5383SAlexander Duyck 	/* load onto outgoing mailbox */
1568401b5383SAlexander Duyck 	return mbx->ops.enqueue_tx(hw, mbx, msg);
1569401b5383SAlexander Duyck }
1570401b5383SAlexander Duyck 
1571401b5383SAlexander Duyck /**
1572401b5383SAlexander Duyck  *  fm10k_get_host_state_pf - Returns the state of the switch and mailbox
1573401b5383SAlexander Duyck  *  @hw: pointer to hardware structure
1574401b5383SAlexander Duyck  *  @switch_ready: pointer to boolean value that will record switch state
1575401b5383SAlexander Duyck  *
1576401b5383SAlexander Duyck  *  This funciton will check the DMA_CTRL2 register and mailbox in order
1577401b5383SAlexander Duyck  *  to determine if the switch is ready for the PF to begin requesting
1578401b5383SAlexander Duyck  *  addresses and mapping traffic to the local interface.
1579401b5383SAlexander Duyck  **/
1580401b5383SAlexander Duyck static s32 fm10k_get_host_state_pf(struct fm10k_hw *hw, bool *switch_ready)
1581401b5383SAlexander Duyck {
1582401b5383SAlexander Duyck 	s32 ret_val = 0;
1583401b5383SAlexander Duyck 	u32 dma_ctrl2;
1584401b5383SAlexander Duyck 
1585eca32047SMatthew Vick 	/* verify the switch is ready for interaction */
1586401b5383SAlexander Duyck 	dma_ctrl2 = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
1587401b5383SAlexander Duyck 	if (!(dma_ctrl2 & FM10K_DMA_CTRL2_SWITCH_READY))
1588401b5383SAlexander Duyck 		goto out;
1589401b5383SAlexander Duyck 
1590401b5383SAlexander Duyck 	/* retrieve generic host state info */
1591401b5383SAlexander Duyck 	ret_val = fm10k_get_host_state_generic(hw, switch_ready);
1592401b5383SAlexander Duyck 	if (ret_val)
1593401b5383SAlexander Duyck 		goto out;
1594401b5383SAlexander Duyck 
1595401b5383SAlexander Duyck 	/* interface cannot receive traffic without logical ports */
1596401b5383SAlexander Duyck 	if (hw->mac.dglort_map == FM10K_DGLORTMAP_NONE)
1597401b5383SAlexander Duyck 		ret_val = fm10k_request_lport_map_pf(hw);
1598401b5383SAlexander Duyck 
1599401b5383SAlexander Duyck out:
1600401b5383SAlexander Duyck 	return ret_val;
1601401b5383SAlexander Duyck }
1602401b5383SAlexander Duyck 
1603401b5383SAlexander Duyck /* This structure defines the attibutes to be parsed below */
1604401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = {
1605401b5383SAlexander Duyck 	FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP),
1606401b5383SAlexander Duyck 	FM10K_TLV_ATTR_LAST
1607401b5383SAlexander Duyck };
1608401b5383SAlexander Duyck 
1609401b5383SAlexander Duyck /**
1610401b5383SAlexander Duyck  *  fm10k_msg_lport_map_pf - Message handler for lport_map message from SM
1611401b5383SAlexander Duyck  *  @hw: Pointer to hardware structure
1612401b5383SAlexander Duyck  *  @results: pointer array containing parsed data
1613401b5383SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1614401b5383SAlexander Duyck  *
1615401b5383SAlexander Duyck  *  This handler configures the lport mapping based on the reply from the
1616401b5383SAlexander Duyck  *  switch API.
1617401b5383SAlexander Duyck  **/
1618401b5383SAlexander Duyck s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results,
1619401b5383SAlexander Duyck 			   struct fm10k_mbx_info *mbx)
1620401b5383SAlexander Duyck {
1621401b5383SAlexander Duyck 	u16 glort, mask;
1622401b5383SAlexander Duyck 	u32 dglort_map;
1623401b5383SAlexander Duyck 	s32 err;
1624401b5383SAlexander Duyck 
1625401b5383SAlexander Duyck 	err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_LPORT_MAP],
1626401b5383SAlexander Duyck 				     &dglort_map);
1627401b5383SAlexander Duyck 	if (err)
1628401b5383SAlexander Duyck 		return err;
1629401b5383SAlexander Duyck 
1630401b5383SAlexander Duyck 	/* extract values out of the header */
1631401b5383SAlexander Duyck 	glort = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_GLORT);
1632401b5383SAlexander Duyck 	mask = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_MASK);
1633401b5383SAlexander Duyck 
1634401b5383SAlexander Duyck 	/* verify mask is set and none of the masked bits in glort are set */
1635401b5383SAlexander Duyck 	if (!mask || (glort & ~mask))
1636401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
1637401b5383SAlexander Duyck 
1638401b5383SAlexander Duyck 	/* verify the mask is contiguous, and that it is 1's followed by 0's */
1639401b5383SAlexander Duyck 	if (((~(mask - 1) & mask) + mask) & FM10K_DGLORTMAP_NONE)
1640401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
1641401b5383SAlexander Duyck 
1642401b5383SAlexander Duyck 	/* record the glort, mask, and port count */
1643401b5383SAlexander Duyck 	hw->mac.dglort_map = dglort_map;
1644401b5383SAlexander Duyck 
1645401b5383SAlexander Duyck 	return 0;
1646401b5383SAlexander Duyck }
1647401b5383SAlexander Duyck 
1648401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = {
1649401b5383SAlexander Duyck 	FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID),
1650401b5383SAlexander Duyck 	FM10K_TLV_ATTR_LAST
1651401b5383SAlexander Duyck };
1652401b5383SAlexander Duyck 
1653401b5383SAlexander Duyck /**
1654401b5383SAlexander Duyck  *  fm10k_msg_update_pvid_pf - Message handler for port VLAN message from SM
1655401b5383SAlexander Duyck  *  @hw: Pointer to hardware structure
1656401b5383SAlexander Duyck  *  @results: pointer array containing parsed data
1657401b5383SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1658401b5383SAlexander Duyck  *
1659401b5383SAlexander Duyck  *  This handler configures the default VLAN for the PF
1660401b5383SAlexander Duyck  **/
1661401b5383SAlexander Duyck s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results,
1662401b5383SAlexander Duyck 			     struct fm10k_mbx_info *mbx)
1663401b5383SAlexander Duyck {
1664401b5383SAlexander Duyck 	u16 glort, pvid;
1665401b5383SAlexander Duyck 	u32 pvid_update;
1666401b5383SAlexander Duyck 	s32 err;
1667401b5383SAlexander Duyck 
1668401b5383SAlexander Duyck 	err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1669401b5383SAlexander Duyck 				     &pvid_update);
1670401b5383SAlexander Duyck 	if (err)
1671401b5383SAlexander Duyck 		return err;
1672401b5383SAlexander Duyck 
1673401b5383SAlexander Duyck 	/* extract values from the pvid update */
1674401b5383SAlexander Duyck 	glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1675401b5383SAlexander Duyck 	pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1676401b5383SAlexander Duyck 
1677401b5383SAlexander Duyck 	/* if glort is not valid return error */
1678401b5383SAlexander Duyck 	if (!fm10k_glort_valid_pf(hw, glort))
1679401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
1680401b5383SAlexander Duyck 
1681401b5383SAlexander Duyck 	/* verify VID is valid */
1682401b5383SAlexander Duyck 	if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1683401b5383SAlexander Duyck 		return FM10K_ERR_PARAM;
1684401b5383SAlexander Duyck 
1685401b5383SAlexander Duyck 	/* record the port VLAN ID value */
1686401b5383SAlexander Duyck 	hw->mac.default_vid = pvid;
1687401b5383SAlexander Duyck 
1688401b5383SAlexander Duyck 	return 0;
1689401b5383SAlexander Duyck }
1690401b5383SAlexander Duyck 
1691401b5383SAlexander Duyck /**
1692401b5383SAlexander Duyck  *  fm10k_record_global_table_data - Move global table data to swapi table info
1693401b5383SAlexander Duyck  *  @from: pointer to source table data structure
1694401b5383SAlexander Duyck  *  @to: pointer to destination table info structure
1695401b5383SAlexander Duyck  *
1696401b5383SAlexander Duyck  *  This function is will copy table_data to the table_info contained in
1697401b5383SAlexander Duyck  *  the hw struct.
1698401b5383SAlexander Duyck  **/
1699401b5383SAlexander Duyck static void fm10k_record_global_table_data(struct fm10k_global_table_data *from,
1700401b5383SAlexander Duyck 					   struct fm10k_swapi_table_info *to)
1701401b5383SAlexander Duyck {
1702401b5383SAlexander Duyck 	/* convert from le32 struct to CPU byte ordered values */
1703401b5383SAlexander Duyck 	to->used = le32_to_cpu(from->used);
1704401b5383SAlexander Duyck 	to->avail = le32_to_cpu(from->avail);
1705401b5383SAlexander Duyck }
1706401b5383SAlexander Duyck 
1707401b5383SAlexander Duyck const struct fm10k_tlv_attr fm10k_err_msg_attr[] = {
1708401b5383SAlexander Duyck 	FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1709401b5383SAlexander Duyck 				 sizeof(struct fm10k_swapi_error)),
1710401b5383SAlexander Duyck 	FM10K_TLV_ATTR_LAST
1711401b5383SAlexander Duyck };
1712401b5383SAlexander Duyck 
1713401b5383SAlexander Duyck /**
1714401b5383SAlexander Duyck  *  fm10k_msg_err_pf - Message handler for error reply
1715401b5383SAlexander Duyck  *  @hw: Pointer to hardware structure
1716401b5383SAlexander Duyck  *  @results: pointer array containing parsed data
1717401b5383SAlexander Duyck  *  @mbx: Pointer to mailbox information structure
1718401b5383SAlexander Duyck  *
1719401b5383SAlexander Duyck  *  This handler will capture the data for any error replies to previous
1720401b5383SAlexander Duyck  *  messages that the PF has sent.
1721401b5383SAlexander Duyck  **/
1722401b5383SAlexander Duyck s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
1723401b5383SAlexander Duyck 		     struct fm10k_mbx_info *mbx)
1724401b5383SAlexander Duyck {
1725401b5383SAlexander Duyck 	struct fm10k_swapi_error err_msg;
1726401b5383SAlexander Duyck 	s32 err;
1727401b5383SAlexander Duyck 
1728401b5383SAlexander Duyck 	/* extract structure from message */
1729401b5383SAlexander Duyck 	err = fm10k_tlv_attr_get_le_struct(results[FM10K_PF_ATTR_ID_ERR],
1730401b5383SAlexander Duyck 					   &err_msg, sizeof(err_msg));
1731401b5383SAlexander Duyck 	if (err)
1732401b5383SAlexander Duyck 		return err;
1733401b5383SAlexander Duyck 
1734401b5383SAlexander Duyck 	/* record table status */
1735401b5383SAlexander Duyck 	fm10k_record_global_table_data(&err_msg.mac, &hw->swapi.mac);
1736401b5383SAlexander Duyck 	fm10k_record_global_table_data(&err_msg.nexthop, &hw->swapi.nexthop);
1737401b5383SAlexander Duyck 	fm10k_record_global_table_data(&err_msg.ffu, &hw->swapi.ffu);
1738401b5383SAlexander Duyck 
1739401b5383SAlexander Duyck 	/* record SW API status value */
1740401b5383SAlexander Duyck 	hw->swapi.status = le32_to_cpu(err_msg.status);
1741401b5383SAlexander Duyck 
1742401b5383SAlexander Duyck 	return 0;
1743401b5383SAlexander Duyck }
1744401b5383SAlexander Duyck 
17455f226ddbSAlexander Duyck const struct fm10k_tlv_attr fm10k_1588_timestamp_msg_attr[] = {
17465f226ddbSAlexander Duyck 	FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_1588_TIMESTAMP,
17475f226ddbSAlexander Duyck 				 sizeof(struct fm10k_swapi_1588_timestamp)),
17485f226ddbSAlexander Duyck 	FM10K_TLV_ATTR_LAST
17495f226ddbSAlexander Duyck };
17505f226ddbSAlexander Duyck 
17515f226ddbSAlexander Duyck /* currently there is no shared 1588 timestamp handler */
17525f226ddbSAlexander Duyck 
17535f226ddbSAlexander Duyck /**
17545f226ddbSAlexander Duyck  *  fm10k_adjust_systime_pf - Adjust systime frequency
17555f226ddbSAlexander Duyck  *  @hw: pointer to hardware structure
17565f226ddbSAlexander Duyck  *  @ppb: adjustment rate in parts per billion
17575f226ddbSAlexander Duyck  *
17585f226ddbSAlexander Duyck  *  This function will adjust the SYSTIME_CFG register contained in BAR 4
17595f226ddbSAlexander Duyck  *  if this function is supported for BAR 4 access.  The adjustment amount
17605f226ddbSAlexander Duyck  *  is based on the parts per billion value provided and adjusted to a
17615f226ddbSAlexander Duyck  *  value based on parts per 2^48 clock cycles.
17625f226ddbSAlexander Duyck  *
17635f226ddbSAlexander Duyck  *  If adjustment is not supported or the requested value is too large
17645f226ddbSAlexander Duyck  *  we will return an error.
17655f226ddbSAlexander Duyck  **/
17665f226ddbSAlexander Duyck static s32 fm10k_adjust_systime_pf(struct fm10k_hw *hw, s32 ppb)
17675f226ddbSAlexander Duyck {
17685f226ddbSAlexander Duyck 	u64 systime_adjust;
17695f226ddbSAlexander Duyck 
17705f226ddbSAlexander Duyck 	/* if sw_addr is not set we don't have switch register access */
17715f226ddbSAlexander Duyck 	if (!hw->sw_addr)
17725f226ddbSAlexander Duyck 		return ppb ? FM10K_ERR_PARAM : 0;
17735f226ddbSAlexander Duyck 
17745f226ddbSAlexander Duyck 	/* we must convert the value from parts per billion to parts per
17755f226ddbSAlexander Duyck 	 * 2^48 cycles.  In addition I have opted to only use the 30 most
17765f226ddbSAlexander Duyck 	 * significant bits of the adjustment value as the 8 least
17775f226ddbSAlexander Duyck 	 * significant bits are located in another register and represent
17785f226ddbSAlexander Duyck 	 * a value significantly less than a part per billion, the result
17795f226ddbSAlexander Duyck 	 * of dropping the 8 least significant bits is that the adjustment
17805f226ddbSAlexander Duyck 	 * value is effectively multiplied by 2^8 when we write it.
17815f226ddbSAlexander Duyck 	 *
17825f226ddbSAlexander Duyck 	 * As a result of all this the math for this breaks down as follows:
17835f226ddbSAlexander Duyck 	 *	ppb / 10^9 == adjust * 2^8 / 2^48
17845f226ddbSAlexander Duyck 	 * If we solve this for adjust, and simplify it comes out as:
17855f226ddbSAlexander Duyck 	 *	ppb * 2^31 / 5^9 == adjust
17865f226ddbSAlexander Duyck 	 */
17875f226ddbSAlexander Duyck 	systime_adjust = (ppb < 0) ? -ppb : ppb;
17885f226ddbSAlexander Duyck 	systime_adjust <<= 31;
17895f226ddbSAlexander Duyck 	do_div(systime_adjust, 1953125);
17905f226ddbSAlexander Duyck 
17915f226ddbSAlexander Duyck 	/* verify the requested adjustment value is in range */
17925f226ddbSAlexander Duyck 	if (systime_adjust > FM10K_SW_SYSTIME_ADJUST_MASK)
17935f226ddbSAlexander Duyck 		return FM10K_ERR_PARAM;
17945f226ddbSAlexander Duyck 
17955f226ddbSAlexander Duyck 	if (ppb < 0)
17965f226ddbSAlexander Duyck 		systime_adjust |= FM10K_SW_SYSTIME_ADJUST_DIR_NEGATIVE;
17975f226ddbSAlexander Duyck 
17985f226ddbSAlexander Duyck 	fm10k_write_sw_reg(hw, FM10K_SW_SYSTIME_ADJUST, (u32)systime_adjust);
17995f226ddbSAlexander Duyck 
18005f226ddbSAlexander Duyck 	return 0;
18015f226ddbSAlexander Duyck }
18025f226ddbSAlexander Duyck 
18035f226ddbSAlexander Duyck /**
18045f226ddbSAlexander Duyck  *  fm10k_read_systime_pf - Reads value of systime registers
18055f226ddbSAlexander Duyck  *  @hw: pointer to the hardware structure
18065f226ddbSAlexander Duyck  *
18075f226ddbSAlexander Duyck  *  Function reads the content of 2 registers, combined to represent a 64 bit
18085f226ddbSAlexander Duyck  *  value measured in nanosecods.  In order to guarantee the value is accurate
18095f226ddbSAlexander Duyck  *  we check the 32 most significant bits both before and after reading the
18105f226ddbSAlexander Duyck  *  32 least significant bits to verify they didn't change as we were reading
18115f226ddbSAlexander Duyck  *  the registers.
18125f226ddbSAlexander Duyck  **/
18135f226ddbSAlexander Duyck static u64 fm10k_read_systime_pf(struct fm10k_hw *hw)
18145f226ddbSAlexander Duyck {
18155f226ddbSAlexander Duyck 	u32 systime_l, systime_h, systime_tmp;
18165f226ddbSAlexander Duyck 
18175f226ddbSAlexander Duyck 	systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1);
18185f226ddbSAlexander Duyck 
18195f226ddbSAlexander Duyck 	do {
18205f226ddbSAlexander Duyck 		systime_tmp = systime_h;
18215f226ddbSAlexander Duyck 		systime_l = fm10k_read_reg(hw, FM10K_SYSTIME);
18225f226ddbSAlexander Duyck 		systime_h = fm10k_read_reg(hw, FM10K_SYSTIME + 1);
18235f226ddbSAlexander Duyck 	} while (systime_tmp != systime_h);
18245f226ddbSAlexander Duyck 
18255f226ddbSAlexander Duyck 	return ((u64)systime_h << 32) | systime_l;
18265f226ddbSAlexander Duyck }
18275f226ddbSAlexander Duyck 
1828401b5383SAlexander Duyck static const struct fm10k_msg_data fm10k_msg_data_pf[] = {
1829401b5383SAlexander Duyck 	FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1830401b5383SAlexander Duyck 	FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1831401b5383SAlexander Duyck 	FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf),
1832401b5383SAlexander Duyck 	FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1833401b5383SAlexander Duyck 	FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1834401b5383SAlexander Duyck 	FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
1835401b5383SAlexander Duyck 	FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1836401b5383SAlexander Duyck };
1837401b5383SAlexander Duyck 
1838b6fec18fSAlexander Duyck static struct fm10k_mac_ops mac_ops_pf = {
1839b6fec18fSAlexander Duyck 	.get_bus_info		= &fm10k_get_bus_info_generic,
1840b6fec18fSAlexander Duyck 	.reset_hw		= &fm10k_reset_hw_pf,
1841b6fec18fSAlexander Duyck 	.init_hw		= &fm10k_init_hw_pf,
1842b6fec18fSAlexander Duyck 	.start_hw		= &fm10k_start_hw_generic,
1843b6fec18fSAlexander Duyck 	.stop_hw		= &fm10k_stop_hw_generic,
1844b6fec18fSAlexander Duyck 	.is_slot_appropriate	= &fm10k_is_slot_appropriate_pf,
1845401b5383SAlexander Duyck 	.update_vlan		= &fm10k_update_vlan_pf,
1846b6fec18fSAlexander Duyck 	.read_mac_addr		= &fm10k_read_mac_addr_pf,
1847401b5383SAlexander Duyck 	.update_uc_addr		= &fm10k_update_uc_addr_pf,
1848401b5383SAlexander Duyck 	.update_mc_addr		= &fm10k_update_mc_addr_pf,
1849401b5383SAlexander Duyck 	.update_xcast_mode	= &fm10k_update_xcast_mode_pf,
1850401b5383SAlexander Duyck 	.update_int_moderator	= &fm10k_update_int_moderator_pf,
1851401b5383SAlexander Duyck 	.update_lport_state	= &fm10k_update_lport_state_pf,
1852b6fec18fSAlexander Duyck 	.update_hw_stats	= &fm10k_update_hw_stats_pf,
1853b6fec18fSAlexander Duyck 	.rebind_hw_stats	= &fm10k_rebind_hw_stats_pf,
1854401b5383SAlexander Duyck 	.configure_dglort_map	= &fm10k_configure_dglort_map_pf,
1855401b5383SAlexander Duyck 	.set_dma_mask		= &fm10k_set_dma_mask_pf,
1856b6fec18fSAlexander Duyck 	.get_fault		= &fm10k_get_fault_pf,
1857401b5383SAlexander Duyck 	.get_host_state		= &fm10k_get_host_state_pf,
18585f226ddbSAlexander Duyck 	.adjust_systime		= &fm10k_adjust_systime_pf,
18595f226ddbSAlexander Duyck 	.read_systime		= &fm10k_read_systime_pf,
1860b6fec18fSAlexander Duyck };
1861b6fec18fSAlexander Duyck 
1862c2653865SAlexander Duyck static struct fm10k_iov_ops iov_ops_pf = {
1863c2653865SAlexander Duyck 	.assign_resources		= &fm10k_iov_assign_resources_pf,
1864c2653865SAlexander Duyck 	.configure_tc			= &fm10k_iov_configure_tc_pf,
1865c2653865SAlexander Duyck 	.assign_int_moderator		= &fm10k_iov_assign_int_moderator_pf,
1866c2653865SAlexander Duyck 	.assign_default_mac_vlan	= fm10k_iov_assign_default_mac_vlan_pf,
1867c2653865SAlexander Duyck 	.reset_resources		= &fm10k_iov_reset_resources_pf,
1868c2653865SAlexander Duyck 	.set_lport			= &fm10k_iov_set_lport_pf,
1869c2653865SAlexander Duyck 	.reset_lport			= &fm10k_iov_reset_lport_pf,
1870c2653865SAlexander Duyck 	.update_stats			= &fm10k_iov_update_stats_pf,
18715f226ddbSAlexander Duyck 	.report_timestamp		= &fm10k_iov_report_timestamp_pf,
1872c2653865SAlexander Duyck };
1873c2653865SAlexander Duyck 
1874401b5383SAlexander Duyck static s32 fm10k_get_invariants_pf(struct fm10k_hw *hw)
1875401b5383SAlexander Duyck {
1876401b5383SAlexander Duyck 	fm10k_get_invariants_generic(hw);
1877401b5383SAlexander Duyck 
1878401b5383SAlexander Duyck 	return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf);
1879401b5383SAlexander Duyck }
1880401b5383SAlexander Duyck 
1881b6fec18fSAlexander Duyck struct fm10k_info fm10k_pf_info = {
1882b6fec18fSAlexander Duyck 	.mac		= fm10k_mac_pf,
1883401b5383SAlexander Duyck 	.get_invariants	= &fm10k_get_invariants_pf,
1884b6fec18fSAlexander Duyck 	.mac_ops	= &mac_ops_pf,
1885c2653865SAlexander Duyck 	.iov_ops	= &iov_ops_pf,
1886b6fec18fSAlexander Duyck };
1887