165be2c79SMatthew R. Ochs /* 265be2c79SMatthew R. Ochs * CXL Flash Device Driver 365be2c79SMatthew R. Ochs * 465be2c79SMatthew R. Ochs * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 565be2c79SMatthew R. Ochs * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 665be2c79SMatthew R. Ochs * 765be2c79SMatthew R. Ochs * Copyright (C) 2015 IBM Corporation 865be2c79SMatthew R. Ochs * 965be2c79SMatthew R. Ochs * This program is free software; you can redistribute it and/or 1065be2c79SMatthew R. Ochs * modify it under the terms of the GNU General Public License 1165be2c79SMatthew R. Ochs * as published by the Free Software Foundation; either version 1265be2c79SMatthew R. Ochs * 2 of the License, or (at your option) any later version. 1365be2c79SMatthew R. Ochs */ 1465be2c79SMatthew R. Ochs 1565be2c79SMatthew R. Ochs #ifndef _CXLFLASH_SUPERPIPE_H 1665be2c79SMatthew R. Ochs #define _CXLFLASH_SUPERPIPE_H 1765be2c79SMatthew R. Ochs 1865be2c79SMatthew R. Ochs extern struct cxlflash_global global; 1965be2c79SMatthew R. Ochs 2065be2c79SMatthew R. Ochs /* 2165be2c79SMatthew R. Ochs * Terminology: use afu (and not adapter) to refer to the HW. 2265be2c79SMatthew R. Ochs * Adapter is the entire slot and includes PSL out of which 2365be2c79SMatthew R. Ochs * only the AFU is visible to user space. 2465be2c79SMatthew R. Ochs */ 2565be2c79SMatthew R. Ochs 2665be2c79SMatthew R. Ochs /* Chunk size parms: note sislite minimum chunk size is 2765be2c79SMatthew R. Ochs 0x10000 LBAs corresponding to a NMASK or 16. 2865be2c79SMatthew R. Ochs */ 2965be2c79SMatthew R. Ochs #define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */ 3065be2c79SMatthew R. Ochs 3165be2c79SMatthew R. Ochs #define MC_DISCOVERY_TIMEOUT 5 /* 5 secs */ 3265be2c79SMatthew R. Ochs 3365be2c79SMatthew R. Ochs #define CHAN2PORT(_x) ((_x) + 1) 34*2cb79266SMatthew R. Ochs #define PORT2CHAN(_x) ((_x) - 1) 3565be2c79SMatthew R. Ochs 3665be2c79SMatthew R. Ochs enum lun_mode { 3765be2c79SMatthew R. Ochs MODE_NONE = 0, 38*2cb79266SMatthew R. Ochs MODE_VIRTUAL, 3965be2c79SMatthew R. Ochs MODE_PHYSICAL 4065be2c79SMatthew R. Ochs }; 4165be2c79SMatthew R. Ochs 4265be2c79SMatthew R. Ochs /* Global (entire driver, spans adapters) lun_info structure */ 4365be2c79SMatthew R. Ochs struct glun_info { 4465be2c79SMatthew R. Ochs u64 max_lba; /* from read cap(16) */ 4565be2c79SMatthew R. Ochs u32 blk_len; /* from read cap(16) */ 46*2cb79266SMatthew R. Ochs enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */ 4765be2c79SMatthew R. Ochs int users; /* Number of users w/ references to LUN */ 4865be2c79SMatthew R. Ochs 4965be2c79SMatthew R. Ochs u8 wwid[16]; 5065be2c79SMatthew R. Ochs 5165be2c79SMatthew R. Ochs struct mutex mutex; 5265be2c79SMatthew R. Ochs 53*2cb79266SMatthew R. Ochs struct blka blka; 5465be2c79SMatthew R. Ochs struct list_head list; 5565be2c79SMatthew R. Ochs }; 5665be2c79SMatthew R. Ochs 5765be2c79SMatthew R. Ochs /* Local (per-adapter) lun_info structure */ 5865be2c79SMatthew R. Ochs struct llun_info { 5965be2c79SMatthew R. Ochs u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */ 6065be2c79SMatthew R. Ochs u32 lun_index; /* Index in the LUN table */ 6165be2c79SMatthew R. Ochs u32 host_no; /* host_no from Scsi_host */ 6265be2c79SMatthew R. Ochs u32 port_sel; /* What port to use for this LUN */ 6365be2c79SMatthew R. Ochs bool newly_created; /* Whether the LUN was just discovered */ 64*2cb79266SMatthew R. Ochs bool in_table; /* Whether a LUN table entry was created */ 6565be2c79SMatthew R. Ochs 6665be2c79SMatthew R. Ochs u8 wwid[16]; /* Keep a duplicate copy here? */ 6765be2c79SMatthew R. Ochs 6865be2c79SMatthew R. Ochs struct glun_info *parent; /* Pointer to entry in global LUN structure */ 6965be2c79SMatthew R. Ochs struct scsi_device *sdev; 7065be2c79SMatthew R. Ochs struct list_head list; 7165be2c79SMatthew R. Ochs }; 7265be2c79SMatthew R. Ochs 7365be2c79SMatthew R. Ochs struct lun_access { 7465be2c79SMatthew R. Ochs struct llun_info *lli; 7565be2c79SMatthew R. Ochs struct scsi_device *sdev; 7665be2c79SMatthew R. Ochs struct list_head list; 7765be2c79SMatthew R. Ochs }; 7865be2c79SMatthew R. Ochs 7965be2c79SMatthew R. Ochs enum ctx_ctrl { 8065be2c79SMatthew R. Ochs CTX_CTRL_CLONE = (1 << 1), 8165be2c79SMatthew R. Ochs CTX_CTRL_ERR = (1 << 2), 8265be2c79SMatthew R. Ochs CTX_CTRL_ERR_FALLBACK = (1 << 3), 8365be2c79SMatthew R. Ochs CTX_CTRL_NOPID = (1 << 4), 8465be2c79SMatthew R. Ochs CTX_CTRL_FILE = (1 << 5) 8565be2c79SMatthew R. Ochs }; 8665be2c79SMatthew R. Ochs 8765be2c79SMatthew R. Ochs #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0) << 28) | _id) 8865be2c79SMatthew R. Ochs #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF) 8965be2c79SMatthew R. Ochs 9065be2c79SMatthew R. Ochs struct ctx_info { 9165be2c79SMatthew R. Ochs struct sisl_ctrl_map *ctrl_map; /* initialized at startup */ 9265be2c79SMatthew R. Ochs struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment), 9365be2c79SMatthew R. Ochs alloc/free on attach/detach */ 9465be2c79SMatthew R. Ochs u32 rht_out; /* Number of checked out RHT entries */ 9565be2c79SMatthew R. Ochs u32 rht_perms; /* User-defined permissions for RHT entries */ 9665be2c79SMatthew R. Ochs struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */ 97*2cb79266SMatthew R. Ochs bool *rht_needs_ws; /* User-desired write-same function per RHTE */ 9865be2c79SMatthew R. Ochs 9965be2c79SMatthew R. Ochs struct cxl_ioctl_start_work work; 10065be2c79SMatthew R. Ochs u64 ctxid; 10165be2c79SMatthew R. Ochs int lfd; 10265be2c79SMatthew R. Ochs pid_t pid; 10365be2c79SMatthew R. Ochs bool unavail; 10465be2c79SMatthew R. Ochs bool err_recovery_active; 10565be2c79SMatthew R. Ochs struct mutex mutex; /* Context protection */ 10665be2c79SMatthew R. Ochs struct cxl_context *ctx; 10765be2c79SMatthew R. Ochs struct list_head luns; /* LUNs attached to this context */ 10865be2c79SMatthew R. Ochs const struct vm_operations_struct *cxl_mmap_vmops; 10965be2c79SMatthew R. Ochs struct file *file; 11065be2c79SMatthew R. Ochs struct list_head list; /* Link contexts in error recovery */ 11165be2c79SMatthew R. Ochs }; 11265be2c79SMatthew R. Ochs 11365be2c79SMatthew R. Ochs struct cxlflash_global { 11465be2c79SMatthew R. Ochs struct mutex mutex; 11565be2c79SMatthew R. Ochs struct list_head gluns;/* list of glun_info structs */ 11665be2c79SMatthew R. Ochs struct page *err_page; /* One page of all 0xF for error notification */ 11765be2c79SMatthew R. Ochs }; 11865be2c79SMatthew R. Ochs 119*2cb79266SMatthew R. Ochs int cxlflash_vlun_resize(struct scsi_device *, struct dk_cxlflash_resize *); 120*2cb79266SMatthew R. Ochs int _cxlflash_vlun_resize(struct scsi_device *, struct ctx_info *, 121*2cb79266SMatthew R. Ochs struct dk_cxlflash_resize *); 122*2cb79266SMatthew R. Ochs 12365be2c79SMatthew R. Ochs int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *); 12465be2c79SMatthew R. Ochs int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *, 12565be2c79SMatthew R. Ochs struct dk_cxlflash_release *); 12665be2c79SMatthew R. Ochs 127*2cb79266SMatthew R. Ochs int cxlflash_disk_clone(struct scsi_device *, struct dk_cxlflash_clone *); 128*2cb79266SMatthew R. Ochs 129*2cb79266SMatthew R. Ochs int cxlflash_disk_virtual_open(struct scsi_device *, void *); 130*2cb79266SMatthew R. Ochs 13165be2c79SMatthew R. Ochs int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool); 13265be2c79SMatthew R. Ochs void cxlflash_lun_detach(struct glun_info *); 13365be2c79SMatthew R. Ochs 13465be2c79SMatthew R. Ochs struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl); 13565be2c79SMatthew R. Ochs void put_context(struct ctx_info *); 13665be2c79SMatthew R. Ochs 13765be2c79SMatthew R. Ochs struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t, 13865be2c79SMatthew R. Ochs struct llun_info *); 13965be2c79SMatthew R. Ochs 14065be2c79SMatthew R. Ochs struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *); 14165be2c79SMatthew R. Ochs void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *); 14265be2c79SMatthew R. Ochs 143*2cb79266SMatthew R. Ochs void cxlflash_ba_terminate(struct ba_lun *); 144*2cb79266SMatthew R. Ochs 14565be2c79SMatthew R. Ochs int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *); 14665be2c79SMatthew R. Ochs 14765be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 148