Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * CXL Flash Device Driver |
| 3 | * |
| 4 | * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation |
| 5 | * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation |
| 6 | * |
| 7 | * Copyright (C) 2015 IBM Corporation |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #ifndef _CXLFLASH_SUPERPIPE_H |
| 16 | #define _CXLFLASH_SUPERPIPE_H |
| 17 | |
| 18 | extern struct cxlflash_global global; |
| 19 | |
| 20 | /* |
| 21 | * Terminology: use afu (and not adapter) to refer to the HW. |
| 22 | * Adapter is the entire slot and includes PSL out of which |
| 23 | * only the AFU is visible to user space. |
| 24 | */ |
| 25 | |
| 26 | /* Chunk size parms: note sislite minimum chunk size is |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 27 | * 0x10000 LBAs corresponding to a NMASK or 16. |
| 28 | */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 29 | #define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */ |
| 30 | |
Manoj Kumar | 471a5a6 | 2015-10-21 15:11:10 -0500 | [diff] [blame] | 31 | #define CMD_TIMEOUT 30 /* 30 secs */ |
Manoj Kumar | 3ebf203 | 2015-10-21 15:11:00 -0500 | [diff] [blame] | 32 | #define CMD_RETRIES 5 /* 5 retries for scsi_execute */ |
| 33 | |
| 34 | #define MAX_SECTOR_UNIT 512 /* max_sector is in 512 byte multiples */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 35 | |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 36 | enum lun_mode { |
| 37 | MODE_NONE = 0, |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 38 | MODE_VIRTUAL, |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 39 | MODE_PHYSICAL |
| 40 | }; |
| 41 | |
| 42 | /* Global (entire driver, spans adapters) lun_info structure */ |
| 43 | struct glun_info { |
| 44 | u64 max_lba; /* from read cap(16) */ |
| 45 | u32 blk_len; /* from read cap(16) */ |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 46 | enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 47 | int users; /* Number of users w/ references to LUN */ |
| 48 | |
| 49 | u8 wwid[16]; |
| 50 | |
| 51 | struct mutex mutex; |
| 52 | |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 53 | struct blka blka; |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 54 | struct list_head list; |
| 55 | }; |
| 56 | |
| 57 | /* Local (per-adapter) lun_info structure */ |
| 58 | struct llun_info { |
Matthew R. Ochs | 78ae028 | 2017-04-12 14:13:50 -0500 | [diff] [blame] | 59 | u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 60 | u32 lun_index; /* Index in the LUN table */ |
| 61 | u32 host_no; /* host_no from Scsi_host */ |
| 62 | u32 port_sel; /* What port to use for this LUN */ |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 63 | bool in_table; /* Whether a LUN table entry was created */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 64 | |
| 65 | u8 wwid[16]; /* Keep a duplicate copy here? */ |
| 66 | |
| 67 | struct glun_info *parent; /* Pointer to entry in global LUN structure */ |
| 68 | struct scsi_device *sdev; |
| 69 | struct list_head list; |
| 70 | }; |
| 71 | |
| 72 | struct lun_access { |
| 73 | struct llun_info *lli; |
| 74 | struct scsi_device *sdev; |
| 75 | struct list_head list; |
| 76 | }; |
| 77 | |
| 78 | enum ctx_ctrl { |
| 79 | CTX_CTRL_CLONE = (1 << 1), |
| 80 | CTX_CTRL_ERR = (1 << 2), |
| 81 | CTX_CTRL_ERR_FALLBACK = (1 << 3), |
| 82 | CTX_CTRL_NOPID = (1 << 4), |
| 83 | CTX_CTRL_FILE = (1 << 5) |
| 84 | }; |
| 85 | |
Matthew R. Ochs | a76df36 | 2015-10-21 15:11:43 -0500 | [diff] [blame] | 86 | #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id) |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 87 | #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF) |
| 88 | |
| 89 | struct ctx_info { |
Matthew R. Ochs | 1786f4a | 2015-10-21 15:14:48 -0500 | [diff] [blame] | 90 | struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 91 | struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment), |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 92 | * alloc/free on attach/detach |
| 93 | */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 94 | u32 rht_out; /* Number of checked out RHT entries */ |
| 95 | u32 rht_perms; /* User-defined permissions for RHT entries */ |
| 96 | struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */ |
Matthew R. Ochs | e568e23 | 2015-10-21 15:11:34 -0500 | [diff] [blame] | 97 | u8 *rht_needs_ws; /* User-desired write-same function per RHTE */ |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 98 | |
| 99 | struct cxl_ioctl_start_work work; |
| 100 | u64 ctxid; |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 101 | pid_t pid; |
Matthew R. Ochs | 5e6632d | 2016-03-04 15:55:16 -0600 | [diff] [blame] | 102 | bool initialized; |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 103 | bool unavail; |
| 104 | bool err_recovery_active; |
| 105 | struct mutex mutex; /* Context protection */ |
Matthew R. Ochs | 888baf0 | 2016-08-09 18:39:42 -0500 | [diff] [blame] | 106 | struct kref kref; |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 107 | struct cxl_context *ctx; |
Matthew R. Ochs | 44ef38f | 2016-08-09 18:39:30 -0500 | [diff] [blame] | 108 | struct cxlflash_cfg *cfg; |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 109 | struct list_head luns; /* LUNs attached to this context */ |
| 110 | const struct vm_operations_struct *cxl_mmap_vmops; |
| 111 | struct file *file; |
| 112 | struct list_head list; /* Link contexts in error recovery */ |
| 113 | }; |
| 114 | |
| 115 | struct cxlflash_global { |
| 116 | struct mutex mutex; |
| 117 | struct list_head gluns;/* list of glun_info structs */ |
| 118 | struct page *err_page; /* One page of all 0xF for error notification */ |
| 119 | }; |
| 120 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 121 | int cxlflash_vlun_resize(struct scsi_device *sdev, |
| 122 | struct dk_cxlflash_resize *resize); |
| 123 | int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi, |
| 124 | struct dk_cxlflash_resize *resize); |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 125 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 126 | int cxlflash_disk_release(struct scsi_device *sdev, |
| 127 | struct dk_cxlflash_release *release); |
| 128 | int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi, |
| 129 | struct dk_cxlflash_release *release); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 130 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 131 | int cxlflash_disk_clone(struct scsi_device *sdev, |
| 132 | struct dk_cxlflash_clone *clone); |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 133 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 134 | int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg); |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 135 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 136 | int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked); |
| 137 | void cxlflash_lun_detach(struct glun_info *gli); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 138 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 139 | struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg, |
| 140 | enum ctx_ctrl ctrl); |
| 141 | void put_context(struct ctx_info *ctxi); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 142 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 143 | struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, |
| 144 | struct llun_info *lli); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 145 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 146 | struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, |
| 147 | struct llun_info *lli); |
| 148 | void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 149 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 150 | void cxlflash_ba_terminate(struct ba_lun *ba_lun); |
Matthew R. Ochs | 2cb7926 | 2015-08-13 21:47:53 -0500 | [diff] [blame] | 151 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 152 | int cxlflash_manage_lun(struct scsi_device *sdev, |
| 153 | struct dk_cxlflash_manage_lun *manage); |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 154 | |
Matthew R. Ochs | fcc87e7 | 2017-04-12 14:15:20 -0500 | [diff] [blame] | 155 | int check_state(struct cxlflash_cfg *cfg); |
Matthew R. Ochs | aacb4ff | 2015-10-21 15:15:52 -0500 | [diff] [blame] | 156 | |
Matthew R. Ochs | 65be2c7 | 2015-08-13 21:47:43 -0500 | [diff] [blame] | 157 | #endif /* ifndef _CXLFLASH_SUPERPIPE_H */ |