9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The contents of this file are subject to the terms of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Common Development and Distribution License (the "License").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You may not use this file except in compliance with the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
13cc0a0b8d667c14344b4ff49cc47350cd9ef182Bill Taylor * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Hemron IOCTL Routines
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Implements all ioctl access into the driver. This includes all routines
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * necessary for updating firmware, accessing the hermon flash device, and
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * providing interfaces for VTS.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Hemron HCA state pointer (extern) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The ioctl declarations (for firmware flash burning, register read/write
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * (DEBUG-only), and VTS interfaces)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_read(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_write(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_erase(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_init(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_fini(hermon_state_t *state, dev_t dev);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_cleanup(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_flash_cleanup_nolock(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_reg_write(hermon_state_t *state, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_reg_read(hermon_state_t *state, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* DEBUG */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_write_boot_addr(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_info(hermon_state_t *state, dev_t dev,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_ports(hermon_state_t *state, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_ioctl_loopback(hermon_state_t *state, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Hemron Flash Functions */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_spi_exec_command(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_read_sector(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_read_quadlet(hermon_state_t *state, uint32_t *data,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_write_sector(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_spi_write_dword(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_write_byte(hermon_state_t *state, uint32_t addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_erase_sector(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_erase_chip(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_bank(hermon_state_t *state, uint32_t addr);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic uint32_t hermon_flash_read(hermon_state_t *state, uint32_t addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_write(hermon_state_t *state, uint32_t addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_spi_wait_wip(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_spi_write_enable(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_init(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_cfi_init(hermon_state_t *state, uint32_t *cfi_info,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_fini(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_flash_reset(hermon_state_t *state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic uint32_t hermon_flash_read_cfg(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_write_cfg(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr, uint32_t data);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_write_cfg_helper(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr, uint32_t data);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_write_confirm(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_cfi_byte(uint8_t *ch, uint32_t dword, int i);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_flash_cfi_dword(uint32_t *dword, uint8_t *ch, int i);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Hemron loopback test functions */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_loopback_free_qps(hermon_loopback_state_t *lstate);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_loopback_free_state(hermon_loopback_state_t *lstate);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_init(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void hermon_loopback_init_qp_info(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_alloc_mem(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_alloc_qps(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_modify_qp(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_copyout(hermon_loopback_ioctl_t *lb,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_post_send(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_loopback_comm_t *tx, hermon_loopback_comm_t *rx);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic int hermon_loopback_poll_cq(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* Patchable timeout values for flash operations */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_hw_flash_timeout_gpio_sema = HERMON_HW_FLASH_TIMEOUT_GPIO_SEMA;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_hw_flash_timeout_config = HERMON_HW_FLASH_TIMEOUT_CONFIG;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_hw_flash_timeout_write = HERMON_HW_FLASH_TIMEOUT_WRITE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorint hermon_hw_flash_timeout_erase = HERMON_HW_FLASH_TIMEOUT_ERASE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor/* ARGSUSED */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state = ddi_get_soft_state(hermon_statep, instance);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_flash_read(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_flash_write(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_flash_erase(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_flash_init(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_info(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_loopback(state, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_reg_write(state, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_reg_read(state, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* DEBUG */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* XXX guard until the ioctl header is cleaned up */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_write_boot_addr(state, dev, arg, mode);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_read()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_read(hermon_state_t *state, dev_t dev, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check that flash init ioctl has been called first. And check
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that the same dev_t that called init is the one calling read now.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector = (caddr_t)(uintptr_t)info32.af_sector;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector_num = info32.af_sector_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)arg, &ioctl_info, sizeof (hermon_flash_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine type of READ ioctl
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Check if sector num is too large for flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform the Sector Read */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_reset(state)) != 0 ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copyout the firmware sector image data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &ioctl_info.af_sector[0], 1 << state->hs_fw_log_sector_sz,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Check if addr is too large for flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ioctl_info.af_addr >= state->hs_fw_device_sz) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform the Quadlet Read */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_reset(state)) != 0 ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &ioctl_info.af_quadlet, ioctl_info.af_addr)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy results back to userland */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info32.af_sector_num = ioctl_info.af_sector_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info32.af_sector = (caddr32_t)(uintptr_t)ioctl_info.af_sector;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_write()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_write(hermon_state_t *state, dev_t dev, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check that flash init ioctl has been called first. And check
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that the same dev_t that called init is the one calling write now.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector = (caddr_t)(uintptr_t)info32.af_sector;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector_num = info32.af_sector_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine type of WRITE ioctl
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Check if sector num is too large for flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy in fw sector image data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &state->hs_fw_sector[0], 1 << state->hs_fw_log_sector_sz,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform Write Sector */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Check if addr is too large for flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ioctl_info.af_addr >= state->hs_fw_device_sz) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform Write Byte */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CMJ -- is a reset really needed before and after writing
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * each byte? This code came from arbel, but we should look
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * into this. Also, for SPI, no reset is actually performed.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_addr, ioctl_info.af_byte)) != 0 ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_erase()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_erase(hermon_state_t *state, dev_t dev, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check that flash init ioctl has been called first. And check
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that the same dev_t that called init is the one calling erase now.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector_num = info32.af_sector_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)arg, &ioctl_info, sizeof (hermon_flash_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine type of ERASE ioctl
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Check if sector num is too large for flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (state->hs_fw_device_sz >> state->hs_fw_log_sector_sz)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform Sector Erase */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Perform Chip Erase */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_init()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_init(hermon_state_t *state, dev_t dev, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_hdl = hermon_get_pcihdl(state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * init cannot be called more than once. If we have already init'd the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * flash, return directly.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copyin the user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sizeof (hermon_flash_init_ioctl_t), mode) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Init Flash */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read CFI info */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((ret = hermon_flash_cfi_init(state, &init_info.af_cfi_info[0],
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Return error if the command set is unknown.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_fw_cmdset == HERMON_FLASH_UNKNOWN_CMDSET) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read HWREV - least significant 8 bits is revision ID */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, pci_hdl, pio_error, fm_loop_cnt,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Fill in the firmwate revision numbers */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor init_info.af_fwrev.afi_maj = state->hs_fw.fw_rev_major;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor init_info.af_fwrev.afi_min = state->hs_fw.fw_rev_minor;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor init_info.af_fwrev.afi_sub = state->hs_fw.fw_rev_subminor;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Alloc flash mem for one sector size */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_sector = (uint32_t *)kmem_zalloc(1 <<
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set HW part number and length */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (void) memcpy(init_info.af_hwpn, state->hs_hca_pn,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy ioctl results back to userland */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sizeof (hermon_flash_init_ioctl_t), mode) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set flash state to started */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If "flash init" is successful, add an "on close" callback to the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * current dev node to ensure that "flash fini" gets called later
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * even if the userland process prematurely exits.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (int (*)(void *))hermon_ioctl_flash_cleanup, state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor int status = hermon_ioctl_flash_fini(state, dev);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_fini()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_fini(hermon_state_t *state, dev_t dev)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check that flash init ioctl has been called first. And check
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that the same dev_t that called init is the one calling fini now.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((ret = hermon_ioctl_flash_cleanup_nolock(state)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If "flash fini" is successful, remove the "on close" callback
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that was setup during "flash init".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_cleanup()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_cleanup(hermon_state_t *state)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_ioctl_flash_cleanup_nolock(state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_cleanup_nolock()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_flash_cleanup_nolock(hermon_state_t *state)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* free flash mem */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(state->hs_fw_sector, 1 << state->hs_fw_log_sector_sz);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Fini the Flash */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set flash state to fini */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_info()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_info(hermon_state_t *state, dev_t dev, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Access to Hemron VTS ioctls is not allowed in "maintenance mode".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copyin the user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)arg, &info, sizeof (hermon_info_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check ioctl revision
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (info.ai_revision != HERMON_VTS_IOCTL_REVISION) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If the 'fw_device_sz' has not been initialized yet, we initialize it
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * here. This is done by leveraging the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_flash_init()/fini() calls. We also hold our own mutex
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * around this operation in case we have multiple VTS threads in
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * process at the same time.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_ioctl_flash_init(state, dev, (intptr_t)&init_info,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info.ai_fw_rev.afi_maj = state->hs_fw.fw_rev_major;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info.ai_fw_rev.afi_min = state->hs_fw.fw_rev_minor;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info.ai_fw_rev.afi_sub = state->hs_fw.fw_rev_subminor;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy ioctl results back to user struct */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyout(&info, (void *)arg, sizeof (hermon_info_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_ports()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_ports(hermon_state_t *state, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Access to Hemron VTS ioctls is not allowed in "maintenance mode".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copyin the user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (hermon_stat_port_ioctl_t *)(uintptr_t)info32.ap_ports;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)arg, &info, sizeof (hermon_ports_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check ioctl revision
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (info.ap_revision != HERMON_VTS_IOCTL_REVISION) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate space for temporary GID table/PKey table */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sgid_tbl = (ib_gid_t *)kmem_zalloc(tbl_size * sizeof (ib_gid_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor pkey_tbl = (ib_pkey_t *)kmem_zalloc(tbl_size * sizeof (ib_pkey_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*sgid_tbl, *pkey_tbl))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Setup the number of ports, then loop through all ports and
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * query properties of each.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info.ap_num_ports = (uint8_t)state->hs_cfg_profile->cp_num_ports;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Get portstate information from the device. If
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_port_query() fails, leave zeroes in user
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * struct port entry and continue.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copy queried port results back to user struct. If
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * this fails, then break out of loop, attempt to copy
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * out remaining info to user struct, and return (without
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &(((hermon_stat_port_ioctl_t *)info.ap_ports)[i]),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sizeof (hermon_stat_port_ioctl_t), mode) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Free the temporary space used for GID table/PKey table */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(sgid_tbl, tbl_size * sizeof (ib_gid_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(pkey_tbl, tbl_size * sizeof (ib_pkey_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy ioctl results back to user struct */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor info32.ap_ports = (caddr32_t)(uintptr_t)info.ap_ports;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyout(&info, (void *)arg, sizeof (hermon_ports_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_loopback()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_loopback(hermon_state_t *state, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Access to Hemron VTS ioctls is not allowed in "maintenance mode".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copyin the user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sizeof (hermon_loopback_ioctl32_t), mode) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_send_buf = (caddr_t)(uintptr_t)lb32.alb_send_buf;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_fail_buf = (caddr_t)(uintptr_t)lb32.alb_fail_buf;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)arg, &lb, sizeof (hermon_loopback_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Initialize the internal loopback test state structure */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(&lstate, sizeof (hermon_loopback_state_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check ioctl revision
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (lb.alb_revision != HERMON_VTS_IOCTL_REVISION) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_INVALID_REVISION;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Validate that specified port number is legal */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (!hermon_portnum_is_valid(state, lb.alb_port_num)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_INVALID_PORT;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate space for temporary GID table/PKey table */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sgid_tbl = (ib_gid_t *)kmem_zalloc(tbl_size * sizeof (ib_gid_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor pkey_tbl = (ib_pkey_t *)kmem_zalloc(tbl_size * sizeof (ib_pkey_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Get portstate information from specific port on device
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_port_query(state, lb.alb_port_num, &pi) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Free the temporary space used for GID table/PKey table */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(sgid_tbl, tbl_size * sizeof (ib_gid_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(pkey_tbl, tbl_size * sizeof (ib_pkey_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_INVALID_PORT;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate.hls_pkey_ix = (pi.p_linkstate == HERMON_PORT_LINK_ACTIVE) ?
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor 1 : 0; /* XXX bogus assumption of a SUN subnet manager */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Free the temporary space used for GID table/PKey table */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_gidtbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(sgid_tbl, tbl_size * sizeof (ib_gid_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tbl_size = (1 << state->hs_cfg_profile->cp_log_max_pkeytbl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(pkey_tbl, tbl_size * sizeof (ib_pkey_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Compute the timeout duration in usec per the formula:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * to_usec_per_retry = 4.096us * (2 ^ supplied_timeout)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * (plus we add a little fudge-factor here too)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor max_usec = (4096 * (1 << lstate.hls_timeout)) / 1000;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine how many times we should loop before declaring a
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * timeout failure.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor loopmax = max_usec/HERMON_VTS_LOOPBACK_MIN_WAIT_DUR;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((max_usec % HERMON_VTS_LOOPBACK_MIN_WAIT_DUR) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (lb.alb_send_buf == NULL || lb.alb_buf_sz == 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_SEND_BUF_INVALID;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate protection domain (PD) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_init(state, &lstate) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate and register a TX buffer */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_alloc_mem(&lstate, &lstate.hls_tx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate and register an RX buffer */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_alloc_mem(&lstate, &lstate.hls_rx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy in the transmit buffer data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyin((void *)lb.alb_send_buf, lstate.hls_tx.hlc_buf,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_SEND_BUF_COPY_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate the transmit QP and CQs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate.hls_err = HERMON_LOOPBACK_XMIT_SEND_CQ_ALLOC_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_alloc_qps(&lstate, &lstate.hls_tx) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate the receive QP and CQs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate.hls_err = HERMON_LOOPBACK_RECV_SEND_CQ_ALLOC_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_alloc_qps(&lstate, &lstate.hls_rx) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Activate the TX QP (connect to RX QP) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate.hls_err = HERMON_LOOPBACK_XMIT_QP_INIT_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_modify_qp(&lstate, &lstate.hls_tx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Activate the RX QP (connect to TX QP) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate.hls_err = HERMON_LOOPBACK_RECV_QP_INIT_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_modify_qp(&lstate, &lstate.hls_rx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Run the loopback test (for specified number of iterations) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (iter = 0; iter < lb.alb_num_iter; iter++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Post RDMA Write work request */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (hermon_loopback_post_send(&lstate, &lstate.hls_tx,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lb.alb_error_type = HERMON_LOOPBACK_WQE_POST_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Poll the TX CQ for a completion every few ticks */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (j = 0; j < loopmax; j++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor delay(drv_usectohz(HERMON_VTS_LOOPBACK_MIN_WAIT_DUR));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ret = hermon_loopback_poll_cq(&lstate, &lstate.hls_tx);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (((ret != IBT_SUCCESS) && (ret != IBT_CQ_EMPTY)) ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((ret == IBT_CQ_EMPTY) && (j == loopmax - 1))) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Compare the data buffers */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (bcmp(lstate.hls_tx.hlc_buf, lstate.hls_rx.hlc_buf,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy ioctl results back to user struct */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Free up everything and release all consumed resources */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_reg_read()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_reg_read(hermon_state_t *state, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Access to Hemron registers is not allowed in "maintenance mode".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This is primarily because the device may not have BARs to access
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy in the hermon_reg_ioctl_t structure */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = ddi_copyin((void *)arg, &rdreg, sizeof (hermon_reg_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine base address for requested register set */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor baseaddr = (uintptr_t)state->hs_reg_cmd_baseaddr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor baseaddr = (uintptr_t)state->hs_reg_uar_baseaddr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Ensure that address is properly-aligned */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor addr = (uint32_t *)((baseaddr + rdreg.arg_offset) & ~0x3);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, handle, pio_error, fm_loop_cnt,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read the register pointed to by addr */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, handle, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy in the result into the hermon_reg_ioctl_t structure */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = ddi_copyout(&rdreg, (void *)arg, sizeof (hermon_reg_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_ioctl_reg_write()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_reg_write(hermon_state_t *state, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Access to Hermon registers is not allowed in "maintenance mode".
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * This is primarily because the device may not have BARs to access
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_operational_mode == HERMON_MAINTENANCE_MODE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Copy in the hermon_reg_ioctl_t structure */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = ddi_copyin((void *)arg, &wrreg, sizeof (hermon_reg_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine base address for requested register set */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor baseaddr = (uintptr_t)state->hs_reg_cmd_baseaddr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor baseaddr = (uintptr_t)state->hs_reg_uar_baseaddr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Ensure that address is properly-aligned */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor addr = (uint32_t *)((baseaddr + wrreg.arg_offset) & ~0x3);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, handle, pio_error, fm_loop_cnt,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Write the data to the register pointed to by addr */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, handle, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* DEBUG */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_ioctl_write_boot_addr(hermon_state_t *state, dev_t dev, intptr_t arg,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Check that flash init ioctl has been called first. And check
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * that the same dev_t that called init is the one calling write now.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* copy user struct to kernel */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector = (caddr_t)(uintptr_t)info32.af_sector;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ioctl_info.af_sector_num = info32.af_sector_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_hdl = hermon_get_pcihdl(state);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_reset()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Performs a reset to the flash device. After a reset the flash will
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * be operating in normal mode (capable of read/write, etc.).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, 0x555, HERMON_HW_FLASH_RESET_AMD,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, 0x555, HERMON_HW_FLASH_RESET_INTEL,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* It appears no reset is needed for SPI */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_read_sector()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_read_sector(hermon_state_t *state, uint32_t sector_num)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Calculate the start and end address of the sector, based on the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * sector number passed in.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor addr = sector_num << state->hs_fw_log_sector_sz;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor end_addr = addr + (1 << state->hs_fw_log_sector_sz);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the flash bank correctly for the given address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_bank(state, addr)) != 0)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read the entire sector, one quadlet at a time */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor image[i] = hermon_flash_read(state, addr, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_read_quadlet()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_read_quadlet(hermon_state_t *state, uint32_t *data,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the flash bank correctly for the given address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_bank(state, addr)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read one quadlet of data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *data = hermon_flash_read(state, addr, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_write_sector()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_write_sector(hermon_state_t *state, uint32_t sector_num)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Calculate the start and end address of the sector, based on the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * sector number passed in.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor addr = sector_num << state->hs_fw_log_sector_sz;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor end_addr = addr + (1 << state->hs_fw_log_sector_sz);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the flash bank correctly for the given address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_bank(state, addr)) != 0 ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Erase the sector before writing */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_flash_erase_sector(state, sector_num);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Write the sector, one dword at a time */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_spi_write_dword(state, addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Write the sector, one byte at a time */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_spi_write_dword()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * NOTE: This function assumes that "data" is in network byte order.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_spi_write_dword(hermon_state_t *state, uint32_t addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Write Enable */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the Address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the Data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_DATA, data);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the Page Program and execute */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for write to complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_spi_wait_wip(state)) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_write_byte()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_write_byte(hermon_state_t *state, uint32_t addr, uchar_t data)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Byte program command */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Write Byte to Complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor stat = hermon_flash_read(state, addr & ~3, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_write_byte: ACS write "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "timeout: addr: 0x%x, data: 0x%x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } while (data != ((stat >> ((3 - (addr & 3)) << 3)) & 0xFF));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Byte program command */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_WRITE,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Write Byte to Complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor stat = hermon_flash_read(state, addr & ~3, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_write_byte: ICS write "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "timeout: addr: %x, data: %x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } while ((stat & HERMON_HW_FLASH_ICS_READY) == 0);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_write_byte: ICS write cmd error: "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "addr: %x, data: %x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Our lowest write granularity on SPI is a dword.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * To support this ioctl option, we can read in the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dword that contains this byte, modify this byte,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and write the dword back out.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine dword offset and byte offset within the dword */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read in dword */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_read_quadlet(state, &dword.dword,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set "data" to the appopriate byte */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Write modified dword back out */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = hermon_flash_spi_write_dword(state, dword_addr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_write_byte: unknown cmd set: 0x%x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_erase_sector()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_erase_sector(hermon_state_t *state, uint32_t sector_num)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Get address from sector num */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor addr = sector_num << state->hs_fw_log_sector_sz;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Sector Erase Command */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Sector Erase to complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_sector: "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "ACS erase timeout\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Sector Erase Command */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_ERASE,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, addr, HERMON_HW_FLASH_ICS_CONFIRM,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Sector Erase to complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor stat = hermon_flash_read(state, addr & ~3, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_sector: "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "ICS erase timeout\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } while ((stat & HERMON_HW_FLASH_ICS_READY) == 0);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_sector: "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "ICS erase cmd error\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Write Enable */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the Address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Sector Erase */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ((uint32_t)(HERMON_HW_FLASH_SPI_SECTOR_ERASE) <<
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Sector Erase to complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_sector: unknown cmd set: 0x%x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Reset the flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_erase_chip()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Issue Flash Chip Erase Command */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Wait for Chip Erase to Complete */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_chip: erase timeout\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * These chips don't have a chip erase command, so erase
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * all blocks one at a time.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (i = 0; i < num_sect; i++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_erase_chip: "
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "sector %d erase error\n", i);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "unknown cmd set: 0x%x\n", state->hs_fw_cmdset);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_spi_write_enable()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_spi_write_enable(hermon_state_t *state)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_spi_wait_wip()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* wait on the gateway to clear busy */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* now, get the status and check for WIP to clear */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_bank()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_bank(hermon_state_t *state, uint32_t addr)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set handle */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine the bank setting from the address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(state->hs_fw_flashbank))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If the bank is different from the currently set bank, we need to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * change it. Also, if an 'addr' of 0 is given, this allows the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * capability to force the flash bank to 0. This is useful at init
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * time to initially set the bank value
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_fw_flashbank != bank || addr == 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* CMJ: not needed for hermon */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor HERMON_HW_FLASH_GPIO_DATASET, (bank >> 15) & 0x70);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_spi_exec_command()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_spi_exec_command(hermon_state_t *state, ddi_acc_handle_t hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmd |= HERMON_HW_FLASH_SPI_BUSY | HERMON_HW_FLASH_SPI_ENABLE_OFF;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_GW, cmd);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_read()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_read(hermon_state_t *state, uint32_t addr, int *err)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set the transaction address */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_SPI_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The Read operation does the following:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 1) Write the masked address to the HERMON_FLASH_ADDR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * register. Only the least significant 19 bits are valid.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 2) Read back the register until the command has completed.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 3) Read the data retrieved from the address at the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * HERMON_FLASH_DATA register.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (addr & HERMON_HW_FLASH_ADDR_MASK) | (1 << 29));
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath if (timeout == hermon_hw_flash_timeout_config) {
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath cmn_err(CE_WARN, "hermon_flash_read: command timed "
261906274d77b4a1c6d61c75d170ab5a8e85a6a7Shantkumar Hiremath hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor data = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_DATA);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmn_err(CE_CONT, "hermon_flash_read: unknown cmdset: 0x%x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_write()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_write(hermon_state_t *state, uint32_t addr, uchar_t data, int *err)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The Write operation does the following:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 1) Write the data to be written to the HERMON_FLASH_DATA offset.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 2) Write the address to write the data to to the HERMON_FLASH_ADDR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 3) Wait until the write completes.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_DATA, data << 24);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmd = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_ADDR);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (timeout == hermon_hw_flash_timeout_config) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmn_err(CE_WARN, "hermon_flash_write: config cmd timeout.\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_init()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set handle */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Init the flash */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Grab the WRCONF semaphore.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor word = hermon_flash_read_cfg(state, hdl, HERMON_HW_FLASH_WRCONF_SEMA);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Grab the GPIO semaphore. This allows us exclusive access to the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * GPIO settings on the Hermon for the duration of the flash burning
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * procedure.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } while (sema_cnt < hermon_hw_flash_timeout_gpio_sema);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine if we timed out trying to grab the GPIO semaphore
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (sema_cnt == hermon_hw_flash_timeout_gpio_sema) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmn_err(CE_WARN, "hermon_flash_init: GPIO SEMA timeout\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cmn_err(CE_WARN, "GPIO_SEMA value: 0x%x\n", word);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Save away original GPIO Values */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_gpio[0] = hermon_flash_read_cfg(state, hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set new GPIO value */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor gpio = state->hs_fw_gpio[0] | HERMON_HW_FLASH_GPIO_PIN_ENABLE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_DATA, gpio);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Save away original GPIO Values */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_gpio[1] = hermon_flash_read_cfg(state, hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_gpio[2] = hermon_flash_read_cfg(state, hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* unlock GPIO */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Set new GPIO values
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor gpio = state->hs_fw_gpio[1] | HERMON_HW_FLASH_GPIO_PIN_ENABLE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD0, gpio);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor gpio = state->hs_fw_gpio[2] & ~HERMON_HW_FLASH_GPIO_PIN_ENABLE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD1, gpio);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* re-lock GPIO */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, 0);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set CPUMODE to enable hermon to access the flash device */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* CMJ This code came from arbel. Hermon doesn't seem to need it. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_CPUMODE,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 1 << HERMON_HW_FLASH_CPU_SHIFT);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_cfi_init
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Implements access to the CFI (Common Flash Interface) data
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_cfi_init(hermon_state_t *state, uint32_t *cfi_info,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Right now, all hermon cards use SPI. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Don't use CFI for SPI part. Just fill in what we need
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and return.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_log_sector_sz = HERMON_FLASH_SPI_LOG_SECTOR_SIZE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_device_sz = HERMON_FLASH_SPI_DEVICE_SIZE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * set this to inform caller of cmdset type.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_cfi_dword(&cfi_info[4], cfi_ch_info, 0x10);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Determine if the user command supports the Intel Extended
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Command Set. The query string is contained in the fourth
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * quad word.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_cfi_byte(cfi_ch_info, cfi_info[0x04], 0x10);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "Support for Intel X is present\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* CFI QUERY */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write(state, 0x55, HERMON_FLASH_CFI_INIT, &status);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* temporarily set the cmdset in order to do the initial read */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_cmdset = HERMON_FLASH_INTEL_CMDSET;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Read in CFI data */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine chip set */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_cmdset = HERMON_FLASH_UNKNOWN_CMDSET;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Mode: x16 working in x8 mode (Intel).
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Pack data - skip spacing bytes.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "x16 working in x8 mode (Intel)\n");
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (state->hs_fw_cmdset != HERMON_FLASH_INTEL_CMDSET &&
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_cmdset != HERMON_FLASH_AMD_CMDSET) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "hermon_flash_cfi_init: UNKNOWN chip cmd set 0x%04x\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_cmdset = HERMON_FLASH_UNKNOWN_CMDSET;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Determine total bytes in one sector size */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sector_sz_bytes = ((cfi_ch_info[0x30] << 8) | cfi_ch_info[0x2F]) << 8;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Calculate equivalent of log2 (n) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (bit_count = 0; sector_sz_bytes > 1; bit_count++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set sector size */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set flash size */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor state->hs_fw_device_sz = 0x1 << cfi_ch_info[0x27];
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Reset to turn off CFI mode */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Pass CFI data back to user command. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (i = 0; i < HERMON_FLASH_CFI_SIZE_QUADLET; i++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_cfi_dword(&cfi_info[i], cfi_ch_info, i << 2);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Inform the user cmd that this driver does support the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Intel Extended Command Set.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_cfi_dword(&cfi_info[0x4], cfi_ch_info, 0x10);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_fini()
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* initialize the FMA retry loop */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_init(fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Set handle */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((status = hermon_flash_bank(state, 0)) != 0)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop starts. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_start(state, hdl, pio_error, fm_loop_cnt, fm_status,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Restore original GPIO Values
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_DATA,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* unlock GPIOs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD0,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_MOD1,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* re-lock GPIOs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_LOCK, 0);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Give up gpio semaphore */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg(state, hdl, HERMON_HW_FLASH_GPIO_SEMA, 0);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* the FMA retry loop ends. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_pio_end(state, hdl, pio_error, fm_loop_cnt, fm_status, fm_test);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_fm_ereport(state, HCA_SYS_ERR, HCA_ERR_IOCTL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_read_cfg
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_read_cfg(hermon_state_t *state, ddi_acc_handle_t pci_config_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor read = ddi_get32(hermon_get_cmdhdl(state), (uint32_t *)(void *)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Perform flash read operation:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 1) Place addr to read from on the HERMON_HW_FLASH_CFG_ADDR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 2) Read data at that addr from the HERMON_HW_FLASH_CFG_DATA
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor pci_config_put32(pci_config_hdl, HERMON_HW_FLASH_CFG_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr, uint32_t data)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg_helper(state, pci_config_hdl, addr, data);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_confirm(state, pci_config_hdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_write_confirm(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_flash_write_cfg_helper(state, pci_config_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sem_value = hermon_flash_read_cfg(state, pci_config_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_flash_write_cfg
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_write_cfg_helper(hermon_state_t *state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr, uint32_t data)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_acc_handle_t pci_config_hdl, uint32_t addr, uint32_t data)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ddi_put32(hermon_get_cmdhdl(state), (uint32_t *)(void *)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Perform flash write operation:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 1) Place addr to write to on the HERMON_HW_FLASH_CFG_ADDR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * 2) Place data to write on to the HERMON_HW_FLASH_CFG_DATA
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor pci_config_put32(pci_config_hdl, HERMON_HW_FLASH_CFG_ADDR,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor pci_config_put32(pci_config_hdl, HERMON_HW_FLASH_CFG_DATA,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Support routines to convert Common Flash Interface (CFI) data
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * from a 32 bit word to a char array, and from a char array to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a 32 bit word.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_cfi_byte(uint8_t *ch, uint32_t dword, int i)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ch[i+1] = (uint8_t)((dword & 0x00FF0000) >> 16);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_flash_cfi_dword(uint32_t *dword, uint8_t *ch, int i)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_free_qps
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_free_qps(hermon_loopback_state_t *lstate)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &lstate->hls_tx.hlc_qp_hdl, IBC_FREE_QP_AND_QPN, NULL,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor &lstate->hls_rx.hlc_qp_hdl, IBC_FREE_QP_AND_QPN, NULL,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (i = 0; i < 2; i++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_free_state
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_free_state(hermon_loopback_state_t *lstate)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (void) hermon_pd_free(lstate->hls_state, &lstate->hls_pd_hdl);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(lstate->hls_tx.hlc_buf, lstate->hls_tx.hlc_buf_sz);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor kmem_free(lstate->hls_rx.hlc_buf, lstate->hls_rx.hlc_buf_sz);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(lstate, sizeof (hermon_loopback_state_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_init
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_init(hermon_state_t *state, hermon_loopback_state_t *lstate)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate->hls_status = hermon_pd_alloc(lstate->hls_state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate->hls_err = HERMON_LOOPBACK_PROT_DOMAIN_ALLOC_FAIL;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_init_qp_info
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_init_qp_info(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(&comm->hlc_cq_attr, sizeof (ibt_cq_attr_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(&comm->hlc_qp_attr, sizeof (ibt_qp_alloc_attr_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(&comm->hlc_qp_info, sizeof (ibt_qp_info_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_flags = IBT_CEP_RDMA_RD | IBT_CEP_RDMA_WR;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_hca_port_num =
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_pkey_ix =
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_timeout =
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_srvl = 0;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_srate =
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_send_grh = 0;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dlid =
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_retry_cnt = lstate->hls_retry;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_sq_psn = 0;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_rq_psn = 0;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_rdma_ra_in = 4;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_rdma_ra_out = 4;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_dst_qpn = 0;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_min_rnr_nak = IBT_RNR_NAK_655ms;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path_mtu = IB_MTU_1K;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_alloc_mem
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_alloc_mem(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate buffer of specified size */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Register the buffer as a memory region */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_memattr.mr_vaddr = (uint64_t)(uintptr_t)comm->hlc_buf;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor IBT_MR_ENABLE_REMOTE_WRITE | IBT_MR_ENABLE_LOCAL_WRITE;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_mr_register(lstate->hls_state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor lstate->hls_pd_hdl, &comm->hlc_memattr, &comm->hlc_mrhdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*comm->hlc_mrhdl))
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_mrdesc.md_vaddr = comm->hlc_mrhdl->mr_bindinfo.bi_addr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_mrdesc.md_lkey = comm->hlc_mrhdl->mr_lkey;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_mrdesc.md_rkey = comm->hlc_mrhdl->mr_rkey;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_alloc_qps
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_alloc_qps(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate send and recv CQs */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor for (i = 0; i < 2; i++) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor bzero(&comm->hlc_cq_attr, sizeof (ibt_cq_attr_t));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_cq_alloc(lstate->hls_state,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (ibt_cq_hdl_t)NULL, &comm->hlc_cq_attr, &real_size,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Allocate the QP */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_attr.qp_pd_hdl = (ibt_pd_hdl_t)lstate->hls_pd_hdl;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_attr.qp_scq_hdl = (ibt_cq_hdl_t)comm->hlc_cqhdl[0];
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_attr.qp_rcq_hdl = (ibt_cq_hdl_t)comm->hlc_cqhdl[1];
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_attr.qp_ibc_scq_hdl = (ibt_opaque1_t)comm->hlc_cqhdl[0];
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_attr.qp_ibc_rcq_hdl = (ibt_opaque1_t)comm->hlc_cqhdl[1];
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_qp_alloc(lstate->hls_state, &qpinfo,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_modify_qp
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_modify_qp(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Modify QP to INIT */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_qp_modify(lstate->hls_state, comm->hlc_qp_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor IBT_CEP_SET_STATE, &comm->hlc_qp_info, &comm->hlc_queue_sizes);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Modify QP to RTR (set destination LID and QP number to local
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * LID and QP number)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_path.cep_adds_vect.av_dlid
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_transport.rc.rc_dst_qpn = qp_num;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_qp_modify(lstate->hls_state, comm->hlc_qp_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor IBT_CEP_SET_STATE, &comm->hlc_qp_info, &comm->hlc_queue_sizes);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Modify QP to RTS */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_qp_info.qp_current_state = IBT_STATE_RTR;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_qp_modify(lstate->hls_state, comm->hlc_qp_hdl,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor IBT_CEP_SET_STATE, &comm->hlc_qp_info, &comm->hlc_queue_sizes);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_copyout
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_copyout(hermon_loopback_ioctl_t *lb, intptr_t arg, int mode)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor sizeof (hermon_loopback_ioctl32_t), mode) != 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#endif /* _MULTI_DATAMODEL */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ddi_copyout(lb, (void *)arg, sizeof (hermon_loopback_ioctl_t),
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_post_send
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_post_send(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hermon_loopback_comm_t *tx, hermon_loopback_comm_t *rx)
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Initialize local address for TX buffer */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Initialize the remaining details of the work request */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Initialize the remote address for RX buffer */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tx->hlc_wr.wr.rc.rcwr.rdma.rdma_raddr = rx->hlc_mrdesc.md_vaddr;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor tx->hlc_wr.wr.rc.rcwr.rdma.rdma_rkey = rx->hlc_mrdesc.md_rkey;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ret = hermon_post_send(lstate->hls_state, tx->hlc_qp_hdl, &tx->hlc_wr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hermon_loopback_poll_cq
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorhermon_loopback_poll_cq(hermon_loopback_state_t *lstate,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor comm->hlc_status = hermon_cq_poll(lstate->hls_state,