Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * CXL Flash Device Driver
0004  *
0005  * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
0006  *             Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
0007  *
0008  * Copyright (C) 2018 IBM Corporation
0009  */
0010 
0011 #include <misc/cxl.h>
0012 
0013 #include "backend.h"
0014 
0015 /*
0016  * The following routines map the cxlflash backend operations to existing CXL
0017  * kernel API function and are largely simple shims that provide an abstraction
0018  * for converting generic context and AFU cookies into cxl_context or cxl_afu
0019  * pointers.
0020  */
0021 
0022 static void __iomem *cxlflash_psa_map(void *ctx_cookie)
0023 {
0024     return cxl_psa_map(ctx_cookie);
0025 }
0026 
0027 static void cxlflash_psa_unmap(void __iomem *addr)
0028 {
0029     cxl_psa_unmap(addr);
0030 }
0031 
0032 static int cxlflash_process_element(void *ctx_cookie)
0033 {
0034     return cxl_process_element(ctx_cookie);
0035 }
0036 
0037 static int cxlflash_map_afu_irq(void *ctx_cookie, int num,
0038                 irq_handler_t handler, void *cookie, char *name)
0039 {
0040     return cxl_map_afu_irq(ctx_cookie, num, handler, cookie, name);
0041 }
0042 
0043 static void cxlflash_unmap_afu_irq(void *ctx_cookie, int num, void *cookie)
0044 {
0045     cxl_unmap_afu_irq(ctx_cookie, num, cookie);
0046 }
0047 
0048 static u64 cxlflash_get_irq_objhndl(void *ctx_cookie, int irq)
0049 {
0050     /* Dummy fop for cxl */
0051     return 0;
0052 }
0053 
0054 static int cxlflash_start_context(void *ctx_cookie)
0055 {
0056     return cxl_start_context(ctx_cookie, 0, NULL);
0057 }
0058 
0059 static int cxlflash_stop_context(void *ctx_cookie)
0060 {
0061     return cxl_stop_context(ctx_cookie);
0062 }
0063 
0064 static int cxlflash_afu_reset(void *ctx_cookie)
0065 {
0066     return cxl_afu_reset(ctx_cookie);
0067 }
0068 
0069 static void cxlflash_set_master(void *ctx_cookie)
0070 {
0071     cxl_set_master(ctx_cookie);
0072 }
0073 
0074 static void *cxlflash_get_context(struct pci_dev *dev, void *afu_cookie)
0075 {
0076     return cxl_get_context(dev);
0077 }
0078 
0079 static void *cxlflash_dev_context_init(struct pci_dev *dev, void *afu_cookie)
0080 {
0081     return cxl_dev_context_init(dev);
0082 }
0083 
0084 static int cxlflash_release_context(void *ctx_cookie)
0085 {
0086     return cxl_release_context(ctx_cookie);
0087 }
0088 
0089 static void cxlflash_perst_reloads_same_image(void *afu_cookie, bool image)
0090 {
0091     cxl_perst_reloads_same_image(afu_cookie, image);
0092 }
0093 
0094 static ssize_t cxlflash_read_adapter_vpd(struct pci_dev *dev,
0095                      void *buf, size_t count)
0096 {
0097     return cxl_read_adapter_vpd(dev, buf, count);
0098 }
0099 
0100 static int cxlflash_allocate_afu_irqs(void *ctx_cookie, int num)
0101 {
0102     return cxl_allocate_afu_irqs(ctx_cookie, num);
0103 }
0104 
0105 static void cxlflash_free_afu_irqs(void *ctx_cookie)
0106 {
0107     cxl_free_afu_irqs(ctx_cookie);
0108 }
0109 
0110 static void *cxlflash_create_afu(struct pci_dev *dev)
0111 {
0112     return cxl_pci_to_afu(dev);
0113 }
0114 
0115 static void cxlflash_destroy_afu(void *afu)
0116 {
0117     /* Dummy fop for cxl */
0118 }
0119 
0120 static struct file *cxlflash_get_fd(void *ctx_cookie,
0121                     struct file_operations *fops, int *fd)
0122 {
0123     return cxl_get_fd(ctx_cookie, fops, fd);
0124 }
0125 
0126 static void *cxlflash_fops_get_context(struct file *file)
0127 {
0128     return cxl_fops_get_context(file);
0129 }
0130 
0131 static int cxlflash_start_work(void *ctx_cookie, u64 irqs)
0132 {
0133     struct cxl_ioctl_start_work work = { 0 };
0134 
0135     work.num_interrupts = irqs;
0136     work.flags = CXL_START_WORK_NUM_IRQS;
0137 
0138     return cxl_start_work(ctx_cookie, &work);
0139 }
0140 
0141 static int cxlflash_fd_mmap(struct file *file, struct vm_area_struct *vm)
0142 {
0143     return cxl_fd_mmap(file, vm);
0144 }
0145 
0146 static int cxlflash_fd_release(struct inode *inode, struct file *file)
0147 {
0148     return cxl_fd_release(inode, file);
0149 }
0150 
0151 const struct cxlflash_backend_ops cxlflash_cxl_ops = {
0152     .module         = THIS_MODULE,
0153     .psa_map        = cxlflash_psa_map,
0154     .psa_unmap      = cxlflash_psa_unmap,
0155     .process_element    = cxlflash_process_element,
0156     .map_afu_irq        = cxlflash_map_afu_irq,
0157     .unmap_afu_irq      = cxlflash_unmap_afu_irq,
0158     .get_irq_objhndl    = cxlflash_get_irq_objhndl,
0159     .start_context      = cxlflash_start_context,
0160     .stop_context       = cxlflash_stop_context,
0161     .afu_reset      = cxlflash_afu_reset,
0162     .set_master     = cxlflash_set_master,
0163     .get_context        = cxlflash_get_context,
0164     .dev_context_init   = cxlflash_dev_context_init,
0165     .release_context    = cxlflash_release_context,
0166     .perst_reloads_same_image = cxlflash_perst_reloads_same_image,
0167     .read_adapter_vpd   = cxlflash_read_adapter_vpd,
0168     .allocate_afu_irqs  = cxlflash_allocate_afu_irqs,
0169     .free_afu_irqs      = cxlflash_free_afu_irqs,
0170     .create_afu     = cxlflash_create_afu,
0171     .destroy_afu        = cxlflash_destroy_afu,
0172     .get_fd         = cxlflash_get_fd,
0173     .fops_get_context   = cxlflash_fops_get_context,
0174     .start_work     = cxlflash_start_work,
0175     .fd_mmap        = cxlflash_fd_mmap,
0176     .fd_release     = cxlflash_fd_release,
0177 };