Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65b30348 authored by Johannes Berg's avatar Johannes Berg Committed by Emmanuel Grumbach
Browse files

iwlwifi: add inline helper for packet lengths



Add an inline helper function for getting an RX packet's
length or payload length and use it throughout the code
(most of which I did using an spatch.)

While at it, adjust some code, and remove a bogus comment
from the dvm calibration code.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Reviewed-by: default avatarEran Harary <eran.harary@intel.com>
Signed-off-by: default avatarEmmanuel Grumbach <emmanuel.grumbach@intel.com>
parent e36b766d
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -407,9 +407,8 @@ static bool iwl_resume_status_fn(struct iwl_notif_wait_data *notif_wait,
{
{
	struct iwl_resume_data *resume_data = data;
	struct iwl_resume_data *resume_data = data;
	struct iwl_priv *priv = resume_data->priv;
	struct iwl_priv *priv = resume_data->priv;
	u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;


	if (len - 4 != sizeof(*resume_data->cmd)) {
	if (iwl_rx_packet_payload_len(pkt) != sizeof(*resume_data->cmd)) {
		IWL_ERR(priv, "rx wrong size data\n");
		IWL_ERR(priv, "rx wrong size data\n");
		return true;
		return true;
	}
	}
+2 −5
Original line number Original line Diff line number Diff line
@@ -205,8 +205,7 @@ static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
					     struct iwl_device_cmd *cmd)
					     struct iwl_device_cmd *cmd)
{
{
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	u32 __maybe_unused len =
	u32 __maybe_unused len = iwl_rx_packet_len(pkt);
		le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
	IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
	IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
			"notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
			"notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
	iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
	iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
@@ -457,7 +456,7 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
	const int reg_recalib_period = 60;
	const int reg_recalib_period = 60;
	int change;
	int change;
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	struct iwl_rx_packet *pkt = rxb_addr(rxb);
	u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
	u32 len = iwl_rx_packet_payload_len(pkt);
	__le32 *flag;
	__le32 *flag;
	struct statistics_general_common *common;
	struct statistics_general_common *common;
	struct statistics_rx_non_phy *rx_non_phy;
	struct statistics_rx_non_phy *rx_non_phy;
@@ -467,8 +466,6 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
	struct statistics_tx *tx;
	struct statistics_tx *tx;
	struct statistics_bt_activity *bt_activity;
	struct statistics_bt_activity *bt_activity;


	len -= sizeof(struct iwl_cmd_header); /* skip header */

	IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
	IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
		     len);
		     len);


+1 −6
Original line number Original line Diff line number Diff line
@@ -389,7 +389,6 @@ static bool iwlagn_wait_calib(struct iwl_notif_wait_data *notif_wait,
{
{
	struct iwl_priv *priv = data;
	struct iwl_priv *priv = data;
	struct iwl_calib_hdr *hdr;
	struct iwl_calib_hdr *hdr;
	int len;


	if (pkt->hdr.cmd != CALIBRATION_RES_NOTIFICATION) {
	if (pkt->hdr.cmd != CALIBRATION_RES_NOTIFICATION) {
		WARN_ON(pkt->hdr.cmd != CALIBRATION_COMPLETE_NOTIFICATION);
		WARN_ON(pkt->hdr.cmd != CALIBRATION_COMPLETE_NOTIFICATION);
@@ -397,12 +396,8 @@ static bool iwlagn_wait_calib(struct iwl_notif_wait_data *notif_wait,
	}
	}


	hdr = (struct iwl_calib_hdr *)pkt->data;
	hdr = (struct iwl_calib_hdr *)pkt->data;
	len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;


	/* reduce the size by the length field itself */
	if (iwl_calib_set(priv, hdr, iwl_rx_packet_payload_len(pkt)))
	len -= sizeof(__le32);

	if (iwl_calib_set(priv, hdr, len))
		IWL_ERR(priv, "Failed to record calibration data %d\n",
		IWL_ERR(priv, "Failed to record calibration data %d\n",
			hdr->op_code);
			hdr->op_code);


+10 −0
Original line number Original line Diff line number Diff line
@@ -176,6 +176,16 @@ struct iwl_rx_packet {
	u8 data[];
	u8 data[];
} __packed;
} __packed;


static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt)
{
	return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
}

static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt)
{
	return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr);
}

/**
/**
 * enum CMD_MODE - how to send the host commands ?
 * enum CMD_MODE - how to send the host commands ?
 *
 *
+6 −9
Original line number Original line Diff line number Diff line
@@ -886,8 +886,7 @@ static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm,
	if (err)
	if (err)
		return err;
		return err;


	size = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
	size = iwl_rx_packet_payload_len(cmd.resp_pkt);
	size -= sizeof(cmd.resp_pkt->hdr);
	if (size < sizeof(__le16)) {
	if (size < sizeof(__le16)) {
		err = -EINVAL;
		err = -EINVAL;
	} else {
	} else {
@@ -1211,9 +1210,8 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
	if (ret)
	if (ret)
		goto out;
		goto out;
#ifdef CONFIG_IWLWIFI_DEBUGFS
#ifdef CONFIG_IWLWIFI_DEBUGFS
	len = le32_to_cpu(d3_cfg_cmd.resp_pkt->len_n_flags) &
	len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt);
		FH_RSCSR_FRAME_SIZE_MSK;
	if (len >= sizeof(u32)) {
	if (len >= sizeof(u32) * 2) {
		mvm->d3_test_pme_ptr =
		mvm->d3_test_pme_ptr =
			le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data);
			le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data);
	}
	}
@@ -1668,8 +1666,8 @@ static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
	else
	else
		status_size = sizeof(struct iwl_wowlan_status_v4);
		status_size = sizeof(struct iwl_wowlan_status_v4);


	len = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
	len = iwl_rx_packet_payload_len(cmd.resp_pkt);
	if (len - sizeof(struct iwl_cmd_header) < status_size) {
	if (len < status_size) {
		IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
		IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
		goto out_free_resp;
		goto out_free_resp;
	}
	}
@@ -1704,8 +1702,7 @@ static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
		status.wake_packet = status_v4->wake_packet;
		status.wake_packet = status_v4->wake_packet;
	}
	}


	if (len - sizeof(struct iwl_cmd_header) !=
	if (len != status_size + ALIGN(status.wake_packet_bufsize, 4)) {
	    status_size + ALIGN(status.wake_packet_bufsize, 4)) {
		IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
		IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
		goto out_free_resp;
		goto out_free_resp;
	}
	}
Loading