* [PATCH][RFC] : Megaraid patch for 2.6 5/5
@ 2004-02-20 2:09 Paul Wagland
0 siblings, 0 replies; only message in thread
From: Paul Wagland @ 2004-02-20 2:09 UTC (permalink / raw)
To: Linux SCSI mailing list, Linux kernel mailing list; +Cc: James.Bottomley, atulm
[-- Attachment #1.1: Type: text/plain, Size: 4311 bytes --]
Hi all,
This is the last patch in the current series. This is my initial attempt
at adding better sysfs support to the megaraid driver. Please note that
this is not yet complete, but it is a start, and is how I want to export
the rest of the /proc card state.
patch attached and below
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.c linux-2.6.2.megaraid/drivers/scsi/megaraid.c
--- linux-2.6.2.o/drivers/scsi/megaraid.c 2004-02-20 01:32:34.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.c 2004-02-20 01:32:39.000000000 +0100
@@ -46,6 +46,8 @@
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
#include <scsi/scsicam.h>
#include "scsi.h"
@@ -2333,46 +2335,15 @@
void *data)
{
adapter_t *adapter = (adapter_t *)data;
- dma_addr_t dma_handle;
- caddr_t inquiry;
- struct pci_dev *pdev;
- int len = 0;
-
- pdev = adapter->dev;
-
- if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- *eof = 1;
- return len;
- }
-
- if( mega_adapinq(adapter, dma_handle) != 0 ) {
-
+ int len;
+ int rate = mega_get_rebuild_percentage (adapter);
+ if (rate < 0 ) {
len = sprintf(page, "Adapter inquiry failed.\n");
-
printk(KERN_WARNING "megaraid: inquiry failed.\n");
-
- mega_free_inquiry(inquiry, dma_handle, pdev);
-
- *eof = 1;
-
- return len;
- }
-
- if( adapter->flag & BOARD_40LD ) {
- len = sprintf(page, "Rebuild Rate: [%d%%]\n",
- ((mega_inquiry3 *)inquiry)->rebuild_rate);
- }
- else {
- len = sprintf(page, "Rebuild Rate: [%d%%]\n",
- ((mraid_ext_inquiry *)
- inquiry)->raid_inq.adapter_info.rebuild_rate);
- }
-
-
- mega_free_inquiry(inquiry, dma_handle, pdev);
+ } else
+ len = snprintf(page, 22, "Rebuild Rate: [%d%%]\n", rate);
*eof = 1;
-
return len;
}
@@ -4533,6 +4504,55 @@
}
+/*
+ * This is where we have all of the sysfs related code
+ */
+static ssize_t
+sysfs_show_rebuild_percentage(struct class_device *class_dev, char *buf)
+{
+ struct Scsi_Host *shost = class_to_shost(class_dev);
+ adapter_t *adapter = (adapter_t *)shost->hostdata;
+
+ return snprintf(buf, 20, "%d\n", mega_get_rebuild_percentage(adapter));
+}
+static CLASS_DEVICE_ATTR(rebuild_percentage, S_IRUGO, sysfs_show_rebuild_percentage, NULL)
+
+static struct class_device_attribute *megaraid_dev_attrs[] = {
+ &class_device_attr_rebuild_percentage,
+ NULL,
+};
+
+
+static int
+mega_get_rebuild_percentage(adapter_t *adapter) {
+ dma_addr_t dma_handle;
+ caddr_t inquiry;
+ struct pci_dev *pdev;
+ int rate;
+
+ pdev = adapter->dev;
+
+ if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
+ return -1;
+ }
+
+ if( mega_adapinq(adapter, dma_handle) != 0 ) {
+ mega_free_inquiry(inquiry, dma_handle, pdev);
+ return -1;
+}
+
+ if( adapter->flag & BOARD_40LD ) {
+ rate = ((mega_inquiry3 *)inquiry)->rebuild_rate;
+}
+ else {
+ rate = ((mraid_ext_inquiry *)
+ inquiry)->raid_inq.adapter_info.rebuild_rate;
+ }
+
+ mega_free_inquiry(inquiry, dma_handle, pdev);
+ return rate;
+}
+
static struct scsi_host_template megaraid_template = {
.module = THIS_MODULE,
@@ -4551,6 +4571,7 @@
.eh_device_reset_handler = megaraid_reset,
.eh_bus_reset_handler = megaraid_reset,
.eh_host_reset_handler = megaraid_reset,
+ .shost_attrs = megaraid_dev_attrs,
};
static int __devinit
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.h linux-2.6.2.megaraid/drivers/scsi/megaraid.h
--- linux-2.6.2.o/drivers/scsi/megaraid.h 2004-02-20 01:32:30.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.h 2004-02-20 01:32:39.000000000 +0100
@@ -1051,6 +1051,12 @@
static int proc_rdrv(adapter_t *, char *, int, int);
#endif
+/* sysfs routines */
+static ssize_t sysfs_show_rebuild_percentage(struct class_device *, char *);
+
+/* common data collection routines */
+static int mega_get_rebuild_percentage(adapter_t *);
+
static int mega_adapinq(adapter_t *, dma_addr_t);
static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
static inline caddr_t mega_allocate_inquiry(dma_addr_t *, struct pci_dev *);
[-- Attachment #1.2: 5-megaraid.proto-sysfs.patch --]
[-- Type: text/x-patch, Size: 4012 bytes --]
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.c linux-2.6.2.megaraid/drivers/scsi/megaraid.c
--- linux-2.6.2.o/drivers/scsi/megaraid.c 2004-02-20 01:32:34.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.c 2004-02-20 01:32:39.000000000 +0100
@@ -46,6 +46,8 @@
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
#include <scsi/scsicam.h>
#include "scsi.h"
@@ -2333,46 +2335,15 @@
void *data)
{
adapter_t *adapter = (adapter_t *)data;
- dma_addr_t dma_handle;
- caddr_t inquiry;
- struct pci_dev *pdev;
- int len = 0;
-
- pdev = adapter->dev;
-
- if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
- *eof = 1;
- return len;
- }
-
- if( mega_adapinq(adapter, dma_handle) != 0 ) {
-
+ int len;
+ int rate = mega_get_rebuild_percentage (adapter);
+ if (rate < 0 ) {
len = sprintf(page, "Adapter inquiry failed.\n");
-
printk(KERN_WARNING "megaraid: inquiry failed.\n");
-
- mega_free_inquiry(inquiry, dma_handle, pdev);
-
- *eof = 1;
-
- return len;
- }
-
- if( adapter->flag & BOARD_40LD ) {
- len = sprintf(page, "Rebuild Rate: [%d%%]\n",
- ((mega_inquiry3 *)inquiry)->rebuild_rate);
- }
- else {
- len = sprintf(page, "Rebuild Rate: [%d%%]\n",
- ((mraid_ext_inquiry *)
- inquiry)->raid_inq.adapter_info.rebuild_rate);
- }
-
-
- mega_free_inquiry(inquiry, dma_handle, pdev);
+ } else
+ len = snprintf(page, 22, "Rebuild Rate: [%d%%]\n", rate);
*eof = 1;
-
return len;
}
@@ -4533,6 +4504,55 @@
}
+/*
+ * This is where we have all of the sysfs related code
+ */
+static ssize_t
+sysfs_show_rebuild_percentage(struct class_device *class_dev, char *buf)
+{
+ struct Scsi_Host *shost = class_to_shost(class_dev);
+ adapter_t *adapter = (adapter_t *)shost->hostdata;
+
+ return snprintf(buf, 20, "%d\n", mega_get_rebuild_percentage(adapter));
+}
+static CLASS_DEVICE_ATTR(rebuild_percentage, S_IRUGO, sysfs_show_rebuild_percentage, NULL)
+
+static struct class_device_attribute *megaraid_dev_attrs[] = {
+ &class_device_attr_rebuild_percentage,
+ NULL,
+};
+
+
+static int
+mega_get_rebuild_percentage(adapter_t *adapter) {
+ dma_addr_t dma_handle;
+ caddr_t inquiry;
+ struct pci_dev *pdev;
+ int rate;
+
+ pdev = adapter->dev;
+
+ if( (inquiry = mega_allocate_inquiry(&dma_handle, pdev)) == NULL ) {
+ return -1;
+ }
+
+ if( mega_adapinq(adapter, dma_handle) != 0 ) {
+ mega_free_inquiry(inquiry, dma_handle, pdev);
+ return -1;
+}
+
+ if( adapter->flag & BOARD_40LD ) {
+ rate = ((mega_inquiry3 *)inquiry)->rebuild_rate;
+}
+ else {
+ rate = ((mraid_ext_inquiry *)
+ inquiry)->raid_inq.adapter_info.rebuild_rate;
+ }
+
+ mega_free_inquiry(inquiry, dma_handle, pdev);
+ return rate;
+}
+
static struct scsi_host_template megaraid_template = {
.module = THIS_MODULE,
@@ -4551,6 +4571,7 @@
.eh_device_reset_handler = megaraid_reset,
.eh_bus_reset_handler = megaraid_reset,
.eh_host_reset_handler = megaraid_reset,
+ .shost_attrs = megaraid_dev_attrs,
};
static int __devinit
diff --recursive --ignore-all-space --unified linux-2.6.2.o/drivers/scsi/megaraid.h linux-2.6.2.megaraid/drivers/scsi/megaraid.h
--- linux-2.6.2.o/drivers/scsi/megaraid.h 2004-02-20 01:32:30.000000000 +0100
+++ linux-2.6.2.megaraid/drivers/scsi/megaraid.h 2004-02-20 01:32:39.000000000 +0100
@@ -1051,6 +1051,12 @@
static int proc_rdrv(adapter_t *, char *, int, int);
#endif
+/* sysfs routines */
+static ssize_t sysfs_show_rebuild_percentage(struct class_device *, char *);
+
+/* common data collection routines */
+static int mega_get_rebuild_percentage(adapter_t *);
+
static int mega_adapinq(adapter_t *, dma_addr_t);
static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
static inline caddr_t mega_allocate_inquiry(dma_addr_t *, struct pci_dev *);
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-02-20 2:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 2:09 [PATCH][RFC] : Megaraid patch for 2.6 5/5 Paul Wagland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®