Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3057862ybv; Sat, 15 Feb 2020 09:55:24 -0800 (PST) X-Google-Smtp-Source: APXvYqylBb2+l5cSBofySdp0dF+0uz2MSIMU19ddjCreTuEQZzf7n6BmXPQWgfLL/DgxDeQcYe9s X-Received: by 2002:a9d:7489:: with SMTP id t9mr4880528otk.255.1581789324866; Sat, 15 Feb 2020 09:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581789324; cv=none; d=google.com; s=arc-20160816; b=F5VGb4my6TVooppSeQCPi/Lh2/oZzBnE0J2zOkSkGo3rm4h94SbtuoFKcUWyxk3ZoB isSyRflzO0Sbnsm0bmCGSzS1sSrLOo0OmWPQaTCJ05Nc2Ow0ewZrDhu6YW7vI/hC2Ez+ 5roox3K/amth3T6pebb5hvMsYwEWm81Z8BuAvjPDqs44X1vrDhuDMYaV1pkEufeKOKDa Abn6LEYVEfONmH5PaUOBnU8Mb5cl1t8zKXMMmCEPqc7nj38Gc/Oi45mxVaGUZzeCbgXO d4JSrjdHiVRBP+/joFjC+GmfC4jSTSGT+WznHsV5cw73wjfpRkeI250ePDDibdFyQotg h+tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=aOCzRdTt1yQCLavJegkAAZRjlqi9VOCuKyoKogIlAn0=; b=FeuQqOIj7NXI0OhLv5G/MTden/HqagvUR6JTOuy/N4ixfklgIFshR+C9jSWfjRG971 URCJ2UgiFeJiwHaeCtN7gnE20ZqC6SfSflE/NnXTu0hAgO/X7FIr/mTsbXjGf0+rpYwe GYhxKRv3nBwACTND2rRRLnWar4Ni9XWZeVYFypE3aH58Pprz2rDx8bmCiHOWEnVZtsSW 4I0UFfyqAu0ihKixTT+FFkriJy65HRkGtxZC8iaUhwbK5HmJtGBkJywirQjAo8PRPgNu utR4HwnFRxmuHtVeUWgMIV9yDAZuLIF/M1hAL00C2UdxVVYjWzrNJIk58HeoURBNMG6N 7VAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bigP+Fe7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e20si4486168oig.199.2020.02.15.09.55.11; Sat, 15 Feb 2020 09:55:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bigP+Fe7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727640AbgBORvg (ORCPT + 99 others); Sat, 15 Feb 2020 12:51:36 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41845 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgBORvf (ORCPT ); Sat, 15 Feb 2020 12:51:35 -0500 Received: by mail-pf1-f194.google.com with SMTP id j9so6652735pfa.8; Sat, 15 Feb 2020 09:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aOCzRdTt1yQCLavJegkAAZRjlqi9VOCuKyoKogIlAn0=; b=bigP+Fe7+KvZpDJn4uA7EPgogBtxY6xbioR8I+vSPWGlrX3S/3OFrdn426sC+N/3H5 CUWD694QkhRxSolqE3QvvWy8lZq4c48vFYpLMiirSwscGn5VNukknWkOfNW3wImrrThW 5kiIg7hBf+BPXYbJIOiZL6/+jTXv38QJAnYDl3XDWsdlkgri753NPV2bGaZYcJb1XTjZ NJQ3vlynSHX1zx6zUuKzJfMGjnVOQXmYOaIlCDsKSS3a0cMlQZg/4hJ/Gk5/HHew4q1K DfznvhBPF1eOQksoE2fArI0NHJj0a+Ag/wbm7GrcUSXTsMGXf3aFVDAPHzd6O1aB3Lep bNyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aOCzRdTt1yQCLavJegkAAZRjlqi9VOCuKyoKogIlAn0=; b=rd6ywg8PTCpKT/4GH6KA7ioz6AAePurxdap0QCbI5mLd7W7joqh5ImbXLbBMOrdAj9 43aqm0PsguUMH7Sm9ZAL9rgtAIfc/ptLNY+bqChOIP5SgM2S0/jPskzy3pmNMQvhNWRg JWhxNs5qPeQHxBIncTJ+uNsuY8OkP+CqQmfD2dZ4YChrD+MQ///tUpPg41X5Jtybvqst GFyOffDCmxUoMamFvE4XAYkr5MthEZIZP4N5hUSCNGXn6B7SvuvqamFCALKlMRfN83St WKabPEOFqk71AfHxxrd/GaI8twuM7HqqfebGssggw20ujukQAdkBKQuXGnzQ4YMN8/0A AF6w== X-Gm-Message-State: APjAAAXvU5lmNU93LdE5mL36PYAkWreyuHmN7sZDVU7EsK8A5NxqSwHQ zQudchYaK17Yk4Za3pWF/fk= X-Received: by 2002:a63:fc51:: with SMTP id r17mr9600461pgk.292.1581789094682; Sat, 15 Feb 2020 09:51:34 -0800 (PST) Received: from localhost.localdomain ([49.207.56.214]) by smtp.gmail.com with ESMTPSA id g13sm7176375pgh.82.2020.02.15.09.51.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 15 Feb 2020 09:51:34 -0800 (PST) From: Rishi Gupta To: gregkh@linuxfoundation.org, robh+dt@kernel.org Cc: jslaby@suse.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Rishi Gupta Subject: [PATCH v2 4/4] tty: documentation: document how to use ttyvs driver Date: Sat, 15 Feb 2020 23:21:09 +0530 Message-Id: <1581789069-5232-4-git-send-email-gupt21@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1581789069-5232-1-git-send-email-gupt21@gmail.com> References: <1581789069-5232-1-git-send-email-gupt21@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit documents how to use ttyvs driver to create/delete virtual tty devices, how to emulate various serial port events through this driver etc. Signed-off-by: Rishi Gupta --- Changes in v2: - Added this file from v2 only Documentation/virtual/tty-ttyvs.rst | 142 ++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Documentation/virtual/tty-ttyvs.rst diff --git a/Documentation/virtual/tty-ttyvs.rst b/Documentation/virtual/tty-ttyvs.rst new file mode 100644 index 0000000..4321e05 --- /dev/null +++ b/Documentation/virtual/tty-ttyvs.rst @@ -0,0 +1,142 @@ +================================================ +Kernel driver for virtual tty null modem devices +================================================ + +Author: Rishi Gupta + +The ttyvs driver (drivers/tty/ttyvs.c) creates virtual tty devices +that can be used with standard POSIX APIs for terminal devices. + +Applications can write to the sysfs file provided by this driver to +emulate various serial port communication events and error conditions. + +This driver creates a virtual card which can have 0 to 65535 virtual +tty devices. + +Use cases +========= +- Automated performance and scalability testing +- Serial port redirector to any other subsystem like TCP/IP +- Feeding data to GPS simulator +- Segregating hardware issues from software bugs quickly +- Serial port communication sniffer or test sniffer application itself +- Application development when hardware is still not available +- Testing user space drivers & corner case by injecting handcrafted data +- Migrate binary only or legacy applications to new communication medium +- Analyze and reverse-engineer serial protocols +- Cases where socat utility does not meet requirements for unix-like OS +- Cases where available physical serial ports don't meet requirements +- Product demo where data from hardware needs to be sent to the GUI app +- Stress and corner case testing of user space application + +How to create devices +===================== +There are two ways to create devices: + +1. Using device tree: +The card is modelled as a node with zero or more child nodes each +representing a virtual tty device. To create a device simply define +a child node with the required device parameters. This is explained +in detail in DT binding file: +Documentation/devicetree/bindings/serial/ttyvs.yaml + +2. Using configfs: +When ttyvs driver is loaded, it will create ttyvs directory inside +configfs mount point. For ex; if configfs is mounted at /config, then +/config/ttyvs directory will be created. To create a device, simply +create directory inside this, write values to be used as device +parameters and finally write 1 to create attribute. Defining ownidx +and devtype is mandatory. + +Pin mappings are bit maps; set bit 0 to connect a pin to CTS pin, +set bit 1 to connect to DCD pin, set bit 2 to connect to DSR and +set bit 3 to connect to RI. Pin naming conventions are follows +standard RS232 DB9 connector naming conventions. + +An example to create a loop-back device with device number as 0 +(/dev/ttyvs0), RTS and DTR pins unconnected, no need to assert DTR +when device is opened would be something like this: + +.. code-block:: sh + + mkdir /config/ttyvs/devlb-0 + echo 0 > /config/ttyvs/devlb-0/ownidx + echo lb > /config/ttyvs/devlb-0/devtype + echo 0 > /config/ttyvs/devlb-0/ortsmap + echo 0 > /config/ttyvs/devlb-0/odtrmap + echo 0 > /config/ttyvs/devlb-0/odtratopn + echo 1 > /config/ttyvs/devlb-0/create + +An example to create a standard null modem pair with device numbers +0 and 1 with pin numbers as per RS232 standards will be something +like this: + +.. code-block:: sh + + /dev/ttyvs0 /dev/ttyvs1 + TX (3) ----> (2) RX + RX (2) <---- (3) TX + RTS (7) ----> (8) CTS + DTR (4) --+-> (1) DCD + +-> (6) DSR + CTS (8) <---- (7) RTS + DCD (1) <-+-- (4) DTR + DSR (6) <-+ + + mkdir /config/ttyvs/devnm-0-1 + echo nm > /config/ttyvs/devnm-0-1/devtype + echo 0 > /config/ttyvs/devnm-0-1/ownidx + echo 1 > /config/ttyvs/devnm-0-1/ortsmap + echo 6 > /config/ttyvs/devnm-0-1/odtrmap + echo 0 > /config/ttyvs/devnm-0-1/odtratopn + echo 1 > /config/ttyvs/devnm-0-1/peeridx + echo 1 > /config/ttyvs/devnm-0-1/prtsmap + echo 6 > /config/ttyvs/devnm-0-1/pdtrmap + echo 0 > /config/ttyvs/devnm-0-1/pdtratopn + echo 1 > /config/ttyvs/devnm-0-1/create + +Directory name devnm-0-1 can be user defined. We used this simple style +as it is intuitive to understand that the device is null modem with +numbers 0 and 1. Further, to use configfs based approach, kernel must +be compiled with CONFIG_CONFIGFS_FS=y option. + +How to delete devices +===================== +To delete a device created by configfs simply delete the directory +created in /config/ttyvs directory. If the device is part of a null +modem pair, peer device will also be deleted automatically. + +How to emulate events +===================== +When a virtual tty device is created, an event sysfs file will also +be created by the driver (/sys/class/tty/ttyvsN/event N is device +number). + +1. Emulating framing error: the driver inserts -7 in data buffer as +the byte that got corrupted due to framing error while receiving data. +To emulate this write 1 to /sys/class/tty/ttyvsN/event file. + +2. Emulating parity error: the driver inserts -8 in data buffer as +the byte that got corrupted due to parity error while receiving data. +To emulate this write 2 to /sys/class/tty/ttyvsN/event file. + +3. Emulating overrun error: the driver reports to tty layer that an +overrun has happened.To emulate this write 3 to /sys/class/tty/ttyvsN/event +file. + +4. Emulating ring indication: to emulate as if ring indication has been +observed write 4 to the event file. To emulate as if ring indication has +been removed write 5 to the event file. + +5. Emulate break received: to emulate as if break condition has been received +write 6 to the /sys/class/tty/ttyvsN/event file. + +6. Emulate faulty cable: to emulate as if the cable is faulty write 7 +to the event file. In this case data sent from sender will not be received +by the receiver end. To remove this condition write 8 to the event file. + +How to support more devices +=========================== +By default ttyvs driver supports upto 64 devices. This can be +changed by passing module parameter max_num_vs_devs or by defining +max-num-vs-devs device tree property. -- 2.7.4