aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/ad525x_dpot-spi.c4
-rw-r--r--drivers/misc/ad525x_dpot.c7
-rw-r--r--drivers/misc/cxl/Makefile5
-rw-r--r--drivers/misc/cxl/context.c82
-rw-r--r--drivers/misc/cxl/cxl.h22
-rw-r--r--drivers/misc/cxl/fault.c11
-rw-r--r--drivers/misc/cxl/file.c21
-rw-r--r--drivers/misc/cxl/irq.c7
-rw-r--r--drivers/misc/cxl/main.c2
-rw-r--r--drivers/misc/cxl/native.c39
-rw-r--r--drivers/misc/cxl/pci.c123
-rw-r--r--drivers/misc/cxl/sysfs.c236
-rw-r--r--drivers/misc/cxl/trace.c13
-rw-r--r--drivers/misc/cxl/trace.h459
-rw-r--r--drivers/misc/enclosure.c108
-rw-r--r--drivers/misc/genwqe/card_base.h1
-rw-r--r--drivers/misc/genwqe/card_sysfs.c1
-rw-r--r--drivers/misc/ioc4.c31
-rw-r--r--drivers/misc/mei/amthif.c14
-rw-r--r--drivers/misc/mei/bus.c69
-rw-r--r--drivers/misc/mei/client.c156
-rw-r--r--drivers/misc/mei/client.h17
-rw-r--r--drivers/misc/mei/debugfs.c32
-rw-r--r--drivers/misc/mei/hbm.c34
-rw-r--r--drivers/misc/mei/hw-me.c15
-rw-r--r--drivers/misc/mei/main.c22
-rw-r--r--drivers/misc/mei/mei_dev.h8
-rw-r--r--drivers/misc/mei/nfc.c2
-rw-r--r--drivers/misc/mei/wd.c1
-rw-r--r--drivers/misc/ti-st/st_core.c24
-rw-r--r--drivers/misc/ti-st/st_kim.c144
-rw-r--r--drivers/misc/ti-st/st_ll.c17
-rw-r--r--drivers/misc/vmw_vmci/vmci_driver.c2
-rw-r--r--drivers/misc/vmw_vmci/vmci_host.c13
-rw-r--r--drivers/misc/vmw_vmci/vmci_queue_pair.c16
35 files changed, 1502 insertions, 256 deletions
diff --git a/drivers/misc/ad525x_dpot-spi.c b/drivers/misc/ad525x_dpot-spi.c
index 9da04ede04f3..f4c82eafa8e5 100644
--- a/drivers/misc/ad525x_dpot-spi.c
+++ b/drivers/misc/ad525x_dpot-spi.c
@@ -15,18 +15,21 @@
15static int write8(void *client, u8 val) 15static int write8(void *client, u8 val)
16{ 16{
17 u8 data = val; 17 u8 data = val;
18
18 return spi_write(client, &data, 1); 19 return spi_write(client, &data, 1);
19} 20}
20 21
21static int write16(void *client, u8 reg, u8 val) 22static int write16(void *client, u8 reg, u8 val)
22{ 23{
23 u8 data[2] = {reg, val}; 24 u8 data[2] = {reg, val};
25
24 return spi_write(client, data, 2); 26 return spi_write(client, data, 2);
25} 27}
26 28
27static int write24(void *client, u8 reg, u16 val) 29static int write24(void *client, u8 reg, u16 val)
28{ 30{
29 u8 data[3] = {reg, val >> 8, val}; 31 u8 data[3] = {reg, val >> 8, val};
32
30 return spi_write(client, data, 3); 33 return spi_write(client, data, 3);
31} 34}
32 35
@@ -34,6 +37,7 @@ static int read8(void *client)
34{ 37{
35 int ret; 38 int ret;
36 u8 data; 39 u8 data;
40
37 ret = spi_read(client, &data, 1); 41 ret = spi_read(client, &data, 1);
38 if (ret < 0) 42 if (ret < 0)
39 return ret; 43 return ret;
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index a43053daad0e..15e88078ba1e 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -176,6 +176,7 @@ static s32 dpot_read_i2c(struct dpot_data *dpot, u8 reg)
176{ 176{
177 int value; 177 int value;
178 unsigned ctrl = 0; 178 unsigned ctrl = 0;
179
179 switch (dpot->uid) { 180 switch (dpot->uid) {
180 case DPOT_UID(AD5246_ID): 181 case DPOT_UID(AD5246_ID):
181 case DPOT_UID(AD5247_ID): 182 case DPOT_UID(AD5247_ID):
@@ -333,7 +334,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
333 case DPOT_UID(AD5246_ID): 334 case DPOT_UID(AD5246_ID):
334 case DPOT_UID(AD5247_ID): 335 case DPOT_UID(AD5247_ID):
335 return dpot_write_d8(dpot, value); 336 return dpot_write_d8(dpot, value);
336 break;
337 337
338 case DPOT_UID(AD5245_ID): 338 case DPOT_UID(AD5245_ID):
339 case DPOT_UID(AD5241_ID): 339 case DPOT_UID(AD5241_ID):
@@ -345,7 +345,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 345 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
346 0 : DPOT_AD5282_RDAC_AB; 346 0 : DPOT_AD5282_RDAC_AB;
347 return dpot_write_r8d8(dpot, ctrl, value); 347 return dpot_write_r8d8(dpot, ctrl, value);
348 break;
349 case DPOT_UID(AD5171_ID): 348 case DPOT_UID(AD5171_ID):
350 case DPOT_UID(AD5273_ID): 349 case DPOT_UID(AD5273_ID):
351 if (reg & DPOT_ADDR_OTP) { 350 if (reg & DPOT_ADDR_OTP) {
@@ -355,7 +354,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
355 ctrl = DPOT_AD5273_FUSE; 354 ctrl = DPOT_AD5273_FUSE;
356 } 355 }
357 return dpot_write_r8d8(dpot, ctrl, value); 356 return dpot_write_r8d8(dpot, ctrl, value);
358 break;
359 case DPOT_UID(AD5172_ID): 357 case DPOT_UID(AD5172_ID):
360 case DPOT_UID(AD5173_ID): 358 case DPOT_UID(AD5173_ID):
361 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ? 359 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
@@ -367,7 +365,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
367 ctrl |= DPOT_AD5170_2_3_FUSE; 365 ctrl |= DPOT_AD5170_2_3_FUSE;
368 } 366 }
369 return dpot_write_r8d8(dpot, ctrl, value); 367 return dpot_write_r8d8(dpot, ctrl, value);
370 break;
371 case DPOT_UID(AD5170_ID): 368 case DPOT_UID(AD5170_ID):
372 if (reg & DPOT_ADDR_OTP) { 369 if (reg & DPOT_ADDR_OTP) {
373 tmp = dpot_read_r8d16(dpot, tmp); 370 tmp = dpot_read_r8d16(dpot, tmp);
@@ -376,7 +373,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
376 ctrl = DPOT_AD5170_2_3_FUSE; 373 ctrl = DPOT_AD5170_2_3_FUSE;
377 } 374 }
378 return dpot_write_r8d8(dpot, ctrl, value); 375 return dpot_write_r8d8(dpot, ctrl, value);
379 break;
380 case DPOT_UID(AD5272_ID): 376 case DPOT_UID(AD5272_ID):
381 case DPOT_UID(AD5274_ID): 377 case DPOT_UID(AD5274_ID):
382 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2, 378 dpot_write_r8d8(dpot, DPOT_AD5270_1_2_4_CTRLREG << 2,
@@ -391,7 +387,6 @@ static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
391 387
392 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) | 388 return dpot_write_r8d8(dpot, (DPOT_AD5270_1_2_4_RDAC << 2) |
393 (value >> 8), value & 0xFF); 389 (value >> 8), value & 0xFF);
394 break;
395 default: 390 default:
396 if (reg & DPOT_ADDR_CMD) 391 if (reg & DPOT_ADDR_CMD)
397 return dpot_write_d8(dpot, reg); 392 return dpot_write_d8(dpot, reg);
diff --git a/drivers/misc/cxl/Makefile b/drivers/misc/cxl/Makefile
index 165e98fef2c2..edb494d3ff27 100644
--- a/drivers/misc/cxl/Makefile
+++ b/drivers/misc/cxl/Makefile
@@ -1,3 +1,6 @@
1cxl-y += main.o file.o irq.o fault.o native.o context.o sysfs.o debugfs.o pci.o 1cxl-y += main.o file.o irq.o fault.o native.o context.o sysfs.o debugfs.o pci.o trace.o
2obj-$(CONFIG_CXL) += cxl.o 2obj-$(CONFIG_CXL) += cxl.o
3obj-$(CONFIG_CXL_BASE) += base.o 3obj-$(CONFIG_CXL_BASE) += base.o
4
5# For tracepoints to include our trace.h from tracepoint infrastructure:
6CFLAGS_trace.o := -I$(src)
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index 51fd6b524371..d1b55fe62817 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -100,6 +100,46 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
100 return 0; 100 return 0;
101} 101}
102 102
103static int cxl_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
104{
105 struct cxl_context *ctx = vma->vm_file->private_data;
106 unsigned long address = (unsigned long)vmf->virtual_address;
107 u64 area, offset;
108
109 offset = vmf->pgoff << PAGE_SHIFT;
110
111 pr_devel("%s: pe: %i address: 0x%lx offset: 0x%llx\n",
112 __func__, ctx->pe, address, offset);
113
114 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) {
115 area = ctx->afu->psn_phys;
116 if (offset > ctx->afu->adapter->ps_size)
117 return VM_FAULT_SIGBUS;
118 } else {
119 area = ctx->psn_phys;
120 if (offset > ctx->psn_size)
121 return VM_FAULT_SIGBUS;
122 }
123
124 mutex_lock(&ctx->status_mutex);
125
126 if (ctx->status != STARTED) {
127 mutex_unlock(&ctx->status_mutex);
128 pr_devel("%s: Context not started, failing problem state access\n", __func__);
129 return VM_FAULT_SIGBUS;
130 }
131
132 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
133
134 mutex_unlock(&ctx->status_mutex);
135
136 return VM_FAULT_NOPAGE;
137}
138
139static const struct vm_operations_struct cxl_mmap_vmops = {
140 .fault = cxl_mmap_fault,
141};
142
103/* 143/*
104 * Map a per-context mmio space into the given vma. 144 * Map a per-context mmio space into the given vma.
105 */ 145 */
@@ -108,26 +148,25 @@ int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma)
108 u64 len = vma->vm_end - vma->vm_start; 148 u64 len = vma->vm_end - vma->vm_start;
109 len = min(len, ctx->psn_size); 149 len = min(len, ctx->psn_size);
110 150
111 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) { 151 if (ctx->afu->current_mode != CXL_MODE_DEDICATED) {
112 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 152 /* make sure there is a valid per process space for this AFU */
113 return vm_iomap_memory(vma, ctx->afu->psn_phys, ctx->afu->adapter->ps_size); 153 if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) {
114 } 154 pr_devel("AFU doesn't support mmio space\n");
155 return -EINVAL;
156 }
115 157
116 /* make sure there is a valid per process space for this AFU */ 158 /* Can't mmap until the AFU is enabled */
117 if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) { 159 if (!ctx->afu->enabled)
118 pr_devel("AFU doesn't support mmio space\n"); 160 return -EBUSY;
119 return -EINVAL;
120 } 161 }
121 162
122 /* Can't mmap until the AFU is enabled */
123 if (!ctx->afu->enabled)
124 return -EBUSY;
125
126 pr_devel("%s: mmio physical: %llx pe: %i master:%i\n", __func__, 163 pr_devel("%s: mmio physical: %llx pe: %i master:%i\n", __func__,
127 ctx->psn_phys, ctx->pe , ctx->master); 164 ctx->psn_phys, ctx->pe , ctx->master);
128 165
166 vma->vm_flags |= VM_IO | VM_PFNMAP;
129 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 167 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
130 return vm_iomap_memory(vma, ctx->psn_phys, len); 168 vma->vm_ops = &cxl_mmap_vmops;
169 return 0;
131} 170}
132 171
133/* 172/*
@@ -150,12 +189,6 @@ static void __detach_context(struct cxl_context *ctx)
150 afu_release_irqs(ctx); 189 afu_release_irqs(ctx);
151 flush_work(&ctx->fault_work); /* Only needed for dedicated process */ 190 flush_work(&ctx->fault_work); /* Only needed for dedicated process */
152 wake_up_all(&ctx->wq); 191 wake_up_all(&ctx->wq);
153
154 /* Release Problem State Area mapping */
155 mutex_lock(&ctx->mapping_lock);
156 if (ctx->mapping)
157 unmap_mapping_range(ctx->mapping, 0, 0, 1);
158 mutex_unlock(&ctx->mapping_lock);
159} 192}
160 193
161/* 194/*
@@ -184,6 +217,17 @@ void cxl_context_detach_all(struct cxl_afu *afu)
184 * created and torn down after the IDR removed 217 * created and torn down after the IDR removed
185 */ 218 */
186 __detach_context(ctx); 219 __detach_context(ctx);
220
221 /*
222 * We are force detaching - remove any active PSA mappings so
223 * userspace cannot interfere with the card if it comes back.
224 * Easiest way to exercise this is to unbind and rebind the
225 * driver via sysfs while it is in use.
226 */
227 mutex_lock(&ctx->mapping_lock);
228 if (ctx->mapping)
229 unmap_mapping_range(ctx->mapping, 0, 0, 1);
230 mutex_unlock(&ctx->mapping_lock);
187 } 231 }
188 mutex_unlock(&afu->contexts_lock); 232 mutex_unlock(&afu->contexts_lock);
189} 233}
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index 28078f8894a5..a1cee4767ec6 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -287,6 +287,13 @@ static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
287#define CXL_PE_SOFTWARE_STATE_S (1ul << (31 - 30)) /* Suspend */ 287#define CXL_PE_SOFTWARE_STATE_S (1ul << (31 - 30)) /* Suspend */
288#define CXL_PE_SOFTWARE_STATE_T (1ul << (31 - 31)) /* Terminate */ 288#define CXL_PE_SOFTWARE_STATE_T (1ul << (31 - 31)) /* Terminate */
289 289
290/****** CXL_PSL_RXCTL_An (Implementation Specific) **************************
291 * Controls AFU Hang Pulse, which sets the timeout for the AFU to respond to
292 * the PSL for any response (except MMIO). Timeouts will occur between 1x to 2x
293 * of the hang pulse frequency.
294 */
295#define CXL_PSL_RXCTL_AFUHP_4S 0x7000000000000000ULL
296
290/* SPA->sw_command_status */ 297/* SPA->sw_command_status */
291#define CXL_SPA_SW_CMD_MASK 0xffff000000000000ULL 298#define CXL_SPA_SW_CMD_MASK 0xffff000000000000ULL
292#define CXL_SPA_SW_CMD_TERMINATE 0x0001000000000000ULL 299#define CXL_SPA_SW_CMD_TERMINATE 0x0001000000000000ULL
@@ -375,6 +382,10 @@ struct cxl_afu {
375 int slice; 382 int slice;
376 int modes_supported; 383 int modes_supported;
377 int current_mode; 384 int current_mode;
385 int crs_num;
386 u64 crs_len;
387 u64 crs_offset;
388 struct list_head crs;
378 enum prefault_modes prefault_mode; 389 enum prefault_modes prefault_mode;
379 bool psa; 390 bool psa;
380 bool pp_psa; 391 bool pp_psa;
@@ -481,6 +492,8 @@ void cxl_release_one_irq(struct cxl *adapter, int hwirq);
481int cxl_alloc_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter, unsigned int num); 492int cxl_alloc_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter, unsigned int num);
482void cxl_release_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter); 493void cxl_release_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter);
483int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq, unsigned int virq); 494int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq, unsigned int virq);
495int cxl_update_image_control(struct cxl *adapter);
496int cxl_reset(struct cxl *adapter);
484 497
485/* common == phyp + powernv */ 498/* common == phyp + powernv */
486struct cxl_process_element_common { 499struct cxl_process_element_common {
@@ -542,6 +555,15 @@ static inline void __iomem *_cxl_p2n_addr(struct cxl_afu *afu, cxl_p2n_reg_t reg
542#define cxl_p2n_read(afu, reg) \ 555#define cxl_p2n_read(afu, reg) \
543 in_be64(_cxl_p2n_addr(afu, reg)) 556 in_be64(_cxl_p2n_addr(afu, reg))
544 557
558
559#define cxl_afu_cr_read64(afu, cr, off) \
560 in_le64((afu)->afu_desc_mmio + (afu)->crs_offset + ((cr) * (afu)->crs_len) + (off))
561#define cxl_afu_cr_read32(afu, cr, off) \
562 in_le32((afu)->afu_desc_mmio + (afu)->crs_offset + ((cr) * (afu)->crs_len) + (off))
563u16 cxl_afu_cr_read16(struct cxl_afu *afu, int cr, u64 off);
564u8 cxl_afu_cr_read8(struct cxl_afu *afu, int cr, u64 off);
565
566
545struct cxl_calls { 567struct cxl_calls {
546 void (*cxl_slbia)(struct mm_struct *mm); 568 void (*cxl_slbia)(struct mm_struct *mm);
547 struct module *owner; 569 struct module *owner;
diff --git a/drivers/misc/cxl/fault.c b/drivers/misc/cxl/fault.c
index f8684bca2d79..5286b8b704f5 100644
--- a/drivers/misc/cxl/fault.c
+++ b/drivers/misc/cxl/fault.c
@@ -20,6 +20,7 @@
20#include <asm/mmu.h> 20#include <asm/mmu.h>
21 21
22#include "cxl.h" 22#include "cxl.h"
23#include "trace.h"
23 24
24static bool sste_matches(struct cxl_sste *sste, struct copro_slb *slb) 25static bool sste_matches(struct cxl_sste *sste, struct copro_slb *slb)
25{ 26{
@@ -75,6 +76,7 @@ static void cxl_load_segment(struct cxl_context *ctx, struct copro_slb *slb)
75 76
76 pr_devel("CXL Populating SST[%li]: %#llx %#llx\n", 77 pr_devel("CXL Populating SST[%li]: %#llx %#llx\n",
77 sste - ctx->sstp, slb->vsid, slb->esid); 78 sste - ctx->sstp, slb->vsid, slb->esid);
79 trace_cxl_ste_write(ctx, sste - ctx->sstp, slb->esid, slb->vsid);
78 80
79 sste->vsid_data = cpu_to_be64(slb->vsid); 81 sste->vsid_data = cpu_to_be64(slb->vsid);
80 sste->esid_data = cpu_to_be64(slb->esid); 82 sste->esid_data = cpu_to_be64(slb->esid);
@@ -116,6 +118,7 @@ static int cxl_handle_segment_miss(struct cxl_context *ctx,
116 int rc; 118 int rc;
117 119
118 pr_devel("CXL interrupt: Segment fault pe: %i ea: %#llx\n", ctx->pe, ea); 120 pr_devel("CXL interrupt: Segment fault pe: %i ea: %#llx\n", ctx->pe, ea);
121 trace_cxl_ste_miss(ctx, ea);
119 122
120 if ((rc = cxl_fault_segment(ctx, mm, ea))) 123 if ((rc = cxl_fault_segment(ctx, mm, ea)))
121 cxl_ack_ae(ctx); 124 cxl_ack_ae(ctx);
@@ -135,6 +138,8 @@ static void cxl_handle_page_fault(struct cxl_context *ctx,
135 int result; 138 int result;
136 unsigned long access, flags, inv_flags = 0; 139 unsigned long access, flags, inv_flags = 0;
137 140
141 trace_cxl_pte_miss(ctx, dsisr, dar);
142
138 if ((result = copro_handle_mm_fault(mm, dar, dsisr, &flt))) { 143 if ((result = copro_handle_mm_fault(mm, dar, dsisr, &flt))) {
139 pr_devel("copro_handle_mm_fault failed: %#x\n", result); 144 pr_devel("copro_handle_mm_fault failed: %#x\n", result);
140 return cxl_ack_ae(ctx); 145 return cxl_ack_ae(ctx);
@@ -180,6 +185,12 @@ void cxl_handle_fault(struct work_struct *fault_work)
180 return; 185 return;
181 } 186 }
182 187
188 /* Early return if the context is being / has been detached */
189 if (ctx->status == CLOSED) {
190 cxl_ack_ae(ctx);
191 return;
192 }
193
183 pr_devel("CXL BOTTOM HALF handling fault for afu pe: %i. " 194 pr_devel("CXL BOTTOM HALF handling fault for afu pe: %i. "
184 "DSISR: %#llx DAR: %#llx\n", ctx->pe, dsisr, dar); 195 "DSISR: %#llx DAR: %#llx\n", ctx->pe, dsisr, dar);
185 196
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index e9f2f10dbb37..2364bcadb9a9 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -23,6 +23,7 @@
23#include <asm/copro.h> 23#include <asm/copro.h>
24 24
25#include "cxl.h" 25#include "cxl.h"
26#include "trace.h"
26 27
27#define CXL_NUM_MINORS 256 /* Total to reserve */ 28#define CXL_NUM_MINORS 256 /* Total to reserve */
28#define CXL_DEV_MINORS 13 /* 1 control + 4 AFUs * 3 (dedicated/master/shared) */ 29#define CXL_DEV_MINORS 13 /* 1 control + 4 AFUs * 3 (dedicated/master/shared) */
@@ -140,18 +141,20 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
140 141
141 pr_devel("%s: pe: %i\n", __func__, ctx->pe); 142 pr_devel("%s: pe: %i\n", __func__, ctx->pe);
142 143
143 mutex_lock(&ctx->status_mutex); 144 /* Do this outside the status_mutex to avoid a circular dependency with
144 if (ctx->status != OPENED) { 145 * the locking in cxl_mmap_fault() */
145 rc = -EIO;
146 goto out;
147 }
148
149 if (copy_from_user(&work, uwork, 146 if (copy_from_user(&work, uwork,
150 sizeof(struct cxl_ioctl_start_work))) { 147 sizeof(struct cxl_ioctl_start_work))) {
151 rc = -EFAULT; 148 rc = -EFAULT;
152 goto out; 149 goto out;
153 } 150 }
154 151
152 mutex_lock(&ctx->status_mutex);
153 if (ctx->status != OPENED) {
154 rc = -EIO;
155 goto out;
156 }
157
155 /* 158 /*
156 * if any of the reserved fields are set or any of the unused 159 * if any of the reserved fields are set or any of the unused
157 * flags are set it's invalid 160 * flags are set it's invalid
@@ -184,9 +187,13 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
184 */ 187 */
185 ctx->pid = get_pid(get_task_pid(current, PIDTYPE_PID)); 188 ctx->pid = get_pid(get_task_pid(current, PIDTYPE_PID));
186 189
190 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
191
187 if ((rc = cxl_attach_process(ctx, false, work.work_element_descriptor, 192 if ((rc = cxl_attach_process(ctx, false, work.work_element_descriptor,
188 amr))) 193 amr))) {
194 afu_release_irqs(ctx);
189 goto out; 195 goto out;
196 }
190 197
191 ctx->status = STARTED; 198 ctx->status = STARTED;
192 rc = 0; 199 rc = 0;
diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c
index c294925f73ee..c8929c526691 100644
--- a/drivers/misc/cxl/irq.c
+++ b/drivers/misc/cxl/irq.c
@@ -17,6 +17,7 @@
17#include <misc/cxl.h> 17#include <misc/cxl.h>
18 18
19#include "cxl.h" 19#include "cxl.h"
20#include "trace.h"
20 21
21/* XXX: This is implementation specific */ 22/* XXX: This is implementation specific */
22static irqreturn_t handle_psl_slice_error(struct cxl_context *ctx, u64 dsisr, u64 errstat) 23static irqreturn_t handle_psl_slice_error(struct cxl_context *ctx, u64 dsisr, u64 errstat)
@@ -100,6 +101,8 @@ static irqreturn_t cxl_irq(int irq, void *data, struct cxl_irq_info *irq_info)
100 dsisr = irq_info->dsisr; 101 dsisr = irq_info->dsisr;
101 dar = irq_info->dar; 102 dar = irq_info->dar;
102 103
104 trace_cxl_psl_irq(ctx, irq, dsisr, dar);
105
103 pr_devel("CXL interrupt %i for afu pe: %i DSISR: %#llx DAR: %#llx\n", irq, ctx->pe, dsisr, dar); 106 pr_devel("CXL interrupt %i for afu pe: %i DSISR: %#llx DAR: %#llx\n", irq, ctx->pe, dsisr, dar);
104 107
105 if (dsisr & CXL_PSL_DSISR_An_DS) { 108 if (dsisr & CXL_PSL_DSISR_An_DS) {
@@ -167,6 +170,7 @@ static irqreturn_t cxl_irq(int irq, void *data, struct cxl_irq_info *irq_info)
167 } 170 }
168 171
169 cxl_ack_irq(ctx, CXL_PSL_TFC_An_A, 0); 172 cxl_ack_irq(ctx, CXL_PSL_TFC_An_A, 0);
173 return IRQ_HANDLED;
170 } 174 }
171 if (dsisr & CXL_PSL_DSISR_An_OC) 175 if (dsisr & CXL_PSL_DSISR_An_OC)
172 pr_devel("CXL interrupt: OS Context Warning\n"); 176 pr_devel("CXL interrupt: OS Context Warning\n");
@@ -237,6 +241,7 @@ static irqreturn_t cxl_irq_afu(int irq, void *data)
237 return IRQ_HANDLED; 241 return IRQ_HANDLED;
238 } 242 }
239 243
244 trace_cxl_afu_irq(ctx, afu_irq, irq, hwirq);
240 pr_devel("Received AFU interrupt %i for pe: %i (virq %i hwirq %lx)\n", 245 pr_devel("Received AFU interrupt %i for pe: %i (virq %i hwirq %lx)\n",
241 afu_irq, ctx->pe, irq, hwirq); 246 afu_irq, ctx->pe, irq, hwirq);
242 247
@@ -436,7 +441,7 @@ int afu_register_irqs(struct cxl_context *ctx, u32 count)
436 */ 441 */
437 INIT_LIST_HEAD(&ctx->irq_names); 442 INIT_LIST_HEAD(&ctx->irq_names);
438 for (r = 1; r < CXL_IRQ_RANGES; r++) { 443 for (r = 1; r < CXL_IRQ_RANGES; r++) {
439 for (i = 0; i < ctx->irqs.range[r]; hwirq++, i++) { 444 for (i = 0; i < ctx->irqs.range[r]; i++) {
440 irq_name = kmalloc(sizeof(struct cxl_irq_name), 445 irq_name = kmalloc(sizeof(struct cxl_irq_name),
441 GFP_KERNEL); 446 GFP_KERNEL);
442 if (!irq_name) 447 if (!irq_name)
diff --git a/drivers/misc/cxl/main.c b/drivers/misc/cxl/main.c
index 4cde9b661642..8ccddceead66 100644
--- a/drivers/misc/cxl/main.c
+++ b/drivers/misc/cxl/main.c
@@ -23,6 +23,7 @@
23#include <misc/cxl.h> 23#include <misc/cxl.h>
24 24
25#include "cxl.h" 25#include "cxl.h"
26#include "trace.h"
26 27
27static DEFINE_SPINLOCK(adapter_idr_lock); 28static DEFINE_SPINLOCK(adapter_idr_lock);
28static DEFINE_IDR(cxl_adapter_idr); 29static DEFINE_IDR(cxl_adapter_idr);
@@ -48,6 +49,7 @@ static inline void _cxl_slbia(struct cxl_context *ctx, struct mm_struct *mm)
48 ctx->afu->adapter->adapter_num, ctx->afu->slice, ctx->pe); 49 ctx->afu->adapter->adapter_num, ctx->afu->slice, ctx->pe);
49 50
50 spin_lock_irqsave(&ctx->sste_lock, flags); 51 spin_lock_irqsave(&ctx->sste_lock, flags);
52 trace_cxl_slbia(ctx);
51 memset(ctx->sstp, 0, ctx->sst_size); 53 memset(ctx->sstp, 0, ctx->sst_size);
52 spin_unlock_irqrestore(&ctx->sste_lock, flags); 54 spin_unlock_irqrestore(&ctx->sste_lock, flags);
53 mb(); 55 mb();
diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c
index f2b37b41a0da..29185fc61276 100644
--- a/drivers/misc/cxl/native.c
+++ b/drivers/misc/cxl/native.c
@@ -18,24 +18,28 @@
18#include <misc/cxl.h> 18#include <misc/cxl.h>
19 19
20#include "cxl.h" 20#include "cxl.h"
21#include "trace.h"
21 22
22static int afu_control(struct cxl_afu *afu, u64 command, 23static int afu_control(struct cxl_afu *afu, u64 command,
23 u64 result, u64 mask, bool enabled) 24 u64 result, u64 mask, bool enabled)
24{ 25{
25 u64 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); 26 u64 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An);
26 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); 27 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT);
28 int rc = 0;
27 29
28 spin_lock(&afu->afu_cntl_lock); 30 spin_lock(&afu->afu_cntl_lock);
29 pr_devel("AFU command starting: %llx\n", command); 31 pr_devel("AFU command starting: %llx\n", command);
30 32
33 trace_cxl_afu_ctrl(afu, command);
34
31 cxl_p2n_write(afu, CXL_AFU_Cntl_An, AFU_Cntl | command); 35 cxl_p2n_write(afu, CXL_AFU_Cntl_An, AFU_Cntl | command);
32 36
33 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An); 37 AFU_Cntl = cxl_p2n_read(afu, CXL_AFU_Cntl_An);
34 while ((AFU_Cntl & mask) != result) { 38 while ((AFU_Cntl & mask) != result) {
35 if (time_after_eq(jiffies, timeout)) { 39 if (time_after_eq(jiffies, timeout)) {
36 dev_warn(&afu->dev, "WARNING: AFU control timed out!\n"); 40 dev_warn(&afu->dev, "WARNING: AFU control timed out!\n");
37 spin_unlock(&afu->afu_cntl_lock); 41 rc = -EBUSY;
38 return -EBUSY; 42 goto out;
39 } 43 }
40 pr_devel_ratelimited("AFU control... (0x%.16llx)\n", 44 pr_devel_ratelimited("AFU control... (0x%.16llx)\n",
41 AFU_Cntl | command); 45 AFU_Cntl | command);
@@ -44,9 +48,11 @@ static int afu_control(struct cxl_afu *afu, u64 command,
44 }; 48 };
45 pr_devel("AFU command complete: %llx\n", command); 49 pr_devel("AFU command complete: %llx\n", command);
46 afu->enabled = enabled; 50 afu->enabled = enabled;
51out:
52 trace_cxl_afu_ctrl_done(afu, command, rc);
47 spin_unlock(&afu->afu_cntl_lock); 53 spin_unlock(&afu->afu_cntl_lock);
48 54
49 return 0; 55 return rc;
50} 56}
51 57
52static int afu_enable(struct cxl_afu *afu) 58static int afu_enable(struct cxl_afu *afu)
@@ -91,6 +97,9 @@ int cxl_psl_purge(struct cxl_afu *afu)
91 u64 dsisr, dar; 97 u64 dsisr, dar;
92 u64 start, end; 98 u64 start, end;
93 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); 99 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT);
100 int rc = 0;
101
102 trace_cxl_psl_ctrl(afu, CXL_PSL_SCNTL_An_Pc);
94 103
95 pr_devel("PSL purge request\n"); 104 pr_devel("PSL purge request\n");
96 105
@@ -107,7 +116,8 @@ int cxl_psl_purge(struct cxl_afu *afu)
107 == CXL_PSL_SCNTL_An_Ps_Pending) { 116 == CXL_PSL_SCNTL_An_Ps_Pending) {
108 if (time_after_eq(jiffies, timeout)) { 117 if (time_after_eq(jiffies, timeout)) {
109 dev_warn(&afu->dev, "WARNING: PSL Purge timed out!\n"); 118 dev_warn(&afu->dev, "WARNING: PSL Purge timed out!\n");
110 return -EBUSY; 119 rc = -EBUSY;
120 goto out;
111 } 121 }
112 dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); 122 dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An);
113 pr_devel_ratelimited("PSL purging... PSL_CNTL: 0x%.16llx PSL_DSISR: 0x%.16llx\n", PSL_CNTL, dsisr); 123 pr_devel_ratelimited("PSL purging... PSL_CNTL: 0x%.16llx PSL_DSISR: 0x%.16llx\n", PSL_CNTL, dsisr);
@@ -128,7 +138,9 @@ int cxl_psl_purge(struct cxl_afu *afu)
128 138
129 cxl_p1n_write(afu, CXL_PSL_SCNTL_An, 139 cxl_p1n_write(afu, CXL_PSL_SCNTL_An,
130 PSL_CNTL & ~CXL_PSL_SCNTL_An_Pc); 140 PSL_CNTL & ~CXL_PSL_SCNTL_An_Pc);
131 return 0; 141out:
142 trace_cxl_psl_ctrl_done(afu, CXL_PSL_SCNTL_An_Pc, rc);
143 return rc;
132} 144}
133 145
134static int spa_max_procs(int spa_size) 146static int spa_max_procs(int spa_size)
@@ -185,6 +197,7 @@ static int alloc_spa(struct cxl_afu *afu)
185 197
186static void release_spa(struct cxl_afu *afu) 198static void release_spa(struct cxl_afu *afu)
187{ 199{
200 cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0);
188 free_pages((unsigned long) afu->spa, afu->spa_order); 201 free_pages((unsigned long) afu->spa, afu->spa_order);
189} 202}
190 203
@@ -278,6 +291,9 @@ static int do_process_element_cmd(struct cxl_context *ctx,
278{ 291{
279 u64 state; 292 u64 state;
280 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); 293 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT);
294 int rc = 0;
295
296 trace_cxl_llcmd(ctx, cmd);
281 297
282 WARN_ON(!ctx->afu->enabled); 298 WARN_ON(!ctx->afu->enabled);
283 299
@@ -289,12 +305,14 @@ static int do_process_element_cmd(struct cxl_context *ctx,
289 while (1) { 305 while (1) {
290 if (time_after_eq(jiffies, timeout)) { 306 if (time_after_eq(jiffies, timeout)) {
291 dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n"); 307 dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n");
292 return -EBUSY; 308 rc = -EBUSY;
309 goto out;
293 } 310 }
294 state = be64_to_cpup(ctx->afu->sw_command_status); 311 state = be64_to_cpup(ctx->afu->sw_command_status);
295 if (state == ~0ULL) { 312 if (state == ~0ULL) {
296 pr_err("cxl: Error adding process element to AFU\n"); 313 pr_err("cxl: Error adding process element to AFU\n");
297 return -1; 314 rc = -1;
315 goto out;
298 } 316 }
299 if ((state & (CXL_SPA_SW_CMD_MASK | CXL_SPA_SW_STATE_MASK | CXL_SPA_SW_LINK_MASK)) == 317 if ((state & (CXL_SPA_SW_CMD_MASK | CXL_SPA_SW_STATE_MASK | CXL_SPA_SW_LINK_MASK)) ==
300 (cmd | (cmd >> 16) | ctx->pe)) 318 (cmd | (cmd >> 16) | ctx->pe))
@@ -309,7 +327,9 @@ static int do_process_element_cmd(struct cxl_context *ctx,
309 schedule(); 327 schedule();
310 328
311 } 329 }
312 return 0; 330out:
331 trace_cxl_llcmd_done(ctx, cmd, rc);
332 return rc;
313} 333}
314 334
315static int add_process_element(struct cxl_context *ctx) 335static int add_process_element(struct cxl_context *ctx)
@@ -629,6 +649,8 @@ static inline int detach_process_native_afu_directed(struct cxl_context *ctx)
629 649
630int cxl_detach_process(struct cxl_context *ctx) 650int cxl_detach_process(struct cxl_context *ctx)
631{ 651{
652 trace_cxl_detach(ctx);
653
632 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) 654 if (ctx->afu->current_mode == CXL_MODE_DEDICATED)
633 return detach_process_native_dedicated(ctx); 655 return detach_process_native_dedicated(ctx);
634 656
@@ -667,6 +689,7 @@ static void recover_psl_err(struct cxl_afu *afu, u64 errstat)
667 689
668int cxl_ack_irq(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask) 690int cxl_ack_irq(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask)
669{ 691{
692 trace_cxl_psl_irq_ack(ctx, tfc);
670 if (tfc) 693 if (tfc)
671 cxl_p2n_write(ctx->afu, CXL_PSL_TFC_An, tfc); 694 cxl_p2n_write(ctx->afu, CXL_PSL_TFC_An, tfc);
672 if (psl_reset_mask) 695 if (psl_reset_mask)
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 0f2cc9f8b4db..1ef01647265f 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -21,6 +21,7 @@
21#include <asm/msi_bitmap.h> 21#include <asm/msi_bitmap.h>
22#include <asm/pci-bridge.h> /* for struct pci_controller */ 22#include <asm/pci-bridge.h> /* for struct pci_controller */
23#include <asm/pnv-pci.h> 23#include <asm/pnv-pci.h>
24#include <asm/io.h>
24 25
25#include "cxl.h" 26#include "cxl.h"
26 27
@@ -113,6 +114,24 @@
113#define AFUD_EB_LEN(val) EXTRACT_PPC_BITS(val, 8, 63) 114#define AFUD_EB_LEN(val) EXTRACT_PPC_BITS(val, 8, 63)
114#define AFUD_READ_EB_OFF(afu) AFUD_READ(afu, 0x48) 115#define AFUD_READ_EB_OFF(afu) AFUD_READ(afu, 0x48)
115 116
117u16 cxl_afu_cr_read16(struct cxl_afu *afu, int cr, u64 off)
118{
119 u64 aligned_off = off & ~0x3L;
120 u32 val;
121
122 val = cxl_afu_cr_read32(afu, cr, aligned_off);
123 return (val >> ((off & 0x2) * 8)) & 0xffff;
124}
125
126u8 cxl_afu_cr_read8(struct cxl_afu *afu, int cr, u64 off)
127{
128 u64 aligned_off = off & ~0x3L;
129 u32 val;
130
131 val = cxl_afu_cr_read32(afu, cr, aligned_off);
132 return (val >> ((off & 0x3) * 8)) & 0xff;
133}
134
116static DEFINE_PCI_DEVICE_TABLE(cxl_pci_tbl) = { 135static DEFINE_PCI_DEVICE_TABLE(cxl_pci_tbl) = {
117 { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x0477), }, 136 { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x0477), },
118 { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x044b), }, 137 { PCI_DEVICE(PCI_VENDOR_ID_IBM, 0x044b), },
@@ -316,7 +335,7 @@ static int init_implementation_adapter_regs(struct cxl *adapter, struct pci_dev
316 u64 psl_dsnctl; 335 u64 psl_dsnctl;
317 u64 chipid; 336 u64 chipid;
318 337
319 if (!(np = pnv_pci_to_phb_node(dev))) 338 if (!(np = pnv_pci_get_phb_node(dev)))
320 return -ENODEV; 339 return -ENODEV;
321 340
322 while (np && !(prop = of_get_property(np, "ibm,chip-id", NULL))) 341 while (np && !(prop = of_get_property(np, "ibm,chip-id", NULL)))
@@ -348,7 +367,7 @@ static int init_implementation_afu_regs(struct cxl_afu *afu)
348 cxl_p1n_write(afu, CXL_PSL_COALLOC_A, 0xFF000000FEFEFEFEULL); 367 cxl_p1n_write(afu, CXL_PSL_COALLOC_A, 0xFF000000FEFEFEFEULL);
349 /* for debugging with trace arrays */ 368 /* for debugging with trace arrays */
350 cxl_p1n_write(afu, CXL_PSL_SLICE_TRACE, 0x0000FFFF00000000ULL); 369 cxl_p1n_write(afu, CXL_PSL_SLICE_TRACE, 0x0000FFFF00000000ULL);
351 cxl_p1n_write(afu, CXL_PSL_RXCTL_A, 0xF000000000000000ULL); 370 cxl_p1n_write(afu, CXL_PSL_RXCTL_A, CXL_PSL_RXCTL_AFUHP_4S);
352 371
353 return 0; 372 return 0;
354} 373}
@@ -361,6 +380,41 @@ int cxl_setup_irq(struct cxl *adapter, unsigned int hwirq,
361 return pnv_cxl_ioda_msi_setup(dev, hwirq, virq); 380 return pnv_cxl_ioda_msi_setup(dev, hwirq, virq);
362} 381}
363 382
383int cxl_update_image_control(struct cxl *adapter)
384{
385 struct pci_dev *dev = to_pci_dev(adapter->dev.parent);
386 int rc;
387 int vsec;
388 u8 image_state;
389
390 if (!(vsec = find_cxl_vsec(dev))) {
391 dev_err(&dev->dev, "ABORTING: CXL VSEC not found!\n");
392 return -ENODEV;
393 }
394
395 if ((rc = CXL_READ_VSEC_IMAGE_STATE(dev, vsec, &image_state))) {
396 dev_err(&dev->dev, "failed to read image state: %i\n", rc);
397 return rc;
398 }
399
400 if (adapter->perst_loads_image)
401 image_state |= CXL_VSEC_PERST_LOADS_IMAGE;
402 else
403 image_state &= ~CXL_VSEC_PERST_LOADS_IMAGE;
404
405 if (adapter->perst_select_user)
406 image_state |= CXL_VSEC_PERST_SELECT_USER;
407 else
408 image_state &= ~CXL_VSEC_PERST_SELECT_USER;
409
410 if ((rc = CXL_WRITE_VSEC_IMAGE_STATE(dev, vsec, image_state))) {
411 dev_err(&dev->dev, "failed to update image control: %i\n", rc);
412 return rc;
413 }
414
415 return 0;
416}
417
364int cxl_alloc_one_irq(struct cxl *adapter) 418int cxl_alloc_one_irq(struct cxl *adapter)
365{ 419{
366 struct pci_dev *dev = to_pci_dev(adapter->dev.parent); 420 struct pci_dev *dev = to_pci_dev(adapter->dev.parent);
@@ -520,6 +574,7 @@ static int cxl_read_afu_descriptor(struct cxl_afu *afu)
520 val = AFUD_READ_INFO(afu); 574 val = AFUD_READ_INFO(afu);
521 afu->pp_irqs = AFUD_NUM_INTS_PER_PROC(val); 575 afu->pp_irqs = AFUD_NUM_INTS_PER_PROC(val);
522 afu->max_procs_virtualised = AFUD_NUM_PROCS(val); 576 afu->max_procs_virtualised = AFUD_NUM_PROCS(val);
577 afu->crs_num = AFUD_NUM_CRS(val);
523 578
524 if (AFUD_AFU_DIRECTED(val)) 579 if (AFUD_AFU_DIRECTED(val))
525 afu->modes_supported |= CXL_MODE_DIRECTED; 580 afu->modes_supported |= CXL_MODE_DIRECTED;
@@ -534,11 +589,17 @@ static int cxl_read_afu_descriptor(struct cxl_afu *afu)
534 if ((afu->pp_psa = AFUD_PPPSA_PP(val))) 589 if ((afu->pp_psa = AFUD_PPPSA_PP(val)))
535 afu->pp_offset = AFUD_READ_PPPSA_OFF(afu); 590 afu->pp_offset = AFUD_READ_PPPSA_OFF(afu);
536 591
592 val = AFUD_READ_CR(afu);
593 afu->crs_len = AFUD_CR_LEN(val) * 256;
594 afu->crs_offset = AFUD_READ_CR_OFF(afu);
595
537 return 0; 596 return 0;
538} 597}
539 598
540static int cxl_afu_descriptor_looks_ok(struct cxl_afu *afu) 599static int cxl_afu_descriptor_looks_ok(struct cxl_afu *afu)
541{ 600{
601 int i;
602
542 if (afu->psa && afu->adapter->ps_size < 603 if (afu->psa && afu->adapter->ps_size <
543 (afu->pp_offset + afu->pp_size*afu->max_procs_virtualised)) { 604 (afu->pp_offset + afu->pp_size*afu->max_procs_virtualised)) {
544 dev_err(&afu->dev, "per-process PSA can't fit inside the PSA!\n"); 605 dev_err(&afu->dev, "per-process PSA can't fit inside the PSA!\n");
@@ -548,6 +609,13 @@ static int cxl_afu_descriptor_looks_ok(struct cxl_afu *afu)
548 if (afu->pp_psa && (afu->pp_size < PAGE_SIZE)) 609 if (afu->pp_psa && (afu->pp_size < PAGE_SIZE))
549 dev_warn(&afu->dev, "AFU uses < PAGE_SIZE per-process PSA!"); 610 dev_warn(&afu->dev, "AFU uses < PAGE_SIZE per-process PSA!");
550 611
612 for (i = 0; i < afu->crs_num; i++) {
613 if ((cxl_afu_cr_read32(afu, i, 0) == 0)) {
614 dev_err(&afu->dev, "ABORTING: AFU configuration record %i is invalid\n", i);
615 return -EINVAL;
616 }
617 }
618
551 return 0; 619 return 0;
552} 620}
553 621
@@ -706,6 +774,42 @@ static void cxl_remove_afu(struct cxl_afu *afu)
706 device_unregister(&afu->dev); 774 device_unregister(&afu->dev);
707} 775}
708 776
777int cxl_reset(struct cxl *adapter)
778{
779 struct pci_dev *dev = to_pci_dev(adapter->dev.parent);
780 int rc;
781 int i;
782 u32 val;
783
784 dev_info(&dev->dev, "CXL reset\n");
785
786 for (i = 0; i < adapter->slices; i++)
787 cxl_remove_afu(adapter->afu[i]);
788
789 /* pcie_warm_reset requests a fundamental pci reset which includes a
790 * PERST assert/deassert. PERST triggers a loading of the image
791 * if "user" or "factory" is selected in sysfs */
792 if ((rc = pci_set_pcie_reset_state(dev, pcie_warm_reset))) {
793 dev_err(&dev->dev, "cxl: pcie_warm_reset failed\n");
794 return rc;
795 }
796
797 /* the PERST done above fences the PHB. So, reset depends on EEH
798 * to unbind the driver, tell Sapphire to reinit the PHB, and rebind
799 * the driver. Do an mmio read explictly to ensure EEH notices the
800 * fenced PHB. Retry for a few seconds before giving up. */
801 i = 0;
802 while (((val = mmio_read32be(adapter->p1_mmio)) != 0xffffffff) &&
803 (i < 5)) {
804 msleep(500);
805 i++;
806 }
807
808 if (val != 0xffffffff)
809 dev_err(&dev->dev, "cxl: PERST failed to trigger EEH\n");
810
811 return rc;
812}
709 813
710static int cxl_map_adapter_regs(struct cxl *adapter, struct pci_dev *dev) 814static int cxl_map_adapter_regs(struct cxl *adapter, struct pci_dev *dev)
711{ 815{
@@ -770,8 +874,8 @@ static int cxl_read_vsec(struct cxl *adapter, struct pci_dev *dev)
770 CXL_READ_VSEC_BASE_IMAGE(dev, vsec, &adapter->base_image); 874 CXL_READ_VSEC_BASE_IMAGE(dev, vsec, &adapter->base_image);
771 CXL_READ_VSEC_IMAGE_STATE(dev, vsec, &image_state); 875 CXL_READ_VSEC_IMAGE_STATE(dev, vsec, &image_state);
772 adapter->user_image_loaded = !!(image_state & CXL_VSEC_USER_IMAGE_LOADED); 876 adapter->user_image_loaded = !!(image_state & CXL_VSEC_USER_IMAGE_LOADED);
773 adapter->perst_loads_image = !!(image_state & CXL_VSEC_PERST_LOADS_IMAGE); 877 adapter->perst_loads_image = true;
774 adapter->perst_select_user = !!(image_state & CXL_VSEC_PERST_SELECT_USER); 878 adapter->perst_select_user = !!(image_state & CXL_VSEC_USER_IMAGE_LOADED);
775 879
776 CXL_READ_VSEC_NAFUS(dev, vsec, &adapter->slices); 880 CXL_READ_VSEC_NAFUS(dev, vsec, &adapter->slices);
777 CXL_READ_VSEC_AFU_DESC_OFF(dev, vsec, &afu_desc_off); 881 CXL_READ_VSEC_AFU_DESC_OFF(dev, vsec, &afu_desc_off);
@@ -879,6 +983,9 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)
879 if ((rc = cxl_vsec_looks_ok(adapter, dev))) 983 if ((rc = cxl_vsec_looks_ok(adapter, dev)))
880 goto err2; 984 goto err2;
881 985
986 if ((rc = cxl_update_image_control(adapter)))
987 goto err2;
988
882 if ((rc = cxl_map_adapter_regs(adapter, dev))) 989 if ((rc = cxl_map_adapter_regs(adapter, dev)))
883 goto err2; 990 goto err2;
884 991
@@ -888,9 +995,15 @@ static struct cxl *cxl_init_adapter(struct pci_dev *dev)
888 if ((rc = init_implementation_adapter_regs(adapter, dev))) 995 if ((rc = init_implementation_adapter_regs(adapter, dev)))
889 goto err3; 996 goto err3;
890 997
891 if ((rc = pnv_phb_to_cxl(dev))) 998 if ((rc = pnv_phb_to_cxl_mode(dev, OPAL_PHB_CAPI_MODE_CAPI)))
892 goto err3; 999 goto err3;
893 1000
1001 /* If recovery happened, the last step is to turn on snooping.
1002 * In the non-recovery case this has no effect */
1003 if ((rc = pnv_phb_to_cxl_mode(dev, OPAL_PHB_CAPI_MODE_SNOOP_ON))) {
1004 goto err3;
1005 }
1006
894 if ((rc = cxl_register_psl_err_irq(adapter))) 1007 if ((rc = cxl_register_psl_err_irq(adapter)))
895 goto err3; 1008 goto err3;
896 1009
diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
index 461bdbd5d483..d0c38c7bc0c4 100644
--- a/drivers/misc/cxl/sysfs.c
+++ b/drivers/misc/cxl/sysfs.c
@@ -10,6 +10,7 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/sysfs.h> 12#include <linux/sysfs.h>
13#include <linux/pci_regs.h>
13 14
14#include "cxl.h" 15#include "cxl.h"
15 16
@@ -56,11 +57,68 @@ static ssize_t image_loaded_show(struct device *device,
56 return scnprintf(buf, PAGE_SIZE, "factory\n"); 57 return scnprintf(buf, PAGE_SIZE, "factory\n");
57} 58}
58 59
60static ssize_t reset_adapter_store(struct device *device,
61 struct device_attribute *attr,
62 const char *buf, size_t count)
63{
64 struct cxl *adapter = to_cxl_adapter(device);
65 int rc;
66 int val;
67
68 rc = sscanf(buf, "%i", &val);
69 if ((rc != 1) || (val != 1))
70 return -EINVAL;
71
72 if ((rc = cxl_reset(adapter)))
73 return rc;
74 return count;
75}
76
77static ssize_t load_image_on_perst_show(struct device *device,
78 struct device_attribute *attr,
79 char *buf)
80{
81 struct cxl *adapter = to_cxl_adapter(device);
82
83 if (!adapter->perst_loads_image)
84 return scnprintf(buf, PAGE_SIZE, "none\n");
85
86 if (adapter->perst_select_user)
87 return scnprintf(buf, PAGE_SIZE, "user\n");
88 return scnprintf(buf, PAGE_SIZE, "factory\n");
89}
90
91static ssize_t load_image_on_perst_store(struct device *device,
92 struct device_attribute *attr,
93 const char *buf, size_t count)
94{
95 struct cxl *adapter = to_cxl_adapter(device);
96 int rc;
97
98 if (!strncmp(buf, "none", 4))
99 adapter->perst_loads_image = false;
100 else if (!strncmp(buf, "user", 4)) {
101 adapter->perst_select_user = true;
102 adapter->perst_loads_image = true;
103 } else if (!strncmp(buf, "factory", 7)) {
104 adapter->perst_select_user = false;
105 adapter->perst_loads_image = true;
106 } else
107 return -EINVAL;
108
109 if ((rc = cxl_update_image_control(adapter)))
110 return rc;
111
112 return count;
113}
114
59static struct device_attribute adapter_attrs[] = { 115static struct device_attribute adapter_attrs[] = {
60 __ATTR_RO(caia_version), 116 __ATTR_RO(caia_version),
61 __ATTR_RO(psl_revision), 117 __ATTR_RO(psl_revision),
62 __ATTR_RO(base_image), 118 __ATTR_RO(base_image),
63 __ATTR_RO(image_loaded), 119 __ATTR_RO(image_loaded),
120 __ATTR_RW(load_image_on_perst),
121 __ATTR(reset, S_IWUSR, NULL, reset_adapter_store),
64}; 122};
65 123
66 124
@@ -310,8 +368,6 @@ static struct device_attribute afu_attrs[] = {
310 __ATTR(reset, S_IWUSR, NULL, reset_store_afu), 368 __ATTR(reset, S_IWUSR, NULL, reset_store_afu),
311}; 369};
312 370
313
314
315int cxl_sysfs_adapter_add(struct cxl *adapter) 371int cxl_sysfs_adapter_add(struct cxl *adapter)
316{ 372{
317 int i, rc; 373 int i, rc;
@@ -334,31 +390,191 @@ void cxl_sysfs_adapter_remove(struct cxl *adapter)
334 device_remove_file(&adapter->dev, &adapter_attrs[i]); 390 device_remove_file(&adapter->dev, &adapter_attrs[i]);
335} 391}
336 392
393struct afu_config_record {
394 struct kobject kobj;
395 struct bin_attribute config_attr;
396 struct list_head list;
397 int cr;
398 u16 device;
399 u16 vendor;
400 u32 class;
401};
402
403#define to_cr(obj) container_of(obj, struct afu_config_record, kobj)
404
405static ssize_t vendor_show(struct kobject *kobj,
406 struct kobj_attribute *attr, char *buf)
407{
408 struct afu_config_record *cr = to_cr(kobj);
409
410 return scnprintf(buf, PAGE_SIZE, "0x%.4x\n", cr->vendor);
411}
412
413static ssize_t device_show(struct kobject *kobj,
414 struct kobj_attribute *attr, char *buf)
415{
416 struct afu_config_record *cr = to_cr(kobj);
417
418 return scnprintf(buf, PAGE_SIZE, "0x%.4x\n", cr->device);
419}
420
421static ssize_t class_show(struct kobject *kobj,
422 struct kobj_attribute *attr, char *buf)
423{
424 struct afu_config_record *cr = to_cr(kobj);
425
426 return scnprintf(buf, PAGE_SIZE, "0x%.6x\n", cr->class);
427}
428
429static ssize_t afu_read_config(struct file *filp, struct kobject *kobj,
430 struct bin_attribute *bin_attr, char *buf,
431 loff_t off, size_t count)
432{
433 struct afu_config_record *cr = to_cr(kobj);
434 struct cxl_afu *afu = to_cxl_afu(container_of(kobj->parent, struct device, kobj));
435
436 u64 i, j, val, size = afu->crs_len;
437
438 if (off > size)
439 return 0;
440 if (off + count > size)
441 count = size - off;
442
443 for (i = 0; i < count;) {
444 val = cxl_afu_cr_read64(afu, cr->cr, off & ~0x7);
445 for (j = off & 0x7; j < 8 && i < count; i++, j++, off++)
446 buf[i] = (val >> (j * 8)) & 0xff;
447 }
448
449 return count;
450}
451
452static struct kobj_attribute vendor_attribute =
453 __ATTR_RO(vendor);
454static struct kobj_attribute device_attribute =
455 __ATTR_RO(device);
456static struct kobj_attribute class_attribute =
457 __ATTR_RO(class);
458
459static struct attribute *afu_cr_attrs[] = {
460 &vendor_attribute.attr,
461 &device_attribute.attr,
462 &class_attribute.attr,
463 NULL,
464};
465
466static void release_afu_config_record(struct kobject *kobj)
467{
468 struct afu_config_record *cr = to_cr(kobj);
469
470 kfree(cr);
471}
472
473static struct kobj_type afu_config_record_type = {
474 .sysfs_ops = &kobj_sysfs_ops,
475 .release = release_afu_config_record,
476 .default_attrs = afu_cr_attrs,
477};
478
479static struct afu_config_record *cxl_sysfs_afu_new_cr(struct cxl_afu *afu, int cr_idx)
480{
481 struct afu_config_record *cr;
482 int rc;
483
484 cr = kzalloc(sizeof(struct afu_config_record), GFP_KERNEL);
485 if (!cr)
486 return ERR_PTR(-ENOMEM);
487
488 cr->cr = cr_idx;
489 cr->device = cxl_afu_cr_read16(afu, cr_idx, PCI_DEVICE_ID);
490 cr->vendor = cxl_afu_cr_read16(afu, cr_idx, PCI_VENDOR_ID);
491 cr->class = cxl_afu_cr_read32(afu, cr_idx, PCI_CLASS_REVISION) >> 8;
492
493 /*
494 * Export raw AFU PCIe like config record. For now this is read only by
495 * root - we can expand that later to be readable by non-root and maybe
496 * even writable provided we have a good use-case. Once we suport
497 * exposing AFUs through a virtual PHB they will get that for free from
498 * Linux' PCI infrastructure, but until then it's not clear that we
499 * need it for anything since the main use case is just identifying
500 * AFUs, which can be done via the vendor, device and class attributes.
501 */
502 sysfs_bin_attr_init(&cr->config_attr);
503 cr->config_attr.attr.name = "config";
504 cr->config_attr.attr.mode = S_IRUSR;
505 cr->config_attr.size = afu->crs_len;
506 cr->config_attr.read = afu_read_config;
507
508 rc = kobject_init_and_add(&cr->kobj, &afu_config_record_type,
509 &afu->dev.kobj, "cr%i", cr->cr);
510 if (rc)
511 goto err;
512
513 rc = sysfs_create_bin_file(&cr->kobj, &cr->config_attr);
514 if (rc)
515 goto err1;
516
517 rc = kobject_uevent(&cr->kobj, KOBJ_ADD);
518 if (rc)
519 goto err2;
520
521 return cr;
522err2:
523 sysfs_remove_bin_file(&cr->kobj, &cr->config_attr);
524err1:
525 kobject_put(&cr->kobj);
526 return ERR_PTR(rc);
527err:
528 kfree(cr);
529 return ERR_PTR(rc);
530}
531
532void cxl_sysfs_afu_remove(struct cxl_afu *afu)
533{
534 struct afu_config_record *cr, *tmp;
535 int i;
536
537 for (i = 0; i < ARRAY_SIZE(afu_attrs); i++)
538 device_remove_file(&afu->dev, &afu_attrs[i]);
539
540 list_for_each_entry_safe(cr, tmp, &afu->crs, list) {
541 sysfs_remove_bin_file(&cr->kobj, &cr->config_attr);
542 kobject_put(&cr->kobj);
543 }
544}
545
337int cxl_sysfs_afu_add(struct cxl_afu *afu) 546int cxl_sysfs_afu_add(struct cxl_afu *afu)
338{ 547{
548 struct afu_config_record *cr;
339 int i, rc; 549 int i, rc;
340 550
551 INIT_LIST_HEAD(&afu->crs);
552
341 for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) { 553 for (i = 0; i < ARRAY_SIZE(afu_attrs); i++) {
342 if ((rc = device_create_file(&afu->dev, &afu_attrs[i]))) 554 if ((rc = device_create_file(&afu->dev, &afu_attrs[i])))
343 goto err; 555 goto err;
344 } 556 }
345 557
558 for (i = 0; i < afu->crs_num; i++) {
559 cr = cxl_sysfs_afu_new_cr(afu, i);
560 if (IS_ERR(cr)) {
561 rc = PTR_ERR(cr);
562 goto err1;
563 }
564 list_add(&cr->list, &afu->crs);
565 }
566
346 return 0; 567 return 0;
347 568
569err1:
570 cxl_sysfs_afu_remove(afu);
571 return rc;
348err: 572err:
349 for (i--; i >= 0; i--) 573 for (i--; i >= 0; i--)
350 device_remove_file(&afu->dev, &afu_attrs[i]); 574 device_remove_file(&afu->dev, &afu_attrs[i]);
351 return rc; 575 return rc;
352} 576}
353 577
354void cxl_sysfs_afu_remove(struct cxl_afu *afu)
355{
356 int i;
357
358 for (i = 0; i < ARRAY_SIZE(afu_attrs); i++)
359 device_remove_file(&afu->dev, &afu_attrs[i]);
360}
361
362int cxl_sysfs_afu_m_add(struct cxl_afu *afu) 578int cxl_sysfs_afu_m_add(struct cxl_afu *afu)
363{ 579{
364 int i, rc; 580 int i, rc;
diff --git a/drivers/misc/cxl/trace.c b/drivers/misc/cxl/trace.c
new file mode 100644
index 000000000000..c2b06d319e6e
--- /dev/null
+++ b/drivers/misc/cxl/trace.c
@@ -0,0 +1,13 @@
1/*
2 * Copyright 2015 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#ifndef __CHECKER__
11#define CREATE_TRACE_POINTS
12#include "trace.h"
13#endif
diff --git a/drivers/misc/cxl/trace.h b/drivers/misc/cxl/trace.h
new file mode 100644
index 000000000000..ae434d87887e
--- /dev/null
+++ b/drivers/misc/cxl/trace.h
@@ -0,0 +1,459 @@
1/*
2 * Copyright 2015 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#undef TRACE_SYSTEM
11#define TRACE_SYSTEM cxl
12
13#if !defined(_CXL_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
14#define _CXL_TRACE_H
15
16#include <linux/tracepoint.h>
17
18#include "cxl.h"
19
20#define DSISR_FLAGS \
21 { CXL_PSL_DSISR_An_DS, "DS" }, \
22 { CXL_PSL_DSISR_An_DM, "DM" }, \
23 { CXL_PSL_DSISR_An_ST, "ST" }, \
24 { CXL_PSL_DSISR_An_UR, "UR" }, \
25 { CXL_PSL_DSISR_An_PE, "PE" }, \
26 { CXL_PSL_DSISR_An_AE, "AE" }, \
27 { CXL_PSL_DSISR_An_OC, "OC" }, \
28 { CXL_PSL_DSISR_An_M, "M" }, \
29 { CXL_PSL_DSISR_An_P, "P" }, \
30 { CXL_PSL_DSISR_An_A, "A" }, \
31 { CXL_PSL_DSISR_An_S, "S" }, \
32 { CXL_PSL_DSISR_An_K, "K" }
33
34#define TFC_FLAGS \
35 { CXL_PSL_TFC_An_A, "A" }, \
36 { CXL_PSL_TFC_An_C, "C" }, \
37 { CXL_PSL_TFC_An_AE, "AE" }, \
38 { CXL_PSL_TFC_An_R, "R" }
39
40#define LLCMD_NAMES \
41 { CXL_SPA_SW_CMD_TERMINATE, "TERMINATE" }, \
42 { CXL_SPA_SW_CMD_REMOVE, "REMOVE" }, \
43 { CXL_SPA_SW_CMD_SUSPEND, "SUSPEND" }, \
44 { CXL_SPA_SW_CMD_RESUME, "RESUME" }, \
45 { CXL_SPA_SW_CMD_ADD, "ADD" }, \
46 { CXL_SPA_SW_CMD_UPDATE, "UPDATE" }
47
48#define AFU_COMMANDS \
49 { 0, "DISABLE" }, \
50 { CXL_AFU_Cntl_An_E, "ENABLE" }, \
51 { CXL_AFU_Cntl_An_RA, "RESET" }
52
53#define PSL_COMMANDS \
54 { CXL_PSL_SCNTL_An_Pc, "PURGE" }, \
55 { CXL_PSL_SCNTL_An_Sc, "SUSPEND" }
56
57
58DECLARE_EVENT_CLASS(cxl_pe_class,
59 TP_PROTO(struct cxl_context *ctx),
60
61 TP_ARGS(ctx),
62
63 TP_STRUCT__entry(
64 __field(u8, card)
65 __field(u8, afu)
66 __field(u16, pe)
67 ),
68
69 TP_fast_assign(
70 __entry->card = ctx->afu->adapter->adapter_num;
71 __entry->afu = ctx->afu->slice;
72 __entry->pe = ctx->pe;
73 ),
74
75 TP_printk("afu%i.%i pe=%i",
76 __entry->card,
77 __entry->afu,
78 __entry->pe
79 )
80);
81
82
83TRACE_EVENT(cxl_attach,
84 TP_PROTO(struct cxl_context *ctx, u64 wed, s16 num_interrupts, u64 amr),
85
86 TP_ARGS(ctx, wed, num_interrupts, amr),
87
88 TP_STRUCT__entry(
89 __field(u8, card)
90 __field(u8, afu)
91 __field(u16, pe)
92 __field(pid_t, pid)
93 __field(u64, wed)
94 __field(u64, amr)
95 __field(s16, num_interrupts)
96 ),
97
98 TP_fast_assign(
99 __entry->card = ctx->afu->adapter->adapter_num;
100 __entry->afu = ctx->afu->slice;
101 __entry->pe = ctx->pe;
102 __entry->pid = pid_nr(ctx->pid);
103 __entry->wed = wed;
104 __entry->amr = amr;
105 __entry->num_interrupts = num_interrupts;
106 ),
107
108 TP_printk("afu%i.%i pid=%i pe=%i wed=0x%.16llx irqs=%i amr=0x%llx",
109 __entry->card,
110 __entry->afu,
111 __entry->pid,
112 __entry->pe,
113 __entry->wed,
114 __entry->num_interrupts,
115 __entry->amr
116 )
117);
118
119DEFINE_EVENT(cxl_pe_class, cxl_detach,
120 TP_PROTO(struct cxl_context *ctx),
121 TP_ARGS(ctx)
122);
123
124TRACE_EVENT(cxl_afu_irq,
125 TP_PROTO(struct cxl_context *ctx, int afu_irq, int virq, irq_hw_number_t hwirq),
126
127 TP_ARGS(ctx, afu_irq, virq, hwirq),
128
129 TP_STRUCT__entry(
130 __field(u8, card)
131 __field(u8, afu)
132 __field(u16, pe)
133 __field(u16, afu_irq)
134 __field(int, virq)
135 __field(irq_hw_number_t, hwirq)
136 ),
137
138 TP_fast_assign(
139 __entry->card = ctx->afu->adapter->adapter_num;
140 __entry->afu = ctx->afu->slice;
141 __entry->pe = ctx->pe;
142 __entry->afu_irq = afu_irq;
143 __entry->virq = virq;
144 __entry->hwirq = hwirq;
145 ),
146
147 TP_printk("afu%i.%i pe=%i afu_irq=%i virq=%i hwirq=0x%lx",
148 __entry->card,
149 __entry->afu,
150 __entry->pe,
151 __entry->afu_irq,
152 __entry->virq,
153 __entry->hwirq
154 )
155);
156
157TRACE_EVENT(cxl_psl_irq,
158 TP_PROTO(struct cxl_context *ctx, int irq, u64 dsisr, u64 dar),
159
160 TP_ARGS(ctx, irq, dsisr, dar),
161
162 TP_STRUCT__entry(
163 __field(u8, card)
164 __field(u8, afu)
165 __field(u16, pe)
166 __field(int, irq)
167 __field(u64, dsisr)
168 __field(u64, dar)
169 ),
170
171 TP_fast_assign(
172 __entry->card = ctx->afu->adapter->adapter_num;
173 __entry->afu = ctx->afu->slice;
174 __entry->pe = ctx->pe;
175 __entry->irq = irq;
176 __entry->dsisr = dsisr;
177 __entry->dar = dar;
178 ),
179
180 TP_printk("afu%i.%i pe=%i irq=%i dsisr=%s dar=0x%.16llx",
181 __entry->card,
182 __entry->afu,
183 __entry->pe,
184 __entry->irq,
185 __print_flags(__entry->dsisr, "|", DSISR_FLAGS),
186 __entry->dar
187 )
188);
189
190TRACE_EVENT(cxl_psl_irq_ack,
191 TP_PROTO(struct cxl_context *ctx, u64 tfc),
192
193 TP_ARGS(ctx, tfc),
194
195 TP_STRUCT__entry(
196 __field(u8, card)
197 __field(u8, afu)
198 __field(u16, pe)
199 __field(u64, tfc)
200 ),
201
202 TP_fast_assign(
203 __entry->card = ctx->afu->adapter->adapter_num;
204 __entry->afu = ctx->afu->slice;
205 __entry->pe = ctx->pe;
206 __entry->tfc = tfc;
207 ),
208
209 TP_printk("afu%i.%i pe=%i tfc=%s",
210 __entry->card,
211 __entry->afu,
212 __entry->pe,
213 __print_flags(__entry->tfc, "|", TFC_FLAGS)
214 )
215);
216
217TRACE_EVENT(cxl_ste_miss,
218 TP_PROTO(struct cxl_context *ctx, u64 dar),
219
220 TP_ARGS(ctx, dar),
221
222 TP_STRUCT__entry(
223 __field(u8, card)
224 __field(u8, afu)
225 __field(u16, pe)
226 __field(u64, dar)
227 ),
228
229 TP_fast_assign(
230 __entry->card = ctx->afu->adapter->adapter_num;
231 __entry->afu = ctx->afu->slice;
232 __entry->pe = ctx->pe;
233 __entry->dar = dar;
234 ),
235
236 TP_printk("afu%i.%i pe=%i dar=0x%.16llx",
237 __entry->card,
238 __entry->afu,
239 __entry->pe,
240 __entry->dar
241 )
242);
243
244TRACE_EVENT(cxl_ste_write,
245 TP_PROTO(struct cxl_context *ctx, unsigned int idx, u64 e, u64 v),
246
247 TP_ARGS(ctx, idx, e, v),
248
249 TP_STRUCT__entry(
250 __field(u8, card)
251 __field(u8, afu)
252 __field(u16, pe)
253 __field(unsigned int, idx)
254 __field(u64, e)
255 __field(u64, v)
256 ),
257
258 TP_fast_assign(
259 __entry->card = ctx->afu->adapter->adapter_num;
260 __entry->afu = ctx->afu->slice;
261 __entry->pe = ctx->pe;
262 __entry->idx = idx;
263 __entry->e = e;
264 __entry->v = v;
265 ),
266
267 TP_printk("afu%i.%i pe=%i SSTE[%i] E=0x%.16llx V=0x%.16llx",
268 __entry->card,
269 __entry->afu,
270 __entry->pe,
271 __entry->idx,
272 __entry->e,
273 __entry->v
274 )
275);
276
277TRACE_EVENT(cxl_pte_miss,
278 TP_PROTO(struct cxl_context *ctx, u64 dsisr, u64 dar),
279
280 TP_ARGS(ctx, dsisr, dar),
281
282 TP_STRUCT__entry(
283 __field(u8, card)
284 __field(u8, afu)
285 __field(u16, pe)
286 __field(u64, dsisr)
287 __field(u64, dar)
288 ),
289
290 TP_fast_assign(
291 __entry->card = ctx->afu->adapter->adapter_num;
292 __entry->afu = ctx->afu->slice;
293 __entry->pe = ctx->pe;
294 __entry->dsisr = dsisr;
295 __entry->dar = dar;
296 ),
297
298 TP_printk("afu%i.%i pe=%i dsisr=%s dar=0x%.16llx",
299 __entry->card,
300 __entry->afu,
301 __entry->pe,
302 __print_flags(__entry->dsisr, "|", DSISR_FLAGS),
303 __entry->dar
304 )
305);
306
307TRACE_EVENT(cxl_llcmd,
308 TP_PROTO(struct cxl_context *ctx, u64 cmd),
309
310 TP_ARGS(ctx, cmd),
311
312 TP_STRUCT__entry(
313 __field(u8, card)
314 __field(u8, afu)
315 __field(u16, pe)
316 __field(u64, cmd)
317 ),
318
319 TP_fast_assign(
320 __entry->card = ctx->afu->adapter->adapter_num;
321 __entry->afu = ctx->afu->slice;
322 __entry->pe = ctx->pe;
323 __entry->cmd = cmd;
324 ),
325
326 TP_printk("afu%i.%i pe=%i cmd=%s",
327 __entry->card,
328 __entry->afu,
329 __entry->pe,
330 __print_symbolic_u64(__entry->cmd, LLCMD_NAMES)
331 )
332);
333
334TRACE_EVENT(cxl_llcmd_done,
335 TP_PROTO(struct cxl_context *ctx, u64 cmd, int rc),
336
337 TP_ARGS(ctx, cmd, rc),
338
339 TP_STRUCT__entry(
340 __field(u8, card)
341 __field(u8, afu)
342 __field(u16, pe)
343 __field(u64, cmd)
344 __field(int, rc)
345 ),
346
347 TP_fast_assign(
348 __entry->card = ctx->afu->adapter->adapter_num;
349 __entry->afu = ctx->afu->slice;
350 __entry->pe = ctx->pe;
351 __entry->rc = rc;
352 __entry->cmd = cmd;
353 ),
354
355 TP_printk("afu%i.%i pe=%i cmd=%s rc=%i",
356 __entry->card,
357 __entry->afu,
358 __entry->pe,
359 __print_symbolic_u64(__entry->cmd, LLCMD_NAMES),
360 __entry->rc
361 )
362);
363
364DECLARE_EVENT_CLASS(cxl_afu_psl_ctrl,
365 TP_PROTO(struct cxl_afu *afu, u64 cmd),
366
367 TP_ARGS(afu, cmd),
368
369 TP_STRUCT__entry(
370 __field(u8, card)
371 __field(u8, afu)
372 __field(u64, cmd)
373 ),
374
375 TP_fast_assign(
376 __entry->card = afu->adapter->adapter_num;
377 __entry->afu = afu->slice;
378 __entry->cmd = cmd;
379 ),
380
381 TP_printk("afu%i.%i cmd=%s",
382 __entry->card,
383 __entry->afu,
384 __print_symbolic_u64(__entry->cmd, AFU_COMMANDS)
385 )
386);
387
388DECLARE_EVENT_CLASS(cxl_afu_psl_ctrl_done,
389 TP_PROTO(struct cxl_afu *afu, u64 cmd, int rc),
390
391 TP_ARGS(afu, cmd, rc),
392
393 TP_STRUCT__entry(
394 __field(u8, card)
395 __field(u8, afu)
396 __field(u64, cmd)
397 __field(int, rc)
398 ),
399
400 TP_fast_assign(
401 __entry->card = afu->adapter->adapter_num;
402 __entry->afu = afu->slice;
403 __entry->rc = rc;
404 __entry->cmd = cmd;
405 ),
406
407 TP_printk("afu%i.%i cmd=%s rc=%i",
408 __entry->card,
409 __entry->afu,
410 __print_symbolic_u64(__entry->cmd, AFU_COMMANDS),
411 __entry->rc
412 )
413);
414
415DEFINE_EVENT(cxl_afu_psl_ctrl, cxl_afu_ctrl,
416 TP_PROTO(struct cxl_afu *afu, u64 cmd),
417 TP_ARGS(afu, cmd)
418);
419
420DEFINE_EVENT(cxl_afu_psl_ctrl_done, cxl_afu_ctrl_done,
421 TP_PROTO(struct cxl_afu *afu, u64 cmd, int rc),
422 TP_ARGS(afu, cmd, rc)
423);
424
425DEFINE_EVENT_PRINT(cxl_afu_psl_ctrl, cxl_psl_ctrl,
426 TP_PROTO(struct cxl_afu *afu, u64 cmd),
427 TP_ARGS(afu, cmd),
428
429 TP_printk("psl%i.%i cmd=%s",
430 __entry->card,
431 __entry->afu,
432 __print_symbolic_u64(__entry->cmd, PSL_COMMANDS)
433 )
434);
435
436DEFINE_EVENT_PRINT(cxl_afu_psl_ctrl_done, cxl_psl_ctrl_done,
437 TP_PROTO(struct cxl_afu *afu, u64 cmd, int rc),
438 TP_ARGS(afu, cmd, rc),
439
440 TP_printk("psl%i.%i cmd=%s rc=%i",
441 __entry->card,
442 __entry->afu,
443 __print_symbolic_u64(__entry->cmd, PSL_COMMANDS),
444 __entry->rc
445 )
446);
447
448DEFINE_EVENT(cxl_pe_class, cxl_slbia,
449 TP_PROTO(struct cxl_context *ctx),
450 TP_ARGS(ctx)
451);
452
453#endif /* _CXL_TRACE_H */
454
455/* This part must be outside protection */
456#undef TRACE_INCLUDE_PATH
457#define TRACE_INCLUDE_PATH .
458#define TRACE_INCLUDE_FILE trace
459#include <trace/define_trace.h>
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 180a5442fd4b..38552a31304a 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -145,8 +145,11 @@ enclosure_register(struct device *dev, const char *name, int components,
145 if (err) 145 if (err)
146 goto err; 146 goto err;
147 147
148 for (i = 0; i < components; i++) 148 for (i = 0; i < components; i++) {
149 edev->component[i].number = -1; 149 edev->component[i].number = -1;
150 edev->component[i].slot = -1;
151 edev->component[i].power_status = 1;
152 }
150 153
151 mutex_lock(&container_list_lock); 154 mutex_lock(&container_list_lock);
152 list_add_tail(&edev->node, &container_list); 155 list_add_tail(&edev->node, &container_list);
@@ -273,27 +276,26 @@ enclosure_component_find_by_name(struct enclosure_device *edev,
273static const struct attribute_group *enclosure_component_groups[]; 276static const struct attribute_group *enclosure_component_groups[];
274 277
275/** 278/**
276 * enclosure_component_register - add a particular component to an enclosure 279 * enclosure_component_alloc - prepare a new enclosure component
277 * @edev: the enclosure to add the component 280 * @edev: the enclosure to add the component
278 * @num: the device number 281 * @num: the device number
279 * @type: the type of component being added 282 * @type: the type of component being added
280 * @name: an optional name to appear in sysfs (leave NULL if none) 283 * @name: an optional name to appear in sysfs (leave NULL if none)
281 * 284 *
282 * Registers the component. The name is optional for enclosures that 285 * The name is optional for enclosures that give their components a unique
283 * give their components a unique name. If not, leave the field NULL 286 * name. If not, leave the field NULL and a name will be assigned.
284 * and a name will be assigned.
285 * 287 *
286 * Returns a pointer to the enclosure component or an error. 288 * Returns a pointer to the enclosure component or an error.
287 */ 289 */
288struct enclosure_component * 290struct enclosure_component *
289enclosure_component_register(struct enclosure_device *edev, 291enclosure_component_alloc(struct enclosure_device *edev,
290 unsigned int number, 292 unsigned int number,
291 enum enclosure_component_type type, 293 enum enclosure_component_type type,
292 const char *name) 294 const char *name)
293{ 295{
294 struct enclosure_component *ecomp; 296 struct enclosure_component *ecomp;
295 struct device *cdev; 297 struct device *cdev;
296 int err, i; 298 int i;
297 char newname[COMPONENT_NAME_SIZE]; 299 char newname[COMPONENT_NAME_SIZE];
298 300
299 if (number >= edev->components) 301 if (number >= edev->components)
@@ -327,14 +329,30 @@ enclosure_component_register(struct enclosure_device *edev,
327 cdev->release = enclosure_component_release; 329 cdev->release = enclosure_component_release;
328 cdev->groups = enclosure_component_groups; 330 cdev->groups = enclosure_component_groups;
329 331
332 return ecomp;
333}
334EXPORT_SYMBOL_GPL(enclosure_component_alloc);
335
336/**
337 * enclosure_component_register - publishes an initialized enclosure component
338 * @ecomp: component to add
339 *
340 * Returns 0 on successful registration, releases the component otherwise
341 */
342int enclosure_component_register(struct enclosure_component *ecomp)
343{
344 struct device *cdev;
345 int err;
346
347 cdev = &ecomp->cdev;
330 err = device_register(cdev); 348 err = device_register(cdev);
331 if (err) { 349 if (err) {
332 ecomp->number = -1; 350 ecomp->number = -1;
333 put_device(cdev); 351 put_device(cdev);
334 return ERR_PTR(err); 352 return err;
335 } 353 }
336 354
337 return ecomp; 355 return 0;
338} 356}
339EXPORT_SYMBOL_GPL(enclosure_component_register); 357EXPORT_SYMBOL_GPL(enclosure_component_register);
340 358
@@ -417,8 +435,21 @@ static ssize_t components_show(struct device *cdev,
417} 435}
418static DEVICE_ATTR_RO(components); 436static DEVICE_ATTR_RO(components);
419 437
438static ssize_t id_show(struct device *cdev,
439 struct device_attribute *attr,
440 char *buf)
441{
442 struct enclosure_device *edev = to_enclosure_device(cdev);
443
444 if (edev->cb->show_id)
445 return edev->cb->show_id(edev, buf);
446 return -EINVAL;
447}
448static DEVICE_ATTR_RO(id);
449
420static struct attribute *enclosure_class_attrs[] = { 450static struct attribute *enclosure_class_attrs[] = {
421 &dev_attr_components.attr, 451 &dev_attr_components.attr,
452 &dev_attr_id.attr,
422 NULL, 453 NULL,
423}; 454};
424ATTRIBUTE_GROUPS(enclosure_class); 455ATTRIBUTE_GROUPS(enclosure_class);
@@ -553,6 +584,40 @@ static ssize_t set_component_locate(struct device *cdev,
553 return count; 584 return count;
554} 585}
555 586
587static ssize_t get_component_power_status(struct device *cdev,
588 struct device_attribute *attr,
589 char *buf)
590{
591 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
592 struct enclosure_component *ecomp = to_enclosure_component(cdev);
593
594 if (edev->cb->get_power_status)
595 edev->cb->get_power_status(edev, ecomp);
596 return snprintf(buf, 40, "%s\n", ecomp->power_status ? "on" : "off");
597}
598
599static ssize_t set_component_power_status(struct device *cdev,
600 struct device_attribute *attr,
601 const char *buf, size_t count)
602{
603 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
604 struct enclosure_component *ecomp = to_enclosure_component(cdev);
605 int val;
606
607 if (strncmp(buf, "on", 2) == 0 &&
608 (buf[2] == '\n' || buf[2] == '\0'))
609 val = 1;
610 else if (strncmp(buf, "off", 3) == 0 &&
611 (buf[3] == '\n' || buf[3] == '\0'))
612 val = 0;
613 else
614 return -EINVAL;
615
616 if (edev->cb->set_power_status)
617 edev->cb->set_power_status(edev, ecomp, val);
618 return count;
619}
620
556static ssize_t get_component_type(struct device *cdev, 621static ssize_t get_component_type(struct device *cdev,
557 struct device_attribute *attr, char *buf) 622 struct device_attribute *attr, char *buf)
558{ 623{
@@ -561,6 +626,20 @@ static ssize_t get_component_type(struct device *cdev,
561 return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]); 626 return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
562} 627}
563 628
629static ssize_t get_component_slot(struct device *cdev,
630 struct device_attribute *attr, char *buf)
631{
632 struct enclosure_component *ecomp = to_enclosure_component(cdev);
633 int slot;
634
635 /* if the enclosure does not override then use 'number' as a stand-in */
636 if (ecomp->slot >= 0)
637 slot = ecomp->slot;
638 else
639 slot = ecomp->number;
640
641 return snprintf(buf, 40, "%d\n", slot);
642}
564 643
565static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault, 644static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
566 set_component_fault); 645 set_component_fault);
@@ -570,14 +649,19 @@ static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
570 set_component_active); 649 set_component_active);
571static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate, 650static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
572 set_component_locate); 651 set_component_locate);
652static DEVICE_ATTR(power_status, S_IRUGO | S_IWUSR, get_component_power_status,
653 set_component_power_status);
573static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL); 654static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL);
655static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL);
574 656
575static struct attribute *enclosure_component_attrs[] = { 657static struct attribute *enclosure_component_attrs[] = {
576 &dev_attr_fault.attr, 658 &dev_attr_fault.attr,
577 &dev_attr_status.attr, 659 &dev_attr_status.attr,
578 &dev_attr_active.attr, 660 &dev_attr_active.attr,
579 &dev_attr_locate.attr, 661 &dev_attr_locate.attr,
662 &dev_attr_power_status.attr,
580 &dev_attr_type.attr, 663 &dev_attr_type.attr,
664 &dev_attr_slot.attr,
581 NULL 665 NULL
582}; 666};
583ATTRIBUTE_GROUPS(enclosure_component); 667ATTRIBUTE_GROUPS(enclosure_component);
diff --git a/drivers/misc/genwqe/card_base.h b/drivers/misc/genwqe/card_base.h
index c64d7cad1085..e7353449874b 100644
--- a/drivers/misc/genwqe/card_base.h
+++ b/drivers/misc/genwqe/card_base.h
@@ -34,7 +34,6 @@
34#include <linux/semaphore.h> 34#include <linux/semaphore.h>
35#include <linux/uaccess.h> 35#include <linux/uaccess.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/version.h>
38#include <linux/debugfs.h> 37#include <linux/debugfs.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40 39
diff --git a/drivers/misc/genwqe/card_sysfs.c b/drivers/misc/genwqe/card_sysfs.c
index 2c33fbca9225..6ab31eff0536 100644
--- a/drivers/misc/genwqe/card_sysfs.c
+++ b/drivers/misc/genwqe/card_sysfs.c
@@ -24,7 +24,6 @@
24 * debugging, please also see the debugfs interfaces of this driver. 24 * debugging, please also see the debugfs interfaces of this driver.
25 */ 25 */
26 26
27#include <linux/version.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/types.h> 28#include <linux/types.h>
30#include <linux/module.h> 29#include <linux/module.h>
diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 3336ddca45ac..8758d033db23 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -144,9 +144,9 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
144{ 144{
145 union ioc4_int_out int_out; 145 union ioc4_int_out int_out;
146 union ioc4_gpcr gpcr; 146 union ioc4_gpcr gpcr;
147 unsigned int state, last_state = 1; 147 unsigned int state, last_state;
148 uint64_t start, end, period; 148 uint64_t start, end, period;
149 unsigned int count = 0; 149 unsigned int count;
150 150
151 /* Enable output */ 151 /* Enable output */
152 gpcr.raw = 0; 152 gpcr.raw = 0;
@@ -167,19 +167,20 @@ ioc4_clock_calibrate(struct ioc4_driver_data *idd)
167 mmiowb(); 167 mmiowb();
168 168
169 /* Check square wave period averaged over some number of cycles */ 169 /* Check square wave period averaged over some number of cycles */
170 do { 170 start = ktime_get_ns();
171 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw); 171 state = 1; /* make sure the first read isn't a rising edge */
172 state = int_out.fields.int_out; 172 for (count = 0; count <= IOC4_CALIBRATE_END; count++) {
173 if (!last_state && state) { 173 do { /* wait for a rising edge */
174 count++; 174 last_state = state;
175 if (count == IOC4_CALIBRATE_END) { 175 int_out.raw = readl(&idd->idd_misc_regs->int_out.raw);
176 end = ktime_get_ns(); 176 state = int_out.fields.int_out;
177 break; 177 } while (last_state || !state);
178 } else if (count == IOC4_CALIBRATE_DISCARD) 178
179 start = ktime_get_ns(); 179 /* discard the first few cycles */
180 } 180 if (count == IOC4_CALIBRATE_DISCARD)
181 last_state = state; 181 start = ktime_get_ns();
182 } while (1); 182 }
183 end = ktime_get_ns();
183 184
184 /* Calculation rearranged to preserve intermediate precision. 185 /* Calculation rearranged to preserve intermediate precision.
185 * Logically: 186 * Logically:
diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c
index 79f53941779d..c4cb9a984a5f 100644
--- a/drivers/misc/mei/amthif.c
+++ b/drivers/misc/mei/amthif.c
@@ -97,23 +97,25 @@ int mei_amthif_host_init(struct mei_device *dev)
97 /* allocate storage for ME message buffer */ 97 /* allocate storage for ME message buffer */
98 msg_buf = kcalloc(dev->iamthif_mtu, 98 msg_buf = kcalloc(dev->iamthif_mtu,
99 sizeof(unsigned char), GFP_KERNEL); 99 sizeof(unsigned char), GFP_KERNEL);
100 if (!msg_buf) 100 if (!msg_buf) {
101 return -ENOMEM; 101 ret = -ENOMEM;
102 goto out;
103 }
102 104
103 dev->iamthif_msg_buf = msg_buf; 105 dev->iamthif_msg_buf = msg_buf;
104 106
105 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); 107 ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID);
106
107 if (ret < 0) { 108 if (ret < 0) {
108 dev_err(dev->dev, 109 dev_err(dev->dev, "amthif: failed cl_link %d\n", ret);
109 "amthif: failed link client %d\n", ret); 110 goto out;
110 return ret;
111 } 111 }
112 112
113 ret = mei_cl_connect(cl, NULL); 113 ret = mei_cl_connect(cl, NULL);
114 114
115 dev->iamthif_state = MEI_IAMTHIF_IDLE; 115 dev->iamthif_state = MEI_IAMTHIF_IDLE;
116 116
117out:
118 mei_me_cl_put(me_cl);
117 return ret; 119 return ret;
118} 120}
119 121
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index b3a72bca5242..be767f4db26a 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -224,46 +224,53 @@ void mei_cl_driver_unregister(struct mei_cl_driver *driver)
224} 224}
225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister); 225EXPORT_SYMBOL_GPL(mei_cl_driver_unregister);
226 226
227static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, 227static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
228 bool blocking) 228 bool blocking)
229{ 229{
230 struct mei_device *dev; 230 struct mei_device *dev;
231 struct mei_me_client *me_cl; 231 struct mei_me_client *me_cl = NULL;
232 struct mei_cl_cb *cb; 232 struct mei_cl_cb *cb = NULL;
233 int rets; 233 ssize_t rets;
234 234
235 if (WARN_ON(!cl || !cl->dev)) 235 if (WARN_ON(!cl || !cl->dev))
236 return -ENODEV; 236 return -ENODEV;
237 237
238 dev = cl->dev; 238 dev = cl->dev;
239 239
240 if (cl->state != MEI_FILE_CONNECTED) 240 mutex_lock(&dev->device_lock);
241 return -ENODEV; 241 if (cl->state != MEI_FILE_CONNECTED) {
242 rets = -ENODEV;
243 goto out;
244 }
242 245
243 /* Check if we have an ME client device */ 246 /* Check if we have an ME client device */
244 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); 247 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
245 if (!me_cl) 248 if (!me_cl) {
246 return -ENOTTY; 249 rets = -ENOTTY;
250 goto out;
251 }
247 252
248 if (length > me_cl->props.max_msg_length) 253 if (length > me_cl->props.max_msg_length) {
249 return -EFBIG; 254 rets = -EFBIG;
255 goto out;
256 }
250 257
251 cb = mei_io_cb_init(cl, NULL); 258 cb = mei_io_cb_init(cl, NULL);
252 if (!cb) 259 if (!cb) {
253 return -ENOMEM; 260 rets = -ENOMEM;
261 goto out;
262 }
254 263
255 rets = mei_io_cb_alloc_req_buf(cb, length); 264 rets = mei_io_cb_alloc_req_buf(cb, length);
256 if (rets < 0) { 265 if (rets < 0)
257 mei_io_cb_free(cb); 266 goto out;
258 return rets;
259 }
260 267
261 memcpy(cb->request_buffer.data, buf, length); 268 memcpy(cb->request_buffer.data, buf, length);
262 269
263 mutex_lock(&dev->device_lock);
264
265 rets = mei_cl_write(cl, cb, blocking); 270 rets = mei_cl_write(cl, cb, blocking);
266 271
272out:
273 mei_me_cl_put(me_cl);
267 mutex_unlock(&dev->device_lock); 274 mutex_unlock(&dev->device_lock);
268 if (rets < 0) 275 if (rets < 0)
269 mei_io_cb_free(cb); 276 mei_io_cb_free(cb);
@@ -271,12 +278,12 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
271 return rets; 278 return rets;
272} 279}
273 280
274int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length) 281ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
275{ 282{
276 struct mei_device *dev; 283 struct mei_device *dev;
277 struct mei_cl_cb *cb; 284 struct mei_cl_cb *cb;
278 size_t r_length; 285 size_t r_length;
279 int err; 286 ssize_t rets;
280 287
281 if (WARN_ON(!cl || !cl->dev)) 288 if (WARN_ON(!cl || !cl->dev))
282 return -ENODEV; 289 return -ENODEV;
@@ -286,11 +293,9 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
286 mutex_lock(&dev->device_lock); 293 mutex_lock(&dev->device_lock);
287 294
288 if (!cl->read_cb) { 295 if (!cl->read_cb) {
289 err = mei_cl_read_start(cl, length); 296 rets = mei_cl_read_start(cl, length);
290 if (err < 0) { 297 if (rets < 0)
291 mutex_unlock(&dev->device_lock); 298 goto out;
292 return err;
293 }
294 } 299 }
295 300
296 if (cl->reading_state != MEI_READ_COMPLETE && 301 if (cl->reading_state != MEI_READ_COMPLETE &&
@@ -313,13 +318,13 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
313 cb = cl->read_cb; 318 cb = cl->read_cb;
314 319
315 if (cl->reading_state != MEI_READ_COMPLETE) { 320 if (cl->reading_state != MEI_READ_COMPLETE) {
316 r_length = 0; 321 rets = 0;
317 goto out; 322 goto out;
318 } 323 }
319 324
320 r_length = min_t(size_t, length, cb->buf_idx); 325 r_length = min_t(size_t, length, cb->buf_idx);
321
322 memcpy(buf, cb->response_buffer.data, r_length); 326 memcpy(buf, cb->response_buffer.data, r_length);
327 rets = r_length;
323 328
324 mei_io_cb_free(cb); 329 mei_io_cb_free(cb);
325 cl->reading_state = MEI_IDLE; 330 cl->reading_state = MEI_IDLE;
@@ -328,20 +333,20 @@ int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length)
328out: 333out:
329 mutex_unlock(&dev->device_lock); 334 mutex_unlock(&dev->device_lock);
330 335
331 return r_length; 336 return rets;
332} 337}
333 338
334inline int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length) 339inline ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length)
335{ 340{
336 return ___mei_cl_send(cl, buf, length, 0); 341 return ___mei_cl_send(cl, buf, length, 0);
337} 342}
338 343
339inline int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length) 344inline ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length)
340{ 345{
341 return ___mei_cl_send(cl, buf, length, 1); 346 return ___mei_cl_send(cl, buf, length, 1);
342} 347}
343 348
344int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length) 349ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
345{ 350{
346 struct mei_cl *cl = device->cl; 351 struct mei_cl *cl = device->cl;
347 352
@@ -355,7 +360,7 @@ int mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length)
355} 360}
356EXPORT_SYMBOL_GPL(mei_cl_send); 361EXPORT_SYMBOL_GPL(mei_cl_send);
357 362
358int mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length) 363ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length)
359{ 364{
360 struct mei_cl *cl = device->cl; 365 struct mei_cl *cl = device->cl;
361 366
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 1382d551d7ed..dfbddfe1c7a0 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -27,7 +27,63 @@
27#include "client.h" 27#include "client.h"
28 28
29/** 29/**
30 * mei_me_cl_init - initialize me client
31 *
32 * @me_cl: me client
33 */
34void mei_me_cl_init(struct mei_me_client *me_cl)
35{
36 INIT_LIST_HEAD(&me_cl->list);
37 kref_init(&me_cl->refcnt);
38}
39
40/**
41 * mei_me_cl_get - increases me client refcount
42 *
43 * @me_cl: me client
44 *
45 * Locking: called under "dev->device_lock" lock
46 *
47 * Return: me client or NULL
48 */
49struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl)
50{
51 if (me_cl)
52 kref_get(&me_cl->refcnt);
53
54 return me_cl;
55}
56
57/**
58 * mei_me_cl_release - unlink and free me client
59 *
60 * Locking: called under "dev->device_lock" lock
61 *
62 * @ref: me_client refcount
63 */
64static void mei_me_cl_release(struct kref *ref)
65{
66 struct mei_me_client *me_cl =
67 container_of(ref, struct mei_me_client, refcnt);
68 list_del(&me_cl->list);
69 kfree(me_cl);
70}
71/**
72 * mei_me_cl_put - decrease me client refcount and free client if necessary
73 *
74 * Locking: called under "dev->device_lock" lock
75 *
76 * @me_cl: me client
77 */
78void mei_me_cl_put(struct mei_me_client *me_cl)
79{
80 if (me_cl)
81 kref_put(&me_cl->refcnt, mei_me_cl_release);
82}
83
84/**
30 * mei_me_cl_by_uuid - locate me client by uuid 85 * mei_me_cl_by_uuid - locate me client by uuid
86 * increases ref count
31 * 87 *
32 * @dev: mei device 88 * @dev: mei device
33 * @uuid: me client uuid 89 * @uuid: me client uuid
@@ -43,13 +99,14 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
43 99
44 list_for_each_entry(me_cl, &dev->me_clients, list) 100 list_for_each_entry(me_cl, &dev->me_clients, list)
45 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) 101 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
46 return me_cl; 102 return mei_me_cl_get(me_cl);
47 103
48 return NULL; 104 return NULL;
49} 105}
50 106
51/** 107/**
52 * mei_me_cl_by_id - locate me client by client id 108 * mei_me_cl_by_id - locate me client by client id
109 * increases ref count
53 * 110 *
54 * @dev: the device structure 111 * @dev: the device structure
55 * @client_id: me client id 112 * @client_id: me client id
@@ -65,12 +122,14 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
65 122
66 list_for_each_entry(me_cl, &dev->me_clients, list) 123 list_for_each_entry(me_cl, &dev->me_clients, list)
67 if (me_cl->client_id == client_id) 124 if (me_cl->client_id == client_id)
68 return me_cl; 125 return mei_me_cl_get(me_cl);
126
69 return NULL; 127 return NULL;
70} 128}
71 129
72/** 130/**
73 * mei_me_cl_by_uuid_id - locate me client by client id and uuid 131 * mei_me_cl_by_uuid_id - locate me client by client id and uuid
132 * increases ref count
74 * 133 *
75 * @dev: the device structure 134 * @dev: the device structure
76 * @uuid: me client uuid 135 * @uuid: me client uuid
@@ -88,31 +147,67 @@ struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
88 list_for_each_entry(me_cl, &dev->me_clients, list) 147 list_for_each_entry(me_cl, &dev->me_clients, list)
89 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 148 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
90 me_cl->client_id == client_id) 149 me_cl->client_id == client_id)
91 return me_cl; 150 return mei_me_cl_get(me_cl);
151
92 return NULL; 152 return NULL;
93} 153}
94 154
95/** 155/**
96 * mei_me_cl_remove - remove me client matching uuid and client_id 156 * mei_me_cl_rm_by_uuid - remove all me clients matching uuid
97 * 157 *
98 * @dev: the device structure 158 * @dev: the device structure
99 * @uuid: me client uuid 159 * @uuid: me client uuid
100 * @client_id: me client address 160 *
161 * Locking: called under "dev->device_lock" lock
101 */ 162 */
102void mei_me_cl_remove(struct mei_device *dev, const uuid_le *uuid, u8 client_id) 163void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid)
103{ 164{
104 struct mei_me_client *me_cl, *next; 165 struct mei_me_client *me_cl, *next;
105 166
167 dev_dbg(dev->dev, "remove %pUl\n", uuid);
168 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
169 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
170 mei_me_cl_put(me_cl);
171}
172
173/**
174 * mei_me_cl_rm_by_uuid_id - remove all me clients matching client id
175 *
176 * @dev: the device structure
177 * @uuid: me client uuid
178 * @id: me client id
179 *
180 * Locking: called under "dev->device_lock" lock
181 */
182void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id)
183{
184 struct mei_me_client *me_cl, *next;
185 const uuid_le *pn;
186
187 dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id);
106 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { 188 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
107 if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && 189 pn = &me_cl->props.protocol_name;
108 me_cl->client_id == client_id) { 190 if (me_cl->client_id == id && uuid_le_cmp(*uuid, *pn) == 0)
109 list_del(&me_cl->list); 191 mei_me_cl_put(me_cl);
110 kfree(me_cl);
111 break;
112 }
113 } 192 }
114} 193}
115 194
195/**
196 * mei_me_cl_rm_all - remove all me clients
197 *
198 * @dev: the device structure
199 *
200 * Locking: called under "dev->device_lock" lock
201 */
202void mei_me_cl_rm_all(struct mei_device *dev)
203{
204 struct mei_me_client *me_cl, *next;
205
206 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
207 mei_me_cl_put(me_cl);
208}
209
210
116 211
117/** 212/**
118 * mei_cl_cmp_id - tells if the clients are the same 213 * mei_cl_cmp_id - tells if the clients are the same
@@ -695,6 +790,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
695{ 790{
696 struct mei_device *dev; 791 struct mei_device *dev;
697 struct mei_me_client *me_cl; 792 struct mei_me_client *me_cl;
793 int rets = 0;
698 794
699 if (WARN_ON(!cl || !cl->dev)) 795 if (WARN_ON(!cl || !cl->dev))
700 return -EINVAL; 796 return -EINVAL;
@@ -704,18 +800,19 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
704 if (cl->mei_flow_ctrl_creds > 0) 800 if (cl->mei_flow_ctrl_creds > 0)
705 return 1; 801 return 1;
706 802
707 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 803 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
708 if (!me_cl) { 804 if (!me_cl) {
709 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 805 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
710 return -ENOENT; 806 return -ENOENT;
711 } 807 }
712 808
713 if (me_cl->mei_flow_ctrl_creds) { 809 if (me_cl->mei_flow_ctrl_creds > 0) {
810 rets = 1;
714 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 811 if (WARN_ON(me_cl->props.single_recv_buf == 0))
715 return -EINVAL; 812 rets = -EINVAL;
716 return 1;
717 } 813 }
718 return 0; 814 mei_me_cl_put(me_cl);
815 return rets;
719} 816}
720 817
721/** 818/**
@@ -732,28 +829,36 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
732{ 829{
733 struct mei_device *dev; 830 struct mei_device *dev;
734 struct mei_me_client *me_cl; 831 struct mei_me_client *me_cl;
832 int rets;
735 833
736 if (WARN_ON(!cl || !cl->dev)) 834 if (WARN_ON(!cl || !cl->dev))
737 return -EINVAL; 835 return -EINVAL;
738 836
739 dev = cl->dev; 837 dev = cl->dev;
740 838
741 me_cl = mei_me_cl_by_id(dev, cl->me_client_id); 839 me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
742 if (!me_cl) { 840 if (!me_cl) {
743 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 841 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
744 return -ENOENT; 842 return -ENOENT;
745 } 843 }
746 844
747 if (me_cl->props.single_recv_buf) { 845 if (me_cl->props.single_recv_buf) {
748 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) 846 if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) {
749 return -EINVAL; 847 rets = -EINVAL;
848 goto out;
849 }
750 me_cl->mei_flow_ctrl_creds--; 850 me_cl->mei_flow_ctrl_creds--;
751 } else { 851 } else {
752 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) 852 if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) {
753 return -EINVAL; 853 rets = -EINVAL;
854 goto out;
855 }
754 cl->mei_flow_ctrl_creds--; 856 cl->mei_flow_ctrl_creds--;
755 } 857 }
756 return 0; 858 rets = 0;
859out:
860 mei_me_cl_put(me_cl);
861 return rets;
757} 862}
758 863
759/** 864/**
@@ -788,6 +893,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
788 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); 893 cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
789 return -ENOTTY; 894 return -ENOTTY;
790 } 895 }
896 /* always allocate at least client max message */
897 length = max_t(size_t, length, me_cl->props.max_msg_length);
898 mei_me_cl_put(me_cl);
791 899
792 rets = pm_runtime_get(dev->dev); 900 rets = pm_runtime_get(dev->dev);
793 if (rets < 0 && rets != -EINPROGRESS) { 901 if (rets < 0 && rets != -EINPROGRESS) {
@@ -802,8 +910,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
802 goto out; 910 goto out;
803 } 911 }
804 912
805 /* always allocate at least client max message */
806 length = max_t(size_t, length, me_cl->props.max_msg_length);
807 rets = mei_io_cb_alloc_resp_buf(cb, length); 913 rets = mei_io_cb_alloc_resp_buf(cb, length);
808 if (rets) 914 if (rets)
809 goto out; 915 goto out;
diff --git a/drivers/misc/mei/client.h b/drivers/misc/mei/client.h
index d9d0c1525259..cfcde8e97fc4 100644
--- a/drivers/misc/mei/client.h
+++ b/drivers/misc/mei/client.h
@@ -24,15 +24,22 @@
24 24
25#include "mei_dev.h" 25#include "mei_dev.h"
26 26
27/*
28 * reference counting base function
29 */
30void mei_me_cl_init(struct mei_me_client *me_cl);
31void mei_me_cl_put(struct mei_me_client *me_cl);
32struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
33
27struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, 34struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
28 const uuid_le *cuuid); 35 const uuid_le *uuid);
29struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id); 36struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
30
31struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, 37struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
32 const uuid_le *uuid, u8 client_id); 38 const uuid_le *uuid, u8 client_id);
33 39void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
34void mei_me_cl_remove(struct mei_device *dev, 40void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
35 const uuid_le *uuid, u8 client_id); 41 const uuid_le *uuid, u8 id);
42void mei_me_cl_rm_all(struct mei_device *dev);
36 43
37/* 44/*
38 * MEI IO Functions 45 * MEI IO Functions
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c
index b60b4263cf0f..b125380ee871 100644
--- a/drivers/misc/mei/debugfs.c
+++ b/drivers/misc/mei/debugfs.c
@@ -21,20 +21,22 @@
21#include <linux/mei.h> 21#include <linux/mei.h>
22 22
23#include "mei_dev.h" 23#include "mei_dev.h"
24#include "client.h"
24#include "hw.h" 25#include "hw.h"
25 26
26static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, 27static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
27 size_t cnt, loff_t *ppos) 28 size_t cnt, loff_t *ppos)
28{ 29{
29 struct mei_device *dev = fp->private_data; 30 struct mei_device *dev = fp->private_data;
30 struct mei_me_client *me_cl; 31 struct mei_me_client *me_cl, *n;
31 size_t bufsz = 1; 32 size_t bufsz = 1;
32 char *buf; 33 char *buf;
33 int i = 0; 34 int i = 0;
34 int pos = 0; 35 int pos = 0;
35 int ret; 36 int ret;
36 37
37#define HDR " |id|fix| UUID |con|msg len|sb|\n" 38#define HDR \
39" |id|fix| UUID |con|msg len|sb|refc|\n"
38 40
39 mutex_lock(&dev->device_lock); 41 mutex_lock(&dev->device_lock);
40 42
@@ -54,16 +56,22 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
54 if (dev->dev_state != MEI_DEV_ENABLED) 56 if (dev->dev_state != MEI_DEV_ENABLED)
55 goto out; 57 goto out;
56 58
57 list_for_each_entry(me_cl, &dev->me_clients, list) { 59 list_for_each_entry_safe(me_cl, n, &dev->me_clients, list) {
58 60
59 pos += scnprintf(buf + pos, bufsz - pos, 61 me_cl = mei_me_cl_get(me_cl);
60 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n", 62 if (me_cl) {
61 i++, me_cl->client_id, 63 pos += scnprintf(buf + pos, bufsz - pos,
62 me_cl->props.fixed_address, 64 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
63 &me_cl->props.protocol_name, 65 i++, me_cl->client_id,
64 me_cl->props.max_number_of_connections, 66 me_cl->props.fixed_address,
65 me_cl->props.max_msg_length, 67 &me_cl->props.protocol_name,
66 me_cl->props.single_recv_buf); 68 me_cl->props.max_number_of_connections,
69 me_cl->props.max_msg_length,
70 me_cl->props.single_recv_buf,
71 atomic_read(&me_cl->refcnt.refcount));
72 }
73
74 mei_me_cl_put(me_cl);
67 } 75 }
68out: 76out:
69 mutex_unlock(&dev->device_lock); 77 mutex_unlock(&dev->device_lock);
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index 239d7f5d6a92..c8412d41e4f1 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -105,21 +105,6 @@ void mei_hbm_idle(struct mei_device *dev)
105} 105}
106 106
107/** 107/**
108 * mei_me_cl_remove_all - remove all me clients
109 *
110 * @dev: the device structure
111 */
112static void mei_me_cl_remove_all(struct mei_device *dev)
113{
114 struct mei_me_client *me_cl, *next;
115
116 list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
117 list_del(&me_cl->list);
118 kfree(me_cl);
119 }
120}
121
122/**
123 * mei_hbm_reset - reset hbm counters and book keeping data structurs 108 * mei_hbm_reset - reset hbm counters and book keeping data structurs
124 * 109 *
125 * @dev: the device structure 110 * @dev: the device structure
@@ -128,7 +113,7 @@ void mei_hbm_reset(struct mei_device *dev)
128{ 113{
129 dev->me_client_index = 0; 114 dev->me_client_index = 0;
130 115
131 mei_me_cl_remove_all(dev); 116 mei_me_cl_rm_all(dev);
132 117
133 mei_hbm_idle(dev); 118 mei_hbm_idle(dev);
134} 119}
@@ -339,11 +324,16 @@ static int mei_hbm_me_cl_add(struct mei_device *dev,
339 struct hbm_props_response *res) 324 struct hbm_props_response *res)
340{ 325{
341 struct mei_me_client *me_cl; 326 struct mei_me_client *me_cl;
327 const uuid_le *uuid = &res->client_properties.protocol_name;
328
329 mei_me_cl_rm_by_uuid(dev, uuid);
342 330
343 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); 331 me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
344 if (!me_cl) 332 if (!me_cl)
345 return -ENOMEM; 333 return -ENOMEM;
346 334
335 mei_me_cl_init(me_cl);
336
347 me_cl->props = res->client_properties; 337 me_cl->props = res->client_properties;
348 me_cl->client_id = res->me_addr; 338 me_cl->client_id = res->me_addr;
349 me_cl->mei_flow_ctrl_creds = 0; 339 me_cl->mei_flow_ctrl_creds = 0;
@@ -484,6 +474,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
484 struct hbm_flow_control *flow) 474 struct hbm_flow_control *flow)
485{ 475{
486 struct mei_me_client *me_cl; 476 struct mei_me_client *me_cl;
477 int rets;
487 478
488 me_cl = mei_me_cl_by_id(dev, flow->me_addr); 479 me_cl = mei_me_cl_by_id(dev, flow->me_addr);
489 if (!me_cl) { 480 if (!me_cl) {
@@ -492,14 +483,19 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
492 return -ENOENT; 483 return -ENOENT;
493 } 484 }
494 485
495 if (WARN_ON(me_cl->props.single_recv_buf == 0)) 486 if (WARN_ON(me_cl->props.single_recv_buf == 0)) {
496 return -EINVAL; 487 rets = -EINVAL;
488 goto out;
489 }
497 490
498 me_cl->mei_flow_ctrl_creds++; 491 me_cl->mei_flow_ctrl_creds++;
499 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", 492 dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n",
500 flow->me_addr, me_cl->mei_flow_ctrl_creds); 493 flow->me_addr, me_cl->mei_flow_ctrl_creds);
501 494
502 return 0; 495 rets = 0;
496out:
497 mei_me_cl_put(me_cl);
498 return rets;
503} 499}
504 500
505/** 501/**
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index ff2755062b44..f8fd503dfbd6 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -234,6 +234,18 @@ static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
234 struct mei_me_hw *hw = to_me_hw(dev); 234 struct mei_me_hw *hw = to_me_hw(dev);
235 u32 hcsr = mei_hcsr_read(hw); 235 u32 hcsr = mei_hcsr_read(hw);
236 236
237 /* H_RST may be found lit before reset is started,
238 * for example if preceding reset flow hasn't completed.
239 * In that case asserting H_RST will be ignored, therefore
240 * we need to clean H_RST bit to start a successful reset sequence.
241 */
242 if ((hcsr & H_RST) == H_RST) {
243 dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
244 hcsr &= ~H_RST;
245 mei_hcsr_set(hw, hcsr);
246 hcsr = mei_hcsr_read(hw);
247 }
248
237 hcsr |= H_RST | H_IG | H_IS; 249 hcsr |= H_RST | H_IG | H_IS;
238 250
239 if (intr_enable) 251 if (intr_enable)
@@ -323,6 +335,7 @@ static int mei_me_hw_ready_wait(struct mei_device *dev)
323 return -ETIME; 335 return -ETIME;
324 } 336 }
325 337
338 mei_me_hw_reset_release(dev);
326 dev->recvd_hw_ready = false; 339 dev->recvd_hw_ready = false;
327 return 0; 340 return 0;
328} 341}
@@ -719,9 +732,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
719 /* check if we need to start the dev */ 732 /* check if we need to start the dev */
720 if (!mei_host_is_ready(dev)) { 733 if (!mei_host_is_ready(dev)) {
721 if (mei_hw_is_ready(dev)) { 734 if (mei_hw_is_ready(dev)) {
722 mei_me_hw_reset_release(dev);
723 dev_dbg(dev->dev, "we need to start the dev.\n"); 735 dev_dbg(dev->dev, "we need to start the dev.\n");
724
725 dev->recvd_hw_ready = true; 736 dev->recvd_hw_ready = true;
726 wake_up(&dev->wait_hw_ready); 737 wake_up(&dev->wait_hw_ready);
727 } else { 738 } else {
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index ae56ba6ca0e3..3c019c0e60eb 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -303,7 +303,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
303 size_t length, loff_t *offset) 303 size_t length, loff_t *offset)
304{ 304{
305 struct mei_cl *cl = file->private_data; 305 struct mei_cl *cl = file->private_data;
306 struct mei_me_client *me_cl; 306 struct mei_me_client *me_cl = NULL;
307 struct mei_cl_cb *write_cb = NULL; 307 struct mei_cl_cb *write_cb = NULL;
308 struct mei_device *dev; 308 struct mei_device *dev;
309 unsigned long timeout = 0; 309 unsigned long timeout = 0;
@@ -399,12 +399,14 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
399 "amthif write failed with status = %d\n", rets); 399 "amthif write failed with status = %d\n", rets);
400 goto out; 400 goto out;
401 } 401 }
402 mei_me_cl_put(me_cl);
402 mutex_unlock(&dev->device_lock); 403 mutex_unlock(&dev->device_lock);
403 return length; 404 return length;
404 } 405 }
405 406
406 rets = mei_cl_write(cl, write_cb, false); 407 rets = mei_cl_write(cl, write_cb, false);
407out: 408out:
409 mei_me_cl_put(me_cl);
408 mutex_unlock(&dev->device_lock); 410 mutex_unlock(&dev->device_lock);
409 if (rets < 0) 411 if (rets < 0)
410 mei_io_cb_free(write_cb); 412 mei_io_cb_free(write_cb);
@@ -433,24 +435,19 @@ static int mei_ioctl_connect_client(struct file *file,
433 cl = file->private_data; 435 cl = file->private_data;
434 dev = cl->dev; 436 dev = cl->dev;
435 437
436 if (dev->dev_state != MEI_DEV_ENABLED) { 438 if (dev->dev_state != MEI_DEV_ENABLED)
437 rets = -ENODEV; 439 return -ENODEV;
438 goto end;
439 }
440 440
441 if (cl->state != MEI_FILE_INITIALIZING && 441 if (cl->state != MEI_FILE_INITIALIZING &&
442 cl->state != MEI_FILE_DISCONNECTED) { 442 cl->state != MEI_FILE_DISCONNECTED)
443 rets = -EBUSY; 443 return -EBUSY;
444 goto end;
445 }
446 444
447 /* find ME client we're trying to connect to */ 445 /* find ME client we're trying to connect to */
448 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid); 446 me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
449 if (!me_cl || me_cl->props.fixed_address) { 447 if (!me_cl || me_cl->props.fixed_address) {
450 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n", 448 dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
451 &data->in_client_uuid); 449 &data->in_client_uuid);
452 rets = -ENOTTY; 450 return -ENOTTY;
453 goto end;
454 } 451 }
455 452
456 cl->me_client_id = me_cl->client_id; 453 cl->me_client_id = me_cl->client_id;
@@ -487,17 +484,16 @@ static int mei_ioctl_connect_client(struct file *file,
487 goto end; 484 goto end;
488 } 485 }
489 486
490
491 /* prepare the output buffer */ 487 /* prepare the output buffer */
492 client = &data->out_client_properties; 488 client = &data->out_client_properties;
493 client->max_msg_length = me_cl->props.max_msg_length; 489 client->max_msg_length = me_cl->props.max_msg_length;
494 client->protocol_version = me_cl->props.protocol_version; 490 client->protocol_version = me_cl->props.protocol_version;
495 dev_dbg(dev->dev, "Can connect?\n"); 491 dev_dbg(dev->dev, "Can connect?\n");
496 492
497
498 rets = mei_cl_connect(cl, file); 493 rets = mei_cl_connect(cl, file);
499 494
500end: 495end:
496 mei_me_cl_put(me_cl);
501 return rets; 497 return rets;
502} 498}
503 499
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 3dad74a8d496..6c6ce9381535 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -172,12 +172,14 @@ struct mei_fw_status {
172 * struct mei_me_client - representation of me (fw) client 172 * struct mei_me_client - representation of me (fw) client
173 * 173 *
174 * @list: link in me client list 174 * @list: link in me client list
175 * @refcnt: struct reference count
175 * @props: client properties 176 * @props: client properties
176 * @client_id: me client id 177 * @client_id: me client id
177 * @mei_flow_ctrl_creds: flow control credits 178 * @mei_flow_ctrl_creds: flow control credits
178 */ 179 */
179struct mei_me_client { 180struct mei_me_client {
180 struct list_head list; 181 struct list_head list;
182 struct kref refcnt;
181 struct mei_client_properties props; 183 struct mei_client_properties props;
182 u8 client_id; 184 u8 client_id;
183 u8 mei_flow_ctrl_creds; 185 u8 mei_flow_ctrl_creds;
@@ -345,9 +347,9 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
345 struct mei_cl_ops *ops); 347 struct mei_cl_ops *ops);
346void mei_cl_remove_device(struct mei_cl_device *device); 348void mei_cl_remove_device(struct mei_cl_device *device);
347 349
348int __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length); 350ssize_t __mei_cl_async_send(struct mei_cl *cl, u8 *buf, size_t length);
349int __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length); 351ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length);
350int __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length); 352ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
351void mei_cl_bus_rx_event(struct mei_cl *cl); 353void mei_cl_bus_rx_event(struct mei_cl *cl);
352void mei_cl_bus_remove_devices(struct mei_device *dev); 354void mei_cl_bus_remove_devices(struct mei_device *dev);
353int mei_cl_bus_init(void); 355int mei_cl_bus_init(void);
diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c
index 60ca9240368e..bb61a119b8bb 100644
--- a/drivers/misc/mei/nfc.c
+++ b/drivers/misc/mei/nfc.c
@@ -521,6 +521,7 @@ int mei_nfc_host_init(struct mei_device *dev)
521 521
522 cl_info->me_client_id = me_cl->client_id; 522 cl_info->me_client_id = me_cl->client_id;
523 cl_info->cl_uuid = me_cl->props.protocol_name; 523 cl_info->cl_uuid = me_cl->props.protocol_name;
524 mei_me_cl_put(me_cl);
524 525
525 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); 526 ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
526 if (ret) 527 if (ret)
@@ -539,6 +540,7 @@ int mei_nfc_host_init(struct mei_device *dev)
539 540
540 cl->me_client_id = me_cl->client_id; 541 cl->me_client_id = me_cl->client_id;
541 cl->cl_uuid = me_cl->props.protocol_name; 542 cl->cl_uuid = me_cl->props.protocol_name;
543 mei_me_cl_put(me_cl);
542 544
543 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); 545 ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
544 if (ret) 546 if (ret)
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index b1d892cea94d..475f1dea45bf 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev)
76 76
77 cl->me_client_id = me_cl->client_id; 77 cl->me_client_id = me_cl->client_id;
78 cl->cl_uuid = me_cl->props.protocol_name; 78 cl->cl_uuid = me_cl->props.protocol_name;
79 mei_me_cl_put(me_cl);
79 80
80 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID); 81 ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
81 82
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 54be83d3efdd..c8c6a363069c 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -343,12 +343,26 @@ void st_int_recv(void *disc_data,
343 /* Unknow packet? */ 343 /* Unknow packet? */
344 default: 344 default:
345 type = *ptr; 345 type = *ptr;
346 if (st_gdata->list[type] == NULL) {
347 pr_err("chip/interface misbehavior dropping"
348 " frame starting with 0x%02x", type);
349 goto done;
350 346
347 /* Default case means non-HCILL packets,
348 * possibilities are packets for:
349 * (a) valid protocol - Supported Protocols within
350 * the ST_MAX_CHANNELS.
351 * (b) registered protocol - Checked by
352 * "st_gdata->list[type] == NULL)" are supported
353 * protocols only.
354 * Rules out any invalid protocol and
355 * unregistered protocols with channel ID < 16.
356 */
357
358 if ((type >= ST_MAX_CHANNELS) ||
359 (st_gdata->list[type] == NULL)) {
360 pr_err("chip/interface misbehavior: "
361 "dropping frame starting "
362 "with 0x%02x\n", type);
363 goto done;
351 } 364 }
365
352 st_gdata->rx_skb = alloc_skb( 366 st_gdata->rx_skb = alloc_skb(
353 st_gdata->list[type]->max_frame_size, 367 st_gdata->list[type]->max_frame_size,
354 GFP_ATOMIC); 368 GFP_ATOMIC);
@@ -893,5 +907,3 @@ void st_core_exit(struct st_data_s *st_gdata)
893 kfree(st_gdata); 907 kfree(st_gdata);
894 } 908 }
895} 909}
896
897
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index e4b7ee4f57b8..18e7a03985d4 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -36,7 +36,8 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/ti_wilink_st.h> 37#include <linux/ti_wilink_st.h>
38#include <linux/module.h> 38#include <linux/module.h>
39 39#include <linux/of.h>
40#include <linux/of_device.h>
40 41
41#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 42#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
42static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 43static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
@@ -44,6 +45,9 @@ static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
44/**********************************************************************/ 45/**********************************************************************/
45/* internal functions */ 46/* internal functions */
46 47
48struct ti_st_plat_data *dt_pdata;
49static struct ti_st_plat_data *get_platform_data(struct device *dev);
50
47/** 51/**
48 * st_get_plat_device - 52 * st_get_plat_device -
49 * function which returns the reference to the platform device 53 * function which returns the reference to the platform device
@@ -215,6 +219,7 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
215{ 219{
216 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0; 220 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
217 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 }; 221 const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
222 long timeout;
218 223
219 pr_debug("%s", __func__); 224 pr_debug("%s", __func__);
220 225
@@ -224,10 +229,11 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
224 return -EIO; 229 return -EIO;
225 } 230 }
226 231
227 if (!wait_for_completion_interruptible_timeout( 232 timeout = wait_for_completion_interruptible_timeout(
228 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 233 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME));
229 pr_err(" waiting for ver info- timed out "); 234 if (timeout <= 0) {
230 return -ETIMEDOUT; 235 pr_err(" waiting for ver info- timed out or received signal");
236 return timeout ? -ERESTARTSYS : -ETIMEDOUT;
231 } 237 }
232 reinit_completion(&kim_gdata->kim_rcvd); 238 reinit_completion(&kim_gdata->kim_rcvd);
233 /* the positions 12 & 13 in the response buffer provide with the 239 /* the positions 12 & 13 in the response buffer provide with the
@@ -391,13 +397,14 @@ static long download_firmware(struct kim_data_s *kim_gdata)
391 break; 397 break;
392 case ACTION_WAIT_EVENT: /* wait */ 398 case ACTION_WAIT_EVENT: /* wait */
393 pr_debug("W"); 399 pr_debug("W");
394 if (!wait_for_completion_interruptible_timeout( 400 err = wait_for_completion_interruptible_timeout(
395 &kim_gdata->kim_rcvd, 401 &kim_gdata->kim_rcvd,
396 msecs_to_jiffies(CMD_RESP_TIME))) { 402 msecs_to_jiffies(CMD_RESP_TIME));
397 pr_err("response timeout during fw download "); 403 if (err <= 0) {
404 pr_err("response timeout/signaled during fw download ");
398 /* timed out */ 405 /* timed out */
399 release_firmware(kim_gdata->fw_entry); 406 release_firmware(kim_gdata->fw_entry);
400 return -ETIMEDOUT; 407 return err ? -ERESTARTSYS : -ETIMEDOUT;
401 } 408 }
402 reinit_completion(&kim_gdata->kim_rcvd); 409 reinit_completion(&kim_gdata->kim_rcvd);
403 break; 410 break;
@@ -462,7 +469,12 @@ long st_kim_start(void *kim_data)
462 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 469 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
463 470
464 pr_info(" %s", __func__); 471 pr_info(" %s", __func__);
465 pdata = kim_gdata->kim_pdev->dev.platform_data; 472 if (kim_gdata->kim_pdev->dev.of_node) {
473 pr_debug("use device tree data");
474 pdata = dt_pdata;
475 } else {
476 pdata = kim_gdata->kim_pdev->dev.platform_data;
477 }
466 478
467 do { 479 do {
468 /* platform specific enabling code here */ 480 /* platform specific enabling code here */
@@ -522,12 +534,18 @@ long st_kim_stop(void *kim_data)
522{ 534{
523 long err = 0; 535 long err = 0;
524 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 536 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
525 struct ti_st_plat_data *pdata = 537 struct ti_st_plat_data *pdata;
526 kim_gdata->kim_pdev->dev.platform_data;
527 struct tty_struct *tty = kim_gdata->core_data->tty; 538 struct tty_struct *tty = kim_gdata->core_data->tty;
528 539
529 reinit_completion(&kim_gdata->ldisc_installed); 540 reinit_completion(&kim_gdata->ldisc_installed);
530 541
542 if (kim_gdata->kim_pdev->dev.of_node) {
543 pr_debug("use device tree data");
544 pdata = dt_pdata;
545 } else
546 pdata = kim_gdata->kim_pdev->dev.platform_data;
547
548
531 if (tty) { /* can be called before ldisc is installed */ 549 if (tty) { /* can be called before ldisc is installed */
532 /* Flush any pending characters in the driver and discipline. */ 550 /* Flush any pending characters in the driver and discipline. */
533 tty_ldisc_flush(tty); 551 tty_ldisc_flush(tty);
@@ -620,7 +638,7 @@ static ssize_t show_baud_rate(struct device *dev,
620 struct device_attribute *attr, char *buf) 638 struct device_attribute *attr, char *buf)
621{ 639{
622 struct kim_data_s *kim_data = dev_get_drvdata(dev); 640 struct kim_data_s *kim_data = dev_get_drvdata(dev);
623 return sprintf(buf, "%ld\n", kim_data->baud_rate); 641 return sprintf(buf, "%d\n", kim_data->baud_rate);
624} 642}
625 643
626static ssize_t show_flow_cntrl(struct device *dev, 644static ssize_t show_flow_cntrl(struct device *dev,
@@ -676,12 +694,16 @@ void st_kim_ref(struct st_data_s **core_data, int id)
676 struct kim_data_s *kim_gdata; 694 struct kim_data_s *kim_gdata;
677 /* get kim_gdata reference from platform device */ 695 /* get kim_gdata reference from platform device */
678 pdev = st_get_plat_device(id); 696 pdev = st_get_plat_device(id);
679 if (!pdev) { 697 if (!pdev)
680 *core_data = NULL; 698 goto err;
681 return;
682 }
683 kim_gdata = platform_get_drvdata(pdev); 699 kim_gdata = platform_get_drvdata(pdev);
700 if (!kim_gdata)
701 goto err;
702
684 *core_data = kim_gdata->core_data; 703 *core_data = kim_gdata->core_data;
704 return;
705err:
706 *core_data = NULL;
685} 707}
686 708
687static int kim_version_open(struct inode *i, struct file *f) 709static int kim_version_open(struct inode *i, struct file *f)
@@ -715,13 +737,53 @@ static const struct file_operations list_debugfs_fops = {
715 * board-*.c file 737 * board-*.c file
716 */ 738 */
717 739
740static const struct of_device_id kim_of_match[] = {
741{
742 .compatible = "kim",
743 },
744 {}
745};
746MODULE_DEVICE_TABLE(of, kim_of_match);
747
748static struct ti_st_plat_data *get_platform_data(struct device *dev)
749{
750 struct device_node *np = dev->of_node;
751 const u32 *dt_property;
752 int len;
753
754 dt_pdata = kzalloc(sizeof(*dt_pdata), GFP_KERNEL);
755
756 if (!dt_pdata)
757 pr_err("Can't allocate device_tree platform data\n");
758
759 dt_property = of_get_property(np, "dev_name", &len);
760 if (dt_property)
761 memcpy(&dt_pdata->dev_name, dt_property, len);
762 of_property_read_u32(np, "nshutdown_gpio",
763 &dt_pdata->nshutdown_gpio);
764 of_property_read_u32(np, "flow_cntrl", &dt_pdata->flow_cntrl);
765 of_property_read_u32(np, "baud_rate", &dt_pdata->baud_rate);
766
767 return dt_pdata;
768}
769
718static struct dentry *kim_debugfs_dir; 770static struct dentry *kim_debugfs_dir;
719static int kim_probe(struct platform_device *pdev) 771static int kim_probe(struct platform_device *pdev)
720{ 772{
721 struct kim_data_s *kim_gdata; 773 struct kim_data_s *kim_gdata;
722 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 774 struct ti_st_plat_data *pdata;
723 int err; 775 int err;
724 776
777 if (pdev->dev.of_node)
778 pdata = get_platform_data(&pdev->dev);
779 else
780 pdata = pdev->dev.platform_data;
781
782 if (pdata == NULL) {
783 dev_err(&pdev->dev, "Platform Data is missing\n");
784 return -ENXIO;
785 }
786
725 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 787 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
726 /* multiple devices could exist */ 788 /* multiple devices could exist */
727 st_kim_devices[pdev->id] = pdev; 789 st_kim_devices[pdev->id] = pdev;
@@ -750,14 +812,14 @@ static int kim_probe(struct platform_device *pdev)
750 kim_gdata->nshutdown = pdata->nshutdown_gpio; 812 kim_gdata->nshutdown = pdata->nshutdown_gpio;
751 err = gpio_request(kim_gdata->nshutdown, "kim"); 813 err = gpio_request(kim_gdata->nshutdown, "kim");
752 if (unlikely(err)) { 814 if (unlikely(err)) {
753 pr_err(" gpio %ld request failed ", kim_gdata->nshutdown); 815 pr_err(" gpio %d request failed ", kim_gdata->nshutdown);
754 return err; 816 return err;
755 } 817 }
756 818
757 /* Configure nShutdown GPIO as output=0 */ 819 /* Configure nShutdown GPIO as output=0 */
758 err = gpio_direction_output(kim_gdata->nshutdown, 0); 820 err = gpio_direction_output(kim_gdata->nshutdown, 0);
759 if (unlikely(err)) { 821 if (unlikely(err)) {
760 pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown); 822 pr_err(" unable to configure gpio %d", kim_gdata->nshutdown);
761 return err; 823 return err;
762 } 824 }
763 /* get reference of pdev for request_firmware 825 /* get reference of pdev for request_firmware
@@ -781,8 +843,7 @@ static int kim_probe(struct platform_device *pdev)
781 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 843 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
782 if (!kim_debugfs_dir) { 844 if (!kim_debugfs_dir) {
783 pr_err(" debugfs entries creation failed "); 845 pr_err(" debugfs entries creation failed ");
784 err = -EIO; 846 return 0;
785 goto err_debugfs_dir;
786 } 847 }
787 848
788 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, 849 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
@@ -791,9 +852,6 @@ static int kim_probe(struct platform_device *pdev)
791 kim_gdata, &list_debugfs_fops); 852 kim_gdata, &list_debugfs_fops);
792 return 0; 853 return 0;
793 854
794err_debugfs_dir:
795 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
796
797err_sysfs_group: 855err_sysfs_group:
798 st_core_exit(kim_gdata->core_data); 856 st_core_exit(kim_gdata->core_data);
799 857
@@ -806,9 +864,16 @@ err_core_init:
806static int kim_remove(struct platform_device *pdev) 864static int kim_remove(struct platform_device *pdev)
807{ 865{
808 /* free the GPIOs requested */ 866 /* free the GPIOs requested */
809 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 867 struct ti_st_plat_data *pdata;
810 struct kim_data_s *kim_gdata; 868 struct kim_data_s *kim_gdata;
811 869
870 if (pdev->dev.of_node) {
871 pr_debug("use device tree data");
872 pdata = dt_pdata;
873 } else {
874 pdata = pdev->dev.platform_data;
875 }
876
812 kim_gdata = platform_get_drvdata(pdev); 877 kim_gdata = platform_get_drvdata(pdev);
813 878
814 /* Free the Bluetooth/FM/GPIO 879 /* Free the Bluetooth/FM/GPIO
@@ -826,27 +891,44 @@ static int kim_remove(struct platform_device *pdev)
826 891
827 kfree(kim_gdata); 892 kfree(kim_gdata);
828 kim_gdata = NULL; 893 kim_gdata = NULL;
894 kfree(dt_pdata);
895 dt_pdata = NULL;
896
829 return 0; 897 return 0;
830} 898}
831 899
832static int kim_suspend(struct platform_device *pdev, pm_message_t state) 900static int kim_suspend(struct platform_device *pdev, pm_message_t state)
833{ 901{
834 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 902 struct ti_st_plat_data *pdata;
903
904 if (pdev->dev.of_node) {
905 pr_debug("use device tree data");
906 pdata = dt_pdata;
907 } else {
908 pdata = pdev->dev.platform_data;
909 }
835 910
836 if (pdata->suspend) 911 if (pdata->suspend)
837 return pdata->suspend(pdev, state); 912 return pdata->suspend(pdev, state);
838 913
839 return -EOPNOTSUPP; 914 return 0;
840} 915}
841 916
842static int kim_resume(struct platform_device *pdev) 917static int kim_resume(struct platform_device *pdev)
843{ 918{
844 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 919 struct ti_st_plat_data *pdata;
920
921 if (pdev->dev.of_node) {
922 pr_debug("use device tree data");
923 pdata = dt_pdata;
924 } else {
925 pdata = pdev->dev.platform_data;
926 }
845 927
846 if (pdata->resume) 928 if (pdata->resume)
847 return pdata->resume(pdev); 929 return pdata->resume(pdev);
848 930
849 return -EOPNOTSUPP; 931 return 0;
850} 932}
851 933
852/**********************************************************************/ 934/**********************************************************************/
@@ -858,6 +940,8 @@ static struct platform_driver kim_platform_driver = {
858 .resume = kim_resume, 940 .resume = kim_resume,
859 .driver = { 941 .driver = {
860 .name = "kim", 942 .name = "kim",
943 .owner = THIS_MODULE,
944 .of_match_table = of_match_ptr(kim_of_match),
861 }, 945 },
862}; 946};
863 947
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c
index 93b4d67cc4a3..518e1b7f2f95 100644
--- a/drivers/misc/ti-st/st_ll.c
+++ b/drivers/misc/ti-st/st_ll.c
@@ -26,6 +26,7 @@
26#include <linux/ti_wilink_st.h> 26#include <linux/ti_wilink_st.h>
27 27
28/**********************************************************************/ 28/**********************************************************************/
29
29/* internal functions */ 30/* internal functions */
30static void send_ll_cmd(struct st_data_s *st_data, 31static void send_ll_cmd(struct st_data_s *st_data,
31 unsigned char cmd) 32 unsigned char cmd)
@@ -53,7 +54,13 @@ static void ll_device_want_to_sleep(struct st_data_s *st_data)
53 54
54 /* communicate to platform about chip asleep */ 55 /* communicate to platform about chip asleep */
55 kim_data = st_data->kim_data; 56 kim_data = st_data->kim_data;
56 pdata = kim_data->kim_pdev->dev.platform_data; 57 if (kim_data->kim_pdev->dev.of_node) {
58 pr_debug("use device tree data");
59 pdata = dt_pdata;
60 } else {
61 pdata = kim_data->kim_pdev->dev.platform_data;
62 }
63
57 if (pdata->chip_asleep) 64 if (pdata->chip_asleep)
58 pdata->chip_asleep(NULL); 65 pdata->chip_asleep(NULL);
59} 66}
@@ -86,7 +93,13 @@ static void ll_device_want_to_wakeup(struct st_data_s *st_data)
86 93
87 /* communicate to platform about chip wakeup */ 94 /* communicate to platform about chip wakeup */
88 kim_data = st_data->kim_data; 95 kim_data = st_data->kim_data;
89 pdata = kim_data->kim_pdev->dev.platform_data; 96 if (kim_data->kim_pdev->dev.of_node) {
97 pr_debug("use device tree data");
98 pdata = dt_pdata;
99 } else {
100 pdata = kim_data->kim_pdev->dev.platform_data;
101 }
102
90 if (pdata->chip_awake) 103 if (pdata->chip_awake)
91 pdata->chip_awake(NULL); 104 pdata->chip_awake(NULL);
92} 105}
diff --git a/drivers/misc/vmw_vmci/vmci_driver.c b/drivers/misc/vmw_vmci/vmci_driver.c
index 3dee7ae123e7..032d35cf93ca 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
113 113
114MODULE_AUTHOR("VMware, Inc."); 114MODULE_AUTHOR("VMware, Inc.");
115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface."); 115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116MODULE_VERSION("1.1.0.0-k"); 116MODULE_VERSION("1.1.1.0-k");
117MODULE_LICENSE("GPL v2"); 117MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c
index 1723a6e4f2e8..66fc9921fc85 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -218,13 +218,12 @@ static int drv_cp_harray_to_user(void __user *user_buf_uva,
218} 218}
219 219
220/* 220/*
221 * Sets up a given context for notify to work. Calls drv_map_bool_ptr() 221 * Sets up a given context for notify to work. Maps the notify
222 * which maps the notify boolean in user VA in kernel space. 222 * boolean in user VA into kernel space.
223 */ 223 */
224static int vmci_host_setup_notify(struct vmci_ctx *context, 224static int vmci_host_setup_notify(struct vmci_ctx *context,
225 unsigned long uva) 225 unsigned long uva)
226{ 226{
227 struct page *page;
228 int retval; 227 int retval;
229 228
230 if (context->notify_page) { 229 if (context->notify_page) {
@@ -243,14 +242,16 @@ static int vmci_host_setup_notify(struct vmci_ctx *context,
243 /* 242 /*
244 * Lock physical page backing a given user VA. 243 * Lock physical page backing a given user VA.
245 */ 244 */
246 retval = get_user_pages_fast(PAGE_ALIGN(uva), 1, 1, &page); 245 retval = get_user_pages_fast(uva, 1, 1, &context->notify_page);
247 if (retval != 1) 246 if (retval != 1) {
247 context->notify_page = NULL;
248 return VMCI_ERROR_GENERIC; 248 return VMCI_ERROR_GENERIC;
249 }
249 250
250 /* 251 /*
251 * Map the locked page and set up notify pointer. 252 * Map the locked page and set up notify pointer.
252 */ 253 */
253 context->notify = kmap(page) + (uva & (PAGE_SIZE - 1)); 254 context->notify = kmap(context->notify_page) + (uva & (PAGE_SIZE - 1));
254 vmci_ctx_check_signal_notify(context); 255 vmci_ctx_check_signal_notify(context);
255 256
256 return VMCI_SUCCESS; 257 return VMCI_SUCCESS;
diff --git a/drivers/misc/vmw_vmci/vmci_queue_pair.c b/drivers/misc/vmw_vmci/vmci_queue_pair.c
index 7aaaf51e1596..35f19a683822 100644
--- a/drivers/misc/vmw_vmci/vmci_queue_pair.c
+++ b/drivers/misc/vmw_vmci/vmci_queue_pair.c
@@ -370,12 +370,12 @@ static int __qp_memcpy_to_queue(struct vmci_queue *queue,
370 to_copy = size - bytes_copied; 370 to_copy = size - bytes_copied;
371 371
372 if (is_iovec) { 372 if (is_iovec) {
373 struct iovec *iov = (struct iovec *)src; 373 struct msghdr *msg = (struct msghdr *)src;
374 int err; 374 int err;
375 375
376 /* The iovec will track bytes_copied internally. */ 376 /* The iovec will track bytes_copied internally. */
377 err = memcpy_fromiovec((u8 *)va + page_offset, 377 err = memcpy_from_msg((u8 *)va + page_offset,
378 iov, to_copy); 378 msg, to_copy);
379 if (err != 0) { 379 if (err != 0) {
380 if (kernel_if->host) 380 if (kernel_if->host)
381 kunmap(kernel_if->u.h.page[page_index]); 381 kunmap(kernel_if->u.h.page[page_index]);
@@ -580,7 +580,7 @@ static int qp_memcpy_from_queue(void *dest,
580 */ 580 */
581static int qp_memcpy_to_queue_iov(struct vmci_queue *queue, 581static int qp_memcpy_to_queue_iov(struct vmci_queue *queue,
582 u64 queue_offset, 582 u64 queue_offset,
583 const void *src, 583 const void *msg,
584 size_t src_offset, size_t size) 584 size_t src_offset, size_t size)
585{ 585{
586 586
@@ -588,7 +588,7 @@ static int qp_memcpy_to_queue_iov(struct vmci_queue *queue,
588 * We ignore src_offset because src is really a struct iovec * and will 588 * We ignore src_offset because src is really a struct iovec * and will
589 * maintain offset internally. 589 * maintain offset internally.
590 */ 590 */
591 return __qp_memcpy_to_queue(queue, queue_offset, src, size, true); 591 return __qp_memcpy_to_queue(queue, queue_offset, msg, size, true);
592} 592}
593 593
594/* 594/*
@@ -3223,13 +3223,13 @@ EXPORT_SYMBOL_GPL(vmci_qpair_peek);
3223 * of bytes enqueued or < 0 on error. 3223 * of bytes enqueued or < 0 on error.
3224 */ 3224 */
3225ssize_t vmci_qpair_enquev(struct vmci_qp *qpair, 3225ssize_t vmci_qpair_enquev(struct vmci_qp *qpair,
3226 void *iov, 3226 struct msghdr *msg,
3227 size_t iov_size, 3227 size_t iov_size,
3228 int buf_type) 3228 int buf_type)
3229{ 3229{
3230 ssize_t result; 3230 ssize_t result;
3231 3231
3232 if (!qpair || !iov) 3232 if (!qpair)
3233 return VMCI_ERROR_INVALID_ARGS; 3233 return VMCI_ERROR_INVALID_ARGS;
3234 3234
3235 qp_lock(qpair); 3235 qp_lock(qpair);
@@ -3238,7 +3238,7 @@ ssize_t vmci_qpair_enquev(struct vmci_qp *qpair,
3238 result = qp_enqueue_locked(qpair->produce_q, 3238 result = qp_enqueue_locked(qpair->produce_q,
3239 qpair->consume_q, 3239 qpair->consume_q,
3240 qpair->produce_q_size, 3240 qpair->produce_q_size,
3241 iov, iov_size, 3241 msg, iov_size,
3242 qp_memcpy_to_queue_iov); 3242 qp_memcpy_to_queue_iov);
3243 3243
3244 if (result == VMCI_ERROR_QUEUEPAIR_NOT_READY && 3244 if (result == VMCI_ERROR_QUEUEPAIR_NOT_READY &&