static void qt_break(struct tty_struct *tty, int break_state) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; u16 index, onoff; unsigned int result; index = tty->index - serial->minor; qt_port = qt_get_port_private(port); if (break_state == -1) onoff = 1; else onoff = 0; mutex_lock(&qt_port->lock); result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), QT_BREAK_CONTROL, 0x40, onoff, index, NULL, 0, 300); mutex_unlock(&qt_port->lock); }
static void ir_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); --port->open_count; if (port->open_count <= 0) { if (serial->dev) { /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } port->active = 0; port->open_count = 0; } up (&port->sem); MOD_DEC_USE_COUNT; }
static void qt_unthrottle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; if (!serial) return; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); if (qt_port->RxHolding == 1) { dev_dbg(&port->dev, "%s -qt_port->RxHolding == 1\n", __func__); qt_port->RxHolding = 0; dev_dbg(&port->dev, "%s - qt_port->RxHolding = 0\n", __func__); /* if we have a bulk endpoint, start it up */ if ((serial->num_bulk_in) && (qt_port->ReadBulkStopped == 1)) qt_submit_urb_from_unthrottle(port, serial); } mutex_unlock(&qt_port->lock); }
static int qt_write_room(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial; struct quatech_port *qt_port; int retval = -EINVAL; if (port_paranoia_check(port, __func__)) return -1; serial = get_usb_serial(port, __func__); if (!serial) return -ENODEV; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); if (serial->num_bulk_out) { if (port->write_urb->status != -EINPROGRESS) retval = port->bulk_out_size; } mutex_unlock(&qt_port->lock); return retval; }
static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); int retval = -EINVAL; if (!serial) return -ENODEV; down (&port->sem); dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); if (!port->open_count) { dbg("%s - port not opened", __FUNCTION__); goto exit; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->write) retval = serial->type->write(port, from_user, buf, count); else retval = generic_write(port, from_user, buf, count); exit: up (&port->sem); return retval; }
static int serial_chars_in_buffer (struct tty_struct *tty) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); int retval = -EINVAL; if (!serial) return -ENODEV; down (&port->sem); dbg("%s = port %d", __FUNCTION__, port->number); if (!port->open_count) { dbg("%s - port not open", __FUNCTION__); goto exit; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->chars_in_buffer) retval = serial->type->chars_in_buffer(port); else retval = generic_chars_in_buffer(port); exit: up (&port->sem); return retval; }
static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); int retval = -ENODEV; if (!serial) return -ENODEV; down (&port->sem); dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); if (!port->open_count) { dbg ("%s - port not open", __FUNCTION__); goto exit; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->ioctl) retval = serial->type->ioctl(port, file, cmd, arg); else retval = -ENOIOCTLCMD; exit: up (&port->sem); return retval; }
static void serial_close(struct tty_struct *tty, struct file * filp) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return; } dbg(__FUNCTION__ " - port %d", port->number); if (!port->open_count) { dbg (__FUNCTION__ " - port not opened"); return; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->close) { serial->type->close(port, filp); if (serial->type->owner) __MOD_DEC_USE_COUNT(serial->type->owner); } else { generic_close(port, filp); } }
static void visor_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; unsigned char *transfer_buffer; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; if (serial->dev) { /* only send a shutdown message if the * device is still here */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (!transfer_buffer) { err("%s - kmalloc(%d) failed.", __FUNCTION__, 0x12); } else { /* send a shutdown message to the device */ usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } /* shutdown our urbs */ usb_unlink_urb (port->read_urb); if (port->interrupt_in_urb) usb_unlink_urb (port->interrupt_in_urb); /* Try to send shutdown message, if the device is gone, this will just fail. */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (transfer_buffer) { usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } } /* Uncomment the following line if you want to see some statistics in your syslog */ info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); }
static void visor_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int i; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) { dbg("%s - bad serial pointer, exiting", __FUNCTION__); return; } if (urb->status) { dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status); return; } usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data); tty = port->tty; if (tty && urb->actual_length) { for (i = 0; i < urb->actual_length ; ++i) { /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ if(tty->flip.count >= TTY_FLIPBUF_SIZE) { tty_flip_buffer_push(tty); } /* this doesn't actually push the data through unless tty->low_latency is set */ tty_insert_flip_char(tty, data[i], 0); } tty_flip_buffer_push(tty); bytes_in += urb->actual_length; } /* Continue trying to always read */ usb_fill_bulk_urb (port->read_urb, serial->dev, usb_rcvbulkpipe (serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, visor_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result); return; }
static int qt_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { int result; struct usb_serial *serial = get_usb_serial(port, __func__); if (serial == NULL) return -ENODEV; if (count == 0) { dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); return 0; } /* only do something if we have a bulk out endpoint */ if (serial->num_bulk_out) { if (port->write_urb->status == -EINPROGRESS) { dev_dbg(&port->dev, "%s - already writing\n", __func__); return 0; } count = (count > port->bulk_out_size) ? port->bulk_out_size : count; memcpy(port->write_urb->transfer_buffer, buf, count); /* set up our urb */ usb_fill_bulk_urb(port->write_urb, serial->dev, usb_sndbulkpipe(serial->dev, port-> bulk_out_endpointAddress), port->write_urb->transfer_buffer, count, qt_write_bulk_callback, port); /* send the data out the bulk port */ result = usb_submit_urb(port->write_urb, GFP_ATOMIC); if (result) dev_dbg(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); else result = count; return result; } /* no bulk out, so return 0 bytes written */ return 0; }
static int qt_chars_in_buffer(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial; int chars = 0; serial = get_usb_serial(port, __func__); if (serial->num_bulk_out) { if (port->write_urb->status == -EINPROGRESS) chars = port->write_urb->transfer_buffer_length; } return chars; }
static int qt_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port = qt_get_port_private(port); int retval; if (!serial) return -ENODEV; mutex_lock(&qt_port->lock); retval = qt_real_tiocmget(tty, port, serial); mutex_unlock(&qt_port->lock); return retval; }
static int qt_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = tty->driver_data; struct quatech_port *qt_port = qt_get_port_private(port); struct usb_serial *serial = get_usb_serial(port, __func__); unsigned int index; dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); index = tty->index - serial->minor; if (cmd == TIOCMIWAIT) { while (qt_port != NULL) { interruptible_sleep_on(&qt_port->msr_wait); if (signal_pending(current)) return -ERESTARTSYS; else { char diff = qt_port->diff_status; if (diff == 0) return -EIO; /* no change => error */ /* Consume all events */ qt_port->diff_status = 0; if (((arg & TIOCM_RNG) && (diff & SERIAL_MSR_RI)) || ((arg & TIOCM_DSR) && (diff & SERIAL_MSR_DSR)) || ((arg & TIOCM_CD) && (diff & SERIAL_MSR_CD)) || ((arg & TIOCM_CTS) && (diff & SERIAL_MSR_CTS))) { return 0; } } } return 0; } dev_dbg(&port->dev, "%s -No ioctl for that one. port = %d\n", __func__, port->number); return -ENOIOCTLCMD; }
static void qt_throttle(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct usb_serial *serial = get_usb_serial(port, __func__); struct quatech_port *qt_port; if (!serial) return; qt_port = qt_get_port_private(port); mutex_lock(&qt_port->lock); /* pass on to the driver specific version of this function */ qt_port->RxHolding = 1; mutex_unlock(&qt_port->lock); }
static void visor_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; unsigned char *transfer_buffer; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); --port->open_count; if (port->open_count <= 0) { if (serial->dev) { /* only send a shutdown message if the * device is still here */ transfer_buffer = kmalloc (0x12, GFP_KERNEL); if (!transfer_buffer) { err(__FUNCTION__ " - kmalloc(%d) failed.", 0x12); } else { /* send a shutdown message to the device */ usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_CLOSE_NOTIFICATION, 0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300); kfree (transfer_buffer); } /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } port->open_count = 0; } up (&port->sem); /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ }
static void serial_close(struct tty_struct *tty, struct file * filp) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); dbg("%s - port %d", __FUNCTION__, port->number); /* if disconnect beat us to the punch here, there's nothing to do */ if (tty->driver_data) { __serial_close(port, filp); } up (&port->sem); }
static void empeg_close (struct usb_serial_port *port, struct file * filp) { struct usb_serial *serial; if (port_paranoia_check (port, __FUNCTION__)) return; dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; if (serial->dev) { /* shutdown our bulk read */ usb_unlink_urb (port->read_urb); } /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ }
static void ir_read_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; int result; if (port_paranoia_check (port, __FUNCTION__)) return; dbg(__FUNCTION__ " - port %d", port->number); if (!serial) { dbg(__FUNCTION__ " - bad serial pointer, exiting"); return; } if (urb->status) { dbg(__FUNCTION__ " - nonzero read bulk status received: %d", urb->status); return; } usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data); /* Bypass flip-buffers, and feed the ldisc directly due to our * potentally large buffer size. Since we used to set low_latency, * this is exactly what the tty layer did anyway :) */ tty = port->tty; tty->ldisc.receive_buf(tty, data+1, NULL, urb->actual_length-1); /* Continue trying to always read */ FILL_BULK_URB(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ir_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) err(__FUNCTION__ " - failed resubmitting read urb, error %d", result); return; }
static int serial_chars_in_buffer (struct tty_struct *tty) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return -ENODEV; } if (!port->active) { dbg (__FUNCTION__ " - port not open"); return -EINVAL; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->chars_in_buffer) { return (serial->type->chars_in_buffer(port)); } else { return (generic_chars_in_buffer(port)); } }
static void generic_write_bulk_callback (struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) { dbg("%s - bad serial pointer, exiting", __FUNCTION__); return; } if (urb->status) { dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status); return; } queue_task(&port->tqueue, &tq_immediate); mark_bh(IMMEDIATE_BH); return; }
static void serial_break (struct tty_struct *tty, int break_state) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return; } dbg(__FUNCTION__ " - port %d", port->number); if (!port->active) { dbg (__FUNCTION__ " - port not open"); return; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->break_ctl) { serial->type->break_ctl(port, break_state); } }
static int serial_write_room (struct tty_struct *tty) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return -ENODEV; } dbg(__FUNCTION__ " - port %d", port->number); if (!port->open_count) { dbg (__FUNCTION__ " - port not open"); return -EINVAL; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->write_room) { return (serial->type->write_room(port)); } else { return (generic_write_room(port)); } }
static void serial_set_termios (struct tty_struct *tty, struct termios * old) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return; } dbg(__FUNCTION__ " - port %d", port->number); if (!port->open_count) { dbg (__FUNCTION__ " - port not open"); return; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->set_termios) { serial->type->set_termios(port, old); } return; }
static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return -ENODEV; } dbg(__FUNCTION__ " - port %d, %d byte(s)", port->number, count); if (!port->active) { dbg (__FUNCTION__ " - port not opened"); return -EINVAL; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->write) { return (serial->type->write(port, from_user, buf, count)); } else { return (generic_write(port, from_user, buf, count)); } }
static void serial_unthrottle (struct tty_struct * tty) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return; } dbg(__FUNCTION__ " - port %d", port->number); if (!port->active) { dbg (__FUNCTION__ " - port not open"); return; } /* pass on to the driver specific version of this function */ if (serial->type->unthrottle) { serial->type->unthrottle(port); } return; }
static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) { return -ENODEV; } dbg(__FUNCTION__ " - port %d, cmd 0x%.4x", port->number, cmd); if (!port->active) { dbg (__FUNCTION__ " - port not open"); return -ENODEV; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->ioctl) { return (serial->type->ioctl(port, file, cmd, arg)); } else { return -ENOIOCTLCMD; } }
static void serial_break (struct tty_struct *tty, int break_state) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); dbg("%s - port %d", __FUNCTION__, port->number); if (!port->open_count) { dbg("%s - port not open", __FUNCTION__); goto exit; } /* pass on to the driver specific version of this function if it is available */ if (serial->type->break_ctl) serial->type->break_ctl(port, break_state); exit: up (&port->sem); }
static void serial_unthrottle (struct tty_struct * tty) { struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); if (!serial) return; down (&port->sem); dbg("%s - port %d", __FUNCTION__, port->number); if (!port->open_count) { dbg("%s - port not open", __FUNCTION__); goto exit; } /* pass on to the driver specific version of this function */ if (serial->type->unthrottle) serial->type->unthrottle(port); exit: up (&port->sem); }
static void generic_shutdown (struct usb_serial *serial) { int i; dbg("%s", __FUNCTION__); /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { generic_cleanup (&serial->port[i]); } } static void port_softint(void *private) { struct usb_serial_port *port = (struct usb_serial_port *)private; struct usb_serial *serial = get_usb_serial (port, __FUNCTION__); struct tty_struct *tty; dbg("%s - port %d", __FUNCTION__, port->number); if (!serial) return; tty = port->tty; if (!tty) return; if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) { dbg("%s - write wakeup call.", __FUNCTION__); (tty->ldisc.write_wakeup)(tty); }