2559b4c16e9dd350819d45c1c2d43d4f7298cd04
[dpdk.git] / drivers / net / ionic / ionic_lif.c
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  * Copyright(c) 2018-2019 Pensando Systems, Inc. All rights reserved.
3  */
4
5 #include <rte_malloc.h>
6 #include <rte_ethdev_driver.h>
7
8 #include "ionic.h"
9 #include "ionic_logs.h"
10 #include "ionic_lif.h"
11 #include "ionic_ethdev.h"
12
13 int
14 ionic_lif_alloc(struct ionic_lif *lif)
15 {
16         uint32_t socket_id = rte_socket_id();
17
18         snprintf(lif->name, sizeof(lif->name), "lif%u", lif->index);
19
20         IONIC_PRINT(DEBUG, "Allocating Lif Info");
21
22         lif->info_sz = RTE_ALIGN(sizeof(*lif->info), PAGE_SIZE);
23
24         lif->info_z = rte_eth_dma_zone_reserve(lif->eth_dev,
25                 "lif_info", 0 /* queue_idx*/,
26                 lif->info_sz, IONIC_ALIGN, socket_id);
27         if (!lif->info_z) {
28                 IONIC_PRINT(ERR, "Cannot allocate lif info memory");
29                 return -ENOMEM;
30         }
31
32         lif->info = lif->info_z->addr;
33         lif->info_pa = lif->info_z->iova;
34
35         return 0;
36 }
37
38 void
39 ionic_lif_free(struct ionic_lif *lif)
40 {
41         if (lif->info) {
42                 rte_memzone_free(lif->info_z);
43                 lif->info = NULL;
44         }
45 }
46
47 int
48 ionic_lif_init(struct ionic_lif *lif)
49 {
50         struct ionic_dev *idev = &lif->adapter->idev;
51         struct ionic_q_init_comp comp;
52         int err;
53
54         ionic_dev_cmd_lif_init(idev, lif->index, lif->info_pa);
55         err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
56         ionic_dev_cmd_comp(idev, &comp);
57         if (err)
58                 return err;
59
60         lif->hw_index = comp.hw_index;
61
62         lif->state |= IONIC_LIF_F_INITED;
63
64         return 0;
65 }
66
67 void
68 ionic_lif_deinit(struct ionic_lif *lif)
69 {
70         if (!(lif->state & IONIC_LIF_F_INITED))
71                 return;
72
73         lif->state &= ~IONIC_LIF_F_INITED;
74 }
75
76 int
77 ionic_lif_identify(struct ionic_adapter *adapter)
78 {
79         struct ionic_dev *idev = &adapter->idev;
80         struct ionic_identity *ident = &adapter->ident;
81         int err;
82         unsigned int i;
83         unsigned int lif_words = sizeof(ident->lif.words) /
84                 sizeof(ident->lif.words[0]);
85         unsigned int cmd_words = sizeof(idev->dev_cmd->data) /
86                 sizeof(idev->dev_cmd->data[0]);
87         unsigned int nwords;
88
89         ionic_dev_cmd_lif_identify(idev, IONIC_LIF_TYPE_CLASSIC,
90                 IONIC_IDENTITY_VERSION_1);
91         err = ionic_dev_cmd_wait_check(idev, IONIC_DEVCMD_TIMEOUT);
92         if (err)
93                 return (err);
94
95         nwords = RTE_MIN(lif_words, cmd_words);
96         for (i = 0; i < nwords; i++)
97                 ident->lif.words[i] = ioread32(&idev->dev_cmd->data[i]);
98
99         IONIC_PRINT(INFO, "capabilities 0x%" PRIx64 " ",
100                 ident->lif.capabilities);
101
102         IONIC_PRINT(INFO, "eth.max_ucast_filters 0x%" PRIx32 " ",
103                 ident->lif.eth.max_ucast_filters);
104         IONIC_PRINT(INFO, "eth.max_mcast_filters 0x%" PRIx32 " ",
105                 ident->lif.eth.max_mcast_filters);
106
107         IONIC_PRINT(INFO, "eth.features 0x%" PRIx64 " ",
108                 ident->lif.eth.config.features);
109         IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_ADMINQ] 0x%" PRIx32 " ",
110                 ident->lif.eth.config.queue_count[IONIC_QTYPE_ADMINQ]);
111         IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_NOTIFYQ] 0x%" PRIx32 " ",
112                 ident->lif.eth.config.queue_count[IONIC_QTYPE_NOTIFYQ]);
113         IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_RXQ] 0x%" PRIx32 " ",
114                 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ]);
115         IONIC_PRINT(INFO, "eth.queue_count[IONIC_QTYPE_TXQ] 0x%" PRIx32 " ",
116                 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ]);
117
118         return 0;
119 }
120
121 int
122 ionic_lifs_size(struct ionic_adapter *adapter)
123 {
124         struct ionic_identity *ident = &adapter->ident;
125         uint32_t nlifs = ident->dev.nlifs;
126         uint32_t nintrs, dev_nintrs = ident->dev.nintrs;
127
128         adapter->max_ntxqs_per_lif =
129                 ident->lif.eth.config.queue_count[IONIC_QTYPE_TXQ];
130         adapter->max_nrxqs_per_lif =
131                 ident->lif.eth.config.queue_count[IONIC_QTYPE_RXQ];
132
133         nintrs = nlifs * 1 /* notifyq */;
134
135         if (nintrs > dev_nintrs) {
136                 IONIC_PRINT(ERR, "At most %d intr queues supported, minimum required is %u",
137                         dev_nintrs, nintrs);
138                 return -ENOSPC;
139         }
140
141         adapter->nintrs = nintrs;
142
143         return 0;
144 }