scsi_netlink.h 4.3 KB

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