Lines Matching +full:serial +full:- +full:number

1 // SPDX-License-Identifier: GPL-2.0
30 #include <linux/usb/serial.h>
41 #define MAX_TRANSFER (PAGE_SIZE - 512)
43 allocations > PAGE_SIZE and the number of packets in a page
50 size_t count; /* number of elements in array */
84 static int sierra_calc_num_ports(struct usb_serial *serial, in sierra_calc_num_ports() argument
90 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; in sierra_calc_num_ports()
91 numendpoints = serial->interface->cur_altsetting->desc.bNumEndpoints; in sierra_calc_num_ports()
99 num_ports = (numendpoints-1)/2; in sierra_calc_num_ports()
110 for (i = 0; i < list->count; i++) { in is_listed()
111 if (list->nums[i] == ifnum) in is_listed()
118 static u8 sierra_interface_num(struct usb_serial *serial) in sierra_interface_num() argument
120 return serial->interface->cur_altsetting->desc.bInterfaceNumber; in sierra_interface_num()
123 static int sierra_probe(struct usb_serial *serial, in sierra_probe() argument
131 udev = serial->dev; in sierra_probe()
132 ifnum = sierra_interface_num(serial); in sierra_probe()
138 if (serial->interface->num_altsetting == 2) { in sierra_probe()
139 dev_dbg(&udev->dev, "Selecting alt setting for interface %d\n", in sierra_probe()
145 ignore_list = (const struct sierra_iface_list *)id->driver_info; in sierra_probe()
148 dev_dbg(&serial->dev->dev, "Ignoring interface #%d\n", ifnum); in sierra_probe()
149 return -ENODEV; in sierra_probe()
243 /* Sierra Wireless HSPA Non-Composite Device */
270 int outstanding_urbs; /* number of out urbs in flight */
290 struct usb_serial *serial = port->serial; in sierra_send_setup() local
299 if (portdata->dtr_state) in sierra_send_setup()
301 if (portdata->rts_state) in sierra_send_setup()
305 if (serial->num_ports == 1) { in sierra_send_setup()
306 interface = sierra_interface_num(serial); in sierra_send_setup()
310 if (port->interrupt_in_urb) { in sierra_send_setup()
316 /* Otherwise the need to do non-composite mapping */ in sierra_send_setup()
318 if (port->bulk_out_endpointAddress == 2) in sierra_send_setup()
320 else if (port->bulk_out_endpointAddress == 4) in sierra_send_setup()
322 else if (port->bulk_out_endpointAddress == 5) in sierra_send_setup()
330 retval = usb_autopm_get_interface(serial->interface); in sierra_send_setup()
334 retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), in sierra_send_setup()
336 usb_autopm_put_interface(serial->interface); in sierra_send_setup()
343 struct usb_serial_port *port = tty->driver_data; in sierra_tiocmget()
349 value = ((portdata->rts_state) ? TIOCM_RTS : 0) | in sierra_tiocmget()
350 ((portdata->dtr_state) ? TIOCM_DTR : 0) | in sierra_tiocmget()
351 ((portdata->cts_state) ? TIOCM_CTS : 0) | in sierra_tiocmget()
352 ((portdata->dsr_state) ? TIOCM_DSR : 0) | in sierra_tiocmget()
353 ((portdata->dcd_state) ? TIOCM_CAR : 0) | in sierra_tiocmget()
354 ((portdata->ri_state) ? TIOCM_RNG : 0); in sierra_tiocmget()
362 struct usb_serial_port *port = tty->driver_data; in sierra_tiocmset()
368 portdata->rts_state = 1; in sierra_tiocmset()
370 portdata->dtr_state = 1; in sierra_tiocmset()
373 portdata->rts_state = 0; in sierra_tiocmset()
375 portdata->dtr_state = 0; in sierra_tiocmset()
382 kfree(urb->transfer_buffer); in sierra_release_urb()
389 struct usb_serial_port *port = urb->context; in sierra_outdat_callback()
392 int status = urb->status; in sierra_outdat_callback()
395 intfdata = usb_get_serial_data(port->serial); in sierra_outdat_callback()
398 kfree(urb->transfer_buffer); in sierra_outdat_callback()
399 usb_autopm_put_interface_async(port->serial->interface); in sierra_outdat_callback()
401 dev_dbg(&port->dev, "%s - nonzero write bulk status " in sierra_outdat_callback()
404 spin_lock_irqsave(&portdata->lock, flags); in sierra_outdat_callback()
405 --portdata->outstanding_urbs; in sierra_outdat_callback()
406 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_outdat_callback()
407 spin_lock_irqsave(&intfdata->susp_lock, flags); in sierra_outdat_callback()
408 --intfdata->in_flight; in sierra_outdat_callback()
409 spin_unlock_irqrestore(&intfdata->susp_lock, flags); in sierra_outdat_callback()
420 struct usb_serial *serial = port->serial; in sierra_write() local
432 intfdata = usb_get_serial_data(serial); in sierra_write()
434 dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); in sierra_write()
435 spin_lock_irqsave(&portdata->lock, flags); in sierra_write()
436 dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, in sierra_write()
437 portdata->outstanding_urbs); in sierra_write()
438 if (portdata->outstanding_urbs > portdata->num_out_urbs) { in sierra_write()
439 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write()
440 dev_dbg(&port->dev, "%s - write limit hit\n", __func__); in sierra_write()
443 portdata->outstanding_urbs++; in sierra_write()
444 dev_dbg(&port->dev, "%s - 1, outstanding_urbs: %d\n", __func__, in sierra_write()
445 portdata->outstanding_urbs); in sierra_write()
446 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write()
448 retval = usb_autopm_get_interface_async(serial->interface); in sierra_write()
450 spin_lock_irqsave(&portdata->lock, flags); in sierra_write()
451 portdata->outstanding_urbs--; in sierra_write()
452 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write()
458 retval = -ENOMEM; in sierra_write()
464 retval = -ENOMEM; in sierra_write()
468 usb_serial_debug_data(&port->dev, __func__, writesize, buffer); in sierra_write()
470 usb_fill_bulk_urb(urb, serial->dev, in sierra_write()
471 usb_sndbulkpipe(serial->dev, in sierra_write()
472 port->bulk_out_endpointAddress), in sierra_write()
476 urb->transfer_flags |= URB_ZERO_PACKET; in sierra_write()
478 spin_lock_irqsave(&intfdata->susp_lock, flags); in sierra_write()
480 if (intfdata->suspended) { in sierra_write()
481 usb_anchor_urb(urb, &portdata->delayed); in sierra_write()
482 spin_unlock_irqrestore(&intfdata->susp_lock, flags); in sierra_write()
485 usb_anchor_urb(urb, &portdata->active); in sierra_write()
491 spin_unlock_irqrestore(&intfdata->susp_lock, flags); in sierra_write()
492 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " in sierra_write()
496 intfdata->in_flight++; in sierra_write()
497 spin_unlock_irqrestore(&intfdata->susp_lock, flags); in sierra_write()
511 spin_lock_irqsave(&portdata->lock, flags); in sierra_write()
512 --portdata->outstanding_urbs; in sierra_write()
513 dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, in sierra_write()
514 portdata->outstanding_urbs); in sierra_write()
515 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write()
516 usb_autopm_put_interface_async(serial->interface); in sierra_write()
526 unsigned char *data = urb->transfer_buffer; in sierra_indat_callback()
527 int status = urb->status; in sierra_indat_callback()
529 endpoint = usb_pipeendpoint(urb->pipe); in sierra_indat_callback()
530 port = urb->context; in sierra_indat_callback()
533 dev_dbg(&port->dev, "%s: nonzero status: %d on" in sierra_indat_callback()
536 if (urb->actual_length) { in sierra_indat_callback()
537 tty_insert_flip_string(&port->port, data, in sierra_indat_callback()
538 urb->actual_length); in sierra_indat_callback()
539 tty_flip_buffer_push(&port->port); in sierra_indat_callback()
541 usb_serial_debug_data(&port->dev, __func__, in sierra_indat_callback()
542 urb->actual_length, data); in sierra_indat_callback()
544 dev_dbg(&port->dev, "%s: empty read urb" in sierra_indat_callback()
550 if (status != -ESHUTDOWN && status != -EPERM) { in sierra_indat_callback()
551 usb_mark_last_busy(port->serial->dev); in sierra_indat_callback()
553 if (err && err != -EPERM) in sierra_indat_callback()
554 dev_err(&port->dev, "resubmit read urb failed." in sierra_indat_callback()
562 int status = urb->status; in sierra_instat_callback()
563 struct usb_serial_port *port = urb->context; in sierra_instat_callback()
565 struct usb_serial *serial = port->serial; in sierra_instat_callback() local
567 dev_dbg(&port->dev, "%s: urb %p port %p has data %p\n", __func__, in sierra_instat_callback()
571 struct usb_ctrlrequest *req_pkt = urb->transfer_buffer; in sierra_instat_callback()
574 dev_dbg(&port->dev, "%s: NULL req_pkt\n", in sierra_instat_callback()
578 if ((req_pkt->bRequestType == 0xA1) && in sierra_instat_callback()
579 (req_pkt->bRequest == 0x20)) { in sierra_instat_callback()
582 urb->transfer_buffer + in sierra_instat_callback()
585 dev_dbg(&port->dev, "%s: signal x%x\n", __func__, in sierra_instat_callback()
588 old_dcd_state = portdata->dcd_state; in sierra_instat_callback()
589 portdata->cts_state = 1; in sierra_instat_callback()
590 portdata->dcd_state = ((signals & 0x01) ? 1 : 0); in sierra_instat_callback()
591 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); in sierra_instat_callback()
592 portdata->ri_state = ((signals & 0x08) ? 1 : 0); in sierra_instat_callback()
594 if (old_dcd_state && !portdata->dcd_state) in sierra_instat_callback()
595 tty_port_tty_hangup(&port->port, true); in sierra_instat_callback()
597 dev_dbg(&port->dev, "%s: type %x req %x\n", in sierra_instat_callback()
598 __func__, req_pkt->bRequestType, in sierra_instat_callback()
599 req_pkt->bRequest); in sierra_instat_callback()
602 dev_dbg(&port->dev, "%s: error %d\n", __func__, status); in sierra_instat_callback()
605 if (status != -ESHUTDOWN && status != -ENOENT) { in sierra_instat_callback()
606 usb_mark_last_busy(serial->dev); in sierra_instat_callback()
608 if (err && err != -EPERM) in sierra_instat_callback()
609 dev_err(&port->dev, "%s: resubmit intr urb " in sierra_instat_callback()
616 struct usb_serial_port *port = tty->driver_data; in sierra_write_room()
620 /* try to give a good number back based on if we have any free urbs at in sierra_write_room()
622 spin_lock_irqsave(&portdata->lock, flags); in sierra_write_room()
623 if (portdata->outstanding_urbs > (portdata->num_out_urbs * 2) / 3) { in sierra_write_room()
624 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write_room()
625 dev_dbg(&port->dev, "%s - write limit hit\n", __func__); in sierra_write_room()
628 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_write_room()
635 struct usb_serial_port *port = tty->driver_data; in sierra_chars_in_buffer()
641 spin_lock_irqsave(&portdata->lock, flags); in sierra_chars_in_buffer()
642 chars = portdata->outstanding_urbs * MAX_TRANSFER; in sierra_chars_in_buffer()
643 spin_unlock_irqrestore(&portdata->lock, flags); in sierra_chars_in_buffer()
645 dev_dbg(&port->dev, "%s - %u\n", __func__, chars); in sierra_chars_in_buffer()
655 for (i = 0; i < portdata->num_in_urbs; i++) in sierra_stop_rx_urbs()
656 usb_kill_urb(portdata->in_urbs[i]); in sierra_stop_rx_urbs()
658 usb_kill_urb(port->interrupt_in_urb); in sierra_stop_rx_urbs()
664 int err = -EINVAL; in sierra_submit_rx_urbs()
670 for (i = 0; i < portdata->num_in_urbs; i++) { in sierra_submit_rx_urbs()
671 urb = portdata->in_urbs[i]; in sierra_submit_rx_urbs()
676 dev_err(&port->dev, "%s: submit urb failed: %d\n", in sierra_submit_rx_urbs()
683 if (ok_cnt && port->interrupt_in_urb) { in sierra_submit_rx_urbs()
684 err = usb_submit_urb(port->interrupt_in_urb, mem_flags); in sierra_submit_rx_urbs()
686 dev_err(&port->dev, "%s: submit intr urb failed: %d\n", in sierra_submit_rx_urbs()
697 static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, in sierra_setup_urb() argument
712 usb_fill_bulk_urb(urb, serial->dev, in sierra_setup_urb()
713 usb_sndbulkpipe(serial->dev, endpoint) | dir, in sierra_setup_urb()
716 dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__, in sierra_setup_urb()
729 struct usb_serial *serial = port->serial; in sierra_close() local
731 struct sierra_intf_private *intfdata = usb_get_serial_data(serial); in sierra_close()
738 * resumed, but no need to hold it due to the tty-port initialized in sierra_close()
741 spin_lock_irq(&intfdata->susp_lock); in sierra_close()
742 if (--intfdata->open_ports == 0) in sierra_close()
743 serial->interface->needs_remote_wakeup = 0; in sierra_close()
744 spin_unlock_irq(&intfdata->susp_lock); in sierra_close()
747 urb = usb_get_from_anchor(&portdata->delayed); in sierra_close()
750 kfree(urb->transfer_buffer); in sierra_close()
752 usb_autopm_put_interface_async(serial->interface); in sierra_close()
753 spin_lock_irq(&portdata->lock); in sierra_close()
754 portdata->outstanding_urbs--; in sierra_close()
755 spin_unlock_irq(&portdata->lock); in sierra_close()
759 usb_kill_anchored_urbs(&portdata->active); in sierra_close()
761 for (i = 0; i < portdata->num_in_urbs; i++) { in sierra_close()
762 sierra_release_urb(portdata->in_urbs[i]); in sierra_close()
763 portdata->in_urbs[i] = NULL; in sierra_close()
766 usb_autopm_get_interface_no_resume(serial->interface); in sierra_close()
772 struct usb_serial *serial = port->serial; in sierra_open() local
773 struct sierra_intf_private *intfdata = usb_get_serial_data(serial); in sierra_open()
781 endpoint = port->bulk_in_endpointAddress; in sierra_open()
782 for (i = 0; i < portdata->num_in_urbs; i++) { in sierra_open()
783 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, in sierra_open()
786 portdata->in_urbs[i] = urb; in sierra_open()
789 usb_clear_halt(serial->dev, in sierra_open()
790 usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); in sierra_open()
796 spin_lock_irq(&intfdata->susp_lock); in sierra_open()
797 if (++intfdata->open_ports == 1) in sierra_open()
798 serial->interface->needs_remote_wakeup = 1; in sierra_open()
799 spin_unlock_irq(&intfdata->susp_lock); in sierra_open()
800 usb_autopm_put_interface(serial->interface); in sierra_open()
807 for (i = 0; i < portdata->num_in_urbs; i++) { in sierra_open()
808 sierra_release_urb(portdata->in_urbs[i]); in sierra_open()
809 portdata->in_urbs[i] = NULL; in sierra_open()
821 portdata->rts_state = on; in sierra_dtr_rts()
822 portdata->dtr_state = on; in sierra_dtr_rts()
827 static int sierra_startup(struct usb_serial *serial) in sierra_startup() argument
833 return -ENOMEM; in sierra_startup()
835 spin_lock_init(&intfdata->susp_lock); in sierra_startup()
837 usb_set_serial_data(serial, intfdata); in sierra_startup()
840 sierra_set_power_state(serial->dev, 0x0000); in sierra_startup()
844 sierra_vsc_set_nmea(serial->dev, 1); in sierra_startup()
849 static void sierra_release(struct usb_serial *serial) in sierra_release() argument
853 intfdata = usb_get_serial_data(serial); in sierra_release()
859 struct usb_serial *serial = port->serial; in sierra_port_probe() local
866 return -ENOMEM; in sierra_port_probe()
868 spin_lock_init(&portdata->lock); in sierra_port_probe()
869 init_usb_anchor(&portdata->active); in sierra_port_probe()
870 init_usb_anchor(&portdata->delayed); in sierra_port_probe()
873 portdata->num_out_urbs = N_OUT_URB; in sierra_port_probe()
874 portdata->num_in_urbs = N_IN_URB; in sierra_port_probe()
877 if (serial->num_ports == 1) { in sierra_port_probe()
878 /* Get interface number for composite device */ in sierra_port_probe()
879 ifnum = sierra_interface_num(serial); in sierra_port_probe()
882 /* This is really the usb-serial port number of the interface in sierra_port_probe()
883 * rather than the interface number. in sierra_port_probe()
885 ifnum = port->port_number; in sierra_port_probe()
890 portdata->num_out_urbs = N_OUT_URB_HM; in sierra_port_probe()
891 portdata->num_in_urbs = N_IN_URB_HM; in sierra_port_probe()
894 dev_dbg(&port->dev, in sierra_port_probe()
896 ifnum, portdata->num_in_urbs, portdata->num_out_urbs); in sierra_port_probe()
913 static void stop_read_write_urbs(struct usb_serial *serial) in stop_read_write_urbs() argument
920 for (i = 0; i < serial->num_ports; ++i) { in stop_read_write_urbs()
921 port = serial->port[i]; in stop_read_write_urbs()
926 usb_kill_anchored_urbs(&portdata->active); in stop_read_write_urbs()
930 static int sierra_suspend(struct usb_serial *serial, pm_message_t message) in sierra_suspend() argument
932 struct sierra_intf_private *intfdata = usb_get_serial_data(serial); in sierra_suspend()
934 spin_lock_irq(&intfdata->susp_lock); in sierra_suspend()
936 if (intfdata->in_flight) { in sierra_suspend()
937 spin_unlock_irq(&intfdata->susp_lock); in sierra_suspend()
938 return -EBUSY; in sierra_suspend()
941 intfdata->suspended = 1; in sierra_suspend()
942 spin_unlock_irq(&intfdata->susp_lock); in sierra_suspend()
944 stop_read_write_urbs(serial); in sierra_suspend()
958 intfdata = usb_get_serial_data(port->serial); in sierra_submit_delayed_urbs()
961 urb = usb_get_from_anchor(&portdata->delayed); in sierra_submit_delayed_urbs()
965 usb_anchor_urb(urb, &portdata->active); in sierra_submit_delayed_urbs()
966 intfdata->in_flight++; in sierra_submit_delayed_urbs()
969 dev_err(&port->dev, "%s - submit urb failed: %d", in sierra_submit_delayed_urbs()
972 intfdata->in_flight--; in sierra_submit_delayed_urbs()
974 kfree(urb->transfer_buffer); in sierra_submit_delayed_urbs()
977 spin_lock(&portdata->lock); in sierra_submit_delayed_urbs()
978 portdata->outstanding_urbs--; in sierra_submit_delayed_urbs()
979 spin_unlock(&portdata->lock); in sierra_submit_delayed_urbs()
984 return -EIO; in sierra_submit_delayed_urbs()
989 static int sierra_resume(struct usb_serial *serial) in sierra_resume() argument
992 struct sierra_intf_private *intfdata = usb_get_serial_data(serial); in sierra_resume()
996 spin_lock_irq(&intfdata->susp_lock); in sierra_resume()
997 for (i = 0; i < serial->num_ports; i++) { in sierra_resume()
998 port = serial->port[i]; in sierra_resume()
1000 if (!tty_port_initialized(&port->port)) in sierra_resume()
1011 intfdata->suspended = 0; in sierra_resume()
1012 spin_unlock_irq(&intfdata->susp_lock); in sierra_resume()
1014 return ec ? -EIO : 0; in sierra_resume()