Skip to content

Commit

Permalink
idpf: add module register and probe functionality
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
burra006 authored and anguy11 committed Sep 13, 2023
1 parent 0d7502a commit e850efe
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/net/ethernet/intel/idpf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2023 Intel Corporation

# Makefile for Intel(R) Infrastructure Data Path Function Linux Driver

obj-$(CONFIG_IDPF) += idpf.o

idpf-y := \
idpf_main.o
28 changes: 28 additions & 0 deletions drivers/net/ethernet/intel/idpf/idpf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2023 Intel Corporation */

#ifndef _IDPF_H_
#define _IDPF_H_

#include <linux/aer.h>
#include <linux/etherdevice.h>
#include <linux/pci.h>

#include "idpf_controlq.h"

/* available message levels */
#define IDPF_AVAIL_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)

/**
* struct idpf_adapter - Device data struct generated on probe
* @pdev: PCI device struct given on probe
* @msg_enable: Debug message level enabled
* @hw: Device access data
*/
struct idpf_adapter {
struct pci_dev *pdev;
u32 msg_enable;
struct idpf_hw hw;
};

#endif /* !_IDPF_H_ */
14 changes: 14 additions & 0 deletions drivers/net/ethernet/intel/idpf/idpf_controlq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2023 Intel Corporation */

#ifndef _IDPF_CONTROLQ_H_
#define _IDPF_CONTROLQ_H_

struct idpf_hw {
void __iomem *hw_addr;
resource_size_t hw_addr_len;

struct idpf_adapter *back;
};

#endif /* _IDPF_CONTROLQ_H_ */
10 changes: 10 additions & 0 deletions drivers/net/ethernet/intel/idpf/idpf_devids.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2023 Intel Corporation */

#ifndef _IDPF_DEVIDS_H_
#define _IDPF_DEVIDS_H_

#define IDPF_DEV_ID_PF 0x1452
#define IDPF_DEV_ID_VF 0x145C

#endif /* _IDPF_DEVIDS_H_ */
132 changes: 132 additions & 0 deletions drivers/net/ethernet/intel/idpf/idpf_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (C) 2023 Intel Corporation */

#include "idpf.h"
#include "idpf_devids.h"

#define DRV_SUMMARY "Intel(R) Infrastructure Data Path Function Linux Driver"

MODULE_DESCRIPTION(DRV_SUMMARY);
MODULE_LICENSE("GPL");

/**
* idpf_remove - Device removal routine
* @pdev: PCI device information struct
*/
static void idpf_remove(struct pci_dev *pdev)
{
struct idpf_adapter *adapter = pci_get_drvdata(pdev);

pci_set_drvdata(pdev, NULL);
kfree(adapter);
}

/**
* idpf_shutdown - PCI callback for shutting down device
* @pdev: PCI device information struct
*/
static void idpf_shutdown(struct pci_dev *pdev)
{
idpf_remove(pdev);

if (system_state == SYSTEM_POWER_OFF)
pci_set_power_state(pdev, PCI_D3hot);
}

/**
* idpf_cfg_hw - Initialize HW struct
* @adapter: adapter to setup hw struct for
*
* Returns 0 on success, negative on failure
*/
static int idpf_cfg_hw(struct idpf_adapter *adapter)
{
struct pci_dev *pdev = adapter->pdev;
struct idpf_hw *hw = &adapter->hw;

hw->hw_addr = pcim_iomap_table(pdev)[0];
if (!hw->hw_addr) {
pci_err(pdev, "failed to allocate PCI iomap table\n");

return -ENOMEM;
}

hw->back = adapter;

return 0;
}

/**
* idpf_probe - Device initialization routine
* @pdev: PCI device information struct
* @ent: entry in idpf_pci_tbl
*
* Returns 0 on success, negative on failure
*/
static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
struct device *dev = &pdev->dev;
struct idpf_adapter *adapter;
int err;

adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
if (!adapter)
return -ENOMEM;
adapter->pdev = pdev;

err = pcim_enable_device(pdev);
if (err)
goto err_free;

err = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
if (err) {
pci_err(pdev, "pcim_iomap_regions failed %pe\n", ERR_PTR(err));

goto err_free;
}

/* set up for high or low dma */
err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
if (err) {
pci_err(pdev, "DMA configuration failed: %pe\n", ERR_PTR(err));

goto err_free;
}

pci_set_master(pdev);
pci_set_drvdata(pdev, adapter);

/* setup msglvl */
adapter->msg_enable = netif_msg_init(-1, IDPF_AVAIL_NETIF_M);

err = idpf_cfg_hw(adapter);
if (err) {
dev_err(dev, "Failed to configure HW structure for adapter: %d\n",
err);
goto err_free;
}

return 0;

err_free:
kfree(adapter);
return err;
}

/* idpf_pci_tbl - PCI Dev idpf ID Table
*/
static const struct pci_device_id idpf_pci_tbl[] = {
{ PCI_VDEVICE(INTEL, IDPF_DEV_ID_PF)},
{ PCI_VDEVICE(INTEL, IDPF_DEV_ID_VF)},
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(pci, idpf_pci_tbl);

static struct pci_driver idpf_driver = {
.name = KBUILD_MODNAME,
.id_table = idpf_pci_tbl,
.probe = idpf_probe,
.remove = idpf_remove,
.shutdown = idpf_shutdown,
};
module_pci_driver(idpf_driver);

0 comments on commit e850efe

Please sign in to comment.