Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / scsi / cxlflash / cxl_hw.c
blobb814130f3f5cb4f94e2b0c65e8abba0581605dd6
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * CXL Flash Device Driver
5 * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6 * Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
8 * Copyright (C) 2018 IBM Corporation
9 */
11 #include <misc/cxl.h>
13 #include "backend.h"
16 * The following routines map the cxlflash backend operations to existing CXL
17 * kernel API function and are largely simple shims that provide an abstraction
18 * for converting generic context and AFU cookies into cxl_context or cxl_afu
19 * pointers.
22 static void __iomem *cxlflash_psa_map(void *ctx_cookie)
24 return cxl_psa_map(ctx_cookie);
27 static void cxlflash_psa_unmap(void __iomem *addr)
29 cxl_psa_unmap(addr);
32 static int cxlflash_process_element(void *ctx_cookie)
34 return cxl_process_element(ctx_cookie);
37 static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
38 irq_handler_t handler, void *cookie, char *name)
40 return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
43 static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
45 cxl_unmap_afu_irq(ctx_cookie, num, cookie);
48 static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
50 /* Dummy fop for cxl */
51 return 0;
54 static int cxlflash_start_context(void *ctx_cookie)
56 return cxl_start_context(ctx_cookie, 0, NULL);
59 static int cxlflash_stop_context(void *ctx_cookie)
61 return cxl_stop_context(ctx_cookie);
64 static int cxlflash_afu_reset(void *ctx_cookie)
66 return cxl_afu_reset(ctx_cookie);
69 static void cxlflash_set_master(void *ctx_cookie)
71 cxl_set_master(ctx_cookie);
74 static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
76 return cxl_get_context(dev);
79 static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
81 return cxl_dev_context_init(dev);
84 static int cxlflash_release_context(void *ctx_cookie)
86 return cxl_release_context(ctx_cookie);
89 static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
91 cxl_perst_reloads_same_image(afu_cookie, image);
94 static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
95 void *buf, size_t count)
97 return cxl_read_adapter_vpd(dev, buf, count);
100 static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
102 return cxl_allocate_afu_irqs(ctx_cookie, num);
105 static void cxlflash_free_afu_irqs(void *ctx_cookie)
107 cxl_free_afu_irqs(ctx_cookie);
110 static void *cxlflash_create_afu(struct pci_dev *dev)
112 return cxl_pci_to_afu(dev);
115 static void cxlflash_destroy_afu(void *afu)
117 /* Dummy fop for cxl */
120 static struct file *cxlflash_get_fd(void *ctx_cookie,
121 struct file_operations *fops, int *fd)
123 return cxl_get_fd(ctx_cookie, fops, fd);
126 static void *cxlflash_fops_get_context(struct file *file)
128 return cxl_fops_get_context(file);
131 static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
133 struct cxl_ioctl_start_work work = { 0 };
135 work.num_interrupts = irqs;
136 work.flags = CXL_START_WORK_NUM_IRQS;
138 return cxl_start_work(ctx_cookie, &work);
141 static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
143 return cxl_fd_mmap(file, vm);
146 static int cxlflash_fd_release(struct inode *inode, struct file *file)
148 return cxl_fd_release(inode, file);
151 const struct cxlflash_backend_ops cxlflash_cxl_ops = {
152 .module = THIS_MODULE,
153 .psa_map = cxlflash_psa_map,
154 .psa_unmap = cxlflash_psa_unmap,
155 .process_element = cxlflash_process_element,
156 .map_afu_irq = cxlflash_map_afu_irq,
157 .unmap_afu_irq = cxlflash_unmap_afu_irq,
158 .get_irq_objhndl = cxlflash_get_irq_objhndl,
159 .start_context = cxlflash_start_context,
160 .stop_context = cxlflash_stop_context,
161 .afu_reset = cxlflash_afu_reset,
162 .set_master = cxlflash_set_master,
163 .get_context = cxlflash_get_context,
164 .dev_context_init = cxlflash_dev_context_init,
165 .release_context = cxlflash_release_context,
166 .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
167 .read_adapter_vpd = cxlflash_read_adapter_vpd,
168 .allocate_afu_irqs = cxlflash_allocate_afu_irqs,
169 .free_afu_irqs = cxlflash_free_afu_irqs,
170 .create_afu = cxlflash_create_afu,
171 .destroy_afu = cxlflash_destroy_afu,
172 .get_fd = cxlflash_get_fd,
173 .fops_get_context = cxlflash_fops_get_context,
174 .start_work = cxlflash_start_work,
175 .fd_mmap = cxlflash_fd_mmap,
176 .fd_release = cxlflash_fd_release,