130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  SCSI Transport Netlink Interface
330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *    Used for the posting of outbound SCSI transport events
430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  Copyright (C) 2006   James Smart, Emulex Corporation
630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  This program is free software; you can redistribute it and/or modify
830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  it under the terms of the GNU General Public License as published by
930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  the Free Software Foundation; either version 2 of the License, or
1030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  (at your option) any later version.
1130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
1230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  This program is distributed in the hope that it will be useful,
1330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  GNU General Public License for more details.
1630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
1730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  You should have received a copy of the GNU General Public License
1830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  along with this program; if not, write to the Free Software
1930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
2130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
2230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#ifndef SCSI_NETLINK_H
2330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NETLINK_H
2430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
2530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/netlink.h>
2630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/types.h>
2730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
2830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
2930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * This file intended to be included by both kernel and user space
3030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
3130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Single Netlink Message type to send all SCSI Transport messages */
3330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_TRANSPORT_MSG		NLMSG_MIN_TYPE + 1
3430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* SCSI Transport Broadcast Groups */
3630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	/* leaving groups 0 and 1 unassigned */
3730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_GRP_FC_EVENTS		(1<<2)		/* Group 2 */
3830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_GRP_CNT			3
3930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* SCSI_TRANSPORT_MSG event message header */
4230692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct scsi_nl_hdr {
4330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint8_t version;
4430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint8_t transport;
4530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint16_t magic;
4630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint16_t msgtype;
4730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint16_t msglen;
4830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} __attribute__((aligned(sizeof(uint64_t))));
4930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* scsi_nl_hdr->version value */
5130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_VERSION				1
5230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* scsi_nl_hdr->magic value */
5430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_MAGIC				0xA1B2
5530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
5630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* scsi_nl_hdr->transport value */
5730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_TRANSPORT			0
5830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_TRANSPORT_FC			1
5930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_MAX_TRANSPORTS			2
6030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
6130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */
6230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
6330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
6430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * GENERIC SCSI scsi_nl_hdr->msgtype Values
6530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
6630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	/* kernel -> user */
6730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_SHOST_VENDOR			0x0001
6830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	/* user -> kernel */
6930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* SCSI_NL_SHOST_VENDOR msgtype is kernel->user and user->kernel */
7030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
7130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
7230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
7330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Message Structures :
7430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
7530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
7630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* macro to round up message lengths to 8byte boundary */
7730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_MSGALIGN(len)		(((len) + 7) & ~7)
7830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
7930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
8030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
8130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * SCSI HOST Vendor Unique messages :
8230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   SCSI_NL_SHOST_VENDOR
8330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
8430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Note: The Vendor Unique message payload will begin directly after
8530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * 	 this structure, with the length of the payload per vmsg_datalen.
8630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
8730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Note: When specifying vendor_id, be sure to read the Vendor Type and ID
8830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   formatting requirements specified below
8930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
9030692c65c4174412c90e79489e98ab85c1a7412fBen Chengstruct scsi_nl_host_vendor_msg {
9130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	struct scsi_nl_hdr snlh;		/* must be 1st element ! */
9230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint64_t vendor_id;
9330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint16_t host_no;
9430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	uint16_t vmsg_datalen;
9530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} __attribute__((aligned(sizeof(uint64_t))));
9630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
9730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
9830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
9930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Vendor ID:
10030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   If transports post vendor-unique events, they must pass a well-known
10130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   32-bit vendor identifier. This identifier consists of 8 bits indicating
10230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   the "type" of identifier contained, and 24 bits of id data.
10330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
10430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   Identifiers for each type:
10530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *    PCI :  ID data is the 16 bit PCI Registered Vendor ID
10630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
10730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_VID_TYPE_SHIFT		56
10830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_VID_TYPE_MASK		((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT)
10930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_VID_TYPE_PCI		((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT)
11030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SCSI_NL_VID_ID_MASK		(~ SCSI_NL_VID_TYPE_MASK)
11130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
11230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
11330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define INIT_SCSI_NL_HDR(hdr, t, mtype, mlen)			\
11430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	{							\
11530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	(hdr)->version = SCSI_NL_VERSION;			\
11630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	(hdr)->transport = t;					\
11730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	(hdr)->magic = SCSI_NL_MAGIC;				\
11830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	(hdr)->msgtype = mtype;					\
11930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	(hdr)->msglen = mlen;					\
12030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng	}
12130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
12230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#endif /* SCSI_NETLINK_H */
12330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
124