Skip to content

Commit e850efe

Browse files
burra006anguy11
authored andcommitted
idpf: add module register and probe functionality
Add the required support to register IDPF PCI driver, as well as probe and remove call backs. Enable the PCI device and request the kernel to reserve the memory resources that will be used by the driver. Finally map the BAR0 address space. Signed-off-by: Phani Burra <[email protected]> Co-developed-by: Alan Brady <[email protected]> Signed-off-by: Alan Brady <[email protected]> Co-developed-by: Madhu Chittim <[email protected]> Signed-off-by: Madhu Chittim <[email protected]> Co-developed-by: Shailendra Bhatnagar <[email protected]> Signed-off-by: Shailendra Bhatnagar <[email protected]> Reviewed-by: Sridhar Samudrala <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Co-developed-by: Pavan Kumar Linga <[email protected]> Signed-off-by: Pavan Kumar Linga <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 0d7502a commit e850efe

File tree

5 files changed

+193
-0
lines changed

5 files changed

+193
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
# Copyright (C) 2023 Intel Corporation
3+
4+
# Makefile for Intel(R) Infrastructure Data Path Function Linux Driver
5+
6+
obj-$(CONFIG_IDPF) += idpf.o
7+
8+
idpf-y := \
9+
idpf_main.o
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright (C) 2023 Intel Corporation */
3+
4+
#ifndef _IDPF_H_
5+
#define _IDPF_H_
6+
7+
#include <linux/aer.h>
8+
#include <linux/etherdevice.h>
9+
#include <linux/pci.h>
10+
11+
#include "idpf_controlq.h"
12+
13+
/* available message levels */
14+
#define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
15+
16+
/**
17+
* struct idpf_adapter - Device data struct generated on probe
18+
* @pdev: PCI device struct given on probe
19+
* @msg_enable: Debug message level enabled
20+
* @hw: Device access data
21+
*/
22+
struct idpf_adapter {
23+
struct pci_dev *pdev;
24+
u32 msg_enable;
25+
struct idpf_hw hw;
26+
};
27+
28+
#endif /* !_IDPF_H_ */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright (C) 2023 Intel Corporation */
3+
4+
#ifndef _IDPF_CONTROLQ_H_
5+
#define _IDPF_CONTROLQ_H_
6+
7+
struct idpf_hw {
8+
void __iomem *hw_addr;
9+
resource_size_t hw_addr_len;
10+
11+
struct idpf_adapter *back;
12+
};
13+
14+
#endif /* _IDPF_CONTROLQ_H_ */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright (C) 2023 Intel Corporation */
3+
4+
#ifndef _IDPF_DEVIDS_H_
5+
#define _IDPF_DEVIDS_H_
6+
7+
#define IDPF_DEV_ID_PF 0x1452
8+
#define IDPF_DEV_ID_VF 0x145C
9+
10+
#endif /* _IDPF_DEVIDS_H_ */
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/* Copyright (C) 2023 Intel Corporation */
3+
4+
#include "idpf.h"
5+
#include "idpf_devids.h"
6+
7+
#define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver"
8+
9+
MODULE_DESCRIPTION(DRV_SUMMARY);
10+
MODULE_LICENSE("GPL");
11+
12+
/**
13+
* idpf_remove - Device removal routine
14+
* @pdev: PCI device information struct
15+
*/
16+
static void idpf_remove(struct pci_dev *pdev)
17+
{
18+
struct idpf_adapter *adapter = pci_get_drvdata(pdev);
19+
20+
pci_set_drvdata(pdev, NULL);
21+
kfree(adapter);
22+
}
23+
24+
/**
25+
* idpf_shutdown - PCI callback for shutting down device
26+
* @pdev: PCI device information struct
27+
*/
28+
static void idpf_shutdown(struct pci_dev *pdev)
29+
{
30+
idpf_remove(pdev);
31+
32+
if (system_state == SYSTEM_POWER_OFF)
33+
pci_set_power_state(pdev, PCI_D3hot);
34+
}
35+
36+
/**
37+
* idpf_cfg_hw - Initialize HW struct
38+
* @adapter: adapter to setup hw struct for
39+
*
40+
* Returns 0 on success, negative on failure
41+
*/
42+
static int idpf_cfg_hw(struct idpf_adapter *adapter)
43+
{
44+
struct pci_dev *pdev = adapter->pdev;
45+
struct idpf_hw *hw = &adapter->hw;
46+
47+
hw->hw_addr = pcim_iomap_table(pdev)[0];
48+
if (!hw->hw_addr) {
49+
pci_err(pdev, "failed to allocate PCI iomap table\n");
50+
51+
return -ENOMEM;
52+
}
53+
54+
hw->back = adapter;
55+
56+
return 0;
57+
}
58+
59+
/**
60+
* idpf_probe - Device initialization routine
61+
* @pdev: PCI device information struct
62+
* @ent: entry in idpf_pci_tbl
63+
*
64+
* Returns 0 on success, negative on failure
65+
*/
66+
static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
67+
{
68+
struct device *dev = &pdev->dev;
69+
struct idpf_adapter *adapter;
70+
int err;
71+
72+
adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
73+
if (!adapter)
74+
return -ENOMEM;
75+
adapter->pdev = pdev;
76+
77+
err = pcim_enable_device(pdev);
78+
if (err)
79+
goto err_free;
80+
81+
err = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
82+
if (err) {
83+
pci_err(pdev, "pcim_iomap_regions failed %pe\n", ERR_PTR(err));
84+
85+
goto err_free;
86+
}
87+
88+
/* set up for high or low dma */
89+
err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
90+
if (err) {
91+
pci_err(pdev, "DMA configuration failed: %pe\n", ERR_PTR(err));
92+
93+
goto err_free;
94+
}
95+
96+
pci_set_master(pdev);
97+
pci_set_drvdata(pdev, adapter);
98+
99+
/* setup msglvl */
100+
adapter->msg_enable = netif_msg_init(-1, IDPF_AVAIL_NETIF_M);
101+
102+
err = idpf_cfg_hw(adapter);
103+
if (err) {
104+
dev_err(dev, "Failed to configure HW structure for adapter: %d\n",
105+
err);
106+
goto err_free;
107+
}
108+
109+
return 0;
110+
111+
err_free:
112+
kfree(adapter);
113+
return err;
114+
}
115+
116+
/* idpf_pci_tbl - PCI Dev idpf ID Table
117+
*/
118+
static const struct pci_device_id idpf_pci_tbl[] = {
119+
{ PCI_VDEVICE(INTEL, IDPF_DEV_ID_PF)},
120+
{ PCI_VDEVICE(INTEL, IDPF_DEV_ID_VF)},
121+
{ /* Sentinel */ }
122+
};
123+
MODULE_DEVICE_TABLE(pci, idpf_pci_tbl);
124+
125+
static struct pci_driver idpf_driver = {
126+
.name = KBUILD_MODNAME,
127+
.id_table = idpf_pci_tbl,
128+
.probe = idpf_probe,
129+
.remove = idpf_remove,
130+
.shutdown = idpf_shutdown,
131+
};
132+
module_pci_driver(idpf_driver);

0 commit comments

Comments
 (0)