cndm: Register misc device

Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
Alex Forencich
2025-12-31 23:48:50 -08:00
parent 96e24756de
commit cc4e465462
4 changed files with 61 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ ifneq ($(KERNELRELEASE),)
obj-m += cndm.o obj-m += cndm.o
cndm-y += cndm_main.o cndm-y += cndm_main.o
cndm-y += cndm_devlink.o cndm-y += cndm_devlink.o
cndm-y += cndm_dev.o
cndm-y += cndm_netdev.o cndm-y += cndm_netdev.o
cndm-y += cndm_tx.o cndm-y += cndm_tx.o
cndm-y += cndm_rx.o cndm-y += cndm_rx.o

View File

@@ -13,6 +13,7 @@ Authors:
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/miscdevice.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/ptp_clock_kernel.h> #include <linux/ptp_clock_kernel.h>
@@ -28,6 +29,8 @@ struct cndm_dev {
unsigned int id; unsigned int id;
char name[16]; char name[16];
struct miscdevice misc_dev;
struct net_device *ndev[32]; struct net_device *ndev[32];
void __iomem *bar; void __iomem *bar;
@@ -135,6 +138,9 @@ irqreturn_t cndm_irq(int irqn, void *data);
struct net_device *cndm_create_netdev(struct cndm_dev *cdev, int port, void __iomem *hw_addr); struct net_device *cndm_create_netdev(struct cndm_dev *cdev, int port, void __iomem *hw_addr);
void cndm_destroy_netdev(struct net_device *ndev); void cndm_destroy_netdev(struct net_device *ndev);
// cndm_dev.c
extern const struct file_operations cndm_fops;
// cndm_tx.c // cndm_tx.c
int cndm_free_tx_buf(struct cndm_priv *priv); int cndm_free_tx_buf(struct cndm_priv *priv);
int cndm_poll_tx_cq(struct napi_struct *napi, int budget); int cndm_poll_tx_cq(struct napi_struct *napi, int budget);

View File

@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL
/*
Copyright (c) 2025 FPGA Ninja, LLC
Authors:
- Alex Forencich
*/
#include "cndm.h"
#include <linux/uaccess.h>
static int cndm_open(struct inode *inode, struct file *file)
{
// struct miscdevice *miscdev = file->private_data;
// struct cndm_dev *cdev = container_of(miscdev, struct cndm_dev, misc_dev);
return 0;
}
static int cndm_release(struct inode *inode, struct file *file)
{
// struct miscdevice *miscdev = file->private_data;
// struct cndm_dev *cdev = container_of(miscdev, struct cndm_dev, misc_dev);
return 0;
}
const struct file_operations cndm_fops = {
.owner = THIS_MODULE,
.open = cndm_open,
.release = cndm_release,
};

View File

@@ -135,8 +135,24 @@ static int cndm_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
cdev->ndev[k] = ndev; cdev->ndev[k] = ndev;
} }
cdev->misc_dev.minor = MISC_DYNAMIC_MINOR;
cdev->misc_dev.name = cdev->name;
cdev->misc_dev.fops = &cndm_fops;
cdev->misc_dev.parent = dev;
ret = misc_register(&cdev->misc_dev);
if (ret) {
cdev->misc_dev.this_device = NULL;
dev_err(dev, "misc_register failed: %d", ret);
goto fail_miscdev;
}
dev_info(dev, "Registered device %s", cdev->name);
return 0; return 0;
fail_miscdev:
fail_netdev: fail_netdev:
for (k = 0; k < 32; k++) { for (k = 0; k < 32; k++) {
if (cdev->ndev[k]) { if (cdev->ndev[k]) {
@@ -170,6 +186,9 @@ static void cndm_pci_remove(struct pci_dev *pdev)
dev_info(dev, DRIVER_NAME " PCI remove"); dev_info(dev, DRIVER_NAME " PCI remove");
if (cdev->misc_dev.this_device)
misc_deregister(&cdev->misc_dev);
for (k = 0; k < 32; k++) { for (k = 0; k < 32; k++) {
if (cdev->ndev[k]) { if (cdev->ndev[k]) {
pci_free_irq(pdev, k, cdev->ndev[k]); pci_free_irq(pdev, k, cdev->ndev[k]);