Exemple #1
0
static int dpni_init(void)
{
	int err;
	struct dpni_attr dpni_attr;
	struct dpni_cfg dpni_cfg;

	dflt_dpni = (struct fsl_dpni_obj *)malloc(sizeof(struct fsl_dpni_obj));
	if (!dflt_dpni) {
		printf("No memory: malloc() failed\n");
		err = -ENOMEM;
		goto err_malloc;
	}

	memset(&dpni_cfg, 0, sizeof(dpni_cfg));
	dpni_cfg.adv.options = DPNI_OPT_UNICAST_FILTER |
			       DPNI_OPT_MULTICAST_FILTER;

	err = dpni_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpni_cfg,
			  &dflt_dpni->dpni_handle);

	if (err < 0) {
		err = -ENODEV;
		printf("dpni_create() failed: %d\n", err);
		goto err_create;
	}

	memset(&dpni_attr, 0, sizeof(struct dpni_attr));
	err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
				  dflt_dpni->dpni_handle,
				  &dpni_attr);
	if (err < 0) {
		printf("dpni_get_attributes() failed: %d\n", err);
		goto err_get_attr;
	}

	dflt_dpni->dpni_id = dpni_attr.id;
#ifdef DEBUG
	printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
#endif

	err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0) {
		printf("dpni_close() failed: %d\n", err);
		goto err_close;
	}

	return 0;

err_close:
	free(dflt_dpni);
err_get_attr:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_create:
err_malloc:
	return err;
}
static void ldpaa_eth_stop(struct eth_device *net_dev)
{
	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
	int err = 0;

	if ((net_dev->state == ETH_STATE_PASSIVE) ||
	    (net_dev->state == ETH_STATE_INIT))
		return;

#ifdef DEBUG
	ldpaa_eth_get_dpni_counter();
#endif

	err = dprc_disconnect(dflt_mc_io, MC_CMD_NO_FLAGS,
			      dflt_dprc_handle, &dpmac_endpoint);
	if (err < 0)
		printf("dprc_disconnect() failed dpmac_endpoint\n");

	err = dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
	if (err < 0)
		printf("dpmac_destroy() failed\n");

	/* Stop Tx and Rx traffic */
	err = dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0)
		printf("dpni_disable() failed\n");

#ifdef CONFIG_PHYLIB
	phy_shutdown(priv->phydev);
#endif

	ldpaa_dpbp_free();
	dpni_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
}
Exemple #3
0
static void ldpaa_eth_stop(struct eth_device *net_dev)
{
	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
	int err = 0;

	if ((net_dev->state == ETH_STATE_PASSIVE) ||
	    (net_dev->state == ETH_STATE_INIT))
		return;
	/* Stop Tx and Rx traffic */
	err = dpni_disable(dflt_mc_io, priv->dpni_handle);
	if (err < 0)
		printf("dpni_disable() failed\n");

#ifdef CONFIG_PHYLIB
	phy_shutdown(priv->phydev);
#endif

	ldpaa_dpbp_free();
	dpni_reset(dflt_mc_io, priv->dpni_handle);
	dpni_close(dflt_mc_io, priv->dpni_handle);
}
static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
{
	int err = 0;
	struct dprc_connection_cfg dprc_connection_cfg = {
		/* If both rates are zero the connection */
		/* will be configured in "best effort" mode. */
		.committed_rate = 0,
		.max_rate = 0
	};

#ifdef DEBUG
	struct dprc_endpoint dbg_endpoint;
	int state = 0;
#endif

	memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
	sprintf(dpmac_endpoint.type, "dpmac");
	dpmac_endpoint.id = priv->dpmac_id;

	memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
	sprintf(dpni_endpoint.type, "dpni");
	dpni_endpoint.id = dflt_dpni->dpni_id;

	err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
			     dflt_dprc_handle,
			     &dpmac_endpoint,
			     &dpni_endpoint,
			     &dprc_connection_cfg);
	if (err)
		printf("dprc_connect() failed\n");

#ifdef DEBUG
	err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
				    dflt_dprc_handle, &dpni_endpoint,
				    &dbg_endpoint, &state);
	printf("%s, DPMAC Type= %s\n", __func__, dbg_endpoint.type);
	printf("%s, DPMAC ID= %d\n", __func__, dbg_endpoint.id);
	printf("%s, DPMAC State= %d\n", __func__, state);

	memset(&dbg_endpoint, 0, sizeof(struct dprc_endpoint));
	err = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
				    dflt_dprc_handle, &dpmac_endpoint,
				    &dbg_endpoint, &state);
	printf("%s, DPNI Type= %s\n", __func__, dbg_endpoint.type);
	printf("%s, DPNI ID= %d\n", __func__, dbg_endpoint.id);
	printf("%s, DPNI State= %d\n", __func__, state);
#endif
	return err;
}

static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
{
	int err;

	/* and get a handle for the DPNI this interface is associate with */
	err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
			&dflt_dpni->dpni_handle);
	if (err) {
		printf("dpni_open() failed\n");
		goto err_open;
	}

	err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
				  dflt_dpni->dpni_handle,
				  &dflt_dpni->dpni_attrs);
	if (err) {
		printf("dpni_get_attributes() failed (err=%d)\n", err);
		goto err_get_attr;
	}

	/* Configure our buffers' layout */
	dflt_dpni->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
				   DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
				   DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
				   DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
	dflt_dpni->buf_layout.pass_parser_result = true;
	dflt_dpni->buf_layout.pass_frame_status = true;
	dflt_dpni->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
	/* HW erratum mandates data alignment in multiples of 256 */
	dflt_dpni->buf_layout.data_align = LDPAA_ETH_BUF_ALIGN;
	/* ...rx, ... */
	err = dpni_set_rx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
					dflt_dpni->dpni_handle,
					&dflt_dpni->buf_layout);
	if (err) {
		printf("dpni_set_rx_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* ... tx, ... */
	/* remove Rx-only options */
	dflt_dpni->buf_layout.options &= ~(DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
				      DPNI_BUF_LAYOUT_OPT_PARSER_RESULT);
	err = dpni_set_tx_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
					dflt_dpni->dpni_handle,
					&dflt_dpni->buf_layout);
	if (err) {
		printf("dpni_set_tx_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* ... tx-confirm. */
	dflt_dpni->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
	err = dpni_set_tx_conf_buffer_layout(dflt_mc_io, MC_CMD_NO_FLAGS,
					     dflt_dpni->dpni_handle,
					     &dflt_dpni->buf_layout);
	if (err) {
		printf("dpni_set_tx_conf_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* Now that we've set our tx buffer layout, retrieve the minimum
	 * required tx data offset.
	 */
	err = dpni_get_tx_data_offset(dflt_mc_io, MC_CMD_NO_FLAGS,
				      dflt_dpni->dpni_handle,
				      &priv->tx_data_offset);
	if (err) {
		printf("dpni_get_tx_data_offset() failed\n");
		goto err_data_offset;
	}

	/* Warn in case TX data offset is not multiple of 64 bytes. */
	WARN_ON(priv->tx_data_offset % 64);

	/* Accomodate SWA space. */
	priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
	debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);

	return 0;

err_data_offset:
err_buf_layout:
err_get_attr:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_open:
	return err;
}
static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
{
	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
	struct dpni_queue_attr rx_queue_attr;
	struct dpmac_link_state	dpmac_link_state = { 0 };
#ifdef DEBUG
	struct dpni_link_state link_state;
#endif
	int err;

	if (net_dev->state == ETH_STATE_ACTIVE)
		return 0;

	if (get_mc_boot_status() != 0) {
		printf("ERROR (MC is not booted)\n");
		return -ENODEV;
	}

	if (get_dpl_apply_status() == 0) {
		printf("ERROR (DPL is deployed. No device available)\n");
		return -ENODEV;
	}
	/* DPMAC initialization */
	err = ldpaa_dpmac_setup(priv);
	if (err < 0)
		goto err_dpmac_setup;

	/* DPMAC binding DPNI */
	err = ldpaa_dpmac_bind(priv);
	if (err)
		goto err_dpamc_bind;

	/* DPNI initialization */
	err = ldpaa_dpni_setup(priv);
	if (err < 0)
		goto err_dpni_setup;

	err = ldpaa_dpbp_setup();
	if (err < 0)
		goto err_dpbp_setup;

	/* DPNI binding DPBP */
	err = ldpaa_dpni_bind(priv);
	if (err)
		goto err_dpni_bind;

	err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
				dflt_dpni->dpni_handle, net_dev->enetaddr);
	if (err) {
		printf("dpni_add_mac_addr() failed\n");
		return err;
	}

#ifdef CONFIG_PHYLIB
	/* TODO Check this path */
	err = phy_startup(priv->phydev);
	if (err) {
		printf("%s: Could not initialize\n", priv->phydev->dev->name);
		return err;
	}
#else
	priv->phydev->speed = SPEED_1000;
	priv->phydev->link = 1;
	priv->phydev->duplex = DUPLEX_FULL;
#endif

	err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0) {
		printf("dpni_enable() failed\n");
		return err;
	}

	dpmac_link_state.rate = SPEED_1000;
	dpmac_link_state.options = DPMAC_LINK_OPT_AUTONEG;
	dpmac_link_state.up = 1;
	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
				  priv->dpmac_handle, &dpmac_link_state);
	if (err < 0) {
		printf("dpmac_set_link_state() failed\n");
		return err;
	}

#ifdef DEBUG
	err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
				  dflt_dpni->dpni_handle, &link_state);
	if (err < 0) {
		printf("dpni_get_link_state() failed\n");
		return err;
	}

	printf("link status: %d - ", link_state.up);
	link_state.up == 0 ? printf("down\n") :
	link_state.up == 1 ? printf("up\n") : printf("error state\n");
#endif

	/* TODO: support multiple Rx flows */
	err = dpni_get_rx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
			       dflt_dpni->dpni_handle, 0, 0, &rx_queue_attr);
	if (err) {
		printf("dpni_get_rx_flow() failed\n");
		goto err_rx_flow;
	}

	priv->rx_dflt_fqid = rx_queue_attr.fqid;

	err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
			    &priv->tx_qdid);
	if (err) {
		printf("dpni_get_qdid() failed\n");
		goto err_qdid;
	}

	if (!priv->phydev->link)
		printf("%s: No link.\n", priv->phydev->dev->name);

	return priv->phydev->link ? 0 : -1;

err_qdid:
err_rx_flow:
	dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_dpni_bind:
	ldpaa_dpbp_free();
err_dpbp_setup:
err_dpamc_bind:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_dpni_setup:
err_dpmac_setup:
	return err;
}
Exemple #6
0
static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
{
	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
	struct dpni_queue_attr rx_queue_attr;
	struct dpmac_link_state	dpmac_link_state = { 0 };
#ifdef DEBUG
	struct dpni_link_state link_state;
#endif
	int err = 0;
	struct mii_dev *bus;
	phy_interface_t enet_if;

	if (net_dev->state == ETH_STATE_ACTIVE)
		return 0;

	if (get_mc_boot_status() != 0) {
		printf("ERROR (MC is not booted)\n");
		return -ENODEV;
	}

	if (get_dpl_apply_status() == 0) {
		printf("ERROR (DPL is deployed. No device available)\n");
		return -ENODEV;
	}

	/* DPMAC initialization */
	err = ldpaa_dpmac_setup(priv);
	if (err < 0)
		goto err_dpmac_setup;

#ifdef CONFIG_PHYLIB
	if (priv->phydev)
		err = phy_startup(priv->phydev);
		if (err) {
			printf("%s: Could not initialize\n",
			       priv->phydev->dev->name);
			goto err_dpamc_bind;
		}
#else
	priv->phydev = (struct phy_device *)malloc(sizeof(struct phy_device));
	memset(priv->phydev, 0, sizeof(struct phy_device));

	priv->phydev->speed = SPEED_1000;
	priv->phydev->link = 1;
	priv->phydev->duplex = DUPLEX_FULL;
#endif

	bus = wriop_get_mdio(priv->dpmac_id);
	enet_if = wriop_get_enet_if(priv->dpmac_id);
	if ((bus == NULL) &&
	    (enet_if == PHY_INTERFACE_MODE_XGMII)) {
		priv->phydev = (struct phy_device *)
				malloc(sizeof(struct phy_device));
		memset(priv->phydev, 0, sizeof(struct phy_device));

		priv->phydev->speed = SPEED_10000;
		priv->phydev->link = 1;
		priv->phydev->duplex = DUPLEX_FULL;
	}

	if (!priv->phydev->link) {
		printf("%s: No link.\n", priv->phydev->dev->name);
		err = -1;
		goto err_dpamc_bind;
	}

	/* DPMAC binding DPNI */
	err = ldpaa_dpmac_bind(priv);
	if (err)
		goto err_dpamc_bind;

	/* DPNI initialization */
	err = ldpaa_dpni_setup(priv);
	if (err < 0)
		goto err_dpni_setup;

	err = ldpaa_dpbp_setup();
	if (err < 0)
		goto err_dpbp_setup;

	/* DPNI binding DPBP */
	err = ldpaa_dpni_bind(priv);
	if (err)
		goto err_dpni_bind;

	err = dpni_add_mac_addr(dflt_mc_io, MC_CMD_NO_FLAGS,
				dflt_dpni->dpni_handle, net_dev->enetaddr);
	if (err) {
		printf("dpni_add_mac_addr() failed\n");
		return err;
	}

	err = dpni_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0) {
		printf("dpni_enable() failed\n");
		return err;
	}

	dpmac_link_state.rate = priv->phydev->speed;

	if (priv->phydev->autoneg == AUTONEG_DISABLE)
		dpmac_link_state.options &= ~DPMAC_LINK_OPT_AUTONEG;
	else
		dpmac_link_state.options |= DPMAC_LINK_OPT_AUTONEG;

	if (priv->phydev->duplex == DUPLEX_HALF)
		dpmac_link_state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;

	dpmac_link_state.up = priv->phydev->link;

	err = dpmac_set_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
				  priv->dpmac_handle, &dpmac_link_state);
	if (err < 0) {
		printf("dpmac_set_link_state() failed\n");
		return err;
	}

#ifdef DEBUG
	err = dpni_get_link_state(dflt_mc_io, MC_CMD_NO_FLAGS,
				  dflt_dpni->dpni_handle, &link_state);
	if (err < 0) {
		printf("dpni_get_link_state() failed\n");
		return err;
	}

	printf("link status: %d - ", link_state.up);
	link_state.up == 0 ? printf("down\n") :
	link_state.up == 1 ? printf("up\n") : printf("error state\n");
#endif

	/* TODO: support multiple Rx flows */
	err = dpni_get_rx_flow(dflt_mc_io, MC_CMD_NO_FLAGS,
			       dflt_dpni->dpni_handle, 0, 0, &rx_queue_attr);
	if (err) {
		printf("dpni_get_rx_flow() failed\n");
		goto err_rx_flow;
	}

	priv->rx_dflt_fqid = rx_queue_attr.fqid;

	err = dpni_get_qdid(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle,
			    &priv->tx_qdid);
	if (err) {
		printf("dpni_get_qdid() failed\n");
		goto err_qdid;
	}

	return priv->phydev->link;

err_qdid:
err_rx_flow:
	dpni_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_dpni_bind:
	ldpaa_dpbp_free();
err_dpbp_setup:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_dpni_setup:
err_dpamc_bind:
	dpmac_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, priv->dpmac_handle);
err_dpmac_setup:
	return err;
}
Exemple #7
0
static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv)
{
	int err;

	/* and get a handle for the DPNI this interface is associate with */
	err = dpni_open(dflt_mc_io, priv->dpni_id, &priv->dpni_handle);
	if (err) {
		printf("dpni_open() failed\n");
		goto err_open;
	}

	err = dpni_get_attributes(dflt_mc_io, priv->dpni_handle,
				  &priv->dpni_attrs);
	if (err) {
		printf("dpni_get_attributes() failed (err=%d)\n", err);
		goto err_get_attr;
	}

	/* Configure our buffers' layout */
	priv->buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
				   DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
				   DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
	priv->buf_layout.pass_parser_result = true;
	priv->buf_layout.pass_frame_status = true;
	priv->buf_layout.private_data_size = LDPAA_ETH_SWA_SIZE;
	/* ...rx, ... */
	err = dpni_set_rx_buffer_layout(dflt_mc_io, priv->dpni_handle,
					&priv->buf_layout);
	if (err) {
		printf("dpni_set_rx_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* ... tx, ... */
	priv->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PARSER_RESULT;
	err = dpni_set_tx_buffer_layout(dflt_mc_io, priv->dpni_handle,
					&priv->buf_layout);
	if (err) {
		printf("dpni_set_tx_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* ... tx-confirm. */
	priv->buf_layout.options &= ~DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
	err = dpni_set_tx_conf_buffer_layout(dflt_mc_io, priv->dpni_handle,
					     &priv->buf_layout);
	if (err) {
		printf("dpni_set_tx_conf_buffer_layout() failed");
		goto err_buf_layout;
	}

	/* Now that we've set our tx buffer layout, retrieve the minimum
	 * required tx data offset.
	 */
	err = dpni_get_tx_data_offset(dflt_mc_io, priv->dpni_handle,
				      &priv->tx_data_offset);
	if (err) {
		printf("dpni_get_tx_data_offset() failed\n");
		goto err_data_offset;
	}

	/* Warn in case TX data offset is not multiple of 64 bytes. */
	WARN_ON(priv->tx_data_offset % 64);

	/* Accomodate SWA space. */
	priv->tx_data_offset += LDPAA_ETH_SWA_SIZE;
	debug("priv->tx_data_offset=%d\n", priv->tx_data_offset);

	return 0;

err_data_offset:
err_buf_layout:
err_get_attr:
	dpni_close(dflt_mc_io, priv->dpni_handle);
err_open:
	return err;
}
Exemple #8
0
static int ldpaa_eth_open(struct eth_device *net_dev, bd_t *bd)
{
	struct ldpaa_eth_priv *priv = (struct ldpaa_eth_priv *)net_dev->priv;
	struct dpni_queue_attr rx_queue_attr;
	uint8_t mac_addr[6];
	int err;

	if (net_dev->state == ETH_STATE_ACTIVE)
		return 0;

	/* DPNI initialization */
	err = ldpaa_dpni_setup(priv);
	if (err < 0)
		goto err_dpni_setup;

	err = ldpaa_dpbp_setup();
	if (err < 0)
		goto err_dpbp_setup;

	/* DPNI binding DPBP */
	err = ldpaa_dpni_bind(priv);
	if (err)
		goto err_bind;

	err = dpni_get_primary_mac_addr(dflt_mc_io, priv->dpni_handle,
					mac_addr);
	if (err) {
		printf("dpni_get_primary_mac_addr() failed\n");
		return err;
	}

	memcpy(net_dev->enetaddr, mac_addr, 0x6);

	/* setup the MAC address */
	if (net_dev->enetaddr[0] & 0x01) {
		printf("%s: MacAddress is multcast address\n",	__func__);
		return 1;
	}

#ifdef CONFIG_PHYLIB
	/* TODO Check this path */
	err = phy_startup(priv->phydev);
	if (err) {
		printf("%s: Could not initialize\n", priv->phydev->dev->name);
		return err;
	}
#else
	priv->phydev->speed = SPEED_1000;
	priv->phydev->link = 1;
	priv->phydev->duplex = DUPLEX_FULL;
#endif

	err = dpni_enable(dflt_mc_io, priv->dpni_handle);
	if (err < 0) {
		printf("dpni_enable() failed\n");
		return err;
	}

	/* TODO: support multiple Rx flows */
	err = dpni_get_rx_flow(dflt_mc_io, priv->dpni_handle, 0, 0,
			       &rx_queue_attr);
	if (err) {
		printf("dpni_get_rx_flow() failed\n");
		goto err_rx_flow;
	}

	priv->rx_dflt_fqid = rx_queue_attr.fqid;

	err = dpni_get_qdid(dflt_mc_io, priv->dpni_handle, &priv->tx_qdid);
	if (err) {
		printf("dpni_get_qdid() failed\n");
		goto err_qdid;
	}

	if (!priv->phydev->link)
		printf("%s: No link.\n", priv->phydev->dev->name);

	return priv->phydev->link ? 0 : -1;

err_qdid:
err_rx_flow:
	dpni_disable(dflt_mc_io, priv->dpni_handle);
err_bind:
	ldpaa_dpbp_free();
err_dpbp_setup:
	dpni_close(dflt_mc_io, priv->dpni_handle);
err_dpni_setup:
	return err;
}
Exemple #9
0
static int dpni_init(void)
{
	int err;
	uint8_t	cfg_buf[256] = {0};
	struct dpni_cfg dpni_cfg;
	uint16_t major_ver, minor_ver;

	dflt_dpni = (struct fsl_dpni_obj *)calloc(
					sizeof(struct fsl_dpni_obj), 1);
	if (!dflt_dpni) {
		printf("No memory: calloc() failed\n");
		err = -ENOMEM;
		goto err_calloc;
	}

	memset(&dpni_cfg, 0, sizeof(dpni_cfg));
	err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
	if (err < 0) {
		err = -ENODEV;
		printf("dpni_prepare_cfg() failed: %d\n", err);
		goto err_prepare_cfg;
	}

	err = dpni_create(dflt_mc_io,
			  dflt_dprc_handle,
			  MC_CMD_NO_FLAGS,
			  &dpni_cfg,
			  &dflt_dpni->dpni_id);
	if (err < 0) {
		err = -ENODEV;
		printf("dpni create() failed: %d\n", err);
		goto err_create;
	}

	err = dpni_get_api_version(dflt_mc_io, 0,
				   &major_ver,
				   &minor_ver);
	if (err < 0) {
		printf("dpni_get_api_version() failed: %d\n", err);
		goto err_get_version;
	}

	if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
					   minor_ver < DPNI_VER_MINOR)) {
		printf("DPNI version mismatch found %u.%u,",
		       major_ver, minor_ver);
		printf("supported version is %u.%u\n",
		       DPNI_VER_MAJOR, DPNI_VER_MINOR);
	}

	err = dpni_open(dflt_mc_io,
			MC_CMD_NO_FLAGS,
			dflt_dpni->dpni_id,
			&dflt_dpni->dpni_handle);
	if (err) {
		printf("dpni_open() failed\n");
		goto err_open;
	}

#ifdef DEBUG
	printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
#endif
	err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0) {
		printf("dpni_close() failed: %d\n", err);
		goto err_close;
	}

	return 0;

err_close:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_open:
err_get_version:
	dpni_destroy(dflt_mc_io,
		     dflt_dprc_handle,
		     MC_CMD_NO_FLAGS,
		     dflt_dpni->dpni_id);
err_create:
err_prepare_cfg:
	free(dflt_dpni);
err_calloc:
	return err;
}
Exemple #10
0
static int dpni_init(void)
{
	int err;
	struct dpni_attr dpni_attr;
	uint8_t	ext_cfg_buf[256] = {0};
	struct dpni_extended_cfg dpni_extended_cfg;
	struct dpni_cfg dpni_cfg;

	dflt_dpni = (struct fsl_dpni_obj *)malloc(sizeof(struct fsl_dpni_obj));
	if (!dflt_dpni) {
		printf("No memory: malloc() failed\n");
		err = -ENOMEM;
		goto err_malloc;
	}

	memset(&dpni_extended_cfg, 0, sizeof(dpni_extended_cfg));
	err = dpni_prepare_extended_cfg(&dpni_extended_cfg, &ext_cfg_buf[0]);
	if (err < 0) {
		err = -ENODEV;
		printf("dpni_prepare_extended_cfg() failed: %d\n", err);
		goto err_prepare_extended_cfg;
	}

	memset(&dpni_cfg, 0, sizeof(dpni_cfg));
	dpni_cfg.adv.options = DPNI_OPT_UNICAST_FILTER |
			       DPNI_OPT_MULTICAST_FILTER;

	dpni_cfg.adv.ext_cfg_iova = (uint64_t)&ext_cfg_buf[0];
	err = dpni_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpni_cfg,
			  &dflt_dpni->dpni_handle);

	if (err < 0) {
		err = -ENODEV;
		printf("dpni_create() failed: %d\n", err);
		goto err_create;
	}

	memset(&dpni_attr, 0, sizeof(struct dpni_attr));
	err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
				  dflt_dpni->dpni_handle,
				  &dpni_attr);
	if (err < 0) {
		printf("dpni_get_attributes() failed: %d\n", err);
		goto err_get_attr;
	}

	if ((dpni_attr.version.major != DPNI_VER_MAJOR) ||
	    (dpni_attr.version.minor != DPNI_VER_MINOR)) {
		printf("DPNI version mismatch found %u.%u,",
		       dpni_attr.version.major, dpni_attr.version.minor);
		printf("supported version is %u.%u\n",
		       DPNI_VER_MAJOR, DPNI_VER_MINOR);
	}

	dflt_dpni->dpni_id = dpni_attr.id;
#ifdef DEBUG
	printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
#endif

	err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	if (err < 0) {
		printf("dpni_close() failed: %d\n", err);
		goto err_close;
	}

	return 0;

err_close:
err_get_attr:
	dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
	dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
err_create:
err_prepare_extended_cfg:
	free(dflt_dpni);
err_malloc:
	return err;
}