scsi_transport_fc.c revision 84314fd4740ad73550c76dee4a9578979d84af48
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 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 * 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2004-2005 James Smart, Emulex Corporation 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Rewrite for host, target, device, and remote port attributes, 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * statistics, and service functions... 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 294e57b6817880946a3a78d5d8cad1ace363f7e449Tim Schmielau#include <linux/sched.h> /* workqueue stuff, HZ */ 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_device.h> 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_host.h> 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_transport.h> 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <scsi/scsi_transport_fc.h> 34c829c394165f981d49f05a9be228404d7a9398d4James Smart#include <scsi/scsi_cmnd.h> 3584314fd4740ad73550c76dee4a9578979d84af48James Smart#include <linux/netlink.h> 3684314fd4740ad73550c76dee4a9578979d84af48James Smart#include <net/netlink.h> 3784314fd4740ad73550c76dee4a9578979d84af48James Smart#include <scsi/scsi_netlink_fc.h> 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "scsi_priv.h" 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 40aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int fc_queue_work(struct Scsi_Host *, struct work_struct *); 41aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redefine so that we can have same named attributes in the 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * sdev/starget/host objects. 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \ 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct class_device_attribute class_device_attr_##_prefix##_##_name = \ 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ATTR(_name,_mode,_show,_store) 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_enum_name_search(title, table_type, table) \ 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic const char *get_fc_##title##_name(enum table_type table_key) \ 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name = NULL; \ 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 566391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (table[i].value == table_key) { \ 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = table[i].name; \ 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return name; \ 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_enum_name_match(title, table_type, table) \ 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int get_fc_##title##_match(const char *table_key, \ 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum table_type *value) \ 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 716391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (strncmp(table_key, table[i].name, \ 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds table[i].matchlen) == 0) { \ 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *value = table[i].value; \ 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; /* success */ \ 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 1; /* failure */ \ 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_port_type values to ascii string name */ 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct { 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_port_type value; 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_type_names[] = { 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_UNKNOWN, "Unknown" }, 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_OTHER, "Other" }, 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NOTPRESENT, "Not Present" }, 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" }, 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" }, 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_LPORT, "LPort (private loop)" }, 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" }, 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(port_type, fc_port_type, fc_port_type_names) 961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_PORTTYPE_MAX_NAMELEN 50 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9984314fd4740ad73550c76dee4a9578979d84af48James Smart/* Convert fc_host_event_code values to ascii string name */ 10084314fd4740ad73550c76dee4a9578979d84af48James Smartstatic const struct { 10184314fd4740ad73550c76dee4a9578979d84af48James Smart enum fc_host_event_code value; 10284314fd4740ad73550c76dee4a9578979d84af48James Smart char *name; 10384314fd4740ad73550c76dee4a9578979d84af48James Smart} fc_host_event_code_names[] = { 10484314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LIP, "lip" }, 10584314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINKUP, "link_up" }, 10684314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINKDOWN, "link_down" }, 10784314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LIPRESET, "lip_reset" }, 10884314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_RSCN, "rscn" }, 10984314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" }, 11084314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_UNKNOWN, "port_unknown" }, 11184314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_ONLINE, "port_online" }, 11284314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_OFFLINE, "port_offline" }, 11384314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_PORT_FABRIC, "port_fabric" }, 11484314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_LINK_UNKNOWN, "link_unknown" }, 11584314fd4740ad73550c76dee4a9578979d84af48James Smart { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" }, 11684314fd4740ad73550c76dee4a9578979d84af48James Smart}; 11784314fd4740ad73550c76dee4a9578979d84af48James Smartfc_enum_name_search(host_event_code, fc_host_event_code, 11884314fd4740ad73550c76dee4a9578979d84af48James Smart fc_host_event_code_names) 11984314fd4740ad73550c76dee4a9578979d84af48James Smart#define FC_HOST_EVENT_CODE_MAX_NAMELEN 30 12084314fd4740ad73550c76dee4a9578979d84af48James Smart 12184314fd4740ad73550c76dee4a9578979d84af48James Smart 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_port_state values to ascii string name */ 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct { 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_port_state value; 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_state_names[] = { 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_UNKNOWN, "Unknown" }, 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_NOTPRESENT, "Not Present" }, 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_ONLINE, "Online" }, 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_OFFLINE, "Offline" }, 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_BLOCKED, "Blocked" }, 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_BYPASSED, "Bypassed" }, 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" }, 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_LINKDOWN, "Linkdown" }, 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_ERROR, "Error" }, 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSTATE_LOOPBACK, "Loopback" }, 13742e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com { FC_PORTSTATE_DELETED, "Deleted" }, 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(port_state, fc_port_state, fc_port_state_names) 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_PORTSTATE_MAX_NAMELEN 20 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert fc_tgtid_binding_type values to ascii string name */ 1440ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_tgtid_binding_type value; 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int matchlen; 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_tgtid_binding_type_names[] = { 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_NONE, "none", 4 }, 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 }, 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 }, 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 }, 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type, 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_tgtid_binding_type_names) 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type, 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_tgtid_binding_type_names) 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_BINDTYPE_MAX_NAMELEN 30 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_bitfield_name_search(title, table) \ 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsget_fc_##title##_names(u32 table_key, char *buf) \ 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *prefix = ""; \ 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ssize_t len = 0; \ 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i; \ 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 1696391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(table); i++) { \ 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (table[i].value & table_key) { \ 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "%s%s", \ 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prefix, table[i].name); \ 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prefix = ", "; \ 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "\n"); \ 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return len; \ 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert FC_COS bit values to ascii string name */ 1820ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_cos_names[] = { 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS1, "Class 1" }, 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS2, "Class 2" }, 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS3, "Class 3" }, 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS4, "Class 4" }, 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_COS_CLASS6, "Class 6" }, 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_bitfield_name_search(cos, fc_cos_names) 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert FC_PORTSPEED bit values to ascii string name */ 1960ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_port_speed_names[] = { 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_1GBIT, "1 Gbit" }, 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_2GBIT, "2 Gbit" }, 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_4GBIT, "4 Gbit" }, 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_10GBIT, "10 Gbit" }, 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" }, 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_bitfield_name_search(port_speed, fc_port_speed_names) 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_fc4s (char *buf, u8 *fc4_list) 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int i, len=0; 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++) 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len , "0x%02x ", *fc4_list); 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len += sprintf(buf + len, "\n"); 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return len; 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Convert FC_RPORT_ROLE bit values to ascii string name */ 2220ad78200baf1f85a21e6b26c225717ad80980d8fArjan van de Venstatic const struct { 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u32 value; 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *name; 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} fc_remote_port_role_names[] = { 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" }, 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" }, 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { FC_RPORT_ROLE_IP_PORT, "IP Port" }, 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names) 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Define roles that are specific to port_id. Values are relative to ROLE_MASK. 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_WELLKNOWN_PORTID_MASK 0xfffff0 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_WELLKNOWN_ROLE_MASK 0x00000f 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_FPORT_PORTID 0x00000e 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_FABCTLR_PORTID 0x00000d 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_DIRSRVR_PORTID 0x00000c 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_TIMESRVR_PORTID 0x00000b 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_MGMTSRVR_PORTID 0x00000a 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 24419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstatic void fc_timeout_deleted_rport(void *data); 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void fc_scsi_scan_rport(void *data); 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Attribute counts pre object type... 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Increase these values if you add attributes 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_STARGET_NUM_ATTRS 3 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define FC_RPORT_NUM_ATTRS 9 253ad139a2f56e5789aa8a9f74e3600a7f854a38de9Andreas Herrmann#define FC_HOST_NUM_ATTRS 17 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct fc_internal { 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct scsi_transport_template t; 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_function_template *f; 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For attributes : each object has : 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * An array of the actual attributes structures 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * An array of null-terminated pointers to the attribute 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * structures - used for mid-layer interaction. 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The attribute containers for the starget and host are are 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * part of the midlayer. As the remote port is specific to the 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc transport, we must provide the attribute container. 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute private_starget_attrs[ 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FC_STARGET_NUM_ATTRS]; 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1]; 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS]; 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1]; 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct transport_container rport_attr_cont; 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS]; 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1]; 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 283d0a7e574007fd547d72ec693bfa35778623d0738James Bottomleystatic int fc_target_setup(struct transport_container *tc, struct device *dev, 284d0a7e574007fd547d72ec693bfa35778623d0738James Bottomley struct class_device *cdev) 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct scsi_target *starget = to_scsi_target(dev); 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = starget_to_rport(starget); 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * if parent is remote port, use values from remote port. 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Otherwise, this host uses the fc_transport, but not the 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * remote port interface. As such, initialize to known non-values. 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport) { 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_node_name(starget) = rport->node_name; 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_name(starget) = rport->port_name; 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_id(starget) = rport->port_id; 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_node_name(starget) = -1; 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_name(starget) = -1; 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_port_id(starget) = -1; 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_transport_class, 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_transport", 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_target_setup, 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 313d0a7e574007fd547d72ec693bfa35778623d0738James Bottomleystatic int fc_host_setup(struct transport_container *tc, struct device *dev, 314d0a7e574007fd547d72ec693bfa35778623d0738James Bottomley struct class_device *cdev) 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = dev_to_shost(dev); 317aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Set default values easily detected by the midlayer as 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * failure cases. The scsi lldd is responsible for initializing 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * all transport attributes to valid values per host. 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 324aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->node_name = -1; 325aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_name = -1; 326aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->permanent_port_name = -1; 327aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->supported_classes = FC_COS_UNSPECIFIED; 328aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->supported_fc4s, 0, 329aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->supported_fc4s)); 330aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN; 331aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->maxframe_size = -1; 332aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->serial_number, 0, 333aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->serial_number)); 334aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 335aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_id = -1; 336aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_type = FC_PORTTYPE_UNKNOWN; 337aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->port_state = FC_PORTSTATE_UNKNOWN; 338aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart memset(fc_host->active_fc4s, 0, 339aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart sizeof(fc_host->active_fc4s)); 340aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->speed = FC_PORTSPEED_UNKNOWN; 341aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->fabric_name = -1; 342b8d08210126a7b769b857720a59721a453a57a1eJames Smart memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name)); 343b8d08210126a7b769b857720a59721a453a57a1eJames Smart memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname)); 344aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 345aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN; 346aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 347aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_LIST_HEAD(&fc_host->rports); 348aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_LIST_HEAD(&fc_host->rport_bindings); 349aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->next_rport_number = 0; 350aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->next_target_id = 0; 351aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 352aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d", 353aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart shost->host_no); 354aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q = create_singlethread_workqueue( 355aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q_name); 356aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host->work_q) 357aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -ENOMEM; 358aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 359aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d", 360aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart shost->host_no); 361aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->devloss_work_q = create_singlethread_workqueue( 362aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->devloss_work_q_name); 363aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host->devloss_work_q) { 364aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(fc_host->work_q); 365aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q = NULL; 366aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -ENOMEM; 367aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 368aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_host_class, 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_host", 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_setup, 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup and Remove actions for remote ports are handled 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in the service functions below. 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic DECLARE_TRANSPORT_CLASS(fc_rport_class, 3831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "fc_remote_ports", 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 3851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL, 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL); 3871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Module Parameters 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * dev_loss_tmo: the default number of seconds that the FC transport 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * should insulate the loss of a remote port. 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT. 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3971c9e16e47a22c61d99aabb1c154e5106ddbf3575James Smartstatic unsigned int fc_dev_loss_tmo = 60; /* seconds */ 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR); 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_PARM_DESC(dev_loss_tmo, 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "Maximum number of seconds that the FC transport should" 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds " insulate the loss of a remote port. Once this value is" 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds " exceeded, the scsi target is removed. Value should be" 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT."); 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 40684314fd4740ad73550c76dee4a9578979d84af48James Smart/** 40784314fd4740ad73550c76dee4a9578979d84af48James Smart * Netlink Infrastructure 40884314fd4740ad73550c76dee4a9578979d84af48James Smart **/ 40984314fd4740ad73550c76dee4a9578979d84af48James Smart 41084314fd4740ad73550c76dee4a9578979d84af48James Smartstatic atomic_t fc_event_seq; 41184314fd4740ad73550c76dee4a9578979d84af48James Smart 41284314fd4740ad73550c76dee4a9578979d84af48James Smart/** 41384314fd4740ad73550c76dee4a9578979d84af48James Smart * fc_get_event_number - Obtain the next sequential FC event number 41484314fd4740ad73550c76dee4a9578979d84af48James Smart * 41584314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 41684314fd4740ad73550c76dee4a9578979d84af48James Smart * We could have inline'd this, but it would have required fc_event_seq to 41784314fd4740ad73550c76dee4a9578979d84af48James Smart * be exposed. For now, live with the subroutine call. 41884314fd4740ad73550c76dee4a9578979d84af48James Smart * Atomic used to avoid lock/unlock... 41984314fd4740ad73550c76dee4a9578979d84af48James Smart **/ 42084314fd4740ad73550c76dee4a9578979d84af48James Smartu32 42184314fd4740ad73550c76dee4a9578979d84af48James Smartfc_get_event_number(void) 42284314fd4740ad73550c76dee4a9578979d84af48James Smart{ 42384314fd4740ad73550c76dee4a9578979d84af48James Smart return atomic_add_return(1, &fc_event_seq); 42484314fd4740ad73550c76dee4a9578979d84af48James Smart} 42584314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_get_event_number); 42684314fd4740ad73550c76dee4a9578979d84af48James Smart 42784314fd4740ad73550c76dee4a9578979d84af48James Smart 42884314fd4740ad73550c76dee4a9578979d84af48James Smart/** 42984314fd4740ad73550c76dee4a9578979d84af48James Smart * fc_host_post_event - called to post an even on an fc_host. 43084314fd4740ad73550c76dee4a9578979d84af48James Smart * 43184314fd4740ad73550c76dee4a9578979d84af48James Smart * @shost: host the event occurred on 43284314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_number: fc event number obtained from get_fc_event_number() 43384314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_code: fc_host event being posted 43484314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_data: 32bits of data for the event being posted 43584314fd4740ad73550c76dee4a9578979d84af48James Smart * 43684314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 43784314fd4740ad73550c76dee4a9578979d84af48James Smart * This routine assumes no locks are held on entry. 43884314fd4740ad73550c76dee4a9578979d84af48James Smart **/ 43984314fd4740ad73550c76dee4a9578979d84af48James Smartvoid 44084314fd4740ad73550c76dee4a9578979d84af48James Smartfc_host_post_event(struct Scsi_Host *shost, u32 event_number, 44184314fd4740ad73550c76dee4a9578979d84af48James Smart enum fc_host_event_code event_code, u32 event_data) 44284314fd4740ad73550c76dee4a9578979d84af48James Smart{ 44384314fd4740ad73550c76dee4a9578979d84af48James Smart struct sk_buff *skb; 44484314fd4740ad73550c76dee4a9578979d84af48James Smart struct nlmsghdr *nlh; 44584314fd4740ad73550c76dee4a9578979d84af48James Smart struct fc_nl_event *event; 44684314fd4740ad73550c76dee4a9578979d84af48James Smart const char *name; 44784314fd4740ad73550c76dee4a9578979d84af48James Smart u32 len, skblen; 44884314fd4740ad73550c76dee4a9578979d84af48James Smart int err; 44984314fd4740ad73550c76dee4a9578979d84af48James Smart 45084314fd4740ad73550c76dee4a9578979d84af48James Smart if (!scsi_nl_sock) { 45184314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOENT; 45284314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail; 45384314fd4740ad73550c76dee4a9578979d84af48James Smart } 45484314fd4740ad73550c76dee4a9578979d84af48James Smart 45584314fd4740ad73550c76dee4a9578979d84af48James Smart len = FC_NL_MSGALIGN(sizeof(*event)); 45684314fd4740ad73550c76dee4a9578979d84af48James Smart skblen = NLMSG_SPACE(len); 45784314fd4740ad73550c76dee4a9578979d84af48James Smart 45884314fd4740ad73550c76dee4a9578979d84af48James Smart skb = alloc_skb(skblen, GFP_KERNEL); 45984314fd4740ad73550c76dee4a9578979d84af48James Smart if (!skb) { 46084314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 46184314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail; 46284314fd4740ad73550c76dee4a9578979d84af48James Smart } 46384314fd4740ad73550c76dee4a9578979d84af48James Smart 46484314fd4740ad73550c76dee4a9578979d84af48James Smart nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, 46584314fd4740ad73550c76dee4a9578979d84af48James Smart skblen - sizeof(*nlh), 0); 46684314fd4740ad73550c76dee4a9578979d84af48James Smart if (!nlh) { 46784314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 46884314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail_skb; 46984314fd4740ad73550c76dee4a9578979d84af48James Smart } 47084314fd4740ad73550c76dee4a9578979d84af48James Smart event = NLMSG_DATA(nlh); 47184314fd4740ad73550c76dee4a9578979d84af48James Smart 47284314fd4740ad73550c76dee4a9578979d84af48James Smart INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 47384314fd4740ad73550c76dee4a9578979d84af48James Smart FC_NL_ASYNC_EVENT, len); 47484314fd4740ad73550c76dee4a9578979d84af48James Smart event->seconds = get_seconds(); 47584314fd4740ad73550c76dee4a9578979d84af48James Smart event->vendor_id = 0; 47684314fd4740ad73550c76dee4a9578979d84af48James Smart event->host_no = shost->host_no; 47784314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_datalen = sizeof(u32); /* bytes */ 47884314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_num = event_number; 47984314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_code = event_code; 48084314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_data = event_data; 48184314fd4740ad73550c76dee4a9578979d84af48James Smart 48284314fd4740ad73550c76dee4a9578979d84af48James Smart err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS); 48384314fd4740ad73550c76dee4a9578979d84af48James Smart if (err && (err != -ESRCH)) /* filter no recipient errors */ 48484314fd4740ad73550c76dee4a9578979d84af48James Smart /* nlmsg_multicast already kfree_skb'd */ 48584314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_fail; 48684314fd4740ad73550c76dee4a9578979d84af48James Smart 48784314fd4740ad73550c76dee4a9578979d84af48James Smart return; 48884314fd4740ad73550c76dee4a9578979d84af48James Smart 48984314fd4740ad73550c76dee4a9578979d84af48James Smartsend_fail_skb: 49084314fd4740ad73550c76dee4a9578979d84af48James Smart kfree_skb(skb); 49184314fd4740ad73550c76dee4a9578979d84af48James Smartsend_fail: 49284314fd4740ad73550c76dee4a9578979d84af48James Smart name = get_fc_host_event_code_name(event_code); 49384314fd4740ad73550c76dee4a9578979d84af48James Smart printk(KERN_WARNING 49484314fd4740ad73550c76dee4a9578979d84af48James Smart "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", 49584314fd4740ad73550c76dee4a9578979d84af48James Smart __FUNCTION__, shost->host_no, 49684314fd4740ad73550c76dee4a9578979d84af48James Smart (name) ? name : "<unknown>", event_data, err); 49784314fd4740ad73550c76dee4a9578979d84af48James Smart return; 49884314fd4740ad73550c76dee4a9578979d84af48James Smart} 49984314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_host_post_event); 50084314fd4740ad73550c76dee4a9578979d84af48James Smart 50184314fd4740ad73550c76dee4a9578979d84af48James Smart 50284314fd4740ad73550c76dee4a9578979d84af48James Smart/** 50384314fd4740ad73550c76dee4a9578979d84af48James Smart * fc_host_post_vendor_event - called to post a vendor unique event on 50484314fd4740ad73550c76dee4a9578979d84af48James Smart * a fc_host 50584314fd4740ad73550c76dee4a9578979d84af48James Smart * 50684314fd4740ad73550c76dee4a9578979d84af48James Smart * @shost: host the event occurred on 50784314fd4740ad73550c76dee4a9578979d84af48James Smart * @event_number: fc event number obtained from get_fc_event_number() 50884314fd4740ad73550c76dee4a9578979d84af48James Smart * @data_len: amount, in bytes, of vendor unique data 50984314fd4740ad73550c76dee4a9578979d84af48James Smart * @data_buf: pointer to vendor unique data 51084314fd4740ad73550c76dee4a9578979d84af48James Smart * 51184314fd4740ad73550c76dee4a9578979d84af48James Smart * Notes: 51284314fd4740ad73550c76dee4a9578979d84af48James Smart * This routine assumes no locks are held on entry. 51384314fd4740ad73550c76dee4a9578979d84af48James Smart **/ 51484314fd4740ad73550c76dee4a9578979d84af48James Smartvoid 51584314fd4740ad73550c76dee4a9578979d84af48James Smartfc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, 51684314fd4740ad73550c76dee4a9578979d84af48James Smart u32 data_len, char * data_buf, u32 vendor_id) 51784314fd4740ad73550c76dee4a9578979d84af48James Smart{ 51884314fd4740ad73550c76dee4a9578979d84af48James Smart struct sk_buff *skb; 51984314fd4740ad73550c76dee4a9578979d84af48James Smart struct nlmsghdr *nlh; 52084314fd4740ad73550c76dee4a9578979d84af48James Smart struct fc_nl_event *event; 52184314fd4740ad73550c76dee4a9578979d84af48James Smart u32 len, skblen; 52284314fd4740ad73550c76dee4a9578979d84af48James Smart int err; 52384314fd4740ad73550c76dee4a9578979d84af48James Smart 52484314fd4740ad73550c76dee4a9578979d84af48James Smart if (!scsi_nl_sock) { 52584314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOENT; 52684314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail; 52784314fd4740ad73550c76dee4a9578979d84af48James Smart } 52884314fd4740ad73550c76dee4a9578979d84af48James Smart 52984314fd4740ad73550c76dee4a9578979d84af48James Smart len = FC_NL_MSGALIGN(sizeof(*event) + data_len); 53084314fd4740ad73550c76dee4a9578979d84af48James Smart skblen = NLMSG_SPACE(len); 53184314fd4740ad73550c76dee4a9578979d84af48James Smart 53284314fd4740ad73550c76dee4a9578979d84af48James Smart skb = alloc_skb(skblen, GFP_KERNEL); 53384314fd4740ad73550c76dee4a9578979d84af48James Smart if (!skb) { 53484314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 53584314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail; 53684314fd4740ad73550c76dee4a9578979d84af48James Smart } 53784314fd4740ad73550c76dee4a9578979d84af48James Smart 53884314fd4740ad73550c76dee4a9578979d84af48James Smart nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, 53984314fd4740ad73550c76dee4a9578979d84af48James Smart skblen - sizeof(*nlh), 0); 54084314fd4740ad73550c76dee4a9578979d84af48James Smart if (!nlh) { 54184314fd4740ad73550c76dee4a9578979d84af48James Smart err = -ENOBUFS; 54284314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail_skb; 54384314fd4740ad73550c76dee4a9578979d84af48James Smart } 54484314fd4740ad73550c76dee4a9578979d84af48James Smart event = NLMSG_DATA(nlh); 54584314fd4740ad73550c76dee4a9578979d84af48James Smart 54684314fd4740ad73550c76dee4a9578979d84af48James Smart INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, 54784314fd4740ad73550c76dee4a9578979d84af48James Smart FC_NL_ASYNC_EVENT, len); 54884314fd4740ad73550c76dee4a9578979d84af48James Smart event->seconds = get_seconds(); 54984314fd4740ad73550c76dee4a9578979d84af48James Smart event->vendor_id = vendor_id; 55084314fd4740ad73550c76dee4a9578979d84af48James Smart event->host_no = shost->host_no; 55184314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_datalen = data_len; /* bytes */ 55284314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_num = event_number; 55384314fd4740ad73550c76dee4a9578979d84af48James Smart event->event_code = FCH_EVT_VENDOR_UNIQUE; 55484314fd4740ad73550c76dee4a9578979d84af48James Smart memcpy(&event->event_data, data_buf, data_len); 55584314fd4740ad73550c76dee4a9578979d84af48James Smart 55684314fd4740ad73550c76dee4a9578979d84af48James Smart err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS); 55784314fd4740ad73550c76dee4a9578979d84af48James Smart if (err && (err != -ESRCH)) /* filter no recipient errors */ 55884314fd4740ad73550c76dee4a9578979d84af48James Smart /* nlmsg_multicast already kfree_skb'd */ 55984314fd4740ad73550c76dee4a9578979d84af48James Smart goto send_vendor_fail; 56084314fd4740ad73550c76dee4a9578979d84af48James Smart 56184314fd4740ad73550c76dee4a9578979d84af48James Smart return; 56284314fd4740ad73550c76dee4a9578979d84af48James Smart 56384314fd4740ad73550c76dee4a9578979d84af48James Smartsend_vendor_fail_skb: 56484314fd4740ad73550c76dee4a9578979d84af48James Smart kfree_skb(skb); 56584314fd4740ad73550c76dee4a9578979d84af48James Smartsend_vendor_fail: 56684314fd4740ad73550c76dee4a9578979d84af48James Smart printk(KERN_WARNING 56784314fd4740ad73550c76dee4a9578979d84af48James Smart "%s: Dropped Event : host %d vendor_unique - err %d\n", 56884314fd4740ad73550c76dee4a9578979d84af48James Smart __FUNCTION__, shost->host_no, err); 56984314fd4740ad73550c76dee4a9578979d84af48James Smart return; 57084314fd4740ad73550c76dee4a9578979d84af48James Smart} 57184314fd4740ad73550c76dee4a9578979d84af48James SmartEXPORT_SYMBOL(fc_host_post_vendor_event); 57284314fd4740ad73550c76dee4a9578979d84af48James Smart 57384314fd4740ad73550c76dee4a9578979d84af48James Smart 5741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic __init int fc_transport_init(void) 5761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 57784314fd4740ad73550c76dee4a9578979d84af48James Smart int error; 57884314fd4740ad73550c76dee4a9578979d84af48James Smart 57984314fd4740ad73550c76dee4a9578979d84af48James Smart atomic_set(&fc_event_seq, 0); 58084314fd4740ad73550c76dee4a9578979d84af48James Smart 58184314fd4740ad73550c76dee4a9578979d84af48James Smart error = transport_class_register(&fc_host_class); 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return error; 5841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds error = transport_class_register(&fc_rport_class); 5851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) 5861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return error; 5871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return transport_class_register(&fc_transport_class); 5881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit fc_transport_exit(void) 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 5921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_transport_class); 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_rport_class); 5941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_class_unregister(&fc_host_class); 5951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 5961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FC Remote Port Attribute Management 5991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 6001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_show_function(field, format_string, sz, cast) \ 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_rport_##field (struct class_device *cdev, char *buf) \ 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); \ 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); \ 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 60819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((i->f->get_rport_##field) && \ 60919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com !((rport->port_state == FC_PORTSTATE_BLOCKED) || \ 61042e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || \ 61119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \ 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_rport_##field(rport); \ 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast rport->field); \ 6141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_store_function(field) \ 6171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstore_fc_rport_##field(struct class_device *cdev, const char *buf, \ 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val; \ 6221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); \ 6231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); \ 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 62519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \ 62642e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || \ 62719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \ 62819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return -EBUSY; \ 6291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds val = simple_strtoul(buf, NULL, 0); \ 6301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->set_rport_##field(rport, val); \ 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rd_attr(field, format_string, sz) \ 6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, ) \ 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \ 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rd_attr_cast(field, format_string, sz, cast) \ 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, (cast)) \ 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \ 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_rport_rw_attr(field, format_string, sz) \ 6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_show_function(field, format_string, sz, ) \ 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_rport_store_function(field) \ 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \ 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, \ 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_rport_##field) 6501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_show_function(field, format_string, sz, cast) \ 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_rport_##field (struct class_device *cdev, char *buf) \ 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 6561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); \ 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast rport->field); \ 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_attr(field, format_string, sz) \ 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_rport_show_function(field, format_string, sz, ) \ 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \ 6631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \ 6661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_rport_show_function(field, format_string, sz, (cast)) \ 6671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \ 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##field, NULL) 6691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_rport_rd_enum_attr(title, maxlen) \ 6721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 6731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_rport_##title (struct class_device *cdev, char *buf) \ 6741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 6751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); \ 6761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; \ 6771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_##title##_name(rport->title); \ 6781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) \ 6791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; \ 6801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, maxlen, "%s\n", name); \ 6811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 6821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \ 6831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_##title, NULL) 6841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_RPORT_ATTRIBUTE_RD(field) \ 6871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count] = class_device_attr_rport_##field; \ 6881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 6891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 6901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 6911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_rport_##field) \ 6921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 6931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \ 6951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count] = class_device_attr_rport_##field; \ 6961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 6971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 6981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 6991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 7001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_RPORT_ATTRIBUTE_RW(field) \ 7021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count] = class_device_attr_rport_##field; \ 7031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_rport_##field) { \ 7041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].attr.mode = S_IRUGO; \ 7051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_rport_attrs[count].store = NULL; \ 7061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 7071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = &i->private_rport_attrs[count]; \ 7081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_rport_##field) \ 7091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 7101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* The FC Transport Remote Port Attributes: */ 7131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Fixed Remote Port Attributes */ 7151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20); 7171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 7191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_rport_supported_classes (struct class_device *cdev, char *buf) 7201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); 7221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->supported_classes == FC_COS_UNSPECIFIED) 7231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unspecified\n"); 7241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_cos_names(rport->supported_classes, buf); 7251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO, 7271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_supported_classes, NULL); 7281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Dynamic Remote Port Attributes */ 7301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 73119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com/* 73219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * dev_loss_tmo attribute 73319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 73419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comfc_rport_show_function(dev_loss_tmo, "%d\n", 20, ) 73519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstatic ssize_t 73619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstore_fc_rport_dev_loss_tmo(struct class_device *cdev, const char *buf, 73719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com size_t count) 73819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com{ 73919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com int val; 74019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct fc_rport *rport = transport_class_to_rport(cdev); 74119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct Scsi_Host *shost = rport_to_shost(rport); 74219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct fc_internal *i = to_fc_internal(shost->transportt); 74319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) || 74442e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_DELETED) || 74519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->port_state == FC_PORTSTATE_NOTPRESENT)) 74619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return -EBUSY; 74719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com val = simple_strtoul(buf, NULL, 0); 74819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)) 74919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return -EINVAL; 75019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com i->f->set_rport_dev_loss_tmo(rport, val); 75119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return count; 75219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com} 75319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstatic FC_CLASS_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR, 75419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo); 7551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Private Remote Port Attributes */ 7581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 7601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 7611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(port_id, "0x%06x\n", 20); 7621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 7641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_rport_roles (struct class_device *cdev, char *buf) 7651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 7661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = transport_class_to_rport(cdev); 7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* identify any roles that are port_id specific */ 7691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((rport->port_id != -1) && 7701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (rport->port_id & FC_WELLKNOWN_PORTID_MASK) == 7711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds FC_WELLKNOWN_PORTID_MASK) { 7721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) { 7731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_FPORT_PORTID: 7741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Fabric Port\n"); 7751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_FABCTLR_PORTID: 7761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Fabric Controller\n"); 7771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_DIRSRVR_PORTID: 7781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Directory Server\n"); 7791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TIMESRVR_PORTID: 7801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Time Server\n"); 7811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_MGMTSRVR_PORTID: 7821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Management Server\n"); 7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds default: 7841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 30, "Unknown Fabric Entity\n"); 7851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 7871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->roles == FC_RPORT_ROLE_UNKNOWN) 7881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_remote_port_roles_names(rport->roles, buf); 7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 7911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 7921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO, 7931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_rport_roles, NULL); 7941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); 7961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_rport_rd_attr(scsi_target_id, "%d\n", 20); 7971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 7991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 8011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FC SCSI Target Attribute Management 8021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 8031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 8051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Note: in the target show function we recognize when the remote 8061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * port is in the heirarchy and do not allow the driver to get 8071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * involved in sysfs functions. The driver only gets involved if 8081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it's the "old" style that doesn't use rports. 8091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 8101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_show_function(field, format_string, sz, cast) \ 8111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 8121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_starget_##field (struct class_device *cdev, char *buf) \ 8131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 8141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct scsi_target *starget = transport_class_to_starget(cdev); \ 8151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \ 8161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 8171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = starget_to_rport(starget); \ 8181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport) \ 8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_##field(starget) = rport->field; \ 8201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else if (i->f->get_starget_##field) \ 8211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_starget_##field(starget); \ 8221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, \ 8231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds cast fc_starget_##field(starget)); \ 8241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_rd_attr(field, format_string, sz) \ 8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_show_function(field, format_string, sz, ) \ 8281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \ 8291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_starget_##field, NULL) 8301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_starget_rd_attr_cast(field, format_string, sz, cast) \ 8321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_starget_show_function(field, format_string, sz, (cast)) \ 8331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \ 8341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_starget_##field, NULL) 8351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_STARGET_ATTRIBUTE_RD(field) \ 8371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count] = class_device_attr_starget_##field; \ 8381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].attr.mode = S_IRUGO; \ 8391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].store = NULL; \ 8401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = &i->private_starget_attrs[count]; \ 8411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_starget_##field) \ 8421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 8431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_STARGET_ATTRIBUTE_RW(field) \ 8451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count] = class_device_attr_starget_##field; \ 8461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_starget_##field) { \ 8471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].attr.mode = S_IRUGO; \ 8481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_starget_attrs[count].store = NULL; \ 8491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 8501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = &i->private_starget_attrs[count]; \ 8511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_starget_##field) \ 8521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 8531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* The FC Transport SCSI Target Attributes: */ 8551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 8561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 8571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_starget_rd_attr(port_id, "0x%06x\n", 20); 8581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 8611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Host Attribute Management 8621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 8631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_show_function(field, format_string, sz, cast) \ 8651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 8661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_##field (struct class_device *cdev, char *buf) \ 8671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 8681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); \ 8691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 8701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_##field) \ 8711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_##field(shost); \ 8721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ 8731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_store_function(field) \ 8761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 8771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstore_fc_host_##field(struct class_device *cdev, const char *buf, \ 8781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) \ 8791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 8801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int val; \ 8811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); \ 8821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 8831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 8841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds val = simple_strtoul(buf, NULL, 0); \ 8851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->set_host_##field(shost, val); \ 8861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; \ 8871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 8881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 889b8d08210126a7b769b857720a59721a453a57a1eJames Smart#define fc_host_store_str_function(field, slen) \ 890b8d08210126a7b769b857720a59721a453a57a1eJames Smartstatic ssize_t \ 891b8d08210126a7b769b857720a59721a453a57a1eJames Smartstore_fc_host_##field(struct class_device *cdev, const char *buf, \ 892b8d08210126a7b769b857720a59721a453a57a1eJames Smart size_t count) \ 893b8d08210126a7b769b857720a59721a453a57a1eJames Smart{ \ 894b8d08210126a7b769b857720a59721a453a57a1eJames Smart struct Scsi_Host *shost = transport_class_to_shost(cdev); \ 895b8d08210126a7b769b857720a59721a453a57a1eJames Smart struct fc_internal *i = to_fc_internal(shost->transportt); \ 896b8d08210126a7b769b857720a59721a453a57a1eJames Smart unsigned int cnt=count; \ 897b8d08210126a7b769b857720a59721a453a57a1eJames Smart \ 898b8d08210126a7b769b857720a59721a453a57a1eJames Smart /* count may include a LF at end of string */ \ 899b8d08210126a7b769b857720a59721a453a57a1eJames Smart if (buf[cnt-1] == '\n') \ 900b8d08210126a7b769b857720a59721a453a57a1eJames Smart cnt--; \ 901b8d08210126a7b769b857720a59721a453a57a1eJames Smart if (cnt > ((slen) - 1)) \ 902b8d08210126a7b769b857720a59721a453a57a1eJames Smart return -EINVAL; \ 903b8d08210126a7b769b857720a59721a453a57a1eJames Smart memcpy(fc_host_##field(shost), buf, cnt); \ 904b8d08210126a7b769b857720a59721a453a57a1eJames Smart i->f->set_host_##field(shost); \ 905b8d08210126a7b769b857720a59721a453a57a1eJames Smart return count; \ 906b8d08210126a7b769b857720a59721a453a57a1eJames Smart} 907b8d08210126a7b769b857720a59721a453a57a1eJames Smart 9081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_attr(field, format_string, sz) \ 9091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, ) \ 9101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \ 9111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 9121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_attr_cast(field, format_string, sz, cast) \ 9141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, (cast)) \ 9151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \ 9161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 9171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rw_attr(field, format_string, sz) \ 9191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_show_function(field, format_string, sz, ) \ 9201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_store_function(field) \ 9211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \ 9221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, \ 9231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_host_##field) 9241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_rd_enum_attr(title, maxlen) \ 9261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 9271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_##title (struct class_device *cdev, char *buf) \ 9281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 9291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); \ 9301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); \ 9311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; \ 9321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_##title) \ 9331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_##title(shost); \ 9341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_##title##_name(fc_host_##title(shost)); \ 9351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) \ 9361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; \ 9371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, maxlen, "%s\n", name); \ 9381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 9391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL) 9401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_HOST_ATTRIBUTE_RD(field) \ 9421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count] = class_device_attr_host_##field; \ 9431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 9441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 9451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 9461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_host_##field) \ 9471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 9481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_HOST_ATTRIBUTE_RW(field) \ 9501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count] = class_device_attr_host_##field; \ 9511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!i->f->set_host_##field) { \ 9521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 9531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 9541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 9551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 9561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->show_host_##field) \ 9571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 9581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_show_function(field, format_string, sz, cast) \ 9611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t \ 9621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_##field (struct class_device *cdev, char *buf) \ 9631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 9641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); \ 9651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \ 9661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 9671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_rd_attr(field, format_string, sz) \ 9691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_host_show_function(field, format_string, sz, ) \ 9701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \ 9711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 9721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \ 9741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_private_host_show_function(field, format_string, sz, (cast)) \ 9751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \ 9761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_##field, NULL) 9771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \ 9791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count] = class_device_attr_host_##field; \ 9801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].attr.mode = S_IRUGO; \ 9811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count].store = NULL; \ 9821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 9831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count++ 9841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \ 98691ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez{ \ 9871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->private_host_attrs[count] = class_device_attr_host_##field; \ 9881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = &i->private_host_attrs[count]; \ 98991ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez count++; \ 99091ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez} 9911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Fixed Host Attributes */ 9941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 9951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 9961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_supported_classes (struct class_device *cdev, char *buf) 9971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 9981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 9991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED) 10011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unspecified\n"); 10021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_cos_names(fc_host_supported_classes(shost), buf); 10041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO, 10061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_classes, NULL); 10071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 10091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_supported_fc4s (struct class_device *cdev, char *buf) 10101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 10121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost)); 10131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO, 10151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_fc4s, NULL); 10161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 10181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_supported_speeds (struct class_device *cdev, char *buf) 10191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 10211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN) 10231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 10241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf); 10261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO, 10281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_supported_speeds, NULL); 10291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long); 10321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long); 10336b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmannfc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20, 10346b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmann unsigned long long); 10351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20); 10361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1)); 10371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Dynamic Host Attributes */ 10401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 10421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_active_fc4s (struct class_device *cdev, char *buf) 10431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 10451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 10461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_active_fc4s) 10481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_active_fc4s(shost); 10491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost)); 10511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO, 10531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_active_fc4s, NULL); 10541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 10561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_host_speed (struct class_device *cdev, char *buf) 10571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 10591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 10601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_host_speed) 10621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->get_host_speed(shost); 10631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN) 10651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, 20, "unknown\n"); 10661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return get_fc_port_speed_names(fc_host_speed(shost), buf); 10681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO, 10701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_host_speed, NULL); 10711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_attr(port_id, "0x%06x\n", 20); 10741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN); 10751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); 10761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long); 1077016131b8fffa1085b4ad165ab228116fdc278ebeJames Smartfc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1); 10781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1079b8d08210126a7b769b857720a59721a453a57a1eJames Smartfc_private_host_show_function(system_hostname, "%s\n", 1080b8d08210126a7b769b857720a59721a453a57a1eJames Smart FC_SYMBOLIC_NAME_SIZE + 1, ) 1081b8d08210126a7b769b857720a59721a453a57a1eJames Smartfc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE) 1082b8d08210126a7b769b857720a59721a453a57a1eJames Smartstatic FC_CLASS_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR, 1083b8d08210126a7b769b857720a59721a453a57a1eJames Smart show_fc_host_system_hostname, store_fc_host_system_hostname); 1084b8d08210126a7b769b857720a59721a453a57a1eJames Smart 10851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Private Host Attributes */ 10871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 10891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsshow_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf) 10901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 10911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 10921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *name; 10931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 10941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost)); 10951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!name) 10961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 10971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name); 10981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 10991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1100d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com#define get_list_head_entry(pos, head, member) \ 1101d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com pos = list_entry((head)->next, typeof(*pos), member) 1102d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com 11031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 11041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstore_fc_private_host_tgtid_bind_type(struct class_device *cdev, 11051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds const char *buf, size_t count) 11061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 11071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 1108d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com struct fc_rport *rport; 11091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds enum fc_tgtid_binding_type val; 11101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 11111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (get_fc_tgtid_bind_type_match(buf, &val)) 11131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EINVAL; 11141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* if changing bind type, purge all unused consistent bindings */ 11161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (val != fc_host_tgtid_bind_type(shost)) { 11171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 1118d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com while (!list_empty(&fc_host_rport_bindings(shost))) { 1119d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com get_list_head_entry(rport, 1120d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com &fc_host_rport_bindings(shost), peers); 1121aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 1122aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 1123aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 1124d16794f6ac8d9b50f62e02a6e6175ae1a30d0ccdJames.Smart@Emulex.Com } 11251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 11261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_host_tgtid_bind_type(shost) = val; 11291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; 11301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR, 11331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds show_fc_private_host_tgtid_bind_type, 11341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds store_fc_private_host_tgtid_bind_type); 11351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 113691ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquezstatic ssize_t 113791ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquezstore_fc_private_host_issue_lip(struct class_device *cdev, 113891ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez const char *buf, size_t count) 113991ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez{ 114091ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez struct Scsi_Host *shost = transport_class_to_shost(cdev); 114191ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez struct fc_internal *i = to_fc_internal(shost->transportt); 114291ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez int ret; 114391ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 114491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez /* ignore any data value written to the attribute */ 114591ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez if (i->f->issue_fc_host_lip) { 114691ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez ret = i->f->issue_fc_host_lip(shost); 114791ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez return ret ? ret: count; 114891ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez } 114991ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 115091ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez return -ENOENT; 115191ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez} 115291ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 115391ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquezstatic FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL, 115491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez store_fc_private_host_issue_lip); 115591ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez 11561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 11571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Host Statistics Management 11581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 11591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Show a given an attribute in the statistics group */ 11611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 11621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset) 11631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 11641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 11651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 11661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_host_statistics *stats; 11671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ssize_t ret = -ENOENT; 11681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (offset > sizeof(struct fc_host_statistics) || 11701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offset % sizeof(u64) != 0) 11711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds WARN_ON(1); 11721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->get_fc_host_stats) { 11741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds stats = (i->f->get_fc_host_stats)(shost); 11751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (stats) 11761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = snprintf(buf, 20, "0x%llx\n", 11771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (unsigned long long)*(u64 *)(((u8 *) stats) + offset)); 11781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return ret; 11801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 11811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* generate a read-only statistics attribute */ 11841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fc_host_statistic(name) \ 11851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \ 11861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ \ 11871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return fc_stat_show(cd, buf, \ 11881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds offsetof(struct fc_host_statistics, name)); \ 11891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} \ 11901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL) 11911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 11921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(seconds_since_last_reset); 11931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(tx_frames); 11941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(tx_words); 11951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(rx_frames); 11961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(rx_words); 11971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(lip_count); 11981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(nos_count); 11991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(error_frames); 12001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(dumped_frames); 12011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(link_failure_count); 12021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(loss_of_sync_count); 12031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(loss_of_signal_count); 12041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(prim_seq_protocol_err_count); 12051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(invalid_tx_word_count); 12061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(invalid_crc_count); 12071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_input_requests); 12081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_output_requests); 12091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_control_requests); 12101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_input_megabytes); 12111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_host_statistic(fcp_output_megabytes); 12121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic ssize_t 12141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_reset_statistics(struct class_device *cdev, const char *buf, 12151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t count) 12161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = transport_class_to_shost(cdev); 12181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(shost->transportt); 12191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* ignore any data value written to the attribute */ 12211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i->f->reset_fc_host_stats) { 12221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f->reset_fc_host_stats(shost); 12231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return count; 12241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 12251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENOENT; 12271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL, 12291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds fc_reset_statistics); 12301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct attribute *fc_statistics_attrs[] = { 12331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_seconds_since_last_reset.attr, 12341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_tx_frames.attr, 12351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_tx_words.attr, 12361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_rx_frames.attr, 12371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_rx_words.attr, 12381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_lip_count.attr, 12391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_nos_count.attr, 12401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_error_frames.attr, 12411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_dumped_frames.attr, 12421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_link_failure_count.attr, 12431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_loss_of_sync_count.attr, 12441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_loss_of_signal_count.attr, 12451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_prim_seq_protocol_err_count.attr, 12461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_invalid_tx_word_count.attr, 12471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_invalid_crc_count.attr, 12481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_fcp_input_requests.attr, 12491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_fcp_output_requests.attr, 12501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_fcp_control_requests.attr, 12511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_fcp_input_megabytes.attr, 12521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_fcp_output_megabytes.attr, 12531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds &class_device_attr_host_reset_statistics.attr, 12541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds NULL 12551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 12561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct attribute_group fc_statistics_group = { 12581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "statistics", 12591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .attrs = fc_statistics_attrs, 12601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 12611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_host_match(struct attribute_container *cont, 12631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 12641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 12661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 12671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_host_device(dev)) 12691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 12701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev); 12721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 12731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 12741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 12751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 12771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t.host_attrs.ac == cont; 12791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_target_match(struct attribute_container *cont, 12821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 12831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 12841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 12851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 12861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_target_device(dev)) 12881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 12891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev->parent); 12911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 12921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 12931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 12941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 12961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 12971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t.target_attrs.ac == cont; 12981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 12991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void fc_rport_dev_release(struct device *dev) 13011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 13021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = dev_to_rport(dev); 13031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds put_device(dev->parent); 13041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(rport); 13051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint scsi_is_fc_rport(const struct device *dev) 13081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 13091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return dev->release == fc_rport_dev_release; 13101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(scsi_is_fc_rport); 13121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int fc_rport_match(struct attribute_container *cont, 13141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev) 13151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 13161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost; 13171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i; 13181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!scsi_is_fc_rport(dev)) 13201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 13211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost = dev_to_shost(dev->parent); 13231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!shost->transportt || shost->transportt->host_attrs.ac.class 13241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds != &fc_host_class.class) 13251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 13261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i = to_fc_internal(shost->transportt); 13281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->rport_attr_cont.ac == cont; 13301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 13311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13325c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 1333c829c394165f981d49f05a9be228404d7a9398d4James Smart/** 1334c829c394165f981d49f05a9be228404d7a9398d4James Smart * fc_timed_out - FC Transport I/O timeout intercept handler 1335c829c394165f981d49f05a9be228404d7a9398d4James Smart * 1336c829c394165f981d49f05a9be228404d7a9398d4James Smart * @scmd: The SCSI command which timed out 1337c829c394165f981d49f05a9be228404d7a9398d4James Smart * 1338c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine protects against error handlers getting invoked while a 1339c829c394165f981d49f05a9be228404d7a9398d4James Smart * rport is in a blocked state, typically due to a temporarily loss of 1340c829c394165f981d49f05a9be228404d7a9398d4James Smart * connectivity. If the error handlers are allowed to proceed, requests 1341c829c394165f981d49f05a9be228404d7a9398d4James Smart * to abort i/o, reset the target, etc will likely fail as there is no way 1342c829c394165f981d49f05a9be228404d7a9398d4James Smart * to communicate with the device to perform the requested function. These 1343c829c394165f981d49f05a9be228404d7a9398d4James Smart * failures may result in the midlayer taking the device offline, requiring 1344c829c394165f981d49f05a9be228404d7a9398d4James Smart * manual intervention to restore operation. 1345c829c394165f981d49f05a9be228404d7a9398d4James Smart * 1346c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine, called whenever an i/o times out, validates the state of 1347c829c394165f981d49f05a9be228404d7a9398d4James Smart * the underlying rport. If the rport is blocked, it returns 1348c829c394165f981d49f05a9be228404d7a9398d4James Smart * EH_RESET_TIMER, which will continue to reschedule the timeout. 1349c829c394165f981d49f05a9be228404d7a9398d4James Smart * Eventually, either the device will return, or devloss_tmo will fire, 1350c829c394165f981d49f05a9be228404d7a9398d4James Smart * and when the timeout then fires, it will be handled normally. 1351c829c394165f981d49f05a9be228404d7a9398d4James Smart * If the rport is not blocked, normal error handling continues. 1352c829c394165f981d49f05a9be228404d7a9398d4James Smart * 1353c829c394165f981d49f05a9be228404d7a9398d4James Smart * Notes: 1354c829c394165f981d49f05a9be228404d7a9398d4James Smart * This routine assumes no locks are held on entry. 1355c829c394165f981d49f05a9be228404d7a9398d4James Smart **/ 1356c829c394165f981d49f05a9be228404d7a9398d4James Smartstatic enum scsi_eh_timer_return 1357c829c394165f981d49f05a9be228404d7a9398d4James Smartfc_timed_out(struct scsi_cmnd *scmd) 1358c829c394165f981d49f05a9be228404d7a9398d4James Smart{ 1359c829c394165f981d49f05a9be228404d7a9398d4James Smart struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device)); 1360c829c394165f981d49f05a9be228404d7a9398d4James Smart 1361c829c394165f981d49f05a9be228404d7a9398d4James Smart if (rport->port_state == FC_PORTSTATE_BLOCKED) 1362c829c394165f981d49f05a9be228404d7a9398d4James Smart return EH_RESET_TIMER; 1363c829c394165f981d49f05a9be228404d7a9398d4James Smart 1364c829c394165f981d49f05a9be228404d7a9398d4James Smart return EH_NOT_HANDLED; 1365c829c394165f981d49f05a9be228404d7a9398d4James Smart} 1366c829c394165f981d49f05a9be228404d7a9398d4James Smart 13675c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com/* 13685c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com * Must be called with shost->host_lock held 13695c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com */ 1370e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwigstatic int fc_user_scan(struct Scsi_Host *shost, uint channel, 1371e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig uint id, uint lun) 13725c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com{ 13735c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com struct fc_rport *rport; 13745c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 1375e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig list_for_each_entry(rport, &fc_host_rports(shost), peers) { 1376e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig if (rport->scsi_target_id == -1) 1377e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig continue; 13785c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 1379e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig if ((channel == SCAN_WILD_CARD || channel == rport->channel) && 1380e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) { 1381e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig scsi_scan_target(&rport->dev, rport->channel, 1382e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig rport->scsi_target_id, lun, 1); 1383e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig } 1384e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig } 1385e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig 1386e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig return 0; 13875c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com} 13885c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 13891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct scsi_transport_template * 13901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_attach_transport(struct fc_function_template *ft) 13911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 13921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int count; 139324669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen struct fc_internal *i = kzalloc(sizeof(struct fc_internal), 139424669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen GFP_KERNEL); 13951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(!i)) 13971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 13981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 13991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.attrs = &i->starget_attrs[0]; 14001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.class = &fc_transport_class.class; 14011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_attrs.ac.match = fc_target_match; 14021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.target_size = sizeof(struct fc_starget_attrs); 14031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->t.target_attrs); 14041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.attrs = &i->host_attrs[0]; 14061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.class = &fc_host_class.class; 14071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.ac.match = fc_host_match; 14081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_size = sizeof(struct fc_host_attrs); 14091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ft->get_fc_host_stats) 14101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.host_attrs.statistics = &fc_statistics_group; 14111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->t.host_attrs); 14121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.attrs = &i->rport_attrs[0]; 14141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.class = &fc_rport_class.class; 14151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attr_cont.ac.match = fc_rport_match; 14161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_register(&i->rport_attr_cont); 14171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->f = ft; 14191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Transport uses the shost workq for scsi scanning */ 14211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->t.create_work_queue = 1; 14225c44cd2afad3f7b015542187e147a820600172f1James.Smart@Emulex.Com 1423c829c394165f981d49f05a9be228404d7a9398d4James Smart i->t.eh_timed_out = fc_timed_out; 1424c829c394165f981d49f05a9be228404d7a9398d4James Smart 1425e02f3f59225d8c3b2a0ad0dc941a09865e27da61Christoph Hellwig i->t.user_scan = fc_user_scan; 14261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 14281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup SCSI Target Attributes. 14291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 14301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count = 0; 14311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(node_name); 14321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(port_name); 14331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_STARGET_ATTRIBUTE_RD(port_id); 14341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_STARGET_NUM_ATTRS); 14361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->starget_attrs[count] = NULL; 14381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 14411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup SCSI Host Attributes. 14421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 14431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count=0; 14441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(node_name); 14451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_name); 14466b7281d0a0f8f99d39808088a036459f6f7906a6Andreas Herrmann SETUP_HOST_ATTRIBUTE_RD(permanent_port_name); 14471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_classes); 14481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_fc4s); 14491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(supported_speeds); 14501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(maxframe_size); 14511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(serial_number); 14521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_id); 14541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_type); 14551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(port_state); 14561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(active_fc4s); 14571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(speed); 14581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_HOST_ATTRIBUTE_RD(fabric_name); 1459016131b8fffa1085b4ad165ab228116fdc278ebeJames Smart SETUP_HOST_ATTRIBUTE_RD(symbolic_name); 1460b8d08210126a7b769b857720a59721a453a57a1eJames Smart SETUP_HOST_ATTRIBUTE_RW(system_hostname); 14611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Transport-managed attributes */ 14631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type); 146491ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez if (ft->issue_fc_host_lip) 146591ca7b01ecc916632202180569a7ddbfccfc3f05Andrew Vasquez SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip); 14661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_HOST_NUM_ATTRS); 14681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->host_attrs[count] = NULL; 14701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 14721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Setup Remote Port Attributes. 14731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 14741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds count=0; 14751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RD(maxframe_size); 14761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RD(supported_classes); 14771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo); 14781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name); 14791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name); 14801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id); 14811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles); 14821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state); 14831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id); 14841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds BUG_ON(count > FC_RPORT_NUM_ATTRS); 14861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds i->rport_attrs[count] = NULL; 14881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return &i->t; 14901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 14911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_attach_transport); 14921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid fc_release_transport(struct scsi_transport_template *t) 14941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 14951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *i = to_fc_internal(t); 14961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 14971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->t.target_attrs); 14981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->t.host_attrs); 14991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_container_unregister(&i->rport_attr_cont); 15001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(i); 15021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 15031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_release_transport); 15041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1505aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1506aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_queue_work - Queue work to the fc_host workqueue. 1507aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 1508aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @work: Work to queue for execution. 1509aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 1510aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * Return value: 1511a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * 1 - work queued for execution 1512a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * 0 - work is already queued 1513a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart * -EINVAL - work queue doesn't exist 1514aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 1515aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int 1516aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_queue_work(struct Scsi_Host *shost, struct work_struct *work) 1517aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 1518aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (unlikely(!fc_host_work_q(shost))) { 1519aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 1520aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to queue work, " 1521aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 1522aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 1523aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1524aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -EINVAL; 1525aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1526aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1527aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return queue_work(fc_host_work_q(shost), work); 1528aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 1529aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1530aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1531aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_flush_work - Flush a fc_host's workqueue. 1532aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 1533aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 1534aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 1535aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_flush_work(struct Scsi_Host *shost) 1536aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 1537aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host_work_q(shost)) { 1538aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 1539aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to flush work, " 1540aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 1541aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 1542aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return; 1543aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1544aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1545aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart flush_workqueue(fc_host_work_q(shost)); 1546aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 1547aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1548aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1549aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue. 1550aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 1551aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @work: Work to queue for execution. 1552aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @delay: jiffies to delay the work queuing 1553aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 1554aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * Return value: 1555aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 0 on success / != 0 for error 1556aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 1557aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic int 1558aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_queue_devloss_work(struct Scsi_Host *shost, struct work_struct *work, 1559aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart unsigned long delay) 1560aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 1561aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (unlikely(!fc_host_devloss_work_q(shost))) { 1562aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 1563aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to queue work, " 1564aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 1565aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 1566aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1567aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return -EINVAL; 1568aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1569aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1570aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay); 1571aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 1572aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1573aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1574aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_flush_devloss - Flush a fc_host's devloss workqueue. 1575aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @shost: Pointer to Scsi_Host bound to fc_host. 1576aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 1577aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 1578aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_flush_devloss(struct Scsi_Host *shost) 1579aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 1580aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!fc_host_devloss_work_q(shost)) { 1581aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart printk(KERN_ERR 1582aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "ERROR: FC host '%s' attempted to flush work, " 1583aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "when no workqueue created.\n", shost->hostt->name); 1584aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart dump_stack(); 1585aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart return; 1586aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1587aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1588aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart flush_workqueue(fc_host_devloss_work_q(shost)); 1589aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 1590aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 15911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 15931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_remove_host - called to terminate any fc_transport-related elements 15941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * for a scsi host. 15951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @rport: remote port to be unblocked. 15961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 15971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine is expected to be called immediately preceeding the 15981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a driver's call to scsi_remove_host(). 15991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 16001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * WARNING: A driver utilizing the fc_transport, which fails to call 16011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * this routine prior to scsi_remote_host(), will leave dangling 16021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * objects in /sys/class/fc_remote_ports. Access to any of these 16031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * objects can result in a system crash !!! 16041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 16051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 16061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 16071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 16081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 16091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remove_host(struct Scsi_Host *shost) 16101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 16111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport, *next_rport; 1612aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct workqueue_struct *work_q; 1613aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 16141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 16151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Remove any remote ports */ 16161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_for_each_entry_safe(rport, next_rport, 1617aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart &fc_host->rports, peers) { 1618aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 1619aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 1620aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 1621aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1622aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 16231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_for_each_entry_safe(rport, next_rport, 1624aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart &fc_host->rport_bindings, peers) { 1625aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 1626aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 1627aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 1628aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1629aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1630aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all scan work items */ 1631aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_flush_work(shost); 1632aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1633aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all stgt delete, and rport delete work items, then kill it */ 1634aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->work_q) { 1635aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart work_q = fc_host->work_q; 1636aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->work_q = NULL; 1637aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(work_q); 1638aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1639aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1640aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* flush all devloss work items, then kill it */ 1641aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->devloss_work_q) { 1642aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart work_q = fc_host->devloss_work_q; 1643aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_host->devloss_work_q = NULL; 1644aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart destroy_workqueue(work_q); 1645aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 16461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 16471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remove_host); 16481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1649aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1650aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1651aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_starget_delete - called to delete the scsi decendents of an rport 1652aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * (target and all sdevs) 1653aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 1654aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @data: remote port to be operated on. 1655aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 165619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comstatic void 1657aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_starget_delete(void *data) 165819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com{ 1659aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_rport *rport = (struct fc_rport *)data; 166019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct Scsi_Host *shost = rport_to_shost(rport); 1661aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart unsigned long flags; 166219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1663aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 1664aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->flags & FC_RPORT_DEVLOSS_PENDING) { 1665aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 1666aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (!cancel_delayed_work(&rport->dev_loss_work)) 1667aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_devloss(shost); 1668aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 1669aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 1670aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 1671aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 167219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 167319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com scsi_remove_target(&rport->dev); 167419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com} 167519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1676aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1677aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart/** 1678aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * fc_rport_final_delete - finish rport termination and delete it. 1679aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 1680aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * @data: remote port to be deleted. 1681aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart **/ 1682aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartstatic void 1683aedf349773e5877d716a89368d512b9baa3e8c7bJames Smartfc_rport_final_delete(void *data) 1684aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart{ 1685aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_rport *rport = (struct fc_rport *)data; 1686aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct device *dev = &rport->dev; 1687aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 1688aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1689aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* Delete SCSI target and sdevs */ 1690aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->scsi_target_id != -1) 1691aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_starget_delete(data); 1692aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1693aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* 1694aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * if a scan is pending, flush the SCSI Host work_q so that 1695aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * that we can reclaim the rport scan work element. 1696aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart */ 1697aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->flags & FC_RPORT_SCAN_PENDING) 1698aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_flush_work(shost); 1699aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1700aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart transport_remove_device(dev); 1701aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart device_del(dev); 1702aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart transport_destroy_device(dev); 17033bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(&shost->shost_gendev); /* for fc_host->rport list */ 17043bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(dev); /* for self-reference */ 1705aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart} 1706aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1707aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 17081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 17091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_rport_create - allocates and creates a remote FC port. 17101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @shost: scsi host the remote port is connected to. 17111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @channel: Channel on shost port connected to. 17121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @ids: The world wide names, fc address, and FC4 port 17131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * roles for the remote port. 17141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 17151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Allocates and creates the remoter port structure, including the 17161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * class and sysfs creation. 17171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 17181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 17191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 17201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 17211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct fc_rport * 17221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_rport_create(struct Scsi_Host *shost, int channel, 17231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport_identifiers *ids) 17241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1725aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 17261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_internal *fci = to_fc_internal(shost->transportt); 17271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport; 17281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct device *dev; 17291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 17301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int error; 17311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size_t size; 17321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size); 173424669f75a3231fa37444977c92d1f4838bec1233Jes Sorensen rport = kzalloc(size, GFP_KERNEL); 17351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (unlikely(!rport)) { 17361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__); 17371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 17381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->maxframe_size = -1; 17411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->supported_classes = FC_COS_UNSPECIFIED; 17421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->dev_loss_tmo = fc_dev_loss_tmo; 17431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name)); 17441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name)); 17451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_id = ids->port_id; 17461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->roles = ids->roles; 17471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_state = FC_PORTSTATE_ONLINE; 17481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (fci->f->dd_fcrport_size) 17491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->dd_data = &rport[1]; 17501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->channel = channel; 17511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 175219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport); 17531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport); 1754aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_WORK(&rport->stgt_delete_work, fc_starget_delete, rport); 1755aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete, rport); 17561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 17581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->number = fc_host->next_rport_number++; 17601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) 17611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->scsi_target_id = fc_host->next_target_id++; 17621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 17631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->scsi_target_id = -1; 1764aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_add_tail(&rport->peers, &fc_host->rports); 17653bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart get_device(&shost->shost_gendev); /* for fc_host->rport list */ 17661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 17681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev = &rport->dev; 17703bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart device_initialize(dev); /* takes self reference */ 17713bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart dev->parent = get_device(&shost->shost_gendev); /* parent reference */ 17721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds dev->release = fc_rport_dev_release; 17731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sprintf(dev->bus_id, "rport-%d:%d-%d", 17741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds shost->host_no, channel, rport->number); 17751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_setup_device(dev); 17761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds error = device_add(dev); 17781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (error) { 17791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk(KERN_ERR "FC Remote Port device_add failed\n"); 17801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto delete_rport; 17811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 17821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_add_device(dev); 17831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_configure_device(dev); 17841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1785aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) { 17861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 1787aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 17881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 1789aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart } 17901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 17921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 17931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdelete_rport: 17941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds transport_destroy_device(dev); 17951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 17961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_del(&rport->peers); 17973bdad7bd253f17ead00b4af2e82f84e9522c95acJames Smart put_device(&shost->shost_gendev); /* for fc_host->rport list */ 17981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_unlock_irqrestore(shost->host_lock, flags); 17991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds put_device(dev->parent); 18001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds kfree(rport); 18011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return NULL; 18021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 18031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 18041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 18051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_remote_port_add - notifies the fc transport of the existence 18061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of a remote FC port. 18071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @shost: scsi host the remote port is connected to. 18081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @channel: Channel on shost port connected to. 18091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @ids: The world wide names, fc address, and FC4 port 18101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * roles for the remote port. 18111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The LLDD calls this routine to notify the transport of the existence 18131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn) 18141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of the port, it's FC address (port_id), and the FC4 roles that are 18151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * active for the port. 18161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For ports that are FCP targets (aka scsi targets), the FC transport 18181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * maintains consistent target id bindings on behalf of the LLDD. 18191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A consistent target id binding is an assignment of a target id to 18201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a remote port identifier, which persists while the scsi host is 18211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * attached. The remote port can disappear, then later reappear, and 18221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it's target id assignment remains the same. This allows for shifts 18231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * in FC addressing (if binding by wwpn or wwnn) with no apparent 18241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * changes to the scsi subsystem which is based on scsi host number and 18251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * target id values. Bindings are only valid during the attachment of 18261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the scsi host. If the host detaches, then later re-attaches, target 18271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * id bindings may change. 18281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine is responsible for returning a remote port structure. 18301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The routine will search the list of remote ports it maintains 18311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * internally on behalf of consistent target id mappings. If found, the 18321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * remote port structure will be reused. Otherwise, a new remote port 18331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * structure will be allocated. 18341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Whenever a remote port is allocated, a new fc_remote_port class 18361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * device is created. 18371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Should not be called from interrupt context. 18391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 18401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 18411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 18421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 18431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct fc_rport * 18441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_add(struct Scsi_Host *shost, int channel, 18451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport_identifiers *ids) 18461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 184719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct fc_internal *fci = to_fc_internal(shost->transportt); 1848aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 18491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport; 18501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 18511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int match = 0; 18521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1853aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* ensure any stgt delete functions are done */ 1854aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_work(shost); 1855aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 185619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 185719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Search the list of "active" rports, for an rport that has been 185819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * deleted, but we've held off the real delete while the target 185919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * is in a "blocked" state. 186019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 186119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_lock_irqsave(shost->host_lock, flags); 186219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1863aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_for_each_entry(rport, &fc_host->rports, peers) { 186419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 186519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if ((rport->port_state == FC_PORTSTATE_BLOCKED) && 186619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com (rport->channel == channel)) { 186719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1868aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart switch (fc_host->tgtid_bind_type) { 186919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWPN: 187019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_NONE: 187119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_name == ids->port_name) 187219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 187319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 187419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWNN: 187519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->node_name == ids->node_name) 187619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 187719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 187819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_ID: 187919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_id == ids->port_id) 188019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com match = 1; 188119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 188219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 188319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 188419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (match) { 188519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct work_struct *work = 188619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com &rport->dev_loss_work; 188719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 188819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memcpy(&rport->node_name, &ids->node_name, 188919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com sizeof(rport->node_name)); 189019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memcpy(&rport->port_name, &ids->port_name, 189119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com sizeof(rport->port_name)); 189219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_id = ids->port_id; 189319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 189419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_state = FC_PORTSTATE_ONLINE; 189519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->roles = ids->roles; 189619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 189719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 189819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 189919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (fci->f->dd_fcrport_size) 190019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memset(rport->dd_data, 0, 190119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com fci->f->dd_fcrport_size); 190219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 190319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 190419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If we were blocked, we were a target. 190519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If no longer a target, we leave the timer 190619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * running in case the port changes roles 190719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * prior to the timer expiring. If the timer 190819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * fires, the target will be torn down. 190919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 191019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET)) 191119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return rport; 191219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 191319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* restart the target */ 191419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 191519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 191619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Stop the target timer first. Take no action 191719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * on the del_timer failure as the state 191819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * machine state change will validate the 191919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * transaction. 192019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 192119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (!cancel_delayed_work(work)) 1922aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_devloss(shost); 1923aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1924aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 1925aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1926aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 192719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 192819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* initiate a scan of the target */ 1929aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 193019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com scsi_queue_work(shost, &rport->scan_work); 193119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1932aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 1933aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 1934a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart scsi_target_unblock(&rport->dev); 1935a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart 193619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return rport; 193719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 193819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 193919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 194019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 194119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* Search the bindings array */ 1942aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { 19431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* search for a matching consistent binding */ 19451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1946aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_for_each_entry(rport, &fc_host->rport_bindings, 19471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds peers) { 19481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->channel != channel) 19491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 19501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1951aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart switch (fc_host->tgtid_bind_type) { 19521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_WWPN: 19531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->port_name == ids->port_name) 19541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 19551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_WWNN: 19571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->node_name == ids->node_name) 19581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 19591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_BY_ID: 19611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (rport->port_id == ids->port_id) 19621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds match = 1; 19631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds case FC_TGTID_BIND_NONE: /* to keep compiler happy */ 19651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (match) { 1969aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_move_tail(&rport->peers, &fc_host->rports); 19701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; 19711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (match) { 19751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->node_name, &ids->node_name, 19761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sizeof(rport->node_name)); 19771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(&rport->port_name, &ids->port_name, 19781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sizeof(rport->port_name)); 19791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_id = ids->port_id; 19801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->roles = ids->roles; 19811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport->port_state = FC_PORTSTATE_ONLINE; 19821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 198319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (fci->f->dd_fcrport_size) 198419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com memset(rport->dd_data, 0, 198519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com fci->f->dd_fcrport_size); 198619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 1987aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) { 19881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 1989aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 19901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 1991a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 1992a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart scsi_target_unblock(&rport->dev); 1993a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart } else 1994a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 19951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 19961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 19971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 19991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 200019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 200119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 20021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* No consistent binding found - create new remote port entry */ 20031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds rport = fc_rport_create(shost, channel, ids); 20041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return rport; 20061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 20071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_add); 20081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 20111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_remote_port_delete - notifies the fc transport that a remote 20121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * port is no longer in existence. 20131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @rport: The remote port that no longer exists 20141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 20151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The LLDD calls this routine to notify the transport that a remote 20161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * port is no longer part of the topology. Note: Although a port 20171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * may no longer be part of the topology, it may persist in the remote 201819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * ports displayed by the fc_host. We do this under 2 conditions: 201919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * - If the port was a scsi target, we delay its deletion by "blocking" it. 202019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * This allows the port to temporarily disappear, then reappear without 202119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * disrupting the SCSI device tree attached to it. During the "blocked" 202219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * period the port will still exist. 202319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * - If the port was a scsi target and disappears for longer than we 202419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * expect, we'll delete the port and the tear down the SCSI device tree 202519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * attached to it. However, we want to semi-persist the target id assigned 202619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * to that port if it eventually does exist. The port structure will 202719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * remain (although with minimal information) so that the target id 202819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * bindings remails. 20291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 20301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * If the remote port is not an FCP Target, it will be fully torn down 20311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and deallocated, including the fc_remote_port class device. 20321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 203319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port is an FCP Target, the port will be placed in a 203419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * temporary blocked state. From the LLDD's perspective, the rport no 203519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * longer exists. From the SCSI midlayer's perspective, the SCSI target 203619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * exists, but all sdevs on it are blocked from further I/O. The following 203719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * is then expected: 203819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port does not return (signaled by a LLDD call to 203919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * fc_remote_port_add()) within the dev_loss_tmo timeout, then the 204019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi target is removed - killing all outstanding i/o and removing the 204119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi devices attached ot it. The port structure will be marked Not 204219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Present and be partially cleared, leaving only enough information to 204319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * recognize the remote port relative to the scsi target id binding if 204419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * it later appears. The port will remain as long as there is a valid 204519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * binding (e.g. until the user changes the binding type or unloads the 204619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi host with the binding). 20471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 204819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * If the remote port returns within the dev_loss_tmo value (and matches 204919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * according to the target id binding type), the port structure will be 205019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * reused. If it is no longer a SCSI target, the target will be torn 205119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * down. If it continues to be a SCSI target, then the target will be 205219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * unblocked (allowing i/o to be resumed), and a scan will be activated 205319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * to ensure that all luns are detected. 205419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 205519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Called from normal process context only - cannot be called from interrupt. 20561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 20571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 20581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 20591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 20601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 20611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_delete(struct fc_rport *rport) 20621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2063aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 206419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com int timeout = rport->dev_loss_tmo; 2065aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart unsigned long flags; 2066aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2067aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* 2068aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * No need to flush the fc_host work_q's, as all adds are synchronous. 2069aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * 2070aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * We do need to reclaim the rport scan work element, so eventually 2071aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * (in fc_rport_final_delete()) we'll flush the scsi host work_q if 2072aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * there's still a scan pending. 2073aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart */ 2074aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2075aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 20761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 207719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* If no scsi target id mapping, delete it */ 207819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->scsi_target_id == -1) { 2079aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 2080aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 2081aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 2082aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 20831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 20841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 20851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2086aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_BLOCKED; 2087aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2088aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_DEVLOSS_PENDING; 2089aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2090aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 2091aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 209219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com scsi_target_block(&rport->dev); 20931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 209419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* cap the length the devices can be blocked until they are deleted */ 2095aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ); 20961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 20971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_delete); 20981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 20991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 21001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_remote_port_rolechg - notifies the fc transport that the roles 21011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * on a remote may have changed. 21021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @rport: The remote port that changed. 21031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 21041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The LLDD calls this routine to notify the transport that the roles 21051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * on a remote port may have changed. The largest effect of this is 21061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * if a port now becomes a FCP Target, it must be allocated a 21071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * scsi target id. If the port is no longer a FCP target, any 21081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * scsi target id value assigned to it will persist in case the 21091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * role changes back to include FCP Target. No changes in the scsi 21101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * midlayer will be invoked if the role changes (in the expectation 21111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * that the role will be resumed. If it doesn't normal error processing 21121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * will take place). 21131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 21141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Should not be called from interrupt context. 21151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 21161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Notes: 21171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This routine assumes no locks are held on entry. 21181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 21191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsvoid 21201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_remote_port_rolechg(struct fc_rport *rport, u32 roles) 21211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 21221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct Scsi_Host *shost = rport_to_shost(rport); 2123aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 21241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned long flags; 21251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int create = 0; 21261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spin_lock_irqsave(shost->host_lock, flags); 212819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (roles & FC_RPORT_ROLE_FCP_TARGET) { 212919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->scsi_target_id == -1) { 213019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->scsi_target_id = fc_host->next_target_id++; 213119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com create = 1; 213219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) 213319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com create = 1; 21341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 21351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 213619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->roles = roles; 213719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2138aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 2139aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 214019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (create) { 214119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 214219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * There may have been a delete timer running on the 214319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * port. Ensure that it is cancelled as we now know 214419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * the port is an FCP Target. 214519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Note: we know the rport is exists and in an online 214619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * state as the LLDD would not have had an rport 214719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * reference to pass us. 214819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 214919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Take no action on the del_timer failure as the state 215019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * machine state change will validate the 215119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * transaction. 215219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 215319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (!cancel_delayed_work(&rport->dev_loss_work)) 2154aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_devloss(shost); 2155aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2156aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 2157aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 2158aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 2159aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2160aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart /* ensure any stgt delete functions are done */ 2161aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_flush_work(shost); 216219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 21631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* initiate a scan of the target */ 2164aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 2165aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags |= FC_RPORT_SCAN_PENDING; 21661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds scsi_queue_work(shost, &rport->scan_work); 2167aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 2168a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart scsi_target_unblock(&rport->dev); 216919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 21701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 21711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsEXPORT_SYMBOL(fc_remote_port_rolechg); 21721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 21731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 217419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * fc_timeout_deleted_rport - Timeout handler for a deleted remote port that 217519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * was a SCSI target (thus was blocked), and failed 217619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * to return in the alloted time. 217719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 217819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * @data: rport target that failed to reappear in the alloted time. 21791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 21801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 218119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Comfc_timeout_deleted_rport(void *data) 21821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 21831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = (struct fc_rport *)data; 218419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com struct Scsi_Host *shost = rport_to_shost(rport); 2185aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct fc_host_attrs *fc_host = shost_to_fc_host(shost); 218619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com unsigned long flags; 21871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 218819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_lock_irqsave(shost->host_lock, flags); 21891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2190aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 2191aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 21921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 2193aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * If the port is ONLINE, then it came back. Validate it's still an 2194aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart * FCP target. If not, tear down the scsi_target on it. 21951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2196aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if ((rport->port_state == FC_PORTSTATE_ONLINE) && 2197aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { 219819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 2199aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart "blocked FC remote port time out: no longer" 2200aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart " a FCP target, removing starget\n"); 2201aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 2202a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart scsi_target_unblock(&rport->dev); 2203a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart fc_queue_work(shost, &rport->stgt_delete_work); 220419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 220519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 22061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 220719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com if (rport->port_state != FC_PORTSTATE_BLOCKED) { 220819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 220919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 221019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "blocked FC remote port time out: leaving target alone\n"); 221119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 221219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 22131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2214aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) { 2215aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_del(&rport->peers); 2216aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_DELETED; 221719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 221819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "blocked FC remote port time out: removing target\n"); 2219aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart fc_queue_work(shost, &rport->rport_delete_work); 2220aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_unlock_irqrestore(shost->host_lock, flags); 222119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com return; 222219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 22231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 222419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com dev_printk(KERN_ERR, &rport->dev, 222519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "blocked FC remote port time out: removing target and " 222619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com "saving binding\n"); 222719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 2228aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart list_move_tail(&rport->peers, &fc_host->rport_bindings); 22291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 223119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Note: We do not remove or clear the hostdata area. This allows 223219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * host-specific target data to persist along with the 223319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * scsi_target_id. It's up to the host to manage it's hostdata area. 22341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 22351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 223619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 223719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * Reinitialize port attributes that may change if the port comes back. 223819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 223919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->maxframe_size = -1; 224019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->supported_classes = FC_COS_UNSPECIFIED; 224119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->roles = FC_RPORT_ROLE_UNKNOWN; 2242aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->port_state = FC_PORTSTATE_NOTPRESENT; 22431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 224419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* remove the identifiers that aren't used in the consisting binding */ 2245aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart switch (fc_host->tgtid_bind_type) { 224619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWPN: 224719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->node_name = -1; 224819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_id = -1; 224919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 225019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_WWNN: 225119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_name = -1; 225219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_id = -1; 225319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 225419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_BY_ID: 225519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->node_name = -1; 225619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com rport->port_name = -1; 225719a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 225819a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com case FC_TGTID_BIND_NONE: /* to keep compiler happy */ 225919a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com break; 226019a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com } 226119a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com 226219a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com /* 226319a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * As this only occurs if the remote port (scsi target) 226419a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * went away and didn't come back - we'll remove 226519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * all attached scsi devices. 226619a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com */ 226742e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 2268a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart 2269a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart scsi_target_unblock(&rport->dev); 2270a0785edff7b316cad566bdc369d3d034c4c1a39cJames Smart fc_queue_work(shost, &rport->stgt_delete_work); 22711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 22721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 22731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 22741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * fc_scsi_scan_rport - called to perform a scsi scan on a remote port. 227519a7b4aebf9ad435c69a7e39930338499af4d152James.Smart@Emulex.Com * 22761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @data: remote port to be scanned. 22771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds **/ 22781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 22791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfc_scsi_scan_rport(void *data) 22801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 22811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct fc_rport *rport = (struct fc_rport *)data; 2282aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart struct Scsi_Host *shost = rport_to_shost(rport); 228342e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com unsigned long flags; 228442e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 2285aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart if ((rport->port_state == FC_PORTSTATE_ONLINE) && 2286aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { 2287aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart scsi_scan_target(&rport->dev, rport->channel, 2288aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->scsi_target_id, SCAN_WILD_CARD, 1); 228942e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com } 2290aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart 2291aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart spin_lock_irqsave(shost->host_lock, flags); 2292aedf349773e5877d716a89368d512b9baa3e8c7bJames Smart rport->flags &= ~FC_RPORT_SCAN_PENDING; 229342e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com spin_unlock_irqrestore(shost->host_lock, flags); 229442e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com} 229542e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 229642e33148df38c60b99d984b76b302c64397ebe4cJames.Smart@Emulex.Com 22971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_AUTHOR("Martin Hicks"); 22981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("FC Transport Attributes"); 22991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 23001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 23011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(fc_transport_init); 23021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(fc_transport_exit); 2303