Lines Matching refs:state

55 static int hermon_ioctl_flash_read(hermon_state_t *state, dev_t dev,
57 static int hermon_ioctl_flash_write(hermon_state_t *state, dev_t dev,
59 static int hermon_ioctl_flash_erase(hermon_state_t *state, dev_t dev,
61 static int hermon_ioctl_flash_init(hermon_state_t *state, dev_t dev,
63 static int hermon_ioctl_flash_fini(hermon_state_t *state, dev_t dev);
64 static int hermon_ioctl_flash_cleanup(hermon_state_t *state);
65 static int hermon_ioctl_flash_cleanup_nolock(hermon_state_t *state);
67 static int hermon_ioctl_reg_write(hermon_state_t *state, intptr_t arg,
69 static int hermon_ioctl_reg_read(hermon_state_t *state, intptr_t arg,
72 static int hermon_ioctl_write_boot_addr(hermon_state_t *state, dev_t dev,
74 static int hermon_ioctl_info(hermon_state_t *state, dev_t dev,
76 static int hermon_ioctl_ports(hermon_state_t *state, intptr_t arg,
78 static int hermon_ioctl_loopback(hermon_state_t *state, intptr_t arg,
82 static void hermon_flash_spi_exec_command(hermon_state_t *state,
84 static int hermon_flash_read_sector(hermon_state_t *state,
86 static int hermon_flash_read_quadlet(hermon_state_t *state, uint32_t *data,
88 static int hermon_flash_write_sector(hermon_state_t *state,
90 static int hermon_flash_spi_write_dword(hermon_state_t *state,
92 static int hermon_flash_write_byte(hermon_state_t *state, uint32_t addr,
94 static int hermon_flash_erase_sector(hermon_state_t *state,
96 static int hermon_flash_erase_chip(hermon_state_t *state);
97 static int hermon_flash_bank(hermon_state_t *state, uint32_t addr);
98 static uint32_t hermon_flash_read(hermon_state_t *state, uint32_t addr,
100 static void hermon_flash_write(hermon_state_t *state, uint32_t addr,
102 static int hermon_flash_spi_wait_wip(hermon_state_t *state);
103 static void hermon_flash_spi_write_enable(hermon_state_t *state);
104 static int hermon_flash_init(hermon_state_t *state);
105 static int hermon_flash_cfi_init(hermon_state_t *state, uint32_t *cfi_info,
107 static int hermon_flash_fini(hermon_state_t *state);
108 static int hermon_flash_reset(hermon_state_t *state);
109 static uint32_t hermon_flash_read_cfg(hermon_state_t *state,
112 static void hermon_flash_write_cfg(hermon_state_t *state,
114 static void hermon_flash_write_cfg_helper(hermon_state_t *state,
116 static void hermon_flash_write_confirm(hermon_state_t *state,
125 static int hermon_loopback_init(hermon_state_t *state,
156 hermon_state_t *state; in hermon_ioctl() local
169 state = ddi_get_soft_state(hermon_statep, instance); in hermon_ioctl()
170 if (state == NULL) { in hermon_ioctl()
178 status = hermon_ioctl_flash_read(state, dev, arg, mode); in hermon_ioctl()
182 status = hermon_ioctl_flash_write(state, dev, arg, mode); in hermon_ioctl()
186 status = hermon_ioctl_flash_erase(state, dev, arg, mode); in hermon_ioctl()
190 status = hermon_ioctl_flash_init(state, dev, arg, mode); in hermon_ioctl()
194 status = hermon_ioctl_flash_fini(state, dev); in hermon_ioctl()
198 status = hermon_ioctl_info(state, dev, arg, mode); in hermon_ioctl()
202 status = hermon_ioctl_ports(state, arg, mode); in hermon_ioctl()
206 status = hermon_ioctl_loopback(state, arg, mode); in hermon_ioctl()
211 status = hermon_ioctl_reg_write(state, arg, mode); in hermon_ioctl()
215 status = hermon_ioctl_reg_read(state, arg, mode); in hermon_ioctl()
225 status = hermon_ioctl_write_boot_addr(state, dev, arg, mode); in hermon_ioctl()
241 hermon_ioctl_flash_read(hermon_state_t *state, dev_t dev, intptr_t arg, in hermon_ioctl_flash_read() argument
251 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
252 if ((state->hs_fw_flashdev != dev) || in hermon_ioctl_flash_read()
253 (state->hs_fw_flashstarted == 0)) { in hermon_ioctl_flash_read()
254 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
265 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
276 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
287 (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) { in hermon_ioctl_flash_read()
288 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
293 if ((status = hermon_flash_reset(state)) != 0 || in hermon_ioctl_flash_read()
294 (status = hermon_flash_read_sector(state, in hermon_ioctl_flash_read()
296 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
301 if (ddi_copyout(&state->hs_fw_sector[0], in hermon_ioctl_flash_read()
302 &ioctl_info.af_sector[0], 1 << state->hs_fw_log_sector_sz, in hermon_ioctl_flash_read()
304 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
311 if (ioctl_info.af_addr >= state->hs_fw_device_sz) { in hermon_ioctl_flash_read()
312 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
317 if ((status = hermon_flash_reset(state)) != 0 || in hermon_ioctl_flash_read()
318 (status = hermon_flash_read_quadlet(state, in hermon_ioctl_flash_read()
320 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
326 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
343 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
350 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
354 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_read()
362 hermon_ioctl_flash_write(hermon_state_t *state, dev_t dev, intptr_t arg, in hermon_ioctl_flash_write() argument
372 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
373 if ((state->hs_fw_flashdev != dev) || in hermon_ioctl_flash_write()
374 (state->hs_fw_flashstarted == 0)) { in hermon_ioctl_flash_write()
375 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
386 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
398 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
409 (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) { in hermon_ioctl_flash_write()
410 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
416 &state->hs_fw_sector[0], 1 << state->hs_fw_log_sector_sz, in hermon_ioctl_flash_write()
418 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
423 status = hermon_flash_write_sector(state, in hermon_ioctl_flash_write()
429 if (ioctl_info.af_addr >= state->hs_fw_device_sz) { in hermon_ioctl_flash_write()
430 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
440 if ((status = hermon_flash_bank(state, in hermon_ioctl_flash_write()
442 (status = hermon_flash_reset(state)) != 0 || in hermon_ioctl_flash_write()
443 (status = hermon_flash_write_byte(state, in hermon_ioctl_flash_write()
445 (status = hermon_flash_reset(state)) != 0) { in hermon_ioctl_flash_write()
446 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
456 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_write()
464 hermon_ioctl_flash_erase(hermon_state_t *state, dev_t dev, intptr_t arg, in hermon_ioctl_flash_erase() argument
474 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
475 if ((state->hs_fw_flashdev != dev) || in hermon_ioctl_flash_erase()
476 (state->hs_fw_flashstarted == 0)) { in hermon_ioctl_flash_erase()
477 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
488 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
497 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
508 (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) { in hermon_ioctl_flash_erase()
509 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
514 status = hermon_flash_erase_sector(state, in hermon_ioctl_flash_erase()
520 status = hermon_flash_erase_chip(state); in hermon_ioctl_flash_erase()
528 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_erase()
536 hermon_ioctl_flash_init(hermon_state_t *state, dev_t dev, intptr_t arg, in hermon_ioctl_flash_init() argument
542 ddi_acc_handle_t pci_hdl = hermon_get_pcihdl(state); in hermon_ioctl_flash_init()
547 state->hs_fw_sector = NULL; in hermon_ioctl_flash_init()
553 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
554 if (state->hs_fw_flashstarted == 1) { in hermon_ioctl_flash_init()
555 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
562 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
567 if ((ret = hermon_flash_init(state)) != 0) { in hermon_ioctl_flash_init()
571 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
576 if ((ret = hermon_flash_cfi_init(state, &init_info.af_cfi_info[0], in hermon_ioctl_flash_init()
581 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
588 if (state->hs_fw_cmdset == HERMON_FLASH_UNKNOWN_CMDSET) { in hermon_ioctl_flash_init()
589 if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) { in hermon_ioctl_flash_init()
593 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
596 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
601 hermon_pio_start(state, pci_hdl, pio_error, in hermon_ioctl_flash_init()
609 hermon_pio_end(state, pci_hdl, pio_error, fm_loop_cnt, in hermon_ioctl_flash_init()
613 init_info.af_fwrev.afi_maj = state->hs_fw.fw_rev_major; in hermon_ioctl_flash_init()
614 init_info.af_fwrev.afi_min = state->hs_fw.fw_rev_minor; in hermon_ioctl_flash_init()
615 init_info.af_fwrev.afi_sub = state->hs_fw.fw_rev_subminor; in hermon_ioctl_flash_init()
618 state->hs_fw_sector = (uint32_t *)kmem_zalloc(1 << in hermon_ioctl_flash_init()
619 state->hs_fw_log_sector_sz, KM_SLEEP); in hermon_ioctl_flash_init()
622 init_info.af_pn_len = state->hs_hca_pn_len; in hermon_ioctl_flash_init()
623 if (state->hs_hca_pn_len != 0) { in hermon_ioctl_flash_init()
624 (void) memcpy(init_info.af_hwpn, state->hs_hca_pn, in hermon_ioctl_flash_init()
625 state->hs_hca_pn_len); in hermon_ioctl_flash_init()
631 if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) { in hermon_ioctl_flash_init()
635 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
638 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
643 state->hs_fw_flashstarted = 1; in hermon_ioctl_flash_init()
644 state->hs_fw_flashdev = dev; in hermon_ioctl_flash_init()
646 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
655 (int (*)(void *))hermon_ioctl_flash_cleanup, state); in hermon_ioctl_flash_init()
657 int status = hermon_ioctl_flash_fini(state, dev); in hermon_ioctl_flash_init()
660 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_ioctl_flash_init()
670 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_init()
671 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_ioctl_flash_init()
679 hermon_ioctl_flash_fini(hermon_state_t *state, dev_t dev) in hermon_ioctl_flash_fini() argument
687 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_fini()
688 if ((state->hs_fw_flashdev != dev) || in hermon_ioctl_flash_fini()
689 (state->hs_fw_flashstarted == 0)) { in hermon_ioctl_flash_fini()
690 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_fini()
694 if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) { in hermon_ioctl_flash_fini()
695 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_fini()
697 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_ioctl_flash_fini()
701 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_fini()
720 hermon_ioctl_flash_cleanup(hermon_state_t *state) in hermon_ioctl_flash_cleanup() argument
724 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_flash_cleanup()
725 status = hermon_ioctl_flash_cleanup_nolock(state); in hermon_ioctl_flash_cleanup()
726 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_flash_cleanup()
736 hermon_ioctl_flash_cleanup_nolock(hermon_state_t *state) in hermon_ioctl_flash_cleanup_nolock() argument
739 ASSERT(MUTEX_HELD(&state->hs_fw_flashlock)); in hermon_ioctl_flash_cleanup_nolock()
742 if (state->hs_fw_sector) { in hermon_ioctl_flash_cleanup_nolock()
743 kmem_free(state->hs_fw_sector, 1 << state->hs_fw_log_sector_sz); in hermon_ioctl_flash_cleanup_nolock()
747 if ((status = hermon_flash_fini(state)) != 0) in hermon_ioctl_flash_cleanup_nolock()
751 state->hs_fw_flashstarted = 0; in hermon_ioctl_flash_cleanup_nolock()
752 state->hs_fw_flashdev = 0; in hermon_ioctl_flash_cleanup_nolock()
761 hermon_ioctl_info(hermon_state_t *state, dev_t dev, intptr_t arg, int mode) in hermon_ioctl_info() argument
769 if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) { in hermon_ioctl_info()
793 mutex_enter(&state->hs_info_lock); in hermon_ioctl_info()
794 if (state->hs_fw_device_sz == 0) { in hermon_ioctl_info()
795 if (hermon_ioctl_flash_init(state, dev, (intptr_t)&init_info, in hermon_ioctl_info()
797 mutex_exit(&state->hs_info_lock); in hermon_ioctl_info()
800 (void) hermon_ioctl_flash_fini(state, dev); in hermon_ioctl_info()
802 mutex_exit(&state->hs_info_lock); in hermon_ioctl_info()
804 info.ai_hw_rev = state->hs_revision_id; in hermon_ioctl_info()
805 info.ai_flash_sz = state->hs_fw_device_sz; in hermon_ioctl_info()
806 info.ai_fw_rev.afi_maj = state->hs_fw.fw_rev_major; in hermon_ioctl_info()
807 info.ai_fw_rev.afi_min = state->hs_fw.fw_rev_minor; in hermon_ioctl_info()
808 info.ai_fw_rev.afi_sub = state->hs_fw.fw_rev_subminor; in hermon_ioctl_info()
823 hermon_ioctl_ports(hermon_state_t *state, intptr_t arg, int mode) in hermon_ioctl_ports() argument
836 if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) { in hermon_ioctl_ports()
869 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl); in hermon_ioctl_ports()
872 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl); in hermon_ioctl_ports()
882 info.ap_num_ports = (uint8_t)state->hs_cfg_profile->cp_num_ports; in hermon_ioctl_ports()
892 (void) hermon_port_query(state, i + 1, &pi); in hermon_ioctl_ports()
912 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl); in hermon_ioctl_ports()
914 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl); in hermon_ioctl_ports()
944 hermon_ioctl_loopback(hermon_state_t *state, intptr_t arg, int mode) in hermon_ioctl_loopback() argument
959 if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) { in hermon_ioctl_loopback()
1002 if (!hermon_portnum_is_valid(state, lb.alb_port_num)) { in hermon_ioctl_loopback()
1009 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl); in hermon_ioctl_loopback()
1012 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl); in hermon_ioctl_loopback()
1022 if (hermon_port_query(state, lb.alb_port_num, &pi) != 0) { in hermon_ioctl_loopback()
1024 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl); in hermon_ioctl_loopback()
1026 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl); in hermon_ioctl_loopback()
1039 lstate.hls_state = state; in hermon_ioctl_loopback()
1043 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl); in hermon_ioctl_loopback()
1045 tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl); in hermon_ioctl_loopback()
1075 if (hermon_loopback_init(state, &lstate) != 0) { in hermon_ioctl_loopback()
1223 hermon_ioctl_reg_read(hermon_state_t *state, intptr_t arg, int mode) in hermon_ioctl_reg_read() argument
1238 if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) { in hermon_ioctl_reg_read()
1252 baseaddr = (uintptr_t)state->hs_reg_cmd_baseaddr; in hermon_ioctl_reg_read()
1253 handle = hermon_get_cmdhdl(state); in hermon_ioctl_reg_read()
1257 baseaddr = (uintptr_t)state->hs_reg_uar_baseaddr; in hermon_ioctl_reg_read()
1258 handle = hermon_get_uarhdl(state); in hermon_ioctl_reg_read()
1270 hermon_pio_start(state, handle, pio_error, fm_loop_cnt, in hermon_ioctl_reg_read()
1277 hermon_pio_end(state, handle, pio_error, fm_loop_cnt, fm_status, in hermon_ioctl_reg_read()
1289 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_ioctl_reg_read()
1298 hermon_ioctl_reg_write(hermon_state_t *state, intptr_t arg, int mode) in hermon_ioctl_reg_write() argument
1313 if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) { in hermon_ioctl_reg_write()
1327 baseaddr = (uintptr_t)state->hs_reg_cmd_baseaddr; in hermon_ioctl_reg_write()
1328 handle = hermon_get_cmdhdl(state); in hermon_ioctl_reg_write()
1332 baseaddr = (uintptr_t)state->hs_reg_uar_baseaddr; in hermon_ioctl_reg_write()
1333 handle = hermon_get_uarhdl(state); in hermon_ioctl_reg_write()
1344 hermon_pio_start(state, handle, pio_error, fm_loop_cnt, in hermon_ioctl_reg_write()
1351 hermon_pio_end(state, handle, pio_error, fm_loop_cnt, fm_status, in hermon_ioctl_reg_write()
1356 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_ioctl_reg_write()
1362 hermon_ioctl_write_boot_addr(hermon_state_t *state, dev_t dev, intptr_t arg, in hermon_ioctl_write_boot_addr() argument
1374 mutex_enter(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1375 if ((state->hs_fw_flashdev != dev) || in hermon_ioctl_write_boot_addr()
1376 (state->hs_fw_flashstarted == 0)) { in hermon_ioctl_write_boot_addr()
1377 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1388 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1400 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1404 switch (state->hs_fw_cmdset) { in hermon_ioctl_write_boot_addr()
1411 ddi_acc_handle_t pci_hdl = hermon_get_pcihdl(state); in hermon_ioctl_write_boot_addr()
1414 hermon_pio_start(state, pci_hdl, pio_error, in hermon_ioctl_write_boot_addr()
1417 hermon_flash_write_cfg(state, pci_hdl, in hermon_ioctl_write_boot_addr()
1422 hermon_pio_end(state, pci_hdl, pio_error, in hermon_ioctl_write_boot_addr()
1429 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1432 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1436 mutex_exit(&state->hs_fw_flashlock); in hermon_ioctl_write_boot_addr()
1437 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_ioctl_write_boot_addr()
1445 hermon_flash_reset(hermon_state_t *state) in hermon_flash_reset() argument
1453 switch (state->hs_fw_cmdset) { in hermon_flash_reset()
1455 hermon_flash_write(state, 0x555, HERMON_HW_FLASH_RESET_AMD, in hermon_flash_reset()
1463 hermon_flash_write(state, 0x555, HERMON_HW_FLASH_RESET_INTEL, in hermon_flash_reset()
1487 hermon_flash_read_sector(hermon_state_t *state, uint32_t sector_num) in hermon_flash_read_sector() argument
1494 image = (uint32_t *)&state->hs_fw_sector[0]; in hermon_flash_read_sector()
1500 addr = sector_num << state->hs_fw_log_sector_sz; in hermon_flash_read_sector()
1501 end_addr = addr + (1 << state->hs_fw_log_sector_sz); in hermon_flash_read_sector()
1504 if ((status = hermon_flash_bank(state, addr)) != 0) in hermon_flash_read_sector()
1509 image[i] = hermon_flash_read(state, addr, &status); in hermon_flash_read_sector()
1521 hermon_flash_read_quadlet(hermon_state_t *state, uint32_t *data, in hermon_flash_read_quadlet() argument
1527 if ((status = hermon_flash_bank(state, addr)) != 0) { in hermon_flash_read_quadlet()
1532 *data = hermon_flash_read(state, addr, &status); in hermon_flash_read_quadlet()
1544 hermon_flash_write_sector(hermon_state_t *state, uint32_t sector_num) in hermon_flash_write_sector() argument
1553 sector = (uchar_t *)&state->hs_fw_sector[0]; in hermon_flash_write_sector()
1559 addr = sector_num << state->hs_fw_log_sector_sz; in hermon_flash_write_sector()
1560 end_addr = addr + (1 << state->hs_fw_log_sector_sz); in hermon_flash_write_sector()
1563 if ((status = hermon_flash_bank(state, addr)) != 0 || in hermon_flash_write_sector()
1564 (status = hermon_flash_reset(state)) != 0) { in hermon_flash_write_sector()
1569 status = hermon_flash_erase_sector(state, sector_num); in hermon_flash_write_sector()
1574 switch (state->hs_fw_cmdset) { in hermon_flash_write_sector()
1579 if ((status = hermon_flash_spi_write_dword(state, addr, in hermon_flash_write_sector()
1584 status = hermon_flash_reset(state); in hermon_flash_write_sector()
1591 status = hermon_flash_write_byte(state, addr, in hermon_flash_write_sector()
1597 status = hermon_flash_reset(state); in hermon_flash_write_sector()
1616 hermon_flash_spi_write_dword(hermon_state_t *state, uint32_t addr, in hermon_flash_spi_write_dword() argument
1625 hdl = hermon_get_pcihdl(state); in hermon_flash_spi_write_dword()
1628 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_spi_write_dword()
1632 hermon_flash_spi_write_enable(state); in hermon_flash_spi_write_dword()
1635 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR, in hermon_flash_spi_write_dword()
1639 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_DATA, data); in hermon_flash_spi_write_dword()
1642 hermon_flash_spi_exec_command(state, hdl, in hermon_flash_spi_write_dword()
1651 if ((status = hermon_flash_spi_wait_wip(state)) != 0) { in hermon_flash_spi_write_dword()
1656 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_spi_write_dword()
1660 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_spi_write_dword()
1668 hermon_flash_write_byte(hermon_state_t *state, uint32_t addr, uchar_t data) in hermon_flash_write_byte() argument
1680 switch (state->hs_fw_cmdset) { in hermon_flash_write_byte()
1683 hermon_flash_write(state, addr, 0xAA, &status); in hermon_flash_write_byte()
1688 hermon_flash_write(state, addr, 0x55, &status); in hermon_flash_write_byte()
1693 hermon_flash_write(state, addr, 0xA0, &status); in hermon_flash_write_byte()
1698 hermon_flash_write(state, addr, data, &status); in hermon_flash_write_byte()
1707 stat = hermon_flash_read(state, addr & ~3, &status); in hermon_flash_write_byte()
1717 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_write_byte()
1728 hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_WRITE, in hermon_flash_write_byte()
1733 hermon_flash_write(state, addr, data, &status); in hermon_flash_write_byte()
1742 stat = hermon_flash_read(state, addr & ~3, &status); in hermon_flash_write_byte()
1752 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_write_byte()
1764 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_write_byte()
1785 if ((status = hermon_flash_read_quadlet(state, &dword.dword, in hermon_flash_write_byte()
1793 status = hermon_flash_spi_write_dword(state, dword_addr, in hermon_flash_write_byte()
1802 state->hs_fw_cmdset); in hermon_flash_write_byte()
1814 hermon_flash_erase_sector(hermon_state_t *state, uint32_t sector_num) in hermon_flash_erase_sector() argument
1826 addr = sector_num << state->hs_fw_log_sector_sz; in hermon_flash_erase_sector()
1828 switch (state->hs_fw_cmdset) { in hermon_flash_erase_sector()
1831 hermon_flash_write(state, addr, 0xAA, &status); in hermon_flash_erase_sector()
1836 hermon_flash_write(state, addr, 0x55, &status); in hermon_flash_erase_sector()
1841 hermon_flash_write(state, addr, 0x80, &status); in hermon_flash_erase_sector()
1846 hermon_flash_write(state, addr, 0xAA, &status); in hermon_flash_erase_sector()
1851 hermon_flash_write(state, addr, 0x55, &status); in hermon_flash_erase_sector()
1856 hermon_flash_write(state, addr, 0x30, &status); in hermon_flash_erase_sector()
1865 stat = hermon_flash_read(state, addr, &status); in hermon_flash_erase_sector()
1874 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_erase_sector()
1884 hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_ERASE, in hermon_flash_erase_sector()
1890 hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_CONFIRM, in hermon_flash_erase_sector()
1900 stat = hermon_flash_read(state, addr & ~3, &status); in hermon_flash_erase_sector()
1909 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_erase_sector()
1920 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_erase_sector()
1927 hdl = hermon_get_pcihdl(state); in hermon_flash_erase_sector()
1930 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_erase_sector()
1934 hermon_flash_spi_write_enable(state); in hermon_flash_erase_sector()
1937 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR, in hermon_flash_erase_sector()
1941 hermon_flash_spi_exec_command(state, hdl, in hermon_flash_erase_sector()
1948 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_erase_sector()
1952 status = hermon_flash_spi_wait_wip(state); in hermon_flash_erase_sector()
1959 state->hs_fw_cmdset); in hermon_flash_erase_sector()
1966 status = hermon_flash_reset(state); in hermon_flash_erase_sector()
1971 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_erase_sector()
1979 hermon_flash_erase_chip(hermon_state_t *state) in hermon_flash_erase_chip() argument
1987 switch (state->hs_fw_cmdset) { in hermon_flash_erase_chip()
1990 hermon_flash_write(state, 0, 0xAA, &status); in hermon_flash_erase_chip()
1995 hermon_flash_write(state, 0, 0x55, &status); in hermon_flash_erase_chip()
2000 hermon_flash_write(state, 0, 0x80, &status); in hermon_flash_erase_chip()
2005 hermon_flash_write(state, 0, 0xAA, &status); in hermon_flash_erase_chip()
2010 hermon_flash_write(state, 0, 0x55, &status); in hermon_flash_erase_chip()
2015 hermon_flash_write(state, 0, 0x10, &status); in hermon_flash_erase_chip()
2024 stat = hermon_flash_read(state, 0, &status); in hermon_flash_erase_chip()
2032 hermon_fm_ereport(state, HCA_SYS_ERR, in hermon_flash_erase_chip()
2046 size = (0x1 << state->hs_fw_log_sector_sz); in hermon_flash_erase_chip()
2047 num_sect = state->hs_fw_device_sz / size; in hermon_flash_erase_chip()
2050 status = hermon_flash_erase_sector(state, i); in hermon_flash_erase_chip()
2063 "unknown cmd set: 0x%x\n", state->hs_fw_cmdset); in hermon_flash_erase_chip()
2075 hermon_flash_spi_write_enable(hermon_state_t *state) in hermon_flash_spi_write_enable() argument
2079 hdl = hermon_get_pcihdl(state); in hermon_flash_spi_write_enable()
2081 hermon_flash_spi_exec_command(state, hdl, in hermon_flash_spi_write_enable()
2091 hermon_flash_spi_wait_wip(hermon_state_t *state) in hermon_flash_spi_wait_wip() argument
2099 hdl = hermon_get_pcihdl(state); in hermon_flash_spi_wait_wip()
2102 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_spi_wait_wip()
2107 status = hermon_flash_read_cfg(state, hdl, in hermon_flash_spi_wait_wip()
2113 hermon_flash_spi_exec_command(state, hdl, in hermon_flash_spi_wait_wip()
2121 status = hermon_flash_read_cfg(state, hdl, in hermon_flash_spi_wait_wip()
2126 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_spi_wait_wip()
2130 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_spi_wait_wip()
2138 hermon_flash_bank(hermon_state_t *state, uint32_t addr) in hermon_flash_bank() argument
2147 hdl = hermon_get_pcihdl(state); in hermon_flash_bank()
2152 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(state->hs_fw_flashbank)) in hermon_flash_bank()
2160 if (state->hs_fw_flashbank != bank || addr == 0) { in hermon_flash_bank()
2161 switch (state->hs_fw_cmdset) { in hermon_flash_bank()
2169 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, in hermon_flash_bank()
2172 hermon_flash_write_cfg(state, hdl, in hermon_flash_bank()
2174 hermon_flash_write_cfg(state, hdl, in hermon_flash_bank()
2178 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, in hermon_flash_bank()
2187 state->hs_fw_flashbank = bank; in hermon_flash_bank()
2192 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_bank()
2200 hermon_flash_spi_exec_command(hermon_state_t *state, ddi_acc_handle_t hdl, in hermon_flash_spi_exec_command() argument
2208 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_GW, cmd); in hermon_flash_spi_exec_command()
2211 data = hermon_flash_read_cfg(state, hdl, in hermon_flash_spi_exec_command()
2222 hermon_flash_read(hermon_state_t *state, uint32_t addr, int *err) in hermon_flash_read() argument
2231 hdl = hermon_get_pcihdl(state); in hermon_flash_read()
2234 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_read()
2237 switch (state->hs_fw_cmdset) { in hermon_flash_read()
2240 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR, in hermon_flash_read()
2243 hermon_flash_spi_exec_command(state, hdl, in hermon_flash_read()
2252 data = hermon_flash_read_cfg(state, hdl, in hermon_flash_read()
2266 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_ADDR, in hermon_flash_read()
2271 data = hermon_flash_read_cfg(state, hdl, in hermon_flash_read()
2281 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_read()
2285 data = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_DATA); in hermon_flash_read()
2291 state->hs_fw_cmdset); in hermon_flash_read()
2298 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_read()
2304 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_read()
2312 hermon_flash_write(hermon_state_t *state, uint32_t addr, uchar_t data, int *err) in hermon_flash_write() argument
2321 hdl = hermon_get_pcihdl(state); in hermon_flash_write()
2324 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_write()
2335 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_DATA, data << 24); in hermon_flash_write()
2336 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_ADDR, in hermon_flash_write()
2341 cmd = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_ADDR); in hermon_flash_write()
2349 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_write()
2354 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_write()
2360 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_write()
2367 hermon_flash_init(hermon_state_t *state) in hermon_flash_init() argument
2378 hdl = hermon_get_pcihdl(state); in hermon_flash_init()
2381 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_init()
2390 word = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_WRCONF_SEMA); in hermon_flash_init()
2400 word = hermon_flash_read_cfg(state, hdl, in hermon_flash_init()
2417 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_init()
2422 state->hs_fw_gpio[0] = hermon_flash_read_cfg(state, hdl, in hermon_flash_init()
2426 gpio = state->hs_fw_gpio[0] | HERMON_HW_FLASH_GPIO_PIN_ENABLE; in hermon_flash_init()
2427 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_DATA, gpio); in hermon_flash_init()
2430 state->hs_fw_gpio[1] = hermon_flash_read_cfg(state, hdl, in hermon_flash_init()
2432 state->hs_fw_gpio[2] = hermon_flash_read_cfg(state, hdl, in hermon_flash_init()
2436 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, in hermon_flash_init()
2442 gpio = state->hs_fw_gpio[1] | HERMON_HW_FLASH_GPIO_PIN_ENABLE; in hermon_flash_init()
2443 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD0, gpio); in hermon_flash_init()
2445 gpio = state->hs_fw_gpio[2] & ~HERMON_HW_FLASH_GPIO_PIN_ENABLE; in hermon_flash_init()
2446 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD1, gpio); in hermon_flash_init()
2449 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, 0); in hermon_flash_init()
2459 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_init()
2463 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_init()
2472 hermon_flash_cfi_init(hermon_state_t *state, uint32_t *cfi_info, in hermon_flash_cfi_init() argument
2483 if (hermon_device_mode(state)) { in hermon_flash_cfi_init()
2488 state->hs_fw_cmdset = HERMON_FLASH_SPI_CMDSET; in hermon_flash_cfi_init()
2489 state->hs_fw_log_sector_sz = HERMON_FLASH_SPI_LOG_SECTOR_SIZE; in hermon_flash_cfi_init()
2490 state->hs_fw_device_sz = HERMON_FLASH_SPI_DEVICE_SIZE; in hermon_flash_cfi_init()
2517 hermon_flash_write(state, 0x55, HERMON_FLASH_CFI_INIT, &status); in hermon_flash_cfi_init()
2523 state->hs_fw_cmdset = HERMON_FLASH_INTEL_CMDSET; in hermon_flash_cfi_init()
2527 data = hermon_flash_read(state, i, &status); in hermon_flash_cfi_init()
2535 state->hs_fw_cmdset = HERMON_FLASH_UNKNOWN_CMDSET; in hermon_flash_cfi_init()
2551 state->hs_fw_cmdset = cfi_ch_info[0x13]; in hermon_flash_cfi_init()
2553 if (state->hs_fw_cmdset != HERMON_FLASH_INTEL_CMDSET && in hermon_flash_cfi_init()
2554 state->hs_fw_cmdset != HERMON_FLASH_AMD_CMDSET) { in hermon_flash_cfi_init()
2557 state->hs_fw_cmdset); in hermon_flash_cfi_init()
2558 state->hs_fw_cmdset = HERMON_FLASH_UNKNOWN_CMDSET; in hermon_flash_cfi_init()
2571 state->hs_fw_log_sector_sz = bit_count; in hermon_flash_cfi_init()
2574 state->hs_fw_device_sz = 0x1 << cfi_ch_info[0x27]; in hermon_flash_cfi_init()
2577 if ((status = hermon_flash_reset(state)) != 0) in hermon_flash_cfi_init()
2598 cfi_ch_info[0x13] = state->hs_fw_cmdset; in hermon_flash_cfi_init()
2608 hermon_flash_fini(hermon_state_t *state) in hermon_flash_fini() argument
2617 hdl = hermon_get_pcihdl(state); in hermon_flash_fini()
2619 if ((status = hermon_flash_bank(state, 0)) != 0) in hermon_flash_fini()
2623 hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status, in hermon_flash_fini()
2629 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_DATA, in hermon_flash_fini()
2630 state->hs_fw_gpio[0]); in hermon_flash_fini()
2633 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, in hermon_flash_fini()
2636 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD0, in hermon_flash_fini()
2637 state->hs_fw_gpio[1]); in hermon_flash_fini()
2638 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD1, in hermon_flash_fini()
2639 state->hs_fw_gpio[2]); in hermon_flash_fini()
2642 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, 0); in hermon_flash_fini()
2645 hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_SEMA, 0); in hermon_flash_fini()
2648 hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test); in hermon_flash_fini()
2652 hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL); in hermon_flash_fini()
2660 hermon_flash_read_cfg(hermon_state_t *state, ddi_acc_handle_t pci_config_hdl, in hermon_flash_read_cfg() argument
2666 read = ddi_get32(hermon_get_cmdhdl(state), (uint32_t *)(void *) in hermon_flash_read_cfg()
2667 (state->hs_reg_cmd_baseaddr + addr)); in hermon_flash_read_cfg()
2687 hermon_flash_write_cfg(hermon_state_t *state, in hermon_flash_write_cfg() argument
2690 hermon_flash_write_cfg_helper(state, pci_config_hdl, addr, data); in hermon_flash_write_cfg()
2691 hermon_flash_write_confirm(state, pci_config_hdl); in hermon_flash_write_cfg()
2695 hermon_flash_write_confirm(hermon_state_t *state, in hermon_flash_write_confirm() argument
2700 hermon_flash_write_cfg_helper(state, pci_config_hdl, in hermon_flash_write_confirm()
2703 sem_value = hermon_flash_read_cfg(state, pci_config_hdl, in hermon_flash_write_confirm()
2714 hermon_flash_write_cfg_helper(hermon_state_t *state, in hermon_flash_write_cfg_helper() argument
2717 hermon_flash_write_cfg(hermon_state_t *state, in hermon_flash_write_cfg_helper()
2722 ddi_put32(hermon_get_cmdhdl(state), (uint32_t *)(void *) in hermon_flash_write_cfg_helper()
2723 (state->hs_reg_cmd_baseaddr + addr), data); in hermon_flash_write_cfg_helper()
2834 hermon_loopback_init(hermon_state_t *state, hermon_loopback_state_t *lstate) in hermon_loopback_init() argument
2838 lstate->hls_hca_hdl = (ibc_hca_hdl_t)state; in hermon_loopback_init()