xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/intel/fm10k/fm10k_pf.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright(c) 2013 - 2019 Intel Corporation. */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #include "fm10k_pf.h"
5*4882a593Smuzhiyun #include "fm10k_vf.h"
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun /**
8*4882a593Smuzhiyun  *  fm10k_reset_hw_pf - PF hardware reset
9*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  This function should return the hardware to a state similar to the
12*4882a593Smuzhiyun  *  one it is in after being powered on.
13*4882a593Smuzhiyun  **/
fm10k_reset_hw_pf(struct fm10k_hw * hw)14*4882a593Smuzhiyun static s32 fm10k_reset_hw_pf(struct fm10k_hw *hw)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 	s32 err;
17*4882a593Smuzhiyun 	u32 reg;
18*4882a593Smuzhiyun 	u16 i;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun 	/* Disable interrupts */
21*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(ALL));
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	/* Lock ITR2 reg 0 into itself and disable interrupt moderation */
24*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_ITR2(0), 0);
25*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_INT_CTRL, 0);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 	/* We assume here Tx and Rx queue 0 are owned by the PF */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	/* Shut off VF access to their queues forcing them to queue 0 */
30*4882a593Smuzhiyun 	for (i = 0; i < FM10K_TQMAP_TABLE_SIZE; i++) {
31*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQMAP(i), 0);
32*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RQMAP(i), 0);
33*4882a593Smuzhiyun 	}
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	/* shut down all rings */
36*4882a593Smuzhiyun 	err = fm10k_disable_queues_generic(hw, FM10K_MAX_QUEUES);
37*4882a593Smuzhiyun 	if (err == FM10K_ERR_REQUESTS_PENDING) {
38*4882a593Smuzhiyun 		hw->mac.reset_while_pending++;
39*4882a593Smuzhiyun 		goto force_reset;
40*4882a593Smuzhiyun 	} else if (err) {
41*4882a593Smuzhiyun 		return err;
42*4882a593Smuzhiyun 	}
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun 	/* Verify that DMA is no longer active */
45*4882a593Smuzhiyun 	reg = fm10k_read_reg(hw, FM10K_DMA_CTRL);
46*4882a593Smuzhiyun 	if (reg & (FM10K_DMA_CTRL_TX_ACTIVE | FM10K_DMA_CTRL_RX_ACTIVE))
47*4882a593Smuzhiyun 		return FM10K_ERR_DMA_PENDING;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun force_reset:
50*4882a593Smuzhiyun 	/* Inititate data path reset */
51*4882a593Smuzhiyun 	reg = FM10K_DMA_CTRL_DATAPATH_RESET;
52*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DMA_CTRL, reg);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	/* Flush write and allow 100us for reset to complete */
55*4882a593Smuzhiyun 	fm10k_write_flush(hw);
56*4882a593Smuzhiyun 	udelay(FM10K_RESET_TIMEOUT);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/* Verify we made it out of reset */
59*4882a593Smuzhiyun 	reg = fm10k_read_reg(hw, FM10K_IP);
60*4882a593Smuzhiyun 	if (!(reg & FM10K_IP_NOTINRESET))
61*4882a593Smuzhiyun 		return FM10K_ERR_RESET_FAILED;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	return 0;
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /**
67*4882a593Smuzhiyun  *  fm10k_is_ari_hierarchy_pf - Indicate ARI hierarchy support
68*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
69*4882a593Smuzhiyun  *
70*4882a593Smuzhiyun  *  Looks at the ARI hierarchy bit to determine whether ARI is supported or not.
71*4882a593Smuzhiyun  **/
fm10k_is_ari_hierarchy_pf(struct fm10k_hw * hw)72*4882a593Smuzhiyun static bool fm10k_is_ari_hierarchy_pf(struct fm10k_hw *hw)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	u16 sriov_ctrl = fm10k_read_pci_cfg_word(hw, FM10K_PCIE_SRIOV_CTRL);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	return !!(sriov_ctrl & FM10K_PCIE_SRIOV_CTRL_VFARI);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /**
80*4882a593Smuzhiyun  *  fm10k_init_hw_pf - PF hardware initialization
81*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  **/
fm10k_init_hw_pf(struct fm10k_hw * hw)84*4882a593Smuzhiyun static s32 fm10k_init_hw_pf(struct fm10k_hw *hw)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun 	u32 dma_ctrl, txqctl;
87*4882a593Smuzhiyun 	u16 i;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 	/* Establish default VSI as valid */
90*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DGLORTDEC(fm10k_dglort_default), 0);
91*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DGLORTMAP(fm10k_dglort_default),
92*4882a593Smuzhiyun 			FM10K_DGLORTMAP_ANY);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	/* Invalidate all other GLORT entries */
95*4882a593Smuzhiyun 	for (i = 1; i < FM10K_DGLORT_COUNT; i++)
96*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_DGLORTMAP(i), FM10K_DGLORTMAP_NONE);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	/* reset ITR2(0) to point to itself */
99*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_ITR2(0), 0);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	/* reset VF ITR2(0) to point to 0 avoid PF registers */
102*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), 0);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	/* loop through all PF ITR2 registers pointing them to the previous */
105*4882a593Smuzhiyun 	for (i = 1; i < FM10K_ITR_REG_COUNT_PF; i++)
106*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	/* Enable interrupt moderator if not already enabled */
109*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	/* compute the default txqctl configuration */
112*4882a593Smuzhiyun 	txqctl = FM10K_TXQCTL_PF | FM10K_TXQCTL_UNLIMITED_BW |
113*4882a593Smuzhiyun 		 (hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	for (i = 0; i < FM10K_MAX_QUEUES; i++) {
116*4882a593Smuzhiyun 		/* configure rings for 256 Queue / 32 Descriptor cache mode */
117*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQDLOC(i),
118*4882a593Smuzhiyun 				(i * FM10K_TQDLOC_BASE_32_DESC) |
119*4882a593Smuzhiyun 				FM10K_TQDLOC_SIZE_32_DESC);
120*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 		/* configure rings to provide TPH processing hints */
123*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TPH_TXCTRL(i),
124*4882a593Smuzhiyun 				FM10K_TPH_TXCTRL_DESC_TPHEN |
125*4882a593Smuzhiyun 				FM10K_TPH_TXCTRL_DESC_RROEN |
126*4882a593Smuzhiyun 				FM10K_TPH_TXCTRL_DESC_WROEN |
127*4882a593Smuzhiyun 				FM10K_TPH_TXCTRL_DATA_RROEN);
128*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TPH_RXCTRL(i),
129*4882a593Smuzhiyun 				FM10K_TPH_RXCTRL_DESC_TPHEN |
130*4882a593Smuzhiyun 				FM10K_TPH_RXCTRL_DESC_RROEN |
131*4882a593Smuzhiyun 				FM10K_TPH_RXCTRL_DATA_WROEN |
132*4882a593Smuzhiyun 				FM10K_TPH_RXCTRL_HDR_WROEN);
133*4882a593Smuzhiyun 	}
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	/* set max hold interval to align with 1.024 usec in all modes and
136*4882a593Smuzhiyun 	 * store ITR scale
137*4882a593Smuzhiyun 	 */
138*4882a593Smuzhiyun 	switch (hw->bus.speed) {
139*4882a593Smuzhiyun 	case fm10k_bus_speed_2500:
140*4882a593Smuzhiyun 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN1;
141*4882a593Smuzhiyun 		hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN1;
142*4882a593Smuzhiyun 		break;
143*4882a593Smuzhiyun 	case fm10k_bus_speed_5000:
144*4882a593Smuzhiyun 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN2;
145*4882a593Smuzhiyun 		hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN2;
146*4882a593Smuzhiyun 		break;
147*4882a593Smuzhiyun 	case fm10k_bus_speed_8000:
148*4882a593Smuzhiyun 		dma_ctrl = FM10K_DMA_CTRL_MAX_HOLD_1US_GEN3;
149*4882a593Smuzhiyun 		hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
150*4882a593Smuzhiyun 		break;
151*4882a593Smuzhiyun 	default:
152*4882a593Smuzhiyun 		dma_ctrl = 0;
153*4882a593Smuzhiyun 		/* just in case, assume Gen3 ITR scale */
154*4882a593Smuzhiyun 		hw->mac.itr_scale = FM10K_TDLEN_ITR_SCALE_GEN3;
155*4882a593Smuzhiyun 		break;
156*4882a593Smuzhiyun 	}
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	/* Configure TSO flags */
159*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DTXTCPFLGL, FM10K_TSO_FLAGS_LOW);
160*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DTXTCPFLGH, FM10K_TSO_FLAGS_HI);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* Enable DMA engine
163*4882a593Smuzhiyun 	 * Set Rx Descriptor size to 32
164*4882a593Smuzhiyun 	 * Set Minimum MSS to 64
165*4882a593Smuzhiyun 	 * Set Maximum number of Rx queues to 256 / 32 Descriptor
166*4882a593Smuzhiyun 	 */
167*4882a593Smuzhiyun 	dma_ctrl |= FM10K_DMA_CTRL_TX_ENABLE | FM10K_DMA_CTRL_RX_ENABLE |
168*4882a593Smuzhiyun 		    FM10K_DMA_CTRL_RX_DESC_SIZE | FM10K_DMA_CTRL_MINMSS_64 |
169*4882a593Smuzhiyun 		    FM10K_DMA_CTRL_32_DESC;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DMA_CTRL, dma_ctrl);
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	/* record maximum queue count, we limit ourselves to 128 */
174*4882a593Smuzhiyun 	hw->mac.max_queues = FM10K_MAX_QUEUES_PF;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	/* We support either 64 VFs or 7 VFs depending on if we have ARI */
177*4882a593Smuzhiyun 	hw->iov.total_vfs = fm10k_is_ari_hierarchy_pf(hw) ? 64 : 7;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	return 0;
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun /**
183*4882a593Smuzhiyun  *  fm10k_update_vlan_pf - Update status of VLAN ID in VLAN filter table
184*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
185*4882a593Smuzhiyun  *  @vid: VLAN ID to add to table
186*4882a593Smuzhiyun  *  @vsi: Index indicating VF ID or PF ID in table
187*4882a593Smuzhiyun  *  @set: Indicates if this is a set or clear operation
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  *  This function adds or removes the corresponding VLAN ID from the VLAN
190*4882a593Smuzhiyun  *  filter table for the corresponding function.  In addition to the
191*4882a593Smuzhiyun  *  standard set/clear that supports one bit a multi-bit write is
192*4882a593Smuzhiyun  *  supported to set 64 bits at a time.
193*4882a593Smuzhiyun  **/
fm10k_update_vlan_pf(struct fm10k_hw * hw,u32 vid,u8 vsi,bool set)194*4882a593Smuzhiyun static s32 fm10k_update_vlan_pf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
195*4882a593Smuzhiyun {
196*4882a593Smuzhiyun 	u32 vlan_table, reg, mask, bit, len;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	/* verify the VSI index is valid */
199*4882a593Smuzhiyun 	if (vsi > FM10K_VLAN_TABLE_VSI_MAX)
200*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	/* VLAN multi-bit write:
203*4882a593Smuzhiyun 	 * The multi-bit write has several parts to it.
204*4882a593Smuzhiyun 	 *               24              16               8               0
205*4882a593Smuzhiyun 	 *  7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
206*4882a593Smuzhiyun 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
207*4882a593Smuzhiyun 	 * | RSVD0 |         Length        |C|RSVD0|        VLAN ID        |
208*4882a593Smuzhiyun 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209*4882a593Smuzhiyun 	 *
210*4882a593Smuzhiyun 	 * VLAN ID: Vlan Starting value
211*4882a593Smuzhiyun 	 * RSVD0: Reserved section, must be 0
212*4882a593Smuzhiyun 	 * C: Flag field, 0 is set, 1 is clear (Used in VF VLAN message)
213*4882a593Smuzhiyun 	 * Length: Number of times to repeat the bit being set
214*4882a593Smuzhiyun 	 */
215*4882a593Smuzhiyun 	len = vid >> 16;
216*4882a593Smuzhiyun 	vid = (vid << 17) >> 17;
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 	/* verify the reserved 0 fields are 0 */
219*4882a593Smuzhiyun 	if (len >= FM10K_VLAN_TABLE_VID_MAX || vid >= FM10K_VLAN_TABLE_VID_MAX)
220*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	/* Loop through the table updating all required VLANs */
223*4882a593Smuzhiyun 	for (reg = FM10K_VLAN_TABLE(vsi, vid / 32), bit = vid % 32;
224*4882a593Smuzhiyun 	     len < FM10K_VLAN_TABLE_VID_MAX;
225*4882a593Smuzhiyun 	     len -= 32 - bit, reg++, bit = 0) {
226*4882a593Smuzhiyun 		/* record the initial state of the register */
227*4882a593Smuzhiyun 		vlan_table = fm10k_read_reg(hw, reg);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 		/* truncate mask if we are at the start or end of the run */
230*4882a593Smuzhiyun 		mask = (~(u32)0 >> ((len < 31) ? 31 - len : 0)) << bit;
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 		/* make necessary modifications to the register */
233*4882a593Smuzhiyun 		mask &= set ? ~vlan_table : vlan_table;
234*4882a593Smuzhiyun 		if (mask)
235*4882a593Smuzhiyun 			fm10k_write_reg(hw, reg, vlan_table ^ mask);
236*4882a593Smuzhiyun 	}
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 	return 0;
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun /**
242*4882a593Smuzhiyun  *  fm10k_read_mac_addr_pf - Read device MAC address
243*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
244*4882a593Smuzhiyun  *
245*4882a593Smuzhiyun  *  Reads the device MAC address from the SM_AREA and stores the value.
246*4882a593Smuzhiyun  **/
fm10k_read_mac_addr_pf(struct fm10k_hw * hw)247*4882a593Smuzhiyun static s32 fm10k_read_mac_addr_pf(struct fm10k_hw *hw)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun 	u8 perm_addr[ETH_ALEN];
250*4882a593Smuzhiyun 	u32 serial_num;
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun 	serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(1));
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	/* last byte should be all 1's */
255*4882a593Smuzhiyun 	if ((~serial_num) << 24)
256*4882a593Smuzhiyun 		return  FM10K_ERR_INVALID_MAC_ADDR;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	perm_addr[0] = (u8)(serial_num >> 24);
259*4882a593Smuzhiyun 	perm_addr[1] = (u8)(serial_num >> 16);
260*4882a593Smuzhiyun 	perm_addr[2] = (u8)(serial_num >> 8);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	serial_num = fm10k_read_reg(hw, FM10K_SM_AREA(0));
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	/* first byte should be all 1's */
265*4882a593Smuzhiyun 	if ((~serial_num) >> 24)
266*4882a593Smuzhiyun 		return  FM10K_ERR_INVALID_MAC_ADDR;
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	perm_addr[3] = (u8)(serial_num >> 16);
269*4882a593Smuzhiyun 	perm_addr[4] = (u8)(serial_num >> 8);
270*4882a593Smuzhiyun 	perm_addr[5] = (u8)(serial_num);
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun 	ether_addr_copy(hw->mac.perm_addr, perm_addr);
273*4882a593Smuzhiyun 	ether_addr_copy(hw->mac.addr, perm_addr);
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 	return 0;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /**
279*4882a593Smuzhiyun  *  fm10k_glort_valid_pf - Validate that the provided glort is valid
280*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
281*4882a593Smuzhiyun  *  @glort: base glort to be validated
282*4882a593Smuzhiyun  *
283*4882a593Smuzhiyun  *  This function will return an error if the provided glort is invalid
284*4882a593Smuzhiyun  **/
fm10k_glort_valid_pf(struct fm10k_hw * hw,u16 glort)285*4882a593Smuzhiyun bool fm10k_glort_valid_pf(struct fm10k_hw *hw, u16 glort)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun 	glort &= hw->mac.dglort_map >> FM10K_DGLORTMAP_MASK_SHIFT;
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	return glort == (hw->mac.dglort_map & FM10K_DGLORTMAP_NONE);
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun /**
293*4882a593Smuzhiyun  *  fm10k_update_xc_addr_pf - Update device addresses
294*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
295*4882a593Smuzhiyun  *  @glort: base resource tag for this request
296*4882a593Smuzhiyun  *  @mac: MAC address to add/remove from table
297*4882a593Smuzhiyun  *  @vid: VLAN ID to add/remove from table
298*4882a593Smuzhiyun  *  @add: Indicates if this is an add or remove operation
299*4882a593Smuzhiyun  *  @flags: flags field to indicate add and secure
300*4882a593Smuzhiyun  *
301*4882a593Smuzhiyun  *  This function generates a message to the Switch API requesting
302*4882a593Smuzhiyun  *  that the given logical port add/remove the given L2 MAC/VLAN address.
303*4882a593Smuzhiyun  **/
fm10k_update_xc_addr_pf(struct fm10k_hw * hw,u16 glort,const u8 * mac,u16 vid,bool add,u8 flags)304*4882a593Smuzhiyun static s32 fm10k_update_xc_addr_pf(struct fm10k_hw *hw, u16 glort,
305*4882a593Smuzhiyun 				   const u8 *mac, u16 vid, bool add, u8 flags)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun 	struct fm10k_mbx_info *mbx = &hw->mbx;
308*4882a593Smuzhiyun 	struct fm10k_mac_update mac_update;
309*4882a593Smuzhiyun 	u32 msg[5];
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* clear set bit from VLAN ID */
312*4882a593Smuzhiyun 	vid &= ~FM10K_VLAN_CLEAR;
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 	/* if glort or VLAN are not valid return error */
315*4882a593Smuzhiyun 	if (!fm10k_glort_valid_pf(hw, glort) || vid >= FM10K_VLAN_TABLE_VID_MAX)
316*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 	/* record fields */
319*4882a593Smuzhiyun 	mac_update.mac_lower = cpu_to_le32(((u32)mac[2] << 24) |
320*4882a593Smuzhiyun 						 ((u32)mac[3] << 16) |
321*4882a593Smuzhiyun 						 ((u32)mac[4] << 8) |
322*4882a593Smuzhiyun 						 ((u32)mac[5]));
323*4882a593Smuzhiyun 	mac_update.mac_upper = cpu_to_le16(((u16)mac[0] << 8) |
324*4882a593Smuzhiyun 					   ((u16)mac[1]));
325*4882a593Smuzhiyun 	mac_update.vlan = cpu_to_le16(vid);
326*4882a593Smuzhiyun 	mac_update.glort = cpu_to_le16(glort);
327*4882a593Smuzhiyun 	mac_update.action = add ? 0 : 1;
328*4882a593Smuzhiyun 	mac_update.flags = flags;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	/* populate mac_update fields */
331*4882a593Smuzhiyun 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_UPDATE_MAC_FWD_RULE);
332*4882a593Smuzhiyun 	fm10k_tlv_attr_put_le_struct(msg, FM10K_PF_ATTR_ID_MAC_UPDATE,
333*4882a593Smuzhiyun 				     &mac_update, sizeof(mac_update));
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	/* load onto outgoing mailbox */
336*4882a593Smuzhiyun 	return mbx->ops.enqueue_tx(hw, mbx, msg);
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun /**
340*4882a593Smuzhiyun  *  fm10k_update_uc_addr_pf - Update device unicast addresses
341*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
342*4882a593Smuzhiyun  *  @glort: base resource tag for this request
343*4882a593Smuzhiyun  *  @mac: MAC address to add/remove from table
344*4882a593Smuzhiyun  *  @vid: VLAN ID to add/remove from table
345*4882a593Smuzhiyun  *  @add: Indicates if this is an add or remove operation
346*4882a593Smuzhiyun  *  @flags: flags field to indicate add and secure
347*4882a593Smuzhiyun  *
348*4882a593Smuzhiyun  *  This function is used to add or remove unicast addresses for
349*4882a593Smuzhiyun  *  the PF.
350*4882a593Smuzhiyun  **/
fm10k_update_uc_addr_pf(struct fm10k_hw * hw,u16 glort,const u8 * mac,u16 vid,bool add,u8 flags)351*4882a593Smuzhiyun static s32 fm10k_update_uc_addr_pf(struct fm10k_hw *hw, u16 glort,
352*4882a593Smuzhiyun 				   const u8 *mac, u16 vid, bool add, u8 flags)
353*4882a593Smuzhiyun {
354*4882a593Smuzhiyun 	/* verify MAC address is valid */
355*4882a593Smuzhiyun 	if (!is_valid_ether_addr(mac))
356*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, flags);
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun /**
362*4882a593Smuzhiyun  *  fm10k_update_mc_addr_pf - Update device multicast addresses
363*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
364*4882a593Smuzhiyun  *  @glort: base resource tag for this request
365*4882a593Smuzhiyun  *  @mac: MAC address to add/remove from table
366*4882a593Smuzhiyun  *  @vid: VLAN ID to add/remove from table
367*4882a593Smuzhiyun  *  @add: Indicates if this is an add or remove operation
368*4882a593Smuzhiyun  *
369*4882a593Smuzhiyun  *  This function is used to add or remove multicast MAC addresses for
370*4882a593Smuzhiyun  *  the PF.
371*4882a593Smuzhiyun  **/
fm10k_update_mc_addr_pf(struct fm10k_hw * hw,u16 glort,const u8 * mac,u16 vid,bool add)372*4882a593Smuzhiyun static s32 fm10k_update_mc_addr_pf(struct fm10k_hw *hw, u16 glort,
373*4882a593Smuzhiyun 				   const u8 *mac, u16 vid, bool add)
374*4882a593Smuzhiyun {
375*4882a593Smuzhiyun 	/* verify multicast address is valid */
376*4882a593Smuzhiyun 	if (!is_multicast_ether_addr(mac))
377*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun 	return fm10k_update_xc_addr_pf(hw, glort, mac, vid, add, 0);
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun /**
383*4882a593Smuzhiyun  *  fm10k_update_xcast_mode_pf - Request update of multicast mode
384*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
385*4882a593Smuzhiyun  *  @glort: base resource tag for this request
386*4882a593Smuzhiyun  *  @mode: integer value indicating mode being requested
387*4882a593Smuzhiyun  *
388*4882a593Smuzhiyun  *  This function will attempt to request a higher mode for the port
389*4882a593Smuzhiyun  *  so that it can enable either multicast, multicast promiscuous, or
390*4882a593Smuzhiyun  *  promiscuous mode of operation.
391*4882a593Smuzhiyun  **/
fm10k_update_xcast_mode_pf(struct fm10k_hw * hw,u16 glort,u8 mode)392*4882a593Smuzhiyun static s32 fm10k_update_xcast_mode_pf(struct fm10k_hw *hw, u16 glort, u8 mode)
393*4882a593Smuzhiyun {
394*4882a593Smuzhiyun 	struct fm10k_mbx_info *mbx = &hw->mbx;
395*4882a593Smuzhiyun 	u32 msg[3], xcast_mode;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun 	if (mode > FM10K_XCAST_MODE_NONE)
398*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun 	/* if glort is not valid return error */
401*4882a593Smuzhiyun 	if (!fm10k_glort_valid_pf(hw, glort))
402*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	/* write xcast mode as a single u32 value,
405*4882a593Smuzhiyun 	 * lower 16 bits: glort
406*4882a593Smuzhiyun 	 * upper 16 bits: mode
407*4882a593Smuzhiyun 	 */
408*4882a593Smuzhiyun 	xcast_mode = ((u32)mode << 16) | glort;
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun 	/* generate message requesting to change xcast mode */
411*4882a593Smuzhiyun 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_XCAST_MODES);
412*4882a593Smuzhiyun 	fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_XCAST_MODE, xcast_mode);
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	/* load onto outgoing mailbox */
415*4882a593Smuzhiyun 	return mbx->ops.enqueue_tx(hw, mbx, msg);
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun /**
419*4882a593Smuzhiyun  *  fm10k_update_int_moderator_pf - Update interrupt moderator linked list
420*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
421*4882a593Smuzhiyun  *
422*4882a593Smuzhiyun  *  This function walks through the MSI-X vector table to determine the
423*4882a593Smuzhiyun  *  number of active interrupts and based on that information updates the
424*4882a593Smuzhiyun  *  interrupt moderator linked list.
425*4882a593Smuzhiyun  **/
fm10k_update_int_moderator_pf(struct fm10k_hw * hw)426*4882a593Smuzhiyun static void fm10k_update_int_moderator_pf(struct fm10k_hw *hw)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun 	u32 i;
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun 	/* Disable interrupt moderator */
431*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_INT_CTRL, 0);
432*4882a593Smuzhiyun 
433*4882a593Smuzhiyun 	/* loop through PF from last to first looking enabled vectors */
434*4882a593Smuzhiyun 	for (i = FM10K_ITR_REG_COUNT_PF - 1; i; i--) {
435*4882a593Smuzhiyun 		if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
436*4882a593Smuzhiyun 			break;
437*4882a593Smuzhiyun 	}
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun 	/* always reset VFITR2[0] to point to last enabled PF vector */
440*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_ITR2(FM10K_ITR_REG_COUNT_PF), i);
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	/* reset ITR2[0] to point to last enabled PF vector */
443*4882a593Smuzhiyun 	if (!hw->iov.num_vfs)
444*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(0), i);
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun 	/* Enable interrupt moderator */
447*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_INT_CTRL, FM10K_INT_CTRL_ENABLEMODERATOR);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun /**
451*4882a593Smuzhiyun  *  fm10k_update_lport_state_pf - Notify the switch of a change in port state
452*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
453*4882a593Smuzhiyun  *  @glort: base resource tag for this request
454*4882a593Smuzhiyun  *  @count: number of logical ports being updated
455*4882a593Smuzhiyun  *  @enable: boolean value indicating enable or disable
456*4882a593Smuzhiyun  *
457*4882a593Smuzhiyun  *  This function is used to add/remove a logical port from the switch.
458*4882a593Smuzhiyun  **/
fm10k_update_lport_state_pf(struct fm10k_hw * hw,u16 glort,u16 count,bool enable)459*4882a593Smuzhiyun static s32 fm10k_update_lport_state_pf(struct fm10k_hw *hw, u16 glort,
460*4882a593Smuzhiyun 				       u16 count, bool enable)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun 	struct fm10k_mbx_info *mbx = &hw->mbx;
463*4882a593Smuzhiyun 	u32 msg[3], lport_msg;
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun 	/* do nothing if we are being asked to create or destroy 0 ports */
466*4882a593Smuzhiyun 	if (!count)
467*4882a593Smuzhiyun 		return 0;
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	/* if glort is not valid return error */
470*4882a593Smuzhiyun 	if (!fm10k_glort_valid_pf(hw, glort))
471*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	/* reset multicast mode if deleting lport */
474*4882a593Smuzhiyun 	if (!enable)
475*4882a593Smuzhiyun 		fm10k_update_xcast_mode_pf(hw, glort, FM10K_XCAST_MODE_NONE);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun 	/* construct the lport message from the 2 pieces of data we have */
478*4882a593Smuzhiyun 	lport_msg = ((u32)count << 16) | glort;
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun 	/* generate lport create/delete message */
481*4882a593Smuzhiyun 	fm10k_tlv_msg_init(msg, enable ? FM10K_PF_MSG_ID_LPORT_CREATE :
482*4882a593Smuzhiyun 					 FM10K_PF_MSG_ID_LPORT_DELETE);
483*4882a593Smuzhiyun 	fm10k_tlv_attr_put_u32(msg, FM10K_PF_ATTR_ID_PORT, lport_msg);
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	/* load onto outgoing mailbox */
486*4882a593Smuzhiyun 	return mbx->ops.enqueue_tx(hw, mbx, msg);
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun /**
490*4882a593Smuzhiyun  *  fm10k_configure_dglort_map_pf - Configures GLORT entry and queues
491*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
492*4882a593Smuzhiyun  *  @dglort: pointer to dglort configuration structure
493*4882a593Smuzhiyun  *
494*4882a593Smuzhiyun  *  Reads the configuration structure contained in dglort_cfg and uses
495*4882a593Smuzhiyun  *  that information to then populate a DGLORTMAP/DEC entry and the queues
496*4882a593Smuzhiyun  *  to which it has been assigned.
497*4882a593Smuzhiyun  **/
fm10k_configure_dglort_map_pf(struct fm10k_hw * hw,struct fm10k_dglort_cfg * dglort)498*4882a593Smuzhiyun static s32 fm10k_configure_dglort_map_pf(struct fm10k_hw *hw,
499*4882a593Smuzhiyun 					 struct fm10k_dglort_cfg *dglort)
500*4882a593Smuzhiyun {
501*4882a593Smuzhiyun 	u16 glort, queue_count, vsi_count, pc_count;
502*4882a593Smuzhiyun 	u16 vsi, queue, pc, q_idx;
503*4882a593Smuzhiyun 	u32 txqctl, dglortdec, dglortmap;
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun 	/* verify the dglort pointer */
506*4882a593Smuzhiyun 	if (!dglort)
507*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 	/* verify the dglort values */
510*4882a593Smuzhiyun 	if ((dglort->idx > 7) || (dglort->rss_l > 7) || (dglort->pc_l > 3) ||
511*4882a593Smuzhiyun 	    (dglort->vsi_l > 6) || (dglort->vsi_b > 64) ||
512*4882a593Smuzhiyun 	    (dglort->queue_l > 8) || (dglort->queue_b >= 256))
513*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun 	/* determine count of VSIs and queues */
516*4882a593Smuzhiyun 	queue_count = BIT(dglort->rss_l + dglort->pc_l);
517*4882a593Smuzhiyun 	vsi_count = BIT(dglort->vsi_l + dglort->queue_l);
518*4882a593Smuzhiyun 	glort = dglort->glort;
519*4882a593Smuzhiyun 	q_idx = dglort->queue_b;
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun 	/* configure SGLORT for queues */
522*4882a593Smuzhiyun 	for (vsi = 0; vsi < vsi_count; vsi++, glort++) {
523*4882a593Smuzhiyun 		for (queue = 0; queue < queue_count; queue++, q_idx++) {
524*4882a593Smuzhiyun 			if (q_idx >= FM10K_MAX_QUEUES)
525*4882a593Smuzhiyun 				break;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TX_SGLORT(q_idx), glort);
528*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_RX_SGLORT(q_idx), glort);
529*4882a593Smuzhiyun 		}
530*4882a593Smuzhiyun 	}
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun 	/* determine count of PCs and queues */
533*4882a593Smuzhiyun 	queue_count = BIT(dglort->queue_l + dglort->rss_l + dglort->vsi_l);
534*4882a593Smuzhiyun 	pc_count = BIT(dglort->pc_l);
535*4882a593Smuzhiyun 
536*4882a593Smuzhiyun 	/* configure PC for Tx queues */
537*4882a593Smuzhiyun 	for (pc = 0; pc < pc_count; pc++) {
538*4882a593Smuzhiyun 		q_idx = pc + dglort->queue_b;
539*4882a593Smuzhiyun 		for (queue = 0; queue < queue_count; queue++) {
540*4882a593Smuzhiyun 			if (q_idx >= FM10K_MAX_QUEUES)
541*4882a593Smuzhiyun 				break;
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun 			txqctl = fm10k_read_reg(hw, FM10K_TXQCTL(q_idx));
544*4882a593Smuzhiyun 			txqctl &= ~FM10K_TXQCTL_PC_MASK;
545*4882a593Smuzhiyun 			txqctl |= pc << FM10K_TXQCTL_PC_SHIFT;
546*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TXQCTL(q_idx), txqctl);
547*4882a593Smuzhiyun 
548*4882a593Smuzhiyun 			q_idx += pc_count;
549*4882a593Smuzhiyun 		}
550*4882a593Smuzhiyun 	}
551*4882a593Smuzhiyun 
552*4882a593Smuzhiyun 	/* configure DGLORTDEC */
553*4882a593Smuzhiyun 	dglortdec = ((u32)(dglort->rss_l) << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) |
554*4882a593Smuzhiyun 		    ((u32)(dglort->queue_b) << FM10K_DGLORTDEC_QBASE_SHIFT) |
555*4882a593Smuzhiyun 		    ((u32)(dglort->pc_l) << FM10K_DGLORTDEC_PCLENGTH_SHIFT) |
556*4882a593Smuzhiyun 		    ((u32)(dglort->vsi_b) << FM10K_DGLORTDEC_VSIBASE_SHIFT) |
557*4882a593Smuzhiyun 		    ((u32)(dglort->vsi_l) << FM10K_DGLORTDEC_VSILENGTH_SHIFT) |
558*4882a593Smuzhiyun 		    ((u32)(dglort->queue_l));
559*4882a593Smuzhiyun 	if (dglort->inner_rss)
560*4882a593Smuzhiyun 		dglortdec |=  FM10K_DGLORTDEC_INNERRSS_ENABLE;
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	/* configure DGLORTMAP */
563*4882a593Smuzhiyun 	dglortmap = (dglort->idx == fm10k_dglort_default) ?
564*4882a593Smuzhiyun 			FM10K_DGLORTMAP_ANY : FM10K_DGLORTMAP_ZERO;
565*4882a593Smuzhiyun 	dglortmap <<= dglort->vsi_l + dglort->queue_l + dglort->shared_l;
566*4882a593Smuzhiyun 	dglortmap |= dglort->glort;
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	/* write values to hardware */
569*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DGLORTDEC(dglort->idx), dglortdec);
570*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_DGLORTMAP(dglort->idx), dglortmap);
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 	return 0;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun 
fm10k_queues_per_pool(struct fm10k_hw * hw)575*4882a593Smuzhiyun u16 fm10k_queues_per_pool(struct fm10k_hw *hw)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun 	u16 num_pools = hw->iov.num_pools;
578*4882a593Smuzhiyun 
579*4882a593Smuzhiyun 	return (num_pools > 32) ? 2 : (num_pools > 16) ? 4 : (num_pools > 8) ?
580*4882a593Smuzhiyun 	       8 : FM10K_MAX_QUEUES_POOL;
581*4882a593Smuzhiyun }
582*4882a593Smuzhiyun 
fm10k_vf_queue_index(struct fm10k_hw * hw,u16 vf_idx)583*4882a593Smuzhiyun u16 fm10k_vf_queue_index(struct fm10k_hw *hw, u16 vf_idx)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun 	u16 num_vfs = hw->iov.num_vfs;
586*4882a593Smuzhiyun 	u16 vf_q_idx = FM10K_MAX_QUEUES;
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	vf_q_idx -= fm10k_queues_per_pool(hw) * (num_vfs - vf_idx);
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun 	return vf_q_idx;
591*4882a593Smuzhiyun }
592*4882a593Smuzhiyun 
fm10k_vectors_per_pool(struct fm10k_hw * hw)593*4882a593Smuzhiyun static u16 fm10k_vectors_per_pool(struct fm10k_hw *hw)
594*4882a593Smuzhiyun {
595*4882a593Smuzhiyun 	u16 num_pools = hw->iov.num_pools;
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun 	return (num_pools > 32) ? 8 : (num_pools > 16) ? 16 :
598*4882a593Smuzhiyun 	       FM10K_MAX_VECTORS_POOL;
599*4882a593Smuzhiyun }
600*4882a593Smuzhiyun 
fm10k_vf_vector_index(struct fm10k_hw * hw,u16 vf_idx)601*4882a593Smuzhiyun static u16 fm10k_vf_vector_index(struct fm10k_hw *hw, u16 vf_idx)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun 	u16 vf_v_idx = FM10K_MAX_VECTORS_PF;
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun 	vf_v_idx += fm10k_vectors_per_pool(hw) * vf_idx;
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun 	return vf_v_idx;
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun 
610*4882a593Smuzhiyun /**
611*4882a593Smuzhiyun  *  fm10k_iov_assign_resources_pf - Assign pool resources for virtualization
612*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
613*4882a593Smuzhiyun  *  @num_vfs: number of VFs to be allocated
614*4882a593Smuzhiyun  *  @num_pools: number of virtualization pools to be allocated
615*4882a593Smuzhiyun  *
616*4882a593Smuzhiyun  *  Allocates queues and traffic classes to virtualization entities to prepare
617*4882a593Smuzhiyun  *  the PF for SR-IOV and VMDq
618*4882a593Smuzhiyun  **/
fm10k_iov_assign_resources_pf(struct fm10k_hw * hw,u16 num_vfs,u16 num_pools)619*4882a593Smuzhiyun static s32 fm10k_iov_assign_resources_pf(struct fm10k_hw *hw, u16 num_vfs,
620*4882a593Smuzhiyun 					 u16 num_pools)
621*4882a593Smuzhiyun {
622*4882a593Smuzhiyun 	u16 qmap_stride, qpp, vpp, vf_q_idx, vf_q_idx0, qmap_idx;
623*4882a593Smuzhiyun 	u32 vid = hw->mac.default_vid << FM10K_TXQCTL_VID_SHIFT;
624*4882a593Smuzhiyun 	int i, j;
625*4882a593Smuzhiyun 
626*4882a593Smuzhiyun 	/* hardware only supports up to 64 pools */
627*4882a593Smuzhiyun 	if (num_pools > 64)
628*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun 	/* the number of VFs cannot exceed the number of pools */
631*4882a593Smuzhiyun 	if ((num_vfs > num_pools) || (num_vfs > hw->iov.total_vfs))
632*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun 	/* record number of virtualization entities */
635*4882a593Smuzhiyun 	hw->iov.num_vfs = num_vfs;
636*4882a593Smuzhiyun 	hw->iov.num_pools = num_pools;
637*4882a593Smuzhiyun 
638*4882a593Smuzhiyun 	/* determine qmap offsets and counts */
639*4882a593Smuzhiyun 	qmap_stride = (num_vfs > 8) ? 32 : 256;
640*4882a593Smuzhiyun 	qpp = fm10k_queues_per_pool(hw);
641*4882a593Smuzhiyun 	vpp = fm10k_vectors_per_pool(hw);
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 	/* calculate starting index for queues */
644*4882a593Smuzhiyun 	vf_q_idx = fm10k_vf_queue_index(hw, 0);
645*4882a593Smuzhiyun 	qmap_idx = 0;
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun 	/* establish TCs with -1 credits and no quanta to prevent transmit */
648*4882a593Smuzhiyun 	for (i = 0; i < num_vfs; i++) {
649*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(i), 0);
650*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TC_RATE(i), 0);
651*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TC_CREDIT(i),
652*4882a593Smuzhiyun 				FM10K_TC_CREDIT_CREDIT_MASK);
653*4882a593Smuzhiyun 	}
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	/* zero out all mbmem registers */
656*4882a593Smuzhiyun 	for (i = FM10K_VFMBMEM_LEN * num_vfs; i--;)
657*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_MBMEM(i), 0);
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun 	/* clear event notification of VF FLR */
660*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_PFVFLREC(0), ~0);
661*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_PFVFLREC(1), ~0);
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun 	/* loop through unallocated rings assigning them back to PF */
664*4882a593Smuzhiyun 	for (i = FM10K_MAX_QUEUES_PF; i < vf_q_idx; i++) {
665*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
666*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXQCTL(i), FM10K_TXQCTL_PF |
667*4882a593Smuzhiyun 				FM10K_TXQCTL_UNLIMITED_BW | vid);
668*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RXQCTL(i), FM10K_RXQCTL_PF);
669*4882a593Smuzhiyun 	}
670*4882a593Smuzhiyun 
671*4882a593Smuzhiyun 	/* PF should have already updated VFITR2[0] */
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun 	/* update all ITR registers to flow to VFITR2[0] */
674*4882a593Smuzhiyun 	for (i = FM10K_ITR_REG_COUNT_PF + 1; i < FM10K_ITR_REG_COUNT; i++) {
675*4882a593Smuzhiyun 		if (!(i & (vpp - 1)))
676*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_ITR2(i), i - vpp);
677*4882a593Smuzhiyun 		else
678*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_ITR2(i), i - 1);
679*4882a593Smuzhiyun 	}
680*4882a593Smuzhiyun 
681*4882a593Smuzhiyun 	/* update PF ITR2[0] to reference the last vector */
682*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_ITR2(0),
683*4882a593Smuzhiyun 			fm10k_vf_vector_index(hw, num_vfs - 1));
684*4882a593Smuzhiyun 
685*4882a593Smuzhiyun 	/* loop through rings populating rings and TCs */
686*4882a593Smuzhiyun 	for (i = 0; i < num_vfs; i++) {
687*4882a593Smuzhiyun 		/* record index for VF queue 0 for use in end of loop */
688*4882a593Smuzhiyun 		vf_q_idx0 = vf_q_idx;
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 		for (j = 0; j < qpp; j++, qmap_idx++, vf_q_idx++) {
691*4882a593Smuzhiyun 			/* assign VF and locked TC to queues */
692*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
693*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx),
694*4882a593Smuzhiyun 					(i << FM10K_TXQCTL_TC_SHIFT) | i |
695*4882a593Smuzhiyun 					FM10K_TXQCTL_VF | vid);
696*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_RXDCTL(vf_q_idx),
697*4882a593Smuzhiyun 					FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
698*4882a593Smuzhiyun 					FM10K_RXDCTL_DROP_ON_EMPTY);
699*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_RXQCTL(vf_q_idx),
700*4882a593Smuzhiyun 					(i << FM10K_RXQCTL_VF_SHIFT) |
701*4882a593Smuzhiyun 					FM10K_RXQCTL_VF);
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 			/* map queue pair to VF */
704*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
705*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx);
706*4882a593Smuzhiyun 		}
707*4882a593Smuzhiyun 
708*4882a593Smuzhiyun 		/* repeat the first ring for all of the remaining VF rings */
709*4882a593Smuzhiyun 		for (; j < qmap_stride; j++, qmap_idx++) {
710*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx0);
711*4882a593Smuzhiyun 			fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), vf_q_idx0);
712*4882a593Smuzhiyun 		}
713*4882a593Smuzhiyun 	}
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun 	/* loop through remaining indexes assigning all to queue 0 */
716*4882a593Smuzhiyun 	while (qmap_idx < FM10K_TQMAP_TABLE_SIZE) {
717*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
718*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx), 0);
719*4882a593Smuzhiyun 		qmap_idx++;
720*4882a593Smuzhiyun 	}
721*4882a593Smuzhiyun 
722*4882a593Smuzhiyun 	return 0;
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun 
725*4882a593Smuzhiyun /**
726*4882a593Smuzhiyun  *  fm10k_iov_configure_tc_pf - Configure the shaping group for VF
727*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
728*4882a593Smuzhiyun  *  @vf_idx: index of VF receiving GLORT
729*4882a593Smuzhiyun  *  @rate: Rate indicated in Mb/s
730*4882a593Smuzhiyun  *
731*4882a593Smuzhiyun  *  Configured the TC for a given VF to allow only up to a given number
732*4882a593Smuzhiyun  *  of Mb/s of outgoing Tx throughput.
733*4882a593Smuzhiyun  **/
fm10k_iov_configure_tc_pf(struct fm10k_hw * hw,u16 vf_idx,int rate)734*4882a593Smuzhiyun static s32 fm10k_iov_configure_tc_pf(struct fm10k_hw *hw, u16 vf_idx, int rate)
735*4882a593Smuzhiyun {
736*4882a593Smuzhiyun 	/* configure defaults */
737*4882a593Smuzhiyun 	u32 interval = FM10K_TC_RATE_INTERVAL_4US_GEN3;
738*4882a593Smuzhiyun 	u32 tc_rate = FM10K_TC_RATE_QUANTA_MASK;
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun 	/* verify vf is in range */
741*4882a593Smuzhiyun 	if (vf_idx >= hw->iov.num_vfs)
742*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun 	/* set interval to align with 4.096 usec in all modes */
745*4882a593Smuzhiyun 	switch (hw->bus.speed) {
746*4882a593Smuzhiyun 	case fm10k_bus_speed_2500:
747*4882a593Smuzhiyun 		interval = FM10K_TC_RATE_INTERVAL_4US_GEN1;
748*4882a593Smuzhiyun 		break;
749*4882a593Smuzhiyun 	case fm10k_bus_speed_5000:
750*4882a593Smuzhiyun 		interval = FM10K_TC_RATE_INTERVAL_4US_GEN2;
751*4882a593Smuzhiyun 		break;
752*4882a593Smuzhiyun 	default:
753*4882a593Smuzhiyun 		break;
754*4882a593Smuzhiyun 	}
755*4882a593Smuzhiyun 
756*4882a593Smuzhiyun 	if (rate) {
757*4882a593Smuzhiyun 		if (rate > FM10K_VF_TC_MAX || rate < FM10K_VF_TC_MIN)
758*4882a593Smuzhiyun 			return FM10K_ERR_PARAM;
759*4882a593Smuzhiyun 
760*4882a593Smuzhiyun 		/* The quanta is measured in Bytes per 4.096 or 8.192 usec
761*4882a593Smuzhiyun 		 * The rate is provided in Mbits per second
762*4882a593Smuzhiyun 		 * To tralslate from rate to quanta we need to multiply the
763*4882a593Smuzhiyun 		 * rate by 8.192 usec and divide by 8 bits/byte.  To avoid
764*4882a593Smuzhiyun 		 * dealing with floating point we can round the values up
765*4882a593Smuzhiyun 		 * to the nearest whole number ratio which gives us 128 / 125.
766*4882a593Smuzhiyun 		 */
767*4882a593Smuzhiyun 		tc_rate = (rate * 128) / 125;
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun 		/* try to keep the rate limiting accurate by increasing
770*4882a593Smuzhiyun 		 * the number of credits and interval for rates less than 4Gb/s
771*4882a593Smuzhiyun 		 */
772*4882a593Smuzhiyun 		if (rate < 4000)
773*4882a593Smuzhiyun 			interval <<= 1;
774*4882a593Smuzhiyun 		else
775*4882a593Smuzhiyun 			tc_rate >>= 1;
776*4882a593Smuzhiyun 	}
777*4882a593Smuzhiyun 
778*4882a593Smuzhiyun 	/* update rate limiter with new values */
779*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), tc_rate | interval);
780*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
781*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx), FM10K_TC_MAXCREDIT_64K);
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun 	return 0;
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun /**
787*4882a593Smuzhiyun  *  fm10k_iov_assign_int_moderator_pf - Add VF interrupts to moderator list
788*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
789*4882a593Smuzhiyun  *  @vf_idx: index of VF receiving GLORT
790*4882a593Smuzhiyun  *
791*4882a593Smuzhiyun  *  Update the interrupt moderator linked list to include any MSI-X
792*4882a593Smuzhiyun  *  interrupts which the VF has enabled in the MSI-X vector table.
793*4882a593Smuzhiyun  **/
fm10k_iov_assign_int_moderator_pf(struct fm10k_hw * hw,u16 vf_idx)794*4882a593Smuzhiyun static s32 fm10k_iov_assign_int_moderator_pf(struct fm10k_hw *hw, u16 vf_idx)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun 	u16 vf_v_idx, vf_v_limit, i;
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun 	/* verify vf is in range */
799*4882a593Smuzhiyun 	if (vf_idx >= hw->iov.num_vfs)
800*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun 	/* determine vector offset and count */
803*4882a593Smuzhiyun 	vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
804*4882a593Smuzhiyun 	vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
805*4882a593Smuzhiyun 
806*4882a593Smuzhiyun 	/* search for first vector that is not masked */
807*4882a593Smuzhiyun 	for (i = vf_v_limit - 1; i > vf_v_idx; i--) {
808*4882a593Smuzhiyun 		if (!fm10k_read_reg(hw, FM10K_MSIX_VECTOR_MASK(i)))
809*4882a593Smuzhiyun 			break;
810*4882a593Smuzhiyun 	}
811*4882a593Smuzhiyun 
812*4882a593Smuzhiyun 	/* reset linked list so it now includes our active vectors */
813*4882a593Smuzhiyun 	if (vf_idx == (hw->iov.num_vfs - 1))
814*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(0), i);
815*4882a593Smuzhiyun 	else
816*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), i);
817*4882a593Smuzhiyun 
818*4882a593Smuzhiyun 	return 0;
819*4882a593Smuzhiyun }
820*4882a593Smuzhiyun 
821*4882a593Smuzhiyun /**
822*4882a593Smuzhiyun  *  fm10k_iov_assign_default_mac_vlan_pf - Assign a MAC and VLAN to VF
823*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
824*4882a593Smuzhiyun  *  @vf_info: pointer to VF information structure
825*4882a593Smuzhiyun  *
826*4882a593Smuzhiyun  *  Assign a MAC address and default VLAN to a VF and notify it of the update
827*4882a593Smuzhiyun  **/
fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw * hw,struct fm10k_vf_info * vf_info)828*4882a593Smuzhiyun static s32 fm10k_iov_assign_default_mac_vlan_pf(struct fm10k_hw *hw,
829*4882a593Smuzhiyun 						struct fm10k_vf_info *vf_info)
830*4882a593Smuzhiyun {
831*4882a593Smuzhiyun 	u16 qmap_stride, queues_per_pool, vf_q_idx, timeout, qmap_idx, i;
832*4882a593Smuzhiyun 	u32 msg[4], txdctl, txqctl, tdbal = 0, tdbah = 0;
833*4882a593Smuzhiyun 	s32 err = 0;
834*4882a593Smuzhiyun 	u16 vf_idx, vf_vid;
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 	/* verify vf is in range */
837*4882a593Smuzhiyun 	if (!vf_info || vf_info->vf_idx >= hw->iov.num_vfs)
838*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
839*4882a593Smuzhiyun 
840*4882a593Smuzhiyun 	/* determine qmap offsets and counts */
841*4882a593Smuzhiyun 	qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
842*4882a593Smuzhiyun 	queues_per_pool = fm10k_queues_per_pool(hw);
843*4882a593Smuzhiyun 
844*4882a593Smuzhiyun 	/* calculate starting index for queues */
845*4882a593Smuzhiyun 	vf_idx = vf_info->vf_idx;
846*4882a593Smuzhiyun 	vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
847*4882a593Smuzhiyun 	qmap_idx = qmap_stride * vf_idx;
848*4882a593Smuzhiyun 
849*4882a593Smuzhiyun 	/* Determine correct default VLAN ID. The FM10K_VLAN_OVERRIDE bit is
850*4882a593Smuzhiyun 	 * used here to indicate to the VF that it will not have privilege to
851*4882a593Smuzhiyun 	 * write VLAN_TABLE. All policy is enforced on the PF but this allows
852*4882a593Smuzhiyun 	 * the VF to correctly report errors to userspace requests.
853*4882a593Smuzhiyun 	 */
854*4882a593Smuzhiyun 	if (vf_info->pf_vid)
855*4882a593Smuzhiyun 		vf_vid = vf_info->pf_vid | FM10K_VLAN_OVERRIDE;
856*4882a593Smuzhiyun 	else
857*4882a593Smuzhiyun 		vf_vid = vf_info->sw_vid;
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun 	/* generate MAC_ADDR request */
860*4882a593Smuzhiyun 	fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
861*4882a593Smuzhiyun 	fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_DEFAULT_MAC,
862*4882a593Smuzhiyun 				    vf_info->mac, vf_vid);
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun 	/* Configure Queue control register with new VLAN ID. The TXQCTL
865*4882a593Smuzhiyun 	 * register is RO from the VF, so the PF must do this even in the
866*4882a593Smuzhiyun 	 * case of notifying the VF of a new VID via the mailbox.
867*4882a593Smuzhiyun 	 */
868*4882a593Smuzhiyun 	txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) &
869*4882a593Smuzhiyun 		 FM10K_TXQCTL_VID_MASK;
870*4882a593Smuzhiyun 	txqctl |= (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
871*4882a593Smuzhiyun 		  FM10K_TXQCTL_VF | vf_idx;
872*4882a593Smuzhiyun 
873*4882a593Smuzhiyun 	for (i = 0; i < queues_per_pool; i++)
874*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXQCTL(vf_q_idx + i), txqctl);
875*4882a593Smuzhiyun 
876*4882a593Smuzhiyun 	/* try loading a message onto outgoing mailbox first */
877*4882a593Smuzhiyun 	if (vf_info->mbx.ops.enqueue_tx) {
878*4882a593Smuzhiyun 		err = vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
879*4882a593Smuzhiyun 		if (err != FM10K_MBX_ERR_NO_MBX)
880*4882a593Smuzhiyun 			return err;
881*4882a593Smuzhiyun 		err = 0;
882*4882a593Smuzhiyun 	}
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun 	/* If we aren't connected to a mailbox, this is most likely because
885*4882a593Smuzhiyun 	 * the VF driver is not running. It should thus be safe to re-map
886*4882a593Smuzhiyun 	 * queues and use the registers to pass the MAC address so that the VF
887*4882a593Smuzhiyun 	 * driver gets correct information during its initialization.
888*4882a593Smuzhiyun 	 */
889*4882a593Smuzhiyun 
890*4882a593Smuzhiyun 	/* MAP Tx queue back to 0 temporarily, and disable it */
891*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), 0);
892*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TXDCTL(vf_q_idx), 0);
893*4882a593Smuzhiyun 
894*4882a593Smuzhiyun 	/* verify ring has disabled before modifying base address registers */
895*4882a593Smuzhiyun 	txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
896*4882a593Smuzhiyun 	for (timeout = 0; txdctl & FM10K_TXDCTL_ENABLE; timeout++) {
897*4882a593Smuzhiyun 		/* limit ourselves to a 1ms timeout */
898*4882a593Smuzhiyun 		if (timeout == 10) {
899*4882a593Smuzhiyun 			err = FM10K_ERR_DMA_PENDING;
900*4882a593Smuzhiyun 			goto err_out;
901*4882a593Smuzhiyun 		}
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun 		usleep_range(100, 200);
904*4882a593Smuzhiyun 		txdctl = fm10k_read_reg(hw, FM10K_TXDCTL(vf_q_idx));
905*4882a593Smuzhiyun 	}
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun 	/* Update base address registers to contain MAC address */
908*4882a593Smuzhiyun 	if (is_valid_ether_addr(vf_info->mac)) {
909*4882a593Smuzhiyun 		tdbal = (((u32)vf_info->mac[3]) << 24) |
910*4882a593Smuzhiyun 			(((u32)vf_info->mac[4]) << 16) |
911*4882a593Smuzhiyun 			(((u32)vf_info->mac[5]) << 8);
912*4882a593Smuzhiyun 
913*4882a593Smuzhiyun 		tdbah = (((u32)0xFF)	        << 24) |
914*4882a593Smuzhiyun 			(((u32)vf_info->mac[0]) << 16) |
915*4882a593Smuzhiyun 			(((u32)vf_info->mac[1]) << 8) |
916*4882a593Smuzhiyun 			((u32)vf_info->mac[2]);
917*4882a593Smuzhiyun 	}
918*4882a593Smuzhiyun 
919*4882a593Smuzhiyun 	/* Record the base address into queue 0 */
920*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx), tdbal);
921*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx), tdbah);
922*4882a593Smuzhiyun 
923*4882a593Smuzhiyun 	/* Provide the VF the ITR scale, using software-defined fields in TDLEN
924*4882a593Smuzhiyun 	 * to pass the information during VF initialization. See definition of
925*4882a593Smuzhiyun 	 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details.
926*4882a593Smuzhiyun 	 */
927*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx), hw->mac.itr_scale <<
928*4882a593Smuzhiyun 						   FM10K_TDLEN_ITR_SCALE_SHIFT);
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun err_out:
931*4882a593Smuzhiyun 	/* restore the queue back to VF ownership */
932*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx), vf_q_idx);
933*4882a593Smuzhiyun 	return err;
934*4882a593Smuzhiyun }
935*4882a593Smuzhiyun 
936*4882a593Smuzhiyun /**
937*4882a593Smuzhiyun  *  fm10k_iov_reset_resources_pf - Reassign queues and interrupts to a VF
938*4882a593Smuzhiyun  *  @hw: pointer to the HW structure
939*4882a593Smuzhiyun  *  @vf_info: pointer to VF information structure
940*4882a593Smuzhiyun  *
941*4882a593Smuzhiyun  *  Reassign the interrupts and queues to a VF following an FLR
942*4882a593Smuzhiyun  **/
fm10k_iov_reset_resources_pf(struct fm10k_hw * hw,struct fm10k_vf_info * vf_info)943*4882a593Smuzhiyun static s32 fm10k_iov_reset_resources_pf(struct fm10k_hw *hw,
944*4882a593Smuzhiyun 					struct fm10k_vf_info *vf_info)
945*4882a593Smuzhiyun {
946*4882a593Smuzhiyun 	u16 qmap_stride, queues_per_pool, vf_q_idx, qmap_idx;
947*4882a593Smuzhiyun 	u32 tdbal = 0, tdbah = 0, txqctl, rxqctl;
948*4882a593Smuzhiyun 	u16 vf_v_idx, vf_v_limit, vf_vid;
949*4882a593Smuzhiyun 	u8 vf_idx = vf_info->vf_idx;
950*4882a593Smuzhiyun 	int i;
951*4882a593Smuzhiyun 
952*4882a593Smuzhiyun 	/* verify vf is in range */
953*4882a593Smuzhiyun 	if (vf_idx >= hw->iov.num_vfs)
954*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
955*4882a593Smuzhiyun 
956*4882a593Smuzhiyun 	/* clear event notification of VF FLR */
957*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_PFVFLREC(vf_idx / 32), BIT(vf_idx % 32));
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun 	/* force timeout and then disconnect the mailbox */
960*4882a593Smuzhiyun 	vf_info->mbx.timeout = 0;
961*4882a593Smuzhiyun 	if (vf_info->mbx.ops.disconnect)
962*4882a593Smuzhiyun 		vf_info->mbx.ops.disconnect(hw, &vf_info->mbx);
963*4882a593Smuzhiyun 
964*4882a593Smuzhiyun 	/* determine vector offset and count */
965*4882a593Smuzhiyun 	vf_v_idx = fm10k_vf_vector_index(hw, vf_idx);
966*4882a593Smuzhiyun 	vf_v_limit = vf_v_idx + fm10k_vectors_per_pool(hw);
967*4882a593Smuzhiyun 
968*4882a593Smuzhiyun 	/* determine qmap offsets and counts */
969*4882a593Smuzhiyun 	qmap_stride = (hw->iov.num_vfs > 8) ? 32 : 256;
970*4882a593Smuzhiyun 	queues_per_pool = fm10k_queues_per_pool(hw);
971*4882a593Smuzhiyun 	qmap_idx = qmap_stride * vf_idx;
972*4882a593Smuzhiyun 
973*4882a593Smuzhiyun 	/* make all the queues inaccessible to the VF */
974*4882a593Smuzhiyun 	for (i = qmap_idx; i < (qmap_idx + qmap_stride); i++) {
975*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQMAP(i), 0);
976*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RQMAP(i), 0);
977*4882a593Smuzhiyun 	}
978*4882a593Smuzhiyun 
979*4882a593Smuzhiyun 	/* calculate starting index for queues */
980*4882a593Smuzhiyun 	vf_q_idx = fm10k_vf_queue_index(hw, vf_idx);
981*4882a593Smuzhiyun 
982*4882a593Smuzhiyun 	/* determine correct default VLAN ID */
983*4882a593Smuzhiyun 	if (vf_info->pf_vid)
984*4882a593Smuzhiyun 		vf_vid = vf_info->pf_vid;
985*4882a593Smuzhiyun 	else
986*4882a593Smuzhiyun 		vf_vid = vf_info->sw_vid;
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun 	/* configure Queue control register */
989*4882a593Smuzhiyun 	txqctl = ((u32)vf_vid << FM10K_TXQCTL_VID_SHIFT) |
990*4882a593Smuzhiyun 		 (vf_idx << FM10K_TXQCTL_TC_SHIFT) |
991*4882a593Smuzhiyun 		 FM10K_TXQCTL_VF | vf_idx;
992*4882a593Smuzhiyun 	rxqctl = (vf_idx << FM10K_RXQCTL_VF_SHIFT) | FM10K_RXQCTL_VF;
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun 	/* stop further DMA and reset queue ownership back to VF */
995*4882a593Smuzhiyun 	for (i = vf_q_idx; i < (queues_per_pool + vf_q_idx); i++) {
996*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXDCTL(i), 0);
997*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TXQCTL(i), txqctl);
998*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RXDCTL(i),
999*4882a593Smuzhiyun 				FM10K_RXDCTL_WRITE_BACK_MIN_DELAY |
1000*4882a593Smuzhiyun 				FM10K_RXDCTL_DROP_ON_EMPTY);
1001*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RXQCTL(i), rxqctl);
1002*4882a593Smuzhiyun 	}
1003*4882a593Smuzhiyun 
1004*4882a593Smuzhiyun 	/* reset TC with -1 credits and no quanta to prevent transmit */
1005*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_MAXCREDIT(vf_idx), 0);
1006*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_RATE(vf_idx), 0);
1007*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_TC_CREDIT(vf_idx),
1008*4882a593Smuzhiyun 			FM10K_TC_CREDIT_CREDIT_MASK);
1009*4882a593Smuzhiyun 
1010*4882a593Smuzhiyun 	/* update our first entry in the table based on previous VF */
1011*4882a593Smuzhiyun 	if (!vf_idx)
1012*4882a593Smuzhiyun 		hw->mac.ops.update_int_moderator(hw);
1013*4882a593Smuzhiyun 	else
1014*4882a593Smuzhiyun 		hw->iov.ops.assign_int_moderator(hw, vf_idx - 1);
1015*4882a593Smuzhiyun 
1016*4882a593Smuzhiyun 	/* reset linked list so it now includes our active vectors */
1017*4882a593Smuzhiyun 	if (vf_idx == (hw->iov.num_vfs - 1))
1018*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(0), vf_v_idx);
1019*4882a593Smuzhiyun 	else
1020*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_limit), vf_v_idx);
1021*4882a593Smuzhiyun 
1022*4882a593Smuzhiyun 	/* link remaining vectors so that next points to previous */
1023*4882a593Smuzhiyun 	for (vf_v_idx++; vf_v_idx < vf_v_limit; vf_v_idx++)
1024*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_ITR2(vf_v_idx), vf_v_idx - 1);
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun 	/* zero out MBMEM, VLAN_TABLE, RETA, RSSRK, and MRQC registers */
1027*4882a593Smuzhiyun 	for (i = FM10K_VFMBMEM_LEN; i--;)
1028*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_MBMEM_VF(vf_idx, i), 0);
1029*4882a593Smuzhiyun 	for (i = FM10K_VLAN_TABLE_SIZE; i--;)
1030*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_VLAN_TABLE(vf_info->vsi, i), 0);
1031*4882a593Smuzhiyun 	for (i = FM10K_RETA_SIZE; i--;)
1032*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RETA(vf_info->vsi, i), 0);
1033*4882a593Smuzhiyun 	for (i = FM10K_RSSRK_SIZE; i--;)
1034*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RSSRK(vf_info->vsi, i), 0);
1035*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_MRQC(vf_info->vsi), 0);
1036*4882a593Smuzhiyun 
1037*4882a593Smuzhiyun 	/* Update base address registers to contain MAC address */
1038*4882a593Smuzhiyun 	if (is_valid_ether_addr(vf_info->mac)) {
1039*4882a593Smuzhiyun 		tdbal = (((u32)vf_info->mac[3]) << 24) |
1040*4882a593Smuzhiyun 			(((u32)vf_info->mac[4]) << 16) |
1041*4882a593Smuzhiyun 			(((u32)vf_info->mac[5]) << 8);
1042*4882a593Smuzhiyun 		tdbah = (((u32)0xFF)	   << 24) |
1043*4882a593Smuzhiyun 			(((u32)vf_info->mac[0]) << 16) |
1044*4882a593Smuzhiyun 			(((u32)vf_info->mac[1]) << 8) |
1045*4882a593Smuzhiyun 			((u32)vf_info->mac[2]);
1046*4882a593Smuzhiyun 	}
1047*4882a593Smuzhiyun 
1048*4882a593Smuzhiyun 	/* map queue pairs back to VF from last to first */
1049*4882a593Smuzhiyun 	for (i = queues_per_pool; i--;) {
1050*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TDBAL(vf_q_idx + i), tdbal);
1051*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TDBAH(vf_q_idx + i), tdbah);
1052*4882a593Smuzhiyun 		/* See definition of FM10K_TDLEN_ITR_SCALE_SHIFT for an
1053*4882a593Smuzhiyun 		 * explanation of how TDLEN is used.
1054*4882a593Smuzhiyun 		 */
1055*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TDLEN(vf_q_idx + i),
1056*4882a593Smuzhiyun 				hw->mac.itr_scale <<
1057*4882a593Smuzhiyun 				FM10K_TDLEN_ITR_SCALE_SHIFT);
1058*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx + i);
1059*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx + i);
1060*4882a593Smuzhiyun 	}
1061*4882a593Smuzhiyun 
1062*4882a593Smuzhiyun 	/* repeat the first ring for all the remaining VF rings */
1063*4882a593Smuzhiyun 	for (i = queues_per_pool; i < qmap_stride; i++) {
1064*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_TQMAP(qmap_idx + i), vf_q_idx);
1065*4882a593Smuzhiyun 		fm10k_write_reg(hw, FM10K_RQMAP(qmap_idx + i), vf_q_idx);
1066*4882a593Smuzhiyun 	}
1067*4882a593Smuzhiyun 
1068*4882a593Smuzhiyun 	return 0;
1069*4882a593Smuzhiyun }
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun /**
1072*4882a593Smuzhiyun  *  fm10k_iov_set_lport_pf - Assign and enable a logical port for a given VF
1073*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1074*4882a593Smuzhiyun  *  @vf_info: pointer to VF information structure
1075*4882a593Smuzhiyun  *  @lport_idx: Logical port offset from the hardware glort
1076*4882a593Smuzhiyun  *  @flags: Set of capability flags to extend port beyond basic functionality
1077*4882a593Smuzhiyun  *
1078*4882a593Smuzhiyun  *  This function allows enabling a VF port by assigning it a GLORT and
1079*4882a593Smuzhiyun  *  setting the flags so that it can enable an Rx mode.
1080*4882a593Smuzhiyun  **/
fm10k_iov_set_lport_pf(struct fm10k_hw * hw,struct fm10k_vf_info * vf_info,u16 lport_idx,u8 flags)1081*4882a593Smuzhiyun static s32 fm10k_iov_set_lport_pf(struct fm10k_hw *hw,
1082*4882a593Smuzhiyun 				  struct fm10k_vf_info *vf_info,
1083*4882a593Smuzhiyun 				  u16 lport_idx, u8 flags)
1084*4882a593Smuzhiyun {
1085*4882a593Smuzhiyun 	u16 glort = (hw->mac.dglort_map + lport_idx) & FM10K_DGLORTMAP_NONE;
1086*4882a593Smuzhiyun 
1087*4882a593Smuzhiyun 	/* if glort is not valid return error */
1088*4882a593Smuzhiyun 	if (!fm10k_glort_valid_pf(hw, glort))
1089*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1090*4882a593Smuzhiyun 
1091*4882a593Smuzhiyun 	vf_info->vf_flags = flags | FM10K_VF_FLAG_NONE_CAPABLE;
1092*4882a593Smuzhiyun 	vf_info->glort = glort;
1093*4882a593Smuzhiyun 
1094*4882a593Smuzhiyun 	return 0;
1095*4882a593Smuzhiyun }
1096*4882a593Smuzhiyun 
1097*4882a593Smuzhiyun /**
1098*4882a593Smuzhiyun  *  fm10k_iov_reset_lport_pf - Disable a logical port for a given VF
1099*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1100*4882a593Smuzhiyun  *  @vf_info: pointer to VF information structure
1101*4882a593Smuzhiyun  *
1102*4882a593Smuzhiyun  *  This function disables a VF port by stripping it of a GLORT and
1103*4882a593Smuzhiyun  *  setting the flags so that it cannot enable any Rx mode.
1104*4882a593Smuzhiyun  **/
fm10k_iov_reset_lport_pf(struct fm10k_hw * hw,struct fm10k_vf_info * vf_info)1105*4882a593Smuzhiyun static void fm10k_iov_reset_lport_pf(struct fm10k_hw *hw,
1106*4882a593Smuzhiyun 				     struct fm10k_vf_info *vf_info)
1107*4882a593Smuzhiyun {
1108*4882a593Smuzhiyun 	u32 msg[1];
1109*4882a593Smuzhiyun 
1110*4882a593Smuzhiyun 	/* need to disable the port if it is already enabled */
1111*4882a593Smuzhiyun 	if (FM10K_VF_FLAG_ENABLED(vf_info)) {
1112*4882a593Smuzhiyun 		/* notify switch that this port has been disabled */
1113*4882a593Smuzhiyun 		fm10k_update_lport_state_pf(hw, vf_info->glort, 1, false);
1114*4882a593Smuzhiyun 
1115*4882a593Smuzhiyun 		/* generate port state response to notify VF it is not ready */
1116*4882a593Smuzhiyun 		fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1117*4882a593Smuzhiyun 		vf_info->mbx.ops.enqueue_tx(hw, &vf_info->mbx, msg);
1118*4882a593Smuzhiyun 	}
1119*4882a593Smuzhiyun 
1120*4882a593Smuzhiyun 	/* clear flags and glort if it exists */
1121*4882a593Smuzhiyun 	vf_info->vf_flags = 0;
1122*4882a593Smuzhiyun 	vf_info->glort = 0;
1123*4882a593Smuzhiyun }
1124*4882a593Smuzhiyun 
1125*4882a593Smuzhiyun /**
1126*4882a593Smuzhiyun  *  fm10k_iov_update_stats_pf - Updates hardware related statistics for VFs
1127*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1128*4882a593Smuzhiyun  *  @q: stats for all queues of a VF
1129*4882a593Smuzhiyun  *  @vf_idx: index of VF
1130*4882a593Smuzhiyun  *
1131*4882a593Smuzhiyun  *  This function collects queue stats for VFs.
1132*4882a593Smuzhiyun  **/
fm10k_iov_update_stats_pf(struct fm10k_hw * hw,struct fm10k_hw_stats_q * q,u16 vf_idx)1133*4882a593Smuzhiyun static void fm10k_iov_update_stats_pf(struct fm10k_hw *hw,
1134*4882a593Smuzhiyun 				      struct fm10k_hw_stats_q *q,
1135*4882a593Smuzhiyun 				      u16 vf_idx)
1136*4882a593Smuzhiyun {
1137*4882a593Smuzhiyun 	u32 idx, qpp;
1138*4882a593Smuzhiyun 
1139*4882a593Smuzhiyun 	/* get stats for all of the queues */
1140*4882a593Smuzhiyun 	qpp = fm10k_queues_per_pool(hw);
1141*4882a593Smuzhiyun 	idx = fm10k_vf_queue_index(hw, vf_idx);
1142*4882a593Smuzhiyun 	fm10k_update_hw_stats_q(hw, q, idx, qpp);
1143*4882a593Smuzhiyun }
1144*4882a593Smuzhiyun 
1145*4882a593Smuzhiyun /**
1146*4882a593Smuzhiyun  *  fm10k_iov_msg_msix_pf - Message handler for MSI-X request from VF
1147*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1148*4882a593Smuzhiyun  *  @results: Pointer array to message, results[0] is pointer to message
1149*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1150*4882a593Smuzhiyun  *
1151*4882a593Smuzhiyun  *  This function is a default handler for MSI-X requests from the VF. The
1152*4882a593Smuzhiyun  *  assumption is that in this case it is acceptable to just directly
1153*4882a593Smuzhiyun  *  hand off the message from the VF to the underlying shared code.
1154*4882a593Smuzhiyun  **/
fm10k_iov_msg_msix_pf(struct fm10k_hw * hw,u32 __always_unused ** results,struct fm10k_mbx_info * mbx)1155*4882a593Smuzhiyun s32 fm10k_iov_msg_msix_pf(struct fm10k_hw *hw, u32 __always_unused **results,
1156*4882a593Smuzhiyun 			  struct fm10k_mbx_info *mbx)
1157*4882a593Smuzhiyun {
1158*4882a593Smuzhiyun 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1159*4882a593Smuzhiyun 	u8 vf_idx = vf_info->vf_idx;
1160*4882a593Smuzhiyun 
1161*4882a593Smuzhiyun 	return hw->iov.ops.assign_int_moderator(hw, vf_idx);
1162*4882a593Smuzhiyun }
1163*4882a593Smuzhiyun 
1164*4882a593Smuzhiyun /**
1165*4882a593Smuzhiyun  * fm10k_iov_select_vid - Select correct default VLAN ID
1166*4882a593Smuzhiyun  * @vf_info: pointer to VF information structure
1167*4882a593Smuzhiyun  * @vid: VLAN ID to correct
1168*4882a593Smuzhiyun  *
1169*4882a593Smuzhiyun  * Will report an error if the VLAN ID is out of range. For VID = 0, it will
1170*4882a593Smuzhiyun  * return either the pf_vid or sw_vid depending on which one is set.
1171*4882a593Smuzhiyun  */
fm10k_iov_select_vid(struct fm10k_vf_info * vf_info,u16 vid)1172*4882a593Smuzhiyun s32 fm10k_iov_select_vid(struct fm10k_vf_info *vf_info, u16 vid)
1173*4882a593Smuzhiyun {
1174*4882a593Smuzhiyun 	if (!vid)
1175*4882a593Smuzhiyun 		return vf_info->pf_vid ? vf_info->pf_vid : vf_info->sw_vid;
1176*4882a593Smuzhiyun 	else if (vf_info->pf_vid && vid != vf_info->pf_vid)
1177*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1178*4882a593Smuzhiyun 	else
1179*4882a593Smuzhiyun 		return vid;
1180*4882a593Smuzhiyun }
1181*4882a593Smuzhiyun 
1182*4882a593Smuzhiyun /**
1183*4882a593Smuzhiyun  *  fm10k_iov_msg_mac_vlan_pf - Message handler for MAC/VLAN request from VF
1184*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1185*4882a593Smuzhiyun  *  @results: Pointer array to message, results[0] is pointer to message
1186*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1187*4882a593Smuzhiyun  *
1188*4882a593Smuzhiyun  *  This function is a default handler for MAC/VLAN requests from the VF.
1189*4882a593Smuzhiyun  *  The assumption is that in this case it is acceptable to just directly
1190*4882a593Smuzhiyun  *  hand off the message from the VF to the underlying shared code.
1191*4882a593Smuzhiyun  **/
fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw * hw,u32 ** results,struct fm10k_mbx_info * mbx)1192*4882a593Smuzhiyun s32 fm10k_iov_msg_mac_vlan_pf(struct fm10k_hw *hw, u32 **results,
1193*4882a593Smuzhiyun 			      struct fm10k_mbx_info *mbx)
1194*4882a593Smuzhiyun {
1195*4882a593Smuzhiyun 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1196*4882a593Smuzhiyun 	u8 mac[ETH_ALEN];
1197*4882a593Smuzhiyun 	u32 *result;
1198*4882a593Smuzhiyun 	int err = 0;
1199*4882a593Smuzhiyun 	bool set;
1200*4882a593Smuzhiyun 	u16 vlan;
1201*4882a593Smuzhiyun 	u32 vid;
1202*4882a593Smuzhiyun 
1203*4882a593Smuzhiyun 	/* we shouldn't be updating rules on a disabled interface */
1204*4882a593Smuzhiyun 	if (!FM10K_VF_FLAG_ENABLED(vf_info))
1205*4882a593Smuzhiyun 		err = FM10K_ERR_PARAM;
1206*4882a593Smuzhiyun 
1207*4882a593Smuzhiyun 	if (!err && !!results[FM10K_MAC_VLAN_MSG_VLAN]) {
1208*4882a593Smuzhiyun 		result = results[FM10K_MAC_VLAN_MSG_VLAN];
1209*4882a593Smuzhiyun 
1210*4882a593Smuzhiyun 		/* record VLAN id requested */
1211*4882a593Smuzhiyun 		err = fm10k_tlv_attr_get_u32(result, &vid);
1212*4882a593Smuzhiyun 		if (err)
1213*4882a593Smuzhiyun 			return err;
1214*4882a593Smuzhiyun 
1215*4882a593Smuzhiyun 		set = !(vid & FM10K_VLAN_CLEAR);
1216*4882a593Smuzhiyun 		vid &= ~FM10K_VLAN_CLEAR;
1217*4882a593Smuzhiyun 
1218*4882a593Smuzhiyun 		/* if the length field has been set, this is a multi-bit
1219*4882a593Smuzhiyun 		 * update request. For multi-bit requests, simply disallow
1220*4882a593Smuzhiyun 		 * them when the pf_vid has been set. In this case, the PF
1221*4882a593Smuzhiyun 		 * should have already cleared the VLAN_TABLE, and if we
1222*4882a593Smuzhiyun 		 * allowed them, it could allow a rogue VF to receive traffic
1223*4882a593Smuzhiyun 		 * on a VLAN it was not assigned. In the single-bit case, we
1224*4882a593Smuzhiyun 		 * need to modify requests for VLAN 0 to use the default PF or
1225*4882a593Smuzhiyun 		 * SW vid when assigned.
1226*4882a593Smuzhiyun 		 */
1227*4882a593Smuzhiyun 
1228*4882a593Smuzhiyun 		if (vid >> 16) {
1229*4882a593Smuzhiyun 			/* prevent multi-bit requests when PF has
1230*4882a593Smuzhiyun 			 * administratively set the VLAN for this VF
1231*4882a593Smuzhiyun 			 */
1232*4882a593Smuzhiyun 			if (vf_info->pf_vid)
1233*4882a593Smuzhiyun 				return FM10K_ERR_PARAM;
1234*4882a593Smuzhiyun 		} else {
1235*4882a593Smuzhiyun 			err = fm10k_iov_select_vid(vf_info, (u16)vid);
1236*4882a593Smuzhiyun 			if (err < 0)
1237*4882a593Smuzhiyun 				return err;
1238*4882a593Smuzhiyun 
1239*4882a593Smuzhiyun 			vid = err;
1240*4882a593Smuzhiyun 		}
1241*4882a593Smuzhiyun 
1242*4882a593Smuzhiyun 		/* update VSI info for VF in regards to VLAN table */
1243*4882a593Smuzhiyun 		err = hw->mac.ops.update_vlan(hw, vid, vf_info->vsi, set);
1244*4882a593Smuzhiyun 	}
1245*4882a593Smuzhiyun 
1246*4882a593Smuzhiyun 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MAC]) {
1247*4882a593Smuzhiyun 		result = results[FM10K_MAC_VLAN_MSG_MAC];
1248*4882a593Smuzhiyun 
1249*4882a593Smuzhiyun 		/* record unicast MAC address requested */
1250*4882a593Smuzhiyun 		err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1251*4882a593Smuzhiyun 		if (err)
1252*4882a593Smuzhiyun 			return err;
1253*4882a593Smuzhiyun 
1254*4882a593Smuzhiyun 		/* block attempts to set MAC for a locked device */
1255*4882a593Smuzhiyun 		if (is_valid_ether_addr(vf_info->mac) &&
1256*4882a593Smuzhiyun 		    !ether_addr_equal(mac, vf_info->mac))
1257*4882a593Smuzhiyun 			return FM10K_ERR_PARAM;
1258*4882a593Smuzhiyun 
1259*4882a593Smuzhiyun 		set = !(vlan & FM10K_VLAN_CLEAR);
1260*4882a593Smuzhiyun 		vlan &= ~FM10K_VLAN_CLEAR;
1261*4882a593Smuzhiyun 
1262*4882a593Smuzhiyun 		err = fm10k_iov_select_vid(vf_info, vlan);
1263*4882a593Smuzhiyun 		if (err < 0)
1264*4882a593Smuzhiyun 			return err;
1265*4882a593Smuzhiyun 
1266*4882a593Smuzhiyun 		vlan = (u16)err;
1267*4882a593Smuzhiyun 
1268*4882a593Smuzhiyun 		/* notify switch of request for new unicast address */
1269*4882a593Smuzhiyun 		err = hw->mac.ops.update_uc_addr(hw, vf_info->glort,
1270*4882a593Smuzhiyun 						 mac, vlan, set, 0);
1271*4882a593Smuzhiyun 	}
1272*4882a593Smuzhiyun 
1273*4882a593Smuzhiyun 	if (!err && !!results[FM10K_MAC_VLAN_MSG_MULTICAST]) {
1274*4882a593Smuzhiyun 		result = results[FM10K_MAC_VLAN_MSG_MULTICAST];
1275*4882a593Smuzhiyun 
1276*4882a593Smuzhiyun 		/* record multicast MAC address requested */
1277*4882a593Smuzhiyun 		err = fm10k_tlv_attr_get_mac_vlan(result, mac, &vlan);
1278*4882a593Smuzhiyun 		if (err)
1279*4882a593Smuzhiyun 			return err;
1280*4882a593Smuzhiyun 
1281*4882a593Smuzhiyun 		/* verify that the VF is allowed to request multicast */
1282*4882a593Smuzhiyun 		if (!(vf_info->vf_flags & FM10K_VF_FLAG_MULTI_ENABLED))
1283*4882a593Smuzhiyun 			return FM10K_ERR_PARAM;
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun 		set = !(vlan & FM10K_VLAN_CLEAR);
1286*4882a593Smuzhiyun 		vlan &= ~FM10K_VLAN_CLEAR;
1287*4882a593Smuzhiyun 
1288*4882a593Smuzhiyun 		err = fm10k_iov_select_vid(vf_info, vlan);
1289*4882a593Smuzhiyun 		if (err < 0)
1290*4882a593Smuzhiyun 			return err;
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun 		vlan = (u16)err;
1293*4882a593Smuzhiyun 
1294*4882a593Smuzhiyun 		/* notify switch of request for new multicast address */
1295*4882a593Smuzhiyun 		err = hw->mac.ops.update_mc_addr(hw, vf_info->glort,
1296*4882a593Smuzhiyun 						 mac, vlan, set);
1297*4882a593Smuzhiyun 	}
1298*4882a593Smuzhiyun 
1299*4882a593Smuzhiyun 	return err;
1300*4882a593Smuzhiyun }
1301*4882a593Smuzhiyun 
1302*4882a593Smuzhiyun /**
1303*4882a593Smuzhiyun  *  fm10k_iov_supported_xcast_mode_pf - Determine best match for xcast mode
1304*4882a593Smuzhiyun  *  @vf_info: VF info structure containing capability flags
1305*4882a593Smuzhiyun  *  @mode: Requested xcast mode
1306*4882a593Smuzhiyun  *
1307*4882a593Smuzhiyun  *  This function outputs the mode that most closely matches the requested
1308*4882a593Smuzhiyun  *  mode.  If not modes match it will request we disable the port
1309*4882a593Smuzhiyun  **/
fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info * vf_info,u8 mode)1310*4882a593Smuzhiyun static u8 fm10k_iov_supported_xcast_mode_pf(struct fm10k_vf_info *vf_info,
1311*4882a593Smuzhiyun 					    u8 mode)
1312*4882a593Smuzhiyun {
1313*4882a593Smuzhiyun 	u8 vf_flags = vf_info->vf_flags;
1314*4882a593Smuzhiyun 
1315*4882a593Smuzhiyun 	/* match up mode to capabilities as best as possible */
1316*4882a593Smuzhiyun 	switch (mode) {
1317*4882a593Smuzhiyun 	case FM10K_XCAST_MODE_PROMISC:
1318*4882a593Smuzhiyun 		if (vf_flags & FM10K_VF_FLAG_PROMISC_CAPABLE)
1319*4882a593Smuzhiyun 			return FM10K_XCAST_MODE_PROMISC;
1320*4882a593Smuzhiyun 		fallthrough;
1321*4882a593Smuzhiyun 	case FM10K_XCAST_MODE_ALLMULTI:
1322*4882a593Smuzhiyun 		if (vf_flags & FM10K_VF_FLAG_ALLMULTI_CAPABLE)
1323*4882a593Smuzhiyun 			return FM10K_XCAST_MODE_ALLMULTI;
1324*4882a593Smuzhiyun 		fallthrough;
1325*4882a593Smuzhiyun 	case FM10K_XCAST_MODE_MULTI:
1326*4882a593Smuzhiyun 		if (vf_flags & FM10K_VF_FLAG_MULTI_CAPABLE)
1327*4882a593Smuzhiyun 			return FM10K_XCAST_MODE_MULTI;
1328*4882a593Smuzhiyun 		fallthrough;
1329*4882a593Smuzhiyun 	case FM10K_XCAST_MODE_NONE:
1330*4882a593Smuzhiyun 		if (vf_flags & FM10K_VF_FLAG_NONE_CAPABLE)
1331*4882a593Smuzhiyun 			return FM10K_XCAST_MODE_NONE;
1332*4882a593Smuzhiyun 		fallthrough;
1333*4882a593Smuzhiyun 	default:
1334*4882a593Smuzhiyun 		break;
1335*4882a593Smuzhiyun 	}
1336*4882a593Smuzhiyun 
1337*4882a593Smuzhiyun 	/* disable interface as it should not be able to request any */
1338*4882a593Smuzhiyun 	return FM10K_XCAST_MODE_DISABLE;
1339*4882a593Smuzhiyun }
1340*4882a593Smuzhiyun 
1341*4882a593Smuzhiyun /**
1342*4882a593Smuzhiyun  *  fm10k_iov_msg_lport_state_pf - Message handler for port state requests
1343*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1344*4882a593Smuzhiyun  *  @results: Pointer array to message, results[0] is pointer to message
1345*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1346*4882a593Smuzhiyun  *
1347*4882a593Smuzhiyun  *  This function is a default handler for port state requests.  The port
1348*4882a593Smuzhiyun  *  state requests for now are basic and consist of enabling or disabling
1349*4882a593Smuzhiyun  *  the port.
1350*4882a593Smuzhiyun  **/
fm10k_iov_msg_lport_state_pf(struct fm10k_hw * hw,u32 ** results,struct fm10k_mbx_info * mbx)1351*4882a593Smuzhiyun s32 fm10k_iov_msg_lport_state_pf(struct fm10k_hw *hw, u32 **results,
1352*4882a593Smuzhiyun 				 struct fm10k_mbx_info *mbx)
1353*4882a593Smuzhiyun {
1354*4882a593Smuzhiyun 	struct fm10k_vf_info *vf_info = (struct fm10k_vf_info *)mbx;
1355*4882a593Smuzhiyun 	s32 err = 0;
1356*4882a593Smuzhiyun 	u32 msg[2];
1357*4882a593Smuzhiyun 	u8 mode = 0;
1358*4882a593Smuzhiyun 
1359*4882a593Smuzhiyun 	/* verify VF is allowed to enable even minimal mode */
1360*4882a593Smuzhiyun 	if (!(vf_info->vf_flags & FM10K_VF_FLAG_NONE_CAPABLE))
1361*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1362*4882a593Smuzhiyun 
1363*4882a593Smuzhiyun 	if (!!results[FM10K_LPORT_STATE_MSG_XCAST_MODE]) {
1364*4882a593Smuzhiyun 		u32 *result = results[FM10K_LPORT_STATE_MSG_XCAST_MODE];
1365*4882a593Smuzhiyun 
1366*4882a593Smuzhiyun 		/* XCAST mode update requested */
1367*4882a593Smuzhiyun 		err = fm10k_tlv_attr_get_u8(result, &mode);
1368*4882a593Smuzhiyun 		if (err)
1369*4882a593Smuzhiyun 			return FM10K_ERR_PARAM;
1370*4882a593Smuzhiyun 
1371*4882a593Smuzhiyun 		/* prep for possible demotion depending on capabilities */
1372*4882a593Smuzhiyun 		mode = fm10k_iov_supported_xcast_mode_pf(vf_info, mode);
1373*4882a593Smuzhiyun 
1374*4882a593Smuzhiyun 		/* if mode is not currently enabled, enable it */
1375*4882a593Smuzhiyun 		if (!(FM10K_VF_FLAG_ENABLED(vf_info) & BIT(mode)))
1376*4882a593Smuzhiyun 			fm10k_update_xcast_mode_pf(hw, vf_info->glort, mode);
1377*4882a593Smuzhiyun 
1378*4882a593Smuzhiyun 		/* swap mode back to a bit flag */
1379*4882a593Smuzhiyun 		mode = FM10K_VF_FLAG_SET_MODE(mode);
1380*4882a593Smuzhiyun 	} else if (!results[FM10K_LPORT_STATE_MSG_DISABLE]) {
1381*4882a593Smuzhiyun 		/* need to disable the port if it is already enabled */
1382*4882a593Smuzhiyun 		if (FM10K_VF_FLAG_ENABLED(vf_info))
1383*4882a593Smuzhiyun 			err = fm10k_update_lport_state_pf(hw, vf_info->glort,
1384*4882a593Smuzhiyun 							  1, false);
1385*4882a593Smuzhiyun 
1386*4882a593Smuzhiyun 		/* we need to clear VF_FLAG_ENABLED flags in order to ensure
1387*4882a593Smuzhiyun 		 * that we actually re-enable the LPORT state below. Note that
1388*4882a593Smuzhiyun 		 * this has no impact if the VF is already disabled, as the
1389*4882a593Smuzhiyun 		 * flags are already cleared.
1390*4882a593Smuzhiyun 		 */
1391*4882a593Smuzhiyun 		if (!err)
1392*4882a593Smuzhiyun 			vf_info->vf_flags = FM10K_VF_FLAG_CAPABLE(vf_info);
1393*4882a593Smuzhiyun 
1394*4882a593Smuzhiyun 		/* when enabling the port we should reset the rate limiters */
1395*4882a593Smuzhiyun 		hw->iov.ops.configure_tc(hw, vf_info->vf_idx, vf_info->rate);
1396*4882a593Smuzhiyun 
1397*4882a593Smuzhiyun 		/* set mode for minimal functionality */
1398*4882a593Smuzhiyun 		mode = FM10K_VF_FLAG_SET_MODE_NONE;
1399*4882a593Smuzhiyun 
1400*4882a593Smuzhiyun 		/* generate port state response to notify VF it is ready */
1401*4882a593Smuzhiyun 		fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
1402*4882a593Smuzhiyun 		fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_READY);
1403*4882a593Smuzhiyun 		mbx->ops.enqueue_tx(hw, mbx, msg);
1404*4882a593Smuzhiyun 	}
1405*4882a593Smuzhiyun 
1406*4882a593Smuzhiyun 	/* if enable state toggled note the update */
1407*4882a593Smuzhiyun 	if (!err && (!FM10K_VF_FLAG_ENABLED(vf_info) != !mode))
1408*4882a593Smuzhiyun 		err = fm10k_update_lport_state_pf(hw, vf_info->glort, 1,
1409*4882a593Smuzhiyun 						  !!mode);
1410*4882a593Smuzhiyun 
1411*4882a593Smuzhiyun 	/* if state change succeeded, then update our stored state */
1412*4882a593Smuzhiyun 	mode |= FM10K_VF_FLAG_CAPABLE(vf_info);
1413*4882a593Smuzhiyun 	if (!err)
1414*4882a593Smuzhiyun 		vf_info->vf_flags = mode;
1415*4882a593Smuzhiyun 
1416*4882a593Smuzhiyun 	return err;
1417*4882a593Smuzhiyun }
1418*4882a593Smuzhiyun 
1419*4882a593Smuzhiyun /**
1420*4882a593Smuzhiyun  *  fm10k_update_stats_hw_pf - Updates hardware related statistics of PF
1421*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1422*4882a593Smuzhiyun  *  @stats: pointer to the stats structure to update
1423*4882a593Smuzhiyun  *
1424*4882a593Smuzhiyun  *  This function collects and aggregates global and per queue hardware
1425*4882a593Smuzhiyun  *  statistics.
1426*4882a593Smuzhiyun  **/
fm10k_update_hw_stats_pf(struct fm10k_hw * hw,struct fm10k_hw_stats * stats)1427*4882a593Smuzhiyun static void fm10k_update_hw_stats_pf(struct fm10k_hw *hw,
1428*4882a593Smuzhiyun 				     struct fm10k_hw_stats *stats)
1429*4882a593Smuzhiyun {
1430*4882a593Smuzhiyun 	u32 timeout, ur, ca, um, xec, vlan_drop, loopback_drop, nodesc_drop;
1431*4882a593Smuzhiyun 	u32 id, id_prev;
1432*4882a593Smuzhiyun 
1433*4882a593Smuzhiyun 	/* Use Tx queue 0 as a canary to detect a reset */
1434*4882a593Smuzhiyun 	id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1435*4882a593Smuzhiyun 
1436*4882a593Smuzhiyun 	/* Read Global Statistics */
1437*4882a593Smuzhiyun 	do {
1438*4882a593Smuzhiyun 		timeout = fm10k_read_hw_stats_32b(hw, FM10K_STATS_TIMEOUT,
1439*4882a593Smuzhiyun 						  &stats->timeout);
1440*4882a593Smuzhiyun 		ur = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UR, &stats->ur);
1441*4882a593Smuzhiyun 		ca = fm10k_read_hw_stats_32b(hw, FM10K_STATS_CA, &stats->ca);
1442*4882a593Smuzhiyun 		um = fm10k_read_hw_stats_32b(hw, FM10K_STATS_UM, &stats->um);
1443*4882a593Smuzhiyun 		xec = fm10k_read_hw_stats_32b(hw, FM10K_STATS_XEC, &stats->xec);
1444*4882a593Smuzhiyun 		vlan_drop = fm10k_read_hw_stats_32b(hw, FM10K_STATS_VLAN_DROP,
1445*4882a593Smuzhiyun 						    &stats->vlan_drop);
1446*4882a593Smuzhiyun 		loopback_drop =
1447*4882a593Smuzhiyun 			fm10k_read_hw_stats_32b(hw,
1448*4882a593Smuzhiyun 						FM10K_STATS_LOOPBACK_DROP,
1449*4882a593Smuzhiyun 						&stats->loopback_drop);
1450*4882a593Smuzhiyun 		nodesc_drop = fm10k_read_hw_stats_32b(hw,
1451*4882a593Smuzhiyun 						      FM10K_STATS_NODESC_DROP,
1452*4882a593Smuzhiyun 						      &stats->nodesc_drop);
1453*4882a593Smuzhiyun 
1454*4882a593Smuzhiyun 		/* if value has not changed then we have consistent data */
1455*4882a593Smuzhiyun 		id_prev = id;
1456*4882a593Smuzhiyun 		id = fm10k_read_reg(hw, FM10K_TXQCTL(0));
1457*4882a593Smuzhiyun 	} while ((id ^ id_prev) & FM10K_TXQCTL_ID_MASK);
1458*4882a593Smuzhiyun 
1459*4882a593Smuzhiyun 	/* drop non-ID bits and set VALID ID bit */
1460*4882a593Smuzhiyun 	id &= FM10K_TXQCTL_ID_MASK;
1461*4882a593Smuzhiyun 	id |= FM10K_STAT_VALID;
1462*4882a593Smuzhiyun 
1463*4882a593Smuzhiyun 	/* Update Global Statistics */
1464*4882a593Smuzhiyun 	if (stats->stats_idx == id) {
1465*4882a593Smuzhiyun 		stats->timeout.count += timeout;
1466*4882a593Smuzhiyun 		stats->ur.count += ur;
1467*4882a593Smuzhiyun 		stats->ca.count += ca;
1468*4882a593Smuzhiyun 		stats->um.count += um;
1469*4882a593Smuzhiyun 		stats->xec.count += xec;
1470*4882a593Smuzhiyun 		stats->vlan_drop.count += vlan_drop;
1471*4882a593Smuzhiyun 		stats->loopback_drop.count += loopback_drop;
1472*4882a593Smuzhiyun 		stats->nodesc_drop.count += nodesc_drop;
1473*4882a593Smuzhiyun 	}
1474*4882a593Smuzhiyun 
1475*4882a593Smuzhiyun 	/* Update bases and record current PF id */
1476*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->timeout, timeout);
1477*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->ur, ur);
1478*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->ca, ca);
1479*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->um, um);
1480*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->xec, xec);
1481*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->vlan_drop, vlan_drop);
1482*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->loopback_drop, loopback_drop);
1483*4882a593Smuzhiyun 	fm10k_update_hw_base_32b(&stats->nodesc_drop, nodesc_drop);
1484*4882a593Smuzhiyun 	stats->stats_idx = id;
1485*4882a593Smuzhiyun 
1486*4882a593Smuzhiyun 	/* Update Queue Statistics */
1487*4882a593Smuzhiyun 	fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
1488*4882a593Smuzhiyun }
1489*4882a593Smuzhiyun 
1490*4882a593Smuzhiyun /**
1491*4882a593Smuzhiyun  *  fm10k_rebind_hw_stats_pf - Resets base for hardware statistics of PF
1492*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1493*4882a593Smuzhiyun  *  @stats: pointer to the stats structure to update
1494*4882a593Smuzhiyun  *
1495*4882a593Smuzhiyun  *  This function resets the base for global and per queue hardware
1496*4882a593Smuzhiyun  *  statistics.
1497*4882a593Smuzhiyun  **/
fm10k_rebind_hw_stats_pf(struct fm10k_hw * hw,struct fm10k_hw_stats * stats)1498*4882a593Smuzhiyun static void fm10k_rebind_hw_stats_pf(struct fm10k_hw *hw,
1499*4882a593Smuzhiyun 				     struct fm10k_hw_stats *stats)
1500*4882a593Smuzhiyun {
1501*4882a593Smuzhiyun 	/* Unbind Global Statistics */
1502*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->timeout);
1503*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->ur);
1504*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->ca);
1505*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->um);
1506*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->xec);
1507*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->vlan_drop);
1508*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->loopback_drop);
1509*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_32b(&stats->nodesc_drop);
1510*4882a593Smuzhiyun 
1511*4882a593Smuzhiyun 	/* Unbind Queue Statistics */
1512*4882a593Smuzhiyun 	fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
1513*4882a593Smuzhiyun 
1514*4882a593Smuzhiyun 	/* Reinitialize bases for all stats */
1515*4882a593Smuzhiyun 	fm10k_update_hw_stats_pf(hw, stats);
1516*4882a593Smuzhiyun }
1517*4882a593Smuzhiyun 
1518*4882a593Smuzhiyun /**
1519*4882a593Smuzhiyun  *  fm10k_set_dma_mask_pf - Configures PhyAddrSpace to limit DMA to system
1520*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1521*4882a593Smuzhiyun  *  @dma_mask: 64 bit DMA mask required for platform
1522*4882a593Smuzhiyun  *
1523*4882a593Smuzhiyun  *  This function sets the PHYADDR.PhyAddrSpace bits for the endpoint in order
1524*4882a593Smuzhiyun  *  to limit the access to memory beyond what is physically in the system.
1525*4882a593Smuzhiyun  **/
fm10k_set_dma_mask_pf(struct fm10k_hw * hw,u64 dma_mask)1526*4882a593Smuzhiyun static void fm10k_set_dma_mask_pf(struct fm10k_hw *hw, u64 dma_mask)
1527*4882a593Smuzhiyun {
1528*4882a593Smuzhiyun 	/* we need to write the upper 32 bits of DMA mask to PhyAddrSpace */
1529*4882a593Smuzhiyun 	u32 phyaddr = (u32)(dma_mask >> 32);
1530*4882a593Smuzhiyun 
1531*4882a593Smuzhiyun 	fm10k_write_reg(hw, FM10K_PHYADDR, phyaddr);
1532*4882a593Smuzhiyun }
1533*4882a593Smuzhiyun 
1534*4882a593Smuzhiyun /**
1535*4882a593Smuzhiyun  *  fm10k_get_fault_pf - Record a fault in one of the interface units
1536*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1537*4882a593Smuzhiyun  *  @type: pointer to fault type register offset
1538*4882a593Smuzhiyun  *  @fault: pointer to memory location to record the fault
1539*4882a593Smuzhiyun  *
1540*4882a593Smuzhiyun  *  Record the fault register contents to the fault data structure and
1541*4882a593Smuzhiyun  *  clear the entry from the register.
1542*4882a593Smuzhiyun  *
1543*4882a593Smuzhiyun  *  Returns ERR_PARAM if invalid register is specified or no error is present.
1544*4882a593Smuzhiyun  **/
fm10k_get_fault_pf(struct fm10k_hw * hw,int type,struct fm10k_fault * fault)1545*4882a593Smuzhiyun static s32 fm10k_get_fault_pf(struct fm10k_hw *hw, int type,
1546*4882a593Smuzhiyun 			      struct fm10k_fault *fault)
1547*4882a593Smuzhiyun {
1548*4882a593Smuzhiyun 	u32 func;
1549*4882a593Smuzhiyun 
1550*4882a593Smuzhiyun 	/* verify the fault register is in range and is aligned */
1551*4882a593Smuzhiyun 	switch (type) {
1552*4882a593Smuzhiyun 	case FM10K_PCA_FAULT:
1553*4882a593Smuzhiyun 	case FM10K_THI_FAULT:
1554*4882a593Smuzhiyun 	case FM10K_FUM_FAULT:
1555*4882a593Smuzhiyun 		break;
1556*4882a593Smuzhiyun 	default:
1557*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1558*4882a593Smuzhiyun 	}
1559*4882a593Smuzhiyun 
1560*4882a593Smuzhiyun 	/* only service faults that are valid */
1561*4882a593Smuzhiyun 	func = fm10k_read_reg(hw, type + FM10K_FAULT_FUNC);
1562*4882a593Smuzhiyun 	if (!(func & FM10K_FAULT_FUNC_VALID))
1563*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1564*4882a593Smuzhiyun 
1565*4882a593Smuzhiyun 	/* read remaining fields */
1566*4882a593Smuzhiyun 	fault->address = fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_HI);
1567*4882a593Smuzhiyun 	fault->address <<= 32;
1568*4882a593Smuzhiyun 	fault->address |= fm10k_read_reg(hw, type + FM10K_FAULT_ADDR_LO);
1569*4882a593Smuzhiyun 	fault->specinfo = fm10k_read_reg(hw, type + FM10K_FAULT_SPECINFO);
1570*4882a593Smuzhiyun 
1571*4882a593Smuzhiyun 	/* clear valid bit to allow for next error */
1572*4882a593Smuzhiyun 	fm10k_write_reg(hw, type + FM10K_FAULT_FUNC, FM10K_FAULT_FUNC_VALID);
1573*4882a593Smuzhiyun 
1574*4882a593Smuzhiyun 	/* Record which function triggered the error */
1575*4882a593Smuzhiyun 	if (func & FM10K_FAULT_FUNC_PF)
1576*4882a593Smuzhiyun 		fault->func = 0;
1577*4882a593Smuzhiyun 	else
1578*4882a593Smuzhiyun 		fault->func = 1 + ((func & FM10K_FAULT_FUNC_VF_MASK) >>
1579*4882a593Smuzhiyun 				   FM10K_FAULT_FUNC_VF_SHIFT);
1580*4882a593Smuzhiyun 
1581*4882a593Smuzhiyun 	/* record fault type */
1582*4882a593Smuzhiyun 	fault->type = func & FM10K_FAULT_FUNC_TYPE_MASK;
1583*4882a593Smuzhiyun 
1584*4882a593Smuzhiyun 	return 0;
1585*4882a593Smuzhiyun }
1586*4882a593Smuzhiyun 
1587*4882a593Smuzhiyun /**
1588*4882a593Smuzhiyun  *  fm10k_request_lport_map_pf - Request LPORT map from the switch API
1589*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1590*4882a593Smuzhiyun  *
1591*4882a593Smuzhiyun  **/
fm10k_request_lport_map_pf(struct fm10k_hw * hw)1592*4882a593Smuzhiyun static s32 fm10k_request_lport_map_pf(struct fm10k_hw *hw)
1593*4882a593Smuzhiyun {
1594*4882a593Smuzhiyun 	struct fm10k_mbx_info *mbx = &hw->mbx;
1595*4882a593Smuzhiyun 	u32 msg[1];
1596*4882a593Smuzhiyun 
1597*4882a593Smuzhiyun 	/* issue request asking for LPORT map */
1598*4882a593Smuzhiyun 	fm10k_tlv_msg_init(msg, FM10K_PF_MSG_ID_LPORT_MAP);
1599*4882a593Smuzhiyun 
1600*4882a593Smuzhiyun 	/* load onto outgoing mailbox */
1601*4882a593Smuzhiyun 	return mbx->ops.enqueue_tx(hw, mbx, msg);
1602*4882a593Smuzhiyun }
1603*4882a593Smuzhiyun 
1604*4882a593Smuzhiyun /**
1605*4882a593Smuzhiyun  *  fm10k_get_host_state_pf - Returns the state of the switch and mailbox
1606*4882a593Smuzhiyun  *  @hw: pointer to hardware structure
1607*4882a593Smuzhiyun  *  @switch_ready: pointer to boolean value that will record switch state
1608*4882a593Smuzhiyun  *
1609*4882a593Smuzhiyun  *  This function will check the DMA_CTRL2 register and mailbox in order
1610*4882a593Smuzhiyun  *  to determine if the switch is ready for the PF to begin requesting
1611*4882a593Smuzhiyun  *  addresses and mapping traffic to the local interface.
1612*4882a593Smuzhiyun  **/
fm10k_get_host_state_pf(struct fm10k_hw * hw,bool * switch_ready)1613*4882a593Smuzhiyun static s32 fm10k_get_host_state_pf(struct fm10k_hw *hw, bool *switch_ready)
1614*4882a593Smuzhiyun {
1615*4882a593Smuzhiyun 	u32 dma_ctrl2;
1616*4882a593Smuzhiyun 
1617*4882a593Smuzhiyun 	/* verify the switch is ready for interaction */
1618*4882a593Smuzhiyun 	dma_ctrl2 = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
1619*4882a593Smuzhiyun 	if (!(dma_ctrl2 & FM10K_DMA_CTRL2_SWITCH_READY))
1620*4882a593Smuzhiyun 		return 0;
1621*4882a593Smuzhiyun 
1622*4882a593Smuzhiyun 	/* retrieve generic host state info */
1623*4882a593Smuzhiyun 	return fm10k_get_host_state_generic(hw, switch_ready);
1624*4882a593Smuzhiyun }
1625*4882a593Smuzhiyun 
1626*4882a593Smuzhiyun /* This structure defines the attibutes to be parsed below */
1627*4882a593Smuzhiyun const struct fm10k_tlv_attr fm10k_lport_map_msg_attr[] = {
1628*4882a593Smuzhiyun 	FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1629*4882a593Smuzhiyun 				 sizeof(struct fm10k_swapi_error)),
1630*4882a593Smuzhiyun 	FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_LPORT_MAP),
1631*4882a593Smuzhiyun 	FM10K_TLV_ATTR_LAST
1632*4882a593Smuzhiyun };
1633*4882a593Smuzhiyun 
1634*4882a593Smuzhiyun /**
1635*4882a593Smuzhiyun  *  fm10k_msg_lport_map_pf - Message handler for lport_map message from SM
1636*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1637*4882a593Smuzhiyun  *  @results: pointer array containing parsed data
1638*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1639*4882a593Smuzhiyun  *
1640*4882a593Smuzhiyun  *  This handler configures the lport mapping based on the reply from the
1641*4882a593Smuzhiyun  *  switch API.
1642*4882a593Smuzhiyun  **/
fm10k_msg_lport_map_pf(struct fm10k_hw * hw,u32 ** results,struct fm10k_mbx_info __always_unused * mbx)1643*4882a593Smuzhiyun s32 fm10k_msg_lport_map_pf(struct fm10k_hw *hw, u32 **results,
1644*4882a593Smuzhiyun 			   struct fm10k_mbx_info __always_unused *mbx)
1645*4882a593Smuzhiyun {
1646*4882a593Smuzhiyun 	u16 glort, mask;
1647*4882a593Smuzhiyun 	u32 dglort_map;
1648*4882a593Smuzhiyun 	s32 err;
1649*4882a593Smuzhiyun 
1650*4882a593Smuzhiyun 	err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_LPORT_MAP],
1651*4882a593Smuzhiyun 				     &dglort_map);
1652*4882a593Smuzhiyun 	if (err)
1653*4882a593Smuzhiyun 		return err;
1654*4882a593Smuzhiyun 
1655*4882a593Smuzhiyun 	/* extract values out of the header */
1656*4882a593Smuzhiyun 	glort = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_GLORT);
1657*4882a593Smuzhiyun 	mask = FM10K_MSG_HDR_FIELD_GET(dglort_map, LPORT_MAP_MASK);
1658*4882a593Smuzhiyun 
1659*4882a593Smuzhiyun 	/* verify mask is set and none of the masked bits in glort are set */
1660*4882a593Smuzhiyun 	if (!mask || (glort & ~mask))
1661*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1662*4882a593Smuzhiyun 
1663*4882a593Smuzhiyun 	/* verify the mask is contiguous, and that it is 1's followed by 0's */
1664*4882a593Smuzhiyun 	if (((~(mask - 1) & mask) + mask) & FM10K_DGLORTMAP_NONE)
1665*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1666*4882a593Smuzhiyun 
1667*4882a593Smuzhiyun 	/* record the glort, mask, and port count */
1668*4882a593Smuzhiyun 	hw->mac.dglort_map = dglort_map;
1669*4882a593Smuzhiyun 
1670*4882a593Smuzhiyun 	return 0;
1671*4882a593Smuzhiyun }
1672*4882a593Smuzhiyun 
1673*4882a593Smuzhiyun const struct fm10k_tlv_attr fm10k_update_pvid_msg_attr[] = {
1674*4882a593Smuzhiyun 	FM10K_TLV_ATTR_U32(FM10K_PF_ATTR_ID_UPDATE_PVID),
1675*4882a593Smuzhiyun 	FM10K_TLV_ATTR_LAST
1676*4882a593Smuzhiyun };
1677*4882a593Smuzhiyun 
1678*4882a593Smuzhiyun /**
1679*4882a593Smuzhiyun  *  fm10k_msg_update_pvid_pf - Message handler for port VLAN message from SM
1680*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1681*4882a593Smuzhiyun  *  @results: pointer array containing parsed data
1682*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1683*4882a593Smuzhiyun  *
1684*4882a593Smuzhiyun  *  This handler configures the default VLAN for the PF
1685*4882a593Smuzhiyun  **/
fm10k_msg_update_pvid_pf(struct fm10k_hw * hw,u32 ** results,struct fm10k_mbx_info __always_unused * mbx)1686*4882a593Smuzhiyun static s32 fm10k_msg_update_pvid_pf(struct fm10k_hw *hw, u32 **results,
1687*4882a593Smuzhiyun 				    struct fm10k_mbx_info __always_unused *mbx)
1688*4882a593Smuzhiyun {
1689*4882a593Smuzhiyun 	u16 glort, pvid;
1690*4882a593Smuzhiyun 	u32 pvid_update;
1691*4882a593Smuzhiyun 	s32 err;
1692*4882a593Smuzhiyun 
1693*4882a593Smuzhiyun 	err = fm10k_tlv_attr_get_u32(results[FM10K_PF_ATTR_ID_UPDATE_PVID],
1694*4882a593Smuzhiyun 				     &pvid_update);
1695*4882a593Smuzhiyun 	if (err)
1696*4882a593Smuzhiyun 		return err;
1697*4882a593Smuzhiyun 
1698*4882a593Smuzhiyun 	/* extract values from the pvid update */
1699*4882a593Smuzhiyun 	glort = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_GLORT);
1700*4882a593Smuzhiyun 	pvid = FM10K_MSG_HDR_FIELD_GET(pvid_update, UPDATE_PVID_PVID);
1701*4882a593Smuzhiyun 
1702*4882a593Smuzhiyun 	/* if glort is not valid return error */
1703*4882a593Smuzhiyun 	if (!fm10k_glort_valid_pf(hw, glort))
1704*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1705*4882a593Smuzhiyun 
1706*4882a593Smuzhiyun 	/* verify VLAN ID is valid */
1707*4882a593Smuzhiyun 	if (pvid >= FM10K_VLAN_TABLE_VID_MAX)
1708*4882a593Smuzhiyun 		return FM10K_ERR_PARAM;
1709*4882a593Smuzhiyun 
1710*4882a593Smuzhiyun 	/* record the port VLAN ID value */
1711*4882a593Smuzhiyun 	hw->mac.default_vid = pvid;
1712*4882a593Smuzhiyun 
1713*4882a593Smuzhiyun 	return 0;
1714*4882a593Smuzhiyun }
1715*4882a593Smuzhiyun 
1716*4882a593Smuzhiyun /**
1717*4882a593Smuzhiyun  *  fm10k_record_global_table_data - Move global table data to swapi table info
1718*4882a593Smuzhiyun  *  @from: pointer to source table data structure
1719*4882a593Smuzhiyun  *  @to: pointer to destination table info structure
1720*4882a593Smuzhiyun  *
1721*4882a593Smuzhiyun  *  This function is will copy table_data to the table_info contained in
1722*4882a593Smuzhiyun  *  the hw struct.
1723*4882a593Smuzhiyun  **/
fm10k_record_global_table_data(struct fm10k_global_table_data * from,struct fm10k_swapi_table_info * to)1724*4882a593Smuzhiyun static void fm10k_record_global_table_data(struct fm10k_global_table_data *from,
1725*4882a593Smuzhiyun 					   struct fm10k_swapi_table_info *to)
1726*4882a593Smuzhiyun {
1727*4882a593Smuzhiyun 	/* convert from le32 struct to CPU byte ordered values */
1728*4882a593Smuzhiyun 	to->used = le32_to_cpu(from->used);
1729*4882a593Smuzhiyun 	to->avail = le32_to_cpu(from->avail);
1730*4882a593Smuzhiyun }
1731*4882a593Smuzhiyun 
1732*4882a593Smuzhiyun const struct fm10k_tlv_attr fm10k_err_msg_attr[] = {
1733*4882a593Smuzhiyun 	FM10K_TLV_ATTR_LE_STRUCT(FM10K_PF_ATTR_ID_ERR,
1734*4882a593Smuzhiyun 				 sizeof(struct fm10k_swapi_error)),
1735*4882a593Smuzhiyun 	FM10K_TLV_ATTR_LAST
1736*4882a593Smuzhiyun };
1737*4882a593Smuzhiyun 
1738*4882a593Smuzhiyun /**
1739*4882a593Smuzhiyun  *  fm10k_msg_err_pf - Message handler for error reply
1740*4882a593Smuzhiyun  *  @hw: Pointer to hardware structure
1741*4882a593Smuzhiyun  *  @results: pointer array containing parsed data
1742*4882a593Smuzhiyun  *  @mbx: Pointer to mailbox information structure
1743*4882a593Smuzhiyun  *
1744*4882a593Smuzhiyun  *  This handler will capture the data for any error replies to previous
1745*4882a593Smuzhiyun  *  messages that the PF has sent.
1746*4882a593Smuzhiyun  **/
fm10k_msg_err_pf(struct fm10k_hw * hw,u32 ** results,struct fm10k_mbx_info __always_unused * mbx)1747*4882a593Smuzhiyun s32 fm10k_msg_err_pf(struct fm10k_hw *hw, u32 **results,
1748*4882a593Smuzhiyun 		     struct fm10k_mbx_info __always_unused *mbx)
1749*4882a593Smuzhiyun {
1750*4882a593Smuzhiyun 	struct fm10k_swapi_error err_msg;
1751*4882a593Smuzhiyun 	s32 err;
1752*4882a593Smuzhiyun 
1753*4882a593Smuzhiyun 	/* extract structure from message */
1754*4882a593Smuzhiyun 	err = fm10k_tlv_attr_get_le_struct(results[FM10K_PF_ATTR_ID_ERR],
1755*4882a593Smuzhiyun 					   &err_msg, sizeof(err_msg));
1756*4882a593Smuzhiyun 	if (err)
1757*4882a593Smuzhiyun 		return err;
1758*4882a593Smuzhiyun 
1759*4882a593Smuzhiyun 	/* record table status */
1760*4882a593Smuzhiyun 	fm10k_record_global_table_data(&err_msg.mac, &hw->swapi.mac);
1761*4882a593Smuzhiyun 	fm10k_record_global_table_data(&err_msg.nexthop, &hw->swapi.nexthop);
1762*4882a593Smuzhiyun 	fm10k_record_global_table_data(&err_msg.ffu, &hw->swapi.ffu);
1763*4882a593Smuzhiyun 
1764*4882a593Smuzhiyun 	/* record SW API status value */
1765*4882a593Smuzhiyun 	hw->swapi.status = le32_to_cpu(err_msg.status);
1766*4882a593Smuzhiyun 
1767*4882a593Smuzhiyun 	return 0;
1768*4882a593Smuzhiyun }
1769*4882a593Smuzhiyun 
1770*4882a593Smuzhiyun static const struct fm10k_msg_data fm10k_msg_data_pf[] = {
1771*4882a593Smuzhiyun 	FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1772*4882a593Smuzhiyun 	FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1773*4882a593Smuzhiyun 	FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf),
1774*4882a593Smuzhiyun 	FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1775*4882a593Smuzhiyun 	FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1776*4882a593Smuzhiyun 	FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
1777*4882a593Smuzhiyun 	FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1778*4882a593Smuzhiyun };
1779*4882a593Smuzhiyun 
1780*4882a593Smuzhiyun static const struct fm10k_mac_ops mac_ops_pf = {
1781*4882a593Smuzhiyun 	.get_bus_info		= fm10k_get_bus_info_generic,
1782*4882a593Smuzhiyun 	.reset_hw		= fm10k_reset_hw_pf,
1783*4882a593Smuzhiyun 	.init_hw		= fm10k_init_hw_pf,
1784*4882a593Smuzhiyun 	.start_hw		= fm10k_start_hw_generic,
1785*4882a593Smuzhiyun 	.stop_hw		= fm10k_stop_hw_generic,
1786*4882a593Smuzhiyun 	.update_vlan		= fm10k_update_vlan_pf,
1787*4882a593Smuzhiyun 	.read_mac_addr		= fm10k_read_mac_addr_pf,
1788*4882a593Smuzhiyun 	.update_uc_addr		= fm10k_update_uc_addr_pf,
1789*4882a593Smuzhiyun 	.update_mc_addr		= fm10k_update_mc_addr_pf,
1790*4882a593Smuzhiyun 	.update_xcast_mode	= fm10k_update_xcast_mode_pf,
1791*4882a593Smuzhiyun 	.update_int_moderator	= fm10k_update_int_moderator_pf,
1792*4882a593Smuzhiyun 	.update_lport_state	= fm10k_update_lport_state_pf,
1793*4882a593Smuzhiyun 	.update_hw_stats	= fm10k_update_hw_stats_pf,
1794*4882a593Smuzhiyun 	.rebind_hw_stats	= fm10k_rebind_hw_stats_pf,
1795*4882a593Smuzhiyun 	.configure_dglort_map	= fm10k_configure_dglort_map_pf,
1796*4882a593Smuzhiyun 	.set_dma_mask		= fm10k_set_dma_mask_pf,
1797*4882a593Smuzhiyun 	.get_fault		= fm10k_get_fault_pf,
1798*4882a593Smuzhiyun 	.get_host_state		= fm10k_get_host_state_pf,
1799*4882a593Smuzhiyun 	.request_lport_map	= fm10k_request_lport_map_pf,
1800*4882a593Smuzhiyun };
1801*4882a593Smuzhiyun 
1802*4882a593Smuzhiyun static const struct fm10k_iov_ops iov_ops_pf = {
1803*4882a593Smuzhiyun 	.assign_resources		= fm10k_iov_assign_resources_pf,
1804*4882a593Smuzhiyun 	.configure_tc			= fm10k_iov_configure_tc_pf,
1805*4882a593Smuzhiyun 	.assign_int_moderator		= fm10k_iov_assign_int_moderator_pf,
1806*4882a593Smuzhiyun 	.assign_default_mac_vlan	= fm10k_iov_assign_default_mac_vlan_pf,
1807*4882a593Smuzhiyun 	.reset_resources		= fm10k_iov_reset_resources_pf,
1808*4882a593Smuzhiyun 	.set_lport			= fm10k_iov_set_lport_pf,
1809*4882a593Smuzhiyun 	.reset_lport			= fm10k_iov_reset_lport_pf,
1810*4882a593Smuzhiyun 	.update_stats			= fm10k_iov_update_stats_pf,
1811*4882a593Smuzhiyun };
1812*4882a593Smuzhiyun 
fm10k_get_invariants_pf(struct fm10k_hw * hw)1813*4882a593Smuzhiyun static s32 fm10k_get_invariants_pf(struct fm10k_hw *hw)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun 	fm10k_get_invariants_generic(hw);
1816*4882a593Smuzhiyun 
1817*4882a593Smuzhiyun 	return fm10k_sm_mbx_init(hw, &hw->mbx, fm10k_msg_data_pf);
1818*4882a593Smuzhiyun }
1819*4882a593Smuzhiyun 
1820*4882a593Smuzhiyun const struct fm10k_info fm10k_pf_info = {
1821*4882a593Smuzhiyun 	.mac		= fm10k_mac_pf,
1822*4882a593Smuzhiyun 	.get_invariants	= fm10k_get_invariants_pf,
1823*4882a593Smuzhiyun 	.mac_ops	= &mac_ops_pf,
1824*4882a593Smuzhiyun 	.iov_ops	= &iov_ops_pf,
1825*4882a593Smuzhiyun };
1826