Lines Matching +full:data +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/crc-itu-t.h>
7 #include <linux/nvmem-consumer.h>
52 * not negative and be in the size of the firmware itself.
54 static bool aqr_fw_validate_get(size_t size, size_t offset, size_t get_size) in aqr_fw_validate_get() argument
56 return offset + get_size <= size; in aqr_fw_validate_get()
59 static int aqr_fw_get_be16(const u8 *data, size_t offset, size_t size, u16 *value) in aqr_fw_get_be16() argument
61 if (!aqr_fw_validate_get(size, offset, sizeof(u16))) in aqr_fw_get_be16()
62 return -EINVAL; in aqr_fw_get_be16()
64 *value = get_unaligned_be16(data + offset); in aqr_fw_get_be16()
69 static int aqr_fw_get_le16(const u8 *data, size_t offset, size_t size, u16 *value) in aqr_fw_get_le16() argument
71 if (!aqr_fw_validate_get(size, offset, sizeof(u16))) in aqr_fw_get_le16()
72 return -EINVAL; in aqr_fw_get_le16()
74 *value = get_unaligned_le16(data + offset); in aqr_fw_get_le16()
79 static int aqr_fw_get_le24(const u8 *data, size_t offset, size_t size, u32 *value) in aqr_fw_get_le24() argument
81 if (!aqr_fw_validate_get(size, offset, sizeof(u8) * 3)) in aqr_fw_get_le24()
82 return -EINVAL; in aqr_fw_get_le24()
84 *value = get_unaligned_le24(data + offset); in aqr_fw_get_le24()
89 /* load data into the phy's memory */
91 const u8 *data, size_t len) in aqr_fw_load_memory() argument
106 /* We assume and enforce the size to be word aligned. in aqr_fw_load_memory()
113 /* FW data is always stored in little-endian */ in aqr_fw_load_memory()
114 word = get_unaligned_le32((const u32 *)(data + pos)); in aqr_fw_load_memory()
126 * using big-endian order. Mimic what the PHY does to have a in aqr_fw_load_memory()
134 /* ...calculate CRC as we load data... */ in aqr_fw_load_memory()
143 return -EINVAL; in aqr_fw_load_memory()
149 static int aqr_fw_boot(struct phy_device *phydev, const u8 *data, size_t size, in aqr_fw_boot() argument
160 * CRC is saved in big-endian as PHY is BE in aqr_fw_boot()
162 ret = aqr_fw_get_be16(data, size - sizeof(u16), size, &read_crc); in aqr_fw_boot()
167 calculated_crc = crc_itu_t(0, data, size - sizeof(u16)); in aqr_fw_boot()
171 return -EINVAL; in aqr_fw_boot()
175 ret = aqr_fw_get_le16(data, PRIMARY_OFFSET_OFFSET, size, &read_primary_offset); in aqr_fw_boot()
185 if (!aqr_fw_validate_get(size, primary_offset + HEADER_OFFSET, in aqr_fw_boot()
188 return -EINVAL; in aqr_fw_boot()
192 ret = aqr_fw_get_le24(data, primary_offset + HEADER_OFFSET + in aqr_fw_boot()
194 size, &iram_offset); in aqr_fw_boot()
199 ret = aqr_fw_get_le24(data, primary_offset + HEADER_OFFSET + in aqr_fw_boot()
201 size, &iram_size); in aqr_fw_boot()
203 phydev_err(phydev, "invalid iram size in firmware\n"); in aqr_fw_boot()
206 ret = aqr_fw_get_le24(data, primary_offset + HEADER_OFFSET + in aqr_fw_boot()
208 size, &dram_offset); in aqr_fw_boot()
213 ret = aqr_fw_get_le24(data, primary_offset + HEADER_OFFSET + in aqr_fw_boot()
215 size, &dram_size); in aqr_fw_boot()
217 phydev_err(phydev, "invalid dram size in firmware\n"); in aqr_fw_boot()
222 * Validate iram/dram offset and size. in aqr_fw_boot()
226 phydev_err(phydev, "iram size if not aligned to word size. Please report this upstream!\n"); in aqr_fw_boot()
227 return -EINVAL; in aqr_fw_boot()
229 if (!aqr_fw_validate_get(size, iram_offset, iram_size)) { in aqr_fw_boot()
230 phydev_err(phydev, "invalid iram offset for iram size\n"); in aqr_fw_boot()
231 return -EINVAL; in aqr_fw_boot()
236 phydev_err(phydev, "dram size if not aligned to word size. Please report this upstream!\n"); in aqr_fw_boot()
237 return -EINVAL; in aqr_fw_boot()
239 if (!aqr_fw_validate_get(size, dram_offset, dram_size)) { in aqr_fw_boot()
240 phydev_err(phydev, "invalid iram offset for iram size\n"); in aqr_fw_boot()
241 return -EINVAL; in aqr_fw_boot()
244 phydev_dbg(phydev, "primary %d IRAM offset=%d size=%d DRAM offset=%d size=%d\n", in aqr_fw_boot()
247 if (!aqr_fw_validate_get(size, dram_offset + VERSION_STRING_OFFSET, in aqr_fw_boot()
250 return -EINVAL; in aqr_fw_boot()
252 strscpy(version, (char *)data + dram_offset + VERSION_STRING_OFFSET, in aqr_fw_boot()
256 return -EINVAL; in aqr_fw_boot()
265 phydev_dbg(phydev, "loading DRAM 0x%08x from offset=%d size=%d\n", in aqr_fw_boot()
267 ret = aqr_fw_load_memory(phydev, DRAM_BASE_ADDR, data + dram_offset, in aqr_fw_boot()
272 phydev_dbg(phydev, "loading IRAM 0x%08x from offset=%d size=%d\n", in aqr_fw_boot()
274 ret = aqr_fw_load_memory(phydev, IRAM_BASE_ADDR, data + iram_offset, in aqr_fw_boot()
299 size_t size; in aqr_firmware_load_nvmem() local
303 cell = nvmem_cell_get(&phydev->mdio.dev, "firmware"); in aqr_firmware_load_nvmem()
307 buf = nvmem_cell_read(cell, &size); in aqr_firmware_load_nvmem()
313 ret = aqr_fw_boot(phydev, buf, size, AQR_FW_SRC_NVMEM); in aqr_firmware_load_nvmem()
326 struct device *dev = &phydev->mdio.dev; in aqr_firmware_load_fs()
331 ret = of_property_read_string(dev->of_node, "firmware-name", in aqr_firmware_load_fs()
343 ret = aqr_fw_boot(phydev, fw->data, fw->size, AQR_FW_SRC_FS); in aqr_firmware_load_fs()
364 case -ETIMEDOUT: in aqr_firmware_load()