From nobody Thu Apr 25 00:32:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1596077818; cv=none; d=zohomail.com; s=zohoarc; b=ewcq7dp8b1QcJEO4Mdrb0LluNNFudTUhrkwiU48sOpEeomkLZbegLZTeYWQjKLJRxZJs1Z8HMsbDAXW2bXzxdBGblIxsz8A40DTLySGCuBmTZIT0JhKugPB/1x5vXqW0oGnw5m+iFwK/eW8li6z4/Z2yLttsEwz58PYgIWJYmpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596077818; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nl6raLUsbNq3/9uvbS2S/bPVJiFmOEgFqwV3lRZxT4c=; b=JRFrUYUEPv61XsCfKmXnPkPqVC7YeUku0LrGsZQdpzNBVj7SexJifbSGI+NwsCoZ1KZp40vT3rvJ57GIPCEm94rrWplYjCyz5JLKKxgNXXFAmjbNIzk+LRk0eR4oCsBF4e8I0Tkx3TIZ3Whf9nYPjAWUM7peMTQkYsy7nbFD8DM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1596077818537284.9192740761482; Wed, 29 Jul 2020 19:56:58 -0700 (PDT) Received: from localhost ([::1]:47468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k0ykb-0008Tx-Ag for importer@patchew.org; Wed, 29 Jul 2020 22:56:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0yjm-0007bT-K8 for qemu-devel@nongnu.org; Wed, 29 Jul 2020 22:56:06 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k0yjk-00012k-KI for qemu-devel@nongnu.org; Wed, 29 Jul 2020 22:56:06 -0400 Received: by mail-wr1-x444.google.com with SMTP id a5so13459249wrm.6 for ; Wed, 29 Jul 2020 19:56:04 -0700 (PDT) Received: from lhuhn.localdomain (24-148-42-188.s4794.c3-0.grn-cbr1.chi-grn.il.cable.rcncustomer.com. [24.148.42.188]) by smtp.gmail.com with ESMTPSA id p25sm6958025wma.39.2020.07.29.19.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2020 19:56:01 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=nl6raLUsbNq3/9uvbS2S/bPVJiFmOEgFqwV3lRZxT4c=; b=PBwf0JhF/iwSns876kYTnSQo9ZfA7fk/RPaiRsyCYhqzWGTpOslcJK02zI2gXFTc/U v+1f7D5eeBjm+MQ+BWKIHg1Ltmz1NhVZ6UKbAIfJH+5dsmXfU5ak0zGDHqVPvt1T+PWw wIKR519BMWt+nsh61EYGcOVEJUXVatjo+8mJKGvWlqze4CIPVdsaPevgrBv/RO7DW+Y7 HnFfFKzhULTKZErW9FP4HAMMo9waG5/0QdgA49xPvTTkXv+0mROXXW13yHxKg+tEQLUk 66jEPxFKa9L11ALRCZaGmOLQguWfXKg7X/k/mwmLTI9xjoj14mJQCgnxpdxYvOJCrpxz w4PQ== 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:mime-version:content-transfer-encoding; bh=nl6raLUsbNq3/9uvbS2S/bPVJiFmOEgFqwV3lRZxT4c=; b=nMxgw1av3EXCP/BgDM8ECcjIGSB67Gawe29CtwuwJYwxTDRPdUaxTc22+gTY/hpnA7 wEbIXjlj2QuUmA47HnfFj0n/edzd58LqnQCtyfqWvcgrW1HfbfXDrR6UazKKdH7eXpjf OowaoEv1FGoZeao/z+KAZrKIlBA0v+tiuJTYuoe7Q29EEcRdK/NzPOIRyhLshZdU49xC aSKEHZNKmJA38HZWNUrHUPm7pcZgOElwtkpLrT3agTQWgcUywEtlscioYZAAD9lDUUs8 s1gdbd3igY1SvwiCdVEt+j9oW7jkXBQYZzA3QQkc2DqA3aXVHKXSh2nfSWIxoaazoUSV pyGA== X-Gm-Message-State: AOAM530S8v/HQ1B6Ddz0r/63f5MGem3XTfwJxAXvc6Zr3now2WJ4hGJL ZMC2XmVuGpt07vvDB36ICfEQUR3g X-Google-Smtp-Source: ABdhPJxp4oTW/TJ7TI5RhhYUmdZchjbEWwGnkdqZqy80eh2SU+FSwKK7Oed0esIo0CbKSq91TPkXuA== X-Received: by 2002:adf:e382:: with SMTP id e2mr614479wrm.306.1596077761934; Wed, 29 Jul 2020 19:56:01 -0700 (PDT) From: Leif N Huhn To: qemu-devel@nongnu.org Subject: [PATCH 1/1] linux-user: Add support for SG_IO and SG_GET_VERSION_NUM raw SCSI ioctls Date: Wed, 29 Jul 2020 21:55:48 -0500 Message-Id: <20200730025548.237905-2-leif.n.huhn@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200730025548.237905-1-leif.n.huhn@gmail.com> References: <20200730025548.237905-1-leif.n.huhn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=leif.n.huhn@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leif N Huhn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" This patch implements functionalities of following ioctls: SG_GET_VERSION_NUM - Returns SG driver version number The sg version numbers are of the form "x.y.z" and the single number gi= ven by the SG_GET_VERSION_NUM ioctl() is calculated by (x * 10000 + y * 100 + z). SG_IO - Permits user applications to send SCSI commands to a device It is logically equivalent to a write followed by a read. Implementation notes: For SG_GET_VERSION_NUM the value is an int and the implementation is straightforward. For SG_IO, the generic thunk mechanism is used, and works correctly when the host and guest architecture have the same pointer size. A special i= octl handler may be needed in other situations and is not covered in this implementation. Signed-off-by: Leif N Huhn --- linux-user/ioctls.h | 2 ++ linux-user/syscall.c | 1 + linux-user/syscall_defs.h | 33 +++++++++++++++++++++++++++++++++ linux-user/syscall_types.h | 5 +++++ 4 files changed, 41 insertions(+) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 0713ae1311..92e2f65e05 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -333,6 +333,8 @@ IOCTL(CDROM_DRIVE_STATUS, 0, TYPE_NULL) IOCTL(CDROM_DISC_STATUS, 0, TYPE_NULL) IOCTL(CDROMAUDIOBUFSIZ, 0, TYPE_INT) + IOCTL(SG_GET_VERSION_NUM, 0, TYPE_INT) + IOCTL(SG_IO, IOC_RW, MK_PTR(MK_STRUCT(STRUCT_sg_io_hdr))) =20 #if 0 IOCTL(SNDCTL_COPR_HALT, IOC_RW, MK_PTR(TYPE_INT)) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 945fc25279..d846ef1af2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -115,6 +115,7 @@ #ifdef HAVE_DRM_H #include #endif +#include #include "linux_loop.h" #include "uname.h" =20 diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 3c261cff0e..0e3004eb31 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2774,4 +2774,37 @@ struct target_statx { /* 0x100 */ }; =20 +/* from kernel's include/scsi/sg.h */ + +#define TARGET_SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields= 20134 */ +/* synchronous SCSI command ioctl, (only in version 3 interface) */ +#define TARGET_SG_IO 0x2285 /* similar effect as write() followed by rea= d() */ + +struct target_sg_io_hdr +{ + int interface_id; /* [i] 'S' for SCSI generic (required) */ + int dxfer_direction; /* [i] data transfer direction */ + unsigned char cmd_len; /* [i] SCSI command length */ + unsigned char mx_sb_len; /* [i] max length to write to sbp */ + unsigned short iovec_count; /* [i] 0 implies no scatter gather */ + unsigned int dxfer_len; /* [i] byte count of data transfer */ + abi_ulong dxferp; /* [i], [*io] points to data transfer memory + or scatter gather list */ + abi_ulong cmdp; /* [i], [*i] points to command to perform = */ + abi_ulong sbp; /* [i], [*o] points to sense_buffer memory */ + unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millise= c) */ + unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */ + int pack_id; /* [i->o] unused internally (normally) */ + abi_ulong usr_ptr; /* [i->o] unused internally */ + unsigned char status; /* [o] scsi status */ + unsigned char masked_status;/* [o] shifted, masked scsi status */ + unsigned char msg_status; /* [o] messaging level data (optional) */ + unsigned char sb_len_wr; /* [o] byte count actually written to sbp = */ + unsigned short host_status; /* [o] errors from host adapter */ + unsigned short driver_status;/* [o] errors from software driver */ + int resid; /* [o] dxfer_len - actual_transferred */ + unsigned int duration; /* [o] time taken by cmd (unit: millisec) = */ + unsigned int info; /* [o] auxiliary information */ +}; /* 64 bytes long (on i386) */ + #endif diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 3f1f033464..3752d217e2 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -59,6 +59,11 @@ STRUCT(cdrom_read_audio, TYPE_CHAR, TYPE_CHAR, TYPE_CHAR, TYPE_CHAR, TYPE_CHAR, TYPE_INT, TY= PE_PTRVOID, TYPE_NULL) =20 +STRUCT(sg_io_hdr, + TYPE_INT, TYPE_INT, TYPE_CHAR, TYPE_CHAR, TYPE_SHORT, TYPE_INT, TYP= E_PTRVOID, + TYPE_PTRVOID, TYPE_PTRVOID, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_PTRV= OID, TYPE_CHAR, + TYPE_CHAR, TYPE_CHAR, TYPE_CHAR, TYPE_SHORT, TYPE_SHORT, TYPE_INT, = TYPE_INT, TYPE_INT) + STRUCT(hd_geometry, TYPE_CHAR, TYPE_CHAR, TYPE_SHORT, TYPE_ULONG) =20 --=20 2.28.0