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