Print this page
    
3014 Intel X540 Support (fix lint)
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/io/ixgbe/ixgbe_mbx.c
          +++ new/usr/src/uts/common/io/ixgbe/ixgbe_mbx.c
   1    1  /******************************************************************************
   2    2  
   3    3    Copyright (c) 2001-2012, Intel Corporation 
   4    4    All rights reserved.
   5    5    
   6    6    Redistribution and use in source and binary forms, with or without 
   7    7    modification, are permitted provided that the following conditions are met:
   8    8    
   9    9     1. Redistributions of source code must retain the above copyright notice, 
  10   10        this list of conditions and the following disclaimer.
  11   11    
  12   12     2. Redistributions in binary form must reproduce the above copyright 
  13   13        notice, this list of conditions and the following disclaimer in the 
  14   14        documentation and/or other materials provided with the distribution.
  15   15    
  16   16     3. Neither the name of the Intel Corporation nor the names of its 
  17   17        contributors may be used to endorse or promote products derived from 
  18   18        this software without specific prior written permission.
  19   19    
  20   20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21   21    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  22   22    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  23   23    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  24   24    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  25   25    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  26   26    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  27   27    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  28   28    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  29   29    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30   30    POSSIBILITY OF SUCH DAMAGE.
  31   31  
  32   32  ******************************************************************************/
  33   33  /*$FreeBSD$*/
  34   34  
  35   35  #include "ixgbe_type.h"
  36   36  #include "ixgbe_mbx.h"
  37   37  
  38   38  /**
  39   39   *  ixgbe_read_mbx - Reads a message from the mailbox
  40   40   *  @hw: pointer to the HW structure
  41   41   *  @msg: The message buffer
  42   42   *  @size: Length of buffer
  43   43   *  @mbx_id: id of mailbox to read
  44   44   *
  45   45   *  returns SUCCESS if it successfuly read message from buffer
  46   46   **/
  47   47  s32 ixgbe_read_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
  48   48  {
  49   49          struct ixgbe_mbx_info *mbx = &hw->mbx;
  50   50          s32 ret_val = IXGBE_ERR_MBX;
  51   51  
  52   52          DEBUGFUNC("ixgbe_read_mbx");
  53   53  
  54   54          /* limit read to size of mailbox */
  55   55          if (size > mbx->size)
  56   56                  size = mbx->size;
  57   57  
  58   58          if (mbx->ops.read)
  59   59                  ret_val = mbx->ops.read(hw, msg, size, mbx_id);
  60   60  
  61   61          return ret_val;
  62   62  }
  63   63  
  64   64  /**
  65   65   *  ixgbe_write_mbx - Write a message to the mailbox
  66   66   *  @hw: pointer to the HW structure
  67   67   *  @msg: The message buffer
  68   68   *  @size: Length of buffer
  69   69   *  @mbx_id: id of mailbox to write
  70   70   *
  71   71   *  returns SUCCESS if it successfully copied message into the buffer
  72   72   **/
  73   73  s32 ixgbe_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
  74   74  {
  75   75          struct ixgbe_mbx_info *mbx = &hw->mbx;
  76   76          s32 ret_val = IXGBE_SUCCESS;
  77   77  
  78   78          DEBUGFUNC("ixgbe_write_mbx");
  79   79  
  80   80          if (size > mbx->size)
  81   81                  ret_val = IXGBE_ERR_MBX;
  82   82  
  83   83          else if (mbx->ops.write)
  84   84                  ret_val = mbx->ops.write(hw, msg, size, mbx_id);
  85   85  
  86   86          return ret_val;
  87   87  }
  88   88  
  89   89  /**
  90   90   *  ixgbe_check_for_msg - checks to see if someone sent us mail
  91   91   *  @hw: pointer to the HW structure
  92   92   *  @mbx_id: id of mailbox to check
  93   93   *
  94   94   *  returns SUCCESS if the Status bit was found or else ERR_MBX
  95   95   **/
  96   96  s32 ixgbe_check_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
  97   97  {
  98   98          struct ixgbe_mbx_info *mbx = &hw->mbx;
  99   99          s32 ret_val = IXGBE_ERR_MBX;
 100  100  
 101  101          DEBUGFUNC("ixgbe_check_for_msg");
 102  102  
 103  103          if (mbx->ops.check_for_msg)
 104  104                  ret_val = mbx->ops.check_for_msg(hw, mbx_id);
 105  105  
 106  106          return ret_val;
 107  107  }
 108  108  
 109  109  /**
 110  110   *  ixgbe_check_for_ack - checks to see if someone sent us ACK
 111  111   *  @hw: pointer to the HW structure
 112  112   *  @mbx_id: id of mailbox to check
 113  113   *
 114  114   *  returns SUCCESS if the Status bit was found or else ERR_MBX
 115  115   **/
 116  116  s32 ixgbe_check_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
 117  117  {
 118  118          struct ixgbe_mbx_info *mbx = &hw->mbx;
 119  119          s32 ret_val = IXGBE_ERR_MBX;
 120  120  
 121  121          DEBUGFUNC("ixgbe_check_for_ack");
 122  122  
 123  123          if (mbx->ops.check_for_ack)
 124  124                  ret_val = mbx->ops.check_for_ack(hw, mbx_id);
 125  125  
 126  126          return ret_val;
 127  127  }
 128  128  
 129  129  /**
 130  130   *  ixgbe_check_for_rst - checks to see if other side has reset
 131  131   *  @hw: pointer to the HW structure
 132  132   *  @mbx_id: id of mailbox to check
 133  133   *
 134  134   *  returns SUCCESS if the Status bit was found or else ERR_MBX
 135  135   **/
 136  136  s32 ixgbe_check_for_rst(struct ixgbe_hw *hw, u16 mbx_id)
 137  137  {
 138  138          struct ixgbe_mbx_info *mbx = &hw->mbx;
 139  139          s32 ret_val = IXGBE_ERR_MBX;
 140  140  
 141  141          DEBUGFUNC("ixgbe_check_for_rst");
 142  142  
 143  143          if (mbx->ops.check_for_rst)
 144  144                  ret_val = mbx->ops.check_for_rst(hw, mbx_id);
 145  145  
 146  146          return ret_val;
 147  147  }
 148  148  
 149  149  /**
 150  150   *  ixgbe_poll_for_msg - Wait for message notification
 151  151   *  @hw: pointer to the HW structure
 152  152   *  @mbx_id: id of mailbox to write
 153  153   *
 154  154   *  returns SUCCESS if it successfully received a message notification
 155  155   **/
 156  156  static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
 157  157  {
 158  158          struct ixgbe_mbx_info *mbx = &hw->mbx;
 159  159          int countdown = mbx->timeout;
 160  160  
 161  161          DEBUGFUNC("ixgbe_poll_for_msg");
 162  162  
 163  163          if (!countdown || !mbx->ops.check_for_msg)
 164  164                  goto out;
 165  165  
 166  166          while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
 167  167                  countdown--;
 168  168                  if (!countdown)
 169  169                          break;
 170  170                  usec_delay(mbx->usec_delay);
 171  171          }
 172  172  
 173  173  out:
 174  174          return countdown ? IXGBE_SUCCESS : IXGBE_ERR_MBX;
 175  175  }
 176  176  
 177  177  /**
 178  178   *  ixgbe_poll_for_ack - Wait for message acknowledgement
 179  179   *  @hw: pointer to the HW structure
 180  180   *  @mbx_id: id of mailbox to write
 181  181   *
 182  182   *  returns SUCCESS if it successfully received a message acknowledgement
 183  183   **/
 184  184  static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
 185  185  {
 186  186          struct ixgbe_mbx_info *mbx = &hw->mbx;
 187  187          int countdown = mbx->timeout;
 188  188  
 189  189          DEBUGFUNC("ixgbe_poll_for_ack");
 190  190  
 191  191          if (!countdown || !mbx->ops.check_for_ack)
 192  192                  goto out;
 193  193  
 194  194          while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
 195  195                  countdown--;
 196  196                  if (!countdown)
 197  197                          break;
 198  198                  usec_delay(mbx->usec_delay);
 199  199          }
 200  200  
 201  201  out:
 202  202          return countdown ? IXGBE_SUCCESS : IXGBE_ERR_MBX;
 203  203  }
 204  204  
 205  205  /**
 206  206   *  ixgbe_read_posted_mbx - Wait for message notification and receive message
 207  207   *  @hw: pointer to the HW structure
 208  208   *  @msg: The message buffer
 209  209   *  @size: Length of buffer
 210  210   *  @mbx_id: id of mailbox to write
 211  211   *
 212  212   *  returns SUCCESS if it successfully received a message notification and
 213  213   *  copied it into the receive buffer.
 214  214   **/
 215  215  s32 ixgbe_read_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
 216  216  {
 217  217          struct ixgbe_mbx_info *mbx = &hw->mbx;
 218  218          s32 ret_val = IXGBE_ERR_MBX;
 219  219  
 220  220          DEBUGFUNC("ixgbe_read_posted_mbx");
 221  221  
 222  222          if (!mbx->ops.read)
 223  223                  goto out;
 224  224  
 225  225          ret_val = ixgbe_poll_for_msg(hw, mbx_id);
 226  226  
 227  227          /* if ack received read message, otherwise we timed out */
 228  228          if (!ret_val)
 229  229                  ret_val = mbx->ops.read(hw, msg, size, mbx_id);
 230  230  out:
 231  231          return ret_val;
 232  232  }
 233  233  
 234  234  /**
 235  235   *  ixgbe_write_posted_mbx - Write a message to the mailbox, wait for ack
 236  236   *  @hw: pointer to the HW structure
 237  237   *  @msg: The message buffer
 238  238   *  @size: Length of buffer
 239  239   *  @mbx_id: id of mailbox to write
 240  240   *
 241  241   *  returns SUCCESS if it successfully copied message into the buffer and
 242  242   *  received an ack to that message within delay * timeout period
 243  243   **/
 244  244  s32 ixgbe_write_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size,
 245  245                             u16 mbx_id)
 246  246  {
 247  247          struct ixgbe_mbx_info *mbx = &hw->mbx;
 248  248          s32 ret_val = IXGBE_ERR_MBX;
 249  249  
 250  250          DEBUGFUNC("ixgbe_write_posted_mbx");
 251  251  
 252  252          /* exit if either we can't write or there isn't a defined timeout */
 253  253          if (!mbx->ops.write || !mbx->timeout)
 254  254                  goto out;
 255  255  
 256  256          /* send msg */
 257  257          ret_val = mbx->ops.write(hw, msg, size, mbx_id);
 258  258  
 259  259          /* if msg sent wait until we receive an ack */
 260  260          if (!ret_val)
 261  261                  ret_val = ixgbe_poll_for_ack(hw, mbx_id);
 262  262  out:
 263  263          return ret_val;
 264  264  }
 265  265  
 266  266  /**
 267  267   *  ixgbe_init_mbx_ops_generic - Initialize MB function pointers
 268  268   *  @hw: pointer to the HW structure
 269  269   *
 270  270   *  Setups up the mailbox read and write message function pointers
 271  271   **/
 272  272  void ixgbe_init_mbx_ops_generic(struct ixgbe_hw *hw)
 273  273  {
 274  274          struct ixgbe_mbx_info *mbx = &hw->mbx;
 275  275  
 276  276          mbx->ops.read_posted = ixgbe_read_posted_mbx;
 277  277          mbx->ops.write_posted = ixgbe_write_posted_mbx;
 278  278  }
 279  279  
 280  280  /**
 281  281   *  ixgbe_read_v2p_mailbox - read v2p mailbox
 282  282   *  @hw: pointer to the HW structure
 283  283   *
 284  284   *  This function is used to read the v2p mailbox without losing the read to
 285  285   *  clear status bits.
 286  286   **/
 287  287  static u32 ixgbe_read_v2p_mailbox(struct ixgbe_hw *hw)
 288  288  {
 289  289          u32 v2p_mailbox = IXGBE_READ_REG(hw, IXGBE_VFMAILBOX);
 290  290  
 291  291          v2p_mailbox |= hw->mbx.v2p_mailbox;
 292  292          hw->mbx.v2p_mailbox |= v2p_mailbox & IXGBE_VFMAILBOX_R2C_BITS;
 293  293  
 294  294          return v2p_mailbox;
 295  295  }
 296  296  
 297  297  /**
 298  298   *  ixgbe_check_for_bit_vf - Determine if a status bit was set
 299  299   *  @hw: pointer to the HW structure
 300  300   *  @mask: bitmask for bits to be tested and cleared
 301  301   *
 302  302   *  This function is used to check for the read to clear bits within
 303  303   *  the V2P mailbox.
 304  304   **/
 305  305  static s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
 306  306  {
 307  307          u32 v2p_mailbox = ixgbe_read_v2p_mailbox(hw);
 308  308          s32 ret_val = IXGBE_ERR_MBX;
 309  309  
 310  310          if (v2p_mailbox & mask)
 311  311                  ret_val = IXGBE_SUCCESS;
 312  312  
 313  313          hw->mbx.v2p_mailbox &= ~mask;
 314  314  
 315  315          return ret_val;
 316  316  }
 317  317  
 318  318  /**
 319  319   *  ixgbe_check_for_msg_vf - checks to see if the PF has sent mail
 320  320   *  @hw: pointer to the HW structure
 321  321   *  @mbx_id: id of mailbox to check
 322  322   *
 323  323   *  returns SUCCESS if the PF has set the Status bit or else ERR_MBX
 324  324   **/
 325  325  static s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
 326  326  {
 327  327          s32 ret_val = IXGBE_ERR_MBX;
 328  328  
 329  329          UNREFERENCED_1PARAMETER(mbx_id);
 330  330          DEBUGFUNC("ixgbe_check_for_msg_vf");
 331  331  
 332  332          if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFSTS)) {
 333  333                  ret_val = IXGBE_SUCCESS;
 334  334                  hw->mbx.stats.reqs++;
 335  335          }
 336  336  
 337  337          return ret_val;
 338  338  }
 339  339  
 340  340  /**
 341  341   *  ixgbe_check_for_ack_vf - checks to see if the PF has ACK'd
 342  342   *  @hw: pointer to the HW structure
 343  343   *  @mbx_id: id of mailbox to check
 344  344   *
 345  345   *  returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
 346  346   **/
 347  347  static s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
 348  348  {
 349  349          s32 ret_val = IXGBE_ERR_MBX;
 350  350  
 351  351          UNREFERENCED_1PARAMETER(mbx_id);
 352  352          DEBUGFUNC("ixgbe_check_for_ack_vf");
 353  353  
 354  354          if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFACK)) {
 355  355                  ret_val = IXGBE_SUCCESS;
 356  356                  hw->mbx.stats.acks++;
 357  357          }
 358  358  
 359  359          return ret_val;
 360  360  }
 361  361  
 362  362  /**
 363  363   *  ixgbe_check_for_rst_vf - checks to see if the PF has reset
 364  364   *  @hw: pointer to the HW structure
 365  365   *  @mbx_id: id of mailbox to check
 366  366   *
 367  367   *  returns TRUE if the PF has set the reset done bit or else FALSE
 368  368   **/
 369  369  static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
 370  370  {
 371  371          s32 ret_val = IXGBE_ERR_MBX;
 372  372  
 373  373          UNREFERENCED_1PARAMETER(mbx_id);
 374  374          DEBUGFUNC("ixgbe_check_for_rst_vf");
 375  375  
 376  376          if (!ixgbe_check_for_bit_vf(hw, (IXGBE_VFMAILBOX_RSTD |
 377  377              IXGBE_VFMAILBOX_RSTI))) {
 378  378                  ret_val = IXGBE_SUCCESS;
 379  379                  hw->mbx.stats.rsts++;
 380  380          }
 381  381  
 382  382          return ret_val;
 383  383  }
 384  384  
 385  385  /**
 386  386   *  ixgbe_obtain_mbx_lock_vf - obtain mailbox lock
 387  387   *  @hw: pointer to the HW structure
 388  388   *
 389  389   *  return SUCCESS if we obtained the mailbox lock
 390  390   **/
 391  391  static s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
 392  392  {
 393  393          s32 ret_val = IXGBE_ERR_MBX;
 394  394  
 395  395          DEBUGFUNC("ixgbe_obtain_mbx_lock_vf");
 396  396  
 397  397          /* Take ownership of the buffer */
 398  398          IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_VFU);
 399  399  
 400  400          /* reserve mailbox for vf use */
 401  401          if (ixgbe_read_v2p_mailbox(hw) & IXGBE_VFMAILBOX_VFU)
 402  402                  ret_val = IXGBE_SUCCESS;
 403  403  
 404  404          return ret_val;
 405  405  }
 406  406  
 407  407  /**
 408  408   *  ixgbe_write_mbx_vf - Write a message to the mailbox
 409  409   *  @hw: pointer to the HW structure
 410  410   *  @msg: The message buffer
 411  411   *  @size: Length of buffer
 412  412   *  @mbx_id: id of mailbox to write
 413  413   *
 414  414   *  returns SUCCESS if it successfully copied message into the buffer
 415  415   **/
 416  416  static s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
 417  417                                u16 mbx_id)
 418  418  {
 419  419          s32 ret_val;
 420  420          u16 i;
 421  421  
  
    | 
      ↓ open down ↓ | 
    421 lines elided | 
    
      ↑ open up ↑ | 
  
 422  422          UNREFERENCED_1PARAMETER(mbx_id);
 423  423  
 424  424          DEBUGFUNC("ixgbe_write_mbx_vf");
 425  425  
 426  426          /* lock the mailbox to prevent pf/vf race condition */
 427  427          ret_val = ixgbe_obtain_mbx_lock_vf(hw);
 428  428          if (ret_val)
 429  429                  goto out_no_write;
 430  430  
 431  431          /* flush msg and acks as we are overwriting the message buffer */
 432      -        ixgbe_check_for_msg_vf(hw, 0);
 433      -        ixgbe_check_for_ack_vf(hw, 0);
      432 +        ret_val = ixgbe_check_for_msg_vf(hw, 0);
      433 +        if (ret_val)
      434 +                goto out_no_write;
      435 +        ret_val = ixgbe_check_for_ack_vf(hw, 0);
      436 +        if (ret_val)
      437 +                goto out_no_write;
 434  438  
 435  439          /* copy the caller specified message to the mailbox memory buffer */
 436  440          for (i = 0; i < size; i++)
 437  441                  IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
 438  442  
 439  443          /* update stats */
 440  444          hw->mbx.stats.msgs_tx++;
 441  445  
 442  446          /* Drop VFU and interrupt the PF to tell it a message has been sent */
 443  447          IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_REQ);
 444  448  
 445  449  out_no_write:
 446  450          return ret_val;
 447  451  }
 448  452  
 449  453  /**
 450  454   *  ixgbe_read_mbx_vf - Reads a message from the inbox intended for vf
 451  455   *  @hw: pointer to the HW structure
 452  456   *  @msg: The message buffer
 453  457   *  @size: Length of buffer
 454  458   *  @mbx_id: id of mailbox to read
 455  459   *
 456  460   *  returns SUCCESS if it successfuly read message from buffer
 457  461   **/
 458  462  static s32 ixgbe_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
 459  463                               u16 mbx_id)
 460  464  {
 461  465          s32 ret_val = IXGBE_SUCCESS;
 462  466          u16 i;
 463  467  
 464  468          DEBUGFUNC("ixgbe_read_mbx_vf");
 465  469          UNREFERENCED_1PARAMETER(mbx_id);
 466  470  
 467  471          /* lock the mailbox to prevent pf/vf race condition */
 468  472          ret_val = ixgbe_obtain_mbx_lock_vf(hw);
 469  473          if (ret_val)
 470  474                  goto out_no_read;
 471  475  
 472  476          /* copy the message from the mailbox memory buffer */
 473  477          for (i = 0; i < size; i++)
 474  478                  msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i);
 475  479  
 476  480          /* Acknowledge receipt and release mailbox, then we're done */
 477  481          IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_ACK);
 478  482  
 479  483          /* update stats */
 480  484          hw->mbx.stats.msgs_rx++;
 481  485  
 482  486  out_no_read:
 483  487          return ret_val;
 484  488  }
 485  489  
 486  490  /**
 487  491   *  ixgbe_init_mbx_params_vf - set initial values for vf mailbox
 488  492   *  @hw: pointer to the HW structure
 489  493   *
 490  494   *  Initializes the hw->mbx struct to correct values for vf mailbox
 491  495   */
 492  496  void ixgbe_init_mbx_params_vf(struct ixgbe_hw *hw)
 493  497  {
 494  498          struct ixgbe_mbx_info *mbx = &hw->mbx;
 495  499  
 496  500          /* start mailbox as timed out and let the reset_hw call set the timeout
 497  501           * value to begin communications */
 498  502          mbx->timeout = 0;
 499  503          mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
 500  504  
 501  505          mbx->size = IXGBE_VFMAILBOX_SIZE;
 502  506  
 503  507          mbx->ops.read = ixgbe_read_mbx_vf;
 504  508          mbx->ops.write = ixgbe_write_mbx_vf;
 505  509          mbx->ops.read_posted = ixgbe_read_posted_mbx;
 506  510          mbx->ops.write_posted = ixgbe_write_posted_mbx;
 507  511          mbx->ops.check_for_msg = ixgbe_check_for_msg_vf;
 508  512          mbx->ops.check_for_ack = ixgbe_check_for_ack_vf;
 509  513          mbx->ops.check_for_rst = ixgbe_check_for_rst_vf;
 510  514  
 511  515          mbx->stats.msgs_tx = 0;
 512  516          mbx->stats.msgs_rx = 0;
 513  517          mbx->stats.reqs = 0;
 514  518          mbx->stats.acks = 0;
 515  519          mbx->stats.rsts = 0;
 516  520  }
 517  521  
 518  522  static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
 519  523  {
 520  524          u32 mbvficr = IXGBE_READ_REG(hw, IXGBE_MBVFICR(index));
 521  525          s32 ret_val = IXGBE_ERR_MBX;
 522  526  
 523  527          if (mbvficr & mask) {
 524  528                  ret_val = IXGBE_SUCCESS;
 525  529                  IXGBE_WRITE_REG(hw, IXGBE_MBVFICR(index), mask);
 526  530          }
 527  531  
 528  532          return ret_val;
 529  533  }
 530  534  
 531  535  /**
 532  536   *  ixgbe_check_for_msg_pf - checks to see if the VF has sent mail
 533  537   *  @hw: pointer to the HW structure
 534  538   *  @vf_number: the VF index
 535  539   *
 536  540   *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
 537  541   **/
 538  542  static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number)
 539  543  {
 540  544          s32 ret_val = IXGBE_ERR_MBX;
 541  545          s32 index = IXGBE_MBVFICR_INDEX(vf_number);
 542  546          u32 vf_bit = vf_number % 16;
 543  547  
 544  548          DEBUGFUNC("ixgbe_check_for_msg_pf");
 545  549  
 546  550          if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFREQ_VF1 << vf_bit,
 547  551                                      index)) {
 548  552                  ret_val = IXGBE_SUCCESS;
 549  553                  hw->mbx.stats.reqs++;
 550  554          }
 551  555  
 552  556          return ret_val;
 553  557  }
 554  558  
 555  559  /**
 556  560   *  ixgbe_check_for_ack_pf - checks to see if the VF has ACKed
 557  561   *  @hw: pointer to the HW structure
 558  562   *  @vf_number: the VF index
 559  563   *
 560  564   *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
 561  565   **/
 562  566  static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number)
 563  567  {
 564  568          s32 ret_val = IXGBE_ERR_MBX;
 565  569          s32 index = IXGBE_MBVFICR_INDEX(vf_number);
 566  570          u32 vf_bit = vf_number % 16;
 567  571  
 568  572          DEBUGFUNC("ixgbe_check_for_ack_pf");
 569  573  
 570  574          if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFACK_VF1 << vf_bit,
 571  575                                      index)) {
 572  576                  ret_val = IXGBE_SUCCESS;
 573  577                  hw->mbx.stats.acks++;
 574  578          }
 575  579  
 576  580          return ret_val;
 577  581  }
 578  582  
 579  583  /**
 580  584   *  ixgbe_check_for_rst_pf - checks to see if the VF has reset
 581  585   *  @hw: pointer to the HW structure
 582  586   *  @vf_number: the VF index
 583  587   *
 584  588   *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
 585  589   **/
 586  590  static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number)
 587  591  {
 588  592          u32 reg_offset = (vf_number < 32) ? 0 : 1;
 589  593          u32 vf_shift = vf_number % 32;
 590  594          u32 vflre = 0;
 591  595          s32 ret_val = IXGBE_ERR_MBX;
 592  596  
 593  597          DEBUGFUNC("ixgbe_check_for_rst_pf");
 594  598  
 595  599          switch (hw->mac.type) {
 596  600          case ixgbe_mac_82599EB:
 597  601                  vflre = IXGBE_READ_REG(hw, IXGBE_VFLRE(reg_offset));
 598  602                  break;
 599  603          case ixgbe_mac_X540:
 600  604                  vflre = IXGBE_READ_REG(hw, IXGBE_VFLREC(reg_offset));
 601  605                  break;
 602  606          default:
 603  607                  break;
 604  608          }
 605  609  
 606  610          if (vflre & (1 << vf_shift)) {
 607  611                  ret_val = IXGBE_SUCCESS;
 608  612                  IXGBE_WRITE_REG(hw, IXGBE_VFLREC(reg_offset), (1 << vf_shift));
 609  613                  hw->mbx.stats.rsts++;
 610  614          }
 611  615  
 612  616          return ret_val;
 613  617  }
 614  618  
 615  619  /**
 616  620   *  ixgbe_obtain_mbx_lock_pf - obtain mailbox lock
 617  621   *  @hw: pointer to the HW structure
 618  622   *  @vf_number: the VF index
 619  623   *
 620  624   *  return SUCCESS if we obtained the mailbox lock
 621  625   **/
 622  626  static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number)
 623  627  {
 624  628          s32 ret_val = IXGBE_ERR_MBX;
 625  629          u32 p2v_mailbox;
 626  630  
 627  631          DEBUGFUNC("ixgbe_obtain_mbx_lock_pf");
 628  632  
 629  633          /* Take ownership of the buffer */
 630  634          IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_PFU);
 631  635  
 632  636          /* reserve mailbox for vf use */
 633  637          p2v_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_number));
 634  638          if (p2v_mailbox & IXGBE_PFMAILBOX_PFU)
 635  639                  ret_val = IXGBE_SUCCESS;
 636  640  
 637  641          return ret_val;
 638  642  }
 639  643  
 640  644  /**
 641  645   *  ixgbe_write_mbx_pf - Places a message in the mailbox
 642  646   *  @hw: pointer to the HW structure
 643  647   *  @msg: The message buffer
 644  648   *  @size: Length of buffer
 645  649   *  @vf_number: the VF index
 646  650   *
 647  651   *  returns SUCCESS if it successfully copied message into the buffer
 648  652   **/
 649  653  static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
 650  654                                u16 vf_number)
 651  655  {
 652  656          s32 ret_val;
  
    | 
      ↓ open down ↓ | 
    209 lines elided | 
    
      ↑ open up ↑ | 
  
 653  657          u16 i;
 654  658  
 655  659          DEBUGFUNC("ixgbe_write_mbx_pf");
 656  660  
 657  661          /* lock the mailbox to prevent pf/vf race condition */
 658  662          ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_number);
 659  663          if (ret_val)
 660  664                  goto out_no_write;
 661  665  
 662  666          /* flush msg and acks as we are overwriting the message buffer */
 663      -        ixgbe_check_for_msg_pf(hw, vf_number);
 664      -        ixgbe_check_for_ack_pf(hw, vf_number);
      667 +        ret_val = ixgbe_check_for_msg_vf(hw, 0);
      668 +        if (ret_val)
      669 +                goto out_no_write;
      670 +        ret_val = ixgbe_check_for_ack_vf(hw, 0);
      671 +        if (ret_val)
      672 +                goto out_no_write;
 665  673  
 666  674          /* copy the caller specified message to the mailbox memory buffer */
 667  675          for (i = 0; i < size; i++)
 668  676                  IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i, msg[i]);
 669  677  
 670  678          /* Interrupt VF to tell it a message has been sent and release buffer*/
 671  679          IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_STS);
 672  680  
 673  681          /* update stats */
 674  682          hw->mbx.stats.msgs_tx++;
 675  683  
 676  684  out_no_write:
 677  685          return ret_val;
 678  686  
 679  687  }
 680  688  
 681  689  /**
 682  690   *  ixgbe_read_mbx_pf - Read a message from the mailbox
 683  691   *  @hw: pointer to the HW structure
 684  692   *  @msg: The message buffer
 685  693   *  @size: Length of buffer
 686  694   *  @vf_number: the VF index
 687  695   *
 688  696   *  This function copies a message from the mailbox buffer to the caller's
 689  697   *  memory buffer.  The presumption is that the caller knows that there was
 690  698   *  a message due to a VF request so no polling for message is needed.
 691  699   **/
 692  700  static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
 693  701                               u16 vf_number)
 694  702  {
 695  703          s32 ret_val;
 696  704          u16 i;
 697  705  
 698  706          DEBUGFUNC("ixgbe_read_mbx_pf");
 699  707  
 700  708          /* lock the mailbox to prevent pf/vf race condition */
 701  709          ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_number);
 702  710          if (ret_val)
 703  711                  goto out_no_read;
 704  712  
 705  713          /* copy the message to the mailbox memory buffer */
 706  714          for (i = 0; i < size; i++)
 707  715                  msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i);
 708  716  
 709  717          /* Acknowledge the message and release buffer */
 710  718          IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_ACK);
 711  719  
 712  720          /* update stats */
 713  721          hw->mbx.stats.msgs_rx++;
 714  722  
 715  723  out_no_read:
 716  724          return ret_val;
 717  725  }
 718  726  
 719  727  /**
 720  728   *  ixgbe_init_mbx_params_pf - set initial values for pf mailbox
 721  729   *  @hw: pointer to the HW structure
 722  730   *
 723  731   *  Initializes the hw->mbx struct to correct values for pf mailbox
 724  732   */
 725  733  void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw)
 726  734  {
 727  735          struct ixgbe_mbx_info *mbx = &hw->mbx;
 728  736  
 729  737          if (hw->mac.type != ixgbe_mac_82599EB &&
 730  738              hw->mac.type != ixgbe_mac_X540)
 731  739                  return;
 732  740  
 733  741          mbx->timeout = 0;
 734  742          mbx->usec_delay = 0;
 735  743  
 736  744          mbx->size = IXGBE_VFMAILBOX_SIZE;
 737  745  
 738  746          mbx->ops.read = ixgbe_read_mbx_pf;
 739  747          mbx->ops.write = ixgbe_write_mbx_pf;
 740  748          mbx->ops.read_posted = ixgbe_read_posted_mbx;
 741  749          mbx->ops.write_posted = ixgbe_write_posted_mbx;
 742  750          mbx->ops.check_for_msg = ixgbe_check_for_msg_pf;
 743  751          mbx->ops.check_for_ack = ixgbe_check_for_ack_pf;
 744  752          mbx->ops.check_for_rst = ixgbe_check_for_rst_pf;
 745  753  
 746  754          mbx->stats.msgs_tx = 0;
 747  755          mbx->stats.msgs_rx = 0;
 748  756          mbx->stats.reqs = 0;
 749  757          mbx->stats.acks = 0;
 750  758          mbx->stats.rsts = 0;
 751  759  }
  
    | 
      ↓ open down ↓ | 
    77 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX