New upstream version 18.08
[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 #include "sfc_log.h"
18
19 void
20 sfc_dp_queue_init(struct sfc_dp_queue *dpq, uint16_t port_id, uint16_t queue_id,
21                   const struct rte_pci_addr *pci_addr)
22 {
23         dpq->port_id = port_id;
24         dpq->queue_id = queue_id;
25         dpq->pci_addr = *pci_addr;
26 }
27
28 struct sfc_dp *
29 sfc_dp_find_by_name(struct sfc_dp_list *head, enum sfc_dp_type type,
30                     const char *name)
31 {
32         struct sfc_dp *entry;
33
34         TAILQ_FOREACH(entry, head, links) {
35                 if (entry->type != type)
36                         continue;
37
38                 if (strcmp(entry->name, name) == 0)
39                         return entry;
40         }
41
42         return NULL;
43 }
44
45 struct sfc_dp *
46 sfc_dp_find_by_caps(struct sfc_dp_list *head, enum sfc_dp_type type,
47                     unsigned int avail_caps)
48 {
49         struct sfc_dp *entry;
50
51         TAILQ_FOREACH(entry, head, links) {
52                 if (entry->type != type)
53                         continue;
54
55                 /* Take the first matching */
56                 if (sfc_dp_match_hw_fw_caps(entry, avail_caps))
57                         return entry;
58         }
59
60         return NULL;
61 }
62
63 int
64 sfc_dp_register(struct sfc_dp_list *head, struct sfc_dp *entry)
65 {
66         if (sfc_dp_find_by_name(head, entry->type, entry->name) != NULL) {
67                 SFC_GENERIC_LOG(ERR,
68                         "sfc %s dapapath '%s' already registered",
69                         entry->type == SFC_DP_RX ? "Rx" :
70                         entry->type == SFC_DP_TX ? "Tx" :
71                         "unknown",
72                         entry->name);
73                 return EEXIST;
74         }
75
76         TAILQ_INSERT_TAIL(head, entry, links);
77
78         return 0;
79 }