linux kernel mmc storage driver overview

26

Click here to load reader

Upload: rajkumar-rampelli

Post on 13-Apr-2017

463 views

Category:

Education


50 download

TRANSCRIPT

Page 1: Linux Kernel MMC Storage driver Overview

Linux Kernel MMC Storage Driver Overview

- Raj Kumar Rampelli

Page 2: Linux Kernel MMC Storage driver Overview

Outline 0 Storage Devices on mobile platform

(smart phones, tablets etc.)0 RAM0 Internal Storage Devices0 External Storage Devices0 What is Flash Memory ?

0 Kernel storage driver overview (http://lxr.free-electrons.com/source/drivers/mmc/ )

0 mmc device driver overview0 Top view diagram0 block diagram and Internal diagram

0 SD and SPI protocol0 Mmc driver different Layers0 Important functions to look

for0 Tuning procedure0 SD Hot-plug

0 Sdhci controller role in Data transfer

0 SDMMC device registration0 Sdhci probe()

0 How to configure/enable SDHCI support

Note: To understand the few terms in this presentation, please refer to Introduction to Kernel & Device Drivers PPT (

http://www.slideshare.net/rampalliraj/kernel-device-drivers): It covers what is Kernel, what is a Module and what is device driver .

Page 3: Linux Kernel MMC Storage driver Overview

Storage Devices on Mobile Platforms0 Mobile Platforms will have mainly Three storage devices for applications/users to

store the Data0 RAM (Random Access Memory): also known as main memory and primary memory.0 Internal Storage device (Non-removable device)0 External Storage device (Removable device)

0 RAM is Volatile memory i.e. data present in this device will be lost when power is removed/off.

0 Internal Storage Device: Mobile devices will have a built-in non-volatile memory called internal storage.

0 External Storage Device: Android devices may support removable non-volatile memory called external storage devices.

0 Example: Look at Memory & Storage specification of smartphone mobile.

RAM: 2GB

Internal Storage: 16GB

External storage: upto 128GB

Snapshot taken from Flipkart Samsung j5-6 mobile spec.

Page 4: Linux Kernel MMC Storage driver Overview

What is Flash Memory ?0 Flash Memory is a non-volatile, solid state storage device i.e. keeps its data

without power.

0 Flash Memory is being used in wide range of devices. Examples are

0 Internal storage devices (eMMC or UFS)

0 USB sticks and SD Memory Cards

0 Digital audio players

0 Flash memory offers very high speed access to data.

0 Advantage: Flash memory, when packaged in a "memory card", is very resilient to damage, unlike many other storage devices. It can withstand extremes of temperature, being immersed in water or being accidentally dropped [2].

0 Disadvantage: It has a limited number of read/write cycles which limits its useful life span.

Page 5: Linux Kernel MMC Storage driver Overview

Internal Storage Device0 Internal Storage mostly holds the android operating

system so that the android device is able to access input and output devices.0 System memory (see image)

0 It is also called as Device Memory (internal memory).0 Go to settings page and select Storage option and you will

see the internal storage capacity of your device.

0 It also stores the applications or data that user saves in it.

0 The data stored in internal storage can be accesses much faster than the data present in external storage device.

0 Internal storage device is directly connected to the mother board where as the external device connected through a hardware interface.

0 Disadvantage: If device fails to boot then all the data present in the internal storage device may be lost.

Page 6: Linux Kernel MMC Storage driver Overview

Internal Storage Devices0Following are the storage devices which are mainly used for

main storage devices on mobile platforms0 eMMC: embedded Multi-Media Controller, refers to a package

consisting of both flash memory and a flash memory controller integrated on the same silicon die.

0 UFS: Universal Flash Storage (UFS) is a flash storage like eMMC device with higher data rates compared to it.

0 SATA: Serial ATA is a computer bus interface that connects host bus adapters to mass storage devices such as hard disk drives, optical drives, and solid-state drives.

0Will cover Linux Kernel eMMC (MMC storage)device drivers in this presentation.

Page 7: Linux Kernel MMC Storage driver Overview

External Storage Device0 Android devices may support

the capability of adding more external storage via removable cards like SD memory cards.

0 SD card: Secure Digital (SD) is a non-volatile memory card format developed by the SD Card Association (SDA) for use in portable devices.

0 Advantage: External storage devices are portal i.e. data can be easily moved from one location to other location.0 These storage devices are

used for data backup0 Disadvantage: Data transfer

rate is slow compared to internal storage devices.

SD card details found in settings->storage android

Page 8: Linux Kernel MMC Storage driver Overview

How to identify SD card’s class?Preferable card: class 10 or UHS-I cards

Class

Minimum Serial Data

Writing Speed

Symbol on SD card

 Class 2 2MB/s

 Class 4 4MB/s

 Class 6 6MB/s

 Class 10 10MB/s

 UHS Speed Class 1 (U1)

10MB/s

Page 9: Linux Kernel MMC Storage driver Overview

SD Memory card architecture

Card Info registers

Usage

CID Card identification number

RCA Relative card address published by the card during card identification process.

DSR Driver stage register

CSD Max data transfer rate and defines data format, error correction type, maximum data access/transfer time, Maximum read/write block length.

SCR SD configuration register

OCR Operation condition reg

SSR SD status register

CSR Card status register

Page 10: Linux Kernel MMC Storage driver Overview

SD and SPI protocolSPI Protocol SD Protocol

Design simple Complex

Loss of performance: 1bit mode Wide bus option. Supports 1bit and 4bit modes.

Card identification and addressing methods replaced by the h/w chip select CS signal

Its own Card Identification process

No broadcast commands Available

Uses only 7 pinsDAT1 and DAT2 are not usedDAT3 used as CSDAT0 data transferCLK lineDataIn line (Host to card line)

9 pins model:DAT0-DAT3 lines for data transferCLK line – clock lineCMD line – command line3 Power lines – supply voltage lines

Page 11: Linux Kernel MMC Storage driver Overview

Storage Device Driver for eMMC and SD devices

0Storage Device Driver ($kernel/drivers/mmc) is common for eMMC devices (internal storage device) and for SD memory cards (external storage device).

0eMMC and SD are block devices i.e. mmc device driver communicates with these devices in the form of blocks of data (512 bytes)0 Character device is one with which the driver communicates

by sending/receiving single characters (bytes), eg: 0mmc drivers receives the block requests from generic block

layer (upper layer)

Page 12: Linux Kernel MMC Storage driver Overview

mmc Device Driver Top View

Kernel Space

User Space

Virtual File System Layer

Generic Block Layer

mmc device driver

Hardware devices

eMMC device SD memory card

User applications

Page 13: Linux Kernel MMC Storage driver Overview

mmc Device Driver block diagram

Kernel Space

Virtual File System Layer

Generic Block Layer

Hardware devices

eMMC device SD memory card

mmc device driver

mmc Block/Queue driver

mmc core driver

mmc host driver

SDHCI Host driver

/mmc/card/block.c/mmc/card/queue.c

/mmc/core/core.c/mmc/core/mmc.c

/mmc/core/sd.c

/mmc/host/sdhci.c

Page 14: Linux Kernel MMC Storage driver Overview

mmc device driver overview0 mmc queue receives block read/write/erase

requests from the generic core block layer0 mmc queue driver picks up one request from its

queue and assign it to mmc block driver0 mmc block driver analyze the type of request and

forwards the request to mmc core driver.0 mmc core driver has the protocol implementation

for eMMC/SD devices detection, enumeration and data transfers to communicated with the actual Hardware device.

0 mmc core driver receives the request from block driver, prepares a mmc_request and forwards it to the mmc host driver.

0 mmc host driver initiates the transfer to device by programming Hardware controller registers.

0 Once the request get processed by the hardware controller, an interrupt gets generated .

0 mmc host driver receives request complete interrupt, analyzes it and pass the response to block driver. This process continues for all block requests.

mmc Queue driver (queue.c)

mmc core driver(core.c, mmc.c, sd.c)

mmc host (controller) driver

SDHCI Host driversdhci.c

mmc Block driver(block.c)

Page 15: Linux Kernel MMC Storage driver Overview

mmc queue layer(/drivers/mmc/card/queue.c)0 Important functions:0mmc_init_queue()

0 initializes the device queue0 Creates and run the kernel thread (mmc_queue_thread)

“mmcqd” to fetch block I/O requests from core block layer and pass it mmc block layer.

0mmc_queue_thread()0 Fetch block I/O requests using blk_fetch_request()0 Pass the request to mmc block layer using callback issue_fn()

-> redirects to -> mmc_blk_issue_rq() in mmc block driver

Page 16: Linux Kernel MMC Storage driver Overview

mmc block layer (/drivers/mmc/card/block.c)0 Important functions: 1) mmc_blk_probe()

0 Calls the mmc_queue_initialize() to initialize mmc queue.0 Allocates the block devices (eMMC and SD card) and its partitions.0 Initializes the mmc_blk_data (md) structure with required function callbacks for

I/O requests, assigns MAJOR/MINOR info.md->queue.issue_fn = mmc_blk_issue_rq; md->disk->major = MMC_BLOCK_MAJOR; md->disk->first_minor = devidx * perdev_minors;

0 2) mmc_blk_issue_rq() – receives block I/O request from mmc queue thread from mmc queue driver. If I/O request type is ERASE then it calls mmc_blk_issue_discard_rq(). If I/O request is READ/WRITE then calls mmc_blk_issue_rw_rq()

0 2A) mmc_blk_issue_rw_rq() – prepares mmc block request and responsible for followings: Sets data block size to 512 (FIXED) 0 Retrieve block count information using blk_rq_sectors()0 Assigns appropriate command flags and data flags0 Sets the timeout for a Data command using mmc_set_data_timeout() function

(defined in mmc core driver)0 Assign the mmc block request to mmc core driver by calling mmc_start_req()

function.

Page 17: Linux Kernel MMC Storage driver Overview

mmc core layer(/drivers/mmc/core/*)

0 It Implements all SD/eMMC-dependent functionality, entire communication protocol is implemented in this layer.

0Receives request in mmc_start_req() from mmc block layer0 Before starting this new request, it checks for any ongoing

request. Holds this new request until the ongoing request is processed.

0 It calls mmc host layer function sdhci_request() to program the command and its dependant parameters in the mmc controller register for initiating the command transfer. (/drivers/mmc/host/sdhci.c)

Page 18: Linux Kernel MMC Storage driver Overview

mmc host layer (drivers/mmc/host/*)

0 It implements the driver for most known platform controllers and is platform dependent.

0 Important functions:0 sdhci_add_host() : adds the sdhci host controller with the driver model. It

initializes the sdhci h/w controller and enables sdhci interrupts.0 sdhci_request(): It initiates the data transfer of received request by

programming the command details in the corresponding h/w register.0 Sets the SW timer to ensure that there is no infinite wait for the transfer complete

interrupt0 Prepares the data and sets SDMA or ADMA mode

0 sdhci_irq(): It receives the transfer complete interrupt and analyzes it for any errors. It sends the response of the transfer to block layer.

0 sdhci_execute_tuning(): Tuning procedure: It is required for reliable data transfers when interface freq is more than 50MHz. It determines the TAP value by issuing CMD19.0 Controller issues CMD19 (SD/SDIO) or CMD21(eMMC) to get card’s tuning block at the current tap value

X. Compares with its tuning block0 If matches - Tuning is passed for the tap value X0 Else - Tuning is not passed for the tap value X, try next tap X+1

Page 19: Linux Kernel MMC Storage driver Overview

SD Host controller role @Data Transfer

0 Data location of system memory DMA_SYSTEM_ADDR (If DMA supported)0 Set Block size BLOCK_SIZE0 Set Block count BLOCK_COUNT0 Set argument value ARGUMENT0 Set TRANSFER_MODE value, determines

0 Single/Multi-Block transfer0 Block count enabled ?0 Data transfer direction0 ACMD12(eMMC/SD) or CMD52(SDIO) enabled ?0 DMA enabled ?

0 Set COMMAND execution started0 Wait for CMD complete Interrupt0 Write 1 to the CMD_COMPLETE in Normal status Interrupt Register0 Based on Read/Write CMD, the associated Registers/Interrupts enabled

0 Wait for Buffer Read Ready or Buffer Write Ready Interrupt0 Clear Buffer Read Ready Status or Buffer Write Ready Status0 Wait for TRANSFER_COMPLETE Interrupt0 Clear TRANSFER_COMPLETE Status

Page 20: Linux Kernel MMC Storage driver Overview

Mmc driver features0 Host-Device interface is reliable when FREQ limits upto 50MHz

0 SD: High speed (HS) SD cards, class 4 cards0 eMMC: eMMC devices with versions 4.41 or below

0 Tuning procedure is required when host-device interface runs at more than 50MHz.0 SD: Ultra High Speed (UHS) SD cards, and class 10 SD cards.0 eMMC: eMMC devices with versions 4.5 or more supports tuning

0 Mmc driver supports SD hot-plug feature, so that SD card can be inserted into already running device without powering of the device.

0 MMC driver supports voltage switching feature, if SD cards of type 10 or UHS-I inserted then voltage switching is invoked to switch voltage from 3.3 V to 1.8V for power optimization.0 UHS SD cards runs at 1.8V

0 Clock gating is enabled: If there are no transactions on eMMC/SD interface then clock supply will be off, to save the power of the device.

Page 21: Linux Kernel MMC Storage driver Overview

SDMMC devices registration0 Device registration requires both device name and driver name should match0 Device registration is done in board-<board-name>-sdhci.c

0 platform_device_register(&tegra_sdhci_device3); /* eMMC */ platform_device_register(&tegra_sdhci_device2); /* SD/SDIO */ platform_device_register(&tegra_sdhci_device0); /* SDIO/SD */

0 Platform_device Structure:static struct platform_device tegra_sdhci_deviceX = { .name = "sdhci-tegra",.id = X, /* X = 0 or 1 or 2 or 3 */.resource = sdhci_resourceX,.num_resources = ARRAY_SIZE(sdhci_resourceX),.dev = { .platform_data = &tegra_sdhci_platform_data3, }, };

0 As part of device enumeration, we use discovery method to identify whether the device is eMMC or SD or SDIO.

Page 22: Linux Kernel MMC Storage driver Overview

SDHCI probe()Probe() is called when device is recognized by the platform

Driver’s init function gives kernel a list of devices it is able to service, along with a pointer to a probe function. Kernel then calls the driver’s probe function one for each device.

0 probe function starts the per-device initialization:0 initializing hardware, allocating resources, and 0 registering the device with the kernel as a block device.

0 Kernel/drivers/mmc/host/sdhic-tegra.c sdhci_tegra_probe()0 Host controller initialization at

kernel/drivers/mmc/host/sdhci.c sdhci_add_host()0 Device initialization starts in

kernel/drivers/mmc/core/core.c mmc_rescan()0 Starts execution when Host detects the device.0 mmc_attach_sdio() sdio.c [core driver]0 mmc_attach_sd() sd.c [core driver]0 mmc_attach_mmc() mmc.c [core driver]

Page 23: Linux Kernel MMC Storage driver Overview

How to enable SDHCI controller: MMC/SD Card support Configuration

0Configure below variables for mmc devices (eMMC and SD devices share same sdhci controller)0 MMC0 MMC_SDHCI0 MMC_SDHCI_PLTFM

0Optional0 MMC_DEBUG0 MMC_BLOCK

0drivers/mmc/Kconfig

Page 24: Linux Kernel MMC Storage driver Overview

Conclusion0 eMMC device is used for internal storage on mobile platforms0 SD device (external SD cards) is used for external storage on

mobile platforms0 eMMC device and SD device both uses same driver on Linux

platform. Pointer to this driver ishttp://lxr.free-electrons.com/source/drivers/mmc/

0 eMMC and SD devices registers with block layer as a block devices.

0 Mmc driver sub-divided into three layers block (or queue) subsystem, core layer and host layer.

0 eMMC and SD uses SD protocol for communication.0 Sdhci host controller communicates with eMMC and SD devices.0 Class 10 or UHS-I type SD cards are preferable for high data rates.

Page 25: Linux Kernel MMC Storage driver Overview

References

1. Wikipedia: https://en.wikipedia.org/wiki/Secure_Digital

2. TEACH-ICT – The very best KS3, GCSE and A Level Computer Science resources.

3. SAMSUNG Galaxy J5 - 6 (New 2016 Edition)(Black, 16 GB) Specification snapshot from flipkart.com

4. SD Specifications Part A2 SD Host Controller Standard Specification Version 3.0

5. JEDEC STANDARD EMBEDDED MULTI-MEDIA CARD (e•MMC), ELECTRICAL STANDARD (4.5 device)

Page 26: Linux Kernel MMC Storage driver Overview

THANK YOU Have a look atMy PPTs: http://www.slideshare.net/rampalliraj/My Blog: http://practicepeople.blogspot.in/