[PATCH v2 3/3] crypto: sa2ul: Add support for AM64

2021-04-13 Thread Vaibhav Gupta
From: Peter Ujfalusi 

The sa2ul module in am64 have limited support for algorithms, and the
priv and priv_id used on the platform is different compared to AM654 or
j721e.

Use match data to get the SoC specific information and use it throughout
the driver.

Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 drivers/crypto/sa2ul.c | 131 +
 drivers/crypto/sa2ul.h |   4 ++
 2 files changed, 96 insertions(+), 39 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 6107bfea862d..8a17ab8af444 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -69,8 +69,24 @@
 /* Max Authentication tag size */
 #define SA_MAX_AUTH_TAG_SZ 64
 
-#define PRIV_ID0x1
-#define PRIV   0x1
+enum sa_algo_id {
+   SA_ALG_CBC_AES = 0,
+   SA_ALG_EBC_AES,
+   SA_ALG_CBC_DES3,
+   SA_ALG_ECB_DES3,
+   SA_ALG_SHA1,
+   SA_ALG_SHA256,
+   SA_ALG_SHA512,
+   SA_ALG_AUTHENC_SHA1_AES,
+   SA_ALG_AUTHENC_SHA256_AES,
+};
+
+struct sa_match_data {
+   u8 priv;
+   u8 priv_id;
+   u32 supported_algos;
+   bool skip_engine_control;
+};
 
 static struct device *sa_k3_dev;
 
@@ -696,8 +712,9 @@ static void sa_dump_sc(u8 *buf, dma_addr_t dma_addr)
 }
 
 static
-int sa_init_sc(struct sa_ctx_info *ctx, const u8 *enc_key,
-  u16 enc_key_sz, const u8 *auth_key, u16 auth_key_sz,
+int sa_init_sc(struct sa_ctx_info *ctx, const struct sa_match_data *match_data,
+  const u8 *enc_key, u16 enc_key_sz,
+  const u8 *auth_key, u16 auth_key_sz,
   struct algo_data *ad, u8 enc, u32 *swinfo)
 {
int enc_sc_offset = 0;
@@ -732,8 +749,8 @@ int sa_init_sc(struct sa_ctx_info *ctx, const u8 *enc_key,
sc_buf[SA_CTX_SCCTL_OWNER_OFFSET] = 0;
memcpy(_buf[2], _id, 2);
sc_buf[4] = 0x0;
-   sc_buf[5] = PRIV_ID;
-   sc_buf[6] = PRIV;
+   sc_buf[5] = match_data->priv_id;
+   sc_buf[6] = match_data->priv;
sc_buf[7] = 0x0;
 
/* Prepare context for encryption engine */
@@ -892,8 +909,8 @@ static int sa_cipher_setkey(struct crypto_skcipher *tfm, 
const u8 *key,
return ret;
 
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, key, keylen, NULL, 0, ad, 1,
-  >enc.epib[1]))
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, key, keylen, NULL, 
0,
+  ad, 1, >enc.epib[1]))
goto badkey;
 
cmdl_len = sa_format_cmdl_gen(,
@@ -905,8 +922,8 @@ static int sa_cipher_setkey(struct crypto_skcipher *tfm, 
const u8 *key,
ctx->enc.cmdl_size = cmdl_len;
 
/* Setup Decryption Security Context & Command label template */
-   if (sa_init_sc(>dec, key, keylen, NULL, 0, ad, 0,
-  >dec.epib[1]))
+   if (sa_init_sc(>dec, ctx->dev_data->match_data, key, keylen, NULL, 
0,
+  ad, 0, >dec.epib[1]))
goto badkey;
 
cfg.enc_eng_id = ad->enc_eng.eng_id;
@@ -1446,9 +1463,10 @@ static int sa_sha_setup(struct sa_tfm_ctx *ctx, struct  
algo_data *ad)
cfg.akey = NULL;
cfg.akey_len = 0;
 
+   ctx->dev_data = dev_get_drvdata(sa_k3_dev);
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, NULL, 0, NULL, 0, ad, 0,
-  >enc.epib[1]))
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, NULL, 0, NULL, 0,
+  ad, 0, >enc.epib[1]))
goto badkey;
 
cmdl_len = sa_format_cmdl_gen(,
@@ -1716,6 +1734,7 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, 
const char *hash,
int ret;
 
memzero_explicit(ctx, sizeof(*ctx));
+   ctx->dev_data = data;
 
ctx->shash = crypto_alloc_shash(hash, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(ctx->shash)) {
@@ -1817,8 +1836,8 @@ static int sa_aead_setkey(struct crypto_aead *authenc,
cfg.akey_len = keys.authkeylen;
 
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, keys.enckey, keys.enckeylen,
-  keys.authkey, keys.authkeylen,
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, keys.enckey,
+  keys.enckeylen, keys.authkey, keys.authkeylen,
   ad, 1, >enc.epib[1]))
return -EINVAL;
 
@@ -1831,8 +1850,8 @@ static int sa_aead_setkey(struct crypto_aead *authenc,
ctx->enc.cmdl_size = cmdl_len;
 
/* Setup Decryption Security Context & Command label template */
-   if (sa_init_sc(>dec, keys.enckey, keys.enckeylen,
-  keys.authkey, keys.authkeylen,
+   if (sa_init_sc(>dec, ctx->dev_data->match_data, keys.enckey,
+  keys.enckeylen, 

[PATCH v2 2/3] crypto: sa2ul: Support for per channel coherency

2021-04-13 Thread Vaibhav Gupta
From: Peter Ujfalusi 

On AM64 the DMA channel for sa2ul can be configured to be coherent or
non coherent via DT binding.

Use the dmaengine_get_device_for_dma_api() to get the device pointer which
should be used for with the dma_api to use matching dma_ops for the
channel coherency/non coherency.

Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 drivers/crypto/sa2ul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index f300b0a5958a..6107bfea862d 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -1106,7 +1106,7 @@ static int sa_run(struct sa_req *req)
else
dma_rx = pdata->dma_rx1;
 
-   ddev = dma_rx->device->dev;
+   ddev = dmaengine_get_dma_device(pdata->dma_tx);
rxd->ddev = ddev;
 
memcpy(cmdl, sa_ctx->cmdl, sa_ctx->cmdl_size);
-- 
2.31.0



[PATCH v2 0/3] Update dt-bindings and sa2ul driver for AM64x SoCs

2021-04-13 Thread Vaibhav Gupta
From: Vaibhav Gupta 

This patch series aims to modify necessary files before an entry for sa2ul
can be made in the respective am64 device tree.

v2?
  - Simplify the dt-binding changes.

Peter Ujfalusi (3):
  dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64
  crypto: sa2ul: Support for per channel coherency
  crypto: sa2ul: Add support for AM64

 .../devicetree/bindings/crypto/ti,sa2ul.yaml  |  24 +++-
 drivers/crypto/sa2ul.c| 133 --
 drivers/crypto/sa2ul.h|   4 +
 3 files changed, 120 insertions(+), 41 deletions(-)

-- 
2.31.0



[PATCH v2 1/3] dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64

2021-04-13 Thread Vaibhav Gupta
From: Peter Ujfalusi 

Add the AM64 version of sa2ul to the compatible list.

[v_gu...@ti.com: Conditional dma-coherent requirement, clocks]
Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 .../devicetree/bindings/crypto/ti,sa2ul.yaml  | 24 ++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml 
b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
index 1d48ac712b23..a410d2cedde6 100644
--- a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
+++ b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
@@ -14,6 +14,7 @@ properties:
 enum:
   - ti,j721e-sa2ul
   - ti,am654-sa2ul
+  - ti,am64-sa2ul
 
   reg:
 maxItems: 1
@@ -45,6 +46,18 @@ properties:
 description:
   Address translation for the possible RNG child node for SA2UL
 
+  clocks:
+items:
+  - description: Clock used by PKA
+  - description: Main Input Clock
+  - description: Clock used by rng
+
+  clock-names:
+items:
+  - const: pka_in_clk
+  - const: x1_clk
+  - const: x2_clk
+
 patternProperties:
   "^rng@[a-f0-9]+$":
 type: object
@@ -57,7 +70,16 @@ required:
   - power-domains
   - dmas
   - dma-names
-  - dma-coherent
+
+if:
+  properties:
+compatible:
+  enum:
+- ti,j721e-sa2ul
+- ti,am654-sa2ul
+then:
+  required:
+- dma-coherent
 
 additionalProperties: false
 
-- 
2.31.0



Re: [PATCH v1 1/3] dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64

2021-03-16 Thread Vaibhav Gupta
On Tue, Mar 16, 2021 at 04:05:58PM -0600, Rob Herring wrote:
> On Tue, Mar 09, 2021 at 01:50:03AM +0530, Vaibhav Gupta wrote:
> > From: Peter Ujfalusi 
> > 
> > Add the AM64 version of sa2ul to the compatible list.
> > 
> > [v_gu...@ti.com: Conditional dma-coherent requirement, clocks]
> > Signed-off-by: Peter Ujfalusi 
> > Signed-off-by: Vaibhav Gupta 
> > ---
> >  .../devicetree/bindings/crypto/ti,sa2ul.yaml  | 40 +++
> >  1 file changed, 33 insertions(+), 7 deletions(-)
> > 
> > diff --git a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml 
> > b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
> > index 1d48ac712b23..6eb9acd564c2 100644
> > --- a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
> > +++ b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
> > @@ -14,6 +14,7 @@ properties:
> >  enum:
> >- ti,j721e-sa2ul
> >- ti,am654-sa2ul
> > +  - ti,am64-sa2ul
> >  
> >reg:
> >  maxItems: 1
> > @@ -45,19 +46,44 @@ properties:
> >  description:
> >Address translation for the possible RNG child node for SA2UL
> >  
> > +  clocks:
> > +items:
> > +  - description: Clock used by PKA
> > +  - description: Main Input Clock
> > +  - description: Clock used by rng
> > +
> > +  clock-names:
> > +items:
> > +  - const: pka_in_clk
> > +  - const: x1_clk
> > +  - const: x2_clk
> > +
> >  patternProperties:
> >"^rng@[a-f0-9]+$":
> >  type: object
> >  description:
> >Child RNG node for SA2UL
> >  
> > -required:
> > -  - compatible
> > -  - reg
> > -  - power-domains
> > -  - dmas
> > -  - dma-names
> > -  - dma-coherent
> > +if:
> > +  properties:
> > +compatible:
> > +  const: ti,am64-sa2ul
> > +then:
> > +  required:
> > +- compatible
> > +- reg
> > +- power-domains
> > +- dmas
> > +- dma-names
> > +
> > +else:
> > +  required:
> > +- compatible
> > +- reg
> > +- power-domains
> > +- dmas
> > +- dma-names
> > +- dma-coherent
> 
> The only difference is 'dma-coherent'. You can simplify the if/then to 
> just that.
Hello Rob,

I agree with your point. But with that case we will have to modify/append the
'required' list. Something like:

if !(properties.compatible == 'ti,am64-sa2ul')
required += dma-coherent

I even tried to use anchors but that didn't help. I didn't find it even in
examples. Any hint how to achieve that?

Thanks,
Vaibhav


[PATCH v1 2/3] crypto: sa2ul: Support for per channel coherency

2021-03-08 Thread Vaibhav Gupta
From: Peter Ujfalusi 

On AM64 the DMA channel for sa2ul can be configured to be coherent or
non coherent via DT binding.

Use the dmaengine_get_device_for_dma_api() to get the device pointer which
should be used for with the dma_api to use matching dma_ops for the
channel coherency/non coherency.

Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 drivers/crypto/sa2ul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index f300b0a5958a..6107bfea862d 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -1106,7 +1106,7 @@ static int sa_run(struct sa_req *req)
else
dma_rx = pdata->dma_rx1;
 
-   ddev = dma_rx->device->dev;
+   ddev = dmaengine_get_dma_device(pdata->dma_tx);
rxd->ddev = ddev;
 
memcpy(cmdl, sa_ctx->cmdl, sa_ctx->cmdl_size);
-- 
2.30.1



[PATCH v1 3/3] crypto: sa2ul: Add support for AM64

2021-03-08 Thread Vaibhav Gupta
From: Peter Ujfalusi 

The sa2ul module in am64 have limited support for algorithms, and the
priv and priv_id used on the platform is different compared to AM654 or
j721e.

Use match data to get the SoC specific information and use it throughout
the driver.

Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 drivers/crypto/sa2ul.c | 131 +
 drivers/crypto/sa2ul.h |   4 ++
 2 files changed, 96 insertions(+), 39 deletions(-)

diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 6107bfea862d..8a17ab8af444 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -69,8 +69,24 @@
 /* Max Authentication tag size */
 #define SA_MAX_AUTH_TAG_SZ 64
 
-#define PRIV_ID0x1
-#define PRIV   0x1
+enum sa_algo_id {
+   SA_ALG_CBC_AES = 0,
+   SA_ALG_EBC_AES,
+   SA_ALG_CBC_DES3,
+   SA_ALG_ECB_DES3,
+   SA_ALG_SHA1,
+   SA_ALG_SHA256,
+   SA_ALG_SHA512,
+   SA_ALG_AUTHENC_SHA1_AES,
+   SA_ALG_AUTHENC_SHA256_AES,
+};
+
+struct sa_match_data {
+   u8 priv;
+   u8 priv_id;
+   u32 supported_algos;
+   bool skip_engine_control;
+};
 
 static struct device *sa_k3_dev;
 
@@ -696,8 +712,9 @@ static void sa_dump_sc(u8 *buf, dma_addr_t dma_addr)
 }
 
 static
-int sa_init_sc(struct sa_ctx_info *ctx, const u8 *enc_key,
-  u16 enc_key_sz, const u8 *auth_key, u16 auth_key_sz,
+int sa_init_sc(struct sa_ctx_info *ctx, const struct sa_match_data *match_data,
+  const u8 *enc_key, u16 enc_key_sz,
+  const u8 *auth_key, u16 auth_key_sz,
   struct algo_data *ad, u8 enc, u32 *swinfo)
 {
int enc_sc_offset = 0;
@@ -732,8 +749,8 @@ int sa_init_sc(struct sa_ctx_info *ctx, const u8 *enc_key,
sc_buf[SA_CTX_SCCTL_OWNER_OFFSET] = 0;
memcpy(_buf[2], _id, 2);
sc_buf[4] = 0x0;
-   sc_buf[5] = PRIV_ID;
-   sc_buf[6] = PRIV;
+   sc_buf[5] = match_data->priv_id;
+   sc_buf[6] = match_data->priv;
sc_buf[7] = 0x0;
 
/* Prepare context for encryption engine */
@@ -892,8 +909,8 @@ static int sa_cipher_setkey(struct crypto_skcipher *tfm, 
const u8 *key,
return ret;
 
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, key, keylen, NULL, 0, ad, 1,
-  >enc.epib[1]))
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, key, keylen, NULL, 
0,
+  ad, 1, >enc.epib[1]))
goto badkey;
 
cmdl_len = sa_format_cmdl_gen(,
@@ -905,8 +922,8 @@ static int sa_cipher_setkey(struct crypto_skcipher *tfm, 
const u8 *key,
ctx->enc.cmdl_size = cmdl_len;
 
/* Setup Decryption Security Context & Command label template */
-   if (sa_init_sc(>dec, key, keylen, NULL, 0, ad, 0,
-  >dec.epib[1]))
+   if (sa_init_sc(>dec, ctx->dev_data->match_data, key, keylen, NULL, 
0,
+  ad, 0, >dec.epib[1]))
goto badkey;
 
cfg.enc_eng_id = ad->enc_eng.eng_id;
@@ -1446,9 +1463,10 @@ static int sa_sha_setup(struct sa_tfm_ctx *ctx, struct  
algo_data *ad)
cfg.akey = NULL;
cfg.akey_len = 0;
 
+   ctx->dev_data = dev_get_drvdata(sa_k3_dev);
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, NULL, 0, NULL, 0, ad, 0,
-  >enc.epib[1]))
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, NULL, 0, NULL, 0,
+  ad, 0, >enc.epib[1]))
goto badkey;
 
cmdl_len = sa_format_cmdl_gen(,
@@ -1716,6 +1734,7 @@ static int sa_cra_init_aead(struct crypto_aead *tfm, 
const char *hash,
int ret;
 
memzero_explicit(ctx, sizeof(*ctx));
+   ctx->dev_data = data;
 
ctx->shash = crypto_alloc_shash(hash, 0, CRYPTO_ALG_NEED_FALLBACK);
if (IS_ERR(ctx->shash)) {
@@ -1817,8 +1836,8 @@ static int sa_aead_setkey(struct crypto_aead *authenc,
cfg.akey_len = keys.authkeylen;
 
/* Setup Encryption Security Context & Command label template */
-   if (sa_init_sc(>enc, keys.enckey, keys.enckeylen,
-  keys.authkey, keys.authkeylen,
+   if (sa_init_sc(>enc, ctx->dev_data->match_data, keys.enckey,
+  keys.enckeylen, keys.authkey, keys.authkeylen,
   ad, 1, >enc.epib[1]))
return -EINVAL;
 
@@ -1831,8 +1850,8 @@ static int sa_aead_setkey(struct crypto_aead *authenc,
ctx->enc.cmdl_size = cmdl_len;
 
/* Setup Decryption Security Context & Command label template */
-   if (sa_init_sc(>dec, keys.enckey, keys.enckeylen,
-  keys.authkey, keys.authkeylen,
+   if (sa_init_sc(>dec, ctx->dev_data->match_data, keys.enckey,
+  keys.enckeylen, 

[PATCH v1 1/3] dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64

2021-03-08 Thread Vaibhav Gupta
From: Peter Ujfalusi 

Add the AM64 version of sa2ul to the compatible list.

[v_gu...@ti.com: Conditional dma-coherent requirement, clocks]
Signed-off-by: Peter Ujfalusi 
Signed-off-by: Vaibhav Gupta 
---
 .../devicetree/bindings/crypto/ti,sa2ul.yaml  | 40 +++
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml 
b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
index 1d48ac712b23..6eb9acd564c2 100644
--- a/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
+++ b/Documentation/devicetree/bindings/crypto/ti,sa2ul.yaml
@@ -14,6 +14,7 @@ properties:
 enum:
   - ti,j721e-sa2ul
   - ti,am654-sa2ul
+  - ti,am64-sa2ul
 
   reg:
 maxItems: 1
@@ -45,19 +46,44 @@ properties:
 description:
   Address translation for the possible RNG child node for SA2UL
 
+  clocks:
+items:
+  - description: Clock used by PKA
+  - description: Main Input Clock
+  - description: Clock used by rng
+
+  clock-names:
+items:
+  - const: pka_in_clk
+  - const: x1_clk
+  - const: x2_clk
+
 patternProperties:
   "^rng@[a-f0-9]+$":
 type: object
 description:
   Child RNG node for SA2UL
 
-required:
-  - compatible
-  - reg
-  - power-domains
-  - dmas
-  - dma-names
-  - dma-coherent
+if:
+  properties:
+compatible:
+  const: ti,am64-sa2ul
+then:
+  required:
+- compatible
+- reg
+- power-domains
+- dmas
+- dma-names
+
+else:
+  required:
+- compatible
+- reg
+- power-domains
+- dmas
+- dma-names
+- dma-coherent
 
 additionalProperties: false
 
-- 
2.30.1



[PATCH v1 0/3] Update dt-bindings and sa2ul driver for AM64x SoCs

2021-03-08 Thread Vaibhav Gupta
From: Vaibhav Gupta 

This patch series aims to modify necessary files before an entry for sa2ul
can be made in the respective am64 device tree.

Peter Ujfalusi (3):
  dt-bindings: crypto: ti,sa2ul: Add new compatible for AM64
  crypto: sa2ul: Support for per channel coherency
  crypto: sa2ul: Add support for AM64

 .../devicetree/bindings/crypto/ti,sa2ul.yaml  |  40 +-
 drivers/crypto/sa2ul.c| 133 --
 drivers/crypto/sa2ul.h|   4 +
 3 files changed, 130 insertions(+), 47 deletions(-)

-- 
2.30.1



[PATCH v4 3/3] skd: use generic power management

2021-01-14 Thread Vaibhav Gupta
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta 
Tested-by: Damien Le Moal 
---
 drivers/block/skd_main.c | 30 --
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index a962b4551bed..8194b58525e2 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -3317,10 +3317,11 @@ static void skd_pci_remove(struct pci_dev *pdev)
return;
 }
 
-static int skd_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused skd_pci_suspend(struct device *dev)
 {
int i;
struct skd_device *skdev;
+   struct pci_dev *pdev = to_pci_dev(dev);
 
skdev = pci_get_drvdata(pdev);
if (!skdev) {
@@ -3339,18 +3340,15 @@ static int skd_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
if (skdev->pcie_error_reporting_is_enabled)
pci_disable_pcie_error_reporting(pdev);
 
-   pci_release_regions(pdev);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
return 0;
 }
 
-static int skd_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused skd_pci_resume(struct device *dev)
 {
int i;
int rc = 0;
struct skd_device *skdev;
+   struct pci_dev *pdev = to_pci_dev(dev);
 
skdev = pci_get_drvdata(pdev);
if (!skdev) {
@@ -3358,16 +3356,8 @@ static int skd_pci_resume(struct pci_dev *pdev)
return -1;
}
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
-   pci_restore_state(pdev);
+   device_wakeup_disable(dev);
 
-   rc = pci_enable_device(pdev);
-   if (rc)
-   return rc;
-   rc = pci_request_regions(pdev, DRV_NAME);
-   if (rc)
-   goto err_out;
rc = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
if (rc)
rc = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32));
@@ -3376,7 +3366,6 @@ static int skd_pci_resume(struct pci_dev *pdev)
goto err_out_regions;
}
 
-   pci_set_master(pdev);
rc = pci_enable_pcie_error_reporting(pdev);
if (rc) {
dev_err(>dev,
@@ -3429,10 +3418,6 @@ static int skd_pci_resume(struct pci_dev *pdev)
pci_disable_pcie_error_reporting(pdev);
 
 err_out_regions:
-   pci_release_regions(pdev);
-
-err_out:
-   pci_disable_device(pdev);
return rc;
 }
 
@@ -3452,13 +3437,14 @@ static void skd_pci_shutdown(struct pci_dev *pdev)
skd_stop_device(skdev);
 }
 
+static SIMPLE_DEV_PM_OPS(skd_pci_pm_ops, skd_pci_suspend, skd_pci_resume);
+
 static struct pci_driver skd_driver = {
.name   = DRV_NAME,
.id_table   = skd_pci_tbl,
.probe  = skd_pci_probe,
.remove = skd_pci_remove,
-   .suspend= skd_pci_suspend,
-   .resume = skd_pci_resume,
+   .driver.pm  = _pci_pm_ops,
.shutdown   = skd_pci_shutdown,
 };
 
-- 
2.30.0



[PATCH v4 0/3] block: use generic power management

2021-01-14 Thread Vaibhav Gupta
Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to upgrade power management in block
drivers. This has been done by upgrading .suspend() and .resume() callbacks.

The upgrade makes sure that the involvement of PCI Core does not change the
order of operations executed in a driver. Thus, does not change its behavior.

In general, drivers with legacy PM, .suspend() and .resume() make use of PCI
helper functions like pci_enable/disable_device_mem(), pci_set_power_state(),
pci_save/restore_state(), pci_enable/disable_device(), etc. to complete
their job.

The conversion requires the removal of those function calls, change the
callbacks' definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

Test tools:
- Compiler: gcc (GCC) 10.2.0
- allmodconfig build: make -j$(nproc) W=1 all

v4: patch-set rebased.

Vaibhav Gupta (3):
  mtip32xx: use generic power management
  rsxx: use generic power management
  skd: use generic power management

 drivers/block/mtip32xx/mtip32xx.c | 54 +++
 drivers/block/rsxx/core.c |  9 --
 drivers/block/skd_main.c  | 30 +
 3 files changed, 27 insertions(+), 66 deletions(-)

-- 
2.30.0



[PATCH v4 1/3] mtip32xx: use generic power management

2021-01-14 Thread Vaibhav Gupta
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta 
---
 drivers/block/mtip32xx/mtip32xx.c | 54 +++
 1 file changed, 12 insertions(+), 42 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c 
b/drivers/block/mtip32xx/mtip32xx.c
index 53ac59d19ae5..de1ac3366b97 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4232,14 +4232,13 @@ static void mtip_pci_remove(struct pci_dev *pdev)
  * 0  Success
  * <0 Error
  */
-static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused mtip_pci_suspend(struct device *dev)
 {
int rv = 0;
-   struct driver_data *dd = pci_get_drvdata(pdev);
+   struct driver_data *dd = dev_get_drvdata(dev);
 
if (!dd) {
-   dev_err(>dev,
-   "Driver private datastructure is NULL\n");
+   dev_err(dev, "Driver private datastructure is NULL\n");
return -EFAULT;
}
 
@@ -4247,21 +4246,8 @@ static int mtip_pci_suspend(struct pci_dev *pdev, 
pm_message_t mesg)
 
/* Disable ports & interrupts then send standby immediate */
rv = mtip_block_suspend(dd);
-   if (rv < 0) {
-   dev_err(>dev,
-   "Failed to suspend controller\n");
-   return rv;
-   }
-
-   /*
-* Save the pci config space to pdev structure &
-* disable the device
-*/
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   /* Move to Low power state*/
-   pci_set_power_state(pdev, PCI_D3hot);
+   if (rv < 0)
+   dev_err(dev, "Failed to suspend controller\n");
 
return rv;
 }
@@ -4273,42 +4259,25 @@ static int mtip_pci_suspend(struct pci_dev *pdev, 
pm_message_t mesg)
  *  0  Success
  *  <0 Error
  */
-static int mtip_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused mtip_pci_resume(struct device *dev)
 {
int rv = 0;
struct driver_data *dd;
 
-   dd = pci_get_drvdata(pdev);
+   dd = dev_get_drvdata(dev);
if (!dd) {
-   dev_err(>dev,
-   "Driver private datastructure is NULL\n");
+   dev_err(dev, "Driver private datastructure is NULL\n");
return -EFAULT;
}
 
-   /* Move the device to active State */
-   pci_set_power_state(pdev, PCI_D0);
-
-   /* Restore PCI configuration space */
-   pci_restore_state(pdev);
-
-   /* Enable the PCI device*/
-   rv = pcim_enable_device(pdev);
-   if (rv < 0) {
-   dev_err(>dev,
-   "Failed to enable card during resume\n");
-   goto err;
-   }
-   pci_set_master(pdev);
-
/*
 * Calls hbaReset, initPort, & startPort function
 * then enables interrupts
 */
rv = mtip_block_resume(dd);
if (rv < 0)
-   dev_err(>dev, "Unable to resume\n");
+   dev_err(dev, "Unable to resume\n");
 
-err:
clear_bit(MTIP_DDF_RESUME_BIT, >dd_flag);
 
return rv;
@@ -4339,14 +4308,15 @@ static const struct pci_device_id mtip_pci_tbl[] = {
{ 0 }
 };
 
+static SIMPLE_DEV_PM_OPS(mtip_pci_pm_ops, mtip_pci_suspend, mtip_pci_resume);
+
 /* Structure that describes the PCI driver functions. */
 static struct pci_driver mtip_pci_driver = {
.name   = MTIP_DRV_NAME,
.id_table   = mtip_pci_tbl,
.probe  = mtip_pci_probe,
.remove = mtip_pci_remove,
-   .suspend= mtip_pci_suspend,
-   .resume = mtip_pci_resume,
+   .driver.pm  = _pci_pm_ops,
.shutdown   = mtip_pci_shutdown,
 };
 
-- 
2.30.0



[PATCH v4 2/3] rsxx: use generic power management

2021-01-14 Thread Vaibhav Gupta
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta 
---
 drivers/block/rsxx/core.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index 63f549889f87..937ad8a28e85 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -1032,12 +1032,15 @@ static void rsxx_pci_remove(struct pci_dev *dev)
kfree(card);
 }
 
-static int rsxx_pci_suspend(struct pci_dev *dev, pm_message_t state)
+static int __maybe_unused rsxx_pci_suspend(
+   __attribute__((unused)) struct device *dev)
 {
/* We don't support suspend at this time. */
return -ENOSYS;
 }
 
+#define rsxx_pci_resume NULL
+
 static void rsxx_pci_shutdown(struct pci_dev *dev)
 {
struct rsxx_cardinfo *card = pci_get_drvdata(dev);
@@ -1073,12 +1076,14 @@ static const struct pci_device_id rsxx_pci_ids[] = {
 
 MODULE_DEVICE_TABLE(pci, rsxx_pci_ids);
 
+static SIMPLE_DEV_PM_OPS(rsxx_pci_pm_ops, rsxx_pci_suspend, rsxx_pci_resume);
+
 static struct pci_driver rsxx_pci_driver = {
.name   = DRIVER_NAME,
.id_table   = rsxx_pci_ids,
.probe  = rsxx_pci_probe,
.remove = rsxx_pci_remove,
-   .suspend= rsxx_pci_suspend,
+   .driver.pm  = _pci_pm_ops,
.shutdown   = rsxx_pci_shutdown,
.err_handler= _err_handler,
 };
-- 
2.30.0



[PATCH v2 3/3] via-agp: use generic power management

2021-01-12 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

After upgrading, .suspend() became an empty-body function, hence defined as
NULL.

Signed-off-by: Vaibhav Gupta 
---
 drivers/char/agp/via-agp.c | 25 +
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index 87a92a044570..a460ae352772 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -492,22 +492,11 @@ static void agp_via_remove(struct pci_dev *pdev)
agp_put_bridge(bridge);
 }
 
-#ifdef CONFIG_PM
+#define agp_via_suspend NULL
 
-static int agp_via_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused agp_via_resume(struct device *dev)
 {
-   pci_save_state (pdev);
-   pci_set_power_state (pdev, PCI_D3hot);
-
-   return 0;
-}
-
-static int agp_via_resume(struct pci_dev *pdev)
-{
-   struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
-
-   pci_set_power_state (pdev, PCI_D0);
-   pci_restore_state(pdev);
+   struct agp_bridge_data *bridge = dev_get_drvdata(dev);
 
if (bridge->driver == _agp3_driver)
return via_configure_agp3();
@@ -517,8 +506,6 @@ static int agp_via_resume(struct pci_dev *pdev)
return 0;
 }
 
-#endif /* CONFIG_PM */
-
 /* must be the same order as name table above */
 static const struct pci_device_id agp_via_pci_table[] = {
 #define ID(x) \
@@ -567,16 +554,14 @@ static const struct pci_device_id agp_via_pci_table[] = {
 
 MODULE_DEVICE_TABLE(pci, agp_via_pci_table);
 
+static SIMPLE_DEV_PM_OPS(agp_via_pm_ops, agp_via_suspend, agp_via_resume);
 
 static struct pci_driver agp_via_pci_driver = {
.name   = "agpgart-via",
.id_table   = agp_via_pci_table,
.probe  = agp_via_probe,
.remove = agp_via_remove,
-#ifdef CONFIG_PM
-   .suspend= agp_via_suspend,
-   .resume = agp_via_resume,
-#endif
+   .driver.pm  = _via_pm_ops,
 };
 
 
-- 
2.30.0



[PATCH v2 0/3] char: use generic power management

2021-01-12 Thread Vaibhav Gupta
Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to upgrade power management in char
drivers. This has been done by upgrading .suspend() and .resume() callbacks.

The upgrade makes sure that the involvement of PCI Core does not change the
order of operations executed in a driver. Thus, does not change its behavior.

In general, drivers with legacy PM, .suspend() and .resume() make use of PCI
helper functions like pci_enable/disable_device_mem(), pci_set_power_state(),
pci_save/restore_state(), pci_enable/disable_device(), etc. to complete
their job.

The conversion requires the removal of those function calls, change the
callbacks' definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

Test tools:
- Compiler: gcc (GCC) 10.2.0
- allmodconfig build: make -j$(nproc) W=1 all

v2: patch-set rebased.

Vaibhav Gupta (3):
  amd64-agp: use generic power management
  sis-agp: use generic power management
  via-agp: use generic power management

 drivers/char/agp/amd64-agp.c | 24 ++--
 drivers/char/agp/sis-agp.c   | 25 ++---
 drivers/char/agp/via-agp.c   | 25 +
 3 files changed, 17 insertions(+), 57 deletions(-)

-- 
2.30.0



[PATCH v2 1/3] amd64-agp: use generic power management

2021-01-12 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

After upgrading, .suspend() became an empty-body function, hence defined as
NULL.

Signed-off-by: Vaibhav Gupta 
---
 drivers/char/agp/amd64-agp.c | 24 ++--
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index b40edae32817..dc78a4fb879e 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -588,20 +588,11 @@ static void agp_amd64_remove(struct pci_dev *pdev)
agp_bridges_found--;
 }
 
-#ifdef CONFIG_PM
+#define agp_amd64_suspend NULL
 
-static int agp_amd64_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused agp_amd64_resume(struct device *dev)
 {
-   pci_save_state(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
-   return 0;
-}
-
-static int agp_amd64_resume(struct pci_dev *pdev)
-{
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
+   struct pci_dev *pdev = to_pci_dev(dev);
 
if (pdev->vendor == PCI_VENDOR_ID_NVIDIA)
nforce3_agp_init(pdev);
@@ -609,8 +600,6 @@ static int agp_amd64_resume(struct pci_dev *pdev)
return amd_8151_configure();
 }
 
-#endif /* CONFIG_PM */
-
 static const struct pci_device_id agp_amd64_pci_table[] = {
{
.class  = (PCI_CLASS_BRIDGE_HOST << 8),
@@ -738,15 +727,14 @@ static const struct pci_device_id 
agp_amd64_pci_promisc_table[] = {
{ }
 };
 
+static SIMPLE_DEV_PM_OPS(agp_amd64_pm_ops, agp_amd64_suspend, 
agp_amd64_resume);
+
 static struct pci_driver agp_amd64_pci_driver = {
.name   = "agpgart-amd64",
.id_table   = agp_amd64_pci_table,
.probe  = agp_amd64_probe,
.remove = agp_amd64_remove,
-#ifdef CONFIG_PM
-   .suspend= agp_amd64_suspend,
-   .resume = agp_amd64_resume,
-#endif
+   .driver.pm  = _amd64_pm_ops,
 };
 
 
-- 
2.30.0



[PATCH v2 2/3] sis-agp: use generic power management

2021-01-12 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

After upgrading, .suspend() became an empty-body function, hence defined as
NULL.

Signed-off-by: Vaibhav Gupta 
---
 drivers/char/agp/sis-agp.c | 25 ++---
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index 14909fc5d767..f8a02f4bef1b 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -217,26 +217,14 @@ static void agp_sis_remove(struct pci_dev *pdev)
agp_put_bridge(bridge);
 }
 
-#ifdef CONFIG_PM
+#define agp_sis_suspend NULL
 
-static int agp_sis_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused agp_sis_resume(
+   __attribute__((unused)) struct device *dev)
 {
-   pci_save_state(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
-   return 0;
-}
-
-static int agp_sis_resume(struct pci_dev *pdev)
-{
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
return sis_driver.configure();
 }
 
-#endif /* CONFIG_PM */
-
 static const struct pci_device_id agp_sis_pci_table[] = {
{
.class  = (PCI_CLASS_BRIDGE_HOST << 8),
@@ -419,15 +407,14 @@ static const struct pci_device_id agp_sis_pci_table[] = {
 
 MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
 
+static SIMPLE_DEV_PM_OPS(agp_sis_pm_ops, agp_sis_suspend, agp_sis_resume);
+
 static struct pci_driver agp_sis_pci_driver = {
.name   = "agpgart-sis",
.id_table   = agp_sis_pci_table,
.probe  = agp_sis_probe,
.remove = agp_sis_remove,
-#ifdef CONFIG_PM
-   .suspend= agp_sis_suspend,
-   .resume = agp_sis_resume,
-#endif
+   .driver.pm  = _sis_pm_ops,
 };
 
 static int __init agp_sis_init(void)
-- 
2.30.0



Re: [PATCH v1] i2c: nvidia-gpu: drop empty stub for runtime pm

2020-11-11 Thread Vaibhav Gupta
On Tue, Nov 10, 2020 at 02:33:43PM +0200, Jarkko Nikula wrote:
> On 11/7/20 11:04 AM, Vaibhav Gupta wrote:
> > On Sat, Nov 07, 2020 at 01:51:51PM +0530, Vaibhav Gupta wrote:
> > > After the commit c5eb1190074c ("PCI / PM: Allow runtime PM without 
> > > callback
> > > functions") we no more need empty stubs for runtime-pm to work.
> > > 
> > > The driver has no device specific task(s) for .suspend() . The stub was
> > > placed just for runtime-pm, which can be dropped now.
> > > 
> > > Reported-by: Bjorn Helgaas 
> > > Signed-off-by: Vaibhav Gupta 
> > > ---
> > >   drivers/i2c/busses/i2c-nvidia-gpu.c | 10 +-
> > >   1 file changed, 1 insertion(+), 9 deletions(-)
> > > 
> > > diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c 
> > > b/drivers/i2c/busses/i2c-nvidia-gpu.c
> > > index f9a69b109e5c..6b20601ffb13 100644
> > > --- a/drivers/i2c/busses/i2c-nvidia-gpu.c
> > > +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
> > > @@ -353,15 +353,7 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
> > >   pci_free_irq_vectors(pdev);
> > >   }
> > > -/*
> > > - * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
> > > - * correctly. Without it, lspci shows runtime pm status as "D0" for the 
> > > card.
> > > - * Documentation/power/pci.rst also insists for driver to provide this.
> > > - */
> > > -static __maybe_unused int gpu_i2c_suspend(struct device *dev)
> > > -{
> > > - return 0;
> > > -}
> > > +#define gpu_i2c_suspend NULL
> Perhaps we can put NULL directly into UNIVERSAL_DEV_PM_OPS() for the suspend
> callback?
> 
Yes. I have noticed that the approach for this is random. Many drivers pass
NULL directly to the dev_pm_ops type variable, and rest of them use a macro.

I used it for symmetry. I mean there is 'gpu_i2c_resume', so although a macro,
I have put a 'gpu_i2c_suspend'.

Although it won't make any significant change, but if required, I can send
another patch where NULL is passed into UNIVERSAL_DEV_PM_OPS() instead.
> > >   static __maybe_unused int gpu_i2c_resume(struct device *dev)
> > >   {
> > > -- 
> > > 2.28.0
> > > 
> > The patch is only compile-tested.
> > 
> It should work also system suspend point of view. This patch affects also it
> since callbacks are set with the UNIVERSAL_DEV_PM_OPS(). Means the same
> callback is used for runtime PM and system suspend.
> 
> I quickly debugged this with an another driver and PCI stack does put the
> device into D3 state in system suspend from pci_prepare_to_sleep() if the
> suspend callback is not set and device was on prior it.
> 
> Reviewed-by: Jarkko Nikula 


Thanks for debugging. Theoretically too, according to generic framework, drivers
are supposed to do only device specific jobs. If there is none, or callback is
set as NULL, remaining work to put the device in lower power state is PCI
stack's task.

--Vaibhav


Re: [PATCH v1] scsi: isci: Don't use PCI helper functions

2020-11-07 Thread Vaibhav Gupta
On Sat, Nov 07, 2020 at 03:34:19PM +0530, Vaibhav Gupta wrote:
> PCI helper functions such as pci_enable/disable_device(),
> pci_save/restore_state(), pci_set_power_state(), etc. were used by the
> legacy framework to perform standard operations related to PCI PM.
> 
> This driver is using the generic framework and thus calls for those
> functions should be dropped as those tasks are now performed by the PCI
> core.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/isci/init.c | 18 +-
>  1 file changed, 1 insertion(+), 17 deletions(-)
> 
> diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
> index 93bc9019667f..c452849e7bb4 100644
> --- a/drivers/scsi/isci/init.c
> +++ b/drivers/scsi/isci/init.c
> @@ -715,10 +715,6 @@ static int isci_suspend(struct device *dev)
>   isci_host_deinit(ihost);
>   }
>  
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, PCI_D3hot);
> -
>   return 0;
>  }
>  
> @@ -726,19 +722,7 @@ static int isci_resume(struct device *dev)
>  {
>   struct pci_dev *pdev = to_pci_dev(dev);
>   struct isci_host *ihost;
> - int rc, i;
> -
> - pci_set_power_state(pdev, PCI_D0);
> - pci_restore_state(pdev);
> -
> - rc = pcim_enable_device(pdev);
> - if (rc) {
> - dev_err(>dev,
> - "enabling device failure after resume(%d)\n", rc);
> - return rc;
> - }
> -
> - pci_set_master(pdev);
> + int i;
>  
>   for_each_isci_host(i, ihost, pdev) {
>   sas_prep_resume_ha(>sas_ha);
> -- 
> 2.28.0
> 
The patch is compile-tested only.

--Vaibhav


[PATCH v1] scsi: isci: Don't use PCI helper functions

2020-11-07 Thread Vaibhav Gupta
PCI helper functions such as pci_enable/disable_device(),
pci_save/restore_state(), pci_set_power_state(), etc. were used by the
legacy framework to perform standard operations related to PCI PM.

This driver is using the generic framework and thus calls for those
functions should be dropped as those tasks are now performed by the PCI
core.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/isci/init.c | 18 +-
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 93bc9019667f..c452849e7bb4 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -715,10 +715,6 @@ static int isci_suspend(struct device *dev)
isci_host_deinit(ihost);
}
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, PCI_D3hot);
-
return 0;
 }
 
@@ -726,19 +722,7 @@ static int isci_resume(struct device *dev)
 {
struct pci_dev *pdev = to_pci_dev(dev);
struct isci_host *ihost;
-   int rc, i;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   rc = pcim_enable_device(pdev);
-   if (rc) {
-   dev_err(>dev,
-   "enabling device failure after resume(%d)\n", rc);
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   int i;
 
for_each_isci_host(i, ihost, pdev) {
sas_prep_resume_ha(>sas_ha);
-- 
2.28.0



Re: [PATCH v1] i2c: nvidia-gpu: drop empty stub for runtime pm

2020-11-07 Thread Vaibhav Gupta
On Sat, Nov 07, 2020 at 01:51:51PM +0530, Vaibhav Gupta wrote:
> After the commit c5eb1190074c ("PCI / PM: Allow runtime PM without callback
> functions") we no more need empty stubs for runtime-pm to work.
> 
> The driver has no device specific task(s) for .suspend() . The stub was
> placed just for runtime-pm, which can be dropped now.
> 
> Reported-by: Bjorn Helgaas 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/i2c/busses/i2c-nvidia-gpu.c | 10 +-
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c 
> b/drivers/i2c/busses/i2c-nvidia-gpu.c
> index f9a69b109e5c..6b20601ffb13 100644
> --- a/drivers/i2c/busses/i2c-nvidia-gpu.c
> +++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
> @@ -353,15 +353,7 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
>   pci_free_irq_vectors(pdev);
>  }
>  
> -/*
> - * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
> - * correctly. Without it, lspci shows runtime pm status as "D0" for the card.
> - * Documentation/power/pci.rst also insists for driver to provide this.
> - */
> -static __maybe_unused int gpu_i2c_suspend(struct device *dev)
> -{
> - return 0;
> -}
> +#define gpu_i2c_suspend NULL
>  
>  static __maybe_unused int gpu_i2c_resume(struct device *dev)
>  {
> -- 
> 2.28.0
> 
The patch is only compile-tested.

--Vaibhav


[PATCH v1] i2c: nvidia-gpu: drop empty stub for runtime pm

2020-11-07 Thread Vaibhav Gupta
After the commit c5eb1190074c ("PCI / PM: Allow runtime PM without callback
functions") we no more need empty stubs for runtime-pm to work.

The driver has no device specific task(s) for .suspend() . The stub was
placed just for runtime-pm, which can be dropped now.

Reported-by: Bjorn Helgaas 
Signed-off-by: Vaibhav Gupta 
---
 drivers/i2c/busses/i2c-nvidia-gpu.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c 
b/drivers/i2c/busses/i2c-nvidia-gpu.c
index f9a69b109e5c..6b20601ffb13 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -353,15 +353,7 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
pci_free_irq_vectors(pdev);
 }
 
-/*
- * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
- * correctly. Without it, lspci shows runtime pm status as "D0" for the card.
- * Documentation/power/pci.rst also insists for driver to provide this.
- */
-static __maybe_unused int gpu_i2c_suspend(struct device *dev)
-{
-   return 0;
-}
+#define gpu_i2c_suspend NULL
 
 static __maybe_unused int gpu_i2c_resume(struct device *dev)
 {
-- 
2.28.0



[PATCH v4 28/29] scsi: pmcraid: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in pmcraid_resume(), and
there is no corresponding pci_enable_wake(, true) in pmcraid_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
pmcraid_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pmcraid.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index cbe5fab793eb..5c767cd8ffc3 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5271,7 +5271,6 @@ static int pmcraid_resume(struct pci_dev *pdev)
int rc;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
rc = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v4 29/29] scsi: pmcraid: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pmcraid.c | 43 ++
 1 file changed, 10 insertions(+), 33 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 5c767cd8ffc3..834556ea21d2 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5234,53 +5234,37 @@ static void pmcraid_remove(struct pci_dev *pdev)
return;
 }
 
-#ifdef CONFIG_PM
 /**
  * pmcraid_suspend - driver suspend entry point for power management
- * @pdev:   PCI device structure
- * @state:  PCI power state to suspend routine
+ * @dev:   Device structure
  *
  * Return Value - 0 always
  */
-static int pmcraid_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pmcraid_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
 
pmcraid_shutdown(pdev);
pmcraid_disable_interrupts(pinstance, ~0);
pmcraid_kill_tasklets(pinstance);
-   pci_set_drvdata(pinstance->pdev, pinstance);
pmcraid_unregister_interrupt_handler(pinstance);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
return 0;
 }
 
 /**
  * pmcraid_resume - driver resume entry point PCI power management
- * @pdev: PCI device structure
+ * @dev: Device structure
  *
  * Return Value - 0 in case of success. Error code in case of any failure
  */
-static int pmcraid_resume(struct pci_dev *pdev)
+static int __maybe_unused pmcraid_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
struct Scsi_Host *host = pinstance->host;
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   rc = pci_enable_device(pdev);
-
-   if (rc) {
-   dev_err(>dev, "resume: Enable device failed\n");
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   int rc = 0;
 
if (sizeof(dma_addr_t) == 4 ||
dma_set_mask(>dev, DMA_BIT_MASK(64)))
@@ -5333,18 +5317,10 @@ static int pmcraid_resume(struct pci_dev *pdev)
scsi_host_put(host);
 
 disable_device:
-   pci_disable_device(pdev);
 
return rc;
 }
 
-#else
-
-#define pmcraid_suspend NULL
-#define pmcraid_resume  NULL
-
-#endif /* CONFIG_PM */
-
 /**
  * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
  * completion of the ioa reset
@@ -5832,6 +5808,8 @@ static int pmcraid_probe(struct pci_dev *pdev,
return -ENODEV;
 }
 
+static SIMPLE_DEV_PM_OPS(pmcraid_pm_ops, pmcraid_suspend, pmcraid_resume);
+
 /*
  * PCI driver structure of pmcraid driver
  */
@@ -5840,8 +5818,7 @@ static struct pci_driver pmcraid_driver = {
.id_table = pmcraid_pci_table,
.probe = pmcraid_probe,
.remove = pmcraid_remove,
-   .suspend = pmcraid_suspend,
-   .resume = pmcraid_resume,
+   .driver.pm = _pm_ops,
.shutdown = pmcraid_shutdown
 };
 
-- 
2.28.0



[PATCH v4 24/29] scsi: 3w-sas: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-sas.c | 31 +++
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 0b4888199699..b8f1848ecef2 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1756,11 +1756,10 @@ static void twl_remove(struct pci_dev *pdev)
twl_device_extension_count--;
 } /* End twl_remove() */
 
-#ifdef CONFIG_PM
 /* This function is called on PCI suspend */
-static int twl_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused twl_suspend(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
+   struct Scsi_Host *host = dev_get_drvdata(dev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-sas: Suspending host %d.\n", 
tw_dev->host->host_no);
@@ -1779,31 +1778,18 @@ static int twl_suspend(struct pci_dev *pdev, 
pm_message_t state)
/* Clear doorbell interrupt */
TWL_CLEAR_DB_INTERRUPT(tw_dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 } /* End twl_suspend() */
 
 /* This function is called on PCI resume */
-static int twl_resume(struct pci_dev *pdev)
+static int __maybe_unused twl_resume(struct device *dev)
 {
int retval = 0;
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-sas: Resuming host %d.\n", 
tw_dev->host->host_no);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   retval = pci_enable_device(pdev);
-   if (retval) {
-   TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed 
during resume");
-   return retval;
-   }
-
-   pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
@@ -1841,11 +1827,9 @@ static int twl_resume(struct pci_dev *pdev)
 
 out_disable_device:
scsi_remove_host(host);
-   pci_disable_device(pdev);
 
return retval;
 } /* End twl_resume() */
-#endif
 
 /* PCI Devices supported by this driver */
 static struct pci_device_id twl_pci_tbl[] = {
@@ -1854,16 +1838,15 @@ static struct pci_device_id twl_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, twl_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(twl_pm_ops, twl_suspend, twl_resume);
+
 /* pci_driver initializer */
 static struct pci_driver twl_driver = {
.name   = "3w-sas",
.id_table   = twl_pci_tbl,
.probe  = twl_probe,
.remove = twl_remove,
-#ifdef CONFIG_PM
-   .suspend= twl_suspend,
-   .resume = twl_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = twl_shutdown
 };
 
-- 
2.28.0



[PATCH v4 23/29] scsi: 3w-sas: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in twl_resume(), and
there is no corresponding pci_enable_wake(, true) in twl_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
twl_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-sas.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index dda6fa857709..0b4888199699 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1795,7 +1795,6 @@ static int twl_resume(struct pci_dev *pdev)
 
printk(KERN_WARNING "3w-sas: Resuming host %d.\n", 
tw_dev->host->host_no);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
retval = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v4 26/29] scsi: mvumi: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 46 +---
 1 file changed, 9 insertions(+), 37 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 7cd9c70e32dd..bbf0faac1f05 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2568,46 +2568,26 @@ static void mvumi_shutdown(struct pci_dev *pdev)
mvumi_flush_cache(mhba);
 }
 
-static int __maybe_unused mvumi_suspend(struct pci_dev *pdev, pm_message_t 
state)
+static int __maybe_unused mvumi_suspend(struct device *dev)
 {
-   struct mvumi_hba *mhba = NULL;
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct mvumi_hba *mhba = pci_get_drvdata(pdev);
 
-   mhba = pci_get_drvdata(pdev);
mvumi_flush_cache(mhba);
 
-   pci_set_drvdata(pdev, mhba);
mhba->instancet->disable_intr(mhba);
-   free_irq(mhba->pdev->irq, mhba);
mvumi_unmap_pci_addr(pdev, mhba->base_addr);
-   pci_release_regions(pdev);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
return 0;
 }
 
-static int __maybe_unused mvumi_resume(struct pci_dev *pdev)
+static int __maybe_unused mvumi_resume(struct device *dev)
 {
int ret;
-   struct mvumi_hba *mhba = NULL;
-
-   mhba = pci_get_drvdata(pdev);
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   ret = pci_enable_device(pdev);
-   if (ret) {
-   dev_err(>dev, "enable device failed\n");
-   return ret;
-   }
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct mvumi_hba *mhba = pci_get_drvdata(pdev);
 
-   ret = mvumi_pci_set_master(pdev);
ret = dma_set_mask(>dev, DMA_BIT_MASK(32));
-   if (ret)
-   goto fail;
-   ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
if (ret)
goto fail;
ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
@@ -2627,12 +2607,6 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
goto unmap_pci_addr;
}
 
-   ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
-   "mvumi", mhba);
-   if (ret) {
-   dev_err(>dev, "failed to register IRQ\n");
-   goto unmap_pci_addr;
-   }
mhba->instancet->enable_intr(mhba);
 
return 0;
@@ -2642,11 +2616,12 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
 release_regions:
pci_release_regions(pdev);
 fail:
-   pci_disable_device(pdev);
 
return ret;
 }
 
+static SIMPLE_DEV_PM_OPS(mvumi_pm_ops, mvumi_suspend, mvumi_resume);
+
 static struct pci_driver mvumi_pci_driver = {
 
.name = MV_DRIVER_NAME,
@@ -2654,10 +2629,7 @@ static struct pci_driver mvumi_pci_driver = {
.probe = mvumi_probe_one,
.remove = mvumi_detach_one,
.shutdown = mvumi_shutdown,
-#ifdef CONFIG_PM
-   .suspend = mvumi_suspend,
-   .resume = mvumi_resume,
-#endif
+   .driver.pm = _pm_ops,
 };
 
 module_pci_driver(mvumi_pci_driver);
-- 
2.28.0



[PATCH v4 27/29] scsi: mvumi: update function description

2020-11-02 Thread Vaibhav Gupta
There is no "device" parameter in mvumi_shutdown(). Instead there is
"pdev" which is not described.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index bbf0faac1f05..6c82b0bc391a 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2559,7 +2559,7 @@ static void mvumi_detach_one(struct pci_dev *pdev)
 
 /**
  * mvumi_shutdown -Shutdown entry point
- * @device:Generic device structure
+ * @pdev:  PCI device structure
  */
 static void mvumi_shutdown(struct pci_dev *pdev)
 {
-- 
2.28.0



[PATCH v4 25/29] scsi: mvumi: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in mvumi_resume(), and
there is no corresponding pci_enable_wake(, true) in mvumi_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
mvumi_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 0354898d7cac..7cd9c70e32dd 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2595,7 +2595,6 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
mhba = pci_get_drvdata(pdev);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
ret = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v4 20/29] scsi: hpsa: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hpsa.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 83ce4f11a589..e53364141fa3 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -9090,25 +9090,27 @@ static void hpsa_remove_one(struct pci_dev *pdev)
hpda_free_ctlr_info(h); /* init_one 1 */
 }
 
-static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev,
-   __attribute__((unused)) pm_message_t state)
+static int __maybe_unused hpsa_suspend(
+   __attribute__((unused)) struct device *dev)
 {
return -ENOSYS;
 }
 
-static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev)
+static int __maybe_unused hpsa_resume
+   (__attribute__((unused)) struct device *dev)
 {
return -ENOSYS;
 }
 
+static SIMPLE_DEV_PM_OPS(hpsa_pm_ops, hpsa_suspend, hpsa_resume);
+
 static struct pci_driver hpsa_pci_driver = {
.name = HPSA,
.probe = hpsa_init_one,
.remove = hpsa_remove_one,
.id_table = hpsa_pci_device_id, /* id_table */
.shutdown = hpsa_shutdown,
-   .suspend = hpsa_suspend,
-   .resume = hpsa_resume,
+   .driver.pm = _pm_ops,
 };
 
 /* Fill in bucket_map[], given nsgs (the max number of
-- 
2.28.0



[PATCH v4 21/29] scsi: 3w-9xxx: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in twa_resume(), and
there is no corresponding pci_enable_wake(, true) in twa_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
twa_resume().

Signed-off-by: Vaibhav Gupta 
Acked-by: Don Brace 
---
 drivers/scsi/3w-9xxx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 3337b1e80412..e458e99ff161 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -2230,7 +2230,6 @@ static int twa_resume(struct pci_dev *pdev)
 
printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", 
tw_dev->host->host_no);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
retval = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v4 22/29] scsi: 3w-9xxx: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-9xxx.c | 29 +++--
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index e458e99ff161..b4718a1b2bd6 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -2191,10 +2191,10 @@ static void twa_remove(struct pci_dev *pdev)
twa_device_extension_count--;
 } /* End twa_remove() */
 
-#ifdef CONFIG_PM
 /* This function is called on PCI suspend */
-static int twa_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused twa_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
@@ -2214,31 +2214,19 @@ static int twa_suspend(struct pci_dev *pdev, 
pm_message_t state)
}
TW_CLEAR_ALL_INTERRUPTS(tw_dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 } /* End twa_suspend() */
 
 /* This function is called on PCI resume */
-static int twa_resume(struct pci_dev *pdev)
+static int __maybe_unused twa_resume(struct device *dev)
 {
int retval = 0;
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", 
tw_dev->host->host_no);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
 
-   retval = pci_enable_device(pdev);
-   if (retval) {
-   TW_PRINTK(tw_dev->host, TW_DRIVER, 0x39, "Enable device failed 
during resume");
-   return retval;
-   }
-
-   pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
@@ -2276,11 +2264,9 @@ static int twa_resume(struct pci_dev *pdev)
 
 out_disable_device:
scsi_remove_host(host);
-   pci_disable_device(pdev);
 
return retval;
 } /* End twa_resume() */
-#endif
 
 /* PCI Devices supported by this driver */
 static struct pci_device_id twa_pci_tbl[] = {
@@ -2296,16 +2282,15 @@ static struct pci_device_id twa_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, twa_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(twa_pm_ops, twa_suspend, twa_resume);
+
 /* pci_driver initializer */
 static struct pci_driver twa_driver = {
.name   = "3w-9xxx",
.id_table   = twa_pci_tbl,
.probe  = twa_probe,
.remove = twa_remove,
-#ifdef CONFIG_PM
-   .suspend= twa_suspend,
-   .resume = twa_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = twa_shutdown
 };
 
-- 
2.28.0



[PATCH v4 17/29] scsi: lpfc: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/lpfc/lpfc_init.c | 100 +++---
 1 file changed, 33 insertions(+), 67 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index ca25e54bb782..bf12328a5e45 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12581,8 +12581,7 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
 
 /**
  * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
- * @pdev: pointer to PCI device
- * @msg: power management message
+ * @dev_d: pointer to device
  *
  * This routine is to be called from the kernel's PCI subsystem to support
  * system Power Management (PM) to device with SLI-3 interface spec. When
@@ -12600,10 +12599,10 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
+static int __maybe_unused
+lpfc_pci_suspend_one_s3(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
@@ -12617,16 +12616,12 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
pm_message_t msg)
/* Disable interrupt from device */
lpfc_sli_disable_intr(phba);
 
-   /* Save device state to PCI config space */
-   pci_save_state(pdev);
-   pci_set_power_state(pdev, PCI_D3hot);
-
return 0;
 }
 
 /**
  * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
- * @pdev: pointer to PCI device
+ * @dev_d: pointer to device
  *
  * This routine is to be called from the kernel's PCI subsystem to support
  * system Power Management (PM) to device with SLI-3 interface spec. When PM
@@ -12643,10 +12638,10 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
pm_message_t msg)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_resume_one_s3(struct pci_dev *pdev)
+static int __maybe_unused
+lpfc_pci_resume_one_s3(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
uint32_t intr_mode;
int error;
@@ -12654,19 +12649,6 @@ lpfc_pci_resume_one_s3(struct pci_dev *pdev)
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
"0452 PCI device Power Management resume.\n");
 
-   /* Restore device state from PCI config space */
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   /*
-* As the new kernel behavior of pci_restore_state() API call clears
-* device saved_state flag, need to save the restored state again.
-*/
-   pci_save_state(pdev);
-
-   if (pdev->is_busmaster)
-   pci_set_master(pdev);
-
/* Startup the kernel thread for this host adapter. */
phba->worker_thread = kthread_run(lpfc_do_work, phba,
"lpfc_worker_%d", phba->brd_no);
@@ -13423,8 +13405,7 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
 
 /**
  * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
- * @pdev: pointer to PCI device
- * @msg: power management message
+ * @dev_d: pointer to device
  *
  * This routine is called from the kernel's PCI subsystem to support system
  * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
@@ -13442,10 +13423,10 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
+static int __maybe_unused
+lpfc_pci_suspend_one_s4(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
@@ -13460,16 +13441,12 @@ lpfc_pci_suspend_one_s4(struct pci_dev *pdev, 
pm_message_t msg)
lpfc_sli4_disable_intr(phba);
lpfc_sli4_queue_dest

[PATCH v4 19/29] scsi: pm_8001: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pm8001/pm8001_init.c | 45 +++
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index d47ed9a33173..7a732fd09b38 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1257,23 +1257,21 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
 
 /**
  * pm8001_pci_suspend - power management suspend main entry point
- * @pdev: PCI device struct
- * @state: PM state change to (usually PCI_D3)
+ * @dev: Device struct
  *
  * Returns 0 success, anything else error.
  */
-static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pm8001_pci_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
-   struct pm8001_hba_info *pm8001_ha;
+   struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
int  i, j;
-   u32 device_state;
-   pm8001_ha = sha->lldd_ha;
sas_suspend_ha(sha);
flush_workqueue(pm8001_wq);
scsi_block_requests(pm8001_ha->shost);
if (!pdev->pm_cap) {
-   dev_err(>dev, " PCI PM not supported\n");
+   dev_err(dev, " PCI PM not supported\n");
return -ENODEV;
}
PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
@@ -1296,24 +1294,21 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
tasklet_kill(_ha->tasklet[j]);
 #endif
-   device_state = pci_choose_state(pdev, state);
pm8001_printk("pdev=0x%p, slot=%s, entering "
- "operating state [D%d]\n", pdev,
- pm8001_ha->name, device_state);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, device_state);
+   "suspended state\n", pdev,
+   pm8001_ha->name);
return 0;
 }
 
 /**
  * pm8001_pci_resume - power management resume main entry point
- * @pdev: PCI device struct
+ * @dev: Device struct
  *
  * Returns 0 success, anything else error.
  */
-static int pm8001_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused pm8001_pci_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct pm8001_hba_info *pm8001_ha;
int rc;
@@ -1326,16 +1321,6 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
"operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   rc = pci_enable_device(pdev);
-   if (rc) {
-   pm8001_printk("slot=%s Enable device failed during resume\n",
- pm8001_ha->name);
-   goto err_out_enable;
-   }
-
-   pci_set_master(pdev);
rc = pci_go_44(pdev);
if (rc)
goto err_out_disable;
@@ -1396,8 +1381,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
 
 err_out_disable:
scsi_remove_host(pm8001_ha->shost);
-   pci_disable_device(pdev);
-err_out_enable:
+
return rc;
 }
 
@@ -1480,13 +1464,16 @@ static struct pci_device_id pm8001_pci_table[] = {
{} /* terminate list */
 };
 
+static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
+pm8001_pci_suspend,
+pm8001_pci_resume);
+
 static struct pci_driver pm8001_pci_driver = {
.name   = DRV_NAME,
.id_table   = pm8001_pci_table,
.probe  = pm8001_pci_probe,
.remove = pm8001_pci_remove,
-   .suspend= pm8001_pci_suspend,
-   .resume = pm8001_pci_resume,
+   .driver.pm  = _pci_pm_ops,
 };
 
 /**
-- 
2.28.0



[PATCH v4 18/29] scsi: pm_8001: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in pm8001_pci_resume(), and
there is no corresponding pci_enable_wake(, true) in
pm8001_pci_suspend(). Either it should do enable-wake the device in
.suspend() or should not invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
pm8001_pci__resume().

Signed-off-by: Vaibhav Gupta 
Acked-by: Jack Wang 
---
 drivers/scsi/pm8001/pm8001_init.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index 3cf3e58b6979..d47ed9a33173 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1327,7 +1327,6 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
"operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
rc = pci_enable_device(pdev);
if (rc) {
-- 
2.28.0



[PATCH v4 16/29] scsi: mpt3sas_scsih: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 34 +++-
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 2d201558b8fb..bc68544856b9 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -11084,20 +11084,18 @@ _scsih_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
return rv;
 }
 
-#ifdef CONFIG_PM
 /**
  * scsih_suspend - power management suspend main entry point
- * @pdev: PCI device struct
- * @state: PM state change to (usually PCI_D3)
+ * @dev: Device struct
  *
  * Return: 0 success, anything else error.
  */
-static int
-scsih_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused
+scsih_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost;
struct MPT3SAS_ADAPTER *ioc;
-   pci_power_t device_state;
int rc;
 
rc = _scsih_get_shost_and_ioc(pdev, , );
@@ -11108,25 +11106,23 @@ scsih_suspend(struct pci_dev *pdev, pm_message_t 
state)
flush_scheduled_work();
scsi_block_requests(shost);
_scsih_nvme_shutdown(ioc);
-   device_state = pci_choose_state(pdev, state);
-   ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
-pdev, pci_name(pdev), device_state);
+   ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state\n",
+pdev, pci_name(pdev));
 
-   pci_save_state(pdev);
mpt3sas_base_free_resources(ioc);
-   pci_set_power_state(pdev, device_state);
return 0;
 }
 
 /**
  * scsih_resume - power management resume main entry point
- * @pdev: PCI device struct
+ * @dev: Device struct
  *
  * Return: 0 success, anything else error.
  */
-static int
-scsih_resume(struct pci_dev *pdev)
+static int __maybe_unused
+scsih_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost;
struct MPT3SAS_ADAPTER *ioc;
pci_power_t device_state = pdev->current_state;
@@ -11139,8 +11135,6 @@ scsih_resume(struct pci_dev *pdev)
ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
 pdev, pci_name(pdev), device_state);
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
ioc->pdev = pdev;
r = mpt3sas_base_map_resources(ioc);
if (r)
@@ -11151,7 +11145,6 @@ scsih_resume(struct pci_dev *pdev)
mpt3sas_base_start_watchdog(ioc);
return 0;
 }
-#endif /* CONFIG_PM */
 
 /**
  * scsih_pci_error_detected - Called when a PCI error is detected.
@@ -11453,6 +11446,8 @@ static struct pci_error_handlers _mpt3sas_err_handler = 
{
.resume = scsih_pci_resume,
 };
 
+static SIMPLE_DEV_PM_OPS(scsih_pm_ops, scsih_suspend, scsih_resume);
+
 static struct pci_driver mpt3sas_driver = {
.name   = MPT3SAS_DRIVER_NAME,
.id_table   = mpt3sas_pci_table,
@@ -11460,10 +11455,7 @@ static struct pci_driver mpt3sas_driver = {
.remove = scsih_remove,
.shutdown   = scsih_shutdown,
.err_handler= &_mpt3sas_err_handler,
-#ifdef CONFIG_PM
-   .suspend= scsih_suspend,
-   .resume = scsih_resume,
-#endif
+   .driver.pm  = _pm_ops,
 };
 
 /**
-- 
2.28.0



[PATCH v4 12/29] scsi: hisi_sas_v3_hw: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in hisi_sas_v3_resume(), and
there is no corresponding pci_enable_wake(, true) in
hisi_sas_v3_suspend(). Either it should do enable-wake the device in
.suspend() or should not invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
hisi_sas_v3_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 7133ca859b5e..f19f3db1ac6d 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3492,7 +3492,6 @@ static int _resume_v3_hw(struct device *device)
dev_warn(dev, "resuming from operating state [D%d]\n",
 device_state);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
rc = pci_enable_device(pdev);
if (rc) {
-- 
2.28.0



[PATCH v4 11/29] scsi: esas2r: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/esas2r/esas2r.h  |  5 ++--
 drivers/scsi/esas2r/esas2r_init.c | 44 +--
 drivers/scsi/esas2r/esas2r_main.c |  3 +--
 3 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index e30d2f1f5368..ed63f7a9ea54 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -996,8 +996,9 @@ void esas2r_adapter_tasklet(unsigned long context);
 irqreturn_t esas2r_interrupt(int irq, void *dev_id);
 irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id);
 void esas2r_kickoff_timer(struct esas2r_adapter *a);
-int esas2r_suspend(struct pci_dev *pcid, pm_message_t state);
-int esas2r_resume(struct pci_dev *pcid);
+
+extern const struct dev_pm_ops esas2r_pm_ops;
+
 void esas2r_fw_event_off(struct esas2r_adapter *a);
 void esas2r_fw_event_on(struct esas2r_adapter *a);
 bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 905a6c874789..eb7763af7089 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -640,49 +640,27 @@ void esas2r_kill_adapter(int i)
}
 }
 
-int esas2r_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused esas2r_suspend(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
-   u32 device_state;
+   struct Scsi_Host *host = dev_get_drvdata(dev);
struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
 
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "suspending adapter()");
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "suspending adapter()");
if (!a)
return -ENODEV;
 
esas2r_adapter_power_down(a, 1);
-   device_state = pci_choose_state(pdev, state);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_save_state() called");
-   pci_save_state(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_disable_device() called");
-   pci_disable_device(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_set_power_state() called");
-   pci_set_power_state(pdev, device_state);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "esas2r_suspend(): 0");
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "esas2r_suspend(): 0");
return 0;
 }
 
-int esas2r_resume(struct pci_dev *pdev)
+static int __maybe_unused esas2r_resume(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
+   struct Scsi_Host *host = dev_get_drvdata(dev);
struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
-   int rez;
-
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "resuming adapter()");
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_set_power_state(PCI_D0) "
-  "called");
-   pci_set_power_state(pdev, PCI_D0);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_restore_state() called");
-   pci_restore_state(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_enable_device() called");
-   rez = pci_enable_device(pdev);
-   pci_set_master(pdev);
+   int rez = 0;
+
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "resuming adapter()");
 
if (!a) {
rez = -ENODEV;
@@ -726,11 +704,13 @@ int esas2r_resume(struct pci_dev *pdev)
}
 
 error_exit:
-   esas2r_log_dev(ESAS2R_LOG_CRIT, &(pdev->dev), "esas2r_resume(): %d",
+   esas2r_log_dev(ESAS2R_LOG_CRIT, dev, "esas2r_resume(): %d",
   rez);
return rez;
 }
 
+SIMPLE_DEV_PM_OPS(esas2r_pm_ops, esas2r_suspend, esas2r_resume);
+
 bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str)
 {
set_bit(AF_DEGRADED_MODE, >flags);
diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index 7b49e2e9fcde..aab3ea580e6b 100644
--- a/drivers/scsi/esas

[PATCH v4 15/29] scsi: mpt3sas_scsih: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in scsih_resume(), and
there is no corresponding pci_enable_wake(, true) in scsih_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
scsih_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 5f845d7094fc..2d201558b8fb 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -11140,7 +11140,6 @@ scsih_resume(struct pci_dev *pdev)
 pdev, pci_name(pdev), device_state);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
ioc->pdev = pdev;
r = mpt3sas_base_map_resources(ioc);
-- 
2.28.0



[PATCH v4 13/29] scsi: hisi_sas_v3_hw: Don't use PCI helper functions

2020-11-02 Thread Vaibhav Gupta
Drivers using new-framework/generic-framework should not handle standard
power management operations. These operations were performed by legacy
framework through PCI helper functions like pci_save/restore_state(),
pci_set_power_state(), etc.

Drivers should not use them now.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 17 +
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index f19f3db1ac6d..dfeb86c865d3 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3440,7 +3440,6 @@ static int _suspend_v3_hw(struct device *device)
struct hisi_hba *hisi_hba = sha->lldd_ha;
struct device *dev = hisi_hba->dev;
struct Scsi_Host *shost = hisi_hba->shost;
-   pci_power_t device_state;
int rc;
 
if (!pdev->pm_cap) {
@@ -3466,12 +3465,7 @@ static int _suspend_v3_hw(struct device *device)
 
hisi_sas_init_mem(hisi_hba);
 
-   device_state = pci_choose_state(pdev, PMSG_SUSPEND);
-   dev_warn(dev, "entering operating state [D%d]\n",
-   device_state);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, device_state);
+   dev_warn(dev, "entering suspend state\n");
 
hisi_sas_release_tasks(hisi_hba);
 
@@ -3491,15 +3485,7 @@ static int _resume_v3_hw(struct device *device)
 
dev_warn(dev, "resuming from operating state [D%d]\n",
 device_state);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   rc = pci_enable_device(pdev);
-   if (rc) {
-   dev_err(dev, "enable device failed during resume (%d)\n", rc);
-   return rc;
-   }
 
-   pci_set_master(pdev);
scsi_unblock_requests(shost);
clear_bit(HISI_SAS_REJECT_CMD_BIT, _hba->flags);
 
@@ -3507,7 +3493,6 @@ static int _resume_v3_hw(struct device *device)
rc = hw_init_v3_hw(hisi_hba);
if (rc) {
scsi_remove_host(shost);
-   pci_disable_device(pdev);
return rc;
}
hisi_hba->hw->phys_init(hisi_hba);
-- 
2.28.0



[PATCH v4 14/29] scsi: hisi_sas_v3_hw: Remove extra function calls for runtime pm

2020-11-02 Thread Vaibhav Gupta
Both runtime_suspend_v3_hw() and runtime_resume_v3_hw() do nothing else but
invoke suspend_v3_hw() and resume_v3_hw() respectively. This is the case of
unnecessary function calls. To use those functions for runtime pm as well,
simply use UNIVERSAL_DEV_PM_OPS.

make -j$(nproc) W=1, with CONFIG_PM disabled, throws '-Wunused-function'
warning for runtime_suspend_v3_hw() and runtime_resume_v3_hw(). After
dropping those function definitions, the warning was thrown for
suspend_v3_hw() and resume_v3_hw(). Hence, mark them as '__maybe_unused'.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index dfeb86c865d3..9f0b4fe564cc 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3502,7 +3502,7 @@ static int _resume_v3_hw(struct device *device)
return 0;
 }
 
-static int suspend_v3_hw(struct device *device)
+static int __maybe_unused suspend_v3_hw(struct device *device)
 {
struct pci_dev *pdev = to_pci_dev(device);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
@@ -3518,7 +3518,7 @@ static int suspend_v3_hw(struct device *device)
return rc;
 }
 
-static int resume_v3_hw(struct device *device)
+static int __maybe_unused resume_v3_hw(struct device *device)
 {
struct pci_dev *pdev = to_pci_dev(device);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
@@ -3541,21 +3541,10 @@ static const struct pci_error_handlers 
hisi_sas_err_handler = {
.reset_done = hisi_sas_reset_done_v3_hw,
 };
 
-static int runtime_suspend_v3_hw(struct device *dev)
-{
-   return suspend_v3_hw(dev);
-}
-
-static int runtime_resume_v3_hw(struct device *dev)
-{
-   return resume_v3_hw(dev);
-}
-
-static const struct dev_pm_ops hisi_sas_v3_pm_ops = {
-   SET_SYSTEM_SLEEP_PM_OPS(suspend_v3_hw, resume_v3_hw)
-   SET_RUNTIME_PM_OPS(runtime_suspend_v3_hw,
-  runtime_resume_v3_hw, NULL)
-};
+static UNIVERSAL_DEV_PM_OPS(hisi_sas_v3_pm_ops,
+   suspend_v3_hw,
+   resume_v3_hw,
+   NULL);
 
 static struct pci_driver sas_v3_pci_driver = {
.name   = DRV_NAME,
-- 
2.28.0



[PATCH v4 09/29] scsi: arcmsr: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 28 +---
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index c7ba4cbd197b..907f5af3bbd4 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -113,8 +113,8 @@ static int arcmsr_bios_param(struct scsi_device *sdev,
 static int arcmsr_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
 static int arcmsr_probe(struct pci_dev *pdev,
const struct pci_device_id *id);
-static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state);
-static int arcmsr_resume(struct pci_dev *pdev);
+static int __maybe_unused arcmsr_suspend(struct device *dev);
+static int __maybe_unused arcmsr_resume(struct device *dev);
 static void arcmsr_remove(struct pci_dev *pdev);
 static void arcmsr_shutdown(struct pci_dev *pdev);
 static void arcmsr_iop_init(struct AdapterControlBlock *acb);
@@ -216,13 +216,14 @@ static struct pci_device_id arcmsr_device_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, arcmsr_device_id_table);
 
+static SIMPLE_DEV_PM_OPS(arcmsr_pm_ops, arcmsr_suspend, arcmsr_resume);
+
 static struct pci_driver arcmsr_pci_driver = {
.name   = "arcmsr",
.id_table   = arcmsr_device_id_table,
.probe  = arcmsr_probe,
.remove = arcmsr_remove,
-   .suspend= arcmsr_suspend,
-   .resume = arcmsr_resume,
+   .driver.pm  = _pm_ops,
.shutdown   = arcmsr_shutdown,
 };
 /*
@@ -1126,8 +1127,9 @@ static void arcmsr_free_irq(struct pci_dev *pdev,
pci_free_irq_vectors(pdev);
 }
 
-static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused arcmsr_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *)host->hostdata;
@@ -1140,28 +1142,18 @@ static int arcmsr_suspend(struct pci_dev *pdev, 
pm_message_t state)
flush_work(>arcmsr_do_message_isr_bh);
arcmsr_stop_adapter_bgrb(acb);
arcmsr_flush_adapter_cache(acb);
-   pci_set_drvdata(pdev, host);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
return 0;
 }
 
-static int arcmsr_resume(struct pci_dev *pdev)
+static int __maybe_unused arcmsr_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *)host->hostdata;
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   if (pci_enable_device(pdev)) {
-   pr_warn("%s: pci_enable_device error\n", __func__);
-   return -ENODEV;
-   }
if (arcmsr_set_dma_mask(acb))
goto controller_unregister;
-   pci_set_master(pdev);
if (arcmsr_request_irq(pdev, acb) == FAILED)
goto controller_stop;
switch (acb->adapter_type) {
@@ -1206,9 +1198,7 @@ static int arcmsr_resume(struct pci_dev *pdev)
if (acb->adapter_type == ACB_ADAPTER_TYPE_F)
arcmsr_free_io_queue(acb);
arcmsr_unmap_pciregion(acb);
-   pci_release_regions(pdev);
scsi_host_put(host);
-   pci_disable_device(pdev);
return -ENODEV;
 }
 
-- 
2.28.0



[PATCH v4 08/29] scsi: arcmsr: Drop PCI wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in arcmsr_resume(), and
there is no corresponding pci_enable_wake(, true) in arcmsr_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
arcmsr_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index e4fdb473b990..c7ba4cbd197b 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1154,7 +1154,6 @@ static int arcmsr_resume(struct pci_dev *pdev)
(struct AdapterControlBlock *)host->hostdata;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
if (pci_enable_device(pdev)) {
pr_warn("%s: pci_enable_device error\n", __func__);
-- 
2.28.0



[PATCH v4 07/29] scsi: aic79xx: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aic7xxx/aic79xx.h | 12 +++
 drivers/scsi/aic7xxx/aic79xx_core.c|  8 ++---
 drivers/scsi/aic7xxx/aic79xx_osm_pci.c | 43 +++---
 drivers/scsi/aic7xxx/aic79xx_pci.c |  6 ++--
 4 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index 9a515551641c..dd5dfd4f30a5 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1330,10 +1330,8 @@ const struct ahd_pci_identity 
*ahd_find_pci_device(ahd_dev_softc_t);
 int  ahd_pci_config(struct ahd_softc *,
 const struct ahd_pci_identity *);
 intahd_pci_test_register_access(struct ahd_softc *);
-#ifdef CONFIG_PM
-void   ahd_pci_suspend(struct ahd_softc *);
-void   ahd_pci_resume(struct ahd_softc *);
-#endif
+void __maybe_unusedahd_pci_suspend(struct ahd_softc *);
+void __maybe_unusedahd_pci_resume(struct ahd_softc *);
 
 /** SCB and SCB queue management 
**/
 void   ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
@@ -1344,10 +1342,8 @@ struct ahd_softc *ahd_alloc(void *platform_arg, char 
*name);
 int ahd_softc_init(struct ahd_softc *);
 voidahd_controller_info(struct ahd_softc *ahd, char *buf);
 int ahd_init(struct ahd_softc *ahd);
-#ifdef CONFIG_PM
-int ahd_suspend(struct ahd_softc *ahd);
-voidahd_resume(struct ahd_softc *ahd);
-#endif
+int __maybe_unused  ahd_suspend(struct ahd_softc *ahd);
+void __maybe_unused ahd_resume(struct ahd_softc *ahd);
 int ahd_default_config(struct ahd_softc *ahd);
 int ahd_parse_vpddata(struct ahd_softc *ahd,
   struct vpd_config *vpd);
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
b/drivers/scsi/aic7xxx/aic79xx_core.c
index 98b02e7d38bb..78560a85b1e3 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -7866,11 +7866,9 @@ ahd_pause_and_flushwork(struct ahd_softc *ahd)
ahd->flags &= ~AHD_ALL_INTERRUPTS;
 }
 
-#ifdef CONFIG_PM
-int
+int __maybe_unused
 ahd_suspend(struct ahd_softc *ahd)
 {
-
ahd_pause_and_flushwork(ahd);
 
if (LIST_FIRST(>pending_scbs) != NULL) {
@@ -7881,15 +7879,13 @@ ahd_suspend(struct ahd_softc *ahd)
return (0);
 }
 
-void
+void __maybe_unused
 ahd_resume(struct ahd_softc *ahd)
 {
-
ahd_reset(ahd, /*reinit*/TRUE);
ahd_intr_enable(ahd, TRUE); 
ahd_restart(ahd);
 }
-#endif
 
 /** Busy Target Table 
*/
 /*
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c 
b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index 8b891a05d9e7..07b670b80f1b 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -74,11 +74,10 @@ static const struct pci_device_id ahd_linux_pci_id_table[] 
= {
 
 MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
 
-#ifdef CONFIG_PM
-static int
-ahd_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused
+ahd_linux_pci_dev_suspend(struct device *dev)
 {
-   struct ahd_softc *ahd = pci_get_drvdata(pdev);
+   struct ahd_softc *ahd = dev_get_drvdata(dev);
int rc;
 
if ((rc = ahd_suspend(ahd)))
@@ -86,39 +85,20 @@ ahd_linux_pci_dev_suspend(struct pci_dev *pdev, 
pm_message_t mesg)
 
ahd_pci_suspend(ahd);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   if (mesg.event & PM_EVENT_SLEEP)
-   pci_set_power_state(pdev, PCI_D3hot);
-
return rc;
 }
 
-static int
-ahd_linux_pci_dev_resume(struct pci_dev *pdev)
+static int __maybe_unused
+ahd_linux_pci_dev_resume(struct device *dev)
 {
-   struct ahd_softc *ahd = pci_get_drvdata(pdev);
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   if ((rc = pci_enable_device(pdev))) {
-   dev_printk(KERN_ERR, >dev,
-  "failed to enable device after resume (%d)\n", rc);
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   struct ahd_softc *ahd = dev_get_drvdata(dev);
 
ahd_

[PATCH v4 10/29] scsi: esas2r: Drop PCI Wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in esas2r_resume(), and
there is no corresponding pci_enable_wake(, true) in esas2r_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
esas2r_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/esas2r/esas2r_init.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 09c5c24bf391..905a6c874789 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -676,10 +676,6 @@ int esas2r_resume(struct pci_dev *pdev)
   "pci_set_power_state(PCI_D0) "
   "called");
pci_set_power_state(pdev, PCI_D0);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_enable_wake(PCI_D0, 0) "
-  "called");
-   pci_enable_wake(pdev, PCI_D0, 0);
esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
   "pci_restore_state() called");
pci_restore_state(pdev);
-- 
2.28.0



[PATCH v4 04/29] scsi: aacraid: Drop pci_enable_wake() from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in aac_resume(), and there is
no corresponding pci_enable_wake(, true) in aac_suspend(). Either it
should do enable-wake the device in .suspend() or should not invoke
pci_enable_wake() at all.

Concluding that this is a bug and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
aac_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aacraid/linit.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 8f3772480582..8c4dcb5ab329 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1938,7 +1938,6 @@ static int aac_resume(struct pci_dev *pdev)
int r;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
r = pci_enable_device(pdev);
 
-- 
2.28.0



[PATCH v4 06/29] scsi: aic7xxx: use generic power management

2020-11-02 Thread Vaibhav Gupta
use generic power management

Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aic7xxx/aic7xxx.h | 10 ++
 drivers/scsi/aic7xxx/aic7xxx_core.c|  6 ++--
 drivers/scsi/aic7xxx/aic7xxx_osm_pci.c | 46 ++
 drivers/scsi/aic7xxx/aic7xxx_pci.c |  4 +--
 4 files changed, 17 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index 88b90f9806c9..11a09798e6b5 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -1134,9 +1134,7 @@ const struct ahc_pci_identity 
*ahc_find_pci_device(ahc_dev_softc_t);
 int ahc_pci_config(struct ahc_softc *,
const struct ahc_pci_identity *);
 int ahc_pci_test_register_access(struct ahc_softc *);
-#ifdef CONFIG_PM
-voidahc_pci_resume(struct ahc_softc *ahc);
-#endif
+void __maybe_unused ahc_pci_resume(struct ahc_softc *ahc);
 
 /*** EISA/VL Front End 
/
 struct aic7770_identity *aic7770_find_device(uint32_t);
@@ -1160,10 +1158,8 @@ int   ahc_chip_init(struct ahc_softc 
*ahc);
 int ahc_init(struct ahc_softc *ahc);
 voidahc_intr_enable(struct ahc_softc *ahc, int enable);
 voidahc_pause_and_flushwork(struct ahc_softc *ahc);
-#ifdef CONFIG_PM
-int ahc_suspend(struct ahc_softc *ahc); 
-int ahc_resume(struct ahc_softc *ahc);
-#endif
+int __maybe_unused  ahc_suspend(struct ahc_softc *ahc);
+int __maybe_unused  ahc_resume(struct ahc_softc *ahc);
 voidahc_set_unit(struct ahc_softc *, int);
 voidahc_set_name(struct ahc_softc *, char *);
 voidahc_free(struct ahc_softc *ahc);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 725bb7f58054..4ef7af8c0f55 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -5590,8 +5590,7 @@ ahc_pause_and_flushwork(struct ahc_softc *ahc)
ahc->flags &= ~AHC_ALL_INTERRUPTS;
 }
 
-#ifdef CONFIG_PM
-int
+int __maybe_unused
 ahc_suspend(struct ahc_softc *ahc)
 {
 
@@ -5617,7 +5616,7 @@ ahc_suspend(struct ahc_softc *ahc)
return (0);
 }
 
-int
+int __maybe_unused
 ahc_resume(struct ahc_softc *ahc)
 {
 
@@ -5626,7 +5625,6 @@ ahc_resume(struct ahc_softc *ahc)
ahc_restart(ahc);
return (0);
 }
-#endif
 /** Busy Target Table 
*/
 /*
  * Return the untagged transaction id for a given target/channel lun.
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c 
b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index 9b293b1f0b71..a07e94fac673 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -121,47 +121,23 @@ static const struct pci_device_id 
ahc_linux_pci_id_table[] = {
 
 MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
 
-#ifdef CONFIG_PM
-static int
-ahc_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused
+ahc_linux_pci_dev_suspend(struct device *dev)
 {
-   struct ahc_softc *ahc = pci_get_drvdata(pdev);
-   int rc;
-
-   if ((rc = ahc_suspend(ahc)))
-   return rc;
+   struct ahc_softc *ahc = dev_get_drvdata(dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   if (mesg.event & PM_EVENT_SLEEP)
-   pci_set_power_state(pdev, PCI_D3hot);
-
-   return rc;
+   return ahc_suspend(ahc);
 }
 
-static int
-ahc_linux_pci_dev_resume(struct pci_dev *pdev)
+static int __maybe_unused
+ahc_linux_pci_dev_resume(struct device *dev)
 {
-   struct ahc_softc *ahc = pci_get_drvdata(pdev);
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   if ((rc = pci_enable_device(pdev))) {
-   dev_printk(KERN_ERR, >dev,
-  "failed to enable device after resume (%d)\n", rc);
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   struct ahc_softc *ahc = dev_get_drvdata(dev);
 
ahc_pci_resume(ahc);
 
return (ahc_resume(ahc));
 }
-#endif
 
 static void
 ahc_linux_pci_dev_remove(struct pci_dev *pdev)
@@ -

[PATCH v4 05/29] scsi: aacraid: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
Acked-by: Balsundar P 
---
 drivers/scsi/aacraid/linit.c | 33 +++--
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 8c4dcb5ab329..5177d387854a 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1910,11 +1910,9 @@ static int aac_acquire_resources(struct aac_dev *dev)
 
 }
 
-#if (defined(CONFIG_PM))
-static int aac_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused aac_suspend(struct device *dev)
 {
-
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev);
struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
 
scsi_host_block(shost);
@@ -1923,28 +1921,14 @@ static int aac_suspend(struct pci_dev *pdev, 
pm_message_t state)
 
aac_release_resources(aac);
 
-   pci_set_drvdata(pdev, shost);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 }
 
-static int aac_resume(struct pci_dev *pdev)
+static int __maybe_unused aac_resume(struct device *dev)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev);
struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
-   int r;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   r = pci_enable_device(pdev);
-
-   if (r)
-   goto fail_device;
 
-   pci_set_master(pdev);
if (aac_acquire_resources(aac))
goto fail_device;
/*
@@ -1959,10 +1943,8 @@ static int aac_resume(struct pci_dev *pdev)
 fail_device:
printk(KERN_INFO "%s%d: resume failed.\n", aac->name, aac->id);
scsi_host_put(shost);
-   pci_disable_device(pdev);
return -ENODEV;
 }
-#endif
 
 static void aac_shutdown(struct pci_dev *dev)
 {
@@ -2107,15 +2089,14 @@ static struct pci_error_handlers aac_pci_err_handler = {
.resume = aac_pci_resume,
 };
 
+static SIMPLE_DEV_PM_OPS(aac_pm_ops, aac_suspend, aac_resume);
+
 static struct pci_driver aac_pci_driver = {
.name   = AAC_DRIVERNAME,
.id_table   = aac_pci_tbl,
.probe  = aac_probe_one,
.remove = aac_remove_one,
-#if (defined(CONFIG_PM))
-   .suspend= aac_suspend,
-   .resume = aac_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = aac_shutdown,
.err_handler= _pci_err_handler,
 };
-- 
2.28.0



[PATCH v4 03/29] scsi: megaraid_sas: update function description

2020-11-02 Thread Vaibhav Gupta
Function parameter 'pdev 'is described as Generic Device Structure. It is
a PCI device structure.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index bd330ea4063a..7384c8e9149d 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7958,7 +7958,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
 
 /**
  * megasas_shutdown -  Shutdown entry point
- * @pdev:  Generic device structure
+ * @pdev:  PCI device structure
  */
 static void megasas_shutdown(struct pci_dev *pdev)
 {
-- 
2.28.0



[PATCH v4 02/29] scsi: megaraid_sas: use generic power management

2020-11-02 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 51 ++-
 1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 47ffdada541d..bd330ea4063a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7593,25 +7593,23 @@ static void megasas_shutdown_controller(struct 
megasas_instance *instance,
megasas_return_cmd(instance, cmd);
 }
 
-#ifdef CONFIG_PM
 /**
  * megasas_suspend -   driver suspend entry point
- * @pdev:  PCI device structure
- * @state: PCI power state to suspend routine
+ * @dev:   Device structure
  */
-static int
-megasas_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused
+megasas_suspend(struct device *dev)
 {
struct megasas_instance *instance;
 
-   instance = pci_get_drvdata(pdev);
+   instance = dev_get_drvdata(dev);
 
if (!instance)
return 0;
 
instance->unload = 1;
 
-   dev_info(>dev, "%s is called\n", __func__);
+   dev_info(dev, "%s is called\n", __func__);
 
/* Shutdown SR-IOV heartbeat timer */
if (instance->requestorId && !instance->skip_heartbeat_timer_del)
@@ -7641,47 +7639,29 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
state)
if (instance->msix_vectors)
pci_free_irq_vectors(instance->pdev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 }
 
 /**
  * megasas_resume-  driver resume entry point
- * @pdev:   PCI device structure
+ * @dev:   Device structure
  */
-static int
-megasas_resume(struct pci_dev *pdev)
+static int __maybe_unused
+megasas_resume(struct device *dev)
 {
int rval;
struct Scsi_Host *host;
struct megasas_instance *instance;
u32 status_reg;
 
-   instance = pci_get_drvdata(pdev);
+   instance = dev_get_drvdata(dev);
 
if (!instance)
return 0;
 
host = instance->host;
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   dev_info(>dev, "%s is called\n", __func__);
-   /*
-* PCI prepping: enable device set bus mastering and dma mask
-*/
-   rval = pci_enable_device_mem(pdev);
 
-   if (rval) {
-   dev_err(>dev, "Enable device failed\n");
-   return rval;
-   }
-
-   pci_set_master(pdev);
+   dev_info(dev, "%s is called\n", __func__);
 
/*
 * We expect the FW state to be READY
@@ -7807,14 +7787,8 @@ megasas_resume(struct pci_dev *pdev)
 fail_set_dma_mask:
 fail_ready_state:
 
-   pci_disable_device(pdev);
-
return -ENODEV;
 }
-#else
-#define megasas_suspendNULL
-#define megasas_resume NULL
-#endif
 
 static inline int
 megasas_wait_for_adapter_operational(struct megasas_instance *instance)
@@ -8572,6 +8546,8 @@ static const struct file_operations megasas_mgmt_fops = {
.llseek = noop_llseek,
 };
 
+static SIMPLE_DEV_PM_OPS(megasas_pm_ops, megasas_suspend, megasas_resume);
+
 /*
  * PCI hotplug support registration structure
  */
@@ -8581,8 +8557,7 @@ static struct pci_driver megasas_pci_driver = {
.id_table = megasas_pci_table,
.probe = megasas_probe_one,
.remove = megasas_detach_one,
-   .suspend = megasas_suspend,
-   .resume = megasas_resume,
+   .driver.pm = _pm_ops,
.shutdown = megasas_shutdown,
 };
 
-- 
2.28.0



[PATCH v4 01/29] scsi: megaraid_sas: Drop PCI wakeup calls from .resume

2020-11-02 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in megasas_resume(), and
there is no corresponding pci_enable_wake(, true) in megasas_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
megasas_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 41cd66fc7d81..47ffdada541d 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7668,7 +7668,6 @@ megasas_resume(struct pci_dev *pdev)
 
host = instance->host;
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
dev_info(>dev, "%s is called\n", __func__);
-- 
2.28.0



[PATCH v4 00/29] scsi: use generic power management

2020-11-02 Thread Vaibhav Gupta
Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to upgrade power management in 
drivers. This has been done by upgrading .suspend() and .resume() callbacks.

The upgrade makes sure that the involvement of PCI Core does not change the
order of operations executed in a driver. Thus, does not change its behavior.

In general, drivers with legacy PM, .suspend() and .resume() make use of PCI
helper functions like pci_enable/disable_device_mem(), pci_set_power_state(),
pci_save/restore_state(), pci_enable/disable_device(), etc. to complete
their job.

The conversion requires the removal of those function calls, change the
callbacks' definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

Test tools:
- Compiler: gcc (GCC) 10.2.0
- allmodconfig build: make -j$(nproc) W=1 all

Vaibhav Gupta (29):
  scsi: megaraid_sas: Drop PCI wakeup calls from .resume
  scsi: megaraid_sas: use generic power management
  scsi: megaraid_sas: update function description
  scsi: aacraid: Drop pci_enable_wake() from .resume
  scsi: aacraid: use generic power management
  scsi: aic7xxx: use generic power management
  scsi: aic79xx: use generic power management
  scsi: arcmsr: Drop PCI wakeup calls from .resume
  scsi: arcmsr: use generic power management
  scsi: esas2r: Drop PCI Wakeup calls from .resume
  scsi: esas2r: use generic power management
  scsi: hisi_sas_v3_hw: Drop PCI Wakeup calls from .resume
  scsi: hisi_sas_v3_hw: Don't use PCI helper functions
  scsi: hisi_sas_v3_hw: Remove extra function calls for runtime pm
  scsi: mpt3sas_scsih: Drop PCI Wakeup calls from .resume
  scsi: mpt3sas_scsih: use generic power management
  scsi: lpfc: use generic power management
  scsi: pm_8001: Drop PCI Wakeup calls from .resume
  scsi: pm_8001: use generic power management
  scsi: hpsa: use generic power management
  scsi: 3w-9xxx: Drop PCI Wakeup calls from .resume
  scsi: 3w-9xxx: use generic power management
  scsi: 3w-sas: Drop PCI Wakeup calls from .resume
  scsi: 3w-sas: use generic power management
  scsi: mvumi: Drop PCI Wakeup calls from .resume
  scsi: mvumi: use generic power management
  scsi: mvumi: update function description
  scsi: pmcraid: Drop PCI Wakeup calls from .resume
  scsi: pmcraid: use generic power management

 drivers/scsi/3w-9xxx.c|  30 ++-
 drivers/scsi/3w-sas.c |  32 ++-
 drivers/scsi/aacraid/linit.c  |  34 ++--
 drivers/scsi/aic7xxx/aic79xx.h|  12 +--
 drivers/scsi/aic7xxx/aic79xx_core.c   |   8 +-
 drivers/scsi/aic7xxx/aic79xx_osm_pci.c|  43 +++---
 drivers/scsi/aic7xxx/aic79xx_pci.c|   6 +-
 drivers/scsi/aic7xxx/aic7xxx.h|  10 +--
 drivers/scsi/aic7xxx/aic7xxx_core.c   |   6 +-
 drivers/scsi/aic7xxx/aic7xxx_osm_pci.c|  46 +++---
 drivers/scsi/aic7xxx/aic7xxx_pci.c|   4 +-
 drivers/scsi/arcmsr/arcmsr_hba.c  |  29 ++-
 drivers/scsi/esas2r/esas2r.h  |   5 +-
 drivers/scsi/esas2r/esas2r_init.c |  48 +++
 drivers/scsi/esas2r/esas2r_main.c |   3 +-
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c|  41 ++---
 drivers/scsi/hpsa.c   |  12 +--
 drivers/scsi/lpfc/lpfc_init.c | 100 +++---
 drivers/scsi/megaraid/megaraid_sas_base.c |  54 +++-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  35 +++-
 drivers/scsi/mvumi.c  |  49 +++
 drivers/scsi/pm8001/pm8001_init.c |  46 --
 drivers/scsi/pmcraid.c|  44 +++---
 23 files changed, 193 insertions(+), 504 deletions(-)

-- 
2.28.0



Re: [PATCH v3 00/28] scsi: use generic power management

2020-10-01 Thread Vaibhav Gupta
On Thu, Oct 01, 2020 at 05:54:43PM +0530, Vaibhav Gupta wrote:
Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to upgrade power management in SCSI
drivers. This has been done by upgrading .suspend() and .resume() callbacks.

The upgrade makes sure that the involvement of PCI Core does not change the
order of operations executed in a driver. Thus, does not change its behavior.

In general, drivers with legacy PM, .suspend() and .resume() make use of PCI
helper functions like pci_enable/disable_device_mem(), pci_set_power_state(),
pci_save/restore_state(), pci_enable/disable_device(), etc. to complete
their job.

The conversion requires the removal of those function calls, change the
callbacks' definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

v3: break down the patches to drop PCI wakeup calls.

Test tools:
- Compiler: gcc (GCC) 10.2.0
- allmodconfig build: make -j$(nproc) W=1 all

Vaibhav Gupta (28):
  scsi: megaraid_sas: Drop PCI wakeup calls from .resume
  scsi: megaraid_sas: use generic power management
  scsi: megaraid_sas: update function description
  scsi: aacraid: Drop pci_enable_wake() from .resume
  scsi: aacraid: use generic power management
  scsi: aic7xxx: use generic power management
  scsi: aic79xx: use generic power management
  scsi: arcmsr: Drop PCI wakeup calls from .resume
  scsi: arcmsr: use generic power management
  scsi: esas2r: Drop PCI Wakeup calls from .resume
  scsi: esas2r: use generic power management
  scsi: hisi_sas_v3_hw: Drop PCI Wakeup calls from .resume
  scsi: hisi_sas_v3_hw: use generic power management
  scsi: mpt3sas_scsih: Drop PCI Wakeup calls from .resume
  scsi: mpt3sas_scsih: use generic power management
  scsi: lpfc: use generic power management
  scsi: pm_8001:  Drop PCI Wakeup calls from .resume
  scsi: pm_8001: use generic power management
  scsi: hpsa: use generic power management
  scsi: 3w-9xxx: Drop PCI Wakeup calls from .resume
  scsi: 3w-9xxx: use generic power management
  scsi: 3w-sas: Drop PCI Wakeup calls from .resume
  scsi: 3w-sas: use generic power management
  scsi: mvumi: Drop PCI Wakeup calls from .resume
  scsi: mvumi: use generic power management
  scsi: mvumi: update function description
  scsi: pmcraid: Drop PCI Wakeup calls from .resume
  scsi: pmcraid: use generic power management

 drivers/scsi/3w-9xxx.c|  30 ++-
 drivers/scsi/3w-sas.c |  32 ++-
 drivers/scsi/aacraid/linit.c  |  34 ++--
 drivers/scsi/aic7xxx/aic79xx.h|  12 +--
 drivers/scsi/aic7xxx/aic79xx_core.c   |   8 +-
 drivers/scsi/aic7xxx/aic79xx_osm_pci.c|  43 +++---
 drivers/scsi/aic7xxx/aic79xx_pci.c|   6 +-
 drivers/scsi/aic7xxx/aic7xxx.h|  10 +--
 drivers/scsi/aic7xxx/aic7xxx_core.c   |   6 +-
 drivers/scsi/aic7xxx/aic7xxx_osm_pci.c|  46 +++---
 drivers/scsi/aic7xxx/aic7xxx_pci.c|   4 +-
 drivers/scsi/arcmsr/arcmsr_hba.c  |  33 +++
 drivers/scsi/esas2r/esas2r.h  |   5 +-
 drivers/scsi/esas2r/esas2r_init.c |  48 +++
 drivers/scsi/esas2r/esas2r_main.c |   3 +-
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c|  31 +++
 drivers/scsi/hpsa.c   |  12 +--
 drivers/scsi/lpfc/lpfc_init.c | 100 +++---
 drivers/scsi/megaraid/megaraid_sas_base.c |  54 +++-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  35 +++-
 drivers/scsi/mvumi.c  |  49 +++
 drivers/scsi/pm8001/pm8001_init.c |  46 --
 drivers/scsi/pmcraid.c|  44 +++---
 23 files changed, 198 insertions(+), 493 deletions(-)

-- 
2.28.0



[PATCH v3 25/28] scsi: mvumi: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 46 +---
 1 file changed, 9 insertions(+), 37 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 6a25e6918e26..6c710585a628 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2567,46 +2567,26 @@ static void mvumi_shutdown(struct pci_dev *pdev)
mvumi_flush_cache(mhba);
 }
 
-static int __maybe_unused mvumi_suspend(struct pci_dev *pdev, pm_message_t 
state)
+static int __maybe_unused mvumi_suspend(struct device *dev)
 {
-   struct mvumi_hba *mhba = NULL;
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct mvumi_hba *mhba = pci_get_drvdata(pdev);
 
-   mhba = pci_get_drvdata(pdev);
mvumi_flush_cache(mhba);
 
-   pci_set_drvdata(pdev, mhba);
mhba->instancet->disable_intr(mhba);
-   free_irq(mhba->pdev->irq, mhba);
mvumi_unmap_pci_addr(pdev, mhba->base_addr);
-   pci_release_regions(pdev);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
return 0;
 }
 
-static int __maybe_unused mvumi_resume(struct pci_dev *pdev)
+static int __maybe_unused mvumi_resume(struct device *dev)
 {
int ret;
-   struct mvumi_hba *mhba = NULL;
-
-   mhba = pci_get_drvdata(pdev);
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   ret = pci_enable_device(pdev);
-   if (ret) {
-   dev_err(>dev, "enable device failed\n");
-   return ret;
-   }
+   struct pci_dev *pdev = to_pci_dev(dev);
+   struct mvumi_hba *mhba = pci_get_drvdata(pdev);
 
-   ret = mvumi_pci_set_master(pdev);
ret = dma_set_mask(>dev, DMA_BIT_MASK(32));
-   if (ret)
-   goto fail;
-   ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
if (ret)
goto fail;
ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
@@ -2626,12 +2606,6 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
goto unmap_pci_addr;
}
 
-   ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
-   "mvumi", mhba);
-   if (ret) {
-   dev_err(>dev, "failed to register IRQ\n");
-   goto unmap_pci_addr;
-   }
mhba->instancet->enable_intr(mhba);
 
return 0;
@@ -2641,11 +2615,12 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
 release_regions:
pci_release_regions(pdev);
 fail:
-   pci_disable_device(pdev);
 
return ret;
 }
 
+static SIMPLE_DEV_PM_OPS(mvumi_pm_ops, mvumi_suspend, mvumi_resume);
+
 static struct pci_driver mvumi_pci_driver = {
 
.name = MV_DRIVER_NAME,
@@ -2653,10 +2628,7 @@ static struct pci_driver mvumi_pci_driver = {
.probe = mvumi_probe_one,
.remove = mvumi_detach_one,
.shutdown = mvumi_shutdown,
-#ifdef CONFIG_PM
-   .suspend = mvumi_suspend,
-   .resume = mvumi_resume,
-#endif
+   .driver.pm = _pm_ops,
 };
 
 module_pci_driver(mvumi_pci_driver);
-- 
2.28.0



[PATCH v3 24/28] scsi: mvumi: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in mvumi_resume(), and
there is no corresponding pci_enable_wake(, true) in mvumi_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
mvumi_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 8906aceda4c4..6a25e6918e26 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2594,7 +2594,6 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
*pdev)
mhba = pci_get_drvdata(pdev);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
ret = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v3 26/28] scsi: mvumi: update function description

2020-10-01 Thread Vaibhav Gupta
There is no "device" parameter in mvumi_shutdown(). Instead there is
"pdev" which is not described.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mvumi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 6c710585a628..82dd7c37c14e 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2558,7 +2558,7 @@ static void mvumi_detach_one(struct pci_dev *pdev)
 
 /**
  * mvumi_shutdown -Shutdown entry point
- * @device:Generic device structure
+ * @pdev:  PCI device structure
  */
 static void mvumi_shutdown(struct pci_dev *pdev)
 {
-- 
2.28.0



[PATCH v3 28/28] scsi: pmcraid: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pmcraid.c | 43 ++
 1 file changed, 10 insertions(+), 33 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 7674b8481f35..bbf7fc8d5a2c 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5237,53 +5237,37 @@ static void pmcraid_remove(struct pci_dev *pdev)
return;
 }
 
-#ifdef CONFIG_PM
 /**
  * pmcraid_suspend - driver suspend entry point for power management
- * @pdev:   PCI device structure
- * @state:  PCI power state to suspend routine
+ * @dev:   Device structure
  *
  * Return Value - 0 always
  */
-static int pmcraid_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pmcraid_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
 
pmcraid_shutdown(pdev);
pmcraid_disable_interrupts(pinstance, ~0);
pmcraid_kill_tasklets(pinstance);
-   pci_set_drvdata(pinstance->pdev, pinstance);
pmcraid_unregister_interrupt_handler(pinstance);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
return 0;
 }
 
 /**
  * pmcraid_resume - driver resume entry point PCI power management
- * @pdev: PCI device structure
+ * @dev: Device structure
  *
  * Return Value - 0 in case of success. Error code in case of any failure
  */
-static int pmcraid_resume(struct pci_dev *pdev)
+static int __maybe_unused pmcraid_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
struct Scsi_Host *host = pinstance->host;
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   rc = pci_enable_device(pdev);
-
-   if (rc) {
-   dev_err(>dev, "resume: Enable device failed\n");
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   int rc = 0;
 
if (sizeof(dma_addr_t) == 4 ||
dma_set_mask(>dev, DMA_BIT_MASK(64)))
@@ -5336,18 +5320,10 @@ static int pmcraid_resume(struct pci_dev *pdev)
scsi_host_put(host);
 
 disable_device:
-   pci_disable_device(pdev);
 
return rc;
 }
 
-#else
-
-#define pmcraid_suspend NULL
-#define pmcraid_resume  NULL
-
-#endif /* CONFIG_PM */
-
 /**
  * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
  * completion of the ioa reset
@@ -5835,6 +5811,8 @@ static int pmcraid_probe(struct pci_dev *pdev,
return -ENODEV;
 }
 
+static SIMPLE_DEV_PM_OPS(pmcraid_pm_ops, pmcraid_suspend, pmcraid_resume);
+
 /*
  * PCI driver structure of pmcraid driver
  */
@@ -5843,8 +5821,7 @@ static struct pci_driver pmcraid_driver = {
.id_table = pmcraid_pci_table,
.probe = pmcraid_probe,
.remove = pmcraid_remove,
-   .suspend = pmcraid_suspend,
-   .resume = pmcraid_resume,
+   .driver.pm = _pm_ops,
.shutdown = pmcraid_shutdown
 };
 
-- 
2.28.0



[PATCH v3 27/28] scsi: pmcraid: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in pmcraid_resume(), and
there is no corresponding pci_enable_wake(, true) in pmcraid_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
pmcraid_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pmcraid.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index aa9ae2ae8579..7674b8481f35 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5274,7 +5274,6 @@ static int pmcraid_resume(struct pci_dev *pdev)
int rc;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
rc = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v3 22/28] scsi: 3w-sas: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in twl_resume(), and
there is no corresponding pci_enable_wake(, true) in twl_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
twl_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-sas.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index dda6fa857709..0b4888199699 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1795,7 +1795,6 @@ static int twl_resume(struct pci_dev *pdev)
 
printk(KERN_WARNING "3w-sas: Resuming host %d.\n", 
tw_dev->host->host_no);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
retval = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v3 23/28] scsi: 3w-sas: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-sas.c | 31 +++
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 0b4888199699..b8f1848ecef2 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -1756,11 +1756,10 @@ static void twl_remove(struct pci_dev *pdev)
twl_device_extension_count--;
 } /* End twl_remove() */
 
-#ifdef CONFIG_PM
 /* This function is called on PCI suspend */
-static int twl_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused twl_suspend(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
+   struct Scsi_Host *host = dev_get_drvdata(dev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-sas: Suspending host %d.\n", 
tw_dev->host->host_no);
@@ -1779,31 +1778,18 @@ static int twl_suspend(struct pci_dev *pdev, 
pm_message_t state)
/* Clear doorbell interrupt */
TWL_CLEAR_DB_INTERRUPT(tw_dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 } /* End twl_suspend() */
 
 /* This function is called on PCI resume */
-static int twl_resume(struct pci_dev *pdev)
+static int __maybe_unused twl_resume(struct device *dev)
 {
int retval = 0;
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-sas: Resuming host %d.\n", 
tw_dev->host->host_no);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   retval = pci_enable_device(pdev);
-   if (retval) {
-   TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed 
during resume");
-   return retval;
-   }
-
-   pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
@@ -1841,11 +1827,9 @@ static int twl_resume(struct pci_dev *pdev)
 
 out_disable_device:
scsi_remove_host(host);
-   pci_disable_device(pdev);
 
return retval;
 } /* End twl_resume() */
-#endif
 
 /* PCI Devices supported by this driver */
 static struct pci_device_id twl_pci_tbl[] = {
@@ -1854,16 +1838,15 @@ static struct pci_device_id twl_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, twl_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(twl_pm_ops, twl_suspend, twl_resume);
+
 /* pci_driver initializer */
 static struct pci_driver twl_driver = {
.name   = "3w-sas",
.id_table   = twl_pci_tbl,
.probe  = twl_probe,
.remove = twl_remove,
-#ifdef CONFIG_PM
-   .suspend= twl_suspend,
-   .resume = twl_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = twl_shutdown
 };
 
-- 
2.28.0



[PATCH v3 18/28] scsi: pm_8001: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pm8001/pm8001_init.c | 45 +++
 1 file changed, 16 insertions(+), 29 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index ee27ecb17560..62dc30a45ac4 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1178,23 +1178,21 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
 
 /**
  * pm8001_pci_suspend - power management suspend main entry point
- * @pdev: PCI device struct
- * @state: PM state change to (usually PCI_D3)
+ * @dev: Device struct
  *
  * Returns 0 success, anything else error.
  */
-static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pm8001_pci_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
-   struct pm8001_hba_info *pm8001_ha;
+   struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
int  i, j;
-   u32 device_state;
-   pm8001_ha = sha->lldd_ha;
sas_suspend_ha(sha);
flush_workqueue(pm8001_wq);
scsi_block_requests(pm8001_ha->shost);
if (!pdev->pm_cap) {
-   dev_err(>dev, " PCI PM not supported\n");
+   dev_err(dev, " PCI PM not supported\n");
return -ENODEV;
}
PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
@@ -1217,24 +1215,21 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
pm_message_t state)
for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
tasklet_kill(_ha->tasklet[j]);
 #endif
-   device_state = pci_choose_state(pdev, state);
pm8001_printk("pdev=0x%p, slot=%s, entering "
- "operating state [D%d]\n", pdev,
- pm8001_ha->name, device_state);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, device_state);
+   "suspended state\n", pdev,
+   pm8001_ha->name);
return 0;
 }
 
 /**
  * pm8001_pci_resume - power management resume main entry point
- * @pdev: PCI device struct
+ * @dev: Device struct
  *
  * Returns 0 success, anything else error.
  */
-static int pm8001_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused pm8001_pci_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct pm8001_hba_info *pm8001_ha;
int rc;
@@ -1247,16 +1242,6 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
"operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   rc = pci_enable_device(pdev);
-   if (rc) {
-   pm8001_printk("slot=%s Enable device failed during resume\n",
- pm8001_ha->name);
-   goto err_out_enable;
-   }
-
-   pci_set_master(pdev);
rc = pci_go_44(pdev);
if (rc)
goto err_out_disable;
@@ -1317,8 +1302,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
 
 err_out_disable:
scsi_remove_host(pm8001_ha->shost);
-   pci_disable_device(pdev);
-err_out_enable:
+
return rc;
 }
 
@@ -1401,13 +1385,16 @@ static struct pci_device_id pm8001_pci_table[] = {
{} /* terminate list */
 };
 
+static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
+pm8001_pci_suspend,
+pm8001_pci_resume);
+
 static struct pci_driver pm8001_pci_driver = {
.name   = DRV_NAME,
.id_table   = pm8001_pci_table,
.probe  = pm8001_pci_probe,
.remove = pm8001_pci_remove,
-   .suspend= pm8001_pci_suspend,
-   .resume = pm8001_pci_resume,
+   .driver.pm  = _pci_pm_ops,
 };
 
 /**
-- 
2.28.0



[PATCH v3 21/28] scsi: 3w-9xxx: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-9xxx.c | 29 +++--
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index e458e99ff161..b4718a1b2bd6 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -2191,10 +2191,10 @@ static void twa_remove(struct pci_dev *pdev)
twa_device_extension_count--;
 } /* End twa_remove() */
 
-#ifdef CONFIG_PM
 /* This function is called on PCI suspend */
-static int twa_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused twa_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
@@ -2214,31 +2214,19 @@ static int twa_suspend(struct pci_dev *pdev, 
pm_message_t state)
}
TW_CLEAR_ALL_INTERRUPTS(tw_dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 } /* End twa_suspend() */
 
 /* This function is called on PCI resume */
-static int twa_resume(struct pci_dev *pdev)
+static int __maybe_unused twa_resume(struct device *dev)
 {
int retval = 0;
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
 
printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", 
tw_dev->host->host_no);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
 
-   retval = pci_enable_device(pdev);
-   if (retval) {
-   TW_PRINTK(tw_dev->host, TW_DRIVER, 0x39, "Enable device failed 
during resume");
-   return retval;
-   }
-
-   pci_set_master(pdev);
pci_try_set_mwi(pdev);
 
retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
@@ -2276,11 +2264,9 @@ static int twa_resume(struct pci_dev *pdev)
 
 out_disable_device:
scsi_remove_host(host);
-   pci_disable_device(pdev);
 
return retval;
 } /* End twa_resume() */
-#endif
 
 /* PCI Devices supported by this driver */
 static struct pci_device_id twa_pci_tbl[] = {
@@ -2296,16 +2282,15 @@ static struct pci_device_id twa_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, twa_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(twa_pm_ops, twa_suspend, twa_resume);
+
 /* pci_driver initializer */
 static struct pci_driver twa_driver = {
.name   = "3w-9xxx",
.id_table   = twa_pci_tbl,
.probe  = twa_probe,
.remove = twa_remove,
-#ifdef CONFIG_PM
-   .suspend= twa_suspend,
-   .resume = twa_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = twa_shutdown
 };
 
-- 
2.28.0



[PATCH v3 20/28] scsi: 3w-9xxx: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in twa_resume(), and
there is no corresponding pci_enable_wake(, true) in twa_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
twa_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/3w-9xxx.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 3337b1e80412..e458e99ff161 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -2230,7 +2230,6 @@ static int twa_resume(struct pci_dev *pdev)
 
printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", 
tw_dev->host->host_no);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
retval = pci_enable_device(pdev);
-- 
2.28.0



[PATCH v3 19/28] scsi: hpsa: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hpsa.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 81d0414e2117..70bdd6fe91ee 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -9070,25 +9070,27 @@ static void hpsa_remove_one(struct pci_dev *pdev)
hpda_free_ctlr_info(h); /* init_one 1 */
 }
 
-static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev,
-   __attribute__((unused)) pm_message_t state)
+static int __maybe_unused hpsa_suspend(
+   __attribute__((unused)) struct device *dev)
 {
return -ENOSYS;
 }
 
-static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev)
+static int __maybe_unused hpsa_resume
+   (__attribute__((unused)) struct device *dev)
 {
return -ENOSYS;
 }
 
+static SIMPLE_DEV_PM_OPS(hpsa_pm_ops, hpsa_suspend, hpsa_resume);
+
 static struct pci_driver hpsa_pci_driver = {
.name = HPSA,
.probe = hpsa_init_one,
.remove = hpsa_remove_one,
.id_table = hpsa_pci_device_id, /* id_table */
.shutdown = hpsa_shutdown,
-   .suspend = hpsa_suspend,
-   .resume = hpsa_resume,
+   .driver.pm = _pm_ops,
 };
 
 /* Fill in bucket_map[], given nsgs (the max number of
-- 
2.28.0



[PATCH v3 14/28] scsi: mpt3sas_scsih: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in scsih_resume(), and
there is no corresponding pci_enable_wake(, true) in scsih_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
scsih_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 08fc4b381056..ce3dfe26691f 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -10876,7 +10876,6 @@ scsih_resume(struct pci_dev *pdev)
 pdev, pci_name(pdev), device_state);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
ioc->pdev = pdev;
r = mpt3sas_base_map_resources(ioc);
-- 
2.28.0



[PATCH v3 16/28] scsi: lpfc: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/lpfc/lpfc_init.c | 100 +++---
 1 file changed, 33 insertions(+), 67 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 6637f84a3d1b..a36309b48144 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -12452,8 +12452,7 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
 
 /**
  * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
- * @pdev: pointer to PCI device
- * @msg: power management message
+ * @dev_d: pointer to device
  *
  * This routine is to be called from the kernel's PCI subsystem to support
  * system Power Management (PM) to device with SLI-3 interface spec. When
@@ -12471,10 +12470,10 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
+static int __maybe_unused
+lpfc_pci_suspend_one_s3(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
@@ -12488,16 +12487,12 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
pm_message_t msg)
/* Disable interrupt from device */
lpfc_sli_disable_intr(phba);
 
-   /* Save device state to PCI config space */
-   pci_save_state(pdev);
-   pci_set_power_state(pdev, PCI_D3hot);
-
return 0;
 }
 
 /**
  * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
- * @pdev: pointer to PCI device
+ * @dev_d: pointer to device
  *
  * This routine is to be called from the kernel's PCI subsystem to support
  * system Power Management (PM) to device with SLI-3 interface spec. When PM
@@ -12514,10 +12509,10 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
pm_message_t msg)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_resume_one_s3(struct pci_dev *pdev)
+static int __maybe_unused
+lpfc_pci_resume_one_s3(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
uint32_t intr_mode;
int error;
@@ -12525,19 +12520,6 @@ lpfc_pci_resume_one_s3(struct pci_dev *pdev)
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
"0452 PCI device Power Management resume.\n");
 
-   /* Restore device state from PCI config space */
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   /*
-* As the new kernel behavior of pci_restore_state() API call clears
-* device saved_state flag, need to save the restored state again.
-*/
-   pci_save_state(pdev);
-
-   if (pdev->is_busmaster)
-   pci_set_master(pdev);
-
/* Startup the kernel thread for this host adapter. */
phba->worker_thread = kthread_run(lpfc_do_work, phba,
"lpfc_worker_%d", phba->brd_no);
@@ -13294,8 +13276,7 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
 
 /**
  * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
- * @pdev: pointer to PCI device
- * @msg: power management message
+ * @dev_d: pointer to device
  *
  * This routine is called from the kernel's PCI subsystem to support system
  * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
@@ -13313,10 +13294,10 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
  * 0 - driver suspended the device
  * Error otherwise
  **/
-static int
-lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
+static int __maybe_unused
+lpfc_pci_suspend_one_s4(struct device *dev_d)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev_d);
struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
 
lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
@@ -13331,16 +13312,12 @@ lpfc_pci_suspend_one_s4(struct pci_dev *pdev, 
pm_message_t msg)
lpfc_sli4_disable_intr(phba);
lpfc_sli4_queue_dest

[PATCH v3 17/28] scsi: pm_8001: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in pm8001_pci_resume(), and
there is no corresponding pci_enable_wake(, true) in
pm8001_pci_suspend(). Either it should do enable-wake the device in
.suspend() or should not invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
pm8001_pci__resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/pm8001/pm8001_init.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c 
b/drivers/scsi/pm8001/pm8001_init.c
index 9e99262a2b9d..ee27ecb17560 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1248,7 +1248,6 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
"operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
rc = pci_enable_device(pdev);
if (rc) {
-- 
2.28.0



[PATCH v3 13/28] scsi: hisi_sas_v3_hw: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 30 +-
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 8f0f4084a054..98b1848aabe7 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3374,13 +3374,13 @@ enum {
hip08,
 };
 
-static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused hisi_sas_v3_suspend(struct device *dev_d)
 {
+   struct pci_dev *pdev = to_pci_dev(dev_d);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct hisi_hba *hisi_hba = sha->lldd_ha;
struct device *dev = hisi_hba->dev;
struct Scsi_Host *shost = hisi_hba->shost;
-   pci_power_t device_state;
int rc;
 
if (!pdev->pm_cap) {
@@ -3406,12 +3406,7 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, 
pm_message_t state)
 
hisi_sas_init_mem(hisi_hba);
 
-   device_state = pci_choose_state(pdev, state);
-   dev_warn(dev, "entering operating state [D%d]\n",
-   device_state);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, device_state);
+   dev_warn(dev, "entering suspend state\n");
 
hisi_sas_release_tasks(hisi_hba);
 
@@ -3419,8 +3414,9 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, 
pm_message_t state)
return 0;
 }
 
-static int hisi_sas_v3_resume(struct pci_dev *pdev)
+static int __maybe_unused hisi_sas_v3_resume(struct device *dev_d)
 {
+   struct pci_dev *pdev = to_pci_dev(dev_d);
struct sas_ha_struct *sha = pci_get_drvdata(pdev);
struct hisi_hba *hisi_hba = sha->lldd_ha;
struct Scsi_Host *shost = hisi_hba->shost;
@@ -3430,15 +3426,7 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
 
dev_warn(dev, "resuming from operating state [D%d]\n",
 device_state);
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   rc = pci_enable_device(pdev);
-   if (rc) {
-   dev_err(dev, "enable device failed during resume (%d)\n", rc);
-   return rc;
-   }
 
-   pci_set_master(pdev);
scsi_unblock_requests(shost);
clear_bit(HISI_SAS_REJECT_CMD_BIT, _hba->flags);
 
@@ -3446,7 +3434,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
rc = hw_init_v3_hw(hisi_hba);
if (rc) {
scsi_remove_host(shost);
-   pci_disable_device(pdev);
return rc;
}
hisi_hba->hw->phys_init(hisi_hba);
@@ -3456,6 +3443,10 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
return 0;
 }
 
+static SIMPLE_DEV_PM_OPS(hisi_sas_v3_pm_ops,
+hisi_sas_v3_suspend,
+hisi_sas_v3_resume);
+
 static const struct pci_device_id sas_v3_pci_table[] = {
{ PCI_VDEVICE(HUAWEI, 0xa230), hip08 },
{}
@@ -3472,8 +3463,7 @@ static struct pci_driver sas_v3_pci_driver = {
.id_table   = sas_v3_pci_table,
.probe  = hisi_sas_v3_probe,
.remove = hisi_sas_v3_remove,
-   .suspend= hisi_sas_v3_suspend,
-   .resume = hisi_sas_v3_resume,
+   .driver.pm  = _sas_v3_pm_ops,
.err_handler= _sas_err_handler,
 };
 
-- 
2.28.0



[PATCH v3 15/28] scsi: mpt3sas_scsih: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 34 +++-
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index ce3dfe26691f..6691b7cddfff 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -10829,44 +10829,40 @@ _scsih_probe(struct pci_dev *pdev, const struct 
pci_device_id *id)
return rv;
 }
 
-#ifdef CONFIG_PM
 /**
  * scsih_suspend - power management suspend main entry point
- * @pdev: PCI device struct
- * @state: PM state change to (usually PCI_D3)
+ * @dev: Device struct
  *
  * Return: 0 success, anything else error.
  */
-static int
-scsih_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused
+scsih_suspend(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost = pci_get_drvdata(pdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
-   pci_power_t device_state;
 
mpt3sas_base_stop_watchdog(ioc);
flush_scheduled_work();
scsi_block_requests(shost);
_scsih_nvme_shutdown(ioc);
-   device_state = pci_choose_state(pdev, state);
-   ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
-pdev, pci_name(pdev), device_state);
+   ioc_info(ioc, "pdev=0x%p, slot=%s, entering suspended state\n",
+   pdev, pci_name(pdev));
 
-   pci_save_state(pdev);
mpt3sas_base_free_resources(ioc);
-   pci_set_power_state(pdev, device_state);
return 0;
 }
 
 /**
  * scsih_resume - power management resume main entry point
- * @pdev: PCI device struct
+ * @dev: Device struct
  *
  * Return: 0 success, anything else error.
  */
-static int
-scsih_resume(struct pci_dev *pdev)
+static int __maybe_unused
+scsih_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *shost = pci_get_drvdata(pdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
pci_power_t device_state = pdev->current_state;
@@ -10875,8 +10871,6 @@ scsih_resume(struct pci_dev *pdev)
ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
 pdev, pci_name(pdev), device_state);
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
ioc->pdev = pdev;
r = mpt3sas_base_map_resources(ioc);
if (r)
@@ -10887,7 +10881,6 @@ scsih_resume(struct pci_dev *pdev)
mpt3sas_base_start_watchdog(ioc);
return 0;
 }
-#endif /* CONFIG_PM */
 
 /**
  * scsih_pci_error_detected - Called when a PCI error is detected.
@@ -11161,6 +11154,8 @@ static struct pci_error_handlers _mpt3sas_err_handler = 
{
.resume = scsih_pci_resume,
 };
 
+static SIMPLE_DEV_PM_OPS(scsih_pm_ops, scsih_suspend, scsih_resume);
+
 static struct pci_driver mpt3sas_driver = {
.name   = MPT3SAS_DRIVER_NAME,
.id_table   = mpt3sas_pci_table,
@@ -11168,10 +11163,7 @@ static struct pci_driver mpt3sas_driver = {
.remove = scsih_remove,
.shutdown   = scsih_shutdown,
.err_handler= &_mpt3sas_err_handler,
-#ifdef CONFIG_PM
-   .suspend= scsih_suspend,
-   .resume = scsih_resume,
-#endif
+   .driver.pm  = _pm_ops,
 };
 
 /**
-- 
2.28.0



[PATCH v3 12/28] scsi: hisi_sas_v3_hw: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in hisi_sas_v3_resume(), and
there is no corresponding pci_enable_wake(, true) in
hisi_sas_v3_suspend(). Either it should do enable-wake the device in
.suspend() or should not invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
hisi_sas_v3_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index 55e2321a65bc..8f0f4084a054 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3431,7 +3431,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
dev_warn(dev, "resuming from operating state [D%d]\n",
 device_state);
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
rc = pci_enable_device(pdev);
if (rc) {
-- 
2.28.0



[PATCH v3 08/28] scsi: arcmsr: Drop PCI wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in arcmsr_resume(), and
there is no corresponding pci_enable_wake(, true) in arcmsr_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
arcmsr_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 30914c8f29cc..6ed2ad10bede 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1094,7 +1094,6 @@ static int arcmsr_resume(struct pci_dev *pdev)
(struct AdapterControlBlock *)host->hostdata;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
if (pci_enable_device(pdev)) {
pr_warn("%s: pci_enable_device error\n", __func__);
-- 
2.28.0



[PATCH v3 09/28] scsi: arcmsr: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/arcmsr/arcmsr_hba.c | 32 +++-
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 6ed2ad10bede..43848b467d8c 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -113,8 +113,8 @@ static int arcmsr_bios_param(struct scsi_device *sdev,
 static int arcmsr_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
 static int arcmsr_probe(struct pci_dev *pdev,
const struct pci_device_id *id);
-static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state);
-static int arcmsr_resume(struct pci_dev *pdev);
+static int __maybe_unused arcmsr_suspend(struct device *dev);
+static int __maybe_unused arcmsr_resume(struct device *dev);
 static void arcmsr_remove(struct pci_dev *pdev);
 static void arcmsr_shutdown(struct pci_dev *pdev);
 static void arcmsr_iop_init(struct AdapterControlBlock *acb);
@@ -213,13 +213,14 @@ static struct pci_device_id arcmsr_device_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, arcmsr_device_id_table);
 
+static SIMPLE_DEV_PM_OPS(arcmsr_pm_ops, arcmsr_suspend, arcmsr_resume);
+
 static struct pci_driver arcmsr_pci_driver = {
.name   = "arcmsr",
.id_table   = arcmsr_device_id_table,
.probe  = arcmsr_probe,
.remove = arcmsr_remove,
-   .suspend= arcmsr_suspend,
-   .resume = arcmsr_resume,
+   .driver.pm  = _pm_ops,
.shutdown   = arcmsr_shutdown,
 };
 /*
@@ -1065,14 +1066,14 @@ static void arcmsr_free_irq(struct pci_dev *pdev,
pci_free_irq_vectors(pdev);
 }
 
-static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused arcmsr_suspend(struct device *dev)
 {
-   uint32_t intmask_org;
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *)host->hostdata;
 
-   intmask_org = arcmsr_disable_outbound_ints(acb);
+   arcmsr_disable_outbound_ints(acb);
arcmsr_free_irq(pdev, acb);
del_timer_sync(>eternal_timer);
if (set_date_time)
@@ -1080,28 +1081,19 @@ static int arcmsr_suspend(struct pci_dev *pdev, 
pm_message_t state)
flush_work(>arcmsr_do_message_isr_bh);
arcmsr_stop_adapter_bgrb(acb);
arcmsr_flush_adapter_cache(acb);
-   pci_set_drvdata(pdev, host);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
return 0;
 }
 
-static int arcmsr_resume(struct pci_dev *pdev)
+static int __maybe_unused arcmsr_resume(struct device *dev)
 {
+   struct pci_dev *pdev = to_pci_dev(dev);
struct Scsi_Host *host = pci_get_drvdata(pdev);
struct AdapterControlBlock *acb =
(struct AdapterControlBlock *)host->hostdata;
 
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   if (pci_enable_device(pdev)) {
-   pr_warn("%s: pci_enable_device error\n", __func__);
-   return -ENODEV;
-   }
if (arcmsr_set_dma_mask(acb))
goto controller_unregister;
-   pci_set_master(pdev);
+
if (arcmsr_request_irq(pdev, acb) == FAILED)
goto controller_stop;
switch (acb->adapter_type) {
@@ -1136,9 +1128,7 @@ static int arcmsr_resume(struct pci_dev *pdev)
scsi_remove_host(host);
arcmsr_free_ccb_pool(acb);
arcmsr_unmap_pciregion(acb);
-   pci_release_regions(pdev);
scsi_host_put(host);
-   pci_disable_device(pdev);
return -ENODEV;
 }
 
-- 
2.28.0



[PATCH v3 10/28] scsi: esas2r: Drop PCI Wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in esas2r_resume(), and
there is no corresponding pci_enable_wake(, true) in esas2r_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
esas2r_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/esas2r/esas2r_init.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index eb7d139ffc00..90bc3489964b 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -676,10 +676,6 @@ int esas2r_resume(struct pci_dev *pdev)
   "pci_set_power_state(PCI_D0) "
   "called");
pci_set_power_state(pdev, PCI_D0);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_enable_wake(PCI_D0, 0) "
-  "called");
-   pci_enable_wake(pdev, PCI_D0, 0);
esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
   "pci_restore_state() called");
pci_restore_state(pdev);
-- 
2.28.0



[PATCH v3 11/28] scsi: esas2r: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/esas2r/esas2r.h  |  5 ++--
 drivers/scsi/esas2r/esas2r_init.c | 44 +--
 drivers/scsi/esas2r/esas2r_main.c |  3 +--
 3 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 7f43b95f4e94..6ad3e0871ef0 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -996,8 +996,9 @@ void esas2r_adapter_tasklet(unsigned long context);
 irqreturn_t esas2r_interrupt(int irq, void *dev_id);
 irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id);
 void esas2r_kickoff_timer(struct esas2r_adapter *a);
-int esas2r_suspend(struct pci_dev *pcid, pm_message_t state);
-int esas2r_resume(struct pci_dev *pcid);
+
+extern const struct dev_pm_ops esas2r_pm_ops;
+
 void esas2r_fw_event_off(struct esas2r_adapter *a);
 void esas2r_fw_event_on(struct esas2r_adapter *a);
 bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
diff --git a/drivers/scsi/esas2r/esas2r_init.c 
b/drivers/scsi/esas2r/esas2r_init.c
index 90bc3489964b..f6bf76f49d15 100644
--- a/drivers/scsi/esas2r/esas2r_init.c
+++ b/drivers/scsi/esas2r/esas2r_init.c
@@ -640,49 +640,27 @@ void esas2r_kill_adapter(int i)
}
 }
 
-int esas2r_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused esas2r_suspend(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
-   u32 device_state;
+   struct Scsi_Host *host = dev_get_drvdata(dev);
struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
 
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "suspending adapter()");
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "suspending adapter()");
if (!a)
return -ENODEV;
 
esas2r_adapter_power_down(a, 1);
-   device_state = pci_choose_state(pdev, state);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_save_state() called");
-   pci_save_state(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_disable_device() called");
-   pci_disable_device(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_set_power_state() called");
-   pci_set_power_state(pdev, device_state);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "esas2r_suspend(): 0");
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "esas2r_suspend(): 0");
return 0;
 }
 
-int esas2r_resume(struct pci_dev *pdev)
+static int __maybe_unused esas2r_resume(struct device *dev)
 {
-   struct Scsi_Host *host = pci_get_drvdata(pdev);
+   struct Scsi_Host *host = dev_get_drvdata(dev);
struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
-   int rez;
-
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "resuming adapter()");
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_set_power_state(PCI_D0) "
-  "called");
-   pci_set_power_state(pdev, PCI_D0);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_restore_state() called");
-   pci_restore_state(pdev);
-   esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
-  "pci_enable_device() called");
-   rez = pci_enable_device(pdev);
-   pci_set_master(pdev);
+   int rez = 0;
+
+   esas2r_log_dev(ESAS2R_LOG_INFO, dev, "resuming adapter()");
 
if (!a) {
rez = -ENODEV;
@@ -726,11 +704,13 @@ int esas2r_resume(struct pci_dev *pdev)
}
 
 error_exit:
-   esas2r_log_dev(ESAS2R_LOG_CRIT, &(pdev->dev), "esas2r_resume(): %d",
+   esas2r_log_dev(ESAS2R_LOG_CRIT, dev, "esas2r_resume(): %d",
   rez);
return rez;
 }
 
+SIMPLE_DEV_PM_OPS(esas2r_pm_ops, esas2r_suspend, esas2r_resume);
+
 bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str)
 {
set_bit(AF_DEGRADED_MODE, >flags);
diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index 7b49e2e9fcde..aab3ea580e6b 100644
--- a/drivers/scsi/esas

[PATCH v3 07/28] scsi: aic79xx: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aic7xxx/aic79xx.h | 12 +++
 drivers/scsi/aic7xxx/aic79xx_core.c|  8 ++---
 drivers/scsi/aic7xxx/aic79xx_osm_pci.c | 43 +++---
 drivers/scsi/aic7xxx/aic79xx_pci.c |  6 ++--
 4 files changed, 20 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index 9a515551641c..dd5dfd4f30a5 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1330,10 +1330,8 @@ const struct ahd_pci_identity 
*ahd_find_pci_device(ahd_dev_softc_t);
 int  ahd_pci_config(struct ahd_softc *,
 const struct ahd_pci_identity *);
 intahd_pci_test_register_access(struct ahd_softc *);
-#ifdef CONFIG_PM
-void   ahd_pci_suspend(struct ahd_softc *);
-void   ahd_pci_resume(struct ahd_softc *);
-#endif
+void __maybe_unusedahd_pci_suspend(struct ahd_softc *);
+void __maybe_unusedahd_pci_resume(struct ahd_softc *);
 
 /** SCB and SCB queue management 
**/
 void   ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
@@ -1344,10 +1342,8 @@ struct ahd_softc *ahd_alloc(void *platform_arg, char 
*name);
 int ahd_softc_init(struct ahd_softc *);
 voidahd_controller_info(struct ahd_softc *ahd, char *buf);
 int ahd_init(struct ahd_softc *ahd);
-#ifdef CONFIG_PM
-int ahd_suspend(struct ahd_softc *ahd);
-voidahd_resume(struct ahd_softc *ahd);
-#endif
+int __maybe_unused  ahd_suspend(struct ahd_softc *ahd);
+void __maybe_unused ahd_resume(struct ahd_softc *ahd);
 int ahd_default_config(struct ahd_softc *ahd);
 int ahd_parse_vpddata(struct ahd_softc *ahd,
   struct vpd_config *vpd);
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
b/drivers/scsi/aic7xxx/aic79xx_core.c
index e4a09b93d00c..06ee7abd0f8f 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -7880,11 +7880,9 @@ ahd_pause_and_flushwork(struct ahd_softc *ahd)
ahd->flags &= ~AHD_ALL_INTERRUPTS;
 }
 
-#ifdef CONFIG_PM
-int
+int __maybe_unused
 ahd_suspend(struct ahd_softc *ahd)
 {
-
ahd_pause_and_flushwork(ahd);
 
if (LIST_FIRST(>pending_scbs) != NULL) {
@@ -7895,15 +7893,13 @@ ahd_suspend(struct ahd_softc *ahd)
return (0);
 }
 
-void
+void __maybe_unused
 ahd_resume(struct ahd_softc *ahd)
 {
-
ahd_reset(ahd, /*reinit*/TRUE);
ahd_intr_enable(ahd, TRUE); 
ahd_restart(ahd);
 }
-#endif
 
 /** Busy Target Table 
*/
 /*
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c 
b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index 8b891a05d9e7..07b670b80f1b 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -74,11 +74,10 @@ static const struct pci_device_id ahd_linux_pci_id_table[] 
= {
 
 MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
 
-#ifdef CONFIG_PM
-static int
-ahd_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused
+ahd_linux_pci_dev_suspend(struct device *dev)
 {
-   struct ahd_softc *ahd = pci_get_drvdata(pdev);
+   struct ahd_softc *ahd = dev_get_drvdata(dev);
int rc;
 
if ((rc = ahd_suspend(ahd)))
@@ -86,39 +85,20 @@ ahd_linux_pci_dev_suspend(struct pci_dev *pdev, 
pm_message_t mesg)
 
ahd_pci_suspend(ahd);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   if (mesg.event & PM_EVENT_SLEEP)
-   pci_set_power_state(pdev, PCI_D3hot);
-
return rc;
 }
 
-static int
-ahd_linux_pci_dev_resume(struct pci_dev *pdev)
+static int __maybe_unused
+ahd_linux_pci_dev_resume(struct device *dev)
 {
-   struct ahd_softc *ahd = pci_get_drvdata(pdev);
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   if ((rc = pci_enable_device(pdev))) {
-   dev_printk(KERN_ERR, >dev,
-  "failed to enable device after resume (%d)\n", rc);
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   struct ahd_softc *ahd = dev_get_drvdata(dev);
 
ahd_

[PATCH v3 06/28] scsi: aic7xxx: use generic power management

2020-10-01 Thread Vaibhav Gupta
use generic power management

Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aic7xxx/aic7xxx.h | 10 ++
 drivers/scsi/aic7xxx/aic7xxx_core.c|  6 ++--
 drivers/scsi/aic7xxx/aic7xxx_osm_pci.c | 46 ++
 drivers/scsi/aic7xxx/aic7xxx_pci.c |  4 +--
 4 files changed, 17 insertions(+), 49 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index 88b90f9806c9..11a09798e6b5 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -1134,9 +1134,7 @@ const struct ahc_pci_identity 
*ahc_find_pci_device(ahc_dev_softc_t);
 int ahc_pci_config(struct ahc_softc *,
const struct ahc_pci_identity *);
 int ahc_pci_test_register_access(struct ahc_softc *);
-#ifdef CONFIG_PM
-voidahc_pci_resume(struct ahc_softc *ahc);
-#endif
+void __maybe_unused ahc_pci_resume(struct ahc_softc *ahc);
 
 /*** EISA/VL Front End 
/
 struct aic7770_identity *aic7770_find_device(uint32_t);
@@ -1160,10 +1158,8 @@ int   ahc_chip_init(struct ahc_softc 
*ahc);
 int ahc_init(struct ahc_softc *ahc);
 voidahc_intr_enable(struct ahc_softc *ahc, int enable);
 voidahc_pause_and_flushwork(struct ahc_softc *ahc);
-#ifdef CONFIG_PM
-int ahc_suspend(struct ahc_softc *ahc); 
-int ahc_resume(struct ahc_softc *ahc);
-#endif
+int __maybe_unused  ahc_suspend(struct ahc_softc *ahc);
+int __maybe_unused  ahc_resume(struct ahc_softc *ahc);
 voidahc_set_unit(struct ahc_softc *, int);
 voidahc_set_name(struct ahc_softc *, char *);
 voidahc_free(struct ahc_softc *ahc);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 3d4df906fa4f..c7eb238a9599 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -5590,8 +5590,7 @@ ahc_pause_and_flushwork(struct ahc_softc *ahc)
ahc->flags &= ~AHC_ALL_INTERRUPTS;
 }
 
-#ifdef CONFIG_PM
-int
+int __maybe_unused
 ahc_suspend(struct ahc_softc *ahc)
 {
 
@@ -5617,7 +5616,7 @@ ahc_suspend(struct ahc_softc *ahc)
return (0);
 }
 
-int
+int __maybe_unused
 ahc_resume(struct ahc_softc *ahc)
 {
 
@@ -5626,7 +5625,6 @@ ahc_resume(struct ahc_softc *ahc)
ahc_restart(ahc);
return (0);
 }
-#endif
 /** Busy Target Table 
*/
 /*
  * Return the untagged transaction id for a given target/channel lun.
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c 
b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index 9b293b1f0b71..a07e94fac673 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -121,47 +121,23 @@ static const struct pci_device_id 
ahc_linux_pci_id_table[] = {
 
 MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
 
-#ifdef CONFIG_PM
-static int
-ahc_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused
+ahc_linux_pci_dev_suspend(struct device *dev)
 {
-   struct ahc_softc *ahc = pci_get_drvdata(pdev);
-   int rc;
-
-   if ((rc = ahc_suspend(ahc)))
-   return rc;
+   struct ahc_softc *ahc = dev_get_drvdata(dev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   if (mesg.event & PM_EVENT_SLEEP)
-   pci_set_power_state(pdev, PCI_D3hot);
-
-   return rc;
+   return ahc_suspend(ahc);
 }
 
-static int
-ahc_linux_pci_dev_resume(struct pci_dev *pdev)
+static int __maybe_unused
+ahc_linux_pci_dev_resume(struct device *dev)
 {
-   struct ahc_softc *ahc = pci_get_drvdata(pdev);
-   int rc;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   if ((rc = pci_enable_device(pdev))) {
-   dev_printk(KERN_ERR, >dev,
-  "failed to enable device after resume (%d)\n", rc);
-   return rc;
-   }
-
-   pci_set_master(pdev);
+   struct ahc_softc *ahc = dev_get_drvdata(dev);
 
ahc_pci_resume(ahc);
 
return (ahc_resume(ahc));
 }
-#endif
 
 static void
 ahc_linux_pci_dev_remove(struct pci_dev *pdev)
@@ -

[PATCH v3 02/28] scsi: megaraid_sas: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 51 ++-
 1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 93ade9915ec0..72aa7fabe051 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7539,25 +7539,23 @@ static void megasas_shutdown_controller(struct 
megasas_instance *instance,
megasas_return_cmd(instance, cmd);
 }
 
-#ifdef CONFIG_PM
 /**
  * megasas_suspend -   driver suspend entry point
- * @pdev:  PCI device structure
- * @state: PCI power state to suspend routine
+ * @dev:   Device structure
  */
-static int
-megasas_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused
+megasas_suspend(struct device *dev)
 {
struct megasas_instance *instance;
 
-   instance = pci_get_drvdata(pdev);
+   instance = dev_get_drvdata(dev);
 
if (!instance)
return 0;
 
instance->unload = 1;
 
-   dev_info(>dev, "%s is called\n", __func__);
+   dev_info(dev, "%s is called\n", __func__);
 
/* Shutdown SR-IOV heartbeat timer */
if (instance->requestorId && !instance->skip_heartbeat_timer_del)
@@ -7587,47 +7585,29 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
state)
if (instance->msix_vectors)
pci_free_irq_vectors(instance->pdev);
 
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 }
 
 /**
  * megasas_resume-  driver resume entry point
- * @pdev:   PCI device structure
+ * @dev:   Device structure
  */
-static int
-megasas_resume(struct pci_dev *pdev)
+static int __maybe_unused
+megasas_resume(struct device *dev)
 {
int rval;
struct Scsi_Host *host;
struct megasas_instance *instance;
u32 status_reg;
 
-   instance = pci_get_drvdata(pdev);
+   instance = dev_get_drvdata(dev);
 
if (!instance)
return 0;
 
host = instance->host;
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-
-   dev_info(>dev, "%s is called\n", __func__);
-   /*
-* PCI prepping: enable device set bus mastering and dma mask
-*/
-   rval = pci_enable_device_mem(pdev);
 
-   if (rval) {
-   dev_err(>dev, "Enable device failed\n");
-   return rval;
-   }
-
-   pci_set_master(pdev);
+   dev_info(dev, "%s is called\n", __func__);
 
/*
 * We expect the FW state to be READY
@@ -7753,14 +7733,8 @@ megasas_resume(struct pci_dev *pdev)
 fail_set_dma_mask:
 fail_ready_state:
 
-   pci_disable_device(pdev);
-
return -ENODEV;
 }
-#else
-#define megasas_suspendNULL
-#define megasas_resume NULL
-#endif
 
 static inline int
 megasas_wait_for_adapter_operational(struct megasas_instance *instance)
@@ -8507,6 +8481,8 @@ static const struct file_operations megasas_mgmt_fops = {
.llseek = noop_llseek,
 };
 
+static SIMPLE_DEV_PM_OPS(megasas_pm_ops, megasas_suspend, megasas_resume);
+
 /*
  * PCI hotplug support registration structure
  */
@@ -8516,8 +8492,7 @@ static struct pci_driver megasas_pci_driver = {
.id_table = megasas_pci_table,
.probe = megasas_probe_one,
.remove = megasas_detach_one,
-   .suspend = megasas_suspend,
-   .resume = megasas_resume,
+   .driver.pm = _pm_ops,
.shutdown = megasas_shutdown,
 };
 
-- 
2.28.0



[PATCH v3 04/28] scsi: aacraid: Drop pci_enable_wake() from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in aac_resume(), and there is
no corresponding pci_enable_wake(, true) in aac_suspend(). Either it
should do enable-wake the device in .suspend() or should not invoke
pci_enable_wake() at all.

Concluding that this is a bug and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
aac_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aacraid/linit.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index a308e86a97f1..289887d5cc79 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1938,7 +1938,6 @@ static int aac_resume(struct pci_dev *pdev)
int r;
 
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
r = pci_enable_device(pdev);
 
-- 
2.28.0



[PATCH v3 03/28] scsi: megaraid_sas: update function description

2020-10-01 Thread Vaibhav Gupta
There is no "device" parameter in megasas_shutdown(). Instead there is
"pdev" which is not described.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 72aa7fabe051..63ff8b87fd18 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7904,7 +7904,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
 
 /**
  * megasas_shutdown -  Shutdown entry point
- * @device:Generic device structure
+ * @pdev:  PCI device structure
  */
 static void megasas_shutdown(struct pci_dev *pdev)
 {
-- 
2.28.0



[PATCH v3 05/28] scsi: aacraid: use generic power management

2020-10-01 Thread Vaibhav Gupta
Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/aacraid/linit.c | 33 +++--
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 289887d5cc79..4740b7afa612 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -1910,11 +1910,9 @@ static int aac_acquire_resources(struct aac_dev *dev)
 
 }
 
-#if (defined(CONFIG_PM))
-static int aac_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused aac_suspend(struct device *dev)
 {
-
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev);
struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
 
scsi_host_block(shost);
@@ -1923,28 +1921,14 @@ static int aac_suspend(struct pci_dev *pdev, 
pm_message_t state)
 
aac_release_resources(aac);
 
-   pci_set_drvdata(pdev, shost);
-   pci_save_state(pdev);
-   pci_disable_device(pdev);
-   pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
return 0;
 }
 
-static int aac_resume(struct pci_dev *pdev)
+static int __maybe_unused aac_resume(struct device *dev)
 {
-   struct Scsi_Host *shost = pci_get_drvdata(pdev);
+   struct Scsi_Host *shost = dev_get_drvdata(dev);
struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
-   int r;
-
-   pci_set_power_state(pdev, PCI_D0);
-   pci_restore_state(pdev);
-   r = pci_enable_device(pdev);
-
-   if (r)
-   goto fail_device;
 
-   pci_set_master(pdev);
if (aac_acquire_resources(aac))
goto fail_device;
/*
@@ -1959,10 +1943,8 @@ static int aac_resume(struct pci_dev *pdev)
 fail_device:
printk(KERN_INFO "%s%d: resume failed.\n", aac->name, aac->id);
scsi_host_put(shost);
-   pci_disable_device(pdev);
return -ENODEV;
 }
-#endif
 
 static void aac_shutdown(struct pci_dev *dev)
 {
@@ -2107,15 +2089,14 @@ static struct pci_error_handlers aac_pci_err_handler = {
.resume = aac_pci_resume,
 };
 
+static SIMPLE_DEV_PM_OPS(aac_pm_ops, aac_suspend, aac_resume);
+
 static struct pci_driver aac_pci_driver = {
.name   = AAC_DRIVERNAME,
.id_table   = aac_pci_tbl,
.probe  = aac_probe_one,
.remove = aac_remove_one,
-#if (defined(CONFIG_PM))
-   .suspend= aac_suspend,
-   .resume = aac_resume,
-#endif
+   .driver.pm  = _pm_ops,
.shutdown   = aac_shutdown,
.err_handler= _pci_err_handler,
 };
-- 
2.28.0



[PATCH v3 00/28] scsi: use generic power management

2020-10-01 Thread Vaibhav Gupta
Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to upgrade power management in 
drivers. This has been done by upgrading .suspend() and .resume() callbacks.

The upgrade makes sure that the involvement of PCI Core does not change the
order of operations executed in a driver. Thus, does not change its behavior.

In general, drivers with legacy PM, .suspend() and .resume() make use of PCI
helper functions like pci_enable/disable_device_mem(), pci_set_power_state(),
pci_save/restore_state(), pci_enable/disable_device(), etc. to complete
their job.

The conversion requires the removal of those function calls, change the
callbacks' definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

v3: break down the patches to drop PCI wakeup calls.

Test tools:
- Compiler: gcc (GCC) 10.2.0
- allmodconfig build: make -j$(nproc) W=1 all

Vaibhav Gupta (28):
  scsi: megaraid_sas: Drop PCI wakeup calls from .resume
  scsi: megaraid_sas: use generic power management
  scsi: megaraid_sas: update function description
  scsi: aacraid: Drop pci_enable_wake() from .resume
  scsi: aacraid: use generic power management
  scsi: aic7xxx: use generic power management
  scsi: aic79xx: use generic power management
  scsi: arcmsr: Drop PCI wakeup calls from .resume
  scsi: arcmsr: use generic power management
  scsi: esas2r: Drop PCI Wakeup calls from .resume
  scsi: esas2r: use generic power management
  scsi: hisi_sas_v3_hw: Drop PCI Wakeup calls from .resume
  scsi: hisi_sas_v3_hw: use generic power management
  scsi: mpt3sas_scsih: Drop PCI Wakeup calls from .resume
  scsi: mpt3sas_scsih: use generic power management
  scsi: lpfc: use generic power management
  scsi: pm_8001:  Drop PCI Wakeup calls from .resume
  scsi: pm_8001: use generic power management
  scsi: hpsa: use generic power management
  scsi: 3w-9xxx: Drop PCI Wakeup calls from .resume
  scsi: 3w-9xxx: use generic power management
  scsi: 3w-sas: Drop PCI Wakeup calls from .resume
  scsi: 3w-sas: use generic power management
  scsi: mvumi: Drop PCI Wakeup calls from .resume
  scsi: mvumi: use generic power management
  scsi: mvumi: update function description
  scsi: pmcraid: Drop PCI Wakeup calls from .resume
  scsi: pmcraid: use generic power management

 drivers/scsi/3w-9xxx.c|  30 ++-
 drivers/scsi/3w-sas.c |  32 ++-
 drivers/scsi/aacraid/linit.c  |  34 ++--
 drivers/scsi/aic7xxx/aic79xx.h|  12 +--
 drivers/scsi/aic7xxx/aic79xx_core.c   |   8 +-
 drivers/scsi/aic7xxx/aic79xx_osm_pci.c|  43 +++---
 drivers/scsi/aic7xxx/aic79xx_pci.c|   6 +-
 drivers/scsi/aic7xxx/aic7xxx.h|  10 +--
 drivers/scsi/aic7xxx/aic7xxx_core.c   |   6 +-
 drivers/scsi/aic7xxx/aic7xxx_osm_pci.c|  46 +++---
 drivers/scsi/aic7xxx/aic7xxx_pci.c|   4 +-
 drivers/scsi/arcmsr/arcmsr_hba.c  |  33 +++
 drivers/scsi/esas2r/esas2r.h  |   5 +-
 drivers/scsi/esas2r/esas2r_init.c |  48 +++
 drivers/scsi/esas2r/esas2r_main.c |   3 +-
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c|  31 +++
 drivers/scsi/hpsa.c   |  12 +--
 drivers/scsi/lpfc/lpfc_init.c | 100 +++---
 drivers/scsi/megaraid/megaraid_sas_base.c |  54 +++-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  35 +++-
 drivers/scsi/mvumi.c  |  49 +++
 drivers/scsi/pm8001/pm8001_init.c |  46 --
 drivers/scsi/pmcraid.c|  44 +++---
 23 files changed, 198 insertions(+), 493 deletions(-)

-- 
2.28.0



[PATCH v3 01/28] scsi: megaraid_sas: Drop PCI wakeup calls from .resume

2020-10-01 Thread Vaibhav Gupta
The driver calls pci_enable_wake(, false) in megasas_resume(), and
there is no corresponding pci_enable_wake(, true) in megasas_suspend().
Either it should do enable-wake the device in .suspend() or should not
invoke pci_enable_wake() at all.

Concluding that this driver doesn't support enable-wake and PCI core calls
pci_enable_wake(pci_dev, PCI_D0, false) during resume, drop it from
megasas_resume().

Signed-off-by: Vaibhav Gupta 
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 00668335c2af..93ade9915ec0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7614,7 +7614,6 @@ megasas_resume(struct pci_dev *pdev)
 
host = instance->host;
pci_set_power_state(pdev, PCI_D0);
-   pci_enable_wake(pdev, PCI_D0, 0);
pci_restore_state(pdev);
 
dev_info(>dev, "%s is called\n", __func__);
-- 
2.28.0



[PATCH v1] fbdev: aty: remove CONFIG_PM container

2020-09-17 Thread Vaibhav Gupta
The changes made in below mentioned commit removed CONFIG_PM containers
from drivers/video/fbdev/aty/atyfb_base.c but not from
drivers/video/fbdev/aty/atyfb.h for respective callbacks.

This resulted in error for implicit declaration for those callbacks.

Fixes: 348b2956d5e6 ("fbdev: aty: use generic power management")

Signed-off-by: Vaibhav Gupta 
Reported-by: kernel test robot 
---
 drivers/video/fbdev/aty/atyfb.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/aty/atyfb.h b/drivers/video/fbdev/aty/atyfb.h
index a7833bc98225..551372f9b9aa 100644
--- a/drivers/video/fbdev/aty/atyfb.h
+++ b/drivers/video/fbdev/aty/atyfb.h
@@ -287,8 +287,8 @@ static inline void aty_st_8(int regindex, u8 val, const 
struct atyfb_par *par)
 #endif
 }
 
-#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
-defined (CONFIG_FB_ATY_GENERIC_LCD) || defined (CONFIG_FB_ATY_BACKLIGHT)
+#if defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD) || \
+defined (CONFIG_FB_ATY_BACKLIGHT)
 extern void aty_st_lcd(int index, u32 val, const struct atyfb_par *par);
 extern u32 aty_ld_lcd(int index, const struct atyfb_par *par);
 #endif
-- 
2.28.0



Re: [PATCH v2 01/15] scsi: megaraid_sas: use generic power management

2020-09-09 Thread Vaibhav Gupta
On Wed, Sep 09, 2020 at 08:23:32AM -0500, Bjorn Helgaas wrote:
> On Wed, Sep 09, 2020 at 03:33:15PM +0530, Vaibhav Gupta wrote:
> > On Tue, Sep 08, 2020 at 12:32:09PM -0500, Bjorn Helgaas wrote:
> > > On Mon, Jul 20, 2020 at 07:04:14PM +0530, Vaibhav Gupta wrote:
> > > > With legacy PM hooks, it was the responsibility of a driver to manage 
> > > > PCI
> > > > states and also the device's power state. The generic approach is to let
> > > > the PCI core handle the work.
> > > > 
> > > > PCI core passes "struct device*" as an argument to the .suspend() and
> > > > .resume() callbacks. As the .suspend() work with "struct instance*",
> > > > extract it from "struct device*" using dev_get_drv_data().
> > > > 
> > > > Driver was also using PCI helper functions like 
> > > > pci_save/restore_state(),
> > > > pci_disable/enable_device(), pci_set_power_state() and 
> > > > pci_enable_wake().
> > > > They should not be invoked by the driver.
> > > > 
> > > > Compile-tested only.
> > > > 
> > > > Signed-off-by: Vaibhav Gupta 
> > > > ---
> > > >  drivers/scsi/megaraid/megaraid_sas_base.c | 61 ++-
> > > >  1 file changed, 16 insertions(+), 45 deletions(-)
> > > > 
> > > > diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> > > > b/drivers/scsi/megaraid/megaraid_sas_base.c
> > > > index 00668335c2af..4a6ee7778977 100644
> > > > --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> > > > +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> > > > @@ -7539,25 +7539,21 @@ static void megasas_shutdown_controller(struct 
> > > > megasas_instance *instance,
> > > > megasas_return_cmd(instance, cmd);
> > > >  }
> > > >  
> > > > -#ifdef CONFIG_PM
> > > >  /**
> > > >   * megasas_suspend -   driver suspend entry point
> > > > - * @pdev:  PCI device structure
> > > > - * @state: PCI power state to suspend routine
> > > > + * @dev:   Device structure
> > > >   */
> > > > -static int
> > > > -megasas_suspend(struct pci_dev *pdev, pm_message_t state)
> > > > +static int __maybe_unused
> > > > +megasas_suspend(struct device *dev)
> > > >  {
> > > > -   struct megasas_instance *instance;
> > > > -
> > > > -   instance = pci_get_drvdata(pdev);
> > > > +   struct megasas_instance *instance = dev_get_drvdata(dev);
> > > >  
> > > > if (!instance)
> > > > return 0;
> > > >  
> > > > instance->unload = 1;
> > > >  
> > > > -   dev_info(>dev, "%s is called\n", __func__);
> > > > +   dev_info(dev, "%s is called\n", __func__);
> > > >  
> > > > /* Shutdown SR-IOV heartbeat timer */
> > > > if (instance->requestorId && 
> > > > !instance->skip_heartbeat_timer_del)
> > > > @@ -7579,7 +7575,7 @@ megasas_suspend(struct pci_dev *pdev, 
> > > > pm_message_t state)
> > > >  
> > > > tasklet_kill(>isr_tasklet);
> > > >  
> > > > -   pci_set_drvdata(instance->pdev, instance);
> > > > +   dev_set_drvdata(dev, instance);
> > > 
> > > It *might* be correct to replace "instance->pdev" with "dev", but it's
> > > not obvious and deserves some explanation.  It's true that you can
> > > replace >dev with dev, but I don't know anything about
> > > instance->dev.
> 
> Sorry, I meant "instance->pdev" here.
> 
> > > I don't think this change is actually necessary, is it?
> > > "instance->pdev" is still a pci_dev pointer, so pci_set_drvdata()
> > > should work fine. ...
> > > 
> > There is no instance->dev . The 'dev' passed dev_set_drvdata() is
> > same >dev. 
> 
> Yes, it's true that "dev" here is the same as the ">dev" we had
> previously.  But we passed "instance->pdev" (not "pdev") to
> pci_set_drvdata().  So the question is whether instance->pdev->dev ==
> dev.
> 
> They *might* be the same, but I don't think it's obvious.
> 
Yes, they are same.
driver/pci/pci-driver.c :
'dev' is passed as parameter to both pci_device_probe() and pci_pm_suspend()
>From 'dev', pci_device_probe() extracts "struct pci_dev*" and passes it to the
probe callback of this driver.

In the proble function - megasas_probe_one()
:7347   instance->pdev = pdev;
:7386   pci_set_drvdata(pdev, instance);

The proble function is using "struct pci_dev*" variable "pdev" provided by core
and same we replaced >dev with "struct device *dev".

So the instance->pdev->dev and 'dev' can only differ if 'dev' passed to
pci_device_probe() and pci_pm_suspend() are different.
> > The dev pointer used here, points to same value.
> > 
> > pci_get_drvdata() and pci_set_drvdata() invoke dev_get_drvdata() and
> > dev_set_drvdata() respectively. And they do nothing else. Seems like
> > additional unnecessary function calls and operations.


Re: [PATCH v2 01/15] scsi: megaraid_sas: use generic power management

2020-09-09 Thread Vaibhav Gupta
On Tue, Sep 08, 2020 at 12:32:09PM -0500, Bjorn Helgaas wrote:
> On Mon, Jul 20, 2020 at 07:04:14PM +0530, Vaibhav Gupta wrote:
> > With legacy PM hooks, it was the responsibility of a driver to manage PCI
> > states and also the device's power state. The generic approach is to let
> > the PCI core handle the work.
> > 
> > PCI core passes "struct device*" as an argument to the .suspend() and
> > .resume() callbacks. As the .suspend() work with "struct instance*",
> > extract it from "struct device*" using dev_get_drv_data().
> > 
> > Driver was also using PCI helper functions like pci_save/restore_state(),
> > pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> > They should not be invoked by the driver.
> > 
> > Compile-tested only.
> > 
> > Signed-off-by: Vaibhav Gupta 
> > ---
> >  drivers/scsi/megaraid/megaraid_sas_base.c | 61 ++-
> >  1 file changed, 16 insertions(+), 45 deletions(-)
> > 
> > diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> > b/drivers/scsi/megaraid/megaraid_sas_base.c
> > index 00668335c2af..4a6ee7778977 100644
> > --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> > +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> > @@ -7539,25 +7539,21 @@ static void megasas_shutdown_controller(struct 
> > megasas_instance *instance,
> > megasas_return_cmd(instance, cmd);
> >  }
> >  
> > -#ifdef CONFIG_PM
> >  /**
> >   * megasas_suspend -   driver suspend entry point
> > - * @pdev:  PCI device structure
> > - * @state: PCI power state to suspend routine
> > + * @dev:   Device structure
> >   */
> > -static int
> > -megasas_suspend(struct pci_dev *pdev, pm_message_t state)
> > +static int __maybe_unused
> > +megasas_suspend(struct device *dev)
> >  {
> > -   struct megasas_instance *instance;
> > -
> > -   instance = pci_get_drvdata(pdev);
> > +   struct megasas_instance *instance = dev_get_drvdata(dev);
> >  
> > if (!instance)
> > return 0;
> >  
> > instance->unload = 1;
> >  
> > -   dev_info(>dev, "%s is called\n", __func__);
> > +   dev_info(dev, "%s is called\n", __func__);
> >  
> > /* Shutdown SR-IOV heartbeat timer */
> > if (instance->requestorId && !instance->skip_heartbeat_timer_del)
> > @@ -7579,7 +7575,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
> > state)
> >  
> > tasklet_kill(>isr_tasklet);
> >  
> > -   pci_set_drvdata(instance->pdev, instance);
> > +   dev_set_drvdata(dev, instance);
> 
> It *might* be correct to replace "instance->pdev" with "dev", but it's
> not obvious and deserves some explanation.  It's true that you can
> replace >dev with dev, but I don't know anything about
> instance->dev.
> 
> I don't think this change is actually necessary, is it?
> "instance->pdev" is still a pci_dev pointer, so pci_set_drvdata()
> should work fine.
> 
> It looks goofy to use pci_set_drvdata() or dev_set_drvdata() in a
> suspend routine, but I didn't bother trying to figure out what's going
> on here.
> 
There is no instance->dev . The 'dev' passed dev_set_drvdata() is same
>dev. The dev pointer used here, points to same value.

pci_get_drvdata() and pci_set_drvdata() invoke dev_get_drvdata() and
dev_set_drvdata() respectively. And they do nothing else. Seems like additional
unnecessary function calls and operations.

We can get rid of these PCI helper functions too.
> > instance->instancet->disable_intr(instance);
> >  
> > megasas_destroy_irqs(instance);
> > @@ -7587,48 +7583,28 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
> > state)
> > if (instance->msix_vectors)
> > pci_free_irq_vectors(instance->pdev);
> >  
> > -   pci_save_state(pdev);
> > -   pci_disable_device(pdev);
> > -
> > -   pci_set_power_state(pdev, pci_choose_state(pdev, state));
> > -
> > return 0;
> >  }
> >  
> >  /**
> >   * megasas_resume-  driver resume entry point
> > - * @pdev:   PCI device structure
> > + * @dev:  Device structure
> >   */
> > -static int
> > -megasas_resume(struct pci_dev *pdev)
> > +static int __maybe_unused
> > +megasas_resume(struct device *dev)
> >  {
> > int rval;
> > struct Scsi_Host *host;
> > -   struct megasas_instance *instance;
> > +   struct megasas_

Re: [PATCH v2 12/15] scsi: 3w-9xxx: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:25PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy PM have to manage PCI states and device's PM states
> themselves. They also need to take care of configuration registers.
> 
> With improved and powerful support of generic PM, PCI Core takes care of
> above mentioned, device-independent, jobs.
> 
> This driver makes use of PCI helper functions like
> pci_save/restore_state(), pci_enable/disable_device(),
> pci_set_power_state() and pci_set_master() to do required operations. In
> generic mode, they are no longer needed.
> 
> Change function parameter in both .suspend() and .resume() to
> "struct device*" type. Use to_pci_dev() and dev_get_drvdata() to get
> "struct pci_dev*" variable and drv data.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/3w-9xxx.c | 30 --
>  1 file changed, 8 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
> index 3337b1e80412..c15dcfda3957 100644
> --- a/drivers/scsi/3w-9xxx.c
> +++ b/drivers/scsi/3w-9xxx.c
> @@ -2191,10 +2191,10 @@ static void twa_remove(struct pci_dev *pdev)
>   twa_device_extension_count--;
>  } /* End twa_remove() */
>  
> -#ifdef CONFIG_PM
>  /* This function is called on PCI suspend */
> -static int twa_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused twa_suspend(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *host = pci_get_drvdata(pdev);
>   TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
>  
> @@ -2214,32 +2214,21 @@ static int twa_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>   }
>   TW_CLEAR_ALL_INTERRUPTS(tw_dev);
>  
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
> -
>   return 0;
>  } /* End twa_suspend() */
>  
>  /* This function is called on PCI resume */
> -static int twa_resume(struct pci_dev *pdev)
> +static int __maybe_unused twa_resume(struct device *dev)
>  {
>   int retval = 0;
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *host = pci_get_drvdata(pdev);
>   TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
>  
>   printk(KERN_WARNING "3w-9xxx: Resuming host %d.\n", 
> tw_dev->host->host_no);
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
>  
> - retval = pci_enable_device(pdev);
> - if (retval) {
> - TW_PRINTK(tw_dev->host, TW_DRIVER, 0x39, "Enable device failed 
> during resume");
> - return retval;
> - }
> + device_wakeup_disable(dev);
>  
> - pci_set_master(pdev);
>   pci_try_set_mwi(pdev);
>  
>   retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
> @@ -2277,11 +2266,9 @@ static int twa_resume(struct pci_dev *pdev)
>  
>  out_disable_device:
>   scsi_remove_host(host);
> - pci_disable_device(pdev);
>  
>   return retval;
>  } /* End twa_resume() */
> -#endif
>  
>  /* PCI Devices supported by this driver */
>  static struct pci_device_id twa_pci_tbl[] = {
> @@ -2297,16 +2284,15 @@ static struct pci_device_id twa_pci_tbl[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, twa_pci_tbl);
>  
> +static SIMPLE_DEV_PM_OPS(twa_pm_ops, twa_suspend, twa_resume);
> +
>  /* pci_driver initializer */
>  static struct pci_driver twa_driver = {
>   .name   = "3w-9xxx",
>   .id_table   = twa_pci_tbl,
>   .probe  = twa_probe,
>   .remove = twa_remove,
> -#ifdef CONFIG_PM
> - .suspend= twa_suspend,
> - .resume = twa_resume,
> -#endif
> + .driver.pm  = _pm_ops,
>   .shutdown   = twa_shutdown
>  };
>  
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 15/15] scsi: pmcraid: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:28PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy PM have to manage PCI states and device's PM states
> themselves. They also need to take care of configuration registers.
> 
> With improved and powerful support of generic PM, PCI Core takes care of
> above mentioned, device-independent, jobs.
> 
> This driver makes use of PCI helper functions like
> pci_save/restore_state(), pci_enable/disable_device(),
> pci_set_power_state() and to do required operations. In generic mode, they
> are no longer needed.
> 
> Change function parameter in both .suspend() and .resume() to
> "struct device*" type. Use to_pci_dev() to get "struct pci_dev*" variable.
> 
> In function pmcraid_resume(), earlier, the variable "rc" was set by
> pci_enable_device() which is now removed. Since PCI core does the required
> job, initialize "rc" with 0 value when declaring it.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/pmcraid.c | 44 +++---
>  1 file changed, 11 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
> index aa9ae2ae8579..b6b70ac2e2ee 100644
> --- a/drivers/scsi/pmcraid.c
> +++ b/drivers/scsi/pmcraid.c
> @@ -5237,54 +5237,39 @@ static void pmcraid_remove(struct pci_dev *pdev)
>   return;
>  }
>  
> -#ifdef CONFIG_PM
>  /**
>   * pmcraid_suspend - driver suspend entry point for power management
> - * @pdev:   PCI device structure
> - * @state:  PCI power state to suspend routine
> + * @dev:   Device structure
>   *
>   * Return Value - 0 always
>   */
> -static int pmcraid_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused pmcraid_suspend(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
>  
>   pmcraid_shutdown(pdev);
>   pmcraid_disable_interrupts(pinstance, ~0);
>   pmcraid_kill_tasklets(pinstance);
> - pci_set_drvdata(pinstance->pdev, pinstance);
>   pmcraid_unregister_interrupt_handler(pinstance);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
>  
>   return 0;
>  }
>  
>  /**
>   * pmcraid_resume - driver resume entry point PCI power management
> - * @pdev: PCI device structure
> + * @dev: Device structure
>   *
>   * Return Value - 0 in case of success. Error code in case of any failure
>   */
> -static int pmcraid_resume(struct pci_dev *pdev)
> +static int __maybe_unused pmcraid_resume(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct pmcraid_instance *pinstance = pci_get_drvdata(pdev);
>   struct Scsi_Host *host = pinstance->host;
> - int rc;
> -
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> -
> - rc = pci_enable_device(pdev);
> -
> - if (rc) {
> - dev_err(>dev, "resume: Enable device failed\n");
> - return rc;
> - }
> + int rc = 0;
>  
> - pci_set_master(pdev);
> + device_wakeup_disable(dev);
>  
>   if (sizeof(dma_addr_t) == 4 ||
>   dma_set_mask(>dev, DMA_BIT_MASK(64)))
> @@ -5337,18 +5322,10 @@ static int pmcraid_resume(struct pci_dev *pdev)
>   scsi_host_put(host);
>  
>  disable_device:
> - pci_disable_device(pdev);
>  
>   return rc;
>  }
>  
> -#else
> -
> -#define pmcraid_suspend NULL
> -#define pmcraid_resume  NULL
> -
> -#endif /* CONFIG_PM */
> -
>  /**
>   * pmcraid_complete_ioa_reset - Called by either timer or tasklet during
>   *   completion of the ioa reset
> @@ -5836,6 +5813,8 @@ static int pmcraid_probe(struct pci_dev *pdev,
>   return -ENODEV;
>  }
>  
> +static SIMPLE_DEV_PM_OPS(pmcraid_pm_ops, pmcraid_suspend, pmcraid_resume);
> +
>  /*
>   * PCI driver structure of pmcraid driver
>   */
> @@ -5844,8 +5823,7 @@ static struct pci_driver pmcraid_driver = {
>   .id_table = pmcraid_pci_table,
>   .probe = pmcraid_probe,
>   .remove = pmcraid_remove,
> - .suspend = pmcraid_suspend,
> - .resume = pmcraid_resume,
> + .driver.pm = _pm_ops,
>   .shutdown = pmcraid_shutdown
>  };
>  
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 13/15] scsi: 3w-sas: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:26PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy PM have to manage PCI states and device's PM states
> themselves. They also need to take care of configuration registers.
> 
> With improved and powerful support of generic PM, PCI Core takes care of
> above mentioned, device-independent, jobs.
> 
> This driver makes use of PCI helper functions like
> pci_save/restore_state(), pci_enable/disable_device(),
> pci_set_power_state() and pci_set_master() to do required operations. In
> generic mode, they are no longer needed.
> 
> Change function parameter in both .suspend() and .resume() to
> "struct device*" type. Use to_pci_dev() and dev_get_drvdata() to get
> "struct pci_dev*" variable and drv data.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/3w-sas.c | 31 ---
>  1 file changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
> index dda6fa857709..efaba30b0ca8 100644
> --- a/drivers/scsi/3w-sas.c
> +++ b/drivers/scsi/3w-sas.c
> @@ -1756,11 +1756,10 @@ static void twl_remove(struct pci_dev *pdev)
>   twl_device_extension_count--;
>  } /* End twl_remove() */
>  
> -#ifdef CONFIG_PM
>  /* This function is called on PCI suspend */
> -static int twl_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused twl_suspend(struct device *dev)
>  {
> - struct Scsi_Host *host = pci_get_drvdata(pdev);
> + struct Scsi_Host *host = dev_get_drvdata(dev);
>   TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
>  
>   printk(KERN_WARNING "3w-sas: Suspending host %d.\n", 
> tw_dev->host->host_no);
> @@ -1779,32 +1778,21 @@ static int twl_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>   /* Clear doorbell interrupt */
>   TWL_CLEAR_DB_INTERRUPT(tw_dev);
>  
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
> -
>   return 0;
>  } /* End twl_suspend() */
>  
>  /* This function is called on PCI resume */
> -static int twl_resume(struct pci_dev *pdev)
> +static int __maybe_unused twl_resume(struct device *dev)
>  {
>   int retval = 0;
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *host = pci_get_drvdata(pdev);
>   TW_Device_Extension *tw_dev = (TW_Device_Extension *)host->hostdata;
>  
>   printk(KERN_WARNING "3w-sas: Resuming host %d.\n", 
> tw_dev->host->host_no);
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
>  
> - retval = pci_enable_device(pdev);
> - if (retval) {
> - TW_PRINTK(tw_dev->host, TW_DRIVER, 0x24, "Enable device failed 
> during resume");
> - return retval;
> - }
> + device_wakeup_disable(dev);
>  
> - pci_set_master(pdev);
>   pci_try_set_mwi(pdev);
>  
>   retval = dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64));
> @@ -1842,11 +1830,9 @@ static int twl_resume(struct pci_dev *pdev)
>  
>  out_disable_device:
>   scsi_remove_host(host);
> - pci_disable_device(pdev);
>  
>   return retval;
>  } /* End twl_resume() */
> -#endif
>  
>  /* PCI Devices supported by this driver */
>  static struct pci_device_id twl_pci_tbl[] = {
> @@ -1855,16 +1841,15 @@ static struct pci_device_id twl_pci_tbl[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, twl_pci_tbl);
>  
> +static SIMPLE_DEV_PM_OPS(twl_pm_ops, twl_suspend, twl_resume);
> +
>  /* pci_driver initializer */
>  static struct pci_driver twl_driver = {
>   .name   = "3w-sas",
>   .id_table   = twl_pci_tbl,
>   .probe  = twl_probe,
>   .remove = twl_remove,
> -#ifdef CONFIG_PM
> - .suspend= twl_suspend,
> - .resume = twl_resume,
> -#endif
> + .driver.pm  = _pm_ops,
>   .shutdown   = twl_shutdown
>  };
>  
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 14/15] scsi: mvumi: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:27PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy PM have to manage PCI states and device's PM states
> themselves. They also need to take care of configuration registers.
> 
> With improved and powerful support of generic PM, PCI Core takes care of
> above mentioned, device-independent, jobs.
> 
> This driver makes use of PCI helper functions like
> pci_save/restore_state(), pci_enable/disable_device(),
> pci_set_power_state() and pci_set_master() to do required operations. In
> generic mode, they are no longer needed.
> 
> Change function parameter in both .suspend() and .resume() to
> "struct device*" type. Use dev_get_drvdata() to get drv data.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/mvumi.c | 49 ++--
>  1 file changed, 11 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> index 8906aceda4c4..7a6ef8264e47 100644
> --- a/drivers/scsi/mvumi.c
> +++ b/drivers/scsi/mvumi.c
> @@ -2558,7 +2558,7 @@ static void mvumi_detach_one(struct pci_dev *pdev)
>  
>  /**
>   * mvumi_shutdown -  Shutdown entry point
> - * @device:  Generic device structure
> + * @pdev:PCI device structure
>   */
>  static void mvumi_shutdown(struct pci_dev *pdev)
>  {
> @@ -2567,47 +2567,28 @@ static void mvumi_shutdown(struct pci_dev *pdev)
>   mvumi_flush_cache(mhba);
>  }
>  
> -static int __maybe_unused mvumi_suspend(struct pci_dev *pdev, pm_message_t 
> state)
> +static int __maybe_unused mvumi_suspend(struct device *dev)
>  {
> - struct mvumi_hba *mhba = NULL;
> + struct pci_dev *pdev = to_pci_dev(dev);
>  
> - mhba = pci_get_drvdata(pdev);
> + struct mvumi_hba *mhba = pci_get_drvdata(pdev);
>   mvumi_flush_cache(mhba);
>  
> - pci_set_drvdata(pdev, mhba);
>   mhba->instancet->disable_intr(mhba);
> - free_irq(mhba->pdev->irq, mhba);
>   mvumi_unmap_pci_addr(pdev, mhba->base_addr);
> - pci_release_regions(pdev);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
>  
>   return 0;
>  }
>  
> -static int __maybe_unused mvumi_resume(struct pci_dev *pdev)
> +static int __maybe_unused mvumi_resume(struct device *dev)
>  {
>   int ret;
> - struct mvumi_hba *mhba = NULL;
> -
> - mhba = pci_get_drvdata(pdev);
> -
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> + struct pci_dev *pdev = to_pci_dev(dev);
> + struct mvumi_hba *mhba = pci_get_drvdata(pdev);
>  
> - ret = pci_enable_device(pdev);
> - if (ret) {
> - dev_err(>dev, "enable device failed\n");
> - return ret;
> - }
> + device_wakeup_disable(dev);
>  
> - ret = mvumi_pci_set_master(pdev);
>   ret = dma_set_mask(>dev, DMA_BIT_MASK(32));
> - if (ret)
> - goto fail;
> - ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
>   if (ret)
>   goto fail;
>   ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
> @@ -2627,12 +2608,6 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
> *pdev)
>   goto unmap_pci_addr;
>   }
>  
> - ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
> - "mvumi", mhba);
> - if (ret) {
> - dev_err(>dev, "failed to register IRQ\n");
> - goto unmap_pci_addr;
> - }
>   mhba->instancet->enable_intr(mhba);
>  
>   return 0;
> @@ -2642,11 +2617,12 @@ static int __maybe_unused mvumi_resume(struct pci_dev 
> *pdev)
>  release_regions:
>   pci_release_regions(pdev);
>  fail:
> - pci_disable_device(pdev);
>  
>   return ret;
>  }
>  
> +static SIMPLE_DEV_PM_OPS(mvumi_pm_ops, mvumi_suspend, mvumi_resume);
> +
>  static struct pci_driver mvumi_pci_driver = {
>  
>   .name = MV_DRIVER_NAME,
> @@ -2654,10 +2630,7 @@ static struct pci_driver mvumi_pci_driver = {
>   .probe = mvumi_probe_one,
>   .remove = mvumi_detach_one,
>   .shutdown = mvumi_shutdown,
> -#ifdef CONFIG_PM
> - .suspend = mvumi_suspend,
> - .resume = mvumi_resume,
> -#endif
> + .driver.pm = _pm_ops,
>  };
>  
>  module_pci_driver(mvumi_pci_driver);
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 11/15] scsi: hpsa: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:24PM +0530, Vaibhav Gupta wrote:
> Drivers using legacy PM have to manage PCI states and device's PM states
> themselves. They also need to take care of configuration registers.
> 
> With improved and powerful support of generic PM, PCI Core takes care of
> above mentioned, device-independent, jobs.
> 
> Change function parameter in both .suspend() and .resume() to
> "struct device*" type. The function body remains unchanged as it was empty.
> Also, bind callbacks with "static const struct dev_pm_ops" variable.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/hpsa.c | 12 +++-
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> index 81d0414e2117..70bdd6fe91ee 100644
> --- a/drivers/scsi/hpsa.c
> +++ b/drivers/scsi/hpsa.c
> @@ -9070,25 +9070,27 @@ static void hpsa_remove_one(struct pci_dev *pdev)
>   hpda_free_ctlr_info(h); /* init_one 1 */
>  }
>  
> -static int hpsa_suspend(__attribute__((unused)) struct pci_dev *pdev,
> - __attribute__((unused)) pm_message_t state)
> +static int __maybe_unused hpsa_suspend(
> + __attribute__((unused)) struct device *dev)
>  {
>   return -ENOSYS;
>  }
>  
> -static int hpsa_resume(__attribute__((unused)) struct pci_dev *pdev)
> +static int __maybe_unused hpsa_resume
> + (__attribute__((unused)) struct device *dev)
>  {
>   return -ENOSYS;
>  }
>  
> +static SIMPLE_DEV_PM_OPS(hpsa_pm_ops, hpsa_suspend, hpsa_resume);
> +
>  static struct pci_driver hpsa_pci_driver = {
>   .name = HPSA,
>   .probe = hpsa_init_one,
>   .remove = hpsa_remove_one,
>   .id_table = hpsa_pci_device_id, /* id_table */
>   .shutdown = hpsa_shutdown,
> - .suspend = hpsa_suspend,
> - .resume = hpsa_resume,
> + .driver.pm = _pm_ops,
>  };
>  
>  /* Fill in bucket_map[], given nsgs (the max number of
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 10/15] scsi: pm_8001: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:23PM +0530, Vaibhav Gupta wrote:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
> 
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
> 
> The driver was calling pci_save/restore_state(), pci_choose_state(),
> pci_enable/disable_device() and pci_set_power_state() which is no more
> needed.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/pm8001/pm8001_init.c | 46 ---
>  1 file changed, 17 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/scsi/pm8001/pm8001_init.c 
> b/drivers/scsi/pm8001/pm8001_init.c
> index 9e99262a2b9d..d7d664b87720 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -1178,23 +1178,21 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
>  
>  /**
>   * pm8001_pci_suspend - power management suspend main entry point
> - * @pdev: PCI device struct
> - * @state: PM state change to (usually PCI_D3)
> + * @dev: Device struct
>   *
>   * Returns 0 success, anything else error.
>   */
> -static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused pm8001_pci_suspend(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct sas_ha_struct *sha = pci_get_drvdata(pdev);
> - struct pm8001_hba_info *pm8001_ha;
> + struct pm8001_hba_info *pm8001_ha = sha->lldd_ha;
>   int  i, j;
> - u32 device_state;
> - pm8001_ha = sha->lldd_ha;
>   sas_suspend_ha(sha);
>   flush_workqueue(pm8001_wq);
>   scsi_block_requests(pm8001_ha->shost);
>   if (!pdev->pm_cap) {
> - dev_err(>dev, " PCI PM not supported\n");
> + dev_err(dev, " PCI PM not supported\n");
>   return -ENODEV;
>   }
>   PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
> @@ -1217,24 +1215,21 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>   for (j = 0; j < PM8001_MAX_MSIX_VEC; j++)
>   tasklet_kill(_ha->tasklet[j]);
>  #endif
> - device_state = pci_choose_state(pdev, state);
>   pm8001_printk("pdev=0x%p, slot=%s, entering "
> -   "operating state [D%d]\n", pdev,
> -   pm8001_ha->name, device_state);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, device_state);
> +   "suspended state\n", pdev,
> +   pm8001_ha->name);
>   return 0;
>  }
>  
>  /**
>   * pm8001_pci_resume - power management resume main entry point
> - * @pdev: PCI device struct
> + * @dev: Device struct
>   *
>   * Returns 0 success, anything else error.
>   */
> -static int pm8001_pci_resume(struct pci_dev *pdev)
> +static int __maybe_unused pm8001_pci_resume(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct sas_ha_struct *sha = pci_get_drvdata(pdev);
>   struct pm8001_hba_info *pm8001_ha;
>   int rc;
> @@ -1247,17 +1242,8 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
>   pm8001_printk("pdev=0x%p, slot=%s, resuming from previous "
>   "operating state [D%d]\n", pdev, pm8001_ha->name, device_state);
>  
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> - rc = pci_enable_device(pdev);
> - if (rc) {
> - pm8001_printk("slot=%s Enable device failed during resume\n",
> -   pm8001_ha->name);
> - goto err_out_enable;
> - }
> + device_wakeup_disable(dev);
>  
> - pci_set_master(pdev);
>   rc = pci_go_44(pdev);
>   if (rc)
>   goto err_out_disable;
> @@ -1318,8 +1304,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev)
>  
>  err_out_disable:
>   scsi_remove_host(pm8001_ha->shost);
> - pci_disable_device(pdev);
> -err_out_enable:
> +
>   return rc;
>  }
>  
> @@ -1402,13 +1387,16 @@ static struct pci_device_id pm8001_pci_table[] = {
>   {} /* terminate list */
>  };
>  
> +static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops,
> +  pm8001_pci_suspend,
> +  pm8001_pci_resume);
> +
>  static struct pci_driver pm8001_pci_driver = {
>   .name   = DRV_NAME,
>   .id_table   = pm8001_pci_table,
>   .probe  = pm8001_pci_probe,
>   .remove = pm8001_pci_remove,
> - .suspend= pm8001_pci_suspend,
> - .resume = pm8001_pci_resume,
> + .driver.pm  = _pci_pm_ops,
>  };
>  
>  /**
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 09/15] scsi: lpfc: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:22PM +0530, Vaibhav Gupta wrote:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
> 
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
> 
> The driver was calling pci_save/restore_state(), pci_choose_state() and
> pci_set_power_state() which is no more needed.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/lpfc/lpfc_init.c | 100 +++---
>  1 file changed, 33 insertions(+), 67 deletions(-)
> 
> diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
> index 6637f84a3d1b..a36309b48144 100644
> --- a/drivers/scsi/lpfc/lpfc_init.c
> +++ b/drivers/scsi/lpfc/lpfc_init.c
> @@ -12452,8 +12452,7 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
>  
>  /**
>   * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
> - * @pdev: pointer to PCI device
> - * @msg: power management message
> + * @dev_d: pointer to device
>   *
>   * This routine is to be called from the kernel's PCI subsystem to support
>   * system Power Management (PM) to device with SLI-3 interface spec. When
> @@ -12471,10 +12470,10 @@ lpfc_pci_remove_one_s3(struct pci_dev *pdev)
>   *   0 - driver suspended the device
>   *   Error otherwise
>   **/
> -static int
> -lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg)
> +static int __maybe_unused
> +lpfc_pci_suspend_one_s3(struct device *dev_d)
>  {
> - struct Scsi_Host *shost = pci_get_drvdata(pdev);
> + struct Scsi_Host *shost = dev_get_drvdata(dev_d);
>   struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
>  
>   lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
> @@ -12488,16 +12487,12 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
> pm_message_t msg)
>   /* Disable interrupt from device */
>   lpfc_sli_disable_intr(phba);
>  
> - /* Save device state to PCI config space */
> - pci_save_state(pdev);
> - pci_set_power_state(pdev, PCI_D3hot);
> -
>   return 0;
>  }
>  
>  /**
>   * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
> - * @pdev: pointer to PCI device
> + * @dev_d: pointer to device
>   *
>   * This routine is to be called from the kernel's PCI subsystem to support
>   * system Power Management (PM) to device with SLI-3 interface spec. When PM
> @@ -12514,10 +12509,10 @@ lpfc_pci_suspend_one_s3(struct pci_dev *pdev, 
> pm_message_t msg)
>   *   0 - driver suspended the device
>   *   Error otherwise
>   **/
> -static int
> -lpfc_pci_resume_one_s3(struct pci_dev *pdev)
> +static int __maybe_unused
> +lpfc_pci_resume_one_s3(struct device *dev_d)
>  {
> - struct Scsi_Host *shost = pci_get_drvdata(pdev);
> + struct Scsi_Host *shost = dev_get_drvdata(dev_d);
>   struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
>   uint32_t intr_mode;
>   int error;
> @@ -12525,19 +12520,6 @@ lpfc_pci_resume_one_s3(struct pci_dev *pdev)
>   lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
>   "0452 PCI device Power Management resume.\n");
>  
> - /* Restore device state from PCI config space */
> - pci_set_power_state(pdev, PCI_D0);
> - pci_restore_state(pdev);
> -
> - /*
> -  * As the new kernel behavior of pci_restore_state() API call clears
> -  * device saved_state flag, need to save the restored state again.
> -  */
> - pci_save_state(pdev);
> -
> - if (pdev->is_busmaster)
> - pci_set_master(pdev);
> -
>   /* Startup the kernel thread for this host adapter. */
>   phba->worker_thread = kthread_run(lpfc_do_work, phba,
>   "lpfc_worker_%d", phba->brd_no);
> @@ -13294,8 +13276,7 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
>  
>  /**
>   * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
> - * @pdev: pointer to PCI device
> - * @msg: power management message
> + * @dev_d: pointer to device
>   *
>   * This routine is called from the kernel's PCI subsystem to support system
>   * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
> @@ -13313,10 +13294,10 @@ lpfc_pci_remove_one_s4(struct pci_dev *pdev)
>   *   0 - driver suspended the device
>   *   Error otherwise
>   **/
> -static int
> -lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
> +static int __maybe_unused
> +lpfc_pci_suspend_one_s4(struct device *d

Re: [PATCH v2 08/15] scsi: mpt3sas_scsih: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:21PM +0530, Vaibhav Gupta wrote:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
> 
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
> 
> The driver was calling pci_save/restore_state(), pci_choose_state(),
> pci_enable/disable_device() and pci_set_power_state() which is no more
> needed.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/mpt3sas/mpt3sas_scsih.c | 36 +++-
>  1 file changed, 14 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c 
> b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 08fc4b381056..f3c6e68b2921 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> @@ -10829,44 +10829,40 @@ _scsih_probe(struct pci_dev *pdev, const struct 
> pci_device_id *id)
>   return rv;
>  }
>  
> -#ifdef CONFIG_PM
>  /**
>   * scsih_suspend - power management suspend main entry point
> - * @pdev: PCI device struct
> - * @state: PM state change to (usually PCI_D3)
> + * @dev: Device struct
>   *
>   * Return: 0 success, anything else error.
>   */
> -static int
> -scsih_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused
> +scsih_suspend(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *shost = pci_get_drvdata(pdev);
>   struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
> - pci_power_t device_state;
>  
>   mpt3sas_base_stop_watchdog(ioc);
>   flush_scheduled_work();
>   scsi_block_requests(shost);
>   _scsih_nvme_shutdown(ioc);
> - device_state = pci_choose_state(pdev, state);
> - ioc_info(ioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n",
> -  pdev, pci_name(pdev), device_state);
> + ioc_info(ioc, "pdev=0x%p, slot=%s, entering suspended state\n",
> +  pdev, pci_name(pdev));
>  
> - pci_save_state(pdev);
>   mpt3sas_base_free_resources(ioc);
> - pci_set_power_state(pdev, device_state);
>   return 0;
>  }
>  
>  /**
>   * scsih_resume - power management resume main entry point
> - * @pdev: PCI device struct
> + * @dev: Device struct
>   *
>   * Return: 0 success, anything else error.
>   */
> -static int
> -scsih_resume(struct pci_dev *pdev)
> +static int __maybe_unused
> +scsih_resume(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *shost = pci_get_drvdata(pdev);
>   struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
>   pci_power_t device_state = pdev->current_state;
> @@ -10875,9 +10871,7 @@ scsih_resume(struct pci_dev *pdev)
>   ioc_info(ioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n",
>pdev, pci_name(pdev), device_state);
>  
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> + device_wakeup_disable(dev);
>   ioc->pdev = pdev;
>   r = mpt3sas_base_map_resources(ioc);
>   if (r)
> @@ -10888,7 +10882,6 @@ scsih_resume(struct pci_dev *pdev)
>   mpt3sas_base_start_watchdog(ioc);
>   return 0;
>  }
> -#endif /* CONFIG_PM */
>  
>  /**
>   * scsih_pci_error_detected - Called when a PCI error is detected.
> @@ -11162,6 +11155,8 @@ static struct pci_error_handlers _mpt3sas_err_handler 
> = {
>   .resume = scsih_pci_resume,
>  };
>  
> +static SIMPLE_DEV_PM_OPS(scsih_pm_ops, scsih_suspend, scsih_resume);
> +
>  static struct pci_driver mpt3sas_driver = {
>   .name   = MPT3SAS_DRIVER_NAME,
>   .id_table   = mpt3sas_pci_table,
> @@ -11169,10 +11164,7 @@ static struct pci_driver mpt3sas_driver = {
>   .remove = scsih_remove,
>   .shutdown   = scsih_shutdown,
>   .err_handler= &_mpt3sas_err_handler,
> -#ifdef CONFIG_PM
> - .suspend= scsih_suspend,
> - .resume = scsih_resume,
> -#endif
> + .driver.pm  = _pm_ops,
>  };
>  
>  /**
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 07/15] scsi: hisi_sas_v3_hw: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:20PM +0530, Vaibhav Gupta wrote:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
> 
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
> 
> The driver was calling pci_save/restore_state(), pci_choose_state(),
> pci_enable/disable_device() and pci_set_power_state() which is no more
> needed.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 32 +-
>  1 file changed, 11 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c 
> b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> index 55e2321a65bc..824bfbe1abbb 100644
> --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
> @@ -3374,13 +3374,13 @@ enum {
>   hip08,
>  };
>  
> -static int hisi_sas_v3_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused hisi_sas_v3_suspend(struct device *dev_d)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev_d);
>   struct sas_ha_struct *sha = pci_get_drvdata(pdev);
>   struct hisi_hba *hisi_hba = sha->lldd_ha;
>   struct device *dev = hisi_hba->dev;
>   struct Scsi_Host *shost = hisi_hba->shost;
> - pci_power_t device_state;
>   int rc;
>  
>   if (!pdev->pm_cap) {
> @@ -3406,12 +3406,7 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>  
>   hisi_sas_init_mem(hisi_hba);
>  
> - device_state = pci_choose_state(pdev, state);
> - dev_warn(dev, "entering operating state [D%d]\n",
> - device_state);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, device_state);
> + dev_warn(dev, "entering suspend state\n");
>  
>   hisi_sas_release_tasks(hisi_hba);
>  
> @@ -3419,8 +3414,9 @@ static int hisi_sas_v3_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>   return 0;
>  }
>  
> -static int hisi_sas_v3_resume(struct pci_dev *pdev)
> +static int __maybe_unused hisi_sas_v3_resume(struct device *dev_d)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev_d);
>   struct sas_ha_struct *sha = pci_get_drvdata(pdev);
>   struct hisi_hba *hisi_hba = sha->lldd_ha;
>   struct Scsi_Host *shost = hisi_hba->shost;
> @@ -3430,16 +3426,8 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
>  
>   dev_warn(dev, "resuming from operating state [D%d]\n",
>device_state);
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> - rc = pci_enable_device(pdev);
> - if (rc) {
> - dev_err(dev, "enable device failed during resume (%d)\n", rc);
> - return rc;
> - }
> + device_wakeup_disable(dev_d);
>  
> - pci_set_master(pdev);
>   scsi_unblock_requests(shost);
>   clear_bit(HISI_SAS_REJECT_CMD_BIT, _hba->flags);
>  
> @@ -3447,7 +3435,6 @@ static int hisi_sas_v3_resume(struct pci_dev *pdev)
>   rc = hw_init_v3_hw(hisi_hba);
>   if (rc) {
>   scsi_remove_host(shost);
> - pci_disable_device(pdev);
>   return rc;
>   }
>   hisi_hba->hw->phys_init(hisi_hba);
> @@ -3468,13 +3455,16 @@ static const struct pci_error_handlers 
> hisi_sas_err_handler = {
>   .reset_done = hisi_sas_reset_done_v3_hw,
>  };
>  
> +static SIMPLE_DEV_PM_OPS(hisi_sas_v3_pm_ops,
> +  hisi_sas_v3_suspend,
> +  hisi_sas_v3_resume);
> +
>  static struct pci_driver sas_v3_pci_driver = {
>   .name   = DRV_NAME,
>   .id_table   = sas_v3_pci_table,
>   .probe  = hisi_sas_v3_probe,
>   .remove = hisi_sas_v3_remove,
> - .suspend= hisi_sas_v3_suspend,
> - .resume = hisi_sas_v3_resume,
> + .driver.pm  = _sas_v3_pm_ops,
>   .err_handler= _sas_err_handler,
>  };
>  
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 06/15] scsi: esas2r: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:19PM +0530, Vaibhav Gupta wrote:
> With legacy PM, drivers themselves were responsible for managing the
> device's power states and takes care of register states.
> 
> After upgrading to the generic structure, PCI core will take care of
> required tasks and drivers should do only device-specific operations.
> 
> The driver was calling pci_save/restore_state(), pci_choose_state(),
> pci_enable/disable_device() and pci_set_power_state() which is no more
> needed.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/esas2r/esas2r.h  |  5 ++--
>  drivers/scsi/esas2r/esas2r_init.c | 48 +--
>  drivers/scsi/esas2r/esas2r_main.c |  3 +-
>  3 files changed, 18 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
> index 7f43b95f4e94..6ad3e0871ef0 100644
> --- a/drivers/scsi/esas2r/esas2r.h
> +++ b/drivers/scsi/esas2r/esas2r.h
> @@ -996,8 +996,9 @@ void esas2r_adapter_tasklet(unsigned long context);
>  irqreturn_t esas2r_interrupt(int irq, void *dev_id);
>  irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id);
>  void esas2r_kickoff_timer(struct esas2r_adapter *a);
> -int esas2r_suspend(struct pci_dev *pcid, pm_message_t state);
> -int esas2r_resume(struct pci_dev *pcid);
> +
> +extern const struct dev_pm_ops esas2r_pm_ops;
> +
>  void esas2r_fw_event_off(struct esas2r_adapter *a);
>  void esas2r_fw_event_on(struct esas2r_adapter *a);
>  bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq,
> diff --git a/drivers/scsi/esas2r/esas2r_init.c 
> b/drivers/scsi/esas2r/esas2r_init.c
> index eb7d139ffc00..6c5854969791 100644
> --- a/drivers/scsi/esas2r/esas2r_init.c
> +++ b/drivers/scsi/esas2r/esas2r_init.c
> @@ -640,53 +640,31 @@ void esas2r_kill_adapter(int i)
>   }
>  }
>  
> -int esas2r_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused esas2r_suspend(struct device *dev)
>  {
> - struct Scsi_Host *host = pci_get_drvdata(pdev);
> - u32 device_state;
> + struct Scsi_Host *host = dev_get_drvdata(dev);
>   struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
>  
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "suspending adapter()");
> + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "suspending adapter()");
>   if (!a)
>   return -ENODEV;
>  
>   esas2r_adapter_power_down(a, 1);
> - device_state = pci_choose_state(pdev, state);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_save_state() called");
> - pci_save_state(pdev);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_disable_device() called");
> - pci_disable_device(pdev);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_set_power_state() called");
> - pci_set_power_state(pdev, device_state);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "esas2r_suspend(): 0");
> + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "esas2r_suspend(): 0");
>   return 0;
>  }
>  
> -int esas2r_resume(struct pci_dev *pdev)
> +static int __maybe_unused esas2r_resume(struct device *dev)
>  {
> - struct Scsi_Host *host = pci_get_drvdata(pdev);
> + struct Scsi_Host *host = dev_get_drvdata(dev);
>   struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
> - int rez;
> + int rez = 0;
>  
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "resuming adapter()");
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_set_power_state(PCI_D0) "
> + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "resuming adapter()");
> + esas2r_log_dev(ESAS2R_LOG_INFO, dev,
> +"device_wakeup_disable() "
>  "called");
> - pci_set_power_state(pdev, PCI_D0);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_enable_wake(PCI_D0, 0) "
> -"called");
> - pci_enable_wake(pdev, PCI_D0, 0);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_restore_state() called");
> - pci_restore_state(pdev);
> - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev),
> -"pci_enable_device() called");
> - rez = pci_enable_device(pdev);
> - pci_set_master(pdev);
> + device_wakeup_disable(dev);
>  
>   if (!a) {
&g

Re: [PATCH v2 05/15] scsi: arcmsr: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:18PM +0530, Vaibhav Gupta wrote:
> With legacy PM hooks, it was the responsibility of a driver to manage PCI
> states and also the device's power state. The generic approach is to let
> the PCI core handle the work.
> 
> PCI core passes "struct device*" as an argument to the .suspend() and
> .resume() callbacks.
> 
> Driver was also using PCI helper functions like pci_save/restore_state(),
> pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> They should not be invoked by the driver.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/arcmsr/arcmsr_hba.c | 35 
>  1 file changed, 13 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c 
> b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 30914c8f29cc..7e098ddcc4f5 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -113,8 +113,8 @@ static int arcmsr_bios_param(struct scsi_device *sdev,
>  static int arcmsr_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
>  static int arcmsr_probe(struct pci_dev *pdev,
>   const struct pci_device_id *id);
> -static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state);
> -static int arcmsr_resume(struct pci_dev *pdev);
> +static int __maybe_unused arcmsr_suspend(struct device *dev);
> +static int __maybe_unused arcmsr_resume(struct device *dev);
>  static void arcmsr_remove(struct pci_dev *pdev);
>  static void arcmsr_shutdown(struct pci_dev *pdev);
>  static void arcmsr_iop_init(struct AdapterControlBlock *acb);
> @@ -213,13 +213,14 @@ static struct pci_device_id arcmsr_device_id_table[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, arcmsr_device_id_table);
>  
> +static SIMPLE_DEV_PM_OPS(arcmsr_pm_ops, arcmsr_suspend, arcmsr_resume);
> +
>  static struct pci_driver arcmsr_pci_driver = {
>   .name   = "arcmsr",
>   .id_table   = arcmsr_device_id_table,
>   .probe  = arcmsr_probe,
>   .remove = arcmsr_remove,
> - .suspend= arcmsr_suspend,
> - .resume = arcmsr_resume,
> + .driver.pm  = _pm_ops,
>   .shutdown   = arcmsr_shutdown,
>  };
>  /*
> @@ -1065,14 +1066,14 @@ static void arcmsr_free_irq(struct pci_dev *pdev,
>   pci_free_irq_vectors(pdev);
>  }
>  
> -static int arcmsr_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused arcmsr_suspend(struct device *dev)
>  {
> - uint32_t intmask_org;
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *host = pci_get_drvdata(pdev);
>   struct AdapterControlBlock *acb =
>   (struct AdapterControlBlock *)host->hostdata;
>  
> - intmask_org = arcmsr_disable_outbound_ints(acb);
> + arcmsr_disable_outbound_ints(acb);
>   arcmsr_free_irq(pdev, acb);
>   del_timer_sync(>eternal_timer);
>   if (set_date_time)
> @@ -1080,29 +1081,21 @@ static int arcmsr_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>   flush_work(>arcmsr_do_message_isr_bh);
>   arcmsr_stop_adapter_bgrb(acb);
>   arcmsr_flush_adapter_cache(acb);
> - pci_set_drvdata(pdev, host);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
>   return 0;
>  }
>  
> -static int arcmsr_resume(struct pci_dev *pdev)
> +static int __maybe_unused arcmsr_resume(struct device *dev)
>  {
> + struct pci_dev *pdev = to_pci_dev(dev);
>   struct Scsi_Host *host = pci_get_drvdata(pdev);
>   struct AdapterControlBlock *acb =
>   (struct AdapterControlBlock *)host->hostdata;
>  
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> - if (pci_enable_device(pdev)) {
> - pr_warn("%s: pci_enable_device error\n", __func__);
> - return -ENODEV;
> - }
> + device_wakeup_disable(dev);
> +
>   if (arcmsr_set_dma_mask(acb))
>   goto controller_unregister;
> - pci_set_master(pdev);
> +
>   if (arcmsr_request_irq(pdev, acb) == FAILED)
>   goto controller_stop;
>   switch (acb->adapter_type) {
> @@ -1137,9 +1130,7 @@ static int arcmsr_resume(struct pci_dev *pdev)
>   scsi_remove_host(host);
>   arcmsr_free_ccb_pool(acb);
>   arcmsr_unmap_pciregion(acb);
> - pci_release_regions(pdev);
>   scsi_host_put(host);
> - pci_disable_device(pdev);
>   return -ENODEV;
>  }
>  
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 04/15] scsi: aic79xx: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:17PM +0530, Vaibhav Gupta wrote:
> With legacy PM hooks, it was the responsibility of a driver to manage PCI
> states and also the device's power state. The generic approach is to let
> the PCI core handle the work.
> 
> PCI core passes "struct device*" as an argument to the .suspend() and
> .resume() callbacks.
> 
> Driver was using PCI helper functions like pci_save/restore_state(),
> pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> They should not be invoked by the driver.
> 
> Also, .suspend() and .resume() were invoking other functions for PM, which
> were againg bounded by "#ifdef CONFIG_PM" directive. Remove them and mark
> them as "__maybe_unused".
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/aic7xxx/aic79xx.h | 12 +++
>  drivers/scsi/aic7xxx/aic79xx_core.c|  8 ++---
>  drivers/scsi/aic7xxx/aic79xx_osm_pci.c | 43 +++---
>  drivers/scsi/aic7xxx/aic79xx_pci.c |  6 ++--
>  4 files changed, 20 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
> index 9a515551641c..dd5dfd4f30a5 100644
> --- a/drivers/scsi/aic7xxx/aic79xx.h
> +++ b/drivers/scsi/aic7xxx/aic79xx.h
> @@ -1330,10 +1330,8 @@ const struct   ahd_pci_identity 
> *ahd_find_pci_device(ahd_dev_softc_t);
>  intahd_pci_config(struct ahd_softc *,
>const struct ahd_pci_identity *);
>  int  ahd_pci_test_register_access(struct ahd_softc *);
> -#ifdef CONFIG_PM
> -void ahd_pci_suspend(struct ahd_softc *);
> -void ahd_pci_resume(struct ahd_softc *);
> -#endif
> +void __maybe_unused  ahd_pci_suspend(struct ahd_softc *);
> +void __maybe_unused  ahd_pci_resume(struct ahd_softc *);
>  
>  /** SCB and SCB queue management 
> **/
>  void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
> @@ -1344,10 +1342,8 @@ struct ahd_softc   *ahd_alloc(void *platform_arg, 
> char *name);
>  int   ahd_softc_init(struct ahd_softc *);
>  void  ahd_controller_info(struct ahd_softc *ahd, char *buf);
>  int   ahd_init(struct ahd_softc *ahd);
> -#ifdef CONFIG_PM
> -int   ahd_suspend(struct ahd_softc *ahd);
> -void  ahd_resume(struct ahd_softc *ahd);
> -#endif
> +int __maybe_unusedahd_suspend(struct ahd_softc *ahd);
> +void __maybe_unused   ahd_resume(struct ahd_softc *ahd);
>  int   ahd_default_config(struct ahd_softc *ahd);
>  int   ahd_parse_vpddata(struct ahd_softc *ahd,
>  struct vpd_config *vpd);
> diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
> b/drivers/scsi/aic7xxx/aic79xx_core.c
> index e4a09b93d00c..06ee7abd0f8f 100644
> --- a/drivers/scsi/aic7xxx/aic79xx_core.c
> +++ b/drivers/scsi/aic7xxx/aic79xx_core.c
> @@ -7880,11 +7880,9 @@ ahd_pause_and_flushwork(struct ahd_softc *ahd)
>   ahd->flags &= ~AHD_ALL_INTERRUPTS;
>  }
>  
> -#ifdef CONFIG_PM
> -int
> +int __maybe_unused
>  ahd_suspend(struct ahd_softc *ahd)
>  {
> -
>   ahd_pause_and_flushwork(ahd);
>  
>   if (LIST_FIRST(>pending_scbs) != NULL) {
> @@ -7895,15 +7893,13 @@ ahd_suspend(struct ahd_softc *ahd)
>   return (0);
>  }
>  
> -void
> +void __maybe_unused
>  ahd_resume(struct ahd_softc *ahd)
>  {
> -
>   ahd_reset(ahd, /*reinit*/TRUE);
>   ahd_intr_enable(ahd, TRUE); 
>   ahd_restart(ahd);
>  }
> -#endif
>  
>  /** Busy Target Table 
> */
>  /*
> diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c 
> b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
> index 8b891a05d9e7..07b670b80f1b 100644
> --- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
> +++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
> @@ -74,11 +74,10 @@ static const struct pci_device_id 
> ahd_linux_pci_id_table[] = {
>  
>  MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
>  
> -#ifdef CONFIG_PM
> -static int
> -ahd_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
> +static int __maybe_unused
> +ahd_linux_pci_dev_suspend(struct device *dev)
>  {
> - struct ahd_softc *ahd = pci_get_drvdata(pdev);
> + struct ahd_softc *ahd = dev_get_drvdata(dev);
>   int rc;
>  
>   if ((rc = ahd_suspend(ahd)))
> @@ -86,39 +85,20 @@ ahd_linux_pci_dev_suspend(struct pci_dev *pdev, 
> pm_message_t mesg)
>  
>   ahd_pci_suspend(ahd);
>  
> - pci_save_state(pdev);
> - pci_disable_

Re: [PATCH v2 03/15] scsi: aic7xxx: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:16PM +0530, Vaibhav Gupta wrote:
> With legacy PM hooks, it was the responsibility of a driver to manage PCI
> states and also the device's power state. The generic approach is to let
> the PCI core handle the work.
> 
> PCI core passes "struct device*" as an argument to the .suspend() and
> .resume() callbacks.
> 
> Driver was using PCI helper functions like pci_save/restore_state(),
> pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> They should not be invoked by the driver.
> 
> Also, .suspend() and .resume() are invoking other functions for PM, which
> were againg bounded by "#ifdef CONFIG_PM" directive. Remove the directive
> and mark those functions as "__maybe_unused".
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/aic7xxx/aic7xxx.h | 10 ++
>  drivers/scsi/aic7xxx/aic7xxx_core.c|  6 ++--
>  drivers/scsi/aic7xxx/aic7xxx_osm_pci.c | 46 ++
>  drivers/scsi/aic7xxx/aic7xxx_pci.c |  4 +--
>  4 files changed, 17 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
> index 88b90f9806c9..11a09798e6b5 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx.h
> +++ b/drivers/scsi/aic7xxx/aic7xxx.h
> @@ -1134,9 +1134,7 @@ const struct ahc_pci_identity   
> *ahc_find_pci_device(ahc_dev_softc_t);
>  int   ahc_pci_config(struct ahc_softc *,
>   const struct ahc_pci_identity *);
>  int   ahc_pci_test_register_access(struct ahc_softc *);
> -#ifdef CONFIG_PM
> -void  ahc_pci_resume(struct ahc_softc *ahc);
> -#endif
> +void __maybe_unused   ahc_pci_resume(struct ahc_softc *ahc);
>  
>  /*** EISA/VL Front End 
> /
>  struct aic7770_identity *aic7770_find_device(uint32_t);
> @@ -1160,10 +1158,8 @@ int ahc_chip_init(struct ahc_softc 
> *ahc);
>  int   ahc_init(struct ahc_softc *ahc);
>  void  ahc_intr_enable(struct ahc_softc *ahc, int enable);
>  void  ahc_pause_and_flushwork(struct ahc_softc *ahc);
> -#ifdef CONFIG_PM
> -int   ahc_suspend(struct ahc_softc *ahc); 
> -int   ahc_resume(struct ahc_softc *ahc);
> -#endif
> +int __maybe_unusedahc_suspend(struct ahc_softc *ahc);
> +int __maybe_unusedahc_resume(struct ahc_softc *ahc);
>  void  ahc_set_unit(struct ahc_softc *, int);
>  void  ahc_set_name(struct ahc_softc *, char *);
>  void  ahc_free(struct ahc_softc *ahc);
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
> b/drivers/scsi/aic7xxx/aic7xxx_core.c
> index 3d4df906fa4f..c7eb238a9599 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_core.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
> @@ -5590,8 +5590,7 @@ ahc_pause_and_flushwork(struct ahc_softc *ahc)
>   ahc->flags &= ~AHC_ALL_INTERRUPTS;
>  }
>  
> -#ifdef CONFIG_PM
> -int
> +int __maybe_unused
>  ahc_suspend(struct ahc_softc *ahc)
>  {
>  
> @@ -5617,7 +5616,7 @@ ahc_suspend(struct ahc_softc *ahc)
>   return (0);
>  }
>  
> -int
> +int __maybe_unused
>  ahc_resume(struct ahc_softc *ahc)
>  {
>  
> @@ -5626,7 +5625,6 @@ ahc_resume(struct ahc_softc *ahc)
>   ahc_restart(ahc);
>   return (0);
>  }
> -#endif
>  /** Busy Target Table 
> */
>  /*
>   * Return the untagged transaction id for a given target/channel lun.
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c 
> b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> index 9b293b1f0b71..a07e94fac673 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
> @@ -121,47 +121,23 @@ static const struct pci_device_id 
> ahc_linux_pci_id_table[] = {
>  
>  MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
>  
> -#ifdef CONFIG_PM
> -static int
> -ahc_linux_pci_dev_suspend(struct pci_dev *pdev, pm_message_t mesg)
> +static int __maybe_unused
> +ahc_linux_pci_dev_suspend(struct device *dev)
>  {
> - struct ahc_softc *ahc = pci_get_drvdata(pdev);
> - int rc;
> -
> - if ((rc = ahc_suspend(ahc)))
> - return rc;
> + struct ahc_softc *ahc = dev_get_drvdata(dev);
>  
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> -
> - if (mesg.event & PM_EVENT_SLEEP)
> - pci_set_power_state(pdev, PCI_D3hot);
> -
> - return rc;
> + return ahc_suspend(ahc);
>  }
>  
> -static int
> -ahc_linux_p

Re: [PATCH v2 02/15] scsi: aacraid: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:15PM +0530, Vaibhav Gupta wrote:
> With legacy PM hooks, it was the responsibility of a driver to manage PCI
> states and also the device's power state. The generic approach is to let
> the PCI core handle the work.
> 
> PCI core passes "struct device*" as an argument to the .suspend() and
> .resume() callbacks.
> 
> Driver was using PCI helper functions like pci_save/restore_state(),
> pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> They should not be invoked by the driver.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/aacraid/linit.c | 34 --
>  1 file changed, 8 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
> index a308e86a97f1..1e44868ee953 100644
> --- a/drivers/scsi/aacraid/linit.c
> +++ b/drivers/scsi/aacraid/linit.c
> @@ -1910,11 +1910,9 @@ static int aac_acquire_resources(struct aac_dev *dev)
>  
>  }
>  
> -#if (defined(CONFIG_PM))
> -static int aac_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused aac_suspend(struct device *dev)
>  {
> -
> - struct Scsi_Host *shost = pci_get_drvdata(pdev);
> + struct Scsi_Host *shost = dev_get_drvdata(dev);
>   struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
>  
>   scsi_host_block(shost);
> @@ -1923,29 +1921,16 @@ static int aac_suspend(struct pci_dev *pdev, 
> pm_message_t state)
>  
>   aac_release_resources(aac);
>  
> - pci_set_drvdata(pdev, shost);
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
> -
>   return 0;
>  }
>  
> -static int aac_resume(struct pci_dev *pdev)
> +static int __maybe_unused aac_resume(struct device *dev)
>  {
> - struct Scsi_Host *shost = pci_get_drvdata(pdev);
> + struct Scsi_Host *shost = dev_get_drvdata(dev);
>   struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
> - int r;
>  
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> - r = pci_enable_device(pdev);
> + device_wakeup_disable(dev);
>  
> - if (r)
> - goto fail_device;
> -
> - pci_set_master(pdev);
>   if (aac_acquire_resources(aac))
>   goto fail_device;
>   /*
> @@ -1960,10 +1945,8 @@ static int aac_resume(struct pci_dev *pdev)
>  fail_device:
>   printk(KERN_INFO "%s%d: resume failed.\n", aac->name, aac->id);
>   scsi_host_put(shost);
> - pci_disable_device(pdev);
>   return -ENODEV;
>  }
> -#endif
>  
>  static void aac_shutdown(struct pci_dev *dev)
>  {
> @@ -2108,15 +2091,14 @@ static struct pci_error_handlers aac_pci_err_handler 
> = {
>   .resume = aac_pci_resume,
>  };
>  
> +static SIMPLE_DEV_PM_OPS(aac_pm_ops, aac_suspend, aac_resume);
> +
>  static struct pci_driver aac_pci_driver = {
>   .name   = AAC_DRIVERNAME,
>   .id_table   = aac_pci_tbl,
>   .probe  = aac_probe_one,
>   .remove = aac_remove_one,
> -#if (defined(CONFIG_PM))
> - .suspend= aac_suspend,
> - .resume = aac_resume,
> -#endif
> + .driver.pm  = _pm_ops,
>   .shutdown   = aac_shutdown,
>   .err_handler= _pci_err_handler,
>  };
> -- 
> 2.27.0
> 
.


Re: [PATCH v2 01/15] scsi: megaraid_sas: use generic power management

2020-09-08 Thread Vaibhav Gupta
On Mon, Jul 20, 2020 at 07:04:14PM +0530, Vaibhav Gupta wrote:
> With legacy PM hooks, it was the responsibility of a driver to manage PCI
> states and also the device's power state. The generic approach is to let
> the PCI core handle the work.
> 
> PCI core passes "struct device*" as an argument to the .suspend() and
> .resume() callbacks. As the .suspend() work with "struct instance*",
> extract it from "struct device*" using dev_get_drv_data().
> 
> Driver was also using PCI helper functions like pci_save/restore_state(),
> pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake().
> They should not be invoked by the driver.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta 
> ---
>  drivers/scsi/megaraid/megaraid_sas_base.c | 61 ++-
>  1 file changed, 16 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
> b/drivers/scsi/megaraid/megaraid_sas_base.c
> index 00668335c2af..4a6ee7778977 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -7539,25 +7539,21 @@ static void megasas_shutdown_controller(struct 
> megasas_instance *instance,
>   megasas_return_cmd(instance, cmd);
>  }
>  
> -#ifdef CONFIG_PM
>  /**
>   * megasas_suspend - driver suspend entry point
> - * @pdev:PCI device structure
> - * @state:   PCI power state to suspend routine
> + * @dev: Device structure
>   */
> -static int
> -megasas_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused
> +megasas_suspend(struct device *dev)
>  {
> - struct megasas_instance *instance;
> -
> - instance = pci_get_drvdata(pdev);
> + struct megasas_instance *instance = dev_get_drvdata(dev);
>  
>   if (!instance)
>   return 0;
>  
>   instance->unload = 1;
>  
> - dev_info(>dev, "%s is called\n", __func__);
> + dev_info(dev, "%s is called\n", __func__);
>  
>   /* Shutdown SR-IOV heartbeat timer */
>   if (instance->requestorId && !instance->skip_heartbeat_timer_del)
> @@ -7579,7 +7575,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
> state)
>  
>   tasklet_kill(>isr_tasklet);
>  
> - pci_set_drvdata(instance->pdev, instance);
> + dev_set_drvdata(dev, instance);
>   instance->instancet->disable_intr(instance);
>  
>   megasas_destroy_irqs(instance);
> @@ -7587,48 +7583,28 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t 
> state)
>   if (instance->msix_vectors)
>   pci_free_irq_vectors(instance->pdev);
>  
> - pci_save_state(pdev);
> - pci_disable_device(pdev);
> -
> - pci_set_power_state(pdev, pci_choose_state(pdev, state));
> -
>   return 0;
>  }
>  
>  /**
>   * megasas_resume-  driver resume entry point
> - * @pdev:   PCI device structure
> + * @dev:  Device structure
>   */
> -static int
> -megasas_resume(struct pci_dev *pdev)
> +static int __maybe_unused
> +megasas_resume(struct device *dev)
>  {
>   int rval;
>   struct Scsi_Host *host;
> - struct megasas_instance *instance;
> + struct megasas_instance *instance = dev_get_drvdata(dev);
>   u32 status_reg;
>  
> - instance = pci_get_drvdata(pdev);
> -
>   if (!instance)
>   return 0;
>  
>   host = instance->host;
> - pci_set_power_state(pdev, PCI_D0);
> - pci_enable_wake(pdev, PCI_D0, 0);
> - pci_restore_state(pdev);
> + device_wakeup_disable(dev);
>  
> - dev_info(>dev, "%s is called\n", __func__);
> - /*
> -  * PCI prepping: enable device set bus mastering and dma mask
> -  */
> - rval = pci_enable_device_mem(pdev);
> -
> - if (rval) {
> - dev_err(>dev, "Enable device failed\n");
> - return rval;
> - }
> -
> - pci_set_master(pdev);
> + dev_info(dev, "%s is called\n", __func__);
>  
>   /*
>* We expect the FW state to be READY
> @@ -7754,14 +7730,8 @@ megasas_resume(struct pci_dev *pdev)
>  fail_set_dma_mask:
>  fail_ready_state:
>  
> - pci_disable_device(pdev);
> -
>   return -ENODEV;
>  }
> -#else
> -#define megasas_suspend  NULL
> -#define megasas_resume   NULL
> -#endif
>  
>  static inline int
>  megasas_wait_for_adapter_operational(struct megasas_instance *instance)
> @@ -7931,7 +7901,7 @@ static void megasas_detach_one(struct pci_dev *pdev)
>  
>  /**
>

  1   2   3   4   5   >