@@ -15,6 +15,7 @@
#include <string.h>
#include <interrupt.h>
#include <asm/arch_def.h>
+#include <asm/time.h>
#include <css.h>
@@ -68,3 +69,63 @@ out:
scn, scn_found, dev_found);
return schid;
}
+
+int css_enable(int schid)
+{
+ struct pmcw *pmcw = &schib.pmcw;
+ int retry_count = 0;
+ int cc;
+
+ /* Read the SCHIB for this subchannel */
+ cc = stsch(schid, &schib);
+ if (cc) {
+ report_info("stsch: sch %08x failed with cc=%d", schid, cc);
+ return cc;
+ }
+
+ if (pmcw->flags & PMCW_ENABLE) {
+ report_info("stsch: sch %08x already enabled", schid);
+ return 0;
+ }
+
+retry:
+ /* Update the SCHIB to enable the channel */
+ pmcw->flags |= PMCW_ENABLE;
+
+ /* Tell the CSS we want to modify the subchannel */
+ cc = msch(schid, &schib);
+ if (cc) {
+ /*
+ * If the subchannel is status pending or
+ * if a function is in progress,
+ * we consider both cases as errors.
+ */
+ report_info("msch: sch %08x failed with cc=%d", schid, cc);
+ return cc;
+ }
+
+ /*
+ * Read the SCHIB again to verify the enablement
+ */
+ cc = stsch(schid, &schib);
+ if (cc) {
+ report_info("stsch: updating sch %08x failed with cc=%d",
+ schid, cc);
+ return cc;
+ }
+
+ if (pmcw->flags & PMCW_ENABLE) {
+ report_info("stsch: sch %08x enabled after %d retries",
+ schid, retry_count);
+ return 0;
+ }
+
+ if (retry_count++ < MAX_ENABLE_RETRIES) {
+ mdelay(10); /* the hardware was not ready, give it some time */
+ goto retry;
+ }
+
+ report_info("msch: enabling sch %08x failed after %d retries. pmcw flags: %x",
+ schid, retry_count, pmcw->flags);
+ return -1;
+}
@@ -31,11 +31,26 @@ static void test_enumerate(void)
report(0, "No I/O device found");
}
+static void test_enable(void)
+{
+ int cc;
+
+ if (!test_device_sid) {
+ report_skip("No device");
+ return;
+ }
+
+ cc = css_enable(test_device_sid);
+
+ report(cc == 0, "Enable subchannel %08x", test_device_sid);
+}
+
static struct {
const char *name;
void (*func)(void);
} tests[] = {
{ "enumerate (stsch)", test_enumerate },
+ { "enable (msch)", test_enable },
{ NULL, NULL }
};