Ejemplo n.º 1
0
/**
 *  i40e_asq_send_command - send command to Admin Queue
 *  @hw: pointer to the hw struct
 *  @desc: prefilled descriptor describing the command (non DMA mem)
 *  @buff: buffer to use for indirect commands
 *  @buff_size: size of buffer for indirect commands
 *  @cmd_details: pointer to command details structure
 *
 *  This is the main send command driver routine for the Admin Queue send
 *  queue.  It runs the queue, cleans the queue, etc
 **/
enum i40e_status_code i40e_asq_send_command(struct i40e_hw *hw,
        struct i40e_aq_desc *desc,
        void *buff, /* can be NULL */
        u16  buff_size,
        struct i40e_asq_cmd_details *cmd_details)
{
    enum i40e_status_code status = I40E_SUCCESS;
    struct i40e_dma_mem *dma_buff = NULL;
    struct i40e_asq_cmd_details *details;
    struct i40e_aq_desc *desc_on_ring;
    bool cmd_completed = false;
    u16  retval = 0;
    u32  val = 0;

    val = rd32(hw, hw->aq.asq.head);
    if (val >= hw->aq.num_asq_entries) {
        i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: head overrun at %d\n", val);
        status = I40E_ERR_QUEUE_EMPTY;
        goto asq_send_command_exit;
    }

    if (hw->aq.asq.count == 0) {
        i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: Admin queue not initialized.\n");
        status = I40E_ERR_QUEUE_EMPTY;
        goto asq_send_command_exit;
    }

#ifndef VF_DRIVER
    if (i40e_is_nvm_update_op(desc) && hw->aq.nvm_busy) {
        i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: NVM busy.\n");
        status = I40E_ERR_NVM;
        goto asq_send_command_exit;
    }

#endif
    details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use);
    if (cmd_details) {
        i40e_memcpy(details,
                    cmd_details,
                    sizeof(struct i40e_asq_cmd_details),
                    I40E_NONDMA_TO_NONDMA);

        /* If the cmd_details are defined copy the cookie.  The
         * CPU_TO_LE32 is not needed here because the data is ignored
         * by the FW, only used by the driver
         */
        if (details->cookie) {
            desc->cookie_high =
                CPU_TO_LE32(I40E_HI_DWORD(details->cookie));
            desc->cookie_low =
                CPU_TO_LE32(I40E_LO_DWORD(details->cookie));
        }
    } else {
        i40e_memset(details, 0,
                    sizeof(struct i40e_asq_cmd_details),
                    I40E_NONDMA_MEM);
    }

    /* clear requested flags and then set additional flags if defined */
    desc->flags &= ~CPU_TO_LE16(details->flags_dis);
    desc->flags |= CPU_TO_LE16(details->flags_ena);

    i40e_acquire_spinlock(&hw->aq.asq_spinlock);

    if (buff_size > hw->aq.asq_buf_size) {
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: Invalid buffer size: %d.\n",
                   buff_size);
        status = I40E_ERR_INVALID_SIZE;
        goto asq_send_command_error;
    }

    if (details->postpone && !details->async) {
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: Async flag not set along with postpone flag");
        status = I40E_ERR_PARAM;
        goto asq_send_command_error;
    }

    /* call clean and check queue available function to reclaim the
     * descriptors that were processed by FW, the function returns the
     * number of desc available
     */
    /* the clean function called here could be called in a separate thread
     * in case of asynchronous completions
     */
    if (i40e_clean_asq(hw) == 0) {
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: Error queue is full.\n");
        status = I40E_ERR_ADMIN_QUEUE_FULL;
        goto asq_send_command_error;
    }

    /* initialize the temp desc pointer with the right desc */
    desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use);

    /* if the desc is available copy the temp desc to the right place */
    i40e_memcpy(desc_on_ring, desc, sizeof(struct i40e_aq_desc),
                I40E_NONDMA_TO_DMA);

    /* if buff is not NULL assume indirect command */
    if (buff != NULL) {
        dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]);
        /* copy the user buff into the respective DMA buff */
        i40e_memcpy(dma_buff->va, buff, buff_size,
                    I40E_NONDMA_TO_DMA);
        desc_on_ring->datalen = CPU_TO_LE16(buff_size);

        /* Update the address values in the desc with the pa value
         * for respective buffer
         */
        desc_on_ring->params.external.addr_high =
            CPU_TO_LE32(I40E_HI_DWORD(dma_buff->pa));
        desc_on_ring->params.external.addr_low =
            CPU_TO_LE32(I40E_LO_DWORD(dma_buff->pa));
    }

    /* bump the tail */
    i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: desc and buffer:\n");
    i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring,
                  buff, buff_size);
    (hw->aq.asq.next_to_use)++;
    if (hw->aq.asq.next_to_use == hw->aq.asq.count)
        hw->aq.asq.next_to_use = 0;
    if (!details->postpone)
        wr32(hw, hw->aq.asq.tail, hw->aq.asq.next_to_use);

    /* if cmd_details are not defined or async flag is not set,
     * we need to wait for desc write back
     */
    if (!details->async && !details->postpone) {
        u32 total_delay = 0;

        do {
            /* AQ designers suggest use of head for better
             * timing reliability than DD bit
             */
            if (i40e_asq_done(hw))
                break;
            /* ugh! delay while spin_lock */
            i40e_msec_delay(1);
            total_delay++;
        } while (total_delay < hw->aq.asq_cmd_timeout);
    }

    /* if ready, copy the desc back to temp */
    if (i40e_asq_done(hw)) {
        i40e_memcpy(desc, desc_on_ring, sizeof(struct i40e_aq_desc),
                    I40E_DMA_TO_NONDMA);
        if (buff != NULL)
            i40e_memcpy(buff, dma_buff->va, buff_size,
                        I40E_DMA_TO_NONDMA);
        retval = LE16_TO_CPU(desc->retval);
        if (retval != 0) {
            i40e_debug(hw,
                       I40E_DEBUG_AQ_MESSAGE,
                       "AQTX: Command completed with error 0x%X.\n",
                       retval);

            /* strip off FW internal code */
            retval &= 0xff;
        }
        cmd_completed = true;
        if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_OK)
            status = I40E_SUCCESS;
        else
            status = I40E_ERR_ADMIN_QUEUE_ERROR;
        hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval;
    }

    i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
               "AQTX: desc and buffer writeback:\n");
    i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, buff, buff_size);

    /* update the error if time out occurred */
    if ((!cmd_completed) &&
            (!details->async && !details->postpone)) {
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQTX: Writeback timeout.\n");
        status = I40E_ERR_ADMIN_QUEUE_TIMEOUT;
    }

#ifndef VF_DRIVER
    if (!status && i40e_is_nvm_update_op(desc))
        hw->aq.nvm_busy = true;

#endif /* VF_DRIVER */
asq_send_command_error:
    i40e_release_spinlock(&hw->aq.asq_spinlock);
asq_send_command_exit:
    return status;
}
Ejemplo n.º 2
0
/**
 *  i40e_clean_arq_element
 *  @hw: pointer to the hw struct
 *  @e: event info from the receive descriptor, includes any buffers
 *  @pending: number of events that could be left to process
 *
 *  This function cleans one Admin Receive Queue element and returns
 *  the contents through e.  It can also return how many events are
 *  left to process through 'pending'
 **/
enum i40e_status_code i40e_clean_arq_element(struct i40e_hw *hw,
        struct i40e_arq_event_info *e,
        u16 *pending)
{
    enum i40e_status_code ret_code = I40E_SUCCESS;
    u16 ntc = hw->aq.arq.next_to_clean;
    struct i40e_aq_desc *desc;
    struct i40e_dma_mem *bi;
    u16 desc_idx;
    u16 datalen;
    u16 flags;
    u16 ntu;

    /* take the lock before we start messing with the ring */
    i40e_acquire_spinlock(&hw->aq.arq_spinlock);

    /* set next_to_use to head */
    ntu = (rd32(hw, hw->aq.arq.head) & I40E_PF_ARQH_ARQH_MASK);
    if (ntu == ntc) {
        /* nothing to do - shouldn't need to update ring's values */
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQRX: Queue is empty.\n");
        ret_code = I40E_ERR_ADMIN_QUEUE_NO_WORK;
        goto clean_arq_element_out;
    }

    /* now clean the next descriptor */
    desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
    desc_idx = ntc;

    flags = LE16_TO_CPU(desc->flags);
    if (flags & I40E_AQ_FLAG_ERR) {
        ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
        hw->aq.arq_last_status =
            (enum i40e_admin_queue_err)LE16_TO_CPU(desc->retval);
        i40e_debug(hw,
                   I40E_DEBUG_AQ_MESSAGE,
                   "AQRX: Event received with error 0x%X.\n",
                   hw->aq.arq_last_status);
    }

    i40e_memcpy(&e->desc, desc, sizeof(struct i40e_aq_desc),
                I40E_DMA_TO_NONDMA);
    datalen = LE16_TO_CPU(desc->datalen);
    e->msg_len = min(datalen, e->buf_len);
    if (e->msg_buf != NULL && (e->msg_len != 0))
        i40e_memcpy(e->msg_buf,
                    hw->aq.arq.r.arq_bi[desc_idx].va,
                    e->msg_len, I40E_DMA_TO_NONDMA);

    i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: desc and buffer:\n");
    i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
                  hw->aq.arq_buf_size);

    /* Restore the original datalen and buffer address in the desc,
     * FW updates datalen to indicate the event message
     * size
     */
    bi = &hw->aq.arq.r.arq_bi[ntc];
    i40e_memset((void *)desc, 0, sizeof(struct i40e_aq_desc), I40E_DMA_MEM);

    desc->flags = CPU_TO_LE16(I40E_AQ_FLAG_BUF);
    if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
        desc->flags |= CPU_TO_LE16(I40E_AQ_FLAG_LB);
    desc->datalen = CPU_TO_LE16((u16)bi->size);
    desc->params.external.addr_high = CPU_TO_LE32(I40E_HI_DWORD(bi->pa));
    desc->params.external.addr_low = CPU_TO_LE32(I40E_LO_DWORD(bi->pa));

    /* set tail = the last cleaned desc index. */
    wr32(hw, hw->aq.arq.tail, ntc);
    /* ntc is updated to tail + 1 */
    ntc++;
    if (ntc == hw->aq.num_arq_entries)
        ntc = 0;
    hw->aq.arq.next_to_clean = ntc;
    hw->aq.arq.next_to_use = ntu;

clean_arq_element_out:
    /* Set pending if needed, unlock and return */
    if (pending != NULL)
        *pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc);
    i40e_release_spinlock(&hw->aq.arq_spinlock);

#ifndef VF_DRIVER
    if (i40e_is_nvm_update_op(&e->desc)) {
        hw->aq.nvm_busy = false;
        if (hw->aq.nvm_release_on_done) {
            i40e_release_nvm(hw);
            hw->aq.nvm_release_on_done = false;
        }
    }

#endif
    return ret_code;
}
Ejemplo n.º 3
0
/**
 *  i40e_clean_arq_element
 *  @hw: pointer to the hw struct
 *  @e: event info from the receive descriptor, includes any buffers
 *  @pending: number of events that could be left to process
 *
 *  This function cleans one Admin Receive Queue element and returns
 *  the contents through e.  It can also return how many events are
 *  left to process through 'pending'
 **/
i40e_status i40e_clean_arq_element(struct i40e_hw *hw,
					     struct i40e_arq_event_info *e,
					     u16 *pending)
{
	i40e_status ret_code = 0;
	u16 ntc = hw->aq.arq.next_to_clean;
	struct i40e_aq_desc *desc;
	struct i40e_dma_mem *bi;
	u16 desc_idx;
	u16 datalen;
	u16 flags;
	u16 ntu;

	/* take the lock before we start messing with the ring */
	mutex_lock(&hw->aq.arq_mutex);

	if (hw->aq.arq.count == 0) {
		i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
			   "AQRX: Admin queue not initialized.\n");
		ret_code = I40E_ERR_QUEUE_EMPTY;
		goto clean_arq_element_err;
	}

	/* set next_to_use to head */
	ntu = (rd32(hw, hw->aq.arq.head) & I40E_PF_ARQH_ARQH_MASK);
	if (ntu == ntc) {
		/* nothing to do - shouldn't need to update ring's values */
		ret_code = I40E_ERR_ADMIN_QUEUE_NO_WORK;
		goto clean_arq_element_out;
	}

	/* now clean the next descriptor */
	desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
	desc_idx = ntc;

	flags = le16_to_cpu(desc->flags);
	if (flags & I40E_AQ_FLAG_ERR) {
		ret_code = I40E_ERR_ADMIN_QUEUE_ERROR;
		hw->aq.arq_last_status =
			(enum i40e_admin_queue_err)le16_to_cpu(desc->retval);
		i40e_debug(hw,
			   I40E_DEBUG_AQ_MESSAGE,
			   "AQRX: Event received with error 0x%X.\n",
			   hw->aq.arq_last_status);
	}

	e->desc = *desc;
	datalen = le16_to_cpu(desc->datalen);
	e->msg_len = min(datalen, e->buf_len);
	if (e->msg_buf != NULL && (e->msg_len != 0))
		memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va,
		       e->msg_len);

	i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: desc and buffer:\n");
	i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
		      hw->aq.arq_buf_size);

	/* Restore the original datalen and buffer address in the desc,
	 * FW updates datalen to indicate the event message
	 * size
	 */
	bi = &hw->aq.arq.r.arq_bi[ntc];
	memset((void *)desc, 0, sizeof(struct i40e_aq_desc));

	desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF);
	if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
		desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB);
	desc->datalen = cpu_to_le16((u16)bi->size);
	desc->params.external.addr_high = cpu_to_le32(upper_32_bits(bi->pa));
	desc->params.external.addr_low = cpu_to_le32(lower_32_bits(bi->pa));

	/* set tail = the last cleaned desc index. */
	wr32(hw, hw->aq.arq.tail, ntc);
	/* ntc is updated to tail + 1 */
	ntc++;
	if (ntc == hw->aq.num_arq_entries)
		ntc = 0;
	hw->aq.arq.next_to_clean = ntc;
	hw->aq.arq.next_to_use = ntu;

clean_arq_element_out:
	/* Set pending if needed, unlock and return */
	if (pending != NULL)
		*pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc);

clean_arq_element_err:
	mutex_unlock(&hw->aq.arq_mutex);

	if (i40e_is_nvm_update_op(&e->desc)) {
		if (hw->aq.nvm_release_on_done) {
			i40e_release_nvm(hw);
			hw->aq.nvm_release_on_done = false;
		}

		switch (hw->nvmupd_state) {
		case I40E_NVMUPD_STATE_INIT_WAIT:
			hw->nvmupd_state = I40E_NVMUPD_STATE_INIT;
			break;

		case I40E_NVMUPD_STATE_WRITE_WAIT:
			hw->nvmupd_state = I40E_NVMUPD_STATE_WRITING;
			break;

		default:
			break;
		}
	}

	return ret_code;
}