Linux 5.1.15
[linux/fpc-iii.git] / drivers / scsi / cxlflash / cxl_hw.c
blobb42da88386bddf9260bd778b90b0a19638a3b29d
1 /*
2 * CXL Flash Device Driver
4 * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
5 * Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
7 * Copyright (C) 2018 IBM Corporation
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 #include <misc/cxl.h>
17 #include "backend.h"
20 * The following routines map the cxlflash backend operations to existing CXL
21 * kernel API function and are largely simple shims that provide an abstraction
22 * for converting generic context and AFU cookies into cxl_context or cxl_afu
23 * pointers.
26 static void __iomem *cxlflash_psa_map(void *ctx_cookie)
28 return cxl_psa_map(ctx_cookie);
31 static void cxlflash_psa_unmap(void __iomem *addr)
33 cxl_psa_unmap(addr);
36 static int cxlflash_process_element(void *ctx_cookie)
38 return cxl_process_element(ctx_cookie);
41 static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
42 irq_handler_t handler, void *cookie, char *name)
44 return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
47 static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
49 cxl_unmap_afu_irq(ctx_cookie, num, cookie);
52 static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
54 /* Dummy fop for cxl */
55 return 0;
58 static int cxlflash_start_context(void *ctx_cookie)
60 return cxl_start_context(ctx_cookie, 0, NULL);
63 static int cxlflash_stop_context(void *ctx_cookie)
65 return cxl_stop_context(ctx_cookie);
68 static int cxlflash_afu_reset(void *ctx_cookie)
70 return cxl_afu_reset(ctx_cookie);
73 static void cxlflash_set_master(void *ctx_cookie)
75 cxl_set_master(ctx_cookie);
78 static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
80 return cxl_get_context(dev);
83 static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
85 return cxl_dev_context_init(dev);
88 static int cxlflash_release_context(void *ctx_cookie)
90 return cxl_release_context(ctx_cookie);
93 static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
95 cxl_perst_reloads_same_image(afu_cookie, image);
98 static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
99 void *buf, size_t count)
101 return cxl_read_adapter_vpd(dev, buf, count);
104 static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
106 return cxl_allocate_afu_irqs(ctx_cookie, num);
109 static void cxlflash_free_afu_irqs(void *ctx_cookie)
111 cxl_free_afu_irqs(ctx_cookie);
114 static void *cxlflash_create_afu(struct pci_dev *dev)
116 return cxl_pci_to_afu(dev);
119 static void cxlflash_destroy_afu(void *afu)
121 /* Dummy fop for cxl */
124 static struct file *cxlflash_get_fd(void *ctx_cookie,
125 struct file_operations *fops, int *fd)
127 return cxl_get_fd(ctx_cookie, fops, fd);
130 static void *cxlflash_fops_get_context(struct file *file)
132 return cxl_fops_get_context(file);
135 static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
137 struct cxl_ioctl_start_work work = { 0 };
139 work.num_interrupts = irqs;
140 work.flags = CXL_START_WORK_NUM_IRQS;
142 return cxl_start_work(ctx_cookie, &work);
145 static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
147 return cxl_fd_mmap(file, vm);
150 static int cxlflash_fd_release(struct inode *inode, struct file *file)
152 return cxl_fd_release(inode, file);
155 const struct cxlflash_backend_ops cxlflash_cxl_ops = {
156 .module = THIS_MODULE,
157 .psa_map = cxlflash_psa_map,
158 .psa_unmap = cxlflash_psa_unmap,
159 .process_element = cxlflash_process_element,
160 .map_afu_irq = cxlflash_map_afu_irq,
161 .unmap_afu_irq = cxlflash_unmap_afu_irq,
162 .get_irq_objhndl = cxlflash_get_irq_objhndl,
163 .start_context = cxlflash_start_context,
164 .stop_context = cxlflash_stop_context,
165 .afu_reset = cxlflash_afu_reset,
166 .set_master = cxlflash_set_master,
167 .get_context = cxlflash_get_context,
168 .dev_context_init = cxlflash_dev_context_init,
169 .release_context = cxlflash_release_context,
170 .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
171 .read_adapter_vpd = cxlflash_read_adapter_vpd,
172 .allocate_afu_irqs = cxlflash_allocate_afu_irqs,
173 .free_afu_irqs = cxlflash_free_afu_irqs,
174 .create_afu = cxlflash_create_afu,
175 .destroy_afu = cxlflash_destroy_afu,
176 .get_fd = cxlflash_get_fd,
177 .fops_get_context = cxlflash_fops_get_context,
178 .start_work = cxlflash_start_work,
179 .fd_mmap = cxlflash_fd_mmap,
180 .fd_release = cxlflash_fd_release,