184314fd4740ad73550c76dee4a9578979d84af48James Smart/* 284314fd4740ad73550c76dee4a9578979d84af48James Smart * SCSI Transport Netlink Interface 384314fd4740ad73550c76dee4a9578979d84af48James Smart * Used for the posting of outbound SCSI transport events 484314fd4740ad73550c76dee4a9578979d84af48James Smart * 584314fd4740ad73550c76dee4a9578979d84af48James Smart * Copyright (C) 2006 James Smart, Emulex Corporation 684314fd4740ad73550c76dee4a9578979d84af48James Smart * 784314fd4740ad73550c76dee4a9578979d84af48James Smart * This program is free software; you can redistribute it and/or modify 884314fd4740ad73550c76dee4a9578979d84af48James Smart * it under the terms of the GNU General Public License as published by 984314fd4740ad73550c76dee4a9578979d84af48James Smart * the Free Software Foundation; either version 2 of the License, or 1084314fd4740ad73550c76dee4a9578979d84af48James Smart * (at your option) any later version. 1184314fd4740ad73550c76dee4a9578979d84af48James Smart * 1284314fd4740ad73550c76dee4a9578979d84af48James Smart * This program is distributed in the hope that it will be useful, 1384314fd4740ad73550c76dee4a9578979d84af48James Smart * but WITHOUT ANY WARRANTY; without even the implied warranty of 1484314fd4740ad73550c76dee4a9578979d84af48James Smart * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1584314fd4740ad73550c76dee4a9578979d84af48James Smart * GNU General Public License for more details. 1684314fd4740ad73550c76dee4a9578979d84af48James Smart * 1784314fd4740ad73550c76dee4a9578979d84af48James Smart * You should have received a copy of the GNU General Public License 1884314fd4740ad73550c76dee4a9578979d84af48James Smart * along with this program; if not, write to the Free Software 1984314fd4740ad73550c76dee4a9578979d84af48James Smart * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2084314fd4740ad73550c76dee4a9578979d84af48James Smart * 2184314fd4740ad73550c76dee4a9578979d84af48James Smart */ 2284314fd4740ad73550c76dee4a9578979d84af48James Smart#ifndef SCSI_NETLINK_H 2384314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NETLINK_H 2484314fd4740ad73550c76dee4a9578979d84af48James Smart 2522447be7d15aefcfab84e9bec4859a28198b0c62James Smart#include <linux/netlink.h> 2610db4e1e4e9a910a26b94045660e5ba7e7c71419Bobby Powers#include <linux/types.h> 2722447be7d15aefcfab84e9bec4859a28198b0c62James Smart 2884314fd4740ad73550c76dee4a9578979d84af48James Smart/* 2984314fd4740ad73550c76dee4a9578979d84af48James Smart * This file intended to be included by both kernel and user space 3084314fd4740ad73550c76dee4a9578979d84af48James Smart */ 3184314fd4740ad73550c76dee4a9578979d84af48James Smart 3284314fd4740ad73550c76dee4a9578979d84af48James Smart/* Single Netlink Message type to send all SCSI Transport messages */ 3384314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_TRANSPORT_MSG NLMSG_MIN_TYPE + 1 3484314fd4740ad73550c76dee4a9578979d84af48James Smart 3584314fd4740ad73550c76dee4a9578979d84af48James Smart/* SCSI Transport Broadcast Groups */ 3684314fd4740ad73550c76dee4a9578979d84af48James Smart /* leaving groups 0 and 1 unassigned */ 3784314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_GRP_FC_EVENTS (1<<2) /* Group 2 */ 3884314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_GRP_CNT 3 3984314fd4740ad73550c76dee4a9578979d84af48James Smart 4084314fd4740ad73550c76dee4a9578979d84af48James Smart 4184314fd4740ad73550c76dee4a9578979d84af48James Smart/* SCSI_TRANSPORT_MSG event message header */ 4284314fd4740ad73550c76dee4a9578979d84af48James Smartstruct scsi_nl_hdr { 4384314fd4740ad73550c76dee4a9578979d84af48James Smart uint8_t version; 4484314fd4740ad73550c76dee4a9578979d84af48James Smart uint8_t transport; 4584314fd4740ad73550c76dee4a9578979d84af48James Smart uint16_t magic; 4684314fd4740ad73550c76dee4a9578979d84af48James Smart uint16_t msgtype; 4784314fd4740ad73550c76dee4a9578979d84af48James Smart uint16_t msglen; 4884314fd4740ad73550c76dee4a9578979d84af48James Smart} __attribute__((aligned(sizeof(uint64_t)))); 4984314fd4740ad73550c76dee4a9578979d84af48James Smart 5084314fd4740ad73550c76dee4a9578979d84af48James Smart/* scsi_nl_hdr->version value */ 5184314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_VERSION 1 5284314fd4740ad73550c76dee4a9578979d84af48James Smart 5384314fd4740ad73550c76dee4a9578979d84af48James Smart/* scsi_nl_hdr->magic value */ 5484314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_MAGIC 0xA1B2 5584314fd4740ad73550c76dee4a9578979d84af48James Smart 5684314fd4740ad73550c76dee4a9578979d84af48James Smart/* scsi_nl_hdr->transport value */ 5784314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_TRANSPORT 0 5884314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_TRANSPORT_FC 1 5984314fd4740ad73550c76dee4a9578979d84af48James Smart#define SCSI_NL_MAX_TRANSPORTS 2 6084314fd4740ad73550c76dee4a9578979d84af48James Smart 6122447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */ 6222447be7d15aefcfab84e9bec4859a28198b0c62James Smart 6322447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* 6422447be7d15aefcfab84e9bec4859a28198b0c62James Smart * GENERIC SCSI scsi_nl_hdr->msgtype Values 6522447be7d15aefcfab84e9bec4859a28198b0c62James Smart */ 6622447be7d15aefcfab84e9bec4859a28198b0c62James Smart /* kernel -> user */ 6722447be7d15aefcfab84e9bec4859a28198b0c62James Smart#define SCSI_NL_SHOST_VENDOR 0x0001 6822447be7d15aefcfab84e9bec4859a28198b0c62James Smart /* user -> kernel */ 6922447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* SCSI_NL_SHOST_VENDOR msgtype is kernel->user and user->kernel */ 7022447be7d15aefcfab84e9bec4859a28198b0c62James Smart 7122447be7d15aefcfab84e9bec4859a28198b0c62James Smart 7222447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* 7322447be7d15aefcfab84e9bec4859a28198b0c62James Smart * Message Structures : 7422447be7d15aefcfab84e9bec4859a28198b0c62James Smart */ 7522447be7d15aefcfab84e9bec4859a28198b0c62James Smart 7622447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* macro to round up message lengths to 8byte boundary */ 7722447be7d15aefcfab84e9bec4859a28198b0c62James Smart#define SCSI_NL_MSGALIGN(len) (((len) + 7) & ~7) 7822447be7d15aefcfab84e9bec4859a28198b0c62James Smart 7922447be7d15aefcfab84e9bec4859a28198b0c62James Smart 8022447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* 8122447be7d15aefcfab84e9bec4859a28198b0c62James Smart * SCSI HOST Vendor Unique messages : 8222447be7d15aefcfab84e9bec4859a28198b0c62James Smart * SCSI_NL_SHOST_VENDOR 8322447be7d15aefcfab84e9bec4859a28198b0c62James Smart * 8422447be7d15aefcfab84e9bec4859a28198b0c62James Smart * Note: The Vendor Unique message payload will begin directly after 8522447be7d15aefcfab84e9bec4859a28198b0c62James Smart * this structure, with the length of the payload per vmsg_datalen. 8622447be7d15aefcfab84e9bec4859a28198b0c62James Smart * 8722447be7d15aefcfab84e9bec4859a28198b0c62James Smart * Note: When specifying vendor_id, be sure to read the Vendor Type and ID 8822447be7d15aefcfab84e9bec4859a28198b0c62James Smart * formatting requirements specified below 8922447be7d15aefcfab84e9bec4859a28198b0c62James Smart */ 9022447be7d15aefcfab84e9bec4859a28198b0c62James Smartstruct scsi_nl_host_vendor_msg { 9122447be7d15aefcfab84e9bec4859a28198b0c62James Smart struct scsi_nl_hdr snlh; /* must be 1st element ! */ 9222447be7d15aefcfab84e9bec4859a28198b0c62James Smart uint64_t vendor_id; 9322447be7d15aefcfab84e9bec4859a28198b0c62James Smart uint16_t host_no; 9422447be7d15aefcfab84e9bec4859a28198b0c62James Smart uint16_t vmsg_datalen; 9522447be7d15aefcfab84e9bec4859a28198b0c62James Smart} __attribute__((aligned(sizeof(uint64_t)))); 9684314fd4740ad73550c76dee4a9578979d84af48James Smart 9784314fd4740ad73550c76dee4a9578979d84af48James Smart 9884314fd4740ad73550c76dee4a9578979d84af48James Smart/* 9984314fd4740ad73550c76dee4a9578979d84af48James Smart * Vendor ID: 10084314fd4740ad73550c76dee4a9578979d84af48James Smart * If transports post vendor-unique events, they must pass a well-known 10184314fd4740ad73550c76dee4a9578979d84af48James Smart * 32-bit vendor identifier. This identifier consists of 8 bits indicating 10284314fd4740ad73550c76dee4a9578979d84af48James Smart * the "type" of identifier contained, and 24 bits of id data. 10384314fd4740ad73550c76dee4a9578979d84af48James Smart * 10484314fd4740ad73550c76dee4a9578979d84af48James Smart * Identifiers for each type: 10584314fd4740ad73550c76dee4a9578979d84af48James Smart * PCI : ID data is the 16 bit PCI Registered Vendor ID 10684314fd4740ad73550c76dee4a9578979d84af48James Smart */ 107f14e2e29cdd07f80de6dec168dc2bb39de37eec3James Smart#define SCSI_NL_VID_TYPE_SHIFT 56 108083c8c1e60e5c27a277e87dbeb6b89b47937559fPeter Korsgaard#define SCSI_NL_VID_TYPE_MASK ((__u64)0xFF << SCSI_NL_VID_TYPE_SHIFT) 109083c8c1e60e5c27a277e87dbeb6b89b47937559fPeter Korsgaard#define SCSI_NL_VID_TYPE_PCI ((__u64)0x01 << SCSI_NL_VID_TYPE_SHIFT) 110f14e2e29cdd07f80de6dec168dc2bb39de37eec3James Smart#define SCSI_NL_VID_ID_MASK (~ SCSI_NL_VID_TYPE_MASK) 11184314fd4740ad73550c76dee4a9578979d84af48James Smart 11284314fd4740ad73550c76dee4a9578979d84af48James Smart 11384314fd4740ad73550c76dee4a9578979d84af48James Smart#define INIT_SCSI_NL_HDR(hdr, t, mtype, mlen) \ 11484314fd4740ad73550c76dee4a9578979d84af48James Smart { \ 11584314fd4740ad73550c76dee4a9578979d84af48James Smart (hdr)->version = SCSI_NL_VERSION; \ 11684314fd4740ad73550c76dee4a9578979d84af48James Smart (hdr)->transport = t; \ 11784314fd4740ad73550c76dee4a9578979d84af48James Smart (hdr)->magic = SCSI_NL_MAGIC; \ 11884314fd4740ad73550c76dee4a9578979d84af48James Smart (hdr)->msgtype = mtype; \ 11984314fd4740ad73550c76dee4a9578979d84af48James Smart (hdr)->msglen = mlen; \ 12084314fd4740ad73550c76dee4a9578979d84af48James Smart } 12184314fd4740ad73550c76dee4a9578979d84af48James Smart 12284314fd4740ad73550c76dee4a9578979d84af48James Smart 12322447be7d15aefcfab84e9bec4859a28198b0c62James Smart#ifdef __KERNEL__ 12422447be7d15aefcfab84e9bec4859a28198b0c62James Smart 12522447be7d15aefcfab84e9bec4859a28198b0c62James Smart#include <scsi/scsi_host.h> 12622447be7d15aefcfab84e9bec4859a28198b0c62James Smart 12722447be7d15aefcfab84e9bec4859a28198b0c62James Smart/* Exported Kernel Interfaces */ 12822447be7d15aefcfab84e9bec4859a28198b0c62James Smartint scsi_nl_add_transport(u8 tport, 12922447be7d15aefcfab84e9bec4859a28198b0c62James Smart int (*msg_handler)(struct sk_buff *), 13022447be7d15aefcfab84e9bec4859a28198b0c62James Smart void (*event_handler)(struct notifier_block *, unsigned long, void *)); 13122447be7d15aefcfab84e9bec4859a28198b0c62James Smartvoid scsi_nl_remove_transport(u8 tport); 13222447be7d15aefcfab84e9bec4859a28198b0c62James Smart 13322447be7d15aefcfab84e9bec4859a28198b0c62James Smartint scsi_nl_add_driver(u64 vendor_id, struct scsi_host_template *hostt, 13422447be7d15aefcfab84e9bec4859a28198b0c62James Smart int (*nlmsg_handler)(struct Scsi_Host *shost, void *payload, 13522447be7d15aefcfab84e9bec4859a28198b0c62James Smart u32 len, u32 pid), 13622447be7d15aefcfab84e9bec4859a28198b0c62James Smart void (*nlevt_handler)(struct notifier_block *nb, 13722447be7d15aefcfab84e9bec4859a28198b0c62James Smart unsigned long event, void *notify_ptr)); 13822447be7d15aefcfab84e9bec4859a28198b0c62James Smartvoid scsi_nl_remove_driver(u64 vendor_id); 13922447be7d15aefcfab84e9bec4859a28198b0c62James Smart 14022447be7d15aefcfab84e9bec4859a28198b0c62James Smartvoid scsi_nl_send_transport_msg(u32 pid, struct scsi_nl_hdr *hdr); 14122447be7d15aefcfab84e9bec4859a28198b0c62James Smartint scsi_nl_send_vendor_msg(u32 pid, unsigned short host_no, u64 vendor_id, 14222447be7d15aefcfab84e9bec4859a28198b0c62James Smart char *data_buf, u32 data_len); 14322447be7d15aefcfab84e9bec4859a28198b0c62James Smart 14422447be7d15aefcfab84e9bec4859a28198b0c62James Smart#endif /* __KERNEL__ */ 14522447be7d15aefcfab84e9bec4859a28198b0c62James Smart 14684314fd4740ad73550c76dee4a9578979d84af48James Smart#endif /* SCSI_NETLINK_H */ 14784314fd4740ad73550c76dee4a9578979d84af48James Smart 148