scsi_netlink.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  17. /*
  18. * SCSI Transport Netlink Interface
  19. * Used for the posting of outbound SCSI transport events
  20. *
  21. * Copyright (C) 2006 James Smart, Emulex Corporation
  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. __u8 version;
  39. __u8 transport;
  40. __u16 magic;
  41. __u16 msgtype;
  42. __u16 msglen;
  43. } __attribute__((aligned(sizeof(__u64))));
  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. __u64 vendor_id;
  78. __u16 host_no;
  79. __u16 vmsg_datalen;
  80. } __attribute__((aligned(sizeof(__u64))));
  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 */