2 * Driver for s390 eadm subchannels
4 * Copyright IBM Corp. 2012
5 * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
8 #include <linux/kernel_stat.h>
9 #include <linux/completion.h>
10 #include <linux/workqueue.h>
11 #include <linux/spinlock.h>
12 #include <linux/device.h>
13 #include <linux/module.h>
14 #include <linux/timer.h>
15 #include <linux/slab.h>
16 #include <linux/list.h>
18 #include <asm/css_chars.h>
19 #include <asm/debug.h>
31 MODULE_DESCRIPTION("driver for s390 eadm subchannels");
32 MODULE_LICENSE("GPL");
34 #define EADM_TIMEOUT (5 * HZ)
35 static DEFINE_SPINLOCK(list_lock
);
36 static LIST_HEAD(eadm_list
);
38 static debug_info_t
*eadm_debug
;
40 #define EADM_LOG(imp, txt) do { \
41 debug_text_event(eadm_debug, imp, txt); \
44 static void EADM_LOG_HEX(int level
, void *data
, int length
)
46 if (!debug_level_enabled(eadm_debug
, level
))
49 debug_event(eadm_debug
, level
, data
, length
);
50 length
-= eadm_debug
->buf_size
;
51 data
+= eadm_debug
->buf_size
;
55 static void orb_init(union orb
*orb
)
57 memset(orb
, 0, sizeof(union orb
));
58 orb
->eadm
.compat1
= 1;
59 orb
->eadm
.compat2
= 1;
64 static int eadm_subchannel_start(struct subchannel
*sch
, struct aob
*aob
)
66 union orb
*orb
= &get_eadm_private(sch
)->orb
;
70 orb
->eadm
.aob
= (u32
)__pa(aob
);
71 orb
->eadm
.intparm
= (u32
)(addr_t
)sch
;
72 orb
->eadm
.key
= PAGE_DEFAULT_KEY
>> 4;
75 EADM_LOG_HEX(6, &sch
->schid
, sizeof(sch
->schid
));
77 cc
= ssch(sch
->schid
, orb
);
80 sch
->schib
.scsw
.eadm
.actl
|= SCSW_ACTL_START_PEND
;
82 case 1: /* status pending */
85 case 3: /* not operational */
91 static int eadm_subchannel_clear(struct subchannel
*sch
)
95 cc
= csch(sch
->schid
);
99 sch
->schib
.scsw
.eadm
.actl
|= SCSW_ACTL_CLEAR_PEND
;
103 static void eadm_subchannel_timeout(unsigned long data
)
105 struct subchannel
*sch
= (struct subchannel
*) data
;
107 spin_lock_irq(sch
->lock
);
108 EADM_LOG(1, "timeout");
109 EADM_LOG_HEX(1, &sch
->schid
, sizeof(sch
->schid
));
110 if (eadm_subchannel_clear(sch
))
111 EADM_LOG(0, "clear failed");
112 spin_unlock_irq(sch
->lock
);
115 static void eadm_subchannel_set_timeout(struct subchannel
*sch
, int expires
)
117 struct eadm_private
*private = get_eadm_private(sch
);
120 del_timer(&private->timer
);
123 if (timer_pending(&private->timer
)) {
124 if (mod_timer(&private->timer
, jiffies
+ expires
))
127 private->timer
.function
= eadm_subchannel_timeout
;
128 private->timer
.data
= (unsigned long) sch
;
129 private->timer
.expires
= jiffies
+ expires
;
130 add_timer(&private->timer
);
133 static void eadm_subchannel_irq(struct subchannel
*sch
)
135 struct eadm_private
*private = get_eadm_private(sch
);
136 struct eadm_scsw
*scsw
= &sch
->schib
.scsw
.eadm
;
137 struct irb
*irb
= (struct irb
*)&S390_lowcore
.irb
;
141 EADM_LOG_HEX(6, irb
, sizeof(*irb
));
143 inc_irq_stat(IRQIO_ADM
);
145 if ((scsw
->stctl
& (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))
146 && scsw
->eswf
== 1 && irb
->esw
.eadm
.erw
.r
)
149 if (scsw
->fctl
& SCSW_FCTL_CLEAR_FUNC
)
152 eadm_subchannel_set_timeout(sch
, 0);
154 if (private->state
!= EADM_BUSY
) {
155 EADM_LOG(1, "irq unsol");
156 EADM_LOG_HEX(1, irb
, sizeof(*irb
));
157 private->state
= EADM_NOT_OPER
;
158 css_sched_sch_todo(sch
, SCH_TODO_EVAL
);
161 scm_irq_handler((struct aob
*)(unsigned long)scsw
->aob
, error
);
162 private->state
= EADM_IDLE
;
164 if (private->completion
)
165 complete(private->completion
);
168 static struct subchannel
*eadm_get_idle_sch(void)
170 struct eadm_private
*private;
171 struct subchannel
*sch
;
174 spin_lock_irqsave(&list_lock
, flags
);
175 list_for_each_entry(private, &eadm_list
, head
) {
177 spin_lock(sch
->lock
);
178 if (private->state
== EADM_IDLE
) {
179 private->state
= EADM_BUSY
;
180 list_move_tail(&private->head
, &eadm_list
);
181 spin_unlock(sch
->lock
);
182 spin_unlock_irqrestore(&list_lock
, flags
);
186 spin_unlock(sch
->lock
);
188 spin_unlock_irqrestore(&list_lock
, flags
);
193 int eadm_start_aob(struct aob
*aob
)
195 struct eadm_private
*private;
196 struct subchannel
*sch
;
200 sch
= eadm_get_idle_sch();
204 spin_lock_irqsave(sch
->lock
, flags
);
205 eadm_subchannel_set_timeout(sch
, EADM_TIMEOUT
);
206 ret
= eadm_subchannel_start(sch
, aob
);
210 /* Handle start subchannel failure. */
211 eadm_subchannel_set_timeout(sch
, 0);
212 private = get_eadm_private(sch
);
213 private->state
= EADM_NOT_OPER
;
214 css_sched_sch_todo(sch
, SCH_TODO_EVAL
);
217 spin_unlock_irqrestore(sch
->lock
, flags
);
221 EXPORT_SYMBOL_GPL(eadm_start_aob
);
223 static int eadm_subchannel_probe(struct subchannel
*sch
)
225 struct eadm_private
*private;
228 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
232 INIT_LIST_HEAD(&private->head
);
233 init_timer(&private->timer
);
235 spin_lock_irq(sch
->lock
);
236 set_eadm_private(sch
, private);
237 private->state
= EADM_IDLE
;
239 sch
->isc
= EADM_SCH_ISC
;
240 ret
= cio_enable_subchannel(sch
, (u32
)(unsigned long)sch
);
242 set_eadm_private(sch
, NULL
);
243 spin_unlock_irq(sch
->lock
);
247 spin_unlock_irq(sch
->lock
);
249 spin_lock_irq(&list_lock
);
250 list_add(&private->head
, &eadm_list
);
251 spin_unlock_irq(&list_lock
);
253 if (dev_get_uevent_suppress(&sch
->dev
)) {
254 dev_set_uevent_suppress(&sch
->dev
, 0);
255 kobject_uevent(&sch
->dev
.kobj
, KOBJ_ADD
);
261 static void eadm_quiesce(struct subchannel
*sch
)
263 struct eadm_private
*private = get_eadm_private(sch
);
264 DECLARE_COMPLETION_ONSTACK(completion
);
267 spin_lock_irq(sch
->lock
);
268 if (private->state
!= EADM_BUSY
)
271 if (eadm_subchannel_clear(sch
))
274 private->completion
= &completion
;
275 spin_unlock_irq(sch
->lock
);
277 wait_for_completion_io(&completion
);
279 spin_lock_irq(sch
->lock
);
280 private->completion
= NULL
;
283 eadm_subchannel_set_timeout(sch
, 0);
285 ret
= cio_disable_subchannel(sch
);
286 } while (ret
== -EBUSY
);
288 spin_unlock_irq(sch
->lock
);
291 static int eadm_subchannel_remove(struct subchannel
*sch
)
293 struct eadm_private
*private = get_eadm_private(sch
);
295 spin_lock_irq(&list_lock
);
296 list_del(&private->head
);
297 spin_unlock_irq(&list_lock
);
301 spin_lock_irq(sch
->lock
);
302 set_eadm_private(sch
, NULL
);
303 spin_unlock_irq(sch
->lock
);
310 static void eadm_subchannel_shutdown(struct subchannel
*sch
)
315 static int eadm_subchannel_freeze(struct subchannel
*sch
)
317 return cio_disable_subchannel(sch
);
320 static int eadm_subchannel_restore(struct subchannel
*sch
)
322 return cio_enable_subchannel(sch
, (u32
)(unsigned long)sch
);
326 * eadm_subchannel_sch_event - process subchannel event
328 * @process: non-zero if function is called in process context
330 * An unspecified event occurred for this subchannel. Adjust data according
331 * to the current operational state of the subchannel. Return zero when the
332 * event has been handled sufficiently or -EAGAIN when this function should
333 * be called again in process context.
335 static int eadm_subchannel_sch_event(struct subchannel
*sch
, int process
)
337 struct eadm_private
*private;
341 spin_lock_irqsave(sch
->lock
, flags
);
342 if (!device_is_registered(&sch
->dev
))
345 if (work_pending(&sch
->todo_work
))
348 if (cio_update_schib(sch
)) {
349 css_sched_sch_todo(sch
, SCH_TODO_UNREG
);
352 private = get_eadm_private(sch
);
353 if (private->state
== EADM_NOT_OPER
)
354 private->state
= EADM_IDLE
;
357 spin_unlock_irqrestore(sch
->lock
, flags
);
362 static struct css_device_id eadm_subchannel_ids
[] = {
363 { .match_flags
= 0x1, .type
= SUBCHANNEL_TYPE_ADM
, },
364 { /* end of list */ },
366 MODULE_DEVICE_TABLE(css
, eadm_subchannel_ids
);
368 static struct css_driver eadm_subchannel_driver
= {
370 .name
= "eadm_subchannel",
371 .owner
= THIS_MODULE
,
373 .subchannel_type
= eadm_subchannel_ids
,
374 .irq
= eadm_subchannel_irq
,
375 .probe
= eadm_subchannel_probe
,
376 .remove
= eadm_subchannel_remove
,
377 .shutdown
= eadm_subchannel_shutdown
,
378 .sch_event
= eadm_subchannel_sch_event
,
379 .freeze
= eadm_subchannel_freeze
,
380 .thaw
= eadm_subchannel_restore
,
381 .restore
= eadm_subchannel_restore
,
384 static int __init
eadm_sch_init(void)
388 if (!css_general_characteristics
.eadm
)
391 eadm_debug
= debug_register("eadm_log", 16, 1, 16);
395 debug_register_view(eadm_debug
, &debug_hex_ascii_view
);
396 debug_set_level(eadm_debug
, 2);
398 isc_register(EADM_SCH_ISC
);
399 ret
= css_driver_register(&eadm_subchannel_driver
);
406 isc_unregister(EADM_SCH_ISC
);
407 debug_unregister(eadm_debug
);
411 static void __exit
eadm_sch_exit(void)
413 css_driver_unregister(&eadm_subchannel_driver
);
414 isc_unregister(EADM_SCH_ISC
);
415 debug_unregister(eadm_debug
);
417 module_init(eadm_sch_init
);
418 module_exit(eadm_sch_exit
);