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/sched.h> 2767f4addbSFrank Haverkamp #include <linux/vmalloc.h> 2867f4addbSFrank Haverkamp #include <linux/page-flags.h> 2967f4addbSFrank Haverkamp #include <linux/scatterlist.h> 3067f4addbSFrank Haverkamp #include <linux/hugetlb.h> 3167f4addbSFrank Haverkamp #include <linux/iommu.h> 3267f4addbSFrank Haverkamp #include <linux/pci.h> 3367f4addbSFrank Haverkamp #include <linux/dma-mapping.h> 3467f4addbSFrank Haverkamp #include <linux/ctype.h> 3567f4addbSFrank Haverkamp #include <linux/module.h> 3667f4addbSFrank Haverkamp #include <linux/platform_device.h> 3767f4addbSFrank Haverkamp #include <linux/delay.h> 3867f4addbSFrank Haverkamp #include <asm/pgtable.h> 3967f4addbSFrank Haverkamp 4067f4addbSFrank Haverkamp #include "genwqe_driver.h" 4167f4addbSFrank Haverkamp #include "card_base.h" 4267f4addbSFrank Haverkamp #include "card_ddcb.h" 4367f4addbSFrank Haverkamp 4467f4addbSFrank Haverkamp /** 4567f4addbSFrank Haverkamp * __genwqe_writeq() - Write 64-bit register 4667f4addbSFrank Haverkamp * @cd: genwqe device descriptor 4767f4addbSFrank Haverkamp * @byte_offs: byte offset within BAR 4867f4addbSFrank Haverkamp * @val: 64-bit value 4967f4addbSFrank Haverkamp * 5067f4addbSFrank Haverkamp * Return: 0 if success; < 0 if error 5167f4addbSFrank Haverkamp */ 5267f4addbSFrank Haverkamp int __genwqe_writeq(struct genwqe_dev *cd, u64 byte_offs, u64 val) 5367f4addbSFrank Haverkamp { 54fb145456SKleber Sacilotto de Souza struct pci_dev *pci_dev = cd->pci_dev; 55fb145456SKleber Sacilotto de Souza 5667f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 5767f4addbSFrank Haverkamp return -EIO; 5867f4addbSFrank Haverkamp 5967f4addbSFrank Haverkamp if (cd->mmio == NULL) 6067f4addbSFrank Haverkamp return -EIO; 6167f4addbSFrank Haverkamp 62fb145456SKleber Sacilotto de Souza if (pci_channel_offline(pci_dev)) 63fb145456SKleber Sacilotto de Souza return -EIO; 64fb145456SKleber Sacilotto de Souza 65a45a0258SFrank Haverkamp __raw_writeq((__force u64)cpu_to_be64(val), cd->mmio + byte_offs); 6667f4addbSFrank Haverkamp return 0; 6767f4addbSFrank Haverkamp } 6867f4addbSFrank Haverkamp 6967f4addbSFrank Haverkamp /** 7067f4addbSFrank Haverkamp * __genwqe_readq() - Read 64-bit register 7167f4addbSFrank Haverkamp * @cd: genwqe device descriptor 7267f4addbSFrank Haverkamp * @byte_offs: offset within BAR 7367f4addbSFrank Haverkamp * 7467f4addbSFrank Haverkamp * Return: value from register 7567f4addbSFrank Haverkamp */ 7667f4addbSFrank Haverkamp u64 __genwqe_readq(struct genwqe_dev *cd, u64 byte_offs) 7767f4addbSFrank Haverkamp { 7867f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 7967f4addbSFrank Haverkamp return 0xffffffffffffffffull; 8067f4addbSFrank Haverkamp 8167f4addbSFrank Haverkamp if ((cd->err_inject & GENWQE_INJECT_GFIR_FATAL) && 8267f4addbSFrank Haverkamp (byte_offs == IO_SLC_CFGREG_GFIR)) 8367f4addbSFrank Haverkamp return 0x000000000000ffffull; 8467f4addbSFrank Haverkamp 8567f4addbSFrank Haverkamp if ((cd->err_inject & GENWQE_INJECT_GFIR_INFO) && 8667f4addbSFrank Haverkamp (byte_offs == IO_SLC_CFGREG_GFIR)) 8767f4addbSFrank Haverkamp return 0x00000000ffff0000ull; 8867f4addbSFrank Haverkamp 8967f4addbSFrank Haverkamp if (cd->mmio == NULL) 9067f4addbSFrank Haverkamp return 0xffffffffffffffffull; 9167f4addbSFrank Haverkamp 9258d66ce7SFrank Haverkamp return be64_to_cpu((__force __be64)__raw_readq(cd->mmio + byte_offs)); 9367f4addbSFrank Haverkamp } 9467f4addbSFrank Haverkamp 9567f4addbSFrank Haverkamp /** 9667f4addbSFrank Haverkamp * __genwqe_writel() - Write 32-bit register 9767f4addbSFrank Haverkamp * @cd: genwqe device descriptor 9867f4addbSFrank Haverkamp * @byte_offs: byte offset within BAR 9967f4addbSFrank Haverkamp * @val: 32-bit value 10067f4addbSFrank Haverkamp * 10167f4addbSFrank Haverkamp * Return: 0 if success; < 0 if error 10267f4addbSFrank Haverkamp */ 10367f4addbSFrank Haverkamp int __genwqe_writel(struct genwqe_dev *cd, u64 byte_offs, u32 val) 10467f4addbSFrank Haverkamp { 105fb145456SKleber Sacilotto de Souza struct pci_dev *pci_dev = cd->pci_dev; 106fb145456SKleber Sacilotto de Souza 10767f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 10867f4addbSFrank Haverkamp return -EIO; 10967f4addbSFrank Haverkamp 11067f4addbSFrank Haverkamp if (cd->mmio == NULL) 11167f4addbSFrank Haverkamp return -EIO; 11267f4addbSFrank Haverkamp 113fb145456SKleber Sacilotto de Souza if (pci_channel_offline(pci_dev)) 114fb145456SKleber Sacilotto de Souza return -EIO; 115fb145456SKleber Sacilotto de Souza 11658d66ce7SFrank Haverkamp __raw_writel((__force u32)cpu_to_be32(val), cd->mmio + byte_offs); 11767f4addbSFrank Haverkamp return 0; 11867f4addbSFrank Haverkamp } 11967f4addbSFrank Haverkamp 12067f4addbSFrank Haverkamp /** 12167f4addbSFrank Haverkamp * __genwqe_readl() - Read 32-bit register 12267f4addbSFrank Haverkamp * @cd: genwqe device descriptor 12367f4addbSFrank Haverkamp * @byte_offs: offset within BAR 12467f4addbSFrank Haverkamp * 12567f4addbSFrank Haverkamp * Return: Value from register 12667f4addbSFrank Haverkamp */ 12767f4addbSFrank Haverkamp u32 __genwqe_readl(struct genwqe_dev *cd, u64 byte_offs) 12867f4addbSFrank Haverkamp { 12967f4addbSFrank Haverkamp if (cd->err_inject & GENWQE_INJECT_HARDWARE_FAILURE) 13067f4addbSFrank Haverkamp return 0xffffffff; 13167f4addbSFrank Haverkamp 13267f4addbSFrank Haverkamp if (cd->mmio == NULL) 13367f4addbSFrank Haverkamp return 0xffffffff; 13467f4addbSFrank Haverkamp 13558d66ce7SFrank Haverkamp return be32_to_cpu((__force __be32)__raw_readl(cd->mmio + byte_offs)); 13667f4addbSFrank Haverkamp } 13767f4addbSFrank Haverkamp 13867f4addbSFrank Haverkamp /** 13967f4addbSFrank Haverkamp * genwqe_read_app_id() - Extract app_id 14067f4addbSFrank Haverkamp * 14167f4addbSFrank Haverkamp * app_unitcfg need to be filled with valid data first 14267f4addbSFrank Haverkamp */ 14367f4addbSFrank Haverkamp int genwqe_read_app_id(struct genwqe_dev *cd, char *app_name, int len) 14467f4addbSFrank Haverkamp { 14567f4addbSFrank Haverkamp int i, j; 14667f4addbSFrank Haverkamp u32 app_id = (u32)cd->app_unitcfg; 14767f4addbSFrank Haverkamp 14867f4addbSFrank Haverkamp memset(app_name, 0, len); 14967f4addbSFrank Haverkamp for (i = 0, j = 0; j < min(len, 4); j++) { 15067f4addbSFrank Haverkamp char ch = (char)((app_id >> (24 - j*8)) & 0xff); 151d9c11d45SFrank Haverkamp 15267f4addbSFrank Haverkamp if (ch == ' ') 15367f4addbSFrank Haverkamp continue; 15467f4addbSFrank Haverkamp app_name[i++] = isprint(ch) ? ch : 'X'; 15567f4addbSFrank Haverkamp } 15667f4addbSFrank Haverkamp return i; 15767f4addbSFrank Haverkamp } 15867f4addbSFrank Haverkamp 15967f4addbSFrank Haverkamp /** 16067f4addbSFrank Haverkamp * genwqe_init_crc32() - Prepare a lookup table for fast crc32 calculations 16167f4addbSFrank Haverkamp * 16267f4addbSFrank Haverkamp * Existing kernel functions seem to use a different polynom, 16367f4addbSFrank Haverkamp * therefore we could not use them here. 16467f4addbSFrank Haverkamp * 16567f4addbSFrank Haverkamp * Genwqe's Polynomial = 0x20044009 16667f4addbSFrank Haverkamp */ 16767f4addbSFrank Haverkamp #define CRC32_POLYNOMIAL 0x20044009 16867f4addbSFrank Haverkamp static u32 crc32_tab[256]; /* crc32 lookup table */ 16967f4addbSFrank Haverkamp 17067f4addbSFrank Haverkamp void genwqe_init_crc32(void) 17167f4addbSFrank Haverkamp { 17267f4addbSFrank Haverkamp int i, j; 17367f4addbSFrank Haverkamp u32 crc; 17467f4addbSFrank Haverkamp 17567f4addbSFrank Haverkamp for (i = 0; i < 256; i++) { 17667f4addbSFrank Haverkamp crc = i << 24; 17767f4addbSFrank Haverkamp for (j = 0; j < 8; j++) { 17867f4addbSFrank Haverkamp if (crc & 0x80000000) 17967f4addbSFrank Haverkamp crc = (crc << 1) ^ CRC32_POLYNOMIAL; 18067f4addbSFrank Haverkamp else 18167f4addbSFrank Haverkamp crc = (crc << 1); 18267f4addbSFrank Haverkamp } 18367f4addbSFrank Haverkamp crc32_tab[i] = crc; 18467f4addbSFrank Haverkamp } 18567f4addbSFrank Haverkamp } 18667f4addbSFrank Haverkamp 18767f4addbSFrank Haverkamp /** 18867f4addbSFrank Haverkamp * genwqe_crc32() - Generate 32-bit crc as required for DDCBs 18967f4addbSFrank Haverkamp * @buff: pointer to data buffer 19067f4addbSFrank Haverkamp * @len: length of data for calculation 19167f4addbSFrank Haverkamp * @init: initial crc (0xffffffff at start) 19267f4addbSFrank Haverkamp * 19367f4addbSFrank Haverkamp * polynomial = x^32 * + x^29 + x^18 + x^14 + x^3 + 1 (0x20044009) 19467f4addbSFrank Haverkamp 19567f4addbSFrank Haverkamp * Example: 4 bytes 0x01 0x02 0x03 0x04 with init=0xffffffff should 19667f4addbSFrank Haverkamp * result in a crc32 of 0xf33cb7d3. 19767f4addbSFrank Haverkamp * 19867f4addbSFrank Haverkamp * The existing kernel crc functions did not cover this polynom yet. 19967f4addbSFrank Haverkamp * 20067f4addbSFrank Haverkamp * Return: crc32 checksum. 20167f4addbSFrank Haverkamp */ 20267f4addbSFrank Haverkamp u32 genwqe_crc32(u8 *buff, size_t len, u32 init) 20367f4addbSFrank Haverkamp { 20467f4addbSFrank Haverkamp int i; 20567f4addbSFrank Haverkamp u32 crc; 20667f4addbSFrank Haverkamp 20767f4addbSFrank Haverkamp crc = init; 20867f4addbSFrank Haverkamp while (len--) { 20967f4addbSFrank Haverkamp i = ((crc >> 24) ^ *buff++) & 0xFF; 21067f4addbSFrank Haverkamp crc = (crc << 8) ^ crc32_tab[i]; 21167f4addbSFrank Haverkamp } 21267f4addbSFrank Haverkamp return crc; 21367f4addbSFrank Haverkamp } 21467f4addbSFrank Haverkamp 21567f4addbSFrank Haverkamp void *__genwqe_alloc_consistent(struct genwqe_dev *cd, size_t size, 21667f4addbSFrank Haverkamp dma_addr_t *dma_handle) 21767f4addbSFrank Haverkamp { 218fdd66968SChristian Borntraeger if (get_order(size) >= MAX_ORDER) 21967f4addbSFrank Haverkamp return NULL; 22067f4addbSFrank Haverkamp 221*750afb08SLuis Chamberlain return dma_alloc_coherent(&cd->pci_dev->dev, size, dma_handle, 22219f7767eSSebastian Ott GFP_KERNEL); 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 23119f7767eSSebastian Ott dma_free_coherent(&cd->pci_dev->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, 297de4ce2d1SGuilherme G. Piccoli void __user *user_addr, size_t user_size, int write) 29867f4addbSFrank Haverkamp { 29902241995Szhong jiang int ret = -ENOMEM; 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 307d9c11d45SFrank Haverkamp dev_dbg(&pci_dev->dev, "[%s] uaddr=%p usize=%8ld nr_pages=%ld fpage_offs=%lx fpage_size=%ld lpage_size=%ld\n", 308718f762eSFrank Haverkamp __func__, user_addr, user_size, sgl->nr_pages, 309718f762eSFrank Haverkamp sgl->fpage_offs, sgl->fpage_size, sgl->lpage_size); 310718f762eSFrank Haverkamp 311718f762eSFrank Haverkamp sgl->user_addr = user_addr; 312718f762eSFrank Haverkamp sgl->user_size = user_size; 313de4ce2d1SGuilherme G. Piccoli sgl->write = write; 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__); 31902241995Szhong jiang return ret; 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__); 32702241995Szhong jiang return ret; 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)) { 34002241995Szhong jiang ret = -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)) { 35302241995Szhong jiang ret = -EFAULT; 354a7a7aeefSGerald Schaefer goto err_out2; 355718f762eSFrank Haverkamp } 356718f762eSFrank Haverkamp } 357718f762eSFrank Haverkamp return 0; 358718f762eSFrank Haverkamp 359a7a7aeefSGerald Schaefer err_out2: 360a7a7aeefSGerald Schaefer __genwqe_free_consistent(cd, PAGE_SIZE, sgl->lpage, 361a7a7aeefSGerald Schaefer sgl->lpage_dma_addr); 362a7a7aeefSGerald Schaefer sgl->lpage = NULL; 363a7a7aeefSGerald Schaefer sgl->lpage_dma_addr = 0; 364718f762eSFrank Haverkamp err_out1: 365718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, 366718f762eSFrank Haverkamp sgl->fpage_dma_addr); 367a7a7aeefSGerald Schaefer sgl->fpage = NULL; 368a7a7aeefSGerald Schaefer sgl->fpage_dma_addr = 0; 369718f762eSFrank Haverkamp err_out: 370718f762eSFrank Haverkamp __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl, 371718f762eSFrank Haverkamp sgl->sgl_dma_addr); 372a7a7aeefSGerald Schaefer sgl->sgl = NULL; 373a7a7aeefSGerald Schaefer sgl->sgl_dma_addr = 0; 374a7a7aeefSGerald Schaefer sgl->sgl_size = 0; 37502241995Szhong jiang 37602241995Szhong jiang return ret; 37767f4addbSFrank Haverkamp } 37867f4addbSFrank Haverkamp 379718f762eSFrank Haverkamp int genwqe_setup_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl, 380718f762eSFrank Haverkamp dma_addr_t *dma_list) 38167f4addbSFrank Haverkamp { 38267f4addbSFrank Haverkamp int i = 0, j = 0, p; 38367f4addbSFrank Haverkamp unsigned long dma_offs, map_offs; 38467f4addbSFrank Haverkamp dma_addr_t prev_daddr = 0; 38567f4addbSFrank Haverkamp struct sg_entry *s, *last_s = NULL; 386718f762eSFrank Haverkamp size_t size = sgl->user_size; 38767f4addbSFrank Haverkamp 38867f4addbSFrank Haverkamp dma_offs = 128; /* next block if needed/dma_offset */ 389718f762eSFrank Haverkamp map_offs = sgl->fpage_offs; /* offset in first page */ 39067f4addbSFrank Haverkamp 391718f762eSFrank Haverkamp s = &sgl->sgl[0]; /* first set of 8 entries */ 39267f4addbSFrank Haverkamp p = 0; /* page */ 393718f762eSFrank Haverkamp while (p < sgl->nr_pages) { 39467f4addbSFrank Haverkamp dma_addr_t daddr; 39567f4addbSFrank Haverkamp unsigned int size_to_map; 39667f4addbSFrank Haverkamp 39767f4addbSFrank Haverkamp /* always write the chaining entry, cleanup is done later */ 39867f4addbSFrank Haverkamp j = 0; 399718f762eSFrank Haverkamp s[j].target_addr = cpu_to_be64(sgl->sgl_dma_addr + dma_offs); 40067f4addbSFrank Haverkamp s[j].len = cpu_to_be32(128); 40167f4addbSFrank Haverkamp s[j].flags = cpu_to_be32(SG_CHAINED); 40267f4addbSFrank Haverkamp j++; 40367f4addbSFrank Haverkamp 40467f4addbSFrank Haverkamp while (j < 8) { 40567f4addbSFrank Haverkamp /* DMA mapping for requested page, offs, size */ 40667f4addbSFrank Haverkamp size_to_map = min(size, PAGE_SIZE - map_offs); 407718f762eSFrank Haverkamp 408718f762eSFrank Haverkamp if ((p == 0) && (sgl->fpage != NULL)) { 409718f762eSFrank Haverkamp daddr = sgl->fpage_dma_addr + map_offs; 410718f762eSFrank Haverkamp 411718f762eSFrank Haverkamp } else if ((p == sgl->nr_pages - 1) && 412718f762eSFrank Haverkamp (sgl->lpage != NULL)) { 413718f762eSFrank Haverkamp daddr = sgl->lpage_dma_addr; 414718f762eSFrank Haverkamp } else { 415718f762eSFrank Haverkamp daddr = dma_list[p] + map_offs; 416718f762eSFrank Haverkamp } 417718f762eSFrank Haverkamp 41867f4addbSFrank Haverkamp size -= size_to_map; 41967f4addbSFrank Haverkamp map_offs = 0; 42067f4addbSFrank Haverkamp 42167f4addbSFrank Haverkamp if (prev_daddr == daddr) { 42267f4addbSFrank Haverkamp u32 prev_len = be32_to_cpu(last_s->len); 42367f4addbSFrank Haverkamp 42467f4addbSFrank Haverkamp /* pr_info("daddr combining: " 42567f4addbSFrank Haverkamp "%016llx/%08x -> %016llx\n", 42667f4addbSFrank Haverkamp prev_daddr, prev_len, daddr); */ 42767f4addbSFrank Haverkamp 42867f4addbSFrank Haverkamp last_s->len = cpu_to_be32(prev_len + 42967f4addbSFrank Haverkamp size_to_map); 43067f4addbSFrank Haverkamp 43167f4addbSFrank Haverkamp p++; /* process next page */ 432718f762eSFrank Haverkamp if (p == sgl->nr_pages) 43367f4addbSFrank Haverkamp goto fixup; /* nothing to do */ 43467f4addbSFrank Haverkamp 43567f4addbSFrank Haverkamp prev_daddr = daddr + size_to_map; 43667f4addbSFrank Haverkamp continue; 43767f4addbSFrank Haverkamp } 43867f4addbSFrank Haverkamp 43967f4addbSFrank Haverkamp /* start new entry */ 44067f4addbSFrank Haverkamp s[j].target_addr = cpu_to_be64(daddr); 44167f4addbSFrank Haverkamp s[j].len = cpu_to_be32(size_to_map); 44267f4addbSFrank Haverkamp s[j].flags = cpu_to_be32(SG_DATA); 44367f4addbSFrank Haverkamp prev_daddr = daddr + size_to_map; 44467f4addbSFrank Haverkamp last_s = &s[j]; 44567f4addbSFrank Haverkamp j++; 44667f4addbSFrank Haverkamp 44767f4addbSFrank Haverkamp p++; /* process next page */ 448718f762eSFrank Haverkamp if (p == sgl->nr_pages) 44967f4addbSFrank Haverkamp goto fixup; /* nothing to do */ 45067f4addbSFrank Haverkamp } 45167f4addbSFrank Haverkamp dma_offs += 128; 45267f4addbSFrank Haverkamp s += 8; /* continue 8 elements further */ 45367f4addbSFrank Haverkamp } 45467f4addbSFrank Haverkamp fixup: 4552f097267SMarkus Elfring if (j == 1) { /* combining happened on last entry! */ 45667f4addbSFrank Haverkamp s -= 8; /* full shift needed on previous sgl block */ 45767f4addbSFrank Haverkamp j = 7; /* shift all elements */ 45867f4addbSFrank Haverkamp } 45967f4addbSFrank Haverkamp 46067f4addbSFrank Haverkamp for (i = 0; i < j; i++) /* move elements 1 up */ 46167f4addbSFrank Haverkamp s[i] = s[i + 1]; 46267f4addbSFrank Haverkamp 46367f4addbSFrank Haverkamp s[i].target_addr = cpu_to_be64(0); 46467f4addbSFrank Haverkamp s[i].len = cpu_to_be32(0); 46567f4addbSFrank Haverkamp s[i].flags = cpu_to_be32(SG_END_LIST); 46667f4addbSFrank Haverkamp return 0; 46767f4addbSFrank Haverkamp } 46867f4addbSFrank Haverkamp 469718f762eSFrank Haverkamp /** 470718f762eSFrank Haverkamp * genwqe_free_sync_sgl() - Free memory for sgl and overlapping pages 471718f762eSFrank Haverkamp * 472718f762eSFrank Haverkamp * After the DMA transfer has been completed we free the memory for 4732f097267SMarkus Elfring * the sgl and the cached pages. Data is being transferred from cached 474718f762eSFrank Haverkamp * pages into user-space buffers. 475718f762eSFrank Haverkamp */ 476718f762eSFrank Haverkamp int genwqe_free_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl) 47767f4addbSFrank Haverkamp { 47863fa80cdSChristian Engelmayer int rc = 0; 479de4ce2d1SGuilherme G. Piccoli size_t offset; 480de4ce2d1SGuilherme G. Piccoli unsigned long res; 481718f762eSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 482718f762eSFrank Haverkamp 483718f762eSFrank Haverkamp if (sgl->fpage) { 484de4ce2d1SGuilherme G. Piccoli if (sgl->write) { 485de4ce2d1SGuilherme G. Piccoli res = copy_to_user(sgl->user_addr, 486de4ce2d1SGuilherme G. Piccoli sgl->fpage + sgl->fpage_offs, sgl->fpage_size); 487de4ce2d1SGuilherme G. Piccoli if (res) { 488de4ce2d1SGuilherme G. Piccoli dev_err(&pci_dev->dev, 489de4ce2d1SGuilherme G. Piccoli "[%s] err: copying fpage! (res=%lu)\n", 490de4ce2d1SGuilherme G. Piccoli __func__, res); 491718f762eSFrank Haverkamp rc = -EFAULT; 492718f762eSFrank Haverkamp } 493de4ce2d1SGuilherme G. Piccoli } 494718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, 495718f762eSFrank Haverkamp sgl->fpage_dma_addr); 496718f762eSFrank Haverkamp sgl->fpage = NULL; 497718f762eSFrank Haverkamp sgl->fpage_dma_addr = 0; 498718f762eSFrank Haverkamp } 499718f762eSFrank Haverkamp if (sgl->lpage) { 500de4ce2d1SGuilherme G. Piccoli if (sgl->write) { 501de4ce2d1SGuilherme G. Piccoli offset = sgl->user_size - sgl->lpage_size; 502de4ce2d1SGuilherme G. Piccoli res = copy_to_user(sgl->user_addr + offset, sgl->lpage, 503de4ce2d1SGuilherme G. Piccoli sgl->lpage_size); 504de4ce2d1SGuilherme G. Piccoli if (res) { 505de4ce2d1SGuilherme G. Piccoli dev_err(&pci_dev->dev, 506de4ce2d1SGuilherme G. Piccoli "[%s] err: copying lpage! (res=%lu)\n", 507de4ce2d1SGuilherme G. Piccoli __func__, res); 508718f762eSFrank Haverkamp rc = -EFAULT; 509718f762eSFrank Haverkamp } 510de4ce2d1SGuilherme G. Piccoli } 511718f762eSFrank Haverkamp __genwqe_free_consistent(cd, PAGE_SIZE, sgl->lpage, 512718f762eSFrank Haverkamp sgl->lpage_dma_addr); 513718f762eSFrank Haverkamp sgl->lpage = NULL; 514718f762eSFrank Haverkamp sgl->lpage_dma_addr = 0; 515718f762eSFrank Haverkamp } 516718f762eSFrank Haverkamp __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl, 517718f762eSFrank Haverkamp sgl->sgl_dma_addr); 518718f762eSFrank Haverkamp 519718f762eSFrank Haverkamp sgl->sgl = NULL; 520718f762eSFrank Haverkamp sgl->sgl_dma_addr = 0x0; 521718f762eSFrank Haverkamp sgl->sgl_size = 0; 522718f762eSFrank Haverkamp return rc; 52367f4addbSFrank Haverkamp } 52467f4addbSFrank Haverkamp 52567f4addbSFrank Haverkamp /** 52607864a17SGuilherme G. Piccoli * genwqe_free_user_pages() - Give pinned pages back 52767f4addbSFrank Haverkamp * 52807864a17SGuilherme G. Piccoli * Documentation of get_user_pages is in mm/gup.c: 52967f4addbSFrank Haverkamp * 53067f4addbSFrank Haverkamp * If the page is written to, set_page_dirty (or set_page_dirty_lock, 53167f4addbSFrank Haverkamp * as appropriate) must be called after the page is finished with, and 53267f4addbSFrank Haverkamp * before put_page is called. 53367f4addbSFrank Haverkamp */ 53407864a17SGuilherme G. Piccoli static int genwqe_free_user_pages(struct page **page_list, 53507864a17SGuilherme G. Piccoli unsigned int nr_pages, int dirty) 53667f4addbSFrank Haverkamp { 53767f4addbSFrank Haverkamp unsigned int i; 53867f4addbSFrank Haverkamp 53967f4addbSFrank Haverkamp for (i = 0; i < nr_pages; i++) { 54067f4addbSFrank Haverkamp if (page_list[i] != NULL) { 54167f4addbSFrank Haverkamp if (dirty) 54267f4addbSFrank Haverkamp set_page_dirty_lock(page_list[i]); 54367f4addbSFrank Haverkamp put_page(page_list[i]); 54467f4addbSFrank Haverkamp } 54567f4addbSFrank Haverkamp } 54667f4addbSFrank Haverkamp return 0; 54767f4addbSFrank Haverkamp } 54867f4addbSFrank Haverkamp 54967f4addbSFrank Haverkamp /** 55067f4addbSFrank Haverkamp * genwqe_user_vmap() - Map user-space memory to virtual kernel memory 55167f4addbSFrank Haverkamp * @cd: pointer to genwqe device 55267f4addbSFrank Haverkamp * @m: mapping params 55367f4addbSFrank Haverkamp * @uaddr: user virtual address 55467f4addbSFrank Haverkamp * @size: size of memory to be mapped 55567f4addbSFrank Haverkamp * 55667f4addbSFrank Haverkamp * We need to think about how we could speed this up. Of course it is 55767f4addbSFrank Haverkamp * not a good idea to do this over and over again, like we are 55867f4addbSFrank Haverkamp * currently doing it. Nevertheless, I am curious where on the path 55967f4addbSFrank Haverkamp * the performance is spend. Most probably within the memory 56067f4addbSFrank Haverkamp * allocation functions, but maybe also in the DMA mapping code. 56167f4addbSFrank Haverkamp * 56267f4addbSFrank Haverkamp * Restrictions: The maximum size of the possible mapping currently depends 56367f4addbSFrank Haverkamp * on the amount of memory we can get using kzalloc() for the 56467f4addbSFrank Haverkamp * page_list and pci_alloc_consistent for the sg_list. 56567f4addbSFrank Haverkamp * The sg_list is currently itself not scattered, which could 56667f4addbSFrank Haverkamp * be fixed with some effort. The page_list must be split into 56767f4addbSFrank Haverkamp * PAGE_SIZE chunks too. All that will make the complicated 56867f4addbSFrank Haverkamp * code more complicated. 56967f4addbSFrank Haverkamp * 57067f4addbSFrank Haverkamp * Return: 0 if success 57167f4addbSFrank Haverkamp */ 57267f4addbSFrank Haverkamp int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, 573658a494aSGuilherme G. Piccoli unsigned long size) 57467f4addbSFrank Haverkamp { 57567f4addbSFrank Haverkamp int rc = -EINVAL; 57667f4addbSFrank Haverkamp unsigned long data, offs; 57767f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 57867f4addbSFrank Haverkamp 57967f4addbSFrank Haverkamp if ((uaddr == NULL) || (size == 0)) { 58067f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 58167f4addbSFrank Haverkamp return -EINVAL; 58267f4addbSFrank Haverkamp } 58367f4addbSFrank Haverkamp m->u_vaddr = uaddr; 58467f4addbSFrank Haverkamp m->size = size; 58567f4addbSFrank Haverkamp 58667f4addbSFrank Haverkamp /* determine space needed for page_list. */ 58767f4addbSFrank Haverkamp data = (unsigned long)uaddr; 58867f4addbSFrank Haverkamp offs = offset_in_page(data); 58967f4addbSFrank Haverkamp m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE); 59067f4addbSFrank Haverkamp 59167f4addbSFrank Haverkamp m->page_list = kcalloc(m->nr_pages, 59267f4addbSFrank Haverkamp sizeof(struct page *) + sizeof(dma_addr_t), 59367f4addbSFrank Haverkamp GFP_KERNEL); 59467f4addbSFrank Haverkamp if (!m->page_list) { 59567f4addbSFrank Haverkamp dev_err(&pci_dev->dev, "err: alloc page_list failed\n"); 59667f4addbSFrank Haverkamp m->nr_pages = 0; 59767f4addbSFrank Haverkamp m->u_vaddr = NULL; 59867f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 59967f4addbSFrank Haverkamp return -ENOMEM; 60067f4addbSFrank Haverkamp } 60167f4addbSFrank Haverkamp m->dma_list = (dma_addr_t *)(m->page_list + m->nr_pages); 60267f4addbSFrank Haverkamp 60367f4addbSFrank Haverkamp /* pin user pages in memory */ 60467f4addbSFrank Haverkamp rc = get_user_pages_fast(data & PAGE_MASK, /* page aligned addr */ 60567f4addbSFrank Haverkamp m->nr_pages, 606de4ce2d1SGuilherme G. Piccoli m->write, /* readable/writable */ 60767f4addbSFrank Haverkamp m->page_list); /* ptrs to pages */ 608cf35d6e0SIan Abbott if (rc < 0) 609cf35d6e0SIan Abbott goto fail_get_user_pages; 61067f4addbSFrank Haverkamp 61167f4addbSFrank Haverkamp /* assumption: get_user_pages can be killed by signals. */ 61267f4addbSFrank Haverkamp if (rc < m->nr_pages) { 61307864a17SGuilherme G. Piccoli genwqe_free_user_pages(m->page_list, rc, m->write); 61467f4addbSFrank Haverkamp rc = -EFAULT; 61567f4addbSFrank Haverkamp goto fail_get_user_pages; 61667f4addbSFrank Haverkamp } 61767f4addbSFrank Haverkamp 61867f4addbSFrank Haverkamp rc = genwqe_map_pages(cd, m->page_list, m->nr_pages, m->dma_list); 61967f4addbSFrank Haverkamp if (rc != 0) 62067f4addbSFrank Haverkamp goto fail_free_user_pages; 62167f4addbSFrank Haverkamp 62267f4addbSFrank Haverkamp return 0; 62367f4addbSFrank Haverkamp 62467f4addbSFrank Haverkamp fail_free_user_pages: 62507864a17SGuilherme G. Piccoli genwqe_free_user_pages(m->page_list, m->nr_pages, m->write); 62667f4addbSFrank Haverkamp 62767f4addbSFrank Haverkamp fail_get_user_pages: 62867f4addbSFrank Haverkamp kfree(m->page_list); 62967f4addbSFrank Haverkamp m->page_list = NULL; 63067f4addbSFrank Haverkamp m->dma_list = NULL; 63167f4addbSFrank Haverkamp m->nr_pages = 0; 63267f4addbSFrank Haverkamp m->u_vaddr = NULL; 63367f4addbSFrank Haverkamp m->size = 0; /* mark unused and not added */ 63467f4addbSFrank Haverkamp return rc; 63567f4addbSFrank Haverkamp } 63667f4addbSFrank Haverkamp 63767f4addbSFrank Haverkamp /** 63867f4addbSFrank Haverkamp * genwqe_user_vunmap() - Undo mapping of user-space mem to virtual kernel 63967f4addbSFrank Haverkamp * memory 64067f4addbSFrank Haverkamp * @cd: pointer to genwqe device 64167f4addbSFrank Haverkamp * @m: mapping params 64267f4addbSFrank Haverkamp */ 643658a494aSGuilherme G. Piccoli int genwqe_user_vunmap(struct genwqe_dev *cd, struct dma_mapping *m) 64467f4addbSFrank Haverkamp { 64567f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 64667f4addbSFrank Haverkamp 64767f4addbSFrank Haverkamp if (!dma_mapping_used(m)) { 64867f4addbSFrank Haverkamp dev_err(&pci_dev->dev, "[%s] err: mapping %p not used!\n", 64967f4addbSFrank Haverkamp __func__, m); 65067f4addbSFrank Haverkamp return -EINVAL; 65167f4addbSFrank Haverkamp } 65267f4addbSFrank Haverkamp 65367f4addbSFrank Haverkamp if (m->dma_list) 65467f4addbSFrank Haverkamp genwqe_unmap_pages(cd, m->dma_list, m->nr_pages); 65567f4addbSFrank Haverkamp 65667f4addbSFrank Haverkamp if (m->page_list) { 65707864a17SGuilherme G. Piccoli genwqe_free_user_pages(m->page_list, m->nr_pages, m->write); 65867f4addbSFrank Haverkamp 65967f4addbSFrank Haverkamp kfree(m->page_list); 66067f4addbSFrank Haverkamp m->page_list = NULL; 66167f4addbSFrank Haverkamp m->dma_list = NULL; 66267f4addbSFrank Haverkamp m->nr_pages = 0; 66367f4addbSFrank Haverkamp } 66467f4addbSFrank Haverkamp 66567f4addbSFrank Haverkamp m->u_vaddr = NULL; 66667f4addbSFrank Haverkamp m->size = 0; /* mark as unused and not added */ 66767f4addbSFrank Haverkamp return 0; 66867f4addbSFrank Haverkamp } 66967f4addbSFrank Haverkamp 67067f4addbSFrank Haverkamp /** 67167f4addbSFrank Haverkamp * genwqe_card_type() - Get chip type SLU Configuration Register 67267f4addbSFrank Haverkamp * @cd: pointer to the genwqe device descriptor 67367f4addbSFrank Haverkamp * Return: 0: Altera Stratix-IV 230 67467f4addbSFrank Haverkamp * 1: Altera Stratix-IV 530 67567f4addbSFrank Haverkamp * 2: Altera Stratix-V A4 67667f4addbSFrank Haverkamp * 3: Altera Stratix-V A7 67767f4addbSFrank Haverkamp */ 67867f4addbSFrank Haverkamp u8 genwqe_card_type(struct genwqe_dev *cd) 67967f4addbSFrank Haverkamp { 68067f4addbSFrank Haverkamp u64 card_type = cd->slu_unitcfg; 681d9c11d45SFrank Haverkamp 68267f4addbSFrank Haverkamp return (u8)((card_type & IO_SLU_UNITCFG_TYPE_MASK) >> 20); 68367f4addbSFrank Haverkamp } 68467f4addbSFrank Haverkamp 68567f4addbSFrank Haverkamp /** 68667f4addbSFrank Haverkamp * genwqe_card_reset() - Reset the card 68767f4addbSFrank Haverkamp * @cd: pointer to the genwqe device descriptor 68867f4addbSFrank Haverkamp */ 68967f4addbSFrank Haverkamp int genwqe_card_reset(struct genwqe_dev *cd) 69067f4addbSFrank Haverkamp { 69167f4addbSFrank Haverkamp u64 softrst; 69267f4addbSFrank Haverkamp struct pci_dev *pci_dev = cd->pci_dev; 69367f4addbSFrank Haverkamp 69467f4addbSFrank Haverkamp if (!genwqe_is_privileged(cd)) 69567f4addbSFrank Haverkamp return -ENODEV; 69667f4addbSFrank Haverkamp 69767f4addbSFrank Haverkamp /* new SL */ 69867f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, 0x1ull); 69967f4addbSFrank Haverkamp msleep(1000); 70067f4addbSFrank Haverkamp __genwqe_readq(cd, IO_HSU_FIR_CLR); 70167f4addbSFrank Haverkamp __genwqe_readq(cd, IO_APP_FIR_CLR); 70267f4addbSFrank Haverkamp __genwqe_readq(cd, IO_SLU_FIR_CLR); 70367f4addbSFrank Haverkamp 70467f4addbSFrank Haverkamp /* 70567f4addbSFrank Haverkamp * Read-modify-write to preserve the stealth bits 70667f4addbSFrank Haverkamp * 70767f4addbSFrank Haverkamp * For SL >= 039, Stealth WE bit allows removing 70867f4addbSFrank Haverkamp * the read-modify-wrote. 70967f4addbSFrank Haverkamp * r-m-w may require a mask 0x3C to avoid hitting hard 71067f4addbSFrank Haverkamp * reset again for error reset (should be 0, chicken). 71167f4addbSFrank Haverkamp */ 71267f4addbSFrank Haverkamp softrst = __genwqe_readq(cd, IO_SLC_CFGREG_SOFTRESET) & 0x3cull; 71367f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_CFGREG_SOFTRESET, softrst | 0x2ull); 71467f4addbSFrank Haverkamp 71567f4addbSFrank Haverkamp /* give ERRORRESET some time to finish */ 71667f4addbSFrank Haverkamp msleep(50); 71767f4addbSFrank Haverkamp 71867f4addbSFrank Haverkamp if (genwqe_need_err_masking(cd)) { 71967f4addbSFrank Haverkamp dev_info(&pci_dev->dev, 72067f4addbSFrank Haverkamp "[%s] masking errors for old bitstreams\n", __func__); 72167f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG, 0x0aull); 72267f4addbSFrank Haverkamp } 72367f4addbSFrank Haverkamp return 0; 72467f4addbSFrank Haverkamp } 72567f4addbSFrank Haverkamp 72667f4addbSFrank Haverkamp int genwqe_read_softreset(struct genwqe_dev *cd) 72767f4addbSFrank Haverkamp { 72867f4addbSFrank Haverkamp u64 bitstream; 72967f4addbSFrank Haverkamp 73067f4addbSFrank Haverkamp if (!genwqe_is_privileged(cd)) 73167f4addbSFrank Haverkamp return -ENODEV; 73267f4addbSFrank Haverkamp 73367f4addbSFrank Haverkamp bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM) & 0x1; 73467f4addbSFrank Haverkamp cd->softreset = (bitstream == 0) ? 0x8ull : 0xcull; 73567f4addbSFrank Haverkamp return 0; 73667f4addbSFrank Haverkamp } 73767f4addbSFrank Haverkamp 73867f4addbSFrank Haverkamp /** 73967f4addbSFrank Haverkamp * genwqe_set_interrupt_capability() - Configure MSI capability structure 74067f4addbSFrank Haverkamp * @cd: pointer to the device 74167f4addbSFrank Haverkamp * Return: 0 if no error 74267f4addbSFrank Haverkamp */ 74367f4addbSFrank Haverkamp int genwqe_set_interrupt_capability(struct genwqe_dev *cd, int count) 74467f4addbSFrank Haverkamp { 74567f4addbSFrank Haverkamp int rc; 74667f4addbSFrank Haverkamp 747d3f45647SChristoph Hellwig rc = pci_alloc_irq_vectors(cd->pci_dev, 1, count, PCI_IRQ_MSI); 7487276883fSSebastian Ott if (rc < 0) 74967f4addbSFrank Haverkamp return rc; 7507276883fSSebastian Ott return 0; 75167f4addbSFrank Haverkamp } 75267f4addbSFrank Haverkamp 75367f4addbSFrank Haverkamp /** 75467f4addbSFrank Haverkamp * genwqe_reset_interrupt_capability() - Undo genwqe_set_interrupt_capability() 75567f4addbSFrank Haverkamp * @cd: pointer to the device 75667f4addbSFrank Haverkamp */ 75767f4addbSFrank Haverkamp void genwqe_reset_interrupt_capability(struct genwqe_dev *cd) 75867f4addbSFrank Haverkamp { 759d3f45647SChristoph Hellwig pci_free_irq_vectors(cd->pci_dev); 76067f4addbSFrank Haverkamp } 76167f4addbSFrank Haverkamp 76267f4addbSFrank Haverkamp /** 76367f4addbSFrank Haverkamp * set_reg_idx() - Fill array with data. Ignore illegal offsets. 76467f4addbSFrank Haverkamp * @cd: card device 76567f4addbSFrank Haverkamp * @r: debug register array 76667f4addbSFrank Haverkamp * @i: index to desired entry 76767f4addbSFrank Haverkamp * @m: maximum possible entries 76867f4addbSFrank Haverkamp * @addr: addr which is read 76967f4addbSFrank Haverkamp * @index: index in debug array 77067f4addbSFrank Haverkamp * @val: read value 77167f4addbSFrank Haverkamp */ 77267f4addbSFrank Haverkamp static int set_reg_idx(struct genwqe_dev *cd, struct genwqe_reg *r, 77367f4addbSFrank Haverkamp unsigned int *i, unsigned int m, u32 addr, u32 idx, 77467f4addbSFrank Haverkamp u64 val) 77567f4addbSFrank Haverkamp { 77667f4addbSFrank Haverkamp if (WARN_ON_ONCE(*i >= m)) 77767f4addbSFrank Haverkamp return -EFAULT; 77867f4addbSFrank Haverkamp 77967f4addbSFrank Haverkamp r[*i].addr = addr; 78067f4addbSFrank Haverkamp r[*i].idx = idx; 78167f4addbSFrank Haverkamp r[*i].val = val; 78267f4addbSFrank Haverkamp ++*i; 78367f4addbSFrank Haverkamp return 0; 78467f4addbSFrank Haverkamp } 78567f4addbSFrank Haverkamp 78667f4addbSFrank Haverkamp static int set_reg(struct genwqe_dev *cd, struct genwqe_reg *r, 78767f4addbSFrank Haverkamp unsigned int *i, unsigned int m, u32 addr, u64 val) 78867f4addbSFrank Haverkamp { 78967f4addbSFrank Haverkamp return set_reg_idx(cd, r, i, m, addr, 0, val); 79067f4addbSFrank Haverkamp } 79167f4addbSFrank Haverkamp 79267f4addbSFrank Haverkamp int genwqe_read_ffdc_regs(struct genwqe_dev *cd, struct genwqe_reg *regs, 79367f4addbSFrank Haverkamp unsigned int max_regs, int all) 79467f4addbSFrank Haverkamp { 79567f4addbSFrank Haverkamp unsigned int i, j, idx = 0; 79667f4addbSFrank Haverkamp u32 ufir_addr, ufec_addr, sfir_addr, sfec_addr; 79767f4addbSFrank Haverkamp u64 gfir, sluid, appid, ufir, ufec, sfir, sfec; 79867f4addbSFrank Haverkamp 79967f4addbSFrank Haverkamp /* Global FIR */ 80067f4addbSFrank Haverkamp gfir = __genwqe_readq(cd, IO_SLC_CFGREG_GFIR); 80167f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_SLC_CFGREG_GFIR, gfir); 80267f4addbSFrank Haverkamp 80367f4addbSFrank Haverkamp /* UnitCfg for SLU */ 80467f4addbSFrank Haverkamp sluid = __genwqe_readq(cd, IO_SLU_UNITCFG); /* 0x00000000 */ 80567f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_SLU_UNITCFG, sluid); 80667f4addbSFrank Haverkamp 80767f4addbSFrank Haverkamp /* UnitCfg for APP */ 80867f4addbSFrank Haverkamp appid = __genwqe_readq(cd, IO_APP_UNITCFG); /* 0x02000000 */ 80967f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, IO_APP_UNITCFG, appid); 81067f4addbSFrank Haverkamp 81167f4addbSFrank Haverkamp /* Check all chip Units */ 81267f4addbSFrank Haverkamp for (i = 0; i < GENWQE_MAX_UNITS; i++) { 81367f4addbSFrank Haverkamp 81467f4addbSFrank Haverkamp /* Unit FIR */ 81567f4addbSFrank Haverkamp ufir_addr = (i << 24) | 0x008; 81667f4addbSFrank Haverkamp ufir = __genwqe_readq(cd, ufir_addr); 81767f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, ufir_addr, ufir); 81867f4addbSFrank Haverkamp 81967f4addbSFrank Haverkamp /* Unit FEC */ 82067f4addbSFrank Haverkamp ufec_addr = (i << 24) | 0x018; 82167f4addbSFrank Haverkamp ufec = __genwqe_readq(cd, ufec_addr); 82267f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, ufec_addr, ufec); 82367f4addbSFrank Haverkamp 82467f4addbSFrank Haverkamp for (j = 0; j < 64; j++) { 82567f4addbSFrank Haverkamp /* wherever there is a primary 1, read the 2ndary */ 82667f4addbSFrank Haverkamp if (!all && (!(ufir & (1ull << j)))) 82767f4addbSFrank Haverkamp continue; 82867f4addbSFrank Haverkamp 82967f4addbSFrank Haverkamp sfir_addr = (i << 24) | (0x100 + 8 * j); 83067f4addbSFrank Haverkamp sfir = __genwqe_readq(cd, sfir_addr); 83167f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, sfir_addr, sfir); 83267f4addbSFrank Haverkamp 83367f4addbSFrank Haverkamp sfec_addr = (i << 24) | (0x300 + 8 * j); 83467f4addbSFrank Haverkamp sfec = __genwqe_readq(cd, sfec_addr); 83567f4addbSFrank Haverkamp set_reg(cd, regs, &idx, max_regs, sfec_addr, sfec); 83667f4addbSFrank Haverkamp } 83767f4addbSFrank Haverkamp } 83867f4addbSFrank Haverkamp 83967f4addbSFrank Haverkamp /* fill with invalid data until end */ 84067f4addbSFrank Haverkamp for (i = idx; i < max_regs; i++) { 84167f4addbSFrank Haverkamp regs[i].addr = 0xffffffff; 84267f4addbSFrank Haverkamp regs[i].val = 0xffffffffffffffffull; 84367f4addbSFrank Haverkamp } 84467f4addbSFrank Haverkamp return idx; 84567f4addbSFrank Haverkamp } 84667f4addbSFrank Haverkamp 84767f4addbSFrank Haverkamp /** 84867f4addbSFrank Haverkamp * genwqe_ffdc_buff_size() - Calculates the number of dump registers 84967f4addbSFrank Haverkamp */ 85067f4addbSFrank Haverkamp int genwqe_ffdc_buff_size(struct genwqe_dev *cd, int uid) 85167f4addbSFrank Haverkamp { 85267f4addbSFrank Haverkamp int entries = 0, ring, traps, traces, trace_entries; 85367f4addbSFrank Haverkamp u32 eevptr_addr, l_addr, d_len, d_type; 85467f4addbSFrank Haverkamp u64 eevptr, val, addr; 85567f4addbSFrank Haverkamp 85667f4addbSFrank Haverkamp eevptr_addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_ERROR_POINTER; 85767f4addbSFrank Haverkamp eevptr = __genwqe_readq(cd, eevptr_addr); 85867f4addbSFrank Haverkamp 85967f4addbSFrank Haverkamp if ((eevptr != 0x0) && (eevptr != -1ull)) { 86067f4addbSFrank Haverkamp l_addr = GENWQE_UID_OFFS(uid) | eevptr; 86167f4addbSFrank Haverkamp 86267f4addbSFrank Haverkamp while (1) { 86367f4addbSFrank Haverkamp val = __genwqe_readq(cd, l_addr); 86467f4addbSFrank Haverkamp 86567f4addbSFrank Haverkamp if ((val == 0x0) || (val == -1ull)) 86667f4addbSFrank Haverkamp break; 86767f4addbSFrank Haverkamp 86867f4addbSFrank Haverkamp /* 38:24 */ 86967f4addbSFrank Haverkamp d_len = (val & 0x0000007fff000000ull) >> 24; 87067f4addbSFrank Haverkamp 87167f4addbSFrank Haverkamp /* 39 */ 87267f4addbSFrank Haverkamp d_type = (val & 0x0000008000000000ull) >> 36; 87367f4addbSFrank Haverkamp 87467f4addbSFrank Haverkamp if (d_type) { /* repeat */ 87567f4addbSFrank Haverkamp entries += d_len; 87667f4addbSFrank Haverkamp } else { /* size in bytes! */ 87767f4addbSFrank Haverkamp entries += d_len >> 3; 87867f4addbSFrank Haverkamp } 87967f4addbSFrank Haverkamp 88067f4addbSFrank Haverkamp l_addr += 8; 88167f4addbSFrank Haverkamp } 88267f4addbSFrank Haverkamp } 88367f4addbSFrank Haverkamp 88467f4addbSFrank Haverkamp for (ring = 0; ring < 8; ring++) { 88567f4addbSFrank Haverkamp addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_DIAG_MAP(ring); 88667f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 88767f4addbSFrank Haverkamp 88867f4addbSFrank Haverkamp if ((val == 0x0ull) || (val == -1ull)) 88967f4addbSFrank Haverkamp continue; 89067f4addbSFrank Haverkamp 89167f4addbSFrank Haverkamp traps = (val >> 24) & 0xff; 89267f4addbSFrank Haverkamp traces = (val >> 16) & 0xff; 89367f4addbSFrank Haverkamp trace_entries = val & 0xffff; 89467f4addbSFrank Haverkamp 89567f4addbSFrank Haverkamp entries += traps + (traces * trace_entries); 89667f4addbSFrank Haverkamp } 89767f4addbSFrank Haverkamp return entries; 89867f4addbSFrank Haverkamp } 89967f4addbSFrank Haverkamp 90067f4addbSFrank Haverkamp /** 90167f4addbSFrank Haverkamp * genwqe_ffdc_buff_read() - Implements LogoutExtendedErrorRegisters procedure 90267f4addbSFrank Haverkamp */ 90367f4addbSFrank Haverkamp int genwqe_ffdc_buff_read(struct genwqe_dev *cd, int uid, 90467f4addbSFrank Haverkamp struct genwqe_reg *regs, unsigned int max_regs) 90567f4addbSFrank Haverkamp { 90667f4addbSFrank Haverkamp int i, traps, traces, trace, trace_entries, trace_entry, ring; 90767f4addbSFrank Haverkamp unsigned int idx = 0; 90867f4addbSFrank Haverkamp u32 eevptr_addr, l_addr, d_addr, d_len, d_type; 90967f4addbSFrank Haverkamp u64 eevptr, e, val, addr; 91067f4addbSFrank Haverkamp 91167f4addbSFrank Haverkamp eevptr_addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_ERROR_POINTER; 91267f4addbSFrank Haverkamp eevptr = __genwqe_readq(cd, eevptr_addr); 91367f4addbSFrank Haverkamp 91467f4addbSFrank Haverkamp if ((eevptr != 0x0) && (eevptr != 0xffffffffffffffffull)) { 91567f4addbSFrank Haverkamp l_addr = GENWQE_UID_OFFS(uid) | eevptr; 91667f4addbSFrank Haverkamp while (1) { 91767f4addbSFrank Haverkamp e = __genwqe_readq(cd, l_addr); 91867f4addbSFrank Haverkamp if ((e == 0x0) || (e == 0xffffffffffffffffull)) 91967f4addbSFrank Haverkamp break; 92067f4addbSFrank Haverkamp 92167f4addbSFrank Haverkamp d_addr = (e & 0x0000000000ffffffull); /* 23:0 */ 92267f4addbSFrank Haverkamp d_len = (e & 0x0000007fff000000ull) >> 24; /* 38:24 */ 92367f4addbSFrank Haverkamp d_type = (e & 0x0000008000000000ull) >> 36; /* 39 */ 92467f4addbSFrank Haverkamp d_addr |= GENWQE_UID_OFFS(uid); 92567f4addbSFrank Haverkamp 92667f4addbSFrank Haverkamp if (d_type) { 92767f4addbSFrank Haverkamp for (i = 0; i < (int)d_len; i++) { 92867f4addbSFrank Haverkamp val = __genwqe_readq(cd, d_addr); 92967f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, 93067f4addbSFrank Haverkamp d_addr, i, val); 93167f4addbSFrank Haverkamp } 93267f4addbSFrank Haverkamp } else { 93367f4addbSFrank Haverkamp d_len >>= 3; /* Size in bytes! */ 93467f4addbSFrank Haverkamp for (i = 0; i < (int)d_len; i++, d_addr += 8) { 93567f4addbSFrank Haverkamp val = __genwqe_readq(cd, d_addr); 93667f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, 93767f4addbSFrank Haverkamp d_addr, 0, val); 93867f4addbSFrank Haverkamp } 93967f4addbSFrank Haverkamp } 94067f4addbSFrank Haverkamp l_addr += 8; 94167f4addbSFrank Haverkamp } 94267f4addbSFrank Haverkamp } 94367f4addbSFrank Haverkamp 94467f4addbSFrank Haverkamp /* 94567f4addbSFrank Haverkamp * To save time, there are only 6 traces poplulated on Uid=2, 94667f4addbSFrank Haverkamp * Ring=1. each with iters=512. 94767f4addbSFrank Haverkamp */ 94867f4addbSFrank Haverkamp for (ring = 0; ring < 8; ring++) { /* 0 is fls, 1 is fds, 94967f4addbSFrank Haverkamp 2...7 are ASI rings */ 95067f4addbSFrank Haverkamp addr = GENWQE_UID_OFFS(uid) | IO_EXTENDED_DIAG_MAP(ring); 95167f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 95267f4addbSFrank Haverkamp 95367f4addbSFrank Haverkamp if ((val == 0x0ull) || (val == -1ull)) 95467f4addbSFrank Haverkamp continue; 95567f4addbSFrank Haverkamp 95667f4addbSFrank Haverkamp traps = (val >> 24) & 0xff; /* Number of Traps */ 95767f4addbSFrank Haverkamp traces = (val >> 16) & 0xff; /* Number of Traces */ 95867f4addbSFrank Haverkamp trace_entries = val & 0xffff; /* Entries per trace */ 95967f4addbSFrank Haverkamp 96067f4addbSFrank Haverkamp /* Note: This is a combined loop that dumps both the traps */ 96167f4addbSFrank Haverkamp /* (for the trace == 0 case) as well as the traces 1 to */ 96267f4addbSFrank Haverkamp /* 'traces'. */ 96367f4addbSFrank Haverkamp for (trace = 0; trace <= traces; trace++) { 96467f4addbSFrank Haverkamp u32 diag_sel = 96567f4addbSFrank Haverkamp GENWQE_EXTENDED_DIAG_SELECTOR(ring, trace); 96667f4addbSFrank Haverkamp 96767f4addbSFrank Haverkamp addr = (GENWQE_UID_OFFS(uid) | 96867f4addbSFrank Haverkamp IO_EXTENDED_DIAG_SELECTOR); 96967f4addbSFrank Haverkamp __genwqe_writeq(cd, addr, diag_sel); 97067f4addbSFrank Haverkamp 97167f4addbSFrank Haverkamp for (trace_entry = 0; 97267f4addbSFrank Haverkamp trace_entry < (trace ? trace_entries : traps); 97367f4addbSFrank Haverkamp trace_entry++) { 97467f4addbSFrank Haverkamp addr = (GENWQE_UID_OFFS(uid) | 97567f4addbSFrank Haverkamp IO_EXTENDED_DIAG_READ_MBX); 97667f4addbSFrank Haverkamp val = __genwqe_readq(cd, addr); 97767f4addbSFrank Haverkamp set_reg_idx(cd, regs, &idx, max_regs, addr, 97867f4addbSFrank Haverkamp (diag_sel<<16) | trace_entry, val); 97967f4addbSFrank Haverkamp } 98067f4addbSFrank Haverkamp } 98167f4addbSFrank Haverkamp } 98267f4addbSFrank Haverkamp return 0; 98367f4addbSFrank Haverkamp } 98467f4addbSFrank Haverkamp 98567f4addbSFrank Haverkamp /** 98667f4addbSFrank Haverkamp * genwqe_write_vreg() - Write register in virtual window 98767f4addbSFrank Haverkamp * 98867f4addbSFrank Haverkamp * Note, these registers are only accessible to the PF through the 98967f4addbSFrank Haverkamp * VF-window. It is not intended for the VF to access. 99067f4addbSFrank Haverkamp */ 99167f4addbSFrank Haverkamp int genwqe_write_vreg(struct genwqe_dev *cd, u32 reg, u64 val, int func) 99267f4addbSFrank Haverkamp { 99367f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_PF_SLC_VIRTUAL_WINDOW, func & 0xf); 99467f4addbSFrank Haverkamp __genwqe_writeq(cd, reg, val); 99567f4addbSFrank Haverkamp return 0; 99667f4addbSFrank Haverkamp } 99767f4addbSFrank Haverkamp 99867f4addbSFrank Haverkamp /** 99967f4addbSFrank Haverkamp * genwqe_read_vreg() - Read register in virtual window 100067f4addbSFrank Haverkamp * 100167f4addbSFrank Haverkamp * Note, these registers are only accessible to the PF through the 100267f4addbSFrank Haverkamp * VF-window. It is not intended for the VF to access. 100367f4addbSFrank Haverkamp */ 100467f4addbSFrank Haverkamp u64 genwqe_read_vreg(struct genwqe_dev *cd, u32 reg, int func) 100567f4addbSFrank Haverkamp { 100667f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_PF_SLC_VIRTUAL_WINDOW, func & 0xf); 100767f4addbSFrank Haverkamp return __genwqe_readq(cd, reg); 100867f4addbSFrank Haverkamp } 100967f4addbSFrank Haverkamp 101067f4addbSFrank Haverkamp /** 101167f4addbSFrank Haverkamp * genwqe_base_clock_frequency() - Deteremine base clock frequency of the card 101267f4addbSFrank Haverkamp * 101367f4addbSFrank Haverkamp * Note: From a design perspective it turned out to be a bad idea to 101467f4addbSFrank Haverkamp * use codes here to specifiy the frequency/speed values. An old 101567f4addbSFrank Haverkamp * driver cannot understand new codes and is therefore always a 101667f4addbSFrank Haverkamp * problem. Better is to measure out the value or put the 101767f4addbSFrank Haverkamp * speed/frequency directly into a register which is always a valid 101867f4addbSFrank Haverkamp * value for old as well as for new software. 101967f4addbSFrank Haverkamp * 102067f4addbSFrank Haverkamp * Return: Card clock in MHz 102167f4addbSFrank Haverkamp */ 102267f4addbSFrank Haverkamp int genwqe_base_clock_frequency(struct genwqe_dev *cd) 102367f4addbSFrank Haverkamp { 102467f4addbSFrank Haverkamp u16 speed; /* MHz MHz MHz MHz */ 102567f4addbSFrank Haverkamp static const int speed_grade[] = { 250, 200, 166, 175 }; 102667f4addbSFrank Haverkamp 102767f4addbSFrank Haverkamp speed = (u16)((cd->slu_unitcfg >> 28) & 0x0full); 102867f4addbSFrank Haverkamp if (speed >= ARRAY_SIZE(speed_grade)) 102967f4addbSFrank Haverkamp return 0; /* illegal value */ 103067f4addbSFrank Haverkamp 103167f4addbSFrank Haverkamp return speed_grade[speed]; 103267f4addbSFrank Haverkamp } 103367f4addbSFrank Haverkamp 103467f4addbSFrank Haverkamp /** 103567f4addbSFrank Haverkamp * genwqe_stop_traps() - Stop traps 103667f4addbSFrank Haverkamp * 103767f4addbSFrank Haverkamp * Before reading out the analysis data, we need to stop the traps. 103867f4addbSFrank Haverkamp */ 103967f4addbSFrank Haverkamp void genwqe_stop_traps(struct genwqe_dev *cd) 104067f4addbSFrank Haverkamp { 104167f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG_SET, 0xcull); 104267f4addbSFrank Haverkamp } 104367f4addbSFrank Haverkamp 104467f4addbSFrank Haverkamp /** 104567f4addbSFrank Haverkamp * genwqe_start_traps() - Start traps 104667f4addbSFrank Haverkamp * 104767f4addbSFrank Haverkamp * After having read the data, we can/must enable the traps again. 104867f4addbSFrank Haverkamp */ 104967f4addbSFrank Haverkamp void genwqe_start_traps(struct genwqe_dev *cd) 105067f4addbSFrank Haverkamp { 105167f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG_CLR, 0xcull); 105267f4addbSFrank Haverkamp 105367f4addbSFrank Haverkamp if (genwqe_need_err_masking(cd)) 105467f4addbSFrank Haverkamp __genwqe_writeq(cd, IO_SLC_MISC_DEBUG, 0x0aull); 105567f4addbSFrank Haverkamp } 1056