1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2010 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".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
31 * ixgbevf_start_hw_vf - Prepare hardware for Tx/Rx
32 * @hw: pointer to hardware structure
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
39 static s32
ixgbevf_start_hw_vf(struct ixgbe_hw
*hw
)
41 /* Clear adapter stopped flag */
42 hw
->adapter_stopped
= false;
48 * ixgbevf_init_hw_vf - virtual function hardware initialization
49 * @hw: pointer to hardware structure
51 * Initialize the hardware by resetting the hardware and then starting
54 static s32
ixgbevf_init_hw_vf(struct ixgbe_hw
*hw
)
56 s32 status
= hw
->mac
.ops
.start_hw(hw
);
58 hw
->mac
.ops
.get_mac_addr(hw
, hw
->mac
.addr
);
64 * ixgbevf_reset_hw_vf - Performs hardware reset
65 * @hw: pointer to hardware structure
67 * Resets the hardware by reseting the transmit and receive units, masks and
68 * clears all interrupts.
70 static s32
ixgbevf_reset_hw_vf(struct ixgbe_hw
*hw
)
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]);
78 /* Call adapter stop to disable tx/rx and clear interrupts */
79 hw
->mac
.ops
.stop_adapter(hw
);
81 IXGBE_WRITE_REG(hw
, IXGBE_VFCTRL
, IXGBE_CTRL_RST
);
82 IXGBE_WRITE_FLUSH(hw
);
84 /* we cannot reset while the RSTI / RSTD bits are asserted */
85 while (!mbx
->ops
.check_for_rst(hw
) && timeout
) {
91 return IXGBE_ERR_RESET_FAILED
;
93 /* mailbox timeout can now become active */
94 mbx
->timeout
= IXGBE_VF_MBX_INIT_TIMEOUT
;
96 msgbuf
[0] = IXGBE_VF_RESET
;
97 mbx
->ops
.write_posted(hw
, msgbuf
, 1);
101 /* set our "perm_addr" based on info provided by PF */
102 /* also set up the mc_filter_type which is piggy backed
103 * on the mac address in word 3 */
104 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, IXGBE_VF_PERMADDR_MSG_LEN
);
108 if (msgbuf
[0] != (IXGBE_VF_RESET
| IXGBE_VT_MSGTYPE_ACK
))
109 return IXGBE_ERR_INVALID_MAC_ADDR
;
111 memcpy(hw
->mac
.perm_addr
, addr
, IXGBE_ETH_LENGTH_OF_ADDRESS
);
112 hw
->mac
.mc_filter_type
= msgbuf
[IXGBE_VF_MC_TYPE_WORD
];
118 * ixgbevf_stop_hw_vf - Generic stop Tx/Rx units
119 * @hw: pointer to hardware structure
121 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
122 * disables transmit and receive units. The adapter_stopped flag is used by
123 * the shared code and drivers to determine if the adapter is in a stopped
124 * state and should not touch the hardware.
126 static s32
ixgbevf_stop_hw_vf(struct ixgbe_hw
*hw
)
128 u32 number_of_queues
;
133 * Set the adapter_stopped flag so other driver functions stop touching
136 hw
->adapter_stopped
= true;
138 /* Disable the receive unit by stopped each queue */
139 number_of_queues
= hw
->mac
.max_rx_queues
;
140 for (i
= 0; i
< number_of_queues
; i
++) {
141 reg_val
= IXGBE_READ_REG(hw
, IXGBE_VFRXDCTL(i
));
142 if (reg_val
& IXGBE_RXDCTL_ENABLE
) {
143 reg_val
&= ~IXGBE_RXDCTL_ENABLE
;
144 IXGBE_WRITE_REG(hw
, IXGBE_VFRXDCTL(i
), reg_val
);
148 IXGBE_WRITE_FLUSH(hw
);
150 /* Clear interrupt mask to stop from interrupts being generated */
151 IXGBE_WRITE_REG(hw
, IXGBE_VTEIMC
, IXGBE_VF_IRQ_CLEAR_MASK
);
153 /* Clear any pending interrupts */
154 IXGBE_READ_REG(hw
, IXGBE_VTEICR
);
156 /* Disable the transmit unit. Each queue must be disabled. */
157 number_of_queues
= hw
->mac
.max_tx_queues
;
158 for (i
= 0; i
< number_of_queues
; i
++) {
159 reg_val
= IXGBE_READ_REG(hw
, IXGBE_VFTXDCTL(i
));
160 if (reg_val
& IXGBE_TXDCTL_ENABLE
) {
161 reg_val
&= ~IXGBE_TXDCTL_ENABLE
;
162 IXGBE_WRITE_REG(hw
, IXGBE_VFTXDCTL(i
), reg_val
);
170 * ixgbevf_mta_vector - Determines bit-vector in multicast table to set
171 * @hw: pointer to hardware structure
172 * @mc_addr: the multicast address
174 * Extracts the 12 bits, from a multicast address, to determine which
175 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
176 * incoming rx multicast addresses, to determine the bit-vector to check in
177 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
178 * by the MO field of the MCSTCTRL. The MO field is set during initialization
181 static s32
ixgbevf_mta_vector(struct ixgbe_hw
*hw
, u8
*mc_addr
)
185 switch (hw
->mac
.mc_filter_type
) {
186 case 0: /* use bits [47:36] of the address */
187 vector
= ((mc_addr
[4] >> 4) | (((u16
)mc_addr
[5]) << 4));
189 case 1: /* use bits [46:35] of the address */
190 vector
= ((mc_addr
[4] >> 3) | (((u16
)mc_addr
[5]) << 5));
192 case 2: /* use bits [45:34] of the address */
193 vector
= ((mc_addr
[4] >> 2) | (((u16
)mc_addr
[5]) << 6));
195 case 3: /* use bits [43:32] of the address */
196 vector
= ((mc_addr
[4]) | (((u16
)mc_addr
[5]) << 8));
198 default: /* Invalid mc_filter_type */
202 /* vector can only be 12-bits or boundary will be exceeded */
208 * ixgbevf_get_mac_addr_vf - Read device MAC address
209 * @hw: pointer to the HW structure
210 * @mac_addr: pointer to storage for retrieved MAC address
212 static s32
ixgbevf_get_mac_addr_vf(struct ixgbe_hw
*hw
, u8
*mac_addr
)
214 memcpy(mac_addr
, hw
->mac
.perm_addr
, IXGBE_ETH_LENGTH_OF_ADDRESS
);
219 static s32
ixgbevf_set_uc_addr_vf(struct ixgbe_hw
*hw
, u32 index
, u8
*addr
)
221 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
223 u8
*msg_addr
= (u8
*)(&msgbuf
[1]);
226 memset(msgbuf
, 0, sizeof(msgbuf
));
228 * If index is one then this is the start of a new list and needs
229 * indication to the PF so it can do it's own list management.
230 * If it is zero then that tells the PF to just clear all of
231 * this VF's macvlans and there is no new list.
233 msgbuf
[0] |= index
<< IXGBE_VT_MSGINFO_SHIFT
;
234 msgbuf
[0] |= IXGBE_VF_SET_MACVLAN
;
236 memcpy(msg_addr
, addr
, 6);
237 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 3);
240 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
242 msgbuf
[0] &= ~IXGBE_VT_MSGTYPE_CTS
;
246 (IXGBE_VF_SET_MACVLAN
| IXGBE_VT_MSGTYPE_NACK
))
253 * ixgbevf_set_rar_vf - set device MAC address
254 * @hw: pointer to hardware structure
255 * @index: Receive address register to write
256 * @addr: Address to put into receive address register
257 * @vmdq: Unused in this implementation
259 static s32
ixgbevf_set_rar_vf(struct ixgbe_hw
*hw
, u32 index
, u8
*addr
,
262 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
264 u8
*msg_addr
= (u8
*)(&msgbuf
[1]);
267 memset(msgbuf
, 0, sizeof(msgbuf
));
268 msgbuf
[0] = IXGBE_VF_SET_MAC_ADDR
;
269 memcpy(msg_addr
, addr
, 6);
270 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 3);
273 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
275 msgbuf
[0] &= ~IXGBE_VT_MSGTYPE_CTS
;
277 /* if nacked the address was rejected, use "perm_addr" */
279 (msgbuf
[0] == (IXGBE_VF_SET_MAC_ADDR
| IXGBE_VT_MSGTYPE_NACK
)))
280 ixgbevf_get_mac_addr_vf(hw
, hw
->mac
.addr
);
286 * ixgbevf_update_mc_addr_list_vf - Update Multicast addresses
287 * @hw: pointer to the HW structure
288 * @netdev: pointer to net device structure
290 * Updates the Multicast Table Array.
292 static s32
ixgbevf_update_mc_addr_list_vf(struct ixgbe_hw
*hw
,
293 struct net_device
*netdev
)
295 struct netdev_hw_addr
*ha
;
296 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
297 u32 msgbuf
[IXGBE_VFMAILBOX_SIZE
];
298 u16
*vector_list
= (u16
*)&msgbuf
[1];
301 /* Each entry in the list uses 1 16 bit word. We have 30
302 * 16 bit words available in our HW msg buffer (minus 1 for the
303 * msg type). That's 30 hash values if we pack 'em right. If
304 * there are more than 30 MC addresses to add then punt the
305 * extras for now and then add code to handle more than 30 later.
306 * It would be unusual for a server to request that many multi-cast
307 * addresses except for in large enterprise network environments.
310 cnt
= netdev_mc_count(netdev
);
313 msgbuf
[0] = IXGBE_VF_SET_MULTICAST
;
314 msgbuf
[0] |= cnt
<< IXGBE_VT_MSGINFO_SHIFT
;
317 netdev_for_each_mc_addr(ha
, netdev
) {
320 vector_list
[i
++] = ixgbevf_mta_vector(hw
, ha
->addr
);
323 mbx
->ops
.write_posted(hw
, msgbuf
, IXGBE_VFMAILBOX_SIZE
);
329 * ixgbevf_set_vfta_vf - Set/Unset vlan filter table address
330 * @hw: pointer to the HW structure
331 * @vlan: 12 bit VLAN ID
332 * @vind: unused by VF drivers
333 * @vlan_on: if true then set bit, else clear bit
335 static s32
ixgbevf_set_vfta_vf(struct ixgbe_hw
*hw
, u32 vlan
, u32 vind
,
338 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
341 msgbuf
[0] = IXGBE_VF_SET_VLAN
;
343 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
344 msgbuf
[0] |= vlan_on
<< IXGBE_VT_MSGINFO_SHIFT
;
346 return mbx
->ops
.write_posted(hw
, msgbuf
, 2);
350 * ixgbevf_setup_mac_link_vf - Setup MAC link settings
351 * @hw: pointer to hardware structure
352 * @speed: Unused in this implementation
353 * @autoneg: Unused in this implementation
354 * @autoneg_wait_to_complete: Unused in this implementation
356 * Do nothing and return success. VF drivers are not allowed to change
357 * global settings. Maintained for driver compatibility.
359 static s32
ixgbevf_setup_mac_link_vf(struct ixgbe_hw
*hw
,
360 ixgbe_link_speed speed
, bool autoneg
,
361 bool autoneg_wait_to_complete
)
367 * ixgbevf_check_mac_link_vf - Get link/speed status
368 * @hw: pointer to hardware structure
369 * @speed: pointer to link speed
370 * @link_up: true is link is up, false otherwise
371 * @autoneg_wait_to_complete: true when waiting for completion is needed
373 * Reads the links register to determine if link is up and the current speed
375 static s32
ixgbevf_check_mac_link_vf(struct ixgbe_hw
*hw
,
376 ixgbe_link_speed
*speed
,
378 bool autoneg_wait_to_complete
)
382 if (!(hw
->mbx
.ops
.check_for_rst(hw
))) {
388 links_reg
= IXGBE_READ_REG(hw
, IXGBE_VFLINKS
);
390 if (links_reg
& IXGBE_LINKS_UP
)
395 if ((links_reg
& IXGBE_LINKS_SPEED_82599
) ==
396 IXGBE_LINKS_SPEED_10G_82599
)
397 *speed
= IXGBE_LINK_SPEED_10GB_FULL
;
399 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
404 static struct ixgbe_mac_operations ixgbevf_mac_ops
= {
405 .init_hw
= ixgbevf_init_hw_vf
,
406 .reset_hw
= ixgbevf_reset_hw_vf
,
407 .start_hw
= ixgbevf_start_hw_vf
,
408 .get_mac_addr
= ixgbevf_get_mac_addr_vf
,
409 .stop_adapter
= ixgbevf_stop_hw_vf
,
410 .setup_link
= ixgbevf_setup_mac_link_vf
,
411 .check_link
= ixgbevf_check_mac_link_vf
,
412 .set_rar
= ixgbevf_set_rar_vf
,
413 .update_mc_addr_list
= ixgbevf_update_mc_addr_list_vf
,
414 .set_uc_addr
= ixgbevf_set_uc_addr_vf
,
415 .set_vfta
= ixgbevf_set_vfta_vf
,
418 struct ixgbevf_info ixgbevf_82599_vf_info
= {
419 .mac
= ixgbe_mac_82599_vf
,
420 .mac_ops
= &ixgbevf_mac_ops
,
423 struct ixgbevf_info ixgbevf_X540_vf_info
= {
424 .mac
= ixgbe_mac_X540_vf
,
425 .mac_ops
= &ixgbevf_mac_ops
,