scsi_transport_fc.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  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 <scsi/scsi_device.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_transport.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "scsi_priv.h"
  34. #define FC_PRINTK(x, l, f, a...) printk(l "scsi(%d:%d:%d:%d): " f, (x)->host->host_no, (x)->channel, (x)->id, (x)->lun , ##a)
  35. /*
  36. * Redefine so that we can have same named attributes in the
  37. * sdev/starget/host objects.
  38. */
  39. #define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
  40. struct class_device_attribute class_device_attr_##_prefix##_##_name = \
  41. __ATTR(_name,_mode,_show,_store)
  42. #define fc_enum_name_search(title, table_type, table) \
  43. static const char *get_fc_##title##_name(enum table_type table_key) \
  44. { \
  45. int i; \
  46. char *name = NULL; \
  47. \
  48. for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
  49. if (table[i].value == table_key) { \
  50. name = table[i].name; \
  51. break; \
  52. } \
  53. } \
  54. return name; \
  55. }
  56. #define fc_enum_name_match(title, table_type, table) \
  57. static int get_fc_##title##_match(const char *table_key, \
  58. enum table_type *value) \
  59. { \
  60. int i; \
  61. \
  62. for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
  63. if (strncmp(table_key, table[i].name, \
  64. table[i].matchlen) == 0) { \
  65. *value = table[i].value; \
  66. return 0; /* success */ \
  67. } \
  68. } \
  69. return 1; /* failure */ \
  70. }
  71. /* Convert fc_port_type values to ascii string name */
  72. static struct {
  73. enum fc_port_type value;
  74. char *name;
  75. } fc_port_type_names[] = {
  76. { FC_PORTTYPE_UNKNOWN, "Unknown" },
  77. { FC_PORTTYPE_OTHER, "Other" },
  78. { FC_PORTTYPE_NOTPRESENT, "Not Present" },
  79. { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
  80. { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
  81. { FC_PORTTYPE_LPORT, "LPort (private loop)" },
  82. { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
  83. };
  84. fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
  85. #define FC_PORTTYPE_MAX_NAMELEN 50
  86. /* Convert fc_port_state values to ascii string name */
  87. static struct {
  88. enum fc_port_state value;
  89. char *name;
  90. } fc_port_state_names[] = {
  91. { FC_PORTSTATE_UNKNOWN, "Unknown" },
  92. { FC_PORTSTATE_NOTPRESENT, "Not Present" },
  93. { FC_PORTSTATE_ONLINE, "Online" },
  94. { FC_PORTSTATE_OFFLINE, "Offline" },
  95. { FC_PORTSTATE_BLOCKED, "Blocked" },
  96. { FC_PORTSTATE_BYPASSED, "Bypassed" },
  97. { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
  98. { FC_PORTSTATE_LINKDOWN, "Linkdown" },
  99. { FC_PORTSTATE_ERROR, "Error" },
  100. { FC_PORTSTATE_LOOPBACK, "Loopback" },
  101. };
  102. fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
  103. #define FC_PORTSTATE_MAX_NAMELEN 20
  104. /* Convert fc_tgtid_binding_type values to ascii string name */
  105. static struct {
  106. enum fc_tgtid_binding_type value;
  107. char *name;
  108. int matchlen;
  109. } fc_tgtid_binding_type_names[] = {
  110. { FC_TGTID_BIND_NONE, "none", 4 },
  111. { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
  112. { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
  113. { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
  114. };
  115. fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
  116. fc_tgtid_binding_type_names)
  117. fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
  118. fc_tgtid_binding_type_names)
  119. #define FC_BINDTYPE_MAX_NAMELEN 30
  120. #define fc_bitfield_name_search(title, table) \
  121. static ssize_t \
  122. get_fc_##title##_names(u32 table_key, char *buf) \
  123. { \
  124. char *prefix = ""; \
  125. ssize_t len = 0; \
  126. int i; \
  127. \
  128. for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
  129. if (table[i].value & table_key) { \
  130. len += sprintf(buf + len, "%s%s", \
  131. prefix, table[i].name); \
  132. prefix = ", "; \
  133. } \
  134. } \
  135. len += sprintf(buf + len, "\n"); \
  136. return len; \
  137. }
  138. /* Convert FC_COS bit values to ascii string name */
  139. static struct {
  140. u32 value;
  141. char *name;
  142. } fc_cos_names[] = {
  143. { FC_COS_CLASS1, "Class 1" },
  144. { FC_COS_CLASS2, "Class 2" },
  145. { FC_COS_CLASS3, "Class 3" },
  146. { FC_COS_CLASS4, "Class 4" },
  147. { FC_COS_CLASS6, "Class 6" },
  148. };
  149. fc_bitfield_name_search(cos, fc_cos_names)
  150. /* Convert FC_PORTSPEED bit values to ascii string name */
  151. static struct {
  152. u32 value;
  153. char *name;
  154. } fc_port_speed_names[] = {
  155. { FC_PORTSPEED_1GBIT, "1 Gbit" },
  156. { FC_PORTSPEED_2GBIT, "2 Gbit" },
  157. { FC_PORTSPEED_4GBIT, "4 Gbit" },
  158. { FC_PORTSPEED_10GBIT, "10 Gbit" },
  159. { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
  160. };
  161. fc_bitfield_name_search(port_speed, fc_port_speed_names)
  162. static int
  163. show_fc_fc4s (char *buf, u8 *fc4_list)
  164. {
  165. int i, len=0;
  166. for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
  167. len += sprintf(buf + len , "0x%02x ", *fc4_list);
  168. len += sprintf(buf + len, "\n");
  169. return len;
  170. }
  171. /* Convert FC_RPORT_ROLE bit values to ascii string name */
  172. static struct {
  173. u32 value;
  174. char *name;
  175. } fc_remote_port_role_names[] = {
  176. { FC_RPORT_ROLE_FCP_TARGET, "FCP Target" },
  177. { FC_RPORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
  178. { FC_RPORT_ROLE_IP_PORT, "IP Port" },
  179. };
  180. fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
  181. /*
  182. * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
  183. */
  184. #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
  185. #define FC_WELLKNOWN_ROLE_MASK 0x00000f
  186. #define FC_FPORT_PORTID 0x00000e
  187. #define FC_FABCTLR_PORTID 0x00000d
  188. #define FC_DIRSRVR_PORTID 0x00000c
  189. #define FC_TIMESRVR_PORTID 0x00000b
  190. #define FC_MGMTSRVR_PORTID 0x00000a
  191. static void fc_timeout_blocked_rport(void *data);
  192. static void fc_scsi_scan_rport(void *data);
  193. static void fc_rport_terminate(struct fc_rport *rport);
  194. /*
  195. * Attribute counts pre object type...
  196. * Increase these values if you add attributes
  197. */
  198. #define FC_STARGET_NUM_ATTRS 3
  199. #define FC_RPORT_NUM_ATTRS 9
  200. #define FC_HOST_NUM_ATTRS 15
  201. struct fc_internal {
  202. struct scsi_transport_template t;
  203. struct fc_function_template *f;
  204. /*
  205. * For attributes : each object has :
  206. * An array of the actual attributes structures
  207. * An array of null-terminated pointers to the attribute
  208. * structures - used for mid-layer interaction.
  209. *
  210. * The attribute containers for the starget and host are are
  211. * part of the midlayer. As the remote port is specific to the
  212. * fc transport, we must provide the attribute container.
  213. */
  214. struct class_device_attribute private_starget_attrs[
  215. FC_STARGET_NUM_ATTRS];
  216. struct class_device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
  217. struct class_device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
  218. struct class_device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
  219. struct transport_container rport_attr_cont;
  220. struct class_device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
  221. struct class_device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
  222. };
  223. #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
  224. static int fc_target_setup(struct transport_container *tc, struct device *dev,
  225. struct class_device *cdev)
  226. {
  227. struct scsi_target *starget = to_scsi_target(dev);
  228. struct fc_rport *rport = starget_to_rport(starget);
  229. /*
  230. * if parent is remote port, use values from remote port.
  231. * Otherwise, this host uses the fc_transport, but not the
  232. * remote port interface. As such, initialize to known non-values.
  233. */
  234. if (rport) {
  235. fc_starget_node_name(starget) = rport->node_name;
  236. fc_starget_port_name(starget) = rport->port_name;
  237. fc_starget_port_id(starget) = rport->port_id;
  238. } else {
  239. fc_starget_node_name(starget) = -1;
  240. fc_starget_port_name(starget) = -1;
  241. fc_starget_port_id(starget) = -1;
  242. }
  243. return 0;
  244. }
  245. static DECLARE_TRANSPORT_CLASS(fc_transport_class,
  246. "fc_transport",
  247. fc_target_setup,
  248. NULL,
  249. NULL);
  250. static int fc_host_setup(struct transport_container *tc, struct device *dev,
  251. struct class_device *cdev)
  252. {
  253. struct Scsi_Host *shost = dev_to_shost(dev);
  254. /*
  255. * Set default values easily detected by the midlayer as
  256. * failure cases. The scsi lldd is responsible for initializing
  257. * all transport attributes to valid values per host.
  258. */
  259. fc_host_node_name(shost) = -1;
  260. fc_host_port_name(shost) = -1;
  261. fc_host_supported_classes(shost) = FC_COS_UNSPECIFIED;
  262. memset(fc_host_supported_fc4s(shost), 0,
  263. sizeof(fc_host_supported_fc4s(shost)));
  264. memset(fc_host_symbolic_name(shost), 0,
  265. sizeof(fc_host_symbolic_name(shost)));
  266. fc_host_supported_speeds(shost) = FC_PORTSPEED_UNKNOWN;
  267. fc_host_maxframe_size(shost) = -1;
  268. memset(fc_host_serial_number(shost), 0,
  269. sizeof(fc_host_serial_number(shost)));
  270. fc_host_port_id(shost) = -1;
  271. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  272. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  273. memset(fc_host_active_fc4s(shost), 0,
  274. sizeof(fc_host_active_fc4s(shost)));
  275. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  276. fc_host_fabric_name(shost) = -1;
  277. fc_host_tgtid_bind_type(shost) = FC_TGTID_BIND_BY_WWPN;
  278. INIT_LIST_HEAD(&fc_host_rports(shost));
  279. INIT_LIST_HEAD(&fc_host_rport_bindings(shost));
  280. fc_host_next_rport_number(shost) = 0;
  281. fc_host_next_target_id(shost) = 0;
  282. return 0;
  283. }
  284. static DECLARE_TRANSPORT_CLASS(fc_host_class,
  285. "fc_host",
  286. fc_host_setup,
  287. NULL,
  288. NULL);
  289. /*
  290. * Setup and Remove actions for remote ports are handled
  291. * in the service functions below.
  292. */
  293. static DECLARE_TRANSPORT_CLASS(fc_rport_class,
  294. "fc_remote_ports",
  295. NULL,
  296. NULL,
  297. NULL);
  298. /*
  299. * Module Parameters
  300. */
  301. /*
  302. * dev_loss_tmo: the default number of seconds that the FC transport
  303. * should insulate the loss of a remote port.
  304. * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
  305. */
  306. static unsigned int fc_dev_loss_tmo = SCSI_DEVICE_BLOCK_MAX_TIMEOUT;
  307. module_param_named(dev_loss_tmo, fc_dev_loss_tmo, int, S_IRUGO|S_IWUSR);
  308. MODULE_PARM_DESC(dev_loss_tmo,
  309. "Maximum number of seconds that the FC transport should"
  310. " insulate the loss of a remote port. Once this value is"
  311. " exceeded, the scsi target is removed. Value should be"
  312. " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");
  313. static __init int fc_transport_init(void)
  314. {
  315. int error = transport_class_register(&fc_host_class);
  316. if (error)
  317. return error;
  318. error = transport_class_register(&fc_rport_class);
  319. if (error)
  320. return error;
  321. return transport_class_register(&fc_transport_class);
  322. }
  323. static void __exit fc_transport_exit(void)
  324. {
  325. transport_class_unregister(&fc_transport_class);
  326. transport_class_unregister(&fc_rport_class);
  327. transport_class_unregister(&fc_host_class);
  328. }
  329. /*
  330. * FC Remote Port Attribute Management
  331. */
  332. #define fc_rport_show_function(field, format_string, sz, cast) \
  333. static ssize_t \
  334. show_fc_rport_##field (struct class_device *cdev, char *buf) \
  335. { \
  336. struct fc_rport *rport = transport_class_to_rport(cdev); \
  337. struct Scsi_Host *shost = rport_to_shost(rport); \
  338. struct fc_internal *i = to_fc_internal(shost->transportt); \
  339. if (i->f->get_rport_##field) \
  340. i->f->get_rport_##field(rport); \
  341. return snprintf(buf, sz, format_string, cast rport->field); \
  342. }
  343. #define fc_rport_store_function(field) \
  344. static ssize_t \
  345. store_fc_rport_##field(struct class_device *cdev, const char *buf, \
  346. size_t count) \
  347. { \
  348. int val; \
  349. struct fc_rport *rport = transport_class_to_rport(cdev); \
  350. struct Scsi_Host *shost = rport_to_shost(rport); \
  351. struct fc_internal *i = to_fc_internal(shost->transportt); \
  352. val = simple_strtoul(buf, NULL, 0); \
  353. i->f->set_rport_##field(rport, val); \
  354. return count; \
  355. }
  356. #define fc_rport_rd_attr(field, format_string, sz) \
  357. fc_rport_show_function(field, format_string, sz, ) \
  358. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  359. show_fc_rport_##field, NULL)
  360. #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
  361. fc_rport_show_function(field, format_string, sz, (cast)) \
  362. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  363. show_fc_rport_##field, NULL)
  364. #define fc_rport_rw_attr(field, format_string, sz) \
  365. fc_rport_show_function(field, format_string, sz, ) \
  366. fc_rport_store_function(field) \
  367. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
  368. show_fc_rport_##field, \
  369. store_fc_rport_##field)
  370. #define fc_private_rport_show_function(field, format_string, sz, cast) \
  371. static ssize_t \
  372. show_fc_rport_##field (struct class_device *cdev, char *buf) \
  373. { \
  374. struct fc_rport *rport = transport_class_to_rport(cdev); \
  375. return snprintf(buf, sz, format_string, cast rport->field); \
  376. }
  377. #define fc_private_rport_rd_attr(field, format_string, sz) \
  378. fc_private_rport_show_function(field, format_string, sz, ) \
  379. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  380. show_fc_rport_##field, NULL)
  381. #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
  382. fc_private_rport_show_function(field, format_string, sz, (cast)) \
  383. static FC_CLASS_DEVICE_ATTR(rport, field, S_IRUGO, \
  384. show_fc_rport_##field, NULL)
  385. #define fc_private_rport_rd_enum_attr(title, maxlen) \
  386. static ssize_t \
  387. show_fc_rport_##title (struct class_device *cdev, char *buf) \
  388. { \
  389. struct fc_rport *rport = transport_class_to_rport(cdev); \
  390. const char *name; \
  391. name = get_fc_##title##_name(rport->title); \
  392. if (!name) \
  393. return -EINVAL; \
  394. return snprintf(buf, maxlen, "%s\n", name); \
  395. } \
  396. static FC_CLASS_DEVICE_ATTR(rport, title, S_IRUGO, \
  397. show_fc_rport_##title, NULL)
  398. #define SETUP_RPORT_ATTRIBUTE_RD(field) \
  399. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  400. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  401. i->private_rport_attrs[count].store = NULL; \
  402. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  403. if (i->f->show_rport_##field) \
  404. count++
  405. #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
  406. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  407. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  408. i->private_rport_attrs[count].store = NULL; \
  409. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  410. count++
  411. #define SETUP_RPORT_ATTRIBUTE_RW(field) \
  412. i->private_rport_attrs[count] = class_device_attr_rport_##field; \
  413. if (!i->f->set_rport_##field) { \
  414. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  415. i->private_rport_attrs[count].store = NULL; \
  416. } \
  417. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  418. if (i->f->show_rport_##field) \
  419. count++
  420. /* The FC Transport Remote Port Attributes: */
  421. /* Fixed Remote Port Attributes */
  422. fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
  423. static ssize_t
  424. show_fc_rport_supported_classes (struct class_device *cdev, char *buf)
  425. {
  426. struct fc_rport *rport = transport_class_to_rport(cdev);
  427. if (rport->supported_classes == FC_COS_UNSPECIFIED)
  428. return snprintf(buf, 20, "unspecified\n");
  429. return get_fc_cos_names(rport->supported_classes, buf);
  430. }
  431. static FC_CLASS_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
  432. show_fc_rport_supported_classes, NULL);
  433. /* Dynamic Remote Port Attributes */
  434. fc_rport_rw_attr(dev_loss_tmo, "%d\n", 20);
  435. /* Private Remote Port Attributes */
  436. fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  437. fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  438. fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
  439. static ssize_t
  440. show_fc_rport_roles (struct class_device *cdev, char *buf)
  441. {
  442. struct fc_rport *rport = transport_class_to_rport(cdev);
  443. /* identify any roles that are port_id specific */
  444. if ((rport->port_id != -1) &&
  445. (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
  446. FC_WELLKNOWN_PORTID_MASK) {
  447. switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
  448. case FC_FPORT_PORTID:
  449. return snprintf(buf, 30, "Fabric Port\n");
  450. case FC_FABCTLR_PORTID:
  451. return snprintf(buf, 30, "Fabric Controller\n");
  452. case FC_DIRSRVR_PORTID:
  453. return snprintf(buf, 30, "Directory Server\n");
  454. case FC_TIMESRVR_PORTID:
  455. return snprintf(buf, 30, "Time Server\n");
  456. case FC_MGMTSRVR_PORTID:
  457. return snprintf(buf, 30, "Management Server\n");
  458. default:
  459. return snprintf(buf, 30, "Unknown Fabric Entity\n");
  460. }
  461. } else {
  462. if (rport->roles == FC_RPORT_ROLE_UNKNOWN)
  463. return snprintf(buf, 20, "unknown\n");
  464. return get_fc_remote_port_roles_names(rport->roles, buf);
  465. }
  466. }
  467. static FC_CLASS_DEVICE_ATTR(rport, roles, S_IRUGO,
  468. show_fc_rport_roles, NULL);
  469. fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  470. fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
  471. /*
  472. * FC SCSI Target Attribute Management
  473. */
  474. /*
  475. * Note: in the target show function we recognize when the remote
  476. * port is in the heirarchy and do not allow the driver to get
  477. * involved in sysfs functions. The driver only gets involved if
  478. * it's the "old" style that doesn't use rports.
  479. */
  480. #define fc_starget_show_function(field, format_string, sz, cast) \
  481. static ssize_t \
  482. show_fc_starget_##field (struct class_device *cdev, char *buf) \
  483. { \
  484. struct scsi_target *starget = transport_class_to_starget(cdev); \
  485. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
  486. struct fc_internal *i = to_fc_internal(shost->transportt); \
  487. struct fc_rport *rport = starget_to_rport(starget); \
  488. if (rport) \
  489. fc_starget_##field(starget) = rport->field; \
  490. else if (i->f->get_starget_##field) \
  491. i->f->get_starget_##field(starget); \
  492. return snprintf(buf, sz, format_string, \
  493. cast fc_starget_##field(starget)); \
  494. }
  495. #define fc_starget_rd_attr(field, format_string, sz) \
  496. fc_starget_show_function(field, format_string, sz, ) \
  497. static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
  498. show_fc_starget_##field, NULL)
  499. #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
  500. fc_starget_show_function(field, format_string, sz, (cast)) \
  501. static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
  502. show_fc_starget_##field, NULL)
  503. #define SETUP_STARGET_ATTRIBUTE_RD(field) \
  504. i->private_starget_attrs[count] = class_device_attr_starget_##field; \
  505. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  506. i->private_starget_attrs[count].store = NULL; \
  507. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  508. if (i->f->show_starget_##field) \
  509. count++
  510. #define SETUP_STARGET_ATTRIBUTE_RW(field) \
  511. i->private_starget_attrs[count] = class_device_attr_starget_##field; \
  512. if (!i->f->set_starget_##field) { \
  513. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  514. i->private_starget_attrs[count].store = NULL; \
  515. } \
  516. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  517. if (i->f->show_starget_##field) \
  518. count++
  519. /* The FC Transport SCSI Target Attributes: */
  520. fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  521. fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  522. fc_starget_rd_attr(port_id, "0x%06x\n", 20);
  523. /*
  524. * Host Attribute Management
  525. */
  526. #define fc_host_show_function(field, format_string, sz, cast) \
  527. static ssize_t \
  528. show_fc_host_##field (struct class_device *cdev, char *buf) \
  529. { \
  530. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  531. struct fc_internal *i = to_fc_internal(shost->transportt); \
  532. if (i->f->get_host_##field) \
  533. i->f->get_host_##field(shost); \
  534. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  535. }
  536. #define fc_host_store_function(field) \
  537. static ssize_t \
  538. store_fc_host_##field(struct class_device *cdev, const char *buf, \
  539. size_t count) \
  540. { \
  541. int val; \
  542. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  543. struct fc_internal *i = to_fc_internal(shost->transportt); \
  544. \
  545. val = simple_strtoul(buf, NULL, 0); \
  546. i->f->set_host_##field(shost, val); \
  547. return count; \
  548. }
  549. #define fc_host_rd_attr(field, format_string, sz) \
  550. fc_host_show_function(field, format_string, sz, ) \
  551. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  552. show_fc_host_##field, NULL)
  553. #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
  554. fc_host_show_function(field, format_string, sz, (cast)) \
  555. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  556. show_fc_host_##field, NULL)
  557. #define fc_host_rw_attr(field, format_string, sz) \
  558. fc_host_show_function(field, format_string, sz, ) \
  559. fc_host_store_function(field) \
  560. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
  561. show_fc_host_##field, \
  562. store_fc_host_##field)
  563. #define fc_host_rd_enum_attr(title, maxlen) \
  564. static ssize_t \
  565. show_fc_host_##title (struct class_device *cdev, char *buf) \
  566. { \
  567. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  568. struct fc_internal *i = to_fc_internal(shost->transportt); \
  569. const char *name; \
  570. if (i->f->get_host_##title) \
  571. i->f->get_host_##title(shost); \
  572. name = get_fc_##title##_name(fc_host_##title(shost)); \
  573. if (!name) \
  574. return -EINVAL; \
  575. return snprintf(buf, maxlen, "%s\n", name); \
  576. } \
  577. static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
  578. #define SETUP_HOST_ATTRIBUTE_RD(field) \
  579. i->private_host_attrs[count] = class_device_attr_host_##field; \
  580. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  581. i->private_host_attrs[count].store = NULL; \
  582. i->host_attrs[count] = &i->private_host_attrs[count]; \
  583. if (i->f->show_host_##field) \
  584. count++
  585. #define SETUP_HOST_ATTRIBUTE_RW(field) \
  586. i->private_host_attrs[count] = class_device_attr_host_##field; \
  587. if (!i->f->set_host_##field) { \
  588. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  589. i->private_host_attrs[count].store = NULL; \
  590. } \
  591. i->host_attrs[count] = &i->private_host_attrs[count]; \
  592. if (i->f->show_host_##field) \
  593. count++
  594. #define fc_private_host_show_function(field, format_string, sz, cast) \
  595. static ssize_t \
  596. show_fc_host_##field (struct class_device *cdev, char *buf) \
  597. { \
  598. struct Scsi_Host *shost = transport_class_to_shost(cdev); \
  599. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  600. }
  601. #define fc_private_host_rd_attr(field, format_string, sz) \
  602. fc_private_host_show_function(field, format_string, sz, ) \
  603. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  604. show_fc_host_##field, NULL)
  605. #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
  606. fc_private_host_show_function(field, format_string, sz, (cast)) \
  607. static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
  608. show_fc_host_##field, NULL)
  609. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
  610. i->private_host_attrs[count] = class_device_attr_host_##field; \
  611. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  612. i->private_host_attrs[count].store = NULL; \
  613. i->host_attrs[count] = &i->private_host_attrs[count]; \
  614. count++
  615. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
  616. i->private_host_attrs[count] = class_device_attr_host_##field; \
  617. i->host_attrs[count] = &i->private_host_attrs[count]; \
  618. count++
  619. /* Fixed Host Attributes */
  620. static ssize_t
  621. show_fc_host_supported_classes (struct class_device *cdev, char *buf)
  622. {
  623. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  624. if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
  625. return snprintf(buf, 20, "unspecified\n");
  626. return get_fc_cos_names(fc_host_supported_classes(shost), buf);
  627. }
  628. static FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO,
  629. show_fc_host_supported_classes, NULL);
  630. static ssize_t
  631. show_fc_host_supported_fc4s (struct class_device *cdev, char *buf)
  632. {
  633. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  634. return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
  635. }
  636. static FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
  637. show_fc_host_supported_fc4s, NULL);
  638. static ssize_t
  639. show_fc_host_supported_speeds (struct class_device *cdev, char *buf)
  640. {
  641. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  642. if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
  643. return snprintf(buf, 20, "unknown\n");
  644. return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
  645. }
  646. static FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
  647. show_fc_host_supported_speeds, NULL);
  648. fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  649. fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  650. fc_private_host_rd_attr(symbolic_name, "%s\n", (FC_SYMBOLIC_NAME_SIZE +1));
  651. fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
  652. fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
  653. /* Dynamic Host Attributes */
  654. static ssize_t
  655. show_fc_host_active_fc4s (struct class_device *cdev, char *buf)
  656. {
  657. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  658. struct fc_internal *i = to_fc_internal(shost->transportt);
  659. if (i->f->get_host_active_fc4s)
  660. i->f->get_host_active_fc4s(shost);
  661. return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
  662. }
  663. static FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
  664. show_fc_host_active_fc4s, NULL);
  665. static ssize_t
  666. show_fc_host_speed (struct class_device *cdev, char *buf)
  667. {
  668. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  669. struct fc_internal *i = to_fc_internal(shost->transportt);
  670. if (i->f->get_host_speed)
  671. i->f->get_host_speed(shost);
  672. if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
  673. return snprintf(buf, 20, "unknown\n");
  674. return get_fc_port_speed_names(fc_host_speed(shost), buf);
  675. }
  676. static FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO,
  677. show_fc_host_speed, NULL);
  678. fc_host_rd_attr(port_id, "0x%06x\n", 20);
  679. fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
  680. fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  681. fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
  682. /* Private Host Attributes */
  683. static ssize_t
  684. show_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf)
  685. {
  686. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  687. const char *name;
  688. name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
  689. if (!name)
  690. return -EINVAL;
  691. return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
  692. }
  693. #define get_list_head_entry(pos, head, member) \
  694. pos = list_entry((head)->next, typeof(*pos), member)
  695. static ssize_t
  696. store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
  697. const char *buf, size_t count)
  698. {
  699. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  700. struct fc_rport *rport;
  701. enum fc_tgtid_binding_type val;
  702. unsigned long flags;
  703. if (get_fc_tgtid_bind_type_match(buf, &val))
  704. return -EINVAL;
  705. /* if changing bind type, purge all unused consistent bindings */
  706. if (val != fc_host_tgtid_bind_type(shost)) {
  707. spin_lock_irqsave(shost->host_lock, flags);
  708. while (!list_empty(&fc_host_rport_bindings(shost))) {
  709. get_list_head_entry(rport,
  710. &fc_host_rport_bindings(shost), peers);
  711. spin_unlock_irqrestore(shost->host_lock, flags);
  712. fc_rport_terminate(rport);
  713. spin_lock_irqsave(shost->host_lock, flags);
  714. }
  715. spin_unlock_irqrestore(shost->host_lock, flags);
  716. }
  717. fc_host_tgtid_bind_type(shost) = val;
  718. return count;
  719. }
  720. static FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
  721. show_fc_private_host_tgtid_bind_type,
  722. store_fc_private_host_tgtid_bind_type);
  723. /*
  724. * Host Statistics Management
  725. */
  726. /* Show a given an attribute in the statistics group */
  727. static ssize_t
  728. fc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset)
  729. {
  730. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  731. struct fc_internal *i = to_fc_internal(shost->transportt);
  732. struct fc_host_statistics *stats;
  733. ssize_t ret = -ENOENT;
  734. if (offset > sizeof(struct fc_host_statistics) ||
  735. offset % sizeof(u64) != 0)
  736. WARN_ON(1);
  737. if (i->f->get_fc_host_stats) {
  738. stats = (i->f->get_fc_host_stats)(shost);
  739. if (stats)
  740. ret = snprintf(buf, 20, "0x%llx\n",
  741. (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
  742. }
  743. return ret;
  744. }
  745. /* generate a read-only statistics attribute */
  746. #define fc_host_statistic(name) \
  747. static ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \
  748. { \
  749. return fc_stat_show(cd, buf, \
  750. offsetof(struct fc_host_statistics, name)); \
  751. } \
  752. static FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
  753. fc_host_statistic(seconds_since_last_reset);
  754. fc_host_statistic(tx_frames);
  755. fc_host_statistic(tx_words);
  756. fc_host_statistic(rx_frames);
  757. fc_host_statistic(rx_words);
  758. fc_host_statistic(lip_count);
  759. fc_host_statistic(nos_count);
  760. fc_host_statistic(error_frames);
  761. fc_host_statistic(dumped_frames);
  762. fc_host_statistic(link_failure_count);
  763. fc_host_statistic(loss_of_sync_count);
  764. fc_host_statistic(loss_of_signal_count);
  765. fc_host_statistic(prim_seq_protocol_err_count);
  766. fc_host_statistic(invalid_tx_word_count);
  767. fc_host_statistic(invalid_crc_count);
  768. fc_host_statistic(fcp_input_requests);
  769. fc_host_statistic(fcp_output_requests);
  770. fc_host_statistic(fcp_control_requests);
  771. fc_host_statistic(fcp_input_megabytes);
  772. fc_host_statistic(fcp_output_megabytes);
  773. static ssize_t
  774. fc_reset_statistics(struct class_device *cdev, const char *buf,
  775. size_t count)
  776. {
  777. struct Scsi_Host *shost = transport_class_to_shost(cdev);
  778. struct fc_internal *i = to_fc_internal(shost->transportt);
  779. /* ignore any data value written to the attribute */
  780. if (i->f->reset_fc_host_stats) {
  781. i->f->reset_fc_host_stats(shost);
  782. return count;
  783. }
  784. return -ENOENT;
  785. }
  786. static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
  787. fc_reset_statistics);
  788. static struct attribute *fc_statistics_attrs[] = {
  789. &class_device_attr_host_seconds_since_last_reset.attr,
  790. &class_device_attr_host_tx_frames.attr,
  791. &class_device_attr_host_tx_words.attr,
  792. &class_device_attr_host_rx_frames.attr,
  793. &class_device_attr_host_rx_words.attr,
  794. &class_device_attr_host_lip_count.attr,
  795. &class_device_attr_host_nos_count.attr,
  796. &class_device_attr_host_error_frames.attr,
  797. &class_device_attr_host_dumped_frames.attr,
  798. &class_device_attr_host_link_failure_count.attr,
  799. &class_device_attr_host_loss_of_sync_count.attr,
  800. &class_device_attr_host_loss_of_signal_count.attr,
  801. &class_device_attr_host_prim_seq_protocol_err_count.attr,
  802. &class_device_attr_host_invalid_tx_word_count.attr,
  803. &class_device_attr_host_invalid_crc_count.attr,
  804. &class_device_attr_host_fcp_input_requests.attr,
  805. &class_device_attr_host_fcp_output_requests.attr,
  806. &class_device_attr_host_fcp_control_requests.attr,
  807. &class_device_attr_host_fcp_input_megabytes.attr,
  808. &class_device_attr_host_fcp_output_megabytes.attr,
  809. &class_device_attr_host_reset_statistics.attr,
  810. NULL
  811. };
  812. static struct attribute_group fc_statistics_group = {
  813. .name = "statistics",
  814. .attrs = fc_statistics_attrs,
  815. };
  816. static int fc_host_match(struct attribute_container *cont,
  817. struct device *dev)
  818. {
  819. struct Scsi_Host *shost;
  820. struct fc_internal *i;
  821. if (!scsi_is_host_device(dev))
  822. return 0;
  823. shost = dev_to_shost(dev);
  824. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  825. != &fc_host_class.class)
  826. return 0;
  827. i = to_fc_internal(shost->transportt);
  828. return &i->t.host_attrs.ac == cont;
  829. }
  830. static int fc_target_match(struct attribute_container *cont,
  831. struct device *dev)
  832. {
  833. struct Scsi_Host *shost;
  834. struct fc_internal *i;
  835. if (!scsi_is_target_device(dev))
  836. return 0;
  837. shost = dev_to_shost(dev->parent);
  838. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  839. != &fc_host_class.class)
  840. return 0;
  841. i = to_fc_internal(shost->transportt);
  842. return &i->t.target_attrs.ac == cont;
  843. }
  844. static void fc_rport_dev_release(struct device *dev)
  845. {
  846. struct fc_rport *rport = dev_to_rport(dev);
  847. put_device(dev->parent);
  848. kfree(rport);
  849. }
  850. int scsi_is_fc_rport(const struct device *dev)
  851. {
  852. return dev->release == fc_rport_dev_release;
  853. }
  854. EXPORT_SYMBOL(scsi_is_fc_rport);
  855. static int fc_rport_match(struct attribute_container *cont,
  856. struct device *dev)
  857. {
  858. struct Scsi_Host *shost;
  859. struct fc_internal *i;
  860. if (!scsi_is_fc_rport(dev))
  861. return 0;
  862. shost = dev_to_shost(dev->parent);
  863. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  864. != &fc_host_class.class)
  865. return 0;
  866. i = to_fc_internal(shost->transportt);
  867. return &i->rport_attr_cont.ac == cont;
  868. }
  869. /*
  870. * Must be called with shost->host_lock held
  871. */
  872. static struct device *fc_target_parent(struct Scsi_Host *shost,
  873. int channel, uint id)
  874. {
  875. struct fc_rport *rport;
  876. list_for_each_entry(rport, &fc_host_rports(shost), peers)
  877. if ((rport->channel == channel) &&
  878. (rport->scsi_target_id == id))
  879. return &rport->dev;
  880. return NULL;
  881. }
  882. struct scsi_transport_template *
  883. fc_attach_transport(struct fc_function_template *ft)
  884. {
  885. struct fc_internal *i = kmalloc(sizeof(struct fc_internal),
  886. GFP_KERNEL);
  887. int count;
  888. if (unlikely(!i))
  889. return NULL;
  890. memset(i, 0, sizeof(struct fc_internal));
  891. i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
  892. i->t.target_attrs.ac.class = &fc_transport_class.class;
  893. i->t.target_attrs.ac.match = fc_target_match;
  894. i->t.target_size = sizeof(struct fc_starget_attrs);
  895. transport_container_register(&i->t.target_attrs);
  896. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  897. i->t.host_attrs.ac.class = &fc_host_class.class;
  898. i->t.host_attrs.ac.match = fc_host_match;
  899. i->t.host_size = sizeof(struct fc_host_attrs);
  900. if (ft->get_fc_host_stats)
  901. i->t.host_attrs.statistics = &fc_statistics_group;
  902. transport_container_register(&i->t.host_attrs);
  903. i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
  904. i->rport_attr_cont.ac.class = &fc_rport_class.class;
  905. i->rport_attr_cont.ac.match = fc_rport_match;
  906. transport_container_register(&i->rport_attr_cont);
  907. i->f = ft;
  908. /* Transport uses the shost workq for scsi scanning */
  909. i->t.create_work_queue = 1;
  910. i->t.target_parent = fc_target_parent;
  911. /*
  912. * Setup SCSI Target Attributes.
  913. */
  914. count = 0;
  915. SETUP_STARGET_ATTRIBUTE_RD(node_name);
  916. SETUP_STARGET_ATTRIBUTE_RD(port_name);
  917. SETUP_STARGET_ATTRIBUTE_RD(port_id);
  918. BUG_ON(count > FC_STARGET_NUM_ATTRS);
  919. i->starget_attrs[count] = NULL;
  920. /*
  921. * Setup SCSI Host Attributes.
  922. */
  923. count=0;
  924. SETUP_HOST_ATTRIBUTE_RD(node_name);
  925. SETUP_HOST_ATTRIBUTE_RD(port_name);
  926. SETUP_HOST_ATTRIBUTE_RD(supported_classes);
  927. SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
  928. SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
  929. SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
  930. SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
  931. SETUP_HOST_ATTRIBUTE_RD(serial_number);
  932. SETUP_HOST_ATTRIBUTE_RD(port_id);
  933. SETUP_HOST_ATTRIBUTE_RD(port_type);
  934. SETUP_HOST_ATTRIBUTE_RD(port_state);
  935. SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
  936. SETUP_HOST_ATTRIBUTE_RD(speed);
  937. SETUP_HOST_ATTRIBUTE_RD(fabric_name);
  938. /* Transport-managed attributes */
  939. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
  940. BUG_ON(count > FC_HOST_NUM_ATTRS);
  941. i->host_attrs[count] = NULL;
  942. /*
  943. * Setup Remote Port Attributes.
  944. */
  945. count=0;
  946. SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
  947. SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
  948. SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
  949. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
  950. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
  951. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
  952. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
  953. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
  954. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
  955. BUG_ON(count > FC_RPORT_NUM_ATTRS);
  956. i->rport_attrs[count] = NULL;
  957. return &i->t;
  958. }
  959. EXPORT_SYMBOL(fc_attach_transport);
  960. void fc_release_transport(struct scsi_transport_template *t)
  961. {
  962. struct fc_internal *i = to_fc_internal(t);
  963. transport_container_unregister(&i->t.target_attrs);
  964. transport_container_unregister(&i->t.host_attrs);
  965. transport_container_unregister(&i->rport_attr_cont);
  966. kfree(i);
  967. }
  968. EXPORT_SYMBOL(fc_release_transport);
  969. /**
  970. * fc_remove_host - called to terminate any fc_transport-related elements
  971. * for a scsi host.
  972. * @rport: remote port to be unblocked.
  973. *
  974. * This routine is expected to be called immediately preceeding the
  975. * a driver's call to scsi_remove_host().
  976. *
  977. * WARNING: A driver utilizing the fc_transport, which fails to call
  978. * this routine prior to scsi_remote_host(), will leave dangling
  979. * objects in /sys/class/fc_remote_ports. Access to any of these
  980. * objects can result in a system crash !!!
  981. *
  982. * Notes:
  983. * This routine assumes no locks are held on entry.
  984. **/
  985. void
  986. fc_remove_host(struct Scsi_Host *shost)
  987. {
  988. struct fc_rport *rport, *next_rport;
  989. /* Remove any remote ports */
  990. list_for_each_entry_safe(rport, next_rport,
  991. &fc_host_rports(shost), peers)
  992. fc_rport_terminate(rport);
  993. list_for_each_entry_safe(rport, next_rport,
  994. &fc_host_rport_bindings(shost), peers)
  995. fc_rport_terminate(rport);
  996. }
  997. EXPORT_SYMBOL(fc_remove_host);
  998. /**
  999. * fc_rport_create - allocates and creates a remote FC port.
  1000. * @shost: scsi host the remote port is connected to.
  1001. * @channel: Channel on shost port connected to.
  1002. * @ids: The world wide names, fc address, and FC4 port
  1003. * roles for the remote port.
  1004. *
  1005. * Allocates and creates the remoter port structure, including the
  1006. * class and sysfs creation.
  1007. *
  1008. * Notes:
  1009. * This routine assumes no locks are held on entry.
  1010. **/
  1011. struct fc_rport *
  1012. fc_rport_create(struct Scsi_Host *shost, int channel,
  1013. struct fc_rport_identifiers *ids)
  1014. {
  1015. struct fc_host_attrs *fc_host =
  1016. (struct fc_host_attrs *)shost->shost_data;
  1017. struct fc_internal *fci = to_fc_internal(shost->transportt);
  1018. struct fc_rport *rport;
  1019. struct device *dev;
  1020. unsigned long flags;
  1021. int error;
  1022. size_t size;
  1023. size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
  1024. rport = kmalloc(size, GFP_KERNEL);
  1025. if (unlikely(!rport)) {
  1026. printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
  1027. return NULL;
  1028. }
  1029. memset(rport, 0, size);
  1030. rport->maxframe_size = -1;
  1031. rport->supported_classes = FC_COS_UNSPECIFIED;
  1032. rport->dev_loss_tmo = fc_dev_loss_tmo;
  1033. memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
  1034. memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
  1035. rport->port_id = ids->port_id;
  1036. rport->roles = ids->roles;
  1037. rport->port_state = FC_PORTSTATE_ONLINE;
  1038. if (fci->f->dd_fcrport_size)
  1039. rport->dd_data = &rport[1];
  1040. rport->channel = channel;
  1041. INIT_WORK(&rport->dev_loss_work, fc_timeout_blocked_rport, rport);
  1042. INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport);
  1043. spin_lock_irqsave(shost->host_lock, flags);
  1044. rport->number = fc_host->next_rport_number++;
  1045. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  1046. rport->scsi_target_id = fc_host->next_target_id++;
  1047. else
  1048. rport->scsi_target_id = -1;
  1049. list_add_tail(&rport->peers, &fc_host_rports(shost));
  1050. get_device(&shost->shost_gendev);
  1051. spin_unlock_irqrestore(shost->host_lock, flags);
  1052. dev = &rport->dev;
  1053. device_initialize(dev);
  1054. dev->parent = get_device(&shost->shost_gendev);
  1055. dev->release = fc_rport_dev_release;
  1056. sprintf(dev->bus_id, "rport-%d:%d-%d",
  1057. shost->host_no, channel, rport->number);
  1058. transport_setup_device(dev);
  1059. error = device_add(dev);
  1060. if (error) {
  1061. printk(KERN_ERR "FC Remote Port device_add failed\n");
  1062. goto delete_rport;
  1063. }
  1064. transport_add_device(dev);
  1065. transport_configure_device(dev);
  1066. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  1067. /* initiate a scan of the target */
  1068. scsi_queue_work(shost, &rport->scan_work);
  1069. return rport;
  1070. delete_rport:
  1071. transport_destroy_device(dev);
  1072. put_device(dev->parent);
  1073. spin_lock_irqsave(shost->host_lock, flags);
  1074. list_del(&rport->peers);
  1075. put_device(&shost->shost_gendev);
  1076. spin_unlock_irqrestore(shost->host_lock, flags);
  1077. put_device(dev->parent);
  1078. kfree(rport);
  1079. return NULL;
  1080. }
  1081. /**
  1082. * fc_remote_port_add - notifies the fc transport of the existence
  1083. * of a remote FC port.
  1084. * @shost: scsi host the remote port is connected to.
  1085. * @channel: Channel on shost port connected to.
  1086. * @ids: The world wide names, fc address, and FC4 port
  1087. * roles for the remote port.
  1088. *
  1089. * The LLDD calls this routine to notify the transport of the existence
  1090. * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
  1091. * of the port, it's FC address (port_id), and the FC4 roles that are
  1092. * active for the port.
  1093. *
  1094. * For ports that are FCP targets (aka scsi targets), the FC transport
  1095. * maintains consistent target id bindings on behalf of the LLDD.
  1096. * A consistent target id binding is an assignment of a target id to
  1097. * a remote port identifier, which persists while the scsi host is
  1098. * attached. The remote port can disappear, then later reappear, and
  1099. * it's target id assignment remains the same. This allows for shifts
  1100. * in FC addressing (if binding by wwpn or wwnn) with no apparent
  1101. * changes to the scsi subsystem which is based on scsi host number and
  1102. * target id values. Bindings are only valid during the attachment of
  1103. * the scsi host. If the host detaches, then later re-attaches, target
  1104. * id bindings may change.
  1105. *
  1106. * This routine is responsible for returning a remote port structure.
  1107. * The routine will search the list of remote ports it maintains
  1108. * internally on behalf of consistent target id mappings. If found, the
  1109. * remote port structure will be reused. Otherwise, a new remote port
  1110. * structure will be allocated.
  1111. *
  1112. * Whenever a remote port is allocated, a new fc_remote_port class
  1113. * device is created.
  1114. *
  1115. * Should not be called from interrupt context.
  1116. *
  1117. * Notes:
  1118. * This routine assumes no locks are held on entry.
  1119. **/
  1120. struct fc_rport *
  1121. fc_remote_port_add(struct Scsi_Host *shost, int channel,
  1122. struct fc_rport_identifiers *ids)
  1123. {
  1124. struct fc_rport *rport;
  1125. unsigned long flags;
  1126. int match = 0;
  1127. if (likely((ids->roles & FC_RPORT_ROLE_FCP_TARGET) &&
  1128. (fc_host_tgtid_bind_type(shost) != FC_TGTID_BIND_NONE))) {
  1129. /* search for a matching consistent binding */
  1130. spin_lock_irqsave(shost->host_lock, flags);
  1131. list_for_each_entry(rport, &fc_host_rport_bindings(shost),
  1132. peers) {
  1133. if (rport->channel != channel)
  1134. continue;
  1135. switch (fc_host_tgtid_bind_type(shost)) {
  1136. case FC_TGTID_BIND_BY_WWPN:
  1137. if (rport->port_name == ids->port_name)
  1138. match = 1;
  1139. break;
  1140. case FC_TGTID_BIND_BY_WWNN:
  1141. if (rport->node_name == ids->node_name)
  1142. match = 1;
  1143. break;
  1144. case FC_TGTID_BIND_BY_ID:
  1145. if (rport->port_id == ids->port_id)
  1146. match = 1;
  1147. break;
  1148. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  1149. break;
  1150. }
  1151. if (match) {
  1152. list_move_tail(&rport->peers,
  1153. &fc_host_rports(shost));
  1154. break;
  1155. }
  1156. }
  1157. spin_unlock_irqrestore(shost->host_lock, flags);
  1158. if (match) {
  1159. memcpy(&rport->node_name, &ids->node_name,
  1160. sizeof(rport->node_name));
  1161. memcpy(&rport->port_name, &ids->port_name,
  1162. sizeof(rport->port_name));
  1163. rport->port_id = ids->port_id;
  1164. rport->roles = ids->roles;
  1165. rport->port_state = FC_PORTSTATE_ONLINE;
  1166. if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
  1167. /* initiate a scan of the target */
  1168. scsi_queue_work(shost, &rport->scan_work);
  1169. return rport;
  1170. }
  1171. }
  1172. /* No consistent binding found - create new remote port entry */
  1173. rport = fc_rport_create(shost, channel, ids);
  1174. return rport;
  1175. }
  1176. EXPORT_SYMBOL(fc_remote_port_add);
  1177. /*
  1178. * fc_rport_tgt_remove - Removes the scsi target on the remote port
  1179. * @rport: The remote port to be operated on
  1180. */
  1181. static void
  1182. fc_rport_tgt_remove(struct fc_rport *rport)
  1183. {
  1184. struct Scsi_Host *shost = rport_to_shost(rport);
  1185. scsi_target_unblock(&rport->dev);
  1186. /* Stop anything on the workq */
  1187. if (!cancel_delayed_work(&rport->dev_loss_work))
  1188. flush_scheduled_work();
  1189. scsi_flush_work(shost);
  1190. scsi_remove_target(&rport->dev);
  1191. }
  1192. /*
  1193. * fc_rport_terminate - this routine tears down and deallocates a remote port.
  1194. * @rport: The remote port to be terminated
  1195. *
  1196. * Notes:
  1197. * This routine assumes no locks are held on entry.
  1198. */
  1199. static void
  1200. fc_rport_terminate(struct fc_rport *rport)
  1201. {
  1202. struct Scsi_Host *shost = rport_to_shost(rport);
  1203. struct device *dev = &rport->dev;
  1204. unsigned long flags;
  1205. fc_rport_tgt_remove(rport);
  1206. transport_remove_device(dev);
  1207. device_del(dev);
  1208. transport_destroy_device(dev);
  1209. spin_lock_irqsave(shost->host_lock, flags);
  1210. list_del(&rport->peers);
  1211. spin_unlock_irqrestore(shost->host_lock, flags);
  1212. put_device(&shost->shost_gendev);
  1213. }
  1214. /**
  1215. * fc_remote_port_delete - notifies the fc transport that a remote
  1216. * port is no longer in existence.
  1217. * @rport: The remote port that no longer exists
  1218. *
  1219. * The LLDD calls this routine to notify the transport that a remote
  1220. * port is no longer part of the topology. Note: Although a port
  1221. * may no longer be part of the topology, it may persist in the remote
  1222. * ports displayed by the fc_host. This is done so that target id
  1223. * mappings (managed via the remote port structures), are always visible
  1224. * as long as the mapping is valid, regardless of port state,
  1225. *
  1226. * If the remote port is not an FCP Target, it will be fully torn down
  1227. * and deallocated, including the fc_remote_port class device.
  1228. *
  1229. * If the remote port is an FCP Target, the port structure will be
  1230. * marked as Not Present, but will remain as long as there is a valid
  1231. * SCSI target id mapping associated with the port structure. Validity
  1232. * is determined by the binding type. If binding by wwpn, then the port
  1233. * structure is always valid and will not be deallocated until the host
  1234. * is removed. If binding by wwnn, then the port structure is valid
  1235. * until another port with the same node name is found in the topology.
  1236. * If binding by port id (fc address), then the port structure is valid
  1237. * valid until another port with the same address is identified.
  1238. *
  1239. * Called from interrupt or normal process context.
  1240. *
  1241. * Notes:
  1242. * This routine assumes no locks are held on entry.
  1243. **/
  1244. void
  1245. fc_remote_port_delete(struct fc_rport *rport)
  1246. {
  1247. struct Scsi_Host *shost = rport_to_shost(rport);
  1248. unsigned long flags;
  1249. /* If no scsi target id mapping or consistent binding type, delete it */
  1250. if ((rport->scsi_target_id == -1) ||
  1251. (fc_host_tgtid_bind_type(shost) == FC_TGTID_BIND_NONE)) {
  1252. fc_rport_terminate(rport);
  1253. return;
  1254. }
  1255. fc_rport_tgt_remove(rport);
  1256. spin_lock_irqsave(shost->host_lock, flags);
  1257. list_move_tail(&rport->peers, &fc_host_rport_bindings(shost));
  1258. spin_unlock_irqrestore(shost->host_lock, flags);
  1259. /*
  1260. * Note: We do not remove or clear the hostdata area. This allows
  1261. * host-specific target data to persist along with the
  1262. * scsi_target_id. It's up to the host to manage it's hostdata area.
  1263. */
  1264. /*
  1265. * Reinitialize port attributes that may change if the port comes back.
  1266. */
  1267. rport->maxframe_size = -1;
  1268. rport->supported_classes = FC_COS_UNSPECIFIED;
  1269. rport->roles = FC_RPORT_ROLE_UNKNOWN;
  1270. rport->port_state = FC_PORTSTATE_NOTPRESENT;
  1271. /* remove the identifiers that aren't used in the consisting binding */
  1272. switch (fc_host_tgtid_bind_type(shost)) {
  1273. case FC_TGTID_BIND_BY_WWPN:
  1274. rport->node_name = -1;
  1275. rport->port_id = -1;
  1276. break;
  1277. case FC_TGTID_BIND_BY_WWNN:
  1278. rport->port_name = -1;
  1279. rport->port_id = -1;
  1280. break;
  1281. case FC_TGTID_BIND_BY_ID:
  1282. rport->node_name = -1;
  1283. rport->port_name = -1;
  1284. break;
  1285. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  1286. break;
  1287. }
  1288. }
  1289. EXPORT_SYMBOL(fc_remote_port_delete);
  1290. /**
  1291. * fc_remote_port_rolechg - notifies the fc transport that the roles
  1292. * on a remote may have changed.
  1293. * @rport: The remote port that changed.
  1294. *
  1295. * The LLDD calls this routine to notify the transport that the roles
  1296. * on a remote port may have changed. The largest effect of this is
  1297. * if a port now becomes a FCP Target, it must be allocated a
  1298. * scsi target id. If the port is no longer a FCP target, any
  1299. * scsi target id value assigned to it will persist in case the
  1300. * role changes back to include FCP Target. No changes in the scsi
  1301. * midlayer will be invoked if the role changes (in the expectation
  1302. * that the role will be resumed. If it doesn't normal error processing
  1303. * will take place).
  1304. *
  1305. * Should not be called from interrupt context.
  1306. *
  1307. * Notes:
  1308. * This routine assumes no locks are held on entry.
  1309. **/
  1310. void
  1311. fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
  1312. {
  1313. struct Scsi_Host *shost = rport_to_shost(rport);
  1314. struct fc_host_attrs *fc_host =
  1315. (struct fc_host_attrs *)shost->shost_data;
  1316. unsigned long flags;
  1317. int create = 0;
  1318. rport->roles = roles;
  1319. spin_lock_irqsave(shost->host_lock, flags);
  1320. if ((rport->scsi_target_id == -1) &&
  1321. (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
  1322. rport->scsi_target_id = fc_host->next_target_id++;
  1323. create = 1;
  1324. }
  1325. spin_unlock_irqrestore(shost->host_lock, flags);
  1326. if (create)
  1327. /* initiate a scan of the target */
  1328. scsi_queue_work(shost, &rport->scan_work);
  1329. }
  1330. EXPORT_SYMBOL(fc_remote_port_rolechg);
  1331. /**
  1332. * fc_timeout_blocked_rport - Timeout handler for blocked remote port
  1333. * that fails to return in the alloted time.
  1334. * @data: scsi target that failed to reappear in the alloted time.
  1335. **/
  1336. static void
  1337. fc_timeout_blocked_rport(void *data)
  1338. {
  1339. struct fc_rport *rport = (struct fc_rport *)data;
  1340. rport->port_state = FC_PORTSTATE_OFFLINE;
  1341. dev_printk(KERN_ERR, &rport->dev,
  1342. "blocked FC remote port time out: removing target\n");
  1343. /*
  1344. * As this only occurs if the remote port (scsi target)
  1345. * went away and didn't come back - we'll remove
  1346. * all attached scsi devices.
  1347. */
  1348. scsi_target_unblock(&rport->dev);
  1349. scsi_remove_target(&rport->dev);
  1350. }
  1351. /**
  1352. * fc_remote_port_block - temporarily block any scsi traffic to a remote port.
  1353. * @rport: remote port to be blocked.
  1354. *
  1355. * scsi lldd's with a FC transport call this routine to temporarily stop
  1356. * all scsi traffic to a remote port. If the port is not a SCSI target,
  1357. * no action is taken. If the port is a SCSI target, all attached devices
  1358. * are placed into a SDEV_BLOCK state and a timer is started. The timer is
  1359. * represents the maximum amount of time the port may be blocked. If the
  1360. * timer expires, the port is considered non-existent and the attached
  1361. * scsi devices will be removed.
  1362. *
  1363. * Called from interrupt or normal process context.
  1364. *
  1365. * Returns zero if successful or error if not
  1366. *
  1367. * Notes:
  1368. * This routine assumes no locks are held on entry.
  1369. *
  1370. * The timeout and timer types are extracted from the fc transport
  1371. * attributes from the caller's rport pointer.
  1372. **/
  1373. int
  1374. fc_remote_port_block(struct fc_rport *rport)
  1375. {
  1376. int timeout = rport->dev_loss_tmo;
  1377. struct work_struct *work = &rport->dev_loss_work;
  1378. if (timeout < 0 || timeout > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
  1379. return -EINVAL;
  1380. scsi_target_block(&rport->dev);
  1381. /* cap the length the devices can be blocked */
  1382. schedule_delayed_work(work, timeout * HZ);
  1383. rport->port_state = FC_PORTSTATE_BLOCKED;
  1384. return 0;
  1385. }
  1386. EXPORT_SYMBOL(fc_remote_port_block);
  1387. /**
  1388. * fc_remote_port_unblock - restart any blocked scsi traffic to a remote port.
  1389. * @rport: remote port to be unblocked.
  1390. *
  1391. * scsi lld's with a FC transport call this routine to restart IO to all
  1392. * devices associated with the caller's scsi target following a fc_target_block
  1393. * request. Called from interrupt or normal process context.
  1394. *
  1395. * Notes:
  1396. * This routine assumes no locks are held on entry.
  1397. **/
  1398. void
  1399. fc_remote_port_unblock(struct fc_rport *rport)
  1400. {
  1401. struct work_struct *work = &rport->dev_loss_work;
  1402. struct Scsi_Host *shost = rport_to_shost(rport);
  1403. /*
  1404. * Stop the target timer first. Take no action on the del_timer
  1405. * failure as the state machine state change will validate the
  1406. * transaction.
  1407. */
  1408. if (!cancel_delayed_work(work))
  1409. flush_scheduled_work();
  1410. if (rport->port_state == FC_PORTSTATE_OFFLINE)
  1411. /*
  1412. * initiate a scan of the target as the target has
  1413. * been torn down.
  1414. */
  1415. scsi_queue_work(shost, &rport->scan_work);
  1416. else
  1417. scsi_target_unblock(&rport->dev);
  1418. rport->port_state = FC_PORTSTATE_ONLINE;
  1419. }
  1420. EXPORT_SYMBOL(fc_remote_port_unblock);
  1421. /**
  1422. * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
  1423. * @data: remote port to be scanned.
  1424. **/
  1425. static void
  1426. fc_scsi_scan_rport(void *data)
  1427. {
  1428. struct fc_rport *rport = (struct fc_rport *)data;
  1429. scsi_scan_target(&rport->dev, rport->channel, rport->scsi_target_id,
  1430. SCAN_WILD_CARD, 1);
  1431. }
  1432. MODULE_AUTHOR("Martin Hicks");
  1433. MODULE_DESCRIPTION("FC Transport Attributes");
  1434. MODULE_LICENSE("GPL");
  1435. module_init(fc_transport_init);
  1436. module_exit(fc_transport_exit);