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

Commit de460ddd authored by Luca Coelho's avatar Luca Coelho
Browse files

iwlwifi: fw: combine loading of last page block into main copy loop



Now that we check and copy only the actual size of the page block,
there is no need to treat the last block separately.  Remove the
mostly duplicate code and make the main copy loop handle also the last
block.

Signed-off-by: default avatarLuca Coelho <luciano.coelho@intel.com>
parent 9039d985
Loading
Loading
Loading
Loading
+26 −43
Original line number Original line Diff line number Diff line
@@ -221,66 +221,49 @@ static int iwl_fill_paging_mem(struct iwl_fw_runtime *fwrt,
	sec_idx++;
	sec_idx++;


	/*
	/*
	 * copy the paging blocks to the dram
	 * Copy the paging blocks to the dram.  The loop index starts
	 * loop index start from 1 since that CSS block already copied to dram
	 * from 1 since the CSS block (index 0) was already copied to
	 * and CSS index is 0.
	 * dram.  We use num_of_paging_blk + 1 to account for that.
	 * loop stop at num_of_paging_blk since that last block is not full.
	 */
	 */
	for (idx = 1; idx < fwrt->num_of_paging_blk; idx++) {
	for (idx = 1; idx < fwrt->num_of_paging_blk + 1; idx++) {
		struct iwl_fw_paging *block = &fwrt->fw_paging_db[idx];
		struct iwl_fw_paging *block = &fwrt->fw_paging_db[idx];
		int remaining = image->sec[sec_idx].len - offset;
		int len = block->fw_paging_size;


		if (block->fw_paging_size > image->sec[sec_idx].len - offset) {
		/*
			IWL_ERR(fwrt,
		 * For the last block, we copy all that is remaining,
				"Paging: paging size is larger than remaining data in block %d\n",
		 * for all other blocks, we copy fw_paging_size at a
				idx);
		 * time. */
			ret = -EINVAL;
		if (idx == fwrt->num_of_paging_blk) {
			goto err;
			len = remaining;
		}
			if (remaining !=

			    fwrt->num_of_pages_in_last_blk * FW_PAGING_SIZE) {
		memcpy(page_address(block->fw_paging_block),
		       image->sec[sec_idx].data + offset,
		       block->fw_paging_size);
		dma_sync_single_for_device(fwrt->trans->dev,
					   block->fw_paging_phys,
					   block->fw_paging_size,
					   DMA_BIDIRECTIONAL);

		IWL_DEBUG_FW(fwrt,
			     "Paging: copied %d paging bytes to block %d\n",
			     block->fw_paging_size, idx);

		offset += block->fw_paging_size;

		if (offset > image->sec[sec_idx].len) {
				IWL_ERR(fwrt,
				IWL_ERR(fwrt,
				"Paging: offset goes over section size\n");
					"Paging: last block contains more data than expected %d\n",
					remaining);
				ret = -EINVAL;
				ret = -EINVAL;
				goto err;
				goto err;
			}
			}
	}
		} else if (block->fw_paging_size > remaining) {

	/* copy the last paging block */
	if (fwrt->num_of_pages_in_last_blk > 0) {
		struct iwl_fw_paging *block = &fwrt->fw_paging_db[idx];

		if (image->sec[sec_idx].len - offset > block->fw_paging_size) {
			IWL_ERR(fwrt,
			IWL_ERR(fwrt,
				"Paging: last block is larger than paging size\n");
				"Paging: not enough data in other in block %d (%d)\n",
				idx, remaining);
			ret = -EINVAL;
			ret = -EINVAL;
			goto err;
			goto err;
		}
		}


		memcpy(page_address(block->fw_paging_block),
		memcpy(page_address(block->fw_paging_block),
		       image->sec[sec_idx].data + offset,
		       image->sec[sec_idx].data + offset, len);
		       image->sec[sec_idx].len - offset);
		dma_sync_single_for_device(fwrt->trans->dev,
		dma_sync_single_for_device(fwrt->trans->dev,
					   block->fw_paging_phys,
					   block->fw_paging_phys,
					   block->fw_paging_size,
					   block->fw_paging_size,
					   DMA_BIDIRECTIONAL);
					   DMA_BIDIRECTIONAL);


		IWL_DEBUG_FW(fwrt,
		IWL_DEBUG_FW(fwrt,
			     "Paging: copied %d pages in the last block %d\n",
			     "Paging: copied %d paging bytes to block %d\n",
			     fwrt->num_of_pages_in_last_blk, idx);
			     len, idx);

		offset += block->fw_paging_size;
	}
	}


	return 0;
	return 0;