1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013 - 2015 Intel Corporation
8 * fm10k_stop_hw_vf - Stop Tx/Rx units
9 * @hw: pointer to hardware structure
12 STATIC s32 fm10k_stop_hw_vf(struct fm10k_hw *hw)
14 u8 *perm_addr = hw->mac.perm_addr;
15 u32 bal = 0, bah = 0, tdlen;
19 DEBUGFUNC("fm10k_stop_hw_vf");
21 /* we need to disable the queues before taking further steps */
22 err = fm10k_stop_hw_generic(hw);
23 if (err && err != FM10K_ERR_REQUESTS_PENDING)
26 /* If permanent address is set then we need to restore it */
27 if (IS_VALID_ETHER_ADDR(perm_addr)) {
28 bal = (((u32)perm_addr[3]) << 24) |
29 (((u32)perm_addr[4]) << 16) |
30 (((u32)perm_addr[5]) << 8);
31 bah = (((u32)0xFF) << 24) |
32 (((u32)perm_addr[0]) << 16) |
33 (((u32)perm_addr[1]) << 8) |
37 /* restore default itr_scale for next VF initialization */
38 tdlen = hw->mac.itr_scale << FM10K_TDLEN_ITR_SCALE_SHIFT;
40 /* The queues have already been disabled so we just need to
41 * update their base address registers
43 for (i = 0; i < hw->mac.max_queues; i++) {
44 FM10K_WRITE_REG(hw, FM10K_TDBAL(i), bal);
45 FM10K_WRITE_REG(hw, FM10K_TDBAH(i), bah);
46 FM10K_WRITE_REG(hw, FM10K_RDBAL(i), bal);
47 FM10K_WRITE_REG(hw, FM10K_RDBAH(i), bah);
48 /* Restore ITR scale in software-defined mechanism in TDLEN
49 * for next VF initialization. See definition of
50 * FM10K_TDLEN_ITR_SCALE_SHIFT for more details on the use of
53 FM10K_WRITE_REG(hw, FM10K_TDLEN(i), tdlen);
60 * fm10k_reset_hw_vf - VF hardware reset
61 * @hw: pointer to hardware structure
63 * This function should return the hardware to a state similar to the
64 * one it is in after just being initialized.
66 STATIC s32 fm10k_reset_hw_vf(struct fm10k_hw *hw)
70 DEBUGFUNC("fm10k_reset_hw_vf");
72 /* shut down queues we own and reset DMA configuration */
73 err = fm10k_stop_hw_vf(hw);
74 if (err == FM10K_ERR_REQUESTS_PENDING)
75 hw->mac.reset_while_pending++;
79 /* Inititate VF reset */
80 FM10K_WRITE_REG(hw, FM10K_VFCTRL, FM10K_VFCTRL_RST);
82 /* Flush write and allow 100us for reset to complete */
83 FM10K_WRITE_FLUSH(hw);
84 usec_delay(FM10K_RESET_TIMEOUT);
86 /* Clear reset bit and verify it was cleared */
87 FM10K_WRITE_REG(hw, FM10K_VFCTRL, 0);
88 if (FM10K_READ_REG(hw, FM10K_VFCTRL) & FM10K_VFCTRL_RST)
89 return FM10K_ERR_RESET_FAILED;
95 * fm10k_init_hw_vf - VF hardware initialization
96 * @hw: pointer to hardware structure
99 STATIC s32 fm10k_init_hw_vf(struct fm10k_hw *hw)
101 u32 tqdloc, tqdloc0 = ~FM10K_READ_REG(hw, FM10K_TQDLOC(0));
105 DEBUGFUNC("fm10k_init_hw_vf");
107 /* verify we have at least 1 queue */
108 if (!~FM10K_READ_REG(hw, FM10K_TXQCTL(0)) ||
109 !~FM10K_READ_REG(hw, FM10K_RXQCTL(0))) {
110 err = FM10K_ERR_NO_RESOURCES;
111 goto reset_max_queues;
114 /* determine how many queues we have */
115 for (i = 1; tqdloc0 && (i < FM10K_MAX_QUEUES_POOL); i++) {
116 /* verify the Descriptor cache offsets are increasing */
117 tqdloc = ~FM10K_READ_REG(hw, FM10K_TQDLOC(i));
118 if (!tqdloc || (tqdloc == tqdloc0))
121 /* check to verify the PF doesn't own any of our queues */
122 if (!~FM10K_READ_REG(hw, FM10K_TXQCTL(i)) ||
123 !~FM10K_READ_REG(hw, FM10K_RXQCTL(i)))
127 /* shut down queues we own and reset DMA configuration */
128 err = fm10k_disable_queues_generic(hw, i);
130 goto reset_max_queues;
132 /* record maximum queue count */
133 hw->mac.max_queues = i;
135 /* fetch default VLAN and ITR scale */
136 hw->mac.default_vid = (FM10K_READ_REG(hw, FM10K_TXQCTL(0)) &
137 FM10K_TXQCTL_VID_MASK) >> FM10K_TXQCTL_VID_SHIFT;
138 /* Read the ITR scale from TDLEN. See the definition of
139 * FM10K_TDLEN_ITR_SCALE_SHIFT for more information about how TDLEN is
142 hw->mac.itr_scale = (FM10K_READ_REG(hw, FM10K_TDLEN(0)) &
143 FM10K_TDLEN_ITR_SCALE_MASK) >>
144 FM10K_TDLEN_ITR_SCALE_SHIFT;
146 return FM10K_SUCCESS;
149 hw->mac.max_queues = 0;
154 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
156 * fm10k_is_slot_appropriate_vf - Indicate appropriate slot for this SKU
157 * @hw: pointer to hardware structure
159 * Looks at the PCIe bus info to confirm whether or not this slot can support
160 * the necessary bandwidth for this device. Since the VF has no control over
161 * the "slot" it is in, always indicate that the slot is appropriate.
163 STATIC bool fm10k_is_slot_appropriate_vf(struct fm10k_hw *hw)
165 UNREFERENCED_1PARAMETER(hw);
166 DEBUGFUNC("fm10k_is_slot_appropriate_vf");
172 /* This structure defines the attibutes to be parsed below */
173 const struct fm10k_tlv_attr fm10k_mac_vlan_msg_attr[] = {
174 FM10K_TLV_ATTR_U32(FM10K_MAC_VLAN_MSG_VLAN),
175 FM10K_TLV_ATTR_BOOL(FM10K_MAC_VLAN_MSG_SET),
176 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MAC),
177 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_DEFAULT_MAC),
178 FM10K_TLV_ATTR_MAC_ADDR(FM10K_MAC_VLAN_MSG_MULTICAST),
183 * fm10k_update_vlan_vf - Update status of VLAN ID in VLAN filter table
184 * @hw: pointer to hardware structure
185 * @vid: VLAN ID to add to table
186 * @vsi: Reserved, should always be 0
187 * @set: Indicates if this is a set or clear operation
189 * This function adds or removes the corresponding VLAN ID from the VLAN
190 * filter table for this VF.
192 STATIC s32 fm10k_update_vlan_vf(struct fm10k_hw *hw, u32 vid, u8 vsi, bool set)
194 struct fm10k_mbx_info *mbx = &hw->mbx;
197 /* verify the index is not set */
199 return FM10K_ERR_PARAM;
201 /* clever trick to verify reserved bits in both vid and length */
202 if ((vid << 16 | vid) >> 28)
203 return FM10K_ERR_PARAM;
205 /* encode set bit into the VLAN ID */
207 vid |= FM10K_VLAN_CLEAR;
209 /* generate VLAN request */
210 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
211 fm10k_tlv_attr_put_u32(msg, FM10K_MAC_VLAN_MSG_VLAN, vid);
213 /* load onto outgoing mailbox */
214 return mbx->ops.enqueue_tx(hw, mbx, msg);
218 * fm10k_msg_mac_vlan_vf - Read device MAC address from mailbox message
219 * @hw: pointer to the HW structure
220 * @results: Attributes for message
221 * @mbx: unused mailbox data
223 * This function should determine the MAC address for the VF
225 s32 fm10k_msg_mac_vlan_vf(struct fm10k_hw *hw, u32 **results,
226 struct fm10k_mbx_info *mbx)
228 u8 perm_addr[ETH_ALEN];
232 UNREFERENCED_1PARAMETER(mbx);
233 DEBUGFUNC("fm10k_msg_mac_vlan_vf");
235 /* record MAC address requested */
236 err = fm10k_tlv_attr_get_mac_vlan(
237 results[FM10K_MAC_VLAN_MSG_DEFAULT_MAC],
242 memcpy(hw->mac.perm_addr, perm_addr, ETH_ALEN);
243 hw->mac.default_vid = vid & (FM10K_VLAN_TABLE_VID_MAX - 1);
244 hw->mac.vlan_override = !!(vid & FM10K_VLAN_OVERRIDE);
246 return FM10K_SUCCESS;
250 * fm10k_read_mac_addr_vf - Read device MAC address
251 * @hw: pointer to the HW structure
253 * This function should determine the MAC address for the VF
255 STATIC s32 fm10k_read_mac_addr_vf(struct fm10k_hw *hw)
257 u8 perm_addr[ETH_ALEN];
260 DEBUGFUNC("fm10k_read_mac_addr_vf");
262 base_addr = FM10K_READ_REG(hw, FM10K_TDBAL(0));
264 /* last byte should be 0 */
266 return FM10K_ERR_INVALID_MAC_ADDR;
268 perm_addr[3] = (u8)(base_addr >> 24);
269 perm_addr[4] = (u8)(base_addr >> 16);
270 perm_addr[5] = (u8)(base_addr >> 8);
272 base_addr = FM10K_READ_REG(hw, FM10K_TDBAH(0));
274 /* first byte should be all 1's */
275 if ((~base_addr) >> 24)
276 return FM10K_ERR_INVALID_MAC_ADDR;
278 perm_addr[0] = (u8)(base_addr >> 16);
279 perm_addr[1] = (u8)(base_addr >> 8);
280 perm_addr[2] = (u8)(base_addr);
282 memcpy(hw->mac.perm_addr, perm_addr, ETH_ALEN);
283 memcpy(hw->mac.addr, perm_addr, ETH_ALEN);
285 return FM10K_SUCCESS;
289 * fm10k_update_uc_addr_vf - Update device unicast addresses
290 * @hw: pointer to the HW structure
292 * @mac: MAC address to add/remove from table
293 * @vid: VLAN ID to add/remove from table
294 * @add: Indicates if this is an add or remove operation
295 * @flags: flags field to indicate add and secure - unused
297 * This function is used to add or remove unicast MAC addresses for
300 STATIC s32 fm10k_update_uc_addr_vf(struct fm10k_hw *hw, u16 glort,
301 const u8 *mac, u16 vid, bool add, u8 flags)
303 struct fm10k_mbx_info *mbx = &hw->mbx;
306 DEBUGFUNC("fm10k_update_uc_addr_vf");
308 UNREFERENCED_2PARAMETER(glort, flags);
310 /* verify VLAN ID is valid */
311 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
312 return FM10K_ERR_PARAM;
314 /* verify MAC address is valid */
315 if (!IS_VALID_ETHER_ADDR(mac))
316 return FM10K_ERR_PARAM;
318 /* verify we are not locked down on the MAC address */
319 if (IS_VALID_ETHER_ADDR(hw->mac.perm_addr) &&
320 memcmp(hw->mac.perm_addr, mac, ETH_ALEN))
321 return FM10K_ERR_PARAM;
323 /* add bit to notify us if this is a set or clear operation */
325 vid |= FM10K_VLAN_CLEAR;
327 /* generate VLAN request */
328 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
329 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MAC, mac, vid);
331 /* load onto outgoing mailbox */
332 return mbx->ops.enqueue_tx(hw, mbx, msg);
336 * fm10k_update_mc_addr_vf - Update device multicast addresses
337 * @hw: pointer to the HW structure
339 * @mac: MAC address to add/remove from table
340 * @vid: VLAN ID to add/remove from table
341 * @add: Indicates if this is an add or remove operation
343 * This function is used to add or remove multicast MAC addresses for
346 STATIC s32 fm10k_update_mc_addr_vf(struct fm10k_hw *hw, u16 glort,
347 const u8 *mac, u16 vid, bool add)
349 struct fm10k_mbx_info *mbx = &hw->mbx;
352 DEBUGFUNC("fm10k_update_uc_addr_vf");
354 UNREFERENCED_1PARAMETER(glort);
356 /* verify VLAN ID is valid */
357 if (vid >= FM10K_VLAN_TABLE_VID_MAX)
358 return FM10K_ERR_PARAM;
360 /* verify multicast address is valid */
361 if (!IS_MULTICAST_ETHER_ADDR(mac))
362 return FM10K_ERR_PARAM;
364 /* add bit to notify us if this is a set or clear operation */
366 vid |= FM10K_VLAN_CLEAR;
368 /* generate VLAN request */
369 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MAC_VLAN);
370 fm10k_tlv_attr_put_mac_vlan(msg, FM10K_MAC_VLAN_MSG_MULTICAST,
373 /* load onto outgoing mailbox */
374 return mbx->ops.enqueue_tx(hw, mbx, msg);
378 * fm10k_update_int_moderator_vf - Request update of interrupt moderator list
379 * @hw: pointer to hardware structure
381 * This function will issue a request to the PF to rescan our MSI-X table
382 * and to update the interrupt moderator linked list.
384 STATIC void fm10k_update_int_moderator_vf(struct fm10k_hw *hw)
386 struct fm10k_mbx_info *mbx = &hw->mbx;
389 /* generate MSI-X request */
390 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_MSIX);
392 /* load onto outgoing mailbox */
393 mbx->ops.enqueue_tx(hw, mbx, msg);
396 /* This structure defines the attibutes to be parsed below */
397 const struct fm10k_tlv_attr fm10k_lport_state_msg_attr[] = {
398 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_DISABLE),
399 FM10K_TLV_ATTR_U8(FM10K_LPORT_STATE_MSG_XCAST_MODE),
400 FM10K_TLV_ATTR_BOOL(FM10K_LPORT_STATE_MSG_READY),
405 * fm10k_msg_lport_state_vf - Message handler for lport_state message from PF
406 * @hw: Pointer to hardware structure
407 * @results: pointer array containing parsed data
408 * @mbx: Pointer to mailbox information structure
410 * This handler is meant to capture the indication from the PF that we
411 * are ready to bring up the interface.
413 s32 fm10k_msg_lport_state_vf(struct fm10k_hw *hw, u32 **results,
414 struct fm10k_mbx_info *mbx)
416 UNREFERENCED_1PARAMETER(mbx);
417 DEBUGFUNC("fm10k_msg_lport_state_vf");
419 hw->mac.dglort_map = !results[FM10K_LPORT_STATE_MSG_READY] ?
420 FM10K_DGLORTMAP_NONE : FM10K_DGLORTMAP_ZERO;
422 return FM10K_SUCCESS;
426 * fm10k_update_lport_state_vf - Update device state in lower device
427 * @hw: pointer to the HW structure
429 * @count: number of logical ports to enable - unused (always 1)
430 * @enable: boolean value indicating if this is an enable or disable request
432 * Notify the lower device of a state change. If the lower device is
433 * enabled we can add filters, if it is disabled all filters for this
434 * logical port are flushed.
436 STATIC s32 fm10k_update_lport_state_vf(struct fm10k_hw *hw, u16 glort,
437 u16 count, bool enable)
439 struct fm10k_mbx_info *mbx = &hw->mbx;
442 UNREFERENCED_2PARAMETER(glort, count);
443 DEBUGFUNC("fm10k_update_lport_state_vf");
445 /* reset glort mask 0 as we have to wait to be enabled */
446 hw->mac.dglort_map = FM10K_DGLORTMAP_NONE;
448 /* generate port state request */
449 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
451 fm10k_tlv_attr_put_bool(msg, FM10K_LPORT_STATE_MSG_DISABLE);
453 /* load onto outgoing mailbox */
454 return mbx->ops.enqueue_tx(hw, mbx, msg);
458 * fm10k_update_xcast_mode_vf - Request update of multicast mode
459 * @hw: pointer to hardware structure
461 * @mode: integer value indicating mode being requested
463 * This function will attempt to request a higher mode for the port
464 * so that it can enable either multicast, multicast promiscuous, or
465 * promiscuous mode of operation.
467 STATIC s32 fm10k_update_xcast_mode_vf(struct fm10k_hw *hw, u16 glort, u8 mode)
469 struct fm10k_mbx_info *mbx = &hw->mbx;
472 UNREFERENCED_1PARAMETER(glort);
473 DEBUGFUNC("fm10k_update_xcast_mode_vf");
475 if (mode > FM10K_XCAST_MODE_NONE)
476 return FM10K_ERR_PARAM;
478 /* generate message requesting to change xcast mode */
479 fm10k_tlv_msg_init(msg, FM10K_VF_MSG_ID_LPORT_STATE);
480 fm10k_tlv_attr_put_u8(msg, FM10K_LPORT_STATE_MSG_XCAST_MODE, mode);
482 /* load onto outgoing mailbox */
483 return mbx->ops.enqueue_tx(hw, mbx, msg);
486 const struct fm10k_tlv_attr fm10k_1588_msg_attr[] = {
487 FM10K_TLV_ATTR_U64(FM10K_1588_MSG_CLK_OFFSET),
491 /* currently there is no shared 1588 message handler */
494 * fm10k_update_hw_stats_vf - Updates hardware related statistics of VF
495 * @hw: pointer to hardware structure
496 * @stats: pointer to statistics structure
498 * This function collects and aggregates per queue hardware statistics.
500 void fm10k_update_hw_stats_vf(struct fm10k_hw *hw,
501 struct fm10k_hw_stats *stats)
503 DEBUGFUNC("fm10k_update_hw_stats_vf");
505 fm10k_update_hw_stats_q(hw, stats->q, 0, hw->mac.max_queues);
509 * fm10k_rebind_hw_stats_vf - Resets base for hardware statistics of VF
510 * @hw: pointer to hardware structure
511 * @stats: pointer to the stats structure to update
513 * This function resets the base for queue hardware statistics.
515 void fm10k_rebind_hw_stats_vf(struct fm10k_hw *hw,
516 struct fm10k_hw_stats *stats)
518 DEBUGFUNC("fm10k_rebind_hw_stats_vf");
520 /* Unbind Queue Statistics */
521 fm10k_unbind_hw_stats_q(stats->q, 0, hw->mac.max_queues);
523 /* Reinitialize bases for all stats */
524 fm10k_update_hw_stats_vf(hw, stats);
528 * fm10k_configure_dglort_map_vf - Configures GLORT entry and queues
529 * @hw: pointer to hardware structure
530 * @dglort: pointer to dglort configuration structure
532 * Reads the configuration structure contained in dglort_cfg and uses
533 * that information to then populate a DGLORTMAP/DEC entry and the queues
534 * to which it has been assigned.
536 STATIC s32 fm10k_configure_dglort_map_vf(struct fm10k_hw *hw,
537 struct fm10k_dglort_cfg *dglort)
539 UNREFERENCED_1PARAMETER(hw);
540 DEBUGFUNC("fm10k_configure_dglort_map_vf");
542 /* verify the dglort pointer */
544 return FM10K_ERR_PARAM;
546 /* stub for now until we determine correct message for this */
548 return FM10K_SUCCESS;
552 * fm10k_adjust_systime_vf - Adjust systime frequency
553 * @hw: pointer to hardware structure
554 * @ppb: adjustment rate in parts per billion
556 * This function takes an adjustment rate in parts per billion and will
557 * verify that this value is 0 as the VF cannot support adjusting the
560 * If the ppb value is non-zero the return is ERR_PARAM else success
562 STATIC s32 fm10k_adjust_systime_vf(struct fm10k_hw *hw, s32 ppb)
564 UNREFERENCED_1PARAMETER(hw);
565 DEBUGFUNC("fm10k_adjust_systime_vf");
567 /* The VF cannot adjust the clock frequency, however it should
568 * already have a syntonic clock with whichever host interface is
569 * running as the master for the host interface clock domain so
570 * there should be not frequency adjustment necessary.
572 return ppb ? FM10K_ERR_PARAM : FM10K_SUCCESS;
576 * fm10k_read_systime_vf - Reads value of systime registers
577 * @hw: pointer to the hardware structure
579 * Function reads the content of 2 registers, combined to represent a 64 bit
580 * value measured in nanoseconds. In order to guarantee the value is accurate
581 * we check the 32 most significant bits both before and after reading the
582 * 32 least significant bits to verify they didn't change as we were reading
585 static u64 fm10k_read_systime_vf(struct fm10k_hw *hw)
587 u32 systime_l, systime_h, systime_tmp;
589 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
592 systime_tmp = systime_h;
593 systime_l = fm10k_read_reg(hw, FM10K_VFSYSTIME);
594 systime_h = fm10k_read_reg(hw, FM10K_VFSYSTIME + 1);
595 } while (systime_tmp != systime_h);
597 return ((u64)systime_h << 32) | systime_l;
600 static const struct fm10k_msg_data fm10k_msg_data_vf[] = {
601 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
602 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
603 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
604 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
608 * fm10k_init_ops_vf - Inits func ptrs and MAC type
609 * @hw: pointer to hardware structure
611 * Initialize the function pointers and assign the MAC type for VF.
612 * Does not touch the hardware.
614 s32 fm10k_init_ops_vf(struct fm10k_hw *hw)
616 struct fm10k_mac_info *mac = &hw->mac;
618 DEBUGFUNC("fm10k_init_ops_vf");
620 fm10k_init_ops_generic(hw);
622 mac->ops.reset_hw = &fm10k_reset_hw_vf;
623 mac->ops.init_hw = &fm10k_init_hw_vf;
624 mac->ops.start_hw = &fm10k_start_hw_generic;
625 mac->ops.stop_hw = &fm10k_stop_hw_vf;
626 #ifndef NO_IS_SLOT_APPROPRIATE_CHECK
627 mac->ops.is_slot_appropriate = &fm10k_is_slot_appropriate_vf;
629 mac->ops.update_vlan = &fm10k_update_vlan_vf;
630 mac->ops.read_mac_addr = &fm10k_read_mac_addr_vf;
631 mac->ops.update_uc_addr = &fm10k_update_uc_addr_vf;
632 mac->ops.update_mc_addr = &fm10k_update_mc_addr_vf;
633 mac->ops.update_xcast_mode = &fm10k_update_xcast_mode_vf;
634 mac->ops.update_int_moderator = &fm10k_update_int_moderator_vf;
635 mac->ops.update_lport_state = &fm10k_update_lport_state_vf;
636 mac->ops.update_hw_stats = &fm10k_update_hw_stats_vf;
637 mac->ops.rebind_hw_stats = &fm10k_rebind_hw_stats_vf;
638 mac->ops.configure_dglort_map = &fm10k_configure_dglort_map_vf;
639 mac->ops.get_host_state = &fm10k_get_host_state_generic;
640 mac->ops.adjust_systime = &fm10k_adjust_systime_vf;
641 mac->ops.read_systime = &fm10k_read_systime_vf;
643 mac->max_msix_vectors = fm10k_get_pcie_msix_count_generic(hw);
645 return fm10k_pfvf_mbx_init(hw, &hw->mbx, fm10k_msg_data_vf, 0);