19ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FiberChannel transport specific attributes exported to sysfs. 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License as published by 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (at your option) any later version. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is distributed in the hope that it will be useful, 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License for more details. 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * along with this program; if not, write to the Free Software 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ======== 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 22a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Copyright (C) 2004-2007 James Smart, Emulex Corporation 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Rewrite for host, target, device, and remote port attributes, 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * statistics, and service functions... 259ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart * Add vports, etc 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 305a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h> 3165d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt#include <linux/delay.h> 32ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko#include <linux/kernel.h> 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_device.h> 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_host.h> 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_transport.h> 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_transport_fc.h> 37c829c394165f981d49f05a9be228404d7a9398d4James Smart#include <scsi/scsi_cmnd.h> 3884314fd4740ad73550c76dee4a9578979d84af48James Smart#include <net/netlink.h> 3984314fd4740ad73550c76dee4a9578979d84af48James Smart#include <scsi/scsi_netlink_fc.h> 409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart#include <scsi/scsi_bsg_fc.h> 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "scsi_priv.h" 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 43aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int fc_queue_work(struct Scsi_Host *, struct work_struct *); 449ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smartstatic void fc_vport_sched_delete(struct work_struct *work); 45a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquezstatic int fc_vport_setup(struct Scsi_Host *shost, int channel, 46a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct device *pdev, struct fc_vport_identifiers *ids, 47a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport **vport); 489e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int fc_bsg_hostadd(struct Scsi_Host *, struct fc_host_attrs *); 499e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int fc_bsg_rportadd(struct Scsi_Host *, struct fc_rport *); 509e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void fc_bsg_remove(struct request_queue *); 519e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void fc_bsg_goose_queue(struct fc_rport *); 52a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 53a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 5443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie * Module Parameters 5543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie */ 5643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 5743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie/* 5843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie * dev_loss_tmo: the default number of seconds that the FC transport 5943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie * should insulate the loss of a remote port. 6043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT. 6143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie */ 6243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic unsigned int fc_dev_loss_tmo = 60; /* seconds */ 6343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 6443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiemodule_param_named(dev_loss_tmo, fc_dev_loss_tmo, uint, S_IRUGO|S_IWUSR); 6543ca910a9c90566308f39f51ac03a55f94a5f83cMike ChristieMODULE_PARM_DESC(dev_loss_tmo, 6643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie "Maximum number of seconds that the FC transport should" 6743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie " insulate the loss of a remote port. Once this value is" 6843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie " exceeded, the scsi target is removed. Value should be" 6943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT if" 7043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie " fast_io_fail_tmo is not set."); 7143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 7243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie/* 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redefine so that we can have same named attributes in the 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * sdev/starget/host objects. 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 76ee959b00c335d7780136c5abda37809191fe52c3Tony Jones#define FC_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \ 77ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstruct device_attribute device_attr_##_prefix##_##_name = \ 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ATTR(_name,_mode,_show,_store) 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_enum_name_search(title, table_type, table) \ 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const char *get_fc_##title##_name(enum table_type table_key) \ 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name = NULL; \ 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 866391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (table[i].value == table_key) { \ 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = table[i].name; \ 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return name; \ 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_enum_name_match(title, table_type, table) \ 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int get_fc_##title##_match(const char *table_key, \ 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum table_type *value) \ 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 1016391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (strncmp(table_key, table[i].name, \ 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds table[i].matchlen) == 0) { \ 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *value = table[i].value; \ 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; /* success */ \ 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 1; /* failure */ \ 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_port_type values to ascii string name */ 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct { 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_port_type value; 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_type_names[] = { 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_UNKNOWN, "Unknown" }, 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_OTHER, "Other" }, 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NOTPRESENT, "Not Present" }, 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" }, 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" }, 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_LPORT, "LPort (private loop)" }, 123951948a397e3ddc96658efd648b9d66622965b19Christof Schmitt { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection)" }, 124a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_PORTTYPE_NPIV, "NPIV VPORT" }, 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(port_type, fc_port_type, fc_port_type_names) 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_PORTTYPE_MAX_NAMELEN 50 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 129a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Reuse fc_port_type enum function for vport_type */ 130a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define get_fc_vport_type_name get_fc_port_type_name 131a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13384314fd4740ad73550c76dee4a9578979d84af48James Smart/* Convert fc_host_event_code values to ascii string name */ 13484314fd4740ad73550c76dee4a9578979d84af48James Smartstatic const struct { 13584314fd4740ad73550c76dee4a9578979d84af48James Smart enum fc_host_event_code value; 13684314fd4740ad73550c76dee4a9578979d84af48James Smart char *name; 13784314fd4740ad73550c76dee4a9578979d84af48James Smart} fc_host_event_code_names[] = { 13884314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LIP, "lip" }, 13984314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINKUP, "link_up" }, 14084314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINKDOWN, "link_down" }, 14184314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LIPRESET, "lip_reset" }, 14284314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_RSCN, "rscn" }, 14384314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" }, 14484314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_UNKNOWN, "port_unknown" }, 14584314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_ONLINE, "port_online" }, 14684314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_OFFLINE, "port_offline" }, 14784314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_FABRIC, "port_fabric" }, 14884314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINK_UNKNOWN, "link_unknown" }, 14984314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" }, 15084314fd4740ad73550c76dee4a9578979d84af48James Smart}; 15184314fd4740ad73550c76dee4a9578979d84af48James Smartfc_enum_name_search(host_event_code, fc_host_event_code, 15284314fd4740ad73550c76dee4a9578979d84af48James Smart fc_host_event_code_names) 15384314fd4740ad73550c76dee4a9578979d84af48James Smart#define FC_HOST_EVENT_CODE_MAX_NAMELEN 30 15484314fd4740ad73550c76dee4a9578979d84af48James Smart 15584314fd4740ad73550c76dee4a9578979d84af48James Smart 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_port_state values to ascii string name */ 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct { 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_port_state value; 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_state_names[] = { 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_UNKNOWN, "Unknown" }, 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_NOTPRESENT, "Not Present" }, 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_ONLINE, "Online" }, 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_OFFLINE, "Offline" }, 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_BLOCKED, "Blocked" }, 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_BYPASSED, "Bypassed" }, 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" }, 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_LINKDOWN, "Linkdown" }, 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_ERROR, "Error" }, 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_LOOPBACK, "Loopback" }, 17142e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com { FC_PORTSTATE_DELETED, "Deleted" }, 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(port_state, fc_port_state, fc_port_state_names) 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_PORTSTATE_MAX_NAMELEN 20 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 177a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Convert fc_vport_state values to ascii string name */ 178a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic struct { 179a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart enum fc_vport_state value; 180a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart char *name; 181a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} fc_vport_state_names[] = { 182a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_UNKNOWN, "Unknown" }, 183a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_ACTIVE, "Active" }, 184a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_DISABLED, "Disabled" }, 185a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_LINKDOWN, "Linkdown" }, 186a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_INITIALIZING, "Initializing" }, 187a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_NO_FABRIC_SUPP, "No Fabric Support" }, 188a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_NO_FABRIC_RSCS, "No Fabric Resources" }, 189a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_FABRIC_LOGOUT, "Fabric Logout" }, 190a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_FABRIC_REJ_WWN, "Fabric Rejected WWN" }, 191a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_VPORT_FAILED, "VPort Failed" }, 192a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart}; 193a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names) 194a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define FC_VPORTSTATE_MAX_NAMELEN 24 195a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 196a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Reuse fc_vport_state enum function for vport_last_state */ 197a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define get_fc_vport_last_state_name get_fc_vport_state_name 198a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 199a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_tgtid_binding_type values to ascii string name */ 2010ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_tgtid_binding_type value; 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int matchlen; 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_tgtid_binding_type_names[] = { 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_NONE, "none", 4 }, 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 }, 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 }, 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 }, 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type, 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_tgtid_binding_type_names) 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type, 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_tgtid_binding_type_names) 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_BINDTYPE_MAX_NAMELEN 30 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_bitfield_name_search(title, table) \ 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsget_fc_##title##_names(u32 table_key, char *buf) \ 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *prefix = ""; \ 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ssize_t len = 0; \ 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2266391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (table[i].value & table_key) { \ 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "%s%s", \ 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prefix, table[i].name); \ 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prefix = ", "; \ 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "\n"); \ 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return len; \ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert FC_COS bit values to ascii string name */ 2390ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_cos_names[] = { 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS1, "Class 1" }, 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS2, "Class 2" }, 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS3, "Class 3" }, 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS4, "Class 4" }, 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS6, "Class 6" }, 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_bitfield_name_search(cos, fc_cos_names) 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert FC_PORTSPEED bit values to ascii string name */ 2530ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_speed_names[] = { 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_1GBIT, "1 Gbit" }, 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_2GBIT, "2 Gbit" }, 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_4GBIT, "4 Gbit" }, 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_10GBIT, "10 Gbit" }, 261c3d2350a8420dbf9d48f5f8a0fb72117bfcbc1b0James Smart { FC_PORTSPEED_8GBIT, "8 Gbit" }, 262c3d2350a8420dbf9d48f5f8a0fb72117bfcbc1b0James Smart { FC_PORTSPEED_16GBIT, "16 Gbit" }, 263624f28be81097d06796e12c4c10aa7611305b334Chad Dupuis { FC_PORTSPEED_32GBIT, "32 Gbit" }, 264c21a2c1a4973c8dde32557970fdb44eaa9489aebDick Kennedy { FC_PORTSPEED_20GBIT, "20 Gbit" }, 265c21a2c1a4973c8dde32557970fdb44eaa9489aebDick Kennedy { FC_PORTSPEED_40GBIT, "40 Gbit" }, 266c21a2c1a4973c8dde32557970fdb44eaa9489aebDick Kennedy { FC_PORTSPEED_50GBIT, "50 Gbit" }, 267c21a2c1a4973c8dde32557970fdb44eaa9489aebDick Kennedy { FC_PORTSPEED_100GBIT, "100 Gbit" }, 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" }, 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_bitfield_name_search(port_speed, fc_port_speed_names) 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_fc4s (char *buf, u8 *fc4_list) 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i, len=0; 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++) 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len , "0x%02x ", *fc4_list); 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "\n"); 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return len; 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 285a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Convert FC_PORT_ROLE bit values to ascii string name */ 2860ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 289a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} fc_port_role_names[] = { 290a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_PORT_ROLE_FCP_TARGET, "FCP Target" }, 291a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_PORT_ROLE_FCP_INITIATOR, "FCP Initiator" }, 292a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart { FC_PORT_ROLE_IP_PORT, "IP Port" }, 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 294a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_bitfield_name_search(port_roles, fc_port_role_names) 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Define roles that are specific to port_id. Values are relative to ROLE_MASK. 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_WELLKNOWN_PORTID_MASK 0xfffff0 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_WELLKNOWN_ROLE_MASK 0x00000f 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_FPORT_PORTID 0x00000e 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_FABCTLR_PORTID 0x00000d 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_DIRSRVR_PORTID 0x00000c 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_TIMESRVR_PORTID 0x00000b 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_MGMTSRVR_PORTID 0x00000a 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 308c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsstatic void fc_timeout_deleted_rport(struct work_struct *work); 309c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsstatic void fc_timeout_fail_rport_io(struct work_struct *work); 310c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsstatic void fc_scsi_scan_rport(struct work_struct *work); 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Attribute counts pre object type... 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Increase these values if you add attributes 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_STARGET_NUM_ATTRS 3 3170f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart#define FC_RPORT_NUM_ATTRS 10 318a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define FC_VPORT_NUM_ATTRS 9 319bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh#define FC_HOST_NUM_ATTRS 29 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct fc_internal { 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct scsi_transport_template t; 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_function_template *f; 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For attributes : each object has : 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * An array of the actual attributes structures 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * An array of null-terminated pointers to the attribute 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * structures - used for mid-layer interaction. 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The attribute containers for the starget and host are are 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * part of the midlayer. As the remote port is specific to the 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc transport, we must provide the attribute container. 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 335ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute private_starget_attrs[ 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FC_STARGET_NUM_ATTRS]; 337ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1]; 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 339ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute private_host_attrs[FC_HOST_NUM_ATTRS]; 340ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1]; 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct transport_container rport_attr_cont; 343ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS]; 344ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1]; 345a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 346a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct transport_container vport_attr_cont; 347ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute private_vport_attrs[FC_VPORT_NUM_ATTRS]; 348ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *vport_attrs[FC_VPORT_NUM_ATTRS + 1]; 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 353d0a7e574007fd547d72ec693bfa35778623d0738James Bottomleystatic int fc_target_setup(struct transport_container *tc, struct device *dev, 354ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device *cdev) 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct scsi_target *starget = to_scsi_target(dev); 3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = starget_to_rport(starget); 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * if parent is remote port, use values from remote port. 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Otherwise, this host uses the fc_transport, but not the 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * remote port interface. As such, initialize to known non-values. 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport) { 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_node_name(starget) = rport->node_name; 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_name(starget) = rport->port_name; 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_id(starget) = rport->port_id; 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_node_name(starget) = -1; 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_name(starget) = -1; 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_id(starget) = -1; 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_transport_class, 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_transport", 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_target_setup, 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 383d0a7e574007fd547d72ec693bfa35778623d0738James Bottomleystatic int fc_host_setup(struct transport_container *tc, struct device *dev, 384ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device *cdev) 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = dev_to_shost(dev); 387aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3899ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart /* 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Set default values easily detected by the midlayer as 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * failure cases. The scsi lldd is responsible for initializing 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * all transport attributes to valid values per host. 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 394aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->node_name = -1; 395aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_name = -1; 396aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->permanent_port_name = -1; 397aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->supported_classes = FC_COS_UNSPECIFIED; 398aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->supported_fc4s, 0, 399aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->supported_fc4s)); 400aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; 401aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->maxframe_size = -1; 402a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->max_npiv_vports = 0; 403aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->serial_number, 0, 404aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->serial_number)); 405bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->manufacturer, 0, 406bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->manufacturer)); 407bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->model, 0, 408bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->model)); 409bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->model_description, 0, 410bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->model_description)); 411bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->hardware_version, 0, 412bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->hardware_version)); 413bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->driver_version, 0, 414bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->driver_version)); 415bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->firmware_version, 0, 416bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->firmware_version)); 417bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh memset(fc_host->optionrom_version, 0, 418bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh sizeof(fc_host->optionrom_version)); 419aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 420aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_id = -1; 421aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_type = FC_PORTTYPE_UNKNOWN; 422aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_state = FC_PORTSTATE_UNKNOWN; 423aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->active_fc4s, 0, 424aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->active_fc4s)); 425aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->speed = FC_PORTSPEED_UNKNOWN; 426aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->fabric_name = -1; 427b8d08210126a7b769b857720a59721a453a57a1eJames Smart memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name)); 428b8d08210126a7b769b857720a59721a453a57a1eJames Smart memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname)); 429aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 430aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN; 431aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 432aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_LIST_HEAD(&fc_host->rports); 433aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_LIST_HEAD(&fc_host->rport_bindings); 434a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart INIT_LIST_HEAD(&fc_host->vports); 435aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->next_rport_number = 0; 436aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->next_target_id = 0; 437a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->next_vport_number = 0; 438a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->npiv_vports_inuse = 0; 439aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 440aab0de245150c09e61c30962feb16aacde508dc3Kay Sievers snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name), 441aab0de245150c09e61c30962feb16aacde508dc3Kay Sievers "fc_wq_%d", shost->host_no); 442d8537548c924db3c44afde7646b6e220c7beb79dKees Cook fc_host->work_q = alloc_workqueue("%s", 0, 0, fc_host->work_q_name); 443aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host->work_q) 444aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -ENOMEM; 445aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 44643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie fc_host->dev_loss_tmo = fc_dev_loss_tmo; 447aab0de245150c09e61c30962feb16aacde508dc3Kay Sievers snprintf(fc_host->devloss_work_q_name, 448aab0de245150c09e61c30962feb16aacde508dc3Kay Sievers sizeof(fc_host->devloss_work_q_name), 449aab0de245150c09e61c30962feb16aacde508dc3Kay Sievers "fc_dl_%d", shost->host_no); 450d8537548c924db3c44afde7646b6e220c7beb79dKees Cook fc_host->devloss_work_q = alloc_workqueue("%s", 0, 0, 451d8537548c924db3c44afde7646b6e220c7beb79dKees Cook fc_host->devloss_work_q_name); 452aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host->devloss_work_q) { 453aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(fc_host->work_q); 454aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q = NULL; 455aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -ENOMEM; 456aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 457aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 4589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_hostadd(shost, fc_host); 4599e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* ignore any bsg add error - we just can't do sgio */ 4609e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 4619e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return 0; 4629e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 4639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 4649e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int fc_host_remove(struct transport_container *tc, struct device *dev, 4659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct device *cdev) 4669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 4679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct Scsi_Host *shost = dev_to_shost(dev); 4689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 4699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 4709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_remove(fc_host->rqst_q); 4711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 4721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 4731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_host_class, 4751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_host", 4761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_setup, 4779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_host_remove, 4781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 4791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 4811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup and Remove actions for remote ports are handled 4821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in the service functions below. 4831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 4841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_rport_class, 4851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_remote_ports", 4861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 4871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 4881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 4891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 491a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Setup and Remove actions for virtual ports are handled 492a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * in the service functions below. 493a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 494a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic DECLARE_TRANSPORT_CLASS(fc_vport_class, 495a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart "fc_vports", 496a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart NULL, 497a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart NULL, 498a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart NULL); 499a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 500a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 50184314fd4740ad73550c76dee4a9578979d84af48James Smart * Netlink Infrastructure 502eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 50384314fd4740ad73550c76dee4a9578979d84af48James Smart 50484314fd4740ad73550c76dee4a9578979d84af48James Smartstatic atomic_t fc_event_seq; 50584314fd4740ad73550c76dee4a9578979d84af48James Smart 50684314fd4740ad73550c76dee4a9578979d84af48James Smart/** 50784314fd4740ad73550c76dee4a9578979d84af48James Smart * fc_get_event_number - Obtain the next sequential FC event number 50884314fd4740ad73550c76dee4a9578979d84af48James Smart * 50984314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 510eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * We could have inlined this, but it would have required fc_event_seq to 51184314fd4740ad73550c76dee4a9578979d84af48James Smart * be exposed. For now, live with the subroutine call. 51284314fd4740ad73550c76dee4a9578979d84af48James Smart * Atomic used to avoid lock/unlock... 513eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 51484314fd4740ad73550c76dee4a9578979d84af48James Smartu32 51584314fd4740ad73550c76dee4a9578979d84af48James Smartfc_get_event_number(void) 51684314fd4740ad73550c76dee4a9578979d84af48James Smart{ 51784314fd4740ad73550c76dee4a9578979d84af48James Smart return atomic_add_return(1, &fc_event_seq); 51884314fd4740ad73550c76dee4a9578979d84af48James Smart} 51984314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_get_event_number); 52084314fd4740ad73550c76dee4a9578979d84af48James Smart 52184314fd4740ad73550c76dee4a9578979d84af48James Smart 52284314fd4740ad73550c76dee4a9578979d84af48James Smart/** 52384314fd4740ad73550c76dee4a9578979d84af48James Smart * fc_host_post_event - called to post an even on an fc_host. 52484314fd4740ad73550c76dee4a9578979d84af48James Smart * @shost: host the event occurred on 52584314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_number: fc event number obtained from get_fc_event_number() 52684314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_code: fc_host event being posted 52784314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_data: 32bits of data for the event being posted 52884314fd4740ad73550c76dee4a9578979d84af48James Smart * 52984314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 53084314fd4740ad73550c76dee4a9578979d84af48James Smart * This routine assumes no locks are held on entry. 531eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 53284314fd4740ad73550c76dee4a9578979d84af48James Smartvoid 53384314fd4740ad73550c76dee4a9578979d84af48James Smartfc_host_post_event(struct Scsi_Host *shost, u32 event_number, 53484314fd4740ad73550c76dee4a9578979d84af48James Smart enum fc_host_event_code event_code, u32 event_data) 53584314fd4740ad73550c76dee4a9578979d84af48James Smart{ 53684314fd4740ad73550c76dee4a9578979d84af48James Smart struct sk_buff *skb; 53784314fd4740ad73550c76dee4a9578979d84af48James Smart struct nlmsghdr *nlh; 53884314fd4740ad73550c76dee4a9578979d84af48James Smart struct fc_nl_event *event; 53984314fd4740ad73550c76dee4a9578979d84af48James Smart const char *name; 540e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo u32 len; 54184314fd4740ad73550c76dee4a9578979d84af48James Smart int err; 54284314fd4740ad73550c76dee4a9578979d84af48James Smart 54384314fd4740ad73550c76dee4a9578979d84af48James Smart if (!scsi_nl_sock) { 54484314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOENT; 54584314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail; 54684314fd4740ad73550c76dee4a9578979d84af48James Smart } 54784314fd4740ad73550c76dee4a9578979d84af48James Smart 54884314fd4740ad73550c76dee4a9578979d84af48James Smart len = FC_NL_MSGALIGN(sizeof(*event)); 54984314fd4740ad73550c76dee4a9578979d84af48James Smart 550e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo skb = nlmsg_new(len, GFP_KERNEL); 55184314fd4740ad73550c76dee4a9578979d84af48James Smart if (!skb) { 55284314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 55384314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail; 55484314fd4740ad73550c76dee4a9578979d84af48James Smart } 55584314fd4740ad73550c76dee4a9578979d84af48James Smart 556e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0); 55784314fd4740ad73550c76dee4a9578979d84af48James Smart if (!nlh) { 55884314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 55984314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail_skb; 56084314fd4740ad73550c76dee4a9578979d84af48James Smart } 561e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo event = nlmsg_data(nlh); 56284314fd4740ad73550c76dee4a9578979d84af48James Smart 56384314fd4740ad73550c76dee4a9578979d84af48James Smart INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 56484314fd4740ad73550c76dee4a9578979d84af48James Smart FC_NL_ASYNC_EVENT, len); 56584314fd4740ad73550c76dee4a9578979d84af48James Smart event->seconds = get_seconds(); 56684314fd4740ad73550c76dee4a9578979d84af48James Smart event->vendor_id = 0; 56784314fd4740ad73550c76dee4a9578979d84af48James Smart event->host_no = shost->host_no; 56884314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_datalen = sizeof(u32); /* bytes */ 56984314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_num = event_number; 57084314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_code = event_code; 57184314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_data = event_data; 57284314fd4740ad73550c76dee4a9578979d84af48James Smart 573ff491a7334acfd74e515c896632e37e401f52676Pablo Neira Ayuso nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, 574ff491a7334acfd74e515c896632e37e401f52676Pablo Neira Ayuso GFP_KERNEL); 57584314fd4740ad73550c76dee4a9578979d84af48James Smart return; 57684314fd4740ad73550c76dee4a9578979d84af48James Smart 57784314fd4740ad73550c76dee4a9578979d84af48James Smartsend_fail_skb: 57884314fd4740ad73550c76dee4a9578979d84af48James Smart kfree_skb(skb); 57984314fd4740ad73550c76dee4a9578979d84af48James Smartsend_fail: 58084314fd4740ad73550c76dee4a9578979d84af48James Smart name = get_fc_host_event_code_name(event_code); 58184314fd4740ad73550c76dee4a9578979d84af48James Smart printk(KERN_WARNING 58284314fd4740ad73550c76dee4a9578979d84af48James Smart "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", 583cadbd4a5e36dde7e6c49b587b2c419103c0b7218Harvey Harrison __func__, shost->host_no, 58484314fd4740ad73550c76dee4a9578979d84af48James Smart (name) ? name : "<unknown>", event_data, err); 58584314fd4740ad73550c76dee4a9578979d84af48James Smart return; 58684314fd4740ad73550c76dee4a9578979d84af48James Smart} 58784314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_host_post_event); 58884314fd4740ad73550c76dee4a9578979d84af48James Smart 58984314fd4740ad73550c76dee4a9578979d84af48James Smart 59084314fd4740ad73550c76dee4a9578979d84af48James Smart/** 591eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_host_post_vendor_event - called to post a vendor unique event on an fc_host 59284314fd4740ad73550c76dee4a9578979d84af48James Smart * @shost: host the event occurred on 59384314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_number: fc event number obtained from get_fc_event_number() 59484314fd4740ad73550c76dee4a9578979d84af48James Smart * @data_len: amount, in bytes, of vendor unique data 59584314fd4740ad73550c76dee4a9578979d84af48James Smart * @data_buf: pointer to vendor unique data 596eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * @vendor_id: Vendor id 59784314fd4740ad73550c76dee4a9578979d84af48James Smart * 59884314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 59984314fd4740ad73550c76dee4a9578979d84af48James Smart * This routine assumes no locks are held on entry. 600eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 60184314fd4740ad73550c76dee4a9578979d84af48James Smartvoid 60284314fd4740ad73550c76dee4a9578979d84af48James Smartfc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, 603f14e2e29cdd07f80de6dec168dc2bb39de37eec3James Smart u32 data_len, char * data_buf, u64 vendor_id) 60484314fd4740ad73550c76dee4a9578979d84af48James Smart{ 60584314fd4740ad73550c76dee4a9578979d84af48James Smart struct sk_buff *skb; 60684314fd4740ad73550c76dee4a9578979d84af48James Smart struct nlmsghdr *nlh; 60784314fd4740ad73550c76dee4a9578979d84af48James Smart struct fc_nl_event *event; 608e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo u32 len; 60984314fd4740ad73550c76dee4a9578979d84af48James Smart int err; 61084314fd4740ad73550c76dee4a9578979d84af48James Smart 61184314fd4740ad73550c76dee4a9578979d84af48James Smart if (!scsi_nl_sock) { 61284314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOENT; 61384314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail; 61484314fd4740ad73550c76dee4a9578979d84af48James Smart } 61584314fd4740ad73550c76dee4a9578979d84af48James Smart 61684314fd4740ad73550c76dee4a9578979d84af48James Smart len = FC_NL_MSGALIGN(sizeof(*event) + data_len); 61784314fd4740ad73550c76dee4a9578979d84af48James Smart 618e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo skb = nlmsg_new(len, GFP_KERNEL); 61984314fd4740ad73550c76dee4a9578979d84af48James Smart if (!skb) { 62084314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 62184314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail; 62284314fd4740ad73550c76dee4a9578979d84af48James Smart } 62384314fd4740ad73550c76dee4a9578979d84af48James Smart 624e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0); 62584314fd4740ad73550c76dee4a9578979d84af48James Smart if (!nlh) { 62684314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 62784314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail_skb; 62884314fd4740ad73550c76dee4a9578979d84af48James Smart } 629e07ebea0ccfaf627464460eb57d7f2fdbcccf8ecHong zhi guo event = nlmsg_data(nlh); 63084314fd4740ad73550c76dee4a9578979d84af48James Smart 63184314fd4740ad73550c76dee4a9578979d84af48James Smart INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 63284314fd4740ad73550c76dee4a9578979d84af48James Smart FC_NL_ASYNC_EVENT, len); 63384314fd4740ad73550c76dee4a9578979d84af48James Smart event->seconds = get_seconds(); 63484314fd4740ad73550c76dee4a9578979d84af48James Smart event->vendor_id = vendor_id; 63584314fd4740ad73550c76dee4a9578979d84af48James Smart event->host_no = shost->host_no; 63684314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_datalen = data_len; /* bytes */ 63784314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_num = event_number; 63884314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_code = FCH_EVT_VENDOR_UNIQUE; 63984314fd4740ad73550c76dee4a9578979d84af48James Smart memcpy(&event->event_data, data_buf, data_len); 64084314fd4740ad73550c76dee4a9578979d84af48James Smart 641ff491a7334acfd74e515c896632e37e401f52676Pablo Neira Ayuso nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, 642ff491a7334acfd74e515c896632e37e401f52676Pablo Neira Ayuso GFP_KERNEL); 64384314fd4740ad73550c76dee4a9578979d84af48James Smart return; 64484314fd4740ad73550c76dee4a9578979d84af48James Smart 64584314fd4740ad73550c76dee4a9578979d84af48James Smartsend_vendor_fail_skb: 64684314fd4740ad73550c76dee4a9578979d84af48James Smart kfree_skb(skb); 64784314fd4740ad73550c76dee4a9578979d84af48James Smartsend_vendor_fail: 64884314fd4740ad73550c76dee4a9578979d84af48James Smart printk(KERN_WARNING 64984314fd4740ad73550c76dee4a9578979d84af48James Smart "%s: Dropped Event : host %d vendor_unique - err %d\n", 650cadbd4a5e36dde7e6c49b587b2c419103c0b7218Harvey Harrison __func__, shost->host_no, err); 65184314fd4740ad73550c76dee4a9578979d84af48James Smart return; 65284314fd4740ad73550c76dee4a9578979d84af48James Smart} 65384314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_host_post_vendor_event); 65484314fd4740ad73550c76dee4a9578979d84af48James Smart 65584314fd4740ad73550c76dee4a9578979d84af48James Smart 6561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic __init int fc_transport_init(void) 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 65984314fd4740ad73550c76dee4a9578979d84af48James Smart int error; 66084314fd4740ad73550c76dee4a9578979d84af48James Smart 66184314fd4740ad73550c76dee4a9578979d84af48James Smart atomic_set(&fc_event_seq, 0); 66284314fd4740ad73550c76dee4a9578979d84af48James Smart 66384314fd4740ad73550c76dee4a9578979d84af48James Smart error = transport_class_register(&fc_host_class); 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) 6651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return error; 666a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart error = transport_class_register(&fc_vport_class); 667a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (error) 66848de68a40aef032a2e198437f4781a83bfb938dbMike Christie goto unreg_host_class; 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds error = transport_class_register(&fc_rport_class); 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) 67148de68a40aef032a2e198437f4781a83bfb938dbMike Christie goto unreg_vport_class; 67248de68a40aef032a2e198437f4781a83bfb938dbMike Christie error = transport_class_register(&fc_transport_class); 67348de68a40aef032a2e198437f4781a83bfb938dbMike Christie if (error) 67448de68a40aef032a2e198437f4781a83bfb938dbMike Christie goto unreg_rport_class; 67548de68a40aef032a2e198437f4781a83bfb938dbMike Christie return 0; 67648de68a40aef032a2e198437f4781a83bfb938dbMike Christie 67748de68a40aef032a2e198437f4781a83bfb938dbMike Christieunreg_rport_class: 67848de68a40aef032a2e198437f4781a83bfb938dbMike Christie transport_class_unregister(&fc_rport_class); 67948de68a40aef032a2e198437f4781a83bfb938dbMike Christieunreg_vport_class: 68048de68a40aef032a2e198437f4781a83bfb938dbMike Christie transport_class_unregister(&fc_vport_class); 68148de68a40aef032a2e198437f4781a83bfb938dbMike Christieunreg_host_class: 68248de68a40aef032a2e198437f4781a83bfb938dbMike Christie transport_class_unregister(&fc_host_class); 68348de68a40aef032a2e198437f4781a83bfb938dbMike Christie return error; 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit fc_transport_exit(void) 6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_transport_class); 6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_rport_class); 6901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_host_class); 691a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_class_unregister(&fc_vport_class); 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FC Remote Port Attribute Management 6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 6971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_show_function(field, format_string, sz, cast) \ 6991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 700ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_##field (struct device *dev, \ 701ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 7021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 703ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); \ 7041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); \ 7051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 70619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((i->f->get_rport_##field) && \ 70719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com !((rport->port_state == FC_PORTSTATE_BLOCKED) || \ 70842e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || \ 70919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \ 7101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_rport_##field(rport); \ 7111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast rport->field); \ 7121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_store_function(field) \ 7151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 716ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_rport_##field(struct device *dev, \ 717ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 718ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 7191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 7201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val; \ 721ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); \ 7221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); \ 7231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 7240f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart char *cp; \ 72519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \ 72642e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || \ 72719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \ 72819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return -EBUSY; \ 7290f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart val = simple_strtoul(buf, &cp, 0); \ 7300f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (*cp && (*cp != '\n')) \ 7310f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return -EINVAL; \ 7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->set_rport_##field(rport, val); \ 7331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 7341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rd_attr(field, format_string, sz) \ 7371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, ) \ 738ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, field, S_IRUGO, \ 7391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 7401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rd_attr_cast(field, format_string, sz, cast) \ 7421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, (cast)) \ 743ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, field, S_IRUGO, \ 7441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 7451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rw_attr(field, format_string, sz) \ 7471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, ) \ 7481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_store_function(field) \ 749ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \ 7501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, \ 7511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_rport_##field) 7521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_show_function(field, format_string, sz, cast) \ 7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 756ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_##field (struct device *dev, \ 757ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 759ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); \ 7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast rport->field); \ 7611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_attr(field, format_string, sz) \ 7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_rport_show_function(field, format_string, sz, ) \ 765ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, field, S_IRUGO, \ 7661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \ 7691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_rport_show_function(field, format_string, sz, (cast)) \ 770ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, field, S_IRUGO, \ 7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 7721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_enum_attr(title, maxlen) \ 7751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 776ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_##title (struct device *dev, \ 777ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 779ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); \ 7801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; \ 7811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_##title##_name(rport->title); \ 7821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) \ 7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; \ 7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, maxlen, "%s\n", name); \ 7851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 786ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, title, S_IRUGO, \ 7871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##title, NULL) 7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_RPORT_ATTRIBUTE_RD(field) \ 791ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_rport_attrs[count] = device_attr_rport_##field; \ 7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 7931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 7941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_rport_##field) \ 7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \ 799ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_rport_attrs[count] = device_attr_rport_##field; \ 8001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 8021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 8031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 8041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_RPORT_ATTRIBUTE_RW(field) \ 806ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_rport_attrs[count] = device_attr_rport_##field; \ 8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_rport_##field) { \ 8081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_rport_##field) \ 8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 8141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8150f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(field) \ 8160f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart{ \ 817ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_rport_attrs[count] = device_attr_rport_##field; \ 8180f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 8190f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart count++; \ 8200f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart} 8210f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* The FC Transport Remote Port Attributes: */ 8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Fixed Remote Port Attributes */ 8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20); 8281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 830ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_supported_classes (struct device *dev, 831ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 833ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); 8341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->supported_classes == FC_COS_UNSPECIFIED) 8351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unspecified\n"); 8361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_cos_names(rport->supported_classes, buf); 8371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 838ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO, 8391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_supported_classes, NULL); 8401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Dynamic Remote Port Attributes */ 8421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 84319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com/* 84419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * dev_loss_tmo attribute 84519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 84643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic int fc_str_to_dev_loss(const char *buf, unsigned long *val) 84743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie{ 84843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie char *cp; 84943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 85043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie *val = simple_strtoul(buf, &cp, 0); 85143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie if ((*cp && (*cp != '\n')) || (*val < 0)) 85243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return -EINVAL; 85343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie /* 85443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie * Check for overflow; dev_loss_tmo is u32 85543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie */ 85643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie if (*val > UINT_MAX) 85743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return -EINVAL; 85843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 85943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return 0; 86043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie} 86143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 86243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic int fc_rport_set_dev_loss_tmo(struct fc_rport *rport, 86343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie unsigned long val) 86419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com{ 86519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct Scsi_Host *shost = rport_to_shost(rport); 86619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct fc_internal *i = to_fc_internal(shost->transportt); 86743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 86819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) || 86942e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || 87019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT)) 87119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return -EBUSY; 872f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke /* 87336dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke * Check for overflow; dev_loss_tmo is u32 87436dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke */ 87536dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke if (val > UINT_MAX) 87636dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke return -EINVAL; 87736dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke 87836dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke /* 879f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke * If fast_io_fail is off we have to cap 880f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke * dev_loss_tmo at SCSI_DEVICE_BLOCK_MAX_TIMEOUT 881f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke */ 882f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke if (rport->fast_io_fail_tmo == -1 && 883f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT) 884f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke return -EINVAL; 885f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke 88619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com i->f->set_rport_dev_loss_tmo(rport, val); 88743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return 0; 88843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie} 88943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 89043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiefc_rport_show_function(dev_loss_tmo, "%d\n", 20, ) 89143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic ssize_t 89243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestore_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr, 89343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie const char *buf, size_t count) 89443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie{ 89543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie struct fc_rport *rport = transport_class_to_rport(dev); 89643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie unsigned long val; 89743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie int rc; 89843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 89943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie rc = fc_str_to_dev_loss(buf, &val); 90043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie if (rc) 90143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return rc; 90243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 90343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie rc = fc_rport_set_dev_loss_tmo(rport, val); 90443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie if (rc) 90543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return rc; 90619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return count; 90719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com} 908ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR, 90919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo); 9101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Private Remote Port Attributes */ 9131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 9151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 9161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(port_id, "0x%06x\n", 20); 9171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 919ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_roles (struct device *dev, struct device_attribute *attr, 920ee959b00c335d7780136c5abda37809191fe52c3Tony Jones char *buf) 9211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 922ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); 9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* identify any roles that are port_id specific */ 9251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((rport->port_id != -1) && 9261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (rport->port_id & FC_WELLKNOWN_PORTID_MASK) == 9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FC_WELLKNOWN_PORTID_MASK) { 9281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) { 9291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_FPORT_PORTID: 9301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Fabric Port\n"); 9311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_FABCTLR_PORTID: 9321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Fabric Controller\n"); 9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_DIRSRVR_PORTID: 9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Directory Server\n"); 9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TIMESRVR_PORTID: 9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Time Server\n"); 9371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_MGMTSRVR_PORTID: 9381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Management Server\n"); 9391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 9401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Unknown Fabric Entity\n"); 9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 943a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (rport->roles == FC_PORT_ROLE_UNKNOWN) 9441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 945a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return get_fc_port_roles_names(rport->roles, buf); 9461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 9471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 948ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, roles, S_IRUGO, 9491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_roles, NULL); 9501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); 9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(scsi_target_id, "%d\n", 20); 9531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9540f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart/* 9550f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart * fast_io_fail_tmo attribute 9560f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart */ 9570f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smartstatic ssize_t 958ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_rport_fast_io_fail_tmo (struct device *dev, 959ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 9600f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart{ 961ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); 9620f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 9630f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (rport->fast_io_fail_tmo == -1) 9640f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return snprintf(buf, 5, "off\n"); 9650f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo); 9660f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart} 9670f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 9680f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smartstatic ssize_t 969ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_rport_fast_io_fail_tmo(struct device *dev, 970ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, const char *buf, 971ee959b00c335d7780136c5abda37809191fe52c3Tony Jones size_t count) 9720f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart{ 9730f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart int val; 9740f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart char *cp; 975ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_rport *rport = transport_class_to_rport(dev); 9760f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 9770f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if ((rport->port_state == FC_PORTSTATE_BLOCKED) || 9780f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart (rport->port_state == FC_PORTSTATE_DELETED) || 9790f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart (rport->port_state == FC_PORTSTATE_NOTPRESENT)) 9800f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return -EBUSY; 9810f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (strncmp(buf, "off", 3) == 0) 9820f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart rport->fast_io_fail_tmo = -1; 9830f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart else { 9840f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart val = simple_strtoul(buf, &cp, 0); 985f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke if ((*cp && (*cp != '\n')) || (val < 0)) 986f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke return -EINVAL; 987f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke /* 988f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke * Cap fast_io_fail by dev_loss_tmo or 989f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke * SCSI_DEVICE_BLOCK_MAX_TIMEOUT. 990f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke */ 991f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke if ((val >= rport->dev_loss_tmo) || 992f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)) 9930f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return -EINVAL; 994f2818663c82b7297ff4aa38cbddb870dc02f7104Hannes Reinecke 9950f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart rport->fast_io_fail_tmo = val; 9960f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart } 9970f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return count; 9980f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart} 999ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR, 10000f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart show_fc_rport_fast_io_fail_tmo, store_fc_rport_fast_io_fail_tmo); 10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 10041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FC SCSI Target Attribute Management 10051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 10081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note: in the target show function we recognize when the remote 1009732bee7af3102cad811fb047dee8d15966efe569Uwe Kleine-König * port is in the hierarchy and do not allow the driver to get 10101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * involved in sysfs functions. The driver only gets involved if 10111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it's the "old" style that doesn't use rports. 10121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_show_function(field, format_string, sz, cast) \ 10141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1015ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_starget_##field (struct device *dev, \ 1016ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 10171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1018ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct scsi_target *starget = transport_class_to_starget(dev); \ 10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ 10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 10211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = starget_to_rport(starget); \ 10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport) \ 10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_##field(starget) = rport->field; \ 10241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (i->f->get_starget_##field) \ 10251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_starget_##field(starget); \ 10261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, \ 10271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cast fc_starget_##field(starget)); \ 10281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_rd_attr(field, format_string, sz) \ 10311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_show_function(field, format_string, sz, ) \ 1032ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(starget, field, S_IRUGO, \ 10331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_starget_##field, NULL) 10341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_rd_attr_cast(field, format_string, sz, cast) \ 10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_show_function(field, format_string, sz, (cast)) \ 1037ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(starget, field, S_IRUGO, \ 10381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_starget_##field, NULL) 10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_STARGET_ATTRIBUTE_RD(field) \ 1041ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_starget_attrs[count] = device_attr_starget_##field; \ 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].attr.mode = S_IRUGO; \ 10431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].store = NULL; \ 10441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = &i->private_starget_attrs[count]; \ 10451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_starget_##field) \ 10461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 10471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_STARGET_ATTRIBUTE_RW(field) \ 1049ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_starget_attrs[count] = device_attr_starget_##field; \ 10501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_starget_##field) { \ 10511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].attr.mode = S_IRUGO; \ 10521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].store = NULL; \ 10531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = &i->private_starget_attrs[count]; \ 10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_starget_##field) \ 10561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* The FC Transport SCSI Target Attributes: */ 10591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 10601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 10611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr(port_id, "0x%06x\n", 20); 10621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1065a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * FC Virtual Port Attribute Management 1066a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 1067a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1068a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_show_function(field, format_string, sz, cast) \ 1069a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1070ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_vport_##field (struct device *dev, \ 1071ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 1072a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1073ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1074a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost = vport_to_shost(vport); \ 1075a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i = to_fc_internal(shost->transportt); \ 1076a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if ((i->f->get_vport_##field) && \ 1077a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \ 1078a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->f->get_vport_##field(vport); \ 1079a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return snprintf(buf, sz, format_string, cast vport->field); \ 1080a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1081a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1082a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_store_function(field) \ 1083a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1084ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_vport_##field(struct device *dev, \ 1085ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1086ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 1087a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1088a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int val; \ 1089ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1090a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost = vport_to_shost(vport); \ 1091a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i = to_fc_internal(shost->transportt); \ 1092a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart char *cp; \ 1093a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \ 1094a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EBUSY; \ 1095a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart val = simple_strtoul(buf, &cp, 0); \ 1096a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (*cp && (*cp != '\n')) \ 1097a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; \ 1098a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->f->set_vport_##field(vport, val); \ 1099a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return count; \ 1100a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1101a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1102a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_store_str_function(field, slen) \ 1103a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1104ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_vport_##field(struct device *dev, \ 1105ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1106ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 1107a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1108ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1109a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost = vport_to_shost(vport); \ 1110a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i = to_fc_internal(shost->transportt); \ 1111a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned int cnt=count; \ 1112a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart \ 1113a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* count may include a LF at end of string */ \ 1114a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (buf[cnt-1] == '\n') \ 1115a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart cnt--; \ 1116a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (cnt > ((slen) - 1)) \ 1117a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; \ 1118a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart memcpy(vport->field, buf, cnt); \ 1119a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->f->set_vport_##field(vport); \ 1120a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return count; \ 1121a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1122a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1123a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_rd_attr(field, format_string, sz) \ 1124a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_vport_show_function(field, format_string, sz, ) \ 1125ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO, \ 1126a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, NULL) 1127a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1128a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_rd_attr_cast(field, format_string, sz, cast) \ 1129a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_vport_show_function(field, format_string, sz, (cast)) \ 1130ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO, \ 1131a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, NULL) 1132a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1133a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_vport_rw_attr(field, format_string, sz) \ 1134a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_vport_show_function(field, format_string, sz, ) \ 1135a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_vport_store_function(field) \ 1136ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ 1137a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, \ 1138a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart store_fc_vport_##field) 1139a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1140a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_show_function(field, format_string, sz, cast) \ 1141a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1142ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_vport_##field (struct device *dev, \ 1143ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 1144a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1145ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1146a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return snprintf(buf, sz, format_string, cast vport->field); \ 1147a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1148a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1149a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_store_u32_function(field) \ 1150a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1151ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_vport_##field(struct device *dev, \ 1152ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1153ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 1154a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1155a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart u32 val; \ 1156ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1157a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart char *cp; \ 1158a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \ 1159a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EBUSY; \ 1160a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart val = simple_strtoul(buf, &cp, 0); \ 1161a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (*cp && (*cp != '\n')) \ 1162a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; \ 1163a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->field = val; \ 1164a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return count; \ 1165a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1166a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1167a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1168a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_rd_attr(field, format_string, sz) \ 1169a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_private_vport_show_function(field, format_string, sz, ) \ 1170ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO, \ 1171a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, NULL) 1172a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1173a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_rd_attr_cast(field, format_string, sz, cast) \ 1174a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_private_vport_show_function(field, format_string, sz, (cast)) \ 1175ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO, \ 1176a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, NULL) 1177a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1178a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_rw_u32_attr(field, format_string, sz) \ 1179a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_private_vport_show_function(field, format_string, sz, ) \ 1180a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_private_vport_store_u32_function(field) \ 1181ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \ 1182a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##field, \ 1183a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart store_fc_vport_##field) 1184a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1185a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1186a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define fc_private_vport_rd_enum_attr(title, maxlen) \ 1187a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t \ 1188ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_vport_##title (struct device *dev, \ 1189ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1190ee959b00c335d7780136c5abda37809191fe52c3Tony Jones char *buf) \ 1191a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1192ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); \ 1193a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart const char *name; \ 1194a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart name = get_fc_##title##_name(vport->title); \ 1195a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!name) \ 1196a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; \ 1197a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return snprintf(buf, maxlen, "%s\n", name); \ 1198a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} \ 1199ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, title, S_IRUGO, \ 1200a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_##title, NULL) 1201a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1202a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1203a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_VPORT_ATTRIBUTE_RD(field) \ 1204ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_vport_attrs[count] = device_attr_vport_##field; \ 1205a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].attr.mode = S_IRUGO; \ 1206a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].store = NULL; \ 1207a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = &i->private_vport_attrs[count]; \ 1208a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (i->f->get_##field) \ 1209a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++ 1210a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* NOTE: Above MACRO differs: checks function not show bit */ 1211a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1212a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field) \ 1213ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_vport_attrs[count] = device_attr_vport_##field; \ 1214a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].attr.mode = S_IRUGO; \ 1215a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].store = NULL; \ 1216a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = &i->private_vport_attrs[count]; \ 1217a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++ 1218a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1219a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_VPORT_ATTRIBUTE_WR(field) \ 1220ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_vport_attrs[count] = device_attr_vport_##field; \ 1221a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = &i->private_vport_attrs[count]; \ 1222a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (i->f->field) \ 1223a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++ 1224a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* NOTE: Above MACRO differs: checks function */ 1225a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1226a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_VPORT_ATTRIBUTE_RW(field) \ 1227ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_vport_attrs[count] = device_attr_vport_##field; \ 1228a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!i->f->set_vport_##field) { \ 1229a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].attr.mode = S_IRUGO; \ 1230a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_vport_attrs[count].store = NULL; \ 1231a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } \ 1232a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = &i->private_vport_attrs[count]; \ 1233a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++ 1234a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* NOTE: Above MACRO differs: does not check show bit */ 1235a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1236a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field) \ 1237a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ \ 1238ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_vport_attrs[count] = device_attr_vport_##field; \ 1239a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = &i->private_vport_attrs[count]; \ 1240a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++; \ 1241a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1242a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1243a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1244a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* The FC Transport Virtual Port Attributes: */ 1245a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1246a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Fixed Virtual Port Attributes */ 1247a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1248a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Dynamic Virtual Port Attributes */ 1249a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1250a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Private Virtual Port Attributes */ 1251a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1252a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN); 1253a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN); 1254a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 1255a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 1256a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1257a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t 1258ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_vport_roles (struct device *dev, struct device_attribute *attr, 1259ee959b00c335d7780136c5abda37809191fe52c3Tony Jones char *buf) 1260a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1261ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); 1262a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1263a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->roles == FC_PORT_ROLE_UNKNOWN) 1264a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return snprintf(buf, 20, "unknown\n"); 1265a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return get_fc_port_roles_names(vport->roles, buf); 1266a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1267ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL); 1268a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1269a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN); 1270a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1271a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_vport_show_function(symbolic_name, "%s\n", 1272a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart FC_VPORT_SYMBOLIC_NAMELEN + 1, ) 1273a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_vport_store_str_function(symbolic_name, FC_VPORT_SYMBOLIC_NAMELEN) 1274ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, symbolic_name, S_IRUGO | S_IWUSR, 1275a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart show_fc_vport_symbolic_name, store_fc_vport_symbolic_name); 1276a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1277a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t 1278ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_vport_delete(struct device *dev, struct device_attribute *attr, 1279ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) 1280a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1281ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); 12829ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart struct Scsi_Host *shost = vport_to_shost(vport); 12830d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen unsigned long flags; 12840d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen 12850d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen spin_lock_irqsave(shost->host_lock, flags); 12860d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) { 12870d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen spin_unlock_irqrestore(shost->host_lock, flags); 12880d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen return -EBUSY; 12890d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen } 12900d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen vport->flags |= FC_VPORT_DELETING; 12910d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen spin_unlock_irqrestore(shost->host_lock, flags); 1292a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 12939ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart fc_queue_work(shost, &vport->vport_delete_work); 1294a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return count; 1295a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1296ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, vport_delete, S_IWUSR, 1297a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart NULL, store_fc_vport_delete); 1298a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1299a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1300a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 1301a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Enable/Disable vport 1302a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Write "1" to disable, write "0" to enable 1303a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 1304a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t 1305ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_vport_disable(struct device *dev, struct device_attribute *attr, 1306ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, 1307a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart size_t count) 1308a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1309ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct fc_vport *vport = transport_class_to_vport(dev); 1310a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost = vport_to_shost(vport); 1311a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 1312a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int stat; 1313a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1314a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) 1315a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EBUSY; 1316a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1317a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (*buf == '0') { 1318a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->vport_state != FC_VPORT_DISABLED) 1319a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EALREADY; 1320a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } else if (*buf == '1') { 1321a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (vport->vport_state == FC_VPORT_DISABLED) 1322a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EALREADY; 1323a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } else 1324a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; 1325a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1326a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true)); 1327a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat ? stat : count; 1328a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1329ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(vport, vport_disable, S_IWUSR, 1330a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart NULL, store_fc_vport_disable); 1331a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1332a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1333a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 13341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Host Attribute Management 13351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 13361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_show_function(field, format_string, sz, cast) \ 13381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1339ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_##field (struct device *dev, \ 1340ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 13411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1342ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); \ 13431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 13441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_##field) \ 13451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_##field(shost); \ 13461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ 13471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_store_function(field) \ 13501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1351ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_host_##field(struct device *dev, \ 1352ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1353ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 13541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 13551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val; \ 1356ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); \ 13571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 13580f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart char *cp; \ 13591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 13600f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart val = simple_strtoul(buf, &cp, 0); \ 13610f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (*cp && (*cp != '\n')) \ 13620f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return -EINVAL; \ 13631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->set_host_##field(shost, val); \ 13641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 13651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1367b8d08210126a7b769b857720a59721a453a57a1eJames Smart#define fc_host_store_str_function(field, slen) \ 1368b8d08210126a7b769b857720a59721a453a57a1eJames Smartstatic ssize_t \ 1369ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_host_##field(struct device *dev, \ 1370ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1371ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) \ 1372b8d08210126a7b769b857720a59721a453a57a1eJames Smart{ \ 1373ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); \ 1374b8d08210126a7b769b857720a59721a453a57a1eJames Smart struct fc_internal *i = to_fc_internal(shost->transportt); \ 1375b8d08210126a7b769b857720a59721a453a57a1eJames Smart unsigned int cnt=count; \ 1376b8d08210126a7b769b857720a59721a453a57a1eJames Smart \ 1377b8d08210126a7b769b857720a59721a453a57a1eJames Smart /* count may include a LF at end of string */ \ 1378b8d08210126a7b769b857720a59721a453a57a1eJames Smart if (buf[cnt-1] == '\n') \ 1379b8d08210126a7b769b857720a59721a453a57a1eJames Smart cnt--; \ 1380b8d08210126a7b769b857720a59721a453a57a1eJames Smart if (cnt > ((slen) - 1)) \ 1381b8d08210126a7b769b857720a59721a453a57a1eJames Smart return -EINVAL; \ 1382b8d08210126a7b769b857720a59721a453a57a1eJames Smart memcpy(fc_host_##field(shost), buf, cnt); \ 1383b8d08210126a7b769b857720a59721a453a57a1eJames Smart i->f->set_host_##field(shost); \ 1384b8d08210126a7b769b857720a59721a453a57a1eJames Smart return count; \ 1385b8d08210126a7b769b857720a59721a453a57a1eJames Smart} 1386b8d08210126a7b769b857720a59721a453a57a1eJames Smart 13871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_attr(field, format_string, sz) \ 13881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, ) \ 1389ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, field, S_IRUGO, \ 13901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 13911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_attr_cast(field, format_string, sz, cast) \ 13931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, (cast)) \ 1394ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, field, S_IRUGO, \ 13951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 13961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rw_attr(field, format_string, sz) \ 13981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, ) \ 13991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_store_function(field) \ 1400ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \ 14011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, \ 14021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_host_##field) 14031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_enum_attr(title, maxlen) \ 14051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1406ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_##title (struct device *dev, \ 1407ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 14081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1409ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); \ 14101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 14111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; \ 14121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_##title) \ 14131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_##title(shost); \ 14141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_##title##_name(fc_host_##title(shost)); \ 14151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) \ 14161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; \ 14171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, maxlen, "%s\n", name); \ 14181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 1419ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL) 14201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_HOST_ATTRIBUTE_RD(field) \ 1422ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_host_attrs[count] = device_attr_host_##field; \ 14231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 14241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 14251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 14261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_host_##field) \ 14271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 14281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1429a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart#define SETUP_HOST_ATTRIBUTE_RD_NS(field) \ 1430ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_host_attrs[count] = device_attr_host_##field; \ 1431a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_host_attrs[count].attr.mode = S_IRUGO; \ 1432a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->private_host_attrs[count].store = NULL; \ 1433a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->host_attrs[count] = &i->private_host_attrs[count]; \ 1434a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count++ 1435a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 14361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_HOST_ATTRIBUTE_RW(field) \ 1437ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_host_attrs[count] = device_attr_host_##field; \ 14381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_host_##field) { \ 14391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 14401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 14411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 14421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 14431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_host_##field) \ 14441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 14451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_show_function(field, format_string, sz, cast) \ 14481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1449ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_##field (struct device *dev, \ 1450ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) \ 14511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1452ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); \ 14531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ 14541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 14551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_rd_attr(field, format_string, sz) \ 14571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_host_show_function(field, format_string, sz, ) \ 1458ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, field, S_IRUGO, \ 14591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 14601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \ 14621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_host_show_function(field, format_string, sz, (cast)) \ 1463ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, field, S_IRUGO, \ 14641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 14651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \ 1467ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_host_attrs[count] = device_attr_host_##field; \ 14681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 14691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 14701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 14711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 14721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \ 147491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez{ \ 1475ee959b00c335d7780136c5abda37809191fe52c3Tony Jones i->private_host_attrs[count] = device_attr_host_##field; \ 14761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 147791ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez count++; \ 147891ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez} 14791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Fixed Host Attributes */ 14821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1484ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_supported_classes (struct device *dev, 1485ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 14861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1487ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 14881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED) 14901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unspecified\n"); 14911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_cos_names(fc_host_supported_classes(shost), buf); 14931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1494ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, supported_classes, S_IRUGO, 14951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_classes, NULL); 14961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1498ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_supported_fc4s (struct device *dev, 1499ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 15001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1501ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 15021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost)); 15031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1504ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, supported_fc4s, S_IRUGO, 15051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_fc4s, NULL); 15061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1508ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_supported_speeds (struct device *dev, 1509ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 15101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1511ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 15121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN) 15141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 15151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf); 15171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1518ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, supported_speeds, S_IRUGO, 15191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_speeds, NULL); 15201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 15231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 15246b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmannfc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20, 15256b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmann unsigned long long); 15261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20); 1527a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_private_host_rd_attr(max_npiv_vports, "%u\n", 20); 15281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1)); 1529bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(manufacturer, "%s\n", FC_SERIAL_NUMBER_SIZE + 1); 1530bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(model, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1); 1531bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(model_description, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1); 1532bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(hardware_version, "%s\n", FC_VERSION_STRING_SIZE + 1); 1533bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(driver_version, "%s\n", FC_VERSION_STRING_SIZE + 1); 1534bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(firmware_version, "%s\n", FC_VERSION_STRING_SIZE + 1); 1535bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikhfc_private_host_rd_attr(optionrom_version, "%s\n", FC_VERSION_STRING_SIZE + 1); 15361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Dynamic Host Attributes */ 15391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1541ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_active_fc4s (struct device *dev, 1542ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 15431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1544ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 15451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 15461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_active_fc4s) 15481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_active_fc4s(shost); 15491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost)); 15511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1552ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, active_fc4s, S_IRUGO, 15531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_active_fc4s, NULL); 15541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1556ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_host_speed (struct device *dev, 1557ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 15581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1559ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 15601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 15611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_speed) 15631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_speed(shost); 15641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN) 15661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 15671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_port_speed_names(fc_host_speed(shost), buf); 15691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1570ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, speed, S_IRUGO, 15711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_speed, NULL); 15721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_attr(port_id, "0x%06x\n", 20); 15751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN); 15761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); 15771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long); 1578016131b8fffa1085b4ad165ab228116fdc278ebeJames Smartfc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1); 15791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1580b8d08210126a7b769b857720a59721a453a57a1eJames Smartfc_private_host_show_function(system_hostname, "%s\n", 1581b8d08210126a7b769b857720a59721a453a57a1eJames Smart FC_SYMBOLIC_NAME_SIZE + 1, ) 1582b8d08210126a7b769b857720a59721a453a57a1eJames Smartfc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE) 1583ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR, 1584b8d08210126a7b769b857720a59721a453a57a1eJames Smart show_fc_host_system_hostname, store_fc_host_system_hostname); 1585b8d08210126a7b769b857720a59721a453a57a1eJames Smart 15861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Private Host Attributes */ 15881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1590ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesshow_fc_private_host_tgtid_bind_type(struct device *dev, 1591ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, char *buf) 15921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1593ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 15941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; 15951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost)); 15971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) 15981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 15991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name); 16001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1602d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com#define get_list_head_entry(pos, head, member) \ 1603d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com pos = list_entry((head)->next, typeof(*pos), member) 1604d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com 16051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1606ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_private_host_tgtid_bind_type(struct device *dev, 1607ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, const char *buf, size_t count) 16081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1609ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 1610d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com struct fc_rport *rport; 16111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_tgtid_binding_type val; 16121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 16131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (get_fc_tgtid_bind_type_match(buf, &val)) 16151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 16161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* if changing bind type, purge all unused consistent bindings */ 16181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (val != fc_host_tgtid_bind_type(shost)) { 16191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 1620d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com while (!list_empty(&fc_host_rport_bindings(shost))) { 1621d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com get_list_head_entry(rport, 1622d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com &fc_host_rport_bindings(shost), peers); 1623aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 1624aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 1625aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 1626d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com } 16271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 16281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 16291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_tgtid_bind_type(shost) = val; 16311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; 16321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1634ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR, 16351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_private_host_tgtid_bind_type, 16361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_private_host_tgtid_bind_type); 16371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 163891ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquezstatic ssize_t 1639ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_private_host_issue_lip(struct device *dev, 1640ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, const char *buf, size_t count) 164191ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez{ 1642ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 164391ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez struct fc_internal *i = to_fc_internal(shost->transportt); 164491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez int ret; 164591ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 164691ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez /* ignore any data value written to the attribute */ 164791ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez if (i->f->issue_fc_host_lip) { 164891ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez ret = i->f->issue_fc_host_lip(shost); 164991ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez return ret ? ret: count; 165091ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez } 165191ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 165291ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez return -ENOENT; 165391ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez} 165491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 1655ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL, 165691ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez store_fc_private_host_issue_lip); 165791ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 165843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic ssize_t 165943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestore_fc_private_host_dev_loss_tmo(struct device *dev, 166043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie struct device_attribute *attr, 166143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie const char *buf, size_t count) 166243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie{ 166343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie struct Scsi_Host *shost = transport_class_to_shost(dev); 166443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 166543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie struct fc_rport *rport; 166643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie unsigned long val, flags; 166743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie int rc; 166843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 166943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie rc = fc_str_to_dev_loss(buf, &val); 167043ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie if (rc) 167143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return rc; 167243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 167343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie fc_host_dev_loss_tmo(shost) = val; 167443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie spin_lock_irqsave(shost->host_lock, flags); 167543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie list_for_each_entry(rport, &fc_host->rports, peers) 167643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie fc_rport_set_dev_loss_tmo(rport, val); 167743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie spin_unlock_irqrestore(shost->host_lock, flags); 167843ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie return count; 167943ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie} 1680a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 168143ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiefc_private_host_show_function(dev_loss_tmo, "%d\n", 20, ); 168243ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiestatic FC_DEVICE_ATTR(host, dev_loss_tmo, S_IRUGO | S_IWUSR, 168343ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie show_fc_host_dev_loss_tmo, 168443ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie store_fc_private_host_dev_loss_tmo); 168543ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie 168643ca910a9c90566308f39f51ac03a55f94a5f83cMike Christiefc_private_host_rd_attr(npiv_vports_inuse, "%u\n", 20); 1687a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 16881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 16891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Host Statistics Management 16901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 16911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Show a given an attribute in the statistics group */ 16931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1694ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesfc_stat_show(const struct device *dev, char *buf, unsigned long offset) 16951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1696ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 16971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 16981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_host_statistics *stats; 16991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ssize_t ret = -ENOENT; 17001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (offset > sizeof(struct fc_host_statistics) || 17021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset % sizeof(u64) != 0) 17031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds WARN_ON(1); 17041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_fc_host_stats) { 17061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats = (i->f->get_fc_host_stats)(shost); 17071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (stats) 17081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = snprintf(buf, 20, "0x%llx\n", 17091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (unsigned long long)*(u64 *)(((u8 *) stats) + offset)); 17101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 17121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 17131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* generate a read-only statistics attribute */ 17161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_statistic(name) \ 1717ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic ssize_t show_fcstat_##name(struct device *cd, \ 1718ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct device_attribute *attr, \ 1719ee959b00c335d7780136c5abda37809191fe52c3Tony Jones char *buf) \ 17201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 17211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return fc_stat_show(cd, buf, \ 17221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offsetof(struct fc_host_statistics, name)); \ 17231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 1724ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL) 17251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(seconds_since_last_reset); 17271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(tx_frames); 17281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(tx_words); 17291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(rx_frames); 17301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(rx_words); 17311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(lip_count); 17321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(nos_count); 17331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(error_frames); 17341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(dumped_frames); 17351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(link_failure_count); 17361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(loss_of_sync_count); 17371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(loss_of_signal_count); 17381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(prim_seq_protocol_err_count); 17391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(invalid_tx_word_count); 17401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(invalid_crc_count); 17411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_input_requests); 17421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_output_requests); 17431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_control_requests); 17441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_input_megabytes); 17451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_output_megabytes); 1746e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fcp_packet_alloc_failures); 1747e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fcp_packet_aborts); 1748e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fcp_frame_alloc_failures); 1749e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_no_free_exch); 1750e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_no_free_exch_xid); 1751e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_xid_not_found); 1752e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_xid_busy); 1753e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_seq_not_found); 1754e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Devfc_host_statistic(fc_non_bls_resp); 17551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 1757ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesfc_reset_statistics(struct device *dev, struct device_attribute *attr, 1758ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) 17591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1760ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 17611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 17621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ignore any data value written to the attribute */ 17641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->reset_fc_host_stats) { 17651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->reset_fc_host_stats(shost); 17661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; 17671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOENT; 17701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1771ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL, 17721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_reset_statistics); 17731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct attribute *fc_statistics_attrs[] = { 1775ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_seconds_since_last_reset.attr, 1776ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_tx_frames.attr, 1777ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_tx_words.attr, 1778ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_rx_frames.attr, 1779ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_rx_words.attr, 1780ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_lip_count.attr, 1781ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_nos_count.attr, 1782ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_error_frames.attr, 1783ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_dumped_frames.attr, 1784ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_link_failure_count.attr, 1785ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_loss_of_sync_count.attr, 1786ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_loss_of_signal_count.attr, 1787ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_prim_seq_protocol_err_count.attr, 1788ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_invalid_tx_word_count.attr, 1789ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_invalid_crc_count.attr, 1790ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_fcp_input_requests.attr, 1791ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_fcp_output_requests.attr, 1792ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_fcp_control_requests.attr, 1793ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_fcp_input_megabytes.attr, 1794ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_fcp_output_megabytes.attr, 1795e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fcp_packet_alloc_failures.attr, 1796e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fcp_packet_aborts.attr, 1797e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fcp_frame_alloc_failures.attr, 1798e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_no_free_exch.attr, 1799e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_no_free_exch_xid.attr, 1800e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_xid_not_found.attr, 1801e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_xid_busy.attr, 1802e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_seq_not_found.attr, 1803e58abb0ca423fc7adcf70bee018723b87c9e38c2Vasu Dev &device_attr_host_fc_non_bls_resp.attr, 1804ee959b00c335d7780136c5abda37809191fe52c3Tony Jones &device_attr_host_reset_statistics.attr, 18051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL 18061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 18071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct attribute_group fc_statistics_group = { 18091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "statistics", 18101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .attrs = fc_statistics_attrs, 18111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 18121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1813a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1814a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* Host Vport Attributes */ 1815a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1816a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic int 1817a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_parse_wwn(const char *ns, u64 *nm) 1818a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1819a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned int i, j; 1820a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart u8 wwn[8]; 1821a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1822a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart memset(wwn, 0, sizeof(wwn)); 1823a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1824a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* Validate and store the new name */ 1825a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart for (i=0, j=0; i < 16; i++) { 1826ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko int value; 1827ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko 1828ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko value = hex_to_bin(*ns++); 1829ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko if (value >= 0) 1830ecc3099002c1cc87e9e4b3dc5fdf7821828f6733Andy Shevchenko j = (j << 4) | value; 1831a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart else 1832a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; 1833a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (i % 2) { 1834a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart wwn[i/2] = j & 0xff; 1835a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart j = 0; 1836a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 1837a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 1838a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1839a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart *nm = wwn_to_u64(wwn); 1840a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1841a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return 0; 1842a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1843a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1844a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1845a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 1846a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * "Short-cut" sysfs variable to create a new vport on a FC Host. 1847a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Input is a string of the form "<WWPN>:<WWNN>". Other attributes 1848a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * will default to a NPIV-based FCP_Initiator; The WWNs are specified 1849a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * as hex characters, and may *not* contain any prefixes (e.g. 0x, x, etc) 1850a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 1851a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t 1852ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_host_vport_create(struct device *dev, struct device_attribute *attr, 1853ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) 1854a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1855ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 1856a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport_identifiers vid; 1857a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport; 1858a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned int cnt=count; 1859a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int stat; 1860a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1861a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart memset(&vid, 0, sizeof(vid)); 1862a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1863a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* count may include a LF at end of string */ 1864a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (buf[cnt-1] == '\n') 1865a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart cnt--; 1866a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1867a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* validate we have enough characters for WWPN */ 1868a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if ((cnt != (16+1+16)) || (buf[16] != ':')) 1869a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; 1870a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1871a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = fc_parse_wwn(&buf[0], &vid.port_name); 1872a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (stat) 1873a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat; 1874a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1875a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = fc_parse_wwn(&buf[17], &vid.node_name); 1876a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (stat) 1877a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat; 1878a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1879a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vid.roles = FC_PORT_ROLE_FCP_INITIATOR; 1880a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vid.vport_type = FC_PORTTYPE_NPIV; 1881a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* vid.symbolic_name is already zero/NULL's */ 1882a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vid.disable = false; /* always enabled */ 1883a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1884a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* we only allow support on Channel 0 !!! */ 1885a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez stat = fc_vport_setup(shost, 0, &shost->shost_gendev, &vid, &vport); 1886a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat ? stat : count; 1887a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1888ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, vport_create, S_IWUSR, NULL, 1889a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart store_fc_host_vport_create); 1890a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1891a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1892a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/* 1893a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * "Short-cut" sysfs variable to delete a vport on a FC Host. 1894a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Vport is identified by a string containing "<WWPN>:<WWNN>". 1895a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * The WWNs are specified as hex characters, and may *not* contain 1896a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * any prefixes (e.g. 0x, x, etc) 1897a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 1898a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic ssize_t 1899ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstore_fc_host_vport_delete(struct device *dev, struct device_attribute *attr, 1900ee959b00c335d7780136c5abda37809191fe52c3Tony Jones const char *buf, size_t count) 1901a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 1902ee959b00c335d7780136c5abda37809191fe52c3Tony Jones struct Scsi_Host *shost = transport_class_to_shost(dev); 1903a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 1904a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport; 1905a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart u64 wwpn, wwnn; 1906a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned long flags; 1907a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned int cnt=count; 1908a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int stat, match; 1909a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1910a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* count may include a LF at end of string */ 1911a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (buf[cnt-1] == '\n') 1912a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart cnt--; 1913a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1914a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* validate we have enough characters for WWPN */ 1915a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if ((cnt != (16+1+16)) || (buf[16] != ':')) 1916a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -EINVAL; 1917a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1918a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = fc_parse_wwn(&buf[0], &wwpn); 1919a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (stat) 1920a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat; 1921a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1922a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = fc_parse_wwn(&buf[17], &wwnn); 1923a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (stat) 1924a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat; 1925a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1926a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 1927a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart match = 0; 1928a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* we only allow support on Channel 0 !!! */ 1929a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart list_for_each_entry(vport, &fc_host->vports, peers) { 1930a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if ((vport->channel == 0) && 1931a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart (vport->port_name == wwpn) && (vport->node_name == wwnn)) { 19320d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) 19330d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen break; 19340d9dc7c8b9b7fa0f53647423b41056ee1beed735Gal Rosen vport->flags |= FC_VPORT_DELETING; 1935a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart match = 1; 1936a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart break; 1937a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 1938a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 1939a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 1940a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1941a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!match) 1942a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -ENODEV; 1943a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1944a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = fc_vport_terminate(vport); 1945a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat ? stat : count; 1946a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 1947ee959b00c335d7780136c5abda37809191fe52c3Tony Jonesstatic FC_DEVICE_ATTR(host, vport_delete, S_IWUSR, NULL, 1948a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart store_fc_host_vport_delete); 1949a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 1950a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 19511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_host_match(struct attribute_container *cont, 19521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 19531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 19541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 19551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 19561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_host_device(dev)) 19581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 19591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev); 19611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 19621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 19631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 19641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 19661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t.host_attrs.ac == cont; 19681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_target_match(struct attribute_container *cont, 19711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 19721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 19731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 19741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 19751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_target_device(dev)) 19771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 19781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev->parent); 19801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 19811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 19821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 19831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 19851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t.target_attrs.ac == cont; 19871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void fc_rport_dev_release(struct device *dev) 19901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 19911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = dev_to_rport(dev); 19921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds put_device(dev->parent); 19931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(rport); 19941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 19951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint scsi_is_fc_rport(const struct device *dev) 19971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 19981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return dev->release == fc_rport_dev_release; 19991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 20001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(scsi_is_fc_rport); 20011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_rport_match(struct attribute_container *cont, 20031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 20041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 20051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 20061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 20071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_fc_rport(dev)) 20091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 20101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev->parent); 20121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 20131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 20141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 20151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 20171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->rport_attr_cont.ac == cont; 20191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 20201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20215c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 2022a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic void fc_vport_dev_release(struct device *dev) 2023a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 2024a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport = dev_to_vport(dev); 2025a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart put_device(dev->parent); /* release kobj parent */ 2026a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart kfree(vport); 2027a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 2028a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2029a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartint scsi_is_fc_vport(const struct device *dev) 2030a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 2031a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return dev->release == fc_vport_dev_release; 2032a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 2033a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James SmartEXPORT_SYMBOL(scsi_is_fc_vport); 2034a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2035a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic int fc_vport_match(struct attribute_container *cont, 2036a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct device *dev) 2037a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 2038a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport; 2039a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost; 2040a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i; 2041a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2042a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!scsi_is_fc_vport(dev)) 2043a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return 0; 2044a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport = dev_to_vport(dev); 2045a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2046a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart shost = vport_to_shost(vport); 2047a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!shost->transportt || shost->transportt->host_attrs.ac.class 2048a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart != &fc_host_class.class) 2049a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return 0; 2050a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2051a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i = to_fc_internal(shost->transportt); 2052a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return &i->vport_attr_cont.ac == cont; 2053a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 2054a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2055a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2056c829c394165f981d49f05a9be228404d7a9398d4James Smart/** 2057c829c394165f981d49f05a9be228404d7a9398d4James Smart * fc_timed_out - FC Transport I/O timeout intercept handler 2058c829c394165f981d49f05a9be228404d7a9398d4James Smart * @scmd: The SCSI command which timed out 2059c829c394165f981d49f05a9be228404d7a9398d4James Smart * 2060c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine protects against error handlers getting invoked while a 2061c829c394165f981d49f05a9be228404d7a9398d4James Smart * rport is in a blocked state, typically due to a temporarily loss of 2062c829c394165f981d49f05a9be228404d7a9398d4James Smart * connectivity. If the error handlers are allowed to proceed, requests 2063c829c394165f981d49f05a9be228404d7a9398d4James Smart * to abort i/o, reset the target, etc will likely fail as there is no way 2064c829c394165f981d49f05a9be228404d7a9398d4James Smart * to communicate with the device to perform the requested function. These 2065c829c394165f981d49f05a9be228404d7a9398d4James Smart * failures may result in the midlayer taking the device offline, requiring 2066c829c394165f981d49f05a9be228404d7a9398d4James Smart * manual intervention to restore operation. 2067c829c394165f981d49f05a9be228404d7a9398d4James Smart * 2068c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine, called whenever an i/o times out, validates the state of 2069c829c394165f981d49f05a9be228404d7a9398d4James Smart * the underlying rport. If the rport is blocked, it returns 2070c829c394165f981d49f05a9be228404d7a9398d4James Smart * EH_RESET_TIMER, which will continue to reschedule the timeout. 2071c829c394165f981d49f05a9be228404d7a9398d4James Smart * Eventually, either the device will return, or devloss_tmo will fire, 2072c829c394165f981d49f05a9be228404d7a9398d4James Smart * and when the timeout then fires, it will be handled normally. 2073c829c394165f981d49f05a9be228404d7a9398d4James Smart * If the rport is not blocked, normal error handling continues. 2074c829c394165f981d49f05a9be228404d7a9398d4James Smart * 2075c829c394165f981d49f05a9be228404d7a9398d4James Smart * Notes: 2076c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine assumes no locks are held on entry. 2077eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2078242f9dcb8ba6f68fcd217a119a7648a4f69290e9Jens Axboestatic enum blk_eh_timer_return 2079c829c394165f981d49f05a9be228404d7a9398d4James Smartfc_timed_out(struct scsi_cmnd *scmd) 2080c829c394165f981d49f05a9be228404d7a9398d4James Smart{ 2081c829c394165f981d49f05a9be228404d7a9398d4James Smart struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); 2082c829c394165f981d49f05a9be228404d7a9398d4James Smart 2083c829c394165f981d49f05a9be228404d7a9398d4James Smart if (rport->port_state == FC_PORTSTATE_BLOCKED) 2084242f9dcb8ba6f68fcd217a119a7648a4f69290e9Jens Axboe return BLK_EH_RESET_TIMER; 2085c829c394165f981d49f05a9be228404d7a9398d4James Smart 2086242f9dcb8ba6f68fcd217a119a7648a4f69290e9Jens Axboe return BLK_EH_NOT_HANDLED; 2087c829c394165f981d49f05a9be228404d7a9398d4James Smart} 2088c829c394165f981d49f05a9be228404d7a9398d4James Smart 20895c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com/* 2090bda232531f0c117921690ee3c060953c8f12e5a1James Smart * Called by fc_user_scan to locate an rport on the shost that 2091bda232531f0c117921690ee3c060953c8f12e5a1James Smart * matches the channel and target id, and invoke scsi_scan_target() 2092bda232531f0c117921690ee3c060953c8f12e5a1James Smart * on the rport. 20935c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com */ 2094bda232531f0c117921690ee3c060953c8f12e5a1James Smartstatic void 20959cb78c16f5dadefd8dc5ba0ae5a2f26cd59419b3Hannes Reineckefc_user_scan_tgt(struct Scsi_Host *shost, uint channel, uint id, u64 lun) 20965c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com{ 20975c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com struct fc_rport *rport; 2098bda232531f0c117921690ee3c060953c8f12e5a1James Smart unsigned long flags; 2099bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2100bda232531f0c117921690ee3c060953c8f12e5a1James Smart spin_lock_irqsave(shost->host_lock, flags); 21015c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 2102e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig list_for_each_entry(rport, &fc_host_rports(shost), peers) { 2103e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig if (rport->scsi_target_id == -1) 2104e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig continue; 21055c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 21060d2fcd9f9858a34f7056b3b1cb60ce0f883d06b6Hannes Reinecke if (rport->port_state != FC_PORTSTATE_ONLINE) 21070d2fcd9f9858a34f7056b3b1cb60ce0f883d06b6Hannes Reinecke continue; 21080d2fcd9f9858a34f7056b3b1cb60ce0f883d06b6Hannes Reinecke 2109bda232531f0c117921690ee3c060953c8f12e5a1James Smart if ((channel == rport->channel) && 2110bda232531f0c117921690ee3c060953c8f12e5a1James Smart (id == rport->scsi_target_id)) { 2111bda232531f0c117921690ee3c060953c8f12e5a1James Smart spin_unlock_irqrestore(shost->host_lock, flags); 2112bda232531f0c117921690ee3c060953c8f12e5a1James Smart scsi_scan_target(&rport->dev, channel, id, lun, 1); 2113bda232531f0c117921690ee3c060953c8f12e5a1James Smart return; 2114e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig } 2115e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig } 2116e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig 2117bda232531f0c117921690ee3c060953c8f12e5a1James Smart spin_unlock_irqrestore(shost->host_lock, flags); 2118bda232531f0c117921690ee3c060953c8f12e5a1James Smart} 2119bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2120bda232531f0c117921690ee3c060953c8f12e5a1James Smart/* 2121bda232531f0c117921690ee3c060953c8f12e5a1James Smart * Called via sysfs scan routines. Necessary, as the FC transport 2122bda232531f0c117921690ee3c060953c8f12e5a1James Smart * wants to place all target objects below the rport object. So this 2123bda232531f0c117921690ee3c060953c8f12e5a1James Smart * routine must invoke the scsi_scan_target() routine with the rport 2124bda232531f0c117921690ee3c060953c8f12e5a1James Smart * object as the parent. 2125bda232531f0c117921690ee3c060953c8f12e5a1James Smart */ 2126bda232531f0c117921690ee3c060953c8f12e5a1James Smartstatic int 21279cb78c16f5dadefd8dc5ba0ae5a2f26cd59419b3Hannes Reineckefc_user_scan(struct Scsi_Host *shost, uint channel, uint id, u64 lun) 2128bda232531f0c117921690ee3c060953c8f12e5a1James Smart{ 2129bda232531f0c117921690ee3c060953c8f12e5a1James Smart uint chlo, chhi; 2130bda232531f0c117921690ee3c060953c8f12e5a1James Smart uint tgtlo, tgthi; 2131bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2132bda232531f0c117921690ee3c060953c8f12e5a1James Smart if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || 2133bda232531f0c117921690ee3c060953c8f12e5a1James Smart ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || 2134bda232531f0c117921690ee3c060953c8f12e5a1James Smart ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) 2135bda232531f0c117921690ee3c060953c8f12e5a1James Smart return -EINVAL; 2136bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2137bda232531f0c117921690ee3c060953c8f12e5a1James Smart if (channel == SCAN_WILD_CARD) { 2138bda232531f0c117921690ee3c060953c8f12e5a1James Smart chlo = 0; 2139bda232531f0c117921690ee3c060953c8f12e5a1James Smart chhi = shost->max_channel + 1; 2140bda232531f0c117921690ee3c060953c8f12e5a1James Smart } else { 2141bda232531f0c117921690ee3c060953c8f12e5a1James Smart chlo = channel; 2142bda232531f0c117921690ee3c060953c8f12e5a1James Smart chhi = channel + 1; 2143bda232531f0c117921690ee3c060953c8f12e5a1James Smart } 2144bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2145bda232531f0c117921690ee3c060953c8f12e5a1James Smart if (id == SCAN_WILD_CARD) { 2146bda232531f0c117921690ee3c060953c8f12e5a1James Smart tgtlo = 0; 2147bda232531f0c117921690ee3c060953c8f12e5a1James Smart tgthi = shost->max_id; 2148bda232531f0c117921690ee3c060953c8f12e5a1James Smart } else { 2149bda232531f0c117921690ee3c060953c8f12e5a1James Smart tgtlo = id; 2150bda232531f0c117921690ee3c060953c8f12e5a1James Smart tgthi = id + 1; 2151bda232531f0c117921690ee3c060953c8f12e5a1James Smart } 2152bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2153bda232531f0c117921690ee3c060953c8f12e5a1James Smart for ( ; chlo < chhi; chlo++) 2154bda232531f0c117921690ee3c060953c8f12e5a1James Smart for ( ; tgtlo < tgthi; tgtlo++) 2155bda232531f0c117921690ee3c060953c8f12e5a1James Smart fc_user_scan_tgt(shost, chlo, tgtlo, lun); 2156bda232531f0c117921690ee3c060953c8f12e5a1James Smart 2157e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig return 0; 21585c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com} 21595c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 21607525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonoristatic int fc_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id, 21617525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori int result) 21627525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori{ 21637525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori struct fc_internal *i = to_fc_internal(shost->transportt); 21647525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori return i->f->tsk_mgmt_response(shost, nexus, tm_id, result); 21657525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori} 21667525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori 21677525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonoristatic int fc_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result) 21687525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori{ 21697525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori struct fc_internal *i = to_fc_internal(shost->transportt); 21707525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori return i->f->it_nexus_response(shost, nexus, result); 21717525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori} 21727525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori 21731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct scsi_transport_template * 21741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_attach_transport(struct fc_function_template *ft) 21751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 21761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int count; 217724669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen struct fc_internal *i = kzalloc(sizeof(struct fc_internal), 217824669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen GFP_KERNEL); 21791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(!i)) 21811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 21821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.attrs = &i->starget_attrs[0]; 21841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.class = &fc_transport_class.class; 21851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.match = fc_target_match; 21861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_size = sizeof(struct fc_starget_attrs); 21871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->t.target_attrs); 21881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.attrs = &i->host_attrs[0]; 21901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.class = &fc_host_class.class; 21911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.match = fc_host_match; 21921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_size = sizeof(struct fc_host_attrs); 21931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ft->get_fc_host_stats) 21941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.statistics = &fc_statistics_group; 21951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->t.host_attrs); 21961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.attrs = &i->rport_attrs[0]; 21981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.class = &fc_rport_class.class; 21991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.match = fc_rport_match; 22001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->rport_attr_cont); 22011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2202a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attr_cont.ac.attrs = &i->vport_attrs[0]; 2203a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attr_cont.ac.class = &fc_vport_class.class; 2204a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attr_cont.ac.match = fc_vport_match; 2205a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_container_register(&i->vport_attr_cont); 2206a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 22071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f = ft; 22081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Transport uses the shost workq for scsi scanning */ 22101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.create_work_queue = 1; 22115c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 2212c829c394165f981d49f05a9be228404d7a9398d4James Smart i->t.eh_timed_out = fc_timed_out; 2213c829c394165f981d49f05a9be228404d7a9398d4James Smart 2214e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig i->t.user_scan = fc_user_scan; 22159ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart 22167525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori /* target-mode drivers' functions */ 22177525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori i->t.tsk_mgmt_response = fc_tsk_mgmt_response; 22187525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori i->t.it_nexus_response = fc_it_nexus_response; 22197525236d0bc7ad17eb5e0733417896cab745d6c8FUJITA Tomonori 22201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 22211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup SCSI Target Attributes. 22221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 22231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count = 0; 22241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(node_name); 22251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(port_name); 22261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(port_id); 22271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_STARGET_NUM_ATTRS); 22291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = NULL; 22311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 22341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup SCSI Host Attributes. 22351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 22361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count=0; 22371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(node_name); 22381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_name); 22396b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmann SETUP_HOST_ATTRIBUTE_RD(permanent_port_name); 22401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_classes); 22411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_fc4s); 22421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_speeds); 22431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(maxframe_size); 2244a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (ft->vport_create) { 2245a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_HOST_ATTRIBUTE_RD_NS(max_npiv_vports); 2246a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_HOST_ATTRIBUTE_RD_NS(npiv_vports_inuse); 2247a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 22481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(serial_number); 2249bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(manufacturer); 2250bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(model); 2251bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(model_description); 2252bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(hardware_version); 2253bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(driver_version); 2254bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(firmware_version); 2255bb8ef587a715c6a084f80b9c311136aa765ebfadNeerav Parikh SETUP_HOST_ATTRIBUTE_RD(optionrom_version); 22561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_id); 22581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_type); 22591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_state); 22601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(active_fc4s); 22611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(speed); 22621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(fabric_name); 2263016131b8fffa1085b4ad165ab228116fdc278ebeJames Smart SETUP_HOST_ATTRIBUTE_RD(symbolic_name); 2264b8d08210126a7b769b857720a59721a453a57a1eJames Smart SETUP_HOST_ATTRIBUTE_RW(system_hostname); 22651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Transport-managed attributes */ 226743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie SETUP_PRIVATE_HOST_ATTRIBUTE_RW(dev_loss_tmo); 22681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type); 226991ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez if (ft->issue_fc_host_lip) 227091ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip); 2271a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (ft->vport_create) 2272a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_create); 2273a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (ft->vport_delete) 2274a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_delete); 22751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_HOST_NUM_ATTRS); 22771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = NULL; 22791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 22811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup Remote Port Attributes. 22821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 22831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count=0; 22841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RD(maxframe_size); 22851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RD(supported_classes); 22861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo); 22871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name); 22881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name); 22891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id); 22901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles); 22911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state); 22921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id); 2293fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo); 22941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_RPORT_NUM_ATTRS); 22961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = NULL; 22981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2299a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* 2300a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Setup Virtual Port Attributes. 2301a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 2302a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart count=0; 2303a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_state); 2304a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_last_state); 2305a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(node_name); 2306a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(port_name); 2307a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(roles); 2308a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_type); 2309a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_VPORT_ATTRIBUTE_RW(symbolic_name); 2310a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_VPORT_ATTRIBUTE_WR(vport_delete); 2311a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart SETUP_VPORT_ATTRIBUTE_WR(vport_disable); 2312a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2313a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart BUG_ON(count > FC_VPORT_NUM_ATTRS); 2314a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2315a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart i->vport_attrs[count] = NULL; 2316a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 23171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t; 23181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 23191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_attach_transport); 23201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 23211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid fc_release_transport(struct scsi_transport_template *t) 23221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 23231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(t); 23241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 23251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->t.target_attrs); 23261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->t.host_attrs); 23271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->rport_attr_cont); 2328a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_container_unregister(&i->vport_attr_cont); 23291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 23301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(i); 23311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 23321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_release_transport); 23331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2334aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 2335aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_queue_work - Queue work to the fc_host workqueue. 2336aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 2337aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @work: Work to queue for execution. 2338aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 2339aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * Return value: 2340a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * 1 - work queued for execution 2341a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * 0 - work is already queued 2342a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * -EINVAL - work queue doesn't exist 2343eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2344aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int 2345aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_queue_work(struct Scsi_Host *shost, struct work_struct *work) 2346aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 2347aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (unlikely(!fc_host_work_q(shost))) { 2348aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 2349aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to queue work, " 2350aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 2351aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 2352aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2353aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -EINVAL; 2354aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2355aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2356aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return queue_work(fc_host_work_q(shost), work); 2357aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 2358aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2359aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 2360aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_flush_work - Flush a fc_host's workqueue. 2361aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 2362eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2363aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 2364aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_flush_work(struct Scsi_Host *shost) 2365aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 2366aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host_work_q(shost)) { 2367aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 2368aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to flush work, " 2369aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 2370aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 2371aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return; 2372aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2373aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2374aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart flush_workqueue(fc_host_work_q(shost)); 2375aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 2376aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2377aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 2378aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue. 2379aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 2380aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @work: Work to queue for execution. 2381aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @delay: jiffies to delay the work queuing 2382aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 2383aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * Return value: 23840f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart * 1 on success / 0 already queued / < 0 for error 2385eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2386aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int 2387c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_queue_devloss_work(struct Scsi_Host *shost, struct delayed_work *work, 2388aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart unsigned long delay) 2389aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 2390aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (unlikely(!fc_host_devloss_work_q(shost))) { 2391aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 2392aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to queue work, " 2393aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 2394aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 2395aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2396aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -EINVAL; 2397aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2398aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2399aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay); 2400aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 2401aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2402aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 2403aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_flush_devloss - Flush a fc_host's devloss workqueue. 2404aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 2405eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2406aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 2407aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_flush_devloss(struct Scsi_Host *shost) 2408aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 2409aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host_devloss_work_q(shost)) { 2410aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 2411aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to flush work, " 2412aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 2413aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 2414aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return; 2415aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2416aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2417aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart flush_workqueue(fc_host_devloss_work_q(shost)); 2418aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 2419aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 24201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2422eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host. 2423eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * @shost: Which &Scsi_Host 24241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 242525985edcedea6396277003854657b5f3cb31a628Lucas De Marchi * This routine is expected to be called immediately preceding the 24261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a driver's call to scsi_remove_host(). 24271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 24281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * WARNING: A driver utilizing the fc_transport, which fails to call 2429eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * this routine prior to scsi_remove_host(), will leave dangling 24301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * objects in /sys/class/fc_remote_ports. Access to any of these 24311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * objects can result in a system crash !!! 24321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 24331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 24341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 2435eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 24361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 24371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remove_host(struct Scsi_Host *shost) 24381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2439a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport = NULL, *next_vport = NULL; 2440a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_rport *rport = NULL, *next_rport = NULL; 2441aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct workqueue_struct *work_q; 2442aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 2443a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned long flags; 2444a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2445a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 2446a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2447a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* Remove any vports */ 24489ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers) 24499ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart fc_queue_work(shost, &vport->vport_delete_work); 24501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Remove any remote ports */ 24521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_for_each_entry_safe(rport, next_rport, 2453aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart &fc_host->rports, peers) { 2454aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 2455aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 2456aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 2457aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2458aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 24591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_for_each_entry_safe(rport, next_rport, 2460aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart &fc_host->rport_bindings, peers) { 2461aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 2462aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 2463aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 2464aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2465aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2466a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 2467a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 2468aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all scan work items */ 2469aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_flush_work(shost); 2470aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2471aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all stgt delete, and rport delete work items, then kill it */ 2472aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->work_q) { 2473aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart work_q = fc_host->work_q; 2474aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q = NULL; 2475aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(work_q); 2476aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 2477aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2478aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all devloss work items, then kill it */ 2479aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->devloss_work_q) { 2480aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart work_q = fc_host->devloss_work_q; 2481aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->devloss_work_q = NULL; 2482aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(work_q); 2483aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 24841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 24851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remove_host); 24861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2487fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christiestatic void fc_terminate_rport_io(struct fc_rport *rport) 2488fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie{ 2489fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie struct Scsi_Host *shost = rport_to_shost(rport); 2490fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie struct fc_internal *i = to_fc_internal(shost->transportt); 2491fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie 2492fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie /* Involve the LLDD if possible to terminate all io on the rport. */ 2493fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie if (i->f->terminate_rport_io) 2494fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie i->f->terminate_rport_io(rport); 2495fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie 2496fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie /* 24975d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie * Must unblock to flush queued IO. scsi-ml will fail incoming reqs. 2498fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie */ 24995d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); 2500fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie} 2501aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2502aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 250325985edcedea6396277003854657b5f3cb31a628Lucas De Marchi * fc_starget_delete - called to delete the scsi descendants of an rport 2504c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells * @work: remote port to be operated on. 2505eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * 2506eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * Deletes target and all sdevs. 2507eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 250819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstatic void 2509c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_starget_delete(struct work_struct *work) 251019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com{ 2511c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct fc_rport *rport = 2512c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct fc_rport, stgt_delete_work); 251319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2514fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie fc_terminate_rport_io(rport); 251519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com scsi_remove_target(&rport->dev); 251619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com} 251719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2518aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2519aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 2520aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_rport_final_delete - finish rport termination and delete it. 2521c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells * @work: remote port to be deleted. 2522eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 2523aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 2524c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_rport_final_delete(struct work_struct *work) 2525aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 2526c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct fc_rport *rport = 2527c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct fc_rport, rport_delete_work); 2528aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct device *dev = &rport->dev; 2529aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 25300f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 253192740b24ce6ddac6534fae985aab602548692186James Smart unsigned long flags; 25328798a694da59486e4a3ff0abeec183202fb34c20Michael Reed int do_callback = 0; 2533aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2534112f661d6dac9af1235d2d05299fc2c9cb876ae7Nithin Nayak Sujir fc_terminate_rport_io(rport); 2535112f661d6dac9af1235d2d05299fc2c9cb876ae7Nithin Nayak Sujir 2536aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* 25379ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart * if a scan is pending, flush the SCSI Host work_q so that 2538aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * that we can reclaim the rport scan work element. 2539aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart */ 2540aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->flags & FC_RPORT_SCAN_PENDING) 2541aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_flush_work(shost); 2542aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 254392740b24ce6ddac6534fae985aab602548692186James Smart /* 254492740b24ce6ddac6534fae985aab602548692186James Smart * Cancel any outstanding timers. These should really exist 254592740b24ce6ddac6534fae985aab602548692186James Smart * only when rmmod'ing the LLDD and we're asking for 254692740b24ce6ddac6534fae985aab602548692186James Smart * immediate termination of the rports 254792740b24ce6ddac6534fae985aab602548692186James Smart */ 254892740b24ce6ddac6534fae985aab602548692186James Smart spin_lock_irqsave(shost->host_lock, flags); 254992740b24ce6ddac6534fae985aab602548692186James Smart if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { 255092740b24ce6ddac6534fae985aab602548692186James Smart spin_unlock_irqrestore(shost->host_lock, flags); 255192740b24ce6ddac6534fae985aab602548692186James Smart if (!cancel_delayed_work(&rport->fail_io_work)) 255292740b24ce6ddac6534fae985aab602548692186James Smart fc_flush_devloss(shost); 255392740b24ce6ddac6534fae985aab602548692186James Smart if (!cancel_delayed_work(&rport->dev_loss_work)) 255492740b24ce6ddac6534fae985aab602548692186James Smart fc_flush_devloss(shost); 25550353e085edb0f11e040cf91e71d831ec07943b20Neil Horman cancel_work_sync(&rport->scan_work); 255692740b24ce6ddac6534fae985aab602548692186James Smart spin_lock_irqsave(shost->host_lock, flags); 255792740b24ce6ddac6534fae985aab602548692186James Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 255892740b24ce6ddac6534fae985aab602548692186James Smart } 255992740b24ce6ddac6534fae985aab602548692186James Smart spin_unlock_irqrestore(shost->host_lock, flags); 256092740b24ce6ddac6534fae985aab602548692186James Smart 25610f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart /* Delete SCSI target and sdevs */ 25620f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (rport->scsi_target_id != -1) 2563c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells fc_starget_delete(&rport->stgt_delete_work); 256492740b24ce6ddac6534fae985aab602548692186James Smart 256592740b24ce6ddac6534fae985aab602548692186James Smart /* 256692740b24ce6ddac6534fae985aab602548692186James Smart * Notify the driver that the rport is now dead. The LLDD will 256792740b24ce6ddac6534fae985aab602548692186James Smart * also guarantee that any communication to the rport is terminated 25684be98c0ca304c8a47998b29a7993664f71791250James Smart * 25694be98c0ca304c8a47998b29a7993664f71791250James Smart * Avoid this call if we already called it when we preserved the 25704be98c0ca304c8a47998b29a7993664f71791250James Smart * rport for the binding. 257192740b24ce6ddac6534fae985aab602548692186James Smart */ 25728798a694da59486e4a3ff0abeec183202fb34c20Michael Reed spin_lock_irqsave(shost->host_lock, flags); 25734be98c0ca304c8a47998b29a7993664f71791250James Smart if (!(rport->flags & FC_RPORT_DEVLOSS_CALLBK_DONE) && 25748798a694da59486e4a3ff0abeec183202fb34c20Michael Reed (i->f->dev_loss_tmo_callbk)) { 25758798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; 25768798a694da59486e4a3ff0abeec183202fb34c20Michael Reed do_callback = 1; 25778798a694da59486e4a3ff0abeec183202fb34c20Michael Reed } 25788798a694da59486e4a3ff0abeec183202fb34c20Michael Reed spin_unlock_irqrestore(shost->host_lock, flags); 25798798a694da59486e4a3ff0abeec183202fb34c20Michael Reed 25808798a694da59486e4a3ff0abeec183202fb34c20Michael Reed if (do_callback) 25810f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart i->f->dev_loss_tmo_callbk(rport); 25820f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 25839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_remove(rport->rqst_q); 25849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 2585aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart transport_remove_device(dev); 2586aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart device_del(dev); 2587aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart transport_destroy_device(dev); 25883bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(&shost->shost_gendev); /* for fc_host->rport list */ 25893bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(dev); /* for self-reference */ 2590aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 2591aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2592aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 25931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 25941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_rport_create - allocates and creates a remote FC port. 25951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @shost: scsi host the remote port is connected to. 25961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @channel: Channel on shost port connected to. 25971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @ids: The world wide names, fc address, and FC4 port 25981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * roles for the remote port. 25991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 26001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Allocates and creates the remoter port structure, including the 26011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * class and sysfs creation. 26021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 26031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 26041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 2605eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 260644818efbad185eea75adad0e8cab97650a7370abAdrian Bunkstatic struct fc_rport * 26071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_rport_create(struct Scsi_Host *shost, int channel, 26081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport_identifiers *ids) 26091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2610aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 26111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *fci = to_fc_internal(shost->transportt); 26121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport; 26131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev; 26141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 26151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int error; 26161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t size; 26171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size); 261924669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen rport = kzalloc(size, GFP_KERNEL); 26201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(!rport)) { 2621cadbd4a5e36dde7e6c49b587b2c419103c0b7218Harvey Harrison printk(KERN_ERR "%s: allocation failure\n", __func__); 26221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 26231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 26241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->maxframe_size = -1; 26261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->supported_classes = FC_COS_UNSPECIFIED; 262743ca910a9c90566308f39f51ac03a55f94a5f83cMike Christie rport->dev_loss_tmo = fc_host->dev_loss_tmo; 26281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name)); 26291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name)); 26301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_id = ids->port_id; 26311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->roles = ids->roles; 26321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_state = FC_PORTSTATE_ONLINE; 26331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fci->f->dd_fcrport_size) 26341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->dd_data = &rport[1]; 26351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->channel = channel; 26360f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart rport->fast_io_fail_tmo = -1; 26371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2638c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport); 2639c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io); 2640c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&rport->scan_work, fc_scsi_scan_rport); 2641c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&rport->stgt_delete_work, fc_starget_delete); 2642c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete); 26431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 26451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->number = fc_host->next_rport_number++; 2647a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (rport->roles & FC_PORT_ROLE_FCP_TARGET) 26481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->scsi_target_id = fc_host->next_target_id++; 26491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 26501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->scsi_target_id = -1; 2651aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_add_tail(&rport->peers, &fc_host->rports); 26523bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart get_device(&shost->shost_gendev); /* for fc_host->rport list */ 26531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 26551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev = &rport->dev; 26573bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart device_initialize(dev); /* takes self reference */ 26583bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart dev->parent = get_device(&shost->shost_gendev); /* parent reference */ 26591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->release = fc_rport_dev_release; 266071610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers dev_set_name(dev, "rport-%d:%d-%d", 266171610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers shost->host_no, channel, rport->number); 26621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_setup_device(dev); 26631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds error = device_add(dev); 26651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) { 26661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "FC Remote Port device_add failed\n"); 26671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto delete_rport; 26681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 26691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_add_device(dev); 26701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_configure_device(dev); 26711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_rportadd(shost, rport); 26739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* ignore any bsg add error - we just can't do sgio */ 26749e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 2675a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (rport->roles & FC_PORT_ROLE_FCP_TARGET) { 26761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 2677aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 26781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 2679aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 26801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 26821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdelete_rport: 26841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_destroy_device(dev); 26851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 26861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_del(&rport->peers); 26873bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(&shost->shost_gendev); /* for fc_host->rport list */ 26881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 26891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds put_device(dev->parent); 26901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(rport); 26911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 26921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 26931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 26941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2695eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_remote_port_add - notify fc transport of the existence of a remote FC port. 26961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @shost: scsi host the remote port is connected to. 26971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @channel: Channel on shost port connected to. 26981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @ids: The world wide names, fc address, and FC4 port 26991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * roles for the remote port. 27001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The LLDD calls this routine to notify the transport of the existence 27021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn) 27031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of the port, it's FC address (port_id), and the FC4 roles that are 27041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * active for the port. 27051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For ports that are FCP targets (aka scsi targets), the FC transport 27071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * maintains consistent target id bindings on behalf of the LLDD. 27081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A consistent target id binding is an assignment of a target id to 27091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a remote port identifier, which persists while the scsi host is 27101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * attached. The remote port can disappear, then later reappear, and 27111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it's target id assignment remains the same. This allows for shifts 27121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in FC addressing (if binding by wwpn or wwnn) with no apparent 27131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * changes to the scsi subsystem which is based on scsi host number and 27141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * target id values. Bindings are only valid during the attachment of 27151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the scsi host. If the host detaches, then later re-attaches, target 27161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * id bindings may change. 27171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine is responsible for returning a remote port structure. 27191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The routine will search the list of remote ports it maintains 27201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * internally on behalf of consistent target id mappings. If found, the 27211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * remote port structure will be reused. Otherwise, a new remote port 27221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * structure will be allocated. 27231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Whenever a remote port is allocated, a new fc_remote_port class 27251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * device is created. 27261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Should not be called from interrupt context. 27281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 27291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 27301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 2731eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 27321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct fc_rport * 27331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_add(struct Scsi_Host *shost, int channel, 27341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport_identifiers *ids) 27351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 273619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct fc_internal *fci = to_fc_internal(shost->transportt); 2737aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 27381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport; 27391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 27401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int match = 0; 27411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2742aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* ensure any stgt delete functions are done */ 2743aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_work(shost); 2744aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 274519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 274619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Search the list of "active" rports, for an rport that has been 274719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * deleted, but we've held off the real delete while the target 274819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * is in a "blocked" state. 274919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 275019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_lock_irqsave(shost->host_lock, flags); 275119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2752aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_for_each_entry(rport, &fc_host->rports, peers) { 275319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 275419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) && 275519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->channel == channel)) { 275619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2757aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart switch (fc_host->tgtid_bind_type) { 275819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWPN: 275919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_NONE: 276019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_name == ids->port_name) 276119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 276219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 276319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWNN: 276419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->node_name == ids->node_name) 276519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 276619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 276719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_ID: 276819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_id == ids->port_id) 276919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 277019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 277119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 277219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 277319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (match) { 277419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 277519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memcpy(&rport->node_name, &ids->node_name, 277619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com sizeof(rport->node_name)); 277719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memcpy(&rport->port_name, &ids->port_name, 277819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com sizeof(rport->port_name)); 277919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_id = ids->port_id; 278019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 278119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_state = FC_PORTSTATE_ONLINE; 278219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->roles = ids->roles; 278319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 278419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 278519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 278619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (fci->f->dd_fcrport_size) 278719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memset(rport->dd_data, 0, 278819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com fci->f->dd_fcrport_size); 278919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 279019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 279192740b24ce6ddac6534fae985aab602548692186James Smart * If we were not a target, cancel the 279292740b24ce6ddac6534fae985aab602548692186James Smart * io terminate and rport timers, and 279392740b24ce6ddac6534fae985aab602548692186James Smart * we're done. 279492740b24ce6ddac6534fae985aab602548692186James Smart * 279592740b24ce6ddac6534fae985aab602548692186James Smart * If we were a target, but our new role 279692740b24ce6ddac6534fae985aab602548692186James Smart * doesn't indicate a target, leave the 279792740b24ce6ddac6534fae985aab602548692186James Smart * timers running expecting the role to 279892740b24ce6ddac6534fae985aab602548692186James Smart * change as the target fully logs in. If 279992740b24ce6ddac6534fae985aab602548692186James Smart * it doesn't, the target will be torn down. 280092740b24ce6ddac6534fae985aab602548692186James Smart * 280192740b24ce6ddac6534fae985aab602548692186James Smart * If we were a target, and our role shows 280292740b24ce6ddac6534fae985aab602548692186James Smart * we're still a target, cancel the timers 280392740b24ce6ddac6534fae985aab602548692186James Smart * and kick off a scan. 280419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 280519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 280692740b24ce6ddac6534fae985aab602548692186James Smart /* was a target, not in roles */ 280792740b24ce6ddac6534fae985aab602548692186James Smart if ((rport->scsi_target_id != -1) && 2808a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart (!(ids->roles & FC_PORT_ROLE_FCP_TARGET))) 280992740b24ce6ddac6534fae985aab602548692186James Smart return rport; 281019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 281119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 281292740b24ce6ddac6534fae985aab602548692186James Smart * Stop the fail io and dev_loss timers. 281392740b24ce6ddac6534fae985aab602548692186James Smart * If they flush, the port_state will 281492740b24ce6ddac6534fae985aab602548692186James Smart * be checked and will NOOP the function. 281519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 28160f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (!cancel_delayed_work(&rport->fail_io_work)) 28170f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart fc_flush_devloss(shost); 281892740b24ce6ddac6534fae985aab602548692186James Smart if (!cancel_delayed_work(&rport->dev_loss_work)) 2819aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_devloss(shost); 2820aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2821aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 2822aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2823fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | 28244be98c0ca304c8a47998b29a7993664f71791250James Smart FC_RPORT_DEVLOSS_PENDING | 28254be98c0ca304c8a47998b29a7993664f71791250James Smart FC_RPORT_DEVLOSS_CALLBK_DONE); 282619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 28278fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie spin_unlock_irqrestore(shost->host_lock, flags); 28288fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie 282992740b24ce6ddac6534fae985aab602548692186James Smart /* if target, initiate a scan */ 283092740b24ce6ddac6534fae985aab602548692186James Smart if (rport->scsi_target_id != -1) { 28315d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie scsi_target_unblock(&rport->dev, 28325d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie SDEV_RUNNING); 28338fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie spin_lock_irqsave(shost->host_lock, 28348fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie flags); 283592740b24ce6ddac6534fae985aab602548692186James Smart rport->flags |= FC_RPORT_SCAN_PENDING; 283692740b24ce6ddac6534fae985aab602548692186James Smart scsi_queue_work(shost, 283792740b24ce6ddac6534fae985aab602548692186James Smart &rport->scan_work); 283892740b24ce6ddac6534fae985aab602548692186James Smart spin_unlock_irqrestore(shost->host_lock, 283992740b24ce6ddac6534fae985aab602548692186James Smart flags); 28408fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie } 2841a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart 28429e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_goose_queue(rport); 28439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 284419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return rport; 284519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 284619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 284719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 284819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 284992740b24ce6ddac6534fae985aab602548692186James Smart /* 285092740b24ce6ddac6534fae985aab602548692186James Smart * Search the bindings array 285192740b24ce6ddac6534fae985aab602548692186James Smart * Note: if never a FCP target, you won't be on this list 285292740b24ce6ddac6534fae985aab602548692186James Smart */ 2853aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { 28541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* search for a matching consistent binding */ 28561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2857aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_for_each_entry(rport, &fc_host->rport_bindings, 28581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds peers) { 28591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->channel != channel) 28601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 28611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2862aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart switch (fc_host->tgtid_bind_type) { 28631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_WWPN: 28641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->port_name == ids->port_name) 28651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 28661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 28671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_WWNN: 28681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->node_name == ids->node_name) 28691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 28701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 28711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_ID: 28721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->port_id == ids->port_id) 28731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 28741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 28751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_NONE: /* to keep compiler happy */ 28761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 28771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 28781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (match) { 2880aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_move_tail(&rport->peers, &fc_host->rports); 28811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 28821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 28831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 28841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 28851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (match) { 28861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->node_name, &ids->node_name, 28871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sizeof(rport->node_name)); 28881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->port_name, &ids->port_name, 28891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sizeof(rport->port_name)); 28901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_id = ids->port_id; 28911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->roles = ids->roles; 28921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_state = FC_PORTSTATE_ONLINE; 2893fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; 28941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 289519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (fci->f->dd_fcrport_size) 289619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memset(rport->dd_data, 0, 289719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com fci->f->dd_fcrport_size); 28988fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie spin_unlock_irqrestore(shost->host_lock, flags); 28998fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie 29008fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie if (ids->roles & FC_PORT_ROLE_FCP_TARGET) { 29015d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie scsi_target_unblock(&rport->dev, SDEV_RUNNING); 290219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 29031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 29048fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie spin_lock_irqsave(shost->host_lock, flags); 2905aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 29061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 2907a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 29088fb2ef89b696624ea9853868e370d2e132e76f54Mike Christie } 29091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 29101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 29111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 29121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 291319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 291419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 29151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* No consistent binding found - create new remote port entry */ 29161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport = fc_rport_create(shost, channel, ids); 29171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 29181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 29191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 29201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_add); 29211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 29221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 29231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2924eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_remote_port_delete - notifies the fc transport that a remote port is no longer in existence. 29251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @rport: The remote port that no longer exists 29261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 29271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The LLDD calls this routine to notify the transport that a remote 29281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * port is no longer part of the topology. Note: Although a port 29291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * may no longer be part of the topology, it may persist in the remote 293019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * ports displayed by the fc_host. We do this under 2 conditions: 2931eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * 1) If the port was a scsi target, we delay its deletion by "blocking" it. 293219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * This allows the port to temporarily disappear, then reappear without 293319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * disrupting the SCSI device tree attached to it. During the "blocked" 293419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * period the port will still exist. 2935eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * 2) If the port was a scsi target and disappears for longer than we 293619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * expect, we'll delete the port and the tear down the SCSI device tree 293719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * attached to it. However, we want to semi-persist the target id assigned 293819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * to that port if it eventually does exist. The port structure will 293919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * remain (although with minimal information) so that the target id 294019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * bindings remails. 29411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 29421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If the remote port is not an FCP Target, it will be fully torn down 29431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and deallocated, including the fc_remote_port class device. 29441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 294519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port is an FCP Target, the port will be placed in a 294619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * temporary blocked state. From the LLDD's perspective, the rport no 294719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * longer exists. From the SCSI midlayer's perspective, the SCSI target 294819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * exists, but all sdevs on it are blocked from further I/O. The following 2949eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * is then expected. 2950eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * 295119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port does not return (signaled by a LLDD call to 295219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * fc_remote_port_add()) within the dev_loss_tmo timeout, then the 295319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi target is removed - killing all outstanding i/o and removing the 295419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi devices attached ot it. The port structure will be marked Not 295519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Present and be partially cleared, leaving only enough information to 295619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * recognize the remote port relative to the scsi target id binding if 295719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * it later appears. The port will remain as long as there is a valid 295819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * binding (e.g. until the user changes the binding type or unloads the 295919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi host with the binding). 29601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 296119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port returns within the dev_loss_tmo value (and matches 296219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * according to the target id binding type), the port structure will be 296319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * reused. If it is no longer a SCSI target, the target will be torn 296419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * down. If it continues to be a SCSI target, then the target will be 296519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * unblocked (allowing i/o to be resumed), and a scan will be activated 296619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * to ensure that all luns are detected. 296719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 296819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Called from normal process context only - cannot be called from interrupt. 29691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 29701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 29711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 2972eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 29731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 29741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_delete(struct fc_rport *rport) 29751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2976aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 297736dd288f0f930c154ec6a4d73a6a35f3079418c6Hannes Reinecke unsigned long timeout = rport->dev_loss_tmo; 2978aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart unsigned long flags; 2979aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2980aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* 2981aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * No need to flush the fc_host work_q's, as all adds are synchronous. 2982aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 2983aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * We do need to reclaim the rport scan work element, so eventually 2984aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * (in fc_rport_final_delete()) we'll flush the scsi host work_q if 2985aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * there's still a scan pending. 2986aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart */ 2987aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2988aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 29891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 299092740b24ce6ddac6534fae985aab602548692186James Smart if (rport->port_state != FC_PORTSTATE_ONLINE) { 2991aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 29921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 29931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 29941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 299592740b24ce6ddac6534fae985aab602548692186James Smart /* 299692740b24ce6ddac6534fae985aab602548692186James Smart * In the past, we if this was not an FCP-Target, we would 299792740b24ce6ddac6534fae985aab602548692186James Smart * unconditionally just jump to deleting the rport. 299892740b24ce6ddac6534fae985aab602548692186James Smart * However, rports can be used as node containers by the LLDD, 299992740b24ce6ddac6534fae985aab602548692186James Smart * and its not appropriate to just terminate the rport at the 300092740b24ce6ddac6534fae985aab602548692186James Smart * first sign of a loss in connectivity. The LLDD may want to 300192740b24ce6ddac6534fae985aab602548692186James Smart * send ELS traffic to re-validate the login. If the rport is 300292740b24ce6ddac6534fae985aab602548692186James Smart * immediately deleted, it makes it inappropriate for a node 300392740b24ce6ddac6534fae985aab602548692186James Smart * container. 300492740b24ce6ddac6534fae985aab602548692186James Smart * So... we now unconditionally wait dev_loss_tmo before 300592740b24ce6ddac6534fae985aab602548692186James Smart * destroying an rport. 300692740b24ce6ddac6534fae985aab602548692186James Smart */ 300792740b24ce6ddac6534fae985aab602548692186James Smart 3008aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_BLOCKED; 3009aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3010aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_DEVLOSS_PENDING; 3011aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3012aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 3013aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 301419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com scsi_target_block(&rport->dev); 30151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 30160f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart /* see if we need to kill io faster than waiting for device loss */ 30170f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if ((rport->fast_io_fail_tmo != -1) && 3018fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie (rport->fast_io_fail_tmo < timeout)) 30190f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart fc_queue_devloss_work(shost, &rport->fail_io_work, 30200f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart rport->fast_io_fail_tmo * HZ); 30210f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 302219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* cap the length the devices can be blocked until they are deleted */ 3023aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ); 30241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 30251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_delete); 30261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 30271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 3028eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_remote_port_rolechg - notifies the fc transport that the roles on a remote may have changed. 30291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @rport: The remote port that changed. 3030eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * @roles: New roles for this port. 30311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3032eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * Description: The LLDD calls this routine to notify the transport that the 3033eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * roles on a remote port may have changed. The largest effect of this is 30341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * if a port now becomes a FCP Target, it must be allocated a 30351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * scsi target id. If the port is no longer a FCP target, any 30361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * scsi target id value assigned to it will persist in case the 30371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * role changes back to include FCP Target. No changes in the scsi 30381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * midlayer will be invoked if the role changes (in the expectation 30391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * that the role will be resumed. If it doesn't normal error processing 30401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * will take place). 30411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 30421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Should not be called from interrupt context. 30431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 30441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 30451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 3046eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 30471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 30481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_rolechg(struct fc_rport *rport, u32 roles) 30491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 30501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); 3051aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 30521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 30531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int create = 0; 30541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 30551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 3056a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (roles & FC_PORT_ROLE_FCP_TARGET) { 305719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->scsi_target_id == -1) { 305819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->scsi_target_id = fc_host->next_target_id++; 305919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com create = 1; 3060a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET)) 306119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com create = 1; 30621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 30631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 306419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->roles = roles; 306519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 3066aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 3067aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 306819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (create) { 306919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 307019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * There may have been a delete timer running on the 307119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * port. Ensure that it is cancelled as we now know 307219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * the port is an FCP Target. 307319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Note: we know the rport is exists and in an online 307419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * state as the LLDD would not have had an rport 307519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * reference to pass us. 307619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 307719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Take no action on the del_timer failure as the state 307819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * machine state change will validate the 307919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * transaction. 308019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 30810f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (!cancel_delayed_work(&rport->fail_io_work)) 30820f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart fc_flush_devloss(shost); 308319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (!cancel_delayed_work(&rport->dev_loss_work)) 3084aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_devloss(shost); 3085aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3086aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 3087fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT | 30880eecee413d3157bac4477362bfc4b907b4b2988bJames Smart FC_RPORT_DEVLOSS_PENDING | 30890eecee413d3157bac4477362bfc4b907b4b2988bJames Smart FC_RPORT_DEVLOSS_CALLBK_DONE); 3090aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 3091aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3092aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* ensure any stgt delete functions are done */ 3093aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_work(shost); 309419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 30955d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie scsi_target_unblock(&rport->dev, SDEV_RUNNING); 30961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 3097aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 3098aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 30991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 3100aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 310119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 31021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 31031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_rolechg); 31041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 31051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 3106eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_timeout_deleted_rport - Timeout handler for a deleted remote port. 310792740b24ce6ddac6534fae985aab602548692186James Smart * @work: rport target that failed to reappear in the allotted time. 3108eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * 3109eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * Description: An attempt to delete a remote port blocks, and if it fails 3110eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * to return in the allotted time this gets called. 3111eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 31121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3113c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_timeout_deleted_rport(struct work_struct *work) 31141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3115c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct fc_rport *rport = 3116c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct fc_rport, dev_loss_work.work); 311719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct Scsi_Host *shost = rport_to_shost(rport); 31184be98c0ca304c8a47998b29a7993664f71791250James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 3119aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 312019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com unsigned long flags; 31218798a694da59486e4a3ff0abeec183202fb34c20Michael Reed int do_callback = 0; 31221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 312319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_lock_irqsave(shost->host_lock, flags); 31241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3125aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 3126aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 31271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 312892740b24ce6ddac6534fae985aab602548692186James Smart * If the port is ONLINE, then it came back. If it was a SCSI 312992740b24ce6ddac6534fae985aab602548692186James Smart * target, validate it still is. If not, tear down the 313092740b24ce6ddac6534fae985aab602548692186James Smart * scsi_target on it. 31311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3132aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if ((rport->port_state == FC_PORTSTATE_ONLINE) && 313392740b24ce6ddac6534fae985aab602548692186James Smart (rport->scsi_target_id != -1) && 3134a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) { 313519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 3136aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "blocked FC remote port time out: no longer" 3137aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart " a FCP target, removing starget\n"); 3138aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 31395d9fb5cc1b88277bb28a2a54e51b34cacaa123c2Mike Christie scsi_target_unblock(&rport->dev, SDEV_TRANSPORT_OFFLINE); 3140a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart fc_queue_work(shost, &rport->stgt_delete_work); 314119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 314219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 31431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 314492740b24ce6ddac6534fae985aab602548692186James Smart /* NOOP state - we're flushing workq's */ 314519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_state != FC_PORTSTATE_BLOCKED) { 314619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 314719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 314892740b24ce6ddac6534fae985aab602548692186James Smart "blocked FC remote port time out: leaving" 314992740b24ce6ddac6534fae985aab602548692186James Smart " rport%s alone\n", 315092740b24ce6ddac6534fae985aab602548692186James Smart (rport->scsi_target_id != -1) ? " and starget" : ""); 315119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 315219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 31531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 315492740b24ce6ddac6534fae985aab602548692186James Smart if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) || 315592740b24ce6ddac6534fae985aab602548692186James Smart (rport->scsi_target_id == -1)) { 3156aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 3157aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 315819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 315992740b24ce6ddac6534fae985aab602548692186James Smart "blocked FC remote port time out: removing" 316092740b24ce6ddac6534fae985aab602548692186James Smart " rport%s\n", 316192740b24ce6ddac6534fae985aab602548692186James Smart (rport->scsi_target_id != -1) ? " and starget" : ""); 3162aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 3163aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 316419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 316519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 31661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 316719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 316819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "blocked FC remote port time out: removing target and " 316919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "saving binding\n"); 317019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 3171aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_move_tail(&rport->peers, &fc_host->rport_bindings); 31721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 31731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 317419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Note: We do not remove or clear the hostdata area. This allows 317519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * host-specific target data to persist along with the 317619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi_target_id. It's up to the host to manage it's hostdata area. 31771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 31781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 317919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 318019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Reinitialize port attributes that may change if the port comes back. 318119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 318219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->maxframe_size = -1; 318319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->supported_classes = FC_COS_UNSPECIFIED; 3184a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart rport->roles = FC_PORT_ROLE_UNKNOWN; 3185aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_NOTPRESENT; 3186fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie rport->flags &= ~FC_RPORT_FAST_FAIL_TIMEDOUT; 31871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3188f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart /* 3189f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart * Pre-emptively kill I/O rather than waiting for the work queue 3190f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart * item to teardown the starget. (FCOE libFC folks prefer this 3191f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart * and to have the rport_port_id still set when it's done). 3192f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart */ 3193f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3194f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart fc_terminate_rport_io(rport); 3195f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart 31968798a694da59486e4a3ff0abeec183202fb34c20Michael Reed spin_lock_irqsave(shost->host_lock, flags); 31978798a694da59486e4a3ff0abeec183202fb34c20Michael Reed 31988798a694da59486e4a3ff0abeec183202fb34c20Michael Reed if (rport->port_state == FC_PORTSTATE_NOTPRESENT) { /* still missing */ 3199f78badb1ae07e7f8b835ab2ea0b456ed3fc4caf4James Smart 32008798a694da59486e4a3ff0abeec183202fb34c20Michael Reed /* remove the identifiers that aren't used in the consisting binding */ 32018798a694da59486e4a3ff0abeec183202fb34c20Michael Reed switch (fc_host->tgtid_bind_type) { 32028798a694da59486e4a3ff0abeec183202fb34c20Michael Reed case FC_TGTID_BIND_BY_WWPN: 32038798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->node_name = -1; 32048798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->port_id = -1; 32058798a694da59486e4a3ff0abeec183202fb34c20Michael Reed break; 32068798a694da59486e4a3ff0abeec183202fb34c20Michael Reed case FC_TGTID_BIND_BY_WWNN: 32078798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->port_name = -1; 32088798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->port_id = -1; 32098798a694da59486e4a3ff0abeec183202fb34c20Michael Reed break; 32108798a694da59486e4a3ff0abeec183202fb34c20Michael Reed case FC_TGTID_BIND_BY_ID: 32118798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->node_name = -1; 32128798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->port_name = -1; 32138798a694da59486e4a3ff0abeec183202fb34c20Michael Reed break; 32148798a694da59486e4a3ff0abeec183202fb34c20Michael Reed case FC_TGTID_BIND_NONE: /* to keep compiler happy */ 32158798a694da59486e4a3ff0abeec183202fb34c20Michael Reed break; 32168798a694da59486e4a3ff0abeec183202fb34c20Michael Reed } 32178798a694da59486e4a3ff0abeec183202fb34c20Michael Reed 32188798a694da59486e4a3ff0abeec183202fb34c20Michael Reed /* 32198798a694da59486e4a3ff0abeec183202fb34c20Michael Reed * As this only occurs if the remote port (scsi target) 32208798a694da59486e4a3ff0abeec183202fb34c20Michael Reed * went away and didn't come back - we'll remove 32218798a694da59486e4a3ff0abeec183202fb34c20Michael Reed * all attached scsi devices. 32228798a694da59486e4a3ff0abeec183202fb34c20Michael Reed */ 32238798a694da59486e4a3ff0abeec183202fb34c20Michael Reed rport->flags |= FC_RPORT_DEVLOSS_CALLBK_DONE; 32248798a694da59486e4a3ff0abeec183202fb34c20Michael Reed fc_queue_work(shost, &rport->stgt_delete_work); 32258798a694da59486e4a3ff0abeec183202fb34c20Michael Reed 32268798a694da59486e4a3ff0abeec183202fb34c20Michael Reed do_callback = 1; 322719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 322819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 32298798a694da59486e4a3ff0abeec183202fb34c20Michael Reed spin_unlock_irqrestore(shost->host_lock, flags); 32304be98c0ca304c8a47998b29a7993664f71791250James Smart 32314be98c0ca304c8a47998b29a7993664f71791250James Smart /* 32324be98c0ca304c8a47998b29a7993664f71791250James Smart * Notify the driver that the rport is now dead. The LLDD will 32334be98c0ca304c8a47998b29a7993664f71791250James Smart * also guarantee that any communication to the rport is terminated 32344be98c0ca304c8a47998b29a7993664f71791250James Smart * 32354be98c0ca304c8a47998b29a7993664f71791250James Smart * Note: we set the CALLBK_DONE flag above to correspond 32364be98c0ca304c8a47998b29a7993664f71791250James Smart */ 32378798a694da59486e4a3ff0abeec183202fb34c20Michael Reed if (do_callback && i->f->dev_loss_tmo_callbk) 32384be98c0ca304c8a47998b29a7993664f71791250James Smart i->f->dev_loss_tmo_callbk(rport); 32391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 32401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 32414be98c0ca304c8a47998b29a7993664f71791250James Smart 32421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 3243eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley * fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a disconnected SCSI target. 3244c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells * @work: rport to terminate io on. 32450f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart * 32460f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart * Notes: Only requests the failure of the io, not that all are flushed 32470f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart * prior to returning. 3248eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 32490f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smartstatic void 3250c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_timeout_fail_rport_io(struct work_struct *work) 32510f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart{ 3252c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct fc_rport *rport = 3253c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct fc_rport, fail_io_work.work); 32540f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 32550f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart if (rport->port_state != FC_PORTSTATE_BLOCKED) 32560f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart return; 32570f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 3258fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie rport->flags |= FC_RPORT_FAST_FAIL_TIMEDOUT; 3259fff9d40ce0eb4b46f3e186823ceab6bc02c3e5d3Mike Christie fc_terminate_rport_io(rport); 32600f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart} 32610f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart 32620f29b966d60e9a4f5ecff9f3832257b38aea4f13James Smart/** 32631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_scsi_scan_rport - called to perform a scsi scan on a remote port. 3264c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells * @work: remote port to be scanned. 3265eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 32661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 3267c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsfc_scsi_scan_rport(struct work_struct *work) 32681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3269c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells struct fc_rport *rport = 3270c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howells container_of(work, struct fc_rport, scan_work); 3271aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 327203f002f778e58e9056e8e9a22952c5c6f4d76269Christof Schmitt struct fc_internal *i = to_fc_internal(shost->transportt); 327342e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com unsigned long flags; 327442e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 3275aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if ((rport->port_state == FC_PORTSTATE_ONLINE) && 327603f002f778e58e9056e8e9a22952c5c6f4d76269Christof Schmitt (rport->roles & FC_PORT_ROLE_FCP_TARGET) && 327703f002f778e58e9056e8e9a22952c5c6f4d76269Christof Schmitt !(i->f->disable_target_scan)) { 3278aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_scan_target(&rport->dev, rport->channel, 3279aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->scsi_target_id, SCAN_WILD_CARD, 1); 328042e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com } 3281aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3282aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 3283aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_SCAN_PENDING; 328442e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 328542e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com} 328642e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 328765d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt/** 328865d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt * fc_block_scsi_eh - Block SCSI eh thread for blocked fc_rport 328965d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt * @cmnd: SCSI command that scsi_eh is trying to recover 329065d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt * 329165d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt * This routine can be called from a FC LLD scsi_eh callback. It 329265d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt * blocks the scsi_eh thread until the fc_rport leaves the 32932f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * FC_PORTSTATE_BLOCKED, or the fast_io_fail_tmo fires. This is 32942f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * necessary to avoid the scsi_eh failing recovery actions for blocked 32952f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * rports which would lead to offlined SCSI devices. 32962f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * 32972f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * Returns: 0 if the fc_rport left the state FC_PORTSTATE_BLOCKED. 32982f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * FAST_IO_FAIL if the fast_io_fail_tmo fired, this should be 32992f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt * passed back to scsi_eh. 330065d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt */ 33012f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmittint fc_block_scsi_eh(struct scsi_cmnd *cmnd) 330265d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt{ 330365d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt struct Scsi_Host *shost = cmnd->device->host; 330465d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device)); 330565d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt unsigned long flags; 330665d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt 330765d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt spin_lock_irqsave(shost->host_lock, flags); 33082f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt while (rport->port_state == FC_PORTSTATE_BLOCKED && 33092f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) { 331065d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt spin_unlock_irqrestore(shost->host_lock, flags); 331165d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt msleep(1000); 331265d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt spin_lock_irqsave(shost->host_lock, flags); 331365d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt } 331465d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt spin_unlock_irqrestore(shost->host_lock, flags); 33152f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt 33162f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt if (rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT) 33172f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt return FAST_IO_FAIL; 33182f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt 33192f2eb58762b4dcddfe25c90800323765c1257ecaChristof Schmitt return 0; 332065d430fa99cbd0e88d09a3343f697c51fc8a7009Christof Schmitt} 332165d430fa99cbd0e88d09a3343f697c51fc8a7009Christof SchmittEXPORT_SYMBOL(fc_block_scsi_eh); 332242e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 3323a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/** 3324a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * fc_vport_setup - allocates and creates a FC virtual port. 3325a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @shost: scsi host the virtual port is connected to. 3326a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @channel: Channel on shost port connected to. 3327a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @pdev: parent device for vport 3328a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @ids: The world wide names, FC4 port roles, etc for 3329a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * the virtual port. 3330a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @ret_vport: The pointer to the created vport. 3331a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * 3332a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Allocates and creates the vport structure, calls the parent host 3333a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * to instantiate the vport, the completes w/ class and sysfs creation. 3334a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * 3335a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Notes: 3336a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * This routine assumes no locks are held on entry. 3337eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 3338a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartstatic int 3339a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquezfc_vport_setup(struct Scsi_Host *shost, int channel, struct device *pdev, 3340a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport_identifiers *ids, struct fc_vport **ret_vport) 3341a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 3342a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 3343a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *fci = to_fc_internal(shost->transportt); 3344a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_vport *vport; 3345a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct device *dev; 3346a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned long flags; 3347a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart size_t size; 3348a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int error; 3349a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3350a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart *ret_vport = NULL; 3351a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3352a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if ( ! fci->f->vport_create) 3353a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -ENOENT; 3354a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3355a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size); 3356a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport = kzalloc(size, GFP_KERNEL); 3357a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (unlikely(!vport)) { 3358cadbd4a5e36dde7e6c49b587b2c419103c0b7218Harvey Harrison printk(KERN_ERR "%s: allocation failure\n", __func__); 3359a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -ENOMEM; 3360a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3361a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3362a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->vport_state = FC_VPORT_UNKNOWN; 3363a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->vport_last_state = FC_VPORT_UNKNOWN; 3364a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->node_name = ids->node_name; 3365a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->port_name = ids->port_name; 3366a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->roles = ids->roles; 3367a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->vport_type = ids->vport_type; 3368a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (fci->f->dd_fcvport_size) 3369a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->dd_data = &vport[1]; 3370a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->shost = shost; 3371a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->channel = channel; 3372a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->flags = FC_VPORT_CREATING; 33739ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete); 3374a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3375a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 3376a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3377a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) { 3378a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3379a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart kfree(vport); 3380a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return -ENOSPC; 3381a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3382a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->npiv_vports_inuse++; 3383a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->number = fc_host->next_vport_number++; 3384a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart list_add_tail(&vport->peers, &fc_host->vports); 3385a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart get_device(&shost->shost_gendev); /* for fc_host->vport list */ 3386a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3387a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3388a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3389a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart dev = &vport->dev; 3390a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart device_initialize(dev); /* takes self reference */ 3391a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart dev->parent = get_device(pdev); /* takes parent reference */ 3392a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart dev->release = fc_vport_dev_release; 339371610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers dev_set_name(dev, "vport-%d:%d-%d", 339471610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers shost->host_no, channel, vport->number); 3395a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_setup_device(dev); 3396a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3397a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart error = device_add(dev); 3398a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (error) { 3399a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart printk(KERN_ERR "FC Virtual Port device_add failed\n"); 3400a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart goto delete_vport; 3401a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3402a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_add_device(dev); 3403a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_configure_device(dev); 3404a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3405a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart error = fci->f->vport_create(vport, ids->disable); 3406a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (error) { 3407a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart printk(KERN_ERR "FC Virtual Port LLDD Create failed\n"); 3408a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart goto delete_vport_all; 3409a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3410a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3411a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* 3412a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * if the parent isn't the physical adapter's Scsi_Host, ensure 3413a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * the Scsi_Host at least contains ia symlink to the vport. 3414a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 3415a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (pdev != &shost->shost_gendev) { 3416a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart error = sysfs_create_link(&shost->shost_gendev.kobj, 341771610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers &dev->kobj, dev_name(dev)); 3418a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (error) 3419a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart printk(KERN_ERR 3420a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart "%s: Cannot create vport symlinks for " 3421a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart "%s, err=%d\n", 342271610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers __func__, dev_name(dev), error); 3423a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3424a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 3425a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->flags &= ~FC_VPORT_CREATING; 3426a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3427a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3428a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart dev_printk(KERN_NOTICE, pdev, 342971610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers "%s created via shost%d channel %d\n", dev_name(dev), 3430a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart shost->host_no, channel); 3431a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3432a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart *ret_vport = vport; 3433a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3434a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return 0; 3435a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3436a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartdelete_vport_all: 3437a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_remove_device(dev); 3438a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart device_del(dev); 3439a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartdelete_vport: 3440a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_destroy_device(dev); 3441a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 3442a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart list_del(&vport->peers); 3443a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart put_device(&shost->shost_gendev); /* for fc_host->vport list */ 3444a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->npiv_vports_inuse--; 3445a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3446a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart put_device(dev->parent); 3447a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart kfree(vport); 3448a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3449a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return error; 3450a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 3451a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3452a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez/** 3453a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * fc_vport_create - Admin App or LLDD requests creation of a vport 3454a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * @shost: scsi host the virtual port is connected to. 3455a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * @channel: channel on shost port connected to. 3456a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * @ids: The world wide names, FC4 port roles, etc for 3457a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * the virtual port. 3458a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * 3459a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * Notes: 3460a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez * This routine assumes no locks are held on entry. 3461a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez */ 3462a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquezstruct fc_vport * 3463a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquezfc_vport_create(struct Scsi_Host *shost, int channel, 3464a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez struct fc_vport_identifiers *ids) 3465a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez{ 3466a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez int stat; 3467a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez struct fc_vport *vport; 3468a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez 3469a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez stat = fc_vport_setup(shost, channel, &shost->shost_gendev, 3470a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez ids, &vport); 3471a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez return stat ? NULL : vport; 3472a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew Vasquez} 3473a30c3f69e6336cb9b09a989595e417367e4e9b1bAndrew VasquezEXPORT_SYMBOL(fc_vport_create); 3474a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3475a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart/** 3476a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * fc_vport_terminate - Admin App or LLDD requests termination of a vport 3477a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * @vport: fc_vport to be terminated 3478a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * 3479a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Calls the LLDD vport_delete() function, then deallocates and removes 3480a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * the vport from the shost and object tree. 3481a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * 3482a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Notes: 3483a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * This routine assumes no locks are held on entry. 3484eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 3485a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartint 3486a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smartfc_vport_terminate(struct fc_vport *vport) 3487a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart{ 3488a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct Scsi_Host *shost = vport_to_shost(vport); 3489a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 3490a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 3491a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart struct device *dev = &vport->dev; 3492a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart unsigned long flags; 3493a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart int stat; 3494a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3495a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (i->f->vport_delete) 3496a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = i->f->vport_delete(vport); 3497a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart else 3498a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart stat = -ENOENT; 3499a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3500a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_lock_irqsave(shost->host_lock, flags); 3501a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->flags &= ~FC_VPORT_DELETING; 3502a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (!stat) { 3503a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart vport->flags |= FC_VPORT_DELETED; 3504a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart list_del(&vport->peers); 3505a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart fc_host->npiv_vports_inuse--; 3506a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart put_device(&shost->shost_gendev); /* for fc_host->vport list */ 3507a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart } 3508a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart spin_unlock_irqrestore(shost->host_lock, flags); 3509a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3510a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (stat) 3511a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return stat; 3512a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3513a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart if (dev->parent != &shost->shost_gendev) 351471610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers sysfs_remove_link(&shost->shost_gendev.kobj, dev_name(dev)); 3515a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_remove_device(dev); 3516a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart device_del(dev); 3517a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart transport_destroy_device(dev); 3518a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3519a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart /* 3520a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * Removing our self-reference should mean our 3521a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * release function gets called, which will drop the remaining 3522a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart * parent reference and free the data structure. 3523a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart */ 3524a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart put_device(dev); /* for self-reference */ 3525a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 3526a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart return 0; /* SUCCESS */ 3527a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart} 3528a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James SmartEXPORT_SYMBOL(fc_vport_terminate); 3529a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 35309ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart/** 35319ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart * fc_vport_sched_delete - workq-based delete request for a vport 35329ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart * @work: vport to be deleted. 3533eb44820c28bc9a042e1157b41c677018a8fdfc74Rob Landley */ 35349ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smartstatic void 35359ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smartfc_vport_sched_delete(struct work_struct *work) 35369ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart{ 35379ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart struct fc_vport *vport = 35389ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart container_of(work, struct fc_vport, vport_delete_work); 35399ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart int stat; 35409ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart 35419ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart stat = fc_vport_terminate(vport); 35429ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart if (stat) 35439ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart dev_printk(KERN_ERR, vport->dev.parent, 35449ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart "%s: %s could not be deleted created via " 3545cadbd4a5e36dde7e6c49b587b2c419103c0b7218Harvey Harrison "shost%d channel %d - error %d\n", __func__, 354671610f55fa4db63dbf5385929a47c9fb2451f332Kay Sievers dev_name(&vport->dev), vport->shost->host_no, 35479ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart vport->channel, stat); 35489ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart} 35499ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart 3550a53eb5e060c0ec7245c8f93b9dcd94afa6041e06James Smart 35519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/* 35529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * BSG support 35539e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 35549e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35569e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 35579e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_destroy_bsgjob - routine to teardown/delete a fc bsg job 35589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @job: fc_bsg_job that is to be torn down 35599e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 35609e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 35619e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_destroy_bsgjob(struct fc_bsg_job *job) 35629e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 35639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart unsigned long flags; 35649e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irqsave(&job->job_lock, flags); 35669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->ref_cnt) { 35679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irqrestore(&job->job_lock, flags); 35689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return; 35699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 35709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irqrestore(&job->job_lock, flags); 35719e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart put_device(job->dev); /* release reference for the request */ 35739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35749e4f5e29610162fd426366f3b29e3cc6e575b858James Smart kfree(job->request_payload.sg_list); 35759e4f5e29610162fd426366f3b29e3cc6e575b858James Smart kfree(job->reply_payload.sg_list); 35769e4f5e29610162fd426366f3b29e3cc6e575b858James Smart kfree(job); 35779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 35789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 35809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_jobdone - completion routine for bsg requests that the LLD has 35819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * completed 35829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @job: fc_bsg_job that is complete 35839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 35849e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 35859e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_jobdone(struct fc_bsg_job *job) 35869e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 35879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request *req = job->req; 35889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request *rsp = req->next_rq; 35899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int err; 35909e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart err = job->req->errors = job->reply->result; 3592b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali 35939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (err < 0) 35949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* we're only returning the result field in the reply */ 35959e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->req->sense_len = sizeof(uint32_t); 35969e4f5e29610162fd426366f3b29e3cc6e575b858James Smart else 35979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->req->sense_len = job->reply_len; 35989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 35999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* we assume all request payload was transferred, residual == 0 */ 36009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart req->resid_len = 0; 36019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (rsp) { 36039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart WARN_ON(job->reply->reply_payload_rcv_len > rsp->resid_len); 36049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* set reply (bidi) residual */ 36069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart rsp->resid_len -= min(job->reply->reply_payload_rcv_len, 36079e4f5e29610162fd426366f3b29e3cc6e575b858James Smart rsp->resid_len); 36089e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 3609b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali blk_complete_request(req); 3610b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali} 3611b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali 3612b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali/** 3613b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali * fc_bsg_softirq_done - softirq done routine for destroying the bsg requests 3614fe5d20c818a8c5fe83d9f2223a051fb5bc50d180Randy Dunlap * @rq: BSG request that holds the job to be destroyed 3615b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali */ 3616b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavalistatic void fc_bsg_softirq_done(struct request *rq) 3617b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali{ 3618b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali struct fc_bsg_job *job = rq->special; 3619b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali unsigned long flags; 36209e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 3621b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali spin_lock_irqsave(&job->job_lock, flags); 3622b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali job->state_flags |= FC_RQST_STATE_DONE; 3623b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali job->ref_cnt--; 3624b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali spin_unlock_irqrestore(&job->job_lock, flags); 36259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 3626b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali blk_end_request_all(rq, rq->errors); 36279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_destroy_bsgjob(job); 36289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 36299e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36309e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 36319e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_job_timeout - handler for when a bsg request timesout 36329e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @req: request that timed out 36339e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 36349e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic enum blk_eh_timer_return 36359e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_job_timeout(struct request *req) 36369e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 36379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_bsg_job *job = (void *) req->special; 36389e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct Scsi_Host *shost = job->shost; 36399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 36409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart unsigned long flags; 36419e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int err = 0, done = 0; 36429e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->rport && job->rport->port_state == FC_PORTSTATE_BLOCKED) 36449e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return BLK_EH_RESET_TIMER; 36459e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36469e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irqsave(&job->job_lock, flags); 36479e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->state_flags & FC_RQST_STATE_DONE) 36489e4f5e29610162fd426366f3b29e3cc6e575b858James Smart done = 1; 36499e4f5e29610162fd426366f3b29e3cc6e575b858James Smart else 36509e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->ref_cnt++; 36519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irqrestore(&job->job_lock, flags); 36529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36539e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!done && i->f->bsg_timeout) { 36549e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* call LLDD to abort the i/o as it has timed out */ 36559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart err = i->f->bsg_timeout(job); 3656b8f08645f80a0c93246f3539ce53d3cae6a91fa0Swen Schillig if (err == -EAGAIN) { 3657b8f08645f80a0c93246f3539ce53d3cae6a91fa0Swen Schillig job->ref_cnt--; 3658b8f08645f80a0c93246f3539ce53d3cae6a91fa0Swen Schillig return BLK_EH_RESET_TIMER; 3659b8f08645f80a0c93246f3539ce53d3cae6a91fa0Swen Schillig } else if (err) 36609e4f5e29610162fd426366f3b29e3cc6e575b858James Smart printk(KERN_ERR "ERROR: FC BSG request timeout - LLD " 36619e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "abort failed with status %d\n", err); 36629e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 36639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36649e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* the blk_end_sync_io() doesn't check the error */ 366547e7e89ed029780adf2cc0cf506fcd4c2d5ca1e2Giridhar Malavali if (done) 366647e7e89ed029780adf2cc0cf506fcd4c2d5ca1e2Giridhar Malavali return BLK_EH_NOT_HANDLED; 366747e7e89ed029780adf2cc0cf506fcd4c2d5ca1e2Giridhar Malavali else 366847e7e89ed029780adf2cc0cf506fcd4c2d5ca1e2Giridhar Malavali return BLK_EH_HANDLED; 36699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 36709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36719e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int 36729e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_map_buffer(struct fc_bsg_buffer *buf, struct request *req) 36739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 36749e4f5e29610162fd426366f3b29e3cc6e575b858James Smart size_t sz = (sizeof(struct scatterlist) * req->nr_phys_segments); 36759e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36769e4f5e29610162fd426366f3b29e3cc6e575b858James Smart BUG_ON(!req->nr_phys_segments); 36779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart buf->sg_list = kzalloc(sz, GFP_KERNEL); 36799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!buf->sg_list) 36809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOMEM; 36819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart sg_init_table(buf->sg_list, req->nr_phys_segments); 36829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list); 36839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart buf->payload_len = blk_rq_bytes(req); 36849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return 0; 36859e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 36869e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 36889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 36899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_req_to_bsgjob - Allocate/create the fc_bsg_job structure for the 36909e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * bsg request 36919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: SCSI Host corresponding to the bsg object 36929e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @rport: (optional) FC Remote Port corresponding to the bsg object 36939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @req: BSG request that needs a job structure 36949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 36959e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int 36969e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_req_to_bsgjob(struct Scsi_Host *shost, struct fc_rport *rport, 36979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request *req) 36989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 36999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 37009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request *rsp = req->next_rq; 37019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_bsg_job *job; 37029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int ret; 37039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart BUG_ON(req->special); 37059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job = kzalloc(sizeof(struct fc_bsg_job) + i->f->dd_bsg_size, 37079e4f5e29610162fd426366f3b29e3cc6e575b858James Smart GFP_KERNEL); 37089e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!job) 37099e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOMEM; 37109e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37119e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* 37129e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * Note: this is a bit silly. 37139e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * The request gets formatted as a SGIO v4 ioctl request, which 37149e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * then gets reformatted as a blk request, which then gets 37159e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * reformatted as a fc bsg request. And on completion, we have 37169e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * to wrap return results such that SGIO v4 thinks it was a scsi 37179e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * status. I hope this was all worth it. 37189e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 37199e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37209e4f5e29610162fd426366f3b29e3cc6e575b858James Smart req->special = job; 37219e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->shost = shost; 37229e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->rport = rport; 37239e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->req = req; 37249e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (i->f->dd_bsg_size) 37259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->dd_data = (void *)&job[1]; 37269e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_init(&job->job_lock); 37279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->request = (struct fc_bsg_request *)req->cmd; 37289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->request_len = req->cmd_len; 37299e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply = req->sense; 37309e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer 37319e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * allocated */ 37329e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (req->bio) { 37339e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = fc_bsg_map_buffer(&job->request_payload, req); 37349e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (ret) 37359e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto failjob_rls_job; 37369e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 37379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (rsp && rsp->bio) { 37389e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = fc_bsg_map_buffer(&job->reply_payload, rsp); 37399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (ret) 37409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto failjob_rls_rqst_payload; 37419e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 37429e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->job_done = fc_bsg_jobdone; 37439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (rport) 37449e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->dev = &rport->dev; 37459e4f5e29610162fd426366f3b29e3cc6e575b858James Smart else 37469e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->dev = &shost->shost_gendev; 37479e4f5e29610162fd426366f3b29e3cc6e575b858James Smart get_device(job->dev); /* take a reference for the request */ 37489e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37499e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->ref_cnt = 1; 37509e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return 0; 37529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37539e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37549e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfailjob_rls_rqst_payload: 37559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart kfree(job->request_payload.sg_list); 37569e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfailjob_rls_job: 37579e4f5e29610162fd426366f3b29e3cc6e575b858James Smart kfree(job); 37589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOMEM; 37599e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 37609e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37619e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37629e4f5e29610162fd426366f3b29e3cc6e575b858James Smartenum fc_dispatch_result { 37639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart FC_DISPATCH_BREAK, /* on return, q is locked, break from q loop */ 37649e4f5e29610162fd426366f3b29e3cc6e575b858James Smart FC_DISPATCH_LOCKED, /* on return, q is locked, continue on */ 37659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart FC_DISPATCH_UNLOCKED, /* on return, q is unlocked, continue on */ 37669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart}; 37679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 37709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_host_dispatch - process fc host bsg requests and dispatch to LLDD 37715415907af1f5ef80c95147bacbd321b0d4236dd5Randy Dunlap * @q: fc host request queue 37729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: scsi host rport attached to 37739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @job: bsg job to be processed 37749e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 37759e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic enum fc_dispatch_result 37769e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_host_dispatch(struct request_queue *q, struct Scsi_Host *shost, 37779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_bsg_job *job) 37789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 37799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 37809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ 37819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int ret; 37829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* Validate the host command */ 37849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart switch (job->request->msgcode) { 37859e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_HST_ADD_RPORT: 37869e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_host_add_rport); 37879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 37889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_HST_DEL_RPORT: 37909e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_host_del_rport); 37919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 37929e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 37939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_HST_ELS_NOLOGIN: 37949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_host_els); 37959e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* there better be a xmt and rcv payloads */ 37969e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if ((!job->request_payload.payload_len) || 37979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart (!job->reply_payload.payload_len)) { 37989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -EINVAL; 37999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_host_msg; 38009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 38029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_HST_CT: 38049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_host_ct); 38059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* there better be xmt and rcv payloads */ 38069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if ((!job->request_payload.payload_len) || 38079e4f5e29610162fd426366f3b29e3cc6e575b858James Smart (!job->reply_payload.payload_len)) { 38089e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -EINVAL; 38099e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_host_msg; 38109e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38119e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 38129e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38139e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_HST_VENDOR: 38149e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_host_vendor); 38159e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if ((shost->hostt->vendor_id == 0L) || 38169e4f5e29610162fd426366f3b29e3cc6e575b858James Smart (job->request->rqst_data.h_vendor.vendor_id != 38179e4f5e29610162fd426366f3b29e3cc6e575b858James Smart shost->hostt->vendor_id)) { 38189e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -ESRCH; 38199e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_host_msg; 38209e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38219e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 38229e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38239e4f5e29610162fd426366f3b29e3cc6e575b858James Smart default: 38249e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -EBADR; 38259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_host_msg; 38269e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* check if we really have all the request data needed */ 38299e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->request_len < cmdlen) { 38309e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -ENOMSG; 38319e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_host_msg; 38329e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38339e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38349e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = i->f->bsg_request(job); 38359e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!ret) 38369e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return FC_DISPATCH_UNLOCKED; 38379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38389e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfail_host_msg: 38399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* return the errno failure code as the only status */ 38409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart BUG_ON(job->reply_len < sizeof(uint32_t)); 384161ec33eb7d8e1e94a93a8243238dc5f9a183001aBrian King job->reply->reply_payload_rcv_len = 0; 38429e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply->result = ret; 38439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply_len = sizeof(uint32_t); 38449e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_jobdone(job); 38459e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return FC_DISPATCH_UNLOCKED; 38469e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 38479e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38489e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38499e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/* 38509e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_goose_queue - restart rport queue in case it was stopped 38519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @rport: rport to be restarted 38529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 38539e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 38549e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_goose_queue(struct fc_rport *rport) 38559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 38569e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!rport->rqst_q) 38579e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return; 38589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 3859c21e6beba8835d09bb80e34961430b13e60381c5Jens Axboe /* 3860c21e6beba8835d09bb80e34961430b13e60381c5Jens Axboe * This get/put dance makes no sense 3861c21e6beba8835d09bb80e34961430b13e60381c5Jens Axboe */ 38629e4f5e29610162fd426366f3b29e3cc6e575b858James Smart get_device(&rport->dev); 3863c21e6beba8835d09bb80e34961430b13e60381c5Jens Axboe blk_run_queue_async(rport->rqst_q); 38649e4f5e29610162fd426366f3b29e3cc6e575b858James Smart put_device(&rport->dev); 38659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 38669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 38689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_rport_dispatch - process rport bsg requests and dispatch to LLDD 38695415907af1f5ef80c95147bacbd321b0d4236dd5Randy Dunlap * @q: rport request queue 38709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: scsi host rport attached to 38719e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @rport: rport request destined to 38729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @job: bsg job to be processed 38739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 38749e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic enum fc_dispatch_result 38759e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_rport_dispatch(struct request_queue *q, struct Scsi_Host *shost, 38769e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_rport *rport, struct fc_bsg_job *job) 38779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 38789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 38799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ 38809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int ret; 38819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* Validate the rport command */ 38839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart switch (job->request->msgcode) { 38849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_RPT_ELS: 38859e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_rport_els); 38869e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto check_bidi; 38879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 38889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart case FC_BSG_RPT_CT: 38899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart cmdlen += sizeof(struct fc_bsg_rport_ct); 38909e4f5e29610162fd426366f3b29e3cc6e575b858James Smartcheck_bidi: 38919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* there better be xmt and rcv payloads */ 38929e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if ((!job->request_payload.payload_len) || 38939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart (!job->reply_payload.payload_len)) { 38949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -EINVAL; 38959e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_rport_msg; 38969e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 38979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 38989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart default: 38999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -EBADR; 39009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_rport_msg; 39019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* check if we really have all the request data needed */ 39049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->request_len < cmdlen) { 39059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = -ENOMSG; 39069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart goto fail_rport_msg; 39079e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39089e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39099e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = i->f->bsg_request(job); 39109e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!ret) 39119e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return FC_DISPATCH_UNLOCKED; 39129e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39139e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfail_rport_msg: 39149e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* return the errno failure code as the only status */ 39159e4f5e29610162fd426366f3b29e3cc6e575b858James Smart BUG_ON(job->reply_len < sizeof(uint32_t)); 391661ec33eb7d8e1e94a93a8243238dc5f9a183001aBrian King job->reply->reply_payload_rcv_len = 0; 39179e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply->result = ret; 39189e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply_len = sizeof(uint32_t); 39199e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_jobdone(job); 39209e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return FC_DISPATCH_UNLOCKED; 39219e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 39229e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39239e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39249e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 39259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_request_handler - generic handler for bsg requests 39269e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @q: request queue to manage 39279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: Scsi_Host related to the bsg object 39289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @rport: FC remote port related to the bsg object (optional) 39299e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @dev: device structure for bsg object 39309e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 39319e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 39329e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_request_handler(struct request_queue *q, struct Scsi_Host *shost, 39339e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_rport *rport, struct device *dev) 39349e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 39359e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request *req; 39369e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_bsg_job *job; 39379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart enum fc_dispatch_result ret; 39389e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!get_device(dev)) 39409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return; 39419e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39427eaceaccab5f40bbfda044629a6298616aeaed50Jens Axboe while (1) { 39432bc1c59dbdefdb6f9767e06efb86bbdb2923a8beMike Christie if (rport && (rport->port_state == FC_PORTSTATE_BLOCKED) && 39442bc1c59dbdefdb6f9767e06efb86bbdb2923a8beMike Christie !(rport->flags & FC_RPORT_FAST_FAIL_TIMEDOUT)) 39452bc1c59dbdefdb6f9767e06efb86bbdb2923a8beMike Christie break; 39469e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39479e4f5e29610162fd426366f3b29e3cc6e575b858James Smart req = blk_fetch_request(q); 39489e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!req) 39499e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 39509e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (rport && (rport->port_state != FC_PORTSTATE_ONLINE)) { 39529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart req->errors = -ENXIO; 39539e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irq(q->queue_lock); 3954d88a714bfefa7aed7b9cb6c3721707fcd056b472Sarang Radke blk_end_request_all(req, -ENXIO); 39559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irq(q->queue_lock); 39569e4f5e29610162fd426366f3b29e3cc6e575b858James Smart continue; 39579e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39599e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irq(q->queue_lock); 39609e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39619e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = fc_req_to_bsgjob(shost, rport, req); 39629e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (ret) { 39639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart req->errors = ret; 3964d88a714bfefa7aed7b9cb6c3721707fcd056b472Sarang Radke blk_end_request_all(req, ret); 39659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irq(q->queue_lock); 39669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart continue; 39679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job = req->special; 39709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39719e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* check if we have the msgcode value at least */ 39729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (job->request_len < sizeof(uint32_t)) { 39739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart BUG_ON(job->reply_len < sizeof(uint32_t)); 397461ec33eb7d8e1e94a93a8243238dc5f9a183001aBrian King job->reply->reply_payload_rcv_len = 0; 39759e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply->result = -ENOMSG; 39769e4f5e29610162fd426366f3b29e3cc6e575b858James Smart job->reply_len = sizeof(uint32_t); 39779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_jobdone(job); 39789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irq(q->queue_lock); 39799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart continue; 39809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* the dispatch routines will unlock the queue_lock */ 39839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (rport) 39849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = fc_bsg_rport_dispatch(q, shost, rport, job); 39859e4f5e29610162fd426366f3b29e3cc6e575b858James Smart else 39869e4f5e29610162fd426366f3b29e3cc6e575b858James Smart ret = fc_bsg_host_dispatch(q, shost, job); 39879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* did dispatcher hit state that can't process any more */ 39899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (ret == FC_DISPATCH_BREAK) 39909e4f5e29610162fd426366f3b29e3cc6e575b858James Smart break; 39919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39929e4f5e29610162fd426366f3b29e3cc6e575b858James Smart /* did dispatcher had released the lock */ 39939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (ret == FC_DISPATCH_UNLOCKED) 39949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irq(q->queue_lock); 39959e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 39969e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 39979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_unlock_irq(q->queue_lock); 39989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart put_device(dev); 39999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart spin_lock_irq(q->queue_lock); 40009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 40019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 40049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_host_handler - handler for bsg requests for a fc host 40059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @q: fc host request queue 40069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 40079e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 40089e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_host_handler(struct request_queue *q) 40099e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 40109e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct Scsi_Host *shost = q->queuedata; 40119e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40129e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_request_handler(q, shost, NULL, &shost->shost_gendev); 40139e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 40149e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40159e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40169e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 40179e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_rport_handler - handler for bsg requests for a fc rport 40189e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @q: rport request queue 40199e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 40209e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 40219e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_rport_handler(struct request_queue *q) 40229e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 40239e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_rport *rport = q->queuedata; 40249e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct Scsi_Host *shost = rport_to_shost(rport); 40259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40269e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_bsg_request_handler(q, shost, rport, &rport->dev); 40279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 40289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40299e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40309e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 40319e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_hostadd - Create and add the bsg hooks so we can receive requests 40329e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: shost for fc_host 40339e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @fc_host: fc_host adding the structures to 40349e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 40359e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int 40369e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_hostadd(struct Scsi_Host *shost, struct fc_host_attrs *fc_host) 40379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 40389e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct device *dev = &shost->shost_gendev; 40399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 40409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request_queue *q; 40419e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int err; 40423c559ea8fd003962d9a28c64b2dd5c6d83ca6edbJames Bottomley char bsg_name[20]; 40439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40449e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_host->rqst_q = NULL; 40459e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40469e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!i->f->bsg_request) 40479e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOTSUPP; 40489e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40499e4f5e29610162fd426366f3b29e3cc6e575b858James Smart snprintf(bsg_name, sizeof(bsg_name), 40509e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "fc_host%d", shost->host_no); 40519e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40529e4f5e29610162fd426366f3b29e3cc6e575b858James Smart q = __scsi_alloc_queue(shost, fc_bsg_host_handler); 40539e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!q) { 40549e4f5e29610162fd426366f3b29e3cc6e575b858James Smart printk(KERN_ERR "fc_host%d: bsg interface failed to " 40559e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "initialize - no request queue\n", 40569e4f5e29610162fd426366f3b29e3cc6e575b858James Smart shost->host_no); 40579e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOMEM; 40589e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 40599e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40609e4f5e29610162fd426366f3b29e3cc6e575b858James Smart q->queuedata = shost; 40619e4f5e29610162fd426366f3b29e3cc6e575b858James Smart queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); 4062b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali blk_queue_softirq_done(q, fc_bsg_softirq_done); 40639e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_queue_rq_timed_out(q, fc_bsg_job_timeout); 40649e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT); 40659e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40669e4f5e29610162fd426366f3b29e3cc6e575b858James Smart err = bsg_register_queue(q, dev, bsg_name, NULL); 40679e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (err) { 40689e4f5e29610162fd426366f3b29e3cc6e575b858James Smart printk(KERN_ERR "fc_host%d: bsg interface failed to " 40699e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "initialize - register queue\n", 40709e4f5e29610162fd426366f3b29e3cc6e575b858James Smart shost->host_no); 40719e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_cleanup_queue(q); 40729e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return err; 40739e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 40749e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40759e4f5e29610162fd426366f3b29e3cc6e575b858James Smart fc_host->rqst_q = q; 40769e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return 0; 40779e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 40789e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40799e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40809e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 40819e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_rportadd - Create and add the bsg hooks so we can receive requests 40829e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @shost: shost that rport is attached to 40839e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @rport: rport that the bsg hooks are being attached to 40849e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 40859e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic int 40869e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_rportadd(struct Scsi_Host *shost, struct fc_rport *rport) 40879e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 40889e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct device *dev = &rport->dev; 40899e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct fc_internal *i = to_fc_internal(shost->transportt); 40909e4f5e29610162fd426366f3b29e3cc6e575b858James Smart struct request_queue *q; 40919e4f5e29610162fd426366f3b29e3cc6e575b858James Smart int err; 40929e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40939e4f5e29610162fd426366f3b29e3cc6e575b858James Smart rport->rqst_q = NULL; 40949e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40959e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!i->f->bsg_request) 40969e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOTSUPP; 40979e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 40989e4f5e29610162fd426366f3b29e3cc6e575b858James Smart q = __scsi_alloc_queue(shost, fc_bsg_rport_handler); 40999e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (!q) { 41009e4f5e29610162fd426366f3b29e3cc6e575b858James Smart printk(KERN_ERR "%s: bsg interface failed to " 41019e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "initialize - no request queue\n", 41029e4f5e29610162fd426366f3b29e3cc6e575b858James Smart dev->kobj.name); 41039e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return -ENOMEM; 41049e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 41059e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41069e4f5e29610162fd426366f3b29e3cc6e575b858James Smart q->queuedata = rport; 41079e4f5e29610162fd426366f3b29e3cc6e575b858James Smart queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); 4108b5c6f77680f4ff1775838fcedfdd6026bf5ad777Giridhar Malavali blk_queue_softirq_done(q, fc_bsg_softirq_done); 41099e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_queue_rq_timed_out(q, fc_bsg_job_timeout); 41109e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT); 41119e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41129e4f5e29610162fd426366f3b29e3cc6e575b858James Smart err = bsg_register_queue(q, dev, NULL, NULL); 41139e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (err) { 41149e4f5e29610162fd426366f3b29e3cc6e575b858James Smart printk(KERN_ERR "%s: bsg interface failed to " 41159e4f5e29610162fd426366f3b29e3cc6e575b858James Smart "initialize - register queue\n", 41169e4f5e29610162fd426366f3b29e3cc6e575b858James Smart dev->kobj.name); 41179e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_cleanup_queue(q); 41189e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return err; 41199e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 41209e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41219e4f5e29610162fd426366f3b29e3cc6e575b858James Smart rport->rqst_q = q; 41229e4f5e29610162fd426366f3b29e3cc6e575b858James Smart return 0; 41239e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 41249e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41259e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41269e4f5e29610162fd426366f3b29e3cc6e575b858James Smart/** 41279e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * fc_bsg_remove - Deletes the bsg hooks on fchosts/rports 41289e4f5e29610162fd426366f3b29e3cc6e575b858James Smart * @q: the request_queue that is to be torn down. 412978d16341facf829a71b6f7c68ec5511b9c168060James Smart * 413078d16341facf829a71b6f7c68ec5511b9c168060James Smart * Notes: 413178d16341facf829a71b6f7c68ec5511b9c168060James Smart * Before unregistering the queue empty any requests that are blocked 413278d16341facf829a71b6f7c68ec5511b9c168060James Smart * 413378d16341facf829a71b6f7c68ec5511b9c168060James Smart * 41349e4f5e29610162fd426366f3b29e3cc6e575b858James Smart */ 41359e4f5e29610162fd426366f3b29e3cc6e575b858James Smartstatic void 41369e4f5e29610162fd426366f3b29e3cc6e575b858James Smartfc_bsg_remove(struct request_queue *q) 41379e4f5e29610162fd426366f3b29e3cc6e575b858James Smart{ 41389e4f5e29610162fd426366f3b29e3cc6e575b858James Smart if (q) { 41399e4f5e29610162fd426366f3b29e3cc6e575b858James Smart bsg_unregister_queue(q); 41409e4f5e29610162fd426366f3b29e3cc6e575b858James Smart blk_cleanup_queue(q); 41419e4f5e29610162fd426366f3b29e3cc6e575b858James Smart } 41429e4f5e29610162fd426366f3b29e3cc6e575b858James Smart} 41439e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41449e4f5e29610162fd426366f3b29e3cc6e575b858James Smart 41459ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames Smart/* Original Author: Martin Hicks */ 41469ef3e4a4527e1f65b8776287c6d4fd1fca5ba98fJames SmartMODULE_AUTHOR("James Smart"); 41471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("FC Transport Attributes"); 41481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 41491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 41501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(fc_transport_init); 41511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(fc_transport_exit); 4152