2014/01/07

Data Into Storage

I uploaded a picture to Facebook, here is a my guess how a packet of the picture flies and lands.


  • Packet is sent to Linux kernel
  • Linux kernel handles it to network adapter driver
  • Network adaptor sends packet to network, Packet goes through few routers or any other devices and  reaches server in Facebook data center.
  • Server network adapter collects data and sends it HTTP server application.
  • HTTP server application wants save this packet permanently, so the packet is sent back to server kernel to be written on a storage device.
  • Packet is sent to Fibre Channel driver, Fibre Channel adapter use Fibre Channel protocol to wrappers SCSI write command which contains the packet. 
  • Packet in SCSI command flies over SAN and arrives at a storage controller system
  • Storage controller system ( may be a RAID controller ) finds out which hard disk to write the data and wrap the data with ATA command.
  • ATA command is sent via SATA cable and received by hard disk controller
  • Hard disk controller decodes SATA information and the encode packet with EDC+LPDC and write to hard disk. ( a lot of complexity is hidden in this step, that is the my current job ...  )
There is a lot of overhead and complexity here and there. 


Reference

AHCI

AHCI Implementation
drivers/ata/ahci_platform.c
drivers/ata/libahci.c
implements most ata_port_operations operations

ahci_init_one,
  memory mapping
  hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar];  AHCI_PCI_BAR_STANDARD

static inline void __iomem *__ahci_port_base(struct ata_host *host,
     unsigned int port_no)
{
struct ahci_host_priv *hpriv = host->private_data;
void __iomem *mmio = hpriv->mmio;

return mmio + 0x100 + (port_no * 0x80);
}

hpriv->mmio points to the HBA memory registers,  pointed by ABAR(AHCI Base Address).
 __ahci_port_base gets the port register.


















Command table is initialized in ahci_port_start(), pp->cmd_tbl = mem;

Below maps to AHCI spec v3.3, port registers.
PORT_LST_ADDR = 0x00, /* command list DMA addr */
PORT_LST_ADDR_HI = 0x04, /* command list DMA addr hi */
PORT_FIS_ADDR = 0x08, /* FIS rx buf addr */
PORT_FIS_ADDR_HI = 0x0c, /* FIS rx buf addr hi */
PORT_IRQ_STAT = 0x10, /* interrupt status */
PORT_IRQ_MASK = 0x14, /* interrupt enable/disable mask */
PORT_CMD = 0x18, /* port command */
PORT_TFDATA = 0x20, /* taskfile data */
PORT_SIG = 0x24, /* device TF signature */
PORT_CMD_ISSUE = 0x38, /* command issue */
PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */
PORT_SCR_CTL = 0x2c, /* SATA phy register: SControl */
PORT_SCR_ERR = 0x30, /* SATA phy register: SError */
PORT_SCR_ACT = 0x34, /* SATA phy register: SActive */
PORT_SCR_NTF = 0x3c, /* SATA phy register: SNotification */
PORT_FBS = 0x40, /* FIS-based Switching */
PORT_DEVSLP = 0x44, /* device sleep */

2013/12/17

Get backtrace

This the place holder for all the investigation made about how to get back trace information at run time.

I have a embedded system running a tiny proprietary real time OS which can handle few tasks. When the system is stopped at debugger break point, from debugger it is easy to find out stack trace of the task get stopped ( or OS kernel ), but I have no way to get other task's stack trace.  ARM's debugging toolchain has little help on this since everything is proprietary.

http://www.dwarfstd.org/doc/DWARF4.pdf
https://github.com/eliben/pyelftools/wiki/User's-guide
http://eli.thegreenplace.net/2011/02/07/how-debuggers-work-part-3-debugging-information/

2013/11/14

My girl's math home work

Here is the python script to generate it, she must hate to have a father as a programmer.

2013/10/08

ATA in Linux

SG_IO
The scsi-core (also known as the "mid level") contains the core of scsi support.
scsi generics driver (sg.o) represent the upper level drivers.

A significant addition in sg v3 is an ioctl() called SG_IO which is functionally equivalent to a write() followed by a blocking read(). In certain contexts the write()/read() combination have advantages over SG_IO (e.g. command queuing) and continue to be supported.

SG_IO call path, the IO request was put to block layer's queue, it is queue handlers responsibility to actually handle the request.

sd_ioctl
scsi_cmd_blk_ioctl
scsi_cmd_ioctl
sg_io
blk_execute_rq
blk_execute_rq_nowait
blk_mq_insert_request

sd_ioctl is registered as ioctl of block_device_operations, which will be registered to system via add_disk(), in function sd_probe_async().


And Here is the queue handling part:

scsi_queue_rq (queue_rq, registered as a blk_mq_ops)
scsi_dispatch_cmd
ata_scsi_queuecmd ( queuecommand )
__ata_scsi_queuecmd
ata_scsi_translate
ata_qc_issue


Zone ATA Command
sd_ioctl
_report_zones_ioctl
blk_zoned_report
blk_cmd_with_sense
blk_cmd_execute
blk_execute_rq



ATA Command Definition
include/linux/ata.h



LibATA
http://linuxmafia.com/faq/Hardware/sata.html

This is the newer ATA driver set for selected SATA chipsets only, maintained by Jeff Garzik, leveraging the kernel's well-tested SCSI layer. Garzik developed it in the 2.6 kernel series. 2.4 support was available only with a backported patch until libata's inclusion in 2.4.27 and later.

libata causes each SATA port appear as a new SCSI bus. There are individual low-level drivers for the individual SATA chipsets, e.g., ahci, pdc_adma, ata_piix, sata_nv, sata_mv, sata_promise, sata_qstor, sata_sil, sata_sil24, sata_sis, sata_sx4, sata_uli, sata_svw, sata_via, sata_vsc.


http://ftp.dei.uc.pt/pub/linux/kernel/people/jgarzik/libata/libata.pdf
struct ata_port_operations is defined for every low-level libata hardware driver, and it controls how the low-level driver interfaces with the ATA and SCSI layers.

2013/09/26

ARM Soc Tracing

How It Work
The external debug software configures the trace and debug components through the DAP. The ROM table contains a unique identification code for the SoC and the base addresses of the components connected to the debug APB. The trace stream from the ETM-R4 is replicated to provide on-chip storage using the CoreSight ETB or output off-chip using the TPIU.



Configuring the Trace Data Output Mode on SoC
After a single ATB trace stream is formed through TF, it goes through the Trace Port Interface Unit (TPIU) to reach the trace data pins, TEST[7:0], and trace clock output pin, TEST[8], while in parallel ETM mode
The TPIU formats the ATB trace stream to generate the formatted data output to the SOC pins, which are connected to TPA.
TPA ( Trace Port Analyser ) is a module in sider in DSTREAM.

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...