scsi_netlink.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <linux/netlink.h>
  26. #include <linux/types.h>
  27. /*
  28. * This file intended to be included by both kernel and user space
  29. */
  30. /* Single Netlink Message type to send all SCSI Transport messages */
  31. #define SCSI_TRANSPORT_MSG NLMSG_MIN_TYPE + 1
  32. /* SCSI Transport Broadcast Groups */
  33. /* leaving groups 0 and 1 unassigned */
  34. #define SCSI_NL_GRP_FC_EVENTS (1<<2) /* Group 2 */
  35. #define SCSI_NL_GRP_CNT 3
  36. /* SCSI_TRANSPORT_MSG event message header */
  37. struct scsi_nl_hdr {
  38. uint8_t version;
  39. uint8_t transport;
  40. uint16_t magic;
  41. uint16_t msgtype;
  42. uint16_t msglen;
  43. } __attribute__((aligned(sizeof(uint64_t))));
  44. /* scsi_nl_hdr->version value */
  45. #define SCSI_NL_VERSION 1
  46. /* scsi_nl_hdr->magic value */
  47. #define SCSI_NL_MAGIC 0xA1B2
  48. /* scsi_nl_hdr->transport value */
  49. #define SCSI_NL_TRANSPORT 0
  50. #define SCSI_NL_TRANSPORT_FC 1
  51. #define SCSI_NL_MAX_TRANSPORTS 2
  52. /* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */
  53. /*
  54. * GENERIC SCSI scsi_nl_hdr->msgtype Values
  55. */
  56. /* kernel -> user */
  57. #define SCSI_NL_SHOST_VENDOR 0x0001
  58. /* user -> kernel */
  59. /* SCSI_NL_SHOST_VENDOR msgtype is kernel->user and user->kernel */
  60. /*
  61. * Message Structures :
  62. */
  63. /* macro to round up message lengths to 8byte boundary */
  64. #define SCSI_NL_MSGALIGN(len) (((len) + 7) & ~7)
  65. /*
  66. * SCSI HOST Vendor Unique messages :
  67. * SCSI_NL_SHOST_VENDOR
  68. *
  69. * Note: The Vendor Unique message payload will begin directly after
  70. * this structure, with the length of the payload per vmsg_datalen.
  71. *
  72. * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
  73. * formatting requirements specified below
  74. */
  75. struct scsi_nl_host_vendor_msg {
  76. struct scsi_nl_hdr snlh; /* must be 1st element ! */
  77. uint64_t vendor_id;
  78. uint16_t host_no;
  79. uint16_t vmsg_datalen;
  80. } __attribute__((aligned(sizeof(uint64_t))));
  81. /*
  82. * Vendor ID:
  83. * If transports post vendor-unique events, they must pass a well-known
  84. * 32-bit vendor identifier. This identifier consists of 8 bits indicating
  85. * the "type" of identifier contained, and 24 bits of id data.
  86. *
  87. * Identifiers for each type:
  88. * PCI : ID data is the 16 bit PCI Registered Vendor ID
  89. */
  90. #define SCSI_NL_VID_TYPE_SHIFT 56
  91. #define SCSI_NL_VID_TYPE_MASK ((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT)
  92. #define SCSI_NL_VID_TYPE_PCI ((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT)
  93. #define SCSI_NL_VID_ID_MASK (~ SCSI_NL_VID_TYPE_MASK)
  94. #define INIT_SCSI_NL_HDR(hdr, t, mtype, mlen) \
  95. { \
  96. (hdr)->version = SCSI_NL_VERSION; \
  97. (hdr)->transport = t; \
  98. (hdr)->magic = SCSI_NL_MAGIC; \
  99. (hdr)->msgtype = mtype; \
  100. (hdr)->msglen = mlen; \
  101. }
  102. #endif /* SCSI_NETLINK_H */