/*1* SCSI Transport Netlink Interface2* Used for the posting of outbound SCSI transport events3*4* Copyright (C) 2006 James Smart, Emulex Corporation5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*20*/21#ifndef SCSI_NETLINK_H22#define SCSI_NETLINK_H2324#include <linux/netlink.h>252627/*28* This file intended to be included by both kernel and user space29*/3031/* Single Netlink Message type to send all SCSI Transport messages */32#define SCSI_TRANSPORT_MSG NLMSG_MIN_TYPE + 13334/* SCSI Transport Broadcast Groups */35/* leaving groups 0 and 1 unassigned */36#define SCSI_NL_GRP_FC_EVENTS (1<<2) /* Group 2 */37#define SCSI_NL_GRP_CNT 3383940/* SCSI_TRANSPORT_MSG event message header */41struct scsi_nl_hdr {42uint8_t version;43uint8_t transport;44uint16_t magic;45uint16_t msgtype;46uint16_t msglen;47} __attribute__((aligned(sizeof(uint64_t))));4849/* scsi_nl_hdr->version value */50#define SCSI_NL_VERSION 15152/* scsi_nl_hdr->magic value */53#define SCSI_NL_MAGIC 0xA1B25455/* scsi_nl_hdr->transport value */56#define SCSI_NL_TRANSPORT 057#define SCSI_NL_TRANSPORT_FC 158#define SCSI_NL_MAX_TRANSPORTS 25960/* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */6162/*63* GENERIC SCSI scsi_nl_hdr->msgtype Values64*/65/* kernel -> user */66#define SCSI_NL_SHOST_VENDOR 0x000167/* user -> kernel */68/* SCSI_NL_SHOST_VENDOR msgtype is kernel->user and user->kernel */697071/*72* Message Structures :73*/7475/* macro to round up message lengths to 8byte boundary */76#define SCSI_NL_MSGALIGN(len) (((len) + 7) & ~7)777879/*80* SCSI HOST Vendor Unique messages :81* SCSI_NL_SHOST_VENDOR82*83* Note: The Vendor Unique message payload will begin directly after84* this structure, with the length of the payload per vmsg_datalen.85*86* Note: When specifying vendor_id, be sure to read the Vendor Type and ID87* formatting requirements specified below88*/89struct scsi_nl_host_vendor_msg {90struct scsi_nl_hdr snlh; /* must be 1st element ! */91uint64_t vendor_id;92uint16_t host_no;93uint16_t vmsg_datalen;94} __attribute__((aligned(sizeof(uint64_t))));959697/*98* Vendor ID:99* If transports post vendor-unique events, they must pass a well-known100* 32-bit vendor identifier. This identifier consists of 8 bits indicating101* the "type" of identifier contained, and 24 bits of id data.102*103* Identifiers for each type:104* PCI : ID data is the 16 bit PCI Registered Vendor ID105*/106#define SCSI_NL_VID_TYPE_SHIFT 56107#define SCSI_NL_VID_TYPE_MASK ((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT)108#define SCSI_NL_VID_TYPE_PCI ((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT)109#define SCSI_NL_VID_ID_MASK (~ SCSI_NL_VID_TYPE_MASK)110111112#define INIT_SCSI_NL_HDR(hdr, t, mtype, mlen) \113{ \114(hdr)->version = SCSI_NL_VERSION; \115(hdr)->transport = t; \116(hdr)->magic = SCSI_NL_MAGIC; \117(hdr)->msgtype = mtype; \118(hdr)->msglen = mlen; \119}120121122#ifdef __KERNEL__123124#include <scsi/scsi_host.h>125126/* Exported Kernel Interfaces */127int scsi_nl_add_transport(u8 tport,128int (*msg_handler)(struct sk_buff *),129void (*event_handler)(struct notifier_block *, unsigned long, void *));130void scsi_nl_remove_transport(u8 tport);131132int scsi_nl_add_driver(u64 vendor_id, struct scsi_host_template *hostt,133int (*nlmsg_handler)(struct Scsi_Host *shost, void *payload,134u32 len, u32 pid),135void (*nlevt_handler)(struct notifier_block *nb,136unsigned long event, void *notify_ptr));137void scsi_nl_remove_driver(u64 vendor_id);138139void scsi_nl_send_transport_msg(u32 pid, struct scsi_nl_hdr *hdr);140int scsi_nl_send_vendor_msg(u32 pid, unsigned short host_no, u64 vendor_id,141char *data_buf, u32 data_len);142143#endif /* __KERNEL__ */144145#endif /* SCSI_NETLINK_H */146147148149