X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fszedata2%2Frte_eth_szedata2.c;h=824debb22801e2a2a91875f6c5994e8c05af212c;hb=caccf8b318cafcdafe39faa3c5ce3eef67007621;hp=dd1ae9e9201962dbd017781cb40323e600fa6855;hpb=39fd068a27237ff0f825d8efd9ba9ed9a28cacb0;p=dpdk.git diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c index dd1ae9e920..824debb228 100644 --- a/drivers/net/szedata2/rte_eth_szedata2.c +++ b/drivers/net/szedata2/rte_eth_szedata2.c @@ -1,34 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright (c) 2015 - 2016 CESNET - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of CESNET nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT - * OWNER 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. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2015 - 2016 CESNET */ #include @@ -44,14 +15,16 @@ #include #include -#include +#include +#include #include #include #include #include -#include #include "rte_eth_szedata2.h" +#include "szedata2_logs.h" +#include "szedata2_iobuf.h" #define RTE_ETH_SZEDATA2_MAX_RX_QUEUES 32 #define RTE_ETH_SZEDATA2_MAX_TX_QUEUES 32 @@ -62,15 +35,23 @@ */ #define RTE_SZE2_PACKET_HEADER_SIZE_ALIGNED 8 -#define RTE_SZEDATA2_DRIVER_NAME "rte_szedata2_pmd" -#define RTE_SZEDATA2_PCI_DRIVER_NAME "rte_szedata2_pmd" +#define RTE_SZEDATA2_DRIVER_NAME net_szedata2 #define SZEDATA2_DEV_PATH_FMT "/dev/szedataII%u" +struct pmd_internals { + struct rte_eth_dev *dev; + uint16_t max_rx_queues; + uint16_t max_tx_queues; + char sze_dev[PATH_MAX]; + struct rte_mem_resource *pci_rsc; +}; + struct szedata2_rx_queue { + struct pmd_internals *priv; struct szedata *sze; uint8_t rx_channel; - uint8_t in_port; + uint16_t in_port; struct rte_mempool *mb_pool; volatile uint64_t rx_pkts; volatile uint64_t rx_bytes; @@ -78,6 +59,7 @@ struct szedata2_rx_queue { }; struct szedata2_tx_queue { + struct pmd_internals *priv; struct szedata *sze; uint8_t tx_channel; volatile uint64_t tx_pkts; @@ -85,13 +67,8 @@ struct szedata2_tx_queue { volatile uint64_t err_pkts; }; -struct pmd_internals { - struct szedata2_rx_queue rx_queue[RTE_ETH_SZEDATA2_MAX_RX_QUEUES]; - struct szedata2_tx_queue tx_queue[RTE_ETH_SZEDATA2_MAX_TX_QUEUES]; - uint16_t max_rx_queues; - uint16_t max_tx_queues; - char sze_dev[PATH_MAX]; -}; +int szedata2_logtype_init; +int szedata2_logtype_driver; static struct ether_addr eth_addr = { .addr_bytes = { 0x00, 0x11, 0x17, 0x00, 0x00, 0x00 } @@ -131,8 +108,10 @@ eth_szedata2_rx(void *queue, for (i = 0; i < nb_pkts; i++) { mbuf = rte_pktmbuf_alloc(sze_q->mb_pool); - if (unlikely(mbuf == NULL)) + if (unlikely(mbuf == NULL)) { + sze_q->priv->dev->data->rx_mbuf_alloc_failed++; break; + } /* get the next sze packet */ if (sze->ct_rx_lck != NULL && !sze->ct_rx_rem_bytes && @@ -316,10 +295,10 @@ eth_szedata2_rx(void *queue, * sze packet will not fit in one mbuf, * scattered mode is not enabled, drop packet */ - RTE_LOG(ERR, PMD, + PMD_DRV_LOG(ERR, "SZE segment %d bytes will not fit in one mbuf " "(%d bytes), scattered mode is not enabled, " - "drop packet!!\n", + "drop packet!!", packet_size, buf_size); rte_pktmbuf_free(mbuf); } @@ -352,6 +331,8 @@ eth_szedata2_rx_scattered(void *queue, uint16_t packet_len1 = 0; uint16_t packet_len2 = 0; uint16_t hw_data_align; + uint64_t *mbuf_failed_ptr = + &sze_q->priv->dev->data->rx_mbuf_alloc_failed; if (unlikely(sze_q->sze == NULL || nb_pkts == 0)) return 0; @@ -539,6 +520,7 @@ eth_szedata2_rx_scattered(void *queue, sze->ct_rx_lck = ct_rx_lck_backup; sze->ct_rx_rem_bytes = ct_rx_rem_bytes_backup; sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup; + sze_q->priv->dev->data->rx_mbuf_alloc_failed++; break; } @@ -588,6 +570,7 @@ eth_szedata2_rx_scattered(void *queue, ct_rx_rem_bytes_backup; sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup; + (*mbuf_failed_ptr)++; goto finish; } @@ -631,6 +614,7 @@ eth_szedata2_rx_scattered(void *queue, ct_rx_rem_bytes_backup; sze->ct_rx_cur_ptr = ct_rx_cur_ptr_backup; + (*mbuf_failed_ptr)++; goto finish; } @@ -680,7 +664,7 @@ eth_szedata2_tx(void *queue, uint32_t hwpkt_len; uint32_t unlock_size; uint32_t rem_len; - uint8_t mbuf_segs; + uint16_t mbuf_segs; uint16_t pkt_left = nb_pkts; if (sze_q->sze == NULL || nb_pkts == 0) @@ -1015,7 +999,7 @@ static int eth_dev_configure(struct rte_eth_dev *dev) { struct rte_eth_dev_data *data = dev->data; - if (data->dev_conf.rxmode.enable_scatter == 1) { + if (data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER) { dev->rx_pkt_burst = eth_szedata2_rx_scattered; data->scattered_rx = 1; } else { @@ -1030,15 +1014,21 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { struct pmd_internals *internals = dev->data->dev_private; + dev_info->if_index = 0; dev_info->max_mac_addrs = 1; dev_info->max_rx_pktlen = (uint32_t)-1; dev_info->max_rx_queues = internals->max_rx_queues; dev_info->max_tx_queues = internals->max_tx_queues; dev_info->min_rx_bufsize = 0; + dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER; + dev_info->tx_offload_capa = 0; + dev_info->rx_queue_offload_capa = 0; + dev_info->tx_queue_offload_capa = 0; + dev_info->speed_capa = ETH_LINK_SPEED_100G; } -static void +static int eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { @@ -1050,22 +1040,29 @@ eth_stats_get(struct rte_eth_dev *dev, uint64_t tx_err_total = 0; uint64_t rx_total_bytes = 0; uint64_t tx_total_bytes = 0; - const struct pmd_internals *internals = dev->data->dev_private; - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_rx; i++) { - stats->q_ipackets[i] = internals->rx_queue[i].rx_pkts; - stats->q_ibytes[i] = internals->rx_queue[i].rx_bytes; - rx_total += stats->q_ipackets[i]; - rx_total_bytes += stats->q_ibytes[i]; + for (i = 0; i < nb_rx; i++) { + struct szedata2_rx_queue *rxq = dev->data->rx_queues[i]; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[i] = rxq->rx_pkts; + stats->q_ibytes[i] = rxq->rx_bytes; + } + rx_total += rxq->rx_pkts; + rx_total_bytes += rxq->rx_bytes; } - for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < nb_tx; i++) { - stats->q_opackets[i] = internals->tx_queue[i].tx_pkts; - stats->q_obytes[i] = internals->tx_queue[i].tx_bytes; - stats->q_errors[i] = internals->tx_queue[i].err_pkts; - tx_total += stats->q_opackets[i]; - tx_total_bytes += stats->q_obytes[i]; - tx_err_total += stats->q_errors[i]; + for (i = 0; i < nb_tx; i++) { + struct szedata2_tx_queue *txq = dev->data->tx_queues[i]; + + if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_opackets[i] = txq->tx_pkts; + stats->q_obytes[i] = txq->tx_bytes; + stats->q_errors[i] = txq->err_pkts; + } + tx_total += txq->tx_pkts; + tx_total_bytes += txq->tx_bytes; + tx_err_total += txq->err_pkts; } stats->ipackets = rx_total; @@ -1073,6 +1070,9 @@ eth_stats_get(struct rte_eth_dev *dev, stats->ibytes = rx_total_bytes; stats->obytes = tx_total_bytes; stats->oerrors = tx_err_total; + stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed; + + return 0; } static void @@ -1081,17 +1081,18 @@ eth_stats_reset(struct rte_eth_dev *dev) uint16_t i; uint16_t nb_rx = dev->data->nb_rx_queues; uint16_t nb_tx = dev->data->nb_tx_queues; - struct pmd_internals *internals = dev->data->dev_private; for (i = 0; i < nb_rx; i++) { - internals->rx_queue[i].rx_pkts = 0; - internals->rx_queue[i].rx_bytes = 0; - internals->rx_queue[i].err_pkts = 0; + struct szedata2_rx_queue *rxq = dev->data->rx_queues[i]; + rxq->rx_pkts = 0; + rxq->rx_bytes = 0; + rxq->err_pkts = 0; } for (i = 0; i < nb_tx; i++) { - internals->tx_queue[i].tx_pkts = 0; - internals->tx_queue[i].tx_bytes = 0; - internals->tx_queue[i].err_pkts = 0; + struct szedata2_tx_queue *txq = dev->data->tx_queues[i]; + txq->tx_pkts = 0; + txq->tx_bytes = 0; + txq->err_pkts = 0; } } @@ -1099,9 +1100,11 @@ static void eth_rx_queue_release(void *q) { struct szedata2_rx_queue *rxq = (struct szedata2_rx_queue *)q; - if (rxq->sze != NULL) { - szedata_close(rxq->sze); - rxq->sze = NULL; + + if (rxq != NULL) { + if (rxq->sze != NULL) + szedata_close(rxq->sze); + rte_free(rxq); } } @@ -1109,9 +1112,11 @@ static void eth_tx_queue_release(void *q) { struct szedata2_tx_queue *txq = (struct szedata2_tx_queue *)q; - if (txq->sze != NULL) { - szedata_close(txq->sze); - txq->sze = NULL; + + if (txq != NULL) { + if (txq->sze != NULL) + szedata_close(txq->sze); + rte_free(txq); } } @@ -1136,18 +1141,47 @@ eth_dev_close(struct rte_eth_dev *dev) dev->data->nb_tx_queues = 0; } +/** + * Function takes value from first IBUF status register. + * Values in IBUF and OBUF should be same. + * + * @param internals + * Pointer to device private structure. + * @return + * Link speed constant. + */ +static inline enum szedata2_link_speed +get_link_speed(const struct pmd_internals *internals) +{ + const volatile struct szedata2_ibuf *ibuf = + ibuf_ptr_by_index(internals->pci_rsc, 0); + uint32_t speed = (szedata2_read32(&ibuf->ibuf_st) & 0x70) >> 4; + switch (speed) { + case 0x03: + return SZEDATA2_LINK_SPEED_10G; + case 0x04: + return SZEDATA2_LINK_SPEED_40G; + case 0x05: + return SZEDATA2_LINK_SPEED_100G; + default: + return SZEDATA2_LINK_SPEED_DEFAULT; + } +} + static int eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) { struct rte_eth_link link; - struct rte_eth_link *link_ptr = &link; - struct rte_eth_link *dev_link = &dev->data->dev_link; - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + const volatile struct szedata2_ibuf *ibuf; + uint32_t i; + bool link_is_up = false; + + memset(&link, 0, sizeof(link)); - switch (cgmii_link_speed(ibuf)) { + switch (get_link_speed(internals)) { case SZEDATA2_LINK_SPEED_10G: link.link_speed = ETH_SPEED_NUM_10G; break; @@ -1155,13 +1189,7 @@ eth_link_update(struct rte_eth_dev *dev, link.link_speed = ETH_SPEED_NUM_40G; break; case SZEDATA2_LINK_SPEED_100G: - /* - * TODO - * If link_speed value from rte_eth_link structure - * will be changed to support 100Gbps speed change - * this value to 100G. - */ - link.link_speed = ETH_SPEED_NUM_10G; + link.link_speed = ETH_SPEED_NUM_100G; break; default: link.link_speed = ETH_SPEED_NUM_10G; @@ -1171,42 +1199,51 @@ eth_link_update(struct rte_eth_dev *dev, /* szedata2 uses only full duplex */ link.link_duplex = ETH_LINK_FULL_DUPLEX; - link.link_status = (cgmii_ibuf_is_enabled(ibuf) && - cgmii_ibuf_is_link_up(ibuf)) ? ETH_LINK_UP : ETH_LINK_DOWN; + for (i = 0; i < szedata2_ibuf_count; i++) { + ibuf = ibuf_ptr_by_index(internals->pci_rsc, i); + /* + * Link is considered up if at least one ibuf is enabled + * and up. + */ + if (ibuf_is_enabled(ibuf) && ibuf_is_link_up(ibuf)) { + link_is_up = true; + break; + } + } - rte_atomic64_cmpset((uint64_t *)dev_link, *(uint64_t *)dev_link, - *(uint64_t *)link_ptr); + link.link_status = link_is_up ? ETH_LINK_UP : ETH_LINK_DOWN; + link.link_autoneg = ETH_LINK_FIXED; + + rte_eth_linkstatus_set(dev, &link); return 0; } static int eth_dev_set_link_up(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_OBUF_BASE_OFF, - volatile struct szedata2_cgmii_obuf *); - - cgmii_ibuf_enable(ibuf); - cgmii_obuf_enable(obuf); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) + ibuf_enable(ibuf_ptr_by_index(internals->pci_rsc, i)); + for (i = 0; i < szedata2_obuf_count; i++) + obuf_enable(obuf_ptr_by_index(internals->pci_rsc, i)); return 0; } static int eth_dev_set_link_down(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - volatile struct szedata2_cgmii_obuf *obuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_OBUF_BASE_OFF, - volatile struct szedata2_cgmii_obuf *); - - cgmii_ibuf_disable(ibuf); - cgmii_obuf_disable(obuf); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) + ibuf_disable(ibuf_ptr_by_index(internals->pci_rsc, i)); + for (i = 0; i < szedata2_obuf_count; i++) + obuf_disable(obuf_ptr_by_index(internals->pci_rsc, i)); return 0; } @@ -1214,23 +1251,43 @@ static int eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, uint16_t nb_rx_desc __rte_unused, - unsigned int socket_id __rte_unused, + unsigned int socket_id, const struct rte_eth_rxconf *rx_conf __rte_unused, struct rte_mempool *mb_pool) { struct pmd_internals *internals = dev->data->dev_private; - struct szedata2_rx_queue *rxq = &internals->rx_queue[rx_queue_id]; + struct szedata2_rx_queue *rxq; int ret; uint32_t rx = 1 << rx_queue_id; uint32_t tx = 0; + if (dev->data->rx_queues[rx_queue_id] != NULL) { + eth_rx_queue_release(dev->data->rx_queues[rx_queue_id]); + dev->data->rx_queues[rx_queue_id] = NULL; + } + + rxq = rte_zmalloc_socket("szedata2 rx queue", + sizeof(struct szedata2_rx_queue), + RTE_CACHE_LINE_SIZE, socket_id); + if (rxq == NULL) { + PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for rx queue id " + "%" PRIu16 "!", rx_queue_id); + return -ENOMEM; + } + + rxq->priv = internals; rxq->sze = szedata_open(internals->sze_dev); - if (rxq->sze == NULL) + if (rxq->sze == NULL) { + PMD_INIT_LOG(ERR, "szedata_open() failed for rx queue id " + "%" PRIu16 "!", rx_queue_id); + eth_rx_queue_release(rxq); return -EINVAL; + } ret = szedata_subscribe3(rxq->sze, &rx, &tx); if (ret != 0 || rx == 0) { - szedata_close(rxq->sze); - rxq->sze = NULL; + PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for rx queue id " + "%" PRIu16 "!", rx_queue_id); + eth_rx_queue_release(rxq); return -EINVAL; } rxq->rx_channel = rx_queue_id; @@ -1241,6 +1298,10 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, rxq->err_pkts = 0; dev->data->rx_queues[rx_queue_id] = rxq; + + PMD_INIT_LOG(DEBUG, "Configured rx queue id %" PRIu16 " on socket " + "%u.", rx_queue_id, socket_id); + return 0; } @@ -1248,22 +1309,42 @@ static int eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, uint16_t nb_tx_desc __rte_unused, - unsigned int socket_id __rte_unused, + unsigned int socket_id, const struct rte_eth_txconf *tx_conf __rte_unused) { struct pmd_internals *internals = dev->data->dev_private; - struct szedata2_tx_queue *txq = &internals->tx_queue[tx_queue_id]; + struct szedata2_tx_queue *txq; int ret; uint32_t rx = 0; uint32_t tx = 1 << tx_queue_id; + if (dev->data->tx_queues[tx_queue_id] != NULL) { + eth_tx_queue_release(dev->data->tx_queues[tx_queue_id]); + dev->data->tx_queues[tx_queue_id] = NULL; + } + + txq = rte_zmalloc_socket("szedata2 tx queue", + sizeof(struct szedata2_tx_queue), + RTE_CACHE_LINE_SIZE, socket_id); + if (txq == NULL) { + PMD_INIT_LOG(ERR, "rte_zmalloc_socket() failed for tx queue id " + "%" PRIu16 "!", tx_queue_id); + return -ENOMEM; + } + + txq->priv = internals; txq->sze = szedata_open(internals->sze_dev); - if (txq->sze == NULL) + if (txq->sze == NULL) { + PMD_INIT_LOG(ERR, "szedata_open() failed for tx queue id " + "%" PRIu16 "!", tx_queue_id); + eth_tx_queue_release(txq); return -EINVAL; + } ret = szedata_subscribe3(txq->sze, &rx, &tx); if (ret != 0 || tx == 0) { - szedata_close(txq->sze); - txq->sze = NULL; + PMD_INIT_LOG(ERR, "szedata_subscribe3() failed for tx queue id " + "%" PRIu16 "!", tx_queue_id); + eth_tx_queue_release(txq); return -EINVAL; } txq->tx_channel = tx_queue_id; @@ -1272,49 +1353,70 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, txq->err_pkts = 0; dev->data->tx_queues[tx_queue_id] = txq; + + PMD_INIT_LOG(DEBUG, "Configured tx queue id %" PRIu16 " on socket " + "%u.", tx_queue_id, socket_id); + return 0; } -static void +static int eth_mac_addr_set(struct rte_eth_dev *dev __rte_unused, struct ether_addr *mac_addr __rte_unused) { + return 0; } static void eth_promiscuous_enable(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_PROMISC); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) { + ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i), + SZEDATA2_MAC_CHMODE_PROMISC); + } } static void eth_promiscuous_disable(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) { + ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i), + SZEDATA2_MAC_CHMODE_ONLY_VALID); + } } static void eth_allmulticast_enable(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ALL_MULTICAST); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) { + ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i), + SZEDATA2_MAC_CHMODE_ALL_MULTICAST); + } } static void eth_allmulticast_disable(struct rte_eth_dev *dev) { - volatile struct szedata2_cgmii_ibuf *ibuf = SZEDATA2_PCI_RESOURCE_PTR( - dev, SZEDATA2_CGMII_IBUF_BASE_OFF, - volatile struct szedata2_cgmii_ibuf *); - cgmii_ibuf_mac_mode_write(ibuf, SZEDATA2_MAC_CHMODE_ONLY_VALID); + struct pmd_internals *internals = (struct pmd_internals *) + dev->data->dev_private; + uint32_t i; + + for (i = 0; i < szedata2_ibuf_count; i++) { + ibuf_mac_mode_write(ibuf_ptr_by_index(internals->pci_rsc, i), + SZEDATA2_MAC_CHMODE_ONLY_VALID); + } } static const struct eth_dev_ops ops = { @@ -1352,7 +1454,7 @@ static const struct eth_dev_ops ops = { * -1 on error */ static int -get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index) +get_szedata2_index(const struct rte_pci_addr *pcislot_addr, uint32_t *index) { DIR *dir; struct dirent *entry; @@ -1360,11 +1462,10 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index) uint32_t tmp_index; FILE *fd; char pcislot_path[PATH_MAX]; - struct rte_pci_addr pcislot_addr = dev->pci_dev->addr; uint32_t domain; - uint32_t bus; - uint32_t devid; - uint32_t function; + uint8_t bus; + uint8_t devid; + uint8_t function; dir = opendir("/sys/class/combo"); if (dir == NULL) @@ -1389,16 +1490,16 @@ get_szedata2_index(struct rte_eth_dev *dev, uint32_t *index) if (fd == NULL) continue; - ret = fscanf(fd, "%4" PRIx16 ":%2" PRIx8 ":%2" PRIx8 ".%" PRIx8, + ret = fscanf(fd, "%8" SCNx32 ":%2" SCNx8 ":%2" SCNx8 ".%" SCNx8, &domain, &bus, &devid, &function); fclose(fd); if (ret != 4) continue; - if (pcislot_addr.domain == domain && - pcislot_addr.bus == bus && - pcislot_addr.devid == devid && - pcislot_addr.function == function) { + if (pcislot_addr->domain == domain && + pcislot_addr->bus == bus && + pcislot_addr->devid == devid && + pcislot_addr->function == function) { *index = tmp_index; closedir(dir); return 0; @@ -1418,27 +1519,30 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) struct szedata *szedata_temp; int ret; uint32_t szedata2_index; - struct rte_pci_addr *pci_addr = &dev->pci_dev->addr; - struct rte_pci_resource *pci_rsc = - &dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER]; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_pci_addr *pci_addr = &pci_dev->addr; + struct rte_mem_resource *pci_rsc = + &pci_dev->mem_resource[PCI_RESOURCE_NUMBER]; char rsc_filename[PATH_MAX]; void *pci_resource_ptr = NULL; int fd; - RTE_LOG(INFO, PMD, "Initializing szedata2 device (" PCI_PRI_FMT ")\n", + PMD_INIT_LOG(INFO, "Initializing szedata2 device (" PCI_PRI_FMT ")", pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function); + internals->dev = dev; + /* Get index of szedata2 device file and create path to device file */ - ret = get_szedata2_index(dev, &szedata2_index); + ret = get_szedata2_index(pci_addr, &szedata2_index); if (ret != 0) { - RTE_LOG(ERR, PMD, "Failed to get szedata2 device index!\n"); + PMD_INIT_LOG(ERR, "Failed to get szedata2 device index!"); return -ENODEV; } snprintf(internals->sze_dev, PATH_MAX, SZEDATA2_DEV_PATH_FMT, szedata2_index); - RTE_LOG(INFO, PMD, "SZEDATA2 path: %s\n", internals->sze_dev); + PMD_INIT_LOG(INFO, "SZEDATA2 path: %s", internals->sze_dev); /* * Get number of available DMA RX and TX channels, which is maximum @@ -1447,7 +1551,7 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) */ szedata_temp = szedata_open(internals->sze_dev); if (szedata_temp == NULL) { - RTE_LOG(ERR, PMD, "szedata_open(): failed to open %s", + PMD_INIT_LOG(ERR, "szedata_open(): failed to open %s", internals->sze_dev); return -EINVAL; } @@ -1457,56 +1561,52 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) SZE2_DIR_TX); szedata_close(szedata_temp); - RTE_LOG(INFO, PMD, "Available DMA channels RX: %u TX: %u\n", + PMD_INIT_LOG(INFO, "Available DMA channels RX: %u TX: %u", internals->max_rx_queues, internals->max_tx_queues); /* Set rx, tx burst functions */ - if (data->dev_conf.rxmode.enable_scatter == 1 || - data->scattered_rx == 1) { + if (data->scattered_rx == 1) dev->rx_pkt_burst = eth_szedata2_rx_scattered; - data->scattered_rx = 1; - } else { + else dev->rx_pkt_burst = eth_szedata2_rx; - data->scattered_rx = 0; - } dev->tx_pkt_burst = eth_szedata2_tx; /* Set function callbacks for Ethernet API */ dev->dev_ops = &ops; - rte_eth_copy_pci_info(dev, dev->pci_dev); + rte_eth_copy_pci_info(dev, pci_dev); - /* mmap pci resource0 file to rte_pci_resource structure */ - if (dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr == + /* mmap pci resource0 file to rte_mem_resource structure */ + if (pci_dev->mem_resource[PCI_RESOURCE_NUMBER].phys_addr == 0) { - RTE_LOG(ERR, PMD, "Missing resource%u file\n", + PMD_INIT_LOG(ERR, "Missing resource%u file", PCI_RESOURCE_NUMBER); return -EINVAL; } snprintf(rsc_filename, PATH_MAX, - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/resource%u", + "%s/" PCI_PRI_FMT "/resource%u", rte_pci_get_sysfs_path(), pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function, PCI_RESOURCE_NUMBER); fd = open(rsc_filename, O_RDWR); if (fd < 0) { - RTE_LOG(ERR, PMD, "Could not open file %s\n", rsc_filename); + PMD_INIT_LOG(ERR, "Could not open file %s", rsc_filename); return -EINVAL; } pci_resource_ptr = mmap(0, - dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len, + pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); - if (pci_resource_ptr == NULL) { - RTE_LOG(ERR, PMD, "Could not mmap file %s (fd = %d)\n", + if (pci_resource_ptr == MAP_FAILED) { + PMD_INIT_LOG(ERR, "Could not mmap file %s (fd = %d)", rsc_filename, fd); return -EINVAL; } - dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = - pci_resource_ptr; + pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr = pci_resource_ptr; + internals->pci_rsc = pci_rsc; - RTE_LOG(DEBUG, PMD, "resource%u phys_addr = 0x%llx len = %llu " - "virt addr = %llx\n", PCI_RESOURCE_NUMBER, + PMD_INIT_LOG(DEBUG, "resource%u phys_addr = 0x%llx len = %llu " + "virt addr = %llx", PCI_RESOURCE_NUMBER, (unsigned long long)pci_rsc->phys_addr, (unsigned long long)pci_rsc->len, (unsigned long long)pci_rsc->addr); @@ -1518,9 +1618,9 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) data->mac_addrs = rte_zmalloc(data->name, sizeof(struct ether_addr), RTE_CACHE_LINE_SIZE); if (data->mac_addrs == NULL) { - RTE_LOG(ERR, PMD, "Could not alloc space for MAC address!\n"); - munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr, - dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len); + PMD_INIT_LOG(ERR, "Could not alloc space for MAC address!"); + munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr, + pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len); return -EINVAL; } @@ -1529,8 +1629,8 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) /* At initial state COMBO card is in promiscuous mode so disable it */ eth_promiscuous_disable(dev); - RTE_LOG(INFO, PMD, "szedata2 device (" - PCI_PRI_FMT ") successfully initialized\n", + PMD_INIT_LOG(INFO, "szedata2 device (" + PCI_PRI_FMT ") successfully initialized", pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function); @@ -1540,15 +1640,16 @@ rte_szedata2_eth_dev_init(struct rte_eth_dev *dev) static int rte_szedata2_eth_dev_uninit(struct rte_eth_dev *dev) { - struct rte_pci_addr *pci_addr = &dev->pci_dev->addr; + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); + struct rte_pci_addr *pci_addr = &pci_dev->addr; rte_free(dev->data->mac_addrs); dev->data->mac_addrs = NULL; - munmap(dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr, - dev->pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len); + munmap(pci_dev->mem_resource[PCI_RESOURCE_NUMBER].addr, + pci_dev->mem_resource[PCI_RESOURCE_NUMBER].len); - RTE_LOG(INFO, PMD, "szedata2 device (" - PCI_PRI_FMT ") successfully uninitialized\n", + PMD_DRV_LOG(INFO, "szedata2 device (" + PCI_PRI_FMT ") successfully uninitialized", pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function); @@ -1573,35 +1674,38 @@ static const struct rte_pci_id rte_szedata2_pci_id_table[] = { } }; -static struct eth_driver szedata2_eth_driver = { - .pci_drv = { - .name = RTE_SZEDATA2_PCI_DRIVER_NAME, - .id_table = rte_szedata2_pci_id_table, - }, - .eth_dev_init = rte_szedata2_eth_dev_init, - .eth_dev_uninit = rte_szedata2_eth_dev_uninit, - .dev_private_size = sizeof(struct pmd_internals), -}; - -static int -rte_szedata2_init(const char *name __rte_unused, - const char *args __rte_unused) +static int szedata2_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) { - rte_eth_driver_register(&szedata2_eth_driver); - return 0; + return rte_eth_dev_pci_generic_probe(pci_dev, + sizeof(struct pmd_internals), rte_szedata2_eth_dev_init); } -static int -rte_szedata2_uninit(const char *name __rte_unused) +static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev) { - return 0; + return rte_eth_dev_pci_generic_remove(pci_dev, + rte_szedata2_eth_dev_uninit); } -static struct rte_driver rte_szedata2_driver = { - .type = PMD_PDEV, - .name = RTE_SZEDATA2_DRIVER_NAME, - .init = rte_szedata2_init, - .uninit = rte_szedata2_uninit, +static struct rte_pci_driver szedata2_eth_driver = { + .id_table = rte_szedata2_pci_id_table, + .probe = szedata2_eth_pci_probe, + .remove = szedata2_eth_pci_remove, }; -PMD_REGISTER_DRIVER(rte_szedata2_driver); +RTE_PMD_REGISTER_PCI(RTE_SZEDATA2_DRIVER_NAME, szedata2_eth_driver); +RTE_PMD_REGISTER_PCI_TABLE(RTE_SZEDATA2_DRIVER_NAME, rte_szedata2_pci_id_table); +RTE_PMD_REGISTER_KMOD_DEP(RTE_SZEDATA2_DRIVER_NAME, + "* combo6core & combov3 & szedata2 & szedata2_cv3"); + +RTE_INIT(szedata2_init_log); +static void +szedata2_init_log(void) +{ + szedata2_logtype_init = rte_log_register("pmd.net.szedata2.init"); + if (szedata2_logtype_init >= 0) + rte_log_set_level(szedata2_logtype_init, RTE_LOG_NOTICE); + szedata2_logtype_driver = rte_log_register("pmd.net.szedata2.driver"); + if (szedata2_logtype_driver >= 0) + rte_log_set_level(szedata2_logtype_driver, RTE_LOG_NOTICE); +}