Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 82599 Virtual Function driver |
Greg Rose | 5c47a2b | 2012-01-06 02:53:30 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 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 "vf.h" |
Stephen Hemminger | b5417bf | 2012-01-18 22:13:33 +0000 | [diff] [blame] | 29 | #include "ixgbevf.h" |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx |
| 33 | * @hw: pointer to hardware structure |
| 34 | * |
| 35 | * Starts the hardware by filling the bus info structure and media type, clears |
| 36 | * all on chip counters, initializes receive address registers, multicast |
| 37 | * table, VLAN filter table, calls routine to set up link and flow control |
| 38 | * settings, and leaves transmit and receive units disabled and uninitialized |
| 39 | **/ |
| 40 | static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw) |
| 41 | { |
| 42 | /* Clear adapter stopped flag */ |
| 43 | hw->adapter_stopped = false; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * ixgbevf_init_hw_vf - virtual function hardware initialization |
| 50 | * @hw: pointer to hardware structure |
| 51 | * |
| 52 | * Initialize the hardware by resetting the hardware and then starting |
| 53 | * the hardware |
| 54 | **/ |
| 55 | static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw) |
| 56 | { |
| 57 | s32 status = hw->mac.ops.start_hw(hw); |
| 58 | |
| 59 | hw->mac.ops.get_mac_addr(hw, hw->mac.addr); |
| 60 | |
| 61 | return status; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * ixgbevf_reset_hw_vf - Performs hardware reset |
| 66 | * @hw: pointer to hardware structure |
| 67 | * |
| 68 | * Resets the hardware by reseting the transmit and receive units, masks and |
| 69 | * clears all interrupts. |
| 70 | **/ |
| 71 | static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw) |
| 72 | { |
| 73 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
| 74 | u32 timeout = IXGBE_VF_INIT_TIMEOUT; |
| 75 | s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR; |
| 76 | u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN]; |
| 77 | u8 *addr = (u8 *)(&msgbuf[1]); |
| 78 | |
| 79 | /* Call adapter stop to disable tx/rx and clear interrupts */ |
| 80 | hw->mac.ops.stop_adapter(hw); |
| 81 | |
Alexander Duyck | 3118678 | 2012-07-20 08:09:58 +0000 | [diff] [blame] | 82 | /* reset the api version */ |
| 83 | hw->api_version = ixgbe_mbox_api_10; |
| 84 | |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 85 | IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST); |
| 86 | IXGBE_WRITE_FLUSH(hw); |
| 87 | |
| 88 | /* we cannot reset while the RSTI / RSTD bits are asserted */ |
| 89 | while (!mbx->ops.check_for_rst(hw) && timeout) { |
| 90 | timeout--; |
| 91 | udelay(5); |
| 92 | } |
| 93 | |
| 94 | if (!timeout) |
| 95 | return IXGBE_ERR_RESET_FAILED; |
| 96 | |
| 97 | /* mailbox timeout can now become active */ |
| 98 | mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT; |
| 99 | |
| 100 | msgbuf[0] = IXGBE_VF_RESET; |
| 101 | mbx->ops.write_posted(hw, msgbuf, 1); |
| 102 | |
John Fastabend | 012dc19 | 2012-09-19 21:35:57 +0000 | [diff] [blame] | 103 | mdelay(10); |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 104 | |
| 105 | /* set our "perm_addr" based on info provided by PF */ |
| 106 | /* also set up the mc_filter_type which is piggy backed |
| 107 | * on the mac address in word 3 */ |
| 108 | ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN); |
| 109 | if (ret_val) |
| 110 | return ret_val; |
| 111 | |
| 112 | if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK)) |
| 113 | return IXGBE_ERR_INVALID_MAC_ADDR; |
| 114 | |
Joe Perches | ea99d83 | 2011-09-20 15:32:52 +0000 | [diff] [blame] | 115 | memcpy(hw->mac.perm_addr, addr, ETH_ALEN); |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 116 | hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD]; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units |
| 123 | * @hw: pointer to hardware structure |
| 124 | * |
| 125 | * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, |
| 126 | * disables transmit and receive units. The adapter_stopped flag is used by |
| 127 | * the shared code and drivers to determine if the adapter is in a stopped |
| 128 | * state and should not touch the hardware. |
| 129 | **/ |
| 130 | static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw) |
| 131 | { |
| 132 | u32 number_of_queues; |
| 133 | u32 reg_val; |
| 134 | u16 i; |
| 135 | |
| 136 | /* |
| 137 | * Set the adapter_stopped flag so other driver functions stop touching |
| 138 | * the hardware |
| 139 | */ |
| 140 | hw->adapter_stopped = true; |
| 141 | |
| 142 | /* Disable the receive unit by stopped each queue */ |
| 143 | number_of_queues = hw->mac.max_rx_queues; |
| 144 | for (i = 0; i < number_of_queues; i++) { |
| 145 | reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i)); |
| 146 | if (reg_val & IXGBE_RXDCTL_ENABLE) { |
| 147 | reg_val &= ~IXGBE_RXDCTL_ENABLE; |
| 148 | IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | IXGBE_WRITE_FLUSH(hw); |
| 153 | |
| 154 | /* Clear interrupt mask to stop from interrupts being generated */ |
| 155 | IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK); |
| 156 | |
| 157 | /* Clear any pending interrupts */ |
| 158 | IXGBE_READ_REG(hw, IXGBE_VTEICR); |
| 159 | |
| 160 | /* Disable the transmit unit. Each queue must be disabled. */ |
| 161 | number_of_queues = hw->mac.max_tx_queues; |
| 162 | for (i = 0; i < number_of_queues; i++) { |
| 163 | reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i)); |
| 164 | if (reg_val & IXGBE_TXDCTL_ENABLE) { |
| 165 | reg_val &= ~IXGBE_TXDCTL_ENABLE; |
| 166 | IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * ixgbevf_mta_vector - Determines bit-vector in multicast table to set |
| 175 | * @hw: pointer to hardware structure |
| 176 | * @mc_addr: the multicast address |
| 177 | * |
| 178 | * Extracts the 12 bits, from a multicast address, to determine which |
| 179 | * bit-vector to set in the multicast table. The hardware uses 12 bits, from |
| 180 | * incoming rx multicast addresses, to determine the bit-vector to check in |
| 181 | * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set |
| 182 | * by the MO field of the MCSTCTRL. The MO field is set during initialization |
| 183 | * to mc_filter_type. |
| 184 | **/ |
| 185 | static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) |
| 186 | { |
| 187 | u32 vector = 0; |
| 188 | |
| 189 | switch (hw->mac.mc_filter_type) { |
| 190 | case 0: /* use bits [47:36] of the address */ |
| 191 | vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); |
| 192 | break; |
| 193 | case 1: /* use bits [46:35] of the address */ |
| 194 | vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); |
| 195 | break; |
| 196 | case 2: /* use bits [45:34] of the address */ |
| 197 | vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); |
| 198 | break; |
| 199 | case 3: /* use bits [43:32] of the address */ |
| 200 | vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); |
| 201 | break; |
| 202 | default: /* Invalid mc_filter_type */ |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | /* vector can only be 12-bits or boundary will be exceeded */ |
| 207 | vector &= 0xFFF; |
| 208 | return vector; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * ixgbevf_get_mac_addr_vf - Read device MAC address |
| 213 | * @hw: pointer to the HW structure |
| 214 | * @mac_addr: pointer to storage for retrieved MAC address |
| 215 | **/ |
| 216 | static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr) |
| 217 | { |
Joe Perches | ea99d83 | 2011-09-20 15:32:52 +0000 | [diff] [blame] | 218 | memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN); |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
Greg Rose | 46ec20f | 2011-05-13 01:33:42 +0000 | [diff] [blame] | 223 | static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr) |
| 224 | { |
| 225 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
| 226 | u32 msgbuf[3]; |
| 227 | u8 *msg_addr = (u8 *)(&msgbuf[1]); |
| 228 | s32 ret_val; |
| 229 | |
| 230 | memset(msgbuf, 0, sizeof(msgbuf)); |
| 231 | /* |
| 232 | * If index is one then this is the start of a new list and needs |
| 233 | * indication to the PF so it can do it's own list management. |
| 234 | * If it is zero then that tells the PF to just clear all of |
| 235 | * this VF's macvlans and there is no new list. |
| 236 | */ |
| 237 | msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT; |
| 238 | msgbuf[0] |= IXGBE_VF_SET_MACVLAN; |
| 239 | if (addr) |
| 240 | memcpy(msg_addr, addr, 6); |
| 241 | ret_val = mbx->ops.write_posted(hw, msgbuf, 3); |
| 242 | |
| 243 | if (!ret_val) |
| 244 | ret_val = mbx->ops.read_posted(hw, msgbuf, 3); |
| 245 | |
| 246 | msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS; |
| 247 | |
| 248 | if (!ret_val) |
| 249 | if (msgbuf[0] == |
| 250 | (IXGBE_VF_SET_MACVLAN | IXGBE_VT_MSGTYPE_NACK)) |
| 251 | ret_val = -ENOMEM; |
| 252 | |
| 253 | return ret_val; |
| 254 | } |
| 255 | |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 256 | /** |
| 257 | * ixgbevf_set_rar_vf - set device MAC address |
| 258 | * @hw: pointer to hardware structure |
| 259 | * @index: Receive address register to write |
| 260 | * @addr: Address to put into receive address register |
| 261 | * @vmdq: Unused in this implementation |
| 262 | **/ |
| 263 | static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr, |
| 264 | u32 vmdq) |
| 265 | { |
| 266 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
| 267 | u32 msgbuf[3]; |
| 268 | u8 *msg_addr = (u8 *)(&msgbuf[1]); |
| 269 | s32 ret_val; |
| 270 | |
| 271 | memset(msgbuf, 0, sizeof(msgbuf)); |
| 272 | msgbuf[0] = IXGBE_VF_SET_MAC_ADDR; |
| 273 | memcpy(msg_addr, addr, 6); |
| 274 | ret_val = mbx->ops.write_posted(hw, msgbuf, 3); |
| 275 | |
| 276 | if (!ret_val) |
| 277 | ret_val = mbx->ops.read_posted(hw, msgbuf, 3); |
| 278 | |
| 279 | msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS; |
| 280 | |
| 281 | /* if nacked the address was rejected, use "perm_addr" */ |
| 282 | if (!ret_val && |
| 283 | (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK))) |
| 284 | ixgbevf_get_mac_addr_vf(hw, hw->mac.addr); |
| 285 | |
| 286 | return ret_val; |
| 287 | } |
| 288 | |
Greg Rose | 3a2c403 | 2012-02-01 01:28:15 +0000 | [diff] [blame] | 289 | static void ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw, |
| 290 | u32 *msg, u16 size) |
| 291 | { |
| 292 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
| 293 | u32 retmsg[IXGBE_VFMAILBOX_SIZE]; |
| 294 | s32 retval = mbx->ops.write_posted(hw, msg, size); |
| 295 | |
| 296 | if (!retval) |
| 297 | mbx->ops.read_posted(hw, retmsg, size); |
| 298 | } |
| 299 | |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 300 | /** |
| 301 | * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses |
| 302 | * @hw: pointer to the HW structure |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 303 | * @netdev: pointer to net device structure |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 304 | * |
| 305 | * Updates the Multicast Table Array. |
| 306 | **/ |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 307 | static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw, |
| 308 | struct net_device *netdev) |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 309 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 310 | struct netdev_hw_addr *ha; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 311 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; |
| 312 | u16 *vector_list = (u16 *)&msgbuf[1]; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 313 | u32 cnt, i; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 314 | |
| 315 | /* Each entry in the list uses 1 16 bit word. We have 30 |
| 316 | * 16 bit words available in our HW msg buffer (minus 1 for the |
| 317 | * msg type). That's 30 hash values if we pack 'em right. If |
| 318 | * there are more than 30 MC addresses to add then punt the |
| 319 | * extras for now and then add code to handle more than 30 later. |
| 320 | * It would be unusual for a server to request that many multi-cast |
| 321 | * addresses except for in large enterprise network environments. |
| 322 | */ |
| 323 | |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 324 | cnt = netdev_mc_count(netdev); |
| 325 | if (cnt > 30) |
| 326 | cnt = 30; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 327 | msgbuf[0] = IXGBE_VF_SET_MULTICAST; |
| 328 | msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT; |
| 329 | |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 330 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 331 | netdev_for_each_mc_addr(ha, netdev) { |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 332 | if (i == cnt) |
| 333 | break; |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame^] | 334 | if (is_link_local_ether_addr(ha->addr)) |
John Fastabend | b3343a2 | 2012-09-18 00:01:12 +0000 | [diff] [blame] | 335 | continue; |
| 336 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 337 | vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr); |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Greg Rose | 3a2c403 | 2012-02-01 01:28:15 +0000 | [diff] [blame] | 340 | ixgbevf_write_msg_read_ack(hw, msgbuf, IXGBE_VFMAILBOX_SIZE); |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * ixgbevf_set_vfta_vf - Set/Unset vlan filter table address |
| 347 | * @hw: pointer to the HW structure |
| 348 | * @vlan: 12 bit VLAN ID |
| 349 | * @vind: unused by VF drivers |
| 350 | * @vlan_on: if true then set bit, else clear bit |
| 351 | **/ |
| 352 | static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind, |
| 353 | bool vlan_on) |
| 354 | { |
Alexander Duyck | 2ddc7fe | 2012-08-21 00:15:13 +0000 | [diff] [blame] | 355 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 356 | u32 msgbuf[2]; |
Alexander Duyck | 2ddc7fe | 2012-08-21 00:15:13 +0000 | [diff] [blame] | 357 | s32 err; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 358 | |
| 359 | msgbuf[0] = IXGBE_VF_SET_VLAN; |
| 360 | msgbuf[1] = vlan; |
| 361 | /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */ |
| 362 | msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT; |
| 363 | |
Alexander Duyck | 2ddc7fe | 2012-08-21 00:15:13 +0000 | [diff] [blame] | 364 | err = mbx->ops.write_posted(hw, msgbuf, 2); |
| 365 | if (err) |
| 366 | goto mbx_err; |
Greg Rose | 3a2c403 | 2012-02-01 01:28:15 +0000 | [diff] [blame] | 367 | |
Alexander Duyck | 2ddc7fe | 2012-08-21 00:15:13 +0000 | [diff] [blame] | 368 | err = mbx->ops.read_posted(hw, msgbuf, 2); |
| 369 | if (err) |
| 370 | goto mbx_err; |
| 371 | |
| 372 | /* remove extra bits from the message */ |
| 373 | msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS; |
| 374 | msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT); |
| 375 | |
| 376 | if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK)) |
| 377 | err = IXGBE_ERR_INVALID_ARGUMENT; |
| 378 | |
| 379 | mbx_err: |
| 380 | return err; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /** |
| 384 | * ixgbevf_setup_mac_link_vf - Setup MAC link settings |
| 385 | * @hw: pointer to hardware structure |
| 386 | * @speed: Unused in this implementation |
| 387 | * @autoneg: Unused in this implementation |
| 388 | * @autoneg_wait_to_complete: Unused in this implementation |
| 389 | * |
| 390 | * Do nothing and return success. VF drivers are not allowed to change |
| 391 | * global settings. Maintained for driver compatibility. |
| 392 | **/ |
| 393 | static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw, |
| 394 | ixgbe_link_speed speed, bool autoneg, |
| 395 | bool autoneg_wait_to_complete) |
| 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * ixgbevf_check_mac_link_vf - Get link/speed status |
| 402 | * @hw: pointer to hardware structure |
| 403 | * @speed: pointer to link speed |
| 404 | * @link_up: true is link is up, false otherwise |
| 405 | * @autoneg_wait_to_complete: true when waiting for completion is needed |
| 406 | * |
| 407 | * Reads the links register to determine if link is up and the current speed |
| 408 | **/ |
| 409 | static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw, |
| 410 | ixgbe_link_speed *speed, |
| 411 | bool *link_up, |
| 412 | bool autoneg_wait_to_complete) |
| 413 | { |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 414 | struct ixgbe_mbx_info *mbx = &hw->mbx; |
| 415 | struct ixgbe_mac_info *mac = &hw->mac; |
| 416 | s32 ret_val = 0; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 417 | u32 links_reg; |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 418 | u32 in_msg = 0; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 419 | |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 420 | /* If we were hit with a reset drop the link */ |
| 421 | if (!mbx->ops.check_for_rst(hw) || !mbx->timeout) |
| 422 | mac->get_link_status = true; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 423 | |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 424 | if (!mac->get_link_status) |
| 425 | goto out; |
| 426 | |
| 427 | /* if link status is down no point in checking to see if pf is up */ |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 428 | links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS); |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 429 | if (!(links_reg & IXGBE_LINKS_UP)) |
| 430 | goto out; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 431 | |
Greg Rose | 31a1b37 | 2012-04-10 01:56:37 +0000 | [diff] [blame] | 432 | switch (links_reg & IXGBE_LINKS_SPEED_82599) { |
| 433 | case IXGBE_LINKS_SPEED_10G_82599: |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 434 | *speed = IXGBE_LINK_SPEED_10GB_FULL; |
Greg Rose | 31a1b37 | 2012-04-10 01:56:37 +0000 | [diff] [blame] | 435 | break; |
| 436 | case IXGBE_LINKS_SPEED_1G_82599: |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 437 | *speed = IXGBE_LINK_SPEED_1GB_FULL; |
Greg Rose | 31a1b37 | 2012-04-10 01:56:37 +0000 | [diff] [blame] | 438 | break; |
| 439 | case IXGBE_LINKS_SPEED_100_82599: |
| 440 | *speed = IXGBE_LINK_SPEED_100_FULL; |
| 441 | break; |
| 442 | } |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 443 | |
Alexander Duyck | 4b2cd27 | 2012-08-02 01:16:59 +0000 | [diff] [blame] | 444 | /* if the read failed it could just be a mailbox collision, best wait |
| 445 | * until we are called again and don't report an error */ |
| 446 | if (mbx->ops.read(hw, &in_msg, 1)) |
| 447 | goto out; |
| 448 | |
| 449 | if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) { |
| 450 | /* msg is not CTS and is NACK we must have lost CTS status */ |
| 451 | if (in_msg & IXGBE_VT_MSGTYPE_NACK) |
| 452 | ret_val = -1; |
| 453 | goto out; |
| 454 | } |
| 455 | |
| 456 | /* the pf is talking, if we timed out in the past we reinit */ |
| 457 | if (!mbx->timeout) { |
| 458 | ret_val = -1; |
| 459 | goto out; |
| 460 | } |
| 461 | |
| 462 | /* if we passed all the tests above then the link is up and we no |
| 463 | * longer need to check for link */ |
| 464 | mac->get_link_status = false; |
| 465 | |
| 466 | out: |
| 467 | *link_up = !mac->get_link_status; |
| 468 | return ret_val; |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Alexander Duyck | dd1fe11 | 2012-07-20 08:09:48 +0000 | [diff] [blame] | 471 | /** |
| 472 | * ixgbevf_rlpml_set_vf - Set the maximum receive packet length |
| 473 | * @hw: pointer to the HW structure |
| 474 | * @max_size: value to assign to max frame size |
| 475 | **/ |
| 476 | void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size) |
| 477 | { |
| 478 | u32 msgbuf[2]; |
| 479 | |
| 480 | msgbuf[0] = IXGBE_VF_SET_LPE; |
| 481 | msgbuf[1] = max_size; |
| 482 | ixgbevf_write_msg_read_ack(hw, msgbuf, 2); |
| 483 | } |
| 484 | |
Alexander Duyck | 3118678 | 2012-07-20 08:09:58 +0000 | [diff] [blame] | 485 | /** |
| 486 | * ixgbevf_negotiate_api_version - Negotiate supported API version |
| 487 | * @hw: pointer to the HW structure |
| 488 | * @api: integer containing requested API version |
| 489 | **/ |
| 490 | int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api) |
| 491 | { |
| 492 | int err; |
| 493 | u32 msg[3]; |
| 494 | |
| 495 | /* Negotiate the mailbox API version */ |
| 496 | msg[0] = IXGBE_VF_API_NEGOTIATE; |
| 497 | msg[1] = api; |
| 498 | msg[2] = 0; |
| 499 | err = hw->mbx.ops.write_posted(hw, msg, 3); |
| 500 | |
| 501 | if (!err) |
| 502 | err = hw->mbx.ops.read_posted(hw, msg, 3); |
| 503 | |
| 504 | if (!err) { |
| 505 | msg[0] &= ~IXGBE_VT_MSGTYPE_CTS; |
| 506 | |
| 507 | /* Store value and return 0 on success */ |
| 508 | if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) { |
| 509 | hw->api_version = api; |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | err = IXGBE_ERR_INVALID_ARGUMENT; |
| 514 | } |
| 515 | |
| 516 | return err; |
| 517 | } |
| 518 | |
Alexander Duyck | 56e9409 | 2012-07-20 08:10:03 +0000 | [diff] [blame] | 519 | int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs, |
| 520 | unsigned int *default_tc) |
| 521 | { |
| 522 | int err; |
| 523 | u32 msg[5]; |
| 524 | |
| 525 | /* do nothing if API doesn't support ixgbevf_get_queues */ |
| 526 | switch (hw->api_version) { |
| 527 | case ixgbe_mbox_api_11: |
| 528 | break; |
| 529 | default: |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | /* Fetch queue configuration from the PF */ |
| 534 | msg[0] = IXGBE_VF_GET_QUEUE; |
| 535 | msg[1] = msg[2] = msg[3] = msg[4] = 0; |
| 536 | err = hw->mbx.ops.write_posted(hw, msg, 5); |
| 537 | |
| 538 | if (!err) |
| 539 | err = hw->mbx.ops.read_posted(hw, msg, 5); |
| 540 | |
| 541 | if (!err) { |
| 542 | msg[0] &= ~IXGBE_VT_MSGTYPE_CTS; |
| 543 | |
| 544 | /* |
| 545 | * if we we didn't get an ACK there must have been |
| 546 | * some sort of mailbox error so we should treat it |
| 547 | * as such |
| 548 | */ |
| 549 | if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK)) |
| 550 | return IXGBE_ERR_MBX; |
| 551 | |
| 552 | /* record and validate values from message */ |
| 553 | hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES]; |
| 554 | if (hw->mac.max_tx_queues == 0 || |
| 555 | hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES) |
| 556 | hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES; |
| 557 | |
| 558 | hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES]; |
| 559 | if (hw->mac.max_rx_queues == 0 || |
| 560 | hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES) |
| 561 | hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES; |
| 562 | |
| 563 | *num_tcs = msg[IXGBE_VF_TRANS_VLAN]; |
| 564 | /* in case of unknown state assume we cannot tag frames */ |
| 565 | if (*num_tcs > hw->mac.max_rx_queues) |
| 566 | *num_tcs = 1; |
| 567 | |
| 568 | *default_tc = msg[IXGBE_VF_DEF_QUEUE]; |
| 569 | /* default to queue 0 on out-of-bounds queue number */ |
| 570 | if (*default_tc >= hw->mac.max_tx_queues) |
| 571 | *default_tc = 0; |
| 572 | } |
| 573 | |
| 574 | return err; |
| 575 | } |
| 576 | |
Stephen Hemminger | 3d8fe98 | 2012-01-18 22:13:34 +0000 | [diff] [blame] | 577 | static const struct ixgbe_mac_operations ixgbevf_mac_ops = { |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 578 | .init_hw = ixgbevf_init_hw_vf, |
| 579 | .reset_hw = ixgbevf_reset_hw_vf, |
| 580 | .start_hw = ixgbevf_start_hw_vf, |
| 581 | .get_mac_addr = ixgbevf_get_mac_addr_vf, |
| 582 | .stop_adapter = ixgbevf_stop_hw_vf, |
| 583 | .setup_link = ixgbevf_setup_mac_link_vf, |
| 584 | .check_link = ixgbevf_check_mac_link_vf, |
| 585 | .set_rar = ixgbevf_set_rar_vf, |
| 586 | .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf, |
Greg Rose | 46ec20f | 2011-05-13 01:33:42 +0000 | [diff] [blame] | 587 | .set_uc_addr = ixgbevf_set_uc_addr_vf, |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 588 | .set_vfta = ixgbevf_set_vfta_vf, |
| 589 | }; |
| 590 | |
Stephen Hemminger | 3d8fe98 | 2012-01-18 22:13:34 +0000 | [diff] [blame] | 591 | const struct ixgbevf_info ixgbevf_82599_vf_info = { |
Greg Rose | 3047f90 | 2010-01-09 02:23:31 +0000 | [diff] [blame] | 592 | .mac = ixgbe_mac_82599_vf, |
| 593 | .mac_ops = &ixgbevf_mac_ops, |
| 594 | }; |
| 595 | |
Stephen Hemminger | 3d8fe98 | 2012-01-18 22:13:34 +0000 | [diff] [blame] | 596 | const struct ixgbevf_info ixgbevf_X540_vf_info = { |
Greg Rose | 2316aa2 | 2010-12-02 07:12:26 +0000 | [diff] [blame] | 597 | .mac = ixgbe_mac_X540_vf, |
| 598 | .mac_ops = &ixgbevf_mac_ops, |
| 599 | }; |