Commit e0439cd9 authored by Johan Hovold's avatar Johan Hovold

USB: serial: sierra: clean up special-interface handling

Clean up the handling of special interfaces that either should be
ignored or that need a larger number of URBs.

Commit 66f092ed ("USB: serial: sierra: unify quirk handling logic")
replaced the previous is_blacklisted() and is_highmemory() helpers with
a single is_quirk() helper which made it even harder to understand what
the interface lists were used for.

Rename the interface-list struct, its members and the interface-lookup
helper and restructure the code somewhat in order to make it more
self-explanatory.

Link: https://lore.kernel.org/r/20200713153936.18032-1-johan@kernel.orgReviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
parent 16045bab
...@@ -45,10 +45,9 @@ ...@@ -45,10 +45,9 @@
static bool nmea; static bool nmea;
/* Used in interface quirks */ struct sierra_iface_list {
struct sierra_iface_quirk { const u8 *nums; /* array of interface numbers */
const u32 infolen; /* number of interface numbers on the list */ size_t count; /* number of elements in array */
const u8 *ifaceinfo; /* pointer to the array holding the numbers */
}; };
struct sierra_intf_private { struct sierra_intf_private {
...@@ -101,20 +100,19 @@ static int sierra_calc_num_ports(struct usb_serial *serial, ...@@ -101,20 +100,19 @@ static int sierra_calc_num_ports(struct usb_serial *serial,
return num_ports; return num_ports;
} }
static int is_quirk(const u8 ifnum, const struct sierra_iface_quirk *quirk) static bool is_listed(const u8 ifnum, const struct sierra_iface_list *list)
{ {
const u8 *info;
int i; int i;
if (quirk) { if (!list)
info = quirk->ifaceinfo; return false;
for (i = 0; i < quirk->infolen; i++) { for (i = 0; i < list->count; i++) {
if (info[i] == ifnum) if (list->nums[i] == ifnum)
return 1; return true;
} }
}
return 0; return false;
} }
static u8 sierra_interface_num(struct usb_serial *serial) static u8 sierra_interface_num(struct usb_serial *serial)
...@@ -125,6 +123,7 @@ static u8 sierra_interface_num(struct usb_serial *serial) ...@@ -125,6 +123,7 @@ static u8 sierra_interface_num(struct usb_serial *serial)
static int sierra_probe(struct usb_serial *serial, static int sierra_probe(struct usb_serial *serial,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
const struct sierra_iface_list *ignore_list;
int result = 0; int result = 0;
struct usb_device *udev; struct usb_device *udev;
u8 ifnum; u8 ifnum;
...@@ -143,9 +142,10 @@ static int sierra_probe(struct usb_serial *serial, ...@@ -143,9 +142,10 @@ static int sierra_probe(struct usb_serial *serial,
usb_set_interface(udev, ifnum, 1); usb_set_interface(udev, ifnum, 1);
} }
if (is_quirk(ifnum, (struct sierra_iface_quirk *)id->driver_info)) { ignore_list = (const struct sierra_iface_list *)id->driver_info;
dev_dbg(&serial->dev->dev,
"Ignoring interface #%d\n", ifnum); if (is_listed(ifnum, ignore_list)) {
dev_dbg(&serial->dev->dev, "Ignoring interface #%d\n", ifnum);
return -ENODEV; return -ENODEV;
} }
...@@ -154,22 +154,22 @@ static int sierra_probe(struct usb_serial *serial, ...@@ -154,22 +154,22 @@ static int sierra_probe(struct usb_serial *serial,
/* interfaces with higher memory requirements */ /* interfaces with higher memory requirements */
static const u8 hi_memory_typeA_ifaces[] = { 0, 2 }; static const u8 hi_memory_typeA_ifaces[] = { 0, 2 };
static const struct sierra_iface_quirk typeA_interface_list = { static const struct sierra_iface_list typeA_interface_list = {
.infolen = ARRAY_SIZE(hi_memory_typeA_ifaces), .nums = hi_memory_typeA_ifaces,
.ifaceinfo = hi_memory_typeA_ifaces, .count = ARRAY_SIZE(hi_memory_typeA_ifaces),
}; };
static const u8 hi_memory_typeB_ifaces[] = { 3, 4, 5, 6 }; static const u8 hi_memory_typeB_ifaces[] = { 3, 4, 5, 6 };
static const struct sierra_iface_quirk typeB_interface_list = { static const struct sierra_iface_list typeB_interface_list = {
.infolen = ARRAY_SIZE(hi_memory_typeB_ifaces), .nums = hi_memory_typeB_ifaces,
.ifaceinfo = hi_memory_typeB_ifaces, .count = ARRAY_SIZE(hi_memory_typeB_ifaces),
}; };
/* 'ignorelist' of interfaces not served by this driver */ /* 'ignorelist' of interfaces not served by this driver */
static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11, 19, 20 }; static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11, 19, 20 };
static const struct sierra_iface_quirk direct_ip_interface_ignore = { static const struct sierra_iface_list direct_ip_interface_ignore = {
.infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), .nums = direct_ip_non_serial_ifaces,
.ifaceinfo = direct_ip_non_serial_ifaces, .count = ARRAY_SIZE(direct_ip_non_serial_ifaces),
}; };
static const struct usb_device_id id_table[] = { static const struct usb_device_id id_table[] = {
...@@ -859,7 +859,7 @@ static int sierra_port_probe(struct usb_serial_port *port) ...@@ -859,7 +859,7 @@ static int sierra_port_probe(struct usb_serial_port *port)
{ {
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
struct sierra_port_private *portdata; struct sierra_port_private *portdata;
const struct sierra_iface_quirk *himemoryp; const struct sierra_iface_list *himemory_list;
u8 ifnum; u8 ifnum;
portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
...@@ -878,16 +878,16 @@ static int sierra_port_probe(struct usb_serial_port *port) ...@@ -878,16 +878,16 @@ static int sierra_port_probe(struct usb_serial_port *port)
if (serial->num_ports == 1) { if (serial->num_ports == 1) {
/* Get interface number for composite device */ /* Get interface number for composite device */
ifnum = sierra_interface_num(serial); ifnum = sierra_interface_num(serial);
himemoryp = &typeB_interface_list; himemory_list = &typeB_interface_list;
} else { } else {
/* This is really the usb-serial port number of the interface /* This is really the usb-serial port number of the interface
* rather than the interface number. * rather than the interface number.
*/ */
ifnum = port->port_number; ifnum = port->port_number;
himemoryp = &typeA_interface_list; himemory_list = &typeA_interface_list;
} }
if (is_quirk(ifnum, himemoryp)) { if (is_listed(ifnum, himemory_list)) {
portdata->num_out_urbs = N_OUT_URB_HM; portdata->num_out_urbs = N_OUT_URB_HM;
portdata->num_in_urbs = N_IN_URB_HM; portdata->num_in_urbs = N_IN_URB_HM;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment