Commit 920767a9 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'liquidio-improve-soft-command-response-handling'



Weilin Chang says:

====================
liquidio: improve soft command/response handling

Change soft command handling to fix the possible race condition when the
process handles a response of a soft command that was already freed by an
application which got timeout for this request.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0927f71d 64fecd3e
Loading
Loading
Loading
Loading
+54 −178
Original line number Diff line number Diff line
@@ -31,38 +31,6 @@

#define OCTNIC_MAX_SG  MAX_SKB_FRAGS

/**
 * \brief Callback for getting interface configuration
 * @param status status of request
 * @param buf pointer to resp structure
 */
void lio_if_cfg_callback(struct octeon_device *oct,
			 u32 status __attribute__((unused)), void *buf)
{
	struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
	struct liquidio_if_cfg_context *ctx;
	struct liquidio_if_cfg_resp *resp;

	resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
	ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;

	oct = lio_get_device(ctx->octeon_id);
	if (resp->status)
		dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: %llx\n",
			CVM_CAST64(resp->status));
	WRITE_ONCE(ctx->cond, 1);

	snprintf(oct->fw_info.liquidio_firmware_version, 32, "%s",
		 resp->cfg_info.liquidio_firmware_version);

	/* This barrier is required to be sure that the response has been
	 * written fully before waking up the handler
	 */
	wmb();

	wake_up_interruptible(&ctx->wc);
}

/**
 * \brief Delete gather lists
 * @param lio per-network private data
@@ -198,14 +166,15 @@ int liquidio_set_feature(struct net_device *netdev, int cmd, u16 param1)
	nctrl.ncmd.s.cmd = cmd;
	nctrl.ncmd.s.param1 = param1;
	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
	nctrl.wait_time = 100;
	nctrl.netpndev = (u64)netdev;
	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;

	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
	if (ret < 0) {
	if (ret) {
		dev_err(&oct->pci_dev->dev, "Feature change failed in core (ret: 0x%x)\n",
			ret);
		if (ret > 0)
			ret = -EIO;
	}
	return ret;
}
@@ -285,15 +254,7 @@ void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
	struct octeon_device *oct = lio->oct_dev;
	u8 *mac;

	if (nctrl->completion && nctrl->response_code) {
		/* Signal whoever is interested that the response code from the
		 * firmware has arrived.
		 */
		WRITE_ONCE(*nctrl->response_code, nctrl->status);
		complete(nctrl->completion);
	}

	if (nctrl->status)
	if (nctrl->sc_status)
		return;

	switch (nctrl->ncmd.s.cmd) {
@@ -1218,30 +1179,6 @@ int octeon_setup_interrupt(struct octeon_device *oct, u32 num_ioqs)
	return 0;
}

static void liquidio_change_mtu_completion(struct octeon_device *oct,
					   u32 status, void *buf)
{
	struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
	struct liquidio_if_cfg_context *ctx;

	ctx  = (struct liquidio_if_cfg_context *)sc->ctxptr;

	if (status) {
		dev_err(&oct->pci_dev->dev, "MTU change failed. Status: %llx\n",
			CVM_CAST64(status));
		WRITE_ONCE(ctx->cond, LIO_CHANGE_MTU_FAIL);
	} else {
		WRITE_ONCE(ctx->cond, LIO_CHANGE_MTU_SUCCESS);
	}

	/* This barrier is required to be sure that the response has been
	 * written fully before waking up the handler
	 */
	wmb();

	wake_up_interruptible(&ctx->wc);
}

/**
 * \brief Net device change_mtu
 * @param netdev network device
@@ -1250,22 +1187,17 @@ int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
{
	struct lio *lio = GET_LIO(netdev);
	struct octeon_device *oct = lio->oct_dev;
	struct liquidio_if_cfg_context *ctx;
	struct octeon_soft_command *sc;
	union octnet_cmd *ncmd;
	int ctx_size;
	int ret = 0;

	ctx_size = sizeof(struct liquidio_if_cfg_context);
	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE, 16, ctx_size);
		octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE, 16, 0);

	ncmd = (union octnet_cmd *)sc->virtdptr;
	ctx  = (struct liquidio_if_cfg_context *)sc->ctxptr;

	WRITE_ONCE(ctx->cond, 0);
	ctx->octeon_id = lio_get_device_id(oct);
	init_waitqueue_head(&ctx->wc);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	ncmd->u64 = 0;
	ncmd->s.cmd = OCTNET_CMD_CHANGE_MTU;
@@ -1278,28 +1210,28 @@ int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
				    OPCODE_NIC_CMD, 0, 0, 0);

	sc->callback = liquidio_change_mtu_completion;
	sc->callback_arg = sc;
	sc->wait_time = 100;

	ret = octeon_send_soft_command(oct, sc);
	if (ret == IQ_SEND_FAILED) {
		netif_info(lio, rx_err, lio->netdev, "Failed to change MTU\n");
		octeon_free_soft_command(oct, sc);
		return -EINVAL;
	}
	/* Sleep on a wait queue till the cond flag indicates that the
	 * response arrived or timed-out.
	 */
	if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR ||
	    ctx->cond == LIO_CHANGE_MTU_FAIL) {
		octeon_free_soft_command(oct, sc);
	ret = wait_for_sc_completion_timeout(oct, sc, 0);
	if (ret)
		return ret;

	if (sc->sc_status) {
		WRITE_ONCE(sc->caller_is_done, true);
		return -EINVAL;
	}

	netdev->mtu = new_mtu;
	lio->mtu = new_mtu;

	octeon_free_soft_command(oct, sc);
	WRITE_ONCE(sc->caller_is_done, true);
	return 0;
}

@@ -1333,8 +1265,6 @@ octnet_nic_stats_callback(struct octeon_device *oct_dev,
	struct octeon_soft_command *sc = (struct octeon_soft_command *)ptr;
	struct oct_nic_stats_resp *resp =
	    (struct oct_nic_stats_resp *)sc->virtrptr;
	struct oct_nic_stats_ctrl *ctrl =
	    (struct oct_nic_stats_ctrl *)sc->ctxptr;
	struct nic_rx_stats *rsp_rstats = &resp->stats.fromwire;
	struct nic_tx_stats *rsp_tstats = &resp->stats.fromhost;
	struct nic_rx_stats *rstats = &oct_dev->link_stats.fromwire;
@@ -1424,7 +1354,6 @@ octnet_nic_stats_callback(struct octeon_device *oct_dev,
	} else {
		resp->status = -1;
	}
	complete(&ctrl->complete);
}

int octnet_get_link_stats(struct net_device *netdev)
@@ -1432,7 +1361,6 @@ int octnet_get_link_stats(struct net_device *netdev)
	struct lio *lio = GET_LIO(netdev);
	struct octeon_device *oct_dev = lio->oct_dev;
	struct octeon_soft_command *sc;
	struct oct_nic_stats_ctrl *ctrl;
	struct oct_nic_stats_resp *resp;
	int retval;

@@ -1441,7 +1369,7 @@ int octnet_get_link_stats(struct net_device *netdev)
		octeon_alloc_soft_command(oct_dev,
					  0,
					  sizeof(struct oct_nic_stats_resp),
					  sizeof(struct octnic_ctrl_pkt));
					  0);

	if (!sc)
		return -ENOMEM;
@@ -1449,66 +1377,39 @@ int octnet_get_link_stats(struct net_device *netdev)
	resp = (struct oct_nic_stats_resp *)sc->virtrptr;
	memset(resp, 0, sizeof(struct oct_nic_stats_resp));

	ctrl = (struct oct_nic_stats_ctrl *)sc->ctxptr;
	memset(ctrl, 0, sizeof(struct oct_nic_stats_ctrl));
	ctrl->netdev = netdev;
	init_completion(&ctrl->complete);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	sc->iq_no = lio->linfo.txpciq[0].s.q_no;

	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
				    OPCODE_NIC_PORT_STATS, 0, 0, 0);

	sc->callback = octnet_nic_stats_callback;
	sc->callback_arg = sc;
	sc->wait_time = 500;	/*in milli seconds*/

	retval = octeon_send_soft_command(oct_dev, sc);
	if (retval == IQ_SEND_FAILED) {
		octeon_free_soft_command(oct_dev, sc);
		return -EINVAL;
	}

	wait_for_completion_timeout(&ctrl->complete, msecs_to_jiffies(1000));

	if (resp->status != 1) {
		octeon_free_soft_command(oct_dev, sc);

		return -EINVAL;
	retval = wait_for_sc_completion_timeout(oct_dev, sc,
						(2 * LIO_SC_MAX_TMO_MS));
	if (retval)  {
		dev_err(&oct_dev->pci_dev->dev, "sc OPCODE_NIC_PORT_STATS command failed\n");
		return retval;
	}

	octeon_free_soft_command(oct_dev, sc);
	octnet_nic_stats_callback(oct_dev, sc->sc_status, sc);
	WRITE_ONCE(sc->caller_is_done, true);

	return 0;
}

static void liquidio_nic_seapi_ctl_callback(struct octeon_device *oct,
					    u32 status,
					    void *buf)
{
	struct liquidio_nic_seapi_ctl_context *ctx;
	struct octeon_soft_command *sc = buf;

	ctx = sc->ctxptr;

	oct = lio_get_device(ctx->octeon_id);
	if (status) {
		dev_err(&oct->pci_dev->dev, "%s: instruction failed. Status: %llx\n",
			__func__,
			CVM_CAST64(status));
	}
	ctx->status = status;
	complete(&ctx->complete);
}

int liquidio_set_speed(struct lio *lio, int speed)
{
	struct liquidio_nic_seapi_ctl_context *ctx;
	struct octeon_device *oct = lio->oct_dev;
	struct oct_nic_seapi_resp *resp;
	struct octeon_soft_command *sc;
	union octnet_cmd *ncmd;
	u32 ctx_size;
	int retval;
	u32 var;

@@ -1521,21 +1422,18 @@ int liquidio_set_speed(struct lio *lio, int speed)
		return -EOPNOTSUPP;
	}

	ctx_size = sizeof(struct liquidio_nic_seapi_ctl_context);
	sc = octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
				       sizeof(struct oct_nic_seapi_resp),
				       ctx_size);
				       0);
	if (!sc)
		return -ENOMEM;

	ncmd = sc->virtdptr;
	ctx  = sc->ctxptr;
	resp = sc->virtrptr;
	memset(resp, 0, sizeof(struct oct_nic_seapi_resp));

	ctx->octeon_id = lio_get_device_id(oct);
	ctx->status = 0;
	init_completion(&ctx->complete);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	ncmd->u64 = 0;
	ncmd->s.cmd = SEAPI_CMD_SPEED_SET;
@@ -1548,30 +1446,24 @@ int liquidio_set_speed(struct lio *lio, int speed)
	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
				    OPCODE_NIC_UBOOT_CTL, 0, 0, 0);

	sc->callback = liquidio_nic_seapi_ctl_callback;
	sc->callback_arg = sc;
	sc->wait_time = 5000;

	retval = octeon_send_soft_command(oct, sc);
	if (retval == IQ_SEND_FAILED) {
		dev_info(&oct->pci_dev->dev, "Failed to send soft command\n");
		octeon_free_soft_command(oct, sc);
		retval = -EBUSY;
	} else {
		/* Wait for response or timeout */
		if (wait_for_completion_timeout(&ctx->complete,
						msecs_to_jiffies(10000)) == 0) {
			dev_err(&oct->pci_dev->dev, "%s: sc timeout\n",
				__func__);
			octeon_free_soft_command(oct, sc);
			return -EINTR;
		}
		retval = wait_for_sc_completion_timeout(oct, sc, 0);
		if (retval)
			return retval;

		retval = resp->status;

		if (retval) {
			dev_err(&oct->pci_dev->dev, "%s failed, retval=%d\n",
				__func__, retval);
			octeon_free_soft_command(oct, sc);
			WRITE_ONCE(sc->caller_is_done, true);

			return -EIO;
		}

@@ -1583,38 +1475,32 @@ int liquidio_set_speed(struct lio *lio, int speed)
		}

		oct->speed_setting = var;
		WRITE_ONCE(sc->caller_is_done, true);
	}

	octeon_free_soft_command(oct, sc);

	return retval;
}

int liquidio_get_speed(struct lio *lio)
{
	struct liquidio_nic_seapi_ctl_context *ctx;
	struct octeon_device *oct = lio->oct_dev;
	struct oct_nic_seapi_resp *resp;
	struct octeon_soft_command *sc;
	union octnet_cmd *ncmd;
	u32 ctx_size;
	int retval;

	ctx_size = sizeof(struct liquidio_nic_seapi_ctl_context);
	sc = octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
				       sizeof(struct oct_nic_seapi_resp),
				       ctx_size);
				       0);
	if (!sc)
		return -ENOMEM;

	ncmd = sc->virtdptr;
	ctx  = sc->ctxptr;
	resp = sc->virtrptr;
	memset(resp, 0, sizeof(struct oct_nic_seapi_resp));

	ctx->octeon_id = lio_get_device_id(oct);
	ctx->status = 0;
	init_completion(&ctx->complete);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	ncmd->u64 = 0;
	ncmd->s.cmd = SEAPI_CMD_SPEED_GET;
@@ -1626,37 +1512,20 @@ int liquidio_get_speed(struct lio *lio)
	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
				    OPCODE_NIC_UBOOT_CTL, 0, 0, 0);

	sc->callback = liquidio_nic_seapi_ctl_callback;
	sc->callback_arg = sc;
	sc->wait_time = 5000;

	retval = octeon_send_soft_command(oct, sc);
	if (retval == IQ_SEND_FAILED) {
		dev_info(&oct->pci_dev->dev, "Failed to send soft command\n");
		oct->no_speed_setting = 1;
		oct->speed_setting = 25;

		retval = -EBUSY;
	} else {
		if (wait_for_completion_timeout(&ctx->complete,
						msecs_to_jiffies(10000)) == 0) {
			dev_err(&oct->pci_dev->dev, "%s: sc timeout\n",
				__func__);

			oct->speed_setting = 25;
			oct->no_speed_setting = 1;

		octeon_free_soft_command(oct, sc);
		retval = -EIO;
	} else {
		retval = wait_for_sc_completion_timeout(oct, sc, 0);
		if (retval)
			return retval;

			return -EINTR;
		}
		retval = resp->status;
		if (retval) {
			dev_err(&oct->pci_dev->dev,
				"%s failed retval=%d\n", __func__, retval);
			oct->no_speed_setting = 1;
			oct->speed_setting = 25;
			octeon_free_soft_command(oct, sc);
			retval = -EIO;
		} else {
			u32 var;
@@ -1664,16 +1533,23 @@ int liquidio_get_speed(struct lio *lio)
			var = be32_to_cpu((__force __be32)resp->speed);
			oct->speed_setting = var;
			if (var == 0xffff) {
				oct->no_speed_setting = 1;
				/* unable to access boot variables
				 * get the default value based on the NIC type
				 */
				if (oct->subsystem_id ==
						OCTEON_CN2350_25GB_SUBSYS_ID ||
				    oct->subsystem_id ==
						OCTEON_CN2360_25GB_SUBSYS_ID) {
					oct->no_speed_setting = 1;
					oct->speed_setting = 25;
			}
				} else {
					oct->speed_setting = 10;
				}
			}

	octeon_free_soft_command(oct, sc);
		}
		WRITE_ONCE(sc->caller_is_done, true);
	}

	return retval;
}
+77 −179
Original line number Diff line number Diff line
@@ -33,25 +33,12 @@

static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs);

struct oct_intrmod_context {
	int octeon_id;
	wait_queue_head_t wc;
	int cond;
	int status;
};

struct oct_intrmod_resp {
	u64     rh;
	struct oct_intrmod_cfg intrmod;
	u64     status;
};

struct oct_mdio_cmd_context {
	int octeon_id;
	wait_queue_head_t wc;
	int cond;
};

struct oct_mdio_cmd_resp {
	u64 rh;
	struct oct_mdio_cmd resp;
@@ -472,12 +459,11 @@ lio_send_queue_count_update(struct net_device *netdev, uint32_t num_queues)
	nctrl.ncmd.s.param1 = num_queues;
	nctrl.ncmd.s.param2 = num_queues;
	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
	nctrl.wait_time = 100;
	nctrl.netpndev = (u64)netdev;
	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;

	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
	if (ret < 0) {
	if (ret) {
		dev_err(&oct->pci_dev->dev, "Failed to send Queue reset command (ret: 0x%x)\n",
			ret);
		return -1;
@@ -708,13 +694,13 @@ static int octnet_gpio_access(struct net_device *netdev, int addr, int val)
	nctrl.ncmd.s.param1 = addr;
	nctrl.ncmd.s.param2 = val;
	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
	nctrl.wait_time = 100;
	nctrl.netpndev = (u64)netdev;
	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;

	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
	if (ret < 0) {
		dev_err(&oct->pci_dev->dev, "Failed to configure gpio value\n");
	if (ret) {
		dev_err(&oct->pci_dev->dev,
			"Failed to configure gpio value, ret=%d\n", ret);
		return -EINVAL;
	}

@@ -734,41 +720,19 @@ static int octnet_id_active(struct net_device *netdev, int val)
	nctrl.ncmd.s.cmd = OCTNET_CMD_ID_ACTIVE;
	nctrl.ncmd.s.param1 = val;
	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
	nctrl.wait_time = 100;
	nctrl.netpndev = (u64)netdev;
	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;

	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
	if (ret < 0) {
		dev_err(&oct->pci_dev->dev, "Failed to configure gpio value\n");
	if (ret) {
		dev_err(&oct->pci_dev->dev,
			"Failed to configure gpio value, ret=%d\n", ret);
		return -EINVAL;
	}

	return 0;
}

/* Callback for when mdio command response arrives
 */
static void octnet_mdio_resp_callback(struct octeon_device *oct,
				      u32 status,
				      void *buf)
{
	struct oct_mdio_cmd_context *mdio_cmd_ctx;
	struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;

	mdio_cmd_ctx = (struct oct_mdio_cmd_context *)sc->ctxptr;

	oct = lio_get_device(mdio_cmd_ctx->octeon_id);
	if (status) {
		dev_err(&oct->pci_dev->dev, "MIDO instruction failed. Status: %llx\n",
			CVM_CAST64(status));
		WRITE_ONCE(mdio_cmd_ctx->cond, -1);
	} else {
		WRITE_ONCE(mdio_cmd_ctx->cond, 1);
	}
	wake_up_interruptible(&mdio_cmd_ctx->wc);
}

/* This routine provides PHY access routines for
 * mdio  clause45 .
 */
@@ -778,25 +742,20 @@ octnet_mdio45_access(struct lio *lio, int op, int loc, int *value)
	struct octeon_device *oct_dev = lio->oct_dev;
	struct octeon_soft_command *sc;
	struct oct_mdio_cmd_resp *mdio_cmd_rsp;
	struct oct_mdio_cmd_context *mdio_cmd_ctx;
	struct oct_mdio_cmd *mdio_cmd;
	int retval = 0;

	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct_dev,
					  sizeof(struct oct_mdio_cmd),
					  sizeof(struct oct_mdio_cmd_resp),
					  sizeof(struct oct_mdio_cmd_context));
					  sizeof(struct oct_mdio_cmd_resp), 0);

	if (!sc)
		return -ENOMEM;

	mdio_cmd_ctx = (struct oct_mdio_cmd_context *)sc->ctxptr;
	mdio_cmd_rsp = (struct oct_mdio_cmd_resp *)sc->virtrptr;
	mdio_cmd = (struct oct_mdio_cmd *)sc->virtdptr;

	WRITE_ONCE(mdio_cmd_ctx->cond, 0);
	mdio_cmd_ctx->octeon_id = lio_get_device_id(oct_dev);
	mdio_cmd->op = op;
	mdio_cmd->mdio_addr = loc;
	if (op)
@@ -808,42 +767,40 @@ octnet_mdio45_access(struct lio *lio, int op, int loc, int *value)
	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC, OPCODE_NIC_MDIO45,
				    0, 0, 0);

	sc->wait_time = 1000;
	sc->callback = octnet_mdio_resp_callback;
	sc->callback_arg = sc;

	init_waitqueue_head(&mdio_cmd_ctx->wc);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	retval = octeon_send_soft_command(oct_dev, sc);

	if (retval == IQ_SEND_FAILED) {
		dev_err(&oct_dev->pci_dev->dev,
			"octnet_mdio45_access instruction failed status: %x\n",
			retval);
		retval = -EBUSY;
		octeon_free_soft_command(oct_dev, sc);
		return -EBUSY;
	} else {
		/* Sleep on a wait queue till the cond flag indicates that the
		 * response arrived
		 */
		sleep_cond(&mdio_cmd_ctx->wc, &mdio_cmd_ctx->cond);
		retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
		if (retval)
			return retval;

		retval = mdio_cmd_rsp->status;
		if (retval) {
			dev_err(&oct_dev->pci_dev->dev, "octnet mdio45 access failed\n");
			retval = -EBUSY;
		} else {
			dev_err(&oct_dev->pci_dev->dev,
				"octnet mdio45 access failed: %x\n", retval);
			WRITE_ONCE(sc->caller_is_done, true);
			return -EBUSY;
		}

		octeon_swap_8B_data((u64 *)(&mdio_cmd_rsp->resp),
				    sizeof(struct oct_mdio_cmd) / 8);

			if (READ_ONCE(mdio_cmd_ctx->cond) == 1) {
		if (!op)
			*value = mdio_cmd_rsp->resp.value1;
			} else {
				retval = -EINVAL;
			}
		}
	}

	octeon_free_soft_command(oct_dev, sc);
		WRITE_ONCE(sc->caller_is_done, true);
	}

	return retval;
}
@@ -1007,8 +964,7 @@ lio_ethtool_get_ringparam(struct net_device *netdev,
static int lio_23xx_reconfigure_queue_count(struct lio *lio)
{
	struct octeon_device *oct = lio->oct_dev;
	struct liquidio_if_cfg_context *ctx;
	u32 resp_size, ctx_size, data_size;
	u32 resp_size, data_size;
	struct liquidio_if_cfg_resp *resp;
	struct octeon_soft_command *sc;
	union oct_nic_if_cfg if_cfg;
@@ -1018,11 +974,10 @@ static int lio_23xx_reconfigure_queue_count(struct lio *lio)
	int j;

	resp_size = sizeof(struct liquidio_if_cfg_resp);
	ctx_size = sizeof(struct liquidio_if_cfg_context);
	data_size = sizeof(struct lio_version);
	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct, data_size,
					  resp_size, ctx_size);
					  resp_size, 0);
	if (!sc) {
		dev_err(&oct->pci_dev->dev, "%s: Failed to allocate soft command\n",
			__func__);
@@ -1030,7 +985,6 @@ static int lio_23xx_reconfigure_queue_count(struct lio *lio)
	}

	resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
	ctx  = (struct liquidio_if_cfg_context *)sc->ctxptr;
	vdata = (struct lio_version *)sc->virtdptr;

	vdata->major = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
@@ -1038,9 +992,6 @@ static int lio_23xx_reconfigure_queue_count(struct lio *lio)
	vdata->micro = (__force u16)cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);

	ifidx_or_pfnum = oct->pf_num;
	WRITE_ONCE(ctx->cond, 0);
	ctx->octeon_id = lio_get_device_id(oct);
	init_waitqueue_head(&ctx->wc);

	if_cfg.u64 = 0;
	if_cfg.s.num_iqueues = oct->sriov_info.num_pf_rings;
@@ -1052,27 +1003,29 @@ static int lio_23xx_reconfigure_queue_count(struct lio *lio)
	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
				    OPCODE_NIC_QCOUNT_UPDATE, 0,
				    if_cfg.u64, 0);
	sc->callback = lio_if_cfg_callback;
	sc->callback_arg = sc;
	sc->wait_time = LIO_IFCFG_WAIT_TIME;

	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	retval = octeon_send_soft_command(oct, sc);
	if (retval == IQ_SEND_FAILED) {
		dev_err(&oct->pci_dev->dev,
			"iq/oq config failed status: %x\n",
			"Sending iq/oq config failed status: %x\n",
			retval);
		goto qcount_update_fail;
		octeon_free_soft_command(oct, sc);
		return -EIO;
	}

	if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
		dev_err(&oct->pci_dev->dev, "Wait interrupted\n");
		return -1;
	}
	retval = wait_for_sc_completion_timeout(oct, sc, 0);
	if (retval)
		return retval;

	retval = resp->status;
	if (retval) {
		dev_err(&oct->pci_dev->dev, "iq/oq config failed\n");
		goto qcount_update_fail;
		dev_err(&oct->pci_dev->dev,
			"iq/oq config failed: %x\n", retval);
		WRITE_ONCE(sc->caller_is_done, true);
		return -1;
	}

	octeon_swap_8B_data((u64 *)(&resp->cfg_info),
@@ -1097,16 +1050,12 @@ static int lio_23xx_reconfigure_queue_count(struct lio *lio)
	lio->txq = lio->linfo.txpciq[0].s.q_no;
	lio->rxq = lio->linfo.rxpciq[0].s.q_no;

	octeon_free_soft_command(oct, sc);
	dev_info(&oct->pci_dev->dev, "Queue count updated to %d\n",
		 lio->linfo.num_rxpciq);

	return 0;
	WRITE_ONCE(sc->caller_is_done, true);

qcount_update_fail:
	octeon_free_soft_command(oct, sc);

	return -1;
	return 0;
}

static int lio_reset_queues(struct net_device *netdev, uint32_t num_qs)
@@ -1412,7 +1361,6 @@ lio_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
	nctrl.ncmd.u64 = 0;
	nctrl.ncmd.s.cmd = OCTNET_CMD_SET_FLOW_CTL;
	nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
	nctrl.wait_time = 100;
	nctrl.netpndev = (u64)netdev;
	nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;

@@ -1433,8 +1381,9 @@ lio_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
	}

	ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
	if (ret < 0) {
		dev_err(&oct->pci_dev->dev, "Failed to set pause parameter\n");
	if (ret) {
		dev_err(&oct->pci_dev->dev,
			"Failed to set pause parameter, ret=%d\n", ret);
		return -EINVAL;
	}

@@ -2013,34 +1962,11 @@ static int lio_vf_get_sset_count(struct net_device *netdev, int sset)
	}
}

/* Callback function for intrmod */
static void octnet_intrmod_callback(struct octeon_device *oct_dev,
				    u32 status,
				    void *ptr)
{
	struct octeon_soft_command *sc = (struct octeon_soft_command *)ptr;
	struct oct_intrmod_context *ctx;

	ctx  = (struct oct_intrmod_context *)sc->ctxptr;

	ctx->status = status;

	WRITE_ONCE(ctx->cond, 1);

	/* This barrier is required to be sure that the response has been
	 * written fully before waking up the handler
	 */
	wmb();

	wake_up_interruptible(&ctx->wc);
}

/*  get interrupt moderation parameters */
static int octnet_get_intrmod_cfg(struct lio *lio,
				  struct oct_intrmod_cfg *intr_cfg)
{
	struct octeon_soft_command *sc;
	struct oct_intrmod_context *ctx;
	struct oct_intrmod_resp *resp;
	int retval;
	struct octeon_device *oct_dev = lio->oct_dev;
@@ -2049,8 +1975,7 @@ static int octnet_get_intrmod_cfg(struct lio *lio,
	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct_dev,
					  0,
					  sizeof(struct oct_intrmod_resp),
					  sizeof(struct oct_intrmod_context));
					  sizeof(struct oct_intrmod_resp), 0);

	if (!sc)
		return -ENOMEM;
@@ -2058,20 +1983,13 @@ static int octnet_get_intrmod_cfg(struct lio *lio,
	resp = (struct oct_intrmod_resp *)sc->virtrptr;
	memset(resp, 0, sizeof(struct oct_intrmod_resp));

	ctx = (struct oct_intrmod_context *)sc->ctxptr;
	memset(ctx, 0, sizeof(struct oct_intrmod_context));
	WRITE_ONCE(ctx->cond, 0);
	ctx->octeon_id = lio_get_device_id(oct_dev);
	init_waitqueue_head(&ctx->wc);

	sc->iq_no = lio->linfo.txpciq[0].s.q_no;

	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
				    OPCODE_NIC_INTRMOD_PARAMS, 0, 0, 0);

	sc->callback = octnet_intrmod_callback;
	sc->callback_arg = sc;
	sc->wait_time = 1000;
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	retval = octeon_send_soft_command(oct_dev, sc);
	if (retval == IQ_SEND_FAILED) {
@@ -2082,32 +2000,23 @@ static int octnet_get_intrmod_cfg(struct lio *lio,
	/* Sleep on a wait queue till the cond flag indicates that the
	 * response arrived or timed-out.
	 */
	if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
		dev_err(&oct_dev->pci_dev->dev, "Wait interrupted\n");
		goto intrmod_info_wait_intr;
	}
	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
	if (retval)
		return -ENODEV;

	retval = ctx->status || resp->status;
	if (retval) {
	if (resp->status) {
		dev_err(&oct_dev->pci_dev->dev,
			"Get interrupt moderation parameters failed\n");
		goto intrmod_info_wait_fail;
		WRITE_ONCE(sc->caller_is_done, true);
		return -ENODEV;
	}

	octeon_swap_8B_data((u64 *)&resp->intrmod,
			    (sizeof(struct oct_intrmod_cfg)) / 8);
	memcpy(intr_cfg, &resp->intrmod, sizeof(struct oct_intrmod_cfg));
	octeon_free_soft_command(oct_dev, sc);
	WRITE_ONCE(sc->caller_is_done, true);

	return 0;

intrmod_info_wait_fail:

	octeon_free_soft_command(oct_dev, sc);

intrmod_info_wait_intr:

	return -ENODEV;
}

/*  Configure interrupt moderation parameters */
@@ -2115,7 +2024,6 @@ static int octnet_set_intrmod_cfg(struct lio *lio,
				  struct oct_intrmod_cfg *intr_cfg)
{
	struct octeon_soft_command *sc;
	struct oct_intrmod_context *ctx;
	struct oct_intrmod_cfg *cfg;
	int retval;
	struct octeon_device *oct_dev = lio->oct_dev;
@@ -2124,18 +2032,11 @@ static int octnet_set_intrmod_cfg(struct lio *lio,
	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct_dev,
					  sizeof(struct oct_intrmod_cfg),
					  0,
					  sizeof(struct oct_intrmod_context));
					  16, 0);

	if (!sc)
		return -ENOMEM;

	ctx = (struct oct_intrmod_context *)sc->ctxptr;

	WRITE_ONCE(ctx->cond, 0);
	ctx->octeon_id = lio_get_device_id(oct_dev);
	init_waitqueue_head(&ctx->wc);

	cfg = (struct oct_intrmod_cfg *)sc->virtdptr;

	memcpy(cfg, intr_cfg, sizeof(struct oct_intrmod_cfg));
@@ -2146,9 +2047,8 @@ static int octnet_set_intrmod_cfg(struct lio *lio,
	octeon_prepare_soft_command(oct_dev, sc, OPCODE_NIC,
				    OPCODE_NIC_INTRMOD_CFG, 0, 0, 0);

	sc->callback = octnet_intrmod_callback;
	sc->callback_arg = sc;
	sc->wait_time = 1000;
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	retval = octeon_send_soft_command(oct_dev, sc);
	if (retval == IQ_SEND_FAILED) {
@@ -2159,26 +2059,24 @@ static int octnet_set_intrmod_cfg(struct lio *lio,
	/* Sleep on a wait queue till the cond flag indicates that the
	 * response arrived or timed-out.
	 */
	if (sleep_cond(&ctx->wc, &ctx->cond) != -EINTR) {
		retval = ctx->status;
	retval = wait_for_sc_completion_timeout(oct_dev, sc, 0);
	if (retval)
			dev_err(&oct_dev->pci_dev->dev,
				"intrmod config failed. Status: %llx\n",
				CVM_CAST64(retval));
		else
		return retval;

	retval = sc->sc_status;
	if (retval == 0) {
		dev_info(&oct_dev->pci_dev->dev,
			 "Rx-Adaptive Interrupt moderation %s\n",
			 (intr_cfg->rx_enable) ?
			 "enabled" : "disabled");

		octeon_free_soft_command(oct_dev, sc);

		return ((retval) ? -ENODEV : 0);
		WRITE_ONCE(sc->caller_is_done, true);
		return 0;
	}

	dev_err(&oct_dev->pci_dev->dev, "iq/oq config failed\n");

	return -EINTR;
	dev_err(&oct_dev->pci_dev->dev,
		"intrmod config failed. Status: %x\n", retval);
	WRITE_ONCE(sc->caller_is_done, true);
	return -ENODEV;
}

static int lio_get_intr_coalesce(struct net_device *netdev,
+138 −169

File changed.

Preview size limit exceeded, changes collapsed.

+83 −111

File changed.

Preview size limit exceeded, changes collapsed.

+16 −31
Original line number Diff line number Diff line
@@ -49,44 +49,25 @@ static const struct net_device_ops lio_vf_rep_ndev_ops = {
	.ndo_change_mtu = lio_vf_rep_change_mtu,
};

static void
lio_vf_rep_send_sc_complete(struct octeon_device *oct,
			    u32 status, void *ptr)
{
	struct octeon_soft_command *sc = (struct octeon_soft_command *)ptr;
	struct lio_vf_rep_sc_ctx *ctx =
		(struct lio_vf_rep_sc_ctx *)sc->ctxptr;
	struct lio_vf_rep_resp *resp =
		(struct lio_vf_rep_resp *)sc->virtrptr;

	if (status != OCTEON_REQUEST_TIMEOUT && READ_ONCE(resp->status))
		WRITE_ONCE(resp->status, 0);

	complete(&ctx->complete);
}

static int
lio_vf_rep_send_soft_command(struct octeon_device *oct,
			     void *req, int req_size,
			     void *resp, int resp_size)
{
	int tot_resp_size = sizeof(struct lio_vf_rep_resp) + resp_size;
	int ctx_size = sizeof(struct lio_vf_rep_sc_ctx);
	struct octeon_soft_command *sc = NULL;
	struct lio_vf_rep_resp *rep_resp;
	struct lio_vf_rep_sc_ctx *ctx;
	void *sc_req;
	int err;

	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct, req_size,
					  tot_resp_size, ctx_size);
					  tot_resp_size, 0);
	if (!sc)
		return -ENOMEM;

	ctx = (struct lio_vf_rep_sc_ctx *)sc->ctxptr;
	memset(ctx, 0, ctx_size);
	init_completion(&ctx->complete);
	init_completion(&sc->complete);
	sc->sc_status = OCTEON_REQUEST_PENDING;

	sc_req = (struct lio_vf_rep_req *)sc->virtdptr;
	memcpy(sc_req, req, req_size);
@@ -98,23 +79,24 @@ lio_vf_rep_send_soft_command(struct octeon_device *oct,
	sc->iq_no = 0;
	octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
				    OPCODE_NIC_VF_REP_CMD, 0, 0, 0);
	sc->callback = lio_vf_rep_send_sc_complete;
	sc->callback_arg = sc;
	sc->wait_time = LIO_VF_REP_REQ_TMO_MS;

	err = octeon_send_soft_command(oct, sc);
	if (err == IQ_SEND_FAILED)
		goto free_buff;

	wait_for_completion_timeout(&ctx->complete,
				    msecs_to_jiffies
				    (2 * LIO_VF_REP_REQ_TMO_MS));
	err = wait_for_sc_completion_timeout(oct, sc, 0);
	if (err)
		return err;

	err = READ_ONCE(rep_resp->status) ? -EBUSY : 0;
	if (err)
		dev_err(&oct->pci_dev->dev, "VF rep send config failed\n");

	if (resp)
	else if (resp)
		memcpy(resp, (rep_resp + 1), resp_size);

	WRITE_ONCE(sc->caller_is_done, true);
	return err;

free_buff:
	octeon_free_soft_command(oct, sc);

@@ -404,7 +386,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
	}

	sc = (struct octeon_soft_command *)
		octeon_alloc_soft_command(oct, 0, 0, 0);
		octeon_alloc_soft_command(oct, 0, 16, 0);
	if (!sc) {
		dev_err(&oct->pci_dev->dev, "VF rep: Soft command alloc failed\n");
		goto xmit_failed;
@@ -413,6 +395,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
	/* Multiple buffers are not used for vf_rep packets. */
	if (skb_shinfo(skb)->nr_frags != 0) {
		dev_err(&oct->pci_dev->dev, "VF rep: nr_frags != 0. Dropping packet\n");
		octeon_free_soft_command(oct, sc);
		goto xmit_failed;
	}

@@ -420,6 +403,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
				     skb->data, skb->len, DMA_TO_DEVICE);
	if (dma_mapping_error(&oct->pci_dev->dev, sc->dmadptr)) {
		dev_err(&oct->pci_dev->dev, "VF rep: DMA mapping failed\n");
		octeon_free_soft_command(oct, sc);
		goto xmit_failed;
	}

@@ -440,6 +424,7 @@ lio_vf_rep_pkt_xmit(struct sk_buff *skb, struct net_device *ndev)
	if (status == IQ_SEND_FAILED) {
		dma_unmap_single(&oct->pci_dev->dev, sc->dmadptr,
				 sc->datasize, DMA_TO_DEVICE);
		octeon_free_soft_command(oct, sc);
		goto xmit_failed;
	}

Loading