aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/mtip32xx/mtip32xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/mtip32xx/mtip32xx.c')
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c166
1 files changed, 118 insertions, 48 deletions
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 264bc77dcb91..a8fddeb3d638 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -37,6 +37,7 @@
37#include <linux/kthread.h> 37#include <linux/kthread.h>
38#include <../drivers/ata/ahci.h> 38#include <../drivers/ata/ahci.h>
39#include <linux/export.h> 39#include <linux/export.h>
40#include <linux/debugfs.h>
40#include "mtip32xx.h" 41#include "mtip32xx.h"
41 42
42#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32) 43#define HW_CMD_SLOT_SZ (MTIP_MAX_COMMAND_SLOTS * 32)
@@ -85,6 +86,7 @@ static int instance;
85 * allocated in mtip_init(). 86 * allocated in mtip_init().
86 */ 87 */
87static int mtip_major; 88static int mtip_major;
89static struct dentry *dfs_parent;
88 90
89static DEFINE_SPINLOCK(rssd_index_lock); 91static DEFINE_SPINLOCK(rssd_index_lock);
90static DEFINE_IDA(rssd_index_ida); 92static DEFINE_IDA(rssd_index_ida);
@@ -2546,7 +2548,7 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2546} 2548}
2547 2549
2548/* 2550/*
2549 * Sysfs register/status dump. 2551 * Sysfs status dump.
2550 * 2552 *
2551 * @dev Pointer to the device structure, passed by the kernrel. 2553 * @dev Pointer to the device structure, passed by the kernrel.
2552 * @attr Pointer to the device_attribute structure passed by the kernel. 2554 * @attr Pointer to the device_attribute structure passed by the kernel.
@@ -2555,45 +2557,68 @@ static struct scatterlist *mtip_hw_get_scatterlist(struct driver_data *dd,
2555 * return value 2557 * return value
2556 * The size, in bytes, of the data copied into buf. 2558 * The size, in bytes, of the data copied into buf.
2557 */ 2559 */
2558static ssize_t mtip_hw_show_registers(struct device *dev, 2560static ssize_t mtip_hw_show_status(struct device *dev,
2559 struct device_attribute *attr, 2561 struct device_attribute *attr,
2560 char *buf) 2562 char *buf)
2561{ 2563{
2562 u32 group_allocated;
2563 struct driver_data *dd = dev_to_disk(dev)->private_data; 2564 struct driver_data *dd = dev_to_disk(dev)->private_data;
2564 int size = 0; 2565 int size = 0;
2566
2567 if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag))
2568 size += sprintf(buf, "%s", "thermal_shutdown\n");
2569 else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
2570 size += sprintf(buf, "%s", "write_protect\n");
2571 else
2572 size += sprintf(buf, "%s", "online\n");
2573
2574 return size;
2575}
2576
2577static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL);
2578
2579static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
2580 size_t len, loff_t *offset)
2581{
2582 struct driver_data *dd = (struct driver_data *)f->private_data;
2583 char buf[MTIP_DFS_MAX_BUF_SIZE];
2584 u32 group_allocated;
2585 int size = *offset;
2565 int n; 2586 int n;
2566 2587
2567 size += sprintf(&buf[size], "Hardware\n--------\n"); 2588 if (!len || size)
2568 size += sprintf(&buf[size], "S ACTive : [ 0x"); 2589 return 0;
2590
2591 if (size < 0)
2592 return -EINVAL;
2593
2594 size += sprintf(&buf[size], "H/ S ACTive : [ 0x");
2569 2595
2570 for (n = dd->slot_groups-1; n >= 0; n--) 2596 for (n = dd->slot_groups-1; n >= 0; n--)
2571 size += sprintf(&buf[size], "%08X ", 2597 size += sprintf(&buf[size], "%08X ",
2572 readl(dd->port->s_active[n])); 2598 readl(dd->port->s_active[n]));
2573 2599
2574 size += sprintf(&buf[size], "]\n"); 2600 size += sprintf(&buf[size], "]\n");
2575 size += sprintf(&buf[size], "Command Issue : [ 0x"); 2601 size += sprintf(&buf[size], "H/ Command Issue : [ 0x");
2576 2602
2577 for (n = dd->slot_groups-1; n >= 0; n--) 2603 for (n = dd->slot_groups-1; n >= 0; n--)
2578 size += sprintf(&buf[size], "%08X ", 2604 size += sprintf(&buf[size], "%08X ",
2579 readl(dd->port->cmd_issue[n])); 2605 readl(dd->port->cmd_issue[n]));
2580 2606
2581 size += sprintf(&buf[size], "]\n"); 2607 size += sprintf(&buf[size], "]\n");
2582 size += sprintf(&buf[size], "Completed : [ 0x"); 2608 size += sprintf(&buf[size], "H/ Completed : [ 0x");
2583 2609
2584 for (n = dd->slot_groups-1; n >= 0; n--) 2610 for (n = dd->slot_groups-1; n >= 0; n--)
2585 size += sprintf(&buf[size], "%08X ", 2611 size += sprintf(&buf[size], "%08X ",
2586 readl(dd->port->completed[n])); 2612 readl(dd->port->completed[n]));
2587 2613
2588 size += sprintf(&buf[size], "]\n"); 2614 size += sprintf(&buf[size], "]\n");
2589 size += sprintf(&buf[size], "PORT IRQ STAT : [ 0x%08X ]\n", 2615 size += sprintf(&buf[size], "H/ PORT IRQ STAT : [ 0x%08X ]\n",
2590 readl(dd->port->mmio + PORT_IRQ_STAT)); 2616 readl(dd->port->mmio + PORT_IRQ_STAT));
2591 size += sprintf(&buf[size], "HOST IRQ STAT : [ 0x%08X ]\n", 2617 size += sprintf(&buf[size], "H/ HOST IRQ STAT : [ 0x%08X ]\n",
2592 readl(dd->mmio + HOST_IRQ_STAT)); 2618 readl(dd->mmio + HOST_IRQ_STAT));
2593 size += sprintf(&buf[size], "\n"); 2619 size += sprintf(&buf[size], "\n");
2594 2620
2595 size += sprintf(&buf[size], "Local\n-----\n"); 2621 size += sprintf(&buf[size], "L/ Allocated : [ 0x");
2596 size += sprintf(&buf[size], "Allocated : [ 0x");
2597 2622
2598 for (n = dd->slot_groups-1; n >= 0; n--) { 2623 for (n = dd->slot_groups-1; n >= 0; n--) {
2599 if (sizeof(long) > sizeof(u32)) 2624 if (sizeof(long) > sizeof(u32))
@@ -2605,7 +2630,7 @@ static ssize_t mtip_hw_show_registers(struct device *dev,
2605 } 2630 }
2606 size += sprintf(&buf[size], "]\n"); 2631 size += sprintf(&buf[size], "]\n");
2607 2632
2608 size += sprintf(&buf[size], "Commands in Q: [ 0x"); 2633 size += sprintf(&buf[size], "L/ Commands in Q : [ 0x");
2609 2634
2610 for (n = dd->slot_groups-1; n >= 0; n--) { 2635 for (n = dd->slot_groups-1; n >= 0; n--) {
2611 if (sizeof(long) > sizeof(u32)) 2636 if (sizeof(long) > sizeof(u32))
@@ -2617,44 +2642,53 @@ static ssize_t mtip_hw_show_registers(struct device *dev,
2617 } 2642 }
2618 size += sprintf(&buf[size], "]\n"); 2643 size += sprintf(&buf[size], "]\n");
2619 2644
2620 return size; 2645 *offset = size <= len ? size : len;
2646 size = copy_to_user(ubuf, buf, *offset);
2647 if (size)
2648 return -EFAULT;
2649
2650 return *offset;
2621} 2651}
2622 2652
2623static ssize_t mtip_hw_show_status(struct device *dev, 2653static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
2624 struct device_attribute *attr, 2654 size_t len, loff_t *offset)
2625 char *buf)
2626{ 2655{
2627 struct driver_data *dd = dev_to_disk(dev)->private_data; 2656 struct driver_data *dd = (struct driver_data *)f->private_data;
2628 int size = 0; 2657 char buf[MTIP_DFS_MAX_BUF_SIZE];
2658 int size = *offset;
2629 2659
2630 if (test_bit(MTIP_DDF_OVER_TEMP_BIT, &dd->dd_flag)) 2660 if (!len || size)
2631 size += sprintf(buf, "%s", "thermal_shutdown\n"); 2661 return 0;
2632 else if (test_bit(MTIP_DDF_WRITE_PROTECT_BIT, &dd->dd_flag))
2633 size += sprintf(buf, "%s", "write_protect\n");
2634 else
2635 size += sprintf(buf, "%s", "online\n");
2636
2637 return size;
2638}
2639 2662
2640static ssize_t mtip_hw_show_flags(struct device *dev, 2663 if (size < 0)
2641 struct device_attribute *attr, 2664 return -EINVAL;
2642 char *buf)
2643{
2644 struct driver_data *dd = dev_to_disk(dev)->private_data;
2645 int size = 0;
2646 2665
2647 size += sprintf(&buf[size], "Flag in port struct : [ %08lX ]\n", 2666 size += sprintf(&buf[size], "Flag-port : [ %08lX ]\n",
2648 dd->port->flags); 2667 dd->port->flags);
2649 size += sprintf(&buf[size], "Flag in dd struct : [ %08lX ]\n", 2668 size += sprintf(&buf[size], "Flag-dd : [ %08lX ]\n",
2650 dd->dd_flag); 2669 dd->dd_flag);
2651 2670
2652 return size; 2671 *offset = size <= len ? size : len;
2672 size = copy_to_user(ubuf, buf, *offset);
2673 if (size)
2674 return -EFAULT;
2675
2676 return *offset;
2653} 2677}
2654 2678
2655static DEVICE_ATTR(registers, S_IRUGO, mtip_hw_show_registers, NULL); 2679static const struct file_operations mtip_regs_fops = {
2656static DEVICE_ATTR(status, S_IRUGO, mtip_hw_show_status, NULL); 2680 .owner = THIS_MODULE,
2657static DEVICE_ATTR(flags, S_IRUGO, mtip_hw_show_flags, NULL); 2681 .open = simple_open,
2682 .read = mtip_hw_read_registers,
2683 .llseek = no_llseek,
2684};
2685
2686static const struct file_operations mtip_flags_fops = {
2687 .owner = THIS_MODULE,
2688 .open = simple_open,
2689 .read = mtip_hw_read_flags,
2690 .llseek = no_llseek,
2691};
2658 2692
2659/* 2693/*
2660 * Create the sysfs related attributes. 2694 * Create the sysfs related attributes.
@@ -2671,15 +2705,9 @@ static int mtip_hw_sysfs_init(struct driver_data *dd, struct kobject *kobj)
2671 if (!kobj || !dd) 2705 if (!kobj || !dd)
2672 return -EINVAL; 2706 return -EINVAL;
2673 2707
2674 if (sysfs_create_file(kobj, &dev_attr_registers.attr))
2675 dev_warn(&dd->pdev->dev,
2676 "Error creating 'registers' sysfs entry\n");
2677 if (sysfs_create_file(kobj, &dev_attr_status.attr)) 2708 if (sysfs_create_file(kobj, &dev_attr_status.attr))
2678 dev_warn(&dd->pdev->dev, 2709 dev_warn(&dd->pdev->dev,
2679 "Error creating 'status' sysfs entry\n"); 2710 "Error creating 'status' sysfs entry\n");
2680 if (sysfs_create_file(kobj, &dev_attr_flags.attr))
2681 dev_warn(&dd->pdev->dev,
2682 "Error creating 'flags' sysfs entry\n");
2683 return 0; 2711 return 0;
2684} 2712}
2685 2713
@@ -2698,13 +2726,39 @@ static int mtip_hw_sysfs_exit(struct driver_data *dd, struct kobject *kobj)
2698 if (!kobj || !dd) 2726 if (!kobj || !dd)
2699 return -EINVAL; 2727 return -EINVAL;
2700 2728
2701 sysfs_remove_file(kobj, &dev_attr_registers.attr);
2702 sysfs_remove_file(kobj, &dev_attr_status.attr); 2729 sysfs_remove_file(kobj, &dev_attr_status.attr);
2703 sysfs_remove_file(kobj, &dev_attr_flags.attr);
2704 2730
2705 return 0; 2731 return 0;
2706} 2732}
2707 2733
2734static int mtip_hw_debugfs_init(struct driver_data *dd)
2735{
2736 if (!dfs_parent)
2737 return -1;
2738
2739 dd->dfs_node = debugfs_create_dir(dd->disk->disk_name, dfs_parent);
2740 if (IS_ERR_OR_NULL(dd->dfs_node)) {
2741 dev_warn(&dd->pdev->dev,
2742 "Error creating node %s under debugfs\n",
2743 dd->disk->disk_name);
2744 dd->dfs_node = NULL;
2745 return -1;
2746 }
2747
2748 debugfs_create_file("flags", S_IRUGO, dd->dfs_node, dd,
2749 &mtip_flags_fops);
2750 debugfs_create_file("registers", S_IRUGO, dd->dfs_node, dd,
2751 &mtip_regs_fops);
2752
2753 return 0;
2754}
2755
2756static void mtip_hw_debugfs_exit(struct driver_data *dd)
2757{
2758 debugfs_remove_recursive(dd->dfs_node);
2759}
2760
2761
2708/* 2762/*
2709 * Perform any init/resume time hardware setup 2763 * Perform any init/resume time hardware setup
2710 * 2764 *
@@ -3730,6 +3784,7 @@ skip_create_disk:
3730 mtip_hw_sysfs_init(dd, kobj); 3784 mtip_hw_sysfs_init(dd, kobj);
3731 kobject_put(kobj); 3785 kobject_put(kobj);
3732 } 3786 }
3787 mtip_hw_debugfs_init(dd);
3733 3788
3734 if (dd->mtip_svc_handler) { 3789 if (dd->mtip_svc_handler) {
3735 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag); 3790 set_bit(MTIP_DDF_INIT_DONE_BIT, &dd->dd_flag);
@@ -3755,6 +3810,8 @@ start_service_thread:
3755 return rv; 3810 return rv;
3756 3811
3757kthread_run_error: 3812kthread_run_error:
3813 mtip_hw_debugfs_exit(dd);
3814
3758 /* Delete our gendisk. This also removes the device from /dev */ 3815 /* Delete our gendisk. This also removes the device from /dev */
3759 del_gendisk(dd->disk); 3816 del_gendisk(dd->disk);
3760 3817
@@ -3805,6 +3862,7 @@ static int mtip_block_remove(struct driver_data *dd)
3805 kobject_put(kobj); 3862 kobject_put(kobj);
3806 } 3863 }
3807 } 3864 }
3865 mtip_hw_debugfs_exit(dd);
3808 3866
3809 /* 3867 /*
3810 * Delete our gendisk structure. This also removes the device 3868 * Delete our gendisk structure. This also removes the device
@@ -4152,10 +4210,20 @@ static int __init mtip_init(void)
4152 } 4210 }
4153 mtip_major = error; 4211 mtip_major = error;
4154 4212
4213 if (!dfs_parent) {
4214 dfs_parent = debugfs_create_dir("rssd", NULL);
4215 if (IS_ERR_OR_NULL(dfs_parent)) {
4216 printk(KERN_WARNING "Error creating debugfs parent\n");
4217 dfs_parent = NULL;
4218 }
4219 }
4220
4155 /* Register our PCI operations. */ 4221 /* Register our PCI operations. */
4156 error = pci_register_driver(&mtip_pci_driver); 4222 error = pci_register_driver(&mtip_pci_driver);
4157 if (error) 4223 if (error) {
4224 debugfs_remove(dfs_parent);
4158 unregister_blkdev(mtip_major, MTIP_DRV_NAME); 4225 unregister_blkdev(mtip_major, MTIP_DRV_NAME);
4226 }
4159 4227
4160 return error; 4228 return error;
4161} 4229}
@@ -4172,6 +4240,8 @@ static int __init mtip_init(void)
4172 */ 4240 */
4173static void __exit mtip_exit(void) 4241static void __exit mtip_exit(void)
4174{ 4242{
4243 debugfs_remove_recursive(dfs_parent);
4244
4175 /* Release the allocated major block device number. */ 4245 /* Release the allocated major block device number. */
4176 unregister_blkdev(mtip_major, MTIP_DRV_NAME); 4246 unregister_blkdev(mtip_major, MTIP_DRV_NAME);
4177 4247