[PATCH 3/8] sg: split header, expand and correct descriptions

2018-10-18 Thread Douglas Gilbert
Split scsi/sg.h into a smaller scsi/sg.h which includes a new header:
uapi/scsi/sg.h . Overall expand the twin header files with new
functionality in this patchset and functionality to be added in the
next patchset to implement SG_IOSUBMIT and friends. Adjust format to
modern kernel conventions. Correct and expand some comments.

Signed-off-by: Douglas Gilbert 
---

The new header file: uapi/scsi/sg.h is expected to be in the
kernel's public interface. This takes time (i.e. months or years)
to find its way into glibc and Linux distributions. So the sooner
it is presented and accepted the better.

>From the C perspective, nothing is removed or changed (or shouldn't
be), only additions. This means that the original typedefs stay (but
they are not used in the driver source file: sg.c) since user space
programs may be using them.

 include/scsi/sg.h  | 252 ++---
 include/uapi/scsi/sg.h | 415 +
 2 files changed, 426 insertions(+), 241 deletions(-)
 create mode 100644 include/uapi/scsi/sg.h

diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index f91bcca604e4..596f68746f66 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -7,23 +7,23 @@
 /*
  * History:
  *  Started: Aug 9 by Lawrence Foard (entr...@world.std.com), to allow user
- *   process control of SCSI devices.
+ *  process control of SCSI devices.
  *  Development Sponsored by Killy Corp. NY NY
  *
  * Original driver (sg.h):
- *   Copyright (C) 1992 Lawrence Foard
+ *   Copyright (C) 1992 Lawrence Foard
  * Version 2 and 3 extensions to driver:
- * Copyright (C) 1998 - 2014 Douglas Gilbert
+ *   Copyright (C) 1998 - 2018 Douglas Gilbert
  *
- *  Version: 3.5.36 (20140603)
- *  This version is for 2.6 and 3 series kernels.
+ *  Version: 3.9.01 (20181016)
+ *  This version is for 2.6, 3 and 4 series kernels.
  *
  * Documentation
  * =
  * A web site for the SG device driver can be found at:
- * http://sg.danny.cz/sg  [alternatively check the MAINTAINERS file]
+ *   http://sg.danny.cz/sg  [alternatively check the MAINTAINERS file]
  * The documentation for the sg version 3 driver can be found at:
- * http://sg.danny.cz/sg/p/sg_v3_ho.html
+ *   http://sg.danny.cz/sg/p/sg_v3_ho.html
  * Also see: /Documentation/scsi/scsi-generic.txt
  *
  * For utility and test programs see: http://sg.danny.cz/sg/sg3_utils.html
@@ -33,242 +33,12 @@
 extern int sg_big_buff; /* for sysctl */
 #endif
 
+#include 
 
-typedef struct sg_iovec /* same structure as used by readv() Linux system */
-{   /* call. It defines one scatter-gather element. */
-void __user *iov_base;  /* Starting address  */
-size_t iov_len; /* Length in bytes  */
-} sg_iovec_t;
-
-
-typedef struct 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 */
-void __user *dxferp;   /* [i], [*io] points to data transfer memory
- or scatter gather list */
-unsigned char __user *cmdp; /* [i], [*i] points to command to perform */
-void __user *sbp;  /* [i], [*o] points to sense_buffer memory */
-unsigned int timeout;   /* [i] MAX_UINT->no timeout (unit: millisec) */
-unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */
-int pack_id;/* [i->o] unused internally (normally) */
-void __user * 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 */
-} sg_io_hdr_t;  /* 64 bytes long (on i386) */
-
-#define SG_INTERFACE_ID_ORIG 'S'
-
-/* Use negative values to flag difference from original sg_header structure */
-#define SG_DXFER_NONE (-1)  /* e.g. a SCSI Test Unit Ready command */
-#define SG_DXFER_TO_DEV (-2)/* e.g. a SCSI WRITE command */
-#define SG_DXFER_FROM_DEV (-3)  /* e.g. a SCSI READ command */
-#define SG_DXFER_TO_FROM_DEV (-4) /* treated like SG_DXFER_FROM_DEV with the
-  additional property than during indirect
-  

Re: [PATCH 3/8] sg: split header, expand and correct descriptions

2018-10-19 Thread Johannes Thumshirn
On 19/10/18 08:24, Douglas Gilbert wrote:
> +/* Alternate style type names, "..._t" variants preferred */
> +typedef struct sg_io_hdr Sg_io_hdr;
> +typedef struct sg_io_vec Sg_io_vec;
> +typedef struct sg_scsi_id Sg_scsi_id;
> +typedef struct sg_req_info Sg_req_info;

There are no _t variants for the above, or am I missing something?


-- 
Johannes ThumshirnSUSE Labs
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


Re: [PATCH 3/8] sg: split header, expand and correct descriptions

2018-10-19 Thread Douglas Gilbert

On 2018-10-19 4:31 a.m., Johannes Thumshirn wrote:

On 19/10/18 08:24, Douglas Gilbert wrote:

+/* Alternate style type names, "..._t" variants preferred */
+typedef struct sg_io_hdr Sg_io_hdr;
+typedef struct sg_io_vec Sg_io_vec;
+typedef struct sg_scsi_id Sg_scsi_id;
+typedef struct sg_req_info Sg_req_info;


There are no _t variants for the above, or am I missing something?


I've expanded the comment to make it clearer I'm referring to the
definitions above in that header ***.

For example: Referring to

typedef struct sg_io_hdr {
... /* the definition of its fields */
} sg_io_hdr_t;


So the suggestion is to prefer sg_io_hdr_t to Sg_io_hdr and if you
are using C rather that C++ (in the user space) and you have very
backward looking conventions then prefer:
   struct sg_io_hdr

Is that clearer?

Doug Gilbert


*** If the unified diff doesn't show that, then that is one of the
many weakness of using unified diffs for code reviews. One
of the things I'm trying to clean up is 15 years of
"laparoscopic" patches (and diff and patch are fighting back).