Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: allow subdrivers to modify port-endpoint mapping

Allow subdrivers to modify the port-endpoint mapping by passing the
endpoint descriptors to calc_num_ports.

The callback can now also be used to verify that the required endpoints
exists and abort probing otherwise.

This will allow us to get rid of a few hacks in subdrivers that are
already modifying the port-endpoint mapping (or aborting probe due to
missing endpoints), but only after the port structures have been setup.

Signed-off-by: Johan Hovold <johan@kernel.org>

+42 -26
+2 -1
drivers/usb/serial/f81534.c
··· 611 611 * The f81534_calc_num_ports() will run to "new style" with checking 612 612 * F81534_PORT_UNAVAILABLE section. 613 613 */ 614 - static int f81534_calc_num_ports(struct usb_serial *serial) 614 + static int f81534_calc_num_ports(struct usb_serial *serial, 615 + struct usb_serial_endpoints *epds) 615 616 { 616 617 u8 setting[F81534_CUSTOM_DATA_SIZE]; 617 618 u8 setting_idx;
+4 -2
drivers/usb/serial/ipaq.c
··· 33 33 /* Function prototypes for an ipaq */ 34 34 static int ipaq_open(struct tty_struct *tty, 35 35 struct usb_serial_port *port); 36 - static int ipaq_calc_num_ports(struct usb_serial *serial); 36 + static int ipaq_calc_num_ports(struct usb_serial *serial, 37 + struct usb_serial_endpoints *epds); 37 38 static int ipaq_startup(struct usb_serial *serial); 38 39 39 40 static const struct usb_device_id ipaq_id_table[] = { ··· 551 550 return usb_serial_generic_open(tty, port); 552 551 } 553 552 554 - static int ipaq_calc_num_ports(struct usb_serial *serial) 553 + static int ipaq_calc_num_ports(struct usb_serial *serial, 554 + struct usb_serial_endpoints *epds) 555 555 { 556 556 /* 557 557 * some devices have 3 endpoints, the 3rd of which
+2 -1
drivers/usb/serial/mos7720.c
··· 973 973 tty_port_tty_wakeup(&mos7720_port->port->port); 974 974 } 975 975 976 - static int mos77xx_calc_num_ports(struct usb_serial *serial) 976 + static int mos77xx_calc_num_ports(struct usb_serial *serial, 977 + struct usb_serial_endpoints *epds) 977 978 { 978 979 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 979 980 if (product == MOSCHIP_DEVICE_ID_7715)
+2 -1
drivers/usb/serial/mos7840.c
··· 2104 2104 return 0; 2105 2105 } 2106 2106 2107 - static int mos7840_calc_num_ports(struct usb_serial *serial) 2107 + static int mos7840_calc_num_ports(struct usb_serial *serial, 2108 + struct usb_serial_endpoints *epds) 2108 2109 { 2109 2110 int device_type = (unsigned long)usb_get_serial_data(serial); 2110 2111 int mos7840_num_ports;
+2 -1
drivers/usb/serial/mxuport.c
··· 946 946 * Determine how many ports this device has dynamically. It will be 947 947 * called after the probe() callback is called, but before attach(). 948 948 */ 949 - static int mxuport_calc_num_ports(struct usb_serial *serial) 949 + static int mxuport_calc_num_ports(struct usb_serial *serial, 950 + struct usb_serial_endpoints *epds) 950 951 { 951 952 unsigned long features = (unsigned long)usb_get_serial_data(serial); 952 953
+2 -1
drivers/usb/serial/quatech2.c
··· 246 246 return status; 247 247 } 248 248 249 - static int qt2_calc_num_ports(struct usb_serial *serial) 249 + static int qt2_calc_num_ports(struct usb_serial *serial, 250 + struct usb_serial_endpoints *epds) 250 251 { 251 252 struct qt2_device_detail d; 252 253 int i;
+2 -1
drivers/usb/serial/sierra.c
··· 85 85 USB_CTRL_SET_TIMEOUT); /* int timeout */ 86 86 } 87 87 88 - static int sierra_calc_num_ports(struct usb_serial *serial) 88 + static int sierra_calc_num_ports(struct usb_serial *serial, 89 + struct usb_serial_endpoints *epds) 89 90 { 90 91 int num_ports = 0; 91 92 u8 ifnum, numendpoints;
+6 -13
drivers/usb/serial/usb-serial.c
··· 710 710 .shutdown = serial_port_shutdown, 711 711 }; 712 712 713 - struct usb_serial_endpoints { 714 - unsigned char num_bulk_in; 715 - unsigned char num_bulk_out; 716 - unsigned char num_interrupt_in; 717 - unsigned char num_interrupt_out; 718 - struct usb_endpoint_descriptor *bulk_in[MAX_NUM_PORTS]; 719 - struct usb_endpoint_descriptor *bulk_out[MAX_NUM_PORTS]; 720 - struct usb_endpoint_descriptor *interrupt_in[MAX_NUM_PORTS]; 721 - struct usb_endpoint_descriptor *interrupt_out[MAX_NUM_PORTS]; 722 - }; 723 - 724 713 static void find_endpoints(struct usb_serial *serial, 725 714 struct usb_serial_endpoints *epds) 726 715 { ··· 864 875 #endif 865 876 if (!num_ports) { 866 877 /* if this device type has a calc_num_ports function, call it */ 867 - if (type->calc_num_ports) 868 - num_ports = type->calc_num_ports(serial); 878 + if (type->calc_num_ports) { 879 + retval = type->calc_num_ports(serial, epds); 880 + if (retval < 0) 881 + goto err_free_epds; 882 + num_ports = retval; 883 + } 869 884 if (!num_ports) 870 885 num_ports = type->num_ports; 871 886 }
+4 -2
drivers/usb/serial/visor.c
··· 40 40 static void visor_close(struct usb_serial_port *port); 41 41 static int visor_probe(struct usb_serial *serial, 42 42 const struct usb_device_id *id); 43 - static int visor_calc_num_ports(struct usb_serial *serial); 43 + static int visor_calc_num_ports(struct usb_serial *serial, 44 + struct usb_serial_endpoints *epds); 44 45 static void visor_read_int_callback(struct urb *urb); 45 46 static int clie_3_5_startup(struct usb_serial *serial); 46 47 static int treo_attach(struct usb_serial *serial); ··· 467 466 return retval; 468 467 } 469 468 470 - static int visor_calc_num_ports(struct usb_serial *serial) 469 + static int visor_calc_num_ports(struct usb_serial *serial, 470 + struct usb_serial_endpoints *epds) 471 471 { 472 472 int num_ports = (int)(long)(usb_get_serial_data(serial)); 473 473
+16 -3
include/linux/usb/serial.h
··· 181 181 serial->private = data; 182 182 } 183 183 184 + struct usb_serial_endpoints { 185 + unsigned char num_bulk_in; 186 + unsigned char num_bulk_out; 187 + unsigned char num_interrupt_in; 188 + unsigned char num_interrupt_out; 189 + struct usb_endpoint_descriptor *bulk_in[MAX_NUM_PORTS]; 190 + struct usb_endpoint_descriptor *bulk_out[MAX_NUM_PORTS]; 191 + struct usb_endpoint_descriptor *interrupt_in[MAX_NUM_PORTS]; 192 + struct usb_endpoint_descriptor *interrupt_out[MAX_NUM_PORTS]; 193 + }; 194 + 184 195 /** 185 196 * usb_serial_driver - describes a usb serial driver 186 197 * @description: pointer to a string that describes this driver. This string ··· 207 196 * (0 = end-point size) 208 197 * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size) 209 198 * @calc_num_ports: pointer to a function to determine how many ports this 210 - * device has dynamically. It will be called after the probe() 211 - * callback is called, but before attach() 199 + * device has dynamically. It can also be used to verify the number of 200 + * endpoints or to modify the port-endpoint mapping. It will be called 201 + * after the probe() callback is called, but before attach(). 212 202 * @probe: pointer to the driver's probe function. 213 203 * This will be called when the device is inserted into the system, 214 204 * but before the device has been fully initialized by the usb_serial ··· 261 249 262 250 int (*probe)(struct usb_serial *serial, const struct usb_device_id *id); 263 251 int (*attach)(struct usb_serial *serial); 264 - int (*calc_num_ports) (struct usb_serial *serial); 252 + int (*calc_num_ports)(struct usb_serial *serial, 253 + struct usb_serial_endpoints *epds); 265 254 266 255 void (*disconnect)(struct usb_serial *serial); 267 256 void (*release)(struct usb_serial *serial);