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