Merge tag 'drm-misc-fixes-2018-02-21' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / include / uapi / scsi / scsi_netlink.h
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 /*
3  *  SCSI Transport Netlink Interface
4  *    Used for the posting of outbound SCSI transport events
5  *
6  *  Copyright (C) 2006   James Smart, Emulex Corporation
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23 #ifndef SCSI_NETLINK_H
24 #define SCSI_NETLINK_H
25
26 #include <linux/netlink.h>
27 #include <linux/types.h>
28
29 /*
30  * This file intended to be included by both kernel and user space
31  */
32
33 /* Single Netlink Message type to send all SCSI Transport messages */
34 #define SCSI_TRANSPORT_MSG              NLMSG_MIN_TYPE + 1
35
36 /* SCSI Transport Broadcast Groups */
37         /* leaving groups 0 and 1 unassigned */
38 #define SCSI_NL_GRP_FC_EVENTS           (1<<2)          /* Group 2 */
39 #define SCSI_NL_GRP_CNT                 3
40
41
42 /* SCSI_TRANSPORT_MSG event message header */
43 struct scsi_nl_hdr {
44         uint8_t version;
45         uint8_t transport;
46         uint16_t magic;
47         uint16_t msgtype;
48         uint16_t msglen;
49 } __attribute__((aligned(sizeof(uint64_t))));
50
51 /* scsi_nl_hdr->version value */
52 #define SCSI_NL_VERSION                         1
53
54 /* scsi_nl_hdr->magic value */
55 #define SCSI_NL_MAGIC                           0xA1B2
56
57 /* scsi_nl_hdr->transport value */
58 #define SCSI_NL_TRANSPORT                       0
59 #define SCSI_NL_TRANSPORT_FC                    1
60 #define SCSI_NL_MAX_TRANSPORTS                  2
61
62 /* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */
63
64 /*
65  * GENERIC SCSI scsi_nl_hdr->msgtype Values
66  */
67         /* kernel -> user */
68 #define SCSI_NL_SHOST_VENDOR                    0x0001
69         /* user -> kernel */
70 /* SCSI_NL_SHOST_VENDOR msgtype is kernel->user and user->kernel */
71
72
73 /*
74  * Message Structures :
75  */
76
77 /* macro to round up message lengths to 8byte boundary */
78 #define SCSI_NL_MSGALIGN(len)           (((len) + 7) & ~7)
79
80
81 /*
82  * SCSI HOST Vendor Unique messages :
83  *   SCSI_NL_SHOST_VENDOR
84  *
85  * Note: The Vendor Unique message payload will begin directly after
86  *       this structure, with the length of the payload per vmsg_datalen.
87  *
88  * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
89  *   formatting requirements specified below
90  */
91 struct scsi_nl_host_vendor_msg {
92         struct scsi_nl_hdr snlh;                /* must be 1st element ! */
93         uint64_t vendor_id;
94         uint16_t host_no;
95         uint16_t vmsg_datalen;
96 } __attribute__((aligned(sizeof(uint64_t))));
97
98
99 /*
100  * Vendor ID:
101  *   If transports post vendor-unique events, they must pass a well-known
102  *   32-bit vendor identifier. This identifier consists of 8 bits indicating
103  *   the "type" of identifier contained, and 24 bits of id data.
104  *
105  *   Identifiers for each type:
106  *    PCI :  ID data is the 16 bit PCI Registered Vendor ID
107  */
108 #define SCSI_NL_VID_TYPE_SHIFT          56
109 #define SCSI_NL_VID_TYPE_MASK           ((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT)
110 #define SCSI_NL_VID_TYPE_PCI            ((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT)
111 #define SCSI_NL_VID_ID_MASK             (~ SCSI_NL_VID_TYPE_MASK)
112
113
114 #define INIT_SCSI_NL_HDR(hdr, t, mtype, mlen)                   \
115         {                                                       \
116         (hdr)->version = SCSI_NL_VERSION;                       \
117         (hdr)->transport = t;                                   \
118         (hdr)->magic = SCSI_NL_MAGIC;                           \
119         (hdr)->msgtype = mtype;                                 \
120         (hdr)->msglen = mlen;                                   \
121         }
122
123 #endif /* SCSI_NETLINK_H */
124