mirror of
https://github.com/fpganinja/taxi.git
synced 2026-01-18 01:30:36 -08:00
cndm: Register misc device
Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
@@ -6,6 +6,7 @@ ifneq ($(KERNELRELEASE),)
|
||||
obj-m += cndm.o
|
||||
cndm-y += cndm_main.o
|
||||
cndm-y += cndm_devlink.o
|
||||
cndm-y += cndm_dev.o
|
||||
cndm-y += cndm_netdev.o
|
||||
cndm-y += cndm_tx.o
|
||||
cndm-y += cndm_rx.o
|
||||
|
||||
@@ -13,6 +13,7 @@ Authors:
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/ptp_clock_kernel.h>
|
||||
@@ -28,6 +29,8 @@ struct cndm_dev {
|
||||
unsigned int id;
|
||||
char name[16];
|
||||
|
||||
struct miscdevice misc_dev;
|
||||
|
||||
struct net_device *ndev[32];
|
||||
|
||||
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);
|
||||
void cndm_destroy_netdev(struct net_device *ndev);
|
||||
|
||||
// cndm_dev.c
|
||||
extern const struct file_operations cndm_fops;
|
||||
|
||||
// cndm_tx.c
|
||||
int cndm_free_tx_buf(struct cndm_priv *priv);
|
||||
int cndm_poll_tx_cq(struct napi_struct *napi, int budget);
|
||||
|
||||
35
src/cndm/modules/cndm/cndm_dev.c
Normal file
35
src/cndm/modules/cndm/cndm_dev.c
Normal 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,
|
||||
};
|
||||
@@ -135,8 +135,24 @@ static int cndm_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
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;
|
||||
|
||||
fail_miscdev:
|
||||
fail_netdev:
|
||||
for (k = 0; k < 32; 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");
|
||||
|
||||
if (cdev->misc_dev.this_device)
|
||||
misc_deregister(&cdev->misc_dev);
|
||||
|
||||
for (k = 0; k < 32; k++) {
|
||||
if (cdev->ndev[k]) {
|
||||
pci_free_irq(pdev, k, cdev->ndev[k]);
|
||||
|
||||
Reference in New Issue
Block a user