2 * hvc_iucv.c - z/VM IUCV back-end for the Hypervisor Console (HVC)
4 * This back-end for HVC provides terminal access via
5 * z/VM IUCV communication paths.
7 * Copyright IBM Corp. 2008.
9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
11 #define KMSG_COMPONENT "hvc_iucv"
13 #include <linux/types.h>
14 #include <asm/ebcdic.h>
15 #include <linux/mempool.h>
16 #include <linux/module.h>
17 #include <linux/tty.h>
18 #include <net/iucv/iucv.h>
20 #include "hvc_console.h"
23 /* HVC backend for z/VM IUCV */
24 #define HVC_IUCV_MAGIC 0xc9e4c3e5
25 #define MAX_HVC_IUCV_LINES HVC_ALLOC_TTY_ADAPTERS
26 #define MEMPOOL_MIN_NR (PAGE_SIZE / sizeof(struct iucv_tty_buffer)/4)
28 /* IUCV TTY message */
29 #define MSG_VERSION 0x02 /* Message version */
30 #define MSG_TYPE_ERROR 0x01 /* Error message */
31 #define MSG_TYPE_TERMENV 0x02 /* Terminal environment variable */
32 #define MSG_TYPE_TERMIOS 0x04 /* Terminal IO struct update */
33 #define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update */
34 #define MSG_TYPE_DATA 0x10 /* Terminal data */
36 #define MSG_SIZE(s) ((s) + offsetof(struct iucv_tty_msg, data))
38 u8 version
; /* Message version */
39 u8 type
; /* Message type */
40 #define MSG_MAX_DATALEN (~(u16)0)
41 u16 datalen
; /* Payload length */
42 u8 data
[]; /* Payload buffer */
43 } __attribute__((packed
));
56 struct hvc_iucv_private
{
57 struct hvc_struct
*hvc
; /* HVC console struct reference */
58 u8 srv_name
[8]; /* IUCV service name (ebcdic) */
59 enum iucv_state_t iucv_state
; /* IUCV connection status */
60 enum tty_state_t tty_state
; /* TTY status */
61 struct iucv_path
*path
; /* IUCV path pointer */
62 spinlock_t lock
; /* hvc_iucv_private lock */
63 struct list_head tty_outqueue
; /* outgoing IUCV messages */
64 struct list_head tty_inqueue
; /* incoming IUCV messages */
67 struct iucv_tty_buffer
{
68 struct list_head list
; /* list pointer */
69 struct iucv_message msg
; /* store an incoming IUCV message */
70 size_t offset
; /* data buffer offset */
71 struct iucv_tty_msg
*mbuf
; /* buffer to store input/output data */
74 /* IUCV callback handler */
75 static int hvc_iucv_path_pending(struct iucv_path
*, u8
[8], u8
[16]);
76 static void hvc_iucv_path_severed(struct iucv_path
*, u8
[16]);
77 static void hvc_iucv_msg_pending(struct iucv_path
*, struct iucv_message
*);
78 static void hvc_iucv_msg_complete(struct iucv_path
*, struct iucv_message
*);
81 /* Kernel module parameters */
82 static unsigned long hvc_iucv_devices
;
84 /* Array of allocated hvc iucv tty lines... */
85 static struct hvc_iucv_private
*hvc_iucv_table
[MAX_HVC_IUCV_LINES
];
87 /* Kmem cache and mempool for iucv_tty_buffer elements */
88 static struct kmem_cache
*hvc_iucv_buffer_cache
;
89 static mempool_t
*hvc_iucv_mempool
;
91 /* IUCV handler callback functions */
92 static struct iucv_handler hvc_iucv_handler
= {
93 .path_pending
= hvc_iucv_path_pending
,
94 .path_severed
= hvc_iucv_path_severed
,
95 .message_complete
= hvc_iucv_msg_complete
,
96 .message_pending
= hvc_iucv_msg_pending
,
101 * hvc_iucv_get_private() - Return a struct hvc_iucv_private instance.
102 * @num: The HVC virtual terminal number (vtermno)
104 * This function returns the struct hvc_iucv_private instance that corresponds
105 * to the HVC virtual terminal number specified as parameter @num.
107 struct hvc_iucv_private
*hvc_iucv_get_private(uint32_t num
)
109 if ((num
< HVC_IUCV_MAGIC
) || (num
- HVC_IUCV_MAGIC
> hvc_iucv_devices
))
111 return hvc_iucv_table
[num
- HVC_IUCV_MAGIC
];
115 * alloc_tty_buffer() - Returns a new struct iucv_tty_buffer element.
116 * @size: Size of the internal buffer used to store data.
117 * @flags: Memory allocation flags passed to mempool.
119 * This function allocates a new struct iucv_tty_buffer element and, optionally,
120 * allocates an internal data buffer with the specified size @size.
121 * Note: The total message size arises from the internal buffer size and the
122 * members of the iucv_tty_msg structure.
124 * The function returns NULL if memory allocation has failed.
126 static struct iucv_tty_buffer
*alloc_tty_buffer(size_t size
, gfp_t flags
)
128 struct iucv_tty_buffer
*bufp
;
130 bufp
= mempool_alloc(hvc_iucv_mempool
, flags
);
133 memset(bufp
, 0, sizeof(struct iucv_tty_buffer
));
136 bufp
->msg
.length
= MSG_SIZE(size
);
137 bufp
->mbuf
= kmalloc(bufp
->msg
.length
, flags
);
139 mempool_free(bufp
, hvc_iucv_mempool
);
142 bufp
->mbuf
->version
= MSG_VERSION
;
143 bufp
->mbuf
->type
= MSG_TYPE_DATA
;
144 bufp
->mbuf
->datalen
= (u16
) size
;
150 * destroy_tty_buffer() - destroy struct iucv_tty_buffer element.
151 * @bufp: Pointer to a struct iucv_tty_buffer element, SHALL NOT be NULL.
153 * The destroy_tty_buffer() function frees the internal data buffer and returns
154 * the struct iucv_tty_buffer element back to the mempool for freeing.
156 static void destroy_tty_buffer(struct iucv_tty_buffer
*bufp
)
159 mempool_free(bufp
, hvc_iucv_mempool
);
163 * destroy_tty_buffer_list() - call destroy_tty_buffer() for each list element.
164 * @list: List head pointer to a list containing struct iucv_tty_buffer
167 * Calls destroy_tty_buffer() for each struct iucv_tty_buffer element in the
170 static void destroy_tty_buffer_list(struct list_head
*list
)
172 struct iucv_tty_buffer
*ent
, *next
;
174 list_for_each_entry_safe(ent
, next
, list
, list
) {
175 list_del(&ent
->list
);
176 destroy_tty_buffer(ent
);
181 * hvc_iucv_write() - Receive IUCV message write data to HVC console buffer.
182 * @priv: Pointer to hvc_iucv_private structure.
183 * @buf: HVC console buffer for writing received terminal data.
184 * @count: HVC console buffer size.
185 * @has_more_data: Pointer to an int variable.
187 * The function picks up pending messages from the input queue and receives
188 * the message data that is then written to the specified buffer @buf.
189 * If the buffer size @count is less than the data message size, then the
190 * message is kept on the input queue and @has_more_data is set to 1.
191 * If the message data has been entirely written, the message is removed from
194 * The function returns the number of bytes written to the terminal, zero if
195 * there are no pending data messages available or if there is no established
197 * If the IUCV path has been severed, then -EPIPE is returned to cause a
198 * hang up (that is issued by the HVC console layer).
200 static int hvc_iucv_write(struct hvc_iucv_private
*priv
,
201 char *buf
, int count
, int *has_more_data
)
203 struct iucv_tty_buffer
*rb
;
207 /* Immediately return if there is no IUCV connection */
208 if (priv
->iucv_state
== IUCV_DISCONN
)
211 /* If the IUCV path has been severed, return -EPIPE to inform the
212 * hvc console layer to hang up the tty device. */
213 if (priv
->iucv_state
== IUCV_SEVERED
)
216 /* check if there are pending messages */
217 if (list_empty(&priv
->tty_inqueue
))
220 /* receive a iucv message and flip data to the tty (ldisc) */
221 rb
= list_first_entry(&priv
->tty_inqueue
, struct iucv_tty_buffer
, list
);
224 if (!rb
->mbuf
) { /* message not yet received ... */
225 /* allocate mem to store msg data; if no memory is available
226 * then leave the buffer on the list and re-try later */
227 rb
->mbuf
= kmalloc(rb
->msg
.length
, GFP_ATOMIC
);
231 rc
= __iucv_message_receive(priv
->path
, &rb
->msg
, 0,
232 rb
->mbuf
, rb
->msg
.length
, NULL
);
234 case 0: /* Successful */
236 case 2: /* No message found */
237 case 9: /* Message purged */
242 /* remove buffer if an error has occured or received data
244 if (rc
|| (rb
->mbuf
->version
!= MSG_VERSION
) ||
245 (rb
->msg
.length
!= MSG_SIZE(rb
->mbuf
->datalen
)))
246 goto out_remove_buffer
;
249 switch (rb
->mbuf
->type
) {
251 written
= min_t(int, rb
->mbuf
->datalen
- rb
->offset
, count
);
252 memcpy(buf
, rb
->mbuf
->data
+ rb
->offset
, written
);
253 if (written
< (rb
->mbuf
->datalen
- rb
->offset
)) {
254 rb
->offset
+= written
;
260 case MSG_TYPE_WINSIZE
:
261 if (rb
->mbuf
->datalen
!= sizeof(struct winsize
))
263 hvc_resize(priv
->hvc
, *((struct winsize
*)rb
->mbuf
->data
));
266 case MSG_TYPE_ERROR
: /* ignored ... */
267 case MSG_TYPE_TERMENV
: /* ignored ... */
268 case MSG_TYPE_TERMIOS
: /* ignored ... */
274 destroy_tty_buffer(rb
);
275 *has_more_data
= !list_empty(&priv
->tty_inqueue
);
282 * hvc_iucv_get_chars() - HVC get_chars operation.
283 * @vtermno: HVC virtual terminal number.
284 * @buf: Pointer to a buffer to store data
285 * @count: Size of buffer available for writing
287 * The hvc_console thread calls this method to read characters from
288 * the terminal backend. If an IUCV communication path has been established,
289 * pending IUCV messages are received and data is copied into buffer @buf
290 * up to @count bytes.
292 * Locking: The routine gets called under an irqsave() spinlock; and
293 * the routine locks the struct hvc_iucv_private->lock to call
296 static int hvc_iucv_get_chars(uint32_t vtermno
, char *buf
, int count
)
298 struct hvc_iucv_private
*priv
= hvc_iucv_get_private(vtermno
);
308 spin_lock(&priv
->lock
);
310 written
= hvc_iucv_write(priv
, buf
, count
, &has_more_data
);
311 spin_unlock(&priv
->lock
);
313 /* if there are still messages on the queue... schedule another run */
321 * hvc_iucv_send() - Send an IUCV message containing terminal data.
322 * @priv: Pointer to struct hvc_iucv_private instance.
323 * @buf: Buffer containing data to send.
324 * @size: Size of buffer and amount of data to send.
326 * If an IUCV communication path is established, the function copies the buffer
327 * data to a newly allocated struct iucv_tty_buffer element, sends the data and
328 * puts the element to the outqueue.
330 * If there is no IUCV communication path established, the function returns 0.
331 * If an existing IUCV communicaton path has been severed, the function returns
332 * -EPIPE (can be passed to HVC layer to cause a tty hangup).
334 static int hvc_iucv_send(struct hvc_iucv_private
*priv
, const char *buf
,
337 struct iucv_tty_buffer
*sb
;
341 if (priv
->iucv_state
== IUCV_SEVERED
)
344 if (priv
->iucv_state
== IUCV_DISCONN
)
347 len
= min_t(u16
, MSG_MAX_DATALEN
, count
);
349 /* allocate internal buffer to store msg data and also compute total
351 sb
= alloc_tty_buffer(len
, GFP_ATOMIC
);
355 sb
->mbuf
->datalen
= len
;
356 memcpy(sb
->mbuf
->data
, buf
, len
);
358 list_add_tail(&sb
->list
, &priv
->tty_outqueue
);
360 rc
= __iucv_message_send(priv
->path
, &sb
->msg
, 0, 0,
361 (void *) sb
->mbuf
, sb
->msg
.length
);
364 destroy_tty_buffer(sb
);
372 * hvc_iucv_put_chars() - HVC put_chars operation.
373 * @vtermno: HVC virtual terminal number.
374 * @buf: Pointer to an buffer to read data from
375 * @count: Size of buffer available for reading
377 * The hvc_console thread calls this method to write characters from
378 * to the terminal backend.
379 * The function calls hvc_iucv_send() under the lock of the
380 * struct hvc_iucv_private instance that corresponds to the tty @vtermno.
382 * Locking: The method gets called under an irqsave() spinlock; and
383 * locks struct hvc_iucv_private->lock.
385 static int hvc_iucv_put_chars(uint32_t vtermno
, const char *buf
, int count
)
387 struct hvc_iucv_private
*priv
= hvc_iucv_get_private(vtermno
);
396 spin_lock(&priv
->lock
);
397 sent
= hvc_iucv_send(priv
, buf
, count
);
398 spin_unlock(&priv
->lock
);
404 * hvc_iucv_notifier_add() - HVC notifier for opening a TTY for the first time.
405 * @hp: Pointer to the HVC device (struct hvc_struct)
406 * @id: Additional data (originally passed to hvc_alloc): the index of an struct
407 * hvc_iucv_private instance.
409 * The function sets the tty state to TTY_OPEN for the struct hvc_iucv_private
410 * instance that is derived from @id. Always returns 0.
412 * Locking: struct hvc_iucv_private->lock, spin_lock_bh
414 static int hvc_iucv_notifier_add(struct hvc_struct
*hp
, int id
)
416 struct hvc_iucv_private
*priv
;
418 priv
= hvc_iucv_get_private(id
);
422 spin_lock_bh(&priv
->lock
);
423 priv
->tty_state
= TTY_OPENED
;
424 spin_unlock_bh(&priv
->lock
);
430 * hvc_iucv_cleanup() - Clean up function if the tty portion is finally closed.
431 * @priv: Pointer to the struct hvc_iucv_private instance.
433 * The functions severs the established IUCV communication path (if any), and
434 * destroy struct iucv_tty_buffer elements from the in- and outqueue. Finally,
435 * the functions resets the states to TTY_CLOSED and IUCV_DISCONN.
437 static void hvc_iucv_cleanup(struct hvc_iucv_private
*priv
)
439 destroy_tty_buffer_list(&priv
->tty_outqueue
);
440 destroy_tty_buffer_list(&priv
->tty_inqueue
);
442 priv
->tty_state
= TTY_CLOSED
;
443 priv
->iucv_state
= IUCV_DISCONN
;
447 * hvc_iucv_notifier_hangup() - HVC notifier for tty hangups.
448 * @hp: Pointer to the HVC device (struct hvc_struct)
449 * @id: Additional data (originally passed to hvc_alloc): the index of an struct
450 * hvc_iucv_private instance.
452 * This routine notifies the HVC backend that a tty hangup (carrier loss,
453 * virtual or otherwise) has occured.
455 * The HVC backend for z/VM IUCV ignores virtual hangups (vhangup()), to keep
456 * an existing IUCV communication path established.
457 * (Background: vhangup() is called from user space (by getty or login) to
458 * disable writing to the tty by other applications).
460 * If the tty has been opened (e.g. getty) and an established IUCV path has been
461 * severed (we caused the tty hangup in that case), then the functions invokes
462 * hvc_iucv_cleanup() to clean up.
464 * Locking: struct hvc_iucv_private->lock
466 static void hvc_iucv_notifier_hangup(struct hvc_struct
*hp
, int id
)
468 struct hvc_iucv_private
*priv
;
470 priv
= hvc_iucv_get_private(id
);
474 spin_lock_bh(&priv
->lock
);
475 /* NOTE: If the hangup was scheduled by ourself (from the iucv
476 * path_servered callback [IUCV_SEVERED]), then we have to
477 * finally clean up the tty backend structure and set state to
480 * If the tty was hung up otherwise (e.g. vhangup()), then we
481 * ignore this hangup and keep an established IUCV path open...
482 * (...the reason is that we are not able to connect back to the
483 * client if we disconnect on hang up) */
484 priv
->tty_state
= TTY_CLOSED
;
486 if (priv
->iucv_state
== IUCV_SEVERED
)
487 hvc_iucv_cleanup(priv
);
488 spin_unlock_bh(&priv
->lock
);
492 * hvc_iucv_notifier_del() - HVC notifier for closing a TTY for the last time.
493 * @hp: Pointer to the HVC device (struct hvc_struct)
494 * @id: Additional data (originally passed to hvc_alloc):
495 * the index of an struct hvc_iucv_private instance.
497 * This routine notifies the HVC backend that the last tty device file
498 * descriptor has been closed.
499 * The function calls hvc_iucv_cleanup() to clean up the struct hvc_iucv_private
502 * Locking: struct hvc_iucv_private->lock
504 static void hvc_iucv_notifier_del(struct hvc_struct
*hp
, int id
)
506 struct hvc_iucv_private
*priv
;
507 struct iucv_path
*path
;
509 priv
= hvc_iucv_get_private(id
);
513 spin_lock_bh(&priv
->lock
);
514 path
= priv
->path
; /* save reference to IUCV path */
516 hvc_iucv_cleanup(priv
);
517 spin_unlock_bh(&priv
->lock
);
519 /* sever IUCV path outside of priv->lock due to lock ordering of:
520 * priv->lock <--> iucv_table_lock */
522 iucv_path_sever(path
, NULL
);
523 iucv_path_free(path
);
528 * hvc_iucv_path_pending() - IUCV handler to process a connection request.
529 * @path: Pending path (struct iucv_path)
530 * @ipvmid: Originator z/VM system identifier
531 * @ipuser: User specified data for this path
532 * (AF_IUCV: port/service name and originator port)
534 * The function uses the @ipuser data to check to determine if the pending
535 * path belongs to a terminal managed by this HVC backend.
536 * If the check is successful, then an additional check is done to ensure
537 * that a terminal cannot be accessed multiple times (only one connection
538 * to a terminal is allowed). In that particular case, the pending path is
539 * severed. If it is the first connection, the pending path is accepted and
540 * associated to the struct hvc_iucv_private. The iucv state is updated to
541 * reflect that a communication path has been established.
543 * Returns 0 if the path belongs to a terminal managed by the this HVC backend;
544 * otherwise returns -ENODEV in order to dispatch this path to other handlers.
546 * Locking: struct hvc_iucv_private->lock
548 static int hvc_iucv_path_pending(struct iucv_path
*path
,
549 u8 ipvmid
[8], u8 ipuser
[16])
551 struct hvc_iucv_private
*priv
;
556 for (i
= 0; i
< hvc_iucv_devices
; i
++)
557 if (hvc_iucv_table
[i
] &&
558 (0 == memcmp(hvc_iucv_table
[i
]->srv_name
, ipuser
, 8))) {
559 priv
= hvc_iucv_table
[i
];
566 spin_lock(&priv
->lock
);
568 /* If the terminal is already connected or being severed, then sever
569 * this path to enforce that there is only ONE established communication
570 * path per terminal. */
571 if (priv
->iucv_state
!= IUCV_DISCONN
) {
572 iucv_path_sever(path
, ipuser
);
573 iucv_path_free(path
);
574 goto out_path_handled
;
578 memcpy(nuser_data
, ipuser
+ 8, 8); /* remote service (for af_iucv) */
579 memcpy(nuser_data
+ 8, ipuser
, 8); /* local service (for af_iucv) */
580 path
->msglim
= 0xffff; /* IUCV MSGLIMIT */
581 path
->flags
&= ~IUCV_IPRMDATA
; /* TODO: use IUCV_IPRMDATA */
582 rc
= iucv_path_accept(path
, &hvc_iucv_handler
, nuser_data
, priv
);
584 iucv_path_sever(path
, ipuser
);
585 iucv_path_free(path
);
586 goto out_path_handled
;
589 priv
->iucv_state
= IUCV_CONNECTED
;
592 spin_unlock(&priv
->lock
);
597 * hvc_iucv_path_severed() - IUCV handler to process a path sever.
598 * @path: Pending path (struct iucv_path)
599 * @ipuser: User specified data for this path
600 * (AF_IUCV: port/service name and originator port)
602 * The function also severs the path (as required by the IUCV protocol) and
603 * sets the iucv state to IUCV_SEVERED for the associated struct
604 * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty
605 * hangup (hvc_iucv_get_chars() / hvc_iucv_write()).
607 * If tty portion of the HVC is closed then clean up the outqueue in addition.
609 * Locking: struct hvc_iucv_private->lock
611 static void hvc_iucv_path_severed(struct iucv_path
*path
, u8 ipuser
[16])
613 struct hvc_iucv_private
*priv
= path
->private;
615 spin_lock(&priv
->lock
);
616 priv
->iucv_state
= IUCV_SEVERED
;
618 /* NOTE: If the tty has not yet been opened by a getty program
619 * (e.g. to see console messages), then cleanup the
620 * hvc_iucv_private structure to allow re-connects.
622 * If the tty has been opened, the get_chars() callback returns
623 * -EPIPE to signal the hvc console layer to hang up the tty. */
625 if (priv
->tty_state
== TTY_CLOSED
)
626 hvc_iucv_cleanup(priv
);
627 spin_unlock(&priv
->lock
);
629 /* finally sever path (outside of priv->lock due to lock ordering) */
630 iucv_path_sever(path
, ipuser
);
631 iucv_path_free(path
);
635 * hvc_iucv_msg_pending() - IUCV handler to process an incoming IUCV message.
636 * @path: Pending path (struct iucv_path)
637 * @msg: Pointer to the IUCV message
639 * The function stores an incoming message on the input queue for later
640 * processing (by hvc_iucv_get_chars() / hvc_iucv_write()).
641 * However, if the tty has not yet been opened, the message is rejected.
643 * Locking: struct hvc_iucv_private->lock
645 static void hvc_iucv_msg_pending(struct iucv_path
*path
,
646 struct iucv_message
*msg
)
648 struct hvc_iucv_private
*priv
= path
->private;
649 struct iucv_tty_buffer
*rb
;
651 spin_lock(&priv
->lock
);
653 /* reject messages if tty has not yet been opened */
654 if (priv
->tty_state
== TTY_CLOSED
) {
655 iucv_message_reject(path
, msg
);
659 /* allocate buffer an empty buffer element */
660 rb
= alloc_tty_buffer(0, GFP_ATOMIC
);
662 iucv_message_reject(path
, msg
);
663 goto unlock_return
; /* -ENOMEM */
667 list_add_tail(&rb
->list
, &priv
->tty_inqueue
);
669 hvc_kick(); /* wakup hvc console thread */
672 spin_unlock(&priv
->lock
);
676 * hvc_iucv_msg_complete() - IUCV handler to process message completion
677 * @path: Pending path (struct iucv_path)
678 * @msg: Pointer to the IUCV message
680 * The function is called upon completion of message delivery and the
681 * message is removed from the outqueue. Additional delivery information
682 * can be found in msg->audit: rejected messages (0x040000 (IPADRJCT)) and
683 * purged messages (0x010000 (IPADPGNR)).
685 * Locking: struct hvc_iucv_private->lock
687 static void hvc_iucv_msg_complete(struct iucv_path
*path
,
688 struct iucv_message
*msg
)
690 struct hvc_iucv_private
*priv
= path
->private;
691 struct iucv_tty_buffer
*ent
, *next
;
692 LIST_HEAD(list_remove
);
694 spin_lock(&priv
->lock
);
695 list_for_each_entry_safe(ent
, next
, &priv
->tty_outqueue
, list
)
696 if (ent
->msg
.id
== msg
->id
) {
697 list_move(&ent
->list
, &list_remove
);
700 spin_unlock(&priv
->lock
);
701 destroy_tty_buffer_list(&list_remove
);
706 static struct hv_ops hvc_iucv_ops
= {
707 .get_chars
= hvc_iucv_get_chars
,
708 .put_chars
= hvc_iucv_put_chars
,
709 .notifier_add
= hvc_iucv_notifier_add
,
710 .notifier_del
= hvc_iucv_notifier_del
,
711 .notifier_hangup
= hvc_iucv_notifier_hangup
,
715 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance
716 * @id: hvc_iucv_table index
718 * This function allocates a new hvc_iucv_private struct and put the
719 * instance into hvc_iucv_table at index @id.
720 * Returns 0 on success; otherwise non-zero.
722 static int __init
hvc_iucv_alloc(int id
)
724 struct hvc_iucv_private
*priv
;
728 priv
= kzalloc(sizeof(struct hvc_iucv_private
), GFP_KERNEL
);
732 spin_lock_init(&priv
->lock
);
733 INIT_LIST_HEAD(&priv
->tty_outqueue
);
734 INIT_LIST_HEAD(&priv
->tty_inqueue
);
736 /* Finally allocate hvc */
737 priv
->hvc
= hvc_alloc(HVC_IUCV_MAGIC
+ id
,
738 HVC_IUCV_MAGIC
+ id
, &hvc_iucv_ops
, PAGE_SIZE
);
739 if (IS_ERR(priv
->hvc
)) {
740 rc
= PTR_ERR(priv
->hvc
);
745 /* setup iucv related information */
746 snprintf(name
, 9, "ihvc%-4d", id
);
747 memcpy(priv
->srv_name
, name
, 8);
748 ASCEBC(priv
->srv_name
, 8);
750 hvc_iucv_table
[id
] = priv
;
755 * hvc_iucv_init() - Initialization of HVC backend for z/VM IUCV
757 static int __init
hvc_iucv_init(void)
761 if (!MACHINE_IS_VM
) {
762 pr_warning("The z/VM IUCV Hypervisor console cannot be "
763 "used without z/VM.\n");
767 if (!hvc_iucv_devices
)
770 if (hvc_iucv_devices
> MAX_HVC_IUCV_LINES
)
773 hvc_iucv_buffer_cache
= kmem_cache_create(KMSG_COMPONENT
,
774 sizeof(struct iucv_tty_buffer
),
776 if (!hvc_iucv_buffer_cache
) {
777 pr_err("Not enough memory for driver initialization "
782 hvc_iucv_mempool
= mempool_create_slab_pool(MEMPOOL_MIN_NR
,
783 hvc_iucv_buffer_cache
);
784 if (!hvc_iucv_mempool
) {
785 pr_err("Not enough memory for driver initialization "
787 kmem_cache_destroy(hvc_iucv_buffer_cache
);
791 /* allocate hvc_iucv_private structs */
792 for (i
= 0; i
< hvc_iucv_devices
; i
++) {
793 rc
= hvc_iucv_alloc(i
);
795 pr_err("Could not create new z/VM IUCV HVC backend "
801 /* register IUCV callback handler */
802 rc
= iucv_register(&hvc_iucv_handler
, 0);
804 pr_err("Could not register iucv handler (rc=%d).\n", rc
);
811 iucv_unregister(&hvc_iucv_handler
, 0);
813 for (i
= 0; i
< hvc_iucv_devices
; i
++)
814 if (hvc_iucv_table
[i
]) {
815 if (hvc_iucv_table
[i
]->hvc
)
816 hvc_remove(hvc_iucv_table
[i
]->hvc
);
817 kfree(hvc_iucv_table
[i
]);
819 mempool_destroy(hvc_iucv_mempool
);
820 kmem_cache_destroy(hvc_iucv_buffer_cache
);
825 * hvc_iucv_console_init() - Early console initialization
827 static int __init
hvc_iucv_console_init(void)
829 if (!MACHINE_IS_VM
|| !hvc_iucv_devices
)
831 return hvc_instantiate(HVC_IUCV_MAGIC
, 0, &hvc_iucv_ops
);
835 * hvc_iucv_config() - Parsing of hvc_iucv= kernel command line parameter
836 * @val: Parameter value (numeric)
838 static int __init
hvc_iucv_config(char *val
)
840 return strict_strtoul(val
, 10, &hvc_iucv_devices
);
844 module_init(hvc_iucv_init
);
845 console_initcall(hvc_iucv_console_init
);
846 __setup("hvc_iucv=", hvc_iucv_config
);
848 MODULE_LICENSE("GPL");
849 MODULE_DESCRIPTION("HVC back-end for z/VM IUCV.");
850 MODULE_AUTHOR("Hendrik Brueckner <brueckner@linux.vnet.ibm.com>");