1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009 - 2018 Intel Corporation. */
4 #include <linux/etherdevice.h>
8 static s32
e1000_check_for_link_vf(struct e1000_hw
*hw
);
9 static s32
e1000_get_link_up_info_vf(struct e1000_hw
*hw
, u16
*speed
,
11 static s32
e1000_init_hw_vf(struct e1000_hw
*hw
);
12 static s32
e1000_reset_hw_vf(struct e1000_hw
*hw
);
14 static void e1000_update_mc_addr_list_vf(struct e1000_hw
*hw
, u8
*,
16 static void e1000_rar_set_vf(struct e1000_hw
*, u8
*, u32
);
17 static s32
e1000_read_mac_addr_vf(struct e1000_hw
*);
18 static s32
e1000_set_uc_addr_vf(struct e1000_hw
*hw
, u32 subcmd
, u8
*addr
);
19 static s32
e1000_set_vfta_vf(struct e1000_hw
*, u16
, bool);
22 * e1000_init_mac_params_vf - Inits MAC params
23 * @hw: pointer to the HW structure
25 static s32
e1000_init_mac_params_vf(struct e1000_hw
*hw
)
27 struct e1000_mac_info
*mac
= &hw
->mac
;
29 /* VF's have no MTA Registers - PF feature only */
30 mac
->mta_reg_count
= 128;
31 /* VF's have no access to RAR entries */
32 mac
->rar_entry_count
= 1;
34 /* Function pointers */
36 mac
->ops
.reset_hw
= e1000_reset_hw_vf
;
37 /* hw initialization */
38 mac
->ops
.init_hw
= e1000_init_hw_vf
;
40 mac
->ops
.check_for_link
= e1000_check_for_link_vf
;
42 mac
->ops
.get_link_up_info
= e1000_get_link_up_info_vf
;
43 /* multicast address update */
44 mac
->ops
.update_mc_addr_list
= e1000_update_mc_addr_list_vf
;
46 mac
->ops
.rar_set
= e1000_rar_set_vf
;
47 /* read mac address */
48 mac
->ops
.read_mac_addr
= e1000_read_mac_addr_vf
;
50 mac
->ops
.set_uc_addr
= e1000_set_uc_addr_vf
;
51 /* set vlan filter table array */
52 mac
->ops
.set_vfta
= e1000_set_vfta_vf
;
58 * e1000_init_function_pointers_vf - Inits function pointers
59 * @hw: pointer to the HW structure
61 void e1000_init_function_pointers_vf(struct e1000_hw
*hw
)
63 hw
->mac
.ops
.init_params
= e1000_init_mac_params_vf
;
64 hw
->mbx
.ops
.init_params
= e1000_init_mbx_params_vf
;
68 * e1000_get_link_up_info_vf - Gets link info.
69 * @hw: pointer to the HW structure
70 * @speed: pointer to 16 bit value to store link speed.
71 * @duplex: pointer to 16 bit value to store duplex.
73 * Since we cannot read the PHY and get accurate link info, we must rely upon
74 * the status register's data which is often stale and inaccurate.
76 static s32
e1000_get_link_up_info_vf(struct e1000_hw
*hw
, u16
*speed
,
81 status
= er32(STATUS
);
82 if (status
& E1000_STATUS_SPEED_1000
)
84 else if (status
& E1000_STATUS_SPEED_100
)
89 if (status
& E1000_STATUS_FD
)
90 *duplex
= FULL_DUPLEX
;
92 *duplex
= HALF_DUPLEX
;
98 * e1000_reset_hw_vf - Resets the HW
99 * @hw: pointer to the HW structure
101 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
102 * This is all the reset we can perform on a VF.
104 static s32
e1000_reset_hw_vf(struct e1000_hw
*hw
)
106 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
107 u32 timeout
= E1000_VF_INIT_TIMEOUT
;
108 u32 ret_val
= -E1000_ERR_MAC_INIT
;
110 u8
*addr
= (u8
*)(&msgbuf
[1]);
113 /* assert VF queue/interrupt reset */
115 ew32(CTRL
, ctrl
| E1000_CTRL_RST
);
117 /* we cannot initialize while the RSTI / RSTD bits are asserted */
118 while (!mbx
->ops
.check_for_rst(hw
) && timeout
) {
124 /* mailbox timeout can now become active */
125 mbx
->timeout
= E1000_VF_MBX_INIT_TIMEOUT
;
127 /* notify PF of VF reset completion */
128 msgbuf
[0] = E1000_VF_RESET
;
129 mbx
->ops
.write_posted(hw
, msgbuf
, 1);
133 /* set our "perm_addr" based on info provided by PF */
134 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
137 case E1000_VF_RESET
| E1000_VT_MSGTYPE_ACK
:
138 memcpy(hw
->mac
.perm_addr
, addr
, ETH_ALEN
);
140 case E1000_VF_RESET
| E1000_VT_MSGTYPE_NACK
:
141 eth_zero_addr(hw
->mac
.perm_addr
);
144 ret_val
= -E1000_ERR_MAC_INIT
;
153 * e1000_init_hw_vf - Inits the HW
154 * @hw: pointer to the HW structure
156 * Not much to do here except clear the PF Reset indication if there is one.
158 static s32
e1000_init_hw_vf(struct e1000_hw
*hw
)
160 /* attempt to set and restore our mac address */
161 e1000_rar_set_vf(hw
, hw
->mac
.addr
, 0);
163 return E1000_SUCCESS
;
167 * e1000_hash_mc_addr_vf - Generate a multicast hash value
168 * @hw: pointer to the HW structure
169 * @mc_addr: pointer to a multicast address
171 * Generates a multicast address hash value which is used to determine
172 * the multicast filter table array address and new table value. See
173 * e1000_mta_set_generic()
175 static u32
e1000_hash_mc_addr_vf(struct e1000_hw
*hw
, u8
*mc_addr
)
177 u32 hash_value
, hash_mask
;
180 /* Register count multiplied by bits per register */
181 hash_mask
= (hw
->mac
.mta_reg_count
* 32) - 1;
183 /* The bit_shift is the number of left-shifts
184 * where 0xFF would still fall within the hash mask.
186 while (hash_mask
>> bit_shift
!= 0xFF)
189 hash_value
= hash_mask
& (((mc_addr
[4] >> (8 - bit_shift
)) |
190 (((u16
)mc_addr
[5]) << bit_shift
)));
196 * e1000_update_mc_addr_list_vf - Update Multicast addresses
197 * @hw: pointer to the HW structure
198 * @mc_addr_list: array of multicast addresses to program
199 * @mc_addr_count: number of multicast addresses to program
200 * @rar_used_count: the first RAR register free to program
201 * @rar_count: total number of supported Receive Address Registers
203 * Updates the Receive Address Registers and Multicast Table Array.
204 * The caller must have a packed mc_addr_list of multicast addresses.
205 * The parameter rar_count will usually be hw->mac.rar_entry_count
206 * unless there are workarounds that change this.
208 static void e1000_update_mc_addr_list_vf(struct e1000_hw
*hw
,
209 u8
*mc_addr_list
, u32 mc_addr_count
,
210 u32 rar_used_count
, u32 rar_count
)
212 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
213 u32 msgbuf
[E1000_VFMAILBOX_SIZE
];
214 u16
*hash_list
= (u16
*)&msgbuf
[1];
219 /* Each entry in the list uses 1 16 bit word. We have 30
220 * 16 bit words available in our HW msg buffer (minus 1 for the
221 * msg type). That's 30 hash values if we pack 'em right. If
222 * there are more than 30 MC addresses to add then punt the
223 * extras for now and then add code to handle more than 30 later.
224 * It would be unusual for a server to request that many multi-cast
225 * addresses except for in large enterprise network environments.
228 cnt
= (mc_addr_count
> 30) ? 30 : mc_addr_count
;
229 msgbuf
[0] = E1000_VF_SET_MULTICAST
;
230 msgbuf
[0] |= cnt
<< E1000_VT_MSGINFO_SHIFT
;
232 for (i
= 0; i
< cnt
; i
++) {
233 hash_value
= e1000_hash_mc_addr_vf(hw
, mc_addr_list
);
234 hash_list
[i
] = hash_value
& 0x0FFFF;
235 mc_addr_list
+= ETH_ALEN
;
238 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, E1000_VFMAILBOX_SIZE
);
240 mbx
->ops
.read_posted(hw
, msgbuf
, 1);
244 * e1000_set_vfta_vf - Set/Unset vlan filter table address
245 * @hw: pointer to the HW structure
246 * @vid: determines the vfta register and bit to set/unset
247 * @set: if true then set bit, else clear bit
249 static s32
e1000_set_vfta_vf(struct e1000_hw
*hw
, u16 vid
, bool set
)
251 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
255 msgbuf
[0] = E1000_VF_SET_VLAN
;
257 /* Setting the 8 bit field MSG INFO to true indicates "add" */
259 msgbuf
[0] |= BIT(E1000_VT_MSGINFO_SHIFT
);
261 mbx
->ops
.write_posted(hw
, msgbuf
, 2);
263 err
= mbx
->ops
.read_posted(hw
, msgbuf
, 2);
265 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
267 /* if nacked the vlan was rejected */
268 if (!err
&& (msgbuf
[0] == (E1000_VF_SET_VLAN
| E1000_VT_MSGTYPE_NACK
)))
269 err
= -E1000_ERR_MAC_INIT
;
275 * e1000_rlpml_set_vf - Set the maximum receive packet length
276 * @hw: pointer to the HW structure
277 * @max_size: value to assign to max frame size
279 void e1000_rlpml_set_vf(struct e1000_hw
*hw
, u16 max_size
)
281 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
285 msgbuf
[0] = E1000_VF_SET_LPE
;
286 msgbuf
[1] = max_size
;
288 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 2);
290 mbx
->ops
.read_posted(hw
, msgbuf
, 1);
294 * e1000_rar_set_vf - set device MAC address
295 * @hw: pointer to the HW structure
296 * @addr: pointer to the receive address
297 * @index: receive address array register
299 static void e1000_rar_set_vf(struct e1000_hw
*hw
, u8
*addr
, u32 index
)
301 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
303 u8
*msg_addr
= (u8
*)(&msgbuf
[1]);
306 memset(msgbuf
, 0, 12);
307 msgbuf
[0] = E1000_VF_SET_MAC_ADDR
;
308 memcpy(msg_addr
, addr
, ETH_ALEN
);
309 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 3);
312 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
314 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
316 /* if nacked the address was rejected, use "perm_addr" */
318 (msgbuf
[0] == (E1000_VF_SET_MAC_ADDR
| E1000_VT_MSGTYPE_NACK
)))
319 e1000_read_mac_addr_vf(hw
);
323 * e1000_read_mac_addr_vf - Read device MAC address
324 * @hw: pointer to the HW structure
326 static s32
e1000_read_mac_addr_vf(struct e1000_hw
*hw
)
328 memcpy(hw
->mac
.addr
, hw
->mac
.perm_addr
, ETH_ALEN
);
330 return E1000_SUCCESS
;
334 * e1000_set_uc_addr_vf - Set or clear unicast filters
335 * @hw: pointer to the HW structure
336 * @sub_cmd: add or clear filters
337 * @addr: pointer to the filter MAC address
339 static s32
e1000_set_uc_addr_vf(struct e1000_hw
*hw
, u32 sub_cmd
, u8
*addr
)
341 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
342 u32 msgbuf
[3], msgbuf_chk
;
343 u8
*msg_addr
= (u8
*)(&msgbuf
[1]);
346 memset(msgbuf
, 0, sizeof(msgbuf
));
347 msgbuf
[0] |= sub_cmd
;
348 msgbuf
[0] |= E1000_VF_SET_MAC_ADDR
;
349 msgbuf_chk
= msgbuf
[0];
352 memcpy(msg_addr
, addr
, ETH_ALEN
);
354 ret_val
= mbx
->ops
.write_posted(hw
, msgbuf
, 3);
357 ret_val
= mbx
->ops
.read_posted(hw
, msgbuf
, 3);
359 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
362 msgbuf
[0] &= ~E1000_VT_MSGTYPE_CTS
;
364 if (msgbuf
[0] == (msgbuf_chk
| E1000_VT_MSGTYPE_NACK
))
372 * e1000_check_for_link_vf - Check for link for a virtual interface
373 * @hw: pointer to the HW structure
375 * Checks to see if the underlying PF is still talking to the VF and
376 * if it is then it reports the link state to the hardware, otherwise
377 * it reports link down and returns an error.
379 static s32
e1000_check_for_link_vf(struct e1000_hw
*hw
)
381 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
382 struct e1000_mac_info
*mac
= &hw
->mac
;
383 s32 ret_val
= E1000_SUCCESS
;
386 /* We only want to run this if there has been a rst asserted.
387 * in this case that could mean a link change, device reset,
388 * or a virtual function reset
391 /* If we were hit with a reset or timeout drop the link */
392 if (!mbx
->ops
.check_for_rst(hw
) || !mbx
->timeout
)
393 mac
->get_link_status
= true;
395 if (!mac
->get_link_status
)
398 /* if link status is down no point in checking to see if PF is up */
399 if (!(er32(STATUS
) & E1000_STATUS_LU
))
402 /* if the read failed it could just be a mailbox collision, best wait
403 * until we are called again and don't report an error
405 if (mbx
->ops
.read(hw
, &in_msg
, 1))
408 /* if incoming message isn't clear to send we are waiting on response */
409 if (!(in_msg
& E1000_VT_MSGTYPE_CTS
)) {
410 /* msg is not CTS and is NACK we must have lost CTS status */
411 if (in_msg
& E1000_VT_MSGTYPE_NACK
)
412 ret_val
= -E1000_ERR_MAC_INIT
;
416 /* the PF is talking, if we timed out in the past we reinit */
418 ret_val
= -E1000_ERR_MAC_INIT
;
422 /* if we passed all the tests above then the link is up and we no
423 * longer need to check for link
425 mac
->get_link_status
= false;