hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/aacraid/commsup.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Adaptec AAC series RAID controller driver
34 * (c) Copyright 2001 Red Hat Inc.
....@@ -9,26 +10,11 @@
910 * 2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
1011 * 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
1112 *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2, or (at your option)
15
- * any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program; see the file COPYING. If not, write to
24
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
- *
2613 * Module Name:
2714 * commsup.c
2815 *
2916 * Abstract: Contain all routines that are required for FSA host/adapter
3017 * communication.
31
- *
3218 */
3319
3420 #include <linux/kernel.h>
....@@ -44,7 +30,6 @@
4430 #include <linux/delay.h>
4531 #include <linux/kthread.h>
4632 #include <linux/interrupt.h>
47
-#include <linux/semaphore.h>
4833 #include <linux/bcd.h>
4934 #include <scsi/scsi.h>
5035 #include <scsi/scsi_host.h>
....@@ -189,7 +174,7 @@
189174 fibptr->hw_fib_va = hw_fib;
190175 fibptr->data = (void *) fibptr->hw_fib_va->data;
191176 fibptr->next = fibptr+1; /* Forward chain the fibs */
192
- sema_init(&fibptr->event_wait, 0);
177
+ init_completion(&fibptr->event_wait);
193178 spin_lock_init(&fibptr->event_lock);
194179 hw_fib->header.XferState = cpu_to_le32(0xffffffff);
195180 hw_fib->header.SenderSize =
....@@ -229,6 +214,7 @@
229214 /**
230215 * aac_fib_alloc_tag-allocate a fib using tags
231216 * @dev: Adapter to allocate the fib for
217
+ * @scmd: SCSI command
232218 *
233219 * Allocate a fib from the adapter fib pool using tags
234220 * from the blk layer.
....@@ -247,6 +233,7 @@
247233 fibptr->type = FSAFS_NTC_FIB_CONTEXT;
248234 fibptr->callback_data = NULL;
249235 fibptr->callback = NULL;
236
+ fibptr->flags = 0;
250237
251238 return fibptr;
252239 }
....@@ -419,8 +406,8 @@
419406 * aac_queue_get - get the next free QE
420407 * @dev: Adapter
421408 * @index: Returned index
422
- * @priority: Priority of fib
423
- * @fib: Fib to associate with the queue entry
409
+ * @qid: Queue number
410
+ * @hw_fib: Fib to associate with the queue entry
424411 * @wait: Wait if queue full
425412 * @fibptr: Driver fib object to go with fib
426413 * @nonotify: Don't notify the adapter
....@@ -623,7 +610,7 @@
623610 }
624611 if (wait) {
625612 fibptr->flags |= FIB_CONTEXT_FLAG_WAIT;
626
- if (down_interruptible(&fibptr->event_wait)) {
613
+ if (wait_for_completion_interruptible(&fibptr->event_wait)) {
627614 fibptr->flags &= ~FIB_CONTEXT_FLAG_WAIT;
628615 return -EFAULT;
629616 }
....@@ -659,7 +646,7 @@
659646 * hardware failure has occurred.
660647 */
661648 unsigned long timeout = jiffies + (180 * HZ); /* 3 minutes */
662
- while (down_trylock(&fibptr->event_wait)) {
649
+ while (!try_wait_for_completion(&fibptr->event_wait)) {
663650 int blink;
664651 if (time_is_before_eq_jiffies(timeout)) {
665652 struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue];
....@@ -689,9 +676,9 @@
689676 */
690677 schedule();
691678 }
692
- } else if (down_interruptible(&fibptr->event_wait)) {
679
+ } else if (wait_for_completion_interruptible(&fibptr->event_wait)) {
693680 /* Do nothing ... satisfy
694
- * down_interruptible must_check */
681
+ * wait_for_completion_interruptible must_check */
695682 }
696683
697684 spin_lock_irqsave(&fibptr->event_lock, flags);
....@@ -777,7 +764,7 @@
777764 return -EFAULT;
778765
779766 fibptr->flags |= FIB_CONTEXT_FLAG_WAIT;
780
- if (down_interruptible(&fibptr->event_wait))
767
+ if (wait_for_completion_interruptible(&fibptr->event_wait))
781768 fibptr->done = 2;
782769 fibptr->flags &= ~(FIB_CONTEXT_FLAG_WAIT);
783770
....@@ -948,7 +935,7 @@
948935
949936 /**
950937 * aac_fib_complete - fib completion handler
951
- * @fib: FIB to complete
938
+ * @fibptr: FIB to complete
952939 *
953940 * Will do all necessary work to complete a FIB.
954941 */
....@@ -1063,6 +1050,7 @@
10631050 }
10641051 }
10651052
1053
+#define AIF_SNIFF_TIMEOUT (500*HZ)
10661054 /**
10671055 * aac_handle_aif - Handle a message from the firmware
10681056 * @dev: Which adapter this fib is from
....@@ -1071,8 +1059,6 @@
10711059 * This routine handles a driver notify fib from the adapter and
10721060 * dispatches it to the appropriate routine for handling.
10731061 */
1074
-
1075
-#define AIF_SNIFF_TIMEOUT (500*HZ)
10761062 static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
10771063 {
10781064 struct hw_fib * hw_fib = fibptr->hw_fib_va;
....@@ -1378,18 +1364,19 @@
13781364
13791365 container = 0;
13801366 retry_next:
1381
- if (device_config_needed == NOTHING)
1382
- for (; container < dev->maximum_num_containers; ++container) {
1383
- if ((dev->fsa_dev[container].config_waiting_on == 0) &&
1384
- (dev->fsa_dev[container].config_needed != NOTHING) &&
1385
- time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
1386
- device_config_needed =
1387
- dev->fsa_dev[container].config_needed;
1388
- dev->fsa_dev[container].config_needed = NOTHING;
1389
- channel = CONTAINER_TO_CHANNEL(container);
1390
- id = CONTAINER_TO_ID(container);
1391
- lun = CONTAINER_TO_LUN(container);
1392
- break;
1367
+ if (device_config_needed == NOTHING) {
1368
+ for (; container < dev->maximum_num_containers; ++container) {
1369
+ if ((dev->fsa_dev[container].config_waiting_on == 0) &&
1370
+ (dev->fsa_dev[container].config_needed != NOTHING) &&
1371
+ time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
1372
+ device_config_needed =
1373
+ dev->fsa_dev[container].config_needed;
1374
+ dev->fsa_dev[container].config_needed = NOTHING;
1375
+ channel = CONTAINER_TO_CHANNEL(container);
1376
+ id = CONTAINER_TO_ID(container);
1377
+ lun = CONTAINER_TO_LUN(container);
1378
+ break;
1379
+ }
13931380 }
13941381 }
13951382 if (device_config_needed == NOTHING)
....@@ -1444,7 +1431,7 @@
14441431 "enclosure services event");
14451432 scsi_device_set_state(device, SDEV_RUNNING);
14461433 }
1447
- /* FALLTHRU */
1434
+ fallthrough;
14481435 case CHANGE:
14491436 if ((channel == CONTAINER_CHANNEL)
14501437 && (!dev->fsa_dev[container].valid)) {
....@@ -1477,14 +1464,19 @@
14771464 }
14781465 }
14791466
1467
+static void aac_schedule_bus_scan(struct aac_dev *aac)
1468
+{
1469
+ if (aac->sa_firmware)
1470
+ aac_schedule_safw_scan_worker(aac);
1471
+ else
1472
+ aac_schedule_src_reinit_aif_worker(aac);
1473
+}
1474
+
14801475 static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
14811476 {
14821477 int index, quirks;
14831478 int retval;
1484
- struct Scsi_Host *host;
1485
- struct scsi_device *dev;
1486
- struct scsi_cmnd *command;
1487
- struct scsi_cmnd *command_list;
1479
+ struct Scsi_Host *host = aac->scsi_host_ptr;
14881480 int jafo = 0;
14891481 int bled;
14901482 u64 dmamask;
....@@ -1500,8 +1492,6 @@
15001492 * - The card is dead, or will be very shortly ;-/ so no new
15011493 * commands are completing in the interrupt service.
15021494 */
1503
- host = aac->scsi_host_ptr;
1504
- scsi_block_requests(host);
15051495 aac_adapter_disable_int(aac);
15061496 if (aac->thread && aac->thread->pid != current->pid) {
15071497 spin_unlock_irq(host->host_lock);
....@@ -1539,7 +1529,7 @@
15391529 || fib->flags & FIB_CONTEXT_FLAG_WAIT) {
15401530 unsigned long flagv;
15411531 spin_lock_irqsave(&fib->event_lock, flagv);
1542
- up(&fib->event_wait);
1532
+ complete(&fib->event_wait);
15431533 spin_unlock_irqrestore(&fib->event_lock, flagv);
15441534 schedule();
15451535 retval = 0;
....@@ -1561,6 +1551,7 @@
15611551 aac_fib_map_free(aac);
15621552 dma_free_coherent(&aac->pdev->dev, aac->comm_size, aac->comm_addr,
15631553 aac->comm_phys);
1554
+ aac_adapter_ioremap(aac, 0);
15641555 aac->comm_addr = NULL;
15651556 aac->comm_phys = 0;
15661557 kfree(aac->queues);
....@@ -1571,15 +1562,15 @@
15711562 dmamask = DMA_BIT_MASK(32);
15721563 quirks = aac_get_driver_ident(index)->quirks;
15731564 if (quirks & AAC_QUIRK_31BIT)
1574
- retval = pci_set_dma_mask(aac->pdev, dmamask);
1565
+ retval = dma_set_mask(&aac->pdev->dev, dmamask);
15751566 else if (!(quirks & AAC_QUIRK_SRC))
1576
- retval = pci_set_dma_mask(aac->pdev, dmamask);
1567
+ retval = dma_set_mask(&aac->pdev->dev, dmamask);
15771568 else
1578
- retval = pci_set_consistent_dma_mask(aac->pdev, dmamask);
1569
+ retval = dma_set_coherent_mask(&aac->pdev->dev, dmamask);
15791570
15801571 if (quirks & AAC_QUIRK_31BIT && !retval) {
15811572 dmamask = DMA_BIT_MASK(31);
1582
- retval = pci_set_consistent_dma_mask(aac->pdev, dmamask);
1573
+ retval = dma_set_coherent_mask(&aac->pdev->dev, dmamask);
15831574 }
15841575
15851576 if (retval)
....@@ -1612,39 +1603,11 @@
16121603 * This is where the assumption that the Adapter is quiesced
16131604 * is important.
16141605 */
1615
- command_list = NULL;
1616
- __shost_for_each_device(dev, host) {
1617
- unsigned long flags;
1618
- spin_lock_irqsave(&dev->list_lock, flags);
1619
- list_for_each_entry(command, &dev->cmd_list, list)
1620
- if (command->SCp.phase == AAC_OWNER_FIRMWARE) {
1621
- command->SCp.buffer = (struct scatterlist *)command_list;
1622
- command_list = command;
1623
- }
1624
- spin_unlock_irqrestore(&dev->list_lock, flags);
1625
- }
1626
- while ((command = command_list)) {
1627
- command_list = (struct scsi_cmnd *)command->SCp.buffer;
1628
- command->SCp.buffer = NULL;
1629
- command->result = DID_OK << 16
1630
- | COMMAND_COMPLETE << 8
1631
- | SAM_STAT_TASK_SET_FULL;
1632
- command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
1633
- command->scsi_done(command);
1634
- }
1635
- /*
1636
- * Any Device that was already marked offline needs to be marked
1637
- * running
1638
- */
1639
- __shost_for_each_device(dev, host) {
1640
- if (!scsi_device_online(dev))
1641
- scsi_device_set_state(dev, SDEV_RUNNING);
1642
- }
1643
- retval = 0;
1606
+ scsi_host_complete_all_commands(host, DID_RESET);
16441607
1608
+ retval = 0;
16451609 out:
16461610 aac->in_reset = 0;
1647
- scsi_unblock_requests(host);
16481611
16491612 /*
16501613 * Issue bus rescan to catch any configuration that might have
....@@ -1652,7 +1615,7 @@
16521615 */
16531616 if (!retval && !is_kdump_kernel()) {
16541617 dev_info(&aac->pdev->dev, "Scheduling bus rescan\n");
1655
- aac_schedule_safw_scan_worker(aac);
1618
+ aac_schedule_bus_scan(aac);
16561619 }
16571620
16581621 if (jafo) {
....@@ -1664,8 +1627,8 @@
16641627 int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
16651628 {
16661629 unsigned long flagv = 0;
1667
- int retval;
1668
- struct Scsi_Host * host;
1630
+ int retval, unblock_retval;
1631
+ struct Scsi_Host *host = aac->scsi_host_ptr;
16691632 int bled;
16701633
16711634 if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0)
....@@ -1683,8 +1646,7 @@
16831646 * target (block maximum 60 seconds). Although not necessary,
16841647 * it does make us a good storage citizen.
16851648 */
1686
- host = aac->scsi_host_ptr;
1687
- scsi_block_requests(host);
1649
+ scsi_host_block(host);
16881650
16891651 /* Quiesce build, flush cache, write through mode */
16901652 if (forced < 2)
....@@ -1695,6 +1657,9 @@
16951657 retval = _aac_reset_adapter(aac, bled, reset_type);
16961658 spin_unlock_irqrestore(host->host_lock, flagv);
16971659
1660
+ unblock_retval = scsi_host_unblock(host, SDEV_RUNNING);
1661
+ if (!retval)
1662
+ retval = unblock_retval;
16981663 if ((forced < 2) && (retval == -ENODEV)) {
16991664 /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
17001665 struct fib * fibctx = aac_fib_alloc(aac);
....@@ -1829,7 +1794,7 @@
18291794 * Set the event to wake up the
18301795 * thread that will waiting.
18311796 */
1832
- up(&fibctx->wait_sem);
1797
+ complete(&fibctx->completion);
18331798 } else {
18341799 printk(KERN_WARNING "aifd: didn't allocate NewFib.\n");
18351800 kfree(fib);
....@@ -1971,6 +1936,16 @@
19711936 mutex_unlock(&dev->scan_mutex);
19721937
19731938 return rcode;
1939
+}
1940
+
1941
+void aac_src_reinit_aif_worker(struct work_struct *work)
1942
+{
1943
+ struct aac_dev *dev = container_of(to_delayed_work(work),
1944
+ struct aac_dev, src_reinit_aif_worker);
1945
+
1946
+ wait_event(dev->scsi_host_ptr->host_wait,
1947
+ !scsi_host_in_recovery(dev->scsi_host_ptr));
1948
+ aac_reinit_aif(dev, dev->cardtype);
19741949 }
19751950
19761951 /**
....@@ -2166,7 +2141,7 @@
21662141 * Set the event to wake up the
21672142 * thread that is waiting.
21682143 */
2169
- up(&fibctx->wait_sem);
2144
+ complete(&fibctx->completion);
21702145
21712146 entry = entry->next;
21722147 }
....@@ -2377,7 +2352,7 @@
23772352 goto out;
23782353 }
23792354
2380
-int aac_send_safw_hostttime(struct aac_dev *dev, struct timespec64 *now)
2355
+static int aac_send_safw_hostttime(struct aac_dev *dev, struct timespec64 *now)
23812356 {
23822357 struct tm cur_tm;
23832358 char wellness_str[] = "<HW>TD\010\0\0\0\0\0\0\0\0\0DW\0\0ZZ";
....@@ -2406,7 +2381,7 @@
24062381 return ret;
24072382 }
24082383
2409
-int aac_send_hosttime(struct aac_dev *dev, struct timespec64 *now)
2384
+static int aac_send_hosttime(struct aac_dev *dev, struct timespec64 *now)
24102385 {
24112386 int ret = -ENOMEM;
24122387 struct fib *fibptr;
....@@ -2442,7 +2417,7 @@
24422417
24432418 /**
24442419 * aac_command_thread - command processing thread
2445
- * @dev: Adapter to monitor
2420
+ * @data: Adapter to monitor
24462421 *
24472422 * Waits on the commandready event in it's queue. When the event gets set
24482423 * it will pull FIBs off it's queue. It will continue to pull FIBs off
....@@ -2587,9 +2562,7 @@
25872562 void aac_free_irq(struct aac_dev *dev)
25882563 {
25892564 int i;
2590
- int cpu;
25912565
2592
- cpu = cpumask_first(cpu_online_mask);
25932566 if (aac_is_src(dev)) {
25942567 if (dev->max_msix > 1) {
25952568 for (i = 0; i < dev->max_msix; i++)