scsi_transport_fc.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  1. /*
  2. * FiberChannel transport specific attributes exported to sysfs.
  3. *
  4. * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * ========
  21. *
  22. * Copyright (C) 2004-2005 James Smart, Emulex Corporation
  23. * Rewrite for host, target, device, and remote port attributes,
  24. * statistics, and service functions...
  25. *
  26. */
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/sched.h> /* workqueue stuff, HZ */
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/scsi_cmnd.h>
  35. #include <linux/netlink.h>
  36. #include <net/netlink.h>
  37. #include <scsi/scsi_netlink_fc.h>
  38. #include "scsi_priv.h"
  39. static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
  40. /*
  41. * Redefine so that we can have same named attributes in the
  42. * sdev/starget/host objects.
  43. */
  44. #define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
  45. struct class_device_attribute class_device_attr_##_prefix##_##_name = \
  46. __ATTR(_name,_mode,_show,_store)
  47. #define fc_enum_name_search(title, table_type, table) \
  48. static const char *get_fc_##title##_name(enum table_type table_key) \
  49. { \
  50. int i; \
  51. char *name = NULL; \
  52. \
  53. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  54. if (table[i].value == table_key) { \
  55. name = table[i].name; \
  56. break; \
  57. } \
  58. } \
  59. return name; \
  60. }
  61. #define fc_enum_name_match(title, table_type, table) \
  62. static int get_fc_##title##_match(const char *table_key, \
  63. enum table_type *value) \
  64. { \
  65. int i; \
  66. \
  67. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  68. if (strncmp(table_key, table[i].name, \
  69. table[i].matchlen) == 0) { \
  70. *value = table[i].value; \
  71. return 0; /* success */ \
  72. } \
  73. } \
  74. return 1; /* failure */ \
  75. }
  76. /* Convert fc_port_type values to ascii string name */
  77. static struct {
  78. enum fc_port_type value;
  79. char *name;
  80. } fc_port_type_names[] = {
  81. { FC_PORTTYPE_UNKNOWN, "Unknown" },
  82. { FC_PORTTYPE_OTHER, "Other" },
  83. { FC_PORTTYPE_NOTPRESENT, "Not Present" },
  84. { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
  85. { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
  86. { FC_PORTTYPE_LPORT, "LPort (private loop)" },
  87. { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
  88. };
  89. fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
  90. #define FC_PORTTYPE_MAX_NAMELEN 50
  91. /* Convert fc_host_event_code values to ascii string name */
  92. static const struct {
  93. enum fc_host_event_code value;
  94. char *name;
  95. } fc_host_event_code_names[] = {
  96. { FCH_EVT_LIP, "lip" },
  97. { FCH_EVT_LINKUP, "link_up" },
  98. { FCH_EVT_LINKDOWN, "link_down" },
  99. { FCH_EVT_LIPRESET, "lip_reset" },
  100. { FCH_EVT_RSCN, "rscn" },
  101. { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" },
  102. { FCH_EVT_PORT_UNKNOWN, "port_unknown" },
  103. { FCH_EVT_PORT_ONLINE, "port_online" },
  104. { FCH_EVT_PORT_OFFLINE, "port_offline" },
  105. { FCH_EVT_PORT_FABRIC, "port_fabric" },
  106. { FCH_EVT_LINK_UNKNOWN, "link_unknown" },
  107. { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" },
  108. };
  109. fc_enum_name_search(host_event_code, fc_host_event_code,
  110. fc_host_event_code_names)
  111. #define FC_HOST_EVENT_CODE_MAX_NAMELEN 30
  112. /* Convert fc_port_state values to ascii string name */
  113. static struct {
  114. enum fc_port_state value;
  115. char *name;
  116. } fc_port_state_names[] = {
  117. { FC_PORTSTATE_UNKNOWN, "Unknown" },
  118. { FC_PORTSTATE_NOTPRESENT, "Not Present" },
  119. { FC_PORTSTATE_ONLINE, "Online" },
  120. { FC_PORTSTATE_OFFLINE, "Offline" },
  121. { FC_PORTSTATE_BLOCKED, "Blocked" },
  122. { FC_PORTSTATE_BYPASSED, "Bypassed" },
  123. { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
  124. { FC_PORTSTATE_LINKDOWN, "Linkdown" },
  125. { FC_PORTSTATE_ERROR, "Error" },
  126. { FC_PORTSTATE_LOOPBACK, "Loopback" },
  127. { FC_PORTSTATE_DELETED, "Deleted" },
  128. };
  129. fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
  130. #define FC_PORTSTATE_MAX_NAMELEN 20
  131. /* Convert fc_tgtid_binding_type values to ascii string name */
  132. static const struct {
  133. enum fc_tgtid_binding_type value;
  134. char *name;
  135. int matchlen;
  136. } fc_tgtid_binding_type_names[] = {
  137. { FC_TGTID_BIND_NONE, "none", 4 },
  138. { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
  139. { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
  140. { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
  141. };
  142. fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
  143. fc_tgtid_binding_type_names)
  144. fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
  145. fc_tgtid_binding_type_names)
  146. #define FC_BINDTYPE_MAX_NAMELEN 30
  147. #define fc_bitfield_name_search(title, table) \
  148. static ssize_t \
  149. get_fc_##title##_names(u32 table_key, char *buf) \
  150. { \
  151. char *prefix = ""; \
  152. ssize_t len = 0; \
  153. int i; \
  154. \
  155. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  156. if (table[i].value & table_key) { \
  157. len += sprintf(buf + len, "%s%s", \
  158. prefix, table[i].name); \
  159. prefix = ", "; \
  160. } \
  161. } \
  162. len += sprintf(buf + len, "\n"); \
  163. return len; \
  164. }
  165. /* Convert FC_COS bit values to ascii string name */
  166. static const struct {
  167. u32 value;
  168. char *name;
  169. } fc_cos_names[] = {
  170. { FC_COS_CLASS1, "Class 1" },
  171. { FC_COS_CLASS2, "Class 2" },
  172. { FC_COS_CLASS3, "Class 3" },
  173. { FC_COS_CLASS4, "Class 4" },
  174. { FC_COS_CLASS6, "Class 6" },
  175. };
  176. fc_bitfield_name_search(cos, fc_cos_names)
  177. /* Convert FC_PORTSPEED bit values to ascii string name */
  178. static const struct {
  179. u32 value;
  180. char *name;
  181. } fc_port_speed_names[] = {
  182. { FC_PORTSPEED_1GBIT, "1 Gbit" },
  183. { FC_PORTSPEED_2GBIT, "2 Gbit" },
  184. { FC_PORTSPEED_4GBIT, "4 Gbit" },
  185. { FC_PORTSPEED_10GBIT, "10 Gbit" },
  186. { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
  187. };
  188. fc_bitfield_name_search(port_speed, fc_port_speed_names)
  189. static int
  190. show_fc_fc4s (char *buf, u8 *fc4_list)
  191. {
  192. int i, len=0;
  193. for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
  194. len += sprintf(buf + len , "0x%02x ", *fc4_list);
  195. len += sprintf(buf + len, "\n");
  196. return len;
  197. }
  198. /* Convert FC_RPORT_ROLE bit values to ascii string name */
  199. static const struct {
  200. u32 value;
  201. char *name;
  202. } fc_remote_port_role_names[] = {
  203. { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" },
  204. { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
  205. { FC_RPORT_ROLE_IP_PORT, "IP Port" },
  206. };
  207. fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
  208. /*
  209. * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
  210. */
  211. #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
  212. #define FC_WELLKNOWN_ROLE_MASK 0x00000f
  213. #define FC_FPORT_PORTID 0x00000e
  214. #define FC_FABCTLR_PORTID 0x00000d
  215. #define FC_DIRSRVR_PORTID 0x00000c
  216. #define FC_TIMESRVR_PORTID 0x00000b
  217. #define FC_MGMTSRVR_PORTID 0x00000a
  218. static void fc_timeout_deleted_rport(void *data);
  219. static void fc_scsi_scan_rport(void *data);
  220. /*
  221. * Attribute counts pre object type...
  222. * Increase these values if you add attributes
  223. */
  224. #define FC_STARGET_NUM_ATTRS 3
  225. #define FC_RPORT_NUM_ATTRS 9
  226. #define FC_HOST_NUM_ATTRS 17
  227. struct fc_internal {
  228. struct scsi_transport_template t;
  229. struct fc_function_template *f;
  230. /*
  231. * For attributes : each object has :
  232. * An array of the actual attributes structures
  233. * An array of null-terminated pointers to the attribute
  234. * structures - used for mid-layer interaction.
  235. *
  236. * The attribute containers for the starget and host are are
  237. * part of the midlayer. As the remote port is specific to the
  238. * fc transport, we must provide the attribute container.
  239. */
  240. struct class_device_attribute private_starget_attrs[
  241. FC_STARGET_NUM_ATTRS];
  242. struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
  243. struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
  244. struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
  245. struct transport_container rport_attr_cont;
  246. struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
  247. struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
  248. };
  249. #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
  250. static int fc_target_setup(struct transport_container *tc, struct device *dev,
  251. struct class_device *cdev)
  252. {
  253. struct scsi_target *starget = to_scsi_target(dev);
  254. struct fc_rport *rport = starget_to_rport(starget);
  255. /*
  256. * if parent is remote port, use values from remote port.
  257. * Otherwise, this host uses the fc_transport, but not the
  258. * remote port interface. As such, initialize to known non-values.
  259. */
  260. if (rport) {
  261. fc_starget_node_name(starget) = rport->node_name;
  262. fc_starget_port_name(starget) = rport->port_name;
  263. fc_starget_port_id(starget) = rport->port_id;
  264. } else {
  265. fc_starget_node_name(starget) = -1;
  266. fc_starget_port_name(starget) = -1;
  267. fc_starget_port_id(starget) = -1;
  268. }
  269. return 0;
  270. }
  271. static DECLARE_TRANSPORT_CLASS(fc_transport_class,
  272. "fc_transport",
  273. fc_target_setup,
  274. NULL,
  275. NULL);
  276. static int fc_host_setup(struct transport_container *tc, struct device *dev,
  277. struct class_device *cdev)
  278. {
  279. struct Scsi_Host *shost = dev_to_shost(dev);
  280. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  281. /*
  282. * Set default values easily detected by the midlayer as
  283. * failure cases. The scsi lldd is responsible for initializing
  284. * all transport attributes to valid values per host.
  285. */
  286. fc_host->node_name = -1;
  287. fc_host->port_name = -1;
  288. fc_host->permanent_port_name = -1;
  289. fc_host->supported_classes = FC_COS_UNSPECIFIED;
  290. memset(fc_host->supported_fc4s, 0,
  291. sizeof(fc_host->supported_fc4s));
  292. fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
  293. fc_host->maxframe_size = -1;
  294. memset(fc_host->serial_number, 0,
  295. sizeof(fc_host->serial_number));
  296. fc_host->port_id = -1;
  297. fc_host->port_type = FC_PORTTYPE_UNKNOWN;
  298. fc_host->port_state = FC_PORTSTATE_UNKNOWN;
  299. memset(fc_host->active_fc4s, 0,
  300. sizeof(fc_host->active_fc4s));
  301. fc_host->speed = FC_PORTSPEED_UNKNOWN;
  302. fc_host->fabric_name = -1;
  303. memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
  304. memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
  305. fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
  306. INIT_LIST_HEAD(&fc_host->rports);
  307. INIT_LIST_HEAD(&fc_host->rport_bindings);
  308. fc_host->next_rport_number = 0;
  309. fc_host->next_target_id = 0;
  310. snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d",
  311. shost->host_no);
  312. fc_host->work_q = create_singlethread_workqueue(
  313. fc_host->work_q_name);
  314. if (!fc_host->work_q)
  315. return -ENOMEM;
  316. snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d",
  317. shost->host_no);
  318. fc_host->devloss_work_q = create_singlethread_workqueue(
  319. fc_host->devloss_work_q_name);
  320. if (!fc_host->devloss_work_q) {
  321. destroy_workqueue(fc_host->work_q);
  322. fc_host->work_q = NULL;
  323. return -ENOMEM;
  324. }
  325. return 0;
  326. }
  327. static DECLARE_TRANSPORT_CLASS(fc_host_class,
  328. "fc_host",
  329. fc_host_setup,
  330. NULL,
  331. NULL);
  332. /*
  333. * Setup and Remove actions for remote ports are handled
  334. * in the service functions below.
  335. */
  336. static DECLARE_TRANSPORT_CLASS(fc_rport_class,
  337. "fc_remote_ports",
  338. NULL,
  339. NULL,
  340. NULL);
  341. /*
  342. * Module Parameters
  343. */
  344. /*
  345. * dev_loss_tmo: the default number of seconds that the FC transport
  346. * should insulate the loss of a remote port.
  347. * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
  348. */
  349. static unsigned int fc_dev_loss_tmo = 60; /* seconds */
  350. module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR);
  351. MODULE_PARM_DESC(dev_loss_tmo,
  352. "Maximum number of seconds that the FC transport should"
  353. " insulate the loss of a remote port. Once this value is"
  354. " exceeded, the scsi target is removed. Value should be"
  355. " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");
  356. /**
  357. * Netlink Infrastructure
  358. **/
  359. static atomic_t fc_event_seq;
  360. /**
  361. * fc_get_event_number - Obtain the next sequential FC event number
  362. *
  363. * Notes:
  364. * We could have inline'd this, but it would have required fc_event_seq to
  365. * be exposed. For now, live with the subroutine call.
  366. * Atomic used to avoid lock/unlock...
  367. **/
  368. u32
  369. fc_get_event_number(void)
  370. {
  371. return atomic_add_return(1, &fc_event_seq);
  372. }
  373. EXPORT_SYMBOL(fc_get_event_number);
  374. /**
  375. * fc_host_post_event - called to post an even on an fc_host.
  376. *
  377. * @shost: host the event occurred on
  378. * @event_number: fc event number obtained from get_fc_event_number()
  379. * @event_code: fc_host event being posted
  380. * @event_data: 32bits of data for the event being posted
  381. *
  382. * Notes:
  383. * This routine assumes no locks are held on entry.
  384. **/
  385. void
  386. fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
  387. enum fc_host_event_code event_code, u32 event_data)
  388. {
  389. struct sk_buff *skb;
  390. struct nlmsghdr *nlh;
  391. struct fc_nl_event *event;
  392. const char *name;
  393. u32 len, skblen;
  394. int err;
  395. if (!scsi_nl_sock) {
  396. err = -ENOENT;
  397. goto send_fail;
  398. }
  399. len = FC_NL_MSGALIGN(sizeof(*event));
  400. skblen = NLMSG_SPACE(len);
  401. skb = alloc_skb(skblen, GFP_KERNEL);
  402. if (!skb) {
  403. err = -ENOBUFS;
  404. goto send_fail;
  405. }
  406. nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
  407. skblen - sizeof(*nlh), 0);
  408. if (!nlh) {
  409. err = -ENOBUFS;
  410. goto send_fail_skb;
  411. }
  412. event = NLMSG_DATA(nlh);
  413. INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
  414. FC_NL_ASYNC_EVENT, len);
  415. event->seconds = get_seconds();
  416. event->vendor_id = 0;
  417. event->host_no = shost->host_no;
  418. event->event_datalen = sizeof(u32); /* bytes */
  419. event->event_num = event_number;
  420. event->event_code = event_code;
  421. event->event_data = event_data;
  422. err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS);
  423. if (err && (err != -ESRCH)) /* filter no recipient errors */
  424. /* nlmsg_multicast already kfree_skb'd */
  425. goto send_fail;
  426. return;
  427. send_fail_skb:
  428. kfree_skb(skb);
  429. send_fail:
  430. name = get_fc_host_event_code_name(event_code);
  431. printk(KERN_WARNING
  432. "%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
  433. __FUNCTION__, shost->host_no,
  434. (name) ? name : "<unknown>", event_data, err);
  435. return;
  436. }
  437. EXPORT_SYMBOL(fc_host_post_event);
  438. /**
  439. * fc_host_post_vendor_event - called to post a vendor unique event on
  440. * a fc_host
  441. *
  442. * @shost: host the event occurred on
  443. * @event_number: fc event number obtained from get_fc_event_number()
  444. * @data_len: amount, in bytes, of vendor unique data
  445. * @data_buf: pointer to vendor unique data
  446. *
  447. * Notes:
  448. * This routine assumes no locks are held on entry.
  449. **/
  450. void
  451. fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
  452. u32 data_len, char * data_buf, u64 vendor_id)
  453. {
  454. struct sk_buff *skb;
  455. struct nlmsghdr *nlh;
  456. struct fc_nl_event *event;
  457. u32 len, skblen;
  458. int err;
  459. if (!scsi_nl_sock) {
  460. err = -ENOENT;
  461. goto send_vendor_fail;
  462. }
  463. len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
  464. skblen = NLMSG_SPACE(len);
  465. skb = alloc_skb(skblen, GFP_KERNEL);
  466. if (!skb) {
  467. err = -ENOBUFS;
  468. goto send_vendor_fail;
  469. }
  470. nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
  471. skblen - sizeof(*nlh), 0);
  472. if (!nlh) {
  473. err = -ENOBUFS;
  474. goto send_vendor_fail_skb;
  475. }
  476. event = NLMSG_DATA(nlh);
  477. INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
  478. FC_NL_ASYNC_EVENT, len);
  479. event->seconds = get_seconds();
  480. event->vendor_id = vendor_id;
  481. event->host_no = shost->host_no;
  482. event->event_datalen = data_len; /* bytes */
  483. event->event_num = event_number;
  484. event->event_code = FCH_EVT_VENDOR_UNIQUE;
  485. memcpy(&event->event_data, data_buf, data_len);
  486. err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS);
  487. if (err && (err != -ESRCH)) /* filter no recipient errors */
  488. /* nlmsg_multicast already kfree_skb'd */
  489. goto send_vendor_fail;
  490. return;
  491. send_vendor_fail_skb:
  492. kfree_skb(skb);
  493. send_vendor_fail:
  494. printk(KERN_WARNING
  495. "%s: Dropped Event : host %d vendor_unique - err %d\n",
  496. __FUNCTION__, shost->host_no, err);
  497. return;
  498. }
  499. EXPORT_SYMBOL(fc_host_post_vendor_event);
  500. static __init int fc_transport_init(void)
  501. {
  502. int error;
  503. atomic_set(&fc_event_seq, 0);
  504. error = transport_class_register(&fc_host_class);
  505. if (error)
  506. return error;
  507. error = transport_class_register(&fc_rport_class);
  508. if (error)
  509. return error;
  510. return transport_class_register(&fc_transport_class);
  511. }
  512. static void __exit fc_transport_exit(void)
  513. {
  514. transport_class_unregister(&fc_transport_class);
  515. transport_class_unregister(&fc_rport_class);
  516. transport_class_unregister(&fc_host_class);
  517. }
  518. /*
  519. * FC Remote Port Attribute Management
  520. */
  521. #define fc_rport_show_function(field, format_string, sz, cast) \
  522. static ssize_t \
  523. show_fc_rport_##field (struct class_device *cdev, char *buf) \
  524. { \
  525. struct fc_rport *rport = transport_class_to_rport(cdev); \
  526. struct Scsi_Host *shost = rport_to_shost(rport); \
  527. struct fc_internal *i = to_fc_internal(shost->transportt); \
  528. if ((i->f->get_rport_##field) && \
  529. !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
  530. (rport->port_state == FC_PORTSTATE_DELETED) || \
  531. (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
  532. i->f->get_rport_##field(rport); \
  533. return snprintf(buf, sz, format_string, cast rport->field); \
  534. }
  535. #define fc_rport_store_function(field) \
  536. static ssize_t \
  537. store_fc_rport_##field(struct class_device *cdev, const char *buf, \
  538. size_t count) \
  539. { \
  540. int val; \
  541. struct fc_rport *rport = transport_class_to_rport(cdev); \
  542. struct Scsi_Host *shost = rport_to_shost(rport); \
  543. struct fc_internal *i = to_fc_internal(shost->transportt); \
  544. if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
  545. (rport->port_state == FC_PORTSTATE_DELETED) || \
  546. (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
  547. return -EBUSY; \
  548. val = simple_strtoul(buf, NULL, 0); \
  549. i->f->set_rport_##field(rport, val); \
  550. return count; \
  551. }
  552. #define fc_rport_rd_attr(field, format_string, sz) \
  553. fc_rport_show_function(field, format_string, sz, ) \
  554. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  555. show_fc_rport_##field, NULL)
  556. #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
  557. fc_rport_show_function(field, format_string, sz, (cast)) \
  558. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  559. show_fc_rport_##field, NULL)
  560. #define fc_rport_rw_attr(field, format_string, sz) \
  561. fc_rport_show_function(field, format_string, sz, ) \
  562. fc_rport_store_function(field) \
  563. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
  564. show_fc_rport_##field, \
  565. store_fc_rport_##field)
  566. #define fc_private_rport_show_function(field, format_string, sz, cast) \
  567. static ssize_t \
  568. show_fc_rport_##field (struct class_device *cdev, char *buf) \
  569. { \
  570. struct fc_rport *rport = transport_class_to_rport(cdev); \
  571. return snprintf(buf, sz, format_string, cast rport->field); \
  572. }
  573. #define fc_private_rport_rd_attr(field, format_string, sz) \
  574. fc_private_rport_show_function(field, format_string, sz, ) \
  575. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  576. show_fc_rport_##field, NULL)
  577. #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
  578. fc_private_rport_show_function(field, format_string, sz, (cast)) \
  579. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  580. show_fc_rport_##field, NULL)
  581. #define fc_private_rport_rd_enum_attr(title, maxlen) \
  582. static ssize_t \
  583. show_fc_rport_##title (struct class_device *cdev, char *buf) \
  584. { \
  585. struct fc_rport *rport = transport_class_to_rport(cdev); \
  586. const char *name; \
  587. name = get_fc_##title##_name(rport->title); \
  588. if (!name) \
  589. return -EINVAL; \
  590. return snprintf(buf, maxlen, "%s\n", name); \
  591. } \
  592. static FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \
  593. show_fc_rport_##title, NULL)
  594. #define SETUP_RPORT_ATTRIBUTE_RD(field) \
  595. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  596. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  597. i->private_rport_attrs[count].store = NULL; \
  598. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  599. if (i->f->show_rport_##field) \
  600. count++
  601. #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
  602. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  603. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  604. i->private_rport_attrs[count].store = NULL; \
  605. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  606. count++
  607. #define SETUP_RPORT_ATTRIBUTE_RW(field) \
  608. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  609. if (!i->f->set_rport_##field) { \
  610. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  611. i->private_rport_attrs[count].store = NULL; \
  612. } \
  613. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  614. if (i->f->show_rport_##field) \
  615. count++
  616. /* The FC Transport Remote Port Attributes: */
  617. /* Fixed Remote Port Attributes */
  618. fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
  619. static ssize_t
  620. show_fc_rport_supported_classes (struct class_device *cdev, char *buf)
  621. {
  622. struct fc_rport *rport = transport_class_to_rport(cdev);
  623. if (rport->supported_classes == FC_COS_UNSPECIFIED)
  624. return snprintf(buf, 20, "unspecified\n");
  625. return get_fc_cos_names(rport->supported_classes, buf);
  626. }
  627. static FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
  628. show_fc_rport_supported_classes, NULL);
  629. /* Dynamic Remote Port Attributes */
  630. /*
  631. * dev_loss_tmo attribute
  632. */
  633. fc_rport_show_function(dev_loss_tmo, "%d\n", 20, )
  634. static ssize_t
  635. store_fc_rport_dev_loss_tmo(struct class_device *cdev, const char *buf,
  636. size_t count)
  637. {
  638. int val;
  639. struct fc_rport *rport = transport_class_to_rport(cdev);
  640. struct Scsi_Host *shost = rport_to_shost(rport);
  641. struct fc_internal *i = to_fc_internal(shost->transportt);
  642. if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
  643. (rport->port_state == FC_PORTSTATE_DELETED) ||
  644. (rport->port_state == FC_PORTSTATE_NOTPRESENT))
  645. return -EBUSY;
  646. val = simple_strtoul(buf, NULL, 0);
  647. if ((val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
  648. return -EINVAL;
  649. i->f->set_rport_dev_loss_tmo(rport, val);
  650. return count;
  651. }
  652. static FC_CLASS_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
  653. show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
  654. /* Private Remote Port Attributes */
  655. fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  656. fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  657. fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
  658. static ssize_t
  659. show_fc_rport_roles (struct class_device *cdev, char *buf)
  660. {
  661. struct fc_rport *rport = transport_class_to_rport(cdev);
  662. /* identify any roles that are port_id specific */
  663. if ((rport->port_id != -1) &&
  664. (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
  665. FC_WELLKNOWN_PORTID_MASK) {
  666. switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
  667. case FC_FPORT_PORTID:
  668. return snprintf(buf, 30, "Fabric Port\n");
  669. case FC_FABCTLR_PORTID:
  670. return snprintf(buf, 30, "Fabric Controller\n");
  671. case FC_DIRSRVR_PORTID:
  672. return snprintf(buf, 30, "Directory Server\n");
  673. case FC_TIMESRVR_PORTID:
  674. return snprintf(buf, 30, "Time Server\n");
  675. case FC_MGMTSRVR_PORTID:
  676. return snprintf(buf, 30, "Management Server\n");
  677. default:
  678. return snprintf(buf, 30, "Unknown Fabric Entity\n");
  679. }
  680. } else {
  681. if (rport->roles == FC_RPORT_ROLE_UNKNOWN)
  682. return snprintf(buf, 20, "unknown\n");
  683. return get_fc_remote_port_roles_names(rport->roles, buf);
  684. }
  685. }
  686. static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO,
  687. show_fc_rport_roles, NULL);
  688. fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  689. fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
  690. /*
  691. * FC SCSI Target Attribute Management
  692. */
  693. /*
  694. * Note: in the target show function we recognize when the remote
  695. * port is in the heirarchy and do not allow the driver to get
  696. * involved in sysfs functions. The driver only gets involved if
  697. * it's the "old" style that doesn't use rports.
  698. */
  699. #define fc_starget_show_function(field, format_string, sz, cast) \
  700. static ssize_t \
  701. show_fc_starget_##field (struct class_device *cdev, char *buf) \
  702. { \
  703. struct scsi_target *starget = transport_class_to_starget(cdev); \
  704. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
  705. struct fc_internal *i = to_fc_internal(shost->transportt); \
  706. struct fc_rport *rport = starget_to_rport(starget); \
  707. if (rport) \
  708. fc_starget_##field(starget) = rport->field; \
  709. else if (i->f->get_starget_##field) \
  710. i->f->get_starget_##field(starget); \
  711. return snprintf(buf, sz, format_string, \
  712. cast fc_starget_##field(starget)); \
  713. }
  714. #define fc_starget_rd_attr(field, format_string, sz) \
  715. fc_starget_show_function(field, format_string, sz, ) \
  716. static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
  717. show_fc_starget_##field, NULL)
  718. #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
  719. fc_starget_show_function(field, format_string, sz, (cast)) \
  720. static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
  721. show_fc_starget_##field, NULL)
  722. #define SETUP_STARGET_ATTRIBUTE_RD(field) \
  723. i->private_starget_attrs[count] = class_device_attr_starget_##field; \
  724. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  725. i->private_starget_attrs[count].store = NULL; \
  726. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  727. if (i->f->show_starget_##field) \
  728. count++
  729. #define SETUP_STARGET_ATTRIBUTE_RW(field) \
  730. i->private_starget_attrs[count] = class_device_attr_starget_##field; \
  731. if (!i->f->set_starget_##field) { \
  732. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  733. i->private_starget_attrs[count].store = NULL; \
  734. } \
  735. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  736. if (i->f->show_starget_##field) \
  737. count++
  738. /* The FC Transport SCSI Target Attributes: */
  739. fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  740. fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  741. fc_starget_rd_attr(port_id, "0x%06x\n", 20);
  742. /*
  743. * Host Attribute Management
  744. */
  745. #define fc_host_show_function(field, format_string, sz, cast) \
  746. static ssize_t \
  747. show_fc_host_##field (struct class_device *cdev, char *buf) \
  748. { \
  749. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  750. struct fc_internal *i = to_fc_internal(shost->transportt); \
  751. if (i->f->get_host_##field) \
  752. i->f->get_host_##field(shost); \
  753. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  754. }
  755. #define fc_host_store_function(field) \
  756. static ssize_t \
  757. store_fc_host_##field(struct class_device *cdev, const char *buf, \
  758. size_t count) \
  759. { \
  760. int val; \
  761. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  762. struct fc_internal *i = to_fc_internal(shost->transportt); \
  763. \
  764. val = simple_strtoul(buf, NULL, 0); \
  765. i->f->set_host_##field(shost, val); \
  766. return count; \
  767. }
  768. #define fc_host_store_str_function(field, slen) \
  769. static ssize_t \
  770. store_fc_host_##field(struct class_device *cdev, const char *buf, \
  771. size_t count) \
  772. { \
  773. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  774. struct fc_internal *i = to_fc_internal(shost->transportt); \
  775. unsigned int cnt=count; \
  776. \
  777. /* count may include a LF at end of string */ \
  778. if (buf[cnt-1] == '\n') \
  779. cnt--; \
  780. if (cnt > ((slen) - 1)) \
  781. return -EINVAL; \
  782. memcpy(fc_host_##field(shost), buf, cnt); \
  783. i->f->set_host_##field(shost); \
  784. return count; \
  785. }
  786. #define fc_host_rd_attr(field, format_string, sz) \
  787. fc_host_show_function(field, format_string, sz, ) \
  788. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  789. show_fc_host_##field, NULL)
  790. #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
  791. fc_host_show_function(field, format_string, sz, (cast)) \
  792. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  793. show_fc_host_##field, NULL)
  794. #define fc_host_rw_attr(field, format_string, sz) \
  795. fc_host_show_function(field, format_string, sz, ) \
  796. fc_host_store_function(field) \
  797. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
  798. show_fc_host_##field, \
  799. store_fc_host_##field)
  800. #define fc_host_rd_enum_attr(title, maxlen) \
  801. static ssize_t \
  802. show_fc_host_##title (struct class_device *cdev, char *buf) \
  803. { \
  804. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  805. struct fc_internal *i = to_fc_internal(shost->transportt); \
  806. const char *name; \
  807. if (i->f->get_host_##title) \
  808. i->f->get_host_##title(shost); \
  809. name = get_fc_##title##_name(fc_host_##title(shost)); \
  810. if (!name) \
  811. return -EINVAL; \
  812. return snprintf(buf, maxlen, "%s\n", name); \
  813. } \
  814. static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
  815. #define SETUP_HOST_ATTRIBUTE_RD(field) \
  816. i->private_host_attrs[count] = class_device_attr_host_##field; \
  817. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  818. i->private_host_attrs[count].store = NULL; \
  819. i->host_attrs[count] = &i->private_host_attrs[count]; \
  820. if (i->f->show_host_##field) \
  821. count++
  822. #define SETUP_HOST_ATTRIBUTE_RW(field) \
  823. i->private_host_attrs[count] = class_device_attr_host_##field; \
  824. if (!i->f->set_host_##field) { \
  825. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  826. i->private_host_attrs[count].store = NULL; \
  827. } \
  828. i->host_attrs[count] = &i->private_host_attrs[count]; \
  829. if (i->f->show_host_##field) \
  830. count++
  831. #define fc_private_host_show_function(field, format_string, sz, cast) \
  832. static ssize_t \
  833. show_fc_host_##field (struct class_device *cdev, char *buf) \
  834. { \
  835. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  836. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  837. }
  838. #define fc_private_host_rd_attr(field, format_string, sz) \
  839. fc_private_host_show_function(field, format_string, sz, ) \
  840. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  841. show_fc_host_##field, NULL)
  842. #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
  843. fc_private_host_show_function(field, format_string, sz, (cast)) \
  844. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  845. show_fc_host_##field, NULL)
  846. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
  847. i->private_host_attrs[count] = class_device_attr_host_##field; \
  848. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  849. i->private_host_attrs[count].store = NULL; \
  850. i->host_attrs[count] = &i->private_host_attrs[count]; \
  851. count++
  852. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
  853. { \
  854. i->private_host_attrs[count] = class_device_attr_host_##field; \
  855. i->host_attrs[count] = &i->private_host_attrs[count]; \
  856. count++; \
  857. }
  858. /* Fixed Host Attributes */
  859. static ssize_t
  860. show_fc_host_supported_classes (struct class_device *cdev, char *buf)
  861. {
  862. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  863. if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
  864. return snprintf(buf, 20, "unspecified\n");
  865. return get_fc_cos_names(fc_host_supported_classes(shost), buf);
  866. }
  867. static FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO,
  868. show_fc_host_supported_classes, NULL);
  869. static ssize_t
  870. show_fc_host_supported_fc4s (struct class_device *cdev, char *buf)
  871. {
  872. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  873. return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
  874. }
  875. static FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
  876. show_fc_host_supported_fc4s, NULL);
  877. static ssize_t
  878. show_fc_host_supported_speeds (struct class_device *cdev, char *buf)
  879. {
  880. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  881. if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
  882. return snprintf(buf, 20, "unknown\n");
  883. return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
  884. }
  885. static FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
  886. show_fc_host_supported_speeds, NULL);
  887. fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  888. fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  889. fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
  890. unsigned long long);
  891. fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
  892. fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
  893. /* Dynamic Host Attributes */
  894. static ssize_t
  895. show_fc_host_active_fc4s (struct class_device *cdev, char *buf)
  896. {
  897. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  898. struct fc_internal *i = to_fc_internal(shost->transportt);
  899. if (i->f->get_host_active_fc4s)
  900. i->f->get_host_active_fc4s(shost);
  901. return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
  902. }
  903. static FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
  904. show_fc_host_active_fc4s, NULL);
  905. static ssize_t
  906. show_fc_host_speed (struct class_device *cdev, char *buf)
  907. {
  908. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  909. struct fc_internal *i = to_fc_internal(shost->transportt);
  910. if (i->f->get_host_speed)
  911. i->f->get_host_speed(shost);
  912. if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
  913. return snprintf(buf, 20, "unknown\n");
  914. return get_fc_port_speed_names(fc_host_speed(shost), buf);
  915. }
  916. static FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO,
  917. show_fc_host_speed, NULL);
  918. fc_host_rd_attr(port_id, "0x%06x\n", 20);
  919. fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
  920. fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  921. fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
  922. fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
  923. fc_private_host_show_function(system_hostname, "%s\n",
  924. FC_SYMBOLIC_NAME_SIZE + 1, )
  925. fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
  926. static FC_CLASS_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
  927. show_fc_host_system_hostname, store_fc_host_system_hostname);
  928. /* Private Host Attributes */
  929. static ssize_t
  930. show_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf)
  931. {
  932. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  933. const char *name;
  934. name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
  935. if (!name)
  936. return -EINVAL;
  937. return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
  938. }
  939. #define get_list_head_entry(pos, head, member) \
  940. pos = list_entry((head)->next, typeof(*pos), member)
  941. static ssize_t
  942. store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
  943. const char *buf, size_t count)
  944. {
  945. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  946. struct fc_rport *rport;
  947. enum fc_tgtid_binding_type val;
  948. unsigned long flags;
  949. if (get_fc_tgtid_bind_type_match(buf, &val))
  950. return -EINVAL;
  951. /* if changing bind type, purge all unused consistent bindings */
  952. if (val != fc_host_tgtid_bind_type(shost)) {
  953. spin_lock_irqsave(shost->host_lock, flags);
  954. while (!list_empty(&fc_host_rport_bindings(shost))) {
  955. get_list_head_entry(rport,
  956. &fc_host_rport_bindings(shost), peers);
  957. list_del(&rport->peers);
  958. rport->port_state = FC_PORTSTATE_DELETED;
  959. fc_queue_work(shost, &rport->rport_delete_work);
  960. }
  961. spin_unlock_irqrestore(shost->host_lock, flags);
  962. }
  963. fc_host_tgtid_bind_type(shost) = val;
  964. return count;
  965. }
  966. static FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
  967. show_fc_private_host_tgtid_bind_type,
  968. store_fc_private_host_tgtid_bind_type);
  969. static ssize_t
  970. store_fc_private_host_issue_lip(struct class_device *cdev,
  971. const char *buf, size_t count)
  972. {
  973. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  974. struct fc_internal *i = to_fc_internal(shost->transportt);
  975. int ret;
  976. /* ignore any data value written to the attribute */
  977. if (i->f->issue_fc_host_lip) {
  978. ret = i->f->issue_fc_host_lip(shost);
  979. return ret ? ret: count;
  980. }
  981. return -ENOENT;
  982. }
  983. static FC_CLASS_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL,
  984. store_fc_private_host_issue_lip);
  985. /*
  986. * Host Statistics Management
  987. */
  988. /* Show a given an attribute in the statistics group */
  989. static ssize_t
  990. fc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset)
  991. {
  992. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  993. struct fc_internal *i = to_fc_internal(shost->transportt);
  994. struct fc_host_statistics *stats;
  995. ssize_t ret = -ENOENT;
  996. if (offset > sizeof(struct fc_host_statistics) ||
  997. offset % sizeof(u64) != 0)
  998. WARN_ON(1);
  999. if (i->f->get_fc_host_stats) {
  1000. stats = (i->f->get_fc_host_stats)(shost);
  1001. if (stats)
  1002. ret = snprintf(buf, 20, "0x%llx\n",
  1003. (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
  1004. }
  1005. return ret;
  1006. }
  1007. /* generate a read-only statistics attribute */
  1008. #define fc_host_statistic(name) \
  1009. static ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \
  1010. { \
  1011. return fc_stat_show(cd, buf, \
  1012. offsetof(struct fc_host_statistics, name)); \
  1013. } \
  1014. static FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
  1015. fc_host_statistic(seconds_since_last_reset);
  1016. fc_host_statistic(tx_frames);
  1017. fc_host_statistic(tx_words);
  1018. fc_host_statistic(rx_frames);
  1019. fc_host_statistic(rx_words);
  1020. fc_host_statistic(lip_count);
  1021. fc_host_statistic(nos_count);
  1022. fc_host_statistic(error_frames);
  1023. fc_host_statistic(dumped_frames);
  1024. fc_host_statistic(link_failure_count);
  1025. fc_host_statistic(loss_of_sync_count);
  1026. fc_host_statistic(loss_of_signal_count);
  1027. fc_host_statistic(prim_seq_protocol_err_count);
  1028. fc_host_statistic(invalid_tx_word_count);
  1029. fc_host_statistic(invalid_crc_count);
  1030. fc_host_statistic(fcp_input_requests);
  1031. fc_host_statistic(fcp_output_requests);
  1032. fc_host_statistic(fcp_control_requests);
  1033. fc_host_statistic(fcp_input_megabytes);
  1034. fc_host_statistic(fcp_output_megabytes);
  1035. static ssize_t
  1036. fc_reset_statistics(struct class_device *cdev, const char *buf,
  1037. size_t count)
  1038. {
  1039. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  1040. struct fc_internal *i = to_fc_internal(shost->transportt);
  1041. /* ignore any data value written to the attribute */
  1042. if (i->f->reset_fc_host_stats) {
  1043. i->f->reset_fc_host_stats(shost);
  1044. return count;
  1045. }
  1046. return -ENOENT;
  1047. }
  1048. static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
  1049. fc_reset_statistics);
  1050. static struct attribute *fc_statistics_attrs[] = {
  1051. &class_device_attr_host_seconds_since_last_reset.attr,
  1052. &class_device_attr_host_tx_frames.attr,
  1053. &class_device_attr_host_tx_words.attr,
  1054. &class_device_attr_host_rx_frames.attr,
  1055. &class_device_attr_host_rx_words.attr,
  1056. &class_device_attr_host_lip_count.attr,
  1057. &class_device_attr_host_nos_count.attr,
  1058. &class_device_attr_host_error_frames.attr,
  1059. &class_device_attr_host_dumped_frames.attr,
  1060. &class_device_attr_host_link_failure_count.attr,
  1061. &class_device_attr_host_loss_of_sync_count.attr,
  1062. &class_device_attr_host_loss_of_signal_count.attr,
  1063. &class_device_attr_host_prim_seq_protocol_err_count.attr,
  1064. &class_device_attr_host_invalid_tx_word_count.attr,
  1065. &class_device_attr_host_invalid_crc_count.attr,
  1066. &class_device_attr_host_fcp_input_requests.attr,
  1067. &class_device_attr_host_fcp_output_requests.attr,
  1068. &class_device_attr_host_fcp_control_requests.attr,
  1069. &class_device_attr_host_fcp_input_megabytes.attr,
  1070. &class_device_attr_host_fcp_output_megabytes.attr,
  1071. &class_device_attr_host_reset_statistics.attr,
  1072. NULL
  1073. };
  1074. static struct attribute_group fc_statistics_group = {
  1075. .name = "statistics",
  1076. .attrs = fc_statistics_attrs,
  1077. };
  1078. static int fc_host_match(struct attribute_container *cont,
  1079. struct device *dev)
  1080. {
  1081. struct Scsi_Host *shost;
  1082. struct fc_internal *i;
  1083. if (!scsi_is_host_device(dev))
  1084. return 0;
  1085. shost = dev_to_shost(dev);
  1086. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1087. != &fc_host_class.class)
  1088. return 0;
  1089. i = to_fc_internal(shost->transportt);
  1090. return &i->t.host_attrs.ac == cont;
  1091. }
  1092. static int fc_target_match(struct attribute_container *cont,
  1093. struct device *dev)
  1094. {
  1095. struct Scsi_Host *shost;
  1096. struct fc_internal *i;
  1097. if (!scsi_is_target_device(dev))
  1098. return 0;
  1099. shost = dev_to_shost(dev->parent);
  1100. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1101. != &fc_host_class.class)
  1102. return 0;
  1103. i = to_fc_internal(shost->transportt);
  1104. return &i->t.target_attrs.ac == cont;
  1105. }
  1106. static void fc_rport_dev_release(struct device *dev)
  1107. {
  1108. struct fc_rport *rport = dev_to_rport(dev);
  1109. put_device(dev->parent);
  1110. kfree(rport);
  1111. }
  1112. int scsi_is_fc_rport(const struct device *dev)
  1113. {
  1114. return dev->release == fc_rport_dev_release;
  1115. }
  1116. EXPORT_SYMBOL(scsi_is_fc_rport);
  1117. static int fc_rport_match(struct attribute_container *cont,
  1118. struct device *dev)
  1119. {
  1120. struct Scsi_Host *shost;
  1121. struct fc_internal *i;
  1122. if (!scsi_is_fc_rport(dev))
  1123. return 0;
  1124. shost = dev_to_shost(dev->parent);
  1125. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1126. != &fc_host_class.class)
  1127. return 0;
  1128. i = to_fc_internal(shost->transportt);
  1129. return &i->rport_attr_cont.ac == cont;
  1130. }
  1131. /**
  1132. * fc_timed_out - FC Transport I/O timeout intercept handler
  1133. *
  1134. * @scmd: The SCSI command which timed out
  1135. *
  1136. * This routine protects against error handlers getting invoked while a
  1137. * rport is in a blocked state, typically due to a temporarily loss of
  1138. * connectivity. If the error handlers are allowed to proceed, requests
  1139. * to abort i/o, reset the target, etc will likely fail as there is no way
  1140. * to communicate with the device to perform the requested function. These
  1141. * failures may result in the midlayer taking the device offline, requiring
  1142. * manual intervention to restore operation.
  1143. *
  1144. * This routine, called whenever an i/o times out, validates the state of
  1145. * the underlying rport. If the rport is blocked, it returns
  1146. * EH_RESET_TIMER, which will continue to reschedule the timeout.
  1147. * Eventually, either the device will return, or devloss_tmo will fire,
  1148. * and when the timeout then fires, it will be handled normally.
  1149. * If the rport is not blocked, normal error handling continues.
  1150. *
  1151. * Notes:
  1152. * This routine assumes no locks are held on entry.
  1153. **/
  1154. static enum scsi_eh_timer_return
  1155. fc_timed_out(struct scsi_cmnd *scmd)
  1156. {
  1157. struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
  1158. if (rport->port_state == FC_PORTSTATE_BLOCKED)
  1159. return EH_RESET_TIMER;
  1160. return EH_NOT_HANDLED;
  1161. }
  1162. /*
  1163. * Must be called with shost->host_lock held
  1164. */
  1165. static int fc_user_scan(struct Scsi_Host *shost, uint channel,
  1166. uint id, uint lun)
  1167. {
  1168. struct fc_rport *rport;
  1169. list_for_each_entry(rport, &fc_host_rports(shost), peers) {
  1170. if (rport->scsi_target_id == -1)
  1171. continue;
  1172. if ((channel == SCAN_WILD_CARD || channel == rport->channel) &&
  1173. (id == SCAN_WILD_CARD || id == rport->scsi_target_id)) {
  1174. scsi_scan_target(&rport->dev, rport->channel,
  1175. rport->scsi_target_id, lun, 1);
  1176. }
  1177. }
  1178. return 0;
  1179. }
  1180. struct scsi_transport_template *
  1181. fc_attach_transport(struct fc_function_template *ft)
  1182. {
  1183. int count;
  1184. struct fc_internal *i = kzalloc(sizeof(struct fc_internal),
  1185. GFP_KERNEL);
  1186. if (unlikely(!i))
  1187. return NULL;
  1188. i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
  1189. i->t.target_attrs.ac.class = &fc_transport_class.class;
  1190. i->t.target_attrs.ac.match = fc_target_match;
  1191. i->t.target_size = sizeof(struct fc_starget_attrs);
  1192. transport_container_register(&i->t.target_attrs);
  1193. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  1194. i->t.host_attrs.ac.class = &fc_host_class.class;
  1195. i->t.host_attrs.ac.match = fc_host_match;
  1196. i->t.host_size = sizeof(struct fc_host_attrs);
  1197. if (ft->get_fc_host_stats)
  1198. i->t.host_attrs.statistics = &fc_statistics_group;
  1199. transport_container_register(&i->t.host_attrs);
  1200. i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
  1201. i->rport_attr_cont.ac.class = &fc_rport_class.class;
  1202. i->rport_attr_cont.ac.match = fc_rport_match;
  1203. transport_container_register(&i->rport_attr_cont);
  1204. i->f = ft;
  1205. /* Transport uses the shost workq for scsi scanning */
  1206. i->t.create_work_queue = 1;
  1207. i->t.eh_timed_out = fc_timed_out;
  1208. i->t.user_scan = fc_user_scan;
  1209. /*
  1210. * Setup SCSI Target Attributes.
  1211. */
  1212. count = 0;
  1213. SETUP_STARGET_ATTRIBUTE_RD(node_name);
  1214. SETUP_STARGET_ATTRIBUTE_RD(port_name);
  1215. SETUP_STARGET_ATTRIBUTE_RD(port_id);
  1216. BUG_ON(count > FC_STARGET_NUM_ATTRS);
  1217. i->starget_attrs[count] = NULL;
  1218. /*
  1219. * Setup SCSI Host Attributes.
  1220. */
  1221. count=0;
  1222. SETUP_HOST_ATTRIBUTE_RD(node_name);
  1223. SETUP_HOST_ATTRIBUTE_RD(port_name);
  1224. SETUP_HOST_ATTRIBUTE_RD(permanent_port_name);
  1225. SETUP_HOST_ATTRIBUTE_RD(supported_classes);
  1226. SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
  1227. SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
  1228. SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
  1229. SETUP_HOST_ATTRIBUTE_RD(serial_number);
  1230. SETUP_HOST_ATTRIBUTE_RD(port_id);
  1231. SETUP_HOST_ATTRIBUTE_RD(port_type);
  1232. SETUP_HOST_ATTRIBUTE_RD(port_state);
  1233. SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
  1234. SETUP_HOST_ATTRIBUTE_RD(speed);
  1235. SETUP_HOST_ATTRIBUTE_RD(fabric_name);
  1236. SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
  1237. SETUP_HOST_ATTRIBUTE_RW(system_hostname);
  1238. /* Transport-managed attributes */
  1239. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
  1240. if (ft->issue_fc_host_lip)
  1241. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip);
  1242. BUG_ON(count > FC_HOST_NUM_ATTRS);
  1243. i->host_attrs[count] = NULL;
  1244. /*
  1245. * Setup Remote Port Attributes.
  1246. */
  1247. count=0;
  1248. SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
  1249. SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
  1250. SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
  1251. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
  1252. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
  1253. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
  1254. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
  1255. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
  1256. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
  1257. BUG_ON(count > FC_RPORT_NUM_ATTRS);
  1258. i->rport_attrs[count] = NULL;
  1259. return &i->t;
  1260. }
  1261. EXPORT_SYMBOL(fc_attach_transport);
  1262. void fc_release_transport(struct scsi_transport_template *t)
  1263. {
  1264. struct fc_internal *i = to_fc_internal(t);
  1265. transport_container_unregister(&i->t.target_attrs);
  1266. transport_container_unregister(&i->t.host_attrs);
  1267. transport_container_unregister(&i->rport_attr_cont);
  1268. kfree(i);
  1269. }
  1270. EXPORT_SYMBOL(fc_release_transport);
  1271. /**
  1272. * fc_queue_work - Queue work to the fc_host workqueue.
  1273. * @shost: Pointer to Scsi_Host bound to fc_host.
  1274. * @work: Work to queue for execution.
  1275. *
  1276. * Return value:
  1277. * 1 - work queued for execution
  1278. * 0 - work is already queued
  1279. * -EINVAL - work queue doesn't exist
  1280. **/
  1281. static int
  1282. fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
  1283. {
  1284. if (unlikely(!fc_host_work_q(shost))) {
  1285. printk(KERN_ERR
  1286. "ERROR: FC host '%s' attempted to queue work, "
  1287. "when no workqueue created.\n", shost->hostt->name);
  1288. dump_stack();
  1289. return -EINVAL;
  1290. }
  1291. return queue_work(fc_host_work_q(shost), work);
  1292. }
  1293. /**
  1294. * fc_flush_work - Flush a fc_host's workqueue.
  1295. * @shost: Pointer to Scsi_Host bound to fc_host.
  1296. **/
  1297. static void
  1298. fc_flush_work(struct Scsi_Host *shost)
  1299. {
  1300. if (!fc_host_work_q(shost)) {
  1301. printk(KERN_ERR
  1302. "ERROR: FC host '%s' attempted to flush work, "
  1303. "when no workqueue created.\n", shost->hostt->name);
  1304. dump_stack();
  1305. return;
  1306. }
  1307. flush_workqueue(fc_host_work_q(shost));
  1308. }
  1309. /**
  1310. * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
  1311. * @shost: Pointer to Scsi_Host bound to fc_host.
  1312. * @work: Work to queue for execution.
  1313. * @delay: jiffies to delay the work queuing
  1314. *
  1315. * Return value:
  1316. * 0 on success / != 0 for error
  1317. **/
  1318. static int
  1319. fc_queue_devloss_work(struct Scsi_Host *shost, struct work_struct *work,
  1320. unsigned long delay)
  1321. {
  1322. if (unlikely(!fc_host_devloss_work_q(shost))) {
  1323. printk(KERN_ERR
  1324. "ERROR: FC host '%s' attempted to queue work, "
  1325. "when no workqueue created.\n", shost->hostt->name);
  1326. dump_stack();
  1327. return -EINVAL;
  1328. }
  1329. return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay);
  1330. }
  1331. /**
  1332. * fc_flush_devloss - Flush a fc_host's devloss workqueue.
  1333. * @shost: Pointer to Scsi_Host bound to fc_host.
  1334. **/
  1335. static void
  1336. fc_flush_devloss(struct Scsi_Host *shost)
  1337. {
  1338. if (!fc_host_devloss_work_q(shost)) {
  1339. printk(KERN_ERR
  1340. "ERROR: FC host '%s' attempted to flush work, "
  1341. "when no workqueue created.\n", shost->hostt->name);
  1342. dump_stack();
  1343. return;
  1344. }
  1345. flush_workqueue(fc_host_devloss_work_q(shost));
  1346. }
  1347. /**
  1348. * fc_remove_host - called to terminate any fc_transport-related elements
  1349. * for a scsi host.
  1350. * @rport: remote port to be unblocked.
  1351. *
  1352. * This routine is expected to be called immediately preceeding the
  1353. * a driver's call to scsi_remove_host().
  1354. *
  1355. * WARNING: A driver utilizing the fc_transport, which fails to call
  1356. * this routine prior to scsi_remote_host(), will leave dangling
  1357. * objects in /sys/class/fc_remote_ports. Access to any of these
  1358. * objects can result in a system crash !!!
  1359. *
  1360. * Notes:
  1361. * This routine assumes no locks are held on entry.
  1362. **/
  1363. void
  1364. fc_remove_host(struct Scsi_Host *shost)
  1365. {
  1366. struct fc_rport *rport, *next_rport;
  1367. struct workqueue_struct *work_q;
  1368. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1369. /* Remove any remote ports */
  1370. list_for_each_entry_safe(rport, next_rport,
  1371. &fc_host->rports, peers) {
  1372. list_del(&rport->peers);
  1373. rport->port_state = FC_PORTSTATE_DELETED;
  1374. fc_queue_work(shost, &rport->rport_delete_work);
  1375. }
  1376. list_for_each_entry_safe(rport, next_rport,
  1377. &fc_host->rport_bindings, peers) {
  1378. list_del(&rport->peers);
  1379. rport->port_state = FC_PORTSTATE_DELETED;
  1380. fc_queue_work(shost, &rport->rport_delete_work);
  1381. }
  1382. /* flush all scan work items */
  1383. scsi_flush_work(shost);
  1384. /* flush all stgt delete, and rport delete work items, then kill it */
  1385. if (fc_host->work_q) {
  1386. work_q = fc_host->work_q;
  1387. fc_host->work_q = NULL;
  1388. destroy_workqueue(work_q);
  1389. }
  1390. /* flush all devloss work items, then kill it */
  1391. if (fc_host->devloss_work_q) {
  1392. work_q = fc_host->devloss_work_q;
  1393. fc_host->devloss_work_q = NULL;
  1394. destroy_workqueue(work_q);
  1395. }
  1396. }
  1397. EXPORT_SYMBOL(fc_remove_host);
  1398. /**
  1399. * fc_starget_delete - called to delete the scsi decendents of an rport
  1400. * (target and all sdevs)
  1401. *
  1402. * @data: remote port to be operated on.
  1403. **/
  1404. static void
  1405. fc_starget_delete(void *data)
  1406. {
  1407. struct fc_rport *rport = (struct fc_rport *)data;
  1408. struct Scsi_Host *shost = rport_to_shost(rport);
  1409. unsigned long flags;
  1410. spin_lock_irqsave(shost->host_lock, flags);
  1411. if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
  1412. spin_unlock_irqrestore(shost->host_lock, flags);
  1413. if (!cancel_delayed_work(&rport->dev_loss_work))
  1414. fc_flush_devloss(shost);
  1415. spin_lock_irqsave(shost->host_lock, flags);
  1416. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  1417. }
  1418. spin_unlock_irqrestore(shost->host_lock, flags);
  1419. scsi_remove_target(&rport->dev);
  1420. }
  1421. /**
  1422. * fc_rport_final_delete - finish rport termination and delete it.
  1423. *
  1424. * @data: remote port to be deleted.
  1425. **/
  1426. static void
  1427. fc_rport_final_delete(void *data)
  1428. {
  1429. struct fc_rport *rport = (struct fc_rport *)data;
  1430. struct device *dev = &rport->dev;
  1431. struct Scsi_Host *shost = rport_to_shost(rport);
  1432. /* Delete SCSI target and sdevs */
  1433. if (rport->scsi_target_id != -1)
  1434. fc_starget_delete(data);
  1435. /*
  1436. * if a scan is pending, flush the SCSI Host work_q so that
  1437. * that we can reclaim the rport scan work element.
  1438. */
  1439. if (rport->flags & FC_RPORT_SCAN_PENDING)
  1440. scsi_flush_work(shost);
  1441. transport_remove_device(dev);
  1442. device_del(dev);
  1443. transport_destroy_device(dev);
  1444. put_device(&shost->shost_gendev); /* for fc_host->rport list */
  1445. put_device(dev); /* for self-reference */
  1446. }
  1447. /**
  1448. * fc_rport_create - allocates and creates a remote FC port.
  1449. * @shost: scsi host the remote port is connected to.
  1450. * @channel: Channel on shost port connected to.
  1451. * @ids: The world wide names, fc address, and FC4 port
  1452. * roles for the remote port.
  1453. *
  1454. * Allocates and creates the remoter port structure, including the
  1455. * class and sysfs creation.
  1456. *
  1457. * Notes:
  1458. * This routine assumes no locks are held on entry.
  1459. **/
  1460. struct fc_rport *
  1461. fc_rport_create(struct Scsi_Host *shost, int channel,
  1462. struct fc_rport_identifiers *ids)
  1463. {
  1464. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1465. struct fc_internal *fci = to_fc_internal(shost->transportt);
  1466. struct fc_rport *rport;
  1467. struct device *dev;
  1468. unsigned long flags;
  1469. int error;
  1470. size_t size;
  1471. size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
  1472. rport = kzalloc(size, GFP_KERNEL);
  1473. if (unlikely(!rport)) {
  1474. printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
  1475. return NULL;
  1476. }
  1477. rport->maxframe_size = -1;
  1478. rport->supported_classes = FC_COS_UNSPECIFIED;
  1479. rport->dev_loss_tmo = fc_dev_loss_tmo;
  1480. memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
  1481. memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
  1482. rport->port_id = ids->port_id;
  1483. rport->roles = ids->roles;
  1484. rport->port_state = FC_PORTSTATE_ONLINE;
  1485. if (fci->f->dd_fcrport_size)
  1486. rport->dd_data = &rport[1];
  1487. rport->channel = channel;
  1488. INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport);
  1489. INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport);
  1490. INIT_WORK(&rport->stgt_delete_work, fc_starget_delete, rport);
  1491. INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete, rport);
  1492. spin_lock_irqsave(shost->host_lock, flags);
  1493. rport->number = fc_host->next_rport_number++;
  1494. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  1495. rport->scsi_target_id = fc_host->next_target_id++;
  1496. else
  1497. rport->scsi_target_id = -1;
  1498. list_add_tail(&rport->peers, &fc_host->rports);
  1499. get_device(&shost->shost_gendev); /* for fc_host->rport list */
  1500. spin_unlock_irqrestore(shost->host_lock, flags);
  1501. dev = &rport->dev;
  1502. device_initialize(dev); /* takes self reference */
  1503. dev->parent = get_device(&shost->shost_gendev); /* parent reference */
  1504. dev->release = fc_rport_dev_release;
  1505. sprintf(dev->bus_id, "rport-%d:%d-%d",
  1506. shost->host_no, channel, rport->number);
  1507. transport_setup_device(dev);
  1508. error = device_add(dev);
  1509. if (error) {
  1510. printk(KERN_ERR "FC Remote Port device_add failed\n");
  1511. goto delete_rport;
  1512. }
  1513. transport_add_device(dev);
  1514. transport_configure_device(dev);
  1515. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
  1516. /* initiate a scan of the target */
  1517. rport->flags |= FC_RPORT_SCAN_PENDING;
  1518. scsi_queue_work(shost, &rport->scan_work);
  1519. }
  1520. return rport;
  1521. delete_rport:
  1522. transport_destroy_device(dev);
  1523. spin_lock_irqsave(shost->host_lock, flags);
  1524. list_del(&rport->peers);
  1525. put_device(&shost->shost_gendev); /* for fc_host->rport list */
  1526. spin_unlock_irqrestore(shost->host_lock, flags);
  1527. put_device(dev->parent);
  1528. kfree(rport);
  1529. return NULL;
  1530. }
  1531. /**
  1532. * fc_remote_port_add - notifies the fc transport of the existence
  1533. * of a remote FC port.
  1534. * @shost: scsi host the remote port is connected to.
  1535. * @channel: Channel on shost port connected to.
  1536. * @ids: The world wide names, fc address, and FC4 port
  1537. * roles for the remote port.
  1538. *
  1539. * The LLDD calls this routine to notify the transport of the existence
  1540. * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
  1541. * of the port, it's FC address (port_id), and the FC4 roles that are
  1542. * active for the port.
  1543. *
  1544. * For ports that are FCP targets (aka scsi targets), the FC transport
  1545. * maintains consistent target id bindings on behalf of the LLDD.
  1546. * A consistent target id binding is an assignment of a target id to
  1547. * a remote port identifier, which persists while the scsi host is
  1548. * attached. The remote port can disappear, then later reappear, and
  1549. * it's target id assignment remains the same. This allows for shifts
  1550. * in FC addressing (if binding by wwpn or wwnn) with no apparent
  1551. * changes to the scsi subsystem which is based on scsi host number and
  1552. * target id values. Bindings are only valid during the attachment of
  1553. * the scsi host. If the host detaches, then later re-attaches, target
  1554. * id bindings may change.
  1555. *
  1556. * This routine is responsible for returning a remote port structure.
  1557. * The routine will search the list of remote ports it maintains
  1558. * internally on behalf of consistent target id mappings. If found, the
  1559. * remote port structure will be reused. Otherwise, a new remote port
  1560. * structure will be allocated.
  1561. *
  1562. * Whenever a remote port is allocated, a new fc_remote_port class
  1563. * device is created.
  1564. *
  1565. * Should not be called from interrupt context.
  1566. *
  1567. * Notes:
  1568. * This routine assumes no locks are held on entry.
  1569. **/
  1570. struct fc_rport *
  1571. fc_remote_port_add(struct Scsi_Host *shost, int channel,
  1572. struct fc_rport_identifiers *ids)
  1573. {
  1574. struct fc_internal *fci = to_fc_internal(shost->transportt);
  1575. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1576. struct fc_rport *rport;
  1577. unsigned long flags;
  1578. int match = 0;
  1579. /* ensure any stgt delete functions are done */
  1580. fc_flush_work(shost);
  1581. /*
  1582. * Search the list of "active" rports, for an rport that has been
  1583. * deleted, but we've held off the real delete while the target
  1584. * is in a "blocked" state.
  1585. */
  1586. spin_lock_irqsave(shost->host_lock, flags);
  1587. list_for_each_entry(rport, &fc_host->rports, peers) {
  1588. if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
  1589. (rport->channel == channel)) {
  1590. switch (fc_host->tgtid_bind_type) {
  1591. case FC_TGTID_BIND_BY_WWPN:
  1592. case FC_TGTID_BIND_NONE:
  1593. if (rport->port_name == ids->port_name)
  1594. match = 1;
  1595. break;
  1596. case FC_TGTID_BIND_BY_WWNN:
  1597. if (rport->node_name == ids->node_name)
  1598. match = 1;
  1599. break;
  1600. case FC_TGTID_BIND_BY_ID:
  1601. if (rport->port_id == ids->port_id)
  1602. match = 1;
  1603. break;
  1604. }
  1605. if (match) {
  1606. struct work_struct *work =
  1607. &rport->dev_loss_work;
  1608. memcpy(&rport->node_name, &ids->node_name,
  1609. sizeof(rport->node_name));
  1610. memcpy(&rport->port_name, &ids->port_name,
  1611. sizeof(rport->port_name));
  1612. rport->port_id = ids->port_id;
  1613. rport->port_state = FC_PORTSTATE_ONLINE;
  1614. rport->roles = ids->roles;
  1615. spin_unlock_irqrestore(shost->host_lock, flags);
  1616. if (fci->f->dd_fcrport_size)
  1617. memset(rport->dd_data, 0,
  1618. fci->f->dd_fcrport_size);
  1619. /*
  1620. * If we were blocked, we were a target.
  1621. * If no longer a target, we leave the timer
  1622. * running in case the port changes roles
  1623. * prior to the timer expiring. If the timer
  1624. * fires, the target will be torn down.
  1625. */
  1626. if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET))
  1627. return rport;
  1628. /* restart the target */
  1629. /*
  1630. * Stop the target timer first. Take no action
  1631. * on the del_timer failure as the state
  1632. * machine state change will validate the
  1633. * transaction.
  1634. */
  1635. if (!cancel_delayed_work(work))
  1636. fc_flush_devloss(shost);
  1637. spin_lock_irqsave(shost->host_lock, flags);
  1638. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  1639. /* initiate a scan of the target */
  1640. rport->flags |= FC_RPORT_SCAN_PENDING;
  1641. scsi_queue_work(shost, &rport->scan_work);
  1642. spin_unlock_irqrestore(shost->host_lock, flags);
  1643. scsi_target_unblock(&rport->dev);
  1644. return rport;
  1645. }
  1646. }
  1647. }
  1648. /* Search the bindings array */
  1649. if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
  1650. /* search for a matching consistent binding */
  1651. list_for_each_entry(rport, &fc_host->rport_bindings,
  1652. peers) {
  1653. if (rport->channel != channel)
  1654. continue;
  1655. switch (fc_host->tgtid_bind_type) {
  1656. case FC_TGTID_BIND_BY_WWPN:
  1657. if (rport->port_name == ids->port_name)
  1658. match = 1;
  1659. break;
  1660. case FC_TGTID_BIND_BY_WWNN:
  1661. if (rport->node_name == ids->node_name)
  1662. match = 1;
  1663. break;
  1664. case FC_TGTID_BIND_BY_ID:
  1665. if (rport->port_id == ids->port_id)
  1666. match = 1;
  1667. break;
  1668. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  1669. break;
  1670. }
  1671. if (match) {
  1672. list_move_tail(&rport->peers, &fc_host->rports);
  1673. break;
  1674. }
  1675. }
  1676. if (match) {
  1677. memcpy(&rport->node_name, &ids->node_name,
  1678. sizeof(rport->node_name));
  1679. memcpy(&rport->port_name, &ids->port_name,
  1680. sizeof(rport->port_name));
  1681. rport->port_id = ids->port_id;
  1682. rport->roles = ids->roles;
  1683. rport->port_state = FC_PORTSTATE_ONLINE;
  1684. if (fci->f->dd_fcrport_size)
  1685. memset(rport->dd_data, 0,
  1686. fci->f->dd_fcrport_size);
  1687. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
  1688. /* initiate a scan of the target */
  1689. rport->flags |= FC_RPORT_SCAN_PENDING;
  1690. scsi_queue_work(shost, &rport->scan_work);
  1691. spin_unlock_irqrestore(shost->host_lock, flags);
  1692. scsi_target_unblock(&rport->dev);
  1693. } else
  1694. spin_unlock_irqrestore(shost->host_lock, flags);
  1695. return rport;
  1696. }
  1697. }
  1698. spin_unlock_irqrestore(shost->host_lock, flags);
  1699. /* No consistent binding found - create new remote port entry */
  1700. rport = fc_rport_create(shost, channel, ids);
  1701. return rport;
  1702. }
  1703. EXPORT_SYMBOL(fc_remote_port_add);
  1704. /**
  1705. * fc_remote_port_delete - notifies the fc transport that a remote
  1706. * port is no longer in existence.
  1707. * @rport: The remote port that no longer exists
  1708. *
  1709. * The LLDD calls this routine to notify the transport that a remote
  1710. * port is no longer part of the topology. Note: Although a port
  1711. * may no longer be part of the topology, it may persist in the remote
  1712. * ports displayed by the fc_host. We do this under 2 conditions:
  1713. * - If the port was a scsi target, we delay its deletion by "blocking" it.
  1714. * This allows the port to temporarily disappear, then reappear without
  1715. * disrupting the SCSI device tree attached to it. During the "blocked"
  1716. * period the port will still exist.
  1717. * - If the port was a scsi target and disappears for longer than we
  1718. * expect, we'll delete the port and the tear down the SCSI device tree
  1719. * attached to it. However, we want to semi-persist the target id assigned
  1720. * to that port if it eventually does exist. The port structure will
  1721. * remain (although with minimal information) so that the target id
  1722. * bindings remails.
  1723. *
  1724. * If the remote port is not an FCP Target, it will be fully torn down
  1725. * and deallocated, including the fc_remote_port class device.
  1726. *
  1727. * If the remote port is an FCP Target, the port will be placed in a
  1728. * temporary blocked state. From the LLDD's perspective, the rport no
  1729. * longer exists. From the SCSI midlayer's perspective, the SCSI target
  1730. * exists, but all sdevs on it are blocked from further I/O. The following
  1731. * is then expected:
  1732. * If the remote port does not return (signaled by a LLDD call to
  1733. * fc_remote_port_add()) within the dev_loss_tmo timeout, then the
  1734. * scsi target is removed - killing all outstanding i/o and removing the
  1735. * scsi devices attached ot it. The port structure will be marked Not
  1736. * Present and be partially cleared, leaving only enough information to
  1737. * recognize the remote port relative to the scsi target id binding if
  1738. * it later appears. The port will remain as long as there is a valid
  1739. * binding (e.g. until the user changes the binding type or unloads the
  1740. * scsi host with the binding).
  1741. *
  1742. * If the remote port returns within the dev_loss_tmo value (and matches
  1743. * according to the target id binding type), the port structure will be
  1744. * reused. If it is no longer a SCSI target, the target will be torn
  1745. * down. If it continues to be a SCSI target, then the target will be
  1746. * unblocked (allowing i/o to be resumed), and a scan will be activated
  1747. * to ensure that all luns are detected.
  1748. *
  1749. * Called from normal process context only - cannot be called from interrupt.
  1750. *
  1751. * Notes:
  1752. * This routine assumes no locks are held on entry.
  1753. **/
  1754. void
  1755. fc_remote_port_delete(struct fc_rport *rport)
  1756. {
  1757. struct Scsi_Host *shost = rport_to_shost(rport);
  1758. int timeout = rport->dev_loss_tmo;
  1759. unsigned long flags;
  1760. /*
  1761. * No need to flush the fc_host work_q's, as all adds are synchronous.
  1762. *
  1763. * We do need to reclaim the rport scan work element, so eventually
  1764. * (in fc_rport_final_delete()) we'll flush the scsi host work_q if
  1765. * there's still a scan pending.
  1766. */
  1767. spin_lock_irqsave(shost->host_lock, flags);
  1768. /* If no scsi target id mapping, delete it */
  1769. if (rport->scsi_target_id == -1) {
  1770. list_del(&rport->peers);
  1771. rport->port_state = FC_PORTSTATE_DELETED;
  1772. fc_queue_work(shost, &rport->rport_delete_work);
  1773. spin_unlock_irqrestore(shost->host_lock, flags);
  1774. return;
  1775. }
  1776. rport->port_state = FC_PORTSTATE_BLOCKED;
  1777. rport->flags |= FC_RPORT_DEVLOSS_PENDING;
  1778. spin_unlock_irqrestore(shost->host_lock, flags);
  1779. scsi_target_block(&rport->dev);
  1780. /* cap the length the devices can be blocked until they are deleted */
  1781. fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ);
  1782. }
  1783. EXPORT_SYMBOL(fc_remote_port_delete);
  1784. /**
  1785. * fc_remote_port_rolechg - notifies the fc transport that the roles
  1786. * on a remote may have changed.
  1787. * @rport: The remote port that changed.
  1788. *
  1789. * The LLDD calls this routine to notify the transport that the roles
  1790. * on a remote port may have changed. The largest effect of this is
  1791. * if a port now becomes a FCP Target, it must be allocated a
  1792. * scsi target id. If the port is no longer a FCP target, any
  1793. * scsi target id value assigned to it will persist in case the
  1794. * role changes back to include FCP Target. No changes in the scsi
  1795. * midlayer will be invoked if the role changes (in the expectation
  1796. * that the role will be resumed. If it doesn't normal error processing
  1797. * will take place).
  1798. *
  1799. * Should not be called from interrupt context.
  1800. *
  1801. * Notes:
  1802. * This routine assumes no locks are held on entry.
  1803. **/
  1804. void
  1805. fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
  1806. {
  1807. struct Scsi_Host *shost = rport_to_shost(rport);
  1808. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1809. unsigned long flags;
  1810. int create = 0;
  1811. spin_lock_irqsave(shost->host_lock, flags);
  1812. if (roles & FC_RPORT_ROLE_FCP_TARGET) {
  1813. if (rport->scsi_target_id == -1) {
  1814. rport->scsi_target_id = fc_host->next_target_id++;
  1815. create = 1;
  1816. } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET))
  1817. create = 1;
  1818. }
  1819. rport->roles = roles;
  1820. spin_unlock_irqrestore(shost->host_lock, flags);
  1821. if (create) {
  1822. /*
  1823. * There may have been a delete timer running on the
  1824. * port. Ensure that it is cancelled as we now know
  1825. * the port is an FCP Target.
  1826. * Note: we know the rport is exists and in an online
  1827. * state as the LLDD would not have had an rport
  1828. * reference to pass us.
  1829. *
  1830. * Take no action on the del_timer failure as the state
  1831. * machine state change will validate the
  1832. * transaction.
  1833. */
  1834. if (!cancel_delayed_work(&rport->dev_loss_work))
  1835. fc_flush_devloss(shost);
  1836. spin_lock_irqsave(shost->host_lock, flags);
  1837. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  1838. spin_unlock_irqrestore(shost->host_lock, flags);
  1839. /* ensure any stgt delete functions are done */
  1840. fc_flush_work(shost);
  1841. /* initiate a scan of the target */
  1842. spin_lock_irqsave(shost->host_lock, flags);
  1843. rport->flags |= FC_RPORT_SCAN_PENDING;
  1844. scsi_queue_work(shost, &rport->scan_work);
  1845. spin_unlock_irqrestore(shost->host_lock, flags);
  1846. scsi_target_unblock(&rport->dev);
  1847. }
  1848. }
  1849. EXPORT_SYMBOL(fc_remote_port_rolechg);
  1850. /**
  1851. * fc_timeout_deleted_rport - Timeout handler for a deleted remote port that
  1852. * was a SCSI target (thus was blocked), and failed
  1853. * to return in the alloted time.
  1854. *
  1855. * @data: rport target that failed to reappear in the alloted time.
  1856. **/
  1857. static void
  1858. fc_timeout_deleted_rport(void *data)
  1859. {
  1860. struct fc_rport *rport = (struct fc_rport *)data;
  1861. struct Scsi_Host *shost = rport_to_shost(rport);
  1862. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1863. unsigned long flags;
  1864. spin_lock_irqsave(shost->host_lock, flags);
  1865. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  1866. /*
  1867. * If the port is ONLINE, then it came back. Validate it's still an
  1868. * FCP target. If not, tear down the scsi_target on it.
  1869. */
  1870. if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
  1871. !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  1872. dev_printk(KERN_ERR, &rport->dev,
  1873. "blocked FC remote port time out: no longer"
  1874. " a FCP target, removing starget\n");
  1875. spin_unlock_irqrestore(shost->host_lock, flags);
  1876. scsi_target_unblock(&rport->dev);
  1877. fc_queue_work(shost, &rport->stgt_delete_work);
  1878. return;
  1879. }
  1880. if (rport->port_state != FC_PORTSTATE_BLOCKED) {
  1881. spin_unlock_irqrestore(shost->host_lock, flags);
  1882. dev_printk(KERN_ERR, &rport->dev,
  1883. "blocked FC remote port time out: leaving target alone\n");
  1884. return;
  1885. }
  1886. if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) {
  1887. list_del(&rport->peers);
  1888. rport->port_state = FC_PORTSTATE_DELETED;
  1889. dev_printk(KERN_ERR, &rport->dev,
  1890. "blocked FC remote port time out: removing target\n");
  1891. fc_queue_work(shost, &rport->rport_delete_work);
  1892. spin_unlock_irqrestore(shost->host_lock, flags);
  1893. return;
  1894. }
  1895. dev_printk(KERN_ERR, &rport->dev,
  1896. "blocked FC remote port time out: removing target and "
  1897. "saving binding\n");
  1898. list_move_tail(&rport->peers, &fc_host->rport_bindings);
  1899. /*
  1900. * Note: We do not remove or clear the hostdata area. This allows
  1901. * host-specific target data to persist along with the
  1902. * scsi_target_id. It's up to the host to manage it's hostdata area.
  1903. */
  1904. /*
  1905. * Reinitialize port attributes that may change if the port comes back.
  1906. */
  1907. rport->maxframe_size = -1;
  1908. rport->supported_classes = FC_COS_UNSPECIFIED;
  1909. rport->roles = FC_RPORT_ROLE_UNKNOWN;
  1910. rport->port_state = FC_PORTSTATE_NOTPRESENT;
  1911. /* remove the identifiers that aren't used in the consisting binding */
  1912. switch (fc_host->tgtid_bind_type) {
  1913. case FC_TGTID_BIND_BY_WWPN:
  1914. rport->node_name = -1;
  1915. rport->port_id = -1;
  1916. break;
  1917. case FC_TGTID_BIND_BY_WWNN:
  1918. rport->port_name = -1;
  1919. rport->port_id = -1;
  1920. break;
  1921. case FC_TGTID_BIND_BY_ID:
  1922. rport->node_name = -1;
  1923. rport->port_name = -1;
  1924. break;
  1925. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  1926. break;
  1927. }
  1928. /*
  1929. * As this only occurs if the remote port (scsi target)
  1930. * went away and didn't come back - we'll remove
  1931. * all attached scsi devices.
  1932. */
  1933. spin_unlock_irqrestore(shost->host_lock, flags);
  1934. scsi_target_unblock(&rport->dev);
  1935. fc_queue_work(shost, &rport->stgt_delete_work);
  1936. }
  1937. /**
  1938. * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
  1939. *
  1940. * @data: remote port to be scanned.
  1941. **/
  1942. static void
  1943. fc_scsi_scan_rport(void *data)
  1944. {
  1945. struct fc_rport *rport = (struct fc_rport *)data;
  1946. struct Scsi_Host *shost = rport_to_shost(rport);
  1947. unsigned long flags;
  1948. if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
  1949. (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  1950. scsi_scan_target(&rport->dev, rport->channel,
  1951. rport->scsi_target_id, SCAN_WILD_CARD, 1);
  1952. }
  1953. spin_lock_irqsave(shost->host_lock, flags);
  1954. rport->flags &= ~FC_RPORT_SCAN_PENDING;
  1955. spin_unlock_irqrestore(shost->host_lock, flags);
  1956. }
  1957. MODULE_AUTHOR("Martin Hicks");
  1958. MODULE_DESCRIPTION("FC Transport Attributes");
  1959. MODULE_LICENSE("GPL");
  1960. module_init(fc_transport_init);
  1961. module_exit(fc_transport_exit);