Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 IBM Corp. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/mutex.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/uaccess.h> |
| 17 | #include <asm/synch.h> |
Michael Neuling | ec249dd | 2015-05-27 16:07:16 +1000 | [diff] [blame] | 18 | #include <misc/cxl-base.h> |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 19 | |
| 20 | #include "cxl.h" |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 21 | #include "trace.h" |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 22 | |
| 23 | static int afu_control(struct cxl_afu *afu, u64 command, |
| 24 | u64 result, u64 mask, bool enabled) |
| 25 | { |
| 26 | u64 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 27 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 28 | int rc = 0; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 29 | |
| 30 | spin_lock(&afu->afu_cntl_lock); |
| 31 | pr_devel("AFU command starting: %llx\n", command); |
| 32 | |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 33 | trace_cxl_afu_ctrl(afu, command); |
| 34 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 35 | cxl_p2n_write(afu, CXL_AFU_Cntl_An, AFU_Cntl | command); |
| 36 | |
| 37 | AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 38 | while ((AFU_Cntl & mask) != result) { |
| 39 | if (time_after_eq(jiffies, timeout)) { |
| 40 | dev_warn(&afu->dev, "WARNING: AFU control timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 41 | rc = -EBUSY; |
| 42 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 43 | } |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 44 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 45 | if (!cxl_ops->link_ok(afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 46 | afu->enabled = enabled; |
| 47 | rc = -EIO; |
| 48 | goto out; |
| 49 | } |
| 50 | |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 51 | pr_devel_ratelimited("AFU control... (0x%016llx)\n", |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 52 | AFU_Cntl | command); |
| 53 | cpu_relax(); |
| 54 | AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 55 | }; |
| 56 | pr_devel("AFU command complete: %llx\n", command); |
| 57 | afu->enabled = enabled; |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 58 | out: |
| 59 | trace_cxl_afu_ctrl_done(afu, command, rc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 60 | spin_unlock(&afu->afu_cntl_lock); |
| 61 | |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 62 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static int afu_enable(struct cxl_afu *afu) |
| 66 | { |
| 67 | pr_devel("AFU enable request\n"); |
| 68 | |
| 69 | return afu_control(afu, CXL_AFU_Cntl_An_E, |
| 70 | CXL_AFU_Cntl_An_ES_Enabled, |
| 71 | CXL_AFU_Cntl_An_ES_MASK, true); |
| 72 | } |
| 73 | |
| 74 | int cxl_afu_disable(struct cxl_afu *afu) |
| 75 | { |
| 76 | pr_devel("AFU disable request\n"); |
| 77 | |
| 78 | return afu_control(afu, 0, CXL_AFU_Cntl_An_ES_Disabled, |
| 79 | CXL_AFU_Cntl_An_ES_MASK, false); |
| 80 | } |
| 81 | |
| 82 | /* This will disable as well as reset */ |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 83 | static int native_afu_reset(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 84 | { |
| 85 | pr_devel("AFU reset request\n"); |
| 86 | |
| 87 | return afu_control(afu, CXL_AFU_Cntl_An_RA, |
| 88 | CXL_AFU_Cntl_An_RS_Complete | CXL_AFU_Cntl_An_ES_Disabled, |
| 89 | CXL_AFU_Cntl_An_RS_MASK | CXL_AFU_Cntl_An_ES_MASK, |
| 90 | false); |
| 91 | } |
| 92 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 93 | static int native_afu_check_and_enable(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 94 | { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 95 | if (!cxl_ops->link_ok(afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 96 | WARN(1, "Refusing to enable afu while link down!\n"); |
| 97 | return -EIO; |
| 98 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 99 | if (afu->enabled) |
| 100 | return 0; |
| 101 | return afu_enable(afu); |
| 102 | } |
| 103 | |
| 104 | int cxl_psl_purge(struct cxl_afu *afu) |
| 105 | { |
| 106 | u64 PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
| 107 | u64 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 108 | u64 dsisr, dar; |
| 109 | u64 start, end; |
| 110 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 111 | int rc = 0; |
| 112 | |
| 113 | trace_cxl_psl_ctrl(afu, CXL_PSL_SCNTL_An_Pc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 114 | |
| 115 | pr_devel("PSL purge request\n"); |
| 116 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 117 | if (!cxl_ops->link_ok(afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 118 | dev_warn(&afu->dev, "PSL Purge called with link down, ignoring\n"); |
| 119 | rc = -EIO; |
| 120 | goto out; |
| 121 | } |
| 122 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 123 | if ((AFU_Cntl & CXL_AFU_Cntl_An_ES_MASK) != CXL_AFU_Cntl_An_ES_Disabled) { |
| 124 | WARN(1, "psl_purge request while AFU not disabled!\n"); |
| 125 | cxl_afu_disable(afu); |
| 126 | } |
| 127 | |
| 128 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, |
| 129 | PSL_CNTL | CXL_PSL_SCNTL_An_Pc); |
| 130 | start = local_clock(); |
| 131 | PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
| 132 | while ((PSL_CNTL & CXL_PSL_SCNTL_An_Ps_MASK) |
| 133 | == CXL_PSL_SCNTL_An_Ps_Pending) { |
| 134 | if (time_after_eq(jiffies, timeout)) { |
| 135 | dev_warn(&afu->dev, "WARNING: PSL Purge timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 136 | rc = -EBUSY; |
| 137 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 138 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 139 | if (!cxl_ops->link_ok(afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 140 | rc = -EIO; |
| 141 | goto out; |
| 142 | } |
| 143 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 144 | dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 145 | pr_devel_ratelimited("PSL purging... PSL_CNTL: 0x%016llx PSL_DSISR: 0x%016llx\n", PSL_CNTL, dsisr); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 146 | if (dsisr & CXL_PSL_DSISR_TRANS) { |
| 147 | dar = cxl_p2n_read(afu, CXL_PSL_DAR_An); |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 148 | dev_notice(&afu->dev, "PSL purge terminating pending translation, DSISR: 0x%016llx, DAR: 0x%016llx\n", dsisr, dar); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 149 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE); |
| 150 | } else if (dsisr) { |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 151 | dev_notice(&afu->dev, "PSL purge acknowledging pending non-translation fault, DSISR: 0x%016llx\n", dsisr); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 152 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A); |
| 153 | } else { |
| 154 | cpu_relax(); |
| 155 | } |
| 156 | PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
| 157 | }; |
| 158 | end = local_clock(); |
| 159 | pr_devel("PSL purged in %lld ns\n", end - start); |
| 160 | |
| 161 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, |
| 162 | PSL_CNTL & ~CXL_PSL_SCNTL_An_Pc); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 163 | out: |
| 164 | trace_cxl_psl_ctrl_done(afu, CXL_PSL_SCNTL_An_Pc, rc); |
| 165 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static int spa_max_procs(int spa_size) |
| 169 | { |
| 170 | /* |
| 171 | * From the CAIA: |
| 172 | * end_of_SPA_area = SPA_Base + ((n+4) * 128) + (( ((n*8) + 127) >> 7) * 128) + 255 |
| 173 | * Most of that junk is really just an overly-complicated way of saying |
| 174 | * the last 256 bytes are __aligned(128), so it's really: |
| 175 | * end_of_SPA_area = end_of_PSL_queue_area + __aligned(128) 255 |
| 176 | * and |
| 177 | * end_of_PSL_queue_area = SPA_Base + ((n+4) * 128) + (n*8) - 1 |
| 178 | * so |
| 179 | * sizeof(SPA) = ((n+4) * 128) + (n*8) + __aligned(128) 256 |
| 180 | * Ignore the alignment (which is safe in this case as long as we are |
| 181 | * careful with our rounding) and solve for n: |
| 182 | */ |
| 183 | return ((spa_size / 8) - 96) / 17; |
| 184 | } |
| 185 | |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 186 | int cxl_alloc_spa(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 187 | { |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 188 | /* Work out how many pages to allocate */ |
| 189 | afu->spa_order = 0; |
| 190 | do { |
| 191 | afu->spa_order++; |
| 192 | afu->spa_size = (1 << afu->spa_order) * PAGE_SIZE; |
| 193 | afu->spa_max_procs = spa_max_procs(afu->spa_size); |
| 194 | } while (afu->spa_max_procs < afu->num_procs); |
| 195 | |
| 196 | WARN_ON(afu->spa_size > 0x100000); /* Max size supported by the hardware */ |
| 197 | |
| 198 | if (!(afu->spa = (struct cxl_process_element *) |
| 199 | __get_free_pages(GFP_KERNEL | __GFP_ZERO, afu->spa_order))) { |
| 200 | pr_err("cxl_alloc_spa: Unable to allocate scheduled process area\n"); |
| 201 | return -ENOMEM; |
| 202 | } |
| 203 | pr_devel("spa pages: %i afu->spa_max_procs: %i afu->num_procs: %i\n", |
| 204 | 1<<afu->spa_order, afu->spa_max_procs, afu->num_procs); |
| 205 | |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static void attach_spa(struct cxl_afu *afu) |
| 210 | { |
| 211 | u64 spap; |
| 212 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 213 | afu->sw_command_status = (__be64 *)((char *)afu->spa + |
| 214 | ((afu->spa_max_procs + 3) * 128)); |
| 215 | |
| 216 | spap = virt_to_phys(afu->spa) & CXL_PSL_SPAP_Addr; |
| 217 | spap |= ((afu->spa_size >> (12 - CXL_PSL_SPAP_Size_Shift)) - 1) & CXL_PSL_SPAP_Size; |
| 218 | spap |= CXL_PSL_SPAP_V; |
| 219 | pr_devel("cxl: SPA allocated at 0x%p. Max processes: %i, sw_command_status: 0x%p CXL_PSL_SPAP_An=0x%016llx\n", afu->spa, afu->spa_max_procs, afu->sw_command_status, spap); |
| 220 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, spap); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 221 | } |
| 222 | |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 223 | static inline void detach_spa(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 224 | { |
Ian Munsie | db7933f | 2014-12-08 19:18:00 +1100 | [diff] [blame] | 225 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0); |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void cxl_release_spa(struct cxl_afu *afu) |
| 229 | { |
| 230 | if (afu->spa) { |
| 231 | free_pages((unsigned long) afu->spa, afu->spa_order); |
| 232 | afu->spa = NULL; |
| 233 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | int cxl_tlb_slb_invalidate(struct cxl *adapter) |
| 237 | { |
| 238 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
| 239 | |
| 240 | pr_devel("CXL adapter wide TLBIA & SLBIA\n"); |
| 241 | |
| 242 | cxl_p1_write(adapter, CXL_PSL_AFUSEL, CXL_PSL_AFUSEL_A); |
| 243 | |
| 244 | cxl_p1_write(adapter, CXL_PSL_TLBIA, CXL_TLB_SLB_IQ_ALL); |
| 245 | while (cxl_p1_read(adapter, CXL_PSL_TLBIA) & CXL_TLB_SLB_P) { |
| 246 | if (time_after_eq(jiffies, timeout)) { |
| 247 | dev_warn(&adapter->dev, "WARNING: CXL adapter wide TLBIA timed out!\n"); |
| 248 | return -EBUSY; |
| 249 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 250 | if (!cxl_ops->link_ok(adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 251 | return -EIO; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 252 | cpu_relax(); |
| 253 | } |
| 254 | |
| 255 | cxl_p1_write(adapter, CXL_PSL_SLBIA, CXL_TLB_SLB_IQ_ALL); |
| 256 | while (cxl_p1_read(adapter, CXL_PSL_SLBIA) & CXL_TLB_SLB_P) { |
| 257 | if (time_after_eq(jiffies, timeout)) { |
| 258 | dev_warn(&adapter->dev, "WARNING: CXL adapter wide SLBIA timed out!\n"); |
| 259 | return -EBUSY; |
| 260 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 261 | if (!cxl_ops->link_ok(adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 262 | return -EIO; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 263 | cpu_relax(); |
| 264 | } |
| 265 | return 0; |
| 266 | } |
| 267 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 268 | static int cxl_write_sstp(struct cxl_afu *afu, u64 sstp0, u64 sstp1) |
| 269 | { |
| 270 | int rc; |
| 271 | |
| 272 | /* 1. Disable SSTP by writing 0 to SSTP1[V] */ |
| 273 | cxl_p2n_write(afu, CXL_SSTP1_An, 0); |
| 274 | |
| 275 | /* 2. Invalidate all SLB entries */ |
| 276 | if ((rc = cxl_afu_slbia(afu))) |
| 277 | return rc; |
| 278 | |
| 279 | /* 3. Set SSTP0_An */ |
| 280 | cxl_p2n_write(afu, CXL_SSTP0_An, sstp0); |
| 281 | |
| 282 | /* 4. Set SSTP1_An */ |
| 283 | cxl_p2n_write(afu, CXL_SSTP1_An, sstp1); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /* Using per slice version may improve performance here. (ie. SLBIA_An) */ |
| 289 | static void slb_invalid(struct cxl_context *ctx) |
| 290 | { |
| 291 | struct cxl *adapter = ctx->afu->adapter; |
| 292 | u64 slbia; |
| 293 | |
| 294 | WARN_ON(!mutex_is_locked(&ctx->afu->spa_mutex)); |
| 295 | |
| 296 | cxl_p1_write(adapter, CXL_PSL_LBISEL, |
| 297 | ((u64)be32_to_cpu(ctx->elem->common.pid) << 32) | |
| 298 | be32_to_cpu(ctx->elem->lpid)); |
| 299 | cxl_p1_write(adapter, CXL_PSL_SLBIA, CXL_TLB_SLB_IQ_LPIDPID); |
| 300 | |
| 301 | while (1) { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 302 | if (!cxl_ops->link_ok(adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 303 | break; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 304 | slbia = cxl_p1_read(adapter, CXL_PSL_SLBIA); |
| 305 | if (!(slbia & CXL_TLB_SLB_P)) |
| 306 | break; |
| 307 | cpu_relax(); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | static int do_process_element_cmd(struct cxl_context *ctx, |
| 312 | u64 cmd, u64 pe_state) |
| 313 | { |
| 314 | u64 state; |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 315 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 316 | int rc = 0; |
| 317 | |
| 318 | trace_cxl_llcmd(ctx, cmd); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 319 | |
| 320 | WARN_ON(!ctx->afu->enabled); |
| 321 | |
| 322 | ctx->elem->software_state = cpu_to_be32(pe_state); |
| 323 | smp_wmb(); |
| 324 | *(ctx->afu->sw_command_status) = cpu_to_be64(cmd | 0 | ctx->pe); |
| 325 | smp_mb(); |
| 326 | cxl_p1n_write(ctx->afu, CXL_PSL_LLCMD_An, cmd | ctx->pe); |
| 327 | while (1) { |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 328 | if (time_after_eq(jiffies, timeout)) { |
| 329 | dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 330 | rc = -EBUSY; |
| 331 | goto out; |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 332 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 333 | if (!cxl_ops->link_ok(ctx->afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 334 | dev_warn(&ctx->afu->dev, "WARNING: Device link down, aborting Process Element Command!\n"); |
| 335 | rc = -EIO; |
| 336 | goto out; |
| 337 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 338 | state = be64_to_cpup(ctx->afu->sw_command_status); |
| 339 | if (state == ~0ULL) { |
| 340 | pr_err("cxl: Error adding process element to AFU\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 341 | rc = -1; |
| 342 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 343 | } |
| 344 | if ((state & (CXL_SPA_SW_CMD_MASK | CXL_SPA_SW_STATE_MASK | CXL_SPA_SW_LINK_MASK)) == |
| 345 | (cmd | (cmd >> 16) | ctx->pe)) |
| 346 | break; |
| 347 | /* |
| 348 | * The command won't finish in the PSL if there are |
| 349 | * outstanding DSIs. Hence we need to yield here in |
| 350 | * case there are outstanding DSIs that we need to |
| 351 | * service. Tuning possiblity: we could wait for a |
| 352 | * while before sched |
| 353 | */ |
| 354 | schedule(); |
| 355 | |
| 356 | } |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 357 | out: |
| 358 | trace_cxl_llcmd_done(ctx, cmd, rc); |
| 359 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static int add_process_element(struct cxl_context *ctx) |
| 363 | { |
| 364 | int rc = 0; |
| 365 | |
| 366 | mutex_lock(&ctx->afu->spa_mutex); |
| 367 | pr_devel("%s Adding pe: %i started\n", __func__, ctx->pe); |
| 368 | if (!(rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_ADD, CXL_PE_SOFTWARE_STATE_V))) |
| 369 | ctx->pe_inserted = true; |
| 370 | pr_devel("%s Adding pe: %i finished\n", __func__, ctx->pe); |
| 371 | mutex_unlock(&ctx->afu->spa_mutex); |
| 372 | return rc; |
| 373 | } |
| 374 | |
| 375 | static int terminate_process_element(struct cxl_context *ctx) |
| 376 | { |
| 377 | int rc = 0; |
| 378 | |
| 379 | /* fast path terminate if it's already invalid */ |
| 380 | if (!(ctx->elem->software_state & cpu_to_be32(CXL_PE_SOFTWARE_STATE_V))) |
| 381 | return rc; |
| 382 | |
| 383 | mutex_lock(&ctx->afu->spa_mutex); |
| 384 | pr_devel("%s Terminate pe: %i started\n", __func__, ctx->pe); |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 385 | /* We could be asked to terminate when the hw is down. That |
| 386 | * should always succeed: it's not running if the hw has gone |
| 387 | * away and is being reset. |
| 388 | */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 389 | if (cxl_ops->link_ok(ctx->afu->adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 390 | rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_TERMINATE, |
| 391 | CXL_PE_SOFTWARE_STATE_V | CXL_PE_SOFTWARE_STATE_T); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 392 | ctx->elem->software_state = 0; /* Remove Valid bit */ |
| 393 | pr_devel("%s Terminate pe: %i finished\n", __func__, ctx->pe); |
| 394 | mutex_unlock(&ctx->afu->spa_mutex); |
| 395 | return rc; |
| 396 | } |
| 397 | |
| 398 | static int remove_process_element(struct cxl_context *ctx) |
| 399 | { |
| 400 | int rc = 0; |
| 401 | |
| 402 | mutex_lock(&ctx->afu->spa_mutex); |
| 403 | pr_devel("%s Remove pe: %i started\n", __func__, ctx->pe); |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 404 | |
| 405 | /* We could be asked to remove when the hw is down. Again, if |
| 406 | * the hw is down, the PE is gone, so we succeed. |
| 407 | */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 408 | if (cxl_ops->link_ok(ctx->afu->adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 409 | rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_REMOVE, 0); |
| 410 | |
| 411 | if (!rc) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 412 | ctx->pe_inserted = false; |
| 413 | slb_invalid(ctx); |
| 414 | pr_devel("%s Remove pe: %i finished\n", __func__, ctx->pe); |
| 415 | mutex_unlock(&ctx->afu->spa_mutex); |
| 416 | |
| 417 | return rc; |
| 418 | } |
| 419 | |
| 420 | |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 421 | void cxl_assign_psn_space(struct cxl_context *ctx) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 422 | { |
| 423 | if (!ctx->afu->pp_size || ctx->master) { |
| 424 | ctx->psn_phys = ctx->afu->psn_phys; |
| 425 | ctx->psn_size = ctx->afu->adapter->ps_size; |
| 426 | } else { |
| 427 | ctx->psn_phys = ctx->afu->psn_phys + |
| 428 | (ctx->afu->pp_offset + ctx->afu->pp_size * ctx->pe); |
| 429 | ctx->psn_size = ctx->afu->pp_size; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | static int activate_afu_directed(struct cxl_afu *afu) |
| 434 | { |
| 435 | int rc; |
| 436 | |
| 437 | dev_info(&afu->dev, "Activating AFU directed mode\n"); |
| 438 | |
Christophe Lombard | 4108efb | 2015-10-07 16:07:40 +1100 | [diff] [blame] | 439 | afu->num_procs = afu->max_procs_virtualised; |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 440 | if (afu->spa == NULL) { |
| 441 | if (cxl_alloc_spa(afu)) |
| 442 | return -ENOMEM; |
| 443 | } |
| 444 | attach_spa(afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 445 | |
| 446 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_AFU); |
| 447 | cxl_p1n_write(afu, CXL_PSL_AMOR_An, 0xFFFFFFFFFFFFFFFFULL); |
| 448 | cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L); |
| 449 | |
| 450 | afu->current_mode = CXL_MODE_DIRECTED; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 451 | |
| 452 | if ((rc = cxl_chardev_m_afu_add(afu))) |
| 453 | return rc; |
| 454 | |
| 455 | if ((rc = cxl_sysfs_afu_m_add(afu))) |
| 456 | goto err; |
| 457 | |
| 458 | if ((rc = cxl_chardev_s_afu_add(afu))) |
| 459 | goto err1; |
| 460 | |
| 461 | return 0; |
| 462 | err1: |
| 463 | cxl_sysfs_afu_m_remove(afu); |
| 464 | err: |
| 465 | cxl_chardev_afu_remove(afu); |
| 466 | return rc; |
| 467 | } |
| 468 | |
| 469 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 470 | #define set_endian(sr) ((sr) |= CXL_PSL_SR_An_LE) |
| 471 | #else |
| 472 | #define set_endian(sr) ((sr) &= ~(CXL_PSL_SR_An_LE)) |
| 473 | #endif |
| 474 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 475 | static u64 calculate_sr(struct cxl_context *ctx) |
| 476 | { |
| 477 | u64 sr = 0; |
| 478 | |
Frederic Barrat | e606e03 | 2015-12-07 14:34:40 +0100 | [diff] [blame] | 479 | set_endian(sr); |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 480 | if (ctx->master) |
| 481 | sr |= CXL_PSL_SR_An_MP; |
| 482 | if (mfspr(SPRN_LPCR) & LPCR_TC) |
| 483 | sr |= CXL_PSL_SR_An_TC; |
| 484 | if (ctx->kernel) { |
| 485 | sr |= CXL_PSL_SR_An_R | (mfmsr() & MSR_SF); |
| 486 | sr |= CXL_PSL_SR_An_HV; |
| 487 | } else { |
| 488 | sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 489 | sr &= ~(CXL_PSL_SR_An_HV); |
| 490 | if (!test_tsk_thread_flag(current, TIF_32BIT)) |
| 491 | sr |= CXL_PSL_SR_An_SF; |
| 492 | } |
| 493 | return sr; |
| 494 | } |
| 495 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 496 | static int attach_afu_directed(struct cxl_context *ctx, u64 wed, u64 amr) |
| 497 | { |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 498 | u32 pid; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 499 | int r, result; |
| 500 | |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 501 | cxl_assign_psn_space(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 502 | |
| 503 | ctx->elem->ctxtime = 0; /* disable */ |
| 504 | ctx->elem->lpid = cpu_to_be32(mfspr(SPRN_LPID)); |
| 505 | ctx->elem->haurp = 0; /* disable */ |
| 506 | ctx->elem->sdr = cpu_to_be64(mfspr(SPRN_SDR1)); |
| 507 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 508 | pid = current->pid; |
| 509 | if (ctx->kernel) |
| 510 | pid = 0; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 511 | ctx->elem->common.tid = 0; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 512 | ctx->elem->common.pid = cpu_to_be32(pid); |
| 513 | |
| 514 | ctx->elem->sr = cpu_to_be64(calculate_sr(ctx)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 515 | |
| 516 | ctx->elem->common.csrp = 0; /* disable */ |
| 517 | ctx->elem->common.aurp0 = 0; /* disable */ |
| 518 | ctx->elem->common.aurp1 = 0; /* disable */ |
| 519 | |
| 520 | cxl_prefault(ctx, wed); |
| 521 | |
| 522 | ctx->elem->common.sstp0 = cpu_to_be64(ctx->sstp0); |
| 523 | ctx->elem->common.sstp1 = cpu_to_be64(ctx->sstp1); |
| 524 | |
| 525 | for (r = 0; r < CXL_IRQ_RANGES; r++) { |
| 526 | ctx->elem->ivte_offsets[r] = cpu_to_be16(ctx->irqs.offset[r]); |
| 527 | ctx->elem->ivte_ranges[r] = cpu_to_be16(ctx->irqs.range[r]); |
| 528 | } |
| 529 | |
| 530 | ctx->elem->common.amr = cpu_to_be64(amr); |
| 531 | ctx->elem->common.wed = cpu_to_be64(wed); |
| 532 | |
| 533 | /* first guy needs to enable */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 534 | if ((result = cxl_ops->afu_check_and_enable(ctx->afu))) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 535 | return result; |
| 536 | |
Daniel Axtens | 368857c | 2015-07-29 14:07:22 +1000 | [diff] [blame] | 537 | return add_process_element(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static int deactivate_afu_directed(struct cxl_afu *afu) |
| 541 | { |
| 542 | dev_info(&afu->dev, "Deactivating AFU directed mode\n"); |
| 543 | |
| 544 | afu->current_mode = 0; |
| 545 | afu->num_procs = 0; |
| 546 | |
| 547 | cxl_sysfs_afu_m_remove(afu); |
| 548 | cxl_chardev_afu_remove(afu); |
| 549 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 550 | cxl_ops->afu_reset(afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 551 | cxl_afu_disable(afu); |
| 552 | cxl_psl_purge(afu); |
| 553 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int activate_dedicated_process(struct cxl_afu *afu) |
| 558 | { |
| 559 | dev_info(&afu->dev, "Activating dedicated process mode\n"); |
| 560 | |
| 561 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_Process); |
| 562 | |
| 563 | cxl_p1n_write(afu, CXL_PSL_CtxTime_An, 0); /* disable */ |
| 564 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0); /* disable */ |
| 565 | cxl_p1n_write(afu, CXL_PSL_AMOR_An, 0xFFFFFFFFFFFFFFFFULL); |
| 566 | cxl_p1n_write(afu, CXL_PSL_LPID_An, mfspr(SPRN_LPID)); |
| 567 | cxl_p1n_write(afu, CXL_HAURP_An, 0); /* disable */ |
| 568 | cxl_p1n_write(afu, CXL_PSL_SDR_An, mfspr(SPRN_SDR1)); |
| 569 | |
| 570 | cxl_p2n_write(afu, CXL_CSRP_An, 0); /* disable */ |
| 571 | cxl_p2n_write(afu, CXL_AURP0_An, 0); /* disable */ |
| 572 | cxl_p2n_write(afu, CXL_AURP1_An, 0); /* disable */ |
| 573 | |
| 574 | afu->current_mode = CXL_MODE_DEDICATED; |
| 575 | afu->num_procs = 1; |
| 576 | |
| 577 | return cxl_chardev_d_afu_add(afu); |
| 578 | } |
| 579 | |
| 580 | static int attach_dedicated(struct cxl_context *ctx, u64 wed, u64 amr) |
| 581 | { |
| 582 | struct cxl_afu *afu = ctx->afu; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 583 | u64 pid; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 584 | int rc; |
| 585 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 586 | pid = (u64)current->pid << 32; |
| 587 | if (ctx->kernel) |
| 588 | pid = 0; |
| 589 | cxl_p2n_write(afu, CXL_PSL_PID_TID_An, pid); |
| 590 | |
| 591 | cxl_p1n_write(afu, CXL_PSL_SR_An, calculate_sr(ctx)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 592 | |
| 593 | if ((rc = cxl_write_sstp(afu, ctx->sstp0, ctx->sstp1))) |
| 594 | return rc; |
| 595 | |
| 596 | cxl_prefault(ctx, wed); |
| 597 | |
| 598 | cxl_p1n_write(afu, CXL_PSL_IVTE_Offset_An, |
| 599 | (((u64)ctx->irqs.offset[0] & 0xffff) << 48) | |
| 600 | (((u64)ctx->irqs.offset[1] & 0xffff) << 32) | |
| 601 | (((u64)ctx->irqs.offset[2] & 0xffff) << 16) | |
| 602 | ((u64)ctx->irqs.offset[3] & 0xffff)); |
| 603 | cxl_p1n_write(afu, CXL_PSL_IVTE_Limit_An, (u64) |
| 604 | (((u64)ctx->irqs.range[0] & 0xffff) << 48) | |
| 605 | (((u64)ctx->irqs.range[1] & 0xffff) << 32) | |
| 606 | (((u64)ctx->irqs.range[2] & 0xffff) << 16) | |
| 607 | ((u64)ctx->irqs.range[3] & 0xffff)); |
| 608 | |
| 609 | cxl_p2n_write(afu, CXL_PSL_AMR_An, amr); |
| 610 | |
| 611 | /* master only context for dedicated */ |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 612 | cxl_assign_psn_space(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 613 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 614 | if ((rc = cxl_ops->afu_reset(afu))) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 615 | return rc; |
| 616 | |
| 617 | cxl_p2n_write(afu, CXL_PSL_WED_An, wed); |
| 618 | |
| 619 | return afu_enable(afu); |
| 620 | } |
| 621 | |
| 622 | static int deactivate_dedicated_process(struct cxl_afu *afu) |
| 623 | { |
| 624 | dev_info(&afu->dev, "Deactivating dedicated process mode\n"); |
| 625 | |
| 626 | afu->current_mode = 0; |
| 627 | afu->num_procs = 0; |
| 628 | |
| 629 | cxl_chardev_afu_remove(afu); |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 634 | static int native_afu_deactivate_mode(struct cxl_afu *afu, int mode) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 635 | { |
| 636 | if (mode == CXL_MODE_DIRECTED) |
| 637 | return deactivate_afu_directed(afu); |
| 638 | if (mode == CXL_MODE_DEDICATED) |
| 639 | return deactivate_dedicated_process(afu); |
| 640 | return 0; |
| 641 | } |
| 642 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 643 | static int native_afu_activate_mode(struct cxl_afu *afu, int mode) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 644 | { |
| 645 | if (!mode) |
| 646 | return 0; |
| 647 | if (!(mode & afu->modes_supported)) |
| 648 | return -EINVAL; |
| 649 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 650 | if (!cxl_ops->link_ok(afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 651 | WARN(1, "Device link is down, refusing to activate!\n"); |
| 652 | return -EIO; |
| 653 | } |
| 654 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 655 | if (mode == CXL_MODE_DIRECTED) |
| 656 | return activate_afu_directed(afu); |
| 657 | if (mode == CXL_MODE_DEDICATED) |
| 658 | return activate_dedicated_process(afu); |
| 659 | |
| 660 | return -EINVAL; |
| 661 | } |
| 662 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 663 | static int native_attach_process(struct cxl_context *ctx, bool kernel, |
| 664 | u64 wed, u64 amr) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 665 | { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 666 | if (!cxl_ops->link_ok(ctx->afu->adapter)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 667 | WARN(1, "Device link is down, refusing to attach process!\n"); |
| 668 | return -EIO; |
| 669 | } |
| 670 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 671 | ctx->kernel = kernel; |
| 672 | if (ctx->afu->current_mode == CXL_MODE_DIRECTED) |
| 673 | return attach_afu_directed(ctx, wed, amr); |
| 674 | |
| 675 | if (ctx->afu->current_mode == CXL_MODE_DEDICATED) |
| 676 | return attach_dedicated(ctx, wed, amr); |
| 677 | |
| 678 | return -EINVAL; |
| 679 | } |
| 680 | |
| 681 | static inline int detach_process_native_dedicated(struct cxl_context *ctx) |
| 682 | { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 683 | cxl_ops->afu_reset(ctx->afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 684 | cxl_afu_disable(ctx->afu); |
| 685 | cxl_psl_purge(ctx->afu); |
| 686 | return 0; |
| 687 | } |
| 688 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 689 | static inline int detach_process_native_afu_directed(struct cxl_context *ctx) |
| 690 | { |
| 691 | if (!ctx->pe_inserted) |
| 692 | return 0; |
| 693 | if (terminate_process_element(ctx)) |
| 694 | return -1; |
| 695 | if (remove_process_element(ctx)) |
| 696 | return -1; |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 701 | static int native_detach_process(struct cxl_context *ctx) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 702 | { |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 703 | trace_cxl_detach(ctx); |
| 704 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 705 | if (ctx->afu->current_mode == CXL_MODE_DEDICATED) |
| 706 | return detach_process_native_dedicated(ctx); |
| 707 | |
| 708 | return detach_process_native_afu_directed(ctx); |
| 709 | } |
| 710 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 711 | static int native_get_irq_info(struct cxl_afu *afu, struct cxl_irq_info *info) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 712 | { |
| 713 | u64 pidtid; |
| 714 | |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 715 | /* If the adapter has gone away, we can't get any meaningful |
| 716 | * information. |
| 717 | */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 718 | if (!cxl_ops->link_ok(afu->adapter)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 719 | return -EIO; |
| 720 | |
Ian Munsie | bc78b05 | 2014-11-14 17:37:50 +1100 | [diff] [blame] | 721 | info->dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
| 722 | info->dar = cxl_p2n_read(afu, CXL_PSL_DAR_An); |
| 723 | info->dsr = cxl_p2n_read(afu, CXL_PSL_DSR_An); |
| 724 | pidtid = cxl_p2n_read(afu, CXL_PSL_PID_TID_An); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 725 | info->pid = pidtid >> 32; |
| 726 | info->tid = pidtid & 0xffffffff; |
Ian Munsie | bc78b05 | 2014-11-14 17:37:50 +1100 | [diff] [blame] | 727 | info->afu_err = cxl_p2n_read(afu, CXL_AFU_ERR_An); |
| 728 | info->errstat = cxl_p2n_read(afu, CXL_PSL_ErrStat_An); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 733 | static irqreturn_t native_handle_psl_slice_error(struct cxl_context *ctx, |
| 734 | u64 dsisr, u64 errstat) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 735 | { |
| 736 | u64 fir1, fir2, fir_slice, serr, afu_debug; |
| 737 | |
| 738 | fir1 = cxl_p1_read(ctx->afu->adapter, CXL_PSL_FIR1); |
| 739 | fir2 = cxl_p1_read(ctx->afu->adapter, CXL_PSL_FIR2); |
| 740 | fir_slice = cxl_p1n_read(ctx->afu, CXL_PSL_FIR_SLICE_An); |
| 741 | serr = cxl_p1n_read(ctx->afu, CXL_PSL_SERR_An); |
| 742 | afu_debug = cxl_p1n_read(ctx->afu, CXL_AFU_DEBUG_An); |
| 743 | |
| 744 | dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%016llx\n", errstat); |
| 745 | dev_crit(&ctx->afu->dev, "PSL_FIR1: 0x%016llx\n", fir1); |
| 746 | dev_crit(&ctx->afu->dev, "PSL_FIR2: 0x%016llx\n", fir2); |
| 747 | dev_crit(&ctx->afu->dev, "PSL_SERR_An: 0x%016llx\n", serr); |
| 748 | dev_crit(&ctx->afu->dev, "PSL_FIR_SLICE_An: 0x%016llx\n", fir_slice); |
| 749 | dev_crit(&ctx->afu->dev, "CXL_PSL_AFU_DEBUG_An: 0x%016llx\n", afu_debug); |
| 750 | |
| 751 | dev_crit(&ctx->afu->dev, "STOPPING CXL TRACE\n"); |
| 752 | cxl_stop_trace(ctx->afu->adapter); |
| 753 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 754 | return cxl_ops->ack_irq(ctx, 0, errstat); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static irqreturn_t fail_psl_irq(struct cxl_afu *afu, struct cxl_irq_info *irq_info) |
| 758 | { |
| 759 | if (irq_info->dsisr & CXL_PSL_DSISR_TRANS) |
| 760 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE); |
| 761 | else |
| 762 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A); |
| 763 | |
| 764 | return IRQ_HANDLED; |
| 765 | } |
| 766 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 767 | static irqreturn_t native_irq_multiplexed(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 768 | { |
| 769 | struct cxl_afu *afu = data; |
| 770 | struct cxl_context *ctx; |
| 771 | struct cxl_irq_info irq_info; |
| 772 | int ph = cxl_p2n_read(afu, CXL_PSL_PEHandle_An) & 0xffff; |
| 773 | int ret; |
| 774 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 775 | if ((ret = native_get_irq_info(afu, &irq_info))) { |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 776 | WARN(1, "Unable to get CXL IRQ Info: %i\n", ret); |
| 777 | return fail_psl_irq(afu, &irq_info); |
| 778 | } |
| 779 | |
| 780 | rcu_read_lock(); |
| 781 | ctx = idr_find(&afu->contexts_idr, ph); |
| 782 | if (ctx) { |
| 783 | ret = cxl_irq(irq, ctx, &irq_info); |
| 784 | rcu_read_unlock(); |
| 785 | return ret; |
| 786 | } |
| 787 | rcu_read_unlock(); |
| 788 | |
| 789 | WARN(1, "Unable to demultiplex CXL PSL IRQ for PE %i DSISR %016llx DAR" |
| 790 | " %016llx\n(Possible AFU HW issue - was a term/remove acked" |
| 791 | " with outstanding transactions?)\n", ph, irq_info.dsisr, |
| 792 | irq_info.dar); |
| 793 | return fail_psl_irq(afu, &irq_info); |
| 794 | } |
| 795 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 796 | static irqreturn_t native_slice_irq_err(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 797 | { |
| 798 | struct cxl_afu *afu = data; |
| 799 | u64 fir_slice, errstat, serr, afu_debug; |
| 800 | |
| 801 | WARN(irq, "CXL SLICE ERROR interrupt %i\n", irq); |
| 802 | |
| 803 | serr = cxl_p1n_read(afu, CXL_PSL_SERR_An); |
| 804 | fir_slice = cxl_p1n_read(afu, CXL_PSL_FIR_SLICE_An); |
| 805 | errstat = cxl_p2n_read(afu, CXL_PSL_ErrStat_An); |
| 806 | afu_debug = cxl_p1n_read(afu, CXL_AFU_DEBUG_An); |
| 807 | dev_crit(&afu->dev, "PSL_SERR_An: 0x%016llx\n", serr); |
| 808 | dev_crit(&afu->dev, "PSL_FIR_SLICE_An: 0x%016llx\n", fir_slice); |
| 809 | dev_crit(&afu->dev, "CXL_PSL_ErrStat_An: 0x%016llx\n", errstat); |
| 810 | dev_crit(&afu->dev, "CXL_PSL_AFU_DEBUG_An: 0x%016llx\n", afu_debug); |
| 811 | |
| 812 | cxl_p1n_write(afu, CXL_PSL_SERR_An, serr); |
| 813 | |
| 814 | return IRQ_HANDLED; |
| 815 | } |
| 816 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 817 | static irqreturn_t native_irq_err(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 818 | { |
| 819 | struct cxl *adapter = data; |
| 820 | u64 fir1, fir2, err_ivte; |
| 821 | |
| 822 | WARN(1, "CXL ERROR interrupt %i\n", irq); |
| 823 | |
| 824 | err_ivte = cxl_p1_read(adapter, CXL_PSL_ErrIVTE); |
| 825 | dev_crit(&adapter->dev, "PSL_ErrIVTE: 0x%016llx\n", err_ivte); |
| 826 | |
| 827 | dev_crit(&adapter->dev, "STOPPING CXL TRACE\n"); |
| 828 | cxl_stop_trace(adapter); |
| 829 | |
| 830 | fir1 = cxl_p1_read(adapter, CXL_PSL_FIR1); |
| 831 | fir2 = cxl_p1_read(adapter, CXL_PSL_FIR2); |
| 832 | |
| 833 | dev_crit(&adapter->dev, "PSL_FIR1: 0x%016llx\nPSL_FIR2: 0x%016llx\n", fir1, fir2); |
| 834 | |
| 835 | return IRQ_HANDLED; |
| 836 | } |
| 837 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 838 | int cxl_native_register_psl_err_irq(struct cxl *adapter) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 839 | { |
| 840 | int rc; |
| 841 | |
| 842 | adapter->irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", |
| 843 | dev_name(&adapter->dev)); |
| 844 | if (!adapter->irq_name) |
| 845 | return -ENOMEM; |
| 846 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 847 | if ((rc = cxl_register_one_irq(adapter, native_irq_err, adapter, |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 848 | &adapter->err_hwirq, |
| 849 | &adapter->err_virq, |
| 850 | adapter->irq_name))) { |
| 851 | kfree(adapter->irq_name); |
| 852 | adapter->irq_name = NULL; |
| 853 | return rc; |
| 854 | } |
| 855 | |
| 856 | cxl_p1_write(adapter, CXL_PSL_ErrIVTE, adapter->err_hwirq & 0xffff); |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 861 | void cxl_native_release_psl_err_irq(struct cxl *adapter) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 862 | { |
| 863 | if (adapter->err_virq != irq_find_mapping(NULL, adapter->err_hwirq)) |
| 864 | return; |
| 865 | |
| 866 | cxl_p1_write(adapter, CXL_PSL_ErrIVTE, 0x0000000000000000); |
| 867 | cxl_unmap_irq(adapter->err_virq, adapter); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 868 | cxl_ops->release_one_irq(adapter, adapter->err_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 869 | kfree(adapter->irq_name); |
| 870 | } |
| 871 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 872 | int cxl_native_register_serr_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 873 | { |
| 874 | u64 serr; |
| 875 | int rc; |
| 876 | |
| 877 | afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", |
| 878 | dev_name(&afu->dev)); |
| 879 | if (!afu->err_irq_name) |
| 880 | return -ENOMEM; |
| 881 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 882 | if ((rc = cxl_register_one_irq(afu->adapter, native_slice_irq_err, afu, |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 883 | &afu->serr_hwirq, |
| 884 | &afu->serr_virq, afu->err_irq_name))) { |
| 885 | kfree(afu->err_irq_name); |
| 886 | afu->err_irq_name = NULL; |
| 887 | return rc; |
| 888 | } |
| 889 | |
| 890 | serr = cxl_p1n_read(afu, CXL_PSL_SERR_An); |
| 891 | serr = (serr & 0x00ffffffffff0000ULL) | (afu->serr_hwirq & 0xffff); |
| 892 | cxl_p1n_write(afu, CXL_PSL_SERR_An, serr); |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 897 | void cxl_native_release_serr_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 898 | { |
| 899 | if (afu->serr_virq != irq_find_mapping(NULL, afu->serr_hwirq)) |
| 900 | return; |
| 901 | |
| 902 | cxl_p1n_write(afu, CXL_PSL_SERR_An, 0x0000000000000000); |
| 903 | cxl_unmap_irq(afu->serr_virq, afu); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 904 | cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 905 | kfree(afu->err_irq_name); |
| 906 | } |
| 907 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 908 | int cxl_native_register_psl_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 909 | { |
| 910 | int rc; |
| 911 | |
| 912 | afu->psl_irq_name = kasprintf(GFP_KERNEL, "cxl-%s", |
| 913 | dev_name(&afu->dev)); |
| 914 | if (!afu->psl_irq_name) |
| 915 | return -ENOMEM; |
| 916 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 917 | if ((rc = cxl_register_one_irq(afu->adapter, native_irq_multiplexed, afu, |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 918 | &afu->psl_hwirq, &afu->psl_virq, |
| 919 | afu->psl_irq_name))) { |
| 920 | kfree(afu->psl_irq_name); |
| 921 | afu->psl_irq_name = NULL; |
| 922 | } |
| 923 | return rc; |
| 924 | } |
| 925 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 926 | void cxl_native_release_psl_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 927 | { |
| 928 | if (afu->psl_virq != irq_find_mapping(NULL, afu->psl_hwirq)) |
| 929 | return; |
| 930 | |
| 931 | cxl_unmap_irq(afu->psl_virq, afu); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 932 | cxl_ops->release_one_irq(afu->adapter, afu->psl_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 933 | kfree(afu->psl_irq_name); |
| 934 | } |
| 935 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 936 | static void recover_psl_err(struct cxl_afu *afu, u64 errstat) |
| 937 | { |
| 938 | u64 dsisr; |
| 939 | |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 940 | pr_devel("RECOVERING FROM PSL ERROR... (0x%016llx)\n", errstat); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 941 | |
| 942 | /* Clear PSL_DSISR[PE] */ |
| 943 | dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
| 944 | cxl_p2n_write(afu, CXL_PSL_DSISR_An, dsisr & ~CXL_PSL_DSISR_An_PE); |
| 945 | |
| 946 | /* Write 1s to clear error status bits */ |
| 947 | cxl_p2n_write(afu, CXL_PSL_ErrStat_An, errstat); |
| 948 | } |
| 949 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 950 | static int native_ack_irq(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 951 | { |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 952 | trace_cxl_psl_irq_ack(ctx, tfc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 953 | if (tfc) |
| 954 | cxl_p2n_write(ctx->afu, CXL_PSL_TFC_An, tfc); |
| 955 | if (psl_reset_mask) |
| 956 | recover_psl_err(ctx->afu, psl_reset_mask); |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | int cxl_check_error(struct cxl_afu *afu) |
| 962 | { |
| 963 | return (cxl_p1n_read(afu, CXL_PSL_SCNTL_An) == ~0ULL); |
| 964 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 965 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 966 | static int native_afu_cr_read64(struct cxl_afu *afu, int cr, u64 off, u64 *out) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 967 | { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 968 | if (unlikely(!cxl_ops->link_ok(afu->adapter))) |
| 969 | return -EIO; |
| 970 | if (unlikely(off >= afu->crs_len)) |
| 971 | return -ERANGE; |
| 972 | *out = in_le64(afu->afu_desc_mmio + afu->crs_offset + |
| 973 | (cr * afu->crs_len) + off); |
| 974 | return 0; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 977 | static int native_afu_cr_read32(struct cxl_afu *afu, int cr, u64 off, u32 *out) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 978 | { |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 979 | if (unlikely(!cxl_ops->link_ok(afu->adapter))) |
| 980 | return -EIO; |
| 981 | if (unlikely(off >= afu->crs_len)) |
| 982 | return -ERANGE; |
| 983 | *out = in_le32(afu->afu_desc_mmio + afu->crs_offset + |
| 984 | (cr * afu->crs_len) + off); |
| 985 | return 0; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 988 | static int native_afu_cr_read16(struct cxl_afu *afu, int cr, u64 off, u16 *out) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 989 | { |
| 990 | u64 aligned_off = off & ~0x3L; |
| 991 | u32 val; |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 992 | int rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 993 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 994 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 995 | if (!rc) |
| 996 | *out = (val >> ((off & 0x3) * 8)) & 0xffff; |
| 997 | return rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 1000 | static int native_afu_cr_read8(struct cxl_afu *afu, int cr, u64 off, u8 *out) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1001 | { |
| 1002 | u64 aligned_off = off & ~0x3L; |
| 1003 | u32 val; |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1004 | int rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1005 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 1006 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1007 | if (!rc) |
| 1008 | *out = (val >> ((off & 0x3) * 8)) & 0xff; |
| 1009 | return rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1010 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1011 | |
| 1012 | const struct cxl_backend_ops cxl_native_ops = { |
| 1013 | .module = THIS_MODULE, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 1014 | .adapter_reset = cxl_pci_reset, |
| 1015 | .alloc_one_irq = cxl_pci_alloc_one_irq, |
| 1016 | .release_one_irq = cxl_pci_release_one_irq, |
| 1017 | .alloc_irq_ranges = cxl_pci_alloc_irq_ranges, |
| 1018 | .release_irq_ranges = cxl_pci_release_irq_ranges, |
| 1019 | .setup_irq = cxl_pci_setup_irq, |
| 1020 | .handle_psl_slice_error = native_handle_psl_slice_error, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1021 | .psl_interrupt = NULL, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 1022 | .ack_irq = native_ack_irq, |
| 1023 | .attach_process = native_attach_process, |
| 1024 | .detach_process = native_detach_process, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1025 | .link_ok = cxl_adapter_link_ok, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame^] | 1026 | .release_afu = cxl_pci_release_afu, |
| 1027 | .afu_read_err_buffer = cxl_pci_afu_read_err_buffer, |
| 1028 | .afu_check_and_enable = native_afu_check_and_enable, |
| 1029 | .afu_activate_mode = native_afu_activate_mode, |
| 1030 | .afu_deactivate_mode = native_afu_deactivate_mode, |
| 1031 | .afu_reset = native_afu_reset, |
| 1032 | .afu_cr_read8 = native_afu_cr_read8, |
| 1033 | .afu_cr_read16 = native_afu_cr_read16, |
| 1034 | .afu_cr_read32 = native_afu_cr_read32, |
| 1035 | .afu_cr_read64 = native_afu_cr_read64, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1036 | }; |