LCOV - code coverage report
Current view: top level - drivers/bus/dpaa/base/fman - fman.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 358 0.0 %
Date: 2024-01-22 15:55:54 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 215 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
       2                 :            :  *
       3                 :            :  * Copyright 2010-2016 Freescale Semiconductor Inc.
       4                 :            :  * Copyright 2017-2020 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : 
       8                 :            : #include <sys/types.h>
       9                 :            : #include <sys/ioctl.h>
      10                 :            : #include <ifaddrs.h>
      11                 :            : 
      12                 :            : /* This header declares the driver interface we implement */
      13                 :            : #include <fman.h>
      14                 :            : #include <dpaa_of.h>
      15                 :            : #include <rte_malloc.h>
      16                 :            : #include <rte_dpaa_logs.h>
      17                 :            : #include <rte_string_fns.h>
      18                 :            : 
      19                 :            : #define QMI_PORT_REGS_OFFSET            0x400
      20                 :            : 
      21                 :            : /* CCSR map address to access ccsr based register */
      22                 :            : void *fman_ccsr_map;
      23                 :            : /* fman version info */
      24                 :            : u16 fman_ip_rev;
      25                 :            : static int get_once;
      26                 :            : u32 fman_dealloc_bufs_mask_hi;
      27                 :            : u32 fman_dealloc_bufs_mask_lo;
      28                 :            : 
      29                 :            : int fman_ccsr_map_fd = -1;
      30                 :            : static COMPAT_LIST_HEAD(__ifs);
      31                 :            : 
      32                 :            : /* This is the (const) global variable that callers have read-only access to.
      33                 :            :  * Internally, we have read-write access directly to __ifs.
      34                 :            :  */
      35                 :            : const struct list_head *fman_if_list = &__ifs;
      36                 :            : 
      37                 :            : static void
      38                 :          0 : if_destructor(struct __fman_if *__if)
      39                 :            : {
      40                 :            :         struct fman_if_bpool *bp, *tmpbp;
      41                 :            : 
      42         [ #  # ]:          0 :         if (!__if)
      43                 :            :                 return;
      44                 :            : 
      45         [ #  # ]:          0 :         if (__if->__if.mac_type == fman_offline)
      46                 :          0 :                 goto cleanup;
      47                 :            : 
      48         [ #  # ]:          0 :         list_for_each_entry_safe(bp, tmpbp, &__if->__if.bpool_list, node) {
      49                 :          0 :                 list_del(&bp->node);
      50                 :          0 :                 free(bp);
      51                 :            :         }
      52                 :          0 : cleanup:
      53                 :          0 :         rte_free(__if);
      54                 :            : }
      55                 :            : 
      56                 :            : static int
      57                 :          0 : fman_get_ip_rev(const struct device_node *fman_node)
      58                 :            : {
      59                 :            :         const uint32_t *fman_addr;
      60                 :            :         uint64_t phys_addr;
      61                 :            :         uint64_t regs_size;
      62                 :            :         uint32_t ip_rev_1;
      63                 :            :         int _errno;
      64                 :            : 
      65                 :          0 :         fman_addr = of_get_address(fman_node, 0, &regs_size, NULL);
      66         [ #  # ]:          0 :         if (!fman_addr) {
      67                 :          0 :                 pr_err("of_get_address cannot return fman address\n");
      68                 :          0 :                 return -EINVAL;
      69                 :            :         }
      70                 :          0 :         phys_addr = of_translate_address(fman_node, fman_addr);
      71         [ #  # ]:          0 :         if (!phys_addr) {
      72                 :          0 :                 pr_err("of_translate_address failed\n");
      73                 :          0 :                 return -EINVAL;
      74                 :            :         }
      75                 :          0 :         fman_ccsr_map = mmap(NULL, regs_size, PROT_READ | PROT_WRITE,
      76                 :            :                              MAP_SHARED, fman_ccsr_map_fd, phys_addr);
      77         [ #  # ]:          0 :         if (fman_ccsr_map == MAP_FAILED) {
      78                 :          0 :                 pr_err("Can not map FMan ccsr base");
      79                 :          0 :                 return -EINVAL;
      80                 :            :         }
      81                 :            : 
      82                 :            :         ip_rev_1 = in_be32(fman_ccsr_map + FMAN_IP_REV_1);
      83                 :          0 :         fman_ip_rev = (ip_rev_1 & FMAN_IP_REV_1_MAJOR_MASK) >>
      84                 :            :                         FMAN_IP_REV_1_MAJOR_SHIFT;
      85                 :            : 
      86                 :          0 :         _errno = munmap(fman_ccsr_map, regs_size);
      87         [ #  # ]:          0 :         if (_errno)
      88                 :          0 :                 pr_err("munmap() of FMan ccsr failed");
      89                 :            : 
      90                 :            :         return 0;
      91                 :            : }
      92                 :            : 
      93                 :            : static int
      94                 :          0 : fman_get_mac_index(uint64_t regs_addr_host, uint8_t *mac_idx)
      95                 :            : {
      96                 :            :         int ret = 0;
      97                 :            : 
      98                 :            :         /*
      99                 :            :          * MAC1 : E_0000h
     100                 :            :          * MAC2 : E_2000h
     101                 :            :          * MAC3 : E_4000h
     102                 :            :          * MAC4 : E_6000h
     103                 :            :          * MAC5 : E_8000h
     104                 :            :          * MAC6 : E_A000h
     105                 :            :          * MAC7 : E_C000h
     106                 :            :          * MAC8 : E_E000h
     107                 :            :          * MAC9 : F_0000h
     108                 :            :          * MAC10: F_2000h
     109                 :            :          */
     110   [ #  #  #  #  :          0 :         switch (regs_addr_host) {
          #  #  #  #  #  
                   #  # ]
     111                 :          0 :         case 0xE0000:
     112                 :          0 :                 *mac_idx = 1;
     113                 :          0 :                 break;
     114                 :          0 :         case 0xE2000:
     115                 :          0 :                 *mac_idx = 2;
     116                 :          0 :                 break;
     117                 :          0 :         case 0xE4000:
     118                 :          0 :                 *mac_idx = 3;
     119                 :          0 :                 break;
     120                 :          0 :         case 0xE6000:
     121                 :          0 :                 *mac_idx = 4;
     122                 :          0 :                 break;
     123                 :          0 :         case 0xE8000:
     124                 :          0 :                 *mac_idx = 5;
     125                 :          0 :                 break;
     126                 :          0 :         case 0xEA000:
     127                 :          0 :                 *mac_idx = 6;
     128                 :          0 :                 break;
     129                 :          0 :         case 0xEC000:
     130                 :          0 :                 *mac_idx = 7;
     131                 :          0 :                 break;
     132                 :          0 :         case 0xEE000:
     133                 :          0 :                 *mac_idx = 8;
     134                 :          0 :                 break;
     135                 :          0 :         case 0xF0000:
     136                 :          0 :                 *mac_idx = 9;
     137                 :          0 :                 break;
     138                 :          0 :         case 0xF2000:
     139                 :          0 :                 *mac_idx = 10;
     140                 :          0 :                 break;
     141                 :            :         default:
     142                 :            :                 ret = -EINVAL;
     143                 :            :         }
     144                 :            : 
     145                 :          0 :         return ret;
     146                 :            : }
     147                 :            : 
     148                 :          0 : static void fman_if_vsp_init(struct __fman_if *__if)
     149                 :            : {
     150                 :            :         const phandle *prop;
     151                 :            :         int cell_index;
     152                 :            :         const struct device_node *dev;
     153                 :            :         size_t lenp;
     154                 :          0 :         const uint8_t mac_idx[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1};
     155                 :            : 
     156         [ #  # ]:          0 :         if (__if->__if.mac_type == fman_mac_1g) {
     157         [ #  # ]:          0 :                 for_each_compatible_node(dev, NULL,
     158                 :            :                         "fsl,fman-port-1g-rx-extended-args") {
     159                 :          0 :                         prop = of_get_property(dev, "cell-index", &lenp);
     160         [ #  # ]:          0 :                         if (prop) {
     161                 :          0 :                                 cell_index = of_read_number(
     162                 :            :                                                 &prop[0],
     163                 :          0 :                                                 lenp / sizeof(phandle));
     164         [ #  # ]:          0 :                                 if (cell_index == mac_idx[__if->__if.mac_idx]) {
     165                 :          0 :                                         prop = of_get_property(
     166                 :            :                                                         dev,
     167                 :            :                                                         "vsp-window", &lenp);
     168         [ #  # ]:          0 :                                         if (prop) {
     169                 :          0 :                                                 __if->__if.num_profiles =
     170                 :            :                                                         of_read_number(
     171                 :            :                                                                 &prop[0], 1);
     172                 :          0 :                                                 __if->__if.base_profile_id =
     173                 :            :                                                         of_read_number(
     174                 :          0 :                                                                 &prop[1], 1);
     175                 :            :                                         }
     176                 :            :                                 }
     177                 :            :                         }
     178                 :            :                 }
     179         [ #  # ]:          0 :         } else if (__if->__if.mac_type == fman_mac_10g) {
     180         [ #  # ]:          0 :                 for_each_compatible_node(dev, NULL,
     181                 :            :                         "fsl,fman-port-10g-rx-extended-args") {
     182                 :          0 :                         prop = of_get_property(dev, "cell-index", &lenp);
     183         [ #  # ]:          0 :                         if (prop) {
     184                 :          0 :                                 cell_index = of_read_number(
     185                 :          0 :                                         &prop[0], lenp / sizeof(phandle));
     186         [ #  # ]:          0 :                                 if (cell_index == mac_idx[__if->__if.mac_idx]) {
     187                 :          0 :                                         prop = of_get_property(
     188                 :            :                                                 dev, "vsp-window", &lenp);
     189         [ #  # ]:          0 :                                         if (prop) {
     190                 :          0 :                                                 __if->__if.num_profiles =
     191                 :            :                                                         of_read_number(
     192                 :            :                                                                 &prop[0], 1);
     193                 :          0 :                                                 __if->__if.base_profile_id =
     194                 :            :                                                         of_read_number(
     195                 :          0 :                                                                 &prop[1], 1);
     196                 :            :                                         }
     197                 :            :                                 }
     198                 :            :                         }
     199                 :            :                 }
     200                 :            :         }
     201                 :          0 : }
     202                 :            : 
     203                 :            : static int
     204                 :          0 : fman_if_init(const struct device_node *dpa_node)
     205                 :            : {
     206                 :            :         const char *rprop, *mprop;
     207                 :            :         uint64_t phys_addr;
     208                 :            :         struct __fman_if *__if;
     209                 :            :         struct fman_if_bpool *bpool;
     210                 :            : 
     211                 :            :         const phandle *mac_phandle, *ports_phandle, *pools_phandle;
     212                 :            :         const phandle *tx_channel_id = NULL, *mac_addr, *cell_idx;
     213                 :            :         const phandle *rx_phandle, *tx_phandle;
     214                 :            :         const phandle *port_cell_idx, *ext_args_cell_idx;
     215                 :            :         const struct device_node *parent_node_ext_args;
     216                 :            :         uint64_t tx_phandle_host[4] = {0};
     217                 :            :         uint64_t rx_phandle_host[6] = {0};
     218                 :            :         uint64_t regs_addr_host = 0;
     219                 :            :         uint64_t cell_idx_host = 0;
     220                 :            :         uint64_t port_cell_idx_val = 0;
     221                 :            :         uint64_t ext_args_cell_idx_val = 0;
     222                 :            : 
     223                 :            :         const struct device_node *mac_node = NULL, *tx_node, *ext_args_node;
     224                 :            :         const struct device_node *pool_node, *fman_node, *rx_node;
     225                 :            :         const uint32_t *regs_addr = NULL;
     226                 :            :         const char *mname, *fname;
     227                 :          0 :         const char *dname = dpa_node->full_name;
     228                 :            :         size_t lenp;
     229                 :            :         int _errno, is_shared = 0;
     230                 :            :         const char *char_prop;
     231                 :            :         uint32_t na;
     232                 :            : 
     233         [ #  # ]:          0 :         if (of_device_is_available(dpa_node) == false)
     234                 :            :                 return 0;
     235                 :            : 
     236   [ #  #  #  # ]:          0 :         if (!of_device_is_compatible(dpa_node, "fsl,dpa-ethernet-init") &&
     237                 :          0 :                 !of_device_is_compatible(dpa_node, "fsl,dpa-ethernet")) {
     238                 :            :                 return 0;
     239                 :            :         }
     240                 :            : 
     241                 :            :         rprop = "fsl,qman-frame-queues-rx";
     242                 :            :         mprop = "fsl,fman-mac";
     243                 :            : 
     244                 :            :         /* Obtain the MAC node used by this interface except macless */
     245                 :          0 :         mac_phandle = of_get_property(dpa_node, mprop, &lenp);
     246         [ #  # ]:          0 :         if (!mac_phandle) {
     247                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no %s\n", dname, mprop);
     248                 :          0 :                 return -EINVAL;
     249                 :            :         }
     250         [ #  # ]:          0 :         assert(lenp == sizeof(phandle));
     251                 :          0 :         mac_node = of_find_node_by_phandle(*mac_phandle);
     252         [ #  # ]:          0 :         if (!mac_node) {
     253                 :          0 :                 FMAN_ERR(-ENXIO, "%s: bad 'fsl,fman-mac\n", dname);
     254                 :          0 :                 return -ENXIO;
     255                 :            :         }
     256                 :          0 :         mname = mac_node->full_name;
     257                 :            : 
     258                 :            :         /* Extract the Rx and Tx ports */
     259                 :          0 :         ports_phandle = of_get_property(mac_node, "fsl,port-handles",
     260                 :            :                                         &lenp);
     261         [ #  # ]:          0 :         if (!ports_phandle)
     262                 :          0 :                 ports_phandle = of_get_property(mac_node, "fsl,fman-ports",
     263                 :            :                                                 &lenp);
     264         [ #  # ]:          0 :         if (!ports_phandle) {
     265                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no fsl,port-handles\n",
     266                 :            :                          mname);
     267                 :          0 :                 return -EINVAL;
     268                 :            :         }
     269         [ #  # ]:          0 :         assert(lenp == (2 * sizeof(phandle)));
     270                 :          0 :         rx_node = of_find_node_by_phandle(ports_phandle[0]);
     271         [ #  # ]:          0 :         if (!rx_node) {
     272                 :          0 :                 FMAN_ERR(-ENXIO, "%s: bad fsl,port-handle[0]\n", mname);
     273                 :          0 :                 return -ENXIO;
     274                 :            :         }
     275                 :          0 :         tx_node = of_find_node_by_phandle(ports_phandle[1]);
     276         [ #  # ]:          0 :         if (!tx_node) {
     277                 :          0 :                 FMAN_ERR(-ENXIO, "%s: bad fsl,port-handle[1]\n", mname);
     278                 :          0 :                 return -ENXIO;
     279                 :            :         }
     280                 :            : 
     281                 :            :         /* Check if the port is shared interface */
     282         [ #  # ]:          0 :         if (of_device_is_compatible(dpa_node, "fsl,dpa-ethernet")) {
     283                 :          0 :                 port_cell_idx = of_get_property(rx_node, "cell-index", &lenp);
     284         [ #  # ]:          0 :                 if (!port_cell_idx) {
     285                 :          0 :                         FMAN_ERR(-ENXIO,
     286                 :            :                                  "%s: no cell-index for port\n", mname);
     287                 :          0 :                         return -ENXIO;
     288                 :            :                 }
     289         [ #  # ]:          0 :                 assert(lenp == sizeof(*port_cell_idx));
     290                 :            :                 port_cell_idx_val =
     291                 :            :                         of_read_number(port_cell_idx, lenp / sizeof(phandle));
     292                 :            : 
     293         [ #  # ]:          0 :                 if (of_device_is_compatible(rx_node, "fsl,fman-port-1g-rx"))
     294                 :          0 :                         port_cell_idx_val -= 0x8;
     295         [ #  # ]:          0 :                 else if (of_device_is_compatible(
     296                 :            :                                 rx_node, "fsl,fman-port-10g-rx"))
     297                 :          0 :                         port_cell_idx_val -= 0x10;
     298                 :            : 
     299                 :          0 :                 parent_node_ext_args = of_find_compatible_node(NULL,
     300                 :            :                         NULL, "fsl,fman-extended-args");
     301         [ #  # ]:          0 :                 if (!parent_node_ext_args)
     302                 :            :                         return 0;
     303                 :            : 
     304         [ #  # ]:          0 :                 for_each_child_node(parent_node_ext_args, ext_args_node) {
     305                 :          0 :                         ext_args_cell_idx = of_get_property(ext_args_node,
     306                 :            :                                 "cell-index", &lenp);
     307         [ #  # ]:          0 :                         if (!ext_args_cell_idx) {
     308                 :          0 :                                 FMAN_ERR(-ENXIO,
     309                 :            :                                          "%s: no cell-index for ext args\n",
     310                 :            :                                          mname);
     311                 :          0 :                                 return -ENXIO;
     312                 :            :                         }
     313         [ #  # ]:          0 :                         assert(lenp == sizeof(*ext_args_cell_idx));
     314                 :            :                         ext_args_cell_idx_val =
     315                 :            :                                 of_read_number(ext_args_cell_idx, lenp /
     316                 :            :                                 sizeof(phandle));
     317                 :            : 
     318         [ #  # ]:          0 :                         if (port_cell_idx_val == ext_args_cell_idx_val) {
     319         [ #  # ]:          0 :                                 if (of_device_is_compatible(ext_args_node,
     320         [ #  # ]:          0 :                                         "fsl,fman-port-1g-rx-extended-args") &&
     321                 :          0 :                                         of_device_is_compatible(rx_node,
     322                 :            :                                         "fsl,fman-port-1g-rx")) {
     323         [ #  # ]:          0 :                                         if (of_get_property(ext_args_node,
     324                 :            :                                                 "vsp-window", &lenp))
     325                 :            :                                                 is_shared = 1;
     326                 :            :                                         break;
     327                 :            :                                 }
     328         [ #  # ]:          0 :                                 if (of_device_is_compatible(ext_args_node,
     329         [ #  # ]:          0 :                                         "fsl,fman-port-10g-rx-extended-args") &&
     330                 :          0 :                                         of_device_is_compatible(rx_node,
     331                 :            :                                         "fsl,fman-port-10g-rx")) {
     332         [ #  # ]:          0 :                                         if (of_get_property(ext_args_node,
     333                 :            :                                                 "vsp-window", &lenp))
     334                 :            :                                                 is_shared = 1;
     335                 :            :                                         break;
     336                 :            :                                 }
     337                 :            :                         }
     338                 :            :                 }
     339                 :            :                 if (!is_shared)
     340                 :          0 :                         return 0;
     341                 :            :         }
     342                 :            : 
     343                 :            :         /* Allocate an object for this network interface */
     344                 :          0 :         __if = rte_malloc(NULL, sizeof(*__if), RTE_CACHE_LINE_SIZE);
     345         [ #  # ]:          0 :         if (!__if) {
     346                 :          0 :                 FMAN_ERR(-ENOMEM, "malloc(%zu)\n", sizeof(*__if));
     347                 :          0 :                 goto err;
     348                 :            :         }
     349                 :            :         memset(__if, 0, sizeof(*__if));
     350                 :          0 :         INIT_LIST_HEAD(&__if->__if.bpool_list);
     351                 :          0 :         strlcpy(__if->node_name, dpa_node->name, IF_NAME_MAX_LEN - 1);
     352                 :          0 :         __if->node_name[IF_NAME_MAX_LEN - 1] = '\0';
     353                 :          0 :         strlcpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
     354                 :          0 :         __if->node_path[PATH_MAX - 1] = '\0';
     355                 :            : 
     356                 :            :         /* Map the CCSR regs for the MAC node */
     357                 :          0 :         regs_addr = of_get_address(mac_node, 0, &__if->regs_size, NULL);
     358         [ #  # ]:          0 :         if (!regs_addr) {
     359                 :          0 :                 FMAN_ERR(-EINVAL, "of_get_address(%s)\n", mname);
     360                 :          0 :                 goto err;
     361                 :            :         }
     362                 :          0 :         phys_addr = of_translate_address(mac_node, regs_addr);
     363         [ #  # ]:          0 :         if (!phys_addr) {
     364                 :          0 :                 FMAN_ERR(-EINVAL, "of_translate_address(%s, %p)\n",
     365                 :            :                          mname, regs_addr);
     366                 :          0 :                 goto err;
     367                 :            :         }
     368                 :          0 :         __if->ccsr_map = mmap(NULL, __if->regs_size,
     369                 :            :                               PROT_READ | PROT_WRITE, MAP_SHARED,
     370                 :            :                               fman_ccsr_map_fd, phys_addr);
     371         [ #  # ]:          0 :         if (__if->ccsr_map == MAP_FAILED) {
     372                 :          0 :                 FMAN_ERR(-errno, "mmap(0x%"PRIx64")\n", phys_addr);
     373                 :          0 :                 goto err;
     374                 :            :         }
     375                 :          0 :         na = of_n_addr_cells(mac_node);
     376                 :            :         /* Get rid of endianness (issues). Convert to host byte order */
     377                 :          0 :         regs_addr_host = of_read_number(regs_addr, na);
     378                 :            : 
     379                 :            :         /* Get the index of the Fman this i/f belongs to */
     380                 :          0 :         fman_node = of_get_parent(mac_node);
     381                 :          0 :         na = of_n_addr_cells(mac_node);
     382         [ #  # ]:          0 :         if (!fman_node) {
     383                 :          0 :                 FMAN_ERR(-ENXIO, "of_get_parent(%s)\n", mname);
     384                 :          0 :                 goto err;
     385                 :            :         }
     386                 :          0 :         fname = fman_node->full_name;
     387                 :          0 :         cell_idx = of_get_property(fman_node, "cell-index", &lenp);
     388         [ #  # ]:          0 :         if (!cell_idx) {
     389                 :          0 :                 FMAN_ERR(-ENXIO, "%s: no cell-index)\n", fname);
     390                 :          0 :                 goto err;
     391                 :            :         }
     392         [ #  # ]:          0 :         assert(lenp == sizeof(*cell_idx));
     393                 :            :         cell_idx_host = of_read_number(cell_idx, lenp / sizeof(phandle));
     394                 :          0 :         __if->__if.fman_idx = cell_idx_host;
     395         [ #  # ]:          0 :         if (!get_once) {
     396                 :          0 :                 _errno = fman_get_ip_rev(fman_node);
     397         [ #  # ]:          0 :                 if (_errno) {
     398                 :          0 :                         FMAN_ERR(-ENXIO, "%s: ip_rev is not available\n",
     399                 :            :                                  fname);
     400                 :          0 :                         goto err;
     401                 :            :                 }
     402                 :            :         }
     403                 :            : 
     404         [ #  # ]:          0 :         if (fman_ip_rev >= FMAN_V3) {
     405                 :            :                 /*
     406                 :            :                  * Set A2V, OVOM, EBD bits in contextA to allow external
     407                 :            :                  * buffer deallocation by fman.
     408                 :            :                  */
     409                 :          0 :                 fman_dealloc_bufs_mask_hi = FMAN_V3_CONTEXTA_EN_A2V |
     410                 :            :                                                 FMAN_V3_CONTEXTA_EN_OVOM;
     411                 :          0 :                 fman_dealloc_bufs_mask_lo = FMAN_V3_CONTEXTA_EN_EBD;
     412                 :            :         } else {
     413                 :          0 :                 fman_dealloc_bufs_mask_hi = 0;
     414                 :          0 :                 fman_dealloc_bufs_mask_lo = 0;
     415                 :            :         }
     416                 :            :         /* Is the MAC node 1G, 2.5G, 10G? */
     417                 :          0 :         __if->__if.is_memac = 0;
     418                 :            : 
     419         [ #  # ]:          0 :         if (of_device_is_compatible(mac_node, "fsl,fman-1g-mac"))
     420                 :          0 :                 __if->__if.mac_type = fman_mac_1g;
     421         [ #  # ]:          0 :         else if (of_device_is_compatible(mac_node, "fsl,fman-10g-mac"))
     422                 :          0 :                 __if->__if.mac_type = fman_mac_10g;
     423         [ #  # ]:          0 :         else if (of_device_is_compatible(mac_node, "fsl,fman-memac")) {
     424                 :          0 :                 __if->__if.is_memac = 1;
     425                 :          0 :                 char_prop = of_get_property(mac_node, "phy-connection-type",
     426                 :            :                                             NULL);
     427         [ #  # ]:          0 :                 if (!char_prop) {
     428                 :            :                         printf("memac: unknown MII type assuming 1G\n");
     429                 :            :                         /* Right now forcing memac to 1g in case of error*/
     430                 :          0 :                         __if->__if.mac_type = fman_mac_1g;
     431                 :            :                 } else {
     432         [ #  # ]:          0 :                         if (strstr(char_prop, "sgmii-2500"))
     433                 :          0 :                                 __if->__if.mac_type = fman_mac_2_5g;
     434         [ #  # ]:          0 :                         else if (strstr(char_prop, "sgmii"))
     435                 :          0 :                                 __if->__if.mac_type = fman_mac_1g;
     436         [ #  # ]:          0 :                         else if (strstr(char_prop, "rgmii")) {
     437                 :          0 :                                 __if->__if.mac_type = fman_mac_1g;
     438                 :          0 :                                 __if->__if.is_rgmii = 1;
     439         [ #  # ]:          0 :                         } else if (strstr(char_prop, "xgmii"))
     440                 :          0 :                                 __if->__if.mac_type = fman_mac_10g;
     441                 :            :                 }
     442                 :            :         } else {
     443                 :          0 :                 FMAN_ERR(-EINVAL, "%s: unknown MAC type\n", mname);
     444                 :          0 :                 goto err;
     445                 :            :         }
     446                 :            : 
     447                 :            :         /*
     448                 :            :          * For MAC ports, we cannot rely on cell-index. In
     449                 :            :          * T2080, two of the 10G ports on single FMAN have same
     450                 :            :          * duplicate cell-indexes as the other two 10G ports on
     451                 :            :          * same FMAN. Hence, we now rely upon addresses of the
     452                 :            :          * ports from device tree to deduce the index.
     453                 :            :          */
     454                 :            : 
     455                 :          0 :         _errno = fman_get_mac_index(regs_addr_host, &__if->__if.mac_idx);
     456         [ #  # ]:          0 :         if (_errno) {
     457                 :          0 :                 FMAN_ERR(-EINVAL, "Invalid register address: %" PRIx64,
     458                 :            :                          regs_addr_host);
     459                 :          0 :                 goto err;
     460                 :            :         }
     461                 :            : 
     462                 :            :         /* Extract the MAC address for private and shared interfaces */
     463                 :          0 :         mac_addr = of_get_property(mac_node, "local-mac-address",
     464                 :            :                                    &lenp);
     465         [ #  # ]:          0 :         if (!mac_addr) {
     466                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no local-mac-address\n",
     467                 :            :                          mname);
     468                 :          0 :                 goto err;
     469                 :            :         }
     470                 :          0 :         memcpy(&__if->__if.mac_addr, mac_addr, ETHER_ADDR_LEN);
     471                 :            : 
     472                 :            :         /* Extract the channel ID (from tx-port-handle) */
     473                 :          0 :         tx_channel_id = of_get_property(tx_node, "fsl,qman-channel-id",
     474                 :            :                                         &lenp);
     475         [ #  # ]:          0 :         if (!tx_channel_id) {
     476                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no fsl-qman-channel-id\n",
     477                 :            :                          tx_node->full_name);
     478                 :          0 :                 goto err;
     479                 :            :         }
     480                 :            : 
     481                 :          0 :         regs_addr = of_get_address(rx_node, 0, &__if->regs_size, NULL);
     482         [ #  # ]:          0 :         if (!regs_addr) {
     483                 :          0 :                 FMAN_ERR(-EINVAL, "of_get_address(%s)\n", mname);
     484                 :          0 :                 goto err;
     485                 :            :         }
     486                 :          0 :         phys_addr = of_translate_address(rx_node, regs_addr);
     487         [ #  # ]:          0 :         if (!phys_addr) {
     488                 :          0 :                 FMAN_ERR(-EINVAL, "of_translate_address(%s, %p)\n",
     489                 :            :                          mname, regs_addr);
     490                 :          0 :                 goto err;
     491                 :            :         }
     492                 :          0 :         __if->bmi_map = mmap(NULL, __if->regs_size,
     493                 :            :                                  PROT_READ | PROT_WRITE, MAP_SHARED,
     494                 :            :                                  fman_ccsr_map_fd, phys_addr);
     495         [ #  # ]:          0 :         if (__if->bmi_map == MAP_FAILED) {
     496                 :          0 :                 FMAN_ERR(-errno, "mmap(0x%"PRIx64")\n", phys_addr);
     497                 :          0 :                 goto err;
     498                 :            :         }
     499                 :            : 
     500                 :            :         /* No channel ID for MAC-less */
     501         [ #  # ]:          0 :         assert(lenp == sizeof(*tx_channel_id));
     502                 :          0 :         na = of_n_addr_cells(mac_node);
     503                 :          0 :         __if->__if.tx_channel_id = of_read_number(tx_channel_id, na);
     504                 :            : 
     505                 :            :         /* Extract the Rx FQIDs. (Note, the device representation is silly,
     506                 :            :          * there are "counts" that must always be 1.)
     507                 :            :          */
     508                 :          0 :         rx_phandle = of_get_property(dpa_node, rprop, &lenp);
     509         [ #  # ]:          0 :         if (!rx_phandle) {
     510                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no fsl,qman-frame-queues-rx\n", dname);
     511                 :          0 :                 goto err;
     512                 :            :         }
     513                 :            : 
     514                 :            :         /* Check if "fsl,qman-frame-queues-rx" in dtb file is valid entry or
     515                 :            :          * not. A valid entry contains at least 4 entries, rx_error_queue,
     516                 :            :          * rx_error_queue_count, fqid_rx_def and rx_error_queue_count.
     517                 :            :          */
     518         [ #  # ]:          0 :         assert(lenp >= (4 * sizeof(phandle)));
     519                 :            : 
     520                 :          0 :         na = of_n_addr_cells(mac_node);
     521                 :            :         /* Get rid of endianness (issues). Convert to host byte order */
     522                 :          0 :         rx_phandle_host[0] = of_read_number(&rx_phandle[0], na);
     523                 :          0 :         rx_phandle_host[1] = of_read_number(&rx_phandle[1], na);
     524                 :          0 :         rx_phandle_host[2] = of_read_number(&rx_phandle[2], na);
     525                 :          0 :         rx_phandle_host[3] = of_read_number(&rx_phandle[3], na);
     526                 :          0 :         rx_phandle_host[4] = of_read_number(&rx_phandle[4], na);
     527                 :          0 :         rx_phandle_host[5] = of_read_number(&rx_phandle[5], na);
     528                 :            : 
     529   [ #  #  #  # ]:          0 :         assert((rx_phandle_host[1] == 1) && (rx_phandle_host[3] == 1));
     530                 :          0 :         __if->__if.fqid_rx_err = rx_phandle_host[0];
     531                 :          0 :         __if->__if.fqid_rx_def = rx_phandle_host[2];
     532                 :            : 
     533                 :            :         /* If there are 6 entries in "fsl,qman-frame-queues-rx" in dtb file, it
     534                 :            :          * means PCD queues are also available. Hence, store that information.
     535                 :            :          */
     536         [ #  # ]:          0 :         if (lenp == 6 * sizeof(phandle)) {
     537                 :          0 :                 __if->__if.fqid_rx_pcd = rx_phandle_host[4];
     538                 :          0 :                 __if->__if.fqid_rx_pcd_count = rx_phandle_host[5];
     539                 :            :         }
     540                 :            : 
     541                 :            :         /* Extract the Tx FQIDs */
     542                 :          0 :         tx_phandle = of_get_property(dpa_node,
     543                 :            :                                      "fsl,qman-frame-queues-tx", &lenp);
     544         [ #  # ]:          0 :         if (!tx_phandle) {
     545                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no fsl,qman-frame-queues-tx\n", dname);
     546                 :          0 :                 goto err;
     547                 :            :         }
     548                 :            : 
     549         [ #  # ]:          0 :         assert(lenp >= (4 * sizeof(phandle)));
     550                 :            :         /*TODO: Fix for other cases also */
     551                 :          0 :         na = of_n_addr_cells(mac_node);
     552                 :            :         /* Get rid of endianness (issues). Convert to host byte order */
     553                 :          0 :         tx_phandle_host[0] = of_read_number(&tx_phandle[0], na);
     554                 :          0 :         tx_phandle_host[1] = of_read_number(&tx_phandle[1], na);
     555                 :          0 :         tx_phandle_host[2] = of_read_number(&tx_phandle[2], na);
     556                 :          0 :         tx_phandle_host[3] = of_read_number(&tx_phandle[3], na);
     557   [ #  #  #  # ]:          0 :         assert((tx_phandle_host[1] == 1) && (tx_phandle_host[3] == 1));
     558                 :          0 :         __if->__if.fqid_tx_err = tx_phandle_host[0];
     559                 :          0 :         __if->__if.fqid_tx_confirm = tx_phandle_host[2];
     560                 :            : 
     561                 :            :         /* Obtain the buffer pool nodes used by this interface */
     562                 :          0 :         pools_phandle = of_get_property(dpa_node, "fsl,bman-buffer-pools",
     563                 :            :                                         &lenp);
     564         [ #  # ]:          0 :         if (!pools_phandle) {
     565                 :          0 :                 FMAN_ERR(-EINVAL, "%s: no fsl,bman-buffer-pools\n", dname);
     566                 :          0 :                 goto err;
     567                 :            :         }
     568                 :            :         /* For each pool, parse the corresponding node and add a pool object
     569                 :            :          * to the interface's "bpool_list"
     570                 :            :          */
     571   [ #  #  #  # ]:          0 :         assert(lenp && !(lenp % sizeof(phandle)));
     572         [ #  # ]:          0 :         while (lenp) {
     573                 :            :                 size_t proplen;
     574                 :            :                 const phandle *prop;
     575                 :            :                 uint64_t bpid_host = 0;
     576                 :            :                 uint64_t bpool_host[6] = {0};
     577                 :            :                 const char *pname;
     578                 :            :                 /* Allocate an object for the pool */
     579                 :          0 :                 bpool = rte_malloc(NULL, sizeof(*bpool), RTE_CACHE_LINE_SIZE);
     580         [ #  # ]:          0 :                 if (!bpool) {
     581                 :          0 :                         FMAN_ERR(-ENOMEM, "malloc(%zu)\n", sizeof(*bpool));
     582                 :          0 :                         goto err;
     583                 :            :                 }
     584                 :            :                 /* Find the pool node */
     585                 :          0 :                 pool_node = of_find_node_by_phandle(*pools_phandle);
     586         [ #  # ]:          0 :                 if (!pool_node) {
     587                 :          0 :                         FMAN_ERR(-ENXIO, "%s: bad fsl,bman-buffer-pools\n",
     588                 :            :                                  dname);
     589                 :          0 :                         rte_free(bpool);
     590                 :          0 :                         goto err;
     591                 :            :                 }
     592                 :          0 :                 pname = pool_node->full_name;
     593                 :            :                 /* Extract the BPID property */
     594                 :          0 :                 prop = of_get_property(pool_node, "fsl,bpid", &proplen);
     595         [ #  # ]:          0 :                 if (!prop) {
     596                 :          0 :                         FMAN_ERR(-EINVAL, "%s: no fsl,bpid\n", pname);
     597                 :          0 :                         rte_free(bpool);
     598                 :          0 :                         goto err;
     599                 :            :                 }
     600         [ #  # ]:          0 :                 assert(proplen == sizeof(*prop));
     601                 :          0 :                 na = of_n_addr_cells(mac_node);
     602                 :            :                 /* Get rid of endianness (issues).
     603                 :            :                  * Convert to host byte-order
     604                 :            :                  */
     605                 :          0 :                 bpid_host = of_read_number(prop, na);
     606                 :          0 :                 bpool->bpid = bpid_host;
     607                 :            :                 /* Extract the cfg property (count/size/addr). "fsl,bpool-cfg"
     608                 :            :                  * indicates for the Bman driver to seed the pool.
     609                 :            :                  * "fsl,bpool-ethernet-cfg" is used by the network driver. The
     610                 :            :                  * two are mutually exclusive, so check for either of them.
     611                 :            :                  */
     612                 :          0 :                 prop = of_get_property(pool_node, "fsl,bpool-cfg",
     613                 :            :                                        &proplen);
     614         [ #  # ]:          0 :                 if (!prop)
     615                 :          0 :                         prop = of_get_property(pool_node,
     616                 :            :                                                "fsl,bpool-ethernet-cfg",
     617                 :            :                                                &proplen);
     618         [ #  # ]:          0 :                 if (!prop) {
     619                 :            :                         /* It's OK for there to be no bpool-cfg */
     620                 :          0 :                         bpool->count = bpool->size = bpool->addr = 0;
     621                 :            :                 } else {
     622         [ #  # ]:          0 :                         assert(proplen == (6 * sizeof(*prop)));
     623                 :          0 :                         na = of_n_addr_cells(mac_node);
     624                 :            :                         /* Get rid of endianness (issues).
     625                 :            :                          * Convert to host byte order
     626                 :            :                          */
     627                 :          0 :                         bpool_host[0] = of_read_number(&prop[0], na);
     628                 :          0 :                         bpool_host[1] = of_read_number(&prop[1], na);
     629                 :          0 :                         bpool_host[2] = of_read_number(&prop[2], na);
     630                 :          0 :                         bpool_host[3] = of_read_number(&prop[3], na);
     631                 :          0 :                         bpool_host[4] = of_read_number(&prop[4], na);
     632                 :          0 :                         bpool_host[5] = of_read_number(&prop[5], na);
     633                 :            : 
     634                 :          0 :                         bpool->count = ((uint64_t)bpool_host[0] << 32) |
     635                 :            :                                         bpool_host[1];
     636                 :          0 :                         bpool->size = ((uint64_t)bpool_host[2] << 32) |
     637                 :            :                                         bpool_host[3];
     638                 :          0 :                         bpool->addr = ((uint64_t)bpool_host[4] << 32) |
     639                 :            :                                         bpool_host[5];
     640                 :            :                 }
     641                 :            :                 /* Parsing of the pool is complete, add it to the interface
     642                 :            :                  * list.
     643                 :            :                  */
     644                 :          0 :                 list_add_tail(&bpool->node, &__if->__if.bpool_list);
     645                 :          0 :                 lenp -= sizeof(phandle);
     646                 :          0 :                 pools_phandle++;
     647                 :            :         }
     648                 :            : 
     649         [ #  # ]:          0 :         if (is_shared)
     650                 :          0 :                 __if->__if.is_shared_mac = 1;
     651                 :            : 
     652                 :          0 :         fman_if_vsp_init(__if);
     653                 :            : 
     654                 :            :         /* Parsing of the network interface is complete, add it to the list */
     655                 :          0 :         DPAA_BUS_LOG(DEBUG, "Found %s, Tx Channel = %x, FMAN = %x,"
     656                 :            :                     "Port ID = %x",
     657                 :            :                     dname, __if->__if.tx_channel_id, __if->__if.fman_idx,
     658                 :            :                     __if->__if.mac_idx);
     659                 :            : 
     660                 :          0 :         list_add_tail(&__if->__if.node, &__ifs);
     661                 :          0 :         return 0;
     662                 :          0 : err:
     663                 :          0 :         if_destructor(__if);
     664                 :          0 :         return _errno;
     665                 :            : }
     666                 :            : 
     667                 :            : int
     668                 :          0 : fman_init(void)
     669                 :            : {
     670                 :            :         const struct device_node *dpa_node, *parent_node;
     671                 :            :         int _errno;
     672                 :            : 
     673                 :            :         /* If multiple dependencies try to initialise the Fman driver, don't
     674                 :            :          * panic.
     675                 :            :          */
     676         [ #  # ]:          0 :         if (fman_ccsr_map_fd != -1)
     677                 :            :                 return 0;
     678                 :            : 
     679                 :          0 :         fman_ccsr_map_fd = open(FMAN_DEVICE_PATH, O_RDWR);
     680         [ #  # ]:          0 :         if (unlikely(fman_ccsr_map_fd < 0)) {
     681                 :          0 :                 DPAA_BUS_LOG(ERR, "Unable to open (/dev/mem)");
     682                 :          0 :                 return fman_ccsr_map_fd;
     683                 :            :         }
     684                 :            : 
     685                 :          0 :         parent_node = of_find_compatible_node(NULL, NULL, "fsl,dpaa");
     686         [ #  # ]:          0 :         if (!parent_node) {
     687                 :          0 :                 DPAA_BUS_LOG(ERR, "Unable to find fsl,dpaa node");
     688                 :          0 :                 return -ENODEV;
     689                 :            :         }
     690                 :            : 
     691         [ #  # ]:          0 :         for_each_child_node(parent_node, dpa_node) {
     692                 :          0 :                 _errno = fman_if_init(dpa_node);
     693         [ #  # ]:          0 :                 if (_errno) {
     694                 :          0 :                         FMAN_ERR(_errno, "if_init(%s)\n", dpa_node->full_name);
     695                 :          0 :                         goto err;
     696                 :            :                 }
     697                 :            :         }
     698                 :            : 
     699                 :            :         return 0;
     700                 :            : err:
     701                 :          0 :         fman_finish();
     702                 :          0 :         return _errno;
     703                 :            : }
     704                 :            : 
     705                 :            : void
     706                 :          0 : fman_finish(void)
     707                 :            : {
     708                 :            :         struct __fman_if *__if, *tmpif;
     709                 :            : 
     710         [ #  # ]:          0 :         assert(fman_ccsr_map_fd != -1);
     711                 :            : 
     712         [ #  # ]:          0 :         list_for_each_entry_safe(__if, tmpif, &__ifs, __if.node) {
     713                 :            :                 int _errno;
     714                 :            : 
     715                 :            :                 /* disable Rx and Tx */
     716         [ #  # ]:          0 :                 if ((__if->__if.mac_type == fman_mac_1g) &&
     717         [ #  # ]:          0 :                     (!__if->__if.is_memac))
     718         [ #  # ]:          0 :                         out_be32(__if->ccsr_map + 0x100,
     719                 :          0 :                                  in_be32(__if->ccsr_map + 0x100) & ~(u32)0x5);
     720                 :            :                 else
     721         [ #  # ]:          0 :                         out_be32(__if->ccsr_map + 8,
     722                 :          0 :                                  in_be32(__if->ccsr_map + 8) & ~(u32)3);
     723                 :            :                 /* release the mapping */
     724                 :          0 :                 _errno = munmap(__if->ccsr_map, __if->regs_size);
     725         [ #  # ]:          0 :                 if (unlikely(_errno < 0))
     726                 :          0 :                         fprintf(stderr, "%s:%d:%s(): munmap() = %d (%s)\n",
     727                 :            :                                 __FILE__, __LINE__, __func__,
     728                 :          0 :                                 -errno, strerror(errno));
     729                 :          0 :                 printf("Tearing down %s\n", __if->node_path);
     730                 :          0 :                 list_del(&__if->__if.node);
     731                 :          0 :                 rte_free(__if);
     732                 :            :         }
     733                 :            : 
     734                 :          0 :         close(fman_ccsr_map_fd);
     735                 :          0 :         fman_ccsr_map_fd = -1;
     736                 :          0 : }

Generated by: LCOV version 1.14