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.1-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_watchdog_subtask - periodic tasks not using event driven scheduling
461 * @pf: board private structure
463 static void ice_watchdog_subtask(struct ice_pf *pf)
467 /* if interface is down do nothing */
468 if (test_bit(__ICE_DOWN, pf->state) ||
469 test_bit(__ICE_CFG_BUSY, pf->state))
472 /* make sure we don't do these things too often */
473 if (time_before(jiffies,
474 pf->serv_tmr_prev + pf->serv_tmr_period))
477 pf->serv_tmr_prev = jiffies;
479 /* Update the stats for active netdevs so the network stack
480 * can look at updated numbers whenever it cares to
482 ice_update_pf_stats(pf);
483 for (i = 0; i < pf->num_alloc_vsi; i++)
484 if (pf->vsi[i] && pf->vsi[i]->netdev)
485 ice_update_vsi_stats(pf->vsi[i]);
489 * ice_print_link_msg - print link up or down message
490 * @vsi: the VSI whose link status is being queried
491 * @isup: boolean for if the link is now up or down
493 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
498 if (vsi->current_isup == isup)
501 vsi->current_isup = isup;
504 netdev_info(vsi->netdev, "NIC Link is Down\n");
508 switch (vsi->port_info->phy.link_info.link_speed) {
509 case ICE_AQ_LINK_SPEED_40GB:
512 case ICE_AQ_LINK_SPEED_25GB:
515 case ICE_AQ_LINK_SPEED_20GB:
518 case ICE_AQ_LINK_SPEED_10GB:
521 case ICE_AQ_LINK_SPEED_5GB:
524 case ICE_AQ_LINK_SPEED_2500MB:
527 case ICE_AQ_LINK_SPEED_1000MB:
530 case ICE_AQ_LINK_SPEED_100MB:
538 switch (vsi->port_info->fc.current_mode) {
542 case ICE_FC_TX_PAUSE:
545 case ICE_FC_RX_PAUSE:
553 netdev_info(vsi->netdev, "NIC Link is up %sbps, Flow Control: %s\n",
558 * ice_init_link_events - enable/initialize link events
559 * @pi: pointer to the port_info instance
561 * Returns -EIO on failure, 0 on success
563 static int ice_init_link_events(struct ice_port_info *pi)
567 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
568 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
570 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
571 dev_dbg(ice_hw_to_dev(pi->hw),
572 "Failed to set link event mask for port %d\n",
577 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
578 dev_dbg(ice_hw_to_dev(pi->hw),
579 "Failed to enable link events for port %d\n",
588 * ice_vsi_link_event - update the vsi's netdev
589 * @vsi: the vsi on which the link event occurred
590 * @link_up: whether or not the vsi needs to be set up or down
592 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
594 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
597 if (vsi->type == ICE_VSI_PF) {
599 dev_dbg(&vsi->back->pdev->dev,
600 "vsi->netdev is not initialized!\n");
604 netif_carrier_on(vsi->netdev);
605 netif_tx_wake_all_queues(vsi->netdev);
607 netif_carrier_off(vsi->netdev);
608 netif_tx_stop_all_queues(vsi->netdev);
614 * ice_link_event - process the link event
615 * @pf: pf that the link event is associated with
616 * @pi: port_info for the port that the link event is associated with
618 * Returns -EIO if ice_get_link_status() fails
619 * Returns 0 on success
622 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi)
624 u8 new_link_speed, old_link_speed;
625 struct ice_phy_info *phy_info;
626 bool new_link_same_as_old;
627 bool new_link, old_link;
632 phy_info->link_info_old = phy_info->link_info;
633 /* Force ice_get_link_status() to update link info */
634 phy_info->get_link_info = true;
636 old_link = (phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
637 old_link_speed = phy_info->link_info_old.link_speed;
640 if (ice_get_link_status(pi, &new_link)) {
641 dev_dbg(&pf->pdev->dev,
642 "Could not get link status for port %d\n", lport);
646 new_link_speed = phy_info->link_info.link_speed;
648 new_link_same_as_old = (new_link == old_link &&
649 new_link_speed == old_link_speed);
651 ice_for_each_vsi(pf, v) {
652 struct ice_vsi *vsi = pf->vsi[v];
654 if (!vsi || !vsi->port_info)
657 if (new_link_same_as_old &&
658 (test_bit(__ICE_DOWN, vsi->state) ||
659 new_link == netif_carrier_ok(vsi->netdev)))
662 if (vsi->port_info->lport == lport) {
663 ice_print_link_msg(vsi, new_link);
664 ice_vsi_link_event(vsi, new_link);
672 * ice_handle_link_event - handle link event via ARQ
673 * @pf: pf that the link event is associated with
675 * Return -EINVAL if port_info is null
676 * Return status on succes
678 static int ice_handle_link_event(struct ice_pf *pf)
680 struct ice_port_info *port_info;
683 port_info = pf->hw.port_info;
687 status = ice_link_event(pf, port_info);
689 dev_dbg(&pf->pdev->dev,
690 "Could not process link event, error %d\n", status);
696 * __ice_clean_ctrlq - helper function to clean controlq rings
697 * @pf: ptr to struct ice_pf
698 * @q_type: specific Control queue type
700 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
702 struct ice_rq_event_info event;
703 struct ice_hw *hw = &pf->hw;
704 struct ice_ctl_q_info *cq;
709 /* Do not clean control queue if/when PF reset fails */
710 if (test_bit(__ICE_RESET_FAILED, pf->state))
714 case ICE_CTL_Q_ADMIN:
718 case ICE_CTL_Q_MAILBOX:
723 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
728 /* check for error indications - PF_xx_AxQLEN register layout for
729 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
731 val = rd32(hw, cq->rq.len);
732 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
733 PF_FW_ARQLEN_ARQCRIT_M)) {
735 if (val & PF_FW_ARQLEN_ARQVFE_M)
736 dev_dbg(&pf->pdev->dev,
737 "%s Receive Queue VF Error detected\n", qtype);
738 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
739 dev_dbg(&pf->pdev->dev,
740 "%s Receive Queue Overflow Error detected\n",
743 if (val & PF_FW_ARQLEN_ARQCRIT_M)
744 dev_dbg(&pf->pdev->dev,
745 "%s Receive Queue Critical Error detected\n",
747 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
748 PF_FW_ARQLEN_ARQCRIT_M);
750 wr32(hw, cq->rq.len, val);
753 val = rd32(hw, cq->sq.len);
754 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
755 PF_FW_ATQLEN_ATQCRIT_M)) {
757 if (val & PF_FW_ATQLEN_ATQVFE_M)
758 dev_dbg(&pf->pdev->dev,
759 "%s Send Queue VF Error detected\n", qtype);
760 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
761 dev_dbg(&pf->pdev->dev,
762 "%s Send Queue Overflow Error detected\n",
765 if (val & PF_FW_ATQLEN_ATQCRIT_M)
766 dev_dbg(&pf->pdev->dev,
767 "%s Send Queue Critical Error detected\n",
769 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
770 PF_FW_ATQLEN_ATQCRIT_M);
772 wr32(hw, cq->sq.len, val);
775 event.buf_len = cq->rq_buf_size;
776 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
785 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
786 if (ret == ICE_ERR_AQ_NO_WORK)
789 dev_err(&pf->pdev->dev,
790 "%s Receive Queue event error %d\n", qtype,
795 opcode = le16_to_cpu(event.desc.opcode);
798 case ice_aqc_opc_get_link_status:
799 if (ice_handle_link_event(pf))
800 dev_err(&pf->pdev->dev,
801 "Could not handle link event\n");
803 case ice_aqc_opc_fw_logging:
804 ice_output_fw_log(hw, &event.desc, event.msg_buf);
807 dev_dbg(&pf->pdev->dev,
808 "%s Receive Queue unknown event 0x%04x ignored\n",
812 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
814 devm_kfree(&pf->pdev->dev, event.msg_buf);
816 return pending && (i == ICE_DFLT_IRQ_WORK);
820 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
821 * @hw: pointer to hardware info
822 * @cq: control queue information
824 * returns true if there are pending messages in a queue, false if there aren't
826 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
830 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
831 return cq->rq.next_to_clean != ntu;
835 * ice_clean_adminq_subtask - clean the AdminQ rings
836 * @pf: board private structure
838 static void ice_clean_adminq_subtask(struct ice_pf *pf)
840 struct ice_hw *hw = &pf->hw;
842 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
845 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
848 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
850 /* There might be a situation where new messages arrive to a control
851 * queue between processing the last message and clearing the
852 * EVENT_PENDING bit. So before exiting, check queue head again (using
853 * ice_ctrlq_pending) and process new messages if any.
855 if (ice_ctrlq_pending(hw, &hw->adminq))
856 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
862 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
863 * @pf: board private structure
865 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
867 struct ice_hw *hw = &pf->hw;
869 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
872 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
875 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
877 if (ice_ctrlq_pending(hw, &hw->mailboxq))
878 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
884 * ice_service_task_schedule - schedule the service task to wake up
885 * @pf: board private structure
887 * If not already scheduled, this puts the task into the work queue.
889 static void ice_service_task_schedule(struct ice_pf *pf)
891 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
892 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
893 !test_bit(__ICE_NEEDS_RESTART, pf->state))
894 queue_work(ice_wq, &pf->serv_task);
898 * ice_service_task_complete - finish up the service task
899 * @pf: board private structure
901 static void ice_service_task_complete(struct ice_pf *pf)
903 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
905 /* force memory (pf->state) to sync before next service task */
906 smp_mb__before_atomic();
907 clear_bit(__ICE_SERVICE_SCHED, pf->state);
911 * ice_service_task_stop - stop service task and cancel works
912 * @pf: board private structure
914 static void ice_service_task_stop(struct ice_pf *pf)
916 set_bit(__ICE_SERVICE_DIS, pf->state);
918 if (pf->serv_tmr.function)
919 del_timer_sync(&pf->serv_tmr);
920 if (pf->serv_task.func)
921 cancel_work_sync(&pf->serv_task);
923 clear_bit(__ICE_SERVICE_SCHED, pf->state);
927 * ice_service_timer - timer callback to schedule service task
928 * @t: pointer to timer_list
930 static void ice_service_timer(struct timer_list *t)
932 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
934 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
935 ice_service_task_schedule(pf);
939 * ice_handle_mdd_event - handle malicious driver detect event
940 * @pf: pointer to the PF structure
942 * Called from service task. OICR interrupt handler indicates MDD event
944 static void ice_handle_mdd_event(struct ice_pf *pf)
946 struct ice_hw *hw = &pf->hw;
947 bool mdd_detected = false;
950 if (!test_bit(__ICE_MDD_EVENT_PENDING, pf->state))
953 /* find what triggered the MDD event */
954 reg = rd32(hw, GL_MDET_TX_PQM);
955 if (reg & GL_MDET_TX_PQM_VALID_M) {
956 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
957 GL_MDET_TX_PQM_PF_NUM_S;
958 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
959 GL_MDET_TX_PQM_VF_NUM_S;
960 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
961 GL_MDET_TX_PQM_MAL_TYPE_S;
962 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
963 GL_MDET_TX_PQM_QNUM_S);
965 if (netif_msg_tx_err(pf))
966 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
967 event, queue, pf_num, vf_num);
968 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
972 reg = rd32(hw, GL_MDET_TX_TCLAN);
973 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
974 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
975 GL_MDET_TX_TCLAN_PF_NUM_S;
976 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
977 GL_MDET_TX_TCLAN_VF_NUM_S;
978 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
979 GL_MDET_TX_TCLAN_MAL_TYPE_S;
980 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
981 GL_MDET_TX_TCLAN_QNUM_S);
983 if (netif_msg_rx_err(pf))
984 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
985 event, queue, pf_num, vf_num);
986 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
990 reg = rd32(hw, GL_MDET_RX);
991 if (reg & GL_MDET_RX_VALID_M) {
992 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
994 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
996 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
997 GL_MDET_RX_MAL_TYPE_S;
998 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1001 if (netif_msg_rx_err(pf))
1002 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1003 event, queue, pf_num, vf_num);
1004 wr32(hw, GL_MDET_RX, 0xffffffff);
1005 mdd_detected = true;
1009 bool pf_mdd_detected = false;
1011 reg = rd32(hw, PF_MDET_TX_PQM);
1012 if (reg & PF_MDET_TX_PQM_VALID_M) {
1013 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1014 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1015 pf_mdd_detected = true;
1018 reg = rd32(hw, PF_MDET_TX_TCLAN);
1019 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1020 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1021 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1022 pf_mdd_detected = true;
1025 reg = rd32(hw, PF_MDET_RX);
1026 if (reg & PF_MDET_RX_VALID_M) {
1027 wr32(hw, PF_MDET_RX, 0xFFFF);
1028 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
1029 pf_mdd_detected = true;
1031 /* Queue belongs to the PF initiate a reset */
1032 if (pf_mdd_detected) {
1033 set_bit(__ICE_NEEDS_RESTART, pf->state);
1034 ice_service_task_schedule(pf);
1038 /* re-enable MDD interrupt cause */
1039 clear_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1040 reg = rd32(hw, PFINT_OICR_ENA);
1041 reg |= PFINT_OICR_MAL_DETECT_M;
1042 wr32(hw, PFINT_OICR_ENA, reg);
1047 * ice_service_task - manage and run subtasks
1048 * @work: pointer to work_struct contained by the PF struct
1050 static void ice_service_task(struct work_struct *work)
1052 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1053 unsigned long start_time = jiffies;
1057 /* process reset requests first */
1058 ice_reset_subtask(pf);
1060 /* bail if a reset/recovery cycle is pending or rebuild failed */
1061 if (ice_is_reset_in_progress(pf->state) ||
1062 test_bit(__ICE_SUSPENDED, pf->state) ||
1063 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1064 ice_service_task_complete(pf);
1068 ice_check_for_hang_subtask(pf);
1069 ice_sync_fltr_subtask(pf);
1070 ice_handle_mdd_event(pf);
1071 ice_process_vflr_event(pf);
1072 ice_watchdog_subtask(pf);
1073 ice_clean_adminq_subtask(pf);
1074 ice_clean_mailboxq_subtask(pf);
1076 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1077 ice_service_task_complete(pf);
1079 /* If the tasks have taken longer than one service timer period
1080 * or there is more work to be done, reset the service timer to
1081 * schedule the service task now.
1083 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1084 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1085 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1086 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1087 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1088 mod_timer(&pf->serv_tmr, jiffies);
1092 * ice_set_ctrlq_len - helper function to set controlq length
1093 * @hw: pointer to the hw instance
1095 static void ice_set_ctrlq_len(struct ice_hw *hw)
1097 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1098 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1099 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1100 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1101 hw->mailboxq.num_rq_entries = ICE_MBXQ_LEN;
1102 hw->mailboxq.num_sq_entries = ICE_MBXQ_LEN;
1103 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1104 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1108 * ice_irq_affinity_notify - Callback for affinity changes
1109 * @notify: context as to what irq was changed
1110 * @mask: the new affinity mask
1112 * This is a callback function used by the irq_set_affinity_notifier function
1113 * so that we may register to receive changes to the irq affinity masks.
1115 static void ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1116 const cpumask_t *mask)
1118 struct ice_q_vector *q_vector =
1119 container_of(notify, struct ice_q_vector, affinity_notify);
1121 cpumask_copy(&q_vector->affinity_mask, mask);
1125 * ice_irq_affinity_release - Callback for affinity notifier release
1126 * @ref: internal core kernel usage
1128 * This is a callback function used by the irq_set_affinity_notifier function
1129 * to inform the current notification subscriber that they will no longer
1130 * receive notifications.
1132 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1135 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1136 * @vsi: the VSI being configured
1138 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1140 struct ice_pf *pf = vsi->back;
1141 struct ice_hw *hw = &pf->hw;
1143 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1146 for (i = 0; i < vsi->num_q_vectors; i++)
1147 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1155 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1156 * @vsi: the VSI being configured
1157 * @basename: name for the vector
1159 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1161 int q_vectors = vsi->num_q_vectors;
1162 struct ice_pf *pf = vsi->back;
1163 int base = vsi->sw_base_vector;
1169 for (vector = 0; vector < q_vectors; vector++) {
1170 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1172 irq_num = pf->msix_entries[base + vector].vector;
1174 if (q_vector->tx.ring && q_vector->rx.ring) {
1175 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1176 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1178 } else if (q_vector->rx.ring) {
1179 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1180 "%s-%s-%d", basename, "rx", rx_int_idx++);
1181 } else if (q_vector->tx.ring) {
1182 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1183 "%s-%s-%d", basename, "tx", tx_int_idx++);
1185 /* skip this unused q_vector */
1188 err = devm_request_irq(&pf->pdev->dev,
1189 pf->msix_entries[base + vector].vector,
1190 vsi->irq_handler, 0, q_vector->name,
1193 netdev_err(vsi->netdev,
1194 "MSIX request_irq failed, error: %d\n", err);
1198 /* register for affinity change notifications */
1199 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1200 q_vector->affinity_notify.release = ice_irq_affinity_release;
1201 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1203 /* assign the mask for this irq */
1204 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1207 vsi->irqs_ready = true;
1213 irq_num = pf->msix_entries[base + vector].vector,
1214 irq_set_affinity_notifier(irq_num, NULL);
1215 irq_set_affinity_hint(irq_num, NULL);
1216 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1222 * ice_ena_misc_vector - enable the non-queue interrupts
1223 * @pf: board private structure
1225 static void ice_ena_misc_vector(struct ice_pf *pf)
1227 struct ice_hw *hw = &pf->hw;
1230 /* clear things first */
1231 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1232 rd32(hw, PFINT_OICR); /* read to clear */
1234 val = (PFINT_OICR_ECC_ERR_M |
1235 PFINT_OICR_MAL_DETECT_M |
1237 PFINT_OICR_PCI_EXCEPTION_M |
1239 PFINT_OICR_HMC_ERR_M |
1240 PFINT_OICR_PE_CRITERR_M);
1242 wr32(hw, PFINT_OICR_ENA, val);
1244 /* SW_ITR_IDX = 0, but don't change INTENA */
1245 wr32(hw, GLINT_DYN_CTL(pf->hw_oicr_idx),
1246 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1250 * ice_misc_intr - misc interrupt handler
1251 * @irq: interrupt number
1252 * @data: pointer to a q_vector
1254 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1256 struct ice_pf *pf = (struct ice_pf *)data;
1257 struct ice_hw *hw = &pf->hw;
1258 irqreturn_t ret = IRQ_NONE;
1261 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1262 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1264 oicr = rd32(hw, PFINT_OICR);
1265 ena_mask = rd32(hw, PFINT_OICR_ENA);
1267 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1268 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1269 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1271 if (oicr & PFINT_OICR_VFLR_M) {
1272 ena_mask &= ~PFINT_OICR_VFLR_M;
1273 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1276 if (oicr & PFINT_OICR_GRST_M) {
1279 /* we have a reset warning */
1280 ena_mask &= ~PFINT_OICR_GRST_M;
1281 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1282 GLGEN_RSTAT_RESET_TYPE_S;
1284 if (reset == ICE_RESET_CORER)
1286 else if (reset == ICE_RESET_GLOBR)
1288 else if (reset == ICE_RESET_EMPR)
1291 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1294 /* If a reset cycle isn't already in progress, we set a bit in
1295 * pf->state so that the service task can start a reset/rebuild.
1296 * We also make note of which reset happened so that peer
1297 * devices/drivers can be informed.
1299 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1300 if (reset == ICE_RESET_CORER)
1301 set_bit(__ICE_CORER_RECV, pf->state);
1302 else if (reset == ICE_RESET_GLOBR)
1303 set_bit(__ICE_GLOBR_RECV, pf->state);
1305 set_bit(__ICE_EMPR_RECV, pf->state);
1307 /* There are couple of different bits at play here.
1308 * hw->reset_ongoing indicates whether the hardware is
1309 * in reset. This is set to true when a reset interrupt
1310 * is received and set back to false after the driver
1311 * has determined that the hardware is out of reset.
1313 * __ICE_RESET_OICR_RECV in pf->state indicates
1314 * that a post reset rebuild is required before the
1315 * driver is operational again. This is set above.
1317 * As this is the start of the reset/rebuild cycle, set
1318 * both to indicate that.
1320 hw->reset_ongoing = true;
1324 if (oicr & PFINT_OICR_HMC_ERR_M) {
1325 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1326 dev_dbg(&pf->pdev->dev,
1327 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1328 rd32(hw, PFHMC_ERRORINFO),
1329 rd32(hw, PFHMC_ERRORDATA));
1332 /* Report and mask off any remaining unexpected interrupts */
1335 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1337 /* If a critical error is pending there is no choice but to
1340 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1341 PFINT_OICR_PCI_EXCEPTION_M |
1342 PFINT_OICR_ECC_ERR_M)) {
1343 set_bit(__ICE_PFR_REQ, pf->state);
1344 ice_service_task_schedule(pf);
1350 /* re-enable interrupt causes that are not handled during this pass */
1351 wr32(hw, PFINT_OICR_ENA, ena_mask);
1352 if (!test_bit(__ICE_DOWN, pf->state)) {
1353 ice_service_task_schedule(pf);
1354 ice_irq_dynamic_ena(hw, NULL, NULL);
1361 * ice_free_irq_msix_misc - Unroll misc vector setup
1362 * @pf: board private structure
1364 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1366 /* disable OICR interrupt */
1367 wr32(&pf->hw, PFINT_OICR_ENA, 0);
1370 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
1371 synchronize_irq(pf->msix_entries[pf->sw_oicr_idx].vector);
1372 devm_free_irq(&pf->pdev->dev,
1373 pf->msix_entries[pf->sw_oicr_idx].vector, pf);
1376 pf->num_avail_sw_msix += 1;
1377 ice_free_res(pf->sw_irq_tracker, pf->sw_oicr_idx, ICE_RES_MISC_VEC_ID);
1378 pf->num_avail_hw_msix += 1;
1379 ice_free_res(pf->hw_irq_tracker, pf->hw_oicr_idx, ICE_RES_MISC_VEC_ID);
1383 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1384 * @pf: board private structure
1386 * This sets up the handler for MSIX 0, which is used to manage the
1387 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1388 * when in MSI or Legacy interrupt mode.
1390 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1392 struct ice_hw *hw = &pf->hw;
1393 int oicr_idx, err = 0;
1397 if (!pf->int_name[0])
1398 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1399 dev_driver_string(&pf->pdev->dev),
1400 dev_name(&pf->pdev->dev));
1402 /* Do not request IRQ but do enable OICR interrupt since settings are
1403 * lost during reset. Note that this function is called only during
1404 * rebuild path and not while reset is in progress.
1406 if (ice_is_reset_in_progress(pf->state))
1409 /* reserve one vector in sw_irq_tracker for misc interrupts */
1410 oicr_idx = ice_get_res(pf, pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1414 pf->num_avail_sw_msix -= 1;
1415 pf->sw_oicr_idx = oicr_idx;
1417 /* reserve one vector in hw_irq_tracker for misc interrupts */
1418 oicr_idx = ice_get_res(pf, pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1420 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1421 pf->num_avail_sw_msix += 1;
1424 pf->num_avail_hw_msix -= 1;
1425 pf->hw_oicr_idx = oicr_idx;
1427 err = devm_request_irq(&pf->pdev->dev,
1428 pf->msix_entries[pf->sw_oicr_idx].vector,
1429 ice_misc_intr, 0, pf->int_name, pf);
1431 dev_err(&pf->pdev->dev,
1432 "devm_request_irq for %s failed: %d\n",
1434 ice_free_res(pf->sw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1435 pf->num_avail_sw_msix += 1;
1436 ice_free_res(pf->hw_irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1437 pf->num_avail_hw_msix += 1;
1442 ice_ena_misc_vector(pf);
1444 val = ((pf->hw_oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1445 PFINT_OICR_CTL_CAUSE_ENA_M);
1446 wr32(hw, PFINT_OICR_CTL, val);
1448 /* This enables Admin queue Interrupt causes */
1449 val = ((pf->hw_oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1450 PFINT_FW_CTL_CAUSE_ENA_M);
1451 wr32(hw, PFINT_FW_CTL, val);
1453 /* This enables Mailbox queue Interrupt causes */
1454 val = ((pf->hw_oicr_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1455 PFINT_MBX_CTL_CAUSE_ENA_M);
1456 wr32(hw, PFINT_MBX_CTL, val);
1458 itr_gran = hw->itr_gran;
1460 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->hw_oicr_idx),
1461 ITR_TO_REG(ICE_ITR_8K, itr_gran));
1464 ice_irq_dynamic_ena(hw, NULL, NULL);
1470 * ice_napi_del - Remove NAPI handler for the VSI
1471 * @vsi: VSI for which NAPI handler is to be removed
1473 static void ice_napi_del(struct ice_vsi *vsi)
1480 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1481 netif_napi_del(&vsi->q_vectors[v_idx]->napi);
1485 * ice_napi_add - register NAPI handler for the VSI
1486 * @vsi: VSI for which NAPI handler is to be registered
1488 * This function is only called in the driver's load path. Registering the NAPI
1489 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1490 * reset/rebuild, etc.)
1492 static void ice_napi_add(struct ice_vsi *vsi)
1499 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
1500 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1501 ice_napi_poll, NAPI_POLL_WEIGHT);
1505 * ice_cfg_netdev - Allocate, configure and register a netdev
1506 * @vsi: the VSI associated with the new netdev
1508 * Returns 0 on success, negative value on failure
1510 static int ice_cfg_netdev(struct ice_vsi *vsi)
1512 netdev_features_t csumo_features;
1513 netdev_features_t vlano_features;
1514 netdev_features_t dflt_features;
1515 netdev_features_t tso_features;
1516 struct ice_netdev_priv *np;
1517 struct net_device *netdev;
1518 u8 mac_addr[ETH_ALEN];
1521 netdev = alloc_etherdev_mqs(sizeof(struct ice_netdev_priv),
1522 vsi->alloc_txq, vsi->alloc_rxq);
1526 vsi->netdev = netdev;
1527 np = netdev_priv(netdev);
1530 dflt_features = NETIF_F_SG |
1534 csumo_features = NETIF_F_RXCSUM |
1538 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1539 NETIF_F_HW_VLAN_CTAG_TX |
1540 NETIF_F_HW_VLAN_CTAG_RX;
1542 tso_features = NETIF_F_TSO;
1544 /* set features that user can change */
1545 netdev->hw_features = dflt_features | csumo_features |
1546 vlano_features | tso_features;
1548 /* enable features */
1549 netdev->features |= netdev->hw_features;
1550 /* encap and VLAN devices inherit default, csumo and tso features */
1551 netdev->hw_enc_features |= dflt_features | csumo_features |
1553 netdev->vlan_features |= dflt_features | csumo_features |
1556 if (vsi->type == ICE_VSI_PF) {
1557 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1558 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1560 ether_addr_copy(netdev->dev_addr, mac_addr);
1561 ether_addr_copy(netdev->perm_addr, mac_addr);
1564 netdev->priv_flags |= IFF_UNICAST_FLT;
1566 /* assign netdev_ops */
1567 netdev->netdev_ops = &ice_netdev_ops;
1569 /* setup watchdog timeout value to be 5 second */
1570 netdev->watchdog_timeo = 5 * HZ;
1572 ice_set_ethtool_ops(netdev);
1574 netdev->min_mtu = ETH_MIN_MTU;
1575 netdev->max_mtu = ICE_MAX_MTU;
1577 err = register_netdev(vsi->netdev);
1581 netif_carrier_off(vsi->netdev);
1583 /* make sure transmit queues start off as stopped */
1584 netif_tx_stop_all_queues(vsi->netdev);
1590 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1591 * @lut: Lookup table
1592 * @rss_table_size: Lookup table size
1593 * @rss_size: Range of queue number for hashing
1595 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1599 for (i = 0; i < rss_table_size; i++)
1600 lut[i] = i % rss_size;
1604 * ice_pf_vsi_setup - Set up a PF VSI
1605 * @pf: board private structure
1606 * @pi: pointer to the port_info instance
1608 * Returns pointer to the successfully allocated VSI sw struct on success,
1609 * otherwise returns NULL on failure.
1611 static struct ice_vsi *
1612 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1614 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
1618 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload
1619 * @netdev: network interface to be adjusted
1620 * @proto: unused protocol
1621 * @vid: vlan id to be added
1623 * net_device_ops implementation for adding vlan ids
1625 static int ice_vlan_rx_add_vid(struct net_device *netdev,
1626 __always_unused __be16 proto, u16 vid)
1628 struct ice_netdev_priv *np = netdev_priv(netdev);
1629 struct ice_vsi *vsi = np->vsi;
1632 if (vid >= VLAN_N_VID) {
1633 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
1641 /* Enable VLAN pruning when VLAN 0 is added */
1642 if (unlikely(!vid)) {
1643 ret = ice_cfg_vlan_pruning(vsi, true);
1648 /* Add all VLAN ids including 0 to the switch filter. VLAN id 0 is
1649 * needed to continue allowing all untagged packets since VLAN prune
1650 * list is applied to all packets by the switch
1652 ret = ice_vsi_add_vlan(vsi, vid);
1655 set_bit(vid, vsi->active_vlans);
1661 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
1662 * @netdev: network interface to be adjusted
1663 * @proto: unused protocol
1664 * @vid: vlan id to be removed
1666 * net_device_ops implementation for removing vlan ids
1668 static int ice_vlan_rx_kill_vid(struct net_device *netdev,
1669 __always_unused __be16 proto, u16 vid)
1671 struct ice_netdev_priv *np = netdev_priv(netdev);
1672 struct ice_vsi *vsi = np->vsi;
1678 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
1681 status = ice_vsi_kill_vlan(vsi, vid);
1685 clear_bit(vid, vsi->active_vlans);
1687 /* Disable VLAN pruning when VLAN 0 is removed */
1689 status = ice_cfg_vlan_pruning(vsi, false);
1695 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
1696 * @pf: board private structure
1698 * Returns 0 on success, negative value on failure
1700 static int ice_setup_pf_sw(struct ice_pf *pf)
1702 LIST_HEAD(tmp_add_list);
1703 u8 broadcast[ETH_ALEN];
1704 struct ice_vsi *vsi;
1707 if (ice_is_reset_in_progress(pf->state))
1710 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
1713 goto unroll_vsi_setup;
1716 status = ice_cfg_netdev(vsi);
1719 goto unroll_vsi_setup;
1722 /* registering the NAPI handler requires both the queues and
1723 * netdev to be created, which are done in ice_pf_vsi_setup()
1724 * and ice_cfg_netdev() respectively
1728 /* To add a MAC filter, first add the MAC to a list and then
1729 * pass the list to ice_add_mac.
1732 /* Add a unicast MAC filter so the VSI can get its packets */
1733 status = ice_add_mac_to_list(vsi, &tmp_add_list,
1734 vsi->port_info->mac.perm_addr);
1736 goto unroll_napi_add;
1738 /* VSI needs to receive broadcast traffic, so add the broadcast
1739 * MAC address to the list as well.
1741 eth_broadcast_addr(broadcast);
1742 status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
1746 /* program MAC filters for entries in tmp_add_list */
1747 status = ice_add_mac(&pf->hw, &tmp_add_list);
1749 dev_err(&pf->pdev->dev, "Could not add MAC filters\n");
1754 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1758 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
1764 if (vsi->netdev->reg_state == NETREG_REGISTERED)
1765 unregister_netdev(vsi->netdev);
1766 free_netdev(vsi->netdev);
1773 ice_vsi_free_q_vectors(vsi);
1774 ice_vsi_delete(vsi);
1775 ice_vsi_put_qs(vsi);
1776 pf->q_left_tx += vsi->alloc_txq;
1777 pf->q_left_rx += vsi->alloc_rxq;
1784 * ice_determine_q_usage - Calculate queue distribution
1785 * @pf: board private structure
1787 * Return -ENOMEM if we don't get enough queues for all ports
1789 static void ice_determine_q_usage(struct ice_pf *pf)
1791 u16 q_left_tx, q_left_rx;
1793 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
1794 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
1796 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
1798 /* only 1 rx queue unless RSS is enabled */
1799 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1802 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
1804 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
1805 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
1809 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
1810 * @pf: board private structure to initialize
1812 static void ice_deinit_pf(struct ice_pf *pf)
1814 ice_service_task_stop(pf);
1815 mutex_destroy(&pf->sw_mutex);
1816 mutex_destroy(&pf->avail_q_mutex);
1820 * ice_init_pf - Initialize general software structures (struct ice_pf)
1821 * @pf: board private structure to initialize
1823 static void ice_init_pf(struct ice_pf *pf)
1825 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
1826 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1827 #ifdef CONFIG_PCI_IOV
1828 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
1829 struct ice_hw *hw = &pf->hw;
1831 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
1832 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
1835 #endif /* CONFIG_PCI_IOV */
1837 mutex_init(&pf->sw_mutex);
1838 mutex_init(&pf->avail_q_mutex);
1840 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
1841 mutex_lock(&pf->avail_q_mutex);
1842 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
1843 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
1844 mutex_unlock(&pf->avail_q_mutex);
1846 if (pf->hw.func_caps.common_cap.rss_table_size)
1847 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
1849 /* setup service timer and periodic service task */
1850 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
1851 pf->serv_tmr_period = HZ;
1852 INIT_WORK(&pf->serv_task, ice_service_task);
1853 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1857 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
1858 * @pf: board private structure
1860 * compute the number of MSIX vectors required (v_budget) and request from
1861 * the OS. Return the number of vectors reserved or negative on failure
1863 static int ice_ena_msix_range(struct ice_pf *pf)
1865 int v_left, v_actual, v_budget = 0;
1868 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
1870 /* reserve one vector for miscellaneous handler */
1875 /* reserve vectors for LAN traffic */
1876 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
1877 v_budget += pf->num_lan_msix;
1878 v_left -= pf->num_lan_msix;
1880 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
1881 sizeof(struct msix_entry), GFP_KERNEL);
1883 if (!pf->msix_entries) {
1888 for (i = 0; i < v_budget; i++)
1889 pf->msix_entries[i].entry = i;
1891 /* actually reserve the vectors */
1892 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
1893 ICE_MIN_MSIX, v_budget);
1896 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
1901 if (v_actual < v_budget) {
1902 dev_warn(&pf->pdev->dev,
1903 "not enough vectors. requested = %d, obtained = %d\n",
1904 v_budget, v_actual);
1905 if (v_actual >= (pf->num_lan_msix + 1)) {
1906 pf->num_avail_sw_msix = v_actual -
1907 (pf->num_lan_msix + 1);
1908 } else if (v_actual >= 2) {
1909 pf->num_lan_msix = 1;
1910 pf->num_avail_sw_msix = v_actual - 2;
1912 pci_disable_msix(pf->pdev);
1921 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1925 pf->num_lan_msix = 0;
1926 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1931 * ice_dis_msix - Disable MSI-X interrupt setup in OS
1932 * @pf: board private structure
1934 static void ice_dis_msix(struct ice_pf *pf)
1936 pci_disable_msix(pf->pdev);
1937 devm_kfree(&pf->pdev->dev, pf->msix_entries);
1938 pf->msix_entries = NULL;
1939 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
1943 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
1944 * @pf: board private structure
1946 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
1948 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1951 if (pf->sw_irq_tracker) {
1952 devm_kfree(&pf->pdev->dev, pf->sw_irq_tracker);
1953 pf->sw_irq_tracker = NULL;
1956 if (pf->hw_irq_tracker) {
1957 devm_kfree(&pf->pdev->dev, pf->hw_irq_tracker);
1958 pf->hw_irq_tracker = NULL;
1963 * ice_init_interrupt_scheme - Determine proper interrupt scheme
1964 * @pf: board private structure to initialize
1966 static int ice_init_interrupt_scheme(struct ice_pf *pf)
1968 int vectors = 0, hw_vectors = 0;
1971 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
1972 vectors = ice_ena_msix_range(pf);
1979 /* set up vector assignment tracking */
1980 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * vectors);
1982 pf->sw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1983 if (!pf->sw_irq_tracker) {
1988 /* populate SW interrupts pool with number of OS granted IRQs. */
1989 pf->num_avail_sw_msix = vectors;
1990 pf->sw_irq_tracker->num_entries = vectors;
1992 /* set up HW vector assignment tracking */
1993 hw_vectors = pf->hw.func_caps.common_cap.num_msix_vectors;
1994 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * hw_vectors);
1996 pf->hw_irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
1997 if (!pf->hw_irq_tracker) {
1998 ice_clear_interrupt_scheme(pf);
2002 /* populate HW interrupts pool with number of HW supported irqs. */
2003 pf->num_avail_hw_msix = hw_vectors;
2004 pf->hw_irq_tracker->num_entries = hw_vectors;
2010 * ice_probe - Device initialization routine
2011 * @pdev: PCI device information struct
2012 * @ent: entry in ice_pci_tbl
2014 * Returns 0 on success, negative on failure
2016 static int ice_probe(struct pci_dev *pdev,
2017 const struct pci_device_id __always_unused *ent)
2023 /* this driver uses devres, see Documentation/driver-model/devres.txt */
2024 err = pcim_enable_device(pdev);
2028 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2030 dev_err(&pdev->dev, "BAR0 I/O map error %d\n", err);
2034 pf = devm_kzalloc(&pdev->dev, sizeof(*pf), GFP_KERNEL);
2038 /* set up for high or low dma */
2039 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
2041 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
2043 dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
2047 pci_enable_pcie_error_reporting(pdev);
2048 pci_set_master(pdev);
2051 pci_set_drvdata(pdev, pf);
2052 set_bit(__ICE_DOWN, pf->state);
2053 /* Disable service task until DOWN bit is cleared */
2054 set_bit(__ICE_SERVICE_DIS, pf->state);
2057 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2059 hw->vendor_id = pdev->vendor;
2060 hw->device_id = pdev->device;
2061 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2062 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2063 hw->subsystem_device_id = pdev->subsystem_device;
2064 hw->bus.device = PCI_SLOT(pdev->devfn);
2065 hw->bus.func = PCI_FUNC(pdev->devfn);
2066 ice_set_ctrlq_len(hw);
2068 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2070 #ifndef CONFIG_DYNAMIC_DEBUG
2072 hw->debug_mask = debug;
2075 err = ice_init_hw(hw);
2077 dev_err(&pdev->dev, "ice_init_hw failed: %d\n", err);
2079 goto err_exit_unroll;
2082 dev_info(&pdev->dev, "firmware %d.%d.%05d api %d.%d\n",
2083 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2084 hw->api_maj_ver, hw->api_min_ver);
2088 ice_determine_q_usage(pf);
2090 pf->num_alloc_vsi = min_t(u16, ICE_MAX_VSI_ALLOC,
2091 hw->func_caps.guaranteed_num_vsi);
2092 if (!pf->num_alloc_vsi) {
2094 goto err_init_pf_unroll;
2097 pf->vsi = devm_kcalloc(&pdev->dev, pf->num_alloc_vsi,
2098 sizeof(struct ice_vsi *), GFP_KERNEL);
2101 goto err_init_pf_unroll;
2104 err = ice_init_interrupt_scheme(pf);
2107 "ice_init_interrupt_scheme failed: %d\n", err);
2109 goto err_init_interrupt_unroll;
2112 /* Driver is mostly up */
2113 clear_bit(__ICE_DOWN, pf->state);
2115 /* In case of MSIX we are going to setup the misc vector right here
2116 * to handle admin queue events etc. In case of legacy and MSI
2117 * the misc functionality and queue processing is combined in
2118 * the same vector and that gets setup at open.
2120 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2121 err = ice_req_irq_msix_misc(pf);
2124 "setup of misc vector failed: %d\n", err);
2125 goto err_init_interrupt_unroll;
2129 /* create switch struct for the switch element created by FW on boot */
2130 pf->first_sw = devm_kzalloc(&pdev->dev, sizeof(struct ice_sw),
2132 if (!pf->first_sw) {
2134 goto err_msix_misc_unroll;
2138 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2140 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2142 pf->first_sw->pf = pf;
2144 /* record the sw_id available for later use */
2145 pf->first_sw->sw_id = hw->port_info->sw_id;
2147 err = ice_setup_pf_sw(pf);
2150 "probe failed due to setup pf switch:%d\n", err);
2151 goto err_alloc_sw_unroll;
2154 clear_bit(__ICE_SERVICE_DIS, pf->state);
2156 /* since everything is good, start the service timer */
2157 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2159 err = ice_init_link_events(pf->hw.port_info);
2161 dev_err(&pdev->dev, "ice_init_link_events failed: %d\n", err);
2162 goto err_alloc_sw_unroll;
2167 err_alloc_sw_unroll:
2168 set_bit(__ICE_SERVICE_DIS, pf->state);
2169 set_bit(__ICE_DOWN, pf->state);
2170 devm_kfree(&pf->pdev->dev, pf->first_sw);
2171 err_msix_misc_unroll:
2172 ice_free_irq_msix_misc(pf);
2173 err_init_interrupt_unroll:
2174 ice_clear_interrupt_scheme(pf);
2175 devm_kfree(&pdev->dev, pf->vsi);
2180 pci_disable_pcie_error_reporting(pdev);
2185 * ice_remove - Device removal routine
2186 * @pdev: PCI device information struct
2188 static void ice_remove(struct pci_dev *pdev)
2190 struct ice_pf *pf = pci_get_drvdata(pdev);
2196 set_bit(__ICE_DOWN, pf->state);
2197 ice_service_task_stop(pf);
2199 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2201 ice_vsi_release_all(pf);
2202 ice_free_irq_msix_misc(pf);
2203 ice_for_each_vsi(pf, i) {
2206 ice_vsi_free_q_vectors(pf->vsi[i]);
2208 ice_clear_interrupt_scheme(pf);
2210 ice_deinit_hw(&pf->hw);
2211 pci_disable_pcie_error_reporting(pdev);
2214 /* ice_pci_tbl - PCI Device ID Table
2216 * Wildcard entries (PCI_ANY_ID) should come last
2217 * Last entry must be all 0s
2219 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2220 * Class, Class Mask, private data (not used) }
2222 static const struct pci_device_id ice_pci_tbl[] = {
2223 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_BACKPLANE), 0 },
2224 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_QSFP), 0 },
2225 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_SFP), 0 },
2226 /* required last entry */
2229 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2231 static struct pci_driver ice_driver = {
2232 .name = KBUILD_MODNAME,
2233 .id_table = ice_pci_tbl,
2235 .remove = ice_remove,
2236 .sriov_configure = ice_sriov_configure,
2240 * ice_module_init - Driver registration routine
2242 * ice_module_init is the first routine called when the driver is
2243 * loaded. All it does is register with the PCI subsystem.
2245 static int __init ice_module_init(void)
2249 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2250 pr_info("%s\n", ice_copyright);
2252 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2254 pr_err("Failed to create workqueue\n");
2258 status = pci_register_driver(&ice_driver);
2260 pr_err("failed to register pci driver, err %d\n", status);
2261 destroy_workqueue(ice_wq);
2266 module_init(ice_module_init);
2269 * ice_module_exit - Driver exit cleanup routine
2271 * ice_module_exit is called just before the driver is removed
2274 static void __exit ice_module_exit(void)
2276 pci_unregister_driver(&ice_driver);
2277 destroy_workqueue(ice_wq);
2278 pr_info("module unloaded\n");
2280 module_exit(ice_module_exit);
2283 * ice_set_mac_address - NDO callback to set mac address
2284 * @netdev: network interface device structure
2285 * @pi: pointer to an address structure
2287 * Returns 0 on success, negative on failure
2289 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2291 struct ice_netdev_priv *np = netdev_priv(netdev);
2292 struct ice_vsi *vsi = np->vsi;
2293 struct ice_pf *pf = vsi->back;
2294 struct ice_hw *hw = &pf->hw;
2295 struct sockaddr *addr = pi;
2296 enum ice_status status;
2297 LIST_HEAD(a_mac_list);
2298 LIST_HEAD(r_mac_list);
2303 mac = (u8 *)addr->sa_data;
2305 if (!is_valid_ether_addr(mac))
2306 return -EADDRNOTAVAIL;
2308 if (ether_addr_equal(netdev->dev_addr, mac)) {
2309 netdev_warn(netdev, "already using mac %pM\n", mac);
2313 if (test_bit(__ICE_DOWN, pf->state) ||
2314 ice_is_reset_in_progress(pf->state)) {
2315 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2320 /* When we change the mac address we also have to change the mac address
2321 * based filter rules that were created previously for the old mac
2322 * address. So first, we remove the old filter rule using ice_remove_mac
2323 * and then create a new filter rule using ice_add_mac. Note that for
2324 * both these operations, we first need to form a "list" of mac
2325 * addresses (even though in this case, we have only 1 mac address to be
2326 * added/removed) and this done using ice_add_mac_to_list. Depending on
2327 * the ensuing operation this "list" of mac addresses is either to be
2328 * added or removed from the filter.
2330 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
2332 err = -EADDRNOTAVAIL;
2336 status = ice_remove_mac(hw, &r_mac_list);
2338 err = -EADDRNOTAVAIL;
2342 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
2344 err = -EADDRNOTAVAIL;
2348 status = ice_add_mac(hw, &a_mac_list);
2350 err = -EADDRNOTAVAIL;
2355 /* free list entries */
2356 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
2357 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
2360 netdev_err(netdev, "can't set mac %pM. filter update failed\n",
2365 /* change the netdev's mac address */
2366 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2367 netdev_dbg(vsi->netdev, "updated mac address to %pM\n",
2370 /* write new mac address to the firmware */
2371 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2372 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2374 netdev_err(netdev, "can't set mac %pM. write to firmware failed.\n",
2381 * ice_set_rx_mode - NDO callback to set the netdev filters
2382 * @netdev: network interface device structure
2384 static void ice_set_rx_mode(struct net_device *netdev)
2386 struct ice_netdev_priv *np = netdev_priv(netdev);
2387 struct ice_vsi *vsi = np->vsi;
2392 /* Set the flags to synchronize filters
2393 * ndo_set_rx_mode may be triggered even without a change in netdev
2396 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2397 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2398 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2400 /* schedule our worker thread which will take care of
2401 * applying the new filter changes
2403 ice_service_task_schedule(vsi->back);
2407 * ice_fdb_add - add an entry to the hardware database
2408 * @ndm: the input from the stack
2409 * @tb: pointer to array of nladdr (unused)
2410 * @dev: the net device pointer
2411 * @addr: the MAC address entry being added
2413 * @flags: instructions from stack about fdb operation
2415 static int ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2416 struct net_device *dev, const unsigned char *addr,
2422 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2425 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2426 netdev_err(dev, "FDB only supports static addresses\n");
2430 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2431 err = dev_uc_add_excl(dev, addr);
2432 else if (is_multicast_ether_addr(addr))
2433 err = dev_mc_add_excl(dev, addr);
2437 /* Only return duplicate errors if NLM_F_EXCL is set */
2438 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2445 * ice_fdb_del - delete an entry from the hardware database
2446 * @ndm: the input from the stack
2447 * @tb: pointer to array of nladdr (unused)
2448 * @dev: the net device pointer
2449 * @addr: the MAC address entry being added
2452 static int ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2453 struct net_device *dev, const unsigned char *addr,
2454 __always_unused u16 vid)
2458 if (ndm->ndm_state & NUD_PERMANENT) {
2459 netdev_err(dev, "FDB only supports static addresses\n");
2463 if (is_unicast_ether_addr(addr))
2464 err = dev_uc_del(dev, addr);
2465 else if (is_multicast_ether_addr(addr))
2466 err = dev_mc_del(dev, addr);
2474 * ice_set_features - set the netdev feature flags
2475 * @netdev: ptr to the netdev being adjusted
2476 * @features: the feature set that the stack is suggesting
2478 static int ice_set_features(struct net_device *netdev,
2479 netdev_features_t features)
2481 struct ice_netdev_priv *np = netdev_priv(netdev);
2482 struct ice_vsi *vsi = np->vsi;
2485 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
2486 ret = ice_vsi_manage_rss_lut(vsi, true);
2487 else if (!(features & NETIF_F_RXHASH) &&
2488 netdev->features & NETIF_F_RXHASH)
2489 ret = ice_vsi_manage_rss_lut(vsi, false);
2491 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
2492 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2493 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2494 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
2495 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2496 ret = ice_vsi_manage_vlan_stripping(vsi, false);
2497 else if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
2498 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2499 ret = ice_vsi_manage_vlan_insertion(vsi);
2500 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
2501 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2502 ret = ice_vsi_manage_vlan_insertion(vsi);
2508 * ice_vsi_vlan_setup - Setup vlan offload properties on a VSI
2509 * @vsi: VSI to setup vlan properties for
2511 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
2515 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2516 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2517 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
2518 ret = ice_vsi_manage_vlan_insertion(vsi);
2524 * ice_restore_vlan - Reinstate VLANs when vsi/netdev comes back up
2525 * @vsi: the VSI being brought back up
2527 static int ice_restore_vlan(struct ice_vsi *vsi)
2535 err = ice_vsi_vlan_setup(vsi);
2539 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) {
2540 err = ice_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), vid);
2549 * ice_vsi_cfg - Setup the VSI
2550 * @vsi: the VSI being configured
2552 * Return 0 on success and negative value on error
2554 static int ice_vsi_cfg(struct ice_vsi *vsi)
2559 ice_set_rx_mode(vsi->netdev);
2560 err = ice_restore_vlan(vsi);
2565 err = ice_vsi_cfg_txqs(vsi);
2567 err = ice_vsi_cfg_rxqs(vsi);
2573 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
2574 * @vsi: the VSI being configured
2576 static void ice_napi_enable_all(struct ice_vsi *vsi)
2583 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
2584 napi_enable(&vsi->q_vectors[q_idx]->napi);
2588 * ice_up_complete - Finish the last steps of bringing up a connection
2589 * @vsi: The VSI being configured
2591 * Return 0 on success and negative value on error
2593 static int ice_up_complete(struct ice_vsi *vsi)
2595 struct ice_pf *pf = vsi->back;
2598 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2599 ice_vsi_cfg_msix(vsi);
2603 /* Enable only Rx rings, Tx rings were enabled by the FW when the
2604 * Tx queue group list was configured and the context bits were
2605 * programmed using ice_vsi_cfg_txqs
2607 err = ice_vsi_start_rx_rings(vsi);
2611 clear_bit(__ICE_DOWN, vsi->state);
2612 ice_napi_enable_all(vsi);
2613 ice_vsi_ena_irq(vsi);
2615 if (vsi->port_info &&
2616 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
2618 ice_print_link_msg(vsi, true);
2619 netif_tx_start_all_queues(vsi->netdev);
2620 netif_carrier_on(vsi->netdev);
2623 ice_service_task_schedule(pf);
2629 * ice_up - Bring the connection back up after being down
2630 * @vsi: VSI being configured
2632 int ice_up(struct ice_vsi *vsi)
2636 err = ice_vsi_cfg(vsi);
2638 err = ice_up_complete(vsi);
2644 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
2645 * @ring: Tx or Rx ring to read stats from
2646 * @pkts: packets stats counter
2647 * @bytes: bytes stats counter
2649 * This function fetches stats from the ring considering the atomic operations
2650 * that needs to be performed to read u64 values in 32 bit machine.
2652 static void ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts,
2662 start = u64_stats_fetch_begin_irq(&ring->syncp);
2663 *pkts = ring->stats.pkts;
2664 *bytes = ring->stats.bytes;
2665 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
2669 * ice_update_vsi_ring_stats - Update VSI stats counters
2670 * @vsi: the VSI to be updated
2672 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
2674 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
2675 struct ice_ring *ring;
2679 /* reset netdev stats */
2680 vsi_stats->tx_packets = 0;
2681 vsi_stats->tx_bytes = 0;
2682 vsi_stats->rx_packets = 0;
2683 vsi_stats->rx_bytes = 0;
2685 /* reset non-netdev (extended) stats */
2686 vsi->tx_restart = 0;
2688 vsi->tx_linearize = 0;
2689 vsi->rx_buf_failed = 0;
2690 vsi->rx_page_failed = 0;
2694 /* update Tx rings counters */
2695 ice_for_each_txq(vsi, i) {
2696 ring = READ_ONCE(vsi->tx_rings[i]);
2697 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2698 vsi_stats->tx_packets += pkts;
2699 vsi_stats->tx_bytes += bytes;
2700 vsi->tx_restart += ring->tx_stats.restart_q;
2701 vsi->tx_busy += ring->tx_stats.tx_busy;
2702 vsi->tx_linearize += ring->tx_stats.tx_linearize;
2705 /* update Rx rings counters */
2706 ice_for_each_rxq(vsi, i) {
2707 ring = READ_ONCE(vsi->rx_rings[i]);
2708 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
2709 vsi_stats->rx_packets += pkts;
2710 vsi_stats->rx_bytes += bytes;
2711 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
2712 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
2719 * ice_update_vsi_stats - Update VSI stats counters
2720 * @vsi: the VSI to be updated
2722 static void ice_update_vsi_stats(struct ice_vsi *vsi)
2724 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
2725 struct ice_eth_stats *cur_es = &vsi->eth_stats;
2726 struct ice_pf *pf = vsi->back;
2728 if (test_bit(__ICE_DOWN, vsi->state) ||
2729 test_bit(__ICE_CFG_BUSY, pf->state))
2732 /* get stats as recorded by Tx/Rx rings */
2733 ice_update_vsi_ring_stats(vsi);
2735 /* get VSI stats as recorded by the hardware */
2736 ice_update_eth_stats(vsi);
2738 cur_ns->tx_errors = cur_es->tx_errors;
2739 cur_ns->rx_dropped = cur_es->rx_discards;
2740 cur_ns->tx_dropped = cur_es->tx_discards;
2741 cur_ns->multicast = cur_es->rx_multicast;
2743 /* update some more netdev stats if this is main VSI */
2744 if (vsi->type == ICE_VSI_PF) {
2745 cur_ns->rx_crc_errors = pf->stats.crc_errors;
2746 cur_ns->rx_errors = pf->stats.crc_errors +
2747 pf->stats.illegal_bytes;
2748 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
2753 * ice_update_pf_stats - Update PF port stats counters
2754 * @pf: PF whose stats needs to be updated
2756 static void ice_update_pf_stats(struct ice_pf *pf)
2758 struct ice_hw_port_stats *prev_ps, *cur_ps;
2759 struct ice_hw *hw = &pf->hw;
2762 prev_ps = &pf->stats_prev;
2763 cur_ps = &pf->stats;
2766 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
2767 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
2768 &cur_ps->eth.rx_bytes);
2770 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
2771 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
2772 &cur_ps->eth.rx_unicast);
2774 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
2775 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
2776 &cur_ps->eth.rx_multicast);
2778 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
2779 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
2780 &cur_ps->eth.rx_broadcast);
2782 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
2783 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
2784 &cur_ps->eth.tx_bytes);
2786 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
2787 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
2788 &cur_ps->eth.tx_unicast);
2790 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
2791 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
2792 &cur_ps->eth.tx_multicast);
2794 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
2795 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
2796 &cur_ps->eth.tx_broadcast);
2798 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
2799 &prev_ps->tx_dropped_link_down,
2800 &cur_ps->tx_dropped_link_down);
2802 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
2803 pf->stat_prev_loaded, &prev_ps->rx_size_64,
2804 &cur_ps->rx_size_64);
2806 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
2807 pf->stat_prev_loaded, &prev_ps->rx_size_127,
2808 &cur_ps->rx_size_127);
2810 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
2811 pf->stat_prev_loaded, &prev_ps->rx_size_255,
2812 &cur_ps->rx_size_255);
2814 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
2815 pf->stat_prev_loaded, &prev_ps->rx_size_511,
2816 &cur_ps->rx_size_511);
2818 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
2819 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
2820 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
2822 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
2823 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
2824 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
2826 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
2827 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
2828 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
2830 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
2831 pf->stat_prev_loaded, &prev_ps->tx_size_64,
2832 &cur_ps->tx_size_64);
2834 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
2835 pf->stat_prev_loaded, &prev_ps->tx_size_127,
2836 &cur_ps->tx_size_127);
2838 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
2839 pf->stat_prev_loaded, &prev_ps->tx_size_255,
2840 &cur_ps->tx_size_255);
2842 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
2843 pf->stat_prev_loaded, &prev_ps->tx_size_511,
2844 &cur_ps->tx_size_511);
2846 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
2847 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
2848 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
2850 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
2851 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
2852 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
2854 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
2855 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
2856 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
2858 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
2859 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
2861 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
2862 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
2864 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
2865 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
2867 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
2868 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
2870 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
2871 &prev_ps->crc_errors, &cur_ps->crc_errors);
2873 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
2874 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
2876 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
2877 &prev_ps->mac_local_faults,
2878 &cur_ps->mac_local_faults);
2880 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
2881 &prev_ps->mac_remote_faults,
2882 &cur_ps->mac_remote_faults);
2884 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
2885 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
2887 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
2888 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
2890 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
2891 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
2893 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
2894 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
2896 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
2897 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
2899 pf->stat_prev_loaded = true;
2903 * ice_get_stats64 - get statistics for network device structure
2904 * @netdev: network interface device structure
2905 * @stats: main device statistics structure
2908 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
2910 struct ice_netdev_priv *np = netdev_priv(netdev);
2911 struct rtnl_link_stats64 *vsi_stats;
2912 struct ice_vsi *vsi = np->vsi;
2914 vsi_stats = &vsi->net_stats;
2916 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
2918 /* netdev packet/byte stats come from ring counter. These are obtained
2919 * by summing up ring counters (done by ice_update_vsi_ring_stats).
2921 ice_update_vsi_ring_stats(vsi);
2922 stats->tx_packets = vsi_stats->tx_packets;
2923 stats->tx_bytes = vsi_stats->tx_bytes;
2924 stats->rx_packets = vsi_stats->rx_packets;
2925 stats->rx_bytes = vsi_stats->rx_bytes;
2927 /* The rest of the stats can be read from the hardware but instead we
2928 * just return values that the watchdog task has already obtained from
2931 stats->multicast = vsi_stats->multicast;
2932 stats->tx_errors = vsi_stats->tx_errors;
2933 stats->tx_dropped = vsi_stats->tx_dropped;
2934 stats->rx_errors = vsi_stats->rx_errors;
2935 stats->rx_dropped = vsi_stats->rx_dropped;
2936 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
2937 stats->rx_length_errors = vsi_stats->rx_length_errors;
2941 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
2942 * @vsi: VSI having NAPI disabled
2944 static void ice_napi_disable_all(struct ice_vsi *vsi)
2951 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
2952 napi_disable(&vsi->q_vectors[q_idx]->napi);
2956 * ice_down - Shutdown the connection
2957 * @vsi: The VSI being stopped
2959 int ice_down(struct ice_vsi *vsi)
2961 int i, tx_err, rx_err;
2963 /* Caller of this function is expected to set the
2964 * vsi->state __ICE_DOWN bit
2967 netif_carrier_off(vsi->netdev);
2968 netif_tx_disable(vsi->netdev);
2971 ice_vsi_dis_irq(vsi);
2972 tx_err = ice_vsi_stop_tx_rings(vsi, ICE_NO_RESET, 0);
2974 netdev_err(vsi->netdev,
2975 "Failed stop Tx rings, VSI %d error %d\n",
2976 vsi->vsi_num, tx_err);
2978 rx_err = ice_vsi_stop_rx_rings(vsi);
2980 netdev_err(vsi->netdev,
2981 "Failed stop Rx rings, VSI %d error %d\n",
2982 vsi->vsi_num, rx_err);
2984 ice_napi_disable_all(vsi);
2986 ice_for_each_txq(vsi, i)
2987 ice_clean_tx_ring(vsi->tx_rings[i]);
2989 ice_for_each_rxq(vsi, i)
2990 ice_clean_rx_ring(vsi->rx_rings[i]);
2992 if (tx_err || rx_err) {
2993 netdev_err(vsi->netdev,
2994 "Failed to close VSI 0x%04X on switch 0x%04X\n",
2995 vsi->vsi_num, vsi->vsw->sw_id);
3003 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
3004 * @vsi: VSI having resources allocated
3006 * Return 0 on success, negative on failure
3008 static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3012 if (!vsi->num_txq) {
3013 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3018 ice_for_each_txq(vsi, i) {
3019 vsi->tx_rings[i]->netdev = vsi->netdev;
3020 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3029 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3030 * @vsi: VSI having resources allocated
3032 * Return 0 on success, negative on failure
3034 static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3038 if (!vsi->num_rxq) {
3039 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3044 ice_for_each_rxq(vsi, i) {
3045 vsi->rx_rings[i]->netdev = vsi->netdev;
3046 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3055 * ice_vsi_req_irq - Request IRQ from the OS
3056 * @vsi: The VSI IRQ is being requested for
3057 * @basename: name for the vector
3059 * Return 0 on success and a negative value on error
3061 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
3063 struct ice_pf *pf = vsi->back;
3066 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3067 err = ice_vsi_req_irq_msix(vsi, basename);
3073 * ice_vsi_open - Called when a network interface is made active
3074 * @vsi: the VSI to open
3076 * Initialization of the VSI
3078 * Returns 0 on success, negative value on error
3080 static int ice_vsi_open(struct ice_vsi *vsi)
3082 char int_name[ICE_INT_NAME_STR_LEN];
3083 struct ice_pf *pf = vsi->back;
3086 /* allocate descriptors */
3087 err = ice_vsi_setup_tx_rings(vsi);
3091 err = ice_vsi_setup_rx_rings(vsi);
3095 err = ice_vsi_cfg(vsi);
3099 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3100 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3101 err = ice_vsi_req_irq(vsi, int_name);
3105 /* Notify the stack of the actual queue counts. */
3106 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3110 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3114 err = ice_up_complete(vsi);
3116 goto err_up_complete;
3123 ice_vsi_free_irq(vsi);
3125 ice_vsi_free_rx_rings(vsi);
3127 ice_vsi_free_tx_rings(vsi);
3133 * ice_vsi_release_all - Delete all VSIs
3134 * @pf: PF from which all VSIs are being removed
3136 static void ice_vsi_release_all(struct ice_pf *pf)
3143 for (i = 0; i < pf->num_alloc_vsi; i++) {
3147 err = ice_vsi_release(pf->vsi[i]);
3149 dev_dbg(&pf->pdev->dev,
3150 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3151 i, err, pf->vsi[i]->vsi_num);
3156 * ice_dis_vsi - pause a VSI
3157 * @vsi: the VSI being paused
3159 static void ice_dis_vsi(struct ice_vsi *vsi)
3161 if (test_bit(__ICE_DOWN, vsi->state))
3164 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3166 if (vsi->netdev && netif_running(vsi->netdev) &&
3167 vsi->type == ICE_VSI_PF) {
3169 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
3177 * ice_ena_vsi - resume a VSI
3178 * @vsi: the VSI being resume
3180 static int ice_ena_vsi(struct ice_vsi *vsi)
3184 if (test_and_clear_bit(__ICE_NEEDS_RESTART, vsi->state))
3185 if (vsi->netdev && netif_running(vsi->netdev)) {
3187 err = vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
3195 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
3198 static void ice_pf_dis_all_vsi(struct ice_pf *pf)
3202 ice_for_each_vsi(pf, v)
3204 ice_dis_vsi(pf->vsi[v]);
3208 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3211 static int ice_pf_ena_all_vsi(struct ice_pf *pf)
3215 ice_for_each_vsi(pf, v)
3217 if (ice_ena_vsi(pf->vsi[v]))
3224 * ice_vsi_rebuild_all - rebuild all VSIs in pf
3227 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3231 /* loop through pf->vsi array and reinit the VSI if found */
3232 for (i = 0; i < pf->num_alloc_vsi; i++) {
3238 /* VF VSI rebuild isn't supported yet */
3239 if (pf->vsi[i]->type == ICE_VSI_VF)
3242 err = ice_vsi_rebuild(pf->vsi[i]);
3244 dev_err(&pf->pdev->dev,
3245 "VSI at index %d rebuild failed\n",
3250 dev_info(&pf->pdev->dev,
3251 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3252 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3259 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3262 static int ice_vsi_replay_all(struct ice_pf *pf)
3264 struct ice_hw *hw = &pf->hw;
3265 enum ice_status ret;
3268 /* loop through pf->vsi array and replay the VSI if found */
3269 for (i = 0; i < pf->num_alloc_vsi; i++) {
3273 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3275 dev_err(&pf->pdev->dev,
3276 "VSI at index %d replay failed %d\n",
3277 pf->vsi[i]->idx, ret);
3281 /* Re-map HW VSI number, using VSI handle that has been
3282 * previously validated in ice_replay_vsi() call above
3284 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3286 dev_info(&pf->pdev->dev,
3287 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3288 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3291 /* Clean up replay filter after successful re-configuration */
3292 ice_replay_post(hw);
3297 * ice_rebuild - rebuild after reset
3298 * @pf: pf to rebuild
3300 static void ice_rebuild(struct ice_pf *pf)
3302 struct device *dev = &pf->pdev->dev;
3303 struct ice_hw *hw = &pf->hw;
3304 enum ice_status ret;
3307 if (test_bit(__ICE_DOWN, pf->state))
3308 goto clear_recovery;
3310 dev_dbg(dev, "rebuilding pf\n");
3312 ret = ice_init_all_ctrlq(hw);
3314 dev_err(dev, "control queues init failed %d\n", ret);
3315 goto err_init_ctrlq;
3318 ret = ice_clear_pf_cfg(hw);
3320 dev_err(dev, "clear PF configuration failed %d\n", ret);
3321 goto err_init_ctrlq;
3324 ice_clear_pxe_mode(hw);
3326 ret = ice_get_caps(hw);
3328 dev_err(dev, "ice_get_caps failed %d\n", ret);
3329 goto err_init_ctrlq;
3332 err = ice_sched_init_port(hw->port_info);
3334 goto err_sched_init_port;
3336 /* reset search_hint of irq_trackers to 0 since interrupts are
3337 * reclaimed and could be allocated from beginning during VSI rebuild
3339 pf->sw_irq_tracker->search_hint = 0;
3340 pf->hw_irq_tracker->search_hint = 0;
3342 err = ice_vsi_rebuild_all(pf);
3344 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3345 goto err_vsi_rebuild;
3348 err = ice_update_link_info(hw->port_info);
3350 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3352 /* Replay all VSIs Configuration, including filters after reset */
3353 if (ice_vsi_replay_all(pf)) {
3354 dev_err(&pf->pdev->dev,
3355 "error replaying VSI configurations with switch filter rules\n");
3356 goto err_vsi_rebuild;
3359 /* start misc vector */
3360 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3361 err = ice_req_irq_msix_misc(pf);
3363 dev_err(dev, "misc vector setup failed: %d\n", err);
3364 goto err_vsi_rebuild;
3368 /* restart the VSIs that were rebuilt and running before the reset */
3369 err = ice_pf_ena_all_vsi(pf);
3371 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3372 /* no need to disable VSIs in tear down path in ice_rebuild()
3373 * since its already taken care in ice_vsi_open()
3375 goto err_vsi_rebuild;
3378 ice_reset_all_vfs(pf, true);
3379 /* if we get here, reset flow is successful */
3380 clear_bit(__ICE_RESET_FAILED, pf->state);
3384 ice_vsi_release_all(pf);
3385 err_sched_init_port:
3386 ice_sched_cleanup_all(hw);
3388 ice_shutdown_all_ctrlq(hw);
3389 set_bit(__ICE_RESET_FAILED, pf->state);
3391 /* set this bit in PF state to control service task scheduling */
3392 set_bit(__ICE_NEEDS_RESTART, pf->state);
3393 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3397 * ice_change_mtu - NDO callback to change the MTU
3398 * @netdev: network interface device structure
3399 * @new_mtu: new value for maximum frame size
3401 * Returns 0 on success, negative on failure
3403 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3405 struct ice_netdev_priv *np = netdev_priv(netdev);
3406 struct ice_vsi *vsi = np->vsi;
3407 struct ice_pf *pf = vsi->back;
3410 if (new_mtu == netdev->mtu) {
3411 netdev_warn(netdev, "mtu is already %u\n", netdev->mtu);
3415 if (new_mtu < netdev->min_mtu) {
3416 netdev_err(netdev, "new mtu invalid. min_mtu is %d\n",
3419 } else if (new_mtu > netdev->max_mtu) {
3420 netdev_err(netdev, "new mtu invalid. max_mtu is %d\n",
3424 /* if a reset is in progress, wait for some time for it to complete */
3426 if (ice_is_reset_in_progress(pf->state)) {
3428 usleep_range(1000, 2000);
3433 } while (count < 100);
3436 netdev_err(netdev, "can't change mtu. Device is busy\n");
3440 netdev->mtu = new_mtu;
3442 /* if VSI is up, bring it down and then back up */
3443 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3446 err = ice_down(vsi);
3448 netdev_err(netdev, "change mtu if_up err %d\n", err);
3454 netdev_err(netdev, "change mtu if_up err %d\n", err);
3459 netdev_dbg(netdev, "changed mtu to %d\n", new_mtu);
3464 * ice_set_rss - Set RSS keys and lut
3465 * @vsi: Pointer to VSI structure
3466 * @seed: RSS hash seed
3467 * @lut: Lookup table
3468 * @lut_size: Lookup table size
3470 * Returns 0 on success, negative on failure
3472 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3474 struct ice_pf *pf = vsi->back;
3475 struct ice_hw *hw = &pf->hw;
3476 enum ice_status status;
3479 struct ice_aqc_get_set_rss_keys *buf =
3480 (struct ice_aqc_get_set_rss_keys *)seed;
3482 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3485 dev_err(&pf->pdev->dev,
3486 "Cannot set RSS key, err %d aq_err %d\n",
3487 status, hw->adminq.rq_last_status);
3493 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3496 dev_err(&pf->pdev->dev,
3497 "Cannot set RSS lut, err %d aq_err %d\n",
3498 status, hw->adminq.rq_last_status);
3507 * ice_get_rss - Get RSS keys and lut
3508 * @vsi: Pointer to VSI structure
3509 * @seed: Buffer to store the keys
3510 * @lut: Buffer to store the lookup table entries
3511 * @lut_size: Size of buffer to store the lookup table entries
3513 * Returns 0 on success, negative on failure
3515 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3517 struct ice_pf *pf = vsi->back;
3518 struct ice_hw *hw = &pf->hw;
3519 enum ice_status status;
3522 struct ice_aqc_get_set_rss_keys *buf =
3523 (struct ice_aqc_get_set_rss_keys *)seed;
3525 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
3527 dev_err(&pf->pdev->dev,
3528 "Cannot get RSS key, err %d aq_err %d\n",
3529 status, hw->adminq.rq_last_status);
3535 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3538 dev_err(&pf->pdev->dev,
3539 "Cannot get RSS lut, err %d aq_err %d\n",
3540 status, hw->adminq.rq_last_status);
3549 * ice_bridge_getlink - Get the hardware bridge mode
3552 * @seq: RTNL message seq
3553 * @dev: the netdev being configured
3554 * @filter_mask: filter mask passed in
3555 * @nlflags: netlink flags passed in
3557 * Return the bridge mode (VEB/VEPA)
3560 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
3561 struct net_device *dev, u32 filter_mask, int nlflags)
3563 struct ice_netdev_priv *np = netdev_priv(dev);
3564 struct ice_vsi *vsi = np->vsi;
3565 struct ice_pf *pf = vsi->back;
3568 bmode = pf->first_sw->bridge_mode;
3570 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
3575 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
3576 * @vsi: Pointer to VSI structure
3577 * @bmode: Hardware bridge mode (VEB/VEPA)
3579 * Returns 0 on success, negative on failure
3581 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
3583 struct device *dev = &vsi->back->pdev->dev;
3584 struct ice_aqc_vsi_props *vsi_props;
3585 struct ice_hw *hw = &vsi->back->hw;
3586 struct ice_vsi_ctx ctxt = { 0 };
3587 enum ice_status status;
3589 vsi_props = &vsi->info;
3590 ctxt.info = vsi->info;
3592 if (bmode == BRIDGE_MODE_VEB)
3593 /* change from VEPA to VEB mode */
3594 ctxt.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3596 /* change from VEB to VEPA mode */
3597 ctxt.info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
3598 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
3600 status = ice_update_vsi(hw, vsi->idx, &ctxt, NULL);
3602 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
3603 bmode, status, hw->adminq.sq_last_status);
3606 /* Update sw flags for book keeping */
3607 vsi_props->sw_flags = ctxt.info.sw_flags;
3613 * ice_bridge_setlink - Set the hardware bridge mode
3614 * @dev: the netdev being configured
3615 * @nlh: RTNL message
3616 * @flags: bridge setlink flags
3618 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
3619 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
3620 * not already set for all VSIs connected to this switch. And also update the
3621 * unicast switch filter rules for the corresponding switch of the netdev.
3624 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
3625 u16 __always_unused flags)
3627 struct ice_netdev_priv *np = netdev_priv(dev);
3628 struct ice_pf *pf = np->vsi->back;
3629 struct nlattr *attr, *br_spec;
3630 struct ice_hw *hw = &pf->hw;
3631 enum ice_status status;
3632 struct ice_sw *pf_sw;
3633 int rem, v, err = 0;
3635 pf_sw = pf->first_sw;
3636 /* find the attribute in the netlink message */
3637 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
3639 nla_for_each_nested(attr, br_spec, rem) {
3642 if (nla_type(attr) != IFLA_BRIDGE_MODE)
3644 mode = nla_get_u16(attr);
3645 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
3647 /* Continue if bridge mode is not being flipped */
3648 if (mode == pf_sw->bridge_mode)
3650 /* Iterates through the PF VSI list and update the loopback
3653 ice_for_each_vsi(pf, v) {
3656 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
3661 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
3662 /* Update the unicast switch filter rules for the corresponding
3663 * switch of the netdev
3665 status = ice_update_sw_rule_bridge_mode(hw);
3667 netdev_err(dev, "update SW_RULE for bridge mode failed, = %d err %d aq_err %d\n",
3668 mode, status, hw->adminq.sq_last_status);
3669 /* revert hw->evb_veb */
3670 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
3674 pf_sw->bridge_mode = mode;
3681 * ice_tx_timeout - Respond to a Tx Hang
3682 * @netdev: network interface device structure
3684 static void ice_tx_timeout(struct net_device *netdev)
3686 struct ice_netdev_priv *np = netdev_priv(netdev);
3687 struct ice_ring *tx_ring = NULL;
3688 struct ice_vsi *vsi = np->vsi;
3689 struct ice_pf *pf = vsi->back;
3690 u32 head, val = 0, i;
3691 int hung_queue = -1;
3693 pf->tx_timeout_count++;
3695 /* find the stopped queue the same way the stack does */
3696 for (i = 0; i < netdev->num_tx_queues; i++) {
3697 struct netdev_queue *q;
3698 unsigned long trans_start;
3700 q = netdev_get_tx_queue(netdev, i);
3701 trans_start = q->trans_start;
3702 if (netif_xmit_stopped(q) &&
3704 (trans_start + netdev->watchdog_timeo))) {
3710 if (i == netdev->num_tx_queues) {
3711 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
3713 /* now that we have an index, find the tx_ring struct */
3714 for (i = 0; i < vsi->num_txq; i++) {
3715 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
3717 vsi->tx_rings[i]->q_index) {
3718 tx_ring = vsi->tx_rings[i];
3725 /* Reset recovery level if enough time has elapsed after last timeout.
3726 * Also ensure no new reset action happens before next timeout period.
3728 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
3729 pf->tx_timeout_recovery_level = 1;
3730 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
3731 netdev->watchdog_timeo)))
3735 head = tx_ring->next_to_clean;
3736 /* Read interrupt register */
3737 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3739 GLINT_DYN_CTL(tx_ring->q_vector->v_idx +
3740 tx_ring->vsi->hw_base_vector));
3742 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",
3743 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
3744 head, tx_ring->next_to_use,
3745 readl(tx_ring->tail), val);
3748 pf->tx_timeout_last_recovery = jiffies;
3749 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
3750 pf->tx_timeout_recovery_level, hung_queue);
3752 switch (pf->tx_timeout_recovery_level) {
3754 set_bit(__ICE_PFR_REQ, pf->state);
3757 set_bit(__ICE_CORER_REQ, pf->state);
3760 set_bit(__ICE_GLOBR_REQ, pf->state);
3763 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
3764 set_bit(__ICE_DOWN, pf->state);
3765 set_bit(__ICE_NEEDS_RESTART, vsi->state);
3766 set_bit(__ICE_SERVICE_DIS, pf->state);
3770 ice_service_task_schedule(pf);
3771 pf->tx_timeout_recovery_level++;
3775 * ice_open - Called when a network interface becomes active
3776 * @netdev: network interface device structure
3778 * The open entry point is called when a network interface is made
3779 * active by the system (IFF_UP). At this point all resources needed
3780 * for transmit and receive operations are allocated, the interrupt
3781 * handler is registered with the OS, the netdev watchdog is enabled,
3782 * and the stack is notified that the interface is ready.
3784 * Returns 0 on success, negative value on failure
3786 static int ice_open(struct net_device *netdev)
3788 struct ice_netdev_priv *np = netdev_priv(netdev);
3789 struct ice_vsi *vsi = np->vsi;
3792 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
3793 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
3797 netif_carrier_off(netdev);
3799 err = ice_vsi_open(vsi);
3802 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
3803 vsi->vsi_num, vsi->vsw->sw_id);
3808 * ice_stop - Disables a network interface
3809 * @netdev: network interface device structure
3811 * The stop entry point is called when an interface is de-activated by the OS,
3812 * and the netdevice enters the DOWN state. The hardware is still under the
3813 * driver's control, but the netdev interface is disabled.
3815 * Returns success only - not allowed to fail
3817 static int ice_stop(struct net_device *netdev)
3819 struct ice_netdev_priv *np = netdev_priv(netdev);
3820 struct ice_vsi *vsi = np->vsi;
3828 * ice_features_check - Validate encapsulated packet conforms to limits
3830 * @netdev: This port's netdev
3831 * @features: Offload features that the stack believes apply
3833 static netdev_features_t
3834 ice_features_check(struct sk_buff *skb,
3835 struct net_device __always_unused *netdev,
3836 netdev_features_t features)
3840 /* No point in doing any of this if neither checksum nor GSO are
3841 * being requested for this frame. We can rule out both by just
3842 * checking for CHECKSUM_PARTIAL
3844 if (skb->ip_summed != CHECKSUM_PARTIAL)
3847 /* We cannot support GSO if the MSS is going to be less than
3848 * 64 bytes. If it is then we need to drop support for GSO.
3850 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
3851 features &= ~NETIF_F_GSO_MASK;
3853 len = skb_network_header(skb) - skb->data;
3854 if (len & ~(ICE_TXD_MACLEN_MAX))
3855 goto out_rm_features;
3857 len = skb_transport_header(skb) - skb_network_header(skb);
3858 if (len & ~(ICE_TXD_IPLEN_MAX))
3859 goto out_rm_features;
3861 if (skb->encapsulation) {
3862 len = skb_inner_network_header(skb) - skb_transport_header(skb);
3863 if (len & ~(ICE_TXD_L4LEN_MAX))
3864 goto out_rm_features;
3866 len = skb_inner_transport_header(skb) -
3867 skb_inner_network_header(skb);
3868 if (len & ~(ICE_TXD_IPLEN_MAX))
3869 goto out_rm_features;
3874 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
3877 static const struct net_device_ops ice_netdev_ops = {
3878 .ndo_open = ice_open,
3879 .ndo_stop = ice_stop,
3880 .ndo_start_xmit = ice_start_xmit,
3881 .ndo_features_check = ice_features_check,
3882 .ndo_set_rx_mode = ice_set_rx_mode,
3883 .ndo_set_mac_address = ice_set_mac_address,
3884 .ndo_validate_addr = eth_validate_addr,
3885 .ndo_change_mtu = ice_change_mtu,
3886 .ndo_get_stats64 = ice_get_stats64,
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,