1 // SPDX-License-Identifier: GPL-2.0
2 /* vcc.c: sun4v virtual channel concentrator
4 * Copyright (C) 2017 Oracle. All rights reserved.
7 #include <linux/delay.h>
8 #include <linux/interrupt.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/sysfs.h>
12 #include <linux/tty.h>
13 #include <linux/tty_flip.h>
17 #define DRV_MODULE_NAME "vcc"
18 #define DRV_MODULE_VERSION "1.1"
19 #define DRV_MODULE_RELDATE "July 1, 2017"
21 static char version
[] =
22 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")";
24 MODULE_DESCRIPTION("Sun LDOM virtual console concentrator driver");
25 MODULE_LICENSE("GPL");
26 MODULE_VERSION(DRV_MODULE_VERSION
);
29 struct vio_driver_state vio
;
33 struct tty_struct
*tty
; /* only populated while dev is open */
34 unsigned long index
; /* index into the vcc_table */
41 /* This buffer is required to support the tty write_room interface
42 * and guarantee that any characters that the driver accepts will
43 * be eventually sent, either immediately or later.
46 struct vio_vcc buffer
;
48 struct timer_list rx_timer
;
49 struct timer_list tx_timer
;
52 /* Microseconds that thread will delay waiting for a vcc port ref */
53 #define VCC_REF_DELAY 100
55 #define VCC_MAX_PORTS 1024
56 #define VCC_MINOR_START 0 /* must be zero */
57 #define VCC_BUFF_LEN VIO_VCC_MTU_SIZE
59 #define VCC_CTL_BREAK -1
60 #define VCC_CTL_HUP -2
62 static const char vcc_driver_name
[] = "vcc";
63 static const char vcc_device_node
[] = "vcc";
64 static struct tty_driver
*vcc_tty_driver
;
66 static struct vcc_port
*vcc_table
[VCC_MAX_PORTS
];
67 static DEFINE_SPINLOCK(vcc_table_lock
);
73 module_param(vcc_dbg
, uint
, 0664);
74 module_param(vcc_dbg_ldc
, uint
, 0664);
75 module_param(vcc_dbg_vio
, uint
, 0664);
77 #define VCC_DBG_DRV 0x1
78 #define VCC_DBG_LDC 0x2
79 #define VCC_DBG_PKT 0x4
81 #define vccdbg(f, a...) \
83 if (vcc_dbg & VCC_DBG_DRV) \
89 if (vcc_dbg & VCC_DBG_LDC) \
93 #define vccdbgp(pkt) \
95 if (vcc_dbg & VCC_DBG_PKT) { \
97 for (i = 0; i < pkt.tag.stype; i++) \
98 pr_info("[%c]", pkt.data[i]); \
102 /* Note: Be careful when adding flags to this line discipline. Don't
103 * add anything that will cause echoing or we'll go into recursive
104 * loop echoing chars back and forth with the console drivers.
106 static const struct ktermios vcc_tty_termios
= {
107 .c_iflag
= IGNBRK
| IGNPAR
,
109 .c_cflag
= B38400
| CS8
| CREAD
| HUPCL
,
116 * vcc_table_add() - Add VCC port to the VCC table
117 * @port: pointer to the VCC port
119 * Return: index of the port in the VCC table on success,
122 static int vcc_table_add(struct vcc_port
*port
)
127 spin_lock_irqsave(&vcc_table_lock
, flags
);
128 for (i
= VCC_MINOR_START
; i
< VCC_MAX_PORTS
; i
++) {
134 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
136 if (i
< VCC_MAX_PORTS
)
143 * vcc_table_remove() - Removes a VCC port from the VCC table
144 * @index: Index into the VCC table
146 static void vcc_table_remove(unsigned long index
)
150 if (WARN_ON(index
>= VCC_MAX_PORTS
))
153 spin_lock_irqsave(&vcc_table_lock
, flags
);
154 vcc_table
[index
] = NULL
;
155 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
159 * vcc_get() - Gets a reference to VCC port
160 * @index: Index into the VCC table
161 * @excl: Indicates if an exclusive access is requested
163 * Return: reference to the VCC port, if found
164 * NULL, if port not found
166 static struct vcc_port
*vcc_get(unsigned long index
, bool excl
)
168 struct vcc_port
*port
;
172 spin_lock_irqsave(&vcc_table_lock
, flags
);
174 port
= vcc_table
[index
];
176 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
181 if (port
->excl_locked
) {
182 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
183 udelay(VCC_REF_DELAY
);
187 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
192 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
193 /* Threads wanting exclusive access will wait half the time,
194 * probably giving them higher priority in the case of
197 udelay(VCC_REF_DELAY
/2);
202 port
->excl_locked
= true;
203 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
209 * vcc_put() - Returns a reference to VCC port
210 * @port: pointer to VCC port
211 * @excl: Indicates if the returned reference is an exclusive reference
213 * Note: It's the caller's responsibility to ensure the correct value
216 static void vcc_put(struct vcc_port
*port
, bool excl
)
223 spin_lock_irqsave(&vcc_table_lock
, flags
);
225 /* check if caller attempted to put with the wrong flags */
226 if (WARN_ON((excl
&& !port
->excl_locked
) ||
227 (!excl
&& port
->excl_locked
)))
233 port
->excl_locked
= false;
236 spin_unlock_irqrestore(&vcc_table_lock
, flags
);
240 * vcc_get_ne() - Get a non-exclusive reference to VCC port
241 * @index: Index into the VCC table
243 * Gets a non-exclusive reference to VCC port, if it's not removed
245 * Return: pointer to the VCC port, if found
246 * NULL, if port not found
248 static struct vcc_port
*vcc_get_ne(unsigned long index
)
250 struct vcc_port
*port
;
252 port
= vcc_get(index
, false);
254 if (port
&& port
->removed
) {
255 vcc_put(port
, false);
262 static void vcc_kick_rx(struct vcc_port
*port
)
264 struct vio_driver_state
*vio
= &port
->vio
;
266 assert_spin_locked(&port
->lock
);
268 if (!timer_pending(&port
->rx_timer
) && !port
->removed
) {
269 disable_irq_nosync(vio
->vdev
->rx_irq
);
270 port
->rx_timer
.expires
= (jiffies
+ 1);
271 add_timer(&port
->rx_timer
);
275 static void vcc_kick_tx(struct vcc_port
*port
)
277 assert_spin_locked(&port
->lock
);
279 if (!timer_pending(&port
->tx_timer
) && !port
->removed
) {
280 port
->tx_timer
.expires
= (jiffies
+ 1);
281 add_timer(&port
->tx_timer
);
285 static int vcc_rx_check(struct tty_struct
*tty
, int size
)
287 if (WARN_ON(!tty
|| !tty
->port
))
290 /* tty_buffer_request_room won't sleep because it uses
291 * GFP_ATOMIC flag to allocate buffer
293 if (test_bit(TTY_THROTTLED
, &tty
->flags
) ||
294 (tty_buffer_request_room(tty
->port
, VCC_BUFF_LEN
) < VCC_BUFF_LEN
))
300 static int vcc_rx(struct tty_struct
*tty
, char *buf
, int size
)
304 if (WARN_ON(!tty
|| !tty
->port
))
307 len
= tty_insert_flip_string(tty
->port
, buf
, size
);
309 tty_flip_buffer_push(tty
->port
);
314 static int vcc_ldc_read(struct vcc_port
*port
)
316 struct vio_driver_state
*vio
= &port
->vio
;
317 struct tty_struct
*tty
;
323 rv
= ldc_rx_reset(vio
->lp
);
324 vccdbg("VCC: reset rx q: rv=%d\n", rv
);
328 /* Read as long as LDC has incoming data. */
330 if (!vcc_rx_check(tty
, VIO_VCC_MTU_SIZE
)) {
337 rv
= ldc_read(vio
->lp
, &pkt
, sizeof(pkt
));
341 vccdbg("VCC: ldc_read()=%d\n", rv
);
342 vccdbg("TAG [%02x:%02x:%04x:%08x]\n",
343 pkt
.tag
.type
, pkt
.tag
.stype
,
344 pkt
.tag
.stype_env
, pkt
.tag
.sid
);
346 if (pkt
.tag
.type
== VIO_TYPE_DATA
) {
348 /* vcc_rx_check ensures memory availability */
349 vcc_rx(tty
, pkt
.data
, pkt
.tag
.stype
);
351 pr_err("VCC: unknown msg [%02x:%02x:%04x:%08x]\n",
352 pkt
.tag
.type
, pkt
.tag
.stype
,
353 pkt
.tag
.stype_env
, pkt
.tag
.sid
);
358 WARN_ON(rv
!= LDC_PACKET_SIZE
);
365 static void vcc_rx_timer(struct timer_list
*t
)
367 struct vcc_port
*port
= from_timer(port
, t
, rx_timer
);
368 struct vio_driver_state
*vio
;
372 spin_lock_irqsave(&port
->lock
, flags
);
373 port
->rx_timer
.expires
= 0;
377 enable_irq(vio
->vdev
->rx_irq
);
379 if (!port
->tty
|| port
->removed
)
382 rv
= vcc_ldc_read(port
);
383 if (rv
== -ECONNRESET
)
387 spin_unlock_irqrestore(&port
->lock
, flags
);
388 vcc_put(port
, false);
391 static void vcc_tx_timer(struct timer_list
*t
)
393 struct vcc_port
*port
= from_timer(port
, t
, tx_timer
);
399 spin_lock_irqsave(&port
->lock
, flags
);
400 port
->tx_timer
.expires
= 0;
402 if (!port
->tty
|| port
->removed
)
405 tosend
= min(VCC_BUFF_LEN
, port
->chars_in_buffer
);
410 pkt
->tag
.type
= VIO_TYPE_DATA
;
411 pkt
->tag
.stype
= tosend
;
412 vccdbgl(port
->vio
.lp
);
414 rv
= ldc_write(port
->vio
.lp
, pkt
, (VIO_TAG_SIZE
+ tosend
));
418 vccdbg("VCC: ldc_write()=%d\n", rv
);
421 struct tty_struct
*tty
= port
->tty
;
423 port
->chars_in_buffer
= 0;
429 spin_unlock_irqrestore(&port
->lock
, flags
);
430 vcc_put(port
, false);
434 * vcc_event() - LDC event processing engine
435 * @arg: VCC private data
438 * Handles LDC events for VCC
440 static void vcc_event(void *arg
, int event
)
442 struct vio_driver_state
*vio
;
443 struct vcc_port
*port
;
450 spin_lock_irqsave(&port
->lock
, flags
);
453 case LDC_EVENT_RESET
:
455 vio_link_state_change(vio
, event
);
458 case LDC_EVENT_DATA_READY
:
459 rv
= vcc_ldc_read(port
);
460 if (rv
== -ECONNRESET
)
465 pr_err("VCC: unexpected LDC event(%d)\n", event
);
468 spin_unlock_irqrestore(&port
->lock
, flags
);
471 static struct ldc_channel_config vcc_ldc_cfg
= {
473 .mtu
= VIO_VCC_MTU_SIZE
,
474 .mode
= LDC_MODE_RAW
,
478 /* Ordered from largest major to lowest */
479 static struct vio_version vcc_versions
[] = {
480 { .major
= 1, .minor
= 0 },
483 static struct tty_port_operations vcc_port_ops
= { 0 };
485 static ssize_t
vcc_sysfs_domain_show(struct device
*dev
,
486 struct device_attribute
*attr
,
489 struct vcc_port
*port
;
492 port
= dev_get_drvdata(dev
);
496 rv
= scnprintf(buf
, PAGE_SIZE
, "%s\n", port
->domain
);
501 static int vcc_send_ctl(struct vcc_port
*port
, int ctl
)
506 pkt
.tag
.type
= VIO_TYPE_CTRL
;
510 rv
= ldc_write(port
->vio
.lp
, &pkt
, sizeof(pkt
.tag
));
512 vccdbg("VCC: ldc_write(%ld)=%d\n", sizeof(pkt
.tag
), rv
);
517 static ssize_t
vcc_sysfs_break_store(struct device
*dev
,
518 struct device_attribute
*attr
,
519 const char *buf
, size_t count
)
521 struct vcc_port
*port
;
526 port
= dev_get_drvdata(dev
);
530 spin_lock_irqsave(&port
->lock
, flags
);
532 if (sscanf(buf
, "%ud", &brk
) != 1 || brk
!= 1)
534 else if (vcc_send_ctl(port
, VCC_CTL_BREAK
) < 0)
537 spin_unlock_irqrestore(&port
->lock
, flags
);
542 static DEVICE_ATTR(domain
, 0400, vcc_sysfs_domain_show
, NULL
);
543 static DEVICE_ATTR(break, 0200, NULL
, vcc_sysfs_break_store
);
545 static struct attribute
*vcc_sysfs_entries
[] = {
546 &dev_attr_domain
.attr
,
547 &dev_attr_break
.attr
,
551 static struct attribute_group vcc_attribute_group
= {
553 .attrs
= vcc_sysfs_entries
,
557 * vcc_probe() - Initialize VCC port
558 * @vdev: Pointer to VIO device of the new VCC port
561 * Initializes a VCC port to receive serial console data from
562 * the guest domain. Sets up a TTY end point on the control
563 * domain. Sets up VIO/LDC link between the guest & control
566 * Return: status of the probe
568 static int vcc_probe(struct vio_dev
*vdev
, const struct vio_device_id
*id
)
570 struct mdesc_handle
*hp
;
571 struct vcc_port
*port
;
578 vccdbg("VCC: name=%s\n", dev_name(&vdev
->dev
));
580 if (!vcc_tty_driver
) {
581 pr_err("VCC: TTY driver not registered\n");
585 port
= kzalloc(sizeof(struct vcc_port
), GFP_KERNEL
);
589 name
= kstrdup(dev_name(&vdev
->dev
), GFP_KERNEL
);
591 rv
= vio_driver_init(&port
->vio
, vdev
, VDEV_CONSOLE_CON
, vcc_versions
,
592 ARRAY_SIZE(vcc_versions
), NULL
, name
);
596 port
->vio
.debug
= vcc_dbg_vio
;
597 vcc_ldc_cfg
.debug
= vcc_dbg_ldc
;
599 rv
= vio_ldc_alloc(&port
->vio
, &vcc_ldc_cfg
, port
);
603 spin_lock_init(&port
->lock
);
605 port
->index
= vcc_table_add(port
);
606 if (port
->index
== -1) {
607 pr_err("VCC: no more TTY indices left for allocation\n");
612 /* Register the device using VCC table index as TTY index */
613 dev
= tty_register_device(vcc_tty_driver
, port
->index
, &vdev
->dev
);
621 node
= vio_vdev_node(hp
, vdev
);
622 if (node
== MDESC_NODE_NULL
) {
628 domain
= mdesc_get_property(hp
, node
, "vcc-domain-name", NULL
);
634 port
->domain
= kstrdup(domain
, GFP_KERNEL
);
638 rv
= sysfs_create_group(&vdev
->dev
.kobj
, &vcc_attribute_group
);
642 timer_setup(&port
->rx_timer
, vcc_rx_timer
, 0);
643 timer_setup(&port
->tx_timer
, vcc_tx_timer
, 0);
645 dev_set_drvdata(&vdev
->dev
, port
);
647 /* It's possible to receive IRQs in the middle of vio_port_up. Disable
648 * IRQs until the port is up.
650 disable_irq_nosync(vdev
->rx_irq
);
651 vio_port_up(&port
->vio
);
652 enable_irq(vdev
->rx_irq
);
659 tty_unregister_device(vcc_tty_driver
, port
->index
);
661 vcc_table_remove(port
->index
);
663 vio_ldc_free(&port
->vio
);
672 * vcc_remove() - Terminate a VCC port
673 * @vdev: Pointer to VIO device of the VCC port
675 * Terminates a VCC port. Sets up the teardown of TTY and
676 * VIO/LDC link between guest and primary domains.
678 * Return: status of removal
680 static int vcc_remove(struct vio_dev
*vdev
)
682 struct vcc_port
*port
= dev_get_drvdata(&vdev
->dev
);
687 del_timer_sync(&port
->rx_timer
);
688 del_timer_sync(&port
->tx_timer
);
690 /* If there's a process with the device open, do a synchronous
691 * hangup of the TTY. This *may* cause the process to call close
692 * asynchronously, but it's not guaranteed.
695 tty_vhangup(port
->tty
);
697 /* Get exclusive reference to VCC, ensures that there are no other
698 * clients to this port
700 port
= vcc_get(port
->index
, true);
705 tty_unregister_device(vcc_tty_driver
, port
->index
);
707 del_timer_sync(&port
->vio
.timer
);
708 vio_ldc_free(&port
->vio
);
709 sysfs_remove_group(&vdev
->dev
.kobj
, &vcc_attribute_group
);
710 dev_set_drvdata(&vdev
->dev
, NULL
);
712 port
->removed
= true;
715 vcc_table_remove(port
->index
);
717 kfree(port
->vio
.name
);
725 static const struct vio_device_id vcc_match
[] = {
731 MODULE_DEVICE_TABLE(vio
, vcc_match
);
733 static struct vio_driver vcc_driver
= {
734 .id_table
= vcc_match
,
736 .remove
= vcc_remove
,
740 static int vcc_open(struct tty_struct
*tty
, struct file
*vcc_file
)
742 struct vcc_port
*port
;
744 if (unlikely(!tty
)) {
745 pr_err("VCC: open: Invalid TTY handle\n");
752 port
= vcc_get_ne(tty
->index
);
753 if (unlikely(!port
)) {
754 pr_err("VCC: open: Failed to find VCC port\n");
758 if (unlikely(!port
->vio
.lp
)) {
759 pr_err("VCC: open: LDC channel not configured\n");
760 vcc_put(port
, false);
763 vccdbgl(port
->vio
.lp
);
765 vcc_put(port
, false);
767 if (unlikely(!tty
->port
)) {
768 pr_err("VCC: open: TTY port not found\n");
772 if (unlikely(!tty
->port
->ops
)) {
773 pr_err("VCC: open: TTY ops not defined\n");
777 return tty_port_open(tty
->port
, tty
, vcc_file
);
780 static void vcc_close(struct tty_struct
*tty
, struct file
*vcc_file
)
782 if (unlikely(!tty
)) {
783 pr_err("VCC: close: Invalid TTY handle\n");
787 if (unlikely(tty
->count
> 1))
790 if (unlikely(!tty
->port
)) {
791 pr_err("VCC: close: TTY port not found\n");
795 tty_port_close(tty
->port
, tty
, vcc_file
);
798 static void vcc_ldc_hup(struct vcc_port
*port
)
802 spin_lock_irqsave(&port
->lock
, flags
);
804 if (vcc_send_ctl(port
, VCC_CTL_HUP
) < 0)
807 spin_unlock_irqrestore(&port
->lock
, flags
);
810 static void vcc_hangup(struct tty_struct
*tty
)
812 struct vcc_port
*port
;
814 if (unlikely(!tty
)) {
815 pr_err("VCC: hangup: Invalid TTY handle\n");
819 port
= vcc_get_ne(tty
->index
);
820 if (unlikely(!port
)) {
821 pr_err("VCC: hangup: Failed to find VCC port\n");
825 if (unlikely(!tty
->port
)) {
826 pr_err("VCC: hangup: TTY port not found\n");
827 vcc_put(port
, false);
833 vcc_put(port
, false);
835 tty_port_hangup(tty
->port
);
838 static int vcc_write(struct tty_struct
*tty
, const unsigned char *buf
,
841 struct vcc_port
*port
;
848 if (unlikely(!tty
)) {
849 pr_err("VCC: write: Invalid TTY handle\n");
853 port
= vcc_get_ne(tty
->index
);
854 if (unlikely(!port
)) {
855 pr_err("VCC: write: Failed to find VCC port");
859 spin_lock_irqsave(&port
->lock
, flags
);
862 pkt
->tag
.type
= VIO_TYPE_DATA
;
865 /* Minimum of data to write and space available */
866 tosend
= min(count
, (VCC_BUFF_LEN
- port
->chars_in_buffer
));
871 memcpy(&pkt
->data
[port
->chars_in_buffer
], &buf
[total_sent
],
873 port
->chars_in_buffer
+= tosend
;
874 pkt
->tag
.stype
= tosend
;
876 vccdbg("TAG [%02x:%02x:%04x:%08x]\n", pkt
->tag
.type
,
877 pkt
->tag
.stype
, pkt
->tag
.stype_env
, pkt
->tag
.sid
);
878 vccdbg("DATA [%s]\n", pkt
->data
);
879 vccdbgl(port
->vio
.lp
);
881 /* Since we know we have enough room in VCC buffer for tosend
882 * we record that it was sent regardless of whether the
883 * hypervisor actually took it because we have it buffered.
885 rv
= ldc_write(port
->vio
.lp
, pkt
, (VIO_TAG_SIZE
+ tosend
));
886 vccdbg("VCC: write: ldc_write(%d)=%d\n",
887 (VIO_TAG_SIZE
+ tosend
), rv
);
889 total_sent
+= tosend
;
896 port
->chars_in_buffer
= 0;
899 spin_unlock_irqrestore(&port
->lock
, flags
);
901 vcc_put(port
, false);
903 vccdbg("VCC: write: total=%d rv=%d", total_sent
, rv
);
905 return total_sent
? total_sent
: rv
;
908 static int vcc_write_room(struct tty_struct
*tty
)
910 struct vcc_port
*port
;
913 if (unlikely(!tty
)) {
914 pr_err("VCC: write_room: Invalid TTY handle\n");
918 port
= vcc_get_ne(tty
->index
);
919 if (unlikely(!port
)) {
920 pr_err("VCC: write_room: Failed to find VCC port\n");
924 num
= VCC_BUFF_LEN
- port
->chars_in_buffer
;
926 vcc_put(port
, false);
931 static int vcc_chars_in_buffer(struct tty_struct
*tty
)
933 struct vcc_port
*port
;
936 if (unlikely(!tty
)) {
937 pr_err("VCC: chars_in_buffer: Invalid TTY handle\n");
941 port
= vcc_get_ne(tty
->index
);
942 if (unlikely(!port
)) {
943 pr_err("VCC: chars_in_buffer: Failed to find VCC port\n");
947 num
= port
->chars_in_buffer
;
949 vcc_put(port
, false);
954 static int vcc_break_ctl(struct tty_struct
*tty
, int state
)
956 struct vcc_port
*port
;
959 if (unlikely(!tty
)) {
960 pr_err("VCC: break_ctl: Invalid TTY handle\n");
964 port
= vcc_get_ne(tty
->index
);
965 if (unlikely(!port
)) {
966 pr_err("VCC: break_ctl: Failed to find VCC port\n");
972 vcc_put(port
, false);
976 spin_lock_irqsave(&port
->lock
, flags
);
978 if (vcc_send_ctl(port
, VCC_CTL_BREAK
) < 0)
981 spin_unlock_irqrestore(&port
->lock
, flags
);
983 vcc_put(port
, false);
988 static int vcc_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
990 struct vcc_port
*port_vcc
;
991 struct tty_port
*port_tty
;
994 if (unlikely(!tty
)) {
995 pr_err("VCC: install: Invalid TTY handle\n");
999 if (tty
->index
>= VCC_MAX_PORTS
)
1002 ret
= tty_standard_install(driver
, tty
);
1006 port_tty
= kzalloc(sizeof(struct tty_port
), GFP_KERNEL
);
1010 port_vcc
= vcc_get(tty
->index
, true);
1012 pr_err("VCC: install: Failed to find VCC port\n");
1018 tty_port_init(port_tty
);
1019 port_tty
->ops
= &vcc_port_ops
;
1020 tty
->port
= port_tty
;
1022 port_vcc
->tty
= tty
;
1024 vcc_put(port_vcc
, true);
1029 static void vcc_cleanup(struct tty_struct
*tty
)
1031 struct vcc_port
*port
;
1033 if (unlikely(!tty
)) {
1034 pr_err("VCC: cleanup: Invalid TTY handle\n");
1038 port
= vcc_get(tty
->index
, true);
1042 if (port
->removed
) {
1043 vcc_table_remove(tty
->index
);
1044 kfree(port
->vio
.name
);
1045 kfree(port
->domain
);
1048 vcc_put(port
, true);
1052 tty_port_destroy(tty
->port
);
1057 static const struct tty_operations vcc_ops
= {
1060 .hangup
= vcc_hangup
,
1062 .write_room
= vcc_write_room
,
1063 .chars_in_buffer
= vcc_chars_in_buffer
,
1064 .break_ctl
= vcc_break_ctl
,
1065 .install
= vcc_install
,
1066 .cleanup
= vcc_cleanup
,
1069 #define VCC_TTY_FLAGS (TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_REAL_RAW)
1071 static int vcc_tty_init(void)
1075 pr_info("VCC: %s\n", version
);
1077 vcc_tty_driver
= tty_alloc_driver(VCC_MAX_PORTS
, VCC_TTY_FLAGS
);
1078 if (IS_ERR(vcc_tty_driver
)) {
1079 pr_err("VCC: TTY driver alloc failed\n");
1080 return PTR_ERR(vcc_tty_driver
);
1083 vcc_tty_driver
->driver_name
= vcc_driver_name
;
1084 vcc_tty_driver
->name
= vcc_device_node
;
1086 vcc_tty_driver
->minor_start
= VCC_MINOR_START
;
1087 vcc_tty_driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
1088 vcc_tty_driver
->init_termios
= vcc_tty_termios
;
1090 tty_set_operations(vcc_tty_driver
, &vcc_ops
);
1092 rv
= tty_register_driver(vcc_tty_driver
);
1094 pr_err("VCC: TTY driver registration failed\n");
1095 put_tty_driver(vcc_tty_driver
);
1096 vcc_tty_driver
= NULL
;
1100 vccdbg("VCC: TTY driver registered\n");
1105 static void vcc_tty_exit(void)
1107 tty_unregister_driver(vcc_tty_driver
);
1108 put_tty_driver(vcc_tty_driver
);
1109 vccdbg("VCC: TTY driver unregistered\n");
1111 vcc_tty_driver
= NULL
;
1114 static int __init
vcc_init(void)
1118 rv
= vcc_tty_init();
1120 pr_err("VCC: TTY init failed\n");
1124 rv
= vio_register_driver(&vcc_driver
);
1126 pr_err("VCC: VIO driver registration failed\n");
1129 vccdbg("VCC: VIO driver registered successfully\n");
1135 static void __exit
vcc_exit(void)
1137 vio_unregister_driver(&vcc_driver
);
1138 vccdbg("VCC: VIO driver unregistered\n");
1140 vccdbg("VCC: TTY driver unregistered\n");
1143 module_init(vcc_init
);
1144 module_exit(vcc_exit
);