Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ixgbevf: Mailbox communication

The 82599 virtual function device and the master 82599 physical function
device implement a mailbox utility for communication between the devices
using some SRAM scratch memory and a doorbell/answering mechanism enabled
via interrupt and/or polling. This C module and accompanying header
file implement the base functions for use of this feature.

Signed-off-by: Greg Rose <gregory.v.rose@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Greg Rose and committed by
David S. Miller
cbf698db 3047f90b

+441
+341
drivers/net/ixgbevf/mbx.c
··· 1 + /******************************************************************************* 2 + 3 + Intel 82599 Virtual Function driver 4 + Copyright(c) 1999 - 2009 Intel Corporation. 5 + 6 + This program is free software; you can redistribute it and/or modify it 7 + under the terms and conditions of the GNU General Public License, 8 + version 2, as published by the Free Software Foundation. 9 + 10 + This program is distributed in the hope it will be useful, but WITHOUT 11 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + more details. 14 + 15 + You should have received a copy of the GNU General Public License along with 16 + this program; if not, write to the Free Software Foundation, Inc., 17 + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 + 19 + The full GNU General Public License is included in this distribution in 20 + the file called "COPYING". 21 + 22 + Contact Information: 23 + e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 + Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 + 26 + *******************************************************************************/ 27 + 28 + #include "mbx.h" 29 + 30 + /** 31 + * ixgbevf_poll_for_msg - Wait for message notification 32 + * @hw: pointer to the HW structure 33 + * 34 + * returns 0 if it successfully received a message notification 35 + **/ 36 + static s32 ixgbevf_poll_for_msg(struct ixgbe_hw *hw) 37 + { 38 + struct ixgbe_mbx_info *mbx = &hw->mbx; 39 + int countdown = mbx->timeout; 40 + 41 + while (countdown && mbx->ops.check_for_msg(hw)) { 42 + countdown--; 43 + udelay(mbx->udelay); 44 + } 45 + 46 + /* if we failed, all future posted messages fail until reset */ 47 + if (!countdown) 48 + mbx->timeout = 0; 49 + 50 + return countdown ? 0 : IXGBE_ERR_MBX; 51 + } 52 + 53 + /** 54 + * ixgbevf_poll_for_ack - Wait for message acknowledgement 55 + * @hw: pointer to the HW structure 56 + * 57 + * returns 0 if it successfully received a message acknowledgement 58 + **/ 59 + static s32 ixgbevf_poll_for_ack(struct ixgbe_hw *hw) 60 + { 61 + struct ixgbe_mbx_info *mbx = &hw->mbx; 62 + int countdown = mbx->timeout; 63 + 64 + while (countdown && mbx->ops.check_for_ack(hw)) { 65 + countdown--; 66 + udelay(mbx->udelay); 67 + } 68 + 69 + /* if we failed, all future posted messages fail until reset */ 70 + if (!countdown) 71 + mbx->timeout = 0; 72 + 73 + return countdown ? 0 : IXGBE_ERR_MBX; 74 + } 75 + 76 + /** 77 + * ixgbevf_read_posted_mbx - Wait for message notification and receive message 78 + * @hw: pointer to the HW structure 79 + * @msg: The message buffer 80 + * @size: Length of buffer 81 + * 82 + * returns 0 if it successfully received a message notification and 83 + * copied it into the receive buffer. 84 + **/ 85 + static s32 ixgbevf_read_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size) 86 + { 87 + struct ixgbe_mbx_info *mbx = &hw->mbx; 88 + s32 ret_val = IXGBE_ERR_MBX; 89 + 90 + ret_val = ixgbevf_poll_for_msg(hw); 91 + 92 + /* if ack received read message, otherwise we timed out */ 93 + if (!ret_val) 94 + ret_val = mbx->ops.read(hw, msg, size); 95 + 96 + return ret_val; 97 + } 98 + 99 + /** 100 + * ixgbevf_write_posted_mbx - Write a message to the mailbox, wait for ack 101 + * @hw: pointer to the HW structure 102 + * @msg: The message buffer 103 + * @size: Length of buffer 104 + * 105 + * returns 0 if it successfully copied message into the buffer and 106 + * received an ack to that message within delay * timeout period 107 + **/ 108 + static s32 ixgbevf_write_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size) 109 + { 110 + struct ixgbe_mbx_info *mbx = &hw->mbx; 111 + s32 ret_val; 112 + 113 + /* send msg */ 114 + ret_val = mbx->ops.write(hw, msg, size); 115 + 116 + /* if msg sent wait until we receive an ack */ 117 + if (!ret_val) 118 + ret_val = ixgbevf_poll_for_ack(hw); 119 + 120 + return ret_val; 121 + } 122 + 123 + /** 124 + * ixgbevf_read_v2p_mailbox - read v2p mailbox 125 + * @hw: pointer to the HW structure 126 + * 127 + * This function is used to read the v2p mailbox without losing the read to 128 + * clear status bits. 129 + **/ 130 + static u32 ixgbevf_read_v2p_mailbox(struct ixgbe_hw *hw) 131 + { 132 + u32 v2p_mailbox = IXGBE_READ_REG(hw, IXGBE_VFMAILBOX); 133 + 134 + v2p_mailbox |= hw->mbx.v2p_mailbox; 135 + hw->mbx.v2p_mailbox |= v2p_mailbox & IXGBE_VFMAILBOX_R2C_BITS; 136 + 137 + return v2p_mailbox; 138 + } 139 + 140 + /** 141 + * ixgbevf_check_for_bit_vf - Determine if a status bit was set 142 + * @hw: pointer to the HW structure 143 + * @mask: bitmask for bits to be tested and cleared 144 + * 145 + * This function is used to check for the read to clear bits within 146 + * the V2P mailbox. 147 + **/ 148 + static s32 ixgbevf_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask) 149 + { 150 + u32 v2p_mailbox = ixgbevf_read_v2p_mailbox(hw); 151 + s32 ret_val = IXGBE_ERR_MBX; 152 + 153 + if (v2p_mailbox & mask) 154 + ret_val = 0; 155 + 156 + hw->mbx.v2p_mailbox &= ~mask; 157 + 158 + return ret_val; 159 + } 160 + 161 + /** 162 + * ixgbevf_check_for_msg_vf - checks to see if the PF has sent mail 163 + * @hw: pointer to the HW structure 164 + * 165 + * returns 0 if the PF has set the Status bit or else ERR_MBX 166 + **/ 167 + static s32 ixgbevf_check_for_msg_vf(struct ixgbe_hw *hw) 168 + { 169 + s32 ret_val = IXGBE_ERR_MBX; 170 + 171 + if (!ixgbevf_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFSTS)) { 172 + ret_val = 0; 173 + hw->mbx.stats.reqs++; 174 + } 175 + 176 + return ret_val; 177 + } 178 + 179 + /** 180 + * ixgbevf_check_for_ack_vf - checks to see if the PF has ACK'd 181 + * @hw: pointer to the HW structure 182 + * 183 + * returns 0 if the PF has set the ACK bit or else ERR_MBX 184 + **/ 185 + static s32 ixgbevf_check_for_ack_vf(struct ixgbe_hw *hw) 186 + { 187 + s32 ret_val = IXGBE_ERR_MBX; 188 + 189 + if (!ixgbevf_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFACK)) { 190 + ret_val = 0; 191 + hw->mbx.stats.acks++; 192 + } 193 + 194 + return ret_val; 195 + } 196 + 197 + /** 198 + * ixgbevf_check_for_rst_vf - checks to see if the PF has reset 199 + * @hw: pointer to the HW structure 200 + * 201 + * returns true if the PF has set the reset done bit or else false 202 + **/ 203 + static s32 ixgbevf_check_for_rst_vf(struct ixgbe_hw *hw) 204 + { 205 + s32 ret_val = IXGBE_ERR_MBX; 206 + 207 + if (!ixgbevf_check_for_bit_vf(hw, (IXGBE_VFMAILBOX_RSTD | 208 + IXGBE_VFMAILBOX_RSTI))) { 209 + ret_val = 0; 210 + hw->mbx.stats.rsts++; 211 + } 212 + 213 + return ret_val; 214 + } 215 + 216 + /** 217 + * ixgbevf_obtain_mbx_lock_vf - obtain mailbox lock 218 + * @hw: pointer to the HW structure 219 + * 220 + * return 0 if we obtained the mailbox lock 221 + **/ 222 + static s32 ixgbevf_obtain_mbx_lock_vf(struct ixgbe_hw *hw) 223 + { 224 + s32 ret_val = IXGBE_ERR_MBX; 225 + 226 + /* Take ownership of the buffer */ 227 + IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_VFU); 228 + 229 + /* reserve mailbox for vf use */ 230 + if (ixgbevf_read_v2p_mailbox(hw) & IXGBE_VFMAILBOX_VFU) 231 + ret_val = 0; 232 + 233 + return ret_val; 234 + } 235 + 236 + /** 237 + * ixgbevf_write_mbx_vf - Write a message to the mailbox 238 + * @hw: pointer to the HW structure 239 + * @msg: The message buffer 240 + * @size: Length of buffer 241 + * 242 + * returns 0 if it successfully copied message into the buffer 243 + **/ 244 + static s32 ixgbevf_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size) 245 + { 246 + s32 ret_val; 247 + u16 i; 248 + 249 + 250 + /* lock the mailbox to prevent pf/vf race condition */ 251 + ret_val = ixgbevf_obtain_mbx_lock_vf(hw); 252 + if (ret_val) 253 + goto out_no_write; 254 + 255 + /* flush msg and acks as we are overwriting the message buffer */ 256 + ixgbevf_check_for_msg_vf(hw); 257 + ixgbevf_check_for_ack_vf(hw); 258 + 259 + /* copy the caller specified message to the mailbox memory buffer */ 260 + for (i = 0; i < size; i++) 261 + IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]); 262 + 263 + /* update stats */ 264 + hw->mbx.stats.msgs_tx++; 265 + 266 + /* Drop VFU and interrupt the PF to tell it a message has been sent */ 267 + IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_REQ); 268 + 269 + out_no_write: 270 + return ret_val; 271 + } 272 + 273 + /** 274 + * ixgbevf_read_mbx_vf - Reads a message from the inbox intended for vf 275 + * @hw: pointer to the HW structure 276 + * @msg: The message buffer 277 + * @size: Length of buffer 278 + * 279 + * returns 0 if it successfuly read message from buffer 280 + **/ 281 + static s32 ixgbevf_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size) 282 + { 283 + s32 ret_val = 0; 284 + u16 i; 285 + 286 + /* lock the mailbox to prevent pf/vf race condition */ 287 + ret_val = ixgbevf_obtain_mbx_lock_vf(hw); 288 + if (ret_val) 289 + goto out_no_read; 290 + 291 + /* copy the message from the mailbox memory buffer */ 292 + for (i = 0; i < size; i++) 293 + msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i); 294 + 295 + /* Acknowledge receipt and release mailbox, then we're done */ 296 + IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_ACK); 297 + 298 + /* update stats */ 299 + hw->mbx.stats.msgs_rx++; 300 + 301 + out_no_read: 302 + return ret_val; 303 + } 304 + 305 + /** 306 + * ixgbevf_init_mbx_params_vf - set initial values for vf mailbox 307 + * @hw: pointer to the HW structure 308 + * 309 + * Initializes the hw->mbx struct to correct values for vf mailbox 310 + */ 311 + s32 ixgbevf_init_mbx_params_vf(struct ixgbe_hw *hw) 312 + { 313 + struct ixgbe_mbx_info *mbx = &hw->mbx; 314 + 315 + /* start mailbox as timed out and let the reset_hw call set the timeout 316 + * value to begin communications */ 317 + mbx->timeout = 0; 318 + mbx->udelay = IXGBE_VF_MBX_INIT_DELAY; 319 + 320 + mbx->size = IXGBE_VFMAILBOX_SIZE; 321 + 322 + mbx->stats.msgs_tx = 0; 323 + mbx->stats.msgs_rx = 0; 324 + mbx->stats.reqs = 0; 325 + mbx->stats.acks = 0; 326 + mbx->stats.rsts = 0; 327 + 328 + return 0; 329 + } 330 + 331 + struct ixgbe_mbx_operations ixgbevf_mbx_ops = { 332 + .init_params = ixgbevf_init_mbx_params_vf, 333 + .read = ixgbevf_read_mbx_vf, 334 + .write = ixgbevf_write_mbx_vf, 335 + .read_posted = ixgbevf_read_posted_mbx, 336 + .write_posted = ixgbevf_write_posted_mbx, 337 + .check_for_msg = ixgbevf_check_for_msg_vf, 338 + .check_for_ack = ixgbevf_check_for_ack_vf, 339 + .check_for_rst = ixgbevf_check_for_rst_vf, 340 + }; 341 +
+100
drivers/net/ixgbevf/mbx.h
··· 1 + /******************************************************************************* 2 + 3 + Intel 82599 Virtual Function driver 4 + Copyright(c) 1999 - 2009 Intel Corporation. 5 + 6 + This program is free software; you can redistribute it and/or modify it 7 + under the terms and conditions of the GNU General Public License, 8 + version 2, as published by the Free Software Foundation. 9 + 10 + This program is distributed in the hope it will be useful, but WITHOUT 11 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + more details. 14 + 15 + You should have received a copy of the GNU General Public License along with 16 + this program; if not, write to the Free Software Foundation, Inc., 17 + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 + 19 + The full GNU General Public License is included in this distribution in 20 + the file called "COPYING". 21 + 22 + Contact Information: 23 + e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 + Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 + 26 + *******************************************************************************/ 27 + 28 + #ifndef _IXGBE_MBX_H_ 29 + #define _IXGBE_MBX_H_ 30 + 31 + #include "vf.h" 32 + 33 + #define IXGBE_VFMAILBOX_SIZE 16 /* 16 32 bit words - 64 bytes */ 34 + #define IXGBE_ERR_MBX -100 35 + 36 + #define IXGBE_VFMAILBOX 0x002FC 37 + #define IXGBE_VFMBMEM 0x00200 38 + 39 + /* Define mailbox register bits */ 40 + #define IXGBE_VFMAILBOX_REQ 0x00000001 /* Request for PF Ready bit */ 41 + #define IXGBE_VFMAILBOX_ACK 0x00000002 /* Ack PF message received */ 42 + #define IXGBE_VFMAILBOX_VFU 0x00000004 /* VF owns the mailbox buffer */ 43 + #define IXGBE_VFMAILBOX_PFU 0x00000008 /* PF owns the mailbox buffer */ 44 + #define IXGBE_VFMAILBOX_PFSTS 0x00000010 /* PF wrote a message in the MB */ 45 + #define IXGBE_VFMAILBOX_PFACK 0x00000020 /* PF ack the previous VF msg */ 46 + #define IXGBE_VFMAILBOX_RSTI 0x00000040 /* PF has reset indication */ 47 + #define IXGBE_VFMAILBOX_RSTD 0x00000080 /* PF has indicated reset done */ 48 + #define IXGBE_VFMAILBOX_R2C_BITS 0x000000B0 /* All read to clear bits */ 49 + 50 + #define IXGBE_PFMAILBOX(x) (0x04B00 + (4 * x)) 51 + #define IXGBE_PFMBMEM(vfn) (0x13000 + (64 * vfn)) 52 + 53 + #define IXGBE_PFMAILBOX_STS 0x00000001 /* Initiate message send to VF */ 54 + #define IXGBE_PFMAILBOX_ACK 0x00000002 /* Ack message recv'd from VF */ 55 + #define IXGBE_PFMAILBOX_VFU 0x00000004 /* VF owns the mailbox buffer */ 56 + #define IXGBE_PFMAILBOX_PFU 0x00000008 /* PF owns the mailbox buffer */ 57 + #define IXGBE_PFMAILBOX_RVFU 0x00000010 /* Reset VFU - used when VF stuck */ 58 + 59 + #define IXGBE_MBVFICR_VFREQ_MASK 0x0000FFFF /* bits for VF messages */ 60 + #define IXGBE_MBVFICR_VFREQ_VF1 0x00000001 /* bit for VF 1 message */ 61 + #define IXGBE_MBVFICR_VFACK_MASK 0xFFFF0000 /* bits for VF acks */ 62 + #define IXGBE_MBVFICR_VFACK_VF1 0x00010000 /* bit for VF 1 ack */ 63 + 64 + 65 + /* If it's a IXGBE_VF_* msg then it originates in the VF and is sent to the 66 + * PF. The reverse is true if it is IXGBE_PF_*. 67 + * Message ACK's are the value or'd with 0xF0000000 68 + */ 69 + #define IXGBE_VT_MSGTYPE_ACK 0x80000000 /* Messages below or'd with 70 + * this are the ACK */ 71 + #define IXGBE_VT_MSGTYPE_NACK 0x40000000 /* Messages below or'd with 72 + * this are the NACK */ 73 + #define IXGBE_VT_MSGTYPE_CTS 0x20000000 /* Indicates that VF is still 74 + * clear to send requests */ 75 + #define IXGBE_VT_MSGINFO_SHIFT 16 76 + /* bits 23:16 are used for exra info for certain messages */ 77 + #define IXGBE_VT_MSGINFO_MASK (0xFF << IXGBE_VT_MSGINFO_SHIFT) 78 + 79 + #define IXGBE_VF_RESET 0x01 /* VF requests reset */ 80 + #define IXGBE_VF_SET_MAC_ADDR 0x02 /* VF requests PF to set MAC addr */ 81 + #define IXGBE_VF_SET_MULTICAST 0x03 /* VF requests PF to set MC addr */ 82 + #define IXGBE_VF_SET_VLAN 0x04 /* VF requests PF to set VLAN */ 83 + #define IXGBE_VF_SET_LPE 0x05 /* VF requests PF to set VMOLR.LPE */ 84 + 85 + /* length of permanent address message returned from PF */ 86 + #define IXGBE_VF_PERMADDR_MSG_LEN 4 87 + /* word in permanent address message with the current multicast type */ 88 + #define IXGBE_VF_MC_TYPE_WORD 3 89 + 90 + #define IXGBE_PF_CONTROL_MSG 0x0100 /* PF control message */ 91 + 92 + #define IXGBE_VF_MBX_INIT_TIMEOUT 2000 /* number of retries on mailbox */ 93 + #define IXGBE_VF_MBX_INIT_DELAY 500 /* microseconds between retries */ 94 + 95 + /* forward declaration of the HW struct */ 96 + struct ixgbe_hw; 97 + 98 + s32 ixgbevf_init_mbx_params_vf(struct ixgbe_hw *); 99 + 100 + #endif /* _IXGBE_MBX_H_ */