Re: [PATCH v4 11/32] cxlflash: Refine host/device attributes

2015-09-28 Thread Andrew Donnellan

On 26/09/15 09:14, Matthew R. Ochs wrote:

Implement the following suggestions and add two new attributes
to allow for debugging the port LUN table.

  - use scnprintf() instead of snprintf()
  - use DEVICE_ATTR_RO and DEVICE_ATTR_RW

Suggested-by: Shane Seymour 
Signed-off-by: Matthew R. Ochs 
Signed-off-by: Manoj N. Kumar 
Reviewed-by: Brian King 


The commit message could explain the patch a bit better.


Andrew

--
Andrew Donnellan  Software Engineer, OzLabs
andrew.donnel...@au1.ibm.com  Australia Development Lab, Canberra
+61 2 6201 8874 (work)IBM Australia Limited

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v4 11/32] cxlflash: Refine host/device attributes

2015-09-25 Thread Matthew R. Ochs
Implement the following suggestions and add two new attributes
to allow for debugging the port LUN table.

 - use scnprintf() instead of snprintf()
 - use DEVICE_ATTR_RO and DEVICE_ATTR_RW

Suggested-by: Shane Seymour 
Signed-off-by: Matthew R. Ochs 
Signed-off-by: Manoj N. Kumar 
Reviewed-by: Brian King 
---
 drivers/scsi/cxlflash/main.c | 180 +--
 1 file changed, 138 insertions(+), 42 deletions(-)

diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
index 226cefe..b44212b 100644
--- a/drivers/scsi/cxlflash/main.c
+++ b/drivers/scsi/cxlflash/main.c
@@ -1995,33 +1995,24 @@ static int cxlflash_change_queue_depth(struct 
scsi_device *sdev, int qdepth)
 
 /**
  * cxlflash_show_port_status() - queries and presents the current port status
- * @dev:   Generic device associated with the host owning the port.
- * @attr:  Device attribute representing the port.
+ * @port:  Desired port for status reporting.
+ * @afu:   AFU owning the specified port.
  * @buf:   Buffer of length PAGE_SIZE to report back port status in ASCII.
  *
  * Return: The size of the ASCII string returned in @buf.
  */
-static ssize_t cxlflash_show_port_status(struct device *dev,
-struct device_attribute *attr,
-char *buf)
+static ssize_t cxlflash_show_port_status(u32 port, struct afu *afu, char *buf)
 {
-   struct Scsi_Host *shost = class_to_shost(dev);
-   struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
-   struct afu *afu = cfg->afu;
-
char *disp_status;
-   int rc;
-   u32 port;
u64 status;
-   u64 *fc_regs;
+   __be64 __iomem *fc_regs;
 
-   rc = kstrtouint((attr->attr.name + 4), 10, &port);
-   if (rc || (port >= NUM_FC_PORTS))
+   if (port >= NUM_FC_PORTS)
return 0;
 
fc_regs = &afu->afu_map->global.fc_regs[port][0];
-   status =
-   (readq_be(&fc_regs[FC_MTIP_STATUS / 8]) & FC_MTIP_STATUS_MASK);
+   status = readq_be(&fc_regs[FC_MTIP_STATUS / 8]);
+   status &= FC_MTIP_STATUS_MASK;
 
if (status == FC_MTIP_STATUS_ONLINE)
disp_status = "online";
@@ -2030,31 +2021,69 @@ static ssize_t cxlflash_show_port_status(struct device 
*dev,
else
disp_status = "unknown";
 
-   return snprintf(buf, PAGE_SIZE, "%s\n", disp_status);
+   return scnprintf(buf, PAGE_SIZE, "%s\n", disp_status);
+}
+
+/**
+ * port0_show() - queries and presents the current status of port 0
+ * @dev:   Generic device associated with the host owning the port.
+ * @attr:  Device attribute representing the port.
+ * @buf:   Buffer of length PAGE_SIZE to report back port status in ASCII.
+ *
+ * Return: The size of the ASCII string returned in @buf.
+ */
+static ssize_t port0_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+   struct Scsi_Host *shost = class_to_shost(dev);
+   struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
+   struct afu *afu = cfg->afu;
+
+   return cxlflash_show_port_status(0, afu, buf);
 }
 
 /**
- * cxlflash_show_lun_mode() - presents the current LUN mode of the host
+ * port1_show() - queries and presents the current status of port 1
+ * @dev:   Generic device associated with the host owning the port.
+ * @attr:  Device attribute representing the port.
+ * @buf:   Buffer of length PAGE_SIZE to report back port status in ASCII.
+ *
+ * Return: The size of the ASCII string returned in @buf.
+ */
+static ssize_t port1_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+   struct Scsi_Host *shost = class_to_shost(dev);
+   struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
+   struct afu *afu = cfg->afu;
+
+   return cxlflash_show_port_status(1, afu, buf);
+}
+
+/**
+ * lun_mode_show() - presents the current LUN mode of the host
  * @dev:   Generic device associated with the host.
- * @attr:  Device attribute representing the lun mode.
+ * @attr:  Device attribute representing the LUN mode.
  * @buf:   Buffer of length PAGE_SIZE to report back the LUN mode in ASCII.
  *
  * Return: The size of the ASCII string returned in @buf.
  */
-static ssize_t cxlflash_show_lun_mode(struct device *dev,
- struct device_attribute *attr, char *buf)
+static ssize_t lun_mode_show(struct device *dev,
+struct device_attribute *attr, char *buf)
 {
struct Scsi_Host *shost = class_to_shost(dev);
struct cxlflash_cfg *cfg = (struct cxlflash_cfg *)shost->hostdata;
struct afu *afu = cfg->afu;
 
-   return snprintf(buf, PAGE_SIZE, "%u\n", afu->internal_lun);
+   return scnprintf(buf, PAGE_SIZE, "%u\n", afu->internal