net/octeontx: add device info
[dpdk.git] / drivers / net / octeontx / octeontx_ethdev.c
index 1e509ea..6ae345b 100644 (file)
@@ -105,6 +105,50 @@ free_kvlist:
        return ret;
 }
 
+static int
+octeontx_port_open(struct octeontx_nic *nic)
+{
+       octeontx_mbox_bgx_port_conf_t bgx_port_conf;
+       int res;
+
+       res = 0;
+
+       PMD_INIT_FUNC_TRACE();
+
+       res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
+       if (res < 0) {
+               octeontx_log_err("failed to open port %d", res);
+               return res;
+       }
+
+       nic->node = bgx_port_conf.node;
+       nic->port_ena = bgx_port_conf.enable;
+       nic->base_ichan = bgx_port_conf.base_chan;
+       nic->base_ochan = bgx_port_conf.base_chan;
+       nic->num_ichans = bgx_port_conf.num_chans;
+       nic->num_ochans = bgx_port_conf.num_chans;
+       nic->mtu = bgx_port_conf.mtu;
+       nic->bpen = bgx_port_conf.bpen;
+       nic->fcs_strip = bgx_port_conf.fcs_strip;
+       nic->bcast_mode = bgx_port_conf.bcast_mode;
+       nic->mcast_mode = bgx_port_conf.mcast_mode;
+       nic->speed      = bgx_port_conf.mode;
+
+       memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
+
+       octeontx_log_dbg("port opened %d", nic->port_id);
+       return res;
+}
+
+static void
+octeontx_port_close(struct octeontx_nic *nic)
+{
+       PMD_INIT_FUNC_TRACE();
+
+       octeontx_bgx_port_close(nic->port_id);
+       octeontx_log_dbg("port closed %d", nic->port_id);
+}
+
 static inline void
 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
                                struct rte_event_dev_info *info)
@@ -126,17 +170,265 @@ devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
                        info->max_num_events;
 }
 
+static int
+octeontx_dev_configure(struct rte_eth_dev *dev)
+{
+       struct rte_eth_dev_data *data = dev->data;
+       struct rte_eth_conf *conf = &data->dev_conf;
+       struct rte_eth_rxmode *rxmode = &conf->rxmode;
+       struct rte_eth_txmode *txmode = &conf->txmode;
+       struct octeontx_nic *nic = octeontx_pmd_priv(dev);
+       int ret;
+
+       PMD_INIT_FUNC_TRACE();
+       RTE_SET_USED(conf);
+
+       if (!rte_eal_has_hugepages()) {
+               octeontx_log_err("huge page is not configured");
+               return -EINVAL;
+       }
+
+       if (txmode->mq_mode) {
+               octeontx_log_err("tx mq_mode DCB or VMDq not supported");
+               return -EINVAL;
+       }
+
+       if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
+               rxmode->mq_mode != ETH_MQ_RX_RSS) {
+               octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
+               return -EINVAL;
+       }
+
+       if (!rxmode->hw_strip_crc) {
+               PMD_INIT_LOG(NOTICE, "can't disable hw crc strip");
+               rxmode->hw_strip_crc = 1;
+       }
+
+       if (rxmode->hw_ip_checksum) {
+               PMD_INIT_LOG(NOTICE, "rxcksum not supported");
+               rxmode->hw_ip_checksum = 0;
+       }
+
+       if (rxmode->split_hdr_size) {
+               octeontx_log_err("rxmode does not support split header");
+               return -EINVAL;
+       }
+
+       if (rxmode->hw_vlan_filter) {
+               octeontx_log_err("VLAN filter not supported");
+               return -EINVAL;
+       }
+
+       if (rxmode->hw_vlan_extend) {
+               octeontx_log_err("VLAN extended not supported");
+               return -EINVAL;
+       }
+
+       if (rxmode->enable_lro) {
+               octeontx_log_err("LRO not supported");
+               return -EINVAL;
+       }
+
+       if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
+               octeontx_log_err("setting link speed/duplex not supported");
+               return -EINVAL;
+       }
+
+       if (conf->dcb_capability_en) {
+               octeontx_log_err("DCB enable not supported");
+               return -EINVAL;
+       }
+
+       if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
+               octeontx_log_err("flow director not supported");
+               return -EINVAL;
+       }
+
+       nic->num_tx_queues = dev->data->nb_tx_queues;
+
+       ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ,
+                                       nic->num_tx_queues,
+                                       nic->base_ochan);
+       if (ret) {
+               octeontx_log_err("failed to open channel %d no-of-txq %d",
+                          nic->base_ochan, nic->num_tx_queues);
+               return -EFAULT;
+       }
+
+       nic->pki.classifier_enable = false;
+       nic->pki.hash_enable = true;
+       nic->pki.initialized = false;
+
+       return 0;
+}
+
+static void
+octeontx_dev_info(struct rte_eth_dev *dev,
+               struct rte_eth_dev_info *dev_info)
+{
+       RTE_SET_USED(dev);
+
+       /* Autonegotiation may be disabled */
+       dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
+       dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
+                       ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
+                       ETH_LINK_SPEED_40G;
+
+       dev_info->driver_name = RTE_STR(rte_octeontx_pmd);
+       dev_info->max_mac_addrs = 1;
+       dev_info->max_rx_pktlen = PKI_MAX_PKTLEN;
+       dev_info->max_rx_queues = 1;
+       dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
+       dev_info->min_rx_bufsize = 0;
+       dev_info->pci_dev = NULL;
+
+       dev_info->default_rxconf = (struct rte_eth_rxconf) {
+               .rx_free_thresh = 0,
+               .rx_drop_en = 0,
+       };
+
+       dev_info->default_txconf = (struct rte_eth_txconf) {
+               .tx_free_thresh = 0,
+               .txq_flags =
+                       ETH_TXQ_FLAGS_NOMULTSEGS |
+                       ETH_TXQ_FLAGS_NOOFFLOADS |
+                       ETH_TXQ_FLAGS_NOXSUMS,
+       };
+
+       dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE;
+}
+
+/* Initialize and register driver with DPDK Application */
+static const struct eth_dev_ops octeontx_dev_ops = {
+       .dev_configure           = octeontx_dev_configure,
+       .dev_infos_get           = octeontx_dev_info,
+};
+
 /* Create Ethdev interface per BGX LMAC ports */
 static int
 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
                        int socket_id)
 {
-       RTE_SET_USED(dev);
-       RTE_SET_USED(port);
-       RTE_SET_USED(evdev);
-       RTE_SET_USED(socket_id);
+       int res;
+       char octtx_name[OCTEONTX_MAX_NAME_LEN];
+       struct octeontx_nic *nic = NULL;
+       struct rte_eth_dev *eth_dev = NULL;
+       struct rte_eth_dev_data *data = NULL;
+       const char *name = rte_vdev_device_name(dev);
+
+       PMD_INIT_FUNC_TRACE();
+
+       sprintf(octtx_name, "%s_%d", name, port);
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+               eth_dev = rte_eth_dev_attach_secondary(octtx_name);
+               if (eth_dev == NULL)
+                       return -ENODEV;
+
+               return 0;
+       }
+
+       data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
+       if (data == NULL) {
+               octeontx_log_err("failed to allocate devdata");
+               res = -ENOMEM;
+               goto err;
+       }
+
+       nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
+       if (nic == NULL) {
+               octeontx_log_err("failed to allocate nic structure");
+               res = -ENOMEM;
+               goto err;
+       }
 
-       return -ENODEV;
+       nic->port_id = port;
+       nic->evdev = evdev;
+
+       res = octeontx_port_open(nic);
+       if (res < 0)
+               goto err;
+
+       /* Rx side port configuration */
+       res = octeontx_pki_port_open(port);
+       if (res != 0) {
+               octeontx_log_err("failed to open PKI port %d", port);
+               res = -ENODEV;
+               goto err;
+       }
+
+       /* Reserve an ethdev entry */
+       eth_dev = rte_eth_dev_allocate(octtx_name);
+       if (eth_dev == NULL) {
+               octeontx_log_err("failed to allocate rte_eth_dev");
+               res = -ENOMEM;
+               goto err;
+       }
+
+       eth_dev->device = &dev->device;
+       eth_dev->intr_handle = NULL;
+       eth_dev->data->kdrv = RTE_KDRV_NONE;
+       eth_dev->data->numa_node = dev->device.numa_node;
+
+       rte_memcpy(data, (eth_dev)->data, sizeof(*data));
+       data->dev_private = nic;
+
+       data->port_id = eth_dev->data->port_id;
+       snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
+
+       nic->ev_queues = 1;
+       nic->ev_ports = 1;
+
+       data->dev_link.link_status = ETH_LINK_DOWN;
+       data->dev_started = 0;
+       data->promiscuous = 0;
+       data->all_multicast = 0;
+       data->scattered_rx = 0;
+
+       data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
+                                                       socket_id);
+       if (data->mac_addrs == NULL) {
+               octeontx_log_err("failed to allocate memory for mac_addrs");
+               res = -ENOMEM;
+               goto err;
+       }
+
+       eth_dev->data = data;
+       eth_dev->dev_ops = &octeontx_dev_ops;
+
+       /* Finally save ethdev pointer to the NIC structure */
+       nic->dev = eth_dev;
+
+       if (nic->port_id != data->port_id) {
+               octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
+                               data->port_id, nic->port_id);
+               res = -EINVAL;
+               goto err;
+       }
+
+       /* Update port_id mac to eth_dev */
+       memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
+
+       PMD_INIT_LOG(DEBUG, "ethdev info: ");
+       PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
+                               nic->port_id, nic->port_ena,
+                               nic->base_ochan, nic->num_ochans,
+                               nic->num_tx_queues);
+       PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
+
+       return data->port_id;
+
+err:
+       if (port)
+               octeontx_port_close(nic);
+
+       if (eth_dev != NULL) {
+               rte_free(eth_dev->data->mac_addrs);
+               rte_free(data);
+               rte_free(nic);
+               rte_eth_dev_release_port(eth_dev);
+       }
+
+       return res;
 }
 
 /* Un initialize octeontx device */