blob: 2614fd328e47d8a3e8380429d010a3a452b13375 [file] [log] [blame]
Greg Rose3047f902010-01-09 02:23:31 +00001/*******************************************************************************
2
3 Intel 82599 Virtual Function driver
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +00004 Copyright(c) 1999 - 2015 Intel Corporation.
Greg Rose3047f902010-01-09 02:23:31 +00005
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
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +000016 this program; if not, see <http://www.gnu.org/licenses/>.
Greg Rose3047f902010-01-09 02:23:31 +000017
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
20
21 Contact Information:
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25*******************************************************************************/
26
27#include "vf.h"
Stephen Hemmingerb5417bf2012-01-18 22:13:33 +000028#include "ixgbevf.h"
Greg Rose3047f902010-01-09 02:23:31 +000029
30/**
31 * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
32 * @hw: pointer to hardware structure
33 *
34 * Starts the hardware by filling the bus info structure and media type, clears
35 * all on chip counters, initializes receive address registers, multicast
36 * table, VLAN filter table, calls routine to set up link and flow control
37 * settings, and leaves transmit and receive units disabled and uninitialized
38 **/
39static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
40{
41 /* Clear adapter stopped flag */
42 hw->adapter_stopped = false;
43
44 return 0;
45}
46
47/**
48 * ixgbevf_init_hw_vf - virtual function hardware initialization
49 * @hw: pointer to hardware structure
50 *
51 * Initialize the hardware by resetting the hardware and then starting
52 * the hardware
53 **/
54static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
55{
56 s32 status = hw->mac.ops.start_hw(hw);
57
58 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
59
60 return status;
61}
62
63/**
64 * ixgbevf_reset_hw_vf - Performs hardware reset
65 * @hw: pointer to hardware structure
66 *
Joe Perchesdbedd442015-03-06 20:49:12 -080067 * Resets the hardware by resetting the transmit and receive units, masks and
Greg Rose3047f902010-01-09 02:23:31 +000068 * clears all interrupts.
69 **/
70static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
71{
72 struct ixgbe_mbx_info *mbx = &hw->mbx;
73 u32 timeout = IXGBE_VF_INIT_TIMEOUT;
74 s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
75 u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
76 u8 *addr = (u8 *)(&msgbuf[1]);
77
78 /* Call adapter stop to disable tx/rx and clear interrupts */
79 hw->mac.ops.stop_adapter(hw);
80
Alexander Duyck31186782012-07-20 08:09:58 +000081 /* reset the api version */
82 hw->api_version = ixgbe_mbox_api_10;
83
Greg Rose3047f902010-01-09 02:23:31 +000084 IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
85 IXGBE_WRITE_FLUSH(hw);
86
87 /* we cannot reset while the RSTI / RSTD bits are asserted */
88 while (!mbx->ops.check_for_rst(hw) && timeout) {
89 timeout--;
90 udelay(5);
91 }
92
93 if (!timeout)
94 return IXGBE_ERR_RESET_FAILED;
95
96 /* mailbox timeout can now become active */
97 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
98
99 msgbuf[0] = IXGBE_VF_RESET;
100 mbx->ops.write_posted(hw, msgbuf, 1);
101
John Fastabend012dc192012-09-19 21:35:57 +0000102 mdelay(10);
Greg Rose3047f902010-01-09 02:23:31 +0000103
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000104 /* set our "perm_addr" based on info provided by PF
105 * also set up the mc_filter_type which is piggy backed
106 * on the mac address in word 3
107 */
Greg Rose3047f902010-01-09 02:23:31 +0000108 ret_val = mbx->ops.read_posted(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN);
109 if (ret_val)
110 return ret_val;
111
Greg Rosee1941a72013-02-13 03:02:05 +0000112 /* New versions of the PF may NACK the reset return message
113 * to indicate that no MAC address has yet been assigned for
114 * the VF.
115 */
116 if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
117 msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
Greg Rose3047f902010-01-09 02:23:31 +0000118 return IXGBE_ERR_INVALID_MAC_ADDR;
119
Jeff Kirsher0d8bb412015-02-14 04:53:03 +0000120 ether_addr_copy(hw->mac.perm_addr, addr);
Greg Rose3047f902010-01-09 02:23:31 +0000121 hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
122
123 return 0;
124}
125
126/**
127 * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
128 * @hw: pointer to hardware structure
129 *
130 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
131 * disables transmit and receive units. The adapter_stopped flag is used by
132 * the shared code and drivers to determine if the adapter is in a stopped
133 * state and should not touch the hardware.
134 **/
135static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
136{
137 u32 number_of_queues;
138 u32 reg_val;
139 u16 i;
140
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000141 /* Set the adapter_stopped flag so other driver functions stop touching
Greg Rose3047f902010-01-09 02:23:31 +0000142 * the hardware
143 */
144 hw->adapter_stopped = true;
145
146 /* Disable the receive unit by stopped each queue */
147 number_of_queues = hw->mac.max_rx_queues;
148 for (i = 0; i < number_of_queues; i++) {
149 reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
150 if (reg_val & IXGBE_RXDCTL_ENABLE) {
151 reg_val &= ~IXGBE_RXDCTL_ENABLE;
152 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
153 }
154 }
155
156 IXGBE_WRITE_FLUSH(hw);
157
158 /* Clear interrupt mask to stop from interrupts being generated */
159 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
160
161 /* Clear any pending interrupts */
162 IXGBE_READ_REG(hw, IXGBE_VTEICR);
163
164 /* Disable the transmit unit. Each queue must be disabled. */
165 number_of_queues = hw->mac.max_tx_queues;
166 for (i = 0; i < number_of_queues; i++) {
167 reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
168 if (reg_val & IXGBE_TXDCTL_ENABLE) {
169 reg_val &= ~IXGBE_TXDCTL_ENABLE;
170 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
171 }
172 }
173
174 return 0;
175}
176
177/**
178 * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
179 * @hw: pointer to hardware structure
180 * @mc_addr: the multicast address
181 *
182 * Extracts the 12 bits, from a multicast address, to determine which
183 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000184 * incoming Rx multicast addresses, to determine the bit-vector to check in
Greg Rose3047f902010-01-09 02:23:31 +0000185 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
186 * by the MO field of the MCSTCTRL. The MO field is set during initialization
187 * to mc_filter_type.
188 **/
189static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
190{
191 u32 vector = 0;
192
193 switch (hw->mac.mc_filter_type) {
194 case 0: /* use bits [47:36] of the address */
195 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
196 break;
197 case 1: /* use bits [46:35] of the address */
198 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
199 break;
200 case 2: /* use bits [45:34] of the address */
201 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
202 break;
203 case 3: /* use bits [43:32] of the address */
204 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
205 break;
206 default: /* Invalid mc_filter_type */
207 break;
208 }
209
210 /* vector can only be 12-bits or boundary will be exceeded */
211 vector &= 0xFFF;
212 return vector;
213}
214
215/**
216 * ixgbevf_get_mac_addr_vf - Read device MAC address
217 * @hw: pointer to the HW structure
218 * @mac_addr: pointer to storage for retrieved MAC address
219 **/
220static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
221{
Jeff Kirsher0d8bb412015-02-14 04:53:03 +0000222 ether_addr_copy(mac_addr, hw->mac.perm_addr);
Greg Rose3047f902010-01-09 02:23:31 +0000223
224 return 0;
225}
226
Greg Rose46ec20f2011-05-13 01:33:42 +0000227static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
228{
229 struct ixgbe_mbx_info *mbx = &hw->mbx;
230 u32 msgbuf[3];
231 u8 *msg_addr = (u8 *)(&msgbuf[1]);
232 s32 ret_val;
233
234 memset(msgbuf, 0, sizeof(msgbuf));
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000235 /* If index is one then this is the start of a new list and needs
Greg Rose46ec20f2011-05-13 01:33:42 +0000236 * indication to the PF so it can do it's own list management.
237 * If it is zero then that tells the PF to just clear all of
238 * this VF's macvlans and there is no new list.
239 */
240 msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
241 msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
242 if (addr)
Jeff Kirsher0d8bb412015-02-14 04:53:03 +0000243 ether_addr_copy(msg_addr, addr);
Greg Rose46ec20f2011-05-13 01:33:42 +0000244 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
245
246 if (!ret_val)
247 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
248
249 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
250
251 if (!ret_val)
252 if (msgbuf[0] ==
253 (IXGBE_VF_SET_MACVLAN | IXGBE_VT_MSGTYPE_NACK))
254 ret_val = -ENOMEM;
255
256 return ret_val;
257}
258
Greg Rose3047f902010-01-09 02:23:31 +0000259/**
260 * ixgbevf_set_rar_vf - set device MAC address
261 * @hw: pointer to hardware structure
262 * @index: Receive address register to write
263 * @addr: Address to put into receive address register
264 * @vmdq: Unused in this implementation
265 **/
266static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
267 u32 vmdq)
268{
269 struct ixgbe_mbx_info *mbx = &hw->mbx;
270 u32 msgbuf[3];
271 u8 *msg_addr = (u8 *)(&msgbuf[1]);
272 s32 ret_val;
273
274 memset(msgbuf, 0, sizeof(msgbuf));
275 msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
Jeff Kirsher0d8bb412015-02-14 04:53:03 +0000276 ether_addr_copy(msg_addr, addr);
Greg Rose3047f902010-01-09 02:23:31 +0000277 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
278
279 if (!ret_val)
280 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
281
282 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
283
284 /* if nacked the address was rejected, use "perm_addr" */
285 if (!ret_val &&
286 (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK)))
287 ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
288
289 return ret_val;
290}
291
Greg Rose3a2c4032012-02-01 01:28:15 +0000292static void ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw,
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000293 u32 *msg, u16 size)
Greg Rose3a2c4032012-02-01 01:28:15 +0000294{
295 struct ixgbe_mbx_info *mbx = &hw->mbx;
296 u32 retmsg[IXGBE_VFMAILBOX_SIZE];
297 s32 retval = mbx->ops.write_posted(hw, msg, size);
298
299 if (!retval)
300 mbx->ops.read_posted(hw, retmsg, size);
301}
302
Greg Rose3047f902010-01-09 02:23:31 +0000303/**
304 * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
305 * @hw: pointer to the HW structure
Jiri Pirko5c58c472010-03-23 22:58:20 +0000306 * @netdev: pointer to net device structure
Greg Rose3047f902010-01-09 02:23:31 +0000307 *
308 * Updates the Multicast Table Array.
309 **/
Jiri Pirko5c58c472010-03-23 22:58:20 +0000310static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
311 struct net_device *netdev)
Greg Rose3047f902010-01-09 02:23:31 +0000312{
Jiri Pirko22bedad32010-04-01 21:22:57 +0000313 struct netdev_hw_addr *ha;
Greg Rose3047f902010-01-09 02:23:31 +0000314 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
315 u16 *vector_list = (u16 *)&msgbuf[1];
Greg Rose3047f902010-01-09 02:23:31 +0000316 u32 cnt, i;
Greg Rose3047f902010-01-09 02:23:31 +0000317
318 /* Each entry in the list uses 1 16 bit word. We have 30
319 * 16 bit words available in our HW msg buffer (minus 1 for the
320 * msg type). That's 30 hash values if we pack 'em right. If
321 * there are more than 30 MC addresses to add then punt the
322 * extras for now and then add code to handle more than 30 later.
323 * It would be unusual for a server to request that many multi-cast
324 * addresses except for in large enterprise network environments.
325 */
326
Jiri Pirko5c58c472010-03-23 22:58:20 +0000327 cnt = netdev_mc_count(netdev);
328 if (cnt > 30)
329 cnt = 30;
Greg Rose3047f902010-01-09 02:23:31 +0000330 msgbuf[0] = IXGBE_VF_SET_MULTICAST;
331 msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
332
Jiri Pirko5c58c472010-03-23 22:58:20 +0000333 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000334 netdev_for_each_mc_addr(ha, netdev) {
Jiri Pirko5c58c472010-03-23 22:58:20 +0000335 if (i == cnt)
336 break;
Ben Hutchings46acc462012-11-01 09:11:11 +0000337 if (is_link_local_ether_addr(ha->addr))
John Fastabendb3343a22012-09-18 00:01:12 +0000338 continue;
339
Jiri Pirko22bedad32010-04-01 21:22:57 +0000340 vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
Greg Rose3047f902010-01-09 02:23:31 +0000341 }
342
Greg Rose3a2c4032012-02-01 01:28:15 +0000343 ixgbevf_write_msg_read_ack(hw, msgbuf, IXGBE_VFMAILBOX_SIZE);
Greg Rose3047f902010-01-09 02:23:31 +0000344
345 return 0;
346}
347
348/**
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000349 * ixgbevf_set_vfta_vf - Set/Unset VLAN filter table address
Greg Rose3047f902010-01-09 02:23:31 +0000350 * @hw: pointer to the HW structure
351 * @vlan: 12 bit VLAN ID
352 * @vind: unused by VF drivers
353 * @vlan_on: if true then set bit, else clear bit
354 **/
355static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
356 bool vlan_on)
357{
Alexander Duyck2ddc7fe2012-08-21 00:15:13 +0000358 struct ixgbe_mbx_info *mbx = &hw->mbx;
Greg Rose3047f902010-01-09 02:23:31 +0000359 u32 msgbuf[2];
Alexander Duyck2ddc7fe2012-08-21 00:15:13 +0000360 s32 err;
Greg Rose3047f902010-01-09 02:23:31 +0000361
362 msgbuf[0] = IXGBE_VF_SET_VLAN;
363 msgbuf[1] = vlan;
364 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
365 msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
366
Alexander Duyck2ddc7fe2012-08-21 00:15:13 +0000367 err = mbx->ops.write_posted(hw, msgbuf, 2);
368 if (err)
369 goto mbx_err;
Greg Rose3a2c4032012-02-01 01:28:15 +0000370
Alexander Duyck2ddc7fe2012-08-21 00:15:13 +0000371 err = mbx->ops.read_posted(hw, msgbuf, 2);
372 if (err)
373 goto mbx_err;
374
375 /* remove extra bits from the message */
376 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
377 msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT);
378
379 if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK))
380 err = IXGBE_ERR_INVALID_ARGUMENT;
381
382mbx_err:
383 return err;
Greg Rose3047f902010-01-09 02:23:31 +0000384}
385
386/**
387 * ixgbevf_setup_mac_link_vf - Setup MAC link settings
388 * @hw: pointer to hardware structure
389 * @speed: Unused in this implementation
390 * @autoneg: Unused in this implementation
391 * @autoneg_wait_to_complete: Unused in this implementation
392 *
393 * Do nothing and return success. VF drivers are not allowed to change
394 * global settings. Maintained for driver compatibility.
395 **/
396static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
397 ixgbe_link_speed speed, bool autoneg,
398 bool autoneg_wait_to_complete)
399{
400 return 0;
401}
402
403/**
404 * ixgbevf_check_mac_link_vf - Get link/speed status
405 * @hw: pointer to hardware structure
406 * @speed: pointer to link speed
407 * @link_up: true is link is up, false otherwise
408 * @autoneg_wait_to_complete: true when waiting for completion is needed
409 *
410 * Reads the links register to determine if link is up and the current speed
411 **/
412static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
413 ixgbe_link_speed *speed,
414 bool *link_up,
415 bool autoneg_wait_to_complete)
416{
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000417 struct ixgbe_mbx_info *mbx = &hw->mbx;
418 struct ixgbe_mac_info *mac = &hw->mac;
419 s32 ret_val = 0;
Greg Rose3047f902010-01-09 02:23:31 +0000420 u32 links_reg;
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000421 u32 in_msg = 0;
Greg Rose3047f902010-01-09 02:23:31 +0000422
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000423 /* If we were hit with a reset drop the link */
424 if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
425 mac->get_link_status = true;
Greg Rose3047f902010-01-09 02:23:31 +0000426
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000427 if (!mac->get_link_status)
428 goto out;
429
430 /* if link status is down no point in checking to see if pf is up */
Greg Rose3047f902010-01-09 02:23:31 +0000431 links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000432 if (!(links_reg & IXGBE_LINKS_UP))
433 goto out;
Greg Rose3047f902010-01-09 02:23:31 +0000434
Emil Tantilovb8a2ca12014-08-13 05:52:13 +0000435 /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
436 * before the link status is correct
437 */
438 if (mac->type == ixgbe_mac_82599_vf) {
439 int i;
440
441 for (i = 0; i < 5; i++) {
442 udelay(100);
443 links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
444
445 if (!(links_reg & IXGBE_LINKS_UP))
446 goto out;
447 }
448 }
449
Greg Rose31a1b372012-04-10 01:56:37 +0000450 switch (links_reg & IXGBE_LINKS_SPEED_82599) {
451 case IXGBE_LINKS_SPEED_10G_82599:
Greg Rose3047f902010-01-09 02:23:31 +0000452 *speed = IXGBE_LINK_SPEED_10GB_FULL;
Greg Rose31a1b372012-04-10 01:56:37 +0000453 break;
454 case IXGBE_LINKS_SPEED_1G_82599:
Greg Rose3047f902010-01-09 02:23:31 +0000455 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Greg Rose31a1b372012-04-10 01:56:37 +0000456 break;
457 case IXGBE_LINKS_SPEED_100_82599:
458 *speed = IXGBE_LINK_SPEED_100_FULL;
459 break;
460 }
Greg Rose3047f902010-01-09 02:23:31 +0000461
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000462 /* if the read failed it could just be a mailbox collision, best wait
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000463 * until we are called again and don't report an error
464 */
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000465 if (mbx->ops.read(hw, &in_msg, 1))
466 goto out;
467
468 if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
469 /* msg is not CTS and is NACK we must have lost CTS status */
470 if (in_msg & IXGBE_VT_MSGTYPE_NACK)
471 ret_val = -1;
472 goto out;
473 }
474
475 /* the pf is talking, if we timed out in the past we reinit */
476 if (!mbx->timeout) {
477 ret_val = -1;
478 goto out;
479 }
480
481 /* if we passed all the tests above then the link is up and we no
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000482 * longer need to check for link
483 */
Alexander Duyck4b2cd272012-08-02 01:16:59 +0000484 mac->get_link_status = false;
485
486out:
487 *link_up = !mac->get_link_status;
488 return ret_val;
Greg Rose3047f902010-01-09 02:23:31 +0000489}
490
Alexander Duyckdd1fe112012-07-20 08:09:48 +0000491/**
492 * ixgbevf_rlpml_set_vf - Set the maximum receive packet length
493 * @hw: pointer to the HW structure
494 * @max_size: value to assign to max frame size
495 **/
496void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
497{
498 u32 msgbuf[2];
499
500 msgbuf[0] = IXGBE_VF_SET_LPE;
501 msgbuf[1] = max_size;
502 ixgbevf_write_msg_read_ack(hw, msgbuf, 2);
503}
504
Alexander Duyck31186782012-07-20 08:09:58 +0000505/**
506 * ixgbevf_negotiate_api_version - Negotiate supported API version
507 * @hw: pointer to the HW structure
508 * @api: integer containing requested API version
509 **/
510int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
511{
512 int err;
513 u32 msg[3];
514
515 /* Negotiate the mailbox API version */
516 msg[0] = IXGBE_VF_API_NEGOTIATE;
517 msg[1] = api;
518 msg[2] = 0;
519 err = hw->mbx.ops.write_posted(hw, msg, 3);
520
521 if (!err)
522 err = hw->mbx.ops.read_posted(hw, msg, 3);
523
524 if (!err) {
525 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
526
527 /* Store value and return 0 on success */
528 if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
529 hw->api_version = api;
530 return 0;
531 }
532
533 err = IXGBE_ERR_INVALID_ARGUMENT;
534 }
535
536 return err;
537}
538
Alexander Duyck56e94092012-07-20 08:10:03 +0000539int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
540 unsigned int *default_tc)
541{
542 int err;
543 u32 msg[5];
544
545 /* do nothing if API doesn't support ixgbevf_get_queues */
546 switch (hw->api_version) {
547 case ixgbe_mbox_api_11:
548 break;
549 default:
550 return 0;
551 }
552
553 /* Fetch queue configuration from the PF */
554 msg[0] = IXGBE_VF_GET_QUEUE;
555 msg[1] = msg[2] = msg[3] = msg[4] = 0;
556 err = hw->mbx.ops.write_posted(hw, msg, 5);
557
558 if (!err)
559 err = hw->mbx.ops.read_posted(hw, msg, 5);
560
561 if (!err) {
562 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
563
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000564 /* if we we didn't get an ACK there must have been
Alexander Duyck56e94092012-07-20 08:10:03 +0000565 * some sort of mailbox error so we should treat it
566 * as such
567 */
568 if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK))
569 return IXGBE_ERR_MBX;
570
571 /* record and validate values from message */
572 hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
573 if (hw->mac.max_tx_queues == 0 ||
574 hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
575 hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
576
577 hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
578 if (hw->mac.max_rx_queues == 0 ||
579 hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
580 hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
581
582 *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
583 /* in case of unknown state assume we cannot tag frames */
584 if (*num_tcs > hw->mac.max_rx_queues)
585 *num_tcs = 1;
586
587 *default_tc = msg[IXGBE_VF_DEF_QUEUE];
588 /* default to queue 0 on out-of-bounds queue number */
589 if (*default_tc >= hw->mac.max_tx_queues)
590 *default_tc = 0;
591 }
592
593 return err;
594}
595
Stephen Hemminger3d8fe982012-01-18 22:13:34 +0000596static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
Jeff Kirsherdec0d8e2015-02-10 11:42:33 +0000597 .init_hw = ixgbevf_init_hw_vf,
598 .reset_hw = ixgbevf_reset_hw_vf,
599 .start_hw = ixgbevf_start_hw_vf,
600 .get_mac_addr = ixgbevf_get_mac_addr_vf,
601 .stop_adapter = ixgbevf_stop_hw_vf,
602 .setup_link = ixgbevf_setup_mac_link_vf,
603 .check_link = ixgbevf_check_mac_link_vf,
604 .set_rar = ixgbevf_set_rar_vf,
605 .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
606 .set_uc_addr = ixgbevf_set_uc_addr_vf,
607 .set_vfta = ixgbevf_set_vfta_vf,
Greg Rose3047f902010-01-09 02:23:31 +0000608};
609
Stephen Hemminger3d8fe982012-01-18 22:13:34 +0000610const struct ixgbevf_info ixgbevf_82599_vf_info = {
Greg Rose3047f902010-01-09 02:23:31 +0000611 .mac = ixgbe_mac_82599_vf,
612 .mac_ops = &ixgbevf_mac_ops,
613};
614
Stephen Hemminger3d8fe982012-01-18 22:13:34 +0000615const struct ixgbevf_info ixgbevf_X540_vf_info = {
Greg Rose2316aa22010-12-02 07:12:26 +0000616 .mac = ixgbe_mac_X540_vf,
617 .mac_ops = &ixgbevf_mac_ops,
618};
Emil Tantilov47068b02014-11-22 07:59:56 +0000619
620const struct ixgbevf_info ixgbevf_X550_vf_info = {
621 .mac = ixgbe_mac_X550_vf,
622 .mac_ops = &ixgbevf_mac_ops,
623};
624
625const struct ixgbevf_info ixgbevf_X550EM_x_vf_info = {
626 .mac = ixgbe_mac_X550EM_x_vf,
627 .mac_ops = &ixgbevf_mac_ops,
628};