UPSTREAM: usb: xhci: Correct last context entry calculation for Configure Endpoint

The current XHCI driver recalculates the Context Entries field in the
Slot Context on every add_endpoint() and drop_endpoint() call. In the
case of drop_endpoint(), it seems to assume that the add_flags will
always contain every endpoint for the new configuration, which is not
necessarily correct if you don't make assumptions about how the USB core
uses the add_endpoint/drop_endpoint interface (add_flags only contains
endpoints that are new additions in the new configuration).

Furthermore, EP0_FLAG is not consistently set in add_flags throughout
the lifetime of a device. This means that when all endpoints are
dropped, the Context Entries field can be set to 0 (which is invalid and
may cause a Parameter Error) or -1 (which is interpreted as 31 and
causes the driver to keep using the old, incorrect value).

The only surefire way to set this field right is to also take all
existing endpoints into account, and to force the value to 1 (meaning
only EP0 is active) if no other endpoint is found. This patch implements
that as a single step in the final check_bandwidth() call and removes
the intermediary calculations from add_endpoint() and drop_endpoint().

Signed-off-by: Julius Werner <jwerner@chromium.org>
(cherry picked from commit 61cee971a20c392f89e153c1ec5bf8e714cd5245)
Cherry-picked from mnyman/xhci.git/for-usb-linus with no conflicts.

BUG=None
TEST=Run with XHCI debugging, connect/unplug/S2R some devices that like
to change configurations and alternate settings (e.g. cameras). Make
sure the new Slot Context always contains the right Context Entries
value after each check_bandwidth().

Change-Id: I1eb26ec22d381a3f9ba3a4521488b60ed7f7bdcf
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/191368
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
(cherry picked from commit d44ca19a1d1e5714e05a5f06de3dd497d2e82eb9)
Reviewed-on: https://chromium-review.googlesource.com/202779