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);
352 ice_shutdown_all_ctrlq(hw);
354 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
358 * ice_do_reset - Initiate one of many types of resets
359 * @pf: board private structure
360 * @reset_type: reset type requested
361 * before this function was called.
363 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
365 struct device *dev = &pf->pdev->dev;
366 struct ice_hw *hw = &pf->hw;
368 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
369 WARN_ON(in_interrupt());
371 ice_prepare_for_reset(pf);
373 /* trigger the reset */
374 if (ice_reset(hw, reset_type)) {
375 dev_err(dev, "reset %d failed\n", reset_type);
376 set_bit(__ICE_RESET_FAILED, pf->state);
377 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
378 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
379 clear_bit(__ICE_PFR_REQ, pf->state);
380 clear_bit(__ICE_CORER_REQ, pf->state);
381 clear_bit(__ICE_GLOBR_REQ, pf->state);
385 /* PFR is a bit of a special case because it doesn't result in an OICR
386 * interrupt. So for PFR, rebuild after the reset and clear the reset-
387 * associated state bits.
389 if (reset_type == ICE_RESET_PFR) {
392 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
393 clear_bit(__ICE_PFR_REQ, pf->state);
398 * ice_reset_subtask - Set up for resetting the device and driver
399 * @pf: board private structure
401 static void ice_reset_subtask(struct ice_pf *pf)
403 enum ice_reset_req reset_type = ICE_RESET_INVAL;
405 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
406 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
407 * of reset is pending and sets bits in pf->state indicating the reset
408 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
409 * prepare for pending reset if not already (for PF software-initiated
410 * global resets the software should already be prepared for it as
411 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
412 * by firmware or software on other PFs, that bit is not set so prepare
413 * for the reset now), poll for reset done, rebuild and return.
415 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
416 clear_bit(__ICE_GLOBR_RECV, pf->state);
417 clear_bit(__ICE_CORER_RECV, pf->state);
418 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
419 ice_prepare_for_reset(pf);
421 /* make sure we are ready to rebuild */
422 if (ice_check_reset(&pf->hw)) {
423 set_bit(__ICE_RESET_FAILED, pf->state);
425 /* done with reset. start rebuild */
426 pf->hw.reset_ongoing = false;
428 /* clear bit to resume normal operations, but
429 * ICE_NEEDS_RESTART bit is set incase rebuild failed
431 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
432 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
433 clear_bit(__ICE_PFR_REQ, pf->state);
434 clear_bit(__ICE_CORER_REQ, pf->state);
435 clear_bit(__ICE_GLOBR_REQ, pf->state);
441 /* No pending resets to finish processing. Check for new resets */
442 if (test_bit(__ICE_PFR_REQ, pf->state))
443 reset_type = ICE_RESET_PFR;
444 if (test_bit(__ICE_CORER_REQ, pf->state))
445 reset_type = ICE_RESET_CORER;
446 if (test_bit(__ICE_GLOBR_REQ, pf->state))
447 reset_type = ICE_RESET_GLOBR;
448 /* If no valid reset type requested just return */
449 if (reset_type == ICE_RESET_INVAL)
452 /* reset if not already down or busy */
453 if (!test_bit(__ICE_DOWN, pf->state) &&
454 !test_bit(__ICE_CFG_BUSY, pf->state)) {
455 ice_do_reset(pf, reset_type);
460 * ice_print_link_msg - print link up or down message
461 * @vsi: the VSI whose link status is being queried
462 * @isup: boolean for if the link is now up or down
464 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
469 if (vsi->current_isup == isup)
472 vsi->current_isup = isup;
475 netdev_info(vsi->netdev, "NIC Link is Down\n");
479 switch (vsi->port_info->phy.link_info.link_speed) {
480 case ICE_AQ_LINK_SPEED_40GB:
483 case ICE_AQ_LINK_SPEED_25GB:
486 case ICE_AQ_LINK_SPEED_20GB:
489 case ICE_AQ_LINK_SPEED_10GB:
492 case ICE_AQ_LINK_SPEED_5GB:
495 case ICE_AQ_LINK_SPEED_2500MB:
498 case ICE_AQ_LINK_SPEED_1000MB:
501 case ICE_AQ_LINK_SPEED_100MB:
509 switch (vsi->port_info->fc.current_mode) {
513 case ICE_FC_TX_PAUSE:
516 case ICE_FC_RX_PAUSE:
524 netdev_info(vsi->netdev, "NIC Link is up %sbps, Flow Control: %s\n",
529 * ice_vsi_link_event - update the vsi's netdev
530 * @vsi: the vsi on which the link event occurred
531 * @link_up: whether or not the vsi needs to be set up or down
533 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
535 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
538 if (vsi->type == ICE_VSI_PF) {
540 dev_dbg(&vsi->back->pdev->dev,
541 "vsi->netdev is not initialized!\n");
545 netif_carrier_on(vsi->netdev);
546 netif_tx_wake_all_queues(vsi->netdev);
548 netif_carrier_off(vsi->netdev);
549 netif_tx_stop_all_queues(vsi->netdev);
555 * ice_link_event - process the link event
556 * @pf: pf that the link event is associated with
557 * @pi: port_info for the port that the link event is associated with
559 * Returns -EIO if ice_get_link_status() fails
560 * Returns 0 on success
563 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi)
565 u8 new_link_speed, old_link_speed;
566 struct ice_phy_info *phy_info;
567 bool new_link_same_as_old;
568 bool new_link, old_link;
573 phy_info->link_info_old = phy_info->link_info;
574 /* Force ice_get_link_status() to update link info */
575 phy_info->get_link_info = true;
577 old_link = (phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
578 old_link_speed = phy_info->link_info_old.link_speed;
581 if (ice_get_link_status(pi, &new_link)) {
582 dev_dbg(&pf->pdev->dev,
583 "Could not get link status for port %d\n", lport);
587 new_link_speed = phy_info->link_info.link_speed;
589 new_link_same_as_old = (new_link == old_link &&
590 new_link_speed == old_link_speed);
592 ice_for_each_vsi(pf, v) {
593 struct ice_vsi *vsi = pf->vsi[v];
595 if (!vsi || !vsi->port_info)
598 if (new_link_same_as_old &&
599 (test_bit(__ICE_DOWN, vsi->state) ||
600 new_link == netif_carrier_ok(vsi->netdev)))
603 if (vsi->port_info->lport == lport) {
604 ice_print_link_msg(vsi, new_link);
605 ice_vsi_link_event(vsi, new_link);
609 ice_vc_notify_link_state(pf);
615 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
616 * @pf: board private structure
618 static void ice_watchdog_subtask(struct ice_pf *pf)
622 /* if interface is down do nothing */
623 if (test_bit(__ICE_DOWN, pf->state) ||
624 test_bit(__ICE_CFG_BUSY, pf->state))
627 /* make sure we don't do these things too often */
628 if (time_before(jiffies,
629 pf->serv_tmr_prev + pf->serv_tmr_period))
632 pf->serv_tmr_prev = jiffies;
634 if (ice_link_event(pf, pf->hw.port_info))
635 dev_dbg(&pf->pdev->dev, "ice_link_event failed\n");
637 /* Update the stats for active netdevs so the network stack
638 * can look at updated numbers whenever it cares to
640 ice_update_pf_stats(pf);
641 for (i = 0; i < pf->num_alloc_vsi; i++)
642 if (pf->vsi[i] && pf->vsi[i]->netdev)
643 ice_update_vsi_stats(pf->vsi[i]);
647 * __ice_clean_ctrlq - helper function to clean controlq rings
648 * @pf: ptr to struct ice_pf
649 * @q_type: specific Control queue type
651 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
653 struct ice_rq_event_info event;
654 struct ice_hw *hw = &pf->hw;
655 struct ice_ctl_q_info *cq;
660 /* Do not clean control queue if/when PF reset fails */
661 if (test_bit(__ICE_RESET_FAILED, pf->state))
665 case ICE_CTL_Q_ADMIN:
669 case ICE_CTL_Q_MAILBOX:
674 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
679 /* check for error indications - PF_xx_AxQLEN register layout for
680 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
682 val = rd32(hw, cq->rq.len);
683 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
684 PF_FW_ARQLEN_ARQCRIT_M)) {
686 if (val & PF_FW_ARQLEN_ARQVFE_M)
687 dev_dbg(&pf->pdev->dev,
688 "%s Receive Queue VF Error detected\n", qtype);
689 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
690 dev_dbg(&pf->pdev->dev,
691 "%s Receive Queue Overflow Error detected\n",
694 if (val & PF_FW_ARQLEN_ARQCRIT_M)
695 dev_dbg(&pf->pdev->dev,
696 "%s Receive Queue Critical Error detected\n",
698 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
699 PF_FW_ARQLEN_ARQCRIT_M);
701 wr32(hw, cq->rq.len, val);
704 val = rd32(hw, cq->sq.len);
705 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
706 PF_FW_ATQLEN_ATQCRIT_M)) {
708 if (val & PF_FW_ATQLEN_ATQVFE_M)
709 dev_dbg(&pf->pdev->dev,
710 "%s Send Queue VF Error detected\n", qtype);
711 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
712 dev_dbg(&pf->pdev->dev,
713 "%s Send Queue Overflow Error detected\n",
716 if (val & PF_FW_ATQLEN_ATQCRIT_M)
717 dev_dbg(&pf->pdev->dev,
718 "%s Send Queue Critical Error detected\n",
720 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
721 PF_FW_ATQLEN_ATQCRIT_M);
723 wr32(hw, cq->sq.len, val);
726 event.buf_len = cq->rq_buf_size;
727 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
736 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
737 if (ret == ICE_ERR_AQ_NO_WORK)
740 dev_err(&pf->pdev->dev,
741 "%s Receive Queue event error %d\n", qtype,
746 opcode = le16_to_cpu(event.desc.opcode);
749 case ice_mbx_opc_send_msg_to_pf:
750 ice_vc_process_vf_msg(pf, &event);
752 case ice_aqc_opc_fw_logging:
753 ice_output_fw_log(hw, &event.desc, event.msg_buf);
756 dev_dbg(&pf->pdev->dev,
757 "%s Receive Queue unknown event 0x%04x ignored\n",
761 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
763 devm_kfree(&pf->pdev->dev, event.msg_buf);
765 return pending && (i == ICE_DFLT_IRQ_WORK);
769 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
770 * @hw: pointer to hardware info
771 * @cq: control queue information
773 * returns true if there are pending messages in a queue, false if there aren't
775 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
779 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
780 return cq->rq.next_to_clean != ntu;
784 * ice_clean_adminq_subtask - clean the AdminQ rings
785 * @pf: board private structure
787 static void ice_clean_adminq_subtask(struct ice_pf *pf)
789 struct ice_hw *hw = &pf->hw;
791 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
794 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
797 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
799 /* There might be a situation where new messages arrive to a control
800 * queue between processing the last message and clearing the
801 * EVENT_PENDING bit. So before exiting, check queue head again (using
802 * ice_ctrlq_pending) and process new messages if any.
804 if (ice_ctrlq_pending(hw, &hw->adminq))
805 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
811 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
812 * @pf: board private structure
814 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
816 struct ice_hw *hw = &pf->hw;
818 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
821 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
824 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
826 if (ice_ctrlq_pending(hw, &hw->mailboxq))
827 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
833 * ice_service_task_schedule - schedule the service task to wake up
834 * @pf: board private structure
836 * If not already scheduled, this puts the task into the work queue.
838 static void ice_service_task_schedule(struct ice_pf *pf)
840 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
841 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
842 !test_bit(__ICE_NEEDS_RESTART, pf->state))
843 queue_work(ice_wq, &pf->serv_task);
847 * ice_service_task_complete - finish up the service task
848 * @pf: board private structure
850 static void ice_service_task_complete(struct ice_pf *pf)
852 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
854 /* force memory (pf->state) to sync before next service task */
855 smp_mb__before_atomic();
856 clear_bit(__ICE_SERVICE_SCHED, pf->state);
860 * ice_service_task_stop - stop service task and cancel works
861 * @pf: board private structure
863 static void ice_service_task_stop(struct ice_pf *pf)
865 set_bit(__ICE_SERVICE_DIS, pf->state);
867 if (pf->serv_tmr.function)
868 del_timer_sync(&pf->serv_tmr);
869 if (pf->serv_task.func)
870 cancel_work_sync(&pf->serv_task);
872 clear_bit(__ICE_SERVICE_SCHED, pf->state);
876 * ice_service_timer - timer callback to schedule service task
877 * @t: pointer to timer_list
879 static void ice_service_timer(struct timer_list *t)
881 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
883 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
884 ice_service_task_schedule(pf);
888 * ice_handle_mdd_event - handle malicious driver detect event
889 * @pf: pointer to the PF structure
891 * Called from service task. OICR interrupt handler indicates MDD event
893 static void ice_handle_mdd_event(struct ice_pf *pf)
895 struct ice_hw *hw = &pf->hw;
896 bool mdd_detected = false;
900 if (!test_bit(__ICE_MDD_EVENT_PENDING, pf->state))
903 /* find what triggered the MDD event */
904 reg = rd32(hw, GL_MDET_TX_PQM);
905 if (reg & GL_MDET_TX_PQM_VALID_M) {
906 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
907 GL_MDET_TX_PQM_PF_NUM_S;
908 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
909 GL_MDET_TX_PQM_VF_NUM_S;
910 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
911 GL_MDET_TX_PQM_MAL_TYPE_S;
912 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
913 GL_MDET_TX_PQM_QNUM_S);
915 if (netif_msg_tx_err(pf))
916 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
917 event, queue, pf_num, vf_num);
918 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
922 reg = rd32(hw, GL_MDET_TX_TCLAN);
923 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
924 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
925 GL_MDET_TX_TCLAN_PF_NUM_S;
926 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
927 GL_MDET_TX_TCLAN_VF_NUM_S;
928 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
929 GL_MDET_TX_TCLAN_MAL_TYPE_S;
930 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
931 GL_MDET_TX_TCLAN_QNUM_S);
933 if (netif_msg_rx_err(pf))
934 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
935 event, queue, pf_num, vf_num);
936 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
940 reg = rd32(hw, GL_MDET_RX);
941 if (reg & GL_MDET_RX_VALID_M) {
942 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
944 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
946 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
947 GL_MDET_RX_MAL_TYPE_S;
948 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
951 if (netif_msg_rx_err(pf))
952 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
953 event, queue, pf_num, vf_num);
954 wr32(hw, GL_MDET_RX, 0xffffffff);
959 bool pf_mdd_detected = false;
961 reg = rd32(hw, PF_MDET_TX_PQM);
962 if (reg & PF_MDET_TX_PQM_VALID_M) {
963 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
964 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
965 pf_mdd_detected = true;
968 reg = rd32(hw, PF_MDET_TX_TCLAN);
969 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
970 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
971 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
972 pf_mdd_detected = true;
975 reg = rd32(hw, PF_MDET_RX);
976 if (reg & PF_MDET_RX_VALID_M) {
977 wr32(hw, PF_MDET_RX, 0xFFFF);
978 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
979 pf_mdd_detected = true;
981 /* Queue belongs to the PF initiate a reset */
982 if (pf_mdd_detected) {
983 set_bit(__ICE_NEEDS_RESTART, pf->state);
984 ice_service_task_schedule(pf);
988 /* see if one of the VFs needs to be reset */
989 for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
990 struct ice_vf *vf = &pf->vf[i];
992 reg = rd32(hw, VP_MDET_TX_PQM(i));
993 if (reg & VP_MDET_TX_PQM_VALID_M) {
994 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
995 vf->num_mdd_events++;
996 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1000 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1001 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1002 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1003 vf->num_mdd_events++;
1004 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1008 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1009 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1010 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1011 vf->num_mdd_events++;
1012 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1016 reg = rd32(hw, VP_MDET_RX(i));
1017 if (reg & VP_MDET_RX_VALID_M) {
1018 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1019 vf->num_mdd_events++;
1020 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1024 if (vf->num_mdd_events > ICE_DFLT_NUM_MDD_EVENTS_ALLOWED) {
1025 dev_info(&pf->pdev->dev,
1026 "Too many MDD events on VF %d, disabled\n", i);
1027 dev_info(&pf->pdev->dev,
1028 "Use PF Control I/F to re-enable the VF\n");
1029 set_bit(ICE_VF_STATE_DIS, vf->vf_states);
1033 /* re-enable MDD interrupt cause */
1034 clear_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1035 reg = rd32(hw, PFINT_OICR_ENA);
1036 reg |= PFINT_OICR_MAL_DETECT_M;
1037 wr32(hw, PFINT_OICR_ENA, reg);
1042 * ice_service_task - manage and run subtasks
1043 * @work: pointer to work_struct contained by the PF struct
1045 static void ice_service_task(struct work_struct *work)
1047 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1048 unsigned long start_time = jiffies;
1052 /* process reset requests first */
1053 ice_reset_subtask(pf);
1055 /* bail if a reset/recovery cycle is pending or rebuild failed */
1056 if (ice_is_reset_in_progress(pf->state) ||
1057 test_bit(__ICE_SUSPENDED, pf->state) ||
1058 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1059 ice_service_task_complete(pf);
1063 ice_check_for_hang_subtask(pf);
1064 ice_sync_fltr_subtask(pf);
1065 ice_handle_mdd_event(pf);
1066 ice_process_vflr_event(pf);
1067 ice_watchdog_subtask(pf);
1068 ice_clean_adminq_subtask(pf);
1069 ice_clean_mailboxq_subtask(pf);
1071 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1072 ice_service_task_complete(pf);
1074 /* If the tasks have taken longer than one service timer period
1075 * or there is more work to be done, reset the service timer to
1076 * schedule the service task now.
1078 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1079 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1080 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1081 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1082 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1083 mod_timer(&pf->serv_tmr, jiffies);
1087 * ice_set_ctrlq_len - helper function to set controlq length
1088 * @hw: pointer to the hw instance
1090 static void ice_set_ctrlq_len(struct ice_hw *hw)
1092 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1093 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1094 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1095 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1096 hw->mailboxq.num_rq_entries = ICE_MBXQ_LEN;
1097 hw->mailboxq.num_sq_entries = ICE_MBXQ_LEN;
1098 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1099 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1103 * ice_irq_affinity_notify - Callback for affinity changes
1104 * @notify: context as to what irq was changed
1105 * @mask: the new affinity mask
1107 * This is a callback function used by the irq_set_affinity_notifier function
1108 * so that we may register to receive changes to the irq affinity masks.
1110 static void ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1111 const cpumask_t *mask)
1113 struct ice_q_vector *q_vector =
1114 container_of(notify, struct ice_q_vector, affinity_notify);
1116 cpumask_copy(&q_vector->affinity_mask, mask);
1120 * ice_irq_affinity_release - Callback for affinity notifier release
1121 * @ref: internal core kernel usage
1123 * This is a callback function used by the irq_set_affinity_notifier function
1124 * to inform the current notification subscriber that they will no longer
1125 * receive notifications.
1127 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1130 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1131 * @vsi: the VSI being configured
1133 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1135 struct ice_pf *pf = vsi->back;
1136 struct ice_hw *hw = &pf->hw;
1138 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1141 for (i = 0; i < vsi->num_q_vectors; i++)
1142 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1150 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1151 * @vsi: the VSI being configured
1152 * @basename: name for the vector
1154 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1156 int q_vectors = vsi->num_q_vectors;
1157 struct ice_pf *pf = vsi->back;
1158 int base = vsi->sw_base_vector;
1164 for (vector = 0; vector < q_vectors; vector++) {
1165 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1167 irq_num = pf->msix_entries[base + vector].vector;
1169 if (q_vector->tx.ring && q_vector->rx.ring) {
1170 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1171 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1173 } else if (q_vector->rx.ring) {
1174 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1175 "%s-%s-%d", basename, "rx", rx_int_idx++);
1176 } else if (q_vector->tx.ring) {
1177 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1178 "%s-%s-%d", basename, "tx", tx_int_idx++);
1180 /* skip this unused q_vector */
1183 err = devm_request_irq(&pf->pdev->dev,
1184 pf->msix_entries[base + vector].vector,
1185 vsi->irq_handler, 0, q_vector->name,
1188 netdev_err(vsi->netdev,
1189 "MSIX request_irq failed, error: %d\n", err);
1193 /* register for affinity change notifications */
1194 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1195 q_vector->affinity_notify.release = ice_irq_affinity_release;
1196 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1198 /* assign the mask for this irq */
1199 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1202 vsi->irqs_ready = true;
1208 irq_num = pf->msix_entries[base + vector].vector,
1209 irq_set_affinity_notifier(irq_num, NULL);
1210 irq_set_affinity_hint(irq_num, NULL);
1211 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1217 * ice_ena_misc_vector - enable the non-queue interrupts
1218 * @pf: board private structure
1220 static void ice_ena_misc_vector(struct ice_pf *pf)
1222 struct ice_hw *hw = &pf->hw;
1225 /* clear things first */
1226 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1227 rd32(hw, PFINT_OICR); /* read to clear */
1229 val = (PFINT_OICR_ECC_ERR_M |
1230 PFINT_OICR_MAL_DETECT_M |
1232 PFINT_OICR_PCI_EXCEPTION_M |
1234 PFINT_OICR_HMC_ERR_M |
1235 PFINT_OICR_PE_CRITERR_M);
1237 wr32(hw, PFINT_OICR_ENA, val);
1239 /* SW_ITR_IDX = 0, but don't change INTENA */
1240 wr32(hw, GLINT_DYN_CTL(pf->hw_oicr_idx),
1241 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1245 * ice_misc_intr - misc interrupt handler
1246 * @irq: interrupt number
1247 * @data: pointer to a q_vector
1249 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1251 struct ice_pf *pf = (struct ice_pf *)data;
1252 struct ice_hw *hw = &pf->hw;
1253 irqreturn_t ret = IRQ_NONE;
1256 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1257 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1259 oicr = rd32(hw, PFINT_OICR);
1260 ena_mask = rd32(hw, PFINT_OICR_ENA);
1262 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1263 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1264 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1266 if (oicr & PFINT_OICR_VFLR_M) {
1267 ena_mask &= ~PFINT_OICR_VFLR_M;
1268 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1271 if (oicr & PFINT_OICR_GRST_M) {
1274 /* we have a reset warning */
1275 ena_mask &= ~PFINT_OICR_GRST_M;
1276 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1277 GLGEN_RSTAT_RESET_TYPE_S;
1279 if (reset == ICE_RESET_CORER)
1281 else if (reset == ICE_RESET_GLOBR)
1283 else if (reset == ICE_RESET_EMPR)
1286 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1289 /* If a reset cycle isn't already in progress, we set a bit in
1290 * pf->state so that the service task can start a reset/rebuild.
1291 * We also make note of which reset happened so that peer
1292 * devices/drivers can be informed.
1294 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1295 if (reset == ICE_RESET_CORER)
1296 set_bit(__ICE_CORER_RECV, pf->state);
1297 else if (reset == ICE_RESET_GLOBR)
1298 set_bit(__ICE_GLOBR_RECV, pf->state);
1300 set_bit(__ICE_EMPR_RECV, pf->state);
1302 /* There are couple of different bits at play here.
1303 * hw->reset_ongoing indicates whether the hardware is
1304 * in reset. This is set to true when a reset interrupt
1305 * is received and set back to false after the driver
1306 * has determined that the hardware is out of reset.
1308 * __ICE_RESET_OICR_RECV in pf->state indicates
1309 * that a post reset rebuild is required before the
1310 * driver is operational again. This is set above.
1312 * As this is the start of the reset/rebuild cycle, set
1313 * both to indicate that.
1315 hw->reset_ongoing = true;
1319 if (oicr & PFINT_OICR_HMC_ERR_M) {
1320 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1321 dev_dbg(&pf->pdev->dev,
1322 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1323 rd32(hw, PFHMC_ERRORINFO),
1324 rd32(hw, PFHMC_ERRORDATA));
1327 /* Report and mask off any remaining unexpected interrupts */
1330 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1332 /* If a critical error is pending there is no choice but to
1335 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1336 PFINT_OICR_PCI_EXCEPTION_M |
1337 PFINT_OICR_ECC_ERR_M)) {
1338 set_bit(__ICE_PFR_REQ, pf->state);
1339 ice_service_task_schedule(pf);
1345 /* re-enable interrupt causes that are not handled during this pass */
1346 wr32(hw, PFINT_OICR_ENA, ena_mask);
1347 if (!test_bit(__ICE_DOWN, pf->state)) {
1348 ice_service_task_schedule(pf);
1349 ice_irq_dynamic_ena(hw, NULL, NULL);
1356 * ice_free_irq_msix_misc - Unroll misc vector setup
1357 * @pf: board private structure
1359 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1361 /* disable OICR interrupt */
1362 wr32(&pf->hw, PFINT_OICR_ENA, 0);
1365 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
1366 synchronize_irq(pf->msix_entries[pf->sw_oicr_idx].vector);
1367 devm_free_irq(&pf->pdev->dev,
1368 pf->msix_entries[pf->sw_oicr_idx].vector, pf);
1371 pf->num_avail_sw_msix += 1;
1372 ice_free_res(pf->sw_irq_tracker, pf->sw_oicr_idx, ICE_RES_MISC_VEC_ID);
1373 pf->num_avail_hw_msix += 1;
1374 ice_free_res(pf->hw_irq_tracker, pf->hw_oicr_idx, ICE_RES_MISC_VEC_ID);
1378 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1379 * @pf: board private structure
1381 * This sets up the handler for MSIX 0, which is used to manage the
1382 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1383 * when in MSI or Legacy interrupt mode.
1385 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1387 struct ice_hw *hw = &pf->hw;
1388 int oicr_idx, err = 0;
1392 if (!pf->int_name[0])
1393 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1394 dev_driver_string(&pf->pdev->dev),
1395 dev_name(&pf->pdev->dev));
1397 /* Do not request IRQ but do enable OICR interrupt since settings are
1398 * lost during reset. Note that this function is called only during
1399 * rebuild path and not while reset is in progress.
1401 if (ice_is_reset_in_progress(pf->state))
1404 /* reserve one vector in sw_irq_tracker for misc interrupts */
1405 oicr_idx = ice_get_res(pf, pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1409 pf->num_avail_sw_msix -= 1;
1410 pf->sw_oicr_idx = oicr_idx;
1412 /* reserve one vector in hw_irq_tracker for misc interrupts */
1413 oicr_idx = ice_get_res(pf, pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1415 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1416 pf->num_avail_sw_msix += 1;
1419 pf->num_avail_hw_msix -= 1;
1420 pf->hw_oicr_idx = oicr_idx;
1422 err = devm_request_irq(&pf->pdev->dev,
1423 pf->msix_entries[pf->sw_oicr_idx].vector,
1424 ice_misc_intr, 0, pf->int_name, pf);
1426 dev_err(&pf->pdev->dev,
1427 "devm_request_irq for %s failed: %d\n",
1429 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1430 pf->num_avail_sw_msix += 1;
1431 ice_free_res(pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1432 pf->num_avail_hw_msix += 1;
1437 ice_ena_misc_vector(pf);
1439 val = ((pf->hw_oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1440 PFINT_OICR_CTL_CAUSE_ENA_M);
1441 wr32(hw, PFINT_OICR_CTL, val);
1443 /* This enables Admin queue Interrupt causes */
1444 val = ((pf->hw_oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1445 PFINT_FW_CTL_CAUSE_ENA_M);
1446 wr32(hw, PFINT_FW_CTL, val);
1448 /* This enables Mailbox queue Interrupt causes */
1449 val = ((pf->hw_oicr_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1450 PFINT_MBX_CTL_CAUSE_ENA_M);
1451 wr32(hw, PFINT_MBX_CTL, val);
1453 itr_gran = hw->itr_gran;
1455 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->hw_oicr_idx),
1456 ITR_TO_REG(ICE_ITR_8K, itr_gran));
1459 ice_irq_dynamic_ena(hw, NULL, NULL);
1465 * ice_napi_del - Remove NAPI handler for the VSI
1466 * @vsi: VSI for which NAPI handler is to be removed
1468 static void ice_napi_del(struct ice_vsi *vsi)
1475 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1476 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
1480 * ice_napi_add - register NAPI handler for the VSI
1481 * @vsi: VSI for which NAPI handler is to be registered
1483 * This function is only called in the driver's load path. Registering the NAPI
1484 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1485 * reset/rebuild, etc.)
1487 static void ice_napi_add(struct ice_vsi *vsi)
1494 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1495 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1496 ice_napi_poll, NAPI_POLL_WEIGHT);
1500 * ice_cfg_netdev - Allocate, configure and register a netdev
1501 * @vsi: the VSI associated with the new netdev
1503 * Returns 0 on success, negative value on failure
1505 static int ice_cfg_netdev(struct ice_vsi *vsi)
1507 netdev_features_t csumo_features;
1508 netdev_features_t vlano_features;
1509 netdev_features_t dflt_features;
1510 netdev_features_t tso_features;
1511 struct ice_netdev_priv *np;
1512 struct net_device *netdev;
1513 u8 mac_addr[ETH_ALEN];
1516 netdev = alloc_etherdev_mqs(sizeof(struct ice_netdev_priv),
1517 vsi->alloc_txq, vsi->alloc_rxq);
1521 vsi->netdev = netdev;
1522 np = netdev_priv(netdev);
1525 dflt_features = NETIF_F_SG |
1529 csumo_features = NETIF_F_RXCSUM |
1533 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1534 NETIF_F_HW_VLAN_CTAG_TX |
1535 NETIF_F_HW_VLAN_CTAG_RX;
1537 tso_features = NETIF_F_TSO;
1539 /* set features that user can change */
1540 netdev->hw_features = dflt_features | csumo_features |
1541 vlano_features | tso_features;
1543 /* enable features */
1544 netdev->features |= netdev->hw_features;
1545 /* encap and VLAN devices inherit default, csumo and tso features */
1546 netdev->hw_enc_features |= dflt_features | csumo_features |
1548 netdev->vlan_features |= dflt_features | csumo_features |
1551 if (vsi->type == ICE_VSI_PF) {
1552 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1553 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1555 ether_addr_copy(netdev->dev_addr, mac_addr);
1556 ether_addr_copy(netdev->perm_addr, mac_addr);
1559 netdev->priv_flags |= IFF_UNICAST_FLT;
1561 /* assign netdev_ops */
1562 netdev->netdev_ops = &ice_netdev_ops;
1564 /* setup watchdog timeout value to be 5 second */
1565 netdev->watchdog_timeo = 5 * HZ;
1567 ice_set_ethtool_ops(netdev);
1569 netdev->min_mtu = ETH_MIN_MTU;
1570 netdev->max_mtu = ICE_MAX_MTU;
1572 err = register_netdev(vsi->netdev);
1576 netif_carrier_off(vsi->netdev);
1578 /* make sure transmit queues start off as stopped */
1579 netif_tx_stop_all_queues(vsi->netdev);
1585 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1586 * @lut: Lookup table
1587 * @rss_table_size: Lookup table size
1588 * @rss_size: Range of queue number for hashing
1590 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1594 for (i = 0; i < rss_table_size; i++)
1595 lut[i] = i % rss_size;
1599 * ice_pf_vsi_setup - Set up a PF VSI
1600 * @pf: board private structure
1601 * @pi: pointer to the port_info instance
1603 * Returns pointer to the successfully allocated VSI sw struct on success,
1604 * otherwise returns NULL on failure.
1606 static struct ice_vsi *
1607 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1609 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
1613 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload
1614 * @netdev: network interface to be adjusted
1615 * @proto: unused protocol
1616 * @vid: vlan id to be added
1618 * net_device_ops implementation for adding vlan ids
1620 static int ice_vlan_rx_add_vid(struct net_device *netdev,
1621 __always_unused __be16 proto, u16 vid)
1623 struct ice_netdev_priv *np = netdev_priv(netdev);
1624 struct ice_vsi *vsi = np->vsi;
1627 if (vid >= VLAN_N_VID) {
1628 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
1636 /* Enable VLAN pruning when VLAN 0 is added */
1637 if (unlikely(!vid)) {
1638 ret = ice_cfg_vlan_pruning(vsi, true);
1643 /* Add all VLAN ids including 0 to the switch filter. VLAN id 0 is
1644 * needed to continue allowing all untagged packets since VLAN prune
1645 * list is applied to all packets by the switch
1647 ret = ice_vsi_add_vlan(vsi, vid);
1650 set_bit(vid, vsi->active_vlans);
1656 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
1657 * @netdev: network interface to be adjusted
1658 * @proto: unused protocol
1659 * @vid: vlan id to be removed
1661 * net_device_ops implementation for removing vlan ids
1663 static int ice_vlan_rx_kill_vid(struct net_device *netdev,
1664 __always_unused __be16 proto, u16 vid)
1666 struct ice_netdev_priv *np = netdev_priv(netdev);
1667 struct ice_vsi *vsi = np->vsi;
1673 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
1676 status = ice_vsi_kill_vlan(vsi, vid);
1680 clear_bit(vid, vsi->active_vlans);
1682 /* Disable VLAN pruning when VLAN 0 is removed */
1684 status = ice_cfg_vlan_pruning(vsi, false);
1690 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
1691 * @pf: board private structure
1693 * Returns 0 on success, negative value on failure
1695 static int ice_setup_pf_sw(struct ice_pf *pf)
1697 LIST_HEAD(tmp_add_list);
1698 u8 broadcast[ETH_ALEN];
1699 struct ice_vsi *vsi;
1702 if (ice_is_reset_in_progress(pf->state))
1705 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
1708 goto unroll_vsi_setup;
1711 status = ice_cfg_netdev(vsi);
1714 goto unroll_vsi_setup;
1717 /* registering the NAPI handler requires both the queues and
1718 * netdev to be created, which are done in ice_pf_vsi_setup()
1719 * and ice_cfg_netdev() respectively
1723 /* To add a MAC filter, first add the MAC to a list and then
1724 * pass the list to ice_add_mac.
1727 /* Add a unicast MAC filter so the VSI can get its packets */
1728 status = ice_add_mac_to_list(vsi, &tmp_add_list,
1729 vsi->port_info->mac.perm_addr);
1731 goto unroll_napi_add;
1733 /* VSI needs to receive broadcast traffic, so add the broadcast
1734 * MAC address to the list as well.
1736 eth_broadcast_addr(broadcast);
1737 status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
1741 /* program MAC filters for entries in tmp_add_list */
1742 status = ice_add_mac(&pf->hw, &tmp_add_list);
1744 dev_err(&pf->pdev->dev, "Could not add MAC filters\n");
1749 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1753 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1759 if (vsi->netdev->reg_state == NETREG_REGISTERED)
1760 unregister_netdev(vsi->netdev);
1761 free_netdev(vsi->netdev);
1768 ice_vsi_free_q_vectors(vsi);
1769 ice_vsi_delete(vsi);
1770 ice_vsi_put_qs(vsi);
1771 pf->q_left_tx += vsi->alloc_txq;
1772 pf->q_left_rx += vsi->alloc_rxq;
1779 * ice_determine_q_usage - Calculate queue distribution
1780 * @pf: board private structure
1782 * Return -ENOMEM if we don't get enough queues for all ports
1784 static void ice_determine_q_usage(struct ice_pf *pf)
1786 u16 q_left_tx, q_left_rx;
1788 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
1789 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
1791 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
1793 /* only 1 rx queue unless RSS is enabled */
1794 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1797 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
1799 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
1800 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
1804 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
1805 * @pf: board private structure to initialize
1807 static void ice_deinit_pf(struct ice_pf *pf)
1809 ice_service_task_stop(pf);
1810 mutex_destroy(&pf->sw_mutex);
1811 mutex_destroy(&pf->avail_q_mutex);
1815 * ice_init_pf - Initialize general software structures (struct ice_pf)
1816 * @pf: board private structure to initialize
1818 static void ice_init_pf(struct ice_pf *pf)
1820 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
1821 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1822 #ifdef CONFIG_PCI_IOV
1823 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
1824 struct ice_hw *hw = &pf->hw;
1826 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
1827 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
1830 #endif /* CONFIG_PCI_IOV */
1832 mutex_init(&pf->sw_mutex);
1833 mutex_init(&pf->avail_q_mutex);
1835 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
1836 mutex_lock(&pf->avail_q_mutex);
1837 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
1838 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
1839 mutex_unlock(&pf->avail_q_mutex);
1841 if (pf->hw.func_caps.common_cap.rss_table_size)
1842 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
1844 /* setup service timer and periodic service task */
1845 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
1846 pf->serv_tmr_period = HZ;
1847 INIT_WORK(&pf->serv_task, ice_service_task);
1848 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1852 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
1853 * @pf: board private structure
1855 * compute the number of MSIX vectors required (v_budget) and request from
1856 * the OS. Return the number of vectors reserved or negative on failure
1858 static int ice_ena_msix_range(struct ice_pf *pf)
1860 int v_left, v_actual, v_budget = 0;
1863 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
1865 /* reserve one vector for miscellaneous handler */
1870 /* reserve vectors for LAN traffic */
1871 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
1872 v_budget += pf->num_lan_msix;
1873 v_left -= pf->num_lan_msix;
1875 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
1876 sizeof(struct msix_entry), GFP_KERNEL);
1878 if (!pf->msix_entries) {
1883 for (i = 0; i < v_budget; i++)
1884 pf->msix_entries[i].entry = i;
1886 /* actually reserve the vectors */
1887 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
1888 ICE_MIN_MSIX, v_budget);
1891 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
1896 if (v_actual < v_budget) {
1897 dev_warn(&pf->pdev->dev,
1898 "not enough vectors. requested = %d, obtained = %d\n",
1899 v_budget, v_actual);
1900 if (v_actual >= (pf->num_lan_msix + 1)) {
1901 pf->num_avail_sw_msix = v_actual -
1902 (pf->num_lan_msix + 1);
1903 } else if (v_actual >= 2) {
1904 pf->num_lan_msix = 1;
1905 pf->num_avail_sw_msix = v_actual - 2;
1907 pci_disable_msix(pf->pdev);
1916 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1920 pf->num_lan_msix = 0;
1921 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1926 * ice_dis_msix - Disable MSI-X interrupt setup in OS
1927 * @pf: board private structure
1929 static void ice_dis_msix(struct ice_pf *pf)
1931 pci_disable_msix(pf->pdev);
1932 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1933 pf->msix_entries = NULL;
1934 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1938 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
1939 * @pf: board private structure
1941 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
1943 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1946 if (pf->sw_irq_tracker) {
1947 devm_kfree(&pf->pdev->dev, pf->sw_irq_tracker);
1948 pf->sw_irq_tracker = NULL;
1951 if (pf->hw_irq_tracker) {
1952 devm_kfree(&pf->pdev->dev, pf->hw_irq_tracker);
1953 pf->hw_irq_tracker = NULL;
1958 * ice_init_interrupt_scheme - Determine proper interrupt scheme
1959 * @pf: board private structure to initialize
1961 static int ice_init_interrupt_scheme(struct ice_pf *pf)
1963 int vectors = 0, hw_vectors = 0;
1966 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1967 vectors = ice_ena_msix_range(pf);
1974 /* set up vector assignment tracking */
1975 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * vectors);
1977 pf->sw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1978 if (!pf->sw_irq_tracker) {
1983 /* populate SW interrupts pool with number of OS granted IRQs. */
1984 pf->num_avail_sw_msix = vectors;
1985 pf->sw_irq_tracker->num_entries = vectors;
1987 /* set up HW vector assignment tracking */
1988 hw_vectors = pf->hw.func_caps.common_cap.num_msix_vectors;
1989 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * hw_vectors);
1991 pf->hw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1992 if (!pf->hw_irq_tracker) {
1993 ice_clear_interrupt_scheme(pf);
1997 /* populate HW interrupts pool with number of HW supported irqs. */
1998 pf->num_avail_hw_msix = hw_vectors;
1999 pf->hw_irq_tracker->num_entries = hw_vectors;
2005 * ice_probe - Device initialization routine
2006 * @pdev: PCI device information struct
2007 * @ent: entry in ice_pci_tbl
2009 * Returns 0 on success, negative on failure
2011 static int ice_probe(struct pci_dev *pdev,
2012 const struct pci_device_id __always_unused *ent)
2018 /* this driver uses devres, see Documentation/driver-model/devres.txt */
2019 err = pcim_enable_device(pdev);
2023 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2025 dev_err(&pdev->dev, "BAR0 I/O map error %d\n", err);
2029 pf = devm_kzalloc(&pdev->dev, sizeof(*pf), GFP_KERNEL);
2033 /* set up for high or low dma */
2034 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2036 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2038 dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
2042 pci_enable_pcie_error_reporting(pdev);
2043 pci_set_master(pdev);
2046 pci_set_drvdata(pdev, pf);
2047 set_bit(__ICE_DOWN, pf->state);
2048 /* Disable service task until DOWN bit is cleared */
2049 set_bit(__ICE_SERVICE_DIS, pf->state);
2052 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2054 hw->vendor_id = pdev->vendor;
2055 hw->device_id = pdev->device;
2056 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2057 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2058 hw->subsystem_device_id = pdev->subsystem_device;
2059 hw->bus.device = PCI_SLOT(pdev->devfn);
2060 hw->bus.func = PCI_FUNC(pdev->devfn);
2061 ice_set_ctrlq_len(hw);
2063 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2065 #ifndef CONFIG_DYNAMIC_DEBUG
2067 hw->debug_mask = debug;
2070 err = ice_init_hw(hw);
2072 dev_err(&pdev->dev, "ice_init_hw failed: %d\n", err);
2074 goto err_exit_unroll;
2077 dev_info(&pdev->dev, "firmware %d.%d.%05d api %d.%d\n",
2078 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2079 hw->api_maj_ver, hw->api_min_ver);
2083 ice_determine_q_usage(pf);
2085 pf->num_alloc_vsi = min_t(u16, ICE_MAX_VSI_ALLOC,
2086 hw->func_caps.guaranteed_num_vsi);
2087 if (!pf->num_alloc_vsi) {
2089 goto err_init_pf_unroll;
2092 pf->vsi = devm_kcalloc(&pdev->dev, pf->num_alloc_vsi,
2093 sizeof(struct ice_vsi *), GFP_KERNEL);
2096 goto err_init_pf_unroll;
2099 err = ice_init_interrupt_scheme(pf);
2102 "ice_init_interrupt_scheme failed: %d\n", err);
2104 goto err_init_interrupt_unroll;
2107 /* Driver is mostly up */
2108 clear_bit(__ICE_DOWN, pf->state);
2110 /* In case of MSIX we are going to setup the misc vector right here
2111 * to handle admin queue events etc. In case of legacy and MSI
2112 * the misc functionality and queue processing is combined in
2113 * the same vector and that gets setup at open.
2115 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2116 err = ice_req_irq_msix_misc(pf);
2119 "setup of misc vector failed: %d\n", err);
2120 goto err_init_interrupt_unroll;
2124 /* create switch struct for the switch element created by FW on boot */
2125 pf->first_sw = devm_kzalloc(&pdev->dev, sizeof(struct ice_sw),
2127 if (!pf->first_sw) {
2129 goto err_msix_misc_unroll;
2133 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2135 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2137 pf->first_sw->pf = pf;
2139 /* record the sw_id available for later use */
2140 pf->first_sw->sw_id = hw->port_info->sw_id;
2142 err = ice_setup_pf_sw(pf);
2145 "probe failed due to setup pf switch:%d\n", err);
2146 goto err_alloc_sw_unroll;
2149 clear_bit(__ICE_SERVICE_DIS, pf->state);
2151 /* since everything is good, start the service timer */
2152 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2156 err_alloc_sw_unroll:
2157 set_bit(__ICE_SERVICE_DIS, pf->state);
2158 set_bit(__ICE_DOWN, pf->state);
2159 devm_kfree(&pf->pdev->dev, pf->first_sw);
2160 err_msix_misc_unroll:
2161 ice_free_irq_msix_misc(pf);
2162 err_init_interrupt_unroll:
2163 ice_clear_interrupt_scheme(pf);
2164 devm_kfree(&pdev->dev, pf->vsi);
2169 pci_disable_pcie_error_reporting(pdev);
2174 * ice_remove - Device removal routine
2175 * @pdev: PCI device information struct
2177 static void ice_remove(struct pci_dev *pdev)
2179 struct ice_pf *pf = pci_get_drvdata(pdev);
2185 set_bit(__ICE_DOWN, pf->state);
2186 ice_service_task_stop(pf);
2188 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2190 ice_vsi_release_all(pf);
2191 ice_free_irq_msix_misc(pf);
2192 ice_for_each_vsi(pf, i) {
2195 ice_vsi_free_q_vectors(pf->vsi[i]);
2197 ice_clear_interrupt_scheme(pf);
2199 ice_deinit_hw(&pf->hw);
2200 pci_disable_pcie_error_reporting(pdev);
2203 /* ice_pci_tbl - PCI Device ID Table
2205 * Wildcard entries (PCI_ANY_ID) should come last
2206 * Last entry must be all 0s
2208 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2209 * Class, Class Mask, private data (not used) }
2211 static const struct pci_device_id ice_pci_tbl[] = {
2212 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
2213 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
2214 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
2215 /* required last entry */
2218 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2220 static struct pci_driver ice_driver = {
2221 .name = KBUILD_MODNAME,
2222 .id_table = ice_pci_tbl,
2224 .remove = ice_remove,
2225 .sriov_configure = ice_sriov_configure,
2229 * ice_module_init - Driver registration routine
2231 * ice_module_init is the first routine called when the driver is
2232 * loaded. All it does is register with the PCI subsystem.
2234 static int __init ice_module_init(void)
2238 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2239 pr_info("%s\n", ice_copyright);
2241 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2243 pr_err("Failed to create workqueue\n");
2247 status = pci_register_driver(&ice_driver);
2249 pr_err("failed to register pci driver, err %d\n", status);
2250 destroy_workqueue(ice_wq);
2255 module_init(ice_module_init);
2258 * ice_module_exit - Driver exit cleanup routine
2260 * ice_module_exit is called just before the driver is removed
2263 static void __exit ice_module_exit(void)
2265 pci_unregister_driver(&ice_driver);
2266 destroy_workqueue(ice_wq);
2267 pr_info("module unloaded\n");
2269 module_exit(ice_module_exit);
2272 * ice_set_mac_address - NDO callback to set mac address
2273 * @netdev: network interface device structure
2274 * @pi: pointer to an address structure
2276 * Returns 0 on success, negative on failure
2278 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2280 struct ice_netdev_priv *np = netdev_priv(netdev);
2281 struct ice_vsi *vsi = np->vsi;
2282 struct ice_pf *pf = vsi->back;
2283 struct ice_hw *hw = &pf->hw;
2284 struct sockaddr *addr = pi;
2285 enum ice_status status;
2286 LIST_HEAD(a_mac_list);
2287 LIST_HEAD(r_mac_list);
2292 mac = (u8 *)addr->sa_data;
2294 if (!is_valid_ether_addr(mac))
2295 return -EADDRNOTAVAIL;
2297 if (ether_addr_equal(netdev->dev_addr, mac)) {
2298 netdev_warn(netdev, "already using mac %pM\n", mac);
2302 if (test_bit(__ICE_DOWN, pf->state) ||
2303 ice_is_reset_in_progress(pf->state)) {
2304 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2309 /* When we change the mac address we also have to change the mac address
2310 * based filter rules that were created previously for the old mac
2311 * address. So first, we remove the old filter rule using ice_remove_mac
2312 * and then create a new filter rule using ice_add_mac. Note that for
2313 * both these operations, we first need to form a "list" of mac
2314 * addresses (even though in this case, we have only 1 mac address to be
2315 * added/removed) and this done using ice_add_mac_to_list. Depending on
2316 * the ensuing operation this "list" of mac addresses is either to be
2317 * added or removed from the filter.
2319 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
2321 err = -EADDRNOTAVAIL;
2325 status = ice_remove_mac(hw, &r_mac_list);
2327 err = -EADDRNOTAVAIL;
2331 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
2333 err = -EADDRNOTAVAIL;
2337 status = ice_add_mac(hw, &a_mac_list);
2339 err = -EADDRNOTAVAIL;
2344 /* free list entries */
2345 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
2346 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
2349 netdev_err(netdev, "can't set mac %pM. filter update failed\n",
2354 /* change the netdev's mac address */
2355 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2356 netdev_dbg(vsi->netdev, "updated mac address to %pM\n",
2359 /* write new mac address to the firmware */
2360 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2361 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2363 netdev_err(netdev, "can't set mac %pM. write to firmware failed.\n",
2370 * ice_set_rx_mode - NDO callback to set the netdev filters
2371 * @netdev: network interface device structure
2373 static void ice_set_rx_mode(struct net_device *netdev)
2375 struct ice_netdev_priv *np = netdev_priv(netdev);
2376 struct ice_vsi *vsi = np->vsi;
2381 /* Set the flags to synchronize filters
2382 * ndo_set_rx_mode may be triggered even without a change in netdev
2385 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2386 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2387 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2389 /* schedule our worker thread which will take care of
2390 * applying the new filter changes
2392 ice_service_task_schedule(vsi->back);
2396 * ice_fdb_add - add an entry to the hardware database
2397 * @ndm: the input from the stack
2398 * @tb: pointer to array of nladdr (unused)
2399 * @dev: the net device pointer
2400 * @addr: the MAC address entry being added
2402 * @flags: instructions from stack about fdb operation
2404 static int ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2405 struct net_device *dev, const unsigned char *addr,
2411 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2414 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2415 netdev_err(dev, "FDB only supports static addresses\n");
2419 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2420 err = dev_uc_add_excl(dev, addr);
2421 else if (is_multicast_ether_addr(addr))
2422 err = dev_mc_add_excl(dev, addr);
2426 /* Only return duplicate errors if NLM_F_EXCL is set */
2427 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2434 * ice_fdb_del - delete an entry from the hardware database
2435 * @ndm: the input from the stack
2436 * @tb: pointer to array of nladdr (unused)
2437 * @dev: the net device pointer
2438 * @addr: the MAC address entry being added
2441 static int ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2442 struct net_device *dev, const unsigned char *addr,
2443 __always_unused u16 vid)
2447 if (ndm->ndm_state & NUD_PERMANENT) {
2448 netdev_err(dev, "FDB only supports static addresses\n");
2452 if (is_unicast_ether_addr(addr))
2453 err = dev_uc_del(dev, addr);
2454 else if (is_multicast_ether_addr(addr))
2455 err = dev_mc_del(dev, addr);
2463 * ice_set_features - set the netdev feature flags
2464 * @netdev: ptr to the netdev being adjusted
2465 * @features: the feature set that the stack is suggesting
2467 static int ice_set_features(struct net_device *netdev,
2468 netdev_features_t features)
2470 struct ice_netdev_priv *np = netdev_priv(netdev);
2471 struct ice_vsi *vsi = np->vsi;
2474 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
2475 ret = ice_vsi_manage_rss_lut(vsi, true);
2476 else if (!(features & NETIF_F_RXHASH) &&
2477 netdev->features & NETIF_F_RXHASH)
2478 ret = ice_vsi_manage_rss_lut(vsi, false);
2480 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
2481 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2482 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2483 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
2484 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2485 ret = ice_vsi_manage_vlan_stripping(vsi, false);
2486 else if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
2487 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2488 ret = ice_vsi_manage_vlan_insertion(vsi);
2489 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
2490 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2491 ret = ice_vsi_manage_vlan_insertion(vsi);
2497 * ice_vsi_vlan_setup - Setup vlan offload properties on a VSI
2498 * @vsi: VSI to setup vlan properties for
2500 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
2504 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2505 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2506 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
2507 ret = ice_vsi_manage_vlan_insertion(vsi);
2513 * ice_restore_vlan - Reinstate VLANs when vsi/netdev comes back up
2514 * @vsi: the VSI being brought back up
2516 static int ice_restore_vlan(struct ice_vsi *vsi)
2524 err = ice_vsi_vlan_setup(vsi);
2528 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) {
2529 err = ice_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), vid);
2538 * ice_vsi_cfg - Setup the VSI
2539 * @vsi: the VSI being configured
2541 * Return 0 on success and negative value on error
2543 static int ice_vsi_cfg(struct ice_vsi *vsi)
2548 ice_set_rx_mode(vsi->netdev);
2549 err = ice_restore_vlan(vsi);
2554 err = ice_vsi_cfg_txqs(vsi);
2556 err = ice_vsi_cfg_rxqs(vsi);
2562 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
2563 * @vsi: the VSI being configured
2565 static void ice_napi_enable_all(struct ice_vsi *vsi)
2572 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
2573 napi_enable(&vsi->q_vectors[q_idx]->napi);
2577 * ice_up_complete - Finish the last steps of bringing up a connection
2578 * @vsi: The VSI being configured
2580 * Return 0 on success and negative value on error
2582 static int ice_up_complete(struct ice_vsi *vsi)
2584 struct ice_pf *pf = vsi->back;
2587 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2588 ice_vsi_cfg_msix(vsi);
2592 /* Enable only Rx rings, Tx rings were enabled by the FW when the
2593 * Tx queue group list was configured and the context bits were
2594 * programmed using ice_vsi_cfg_txqs
2596 err = ice_vsi_start_rx_rings(vsi);
2600 clear_bit(__ICE_DOWN, vsi->state);
2601 ice_napi_enable_all(vsi);
2602 ice_vsi_ena_irq(vsi);
2604 if (vsi->port_info &&
2605 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
2607 ice_print_link_msg(vsi, true);
2608 netif_tx_start_all_queues(vsi->netdev);
2609 netif_carrier_on(vsi->netdev);
2612 ice_service_task_schedule(pf);
2618 * ice_up - Bring the connection back up after being down
2619 * @vsi: VSI being configured
2621 int ice_up(struct ice_vsi *vsi)
2625 err = ice_vsi_cfg(vsi);
2627 err = ice_up_complete(vsi);
2633 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
2634 * @ring: Tx or Rx ring to read stats from
2635 * @pkts: packets stats counter
2636 * @bytes: bytes stats counter
2638 * This function fetches stats from the ring considering the atomic operations
2639 * that needs to be performed to read u64 values in 32 bit machine.
2641 static void ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts,
2651 start = u64_stats_fetch_begin_irq(&ring->syncp);
2652 *pkts = ring->stats.pkts;
2653 *bytes = ring->stats.bytes;
2654 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
2658 * ice_update_vsi_ring_stats - Update VSI stats counters
2659 * @vsi: the VSI to be updated
2661 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
2663 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
2664 struct ice_ring *ring;
2668 /* reset netdev stats */
2669 vsi_stats->tx_packets = 0;
2670 vsi_stats->tx_bytes = 0;
2671 vsi_stats->rx_packets = 0;
2672 vsi_stats->rx_bytes = 0;
2674 /* reset non-netdev (extended) stats */
2675 vsi->tx_restart = 0;
2677 vsi->tx_linearize = 0;
2678 vsi->rx_buf_failed = 0;
2679 vsi->rx_page_failed = 0;
2683 /* update Tx rings counters */
2684 ice_for_each_txq(vsi, i) {
2685 ring = READ_ONCE(vsi->tx_rings[i]);
2686 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2687 vsi_stats->tx_packets += pkts;
2688 vsi_stats->tx_bytes += bytes;
2689 vsi->tx_restart += ring->tx_stats.restart_q;
2690 vsi->tx_busy += ring->tx_stats.tx_busy;
2691 vsi->tx_linearize += ring->tx_stats.tx_linearize;
2694 /* update Rx rings counters */
2695 ice_for_each_rxq(vsi, i) {
2696 ring = READ_ONCE(vsi->rx_rings[i]);
2697 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2698 vsi_stats->rx_packets += pkts;
2699 vsi_stats->rx_bytes += bytes;
2700 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
2701 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
2708 * ice_update_vsi_stats - Update VSI stats counters
2709 * @vsi: the VSI to be updated
2711 static void ice_update_vsi_stats(struct ice_vsi *vsi)
2713 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
2714 struct ice_eth_stats *cur_es = &vsi->eth_stats;
2715 struct ice_pf *pf = vsi->back;
2717 if (test_bit(__ICE_DOWN, vsi->state) ||
2718 test_bit(__ICE_CFG_BUSY, pf->state))
2721 /* get stats as recorded by Tx/Rx rings */
2722 ice_update_vsi_ring_stats(vsi);
2724 /* get VSI stats as recorded by the hardware */
2725 ice_update_eth_stats(vsi);
2727 cur_ns->tx_errors = cur_es->tx_errors;
2728 cur_ns->rx_dropped = cur_es->rx_discards;
2729 cur_ns->tx_dropped = cur_es->tx_discards;
2730 cur_ns->multicast = cur_es->rx_multicast;
2732 /* update some more netdev stats if this is main VSI */
2733 if (vsi->type == ICE_VSI_PF) {
2734 cur_ns->rx_crc_errors = pf->stats.crc_errors;
2735 cur_ns->rx_errors = pf->stats.crc_errors +
2736 pf->stats.illegal_bytes;
2737 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
2742 * ice_update_pf_stats - Update PF port stats counters
2743 * @pf: PF whose stats needs to be updated
2745 static void ice_update_pf_stats(struct ice_pf *pf)
2747 struct ice_hw_port_stats *prev_ps, *cur_ps;
2748 struct ice_hw *hw = &pf->hw;
2751 prev_ps = &pf->stats_prev;
2752 cur_ps = &pf->stats;
2755 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
2756 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
2757 &cur_ps->eth.rx_bytes);
2759 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
2760 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
2761 &cur_ps->eth.rx_unicast);
2763 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
2764 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
2765 &cur_ps->eth.rx_multicast);
2767 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
2768 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
2769 &cur_ps->eth.rx_broadcast);
2771 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
2772 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
2773 &cur_ps->eth.tx_bytes);
2775 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
2776 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
2777 &cur_ps->eth.tx_unicast);
2779 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
2780 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
2781 &cur_ps->eth.tx_multicast);
2783 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
2784 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
2785 &cur_ps->eth.tx_broadcast);
2787 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
2788 &prev_ps->tx_dropped_link_down,
2789 &cur_ps->tx_dropped_link_down);
2791 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
2792 pf->stat_prev_loaded, &prev_ps->rx_size_64,
2793 &cur_ps->rx_size_64);
2795 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
2796 pf->stat_prev_loaded, &prev_ps->rx_size_127,
2797 &cur_ps->rx_size_127);
2799 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
2800 pf->stat_prev_loaded, &prev_ps->rx_size_255,
2801 &cur_ps->rx_size_255);
2803 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
2804 pf->stat_prev_loaded, &prev_ps->rx_size_511,
2805 &cur_ps->rx_size_511);
2807 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
2808 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
2809 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
2811 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
2812 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
2813 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
2815 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
2816 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
2817 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
2819 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
2820 pf->stat_prev_loaded, &prev_ps->tx_size_64,
2821 &cur_ps->tx_size_64);
2823 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
2824 pf->stat_prev_loaded, &prev_ps->tx_size_127,
2825 &cur_ps->tx_size_127);
2827 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
2828 pf->stat_prev_loaded, &prev_ps->tx_size_255,
2829 &cur_ps->tx_size_255);
2831 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
2832 pf->stat_prev_loaded, &prev_ps->tx_size_511,
2833 &cur_ps->tx_size_511);
2835 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
2836 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
2837 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
2839 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
2840 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
2841 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
2843 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
2844 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
2845 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
2847 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
2848 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
2850 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
2851 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
2853 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
2854 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
2856 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
2857 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
2859 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
2860 &prev_ps->crc_errors, &cur_ps->crc_errors);
2862 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
2863 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
2865 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
2866 &prev_ps->mac_local_faults,
2867 &cur_ps->mac_local_faults);
2869 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
2870 &prev_ps->mac_remote_faults,
2871 &cur_ps->mac_remote_faults);
2873 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
2874 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
2876 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
2877 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
2879 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
2880 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
2882 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
2883 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
2885 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
2886 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
2888 pf->stat_prev_loaded = true;
2892 * ice_get_stats64 - get statistics for network device structure
2893 * @netdev: network interface device structure
2894 * @stats: main device statistics structure
2897 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
2899 struct ice_netdev_priv *np = netdev_priv(netdev);
2900 struct rtnl_link_stats64 *vsi_stats;
2901 struct ice_vsi *vsi = np->vsi;
2903 vsi_stats = &vsi->net_stats;
2905 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
2907 /* netdev packet/byte stats come from ring counter. These are obtained
2908 * by summing up ring counters (done by ice_update_vsi_ring_stats).
2910 ice_update_vsi_ring_stats(vsi);
2911 stats->tx_packets = vsi_stats->tx_packets;
2912 stats->tx_bytes = vsi_stats->tx_bytes;
2913 stats->rx_packets = vsi_stats->rx_packets;
2914 stats->rx_bytes = vsi_stats->rx_bytes;
2916 /* The rest of the stats can be read from the hardware but instead we
2917 * just return values that the watchdog task has already obtained from
2920 stats->multicast = vsi_stats->multicast;
2921 stats->tx_errors = vsi_stats->tx_errors;
2922 stats->tx_dropped = vsi_stats->tx_dropped;
2923 stats->rx_errors = vsi_stats->rx_errors;
2924 stats->rx_dropped = vsi_stats->rx_dropped;
2925 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
2926 stats->rx_length_errors = vsi_stats->rx_length_errors;
2930 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
2931 * @vsi: VSI having NAPI disabled
2933 static void ice_napi_disable_all(struct ice_vsi *vsi)
2940 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
2941 napi_disable(&vsi->q_vectors[q_idx]->napi);
2945 * ice_down - Shutdown the connection
2946 * @vsi: The VSI being stopped
2948 int ice_down(struct ice_vsi *vsi)
2950 int i, tx_err, rx_err;
2952 /* Caller of this function is expected to set the
2953 * vsi->state __ICE_DOWN bit
2956 netif_carrier_off(vsi->netdev);
2957 netif_tx_disable(vsi->netdev);
2960 ice_vsi_dis_irq(vsi);
2961 tx_err = ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0);
2963 netdev_err(vsi->netdev,
2964 "Failed stop Tx rings, VSI %d error %d\n",
2965 vsi->vsi_num, tx_err);
2967 rx_err = ice_vsi_stop_rx_rings(vsi);
2969 netdev_err(vsi->netdev,
2970 "Failed stop Rx rings, VSI %d error %d\n",
2971 vsi->vsi_num, rx_err);
2973 ice_napi_disable_all(vsi);
2975 ice_for_each_txq(vsi, i)
2976 ice_clean_tx_ring(vsi->tx_rings[i]);
2978 ice_for_each_rxq(vsi, i)
2979 ice_clean_rx_ring(vsi->rx_rings[i]);
2981 if (tx_err || rx_err) {
2982 netdev_err(vsi->netdev,
2983 "Failed to close VSI 0x%04X on switch 0x%04X\n",
2984 vsi->vsi_num, vsi->vsw->sw_id);
2992 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
2993 * @vsi: VSI having resources allocated
2995 * Return 0 on success, negative on failure
2997 static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3001 if (!vsi->num_txq) {
3002 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3007 ice_for_each_txq(vsi, i) {
3008 vsi->tx_rings[i]->netdev = vsi->netdev;
3009 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3018 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3019 * @vsi: VSI having resources allocated
3021 * Return 0 on success, negative on failure
3023 static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3027 if (!vsi->num_rxq) {
3028 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3033 ice_for_each_rxq(vsi, i) {
3034 vsi->rx_rings[i]->netdev = vsi->netdev;
3035 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3044 * ice_vsi_req_irq - Request IRQ from the OS
3045 * @vsi: The VSI IRQ is being requested for
3046 * @basename: name for the vector
3048 * Return 0 on success and a negative value on error
3050 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
3052 struct ice_pf *pf = vsi->back;
3055 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3056 err = ice_vsi_req_irq_msix(vsi, basename);
3062 * ice_vsi_open - Called when a network interface is made active
3063 * @vsi: the VSI to open
3065 * Initialization of the VSI
3067 * Returns 0 on success, negative value on error
3069 static int ice_vsi_open(struct ice_vsi *vsi)
3071 char int_name[ICE_INT_NAME_STR_LEN];
3072 struct ice_pf *pf = vsi->back;
3075 /* allocate descriptors */
3076 err = ice_vsi_setup_tx_rings(vsi);
3080 err = ice_vsi_setup_rx_rings(vsi);
3084 err = ice_vsi_cfg(vsi);
3088 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3089 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3090 err = ice_vsi_req_irq(vsi, int_name);
3094 /* Notify the stack of the actual queue counts. */
3095 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3099 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3103 err = ice_up_complete(vsi);
3105 goto err_up_complete;
3112 ice_vsi_free_irq(vsi);
3114 ice_vsi_free_rx_rings(vsi);
3116 ice_vsi_free_tx_rings(vsi);
3122 * ice_vsi_release_all - Delete all VSIs
3123 * @pf: PF from which all VSIs are being removed
3125 static void ice_vsi_release_all(struct ice_pf *pf)
3132 for (i = 0; i < pf->num_alloc_vsi; i++) {
3136 err = ice_vsi_release(pf->vsi[i]);
3138 dev_dbg(&pf->pdev->dev,
3139 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3140 i, err, pf->vsi[i]->vsi_num);
3145 * ice_dis_vsi - pause a VSI
3146 * @vsi: the VSI being paused
3148 static void ice_dis_vsi(struct ice_vsi *vsi)
3150 if (test_bit(__ICE_DOWN, vsi->state))
3153 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3155 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
3156 if (netif_running(vsi->netdev)) {
3158 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3167 * ice_ena_vsi - resume a VSI
3168 * @vsi: the VSI being resume
3170 static int ice_ena_vsi(struct ice_vsi *vsi)
3174 if (test_and_clear_bit(__ICE_NEEDS_RESTART, vsi->state) &&
3176 if (netif_running(vsi->netdev)) {
3178 err = vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
3181 err = ice_vsi_open(vsi);
3189 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
3192 static void ice_pf_dis_all_vsi(struct ice_pf *pf)
3196 ice_for_each_vsi(pf, v)
3198 ice_dis_vsi(pf->vsi[v]);
3202 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3205 static int ice_pf_ena_all_vsi(struct ice_pf *pf)
3209 ice_for_each_vsi(pf, v)
3211 if (ice_ena_vsi(pf->vsi[v]))
3218 * ice_vsi_rebuild_all - rebuild all VSIs in pf
3221 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3225 /* loop through pf->vsi array and reinit the VSI if found */
3226 for (i = 0; i < pf->num_alloc_vsi; i++) {
3232 /* VF VSI rebuild isn't supported yet */
3233 if (pf->vsi[i]->type == ICE_VSI_VF)
3236 err = ice_vsi_rebuild(pf->vsi[i]);
3238 dev_err(&pf->pdev->dev,
3239 "VSI at index %d rebuild failed\n",
3244 dev_info(&pf->pdev->dev,
3245 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3246 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3253 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3256 static int ice_vsi_replay_all(struct ice_pf *pf)
3258 struct ice_hw *hw = &pf->hw;
3259 enum ice_status ret;
3262 /* loop through pf->vsi array and replay the VSI if found */
3263 for (i = 0; i < pf->num_alloc_vsi; i++) {
3267 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3269 dev_err(&pf->pdev->dev,
3270 "VSI at index %d replay failed %d\n",
3271 pf->vsi[i]->idx, ret);
3275 /* Re-map HW VSI number, using VSI handle that has been
3276 * previously validated in ice_replay_vsi() call above
3278 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3280 dev_info(&pf->pdev->dev,
3281 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3282 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3285 /* Clean up replay filter after successful re-configuration */
3286 ice_replay_post(hw);
3291 * ice_rebuild - rebuild after reset
3292 * @pf: pf to rebuild
3294 static void ice_rebuild(struct ice_pf *pf)
3296 struct device *dev = &pf->pdev->dev;
3297 struct ice_hw *hw = &pf->hw;
3298 enum ice_status ret;
3301 if (test_bit(__ICE_DOWN, pf->state))
3302 goto clear_recovery;
3304 dev_dbg(dev, "rebuilding pf\n");
3306 ret = ice_init_all_ctrlq(hw);
3308 dev_err(dev, "control queues init failed %d\n", ret);
3309 goto err_init_ctrlq;
3312 ret = ice_clear_pf_cfg(hw);
3314 dev_err(dev, "clear PF configuration failed %d\n", ret);
3315 goto err_init_ctrlq;
3318 ice_clear_pxe_mode(hw);
3320 ret = ice_get_caps(hw);
3322 dev_err(dev, "ice_get_caps failed %d\n", ret);
3323 goto err_init_ctrlq;
3326 err = ice_sched_init_port(hw->port_info);
3328 goto err_sched_init_port;
3330 /* reset search_hint of irq_trackers to 0 since interrupts are
3331 * reclaimed and could be allocated from beginning during VSI rebuild
3333 pf->sw_irq_tracker->search_hint = 0;
3334 pf->hw_irq_tracker->search_hint = 0;
3336 err = ice_vsi_rebuild_all(pf);
3338 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3339 goto err_vsi_rebuild;
3342 err = ice_update_link_info(hw->port_info);
3344 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3346 /* Replay all VSIs Configuration, including filters after reset */
3347 if (ice_vsi_replay_all(pf)) {
3348 dev_err(&pf->pdev->dev,
3349 "error replaying VSI configurations with switch filter rules\n");
3350 goto err_vsi_rebuild;
3353 /* start misc vector */
3354 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3355 err = ice_req_irq_msix_misc(pf);
3357 dev_err(dev, "misc vector setup failed: %d\n", err);
3358 goto err_vsi_rebuild;
3362 /* restart the VSIs that were rebuilt and running before the reset */
3363 err = ice_pf_ena_all_vsi(pf);
3365 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3366 /* no need to disable VSIs in tear down path in ice_rebuild()
3367 * since its already taken care in ice_vsi_open()
3369 goto err_vsi_rebuild;
3372 ice_reset_all_vfs(pf, true);
3373 /* if we get here, reset flow is successful */
3374 clear_bit(__ICE_RESET_FAILED, pf->state);
3378 ice_vsi_release_all(pf);
3379 err_sched_init_port:
3380 ice_sched_cleanup_all(hw);
3382 ice_shutdown_all_ctrlq(hw);
3383 set_bit(__ICE_RESET_FAILED, pf->state);
3385 /* set this bit in PF state to control service task scheduling */
3386 set_bit(__ICE_NEEDS_RESTART, pf->state);
3387 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3391 * ice_change_mtu - NDO callback to change the MTU
3392 * @netdev: network interface device structure
3393 * @new_mtu: new value for maximum frame size
3395 * Returns 0 on success, negative on failure
3397 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3399 struct ice_netdev_priv *np = netdev_priv(netdev);
3400 struct ice_vsi *vsi = np->vsi;
3401 struct ice_pf *pf = vsi->back;
3404 if (new_mtu == netdev->mtu) {
3405 netdev_warn(netdev, "mtu is already %u\n", netdev->mtu);
3409 if (new_mtu < netdev->min_mtu) {
3410 netdev_err(netdev, "new mtu invalid. min_mtu is %d\n",
3413 } else if (new_mtu > netdev->max_mtu) {
3414 netdev_err(netdev, "new mtu invalid. max_mtu is %d\n",
3418 /* if a reset is in progress, wait for some time for it to complete */
3420 if (ice_is_reset_in_progress(pf->state)) {
3422 usleep_range(1000, 2000);
3427 } while (count < 100);
3430 netdev_err(netdev, "can't change mtu. Device is busy\n");
3434 netdev->mtu = new_mtu;
3436 /* if VSI is up, bring it down and then back up */
3437 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3440 err = ice_down(vsi);
3442 netdev_err(netdev, "change mtu if_up err %d\n", err);
3448 netdev_err(netdev, "change mtu if_up err %d\n", err);
3453 netdev_dbg(netdev, "changed mtu to %d\n", new_mtu);
3458 * ice_set_rss - Set RSS keys and lut
3459 * @vsi: Pointer to VSI structure
3460 * @seed: RSS hash seed
3461 * @lut: Lookup table
3462 * @lut_size: Lookup table size
3464 * Returns 0 on success, negative on failure
3466 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3468 struct ice_pf *pf = vsi->back;
3469 struct ice_hw *hw = &pf->hw;
3470 enum ice_status status;
3473 struct ice_aqc_get_set_rss_keys *buf =
3474 (struct ice_aqc_get_set_rss_keys *)seed;
3476 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3479 dev_err(&pf->pdev->dev,
3480 "Cannot set RSS key, err %d aq_err %d\n",
3481 status, hw->adminq.rq_last_status);
3487 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3490 dev_err(&pf->pdev->dev,
3491 "Cannot set RSS lut, err %d aq_err %d\n",
3492 status, hw->adminq.rq_last_status);
3501 * ice_get_rss - Get RSS keys and lut
3502 * @vsi: Pointer to VSI structure
3503 * @seed: Buffer to store the keys
3504 * @lut: Buffer to store the lookup table entries
3505 * @lut_size: Size of buffer to store the lookup table entries
3507 * Returns 0 on success, negative on failure
3509 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3511 struct ice_pf *pf = vsi->back;
3512 struct ice_hw *hw = &pf->hw;
3513 enum ice_status status;
3516 struct ice_aqc_get_set_rss_keys *buf =
3517 (struct ice_aqc_get_set_rss_keys *)seed;
3519 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
3521 dev_err(&pf->pdev->dev,
3522 "Cannot get RSS key, err %d aq_err %d\n",
3523 status, hw->adminq.rq_last_status);
3529 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3532 dev_err(&pf->pdev->dev,
3533 "Cannot get RSS lut, err %d aq_err %d\n",
3534 status, hw->adminq.rq_last_status);
3543 * ice_bridge_getlink - Get the hardware bridge mode
3546 * @seq: RTNL message seq
3547 * @dev: the netdev being configured
3548 * @filter_mask: filter mask passed in
3549 * @nlflags: netlink flags passed in
3551 * Return the bridge mode (VEB/VEPA)
3554 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
3555 struct net_device *dev, u32 filter_mask, int nlflags)
3557 struct ice_netdev_priv *np = netdev_priv(dev);
3558 struct ice_vsi *vsi = np->vsi;
3559 struct ice_pf *pf = vsi->back;
3562 bmode = pf->first_sw->bridge_mode;
3564 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
3569 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
3570 * @vsi: Pointer to VSI structure
3571 * @bmode: Hardware bridge mode (VEB/VEPA)
3573 * Returns 0 on success, negative on failure
3575 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
3577 struct device *dev = &vsi->back->pdev->dev;
3578 struct ice_aqc_vsi_props *vsi_props;
3579 struct ice_hw *hw = &vsi->back->hw;
3580 struct ice_vsi_ctx ctxt = { 0 };
3581 enum ice_status status;
3583 vsi_props = &vsi->info;
3584 ctxt.info = vsi->info;
3586 if (bmode == BRIDGE_MODE_VEB)
3587 /* change from VEPA to VEB mode */
3588 ctxt.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3590 /* change from VEB to VEPA mode */
3591 ctxt.info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3592 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
3594 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3596 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
3597 bmode, status, hw->adminq.sq_last_status);
3600 /* Update sw flags for book keeping */
3601 vsi_props->sw_flags = ctxt.info.sw_flags;
3607 * ice_bridge_setlink - Set the hardware bridge mode
3608 * @dev: the netdev being configured
3609 * @nlh: RTNL message
3610 * @flags: bridge setlink flags
3612 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
3613 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
3614 * not already set for all VSIs connected to this switch. And also update the
3615 * unicast switch filter rules for the corresponding switch of the netdev.
3618 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
3619 u16 __always_unused flags)
3621 struct ice_netdev_priv *np = netdev_priv(dev);
3622 struct ice_pf *pf = np->vsi->back;
3623 struct nlattr *attr, *br_spec;
3624 struct ice_hw *hw = &pf->hw;
3625 enum ice_status status;
3626 struct ice_sw *pf_sw;
3627 int rem, v, err = 0;
3629 pf_sw = pf->first_sw;
3630 /* find the attribute in the netlink message */
3631 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
3633 nla_for_each_nested(attr, br_spec, rem) {
3636 if (nla_type(attr) != IFLA_BRIDGE_MODE)
3638 mode = nla_get_u16(attr);
3639 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
3641 /* Continue if bridge mode is not being flipped */
3642 if (mode == pf_sw->bridge_mode)
3644 /* Iterates through the PF VSI list and update the loopback
3647 ice_for_each_vsi(pf, v) {
3650 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
3655 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
3656 /* Update the unicast switch filter rules for the corresponding
3657 * switch of the netdev
3659 status = ice_update_sw_rule_bridge_mode(hw);
3661 netdev_err(dev, "update SW_RULE for bridge mode failed, = %d err %d aq_err %d\n",
3662 mode, status, hw->adminq.sq_last_status);
3663 /* revert hw->evb_veb */
3664 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
3668 pf_sw->bridge_mode = mode;
3675 * ice_tx_timeout - Respond to a Tx Hang
3676 * @netdev: network interface device structure
3678 static void ice_tx_timeout(struct net_device *netdev)
3680 struct ice_netdev_priv *np = netdev_priv(netdev);
3681 struct ice_ring *tx_ring = NULL;
3682 struct ice_vsi *vsi = np->vsi;
3683 struct ice_pf *pf = vsi->back;
3684 u32 head, val = 0, i;
3685 int hung_queue = -1;
3687 pf->tx_timeout_count++;
3689 /* find the stopped queue the same way the stack does */
3690 for (i = 0; i < netdev->num_tx_queues; i++) {
3691 struct netdev_queue *q;
3692 unsigned long trans_start;
3694 q = netdev_get_tx_queue(netdev, i);
3695 trans_start = q->trans_start;
3696 if (netif_xmit_stopped(q) &&
3698 (trans_start + netdev->watchdog_timeo))) {
3704 if (i == netdev->num_tx_queues) {
3705 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
3707 /* now that we have an index, find the tx_ring struct */
3708 for (i = 0; i < vsi->num_txq; i++) {
3709 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
3711 vsi->tx_rings[i]->q_index) {
3712 tx_ring = vsi->tx_rings[i];
3719 /* Reset recovery level if enough time has elapsed after last timeout.
3720 * Also ensure no new reset action happens before next timeout period.
3722 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
3723 pf->tx_timeout_recovery_level = 1;
3724 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
3725 netdev->watchdog_timeo)))
3729 head = tx_ring->next_to_clean;
3730 /* Read interrupt register */
3731 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3733 GLINT_DYN_CTL(tx_ring->q_vector->v_idx +
3734 tx_ring->vsi->hw_base_vector));
3736 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
3737 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
3738 head, tx_ring->next_to_use,
3739 readl(tx_ring->tail), val);
3742 pf->tx_timeout_last_recovery = jiffies;
3743 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
3744 pf->tx_timeout_recovery_level, hung_queue);
3746 switch (pf->tx_timeout_recovery_level) {
3748 set_bit(__ICE_PFR_REQ, pf->state);
3751 set_bit(__ICE_CORER_REQ, pf->state);
3754 set_bit(__ICE_GLOBR_REQ, pf->state);
3757 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
3758 set_bit(__ICE_DOWN, pf->state);
3759 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3760 set_bit(__ICE_SERVICE_DIS, pf->state);
3764 ice_service_task_schedule(pf);
3765 pf->tx_timeout_recovery_level++;
3769 * ice_open - Called when a network interface becomes active
3770 * @netdev: network interface device structure
3772 * The open entry point is called when a network interface is made
3773 * active by the system (IFF_UP). At this point all resources needed
3774 * for transmit and receive operations are allocated, the interrupt
3775 * handler is registered with the OS, the netdev watchdog is enabled,
3776 * and the stack is notified that the interface is ready.
3778 * Returns 0 on success, negative value on failure
3780 static int ice_open(struct net_device *netdev)
3782 struct ice_netdev_priv *np = netdev_priv(netdev);
3783 struct ice_vsi *vsi = np->vsi;
3786 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
3787 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
3791 netif_carrier_off(netdev);
3793 err = ice_vsi_open(vsi);
3796 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
3797 vsi->vsi_num, vsi->vsw->sw_id);
3802 * ice_stop - Disables a network interface
3803 * @netdev: network interface device structure
3805 * The stop entry point is called when an interface is de-activated by the OS,
3806 * and the netdevice enters the DOWN state. The hardware is still under the
3807 * driver's control, but the netdev interface is disabled.
3809 * Returns success only - not allowed to fail
3811 static int ice_stop(struct net_device *netdev)
3813 struct ice_netdev_priv *np = netdev_priv(netdev);
3814 struct ice_vsi *vsi = np->vsi;
3822 * ice_features_check - Validate encapsulated packet conforms to limits
3824 * @netdev: This port's netdev
3825 * @features: Offload features that the stack believes apply
3827 static netdev_features_t
3828 ice_features_check(struct sk_buff *skb,
3829 struct net_device __always_unused *netdev,
3830 netdev_features_t features)
3834 /* No point in doing any of this if neither checksum nor GSO are
3835 * being requested for this frame. We can rule out both by just
3836 * checking for CHECKSUM_PARTIAL
3838 if (skb->ip_summed != CHECKSUM_PARTIAL)
3841 /* We cannot support GSO if the MSS is going to be less than
3842 * 64 bytes. If it is then we need to drop support for GSO.
3844 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
3845 features &= ~NETIF_F_GSO_MASK;
3847 len = skb_network_header(skb) - skb->data;
3848 if (len & ~(ICE_TXD_MACLEN_MAX))
3849 goto out_rm_features;
3851 len = skb_transport_header(skb) - skb_network_header(skb);
3852 if (len & ~(ICE_TXD_IPLEN_MAX))
3853 goto out_rm_features;
3855 if (skb->encapsulation) {
3856 len = skb_inner_network_header(skb) - skb_transport_header(skb);
3857 if (len & ~(ICE_TXD_L4LEN_MAX))
3858 goto out_rm_features;
3860 len = skb_inner_transport_header(skb) -
3861 skb_inner_network_header(skb);
3862 if (len & ~(ICE_TXD_IPLEN_MAX))
3863 goto out_rm_features;
3868 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
3871 static const struct net_device_ops ice_netdev_ops = {
3872 .ndo_open = ice_open,
3873 .ndo_stop = ice_stop,
3874 .ndo_start_xmit = ice_start_xmit,
3875 .ndo_features_check = ice_features_check,
3876 .ndo_set_rx_mode = ice_set_rx_mode,
3877 .ndo_set_mac_address = ice_set_mac_address,
3878 .ndo_validate_addr = eth_validate_addr,
3879 .ndo_change_mtu = ice_change_mtu,
3880 .ndo_get_stats64 = ice_get_stats64,
3881 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
3882 .ndo_set_vf_mac = ice_set_vf_mac,
3883 .ndo_get_vf_config = ice_get_vf_cfg,
3884 .ndo_set_vf_trust = ice_set_vf_trust,
3885 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
3886 .ndo_set_vf_link_state = ice_set_vf_link_state,
3887 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
3888 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
3889 .ndo_set_features = ice_set_features,
3890 .ndo_bridge_getlink = ice_bridge_getlink,
3891 .ndo_bridge_setlink = ice_bridge_setlink,
3892 .ndo_fdb_add = ice_fdb_add,
3893 .ndo_fdb_del = ice_fdb_del,
3894 .ndo_tx_timeout = ice_tx_timeout,