12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
225b8e08eSMatthew R. Ochs /*
325b8e08eSMatthew R. Ochs * CXL Flash Device Driver
425b8e08eSMatthew R. Ochs *
525b8e08eSMatthew R. Ochs * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
625b8e08eSMatthew R. Ochs * Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
725b8e08eSMatthew R. Ochs *
825b8e08eSMatthew R. Ochs * Copyright (C) 2018 IBM Corporation
925b8e08eSMatthew R. Ochs */
1025b8e08eSMatthew R. Ochs
1125b8e08eSMatthew R. Ochs #include <misc/cxl.h>
1225b8e08eSMatthew R. Ochs
1325b8e08eSMatthew R. Ochs #include "backend.h"
1425b8e08eSMatthew R. Ochs
1525b8e08eSMatthew R. Ochs /*
1625b8e08eSMatthew R. Ochs * The following routines map the cxlflash backend operations to existing CXL
1725b8e08eSMatthew R. Ochs * kernel API function and are largely simple shims that provide an abstraction
1825b8e08eSMatthew R. Ochs * for converting generic context and AFU cookies into cxl_context or cxl_afu
1925b8e08eSMatthew R. Ochs * pointers.
2025b8e08eSMatthew R. Ochs */
2125b8e08eSMatthew R. Ochs
cxlflash_psa_map(void * ctx_cookie)2225b8e08eSMatthew R. Ochs static void __iomem *cxlflash_psa_map(void *ctx_cookie)
2325b8e08eSMatthew R. Ochs {
2425b8e08eSMatthew R. Ochs return cxl_psa_map(ctx_cookie);
2525b8e08eSMatthew R. Ochs }
2625b8e08eSMatthew R. Ochs
cxlflash_psa_unmap(void __iomem * addr)2725b8e08eSMatthew R. Ochs static void cxlflash_psa_unmap(void __iomem *addr)
2825b8e08eSMatthew R. Ochs {
2925b8e08eSMatthew R. Ochs cxl_psa_unmap(addr);
3025b8e08eSMatthew R. Ochs }
3125b8e08eSMatthew R. Ochs
cxlflash_process_element(void * ctx_cookie)3225b8e08eSMatthew R. Ochs static int cxlflash_process_element(void *ctx_cookie)
3325b8e08eSMatthew R. Ochs {
3425b8e08eSMatthew R. Ochs return cxl_process_element(ctx_cookie);
3525b8e08eSMatthew R. Ochs }
3625b8e08eSMatthew R. Ochs
cxlflash_map_afu_irq(void * ctx_cookie,int num,irq_handler_t handler,void * cookie,char * name)3725b8e08eSMatthew R. Ochs static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
3825b8e08eSMatthew R. Ochs irq_handler_t handler, void *cookie, char *name)
3925b8e08eSMatthew R. Ochs {
4025b8e08eSMatthew R. Ochs return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
4125b8e08eSMatthew R. Ochs }
4225b8e08eSMatthew R. Ochs
cxlflash_unmap_afu_irq(void * ctx_cookie,int num,void * cookie)4325b8e08eSMatthew R. Ochs static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
4425b8e08eSMatthew R. Ochs {
4525b8e08eSMatthew R. Ochs cxl_unmap_afu_irq(ctx_cookie, num, cookie);
4625b8e08eSMatthew R. Ochs }
4725b8e08eSMatthew R. Ochs
cxlflash_get_irq_objhndl(void * ctx_cookie,int irq)48402a55eaSUma Krishnan static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
49402a55eaSUma Krishnan {
50402a55eaSUma Krishnan /* Dummy fop for cxl */
51402a55eaSUma Krishnan return 0;
52402a55eaSUma Krishnan }
53402a55eaSUma Krishnan
cxlflash_start_context(void * ctx_cookie)5425b8e08eSMatthew R. Ochs static int cxlflash_start_context(void *ctx_cookie)
5525b8e08eSMatthew R. Ochs {
5625b8e08eSMatthew R. Ochs return cxl_start_context(ctx_cookie, 0, NULL);
5725b8e08eSMatthew R. Ochs }
5825b8e08eSMatthew R. Ochs
cxlflash_stop_context(void * ctx_cookie)5925b8e08eSMatthew R. Ochs static int cxlflash_stop_context(void *ctx_cookie)
6025b8e08eSMatthew R. Ochs {
6125b8e08eSMatthew R. Ochs return cxl_stop_context(ctx_cookie);
6225b8e08eSMatthew R. Ochs }
6325b8e08eSMatthew R. Ochs
cxlflash_afu_reset(void * ctx_cookie)6425b8e08eSMatthew R. Ochs static int cxlflash_afu_reset(void *ctx_cookie)
6525b8e08eSMatthew R. Ochs {
6625b8e08eSMatthew R. Ochs return cxl_afu_reset(ctx_cookie);
6725b8e08eSMatthew R. Ochs }
6825b8e08eSMatthew R. Ochs
cxlflash_set_master(void * ctx_cookie)6925b8e08eSMatthew R. Ochs static void cxlflash_set_master(void *ctx_cookie)
7025b8e08eSMatthew R. Ochs {
7125b8e08eSMatthew R. Ochs cxl_set_master(ctx_cookie);
7225b8e08eSMatthew R. Ochs }
7325b8e08eSMatthew R. Ochs
cxlflash_get_context(struct pci_dev * dev,void * afu_cookie)7425b8e08eSMatthew R. Ochs static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
7525b8e08eSMatthew R. Ochs {
7625b8e08eSMatthew R. Ochs return cxl_get_context(dev);
7725b8e08eSMatthew R. Ochs }
7825b8e08eSMatthew R. Ochs
cxlflash_dev_context_init(struct pci_dev * dev,void * afu_cookie)7925b8e08eSMatthew R. Ochs static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
8025b8e08eSMatthew R. Ochs {
8125b8e08eSMatthew R. Ochs return cxl_dev_context_init(dev);
8225b8e08eSMatthew R. Ochs }
8325b8e08eSMatthew R. Ochs
cxlflash_release_context(void * ctx_cookie)8425b8e08eSMatthew R. Ochs static int cxlflash_release_context(void *ctx_cookie)
8525b8e08eSMatthew R. Ochs {
8625b8e08eSMatthew R. Ochs return cxl_release_context(ctx_cookie);
8725b8e08eSMatthew R. Ochs }
8825b8e08eSMatthew R. Ochs
cxlflash_perst_reloads_same_image(void * afu_cookie,bool image)8925b8e08eSMatthew R. Ochs static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
9025b8e08eSMatthew R. Ochs {
9125b8e08eSMatthew R. Ochs cxl_perst_reloads_same_image(afu_cookie, image);
9225b8e08eSMatthew R. Ochs }
9325b8e08eSMatthew R. Ochs
cxlflash_read_adapter_vpd(struct pci_dev * dev,void * buf,size_t count)9425b8e08eSMatthew R. Ochs static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
9525b8e08eSMatthew R. Ochs void *buf, size_t count)
9625b8e08eSMatthew R. Ochs {
9725b8e08eSMatthew R. Ochs return cxl_read_adapter_vpd(dev, buf, count);
9825b8e08eSMatthew R. Ochs }
9925b8e08eSMatthew R. Ochs
cxlflash_allocate_afu_irqs(void * ctx_cookie,int num)10025b8e08eSMatthew R. Ochs static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
10125b8e08eSMatthew R. Ochs {
10225b8e08eSMatthew R. Ochs return cxl_allocate_afu_irqs(ctx_cookie, num);
10325b8e08eSMatthew R. Ochs }
10425b8e08eSMatthew R. Ochs
cxlflash_free_afu_irqs(void * ctx_cookie)10525b8e08eSMatthew R. Ochs static void cxlflash_free_afu_irqs(void *ctx_cookie)
10625b8e08eSMatthew R. Ochs {
10725b8e08eSMatthew R. Ochs cxl_free_afu_irqs(ctx_cookie);
10825b8e08eSMatthew R. Ochs }
10925b8e08eSMatthew R. Ochs
cxlflash_create_afu(struct pci_dev * dev)11025b8e08eSMatthew R. Ochs static void *cxlflash_create_afu(struct pci_dev *dev)
11125b8e08eSMatthew R. Ochs {
11225b8e08eSMatthew R. Ochs return cxl_pci_to_afu(dev);
11325b8e08eSMatthew R. Ochs }
11425b8e08eSMatthew R. Ochs
cxlflash_destroy_afu(void * afu)11548e077dbSUma Krishnan static void cxlflash_destroy_afu(void *afu)
11648e077dbSUma Krishnan {
11748e077dbSUma Krishnan /* Dummy fop for cxl */
11848e077dbSUma Krishnan }
11948e077dbSUma Krishnan
cxlflash_get_fd(void * ctx_cookie,struct file_operations * fops,int * fd)12025b8e08eSMatthew R. Ochs static struct file *cxlflash_get_fd(void *ctx_cookie,
12125b8e08eSMatthew R. Ochs struct file_operations *fops, int *fd)
12225b8e08eSMatthew R. Ochs {
12325b8e08eSMatthew R. Ochs return cxl_get_fd(ctx_cookie, fops, fd);
12425b8e08eSMatthew R. Ochs }
12525b8e08eSMatthew R. Ochs
cxlflash_fops_get_context(struct file * file)12625b8e08eSMatthew R. Ochs static void *cxlflash_fops_get_context(struct file *file)
12725b8e08eSMatthew R. Ochs {
12825b8e08eSMatthew R. Ochs return cxl_fops_get_context(file);
12925b8e08eSMatthew R. Ochs }
13025b8e08eSMatthew R. Ochs
cxlflash_start_work(void * ctx_cookie,u64 irqs)13125b8e08eSMatthew R. Ochs static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
13225b8e08eSMatthew R. Ochs {
13325b8e08eSMatthew R. Ochs struct cxl_ioctl_start_work work = { 0 };
13425b8e08eSMatthew R. Ochs
13525b8e08eSMatthew R. Ochs work.num_interrupts = irqs;
13625b8e08eSMatthew R. Ochs work.flags = CXL_START_WORK_NUM_IRQS;
13725b8e08eSMatthew R. Ochs
13825b8e08eSMatthew R. Ochs return cxl_start_work(ctx_cookie, &work);
13925b8e08eSMatthew R. Ochs }
14025b8e08eSMatthew R. Ochs
cxlflash_fd_mmap(struct file * file,struct vm_area_struct * vm)14125b8e08eSMatthew R. Ochs static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
14225b8e08eSMatthew R. Ochs {
14325b8e08eSMatthew R. Ochs return cxl_fd_mmap(file, vm);
14425b8e08eSMatthew R. Ochs }
14525b8e08eSMatthew R. Ochs
cxlflash_fd_release(struct inode * inode,struct file * file)14625b8e08eSMatthew R. Ochs static int cxlflash_fd_release(struct inode *inode, struct file *file)
14725b8e08eSMatthew R. Ochs {
14825b8e08eSMatthew R. Ochs return cxl_fd_release(inode, file);
14925b8e08eSMatthew R. Ochs }
15025b8e08eSMatthew R. Ochs
15125b8e08eSMatthew R. Ochs const struct cxlflash_backend_ops cxlflash_cxl_ops = {
15225b8e08eSMatthew R. Ochs .module = THIS_MODULE,
15325b8e08eSMatthew R. Ochs .psa_map = cxlflash_psa_map,
15425b8e08eSMatthew R. Ochs .psa_unmap = cxlflash_psa_unmap,
15525b8e08eSMatthew R. Ochs .process_element = cxlflash_process_element,
15625b8e08eSMatthew R. Ochs .map_afu_irq = cxlflash_map_afu_irq,
15725b8e08eSMatthew R. Ochs .unmap_afu_irq = cxlflash_unmap_afu_irq,
158402a55eaSUma Krishnan .get_irq_objhndl = cxlflash_get_irq_objhndl,
15925b8e08eSMatthew R. Ochs .start_context = cxlflash_start_context,
16025b8e08eSMatthew R. Ochs .stop_context = cxlflash_stop_context,
16125b8e08eSMatthew R. Ochs .afu_reset = cxlflash_afu_reset,
16225b8e08eSMatthew R. Ochs .set_master = cxlflash_set_master,
16325b8e08eSMatthew R. Ochs .get_context = cxlflash_get_context,
16425b8e08eSMatthew R. Ochs .dev_context_init = cxlflash_dev_context_init,
16525b8e08eSMatthew R. Ochs .release_context = cxlflash_release_context,
16625b8e08eSMatthew R. Ochs .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
16725b8e08eSMatthew R. Ochs .read_adapter_vpd = cxlflash_read_adapter_vpd,
16825b8e08eSMatthew R. Ochs .allocate_afu_irqs = cxlflash_allocate_afu_irqs,
16925b8e08eSMatthew R. Ochs .free_afu_irqs = cxlflash_free_afu_irqs,
17025b8e08eSMatthew R. Ochs .create_afu = cxlflash_create_afu,
17148e077dbSUma Krishnan .destroy_afu = cxlflash_destroy_afu,
17225b8e08eSMatthew R. Ochs .get_fd = cxlflash_get_fd,
17325b8e08eSMatthew R. Ochs .fops_get_context = cxlflash_fops_get_context,
17425b8e08eSMatthew R. Ochs .start_work = cxlflash_start_work,
17525b8e08eSMatthew R. Ochs .fd_mmap = cxlflash_fd_mmap,
17625b8e08eSMatthew R. Ochs .fd_release = cxlflash_fd_release,
17725b8e08eSMatthew R. Ochs };
178