aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/xhci.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/xhci.h')
-rw-r--r--drivers/usb/host/xhci.h187
1 files changed, 182 insertions, 5 deletions
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index cae8e23308bf..3c8fbd2772ea 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -272,6 +272,7 @@ struct xhci_op_regs {
272 */ 272 */
273#define PORT_PLS_MASK (0xf << 5) 273#define PORT_PLS_MASK (0xf << 5)
274#define XDEV_U0 (0x0 << 5) 274#define XDEV_U0 (0x0 << 5)
275#define XDEV_U2 (0x2 << 5)
275#define XDEV_U3 (0x3 << 5) 276#define XDEV_U3 (0x3 << 5)
276#define XDEV_RESUME (0xf << 5) 277#define XDEV_RESUME (0xf << 5)
277/* true: port has power (see HCC_PPC) */ 278/* true: port has power (see HCC_PPC) */
@@ -362,7 +363,13 @@ struct xhci_op_regs {
362/* Bits 24:31 for port testing */ 363/* Bits 24:31 for port testing */
363 364
364/* USB2 Protocol PORTSPMSC */ 365/* USB2 Protocol PORTSPMSC */
365#define PORT_RWE (1 << 0x3) 366#define PORT_L1S_MASK 7
367#define PORT_L1S_SUCCESS 1
368#define PORT_RWE (1 << 3)
369#define PORT_HIRD(p) (((p) & 0xf) << 4)
370#define PORT_HIRD_MASK (0xf << 4)
371#define PORT_L1DS(p) (((p) & 0xff) << 8)
372#define PORT_HLE (1 << 16)
366 373
367/** 374/**
368 * struct xhci_intr_reg - Interrupt Register Set 375 * struct xhci_intr_reg - Interrupt Register Set
@@ -611,11 +618,13 @@ struct xhci_ep_ctx {
611#define EP_STATE_ERROR 4 618#define EP_STATE_ERROR 4
612/* Mult - Max number of burtst within an interval, in EP companion desc. */ 619/* Mult - Max number of burtst within an interval, in EP companion desc. */
613#define EP_MULT(p) (((p) & 0x3) << 8) 620#define EP_MULT(p) (((p) & 0x3) << 8)
621#define CTX_TO_EP_MULT(p) (((p) >> 8) & 0x3)
614/* bits 10:14 are Max Primary Streams */ 622/* bits 10:14 are Max Primary Streams */
615/* bit 15 is Linear Stream Array */ 623/* bit 15 is Linear Stream Array */
616/* Interval - period between requests to an endpoint - 125u increments. */ 624/* Interval - period between requests to an endpoint - 125u increments. */
617#define EP_INTERVAL(p) (((p) & 0xff) << 16) 625#define EP_INTERVAL(p) (((p) & 0xff) << 16)
618#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) 626#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
627#define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff)
619#define EP_MAXPSTREAMS_MASK (0x1f << 10) 628#define EP_MAXPSTREAMS_MASK (0x1f << 10)
620#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) 629#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
621/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ 630/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
@@ -640,6 +649,7 @@ struct xhci_ep_ctx {
640/* bit 6 reserved */ 649/* bit 6 reserved */
641/* bit 7 is Host Initiate Disable - for disabling stream selection */ 650/* bit 7 is Host Initiate Disable - for disabling stream selection */
642#define MAX_BURST(p) (((p)&0xff) << 8) 651#define MAX_BURST(p) (((p)&0xff) << 8)
652#define CTX_TO_MAX_BURST(p) (((p) >> 8) & 0xff)
643#define MAX_PACKET(p) (((p)&0xffff) << 16) 653#define MAX_PACKET(p) (((p)&0xffff) << 16)
644#define MAX_PACKET_MASK (0xffff << 16) 654#define MAX_PACKET_MASK (0xffff << 16)
645#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) 655#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
@@ -652,6 +662,7 @@ struct xhci_ep_ctx {
652/* tx_info bitmasks */ 662/* tx_info bitmasks */
653#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) 663#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
654#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) 664#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
665#define CTX_TO_MAX_ESIT_PAYLOAD(p) (((p) >> 16) & 0xffff)
655 666
656/* deq bitmasks */ 667/* deq bitmasks */
657#define EP_CTX_CYCLE_MASK (1 << 0) 668#define EP_CTX_CYCLE_MASK (1 << 0)
@@ -670,6 +681,11 @@ struct xhci_input_control_ctx {
670 __le32 rsvd2[6]; 681 __le32 rsvd2[6];
671}; 682};
672 683
684#define EP_IS_ADDED(ctrl_ctx, i) \
685 (le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))
686#define EP_IS_DROPPED(ctrl_ctx, i) \
687 (le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1)))
688
673/* Represents everything that is needed to issue a command on the command ring. 689/* Represents everything that is needed to issue a command on the command ring.
674 * It's useful to pre-allocate these for commands that cannot fail due to 690 * It's useful to pre-allocate these for commands that cannot fail due to
675 * out-of-memory errors, like freeing streams. 691 * out-of-memory errors, like freeing streams.
@@ -731,6 +747,67 @@ struct xhci_stream_info {
731#define SMALL_STREAM_ARRAY_SIZE 256 747#define SMALL_STREAM_ARRAY_SIZE 256
732#define MEDIUM_STREAM_ARRAY_SIZE 1024 748#define MEDIUM_STREAM_ARRAY_SIZE 1024
733 749
750/* Some Intel xHCI host controllers need software to keep track of the bus
751 * bandwidth. Keep track of endpoint info here. Each root port is allocated
752 * the full bus bandwidth. We must also treat TTs (including each port under a
753 * multi-TT hub) as a separate bandwidth domain. The direct memory interface
754 * (DMI) also limits the total bandwidth (across all domains) that can be used.
755 */
756struct xhci_bw_info {
757 /* ep_interval is zero-based */
758 unsigned int ep_interval;
759 /* mult and num_packets are one-based */
760 unsigned int mult;
761 unsigned int num_packets;
762 unsigned int max_packet_size;
763 unsigned int max_esit_payload;
764 unsigned int type;
765};
766
767/* "Block" sizes in bytes the hardware uses for different device speeds.
768 * The logic in this part of the hardware limits the number of bits the hardware
769 * can use, so must represent bandwidth in a less precise manner to mimic what
770 * the scheduler hardware computes.
771 */
772#define FS_BLOCK 1
773#define HS_BLOCK 4
774#define SS_BLOCK 16
775#define DMI_BLOCK 32
776
777/* Each device speed has a protocol overhead (CRC, bit stuffing, etc) associated
778 * with each byte transferred. SuperSpeed devices have an initial overhead to
779 * set up bursts. These are in blocks, see above. LS overhead has already been
780 * translated into FS blocks.
781 */
782#define DMI_OVERHEAD 8
783#define DMI_OVERHEAD_BURST 4
784#define SS_OVERHEAD 8
785#define SS_OVERHEAD_BURST 32
786#define HS_OVERHEAD 26
787#define FS_OVERHEAD 20
788#define LS_OVERHEAD 128
789/* The TTs need to claim roughly twice as much bandwidth (94 bytes per
790 * microframe ~= 24Mbps) of the HS bus as the devices can actually use because
791 * of overhead associated with split transfers crossing microframe boundaries.
792 * 31 blocks is pure protocol overhead.
793 */
794#define TT_HS_OVERHEAD (31 + 94)
795#define TT_DMI_OVERHEAD (25 + 12)
796
797/* Bandwidth limits in blocks */
798#define FS_BW_LIMIT 1285
799#define TT_BW_LIMIT 1320
800#define HS_BW_LIMIT 1607
801#define SS_BW_LIMIT_IN 3906
802#define DMI_BW_LIMIT_IN 3906
803#define SS_BW_LIMIT_OUT 3906
804#define DMI_BW_LIMIT_OUT 3906
805
806/* Percentage of bus bandwidth reserved for non-periodic transfers */
807#define FS_BW_RESERVED 10
808#define HS_BW_RESERVED 20
809#define SS_BW_RESERVED 10
810
734struct xhci_virt_ep { 811struct xhci_virt_ep {
735 struct xhci_ring *ring; 812 struct xhci_ring *ring;
736 /* Related to endpoints that are configured to use stream IDs only */ 813 /* Related to endpoints that are configured to use stream IDs only */
@@ -772,8 +849,39 @@ struct xhci_virt_ep {
772 * process the missed tds on the endpoint ring. 849 * process the missed tds on the endpoint ring.
773 */ 850 */
774 bool skip; 851 bool skip;
852 /* Bandwidth checking storage */
853 struct xhci_bw_info bw_info;
854 struct list_head bw_endpoint_list;
855};
856
857enum xhci_overhead_type {
858 LS_OVERHEAD_TYPE = 0,
859 FS_OVERHEAD_TYPE,
860 HS_OVERHEAD_TYPE,
861};
862
863struct xhci_interval_bw {
864 unsigned int num_packets;
865 /* Sorted by max packet size.
866 * Head of the list is the greatest max packet size.
867 */
868 struct list_head endpoints;
869 /* How many endpoints of each speed are present. */
870 unsigned int overhead[3];
871};
872
873#define XHCI_MAX_INTERVAL 16
874
875struct xhci_interval_bw_table {
876 unsigned int interval0_esit_payload;
877 struct xhci_interval_bw interval_bw[XHCI_MAX_INTERVAL];
878 /* Includes reserved bandwidth for async endpoints */
879 unsigned int bw_used;
880 unsigned int ss_bw_in;
881 unsigned int ss_bw_out;
775}; 882};
776 883
884
777struct xhci_virt_device { 885struct xhci_virt_device {
778 struct usb_device *udev; 886 struct usb_device *udev;
779 /* 887 /*
@@ -798,7 +906,32 @@ struct xhci_virt_device {
798 /* Status of the last command issued for this device */ 906 /* Status of the last command issued for this device */
799 u32 cmd_status; 907 u32 cmd_status;
800 struct list_head cmd_list; 908 struct list_head cmd_list;
801 u8 port; 909 u8 fake_port;
910 u8 real_port;
911 struct xhci_interval_bw_table *bw_table;
912 struct xhci_tt_bw_info *tt_info;
913};
914
915/*
916 * For each roothub, keep track of the bandwidth information for each periodic
917 * interval.
918 *
919 * If a high speed hub is attached to the roothub, each TT associated with that
920 * hub is a separate bandwidth domain. The interval information for the
921 * endpoints on the devices under that TT will appear in the TT structure.
922 */
923struct xhci_root_port_bw_info {
924 struct list_head tts;
925 unsigned int num_active_tts;
926 struct xhci_interval_bw_table bw_table;
927};
928
929struct xhci_tt_bw_info {
930 struct list_head tt_list;
931 int slot_id;
932 int ttport;
933 struct xhci_interval_bw_table bw_table;
934 int active_eps;
802}; 935};
803 936
804 937
@@ -1198,6 +1331,12 @@ struct s3_save {
1198 u64 erst_dequeue; 1331 u64 erst_dequeue;
1199}; 1332};
1200 1333
1334/* Use for lpm */
1335struct dev_info {
1336 u32 dev_id;
1337 struct list_head list;
1338};
1339
1201struct xhci_bus_state { 1340struct xhci_bus_state {
1202 unsigned long bus_suspended; 1341 unsigned long bus_suspended;
1203 unsigned long next_statechange; 1342 unsigned long next_statechange;
@@ -1261,12 +1400,16 @@ struct xhci_hcd {
1261 struct xhci_erst erst; 1400 struct xhci_erst erst;
1262 /* Scratchpad */ 1401 /* Scratchpad */
1263 struct xhci_scratchpad *scratchpad; 1402 struct xhci_scratchpad *scratchpad;
1403 /* Store LPM test failed devices' information */
1404 struct list_head lpm_failed_devs;
1264 1405
1265 /* slot enabling and address device helpers */ 1406 /* slot enabling and address device helpers */
1266 struct completion addr_dev; 1407 struct completion addr_dev;
1267 int slot_id; 1408 int slot_id;
1268 /* Internal mirror of the HW's dcbaa */ 1409 /* Internal mirror of the HW's dcbaa */
1269 struct xhci_virt_device *devs[MAX_HC_SLOTS]; 1410 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1411 /* For keeping track of bandwidth domains per roothub. */
1412 struct xhci_root_port_bw_info *rh_bw;
1270 1413
1271 /* DMA pools */ 1414 /* DMA pools */
1272 struct dma_pool *device_pool; 1415 struct dma_pool *device_pool;
@@ -1318,6 +1461,8 @@ struct xhci_hcd {
1318#define XHCI_EP_LIMIT_QUIRK (1 << 5) 1461#define XHCI_EP_LIMIT_QUIRK (1 << 5)
1319#define XHCI_BROKEN_MSI (1 << 6) 1462#define XHCI_BROKEN_MSI (1 << 6)
1320#define XHCI_RESET_ON_RESUME (1 << 7) 1463#define XHCI_RESET_ON_RESUME (1 << 7)
1464#define XHCI_SW_BW_CHECKING (1 << 8)
1465#define XHCI_AMD_0x96_HOST (1 << 9)
1321 unsigned int num_active_eps; 1466 unsigned int num_active_eps;
1322 unsigned int limit_active_eps; 1467 unsigned int limit_active_eps;
1323 /* There are two roothubs to keep track of bus suspend info for */ 1468 /* There are two roothubs to keep track of bus suspend info for */
@@ -1330,6 +1475,10 @@ struct xhci_hcd {
1330 /* Array of pointers to USB 2.0 PORTSC registers */ 1475 /* Array of pointers to USB 2.0 PORTSC registers */
1331 __le32 __iomem **usb2_ports; 1476 __le32 __iomem **usb2_ports;
1332 unsigned int num_usb2_ports; 1477 unsigned int num_usb2_ports;
1478 /* support xHCI 0.96 spec USB2 software LPM */
1479 unsigned sw_lpm_support:1;
1480 /* support xHCI 1.0 spec USB2 hardware LPM */
1481 unsigned hw_lpm_support:1;
1333}; 1482};
1334 1483
1335/* convert between an HCD pointer and the corresponding EHCI_HCD */ 1484/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -1401,9 +1550,7 @@ static inline void xhci_write_64(struct xhci_hcd *xhci,
1401 1550
1402static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) 1551static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1403{ 1552{
1404 u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); 1553 return xhci->quirks & XHCI_LINK_TRB_QUIRK;
1405 return ((HC_VERSION(temp) == 0x95) &&
1406 (xhci->quirks & XHCI_LINK_TRB_QUIRK));
1407} 1554}
1408 1555
1409/* xHCI debugging */ 1556/* xHCI debugging */
@@ -1438,6 +1585,20 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1438unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index); 1585unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
1439unsigned int xhci_last_valid_endpoint(u32 added_ctxs); 1586unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
1440void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); 1587void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
1588void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci,
1589 struct xhci_bw_info *ep_bw,
1590 struct xhci_interval_bw_table *bw_table,
1591 struct usb_device *udev,
1592 struct xhci_virt_ep *virt_ep,
1593 struct xhci_tt_bw_info *tt_info);
1594void xhci_update_tt_active_eps(struct xhci_hcd *xhci,
1595 struct xhci_virt_device *virt_dev,
1596 int old_active_eps);
1597void xhci_clear_endpoint_bw_info(struct xhci_bw_info *bw_info);
1598void xhci_update_bw_info(struct xhci_hcd *xhci,
1599 struct xhci_container_ctx *in_ctx,
1600 struct xhci_input_control_ctx *ctrl_ctx,
1601 struct xhci_virt_device *virt_dev);
1441void xhci_endpoint_copy(struct xhci_hcd *xhci, 1602void xhci_endpoint_copy(struct xhci_hcd *xhci,
1442 struct xhci_container_ctx *in_ctx, 1603 struct xhci_container_ctx *in_ctx,
1443 struct xhci_container_ctx *out_ctx, 1604 struct xhci_container_ctx *out_ctx,
@@ -1483,9 +1644,13 @@ void xhci_free_command(struct xhci_hcd *xhci,
1483/* xHCI PCI glue */ 1644/* xHCI PCI glue */
1484int xhci_register_pci(void); 1645int xhci_register_pci(void);
1485void xhci_unregister_pci(void); 1646void xhci_unregister_pci(void);
1647#else
1648static inline int xhci_register_pci(void) { return 0; }
1649static inline void xhci_unregister_pci(void) {}
1486#endif 1650#endif
1487 1651
1488/* xHCI host controller glue */ 1652/* xHCI host controller glue */
1653typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
1489void xhci_quiesce(struct xhci_hcd *xhci); 1654void xhci_quiesce(struct xhci_hcd *xhci);
1490int xhci_halt(struct xhci_hcd *xhci); 1655int xhci_halt(struct xhci_hcd *xhci);
1491int xhci_reset(struct xhci_hcd *xhci); 1656int xhci_reset(struct xhci_hcd *xhci);
@@ -1493,6 +1658,7 @@ int xhci_init(struct usb_hcd *hcd);
1493int xhci_run(struct usb_hcd *hcd); 1658int xhci_run(struct usb_hcd *hcd);
1494void xhci_stop(struct usb_hcd *hcd); 1659void xhci_stop(struct usb_hcd *hcd);
1495void xhci_shutdown(struct usb_hcd *hcd); 1660void xhci_shutdown(struct usb_hcd *hcd);
1661int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
1496 1662
1497#ifdef CONFIG_PM 1663#ifdef CONFIG_PM
1498int xhci_suspend(struct xhci_hcd *xhci); 1664int xhci_suspend(struct xhci_hcd *xhci);
@@ -1507,6 +1673,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd);
1507irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd); 1673irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd);
1508int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1674int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1509void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1675void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1676int xhci_alloc_tt_info(struct xhci_hcd *xhci,
1677 struct xhci_virt_device *virt_dev,
1678 struct usb_device *hdev,
1679 struct usb_tt *tt, gfp_t mem_flags);
1510int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, 1680int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
1511 struct usb_host_endpoint **eps, unsigned int num_eps, 1681 struct usb_host_endpoint **eps, unsigned int num_eps,
1512 unsigned int num_streams, gfp_t mem_flags); 1682 unsigned int num_streams, gfp_t mem_flags);
@@ -1514,6 +1684,9 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1514 struct usb_host_endpoint **eps, unsigned int num_eps, 1684 struct usb_host_endpoint **eps, unsigned int num_eps,
1515 gfp_t mem_flags); 1685 gfp_t mem_flags);
1516int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); 1686int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
1687int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev);
1688int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
1689 struct usb_device *udev, int enable);
1517int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, 1690int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1518 struct usb_tt *tt, gfp_t mem_flags); 1691 struct usb_tt *tt, gfp_t mem_flags);
1519int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); 1692int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
@@ -1572,6 +1745,10 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1572 unsigned int ep_index, unsigned int stream_id); 1745 unsigned int ep_index, unsigned int stream_id);
1573 1746
1574/* xHCI roothub code */ 1747/* xHCI roothub code */
1748void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1749 int port_id, u32 link_state);
1750void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1751 int port_id, u32 port_bit);
1575int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1752int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1576 char *buf, u16 wLength); 1753 char *buf, u16 wLength);
1577int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); 1754int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);