hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/scsi/aacraid/aachba.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,25 +10,10 @@
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 * aachba.c
2815 *
2916 * Abstract: Contains Interfaces to manage IOs.
30
- *
3117 */
3218
3319 #include <linux/kernel.h>
....@@ -256,7 +242,7 @@
256242 int startup_timeout = 180;
257243 int aif_timeout = 120;
258244 int aac_sync_mode; /* Only Sync. transfer - disabled */
259
-int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
245
+static int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
260246
261247 module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
262248 MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
....@@ -304,7 +290,7 @@
304290 " blocks (FIB) allocated. Valid values are 512 and down. Default is"
305291 " to use suggestion from Firmware.");
306292
307
-int acbsize = -1;
293
+static int acbsize = -1;
308294 module_param(acbsize, int, S_IRUGO|S_IWUSR);
309295 MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
310296 " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
....@@ -335,7 +321,7 @@
335321 module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
336322 MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
337323
338
-int aac_wwn = 1;
324
+static int aac_wwn = 1;
339325 module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
340326 MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
341327 "\t0 - Disable\n"
....@@ -364,7 +350,8 @@
364350
365351 /**
366352 * aac_get_config_status - check the adapter configuration
367
- * @common: adapter to query
353
+ * @dev: aac driver data
354
+ * @commit_flag: force sending CT_COMMIT_CONFIG
368355 *
369356 * Query config status, and commit the configuration if needed.
370357 */
....@@ -456,7 +443,7 @@
456443
457444 /**
458445 * aac_get_containers - list containers
459
- * @common: adapter to probe
446
+ * @dev: aac driver data
460447 *
461448 * Make a list of all containers on this controller
462449 */
....@@ -549,7 +536,7 @@
549536 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
550537 && (get_name_reply->data[0] != '\0')) {
551538 char *sp = get_name_reply->data;
552
- int data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
539
+ int data_size = sizeof_field(struct aac_get_name_resp, data);
553540
554541 sp[data_size - 1] = '\0';
555542 while (*sp == ' ')
....@@ -575,7 +562,7 @@
575562 scsicmd->scsi_done(scsicmd);
576563 }
577564
578
-/**
565
+/*
579566 * aac_get_container_name - get container name, none blocking.
580567 */
581568 static int aac_get_container_name(struct scsi_cmnd * scsicmd)
....@@ -588,7 +575,7 @@
588575
589576 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
590577
591
- data_size = FIELD_SIZEOF(struct aac_get_name_resp, data);
578
+ data_size = sizeof_field(struct aac_get_name_resp, data);
592579
593580 cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
594581
....@@ -800,8 +787,7 @@
800787
801788 /**
802789 * aac_probe_container - query a logical volume
803
- * @dev: device to query
804
- * @cid: container identifier
790
+ * @scsicmd: the scsi command block
805791 *
806792 * Queries the controller about the given volume. The volume information
807793 * is updated in the struct fsa_dev_info structure rather than returned.
....@@ -810,6 +796,11 @@
810796 {
811797 scsicmd->device = NULL;
812798 return 0;
799
+}
800
+
801
+static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
802
+{
803
+ aac_probe_container_callback1(scsi_cmnd);
813804 }
814805
815806 int aac_probe_container(struct aac_dev *dev, int cid)
....@@ -823,8 +814,7 @@
823814 kfree(scsidev);
824815 return -ENOMEM;
825816 }
826
- scsicmd->list.next = NULL;
827
- scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1;
817
+ scsicmd->scsi_done = aac_probe_container_scsi_done;
828818
829819 scsicmd->device = scsidev;
830820 scsidev->sdev_state = 0;
....@@ -1108,7 +1098,7 @@
11081098 scsicmd->scsi_done(scsicmd);
11091099 }
11101100
1111
-/**
1101
+/*
11121102 * aac_get_container_serial - get container serial, none blocking.
11131103 */
11141104 static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
....@@ -1491,6 +1481,7 @@
14911481 struct aac_srb * srbcmd;
14921482 u32 flag;
14931483 u32 timeout;
1484
+ struct aac_dev *dev = fib->dev;
14941485
14951486 aac_fib_init(fib);
14961487 switch(cmd->sc_data_direction){
....@@ -1517,7 +1508,7 @@
15171508 srbcmd->flags = cpu_to_le32(flag);
15181509 timeout = cmd->request->timeout/HZ;
15191510 if (timeout == 0)
1520
- timeout = 1;
1511
+ timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
15211512 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
15221513 srbcmd->retry_limit = 0; /* Obsolete parameter */
15231514 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
....@@ -1961,8 +1952,6 @@
19611952 /**
19621953 * aac_set_safw_attr_all_targets- update current hba map with data from FW
19631954 * @dev: aac_dev structure
1964
- * @phys_luns: FW information from report phys luns
1965
- * @rescan: Indicates scan type
19661955 *
19671956 * Update our hba map with the information gathered from the FW
19681957 */
....@@ -2240,10 +2229,10 @@
22402229 }
22412230
22422231 if (dev->dac_support) {
2243
- if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(64))) {
2232
+ if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(64))) {
22442233 if (!dev->in_reset)
22452234 dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
2246
- } else if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(32))) {
2235
+ } else if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(32))) {
22472236 dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
22482237 dev->dac_support = 0;
22492238 } else {
....@@ -2614,9 +2603,7 @@
26142603 static void synchronize_callback(void *context, struct fib *fibptr)
26152604 {
26162605 struct aac_synchronize_reply *synchronizereply;
2617
- struct scsi_cmnd *cmd;
2618
-
2619
- cmd = context;
2606
+ struct scsi_cmnd *cmd = context;
26202607
26212608 if (!aac_valid_context(cmd, fibptr))
26222609 return;
....@@ -2657,77 +2644,8 @@
26572644 int status;
26582645 struct fib *cmd_fibcontext;
26592646 struct aac_synchronize *synchronizecmd;
2660
- struct scsi_cmnd *cmd;
26612647 struct scsi_device *sdev = scsicmd->device;
2662
- int active = 0;
26632648 struct aac_dev *aac;
2664
- u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) |
2665
- (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
2666
- u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
2667
- unsigned long flags;
2668
-
2669
- /*
2670
- * Wait for all outstanding queued commands to complete to this
2671
- * specific target (block).
2672
- */
2673
- spin_lock_irqsave(&sdev->list_lock, flags);
2674
- list_for_each_entry(cmd, &sdev->cmd_list, list)
2675
- if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
2676
- u64 cmnd_lba;
2677
- u32 cmnd_count;
2678
-
2679
- if (cmd->cmnd[0] == WRITE_6) {
2680
- cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) |
2681
- (cmd->cmnd[2] << 8) |
2682
- cmd->cmnd[3];
2683
- cmnd_count = cmd->cmnd[4];
2684
- if (cmnd_count == 0)
2685
- cmnd_count = 256;
2686
- } else if (cmd->cmnd[0] == WRITE_16) {
2687
- cmnd_lba = ((u64)cmd->cmnd[2] << 56) |
2688
- ((u64)cmd->cmnd[3] << 48) |
2689
- ((u64)cmd->cmnd[4] << 40) |
2690
- ((u64)cmd->cmnd[5] << 32) |
2691
- ((u64)cmd->cmnd[6] << 24) |
2692
- (cmd->cmnd[7] << 16) |
2693
- (cmd->cmnd[8] << 8) |
2694
- cmd->cmnd[9];
2695
- cmnd_count = (cmd->cmnd[10] << 24) |
2696
- (cmd->cmnd[11] << 16) |
2697
- (cmd->cmnd[12] << 8) |
2698
- cmd->cmnd[13];
2699
- } else if (cmd->cmnd[0] == WRITE_12) {
2700
- cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2701
- (cmd->cmnd[3] << 16) |
2702
- (cmd->cmnd[4] << 8) |
2703
- cmd->cmnd[5];
2704
- cmnd_count = (cmd->cmnd[6] << 24) |
2705
- (cmd->cmnd[7] << 16) |
2706
- (cmd->cmnd[8] << 8) |
2707
- cmd->cmnd[9];
2708
- } else if (cmd->cmnd[0] == WRITE_10) {
2709
- cmnd_lba = ((u64)cmd->cmnd[2] << 24) |
2710
- (cmd->cmnd[3] << 16) |
2711
- (cmd->cmnd[4] << 8) |
2712
- cmd->cmnd[5];
2713
- cmnd_count = (cmd->cmnd[7] << 8) |
2714
- cmd->cmnd[8];
2715
- } else
2716
- continue;
2717
- if (((cmnd_lba + cmnd_count) < lba) ||
2718
- (count && ((lba + count) < cmnd_lba)))
2719
- continue;
2720
- ++active;
2721
- break;
2722
- }
2723
-
2724
- spin_unlock_irqrestore(&sdev->list_lock, flags);
2725
-
2726
- /*
2727
- * Yield the processor (requeue for later)
2728
- */
2729
- if (active)
2730
- return SCSI_MLQUEUE_DEVICE_BUSY;
27312649
27322650 aac = (struct aac_dev *)sdev->host->hostdata;
27332651 if (aac->in_reset)
....@@ -2736,8 +2654,7 @@
27362654 /*
27372655 * Allocate and initialize a Fib
27382656 */
2739
- if (!(cmd_fibcontext = aac_fib_alloc(aac)))
2740
- return SCSI_MLQUEUE_HOST_BUSY;
2657
+ cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
27412658
27422659 aac_fib_init(cmd_fibcontext);
27432660
....@@ -2892,6 +2809,7 @@
28922809 !(dev->raw_io_64) ||
28932810 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
28942811 break;
2812
+ fallthrough;
28952813 case INQUIRY:
28962814 case READ_CAPACITY:
28972815 case TEST_UNIT_READY:
....@@ -2966,6 +2884,7 @@
29662884 /* Issue FIB to tell Firmware to flush it's cache */
29672885 if ((aac_cache & 6) != 2)
29682886 return aac_synchronize(scsicmd);
2887
+ fallthrough;
29692888 case INQUIRY:
29702889 {
29712890 struct inquiry_data inq_data;
....@@ -3319,8 +3238,9 @@
33193238 min_t(size_t,
33203239 sizeof(dev->fsa_dev[cid].sense_data),
33213240 SCSI_SENSE_BUFFERSIZE));
3322
- break;
3241
+ break;
33233242 }
3243
+ fallthrough;
33243244 case RESERVE:
33253245 case RELEASE:
33263246 case REZERO_UNIT:
....@@ -3333,7 +3253,6 @@
33333253 case START_STOP:
33343254 return aac_start_stop(scsicmd);
33353255
3336
- /* FALLTHRU */
33373256 default:
33383257 /*
33393258 * Unhandled commands
....@@ -3452,7 +3371,7 @@
34523371 }
34533372 }
34543373
3455
-int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg)
3374
+int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
34563375 {
34573376 switch (cmd) {
34583377 case FSACTL_QUERY_DISK:
....@@ -3469,18 +3388,14 @@
34693388 }
34703389
34713390 /**
3472
- *
34733391 * aac_srb_callback
34743392 * @context: the context set in the fib - here it is scsi cmd
34753393 * @fibptr: pointer to the fib
34763394 *
34773395 * Handles the completion of a scsi command to a non dasd device
3478
- *
34793396 */
3480
-
34813397 static void aac_srb_callback(void *context, struct fib * fibptr)
34823398 {
3483
- struct aac_dev *dev;
34843399 struct aac_srb_reply *srbreply;
34853400 struct scsi_cmnd *scsicmd;
34863401
....@@ -3490,8 +3405,6 @@
34903405 return;
34913406
34923407 BUG_ON(fibptr == NULL);
3493
-
3494
- dev = fibptr->dev;
34953408
34963409 srbreply = (struct aac_srb_reply *) fib_data(fibptr);
34973410
....@@ -3765,13 +3678,11 @@
37653678 }
37663679
37673680 /**
3768
- *
37693681 * aac_hba_callback
37703682 * @context: the context set in the fib - here it is scsi cmd
37713683 * @fibptr: pointer to the fib
37723684 *
37733685 * Handles the completion of a native HBA scsi command
3774
- *
37753686 */
37763687 void aac_hba_callback(void *context, struct fib *fibptr)
37773688 {
....@@ -3830,14 +3741,12 @@
38303741 }
38313742
38323743 /**
3833
- *
38343744 * aac_send_srb_fib
38353745 * @scsicmd: the scsi command block
38363746 *
38373747 * This routine will form a FIB and fill in the aac_srb from the
38383748 * scsicmd passed in.
38393749 */
3840
-
38413750 static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
38423751 {
38433752 struct fib* cmd_fibcontext;
....@@ -3873,7 +3782,6 @@
38733782 }
38743783
38753784 /**
3876
- *
38773785 * aac_send_hba_fib
38783786 * @scsicmd: the scsi command block
38793787 *
....@@ -3921,13 +3829,11 @@
39213829
39223830 static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
39233831 {
3924
- struct aac_dev *dev;
39253832 unsigned long byte_count = 0;
39263833 int nseg;
39273834 struct scatterlist *sg;
39283835 int i;
39293836
3930
- dev = (struct aac_dev *)scsicmd->device->host->hostdata;
39313837 // Get rid of old data
39323838 psg->count = 0;
39333839 psg->sg[0].addr = 0;
....@@ -3963,14 +3869,12 @@
39633869
39643870 static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
39653871 {
3966
- struct aac_dev *dev;
39673872 unsigned long byte_count = 0;
39683873 u64 addr;
39693874 int nseg;
39703875 struct scatterlist *sg;
39713876 int i;
39723877
3973
- dev = (struct aac_dev *)scsicmd->device->host->hostdata;
39743878 // Get rid of old data
39753879 psg->count = 0;
39763880 psg->sg[0].addr[0] = 0;