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: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
0006  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
0007  *
0008  * Copyright (C) 2015 IBM Corporation
0009  */
0010 
0011 #ifndef _CXLFLASH_SUPERPIPE_H
0012 #define _CXLFLASH_SUPERPIPE_H
0013 
0014 extern struct cxlflash_global global;
0015 
0016 /*
0017  * Terminology: use afu (and not adapter) to refer to the HW.
0018  * Adapter is the entire slot and includes PSL out of which
0019  * only the AFU is visible to user space.
0020  */
0021 
0022 /* Chunk size parms: note sislite minimum chunk size is
0023  * 0x10000 LBAs corresponding to a NMASK or 16.
0024  */
0025 #define MC_CHUNK_SIZE     (1 << MC_RHT_NMASK)   /* in LBAs */
0026 
0027 #define CMD_TIMEOUT 30  /* 30 secs */
0028 #define CMD_RETRIES 5   /* 5 retries for scsi_execute */
0029 
0030 #define MAX_SECTOR_UNIT  512 /* max_sector is in 512 byte multiples */
0031 
0032 enum lun_mode {
0033     MODE_NONE = 0,
0034     MODE_VIRTUAL,
0035     MODE_PHYSICAL
0036 };
0037 
0038 /* Global (entire driver, spans adapters) lun_info structure */
0039 struct glun_info {
0040     u64 max_lba;        /* from read cap(16) */
0041     u32 blk_len;        /* from read cap(16) */
0042     enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
0043     int users;      /* Number of users w/ references to LUN */
0044 
0045     u8 wwid[16];
0046 
0047     struct mutex mutex;
0048 
0049     struct blka blka;
0050     struct list_head list;
0051 };
0052 
0053 /* Local (per-adapter) lun_info structure */
0054 struct llun_info {
0055     u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */
0056     u32 lun_index;      /* Index in the LUN table */
0057     u32 host_no;        /* host_no from Scsi_host */
0058     u32 port_sel;       /* What port to use for this LUN */
0059     bool in_table;      /* Whether a LUN table entry was created */
0060 
0061     u8 wwid[16];        /* Keep a duplicate copy here? */
0062 
0063     struct glun_info *parent; /* Pointer to entry in global LUN structure */
0064     struct scsi_device *sdev;
0065     struct list_head list;
0066 };
0067 
0068 struct lun_access {
0069     struct llun_info *lli;
0070     struct scsi_device *sdev;
0071     struct list_head list;
0072 };
0073 
0074 enum ctx_ctrl {
0075     CTX_CTRL_CLONE      = (1 << 1),
0076     CTX_CTRL_ERR        = (1 << 2),
0077     CTX_CTRL_ERR_FALLBACK   = (1 << 3),
0078     CTX_CTRL_NOPID      = (1 << 4),
0079     CTX_CTRL_FILE       = (1 << 5)
0080 };
0081 
0082 #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
0083 #define DECODE_CTXID(_val)  (_val & 0xFFFFFFFF)
0084 
0085 struct ctx_info {
0086     struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
0087     struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
0088                        * alloc/free on attach/detach
0089                        */
0090     u32 rht_out;        /* Number of checked out RHT entries */
0091     u32 rht_perms;      /* User-defined permissions for RHT entries */
0092     struct llun_info **rht_lun;       /* Mapping of RHT entries to LUNs */
0093     u8 *rht_needs_ws;   /* User-desired write-same function per RHTE */
0094 
0095     u64 ctxid;
0096     u64 irqs; /* Number of interrupts requested for context */
0097     pid_t pid;
0098     bool initialized;
0099     bool unavail;
0100     bool err_recovery_active;
0101     struct mutex mutex; /* Context protection */
0102     struct kref kref;
0103     void *ctx;
0104     struct cxlflash_cfg *cfg;
0105     struct list_head luns;  /* LUNs attached to this context */
0106     const struct vm_operations_struct *cxl_mmap_vmops;
0107     struct file *file;
0108     struct list_head list; /* Link contexts in error recovery */
0109 };
0110 
0111 struct cxlflash_global {
0112     struct mutex mutex;
0113     struct list_head gluns;/* list of glun_info structs */
0114     struct page *err_page; /* One page of all 0xF for error notification */
0115 };
0116 
0117 int cxlflash_vlun_resize(struct scsi_device *sdev,
0118              struct dk_cxlflash_resize *resize);
0119 int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi,
0120               struct dk_cxlflash_resize *resize);
0121 
0122 int cxlflash_disk_release(struct scsi_device *sdev,
0123               struct dk_cxlflash_release *release);
0124 int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi,
0125                struct dk_cxlflash_release *release);
0126 
0127 int cxlflash_disk_clone(struct scsi_device *sdev,
0128             struct dk_cxlflash_clone *clone);
0129 
0130 int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg);
0131 
0132 int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked);
0133 void cxlflash_lun_detach(struct glun_info *gli);
0134 
0135 struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg,
0136                  enum ctx_ctrl ctrl);
0137 void put_context(struct ctx_info *ctxi);
0138 
0139 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
0140                 struct llun_info *lli);
0141 
0142 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
0143                      struct llun_info *lli);
0144 void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte);
0145 
0146 void cxlflash_ba_terminate(struct ba_lun *ba_lun);
0147 
0148 int cxlflash_manage_lun(struct scsi_device *sdev,
0149             struct dk_cxlflash_manage_lun *manage);
0150 
0151 int check_state(struct cxlflash_cfg *cfg);
0152 
0153 #endif /* ifndef _CXLFLASH_SUPERPIPE_H */