New upstream version 18.02
[deb_dpdk.git] / drivers / net / sfc / sfc_dp.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2017-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #include <sys/queue.h>
11 #include <string.h>
12 #include <errno.h>
13
14 #include <rte_log.h>
15
16 #include "sfc_dp.h"
17
18 void
19 sfc_dp_queue_init(struct sfc_dp_queue *dpq, uint16_t port_id, uint16_t queue_id,
20                   const struct rte_pci_addr *pci_addr)
21 {
22         dpq->port_id = port_id;
23         dpq->queue_id = queue_id;
24         dpq->pci_addr = *pci_addr;
25 }
26
27 struct sfc_dp *
28 sfc_dp_find_by_name(struct sfc_dp_list *head, enum sfc_dp_type type,
29                     const char *name)
30 {
31         struct sfc_dp *entry;
32
33         TAILQ_FOREACH(entry, head, links) {
34                 if (entry->type != type)
35                         continue;
36
37                 if (strcmp(entry->name, name) == 0)
38                         return entry;
39         }
40
41         return NULL;
42 }
43
44 struct sfc_dp *
45 sfc_dp_find_by_caps(struct sfc_dp_list *head, enum sfc_dp_type type,
46                     unsigned int avail_caps)
47 {
48         struct sfc_dp *entry;
49
50         TAILQ_FOREACH(entry, head, links) {
51                 if (entry->type != type)
52                         continue;
53
54                 /* Take the first matching */
55                 if (sfc_dp_match_hw_fw_caps(entry, avail_caps))
56                         return entry;
57         }
58
59         return NULL;
60 }
61
62 int
63 sfc_dp_register(struct sfc_dp_list *head, struct sfc_dp *entry)
64 {
65         if (sfc_dp_find_by_name(head, entry->type, entry->name) != NULL) {
66                 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD,
67                         "sfc %s dapapath '%s' already registered\n",
68                         entry->type == SFC_DP_RX ? "Rx" :
69                         entry->type == SFC_DP_TX ? "Tx" :
70                         "unknown",
71                         entry->name);
72                 return EEXIST;
73         }
74
75         TAILQ_INSERT_TAIL(head, entry, links);
76
77         return 0;
78 }