/* * Broadcom NetXtreme-E RoCE driver. * * Copyright (c) 2016 - 2017, Broadcom. All rights reserved. The term * Broadcom refers to Broadcom Limited and/or its subsidiaries. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * BSD license below: * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Description: RDMA Controller HW interface */ #define dev_fmt(fmt) … #include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/pci.h> #include <linux/prefetch.h> #include <linux/delay.h> #include "roce_hsi.h" #include "qplib_res.h" #include "qplib_rcfw.h" #include "qplib_sp.h" #include "qplib_fp.h" #include "qplib_tlv.h" static void bnxt_qplib_service_creq(struct tasklet_struct *t); /** * bnxt_qplib_map_rc - map return type based on opcode * @opcode: roce slow path opcode * * case #1 * Firmware initiated error recovery is a safe state machine and * driver can consider all the underlying rdma resources are free. * In this state, it is safe to return success for opcodes related to * destroying rdma resources (like destroy qp, destroy cq etc.). * * case #2 * If driver detect potential firmware stall, it is not safe state machine * and the driver can not consider all the underlying rdma resources are * freed. * In this state, it is not safe to return success for opcodes related to * destroying rdma resources (like destroy qp, destroy cq etc.). * * Scope of this helper function is only for case #1. * * Returns: * 0 to communicate success to caller. * Non zero error code to communicate failure to caller. */ static int bnxt_qplib_map_rc(u8 opcode) { … } /** * bnxt_re_is_fw_stalled - Check firmware health * @rcfw: rcfw channel instance of rdev * @cookie: cookie to track the command * * If firmware has not responded any rcfw command within * rcfw->max_timeout, consider firmware as stalled. * * Returns: * 0 if firmware is responding * -ENODEV if firmware is not responding */ static int bnxt_re_is_fw_stalled(struct bnxt_qplib_rcfw *rcfw, u16 cookie) { … } /** * __wait_for_resp - Don't hold the cpu context and wait for response * @rcfw: rcfw channel instance of rdev * @cookie: cookie to track the command * * Wait for command completion in sleepable context. * * Returns: * 0 if command is completed by firmware. * Non zero error code for rest of the case. */ static int __wait_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie) { struct bnxt_qplib_cmdq_ctx *cmdq; struct bnxt_qplib_crsqe *crsqe; int ret; cmdq = &rcfw->cmdq; crsqe = &rcfw->crsqe_tbl[cookie]; do { if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags)) return bnxt_qplib_map_rc(crsqe->opcode); if (test_bit(FIRMWARE_STALL_DETECTED, &cmdq->flags)) return -ETIMEDOUT; wait_event_timeout(cmdq->waitq, !crsqe->is_in_used || test_bit(ERR_DEVICE_DETACHED, &cmdq->flags), msecs_to_jiffies(rcfw->max_timeout * 1000)); if (!crsqe->is_in_used) return 0; bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet); if (!crsqe->is_in_used) return 0; ret = bnxt_re_is_fw_stalled(rcfw, cookie); if (ret) return ret; } while (true); }; /** * __block_for_resp - hold the cpu context and wait for response * @rcfw: rcfw channel instance of rdev * @cookie: cookie to track the command * * This function will hold the cpu (non-sleepable context) and * wait for command completion. Maximum holding interval is 8 second. * * Returns: * -ETIMEOUT if command is not completed in specific time interval. * 0 if command is completed by firmware. */ static int __block_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie) { struct bnxt_qplib_cmdq_ctx *cmdq = &rcfw->cmdq; struct bnxt_qplib_crsqe *crsqe; unsigned long issue_time = 0; issue_time = jiffies; crsqe = &rcfw->crsqe_tbl[cookie]; do { if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags)) return bnxt_qplib_map_rc(crsqe->opcode); if (test_bit(FIRMWARE_STALL_DETECTED, &cmdq->flags)) return -ETIMEDOUT; udelay(1); bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet); if (!crsqe->is_in_used) return 0; } while (time_before(jiffies, issue_time + (8 * HZ))); return -ETIMEDOUT; }; /* __send_message_no_waiter - get cookie and post the message. * @rcfw: rcfw channel instance of rdev * @msg: qplib message internal * * This function will just post and don't bother about completion. * Current design of this function is - * user must hold the completion queue hwq->lock. * user must have used existing completion and free the resources. * this function will not check queue full condition. * this function will explicitly set is_waiter_alive=false. * current use case is - send destroy_ah if create_ah is return * after waiter of create_ah is lost. It can be extended for other * use case as well. * * Returns: Nothing * */ static void __send_message_no_waiter(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_cmdqmsg *msg) { … } static int __send_message(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_cmdqmsg *msg, u8 opcode) { … } /** * __poll_for_resp - self poll completion for rcfw command * @rcfw: rcfw channel instance of rdev * @cookie: cookie to track the command * * It works same as __wait_for_resp except this function will * do self polling in sort interval since interrupt is disabled. * This function can not be called from non-sleepable context. * * Returns: * -ETIMEOUT if command is not completed in specific time interval. * 0 if command is completed by firmware. */ static int __poll_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie) { struct bnxt_qplib_cmdq_ctx *cmdq = &rcfw->cmdq; struct bnxt_qplib_crsqe *crsqe; unsigned long issue_time; int ret; issue_time = jiffies; crsqe = &rcfw->crsqe_tbl[cookie]; do { if (test_bit(ERR_DEVICE_DETACHED, &cmdq->flags)) return bnxt_qplib_map_rc(crsqe->opcode); if (test_bit(FIRMWARE_STALL_DETECTED, &cmdq->flags)) return -ETIMEDOUT; usleep_range(1000, 1001); bnxt_qplib_service_creq(&rcfw->creq.creq_tasklet); if (!crsqe->is_in_used) return 0; if (jiffies_to_msecs(jiffies - issue_time) > (rcfw->max_timeout * 1000)) { ret = bnxt_re_is_fw_stalled(rcfw, cookie); if (ret) return ret; } } while (true); }; static int __send_message_basic_sanity(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_cmdqmsg *msg, u8 opcode) { … } /* This function will just post and do not bother about completion */ static void __destroy_timedout_ah(struct bnxt_qplib_rcfw *rcfw, struct creq_create_ah_resp *create_ah_resp) { … } /** * __bnxt_qplib_rcfw_send_message - qplib interface to send * and complete rcfw command. * @rcfw: rcfw channel instance of rdev * @msg: qplib message internal * * This function does not account shadow queue depth. It will send * all the command unconditionally as long as send queue is not full. * * Returns: * 0 if command completed by firmware. * Non zero if the command is not completed by firmware. */ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_cmdqmsg *msg) { … } /** * bnxt_qplib_rcfw_send_message - qplib interface to send * and complete rcfw command. * @rcfw: rcfw channel instance of rdev * @msg: qplib message internal * * Driver interact with Firmware through rcfw channel/slow path in two ways. * a. Blocking rcfw command send. In this path, driver cannot hold * the context for longer period since it is holding cpu until * command is not completed. * b. Non-blocking rcfw command send. In this path, driver can hold the * context for longer period. There may be many pending command waiting * for completion because of non-blocking nature. * * Driver will use shadow queue depth. Current queue depth of 8K * (due to size of rcfw message there can be actual ~4K rcfw outstanding) * is not optimal for rcfw command processing in firmware. * * Restrict at max #RCFW_CMD_NON_BLOCKING_SHADOW_QD Non-Blocking rcfw commands. * Allow all blocking commands until there is no queue full. * * Returns: * 0 if command completed by firmware. * Non zero if the command is not completed by firmware. */ int bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_cmdqmsg *msg) { … } /* Completions */ static int bnxt_qplib_process_func_event(struct bnxt_qplib_rcfw *rcfw, struct creq_func_event *func_event) { … } static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, struct creq_qp_event *qp_event, u32 *num_wait) { … } /* SP - CREQ Completion handlers */ static void bnxt_qplib_service_creq(struct tasklet_struct *t) { … } static irqreturn_t bnxt_qplib_creq_irq(int irq, void *dev_instance) { … } /* RCFW */ int bnxt_qplib_deinit_rcfw(struct bnxt_qplib_rcfw *rcfw) { … } int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_ctx *ctx, int is_virtfn) { … } void bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_rcfw *rcfw) { … } int bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res, struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_ctx *ctx, int qp_tbl_sz) { … } void bnxt_qplib_rcfw_stop_irq(struct bnxt_qplib_rcfw *rcfw, bool kill) { … } void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw) { … } int bnxt_qplib_rcfw_start_irq(struct bnxt_qplib_rcfw *rcfw, int msix_vector, bool need_init) { … } static int bnxt_qplib_map_cmdq_mbox(struct bnxt_qplib_rcfw *rcfw) { … } static int bnxt_qplib_map_creq_db(struct bnxt_qplib_rcfw *rcfw, u32 reg_offt) { … } static void bnxt_qplib_start_rcfw(struct bnxt_qplib_rcfw *rcfw) { … } int bnxt_qplib_enable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw, int msix_vector, int cp_bar_reg_off, aeq_handler_t aeq_handler) { … }