1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * CXL Flash Device Driver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6*4882a593Smuzhiyun * Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright (C) 2018 IBM Corporation
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <misc/cxl.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include "backend.h"
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun * The following routines map the cxlflash backend operations to existing CXL
17*4882a593Smuzhiyun * kernel API function and are largely simple shims that provide an abstraction
18*4882a593Smuzhiyun * for converting generic context and AFU cookies into cxl_context or cxl_afu
19*4882a593Smuzhiyun * pointers.
20*4882a593Smuzhiyun */
21*4882a593Smuzhiyun
cxlflash_psa_map(void * ctx_cookie)22*4882a593Smuzhiyun static void __iomem *cxlflash_psa_map(void *ctx_cookie)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun return cxl_psa_map(ctx_cookie);
25*4882a593Smuzhiyun }
26*4882a593Smuzhiyun
cxlflash_psa_unmap(void __iomem * addr)27*4882a593Smuzhiyun static void cxlflash_psa_unmap(void __iomem *addr)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun cxl_psa_unmap(addr);
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun
cxlflash_process_element(void * ctx_cookie)32*4882a593Smuzhiyun static int cxlflash_process_element(void *ctx_cookie)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun return cxl_process_element(ctx_cookie);
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun
cxlflash_map_afu_irq(void * ctx_cookie,int num,irq_handler_t handler,void * cookie,char * name)37*4882a593Smuzhiyun static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
38*4882a593Smuzhiyun irq_handler_t handler, void *cookie, char *name)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun
cxlflash_unmap_afu_irq(void * ctx_cookie,int num,void * cookie)43*4882a593Smuzhiyun static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun cxl_unmap_afu_irq(ctx_cookie, num, cookie);
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
cxlflash_get_irq_objhndl(void * ctx_cookie,int irq)48*4882a593Smuzhiyun static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun /* Dummy fop for cxl */
51*4882a593Smuzhiyun return 0;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
cxlflash_start_context(void * ctx_cookie)54*4882a593Smuzhiyun static int cxlflash_start_context(void *ctx_cookie)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun return cxl_start_context(ctx_cookie, 0, NULL);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
cxlflash_stop_context(void * ctx_cookie)59*4882a593Smuzhiyun static int cxlflash_stop_context(void *ctx_cookie)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun return cxl_stop_context(ctx_cookie);
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
cxlflash_afu_reset(void * ctx_cookie)64*4882a593Smuzhiyun static int cxlflash_afu_reset(void *ctx_cookie)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun return cxl_afu_reset(ctx_cookie);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
cxlflash_set_master(void * ctx_cookie)69*4882a593Smuzhiyun static void cxlflash_set_master(void *ctx_cookie)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun cxl_set_master(ctx_cookie);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
cxlflash_get_context(struct pci_dev * dev,void * afu_cookie)74*4882a593Smuzhiyun static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun return cxl_get_context(dev);
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun
cxlflash_dev_context_init(struct pci_dev * dev,void * afu_cookie)79*4882a593Smuzhiyun static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun return cxl_dev_context_init(dev);
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun
cxlflash_release_context(void * ctx_cookie)84*4882a593Smuzhiyun static int cxlflash_release_context(void *ctx_cookie)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun return cxl_release_context(ctx_cookie);
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
cxlflash_perst_reloads_same_image(void * afu_cookie,bool image)89*4882a593Smuzhiyun static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun cxl_perst_reloads_same_image(afu_cookie, image);
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
cxlflash_read_adapter_vpd(struct pci_dev * dev,void * buf,size_t count)94*4882a593Smuzhiyun static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
95*4882a593Smuzhiyun void *buf, size_t count)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun return cxl_read_adapter_vpd(dev, buf, count);
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun
cxlflash_allocate_afu_irqs(void * ctx_cookie,int num)100*4882a593Smuzhiyun static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
101*4882a593Smuzhiyun {
102*4882a593Smuzhiyun return cxl_allocate_afu_irqs(ctx_cookie, num);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
cxlflash_free_afu_irqs(void * ctx_cookie)105*4882a593Smuzhiyun static void cxlflash_free_afu_irqs(void *ctx_cookie)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun cxl_free_afu_irqs(ctx_cookie);
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun
cxlflash_create_afu(struct pci_dev * dev)110*4882a593Smuzhiyun static void *cxlflash_create_afu(struct pci_dev *dev)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun return cxl_pci_to_afu(dev);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
cxlflash_destroy_afu(void * afu)115*4882a593Smuzhiyun static void cxlflash_destroy_afu(void *afu)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun /* Dummy fop for cxl */
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
cxlflash_get_fd(void * ctx_cookie,struct file_operations * fops,int * fd)120*4882a593Smuzhiyun static struct file *cxlflash_get_fd(void *ctx_cookie,
121*4882a593Smuzhiyun struct file_operations *fops, int *fd)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun return cxl_get_fd(ctx_cookie, fops, fd);
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun
cxlflash_fops_get_context(struct file * file)126*4882a593Smuzhiyun static void *cxlflash_fops_get_context(struct file *file)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun return cxl_fops_get_context(file);
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun
cxlflash_start_work(void * ctx_cookie,u64 irqs)131*4882a593Smuzhiyun static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
132*4882a593Smuzhiyun {
133*4882a593Smuzhiyun struct cxl_ioctl_start_work work = { 0 };
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun work.num_interrupts = irqs;
136*4882a593Smuzhiyun work.flags = CXL_START_WORK_NUM_IRQS;
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return cxl_start_work(ctx_cookie, &work);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
cxlflash_fd_mmap(struct file * file,struct vm_area_struct * vm)141*4882a593Smuzhiyun static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun return cxl_fd_mmap(file, vm);
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun
cxlflash_fd_release(struct inode * inode,struct file * file)146*4882a593Smuzhiyun static int cxlflash_fd_release(struct inode *inode, struct file *file)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun return cxl_fd_release(inode, file);
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun const struct cxlflash_backend_ops cxlflash_cxl_ops = {
152*4882a593Smuzhiyun .module = THIS_MODULE,
153*4882a593Smuzhiyun .psa_map = cxlflash_psa_map,
154*4882a593Smuzhiyun .psa_unmap = cxlflash_psa_unmap,
155*4882a593Smuzhiyun .process_element = cxlflash_process_element,
156*4882a593Smuzhiyun .map_afu_irq = cxlflash_map_afu_irq,
157*4882a593Smuzhiyun .unmap_afu_irq = cxlflash_unmap_afu_irq,
158*4882a593Smuzhiyun .get_irq_objhndl = cxlflash_get_irq_objhndl,
159*4882a593Smuzhiyun .start_context = cxlflash_start_context,
160*4882a593Smuzhiyun .stop_context = cxlflash_stop_context,
161*4882a593Smuzhiyun .afu_reset = cxlflash_afu_reset,
162*4882a593Smuzhiyun .set_master = cxlflash_set_master,
163*4882a593Smuzhiyun .get_context = cxlflash_get_context,
164*4882a593Smuzhiyun .dev_context_init = cxlflash_dev_context_init,
165*4882a593Smuzhiyun .release_context = cxlflash_release_context,
166*4882a593Smuzhiyun .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
167*4882a593Smuzhiyun .read_adapter_vpd = cxlflash_read_adapter_vpd,
168*4882a593Smuzhiyun .allocate_afu_irqs = cxlflash_allocate_afu_irqs,
169*4882a593Smuzhiyun .free_afu_irqs = cxlflash_free_afu_irqs,
170*4882a593Smuzhiyun .create_afu = cxlflash_create_afu,
171*4882a593Smuzhiyun .destroy_afu = cxlflash_destroy_afu,
172*4882a593Smuzhiyun .get_fd = cxlflash_get_fd,
173*4882a593Smuzhiyun .fops_get_context = cxlflash_fops_get_context,
174*4882a593Smuzhiyun .start_work = cxlflash_start_work,
175*4882a593Smuzhiyun .fd_mmap = cxlflash_fd_mmap,
176*4882a593Smuzhiyun .fd_release = cxlflash_fd_release,
177*4882a593Smuzhiyun };
178