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> |
Ingo Molnar | e601757 | 2017-02-01 16:36:40 +0100 | [diff] [blame] | 12 | #include <linux/sched/clock.h> |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 13 | #include <linux/slab.h> |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 14 | #include <linux/mutex.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/uaccess.h> |
Michael Neuling | 2bc79ff | 2016-04-22 14:57:49 +1000 | [diff] [blame] | 17 | #include <linux/delay.h> |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 18 | #include <asm/synch.h> |
Michael Neuling | ec249dd | 2015-05-27 16:07:16 +1000 | [diff] [blame] | 19 | #include <misc/cxl-base.h> |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 20 | |
| 21 | #include "cxl.h" |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 22 | #include "trace.h" |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 23 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 24 | static int afu_control(struct cxl_afu *afu, u64 command, u64 clear, |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 25 | u64 result, u64 mask, bool enabled) |
| 26 | { |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 27 | u64 AFU_Cntl; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 28 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 29 | int rc = 0; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 30 | |
| 31 | spin_lock(&afu->afu_cntl_lock); |
| 32 | pr_devel("AFU command starting: %llx\n", command); |
| 33 | |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 34 | trace_cxl_afu_ctrl(afu, command); |
| 35 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 36 | AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 37 | cxl_p2n_write(afu, CXL_AFU_Cntl_An, (AFU_Cntl & ~clear) | command); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 38 | |
| 39 | AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 40 | while ((AFU_Cntl & mask) != result) { |
| 41 | if (time_after_eq(jiffies, timeout)) { |
| 42 | dev_warn(&afu->dev, "WARNING: AFU control timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 43 | rc = -EBUSY; |
| 44 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 45 | } |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 46 | |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 47 | if (!cxl_ops->link_ok(afu->adapter, afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 48 | afu->enabled = enabled; |
| 49 | rc = -EIO; |
| 50 | goto out; |
| 51 | } |
| 52 | |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 53 | pr_devel_ratelimited("AFU control... (0x%016llx)\n", |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 54 | AFU_Cntl | command); |
| 55 | cpu_relax(); |
| 56 | AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
Andrew Donnellan | 3382a62 | 2016-11-22 21:13:27 +1100 | [diff] [blame] | 57 | } |
Ian Munsie | 2a4f667 | 2016-06-30 04:51:26 +1000 | [diff] [blame] | 58 | |
| 59 | if (AFU_Cntl & CXL_AFU_Cntl_An_RA) { |
| 60 | /* |
| 61 | * Workaround for a bug in the XSL used in the Mellanox CX4 |
| 62 | * that fails to clear the RA bit after an AFU reset, |
| 63 | * preventing subsequent AFU resets from working. |
| 64 | */ |
| 65 | cxl_p2n_write(afu, CXL_AFU_Cntl_An, AFU_Cntl & ~CXL_AFU_Cntl_An_RA); |
| 66 | } |
| 67 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 68 | pr_devel("AFU command complete: %llx\n", command); |
| 69 | afu->enabled = enabled; |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 70 | out: |
| 71 | trace_cxl_afu_ctrl_done(afu, command, rc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 72 | spin_unlock(&afu->afu_cntl_lock); |
| 73 | |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 74 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static int afu_enable(struct cxl_afu *afu) |
| 78 | { |
| 79 | pr_devel("AFU enable request\n"); |
| 80 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 81 | return afu_control(afu, CXL_AFU_Cntl_An_E, 0, |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 82 | CXL_AFU_Cntl_An_ES_Enabled, |
| 83 | CXL_AFU_Cntl_An_ES_MASK, true); |
| 84 | } |
| 85 | |
| 86 | int cxl_afu_disable(struct cxl_afu *afu) |
| 87 | { |
| 88 | pr_devel("AFU disable request\n"); |
| 89 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 90 | return afu_control(afu, 0, CXL_AFU_Cntl_An_E, |
| 91 | CXL_AFU_Cntl_An_ES_Disabled, |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 92 | CXL_AFU_Cntl_An_ES_MASK, false); |
| 93 | } |
| 94 | |
| 95 | /* This will disable as well as reset */ |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 96 | static int native_afu_reset(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 97 | { |
| 98 | pr_devel("AFU reset request\n"); |
| 99 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 100 | return afu_control(afu, CXL_AFU_Cntl_An_RA, 0, |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 101 | CXL_AFU_Cntl_An_RS_Complete | CXL_AFU_Cntl_An_ES_Disabled, |
| 102 | CXL_AFU_Cntl_An_RS_MASK | CXL_AFU_Cntl_An_ES_MASK, |
| 103 | false); |
| 104 | } |
| 105 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 106 | static int native_afu_check_and_enable(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 107 | { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 108 | if (!cxl_ops->link_ok(afu->adapter, afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 109 | WARN(1, "Refusing to enable afu while link down!\n"); |
| 110 | return -EIO; |
| 111 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 112 | if (afu->enabled) |
| 113 | return 0; |
| 114 | return afu_enable(afu); |
| 115 | } |
| 116 | |
| 117 | int cxl_psl_purge(struct cxl_afu *afu) |
| 118 | { |
| 119 | u64 PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
| 120 | u64 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); |
| 121 | u64 dsisr, dar; |
| 122 | u64 start, end; |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 123 | u64 trans_fault = 0x0ULL; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 124 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 125 | int rc = 0; |
| 126 | |
| 127 | trace_cxl_psl_ctrl(afu, CXL_PSL_SCNTL_An_Pc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 128 | |
| 129 | pr_devel("PSL purge request\n"); |
| 130 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 131 | if (cxl_is_psl8(afu)) |
| 132 | trans_fault = CXL_PSL_DSISR_TRANS; |
| 133 | if (cxl_is_psl9(afu)) |
| 134 | trans_fault = CXL_PSL9_DSISR_An_TF; |
| 135 | |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 136 | if (!cxl_ops->link_ok(afu->adapter, afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 137 | dev_warn(&afu->dev, "PSL Purge called with link down, ignoring\n"); |
| 138 | rc = -EIO; |
| 139 | goto out; |
| 140 | } |
| 141 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 142 | if ((AFU_Cntl & CXL_AFU_Cntl_An_ES_MASK) != CXL_AFU_Cntl_An_ES_Disabled) { |
| 143 | WARN(1, "psl_purge request while AFU not disabled!\n"); |
| 144 | cxl_afu_disable(afu); |
| 145 | } |
| 146 | |
| 147 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, |
| 148 | PSL_CNTL | CXL_PSL_SCNTL_An_Pc); |
| 149 | start = local_clock(); |
| 150 | PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
| 151 | while ((PSL_CNTL & CXL_PSL_SCNTL_An_Ps_MASK) |
| 152 | == CXL_PSL_SCNTL_An_Ps_Pending) { |
| 153 | if (time_after_eq(jiffies, timeout)) { |
| 154 | dev_warn(&afu->dev, "WARNING: PSL Purge timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 155 | rc = -EBUSY; |
| 156 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 157 | } |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 158 | if (!cxl_ops->link_ok(afu->adapter, afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 159 | rc = -EIO; |
| 160 | goto out; |
| 161 | } |
| 162 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 163 | dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 164 | pr_devel_ratelimited("PSL purging... PSL_CNTL: 0x%016llx PSL_DSISR: 0x%016llx\n", |
| 165 | PSL_CNTL, dsisr); |
| 166 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 167 | if (dsisr & trans_fault) { |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 168 | dar = cxl_p2n_read(afu, CXL_PSL_DAR_An); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 169 | dev_notice(&afu->dev, "PSL purge terminating pending translation, DSISR: 0x%016llx, DAR: 0x%016llx\n", |
| 170 | dsisr, dar); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 171 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE); |
| 172 | } else if (dsisr) { |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 173 | dev_notice(&afu->dev, "PSL purge acknowledging pending non-translation fault, DSISR: 0x%016llx\n", |
| 174 | dsisr); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 175 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A); |
| 176 | } else { |
| 177 | cpu_relax(); |
| 178 | } |
| 179 | PSL_CNTL = cxl_p1n_read(afu, CXL_PSL_SCNTL_An); |
Andrew Donnellan | 3382a62 | 2016-11-22 21:13:27 +1100 | [diff] [blame] | 180 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 181 | end = local_clock(); |
| 182 | pr_devel("PSL purged in %lld ns\n", end - start); |
| 183 | |
| 184 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, |
| 185 | PSL_CNTL & ~CXL_PSL_SCNTL_An_Pc); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 186 | out: |
| 187 | trace_cxl_psl_ctrl_done(afu, CXL_PSL_SCNTL_An_Pc, rc); |
| 188 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static int spa_max_procs(int spa_size) |
| 192 | { |
| 193 | /* |
| 194 | * From the CAIA: |
| 195 | * end_of_SPA_area = SPA_Base + ((n+4) * 128) + (( ((n*8) + 127) >> 7) * 128) + 255 |
| 196 | * Most of that junk is really just an overly-complicated way of saying |
| 197 | * the last 256 bytes are __aligned(128), so it's really: |
| 198 | * end_of_SPA_area = end_of_PSL_queue_area + __aligned(128) 255 |
| 199 | * and |
| 200 | * end_of_PSL_queue_area = SPA_Base + ((n+4) * 128) + (n*8) - 1 |
| 201 | * so |
| 202 | * sizeof(SPA) = ((n+4) * 128) + (n*8) + __aligned(128) 256 |
| 203 | * Ignore the alignment (which is safe in this case as long as we are |
| 204 | * careful with our rounding) and solve for n: |
| 205 | */ |
| 206 | return ((spa_size / 8) - 96) / 17; |
| 207 | } |
| 208 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 209 | static int cxl_alloc_spa(struct cxl_afu *afu, int mode) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 210 | { |
Ian Munsie | 895a798 | 2016-05-04 14:46:30 +1000 | [diff] [blame] | 211 | unsigned spa_size; |
| 212 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 213 | /* Work out how many pages to allocate */ |
Ian Munsie | 2224b67 | 2016-06-29 22:16:26 +1000 | [diff] [blame] | 214 | afu->native->spa_order = -1; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 215 | do { |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 216 | afu->native->spa_order++; |
Ian Munsie | 895a798 | 2016-05-04 14:46:30 +1000 | [diff] [blame] | 217 | spa_size = (1 << afu->native->spa_order) * PAGE_SIZE; |
| 218 | |
| 219 | if (spa_size > 0x100000) { |
| 220 | dev_warn(&afu->dev, "num_of_processes too large for the SPA, limiting to %i (0x%x)\n", |
| 221 | afu->native->spa_max_procs, afu->native->spa_size); |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 222 | if (mode != CXL_MODE_DEDICATED) |
| 223 | afu->num_procs = afu->native->spa_max_procs; |
Ian Munsie | 895a798 | 2016-05-04 14:46:30 +1000 | [diff] [blame] | 224 | break; |
| 225 | } |
| 226 | |
| 227 | afu->native->spa_size = spa_size; |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 228 | afu->native->spa_max_procs = spa_max_procs(afu->native->spa_size); |
| 229 | } while (afu->native->spa_max_procs < afu->num_procs); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 230 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 231 | if (!(afu->native->spa = (struct cxl_process_element *) |
| 232 | __get_free_pages(GFP_KERNEL | __GFP_ZERO, afu->native->spa_order))) { |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 233 | pr_err("cxl_alloc_spa: Unable to allocate scheduled process area\n"); |
| 234 | return -ENOMEM; |
| 235 | } |
| 236 | pr_devel("spa pages: %i afu->spa_max_procs: %i afu->num_procs: %i\n", |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 237 | 1<<afu->native->spa_order, afu->native->spa_max_procs, afu->num_procs); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 238 | |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static void attach_spa(struct cxl_afu *afu) |
| 243 | { |
| 244 | u64 spap; |
| 245 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 246 | afu->native->sw_command_status = (__be64 *)((char *)afu->native->spa + |
| 247 | ((afu->native->spa_max_procs + 3) * 128)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 248 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 249 | spap = virt_to_phys(afu->native->spa) & CXL_PSL_SPAP_Addr; |
| 250 | spap |= ((afu->native->spa_size >> (12 - CXL_PSL_SPAP_Size_Shift)) - 1) & CXL_PSL_SPAP_Size; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 251 | spap |= CXL_PSL_SPAP_V; |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 252 | pr_devel("cxl: SPA allocated at 0x%p. Max processes: %i, sw_command_status: 0x%p CXL_PSL_SPAP_An=0x%016llx\n", |
| 253 | afu->native->spa, afu->native->spa_max_procs, |
| 254 | afu->native->sw_command_status, spap); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 255 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, spap); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 256 | } |
| 257 | |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 258 | static inline void detach_spa(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 259 | { |
Ian Munsie | db7933f | 2014-12-08 19:18:00 +1100 | [diff] [blame] | 260 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0); |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | void cxl_release_spa(struct cxl_afu *afu) |
| 264 | { |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 265 | if (afu->native->spa) { |
| 266 | free_pages((unsigned long) afu->native->spa, |
| 267 | afu->native->spa_order); |
| 268 | afu->native->spa = NULL; |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 269 | } |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 270 | } |
| 271 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 272 | /* |
| 273 | * Invalidation of all ERAT entries is no longer required by CAIA2. Use |
| 274 | * only for debug. |
| 275 | */ |
| 276 | int cxl_invalidate_all_psl9(struct cxl *adapter) |
| 277 | { |
| 278 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
| 279 | u64 ierat; |
| 280 | |
| 281 | pr_devel("CXL adapter - invalidation of all ERAT entries\n"); |
| 282 | |
| 283 | /* Invalidates all ERAT entries for Radix or HPT */ |
| 284 | ierat = CXL_XSL9_IERAT_IALL; |
| 285 | if (radix_enabled()) |
| 286 | ierat |= CXL_XSL9_IERAT_INVR; |
| 287 | cxl_p1_write(adapter, CXL_XSL9_IERAT, ierat); |
| 288 | |
| 289 | while (cxl_p1_read(adapter, CXL_XSL9_IERAT) & CXL_XSL9_IERAT_IINPROG) { |
| 290 | if (time_after_eq(jiffies, timeout)) { |
| 291 | dev_warn(&adapter->dev, |
| 292 | "WARNING: CXL adapter invalidation of all ERAT entries timed out!\n"); |
| 293 | return -EBUSY; |
| 294 | } |
| 295 | if (!cxl_ops->link_ok(adapter, NULL)) |
| 296 | return -EIO; |
| 297 | cpu_relax(); |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 302 | int cxl_invalidate_all_psl8(struct cxl *adapter) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 303 | { |
| 304 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
| 305 | |
| 306 | pr_devel("CXL adapter wide TLBIA & SLBIA\n"); |
| 307 | |
| 308 | cxl_p1_write(adapter, CXL_PSL_AFUSEL, CXL_PSL_AFUSEL_A); |
| 309 | |
| 310 | cxl_p1_write(adapter, CXL_PSL_TLBIA, CXL_TLB_SLB_IQ_ALL); |
| 311 | while (cxl_p1_read(adapter, CXL_PSL_TLBIA) & CXL_TLB_SLB_P) { |
| 312 | if (time_after_eq(jiffies, timeout)) { |
| 313 | dev_warn(&adapter->dev, "WARNING: CXL adapter wide TLBIA timed out!\n"); |
| 314 | return -EBUSY; |
| 315 | } |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 316 | if (!cxl_ops->link_ok(adapter, NULL)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 317 | return -EIO; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 318 | cpu_relax(); |
| 319 | } |
| 320 | |
| 321 | cxl_p1_write(adapter, CXL_PSL_SLBIA, CXL_TLB_SLB_IQ_ALL); |
| 322 | while (cxl_p1_read(adapter, CXL_PSL_SLBIA) & CXL_TLB_SLB_P) { |
| 323 | if (time_after_eq(jiffies, timeout)) { |
| 324 | dev_warn(&adapter->dev, "WARNING: CXL adapter wide SLBIA timed out!\n"); |
| 325 | return -EBUSY; |
| 326 | } |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 327 | if (!cxl_ops->link_ok(adapter, NULL)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 328 | return -EIO; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 329 | cpu_relax(); |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
Frederic Barrat | aaa2245 | 2016-10-03 21:36:02 +0200 | [diff] [blame] | 334 | int cxl_data_cache_flush(struct cxl *adapter) |
| 335 | { |
| 336 | u64 reg; |
| 337 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
| 338 | |
| 339 | pr_devel("Flushing data cache\n"); |
| 340 | |
| 341 | reg = cxl_p1_read(adapter, CXL_PSL_Control); |
| 342 | reg |= CXL_PSL_Control_Fr; |
| 343 | cxl_p1_write(adapter, CXL_PSL_Control, reg); |
| 344 | |
| 345 | reg = cxl_p1_read(adapter, CXL_PSL_Control); |
| 346 | while ((reg & CXL_PSL_Control_Fs_MASK) != CXL_PSL_Control_Fs_Complete) { |
| 347 | if (time_after_eq(jiffies, timeout)) { |
| 348 | dev_warn(&adapter->dev, "WARNING: cache flush timed out!\n"); |
| 349 | return -EBUSY; |
| 350 | } |
| 351 | |
| 352 | if (!cxl_ops->link_ok(adapter, NULL)) { |
| 353 | dev_warn(&adapter->dev, "WARNING: link down when flushing cache\n"); |
| 354 | return -EIO; |
| 355 | } |
| 356 | cpu_relax(); |
| 357 | reg = cxl_p1_read(adapter, CXL_PSL_Control); |
| 358 | } |
| 359 | |
| 360 | reg &= ~CXL_PSL_Control_Fr; |
| 361 | cxl_p1_write(adapter, CXL_PSL_Control, reg); |
| 362 | return 0; |
| 363 | } |
| 364 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 365 | static int cxl_write_sstp(struct cxl_afu *afu, u64 sstp0, u64 sstp1) |
| 366 | { |
| 367 | int rc; |
| 368 | |
| 369 | /* 1. Disable SSTP by writing 0 to SSTP1[V] */ |
| 370 | cxl_p2n_write(afu, CXL_SSTP1_An, 0); |
| 371 | |
| 372 | /* 2. Invalidate all SLB entries */ |
| 373 | if ((rc = cxl_afu_slbia(afu))) |
| 374 | return rc; |
| 375 | |
| 376 | /* 3. Set SSTP0_An */ |
| 377 | cxl_p2n_write(afu, CXL_SSTP0_An, sstp0); |
| 378 | |
| 379 | /* 4. Set SSTP1_An */ |
| 380 | cxl_p2n_write(afu, CXL_SSTP1_An, sstp1); |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /* Using per slice version may improve performance here. (ie. SLBIA_An) */ |
| 386 | static void slb_invalid(struct cxl_context *ctx) |
| 387 | { |
| 388 | struct cxl *adapter = ctx->afu->adapter; |
| 389 | u64 slbia; |
| 390 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 391 | WARN_ON(!mutex_is_locked(&ctx->afu->native->spa_mutex)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 392 | |
| 393 | cxl_p1_write(adapter, CXL_PSL_LBISEL, |
| 394 | ((u64)be32_to_cpu(ctx->elem->common.pid) << 32) | |
| 395 | be32_to_cpu(ctx->elem->lpid)); |
| 396 | cxl_p1_write(adapter, CXL_PSL_SLBIA, CXL_TLB_SLB_IQ_LPIDPID); |
| 397 | |
| 398 | while (1) { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 399 | if (!cxl_ops->link_ok(adapter, NULL)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 400 | break; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 401 | slbia = cxl_p1_read(adapter, CXL_PSL_SLBIA); |
| 402 | if (!(slbia & CXL_TLB_SLB_P)) |
| 403 | break; |
| 404 | cpu_relax(); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static int do_process_element_cmd(struct cxl_context *ctx, |
| 409 | u64 cmd, u64 pe_state) |
| 410 | { |
| 411 | u64 state; |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 412 | unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 413 | int rc = 0; |
| 414 | |
| 415 | trace_cxl_llcmd(ctx, cmd); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 416 | |
| 417 | WARN_ON(!ctx->afu->enabled); |
| 418 | |
| 419 | ctx->elem->software_state = cpu_to_be32(pe_state); |
| 420 | smp_wmb(); |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 421 | *(ctx->afu->native->sw_command_status) = cpu_to_be64(cmd | 0 | ctx->pe); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 422 | smp_mb(); |
| 423 | cxl_p1n_write(ctx->afu, CXL_PSL_LLCMD_An, cmd | ctx->pe); |
| 424 | while (1) { |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 425 | if (time_after_eq(jiffies, timeout)) { |
| 426 | dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 427 | rc = -EBUSY; |
| 428 | goto out; |
Ian Munsie | a98e6e9 | 2014-12-08 19:17:56 +1100 | [diff] [blame] | 429 | } |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 430 | if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 431 | dev_warn(&ctx->afu->dev, "WARNING: Device link down, aborting Process Element Command!\n"); |
| 432 | rc = -EIO; |
| 433 | goto out; |
| 434 | } |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 435 | state = be64_to_cpup(ctx->afu->native->sw_command_status); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 436 | if (state == ~0ULL) { |
| 437 | pr_err("cxl: Error adding process element to AFU\n"); |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 438 | rc = -1; |
| 439 | goto out; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 440 | } |
| 441 | if ((state & (CXL_SPA_SW_CMD_MASK | CXL_SPA_SW_STATE_MASK | CXL_SPA_SW_LINK_MASK)) == |
| 442 | (cmd | (cmd >> 16) | ctx->pe)) |
| 443 | break; |
| 444 | /* |
| 445 | * The command won't finish in the PSL if there are |
| 446 | * outstanding DSIs. Hence we need to yield here in |
| 447 | * case there are outstanding DSIs that we need to |
| 448 | * service. Tuning possiblity: we could wait for a |
| 449 | * while before sched |
| 450 | */ |
| 451 | schedule(); |
| 452 | |
| 453 | } |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 454 | out: |
| 455 | trace_cxl_llcmd_done(ctx, cmd, rc); |
| 456 | return rc; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static int add_process_element(struct cxl_context *ctx) |
| 460 | { |
| 461 | int rc = 0; |
| 462 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 463 | mutex_lock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 464 | pr_devel("%s Adding pe: %i started\n", __func__, ctx->pe); |
| 465 | if (!(rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_ADD, CXL_PE_SOFTWARE_STATE_V))) |
| 466 | ctx->pe_inserted = true; |
| 467 | pr_devel("%s Adding pe: %i finished\n", __func__, ctx->pe); |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 468 | mutex_unlock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 469 | return rc; |
| 470 | } |
| 471 | |
| 472 | static int terminate_process_element(struct cxl_context *ctx) |
| 473 | { |
| 474 | int rc = 0; |
| 475 | |
| 476 | /* fast path terminate if it's already invalid */ |
| 477 | if (!(ctx->elem->software_state & cpu_to_be32(CXL_PE_SOFTWARE_STATE_V))) |
| 478 | return rc; |
| 479 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 480 | mutex_lock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 481 | pr_devel("%s Terminate pe: %i started\n", __func__, ctx->pe); |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 482 | /* We could be asked to terminate when the hw is down. That |
| 483 | * should always succeed: it's not running if the hw has gone |
| 484 | * away and is being reset. |
| 485 | */ |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 486 | if (cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 487 | rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_TERMINATE, |
| 488 | CXL_PE_SOFTWARE_STATE_V | CXL_PE_SOFTWARE_STATE_T); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 489 | ctx->elem->software_state = 0; /* Remove Valid bit */ |
| 490 | pr_devel("%s Terminate pe: %i finished\n", __func__, ctx->pe); |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 491 | mutex_unlock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 492 | return rc; |
| 493 | } |
| 494 | |
| 495 | static int remove_process_element(struct cxl_context *ctx) |
| 496 | { |
| 497 | int rc = 0; |
| 498 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 499 | mutex_lock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 500 | pr_devel("%s Remove pe: %i started\n", __func__, ctx->pe); |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 501 | |
| 502 | /* We could be asked to remove when the hw is down. Again, if |
| 503 | * the hw is down, the PE is gone, so we succeed. |
| 504 | */ |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 505 | if (cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 506 | rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_REMOVE, 0); |
| 507 | |
| 508 | if (!rc) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 509 | ctx->pe_inserted = false; |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 510 | if (cxl_is_power8()) |
| 511 | slb_invalid(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 512 | pr_devel("%s Remove pe: %i finished\n", __func__, ctx->pe); |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 513 | mutex_unlock(&ctx->afu->native->spa_mutex); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 514 | |
| 515 | return rc; |
| 516 | } |
| 517 | |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 518 | void cxl_assign_psn_space(struct cxl_context *ctx) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 519 | { |
| 520 | if (!ctx->afu->pp_size || ctx->master) { |
| 521 | ctx->psn_phys = ctx->afu->psn_phys; |
| 522 | ctx->psn_size = ctx->afu->adapter->ps_size; |
| 523 | } else { |
| 524 | ctx->psn_phys = ctx->afu->psn_phys + |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 525 | (ctx->afu->native->pp_offset + ctx->afu->pp_size * ctx->pe); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 526 | ctx->psn_size = ctx->afu->pp_size; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | static int activate_afu_directed(struct cxl_afu *afu) |
| 531 | { |
| 532 | int rc; |
| 533 | |
| 534 | dev_info(&afu->dev, "Activating AFU directed mode\n"); |
| 535 | |
Christophe Lombard | 4108efb | 2015-10-07 16:07:40 +1100 | [diff] [blame] | 536 | afu->num_procs = afu->max_procs_virtualised; |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 537 | if (afu->native->spa == NULL) { |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 538 | if (cxl_alloc_spa(afu, CXL_MODE_DIRECTED)) |
Daniel Axtens | 05155772 | 2015-08-14 17:41:19 +1000 | [diff] [blame] | 539 | return -ENOMEM; |
| 540 | } |
| 541 | attach_spa(afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 542 | |
| 543 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_AFU); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 544 | if (cxl_is_power8()) |
| 545 | cxl_p1n_write(afu, CXL_PSL_AMOR_An, 0xFFFFFFFFFFFFFFFFULL); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 546 | cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L); |
| 547 | |
| 548 | afu->current_mode = CXL_MODE_DIRECTED; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 549 | |
| 550 | if ((rc = cxl_chardev_m_afu_add(afu))) |
| 551 | return rc; |
| 552 | |
| 553 | if ((rc = cxl_sysfs_afu_m_add(afu))) |
| 554 | goto err; |
| 555 | |
| 556 | if ((rc = cxl_chardev_s_afu_add(afu))) |
| 557 | goto err1; |
| 558 | |
| 559 | return 0; |
| 560 | err1: |
| 561 | cxl_sysfs_afu_m_remove(afu); |
| 562 | err: |
| 563 | cxl_chardev_afu_remove(afu); |
| 564 | return rc; |
| 565 | } |
| 566 | |
| 567 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 568 | #define set_endian(sr) ((sr) |= CXL_PSL_SR_An_LE) |
| 569 | #else |
| 570 | #define set_endian(sr) ((sr) &= ~(CXL_PSL_SR_An_LE)) |
| 571 | #endif |
| 572 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 573 | static u64 calculate_sr(struct cxl_context *ctx) |
| 574 | { |
| 575 | u64 sr = 0; |
| 576 | |
Frederic Barrat | e606e03 | 2015-12-07 14:34:40 +0100 | [diff] [blame] | 577 | set_endian(sr); |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 578 | if (ctx->master) |
| 579 | sr |= CXL_PSL_SR_An_MP; |
| 580 | if (mfspr(SPRN_LPCR) & LPCR_TC) |
| 581 | sr |= CXL_PSL_SR_An_TC; |
| 582 | if (ctx->kernel) { |
Ian Munsie | 7a0d85d | 2016-05-06 17:46:36 +1000 | [diff] [blame] | 583 | if (!ctx->real_mode) |
| 584 | sr |= CXL_PSL_SR_An_R; |
| 585 | sr |= (mfmsr() & MSR_SF) | CXL_PSL_SR_An_HV; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 586 | } else { |
| 587 | sr |= CXL_PSL_SR_An_PR | CXL_PSL_SR_An_R; |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 588 | if (radix_enabled()) |
| 589 | sr |= CXL_PSL_SR_An_HV; |
| 590 | else |
| 591 | sr &= ~(CXL_PSL_SR_An_HV); |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 592 | if (!test_tsk_thread_flag(current, TIF_32BIT)) |
| 593 | sr |= CXL_PSL_SR_An_SF; |
| 594 | } |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 595 | if (cxl_is_psl9(ctx->afu)) { |
| 596 | if (radix_enabled()) |
| 597 | sr |= CXL_PSL_SR_An_XLAT_ror; |
| 598 | else |
| 599 | sr |= CXL_PSL_SR_An_XLAT_hpt; |
| 600 | } |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 601 | return sr; |
| 602 | } |
| 603 | |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 604 | static void update_ivtes_directed(struct cxl_context *ctx) |
| 605 | { |
| 606 | bool need_update = (ctx->status == STARTED); |
| 607 | int r; |
| 608 | |
| 609 | if (need_update) { |
| 610 | WARN_ON(terminate_process_element(ctx)); |
| 611 | WARN_ON(remove_process_element(ctx)); |
| 612 | } |
| 613 | |
| 614 | for (r = 0; r < CXL_IRQ_RANGES; r++) { |
| 615 | ctx->elem->ivte_offsets[r] = cpu_to_be16(ctx->irqs.offset[r]); |
| 616 | ctx->elem->ivte_ranges[r] = cpu_to_be16(ctx->irqs.range[r]); |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | * Theoretically we could use the update llcmd, instead of a |
| 621 | * terminate/remove/add (or if an atomic update was required we could |
| 622 | * do a suspend/update/resume), however it seems there might be issues |
| 623 | * with the update llcmd on some cards (including those using an XSL on |
| 624 | * an ASIC) so for now it's safest to go with the commands that are |
| 625 | * known to work. In the future if we come across a situation where the |
| 626 | * card may be performing transactions using the same PE while we are |
| 627 | * doing this update we might need to revisit this. |
| 628 | */ |
| 629 | if (need_update) |
| 630 | WARN_ON(add_process_element(ctx)); |
| 631 | } |
| 632 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 633 | static int process_element_entry_psl9(struct cxl_context *ctx, u64 wed, u64 amr) |
| 634 | { |
| 635 | u32 pid; |
| 636 | |
| 637 | cxl_assign_psn_space(ctx); |
| 638 | |
| 639 | ctx->elem->ctxtime = 0; /* disable */ |
| 640 | ctx->elem->lpid = cpu_to_be32(mfspr(SPRN_LPID)); |
| 641 | ctx->elem->haurp = 0; /* disable */ |
| 642 | |
| 643 | if (ctx->kernel) |
| 644 | pid = 0; |
| 645 | else { |
| 646 | if (ctx->mm == NULL) { |
| 647 | pr_devel("%s: unable to get mm for pe=%d pid=%i\n", |
| 648 | __func__, ctx->pe, pid_nr(ctx->pid)); |
| 649 | return -EINVAL; |
| 650 | } |
| 651 | pid = ctx->mm->context.id; |
| 652 | } |
| 653 | |
| 654 | ctx->elem->common.tid = 0; |
| 655 | ctx->elem->common.pid = cpu_to_be32(pid); |
| 656 | |
| 657 | ctx->elem->sr = cpu_to_be64(calculate_sr(ctx)); |
| 658 | |
| 659 | ctx->elem->common.csrp = 0; /* disable */ |
| 660 | |
| 661 | cxl_prefault(ctx, wed); |
| 662 | |
| 663 | /* |
| 664 | * Ensure we have the multiplexed PSL interrupt set up to take faults |
| 665 | * for kernel contexts that may not have allocated any AFU IRQs at all: |
| 666 | */ |
| 667 | if (ctx->irqs.range[0] == 0) { |
| 668 | ctx->irqs.offset[0] = ctx->afu->native->psl_hwirq; |
| 669 | ctx->irqs.range[0] = 1; |
| 670 | } |
| 671 | |
| 672 | ctx->elem->common.amr = cpu_to_be64(amr); |
| 673 | ctx->elem->common.wed = cpu_to_be64(wed); |
| 674 | |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | int cxl_attach_afu_directed_psl9(struct cxl_context *ctx, u64 wed, u64 amr) |
| 679 | { |
| 680 | int result; |
| 681 | |
| 682 | /* fill the process element entry */ |
| 683 | result = process_element_entry_psl9(ctx, wed, amr); |
| 684 | if (result) |
| 685 | return result; |
| 686 | |
| 687 | update_ivtes_directed(ctx); |
| 688 | |
| 689 | /* first guy needs to enable */ |
| 690 | result = cxl_ops->afu_check_and_enable(ctx->afu); |
| 691 | if (result) |
| 692 | return result; |
| 693 | |
| 694 | return add_process_element(ctx); |
| 695 | } |
| 696 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 697 | int cxl_attach_afu_directed_psl8(struct cxl_context *ctx, u64 wed, u64 amr) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 698 | { |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 699 | u32 pid; |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 700 | int result; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 701 | |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 702 | cxl_assign_psn_space(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 703 | |
| 704 | ctx->elem->ctxtime = 0; /* disable */ |
| 705 | ctx->elem->lpid = cpu_to_be32(mfspr(SPRN_LPID)); |
| 706 | ctx->elem->haurp = 0; /* disable */ |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 707 | ctx->elem->u.sdr = cpu_to_be64(mfspr(SPRN_SDR1)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 708 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 709 | pid = current->pid; |
| 710 | if (ctx->kernel) |
| 711 | pid = 0; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 712 | ctx->elem->common.tid = 0; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 713 | ctx->elem->common.pid = cpu_to_be32(pid); |
| 714 | |
| 715 | ctx->elem->sr = cpu_to_be64(calculate_sr(ctx)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 716 | |
| 717 | ctx->elem->common.csrp = 0; /* disable */ |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 718 | ctx->elem->common.u.psl8.aurp0 = 0; /* disable */ |
| 719 | ctx->elem->common.u.psl8.aurp1 = 0; /* disable */ |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 720 | |
| 721 | cxl_prefault(ctx, wed); |
| 722 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 723 | ctx->elem->common.u.psl8.sstp0 = cpu_to_be64(ctx->sstp0); |
| 724 | ctx->elem->common.u.psl8.sstp1 = cpu_to_be64(ctx->sstp1); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 725 | |
Ian Munsie | 3c206fa | 2016-05-04 14:52:58 +1000 | [diff] [blame] | 726 | /* |
| 727 | * Ensure we have the multiplexed PSL interrupt set up to take faults |
| 728 | * for kernel contexts that may not have allocated any AFU IRQs at all: |
| 729 | */ |
| 730 | if (ctx->irqs.range[0] == 0) { |
| 731 | ctx->irqs.offset[0] = ctx->afu->native->psl_hwirq; |
| 732 | ctx->irqs.range[0] = 1; |
| 733 | } |
| 734 | |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 735 | update_ivtes_directed(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 736 | |
| 737 | ctx->elem->common.amr = cpu_to_be64(amr); |
| 738 | ctx->elem->common.wed = cpu_to_be64(wed); |
| 739 | |
| 740 | /* first guy needs to enable */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 741 | if ((result = cxl_ops->afu_check_and_enable(ctx->afu))) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 742 | return result; |
| 743 | |
Daniel Axtens | 368857c | 2015-07-29 14:07:22 +1000 | [diff] [blame] | 744 | return add_process_element(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static int deactivate_afu_directed(struct cxl_afu *afu) |
| 748 | { |
| 749 | dev_info(&afu->dev, "Deactivating AFU directed mode\n"); |
| 750 | |
| 751 | afu->current_mode = 0; |
| 752 | afu->num_procs = 0; |
| 753 | |
| 754 | cxl_sysfs_afu_m_remove(afu); |
| 755 | cxl_chardev_afu_remove(afu); |
| 756 | |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 757 | /* |
| 758 | * The CAIA section 2.2.1 indicates that the procedure for starting and |
| 759 | * stopping an AFU in AFU directed mode is AFU specific, which is not |
| 760 | * ideal since this code is generic and with one exception has no |
| 761 | * knowledge of the AFU. This is in contrast to the procedure for |
| 762 | * disabling a dedicated process AFU, which is documented to just |
| 763 | * require a reset. The architecture does indicate that both an AFU |
| 764 | * reset and an AFU disable should result in the AFU being disabled and |
| 765 | * we do both followed by a PSL purge for safety. |
| 766 | * |
| 767 | * Notably we used to have some issues with the disable sequence on PSL |
| 768 | * cards, which is why we ended up using this heavy weight procedure in |
| 769 | * the first place, however a bug was discovered that had rendered the |
| 770 | * disable operation ineffective, so it is conceivable that was the |
| 771 | * sole explanation for those difficulties. Careful regression testing |
| 772 | * is recommended if anyone attempts to remove or reorder these |
| 773 | * operations. |
| 774 | * |
| 775 | * The XSL on the Mellanox CX4 behaves a little differently from the |
| 776 | * PSL based cards and will time out an AFU reset if the AFU is still |
| 777 | * enabled. That card is special in that we do have a means to identify |
| 778 | * it from this code, so in that case we skip the reset and just use a |
| 779 | * disable/purge to avoid the timeout and corresponding noise in the |
| 780 | * kernel log. |
| 781 | */ |
| 782 | if (afu->adapter->native->sl_ops->needs_reset_before_disable) |
| 783 | cxl_ops->afu_reset(afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 784 | cxl_afu_disable(afu); |
| 785 | cxl_psl_purge(afu); |
| 786 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 787 | return 0; |
| 788 | } |
| 789 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 790 | int cxl_activate_dedicated_process_psl9(struct cxl_afu *afu) |
| 791 | { |
| 792 | dev_info(&afu->dev, "Activating dedicated process mode\n"); |
| 793 | |
| 794 | /* |
| 795 | * If XSL is set to dedicated mode (Set in PSL_SCNTL reg), the |
| 796 | * XSL and AFU are programmed to work with a single context. |
| 797 | * The context information should be configured in the SPA area |
| 798 | * index 0 (so PSL_SPAP must be configured before enabling the |
| 799 | * AFU). |
| 800 | */ |
| 801 | afu->num_procs = 1; |
| 802 | if (afu->native->spa == NULL) { |
| 803 | if (cxl_alloc_spa(afu, CXL_MODE_DEDICATED)) |
| 804 | return -ENOMEM; |
| 805 | } |
| 806 | attach_spa(afu); |
| 807 | |
| 808 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_Process); |
| 809 | cxl_p1n_write(afu, CXL_PSL_ID_An, CXL_PSL_ID_An_F | CXL_PSL_ID_An_L); |
| 810 | |
| 811 | afu->current_mode = CXL_MODE_DEDICATED; |
| 812 | |
| 813 | return cxl_chardev_d_afu_add(afu); |
| 814 | } |
| 815 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 816 | int cxl_activate_dedicated_process_psl8(struct cxl_afu *afu) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 817 | { |
| 818 | dev_info(&afu->dev, "Activating dedicated process mode\n"); |
| 819 | |
| 820 | cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_Process); |
| 821 | |
| 822 | cxl_p1n_write(afu, CXL_PSL_CtxTime_An, 0); /* disable */ |
| 823 | cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0); /* disable */ |
| 824 | cxl_p1n_write(afu, CXL_PSL_AMOR_An, 0xFFFFFFFFFFFFFFFFULL); |
| 825 | cxl_p1n_write(afu, CXL_PSL_LPID_An, mfspr(SPRN_LPID)); |
| 826 | cxl_p1n_write(afu, CXL_HAURP_An, 0); /* disable */ |
| 827 | cxl_p1n_write(afu, CXL_PSL_SDR_An, mfspr(SPRN_SDR1)); |
| 828 | |
| 829 | cxl_p2n_write(afu, CXL_CSRP_An, 0); /* disable */ |
| 830 | cxl_p2n_write(afu, CXL_AURP0_An, 0); /* disable */ |
| 831 | cxl_p2n_write(afu, CXL_AURP1_An, 0); /* disable */ |
| 832 | |
| 833 | afu->current_mode = CXL_MODE_DEDICATED; |
| 834 | afu->num_procs = 1; |
| 835 | |
| 836 | return cxl_chardev_d_afu_add(afu); |
| 837 | } |
| 838 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 839 | void cxl_update_dedicated_ivtes_psl9(struct cxl_context *ctx) |
| 840 | { |
| 841 | int r; |
| 842 | |
| 843 | for (r = 0; r < CXL_IRQ_RANGES; r++) { |
| 844 | ctx->elem->ivte_offsets[r] = cpu_to_be16(ctx->irqs.offset[r]); |
| 845 | ctx->elem->ivte_ranges[r] = cpu_to_be16(ctx->irqs.range[r]); |
| 846 | } |
| 847 | } |
| 848 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 849 | void cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx) |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 850 | { |
| 851 | struct cxl_afu *afu = ctx->afu; |
| 852 | |
| 853 | cxl_p1n_write(afu, CXL_PSL_IVTE_Offset_An, |
| 854 | (((u64)ctx->irqs.offset[0] & 0xffff) << 48) | |
| 855 | (((u64)ctx->irqs.offset[1] & 0xffff) << 32) | |
| 856 | (((u64)ctx->irqs.offset[2] & 0xffff) << 16) | |
| 857 | ((u64)ctx->irqs.offset[3] & 0xffff)); |
| 858 | cxl_p1n_write(afu, CXL_PSL_IVTE_Limit_An, (u64) |
| 859 | (((u64)ctx->irqs.range[0] & 0xffff) << 48) | |
| 860 | (((u64)ctx->irqs.range[1] & 0xffff) << 32) | |
| 861 | (((u64)ctx->irqs.range[2] & 0xffff) << 16) | |
| 862 | ((u64)ctx->irqs.range[3] & 0xffff)); |
| 863 | } |
| 864 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 865 | int cxl_attach_dedicated_process_psl9(struct cxl_context *ctx, u64 wed, u64 amr) |
| 866 | { |
| 867 | struct cxl_afu *afu = ctx->afu; |
| 868 | int result; |
| 869 | |
| 870 | /* fill the process element entry */ |
| 871 | result = process_element_entry_psl9(ctx, wed, amr); |
| 872 | if (result) |
| 873 | return result; |
| 874 | |
| 875 | if (ctx->afu->adapter->native->sl_ops->update_dedicated_ivtes) |
| 876 | afu->adapter->native->sl_ops->update_dedicated_ivtes(ctx); |
| 877 | |
| 878 | result = cxl_ops->afu_reset(afu); |
| 879 | if (result) |
| 880 | return result; |
| 881 | |
| 882 | return afu_enable(afu); |
| 883 | } |
| 884 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 885 | int cxl_attach_dedicated_process_psl8(struct cxl_context *ctx, u64 wed, u64 amr) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 886 | { |
| 887 | struct cxl_afu *afu = ctx->afu; |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 888 | u64 pid; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 889 | int rc; |
| 890 | |
Michael Neuling | 2f66352 | 2015-05-27 16:07:13 +1000 | [diff] [blame] | 891 | pid = (u64)current->pid << 32; |
| 892 | if (ctx->kernel) |
| 893 | pid = 0; |
| 894 | cxl_p2n_write(afu, CXL_PSL_PID_TID_An, pid); |
| 895 | |
| 896 | cxl_p1n_write(afu, CXL_PSL_SR_An, calculate_sr(ctx)); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 897 | |
| 898 | if ((rc = cxl_write_sstp(afu, ctx->sstp0, ctx->sstp1))) |
| 899 | return rc; |
| 900 | |
| 901 | cxl_prefault(ctx, wed); |
| 902 | |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 903 | if (ctx->afu->adapter->native->sl_ops->update_dedicated_ivtes) |
| 904 | afu->adapter->native->sl_ops->update_dedicated_ivtes(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 905 | |
| 906 | cxl_p2n_write(afu, CXL_PSL_AMR_An, amr); |
| 907 | |
| 908 | /* master only context for dedicated */ |
Michael Neuling | 1a1a94b | 2015-05-27 16:07:10 +1000 | [diff] [blame] | 909 | cxl_assign_psn_space(ctx); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 910 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 911 | if ((rc = cxl_ops->afu_reset(afu))) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 912 | return rc; |
| 913 | |
| 914 | cxl_p2n_write(afu, CXL_PSL_WED_An, wed); |
| 915 | |
| 916 | return afu_enable(afu); |
| 917 | } |
| 918 | |
| 919 | static int deactivate_dedicated_process(struct cxl_afu *afu) |
| 920 | { |
| 921 | dev_info(&afu->dev, "Deactivating dedicated process mode\n"); |
| 922 | |
| 923 | afu->current_mode = 0; |
| 924 | afu->num_procs = 0; |
| 925 | |
| 926 | cxl_chardev_afu_remove(afu); |
| 927 | |
| 928 | return 0; |
| 929 | } |
| 930 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 931 | static int native_afu_deactivate_mode(struct cxl_afu *afu, int mode) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 932 | { |
| 933 | if (mode == CXL_MODE_DIRECTED) |
| 934 | return deactivate_afu_directed(afu); |
| 935 | if (mode == CXL_MODE_DEDICATED) |
| 936 | return deactivate_dedicated_process(afu); |
| 937 | return 0; |
| 938 | } |
| 939 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 940 | static int native_afu_activate_mode(struct cxl_afu *afu, int mode) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 941 | { |
| 942 | if (!mode) |
| 943 | return 0; |
| 944 | if (!(mode & afu->modes_supported)) |
| 945 | return -EINVAL; |
| 946 | |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 947 | if (!cxl_ops->link_ok(afu->adapter, afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 948 | WARN(1, "Device link is down, refusing to activate!\n"); |
| 949 | return -EIO; |
| 950 | } |
| 951 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 952 | if (mode == CXL_MODE_DIRECTED) |
| 953 | return activate_afu_directed(afu); |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 954 | if ((mode == CXL_MODE_DEDICATED) && |
| 955 | (afu->adapter->native->sl_ops->activate_dedicated_process)) |
| 956 | return afu->adapter->native->sl_ops->activate_dedicated_process(afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 957 | |
| 958 | return -EINVAL; |
| 959 | } |
| 960 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 961 | static int native_attach_process(struct cxl_context *ctx, bool kernel, |
| 962 | u64 wed, u64 amr) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 963 | { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 964 | if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 965 | WARN(1, "Device link is down, refusing to attach process!\n"); |
| 966 | return -EIO; |
| 967 | } |
| 968 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 969 | ctx->kernel = kernel; |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 970 | if ((ctx->afu->current_mode == CXL_MODE_DIRECTED) && |
| 971 | (ctx->afu->adapter->native->sl_ops->attach_afu_directed)) |
| 972 | return ctx->afu->adapter->native->sl_ops->attach_afu_directed(ctx, wed, amr); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 973 | |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 974 | if ((ctx->afu->current_mode == CXL_MODE_DEDICATED) && |
| 975 | (ctx->afu->adapter->native->sl_ops->attach_dedicated_process)) |
| 976 | return ctx->afu->adapter->native->sl_ops->attach_dedicated_process(ctx, wed, amr); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 977 | |
| 978 | return -EINVAL; |
| 979 | } |
| 980 | |
| 981 | static inline int detach_process_native_dedicated(struct cxl_context *ctx) |
| 982 | { |
Ian Munsie | 5e7823c | 2016-07-01 02:50:40 +1000 | [diff] [blame] | 983 | /* |
| 984 | * The CAIA section 2.1.1 indicates that we need to do an AFU reset to |
| 985 | * stop the AFU in dedicated mode (we therefore do not make that |
| 986 | * optional like we do in the afu directed path). It does not indicate |
| 987 | * that we need to do an explicit disable (which should occur |
| 988 | * implicitly as part of the reset) or purge, but we do these as well |
| 989 | * to be on the safe side. |
| 990 | * |
| 991 | * Notably we used to have some issues with the disable sequence |
| 992 | * (before the sequence was spelled out in the architecture) which is |
| 993 | * why we were so heavy weight in the first place, however a bug was |
| 994 | * discovered that had rendered the disable operation ineffective, so |
| 995 | * it is conceivable that was the sole explanation for those |
| 996 | * difficulties. Point is, we should be careful and do some regression |
| 997 | * testing if we ever attempt to remove any part of this procedure. |
| 998 | */ |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 999 | cxl_ops->afu_reset(ctx->afu); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1000 | cxl_afu_disable(ctx->afu); |
| 1001 | cxl_psl_purge(ctx->afu); |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 1005 | static void native_update_ivtes(struct cxl_context *ctx) |
| 1006 | { |
| 1007 | if (ctx->afu->current_mode == CXL_MODE_DIRECTED) |
| 1008 | return update_ivtes_directed(ctx); |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1009 | if ((ctx->afu->current_mode == CXL_MODE_DEDICATED) && |
| 1010 | (ctx->afu->adapter->native->sl_ops->update_dedicated_ivtes)) |
| 1011 | return ctx->afu->adapter->native->sl_ops->update_dedicated_ivtes(ctx); |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 1012 | WARN(1, "native_update_ivtes: Bad mode\n"); |
| 1013 | } |
| 1014 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1015 | static inline int detach_process_native_afu_directed(struct cxl_context *ctx) |
| 1016 | { |
| 1017 | if (!ctx->pe_inserted) |
| 1018 | return 0; |
| 1019 | if (terminate_process_element(ctx)) |
| 1020 | return -1; |
| 1021 | if (remove_process_element(ctx)) |
| 1022 | return -1; |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1027 | static int native_detach_process(struct cxl_context *ctx) |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1028 | { |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 1029 | trace_cxl_detach(ctx); |
| 1030 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1031 | if (ctx->afu->current_mode == CXL_MODE_DEDICATED) |
| 1032 | return detach_process_native_dedicated(ctx); |
| 1033 | |
| 1034 | return detach_process_native_afu_directed(ctx); |
| 1035 | } |
| 1036 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1037 | 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] | 1038 | { |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 1039 | /* If the adapter has gone away, we can't get any meaningful |
| 1040 | * information. |
| 1041 | */ |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 1042 | if (!cxl_ops->link_ok(afu->adapter, afu)) |
Daniel Axtens | 0b3f9c7 | 2015-08-14 17:41:18 +1000 | [diff] [blame] | 1043 | return -EIO; |
| 1044 | |
Ian Munsie | bc78b05 | 2014-11-14 17:37:50 +1100 | [diff] [blame] | 1045 | info->dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
| 1046 | info->dar = cxl_p2n_read(afu, CXL_PSL_DAR_An); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 1047 | if (cxl_is_power8()) |
| 1048 | info->dsr = cxl_p2n_read(afu, CXL_PSL_DSR_An); |
Ian Munsie | bc78b05 | 2014-11-14 17:37:50 +1100 | [diff] [blame] | 1049 | info->afu_err = cxl_p2n_read(afu, CXL_AFU_ERR_An); |
| 1050 | info->errstat = cxl_p2n_read(afu, CXL_PSL_ErrStat_An); |
Christophe Lombard | 444c4ba | 2016-03-04 12:26:34 +0100 | [diff] [blame] | 1051 | info->proc_handle = 0; |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 1056 | void cxl_native_irq_dump_regs_psl9(struct cxl_context *ctx) |
| 1057 | { |
| 1058 | u64 fir1, fir2, serr; |
| 1059 | |
| 1060 | fir1 = cxl_p1_read(ctx->afu->adapter, CXL_PSL9_FIR1); |
| 1061 | fir2 = cxl_p1_read(ctx->afu->adapter, CXL_PSL9_FIR2); |
| 1062 | |
| 1063 | dev_crit(&ctx->afu->dev, "PSL_FIR1: 0x%016llx\n", fir1); |
| 1064 | dev_crit(&ctx->afu->dev, "PSL_FIR2: 0x%016llx\n", fir2); |
| 1065 | if (ctx->afu->adapter->native->sl_ops->register_serr_irq) { |
| 1066 | serr = cxl_p1n_read(ctx->afu, CXL_PSL_SERR_An); |
| 1067 | cxl_afu_decode_psl_serr(ctx->afu, serr); |
| 1068 | } |
| 1069 | } |
| 1070 | |
Christophe Lombard | 64663f3 | 2017-04-07 16:11:57 +0200 | [diff] [blame] | 1071 | void cxl_native_irq_dump_regs_psl8(struct cxl_context *ctx) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1072 | { |
| 1073 | u64 fir1, fir2, fir_slice, serr, afu_debug; |
| 1074 | |
| 1075 | fir1 = cxl_p1_read(ctx->afu->adapter, CXL_PSL_FIR1); |
| 1076 | fir2 = cxl_p1_read(ctx->afu->adapter, CXL_PSL_FIR2); |
| 1077 | fir_slice = cxl_p1n_read(ctx->afu, CXL_PSL_FIR_SLICE_An); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1078 | afu_debug = cxl_p1n_read(ctx->afu, CXL_AFU_DEBUG_An); |
| 1079 | |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1080 | dev_crit(&ctx->afu->dev, "PSL_FIR1: 0x%016llx\n", fir1); |
| 1081 | dev_crit(&ctx->afu->dev, "PSL_FIR2: 0x%016llx\n", fir2); |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1082 | if (ctx->afu->adapter->native->sl_ops->register_serr_irq) { |
| 1083 | serr = cxl_p1n_read(ctx->afu, CXL_PSL_SERR_An); |
Philippe Bergheaud | 6e0c50f | 2016-07-05 13:08:06 +0200 | [diff] [blame] | 1084 | cxl_afu_decode_psl_serr(ctx->afu, serr); |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1085 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1086 | dev_crit(&ctx->afu->dev, "PSL_FIR_SLICE_An: 0x%016llx\n", fir_slice); |
| 1087 | dev_crit(&ctx->afu->dev, "CXL_PSL_AFU_DEBUG_An: 0x%016llx\n", afu_debug); |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1088 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1089 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1090 | static irqreturn_t native_handle_psl_slice_error(struct cxl_context *ctx, |
| 1091 | u64 dsisr, u64 errstat) |
| 1092 | { |
| 1093 | |
| 1094 | dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%016llx\n", errstat); |
| 1095 | |
| 1096 | if (ctx->afu->adapter->native->sl_ops->psl_irq_dump_registers) |
| 1097 | ctx->afu->adapter->native->sl_ops->psl_irq_dump_registers(ctx); |
| 1098 | |
| 1099 | if (ctx->afu->adapter->native->sl_ops->debugfs_stop_trace) { |
| 1100 | dev_crit(&ctx->afu->dev, "STOPPING CXL TRACE\n"); |
| 1101 | ctx->afu->adapter->native->sl_ops->debugfs_stop_trace(ctx->afu->adapter); |
| 1102 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1103 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1104 | return cxl_ops->ack_irq(ctx, 0, errstat); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 1107 | static bool cxl_is_translation_fault(struct cxl_afu *afu, u64 dsisr) |
| 1108 | { |
| 1109 | if ((cxl_is_psl8(afu)) && (dsisr & CXL_PSL_DSISR_TRANS)) |
| 1110 | return true; |
| 1111 | |
| 1112 | if ((cxl_is_psl9(afu)) && (dsisr & CXL_PSL9_DSISR_An_TF)) |
| 1113 | return true; |
| 1114 | |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1118 | irqreturn_t cxl_fail_irq_psl(struct cxl_afu *afu, struct cxl_irq_info *irq_info) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1119 | { |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 1120 | if (cxl_is_translation_fault(afu, irq_info->dsisr)) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1121 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE); |
| 1122 | else |
| 1123 | cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A); |
| 1124 | |
| 1125 | return IRQ_HANDLED; |
| 1126 | } |
| 1127 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1128 | static irqreturn_t native_irq_multiplexed(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1129 | { |
| 1130 | struct cxl_afu *afu = data; |
| 1131 | struct cxl_context *ctx; |
| 1132 | struct cxl_irq_info irq_info; |
Vaibhav Jain | abf051b | 2016-11-16 19:39:33 +0530 | [diff] [blame] | 1133 | u64 phreg = cxl_p2n_read(afu, CXL_PSL_PEHandle_An); |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1134 | int ph, ret = IRQ_HANDLED, res; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1135 | |
Vaibhav Jain | abf051b | 2016-11-16 19:39:33 +0530 | [diff] [blame] | 1136 | /* check if eeh kicked in while the interrupt was in flight */ |
| 1137 | if (unlikely(phreg == ~0ULL)) { |
| 1138 | dev_warn(&afu->dev, |
| 1139 | "Ignoring slice interrupt(%d) due to fenced card", |
| 1140 | irq); |
| 1141 | return IRQ_HANDLED; |
| 1142 | } |
| 1143 | /* Mask the pe-handle from register value */ |
| 1144 | ph = phreg & 0xffff; |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1145 | if ((res = native_get_irq_info(afu, &irq_info))) { |
| 1146 | WARN(1, "Unable to get CXL IRQ Info: %i\n", res); |
| 1147 | if (afu->adapter->native->sl_ops->fail_irq) |
| 1148 | return afu->adapter->native->sl_ops->fail_irq(afu, &irq_info); |
| 1149 | return ret; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | rcu_read_lock(); |
| 1153 | ctx = idr_find(&afu->contexts_idr, ph); |
| 1154 | if (ctx) { |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1155 | if (afu->adapter->native->sl_ops->handle_interrupt) |
| 1156 | ret = afu->adapter->native->sl_ops->handle_interrupt(irq, ctx, &irq_info); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1157 | rcu_read_unlock(); |
| 1158 | return ret; |
| 1159 | } |
| 1160 | rcu_read_unlock(); |
| 1161 | |
| 1162 | WARN(1, "Unable to demultiplex CXL PSL IRQ for PE %i DSISR %016llx DAR" |
| 1163 | " %016llx\n(Possible AFU HW issue - was a term/remove acked" |
| 1164 | " with outstanding transactions?)\n", ph, irq_info.dsisr, |
| 1165 | irq_info.dar); |
Christophe Lombard | bdd2e71 | 2017-04-07 16:11:56 +0200 | [diff] [blame] | 1166 | if (afu->adapter->native->sl_ops->fail_irq) |
| 1167 | ret = afu->adapter->native->sl_ops->fail_irq(afu, &irq_info); |
| 1168 | return ret; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Andrew Donnellan | 6fd40f1 | 2016-07-22 19:01:36 +1000 | [diff] [blame] | 1171 | static void native_irq_wait(struct cxl_context *ctx) |
Michael Neuling | 2bc79ff | 2016-04-22 14:57:49 +1000 | [diff] [blame] | 1172 | { |
| 1173 | u64 dsisr; |
| 1174 | int timeout = 1000; |
| 1175 | int ph; |
| 1176 | |
| 1177 | /* |
| 1178 | * Wait until no further interrupts are presented by the PSL |
| 1179 | * for this context. |
| 1180 | */ |
| 1181 | while (timeout--) { |
| 1182 | ph = cxl_p2n_read(ctx->afu, CXL_PSL_PEHandle_An) & 0xffff; |
| 1183 | if (ph != ctx->pe) |
| 1184 | return; |
| 1185 | dsisr = cxl_p2n_read(ctx->afu, CXL_PSL_DSISR_An); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 1186 | if (cxl_is_psl8(ctx->afu) && |
| 1187 | ((dsisr & CXL_PSL_DSISR_PENDING) == 0)) |
Michael Neuling | 2bc79ff | 2016-04-22 14:57:49 +1000 | [diff] [blame] | 1188 | return; |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 1189 | if (cxl_is_psl9(ctx->afu) && |
| 1190 | ((dsisr & CXL_PSL9_DSISR_PENDING) == 0)) |
| 1191 | return; |
Michael Neuling | 2bc79ff | 2016-04-22 14:57:49 +1000 | [diff] [blame] | 1192 | /* |
| 1193 | * We are waiting for the workqueue to process our |
| 1194 | * irq, so need to let that run here. |
| 1195 | */ |
| 1196 | msleep(1); |
| 1197 | } |
| 1198 | |
| 1199 | dev_warn(&ctx->afu->dev, "WARNING: waiting on DSI for PE %i" |
| 1200 | " DSISR %016llx!\n", ph, dsisr); |
| 1201 | return; |
| 1202 | } |
| 1203 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1204 | static irqreturn_t native_slice_irq_err(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1205 | { |
| 1206 | struct cxl_afu *afu = data; |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 1207 | u64 errstat, serr, afu_error, dsisr; |
| 1208 | u64 fir_slice, afu_debug; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1209 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1210 | /* |
| 1211 | * slice err interrupt is only used with full PSL (no XSL) |
| 1212 | */ |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1213 | serr = cxl_p1n_read(afu, CXL_PSL_SERR_An); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1214 | errstat = cxl_p2n_read(afu, CXL_PSL_ErrStat_An); |
Philippe Bergheaud | 6e0c50f | 2016-07-05 13:08:06 +0200 | [diff] [blame] | 1215 | afu_error = cxl_p2n_read(afu, CXL_AFU_ERR_An); |
| 1216 | dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
| 1217 | cxl_afu_decode_psl_serr(afu, serr); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 1218 | |
| 1219 | if (cxl_is_power8()) { |
| 1220 | fir_slice = cxl_p1n_read(afu, CXL_PSL_FIR_SLICE_An); |
| 1221 | afu_debug = cxl_p1n_read(afu, CXL_AFU_DEBUG_An); |
| 1222 | dev_crit(&afu->dev, "PSL_FIR_SLICE_An: 0x%016llx\n", fir_slice); |
| 1223 | dev_crit(&afu->dev, "CXL_PSL_AFU_DEBUG_An: 0x%016llx\n", afu_debug); |
| 1224 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1225 | dev_crit(&afu->dev, "CXL_PSL_ErrStat_An: 0x%016llx\n", errstat); |
Philippe Bergheaud | 6e0c50f | 2016-07-05 13:08:06 +0200 | [diff] [blame] | 1226 | dev_crit(&afu->dev, "AFU_ERR_An: 0x%.16llx\n", afu_error); |
| 1227 | dev_crit(&afu->dev, "PSL_DSISR_An: 0x%.16llx\n", dsisr); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1228 | |
| 1229 | cxl_p1n_write(afu, CXL_PSL_SERR_An, serr); |
| 1230 | |
| 1231 | return IRQ_HANDLED; |
| 1232 | } |
| 1233 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1234 | void cxl_native_err_irq_dump_regs(struct cxl *adapter) |
| 1235 | { |
| 1236 | u64 fir1, fir2; |
| 1237 | |
| 1238 | fir1 = cxl_p1_read(adapter, CXL_PSL_FIR1); |
| 1239 | fir2 = cxl_p1_read(adapter, CXL_PSL_FIR2); |
| 1240 | |
| 1241 | dev_crit(&adapter->dev, "PSL_FIR1: 0x%016llx\nPSL_FIR2: 0x%016llx\n", fir1, fir2); |
| 1242 | } |
| 1243 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1244 | static irqreturn_t native_irq_err(int irq, void *data) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1245 | { |
| 1246 | struct cxl *adapter = data; |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1247 | u64 err_ivte; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1248 | |
| 1249 | WARN(1, "CXL ERROR interrupt %i\n", irq); |
| 1250 | |
| 1251 | err_ivte = cxl_p1_read(adapter, CXL_PSL_ErrIVTE); |
| 1252 | dev_crit(&adapter->dev, "PSL_ErrIVTE: 0x%016llx\n", err_ivte); |
| 1253 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1254 | if (adapter->native->sl_ops->debugfs_stop_trace) { |
| 1255 | dev_crit(&adapter->dev, "STOPPING CXL TRACE\n"); |
| 1256 | adapter->native->sl_ops->debugfs_stop_trace(adapter); |
| 1257 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1258 | |
Frederic Barrat | 6d38261 | 2016-05-24 03:39:18 +1000 | [diff] [blame] | 1259 | if (adapter->native->sl_ops->err_irq_dump_registers) |
| 1260 | adapter->native->sl_ops->err_irq_dump_registers(adapter); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1261 | |
| 1262 | return IRQ_HANDLED; |
| 1263 | } |
| 1264 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1265 | int cxl_native_register_psl_err_irq(struct cxl *adapter) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1266 | { |
| 1267 | int rc; |
| 1268 | |
| 1269 | adapter->irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", |
| 1270 | dev_name(&adapter->dev)); |
| 1271 | if (!adapter->irq_name) |
| 1272 | return -ENOMEM; |
| 1273 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1274 | if ((rc = cxl_register_one_irq(adapter, native_irq_err, adapter, |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1275 | &adapter->native->err_hwirq, |
| 1276 | &adapter->native->err_virq, |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1277 | adapter->irq_name))) { |
| 1278 | kfree(adapter->irq_name); |
| 1279 | adapter->irq_name = NULL; |
| 1280 | return rc; |
| 1281 | } |
| 1282 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1283 | cxl_p1_write(adapter, CXL_PSL_ErrIVTE, adapter->native->err_hwirq & 0xffff); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1284 | |
| 1285 | return 0; |
| 1286 | } |
| 1287 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1288 | void cxl_native_release_psl_err_irq(struct cxl *adapter) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1289 | { |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1290 | if (adapter->native->err_virq != irq_find_mapping(NULL, adapter->native->err_hwirq)) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1291 | return; |
| 1292 | |
| 1293 | cxl_p1_write(adapter, CXL_PSL_ErrIVTE, 0x0000000000000000); |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1294 | cxl_unmap_irq(adapter->native->err_virq, adapter); |
| 1295 | cxl_ops->release_one_irq(adapter, adapter->native->err_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1296 | kfree(adapter->irq_name); |
| 1297 | } |
| 1298 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1299 | int cxl_native_register_serr_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1300 | { |
| 1301 | u64 serr; |
| 1302 | int rc; |
| 1303 | |
| 1304 | afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", |
| 1305 | dev_name(&afu->dev)); |
| 1306 | if (!afu->err_irq_name) |
| 1307 | return -ENOMEM; |
| 1308 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1309 | 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] | 1310 | &afu->serr_hwirq, |
| 1311 | &afu->serr_virq, afu->err_irq_name))) { |
| 1312 | kfree(afu->err_irq_name); |
| 1313 | afu->err_irq_name = NULL; |
| 1314 | return rc; |
| 1315 | } |
| 1316 | |
| 1317 | serr = cxl_p1n_read(afu, CXL_PSL_SERR_An); |
Christophe Lombard | abd1d99 | 2017-04-07 16:11:58 +0200 | [diff] [blame] | 1318 | if (cxl_is_power8()) |
| 1319 | serr = (serr & 0x00ffffffffff0000ULL) | (afu->serr_hwirq & 0xffff); |
Christophe Lombard | f24be42 | 2017-04-12 16:34:07 +0200 | [diff] [blame^] | 1320 | if (cxl_is_power9()) { |
| 1321 | /* |
| 1322 | * By default, all errors are masked. So don't set all masks. |
| 1323 | * Slice errors will be transfered. |
| 1324 | */ |
| 1325 | serr = (serr & ~0xff0000007fffffffULL) | (afu->serr_hwirq & 0xffff); |
| 1326 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1327 | cxl_p1n_write(afu, CXL_PSL_SERR_An, serr); |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1332 | void cxl_native_release_serr_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1333 | { |
| 1334 | if (afu->serr_virq != irq_find_mapping(NULL, afu->serr_hwirq)) |
| 1335 | return; |
| 1336 | |
| 1337 | cxl_p1n_write(afu, CXL_PSL_SERR_An, 0x0000000000000000); |
| 1338 | cxl_unmap_irq(afu->serr_virq, afu); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1339 | cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1340 | kfree(afu->err_irq_name); |
| 1341 | } |
| 1342 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1343 | int cxl_native_register_psl_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1344 | { |
| 1345 | int rc; |
| 1346 | |
| 1347 | afu->psl_irq_name = kasprintf(GFP_KERNEL, "cxl-%s", |
| 1348 | dev_name(&afu->dev)); |
| 1349 | if (!afu->psl_irq_name) |
| 1350 | return -ENOMEM; |
| 1351 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1352 | if ((rc = cxl_register_one_irq(afu->adapter, native_irq_multiplexed, |
| 1353 | afu, &afu->native->psl_hwirq, &afu->native->psl_virq, |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1354 | afu->psl_irq_name))) { |
| 1355 | kfree(afu->psl_irq_name); |
| 1356 | afu->psl_irq_name = NULL; |
| 1357 | } |
| 1358 | return rc; |
| 1359 | } |
| 1360 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1361 | void cxl_native_release_psl_irq(struct cxl_afu *afu) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1362 | { |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1363 | if (afu->native->psl_virq != irq_find_mapping(NULL, afu->native->psl_hwirq)) |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1364 | return; |
| 1365 | |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1366 | cxl_unmap_irq(afu->native->psl_virq, afu); |
| 1367 | cxl_ops->release_one_irq(afu->adapter, afu->native->psl_hwirq); |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1368 | kfree(afu->psl_irq_name); |
| 1369 | } |
| 1370 | |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1371 | static void recover_psl_err(struct cxl_afu *afu, u64 errstat) |
| 1372 | { |
| 1373 | u64 dsisr; |
| 1374 | |
Rasmus Villemoes | de36953 | 2015-06-11 13:27:52 +0200 | [diff] [blame] | 1375 | pr_devel("RECOVERING FROM PSL ERROR... (0x%016llx)\n", errstat); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1376 | |
| 1377 | /* Clear PSL_DSISR[PE] */ |
| 1378 | dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); |
| 1379 | cxl_p2n_write(afu, CXL_PSL_DSISR_An, dsisr & ~CXL_PSL_DSISR_An_PE); |
| 1380 | |
| 1381 | /* Write 1s to clear error status bits */ |
| 1382 | cxl_p2n_write(afu, CXL_PSL_ErrStat_An, errstat); |
| 1383 | } |
| 1384 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1385 | 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] | 1386 | { |
Ian Munsie | 9bcf28c | 2015-01-09 20:34:36 +1100 | [diff] [blame] | 1387 | trace_cxl_psl_irq_ack(ctx, tfc); |
Ian Munsie | f204e0b | 2014-10-08 19:55:02 +1100 | [diff] [blame] | 1388 | if (tfc) |
| 1389 | cxl_p2n_write(ctx->afu, CXL_PSL_TFC_An, tfc); |
| 1390 | if (psl_reset_mask) |
| 1391 | recover_psl_err(ctx->afu, psl_reset_mask); |
| 1392 | |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | int cxl_check_error(struct cxl_afu *afu) |
| 1397 | { |
| 1398 | return (cxl_p1n_read(afu, CXL_PSL_SCNTL_An) == ~0ULL); |
| 1399 | } |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1400 | |
Christophe Lombard | 4752876 | 2016-03-04 12:26:37 +0100 | [diff] [blame] | 1401 | static bool native_support_attributes(const char *attr_name, |
| 1402 | enum cxl_attrs type) |
| 1403 | { |
| 1404 | return true; |
| 1405 | } |
| 1406 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1407 | 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] | 1408 | { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 1409 | if (unlikely(!cxl_ops->link_ok(afu->adapter, afu))) |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1410 | return -EIO; |
| 1411 | if (unlikely(off >= afu->crs_len)) |
| 1412 | return -ERANGE; |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1413 | *out = in_le64(afu->native->afu_desc_mmio + afu->crs_offset + |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1414 | (cr * afu->crs_len) + off); |
| 1415 | return 0; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1418 | 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] | 1419 | { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 1420 | if (unlikely(!cxl_ops->link_ok(afu->adapter, afu))) |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1421 | return -EIO; |
| 1422 | if (unlikely(off >= afu->crs_len)) |
| 1423 | return -ERANGE; |
Christophe Lombard | cbffa3a | 2016-03-04 12:26:35 +0100 | [diff] [blame] | 1424 | *out = in_le32(afu->native->afu_desc_mmio + afu->crs_offset + |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1425 | (cr * afu->crs_len) + off); |
| 1426 | return 0; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1429 | 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] | 1430 | { |
| 1431 | u64 aligned_off = off & ~0x3L; |
| 1432 | u32 val; |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1433 | int rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1434 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1435 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1436 | if (!rc) |
| 1437 | *out = (val >> ((off & 0x3) * 8)) & 0xffff; |
| 1438 | return rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1441 | 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] | 1442 | { |
| 1443 | u64 aligned_off = off & ~0x3L; |
| 1444 | u32 val; |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1445 | int rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1446 | |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1447 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val); |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1448 | if (!rc) |
| 1449 | *out = (val >> ((off & 0x3) * 8)) & 0xff; |
| 1450 | return rc; |
Frederic Barrat | d56d301 | 2016-03-04 12:26:26 +0100 | [diff] [blame] | 1451 | } |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1452 | |
Frederic Barrat | d601ea9 | 2016-03-04 12:26:40 +0100 | [diff] [blame] | 1453 | static int native_afu_cr_write32(struct cxl_afu *afu, int cr, u64 off, u32 in) |
| 1454 | { |
Christophe Lombard | 0d400f7 | 2016-03-04 12:26:41 +0100 | [diff] [blame] | 1455 | if (unlikely(!cxl_ops->link_ok(afu->adapter, afu))) |
Frederic Barrat | d601ea9 | 2016-03-04 12:26:40 +0100 | [diff] [blame] | 1456 | return -EIO; |
| 1457 | if (unlikely(off >= afu->crs_len)) |
| 1458 | return -ERANGE; |
| 1459 | out_le32(afu->native->afu_desc_mmio + afu->crs_offset + |
| 1460 | (cr * afu->crs_len) + off, in); |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static int native_afu_cr_write16(struct cxl_afu *afu, int cr, u64 off, u16 in) |
| 1465 | { |
| 1466 | u64 aligned_off = off & ~0x3L; |
| 1467 | u32 val32, mask, shift; |
| 1468 | int rc; |
| 1469 | |
| 1470 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val32); |
| 1471 | if (rc) |
| 1472 | return rc; |
| 1473 | shift = (off & 0x3) * 8; |
| 1474 | WARN_ON(shift == 24); |
| 1475 | mask = 0xffff << shift; |
| 1476 | val32 = (val32 & ~mask) | (in << shift); |
| 1477 | |
| 1478 | rc = native_afu_cr_write32(afu, cr, aligned_off, val32); |
| 1479 | return rc; |
| 1480 | } |
| 1481 | |
| 1482 | static int native_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in) |
| 1483 | { |
| 1484 | u64 aligned_off = off & ~0x3L; |
| 1485 | u32 val32, mask, shift; |
| 1486 | int rc; |
| 1487 | |
| 1488 | rc = native_afu_cr_read32(afu, cr, aligned_off, &val32); |
| 1489 | if (rc) |
| 1490 | return rc; |
| 1491 | shift = (off & 0x3) * 8; |
| 1492 | mask = 0xff << shift; |
| 1493 | val32 = (val32 & ~mask) | (in << shift); |
| 1494 | |
| 1495 | rc = native_afu_cr_write32(afu, cr, aligned_off, val32); |
| 1496 | return rc; |
| 1497 | } |
| 1498 | |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1499 | const struct cxl_backend_ops cxl_native_ops = { |
| 1500 | .module = THIS_MODULE, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1501 | .adapter_reset = cxl_pci_reset, |
| 1502 | .alloc_one_irq = cxl_pci_alloc_one_irq, |
| 1503 | .release_one_irq = cxl_pci_release_one_irq, |
| 1504 | .alloc_irq_ranges = cxl_pci_alloc_irq_ranges, |
| 1505 | .release_irq_ranges = cxl_pci_release_irq_ranges, |
| 1506 | .setup_irq = cxl_pci_setup_irq, |
| 1507 | .handle_psl_slice_error = native_handle_psl_slice_error, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1508 | .psl_interrupt = NULL, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1509 | .ack_irq = native_ack_irq, |
Michael Neuling | 2bc79ff | 2016-04-22 14:57:49 +1000 | [diff] [blame] | 1510 | .irq_wait = native_irq_wait, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1511 | .attach_process = native_attach_process, |
| 1512 | .detach_process = native_detach_process, |
Ian Munsie | 292841b | 2016-05-24 02:14:05 +1000 | [diff] [blame] | 1513 | .update_ivtes = native_update_ivtes, |
Christophe Lombard | 4752876 | 2016-03-04 12:26:37 +0100 | [diff] [blame] | 1514 | .support_attributes = native_support_attributes, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1515 | .link_ok = cxl_adapter_link_ok, |
Frederic Barrat | 2b04cf3 | 2016-03-04 12:26:29 +0100 | [diff] [blame] | 1516 | .release_afu = cxl_pci_release_afu, |
| 1517 | .afu_read_err_buffer = cxl_pci_afu_read_err_buffer, |
| 1518 | .afu_check_and_enable = native_afu_check_and_enable, |
| 1519 | .afu_activate_mode = native_afu_activate_mode, |
| 1520 | .afu_deactivate_mode = native_afu_deactivate_mode, |
| 1521 | .afu_reset = native_afu_reset, |
| 1522 | .afu_cr_read8 = native_afu_cr_read8, |
| 1523 | .afu_cr_read16 = native_afu_cr_read16, |
| 1524 | .afu_cr_read32 = native_afu_cr_read32, |
| 1525 | .afu_cr_read64 = native_afu_cr_read64, |
Frederic Barrat | d601ea9 | 2016-03-04 12:26:40 +0100 | [diff] [blame] | 1526 | .afu_cr_write8 = native_afu_cr_write8, |
| 1527 | .afu_cr_write16 = native_afu_cr_write16, |
| 1528 | .afu_cr_write32 = native_afu_cr_write32, |
| 1529 | .read_adapter_vpd = cxl_pci_read_adapter_vpd, |
Frederic Barrat | 5be587b | 2016-03-04 12:26:28 +0100 | [diff] [blame] | 1530 | }; |