1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 - 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 static s32
e1000_check_for_link_vf(struct e1000_hw
*hw
);
32 static s32
e1000_get_link_up_info_vf(struct e1000_hw
*hw
, u16
*speed
,
34 static s32
e1000_init_hw_vf(struct e1000_hw
*hw
);
35 static s32
e1000_reset_hw_vf(struct e1000_hw
*hw
);
37 static void e1000_update_mc_addr_list_vf(struct e1000_hw
*hw
, u8
*,
39 static void e1000_rar_set_vf(struct e1000_hw
*, u8
*, u32
);
40 static s32
e1000_read_mac_addr_vf(struct e1000_hw
*);
41 static s32
e1000_set_vfta_vf(struct e1000_hw
*, u16
, bool);
44 * e1000_init_mac_params_vf - Inits MAC params
45 * @hw: pointer to the HW structure
47 static s32
e1000_init_mac_params_vf(struct e1000_hw
*hw
)
49 struct e1000_mac_info
*mac
= &hw
->mac
;
51 /* VF's have no MTA Registers - PF feature only */
52 mac
->mta_reg_count
= 128;
53 /* VF's have no access to RAR entries */
54 mac
->rar_entry_count
= 1;
56 /* Function pointers */
58 mac
->ops
.reset_hw
= e1000_reset_hw_vf
;
59 /* hw initialization */
60 mac
->ops
.init_hw
= e1000_init_hw_vf
;
62 mac
->ops
.check_for_link
= e1000_check_for_link_vf
;
64 mac
->ops
.get_link_up_info
= e1000_get_link_up_info_vf
;
65 /* multicast address update */
66 mac
->ops
.update_mc_addr_list
= e1000_update_mc_addr_list_vf
;
68 mac
->ops
.rar_set
= e1000_rar_set_vf
;
69 /* read mac address */
70 mac
->ops
.read_mac_addr
= e1000_read_mac_addr_vf
;
71 /* set vlan filter table array */
72 mac
->ops
.set_vfta
= e1000_set_vfta_vf
;
78 * e1000_init_function_pointers_vf - Inits function pointers
79 * @hw: pointer to the HW structure
81 void e1000_init_function_pointers_vf(struct e1000_hw
*hw
)
83 hw
->mac
.ops
.init_params
= e1000_init_mac_params_vf
;
84 hw
->mbx
.ops
.init_params
= e1000_init_mbx_params_vf
;
88 * e1000_get_link_up_info_vf - Gets link info.
89 * @hw: pointer to the HW structure
90 * @speed: pointer to 16 bit value to store link speed.
91 * @duplex: pointer to 16 bit value to store duplex.
93 * Since we cannot read the PHY and get accurate link info, we must rely upon
94 * the status register's data which is often stale and inaccurate.
96 static s32
e1000_get_link_up_info_vf(struct e1000_hw
*hw
, u16
*speed
,
101 status
= er32(STATUS
);
102 if (status
& E1000_STATUS_SPEED_1000
)
104 else if (status
& E1000_STATUS_SPEED_100
)
109 if (status
& E1000_STATUS_FD
)
110 *duplex
= FULL_DUPLEX
;
112 *duplex
= HALF_DUPLEX
;
114 return E1000_SUCCESS
;
118 * e1000_reset_hw_vf - Resets the HW
119 * @hw: pointer to the HW structure
121 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
122 * This is all the reset we can perform on a VF.
124 static s32
e1000_reset_hw_vf(struct e1000_hw
*hw
)
126 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
127 u32 timeout
= E1000_VF_INIT_TIMEOUT
;
128 u32 ret_val
= -E1000_ERR_MAC_INIT
;
130 u8
*addr
= (u8
*)(&msgbuf
[1]);
133 /* assert vf queue/interrupt reset */
135 ew32(CTRL
, ctrl
| E1000_CTRL_RST
);
137 /* we cannot initialize while the RSTI / RSTD bits are asserted */
138 while (!mbx
->ops
.check_for_rst(hw
) && timeout
) {
144 /* mailbox timeout can now become active */
145 mbx
->timeout
= E1000_VF_MBX_INIT_TIMEOUT
;
147 /* notify pf of vf reset completion */
148 msgbuf
[0] = E1000_VF_RESET
;
149 mbx
->ops
.write_posted(hw
, msgbuf
, 1);
153 /* set our "perm_addr" based on info provided by PF */
154 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
156 if (msgbuf
[0] == (E1000_VF_RESET
| E1000_VT_MSGTYPE_ACK
))
157 memcpy(hw
->mac
.perm_addr
, addr
, 6);
159 ret_val
= -E1000_ERR_MAC_INIT
;
167 * e1000_init_hw_vf - Inits the HW
168 * @hw: pointer to the HW structure
170 * Not much to do here except clear the PF Reset indication if there is one.
172 static s32
e1000_init_hw_vf(struct e1000_hw
*hw
)
174 /* attempt to set and restore our mac address */
175 e1000_rar_set_vf(hw
, hw
->mac
.addr
, 0);
177 return E1000_SUCCESS
;
181 * e1000_hash_mc_addr_vf - Generate a multicast hash value
182 * @hw: pointer to the HW structure
183 * @mc_addr: pointer to a multicast address
185 * Generates a multicast address hash value which is used to determine
186 * the multicast filter table array address and new table value. See
187 * e1000_mta_set_generic()
189 static u32
e1000_hash_mc_addr_vf(struct e1000_hw
*hw
, u8
*mc_addr
)
191 u32 hash_value
, hash_mask
;
194 /* Register count multiplied by bits per register */
195 hash_mask
= (hw
->mac
.mta_reg_count
* 32) - 1;
198 * The bit_shift is the number of left-shifts
199 * where 0xFF would still fall within the hash mask.
201 while (hash_mask
>> bit_shift
!= 0xFF)
204 hash_value
= hash_mask
& (((mc_addr
[4] >> (8 - bit_shift
)) |
205 (((u16
) mc_addr
[5]) << bit_shift
)));
211 * e1000_update_mc_addr_list_vf - Update Multicast addresses
212 * @hw: pointer to the HW structure
213 * @mc_addr_list: array of multicast addresses to program
214 * @mc_addr_count: number of multicast addresses to program
215 * @rar_used_count: the first RAR register free to program
216 * @rar_count: total number of supported Receive Address Registers
218 * Updates the Receive Address Registers and Multicast Table Array.
219 * The caller must have a packed mc_addr_list of multicast addresses.
220 * The parameter rar_count will usually be hw->mac.rar_entry_count
221 * unless there are workarounds that change this.
223 static void e1000_update_mc_addr_list_vf(struct e1000_hw
*hw
,
224 u8
*mc_addr_list
, u32 mc_addr_count
,
225 u32 rar_used_count
, u32 rar_count
)
227 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
228 u32 msgbuf
[E1000_VFMAILBOX_SIZE
];
229 u16
*hash_list
= (u16
*)&msgbuf
[1];
233 /* Each entry in the list uses 1 16 bit word. We have 30
234 * 16 bit words available in our HW msg buffer (minus 1 for the
235 * msg type). That's 30 hash values if we pack 'em right. If
236 * there are more than 30 MC addresses to add then punt the
237 * extras for now and then add code to handle more than 30 later.
238 * It would be unusual for a server to request that many multi-cast
239 * addresses except for in large enterprise network environments.
242 cnt
= (mc_addr_count
> 30) ? 30 : mc_addr_count
;
243 msgbuf
[0] = E1000_VF_SET_MULTICAST
;
244 msgbuf
[0] |= cnt
<< E1000_VT_MSGINFO_SHIFT
;
246 for (i
= 0; i
< cnt
; i
++) {
247 hash_value
= e1000_hash_mc_addr_vf(hw
, mc_addr_list
);
248 hash_list
[i
] = hash_value
& 0x0FFFF;
249 mc_addr_list
+= ETH_ADDR_LEN
;
252 mbx
->ops
.write_posted(hw
, msgbuf
, E1000_VFMAILBOX_SIZE
);
256 * e1000_set_vfta_vf - Set/Unset vlan filter table address
257 * @hw: pointer to the HW structure
258 * @vid: determines the vfta register and bit to set/unset
259 * @set: if true then set bit, else clear bit
261 static s32
e1000_set_vfta_vf(struct e1000_hw
*hw
, u16 vid
, bool set
)
263 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
267 msgbuf
[0] = E1000_VF_SET_VLAN
;
269 /* Setting the 8 bit field MSG INFO to true indicates "add" */
271 msgbuf
[0] |= 1 << E1000_VT_MSGINFO_SHIFT
;
273 mbx
->ops
.write_posted(hw
, msgbuf
, 2);
275 err
= mbx
->ops
.read_posted(hw
, msgbuf
, 2);
277 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
279 /* if nacked the vlan was rejected */
280 if (!err
&& (msgbuf
[0] == (E1000_VF_SET_VLAN
| E1000_VT_MSGTYPE_NACK
)))
281 err
= -E1000_ERR_MAC_INIT
;
286 /** e1000_rlpml_set_vf - Set the maximum receive packet length
287 * @hw: pointer to the HW structure
288 * @max_size: value to assign to max frame size
290 void e1000_rlpml_set_vf(struct e1000_hw
*hw
, u16 max_size
)
292 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
295 msgbuf
[0] = E1000_VF_SET_LPE
;
296 msgbuf
[1] = max_size
;
298 mbx
->ops
.write_posted(hw
, msgbuf
, 2);
302 * e1000_rar_set_vf - set device MAC address
303 * @hw: pointer to the HW structure
304 * @addr: pointer to the receive address
305 * @index receive address array register
307 static void e1000_rar_set_vf(struct e1000_hw
*hw
, u8
* addr
, u32 index
)
309 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
311 u8
*msg_addr
= (u8
*)(&msgbuf
[1]);
314 memset(msgbuf
, 0, 12);
315 msgbuf
[0] = E1000_VF_SET_MAC_ADDR
;
316 memcpy(msg_addr
, addr
, 6);
317 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 3);
320 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
322 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
324 /* if nacked the address was rejected, use "perm_addr" */
326 (msgbuf
[0] == (E1000_VF_SET_MAC_ADDR
| E1000_VT_MSGTYPE_NACK
)))
327 e1000_read_mac_addr_vf(hw
);
331 * e1000_read_mac_addr_vf - Read device MAC address
332 * @hw: pointer to the HW structure
334 static s32
e1000_read_mac_addr_vf(struct e1000_hw
*hw
)
338 for (i
= 0; i
< ETH_ADDR_LEN
; i
++)
339 hw
->mac
.addr
[i
] = hw
->mac
.perm_addr
[i
];
341 return E1000_SUCCESS
;
345 * e1000_check_for_link_vf - Check for link for a virtual interface
346 * @hw: pointer to the HW structure
348 * Checks to see if the underlying PF is still talking to the VF and
349 * if it is then it reports the link state to the hardware, otherwise
350 * it reports link down and returns an error.
352 static s32
e1000_check_for_link_vf(struct e1000_hw
*hw
)
354 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
355 struct e1000_mac_info
*mac
= &hw
->mac
;
356 s32 ret_val
= E1000_SUCCESS
;
360 * We only want to run this if there has been a rst asserted.
361 * in this case that could mean a link change, device reset,
362 * or a virtual function reset
365 /* If we were hit with a reset or timeout drop the link */
366 if (!mbx
->ops
.check_for_rst(hw
) || !mbx
->timeout
)
367 mac
->get_link_status
= true;
369 if (!mac
->get_link_status
)
372 /* if link status is down no point in checking to see if pf is up */
373 if (!(er32(STATUS
) & E1000_STATUS_LU
))
376 /* if the read failed it could just be a mailbox collision, best wait
377 * until we are called again and don't report an error */
378 if (mbx
->ops
.read(hw
, &in_msg
, 1))
381 /* if incoming message isn't clear to send we are waiting on response */
382 if (!(in_msg
& E1000_VT_MSGTYPE_CTS
)) {
383 /* message is not CTS and is NACK we must have lost CTS status */
384 if (in_msg
& E1000_VT_MSGTYPE_NACK
)
385 ret_val
= -E1000_ERR_MAC_INIT
;
389 /* the pf is talking, if we timed out in the past we reinit */
391 ret_val
= -E1000_ERR_MAC_INIT
;
395 /* if we passed all the tests above then the link is up and we no
396 * longer need to check for link */
397 mac
->get_link_status
= false;