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 27*fcc87e74SMatthew 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 31471a5a60SManoj Kumar #define CMD_TIMEOUT 30 /* 30 secs */ 323ebf2030SManoj Kumar #define CMD_RETRIES 5 /* 5 retries for scsi_execute */ 333ebf2030SManoj Kumar 343ebf2030SManoj Kumar #define MAX_SECTOR_UNIT 512 /* max_sector is in 512 byte multiples */ 3565be2c79SMatthew R. Ochs 3665be2c79SMatthew R. Ochs enum lun_mode { 3765be2c79SMatthew R. Ochs MODE_NONE = 0, 382cb79266SMatthew 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) */ 462cb79266SMatthew 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 532cb79266SMatthew 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 { 5978ae028eSMatthew R. Ochs u64 lun_id[MAX_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 */ 632cb79266SMatthew R. Ochs bool in_table; /* Whether a LUN table entry was created */ 6465be2c79SMatthew R. Ochs 6565be2c79SMatthew R. Ochs u8 wwid[16]; /* Keep a duplicate copy here? */ 6665be2c79SMatthew R. Ochs 6765be2c79SMatthew R. Ochs struct glun_info *parent; /* Pointer to entry in global LUN structure */ 6865be2c79SMatthew R. Ochs struct scsi_device *sdev; 6965be2c79SMatthew R. Ochs struct list_head list; 7065be2c79SMatthew R. Ochs }; 7165be2c79SMatthew R. Ochs 7265be2c79SMatthew R. Ochs struct lun_access { 7365be2c79SMatthew R. Ochs struct llun_info *lli; 7465be2c79SMatthew R. Ochs struct scsi_device *sdev; 7565be2c79SMatthew R. Ochs struct list_head list; 7665be2c79SMatthew R. Ochs }; 7765be2c79SMatthew R. Ochs 7865be2c79SMatthew R. Ochs enum ctx_ctrl { 7965be2c79SMatthew R. Ochs CTX_CTRL_CLONE = (1 << 1), 8065be2c79SMatthew R. Ochs CTX_CTRL_ERR = (1 << 2), 8165be2c79SMatthew R. Ochs CTX_CTRL_ERR_FALLBACK = (1 << 3), 8265be2c79SMatthew R. Ochs CTX_CTRL_NOPID = (1 << 4), 8365be2c79SMatthew R. Ochs CTX_CTRL_FILE = (1 << 5) 8465be2c79SMatthew R. Ochs }; 8565be2c79SMatthew R. Ochs 86a76df368SMatthew R. Ochs #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id) 8765be2c79SMatthew R. Ochs #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF) 8865be2c79SMatthew R. Ochs 8965be2c79SMatthew R. Ochs struct ctx_info { 901786f4a0SMatthew R. Ochs struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */ 9165be2c79SMatthew R. Ochs struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment), 92*fcc87e74SMatthew R. Ochs * alloc/free on attach/detach 93*fcc87e74SMatthew R. Ochs */ 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 */ 97e568e23fSMatthew R. Ochs u8 *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 pid_t pid; 1025e6632d1SMatthew R. Ochs bool initialized; 10365be2c79SMatthew R. Ochs bool unavail; 10465be2c79SMatthew R. Ochs bool err_recovery_active; 10565be2c79SMatthew R. Ochs struct mutex mutex; /* Context protection */ 106888baf06SMatthew R. Ochs struct kref kref; 10765be2c79SMatthew R. Ochs struct cxl_context *ctx; 10844ef38f9SMatthew R. Ochs struct cxlflash_cfg *cfg; 10965be2c79SMatthew R. Ochs struct list_head luns; /* LUNs attached to this context */ 11065be2c79SMatthew R. Ochs const struct vm_operations_struct *cxl_mmap_vmops; 11165be2c79SMatthew R. Ochs struct file *file; 11265be2c79SMatthew R. Ochs struct list_head list; /* Link contexts in error recovery */ 11365be2c79SMatthew R. Ochs }; 11465be2c79SMatthew R. Ochs 11565be2c79SMatthew R. Ochs struct cxlflash_global { 11665be2c79SMatthew R. Ochs struct mutex mutex; 11765be2c79SMatthew R. Ochs struct list_head gluns;/* list of glun_info structs */ 11865be2c79SMatthew R. Ochs struct page *err_page; /* One page of all 0xF for error notification */ 11965be2c79SMatthew R. Ochs }; 12065be2c79SMatthew R. Ochs 121*fcc87e74SMatthew R. Ochs int cxlflash_vlun_resize(struct scsi_device *sdev, 122*fcc87e74SMatthew R. Ochs struct dk_cxlflash_resize *resize); 123*fcc87e74SMatthew R. Ochs int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi, 124*fcc87e74SMatthew R. Ochs struct dk_cxlflash_resize *resize); 1252cb79266SMatthew R. Ochs 126*fcc87e74SMatthew R. Ochs int cxlflash_disk_release(struct scsi_device *sdev, 127*fcc87e74SMatthew R. Ochs struct dk_cxlflash_release *release); 128*fcc87e74SMatthew R. Ochs int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi, 129*fcc87e74SMatthew R. Ochs struct dk_cxlflash_release *release); 13065be2c79SMatthew R. Ochs 131*fcc87e74SMatthew R. Ochs int cxlflash_disk_clone(struct scsi_device *sdev, 132*fcc87e74SMatthew R. Ochs struct dk_cxlflash_clone *clone); 1332cb79266SMatthew R. Ochs 134*fcc87e74SMatthew R. Ochs int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg); 1352cb79266SMatthew R. Ochs 136*fcc87e74SMatthew R. Ochs int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked); 137*fcc87e74SMatthew R. Ochs void cxlflash_lun_detach(struct glun_info *gli); 13865be2c79SMatthew R. Ochs 139*fcc87e74SMatthew R. Ochs struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg, 140*fcc87e74SMatthew R. Ochs enum ctx_ctrl ctrl); 141*fcc87e74SMatthew R. Ochs void put_context(struct ctx_info *ctxi); 14265be2c79SMatthew R. Ochs 143*fcc87e74SMatthew R. Ochs struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, 144*fcc87e74SMatthew R. Ochs struct llun_info *lli); 14565be2c79SMatthew R. Ochs 146*fcc87e74SMatthew R. Ochs struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, 147*fcc87e74SMatthew R. Ochs struct llun_info *lli); 148*fcc87e74SMatthew R. Ochs void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte); 14965be2c79SMatthew R. Ochs 150*fcc87e74SMatthew R. Ochs void cxlflash_ba_terminate(struct ba_lun *ba_lun); 1512cb79266SMatthew R. Ochs 152*fcc87e74SMatthew R. Ochs int cxlflash_manage_lun(struct scsi_device *sdev, 153*fcc87e74SMatthew R. Ochs struct dk_cxlflash_manage_lun *manage); 15465be2c79SMatthew R. Ochs 155*fcc87e74SMatthew R. Ochs int check_state(struct cxlflash_cfg *cfg); 156aacb4ff6SMatthew R. Ochs 15765be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_SUPERPIPE_H */ 158