1*65be2c79SMatthew R. Ochs /* 2*65be2c79SMatthew R. Ochs * CXL Flash Device Driver 3*65be2c79SMatthew R. Ochs * 4*65be2c79SMatthew R. Ochs * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 5*65be2c79SMatthew R. Ochs * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 6*65be2c79SMatthew R. Ochs * 7*65be2c79SMatthew R. Ochs * Copyright (C) 2015 IBM Corporation 8*65be2c79SMatthew R. Ochs * 9*65be2c79SMatthew R. Ochs * This program is free software; you can redistribute it and/or 10*65be2c79SMatthew R. Ochs * modify it under the terms of the GNU General Public License 11*65be2c79SMatthew R. Ochs * as published by the Free Software Foundation; either version 12*65be2c79SMatthew R. Ochs * 2 of the License, or (at your option) any later version. 13*65be2c79SMatthew R. Ochs */ 14*65be2c79SMatthew R. Ochs 15*65be2c79SMatthew R. Ochs #ifndef _CXLFLASH_SUPERPIPE_H 16*65be2c79SMatthew R. Ochs #define _CXLFLASH_SUPERPIPE_H 17*65be2c79SMatthew R. Ochs 18*65be2c79SMatthew R. Ochs extern struct cxlflash_global global; 19*65be2c79SMatthew R. Ochs 20*65be2c79SMatthew R. Ochs /* 21*65be2c79SMatthew R. Ochs * Terminology: use afu (and not adapter) to refer to the HW. 22*65be2c79SMatthew R. Ochs * Adapter is the entire slot and includes PSL out of which 23*65be2c79SMatthew R. Ochs * only the AFU is visible to user space. 24*65be2c79SMatthew R. Ochs */ 25*65be2c79SMatthew R. Ochs 26*65be2c79SMatthew R. Ochs /* Chunk size parms: note sislite minimum chunk size is 27*65be2c79SMatthew R. Ochs 0x10000 LBAs corresponding to a NMASK or 16. 28*65be2c79SMatthew R. Ochs */ 29*65be2c79SMatthew R. Ochs #define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */ 30*65be2c79SMatthew R. Ochs 31*65be2c79SMatthew R. Ochs #define MC_DISCOVERY_TIMEOUT 5 /* 5 secs */ 32*65be2c79SMatthew R. Ochs 33*65be2c79SMatthew R. Ochs #define CHAN2PORT(_x) ((_x) + 1) 34*65be2c79SMatthew R. Ochs 35*65be2c79SMatthew R. Ochs enum lun_mode { 36*65be2c79SMatthew R. Ochs MODE_NONE = 0, 37*65be2c79SMatthew R. Ochs MODE_PHYSICAL 38*65be2c79SMatthew R. Ochs }; 39*65be2c79SMatthew R. Ochs 40*65be2c79SMatthew R. Ochs /* Global (entire driver, spans adapters) lun_info structure */ 41*65be2c79SMatthew R. Ochs struct glun_info { 42*65be2c79SMatthew R. Ochs u64 max_lba; /* from read cap(16) */ 43*65be2c79SMatthew R. Ochs u32 blk_len; /* from read cap(16) */ 44*65be2c79SMatthew R. Ochs enum lun_mode mode; /* NONE, PHYSICAL */ 45*65be2c79SMatthew R. Ochs int users; /* Number of users w/ references to LUN */ 46*65be2c79SMatthew R. Ochs 47*65be2c79SMatthew R. Ochs u8 wwid[16]; 48*65be2c79SMatthew R. Ochs 49*65be2c79SMatthew R. Ochs struct mutex mutex; 50*65be2c79SMatthew R. Ochs 51*65be2c79SMatthew R. Ochs struct list_head list; 52*65be2c79SMatthew R. Ochs }; 53*65be2c79SMatthew R. Ochs 54*65be2c79SMatthew R. Ochs /* Local (per-adapter) lun_info structure */ 55*65be2c79SMatthew R. Ochs struct llun_info { 56*65be2c79SMatthew R. Ochs u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */ 57*65be2c79SMatthew R. Ochs u32 lun_index; /* Index in the LUN table */ 58*65be2c79SMatthew R. Ochs u32 host_no; /* host_no from Scsi_host */ 59*65be2c79SMatthew R. Ochs u32 port_sel; /* What port to use for this LUN */ 60*65be2c79SMatthew R. Ochs bool newly_created; /* Whether the LUN was just discovered */ 61*65be2c79SMatthew R. Ochs 62*65be2c79SMatthew R. Ochs u8 wwid[16]; /* Keep a duplicate copy here? */ 63*65be2c79SMatthew R. Ochs 64*65be2c79SMatthew R. Ochs struct glun_info *parent; /* Pointer to entry in global LUN structure */ 65*65be2c79SMatthew R. Ochs struct scsi_device *sdev; 66*65be2c79SMatthew R. Ochs struct list_head list; 67*65be2c79SMatthew R. Ochs }; 68*65be2c79SMatthew R. Ochs 69*65be2c79SMatthew R. Ochs struct lun_access { 70*65be2c79SMatthew R. Ochs struct llun_info *lli; 71*65be2c79SMatthew R. Ochs struct scsi_device *sdev; 72*65be2c79SMatthew R. Ochs struct list_head list; 73*65be2c79SMatthew R. Ochs }; 74*65be2c79SMatthew R. Ochs 75*65be2c79SMatthew R. Ochs enum ctx_ctrl { 76*65be2c79SMatthew R. Ochs CTX_CTRL_CLONE = (1 << 1), 77*65be2c79SMatthew R. Ochs CTX_CTRL_ERR = (1 << 2), 78*65be2c79SMatthew R. Ochs CTX_CTRL_ERR_FALLBACK = (1 << 3), 79*65be2c79SMatthew R. Ochs CTX_CTRL_NOPID = (1 << 4), 80*65be2c79SMatthew R. Ochs CTX_CTRL_FILE = (1 << 5) 81*65be2c79SMatthew R. Ochs }; 82*65be2c79SMatthew R. Ochs 83*65be2c79SMatthew R. Ochs #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0) << 28) | _id) 84*65be2c79SMatthew R. Ochs #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF) 85*65be2c79SMatthew R. Ochs 86*65be2c79SMatthew R. Ochs struct ctx_info { 87*65be2c79SMatthew R. Ochs struct sisl_ctrl_map *ctrl_map; /* initialized at startup */ 88*65be2c79SMatthew R. Ochs struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment), 89*65be2c79SMatthew R. Ochs alloc/free on attach/detach */ 90*65be2c79SMatthew R. Ochs u32 rht_out; /* Number of checked out RHT entries */ 91*65be2c79SMatthew R. Ochs u32 rht_perms; /* User-defined permissions for RHT entries */ 92*65be2c79SMatthew R. Ochs struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */ 93*65be2c79SMatthew R. Ochs 94*65be2c79SMatthew R. Ochs struct cxl_ioctl_start_work work; 95*65be2c79SMatthew R. Ochs u64 ctxid; 96*65be2c79SMatthew R. Ochs int lfd; 97*65be2c79SMatthew R. Ochs pid_t pid; 98*65be2c79SMatthew R. Ochs bool unavail; 99*65be2c79SMatthew R. Ochs bool err_recovery_active; 100*65be2c79SMatthew R. Ochs struct mutex mutex; /* Context protection */ 101*65be2c79SMatthew R. Ochs struct cxl_context *ctx; 102*65be2c79SMatthew R. Ochs struct list_head luns; /* LUNs attached to this context */ 103*65be2c79SMatthew R. Ochs const struct vm_operations_struct *cxl_mmap_vmops; 104*65be2c79SMatthew R. Ochs struct file *file; 105*65be2c79SMatthew R. Ochs struct list_head list; /* Link contexts in error recovery */ 106*65be2c79SMatthew R. Ochs }; 107*65be2c79SMatthew R. Ochs 108*65be2c79SMatthew R. Ochs struct cxlflash_global { 109*65be2c79SMatthew R. Ochs struct mutex mutex; 110*65be2c79SMatthew R. Ochs struct list_head gluns;/* list of glun_info structs */ 111*65be2c79SMatthew R. Ochs struct page *err_page; /* One page of all 0xF for error notification */ 112*65be2c79SMatthew R. Ochs }; 113*65be2c79SMatthew R. Ochs 114*65be2c79SMatthew R. Ochs int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *); 115*65be2c79SMatthew R. Ochs int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *, 116*65be2c79SMatthew R. Ochs struct dk_cxlflash_release *); 117*65be2c79SMatthew R. Ochs 118*65be2c79SMatthew R. Ochs int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool); 119*65be2c79SMatthew R. Ochs void cxlflash_lun_detach(struct glun_info *); 120*65be2c79SMatthew R. Ochs 121*65be2c79SMatthew R. Ochs struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl); 122*65be2c79SMatthew R. Ochs void put_context(struct ctx_info *); 123*65be2c79SMatthew R. Ochs 124*65be2c79SMatthew R. Ochs struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t, 125*65be2c79SMatthew R. Ochs struct llun_info *); 126*65be2c79SMatthew R. Ochs 127*65be2c79SMatthew R. Ochs struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *); 128*65be2c79SMatthew R. Ochs void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *); 129*65be2c79SMatthew R. Ochs 130*65be2c79SMatthew R. Ochs int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *); 131*65be2c79SMatthew R. Ochs 132*65be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 133