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