xref: /illumos-gate/usr/src/uts/common/io/usb/hcd/README (revision 77e51571)
17c478bd9Sstevel@tonic-gate#
27c478bd9Sstevel@tonic-gate# CDDL HEADER START
37c478bd9Sstevel@tonic-gate#
47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5*77e51571Sgongtian zhao - Sun Microsystems - Beijing China# Common Development and Distribution License (the "License").
6*77e51571Sgongtian zhao - Sun Microsystems - Beijing China# You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate#
87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate# and limitations under the License.
127c478bd9Sstevel@tonic-gate#
137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate#
197c478bd9Sstevel@tonic-gate# CDDL HEADER END
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate/*
22*77e51571Sgongtian zhao - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate			SOLARIS USB BANDWIDTH ANALYSIS
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate1.Introduction
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate  This document discuss the USB bandwidth allocation scheme, and the protocol
327c478bd9Sstevel@tonic-gate  overheads used for both full and high speed host controller drivers. This
337c478bd9Sstevel@tonic-gate  information is derived from the USB 2.0 specification, the "Bandwidth Analysis
347c478bd9Sstevel@tonic-gate  Whitepaper" which is posted on www.usb.org, and other resources.
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate  The target audience for this whitepaper are USB software & hardware designers
377c478bd9Sstevel@tonic-gate  and engineers, and other interested people. The reader should be familiar with
387c478bd9Sstevel@tonic-gate  the Universal Serial Bus Specification version 2.0, the OpenHCI Specification
397c478bd9Sstevel@tonic-gate  1.0a and the Enhanced HCI Specification 1.0.
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate2.Full speed bus
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate  The following overheads, formulas and scheme are applicable both to full speed
447c478bd9Sstevel@tonic-gate  host controllers and also to high speed hub Transaction Translators (TT),
457c478bd9Sstevel@tonic-gate  which perform full/low speed transactions.
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate  o Timing and data rate calculations
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate    - Timing calculations
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate      1 sec			1000 ms or 1000000000 ns
527c478bd9Sstevel@tonic-gate      1 ms			1 frame
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate    - Data rate calculations
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate      1 ms			1500 bytes or 12000 bits (per  frame)
577c478bd9Sstevel@tonic-gate      668 ns			1 byte or 8 bits
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate      1 full speed bit time	83.54 ns
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate  o Protocol Overheads and Bandwidth numbers
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate    - Protocol Overheads
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate      (Refer 5.11.3 section of USB2.0 specification & page 2 of USB Bandwidth
667c478bd9Sstevel@tonic-gate       Analysis document)
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate      Non Isochronous	  	9107 ns			14 bytes
697c478bd9Sstevel@tonic-gate      Isochronous Output	6265 ns			10 bytes
707c478bd9Sstevel@tonic-gate      Isochronous Input	        7268 ns			11 bytes
717c478bd9Sstevel@tonic-gate      Low-speed overhead       64060 ns			97 bytes
727c478bd9Sstevel@tonic-gate      Hub LS overhead*	         668 ns	 	 	 1 byte
737c478bd9Sstevel@tonic-gate      SOF		        4010 ns 	 	 6 bytes
747c478bd9Sstevel@tonic-gate      EOF		        2673 ns		 	 4 bytes
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate      Host Delay*		Specific to hardware    18 bytes
777c478bd9Sstevel@tonic-gate      Low-Speed clock*		Slower than Full speed	 8
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate    - Bandwidth numbers
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate      (Refer 7.3.5 section of OHCI specification 1.0a & page 2 of USB Bandwidth
827c478bd9Sstevel@tonic-gate       Analysis document)
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate      Maximum bandwidth available		      1500 bytes/frame
857c478bd9Sstevel@tonic-gate      Maximum Non Periodic bandwidth	  	       197 bytes/frame
867c478bd9Sstevel@tonic-gate      Maximum Periodic bandwidth		      1293 bytes/frame
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate      NOTE:
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate      1.Hub specific low speed overhead
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate        The time provided by the Host Controller for hubs to enable Low Speed
937c478bd9Sstevel@tonic-gate        ports. The minimum of 4 full speed bit time.
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate        overhead = 2 x Hub_LS_Setup
967c478bd9Sstevel@tonic-gate                 = 2 x (4 x 83.54) =  668.32 Nano seconds  = 1 byte.
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate      2.Host delay will be specific to particular hardware. The following host
997c478bd9Sstevel@tonic-gate        delay is for RIO USB OHCI host controller (Provided by Ken Ward - RIO
1007c478bd9Sstevel@tonic-gate        USB hardware person). The following is just an example how to calculate
1017c478bd9Sstevel@tonic-gate        "host delay" for given USB host controller implementation.
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate        Ex: Assuming ED (Endpoint Descriptor)/TD's (Transfer Descriptor) are not
1047c478bd9Sstevel@tonic-gate            streaming in Schizo (PCI bridge) and no cache hits for an ED or TD:
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate            To read an ED or TD or data:
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate            PCI_ARB_DELAY + PCI_ADDRESS + SCHIZO_RETRY
1097c478bd9Sstevel@tonic-gate            PCI_ARB_DELAY + PCI_ADDRESS + SCHIZO_TRDY +
1107c478bd9Sstevel@tonic-gate			DATA +  Core_overhead
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate            Where,
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate	    PCI_ARB_DELAY = 2000ns
1157c478bd9Sstevel@tonic-gate	    PCI_ADDRESS = 30ns
1167c478bd9Sstevel@tonic-gate	    SCHIZO RETRY = 60ns
1177c478bd9Sstevel@tonic-gate	    SCHIZO TRDY = 60ns
1187c478bd9Sstevel@tonic-gate	    DATA = 240ns (Always read 64 bytes ...)
1197c478bd9Sstevel@tonic-gate	    Core Overhead =240 + 30 * (MPS/4) + 83.54 * (MPS/4) + 4 * 83.54
1207c478bd9Sstevel@tonic-gate	    =  ~3400ns
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate	    now multiply by 3 for ED+TD+DATA = 10200ns = ~128 bits or 16 bytes.
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate	    This is probably on the optimistic side, only using 2us for the
1257c478bd9Sstevel@tonic-gate	    PCI_ARB_DELAY.
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate	If there is a USB cache hit, the time it takes for an ED or TD is:
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate	CORE SYNC DELAY + CACHE_HIT CHECK + 30 * (MPS/4) + CORE OVERHEAD
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate	240 + 30 + 120 + 1000ns ~ 1400ns , or ~ 2 bytes
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate        Total Host delay will be 18 bytes.
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate      3.The Low-Speed clock is eight times slower than full speed  i.e. 1/8th of
1367c478bd9Sstevel@tonic-gate        the full speed.
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate      4.For non-periodic transfers, reserve for at least one low-speed device
1397c478bd9Sstevel@tonic-gate        transaction per frame. According to the USB Bandwidth Analysis white
1407c478bd9Sstevel@tonic-gate        paper and also as per OHCI Specification 1.0a, section 7.3.5, page 123,
1417c478bd9Sstevel@tonic-gate        one low-speed transaction takes  0x628h full speed bits (197 bytes),
1427c478bd9Sstevel@tonic-gate        which comes to around 13% of USB frame time.
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate     5. Maximum Periodic bandwidth is calculated using the following formula
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate        Maximum Periodic bandwidth  = Maximum bandwidth available
1477c478bd9Sstevel@tonic-gate        - SOF - EOF -  Maximum Non Periodic bandwidth.
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate  o Bus Transaction Formulas
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate    (Refer 5.11.3 section of USB2.0 specification)
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate    - Full-Speed:
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate      Protocol overhead + ((MaxPacketSize * 7) / 6 ) + Host_Delay
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate    - Low-Speed:
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate      Protocol overhead + Hub LS overhead +
1607c478bd9Sstevel@tonic-gate		(Low-Speed clock  * ((MaxPacketSize * 7) / 6 )) + Host_Delay
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate  o Periodic Schedule
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate    The figure 5.5 in OHCI specification 1.0a gives you information on periodic
1657c478bd9Sstevel@tonic-gate    scheduling, different polling intervals that are supported, & other details
1667c478bd9Sstevel@tonic-gate    for the OHCI host controller.
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate    - The host controller processes one interrupt endpoint descriptor list every
1697c478bd9Sstevel@tonic-gate      frame. The lower five bits of the current frame number us  used as an
1707c478bd9Sstevel@tonic-gate      index into an array of 32 interrupt endpoint descriptor lists or periodic
1717c478bd9Sstevel@tonic-gate      frame lists found in the HCCA (Host controller communication area). This
1727c478bd9Sstevel@tonic-gate      means each list is revisited once every 32ms. The host controller driver
1737c478bd9Sstevel@tonic-gate      sets up the interrupt lists to visit any given endpoint descriptor in as
1747c478bd9Sstevel@tonic-gate      many lists as necessary to provide the interrupt granularity required for
1757c478bd9Sstevel@tonic-gate      that endpoint. See figure 5.5 in OHCI specification 1.0a.
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate    - Isochronous endpoint descriptors are added at the end of 1ms interrupt
1787c478bd9Sstevel@tonic-gate      endpoint descriptors.
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate    - The host controller driver maintains an array of 32 frame bandwidth lists
1817c478bd9Sstevel@tonic-gate      to save bandwidth allocated in each USB frame.
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate      Please refer section 5.2.7.2 of OHCI specification 1.0a, page 61 for more
1847c478bd9Sstevel@tonic-gate      details.
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate  o Bandwidth Allocation Scheme
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate    The OHCI host controller driver will go through the following steps to
1897c478bd9Sstevel@tonic-gate    allocate bandwidth needed for  an interrupt or isochronous endpoint as
1907c478bd9Sstevel@tonic-gate    follows
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate    - Calculate the bandwidth required for the given endpoint using the bus
1937c478bd9Sstevel@tonic-gate      transaction formula and protocol overhead calculations mentioned in
1947c478bd9Sstevel@tonic-gate      previous section.
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate    - Compare the bandwidth available in the least allocated frame list out of
1977c478bd9Sstevel@tonic-gate      the 32 frame bandwidth lists, against the bandwidth required by this
1987c478bd9Sstevel@tonic-gate      endpoint. If this exceeds the limit, then, an return error.
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate    - Find out the static node to which the given endpoint needs to be linked
2017c478bd9Sstevel@tonic-gate      so that it will be polled as per the required polling interval. This value
2027c478bd9Sstevel@tonic-gate      varies based on polling interval and current bandwidth load on this
2037c478bd9Sstevel@tonic-gate      schedule. See figure 5.5 in OHCI specification 1.0a.
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate      Ex: If a polling interval is 4ms, then, the endpoint will be linked to one
2067c478bd9Sstevel@tonic-gate          of the four static nodes (range 3-6) in the 4ms column of figure 5.5
2077c478bd9Sstevel@tonic-gate          in OHCI specification 1.0a.
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate    - Depending on the polling interval, we need to add the above calculated
2107c478bd9Sstevel@tonic-gate      bandwidth to one or more frame bandwidth lists. Before adding, we need to
2117c478bd9Sstevel@tonic-gate      double check the availability of bandwidth in those respective lists. If
2127c478bd9Sstevel@tonic-gate      this exceeds the limit, then, return an error. Add this bandwidth to all
2137c478bd9Sstevel@tonic-gate      the required frame bandwidth lists.
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate      Ex: Assume a give polling interval of 4 and a static node value of 3.
2167c478bd9Sstevel@tonic-gate          In this case, we need to add required bandwidth to 0,4,8,12,16,20,24,
2177c478bd9Sstevel@tonic-gate          28 frame bandwidth lists.
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate3.High speed bus
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate  o Timing and data rate calculations
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate    - Timing calculations
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate      1 sec			1000 ms
2277c478bd9Sstevel@tonic-gate      125 us			1 uframe
2287c478bd9Sstevel@tonic-gate      1 ms			1 frame or 8  uframes
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate    - Data rate calculations
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate      125 us			7500 bytes (per uframe)
2337c478bd9Sstevel@tonic-gate      16.66 ns			1 byte or 8 bits
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate      1 high speed bit time	2.083 ns
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate  o Protocol Overheads and Bandwidth numbers
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate    - Protocol Overheads
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate      (Refer 5.11.3, 8.4.2.2 and 8.4.2.3 sections of USB2.0 specification)
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate      Non Isochronous	  	917 ns			55 bytes
2447c478bd9Sstevel@tonic-gate      Isochronous 		634 ns			38 bytes
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate      Start split  overhead 	 67 ns		  	 4 bytes
2477c478bd9Sstevel@tonic-gate      Complete split  overhead 	 67 ns		  	 4 bytes
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate      SOF		  	200 ns			12 bytes
2507c478bd9Sstevel@tonic-gate      EOF		       1667 ns 			70 bytes
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate      Host Delay*		 Specific to hardware 	18 bytes
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate    - Bandwidth numbers
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate      (Refer 5.5.4 section of USB2.0 specification)
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate      Maximum bandwidth available		      7500 bytes/uframe
2597c478bd9Sstevel@tonic-gate      Maximum Non Periodic bandwidth*		      1500 bytes/uframe
2607c478bd9Sstevel@tonic-gate      Maximum Periodic bandwidth*		      5918 bytes/uframe
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate      NOTE:
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate      1.Host delay will be specific to particular hardware.
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate      2.As per USB 2.0 specification section 5.5.4, 20% of bus time is reserved
2677c478bd9Sstevel@tonic-gate        for the non-periodic high-speed transfers, where as periodic high-speed
2687c478bd9Sstevel@tonic-gate        transfers will get 80% of the bus time. In one micro-frame or 125us, we
2697c478bd9Sstevel@tonic-gate        can transfer 7500 bytes or 60,000 bits. So 20% of 7500 is 1500 bytes.
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate      3.Maximum Periodic bandwidth is calculated using the following formula
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate        Maximum Periodic bandwidth  = Maximum bandwidth available
2747c478bd9Sstevel@tonic-gate		- SOF - EOF -  Maximum Non Periodic bandwidth.
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate  o Bus Transaction Formulas
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate    (Refer 5.11.3 8.4.2.2 and 8.4.2.3 sections of USB2.0 specification)
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate    - High-Speed (Non-Split transactions):
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate      (Protocol overhead + ((MaxPacketSize * 7) / 6 ) +
2837c478bd9Sstevel@tonic-gate		Host_Delay) x Number of transactions per micro-frame
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate    - High-Speed (Split transaction - Device to Host):
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate      Start Split transaction:
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate      Protocol overhead  + Host_Delay + Start split overhead
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate      Complete Split transaction:
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate      Protocol overhead  + ((MaxPacketSize * 7) / 6 ) +
2947c478bd9Sstevel@tonic-gate		Host_Delay + Complete split overhead
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate    - High-Speed (Split transaction - Host to Device):
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate      Start Split transaction:
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate      Protocol overhead + ((MaxPacketSize * 7) / 6 ) +
3017c478bd9Sstevel@tonic-gate		Host_Delay) + Start split overhead
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate      Complete Split transaction:
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate      Protocol overhead  + Host_Delay + Complete split overhead
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate  o Interrupt schedule or Start and Complete split masks
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate    (Refer 3.6.2 & 4.12.2 sections of EHCI 1.0 specification)
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate    - Interrupt schedule or Start split mask
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate      This field  is used for for high, full and low speed usb device interrupt
3157c478bd9Sstevel@tonic-gate      and isochronous endpoints. This will tell the host controller which micro-
3167c478bd9Sstevel@tonic-gate      frame of a given usb frame to initiate a high speed interrupt and
3177c478bd9Sstevel@tonic-gate      isochronous transaction. For full/low speed devices, it will tell when to
3187c478bd9Sstevel@tonic-gate      initiate a "start split" transaction.
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate	ehci_start_split_mask[15] = /* One byte field */
3217c478bd9Sstevel@tonic-gate	/*
3227c478bd9Sstevel@tonic-gate	 * For all low/full speed devices, and  for  high speed devices with
3237c478bd9Sstevel@tonic-gate	 * a polling interval greater than or equal to 8us (125us).
3247c478bd9Sstevel@tonic-gate	 */
3257c478bd9Sstevel@tonic-gate	{0x01,	/*  00000001 */
3267c478bd9Sstevel@tonic-gate	0x02,	/*  00000010 */
3277c478bd9Sstevel@tonic-gate	0x04,	/*  00000100 */
3287c478bd9Sstevel@tonic-gate	0x08,	/*  00001000 */
3297c478bd9Sstevel@tonic-gate	0x10,	/*  00010000 */
3307c478bd9Sstevel@tonic-gate	0x20,	/*  00100000 */
3317c478bd9Sstevel@tonic-gate	0x40,	/*  01000000 */
3327c478bd9Sstevel@tonic-gate	0x80,	/*  10000000 */
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate	/* For high speed devices with a polling interval of 4us. */
3357c478bd9Sstevel@tonic-gate	0x11,	/* 00010001 */
3367c478bd9Sstevel@tonic-gate	0x22,	/* 00100010 */
3377c478bd9Sstevel@tonic-gate	0x44,	/* 01000100 */
3387c478bd9Sstevel@tonic-gate	0x88,	/* 10001000 */
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate	/* For high speed devices with a polling interval of 2us. */
3417c478bd9Sstevel@tonic-gate	0x55,	/* 01010101 */
3427c478bd9Sstevel@tonic-gate	0xaa,	/* 10101010 */
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate	/* For high speed devices with a polling interval of 1us. */
3457c478bd9Sstevel@tonic-gate	0xff };	/* 11111111 */
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate    - Complete split mask
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate      This field is used only for full/low speed usb device interrupt and
3507c478bd9Sstevel@tonic-gate      isochronous endpoints. It will tell the host controller which micro frame
3517c478bd9Sstevel@tonic-gate      to initiate a "complete split" transaction. Complete split transactions
3527c478bd9Sstevel@tonic-gate      can to be retried for up to 3 times. So bandwidth for complete split
3537c478bd9Sstevel@tonic-gate      transaction is reserved in 3 consecutive micro frames
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate	ehci_complete_split_mask[8] = /* One byte field */
3567c478bd9Sstevel@tonic-gate	/* Only full/low speed devices */
3577c478bd9Sstevel@tonic-gate	{0x0e,	/*  00001110 */
3587c478bd9Sstevel@tonic-gate	0x1c,	/*  00011100 */
3597c478bd9Sstevel@tonic-gate	0x38,	/*  00111000 */
3607c478bd9Sstevel@tonic-gate	0x70,	/*  01110000 */
3617c478bd9Sstevel@tonic-gate	0xe0,	/*  11100000 */
3627c478bd9Sstevel@tonic-gate	Reserved ,	/*  Need FSTN feature  */
3637c478bd9Sstevel@tonic-gate	Reserved ,	/*  Need FSTN feature  */
3647c478bd9Sstevel@tonic-gate	Reserved};	/*  Need FSTN feature */
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate  o Periodic Schedule
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate    The figure 4.8 in EHCI specification gives you information on periodic
3697c478bd9Sstevel@tonic-gate    scheduling, different polling intervals that are supported, and other
3707c478bd9Sstevel@tonic-gate    details for the EHCI host controller.
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate    - The high speed host controller can support 256, 512 or 1024 periodic frame
3737c478bd9Sstevel@tonic-gate      lists. By default all host controllers will support 1024 frame lists. In
3747c478bd9Sstevel@tonic-gate      our implementation, we support 1024 frame lists and we do this by first
3757c478bd9Sstevel@tonic-gate      constructing 32 periodic frame lists and duplicating the same periodic
3767c478bd9Sstevel@tonic-gate      frame lists for a total of 32 times. See figure 4.8 in EHCI specification.
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate    - The host controller traverses the periodic schedule by constructing an
3797c478bd9Sstevel@tonic-gate      array offset reference from the PERIODICLISTBASE & the FRINDEX registers.
3807c478bd9Sstevel@tonic-gate      It fetches the element and begins traversing the graph of linked schedule
3817c478bd9Sstevel@tonic-gate      data structure. See fig 4.8 in EHCI specification.
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate    - The host controller processes one interrupt endpoint descriptor list every
3847c478bd9Sstevel@tonic-gate      micro frame (125us). This means same list is revisited 8 times in a frame.
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate    - The host controller driver sets up the interrupt lists to visit any given
3877c478bd9Sstevel@tonic-gate      endpoint descriptor in as many lists as necessary to provide the interrupt
3887c478bd9Sstevel@tonic-gate      granularity required for that endpoint.
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate    - For isochronous transfers, we use only transfer descriptors but no
3917c478bd9Sstevel@tonic-gate      endpoint descriptors as in OHCI. Transfer descriptors are added at the
3927c478bd9Sstevel@tonic-gate      beginning of the periodic schedule.
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate    - For EHCI, the bandwidth requirement is depends on the usb device speed
3957c478bd9Sstevel@tonic-gate      i.e.
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate      For a high speed usb device, you only need high speed bandwidth. For a
3987c478bd9Sstevel@tonic-gate      full/low speed device connected through a high speed hub, you need both
3997c478bd9Sstevel@tonic-gate      high speed bandwidth and TT (transaction translator) bandwidth.
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate      High speed bandwidth information is saved in an EHCI data structure and TT
4027c478bd9Sstevel@tonic-gate      bandwidth is saved in the high speed hub's usb device data structure. Each
4037c478bd9Sstevel@tonic-gate      TT acts as a full speed host controller & its bandwidth allocation scheme
4047c478bd9Sstevel@tonic-gate      overhead calculations and other details are similar to those of a full
4057c478bd9Sstevel@tonic-gate      speed  host controller. Refer to the "Full speed bus" section for more
4067c478bd9Sstevel@tonic-gate      details.
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate    - The EHCI host controller driver maintains an array of 32 frame lists to
4097c478bd9Sstevel@tonic-gate      store high speed bandwidth allocated in each  frame and also each frame
4107c478bd9Sstevel@tonic-gate      list has eight micro frame lists, which saves bandwidth allocated in each
4117c478bd9Sstevel@tonic-gate      micro frame of  that particular frame.
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate  o Bandwidth Allocation Scheme
4147c478bd9Sstevel@tonic-gate
4157c478bd9Sstevel@tonic-gate    (Refer 3.6.2 & 4.12.2 sections of EHCI 1.0 specification)
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate    High speed Non Split Transaction (for High speed devices only):
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate    For a given high speed interrupt or isochronous endpoint, the EHCI host
4207c478bd9Sstevel@tonic-gate    controller driver will go through the following steps to allocate
4217c478bd9Sstevel@tonic-gate    bandwidth needed for this endpoint.
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate    - Calculate the bandwidth required for given endpoint using the formula and
4247c478bd9Sstevel@tonic-gate      overhead calculations mentioned in previous section.
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate    - Compare the bandwidth available in the least allocated frame list out of
4277c478bd9Sstevel@tonic-gate      the 32 frame lists against the bandwidth required by this endpoint. If
4287c478bd9Sstevel@tonic-gate      this exceeds the limit, then, return an error.
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate    - Map a given high speed endpoint's polling interval in micro seconds to an
4317c478bd9Sstevel@tonic-gate      interrupt list path based on a millisecond value. For example, an endpoint
4327c478bd9Sstevel@tonic-gate      with a polling interval of 16us will map to an interrupt list path of 2ms.
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate    - Find out the static node to which the given endpoint needs to be linked
4357c478bd9Sstevel@tonic-gate      so that it will be polled at its required polling interval. This varies
4367c478bd9Sstevel@tonic-gate      based on polling interval and current bandwidth load on this schedule.
4377c478bd9Sstevel@tonic-gate
4387c478bd9Sstevel@tonic-gate      Ex: If a polling interval is 32us and its corresponding frame polling
4397c478bd9Sstevel@tonic-gate          interval will be 4ms, then the endpoint will be linked to one of the
4407c478bd9Sstevel@tonic-gate          four static nodes (range 3-6) in the 4ms column of figure 4.8 in EHCI
4417c478bd9Sstevel@tonic-gate          specification.
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate    - Depending on the polling interval, we need to add the above calculated
4447c478bd9Sstevel@tonic-gate      bandwidth to one or more frame bandwidth lists, and also to one or more
4457c478bd9Sstevel@tonic-gate      micro frame bandwidth lists for that particular frame bandwidth list.
4467c478bd9Sstevel@tonic-gate      Before adding, we need to double check the availability of bandwidth in
4477c478bd9Sstevel@tonic-gate      those respective lists. If needed bandwidth is not available, then,
4487c478bd9Sstevel@tonic-gate      return an error. Otherwise add this bandwidth to all the required frame
4497c478bd9Sstevel@tonic-gate      and micro frame lists.
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate      Ex: Assume given endpoint's polling interval is 32us and static node value
4527c478bd9Sstevel@tonic-gate          is 3. In this case, we need to add required bandwidth to 0,4,8,12,16,
4537c478bd9Sstevel@tonic-gate          20,24,28 frame bandwidth lists and micro bandwidth information is
4547c478bd9Sstevel@tonic-gate          saved using ehci_start_split_masks matrix. For this example, we need
4557c478bd9Sstevel@tonic-gate          to use any one of the 15 entries to save micro frame bandwidth.
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate      High speed split transactions (for full and low speed devices only):
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate      For a given full/low speed interrupt or isochronous endpoint, we need both
4607c478bd9Sstevel@tonic-gate      high speed and TT bandwidths. The TT bandwidth allocation is same as full
4617c478bd9Sstevel@tonic-gate      speed bus bandwidth allocation. Please refer to the "full speed bus"
4627c478bd9Sstevel@tonic-gate      bandwidth allocation section for more details.
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate      The EHCI driver will go through the following steps to allocate high speed
4657c478bd9Sstevel@tonic-gate      bandwidth needed for  this full/low speed endpoint.
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate      - Calculate the bandwidth required for a given endpoint using the formula
4687c478bd9Sstevel@tonic-gate        and overhead calculations mentioned in previous section. In this case,
4697c478bd9Sstevel@tonic-gate        we need to calculate bandwidth needed both for Start and Complete start
4707c478bd9Sstevel@tonic-gate        transactions separately.
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate      - Compare the bandwidth available in the least allocated frame list out of
4737c478bd9Sstevel@tonic-gate        32 frame lists against the bandwidth required by this endpoint. If this
4747c478bd9Sstevel@tonic-gate        exceeds the limit, then, return an error.
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate      - Find out the static node to which the given endpoint needs to be linked
4777c478bd9Sstevel@tonic-gate        so that it will be polled as per the required polling interval. This
4787c478bd9Sstevel@tonic-gate        value varies based on polling interval and current bandwidth load on
4797c478bd9Sstevel@tonic-gate        this schedule.
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate        Ex: If a polling interval is  4ms, then the endpoint will be linked to
4827c478bd9Sstevel@tonic-gate            one of the four static nodes (range 3-6) in the 4ms column of figure
4837c478bd9Sstevel@tonic-gate            4.8 in EHCI specification.
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate      - Depending on the polling interval, we need to add the above calculated
4867c478bd9Sstevel@tonic-gate        Start and Complete split transactions bandwidth to one or more frame
4877c478bd9Sstevel@tonic-gate        bandwidth lists and also to one or more micro frame bandwidth lists for
4887c478bd9Sstevel@tonic-gate        that particular frame bandwidth list. In this case, the Start split
4897c478bd9Sstevel@tonic-gate        transaction needs bandwidth in one micro frame, where as the Complete
4907c478bd9Sstevel@tonic-gate        split transaction needs bandwidth in next three subsequent micro frames
4917c478bd9Sstevel@tonic-gate        of that particular frame or next frame. Before adding, we need to double
4927c478bd9Sstevel@tonic-gate        check the availability of bandwidth in those respective lists. If needed
4937c478bd9Sstevel@tonic-gate        bandwidth is not available, then, return an error. Otherwise add this
4947c478bd9Sstevel@tonic-gate        bandwidth to all the required lists.
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate        Ex: Assume give polling interval is 4ms and static node value is 3. In
4977c478bd9Sstevel@tonic-gate            this case, we need to add required Start and Complete split
4987c478bd9Sstevel@tonic-gate            bandwidth to the 0,4,8,12,16,20,24,28  frame bandwidth lists. The
4997c478bd9Sstevel@tonic-gate            micro frame bandwidth lists is stored using ehci_start_split_mask &
5007c478bd9Sstevel@tonic-gate            ehci_complete_split_mask matrices. In this case, we need to use any
5017c478bd9Sstevel@tonic-gate            of the first 8 entries to save micro frame bandwidth.
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate            Assume we found that the following micro frame bandwidth lists of
5047c478bd9Sstevel@tonic-gate            0,4,8,12,16,20,24,28 frame lists can be used for this endpoint.
5057c478bd9Sstevel@tonic-gate            It means, we need to initiate "start split transaction" in first
5067c478bd9Sstevel@tonic-gate            micro frame of 0,4,8,12,16,20,24,28 frames.
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate            Start split mask = 0x01,	/*  00000001 */
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate            For this "start split mask",  the "complete split mask" should be
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate	    Complete split mask = 0x0e, /*  00001110 */
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate	    It means try "complete split transactions" in second, third or
5157c478bd9Sstevel@tonic-gate            fourth micro frames of 0,4,8,12,16,20,24,28 frames.
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate4.Reference
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate  - USB2.0, OHCI and EHCI Specifications
5207c478bd9Sstevel@tonic-gate
5217c478bd9Sstevel@tonic-gate    http://www.usb.org/developers/docs
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate  - USB bandwidth analysis from Intel
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate    http://www.usb.org/developers/whitepapers
526