hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/scsi/aacraid/commctrl.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 * commctrl.c
2815 *
2916 * Abstract: Contains all routines for control of the AFA comm layer
30
- *
3117 */
3218
3319 #include <linux/kernel.h>
....@@ -39,14 +25,16 @@
3925 #include <linux/completion.h>
4026 #include <linux/dma-mapping.h>
4127 #include <linux/blkdev.h>
28
+#include <linux/compat.h>
4229 #include <linux/delay.h> /* ssleep prototype */
4330 #include <linux/kthread.h>
44
-#include <linux/semaphore.h>
4531 #include <linux/uaccess.h>
4632 #include <scsi/scsi_host.h>
4733
4834 #include "aacraid.h"
4935
36
+# define AAC_DEBUG_PREAMBLE KERN_INFO
37
+# define AAC_DEBUG_POSTAMBLE
5038 /**
5139 * ioctl_send_fib - send a FIB from userspace
5240 * @dev: adapter is being processed
....@@ -55,9 +43,6 @@
5543 * This routine sends a fib to the adapter on behalf of a user level
5644 * program.
5745 */
58
-# define AAC_DEBUG_PREAMBLE KERN_INFO
59
-# define AAC_DEBUG_POSTAMBLE
60
-
6146 static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
6247 {
6348 struct hw_fib * kfib;
....@@ -173,11 +158,12 @@
173158
174159 /**
175160 * open_getadapter_fib - Get the next fib
161
+ * @dev: adapter is being processed
162
+ * @arg: arguments to the open call
176163 *
177164 * This routine will get the next Fib, if available, from the AdapterFibContext
178165 * passed in from the user.
179166 */
180
-
181167 static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
182168 {
183169 struct aac_fib_context * fibctx;
....@@ -203,7 +189,7 @@
203189 /*
204190 * Initialize the mutex used to wait for the next AIF.
205191 */
206
- sema_init(&fibctx->wait_sem, 0);
192
+ init_completion(&fibctx->completion);
207193 fibctx->wait = 0;
208194 /*
209195 * Initialize the fibs and set the count of fibs on
....@@ -241,6 +227,12 @@
241227 return status;
242228 }
243229
230
+struct compat_fib_ioctl {
231
+ u32 fibctx;
232
+ s32 wait;
233
+ compat_uptr_t fib;
234
+};
235
+
244236 /**
245237 * next_getadapter_fib - get the next fib
246238 * @dev: adapter to use
....@@ -249,7 +241,6 @@
249241 * This routine will get the next Fib, if available, from the AdapterFibContext
250242 * passed in from the user.
251243 */
252
-
253244 static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
254245 {
255246 struct fib_ioctl f;
....@@ -259,8 +250,19 @@
259250 struct list_head * entry;
260251 unsigned long flags;
261252
262
- if(copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
263
- return -EFAULT;
253
+ if (in_compat_syscall()) {
254
+ struct compat_fib_ioctl cf;
255
+
256
+ if (copy_from_user(&cf, arg, sizeof(struct compat_fib_ioctl)))
257
+ return -EFAULT;
258
+
259
+ f.fibctx = cf.fibctx;
260
+ f.wait = cf.wait;
261
+ f.fib = compat_ptr(cf.fib);
262
+ } else {
263
+ if (copy_from_user(&f, arg, sizeof(struct fib_ioctl)))
264
+ return -EFAULT;
265
+ }
264266 /*
265267 * Verify that the HANDLE passed in was a valid AdapterFibContext
266268 *
....@@ -335,7 +337,7 @@
335337 ssleep(1);
336338 }
337339 if (f.wait) {
338
- if(down_interruptible(&fibctx->wait_sem) < 0) {
340
+ if (wait_for_completion_interruptible(&fibctx->completion) < 0) {
339341 status = -ERESTARTSYS;
340342 } else {
341343 /* Lock again and retry */
....@@ -470,11 +472,10 @@
470472
471473
472474 /**
473
- *
474475 * aac_send_raw_scb
475
- *
476
+ * @dev: adapter is being processed
477
+ * @arg: arguments to the send call
476478 */
477
-
478479 static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
479480 {
480481 struct fib* srbfib;
....@@ -528,15 +529,10 @@
528529 goto cleanup;
529530 }
530531
531
- user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
532
- if (!user_srbcmd) {
533
- dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
534
- rcode = -ENOMEM;
535
- goto cleanup;
536
- }
537
- if(copy_from_user(user_srbcmd, user_srb,fibsize)){
538
- dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
539
- rcode = -EFAULT;
532
+ user_srbcmd = memdup_user(user_srb, fibsize);
533
+ if (IS_ERR(user_srbcmd)) {
534
+ rcode = PTR_ERR(user_srbcmd);
535
+ user_srbcmd = NULL;
540536 goto cleanup;
541537 }
542538
....@@ -692,8 +688,8 @@
692688 goto cleanup;
693689 }
694690 }
695
- addr = pci_map_single(dev->pdev, p, sg_count[i],
696
- data_dir);
691
+ addr = dma_map_single(&dev->pdev->dev, p, sg_count[i],
692
+ data_dir);
697693 hbacmd->sge[i].addr_hi = cpu_to_le32((u32)(addr>>32));
698694 hbacmd->sge[i].addr_lo = cpu_to_le32(
699695 (u32)(addr & 0xffffffff));
....@@ -754,8 +750,8 @@
754750 goto cleanup;
755751 }
756752 }
757
- addr = pci_map_single(dev->pdev, p,
758
- sg_count[i], data_dir);
753
+ addr = dma_map_single(&dev->pdev->dev, p,
754
+ sg_count[i], data_dir);
759755
760756 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
761757 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
....@@ -810,8 +806,8 @@
810806 goto cleanup;
811807 }
812808 }
813
- addr = pci_map_single(dev->pdev, p,
814
- sg_count[i], data_dir);
809
+ addr = dma_map_single(&dev->pdev->dev, p,
810
+ sg_count[i], data_dir);
815811
816812 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
817813 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
....@@ -866,7 +862,9 @@
866862 goto cleanup;
867863 }
868864 }
869
- addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
865
+ addr = dma_map_single(&dev->pdev->dev, p,
866
+ usg->sg[i].count,
867
+ data_dir);
870868
871869 psg->sg[i].addr = cpu_to_le32(addr & 0xffffffff);
872870 byte_count += usg->sg[i].count;
....@@ -905,8 +903,8 @@
905903 goto cleanup;
906904 }
907905 }
908
- addr = pci_map_single(dev->pdev, p,
909
- sg_count[i], data_dir);
906
+ addr = dma_map_single(&dev->pdev->dev, p,
907
+ sg_count[i], data_dir);
910908
911909 psg->sg[i].addr = cpu_to_le32(addr);
912910 byte_count += sg_count[i];
....@@ -1061,7 +1059,7 @@
10611059 return retval;
10621060 }
10631061
1064
-int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg)
1062
+int aac_do_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
10651063 {
10661064 int status;
10671065