167f4addbSFrank Haverkamp /** 267f4addbSFrank Haverkamp * IBM Accelerator Family 'GenWQE' 367f4addbSFrank Haverkamp * 467f4addbSFrank Haverkamp * (C) Copyright IBM Corp. 2013 567f4addbSFrank Haverkamp * 667f4addbSFrank Haverkamp * Author: Frank Haverkamp <haver@linux.vnet.ibm.com> 767f4addbSFrank Haverkamp * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com> 826d8f6f1SFrank Haverkamp * Author: Michael Jung <mijung@gmx.net> 967f4addbSFrank Haverkamp * Author: Michael Ruettger <michael@ibmra.de> 1067f4addbSFrank Haverkamp * 1167f4addbSFrank Haverkamp * This program is free software; you can redistribute it and/or modify 1267f4addbSFrank Haverkamp * it under the terms of the GNU General Public License (version 2 only) 1367f4addbSFrank Haverkamp * as published by the Free Software Foundation. 1467f4addbSFrank Haverkamp * 1567f4addbSFrank Haverkamp * This program is distributed in the hope that it will be useful, 1667f4addbSFrank Haverkamp * but WITHOUT ANY WARRANTY; without even the implied warranty of 1767f4addbSFrank Haverkamp * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1867f4addbSFrank Haverkamp * GNU General Public License for more details. 1967f4addbSFrank Haverkamp */ 2067f4addbSFrank Haverkamp 2167f4addbSFrank Haverkamp /* 2267f4addbSFrank Haverkamp * Miscelanous functionality used in the other GenWQE driver parts. 2367f4addbSFrank Haverkamp */ 2467f4addbSFrank Haverkamp 2567f4addbSFrank Haverkamp #include <linux/kernel.h> 2667f4addbSFrank Haverkamp #include <linux/dma-mapping.h> 2767f4addbSFrank Haverkamp #include <linux/sched.h> 2867f4addbSFrank Haverkamp #include <linux/vmalloc.h> 2967f4addbSFrank Haverkamp #include <linux/page-flags.h> 3067f4addbSFrank Haverkamp #include <linux/scatterlist.h> 3167f4addbSFrank Haverkamp #include <linux/hugetlb.h> 3267f4addbSFrank Haverkamp #include <linux/iommu.h> 3367f4addbSFrank Haverkamp #include <linux/delay.h> 3467f4addbSFrank Haverkamp #include <linux/pci.h> 3567f4addbSFrank Haverkamp #include <linux/dma-mapping.h> 3667f4addbSFrank Haverkamp #include <linux/ctype.h> 3767f4addbSFrank Haverkamp #include <linux/module.h> 3867f4addbSFrank Haverkamp #include <linux/platform_device.h> 3967f4addbSFrank Haverkamp #include <linux/delay.h> 4067f4addbSFrank Haverkamp #include <asm/pgtable.h> 4167f4addbSFrank Haverkamp 4267f4addbSFrank Haverkamp #include "genwqe_driver.h" 4367f4addbSFrank Haverkamp #include "card_base.h" 4467f4addbSFrank Haverkamp #include "card_ddcb.h" 4567f4addbSFrank Haverkamp 4667f4addbSFrank Haverkamp /** 4767f4addbSFrank Haverkamp * __genwqe_writeq() - Write 64-bit register 4867f4addbSFrank Haverkamp * @cd: genwqe device descriptor 4967f4addbSFrank Haverkamp * @byte_offs: byte offset within BAR 5067f4addbSFrank Haverkamp * @val: 64-bit value 5167f4addbSFrank Haverkamp * 5267f4addbSFrank Haverkamp * Return: 0 if success; < 0 if error 5367f4addbSFrank Haverkamp */ 5467f4addbSFrank Haverkamp int __genwqe_writeq(struct genwqe_dev *cd, u64 byte_offs, u64 val) 5567f4addbSFrank Haverkamp { 56fb145456SKleber Sacilotto de Souza struct pci_dev *pci_dev = cd->pci_dev; 57fb145456SKleber Sacilotto de Souza 5867f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 5967f4addbSFrank Haverkamp return -EIO; 6067f4addbSFrank Haverkamp 6167f4addbSFrank Haverkamp if (cd->mmio == NULL) 6267f4addbSFrank Haverkamp return -EIO; 6367f4addbSFrank Haverkamp 64fb145456SKleber Sacilotto de Souza if (pci_channel_offline(pci_dev)) 65fb145456SKleber Sacilotto de Souza return -EIO; 66fb145456SKleber Sacilotto de Souza 67a45a0258SFrank Haverkamp __raw_writeq((__force u64)cpu_to_be64(val), cd->mmio + byte_offs); 6867f4addbSFrank Haverkamp return 0; 6967f4addbSFrank Haverkamp } 7067f4addbSFrank Haverkamp 7167f4addbSFrank Haverkamp /** 7267f4addbSFrank Haverkamp * __genwqe_readq() - Read 64-bit register 7367f4addbSFrank Haverkamp * @cd: genwqe device descriptor 7467f4addbSFrank Haverkamp * @byte_offs: offset within BAR 7567f4addbSFrank Haverkamp * 7667f4addbSFrank Haverkamp * Return: value from register 7767f4addbSFrank Haverkamp */ 7867f4addbSFrank Haverkamp u64 __genwqe_readq(struct genwqe_dev *cd, u64 byte_offs) 7967f4addbSFrank Haverkamp { 8067f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 8167f4addbSFrank Haverkamp return 0xffffffffffffffffull; 8267f4addbSFrank Haverkamp 8367f4addbSFrank Haverkamp if ((cd->err_inject & GENWQE_INJECT_GFIR_FATAL) && 8467f4addbSFrank Haverkamp (byte_offs == IO_SLC_CFGREG_GFIR)) 8567f4addbSFrank Haverkamp return 0x000000000000ffffull; 8667f4addbSFrank Haverkamp 8767f4addbSFrank Haverkamp if ((cd->err_inject & GENWQE_INJECT_GFIR_INFO) && 8867f4addbSFrank Haverkamp (byte_offs == IO_SLC_CFGREG_GFIR)) 8967f4addbSFrank Haverkamp return 0x00000000ffff0000ull; 9067f4addbSFrank Haverkamp 9167f4addbSFrank Haverkamp if (cd->mmio == NULL) 9267f4addbSFrank Haverkamp return 0xffffffffffffffffull; 9367f4addbSFrank Haverkamp 9458d66ce7SFrank Haverkamp return be64_to_cpu((__force __be64)__raw_readq(cd->mmio + byte_offs)); 9567f4addbSFrank Haverkamp } 9667f4addbSFrank Haverkamp 9767f4addbSFrank Haverkamp /** 9867f4addbSFrank Haverkamp * __genwqe_writel() - Write 32-bit register 9967f4addbSFrank Haverkamp * @cd: genwqe device descriptor 10067f4addbSFrank Haverkamp * @byte_offs: byte offset within BAR 10167f4addbSFrank Haverkamp * @val: 32-bit value 10267f4addbSFrank Haverkamp * 10367f4addbSFrank Haverkamp * Return: 0 if success; < 0 if error 10467f4addbSFrank Haverkamp */ 10567f4addbSFrank Haverkamp int __genwqe_writel(struct genwqe_dev *cd, u64 byte_offs, u32 val) 10667f4addbSFrank Haverkamp { 107fb145456SKleber Sacilotto de Souza struct pci_dev *pci_dev = cd->pci_dev; 108fb145456SKleber Sacilotto de Souza 10967f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 11067f4addbSFrank Haverkamp return -EIO; 11167f4addbSFrank Haverkamp 11267f4addbSFrank Haverkamp if (cd->mmio == NULL) 11367f4addbSFrank Haverkamp return -EIO; 11467f4addbSFrank Haverkamp 115fb145456SKleber Sacilotto de Souza if (pci_channel_offline(pci_dev)) 116fb145456SKleber Sacilotto de Souza return -EIO; 117fb145456SKleber Sacilotto de Souza 11858d66ce7SFrank Haverkamp __raw_writel((__force u32)cpu_to_be32(val), cd->mmio + byte_offs); 11967f4addbSFrank Haverkamp return 0; 12067f4addbSFrank Haverkamp } 12167f4addbSFrank Haverkamp 12267f4addbSFrank Haverkamp /** 12367f4addbSFrank Haverkamp * __genwqe_readl() - Read 32-bit register 12467f4addbSFrank Haverkamp * @cd: genwqe device descriptor 12567f4addbSFrank Haverkamp * @byte_offs: offset within BAR 12667f4addbSFrank Haverkamp * 12767f4addbSFrank Haverkamp * Return: Value from register 12867f4addbSFrank Haverkamp */ 12967f4addbSFrank Haverkamp u32 __genwqe_readl(struct genwqe_dev *cd, u64 byte_offs) 13067f4addbSFrank Haverkamp { 13167f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 13267f4addbSFrank Haverkamp return 0xffffffff; 13367f4addbSFrank Haverkamp 13467f4addbSFrank Haverkamp if (cd->mmio == NULL) 13567f4addbSFrank Haverkamp return 0xffffffff; 13667f4addbSFrank Haverkamp 13758d66ce7SFrank Haverkamp return be32_to_cpu((__force __be32)__raw_readl(cd->mmio + byte_offs)); 13867f4addbSFrank Haverkamp } 13967f4addbSFrank Haverkamp 14067f4addbSFrank Haverkamp /** 14167f4addbSFrank Haverkamp * genwqe_read_app_id() - Extract app_id 14267f4addbSFrank Haverkamp * 14367f4addbSFrank Haverkamp * app_unitcfg need to be filled with valid data first 14467f4addbSFrank Haverkamp */ 14567f4addbSFrank Haverkamp int genwqe_read_app_id(struct genwqe_dev *cd, char *app_name, int len) 14667f4addbSFrank Haverkamp { 14767f4addbSFrank Haverkamp int i, j; 14867f4addbSFrank Haverkamp u32 app_id = (u32)cd->app_unitcfg; 14967f4addbSFrank Haverkamp 15067f4addbSFrank Haverkamp memset(app_name, 0, len); 15167f4addbSFrank Haverkamp for (i = 0, j = 0; j < min(len, 4); j++) { 15267f4addbSFrank Haverkamp char ch = (char)((app_id >> (24 - j*8)) & 0xff); 153d9c11d45SFrank Haverkamp 15467f4addbSFrank Haverkamp if (ch == ' ') 15567f4addbSFrank Haverkamp continue; 15667f4addbSFrank Haverkamp app_name[i++] = isprint(ch) ? ch : 'X'; 15767f4addbSFrank Haverkamp } 15867f4addbSFrank Haverkamp return i; 15967f4addbSFrank Haverkamp } 16067f4addbSFrank Haverkamp 16167f4addbSFrank Haverkamp /** 16267f4addbSFrank Haverkamp * genwqe_init_crc32() - Prepare a lookup table for fast crc32 calculations 16367f4addbSFrank Haverkamp * 16467f4addbSFrank Haverkamp * Existing kernel functions seem to use a different polynom, 16567f4addbSFrank Haverkamp * therefore we could not use them here. 16667f4addbSFrank Haverkamp * 16767f4addbSFrank Haverkamp * Genwqe's Polynomial = 0x20044009 16867f4addbSFrank Haverkamp */ 16967f4addbSFrank Haverkamp #define CRC32_POLYNOMIAL 0x20044009 17067f4addbSFrank Haverkamp static u32 crc32_tab[256]; /* crc32 lookup table */ 17167f4addbSFrank Haverkamp 17267f4addbSFrank Haverkamp void genwqe_init_crc32(void) 17367f4addbSFrank Haverkamp { 17467f4addbSFrank Haverkamp int i, j; 17567f4addbSFrank Haverkamp u32 crc; 17667f4addbSFrank Haverkamp 17767f4addbSFrank Haverkamp for (i = 0; i < 256; i++) { 17867f4addbSFrank Haverkamp crc = i << 24; 17967f4addbSFrank Haverkamp for (j = 0; j < 8; j++) { 18067f4addbSFrank Haverkamp if (crc & 0x80000000) 18167f4addbSFrank Haverkamp crc = (crc << 1) ^ CRC32_POLYNOMIAL; 18267f4addbSFrank Haverkamp else 18367f4addbSFrank Haverkamp crc = (crc << 1); 18467f4addbSFrank Haverkamp } 18567f4addbSFrank Haverkamp crc32_tab[i] = crc; 18667f4addbSFrank Haverkamp } 18767f4addbSFrank Haverkamp } 18867f4addbSFrank Haverkamp 18967f4addbSFrank Haverkamp /** 19067f4addbSFrank Haverkamp * genwqe_crc32() - Generate 32-bit crc as required for DDCBs 19167f4addbSFrank Haverkamp * @buff: pointer to data buffer 19267f4addbSFrank Haverkamp * @len: length of data for calculation 19367f4addbSFrank Haverkamp * @init: initial crc (0xffffffff at start) 19467f4addbSFrank Haverkamp * 19567f4addbSFrank Haverkamp * polynomial = x^32 * + x^29 + x^18 + x^14 + x^3 + 1 (0x20044009) 19667f4addbSFrank Haverkamp 19767f4addbSFrank Haverkamp * Example: 4 bytes 0x01 0x02 0x03 0x04 with init=0xffffffff should 19867f4addbSFrank Haverkamp * result in a crc32 of 0xf33cb7d3. 19967f4addbSFrank Haverkamp * 20067f4addbSFrank Haverkamp * The existing kernel crc functions did not cover this polynom yet. 20167f4addbSFrank Haverkamp * 20267f4addbSFrank Haverkamp * Return: crc32 checksum. 20367f4addbSFrank Haverkamp */ 20467f4addbSFrank Haverkamp u32 genwqe_crc32(u8 *buff, size_t len, u32 init) 20567f4addbSFrank Haverkamp { 20667f4addbSFrank Haverkamp int i; 20767f4addbSFrank Haverkamp u32 crc; 20867f4addbSFrank Haverkamp 20967f4addbSFrank Haverkamp crc = init; 21067f4addbSFrank Haverkamp while (len--) { 21167f4addbSFrank Haverkamp i = ((crc >> 24) ^ *buff++) & 0xFF; 21267f4addbSFrank Haverkamp crc = (crc << 8) ^ crc32_tab[i]; 21367f4addbSFrank Haverkamp } 21467f4addbSFrank Haverkamp return crc; 21567f4addbSFrank Haverkamp } 21667f4addbSFrank Haverkamp 21767f4addbSFrank Haverkamp void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size, 21867f4addbSFrank Haverkamp dma_addr_t *dma_handle) 21967f4addbSFrank Haverkamp { 22067f4addbSFrank Haverkamp if (get_order(size) > MAX_ORDER) 22167f4addbSFrank Haverkamp return NULL; 22267f4addbSFrank Haverkamp 223*19f7767eSSebastian Ott return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle, 224*19f7767eSSebastian Ott GFP_KERNEL); 22567f4addbSFrank Haverkamp } 22667f4addbSFrank Haverkamp 22767f4addbSFrank Haverkamp void __genwqe_free_consistent(struct genwqe_dev *cd, size_t size, 22867f4addbSFrank Haverkamp void *vaddr, dma_addr_t dma_handle) 22967f4addbSFrank Haverkamp { 23067f4addbSFrank Haverkamp if (vaddr == NULL) 23167f4addbSFrank Haverkamp return; 23267f4addbSFrank Haverkamp 233*19f7767eSSebastian Ott dma_free_coherent(&cd->pci_dev->dev, size, vaddr, dma_handle); 23467f4addbSFrank Haverkamp } 23567f4addbSFrank Haverkamp 23667f4addbSFrank Haverkamp static void genwqe_unmap_pages(struct genwqe_dev *cd, dma_addr_t *dma_list, 23767f4addbSFrank Haverkamp int num_pages) 23867f4addbSFrank Haverkamp { 23967f4addbSFrank Haverkamp int i; 24067f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 24167f4addbSFrank Haverkamp 24267f4addbSFrank Haverkamp for (i = 0; (i < num_pages) && (dma_list[i] != 0x0); i++) { 24367f4addbSFrank Haverkamp pci_unmap_page(pci_dev, dma_list[i], 24467f4addbSFrank Haverkamp PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 24567f4addbSFrank Haverkamp dma_list[i] = 0x0; 24667f4addbSFrank Haverkamp } 24767f4addbSFrank Haverkamp } 24867f4addbSFrank Haverkamp 24967f4addbSFrank Haverkamp static int genwqe_map_pages(struct genwqe_dev *cd, 25067f4addbSFrank Haverkamp struct page **page_list, int num_pages, 25167f4addbSFrank Haverkamp dma_addr_t *dma_list) 25267f4addbSFrank Haverkamp { 25367f4addbSFrank Haverkamp int i; 25467f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 25567f4addbSFrank Haverkamp 25667f4addbSFrank Haverkamp /* establish DMA mapping for requested pages */ 25767f4addbSFrank Haverkamp for (i = 0; i < num_pages; i++) { 25867f4addbSFrank Haverkamp dma_addr_t daddr; 25967f4addbSFrank Haverkamp 26067f4addbSFrank Haverkamp dma_list[i] = 0x0; 26167f4addbSFrank Haverkamp daddr = pci_map_page(pci_dev, page_list[i], 26267f4addbSFrank Haverkamp 0, /* map_offs */ 26367f4addbSFrank Haverkamp PAGE_SIZE, 26467f4addbSFrank Haverkamp PCI_DMA_BIDIRECTIONAL); /* FIXME rd/rw */ 26567f4addbSFrank Haverkamp 26667f4addbSFrank Haverkamp if (pci_dma_mapping_error(pci_dev, daddr)) { 26767f4addbSFrank Haverkamp dev_err(&pci_dev->dev, 26867f4addbSFrank Haverkamp "[%s] err: no dma addr daddr=%016llx!\n", 26967f4addbSFrank Haverkamp __func__, (long long)daddr); 27067f4addbSFrank Haverkamp goto err; 27167f4addbSFrank Haverkamp } 27267f4addbSFrank Haverkamp 27367f4addbSFrank Haverkamp dma_list[i] = daddr; 27467f4addbSFrank Haverkamp } 27567f4addbSFrank Haverkamp return 0; 27667f4addbSFrank Haverkamp 27767f4addbSFrank Haverkamp err: 27867f4addbSFrank Haverkamp genwqe_unmap_pages(cd, dma_list, num_pages); 27967f4addbSFrank Haverkamp return -EIO; 28067f4addbSFrank Haverkamp } 28167f4addbSFrank Haverkamp 28267f4addbSFrank Haverkamp static int genwqe_sgl_size(int num_pages) 28367f4addbSFrank Haverkamp { 28467f4addbSFrank Haverkamp int len, num_tlb = num_pages / 7; 28567f4addbSFrank Haverkamp 28667f4addbSFrank Haverkamp len = sizeof(struct sg_entry) * (num_pages+num_tlb + 1); 28767f4addbSFrank Haverkamp return roundup(len, PAGE_SIZE); 28867f4addbSFrank Haverkamp } 28967f4addbSFrank Haverkamp 290718f762eSFrank Haverkamp /** 291718f762eSFrank Haverkamp * genwqe_alloc_sync_sgl() - Allocate memory for sgl and overlapping pages 292718f762eSFrank Haverkamp * 293718f762eSFrank Haverkamp * Allocates memory for sgl and overlapping pages. Pages which might 294718f762eSFrank Haverkamp * overlap other user-space memory blocks are being cached for DMAs, 295718f762eSFrank Haverkamp * such that we do not run into syncronization issues. Data is copied 296718f762eSFrank Haverkamp * from user-space into the cached pages. 297718f762eSFrank Haverkamp */ 298718f762eSFrank Haverkamp int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, 299718f762eSFrank Haverkamp void __user *user_addr, size_t user_size) 30067f4addbSFrank Haverkamp { 301718f762eSFrank Haverkamp int rc; 30267f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 30367f4addbSFrank Haverkamp 304718f762eSFrank Haverkamp sgl->fpage_offs = offset_in_page((unsigned long)user_addr); 305718f762eSFrank Haverkamp sgl->fpage_size = min_t(size_t, PAGE_SIZE-sgl->fpage_offs, user_size); 306718f762eSFrank Haverkamp sgl->nr_pages = DIV_ROUND_UP(sgl->fpage_offs + user_size, PAGE_SIZE); 307718f762eSFrank Haverkamp sgl->lpage_size = (user_size - sgl->fpage_size) % PAGE_SIZE; 308718f762eSFrank Haverkamp 309d9c11d45SFrank Haverkamp dev_dbg(&pci_dev->dev, "[%s] uaddr=%p usize=%8ld nr_pages=%ld fpage_offs=%lx fpage_size=%ld lpage_size=%ld\n", 310718f762eSFrank Haverkamp __func__, user_addr, user_size, sgl->nr_pages, 311718f762eSFrank Haverkamp sgl->fpage_offs, sgl->fpage_size, sgl->lpage_size); 312718f762eSFrank Haverkamp 313718f762eSFrank Haverkamp sgl->user_addr = user_addr; 314718f762eSFrank Haverkamp sgl->user_size = user_size; 315718f762eSFrank Haverkamp sgl->sgl_size = genwqe_sgl_size(sgl->nr_pages); 316718f762eSFrank Haverkamp 317718f762eSFrank Haverkamp if (get_order(sgl->sgl_size) > MAX_ORDER) { 31867f4addbSFrank Haverkamp dev_err(&pci_dev->dev, 31967f4addbSFrank Haverkamp "[%s] err: too much memory requested!\n", __func__); 320718f762eSFrank Haverkamp return -ENOMEM; 32167f4addbSFrank Haverkamp } 32267f4addbSFrank Haverkamp 323718f762eSFrank Haverkamp sgl->sgl = __genwqe_alloc_consistent(cd, sgl->sgl_size, 324718f762eSFrank Haverkamp &sgl->sgl_dma_addr); 325718f762eSFrank Haverkamp if (sgl->sgl == NULL) { 32667f4addbSFrank Haverkamp dev_err(&pci_dev->dev, 32767f4addbSFrank Haverkamp "[%s] err: no memory available!\n", __func__); 328718f762eSFrank Haverkamp return -ENOMEM; 32967f4addbSFrank Haverkamp } 33067f4addbSFrank Haverkamp 331718f762eSFrank Haverkamp /* Only use buffering on incomplete pages */ 332718f762eSFrank Haverkamp if ((sgl->fpage_size != 0) && (sgl->fpage_size != PAGE_SIZE)) { 333718f762eSFrank Haverkamp sgl->fpage = __genwqe_alloc_consistent(cd, PAGE_SIZE, 334718f762eSFrank Haverkamp &sgl->fpage_dma_addr); 335718f762eSFrank Haverkamp if (sgl->fpage == NULL) 336718f762eSFrank Haverkamp goto err_out; 337718f762eSFrank Haverkamp 338718f762eSFrank Haverkamp /* Sync with user memory */ 339718f762eSFrank Haverkamp if (copy_from_user(sgl->fpage + sgl->fpage_offs, 340718f762eSFrank Haverkamp user_addr, sgl->fpage_size)) { 341718f762eSFrank Haverkamp rc = -EFAULT; 342718f762eSFrank Haverkamp goto err_out; 343718f762eSFrank Haverkamp } 344718f762eSFrank Haverkamp } 345718f762eSFrank Haverkamp if (sgl->lpage_size != 0) { 346718f762eSFrank Haverkamp sgl->lpage = __genwqe_alloc_consistent(cd, PAGE_SIZE, 347718f762eSFrank Haverkamp &sgl->lpage_dma_addr); 348718f762eSFrank Haverkamp if (sgl->lpage == NULL) 349718f762eSFrank Haverkamp goto err_out1; 350718f762eSFrank Haverkamp 351718f762eSFrank Haverkamp /* Sync with user memory */ 352718f762eSFrank Haverkamp if (copy_from_user(sgl->lpage, user_addr + user_size - 353718f762eSFrank Haverkamp sgl->lpage_size, sgl->lpage_size)) { 354718f762eSFrank Haverkamp rc = -EFAULT; 355718f762eSFrank Haverkamp goto err_out1; 356718f762eSFrank Haverkamp } 357718f762eSFrank Haverkamp } 358718f762eSFrank Haverkamp return 0; 359718f762eSFrank Haverkamp 360718f762eSFrank Haverkamp err_out1: 361718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, 362718f762eSFrank Haverkamp sgl->fpage_dma_addr); 363718f762eSFrank Haverkamp err_out: 364718f762eSFrank Haverkamp __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl, 365718f762eSFrank Haverkamp sgl->sgl_dma_addr); 366718f762eSFrank Haverkamp return -ENOMEM; 36767f4addbSFrank Haverkamp } 36867f4addbSFrank Haverkamp 369718f762eSFrank Haverkamp int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, 370718f762eSFrank Haverkamp dma_addr_t *dma_list) 37167f4addbSFrank Haverkamp { 37267f4addbSFrank Haverkamp int i = 0, j = 0, p; 37367f4addbSFrank Haverkamp unsigned long dma_offs, map_offs; 37467f4addbSFrank Haverkamp dma_addr_t prev_daddr = 0; 37567f4addbSFrank Haverkamp struct sg_entry *s, *last_s = NULL; 376718f762eSFrank Haverkamp size_t size = sgl->user_size; 37767f4addbSFrank Haverkamp 37867f4addbSFrank Haverkamp dma_offs = 128; /* next block if needed/dma_offset */ 379718f762eSFrank Haverkamp map_offs = sgl->fpage_offs; /* offset in first page */ 38067f4addbSFrank Haverkamp 381718f762eSFrank Haverkamp s = &sgl->sgl[0]; /* first set of 8 entries */ 38267f4addbSFrank Haverkamp p = 0; /* page */ 383718f762eSFrank Haverkamp while (p < sgl->nr_pages) { 38467f4addbSFrank Haverkamp dma_addr_t daddr; 38567f4addbSFrank Haverkamp unsigned int size_to_map; 38667f4addbSFrank Haverkamp 38767f4addbSFrank Haverkamp /* always write the chaining entry, cleanup is done later */ 38867f4addbSFrank Haverkamp j = 0; 389718f762eSFrank Haverkamp s[j].target_addr = cpu_to_be64(sgl->sgl_dma_addr + dma_offs); 39067f4addbSFrank Haverkamp s[j].len = cpu_to_be32(128); 39167f4addbSFrank Haverkamp s[j].flags = cpu_to_be32(SG_CHAINED); 39267f4addbSFrank Haverkamp j++; 39367f4addbSFrank Haverkamp 39467f4addbSFrank Haverkamp while (j < 8) { 39567f4addbSFrank Haverkamp /* DMA mapping for requested page, offs, size */ 39667f4addbSFrank Haverkamp size_to_map = min(size, PAGE_SIZE - map_offs); 397718f762eSFrank Haverkamp 398718f762eSFrank Haverkamp if ((p == 0) && (sgl->fpage != NULL)) { 399718f762eSFrank Haverkamp daddr = sgl->fpage_dma_addr + map_offs; 400718f762eSFrank Haverkamp 401718f762eSFrank Haverkamp } else if ((p == sgl->nr_pages - 1) && 402718f762eSFrank Haverkamp (sgl->lpage != NULL)) { 403718f762eSFrank Haverkamp daddr = sgl->lpage_dma_addr; 404718f762eSFrank Haverkamp } else { 405718f762eSFrank Haverkamp daddr = dma_list[p] + map_offs; 406718f762eSFrank Haverkamp } 407718f762eSFrank Haverkamp 40867f4addbSFrank Haverkamp size -= size_to_map; 40967f4addbSFrank Haverkamp map_offs = 0; 41067f4addbSFrank Haverkamp 41167f4addbSFrank Haverkamp if (prev_daddr == daddr) { 41267f4addbSFrank Haverkamp u32 prev_len = be32_to_cpu(last_s->len); 41367f4addbSFrank Haverkamp 41467f4addbSFrank Haverkamp /* pr_info("daddr combining: " 41567f4addbSFrank Haverkamp "%016llx/%08x -> %016llx\n", 41667f4addbSFrank Haverkamp prev_daddr, prev_len, daddr); */ 41767f4addbSFrank Haverkamp 41867f4addbSFrank Haverkamp last_s->len = cpu_to_be32(prev_len + 41967f4addbSFrank Haverkamp size_to_map); 42067f4addbSFrank Haverkamp 42167f4addbSFrank Haverkamp p++; /* process next page */ 422718f762eSFrank Haverkamp if (p == sgl->nr_pages) 42367f4addbSFrank Haverkamp goto fixup; /* nothing to do */ 42467f4addbSFrank Haverkamp 42567f4addbSFrank Haverkamp prev_daddr = daddr + size_to_map; 42667f4addbSFrank Haverkamp continue; 42767f4addbSFrank Haverkamp } 42867f4addbSFrank Haverkamp 42967f4addbSFrank Haverkamp /* start new entry */ 43067f4addbSFrank Haverkamp s[j].target_addr = cpu_to_be64(daddr); 43167f4addbSFrank Haverkamp s[j].len = cpu_to_be32(size_to_map); 43267f4addbSFrank Haverkamp s[j].flags = cpu_to_be32(SG_DATA); 43367f4addbSFrank Haverkamp prev_daddr = daddr + size_to_map; 43467f4addbSFrank Haverkamp last_s = &s[j]; 43567f4addbSFrank Haverkamp j++; 43667f4addbSFrank Haverkamp 43767f4addbSFrank Haverkamp p++; /* process next page */ 438718f762eSFrank Haverkamp if (p == sgl->nr_pages) 43967f4addbSFrank Haverkamp goto fixup; /* nothing to do */ 44067f4addbSFrank Haverkamp } 44167f4addbSFrank Haverkamp dma_offs += 128; 44267f4addbSFrank Haverkamp s += 8; /* continue 8 elements further */ 44367f4addbSFrank Haverkamp } 44467f4addbSFrank Haverkamp fixup: 44567f4addbSFrank Haverkamp if (j == 1) { /* combining happend on last entry! */ 44667f4addbSFrank Haverkamp s -= 8; /* full shift needed on previous sgl block */ 44767f4addbSFrank Haverkamp j = 7; /* shift all elements */ 44867f4addbSFrank Haverkamp } 44967f4addbSFrank Haverkamp 45067f4addbSFrank Haverkamp for (i = 0; i < j; i++) /* move elements 1 up */ 45167f4addbSFrank Haverkamp s[i] = s[i + 1]; 45267f4addbSFrank Haverkamp 45367f4addbSFrank Haverkamp s[i].target_addr = cpu_to_be64(0); 45467f4addbSFrank Haverkamp s[i].len = cpu_to_be32(0); 45567f4addbSFrank Haverkamp s[i].flags = cpu_to_be32(SG_END_LIST); 45667f4addbSFrank Haverkamp return 0; 45767f4addbSFrank Haverkamp } 45867f4addbSFrank Haverkamp 459718f762eSFrank Haverkamp /** 460718f762eSFrank Haverkamp * genwqe_free_sync_sgl() - Free memory for sgl and overlapping pages 461718f762eSFrank Haverkamp * 462718f762eSFrank Haverkamp * After the DMA transfer has been completed we free the memory for 463718f762eSFrank Haverkamp * the sgl and the cached pages. Data is being transfered from cached 464718f762eSFrank Haverkamp * pages into user-space buffers. 465718f762eSFrank Haverkamp */ 466718f762eSFrank Haverkamp int genwqe_free_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl) 46767f4addbSFrank Haverkamp { 46863fa80cdSChristian Engelmayer int rc = 0; 469718f762eSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 470718f762eSFrank Haverkamp 471718f762eSFrank Haverkamp if (sgl->fpage) { 472718f762eSFrank Haverkamp if (copy_to_user(sgl->user_addr, sgl->fpage + sgl->fpage_offs, 473718f762eSFrank Haverkamp sgl->fpage_size)) { 474718f762eSFrank Haverkamp dev_err(&pci_dev->dev, "[%s] err: copying fpage!\n", 475718f762eSFrank Haverkamp __func__); 476718f762eSFrank Haverkamp rc = -EFAULT; 477718f762eSFrank Haverkamp } 478718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, 479718f762eSFrank Haverkamp sgl->fpage_dma_addr); 480718f762eSFrank Haverkamp sgl->fpage = NULL; 481718f762eSFrank Haverkamp sgl->fpage_dma_addr = 0; 482718f762eSFrank Haverkamp } 483718f762eSFrank Haverkamp if (sgl->lpage) { 484718f762eSFrank Haverkamp if (copy_to_user(sgl->user_addr + sgl->user_size - 485718f762eSFrank Haverkamp sgl->lpage_size, sgl->lpage, 486718f762eSFrank Haverkamp sgl->lpage_size)) { 487718f762eSFrank Haverkamp dev_err(&pci_dev->dev, "[%s] err: copying lpage!\n", 488718f762eSFrank Haverkamp __func__); 489718f762eSFrank Haverkamp rc = -EFAULT; 490718f762eSFrank Haverkamp } 491718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->lpage, 492718f762eSFrank Haverkamp sgl->lpage_dma_addr); 493718f762eSFrank Haverkamp sgl->lpage = NULL; 494718f762eSFrank Haverkamp sgl->lpage_dma_addr = 0; 495718f762eSFrank Haverkamp } 496718f762eSFrank Haverkamp __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl, 497718f762eSFrank Haverkamp sgl->sgl_dma_addr); 498718f762eSFrank Haverkamp 499718f762eSFrank Haverkamp sgl->sgl = NULL; 500718f762eSFrank Haverkamp sgl->sgl_dma_addr = 0x0; 501718f762eSFrank Haverkamp sgl->sgl_size = 0; 502718f762eSFrank Haverkamp return rc; 50367f4addbSFrank Haverkamp } 50467f4addbSFrank Haverkamp 50567f4addbSFrank Haverkamp /** 50667f4addbSFrank Haverkamp * free_user_pages() - Give pinned pages back 50767f4addbSFrank Haverkamp * 50867f4addbSFrank Haverkamp * Documentation of get_user_pages is in mm/memory.c: 50967f4addbSFrank Haverkamp * 51067f4addbSFrank Haverkamp * If the page is written to, set_page_dirty (or set_page_dirty_lock, 51167f4addbSFrank Haverkamp * as appropriate) must be called after the page is finished with, and 51267f4addbSFrank Haverkamp * before put_page is called. 51367f4addbSFrank Haverkamp * 51467f4addbSFrank Haverkamp * FIXME Could be of use to others and might belong in the generic 51567f4addbSFrank Haverkamp * code, if others agree. E.g. 51667f4addbSFrank Haverkamp * ll_free_user_pages in drivers/staging/lustre/lustre/llite/rw26.c 51767f4addbSFrank Haverkamp * ceph_put_page_vector in net/ceph/pagevec.c 51867f4addbSFrank Haverkamp * maybe more? 51967f4addbSFrank Haverkamp */ 52067f4addbSFrank Haverkamp static int free_user_pages(struct page **page_list, unsigned int nr_pages, 52167f4addbSFrank Haverkamp int dirty) 52267f4addbSFrank Haverkamp { 52367f4addbSFrank Haverkamp unsigned int i; 52467f4addbSFrank Haverkamp 52567f4addbSFrank Haverkamp for (i = 0; i < nr_pages; i++) { 52667f4addbSFrank Haverkamp if (page_list[i] != NULL) { 52767f4addbSFrank Haverkamp if (dirty) 52867f4addbSFrank Haverkamp set_page_dirty_lock(page_list[i]); 52967f4addbSFrank Haverkamp put_page(page_list[i]); 53067f4addbSFrank Haverkamp } 53167f4addbSFrank Haverkamp } 53267f4addbSFrank Haverkamp return 0; 53367f4addbSFrank Haverkamp } 53467f4addbSFrank Haverkamp 53567f4addbSFrank Haverkamp /** 53667f4addbSFrank Haverkamp * genwqe_user_vmap() - Map user-space memory to virtual kernel memory 53767f4addbSFrank Haverkamp * @cd: pointer to genwqe device 53867f4addbSFrank Haverkamp * @m: mapping params 53967f4addbSFrank Haverkamp * @uaddr: user virtual address 54067f4addbSFrank Haverkamp * @size: size of memory to be mapped 54167f4addbSFrank Haverkamp * 54267f4addbSFrank Haverkamp * We need to think about how we could speed this up. Of course it is 54367f4addbSFrank Haverkamp * not a good idea to do this over and over again, like we are 54467f4addbSFrank Haverkamp * currently doing it. Nevertheless, I am curious where on the path 54567f4addbSFrank Haverkamp * the performance is spend. Most probably within the memory 54667f4addbSFrank Haverkamp * allocation functions, but maybe also in the DMA mapping code. 54767f4addbSFrank Haverkamp * 54867f4addbSFrank Haverkamp * Restrictions: The maximum size of the possible mapping currently depends 54967f4addbSFrank Haverkamp * on the amount of memory we can get using kzalloc() for the 55067f4addbSFrank Haverkamp * page_list and pci_alloc_consistent for the sg_list. 55167f4addbSFrank Haverkamp * The sg_list is currently itself not scattered, which could 55267f4addbSFrank Haverkamp * be fixed with some effort. The page_list must be split into 55367f4addbSFrank Haverkamp * PAGE_SIZE chunks too. All that will make the complicated 55467f4addbSFrank Haverkamp * code more complicated. 55567f4addbSFrank Haverkamp * 55667f4addbSFrank Haverkamp * Return: 0 if success 55767f4addbSFrank Haverkamp */ 55867f4addbSFrank Haverkamp int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, 55967f4addbSFrank Haverkamp unsigned long size, struct ddcb_requ *req) 56067f4addbSFrank Haverkamp { 56167f4addbSFrank Haverkamp int rc = -EINVAL; 56267f4addbSFrank Haverkamp unsigned long data, offs; 56367f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 56467f4addbSFrank Haverkamp 56567f4addbSFrank Haverkamp if ((uaddr == NULL) || (size == 0)) { 56667f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 56767f4addbSFrank Haverkamp return -EINVAL; 56867f4addbSFrank Haverkamp } 56967f4addbSFrank Haverkamp m->u_vaddr = uaddr; 57067f4addbSFrank Haverkamp m->size = size; 57167f4addbSFrank Haverkamp 57267f4addbSFrank Haverkamp /* determine space needed for page_list. */ 57367f4addbSFrank Haverkamp data = (unsigned long)uaddr; 57467f4addbSFrank Haverkamp offs = offset_in_page(data); 57567f4addbSFrank Haverkamp m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE); 57667f4addbSFrank Haverkamp 57767f4addbSFrank Haverkamp m->page_list = kcalloc(m->nr_pages, 57867f4addbSFrank Haverkamp sizeof(struct page *) + sizeof(dma_addr_t), 57967f4addbSFrank Haverkamp GFP_KERNEL); 58067f4addbSFrank Haverkamp if (!m->page_list) { 58167f4addbSFrank Haverkamp dev_err(&pci_dev->dev, "err: alloc page_list failed\n"); 58267f4addbSFrank Haverkamp m->nr_pages = 0; 58367f4addbSFrank Haverkamp m->u_vaddr = NULL; 58467f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 58567f4addbSFrank Haverkamp return -ENOMEM; 58667f4addbSFrank Haverkamp } 58767f4addbSFrank Haverkamp m->dma_list = (dma_addr_t *)(m->page_list + m->nr_pages); 58867f4addbSFrank Haverkamp 58967f4addbSFrank Haverkamp /* pin user pages in memory */ 59067f4addbSFrank Haverkamp rc = get_user_pages_fast(data & PAGE_MASK, /* page aligned addr */ 59167f4addbSFrank Haverkamp m->nr_pages, 59267f4addbSFrank Haverkamp 1, /* write by caller */ 59367f4addbSFrank Haverkamp m->page_list); /* ptrs to pages */ 594cf35d6e0SIan Abbott if (rc < 0) 595cf35d6e0SIan Abbott goto fail_get_user_pages; 59667f4addbSFrank Haverkamp 59767f4addbSFrank Haverkamp /* assumption: get_user_pages can be killed by signals. */ 59867f4addbSFrank Haverkamp if (rc < m->nr_pages) { 59967f4addbSFrank Haverkamp free_user_pages(m->page_list, rc, 0); 60067f4addbSFrank Haverkamp rc = -EFAULT; 60167f4addbSFrank Haverkamp goto fail_get_user_pages; 60267f4addbSFrank Haverkamp } 60367f4addbSFrank Haverkamp 60467f4addbSFrank Haverkamp rc = genwqe_map_pages(cd, m->page_list, m->nr_pages, m->dma_list); 60567f4addbSFrank Haverkamp if (rc != 0) 60667f4addbSFrank Haverkamp goto fail_free_user_pages; 60767f4addbSFrank Haverkamp 60867f4addbSFrank Haverkamp return 0; 60967f4addbSFrank Haverkamp 61067f4addbSFrank Haverkamp fail_free_user_pages: 61167f4addbSFrank Haverkamp free_user_pages(m->page_list, m->nr_pages, 0); 61267f4addbSFrank Haverkamp 61367f4addbSFrank Haverkamp fail_get_user_pages: 61467f4addbSFrank Haverkamp kfree(m->page_list); 61567f4addbSFrank Haverkamp m->page_list = NULL; 61667f4addbSFrank Haverkamp m->dma_list = NULL; 61767f4addbSFrank Haverkamp m->nr_pages = 0; 61867f4addbSFrank Haverkamp m->u_vaddr = NULL; 61967f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 62067f4addbSFrank Haverkamp return rc; 62167f4addbSFrank Haverkamp } 62267f4addbSFrank Haverkamp 62367f4addbSFrank Haverkamp /** 62467f4addbSFrank Haverkamp * genwqe_user_vunmap() - Undo mapping of user-space mem to virtual kernel 62567f4addbSFrank Haverkamp * memory 62667f4addbSFrank Haverkamp * @cd: pointer to genwqe device 62767f4addbSFrank Haverkamp * @m: mapping params 62867f4addbSFrank Haverkamp */ 62967f4addbSFrank Haverkamp int genwqe_user_vunmap(struct genwqe_dev *cd, struct dma_mapping *m, 63067f4addbSFrank Haverkamp struct ddcb_requ *req) 63167f4addbSFrank Haverkamp { 63267f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 63367f4addbSFrank Haverkamp 63467f4addbSFrank Haverkamp if (!dma_mapping_used(m)) { 63567f4addbSFrank Haverkamp dev_err(&pci_dev->dev, "[%s] err: mapping %p not used!\n", 63667f4addbSFrank Haverkamp __func__, m); 63767f4addbSFrank Haverkamp return -EINVAL; 63867f4addbSFrank Haverkamp } 63967f4addbSFrank Haverkamp 64067f4addbSFrank Haverkamp if (m->dma_list) 64167f4addbSFrank Haverkamp genwqe_unmap_pages(cd, m->dma_list, m->nr_pages); 64267f4addbSFrank Haverkamp 64367f4addbSFrank Haverkamp if (m->page_list) { 64467f4addbSFrank Haverkamp free_user_pages(m->page_list, m->nr_pages, 1); 64567f4addbSFrank Haverkamp 64667f4addbSFrank Haverkamp kfree(m->page_list); 64767f4addbSFrank Haverkamp m->page_list = NULL; 64867f4addbSFrank Haverkamp m->dma_list = NULL; 64967f4addbSFrank Haverkamp m->nr_pages = 0; 65067f4addbSFrank Haverkamp } 65167f4addbSFrank Haverkamp 65267f4addbSFrank Haverkamp m->u_vaddr = NULL; 65367f4addbSFrank Haverkamp m->size = 0; /* mark as unused and not added */ 65467f4addbSFrank Haverkamp return 0; 65567f4addbSFrank Haverkamp } 65667f4addbSFrank Haverkamp 65767f4addbSFrank Haverkamp /** 65867f4addbSFrank Haverkamp * genwqe_card_type() - Get chip type SLU Configuration Register 65967f4addbSFrank Haverkamp * @cd: pointer to the genwqe device descriptor 66067f4addbSFrank Haverkamp * Return: 0: Altera Stratix-IV 230 66167f4addbSFrank Haverkamp * 1: Altera Stratix-IV 530 66267f4addbSFrank Haverkamp * 2: Altera Stratix-V A4 66367f4addbSFrank Haverkamp * 3: Altera Stratix-V A7 66467f4addbSFrank Haverkamp */ 66567f4addbSFrank Haverkamp u8 genwqe_card_type(struct genwqe_dev *cd) 66667f4addbSFrank Haverkamp { 66767f4addbSFrank Haverkamp u64 card_type = cd->slu_unitcfg; 668d9c11d45SFrank Haverkamp 66967f4addbSFrank Haverkamp return (u8)((card_type & IO_SLU_UNITCFG_TYPE_MASK) >> 20); 67067f4addbSFrank Haverkamp } 67167f4addbSFrank Haverkamp 67267f4addbSFrank Haverkamp /** 67367f4addbSFrank Haverkamp * genwqe_card_reset() - Reset the card 67467f4addbSFrank Haverkamp * @cd: pointer to the genwqe device descriptor 67567f4addbSFrank Haverkamp */ 67667f4addbSFrank Haverkamp int genwqe_card_reset(struct genwqe_dev *cd) 67767f4addbSFrank Haverkamp { 67867f4addbSFrank Haverkamp u64 softrst; 67967f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 68067f4addbSFrank Haverkamp 68167f4addbSFrank Haverkamp if (!genwqe_is_privileged(cd)) 68267f4addbSFrank Haverkamp return -ENODEV; 68367f4addbSFrank Haverkamp 68467f4addbSFrank Haverkamp /* new SL */ 68567f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, 0x1ull); 68667f4addbSFrank Haverkamp msleep(1000); 68767f4addbSFrank Haverkamp __genwqe_readq(cd, IO_HSU_FIR_CLR); 68867f4addbSFrank Haverkamp __genwqe_readq(cd, IO_APP_FIR_CLR); 68967f4addbSFrank Haverkamp __genwqe_readq(cd, IO_SLU_FIR_CLR); 69067f4addbSFrank Haverkamp 69167f4addbSFrank Haverkamp /* 69267f4addbSFrank Haverkamp * Read-modify-write to preserve the stealth bits 69367f4addbSFrank Haverkamp * 69467f4addbSFrank Haverkamp * For SL >= 039, Stealth WE bit allows removing 69567f4addbSFrank Haverkamp * the read-modify-wrote. 69667f4addbSFrank Haverkamp * r-m-w may require a mask 0x3C to avoid hitting hard 69767f4addbSFrank Haverkamp * reset again for error reset (should be 0, chicken). 69867f4addbSFrank Haverkamp */ 69967f4addbSFrank Haverkamp softrst = __genwqe_readq(cd, IO_SLC_CFGREG_SOFTRESET) & 0x3cull; 70067f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, softrst | 0x2ull); 70167f4addbSFrank Haverkamp 70267f4addbSFrank Haverkamp /* give ERRORRESET some time to finish */ 70367f4addbSFrank Haverkamp msleep(50); 70467f4addbSFrank Haverkamp 70567f4addbSFrank Haverkamp if (genwqe_need_err_masking(cd)) { 70667f4addbSFrank Haverkamp dev_info(&pci_dev->dev, 70767f4addbSFrank Haverkamp "[%s] masking errors for old bitstreams\n", __func__); 70867f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG, 0x0aull); 70967f4addbSFrank Haverkamp } 71067f4addbSFrank Haverkamp return 0; 71167f4addbSFrank Haverkamp } 71267f4addbSFrank Haverkamp 71367f4addbSFrank Haverkamp int genwqe_read_softreset(struct genwqe_dev *cd) 71467f4addbSFrank Haverkamp { 71567f4addbSFrank Haverkamp u64 bitstream; 71667f4addbSFrank Haverkamp 71767f4addbSFrank Haverkamp if (!genwqe_is_privileged(cd)) 71867f4addbSFrank Haverkamp return -ENODEV; 71967f4addbSFrank Haverkamp 72067f4addbSFrank Haverkamp bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM) & 0x1; 72167f4addbSFrank Haverkamp cd->softreset = (bitstream == 0) ? 0x8ull : 0xcull; 72267f4addbSFrank Haverkamp return 0; 72367f4addbSFrank Haverkamp } 72467f4addbSFrank Haverkamp 72567f4addbSFrank Haverkamp /** 72667f4addbSFrank Haverkamp * genwqe_set_interrupt_capability() - Configure MSI capability structure 72767f4addbSFrank Haverkamp * @cd: pointer to the device 72867f4addbSFrank Haverkamp * Return: 0 if no error 72967f4addbSFrank Haverkamp */ 73067f4addbSFrank Haverkamp int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count) 73167f4addbSFrank Haverkamp { 73267f4addbSFrank Haverkamp int rc; 73367f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 73467f4addbSFrank Haverkamp 7357276883fSSebastian Ott rc = pci_enable_msi_range(pci_dev, 1, count); 7367276883fSSebastian Ott if (rc < 0) 73767f4addbSFrank Haverkamp return rc; 7387276883fSSebastian Ott 7397276883fSSebastian Ott cd->flags |= GENWQE_FLAG_MSI_ENABLED; 7407276883fSSebastian Ott return 0; 74167f4addbSFrank Haverkamp } 74267f4addbSFrank Haverkamp 74367f4addbSFrank Haverkamp /** 74467f4addbSFrank Haverkamp * genwqe_reset_interrupt_capability() - Undo genwqe_set_interrupt_capability() 74567f4addbSFrank Haverkamp * @cd: pointer to the device 74667f4addbSFrank Haverkamp */ 74767f4addbSFrank Haverkamp void genwqe_reset_interrupt_capability(struct genwqe_dev *cd) 74867f4addbSFrank Haverkamp { 74967f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 75067f4addbSFrank Haverkamp 75167f4addbSFrank Haverkamp if (cd->flags & GENWQE_FLAG_MSI_ENABLED) { 75267f4addbSFrank Haverkamp pci_disable_msi(pci_dev); 75367f4addbSFrank Haverkamp cd->flags &= ~GENWQE_FLAG_MSI_ENABLED; 75467f4addbSFrank Haverkamp } 75567f4addbSFrank Haverkamp } 75667f4addbSFrank Haverkamp 75767f4addbSFrank Haverkamp /** 75867f4addbSFrank Haverkamp * set_reg_idx() - Fill array with data. Ignore illegal offsets. 75967f4addbSFrank Haverkamp * @cd: card device 76067f4addbSFrank Haverkamp * @r: debug register array 76167f4addbSFrank Haverkamp * @i: index to desired entry 76267f4addbSFrank Haverkamp * @m: maximum possible entries 76367f4addbSFrank Haverkamp * @addr: addr which is read 76467f4addbSFrank Haverkamp * @index: index in debug array 76567f4addbSFrank Haverkamp * @val: read value 76667f4addbSFrank Haverkamp */ 76767f4addbSFrank Haverkamp static int set_reg_idx(struct genwqe_dev *cd, struct genwqe_reg *r, 76867f4addbSFrank Haverkamp unsigned int *i, unsigned int m, u32 addr, u32 idx, 76967f4addbSFrank Haverkamp u64 val) 77067f4addbSFrank Haverkamp { 77167f4addbSFrank Haverkamp if (WARN_ON_ONCE(*i >= m)) 77267f4addbSFrank Haverkamp return -EFAULT; 77367f4addbSFrank Haverkamp 77467f4addbSFrank Haverkamp r[*i].addr = addr; 77567f4addbSFrank Haverkamp r[*i].idx = idx; 77667f4addbSFrank Haverkamp r[*i].val = val; 77767f4addbSFrank Haverkamp ++*i; 77867f4addbSFrank Haverkamp return 0; 77967f4addbSFrank Haverkamp } 78067f4addbSFrank Haverkamp 78167f4addbSFrank Haverkamp static int set_reg(struct genwqe_dev *cd, struct genwqe_reg *r, 78267f4addbSFrank Haverkamp unsigned int *i, unsigned int m, u32 addr, u64 val) 78367f4addbSFrank Haverkamp { 78467f4addbSFrank Haverkamp return set_reg_idx(cd, r, i, m, addr, 0, val); 78567f4addbSFrank Haverkamp } 78667f4addbSFrank Haverkamp 78767f4addbSFrank Haverkamp int genwqe_read_ffdc_regs(struct genwqe_dev *cd, struct genwqe_reg *regs, 78867f4addbSFrank Haverkamp unsigned int max_regs, int all) 78967f4addbSFrank Haverkamp { 79067f4addbSFrank Haverkamp unsigned int i, j, idx = 0; 79167f4addbSFrank Haverkamp u32 ufir_addr, ufec_addr, sfir_addr, sfec_addr; 79267f4addbSFrank Haverkamp u64 gfir, sluid, appid, ufir, ufec, sfir, sfec; 79367f4addbSFrank Haverkamp 79467f4addbSFrank Haverkamp /* Global FIR */ 79567f4addbSFrank Haverkamp gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); 79667f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_SLC_CFGREG_GFIR, gfir); 79767f4addbSFrank Haverkamp 79867f4addbSFrank Haverkamp /* UnitCfg for SLU */ 79967f4addbSFrank Haverkamp sluid = __genwqe_readq(cd, IO_SLU_UNITCFG); /* 0x00000000 */ 80067f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_SLU_UNITCFG, sluid); 80167f4addbSFrank Haverkamp 80267f4addbSFrank Haverkamp /* UnitCfg for APP */ 80367f4addbSFrank Haverkamp appid = __genwqe_readq(cd, IO_APP_UNITCFG); /* 0x02000000 */ 80467f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_APP_UNITCFG, appid); 80567f4addbSFrank Haverkamp 80667f4addbSFrank Haverkamp /* Check all chip Units */ 80767f4addbSFrank Haverkamp for (i = 0; i < GENWQE_MAX_UNITS; i++) { 80867f4addbSFrank Haverkamp 80967f4addbSFrank Haverkamp /* Unit FIR */ 81067f4addbSFrank Haverkamp ufir_addr = (i << 24) | 0x008; 81167f4addbSFrank Haverkamp ufir = __genwqe_readq(cd, ufir_addr); 81267f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, ufir_addr, ufir); 81367f4addbSFrank Haverkamp 81467f4addbSFrank Haverkamp /* Unit FEC */ 81567f4addbSFrank Haverkamp ufec_addr = (i << 24) | 0x018; 81667f4addbSFrank Haverkamp ufec = __genwqe_readq(cd, ufec_addr); 81767f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, ufec_addr, ufec); 81867f4addbSFrank Haverkamp 81967f4addbSFrank Haverkamp for (j = 0; j < 64; j++) { 82067f4addbSFrank Haverkamp /* wherever there is a primary 1, read the 2ndary */ 82167f4addbSFrank Haverkamp if (!all && (!(ufir & (1ull << j)))) 82267f4addbSFrank Haverkamp continue; 82367f4addbSFrank Haverkamp 82467f4addbSFrank Haverkamp sfir_addr = (i << 24) | (0x100 + 8 * j); 82567f4addbSFrank Haverkamp sfir = __genwqe_readq(cd, sfir_addr); 82667f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, sfir_addr, sfir); 82767f4addbSFrank Haverkamp 82867f4addbSFrank Haverkamp sfec_addr = (i << 24) | (0x300 + 8 * j); 82967f4addbSFrank Haverkamp sfec = __genwqe_readq(cd, sfec_addr); 83067f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, sfec_addr, sfec); 83167f4addbSFrank Haverkamp } 83267f4addbSFrank Haverkamp } 83367f4addbSFrank Haverkamp 83467f4addbSFrank Haverkamp /* fill with invalid data until end */ 83567f4addbSFrank Haverkamp for (i = idx; i < max_regs; i++) { 83667f4addbSFrank Haverkamp regs[i].addr = 0xffffffff; 83767f4addbSFrank Haverkamp regs[i].val = 0xffffffffffffffffull; 83867f4addbSFrank Haverkamp } 83967f4addbSFrank Haverkamp return idx; 84067f4addbSFrank Haverkamp } 84167f4addbSFrank Haverkamp 84267f4addbSFrank Haverkamp /** 84367f4addbSFrank Haverkamp * genwqe_ffdc_buff_size() - Calculates the number of dump registers 84467f4addbSFrank Haverkamp */ 84567f4addbSFrank Haverkamp int genwqe_ffdc_buff_size(struct genwqe_dev *cd, int uid) 84667f4addbSFrank Haverkamp { 84767f4addbSFrank Haverkamp int entries = 0, ring, traps, traces, trace_entries; 84867f4addbSFrank Haverkamp u32 eevptr_addr, l_addr, d_len, d_type; 84967f4addbSFrank Haverkamp u64 eevptr, val, addr; 85067f4addbSFrank Haverkamp 85167f4addbSFrank Haverkamp eevptr_addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_ERROR_POINTER; 85267f4addbSFrank Haverkamp eevptr = __genwqe_readq(cd, eevptr_addr); 85367f4addbSFrank Haverkamp 85467f4addbSFrank Haverkamp if ((eevptr != 0x0) && (eevptr != -1ull)) { 85567f4addbSFrank Haverkamp l_addr = GENWQE_UID_OFFS(uid) | eevptr; 85667f4addbSFrank Haverkamp 85767f4addbSFrank Haverkamp while (1) { 85867f4addbSFrank Haverkamp val = __genwqe_readq(cd, l_addr); 85967f4addbSFrank Haverkamp 86067f4addbSFrank Haverkamp if ((val == 0x0) || (val == -1ull)) 86167f4addbSFrank Haverkamp break; 86267f4addbSFrank Haverkamp 86367f4addbSFrank Haverkamp /* 38:24 */ 86467f4addbSFrank Haverkamp d_len = (val & 0x0000007fff000000ull) >> 24; 86567f4addbSFrank Haverkamp 86667f4addbSFrank Haverkamp /* 39 */ 86767f4addbSFrank Haverkamp d_type = (val & 0x0000008000000000ull) >> 36; 86867f4addbSFrank Haverkamp 86967f4addbSFrank Haverkamp if (d_type) { /* repeat */ 87067f4addbSFrank Haverkamp entries += d_len; 87167f4addbSFrank Haverkamp } else { /* size in bytes! */ 87267f4addbSFrank Haverkamp entries += d_len >> 3; 87367f4addbSFrank Haverkamp } 87467f4addbSFrank Haverkamp 87567f4addbSFrank Haverkamp l_addr += 8; 87667f4addbSFrank Haverkamp } 87767f4addbSFrank Haverkamp } 87867f4addbSFrank Haverkamp 87967f4addbSFrank Haverkamp for (ring = 0; ring < 8; ring++) { 88067f4addbSFrank Haverkamp addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_DIAG_MAP(ring); 88167f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 88267f4addbSFrank Haverkamp 88367f4addbSFrank Haverkamp if ((val == 0x0ull) || (val == -1ull)) 88467f4addbSFrank Haverkamp continue; 88567f4addbSFrank Haverkamp 88667f4addbSFrank Haverkamp traps = (val >> 24) & 0xff; 88767f4addbSFrank Haverkamp traces = (val >> 16) & 0xff; 88867f4addbSFrank Haverkamp trace_entries = val & 0xffff; 88967f4addbSFrank Haverkamp 89067f4addbSFrank Haverkamp entries += traps + (traces * trace_entries); 89167f4addbSFrank Haverkamp } 89267f4addbSFrank Haverkamp return entries; 89367f4addbSFrank Haverkamp } 89467f4addbSFrank Haverkamp 89567f4addbSFrank Haverkamp /** 89667f4addbSFrank Haverkamp * genwqe_ffdc_buff_read() - Implements LogoutExtendedErrorRegisters procedure 89767f4addbSFrank Haverkamp */ 89867f4addbSFrank Haverkamp int genwqe_ffdc_buff_read(struct genwqe_dev *cd, int uid, 89967f4addbSFrank Haverkamp struct genwqe_reg *regs, unsigned int max_regs) 90067f4addbSFrank Haverkamp { 90167f4addbSFrank Haverkamp int i, traps, traces, trace, trace_entries, trace_entry, ring; 90267f4addbSFrank Haverkamp unsigned int idx = 0; 90367f4addbSFrank Haverkamp u32 eevptr_addr, l_addr, d_addr, d_len, d_type; 90467f4addbSFrank Haverkamp u64 eevptr, e, val, addr; 90567f4addbSFrank Haverkamp 90667f4addbSFrank Haverkamp eevptr_addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_ERROR_POINTER; 90767f4addbSFrank Haverkamp eevptr = __genwqe_readq(cd, eevptr_addr); 90867f4addbSFrank Haverkamp 90967f4addbSFrank Haverkamp if ((eevptr != 0x0) && (eevptr != 0xffffffffffffffffull)) { 91067f4addbSFrank Haverkamp l_addr = GENWQE_UID_OFFS(uid) | eevptr; 91167f4addbSFrank Haverkamp while (1) { 91267f4addbSFrank Haverkamp e = __genwqe_readq(cd, l_addr); 91367f4addbSFrank Haverkamp if ((e == 0x0) || (e == 0xffffffffffffffffull)) 91467f4addbSFrank Haverkamp break; 91567f4addbSFrank Haverkamp 91667f4addbSFrank Haverkamp d_addr = (e & 0x0000000000ffffffull); /* 23:0 */ 91767f4addbSFrank Haverkamp d_len = (e & 0x0000007fff000000ull) >> 24; /* 38:24 */ 91867f4addbSFrank Haverkamp d_type = (e & 0x0000008000000000ull) >> 36; /* 39 */ 91967f4addbSFrank Haverkamp d_addr |= GENWQE_UID_OFFS(uid); 92067f4addbSFrank Haverkamp 92167f4addbSFrank Haverkamp if (d_type) { 92267f4addbSFrank Haverkamp for (i = 0; i < (int)d_len; i++) { 92367f4addbSFrank Haverkamp val = __genwqe_readq(cd, d_addr); 92467f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, 92567f4addbSFrank Haverkamp d_addr, i, val); 92667f4addbSFrank Haverkamp } 92767f4addbSFrank Haverkamp } else { 92867f4addbSFrank Haverkamp d_len >>= 3; /* Size in bytes! */ 92967f4addbSFrank Haverkamp for (i = 0; i < (int)d_len; i++, d_addr += 8) { 93067f4addbSFrank Haverkamp val = __genwqe_readq(cd, d_addr); 93167f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, 93267f4addbSFrank Haverkamp d_addr, 0, val); 93367f4addbSFrank Haverkamp } 93467f4addbSFrank Haverkamp } 93567f4addbSFrank Haverkamp l_addr += 8; 93667f4addbSFrank Haverkamp } 93767f4addbSFrank Haverkamp } 93867f4addbSFrank Haverkamp 93967f4addbSFrank Haverkamp /* 94067f4addbSFrank Haverkamp * To save time, there are only 6 traces poplulated on Uid=2, 94167f4addbSFrank Haverkamp * Ring=1. each with iters=512. 94267f4addbSFrank Haverkamp */ 94367f4addbSFrank Haverkamp for (ring = 0; ring < 8; ring++) { /* 0 is fls, 1 is fds, 94467f4addbSFrank Haverkamp 2...7 are ASI rings */ 94567f4addbSFrank Haverkamp addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_DIAG_MAP(ring); 94667f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 94767f4addbSFrank Haverkamp 94867f4addbSFrank Haverkamp if ((val == 0x0ull) || (val == -1ull)) 94967f4addbSFrank Haverkamp continue; 95067f4addbSFrank Haverkamp 95167f4addbSFrank Haverkamp traps = (val >> 24) & 0xff; /* Number of Traps */ 95267f4addbSFrank Haverkamp traces = (val >> 16) & 0xff; /* Number of Traces */ 95367f4addbSFrank Haverkamp trace_entries = val & 0xffff; /* Entries per trace */ 95467f4addbSFrank Haverkamp 95567f4addbSFrank Haverkamp /* Note: This is a combined loop that dumps both the traps */ 95667f4addbSFrank Haverkamp /* (for the trace == 0 case) as well as the traces 1 to */ 95767f4addbSFrank Haverkamp /* 'traces'. */ 95867f4addbSFrank Haverkamp for (trace = 0; trace <= traces; trace++) { 95967f4addbSFrank Haverkamp u32 diag_sel = 96067f4addbSFrank Haverkamp GENWQE_EXTENDED_DIAG_SELECTOR(ring, trace); 96167f4addbSFrank Haverkamp 96267f4addbSFrank Haverkamp addr = (GENWQE_UID_OFFS(uid) | 96367f4addbSFrank Haverkamp IO_EXTENDED_DIAG_SELECTOR); 96467f4addbSFrank Haverkamp __genwqe_writeq(cd, addr, diag_sel); 96567f4addbSFrank Haverkamp 96667f4addbSFrank Haverkamp for (trace_entry = 0; 96767f4addbSFrank Haverkamp trace_entry < (trace ? trace_entries : traps); 96867f4addbSFrank Haverkamp trace_entry++) { 96967f4addbSFrank Haverkamp addr = (GENWQE_UID_OFFS(uid) | 97067f4addbSFrank Haverkamp IO_EXTENDED_DIAG_READ_MBX); 97167f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 97267f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, addr, 97367f4addbSFrank Haverkamp (diag_sel<<16) | trace_entry, val); 97467f4addbSFrank Haverkamp } 97567f4addbSFrank Haverkamp } 97667f4addbSFrank Haverkamp } 97767f4addbSFrank Haverkamp return 0; 97867f4addbSFrank Haverkamp } 97967f4addbSFrank Haverkamp 98067f4addbSFrank Haverkamp /** 98167f4addbSFrank Haverkamp * genwqe_write_vreg() - Write register in virtual window 98267f4addbSFrank Haverkamp * 98367f4addbSFrank Haverkamp * Note, these registers are only accessible to the PF through the 98467f4addbSFrank Haverkamp * VF-window. It is not intended for the VF to access. 98567f4addbSFrank Haverkamp */ 98667f4addbSFrank Haverkamp int genwqe_write_vreg(struct genwqe_dev *cd, u32 reg, u64 val, int func) 98767f4addbSFrank Haverkamp { 98867f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_PF_SLC_VIRTUAL_WINDOW, func & 0xf); 98967f4addbSFrank Haverkamp __genwqe_writeq(cd, reg, val); 99067f4addbSFrank Haverkamp return 0; 99167f4addbSFrank Haverkamp } 99267f4addbSFrank Haverkamp 99367f4addbSFrank Haverkamp /** 99467f4addbSFrank Haverkamp * genwqe_read_vreg() - Read register in virtual window 99567f4addbSFrank Haverkamp * 99667f4addbSFrank Haverkamp * Note, these registers are only accessible to the PF through the 99767f4addbSFrank Haverkamp * VF-window. It is not intended for the VF to access. 99867f4addbSFrank Haverkamp */ 99967f4addbSFrank Haverkamp u64 genwqe_read_vreg(struct genwqe_dev *cd, u32 reg, int func) 100067f4addbSFrank Haverkamp { 100167f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_PF_SLC_VIRTUAL_WINDOW, func & 0xf); 100267f4addbSFrank Haverkamp return __genwqe_readq(cd, reg); 100367f4addbSFrank Haverkamp } 100467f4addbSFrank Haverkamp 100567f4addbSFrank Haverkamp /** 100667f4addbSFrank Haverkamp * genwqe_base_clock_frequency() - Deteremine base clock frequency of the card 100767f4addbSFrank Haverkamp * 100867f4addbSFrank Haverkamp * Note: From a design perspective it turned out to be a bad idea to 100967f4addbSFrank Haverkamp * use codes here to specifiy the frequency/speed values. An old 101067f4addbSFrank Haverkamp * driver cannot understand new codes and is therefore always a 101167f4addbSFrank Haverkamp * problem. Better is to measure out the value or put the 101267f4addbSFrank Haverkamp * speed/frequency directly into a register which is always a valid 101367f4addbSFrank Haverkamp * value for old as well as for new software. 101467f4addbSFrank Haverkamp * 101567f4addbSFrank Haverkamp * Return: Card clock in MHz 101667f4addbSFrank Haverkamp */ 101767f4addbSFrank Haverkamp int genwqe_base_clock_frequency(struct genwqe_dev *cd) 101867f4addbSFrank Haverkamp { 101967f4addbSFrank Haverkamp u16 speed; /* MHz MHz MHz MHz */ 102067f4addbSFrank Haverkamp static const int speed_grade[] = { 250, 200, 166, 175 }; 102167f4addbSFrank Haverkamp 102267f4addbSFrank Haverkamp speed = (u16)((cd->slu_unitcfg >> 28) & 0x0full); 102367f4addbSFrank Haverkamp if (speed >= ARRAY_SIZE(speed_grade)) 102467f4addbSFrank Haverkamp return 0; /* illegal value */ 102567f4addbSFrank Haverkamp 102667f4addbSFrank Haverkamp return speed_grade[speed]; 102767f4addbSFrank Haverkamp } 102867f4addbSFrank Haverkamp 102967f4addbSFrank Haverkamp /** 103067f4addbSFrank Haverkamp * genwqe_stop_traps() - Stop traps 103167f4addbSFrank Haverkamp * 103267f4addbSFrank Haverkamp * Before reading out the analysis data, we need to stop the traps. 103367f4addbSFrank Haverkamp */ 103467f4addbSFrank Haverkamp void genwqe_stop_traps(struct genwqe_dev *cd) 103567f4addbSFrank Haverkamp { 103667f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG_SET, 0xcull); 103767f4addbSFrank Haverkamp } 103867f4addbSFrank Haverkamp 103967f4addbSFrank Haverkamp /** 104067f4addbSFrank Haverkamp * genwqe_start_traps() - Start traps 104167f4addbSFrank Haverkamp * 104267f4addbSFrank Haverkamp * After having read the data, we can/must enable the traps again. 104367f4addbSFrank Haverkamp */ 104467f4addbSFrank Haverkamp void genwqe_start_traps(struct genwqe_dev *cd) 104567f4addbSFrank Haverkamp { 104667f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG_CLR, 0xcull); 104767f4addbSFrank Haverkamp 104867f4addbSFrank Haverkamp if (genwqe_need_err_masking(cd)) 104967f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG, 0x0aull); 105067f4addbSFrank Haverkamp } 1051