SlideShare a Scribd company logo
Linux USB drivers
by Satyam
USB drivers
USB core drivers
Architecture independent kernel subsystem.
Implements the USB bus specification.
USB host drivers
Different drivers for each USB control hardware.
Usually available in the Board Support Package.
Architecture and platform dependent.
USB device drivers
Drivers for devices on the USB bus.
USB device controller drivers
For Linux systems with just a USB device controller
USB gadget
drivers
PLATFORM DEPENDENT
Supports the chip connecting to the USB bus.
PLATFORM INDEPENDENT
Ethernet gadget: implements networking
through USB
Storage gadget: makes the host see a USB
storage device
USB SUPPORT ARCHITECTURE
SUPPORT
USB device driver
USB Core
USB host controller
SYSTEM CALL INTERFACE
Other drivers
Hardware (USB DEVICE)
USER APPLICATION USERSPACE
KERNAL
TYPES OF USB HOST
CONTROLLER
1. OHCI (Open Host Controller Interface):
->Compaq’s implementation for USB 1.0 and USB 1.1
->Also used for some firmware devices
2.UHCI (Universal Host Controller Interface):
->Intel implementation for USB 2.0
3.EHCI (Extended Host Controller Interface):
->Only one to provide high speed transfer (USB 2.0)
4.SL811
->host controller, manufactured by Cypress.
->It has 256MB of internal SRAM buffer.
USB transfer speed
LowSpeed: up to 1.5 Mbps Since USB 1.0
FullSpeed: up to 12 Mbps Since USB 1.1
HiSpeed: up to 480 Mbps Since USB 2.0
USB descriptors
Device Represent the devices connected to the USB bus.
Example: USB speaker with volume control buttons.
Configurations Represent the state of the device.
Examples: Active, Standby, Initialization
Interfaces Logical devices.
Examples: speaker, volume control buttons.
Endpoints Unidirectional communication pipes.
Either IN (device to computer) or OUT (computer to device).
TYPES OF ENDPOINTS
Control endpoints: device control, accessing information, small transfers.
Guaranteed bandwidth.
Interrupt endpoints: data transfer at a fixed rate. Guaranteed bandwidth.
Bulk endpoints: use all remaining bandwidth. No bandwidth or latency
guarantee.
Isochronous endpoints:guaranteed speed. Possible data loss.
USB Request Blocks(URB)
An URB consists of all relevant information to execute any USB transaction
Any communication between the host and device is done asynchronously using USB
Request Blocks (urbs).
They are similar to packets in network communications.
Every endpoint can handle a queue of urbs.
Every urb has a completion handler.
A driver may allocate many urbs for a single endpoint, or reuse the same urb for
different endpoints.
The urb structure
PIPES FOR URB’s
Control pipes
usb_sndctrlpipe(), usb_rcvctrlpipe()
Bulk pipes
usb_sndbulkpipe(), usb_rcvbulkpipe()
Interrupt pipes
usb_sndintpipe(), usb_rcvintpipe()
Isochronous pipes
usb_sndisocpipe(), usb_rcvisocpipe()
Creating an URB’s
struct urb *usb_alloc_urb(int isoframes, int mem_flags)
Allocating URB’s isoframes->for isochronous transfer,’0’ for others
mem_flags->holds the memory allocation flag which allows to control the
block
Note: we must do the error handling if allocation fails it returns NULL
Eg:urb = usb_alloc_urb(0, GFP_KERNEL);
if(urb!=0)
printk(KERN_ALERT “Allocation failed”);
Freeing URB
void usb_free_urb(struct urb *urb);
Note : if the allocation dint return a completion call back or not been use it
can deallocate by itself .
Initializing urb’s
interrupt urbs
bulk urbs
control urbs
isochronous urbs(has to be done manually by driver,no function
available).
Function for Initilizing URB’s
void usb_fill_int_urb (
struct urb *urb, // urb to be initialized
struct usb_device *dev, // device to send the urb to
unsigned int pipe, // pipe (endpoint and device specific)
void*transfer_buffer, //transferbuffer
int buffer_length, // transfer buffer size usb_complete_t complete, // completion
handler
void *context, // context (for handler)
int interval // Scheduling interval (for interrupt URB’s)
unsigned char *setup_packet;//for control urbs
interval->low speed in ms/high speed in (1/8)ms
SUBMITTING URB’s
int usb_submit_urb(struct urb *urb, int mem_flags)
mem_flags is used for internal allocations performed by usb_submit_urb().
Settings that should be used:
GFP_ATOMIC: called from code which cannot sleep: a urb completion
handler, hard or soft interrupts. Or called when the caller holds a spinlock.
GPF_NOIO: in some cases when block storage is used.
GFP_KERNEL: in other cases.
Return Values-usb_sumit_urb
Out of memory (-ENOMEM)
Unplugged device (-ENODEV)
Stalled endpoint (-EPIPE)
Too many queued ISO transfers (-EAGAIN)
Too many requested ISO frames (-EFBIG)
Invalid INT interval (-EINVAL)
More than one packet for INT (-EINVAL)
however on submissmision urb->status will be -EINPROGRESS,it is suggested that we should not lookinto
unless we get a completion call.
Cancelling URB’s
There are two ways
->asynchronous cancel: int usb_unlink_urb(struct urb *urb);
->synchronously cancel: void usb_kill_urb(struct urb *urb);
Completion Handlers
After the data transfer successfully completed.
urb->status == 0
Error(s) happened during the transfer.
The urb was unlinked by the USB core.
urb>status should only be checked from the completion handler
Some of the Transfer Status
ECONNRESET: The urb was unlinked by usb_unlink_urb().
ENOENT: The urb was stopped by usb_kill_urb().
ENODEV: Device removed. Often preceded by a burst of other errors,
since the hub driver doesn't detect device removal events immediately.
EINPROGRESS:Urb not completed yet.
Writing USB drivers
checking which device support which driver.
passing the information from the user space to find the right driver during
hot-plug event.
driver needs to call right probe function and disconnect function.
All these information can be derived from usb_device_id structure.
(include/linux/mod_devicetable.h)
Declaring supported devices
USB_DEVICE(vendor, product)
Creates a usb_device_id structure which can be used to
match only the specified vendor and product ids.
Created usb_device_id structures are declared
with the MODULE_DEVICE_TABLE() macro
Drivers need to announce the devices they support in usb_device_id
structures.
Driver Registration
usb_register() to register our driver
static struct usb_driver mtouchusb_driver = {
.name = "mtouchusb",
.probe = mtouchusb_probe,
.disconnect = mtouchusb_disconnect,
.id_table = mtouchusb_devices,
};
static int __init mtouchusb_init(void)
{
return usb_register(&mtouchusb_driver);
}
Driver unregistration
usb_deregister() to register your driver
static void __exit mtouchusb_cleanup(void)
{
usb_deregister(&mtouchusb_driver);
}
probe() and disconnect() functions
The probe() function is called by the USB core to see if the driver is willing to
manage a particular interface on a device.
The driver should then make checks on the information passed to it about the
device.
If it decides to manage the interface, the probe() function will return 0.
Otherwise, it will return a negative value.
The disconnect() function is called by the USB core when a driver should no
longer control the device (even if the driver is still loaded), and should do some
cleanup.
Transfering without URB’s
The kernel provides two usb_bulk_msg()
and usb_control_msg() helper functions that make it possible to transfer
simple bulk and control messages
Constrains of transfering without
URB’s
These functions are synchronous and will make our code sleep
We cannot cancel our requests, as we have no handle on the URB used
internally
Thank you

More Related Content

What's hot

Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
RajKumar Rampelli
 
Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM
ShapeBlue
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
Yan Vugenfirer
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
Wave Digitech
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
Anil Kumar Pugalia
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
SysPlay eLearning Academy for You
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
shimosawa
 
Linux device drivers
Linux device drivers Linux device drivers
What is Bootloader???
What is Bootloader???What is Bootloader???
What is Bootloader???
Dinesh Damodar
 
Armboot process zeelogic
Armboot process zeelogicArmboot process zeelogic
Armboot process zeelogic
Aleem Shariff
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
Gene Chang
 
Basics of boot-loader
Basics of boot-loaderBasics of boot-loader
Basics of boot-loader
iamumr
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
Tushar B Kute
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
Emertxe Information Technologies Pvt Ltd
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
Satpal Parmar
 
Interrupts
InterruptsInterrupts
Interrupts
Anil Kumar Pugalia
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
Anil Kumar Pugalia
 
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
Macpaul Lin
 
spinlock.pdf
spinlock.pdfspinlock.pdf
spinlock.pdf
Adrian Huang
 
QEMU in Cross building
QEMU in Cross buildingQEMU in Cross building
QEMU in Cross building
Tetsuyuki Kobayashi
 

What's hot (20)

Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM Achieving the ultimate performance with KVM
Achieving the ultimate performance with KVM
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
BeagleBone Black Bootloaders
BeagleBone Black BootloadersBeagleBone Black Bootloaders
BeagleBone Black Bootloaders
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
What is Bootloader???
What is Bootloader???What is Bootloader???
What is Bootloader???
 
Armboot process zeelogic
Armboot process zeelogicArmboot process zeelogic
Armboot process zeelogic
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Basics of boot-loader
Basics of boot-loaderBasics of boot-loader
Basics of boot-loader
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Interrupts
InterruptsInterrupts
Interrupts
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)Bootstrap process of u boot (NDS32 RISC CPU)
Bootstrap process of u boot (NDS32 RISC CPU)
 
spinlock.pdf
spinlock.pdfspinlock.pdf
spinlock.pdf
 
QEMU in Cross building
QEMU in Cross buildingQEMU in Cross building
QEMU in Cross building
 

Similar to Linux Usb overview

Usb old
Usb oldUsb old
Usb old
surendartech
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
IJERA Editor
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
IJERA Editor
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
RuggedBoardGroup
 
Us bdrv tips2
Us bdrv tips2Us bdrv tips2
Us bdrv tips2
Sumit Tambe
 
Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_
Ganesh Kamath
 
HKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/OHKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/O
Linaro
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
mukul bhardwaj
 
Un se-bu
Un se-buUn se-bu
Steps to build and run oai
Steps to build and run oaiSteps to build and run oai
Steps to build and run oai
ssuser38b887
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
Sayanton Vhaduri
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
Kernel TLV
 
Usb Overview
Usb OverviewUsb Overview
Usb Overview
Pradeep Patel
 
Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01
KaoMao
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
Samael Wang
 
Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introduction
Project ACRN
 
Iphone ifuse
Iphone ifuseIphone ifuse
Iphone ifuse
guest8a79502
 
Notes for LX0-101 Linux
Notes for LX0-101 Linux Notes for LX0-101 Linux
Notes for LX0-101 Linux
Chris Henson, CCNP
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
Teja Bheemanapally
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
mcganesh
 

Similar to Linux Usb overview (20)

Usb old
Usb oldUsb old
Usb old
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
 
Cp33551556
Cp33551556Cp33551556
Cp33551556
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Us bdrv tips2
Us bdrv tips2Us bdrv tips2
Us bdrv tips2
 
Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_Study of USB Device Drivers under Linux _1_
Study of USB Device Drivers under Linux _1_
 
HKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/OHKG18-110 - net_mdev: Fast path user space I/O
HKG18-110 - net_mdev: Fast path user space I/O
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Un se-bu
Un se-buUn se-bu
Un se-bu
 
Steps to build and run oai
Steps to build and run oaiSteps to build and run oai
Steps to build and run oai
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
Usb Overview
Usb OverviewUsb Overview
Usb Overview
 
Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01Eekol 2012 jan04_int_ems_an_01
Eekol 2012 jan04_int_ems_an_01
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
Project ACRN USB mediator introduction
Project ACRN USB mediator introductionProject ACRN USB mediator introduction
Project ACRN USB mediator introduction
 
Iphone ifuse
Iphone ifuseIphone ifuse
Iphone ifuse
 
Notes for LX0-101 Linux
Notes for LX0-101 Linux Notes for LX0-101 Linux
Notes for LX0-101 Linux
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 

Recently uploaded

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 

Recently uploaded (20)

Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 

Linux Usb overview

  • 2. USB drivers USB core drivers Architecture independent kernel subsystem. Implements the USB bus specification. USB host drivers Different drivers for each USB control hardware. Usually available in the Board Support Package. Architecture and platform dependent. USB device drivers Drivers for devices on the USB bus. USB device controller drivers For Linux systems with just a USB device controller
  • 3. USB gadget drivers PLATFORM DEPENDENT Supports the chip connecting to the USB bus. PLATFORM INDEPENDENT Ethernet gadget: implements networking through USB Storage gadget: makes the host see a USB storage device
  • 4. USB SUPPORT ARCHITECTURE SUPPORT USB device driver USB Core USB host controller SYSTEM CALL INTERFACE Other drivers Hardware (USB DEVICE) USER APPLICATION USERSPACE KERNAL
  • 5. TYPES OF USB HOST CONTROLLER 1. OHCI (Open Host Controller Interface): ->Compaq’s implementation for USB 1.0 and USB 1.1 ->Also used for some firmware devices 2.UHCI (Universal Host Controller Interface): ->Intel implementation for USB 2.0 3.EHCI (Extended Host Controller Interface): ->Only one to provide high speed transfer (USB 2.0) 4.SL811 ->host controller, manufactured by Cypress. ->It has 256MB of internal SRAM buffer.
  • 6. USB transfer speed LowSpeed: up to 1.5 Mbps Since USB 1.0 FullSpeed: up to 12 Mbps Since USB 1.1 HiSpeed: up to 480 Mbps Since USB 2.0
  • 7. USB descriptors Device Represent the devices connected to the USB bus. Example: USB speaker with volume control buttons. Configurations Represent the state of the device. Examples: Active, Standby, Initialization Interfaces Logical devices. Examples: speaker, volume control buttons. Endpoints Unidirectional communication pipes. Either IN (device to computer) or OUT (computer to device).
  • 8. TYPES OF ENDPOINTS Control endpoints: device control, accessing information, small transfers. Guaranteed bandwidth. Interrupt endpoints: data transfer at a fixed rate. Guaranteed bandwidth. Bulk endpoints: use all remaining bandwidth. No bandwidth or latency guarantee. Isochronous endpoints:guaranteed speed. Possible data loss.
  • 9. USB Request Blocks(URB) An URB consists of all relevant information to execute any USB transaction Any communication between the host and device is done asynchronously using USB Request Blocks (urbs). They are similar to packets in network communications. Every endpoint can handle a queue of urbs. Every urb has a completion handler. A driver may allocate many urbs for a single endpoint, or reuse the same urb for different endpoints.
  • 11. PIPES FOR URB’s Control pipes usb_sndctrlpipe(), usb_rcvctrlpipe() Bulk pipes usb_sndbulkpipe(), usb_rcvbulkpipe() Interrupt pipes usb_sndintpipe(), usb_rcvintpipe() Isochronous pipes usb_sndisocpipe(), usb_rcvisocpipe()
  • 12. Creating an URB’s struct urb *usb_alloc_urb(int isoframes, int mem_flags) Allocating URB’s isoframes->for isochronous transfer,’0’ for others mem_flags->holds the memory allocation flag which allows to control the block Note: we must do the error handling if allocation fails it returns NULL Eg:urb = usb_alloc_urb(0, GFP_KERNEL); if(urb!=0) printk(KERN_ALERT “Allocation failed”);
  • 13. Freeing URB void usb_free_urb(struct urb *urb); Note : if the allocation dint return a completion call back or not been use it can deallocate by itself .
  • 14. Initializing urb’s interrupt urbs bulk urbs control urbs isochronous urbs(has to be done manually by driver,no function available).
  • 15. Function for Initilizing URB’s void usb_fill_int_urb ( struct urb *urb, // urb to be initialized struct usb_device *dev, // device to send the urb to unsigned int pipe, // pipe (endpoint and device specific) void*transfer_buffer, //transferbuffer int buffer_length, // transfer buffer size usb_complete_t complete, // completion handler void *context, // context (for handler) int interval // Scheduling interval (for interrupt URB’s) unsigned char *setup_packet;//for control urbs interval->low speed in ms/high speed in (1/8)ms
  • 16. SUBMITTING URB’s int usb_submit_urb(struct urb *urb, int mem_flags) mem_flags is used for internal allocations performed by usb_submit_urb(). Settings that should be used: GFP_ATOMIC: called from code which cannot sleep: a urb completion handler, hard or soft interrupts. Or called when the caller holds a spinlock. GPF_NOIO: in some cases when block storage is used. GFP_KERNEL: in other cases.
  • 17. Return Values-usb_sumit_urb Out of memory (-ENOMEM) Unplugged device (-ENODEV) Stalled endpoint (-EPIPE) Too many queued ISO transfers (-EAGAIN) Too many requested ISO frames (-EFBIG) Invalid INT interval (-EINVAL) More than one packet for INT (-EINVAL) however on submissmision urb->status will be -EINPROGRESS,it is suggested that we should not lookinto unless we get a completion call.
  • 18. Cancelling URB’s There are two ways ->asynchronous cancel: int usb_unlink_urb(struct urb *urb); ->synchronously cancel: void usb_kill_urb(struct urb *urb);
  • 19. Completion Handlers After the data transfer successfully completed. urb->status == 0 Error(s) happened during the transfer. The urb was unlinked by the USB core. urb>status should only be checked from the completion handler
  • 20. Some of the Transfer Status ECONNRESET: The urb was unlinked by usb_unlink_urb(). ENOENT: The urb was stopped by usb_kill_urb(). ENODEV: Device removed. Often preceded by a burst of other errors, since the hub driver doesn't detect device removal events immediately. EINPROGRESS:Urb not completed yet.
  • 21. Writing USB drivers checking which device support which driver. passing the information from the user space to find the right driver during hot-plug event. driver needs to call right probe function and disconnect function. All these information can be derived from usb_device_id structure. (include/linux/mod_devicetable.h)
  • 22. Declaring supported devices USB_DEVICE(vendor, product) Creates a usb_device_id structure which can be used to match only the specified vendor and product ids. Created usb_device_id structures are declared with the MODULE_DEVICE_TABLE() macro Drivers need to announce the devices they support in usb_device_id structures.
  • 23. Driver Registration usb_register() to register our driver static struct usb_driver mtouchusb_driver = { .name = "mtouchusb", .probe = mtouchusb_probe, .disconnect = mtouchusb_disconnect, .id_table = mtouchusb_devices, }; static int __init mtouchusb_init(void) { return usb_register(&mtouchusb_driver); }
  • 24. Driver unregistration usb_deregister() to register your driver static void __exit mtouchusb_cleanup(void) { usb_deregister(&mtouchusb_driver); }
  • 25. probe() and disconnect() functions The probe() function is called by the USB core to see if the driver is willing to manage a particular interface on a device. The driver should then make checks on the information passed to it about the device. If it decides to manage the interface, the probe() function will return 0. Otherwise, it will return a negative value. The disconnect() function is called by the USB core when a driver should no longer control the device (even if the driver is still loaded), and should do some cleanup.
  • 26. Transfering without URB’s The kernel provides two usb_bulk_msg() and usb_control_msg() helper functions that make it possible to transfer simple bulk and control messages
  • 27. Constrains of transfering without URB’s These functions are synchronous and will make our code sleep We cannot cancel our requests, as we have no handle on the URB used internally