hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/misc/genwqe/card_utils.c
....@@ -1,4 +1,5 @@
1
-/**
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/*
23 * IBM Accelerator Family 'GenWQE'
34 *
45 * (C) Copyright IBM Corp. 2013
....@@ -7,15 +8,6 @@
78 * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
89 * Author: Michael Jung <mijung@gmx.net>
910 * Author: Michael Ruettger <michael@ibmra.de>
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License (version 2 only)
13
- * as published by the Free Software Foundation.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
1911 */
2012
2113 /*
....@@ -23,21 +15,19 @@
2315 */
2416
2517 #include <linux/kernel.h>
26
-#include <linux/dma-mapping.h>
2718 #include <linux/sched.h>
2819 #include <linux/vmalloc.h>
2920 #include <linux/page-flags.h>
3021 #include <linux/scatterlist.h>
3122 #include <linux/hugetlb.h>
3223 #include <linux/iommu.h>
33
-#include <linux/delay.h>
3424 #include <linux/pci.h>
3525 #include <linux/dma-mapping.h>
3626 #include <linux/ctype.h>
3727 #include <linux/module.h>
3828 #include <linux/platform_device.h>
3929 #include <linux/delay.h>
40
-#include <asm/pgtable.h>
30
+#include <linux/pgtable.h>
4131
4232 #include "genwqe_driver.h"
4333 #include "card_base.h"
....@@ -139,6 +129,9 @@
139129
140130 /**
141131 * genwqe_read_app_id() - Extract app_id
132
+ * @cd: genwqe device descriptor
133
+ * @app_name: carrier used to pass-back name
134
+ * @len: length of data for name
142135 *
143136 * app_unitcfg need to be filled with valid data first
144137 */
....@@ -193,7 +186,7 @@
193186 * @init: initial crc (0xffffffff at start)
194187 *
195188 * polynomial = x^32 * + x^29 + x^18 + x^14 + x^3 + 1 (0x20044009)
196
-
189
+ *
197190 * Example: 4 bytes 0x01 0x02 0x03 0x04 with init=0xffffffff should
198191 * result in a crc32 of 0xf33cb7d3.
199192 *
....@@ -220,8 +213,8 @@
220213 if (get_order(size) >= MAX_ORDER)
221214 return NULL;
222215
223
- return dma_zalloc_coherent(&cd->pci_dev->dev, size, dma_handle,
224
- GFP_KERNEL);
216
+ return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle,
217
+ GFP_KERNEL);
225218 }
226219
227220 void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size,
....@@ -287,7 +280,7 @@
287280 return roundup(len, PAGE_SIZE);
288281 }
289282
290
-/**
283
+/*
291284 * genwqe_alloc_sync_sgl() - Allocate memory for sgl and overlapping pages
292285 *
293286 * Allocates memory for sgl and overlapping pages. Pages which might
....@@ -470,6 +463,8 @@
470463
471464 /**
472465 * genwqe_free_sync_sgl() - Free memory for sgl and overlapping pages
466
+ * @cd: genwqe device descriptor
467
+ * @sgl: scatter gather list describing user-space memory
473468 *
474469 * After the DMA transfer has been completed we free the memory for
475470 * the sgl and the cached pages. Data is being transferred from cached
....@@ -522,30 +517,6 @@
522517 sgl->sgl_dma_addr = 0x0;
523518 sgl->sgl_size = 0;
524519 return rc;
525
-}
526
-
527
-/**
528
- * genwqe_free_user_pages() - Give pinned pages back
529
- *
530
- * Documentation of get_user_pages is in mm/gup.c:
531
- *
532
- * If the page is written to, set_page_dirty (or set_page_dirty_lock,
533
- * as appropriate) must be called after the page is finished with, and
534
- * before put_page is called.
535
- */
536
-static int genwqe_free_user_pages(struct page **page_list,
537
- unsigned int nr_pages, int dirty)
538
-{
539
- unsigned int i;
540
-
541
- for (i = 0; i < nr_pages; i++) {
542
- if (page_list[i] != NULL) {
543
- if (dirty)
544
- set_page_dirty_lock(page_list[i]);
545
- put_page(page_list[i]);
546
- }
547
- }
548
- return 0;
549520 }
550521
551522 /**
....@@ -607,18 +578,18 @@
607578 m->dma_list = (dma_addr_t *)(m->page_list + m->nr_pages);
608579
609580 /* pin user pages in memory */
610
- rc = get_user_pages_fast(data & PAGE_MASK, /* page aligned addr */
581
+ rc = pin_user_pages_fast(data & PAGE_MASK, /* page aligned addr */
611582 m->nr_pages,
612
- m->write, /* readable/writable */
583
+ m->write ? FOLL_WRITE : 0, /* readable/writable */
613584 m->page_list); /* ptrs to pages */
614585 if (rc < 0)
615
- goto fail_get_user_pages;
586
+ goto fail_pin_user_pages;
616587
617
- /* assumption: get_user_pages can be killed by signals. */
588
+ /* assumption: pin_user_pages can be killed by signals. */
618589 if (rc < m->nr_pages) {
619
- genwqe_free_user_pages(m->page_list, rc, m->write);
590
+ unpin_user_pages_dirty_lock(m->page_list, rc, m->write);
620591 rc = -EFAULT;
621
- goto fail_get_user_pages;
592
+ goto fail_pin_user_pages;
622593 }
623594
624595 rc = genwqe_map_pages(cd, m->page_list, m->nr_pages, m->dma_list);
....@@ -628,9 +599,9 @@
628599 return 0;
629600
630601 fail_free_user_pages:
631
- genwqe_free_user_pages(m->page_list, m->nr_pages, m->write);
602
+ unpin_user_pages_dirty_lock(m->page_list, m->nr_pages, m->write);
632603
633
- fail_get_user_pages:
604
+ fail_pin_user_pages:
634605 kfree(m->page_list);
635606 m->page_list = NULL;
636607 m->dma_list = NULL;
....@@ -660,8 +631,8 @@
660631 genwqe_unmap_pages(cd, m->dma_list, m->nr_pages);
661632
662633 if (m->page_list) {
663
- genwqe_free_user_pages(m->page_list, m->nr_pages, m->write);
664
-
634
+ unpin_user_pages_dirty_lock(m->page_list, m->nr_pages,
635
+ m->write);
665636 kfree(m->page_list);
666637 m->page_list = NULL;
667638 m->dma_list = NULL;
....@@ -744,6 +715,7 @@
744715 /**
745716 * genwqe_set_interrupt_capability() - Configure MSI capability structure
746717 * @cd: pointer to the device
718
+ * @count: number of vectors to allocate
747719 * Return: 0 if no error
748720 */
749721 int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count)
....@@ -772,7 +744,7 @@
772744 * @i: index to desired entry
773745 * @m: maximum possible entries
774746 * @addr: addr which is read
775
- * @index: index in debug array
747
+ * @idx: index in debug array
776748 * @val: read value
777749 */
778750 static int set_reg_idx(struct genwqe_dev *cd, struct genwqe_reg *r,
....@@ -852,6 +824,8 @@
852824
853825 /**
854826 * genwqe_ffdc_buff_size() - Calculates the number of dump registers
827
+ * @cd: genwqe device descriptor
828
+ * @uid: unit ID
855829 */
856830 int genwqe_ffdc_buff_size(struct genwqe_dev *cd, int uid)
857831 {
....@@ -905,6 +879,10 @@
905879
906880 /**
907881 * genwqe_ffdc_buff_read() - Implements LogoutExtendedErrorRegisters procedure
882
+ * @cd: genwqe device descriptor
883
+ * @uid: unit ID
884
+ * @regs: register information
885
+ * @max_regs: number of register entries
908886 */
909887 int genwqe_ffdc_buff_read(struct genwqe_dev *cd, int uid,
910888 struct genwqe_reg *regs, unsigned int max_regs)
....@@ -990,6 +968,10 @@
990968
991969 /**
992970 * genwqe_write_vreg() - Write register in virtual window
971
+ * @cd: genwqe device descriptor
972
+ * @reg: register (byte) offset within BAR
973
+ * @val: value to write
974
+ * @func: PCI virtual function
993975 *
994976 * Note, these registers are only accessible to the PF through the
995977 * VF-window. It is not intended for the VF to access.
....@@ -1003,6 +985,9 @@
1003985
1004986 /**
1005987 * genwqe_read_vreg() - Read register in virtual window
988
+ * @cd: genwqe device descriptor
989
+ * @reg: register (byte) offset within BAR
990
+ * @func: PCI virtual function
1006991 *
1007992 * Note, these registers are only accessible to the PF through the
1008993 * VF-window. It is not intended for the VF to access.
....@@ -1015,6 +1000,7 @@
10151000
10161001 /**
10171002 * genwqe_base_clock_frequency() - Deteremine base clock frequency of the card
1003
+ * @cd: genwqe device descriptor
10181004 *
10191005 * Note: From a design perspective it turned out to be a bad idea to
10201006 * use codes here to specifiy the frequency/speed values. An old
....@@ -1039,6 +1025,7 @@
10391025
10401026 /**
10411027 * genwqe_stop_traps() - Stop traps
1028
+ * @cd: genwqe device descriptor
10421029 *
10431030 * Before reading out the analysis data, we need to stop the traps.
10441031 */
....@@ -1049,6 +1036,7 @@
10491036
10501037 /**
10511038 * genwqe_start_traps() - Start traps
1039
+ * @cd: genwqe device descriptor
10521040 *
10531041 * After having read the data, we can/must enable the traps again.
10541042 */