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/workqueue.h>
10 #include <linux/spinlock.h>
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/timer.h>
14 #include <linux/slab.h>
15 #include <linux/list.h>
17 #include <asm/css_chars.h>
18 #include <asm/debug.h>
30 MODULE_DESCRIPTION("driver for s390 eadm subchannels");
31 MODULE_LICENSE("GPL");
33 #define EADM_TIMEOUT (5 * HZ)
34 static DEFINE_SPINLOCK(list_lock
);
35 static LIST_HEAD(eadm_list
);
37 static debug_info_t
*eadm_debug
;
39 #define EADM_LOG(imp, txt) do { \
40 debug_text_event(eadm_debug, imp, txt); \
43 static void EADM_LOG_HEX(int level
, void *data
, int length
)
45 if (level
> eadm_debug
->level
)
48 debug_event(eadm_debug
, level
, data
, length
);
49 length
-= eadm_debug
->buf_size
;
50 data
+= eadm_debug
->buf_size
;
54 static void orb_init(union orb
*orb
)
56 memset(orb
, 0, sizeof(union orb
));
57 orb
->eadm
.compat1
= 1;
58 orb
->eadm
.compat2
= 1;
63 static int eadm_subchannel_start(struct subchannel
*sch
, struct aob
*aob
)
65 union orb
*orb
= &get_eadm_private(sch
)->orb
;
69 orb
->eadm
.aob
= (u32
)__pa(aob
);
70 orb
->eadm
.intparm
= (u32
)(addr_t
)sch
;
71 orb
->eadm
.key
= PAGE_DEFAULT_KEY
>> 4;
74 EADM_LOG_HEX(6, &sch
->schid
, sizeof(sch
->schid
));
76 cc
= ssch(sch
->schid
, orb
);
79 sch
->schib
.scsw
.eadm
.actl
|= SCSW_ACTL_START_PEND
;
81 case 1: /* status pending */
84 case 3: /* not operational */
90 static int eadm_subchannel_clear(struct subchannel
*sch
)
94 cc
= csch(sch
->schid
);
98 sch
->schib
.scsw
.eadm
.actl
|= SCSW_ACTL_CLEAR_PEND
;
102 static void eadm_subchannel_timeout(unsigned long data
)
104 struct subchannel
*sch
= (struct subchannel
*) data
;
106 spin_lock_irq(sch
->lock
);
107 EADM_LOG(1, "timeout");
108 EADM_LOG_HEX(1, &sch
->schid
, sizeof(sch
->schid
));
109 if (eadm_subchannel_clear(sch
))
110 EADM_LOG(0, "clear failed");
111 spin_unlock_irq(sch
->lock
);
114 static void eadm_subchannel_set_timeout(struct subchannel
*sch
, int expires
)
116 struct eadm_private
*private = get_eadm_private(sch
);
119 del_timer(&private->timer
);
122 if (timer_pending(&private->timer
)) {
123 if (mod_timer(&private->timer
, jiffies
+ expires
))
126 private->timer
.function
= eadm_subchannel_timeout
;
127 private->timer
.data
= (unsigned long) sch
;
128 private->timer
.expires
= jiffies
+ expires
;
129 add_timer(&private->timer
);
132 static void eadm_subchannel_irq(struct subchannel
*sch
)
134 struct eadm_private
*private = get_eadm_private(sch
);
135 struct eadm_scsw
*scsw
= &sch
->schib
.scsw
.eadm
;
136 struct irb
*irb
= (struct irb
*)&S390_lowcore
.irb
;
140 EADM_LOG_HEX(6, irb
, sizeof(*irb
));
142 inc_irq_stat(IRQIO_ADM
);
144 if ((scsw
->stctl
& (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))
145 && scsw
->eswf
== 1 && irb
->esw
.eadm
.erw
.r
)
148 if (scsw
->fctl
& SCSW_FCTL_CLEAR_FUNC
)
151 eadm_subchannel_set_timeout(sch
, 0);
153 if (private->state
!= EADM_BUSY
) {
154 EADM_LOG(1, "irq unsol");
155 EADM_LOG_HEX(1, irb
, sizeof(*irb
));
156 private->state
= EADM_NOT_OPER
;
157 css_sched_sch_todo(sch
, SCH_TODO_EVAL
);
160 scm_irq_handler((struct aob
*)(unsigned long)scsw
->aob
, error
);
161 private->state
= EADM_IDLE
;
164 static struct subchannel
*eadm_get_idle_sch(void)
166 struct eadm_private
*private;
167 struct subchannel
*sch
;
170 spin_lock_irqsave(&list_lock
, flags
);
171 list_for_each_entry(private, &eadm_list
, head
) {
173 spin_lock(sch
->lock
);
174 if (private->state
== EADM_IDLE
) {
175 private->state
= EADM_BUSY
;
176 list_move_tail(&private->head
, &eadm_list
);
177 spin_unlock(sch
->lock
);
178 spin_unlock_irqrestore(&list_lock
, flags
);
182 spin_unlock(sch
->lock
);
184 spin_unlock_irqrestore(&list_lock
, flags
);
189 static int eadm_start_aob(struct aob
*aob
)
191 struct eadm_private
*private;
192 struct subchannel
*sch
;
196 sch
= eadm_get_idle_sch();
200 spin_lock_irqsave(sch
->lock
, flags
);
201 eadm_subchannel_set_timeout(sch
, EADM_TIMEOUT
);
202 ret
= eadm_subchannel_start(sch
, aob
);
206 /* Handle start subchannel failure. */
207 eadm_subchannel_set_timeout(sch
, 0);
208 private = get_eadm_private(sch
);
209 private->state
= EADM_NOT_OPER
;
210 css_sched_sch_todo(sch
, SCH_TODO_EVAL
);
213 spin_unlock_irqrestore(sch
->lock
, flags
);
218 static int eadm_subchannel_probe(struct subchannel
*sch
)
220 struct eadm_private
*private;
223 private = kzalloc(sizeof(*private), GFP_KERNEL
| GFP_DMA
);
227 INIT_LIST_HEAD(&private->head
);
228 init_timer(&private->timer
);
230 spin_lock_irq(sch
->lock
);
231 set_eadm_private(sch
, private);
232 private->state
= EADM_IDLE
;
234 sch
->isc
= EADM_SCH_ISC
;
235 ret
= cio_enable_subchannel(sch
, (u32
)(unsigned long)sch
);
237 set_eadm_private(sch
, NULL
);
238 spin_unlock_irq(sch
->lock
);
242 spin_unlock_irq(sch
->lock
);
244 spin_lock_irq(&list_lock
);
245 list_add(&private->head
, &eadm_list
);
246 spin_unlock_irq(&list_lock
);
248 if (dev_get_uevent_suppress(&sch
->dev
)) {
249 dev_set_uevent_suppress(&sch
->dev
, 0);
250 kobject_uevent(&sch
->dev
.kobj
, KOBJ_ADD
);
256 static void eadm_quiesce(struct subchannel
*sch
)
261 spin_lock_irq(sch
->lock
);
262 ret
= cio_disable_subchannel(sch
);
263 spin_unlock_irq(sch
->lock
);
264 } while (ret
== -EBUSY
);
267 static int eadm_subchannel_remove(struct subchannel
*sch
)
269 struct eadm_private
*private = get_eadm_private(sch
);
271 spin_lock_irq(&list_lock
);
272 list_del(&private->head
);
273 spin_unlock_irq(&list_lock
);
277 spin_lock_irq(sch
->lock
);
278 set_eadm_private(sch
, NULL
);
279 spin_unlock_irq(sch
->lock
);
286 static void eadm_subchannel_shutdown(struct subchannel
*sch
)
291 static int eadm_subchannel_freeze(struct subchannel
*sch
)
293 return cio_disable_subchannel(sch
);
296 static int eadm_subchannel_restore(struct subchannel
*sch
)
298 return cio_enable_subchannel(sch
, (u32
)(unsigned long)sch
);
302 * eadm_subchannel_sch_event - process subchannel event
304 * @process: non-zero if function is called in process context
306 * An unspecified event occurred for this subchannel. Adjust data according
307 * to the current operational state of the subchannel. Return zero when the
308 * event has been handled sufficiently or -EAGAIN when this function should
309 * be called again in process context.
311 static int eadm_subchannel_sch_event(struct subchannel
*sch
, int process
)
313 struct eadm_private
*private;
317 spin_lock_irqsave(sch
->lock
, flags
);
318 if (!device_is_registered(&sch
->dev
))
321 if (work_pending(&sch
->todo_work
))
324 if (cio_update_schib(sch
)) {
325 css_sched_sch_todo(sch
, SCH_TODO_UNREG
);
328 private = get_eadm_private(sch
);
329 if (private->state
== EADM_NOT_OPER
)
330 private->state
= EADM_IDLE
;
333 spin_unlock_irqrestore(sch
->lock
, flags
);
338 static struct css_device_id eadm_subchannel_ids
[] = {
339 { .match_flags
= 0x1, .type
= SUBCHANNEL_TYPE_ADM
, },
340 { /* end of list */ },
342 MODULE_DEVICE_TABLE(css
, eadm_subchannel_ids
);
344 static struct css_driver eadm_subchannel_driver
= {
346 .name
= "eadm_subchannel",
347 .owner
= THIS_MODULE
,
349 .subchannel_type
= eadm_subchannel_ids
,
350 .irq
= eadm_subchannel_irq
,
351 .probe
= eadm_subchannel_probe
,
352 .remove
= eadm_subchannel_remove
,
353 .shutdown
= eadm_subchannel_shutdown
,
354 .sch_event
= eadm_subchannel_sch_event
,
355 .freeze
= eadm_subchannel_freeze
,
356 .thaw
= eadm_subchannel_restore
,
357 .restore
= eadm_subchannel_restore
,
360 static struct eadm_ops eadm_ops
= {
361 .eadm_start
= eadm_start_aob
,
362 .owner
= THIS_MODULE
,
365 static int __init
eadm_sch_init(void)
369 if (!css_general_characteristics
.eadm
)
372 eadm_debug
= debug_register("eadm_log", 16, 1, 16);
376 debug_register_view(eadm_debug
, &debug_hex_ascii_view
);
377 debug_set_level(eadm_debug
, 2);
379 isc_register(EADM_SCH_ISC
);
380 ret
= css_driver_register(&eadm_subchannel_driver
);
384 register_eadm_ops(&eadm_ops
);
388 isc_unregister(EADM_SCH_ISC
);
389 debug_unregister(eadm_debug
);
393 static void __exit
eadm_sch_exit(void)
395 unregister_eadm_ops(&eadm_ops
);
396 css_driver_unregister(&eadm_subchannel_driver
);
397 isc_unregister(EADM_SCH_ISC
);
398 debug_unregister(eadm_debug
);
400 module_init(eadm_sch_init
);
401 module_exit(eadm_sch_exit
);