diff options
Diffstat (limited to 'sys/dev/cxgbe/cudbg/cudbg_flash_utils.c')
-rw-r--r-- | sys/dev/cxgbe/cudbg/cudbg_flash_utils.c | 90 |
1 files changed, 41 insertions, 49 deletions
diff --git a/sys/dev/cxgbe/cudbg/cudbg_flash_utils.c b/sys/dev/cxgbe/cudbg/cudbg_flash_utils.c index b8e6eeba0280..2cd24c635325 100644 --- a/sys/dev/cxgbe/cudbg/cudbg_flash_utils.c +++ b/sys/dev/cxgbe/cudbg/cudbg_flash_utils.c @@ -32,19 +32,6 @@ #include "cudbg.h" #include "cudbg_lib_common.h" -enum { - SF_ATTEMPTS = 10, /* max retries for SF operations */ - - /* flash command opcodes */ - SF_PROG_PAGE = 2, /* program page */ - SF_WR_DISABLE = 4, /* disable writes */ - SF_RD_STATUS = 5, /* read status register */ - SF_WR_ENABLE = 6, /* enable writes */ - SF_RD_DATA_FAST = 0xb, /* read flash */ - SF_RD_ID = 0x9f, /* read ID */ - SF_ERASE_SECTOR = 0xd8, /* erase sector */ -}; - int write_flash(struct adapter *adap, u32 start_sec, void *data, u32 size); int read_flash(struct adapter *adap, u32 start_sec , void *data, u32 size, u32 start_address); @@ -56,10 +43,12 @@ update_skip_size(struct cudbg_flash_sec_info *sec_info, u32 size) } static -void set_sector_availability(struct cudbg_flash_sec_info *sec_info, - int sector_nu, int avail) +void set_sector_availability(struct adapter *adap, + struct cudbg_flash_sec_info *sec_info, int sector_nu, int avail) { - sector_nu -= CUDBG_START_SEC; + int start = t4_flash_loc_start(adap, FLASH_LOC_CUDBG, NULL); + + sector_nu -= start / SF_SEC_SIZE;; if (avail) set_dbg_bitmap(sec_info->sec_bitmap, sector_nu); else @@ -68,13 +57,17 @@ void set_sector_availability(struct cudbg_flash_sec_info *sec_info, /* This function will return empty sector available for filling */ static int -find_empty_sec(struct cudbg_flash_sec_info *sec_info) +find_empty_sec(struct adapter *adap, struct cudbg_flash_sec_info *sec_info) { int i, index, bit; - - for (i = CUDBG_START_SEC; i < CUDBG_SF_MAX_SECTOR; i++) { - index = (i - CUDBG_START_SEC) / 8; - bit = (i - CUDBG_START_SEC) % 8; + unsigned int len = 0; + int start = t4_flash_loc_start(adap, FLASH_LOC_CUDBG, &len); + + start /= SF_SEC_SIZE; /* addr -> sector */ + len /= SF_SEC_SIZE; + for (i = start; i < start + len; i++) { + index = (i - start) / 8; + bit = (i - start) % 8; if (!(sec_info->sec_bitmap[index] & (1 << bit))) return i; } @@ -102,7 +95,7 @@ static void update_headers(void *handle, struct cudbg_buffer *dbg_buff, data_hdr_size = CUDBG_MAX_ENTITY * sizeof(struct cudbg_entity_hdr) + sizeof(struct cudbg_hdr); total_hdr_size = data_hdr_size + sizeof(struct cudbg_flash_hdr); - sec_hdr_start_addr = CUDBG_SF_SECTOR_SIZE - total_hdr_size; + sec_hdr_start_addr = SF_SEC_SIZE - total_hdr_size; sec_hdr = sec_info->sec_data + sec_hdr_start_addr; flash_hdr = (struct cudbg_flash_hdr *)(sec_hdr); @@ -166,11 +159,13 @@ int cudbg_write_flash(void *handle, u64 timestamp, void *data, u32 space_left; int rc = 0; int sec; + unsigned int cudbg_max_size = 0; + t4_flash_loc_start(adap, FLASH_LOC_CUDBG, &cudbg_max_size); data_hdr_size = CUDBG_MAX_ENTITY * sizeof(struct cudbg_entity_hdr) + sizeof(struct cudbg_hdr); total_hdr_size = data_hdr_size + sizeof(struct cudbg_flash_hdr); - sec_hdr_start_addr = CUDBG_SF_SECTOR_SIZE - total_hdr_size; + sec_hdr_start_addr = SF_SEC_SIZE - total_hdr_size; sec_data_size = sec_hdr_start_addr; cudbg_init->print("\tWriting %u bytes to flash\n", cur_entity_size); @@ -191,12 +186,12 @@ int cudbg_write_flash(void *handle, u64 timestamp, void *data, flash_hdr = (struct cudbg_flash_hdr *)(sec_info->sec_data + sec_hdr_start_addr); - if (flash_hdr->data_len > CUDBG_FLASH_SIZE) { + if (flash_hdr->data_len > cudbg_max_size) { rc = CUDBG_STATUS_FLASH_FULL; goto out; } - space_left = CUDBG_FLASH_SIZE - flash_hdr->data_len; + space_left = cudbg_max_size - flash_hdr->data_len; if (cur_entity_size > space_left) { rc = CUDBG_STATUS_FLASH_FULL; @@ -204,10 +199,11 @@ int cudbg_write_flash(void *handle, u64 timestamp, void *data, } while (cur_entity_size > 0) { - sec = find_empty_sec(sec_info); + sec = find_empty_sec(adap, sec_info); if (sec_info->par_sec) { sec_data_offset = sec_info->par_sec_offset; - set_sector_availability(sec_info, sec_info->par_sec, 0); + set_sector_availability(adap, sec_info, + sec_info->par_sec, 0); sec_info->par_sec = 0; sec_info->par_sec_offset = 0; @@ -230,13 +226,12 @@ int cudbg_write_flash(void *handle, u64 timestamp, void *data, (void *)((char *)dbg_buff->data + start_offset), tmp_size); - rc = write_flash(adap, sec, sec_info->sec_data, - CUDBG_SF_SECTOR_SIZE); + rc = write_flash(adap, sec, sec_info->sec_data, SF_SEC_SIZE); if (rc) goto out; cur_entity_size -= tmp_size; - set_sector_availability(sec_info, sec, 1); + set_sector_availability(adap, sec_info, sec, 1); start_offset += tmp_size; } out: @@ -247,19 +242,14 @@ int write_flash(struct adapter *adap, u32 start_sec, void *data, u32 size) { unsigned int addr; unsigned int i, n; - unsigned int sf_sec_size; int rc = 0; u8 *ptr = (u8 *)data; - sf_sec_size = adap->params.sf_size/adap->params.sf_nsec; - - addr = start_sec * CUDBG_SF_SECTOR_SIZE; - i = DIV_ROUND_UP(size,/* # of sectors spanned */ - sf_sec_size); + addr = start_sec * SF_SEC_SIZE; + i = DIV_ROUND_UP(size, SF_SEC_SIZE); - rc = t4_flash_erase_sectors(adap, start_sec, - start_sec + i - 1); + rc = t4_flash_erase_sectors(adap, start_sec, start_sec + i - 1); /* * If size == 0 then we're simply erasing the FLASH sectors associated * with the on-adapter OptionROM Configuration File. @@ -337,6 +327,9 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) u32 data_offset = 0; u32 i, j; int rc; + unsigned int cudbg_len = 0; + int cudbg_start_sec = t4_flash_loc_start(adap, FLASH_LOC_CUDBG, + &cudbg_len) / SF_SEC_SIZE; rc = t4_get_flash_params(adap); if (rc) { @@ -348,7 +341,7 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) data_hdr_size = CUDBG_MAX_ENTITY * sizeof(struct cudbg_entity_hdr) + sizeof(struct cudbg_hdr); total_hdr_size = data_hdr_size + sizeof(struct cudbg_flash_hdr); - sec_hdr_start_addr = CUDBG_SF_SECTOR_SIZE - total_hdr_size; + sec_hdr_start_addr = SF_SEC_SIZE - total_hdr_size; if (!data_flag) { /* fill header */ @@ -357,14 +350,14 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) * have older filled sector also */ memset(&flash_hdr, 0, sizeof(struct cudbg_flash_hdr)); - rc = read_flash(adap, CUDBG_START_SEC, &flash_hdr, + rc = read_flash(adap, cudbg_start_sec, &flash_hdr, sizeof(struct cudbg_flash_hdr), sec_hdr_start_addr); if (flash_hdr.signature == CUDBG_FL_SIGNATURE) { sec_info->max_timestamp = flash_hdr.timestamp; } else { - rc = read_flash(adap, CUDBG_START_SEC + 1, + rc = read_flash(adap, cudbg_start_sec + 1, &flash_hdr, sizeof(struct cudbg_flash_hdr), sec_hdr_start_addr); @@ -383,8 +376,8 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) /* finding max sequence number because max sequenced * sector has updated header */ - for (i = CUDBG_START_SEC; i < - CUDBG_SF_MAX_SECTOR; i++) { + for (i = cudbg_start_sec; i < cudbg_start_sec + + cudbg_len / SF_SEC_SIZE; i++) { memset(&flash_hdr, 0, sizeof(struct cudbg_flash_hdr)); rc = read_flash(adap, i, &flash_hdr, @@ -423,7 +416,8 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) /* finding sector sequence sorted */ for (i = 1; i <= sec_info->max_seq_no; i++) { - for (j = CUDBG_START_SEC; j < CUDBG_SF_MAX_SECTOR; j++) { + for (j = cudbg_start_sec; j < cudbg_start_sec + + cudbg_len / SF_SEC_SIZE; j++) { memset(&flash_hdr, 0, sizeof(struct cudbg_flash_hdr)); rc = read_flash(adap, j, &flash_hdr, sizeof(struct cudbg_flash_hdr), @@ -434,10 +428,8 @@ int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag) sec_info->max_timestamp == flash_hdr.timestamp && flash_hdr.sec_seq_no == i) { - if (size + total_hdr_size > - CUDBG_SF_SECTOR_SIZE) - tmp_size = CUDBG_SF_SECTOR_SIZE - - total_hdr_size; + if (size + total_hdr_size > SF_SEC_SIZE) + tmp_size = SF_SEC_SIZE - total_hdr_size; else tmp_size = size; @@ -468,7 +460,7 @@ int read_flash(struct adapter *adap, u32 start_sec , void *data, u32 size, unsigned int addr, i, n; int rc; u32 *ptr = (u32 *)data; - addr = start_sec * CUDBG_SF_SECTOR_SIZE + start_address; + addr = start_sec * SF_SEC_SIZE + start_address; size = size / 4; for (i = 0; i < size; i += SF_PAGE_SIZE) { if ((size - i) < SF_PAGE_SIZE) |