bus/fslmc: reduce the debug log messages
[dpdk.git] / drivers / bus / fslmc / portal / dpaa2_hw_dpbp.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright (c) 2016 NXP. All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Freescale Semiconductor, Inc nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <unistd.h>
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <fcntl.h>
40 #include <errno.h>
41
42 #include <rte_malloc.h>
43 #include <rte_memcpy.h>
44 #include <rte_string_fns.h>
45 #include <rte_cycles.h>
46 #include <rte_kvargs.h>
47 #include <rte_dev.h>
48 #include <rte_ethdev.h>
49
50 #include <fslmc_logs.h>
51 #include <fslmc_vfio.h>
52 #include <mc/fsl_dpbp.h>
53 #include "portal/dpaa2_hw_pvt.h"
54 #include "portal/dpaa2_hw_dpio.h"
55
56 TAILQ_HEAD(dpbp_dev_list, dpaa2_dpbp_dev);
57 static struct dpbp_dev_list dpbp_dev_list
58         = TAILQ_HEAD_INITIALIZER(dpbp_dev_list); /*!< DPBP device list */
59
60 int
61 dpaa2_create_dpbp_device(
62                 int dpbp_id)
63 {
64         struct dpaa2_dpbp_dev *dpbp_node;
65         int ret;
66
67         /* Allocate DPAA2 dpbp handle */
68         dpbp_node = rte_malloc(NULL, sizeof(struct dpaa2_dpbp_dev), 0);
69         if (!dpbp_node) {
70                 PMD_INIT_LOG(ERR, "Memory allocation failed for DPBP Device");
71                 return -1;
72         }
73
74         /* Open the dpbp object */
75         dpbp_node->dpbp.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX];
76         ret = dpbp_open(&dpbp_node->dpbp,
77                         CMD_PRI_LOW, dpbp_id, &dpbp_node->token);
78         if (ret) {
79                 PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d",
80                              ret);
81                 rte_free(dpbp_node);
82                 return -1;
83         }
84
85         /* Clean the device first */
86         ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
87         if (ret) {
88                 PMD_INIT_LOG(ERR, "Failure cleaning dpbp device with"
89                                         " error code %d\n", ret);
90                 dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
91                 rte_free(dpbp_node);
92                 return -1;
93         }
94
95         dpbp_node->dpbp_id = dpbp_id;
96         rte_atomic16_init(&dpbp_node->in_use);
97
98         TAILQ_INSERT_TAIL(&dpbp_dev_list, dpbp_node, next);
99
100         PMD_INIT_LOG(DEBUG, "DPAA2: Added [dpbp-%d]", dpbp_id);
101
102         return 0;
103 }
104
105 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
106 {
107         struct dpaa2_dpbp_dev *dpbp_dev = NULL;
108
109         /* Get DPBP dev handle from list using index */
110         TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
111                 if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
112                         break;
113         }
114
115         return dpbp_dev;
116 }
117
118 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)
119 {
120         struct dpaa2_dpbp_dev *dpbp_dev = NULL;
121
122         /* Match DPBP handle and mark it free */
123         TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
124                 if (dpbp_dev == dpbp) {
125                         rte_atomic16_dec(&dpbp_dev->in_use);
126                         return;
127                 }
128         }
129 }