1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #define DRV_VERSION "0.7.2-k"
12 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
13 const char ice_drv_ver[] = DRV_VERSION;
14 static const char ice_driver_string[] = DRV_SUMMARY;
15 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
17 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
18 MODULE_DESCRIPTION(DRV_SUMMARY);
19 MODULE_LICENSE("GPL v2");
20 MODULE_VERSION(DRV_VERSION);
22 static int debug = -1;
23 module_param(debug, int, 0644);
24 #ifndef CONFIG_DYNAMIC_DEBUG
25 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
27 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
28 #endif /* !CONFIG_DYNAMIC_DEBUG */
30 static struct workqueue_struct *ice_wq;
31 static const struct net_device_ops ice_netdev_ops;
33 static void ice_pf_dis_all_vsi(struct ice_pf *pf);
34 static void ice_rebuild(struct ice_pf *pf);
36 static void ice_vsi_release_all(struct ice_pf *pf);
37 static void ice_update_vsi_stats(struct ice_vsi *vsi);
38 static void ice_update_pf_stats(struct ice_pf *pf);
41 * ice_get_tx_pending - returns number of Tx descriptors not processed
42 * @ring: the ring of descriptors
44 static u32 ice_get_tx_pending(struct ice_ring *ring)
48 head = ring->next_to_clean;
49 tail = readl(ring->tail);
52 return (head < tail) ?
53 tail - head : (tail + ring->count - head);
58 * ice_check_for_hang_subtask - check for and recover hung queues
59 * @pf: pointer to PF struct
61 static void ice_check_for_hang_subtask(struct ice_pf *pf)
63 struct ice_vsi *vsi = NULL;
68 ice_for_each_vsi(pf, v)
69 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
74 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
77 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
80 for (i = 0; i < vsi->num_txq; i++) {
81 struct ice_ring *tx_ring = vsi->tx_rings[i];
83 if (tx_ring && tx_ring->desc) {
84 int itr = ICE_ITR_NONE;
86 /* If packet counter has not changed the queue is
87 * likely stalled, so force an interrupt for this
90 * prev_pkt would be negative if there was no
93 packets = tx_ring->stats.pkts & INT_MAX;
94 if (tx_ring->tx_stats.prev_pkt == packets) {
95 /* Trigger sw interrupt to revive the queue */
96 v_idx = tx_ring->q_vector->v_idx;
98 GLINT_DYN_CTL(vsi->hw_base_vector + v_idx),
99 (itr << GLINT_DYN_CTL_ITR_INDX_S) |
100 GLINT_DYN_CTL_SWINT_TRIG_M |
101 GLINT_DYN_CTL_INTENA_MSK_M);
105 /* Memory barrier between read of packet count and call
106 * to ice_get_tx_pending()
109 tx_ring->tx_stats.prev_pkt =
110 ice_get_tx_pending(tx_ring) ? packets : -1;
116 * ice_add_mac_to_sync_list - creates list of mac addresses to be synced
117 * @netdev: the net device on which the sync is happening
118 * @addr: mac address to sync
120 * This is a callback function which is called by the in kernel device sync
121 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
122 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
123 * mac filters from the hardware.
125 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
127 struct ice_netdev_priv *np = netdev_priv(netdev);
128 struct ice_vsi *vsi = np->vsi;
130 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
137 * ice_add_mac_to_unsync_list - creates list of mac addresses to be unsynced
138 * @netdev: the net device on which the unsync is happening
139 * @addr: mac address to unsync
141 * This is a callback function which is called by the in kernel device unsync
142 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
143 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
144 * delete the mac filters from the hardware.
146 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
148 struct ice_netdev_priv *np = netdev_priv(netdev);
149 struct ice_vsi *vsi = np->vsi;
151 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
158 * ice_vsi_fltr_changed - check if filter state changed
159 * @vsi: VSI to be checked
161 * returns true if filter state has changed, false otherwise.
163 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
165 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
166 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
167 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
171 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
172 * @vsi: ptr to the VSI
174 * Push any outstanding VSI filter changes through the AdminQ.
176 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
178 struct device *dev = &vsi->back->pdev->dev;
179 struct net_device *netdev = vsi->netdev;
180 bool promisc_forced_on = false;
181 struct ice_pf *pf = vsi->back;
182 struct ice_hw *hw = &pf->hw;
183 enum ice_status status = 0;
184 u32 changed_flags = 0;
190 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
191 usleep_range(1000, 2000);
193 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
194 vsi->current_netdev_flags = vsi->netdev->flags;
196 INIT_LIST_HEAD(&vsi->tmp_sync_list);
197 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
199 if (ice_vsi_fltr_changed(vsi)) {
200 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
201 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
202 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
204 /* grab the netdev's addr_list_lock */
205 netif_addr_lock_bh(netdev);
206 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
207 ice_add_mac_to_unsync_list);
208 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
209 ice_add_mac_to_unsync_list);
210 /* our temp lists are populated. release lock */
211 netif_addr_unlock_bh(netdev);
214 /* Remove mac addresses in the unsync list */
215 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
216 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
218 netdev_err(netdev, "Failed to delete MAC filters\n");
219 /* if we failed because of alloc failures, just bail */
220 if (status == ICE_ERR_NO_MEMORY) {
226 /* Add mac addresses in the sync list */
227 status = ice_add_mac(hw, &vsi->tmp_sync_list);
228 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
230 netdev_err(netdev, "Failed to add MAC filters\n");
231 /* If there is no more space for new umac filters, vsi
232 * should go into promiscuous mode. There should be some
233 * space reserved for promiscuous filters.
235 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
236 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
238 promisc_forced_on = true;
240 "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
247 /* check for changes in promiscuous modes */
248 if (changed_flags & IFF_ALLMULTI)
249 netdev_warn(netdev, "Unsupported configuration\n");
251 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
252 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
253 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
254 if (vsi->current_netdev_flags & IFF_PROMISC) {
255 /* Apply TX filter rule to get traffic from VMs */
256 status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
259 netdev_err(netdev, "Error setting default VSI %i tx rule\n",
261 vsi->current_netdev_flags &= ~IFF_PROMISC;
265 /* Apply RX filter rule to get traffic from wire */
266 status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
269 netdev_err(netdev, "Error setting default VSI %i rx rule\n",
271 vsi->current_netdev_flags &= ~IFF_PROMISC;
276 /* Clear TX filter rule to stop traffic from VMs */
277 status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
280 netdev_err(netdev, "Error clearing default VSI %i tx rule\n",
282 vsi->current_netdev_flags |= IFF_PROMISC;
286 /* Clear RX filter to remove traffic from wire */
287 status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
290 netdev_err(netdev, "Error clearing default VSI %i rx rule\n",
292 vsi->current_netdev_flags |= IFF_PROMISC;
301 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
304 /* if something went wrong then set the changed flag so we try again */
305 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
306 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
308 clear_bit(__ICE_CFG_BUSY, vsi->state);
313 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
314 * @pf: board private structure
316 static void ice_sync_fltr_subtask(struct ice_pf *pf)
320 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
323 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
325 for (v = 0; v < pf->num_alloc_vsi; v++)
326 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
327 ice_vsi_sync_fltr(pf->vsi[v])) {
328 /* come back and try again later */
329 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
335 * ice_prepare_for_reset - prep for the core to reset
336 * @pf: board private structure
338 * Inform or close all dependent features in prep for reset.
341 ice_prepare_for_reset(struct ice_pf *pf)
343 struct ice_hw *hw = &pf->hw;
345 /* Notify VFs of impending reset */
346 if (ice_check_sq_alive(hw, &hw->mailboxq))
347 ice_vc_notify_reset(pf);
349 /* disable the VSIs and their queues that are not already DOWN */
350 ice_pf_dis_all_vsi(pf);
353 ice_sched_clear_port(hw->port_info);
355 ice_shutdown_all_ctrlq(hw);
357 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
361 * ice_do_reset - Initiate one of many types of resets
362 * @pf: board private structure
363 * @reset_type: reset type requested
364 * before this function was called.
366 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
368 struct device *dev = &pf->pdev->dev;
369 struct ice_hw *hw = &pf->hw;
371 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
372 WARN_ON(in_interrupt());
374 ice_prepare_for_reset(pf);
376 /* trigger the reset */
377 if (ice_reset(hw, reset_type)) {
378 dev_err(dev, "reset %d failed\n", reset_type);
379 set_bit(__ICE_RESET_FAILED, pf->state);
380 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
381 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
382 clear_bit(__ICE_PFR_REQ, pf->state);
383 clear_bit(__ICE_CORER_REQ, pf->state);
384 clear_bit(__ICE_GLOBR_REQ, pf->state);
388 /* PFR is a bit of a special case because it doesn't result in an OICR
389 * interrupt. So for PFR, rebuild after the reset and clear the reset-
390 * associated state bits.
392 if (reset_type == ICE_RESET_PFR) {
395 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
396 clear_bit(__ICE_PFR_REQ, pf->state);
401 * ice_reset_subtask - Set up for resetting the device and driver
402 * @pf: board private structure
404 static void ice_reset_subtask(struct ice_pf *pf)
406 enum ice_reset_req reset_type = ICE_RESET_INVAL;
408 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
409 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
410 * of reset is pending and sets bits in pf->state indicating the reset
411 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
412 * prepare for pending reset if not already (for PF software-initiated
413 * global resets the software should already be prepared for it as
414 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
415 * by firmware or software on other PFs, that bit is not set so prepare
416 * for the reset now), poll for reset done, rebuild and return.
418 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
419 clear_bit(__ICE_GLOBR_RECV, pf->state);
420 clear_bit(__ICE_CORER_RECV, pf->state);
421 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
422 ice_prepare_for_reset(pf);
424 /* make sure we are ready to rebuild */
425 if (ice_check_reset(&pf->hw)) {
426 set_bit(__ICE_RESET_FAILED, pf->state);
428 /* done with reset. start rebuild */
429 pf->hw.reset_ongoing = false;
431 /* clear bit to resume normal operations, but
432 * ICE_NEEDS_RESTART bit is set incase rebuild failed
434 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
435 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
436 clear_bit(__ICE_PFR_REQ, pf->state);
437 clear_bit(__ICE_CORER_REQ, pf->state);
438 clear_bit(__ICE_GLOBR_REQ, pf->state);
444 /* No pending resets to finish processing. Check for new resets */
445 if (test_bit(__ICE_PFR_REQ, pf->state))
446 reset_type = ICE_RESET_PFR;
447 if (test_bit(__ICE_CORER_REQ, pf->state))
448 reset_type = ICE_RESET_CORER;
449 if (test_bit(__ICE_GLOBR_REQ, pf->state))
450 reset_type = ICE_RESET_GLOBR;
451 /* If no valid reset type requested just return */
452 if (reset_type == ICE_RESET_INVAL)
455 /* reset if not already down or busy */
456 if (!test_bit(__ICE_DOWN, pf->state) &&
457 !test_bit(__ICE_CFG_BUSY, pf->state)) {
458 ice_do_reset(pf, reset_type);
463 * ice_print_link_msg - print link up or down message
464 * @vsi: the VSI whose link status is being queried
465 * @isup: boolean for if the link is now up or down
467 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
472 if (vsi->current_isup == isup)
475 vsi->current_isup = isup;
478 netdev_info(vsi->netdev, "NIC Link is Down\n");
482 switch (vsi->port_info->phy.link_info.link_speed) {
483 case ICE_AQ_LINK_SPEED_40GB:
486 case ICE_AQ_LINK_SPEED_25GB:
489 case ICE_AQ_LINK_SPEED_20GB:
492 case ICE_AQ_LINK_SPEED_10GB:
495 case ICE_AQ_LINK_SPEED_5GB:
498 case ICE_AQ_LINK_SPEED_2500MB:
501 case ICE_AQ_LINK_SPEED_1000MB:
504 case ICE_AQ_LINK_SPEED_100MB:
512 switch (vsi->port_info->fc.current_mode) {
516 case ICE_FC_TX_PAUSE:
519 case ICE_FC_RX_PAUSE:
527 netdev_info(vsi->netdev, "NIC Link is up %sbps, Flow Control: %s\n",
532 * ice_vsi_link_event - update the vsi's netdev
533 * @vsi: the vsi on which the link event occurred
534 * @link_up: whether or not the vsi needs to be set up or down
536 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
538 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
541 if (vsi->type == ICE_VSI_PF) {
543 dev_dbg(&vsi->back->pdev->dev,
544 "vsi->netdev is not initialized!\n");
548 netif_carrier_on(vsi->netdev);
549 netif_tx_wake_all_queues(vsi->netdev);
551 netif_carrier_off(vsi->netdev);
552 netif_tx_stop_all_queues(vsi->netdev);
558 * ice_link_event - process the link event
559 * @pf: pf that the link event is associated with
560 * @pi: port_info for the port that the link event is associated with
562 * Returns -EIO if ice_get_link_status() fails
563 * Returns 0 on success
566 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi)
568 u8 new_link_speed, old_link_speed;
569 struct ice_phy_info *phy_info;
570 bool new_link_same_as_old;
571 bool new_link, old_link;
576 phy_info->link_info_old = phy_info->link_info;
577 /* Force ice_get_link_status() to update link info */
578 phy_info->get_link_info = true;
580 old_link = (phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
581 old_link_speed = phy_info->link_info_old.link_speed;
584 if (ice_get_link_status(pi, &new_link)) {
585 dev_dbg(&pf->pdev->dev,
586 "Could not get link status for port %d\n", lport);
590 new_link_speed = phy_info->link_info.link_speed;
592 new_link_same_as_old = (new_link == old_link &&
593 new_link_speed == old_link_speed);
595 ice_for_each_vsi(pf, v) {
596 struct ice_vsi *vsi = pf->vsi[v];
598 if (!vsi || !vsi->port_info)
601 if (new_link_same_as_old &&
602 (test_bit(__ICE_DOWN, vsi->state) ||
603 new_link == netif_carrier_ok(vsi->netdev)))
606 if (vsi->port_info->lport == lport) {
607 ice_print_link_msg(vsi, new_link);
608 ice_vsi_link_event(vsi, new_link);
612 ice_vc_notify_link_state(pf);
618 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
619 * @pf: board private structure
621 static void ice_watchdog_subtask(struct ice_pf *pf)
625 /* if interface is down do nothing */
626 if (test_bit(__ICE_DOWN, pf->state) ||
627 test_bit(__ICE_CFG_BUSY, pf->state))
630 /* make sure we don't do these things too often */
631 if (time_before(jiffies,
632 pf->serv_tmr_prev + pf->serv_tmr_period))
635 pf->serv_tmr_prev = jiffies;
637 if (ice_link_event(pf, pf->hw.port_info))
638 dev_dbg(&pf->pdev->dev, "ice_link_event failed\n");
640 /* Update the stats for active netdevs so the network stack
641 * can look at updated numbers whenever it cares to
643 ice_update_pf_stats(pf);
644 for (i = 0; i < pf->num_alloc_vsi; i++)
645 if (pf->vsi[i] && pf->vsi[i]->netdev)
646 ice_update_vsi_stats(pf->vsi[i]);
650 * __ice_clean_ctrlq - helper function to clean controlq rings
651 * @pf: ptr to struct ice_pf
652 * @q_type: specific Control queue type
654 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
656 struct ice_rq_event_info event;
657 struct ice_hw *hw = &pf->hw;
658 struct ice_ctl_q_info *cq;
663 /* Do not clean control queue if/when PF reset fails */
664 if (test_bit(__ICE_RESET_FAILED, pf->state))
668 case ICE_CTL_Q_ADMIN:
672 case ICE_CTL_Q_MAILBOX:
677 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
682 /* check for error indications - PF_xx_AxQLEN register layout for
683 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
685 val = rd32(hw, cq->rq.len);
686 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
687 PF_FW_ARQLEN_ARQCRIT_M)) {
689 if (val & PF_FW_ARQLEN_ARQVFE_M)
690 dev_dbg(&pf->pdev->dev,
691 "%s Receive Queue VF Error detected\n", qtype);
692 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
693 dev_dbg(&pf->pdev->dev,
694 "%s Receive Queue Overflow Error detected\n",
697 if (val & PF_FW_ARQLEN_ARQCRIT_M)
698 dev_dbg(&pf->pdev->dev,
699 "%s Receive Queue Critical Error detected\n",
701 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
702 PF_FW_ARQLEN_ARQCRIT_M);
704 wr32(hw, cq->rq.len, val);
707 val = rd32(hw, cq->sq.len);
708 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
709 PF_FW_ATQLEN_ATQCRIT_M)) {
711 if (val & PF_FW_ATQLEN_ATQVFE_M)
712 dev_dbg(&pf->pdev->dev,
713 "%s Send Queue VF Error detected\n", qtype);
714 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
715 dev_dbg(&pf->pdev->dev,
716 "%s Send Queue Overflow Error detected\n",
719 if (val & PF_FW_ATQLEN_ATQCRIT_M)
720 dev_dbg(&pf->pdev->dev,
721 "%s Send Queue Critical Error detected\n",
723 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
724 PF_FW_ATQLEN_ATQCRIT_M);
726 wr32(hw, cq->sq.len, val);
729 event.buf_len = cq->rq_buf_size;
730 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
739 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
740 if (ret == ICE_ERR_AQ_NO_WORK)
743 dev_err(&pf->pdev->dev,
744 "%s Receive Queue event error %d\n", qtype,
749 opcode = le16_to_cpu(event.desc.opcode);
752 case ice_mbx_opc_send_msg_to_pf:
753 ice_vc_process_vf_msg(pf, &event);
755 case ice_aqc_opc_fw_logging:
756 ice_output_fw_log(hw, &event.desc, event.msg_buf);
759 dev_dbg(&pf->pdev->dev,
760 "%s Receive Queue unknown event 0x%04x ignored\n",
764 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
766 devm_kfree(&pf->pdev->dev, event.msg_buf);
768 return pending && (i == ICE_DFLT_IRQ_WORK);
772 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
773 * @hw: pointer to hardware info
774 * @cq: control queue information
776 * returns true if there are pending messages in a queue, false if there aren't
778 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
782 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
783 return cq->rq.next_to_clean != ntu;
787 * ice_clean_adminq_subtask - clean the AdminQ rings
788 * @pf: board private structure
790 static void ice_clean_adminq_subtask(struct ice_pf *pf)
792 struct ice_hw *hw = &pf->hw;
794 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
797 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
800 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
802 /* There might be a situation where new messages arrive to a control
803 * queue between processing the last message and clearing the
804 * EVENT_PENDING bit. So before exiting, check queue head again (using
805 * ice_ctrlq_pending) and process new messages if any.
807 if (ice_ctrlq_pending(hw, &hw->adminq))
808 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
814 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
815 * @pf: board private structure
817 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
819 struct ice_hw *hw = &pf->hw;
821 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
824 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
827 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
829 if (ice_ctrlq_pending(hw, &hw->mailboxq))
830 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
836 * ice_service_task_schedule - schedule the service task to wake up
837 * @pf: board private structure
839 * If not already scheduled, this puts the task into the work queue.
841 static void ice_service_task_schedule(struct ice_pf *pf)
843 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
844 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
845 !test_bit(__ICE_NEEDS_RESTART, pf->state))
846 queue_work(ice_wq, &pf->serv_task);
850 * ice_service_task_complete - finish up the service task
851 * @pf: board private structure
853 static void ice_service_task_complete(struct ice_pf *pf)
855 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
857 /* force memory (pf->state) to sync before next service task */
858 smp_mb__before_atomic();
859 clear_bit(__ICE_SERVICE_SCHED, pf->state);
863 * ice_service_task_stop - stop service task and cancel works
864 * @pf: board private structure
866 static void ice_service_task_stop(struct ice_pf *pf)
868 set_bit(__ICE_SERVICE_DIS, pf->state);
870 if (pf->serv_tmr.function)
871 del_timer_sync(&pf->serv_tmr);
872 if (pf->serv_task.func)
873 cancel_work_sync(&pf->serv_task);
875 clear_bit(__ICE_SERVICE_SCHED, pf->state);
879 * ice_service_timer - timer callback to schedule service task
880 * @t: pointer to timer_list
882 static void ice_service_timer(struct timer_list *t)
884 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
886 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
887 ice_service_task_schedule(pf);
891 * ice_handle_mdd_event - handle malicious driver detect event
892 * @pf: pointer to the PF structure
894 * Called from service task. OICR interrupt handler indicates MDD event
896 static void ice_handle_mdd_event(struct ice_pf *pf)
898 struct ice_hw *hw = &pf->hw;
899 bool mdd_detected = false;
903 if (!test_bit(__ICE_MDD_EVENT_PENDING, pf->state))
906 /* find what triggered the MDD event */
907 reg = rd32(hw, GL_MDET_TX_PQM);
908 if (reg & GL_MDET_TX_PQM_VALID_M) {
909 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
910 GL_MDET_TX_PQM_PF_NUM_S;
911 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
912 GL_MDET_TX_PQM_VF_NUM_S;
913 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
914 GL_MDET_TX_PQM_MAL_TYPE_S;
915 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
916 GL_MDET_TX_PQM_QNUM_S);
918 if (netif_msg_tx_err(pf))
919 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
920 event, queue, pf_num, vf_num);
921 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
925 reg = rd32(hw, GL_MDET_TX_TCLAN);
926 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
927 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
928 GL_MDET_TX_TCLAN_PF_NUM_S;
929 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
930 GL_MDET_TX_TCLAN_VF_NUM_S;
931 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
932 GL_MDET_TX_TCLAN_MAL_TYPE_S;
933 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
934 GL_MDET_TX_TCLAN_QNUM_S);
936 if (netif_msg_rx_err(pf))
937 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
938 event, queue, pf_num, vf_num);
939 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
943 reg = rd32(hw, GL_MDET_RX);
944 if (reg & GL_MDET_RX_VALID_M) {
945 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
947 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
949 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
950 GL_MDET_RX_MAL_TYPE_S;
951 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
954 if (netif_msg_rx_err(pf))
955 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
956 event, queue, pf_num, vf_num);
957 wr32(hw, GL_MDET_RX, 0xffffffff);
962 bool pf_mdd_detected = false;
964 reg = rd32(hw, PF_MDET_TX_PQM);
965 if (reg & PF_MDET_TX_PQM_VALID_M) {
966 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
967 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
968 pf_mdd_detected = true;
971 reg = rd32(hw, PF_MDET_TX_TCLAN);
972 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
973 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
974 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
975 pf_mdd_detected = true;
978 reg = rd32(hw, PF_MDET_RX);
979 if (reg & PF_MDET_RX_VALID_M) {
980 wr32(hw, PF_MDET_RX, 0xFFFF);
981 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
982 pf_mdd_detected = true;
984 /* Queue belongs to the PF initiate a reset */
985 if (pf_mdd_detected) {
986 set_bit(__ICE_NEEDS_RESTART, pf->state);
987 ice_service_task_schedule(pf);
991 /* see if one of the VFs needs to be reset */
992 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
993 struct ice_vf *vf = &pf->vf[i];
995 reg = rd32(hw, VP_MDET_TX_PQM(i));
996 if (reg & VP_MDET_TX_PQM_VALID_M) {
997 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
998 vf->num_mdd_events++;
999 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1003 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1004 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1005 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1006 vf->num_mdd_events++;
1007 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1011 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1012 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1013 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1014 vf->num_mdd_events++;
1015 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1019 reg = rd32(hw, VP_MDET_RX(i));
1020 if (reg & VP_MDET_RX_VALID_M) {
1021 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1022 vf->num_mdd_events++;
1023 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1027 if (vf->num_mdd_events > ICE_DFLT_NUM_MDD_EVENTS_ALLOWED) {
1028 dev_info(&pf->pdev->dev,
1029 "Too many MDD events on VF %d, disabled\n", i);
1030 dev_info(&pf->pdev->dev,
1031 "Use PF Control I/F to re-enable the VF\n");
1032 set_bit(ICE_VF_STATE_DIS, vf->vf_states);
1036 /* re-enable MDD interrupt cause */
1037 clear_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1038 reg = rd32(hw, PFINT_OICR_ENA);
1039 reg |= PFINT_OICR_MAL_DETECT_M;
1040 wr32(hw, PFINT_OICR_ENA, reg);
1045 * ice_service_task - manage and run subtasks
1046 * @work: pointer to work_struct contained by the PF struct
1048 static void ice_service_task(struct work_struct *work)
1050 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1051 unsigned long start_time = jiffies;
1055 /* process reset requests first */
1056 ice_reset_subtask(pf);
1058 /* bail if a reset/recovery cycle is pending or rebuild failed */
1059 if (ice_is_reset_in_progress(pf->state) ||
1060 test_bit(__ICE_SUSPENDED, pf->state) ||
1061 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1062 ice_service_task_complete(pf);
1066 ice_check_for_hang_subtask(pf);
1067 ice_sync_fltr_subtask(pf);
1068 ice_handle_mdd_event(pf);
1069 ice_process_vflr_event(pf);
1070 ice_watchdog_subtask(pf);
1071 ice_clean_adminq_subtask(pf);
1072 ice_clean_mailboxq_subtask(pf);
1074 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1075 ice_service_task_complete(pf);
1077 /* If the tasks have taken longer than one service timer period
1078 * or there is more work to be done, reset the service timer to
1079 * schedule the service task now.
1081 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1082 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1083 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1084 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1085 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1086 mod_timer(&pf->serv_tmr, jiffies);
1090 * ice_set_ctrlq_len - helper function to set controlq length
1091 * @hw: pointer to the hw instance
1093 static void ice_set_ctrlq_len(struct ice_hw *hw)
1095 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1096 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1097 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1098 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1099 hw->mailboxq.num_rq_entries = ICE_MBXQ_LEN;
1100 hw->mailboxq.num_sq_entries = ICE_MBXQ_LEN;
1101 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1102 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1106 * ice_irq_affinity_notify - Callback for affinity changes
1107 * @notify: context as to what irq was changed
1108 * @mask: the new affinity mask
1110 * This is a callback function used by the irq_set_affinity_notifier function
1111 * so that we may register to receive changes to the irq affinity masks.
1113 static void ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1114 const cpumask_t *mask)
1116 struct ice_q_vector *q_vector =
1117 container_of(notify, struct ice_q_vector, affinity_notify);
1119 cpumask_copy(&q_vector->affinity_mask, mask);
1123 * ice_irq_affinity_release - Callback for affinity notifier release
1124 * @ref: internal core kernel usage
1126 * This is a callback function used by the irq_set_affinity_notifier function
1127 * to inform the current notification subscriber that they will no longer
1128 * receive notifications.
1130 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1133 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1134 * @vsi: the VSI being configured
1136 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1138 struct ice_pf *pf = vsi->back;
1139 struct ice_hw *hw = &pf->hw;
1141 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1144 for (i = 0; i < vsi->num_q_vectors; i++)
1145 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1153 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1154 * @vsi: the VSI being configured
1155 * @basename: name for the vector
1157 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1159 int q_vectors = vsi->num_q_vectors;
1160 struct ice_pf *pf = vsi->back;
1161 int base = vsi->sw_base_vector;
1167 for (vector = 0; vector < q_vectors; vector++) {
1168 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1170 irq_num = pf->msix_entries[base + vector].vector;
1172 if (q_vector->tx.ring && q_vector->rx.ring) {
1173 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1174 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1176 } else if (q_vector->rx.ring) {
1177 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1178 "%s-%s-%d", basename, "rx", rx_int_idx++);
1179 } else if (q_vector->tx.ring) {
1180 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1181 "%s-%s-%d", basename, "tx", tx_int_idx++);
1183 /* skip this unused q_vector */
1186 err = devm_request_irq(&pf->pdev->dev,
1187 pf->msix_entries[base + vector].vector,
1188 vsi->irq_handler, 0, q_vector->name,
1191 netdev_err(vsi->netdev,
1192 "MSIX request_irq failed, error: %d\n", err);
1196 /* register for affinity change notifications */
1197 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1198 q_vector->affinity_notify.release = ice_irq_affinity_release;
1199 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1201 /* assign the mask for this irq */
1202 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1205 vsi->irqs_ready = true;
1211 irq_num = pf->msix_entries[base + vector].vector,
1212 irq_set_affinity_notifier(irq_num, NULL);
1213 irq_set_affinity_hint(irq_num, NULL);
1214 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1220 * ice_ena_misc_vector - enable the non-queue interrupts
1221 * @pf: board private structure
1223 static void ice_ena_misc_vector(struct ice_pf *pf)
1225 struct ice_hw *hw = &pf->hw;
1228 /* clear things first */
1229 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1230 rd32(hw, PFINT_OICR); /* read to clear */
1232 val = (PFINT_OICR_ECC_ERR_M |
1233 PFINT_OICR_MAL_DETECT_M |
1235 PFINT_OICR_PCI_EXCEPTION_M |
1237 PFINT_OICR_HMC_ERR_M |
1238 PFINT_OICR_PE_CRITERR_M);
1240 wr32(hw, PFINT_OICR_ENA, val);
1242 /* SW_ITR_IDX = 0, but don't change INTENA */
1243 wr32(hw, GLINT_DYN_CTL(pf->hw_oicr_idx),
1244 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1248 * ice_misc_intr - misc interrupt handler
1249 * @irq: interrupt number
1250 * @data: pointer to a q_vector
1252 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1254 struct ice_pf *pf = (struct ice_pf *)data;
1255 struct ice_hw *hw = &pf->hw;
1256 irqreturn_t ret = IRQ_NONE;
1259 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1260 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1262 oicr = rd32(hw, PFINT_OICR);
1263 ena_mask = rd32(hw, PFINT_OICR_ENA);
1265 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1266 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1267 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1269 if (oicr & PFINT_OICR_VFLR_M) {
1270 ena_mask &= ~PFINT_OICR_VFLR_M;
1271 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1274 if (oicr & PFINT_OICR_GRST_M) {
1277 /* we have a reset warning */
1278 ena_mask &= ~PFINT_OICR_GRST_M;
1279 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1280 GLGEN_RSTAT_RESET_TYPE_S;
1282 if (reset == ICE_RESET_CORER)
1284 else if (reset == ICE_RESET_GLOBR)
1286 else if (reset == ICE_RESET_EMPR)
1289 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1292 /* If a reset cycle isn't already in progress, we set a bit in
1293 * pf->state so that the service task can start a reset/rebuild.
1294 * We also make note of which reset happened so that peer
1295 * devices/drivers can be informed.
1297 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1298 if (reset == ICE_RESET_CORER)
1299 set_bit(__ICE_CORER_RECV, pf->state);
1300 else if (reset == ICE_RESET_GLOBR)
1301 set_bit(__ICE_GLOBR_RECV, pf->state);
1303 set_bit(__ICE_EMPR_RECV, pf->state);
1305 /* There are couple of different bits at play here.
1306 * hw->reset_ongoing indicates whether the hardware is
1307 * in reset. This is set to true when a reset interrupt
1308 * is received and set back to false after the driver
1309 * has determined that the hardware is out of reset.
1311 * __ICE_RESET_OICR_RECV in pf->state indicates
1312 * that a post reset rebuild is required before the
1313 * driver is operational again. This is set above.
1315 * As this is the start of the reset/rebuild cycle, set
1316 * both to indicate that.
1318 hw->reset_ongoing = true;
1322 if (oicr & PFINT_OICR_HMC_ERR_M) {
1323 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1324 dev_dbg(&pf->pdev->dev,
1325 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1326 rd32(hw, PFHMC_ERRORINFO),
1327 rd32(hw, PFHMC_ERRORDATA));
1330 /* Report and mask off any remaining unexpected interrupts */
1333 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1335 /* If a critical error is pending there is no choice but to
1338 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1339 PFINT_OICR_PCI_EXCEPTION_M |
1340 PFINT_OICR_ECC_ERR_M)) {
1341 set_bit(__ICE_PFR_REQ, pf->state);
1342 ice_service_task_schedule(pf);
1348 /* re-enable interrupt causes that are not handled during this pass */
1349 wr32(hw, PFINT_OICR_ENA, ena_mask);
1350 if (!test_bit(__ICE_DOWN, pf->state)) {
1351 ice_service_task_schedule(pf);
1352 ice_irq_dynamic_ena(hw, NULL, NULL);
1359 * ice_free_irq_msix_misc - Unroll misc vector setup
1360 * @pf: board private structure
1362 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1364 /* disable OICR interrupt */
1365 wr32(&pf->hw, PFINT_OICR_ENA, 0);
1368 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
1369 synchronize_irq(pf->msix_entries[pf->sw_oicr_idx].vector);
1370 devm_free_irq(&pf->pdev->dev,
1371 pf->msix_entries[pf->sw_oicr_idx].vector, pf);
1374 pf->num_avail_sw_msix += 1;
1375 ice_free_res(pf->sw_irq_tracker, pf->sw_oicr_idx, ICE_RES_MISC_VEC_ID);
1376 pf->num_avail_hw_msix += 1;
1377 ice_free_res(pf->hw_irq_tracker, pf->hw_oicr_idx, ICE_RES_MISC_VEC_ID);
1381 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1382 * @pf: board private structure
1384 * This sets up the handler for MSIX 0, which is used to manage the
1385 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1386 * when in MSI or Legacy interrupt mode.
1388 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1390 struct ice_hw *hw = &pf->hw;
1391 int oicr_idx, err = 0;
1395 if (!pf->int_name[0])
1396 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1397 dev_driver_string(&pf->pdev->dev),
1398 dev_name(&pf->pdev->dev));
1400 /* Do not request IRQ but do enable OICR interrupt since settings are
1401 * lost during reset. Note that this function is called only during
1402 * rebuild path and not while reset is in progress.
1404 if (ice_is_reset_in_progress(pf->state))
1407 /* reserve one vector in sw_irq_tracker for misc interrupts */
1408 oicr_idx = ice_get_res(pf, pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1412 pf->num_avail_sw_msix -= 1;
1413 pf->sw_oicr_idx = oicr_idx;
1415 /* reserve one vector in hw_irq_tracker for misc interrupts */
1416 oicr_idx = ice_get_res(pf, pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1418 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1419 pf->num_avail_sw_msix += 1;
1422 pf->num_avail_hw_msix -= 1;
1423 pf->hw_oicr_idx = oicr_idx;
1425 err = devm_request_irq(&pf->pdev->dev,
1426 pf->msix_entries[pf->sw_oicr_idx].vector,
1427 ice_misc_intr, 0, pf->int_name, pf);
1429 dev_err(&pf->pdev->dev,
1430 "devm_request_irq for %s failed: %d\n",
1432 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1433 pf->num_avail_sw_msix += 1;
1434 ice_free_res(pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1435 pf->num_avail_hw_msix += 1;
1440 ice_ena_misc_vector(pf);
1442 val = ((pf->hw_oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1443 PFINT_OICR_CTL_CAUSE_ENA_M);
1444 wr32(hw, PFINT_OICR_CTL, val);
1446 /* This enables Admin queue Interrupt causes */
1447 val = ((pf->hw_oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1448 PFINT_FW_CTL_CAUSE_ENA_M);
1449 wr32(hw, PFINT_FW_CTL, val);
1451 /* This enables Mailbox queue Interrupt causes */
1452 val = ((pf->hw_oicr_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1453 PFINT_MBX_CTL_CAUSE_ENA_M);
1454 wr32(hw, PFINT_MBX_CTL, val);
1456 itr_gran = hw->itr_gran;
1458 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->hw_oicr_idx),
1459 ITR_TO_REG(ICE_ITR_8K, itr_gran));
1462 ice_irq_dynamic_ena(hw, NULL, NULL);
1468 * ice_napi_del - Remove NAPI handler for the VSI
1469 * @vsi: VSI for which NAPI handler is to be removed
1471 void ice_napi_del(struct ice_vsi *vsi)
1478 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1479 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
1483 * ice_napi_add - register NAPI handler for the VSI
1484 * @vsi: VSI for which NAPI handler is to be registered
1486 * This function is only called in the driver's load path. Registering the NAPI
1487 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1488 * reset/rebuild, etc.)
1490 static void ice_napi_add(struct ice_vsi *vsi)
1497 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1498 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1499 ice_napi_poll, NAPI_POLL_WEIGHT);
1503 * ice_cfg_netdev - Allocate, configure and register a netdev
1504 * @vsi: the VSI associated with the new netdev
1506 * Returns 0 on success, negative value on failure
1508 static int ice_cfg_netdev(struct ice_vsi *vsi)
1510 netdev_features_t csumo_features;
1511 netdev_features_t vlano_features;
1512 netdev_features_t dflt_features;
1513 netdev_features_t tso_features;
1514 struct ice_netdev_priv *np;
1515 struct net_device *netdev;
1516 u8 mac_addr[ETH_ALEN];
1519 netdev = alloc_etherdev_mqs(sizeof(struct ice_netdev_priv),
1520 vsi->alloc_txq, vsi->alloc_rxq);
1524 vsi->netdev = netdev;
1525 np = netdev_priv(netdev);
1528 dflt_features = NETIF_F_SG |
1532 csumo_features = NETIF_F_RXCSUM |
1536 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1537 NETIF_F_HW_VLAN_CTAG_TX |
1538 NETIF_F_HW_VLAN_CTAG_RX;
1540 tso_features = NETIF_F_TSO;
1542 /* set features that user can change */
1543 netdev->hw_features = dflt_features | csumo_features |
1544 vlano_features | tso_features;
1546 /* enable features */
1547 netdev->features |= netdev->hw_features;
1548 /* encap and VLAN devices inherit default, csumo and tso features */
1549 netdev->hw_enc_features |= dflt_features | csumo_features |
1551 netdev->vlan_features |= dflt_features | csumo_features |
1554 if (vsi->type == ICE_VSI_PF) {
1555 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1556 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1558 ether_addr_copy(netdev->dev_addr, mac_addr);
1559 ether_addr_copy(netdev->perm_addr, mac_addr);
1562 netdev->priv_flags |= IFF_UNICAST_FLT;
1564 /* assign netdev_ops */
1565 netdev->netdev_ops = &ice_netdev_ops;
1567 /* setup watchdog timeout value to be 5 second */
1568 netdev->watchdog_timeo = 5 * HZ;
1570 ice_set_ethtool_ops(netdev);
1572 netdev->min_mtu = ETH_MIN_MTU;
1573 netdev->max_mtu = ICE_MAX_MTU;
1575 err = register_netdev(vsi->netdev);
1579 netif_carrier_off(vsi->netdev);
1581 /* make sure transmit queues start off as stopped */
1582 netif_tx_stop_all_queues(vsi->netdev);
1588 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1589 * @lut: Lookup table
1590 * @rss_table_size: Lookup table size
1591 * @rss_size: Range of queue number for hashing
1593 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1597 for (i = 0; i < rss_table_size; i++)
1598 lut[i] = i % rss_size;
1602 * ice_pf_vsi_setup - Set up a PF VSI
1603 * @pf: board private structure
1604 * @pi: pointer to the port_info instance
1606 * Returns pointer to the successfully allocated VSI sw struct on success,
1607 * otherwise returns NULL on failure.
1609 static struct ice_vsi *
1610 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1612 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
1616 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload
1617 * @netdev: network interface to be adjusted
1618 * @proto: unused protocol
1619 * @vid: vlan id to be added
1621 * net_device_ops implementation for adding vlan ids
1623 static int ice_vlan_rx_add_vid(struct net_device *netdev,
1624 __always_unused __be16 proto, u16 vid)
1626 struct ice_netdev_priv *np = netdev_priv(netdev);
1627 struct ice_vsi *vsi = np->vsi;
1629 if (vid >= VLAN_N_VID) {
1630 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
1638 /* Enable VLAN pruning when VLAN 0 is added */
1639 if (unlikely(!vid)) {
1640 int ret = ice_cfg_vlan_pruning(vsi, true);
1646 /* Add all VLAN ids including 0 to the switch filter. VLAN id 0 is
1647 * needed to continue allowing all untagged packets since VLAN prune
1648 * list is applied to all packets by the switch
1650 return ice_vsi_add_vlan(vsi, vid);
1654 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
1655 * @netdev: network interface to be adjusted
1656 * @proto: unused protocol
1657 * @vid: vlan id to be removed
1659 * net_device_ops implementation for removing vlan ids
1661 static int ice_vlan_rx_kill_vid(struct net_device *netdev,
1662 __always_unused __be16 proto, u16 vid)
1664 struct ice_netdev_priv *np = netdev_priv(netdev);
1665 struct ice_vsi *vsi = np->vsi;
1671 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
1674 status = ice_vsi_kill_vlan(vsi, vid);
1678 /* Disable VLAN pruning when VLAN 0 is removed */
1680 status = ice_cfg_vlan_pruning(vsi, false);
1686 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
1687 * @pf: board private structure
1689 * Returns 0 on success, negative value on failure
1691 static int ice_setup_pf_sw(struct ice_pf *pf)
1693 LIST_HEAD(tmp_add_list);
1694 u8 broadcast[ETH_ALEN];
1695 struct ice_vsi *vsi;
1698 if (ice_is_reset_in_progress(pf->state))
1701 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
1704 goto unroll_vsi_setup;
1707 status = ice_cfg_netdev(vsi);
1710 goto unroll_vsi_setup;
1713 /* registering the NAPI handler requires both the queues and
1714 * netdev to be created, which are done in ice_pf_vsi_setup()
1715 * and ice_cfg_netdev() respectively
1719 /* To add a MAC filter, first add the MAC to a list and then
1720 * pass the list to ice_add_mac.
1723 /* Add a unicast MAC filter so the VSI can get its packets */
1724 status = ice_add_mac_to_list(vsi, &tmp_add_list,
1725 vsi->port_info->mac.perm_addr);
1727 goto unroll_napi_add;
1729 /* VSI needs to receive broadcast traffic, so add the broadcast
1730 * MAC address to the list as well.
1732 eth_broadcast_addr(broadcast);
1733 status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
1737 /* program MAC filters for entries in tmp_add_list */
1738 status = ice_add_mac(&pf->hw, &tmp_add_list);
1740 dev_err(&pf->pdev->dev, "Could not add MAC filters\n");
1745 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1749 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1755 if (vsi->netdev->reg_state == NETREG_REGISTERED)
1756 unregister_netdev(vsi->netdev);
1757 free_netdev(vsi->netdev);
1764 ice_vsi_free_q_vectors(vsi);
1765 ice_vsi_delete(vsi);
1766 ice_vsi_put_qs(vsi);
1767 pf->q_left_tx += vsi->alloc_txq;
1768 pf->q_left_rx += vsi->alloc_rxq;
1775 * ice_determine_q_usage - Calculate queue distribution
1776 * @pf: board private structure
1778 * Return -ENOMEM if we don't get enough queues for all ports
1780 static void ice_determine_q_usage(struct ice_pf *pf)
1782 u16 q_left_tx, q_left_rx;
1784 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
1785 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
1787 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
1789 /* only 1 Rx queue unless RSS is enabled */
1790 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1793 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
1795 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
1796 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
1800 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
1801 * @pf: board private structure to initialize
1803 static void ice_deinit_pf(struct ice_pf *pf)
1805 ice_service_task_stop(pf);
1806 mutex_destroy(&pf->sw_mutex);
1807 mutex_destroy(&pf->avail_q_mutex);
1811 * ice_init_pf - Initialize general software structures (struct ice_pf)
1812 * @pf: board private structure to initialize
1814 static void ice_init_pf(struct ice_pf *pf)
1816 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
1817 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1818 #ifdef CONFIG_PCI_IOV
1819 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
1820 struct ice_hw *hw = &pf->hw;
1822 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
1823 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
1826 #endif /* CONFIG_PCI_IOV */
1828 mutex_init(&pf->sw_mutex);
1829 mutex_init(&pf->avail_q_mutex);
1831 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
1832 mutex_lock(&pf->avail_q_mutex);
1833 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
1834 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
1835 mutex_unlock(&pf->avail_q_mutex);
1837 if (pf->hw.func_caps.common_cap.rss_table_size)
1838 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
1840 /* setup service timer and periodic service task */
1841 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
1842 pf->serv_tmr_period = HZ;
1843 INIT_WORK(&pf->serv_task, ice_service_task);
1844 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1848 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
1849 * @pf: board private structure
1851 * compute the number of MSIX vectors required (v_budget) and request from
1852 * the OS. Return the number of vectors reserved or negative on failure
1854 static int ice_ena_msix_range(struct ice_pf *pf)
1856 int v_left, v_actual, v_budget = 0;
1859 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
1861 /* reserve one vector for miscellaneous handler */
1866 /* reserve vectors for LAN traffic */
1867 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
1868 v_budget += pf->num_lan_msix;
1869 v_left -= pf->num_lan_msix;
1871 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
1872 sizeof(struct msix_entry), GFP_KERNEL);
1874 if (!pf->msix_entries) {
1879 for (i = 0; i < v_budget; i++)
1880 pf->msix_entries[i].entry = i;
1882 /* actually reserve the vectors */
1883 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
1884 ICE_MIN_MSIX, v_budget);
1887 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
1892 if (v_actual < v_budget) {
1893 dev_warn(&pf->pdev->dev,
1894 "not enough vectors. requested = %d, obtained = %d\n",
1895 v_budget, v_actual);
1896 if (v_actual >= (pf->num_lan_msix + 1)) {
1897 pf->num_avail_sw_msix = v_actual -
1898 (pf->num_lan_msix + 1);
1899 } else if (v_actual >= 2) {
1900 pf->num_lan_msix = 1;
1901 pf->num_avail_sw_msix = v_actual - 2;
1903 pci_disable_msix(pf->pdev);
1912 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1916 pf->num_lan_msix = 0;
1917 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1922 * ice_dis_msix - Disable MSI-X interrupt setup in OS
1923 * @pf: board private structure
1925 static void ice_dis_msix(struct ice_pf *pf)
1927 pci_disable_msix(pf->pdev);
1928 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1929 pf->msix_entries = NULL;
1930 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1934 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
1935 * @pf: board private structure
1937 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
1939 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1942 if (pf->sw_irq_tracker) {
1943 devm_kfree(&pf->pdev->dev, pf->sw_irq_tracker);
1944 pf->sw_irq_tracker = NULL;
1947 if (pf->hw_irq_tracker) {
1948 devm_kfree(&pf->pdev->dev, pf->hw_irq_tracker);
1949 pf->hw_irq_tracker = NULL;
1954 * ice_init_interrupt_scheme - Determine proper interrupt scheme
1955 * @pf: board private structure to initialize
1957 static int ice_init_interrupt_scheme(struct ice_pf *pf)
1959 int vectors = 0, hw_vectors = 0;
1962 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1963 vectors = ice_ena_msix_range(pf);
1970 /* set up vector assignment tracking */
1971 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * vectors);
1973 pf->sw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1974 if (!pf->sw_irq_tracker) {
1979 /* populate SW interrupts pool with number of OS granted IRQs. */
1980 pf->num_avail_sw_msix = vectors;
1981 pf->sw_irq_tracker->num_entries = vectors;
1983 /* set up HW vector assignment tracking */
1984 hw_vectors = pf->hw.func_caps.common_cap.num_msix_vectors;
1985 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * hw_vectors);
1987 pf->hw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1988 if (!pf->hw_irq_tracker) {
1989 ice_clear_interrupt_scheme(pf);
1993 /* populate HW interrupts pool with number of HW supported irqs. */
1994 pf->num_avail_hw_msix = hw_vectors;
1995 pf->hw_irq_tracker->num_entries = hw_vectors;
2001 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
2002 * @pf: pointer to the PF structure
2004 * There is no error returned here because the driver should be able to handle
2005 * 128 Byte cache lines, so we only print a warning in case issues are seen,
2006 * specifically with Tx.
2008 static void ice_verify_cacheline_size(struct ice_pf *pf)
2010 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
2011 dev_warn(&pf->pdev->dev,
2012 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
2013 ICE_CACHE_LINE_BYTES);
2017 * ice_probe - Device initialization routine
2018 * @pdev: PCI device information struct
2019 * @ent: entry in ice_pci_tbl
2021 * Returns 0 on success, negative on failure
2023 static int ice_probe(struct pci_dev *pdev,
2024 const struct pci_device_id __always_unused *ent)
2030 /* this driver uses devres, see Documentation/driver-model/devres.txt */
2031 err = pcim_enable_device(pdev);
2035 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2037 dev_err(&pdev->dev, "BAR0 I/O map error %d\n", err);
2041 pf = devm_kzalloc(&pdev->dev, sizeof(*pf), GFP_KERNEL);
2045 /* set up for high or low dma */
2046 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2048 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2050 dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
2054 pci_enable_pcie_error_reporting(pdev);
2055 pci_set_master(pdev);
2058 pci_set_drvdata(pdev, pf);
2059 set_bit(__ICE_DOWN, pf->state);
2060 /* Disable service task until DOWN bit is cleared */
2061 set_bit(__ICE_SERVICE_DIS, pf->state);
2064 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2066 hw->vendor_id = pdev->vendor;
2067 hw->device_id = pdev->device;
2068 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2069 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2070 hw->subsystem_device_id = pdev->subsystem_device;
2071 hw->bus.device = PCI_SLOT(pdev->devfn);
2072 hw->bus.func = PCI_FUNC(pdev->devfn);
2073 ice_set_ctrlq_len(hw);
2075 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2077 #ifndef CONFIG_DYNAMIC_DEBUG
2079 hw->debug_mask = debug;
2082 err = ice_init_hw(hw);
2084 dev_err(&pdev->dev, "ice_init_hw failed: %d\n", err);
2086 goto err_exit_unroll;
2089 dev_info(&pdev->dev, "firmware %d.%d.%05d api %d.%d\n",
2090 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2091 hw->api_maj_ver, hw->api_min_ver);
2095 ice_determine_q_usage(pf);
2097 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
2098 if (!pf->num_alloc_vsi) {
2100 goto err_init_pf_unroll;
2103 pf->vsi = devm_kcalloc(&pdev->dev, pf->num_alloc_vsi,
2104 sizeof(struct ice_vsi *), GFP_KERNEL);
2107 goto err_init_pf_unroll;
2110 err = ice_init_interrupt_scheme(pf);
2113 "ice_init_interrupt_scheme failed: %d\n", err);
2115 goto err_init_interrupt_unroll;
2118 /* Driver is mostly up */
2119 clear_bit(__ICE_DOWN, pf->state);
2121 /* In case of MSIX we are going to setup the misc vector right here
2122 * to handle admin queue events etc. In case of legacy and MSI
2123 * the misc functionality and queue processing is combined in
2124 * the same vector and that gets setup at open.
2126 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2127 err = ice_req_irq_msix_misc(pf);
2130 "setup of misc vector failed: %d\n", err);
2131 goto err_init_interrupt_unroll;
2135 /* create switch struct for the switch element created by FW on boot */
2136 pf->first_sw = devm_kzalloc(&pdev->dev, sizeof(struct ice_sw),
2138 if (!pf->first_sw) {
2140 goto err_msix_misc_unroll;
2144 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2146 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2148 pf->first_sw->pf = pf;
2150 /* record the sw_id available for later use */
2151 pf->first_sw->sw_id = hw->port_info->sw_id;
2153 err = ice_setup_pf_sw(pf);
2156 "probe failed due to setup pf switch:%d\n", err);
2157 goto err_alloc_sw_unroll;
2160 clear_bit(__ICE_SERVICE_DIS, pf->state);
2162 /* since everything is good, start the service timer */
2163 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2165 ice_verify_cacheline_size(pf);
2169 err_alloc_sw_unroll:
2170 set_bit(__ICE_SERVICE_DIS, pf->state);
2171 set_bit(__ICE_DOWN, pf->state);
2172 devm_kfree(&pf->pdev->dev, pf->first_sw);
2173 err_msix_misc_unroll:
2174 ice_free_irq_msix_misc(pf);
2175 err_init_interrupt_unroll:
2176 ice_clear_interrupt_scheme(pf);
2177 devm_kfree(&pdev->dev, pf->vsi);
2182 pci_disable_pcie_error_reporting(pdev);
2187 * ice_remove - Device removal routine
2188 * @pdev: PCI device information struct
2190 static void ice_remove(struct pci_dev *pdev)
2192 struct ice_pf *pf = pci_get_drvdata(pdev);
2198 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
2199 if (!ice_is_reset_in_progress(pf->state))
2204 set_bit(__ICE_DOWN, pf->state);
2205 ice_service_task_stop(pf);
2207 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2209 ice_vsi_release_all(pf);
2210 ice_free_irq_msix_misc(pf);
2211 ice_for_each_vsi(pf, i) {
2214 ice_vsi_free_q_vectors(pf->vsi[i]);
2216 ice_clear_interrupt_scheme(pf);
2218 ice_deinit_hw(&pf->hw);
2219 pci_disable_pcie_error_reporting(pdev);
2222 /* ice_pci_tbl - PCI Device ID Table
2224 * Wildcard entries (PCI_ANY_ID) should come last
2225 * Last entry must be all 0s
2227 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2228 * Class, Class Mask, private data (not used) }
2230 static const struct pci_device_id ice_pci_tbl[] = {
2231 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
2232 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
2233 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
2234 /* required last entry */
2237 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2239 static struct pci_driver ice_driver = {
2240 .name = KBUILD_MODNAME,
2241 .id_table = ice_pci_tbl,
2243 .remove = ice_remove,
2244 .sriov_configure = ice_sriov_configure,
2248 * ice_module_init - Driver registration routine
2250 * ice_module_init is the first routine called when the driver is
2251 * loaded. All it does is register with the PCI subsystem.
2253 static int __init ice_module_init(void)
2257 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2258 pr_info("%s\n", ice_copyright);
2260 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2262 pr_err("Failed to create workqueue\n");
2266 status = pci_register_driver(&ice_driver);
2268 pr_err("failed to register pci driver, err %d\n", status);
2269 destroy_workqueue(ice_wq);
2274 module_init(ice_module_init);
2277 * ice_module_exit - Driver exit cleanup routine
2279 * ice_module_exit is called just before the driver is removed
2282 static void __exit ice_module_exit(void)
2284 pci_unregister_driver(&ice_driver);
2285 destroy_workqueue(ice_wq);
2286 pr_info("module unloaded\n");
2288 module_exit(ice_module_exit);
2291 * ice_set_mac_address - NDO callback to set mac address
2292 * @netdev: network interface device structure
2293 * @pi: pointer to an address structure
2295 * Returns 0 on success, negative on failure
2297 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2299 struct ice_netdev_priv *np = netdev_priv(netdev);
2300 struct ice_vsi *vsi = np->vsi;
2301 struct ice_pf *pf = vsi->back;
2302 struct ice_hw *hw = &pf->hw;
2303 struct sockaddr *addr = pi;
2304 enum ice_status status;
2305 LIST_HEAD(a_mac_list);
2306 LIST_HEAD(r_mac_list);
2311 mac = (u8 *)addr->sa_data;
2313 if (!is_valid_ether_addr(mac))
2314 return -EADDRNOTAVAIL;
2316 if (ether_addr_equal(netdev->dev_addr, mac)) {
2317 netdev_warn(netdev, "already using mac %pM\n", mac);
2321 if (test_bit(__ICE_DOWN, pf->state) ||
2322 ice_is_reset_in_progress(pf->state)) {
2323 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2328 /* When we change the mac address we also have to change the mac address
2329 * based filter rules that were created previously for the old mac
2330 * address. So first, we remove the old filter rule using ice_remove_mac
2331 * and then create a new filter rule using ice_add_mac. Note that for
2332 * both these operations, we first need to form a "list" of mac
2333 * addresses (even though in this case, we have only 1 mac address to be
2334 * added/removed) and this done using ice_add_mac_to_list. Depending on
2335 * the ensuing operation this "list" of mac addresses is either to be
2336 * added or removed from the filter.
2338 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
2340 err = -EADDRNOTAVAIL;
2344 status = ice_remove_mac(hw, &r_mac_list);
2346 err = -EADDRNOTAVAIL;
2350 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
2352 err = -EADDRNOTAVAIL;
2356 status = ice_add_mac(hw, &a_mac_list);
2358 err = -EADDRNOTAVAIL;
2363 /* free list entries */
2364 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
2365 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
2368 netdev_err(netdev, "can't set mac %pM. filter update failed\n",
2373 /* change the netdev's mac address */
2374 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2375 netdev_dbg(vsi->netdev, "updated mac address to %pM\n",
2378 /* write new mac address to the firmware */
2379 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2380 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2382 netdev_err(netdev, "can't set mac %pM. write to firmware failed.\n",
2389 * ice_set_rx_mode - NDO callback to set the netdev filters
2390 * @netdev: network interface device structure
2392 static void ice_set_rx_mode(struct net_device *netdev)
2394 struct ice_netdev_priv *np = netdev_priv(netdev);
2395 struct ice_vsi *vsi = np->vsi;
2400 /* Set the flags to synchronize filters
2401 * ndo_set_rx_mode may be triggered even without a change in netdev
2404 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2405 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2406 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2408 /* schedule our worker thread which will take care of
2409 * applying the new filter changes
2411 ice_service_task_schedule(vsi->back);
2415 * ice_fdb_add - add an entry to the hardware database
2416 * @ndm: the input from the stack
2417 * @tb: pointer to array of nladdr (unused)
2418 * @dev: the net device pointer
2419 * @addr: the MAC address entry being added
2421 * @flags: instructions from stack about fdb operation
2423 static int ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2424 struct net_device *dev, const unsigned char *addr,
2430 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2433 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2434 netdev_err(dev, "FDB only supports static addresses\n");
2438 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2439 err = dev_uc_add_excl(dev, addr);
2440 else if (is_multicast_ether_addr(addr))
2441 err = dev_mc_add_excl(dev, addr);
2445 /* Only return duplicate errors if NLM_F_EXCL is set */
2446 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2453 * ice_fdb_del - delete an entry from the hardware database
2454 * @ndm: the input from the stack
2455 * @tb: pointer to array of nladdr (unused)
2456 * @dev: the net device pointer
2457 * @addr: the MAC address entry being added
2460 static int ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2461 struct net_device *dev, const unsigned char *addr,
2462 __always_unused u16 vid)
2466 if (ndm->ndm_state & NUD_PERMANENT) {
2467 netdev_err(dev, "FDB only supports static addresses\n");
2471 if (is_unicast_ether_addr(addr))
2472 err = dev_uc_del(dev, addr);
2473 else if (is_multicast_ether_addr(addr))
2474 err = dev_mc_del(dev, addr);
2482 * ice_set_features - set the netdev feature flags
2483 * @netdev: ptr to the netdev being adjusted
2484 * @features: the feature set that the stack is suggesting
2486 static int ice_set_features(struct net_device *netdev,
2487 netdev_features_t features)
2489 struct ice_netdev_priv *np = netdev_priv(netdev);
2490 struct ice_vsi *vsi = np->vsi;
2493 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
2494 ret = ice_vsi_manage_rss_lut(vsi, true);
2495 else if (!(features & NETIF_F_RXHASH) &&
2496 netdev->features & NETIF_F_RXHASH)
2497 ret = ice_vsi_manage_rss_lut(vsi, false);
2499 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
2500 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2501 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2502 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
2503 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2504 ret = ice_vsi_manage_vlan_stripping(vsi, false);
2505 else if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
2506 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2507 ret = ice_vsi_manage_vlan_insertion(vsi);
2508 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
2509 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2510 ret = ice_vsi_manage_vlan_insertion(vsi);
2516 * ice_vsi_vlan_setup - Setup vlan offload properties on a VSI
2517 * @vsi: VSI to setup vlan properties for
2519 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
2523 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2524 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2525 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
2526 ret = ice_vsi_manage_vlan_insertion(vsi);
2532 * ice_vsi_cfg - Setup the VSI
2533 * @vsi: the VSI being configured
2535 * Return 0 on success and negative value on error
2537 static int ice_vsi_cfg(struct ice_vsi *vsi)
2542 ice_set_rx_mode(vsi->netdev);
2544 err = ice_vsi_vlan_setup(vsi);
2549 err = ice_vsi_cfg_txqs(vsi);
2551 err = ice_vsi_cfg_rxqs(vsi);
2557 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
2558 * @vsi: the VSI being configured
2560 static void ice_napi_enable_all(struct ice_vsi *vsi)
2567 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
2568 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
2570 if (q_vector->rx.ring || q_vector->tx.ring)
2571 napi_enable(&q_vector->napi);
2576 * ice_up_complete - Finish the last steps of bringing up a connection
2577 * @vsi: The VSI being configured
2579 * Return 0 on success and negative value on error
2581 static int ice_up_complete(struct ice_vsi *vsi)
2583 struct ice_pf *pf = vsi->back;
2586 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2587 ice_vsi_cfg_msix(vsi);
2591 /* Enable only Rx rings, Tx rings were enabled by the FW when the
2592 * Tx queue group list was configured and the context bits were
2593 * programmed using ice_vsi_cfg_txqs
2595 err = ice_vsi_start_rx_rings(vsi);
2599 clear_bit(__ICE_DOWN, vsi->state);
2600 ice_napi_enable_all(vsi);
2601 ice_vsi_ena_irq(vsi);
2603 if (vsi->port_info &&
2604 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
2606 ice_print_link_msg(vsi, true);
2607 netif_tx_start_all_queues(vsi->netdev);
2608 netif_carrier_on(vsi->netdev);
2611 ice_service_task_schedule(pf);
2617 * ice_up - Bring the connection back up after being down
2618 * @vsi: VSI being configured
2620 int ice_up(struct ice_vsi *vsi)
2624 err = ice_vsi_cfg(vsi);
2626 err = ice_up_complete(vsi);
2632 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
2633 * @ring: Tx or Rx ring to read stats from
2634 * @pkts: packets stats counter
2635 * @bytes: bytes stats counter
2637 * This function fetches stats from the ring considering the atomic operations
2638 * that needs to be performed to read u64 values in 32 bit machine.
2640 static void ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts,
2650 start = u64_stats_fetch_begin_irq(&ring->syncp);
2651 *pkts = ring->stats.pkts;
2652 *bytes = ring->stats.bytes;
2653 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
2657 * ice_update_vsi_ring_stats - Update VSI stats counters
2658 * @vsi: the VSI to be updated
2660 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
2662 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
2663 struct ice_ring *ring;
2667 /* reset netdev stats */
2668 vsi_stats->tx_packets = 0;
2669 vsi_stats->tx_bytes = 0;
2670 vsi_stats->rx_packets = 0;
2671 vsi_stats->rx_bytes = 0;
2673 /* reset non-netdev (extended) stats */
2674 vsi->tx_restart = 0;
2676 vsi->tx_linearize = 0;
2677 vsi->rx_buf_failed = 0;
2678 vsi->rx_page_failed = 0;
2682 /* update Tx rings counters */
2683 ice_for_each_txq(vsi, i) {
2684 ring = READ_ONCE(vsi->tx_rings[i]);
2685 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2686 vsi_stats->tx_packets += pkts;
2687 vsi_stats->tx_bytes += bytes;
2688 vsi->tx_restart += ring->tx_stats.restart_q;
2689 vsi->tx_busy += ring->tx_stats.tx_busy;
2690 vsi->tx_linearize += ring->tx_stats.tx_linearize;
2693 /* update Rx rings counters */
2694 ice_for_each_rxq(vsi, i) {
2695 ring = READ_ONCE(vsi->rx_rings[i]);
2696 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2697 vsi_stats->rx_packets += pkts;
2698 vsi_stats->rx_bytes += bytes;
2699 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
2700 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
2707 * ice_update_vsi_stats - Update VSI stats counters
2708 * @vsi: the VSI to be updated
2710 static void ice_update_vsi_stats(struct ice_vsi *vsi)
2712 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
2713 struct ice_eth_stats *cur_es = &vsi->eth_stats;
2714 struct ice_pf *pf = vsi->back;
2716 if (test_bit(__ICE_DOWN, vsi->state) ||
2717 test_bit(__ICE_CFG_BUSY, pf->state))
2720 /* get stats as recorded by Tx/Rx rings */
2721 ice_update_vsi_ring_stats(vsi);
2723 /* get VSI stats as recorded by the hardware */
2724 ice_update_eth_stats(vsi);
2726 cur_ns->tx_errors = cur_es->tx_errors;
2727 cur_ns->rx_dropped = cur_es->rx_discards;
2728 cur_ns->tx_dropped = cur_es->tx_discards;
2729 cur_ns->multicast = cur_es->rx_multicast;
2731 /* update some more netdev stats if this is main VSI */
2732 if (vsi->type == ICE_VSI_PF) {
2733 cur_ns->rx_crc_errors = pf->stats.crc_errors;
2734 cur_ns->rx_errors = pf->stats.crc_errors +
2735 pf->stats.illegal_bytes;
2736 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
2741 * ice_update_pf_stats - Update PF port stats counters
2742 * @pf: PF whose stats needs to be updated
2744 static void ice_update_pf_stats(struct ice_pf *pf)
2746 struct ice_hw_port_stats *prev_ps, *cur_ps;
2747 struct ice_hw *hw = &pf->hw;
2750 prev_ps = &pf->stats_prev;
2751 cur_ps = &pf->stats;
2754 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
2755 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
2756 &cur_ps->eth.rx_bytes);
2758 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
2759 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
2760 &cur_ps->eth.rx_unicast);
2762 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
2763 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
2764 &cur_ps->eth.rx_multicast);
2766 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
2767 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
2768 &cur_ps->eth.rx_broadcast);
2770 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
2771 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
2772 &cur_ps->eth.tx_bytes);
2774 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
2775 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
2776 &cur_ps->eth.tx_unicast);
2778 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
2779 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
2780 &cur_ps->eth.tx_multicast);
2782 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
2783 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
2784 &cur_ps->eth.tx_broadcast);
2786 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
2787 &prev_ps->tx_dropped_link_down,
2788 &cur_ps->tx_dropped_link_down);
2790 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
2791 pf->stat_prev_loaded, &prev_ps->rx_size_64,
2792 &cur_ps->rx_size_64);
2794 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
2795 pf->stat_prev_loaded, &prev_ps->rx_size_127,
2796 &cur_ps->rx_size_127);
2798 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
2799 pf->stat_prev_loaded, &prev_ps->rx_size_255,
2800 &cur_ps->rx_size_255);
2802 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
2803 pf->stat_prev_loaded, &prev_ps->rx_size_511,
2804 &cur_ps->rx_size_511);
2806 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
2807 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
2808 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
2810 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
2811 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
2812 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
2814 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
2815 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
2816 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
2818 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
2819 pf->stat_prev_loaded, &prev_ps->tx_size_64,
2820 &cur_ps->tx_size_64);
2822 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
2823 pf->stat_prev_loaded, &prev_ps->tx_size_127,
2824 &cur_ps->tx_size_127);
2826 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
2827 pf->stat_prev_loaded, &prev_ps->tx_size_255,
2828 &cur_ps->tx_size_255);
2830 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
2831 pf->stat_prev_loaded, &prev_ps->tx_size_511,
2832 &cur_ps->tx_size_511);
2834 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
2835 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
2836 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
2838 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
2839 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
2840 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
2842 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
2843 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
2844 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
2846 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
2847 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
2849 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
2850 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
2852 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
2853 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
2855 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
2856 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
2858 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
2859 &prev_ps->crc_errors, &cur_ps->crc_errors);
2861 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
2862 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
2864 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
2865 &prev_ps->mac_local_faults,
2866 &cur_ps->mac_local_faults);
2868 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
2869 &prev_ps->mac_remote_faults,
2870 &cur_ps->mac_remote_faults);
2872 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
2873 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
2875 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
2876 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
2878 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
2879 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
2881 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
2882 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
2884 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
2885 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
2887 pf->stat_prev_loaded = true;
2891 * ice_get_stats64 - get statistics for network device structure
2892 * @netdev: network interface device structure
2893 * @stats: main device statistics structure
2896 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
2898 struct ice_netdev_priv *np = netdev_priv(netdev);
2899 struct rtnl_link_stats64 *vsi_stats;
2900 struct ice_vsi *vsi = np->vsi;
2902 vsi_stats = &vsi->net_stats;
2904 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
2906 /* netdev packet/byte stats come from ring counter. These are obtained
2907 * by summing up ring counters (done by ice_update_vsi_ring_stats).
2909 ice_update_vsi_ring_stats(vsi);
2910 stats->tx_packets = vsi_stats->tx_packets;
2911 stats->tx_bytes = vsi_stats->tx_bytes;
2912 stats->rx_packets = vsi_stats->rx_packets;
2913 stats->rx_bytes = vsi_stats->rx_bytes;
2915 /* The rest of the stats can be read from the hardware but instead we
2916 * just return values that the watchdog task has already obtained from
2919 stats->multicast = vsi_stats->multicast;
2920 stats->tx_errors = vsi_stats->tx_errors;
2921 stats->tx_dropped = vsi_stats->tx_dropped;
2922 stats->rx_errors = vsi_stats->rx_errors;
2923 stats->rx_dropped = vsi_stats->rx_dropped;
2924 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
2925 stats->rx_length_errors = vsi_stats->rx_length_errors;
2929 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
2930 * @vsi: VSI having NAPI disabled
2932 static void ice_napi_disable_all(struct ice_vsi *vsi)
2939 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++) {
2940 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
2942 if (q_vector->rx.ring || q_vector->tx.ring)
2943 napi_disable(&q_vector->napi);
2948 * ice_down - Shutdown the connection
2949 * @vsi: The VSI being stopped
2951 int ice_down(struct ice_vsi *vsi)
2953 int i, tx_err, rx_err;
2955 /* Caller of this function is expected to set the
2956 * vsi->state __ICE_DOWN bit
2959 netif_carrier_off(vsi->netdev);
2960 netif_tx_disable(vsi->netdev);
2963 ice_vsi_dis_irq(vsi);
2964 tx_err = ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0);
2966 netdev_err(vsi->netdev,
2967 "Failed stop Tx rings, VSI %d error %d\n",
2968 vsi->vsi_num, tx_err);
2970 rx_err = ice_vsi_stop_rx_rings(vsi);
2972 netdev_err(vsi->netdev,
2973 "Failed stop Rx rings, VSI %d error %d\n",
2974 vsi->vsi_num, rx_err);
2976 ice_napi_disable_all(vsi);
2978 ice_for_each_txq(vsi, i)
2979 ice_clean_tx_ring(vsi->tx_rings[i]);
2981 ice_for_each_rxq(vsi, i)
2982 ice_clean_rx_ring(vsi->rx_rings[i]);
2984 if (tx_err || rx_err) {
2985 netdev_err(vsi->netdev,
2986 "Failed to close VSI 0x%04X on switch 0x%04X\n",
2987 vsi->vsi_num, vsi->vsw->sw_id);
2995 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
2996 * @vsi: VSI having resources allocated
2998 * Return 0 on success, negative on failure
3000 static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3004 if (!vsi->num_txq) {
3005 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3010 ice_for_each_txq(vsi, i) {
3011 vsi->tx_rings[i]->netdev = vsi->netdev;
3012 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3021 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3022 * @vsi: VSI having resources allocated
3024 * Return 0 on success, negative on failure
3026 static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3030 if (!vsi->num_rxq) {
3031 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3036 ice_for_each_rxq(vsi, i) {
3037 vsi->rx_rings[i]->netdev = vsi->netdev;
3038 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3047 * ice_vsi_req_irq - Request IRQ from the OS
3048 * @vsi: The VSI IRQ is being requested for
3049 * @basename: name for the vector
3051 * Return 0 on success and a negative value on error
3053 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
3055 struct ice_pf *pf = vsi->back;
3058 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3059 err = ice_vsi_req_irq_msix(vsi, basename);
3065 * ice_vsi_open - Called when a network interface is made active
3066 * @vsi: the VSI to open
3068 * Initialization of the VSI
3070 * Returns 0 on success, negative value on error
3072 static int ice_vsi_open(struct ice_vsi *vsi)
3074 char int_name[ICE_INT_NAME_STR_LEN];
3075 struct ice_pf *pf = vsi->back;
3078 /* allocate descriptors */
3079 err = ice_vsi_setup_tx_rings(vsi);
3083 err = ice_vsi_setup_rx_rings(vsi);
3087 err = ice_vsi_cfg(vsi);
3091 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3092 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3093 err = ice_vsi_req_irq(vsi, int_name);
3097 /* Notify the stack of the actual queue counts. */
3098 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3102 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3106 err = ice_up_complete(vsi);
3108 goto err_up_complete;
3115 ice_vsi_free_irq(vsi);
3117 ice_vsi_free_rx_rings(vsi);
3119 ice_vsi_free_tx_rings(vsi);
3125 * ice_vsi_release_all - Delete all VSIs
3126 * @pf: PF from which all VSIs are being removed
3128 static void ice_vsi_release_all(struct ice_pf *pf)
3135 for (i = 0; i < pf->num_alloc_vsi; i++) {
3139 err = ice_vsi_release(pf->vsi[i]);
3141 dev_dbg(&pf->pdev->dev,
3142 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3143 i, err, pf->vsi[i]->vsi_num);
3148 * ice_dis_vsi - pause a VSI
3149 * @vsi: the VSI being paused
3150 * @locked: is the rtnl_lock already held
3152 static void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
3154 if (test_bit(__ICE_DOWN, vsi->state))
3157 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3159 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
3160 if (netif_running(vsi->netdev)) {
3163 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3166 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3175 * ice_ena_vsi - resume a VSI
3176 * @vsi: the VSI being resume
3178 static int ice_ena_vsi(struct ice_vsi *vsi)
3182 if (test_and_clear_bit(__ICE_NEEDS_RESTART, vsi->state) &&
3184 if (netif_running(vsi->netdev)) {
3186 err = vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
3189 err = ice_vsi_open(vsi);
3197 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
3200 static void ice_pf_dis_all_vsi(struct ice_pf *pf)
3204 ice_for_each_vsi(pf, v)
3206 ice_dis_vsi(pf->vsi[v], false);
3210 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3213 static int ice_pf_ena_all_vsi(struct ice_pf *pf)
3217 ice_for_each_vsi(pf, v)
3219 if (ice_ena_vsi(pf->vsi[v]))
3226 * ice_vsi_rebuild_all - rebuild all VSIs in pf
3229 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3233 /* loop through pf->vsi array and reinit the VSI if found */
3234 for (i = 0; i < pf->num_alloc_vsi; i++) {
3240 /* VF VSI rebuild isn't supported yet */
3241 if (pf->vsi[i]->type == ICE_VSI_VF)
3244 err = ice_vsi_rebuild(pf->vsi[i]);
3246 dev_err(&pf->pdev->dev,
3247 "VSI at index %d rebuild failed\n",
3252 dev_info(&pf->pdev->dev,
3253 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3254 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3261 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3264 static int ice_vsi_replay_all(struct ice_pf *pf)
3266 struct ice_hw *hw = &pf->hw;
3267 enum ice_status ret;
3270 /* loop through pf->vsi array and replay the VSI if found */
3271 for (i = 0; i < pf->num_alloc_vsi; i++) {
3275 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3277 dev_err(&pf->pdev->dev,
3278 "VSI at index %d replay failed %d\n",
3279 pf->vsi[i]->idx, ret);
3283 /* Re-map HW VSI number, using VSI handle that has been
3284 * previously validated in ice_replay_vsi() call above
3286 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3288 dev_info(&pf->pdev->dev,
3289 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3290 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3293 /* Clean up replay filter after successful re-configuration */
3294 ice_replay_post(hw);
3299 * ice_rebuild - rebuild after reset
3300 * @pf: pf to rebuild
3302 static void ice_rebuild(struct ice_pf *pf)
3304 struct device *dev = &pf->pdev->dev;
3305 struct ice_hw *hw = &pf->hw;
3306 enum ice_status ret;
3309 if (test_bit(__ICE_DOWN, pf->state))
3310 goto clear_recovery;
3312 dev_dbg(dev, "rebuilding pf\n");
3314 ret = ice_init_all_ctrlq(hw);
3316 dev_err(dev, "control queues init failed %d\n", ret);
3317 goto err_init_ctrlq;
3320 ret = ice_clear_pf_cfg(hw);
3322 dev_err(dev, "clear PF configuration failed %d\n", ret);
3323 goto err_init_ctrlq;
3326 ice_clear_pxe_mode(hw);
3328 ret = ice_get_caps(hw);
3330 dev_err(dev, "ice_get_caps failed %d\n", ret);
3331 goto err_init_ctrlq;
3334 err = ice_sched_init_port(hw->port_info);
3336 goto err_sched_init_port;
3338 /* reset search_hint of irq_trackers to 0 since interrupts are
3339 * reclaimed and could be allocated from beginning during VSI rebuild
3341 pf->sw_irq_tracker->search_hint = 0;
3342 pf->hw_irq_tracker->search_hint = 0;
3344 err = ice_vsi_rebuild_all(pf);
3346 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3347 goto err_vsi_rebuild;
3350 err = ice_update_link_info(hw->port_info);
3352 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3354 /* Replay all VSIs Configuration, including filters after reset */
3355 if (ice_vsi_replay_all(pf)) {
3356 dev_err(&pf->pdev->dev,
3357 "error replaying VSI configurations with switch filter rules\n");
3358 goto err_vsi_rebuild;
3361 /* start misc vector */
3362 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3363 err = ice_req_irq_msix_misc(pf);
3365 dev_err(dev, "misc vector setup failed: %d\n", err);
3366 goto err_vsi_rebuild;
3370 /* restart the VSIs that were rebuilt and running before the reset */
3371 err = ice_pf_ena_all_vsi(pf);
3373 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3374 /* no need to disable VSIs in tear down path in ice_rebuild()
3375 * since its already taken care in ice_vsi_open()
3377 goto err_vsi_rebuild;
3380 ice_reset_all_vfs(pf, true);
3382 for (i = 0; i < pf->num_alloc_vsi; i++) {
3385 if (!pf->vsi[i] || pf->vsi[i]->type != ICE_VSI_PF)
3387 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
3389 netif_carrier_on(pf->vsi[i]->netdev);
3390 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
3392 netif_carrier_off(pf->vsi[i]->netdev);
3393 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
3397 /* if we get here, reset flow is successful */
3398 clear_bit(__ICE_RESET_FAILED, pf->state);
3402 ice_vsi_release_all(pf);
3403 err_sched_init_port:
3404 ice_sched_cleanup_all(hw);
3406 ice_shutdown_all_ctrlq(hw);
3407 set_bit(__ICE_RESET_FAILED, pf->state);
3409 /* set this bit in PF state to control service task scheduling */
3410 set_bit(__ICE_NEEDS_RESTART, pf->state);
3411 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3415 * ice_change_mtu - NDO callback to change the MTU
3416 * @netdev: network interface device structure
3417 * @new_mtu: new value for maximum frame size
3419 * Returns 0 on success, negative on failure
3421 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3423 struct ice_netdev_priv *np = netdev_priv(netdev);
3424 struct ice_vsi *vsi = np->vsi;
3425 struct ice_pf *pf = vsi->back;
3428 if (new_mtu == netdev->mtu) {
3429 netdev_warn(netdev, "mtu is already %u\n", netdev->mtu);
3433 if (new_mtu < netdev->min_mtu) {
3434 netdev_err(netdev, "new mtu invalid. min_mtu is %d\n",
3437 } else if (new_mtu > netdev->max_mtu) {
3438 netdev_err(netdev, "new mtu invalid. max_mtu is %d\n",
3442 /* if a reset is in progress, wait for some time for it to complete */
3444 if (ice_is_reset_in_progress(pf->state)) {
3446 usleep_range(1000, 2000);
3451 } while (count < 100);
3454 netdev_err(netdev, "can't change mtu. Device is busy\n");
3458 netdev->mtu = new_mtu;
3460 /* if VSI is up, bring it down and then back up */
3461 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3464 err = ice_down(vsi);
3466 netdev_err(netdev, "change mtu if_up err %d\n", err);
3472 netdev_err(netdev, "change mtu if_up err %d\n", err);
3477 netdev_dbg(netdev, "changed mtu to %d\n", new_mtu);
3482 * ice_set_rss - Set RSS keys and lut
3483 * @vsi: Pointer to VSI structure
3484 * @seed: RSS hash seed
3485 * @lut: Lookup table
3486 * @lut_size: Lookup table size
3488 * Returns 0 on success, negative on failure
3490 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3492 struct ice_pf *pf = vsi->back;
3493 struct ice_hw *hw = &pf->hw;
3494 enum ice_status status;
3497 struct ice_aqc_get_set_rss_keys *buf =
3498 (struct ice_aqc_get_set_rss_keys *)seed;
3500 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3503 dev_err(&pf->pdev->dev,
3504 "Cannot set RSS key, err %d aq_err %d\n",
3505 status, hw->adminq.rq_last_status);
3511 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3514 dev_err(&pf->pdev->dev,
3515 "Cannot set RSS lut, err %d aq_err %d\n",
3516 status, hw->adminq.rq_last_status);
3525 * ice_get_rss - Get RSS keys and lut
3526 * @vsi: Pointer to VSI structure
3527 * @seed: Buffer to store the keys
3528 * @lut: Buffer to store the lookup table entries
3529 * @lut_size: Size of buffer to store the lookup table entries
3531 * Returns 0 on success, negative on failure
3533 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3535 struct ice_pf *pf = vsi->back;
3536 struct ice_hw *hw = &pf->hw;
3537 enum ice_status status;
3540 struct ice_aqc_get_set_rss_keys *buf =
3541 (struct ice_aqc_get_set_rss_keys *)seed;
3543 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
3545 dev_err(&pf->pdev->dev,
3546 "Cannot get RSS key, err %d aq_err %d\n",
3547 status, hw->adminq.rq_last_status);
3553 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3556 dev_err(&pf->pdev->dev,
3557 "Cannot get RSS lut, err %d aq_err %d\n",
3558 status, hw->adminq.rq_last_status);
3567 * ice_bridge_getlink - Get the hardware bridge mode
3570 * @seq: RTNL message seq
3571 * @dev: the netdev being configured
3572 * @filter_mask: filter mask passed in
3573 * @nlflags: netlink flags passed in
3575 * Return the bridge mode (VEB/VEPA)
3578 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
3579 struct net_device *dev, u32 filter_mask, int nlflags)
3581 struct ice_netdev_priv *np = netdev_priv(dev);
3582 struct ice_vsi *vsi = np->vsi;
3583 struct ice_pf *pf = vsi->back;
3586 bmode = pf->first_sw->bridge_mode;
3588 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
3593 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
3594 * @vsi: Pointer to VSI structure
3595 * @bmode: Hardware bridge mode (VEB/VEPA)
3597 * Returns 0 on success, negative on failure
3599 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
3601 struct device *dev = &vsi->back->pdev->dev;
3602 struct ice_aqc_vsi_props *vsi_props;
3603 struct ice_hw *hw = &vsi->back->hw;
3604 struct ice_vsi_ctx ctxt = { 0 };
3605 enum ice_status status;
3607 vsi_props = &vsi->info;
3608 ctxt.info = vsi->info;
3610 if (bmode == BRIDGE_MODE_VEB)
3611 /* change from VEPA to VEB mode */
3612 ctxt.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3614 /* change from VEB to VEPA mode */
3615 ctxt.info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3616 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
3618 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3620 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
3621 bmode, status, hw->adminq.sq_last_status);
3624 /* Update sw flags for book keeping */
3625 vsi_props->sw_flags = ctxt.info.sw_flags;
3631 * ice_bridge_setlink - Set the hardware bridge mode
3632 * @dev: the netdev being configured
3633 * @nlh: RTNL message
3634 * @flags: bridge setlink flags
3635 * @extack: netlink extended ack
3637 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
3638 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
3639 * not already set for all VSIs connected to this switch. And also update the
3640 * unicast switch filter rules for the corresponding switch of the netdev.
3643 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
3644 u16 __always_unused flags, struct netlink_ext_ack *extack)
3646 struct ice_netdev_priv *np = netdev_priv(dev);
3647 struct ice_pf *pf = np->vsi->back;
3648 struct nlattr *attr, *br_spec;
3649 struct ice_hw *hw = &pf->hw;
3650 enum ice_status status;
3651 struct ice_sw *pf_sw;
3652 int rem, v, err = 0;
3654 pf_sw = pf->first_sw;
3655 /* find the attribute in the netlink message */
3656 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
3658 nla_for_each_nested(attr, br_spec, rem) {
3661 if (nla_type(attr) != IFLA_BRIDGE_MODE)
3663 mode = nla_get_u16(attr);
3664 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
3666 /* Continue if bridge mode is not being flipped */
3667 if (mode == pf_sw->bridge_mode)
3669 /* Iterates through the PF VSI list and update the loopback
3672 ice_for_each_vsi(pf, v) {
3675 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
3680 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
3681 /* Update the unicast switch filter rules for the corresponding
3682 * switch of the netdev
3684 status = ice_update_sw_rule_bridge_mode(hw);
3686 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
3687 mode, status, hw->adminq.sq_last_status);
3688 /* revert hw->evb_veb */
3689 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
3693 pf_sw->bridge_mode = mode;
3700 * ice_tx_timeout - Respond to a Tx Hang
3701 * @netdev: network interface device structure
3703 static void ice_tx_timeout(struct net_device *netdev)
3705 struct ice_netdev_priv *np = netdev_priv(netdev);
3706 struct ice_ring *tx_ring = NULL;
3707 struct ice_vsi *vsi = np->vsi;
3708 struct ice_pf *pf = vsi->back;
3709 int hung_queue = -1;
3712 pf->tx_timeout_count++;
3714 /* find the stopped queue the same way dev_watchdog() does */
3715 for (i = 0; i < netdev->num_tx_queues; i++) {
3716 unsigned long trans_start;
3717 struct netdev_queue *q;
3719 q = netdev_get_tx_queue(netdev, i);
3720 trans_start = q->trans_start;
3721 if (netif_xmit_stopped(q) &&
3723 trans_start + netdev->watchdog_timeo)) {
3729 if (i == netdev->num_tx_queues)
3730 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
3732 /* now that we have an index, find the tx_ring struct */
3733 for (i = 0; i < vsi->num_txq; i++)
3734 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
3735 if (hung_queue == vsi->tx_rings[i]->q_index) {
3736 tx_ring = vsi->tx_rings[i];
3740 /* Reset recovery level if enough time has elapsed after last timeout.
3741 * Also ensure no new reset action happens before next timeout period.
3743 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
3744 pf->tx_timeout_recovery_level = 1;
3745 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
3746 netdev->watchdog_timeo)))
3750 struct ice_hw *hw = &pf->hw;
3753 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
3754 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
3755 /* Read interrupt register */
3756 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3758 GLINT_DYN_CTL(tx_ring->q_vector->v_idx +
3759 tx_ring->vsi->hw_base_vector));
3761 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
3762 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
3763 head, tx_ring->next_to_use, val);
3766 pf->tx_timeout_last_recovery = jiffies;
3767 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
3768 pf->tx_timeout_recovery_level, hung_queue);
3770 switch (pf->tx_timeout_recovery_level) {
3772 set_bit(__ICE_PFR_REQ, pf->state);
3775 set_bit(__ICE_CORER_REQ, pf->state);
3778 set_bit(__ICE_GLOBR_REQ, pf->state);
3781 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
3782 set_bit(__ICE_DOWN, pf->state);
3783 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3784 set_bit(__ICE_SERVICE_DIS, pf->state);
3788 ice_service_task_schedule(pf);
3789 pf->tx_timeout_recovery_level++;
3793 * ice_open - Called when a network interface becomes active
3794 * @netdev: network interface device structure
3796 * The open entry point is called when a network interface is made
3797 * active by the system (IFF_UP). At this point all resources needed
3798 * for transmit and receive operations are allocated, the interrupt
3799 * handler is registered with the OS, the netdev watchdog is enabled,
3800 * and the stack is notified that the interface is ready.
3802 * Returns 0 on success, negative value on failure
3804 static int ice_open(struct net_device *netdev)
3806 struct ice_netdev_priv *np = netdev_priv(netdev);
3807 struct ice_vsi *vsi = np->vsi;
3810 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
3811 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
3815 netif_carrier_off(netdev);
3817 err = ice_vsi_open(vsi);
3820 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
3821 vsi->vsi_num, vsi->vsw->sw_id);
3826 * ice_stop - Disables a network interface
3827 * @netdev: network interface device structure
3829 * The stop entry point is called when an interface is de-activated by the OS,
3830 * and the netdevice enters the DOWN state. The hardware is still under the
3831 * driver's control, but the netdev interface is disabled.
3833 * Returns success only - not allowed to fail
3835 static int ice_stop(struct net_device *netdev)
3837 struct ice_netdev_priv *np = netdev_priv(netdev);
3838 struct ice_vsi *vsi = np->vsi;
3846 * ice_features_check - Validate encapsulated packet conforms to limits
3848 * @netdev: This port's netdev
3849 * @features: Offload features that the stack believes apply
3851 static netdev_features_t
3852 ice_features_check(struct sk_buff *skb,
3853 struct net_device __always_unused *netdev,
3854 netdev_features_t features)
3858 /* No point in doing any of this if neither checksum nor GSO are
3859 * being requested for this frame. We can rule out both by just
3860 * checking for CHECKSUM_PARTIAL
3862 if (skb->ip_summed != CHECKSUM_PARTIAL)
3865 /* We cannot support GSO if the MSS is going to be less than
3866 * 64 bytes. If it is then we need to drop support for GSO.
3868 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
3869 features &= ~NETIF_F_GSO_MASK;
3871 len = skb_network_header(skb) - skb->data;
3872 if (len & ~(ICE_TXD_MACLEN_MAX))
3873 goto out_rm_features;
3875 len = skb_transport_header(skb) - skb_network_header(skb);
3876 if (len & ~(ICE_TXD_IPLEN_MAX))
3877 goto out_rm_features;
3879 if (skb->encapsulation) {
3880 len = skb_inner_network_header(skb) - skb_transport_header(skb);
3881 if (len & ~(ICE_TXD_L4LEN_MAX))
3882 goto out_rm_features;
3884 len = skb_inner_transport_header(skb) -
3885 skb_inner_network_header(skb);
3886 if (len & ~(ICE_TXD_IPLEN_MAX))
3887 goto out_rm_features;
3892 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
3895 static const struct net_device_ops ice_netdev_ops = {
3896 .ndo_open = ice_open,
3897 .ndo_stop = ice_stop,
3898 .ndo_start_xmit = ice_start_xmit,
3899 .ndo_features_check = ice_features_check,
3900 .ndo_set_rx_mode = ice_set_rx_mode,
3901 .ndo_set_mac_address = ice_set_mac_address,
3902 .ndo_validate_addr = eth_validate_addr,
3903 .ndo_change_mtu = ice_change_mtu,
3904 .ndo_get_stats64 = ice_get_stats64,
3905 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
3906 .ndo_set_vf_mac = ice_set_vf_mac,
3907 .ndo_get_vf_config = ice_get_vf_cfg,
3908 .ndo_set_vf_trust = ice_set_vf_trust,
3909 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
3910 .ndo_set_vf_link_state = ice_set_vf_link_state,
3911 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
3912 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
3913 .ndo_set_features = ice_set_features,
3914 .ndo_bridge_getlink = ice_bridge_getlink,
3915 .ndo_bridge_setlink = ice_bridge_setlink,
3916 .ndo_fdb_add = ice_fdb_add,
3917 .ndo_fdb_del = ice_fdb_del,
3918 .ndo_tx_timeout = ice_tx_timeout,