1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
3 */
4
5
6 #include "e1000_api.h"
7
8
9 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
10 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
11 STATIC void e1000_release_vf(struct e1000_hw *hw);
12 STATIC s32 e1000_acquire_vf(struct e1000_hw *hw);
13 STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw);
14 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
15 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
16 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw);
17 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
18 u16 *duplex);
19 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw);
20 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw);
21 STATIC void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
22 STATIC int e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
23 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *);
24
25 /**
26 * e1000_init_phy_params_vf - Inits PHY params
27 * @hw: pointer to the HW structure
28 *
29 * Doesn't do much - there's no PHY available to the VF.
30 **/
e1000_init_phy_params_vf(struct e1000_hw * hw)31 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
32 {
33 DEBUGFUNC("e1000_init_phy_params_vf");
34 hw->phy.type = e1000_phy_vf;
35 hw->phy.ops.acquire = e1000_acquire_vf;
36 hw->phy.ops.release = e1000_release_vf;
37
38 return E1000_SUCCESS;
39 }
40
41 /**
42 * e1000_init_nvm_params_vf - Inits NVM params
43 * @hw: pointer to the HW structure
44 *
45 * Doesn't do much - there's no NVM available to the VF.
46 **/
e1000_init_nvm_params_vf(struct e1000_hw * hw)47 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
48 {
49 DEBUGFUNC("e1000_init_nvm_params_vf");
50 hw->nvm.type = e1000_nvm_none;
51 hw->nvm.ops.acquire = e1000_acquire_vf;
52 hw->nvm.ops.release = e1000_release_vf;
53
54 return E1000_SUCCESS;
55 }
56
57 /**
58 * e1000_init_mac_params_vf - Inits MAC params
59 * @hw: pointer to the HW structure
60 **/
e1000_init_mac_params_vf(struct e1000_hw * hw)61 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
62 {
63 struct e1000_mac_info *mac = &hw->mac;
64
65 DEBUGFUNC("e1000_init_mac_params_vf");
66
67 /* Set media type */
68 /*
69 * Virtual functions don't care what they're media type is as they
70 * have no direct access to the PHY, or the media. That is handled
71 * by the physical function driver.
72 */
73 hw->phy.media_type = e1000_media_type_unknown;
74
75 /* No ASF features for the VF driver */
76 mac->asf_firmware_present = false;
77 /* ARC subsystem not supported */
78 mac->arc_subsystem_valid = false;
79 /* Disable adaptive IFS mode so the generic funcs don't do anything */
80 mac->adaptive_ifs = false;
81 /* VF's have no MTA Registers - PF feature only */
82 mac->mta_reg_count = 128;
83 /* VF's have no access to RAR entries */
84 mac->rar_entry_count = 1;
85
86 /* Function pointers */
87 /* link setup */
88 mac->ops.setup_link = e1000_setup_link_vf;
89 /* bus type/speed/width */
90 mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
91 /* reset */
92 mac->ops.reset_hw = e1000_reset_hw_vf;
93 /* hw initialization */
94 mac->ops.init_hw = e1000_init_hw_vf;
95 /* check for link */
96 mac->ops.check_for_link = e1000_check_for_link_vf;
97 /* link info */
98 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
99 /* multicast address update */
100 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
101 /* set mac address */
102 mac->ops.rar_set = e1000_rar_set_vf;
103 /* read mac address */
104 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
105
106
107 return E1000_SUCCESS;
108 }
109
110 /**
111 * e1000_init_function_pointers_vf - Inits function pointers
112 * @hw: pointer to the HW structure
113 **/
e1000_init_function_pointers_vf(struct e1000_hw * hw)114 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
115 {
116 DEBUGFUNC("e1000_init_function_pointers_vf");
117
118 hw->mac.ops.init_params = e1000_init_mac_params_vf;
119 hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
120 hw->phy.ops.init_params = e1000_init_phy_params_vf;
121 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
122 }
123
124 /**
125 * e1000_acquire_vf - Acquire rights to access PHY or NVM.
126 * @hw: pointer to the HW structure
127 *
128 * There is no PHY or NVM so we want all attempts to acquire these to fail.
129 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
130 * even want any SW to attempt to use them.
131 **/
e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG * hw)132 STATIC s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
133 {
134 UNREFERENCED_1PARAMETER(hw);
135 return -E1000_ERR_PHY;
136 }
137
138 /**
139 * e1000_release_vf - Release PHY or NVM
140 * @hw: pointer to the HW structure
141 *
142 * There is no PHY or NVM so we want all attempts to acquire these to fail.
143 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
144 * even want any SW to attempt to use them.
145 **/
e1000_release_vf(struct e1000_hw E1000_UNUSEDARG * hw)146 STATIC void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
147 {
148 UNREFERENCED_1PARAMETER(hw);
149 return;
150 }
151
152 /**
153 * e1000_setup_link_vf - Sets up link.
154 * @hw: pointer to the HW structure
155 *
156 * Virtual functions cannot change link.
157 **/
e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG * hw)158 STATIC s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
159 {
160 DEBUGFUNC("e1000_setup_link_vf");
161 UNREFERENCED_1PARAMETER(hw);
162
163 return E1000_SUCCESS;
164 }
165
166 /**
167 * e1000_get_bus_info_pcie_vf - Gets the bus info.
168 * @hw: pointer to the HW structure
169 *
170 * Virtual functions are not really on their own bus.
171 **/
e1000_get_bus_info_pcie_vf(struct e1000_hw * hw)172 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
173 {
174 struct e1000_bus_info *bus = &hw->bus;
175
176 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
177
178 /* Do not set type PCI-E because we don't want disable master to run */
179 bus->type = e1000_bus_type_reserved;
180 bus->speed = e1000_bus_speed_2500;
181
182 return 0;
183 }
184
185 /**
186 * e1000_get_link_up_info_vf - Gets link info.
187 * @hw: pointer to the HW structure
188 * @speed: pointer to 16 bit value to store link speed.
189 * @duplex: pointer to 16 bit value to store duplex.
190 *
191 * Since we cannot read the PHY and get accurate link info, we must rely upon
192 * the status register's data which is often stale and inaccurate.
193 **/
e1000_get_link_up_info_vf(struct e1000_hw * hw,u16 * speed,u16 * duplex)194 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
195 u16 *duplex)
196 {
197 s32 status;
198
199 DEBUGFUNC("e1000_get_link_up_info_vf");
200
201 status = E1000_READ_REG(hw, E1000_STATUS);
202 if (status & E1000_STATUS_SPEED_1000) {
203 *speed = SPEED_1000;
204 DEBUGOUT("1000 Mbs, ");
205 } else if (status & E1000_STATUS_SPEED_100) {
206 *speed = SPEED_100;
207 DEBUGOUT("100 Mbs, ");
208 } else {
209 *speed = SPEED_10;
210 DEBUGOUT("10 Mbs, ");
211 }
212
213 if (status & E1000_STATUS_FD) {
214 *duplex = FULL_DUPLEX;
215 DEBUGOUT("Full Duplex\n");
216 } else {
217 *duplex = HALF_DUPLEX;
218 DEBUGOUT("Half Duplex\n");
219 }
220
221 return E1000_SUCCESS;
222 }
223
224 /**
225 * e1000_reset_hw_vf - Resets the HW
226 * @hw: pointer to the HW structure
227 *
228 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
229 * This is all the reset we can perform on a VF.
230 **/
e1000_reset_hw_vf(struct e1000_hw * hw)231 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw)
232 {
233 struct e1000_mbx_info *mbx = &hw->mbx;
234 u32 timeout = E1000_VF_INIT_TIMEOUT;
235 s32 ret_val = -E1000_ERR_MAC_INIT;
236 u32 ctrl, msgbuf[3];
237 u8 *addr = (u8 *)(&msgbuf[1]);
238
239 DEBUGFUNC("e1000_reset_hw_vf");
240
241 DEBUGOUT("Issuing a function level reset to MAC\n");
242 ctrl = E1000_READ_REG(hw, E1000_CTRL);
243 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
244
245 /* we cannot reset while the RSTI / RSTD bits are asserted */
246 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
247 timeout--;
248 usec_delay(5);
249 }
250
251 if (timeout) {
252 /* mailbox timeout can now become active */
253 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
254
255 msgbuf[0] = E1000_VF_RESET;
256 mbx->ops.write_posted(hw, msgbuf, 1, 0);
257
258 msec_delay(10);
259
260 /* set our "perm_addr" based on info provided by PF */
261 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
262 if (!ret_val) {
263 if (msgbuf[0] == (E1000_VF_RESET |
264 E1000_VT_MSGTYPE_ACK))
265 memcpy(hw->mac.perm_addr, addr, 6);
266 else
267 ret_val = -E1000_ERR_MAC_INIT;
268 }
269 }
270
271 return ret_val;
272 }
273
274 /**
275 * e1000_init_hw_vf - Inits the HW
276 * @hw: pointer to the HW structure
277 *
278 * Not much to do here except clear the PF Reset indication if there is one.
279 **/
e1000_init_hw_vf(struct e1000_hw * hw)280 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw)
281 {
282 DEBUGFUNC("e1000_init_hw_vf");
283
284 /* attempt to set and restore our mac address */
285 e1000_rar_set_vf(hw, hw->mac.addr, 0);
286
287 return E1000_SUCCESS;
288 }
289
290 /**
291 * e1000_rar_set_vf - set device MAC address
292 * @hw: pointer to the HW structure
293 * @addr: pointer to the receive address
294 * @index receive address array register
295 **/
e1000_rar_set_vf(struct e1000_hw * hw,u8 * addr,u32 E1000_UNUSEDARG index)296 STATIC int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
297 u32 E1000_UNUSEDARG index)
298 {
299 struct e1000_mbx_info *mbx = &hw->mbx;
300 u32 msgbuf[3];
301 u8 *msg_addr = (u8 *)(&msgbuf[1]);
302 s32 ret_val;
303
304 UNREFERENCED_1PARAMETER(index);
305 memset(msgbuf, 0, 12);
306 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
307 memcpy(msg_addr, addr, 6);
308 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
309
310 if (!ret_val)
311 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
312
313 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
314
315 /* if nacked the address was rejected, use "perm_addr" */
316 if (!ret_val &&
317 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
318 e1000_read_mac_addr_vf(hw);
319
320 return E1000_SUCCESS;
321 }
322
323 /**
324 * e1000_hash_mc_addr_vf - Generate a multicast hash value
325 * @hw: pointer to the HW structure
326 * @mc_addr: pointer to a multicast address
327 *
328 * Generates a multicast address hash value which is used to determine
329 * the multicast filter table array address and new table value.
330 **/
e1000_hash_mc_addr_vf(struct e1000_hw * hw,u8 * mc_addr)331 STATIC u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
332 {
333 u32 hash_value, hash_mask;
334 u8 bit_shift = 0;
335
336 DEBUGFUNC("e1000_hash_mc_addr_generic");
337
338 /* Register count multiplied by bits per register */
339 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
340
341 /*
342 * The bit_shift is the number of left-shifts
343 * where 0xFF would still fall within the hash mask.
344 */
345 while (hash_mask >> bit_shift != 0xFF)
346 bit_shift++;
347
348 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
349 (((u16) mc_addr[5]) << bit_shift)));
350
351 return hash_value;
352 }
353
e1000_write_msg_read_ack(struct e1000_hw * hw,u32 * msg,u16 size)354 STATIC void e1000_write_msg_read_ack(struct e1000_hw *hw,
355 u32 *msg, u16 size)
356 {
357 struct e1000_mbx_info *mbx = &hw->mbx;
358 u32 retmsg[E1000_VFMAILBOX_SIZE];
359 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
360
361 if (!retval)
362 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
363 }
364
365 /**
366 * e1000_update_mc_addr_list_vf - Update Multicast addresses
367 * @hw: pointer to the HW structure
368 * @mc_addr_list: array of multicast addresses to program
369 * @mc_addr_count: number of multicast addresses to program
370 *
371 * Updates the Multicast Table Array.
372 * The caller must have a packed mc_addr_list of multicast addresses.
373 **/
e1000_update_mc_addr_list_vf(struct e1000_hw * hw,u8 * mc_addr_list,u32 mc_addr_count)374 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
375 u8 *mc_addr_list, u32 mc_addr_count)
376 {
377 u32 msgbuf[E1000_VFMAILBOX_SIZE];
378 u16 *hash_list = (u16 *)&msgbuf[1];
379 u32 hash_value;
380 u32 i;
381
382 DEBUGFUNC("e1000_update_mc_addr_list_vf");
383
384 /* Each entry in the list uses 1 16 bit word. We have 30
385 * 16 bit words available in our HW msg buffer (minus 1 for the
386 * msg type). That's 30 hash values if we pack 'em right. If
387 * there are more than 30 MC addresses to add then punt the
388 * extras for now and then add code to handle more than 30 later.
389 * It would be unusual for a server to request that many multi-cast
390 * addresses except for in large enterprise network environments.
391 */
392
393 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
394
395 msgbuf[0] = E1000_VF_SET_MULTICAST;
396
397 if (mc_addr_count > 30) {
398 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
399 mc_addr_count = 30;
400 }
401
402 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
403
404 for (i = 0; i < mc_addr_count; i++) {
405 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
406 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
407 hash_list[i] = hash_value & 0x0FFF;
408 mc_addr_list += ETH_ADDR_LEN;
409 }
410
411 e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
412 }
413
414 /**
415 * e1000_vfta_set_vf - Set/Unset vlan filter table address
416 * @hw: pointer to the HW structure
417 * @vid: determines the vfta register and bit to set/unset
418 * @set: if true then set bit, else clear bit
419 **/
e1000_vfta_set_vf(struct e1000_hw * hw,u16 vid,bool set)420 void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
421 {
422 u32 msgbuf[2];
423
424 msgbuf[0] = E1000_VF_SET_VLAN;
425 msgbuf[1] = vid;
426 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
427 if (set)
428 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
429
430 e1000_write_msg_read_ack(hw, msgbuf, 2);
431 }
432
433 /** e1000_rlpml_set_vf - Set the maximum receive packet length
434 * @hw: pointer to the HW structure
435 * @max_size: value to assign to max frame size
436 **/
e1000_rlpml_set_vf(struct e1000_hw * hw,u16 max_size)437 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
438 {
439 u32 msgbuf[2];
440
441 msgbuf[0] = E1000_VF_SET_LPE;
442 msgbuf[1] = max_size;
443
444 e1000_write_msg_read_ack(hw, msgbuf, 2);
445 }
446
447 /**
448 * e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
449 * @hw: pointer to the HW structure
450 * @uni: boolean indicating unicast promisc status
451 * @multi: boolean indicating multicast promisc status
452 **/
e1000_promisc_set_vf(struct e1000_hw * hw,enum e1000_promisc_type type)453 s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
454 {
455 struct e1000_mbx_info *mbx = &hw->mbx;
456 u32 msgbuf = E1000_VF_SET_PROMISC;
457 s32 ret_val;
458
459 switch (type) {
460 case e1000_promisc_multicast:
461 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
462 break;
463 case e1000_promisc_enabled:
464 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
465 /* fall-through */
466 case e1000_promisc_unicast:
467 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
468 /* fall-through */
469 case e1000_promisc_disabled:
470 break;
471 default:
472 return -E1000_ERR_MAC_INIT;
473 }
474
475 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
476
477 if (!ret_val)
478 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
479
480 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
481 ret_val = -E1000_ERR_MAC_INIT;
482
483 return ret_val;
484 }
485
486 /**
487 * e1000_read_mac_addr_vf - Read device MAC address
488 * @hw: pointer to the HW structure
489 **/
e1000_read_mac_addr_vf(struct e1000_hw * hw)490 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
491 {
492 int i;
493
494 for (i = 0; i < ETH_ADDR_LEN; i++)
495 hw->mac.addr[i] = hw->mac.perm_addr[i];
496
497 return E1000_SUCCESS;
498 }
499
500 /**
501 * e1000_check_for_link_vf - Check for link for a virtual interface
502 * @hw: pointer to the HW structure
503 *
504 * Checks to see if the underlying PF is still talking to the VF and
505 * if it is then it reports the link state to the hardware, otherwise
506 * it reports link down and returns an error.
507 **/
e1000_check_for_link_vf(struct e1000_hw * hw)508 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw)
509 {
510 struct e1000_mbx_info *mbx = &hw->mbx;
511 struct e1000_mac_info *mac = &hw->mac;
512 s32 ret_val = E1000_SUCCESS;
513 u32 in_msg = 0;
514
515 DEBUGFUNC("e1000_check_for_link_vf");
516
517 /*
518 * We only want to run this if there has been a rst asserted.
519 * in this case that could mean a link change, device reset,
520 * or a virtual function reset
521 */
522
523 /* If we were hit with a reset or timeout drop the link */
524 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
525 mac->get_link_status = true;
526
527 if (!mac->get_link_status)
528 goto out;
529
530 /* if link status is down no point in checking to see if pf is up */
531 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
532 goto out;
533
534 /* if the read failed it could just be a mailbox collision, best wait
535 * until we are called again and don't report an error */
536 if (mbx->ops.read(hw, &in_msg, 1, 0))
537 goto out;
538
539 /* if incoming message isn't clear to send we are waiting on response */
540 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
541 /* message is not CTS and is NACK we have lost CTS status */
542 if (in_msg & E1000_VT_MSGTYPE_NACK)
543 ret_val = -E1000_ERR_MAC_INIT;
544 goto out;
545 }
546
547 /* at this point we know the PF is talking to us, check and see if
548 * we are still accepting timeout or if we had a timeout failure.
549 * if we failed then we will need to reinit */
550 if (!mbx->timeout) {
551 ret_val = -E1000_ERR_MAC_INIT;
552 goto out;
553 }
554
555 /* if we passed all the tests above then the link is up and we no
556 * longer need to check for link */
557 mac->get_link_status = false;
558
559 out:
560 return ret_val;
561 }
562
563