From 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Fri, 10 May 2024 07:44:59 +0000
Subject: [PATCH] gmac get mac form eeprom
---
kernel/samples/vfio-mdev/mtty.c | 101 +++++++++++++++++++-------------------------------
1 files changed, 38 insertions(+), 63 deletions(-)
diff --git a/kernel/samples/vfio-mdev/mtty.c b/kernel/samples/vfio-mdev/mtty.c
index f6732aa..ce84a30 100644
--- a/kernel/samples/vfio-mdev/mtty.c
+++ b/kernel/samples/vfio-mdev/mtty.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Mediated virtual PCI serial host device driver
*
@@ -5,13 +6,8 @@
* Author: Neo Jia <cjia@nvidia.com>
* Kirti Wankhede <kwankhede@nvidia.com>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
* Sample driver that creates mdev device that simulates serial port over PCI
* card.
- *
*/
#include <linux/init.h>
@@ -72,7 +68,7 @@
* Global Structures
*/
-struct mtty_dev {
+static struct mtty_dev {
dev_t vd_devt;
struct class *vd_class;
struct cdev vd_cdev;
@@ -88,7 +84,7 @@
};
#if defined(DEBUG_REGS)
-const char *wr_reg[] = {
+static const char *wr_reg[] = {
"TX",
"IER",
"FCR",
@@ -99,7 +95,7 @@
"SCR"
};
-const char *rd_reg[] = {
+static const char *rd_reg[] = {
"RX",
"IER",
"IIR",
@@ -147,8 +143,8 @@
int nr_ports;
};
-struct mutex mdev_list_lock;
-struct list_head mdev_devices_list;
+static struct mutex mdev_list_lock;
+static struct list_head mdev_devices_list;
static const struct file_operations vd_fops = {
.owner = THIS_MODULE,
@@ -156,22 +152,11 @@
/* function prototypes */
-static int mtty_trigger_interrupt(uuid_le uuid);
+static int mtty_trigger_interrupt(struct mdev_state *mdev_state);
/* Helper functions */
-static struct mdev_state *find_mdev_state_by_uuid(uuid_le uuid)
-{
- struct mdev_state *mds;
- list_for_each_entry(mds, &mdev_devices_list, next) {
- if (uuid_le_cmp(mdev_uuid(mds->mdev), uuid) == 0)
- return mds;
- }
-
- return NULL;
-}
-
-void dump_buffer(u8 *buf, uint32_t count)
+static void dump_buffer(u8 *buf, uint32_t count)
{
#if defined(DEBUG)
int i;
@@ -341,8 +326,7 @@
pr_err("Serial port %d: Fifo level trigger\n",
index);
#endif
- mtty_trigger_interrupt(
- mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
} else {
#if defined(DEBUG_INTR)
@@ -356,8 +340,7 @@
*/
if (mdev_state->s[index].uart_reg[UART_IER] &
UART_IER_RLSI)
- mtty_trigger_interrupt(
- mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
mutex_unlock(&mdev_state->rxtx_lock);
break;
@@ -376,8 +359,7 @@
pr_err("Serial port %d: IER_THRI write\n",
index);
#endif
- mtty_trigger_interrupt(
- mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
mutex_unlock(&mdev_state->rxtx_lock);
@@ -448,7 +430,7 @@
#if defined(DEBUG_INTR)
pr_err("Serial port %d: MCR_OUT2 write\n", index);
#endif
- mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) &&
@@ -456,7 +438,7 @@
#if defined(DEBUG_INTR)
pr_err("Serial port %d: MCR RTS/DTR write\n", index);
#endif
- mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
break;
@@ -507,8 +489,7 @@
#endif
if (mdev_state->s[index].uart_reg[UART_IER] &
UART_IER_THRI)
- mtty_trigger_interrupt(
- mdev_uuid(mdev_state->mdev));
+ mtty_trigger_interrupt(mdev_state);
}
mutex_unlock(&mdev_state->rxtx_lock);
@@ -727,7 +708,7 @@
return ret;
}
-int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
+static int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
{
struct mdev_state *mdev_state;
char name[MTTY_STRING_LEN];
@@ -777,7 +758,7 @@
return 0;
}
-int mtty_remove(struct mdev_device *mdev)
+static int mtty_remove(struct mdev_device *mdev)
{
struct mdev_state *mds, *tmp_mds;
struct mdev_state *mdev_state = mdev_get_drvdata(mdev);
@@ -799,7 +780,7 @@
return ret;
}
-int mtty_reset(struct mdev_device *mdev)
+static int mtty_reset(struct mdev_device *mdev)
{
struct mdev_state *mdev_state;
@@ -815,8 +796,8 @@
return 0;
}
-ssize_t mtty_read(struct mdev_device *mdev, char __user *buf, size_t count,
- loff_t *ppos)
+static ssize_t mtty_read(struct mdev_device *mdev, char __user *buf,
+ size_t count, loff_t *ppos)
{
unsigned int done = 0;
int ret;
@@ -874,7 +855,7 @@
return -EFAULT;
}
-ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf,
+static ssize_t mtty_write(struct mdev_device *mdev, const char __user *buf,
size_t count, loff_t *ppos)
{
unsigned int done = 0;
@@ -1032,17 +1013,9 @@
return ret;
}
-static int mtty_trigger_interrupt(uuid_le uuid)
+static int mtty_trigger_interrupt(struct mdev_state *mdev_state)
{
int ret = -1;
- struct mdev_state *mdev_state;
-
- mdev_state = find_mdev_state_by_uuid(uuid);
-
- if (!mdev_state) {
- pr_info("%s: mdev not found\n", __func__);
- return -EINVAL;
- }
if ((mdev_state->irq_index == VFIO_PCI_MSI_IRQ_INDEX) &&
(!mdev_state->msi_evtfd))
@@ -1067,7 +1040,7 @@
return ret;
}
-int mtty_get_region_info(struct mdev_device *mdev,
+static int mtty_get_region_info(struct mdev_device *mdev,
struct vfio_region_info *region_info,
u16 *cap_type_id, void **cap_type)
{
@@ -1116,7 +1089,8 @@
return 0;
}
-int mtty_get_irq_info(struct mdev_device *mdev, struct vfio_irq_info *irq_info)
+static int mtty_get_irq_info(struct mdev_device *mdev,
+ struct vfio_irq_info *irq_info)
{
switch (irq_info->index) {
case VFIO_PCI_INTX_IRQ_INDEX:
@@ -1140,7 +1114,7 @@
return 0;
}
-int mtty_get_device_info(struct mdev_device *mdev,
+static int mtty_get_device_info(struct mdev_device *mdev,
struct vfio_device_info *dev_info)
{
dev_info->flags = VFIO_DEVICE_FLAGS_PCI;
@@ -1272,13 +1246,13 @@
return -ENOTTY;
}
-int mtty_open(struct mdev_device *mdev)
+static int mtty_open(struct mdev_device *mdev)
{
pr_info("%s\n", __func__);
return 0;
}
-void mtty_close(struct mdev_device *mdev)
+static void mtty_close(struct mdev_device *mdev)
{
pr_info("%s\n", __func__);
}
@@ -1302,7 +1276,7 @@
.attrs = mtty_dev_attrs,
};
-const struct attribute_group *mtty_dev_groups[] = {
+static const struct attribute_group *mtty_dev_groups[] = {
&mtty_dev_group,
NULL,
};
@@ -1329,7 +1303,7 @@
.attrs = mdev_dev_attrs,
};
-const struct attribute_group *mdev_dev_groups[] = {
+static const struct attribute_group *mdev_dev_groups[] = {
&mdev_dev_group,
NULL,
};
@@ -1351,7 +1325,7 @@
return -EINVAL;
}
-MDEV_TYPE_ATTR_RO(name);
+static MDEV_TYPE_ATTR_RO(name);
static ssize_t
available_instances_show(struct kobject *kobj, struct device *dev, char *buf)
@@ -1379,7 +1353,7 @@
return sprintf(buf, "%d\n", (MAX_MTTYS - used)/ports);
}
-MDEV_TYPE_ATTR_RO(available_instances);
+static MDEV_TYPE_ATTR_RO(available_instances);
static ssize_t device_api_show(struct kobject *kobj, struct device *dev,
@@ -1388,7 +1362,7 @@
return sprintf(buf, "%s\n", VFIO_DEVICE_API_PCI_STRING);
}
-MDEV_TYPE_ATTR_RO(device_api);
+static MDEV_TYPE_ATTR_RO(device_api);
static struct attribute *mdev_types_attrs[] = {
&mdev_type_attr_name.attr,
@@ -1407,7 +1381,7 @@
.attrs = mdev_types_attrs,
};
-struct attribute_group *mdev_type_groups[] = {
+static struct attribute_group *mdev_type_groups[] = {
&mdev_type_group1,
&mdev_type_group2,
NULL,
@@ -1442,7 +1416,8 @@
idr_init(&mtty_dev.vd_idr);
- ret = alloc_chrdev_region(&mtty_dev.vd_devt, 0, MINORMASK, MTTY_NAME);
+ ret = alloc_chrdev_region(&mtty_dev.vd_devt, 0, MINORMASK + 1,
+ MTTY_NAME);
if (ret < 0) {
pr_err("Error: failed to register mtty_dev, err:%d\n", ret);
@@ -1450,7 +1425,7 @@
}
cdev_init(&mtty_dev.vd_cdev, &vd_fops);
- cdev_add(&mtty_dev.vd_cdev, mtty_dev.vd_devt, MINORMASK);
+ cdev_add(&mtty_dev.vd_cdev, mtty_dev.vd_devt, MINORMASK + 1);
pr_info("major_number:%d\n", MAJOR(mtty_dev.vd_devt));
@@ -1487,7 +1462,7 @@
failed1:
cdev_del(&mtty_dev.vd_cdev);
- unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK);
+ unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1);
all_done:
return ret;
@@ -1501,7 +1476,7 @@
device_unregister(&mtty_dev.dev);
idr_destroy(&mtty_dev.vd_idr);
cdev_del(&mtty_dev.vd_cdev);
- unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK);
+ unregister_chrdev_region(mtty_dev.vd_devt, MINORMASK + 1);
class_destroy(mtty_dev.vd_class);
mtty_dev.vd_class = NULL;
pr_info("mtty_dev: Unloaded!\n");
--
Gitblit v1.6.2