[PATCH v1 2/8] scsi: megaraid_sas: use parentheses to enclose macros with complex values

2021-04-09 Thread Luo Jiaxing
checkpatch.pl report several error below:

ERROR: Macros with complex values should be enclosed in parentheses
+#define SCP2LUN(scp)   (u32)(scp)->device->lun // to LUN

ERROR: Macros with complex values should be enclosed in parentheses
+#define SCP2ADAPTER(scp)   (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp))

So fix those by enclosed by parentheses.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/mbox_defs.h|  2 +-
 drivers/scsi/megaraid/mega_common.h  | 16 
 drivers/scsi/megaraid/megaraid_sas.h |  6 +++---
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/megaraid/mbox_defs.h 
b/drivers/scsi/megaraid/mbox_defs.h
index 5001624..3efbfdb 100644
--- a/drivers/scsi/megaraid/mbox_defs.h
+++ b/drivers/scsi/megaraid/mbox_defs.h
@@ -124,7 +124,7 @@
 #define FC_MAX_PHYSICAL_DEVICES256
 #define MAX_MBOX_CHANNELS  5
 #define MAX_MBOX_TARGET15
-#define MBOX_MAX_PHYSICAL_DRIVES   MAX_MBOX_CHANNELS*MAX_MBOX_TARGET
+#define MBOX_MAX_PHYSICAL_DRIVES   (MAX_MBOX_CHANNELS * MAX_MBOX_TARGET)
 #define MAX_ROW_SIZE_40LD  32
 #define MAX_ROW_SIZE_8LD   8
 #define SPAN_DEPTH_8_SPANS 8
diff --git a/drivers/scsi/megaraid/mega_common.h 
b/drivers/scsi/megaraid/mega_common.h
index 2ad0aa2..2a0981b 100644
--- a/drivers/scsi/megaraid/mega_common.h
+++ b/drivers/scsi/megaraid/mega_common.h
@@ -196,22 +196,22 @@ typedef struct {
 
 
 // conversion from scsi command
-#define SCP2HOST(scp)  (scp)->device->host // to host
-#define SCP2HOSTDATA(scp)  SCP2HOST(scp)->hostdata // to soft state
-#define SCP2CHANNEL(scp)   (scp)->device->channel  // to channel
-#define SCP2TARGET(scp)(scp)->device->id   // to 
target
-#define SCP2LUN(scp)   (u32)(scp)->device->lun // to LUN
+#define SCP2HOST(scp)  ((scp)->device->host)   // to host
+#define SCP2HOSTDATA(scp)  (SCP2HOST(scp)->hostdata)   // to 
soft state
+#define SCP2CHANNEL(scp)   ((scp)->device->channel)// to 
channel
+#define SCP2TARGET(scp)((scp)->device->id) // to 
target
+#define SCP2LUN(scp)   ((u32)(scp)->device->lun)   // to 
LUN
 
 // generic macro to convert scsi command and host to controller's soft state
 #define SCSIHOST2ADAP(host)(((caddr_t *)(host->hostdata))[0])
-#define SCP2ADAPTER(scp)   (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp))
+#define SCP2ADAPTER(scp)   ((adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp)))
 
 
 #define MRAID_IS_LOGICAL(adp, scp) \
-   (SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0
+   ((SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0)
 
 #define MRAID_IS_LOGICAL_SDEV(adp, sdev)   \
-   (sdev->channel == (adp)->max_channel) ? 1 : 0
+   ((sdev->channel == (adp)->max_channel) ? 1 : 0)
 
 /**
  * MRAID_GET_DEVICE_MAP - device ids
diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index b5a765b..b652a84 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -154,9 +154,9 @@
 #define MFI_INIT_CLEAR_HANDSHAKE   0x0008
 #define MFI_INIT_HOTPLUG   0x0010
 #define MFI_STOP_ADP   0x0020
-#define MFI_RESET_FLAGSMFI_INIT_READY| \
-   MFI_INIT_MFIMODE| \
-   MFI_INIT_ABORT
+#define MFI_RESET_FLAGS(MFI_INIT_READY | \
+   MFI_INIT_MFIMODE | \
+   MFI_INIT_ABORT)
 #define MFI_ADP_TRIGGER_SNAP_DUMP  0x0100
 #define MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE(0x01)
 
-- 
2.7.4



[PATCH v1 4/8] scsi: megaraid: clean up for open/close brace

2021-04-09 Thread Luo Jiaxing
There are few kinds of error about open/close brace is reported by
checkpatch.pl:

ERROR: open brace '{' following function definitions go on the next line
int
megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {

ERROR: else should follow close brace '}'
+   }
+   else

So fix them all.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/megaraid_mbox.c   | 57 ++---
 drivers/scsi/megaraid/megaraid_mm.c | 10 ++---
 drivers/scsi/megaraid/megaraid_sas_base.c   |  7 ++--
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 11 +++---
 4 files changed, 31 insertions(+), 54 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
b/drivers/scsi/megaraid/megaraid_mbox.c
index 6d76b15..d3fcaca 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -537,8 +537,7 @@ megaraid_detach_one(struct pci_dev *pdev)
pdev->subsystem_device));
 
return;
-   }
-   else {
+   } else {
con_log(CL_ANN, (KERN_NOTICE
"megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
pdev->vendor, pdev->device, pdev->subsystem_vendor,
@@ -1545,8 +1544,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct 
scsi_cmnd *scp, int *busy)
vaddr = (caddr_t) sg_virt(&sgl[0]);
 
memset(vaddr, 0, scp->cmnd[4]);
-   }
-   else {
+   } else {
con_log(CL_ANN, (KERN_WARNING
 "megaraid mailbox: invalid 
sg:%d\n",
 __LINE__));
@@ -1705,8 +1703,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct 
scsi_cmnd *scp, int *busy)
((uint32_t)scp->cmnd[7] << 16) |
((uint32_t)scp->cmnd[8] << 8) |
(uint32_t)scp->cmnd[9];
-   }
-   else {
+   } else {
con_log(CL_ANN, (KERN_WARNING
"megaraid: unsupported CDB length\n"));
 
@@ -1762,8 +1759,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct 
scsi_cmnd *scp, int *busy)
scp->result = (DID_BAD_TARGET << 16);
return NULL;
}
-   }
-   else { // Passthru device commands
+   } else { // Passthru device commands
 
// Do not allow access to target id > 15 or LUN > 7
if (target > 15 || SCP2LUN(scp) > 7) {
@@ -1830,8 +1826,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct 
scsi_cmnd *scp, int *busy)
mbox64->xferaddr_lo = (uint32_t)ccb->epthru_dma_h;
mbox64->xferaddr_hi = 0;
mbox->xferaddr  = 0x;
-   }
-   else {
+   } else {
mbox->cmd = MBOXCMD_PASSTHRU64;
 
megaraid_mbox_prepare_pthru(adapter, scb, scp);
@@ -1961,8 +1956,7 @@ megaraid_mbox_prepare_pthru(adapter_t *adapter, scb_t 
*scb,
pthru->dataxferlen  = scsi_bufflen(scp);
pthru->dataxferaddr = ccb->sgl_dma_h;
pthru->numsge   = megaraid_mbox_mksgl(adapter, scb);
-   }
-   else {
+   } else {
pthru->dataxferaddr = 0;
pthru->dataxferlen  = 0;
pthru->numsge   = 0;
@@ -2010,8 +2004,7 @@ megaraid_mbox_prepare_epthru(adapter_t *adapter, scb_t 
*scb,
epthru->dataxferlen = scsi_bufflen(scp);
epthru->dataxferaddr= ccb->sgl_dma_h;
epthru->numsge  = megaraid_mbox_mksgl(adapter, scb);
-   }
-   else {
+   } else {
epthru->dataxferaddr= 0;
epthru->dataxferlen = 0;
epthru->numsge  = 0;
@@ -2100,8 +2093,7 @@ megaraid_ack_sequence(adapter_t *adapter)
// a cmm command
scb = adapter->uscb_list + (completed[i] -
MBOX_MAX_SCSI_CMDS);
-   }
-   else {
+   } else {
// an os command
scb = adapter->kscb_list + completed[i];
}
@@ -2303,8 +2295,7 @@ megaraid_mbox_dpc(unsigned long devp)
 
scp->result = DRIVER_S

[PATCH v1 6/8] scsi: megaraid: clean up for code indent

2021-04-09 Thread Luo Jiaxing
Following error is reported by checkpatch.pl

ERROR: code indent should use tabs where possible
+^I^Iunsigned long arg)$

So fix them all.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/mega_common.h   | 2 +-
 drivers/scsi/megaraid/megaraid_mm.c   | 2 +-
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid/mega_common.h 
b/drivers/scsi/megaraid/mega_common.h
index 2a0981b..9a19eec 100644
--- a/drivers/scsi/megaraid/mega_common.h
+++ b/drivers/scsi/megaraid/mega_common.h
@@ -249,7 +249,7 @@ typedef struct {
  * ### Helper routines ###
  */
 #define LSI_DBGLVL mraid_debug_level   // each LLD must define a global
-   // mraid_debug_level
+   // mraid_debug_level
 
 #ifdef DEBUG
 #if defined (_ASSERT_PANIC)
diff --git a/drivers/scsi/megaraid/megaraid_mm.c 
b/drivers/scsi/megaraid/megaraid_mm.c
index 234885c..1d6244e 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -213,7 +213,7 @@ mraid_mm_ioctl(struct file *filep, unsigned int cmd, 
unsigned long arg)
 
 static long
 mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
-   unsigned long arg)
+   unsigned long arg)
 {
int err;
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 2b17529..f29a3716 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -4821,7 +4821,7 @@ megasas_ld_list_query(struct megasas_instance *instance, 
u8 query_type)
 
if (!cmd) {
dev_warn(&instance->pdev->dev,
-"megasas_ld_list_query: Failed to get cmd\n");
+"%s: Failed to get cmd\n", __func__);
return -ENOMEM;
}
 
-- 
2.7.4



[PATCH v1 0/8] scsi: megaraid: some misc clean up patches

2021-04-09 Thread Luo Jiaxing
There are several kinds of error are reported by checkpatch.pl.

So fix them together.

Luo Jiaxing (8):
  scsi: megaraid: clean up for white space
  scsi: megaraid_sas: use parentheses to enclose macros with complex
values
  scsi: megaraid: clean up for blank lines
  scsi: megaraid: clean up for open/close brace
  scsi: megaraid: clean up for "foo * bar"
  scsi: megaraid: clean up for code indent
  scsi: megaraid: clean up for trailing statements
  scsi: megaraid: clean up for static variable initialise to 0

 drivers/scsi/megaraid/mbox_defs.h|  23 +++---
 drivers/scsi/megaraid/mega_common.h  |  18 ++---
 drivers/scsi/megaraid/megaraid_ioctl.h   |  12 +--
 drivers/scsi/megaraid/megaraid_mbox.c| 115 ---
 drivers/scsi/megaraid/megaraid_mbox.h|   2 +-
 drivers/scsi/megaraid/megaraid_mm.c  |  66 +++
 drivers/scsi/megaraid/megaraid_mm.h  |   1 -
 drivers/scsi/megaraid/megaraid_sas.h |  52 +---
 drivers/scsi/megaraid/megaraid_sas_base.c|  69 +++-
 drivers/scsi/megaraid/megaraid_sas_debugfs.c |   1 -
 drivers/scsi/megaraid/megaraid_sas_fusion.c  |  16 ++--
 drivers/scsi/megaraid/megaraid_sas_fusion.h  |   1 -
 12 files changed, 149 insertions(+), 227 deletions(-)

-- 
2.7.4



[PATCH v1 8/8] scsi: megaraid: clean up for static variable initialise to 0

2021-04-09 Thread Luo Jiaxing
Following error is reported by checkpatch.pl:

ERROR: do not initialise statics to 0
+static int megaraid_expose_unconf_disks = 0;

So fix them.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/megaraid_mbox.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
b/drivers/scsi/megaraid/megaraid_mbox.c
index 486c01d..0f8fcbf 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -146,7 +146,7 @@ MODULE_VERSION(MEGARAID_VERSION);
 /*
  * Set to enable driver to expose unconfigured disk to kernel
  */
-static int megaraid_expose_unconf_disks = 0;
+static int megaraid_expose_unconf_disks;
 module_param_named(unconf_disks, megaraid_expose_unconf_disks, int, 0);
 MODULE_PARM_DESC(unconf_disks,
"Set to expose unconfigured disks to kernel (default=0)");
@@ -181,7 +181,7 @@ MODULE_PARM_DESC(cmd_per_lun,
  * This would result in non-disk devices being skipped during driver load
  * time. These can be later added though, using /proc/scsi/scsi
  */
-static unsigned int megaraid_fast_load = 0;
+static unsigned int megaraid_fast_load;
 module_param_named(fast_load, megaraid_fast_load, int, 0);
 MODULE_PARM_DESC(fast_load,
"Faster loading of the driver, skips physical devices! (default=0)");
-- 
2.7.4



[PATCH v1 3/8] scsi: megaraid: clean up for blank lines

2021-04-09 Thread Luo Jiaxing
There are some blank line alerts when running
checkpatch.pl, so fix them together here.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/mbox_defs.h|  1 -
 drivers/scsi/megaraid/megaraid_ioctl.h   |  4 ---
 drivers/scsi/megaraid/megaraid_mm.h  |  1 -
 drivers/scsi/megaraid/megaraid_sas.h | 46 
 drivers/scsi/megaraid/megaraid_sas_base.c| 23 --
 drivers/scsi/megaraid/megaraid_sas_debugfs.c |  1 -
 drivers/scsi/megaraid/megaraid_sas_fusion.c  |  5 ---
 drivers/scsi/megaraid/megaraid_sas_fusion.h  |  1 -
 8 files changed, 82 deletions(-)

diff --git a/drivers/scsi/megaraid/mbox_defs.h 
b/drivers/scsi/megaraid/mbox_defs.h
index 3efbfdb..e9b3093 100644
--- a/drivers/scsi/megaraid/mbox_defs.h
+++ b/drivers/scsi/megaraid/mbox_defs.h
@@ -244,7 +244,6 @@ typedef struct {
 } __attribute__ ((packed)) mraid_passthru_t;
 
 typedef struct {
-
uint32_tdataxferaddr_lo;
uint32_tdataxferaddr_hi;
mraid_passthru_tpthru32;
diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h 
b/drivers/scsi/megaraid/megaraid_ioctl.h
index d0ae6f9..87b880fe 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -112,7 +112,6 @@
  * : format sent by applications would be converted to this.
  */
 typedef struct uioc {
-
 /* User Apps: */
 
uint8_t signature[EXT_IOCTL_SIGN_SZ];
@@ -175,7 +174,6 @@ struct uioc_timeout {
  * that total size of the structure remains 256 bytes.
  */
 typedef struct mraid_hba_info {
-
uint16_tpci_vendor_id;
uint16_tpci_device_id;
uint16_tsubsys_vendor_id;
@@ -209,7 +207,6 @@ typedef struct mraid_hba_info {
  * @uid: unique id
  */
 typedef struct mcontroller {
-
uint64_tbase;
uint8_t irq;
uint8_t numldrv;
@@ -267,7 +264,6 @@ typedef struct mm_dmapool {
  */
 
 typedef struct mraid_mmadp {
-
 /* Filled by driver */
 
uint32_tunique_id;
diff --git a/drivers/scsi/megaraid/megaraid_mm.h 
b/drivers/scsi/megaraid/megaraid_mm.h
index bf40115..c48c1d9 100644
--- a/drivers/scsi/megaraid/megaraid_mm.h
+++ b/drivers/scsi/megaraid/megaraid_mm.h
@@ -58,7 +58,6 @@
  */
 
 typedef struct mimd {
-
uint32_t inlen;
uint32_t outlen;
 
diff --git a/drivers/scsi/megaraid/megaraid_sas.h 
b/drivers/scsi/megaraid/megaraid_sas.h
index b652a84..fb0fbeeb 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -336,7 +336,6 @@ enum _MR_CRASH_BUF_STATUS {
 #define MFI_MBOX_SIZE  12
 
 enum MR_EVT_CLASS {
-
MR_EVT_CLASS_DEBUG = -2,
MR_EVT_CLASS_PROGRESS = -1,
MR_EVT_CLASS_INFO = 0,
@@ -344,11 +343,9 @@ enum MR_EVT_CLASS {
MR_EVT_CLASS_CRITICAL = 2,
MR_EVT_CLASS_FATAL = 3,
MR_EVT_CLASS_DEAD = 4,
-
 };
 
 enum MR_EVT_LOCALE {
-
MR_EVT_LOCALE_LD = 0x0001,
MR_EVT_LOCALE_PD = 0x0002,
MR_EVT_LOCALE_ENCL = 0x0004,
@@ -362,7 +359,6 @@ enum MR_EVT_LOCALE {
 };
 
 enum MR_EVT_ARGS {
-
MR_EVT_ARGS_NONE,
MR_EVT_ARGS_CDB_SENSE,
MR_EVT_ARGS_LD,
@@ -824,7 +820,6 @@ struct MR_HOST_DEVICE_LIST {
  * SAS controller properties
  */
 struct megasas_ctrl_prop {
-
u16 seq_num;
u16 pred_fail_poll_interval;
u16 intr_throttle_count;
@@ -939,7 +934,6 @@ struct megasas_ctrl_info {
 * Host interface information
 */
struct {
-
u8 PCIX:1;
u8 PCIE:1;
u8 iSCSI:1;
@@ -949,14 +943,12 @@ struct megasas_ctrl_info {
u8 reserved_1[6];
u8 port_count;
u64 port_addr[8];
-
} __attribute__ ((packed)) host_interface;
 
/*
 * Device (backend) interface information
 */
struct {
-
u8 SPI:1;
u8 SAS_3G:1;
u8 SATA_1_5G:1;
@@ -965,7 +957,6 @@ struct megasas_ctrl_info {
u8 reserved_1[6];
u8 port_count;
u64 port_addr[8];
-
} __attribute__ ((packed)) device_interface;
 
/*
@@ -975,12 +966,10 @@ struct megasas_ctrl_info {
__le32 image_component_count;
 
struct {
-
char name[8];
char version[32];
char build_date[16];
char built_time[16];
-
} __attribute__ ((packed)) image_component[8];
 
/*
@@ -992,12 +981,10 @@ struct megasas_ctrl_info {
__le32 pending_image_component_count;
 
struct {
-
char name[8];
char version[32];
char build_date[16];
char build_time[16];
-
} __attribute__ ((packed)) pending_image_component[8];
 
u8 max_arms;
@@ -1013,13 +1000,11 @@ struct megasas_ctrl_info

[PATCH v1 1/8] scsi: megaraid: clean up for white space

2021-04-09 Thread Luo Jiaxing
Several kinds of error about white space is reported when running
checkpatch.pl:

ERROR: space required after that ',' (ctx:VxV)
+  "commands to complete\n",i,outstanding);

ERROR: trailing whitespace
+^I^I^Idma_pool_free(pool->handle, kioc->buf_vaddr, $

ERROR: need consistent spacing around '*' (ctx:WxV)
+   u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1);

so fix them together here.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/mbox_defs.h | 20 +--
 drivers/scsi/megaraid/megaraid_ioctl.h|  4 ++--
 drivers/scsi/megaraid/megaraid_mbox.c | 24 +++---
 drivers/scsi/megaraid/megaraid_mm.c   | 26 
 drivers/scsi/megaraid/megaraid_sas_base.c | 33 ---
 5 files changed, 58 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/megaraid/mbox_defs.h 
b/drivers/scsi/megaraid/mbox_defs.h
index f0ef8f7..5001624 100644
--- a/drivers/scsi/megaraid/mbox_defs.h
+++ b/drivers/scsi/megaraid/mbox_defs.h
@@ -588,7 +588,7 @@ typedef struct {
 typedef struct {
uint8_t channel;
uint8_t target;
-}__attribute__ ((packed)) adap_device_t;
+} __attribute__ ((packed)) adap_device_t;
 
 
 /**
@@ -600,7 +600,7 @@ typedef struct {
uint32_tstart_blk;
uint32_tnum_blks;
adap_device_t   device[MAX_ROW_SIZE_40LD];
-}__attribute__ ((packed)) adap_span_40ld_t;
+} __attribute__ ((packed)) adap_span_40ld_t;
 
 
 /**
@@ -612,7 +612,7 @@ typedef struct {
uint32_tstart_blk;
uint32_tnum_blks;
adap_device_t   device[MAX_ROW_SIZE_8LD];
-}__attribute__ ((packed)) adap_span_8ld_t;
+} __attribute__ ((packed)) adap_span_8ld_t;
 
 
 /**
@@ -647,7 +647,7 @@ typedef struct {
 typedef struct {
logdrv_param_t  lparam;
adap_span_40ld_tspan[SPAN_DEPTH_8_SPANS];
-}__attribute__ ((packed)) logdrv_40ld_t;
+} __attribute__ ((packed)) logdrv_40ld_t;
 
 
 /**
@@ -660,7 +660,7 @@ typedef struct {
 typedef struct {
logdrv_param_t  lparam;
adap_span_8ld_t span[SPAN_DEPTH_8_SPANS];
-}__attribute__ ((packed)) logdrv_8ld_span8_t;
+} __attribute__ ((packed)) logdrv_8ld_span8_t;
 
 
 /**
@@ -673,7 +673,7 @@ typedef struct {
 typedef struct {
logdrv_param_t  lparam;
adap_span_8ld_t span[SPAN_DEPTH_4_SPANS];
-}__attribute__ ((packed)) logdrv_8ld_span4_t;
+} __attribute__ ((packed)) logdrv_8ld_span4_t;
 
 
 /**
@@ -690,7 +690,7 @@ typedef struct {
uint8_t tag_depth;
uint8_t sync_neg;
uint32_tsize;
-}__attribute__ ((packed)) phys_drive_t;
+} __attribute__ ((packed)) phys_drive_t;
 
 
 /**
@@ -705,7 +705,7 @@ typedef struct {
uint8_t resvd[3];
logdrv_40ld_t   ldrv[MAX_LOGICAL_DRIVES_40LD];
phys_drive_tpdrv[MBOX_MAX_PHYSICAL_DRIVES];
-}__attribute__ ((packed)) disk_array_40ld_t;
+} __attribute__ ((packed)) disk_array_40ld_t;
 
 
 /**
@@ -722,7 +722,7 @@ typedef struct {
uint8_t resvd[3];
logdrv_8ld_span8_t  ldrv[MAX_LOGICAL_DRIVES_8LD];
phys_drive_tpdrv[MBOX_MAX_PHYSICAL_DRIVES];
-}__attribute__ ((packed)) disk_array_8ld_span8_t;
+} __attribute__ ((packed)) disk_array_8ld_span8_t;
 
 
 /**
@@ -739,7 +739,7 @@ typedef struct {
uint8_t resvd[3];
logdrv_8ld_span4_t  ldrv[MAX_LOGICAL_DRIVES_8LD];
phys_drive_tpdrv[MBOX_MAX_PHYSICAL_DRIVES];
-}__attribute__ ((packed)) disk_array_8ld_span4_t;
+} __attribute__ ((packed)) disk_array_8ld_span4_t;
 
 
 /**
diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h 
b/drivers/scsi/megaraid/megaraid_ioctl.h
index ae9c2ff..d0ae6f9 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -76,7 +76,7 @@
 #define DRVRTYPE_MBOX  0x0001  /* regular mbox driver  */
 #define DRVRTYPE_HPE   0x0002  /* new hpe driver   */
 
-#define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno) )
+#define MKADAP(adapno) (MEGAIOC_MAGIC << 8 | (adapno))
 #define GETADAP(mkadap)((mkadap) ^ MEGAIOC_MAGIC << 8)
 
 #define MAX_DMA_POOLS  5   /* 4k, 8k, 16k, 32k, 64k*/
@@ -148,7 +148,7 @@ typedef struct uioc {
 
uint8_t timedout;
 
-} __attribute__ ((aligned(1024),packed)) uioc_t;
+} __attribute__ ((aligned(1024), packed)) uioc_t;
 
 /* For on-stack uioc timers. */
 struct uioc_timeout {
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
b/drivers/scsi/megaraid/megaraid_mbox.c
index 145fde3..6d76b15 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -736,7 +736,7 @@ megaraid_init_mbox(adapter_t *adapter)
if (!raid_dev->baseaddr) {
 
con_log(CL_ANN, (KERN_WARNING
-   "megaraid: 

[PATCH v1 5/8] scsi: megaraid: clean up for "foo * bar"

2021-04-09 Thread Luo Jiaxing
Following error is reported by checkpatch.pl:

"foo * bar" should be "foo *bar"
+ struct megasas_iocpacket __user * user_ioc,

The format of the pointer variable must be "foo *bar", so fix
them.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/megaraid_ioctl.h| 4 ++--
 drivers/scsi/megaraid/megaraid_mbox.h | 2 +-
 drivers/scsi/megaraid/megaraid_mm.c   | 4 ++--
 drivers/scsi/megaraid/megaraid_sas_base.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h 
b/drivers/scsi/megaraid/megaraid_ioctl.h
index 87b880fe..9bc0250 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -126,7 +126,7 @@ typedef struct uioc {
uint8_t reserved[128];
 
 /* Driver Data: */
-   void __user *   user_data;
+   void __user *user_data;
uint32_tuser_data_len;
 
/* 64bit alignment */
@@ -138,7 +138,7 @@ typedef struct uioc {
dma_addr_t  pthru32_h;
 
struct list_headlist;
-   void(*done)(struct uioc*);
+   void(*done)(struct uioc *);
 
caddr_t buf_vaddr;
dma_addr_t  buf_paddr;
diff --git a/drivers/scsi/megaraid/megaraid_mbox.h 
b/drivers/scsi/megaraid/megaraid_mbox.h
index d2fe7f6..3c16d38 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.h
+++ b/drivers/scsi/megaraid/megaraid_mbox.h
@@ -189,7 +189,7 @@ typedef struct {
dma_addr_t  mbox_dma;
spinlock_t  mailbox_lock;
unsigned long   baseport;
-   void __iomem *  baseaddr;
+   void __iomem*baseaddr;
struct mraid_pci_blkmbox_pool[MBOX_MAX_SCSI_CMDS];
struct dma_pool *mbox_pool_handle;
struct mraid_pci_blkepthru_pool[MBOX_MAX_SCSI_CMDS];
diff --git a/drivers/scsi/megaraid/megaraid_mm.c 
b/drivers/scsi/megaraid/megaraid_mm.c
index 864cbb6..234885c 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -582,7 +582,7 @@ static uioc_t *
 mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
 {
uioc_t  *kioc;
-   struct list_head*   head;
+   struct list_head*head;
unsigned long   flags;
 
down(&adp->kioc_semaphore);
@@ -722,7 +722,7 @@ ioctl_done(uioc_t *kioc)
 {
uint32_tadapno;
int iterator;
-   mraid_mmadp_t*  adapter;
+   mraid_mmadp_t   *adapter;
 
/*
 * When the kioc returns from driver, make sure it still doesn't
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 40c77bb..2b17529 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -4402,7 +4402,7 @@ int megasas_alloc_cmds(struct megasas_instance *instance)
 * Allocate the dynamic array first and then allocate individual
 * commands.
 */
-   instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), 
GFP_KERNEL);
+   instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd *), 
GFP_KERNEL);
 
if (!instance->cmd_list) {
dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n");
@@ -8150,7 +8150,7 @@ static int megasas_set_crash_dump_params_ioctl(struct 
megasas_cmd *cmd)
  */
 static int
 megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
- struct megasas_iocpacket __user * user_ioc,
+ struct megasas_iocpacket __user *user_ioc,
  struct megasas_iocpacket *ioc)
 {
struct megasas_sge64 *kern_sge64 = NULL;
-- 
2.7.4



[PATCH v1 7/8] scsi: megaraid: clean up for trailing statements

2021-04-09 Thread Luo Jiaxing
Following error is reported by checkpatch.pl:
ERROR: trailing statements should be on next line
+   if (iterator++ == adapno) break;

So fix them.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/megaraid/megaraid_mbox.c | 30 --
 drivers/scsi/megaraid/megaraid_mm.c   | 24 
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
b/drivers/scsi/megaraid/megaraid_mbox.c
index d3fcaca..486c01d 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -709,7 +709,8 @@ megaraid_init_mbox(adapter_t *adapter)
 * controllers
 */
raid_dev = kzalloc(sizeof(mraid_device_t), GFP_KERNEL);
-   if (raid_dev == NULL) return -1;
+   if (!raid_dev)
+   return -1;
 
 
/*
@@ -2051,7 +2052,8 @@ megaraid_ack_sequence(adapter_t *adapter)
 * interrupt line low.
 */
dword = RDOUTDOOR(raid_dev);
-   if (dword != 0x10001234) break;
+   if (dword != 0x10001234)
+   break;
 
handled = 1;
 
@@ -2074,7 +2076,8 @@ megaraid_ack_sequence(adapter_t *adapter)
 
// wait for valid command index to post
for (j = 0; j < 0xF; j++) {
-   if (mbox->completed[i] != 0xFF) break;
+   if (mbox->completed[i] != 0xFF)
+   break;
rmb();
}
completed[i]= mbox->completed[i];
@@ -2182,7 +2185,8 @@ megaraid_mbox_dpc(unsigned long devp)
uioc_t  *kioc;
 
 
-   if (!adapter) return;
+   if (!adapter)
+   return;
 
raid_dev = ADAP2RAIDDEV(adapter);
 
@@ -2796,7 +2800,8 @@ mbox_post_sync_cmd_fast(adapter_t *adapter, uint8_t 
raw_mbox[])
mbox= raid_dev->mbox;
 
// return immediately if the mailbox is busy
-   if (mbox->busy) return -1;
+   if (mbox->busy)
+   return -1;
 
// Copy mailbox data into host structure
memcpy((caddr_t)mbox, (caddr_t)raw_mbox, 14);
@@ -2811,7 +2816,8 @@ mbox_post_sync_cmd_fast(adapter_t *adapter, uint8_t 
raw_mbox[])
WRINDOOR(raid_dev, raid_dev->mbox_dma | 0x1);
 
for (i = 0; i < MBOX_SYNC_WAIT_CNT; i++) {
-   if (mbox->numstatus != 0xFF) break;
+   if (mbox->numstatus != 0xFF)
+   break;
rmb();
udelay(MBOX_SYNC_DELAY_200);
}
@@ -2848,8 +2854,10 @@ megaraid_busywait_mbox(mraid_device_t *raid_dev)
msleep(1);
}
 
-   if (i < 1000) return 0;
-   else return -1;
+   if (i < 1000)
+   return 0;
+   else
+   return -1;
 }
 
 
@@ -3137,7 +3145,8 @@ megaraid_mbox_get_max_sg(adapter_t *adapter)
nsg =  MBOX_DEFAULT_SG_SIZE;
}
 
-   if (nsg > MBOX_MAX_SG_SIZE) nsg = MBOX_MAX_SG_SIZE;
+   if (nsg > MBOX_MAX_SG_SIZE)
+   nsg = MBOX_MAX_SG_SIZE;
 
return nsg;
 }
@@ -3317,7 +3326,8 @@ megaraid_mbox_display_scb(adapter_t *adapter, scb_t *scb)
mbox->numsectors, mbox->lba, mbox->xferaddr, mbox->logdrv,
mbox->numsge));
 
-   if (!scp) return;
+   if (!scp)
+   return;
 
con_log(level, (KERN_NOTICE "scsi cmnd: "));
 
diff --git a/drivers/scsi/megaraid/megaraid_mm.c 
b/drivers/scsi/megaraid/megaraid_mm.c
index 1d6244e..5e889cb 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -88,7 +88,8 @@ mraid_mm_open(struct inode *inode, struct file *filep)
/*
 * Only allow superuser to access private ioctl interface
 */
-   if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
+   if (!capable(CAP_SYS_ADMIN))
+   return (-EACCES);
 
return 0;
 }
@@ -256,7 +257,8 @@ mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
iterator = 0;
 
list_for_each_entry(adapter, &adapters_list_g, list) {
-   if (iterator++ == adapno) break;
+   if (iterator++ == adapno)
+   break;
}
 
if (!adapter) {
@@ -408,8 +410,10 @@ mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, 
uioc_t *kioc)
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
return (-ENOMEM);
 
-   if (mimd.outlen) kioc->data_dir  = UIOC_RD;
-   if (mimd.inlen) kioc->data_dir |= UIOC_WR;
+   if (mimd.outlen)
+   kioc->data_dir  = UIOC_RD;
+   if (mimd.inlen)
+   kioc->data_dir |= UIOC_WR;
 
break;
 

[PATCH v3 1/2] scsi: pm8001: clean up for white space

2021-04-08 Thread Luo Jiaxing
Some errors are found like below when run checkpatch.pl

ERROR: space prohibited before that ',' (ctx:WxW)
+int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb);

It all about white space, so fix them.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c | 20 +---
 drivers/scsi/pm8001/pm8001_ctl.h |  5 +
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 6 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index 12035ba..90b816f 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -369,24 +369,22 @@ static ssize_t pm8001_ctl_aap_log_show(struct device 
*cdev,
struct Scsi_Host *shost = class_to_shost(cdev);
struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+   u8 *ptr = (u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr;
int i;
-#define AAP1_MEMMAP(r, c) \
-   (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
-   + (c)))
 
char *str = buf;
int max = 2;
for (i = 0; i < max; i++) {
str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
   "0x%08x 0x%08x\n",
-  AAP1_MEMMAP(i, 0),
-  AAP1_MEMMAP(i, 4),
-  AAP1_MEMMAP(i, 8),
-  AAP1_MEMMAP(i, 12),
-  AAP1_MEMMAP(i, 16),
-  AAP1_MEMMAP(i, 20),
-  AAP1_MEMMAP(i, 24),
-  AAP1_MEMMAP(i, 28));
+  pm8001_ctl_aap1_memmap(ptr, i, 0),
+  pm8001_ctl_aap1_memmap(ptr, i, 4),
+  pm8001_ctl_aap1_memmap(ptr, i, 8),
+  pm8001_ctl_aap1_memmap(ptr, i, 12),
+  pm8001_ctl_aap1_memmap(ptr, i, 16),
+  pm8001_ctl_aap1_memmap(ptr, i, 20),
+  pm8001_ctl_aap1_memmap(ptr, i, 24),
+  pm8001_ctl_aap1_memmap(ptr, i, 28));
}
 
return str - buf;
diff --git a/drivers/scsi/pm8001/pm8001_ctl.h b/drivers/scsi/pm8001/pm8001_ctl.h
index d0d43a2..4743f0d 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.h
+++ b/drivers/scsi/pm8001/pm8001_ctl.h
@@ -59,5 +59,10 @@
 #define SYSFS_OFFSET1024
 #define PM80XX_IB_OB_QUEUE_SIZE (32 * 1024)
 #define PM8001_IB_OB_QUEUE_SIZE (16 * 1024)
+
+static inline u32 pm8001_ctl_aap1_memmap(u8 *ptr, int idx, int off)
+{
+   return *(u32 *)(ptr + idx * 32 + off);
+}
 #endif /* PM8001_CTL_H_INCLUDED */
 
diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 49bf2f7..6887fa3 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -1826,7 +1826,7 @@ static void pm8001_send_read_log(struct pm8001_hba_info 
*pm8001_ha,
  * that the task has been finished.
  */
 static void
-mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
+mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
struct pm8001_ccb_info *ccb;
@@ -2058,7 +2058,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion */
-static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
unsigned long flags;
@@ -2294,9 +2294,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
(status != IO_UNDERFLOW)) {
if (!((t->dev->parent) &&
(dev_is_expander(t->dev->parent->dev_type {
-   for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++)
+   for (i = 0, j = 4; j <= 7 && i <= 3; i++, j++)
sata_addr_low[i] = pm8001_ha->sas_addr[j];
-   for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++)
+   for (i = 0, j = 0; j <= 3 && i <= 3; i++, j++)
sata_addr_hi[i] = pm8001_ha->sas_addr[j];
memcpy(&temp_sata_addr_low, sata_addr_low,
sizeof(sata_addr_low));
@@ -2625,7 +2625,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion

[PATCH v3 2/2] scsi: pm8001: clean up for open brace

2021-04-08 Thread Luo Jiaxing
There are few error about open brace is reported by checkpatch.pl:

ERROR: that open brace { should be on the previous line
+static struct error_fw flash_error_table[] =
+{

So fix them all.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index 90b816f..8c253b0 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -645,8 +645,7 @@ struct flash_command {
  int code;
 };
 
-static struct flash_command flash_command_table[] =
-{
+static const struct flash_command flash_command_table[] = {
  {"set_nvmd",FLASH_CMD_SET_NVMD},
  {"update",  FLASH_CMD_UPDATE},
  {"",FLASH_CMD_NONE} /* Last entry should be NULL. */
@@ -657,8 +656,7 @@ struct error_fw {
  int err_code;
 };
 
-static struct error_fw flash_error_table[] =
-{
+static const struct error_fw flash_error_table[] = {
  {"Failed to open fw image file",  FAIL_OPEN_BIOS_FILE},
  {"image header mismatch", FLASH_UPDATE_HDR_ERR},
  {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
-- 
2.7.4



[PATCH v3 0/2] scsi: pm8001: tiny clean up patches

2021-04-08 Thread Luo Jiaxing
Several error is reported by checkpatch.pl, here are two patches to clean
them up.

---
   v1->v2:
  1. modify AAP1_MEMMAP() to inline function
  2. set flash_command_table and flash_error_table as const
   v2->v3:
  1. use lower case names for AAP1_MEMMAP
---
Luo Jiaxing (2):
  scsi: pm8001: clean up for white space
  scsi: pm8001: clean up for open brace

 drivers/scsi/pm8001/pm8001_ctl.c | 26 +++---
 drivers/scsi/pm8001/pm8001_ctl.h |  5 +
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 6 files changed, 41 insertions(+), 40 deletions(-)

-- 
2.7.4



[PATCH v2 1/2] scsi: pm8001: clean up for white space

2021-04-07 Thread Luo Jiaxing
Some errors are found like below when run checkpatch.pl

ERROR: space prohibited before that ',' (ctx:WxW)
+int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb);

It all about white space, so fix them.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c | 20 +---
 drivers/scsi/pm8001/pm8001_ctl.h |  5 +
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 6 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index 12035ba..f5de47f 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -369,24 +369,22 @@ static ssize_t pm8001_ctl_aap_log_show(struct device 
*cdev,
struct Scsi_Host *shost = class_to_shost(cdev);
struct sas_ha_struct *sha = SHOST_TO_SAS_HA(shost);
struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
+   u8 *ptr = (u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr;
int i;
-#define AAP1_MEMMAP(r, c) \
-   (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
-   + (c)))
 
char *str = buf;
int max = 2;
for (i = 0; i < max; i++) {
str += sprintf(str, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x"
   "0x%08x 0x%08x\n",
-  AAP1_MEMMAP(i, 0),
-  AAP1_MEMMAP(i, 4),
-  AAP1_MEMMAP(i, 8),
-  AAP1_MEMMAP(i, 12),
-  AAP1_MEMMAP(i, 16),
-  AAP1_MEMMAP(i, 20),
-  AAP1_MEMMAP(i, 24),
-  AAP1_MEMMAP(i, 28));
+  AAP1_MEMMAP(ptr, i, 0),
+  AAP1_MEMMAP(ptr, i, 4),
+  AAP1_MEMMAP(ptr, i, 8),
+  AAP1_MEMMAP(ptr, i, 12),
+  AAP1_MEMMAP(ptr, i, 16),
+  AAP1_MEMMAP(ptr, i, 20),
+  AAP1_MEMMAP(ptr, i, 24),
+  AAP1_MEMMAP(ptr, i, 28));
}
 
return str - buf;
diff --git a/drivers/scsi/pm8001/pm8001_ctl.h b/drivers/scsi/pm8001/pm8001_ctl.h
index d0d43a2..380d96a 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.h
+++ b/drivers/scsi/pm8001/pm8001_ctl.h
@@ -59,5 +59,10 @@
 #define SYSFS_OFFSET1024
 #define PM80XX_IB_OB_QUEUE_SIZE (32 * 1024)
 #define PM8001_IB_OB_QUEUE_SIZE (16 * 1024)
+
+static inline u32 AAP1_MEMMAP(u8 *ptr, int idx, int off)
+{
+   return *(u32 *)(ptr + idx * 32 + off);
+}
 #endif /* PM8001_CTL_H_INCLUDED */
 
diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 49bf2f7..6887fa3 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -1826,7 +1826,7 @@ static void pm8001_send_read_log(struct pm8001_hba_info 
*pm8001_ha,
  * that the task has been finished.
  */
 static void
-mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
+mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
struct pm8001_ccb_info *ccb;
@@ -2058,7 +2058,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion */
-static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
unsigned long flags;
@@ -2294,9 +2294,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
(status != IO_UNDERFLOW)) {
if (!((t->dev->parent) &&
(dev_is_expander(t->dev->parent->dev_type {
-   for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++)
+   for (i = 0, j = 4; j <= 7 && i <= 3; i++, j++)
sata_addr_low[i] = pm8001_ha->sas_addr[j];
-   for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++)
+   for (i = 0, j = 0; j <= 3 && i <= 3; i++, j++)
sata_addr_hi[i] = pm8001_ha->sas_addr[j];
memcpy(&temp_sata_addr_low, sata_addr_low,
sizeof(sata_addr_low));
@@ -2625,7 +2625,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion */
-static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+static void 

[PATCH v2 2/2] scsi: pm8001: clean up for open brace

2021-04-07 Thread Luo Jiaxing
There are few error about open brace is reported by checkpatch.pl:

ERROR: that open brace { should be on the previous line
+static struct error_fw flash_error_table[] =
+{

So fix them all.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index f5de47f..ffd3ee9 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -645,8 +645,7 @@ struct flash_command {
  int code;
 };
 
-static struct flash_command flash_command_table[] =
-{
+static const struct flash_command flash_command_table[] = {
  {"set_nvmd",FLASH_CMD_SET_NVMD},
  {"update",  FLASH_CMD_UPDATE},
  {"",FLASH_CMD_NONE} /* Last entry should be NULL. */
@@ -657,8 +656,7 @@ struct error_fw {
  int err_code;
 };
 
-static struct error_fw flash_error_table[] =
-{
+static const struct error_fw flash_error_table[] = {
  {"Failed to open fw image file",  FAIL_OPEN_BIOS_FILE},
  {"image header mismatch", FLASH_UPDATE_HDR_ERR},
  {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
-- 
2.7.4



[PATCH v2 0/2] scsi: pm8001: tiny clean up patches

2021-04-07 Thread Luo Jiaxing
Several error is reported by checkpatch.pl, here are two patches to clean
them up.

---
   v1->v2:
  1. modify AAP1_MEMMAP() to inline function
  2. set flash_command_table and flash_error_table as const
---

Luo Jiaxing (2):
  scsi: pm8001: clean up for white space
  scsi: pm8001: clean up for open brace

 drivers/scsi/pm8001/pm8001_ctl.c | 26 +++---
 drivers/scsi/pm8001/pm8001_ctl.h |  5 +
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 6 files changed, 41 insertions(+), 40 deletions(-)

-- 
2.7.4



[PATCH v1 0/2] scsi: pm8001: tiny clean up patches

2021-04-02 Thread Luo Jiaxing
Several error is reported by checkpatch.pl, here are two patches to clean
them up.

Luo Jiaxing (2):
  scsi: pm8001: clean up for white space
  scsi: pm8001: clean up for open brace

 drivers/scsi/pm8001/pm8001_ctl.c |  8 +++-
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 5 files changed, 28 insertions(+), 30 deletions(-)

-- 
2.7.4



[PATCH v1 1/2] scsi: pm8001: clean up for white space

2021-04-02 Thread Luo Jiaxing
Many error are found like below when run checkpatch.pl

ERROR: space prohibited before that ',' (ctx:WxW)
+int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb);

It all about white space, so fix them.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c |  2 +-
 drivers/scsi/pm8001/pm8001_hwi.c | 14 +++---
 drivers/scsi/pm8001/pm8001_sas.c | 20 ++--
 drivers/scsi/pm8001/pm8001_sas.h |  2 +-
 drivers/scsi/pm8001/pm80xx_hwi.c | 14 +++---
 5 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index 12035ba..ffb4387 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -371,7 +371,7 @@ static ssize_t pm8001_ctl_aap_log_show(struct device *cdev,
struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
int i;
 #define AAP1_MEMMAP(r, c) \
-   (*(u32 *)((u8*)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
+   (*(u32 *)((u8 *)pm8001_ha->memoryMap.region[AAP1].virt_ptr + (r) * 32 \
+ (c)))
 
char *str = buf;
diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 49bf2f7..6887fa3 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -1826,7 +1826,7 @@ static void pm8001_send_read_log(struct pm8001_hba_info 
*pm8001_ha,
  * that the task has been finished.
  */
 static void
-mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , void *piomb)
+mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
struct pm8001_ccb_info *ccb;
@@ -2058,7 +2058,7 @@ mpi_ssp_completion(struct pm8001_hba_info *pm8001_ha , 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion */
-static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+static void mpi_ssp_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
unsigned long flags;
@@ -2294,9 +2294,9 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
(status != IO_UNDERFLOW)) {
if (!((t->dev->parent) &&
(dev_is_expander(t->dev->parent->dev_type {
-   for (i = 0 , j = 4; j <= 7 && i <= 3; i++ , j++)
+   for (i = 0, j = 4; j <= 7 && i <= 3; i++, j++)
sata_addr_low[i] = pm8001_ha->sas_addr[j];
-   for (i = 0 , j = 0; j <= 3 && i <= 3; i++ , j++)
+   for (i = 0, j = 0; j <= 3 && i <= 3; i++, j++)
sata_addr_hi[i] = pm8001_ha->sas_addr[j];
memcpy(&temp_sata_addr_low, sata_addr_low,
sizeof(sata_addr_low));
@@ -2625,7 +2625,7 @@ mpi_sata_completion(struct pm8001_hba_info *pm8001_ha, 
void *piomb)
 }
 
 /*See the comments for mpi_ssp_completion */
-static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+static void mpi_sata_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
struct sas_task *t;
struct task_status_struct *ts;
@@ -3602,7 +3602,7 @@ int pm8001_mpi_fw_flash_update_resp(struct 
pm8001_hba_info *pm8001_ha,
return 0;
 }
 
-int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha , void *piomb)
+int pm8001_mpi_general_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
u32 status;
int i;
@@ -3685,7 +3685,7 @@ int pm8001_mpi_task_abort_resp(struct pm8001_hba_info 
*pm8001_ha, void *piomb)
  * @pm8001_ha: our hba card information
  * @piomb: IO message buffer
  */
-static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void* piomb)
+static int mpi_hw_event(struct pm8001_hba_info *pm8001_ha, void *piomb)
 {
unsigned long flags;
struct hw_event_resp *pPayload =
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index a98d449..43b77ac 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -877,8 +877,8 @@ static void pm8001_dev_gone_notify(struct domain_device 
*dev)
   pm8001_dev->device_id, pm8001_dev->dev_type);
if (atomic_read(&pm8001_dev->running_req)) {
spin_unlock_irqrestore(&pm8001_ha->lock, flags);
-   pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev ,
-   dev, 1, 0);
+   pm8001_exec_internal_task_abort(pm8001_ha, pm8001_dev,
+   dev, 1, 0);
while (atomic_read(&pm8001_dev->running_req))
msleep(20);
spin_lock_irqsave

[PATCH v1 2/2] scsi: pm8001: clean up for open brace

2021-04-02 Thread Luo Jiaxing
There are few error about open brace is reported by checkpatch.pl:

ERROR: that open brace { should be on the previous line
+static struct error_fw flash_error_table[] =
+{

So fix them all.

Signed-off-by: Jianqin Xie 
Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/pm8001/pm8001_ctl.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_ctl.c b/drivers/scsi/pm8001/pm8001_ctl.c
index ffb4387..8802fe4 100644
--- a/drivers/scsi/pm8001/pm8001_ctl.c
+++ b/drivers/scsi/pm8001/pm8001_ctl.c
@@ -647,8 +647,7 @@ struct flash_command {
  int code;
 };
 
-static struct flash_command flash_command_table[] =
-{
+static struct flash_command flash_command_table[] = {
  {"set_nvmd",FLASH_CMD_SET_NVMD},
  {"update",  FLASH_CMD_UPDATE},
  {"",FLASH_CMD_NONE} /* Last entry should be NULL. */
@@ -659,8 +658,7 @@ struct error_fw {
  int err_code;
 };
 
-static struct error_fw flash_error_table[] =
-{
+static struct error_fw flash_error_table[] = {
  {"Failed to open fw image file",  FAIL_OPEN_BIOS_FILE},
  {"image header mismatch", FLASH_UPDATE_HDR_ERR},
  {"image offset mismatch", FLASH_UPDATE_OFFSET_ERR},
-- 
2.7.4



[PATCH v1 1/2] scsi: libsas: make switch and case at the same indent in sas_to_ata_err()

2021-03-25 Thread Luo Jiaxing
One checkpatch error is found in sas_to_ata_err() that switch and case is
not at the same indent. So fix it.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/libsas/sas_ata.c | 74 ---
 1 file changed, 34 insertions(+), 40 deletions(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 9f7fe67..4e4b55d 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -35,46 +35,40 @@ static enum ata_completion_errors sas_to_ata_err(struct 
task_status_struct *ts)
/* ts->resp == SAS_TASK_COMPLETE */
/* task delivered, what happened afterwards? */
switch (ts->stat) {
-   case SAS_DEV_NO_RESPONSE:
-   return AC_ERR_TIMEOUT;
-
-   case SAS_INTERRUPTED:
-   case SAS_PHY_DOWN:
-   case SAS_NAK_R_ERR:
-   return AC_ERR_ATA_BUS;
-
-
-   case SAS_DATA_UNDERRUN:
-   /*
-* Some programs that use the taskfile interface
-* (smartctl in particular) can cause underrun
-* problems.  Ignore these errors, perhaps at our
-* peril.
-*/
-   return 0;
-
-   case SAS_DATA_OVERRUN:
-   case SAS_QUEUE_FULL:
-   case SAS_DEVICE_UNKNOWN:
-   case SAS_SG_ERR:
-   return AC_ERR_INVALID;
-
-   case SAS_OPEN_TO:
-   case SAS_OPEN_REJECT:
-   pr_warn("%s: Saw error %d.  What to do?\n",
-   __func__, ts->stat);
-   return AC_ERR_OTHER;
-
-   case SAM_STAT_CHECK_CONDITION:
-   case SAS_ABORTED_TASK:
-   return AC_ERR_DEV;
-
-   case SAS_PROTO_RESPONSE:
-   /* This means the ending_fis has the error
-* value; return 0 here to collect it */
-   return 0;
-   default:
-   return 0;
+   case SAS_DEV_NO_RESPONSE:
+   return AC_ERR_TIMEOUT;
+   case SAS_INTERRUPTED:
+   case SAS_PHY_DOWN:
+   case SAS_NAK_R_ERR:
+   return AC_ERR_ATA_BUS;
+   case SAS_DATA_UNDERRUN:
+   /*
+* Some programs that use the taskfile interface
+* (smartctl in particular) can cause underrun
+* problems.  Ignore these errors, perhaps at our
+* peril.
+*/
+   return 0;
+   case SAS_DATA_OVERRUN:
+   case SAS_QUEUE_FULL:
+   case SAS_DEVICE_UNKNOWN:
+   case SAS_SG_ERR:
+   return AC_ERR_INVALID;
+   case SAS_OPEN_TO:
+   case SAS_OPEN_REJECT:
+   pr_warn("%s: Saw error %d.  What to do?\n",
+   __func__, ts->stat);
+   return AC_ERR_OTHER;
+   case SAM_STAT_CHECK_CONDITION:
+   case SAS_ABORTED_TASK:
+   return AC_ERR_DEV;
+   case SAS_PROTO_RESPONSE:
+   /* This means the ending_fis has the error
+* value; return 0 here to collect it
+*/
+   return 0;
+   default:
+   return 0;
}
 }
 
-- 
2.7.4



[PATCH v1 2/2] scsi: libsas: clean up for white spaces

2021-03-25 Thread Luo Jiaxing
Some checkpatch errors are found that some white spaces are missing or
being used inappropriately. So fix them all.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/libsas/sas_discover.c |  2 +-
 drivers/scsi/libsas/sas_expander.c | 15 ---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/libsas/sas_discover.c 
b/drivers/scsi/libsas/sas_discover.c
index 4a39848..3692817 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -75,7 +75,7 @@ static int sas_get_port_device(struct asd_sas_port *port)
struct dev_to_host_fis *fis =
(struct dev_to_host_fis *) dev->frame_rcvd;
if (fis->interrupt_reason == 1 && fis->lbal == 1 &&
-   fis->byte_count_low==0x69 && fis->byte_count_high == 0x96
+   fis->byte_count_low == 0x69 && fis->byte_count_high == 0x96
&& (fis->device & ~0x10) == 0)
dev->dev_type = SAS_SATA_PM;
else
diff --git a/drivers/scsi/libsas/sas_expander.c 
b/drivers/scsi/libsas/sas_expander.c
index ebb55e4..fc6b9d8 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -553,7 +553,7 @@ static int sas_ex_manuf_info(struct domain_device *dev)
 
mi_req[1] = SMP_REPORT_MANUF_INFO;
 
-   res = smp_execute_task(dev, mi_req, MI_REQ_SIZE, mi_resp,MI_RESP_SIZE);
+   res = smp_execute_task(dev, mi_req, MI_REQ_SIZE, mi_resp, MI_RESP_SIZE);
if (res) {
pr_notice("MI: ex %016llx failed:0x%x\n",
  SAS_ADDR(dev->sas_addr), res);
@@ -594,13 +594,13 @@ int sas_smp_phy_control(struct domain_device *dev, int 
phy_id,
 
pc_req[1] = SMP_PHY_CONTROL;
pc_req[9] = phy_id;
-   pc_req[10]= phy_func;
+   pc_req[10] = phy_func;
if (rates) {
pc_req[32] = rates->minimum_linkrate << 4;
pc_req[33] = rates->maximum_linkrate << 4;
}
 
-   res = smp_execute_task(dev, pc_req, PC_REQ_SIZE, pc_resp,PC_RESP_SIZE);
+   res = smp_execute_task(dev, pc_req, PC_REQ_SIZE, pc_resp, PC_RESP_SIZE);
if (res) {
pr_err("ex %016llx phy%02d PHY control failed: %d\n",
   SAS_ADDR(dev->sas_addr), phy_id, res);
@@ -678,7 +678,7 @@ int sas_smp_get_phy_events(struct sas_phy *phy)
req[9] = phy->number;
 
res = smp_execute_task(dev, req, RPEL_REQ_SIZE,
-   resp, RPEL_RESP_SIZE);
+  resp, RPEL_RESP_SIZE);
 
if (res)
goto out;
@@ -714,7 +714,7 @@ int sas_get_report_phy_sata(struct domain_device *dev, int 
phy_id,
rps_req[9] = phy_id;
 
res = smp_execute_task(dev, rps_req, RPS_REQ_SIZE,
-   rps_resp, RPS_RESP_SIZE);
+  rps_resp, RPS_RESP_SIZE);
 
/* 0x34 is the FIS type for the D2H fis.  There's a potential
 * standards cockup here.  sas-2 explicitly specifies the FIS
@@ -1117,7 +1117,7 @@ static int sas_ex_discover_dev(struct domain_device *dev, 
int phy_id)
 */
if (SAS_ADDR(ex->ex_phy[i].attached_sas_addr) ==
SAS_ADDR(child->sas_addr)) {
-   ex->ex_phy[i].phy_state= PHY_DEVICE_DISCOVERED;
+   ex->ex_phy[i].phy_state = PHY_DEVICE_DISCOVERED;
if (sas_ex_join_wide_port(dev, i))
pr_debug("Attaching ex phy%02d to wide 
port %016llx\n",
 i, 
SAS_ADDR(ex->ex_phy[i].attached_sas_addr));
@@ -1533,7 +1533,8 @@ static int sas_configure_phy(struct domain_device *dev, 
int phy_id,
if (res)
return res;
if (include ^ present)
-   return sas_configure_set(dev, phy_id, sas_addr, index,include);
+   return sas_configure_set(dev, phy_id, sas_addr, index,
+include);
 
return res;
 }
-- 
2.7.4



[PATCH v1 0/2] scsi: libsas: few clean up patches

2021-03-25 Thread Luo Jiaxing
Two types of errors are detected by the checkpatch.
1. Alignment between switches and cases
2. Improper use of some spaces

Here are the clean up patches.

Luo Jiaxing (2):
  scsi: libsas: make switch and case at the same indent in
sas_to_ata_err()
  scsi: libsas: clean up for white spaces

 drivers/scsi/libsas/sas_ata.c  | 74 ++
 drivers/scsi/libsas/sas_discover.c |  2 +-
 drivers/scsi/libsas/sas_expander.c | 15 
 3 files changed, 43 insertions(+), 48 deletions(-)

-- 
2.7.4



[PATCH v1] ata: ahci: Disable SXS for Hisilicon Kunpeng920

2021-03-12 Thread Luo Jiaxing
From: Xingui Yang 

On Hisilicon Kunpeng920, ESP is set to 1 by default for all ports of
SATA controller. In some scenarios, some ports are not external SATA ports,
and it cause disks connected to these ports to be identified as removable
disks. So disable the SXS capability on the software side to prevent users
from mistakenly considering non-removable disks as removable disks and
performing related operations.

Signed-off-by: Xingui Yang 
Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
---
 drivers/ata/ahci.c| 5 +
 drivers/ata/ahci.h| 1 +
 drivers/ata/libahci.c | 5 +
 3 files changed, 11 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 00ba8e5..33192a8 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1772,6 +1772,11 @@ static int ahci_init_one(struct pci_dev *pdev, const 
struct pci_device_id *ent)
hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;
 
 #ifdef CONFIG_ARM64
+   if (pdev->vendor == PCI_VENDOR_ID_HUAWEI &&
+   pdev->device == 0xa235 &&
+   pdev->revision < 0x30)
+   hpriv->flags |= AHCI_HFLAG_NO_SXS;
+
if (pdev->vendor == 0x177d && pdev->device == 0xa01c)
hpriv->irq_handler = ahci_thunderx_irq_handler;
 #endif
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 98b8baa..d1f284f 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -242,6 +242,7 @@ enum {
suspend/resume */
AHCI_HFLAG_IGN_NOTSUPP_POWER_ON = (1 << 27), /* ignore -EOPNOTSUPP
from phy_power_on() */
+   AHCI_HFLAG_NO_SXS   = (1 << 28), /* SXS not supported */
 
/* ap->flags bits */
 
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index ea5bf5f..fec2e97 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -493,6 +493,11 @@ void ahci_save_initial_config(struct device *dev, struct 
ahci_host_priv *hpriv)
cap |= HOST_CAP_ALPM;
}
 
+   if ((cap & HOST_CAP_SXS) && (hpriv->flags & AHCI_HFLAG_NO_SXS)) {
+   dev_info(dev, "controller does not support SXS, disabling 
CAP_SXS\n");
+   cap &= ~HOST_CAP_SXS;
+   }
+
if (hpriv->force_port_map && port_map != hpriv->force_port_map) {
dev_info(dev, "forcing port_map 0x%x -> 0x%x\n",
 port_map, hpriv->force_port_map);
-- 
2.7.4



[PATCH v1] drm/nouveau/device: use snprintf() to replace strncpy() to avoid NUL-terminated string loss

2021-03-08 Thread Luo Jiaxing
Following warning is found when using W=1 to build kernel:

In function ‘nvkm_udevice_info’,
inlined from ‘nvkm_udevice_mthd’ at 
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:195:10:
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:164:2: warning: ‘strncpy’ 
specified bound 16 equals destination size [-Wstringop-truncation]
  164 |  strncpy(args->v0.chip, device->chip->name, sizeof(args->v0.chip));
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:165:2: warning: ‘strncpy’ 
specified bound 64 equals destination size [-Wstringop-truncation]
  165 |  strncpy(args->v0.name, device->name, sizeof(args->v0.name));

The reason of this warning is strncpy() does not guarantee that the
destination buffer will be NUL terminated. If the length of source string
is bigger than number we set by third input parameter, only a part of
characters is copied to the destination, and no NUL-terminated string is
automatically added. There are some potential risks.

So use snprintf() to replace strncpy().

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/nouveau/nvkm/engine/device/user.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
index fea9d8f..4bf65bb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
@@ -161,8 +161,8 @@ nvkm_udevice_info(struct nvkm_udevice *udev, void *data, 
u32 size)
if (imem && args->v0.ram_size > 0)
args->v0.ram_user = args->v0.ram_user - imem->reserved;
 
-   strncpy(args->v0.chip, device->chip->name, sizeof(args->v0.chip));
-   strncpy(args->v0.name, device->name, sizeof(args->v0.name));
+   snprintf(args->v0.chip, sizeof(args->v0.chip), "%s", 
device->chip->name);
+   snprintf(args->v0.name, sizeof(args->v0.name), "%s", device->name);
return 0;
 }
 
-- 
2.7.4



[PATCH v1] drm/nouveau/device: append a NUL-terminated character for the string which filled by strncpy()

2021-02-25 Thread Luo Jiaxing
Following warning is found when using W=1 to build kernel:

In function ‘nvkm_udevice_info’,
inlined from ‘nvkm_udevice_mthd’ at 
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:195:10:
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:164:2: warning: ‘strncpy’ 
specified bound 16 equals destination size [-Wstringop-truncation]
  164 |  strncpy(args->v0.chip, device->chip->name, sizeof(args->v0.chip));
drivers/gpu/drm/nouveau/nvkm/engine/device/user.c:165:2: warning: ‘strncpy’ 
specified bound 64 equals destination size [-Wstringop-truncation]
  165 |  strncpy(args->v0.name, device->name, sizeof(args->v0.name));

The reason of this warning is strncpy() does not guarantee that the
destination buffer will be NUL terminated. If the length of source string
is bigger than number we set by third input parameter, only first [number]
of characters is copied to the destination, and no NUL-terminated is
automatically added. There are some potential risks.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/nouveau/nvkm/engine/device/user.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
index fea9d8f..2a32fe0 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
@@ -161,8 +161,10 @@ nvkm_udevice_info(struct nvkm_udevice *udev, void *data, 
u32 size)
if (imem && args->v0.ram_size > 0)
args->v0.ram_user = args->v0.ram_user - imem->reserved;
 
-   strncpy(args->v0.chip, device->chip->name, sizeof(args->v0.chip));
-   strncpy(args->v0.name, device->name, sizeof(args->v0.name));
+   strncpy(args->v0.chip, device->chip->name, sizeof(args->v0.chip) - 1);
+   args->v0.chip[sizeof(args->v0.chip) - 1] = '\0';
+   strncpy(args->v0.name, device->name, sizeof(args->v0.name) - 1);
+   args->v0.name[sizeof(args->v0.name) - 1] = '\0';
return 0;
 }
 
-- 
2.7.4



[PATCH v1] drm/nouveau: delete unused variables "dev" in nouveau_ttm_tt_populate()

2021-02-25 Thread Luo Jiaxing
After switch to new allocator, dev is no longer used here and should be
deleted.

Fixes: 461619f5c324 ("drm/nouveau: switch to new allocator")

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c 
b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 2375711..0b94f8a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1251,7 +1251,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 {
struct ttm_tt *ttm_dma = (void *)ttm;
struct nouveau_drm *drm;
-   struct device *dev;
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
if (ttm_tt_is_populated(ttm))
@@ -1264,7 +1263,6 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
}
 
drm = nouveau_bdev(bdev);
-   dev = drm->dev->dev;
 
return ttm_pool_alloc(&drm->ttm.bdev.pool, ttm, ctx);
 }
@@ -1274,14 +1272,12 @@ nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev,
  struct ttm_tt *ttm)
 {
struct nouveau_drm *drm;
-   struct device *dev;
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
if (slave)
return;
 
drm = nouveau_bdev(bdev);
-   dev = drm->dev->dev;
 
return ttm_pool_free(&drm->ttm.bdev.pool, ttm);
 }
-- 
2.7.4



[PATCH v1] drm/nouveau/kms: delete an useless function call in nouveau_framebuffer_new()

2021-02-24 Thread Luo Jiaxing
nouveau_framebuffer_new() call drm_format_info_plane_width() to get a width
of plane, but width is not used then, so it's a useless function call here.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/nouveau/nouveau_display.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c 
b/drivers/gpu/drm/nouveau/nouveau_display.c
index 17831ee..7d3b1f8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -306,7 +306,7 @@ nouveau_framebuffer_new(struct drm_device *dev,
struct nouveau_bo *nvbo = nouveau_gem_object(gem);
struct drm_framebuffer *fb;
const struct drm_format_info *info;
-   unsigned int width, height, i;
+   unsigned int height, i;
uint32_t tile_mode;
uint8_t kind;
int ret;
@@ -346,9 +346,6 @@ nouveau_framebuffer_new(struct drm_device *dev,
info = drm_get_format_info(dev, mode_cmd);
 
for (i = 0; i < info->num_planes; i++) {
-   width = drm_format_info_plane_width(info,
-   mode_cmd->width,
-   i);
height = drm_format_info_plane_height(info,
  mode_cmd->height,
  i);
-- 
2.7.4



[PATCH v1 1/2] drm/nouveau/kms/nv50-: Remove several set but not used variables "ret" in disp.c

2021-02-24 Thread Luo Jiaxing
Fixes the following warning when using W=1 to build kernel:

drivers/gpu/drm/nouveau/dispnv50/disp.c: In function ‘nv50_mstm_cleanup’:
drivers/gpu/drm/nouveau/dispnv50/disp.c:1389:6: warning: variable ‘ret’ set but 
not used [-Wunused-but-set-variable]
 1389 |  int ret;
  |  ^~~
drivers/gpu/drm/nouveau/dispnv50/disp.c: In function ‘nv50_mstm_prepare’:
drivers/gpu/drm/nouveau/dispnv50/disp.c:1413:6: warning: variable ‘ret’ set but 
not used [-Wunused-but-set-variable]
 1413 |  int ret;
  |  ^~~

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/nouveau/dispnv50/disp.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c 
b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index 196612a..828f48d 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -1386,12 +1386,11 @@ nv50_mstm_cleanup(struct nv50_mstm *mstm)
 {
struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
struct drm_encoder *encoder;
-   int ret;
 
NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name);
-   ret = drm_dp_check_act_status(&mstm->mgr);
+   drm_dp_check_act_status(&mstm->mgr);
 
-   ret = drm_dp_update_payload_part2(&mstm->mgr);
+   drm_dp_update_payload_part2(&mstm->mgr);
 
drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
@@ -1410,10 +1409,9 @@ nv50_mstm_prepare(struct nv50_mstm *mstm)
 {
struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
struct drm_encoder *encoder;
-   int ret;
 
NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name);
-   ret = drm_dp_update_payload_part1(&mstm->mgr);
+   drm_dp_update_payload_part1(&mstm->mgr);
 
drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
-- 
2.7.4



[PATCH v1 0/2] irqchip/gic-v3-its: don't set bitmap for LPI which user didn't allocate

2021-02-08 Thread Luo Jiaxing
When the number of online CPUs is less than 16, we found that it will fail
to allocate 32 MSI interrupts (including 16 affinity interrupts) after the
hisi_sas module is unloaded and then reloaded.

After analysis, it is found that a bug exists when the ITS releases
interrupt resources, and this patch set contains a bugfix patch and a patch
for appending debugging information.

Luo Jiaxing (2):
  irqchip/gic-v3-its: don't set bitmap for LPI which user didn't
allocate
  genirq/msi: add an error print when __irq_domain_alloc_irqs() failed

 drivers/irqchip/irq-gic-v3-its.c | 4 
 kernel/irq/msi.c | 1 +
 2 files changed, 5 insertions(+)

-- 
2.7.4



[PATCH v1 1/2] irqchip/gic-v3-its: don't set bitmap for LPI which user didn't allocate

2021-02-08 Thread Luo Jiaxing
The driver sets the LPI bitmap of device based on get_count_order(nvecs).
This means that when the number of LPI interrupts does not meet the power
of two, redundant bits are set in the LPI bitmap. However, when free
interrupt, these redundant bits is not cleared. As a result, device will
fails to allocate the same numbers of interrupts next time.

Therefore, clear the redundant bits set in LPI bitmap.

Fixes: 4615fbc3788d ("genirq/irqdomain: Don't try to free an interrupt that has 
no mapping")

Signed-off-by: Luo Jiaxing 
---
 drivers/irqchip/irq-gic-v3-its.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index ed46e60..027f7ef 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -3435,6 +3435,10 @@ static int its_alloc_device_irq(struct its_device *dev, 
int nvecs, irq_hw_number
 
*hwirq = dev->event_map.lpi_base + idx;
 
+   bitmap_clear(dev->event_map.lpi_map,
+idx + nvecs,
+roundup_pow_of_two(nvecs) - nvecs);
+
return 0;
 }
 
-- 
2.7.4



[PATCH v1 2/2] genirq/msi: add an error print when __irq_domain_alloc_irqs() failed

2021-02-08 Thread Luo Jiaxing
During debug, we found that the return value of __irq_domain_alloc_irqs()
will be overwritten by the return value of subsequent function. As a
result, the locating clue will be lost.

To improve debug efficiency, an error message is added to print the
return value of __irq_domain_alloc_irqs().

Signed-off-by: Luo Jiaxing 
---
 kernel/irq/msi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index b338d62..f8729b0 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -418,6 +418,7 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, 
struct device *dev,
   desc->affinity);
if (virq < 0) {
ret = -ENOSPC;
+   dev_err(dev, "failed to allocate irq, virq=%d\n", virq);
if (ops->handle_error)
ret = ops->handle_error(domain, desc, ret);
if (ops->msi_finish)
-- 
2.7.4



[PATCH for next v1 1/2] gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler()

2021-02-08 Thread Luo Jiaxing
There is no need to use API with _irqsave in omap_gpio_irq_handler(),
because it already be in a irq-disabled context.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-omap.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 41952bb..dc8bbf4 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -560,8 +560,6 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
u32 enabled, isr, edge;
unsigned int bit;
struct gpio_bank *bank = gpiobank;
-   unsigned long wa_lock_flags;
-   unsigned long lock_flags;
 
isr_reg = bank->base + bank->regs->irqstatus;
if (WARN_ON(!isr_reg))
@@ -572,7 +570,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
return IRQ_NONE;
 
while (1) {
-   raw_spin_lock_irqsave(&bank->lock, lock_flags);
+   raw_spin_lock(&bank->lock);
 
enabled = omap_get_gpio_irqbank_mask(bank);
isr = readl_relaxed(isr_reg) & enabled;
@@ -586,7 +584,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
if (edge)
omap_clear_gpio_irqbank(bank, edge);
 
-   raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
+   raw_spin_unlock(&bank->lock);
 
if (!isr)
break;
@@ -595,7 +593,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
bit = __ffs(isr);
isr &= ~(BIT(bit));
 
-   raw_spin_lock_irqsave(&bank->lock, lock_flags);
+   raw_spin_lock(&bank->lock);
/*
 * Some chips can't respond to both rising and falling
 * at the same time.  If this irq was requested with
@@ -606,15 +604,14 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
if (bank->toggle_mask & (BIT(bit)))
omap_toggle_gpio_edge_triggering(bank, bit);
 
-   raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
+   raw_spin_unlock(&bank->lock);
 
-   raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags);
+   raw_spin_lock(&bank->wa_lock);
 

generic_handle_irq(irq_find_mapping(bank->chip.irq.domain,
bit));
 
-   raw_spin_unlock_irqrestore(&bank->wa_lock,
-  wa_lock_flags);
+   raw_spin_unlock(&bank->wa_lock);
}
}
 exit:
-- 
2.7.4



[PATCH for next v1 0/2] gpio: few clean up patches to replace spin_lock_irqsave with spin_lock

2021-02-08 Thread Luo Jiaxing
There is no need to use API with _irqsave in hard IRQ handler, So replace
those with spin_lock.

Luo Jiaxing (2):
  gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in
omap_gpio_irq_handler()
  gpio: grgpio: Replace spin_lock_irqsave with spin_lock in
grgpio_irq_handler()

 drivers/gpio/gpio-grgpio.c |  5 ++---
 drivers/gpio/gpio-omap.c   | 15 ++-
 2 files changed, 8 insertions(+), 12 deletions(-)

-- 
2.7.4



[PATCH for next v1 1/2] gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler()

2021-02-08 Thread Luo Jiaxing
There is no need to use API with _irqsave in omap_gpio_irq_handler(),
because it already be in a irq-disabled context.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-omap.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 41952bb..dc8bbf4 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -560,8 +560,6 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
u32 enabled, isr, edge;
unsigned int bit;
struct gpio_bank *bank = gpiobank;
-   unsigned long wa_lock_flags;
-   unsigned long lock_flags;
 
isr_reg = bank->base + bank->regs->irqstatus;
if (WARN_ON(!isr_reg))
@@ -572,7 +570,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
return IRQ_NONE;
 
while (1) {
-   raw_spin_lock_irqsave(&bank->lock, lock_flags);
+   raw_spin_lock(&bank->lock);
 
enabled = omap_get_gpio_irqbank_mask(bank);
isr = readl_relaxed(isr_reg) & enabled;
@@ -586,7 +584,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
if (edge)
omap_clear_gpio_irqbank(bank, edge);
 
-   raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
+   raw_spin_unlock(&bank->lock);
 
if (!isr)
break;
@@ -595,7 +593,7 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
bit = __ffs(isr);
isr &= ~(BIT(bit));
 
-   raw_spin_lock_irqsave(&bank->lock, lock_flags);
+   raw_spin_lock(&bank->lock);
/*
 * Some chips can't respond to both rising and falling
 * at the same time.  If this irq was requested with
@@ -606,15 +604,14 @@ static irqreturn_t omap_gpio_irq_handler(int irq, void 
*gpiobank)
if (bank->toggle_mask & (BIT(bit)))
omap_toggle_gpio_edge_triggering(bank, bit);
 
-   raw_spin_unlock_irqrestore(&bank->lock, lock_flags);
+   raw_spin_unlock(&bank->lock);
 
-   raw_spin_lock_irqsave(&bank->wa_lock, wa_lock_flags);
+   raw_spin_lock(&bank->wa_lock);
 

generic_handle_irq(irq_find_mapping(bank->chip.irq.domain,
bit));
 
-   raw_spin_unlock_irqrestore(&bank->wa_lock,
-  wa_lock_flags);
+   raw_spin_unlock(&bank->wa_lock);
}
}
 exit:
-- 
2.7.4



[PATCH for next v1 2/2] gpio: grgpio: Replace spin_lock_irqsave with spin_lock in grgpio_irq_handler()

2021-02-08 Thread Luo Jiaxing
There is no need to use API with _irqsave in grgpio_irq_handler(),
because it already be in a irq-disabled context.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-grgpio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index f954359..fa5aa31 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -195,11 +195,10 @@ static irqreturn_t grgpio_irq_handler(int irq, void *dev)
 {
struct grgpio_priv *priv = dev;
int ngpio = priv->gc.ngpio;
-   unsigned long flags;
int i;
int match = 0;
 
-   spin_lock_irqsave(&priv->gc.bgpio_lock, flags);
+   spin_lock(&priv->gc.bgpio_lock);
 
/*
 * For each gpio line, call its interrupt handler if it its underlying
@@ -215,7 +214,7 @@ static irqreturn_t grgpio_irq_handler(int irq, void *dev)
}
}
 
-   spin_unlock_irqrestore(&priv->gc.bgpio_lock, flags);
+   spin_unlock(&priv->gc.bgpio_lock);
 
if (!match)
dev_warn(priv->dev, "No gpio line matched irq %d\n", irq);
-- 
2.7.4



[PATCH for next v1 0/2] gpio: few clean up patches to replace spin_lock_irqsave with spin_lock

2021-02-08 Thread Luo Jiaxing
There is no need to use API with _irqsave in hard IRQ handler, So replace
those with spin_lock.

Luo Jiaxing (2):
  gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in
omap_gpio_irq_handler()
  gpio: grgpio: Replace spin_lock_irqsave with spin_lock in
grgpio_irq_handler()

 drivers/gpio/gpio-grgpio.c |  5 ++---
 drivers/gpio/gpio-omap.c   | 15 ++-
 2 files changed, 8 insertions(+), 12 deletions(-)

-- 
2.7.4



[PATCH v1] gpio: hisi: delete some unused variables in hisi_gpio_probe()

2020-12-21 Thread Luo Jiaxing
kernel test rebot report that dat, set and clr in hisi_gpio_probe() is
unused variables. So delete it.

Reported-by: kernel test robot 
Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-hisi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpio/gpio-hisi.c b/drivers/gpio/gpio-hisi.c
index a389780..d2971c9 100644
--- a/drivers/gpio/gpio-hisi.c
+++ b/drivers/gpio/gpio-hisi.c
@@ -254,7 +254,6 @@ static void hisi_gpio_get_pdata(struct device *dev,
 static int hisi_gpio_probe(struct platform_device *pdev)
 {
struct device *dev = &pdev->dev;
-   void __iomem *dat, *set, *clr;
struct hisi_gpio *hisi_gpio;
int port_num;
int ret;
-- 
2.7.4



[PATCH v2 0/3] gpio: gpio-hisi: Add HiSilicon GPIO support

2020-12-14 Thread Luo Jiaxing
This series is the GPIO driver for HiSilicon's ARM SoC.
It provide patches for device driver, MAINTAINER file, and enable gpio-hisi
at defconfig.

Thanks
Jiaxing

---
  v1->v2: 1. set (ARM64 || COMPILE_TEST) && ACPI at kconfig.
  2. Delete some useless header files.
  3. Replace "hisi-ngpio" with "ngpios", fix firmware too
  4. Direction setting is modified to be handle by generic GPIO
  5. Add error code print
      6. Some tiny clean up
---

Luo Jiaxing (3):
  gpio: gpio-hisi: Add HiSilicon GPIO support
  MAINTAINERS: Add maintainer for HiSilicon GPIO driver
  arm64: defconfig: enable GPIO_HISI

 MAINTAINERS  |   7 +
 arch/arm64/configs/defconfig |   1 +
 drivers/gpio/Kconfig |  11 ++
 drivers/gpio/Makefile|   1 +
 drivers/gpio/gpio-hisi.c | 328 +++
 5 files changed, 348 insertions(+)
 create mode 100644 drivers/gpio/gpio-hisi.c

-- 
2.7.4



[PATCH v2 1/3] gpio: gpio-hisi: Add HiSilicon GPIO support

2020-12-14 Thread Luo Jiaxing
This GPIO driver is for HiSilicon's ARM SoC.

HiSilicon's GPIO controller support double-edge interrupt and multi-core
concurrent access.

ACPI table example for this GPIO controller:
Device (GPO0)
{
Name (_HID, "HISI0184")
Device (PRTA)
{
Name (_ADR, Zero)
Name (_UID, Zero)
Name (_DSD, Package (0x01)
{
Package (0x02)
{
"ngpios",
0x20
}
})
    }
}

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/Kconfig |  11 ++
 drivers/gpio/Makefile|   1 +
 drivers/gpio/gpio-hisi.c | 328 +++
 3 files changed, 340 insertions(+)
 create mode 100644 drivers/gpio/gpio-hisi.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 5d4de5c..2598209 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -296,6 +296,17 @@ config GPIO_GRGPIO
  Select this to support Aeroflex Gaisler GRGPIO cores from the GRLIB
  VHDL IP core library.
 
+config GPIO_HISI
+   tristate "HiSilicon GPIO controller driver"
+   depends on (ARM64 || COMPILE_TEST) && ACPI
+   select GPIO_GENERIC
+   select GPIOLIB_IRQCHIP
+   help
+ Say Y or M here to build support for the HiSilicon GPIO controller
+ driver GPIO block.
+ This GPIO controller support double-edge interrupt and multi-core
+ concurrent access.
+
 config GPIO_HLWD
tristate "Nintendo Wii (Hollywood) GPIO"
depends on OF_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 09dada8..260ae25 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_GPIO_GE_FPGA)+= gpio-ge.o
 obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o
 obj-$(CONFIG_GPIO_GRGPIO)  += gpio-grgpio.o
 obj-$(CONFIG_GPIO_GW_PLD)  += gpio-gw-pld.o
+obj-$(CONFIG_GPIO_HISI) += gpio-hisi.o
 obj-$(CONFIG_GPIO_HLWD)+= gpio-hlwd.o
 obj-$(CONFIG_HTC_EGPIO)+= gpio-htc-egpio.o
 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o
diff --git a/drivers/gpio/gpio-hisi.c b/drivers/gpio/gpio-hisi.c
new file mode 100644
index 000..a389780
--- /dev/null
+++ b/drivers/gpio/gpio-hisi.c
@@ -0,0 +1,328 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2020 HiSilicon Limited. */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define HISI_GPIO_SWPORT_DR_SET_WX 0x000
+#define HISI_GPIO_SWPORT_DR_CLR_WX 0x004
+#define HISI_GPIO_SWPORT_DDR_SET_WX0x010
+#define HISI_GPIO_SWPORT_DDR_CLR_WX0x014
+#define HISI_GPIO_SWPORT_DDR_ST_WX 0x018
+#define HISI_GPIO_INTEN_SET_WX 0x020
+#define HISI_GPIO_INTEN_CLR_WX 0x024
+#define HISI_GPIO_INTMASK_SET_WX   0x030
+#define HISI_GPIO_INTMASK_CLR_WX   0x034
+#define HISI_GPIO_INTTYPE_EDGE_SET_WX  0x040
+#define HISI_GPIO_INTTYPE_EDGE_CLR_WX  0x044
+#define HISI_GPIO_INT_POLARITY_SET_WX  0x050
+#define HISI_GPIO_INT_POLARITY_CLR_WX  0x054
+#define HISI_GPIO_DEBOUNCE_SET_WX  0x060
+#define HISI_GPIO_DEBOUNCE_CLR_WX  0x064
+#define HISI_GPIO_INTSTATUS_WX 0x070
+#define HISI_GPIO_PORTA_EOI_WX 0x078
+#define HISI_GPIO_EXT_PORT_WX  0x080
+#define HISI_GPIO_INTCOMB_MASK_WX  0x0a0
+#define HISI_GPIO_INT_DEDGE_SET0x0b0
+#define HISI_GPIO_INT_DEDGE_CLR0x0b4
+#define HISI_GPIO_INT_DEDGE_ST 0x0b8
+
+#define HISI_GPIO_LINE_NUM_MAX 32
+#define HISI_GPIO_DRIVER_NAME  "gpio-hisi"
+
+struct hisi_gpio {
+   struct gpio_chipchip;
+   struct device   *dev;
+   void __iomem*reg_base;
+   unsigned intline_num;
+   struct irq_chip irq_chip;
+   int irq;
+};
+
+static inline u32 hisi_gpio_read_reg(struct gpio_chip *chip,
+unsigned int off)
+{
+   struct hisi_gpio *hisi_gpio =
+   container_of(chip, struct hisi_gpio, chip);
+   void __iomem *reg = hisi_gpio->reg_base + off;
+
+   return readl(reg);
+}
+
+static inline void hisi_gpio_write_reg(struct gpio_chip *chip,
+  unsigned int off, u32 val)
+{
+   struct hisi_gpio *hisi_gpio =
+   container_of(chip, struct hisi_gpio, chip);
+   void __iomem *reg = hisi_gpio->reg_base + off;
+
+   writel(val, reg);
+}
+
+static void hisi_gpio_set_debounce(struct gpio_chip *chip, unsigned int off,
+  u32 debounce)
+{
+   if (debounce)
+   hisi_gpio_write_reg(chip, HISI_GPIO_DEBOUNCE_SET_WX, BIT(off));
+   else
+   hisi_gpio_write_reg(chip, HISI_GPIO_DEBOUNCE_CLR_W

[PATCH v2 3/3] arm64: defconfig: enable GPIO_HISI

2020-12-14 Thread Luo Jiaxing
Enable GPIO controller for HiSilicon's ARM SoC.

GPIO is common driver for HiSilicon's ARM SoC and it provide support for
some function of I2C and SPI.

Signed-off-by: Luo Jiaxing 
---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 5cfe3cf..b5cdf5e 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -498,6 +498,7 @@ CONFIG_PINCTRL_SM8150=y
 CONFIG_PINCTRL_SM8250=y
 CONFIG_GPIO_ALTERA=m
 CONFIG_GPIO_DWAPB=y
+CONFIG_GPIO_HISI=y
 CONFIG_GPIO_MB86S7X=y
 CONFIG_GPIO_MPC8XXX=y
 CONFIG_GPIO_MXC=y
-- 
2.7.4



[PATCH v2 2/3] MAINTAINERS: Add maintainer for HiSilicon GPIO driver

2020-12-14 Thread Luo Jiaxing
Here add maintainer information for HiSilicon GPIO driver.

Signed-off-by: Luo Jiaxing 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2daa6ee..8d13419a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7896,6 +7896,13 @@ L:   dmaeng...@vger.kernel.org
 S: Maintained
 F: drivers/dma/hisi_dma.c
 
+HISILICON GPIO DRIVER
+M: Luo Jiaxing 
+L: linux-g...@vger.kernel.org
+S: Maintained
+F: drivers/gpio/gpio-hisi.c
+F: include/linux/platform_data/gpio-hisi.h
+
 HISILICON HIGH PERFORMANCE RSA ENGINE DRIVER (HPRE)
 M: Zaibo Xu 
 L: linux-cry...@vger.kernel.org
-- 
2.7.4



[PATCH v1 2/3] MAINTAINERS: Add maintainer for HiSilicon GPIO driver

2020-12-02 Thread Luo Jiaxing
Here add maintainer information for HiSilicon GPIO driver.

Signed-off-by: Luo Jiaxing 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2daa6ee..8d13419a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7896,6 +7896,13 @@ L:   dmaeng...@vger.kernel.org
 S: Maintained
 F: drivers/dma/hisi_dma.c
 
+HISILICON GPIO DRIVER
+M: Luo Jiaxing 
+L: linux-g...@vger.kernel.org
+S: Maintained
+F: drivers/gpio/gpio-hisi.c
+F: include/linux/platform_data/gpio-hisi.h
+
 HISILICON HIGH PERFORMANCE RSA ENGINE DRIVER (HPRE)
 M: Zaibo Xu 
 L: linux-cry...@vger.kernel.org
-- 
2.7.4



[PATCH v1 1/3] gpio: gpio-hisi: Add HiSilicon GPIO support

2020-12-02 Thread Luo Jiaxing
This GPIO driver is for HiSilicon's ARM SoC.

HiSilicon's GPIO controller support double-edge interrupt and multi-core
concurrent access.

ACPI table example for this GPIO controller:
Device (GPO0)
{
Name (_HID, "HISI0184")
Device (PRTA)
{
Name (_ADR, Zero)
Name (_UID, Zero)
Name (_DSD, Package (0x01)
{
Package (0x02)
{
"hisi-ngpio",
0x20
}
})
    }
}

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/Kconfig |  11 ++
 drivers/gpio/Makefile|   1 +
 drivers/gpio/gpio-hisi.c | 356 +++
 3 files changed, 368 insertions(+)
 create mode 100644 drivers/gpio/gpio-hisi.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 5d4de5c..0f5d4c6 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -296,6 +296,17 @@ config GPIO_GRGPIO
  Select this to support Aeroflex Gaisler GRGPIO cores from the GRLIB
  VHDL IP core library.
 
+config GPIO_HISI
+   tristate "HISILICON GPIO controller driver"
+   depends on (ARM64 && ACPI) || COMPILE_TEST
+   select GPIO_GENERIC
+   select GENERIC_IRQ_CHIP
+   help
+ Say Y or M here to build support for the HiSilicon GPIO controller 
driver
+ GPIO block.
+ This controller support double-edge interrupt and multi-core 
concurrent
+ access.
+
 config GPIO_HLWD
tristate "Nintendo Wii (Hollywood) GPIO"
depends on OF_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 09dada8..260ae25 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_GPIO_GE_FPGA)+= gpio-ge.o
 obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o
 obj-$(CONFIG_GPIO_GRGPIO)  += gpio-grgpio.o
 obj-$(CONFIG_GPIO_GW_PLD)  += gpio-gw-pld.o
+obj-$(CONFIG_GPIO_HISI) += gpio-hisi.o
 obj-$(CONFIG_GPIO_HLWD)+= gpio-hlwd.o
 obj-$(CONFIG_HTC_EGPIO)+= gpio-htc-egpio.o
 obj-$(CONFIG_GPIO_ICH) += gpio-ich.o
diff --git a/drivers/gpio/gpio-hisi.c b/drivers/gpio/gpio-hisi.c
new file mode 100644
index 000..ab076ca
--- /dev/null
+++ b/drivers/gpio/gpio-hisi.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2020 HiSilicon Limited.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "gpiolib.h"
+#include "gpiolib-acpi.h"
+
+#define HISI_GPIO_SWPORT_DR_SET_WX 0x0
+#define HISI_GPIO_SWPORT_DR_CLR_WX 0x4
+#define HISI_GPIO_SWPORT_DDR_SET_WX0x10
+#define HISI_GPIO_SWPORT_DDR_CLR_WX0x14
+#define HISI_GPIO_SWPORT_DDR_ST_WX 0x18
+#define HISI_GPIO_INTEN_SET_WX 0x20
+#define HISI_GPIO_INTEN_CLR_WX 0x24
+#define HISI_GPIO_INTMASK_SET_WX   0x30
+#define HISI_GPIO_INTMASK_CLR_WX   0x34
+#define HISI_GPIO_INTTYPE_EDGE_SET_WX  0x40
+#define HISI_GPIO_INTTYPE_EDGE_CLR_WX  0x44
+#define HISI_GPIO_INT_POLARITY_SET_WX  0x50
+#define HISI_GPIO_INT_POLARITY_CLR_WX  0x54
+#define HISI_GPIO_DEBOUNCE_SET_WX  0x60
+#define HISI_GPIO_DEBOUNCE_CLR_WX  0x64
+#define HISI_GPIO_INTSTATUS_WX 0x70
+#define HISI_GPIO_PORTA_EOI_WX 0x78
+#define HISI_GPIO_EXT_PORT_WX  0x80
+#define HISI_GPIO_INTCOMB_MASK_WX  0xa0
+#define HISI_GPIO_INT_DEDGE_SET0xb0
+#define HISI_GPIO_INT_DEDGE_CLR0xb4
+#define HISI_GPIO_INT_DEDGE_ST 0xb8
+
+#define HISI_GPIO_REG_SIZE 0x4
+#define HISI_GPIO_REG_MAX  0x100
+#define HISI_GPIO_PIN_NUM_MAX 32
+
+#define HISI_GPIO_DRIVER_NAME  "gpio-hisi"
+
+struct hisi_gpio {
+   struct device   *dev;
+   void __iomem*reg_base;
+   unsigned intpin_num;
+   struct gpio_chipchip;
+   struct irq_chip irq_chip;
+   int irq;
+};
+
+static inline u32 hisi_gpio_read_reg(struct gpio_chip *chip,
+unsigned int off)
+{
+   struct hisi_gpio *hisi_gpio =
+   container_of(chip, struct hisi_gpio, chip);
+
+   return chip->read_reg(hisi_gpio->reg_base + off);
+}
+
+static inline void hisi_gpio_write_reg(struct gpio_chip *chip,
+  unsigned int off, u32 val)
+{
+   struct hisi_gpio *hisi_gpio =
+   container_of(chip, struct hisi_gpio, chip);
+
+   chip->write_reg(hisi_gpio->reg_base + off, val);
+}
+
+static void hisi_gpio_set_debounce(struct gpio_chip *chip, unsigned int off,
+  u32 debounce)
+{
+   unsigned long mask = BIT(off);
+
+   if (debounce)
+   hisi_gpio_wri

[PATCH v1 3/3] arm64: defconfig: enable GPIO_HISI

2020-12-02 Thread Luo Jiaxing
Enable GPIO controller for HiSilicon's ARM SoC.

GPIO is common driver for HiSilicon's ARM SoC and it provide support for
some function of I2C and SPI.

Signed-off-by: Luo Jiaxing 
---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 5cfe3cf..b5cdf5e 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -498,6 +498,7 @@ CONFIG_PINCTRL_SM8150=y
 CONFIG_PINCTRL_SM8250=y
 CONFIG_GPIO_ALTERA=m
 CONFIG_GPIO_DWAPB=y
+CONFIG_GPIO_HISI=y
 CONFIG_GPIO_MB86S7X=y
 CONFIG_GPIO_MPC8XXX=y
 CONFIG_GPIO_MXC=y
-- 
2.7.4



[PATCH v1 0/3] gpio: gpio-hisi: Add HiSilicon GPIO support

2020-12-02 Thread Luo Jiaxing
This series is the GPIO driver for HiSilicon's ARM SoC.
It provide patches for device driver, MAINTAINER file, and enable gpio-hisi
at defconfig.

Thanks
Jiaxing

Luo Jiaxing (3):
  gpio: gpio-hisi: Add HiSilicon GPIO support
  MAINTAINERS: Add maintainer for HiSilicon GPIO driver
  arm64: defconfig: enable GPIO_HISI

 MAINTAINERS  |   7 +
 arch/arm64/configs/defconfig |   1 +
 drivers/gpio/Kconfig |  11 ++
 drivers/gpio/Makefile|   1 +
 drivers/gpio/gpio-hisi.c | 356 +++
 5 files changed, 376 insertions(+)
 create mode 100644 drivers/gpio/gpio-hisi.c

-- 
2.7.4



[PATCH v1] gpio: dwapb: mask/unmask IRQ when disable/enable it

2020-11-30 Thread Luo Jiaxing
The mask and unmask registers are not configured in dwapb_irq_enable() and
dwapb_irq_disable(). In the following situations, the IRQ will be masked by
default after the IRQ is enabled:

mask IRQ -> disable IRQ -> enable IRQ

In this case, the IRQ status of GPIO controller is inconsistent with it's
irq_data too. For example, in __irq_enable(), IRQD_IRQ_DISABLED and
IRQD_IRQ_MASKED are both clear, but GPIO controller do not perform unmask.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-dwapb.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 2a9046c..ca654eb 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -270,6 +270,8 @@ static void dwapb_irq_enable(struct irq_data *d)
u32 val;
 
spin_lock_irqsave(&gc->bgpio_lock, flags);
+   val = dwapb_read(gpio, GPIO_INTMASK) & ~BIT(irqd_to_hwirq(d));
+   dwapb_write(gpio, GPIO_INTMASK, val);
val = dwapb_read(gpio, GPIO_INTEN);
val |= BIT(irqd_to_hwirq(d));
dwapb_write(gpio, GPIO_INTEN, val);
@@ -284,6 +286,8 @@ static void dwapb_irq_disable(struct irq_data *d)
u32 val;
 
spin_lock_irqsave(&gc->bgpio_lock, flags);
+   val = dwapb_read(gpio, GPIO_INTMASK) | BIT(irqd_to_hwirq(d));
+   dwapb_write(gpio, GPIO_INTMASK, val);
val = dwapb_read(gpio, GPIO_INTEN);
val &= ~BIT(irqd_to_hwirq(d));
dwapb_write(gpio, GPIO_INTEN, val);
-- 
2.7.4



[PATCH v2] gpio: dwapb: fix NULL pointer dereference at dwapb_gpio_suspend()

2020-11-27 Thread Luo Jiaxing
Following Calltrace is found when running echo freeze > /sys/power/state.

[  272.755506] Unable to handle kernel NULL pointer dereference at virtual 
address 0010
[  272.755585] Call trace:
[  272.755587]  dwapb_gpio_suspend+0x18/0x318
[  272.755588]  pm_generic_suspend+0x2c/0x48
[  272.755595]  acpi_subsys_suspend+0x60/0x70
[  272.755599]  dpm_run_callback.isra.18+0x40/0xe0
[  272.755601]  __device_suspend+0xf4/0x360

The reason is platform_set_drvdata() is deleted, and dwapb_gpio_suspend()
get *gpio by dev_get_drvdata().

Fixes: feeaefd378ca ("gpio: dwapb: Use resource managed GPIO-chip add data 
method")
Signed-off-by: Luo Jiaxing 
Acked-by: Serge Semin 
Reviewed-by: Andy Shevchenko 

---
   v1->v2:
  1. reduce calltrace log
  2. delete blank line in tag block
---
---
 drivers/gpio/gpio-dwapb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 2a9046c..4275c18 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -724,6 +724,8 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
return err;
}
 
+   platform_set_drvdata(pdev, gpio);
+
return 0;
 }
 
-- 
2.7.4



[PATCH v1] gpio: dwapb: fix NULL pointer dereference at dwapb_gpio_suspend()

2020-11-25 Thread Luo Jiaxing
Following Calltrace is found when running echo freeze > /sys/power/state.

[  272.755506] Unable to handle kernel NULL pointer dereference at virtual 
address 0010
[  272.755508] Mem abort info:
[  272.755508]   ESR = 0x9606
[  272.755510]   EC = 0x25: DABT (current EL), IL = 32 bits
[  272.755511]   SET = 0, FnV = 0
[  272.755512]   EA = 0, S1PTW = 0
[  272.755513] Data abort info:
[  272.755514]   ISV = 0, ISS = 0x0006
[  272.755515]   CM = 0, WnR = 0
[  272.755517] user pgtable: 4k pages, 48-bit VAs, pgdp=0020a3b66000
[  272.755519] [0010] pgd=0020a5ebe003, p4d=0020a5ebe003, 
pud=002093cd3003, pmd=
[  272.755525] Internal error: Oops: 9606 [#1] PREEMPT SMP
[  272.755527] Modules linked in:
[  272.755532] CPU: 2 PID: 3523 Comm: bash Not tainted 
5.10.0-rc1-109487-g2893d0937cea-dirty #936
[  272.755533] Hardware name: Huawei TaiShan 2280 V2/BC82AMDD, BIOS 2280-V2 CS 
V3.B160.01 03/10/2020
[  272.755535] pstate: 6049 (nZCv daif +PAN -UAO -TCO BTYPE=--)
[  272.755544] pc : dwapb_gpio_suspend+0x18/0x318
[  272.70] lr : pm_generic_suspend+0x2c/0x48
[  272.71] sp : 80002f0aba90
[  272.72] x29: 80002f0aba90 x28: 
[  272.75] x27: bc08c155c000 x26: 0002
[  272.77] x25: bc08c155c5f8 x24: bc08c1621000
[  272.79] x23:  x22: bc08c15cc000
[  272.755561] x21: 357204472410 x20: bc08bfd6a7a0
[  272.755563] x19:  x18: 
[  272.755565] x17:  x16: 
[  272.755567] x15: 004a5f1918b8 x14: 0219
[  272.755570] x13: 0219 x12: 
[  272.755572] x11:  x10: 
[  272.755574] x9 :  x8 : 15729beb6180
[  272.755576] x7 :  x6 : 000b
[  272.755578] x5 : 15729dbd4600 x4 : 
[  272.755580] x3 : 357204472504 x2 : bc08bfcefef0
[  272.755582] x1 :  x0 : 357204472410
[  272.755585] Call trace:
[  272.755587]  dwapb_gpio_suspend+0x18/0x318
[  272.755588]  pm_generic_suspend+0x2c/0x48
[  272.755595]  acpi_subsys_suspend+0x60/0x70
[  272.755599]  dpm_run_callback.isra.18+0x40/0xe0
[  272.755601]  __device_suspend+0xf4/0x360
[  272.755603]  dpm_suspend+0xf0/0x1f8
[  272.755605]  dpm_suspend_start+0xa0/0xa8
[  272.755610]  suspend_devices_and_enter+0xe0/0x618
[  272.755612]  pm_suspend+0x250/0x308
[  272.755613]  state_store+0x8c/0x118
[  272.755621]  kobj_attr_store+0x18/0x30
[  272.755625]  sysfs_kf_write+0x40/0x58
[  272.755626]  kernfs_fop_write+0x148/0x240
[  272.755630]  vfs_write+0xc0/0x230
[  272.755632]  ksys_write+0x6c/0x100
[  272.755633]  __arm64_sys_write+0x1c/0x28
[  272.755639]  el0_svc_common.constprop.3+0x68/0x170
[  272.755641]  do_el0_svc+0x24/0x90
[  272.755646]  el0_sync_handler+0x118/0x168
[  272.755647]  el0_sync+0x158/0x180
[  272.755651] Code: 910003fd f9000bf3 f9001ff8 f9403c13 (f9400a78)
[  272.755724] ---[ end trace afcb0e834c241837 ]---
[  272.937286] Kernel panic - not syncing: Oops: Fatal exception
[  273.210068] SMP: stopping secondary CPUs
[  273.214006] Kernel Offset: 0x3c08af7b from 0x80001000
[  273.220071] PHYS_OFFSET: 0xeaae
[  273.224235] CPU features: 0x0040002,62808a38
[  273.228486] Memory Limit: none
[  273.234390] ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---

The reason is platform_set_drvdata() is deleted, and dwapb_gpio_suspend()
get *gpio by dev_get_drvdata().

Fixes: feeaefd378ca ("gpio: dwapb: Use resource managed GPIO-chip add data 
method")

Signed-off-by: Luo Jiaxing 
---
 drivers/gpio/gpio-dwapb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index 2a9046c..4275c18 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -724,6 +724,8 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
return err;
}
 
+   platform_set_drvdata(pdev, gpio);
+
return 0;
 }
 
-- 
2.7.4



[PATCH v4 4/5] usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE

2020-11-11 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at dwc3 debugfs to reduce some duplicated
code.

While at that, also use DEFINE_SHOW_ATTRIBUTE() where possible.

Signed-off-by: Luo Jiaxing 
Acked-by: Felipe Balbi 
---
 drivers/usb/dwc3/debugfs.c | 52 --
 1 file changed, 4 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 5da4f60..2b5de8d 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -348,11 +348,6 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_lsp_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_lsp_show, inode->i_private);
-}
-
 static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
  size_t count, loff_t *ppos)
 {
@@ -377,13 +372,7 @@ static ssize_t dwc3_lsp_write(struct file *file, const 
char __user *ubuf,
return count;
 }
 
-static const struct file_operations dwc3_lsp_fops = {
-   .open   = dwc3_lsp_open,
-   .write  = dwc3_lsp_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_lsp);
 
 static int dwc3_mode_show(struct seq_file *s, void *unused)
 {
@@ -412,11 +401,6 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_mode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_mode_show, inode->i_private);
-}
-
 static ssize_t dwc3_mode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -445,13 +429,7 @@ static ssize_t dwc3_mode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_mode_fops = {
-   .open   = dwc3_mode_open,
-   .write  = dwc3_mode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_mode);
 
 static int dwc3_testmode_show(struct seq_file *s, void *unused)
 {
@@ -491,11 +469,6 @@ static int dwc3_testmode_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_testmode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_testmode_show, inode->i_private);
-}
-
 static ssize_t dwc3_testmode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -528,13 +501,7 @@ static ssize_t dwc3_testmode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_testmode_fops = {
-   .open   = dwc3_testmode_open,
-   .write  = dwc3_testmode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_testmode);
 
 static int dwc3_link_state_show(struct seq_file *s, void *unused)
 {
@@ -564,11 +531,6 @@ static int dwc3_link_state_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_link_state_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_link_state_show, inode->i_private);
-}
-
 static ssize_t dwc3_link_state_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -620,13 +582,7 @@ static ssize_t dwc3_link_state_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_link_state_fops = {
-   .open   = dwc3_link_state_open,
-   .write  = dwc3_link_state_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_link_state);
 
 struct dwc3_ep_file_map {
const char name[25];
-- 
2.7.4



[PATCH v4 1/5] seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro

2020-11-11 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but many of drivers want a helper macro for read-write
file too.

So we make one to decrease code duplication.

Signed-off-by: Luo Jiaxing 
---
 include/linux/seq_file.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 813614d..8a474c8 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -191,6 +191,21 @@ static const struct proc_ops __name ## _proc_ops = {   
\
.proc_release   = single_release,   \
 }
 
+#define DEFINE_SHOW_STORE_ATTRIBUTE(__name)
\
+static int __name ## _open(struct inode *inode, struct file *file) \
+{  \
+   return single_open(file, __name ## _show, inode->i_private);\
+}  \
+   \
+static const struct file_operations __name ## _fops = {
\
+   .owner  = THIS_MODULE,  \
+   .open   = __name ## _open,  \
+   .read   = seq_read, \
+   .write  = __name ## _write, \
+   .llseek = seq_lseek,\
+   .release= single_release,   \
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS
-- 
2.7.4



[PATCH v4 0/5] Introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE at seq_file.c

2020-11-11 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers also want a helper macro
for read-write file too.

So we add this macro to help decrease code duplication.

---
 v1->v2:
1.Rename DEFINE_STORE_ATTRIBUTE() to DEFINE_SHOW_STORE_ATTRIBUTE().
2.AI Viro points out that he doesn't like the definition of macros
  like DEFINE_SHOW_ATTRIBUTE.
 v2->v3:
1.Fixed some spelling mistakes in commit.
2.Revision description are added for easy tracing.

 v3->v4:
1.Add AI Viro's comment to v1->v2's revision description.
2.Fixed a spelling mistakes of "marco" to "macro".
---

Luo Jiaxing (5):
  seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro
  scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE
  drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

 .../gpu/drm/i915/display/intel_display_debugfs.c   |  55 +
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 135 +++--
 drivers/scsi/qla2xxx/qla_dfs.c |  19 +--
 drivers/usb/dwc3/debugfs.c |  52 +---
 include/linux/seq_file.h   |  15 +++
 5 files changed, 41 insertions(+), 235 deletions(-)

-- 
2.7.4



[PATCH v4 3/5] scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-11 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at qla2xxx to reduce some duplicated code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/qla2xxx/qla_dfs.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index f89ad32..a5de808 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -513,14 +513,6 @@ qla_dfs_naqp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int
-qla_dfs_naqp_open(struct inode *inode, struct file *file)
-{
-   struct scsi_qla_host *vha = inode->i_private;
-
-   return single_open(file, qla_dfs_naqp_show, vha);
-}
-
 static ssize_t
 qla_dfs_naqp_write(struct file *file, const char __user *buffer,
 size_t count, loff_t *pos)
@@ -569,14 +561,7 @@ qla_dfs_naqp_write(struct file *file, const char __user 
*buffer,
return rc;
 }
 
-static const struct file_operations dfs_naqp_ops = {
-   .open   = qla_dfs_naqp_open,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-   .write  = qla_dfs_naqp_write,
-};
-
+DEFINE_SHOW_STORE_ATTRIBUTE(qla_dfs_naqp);
 
 int
 qla2x00_dfs_setup(scsi_qla_host_t *vha)
@@ -622,7 +607,7 @@ qla2x00_dfs_setup(scsi_qla_host_t *vha)
 
if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
ha->tgt.dfs_naqp = debugfs_create_file("naqp",
-   0400, ha->dfs_dir, vha, &dfs_naqp_ops);
+   0400, ha->dfs_dir, vha, &qla_dfs_naqp_ops);
if (!ha->tgt.dfs_naqp) {
ql_log(ql_log_warn, vha, 0xd011,
   "Unable to create debugFS naqp node.\n");
-- 
2.7.4



[PATCH v4 2/5] scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-11 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we use it at our code to reduce some duplicated code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 135 --
 1 file changed, 16 insertions(+), 119 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c 
b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 128583d..b8a6fc9 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3403,22 +3403,7 @@ static ssize_t 
hisi_sas_debugfs_bist_linkrate_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_linkrate_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_linkrate_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_linkrate_ops = {
-   .open = hisi_sas_debugfs_bist_linkrate_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_linkrate_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_linkrate);
 
 static const struct {
int value;
@@ -3493,22 +3478,7 @@ static ssize_t 
hisi_sas_debugfs_bist_code_mode_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_code_mode_open(struct inode *inode,
-   struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_code_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_code_mode_ops = {
-   .open = hisi_sas_debugfs_bist_code_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_code_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_code_mode);
 
 static ssize_t hisi_sas_debugfs_bist_phy_write(struct file *filp,
   const char __user *buf,
@@ -3542,22 +3512,7 @@ static int hisi_sas_debugfs_bist_phy_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_phy_open(struct inode *inode,
- struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_phy_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_phy_ops = {
-   .open = hisi_sas_debugfs_bist_phy_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_phy_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_phy);
 
 static const struct {
int value;
@@ -3621,22 +3576,7 @@ static ssize_t hisi_sas_debugfs_bist_mode_write(struct 
file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_mode_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_mode_ops = {
-   .open = hisi_sas_debugfs_bist_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_mode);
 
 static ssize_t hisi_sas_debugfs_bist_enable_write(struct file *filp,
  const char __user *buf,
@@ -3677,22 +3617,7 @@ static int hisi_sas_debugfs_bist_enable_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_enable_open(struct inode *inode,
-struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_enable_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_enable_ops = {
-   .open = hisi_sas_debugfs_bist_enable_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_enable_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_enable);
 
 static const struct {
char *name;
@@ -3730,21 +3655,7 @@ static int hisi_sas_debugfs_show(struct seq_file *s, 
void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_open(struct inode *inode, struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_show,
-  inode->i_private);
-}
-
-static const struct file_operations hi

[PATCH v4 5/5] drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-11 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at drm/i915/display to reduce some
duplicated code.

Signed-off-by: Luo Jiaxing 
---
 .../gpu/drm/i915/display/intel_display_debugfs.c   | 55 ++
 1 file changed, 4 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c 
b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index 0bf31f9..8bf839f 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -1329,21 +1329,7 @@ static int i915_displayport_test_active_show(struct 
seq_file *m, void *data)
return 0;
 }
 
-static int i915_displayport_test_active_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_displayport_test_active_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_displayport_test_active_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_displayport_test_active_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_displayport_test_active_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_displayport_test_active);
 
 static int i915_displayport_test_data_show(struct seq_file *m, void *data)
 {
@@ -1733,19 +1719,7 @@ static ssize_t i915_hpd_storm_ctl_write(struct file 
*file,
return len;
 }
 
-static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
-}
-
-static const struct file_operations i915_hpd_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_storm_ctl_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_storm_ctl);
 
 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
 {
@@ -1811,14 +1785,7 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct 
file *file,
return len;
 }
 
-static const struct file_operations i915_hpd_short_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_short_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_short_storm_ctl_write,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_short_storm_ctl);
 
 static int i915_drrs_ctl_set(void *data, u64 val)
 {
@@ -2181,21 +2148,7 @@ static ssize_t i915_dsc_fec_support_write(struct file 
*file,
return len;
 }
 
-static int i915_dsc_fec_support_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_dsc_fec_support_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_dsc_fec_support_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_dsc_fec_support_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_dsc_fec_support_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_dsc_fec_support);
 
 /**
  * intel_connector_debugfs_add - add i915 specific connector debugfs files
-- 
2.7.4



[PATCH v3 5/5] drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-03 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at drm/i915/display to reduce some
duplicated code.

Signed-off-by: Luo Jiaxing 
---
 .../gpu/drm/i915/display/intel_display_debugfs.c   | 55 ++
 1 file changed, 4 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c 
b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index 0bf31f9..8bf839f 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -1329,21 +1329,7 @@ static int i915_displayport_test_active_show(struct 
seq_file *m, void *data)
return 0;
 }
 
-static int i915_displayport_test_active_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_displayport_test_active_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_displayport_test_active_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_displayport_test_active_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_displayport_test_active_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_displayport_test_active);
 
 static int i915_displayport_test_data_show(struct seq_file *m, void *data)
 {
@@ -1733,19 +1719,7 @@ static ssize_t i915_hpd_storm_ctl_write(struct file 
*file,
return len;
 }
 
-static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
-}
-
-static const struct file_operations i915_hpd_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_storm_ctl_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_storm_ctl);
 
 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
 {
@@ -1811,14 +1785,7 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct 
file *file,
return len;
 }
 
-static const struct file_operations i915_hpd_short_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_short_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_short_storm_ctl_write,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_short_storm_ctl);
 
 static int i915_drrs_ctl_set(void *data, u64 val)
 {
@@ -2181,21 +2148,7 @@ static ssize_t i915_dsc_fec_support_write(struct file 
*file,
return len;
 }
 
-static int i915_dsc_fec_support_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_dsc_fec_support_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_dsc_fec_support_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_dsc_fec_support_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_dsc_fec_support_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_dsc_fec_support);
 
 /**
  * intel_connector_debugfs_add - add i915 specific connector debugfs files
-- 
2.7.4



[PATCH v3 2/5] scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-03 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we use it at our code to reduce some duplicated code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 135 --
 1 file changed, 16 insertions(+), 119 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c 
b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 128583d..b8a6fc9 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3403,22 +3403,7 @@ static ssize_t 
hisi_sas_debugfs_bist_linkrate_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_linkrate_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_linkrate_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_linkrate_ops = {
-   .open = hisi_sas_debugfs_bist_linkrate_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_linkrate_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_linkrate);
 
 static const struct {
int value;
@@ -3493,22 +3478,7 @@ static ssize_t 
hisi_sas_debugfs_bist_code_mode_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_code_mode_open(struct inode *inode,
-   struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_code_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_code_mode_ops = {
-   .open = hisi_sas_debugfs_bist_code_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_code_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_code_mode);
 
 static ssize_t hisi_sas_debugfs_bist_phy_write(struct file *filp,
   const char __user *buf,
@@ -3542,22 +3512,7 @@ static int hisi_sas_debugfs_bist_phy_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_phy_open(struct inode *inode,
- struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_phy_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_phy_ops = {
-   .open = hisi_sas_debugfs_bist_phy_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_phy_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_phy);
 
 static const struct {
int value;
@@ -3621,22 +3576,7 @@ static ssize_t hisi_sas_debugfs_bist_mode_write(struct 
file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_mode_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_mode_ops = {
-   .open = hisi_sas_debugfs_bist_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_mode);
 
 static ssize_t hisi_sas_debugfs_bist_enable_write(struct file *filp,
  const char __user *buf,
@@ -3677,22 +3617,7 @@ static int hisi_sas_debugfs_bist_enable_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_enable_open(struct inode *inode,
-struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_enable_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_enable_ops = {
-   .open = hisi_sas_debugfs_bist_enable_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_enable_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_enable);
 
 static const struct {
char *name;
@@ -3730,21 +3655,7 @@ static int hisi_sas_debugfs_show(struct seq_file *s, 
void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_open(struct inode *inode, struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_show,
-  inode->i_private);
-}
-
-static const struct file_operations hi

[PATCH v3 0/5] Introduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE at seq_file.c

2020-11-03 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers also want a helper macro
for read-write file too.

So we add this macro to help decrease code duplication.

---
 v1->v2:
1.Rename DEFINE_STORE_ATTRIBUTE() to DEFINE_SHOW_STORE_ATTRIBUTE().
 v2->v3:
1.Fixed some spelling mistakes in commit.
2.Revised resumes are added for easy tracing.
---

Luo Jiaxing (5):
  seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro
  scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE
  drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

 .../gpu/drm/i915/display/intel_display_debugfs.c   |  55 +
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 135 +++--
 drivers/scsi/qla2xxx/qla_dfs.c |  19 +--
 drivers/usb/dwc3/debugfs.c |  52 +---
 include/linux/seq_file.h   |  15 +++
 5 files changed, 41 insertions(+), 235 deletions(-)

-- 
2.7.4



[PATCH v3 1/5] seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro

2020-11-03 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but many of drivers want a helper macro for read-write
file too.

So we make one to decrease code duplication.

Signed-off-by: Luo Jiaxing 
---
 include/linux/seq_file.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 813614d..8a474c8 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -191,6 +191,21 @@ static const struct proc_ops __name ## _proc_ops = {   
\
.proc_release   = single_release,   \
 }
 
+#define DEFINE_SHOW_STORE_ATTRIBUTE(__name)
\
+static int __name ## _open(struct inode *inode, struct file *file) \
+{  \
+   return single_open(file, __name ## _show, inode->i_private);\
+}  \
+   \
+static const struct file_operations __name ## _fops = {
\
+   .owner  = THIS_MODULE,  \
+   .open   = __name ## _open,  \
+   .read   = seq_read, \
+   .write  = __name ## _write, \
+   .llseek = seq_lseek,\
+   .release= single_release,   \
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS
-- 
2.7.4



[PATCH v3 3/5] scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-11-03 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at qla2xxx to reduce some duplicated code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/qla2xxx/qla_dfs.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index f89ad32..a5de808 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -513,14 +513,6 @@ qla_dfs_naqp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int
-qla_dfs_naqp_open(struct inode *inode, struct file *file)
-{
-   struct scsi_qla_host *vha = inode->i_private;
-
-   return single_open(file, qla_dfs_naqp_show, vha);
-}
-
 static ssize_t
 qla_dfs_naqp_write(struct file *file, const char __user *buffer,
 size_t count, loff_t *pos)
@@ -569,14 +561,7 @@ qla_dfs_naqp_write(struct file *file, const char __user 
*buffer,
return rc;
 }
 
-static const struct file_operations dfs_naqp_ops = {
-   .open   = qla_dfs_naqp_open,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-   .write  = qla_dfs_naqp_write,
-};
-
+DEFINE_SHOW_STORE_ATTRIBUTE(qla_dfs_naqp);
 
 int
 qla2x00_dfs_setup(scsi_qla_host_t *vha)
@@ -622,7 +607,7 @@ qla2x00_dfs_setup(scsi_qla_host_t *vha)
 
if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
ha->tgt.dfs_naqp = debugfs_create_file("naqp",
-   0400, ha->dfs_dir, vha, &dfs_naqp_ops);
+   0400, ha->dfs_dir, vha, &qla_dfs_naqp_ops);
if (!ha->tgt.dfs_naqp) {
ql_log(ql_log_warn, vha, 0xd011,
   "Unable to create debugFS naqp node.\n");
-- 
2.7.4



[PATCH v3 4/5] usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE

2020-11-03 Thread Luo Jiaxing
Seq introduce a new helper macro DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, so we apply it at dwc3 debugfs to reduce some duplicated
code.

While at that, also use DEFINE_SHOW_ATTRIBUTE() where possible.

Signed-off-by: Luo Jiaxing 
Acked-by: Felipe Balbi 
---
 drivers/usb/dwc3/debugfs.c | 52 --
 1 file changed, 4 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 5da4f60..2b5de8d 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -348,11 +348,6 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_lsp_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_lsp_show, inode->i_private);
-}
-
 static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
  size_t count, loff_t *ppos)
 {
@@ -377,13 +372,7 @@ static ssize_t dwc3_lsp_write(struct file *file, const 
char __user *ubuf,
return count;
 }
 
-static const struct file_operations dwc3_lsp_fops = {
-   .open   = dwc3_lsp_open,
-   .write  = dwc3_lsp_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_lsp);
 
 static int dwc3_mode_show(struct seq_file *s, void *unused)
 {
@@ -412,11 +401,6 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_mode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_mode_show, inode->i_private);
-}
-
 static ssize_t dwc3_mode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -445,13 +429,7 @@ static ssize_t dwc3_mode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_mode_fops = {
-   .open   = dwc3_mode_open,
-   .write  = dwc3_mode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_mode);
 
 static int dwc3_testmode_show(struct seq_file *s, void *unused)
 {
@@ -491,11 +469,6 @@ static int dwc3_testmode_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_testmode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_testmode_show, inode->i_private);
-}
-
 static ssize_t dwc3_testmode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -528,13 +501,7 @@ static ssize_t dwc3_testmode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_testmode_fops = {
-   .open   = dwc3_testmode_open,
-   .write  = dwc3_testmode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_testmode);
 
 static int dwc3_link_state_show(struct seq_file *s, void *unused)
 {
@@ -564,11 +531,6 @@ static int dwc3_link_state_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_link_state_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_link_state_show, inode->i_private);
-}
-
 static ssize_t dwc3_link_state_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -620,13 +582,7 @@ static ssize_t dwc3_link_state_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_link_state_fops = {
-   .open   = dwc3_link_state_open,
-   .write  = dwc3_link_state_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_link_state);
 
 struct dwc3_ep_file_map {
const char name[25];
-- 
2.7.4



[PATCH v2 3/5] scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-10-30 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, So we apply it at qla2xxx to reduce some duplicate code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/qla2xxx/qla_dfs.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index f89ad32..a5de808 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -513,14 +513,6 @@ qla_dfs_naqp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int
-qla_dfs_naqp_open(struct inode *inode, struct file *file)
-{
-   struct scsi_qla_host *vha = inode->i_private;
-
-   return single_open(file, qla_dfs_naqp_show, vha);
-}
-
 static ssize_t
 qla_dfs_naqp_write(struct file *file, const char __user *buffer,
 size_t count, loff_t *pos)
@@ -569,14 +561,7 @@ qla_dfs_naqp_write(struct file *file, const char __user 
*buffer,
return rc;
 }
 
-static const struct file_operations dfs_naqp_ops = {
-   .open   = qla_dfs_naqp_open,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-   .write  = qla_dfs_naqp_write,
-};
-
+DEFINE_SHOW_STORE_ATTRIBUTE(qla_dfs_naqp);
 
 int
 qla2x00_dfs_setup(scsi_qla_host_t *vha)
@@ -622,7 +607,7 @@ qla2x00_dfs_setup(scsi_qla_host_t *vha)
 
if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
ha->tgt.dfs_naqp = debugfs_create_file("naqp",
-   0400, ha->dfs_dir, vha, &dfs_naqp_ops);
+   0400, ha->dfs_dir, vha, &qla_dfs_naqp_ops);
if (!ha->tgt.dfs_naqp) {
ql_log(ql_log_warn, vha, 0xd011,
   "Unable to create debugFS naqp node.\n");
-- 
2.7.4



[PATCH v2 2/5] scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-10-30 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, So we use it at our code to reduce some duplicate code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 135 --
 1 file changed, 16 insertions(+), 119 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c 
b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 128583d..b8a6fc9 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3403,22 +3403,7 @@ static ssize_t 
hisi_sas_debugfs_bist_linkrate_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_linkrate_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_linkrate_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_linkrate_ops = {
-   .open = hisi_sas_debugfs_bist_linkrate_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_linkrate_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_linkrate);
 
 static const struct {
int value;
@@ -3493,22 +3478,7 @@ static ssize_t 
hisi_sas_debugfs_bist_code_mode_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_code_mode_open(struct inode *inode,
-   struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_code_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_code_mode_ops = {
-   .open = hisi_sas_debugfs_bist_code_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_code_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_code_mode);
 
 static ssize_t hisi_sas_debugfs_bist_phy_write(struct file *filp,
   const char __user *buf,
@@ -3542,22 +3512,7 @@ static int hisi_sas_debugfs_bist_phy_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_phy_open(struct inode *inode,
- struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_phy_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_phy_ops = {
-   .open = hisi_sas_debugfs_bist_phy_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_phy_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_phy);
 
 static const struct {
int value;
@@ -3621,22 +3576,7 @@ static ssize_t hisi_sas_debugfs_bist_mode_write(struct 
file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_mode_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_mode_ops = {
-   .open = hisi_sas_debugfs_bist_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_mode);
 
 static ssize_t hisi_sas_debugfs_bist_enable_write(struct file *filp,
  const char __user *buf,
@@ -3677,22 +3617,7 @@ static int hisi_sas_debugfs_bist_enable_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_enable_open(struct inode *inode,
-struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_enable_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_enable_ops = {
-   .open = hisi_sas_debugfs_bist_enable_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_enable_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_enable);
 
 static const struct {
char *name;
@@ -3730,21 +3655,7 @@ static int hisi_sas_debugfs_show(struct seq_file *s, 
void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_open(struct inode *inode, struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_show,
-  inode->i_private);
-}
-
-static const struct file_operations hi

[PATCH v2 0/5] Introduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE at seq_file.c

2020-10-30 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers also want a helper marco for
read-write file too.

So we try to add this macro to help decrease code duplication.

Luo Jiaxing (5):
  seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro
  scsi: hisi_sas: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  scsi: qla2xxx: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs
  usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE
  drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

 .../gpu/drm/i915/display/intel_display_debugfs.c   |  55 +
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 135 +++--
 drivers/scsi/qla2xxx/qla_dfs.c |  19 +--
 drivers/usb/dwc3/debugfs.c |  52 +---
 include/linux/seq_file.h   |  15 +++
 5 files changed, 41 insertions(+), 235 deletions(-)

-- 
2.7.4



[PATCH v2 4/5] usb: dwc3: debugfs: Introduce DEFINE_SHOW_STORE_ATTRIBUTE

2020-10-30 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, So we apply it at dwc3 debugfs to reduce some duplicate
code.

Signed-off-by: Luo Jiaxing 
---
 drivers/usb/dwc3/debugfs.c | 52 --
 1 file changed, 4 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 5da4f60..2b5de8d 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -348,11 +348,6 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_lsp_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_lsp_show, inode->i_private);
-}
-
 static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
  size_t count, loff_t *ppos)
 {
@@ -377,13 +372,7 @@ static ssize_t dwc3_lsp_write(struct file *file, const 
char __user *ubuf,
return count;
 }
 
-static const struct file_operations dwc3_lsp_fops = {
-   .open   = dwc3_lsp_open,
-   .write  = dwc3_lsp_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_lsp);
 
 static int dwc3_mode_show(struct seq_file *s, void *unused)
 {
@@ -412,11 +401,6 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_mode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_mode_show, inode->i_private);
-}
-
 static ssize_t dwc3_mode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -445,13 +429,7 @@ static ssize_t dwc3_mode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_mode_fops = {
-   .open   = dwc3_mode_open,
-   .write  = dwc3_mode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_mode);
 
 static int dwc3_testmode_show(struct seq_file *s, void *unused)
 {
@@ -491,11 +469,6 @@ static int dwc3_testmode_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_testmode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_testmode_show, inode->i_private);
-}
-
 static ssize_t dwc3_testmode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -528,13 +501,7 @@ static ssize_t dwc3_testmode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_testmode_fops = {
-   .open   = dwc3_testmode_open,
-   .write  = dwc3_testmode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_testmode);
 
 static int dwc3_link_state_show(struct seq_file *s, void *unused)
 {
@@ -564,11 +531,6 @@ static int dwc3_link_state_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_link_state_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_link_state_show, inode->i_private);
-}
-
 static ssize_t dwc3_link_state_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -620,13 +582,7 @@ static ssize_t dwc3_link_state_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_link_state_fops = {
-   .open   = dwc3_link_state_open,
-   .write  = dwc3_link_state_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(dwc3_link_state);
 
 struct dwc3_ep_file_map {
const char name[25];
-- 
2.7.4



[PATCH v2 1/5] seq_file: Introduce DEFINE_SHOW_STORE_ATTRIBUTE() helper macro

2020-10-30 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers want a helper marco for
read-write file too.

So we try to make one to decrease code duplication.

Signed-off-by: Luo Jiaxing 
---
 include/linux/seq_file.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 813614d..8a474c8 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -191,6 +191,21 @@ static const struct proc_ops __name ## _proc_ops = {   
\
.proc_release   = single_release,   \
 }
 
+#define DEFINE_SHOW_STORE_ATTRIBUTE(__name)
\
+static int __name ## _open(struct inode *inode, struct file *file) \
+{  \
+   return single_open(file, __name ## _show, inode->i_private);\
+}  \
+   \
+static const struct file_operations __name ## _fops = {
\
+   .owner  = THIS_MODULE,  \
+   .open   = __name ## _open,  \
+   .read   = seq_read, \
+   .write  = __name ## _write, \
+   .llseek = seq_lseek,\
+   .release= single_release,   \
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS
-- 
2.7.4



[PATCH v2 5/5] drm/i915/display: Introduce DEFINE_SHOW_STORE_ATTRIBUTE for debugfs

2020-10-30 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_SHOW_STORE_ATTRIBUTE for
Read-Write file, So we apply it at drm/i915/display to reduce some
duplicate code.

Signed-off-by: Luo Jiaxing 
---
 .../gpu/drm/i915/display/intel_display_debugfs.c   | 55 ++
 1 file changed, 4 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c 
b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index 0bf31f9..8bf839f 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -1329,21 +1329,7 @@ static int i915_displayport_test_active_show(struct 
seq_file *m, void *data)
return 0;
 }
 
-static int i915_displayport_test_active_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_displayport_test_active_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_displayport_test_active_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_displayport_test_active_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_displayport_test_active_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_displayport_test_active);
 
 static int i915_displayport_test_data_show(struct seq_file *m, void *data)
 {
@@ -1733,19 +1719,7 @@ static ssize_t i915_hpd_storm_ctl_write(struct file 
*file,
return len;
 }
 
-static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
-}
-
-static const struct file_operations i915_hpd_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_storm_ctl_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_storm_ctl);
 
 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
 {
@@ -1811,14 +1785,7 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct 
file *file,
return len;
 }
 
-static const struct file_operations i915_hpd_short_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_short_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_short_storm_ctl_write,
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_hpd_short_storm_ctl);
 
 static int i915_drrs_ctl_set(void *data, u64 val)
 {
@@ -2181,21 +2148,7 @@ static ssize_t i915_dsc_fec_support_write(struct file 
*file,
return len;
 }
 
-static int i915_dsc_fec_support_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_dsc_fec_support_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_dsc_fec_support_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_dsc_fec_support_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_dsc_fec_support_write
-};
+DEFINE_SHOW_STORE_ATTRIBUTE(i915_dsc_fec_support);
 
 /**
  * intel_connector_debugfs_add - add i915 specific connector debugfs files
-- 
2.7.4



[PATCH v1 4/5] usb: dwc3: debugfs: Introduce DEFINE_STORE_ATTRIBUTE

2020-10-22 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_STORE_ATTRIBUTE for
Read-Write file, So we apply it at dwc3 debugfs to reduce some duplicate
code.

Signed-off-by: Luo Jiaxing 
---
 drivers/usb/dwc3/debugfs.c | 52 --
 1 file changed, 4 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 5da4f60..27074cb 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -348,11 +348,6 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_lsp_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_lsp_show, inode->i_private);
-}
-
 static ssize_t dwc3_lsp_write(struct file *file, const char __user *ubuf,
  size_t count, loff_t *ppos)
 {
@@ -377,13 +372,7 @@ static ssize_t dwc3_lsp_write(struct file *file, const 
char __user *ubuf,
return count;
 }
 
-static const struct file_operations dwc3_lsp_fops = {
-   .open   = dwc3_lsp_open,
-   .write  = dwc3_lsp_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_STORE_ATTRIBUTE(dwc3_lsp);
 
 static int dwc3_mode_show(struct seq_file *s, void *unused)
 {
@@ -412,11 +401,6 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int dwc3_mode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_mode_show, inode->i_private);
-}
-
 static ssize_t dwc3_mode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -445,13 +429,7 @@ static ssize_t dwc3_mode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_mode_fops = {
-   .open   = dwc3_mode_open,
-   .write  = dwc3_mode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_STORE_ATTRIBUTE(dwc3_mode);
 
 static int dwc3_testmode_show(struct seq_file *s, void *unused)
 {
@@ -491,11 +469,6 @@ static int dwc3_testmode_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_testmode_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_testmode_show, inode->i_private);
-}
-
 static ssize_t dwc3_testmode_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -528,13 +501,7 @@ static ssize_t dwc3_testmode_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_testmode_fops = {
-   .open   = dwc3_testmode_open,
-   .write  = dwc3_testmode_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_STORE_ATTRIBUTE(dwc3_testmode);
 
 static int dwc3_link_state_show(struct seq_file *s, void *unused)
 {
@@ -564,11 +531,6 @@ static int dwc3_link_state_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int dwc3_link_state_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, dwc3_link_state_show, inode->i_private);
-}
-
 static ssize_t dwc3_link_state_write(struct file *file,
const char __user *ubuf, size_t count, loff_t *ppos)
 {
@@ -620,13 +582,7 @@ static ssize_t dwc3_link_state_write(struct file *file,
return count;
 }
 
-static const struct file_operations dwc3_link_state_fops = {
-   .open   = dwc3_link_state_open,
-   .write  = dwc3_link_state_write,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-};
+DEFINE_STORE_ATTRIBUTE(dwc3_link_state);
 
 struct dwc3_ep_file_map {
const char name[25];
-- 
2.7.4



[PATCH v1 2/5] scsi: hisi_sas: Introduce DEFINE_STORE_ATTRIBUTE for debugfs

2020-10-22 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_STORE_ATTRIBUTE for
Read-Write file, So we use it at our code to reduce some duplicate code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 135 --
 1 file changed, 16 insertions(+), 119 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c 
b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 128583d..12a4fdb 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -3403,22 +3403,7 @@ static ssize_t 
hisi_sas_debugfs_bist_linkrate_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_linkrate_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_linkrate_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_linkrate_ops = {
-   .open = hisi_sas_debugfs_bist_linkrate_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_linkrate_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_linkrate);
 
 static const struct {
int value;
@@ -3493,22 +3478,7 @@ static ssize_t 
hisi_sas_debugfs_bist_code_mode_write(struct file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_code_mode_open(struct inode *inode,
-   struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_code_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_code_mode_ops = {
-   .open = hisi_sas_debugfs_bist_code_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_code_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_code_mode);
 
 static ssize_t hisi_sas_debugfs_bist_phy_write(struct file *filp,
   const char __user *buf,
@@ -3542,22 +3512,7 @@ static int hisi_sas_debugfs_bist_phy_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_phy_open(struct inode *inode,
- struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_phy_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_phy_ops = {
-   .open = hisi_sas_debugfs_bist_phy_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_phy_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_phy);
 
 static const struct {
int value;
@@ -3621,22 +3576,7 @@ static ssize_t hisi_sas_debugfs_bist_mode_write(struct 
file *filp,
 
return count;
 }
-
-static int hisi_sas_debugfs_bist_mode_open(struct inode *inode,
-  struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_mode_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_mode_ops = {
-   .open = hisi_sas_debugfs_bist_mode_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_mode_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_mode);
 
 static ssize_t hisi_sas_debugfs_bist_enable_write(struct file *filp,
  const char __user *buf,
@@ -3677,22 +3617,7 @@ static int hisi_sas_debugfs_bist_enable_show(struct 
seq_file *s, void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_bist_enable_open(struct inode *inode,
-struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_bist_enable_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_bist_enable_ops = {
-   .open = hisi_sas_debugfs_bist_enable_open,
-   .read = seq_read,
-   .write = hisi_sas_debugfs_bist_enable_write,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .owner = THIS_MODULE,
-};
+DEFINE_STORE_ATTRIBUTE(hisi_sas_debugfs_bist_enable);
 
 static const struct {
char *name;
@@ -3730,21 +3655,7 @@ static int hisi_sas_debugfs_show(struct seq_file *s, 
void *p)
 
return 0;
 }
-
-static int hisi_sas_debugfs_open(struct inode *inode, struct file *filp)
-{
-   return single_open(filp, hisi_sas_debugfs_show,
-  inode->i_private);
-}
-
-static const struct file_operations hisi_sas_debugfs_ops

[PATCH v1 5/5] drm/i915/display: Introduce DEFINE_STORE_ATTRIBUTE for debugfs

2020-10-22 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_STORE_ATTRIBUTE for
Read-Write file, So we apply it at drm/i915/display to reduce some
duplicate code.

Signed-off-by: Luo Jiaxing 
---
 .../gpu/drm/i915/display/intel_display_debugfs.c   | 55 ++
 1 file changed, 4 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c 
b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
index 0bf31f9..89d38d2 100644
--- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c
+++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c
@@ -1329,21 +1329,7 @@ static int i915_displayport_test_active_show(struct 
seq_file *m, void *data)
return 0;
 }
 
-static int i915_displayport_test_active_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_displayport_test_active_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_displayport_test_active_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_displayport_test_active_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_displayport_test_active_write
-};
+DEFINE_STORE_ATTRIBUTE(i915_displayport_test_active);
 
 static int i915_displayport_test_data_show(struct seq_file *m, void *data)
 {
@@ -1733,19 +1719,7 @@ static ssize_t i915_hpd_storm_ctl_write(struct file 
*file,
return len;
 }
 
-static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
-}
-
-static const struct file_operations i915_hpd_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_storm_ctl_write
-};
+DEFINE_STORE_ATTRIBUTE(i915_hpd_storm_ctl);
 
 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
 {
@@ -1811,14 +1785,7 @@ static ssize_t i915_hpd_short_storm_ctl_write(struct 
file *file,
return len;
 }
 
-static const struct file_operations i915_hpd_short_storm_ctl_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_hpd_short_storm_ctl_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_hpd_short_storm_ctl_write,
-};
+DEFINE_STORE_ATTRIBUTE(i915_hpd_short_storm_ctl);
 
 static int i915_drrs_ctl_set(void *data, u64 val)
 {
@@ -2181,21 +2148,7 @@ static ssize_t i915_dsc_fec_support_write(struct file 
*file,
return len;
 }
 
-static int i915_dsc_fec_support_open(struct inode *inode,
-struct file *file)
-{
-   return single_open(file, i915_dsc_fec_support_show,
-  inode->i_private);
-}
-
-static const struct file_operations i915_dsc_fec_support_fops = {
-   .owner = THIS_MODULE,
-   .open = i915_dsc_fec_support_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-   .write = i915_dsc_fec_support_write
-};
+DEFINE_STORE_ATTRIBUTE(i915_dsc_fec_support);
 
 /**
  * intel_connector_debugfs_add - add i915 specific connector debugfs files
-- 
2.7.4



[PATCH v1 1/5] seq_file: Introduce DEFINE_STORE_ATTRIBUTE() helper macro

2020-10-22 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers want a helper marco for
read-write file too.

So we try to make one to decrease code duplication.

Signed-off-by: Luo Jiaxing 
---
 include/linux/seq_file.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 813614d..3b3b797 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -191,6 +191,21 @@ static const struct proc_ops __name ## _proc_ops = {   
\
.proc_release   = single_release,   \
 }
 
+#define DEFINE_STORE_ATTRIBUTE(__name) \
+static int __name ## _open(struct inode *inode, struct file *file) \
+{  \
+   return single_open(file, __name ## _show, inode->i_private);\
+}  \
+   \
+static const struct file_operations __name ## _fops = {
\
+   .owner  = THIS_MODULE,  \
+   .open   = __name ## _open,  \
+   .read   = seq_read, \
+   .write  = __name ## _write, \
+   .llseek = seq_lseek,\
+   .release= single_release,   \
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS
-- 
2.7.4



[PATCH v1 3/5] scsi: qla2xxx: Introduce DEFINE_STORE_ATTRIBUTE for debugfs

2020-10-22 Thread Luo Jiaxing
Seq instroduce a new helper marco DEFINE_STORE_ATTRIBUTE for
Read-Write file, So we apply it at qla2xxx to reduce some duplicate code.

Signed-off-by: Luo Jiaxing 
---
 drivers/scsi/qla2xxx/qla_dfs.c | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_dfs.c b/drivers/scsi/qla2xxx/qla_dfs.c
index f89ad32..d7796e3 100644
--- a/drivers/scsi/qla2xxx/qla_dfs.c
+++ b/drivers/scsi/qla2xxx/qla_dfs.c
@@ -513,14 +513,6 @@ qla_dfs_naqp_show(struct seq_file *s, void *unused)
return 0;
 }
 
-static int
-qla_dfs_naqp_open(struct inode *inode, struct file *file)
-{
-   struct scsi_qla_host *vha = inode->i_private;
-
-   return single_open(file, qla_dfs_naqp_show, vha);
-}
-
 static ssize_t
 qla_dfs_naqp_write(struct file *file, const char __user *buffer,
 size_t count, loff_t *pos)
@@ -569,14 +561,7 @@ qla_dfs_naqp_write(struct file *file, const char __user 
*buffer,
return rc;
 }
 
-static const struct file_operations dfs_naqp_ops = {
-   .open   = qla_dfs_naqp_open,
-   .read   = seq_read,
-   .llseek = seq_lseek,
-   .release= single_release,
-   .write  = qla_dfs_naqp_write,
-};
-
+DEFINE_STORE_ATTRIBUTE(qla_dfs_naqp);
 
 int
 qla2x00_dfs_setup(scsi_qla_host_t *vha)
@@ -622,7 +607,7 @@ qla2x00_dfs_setup(scsi_qla_host_t *vha)
 
if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha)) {
ha->tgt.dfs_naqp = debugfs_create_file("naqp",
-   0400, ha->dfs_dir, vha, &dfs_naqp_ops);
+   0400, ha->dfs_dir, vha, &qla_dfs_naqp_ops);
if (!ha->tgt.dfs_naqp) {
ql_log(ql_log_warn, vha, 0xd011,
   "Unable to create debugFS naqp node.\n");
-- 
2.7.4



[PATCH v1 0/5] Introduce a new helper marco DEFINE_STORE_ATTRIBUTE at seq_file.c

2020-10-22 Thread Luo Jiaxing
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers also want a helper marco for
read-write file too.

So we try to add this macro to help decrease code duplication.

Luo Jiaxing (5):
  seq_file: Introduce DEFINE_STORE_ATTRIBUTE() helper macro
  scsi: hisi_sas: Introduce DEFINE_STORE_ATTRIBUTE for debugfs
  scsi: qla2xxx: Introduce DEFINE_STORE_ATTRIBUTE for debugfs
  usb: dwc3: debugfs: Introduce DEFINE_STORE_ATTRIBUTE
  drm/i915/display: Introduce DEFINE_STORE_ATTRIBUTE for debugfs

 .../gpu/drm/i915/display/intel_display_debugfs.c   |  55 +
 drivers/scsi/hisi_sas/hisi_sas_main.c  | 135 +++--
 drivers/scsi/qla2xxx/qla_dfs.c |  19 +--
 drivers/usb/dwc3/debugfs.c |  52 +---
 include/linux/seq_file.h   |  15 +++
 5 files changed, 41 insertions(+), 235 deletions(-)

-- 
2.7.4



[PATCH -next] fs_parse: mark fs_param_bad_value() as static

2020-09-28 Thread Luo Jiaxing
We found the following warning when build kernel with W=1:

fs/fs_parser.c:192:5: warning: no previous prototype for ‘fs_param_bad_value’ 
[-Wmissing-prototypes]
int fs_param_bad_value(struct p_log *log, struct fs_parameter *param)
 ^
CC  drivers/usb/gadget/udc/snps_udc_core.o

And no header file define a prototype for this function, so we should mark
it as static.

Signed-off-by: Luo Jiaxing 
---
 fs/fs_parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fs_parser.c b/fs/fs_parser.c
index ab53e42..68b0148 100644
--- a/fs/fs_parser.c
+++ b/fs/fs_parser.c
@@ -189,7 +189,7 @@ int fs_lookup_param(struct fs_context *fc,
 }
 EXPORT_SYMBOL(fs_lookup_param);
 
-int fs_param_bad_value(struct p_log *log, struct fs_parameter *param)
+static int fs_param_bad_value(struct p_log *log, struct fs_parameter *param)
 {
return inval_plog(log, "Bad value for '%s'", param->key);
 }
-- 
2.7.4



[PATCH] drm/msm/dpu: remove unused variables new_cnt and old_cnt in dpu_encoder_phys_vid_vblank_irq()

2020-09-16 Thread Luo Jiaxing
We found two unused variables new_cnt and old_cnt when build kernel with
W=1.

So delete it.

Signed-off-by: Luo Jiaxing 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c
index b5a4905..377ce8d 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c
@@ -298,7 +298,6 @@ static void dpu_encoder_phys_vid_vblank_irq(void *arg, int 
irq_idx)
struct dpu_hw_ctl *hw_ctl;
unsigned long lock_flags;
u32 flush_register = 0;
-   int new_cnt = -1, old_cnt = -1;
 
hw_ctl = phys_enc->hw_ctl;
 
@@ -308,7 +307,7 @@ static void dpu_encoder_phys_vid_vblank_irq(void *arg, int 
irq_idx)
phys_enc->parent_ops->handle_vblank_virt(phys_enc->parent,
phys_enc);
 
-   old_cnt  = atomic_read(&phys_enc->pending_kickoff_cnt);
+   atomic_read(&phys_enc->pending_kickoff_cnt);
 
/*
 * only decrement the pending flush count if we've actually flushed
@@ -320,8 +319,7 @@ static void dpu_encoder_phys_vid_vblank_irq(void *arg, int 
irq_idx)
flush_register = hw_ctl->ops.get_flush_register(hw_ctl);
 
if (!(flush_register & hw_ctl->ops.get_pending_flush(hw_ctl)))
-   new_cnt = atomic_add_unless(&phys_enc->pending_kickoff_cnt,
-   -1, 0);
+   atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0);
spin_unlock_irqrestore(phys_enc->enc_spinlock, lock_flags);
 
/* Signal any waiting atomic commit thread */
-- 
2.7.4



[PATCH net-next] net: ethernet: mlx4: Avoid assigning a value to ring_cons but not used it anymore in mlx4_en_xmit()

2020-09-12 Thread Luo Jiaxing
We found a set but not used variable 'ring_cons' in mlx4_en_xmit(), it will
cause a warning when build the kernel. And after checking the commit record
of this function, we found that it was introduced by a previous patch.

So, We delete this redundant assignment code.

Fixes: 488a9b48e398 ("net/mlx4_en: Wake TX queues only when there's enough 
room")

Signed-off-by: Luo Jiaxing 
---
 drivers/net/ethernet/mellanox/mlx4/en_tx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 9dff7b0..d554344 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -1075,7 +1075,6 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct 
net_device *dev)
 */
smp_rmb();
 
-   ring_cons = READ_ONCE(ring->cons);
if (unlikely(!mlx4_en_is_tx_ring_full(ring))) {
netif_tx_wake_queue(ring->tx_queue);
ring->wake_queue++;
-- 
2.7.4



[PATCH net-next] net: stmmac: set get_rx_header_len() as void for it didn't have any error code to return

2020-09-10 Thread Luo Jiaxing
We found the following warning when using W=1 to build kernel:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3634:6: warning: variable 
‘ret’ set but not used [-Wunused-but-set-variable]
int ret, coe = priv->hw->rx_csum;

When digging stmmac_get_rx_header_len(), dwmac4_get_rx_header_len() and
dwxgmac2_get_rx_header_len() return 0 only, without any error code to
report. Therefore, it's better to define get_rx_header_len() as void.

Signed-off-by: Luo Jiaxing 
---
 drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c   | 3 +--
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 3 +--
 drivers/net/ethernet/stmicro/stmmac/hwif.h   | 4 ++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c| 4 ++--
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index eff8206..c6540b0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -494,10 +494,9 @@ static void dwmac4_set_vlan(struct dma_desc *p, u32 type)
p->des2 |= cpu_to_le32(type & TDES2_VLAN_TAG_MASK);
 }
 
-static int dwmac4_get_rx_header_len(struct dma_desc *p, unsigned int *len)
+static void dwmac4_get_rx_header_len(struct dma_desc *p, unsigned int *len)
 {
*len = le32_to_cpu(p->des2) & RDES2_HL;
-   return 0;
 }
 
 static void dwmac4_set_sec_addr(struct dma_desc *p, dma_addr_t addr)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c 
b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
index c3d654c..0aaf19a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c
@@ -286,11 +286,10 @@ static int dwxgmac2_get_rx_hash(struct dma_desc *p, u32 
*hash,
return -EINVAL;
 }
 
-static int dwxgmac2_get_rx_header_len(struct dma_desc *p, unsigned int *len)
+static void dwxgmac2_get_rx_header_len(struct dma_desc *p, unsigned int *len)
 {
if (le32_to_cpu(p->des3) & XGMAC_RDES3_L34T)
*len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL;
-   return 0;
 }
 
 static void dwxgmac2_set_sec_addr(struct dma_desc *p, dma_addr_t addr)
diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h 
b/drivers/net/ethernet/stmicro/stmmac/hwif.h
index ffe2d63..e2dca9b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/hwif.h
+++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -90,7 +90,7 @@ struct stmmac_desc_ops {
/* RSS */
int (*get_rx_hash)(struct dma_desc *p, u32 *hash,
   enum pkt_hash_types *type);
-   int (*get_rx_header_len)(struct dma_desc *p, unsigned int *len);
+   void (*get_rx_header_len)(struct dma_desc *p, unsigned int *len);
void (*set_sec_addr)(struct dma_desc *p, dma_addr_t addr);
void (*set_sarc)(struct dma_desc *p, u32 sarc_type);
void (*set_vlan_tag)(struct dma_desc *p, u16 tag, u16 inner_tag,
@@ -150,7 +150,7 @@ struct stmmac_desc_ops {
 #define stmmac_get_rx_hash(__priv, __args...) \
stmmac_do_callback(__priv, desc, get_rx_hash, __args)
 #define stmmac_get_rx_header_len(__priv, __args...) \
-   stmmac_do_callback(__priv, desc, get_rx_header_len, __args)
+   stmmac_do_void_callback(__priv, desc, get_rx_header_len, __args)
 #define stmmac_set_desc_sec_addr(__priv, __args...) \
stmmac_do_void_callback(__priv, desc, set_sec_addr, __args)
 #define stmmac_set_desc_sarc(__priv, __args...) \
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 89b2b34..7e95412 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3631,15 +3631,15 @@ static unsigned int stmmac_rx_buf1_len(struct 
stmmac_priv *priv,
   struct dma_desc *p,
   int status, unsigned int len)
 {
-   int ret, coe = priv->hw->rx_csum;
unsigned int plen = 0, hlen = 0;
+   int coe = priv->hw->rx_csum;
 
/* Not first descriptor, buffer is always zero */
if (priv->sph && len)
return 0;
 
/* First descriptor, get split header length */
-   ret = stmmac_get_rx_header_len(priv, p, &hlen);
+   stmmac_get_rx_header_len(priv, p, &hlen);
if (priv->sph && hlen) {
priv->xstats.rx_split_hdr_pkt_n++;
return hlen;
-- 
2.7.4



[PATCH net-next] net: stmmac: Remove unused variable 'ret' at stmmac_rx_buf1_len()

2020-09-09 Thread Luo Jiaxing
Fixes the following warning when using W=1 to build kernel:

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3634:6: warning: variable 
‘ret’ set but not used [-Wunused-but-set-variable]
int ret, coe = priv->hw->rx_csum;

When digging stmmac_get_rx_header_len(), dwmac4_get_rx_header_len() and
dwxgmac2_get_rx_header_len() return 0 by default. Therefore, ret do not
need to check the error value and can be directly deleted.

Signed-off-by: Luo Jiaxing 
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 89b2b34..7e95412 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3631,15 +3631,15 @@ static unsigned int stmmac_rx_buf1_len(struct 
stmmac_priv *priv,
   struct dma_desc *p,
   int status, unsigned int len)
 {
-   int ret, coe = priv->hw->rx_csum;
unsigned int plen = 0, hlen = 0;
+   int coe = priv->hw->rx_csum;
 
/* Not first descriptor, buffer is always zero */
if (priv->sph && len)
return 0;
 
/* First descriptor, get split header length */
-   ret = stmmac_get_rx_header_len(priv, p, &hlen);
+   stmmac_get_rx_header_len(priv, p, &hlen);
if (priv->sph && hlen) {
priv->xstats.rx_split_hdr_pkt_n++;
return hlen;
-- 
2.7.4



[PATCH v1] scsi: libsas: set data_dir as DMA_NONE if libata mark qc as NODATA

2020-08-26 Thread Luo Jiaxing
We found that it will fail every time when set feature to SATA disk by
"sdparm -s WCE=0 /dev/sde".

After checking protocol, we know that MODE SELECT is the SCSI command for
setting WCE, and it do not exist in the SATA protocol. Therefore, this
commands are encapsulated in the SET FEATURE command in SATA protocol.
The difference is that the MODE SELECT command sent to SAS disk contains
data and is sent through the DMA. But when send to SATA disk through
SET FEATURE command, it does not contain data.

I think libsas was not thorough enough in dealing with the situation, at
sas_ata_qc_issue(), task->dma_dir is inherited from qc->dma_dir(qc->dma_dir
is also inherited from SCSI). However, in ATA driver, if qc->tf.protocol is
set to ATA_PROT_NODATA, ata_sg_setup() will not invoked by ata_qc_issue().
It mean that ATA didn't use dma_dir and it's not reliable. So, if libsas
still inherits from qc->dma_dir when there is no data need to be send. As a
result, task with no data are mistakenly considered as carrying data and it
will make LLDD report an error on IO completion.

So, When ATA driver mark tf->protocol as NODATA, dma_dir should be set as
DMA_NONE. And we can see WCE is successfully disable for SATA disk then.

Euler:~ # sdparm -s WCE=0 /dev/sde
 /dev/sde: ATA   ST4000NM0035-1V4  TN03
Euler:~ # sdparm /dev/sde
 /dev/sde: ATA   ST4000NM0035-1V4  TN03
Read write error recovery mode page:
   AWRE1  [cha: n, def:  1]
   ARRE0  [cha: n, def:  0]
   PER 0  [cha: n, def:  0]
Caching (SBC) mode page:
   WCE 0  [cha: y, def:  0]
   RCD 0  [cha: n, def:  0]
Control mode page:
   SWP 0  [cha: n, def:  0]

Fixes: fa1c1e8f1ece ("[SCSI] Add SATA support to libsas")

Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
---
 drivers/scsi/libsas/sas_ata.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 6a521ba..a488798 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -209,7 +209,10 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd 
*qc)
task->num_scatter = si;
}
 
-   task->data_dir = qc->dma_dir;
+   if (qc->tf.protocol == ATA_PROT_NODATA)
+   task->data_dir = DMA_NONE;
+   else
+   task->data_dir = qc->dma_dir;
task->scatter = qc->sg;
task->ata_task.retry_count = 1;
task->task_state_flags = SAS_TASK_STATE_PENDING;
-- 
2.7.4



[PATCH v2 0/2] scsi: libsas: An improvement on error handle and tidy-up

2020-07-25 Thread Luo Jiaxing
This patch introduces an improvement to reduce error handle time and a
tidy-up, including: 
- postreset() is deleted from sas_sata_ops. 
- Do not perform hard reset and delayed retry on a removed SATA disk. This
can effectively reduce the error handle duration of hot unplug a SATA disk
with traffic(reduce about 30s depending on the delay setting of libata). 

Both John garry and Jason Yan participated in the review of the solution
and provided good suggestions during the development.

Change since v1:
- Removed an unnecessary tag from subject.

Luo Jiaxing (2):
  scsi: libsas: delete postreset at sas_sata_ops
  scsi: libsas: check link status at ATA prereset() ops

 drivers/scsi/libsas/sas_ata.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

-- 
2.7.4



[PATCH v2 1/2] scsi: libsas: delete postreset at sas_sata_ops

2020-07-25 Thread Luo Jiaxing
We fill postreset with ata_std_postreset() at sas_sata_ops before, but we
found out that ata_std_postreset() call sata_scr_read()/sata_scr_write()
which need to access SCR register. Actually we don't own these kind of
register, so sata_scr_read()/sata_scr_write always return -EOPNOTSUPP.

We drop ata_std_postreset() at sas_sata_ops.

Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
Reviewed-by: Jason Yan 
---
 drivers/scsi/libsas/sas_ata.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 5d716d3..a7d16d2 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -510,7 +510,6 @@ void sas_ata_end_eh(struct ata_port *ap)
 static struct ata_port_operations sas_sata_ops = {
.prereset   = ata_std_prereset,
.hardreset  = sas_ata_hard_reset,
-   .postreset  = ata_std_postreset,
.error_handler  = ata_std_error_handler,
.post_internal_cmd  = sas_ata_post_internal,
.qc_defer   = ata_std_qc_defer,
-- 
2.7.4



[PATCH v2 2/2] scsi: libsas: check link status at ATA prereset() ops

2020-07-25 Thread Luo Jiaxing
We found out that libata will retry reset even if SATA disk is unpluged. We
should report offline to libata to avoid meaningless reset on the disk.
Libata provide an ops of prereset() for this purpose, it was called by
ata_eh_reset() only and used to decide whether to skip reset base on the
return value of it.

We check status of phy and disk at prereset(). If disk is already offline
or phy is disabled, we return -ENOENT to libata to skip disk reset.

As prereset() should be best-effort, we should continue to try disk reset
beyond the situation we mentioned before.

Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
Reviewed-by: Jason Yan 
---
 drivers/scsi/libsas/sas_ata.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index a7d16d2..1b93332 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -507,8 +507,22 @@ void sas_ata_end_eh(struct ata_port *ap)
spin_unlock_irqrestore(&ha->lock, flags);
 }
 
+static int sas_ata_prereset(struct ata_link *link, unsigned long deadline)
+{
+   struct ata_port *ap = link->ap;
+   struct domain_device *dev = ap->private_data;
+   struct sas_phy *local_phy = sas_get_local_phy(dev);
+   int res = 0;
+
+   if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state))
+   res = -ENOENT;
+   sas_put_local_phy(local_phy);
+
+   return res;
+}
+
 static struct ata_port_operations sas_sata_ops = {
-   .prereset   = ata_std_prereset,
+   .prereset   = sas_ata_prereset,
.hardreset  = sas_ata_hard_reset,
.error_handler  = ata_std_error_handler,
.post_internal_cmd  = sas_ata_post_internal,
-- 
2.7.4



[PATCH v1 2/2] {topost} scsi: libsas: check link status at ATA prereset() ops

2020-07-22 Thread Luo Jiaxing
We found out that libata will retry reset even if SATA disk is unpluged. We
should report offline to libata to avoid meaningless reset on the disk.
Libata provide an ops of prereset() for this purpose, it was called by
ata_eh_reset() only and used to decide whether to skip reset base on the
return value of it.

We check status of phy and disk at prereset(). If disk is already offline
or phy is disabled, we return -ENOENT to libata to skip disk reset.

As prereset() should be best-effort, we should continue to try disk reset
beyond the situation we mentioned before.

Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
---
 drivers/scsi/libsas/sas_ata.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index a7d16d2..1b93332 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -507,8 +507,22 @@ void sas_ata_end_eh(struct ata_port *ap)
spin_unlock_irqrestore(&ha->lock, flags);
 }
 
+static int sas_ata_prereset(struct ata_link *link, unsigned long deadline)
+{
+   struct ata_port *ap = link->ap;
+   struct domain_device *dev = ap->private_data;
+   struct sas_phy *local_phy = sas_get_local_phy(dev);
+   int res = 0;
+
+   if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state))
+   res = -ENOENT;
+   sas_put_local_phy(local_phy);
+
+   return res;
+}
+
 static struct ata_port_operations sas_sata_ops = {
-   .prereset   = ata_std_prereset,
+   .prereset   = sas_ata_prereset,
.hardreset  = sas_ata_hard_reset,
.error_handler  = ata_std_error_handler,
.post_internal_cmd  = sas_ata_post_internal,
-- 
2.7.4



[PATCH v1 0/2] scsi: libsas: An improvement on error handle and tidy-up

2020-07-22 Thread Luo Jiaxing
This patch introduces an improvement to reduce error handle time and a
tidy-up, including: 
- postreset() is deleted from sas_sata_ops. 
- Do not perform hard reset and delayed retry on a removed SATA disk. This
can effectively reduce the error handle duration of hot unplug a SATA disk
with traffic(reduce about 30s depending on the delay setting of libata). 

Both John garry and Jason Yan participated in the review of the solution
and provided good suggestions during the development. 

Luo Jiaxing (2):
  {topost} scsi: libsas: delete postreset at sas_sata_ops
  {topost} scsi: libsas: check link status at ATA prereset() ops

 drivers/scsi/libsas/sas_ata.c | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

-- 
2.7.4



[PATCH v1 1/2] {topost} scsi: libsas: delete postreset at sas_sata_ops

2020-07-22 Thread Luo Jiaxing
We fill postreset with ata_std_postreset() at sas_sata_ops before, but we
found out that ata_std_postreset() call sata_scr_read()/sata_scr_write()
which need to access SCR register. Actually we don't own these kind of
register, so sata_scr_read()/sata_scr_write always return -EOPNOTSUPP.

We drop ata_std_postreset() at sas_sata_ops.

Signed-off-by: Luo Jiaxing 
Reviewed-by: John Garry 
---
 drivers/scsi/libsas/sas_ata.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 5d716d3..a7d16d2 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -510,7 +510,6 @@ void sas_ata_end_eh(struct ata_port *ap)
 static struct ata_port_operations sas_sata_ops = {
.prereset   = ata_std_prereset,
.hardreset  = sas_ata_hard_reset,
-   .postreset  = ata_std_postreset,
.error_handler  = ata_std_error_handler,
.post_internal_cmd  = sas_ata_post_internal,
.qc_defer   = ata_std_qc_defer,
-- 
2.7.4