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