1 From de665f28f788ad72ff6a0ce6ac2721d77248b7cf Mon Sep 17 00:00:00 2001
2 From: Mahesh Rajashekhara <Mahesh.Rajashekhara@pmcs.com>
3 Date: Fri, 28 Aug 2015 06:38:34 -0400
4 Subject: aacraid: Add Power Management support
6 * .suspend() and .resume() routines implemented in the driver
7 * aac_release_resources() initiates firmware shutdown
8 * aac_acquire_resources re-initializes the host interface
10 Reviewed-by: Tomas Henzl <thenzl@redhat.com>
11 Reviewed-by: Murthy Bhat <Murthy.Bhat@pmcs.com>
12 Reviewed-by: Karthikeya Sunkesula <Karthikeya.Sunkesula@pmcs.com>
13 Signed-off-by: Mahesh Rajashekhara <Mahesh.Rajashekhara@pmcs.com>
14 Signed-off-by: James Bottomley <JBottomley@Odin.com>
16 drivers/scsi/aacraid/aacraid.h | 5 ++
17 drivers/scsi/aacraid/comminit.c | 154 ++++++++++++++++++++--------------------
18 drivers/scsi/aacraid/linit.c | 147 ++++++++++++++++++++++++++++++++++++++
19 drivers/scsi/aacraid/rx.c | 1 +
20 drivers/scsi/aacraid/sa.c | 1 +
21 drivers/scsi/aacraid/src.c | 2 +
22 6 files changed, 232 insertions(+), 78 deletions(-)
24 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
25 index 40fe65c..62b0999 100644
26 --- a/drivers/scsi/aacraid/aacraid.h
27 +++ b/drivers/scsi/aacraid/aacraid.h
28 @@ -547,6 +547,7 @@ struct adapter_ops
29 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
30 int (*adapter_check_health)(struct aac_dev *dev);
31 int (*adapter_restart)(struct aac_dev *dev, int bled);
32 + void (*adapter_start)(struct aac_dev *dev);
33 /* Transport operations */
34 int (*adapter_ioremap)(struct aac_dev * dev, u32 size);
35 irq_handler_t adapter_intr;
36 @@ -1247,6 +1248,9 @@ struct aac_dev
37 #define aac_adapter_restart(dev,bled) \
38 (dev)->a_ops.adapter_restart(dev,bled)
40 +#define aac_adapter_start(dev) \
41 + ((dev)->a_ops.adapter_start(dev))
43 #define aac_adapter_ioremap(dev, size) \
44 (dev)->a_ops.adapter_ioremap(dev, size)
46 @@ -2127,6 +2131,7 @@ int aac_sa_init(struct aac_dev *dev);
47 int aac_src_init(struct aac_dev *dev);
48 int aac_srcv_init(struct aac_dev *dev);
49 int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify);
50 +void aac_define_int_mode(struct aac_dev *dev);
51 unsigned int aac_response_normal(struct aac_queue * q);
52 unsigned int aac_command_normal(struct aac_queue * q);
53 unsigned int aac_intr_normal(struct aac_dev *dev, u32 Index,
54 diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
55 index 45db84a..45a0a04 100644
56 --- a/drivers/scsi/aacraid/comminit.c
57 +++ b/drivers/scsi/aacraid/comminit.c
62 -static void aac_define_int_mode(struct aac_dev *dev);
64 struct aac_common aac_config = {
67 @@ -338,6 +336,82 @@ static int aac_comm_init(struct aac_dev * dev)
71 +void aac_define_int_mode(struct aac_dev *dev)
76 + /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
77 + if (dev->max_msix == 0 ||
78 + dev->pdev->device == PMC_DEVICE_S6 ||
82 + dev->scsi_host_ptr->can_queue +
87 + /* Don't bother allocating more MSI-X vectors than cpus */
88 + msi_count = min(dev->max_msix,
89 + (unsigned int)num_online_cpus());
91 + dev->max_msix = msi_count;
93 + if (msi_count > AAC_MAX_MSIX)
94 + msi_count = AAC_MAX_MSIX;
96 + for (i = 0; i < msi_count; i++)
97 + dev->msixentry[i].entry = i;
99 + if (msi_count > 1 &&
100 + pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
101 + i = pci_enable_msix(dev->pdev,
104 + /* Check how many MSIX vectors are allocated */
106 + dev->msi_enabled = 1;
109 + if (pci_enable_msix(dev->pdev,
112 + dev->msi_enabled = 0;
113 + printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
114 + dev->name, dev->id, i);
118 + dev->msi_enabled = 0;
119 + printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
120 + dev->name, dev->id, i);
124 + if (!dev->msi_enabled) {
126 + i = pci_enable_msi(dev->pdev);
129 + dev->msi_enabled = 1;
132 + printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
133 + dev->name, dev->id, i);
137 + if (!dev->msi_enabled)
138 + dev->max_msix = msi_count = 1;
140 + if (dev->max_msix > msi_count)
141 + dev->max_msix = msi_count;
144 + (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
147 struct aac_dev *aac_init_adapter(struct aac_dev *dev)
150 @@ -508,79 +582,3 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev)
154 -static void aac_define_int_mode(struct aac_dev *dev)
160 - /* max. vectors from GET_COMM_PREFERRED_SETTINGS */
161 - if (dev->max_msix == 0 ||
162 - dev->pdev->device == PMC_DEVICE_S6 ||
166 - dev->scsi_host_ptr->can_queue +
171 - msi_count = min(dev->max_msix,
172 - (unsigned int)num_online_cpus());
174 - dev->max_msix = msi_count;
176 - if (msi_count > AAC_MAX_MSIX)
177 - msi_count = AAC_MAX_MSIX;
179 - for (i = 0; i < msi_count; i++)
180 - dev->msixentry[i].entry = i;
182 - if (msi_count > 1 &&
183 - pci_find_capability(dev->pdev, PCI_CAP_ID_MSIX)) {
184 - i = pci_enable_msix(dev->pdev,
187 - /* Check how many MSIX vectors are allocated */
189 - dev->msi_enabled = 1;
192 - if (pci_enable_msix(dev->pdev,
195 - dev->msi_enabled = 0;
196 - printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
197 - dev->name, dev->id, i);
201 - dev->msi_enabled = 0;
202 - printk(KERN_ERR "%s%d: MSIX not supported!! Will try MSI 0x%x.\n",
203 - dev->name, dev->id, i);
207 - if (!dev->msi_enabled) {
209 - i = pci_enable_msi(dev->pdev);
212 - dev->msi_enabled = 1;
215 - printk(KERN_ERR "%s%d: MSI not supported!! Will try INTx 0x%x.\n",
216 - dev->name, dev->id, i);
220 - if (!dev->msi_enabled)
221 - dev->max_msix = msi_count = 1;
223 - if (dev->max_msix > msi_count)
224 - dev->max_msix = msi_count;
227 - (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) /
230 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
231 index 9eec027..37375cf 100644
232 --- a/drivers/scsi/aacraid/linit.c
233 +++ b/drivers/scsi/aacraid/linit.c
234 @@ -1317,6 +1317,149 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
238 +#if (defined(CONFIG_PM))
239 +void aac_release_resources(struct aac_dev *aac)
243 + aac_adapter_disable_int(aac);
244 + if (aac->pdev->device == PMC_DEVICE_S6 ||
245 + aac->pdev->device == PMC_DEVICE_S7 ||
246 + aac->pdev->device == PMC_DEVICE_S8 ||
247 + aac->pdev->device == PMC_DEVICE_S9) {
248 + if (aac->max_msix > 1) {
249 + for (i = 0; i < aac->max_msix; i++)
250 + free_irq(aac->msixentry[i].vector,
251 + &(aac->aac_msix[i]));
253 + free_irq(aac->pdev->irq, &(aac->aac_msix[0]));
256 + free_irq(aac->pdev->irq, aac);
259 + pci_disable_msi(aac->pdev);
260 + else if (aac->max_msix > 1)
261 + pci_disable_msix(aac->pdev);
265 +static int aac_acquire_resources(struct aac_dev *dev)
268 + int instance = dev->id;
269 + const char *name = dev->name;
270 + unsigned long status;
272 + * First clear out all interrupts. Then enable the one's that we
275 + while (!((status = src_readl(dev, MUnit.OMR)) & KERNEL_UP_AND_RUNNING)
276 + || status == 0xffffffff)
279 + aac_adapter_disable_int(dev);
280 + aac_adapter_enable_int(dev);
283 + if ((dev->pdev->device == PMC_DEVICE_S7 ||
284 + dev->pdev->device == PMC_DEVICE_S8 ||
285 + dev->pdev->device == PMC_DEVICE_S9))
286 + aac_define_int_mode(dev);
288 + if (dev->msi_enabled)
289 + aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
291 + if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) {
292 + for (i = 0; i < dev->max_msix; i++) {
293 + dev->aac_msix[i].vector_no = i;
294 + dev->aac_msix[i].dev = dev;
296 + if (request_irq(dev->msixentry[i].vector,
297 + dev->a_ops.adapter_intr,
298 + 0, "aacraid", &(dev->aac_msix[i]))) {
299 + printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n",
300 + name, instance, i);
301 + for (j = 0 ; j < i ; j++)
302 + free_irq(dev->msixentry[j].vector,
303 + &(dev->aac_msix[j]));
304 + pci_disable_msix(dev->pdev);
305 + goto error_iounmap;
309 + dev->aac_msix[0].vector_no = 0;
310 + dev->aac_msix[0].dev = dev;
312 + if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
313 + IRQF_SHARED, "aacraid",
314 + &(dev->aac_msix[0])) < 0) {
316 + pci_disable_msi(dev->pdev);
317 + printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
319 + goto error_iounmap;
323 + aac_adapter_enable_int(dev);
325 + if (!dev->sync_mode)
326 + aac_adapter_start(dev);
333 +static int aac_suspend(struct pci_dev *pdev, pm_message_t state)
336 + struct Scsi_Host *shost = pci_get_drvdata(pdev);
337 + struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
339 + scsi_block_requests(shost);
340 + aac_send_shutdown(aac);
342 + aac_release_resources(aac);
344 + pci_set_drvdata(pdev, shost);
345 + pci_save_state(pdev);
346 + pci_disable_device(pdev);
347 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
352 +static int aac_resume(struct pci_dev *pdev)
354 + struct Scsi_Host *shost = pci_get_drvdata(pdev);
355 + struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
358 + pci_set_power_state(pdev, PCI_D0);
359 + pci_enable_wake(pdev, PCI_D0, 0);
360 + pci_restore_state(pdev);
361 + r = pci_enable_device(pdev);
366 + pci_set_master(pdev);
367 + if (aac_acquire_resources(aac))
369 + scsi_unblock_requests(shost);
374 + printk(KERN_INFO "%s%d: resume failed.\n", aac->name, aac->id);
375 + scsi_host_put(shost);
376 + pci_disable_device(pdev);
381 static void aac_shutdown(struct pci_dev *dev)
383 struct Scsi_Host *shost = pci_get_drvdata(dev);
384 @@ -1356,6 +1499,10 @@ static struct pci_driver aac_pci_driver = {
385 .id_table = aac_pci_tbl,
386 .probe = aac_probe_one,
387 .remove = aac_remove_one,
388 +#if (defined(CONFIG_PM))
389 + .suspend = aac_suspend,
390 + .resume = aac_resume,
392 .shutdown = aac_shutdown,
395 diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
396 index 9570612..ac16380 100644
397 --- a/drivers/scsi/aacraid/rx.c
398 +++ b/drivers/scsi/aacraid/rx.c
399 @@ -623,6 +623,7 @@ int _aac_rx_init(struct aac_dev *dev)
400 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
401 dev->a_ops.adapter_check_health = aac_rx_check_health;
402 dev->a_ops.adapter_restart = aac_rx_restart_adapter;
403 + dev->a_ops.adapter_start = aac_rx_start_adapter;
406 * First clear out all interrupts. Then enable the one's that we
407 diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
408 index e66477c..869aea2 100644
409 --- a/drivers/scsi/aacraid/sa.c
410 +++ b/drivers/scsi/aacraid/sa.c
411 @@ -372,6 +372,7 @@ int aac_sa_init(struct aac_dev *dev)
412 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
413 dev->a_ops.adapter_check_health = aac_sa_check_health;
414 dev->a_ops.adapter_restart = aac_sa_restart_adapter;
415 + dev->a_ops.adapter_start = aac_sa_start_adapter;
416 dev->a_ops.adapter_intr = aac_sa_intr;
417 dev->a_ops.adapter_deliver = aac_rx_deliver_producer;
418 dev->a_ops.adapter_ioremap = aac_sa_ioremap;
419 diff --git a/drivers/scsi/aacraid/src.c b/drivers/scsi/aacraid/src.c
420 index e63cf9f..b147341 100644
421 --- a/drivers/scsi/aacraid/src.c
422 +++ b/drivers/scsi/aacraid/src.c
423 @@ -726,6 +726,7 @@ int aac_src_init(struct aac_dev *dev)
424 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
425 dev->a_ops.adapter_check_health = aac_src_check_health;
426 dev->a_ops.adapter_restart = aac_src_restart_adapter;
427 + dev->a_ops.adapter_start = aac_src_start_adapter;
430 * First clear out all interrupts. Then enable the one's that we
431 @@ -892,6 +893,7 @@ int aac_srcv_init(struct aac_dev *dev)
432 dev->a_ops.adapter_sync_cmd = src_sync_cmd;
433 dev->a_ops.adapter_check_health = aac_src_check_health;
434 dev->a_ops.adapter_restart = aac_src_restart_adapter;
435 + dev->a_ops.adapter_start = aac_src_start_adapter;
438 * First clear out all interrupts. Then enable the one's that we