hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/scsi/gdth_proc.c
....@@ -31,7 +31,6 @@
3131 int i, found;
3232 gdth_cmd_str gdtcmd;
3333 gdth_cpar_str *pcpar;
34
- u64 paddr;
3534
3635 char cmnd[MAX_COMMAND_SIZE];
3736 memset(cmnd, 0xff, 12);
....@@ -113,13 +112,23 @@
113112 }
114113
115114 if (wb_mode) {
116
- if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr))
117
- return(-EBUSY);
115
+ unsigned long flags;
116
+
117
+ BUILD_BUG_ON(sizeof(gdth_cpar_str) > GDTH_SCRATCH);
118
+
119
+ spin_lock_irqsave(&ha->smp_lock, flags);
120
+ if (ha->scratch_busy) {
121
+ spin_unlock_irqrestore(&ha->smp_lock, flags);
122
+ return -EBUSY;
123
+ }
124
+ ha->scratch_busy = TRUE;
125
+ spin_unlock_irqrestore(&ha->smp_lock, flags);
126
+
118127 pcpar = (gdth_cpar_str *)ha->pscratch;
119128 memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
120129 gdtcmd.Service = CACHESERVICE;
121130 gdtcmd.OpCode = GDT_IOCTL;
122
- gdtcmd.u.ioctl.p_param = paddr;
131
+ gdtcmd.u.ioctl.p_param = ha->scratch_phys;
123132 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
124133 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
125134 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
....@@ -127,7 +136,10 @@
127136
128137 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
129138
130
- gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
139
+ spin_lock_irqsave(&ha->smp_lock, flags);
140
+ ha->scratch_busy = FALSE;
141
+ spin_unlock_irqrestore(&ha->smp_lock, flags);
142
+
131143 printk("Done.\n");
132144 return(orig_length);
133145 }
....@@ -143,7 +155,7 @@
143155 int id, i, j, k, sec, flag;
144156 int no_mdrv = 0, drv_no, is_mirr;
145157 u32 cnt;
146
- u64 paddr;
158
+ dma_addr_t paddr;
147159 int rc = -ENOMEM;
148160
149161 gdth_cmd_str *gdtcmd;
....@@ -181,7 +193,7 @@
181193 for (i = 1; i < MAX_RES_ARGS; i++) {
182194 if (reserve_list[i] == 0xff)
183195 break;
184
- hlen += snprintf(hrec + hlen , 161 - hlen, ",%d", reserve_list[i]);
196
+ hlen += scnprintf(hrec + hlen, 161 - hlen, ",%d", reserve_list[i]);
185197 }
186198 }
187199 seq_printf(m,
....@@ -217,20 +229,14 @@
217229 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
218230 ha->binfo.ser_no, ha->binfo.memsize / 1024);
219231
220
-#ifdef GDTH_DMA_STATISTICS
221
- /* controller statistics */
222
- seq_puts(m, "\nController Statistics:\n");
223
- seq_printf(m,
224
- " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",
225
- ha->dma32_cnt, ha->dma64_cnt);
226
-#endif
227
-
228232 if (ha->more_proc) {
233
+ size_t size = max_t(size_t, GDTH_SCRATCH, sizeof(gdth_hget_str));
234
+
229235 /* more information: 2. about physical devices */
230236 seq_puts(m, "\nPhysical Devices:");
231237 flag = FALSE;
232238
233
- buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
239
+ buf = dma_alloc_coherent(&ha->pdev->dev, size, &paddr, GFP_KERNEL);
234240 if (!buf)
235241 goto stop_output;
236242 for (i = 0; i < ha->bus_cnt; ++i) {
....@@ -323,7 +329,6 @@
323329 }
324330 }
325331 }
326
- gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
327332
328333 if (!flag)
329334 seq_puts(m, "\n --\n");
....@@ -332,9 +337,6 @@
332337 seq_puts(m, "\nLogical Drives:");
333338 flag = FALSE;
334339
335
- buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
336
- if (!buf)
337
- goto stop_output;
338340 for (i = 0; i < MAX_LDRIVES; ++i) {
339341 if (!ha->hdr[i].is_logdrv)
340342 continue;
....@@ -408,8 +410,7 @@
408410 seq_printf(m,
409411 " To Array Drv.:\t%s\n", hrec);
410412 }
411
- gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
412
-
413
+
413414 if (!flag)
414415 seq_puts(m, "\n --\n");
415416
....@@ -417,9 +418,6 @@
417418 seq_puts(m, "\nArray Drives:");
418419 flag = FALSE;
419420
420
- buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
421
- if (!buf)
422
- goto stop_output;
423421 for (i = 0; i < MAX_LDRIVES; ++i) {
424422 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
425423 continue;
....@@ -468,8 +466,7 @@
468466 hrec);
469467 }
470468 }
471
- gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
472
-
469
+
473470 if (!flag)
474471 seq_puts(m, "\n --\n");
475472
....@@ -477,9 +474,6 @@
477474 seq_puts(m, "\nHost Drives:");
478475 flag = FALSE;
479476
480
- buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, &paddr);
481
- if (!buf)
482
- goto stop_output;
483477 for (i = 0; i < MAX_LDRIVES; ++i) {
484478 if (!ha->hdr[i].is_logdrv ||
485479 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
....@@ -510,7 +504,7 @@
510504 }
511505 }
512506 }
513
- gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
507
+ dma_free_coherent(&ha->pdev->dev, size, buf, paddr);
514508
515509 for (i = 0; i < MAX_HDRIVES; ++i) {
516510 if (!(ha->hdr[i].present))
....@@ -562,65 +556,6 @@
562556 kfree(estr);
563557 return rc;
564558 }
565
-
566
-static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
567
- u64 *paddr)
568
-{
569
- unsigned long flags;
570
- char *ret_val;
571
-
572
- if (size == 0)
573
- return NULL;
574
-
575
- spin_lock_irqsave(&ha->smp_lock, flags);
576
-
577
- if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
578
- ha->scratch_busy = TRUE;
579
- ret_val = ha->pscratch;
580
- *paddr = ha->scratch_phys;
581
- } else if (scratch) {
582
- ret_val = NULL;
583
- } else {
584
- dma_addr_t dma_addr;
585
-
586
- ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
587
- *paddr = dma_addr;
588
- }
589
-
590
- spin_unlock_irqrestore(&ha->smp_lock, flags);
591
- return ret_val;
592
-}
593
-
594
-static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
595
-{
596
- unsigned long flags;
597
-
598
- if (buf == ha->pscratch) {
599
- spin_lock_irqsave(&ha->smp_lock, flags);
600
- ha->scratch_busy = FALSE;
601
- spin_unlock_irqrestore(&ha->smp_lock, flags);
602
- } else {
603
- pci_free_consistent(ha->pdev, size, buf, paddr);
604
- }
605
-}
606
-
607
-#ifdef GDTH_IOCTL_PROC
608
-static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
609
-{
610
- unsigned long flags;
611
- int ret_val;
612
-
613
- spin_lock_irqsave(&ha->smp_lock, flags);
614
-
615
- ret_val = FALSE;
616
- if (ha->scratch_busy) {
617
- if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
618
- ret_val = TRUE;
619
- }
620
- spin_unlock_irqrestore(&ha->smp_lock, flags);
621
- return ret_val;
622
-}
623
-#endif
624559
625560 static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
626561 {