Lines Matching +full:attr +full:- +full:cnt +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2019-2022 Intel Corporation. All rights reserved.
11 #include <linux/mfd/intel-m10-bmc.h>
43 struct intel_m10bmc *m10bmc = sec->m10bmc; in m10bmc_sec_write()
44 unsigned int stride = regmap_get_reg_stride(m10bmc->regmap); in m10bmc_sec_write()
47 u32 leftover_size = size - leftover_offset; in m10bmc_sec_write()
51 if (sec->m10bmc->flash_bulk_ops) in m10bmc_sec_write()
52 return sec->m10bmc->flash_bulk_ops->write(m10bmc, buf, offset, size); in m10bmc_sec_write()
55 return -EINVAL; in m10bmc_sec_write()
57 ret = regmap_bulk_write(m10bmc->regmap, M10BMC_STAGING_BASE + offset, in m10bmc_sec_write()
65 ret = regmap_write(m10bmc->regmap, M10BMC_STAGING_BASE + offset + leftover_offset, in m10bmc_sec_write()
76 struct intel_m10bmc *m10bmc = sec->m10bmc; in m10bmc_sec_read()
77 unsigned int stride = regmap_get_reg_stride(m10bmc->regmap); in m10bmc_sec_read()
80 u32 leftover_size = size - leftover_offset; in m10bmc_sec_read()
84 if (sec->m10bmc->flash_bulk_ops) in m10bmc_sec_read()
85 return sec->m10bmc->flash_bulk_ops->read(m10bmc, buf, addr, size); in m10bmc_sec_read()
88 return -EINVAL; in m10bmc_sec_read()
90 ret = regmap_bulk_read(m10bmc->regmap, addr, buf, read_count); in m10bmc_sec_read()
96 ret = regmap_read(m10bmc->regmap, addr + leftover_offset, &leftover_tmp); in m10bmc_sec_read()
111 int sha_num_bytes, i, ret, cnt = 0; in show_root_entry_hash() local
125 dev_err(sec->dev, "%s bad sha num bytes %d\n", __func__, in show_root_entry_hash()
127 return -EINVAL; in show_root_entry_hash()
137 cnt += sprintf(buf + cnt, "%02x", hash[i]); in show_root_entry_hash()
138 cnt += sprintf(buf + cnt, "\n"); in show_root_entry_hash()
140 return cnt; in show_root_entry_hash()
145 struct device_attribute *attr, \
149 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; \
151 return show_root_entry_hash(dev, csr_map->_name##_magic, \
152 csr_map->_name##_prog_addr, \
153 csr_map->_name##_reh_addr, \
177 dev_err(sec->dev, "failed to read CSK vector\n"); in show_canceled_csk()
191 struct device_attribute *attr, \
195 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; \
198 csr_map->_name##_prog_addr + CSK_VEC_OFFSET, \
212 struct device_attribute *attr, char *buf) in flash_count_show() argument
215 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in flash_count_show()
218 int cnt, ret; in flash_count_show() local
224 return -ENOMEM; in flash_count_show()
226 ret = m10bmc_sec_read(sec, flash_buf, csr_map->rsu_update_counter, in flash_count_show()
229 dev_err(sec->dev, "failed to read flash count\n"); in flash_count_show()
232 cnt = num_bits - bitmap_weight((unsigned long *)flash_buf, num_bits); in flash_count_show()
237 return ret ? : sysfs_emit(buf, "%u\n", cnt); in flash_count_show()
242 &dev_attr_flash_count.attr,
243 &dev_attr_bmc_root_entry_hash.attr,
244 &dev_attr_sr_root_entry_hash.attr,
245 &dev_attr_pr_root_entry_hash.attr,
246 &dev_attr_sr_canceled_csks.attr,
247 &dev_attr_pr_canceled_csks.attr,
248 &dev_attr_bmc_canceled_csks.attr,
253 .name = "security",
264 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in log_error_regs()
267 dev_err(sec->dev, "Doorbell: 0x%08x\n", doorbell); in log_error_regs()
269 if (!m10bmc_sys_read(sec->m10bmc, csr_map->auth_result, &auth_result)) in log_error_regs()
270 dev_err(sec->dev, "RSU auth result: 0x%08x\n", auth_result); in log_error_regs()
275 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in m10bmc_sec_n3000_rsu_status()
279 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, &doorbell); in m10bmc_sec_n3000_rsu_status()
288 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in m10bmc_sec_n6000_rsu_status()
292 ret = m10bmc_sys_read(sec->m10bmc, csr_map->auth_result, &auth_result); in m10bmc_sec_n6000_rsu_status()
324 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in m10bmc_sec_progress_status()
327 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, doorbell_reg); in m10bmc_sec_progress_status()
331 ret = sec->ops->rsu_status(sec); in m10bmc_sec_progress_status()
343 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in rsu_check_idle()
347 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, &doorbell); in rsu_check_idle()
375 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in rsu_update_init()
379 ret = m10bmc_sys_update_bits(sec->m10bmc, csr_map->doorbell, in rsu_update_init()
394 if (ret == -ETIMEDOUT) { in rsu_update_init()
402 dev_warn(sec->dev, "Excessive flash update count detected\n"); in rsu_update_init()
414 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in rsu_prog_ready()
419 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, &doorbell); in rsu_prog_ready()
429 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, &doorbell); in rsu_prog_ready()
448 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in rsu_send_data()
452 ret = m10bmc_sys_update_bits(sec->m10bmc, csr_map->doorbell, in rsu_send_data()
459 ret = regmap_read_poll_timeout(sec->m10bmc->regmap, in rsu_send_data()
460 csr_map->base + csr_map->doorbell, in rsu_send_data()
466 if (ret == -ETIMEDOUT) { in rsu_send_data()
473 ret = sec->ops->rsu_status(sec); in rsu_send_data()
491 return -EIO; in rsu_check_complete()
494 return -EINVAL; in rsu_check_complete()
500 return -EAGAIN; in rsu_check_complete()
502 return -EINVAL; in rsu_check_complete()
507 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in rsu_cancel()
511 ret = m10bmc_sys_read(sec->m10bmc, csr_map->doorbell, &doorbell); in rsu_cancel()
518 ret = m10bmc_sys_update_bits(sec->m10bmc, csr_map->doorbell, in rsu_cancel()
531 struct m10bmc_sec *sec = fwl->dd_handle; in m10bmc_sec_prepare()
532 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in m10bmc_sec_prepare()
535 sec->cancel_request = false; in m10bmc_sec_prepare()
537 if (!size || size > csr_map->staging_size) in m10bmc_sec_prepare()
540 if (sec->m10bmc->flash_bulk_ops) in m10bmc_sec_prepare()
541 if (sec->m10bmc->flash_bulk_ops->lock_write(sec->m10bmc)) in m10bmc_sec_prepare()
548 m10bmc_fw_state_set(sec->m10bmc, M10BMC_FW_STATE_SEC_UPDATE_PREPARE); in m10bmc_sec_prepare()
558 if (sec->cancel_request) { in m10bmc_sec_prepare()
563 m10bmc_fw_state_set(sec->m10bmc, M10BMC_FW_STATE_SEC_UPDATE_WRITE); in m10bmc_sec_prepare()
568 m10bmc_fw_state_set(sec->m10bmc, M10BMC_FW_STATE_NORMAL); in m10bmc_sec_prepare()
571 if (sec->m10bmc->flash_bulk_ops) in m10bmc_sec_prepare()
572 sec->m10bmc->flash_bulk_ops->unlock_write(sec->m10bmc); in m10bmc_sec_prepare()
576 #define WRITE_BLOCK_SIZE 0x4000 /* Default write-block size is 0x4000 bytes */
581 struct m10bmc_sec *sec = fwl->dd_handle; in m10bmc_sec_fw_write()
582 const struct m10bmc_csr_map *csr_map = sec->m10bmc->info->csr_map; in m10bmc_sec_fw_write()
583 struct intel_m10bmc *m10bmc = sec->m10bmc; in m10bmc_sec_fw_write()
587 if (sec->cancel_request) in m10bmc_sec_fw_write()
590 ret = m10bmc_sys_read(m10bmc, csr_map->doorbell, &doorbell); in m10bmc_sec_fw_write()
598 WARN_ON_ONCE(WRITE_BLOCK_SIZE % regmap_get_reg_stride(m10bmc->regmap)); in m10bmc_sec_fw_write()
610 struct m10bmc_sec *sec = fwl->dd_handle; in m10bmc_sec_poll_complete()
615 if (sec->cancel_request) in m10bmc_sec_poll_complete()
618 m10bmc_fw_state_set(sec->m10bmc, M10BMC_FW_STATE_SEC_UPDATE_PROGRAM); in m10bmc_sec_poll_complete()
628 } while (ret == -EAGAIN && !time_after(jiffies, poll_timeout)); in m10bmc_sec_poll_complete()
630 if (ret == -EAGAIN) { in m10bmc_sec_poll_complete()
633 } else if (ret == -EIO) { in m10bmc_sec_poll_complete()
644 * m10bmc_sec_cancel() may be called asynchronously with an on-going update.
652 struct m10bmc_sec *sec = fwl->dd_handle; in m10bmc_sec_cancel()
654 sec->cancel_request = true; in m10bmc_sec_cancel()
659 struct m10bmc_sec *sec = fwl->dd_handle; in m10bmc_sec_cleanup()
663 m10bmc_fw_state_set(sec->m10bmc, M10BMC_FW_STATE_NORMAL); in m10bmc_sec_cleanup()
665 if (sec->m10bmc->flash_bulk_ops) in m10bmc_sec_cleanup()
666 sec->m10bmc->flash_bulk_ops->unlock_write(sec->m10bmc); in m10bmc_sec_cleanup()
694 sec = devm_kzalloc(&pdev->dev, sizeof(*sec), GFP_KERNEL); in m10bmc_sec_probe()
696 return -ENOMEM; in m10bmc_sec_probe()
698 sec->dev = &pdev->dev; in m10bmc_sec_probe()
699 sec->m10bmc = dev_get_drvdata(pdev->dev.parent); in m10bmc_sec_probe()
700 sec->ops = (struct m10bmc_sec_ops *)platform_get_device_id(pdev)->driver_data; in m10bmc_sec_probe()
701 dev_set_drvdata(&pdev->dev, sec); in m10bmc_sec_probe()
703 ret = xa_alloc(&fw_upload_xa, &sec->fw_name_id, sec, in m10bmc_sec_probe()
708 len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d", in m10bmc_sec_probe()
709 sec->fw_name_id); in m10bmc_sec_probe()
710 sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL); in m10bmc_sec_probe()
711 if (!sec->fw_name) { in m10bmc_sec_probe()
712 ret = -ENOMEM; in m10bmc_sec_probe()
716 fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name, in m10bmc_sec_probe()
719 dev_err(sec->dev, "Firmware Upload driver failed to start\n"); in m10bmc_sec_probe()
724 sec->fwl = fwl; in m10bmc_sec_probe()
728 kfree(sec->fw_name); in m10bmc_sec_probe()
730 xa_erase(&fw_upload_xa, sec->fw_name_id); in m10bmc_sec_probe()
736 struct m10bmc_sec *sec = dev_get_drvdata(&pdev->dev); in m10bmc_sec_remove()
738 firmware_upload_unregister(sec->fwl); in m10bmc_sec_remove()
739 kfree(sec->fw_name); in m10bmc_sec_remove()
740 xa_erase(&fw_upload_xa, sec->fw_name_id); in m10bmc_sec_remove()
745 .name = "n3000bmc-sec-update",
749 .name = "d5005bmc-sec-update",
753 .name = "n6000bmc-sec-update",
764 .name = "intel-m10bmc-sec-update",