Skip to content

Commit 1a58e19

Browse files
emuslndavem330
authored andcommitted
ionic: Add basic lif support
The LIF is the Logical Interface, which represents the external connections. The NIC can multiplex many LIFs to a single port, but in most setups, LIF0 is the primary control for the port. Signed-off-by: Shannon Nelson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0443659 commit 1a58e19

File tree

11 files changed

+477
-1
lines changed

11 files changed

+477
-1
lines changed

drivers/net/ethernet/pensando/ionic/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
obj-$(CONFIG_IONIC) := ionic.o
55

66
ionic-y := ionic_main.o ionic_bus_pci.o ionic_devlink.o ionic_dev.o \
7-
ionic_debugfs.o
7+
ionic_debugfs.o ionic_lif.o

drivers/net/ethernet/pensando/ionic/ionic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ struct ionic {
3232
struct ionic_dev_bar bars[IONIC_BARS_MAX];
3333
unsigned int num_bars;
3434
struct ionic_identity ident;
35+
struct list_head lifs;
36+
unsigned int nnqs_per_lif;
37+
unsigned int neqs_per_lif;
38+
unsigned int ntxqs_per_lif;
39+
unsigned int nrxqs_per_lif;
40+
DECLARE_BITMAP(lifbits, IONIC_LIFS_MAX);
41+
unsigned int nintrs;
3542
};
3643

3744
int ionic_dev_cmd_wait(struct ionic *ionic, unsigned long max_wait);

drivers/net/ethernet/pensando/ionic/ionic_bus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define _IONIC_BUS_H_
66

77
const char *ionic_bus_info(struct ionic *ionic);
8+
int ionic_bus_alloc_irq_vectors(struct ionic *ionic, unsigned int nintrs);
9+
void ionic_bus_free_irq_vectors(struct ionic *ionic);
810
int ionic_bus_register_driver(void);
911
void ionic_bus_unregister_driver(void);
1012

drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "ionic.h"
1010
#include "ionic_bus.h"
11+
#include "ionic_lif.h"
1112
#include "ionic_debugfs.h"
1213

1314
/* Supported devices */
@@ -23,6 +24,17 @@ const char *ionic_bus_info(struct ionic *ionic)
2324
return pci_name(ionic->pdev);
2425
}
2526

27+
int ionic_bus_alloc_irq_vectors(struct ionic *ionic, unsigned int nintrs)
28+
{
29+
return pci_alloc_irq_vectors(ionic->pdev, nintrs, nintrs,
30+
PCI_IRQ_MSIX);
31+
}
32+
33+
void ionic_bus_free_irq_vectors(struct ionic *ionic)
34+
{
35+
pci_free_irq_vectors(ionic->pdev);
36+
}
37+
2638
static int ionic_map_bars(struct ionic *ionic)
2739
{
2840
struct pci_dev *pdev = ionic->pdev;
@@ -151,12 +163,44 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
151163
goto err_out_reset;
152164
}
153165

166+
/* Configure LIFs */
167+
err = ionic_lif_identify(ionic, IONIC_LIF_TYPE_CLASSIC,
168+
&ionic->ident.lif);
169+
if (err) {
170+
dev_err(dev, "Cannot identify LIFs: %d, aborting\n", err);
171+
goto err_out_port_reset;
172+
}
173+
174+
err = ionic_lifs_size(ionic);
175+
if (err) {
176+
dev_err(dev, "Cannot size LIFs: %d, aborting\n", err);
177+
goto err_out_port_reset;
178+
}
179+
180+
err = ionic_lifs_alloc(ionic);
181+
if (err) {
182+
dev_err(dev, "Cannot allocate LIFs: %d, aborting\n", err);
183+
goto err_out_free_irqs;
184+
}
185+
186+
err = ionic_lifs_init(ionic);
187+
if (err) {
188+
dev_err(dev, "Cannot init LIFs: %d, aborting\n", err);
189+
goto err_out_free_lifs;
190+
}
191+
154192
err = ionic_devlink_register(ionic);
155193
if (err)
156194
dev_err(dev, "Cannot register devlink: %d\n", err);
157195

158196
return 0;
159197

198+
err_out_free_lifs:
199+
ionic_lifs_free(ionic);
200+
err_out_free_irqs:
201+
ionic_bus_free_irq_vectors(ionic);
202+
err_out_port_reset:
203+
ionic_port_reset(ionic);
160204
err_out_reset:
161205
ionic_reset(ionic);
162206
err_out_teardown:
@@ -185,6 +229,9 @@ static void ionic_remove(struct pci_dev *pdev)
185229
return;
186230

187231
ionic_devlink_unregister(ionic);
232+
ionic_lifs_deinit(ionic);
233+
ionic_lifs_free(ionic);
234+
ionic_bus_free_irq_vectors(ionic);
188235
ionic_port_reset(ionic);
189236
ionic_reset(ionic);
190237
ionic_dev_teardown(ionic);

drivers/net/ethernet/pensando/ionic/ionic_debugfs.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
33

4+
#include <linux/pci.h>
45
#include <linux/netdevice.h>
56

67
#include "ionic.h"
78
#include "ionic_bus.h"
9+
#include "ionic_lif.h"
810
#include "ionic_debugfs.h"
911

1012
#ifdef CONFIG_DEBUG_FS
@@ -58,4 +60,38 @@ void ionic_debugfs_add_ident(struct ionic *ionic)
5860
ionic, &identity_fops) ? 0 : -EOPNOTSUPP;
5961
}
6062

63+
void ionic_debugfs_add_sizes(struct ionic *ionic)
64+
{
65+
debugfs_create_u32("nlifs", 0400, ionic->dentry,
66+
(u32 *)&ionic->ident.dev.nlifs);
67+
debugfs_create_u32("nintrs", 0400, ionic->dentry, &ionic->nintrs);
68+
69+
debugfs_create_u32("ntxqs_per_lif", 0400, ionic->dentry,
70+
(u32 *)&ionic->ident.lif.eth.config.queue_count[IONIC_QTYPE_TXQ]);
71+
debugfs_create_u32("nrxqs_per_lif", 0400, ionic->dentry,
72+
(u32 *)&ionic->ident.lif.eth.config.queue_count[IONIC_QTYPE_RXQ]);
73+
}
74+
75+
static int netdev_show(struct seq_file *seq, void *v)
76+
{
77+
struct net_device *netdev = seq->private;
78+
79+
seq_printf(seq, "%s\n", netdev->name);
80+
81+
return 0;
82+
}
83+
DEFINE_SHOW_ATTRIBUTE(netdev);
84+
85+
void ionic_debugfs_add_lif(struct ionic_lif *lif)
86+
{
87+
lif->dentry = debugfs_create_dir(lif->name, lif->ionic->dentry);
88+
debugfs_create_file("netdev", 0400, lif->dentry,
89+
lif->netdev, &netdev_fops);
90+
}
91+
92+
void ionic_debugfs_del_lif(struct ionic_lif *lif)
93+
{
94+
debugfs_remove_recursive(lif->dentry);
95+
lif->dentry = NULL;
96+
}
6197
#endif

drivers/net/ethernet/pensando/ionic/ionic_debugfs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ void ionic_debugfs_destroy(void);
1313
void ionic_debugfs_add_dev(struct ionic *ionic);
1414
void ionic_debugfs_del_dev(struct ionic *ionic);
1515
void ionic_debugfs_add_ident(struct ionic *ionic);
16+
void ionic_debugfs_add_sizes(struct ionic *ionic);
17+
void ionic_debugfs_add_lif(struct ionic_lif *lif);
18+
void ionic_debugfs_del_lif(struct ionic_lif *lif);
1619
#else
1720
static inline void ionic_debugfs_create(void) { }
1821
static inline void ionic_debugfs_destroy(void) { }
1922
static inline void ionic_debugfs_add_dev(struct ionic *ionic) { }
2023
static inline void ionic_debugfs_del_dev(struct ionic *ionic) { }
2124
static inline void ionic_debugfs_add_ident(struct ionic *ionic) { }
25+
static inline void ionic_debugfs_add_sizes(struct ionic *ionic) { }
26+
static inline void ionic_debugfs_add_lif(struct ionic_lif *lif) { }
27+
static inline void ionic_debugfs_del_lif(struct ionic_lif *lif) { }
2228
#endif
2329

2430
#endif /* _IONIC_DEBUGFS_H_ */

drivers/net/ethernet/pensando/ionic/ionic_dev.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,37 @@ void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type)
226226

227227
ionic_dev_cmd_go(idev, &cmd);
228228
}
229+
230+
/* LIF commands */
231+
void ionic_dev_cmd_lif_identify(struct ionic_dev *idev, u8 type, u8 ver)
232+
{
233+
union ionic_dev_cmd cmd = {
234+
.lif_identify.opcode = IONIC_CMD_LIF_IDENTIFY,
235+
.lif_identify.type = type,
236+
.lif_identify.ver = ver,
237+
};
238+
239+
ionic_dev_cmd_go(idev, &cmd);
240+
}
241+
242+
void ionic_dev_cmd_lif_init(struct ionic_dev *idev, u16 lif_index,
243+
dma_addr_t info_pa)
244+
{
245+
union ionic_dev_cmd cmd = {
246+
.lif_init.opcode = IONIC_CMD_LIF_INIT,
247+
.lif_init.index = cpu_to_le16(lif_index),
248+
.lif_init.info_pa = cpu_to_le64(info_pa),
249+
};
250+
251+
ionic_dev_cmd_go(idev, &cmd);
252+
}
253+
254+
void ionic_dev_cmd_lif_reset(struct ionic_dev *idev, u16 lif_index)
255+
{
256+
union ionic_dev_cmd cmd = {
257+
.lif_init.opcode = IONIC_CMD_LIF_RESET,
258+
.lif_init.index = cpu_to_le16(lif_index),
259+
};
260+
261+
ionic_dev_cmd_go(idev, &cmd);
262+
}

drivers/net/ethernet/pensando/ionic/ionic_dev.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "ionic_if.h"
1111
#include "ionic_regs.h"
1212

13+
#define IONIC_LIFS_MAX 1024
14+
1315
struct ionic_dev_bar {
1416
void __iomem *vaddr;
1517
phys_addr_t bus_addr;
@@ -148,4 +150,9 @@ void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, u8 an_enable);
148150
void ionic_dev_cmd_port_fec(struct ionic_dev *idev, u8 fec_type);
149151
void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type);
150152

153+
void ionic_dev_cmd_lif_identify(struct ionic_dev *idev, u8 type, u8 ver);
154+
void ionic_dev_cmd_lif_init(struct ionic_dev *idev, u16 lif_index,
155+
dma_addr_t addr);
156+
void ionic_dev_cmd_lif_reset(struct ionic_dev *idev, u16 lif_index);
157+
151158
#endif /* _IONIC_DEV_H_ */

0 commit comments

Comments
 (0)