2246688cfc29e362a6c1f41d0796a95dd549f1cd
[dpdk.git] / lib / librte_pmd_fm10k / base / fm10k_vf.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_vf.h"
35
36 /**
37  *  fm10k_stop_hw_vf - Stop Tx/Rx units
38  *  @hw: pointer to hardware structure
39  *
40  **/
41 STATIC s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
42 {
43         u8 *perm_addr = hw->mac.perm_addr;
44         u32 bal = 0, bah = 0;
45         s32 err;
46         u16 i;
47
48         DEBUGFUNC("fm10k_stop_hw_vf");
49
50         /* we need to disable the queues before taking further steps */
51         err = fm10k_stop_hw_generic(hw);
52         if (err)
53                 return err;
54
55         /* If permanent address is set then we need to restore it */
56         if (FM10K_IS_VALID_ETHER_ADDR(perm_addr)) {
57                 bal = (((u32)perm_addr[3]) << 24) |
58                       (((u32)perm_addr[4]) << 16) |
59                       (((u32)perm_addr[5]) << 8);
60                 bah = (((u32)0xFF)         << 24) |
61                       (((u32)perm_addr[0]) << 16) |
62                       (((u32)perm_addr[1]) << 8) |
63                        ((u32)perm_addr[2]);
64         }
65
66         /* The queues have already been disabled so we just need to
67          * update their base address registers
68          */
69         for (i = 0; i < hw->mac.max_queues; i++) {
70                 FM10K_WRITE_REG(hw, FM10K_TDBAL(i), bal);
71                 FM10K_WRITE_REG(hw, FM10K_TDBAH(i), bah);
72                 FM10K_WRITE_REG(hw, FM10K_RDBAL(i), bal);
73                 FM10K_WRITE_REG(hw, FM10K_RDBAH(i), bah);
74         }
75
76         return FM10K_SUCCESS;
77 }
78
79 /**
80  *  fm10k_reset_hw_vf - VF hardware reset
81  *  @hw: pointer to hardware structure
82  *
83  *  This function should return the hardware to a state similar to the
84  *  one it is in after just being initialized.
85  **/
86 STATIC s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
87 {
88         s32 err;
89
90         DEBUGFUNC("fm10k_reset_hw_vf");
91
92         /* shut down queues we own and reset DMA configuration */
93         err = fm10k_stop_hw_vf(hw);
94         if (err)
95                 return err;
96
97         /* Inititate VF reset */
98         FM10K_WRITE_REG(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
99
100         /* Flush write and allow 100us for reset to complete */
101         FM10K_WRITE_FLUSH(hw);
102         usec_delay(FM10K_RESET_TIMEOUT);
103
104         /* Clear reset bit and verify it was cleared */
105         FM10K_WRITE_REG(hw, FM10K_VFCTRL, 0);
106         if (FM10K_READ_REG(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
107                 err = FM10K_ERR_RESET_FAILED;
108
109         return err;
110 }
111
112 /**
113  *  fm10k_init_hw_vf - VF hardware initialization
114  *  @hw: pointer to hardware structure
115  *
116  **/
117 STATIC s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
118 {
119         u32 tqdloc, tqdloc0 = ~FM10K_READ_REG(hw, FM10K_TQDLOC(0));
120         s32 err;
121         u16 i;
122
123         DEBUGFUNC("fm10k_init_hw_vf");
124
125         /* assume we always have at least 1 queue */
126         for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
127                 /* verify the Descriptor cache offsets are increasing */
128                 tqdloc = ~FM10K_READ_REG(hw, FM10K_TQDLOC(i));
129                 if (!tqdloc || (tqdloc == tqdloc0))
130                         break;
131
132                 /* check to verify the PF doesn't own any of our queues */
133                 if (!~FM10K_READ_REG(hw, FM10K_TXQCTL(i)) ||
134                     !~FM10K_READ_REG(hw, FM10K_RXQCTL(i)))
135                         break;
136         }
137
138         /* shut down queues we own and reset DMA configuration */
139         err = fm10k_disable_queues_generic(hw, i);
140         if (err)
141                 return err;
142
143         /* record maximum queue count */
144         hw->mac.max_queues = i;
145
146         /* fetch default VLAN */
147         hw->mac.default_vid = (FM10K_READ_REG(hw, FM10K_TXQCTL(0)) &
148                                FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
149
150         return FM10K_SUCCESS;
151 }
152
153 /**
154  *  fm10k_is_slot_appropriate_vf - Indicate appropriate slot for this SKU
155  *  @hw: pointer to hardware structure
156  *
157  *  Looks at the PCIe bus info to confirm whether or not this slot can support
158  *  the necessary bandwidth for this device. Since the VF has no control over
159  *  the "slot" it is in, always indicate that the slot is appropriate.
160  **/
161 STATIC bool fm10k_is_slot_appropriate_vf(struct fm10k_hw *hw)
162 {
163         UNREFERENCED_1PARAMETER(hw);
164         DEBUGFUNC("fm10k_is_slot_appropriate_vf");
165
166         return TRUE;
167 }
168
169 /* This structure defines the attibutes to be parsed below */
170 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
171         FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
172         FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
173         FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
174         FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
175         FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
176         FM10K_TLV_ATTR_LAST
177 };
178
179 /**
180  *  fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
181  *  @hw: pointer to hardware structure
182  *  @vid: VLAN ID to add to table
183  *  @vsi: Reserved, should always be 0
184  *  @set: Indicates if this is a set or clear operation
185  *
186  *  This function adds or removes the corresponding VLAN ID from the VLAN
187  *  filter table for this VF.
188  **/
189 STATIC s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
190 {
191         struct fm10k_mbx_info *mbx = &hw->mbx;
192         u32 msg[4];
193
194         /* verify the index is not set */
195         if (vsi)
196                 return FM10K_ERR_PARAM;
197
198         /* verify upper 4 bits of vid and length are 0 */
199         if ((vid << 16 | vid) >> 28)
200                 return FM10K_ERR_PARAM;
201
202         /* encode set bit into the VLAN ID */
203         if (!set)
204                 vid |= FM10K_VLAN_CLEAR;
205
206         /* generate VLAN request */
207         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
208         fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
209
210         /* load onto outgoing mailbox */
211         return mbx->ops.enqueue_tx(hw, mbx, msg);
212 }
213
214 /**
215  *  fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
216  *  @hw: pointer to the HW structure
217  *  @results: Attributes for message
218  *  @mbx: unused mailbox data
219  *
220  *  This function should determine the MAC address for the VF
221  **/
222 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
223                           struct fm10k_mbx_info *mbx)
224 {
225         u8 perm_addr[ETH_ALEN];
226         u16 vid;
227         s32 err;
228
229         UNREFERENCED_1PARAMETER(mbx);
230         DEBUGFUNC("fm10k_msg_mac_vlan_vf");
231
232         /* record MAC address requested */
233         err = fm10k_tlv_attr_get_mac_vlan(
234                                         results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
235                                         perm_addr, &vid);
236         if (err)
237                 return err;
238
239         memcpy(hw->mac.perm_addr, perm_addr, ETH_ALEN);
240         hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
241         hw->mac.vlan_override = !!(vid & FM10K_VLAN_CLEAR);
242
243         return FM10K_SUCCESS;
244 }
245
246 /**
247  *  fm10k_read_mac_addr_vf - Read device MAC address
248  *  @hw: pointer to the HW structure
249  *
250  *  This function should determine the MAC address for the VF
251  **/
252 STATIC s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
253 {
254         u8 perm_addr[ETH_ALEN];
255         u32 base_addr;
256
257         DEBUGFUNC("fm10k_read_mac_addr_vf");
258
259         base_addr = FM10K_READ_REG(hw, FM10K_TDBAL(0));
260
261         /* last byte should be 0 */
262         if (base_addr << 24)
263                 return  FM10K_ERR_INVALID_MAC_ADDR;
264
265         perm_addr[3] = (u8)(base_addr >> 24);
266         perm_addr[4] = (u8)(base_addr >> 16);
267         perm_addr[5] = (u8)(base_addr >> 8);
268
269         base_addr = FM10K_READ_REG(hw, FM10K_TDBAH(0));
270
271         /* first byte should be all 1's */
272         if ((~base_addr) >> 24)
273                 return  FM10K_ERR_INVALID_MAC_ADDR;
274
275         perm_addr[0] = (u8)(base_addr >> 16);
276         perm_addr[1] = (u8)(base_addr >> 8);
277         perm_addr[2] = (u8)(base_addr);
278
279         memcpy(hw->mac.perm_addr, perm_addr, ETH_ALEN);
280         memcpy(hw->mac.addr, perm_addr, ETH_ALEN);
281
282         return FM10K_SUCCESS;
283 }
284
285 /**
286  *  fm10k_update_uc_addr_vf - Update device unicast addresses
287  *  @hw: pointer to the HW structure
288  *  @glort: unused
289  *  @mac: MAC address to add/remove from table
290  *  @vid: VLAN ID to add/remove from table
291  *  @add: Indicates if this is an add or remove operation
292  *  @flags: flags field to indicate add and secure - unused
293  *
294  *  This function is used to add or remove unicast MAC addresses for
295  *  the VF.
296  **/
297 STATIC s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
298                                    const u8 *mac, u16 vid, bool add, u8 flags)
299 {
300         struct fm10k_mbx_info *mbx = &hw->mbx;
301         u32 msg[7];
302
303         DEBUGFUNC("fm10k_update_uc_addr_vf");
304
305         UNREFERENCED_2PARAMETER(glort, flags);
306
307         /* verify VLAN ID is valid */
308         if (vid >= FM10K_VLAN_TABLE_VID_MAX)
309                 return FM10K_ERR_PARAM;
310
311         /* verify MAC address is valid */
312         if (!FM10K_IS_VALID_ETHER_ADDR(mac))
313                 return FM10K_ERR_PARAM;
314
315         /* verify we are not locked down on the MAC address */
316         if (FM10K_IS_VALID_ETHER_ADDR(hw->mac.perm_addr) &&
317             memcmp(hw->mac.perm_addr, mac, ETH_ALEN))
318                 return FM10K_ERR_PARAM;
319
320         /* add bit to notify us if this is a set or clear operation */
321         if (!add)
322                 vid |= FM10K_VLAN_CLEAR;
323
324         /* generate VLAN request */
325         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
326         fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
327
328         /* load onto outgoing mailbox */
329         return mbx->ops.enqueue_tx(hw, mbx, msg);
330 }
331
332 /**
333  *  fm10k_update_mc_addr_vf - Update device multicast addresses
334  *  @hw: pointer to the HW structure
335  *  @glort: unused
336  *  @mac: MAC address to add/remove from table
337  *  @vid: VLAN ID to add/remove from table
338  *  @add: Indicates if this is an add or remove operation
339  *
340  *  This function is used to add or remove multicast MAC addresses for
341  *  the VF.
342  **/
343 STATIC s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
344                                    const u8 *mac, u16 vid, bool add)
345 {
346         struct fm10k_mbx_info *mbx = &hw->mbx;
347         u32 msg[7];
348
349         DEBUGFUNC("fm10k_update_uc_addr_vf");
350
351         UNREFERENCED_1PARAMETER(glort);
352
353         /* verify VLAN ID is valid */
354         if (vid >= FM10K_VLAN_TABLE_VID_MAX)
355                 return FM10K_ERR_PARAM;
356
357         /* verify multicast address is valid */
358         if (!FM10K_IS_MULTICAST_ETHER_ADDR(mac))
359                 return FM10K_ERR_PARAM;
360
361         /* add bit to notify us if this is a set or clear operation */
362         if (!add)
363                 vid |= FM10K_VLAN_CLEAR;
364
365         /* generate VLAN request */
366         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
367         fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
368                                     mac, vid);
369
370         /* load onto outgoing mailbox */
371         return mbx->ops.enqueue_tx(hw, mbx, msg);
372 }
373
374 /**
375  *  fm10k_update_int_moderator_vf - Request update of interrupt moderator list
376  *  @hw: pointer to hardware structure
377  *
378  *  This function will issue a request to the PF to rescan our MSI-X table
379  *  and to update the interrupt moderator linked list.
380  **/
381 STATIC void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
382 {
383         struct fm10k_mbx_info *mbx = &hw->mbx;
384         u32 msg[1];
385
386         /* generate MSI-X request */
387         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
388
389         /* load onto outgoing mailbox */
390         mbx->ops.enqueue_tx(hw, mbx, msg);
391 }
392
393 /* This structure defines the attibutes to be parsed below */
394 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
395         FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
396         FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
397         FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
398         FM10K_TLV_ATTR_LAST
399 };
400
401 /**
402  *  fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
403  *  @hw: Pointer to hardware structure
404  *  @results: pointer array containing parsed data
405  *  @mbx: Pointer to mailbox information structure
406  *
407  *  This handler is meant to capture the indication from the PF that we
408  *  are ready to bring up the interface.
409  **/
410 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
411                              struct fm10k_mbx_info *mbx)
412 {
413         UNREFERENCED_1PARAMETER(mbx);
414         DEBUGFUNC("fm10k_msg_lport_state_vf");
415
416         hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
417                              FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
418
419         return FM10K_SUCCESS;
420 }
421
422 /**
423  *  fm10k_update_lport_state_vf - Update device state in lower device
424  *  @hw: pointer to the HW structure
425  *  @glort: unused
426  *  @count: number of logical ports to enable - unused (always 1)
427  *  @enable: boolean value indicating if this is an enable or disable request
428  *
429  *  Notify the lower device of a state change.  If the lower device is
430  *  enabled we can add filters, if it is disabled all filters for this
431  *  logical port are flushed.
432  **/
433 STATIC s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
434                                        u16 count, bool enable)
435 {
436         struct fm10k_mbx_info *mbx = &hw->mbx;
437         u32 msg[2];
438
439         UNREFERENCED_2PARAMETER(glort, count);
440         DEBUGFUNC("fm10k_update_lport_state_vf");
441
442         /* reset glort mask 0 as we have to wait to be enabled */
443         hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
444
445         /* generate port state request */
446         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
447         if (!enable)
448                 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
449
450         /* load onto outgoing mailbox */
451         return mbx->ops.enqueue_tx(hw, mbx, msg);
452 }
453
454 /**
455  *  fm10k_update_xcast_mode_vf - Request update of multicast mode
456  *  @hw: pointer to hardware structure
457  *  @glort: unused
458  *  @mode: integer value indicating mode being requested
459  *
460  *  This function will attempt to request a higher mode for the port
461  *  so that it can enable either multicast, multicast promiscuous, or
462  *  promiscuous mode of operation.
463  **/
464 STATIC s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
465 {
466         struct fm10k_mbx_info *mbx = &hw->mbx;
467         u32 msg[3];
468
469         UNREFERENCED_1PARAMETER(glort);
470         DEBUGFUNC("fm10k_update_xcast_mode_vf");
471
472         if (mode > FM10K_XCAST_MODE_NONE)
473                 return FM10K_ERR_PARAM;
474
475         /* generate message requesting to change xcast mode */
476         fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
477         fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
478
479         /* load onto outgoing mailbox */
480         return mbx->ops.enqueue_tx(hw, mbx, msg);
481 }
482
483 const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
484         FM10K_TLV_ATTR_U64(FM10K_1588_MSG_TIMESTAMP),
485         FM10K_TLV_ATTR_LAST
486 };
487
488 /* currently there is no shared 1588 timestamp handler */
489
490 /**
491  *  fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
492  *  @hw: pointer to hardware structure
493  *  @stats: pointer to statistics structure
494  *
495  *  This function collects and aggregates per queue hardware statistics.
496  **/
497 STATIC void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
498                                      struct fm10k_hw_stats *stats)
499 {
500         DEBUGFUNC("fm10k_update_hw_stats_vf");
501
502         fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
503 }
504
505 /**
506  *  fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
507  *  @hw: pointer to hardware structure
508  *  @stats: pointer to the stats structure to update
509  *
510  *  This function resets the base for queue hardware statistics.
511  **/
512 STATIC void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
513                                      struct fm10k_hw_stats *stats)
514 {
515         DEBUGFUNC("fm10k_rebind_hw_stats_vf");
516
517         /* Unbind Queue Statistics */
518         fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
519
520         /* Reinitialize bases for all stats */
521         fm10k_update_hw_stats_vf(hw, stats);
522 }
523
524 /**
525  *  fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
526  *  @hw: pointer to hardware structure
527  *  @dglort: pointer to dglort configuration structure
528  *
529  *  Reads the configuration structure contained in dglort_cfg and uses
530  *  that information to then populate a DGLORTMAP/DEC entry and the queues
531  *  to which it has been assigned.
532  **/
533 STATIC s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
534                                          struct fm10k_dglort_cfg *dglort)
535 {
536         UNREFERENCED_1PARAMETER(hw);
537         DEBUGFUNC("fm10k_configure_dglort_map_vf");
538
539         /* verify the dglort pointer */
540         if (!dglort)
541                 return FM10K_ERR_PARAM;
542
543         /* stub for now until we determine correct message for this */
544
545         return FM10K_SUCCESS;
546 }
547
548 /**
549  *  fm10k_adjust_systime_vf - Adjust systime frequency
550  *  @hw: pointer to hardware structure
551  *  @ppb: adjustment rate in parts per billion
552  *
553  *  This function takes an adjustment rate in parts per billion and will
554  *  verify that this value is 0 as the VF cannot support adjusting the
555  *  systime clock.
556  *
557  *  If the ppb value is non-zero the return is ERR_PARAM else success
558  **/
559 STATIC s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
560 {
561         UNREFERENCED_1PARAMETER(hw);
562         DEBUGFUNC("fm10k_adjust_systime_vf");
563
564         /* The VF cannot adjust the clock frequency, however it should
565          * already have a syntonic clock with whichever host interface is
566          * running as the master for the host interface clock domain so
567          * there should be not frequency adjustment necessary.
568          */
569         return ppb ? FM10K_ERR_PARAM : FM10K_SUCCESS;
570 }
571
572 /**
573  *  fm10k_read_systime_vf - Reads value of systime registers
574  *  @hw: pointer to the hardware structure
575  *
576  *  Function reads the content of 2 registers, combined to represent a 64 bit
577  *  value measured in nanoseconds.  In order to guarantee the value is accurate
578  *  we check the 32 most significant bits both before and after reading the
579  *  32 least significant bits to verify they didn't change as we were reading
580  *  the registers.
581  **/
582 static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
583 {
584         u32 systime_l, systime_h, systime_tmp;
585
586         systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
587
588         do {
589                 systime_tmp = systime_h;
590                 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
591                 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
592         } while (systime_tmp != systime_h);
593
594         return ((u64)systime_h << 32) | systime_l;
595 }
596
597 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
598         FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
599         FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
600         FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
601         FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
602 };
603
604 /**
605  *  fm10k_init_ops_vf - Inits func ptrs and MAC type
606  *  @hw: pointer to hardware structure
607  *
608  *  Initialize the function pointers and assign the MAC type for VF.
609  *  Does not touch the hardware.
610  **/
611 s32 fm10k_init_ops_vf(struct fm10k_hw *hw)
612 {
613         struct fm10k_mac_info *mac = &hw->mac;
614
615         DEBUGFUNC("fm10k_init_ops_vf");
616
617         fm10k_init_ops_generic(hw);
618
619         mac->ops.reset_hw = &fm10k_reset_hw_vf;
620         mac->ops.init_hw = &fm10k_init_hw_vf;
621         mac->ops.start_hw = &fm10k_start_hw_generic;
622         mac->ops.stop_hw = &fm10k_stop_hw_vf;
623         mac->ops.is_slot_appropriate = &fm10k_is_slot_appropriate_vf;
624         mac->ops.update_vlan = &fm10k_update_vlan_vf;
625         mac->ops.read_mac_addr = &fm10k_read_mac_addr_vf;
626         mac->ops.update_uc_addr = &fm10k_update_uc_addr_vf;
627         mac->ops.update_mc_addr = &fm10k_update_mc_addr_vf;
628         mac->ops.update_xcast_mode = &fm10k_update_xcast_mode_vf;
629         mac->ops.update_int_moderator = &fm10k_update_int_moderator_vf;
630         mac->ops.update_lport_state = &fm10k_update_lport_state_vf;
631         mac->ops.update_hw_stats = &fm10k_update_hw_stats_vf;
632         mac->ops.rebind_hw_stats = &fm10k_rebind_hw_stats_vf;
633         mac->ops.configure_dglort_map = &fm10k_configure_dglort_map_vf;
634         mac->ops.get_host_state = &fm10k_get_host_state_generic;
635         mac->ops.adjust_systime = &fm10k_adjust_systime_vf;
636         mac->ops.read_systime = &fm10k_read_systime_vf,
637
638         mac->max_msix_vectors = fm10k_get_pcie_msix_count_generic(hw);
639
640         return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);
641 }