[dpdk-dev] [PATCH v6 1/6] raw/ntb: introduce ntb rawdev driver

Wu, Jingjing jingjing.wu at intel.com
Tue Jun 18 18:07:34 CEST 2019


> +
> +static void
> +ntb_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info)
> +{
> +	struct ntb_hw *hw = dev->dev_private;
> +	struct ntb_attr *ntb_attrs = dev_info;
> +
> +	strncpy(ntb_attrs[NTB_TOPO_ID].name, NTB_TOPO_NAME,
> NTB_ATTR_NAME_LEN);
> +	switch (hw->topo) {
> +	case NTB_TOPO_B2B_DSD:
> +		strncpy(ntb_attrs[NTB_TOPO_ID].value, "B2B DSD",
> +			NTB_ATTR_NAME_LEN);
> +		break;
> +	case NTB_TOPO_B2B_USD:
> +		strncpy(ntb_attrs[NTB_TOPO_ID].value, "B2B USD",
> +			NTB_ATTR_NAME_LEN);
> +		break;
> +	default:
> +		strncpy(ntb_attrs[NTB_TOPO_ID].value, "Unsupported",
> +			NTB_ATTR_NAME_LEN);
> +	}
> +
> +	strncpy(ntb_attrs[NTB_LINK_STATUS_ID].name, NTB_LINK_STATUS_NAME,
> +		NTB_ATTR_NAME_LEN);
> +	snprintf(ntb_attrs[NTB_LINK_STATUS_ID].value, NTB_ATTR_NAME_LEN,
> +		 "%d", hw->link_status);
> +
You are sharing NTB_ATTR_NAME_LEN for both name and value? How about NTB_ATTR_NUM_LEN/NTB_ATTR_VALUE_LEN?

[...]


> +	if (!strncmp(attr_name, NTB_PEER_SPAD_14, NTB_ATTR_NAME_LEN)) {
> +		if (hw->ntb_ops->spad_write == NULL)
> +			return -ENOTSUP;
> +		(*hw->ntb_ops->spad_write)(dev, 14, 1, attr_value);
> +		NTB_LOG(INFO, "Set attribute (%s) Value (%" PRIu64 ")",
> +			attr_name, attr_value);
> +		return 0;
> +	}
> +
> +	if (!strncmp(attr_name, NTB_PEER_SPAD_15, NTB_ATTR_NAME_LEN)) {
> +		if (hw->ntb_ops->spad_write == NULL)
> +			return -ENOTSUP;
> +		(*hw->ntb_ops->spad_write)(dev, 15, 1, attr_value);
> +		NTB_LOG(INFO, "Set attribute (%s) Value (%" PRIu64 ")",
> +			attr_name, attr_value);
> +		return 0;
> +	}
> +
What are 14 and 15 for? Is that generic?


> +static int
> +ntb_init_hw(struct rte_rawdev *dev, struct rte_pci_device *pci_dev)
> +{
> +	struct ntb_hw *hw = dev->dev_private;
> +	int ret;
> +
> +	hw->pci_dev = pci_dev;
> +	hw->peer_dev_up = 0;
> +	hw->link_status = 0;
> +	hw->link_speed = NTB_SPEED_NONE;
> +	hw->link_width = NTB_WIDTH_NONE;
> +
> +	switch (pci_dev->id.device_id) {
> +	default:
> +		NTB_LOG(ERR, "Not supported device.");
> +		return -EINVAL;
> +	}
> +
> +	if (hw->ntb_ops->ntb_dev_init == NULL)
> +		return -ENOTSUP;
> +	ret = (*hw->ntb_ops->ntb_dev_init)(dev);
> +	if (ret) {
> +		NTB_LOG(ERR, "Unanle to init ntb dev.");
Typo: unanle -> unable
[...]


> +static int
> +ntb_rawdev_create(struct rte_pci_device *pci_dev, int socket_id)
> +{
> +	char name[RTE_RAWDEV_NAME_MAX_LEN];
> +	struct rte_rawdev *rawdev = NULL;
> +	int ret;
> +
> +	if (pci_dev == NULL) {
> +		NTB_LOG(ERR, "Invalid pci_dev.");
> +		ret = -EINVAL;
> +		goto fail;
Is there possibility to release rawdev at fail? Return might be enough.

> +	}
> +
> +	memset(name, 0, sizeof(name));
> +	snprintf(name, RTE_RAWDEV_NAME_MAX_LEN, "NTB:%x:%02x.%x",
> +		 pci_dev->addr.bus, pci_dev->addr.devid,
> +		 pci_dev->addr.function);
> +
> +	NTB_LOG(INFO, "Init %s on NUMA node %d", name, rte_socket_id());
Why not use the parameter "socket_id"?

> +
> +	/* Allocate device structure. */
> +	rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct ntb_hw),
> +					 socket_id);
> +	if (rawdev == NULL) {
> +		NTB_LOG(ERR, "Unable to allocate rawdev.");
> +		ret = -EINVAL;
> +		goto fail;
No need to goto fail as rawdev in NULL.

[...]


> +enum ntb_link {
> +	NTB_LINK_DOWN = 0,
> +	NTB_LINK_UP,
> +};
> +
You defined the enum, but you used 0 and 1 above.


Thanks
Jingjing


More information about the dev mailing list