1f7d67c1cSKoby Elbaz /* SPDX-License-Identifier: GPL-2.0 2f7d67c1cSKoby Elbaz * 3f7d67c1cSKoby Elbaz * Copyright 2016-2022 HabanaLabs, Ltd. 4f7d67c1cSKoby Elbaz * All Rights Reserved. 5f7d67c1cSKoby Elbaz * 6f7d67c1cSKoby Elbaz */ 7f7d67c1cSKoby Elbaz 8f7d67c1cSKoby Elbaz #ifndef SECURITY_H_ 9f7d67c1cSKoby Elbaz #define SECURITY_H_ 10f7d67c1cSKoby Elbaz 11f7d67c1cSKoby Elbaz #include <linux/io-64-nonatomic-lo-hi.h> 12f7d67c1cSKoby Elbaz 13*69ff5bccSTom Rix struct hl_device; 14f7d67c1cSKoby Elbaz 15f7d67c1cSKoby Elbaz /* special blocks */ 16f7d67c1cSKoby Elbaz #define HL_MAX_NUM_OF_GLBL_ERR_CAUSE 10 17f7d67c1cSKoby Elbaz #define HL_GLBL_ERR_ADDRESS_MASK GENMASK(11, 0) 18f7d67c1cSKoby Elbaz /* GLBL_ERR_ADDR register offset from the start of the block */ 19f7d67c1cSKoby Elbaz #define HL_GLBL_ERR_ADDR_OFFSET 0xF44 20f7d67c1cSKoby Elbaz /* GLBL_ERR_CAUSE register offset from the start of the block */ 21f7d67c1cSKoby Elbaz #define HL_GLBL_ERR_CAUSE_OFFSET 0xF48 22f7d67c1cSKoby Elbaz 23f7d67c1cSKoby Elbaz /* 24f7d67c1cSKoby Elbaz * struct hl_special_block_info - stores address details of a particular type of 25f7d67c1cSKoby Elbaz * IP block which has a SPECIAL part. 26f7d67c1cSKoby Elbaz * 27f7d67c1cSKoby Elbaz * @block_type: block type as described in every ASIC's block_types enum. 28f7d67c1cSKoby Elbaz * @base_addr: base address of the first block of particular type, 29f7d67c1cSKoby Elbaz * e.g., address of NIC0_UMR0_0 of 'NIC_UMR' block. 30f7d67c1cSKoby Elbaz * @major: number of major blocks of particular type. 31f7d67c1cSKoby Elbaz * @minor: number of minor blocks of particular type. 32f7d67c1cSKoby Elbaz * @sub_minor: number of sub minor blocks of particular type. 33f7d67c1cSKoby Elbaz * @major_offset: address gap between 2 consecutive major blocks of particular type, 34f7d67c1cSKoby Elbaz * e.g., offset between NIC0_UMR0_0 and NIC1_UMR0_0 is 0x80000. 35f7d67c1cSKoby Elbaz * @minor_offset: address gap between 2 consecutive minor blocks of particular type, 36f7d67c1cSKoby Elbaz * e.g., offset between NIC0_UMR0_0 and NIC0_UMR1_0 is 0x20000. 37f7d67c1cSKoby Elbaz * @sub_minor_offset: address gap between 2 consecutive sub_minor blocks of particular 38f7d67c1cSKoby Elbaz * type, e.g., offset between NIC0_UMR0_0 and NIC0_UMR0_1 is 0x1000. 39f7d67c1cSKoby Elbaz * 40f7d67c1cSKoby Elbaz * e.g., in Gaudi2, NIC_UMR blocks can be interpreted as: 41f7d67c1cSKoby Elbaz * NIC<major>_UMR<minor>_<sub_minor> where major=12, minor=2, sub_minor=15. 42f7d67c1cSKoby Elbaz * In other words, for each of 12 major numbers (i.e 0 to 11) there are 43f7d67c1cSKoby Elbaz * 2 blocks with different minor numbers (i.e. 0 to 1). Again, for each minor 44f7d67c1cSKoby Elbaz * number there are 15 blocks with different sub_minor numbers (i.e. 0 to 14). 45f7d67c1cSKoby Elbaz * So different blocks are NIC0_UMR0_0, NIC0_UMR0_1, ..., NIC0_UMR1_0, ...., 46f7d67c1cSKoby Elbaz * NIC11_UMR1_14. 47f7d67c1cSKoby Elbaz * 48f7d67c1cSKoby Elbaz * Struct's formatted data is located in the SOL-based auto-generated protbits headers. 49f7d67c1cSKoby Elbaz */ 50f7d67c1cSKoby Elbaz struct hl_special_block_info { 51f7d67c1cSKoby Elbaz int block_type; 52f7d67c1cSKoby Elbaz u32 base_addr; 53f7d67c1cSKoby Elbaz u32 major; 54f7d67c1cSKoby Elbaz u32 minor; 55f7d67c1cSKoby Elbaz u32 sub_minor; 56f7d67c1cSKoby Elbaz u32 major_offset; 57f7d67c1cSKoby Elbaz u32 minor_offset; 58f7d67c1cSKoby Elbaz u32 sub_minor_offset; 59f7d67c1cSKoby Elbaz }; 60f7d67c1cSKoby Elbaz 61f7d67c1cSKoby Elbaz /* 62f7d67c1cSKoby Elbaz * struct hl_automated_pb_cfg - represents configurations of a particular type 63f7d67c1cSKoby Elbaz * of IP block which has protection bits. 64f7d67c1cSKoby Elbaz * 65f7d67c1cSKoby Elbaz * @addr: address details as described in hl_automation_pb_addr struct. 66f7d67c1cSKoby Elbaz * @prot_map: each bit corresponds to one among 32 protection configuration regs 67f7d67c1cSKoby Elbaz * (e.g., SPECIAL_GLBL_PRIV). '1' means 0xffffffff and '0' means 0x0 68f7d67c1cSKoby Elbaz * to be written into the corresponding protection configuration reg. 69f7d67c1cSKoby Elbaz * This bit is meaningful if same bit in data_map is 0, otherwise ignored. 70f7d67c1cSKoby Elbaz * @data_map: each bit corresponds to one among 32 protection configuration regs 71f7d67c1cSKoby Elbaz * (e.g., SPECIAL_GLBL_PRIV). '1' means corresponding protection 72f7d67c1cSKoby Elbaz * configuration reg is to be written with a value in array pointed 73f7d67c1cSKoby Elbaz * by 'data', otherwise the value is decided by 'prot_map'. 74f7d67c1cSKoby Elbaz * @data: pointer to data array which stores the config value(s) to be written 75f7d67c1cSKoby Elbaz * to corresponding protection configuration reg(s). 76f7d67c1cSKoby Elbaz * @data_size: size of the data array. 77f7d67c1cSKoby Elbaz * 78f7d67c1cSKoby Elbaz * Each bit of 'data_map' and 'prot_map' fields corresponds to one among 32 79f7d67c1cSKoby Elbaz * protection configuration registers e.g., SPECIAL GLBL PRIV regs (starting at 80f7d67c1cSKoby Elbaz * offset 0xE80). '1' in 'data_map' means protection configuration to be done 81f7d67c1cSKoby Elbaz * using configuration in data array. '0' in 'data_map" means protection 82f7d67c1cSKoby Elbaz * configuration to be done as per the value of corresponding bit in 'prot_map'. 83f7d67c1cSKoby Elbaz * '1' in 'prot_map' means the register to be programmed with 0xFFFFFFFF 84f7d67c1cSKoby Elbaz * (all non-protected). '0' in 'prot_map' means the register to be programmed 85f7d67c1cSKoby Elbaz * with 0x0 (all protected). 86f7d67c1cSKoby Elbaz * 87f7d67c1cSKoby Elbaz * e.g., prot_map = 0x00000001, data_map = 0xC0000000 , data = {0xff, 0x12} 88f7d67c1cSKoby Elbaz * SPECIAL_GLBL_PRIV[0] = 0xFFFFFFFF 89f7d67c1cSKoby Elbaz * SPECIAL_GLBL_PRIV[1..29] = 0x0 90f7d67c1cSKoby Elbaz * SPECIAL_GLBL_PRIV[30] = 0xFF 91f7d67c1cSKoby Elbaz * SPECIAL_GLBL_PRIV[31] = 0x12 92f7d67c1cSKoby Elbaz */ 93f7d67c1cSKoby Elbaz struct hl_automated_pb_cfg { 94f7d67c1cSKoby Elbaz struct hl_special_block_info addr; 95f7d67c1cSKoby Elbaz u32 prot_map; 96f7d67c1cSKoby Elbaz u32 data_map; 97f7d67c1cSKoby Elbaz const u32 *data; 98f7d67c1cSKoby Elbaz u8 data_size; 99f7d67c1cSKoby Elbaz }; 100f7d67c1cSKoby Elbaz 101f7d67c1cSKoby Elbaz /* struct hl_special_blocks_cfg - holds special blocks cfg data. 102f7d67c1cSKoby Elbaz * 103f7d67c1cSKoby Elbaz * @priv_automated_pb_cfg: points to the main privileged PB array. 104f7d67c1cSKoby Elbaz * @sec_automated_pb_cfg: points to the main secured PB array. 105f7d67c1cSKoby Elbaz * @skip_blocks_cfg: holds arrays of block types & block ranges to be excluded. 106f7d67c1cSKoby Elbaz * @priv_cfg_size: size of the main privileged PB array. 107f7d67c1cSKoby Elbaz * @sec_cfg_size: size of the main secured PB array. 108f7d67c1cSKoby Elbaz * @prot_lvl_priv: indication if it's a privileged/secured PB configurations. 109f7d67c1cSKoby Elbaz */ 110f7d67c1cSKoby Elbaz struct hl_special_blocks_cfg { 111f7d67c1cSKoby Elbaz struct hl_automated_pb_cfg *priv_automated_pb_cfg; 112f7d67c1cSKoby Elbaz struct hl_automated_pb_cfg *sec_automated_pb_cfg; 113f7d67c1cSKoby Elbaz struct hl_skip_blocks_cfg *skip_blocks_cfg; 114f7d67c1cSKoby Elbaz u32 priv_cfg_size; 115f7d67c1cSKoby Elbaz u32 sec_cfg_size; 116f7d67c1cSKoby Elbaz u8 prot_lvl_priv; 117f7d67c1cSKoby Elbaz }; 118f7d67c1cSKoby Elbaz 119f7d67c1cSKoby Elbaz /* Automated security */ 120f7d67c1cSKoby Elbaz 121f7d67c1cSKoby Elbaz /* struct hl_skip_blocks_cfg - holds arrays of block types & block ranges to be 122f7d67c1cSKoby Elbaz * excluded from special blocks configurations. 123f7d67c1cSKoby Elbaz * 124f7d67c1cSKoby Elbaz * @block_types: an array of block types NOT to be configured. 125f7d67c1cSKoby Elbaz * @block_types_len: len of an array of block types not to be configured. 126f7d67c1cSKoby Elbaz * @block_ranges: an array of block ranges not to be configured. 127f7d67c1cSKoby Elbaz * @block_ranges_len: len of an array of block ranges not to be configured. 128f7d67c1cSKoby Elbaz * @skip_block_hook: hook that will be called before initializing special blocks. 129f7d67c1cSKoby Elbaz */ 130f7d67c1cSKoby Elbaz struct hl_skip_blocks_cfg { 131f7d67c1cSKoby Elbaz int *block_types; 132f7d67c1cSKoby Elbaz size_t block_types_len; 133f7d67c1cSKoby Elbaz struct range *block_ranges; 134f7d67c1cSKoby Elbaz size_t block_ranges_len; 135f7d67c1cSKoby Elbaz bool (*skip_block_hook)(struct hl_device *hdev, 136f7d67c1cSKoby Elbaz struct hl_special_blocks_cfg *special_blocks_cfg, 137f7d67c1cSKoby Elbaz u32 blk_idx, u32 major, u32 minor, u32 sub_minor); 138f7d67c1cSKoby Elbaz }; 139f7d67c1cSKoby Elbaz 140f7d67c1cSKoby Elbaz /** 141f7d67c1cSKoby Elbaz * struct iterate_special_ctx - HW module special block iterator 142f7d67c1cSKoby Elbaz * @fn: function to apply to each HW module special block instance 143f7d67c1cSKoby Elbaz * @data: optional internal data to the function iterator 144f7d67c1cSKoby Elbaz */ 145f7d67c1cSKoby Elbaz struct iterate_special_ctx { 146f7d67c1cSKoby Elbaz /* 147f7d67c1cSKoby Elbaz * callback for the HW module special block iterator 148f7d67c1cSKoby Elbaz * @hdev: pointer to the habanalabs device structure 149f7d67c1cSKoby Elbaz * @block_id: block (ASIC specific definition can be dcore/hdcore) 150f7d67c1cSKoby Elbaz * @major: major block index within block_id 151f7d67c1cSKoby Elbaz * @minor: minor block index within the major block 152f7d67c1cSKoby Elbaz * @sub_minor: sub_minor block index within the minor block 153f7d67c1cSKoby Elbaz * @data: function specific data 154f7d67c1cSKoby Elbaz */ 155f7d67c1cSKoby Elbaz int (*fn)(struct hl_device *hdev, u32 block_id, u32 major, u32 minor, 156f7d67c1cSKoby Elbaz u32 sub_minor, void *data); 157f7d67c1cSKoby Elbaz void *data; 158f7d67c1cSKoby Elbaz }; 159f7d67c1cSKoby Elbaz 160f7d67c1cSKoby Elbaz int hl_iterate_special_blocks(struct hl_device *hdev, struct iterate_special_ctx *ctx); 161f7d67c1cSKoby Elbaz void hl_check_for_glbl_errors(struct hl_device *hdev); 162f7d67c1cSKoby Elbaz 163f7d67c1cSKoby Elbaz #endif /* SECURITY_H_ */ 164