Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ice: refactor to use helpers

Use the ice_netdev_to_pf() helper in more places and remove a bunch of
boilerplate code. Not every instance could be replaced due to use of the
netdev_priv() output or the vsi variable within a bunch of functions.

Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Tested-by: Rinitha S <sx.rinitha@intel.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://patch.msgid.link/20251016-jk-iwl-next-2025-10-15-v2-12-ff3a390d9fc6@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Jesse Brandeburg and committed by
Jakub Kicinski
a308ea97 71462475

+24 -54
+15 -33
drivers/net/ethernet/intel/ice/ice_ethtool.c
··· 794 794 static void 795 795 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) 796 796 { 797 - struct ice_netdev_priv *np = netdev_priv(netdev); 798 - struct ice_pf *pf = np->vsi->back; 797 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 799 798 struct ice_hw *hw = &pf->hw; 800 799 u32 *regs_buf = (u32 *)p; 801 800 unsigned int i; ··· 809 810 810 811 static u32 ice_get_msglevel(struct net_device *netdev) 811 812 { 812 - struct ice_netdev_priv *np = netdev_priv(netdev); 813 - struct ice_pf *pf = np->vsi->back; 813 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 814 814 815 815 #ifndef CONFIG_DYNAMIC_DEBUG 816 816 if (pf->hw.debug_mask) ··· 822 824 823 825 static void ice_set_msglevel(struct net_device *netdev, u32 data) 824 826 { 825 - struct ice_netdev_priv *np = netdev_priv(netdev); 826 - struct ice_pf *pf = np->vsi->back; 827 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 827 828 828 829 #ifndef CONFIG_DYNAMIC_DEBUG 829 830 if (ICE_DBG_USER & data) ··· 837 840 static void ice_get_link_ext_stats(struct net_device *netdev, 838 841 struct ethtool_link_ext_stats *stats) 839 842 { 840 - struct ice_netdev_priv *np = netdev_priv(netdev); 841 - struct ice_pf *pf = np->vsi->back; 843 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 842 844 843 845 stats->link_down_events = pf->link_down_events; 844 846 } 845 847 846 848 static int ice_get_eeprom_len(struct net_device *netdev) 847 849 { 848 - struct ice_netdev_priv *np = netdev_priv(netdev); 849 - struct ice_pf *pf = np->vsi->back; 850 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 850 851 851 852 return (int)pf->hw.flash.flash_size; 852 853 } ··· 853 858 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, 854 859 u8 *bytes) 855 860 { 856 - struct ice_netdev_priv *np = netdev_priv(netdev); 857 - struct ice_vsi *vsi = np->vsi; 858 - struct ice_pf *pf = vsi->back; 861 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 859 862 struct ice_hw *hw = &pf->hw; 860 863 struct device *dev; 861 864 int ret; ··· 952 959 */ 953 960 static u64 ice_eeprom_test(struct net_device *netdev) 954 961 { 955 - struct ice_netdev_priv *np = netdev_priv(netdev); 956 - struct ice_pf *pf = np->vsi->back; 962 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 957 963 958 964 netdev_info(netdev, "EEPROM test\n"); 959 965 return !!(ice_nvm_validate_checksum(&pf->hw)); ··· 1266 1274 */ 1267 1275 static u64 ice_loopback_test(struct net_device *netdev) 1268 1276 { 1269 - struct ice_netdev_priv *np = netdev_priv(netdev); 1270 - struct ice_vsi *orig_vsi = np->vsi, *test_vsi; 1271 - struct ice_pf *pf = orig_vsi->back; 1277 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 1278 + struct ice_vsi *test_vsi; 1272 1279 u8 *tx_frame __free(kfree) = NULL; 1273 1280 u8 broadcast[ETH_ALEN], ret = 0; 1274 1281 int num_frames, valid_frames; ··· 1356 1365 */ 1357 1366 static u64 ice_intr_test(struct net_device *netdev) 1358 1367 { 1359 - struct ice_netdev_priv *np = netdev_priv(netdev); 1360 - struct ice_pf *pf = np->vsi->back; 1368 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 1361 1369 u16 swic_old = pf->sw_int_count; 1362 1370 1363 1371 netdev_info(netdev, "interrupt test\n"); ··· 1384 1394 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test, 1385 1395 u64 *data) 1386 1396 { 1387 - struct ice_netdev_priv *np = netdev_priv(netdev); 1397 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 1388 1398 bool if_running = netif_running(netdev); 1389 - struct ice_pf *pf = np->vsi->back; 1390 1399 struct device *dev; 1391 1400 1392 1401 dev = ice_pf_to_dev(pf); ··· 1709 1720 */ 1710 1721 static u32 ice_get_priv_flags(struct net_device *netdev) 1711 1722 { 1712 - struct ice_netdev_priv *np = netdev_priv(netdev); 1713 - struct ice_vsi *vsi = np->vsi; 1714 - struct ice_pf *pf = vsi->back; 1723 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 1715 1724 u32 i, ret_flags = 0; 1716 1725 1717 1726 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { ··· 4404 4417 ice_get_module_info(struct net_device *netdev, 4405 4418 struct ethtool_modinfo *modinfo) 4406 4419 { 4407 - struct ice_netdev_priv *np = netdev_priv(netdev); 4408 - struct ice_vsi *vsi = np->vsi; 4409 - struct ice_pf *pf = vsi->back; 4420 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 4410 4421 struct ice_hw *hw = &pf->hw; 4411 4422 u8 sff8472_comp = 0; 4412 4423 u8 sff8472_swap = 0; ··· 4476 4491 ice_get_module_eeprom(struct net_device *netdev, 4477 4492 struct ethtool_eeprom *ee, u8 *data) 4478 4493 { 4479 - struct ice_netdev_priv *np = netdev_priv(netdev); 4494 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 4480 4495 #define SFF_READ_BLOCK_SIZE 8 4481 4496 u8 value[SFF_READ_BLOCK_SIZE] = { 0 }; 4482 4497 u8 addr = ICE_I2C_EEPROM_DEV_ADDR; 4483 - struct ice_vsi *vsi = np->vsi; 4484 - struct ice_pf *pf = vsi->back; 4485 4498 struct ice_hw *hw = &pf->hw; 4486 4499 bool is_sfp = false; 4487 4500 unsigned int i, j; ··· 4757 4774 */ 4758 4775 static int ice_ethtool_reset(struct net_device *dev, u32 *flags) 4759 4776 { 4760 - struct ice_netdev_priv *np = netdev_priv(dev); 4761 - struct ice_pf *pf = np->vsi->back; 4777 + struct ice_pf *pf = ice_netdev_to_pf(dev); 4762 4778 enum ice_reset_req reset; 4763 4779 4764 4780 switch (*flags) {
+2 -6
drivers/net/ethernet/intel/ice/ice_flex_pipe.c
··· 574 574 int ice_udp_tunnel_set_port(struct net_device *netdev, unsigned int table, 575 575 unsigned int idx, struct udp_tunnel_info *ti) 576 576 { 577 - struct ice_netdev_priv *np = netdev_priv(netdev); 578 - struct ice_vsi *vsi = np->vsi; 579 - struct ice_pf *pf = vsi->back; 577 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 580 578 enum ice_tunnel_type tnl_type; 581 579 int status; 582 580 u16 index; ··· 596 598 int ice_udp_tunnel_unset_port(struct net_device *netdev, unsigned int table, 597 599 unsigned int idx, struct udp_tunnel_info *ti) 598 600 { 599 - struct ice_netdev_priv *np = netdev_priv(netdev); 600 - struct ice_vsi *vsi = np->vsi; 601 - struct ice_pf *pf = vsi->back; 601 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 602 602 enum ice_tunnel_type tnl_type; 603 603 int status; 604 604
+1 -2
drivers/net/ethernet/intel/ice/ice_lag.c
··· 2177 2177 */ 2178 2178 static void ice_lag_disable_sriov_bond(struct ice_lag *lag) 2179 2179 { 2180 - struct ice_netdev_priv *np = netdev_priv(lag->netdev); 2181 - struct ice_pf *pf = np->vsi->back; 2180 + struct ice_pf *pf = ice_netdev_to_pf(lag->netdev); 2182 2181 2183 2182 ice_clear_feature_support(pf, ICE_F_SRIOV_LAG); 2184 2183 ice_clear_feature_support(pf, ICE_F_SRIOV_AA_LAG);
+3 -7
drivers/net/ethernet/intel/ice/ice_main.c
··· 8074 8074 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 8075 8075 struct net_device *dev, u32 filter_mask, int nlflags) 8076 8076 { 8077 - struct ice_netdev_priv *np = netdev_priv(dev); 8078 - struct ice_vsi *vsi = np->vsi; 8079 - struct ice_pf *pf = vsi->back; 8077 + struct ice_pf *pf = ice_netdev_to_pf(dev); 8080 8078 u16 bmode; 8081 8079 8082 8080 bmode = pf->first_sw->bridge_mode; ··· 8144 8146 u16 __always_unused flags, 8145 8147 struct netlink_ext_ack __always_unused *extack) 8146 8148 { 8147 - struct ice_netdev_priv *np = netdev_priv(dev); 8148 - struct ice_pf *pf = np->vsi->back; 8149 + struct ice_pf *pf = ice_netdev_to_pf(dev); 8149 8150 struct nlattr *attr, *br_spec; 8150 8151 struct ice_hw *hw = &pf->hw; 8151 8152 struct ice_sw *pf_sw; ··· 9578 9581 */ 9579 9582 int ice_open(struct net_device *netdev) 9580 9583 { 9581 - struct ice_netdev_priv *np = netdev_priv(netdev); 9582 - struct ice_pf *pf = np->vsi->back; 9584 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 9583 9585 9584 9586 if (ice_is_reset_in_progress(pf->state)) { 9585 9587 netdev_err(netdev, "can't open net device while reset is in progress");
+2 -4
drivers/net/ethernet/intel/ice/ice_ptp.c
··· 2215 2215 int ice_ptp_hwtstamp_get(struct net_device *netdev, 2216 2216 struct kernel_hwtstamp_config *config) 2217 2217 { 2218 - struct ice_netdev_priv *np = netdev_priv(netdev); 2219 - struct ice_pf *pf = np->vsi->back; 2218 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 2220 2219 2221 2220 if (pf->ptp.state != ICE_PTP_READY) 2222 2221 return -EIO; ··· 2286 2287 struct kernel_hwtstamp_config *config, 2287 2288 struct netlink_ext_ack *extack) 2288 2289 { 2289 - struct ice_netdev_priv *np = netdev_priv(netdev); 2290 - struct ice_pf *pf = np->vsi->back; 2290 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 2291 2291 int err; 2292 2292 2293 2293 if (pf->ptp.state != ICE_PTP_READY)
+1 -2
drivers/net/ethernet/intel/ice/ice_sriov.c
··· 1190 1190 */ 1191 1191 int ice_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool ena) 1192 1192 { 1193 - struct ice_netdev_priv *np = netdev_priv(netdev); 1194 - struct ice_pf *pf = np->vsi->back; 1193 + struct ice_pf *pf = ice_netdev_to_pf(netdev); 1195 1194 struct ice_vsi *vf_vsi; 1196 1195 struct device *dev; 1197 1196 struct ice_vf *vf;