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
10 #define DRV_VERSION "ice-0.7.0-k"
11 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
12 const char ice_drv_ver[] = DRV_VERSION;
13 static const char ice_driver_string[] = DRV_SUMMARY;
14 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
17 MODULE_DESCRIPTION(DRV_SUMMARY);
18 MODULE_LICENSE("GPL");
19 MODULE_VERSION(DRV_VERSION);
21 static int debug = -1;
22 module_param(debug, int, 0644);
23 #ifndef CONFIG_DYNAMIC_DEBUG
24 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
26 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
27 #endif /* !CONFIG_DYNAMIC_DEBUG */
29 static struct workqueue_struct *ice_wq;
30 static const struct net_device_ops ice_netdev_ops;
32 static void ice_pf_dis_all_vsi(struct ice_pf *pf);
33 static void ice_rebuild(struct ice_pf *pf);
34 static int ice_vsi_release(struct ice_vsi *vsi);
35 static void ice_update_vsi_stats(struct ice_vsi *vsi);
36 static void ice_update_pf_stats(struct ice_pf *pf);
39 * ice_get_free_slot - get the next non-NULL location index in array
40 * @array: array to search
41 * @size: size of the array
42 * @curr: last known occupied index to be used as a search hint
44 * void * is being used to keep the functionality generic. This lets us use this
45 * function on any array of pointers.
47 static int ice_get_free_slot(void *array, int size, int curr)
49 int **tmp_array = (int **)array;
52 if (curr < (size - 1) && !tmp_array[curr + 1]) {
57 while ((i < size) && (tmp_array[i]))
68 * ice_search_res - Search the tracker for a block of resources
69 * @res: pointer to the resource
70 * @needed: size of the block needed
71 * @id: identifier to track owner
72 * Returns the base item index of the block, or -ENOMEM for error
74 static int ice_search_res(struct ice_res_tracker *res, u16 needed, u16 id)
76 int start = res->search_hint;
79 id |= ICE_RES_VALID_BIT;
82 /* skip already allocated entries */
83 if (res->list[end++] & ICE_RES_VALID_BIT) {
85 if ((start + needed) > res->num_entries)
89 if (end == (start + needed)) {
92 /* there was enough, so assign it to the requestor */
96 if (end == res->num_entries)
99 res->search_hint = end;
108 * ice_get_res - get a block of resources
109 * @pf: board private structure
110 * @res: pointer to the resource
111 * @needed: size of the block needed
112 * @id: identifier to track owner
114 * Returns the base item index of the block, or -ENOMEM for error
115 * The search_hint trick and lack of advanced fit-finding only works
116 * because we're highly likely to have all the same sized requests.
117 * Linear search time and any fragmentation should be minimal.
120 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
127 if (!needed || needed > res->num_entries || id >= ICE_RES_VALID_BIT) {
128 dev_err(&pf->pdev->dev,
129 "param err: needed=%d, num_entries = %d id=0x%04x\n",
130 needed, res->num_entries, id);
134 /* search based on search_hint */
135 ret = ice_search_res(res, needed, id);
138 /* previous search failed. Reset search hint and try again */
139 res->search_hint = 0;
140 ret = ice_search_res(res, needed, id);
147 * ice_free_res - free a block of resources
148 * @res: pointer to the resource
149 * @index: starting index previously returned by ice_get_res
150 * @id: identifier to track owner
151 * Returns number of resources freed
153 static int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
158 if (!res || index >= res->num_entries)
161 id |= ICE_RES_VALID_BIT;
162 for (i = index; i < res->num_entries && res->list[i] == id; i++) {
171 * ice_add_mac_to_list - Add a mac address filter entry to the list
172 * @vsi: the VSI to be forwarded to
173 * @add_list: pointer to the list which contains MAC filter entries
174 * @macaddr: the MAC address to be added.
176 * Adds mac address filter entry to the temp list
178 * Returns 0 on success or ENOMEM on failure.
180 static int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
183 struct ice_fltr_list_entry *tmp;
184 struct ice_pf *pf = vsi->back;
186 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
190 tmp->fltr_info.flag = ICE_FLTR_TX;
191 tmp->fltr_info.src = vsi->vsi_num;
192 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
193 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
194 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
195 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
197 INIT_LIST_HEAD(&tmp->list_entry);
198 list_add(&tmp->list_entry, add_list);
204 * ice_add_mac_to_sync_list - creates list of mac addresses to be synced
205 * @netdev: the net device on which the sync is happening
206 * @addr: mac address to sync
208 * This is a callback function which is called by the in kernel device sync
209 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
210 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
211 * mac filters from the hardware.
213 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
215 struct ice_netdev_priv *np = netdev_priv(netdev);
216 struct ice_vsi *vsi = np->vsi;
218 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
225 * ice_add_mac_to_unsync_list - creates list of mac addresses to be unsynced
226 * @netdev: the net device on which the unsync is happening
227 * @addr: mac address to unsync
229 * This is a callback function which is called by the in kernel device unsync
230 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
231 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
232 * delete the mac filters from the hardware.
234 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
236 struct ice_netdev_priv *np = netdev_priv(netdev);
237 struct ice_vsi *vsi = np->vsi;
239 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
246 * ice_free_fltr_list - free filter lists helper
247 * @dev: pointer to the device struct
248 * @h: pointer to the list head to be freed
250 * Helper function to free filter lists previously created using
251 * ice_add_mac_to_list
253 static void ice_free_fltr_list(struct device *dev, struct list_head *h)
255 struct ice_fltr_list_entry *e, *tmp;
257 list_for_each_entry_safe(e, tmp, h, list_entry) {
258 list_del(&e->list_entry);
264 * ice_vsi_fltr_changed - check if filter state changed
265 * @vsi: VSI to be checked
267 * returns true if filter state has changed, false otherwise.
269 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
271 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
272 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
273 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
277 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
278 * @vsi: ptr to the VSI
280 * Push any outstanding VSI filter changes through the AdminQ.
282 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
284 struct device *dev = &vsi->back->pdev->dev;
285 struct net_device *netdev = vsi->netdev;
286 bool promisc_forced_on = false;
287 struct ice_pf *pf = vsi->back;
288 struct ice_hw *hw = &pf->hw;
289 enum ice_status status = 0;
290 u32 changed_flags = 0;
296 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
297 usleep_range(1000, 2000);
299 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
300 vsi->current_netdev_flags = vsi->netdev->flags;
302 INIT_LIST_HEAD(&vsi->tmp_sync_list);
303 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
305 if (ice_vsi_fltr_changed(vsi)) {
306 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
307 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
308 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
310 /* grab the netdev's addr_list_lock */
311 netif_addr_lock_bh(netdev);
312 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
313 ice_add_mac_to_unsync_list);
314 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
315 ice_add_mac_to_unsync_list);
316 /* our temp lists are populated. release lock */
317 netif_addr_unlock_bh(netdev);
320 /* Remove mac addresses in the unsync list */
321 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
322 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
324 netdev_err(netdev, "Failed to delete MAC filters\n");
325 /* if we failed because of alloc failures, just bail */
326 if (status == ICE_ERR_NO_MEMORY) {
332 /* Add mac addresses in the sync list */
333 status = ice_add_mac(hw, &vsi->tmp_sync_list);
334 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
336 netdev_err(netdev, "Failed to add MAC filters\n");
337 /* If there is no more space for new umac filters, vsi
338 * should go into promiscuous mode. There should be some
339 * space reserved for promiscuous filters.
341 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
342 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
344 promisc_forced_on = true;
346 "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
353 /* check for changes in promiscuous modes */
354 if (changed_flags & IFF_ALLMULTI)
355 netdev_warn(netdev, "Unsupported configuration\n");
357 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
358 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
359 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
360 if (vsi->current_netdev_flags & IFF_PROMISC) {
361 /* Apply TX filter rule to get traffic from VMs */
362 status = ice_cfg_dflt_vsi(hw, vsi->vsi_num, true,
365 netdev_err(netdev, "Error setting default VSI %i tx rule\n",
367 vsi->current_netdev_flags &= ~IFF_PROMISC;
371 /* Apply RX filter rule to get traffic from wire */
372 status = ice_cfg_dflt_vsi(hw, vsi->vsi_num, true,
375 netdev_err(netdev, "Error setting default VSI %i rx rule\n",
377 vsi->current_netdev_flags &= ~IFF_PROMISC;
382 /* Clear TX filter rule to stop traffic from VMs */
383 status = ice_cfg_dflt_vsi(hw, vsi->vsi_num, false,
386 netdev_err(netdev, "Error clearing default VSI %i tx rule\n",
388 vsi->current_netdev_flags |= IFF_PROMISC;
392 /* Clear filter RX to remove traffic from wire */
393 status = ice_cfg_dflt_vsi(hw, vsi->vsi_num, false,
396 netdev_err(netdev, "Error clearing default VSI %i rx rule\n",
398 vsi->current_netdev_flags |= IFF_PROMISC;
407 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
410 /* if something went wrong then set the changed flag so we try again */
411 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
412 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
414 clear_bit(__ICE_CFG_BUSY, vsi->state);
419 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
420 * @pf: board private structure
422 static void ice_sync_fltr_subtask(struct ice_pf *pf)
426 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
429 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
431 for (v = 0; v < pf->num_alloc_vsi; v++)
432 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
433 ice_vsi_sync_fltr(pf->vsi[v])) {
434 /* come back and try again later */
435 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
441 * ice_is_reset_recovery_pending - schedule a reset
442 * @state: pf state field
444 static bool ice_is_reset_recovery_pending(unsigned long int *state)
446 return test_bit(__ICE_RESET_RECOVERY_PENDING, state);
450 * ice_prepare_for_reset - prep for the core to reset
451 * @pf: board private structure
453 * Inform or close all dependent features in prep for reset.
456 ice_prepare_for_reset(struct ice_pf *pf)
458 struct ice_hw *hw = &pf->hw;
461 ice_for_each_vsi(pf, v)
463 ice_remove_vsi_fltr(hw, pf->vsi[v]->vsi_num);
465 dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
467 /* disable the VSIs and their queues that are not already DOWN */
468 /* pf_dis_all_vsi modifies netdev structures -rtnl_lock needed */
469 ice_pf_dis_all_vsi(pf);
471 ice_for_each_vsi(pf, v)
473 pf->vsi[v]->vsi_num = 0;
475 ice_shutdown_all_ctrlq(hw);
479 * ice_do_reset - Initiate one of many types of resets
480 * @pf: board private structure
481 * @reset_type: reset type requested
482 * before this function was called.
484 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
486 struct device *dev = &pf->pdev->dev;
487 struct ice_hw *hw = &pf->hw;
489 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
490 WARN_ON(in_interrupt());
492 /* PFR is a bit of a special case because it doesn't result in an OICR
493 * interrupt. So for PFR, we prepare for reset, issue the reset and
494 * rebuild sequentially.
496 if (reset_type == ICE_RESET_PFR) {
497 set_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
498 ice_prepare_for_reset(pf);
501 /* trigger the reset */
502 if (ice_reset(hw, reset_type)) {
503 dev_err(dev, "reset %d failed\n", reset_type);
504 set_bit(__ICE_RESET_FAILED, pf->state);
505 clear_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
509 if (reset_type == ICE_RESET_PFR) {
512 clear_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
517 * ice_reset_subtask - Set up for resetting the device and driver
518 * @pf: board private structure
520 static void ice_reset_subtask(struct ice_pf *pf)
522 enum ice_reset_req reset_type;
526 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
527 * OICR interrupt. The OICR handler (ice_misc_intr) determines what
528 * type of reset happened and sets __ICE_RESET_RECOVERY_PENDING bit in
529 * pf->state. So if reset/recovery is pending (as indicated by this bit)
530 * we do a rebuild and return.
532 if (ice_is_reset_recovery_pending(pf->state)) {
533 clear_bit(__ICE_GLOBR_RECV, pf->state);
534 clear_bit(__ICE_CORER_RECV, pf->state);
535 ice_prepare_for_reset(pf);
537 /* make sure we are ready to rebuild */
538 if (ice_check_reset(&pf->hw))
539 set_bit(__ICE_RESET_FAILED, pf->state);
542 clear_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
546 /* No pending resets to finish processing. Check for new resets */
547 if (test_and_clear_bit(__ICE_GLOBR_REQ, pf->state))
548 reset_type = ICE_RESET_GLOBR;
549 else if (test_and_clear_bit(__ICE_CORER_REQ, pf->state))
550 reset_type = ICE_RESET_CORER;
551 else if (test_and_clear_bit(__ICE_PFR_REQ, pf->state))
552 reset_type = ICE_RESET_PFR;
556 /* reset if not already down or resetting */
557 if (!test_bit(__ICE_DOWN, pf->state) &&
558 !test_bit(__ICE_CFG_BUSY, pf->state)) {
559 ice_do_reset(pf, reset_type);
567 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
568 * @pf: board private structure
570 static void ice_watchdog_subtask(struct ice_pf *pf)
574 /* if interface is down do nothing */
575 if (test_bit(__ICE_DOWN, pf->state) ||
576 test_bit(__ICE_CFG_BUSY, pf->state))
579 /* make sure we don't do these things too often */
580 if (time_before(jiffies,
581 pf->serv_tmr_prev + pf->serv_tmr_period))
584 pf->serv_tmr_prev = jiffies;
586 /* Update the stats for active netdevs so the network stack
587 * can look at updated numbers whenever it cares to
589 ice_update_pf_stats(pf);
590 for (i = 0; i < pf->num_alloc_vsi; i++)
591 if (pf->vsi[i] && pf->vsi[i]->netdev)
592 ice_update_vsi_stats(pf->vsi[i]);
596 * ice_print_link_msg - print link up or down message
597 * @vsi: the VSI whose link status is being queried
598 * @isup: boolean for if the link is now up or down
600 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
605 if (vsi->current_isup == isup)
608 vsi->current_isup = isup;
611 netdev_info(vsi->netdev, "NIC Link is Down\n");
615 switch (vsi->port_info->phy.link_info.link_speed) {
616 case ICE_AQ_LINK_SPEED_40GB:
619 case ICE_AQ_LINK_SPEED_25GB:
622 case ICE_AQ_LINK_SPEED_20GB:
625 case ICE_AQ_LINK_SPEED_10GB:
628 case ICE_AQ_LINK_SPEED_5GB:
631 case ICE_AQ_LINK_SPEED_2500MB:
634 case ICE_AQ_LINK_SPEED_1000MB:
637 case ICE_AQ_LINK_SPEED_100MB:
645 switch (vsi->port_info->fc.current_mode) {
649 case ICE_FC_TX_PAUSE:
652 case ICE_FC_RX_PAUSE:
660 netdev_info(vsi->netdev, "NIC Link is up %sbps, Flow Control: %s\n",
665 * ice_init_link_events - enable/initialize link events
666 * @pi: pointer to the port_info instance
668 * Returns -EIO on failure, 0 on success
670 static int ice_init_link_events(struct ice_port_info *pi)
674 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
675 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
677 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
678 dev_dbg(ice_hw_to_dev(pi->hw),
679 "Failed to set link event mask for port %d\n",
684 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
685 dev_dbg(ice_hw_to_dev(pi->hw),
686 "Failed to enable link events for port %d\n",
695 * ice_vsi_link_event - update the vsi's netdev
696 * @vsi: the vsi on which the link event occurred
697 * @link_up: whether or not the vsi needs to be set up or down
699 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
701 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
704 if (vsi->type == ICE_VSI_PF) {
706 dev_dbg(&vsi->back->pdev->dev,
707 "vsi->netdev is not initialized!\n");
711 netif_carrier_on(vsi->netdev);
712 netif_tx_wake_all_queues(vsi->netdev);
714 netif_carrier_off(vsi->netdev);
715 netif_tx_stop_all_queues(vsi->netdev);
721 * ice_link_event - process the link event
722 * @pf: pf that the link event is associated with
723 * @pi: port_info for the port that the link event is associated with
725 * Returns -EIO if ice_get_link_status() fails
726 * Returns 0 on success
729 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi)
731 u8 new_link_speed, old_link_speed;
732 struct ice_phy_info *phy_info;
733 bool new_link_same_as_old;
734 bool new_link, old_link;
739 phy_info->link_info_old = phy_info->link_info;
740 /* Force ice_get_link_status() to update link info */
741 phy_info->get_link_info = true;
743 old_link = (phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
744 old_link_speed = phy_info->link_info_old.link_speed;
747 if (ice_get_link_status(pi, &new_link)) {
748 dev_dbg(&pf->pdev->dev,
749 "Could not get link status for port %d\n", lport);
753 new_link_speed = phy_info->link_info.link_speed;
755 new_link_same_as_old = (new_link == old_link &&
756 new_link_speed == old_link_speed);
758 ice_for_each_vsi(pf, v) {
759 struct ice_vsi *vsi = pf->vsi[v];
761 if (!vsi || !vsi->port_info)
764 if (new_link_same_as_old &&
765 (test_bit(__ICE_DOWN, vsi->state) ||
766 new_link == netif_carrier_ok(vsi->netdev)))
769 if (vsi->port_info->lport == lport) {
770 ice_print_link_msg(vsi, new_link);
771 ice_vsi_link_event(vsi, new_link);
779 * ice_handle_link_event - handle link event via ARQ
780 * @pf: pf that the link event is associated with
782 * Return -EINVAL if port_info is null
783 * Return status on succes
785 static int ice_handle_link_event(struct ice_pf *pf)
787 struct ice_port_info *port_info;
790 port_info = pf->hw.port_info;
794 status = ice_link_event(pf, port_info);
796 dev_dbg(&pf->pdev->dev,
797 "Could not process link event, error %d\n", status);
803 * __ice_clean_ctrlq - helper function to clean controlq rings
804 * @pf: ptr to struct ice_pf
805 * @q_type: specific Control queue type
807 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
809 struct ice_rq_event_info event;
810 struct ice_hw *hw = &pf->hw;
811 struct ice_ctl_q_info *cq;
816 /* Do not clean control queue if/when PF reset fails */
817 if (test_bit(__ICE_RESET_FAILED, pf->state))
821 case ICE_CTL_Q_ADMIN:
826 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
831 /* check for error indications - PF_xx_AxQLEN register layout for
832 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
834 val = rd32(hw, cq->rq.len);
835 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
836 PF_FW_ARQLEN_ARQCRIT_M)) {
838 if (val & PF_FW_ARQLEN_ARQVFE_M)
839 dev_dbg(&pf->pdev->dev,
840 "%s Receive Queue VF Error detected\n", qtype);
841 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
842 dev_dbg(&pf->pdev->dev,
843 "%s Receive Queue Overflow Error detected\n",
846 if (val & PF_FW_ARQLEN_ARQCRIT_M)
847 dev_dbg(&pf->pdev->dev,
848 "%s Receive Queue Critical Error detected\n",
850 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
851 PF_FW_ARQLEN_ARQCRIT_M);
853 wr32(hw, cq->rq.len, val);
856 val = rd32(hw, cq->sq.len);
857 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
858 PF_FW_ATQLEN_ATQCRIT_M)) {
860 if (val & PF_FW_ATQLEN_ATQVFE_M)
861 dev_dbg(&pf->pdev->dev,
862 "%s Send Queue VF Error detected\n", qtype);
863 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
864 dev_dbg(&pf->pdev->dev,
865 "%s Send Queue Overflow Error detected\n",
868 if (val & PF_FW_ATQLEN_ATQCRIT_M)
869 dev_dbg(&pf->pdev->dev,
870 "%s Send Queue Critical Error detected\n",
872 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
873 PF_FW_ATQLEN_ATQCRIT_M);
875 wr32(hw, cq->sq.len, val);
878 event.buf_len = cq->rq_buf_size;
879 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
888 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
889 if (ret == ICE_ERR_AQ_NO_WORK)
892 dev_err(&pf->pdev->dev,
893 "%s Receive Queue event error %d\n", qtype,
898 opcode = le16_to_cpu(event.desc.opcode);
901 case ice_aqc_opc_get_link_status:
902 if (ice_handle_link_event(pf))
903 dev_err(&pf->pdev->dev,
904 "Could not handle link event");
907 dev_dbg(&pf->pdev->dev,
908 "%s Receive Queue unknown event 0x%04x ignored\n",
912 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
914 devm_kfree(&pf->pdev->dev, event.msg_buf);
916 return pending && (i == ICE_DFLT_IRQ_WORK);
920 * ice_clean_adminq_subtask - clean the AdminQ rings
921 * @pf: board private structure
923 static void ice_clean_adminq_subtask(struct ice_pf *pf)
925 struct ice_hw *hw = &pf->hw;
928 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
931 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
934 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
936 /* re-enable Admin queue interrupt causes */
937 val = rd32(hw, PFINT_FW_CTL);
938 wr32(hw, PFINT_FW_CTL, (val | PFINT_FW_CTL_CAUSE_ENA_M));
944 * ice_service_task_schedule - schedule the service task to wake up
945 * @pf: board private structure
947 * If not already scheduled, this puts the task into the work queue.
949 static void ice_service_task_schedule(struct ice_pf *pf)
951 if (!test_bit(__ICE_DOWN, pf->state) &&
952 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state))
953 queue_work(ice_wq, &pf->serv_task);
957 * ice_service_task_complete - finish up the service task
958 * @pf: board private structure
960 static void ice_service_task_complete(struct ice_pf *pf)
962 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
964 /* force memory (pf->state) to sync before next service task */
965 smp_mb__before_atomic();
966 clear_bit(__ICE_SERVICE_SCHED, pf->state);
970 * ice_service_timer - timer callback to schedule service task
971 * @t: pointer to timer_list
973 static void ice_service_timer(struct timer_list *t)
975 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
977 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
978 ice_service_task_schedule(pf);
982 * ice_service_task - manage and run subtasks
983 * @work: pointer to work_struct contained by the PF struct
985 static void ice_service_task(struct work_struct *work)
987 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
988 unsigned long start_time = jiffies;
992 /* process reset requests first */
993 ice_reset_subtask(pf);
995 /* bail if a reset/recovery cycle is pending */
996 if (ice_is_reset_recovery_pending(pf->state) ||
997 test_bit(__ICE_SUSPENDED, pf->state)) {
998 ice_service_task_complete(pf);
1002 ice_sync_fltr_subtask(pf);
1003 ice_watchdog_subtask(pf);
1004 ice_clean_adminq_subtask(pf);
1006 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1007 ice_service_task_complete(pf);
1009 /* If the tasks have taken longer than one service timer period
1010 * or there is more work to be done, reset the service timer to
1011 * schedule the service task now.
1013 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1014 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1015 mod_timer(&pf->serv_tmr, jiffies);
1019 * ice_set_ctrlq_len - helper function to set controlq length
1020 * @hw: pointer to the hw instance
1022 static void ice_set_ctrlq_len(struct ice_hw *hw)
1024 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1025 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1026 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1027 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1031 * ice_irq_affinity_notify - Callback for affinity changes
1032 * @notify: context as to what irq was changed
1033 * @mask: the new affinity mask
1035 * This is a callback function used by the irq_set_affinity_notifier function
1036 * so that we may register to receive changes to the irq affinity masks.
1038 static void ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1039 const cpumask_t *mask)
1041 struct ice_q_vector *q_vector =
1042 container_of(notify, struct ice_q_vector, affinity_notify);
1044 cpumask_copy(&q_vector->affinity_mask, mask);
1048 * ice_irq_affinity_release - Callback for affinity notifier release
1049 * @ref: internal core kernel usage
1051 * This is a callback function used by the irq_set_affinity_notifier function
1052 * to inform the current notification subscriber that they will no longer
1053 * receive notifications.
1055 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1058 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
1059 * @vsi: the VSI being un-configured
1061 static void ice_vsi_dis_irq(struct ice_vsi *vsi)
1063 struct ice_pf *pf = vsi->back;
1064 struct ice_hw *hw = &pf->hw;
1065 int base = vsi->base_vector;
1069 /* disable interrupt causation from each queue */
1070 if (vsi->tx_rings) {
1071 ice_for_each_txq(vsi, i) {
1072 if (vsi->tx_rings[i]) {
1075 reg = vsi->tx_rings[i]->reg_idx;
1076 val = rd32(hw, QINT_TQCTL(reg));
1077 val &= ~QINT_TQCTL_CAUSE_ENA_M;
1078 wr32(hw, QINT_TQCTL(reg), val);
1083 if (vsi->rx_rings) {
1084 ice_for_each_rxq(vsi, i) {
1085 if (vsi->rx_rings[i]) {
1088 reg = vsi->rx_rings[i]->reg_idx;
1089 val = rd32(hw, QINT_RQCTL(reg));
1090 val &= ~QINT_RQCTL_CAUSE_ENA_M;
1091 wr32(hw, QINT_RQCTL(reg), val);
1096 /* disable each interrupt */
1097 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1098 for (i = vsi->base_vector;
1099 i < (vsi->num_q_vectors + vsi->base_vector); i++)
1100 wr32(hw, GLINT_DYN_CTL(i), 0);
1103 for (i = 0; i < vsi->num_q_vectors; i++)
1104 synchronize_irq(pf->msix_entries[i + base].vector);
1109 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1110 * @vsi: the VSI being configured
1112 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1114 struct ice_pf *pf = vsi->back;
1115 struct ice_hw *hw = &pf->hw;
1117 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1120 for (i = 0; i < vsi->num_q_vectors; i++)
1121 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1129 * ice_vsi_delete - delete a VSI from the switch
1130 * @vsi: pointer to VSI being removed
1132 static void ice_vsi_delete(struct ice_vsi *vsi)
1134 struct ice_pf *pf = vsi->back;
1135 struct ice_vsi_ctx ctxt;
1136 enum ice_status status;
1138 ctxt.vsi_num = vsi->vsi_num;
1140 memcpy(&ctxt.info, &vsi->info, sizeof(struct ice_aqc_vsi_props));
1142 status = ice_aq_free_vsi(&pf->hw, &ctxt, false, NULL);
1144 dev_err(&pf->pdev->dev, "Failed to delete VSI %i in FW\n",
1149 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1150 * @vsi: the VSI being configured
1151 * @basename: name for the vector
1153 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1155 int q_vectors = vsi->num_q_vectors;
1156 struct ice_pf *pf = vsi->back;
1157 int base = vsi->base_vector;
1163 for (vector = 0; vector < q_vectors; vector++) {
1164 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1166 irq_num = pf->msix_entries[base + vector].vector;
1168 if (q_vector->tx.ring && q_vector->rx.ring) {
1169 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1170 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1172 } else if (q_vector->rx.ring) {
1173 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1174 "%s-%s-%d", basename, "rx", rx_int_idx++);
1175 } else if (q_vector->tx.ring) {
1176 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1177 "%s-%s-%d", basename, "tx", tx_int_idx++);
1179 /* skip this unused q_vector */
1182 err = devm_request_irq(&pf->pdev->dev,
1183 pf->msix_entries[base + vector].vector,
1184 vsi->irq_handler, 0, q_vector->name,
1187 netdev_err(vsi->netdev,
1188 "MSIX request_irq failed, error: %d\n", err);
1192 /* register for affinity change notifications */
1193 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1194 q_vector->affinity_notify.release = ice_irq_affinity_release;
1195 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1197 /* assign the mask for this irq */
1198 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1201 vsi->irqs_ready = true;
1207 irq_num = pf->msix_entries[base + vector].vector,
1208 irq_set_affinity_notifier(irq_num, NULL);
1209 irq_set_affinity_hint(irq_num, NULL);
1210 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1216 * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type
1217 * @vsi: the VSI being configured
1219 static void ice_vsi_set_rss_params(struct ice_vsi *vsi)
1221 struct ice_hw_common_caps *cap;
1222 struct ice_pf *pf = vsi->back;
1224 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
1229 cap = &pf->hw.func_caps.common_cap;
1230 switch (vsi->type) {
1232 /* PF VSI will inherit RSS instance of PF */
1233 vsi->rss_table_size = cap->rss_table_size;
1234 vsi->rss_size = min_t(int, num_online_cpus(),
1235 BIT(cap->rss_table_entry_width));
1236 vsi->rss_lut_type = ICE_AQC_GSET_RSS_LUT_TABLE_TYPE_PF;
1239 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
1245 * ice_vsi_setup_q_map - Setup a VSI queue map
1246 * @vsi: the VSI being configured
1247 * @ctxt: VSI context structure
1249 static void ice_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
1251 u16 offset = 0, qmap = 0, numq_tc;
1252 u16 pow = 0, max_rss = 0, qcount;
1253 u16 qcount_tx = vsi->alloc_txq;
1254 u16 qcount_rx = vsi->alloc_rxq;
1255 bool ena_tc0 = false;
1258 /* at least TC0 should be enabled by default */
1259 if (vsi->tc_cfg.numtc) {
1260 if (!(vsi->tc_cfg.ena_tc & BIT(0)))
1267 vsi->tc_cfg.numtc++;
1268 vsi->tc_cfg.ena_tc |= 1;
1271 numq_tc = qcount_rx / vsi->tc_cfg.numtc;
1273 /* TC mapping is a function of the number of Rx queues assigned to the
1274 * VSI for each traffic class and the offset of these queues.
1275 * The first 10 bits are for queue offset for TC0, next 4 bits for no:of
1276 * queues allocated to TC0. No:of queues is a power-of-2.
1278 * If TC is not enabled, the queue offset is set to 0, and allocate one
1279 * queue, this way, traffic for the given TC will be sent to the default
1282 * Setup number and offset of Rx queues for all TCs for the VSI
1285 /* qcount will change if RSS is enabled */
1286 if (test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) {
1287 if (vsi->type == ICE_VSI_PF)
1288 max_rss = ICE_MAX_LG_RSS_QS;
1290 max_rss = ICE_MAX_SMALL_RSS_QS;
1292 qcount = min_t(int, numq_tc, max_rss);
1293 qcount = min_t(int, qcount, vsi->rss_size);
1298 /* find higher power-of-2 of qcount */
1299 pow = ilog2(qcount);
1301 if (!is_power_of_2(qcount))
1304 for (i = 0; i < ICE_MAX_TRAFFIC_CLASS; i++) {
1305 if (!(vsi->tc_cfg.ena_tc & BIT(i))) {
1306 /* TC is not enabled */
1307 vsi->tc_cfg.tc_info[i].qoffset = 0;
1308 vsi->tc_cfg.tc_info[i].qcount = 1;
1309 ctxt->info.tc_mapping[i] = 0;
1314 vsi->tc_cfg.tc_info[i].qoffset = offset;
1315 vsi->tc_cfg.tc_info[i].qcount = qcount;
1317 qmap = ((offset << ICE_AQ_VSI_TC_Q_OFFSET_S) &
1318 ICE_AQ_VSI_TC_Q_OFFSET_M) |
1319 ((pow << ICE_AQ_VSI_TC_Q_NUM_S) &
1320 ICE_AQ_VSI_TC_Q_NUM_M);
1322 ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
1325 vsi->num_txq = qcount_tx;
1326 vsi->num_rxq = offset;
1328 /* Rx queue mapping */
1329 ctxt->info.mapping_flags |= cpu_to_le16(ICE_AQ_VSI_Q_MAP_CONTIG);
1330 /* q_mapping buffer holds the info for the first queue allocated for
1331 * this VSI in the PF space and also the number of queues associated
1334 ctxt->info.q_mapping[0] = cpu_to_le16(vsi->rxq_map[0]);
1335 ctxt->info.q_mapping[1] = cpu_to_le16(vsi->num_rxq);
1339 * ice_set_dflt_vsi_ctx - Set default VSI context before adding a VSI
1340 * @ctxt: the VSI context being set
1342 * This initializes a default VSI context for all sections except the Queues.
1344 static void ice_set_dflt_vsi_ctx(struct ice_vsi_ctx *ctxt)
1348 memset(&ctxt->info, 0, sizeof(ctxt->info));
1349 /* VSI's should be allocated from shared pool */
1350 ctxt->alloc_from_pool = true;
1351 /* Src pruning enabled by default */
1352 ctxt->info.sw_flags = ICE_AQ_VSI_SW_FLAG_SRC_PRUNE;
1353 /* Traffic from VSI can be sent to LAN */
1354 ctxt->info.sw_flags2 = ICE_AQ_VSI_SW_FLAG_LAN_ENA;
1355 /* Allow all packets untagged/tagged */
1356 ctxt->info.port_vlan_flags = ((ICE_AQ_VSI_PVLAN_MODE_ALL &
1357 ICE_AQ_VSI_PVLAN_MODE_M) >>
1358 ICE_AQ_VSI_PVLAN_MODE_S);
1359 /* Show VLAN/UP from packets in Rx descriptors */
1360 ctxt->info.port_vlan_flags |= ((ICE_AQ_VSI_PVLAN_EMOD_STR_BOTH &
1361 ICE_AQ_VSI_PVLAN_EMOD_M) >>
1362 ICE_AQ_VSI_PVLAN_EMOD_S);
1363 /* Have 1:1 UP mapping for both ingress/egress tables */
1364 table |= ICE_UP_TABLE_TRANSLATE(0, 0);
1365 table |= ICE_UP_TABLE_TRANSLATE(1, 1);
1366 table |= ICE_UP_TABLE_TRANSLATE(2, 2);
1367 table |= ICE_UP_TABLE_TRANSLATE(3, 3);
1368 table |= ICE_UP_TABLE_TRANSLATE(4, 4);
1369 table |= ICE_UP_TABLE_TRANSLATE(5, 5);
1370 table |= ICE_UP_TABLE_TRANSLATE(6, 6);
1371 table |= ICE_UP_TABLE_TRANSLATE(7, 7);
1372 ctxt->info.ingress_table = cpu_to_le32(table);
1373 ctxt->info.egress_table = cpu_to_le32(table);
1374 /* Have 1:1 UP mapping for outer to inner UP table */
1375 ctxt->info.outer_up_table = cpu_to_le32(table);
1376 /* No Outer tag support outer_tag_flags remains to zero */
1380 * ice_set_rss_vsi_ctx - Set RSS VSI context before adding a VSI
1381 * @ctxt: the VSI context being set
1382 * @vsi: the VSI being configured
1384 static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
1386 u8 lut_type, hash_type;
1388 switch (vsi->type) {
1390 /* PF VSI will inherit RSS instance of PF */
1391 lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_PF;
1392 hash_type = ICE_AQ_VSI_Q_OPT_RSS_TPLZ;
1395 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
1400 ctxt->info.q_opt_rss = ((lut_type << ICE_AQ_VSI_Q_OPT_RSS_LUT_S) &
1401 ICE_AQ_VSI_Q_OPT_RSS_LUT_M) |
1402 ((hash_type << ICE_AQ_VSI_Q_OPT_RSS_HASH_S) &
1403 ICE_AQ_VSI_Q_OPT_RSS_HASH_M);
1407 * ice_vsi_add - Create a new VSI or fetch preallocated VSI
1408 * @vsi: the VSI being configured
1410 * This initializes a VSI context depending on the VSI type to be added and
1411 * passes it down to the add_vsi aq command to create a new VSI.
1413 static int ice_vsi_add(struct ice_vsi *vsi)
1415 struct ice_vsi_ctx ctxt = { 0 };
1416 struct ice_pf *pf = vsi->back;
1417 struct ice_hw *hw = &pf->hw;
1420 switch (vsi->type) {
1422 ctxt.flags = ICE_AQ_VSI_TYPE_PF;
1428 ice_set_dflt_vsi_ctx(&ctxt);
1429 /* if the switch is in VEB mode, allow VSI loopback */
1430 if (vsi->vsw->bridge_mode == BRIDGE_MODE_VEB)
1431 ctxt.info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
1433 /* Set LUT type and HASH type if RSS is enabled */
1434 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
1435 ice_set_rss_vsi_ctx(&ctxt, vsi);
1437 ctxt.info.sw_id = vsi->port_info->sw_id;
1438 ice_vsi_setup_q_map(vsi, &ctxt);
1440 ret = ice_aq_add_vsi(hw, &ctxt, NULL);
1442 dev_err(&vsi->back->pdev->dev,
1443 "Add VSI AQ call failed, err %d\n", ret);
1446 vsi->info = ctxt.info;
1447 vsi->vsi_num = ctxt.vsi_num;
1453 * ice_vsi_release_msix - Clear the queue to Interrupt mapping in HW
1454 * @vsi: the VSI being cleaned up
1456 static void ice_vsi_release_msix(struct ice_vsi *vsi)
1458 struct ice_pf *pf = vsi->back;
1459 u16 vector = vsi->base_vector;
1460 struct ice_hw *hw = &pf->hw;
1465 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1466 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1468 wr32(hw, GLINT_ITR(ICE_RX_ITR, vector), 0);
1469 wr32(hw, GLINT_ITR(ICE_TX_ITR, vector), 0);
1470 for (q = 0; q < q_vector->num_ring_tx; q++) {
1471 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), 0);
1475 for (q = 0; q < q_vector->num_ring_rx; q++) {
1476 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), 0);
1485 * ice_vsi_clear_rings - Deallocates the Tx and Rx rings for VSI
1486 * @vsi: the VSI having rings deallocated
1488 static void ice_vsi_clear_rings(struct ice_vsi *vsi)
1492 if (vsi->tx_rings) {
1493 for (i = 0; i < vsi->alloc_txq; i++) {
1494 if (vsi->tx_rings[i]) {
1495 kfree_rcu(vsi->tx_rings[i], rcu);
1496 vsi->tx_rings[i] = NULL;
1500 if (vsi->rx_rings) {
1501 for (i = 0; i < vsi->alloc_rxq; i++) {
1502 if (vsi->rx_rings[i]) {
1503 kfree_rcu(vsi->rx_rings[i], rcu);
1504 vsi->rx_rings[i] = NULL;
1511 * ice_vsi_alloc_rings - Allocates Tx and Rx rings for the VSI
1512 * @vsi: VSI which is having rings allocated
1514 static int ice_vsi_alloc_rings(struct ice_vsi *vsi)
1516 struct ice_pf *pf = vsi->back;
1519 /* Allocate tx_rings */
1520 for (i = 0; i < vsi->alloc_txq; i++) {
1521 struct ice_ring *ring;
1523 /* allocate with kzalloc(), free with kfree_rcu() */
1524 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1530 ring->reg_idx = vsi->txq_map[i];
1531 ring->ring_active = false;
1533 ring->netdev = vsi->netdev;
1534 ring->dev = &pf->pdev->dev;
1535 ring->count = vsi->num_desc;
1537 vsi->tx_rings[i] = ring;
1540 /* Allocate rx_rings */
1541 for (i = 0; i < vsi->alloc_rxq; i++) {
1542 struct ice_ring *ring;
1544 /* allocate with kzalloc(), free with kfree_rcu() */
1545 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1550 ring->reg_idx = vsi->rxq_map[i];
1551 ring->ring_active = false;
1553 ring->netdev = vsi->netdev;
1554 ring->dev = &pf->pdev->dev;
1555 ring->count = vsi->num_desc;
1556 vsi->rx_rings[i] = ring;
1562 ice_vsi_clear_rings(vsi);
1567 * ice_vsi_free_irq - Free the irq association with the OS
1568 * @vsi: the VSI being configured
1570 static void ice_vsi_free_irq(struct ice_vsi *vsi)
1572 struct ice_pf *pf = vsi->back;
1573 int base = vsi->base_vector;
1575 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1578 if (!vsi->q_vectors || !vsi->irqs_ready)
1581 vsi->irqs_ready = false;
1582 for (i = 0; i < vsi->num_q_vectors; i++) {
1583 u16 vector = i + base;
1586 irq_num = pf->msix_entries[vector].vector;
1588 /* free only the irqs that were actually requested */
1589 if (!vsi->q_vectors[i] ||
1590 !(vsi->q_vectors[i]->num_ring_tx ||
1591 vsi->q_vectors[i]->num_ring_rx))
1594 /* clear the affinity notifier in the IRQ descriptor */
1595 irq_set_affinity_notifier(irq_num, NULL);
1597 /* clear the affinity_mask in the IRQ descriptor */
1598 irq_set_affinity_hint(irq_num, NULL);
1599 synchronize_irq(irq_num);
1600 devm_free_irq(&pf->pdev->dev, irq_num,
1603 ice_vsi_release_msix(vsi);
1608 * ice_vsi_cfg_msix - MSIX mode Interrupt Config in the HW
1609 * @vsi: the VSI being configured
1611 static void ice_vsi_cfg_msix(struct ice_vsi *vsi)
1613 struct ice_pf *pf = vsi->back;
1614 u16 vector = vsi->base_vector;
1615 struct ice_hw *hw = &pf->hw;
1616 u32 txq = 0, rxq = 0;
1620 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1621 struct ice_q_vector *q_vector = vsi->q_vectors[i];
1623 itr_gran = hw->itr_gran_200;
1625 if (q_vector->num_ring_rx) {
1627 ITR_TO_REG(vsi->rx_rings[rxq]->rx_itr_setting,
1629 q_vector->rx.latency_range = ICE_LOW_LATENCY;
1632 if (q_vector->num_ring_tx) {
1634 ITR_TO_REG(vsi->tx_rings[txq]->tx_itr_setting,
1636 q_vector->tx.latency_range = ICE_LOW_LATENCY;
1638 wr32(hw, GLINT_ITR(ICE_RX_ITR, vector), q_vector->rx.itr);
1639 wr32(hw, GLINT_ITR(ICE_TX_ITR, vector), q_vector->tx.itr);
1641 /* Both Transmit Queue Interrupt Cause Control register
1642 * and Receive Queue Interrupt Cause control register
1643 * expects MSIX_INDX field to be the vector index
1644 * within the function space and not the absolute
1645 * vector index across PF or across device.
1646 * For SR-IOV VF VSIs queue vector index always starts
1647 * with 1 since first vector index(0) is used for OICR
1648 * in VF space. Since VMDq and other PF VSIs are withtin
1649 * the PF function space, use the vector index thats
1650 * tracked for this PF.
1652 for (q = 0; q < q_vector->num_ring_tx; q++) {
1656 val = QINT_TQCTL_CAUSE_ENA_M |
1657 (itr << QINT_TQCTL_ITR_INDX_S) |
1658 (vector << QINT_TQCTL_MSIX_INDX_S);
1659 wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), val);
1663 for (q = 0; q < q_vector->num_ring_rx; q++) {
1667 val = QINT_RQCTL_CAUSE_ENA_M |
1668 (itr << QINT_RQCTL_ITR_INDX_S) |
1669 (vector << QINT_RQCTL_MSIX_INDX_S);
1670 wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), val);
1679 * ice_ena_misc_vector - enable the non-queue interrupts
1680 * @pf: board private structure
1682 static void ice_ena_misc_vector(struct ice_pf *pf)
1684 struct ice_hw *hw = &pf->hw;
1687 /* clear things first */
1688 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1689 rd32(hw, PFINT_OICR); /* read to clear */
1691 val = (PFINT_OICR_HLP_RDY_M |
1692 PFINT_OICR_CPM_RDY_M |
1693 PFINT_OICR_ECC_ERR_M |
1694 PFINT_OICR_MAL_DETECT_M |
1696 PFINT_OICR_PCI_EXCEPTION_M |
1698 PFINT_OICR_STORM_DETECT_M |
1699 PFINT_OICR_HMC_ERR_M);
1701 wr32(hw, PFINT_OICR_ENA, val);
1703 /* SW_ITR_IDX = 0, but don't change INTENA */
1704 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
1705 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1709 * ice_misc_intr - misc interrupt handler
1710 * @irq: interrupt number
1711 * @data: pointer to a q_vector
1713 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1715 struct ice_pf *pf = (struct ice_pf *)data;
1716 struct ice_hw *hw = &pf->hw;
1717 irqreturn_t ret = IRQ_NONE;
1720 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1722 oicr = rd32(hw, PFINT_OICR);
1723 ena_mask = rd32(hw, PFINT_OICR_ENA);
1725 if (oicr & PFINT_OICR_GRST_M) {
1727 /* we have a reset warning */
1728 ena_mask &= ~PFINT_OICR_GRST_M;
1729 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1730 GLGEN_RSTAT_RESET_TYPE_S;
1732 if (reset == ICE_RESET_CORER)
1734 else if (reset == ICE_RESET_GLOBR)
1739 /* If a reset cycle isn't already in progress, we set a bit in
1740 * pf->state so that the service task can start a reset/rebuild.
1741 * We also make note of which reset happened so that peer
1742 * devices/drivers can be informed.
1744 if (!test_bit(__ICE_RESET_RECOVERY_PENDING, pf->state)) {
1745 if (reset == ICE_RESET_CORER)
1746 set_bit(__ICE_CORER_RECV, pf->state);
1747 else if (reset == ICE_RESET_GLOBR)
1748 set_bit(__ICE_GLOBR_RECV, pf->state);
1750 set_bit(__ICE_EMPR_RECV, pf->state);
1752 set_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
1756 if (oicr & PFINT_OICR_HMC_ERR_M) {
1757 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1758 dev_dbg(&pf->pdev->dev,
1759 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1760 rd32(hw, PFHMC_ERRORINFO),
1761 rd32(hw, PFHMC_ERRORDATA));
1764 /* Report and mask off any remaining unexpected interrupts */
1767 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1769 /* If a critical error is pending there is no choice but to
1772 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1773 PFINT_OICR_PCI_EXCEPTION_M |
1774 PFINT_OICR_ECC_ERR_M)) {
1775 set_bit(__ICE_PFR_REQ, pf->state);
1776 ice_service_task_schedule(pf);
1782 /* re-enable interrupt causes that are not handled during this pass */
1783 wr32(hw, PFINT_OICR_ENA, ena_mask);
1784 if (!test_bit(__ICE_DOWN, pf->state)) {
1785 ice_service_task_schedule(pf);
1786 ice_irq_dynamic_ena(hw, NULL, NULL);
1793 * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
1794 * @vsi: the VSI being configured
1796 * This function maps descriptor rings to the queue-specific vectors allotted
1797 * through the MSI-X enabling code. On a constrained vector budget, we map Tx
1798 * and Rx rings to the vector as "efficiently" as possible.
1800 static void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
1802 int q_vectors = vsi->num_q_vectors;
1803 int tx_rings_rem, rx_rings_rem;
1806 /* initially assigning remaining rings count to VSIs num queue value */
1807 tx_rings_rem = vsi->num_txq;
1808 rx_rings_rem = vsi->num_rxq;
1810 for (v_id = 0; v_id < q_vectors; v_id++) {
1811 struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
1812 int tx_rings_per_v, rx_rings_per_v, q_id, q_base;
1814 /* Tx rings mapping to vector */
1815 tx_rings_per_v = DIV_ROUND_UP(tx_rings_rem, q_vectors - v_id);
1816 q_vector->num_ring_tx = tx_rings_per_v;
1817 q_vector->tx.ring = NULL;
1818 q_base = vsi->num_txq - tx_rings_rem;
1820 for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
1821 struct ice_ring *tx_ring = vsi->tx_rings[q_id];
1823 tx_ring->q_vector = q_vector;
1824 tx_ring->next = q_vector->tx.ring;
1825 q_vector->tx.ring = tx_ring;
1827 tx_rings_rem -= tx_rings_per_v;
1829 /* Rx rings mapping to vector */
1830 rx_rings_per_v = DIV_ROUND_UP(rx_rings_rem, q_vectors - v_id);
1831 q_vector->num_ring_rx = rx_rings_per_v;
1832 q_vector->rx.ring = NULL;
1833 q_base = vsi->num_rxq - rx_rings_rem;
1835 for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
1836 struct ice_ring *rx_ring = vsi->rx_rings[q_id];
1838 rx_ring->q_vector = q_vector;
1839 rx_ring->next = q_vector->rx.ring;
1840 q_vector->rx.ring = rx_ring;
1842 rx_rings_rem -= rx_rings_per_v;
1847 * ice_vsi_set_num_qs - Set num queues, descriptors and vectors for a VSI
1848 * @vsi: the VSI being configured
1850 * Return 0 on success and a negative value on error
1852 static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
1854 struct ice_pf *pf = vsi->back;
1856 switch (vsi->type) {
1858 vsi->alloc_txq = pf->num_lan_tx;
1859 vsi->alloc_rxq = pf->num_lan_rx;
1860 vsi->num_desc = ALIGN(ICE_DFLT_NUM_DESC, ICE_REQ_DESC_MULTIPLE);
1861 vsi->num_q_vectors = max_t(int, pf->num_lan_rx, pf->num_lan_tx);
1864 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
1871 * ice_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
1873 * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
1875 * On error: returns error code (negative)
1876 * On success: returns 0
1878 static int ice_vsi_alloc_arrays(struct ice_vsi *vsi, bool alloc_qvectors)
1880 struct ice_pf *pf = vsi->back;
1882 /* allocate memory for both Tx and Rx ring pointers */
1883 vsi->tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
1884 sizeof(struct ice_ring *), GFP_KERNEL);
1888 vsi->rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
1889 sizeof(struct ice_ring *), GFP_KERNEL);
1893 if (alloc_qvectors) {
1894 /* allocate memory for q_vector pointers */
1895 vsi->q_vectors = devm_kcalloc(&pf->pdev->dev,
1897 sizeof(struct ice_q_vector *),
1899 if (!vsi->q_vectors)
1906 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
1908 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
1914 * ice_msix_clean_rings - MSIX mode Interrupt Handler
1915 * @irq: interrupt number
1916 * @data: pointer to a q_vector
1918 static irqreturn_t ice_msix_clean_rings(int __always_unused irq, void *data)
1920 struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
1922 if (!q_vector->tx.ring && !q_vector->rx.ring)
1925 napi_schedule(&q_vector->napi);
1931 * ice_vsi_alloc - Allocates the next available struct vsi in the PF
1932 * @pf: board private structure
1933 * @type: type of VSI
1935 * returns a pointer to a VSI on success, NULL on failure.
1937 static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type type)
1939 struct ice_vsi *vsi = NULL;
1941 /* Need to protect the allocation of the VSIs at the PF level */
1942 mutex_lock(&pf->sw_mutex);
1944 /* If we have already allocated our maximum number of VSIs,
1945 * pf->next_vsi will be ICE_NO_VSI. If not, pf->next_vsi index
1946 * is available to be populated
1948 if (pf->next_vsi == ICE_NO_VSI) {
1949 dev_dbg(&pf->pdev->dev, "out of VSI slots!\n");
1953 vsi = devm_kzalloc(&pf->pdev->dev, sizeof(*vsi), GFP_KERNEL);
1959 set_bit(__ICE_DOWN, vsi->state);
1960 vsi->idx = pf->next_vsi;
1961 vsi->work_lmt = ICE_DFLT_IRQ_WORK;
1963 ice_vsi_set_num_qs(vsi);
1965 switch (vsi->type) {
1967 if (ice_vsi_alloc_arrays(vsi, true))
1970 /* Setup default MSIX irq handler for VSI */
1971 vsi->irq_handler = ice_msix_clean_rings;
1974 dev_warn(&pf->pdev->dev, "Unknown VSI type %d\n", vsi->type);
1978 /* fill VSI slot in the PF struct */
1979 pf->vsi[pf->next_vsi] = vsi;
1981 /* prepare pf->next_vsi for next use */
1982 pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
1987 devm_kfree(&pf->pdev->dev, vsi);
1990 mutex_unlock(&pf->sw_mutex);
1995 * ice_free_irq_msix_misc - Unroll misc vector setup
1996 * @pf: board private structure
1998 static void ice_free_irq_msix_misc(struct ice_pf *pf)
2000 /* disable OICR interrupt */
2001 wr32(&pf->hw, PFINT_OICR_ENA, 0);
2004 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
2005 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
2006 devm_free_irq(&pf->pdev->dev,
2007 pf->msix_entries[pf->oicr_idx].vector, pf);
2010 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
2014 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2015 * @pf: board private structure
2017 * This sets up the handler for MSIX 0, which is used to manage the
2018 * non-queue interrupts, e.g. AdminQ and errors. This is not used
2019 * when in MSI or Legacy interrupt mode.
2021 static int ice_req_irq_msix_misc(struct ice_pf *pf)
2023 struct ice_hw *hw = &pf->hw;
2024 int oicr_idx, err = 0;
2028 if (!pf->int_name[0])
2029 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
2030 dev_driver_string(&pf->pdev->dev),
2031 dev_name(&pf->pdev->dev));
2033 /* Do not request IRQ but do enable OICR interrupt since settings are
2034 * lost during reset. Note that this function is called only during
2035 * rebuild path and not while reset is in progress.
2037 if (ice_is_reset_recovery_pending(pf->state))
2040 /* reserve one vector in irq_tracker for misc interrupts */
2041 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2045 pf->oicr_idx = oicr_idx;
2047 err = devm_request_irq(&pf->pdev->dev,
2048 pf->msix_entries[pf->oicr_idx].vector,
2049 ice_misc_intr, 0, pf->int_name, pf);
2051 dev_err(&pf->pdev->dev,
2052 "devm_request_irq for %s failed: %d\n",
2054 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2059 ice_ena_misc_vector(pf);
2061 val = (pf->oicr_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2062 (ICE_RX_ITR & PFINT_OICR_CTL_ITR_INDX_M) |
2063 PFINT_OICR_CTL_CAUSE_ENA_M;
2064 wr32(hw, PFINT_OICR_CTL, val);
2066 /* This enables Admin queue Interrupt causes */
2067 val = (pf->oicr_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2068 (ICE_RX_ITR & PFINT_FW_CTL_ITR_INDX_M) |
2069 PFINT_FW_CTL_CAUSE_ENA_M;
2070 wr32(hw, PFINT_FW_CTL, val);
2072 itr_gran = hw->itr_gran_200;
2074 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
2075 ITR_TO_REG(ICE_ITR_8K, itr_gran));
2078 ice_irq_dynamic_ena(hw, NULL, NULL);
2084 * ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
2085 * @vsi: the VSI getting queues
2087 * Return 0 on success and a negative value on error
2089 static int ice_vsi_get_qs_contig(struct ice_vsi *vsi)
2091 struct ice_pf *pf = vsi->back;
2092 int offset, ret = 0;
2094 mutex_lock(&pf->avail_q_mutex);
2095 /* look for contiguous block of queues for tx */
2096 offset = bitmap_find_next_zero_area(pf->avail_txqs, ICE_MAX_TXQS,
2097 0, vsi->alloc_txq, 0);
2098 if (offset < ICE_MAX_TXQS) {
2101 bitmap_set(pf->avail_txqs, offset, vsi->alloc_txq);
2102 for (i = 0; i < vsi->alloc_txq; i++)
2103 vsi->txq_map[i] = i + offset;
2106 vsi->tx_mapping_mode = ICE_VSI_MAP_SCATTER;
2109 /* look for contiguous block of queues for rx */
2110 offset = bitmap_find_next_zero_area(pf->avail_rxqs, ICE_MAX_RXQS,
2111 0, vsi->alloc_rxq, 0);
2112 if (offset < ICE_MAX_RXQS) {
2115 bitmap_set(pf->avail_rxqs, offset, vsi->alloc_rxq);
2116 for (i = 0; i < vsi->alloc_rxq; i++)
2117 vsi->rxq_map[i] = i + offset;
2120 vsi->rx_mapping_mode = ICE_VSI_MAP_SCATTER;
2122 mutex_unlock(&pf->avail_q_mutex);
2128 * ice_vsi_get_qs_scatter - Assign a scattered queues to VSI
2129 * @vsi: the VSI getting queues
2131 * Return 0 on success and a negative value on error
2133 static int ice_vsi_get_qs_scatter(struct ice_vsi *vsi)
2135 struct ice_pf *pf = vsi->back;
2138 mutex_lock(&pf->avail_q_mutex);
2140 if (vsi->tx_mapping_mode == ICE_VSI_MAP_SCATTER) {
2141 for (i = 0; i < vsi->alloc_txq; i++) {
2142 index = find_next_zero_bit(pf->avail_txqs,
2143 ICE_MAX_TXQS, index);
2144 if (index < ICE_MAX_TXQS) {
2145 set_bit(index, pf->avail_txqs);
2146 vsi->txq_map[i] = index;
2148 goto err_scatter_tx;
2153 if (vsi->rx_mapping_mode == ICE_VSI_MAP_SCATTER) {
2154 for (i = 0; i < vsi->alloc_rxq; i++) {
2155 index = find_next_zero_bit(pf->avail_rxqs,
2156 ICE_MAX_RXQS, index);
2157 if (index < ICE_MAX_RXQS) {
2158 set_bit(index, pf->avail_rxqs);
2159 vsi->rxq_map[i] = index;
2161 goto err_scatter_rx;
2166 mutex_unlock(&pf->avail_q_mutex);
2170 /* unflag any queues we have grabbed (i is failed position) */
2171 for (index = 0; index < i; index++) {
2172 clear_bit(vsi->rxq_map[index], pf->avail_rxqs);
2173 vsi->rxq_map[index] = 0;
2177 /* i is either position of failed attempt or vsi->alloc_txq */
2178 for (index = 0; index < i; index++) {
2179 clear_bit(vsi->txq_map[index], pf->avail_txqs);
2180 vsi->txq_map[index] = 0;
2183 mutex_unlock(&pf->avail_q_mutex);
2188 * ice_vsi_get_qs - Assign queues from PF to VSI
2189 * @vsi: the VSI to assign queues to
2191 * Returns 0 on success and a negative value on error
2193 static int ice_vsi_get_qs(struct ice_vsi *vsi)
2197 vsi->tx_mapping_mode = ICE_VSI_MAP_CONTIG;
2198 vsi->rx_mapping_mode = ICE_VSI_MAP_CONTIG;
2200 /* NOTE: ice_vsi_get_qs_contig() will set the rx/tx mapping
2201 * modes individually to scatter if assigning contiguous queues
2204 ret = ice_vsi_get_qs_contig(vsi);
2206 if (vsi->tx_mapping_mode == ICE_VSI_MAP_SCATTER)
2207 vsi->alloc_txq = max_t(u16, vsi->alloc_txq,
2208 ICE_MAX_SCATTER_TXQS);
2209 if (vsi->rx_mapping_mode == ICE_VSI_MAP_SCATTER)
2210 vsi->alloc_rxq = max_t(u16, vsi->alloc_rxq,
2211 ICE_MAX_SCATTER_RXQS);
2212 ret = ice_vsi_get_qs_scatter(vsi);
2219 * ice_vsi_put_qs - Release queues from VSI to PF
2220 * @vsi: the VSI thats going to release queues
2222 static void ice_vsi_put_qs(struct ice_vsi *vsi)
2224 struct ice_pf *pf = vsi->back;
2227 mutex_lock(&pf->avail_q_mutex);
2229 for (i = 0; i < vsi->alloc_txq; i++) {
2230 clear_bit(vsi->txq_map[i], pf->avail_txqs);
2231 vsi->txq_map[i] = ICE_INVAL_Q_INDEX;
2234 for (i = 0; i < vsi->alloc_rxq; i++) {
2235 clear_bit(vsi->rxq_map[i], pf->avail_rxqs);
2236 vsi->rxq_map[i] = ICE_INVAL_Q_INDEX;
2239 mutex_unlock(&pf->avail_q_mutex);
2243 * ice_free_q_vector - Free memory allocated for a specific interrupt vector
2244 * @vsi: VSI having the memory freed
2245 * @v_idx: index of the vector to be freed
2247 static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
2249 struct ice_q_vector *q_vector;
2250 struct ice_ring *ring;
2252 if (!vsi->q_vectors[v_idx]) {
2253 dev_dbg(&vsi->back->pdev->dev, "Queue vector at index %d not found\n",
2257 q_vector = vsi->q_vectors[v_idx];
2259 ice_for_each_ring(ring, q_vector->tx)
2260 ring->q_vector = NULL;
2261 ice_for_each_ring(ring, q_vector->rx)
2262 ring->q_vector = NULL;
2264 /* only VSI with an associated netdev is set up with NAPI */
2266 netif_napi_del(&q_vector->napi);
2268 devm_kfree(&vsi->back->pdev->dev, q_vector);
2269 vsi->q_vectors[v_idx] = NULL;
2273 * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
2274 * @vsi: the VSI having memory freed
2276 static void ice_vsi_free_q_vectors(struct ice_vsi *vsi)
2280 for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
2281 ice_free_q_vector(vsi, v_idx);
2285 * ice_cfg_netdev - Setup the netdev flags
2286 * @vsi: the VSI being configured
2288 * Returns 0 on success, negative value on failure
2290 static int ice_cfg_netdev(struct ice_vsi *vsi)
2292 netdev_features_t csumo_features;
2293 netdev_features_t vlano_features;
2294 netdev_features_t dflt_features;
2295 netdev_features_t tso_features;
2296 struct ice_netdev_priv *np;
2297 struct net_device *netdev;
2298 u8 mac_addr[ETH_ALEN];
2300 netdev = alloc_etherdev_mqs(sizeof(struct ice_netdev_priv),
2301 vsi->alloc_txq, vsi->alloc_rxq);
2305 vsi->netdev = netdev;
2306 np = netdev_priv(netdev);
2309 dflt_features = NETIF_F_SG |
2313 csumo_features = NETIF_F_RXCSUM |
2317 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
2318 NETIF_F_HW_VLAN_CTAG_TX |
2319 NETIF_F_HW_VLAN_CTAG_RX;
2321 tso_features = NETIF_F_TSO;
2323 /* set features that user can change */
2324 netdev->hw_features = dflt_features | csumo_features |
2325 vlano_features | tso_features;
2327 /* enable features */
2328 netdev->features |= netdev->hw_features;
2329 /* encap and VLAN devices inherit default, csumo and tso features */
2330 netdev->hw_enc_features |= dflt_features | csumo_features |
2332 netdev->vlan_features |= dflt_features | csumo_features |
2335 if (vsi->type == ICE_VSI_PF) {
2336 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
2337 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
2339 ether_addr_copy(netdev->dev_addr, mac_addr);
2340 ether_addr_copy(netdev->perm_addr, mac_addr);
2343 netdev->priv_flags |= IFF_UNICAST_FLT;
2345 /* assign netdev_ops */
2346 netdev->netdev_ops = &ice_netdev_ops;
2348 /* setup watchdog timeout value to be 5 second */
2349 netdev->watchdog_timeo = 5 * HZ;
2351 ice_set_ethtool_ops(netdev);
2353 netdev->min_mtu = ETH_MIN_MTU;
2354 netdev->max_mtu = ICE_MAX_MTU;
2360 * ice_vsi_free_arrays - clean up vsi resources
2361 * @vsi: pointer to VSI being cleared
2362 * @free_qvectors: bool to specify if q_vectors should be deallocated
2364 static void ice_vsi_free_arrays(struct ice_vsi *vsi, bool free_qvectors)
2366 struct ice_pf *pf = vsi->back;
2368 /* free the ring and vector containers */
2369 if (free_qvectors && vsi->q_vectors) {
2370 devm_kfree(&pf->pdev->dev, vsi->q_vectors);
2371 vsi->q_vectors = NULL;
2373 if (vsi->tx_rings) {
2374 devm_kfree(&pf->pdev->dev, vsi->tx_rings);
2375 vsi->tx_rings = NULL;
2377 if (vsi->rx_rings) {
2378 devm_kfree(&pf->pdev->dev, vsi->rx_rings);
2379 vsi->rx_rings = NULL;
2384 * ice_vsi_clear - clean up and deallocate the provided vsi
2385 * @vsi: pointer to VSI being cleared
2387 * This deallocates the vsi's queue resources, removes it from the PF's
2388 * VSI array if necessary, and deallocates the VSI
2390 * Returns 0 on success, negative on failure
2392 static int ice_vsi_clear(struct ice_vsi *vsi)
2394 struct ice_pf *pf = NULL;
2404 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) {
2405 dev_dbg(&pf->pdev->dev, "vsi does not exist at pf->vsi[%d]\n",
2410 mutex_lock(&pf->sw_mutex);
2411 /* updates the PF for this cleared vsi */
2413 pf->vsi[vsi->idx] = NULL;
2414 if (vsi->idx < pf->next_vsi)
2415 pf->next_vsi = vsi->idx;
2417 ice_vsi_free_arrays(vsi, true);
2418 mutex_unlock(&pf->sw_mutex);
2419 devm_kfree(&pf->pdev->dev, vsi);
2425 * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
2426 * @vsi: the VSI being configured
2427 * @v_idx: index of the vector in the vsi struct
2429 * We allocate one q_vector. If allocation fails we return -ENOMEM.
2431 static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, int v_idx)
2433 struct ice_pf *pf = vsi->back;
2434 struct ice_q_vector *q_vector;
2436 /* allocate q_vector */
2437 q_vector = devm_kzalloc(&pf->pdev->dev, sizeof(*q_vector), GFP_KERNEL);
2441 q_vector->vsi = vsi;
2442 q_vector->v_idx = v_idx;
2443 /* only set affinity_mask if the CPU is online */
2444 if (cpu_online(v_idx))
2445 cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
2448 netif_napi_add(vsi->netdev, &q_vector->napi, ice_napi_poll,
2450 /* tie q_vector and vsi together */
2451 vsi->q_vectors[v_idx] = q_vector;
2457 * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
2458 * @vsi: the VSI being configured
2460 * We allocate one q_vector per queue interrupt. If allocation fails we
2463 static int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
2465 struct ice_pf *pf = vsi->back;
2466 int v_idx = 0, num_q_vectors;
2469 if (vsi->q_vectors[0]) {
2470 dev_dbg(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
2475 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2476 num_q_vectors = vsi->num_q_vectors;
2482 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
2483 err = ice_vsi_alloc_q_vector(vsi, v_idx);
2492 ice_free_q_vector(vsi, v_idx);
2494 dev_err(&pf->pdev->dev,
2495 "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
2496 vsi->num_q_vectors, vsi->vsi_num, err);
2497 vsi->num_q_vectors = 0;
2502 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
2503 * @vsi: ptr to the VSI
2505 * This should only be called after ice_vsi_alloc() which allocates the
2506 * corresponding SW VSI structure and initializes num_queue_pairs for the
2507 * newly allocated VSI.
2509 * Returns 0 on success or negative on failure
2511 static int ice_vsi_setup_vector_base(struct ice_vsi *vsi)
2513 struct ice_pf *pf = vsi->back;
2514 int num_q_vectors = 0;
2516 if (vsi->base_vector) {
2517 dev_dbg(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
2518 vsi->vsi_num, vsi->base_vector);
2522 if (!test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2525 switch (vsi->type) {
2527 num_q_vectors = vsi->num_q_vectors;
2530 dev_warn(&vsi->back->pdev->dev, "Unknown VSI type %d\n",
2536 vsi->base_vector = ice_get_res(pf, pf->irq_tracker,
2537 num_q_vectors, vsi->idx);
2539 if (vsi->base_vector < 0) {
2540 dev_err(&pf->pdev->dev,
2541 "Failed to get tracking for %d vectors for VSI %d, err=%d\n",
2542 num_q_vectors, vsi->vsi_num, vsi->base_vector);
2550 * ice_fill_rss_lut - Fill the RSS lookup table with default values
2551 * @lut: Lookup table
2552 * @rss_table_size: Lookup table size
2553 * @rss_size: Range of queue number for hashing
2555 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2559 for (i = 0; i < rss_table_size; i++)
2560 lut[i] = i % rss_size;
2564 * ice_vsi_cfg_rss - Configure RSS params for a VSI
2565 * @vsi: VSI to be configured
2567 static int ice_vsi_cfg_rss(struct ice_vsi *vsi)
2569 u8 seed[ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE];
2570 struct ice_aqc_get_set_rss_keys *key;
2571 struct ice_pf *pf = vsi->back;
2572 enum ice_status status;
2576 vsi->rss_size = min_t(int, vsi->rss_size, vsi->num_rxq);
2578 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
2582 if (vsi->rss_lut_user)
2583 memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
2585 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
2587 status = ice_aq_set_rss_lut(&pf->hw, vsi->vsi_num, vsi->rss_lut_type,
2588 lut, vsi->rss_table_size);
2591 dev_err(&vsi->back->pdev->dev,
2592 "set_rss_lut failed, error %d\n", status);
2594 goto ice_vsi_cfg_rss_exit;
2597 key = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*key), GFP_KERNEL);
2600 goto ice_vsi_cfg_rss_exit;
2603 if (vsi->rss_hkey_user)
2604 memcpy(seed, vsi->rss_hkey_user,
2605 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
2607 netdev_rss_key_fill((void *)seed,
2608 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
2609 memcpy(&key->standard_rss_key, seed,
2610 ICE_AQC_GET_SET_RSS_KEY_DATA_RSS_KEY_SIZE);
2612 status = ice_aq_set_rss_key(&pf->hw, vsi->vsi_num, key);
2615 dev_err(&vsi->back->pdev->dev, "set_rss_key failed, error %d\n",
2620 devm_kfree(&pf->pdev->dev, key);
2621 ice_vsi_cfg_rss_exit:
2622 devm_kfree(&pf->pdev->dev, lut);
2627 * ice_vsi_reinit_setup - return resource and reallocate resource for a VSI
2628 * @vsi: pointer to the ice_vsi
2630 * This reallocates the VSIs queue resources
2632 * Returns 0 on success and negative value on failure
2634 static int ice_vsi_reinit_setup(struct ice_vsi *vsi)
2636 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2642 ice_vsi_free_q_vectors(vsi);
2643 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
2644 vsi->base_vector = 0;
2645 ice_vsi_clear_rings(vsi);
2646 ice_vsi_free_arrays(vsi, false);
2647 ice_vsi_set_num_qs(vsi);
2649 /* Initialize VSI struct elements and create VSI in FW */
2650 ret = ice_vsi_add(vsi);
2654 ret = ice_vsi_alloc_arrays(vsi, false);
2658 switch (vsi->type) {
2661 ret = ice_cfg_netdev(vsi);
2665 ret = register_netdev(vsi->netdev);
2669 netif_carrier_off(vsi->netdev);
2670 netif_tx_stop_all_queues(vsi->netdev);
2673 ret = ice_vsi_alloc_q_vectors(vsi);
2677 ret = ice_vsi_setup_vector_base(vsi);
2681 ret = ice_vsi_alloc_rings(vsi);
2685 ice_vsi_map_rings_to_vectors(vsi);
2691 ice_vsi_set_tc_cfg(vsi);
2693 /* configure VSI nodes based on number of queues and TC's */
2694 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2695 max_txqs[i] = vsi->num_txq;
2697 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->vsi_num,
2698 vsi->tc_cfg.ena_tc, max_txqs);
2700 dev_info(&vsi->back->pdev->dev,
2701 "Failed VSI lan queue config\n");
2707 ice_vsi_free_q_vectors(vsi);
2710 vsi->current_netdev_flags = 0;
2711 unregister_netdev(vsi->netdev);
2712 free_netdev(vsi->netdev);
2717 set_bit(__ICE_RESET_FAILED, vsi->back->state);
2722 * ice_vsi_setup - Set up a VSI by a given type
2723 * @pf: board private structure
2725 * @pi: pointer to the port_info instance
2727 * This allocates the sw VSI structure and its queue resources.
2729 * Returns pointer to the successfully allocated and configure VSI sw struct on
2730 * success, otherwise returns NULL on failure.
2732 static struct ice_vsi *
2733 ice_vsi_setup(struct ice_pf *pf, enum ice_vsi_type type,
2734 struct ice_port_info *pi)
2736 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2737 struct device *dev = &pf->pdev->dev;
2738 struct ice_vsi_ctx ctxt = { 0 };
2739 struct ice_vsi *vsi;
2742 vsi = ice_vsi_alloc(pf, type);
2744 dev_err(dev, "could not allocate VSI\n");
2748 vsi->port_info = pi;
2749 vsi->vsw = pf->first_sw;
2751 if (ice_vsi_get_qs(vsi)) {
2752 dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n",
2757 /* set RSS capabilities */
2758 ice_vsi_set_rss_params(vsi);
2760 /* create the VSI */
2761 ret = ice_vsi_add(vsi);
2765 ctxt.vsi_num = vsi->vsi_num;
2767 switch (vsi->type) {
2769 ret = ice_cfg_netdev(vsi);
2771 goto err_cfg_netdev;
2773 ret = register_netdev(vsi->netdev);
2775 goto err_register_netdev;
2777 netif_carrier_off(vsi->netdev);
2779 /* make sure transmit queues start off as stopped */
2780 netif_tx_stop_all_queues(vsi->netdev);
2781 ret = ice_vsi_alloc_q_vectors(vsi);
2785 ret = ice_vsi_setup_vector_base(vsi);
2789 ret = ice_vsi_alloc_rings(vsi);
2793 ice_vsi_map_rings_to_vectors(vsi);
2795 /* Do not exit if configuring RSS had an issue, at least
2796 * receive traffic on first queue. Hence no need to capture
2799 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2800 ice_vsi_cfg_rss(vsi);
2803 /* if vsi type is not recognized, clean up the resources and
2809 ice_vsi_set_tc_cfg(vsi);
2811 /* configure VSI nodes based on number of queues and TC's */
2812 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2813 max_txqs[i] = vsi->num_txq;
2815 ret = ice_cfg_vsi_lan(vsi->port_info, vsi->vsi_num,
2816 vsi->tc_cfg.ena_tc, max_txqs);
2818 dev_info(&pf->pdev->dev, "Failed VSI lan queue config\n");
2825 ice_vsi_free_q_vectors(vsi);
2827 if (vsi->netdev && vsi->netdev->reg_state == NETREG_REGISTERED)
2828 unregister_netdev(vsi->netdev);
2829 err_register_netdev:
2831 free_netdev(vsi->netdev);
2835 ret = ice_aq_free_vsi(&pf->hw, &ctxt, false, NULL);
2837 dev_err(&vsi->back->pdev->dev,
2838 "Free VSI AQ call failed, err %d\n", ret);
2840 ice_vsi_put_qs(vsi);
2842 pf->q_left_tx += vsi->alloc_txq;
2843 pf->q_left_rx += vsi->alloc_rxq;
2850 * ice_vsi_add_vlan - Add vsi membership for given vlan
2851 * @vsi: the vsi being configured
2852 * @vid: vlan id to be added
2854 static int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
2856 struct ice_fltr_list_entry *tmp;
2857 struct ice_pf *pf = vsi->back;
2858 LIST_HEAD(tmp_add_list);
2859 enum ice_status status;
2862 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
2866 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
2867 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2868 tmp->fltr_info.flag = ICE_FLTR_TX;
2869 tmp->fltr_info.src = vsi->vsi_num;
2870 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
2871 tmp->fltr_info.l_data.vlan.vlan_id = vid;
2873 INIT_LIST_HEAD(&tmp->list_entry);
2874 list_add(&tmp->list_entry, &tmp_add_list);
2876 status = ice_add_vlan(&pf->hw, &tmp_add_list);
2879 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
2883 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
2888 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload
2889 * @netdev: network interface to be adjusted
2890 * @proto: unused protocol
2891 * @vid: vlan id to be added
2893 * net_device_ops implementation for adding vlan ids
2895 static int ice_vlan_rx_add_vid(struct net_device *netdev,
2896 __always_unused __be16 proto, u16 vid)
2898 struct ice_netdev_priv *np = netdev_priv(netdev);
2899 struct ice_vsi *vsi = np->vsi;
2902 if (vid >= VLAN_N_VID) {
2903 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2911 /* Add all VLAN ids including 0 to the switch filter. VLAN id 0 is
2912 * needed to continue allowing all untagged packets since VLAN prune
2913 * list is applied to all packets by the switch
2915 ret = ice_vsi_add_vlan(vsi, vid);
2918 set_bit(vid, vsi->active_vlans);
2924 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
2925 * @vsi: the VSI being configured
2926 * @vid: VLAN id to be removed
2928 static void ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
2930 struct ice_fltr_list_entry *list;
2931 struct ice_pf *pf = vsi->back;
2932 LIST_HEAD(tmp_add_list);
2934 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
2938 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
2939 list->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
2940 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
2941 list->fltr_info.l_data.vlan.vlan_id = vid;
2942 list->fltr_info.flag = ICE_FLTR_TX;
2943 list->fltr_info.src = vsi->vsi_num;
2945 INIT_LIST_HEAD(&list->list_entry);
2946 list_add(&list->list_entry, &tmp_add_list);
2948 if (ice_remove_vlan(&pf->hw, &tmp_add_list))
2949 dev_err(&pf->pdev->dev, "Error removing VLAN %d on vsi %i\n",
2952 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
2956 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
2957 * @netdev: network interface to be adjusted
2958 * @proto: unused protocol
2959 * @vid: vlan id to be removed
2961 * net_device_ops implementation for removing vlan ids
2963 static int ice_vlan_rx_kill_vid(struct net_device *netdev,
2964 __always_unused __be16 proto, u16 vid)
2966 struct ice_netdev_priv *np = netdev_priv(netdev);
2967 struct ice_vsi *vsi = np->vsi;
2972 /* return code is ignored as there is nothing a user
2973 * can do about failure to remove and a log message was
2974 * already printed from the other function
2976 ice_vsi_kill_vlan(vsi, vid);
2978 clear_bit(vid, vsi->active_vlans);
2984 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2985 * @pf: board private structure
2987 * Returns 0 on success, negative value on failure
2989 static int ice_setup_pf_sw(struct ice_pf *pf)
2991 LIST_HEAD(tmp_add_list);
2992 u8 broadcast[ETH_ALEN];
2993 struct ice_vsi *vsi;
2996 if (!ice_is_reset_recovery_pending(pf->state)) {
2997 vsi = ice_vsi_setup(pf, ICE_VSI_PF, pf->hw.port_info);
3004 status = ice_vsi_reinit_setup(vsi);
3009 /* tmp_add_list contains a list of MAC addresses for which MAC
3010 * filters need to be programmed. Add the VSI's unicast MAC to
3013 status = ice_add_mac_to_list(vsi, &tmp_add_list,
3014 vsi->port_info->mac.perm_addr);
3018 /* VSI needs to receive broadcast traffic, so add the broadcast
3019 * MAC address to the list.
3021 eth_broadcast_addr(broadcast);
3022 status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
3026 /* program MAC filters for entries in tmp_add_list */
3027 status = ice_add_mac(&pf->hw, &tmp_add_list);
3029 dev_err(&pf->pdev->dev, "Could not add MAC filters\n");
3034 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
3038 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
3041 ice_vsi_free_q_vectors(vsi);
3042 if (vsi->netdev && vsi->netdev->reg_state == NETREG_REGISTERED)
3043 unregister_netdev(vsi->netdev);
3045 free_netdev(vsi->netdev);
3049 ice_vsi_delete(vsi);
3050 ice_vsi_put_qs(vsi);
3051 pf->q_left_tx += vsi->alloc_txq;
3052 pf->q_left_rx += vsi->alloc_rxq;
3059 * ice_determine_q_usage - Calculate queue distribution
3060 * @pf: board private structure
3062 * Return -ENOMEM if we don't get enough queues for all ports
3064 static void ice_determine_q_usage(struct ice_pf *pf)
3066 u16 q_left_tx, q_left_rx;
3068 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
3069 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
3071 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
3073 /* only 1 rx queue unless RSS is enabled */
3074 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3077 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
3079 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
3080 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
3084 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3085 * @pf: board private structure to initialize
3087 static void ice_deinit_pf(struct ice_pf *pf)
3089 if (pf->serv_tmr.function)
3090 del_timer_sync(&pf->serv_tmr);
3091 if (pf->serv_task.func)
3092 cancel_work_sync(&pf->serv_task);
3093 mutex_destroy(&pf->sw_mutex);
3094 mutex_destroy(&pf->avail_q_mutex);
3098 * ice_init_pf - Initialize general software structures (struct ice_pf)
3099 * @pf: board private structure to initialize
3101 static void ice_init_pf(struct ice_pf *pf)
3103 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
3104 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
3106 mutex_init(&pf->sw_mutex);
3107 mutex_init(&pf->avail_q_mutex);
3109 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
3110 mutex_lock(&pf->avail_q_mutex);
3111 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
3112 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
3113 mutex_unlock(&pf->avail_q_mutex);
3115 if (pf->hw.func_caps.common_cap.rss_table_size)
3116 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
3118 /* setup service timer and periodic service task */
3119 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
3120 pf->serv_tmr_period = HZ;
3121 INIT_WORK(&pf->serv_task, ice_service_task);
3122 clear_bit(__ICE_SERVICE_SCHED, pf->state);
3126 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
3127 * @pf: board private structure
3129 * compute the number of MSIX vectors required (v_budget) and request from
3130 * the OS. Return the number of vectors reserved or negative on failure
3132 static int ice_ena_msix_range(struct ice_pf *pf)
3134 int v_left, v_actual, v_budget = 0;
3137 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
3139 /* reserve one vector for miscellaneous handler */
3144 /* reserve vectors for LAN traffic */
3145 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
3146 v_budget += pf->num_lan_msix;
3148 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
3149 sizeof(struct msix_entry), GFP_KERNEL);
3151 if (!pf->msix_entries) {
3156 for (i = 0; i < v_budget; i++)
3157 pf->msix_entries[i].entry = i;
3159 /* actually reserve the vectors */
3160 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
3161 ICE_MIN_MSIX, v_budget);
3164 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
3169 if (v_actual < v_budget) {
3170 dev_warn(&pf->pdev->dev,
3171 "not enough vectors. requested = %d, obtained = %d\n",
3172 v_budget, v_actual);
3173 if (v_actual >= (pf->num_lan_msix + 1)) {
3174 pf->num_avail_msix = v_actual - (pf->num_lan_msix + 1);
3175 } else if (v_actual >= 2) {
3176 pf->num_lan_msix = 1;
3177 pf->num_avail_msix = v_actual - 2;
3179 pci_disable_msix(pf->pdev);
3188 devm_kfree(&pf->pdev->dev, pf->msix_entries);
3192 pf->num_lan_msix = 0;
3193 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
3198 * ice_dis_msix - Disable MSI-X interrupt setup in OS
3199 * @pf: board private structure
3201 static void ice_dis_msix(struct ice_pf *pf)
3203 pci_disable_msix(pf->pdev);
3204 devm_kfree(&pf->pdev->dev, pf->msix_entries);
3205 pf->msix_entries = NULL;
3206 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
3210 * ice_init_interrupt_scheme - Determine proper interrupt scheme
3211 * @pf: board private structure to initialize
3213 static int ice_init_interrupt_scheme(struct ice_pf *pf)
3218 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3219 vectors = ice_ena_msix_range(pf);
3226 /* set up vector assignment tracking */
3227 size = sizeof(struct ice_res_tracker) + (sizeof(u16) * vectors);
3229 pf->irq_tracker = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
3230 if (!pf->irq_tracker) {
3235 pf->irq_tracker->num_entries = vectors;
3241 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
3242 * @pf: board private structure
3244 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
3246 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3249 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
3250 pf->irq_tracker = NULL;
3254 * ice_probe - Device initialization routine
3255 * @pdev: PCI device information struct
3256 * @ent: entry in ice_pci_tbl
3258 * Returns 0 on success, negative on failure
3260 static int ice_probe(struct pci_dev *pdev,
3261 const struct pci_device_id __always_unused *ent)
3267 /* this driver uses devres, see Documentation/driver-model/devres.txt */
3268 err = pcim_enable_device(pdev);
3272 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
3274 dev_err(&pdev->dev, "I/O map error %d\n", err);
3278 pf = devm_kzalloc(&pdev->dev, sizeof(*pf), GFP_KERNEL);
3282 /* set up for high or low dma */
3283 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
3285 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
3287 dev_err(&pdev->dev, "DMA configuration failed: 0x%x\n", err);
3291 pci_enable_pcie_error_reporting(pdev);
3292 pci_set_master(pdev);
3295 pci_set_drvdata(pdev, pf);
3296 set_bit(__ICE_DOWN, pf->state);
3299 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
3301 hw->vendor_id = pdev->vendor;
3302 hw->device_id = pdev->device;
3303 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3304 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3305 hw->subsystem_device_id = pdev->subsystem_device;
3306 hw->bus.device = PCI_SLOT(pdev->devfn);
3307 hw->bus.func = PCI_FUNC(pdev->devfn);
3308 ice_set_ctrlq_len(hw);
3310 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
3312 #ifndef CONFIG_DYNAMIC_DEBUG
3314 hw->debug_mask = debug;
3317 err = ice_init_hw(hw);
3319 dev_err(&pdev->dev, "ice_init_hw failed: %d\n", err);
3321 goto err_exit_unroll;
3324 dev_info(&pdev->dev, "firmware %d.%d.%05d api %d.%d\n",
3325 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
3326 hw->api_maj_ver, hw->api_min_ver);
3330 ice_determine_q_usage(pf);
3332 pf->num_alloc_vsi = min_t(u16, ICE_MAX_VSI_ALLOC,
3333 hw->func_caps.guaranteed_num_vsi);
3334 if (!pf->num_alloc_vsi) {
3336 goto err_init_pf_unroll;
3339 pf->vsi = devm_kcalloc(&pdev->dev, pf->num_alloc_vsi,
3340 sizeof(struct ice_vsi *), GFP_KERNEL);
3343 goto err_init_pf_unroll;
3346 err = ice_init_interrupt_scheme(pf);
3349 "ice_init_interrupt_scheme failed: %d\n", err);
3351 goto err_init_interrupt_unroll;
3354 /* In case of MSIX we are going to setup the misc vector right here
3355 * to handle admin queue events etc. In case of legacy and MSI
3356 * the misc functionality and queue processing is combined in
3357 * the same vector and that gets setup at open.
3359 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3360 err = ice_req_irq_msix_misc(pf);
3363 "setup of misc vector failed: %d\n", err);
3364 goto err_init_interrupt_unroll;
3368 /* create switch struct for the switch element created by FW on boot */
3369 pf->first_sw = devm_kzalloc(&pdev->dev, sizeof(struct ice_sw),
3371 if (!pf->first_sw) {
3373 goto err_msix_misc_unroll;
3376 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
3377 pf->first_sw->pf = pf;
3379 /* record the sw_id available for later use */
3380 pf->first_sw->sw_id = hw->port_info->sw_id;
3382 err = ice_setup_pf_sw(pf);
3385 "probe failed due to setup pf switch:%d\n", err);
3386 goto err_alloc_sw_unroll;
3389 /* Driver is mostly up */
3390 clear_bit(__ICE_DOWN, pf->state);
3392 /* since everything is good, start the service timer */
3393 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3395 err = ice_init_link_events(pf->hw.port_info);
3397 dev_err(&pdev->dev, "ice_init_link_events failed: %d\n", err);
3398 goto err_alloc_sw_unroll;
3403 err_alloc_sw_unroll:
3404 set_bit(__ICE_DOWN, pf->state);
3405 devm_kfree(&pf->pdev->dev, pf->first_sw);
3406 err_msix_misc_unroll:
3407 ice_free_irq_msix_misc(pf);
3408 err_init_interrupt_unroll:
3409 ice_clear_interrupt_scheme(pf);
3410 devm_kfree(&pdev->dev, pf->vsi);
3415 pci_disable_pcie_error_reporting(pdev);
3420 * ice_remove - Device removal routine
3421 * @pdev: PCI device information struct
3423 static void ice_remove(struct pci_dev *pdev)
3425 struct ice_pf *pf = pci_get_drvdata(pdev);
3432 set_bit(__ICE_DOWN, pf->state);
3434 for (i = 0; i < pf->num_alloc_vsi; i++) {
3438 err = ice_vsi_release(pf->vsi[i]);
3440 dev_dbg(&pf->pdev->dev, "Failed to release VSI index %d (err %d)\n",
3444 ice_free_irq_msix_misc(pf);
3445 ice_clear_interrupt_scheme(pf);
3447 ice_deinit_hw(&pf->hw);
3448 pci_disable_pcie_error_reporting(pdev);
3451 /* ice_pci_tbl - PCI Device ID Table
3453 * Wildcard entries (PCI_ANY_ID) should come last
3454 * Last entry must be all 0s
3456 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3457 * Class, Class Mask, private data (not used) }
3459 static const struct pci_device_id ice_pci_tbl[] = {
3460 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_BACKPLANE), 0 },
3461 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_QSFP), 0 },
3462 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_SFP), 0 },
3463 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_10G_BASE_T), 0 },
3464 { PCI_VDEVICE(INTEL, ICE_DEV_ID_C810_SGMII), 0 },
3465 /* required last entry */
3468 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
3470 static struct pci_driver ice_driver = {
3471 .name = KBUILD_MODNAME,
3472 .id_table = ice_pci_tbl,
3474 .remove = ice_remove,
3478 * ice_module_init - Driver registration routine
3480 * ice_module_init is the first routine called when the driver is
3481 * loaded. All it does is register with the PCI subsystem.
3483 static int __init ice_module_init(void)
3487 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
3488 pr_info("%s\n", ice_copyright);
3490 ice_wq = alloc_ordered_workqueue("%s", WQ_MEM_RECLAIM, KBUILD_MODNAME);
3492 pr_err("Failed to create workqueue\n");
3496 status = pci_register_driver(&ice_driver);
3498 pr_err("failed to register pci driver, err %d\n", status);
3499 destroy_workqueue(ice_wq);
3504 module_init(ice_module_init);
3507 * ice_module_exit - Driver exit cleanup routine
3509 * ice_module_exit is called just before the driver is removed
3512 static void __exit ice_module_exit(void)
3514 pci_unregister_driver(&ice_driver);
3515 destroy_workqueue(ice_wq);
3516 pr_info("module unloaded\n");
3518 module_exit(ice_module_exit);
3521 * ice_set_mac_address - NDO callback to set mac address
3522 * @netdev: network interface device structure
3523 * @pi: pointer to an address structure
3525 * Returns 0 on success, negative on failure
3527 static int ice_set_mac_address(struct net_device *netdev, void *pi)
3529 struct ice_netdev_priv *np = netdev_priv(netdev);
3530 struct ice_vsi *vsi = np->vsi;
3531 struct ice_pf *pf = vsi->back;
3532 struct ice_hw *hw = &pf->hw;
3533 struct sockaddr *addr = pi;
3534 enum ice_status status;
3535 LIST_HEAD(a_mac_list);
3536 LIST_HEAD(r_mac_list);
3541 mac = (u8 *)addr->sa_data;
3543 if (!is_valid_ether_addr(mac))
3544 return -EADDRNOTAVAIL;
3546 if (ether_addr_equal(netdev->dev_addr, mac)) {
3547 netdev_warn(netdev, "already using mac %pM\n", mac);
3551 if (test_bit(__ICE_DOWN, pf->state) ||
3552 ice_is_reset_recovery_pending(pf->state)) {
3553 netdev_err(netdev, "can't set mac %pM. device not ready\n",
3558 /* When we change the mac address we also have to change the mac address
3559 * based filter rules that were created previously for the old mac
3560 * address. So first, we remove the old filter rule using ice_remove_mac
3561 * and then create a new filter rule using ice_add_mac. Note that for
3562 * both these operations, we first need to form a "list" of mac
3563 * addresses (even though in this case, we have only 1 mac address to be
3564 * added/removed) and this done using ice_add_mac_to_list. Depending on
3565 * the ensuing operation this "list" of mac addresses is either to be
3566 * added or removed from the filter.
3568 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
3570 err = -EADDRNOTAVAIL;
3574 status = ice_remove_mac(hw, &r_mac_list);
3576 err = -EADDRNOTAVAIL;
3580 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
3582 err = -EADDRNOTAVAIL;
3586 status = ice_add_mac(hw, &a_mac_list);
3588 err = -EADDRNOTAVAIL;
3593 /* free list entries */
3594 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
3595 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
3598 netdev_err(netdev, "can't set mac %pM. filter update failed\n",
3603 /* change the netdev's mac address */
3604 memcpy(netdev->dev_addr, mac, netdev->addr_len);
3605 netdev_dbg(vsi->netdev, "updated mac address to %pM\n",
3608 /* write new mac address to the firmware */
3609 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3610 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
3612 netdev_err(netdev, "can't set mac %pM. write to firmware failed.\n",
3619 * ice_set_rx_mode - NDO callback to set the netdev filters
3620 * @netdev: network interface device structure
3622 static void ice_set_rx_mode(struct net_device *netdev)
3624 struct ice_netdev_priv *np = netdev_priv(netdev);
3625 struct ice_vsi *vsi = np->vsi;
3630 /* Set the flags to synchronize filters
3631 * ndo_set_rx_mode may be triggered even without a change in netdev
3634 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
3635 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
3636 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
3638 /* schedule our worker thread which will take care of
3639 * applying the new filter changes
3641 ice_service_task_schedule(vsi->back);
3645 * ice_fdb_add - add an entry to the hardware database
3646 * @ndm: the input from the stack
3647 * @tb: pointer to array of nladdr (unused)
3648 * @dev: the net device pointer
3649 * @addr: the MAC address entry being added
3651 * @flags: instructions from stack about fdb operation
3653 static int ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
3654 struct net_device *dev, const unsigned char *addr,
3660 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3663 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
3664 netdev_err(dev, "FDB only supports static addresses\n");
3668 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
3669 err = dev_uc_add_excl(dev, addr);
3670 else if (is_multicast_ether_addr(addr))
3671 err = dev_mc_add_excl(dev, addr);
3675 /* Only return duplicate errors if NLM_F_EXCL is set */
3676 if (err == -EEXIST && !(flags & NLM_F_EXCL))
3683 * ice_fdb_del - delete an entry from the hardware database
3684 * @ndm: the input from the stack
3685 * @tb: pointer to array of nladdr (unused)
3686 * @dev: the net device pointer
3687 * @addr: the MAC address entry being added
3690 static int ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
3691 struct net_device *dev, const unsigned char *addr,
3692 __always_unused u16 vid)
3696 if (ndm->ndm_state & NUD_PERMANENT) {
3697 netdev_err(dev, "FDB only supports static addresses\n");
3701 if (is_unicast_ether_addr(addr))
3702 err = dev_uc_del(dev, addr);
3703 else if (is_multicast_ether_addr(addr))
3704 err = dev_mc_del(dev, addr);
3712 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
3713 * @vsi: the vsi being changed
3715 static int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
3717 struct device *dev = &vsi->back->pdev->dev;
3718 struct ice_hw *hw = &vsi->back->hw;
3719 struct ice_vsi_ctx ctxt = { 0 };
3720 enum ice_status status;
3722 /* Here we are configuring the VSI to let the driver add VLAN tags by
3723 * setting port_vlan_flags to ICE_AQ_VSI_PVLAN_MODE_ALL. The actual VLAN
3724 * tag insertion happens in the Tx hot path, in ice_tx_map.
3726 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_MODE_ALL;
3728 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
3729 ctxt.vsi_num = vsi->vsi_num;
3731 status = ice_aq_update_vsi(hw, &ctxt, NULL);
3733 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
3734 status, hw->adminq.sq_last_status);
3738 vsi->info.port_vlan_flags = ctxt.info.port_vlan_flags;
3743 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
3744 * @vsi: the vsi being changed
3745 * @ena: boolean value indicating if this is a enable or disable request
3747 static int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
3749 struct device *dev = &vsi->back->pdev->dev;
3750 struct ice_hw *hw = &vsi->back->hw;
3751 struct ice_vsi_ctx ctxt = { 0 };
3752 enum ice_status status;
3754 /* Here we are configuring what the VSI should do with the VLAN tag in
3755 * the Rx packet. We can either leave the tag in the packet or put it in
3756 * the Rx descriptor.
3759 /* Strip VLAN tag from Rx packet and put it in the desc */
3760 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_EMOD_STR_BOTH;
3762 /* Disable stripping. Leave tag in packet */
3763 ctxt.info.port_vlan_flags = ICE_AQ_VSI_PVLAN_EMOD_NOTHING;
3766 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
3767 ctxt.vsi_num = vsi->vsi_num;
3769 status = ice_aq_update_vsi(hw, &ctxt, NULL);
3771 dev_err(dev, "update VSI for VALN strip failed, ena = %d err %d aq_err %d\n",
3772 ena, status, hw->adminq.sq_last_status);
3776 vsi->info.port_vlan_flags = ctxt.info.port_vlan_flags;
3781 * ice_set_features - set the netdev feature flags
3782 * @netdev: ptr to the netdev being adjusted
3783 * @features: the feature set that the stack is suggesting
3785 static int ice_set_features(struct net_device *netdev,
3786 netdev_features_t features)
3788 struct ice_netdev_priv *np = netdev_priv(netdev);
3789 struct ice_vsi *vsi = np->vsi;
3792 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
3793 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3794 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3795 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
3796 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3797 ret = ice_vsi_manage_vlan_stripping(vsi, false);
3798 else if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
3799 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3800 ret = ice_vsi_manage_vlan_insertion(vsi);
3801 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
3802 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3803 ret = ice_vsi_manage_vlan_insertion(vsi);
3809 * ice_vsi_vlan_setup - Setup vlan offload properties on a VSI
3810 * @vsi: VSI to setup vlan properties for
3812 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
3816 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3817 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3818 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
3819 ret = ice_vsi_manage_vlan_insertion(vsi);
3825 * ice_restore_vlan - Reinstate VLANs when vsi/netdev comes back up
3826 * @vsi: the VSI being brought back up
3828 static int ice_restore_vlan(struct ice_vsi *vsi)
3836 err = ice_vsi_vlan_setup(vsi);
3840 for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID) {
3841 err = ice_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q), vid);
3850 * ice_setup_tx_ctx - setup a struct ice_tlan_ctx instance
3851 * @ring: The Tx ring to configure
3852 * @tlan_ctx: Pointer to the Tx LAN queue context structure to be initialized
3853 * @pf_q: queue index in the PF space
3855 * Configure the Tx descriptor ring in TLAN context.
3858 ice_setup_tx_ctx(struct ice_ring *ring, struct ice_tlan_ctx *tlan_ctx, u16 pf_q)
3860 struct ice_vsi *vsi = ring->vsi;
3861 struct ice_hw *hw = &vsi->back->hw;
3863 tlan_ctx->base = ring->dma >> ICE_TLAN_CTX_BASE_S;
3865 tlan_ctx->port_num = vsi->port_info->lport;
3867 /* Transmit Queue Length */
3868 tlan_ctx->qlen = ring->count;
3871 tlan_ctx->pf_num = hw->pf_id;
3873 /* queue belongs to a specific VSI type
3874 * VF / VM index should be programmed per vmvf_type setting:
3875 * for vmvf_type = VF, it is VF number between 0-256
3876 * for vmvf_type = VM, it is VM number between 0-767
3877 * for PF or EMP this field should be set to zero
3879 switch (vsi->type) {
3881 tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
3887 /* make sure the context is associated with the right VSI */
3888 tlan_ctx->src_vsi = vsi->vsi_num;
3890 tlan_ctx->tso_ena = ICE_TX_LEGACY;
3891 tlan_ctx->tso_qnum = pf_q;
3893 /* Legacy or Advanced Host Interface:
3894 * 0: Advanced Host Interface
3895 * 1: Legacy Host Interface
3897 tlan_ctx->legacy_int = ICE_TX_LEGACY;
3901 * ice_vsi_cfg_txqs - Configure the VSI for Tx
3902 * @vsi: the VSI being configured
3904 * Return 0 on success and a negative value on error
3905 * Configure the Tx VSI for operation.
3907 static int ice_vsi_cfg_txqs(struct ice_vsi *vsi)
3909 struct ice_aqc_add_tx_qgrp *qg_buf;
3910 struct ice_aqc_add_txqs_perq *txq;
3911 struct ice_pf *pf = vsi->back;
3912 enum ice_status status;
3913 u16 buf_len, i, pf_q;
3914 int err = 0, tc = 0;
3917 buf_len = sizeof(struct ice_aqc_add_tx_qgrp);
3918 qg_buf = devm_kzalloc(&pf->pdev->dev, buf_len, GFP_KERNEL);
3922 if (vsi->num_txq > ICE_MAX_TXQ_PER_TXQG) {
3926 qg_buf->num_txqs = 1;
3929 /* set up and configure the tx queues */
3930 ice_for_each_txq(vsi, i) {
3931 struct ice_tlan_ctx tlan_ctx = { 0 };
3933 pf_q = vsi->txq_map[i];
3934 ice_setup_tx_ctx(vsi->tx_rings[i], &tlan_ctx, pf_q);
3935 /* copy context contents into the qg_buf */
3936 qg_buf->txqs[0].txq_id = cpu_to_le16(pf_q);
3937 ice_set_ctx((u8 *)&tlan_ctx, qg_buf->txqs[0].txq_ctx,
3940 /* init queue specific tail reg. It is referred as transmit
3941 * comm scheduler queue doorbell.
3943 vsi->tx_rings[i]->tail = pf->hw.hw_addr + QTX_COMM_DBELL(pf_q);
3944 status = ice_ena_vsi_txq(vsi->port_info, vsi->vsi_num, tc,
3945 num_q_grps, qg_buf, buf_len, NULL);
3947 dev_err(&vsi->back->pdev->dev,
3948 "Failed to set LAN Tx queue context, error: %d\n",
3954 /* Add Tx Queue TEID into the VSI tx ring from the response
3955 * This will complete configuring and enabling the queue.
3957 txq = &qg_buf->txqs[0];
3958 if (pf_q == le16_to_cpu(txq->txq_id))
3959 vsi->tx_rings[i]->txq_teid =
3960 le32_to_cpu(txq->q_teid);
3963 devm_kfree(&pf->pdev->dev, qg_buf);
3968 * ice_setup_rx_ctx - Configure a receive ring context
3969 * @ring: The Rx ring to configure
3971 * Configure the Rx descriptor ring in RLAN context.
3973 static int ice_setup_rx_ctx(struct ice_ring *ring)
3975 struct ice_vsi *vsi = ring->vsi;
3976 struct ice_hw *hw = &vsi->back->hw;
3977 u32 rxdid = ICE_RXDID_FLEX_NIC;
3978 struct ice_rlan_ctx rlan_ctx;
3983 /* what is RX queue number in global space of 2K rx queues */
3984 pf_q = vsi->rxq_map[ring->q_index];
3986 /* clear the context structure first */
3987 memset(&rlan_ctx, 0, sizeof(rlan_ctx));
3989 rlan_ctx.base = ring->dma >> 7;
3991 rlan_ctx.qlen = ring->count;
3993 /* Receive Packet Data Buffer Size.
3994 * The Packet Data Buffer Size is defined in 128 byte units.
3996 rlan_ctx.dbuf = vsi->rx_buf_len >> ICE_RLAN_CTX_DBUF_S;
3998 /* use 32 byte descriptors */
4001 /* Strip the Ethernet CRC bytes before the packet is posted to host
4004 rlan_ctx.crcstrip = 1;
4006 /* L2TSEL flag defines the reported L2 Tags in the receive descriptor */
4007 rlan_ctx.l2tsel = 1;
4009 rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
4010 rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;
4011 rlan_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_NO_SPLIT;
4013 /* This controls whether VLAN is stripped from inner headers
4014 * The VLAN in the inner L2 header is stripped to the receive
4015 * descriptor if enabled by this flag.
4017 rlan_ctx.showiv = 0;
4019 /* Max packet size for this queue - must not be set to a larger value
4022 rlan_ctx.rxmax = min_t(u16, vsi->max_frame,
4023 ICE_MAX_CHAINED_RX_BUFS * vsi->rx_buf_len);
4025 /* Rx queue threshold in units of 64 */
4026 rlan_ctx.lrxqthresh = 1;
4028 /* Enable Flexible Descriptors in the queue context which
4029 * allows this driver to select a specific receive descriptor format
4031 regval = rd32(hw, QRXFLXP_CNTXT(pf_q));
4032 regval |= (rxdid << QRXFLXP_CNTXT_RXDID_IDX_S) &
4033 QRXFLXP_CNTXT_RXDID_IDX_M;
4035 /* increasing context priority to pick up profile id;
4036 * default is 0x01; setting to 0x03 to ensure profile
4037 * is programming if prev context is of same priority
4039 regval |= (0x03 << QRXFLXP_CNTXT_RXDID_PRIO_S) &
4040 QRXFLXP_CNTXT_RXDID_PRIO_M;
4042 wr32(hw, QRXFLXP_CNTXT(pf_q), regval);
4044 /* Absolute queue number out of 2K needs to be passed */
4045 err = ice_write_rxq_ctx(hw, &rlan_ctx, pf_q);
4047 dev_err(&vsi->back->pdev->dev,
4048 "Failed to set LAN Rx queue context for absolute Rx queue %d error: %d\n",
4053 /* init queue specific tail register */
4054 ring->tail = hw->hw_addr + QRX_TAIL(pf_q);
4055 writel(0, ring->tail);
4056 ice_alloc_rx_bufs(ring, ICE_DESC_UNUSED(ring));
4062 * ice_vsi_cfg_rxqs - Configure the VSI for Rx
4063 * @vsi: the VSI being configured
4065 * Return 0 on success and a negative value on error
4066 * Configure the Rx VSI for operation.
4068 static int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
4073 if (vsi->netdev && vsi->netdev->mtu > ETH_DATA_LEN)
4074 vsi->max_frame = vsi->netdev->mtu +
4075 ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
4077 vsi->max_frame = ICE_RXBUF_2048;
4079 vsi->rx_buf_len = ICE_RXBUF_2048;
4080 /* set up individual rings */
4081 for (i = 0; i < vsi->num_rxq && !err; i++)
4082 err = ice_setup_rx_ctx(vsi->rx_rings[i]);
4085 dev_err(&vsi->back->pdev->dev, "ice_setup_rx_ctx failed\n");
4092 * ice_vsi_cfg - Setup the VSI
4093 * @vsi: the VSI being configured
4095 * Return 0 on success and negative value on error
4097 static int ice_vsi_cfg(struct ice_vsi *vsi)
4101 ice_set_rx_mode(vsi->netdev);
4103 err = ice_restore_vlan(vsi);
4107 err = ice_vsi_cfg_txqs(vsi);
4109 err = ice_vsi_cfg_rxqs(vsi);
4115 * ice_vsi_stop_tx_rings - Disable Tx rings
4116 * @vsi: the VSI being configured
4118 static int ice_vsi_stop_tx_rings(struct ice_vsi *vsi)
4120 struct ice_pf *pf = vsi->back;
4121 struct ice_hw *hw = &pf->hw;
4122 enum ice_status status;
4127 if (vsi->num_txq > ICE_LAN_TXQ_MAX_QDIS)
4130 q_teids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_teids),
4135 q_ids = devm_kcalloc(&pf->pdev->dev, vsi->num_txq, sizeof(*q_ids),
4139 goto err_alloc_q_ids;
4142 /* set up the tx queue list to be disabled */
4143 ice_for_each_txq(vsi, i) {
4146 if (!vsi->tx_rings || !vsi->tx_rings[i]) {
4151 q_ids[i] = vsi->txq_map[i];
4152 q_teids[i] = vsi->tx_rings[i]->txq_teid;
4154 /* clear cause_ena bit for disabled queues */
4155 val = rd32(hw, QINT_TQCTL(vsi->tx_rings[i]->reg_idx));
4156 val &= ~QINT_TQCTL_CAUSE_ENA_M;
4157 wr32(hw, QINT_TQCTL(vsi->tx_rings[i]->reg_idx), val);
4159 /* software is expected to wait for 100 ns */
4162 /* trigger a software interrupt for the vector associated to
4163 * the queue to schedule napi handler
4165 v_idx = vsi->tx_rings[i]->q_vector->v_idx;
4166 wr32(hw, GLINT_DYN_CTL(vsi->base_vector + v_idx),
4167 GLINT_DYN_CTL_SWINT_TRIG_M | GLINT_DYN_CTL_INTENA_MSK_M);
4169 status = ice_dis_vsi_txq(vsi->port_info, vsi->num_txq, q_ids, q_teids,
4172 dev_err(&pf->pdev->dev,
4173 "Failed to disable LAN Tx queues, error: %d\n",
4179 devm_kfree(&pf->pdev->dev, q_ids);
4182 devm_kfree(&pf->pdev->dev, q_teids);
4188 * ice_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
4189 * @pf: the PF being configured
4190 * @pf_q: the PF queue
4191 * @ena: enable or disable state of the queue
4193 * This routine will wait for the given Rx queue of the PF to reach the
4194 * enabled or disabled state.
4195 * Returns -ETIMEDOUT in case of failing to reach the requested state after
4196 * multiple retries; else will return 0 in case of success.
4198 static int ice_pf_rxq_wait(struct ice_pf *pf, int pf_q, bool ena)
4202 for (i = 0; i < ICE_Q_WAIT_RETRY_LIMIT; i++) {
4203 u32 rx_reg = rd32(&pf->hw, QRX_CTRL(pf_q));
4205 if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
4208 usleep_range(10, 20);
4210 if (i >= ICE_Q_WAIT_RETRY_LIMIT)
4217 * ice_vsi_ctrl_rx_rings - Start or stop a VSI's rx rings
4218 * @vsi: the VSI being configured
4219 * @ena: start or stop the rx rings
4221 static int ice_vsi_ctrl_rx_rings(struct ice_vsi *vsi, bool ena)
4223 struct ice_pf *pf = vsi->back;
4224 struct ice_hw *hw = &pf->hw;
4227 for (i = 0; i < vsi->num_rxq; i++) {
4228 int pf_q = vsi->rxq_map[i];
4231 for (j = 0; j < ICE_Q_WAIT_MAX_RETRY; j++) {
4232 rx_reg = rd32(hw, QRX_CTRL(pf_q));
4233 if (((rx_reg >> QRX_CTRL_QENA_REQ_S) & 1) ==
4234 ((rx_reg >> QRX_CTRL_QENA_STAT_S) & 1))
4236 usleep_range(1000, 2000);
4239 /* Skip if the queue is already in the requested state */
4240 if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
4243 /* turn on/off the queue */
4245 rx_reg |= QRX_CTRL_QENA_REQ_M;
4247 rx_reg &= ~QRX_CTRL_QENA_REQ_M;
4248 wr32(hw, QRX_CTRL(pf_q), rx_reg);
4250 /* wait for the change to finish */
4251 ret = ice_pf_rxq_wait(pf, pf_q, ena);
4253 dev_err(&pf->pdev->dev,
4254 "VSI idx %d Rx ring %d %sable timeout\n",
4255 vsi->idx, pf_q, (ena ? "en" : "dis"));
4264 * ice_vsi_start_rx_rings - start VSI's rx rings
4265 * @vsi: the VSI whose rings are to be started
4267 * Returns 0 on success and a negative value on error
4269 static int ice_vsi_start_rx_rings(struct ice_vsi *vsi)
4271 return ice_vsi_ctrl_rx_rings(vsi, true);
4275 * ice_vsi_stop_rx_rings - stop VSI's rx rings
4278 * Returns 0 on success and a negative value on error
4280 static int ice_vsi_stop_rx_rings(struct ice_vsi *vsi)
4282 return ice_vsi_ctrl_rx_rings(vsi, false);
4286 * ice_vsi_stop_tx_rx_rings - stop VSI's tx and rx rings
4288 * Returns 0 on success and a negative value on error
4290 static int ice_vsi_stop_tx_rx_rings(struct ice_vsi *vsi)
4294 err_tx = ice_vsi_stop_tx_rings(vsi);
4296 dev_dbg(&vsi->back->pdev->dev, "Failed to disable Tx rings\n");
4298 err_rx = ice_vsi_stop_rx_rings(vsi);
4300 dev_dbg(&vsi->back->pdev->dev, "Failed to disable Rx rings\n");
4302 if (err_tx || err_rx)
4309 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4310 * @vsi: the VSI being configured
4312 static void ice_napi_enable_all(struct ice_vsi *vsi)
4319 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
4320 napi_enable(&vsi->q_vectors[q_idx]->napi);
4324 * ice_up_complete - Finish the last steps of bringing up a connection
4325 * @vsi: The VSI being configured
4327 * Return 0 on success and negative value on error
4329 static int ice_up_complete(struct ice_vsi *vsi)
4331 struct ice_pf *pf = vsi->back;
4334 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
4335 ice_vsi_cfg_msix(vsi);
4339 /* Enable only Rx rings, Tx rings were enabled by the FW when the
4340 * Tx queue group list was configured and the context bits were
4341 * programmed using ice_vsi_cfg_txqs
4343 err = ice_vsi_start_rx_rings(vsi);
4347 clear_bit(__ICE_DOWN, vsi->state);
4348 ice_napi_enable_all(vsi);
4349 ice_vsi_ena_irq(vsi);
4351 if (vsi->port_info &&
4352 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
4354 ice_print_link_msg(vsi, true);
4355 netif_tx_start_all_queues(vsi->netdev);
4356 netif_carrier_on(vsi->netdev);
4359 ice_service_task_schedule(pf);
4365 * ice_up - Bring the connection back up after being down
4366 * @vsi: VSI being configured
4368 int ice_up(struct ice_vsi *vsi)
4372 err = ice_vsi_cfg(vsi);
4374 err = ice_up_complete(vsi);
4380 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
4381 * @ring: Tx or Rx ring to read stats from
4382 * @pkts: packets stats counter
4383 * @bytes: bytes stats counter
4385 * This function fetches stats from the ring considering the atomic operations
4386 * that needs to be performed to read u64 values in 32 bit machine.
4388 static void ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts,
4398 start = u64_stats_fetch_begin_irq(&ring->syncp);
4399 *pkts = ring->stats.pkts;
4400 *bytes = ring->stats.bytes;
4401 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
4405 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4406 * @hw: ptr to the hardware info
4407 * @hireg: high 32 bit HW register to read from
4408 * @loreg: low 32 bit HW register to read from
4409 * @prev_stat_loaded: bool to specify if previous stats are loaded
4410 * @prev_stat: ptr to previous loaded stat value
4411 * @cur_stat: ptr to current stat value
4413 static void ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
4414 bool prev_stat_loaded, u64 *prev_stat,
4419 new_data = rd32(hw, loreg);
4420 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
4422 /* device stats are not reset at PFR, they likely will not be zeroed
4423 * when the driver starts. So save the first values read and use them as
4424 * offsets to be subtracted from the raw values in order to report stats
4425 * that count from zero.
4427 if (!prev_stat_loaded)
4428 *prev_stat = new_data;
4429 if (likely(new_data >= *prev_stat))
4430 *cur_stat = new_data - *prev_stat;
4432 /* to manage the potential roll-over */
4433 *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
4434 *cur_stat &= 0xFFFFFFFFFFULL;
4438 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4439 * @hw: ptr to the hardware info
4440 * @reg: HW register to read from
4441 * @prev_stat_loaded: bool to specify if previous stats are loaded
4442 * @prev_stat: ptr to previous loaded stat value
4443 * @cur_stat: ptr to current stat value
4445 static void ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4446 u64 *prev_stat, u64 *cur_stat)
4450 new_data = rd32(hw, reg);
4452 /* device stats are not reset at PFR, they likely will not be zeroed
4453 * when the driver starts. So save the first values read and use them as
4454 * offsets to be subtracted from the raw values in order to report stats
4455 * that count from zero.
4457 if (!prev_stat_loaded)
4458 *prev_stat = new_data;
4459 if (likely(new_data >= *prev_stat))
4460 *cur_stat = new_data - *prev_stat;
4462 /* to manage the potential roll-over */
4463 *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
4467 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
4468 * @vsi: the VSI to be updated
4470 static void ice_update_eth_stats(struct ice_vsi *vsi)
4472 struct ice_eth_stats *prev_es, *cur_es;
4473 struct ice_hw *hw = &vsi->back->hw;
4474 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
4476 prev_es = &vsi->eth_stats_prev;
4477 cur_es = &vsi->eth_stats;
4479 ice_stat_update40(hw, GLV_GORCH(vsi_num), GLV_GORCL(vsi_num),
4480 vsi->stat_offsets_loaded, &prev_es->rx_bytes,
4483 ice_stat_update40(hw, GLV_UPRCH(vsi_num), GLV_UPRCL(vsi_num),
4484 vsi->stat_offsets_loaded, &prev_es->rx_unicast,
4485 &cur_es->rx_unicast);
4487 ice_stat_update40(hw, GLV_MPRCH(vsi_num), GLV_MPRCL(vsi_num),
4488 vsi->stat_offsets_loaded, &prev_es->rx_multicast,
4489 &cur_es->rx_multicast);
4491 ice_stat_update40(hw, GLV_BPRCH(vsi_num), GLV_BPRCL(vsi_num),
4492 vsi->stat_offsets_loaded, &prev_es->rx_broadcast,
4493 &cur_es->rx_broadcast);
4495 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
4496 &prev_es->rx_discards, &cur_es->rx_discards);
4498 ice_stat_update40(hw, GLV_GOTCH(vsi_num), GLV_GOTCL(vsi_num),
4499 vsi->stat_offsets_loaded, &prev_es->tx_bytes,
4502 ice_stat_update40(hw, GLV_UPTCH(vsi_num), GLV_UPTCL(vsi_num),
4503 vsi->stat_offsets_loaded, &prev_es->tx_unicast,
4504 &cur_es->tx_unicast);
4506 ice_stat_update40(hw, GLV_MPTCH(vsi_num), GLV_MPTCL(vsi_num),
4507 vsi->stat_offsets_loaded, &prev_es->tx_multicast,
4508 &cur_es->tx_multicast);
4510 ice_stat_update40(hw, GLV_BPTCH(vsi_num), GLV_BPTCL(vsi_num),
4511 vsi->stat_offsets_loaded, &prev_es->tx_broadcast,
4512 &cur_es->tx_broadcast);
4514 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
4515 &prev_es->tx_errors, &cur_es->tx_errors);
4517 vsi->stat_offsets_loaded = true;
4521 * ice_update_vsi_ring_stats - Update VSI stats counters
4522 * @vsi: the VSI to be updated
4524 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
4526 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
4527 struct ice_ring *ring;
4531 /* reset netdev stats */
4532 vsi_stats->tx_packets = 0;
4533 vsi_stats->tx_bytes = 0;
4534 vsi_stats->rx_packets = 0;
4535 vsi_stats->rx_bytes = 0;
4537 /* reset non-netdev (extended) stats */
4538 vsi->tx_restart = 0;
4540 vsi->tx_linearize = 0;
4541 vsi->rx_buf_failed = 0;
4542 vsi->rx_page_failed = 0;
4546 /* update Tx rings counters */
4547 ice_for_each_txq(vsi, i) {
4548 ring = READ_ONCE(vsi->tx_rings[i]);
4549 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4550 vsi_stats->tx_packets += pkts;
4551 vsi_stats->tx_bytes += bytes;
4552 vsi->tx_restart += ring->tx_stats.restart_q;
4553 vsi->tx_busy += ring->tx_stats.tx_busy;
4554 vsi->tx_linearize += ring->tx_stats.tx_linearize;
4557 /* update Rx rings counters */
4558 ice_for_each_rxq(vsi, i) {
4559 ring = READ_ONCE(vsi->rx_rings[i]);
4560 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4561 vsi_stats->rx_packets += pkts;
4562 vsi_stats->rx_bytes += bytes;
4563 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
4564 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
4571 * ice_update_vsi_stats - Update VSI stats counters
4572 * @vsi: the VSI to be updated
4574 static void ice_update_vsi_stats(struct ice_vsi *vsi)
4576 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
4577 struct ice_eth_stats *cur_es = &vsi->eth_stats;
4578 struct ice_pf *pf = vsi->back;
4580 if (test_bit(__ICE_DOWN, vsi->state) ||
4581 test_bit(__ICE_CFG_BUSY, pf->state))
4584 /* get stats as recorded by Tx/Rx rings */
4585 ice_update_vsi_ring_stats(vsi);
4587 /* get VSI stats as recorded by the hardware */
4588 ice_update_eth_stats(vsi);
4590 cur_ns->tx_errors = cur_es->tx_errors;
4591 cur_ns->rx_dropped = cur_es->rx_discards;
4592 cur_ns->tx_dropped = cur_es->tx_discards;
4593 cur_ns->multicast = cur_es->rx_multicast;
4595 /* update some more netdev stats if this is main VSI */
4596 if (vsi->type == ICE_VSI_PF) {
4597 cur_ns->rx_crc_errors = pf->stats.crc_errors;
4598 cur_ns->rx_errors = pf->stats.crc_errors +
4599 pf->stats.illegal_bytes;
4600 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
4605 * ice_update_pf_stats - Update PF port stats counters
4606 * @pf: PF whose stats needs to be updated
4608 static void ice_update_pf_stats(struct ice_pf *pf)
4610 struct ice_hw_port_stats *prev_ps, *cur_ps;
4611 struct ice_hw *hw = &pf->hw;
4614 prev_ps = &pf->stats_prev;
4615 cur_ps = &pf->stats;
4618 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
4619 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
4620 &cur_ps->eth.rx_bytes);
4622 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
4623 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
4624 &cur_ps->eth.rx_unicast);
4626 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
4627 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
4628 &cur_ps->eth.rx_multicast);
4630 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
4631 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
4632 &cur_ps->eth.rx_broadcast);
4634 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
4635 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
4636 &cur_ps->eth.tx_bytes);
4638 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
4639 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
4640 &cur_ps->eth.tx_unicast);
4642 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
4643 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
4644 &cur_ps->eth.tx_multicast);
4646 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
4647 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
4648 &cur_ps->eth.tx_broadcast);
4650 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
4651 &prev_ps->tx_dropped_link_down,
4652 &cur_ps->tx_dropped_link_down);
4654 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
4655 pf->stat_prev_loaded, &prev_ps->rx_size_64,
4656 &cur_ps->rx_size_64);
4658 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
4659 pf->stat_prev_loaded, &prev_ps->rx_size_127,
4660 &cur_ps->rx_size_127);
4662 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
4663 pf->stat_prev_loaded, &prev_ps->rx_size_255,
4664 &cur_ps->rx_size_255);
4666 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
4667 pf->stat_prev_loaded, &prev_ps->rx_size_511,
4668 &cur_ps->rx_size_511);
4670 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
4671 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
4672 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
4674 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
4675 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
4676 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
4678 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
4679 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
4680 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
4682 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
4683 pf->stat_prev_loaded, &prev_ps->tx_size_64,
4684 &cur_ps->tx_size_64);
4686 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
4687 pf->stat_prev_loaded, &prev_ps->tx_size_127,
4688 &cur_ps->tx_size_127);
4690 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
4691 pf->stat_prev_loaded, &prev_ps->tx_size_255,
4692 &cur_ps->tx_size_255);
4694 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
4695 pf->stat_prev_loaded, &prev_ps->tx_size_511,
4696 &cur_ps->tx_size_511);
4698 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
4699 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
4700 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
4702 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
4703 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
4704 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
4706 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
4707 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
4708 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
4710 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
4711 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
4713 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
4714 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
4716 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
4717 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
4719 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
4720 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
4722 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
4723 &prev_ps->crc_errors, &cur_ps->crc_errors);
4725 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
4726 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
4728 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
4729 &prev_ps->mac_local_faults,
4730 &cur_ps->mac_local_faults);
4732 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
4733 &prev_ps->mac_remote_faults,
4734 &cur_ps->mac_remote_faults);
4736 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
4737 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
4739 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
4740 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
4742 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
4743 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
4745 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
4746 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
4748 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
4749 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
4751 pf->stat_prev_loaded = true;
4755 * ice_get_stats64 - get statistics for network device structure
4756 * @netdev: network interface device structure
4757 * @stats: main device statistics structure
4760 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
4762 struct ice_netdev_priv *np = netdev_priv(netdev);
4763 struct rtnl_link_stats64 *vsi_stats;
4764 struct ice_vsi *vsi = np->vsi;
4766 vsi_stats = &vsi->net_stats;
4768 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
4770 /* netdev packet/byte stats come from ring counter. These are obtained
4771 * by summing up ring counters (done by ice_update_vsi_ring_stats).
4773 ice_update_vsi_ring_stats(vsi);
4774 stats->tx_packets = vsi_stats->tx_packets;
4775 stats->tx_bytes = vsi_stats->tx_bytes;
4776 stats->rx_packets = vsi_stats->rx_packets;
4777 stats->rx_bytes = vsi_stats->rx_bytes;
4779 /* The rest of the stats can be read from the hardware but instead we
4780 * just return values that the watchdog task has already obtained from
4783 stats->multicast = vsi_stats->multicast;
4784 stats->tx_errors = vsi_stats->tx_errors;
4785 stats->tx_dropped = vsi_stats->tx_dropped;
4786 stats->rx_errors = vsi_stats->rx_errors;
4787 stats->rx_dropped = vsi_stats->rx_dropped;
4788 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
4789 stats->rx_length_errors = vsi_stats->rx_length_errors;
4792 #ifdef CONFIG_NET_POLL_CONTROLLER
4794 * ice_netpoll - polling "interrupt" handler
4795 * @netdev: network interface device structure
4797 * Used by netconsole to send skbs without having to re-enable interrupts.
4798 * This is not called in the normal interrupt path.
4800 static void ice_netpoll(struct net_device *netdev)
4802 struct ice_netdev_priv *np = netdev_priv(netdev);
4803 struct ice_vsi *vsi = np->vsi;
4804 struct ice_pf *pf = vsi->back;
4807 if (test_bit(__ICE_DOWN, vsi->state) ||
4808 !test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
4811 for (i = 0; i < vsi->num_q_vectors; i++)
4812 ice_msix_clean_rings(0, vsi->q_vectors[i]);
4814 #endif /* CONFIG_NET_POLL_CONTROLLER */
4817 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4818 * @vsi: VSI having NAPI disabled
4820 static void ice_napi_disable_all(struct ice_vsi *vsi)
4827 for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
4828 napi_disable(&vsi->q_vectors[q_idx]->napi);
4832 * ice_down - Shutdown the connection
4833 * @vsi: The VSI being stopped
4835 int ice_down(struct ice_vsi *vsi)
4839 /* Caller of this function is expected to set the
4840 * vsi->state __ICE_DOWN bit
4843 netif_carrier_off(vsi->netdev);
4844 netif_tx_disable(vsi->netdev);
4847 ice_vsi_dis_irq(vsi);
4848 err = ice_vsi_stop_tx_rx_rings(vsi);
4849 ice_napi_disable_all(vsi);
4851 ice_for_each_txq(vsi, i)
4852 ice_clean_tx_ring(vsi->tx_rings[i]);
4854 ice_for_each_rxq(vsi, i)
4855 ice_clean_rx_ring(vsi->rx_rings[i]);
4858 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
4859 vsi->vsi_num, vsi->vsw->sw_id);
4864 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
4865 * @vsi: VSI having resources allocated
4867 * Return 0 on success, negative on failure
4869 static int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4873 if (!vsi->num_txq) {
4874 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
4879 ice_for_each_txq(vsi, i) {
4880 err = ice_setup_tx_ring(vsi->tx_rings[i]);
4889 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
4890 * @vsi: VSI having resources allocated
4892 * Return 0 on success, negative on failure
4894 static int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
4898 if (!vsi->num_rxq) {
4899 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
4904 ice_for_each_rxq(vsi, i) {
4905 err = ice_setup_rx_ring(vsi->rx_rings[i]);
4914 * ice_vsi_req_irq - Request IRQ from the OS
4915 * @vsi: The VSI IRQ is being requested for
4916 * @basename: name for the vector
4918 * Return 0 on success and a negative value on error
4920 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
4922 struct ice_pf *pf = vsi->back;
4925 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
4926 err = ice_vsi_req_irq_msix(vsi, basename);
4932 * ice_vsi_free_tx_rings - Free Tx resources for VSI queues
4933 * @vsi: the VSI having resources freed
4935 static void ice_vsi_free_tx_rings(struct ice_vsi *vsi)
4942 ice_for_each_txq(vsi, i)
4943 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
4944 ice_free_tx_ring(vsi->tx_rings[i]);
4948 * ice_vsi_free_rx_rings - Free Rx resources for VSI queues
4949 * @vsi: the VSI having resources freed
4951 static void ice_vsi_free_rx_rings(struct ice_vsi *vsi)
4958 ice_for_each_rxq(vsi, i)
4959 if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
4960 ice_free_rx_ring(vsi->rx_rings[i]);
4964 * ice_vsi_open - Called when a network interface is made active
4965 * @vsi: the VSI to open
4967 * Initialization of the VSI
4969 * Returns 0 on success, negative value on error
4971 static int ice_vsi_open(struct ice_vsi *vsi)
4973 char int_name[ICE_INT_NAME_STR_LEN];
4974 struct ice_pf *pf = vsi->back;
4977 /* allocate descriptors */
4978 err = ice_vsi_setup_tx_rings(vsi);
4982 err = ice_vsi_setup_rx_rings(vsi);
4986 err = ice_vsi_cfg(vsi);
4990 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4991 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
4992 err = ice_vsi_req_irq(vsi, int_name);
4996 /* Notify the stack of the actual queue counts. */
4997 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
5001 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
5005 err = ice_up_complete(vsi);
5007 goto err_up_complete;
5014 ice_vsi_free_irq(vsi);
5016 ice_vsi_free_rx_rings(vsi);
5018 ice_vsi_free_tx_rings(vsi);
5024 * ice_vsi_close - Shut down a VSI
5025 * @vsi: the VSI being shut down
5027 static void ice_vsi_close(struct ice_vsi *vsi)
5029 if (!test_and_set_bit(__ICE_DOWN, vsi->state))
5032 ice_vsi_free_irq(vsi);
5033 ice_vsi_free_tx_rings(vsi);
5034 ice_vsi_free_rx_rings(vsi);
5038 * ice_rss_clean - Delete RSS related VSI structures that hold user inputs
5039 * @vsi: the VSI being removed
5041 static void ice_rss_clean(struct ice_vsi *vsi)
5047 if (vsi->rss_hkey_user)
5048 devm_kfree(&pf->pdev->dev, vsi->rss_hkey_user);
5049 if (vsi->rss_lut_user)
5050 devm_kfree(&pf->pdev->dev, vsi->rss_lut_user);
5054 * ice_vsi_release - Delete a VSI and free its resources
5055 * @vsi: the VSI being removed
5057 * Returns 0 on success or < 0 on error
5059 static int ice_vsi_release(struct ice_vsi *vsi)
5068 unregister_netdev(vsi->netdev);
5069 free_netdev(vsi->netdev);
5073 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags))
5076 /* Disable VSI and free resources */
5077 ice_vsi_dis_irq(vsi);
5080 /* reclaim interrupt vectors back to PF */
5081 ice_free_res(vsi->back->irq_tracker, vsi->base_vector, vsi->idx);
5082 pf->num_avail_msix += vsi->num_q_vectors;
5084 ice_remove_vsi_fltr(&pf->hw, vsi->vsi_num);
5085 ice_vsi_delete(vsi);
5086 ice_vsi_free_q_vectors(vsi);
5087 ice_vsi_clear_rings(vsi);
5089 ice_vsi_put_qs(vsi);
5090 pf->q_left_tx += vsi->alloc_txq;
5091 pf->q_left_rx += vsi->alloc_rxq;
5099 * ice_dis_vsi - pause a VSI
5100 * @vsi: the VSI being paused
5102 static void ice_dis_vsi(struct ice_vsi *vsi)
5104 if (test_bit(__ICE_DOWN, vsi->state))
5107 set_bit(__ICE_NEEDS_RESTART, vsi->state);
5109 if (vsi->netdev && netif_running(vsi->netdev) &&
5110 vsi->type == ICE_VSI_PF)
5111 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
5117 * ice_ena_vsi - resume a VSI
5118 * @vsi: the VSI being resume
5120 static void ice_ena_vsi(struct ice_vsi *vsi)
5122 if (!test_and_clear_bit(__ICE_NEEDS_RESTART, vsi->state))
5125 if (vsi->netdev && netif_running(vsi->netdev))
5126 vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
5127 else if (ice_vsi_open(vsi))
5128 /* this clears the DOWN bit */
5129 dev_dbg(&vsi->back->pdev->dev, "Failed open VSI 0x%04X on switch 0x%04X\n",
5130 vsi->vsi_num, vsi->vsw->sw_id);
5134 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
5137 static void ice_pf_dis_all_vsi(struct ice_pf *pf)
5141 ice_for_each_vsi(pf, v)
5143 ice_dis_vsi(pf->vsi[v]);
5147 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
5150 static void ice_pf_ena_all_vsi(struct ice_pf *pf)
5154 ice_for_each_vsi(pf, v)
5156 ice_ena_vsi(pf->vsi[v]);
5160 * ice_rebuild - rebuild after reset
5161 * @pf: pf to rebuild
5163 static void ice_rebuild(struct ice_pf *pf)
5165 struct device *dev = &pf->pdev->dev;
5166 struct ice_hw *hw = &pf->hw;
5167 enum ice_status ret;
5170 if (test_bit(__ICE_DOWN, pf->state))
5171 goto clear_recovery;
5173 dev_dbg(dev, "rebuilding pf\n");
5175 ret = ice_init_all_ctrlq(hw);
5177 dev_err(dev, "control queues init failed %d\n", ret);
5181 ret = ice_clear_pf_cfg(hw);
5183 dev_err(dev, "clear PF configuration failed %d\n", ret);
5187 ice_clear_pxe_mode(hw);
5189 ret = ice_get_caps(hw);
5191 dev_err(dev, "ice_get_caps failed %d\n", ret);
5195 /* basic nic switch setup */
5196 err = ice_setup_pf_sw(pf);
5198 dev_err(dev, "ice_setup_pf_sw failed\n");
5202 /* start misc vector */
5203 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
5204 err = ice_req_irq_msix_misc(pf);
5206 dev_err(dev, "misc vector setup failed: %d\n", err);
5211 /* restart the VSIs that were rebuilt and running before the reset */
5212 ice_pf_ena_all_vsi(pf);
5217 ice_shutdown_all_ctrlq(hw);
5218 set_bit(__ICE_RESET_FAILED, pf->state);
5220 set_bit(__ICE_RESET_RECOVERY_PENDING, pf->state);
5224 * ice_change_mtu - NDO callback to change the MTU
5225 * @netdev: network interface device structure
5226 * @new_mtu: new value for maximum frame size
5228 * Returns 0 on success, negative on failure
5230 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
5232 struct ice_netdev_priv *np = netdev_priv(netdev);
5233 struct ice_vsi *vsi = np->vsi;
5234 struct ice_pf *pf = vsi->back;
5237 if (new_mtu == netdev->mtu) {
5238 netdev_warn(netdev, "mtu is already %d\n", netdev->mtu);
5242 if (new_mtu < netdev->min_mtu) {
5243 netdev_err(netdev, "new mtu invalid. min_mtu is %d\n",
5246 } else if (new_mtu > netdev->max_mtu) {
5247 netdev_err(netdev, "new mtu invalid. max_mtu is %d\n",
5251 /* if a reset is in progress, wait for some time for it to complete */
5253 if (ice_is_reset_recovery_pending(pf->state)) {
5255 usleep_range(1000, 2000);
5260 } while (count < 100);
5263 netdev_err(netdev, "can't change mtu. Device is busy\n");
5267 netdev->mtu = new_mtu;
5269 /* if VSI is up, bring it down and then back up */
5270 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
5273 err = ice_down(vsi);
5275 netdev_err(netdev, "change mtu if_up err %d\n", err);
5281 netdev_err(netdev, "change mtu if_up err %d\n", err);
5286 netdev_dbg(netdev, "changed mtu to %d\n", new_mtu);
5291 * ice_set_rss - Set RSS keys and lut
5292 * @vsi: Pointer to VSI structure
5293 * @seed: RSS hash seed
5294 * @lut: Lookup table
5295 * @lut_size: Lookup table size
5297 * Returns 0 on success, negative on failure
5299 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
5301 struct ice_pf *pf = vsi->back;
5302 struct ice_hw *hw = &pf->hw;
5303 enum ice_status status;
5306 struct ice_aqc_get_set_rss_keys *buf =
5307 (struct ice_aqc_get_set_rss_keys *)seed;
5309 status = ice_aq_set_rss_key(hw, vsi->vsi_num, buf);
5312 dev_err(&pf->pdev->dev,
5313 "Cannot set RSS key, err %d aq_err %d\n",
5314 status, hw->adminq.rq_last_status);
5320 status = ice_aq_set_rss_lut(hw, vsi->vsi_num,
5321 vsi->rss_lut_type, lut, lut_size);
5323 dev_err(&pf->pdev->dev,
5324 "Cannot set RSS lut, err %d aq_err %d\n",
5325 status, hw->adminq.rq_last_status);
5334 * ice_get_rss - Get RSS keys and lut
5335 * @vsi: Pointer to VSI structure
5336 * @seed: Buffer to store the keys
5337 * @lut: Buffer to store the lookup table entries
5338 * @lut_size: Size of buffer to store the lookup table entries
5340 * Returns 0 on success, negative on failure
5342 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
5344 struct ice_pf *pf = vsi->back;
5345 struct ice_hw *hw = &pf->hw;
5346 enum ice_status status;
5349 struct ice_aqc_get_set_rss_keys *buf =
5350 (struct ice_aqc_get_set_rss_keys *)seed;
5352 status = ice_aq_get_rss_key(hw, vsi->vsi_num, buf);
5354 dev_err(&pf->pdev->dev,
5355 "Cannot get RSS key, err %d aq_err %d\n",
5356 status, hw->adminq.rq_last_status);
5362 status = ice_aq_get_rss_lut(hw, vsi->vsi_num,
5363 vsi->rss_lut_type, lut, lut_size);
5365 dev_err(&pf->pdev->dev,
5366 "Cannot get RSS lut, err %d aq_err %d\n",
5367 status, hw->adminq.rq_last_status);
5376 * ice_open - Called when a network interface becomes active
5377 * @netdev: network interface device structure
5379 * The open entry point is called when a network interface is made
5380 * active by the system (IFF_UP). At this point all resources needed
5381 * for transmit and receive operations are allocated, the interrupt
5382 * handler is registered with the OS, the netdev watchdog is enabled,
5383 * and the stack is notified that the interface is ready.
5385 * Returns 0 on success, negative value on failure
5387 static int ice_open(struct net_device *netdev)
5389 struct ice_netdev_priv *np = netdev_priv(netdev);
5390 struct ice_vsi *vsi = np->vsi;
5393 netif_carrier_off(netdev);
5395 err = ice_vsi_open(vsi);
5398 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
5399 vsi->vsi_num, vsi->vsw->sw_id);
5404 * ice_stop - Disables a network interface
5405 * @netdev: network interface device structure
5407 * The stop entry point is called when an interface is de-activated by the OS,
5408 * and the netdevice enters the DOWN state. The hardware is still under the
5409 * driver's control, but the netdev interface is disabled.
5411 * Returns success only - not allowed to fail
5413 static int ice_stop(struct net_device *netdev)
5415 struct ice_netdev_priv *np = netdev_priv(netdev);
5416 struct ice_vsi *vsi = np->vsi;
5424 * ice_features_check - Validate encapsulated packet conforms to limits
5426 * @netdev: This port's netdev
5427 * @features: Offload features that the stack believes apply
5429 static netdev_features_t
5430 ice_features_check(struct sk_buff *skb,
5431 struct net_device __always_unused *netdev,
5432 netdev_features_t features)
5436 /* No point in doing any of this if neither checksum nor GSO are
5437 * being requested for this frame. We can rule out both by just
5438 * checking for CHECKSUM_PARTIAL
5440 if (skb->ip_summed != CHECKSUM_PARTIAL)
5443 /* We cannot support GSO if the MSS is going to be less than
5444 * 64 bytes. If it is then we need to drop support for GSO.
5446 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
5447 features &= ~NETIF_F_GSO_MASK;
5449 len = skb_network_header(skb) - skb->data;
5450 if (len & ~(ICE_TXD_MACLEN_MAX))
5451 goto out_rm_features;
5453 len = skb_transport_header(skb) - skb_network_header(skb);
5454 if (len & ~(ICE_TXD_IPLEN_MAX))
5455 goto out_rm_features;
5457 if (skb->encapsulation) {
5458 len = skb_inner_network_header(skb) - skb_transport_header(skb);
5459 if (len & ~(ICE_TXD_L4LEN_MAX))
5460 goto out_rm_features;
5462 len = skb_inner_transport_header(skb) -
5463 skb_inner_network_header(skb);
5464 if (len & ~(ICE_TXD_IPLEN_MAX))
5465 goto out_rm_features;
5470 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
5473 static const struct net_device_ops ice_netdev_ops = {
5474 .ndo_open = ice_open,
5475 .ndo_stop = ice_stop,
5476 .ndo_start_xmit = ice_start_xmit,
5477 .ndo_features_check = ice_features_check,
5478 .ndo_set_rx_mode = ice_set_rx_mode,
5479 .ndo_set_mac_address = ice_set_mac_address,
5480 .ndo_validate_addr = eth_validate_addr,
5481 .ndo_change_mtu = ice_change_mtu,
5482 .ndo_get_stats64 = ice_get_stats64,
5483 #ifdef CONFIG_NET_POLL_CONTROLLER
5484 .ndo_poll_controller = ice_netpoll,
5485 #endif /* CONFIG_NET_POLL_CONTROLLER */
5486 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
5487 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
5488 .ndo_set_features = ice_set_features,
5489 .ndo_fdb_add = ice_fdb_add,
5490 .ndo_fdb_del = ice_fdb_del,