1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
32 * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
33 * @hw: pointer to hardware structure
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
40 static s32 ixgbevf_start_hw_vf(struct ixgbe_hw *hw)
42 /* Clear adapter stopped flag */
43 hw->adapter_stopped = false;
49 * ixgbevf_init_hw_vf - virtual function hardware initialization
50 * @hw: pointer to hardware structure
52 * Initialize the hardware by resetting the hardware and then starting
55 static s32 ixgbevf_init_hw_vf(struct ixgbe_hw *hw)
57 s32 status = hw->mac.ops.start_hw(hw);
59 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
65 * ixgbevf_reset_hw_vf - Performs hardware reset
66 * @hw: pointer to hardware structure
68 * Resets the hardware by reseting the transmit and receive units, masks and
69 * clears all interrupts.
71 static s32 ixgbevf_reset_hw_vf(struct ixgbe_hw *hw)
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]);
79 /* Call adapter stop to disable tx/rx and clear interrupts */
80 hw->mac.ops.stop_adapter(hw);
82 /* reset the api version */
83 hw->api_version = ixgbe_mbox_api_10;
85 IXGBE_WRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
86 IXGBE_WRITE_FLUSH(hw);
88 /* we cannot reset while the RSTI / RSTD bits are asserted */
89 while (!mbx->ops.check_for_rst(hw) && timeout) {
95 return IXGBE_ERR_RESET_FAILED;
97 /* mailbox timeout can now become active */
98 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
100 msgbuf[0] = IXGBE_VF_RESET;
101 mbx->ops.write_posted(hw, msgbuf, 1);
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);
112 /* New versions of the PF may NACK the reset return message
113 * to indicate that no MAC address has yet been assigned for
116 if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
117 msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
118 return IXGBE_ERR_INVALID_MAC_ADDR;
120 memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
121 hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
127 * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
128 * @hw: pointer to hardware structure
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.
135 static s32 ixgbevf_stop_hw_vf(struct ixgbe_hw *hw)
137 u32 number_of_queues;
142 * Set the adapter_stopped flag so other driver functions stop touching
145 hw->adapter_stopped = true;
147 /* Disable the receive unit by stopped each queue */
148 number_of_queues = hw->mac.max_rx_queues;
149 for (i = 0; i < number_of_queues; i++) {
150 reg_val = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
151 if (reg_val & IXGBE_RXDCTL_ENABLE) {
152 reg_val &= ~IXGBE_RXDCTL_ENABLE;
153 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
157 IXGBE_WRITE_FLUSH(hw);
159 /* Clear interrupt mask to stop from interrupts being generated */
160 IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
162 /* Clear any pending interrupts */
163 IXGBE_READ_REG(hw, IXGBE_VTEICR);
165 /* Disable the transmit unit. Each queue must be disabled. */
166 number_of_queues = hw->mac.max_tx_queues;
167 for (i = 0; i < number_of_queues; i++) {
168 reg_val = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
169 if (reg_val & IXGBE_TXDCTL_ENABLE) {
170 reg_val &= ~IXGBE_TXDCTL_ENABLE;
171 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), reg_val);
179 * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
180 * @hw: pointer to hardware structure
181 * @mc_addr: the multicast address
183 * Extracts the 12 bits, from a multicast address, to determine which
184 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
185 * incoming rx multicast addresses, to determine the bit-vector to check in
186 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
187 * by the MO field of the MCSTCTRL. The MO field is set during initialization
190 static s32 ixgbevf_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
194 switch (hw->mac.mc_filter_type) {
195 case 0: /* use bits [47:36] of the address */
196 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
198 case 1: /* use bits [46:35] of the address */
199 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
201 case 2: /* use bits [45:34] of the address */
202 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
204 case 3: /* use bits [43:32] of the address */
205 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
207 default: /* Invalid mc_filter_type */
211 /* vector can only be 12-bits or boundary will be exceeded */
217 * ixgbevf_get_mac_addr_vf - Read device MAC address
218 * @hw: pointer to the HW structure
219 * @mac_addr: pointer to storage for retrieved MAC address
221 static s32 ixgbevf_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
223 memcpy(mac_addr, hw->mac.perm_addr, ETH_ALEN);
228 static s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
230 struct ixgbe_mbx_info *mbx = &hw->mbx;
232 u8 *msg_addr = (u8 *)(&msgbuf[1]);
235 memset(msgbuf, 0, sizeof(msgbuf));
237 * If index is one then this is the start of a new list and needs
238 * indication to the PF so it can do it's own list management.
239 * If it is zero then that tells the PF to just clear all of
240 * this VF's macvlans and there is no new list.
242 msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
243 msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
245 memcpy(msg_addr, addr, ETH_ALEN);
246 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
249 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
251 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
255 (IXGBE_VF_SET_MACVLAN | IXGBE_VT_MSGTYPE_NACK))
262 * ixgbevf_set_rar_vf - set device MAC address
263 * @hw: pointer to hardware structure
264 * @index: Receive address register to write
265 * @addr: Address to put into receive address register
266 * @vmdq: Unused in this implementation
268 static s32 ixgbevf_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr,
271 struct ixgbe_mbx_info *mbx = &hw->mbx;
273 u8 *msg_addr = (u8 *)(&msgbuf[1]);
276 memset(msgbuf, 0, sizeof(msgbuf));
277 msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
278 memcpy(msg_addr, addr, ETH_ALEN);
279 ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
282 ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
284 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
286 /* if nacked the address was rejected, use "perm_addr" */
288 (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK)))
289 ixgbevf_get_mac_addr_vf(hw, hw->mac.addr);
294 static void ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw,
297 struct ixgbe_mbx_info *mbx = &hw->mbx;
298 u32 retmsg[IXGBE_VFMAILBOX_SIZE];
299 s32 retval = mbx->ops.write_posted(hw, msg, size);
302 mbx->ops.read_posted(hw, retmsg, size);
306 * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
307 * @hw: pointer to the HW structure
308 * @netdev: pointer to net device structure
310 * Updates the Multicast Table Array.
312 static s32 ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw *hw,
313 struct net_device *netdev)
315 struct netdev_hw_addr *ha;
316 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
317 u16 *vector_list = (u16 *)&msgbuf[1];
320 /* Each entry in the list uses 1 16 bit word. We have 30
321 * 16 bit words available in our HW msg buffer (minus 1 for the
322 * msg type). That's 30 hash values if we pack 'em right. If
323 * there are more than 30 MC addresses to add then punt the
324 * extras for now and then add code to handle more than 30 later.
325 * It would be unusual for a server to request that many multi-cast
326 * addresses except for in large enterprise network environments.
329 cnt = netdev_mc_count(netdev);
332 msgbuf[0] = IXGBE_VF_SET_MULTICAST;
333 msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
336 netdev_for_each_mc_addr(ha, netdev) {
339 if (is_link_local_ether_addr(ha->addr))
342 vector_list[i++] = ixgbevf_mta_vector(hw, ha->addr);
345 ixgbevf_write_msg_read_ack(hw, msgbuf, IXGBE_VFMAILBOX_SIZE);
351 * ixgbevf_set_vfta_vf - Set/Unset vlan filter table address
352 * @hw: pointer to the HW structure
353 * @vlan: 12 bit VLAN ID
354 * @vind: unused by VF drivers
355 * @vlan_on: if true then set bit, else clear bit
357 static s32 ixgbevf_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
360 struct ixgbe_mbx_info *mbx = &hw->mbx;
364 msgbuf[0] = IXGBE_VF_SET_VLAN;
366 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
367 msgbuf[0] |= vlan_on << IXGBE_VT_MSGINFO_SHIFT;
369 err = mbx->ops.write_posted(hw, msgbuf, 2);
373 err = mbx->ops.read_posted(hw, msgbuf, 2);
377 /* remove extra bits from the message */
378 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
379 msgbuf[0] &= ~(0xFF << IXGBE_VT_MSGINFO_SHIFT);
381 if (msgbuf[0] != (IXGBE_VF_SET_VLAN | IXGBE_VT_MSGTYPE_ACK))
382 err = IXGBE_ERR_INVALID_ARGUMENT;
389 * ixgbevf_setup_mac_link_vf - Setup MAC link settings
390 * @hw: pointer to hardware structure
391 * @speed: Unused in this implementation
392 * @autoneg: Unused in this implementation
393 * @autoneg_wait_to_complete: Unused in this implementation
395 * Do nothing and return success. VF drivers are not allowed to change
396 * global settings. Maintained for driver compatibility.
398 static s32 ixgbevf_setup_mac_link_vf(struct ixgbe_hw *hw,
399 ixgbe_link_speed speed, bool autoneg,
400 bool autoneg_wait_to_complete)
406 * ixgbevf_check_mac_link_vf - Get link/speed status
407 * @hw: pointer to hardware structure
408 * @speed: pointer to link speed
409 * @link_up: true is link is up, false otherwise
410 * @autoneg_wait_to_complete: true when waiting for completion is needed
412 * Reads the links register to determine if link is up and the current speed
414 static s32 ixgbevf_check_mac_link_vf(struct ixgbe_hw *hw,
415 ixgbe_link_speed *speed,
417 bool autoneg_wait_to_complete)
419 struct ixgbe_mbx_info *mbx = &hw->mbx;
420 struct ixgbe_mac_info *mac = &hw->mac;
425 /* If we were hit with a reset drop the link */
426 if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
427 mac->get_link_status = true;
429 if (!mac->get_link_status)
432 /* if link status is down no point in checking to see if pf is up */
433 links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
434 if (!(links_reg & IXGBE_LINKS_UP))
437 switch (links_reg & IXGBE_LINKS_SPEED_82599) {
438 case IXGBE_LINKS_SPEED_10G_82599:
439 *speed = IXGBE_LINK_SPEED_10GB_FULL;
441 case IXGBE_LINKS_SPEED_1G_82599:
442 *speed = IXGBE_LINK_SPEED_1GB_FULL;
444 case IXGBE_LINKS_SPEED_100_82599:
445 *speed = IXGBE_LINK_SPEED_100_FULL;
449 /* if the read failed it could just be a mailbox collision, best wait
450 * until we are called again and don't report an error */
451 if (mbx->ops.read(hw, &in_msg, 1))
454 if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
455 /* msg is not CTS and is NACK we must have lost CTS status */
456 if (in_msg & IXGBE_VT_MSGTYPE_NACK)
461 /* the pf is talking, if we timed out in the past we reinit */
467 /* if we passed all the tests above then the link is up and we no
468 * longer need to check for link */
469 mac->get_link_status = false;
472 *link_up = !mac->get_link_status;
477 * ixgbevf_rlpml_set_vf - Set the maximum receive packet length
478 * @hw: pointer to the HW structure
479 * @max_size: value to assign to max frame size
481 void ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
485 msgbuf[0] = IXGBE_VF_SET_LPE;
486 msgbuf[1] = max_size;
487 ixgbevf_write_msg_read_ack(hw, msgbuf, 2);
491 * ixgbevf_negotiate_api_version - Negotiate supported API version
492 * @hw: pointer to the HW structure
493 * @api: integer containing requested API version
495 int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
500 /* Negotiate the mailbox API version */
501 msg[0] = IXGBE_VF_API_NEGOTIATE;
504 err = hw->mbx.ops.write_posted(hw, msg, 3);
507 err = hw->mbx.ops.read_posted(hw, msg, 3);
510 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
512 /* Store value and return 0 on success */
513 if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
514 hw->api_version = api;
518 err = IXGBE_ERR_INVALID_ARGUMENT;
524 int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
525 unsigned int *default_tc)
530 /* do nothing if API doesn't support ixgbevf_get_queues */
531 switch (hw->api_version) {
532 case ixgbe_mbox_api_11:
538 /* Fetch queue configuration from the PF */
539 msg[0] = IXGBE_VF_GET_QUEUE;
540 msg[1] = msg[2] = msg[3] = msg[4] = 0;
541 err = hw->mbx.ops.write_posted(hw, msg, 5);
544 err = hw->mbx.ops.read_posted(hw, msg, 5);
547 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
550 * if we we didn't get an ACK there must have been
551 * some sort of mailbox error so we should treat it
554 if (msg[0] != (IXGBE_VF_GET_QUEUE | IXGBE_VT_MSGTYPE_ACK))
555 return IXGBE_ERR_MBX;
557 /* record and validate values from message */
558 hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
559 if (hw->mac.max_tx_queues == 0 ||
560 hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
561 hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
563 hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
564 if (hw->mac.max_rx_queues == 0 ||
565 hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
566 hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
568 *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
569 /* in case of unknown state assume we cannot tag frames */
570 if (*num_tcs > hw->mac.max_rx_queues)
573 *default_tc = msg[IXGBE_VF_DEF_QUEUE];
574 /* default to queue 0 on out-of-bounds queue number */
575 if (*default_tc >= hw->mac.max_tx_queues)
582 static const struct ixgbe_mac_operations ixgbevf_mac_ops = {
583 .init_hw = ixgbevf_init_hw_vf,
584 .reset_hw = ixgbevf_reset_hw_vf,
585 .start_hw = ixgbevf_start_hw_vf,
586 .get_mac_addr = ixgbevf_get_mac_addr_vf,
587 .stop_adapter = ixgbevf_stop_hw_vf,
588 .setup_link = ixgbevf_setup_mac_link_vf,
589 .check_link = ixgbevf_check_mac_link_vf,
590 .set_rar = ixgbevf_set_rar_vf,
591 .update_mc_addr_list = ixgbevf_update_mc_addr_list_vf,
592 .set_uc_addr = ixgbevf_set_uc_addr_vf,
593 .set_vfta = ixgbevf_set_vfta_vf,
596 const struct ixgbevf_info ixgbevf_82599_vf_info = {
597 .mac = ixgbe_mac_82599_vf,
598 .mac_ops = &ixgbevf_mac_ops,
601 const struct ixgbevf_info ixgbevf_X540_vf_info = {
602 .mac = ixgbe_mac_X540_vf,
603 .mac_ops = &ixgbevf_mac_ops,