xref: /linux/drivers/s390/cio/eadm_sch.c (revision 724117b77bbe2b28f27728d58a432ed22630e33f)
1*724117b7SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2eadb86abSSebastian Ott /*
3eadb86abSSebastian Ott  * Driver for s390 eadm subchannels
4eadb86abSSebastian Ott  *
5eadb86abSSebastian Ott  * Copyright IBM Corp. 2012
6eadb86abSSebastian Ott  * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
7eadb86abSSebastian Ott  */
8eadb86abSSebastian Ott 
92e73c2cfSSebastian Ott #include <linux/kernel_stat.h>
106aa2677aSSebastian Ott #include <linux/completion.h>
11eadb86abSSebastian Ott #include <linux/workqueue.h>
12eadb86abSSebastian Ott #include <linux/spinlock.h>
13eadb86abSSebastian Ott #include <linux/device.h>
14eadb86abSSebastian Ott #include <linux/module.h>
15eadb86abSSebastian Ott #include <linux/timer.h>
16eadb86abSSebastian Ott #include <linux/slab.h>
17eadb86abSSebastian Ott #include <linux/list.h>
18eadb86abSSebastian Ott 
19eadb86abSSebastian Ott #include <asm/css_chars.h>
20eadb86abSSebastian Ott #include <asm/debug.h>
21eadb86abSSebastian Ott #include <asm/isc.h>
22eadb86abSSebastian Ott #include <asm/cio.h>
23eadb86abSSebastian Ott #include <asm/scsw.h>
24eadb86abSSebastian Ott #include <asm/eadm.h>
25eadb86abSSebastian Ott 
26eadb86abSSebastian Ott #include "eadm_sch.h"
27eadb86abSSebastian Ott #include "ioasm.h"
28eadb86abSSebastian Ott #include "cio.h"
29eadb86abSSebastian Ott #include "css.h"
30eadb86abSSebastian Ott #include "orb.h"
31eadb86abSSebastian Ott 
32eadb86abSSebastian Ott MODULE_DESCRIPTION("driver for s390 eadm subchannels");
33eadb86abSSebastian Ott MODULE_LICENSE("GPL");
34eadb86abSSebastian Ott 
35e2578b82SSebastian Ott #define EADM_TIMEOUT (7 * HZ)
36eadb86abSSebastian Ott static DEFINE_SPINLOCK(list_lock);
37eadb86abSSebastian Ott static LIST_HEAD(eadm_list);
38eadb86abSSebastian Ott 
39eadb86abSSebastian Ott static debug_info_t *eadm_debug;
40eadb86abSSebastian Ott 
41eadb86abSSebastian Ott #define EADM_LOG(imp, txt) do {					\
42eadb86abSSebastian Ott 		debug_text_event(eadm_debug, imp, txt);		\
43eadb86abSSebastian Ott 	} while (0)
44eadb86abSSebastian Ott 
45eadb86abSSebastian Ott static void EADM_LOG_HEX(int level, void *data, int length)
46eadb86abSSebastian Ott {
47eadb86abSSebastian Ott 	debug_event(eadm_debug, level, data, length);
48eadb86abSSebastian Ott }
49eadb86abSSebastian Ott 
50eadb86abSSebastian Ott static void orb_init(union orb *orb)
51eadb86abSSebastian Ott {
52eadb86abSSebastian Ott 	memset(orb, 0, sizeof(union orb));
53eadb86abSSebastian Ott 	orb->eadm.compat1 = 1;
54eadb86abSSebastian Ott 	orb->eadm.compat2 = 1;
55eadb86abSSebastian Ott 	orb->eadm.fmt = 1;
56eadb86abSSebastian Ott 	orb->eadm.x = 1;
57eadb86abSSebastian Ott }
58eadb86abSSebastian Ott 
59eadb86abSSebastian Ott static int eadm_subchannel_start(struct subchannel *sch, struct aob *aob)
60eadb86abSSebastian Ott {
61eadb86abSSebastian Ott 	union orb *orb = &get_eadm_private(sch)->orb;
62eadb86abSSebastian Ott 	int cc;
63eadb86abSSebastian Ott 
64eadb86abSSebastian Ott 	orb_init(orb);
65eadb86abSSebastian Ott 	orb->eadm.aob = (u32)__pa(aob);
66eadb86abSSebastian Ott 	orb->eadm.intparm = (u32)(addr_t)sch;
67eadb86abSSebastian Ott 	orb->eadm.key = PAGE_DEFAULT_KEY >> 4;
68eadb86abSSebastian Ott 
69eadb86abSSebastian Ott 	EADM_LOG(6, "start");
70eadb86abSSebastian Ott 	EADM_LOG_HEX(6, &sch->schid, sizeof(sch->schid));
71eadb86abSSebastian Ott 
72eadb86abSSebastian Ott 	cc = ssch(sch->schid, orb);
73eadb86abSSebastian Ott 	switch (cc) {
74eadb86abSSebastian Ott 	case 0:
75eadb86abSSebastian Ott 		sch->schib.scsw.eadm.actl |= SCSW_ACTL_START_PEND;
76eadb86abSSebastian Ott 		break;
77eadb86abSSebastian Ott 	case 1:		/* status pending */
78eadb86abSSebastian Ott 	case 2:		/* busy */
79eadb86abSSebastian Ott 		return -EBUSY;
80eadb86abSSebastian Ott 	case 3:		/* not operational */
81eadb86abSSebastian Ott 		return -ENODEV;
82eadb86abSSebastian Ott 	}
83eadb86abSSebastian Ott 	return 0;
84eadb86abSSebastian Ott }
85eadb86abSSebastian Ott 
86eadb86abSSebastian Ott static int eadm_subchannel_clear(struct subchannel *sch)
87eadb86abSSebastian Ott {
88eadb86abSSebastian Ott 	int cc;
89eadb86abSSebastian Ott 
90eadb86abSSebastian Ott 	cc = csch(sch->schid);
91eadb86abSSebastian Ott 	if (cc)
92eadb86abSSebastian Ott 		return -ENODEV;
93eadb86abSSebastian Ott 
94eadb86abSSebastian Ott 	sch->schib.scsw.eadm.actl |= SCSW_ACTL_CLEAR_PEND;
95eadb86abSSebastian Ott 	return 0;
96eadb86abSSebastian Ott }
97eadb86abSSebastian Ott 
98846d0c6fSKees Cook static void eadm_subchannel_timeout(struct timer_list *t)
99eadb86abSSebastian Ott {
100846d0c6fSKees Cook 	struct eadm_private *private = from_timer(private, t, timer);
101846d0c6fSKees Cook 	struct subchannel *sch = private->sch;
102eadb86abSSebastian Ott 
103eadb86abSSebastian Ott 	spin_lock_irq(sch->lock);
104eadb86abSSebastian Ott 	EADM_LOG(1, "timeout");
105eadb86abSSebastian Ott 	EADM_LOG_HEX(1, &sch->schid, sizeof(sch->schid));
106eadb86abSSebastian Ott 	if (eadm_subchannel_clear(sch))
107eadb86abSSebastian Ott 		EADM_LOG(0, "clear failed");
108eadb86abSSebastian Ott 	spin_unlock_irq(sch->lock);
109eadb86abSSebastian Ott }
110eadb86abSSebastian Ott 
111eadb86abSSebastian Ott static void eadm_subchannel_set_timeout(struct subchannel *sch, int expires)
112eadb86abSSebastian Ott {
113eadb86abSSebastian Ott 	struct eadm_private *private = get_eadm_private(sch);
114eadb86abSSebastian Ott 
115eadb86abSSebastian Ott 	if (expires == 0) {
116eadb86abSSebastian Ott 		del_timer(&private->timer);
117eadb86abSSebastian Ott 		return;
118eadb86abSSebastian Ott 	}
119eadb86abSSebastian Ott 	if (timer_pending(&private->timer)) {
120eadb86abSSebastian Ott 		if (mod_timer(&private->timer, jiffies + expires))
121eadb86abSSebastian Ott 			return;
122eadb86abSSebastian Ott 	}
123eadb86abSSebastian Ott 	private->timer.expires = jiffies + expires;
124eadb86abSSebastian Ott 	add_timer(&private->timer);
125eadb86abSSebastian Ott }
126eadb86abSSebastian Ott 
127eadb86abSSebastian Ott static void eadm_subchannel_irq(struct subchannel *sch)
128eadb86abSSebastian Ott {
129eadb86abSSebastian Ott 	struct eadm_private *private = get_eadm_private(sch);
130eadb86abSSebastian Ott 	struct eadm_scsw *scsw = &sch->schib.scsw.eadm;
1310bf7fcf1SChristoph Lameter 	struct irb *irb = this_cpu_ptr(&cio_irb);
1322a842acaSChristoph Hellwig 	blk_status_t error = BLK_STS_OK;
133eadb86abSSebastian Ott 
134eadb86abSSebastian Ott 	EADM_LOG(6, "irq");
135eadb86abSSebastian Ott 	EADM_LOG_HEX(6, irb, sizeof(*irb));
136eadb86abSSebastian Ott 
137420f42ecSHeiko Carstens 	inc_irq_stat(IRQIO_ADM);
1382e73c2cfSSebastian Ott 
139eadb86abSSebastian Ott 	if ((scsw->stctl & (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))
140eadb86abSSebastian Ott 	    && scsw->eswf == 1 && irb->esw.eadm.erw.r)
1412a842acaSChristoph Hellwig 		error = BLK_STS_IOERR;
142eadb86abSSebastian Ott 
143eadb86abSSebastian Ott 	if (scsw->fctl & SCSW_FCTL_CLEAR_FUNC)
1442a842acaSChristoph Hellwig 		error = BLK_STS_TIMEOUT;
145eadb86abSSebastian Ott 
146eadb86abSSebastian Ott 	eadm_subchannel_set_timeout(sch, 0);
147eadb86abSSebastian Ott 
148eadb86abSSebastian Ott 	if (private->state != EADM_BUSY) {
149eadb86abSSebastian Ott 		EADM_LOG(1, "irq unsol");
150eadb86abSSebastian Ott 		EADM_LOG_HEX(1, irb, sizeof(*irb));
151eadb86abSSebastian Ott 		private->state = EADM_NOT_OPER;
152eadb86abSSebastian Ott 		css_sched_sch_todo(sch, SCH_TODO_EVAL);
153eadb86abSSebastian Ott 		return;
154eadb86abSSebastian Ott 	}
155eadb86abSSebastian Ott 	scm_irq_handler((struct aob *)(unsigned long)scsw->aob, error);
156eadb86abSSebastian Ott 	private->state = EADM_IDLE;
1576aa2677aSSebastian Ott 
1586aa2677aSSebastian Ott 	if (private->completion)
1596aa2677aSSebastian Ott 		complete(private->completion);
160eadb86abSSebastian Ott }
161eadb86abSSebastian Ott 
162eadb86abSSebastian Ott static struct subchannel *eadm_get_idle_sch(void)
163eadb86abSSebastian Ott {
164eadb86abSSebastian Ott 	struct eadm_private *private;
165eadb86abSSebastian Ott 	struct subchannel *sch;
166eadb86abSSebastian Ott 	unsigned long flags;
167eadb86abSSebastian Ott 
168eadb86abSSebastian Ott 	spin_lock_irqsave(&list_lock, flags);
169eadb86abSSebastian Ott 	list_for_each_entry(private, &eadm_list, head) {
170eadb86abSSebastian Ott 		sch = private->sch;
171eadb86abSSebastian Ott 		spin_lock(sch->lock);
172eadb86abSSebastian Ott 		if (private->state == EADM_IDLE) {
173eadb86abSSebastian Ott 			private->state = EADM_BUSY;
174eadb86abSSebastian Ott 			list_move_tail(&private->head, &eadm_list);
175eadb86abSSebastian Ott 			spin_unlock(sch->lock);
176eadb86abSSebastian Ott 			spin_unlock_irqrestore(&list_lock, flags);
177eadb86abSSebastian Ott 
178eadb86abSSebastian Ott 			return sch;
179eadb86abSSebastian Ott 		}
180eadb86abSSebastian Ott 		spin_unlock(sch->lock);
181eadb86abSSebastian Ott 	}
182eadb86abSSebastian Ott 	spin_unlock_irqrestore(&list_lock, flags);
183eadb86abSSebastian Ott 
184eadb86abSSebastian Ott 	return NULL;
185eadb86abSSebastian Ott }
186eadb86abSSebastian Ott 
187605c3698SSebastian Ott int eadm_start_aob(struct aob *aob)
188eadb86abSSebastian Ott {
189eadb86abSSebastian Ott 	struct eadm_private *private;
190eadb86abSSebastian Ott 	struct subchannel *sch;
191eadb86abSSebastian Ott 	unsigned long flags;
192eadb86abSSebastian Ott 	int ret;
193eadb86abSSebastian Ott 
194eadb86abSSebastian Ott 	sch = eadm_get_idle_sch();
195eadb86abSSebastian Ott 	if (!sch)
196eadb86abSSebastian Ott 		return -EBUSY;
197eadb86abSSebastian Ott 
198eadb86abSSebastian Ott 	spin_lock_irqsave(sch->lock, flags);
199eadb86abSSebastian Ott 	eadm_subchannel_set_timeout(sch, EADM_TIMEOUT);
200eadb86abSSebastian Ott 	ret = eadm_subchannel_start(sch, aob);
201eadb86abSSebastian Ott 	if (!ret)
202eadb86abSSebastian Ott 		goto out_unlock;
203eadb86abSSebastian Ott 
204eadb86abSSebastian Ott 	/* Handle start subchannel failure. */
205eadb86abSSebastian Ott 	eadm_subchannel_set_timeout(sch, 0);
206eadb86abSSebastian Ott 	private = get_eadm_private(sch);
207eadb86abSSebastian Ott 	private->state = EADM_NOT_OPER;
208eadb86abSSebastian Ott 	css_sched_sch_todo(sch, SCH_TODO_EVAL);
209eadb86abSSebastian Ott 
210eadb86abSSebastian Ott out_unlock:
211eadb86abSSebastian Ott 	spin_unlock_irqrestore(sch->lock, flags);
212eadb86abSSebastian Ott 
213eadb86abSSebastian Ott 	return ret;
214eadb86abSSebastian Ott }
215605c3698SSebastian Ott EXPORT_SYMBOL_GPL(eadm_start_aob);
216eadb86abSSebastian Ott 
217eadb86abSSebastian Ott static int eadm_subchannel_probe(struct subchannel *sch)
218eadb86abSSebastian Ott {
219eadb86abSSebastian Ott 	struct eadm_private *private;
220eadb86abSSebastian Ott 	int ret;
221eadb86abSSebastian Ott 
222eadb86abSSebastian Ott 	private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
223eadb86abSSebastian Ott 	if (!private)
224eadb86abSSebastian Ott 		return -ENOMEM;
225eadb86abSSebastian Ott 
226eadb86abSSebastian Ott 	INIT_LIST_HEAD(&private->head);
227846d0c6fSKees Cook 	timer_setup(&private->timer, eadm_subchannel_timeout, 0);
228eadb86abSSebastian Ott 
229eadb86abSSebastian Ott 	spin_lock_irq(sch->lock);
230eadb86abSSebastian Ott 	set_eadm_private(sch, private);
231eadb86abSSebastian Ott 	private->state = EADM_IDLE;
232eadb86abSSebastian Ott 	private->sch = sch;
233eadb86abSSebastian Ott 	sch->isc = EADM_SCH_ISC;
234eadb86abSSebastian Ott 	ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
235eadb86abSSebastian Ott 	if (ret) {
236eadb86abSSebastian Ott 		set_eadm_private(sch, NULL);
237eadb86abSSebastian Ott 		spin_unlock_irq(sch->lock);
238eadb86abSSebastian Ott 		kfree(private);
239eadb86abSSebastian Ott 		goto out;
240eadb86abSSebastian Ott 	}
241eadb86abSSebastian Ott 	spin_unlock_irq(sch->lock);
242eadb86abSSebastian Ott 
243eadb86abSSebastian Ott 	spin_lock_irq(&list_lock);
244eadb86abSSebastian Ott 	list_add(&private->head, &eadm_list);
245eadb86abSSebastian Ott 	spin_unlock_irq(&list_lock);
246eadb86abSSebastian Ott 
247eadb86abSSebastian Ott 	if (dev_get_uevent_suppress(&sch->dev)) {
248eadb86abSSebastian Ott 		dev_set_uevent_suppress(&sch->dev, 0);
249eadb86abSSebastian Ott 		kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
250eadb86abSSebastian Ott 	}
251eadb86abSSebastian Ott out:
252eadb86abSSebastian Ott 	return ret;
253eadb86abSSebastian Ott }
254eadb86abSSebastian Ott 
255eadb86abSSebastian Ott static void eadm_quiesce(struct subchannel *sch)
256eadb86abSSebastian Ott {
2576aa2677aSSebastian Ott 	struct eadm_private *private = get_eadm_private(sch);
2586aa2677aSSebastian Ott 	DECLARE_COMPLETION_ONSTACK(completion);
259eadb86abSSebastian Ott 	int ret;
260eadb86abSSebastian Ott 
261eadb86abSSebastian Ott 	spin_lock_irq(sch->lock);
2626aa2677aSSebastian Ott 	if (private->state != EADM_BUSY)
2636aa2677aSSebastian Ott 		goto disable;
2646aa2677aSSebastian Ott 
2656aa2677aSSebastian Ott 	if (eadm_subchannel_clear(sch))
2666aa2677aSSebastian Ott 		goto disable;
2676aa2677aSSebastian Ott 
2686aa2677aSSebastian Ott 	private->completion = &completion;
269eadb86abSSebastian Ott 	spin_unlock_irq(sch->lock);
2706aa2677aSSebastian Ott 
2716aa2677aSSebastian Ott 	wait_for_completion_io(&completion);
2726aa2677aSSebastian Ott 
2736aa2677aSSebastian Ott 	spin_lock_irq(sch->lock);
2746aa2677aSSebastian Ott 	private->completion = NULL;
2756aa2677aSSebastian Ott 
2766aa2677aSSebastian Ott disable:
2776aa2677aSSebastian Ott 	eadm_subchannel_set_timeout(sch, 0);
2786aa2677aSSebastian Ott 	do {
2796aa2677aSSebastian Ott 		ret = cio_disable_subchannel(sch);
280eadb86abSSebastian Ott 	} while (ret == -EBUSY);
2816aa2677aSSebastian Ott 
2826aa2677aSSebastian Ott 	spin_unlock_irq(sch->lock);
283eadb86abSSebastian Ott }
284eadb86abSSebastian Ott 
285eadb86abSSebastian Ott static int eadm_subchannel_remove(struct subchannel *sch)
286eadb86abSSebastian Ott {
287eadb86abSSebastian Ott 	struct eadm_private *private = get_eadm_private(sch);
288eadb86abSSebastian Ott 
289eadb86abSSebastian Ott 	spin_lock_irq(&list_lock);
290eadb86abSSebastian Ott 	list_del(&private->head);
291eadb86abSSebastian Ott 	spin_unlock_irq(&list_lock);
292eadb86abSSebastian Ott 
293eadb86abSSebastian Ott 	eadm_quiesce(sch);
294eadb86abSSebastian Ott 
295eadb86abSSebastian Ott 	spin_lock_irq(sch->lock);
296eadb86abSSebastian Ott 	set_eadm_private(sch, NULL);
297eadb86abSSebastian Ott 	spin_unlock_irq(sch->lock);
298eadb86abSSebastian Ott 
299eadb86abSSebastian Ott 	kfree(private);
300eadb86abSSebastian Ott 
301eadb86abSSebastian Ott 	return 0;
302eadb86abSSebastian Ott }
303eadb86abSSebastian Ott 
304eadb86abSSebastian Ott static void eadm_subchannel_shutdown(struct subchannel *sch)
305eadb86abSSebastian Ott {
306eadb86abSSebastian Ott 	eadm_quiesce(sch);
307eadb86abSSebastian Ott }
308eadb86abSSebastian Ott 
309eadb86abSSebastian Ott static int eadm_subchannel_freeze(struct subchannel *sch)
310eadb86abSSebastian Ott {
311eadb86abSSebastian Ott 	return cio_disable_subchannel(sch);
312eadb86abSSebastian Ott }
313eadb86abSSebastian Ott 
314eadb86abSSebastian Ott static int eadm_subchannel_restore(struct subchannel *sch)
315eadb86abSSebastian Ott {
316eadb86abSSebastian Ott 	return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
317eadb86abSSebastian Ott }
318eadb86abSSebastian Ott 
319eadb86abSSebastian Ott /**
320eadb86abSSebastian Ott  * eadm_subchannel_sch_event - process subchannel event
321eadb86abSSebastian Ott  * @sch: subchannel
322eadb86abSSebastian Ott  * @process: non-zero if function is called in process context
323eadb86abSSebastian Ott  *
324eadb86abSSebastian Ott  * An unspecified event occurred for this subchannel. Adjust data according
325eadb86abSSebastian Ott  * to the current operational state of the subchannel. Return zero when the
326eadb86abSSebastian Ott  * event has been handled sufficiently or -EAGAIN when this function should
327eadb86abSSebastian Ott  * be called again in process context.
328eadb86abSSebastian Ott  */
329eadb86abSSebastian Ott static int eadm_subchannel_sch_event(struct subchannel *sch, int process)
330eadb86abSSebastian Ott {
331eadb86abSSebastian Ott 	struct eadm_private *private;
332eadb86abSSebastian Ott 	unsigned long flags;
333eadb86abSSebastian Ott 
334eadb86abSSebastian Ott 	spin_lock_irqsave(sch->lock, flags);
335eadb86abSSebastian Ott 	if (!device_is_registered(&sch->dev))
336eadb86abSSebastian Ott 		goto out_unlock;
337eadb86abSSebastian Ott 
338eadb86abSSebastian Ott 	if (work_pending(&sch->todo_work))
339eadb86abSSebastian Ott 		goto out_unlock;
340eadb86abSSebastian Ott 
341eadb86abSSebastian Ott 	if (cio_update_schib(sch)) {
342eadb86abSSebastian Ott 		css_sched_sch_todo(sch, SCH_TODO_UNREG);
343eadb86abSSebastian Ott 		goto out_unlock;
344eadb86abSSebastian Ott 	}
345eadb86abSSebastian Ott 	private = get_eadm_private(sch);
346eadb86abSSebastian Ott 	if (private->state == EADM_NOT_OPER)
347eadb86abSSebastian Ott 		private->state = EADM_IDLE;
348eadb86abSSebastian Ott 
349eadb86abSSebastian Ott out_unlock:
350eadb86abSSebastian Ott 	spin_unlock_irqrestore(sch->lock, flags);
351eadb86abSSebastian Ott 
352b2f4de8bSPeter Senna Tschudin 	return 0;
353eadb86abSSebastian Ott }
354eadb86abSSebastian Ott 
355eadb86abSSebastian Ott static struct css_device_id eadm_subchannel_ids[] = {
356eadb86abSSebastian Ott 	{ .match_flags = 0x1, .type = SUBCHANNEL_TYPE_ADM, },
357eadb86abSSebastian Ott 	{ /* end of list */ },
358eadb86abSSebastian Ott };
359eadb86abSSebastian Ott MODULE_DEVICE_TABLE(css, eadm_subchannel_ids);
360eadb86abSSebastian Ott 
361eadb86abSSebastian Ott static struct css_driver eadm_subchannel_driver = {
362eadb86abSSebastian Ott 	.drv = {
363eadb86abSSebastian Ott 		.name = "eadm_subchannel",
364eadb86abSSebastian Ott 		.owner = THIS_MODULE,
365eadb86abSSebastian Ott 	},
366eadb86abSSebastian Ott 	.subchannel_type = eadm_subchannel_ids,
367eadb86abSSebastian Ott 	.irq = eadm_subchannel_irq,
368eadb86abSSebastian Ott 	.probe = eadm_subchannel_probe,
369eadb86abSSebastian Ott 	.remove = eadm_subchannel_remove,
370eadb86abSSebastian Ott 	.shutdown = eadm_subchannel_shutdown,
371eadb86abSSebastian Ott 	.sch_event = eadm_subchannel_sch_event,
372eadb86abSSebastian Ott 	.freeze = eadm_subchannel_freeze,
373eadb86abSSebastian Ott 	.thaw = eadm_subchannel_restore,
374eadb86abSSebastian Ott 	.restore = eadm_subchannel_restore,
375eadb86abSSebastian Ott };
376eadb86abSSebastian Ott 
377eadb86abSSebastian Ott static int __init eadm_sch_init(void)
378eadb86abSSebastian Ott {
379eadb86abSSebastian Ott 	int ret;
380eadb86abSSebastian Ott 
381eadb86abSSebastian Ott 	if (!css_general_characteristics.eadm)
382eadb86abSSebastian Ott 		return -ENXIO;
383eadb86abSSebastian Ott 
384eadb86abSSebastian Ott 	eadm_debug = debug_register("eadm_log", 16, 1, 16);
385eadb86abSSebastian Ott 	if (!eadm_debug)
386eadb86abSSebastian Ott 		return -ENOMEM;
387eadb86abSSebastian Ott 
388eadb86abSSebastian Ott 	debug_register_view(eadm_debug, &debug_hex_ascii_view);
389eadb86abSSebastian Ott 	debug_set_level(eadm_debug, 2);
390eadb86abSSebastian Ott 
391eadb86abSSebastian Ott 	isc_register(EADM_SCH_ISC);
392eadb86abSSebastian Ott 	ret = css_driver_register(&eadm_subchannel_driver);
393eadb86abSSebastian Ott 	if (ret)
394eadb86abSSebastian Ott 		goto cleanup;
395eadb86abSSebastian Ott 
396eadb86abSSebastian Ott 	return ret;
397eadb86abSSebastian Ott 
398eadb86abSSebastian Ott cleanup:
399eadb86abSSebastian Ott 	isc_unregister(EADM_SCH_ISC);
400eadb86abSSebastian Ott 	debug_unregister(eadm_debug);
401eadb86abSSebastian Ott 	return ret;
402eadb86abSSebastian Ott }
403eadb86abSSebastian Ott 
404eadb86abSSebastian Ott static void __exit eadm_sch_exit(void)
405eadb86abSSebastian Ott {
406eadb86abSSebastian Ott 	css_driver_unregister(&eadm_subchannel_driver);
407eadb86abSSebastian Ott 	isc_unregister(EADM_SCH_ISC);
408eadb86abSSebastian Ott 	debug_unregister(eadm_debug);
409eadb86abSSebastian Ott }
410eadb86abSSebastian Ott module_init(eadm_sch_init);
411eadb86abSSebastian Ott module_exit(eadm_sch_exit);
412