forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/scsi/dpt_i2o.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /***************************************************************************
23 dpti.c - description
34 -------------------
....@@ -7,16 +8,12 @@
78 July 30, 2001 First version being submitted
89 for inclusion in the kernel. V2.4
910
10
- See Documentation/scsi/dpti.txt for history, notes, license info
11
+ See Documentation/scsi/dpti.rst for history, notes, license info
1112 and credits
1213 ***************************************************************************/
1314
1415 /***************************************************************************
1516 * *
16
- * This program is free software; you can redistribute it and/or modify *
17
- * it under the terms of the GNU General Public License as published by *
18
- * the Free Software Foundation; either version 2 of the License, or *
19
- * (at your option) any later version. *
2017 * *
2118 ***************************************************************************/
2219 /***************************************************************************
....@@ -30,6 +27,7 @@
3027 /*#define UARTDELAY 1 */
3128
3229 #include <linux/module.h>
30
+#include <linux/pgtable.h>
3331
3432 MODULE_AUTHOR("Deanna Bonds, with _lots_ of help from Mark Salyzyn");
3533 MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
....@@ -58,7 +56,6 @@
5856 #include <linux/mutex.h>
5957
6058 #include <asm/processor.h> /* for boot_cpu_data */
61
-#include <asm/pgtable.h>
6259 #include <asm/io.h> /* for virt_to_bus, etc. */
6360
6461 #include <scsi/scsi.h>
....@@ -411,9 +408,6 @@
411408 static int adpt_slave_configure(struct scsi_device * device)
412409 {
413410 struct Scsi_Host *host = device->host;
414
- adpt_hba* pHba;
415
-
416
- pHba = (adpt_hba *) host->hostdata[0];
417411
418412 if (host->can_queue && device->tagged_supported) {
419413 scsi_change_queue_depth(device,
....@@ -589,46 +583,6 @@
589583 }
590584
591585 /*
592
- * Turn a struct scsi_cmnd * into a unique 32 bit 'context'.
593
- */
594
-static u32 adpt_cmd_to_context(struct scsi_cmnd *cmd)
595
-{
596
- return (u32)cmd->serial_number;
597
-}
598
-
599
-/*
600
- * Go from a u32 'context' to a struct scsi_cmnd * .
601
- * This could probably be made more efficient.
602
- */
603
-static struct scsi_cmnd *
604
- adpt_cmd_from_context(adpt_hba * pHba, u32 context)
605
-{
606
- struct scsi_cmnd * cmd;
607
- struct scsi_device * d;
608
-
609
- if (context == 0)
610
- return NULL;
611
-
612
- spin_unlock(pHba->host->host_lock);
613
- shost_for_each_device(d, pHba->host) {
614
- unsigned long flags;
615
- spin_lock_irqsave(&d->list_lock, flags);
616
- list_for_each_entry(cmd, &d->cmd_list, list) {
617
- if (((u32)cmd->serial_number == context)) {
618
- spin_unlock_irqrestore(&d->list_lock, flags);
619
- scsi_device_put(d);
620
- spin_lock(pHba->host->host_lock);
621
- return cmd;
622
- }
623
- }
624
- spin_unlock_irqrestore(&d->list_lock, flags);
625
- }
626
- spin_lock(pHba->host->host_lock);
627
-
628
- return NULL;
629
-}
630
-
631
-/*
632586 * Turn a pointer to ioctl reply data into an u32 'context'
633587 */
634588 static u32 adpt_ioctl_to_context(adpt_hba * pHba, void *reply)
....@@ -685,9 +639,6 @@
685639 u32 msg[5];
686640 int rcode;
687641
688
- if(cmd->serial_number == 0){
689
- return FAILED;
690
- }
691642 pHba = (adpt_hba*) cmd->device->host->hostdata[0];
692643 printk(KERN_INFO"%s: Trying to Abort\n",pHba->name);
693644 if ((dptdevice = (void*) (cmd->device->hostdata)) == NULL) {
....@@ -699,8 +650,9 @@
699650 msg[0] = FIVE_WORD_MSG_SIZE|SGL_OFFSET_0;
700651 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid;
701652 msg[2] = 0;
702
- msg[3]= 0;
703
- msg[4] = adpt_cmd_to_context(cmd);
653
+ msg[3]= 0;
654
+ /* Add 1 to avoid firmware treating it as invalid command */
655
+ msg[4] = cmd->request->tag + 1;
704656 if (pHba->host)
705657 spin_lock_irq(pHba->host->host_lock);
706658 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER);
....@@ -862,7 +814,7 @@
862814 }
863815 pHba->state &= ~DPTI_STATE_RESET;
864816
865
- adpt_fail_posted_scbs(pHba);
817
+ scsi_host_complete_all_commands(pHba->host, DID_RESET);
866818 return 0; /* return success */
867819 }
868820
....@@ -877,8 +829,8 @@
877829 adpt_hba *pHba, *pNext;
878830 struct adpt_i2o_post_wait_data *p1, *old;
879831
880
- printk(KERN_INFO"Shutting down Adaptec I2O controllers.\n");
881
- printk(KERN_INFO" This could take a few minutes if there are many devices attached\n");
832
+ printk(KERN_INFO "Shutting down Adaptec I2O controllers.\n");
833
+ printk(KERN_INFO " This could take a few minutes if there are many devices attached\n");
882834 /* Delete all IOPs from the controller chain */
883835 /* They should have already been released by the
884836 * scsi-core
....@@ -901,7 +853,7 @@
901853 // spin_unlock_irqrestore(&adpt_post_wait_lock, flags);
902854 adpt_post_wait_queue = NULL;
903855
904
- printk(KERN_INFO "Adaptec I2O controllers down.\n");
856
+ printk(KERN_INFO "Adaptec I2O controllers down.\n");
905857 }
906858
907859 static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
....@@ -934,15 +886,15 @@
934886 * See if we should enable dma64 mode.
935887 */
936888 if (sizeof(dma_addr_t) > 4 &&
937
- pci_set_dma_mask(pDev, DMA_BIT_MASK(64)) == 0) {
938
- if (dma_get_required_mask(&pDev->dev) > DMA_BIT_MASK(32))
939
- dma64 = 1;
940
- }
941
- if (!dma64 && pci_set_dma_mask(pDev, DMA_BIT_MASK(32)) != 0)
889
+ dma_get_required_mask(&pDev->dev) > DMA_BIT_MASK(32) &&
890
+ dma_set_mask(&pDev->dev, DMA_BIT_MASK(64)) == 0)
891
+ dma64 = 1;
892
+
893
+ if (!dma64 && dma_set_mask(&pDev->dev, DMA_BIT_MASK(32)) != 0)
942894 return -EINVAL;
943895
944896 /* adapter only supports message blocks below 4GB */
945
- pci_set_consistent_dma_mask(pDev, DMA_BIT_MASK(32));
897
+ dma_set_coherent_mask(&pDev->dev, DMA_BIT_MASK(32));
946898
947899 base_addr0_phys = pci_resource_start(pDev,0);
948900 hba_map0_area_size = pci_resource_len(pDev,0);
....@@ -1165,7 +1117,7 @@
11651117 {
11661118 struct adpt_device* d;
11671119
1168
- if(chan < 0 || chan >= MAX_CHANNEL)
1120
+ if (chan >= MAX_CHANNEL)
11691121 return NULL;
11701122
11711123 d = pHba->channel[chan].device[id];
....@@ -1376,7 +1328,6 @@
13761328 printk(KERN_ERR"IOP reset failed - no free memory.\n");
13771329 return -ENOMEM;
13781330 }
1379
- memset(status,0,4);
13801331
13811332 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
13821333 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
....@@ -2198,20 +2149,27 @@
21982149 status = I2O_POST_WAIT_OK;
21992150 }
22002151 if(!(context & 0x40000000)) {
2201
- cmd = adpt_cmd_from_context(pHba,
2202
- readl(reply+12));
2152
+ /*
2153
+ * The request tag is one less than the command tag
2154
+ * as the firmware might treat a 0 tag as invalid
2155
+ */
2156
+ cmd = scsi_host_find_tag(pHba->host,
2157
+ readl(reply + 12) - 1);
22032158 if(cmd != NULL) {
22042159 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
22052160 }
22062161 }
22072162 adpt_i2o_post_wait_complete(context, status);
22082163 } else { // SCSI message
2209
- cmd = adpt_cmd_from_context (pHba, readl(reply+12));
2164
+ /*
2165
+ * The request tag is one less than the command tag
2166
+ * as the firmware might treat a 0 tag as invalid
2167
+ */
2168
+ cmd = scsi_host_find_tag(pHba->host,
2169
+ readl(reply + 12) - 1);
22102170 if(cmd != NULL){
22112171 scsi_dma_unmap(cmd);
2212
- if(cmd->serial_number != 0) { // If not timedout
2213
- adpt_i2o_to_scsi(reply, cmd);
2214
- }
2172
+ adpt_i2o_scsi_complete(reply, cmd);
22152173 }
22162174 }
22172175 writel(m, pHba->reply_port);
....@@ -2277,7 +2235,8 @@
22772235 // I2O_CMD_SCSI_EXEC
22782236 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
22792237 msg[2] = 0;
2280
- msg[3] = adpt_cmd_to_context(cmd); /* Want SCSI control block back */
2238
+ /* Add 1 to avoid firmware treating it as invalid command */
2239
+ msg[3] = cmd->request->tag + 1;
22812240 // Our cards use the transaction context as the tag for queueing
22822241 // Adaptec/DPT Private stuff
22832242 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
....@@ -2372,13 +2331,12 @@
23722331 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
23732332 host->sg_tablesize = pHba->sg_tablesize;
23742333 host->can_queue = pHba->post_fifo_size;
2375
- host->use_cmd_list = 1;
23762334
23772335 return 0;
23782336 }
23792337
23802338
2381
-static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
2339
+static void adpt_i2o_scsi_complete(void __iomem *reply, struct scsi_cmnd *cmd)
23822340 {
23832341 adpt_hba* pHba;
23842342 u32 hba_status;
....@@ -2496,7 +2454,6 @@
24962454 if(cmd->scsi_done != NULL){
24972455 cmd->scsi_done(cmd);
24982456 }
2499
- return cmd->result;
25002457 }
25012458
25022459
....@@ -2684,26 +2641,6 @@
26842641 return 0;
26852642 }
26862643
2687
-static void adpt_fail_posted_scbs(adpt_hba* pHba)
2688
-{
2689
- struct scsi_cmnd* cmd = NULL;
2690
- struct scsi_device* d = NULL;
2691
-
2692
- shost_for_each_device(d, pHba->host) {
2693
- unsigned long flags;
2694
- spin_lock_irqsave(&d->list_lock, flags);
2695
- list_for_each_entry(cmd, &d->cmd_list, list) {
2696
- if(cmd->serial_number == 0){
2697
- continue;
2698
- }
2699
- cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
2700
- cmd->scsi_done(cmd);
2701
- }
2702
- spin_unlock_irqrestore(&d->list_lock, flags);
2703
- }
2704
-}
2705
-
2706
-
27072644 /*============================================================================
27082645 * Routines from i2o subsystem
27092646 *============================================================================
....@@ -2843,7 +2780,6 @@
28432780 pHba->name);
28442781 return -ENOMEM;
28452782 }
2846
- memset(status, 0, 4);
28472783
28482784 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
28492785 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
....@@ -2897,7 +2833,6 @@
28972833 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
28982834 return -ENOMEM;
28992835 }
2900
- memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4);
29012836
29022837 for(i = 0; i < pHba->reply_fifo_size; i++) {
29032838 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
....@@ -3132,7 +3067,6 @@
31323067 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
31333068 return -ENOMEM;
31343069 }
3135
- memset(sys_tbl, 0, sys_tbl_len);
31363070
31373071 sys_tbl->num_entries = hba_count;
31383072 sys_tbl->version = I2OVERSION;
....@@ -3427,7 +3361,7 @@
34273361 return -((res[1] >> 16) & 0xFF); /* -BlockStatus */
34283362 }
34293363
3430
- return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
3364
+ return 4 + ((res[1] & 0x0000FFFF) << 2); /* bytes used in resblk */
34313365 }
34323366
34333367
....@@ -3500,8 +3434,8 @@
35003434
35013435 static int adpt_i2o_systab_send(adpt_hba* pHba)
35023436 {
3503
- u32 msg[12];
3504
- int ret;
3437
+ u32 msg[12];
3438
+ int ret;
35053439
35063440 msg[0] = I2O_MESSAGE_SIZE(12) | SGL_OFFSET_6;
35073441 msg[1] = I2O_CMD_SYS_TAB_SET<<24 | HOST_TID<<12 | ADAPTER_TID;
....@@ -3569,7 +3503,6 @@
35693503 .slave_configure = adpt_slave_configure,
35703504 .can_queue = MAX_TO_IOP_MESSAGES,
35713505 .this_id = 7,
3572
- .use_clustering = ENABLE_CLUSTERING,
35733506 };
35743507
35753508 static int __init adpt_init(void)