intel: Update drivers to use ethtool_sprintf
Update the Intel drivers to make use of ethtool_sprintf. The general idea is to reduce code size and overhead by replacing the repeated pattern of string printf statements and ETH_STRING_LEN counter increments. Signed-off-by: Alexander Duyck <alexanderduyck@fb.com> Acked-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									7888fe53b7
								
							
						
					
					
						commit
						c8d4725e98
					
				| @ -2368,21 +2368,15 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data) | |||||||
| 	struct i40e_netdev_priv *np = netdev_priv(netdev); | 	struct i40e_netdev_priv *np = netdev_priv(netdev); | ||||||
| 	struct i40e_vsi *vsi = np->vsi; | 	struct i40e_vsi *vsi = np->vsi; | ||||||
| 	struct i40e_pf *pf = vsi->back; | 	struct i40e_pf *pf = vsi->back; | ||||||
| 	char *p = (char *)data; |  | ||||||
| 	unsigned int i; | 	unsigned int i; | ||||||
|  | 	u8 *p = data; | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) { | 	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) | ||||||
| 		snprintf(p, ETH_GSTRING_LEN, "%s", | 		ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string); | ||||||
| 			 i40e_gstrings_priv_flags[i].flag_string); |  | ||||||
| 		p += ETH_GSTRING_LEN; |  | ||||||
| 	} |  | ||||||
| 	if (pf->hw.pf_id != 0) | 	if (pf->hw.pf_id != 0) | ||||||
| 		return; | 		return; | ||||||
| 	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) { | 	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) | ||||||
| 		snprintf(p, ETH_GSTRING_LEN, "%s", | 		ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string); | ||||||
| 			 i40e_gl_gstrings_priv_flags[i].flag_string); |  | ||||||
| 		p += ETH_GSTRING_LEN; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void i40e_get_strings(struct net_device *netdev, u32 stringset, | static void i40e_get_strings(struct net_device *netdev, u32 stringset, | ||||||
|  | |||||||
| @ -871,68 +871,47 @@ static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data) | |||||||
| { | { | ||||||
| 	struct ice_netdev_priv *np = netdev_priv(netdev); | 	struct ice_netdev_priv *np = netdev_priv(netdev); | ||||||
| 	struct ice_vsi *vsi = np->vsi; | 	struct ice_vsi *vsi = np->vsi; | ||||||
| 	char *p = (char *)data; |  | ||||||
| 	unsigned int i; | 	unsigned int i; | ||||||
|  | 	u8 *p = data; | ||||||
| 
 | 
 | ||||||
| 	switch (stringset) { | 	switch (stringset) { | ||||||
| 	case ETH_SS_STATS: | 	case ETH_SS_STATS: | ||||||
| 		for (i = 0; i < ICE_VSI_STATS_LEN; i++) { | 		for (i = 0; i < ICE_VSI_STATS_LEN; i++) | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, "%s", | 			ethtool_sprintf(&p, | ||||||
| 					ice_gstrings_vsi_stats[i].stat_string); | 					ice_gstrings_vsi_stats[i].stat_string); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		ice_for_each_alloc_txq(vsi, i) { | 		ice_for_each_alloc_txq(vsi, i) { | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, | 			ethtool_sprintf(&p, "tx_queue_%u_packets", i); | ||||||
| 				 "tx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "tx_queue_%u_bytes", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		ice_for_each_alloc_rxq(vsi, i) { | 		ice_for_each_alloc_rxq(vsi, i) { | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, | 			ethtool_sprintf(&p, "rx_queue_%u_packets", i); | ||||||
| 				 "rx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "rx_queue_%u_bytes", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (vsi->type != ICE_VSI_PF) | 		if (vsi->type != ICE_VSI_PF) | ||||||
| 			return; | 			return; | ||||||
| 
 | 
 | ||||||
| 		for (i = 0; i < ICE_PF_STATS_LEN; i++) { | 		for (i = 0; i < ICE_PF_STATS_LEN; i++) | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, "%s", | 			ethtool_sprintf(&p, | ||||||
| 					ice_gstrings_pf_stats[i].stat_string); | 					ice_gstrings_pf_stats[i].stat_string); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { | 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, | 			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i); | ||||||
| 				 "tx_priority_%u_xon.nic", i); | 			ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, |  | ||||||
| 				 "tx_priority_%u_xoff.nic", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { | 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, | 			ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i); | ||||||
| 				 "rx_priority_%u_xon.nic", i); | 			ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, |  | ||||||
| 				 "rx_priority_%u_xoff.nic", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case ETH_SS_TEST: | 	case ETH_SS_TEST: | ||||||
| 		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN); | 		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN); | ||||||
| 		break; | 		break; | ||||||
| 	case ETH_SS_PRIV_FLAGS: | 	case ETH_SS_PRIV_FLAGS: | ||||||
| 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { | 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) | ||||||
| 			snprintf(p, ETH_GSTRING_LEN, "%s", | 			ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name); | ||||||
| 				 ice_gstrings_priv_flags[i].name); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		break; | 		break; | ||||||
|  | |||||||
| @ -2347,35 +2347,23 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data) | |||||||
| 			IGB_TEST_LEN*ETH_GSTRING_LEN); | 			IGB_TEST_LEN*ETH_GSTRING_LEN); | ||||||
| 		break; | 		break; | ||||||
| 	case ETH_SS_STATS: | 	case ETH_SS_STATS: | ||||||
| 		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) { | 		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) | ||||||
| 			memcpy(p, igb_gstrings_stats[i].stat_string, | 			ethtool_sprintf(&p, | ||||||
| 			       ETH_GSTRING_LEN); | 					igb_gstrings_stats[i].stat_string); | ||||||
| 			p += ETH_GSTRING_LEN; | 		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) | ||||||
| 		} | 			ethtool_sprintf(&p, | ||||||
| 		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) { | 					igb_gstrings_net_stats[i].stat_string); | ||||||
| 			memcpy(p, igb_gstrings_net_stats[i].stat_string, |  | ||||||
| 			       ETH_GSTRING_LEN); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 		for (i = 0; i < adapter->num_tx_queues; i++) { | 		for (i = 0; i < adapter->num_tx_queues; i++) { | ||||||
| 			sprintf(p, "tx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "tx_queue_%u_packets", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "tx_queue_%u_bytes", i); | ||||||
| 			sprintf(p, "tx_queue_%u_bytes", i); | 			ethtool_sprintf(&p, "tx_queue_%u_restart", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			sprintf(p, "tx_queue_%u_restart", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; i < adapter->num_rx_queues; i++) { | 		for (i = 0; i < adapter->num_rx_queues; i++) { | ||||||
| 			sprintf(p, "rx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "rx_queue_%u_packets", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "rx_queue_%u_bytes", i); | ||||||
| 			sprintf(p, "rx_queue_%u_bytes", i); | 			ethtool_sprintf(&p, "rx_queue_%u_drops", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "rx_queue_%u_csum_err", i); | ||||||
| 			sprintf(p, "rx_queue_%u_drops", i); | 			ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			sprintf(p, "rx_queue_%u_csum_err", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 			sprintf(p, "rx_queue_%u_alloc_failed", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */ | 		/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */ | ||||||
| 		break; | 		break; | ||||||
|  | |||||||
| @ -1368,45 +1368,33 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev, | |||||||
| static void ixgbe_get_strings(struct net_device *netdev, u32 stringset, | static void ixgbe_get_strings(struct net_device *netdev, u32 stringset, | ||||||
| 			      u8 *data) | 			      u8 *data) | ||||||
| { | { | ||||||
| 	char *p = (char *)data; |  | ||||||
| 	unsigned int i; | 	unsigned int i; | ||||||
|  | 	u8 *p = data; | ||||||
| 
 | 
 | ||||||
| 	switch (stringset) { | 	switch (stringset) { | ||||||
| 	case ETH_SS_TEST: | 	case ETH_SS_TEST: | ||||||
| 		for (i = 0; i < IXGBE_TEST_LEN; i++) { | 		for (i = 0; i < IXGBE_TEST_LEN; i++) | ||||||
| 			memcpy(data, ixgbe_gstrings_test[i], ETH_GSTRING_LEN); | 			ethtool_sprintf(&p, ixgbe_gstrings_test[i]); | ||||||
| 			data += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 		break; | 		break; | ||||||
| 	case ETH_SS_STATS: | 	case ETH_SS_STATS: | ||||||
| 		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { | 		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) | ||||||
| 			memcpy(p, ixgbe_gstrings_stats[i].stat_string, | 			ethtool_sprintf(&p, | ||||||
| 			       ETH_GSTRING_LEN); | 					ixgbe_gstrings_stats[i].stat_string); | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} |  | ||||||
| 		for (i = 0; i < netdev->num_tx_queues; i++) { | 		for (i = 0; i < netdev->num_tx_queues; i++) { | ||||||
| 			sprintf(p, "tx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "tx_queue_%u_packets", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "tx_queue_%u_bytes", i); | ||||||
| 			sprintf(p, "tx_queue_%u_bytes", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) { | 		for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) { | ||||||
| 			sprintf(p, "rx_queue_%u_packets", i); | 			ethtool_sprintf(&p, "rx_queue_%u_packets", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "rx_queue_%u_bytes", i); | ||||||
| 			sprintf(p, "rx_queue_%u_bytes", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { | 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { | ||||||
| 			sprintf(p, "tx_pb_%u_pxon", i); | 			ethtool_sprintf(&p, "tx_pb_%u_pxon", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "tx_pb_%u_pxoff", i); | ||||||
| 			sprintf(p, "tx_pb_%u_pxoff", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { | 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) { | ||||||
| 			sprintf(p, "rx_pb_%u_pxon", i); | 			ethtool_sprintf(&p, "rx_pb_%u_pxon", i); | ||||||
| 			p += ETH_GSTRING_LEN; | 			ethtool_sprintf(&p, "rx_pb_%u_pxoff", i); | ||||||
| 			sprintf(p, "rx_pb_%u_pxoff", i); |  | ||||||
| 			p += ETH_GSTRING_LEN; |  | ||||||
| 		} | 		} | ||||||
| 		/* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */ | 		/* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */ | ||||||
| 		break; | 		break; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user