Lines Matching full:port
51 /* Microseconds that thread will delay waiting for a vcc port ref */
115 * vcc_table_add() - Add VCC port to the VCC table
116 * @port: pointer to the VCC port
118 * Return: index of the port in the VCC table on success,
121 static int vcc_table_add(struct vcc_port *port) in vcc_table_add() argument
129 vcc_table[i] = port; in vcc_table_add()
142 * vcc_table_remove() - Removes a VCC port from the VCC table
158 * vcc_get() - Gets a reference to VCC port
162 * Return: reference to the VCC port, if found
163 * NULL, if port not found
167 struct vcc_port *port; in vcc_get() local
173 port = vcc_table[index]; in vcc_get()
174 if (!port) { in vcc_get()
180 if (port->excl_locked) { in vcc_get()
185 port->refcnt++; in vcc_get()
187 return port; in vcc_get()
190 if (port->refcnt) { in vcc_get()
200 port->refcnt++; in vcc_get()
201 port->excl_locked = true; in vcc_get()
204 return port; in vcc_get()
208 * vcc_put() - Returns a reference to VCC port
209 * @port: pointer to VCC port
215 static void vcc_put(struct vcc_port *port, bool excl) in vcc_put() argument
219 if (!port) in vcc_put()
225 if (WARN_ON((excl && !port->excl_locked) || in vcc_put()
226 (!excl && port->excl_locked))) in vcc_put()
229 port->refcnt--; in vcc_put()
232 port->excl_locked = false; in vcc_put()
239 * vcc_get_ne() - Get a non-exclusive reference to VCC port
242 * Gets a non-exclusive reference to VCC port, if it's not removed
244 * Return: pointer to the VCC port, if found
245 * NULL, if port not found
249 struct vcc_port *port; in vcc_get_ne() local
251 port = vcc_get(index, false); in vcc_get_ne()
253 if (port && port->removed) { in vcc_get_ne()
254 vcc_put(port, false); in vcc_get_ne()
258 return port; in vcc_get_ne()
261 static void vcc_kick_rx(struct vcc_port *port) in vcc_kick_rx() argument
263 struct vio_driver_state *vio = &port->vio; in vcc_kick_rx()
265 assert_spin_locked(&port->lock); in vcc_kick_rx()
267 if (!timer_pending(&port->rx_timer) && !port->removed) { in vcc_kick_rx()
269 port->rx_timer.expires = (jiffies + 1); in vcc_kick_rx()
270 add_timer(&port->rx_timer); in vcc_kick_rx()
274 static void vcc_kick_tx(struct vcc_port *port) in vcc_kick_tx() argument
276 assert_spin_locked(&port->lock); in vcc_kick_tx()
278 if (!timer_pending(&port->tx_timer) && !port->removed) { in vcc_kick_tx()
279 port->tx_timer.expires = (jiffies + 1); in vcc_kick_tx()
280 add_timer(&port->tx_timer); in vcc_kick_tx()
286 if (WARN_ON(!tty || !tty->port)) in vcc_rx_check()
293 (tty_buffer_request_room(tty->port, VCC_BUFF_LEN) < VCC_BUFF_LEN)) in vcc_rx_check()
303 if (WARN_ON(!tty || !tty->port)) in vcc_rx()
306 len = tty_insert_flip_string(tty->port, buf, size); in vcc_rx()
308 tty_flip_buffer_push(tty->port); in vcc_rx()
313 static int vcc_ldc_read(struct vcc_port *port) in vcc_ldc_read() argument
315 struct vio_driver_state *vio = &port->vio; in vcc_ldc_read()
320 tty = port->tty; in vcc_ldc_read()
330 vcc_kick_rx(port); in vcc_ldc_read()
366 struct vcc_port *port = from_timer(port, t, rx_timer); in vcc_rx_timer() local
371 spin_lock_irqsave(&port->lock, flags); in vcc_rx_timer()
372 port->rx_timer.expires = 0; in vcc_rx_timer()
374 vio = &port->vio; in vcc_rx_timer()
378 if (!port->tty || port->removed) in vcc_rx_timer()
381 rv = vcc_ldc_read(port); in vcc_rx_timer()
386 spin_unlock_irqrestore(&port->lock, flags); in vcc_rx_timer()
387 vcc_put(port, false); in vcc_rx_timer()
392 struct vcc_port *port = from_timer(port, t, tx_timer); in vcc_tx_timer() local
398 spin_lock_irqsave(&port->lock, flags); in vcc_tx_timer()
399 port->tx_timer.expires = 0; in vcc_tx_timer()
401 if (!port->tty || port->removed) in vcc_tx_timer()
404 tosend = min(VCC_BUFF_LEN, port->chars_in_buffer); in vcc_tx_timer()
408 pkt = &port->buffer; in vcc_tx_timer()
411 vccdbgl(port->vio.lp); in vcc_tx_timer()
413 rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend)); in vcc_tx_timer()
418 vcc_kick_tx(port); in vcc_tx_timer()
420 struct tty_struct *tty = port->tty; in vcc_tx_timer()
422 port->chars_in_buffer = 0; in vcc_tx_timer()
428 spin_unlock_irqrestore(&port->lock, flags); in vcc_tx_timer()
429 vcc_put(port, false); in vcc_tx_timer()
442 struct vcc_port *port; in vcc_event() local
446 port = arg; in vcc_event()
447 vio = &port->vio; in vcc_event()
449 spin_lock_irqsave(&port->lock, flags); in vcc_event()
458 rv = vcc_ldc_read(port); in vcc_event()
467 spin_unlock_irqrestore(&port->lock, flags); in vcc_event()
488 struct vcc_port *port; in vcc_sysfs_domain_show() local
491 port = dev_get_drvdata(dev); in vcc_sysfs_domain_show()
492 if (!port) in vcc_sysfs_domain_show()
495 rv = scnprintf(buf, PAGE_SIZE, "%s\n", port->domain); in vcc_sysfs_domain_show()
500 static int vcc_send_ctl(struct vcc_port *port, int ctl) in vcc_send_ctl() argument
509 rv = ldc_write(port->vio.lp, &pkt, sizeof(pkt.tag)); in vcc_send_ctl()
520 struct vcc_port *port; in vcc_sysfs_break_store() local
525 port = dev_get_drvdata(dev); in vcc_sysfs_break_store()
526 if (!port) in vcc_sysfs_break_store()
529 spin_lock_irqsave(&port->lock, flags); in vcc_sysfs_break_store()
533 else if (vcc_send_ctl(port, VCC_CTL_BREAK) < 0) in vcc_sysfs_break_store()
534 vcc_kick_tx(port); in vcc_sysfs_break_store()
536 spin_unlock_irqrestore(&port->lock, flags); in vcc_sysfs_break_store()
556 * vcc_probe() - Initialize VCC port
557 * @vdev: Pointer to VIO device of the new VCC port
560 * Initializes a VCC port to receive serial console data from
570 struct vcc_port *port; in vcc_probe() local
584 port = kzalloc(sizeof(struct vcc_port), GFP_KERNEL); in vcc_probe()
585 if (!port) in vcc_probe()
590 rv = vio_driver_init(&port->vio, vdev, VDEV_CONSOLE_CON, vcc_versions, in vcc_probe()
595 port->vio.debug = vcc_dbg_vio; in vcc_probe()
598 rv = vio_ldc_alloc(&port->vio, &vcc_ldc_cfg, port); in vcc_probe()
602 spin_lock_init(&port->lock); in vcc_probe()
604 port->index = vcc_table_add(port); in vcc_probe()
605 if (port->index == -1) { in vcc_probe()
612 dev = tty_register_device(vcc_tty_driver, port->index, &vdev->dev); in vcc_probe()
633 port->domain = kstrdup(domain, GFP_KERNEL); in vcc_probe()
641 timer_setup(&port->rx_timer, vcc_rx_timer, 0); in vcc_probe()
642 timer_setup(&port->tx_timer, vcc_tx_timer, 0); in vcc_probe()
644 dev_set_drvdata(&vdev->dev, port); in vcc_probe()
647 * IRQs until the port is up. in vcc_probe()
650 vio_port_up(&port->vio); in vcc_probe()
656 kfree(port->domain); in vcc_probe()
658 tty_unregister_device(vcc_tty_driver, port->index); in vcc_probe()
660 vcc_table_remove(port->index); in vcc_probe()
662 vio_ldc_free(&port->vio); in vcc_probe()
665 kfree(port); in vcc_probe()
671 * vcc_remove() - Terminate a VCC port
672 * @vdev: Pointer to VIO device of the VCC port
674 * Terminates a VCC port. Sets up the teardown of TTY and
681 struct vcc_port *port = dev_get_drvdata(&vdev->dev); in vcc_remove() local
683 if (!port) in vcc_remove()
686 del_timer_sync(&port->rx_timer); in vcc_remove()
687 del_timer_sync(&port->tx_timer); in vcc_remove()
693 if (port->tty) in vcc_remove()
694 tty_vhangup(port->tty); in vcc_remove()
697 * clients to this port in vcc_remove()
699 port = vcc_get(port->index, true); in vcc_remove()
701 if (WARN_ON(!port)) in vcc_remove()
704 tty_unregister_device(vcc_tty_driver, port->index); in vcc_remove()
706 del_timer_sync(&port->vio.timer); in vcc_remove()
707 vio_ldc_free(&port->vio); in vcc_remove()
710 if (port->tty) { in vcc_remove()
711 port->removed = true; in vcc_remove()
712 vcc_put(port, true); in vcc_remove()
714 vcc_table_remove(port->index); in vcc_remove()
716 kfree(port->vio.name); in vcc_remove()
717 kfree(port->domain); in vcc_remove()
718 kfree(port); in vcc_remove()
726 .type = "vcc-port",
741 struct vcc_port *port; in vcc_open() local
751 port = vcc_get_ne(tty->index); in vcc_open()
752 if (unlikely(!port)) { in vcc_open()
753 pr_err("VCC: open: Failed to find VCC port\n"); in vcc_open()
757 if (unlikely(!port->vio.lp)) { in vcc_open()
759 vcc_put(port, false); in vcc_open()
762 vccdbgl(port->vio.lp); in vcc_open()
764 vcc_put(port, false); in vcc_open()
766 if (unlikely(!tty->port)) { in vcc_open()
767 pr_err("VCC: open: TTY port not found\n"); in vcc_open()
771 if (unlikely(!tty->port->ops)) { in vcc_open()
776 return tty_port_open(tty->port, tty, vcc_file); in vcc_open()
789 if (unlikely(!tty->port)) { in vcc_close()
790 pr_err("VCC: close: TTY port not found\n"); in vcc_close()
794 tty_port_close(tty->port, tty, vcc_file); in vcc_close()
797 static void vcc_ldc_hup(struct vcc_port *port) in vcc_ldc_hup() argument
801 spin_lock_irqsave(&port->lock, flags); in vcc_ldc_hup()
803 if (vcc_send_ctl(port, VCC_CTL_HUP) < 0) in vcc_ldc_hup()
804 vcc_kick_tx(port); in vcc_ldc_hup()
806 spin_unlock_irqrestore(&port->lock, flags); in vcc_ldc_hup()
811 struct vcc_port *port; in vcc_hangup() local
818 port = vcc_get_ne(tty->index); in vcc_hangup()
819 if (unlikely(!port)) { in vcc_hangup()
820 pr_err("VCC: hangup: Failed to find VCC port\n"); in vcc_hangup()
824 if (unlikely(!tty->port)) { in vcc_hangup()
825 pr_err("VCC: hangup: TTY port not found\n"); in vcc_hangup()
826 vcc_put(port, false); in vcc_hangup()
830 vcc_ldc_hup(port); in vcc_hangup()
832 vcc_put(port, false); in vcc_hangup()
834 tty_port_hangup(tty->port); in vcc_hangup()
840 struct vcc_port *port; in vcc_write() local
852 port = vcc_get_ne(tty->index); in vcc_write()
853 if (unlikely(!port)) { in vcc_write()
854 pr_err("VCC: write: Failed to find VCC port"); in vcc_write()
858 spin_lock_irqsave(&port->lock, flags); in vcc_write()
860 pkt = &port->buffer; in vcc_write()
865 tosend = min(count, (VCC_BUFF_LEN - port->chars_in_buffer)); in vcc_write()
870 memcpy(&pkt->data[port->chars_in_buffer], &buf[total_sent], in vcc_write()
872 port->chars_in_buffer += tosend; in vcc_write()
878 vccdbgl(port->vio.lp); in vcc_write()
884 rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend)); in vcc_write()
891 vcc_kick_tx(port); in vcc_write()
895 port->chars_in_buffer = 0; in vcc_write()
898 spin_unlock_irqrestore(&port->lock, flags); in vcc_write()
900 vcc_put(port, false); in vcc_write()
909 struct vcc_port *port; in vcc_write_room() local
917 port = vcc_get_ne(tty->index); in vcc_write_room()
918 if (unlikely(!port)) { in vcc_write_room()
919 pr_err("VCC: write_room: Failed to find VCC port\n"); in vcc_write_room()
923 num = VCC_BUFF_LEN - port->chars_in_buffer; in vcc_write_room()
925 vcc_put(port, false); in vcc_write_room()
932 struct vcc_port *port; in vcc_chars_in_buffer() local
940 port = vcc_get_ne(tty->index); in vcc_chars_in_buffer()
941 if (unlikely(!port)) { in vcc_chars_in_buffer()
942 pr_err("VCC: chars_in_buffer: Failed to find VCC port\n"); in vcc_chars_in_buffer()
946 num = port->chars_in_buffer; in vcc_chars_in_buffer()
948 vcc_put(port, false); in vcc_chars_in_buffer()
955 struct vcc_port *port; in vcc_break_ctl() local
963 port = vcc_get_ne(tty->index); in vcc_break_ctl()
964 if (unlikely(!port)) { in vcc_break_ctl()
965 pr_err("VCC: break_ctl: Failed to find VCC port\n"); in vcc_break_ctl()
971 vcc_put(port, false); in vcc_break_ctl()
975 spin_lock_irqsave(&port->lock, flags); in vcc_break_ctl()
977 if (vcc_send_ctl(port, VCC_CTL_BREAK) < 0) in vcc_break_ctl()
978 vcc_kick_tx(port); in vcc_break_ctl()
980 spin_unlock_irqrestore(&port->lock, flags); in vcc_break_ctl()
982 vcc_put(port, false); in vcc_break_ctl()
1011 pr_err("VCC: install: Failed to find VCC port\n"); in vcc_install()
1012 tty->port = NULL; in vcc_install()
1019 tty->port = port_tty; in vcc_install()
1030 struct vcc_port *port; in vcc_cleanup() local
1037 port = vcc_get(tty->index, true); in vcc_cleanup()
1038 if (port) { in vcc_cleanup()
1039 port->tty = NULL; in vcc_cleanup()
1041 if (port->removed) { in vcc_cleanup()
1043 kfree(port->vio.name); in vcc_cleanup()
1044 kfree(port->domain); in vcc_cleanup()
1045 kfree(port); in vcc_cleanup()
1047 vcc_put(port, true); in vcc_cleanup()
1051 tty_port_destroy(tty->port); in vcc_cleanup()
1052 kfree(tty->port); in vcc_cleanup()
1053 tty->port = NULL; in vcc_cleanup()