scsi_transport_fc.c 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328
  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-2007 James Smart, Emulex Corporation
  23. * Rewrite for host, target, device, and remote port attributes,
  24. * statistics, and service functions...
  25. * Add vports, etc
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/init.h>
  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. #include "scsi_transport_fc_internal.h"
  40. static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
  41. static void fc_vport_sched_delete(struct work_struct *work);
  42. /*
  43. * This is a temporary carrier for creating a vport. It will eventually
  44. * be replaced by a real message definition for sgio or netlink.
  45. *
  46. * fc_vport_identifiers: This set of data contains all elements
  47. * to uniquely identify and instantiate a FC virtual port.
  48. *
  49. * Notes:
  50. * symbolic_name: The driver is to append the symbolic_name string data
  51. * to the symbolic_node_name data that it generates by default.
  52. * the resulting combination should then be registered with the switch.
  53. * It is expected that things like Xen may stuff a VM title into
  54. * this field.
  55. */
  56. struct fc_vport_identifiers {
  57. u64 node_name;
  58. u64 port_name;
  59. u32 roles;
  60. bool disable;
  61. enum fc_port_type vport_type; /* only FC_PORTTYPE_NPIV allowed */
  62. char symbolic_name[FC_VPORT_SYMBOLIC_NAMELEN];
  63. };
  64. static int fc_vport_create(struct Scsi_Host *shost, int channel,
  65. struct device *pdev, struct fc_vport_identifiers *ids,
  66. struct fc_vport **vport);
  67. /*
  68. * Redefine so that we can have same named attributes in the
  69. * sdev/starget/host objects.
  70. */
  71. #define FC_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
  72. struct device_attribute device_attr_##_prefix##_##_name = \
  73. __ATTR(_name,_mode,_show,_store)
  74. #define fc_enum_name_search(title, table_type, table) \
  75. static const char *get_fc_##title##_name(enum table_type table_key) \
  76. { \
  77. int i; \
  78. char *name = NULL; \
  79. \
  80. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  81. if (table[i].value == table_key) { \
  82. name = table[i].name; \
  83. break; \
  84. } \
  85. } \
  86. return name; \
  87. }
  88. #define fc_enum_name_match(title, table_type, table) \
  89. static int get_fc_##title##_match(const char *table_key, \
  90. enum table_type *value) \
  91. { \
  92. int i; \
  93. \
  94. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  95. if (strncmp(table_key, table[i].name, \
  96. table[i].matchlen) == 0) { \
  97. *value = table[i].value; \
  98. return 0; /* success */ \
  99. } \
  100. } \
  101. return 1; /* failure */ \
  102. }
  103. /* Convert fc_port_type values to ascii string name */
  104. static struct {
  105. enum fc_port_type value;
  106. char *name;
  107. } fc_port_type_names[] = {
  108. { FC_PORTTYPE_UNKNOWN, "Unknown" },
  109. { FC_PORTTYPE_OTHER, "Other" },
  110. { FC_PORTTYPE_NOTPRESENT, "Not Present" },
  111. { FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
  112. { FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
  113. { FC_PORTTYPE_LPORT, "LPort (private loop)" },
  114. { FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
  115. { FC_PORTTYPE_NPIV, "NPIV VPORT" },
  116. };
  117. fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
  118. #define FC_PORTTYPE_MAX_NAMELEN 50
  119. /* Reuse fc_port_type enum function for vport_type */
  120. #define get_fc_vport_type_name get_fc_port_type_name
  121. /* Convert fc_host_event_code values to ascii string name */
  122. static const struct {
  123. enum fc_host_event_code value;
  124. char *name;
  125. } fc_host_event_code_names[] = {
  126. { FCH_EVT_LIP, "lip" },
  127. { FCH_EVT_LINKUP, "link_up" },
  128. { FCH_EVT_LINKDOWN, "link_down" },
  129. { FCH_EVT_LIPRESET, "lip_reset" },
  130. { FCH_EVT_RSCN, "rscn" },
  131. { FCH_EVT_ADAPTER_CHANGE, "adapter_chg" },
  132. { FCH_EVT_PORT_UNKNOWN, "port_unknown" },
  133. { FCH_EVT_PORT_ONLINE, "port_online" },
  134. { FCH_EVT_PORT_OFFLINE, "port_offline" },
  135. { FCH_EVT_PORT_FABRIC, "port_fabric" },
  136. { FCH_EVT_LINK_UNKNOWN, "link_unknown" },
  137. { FCH_EVT_VENDOR_UNIQUE, "vendor_unique" },
  138. };
  139. fc_enum_name_search(host_event_code, fc_host_event_code,
  140. fc_host_event_code_names)
  141. #define FC_HOST_EVENT_CODE_MAX_NAMELEN 30
  142. /* Convert fc_port_state values to ascii string name */
  143. static struct {
  144. enum fc_port_state value;
  145. char *name;
  146. } fc_port_state_names[] = {
  147. { FC_PORTSTATE_UNKNOWN, "Unknown" },
  148. { FC_PORTSTATE_NOTPRESENT, "Not Present" },
  149. { FC_PORTSTATE_ONLINE, "Online" },
  150. { FC_PORTSTATE_OFFLINE, "Offline" },
  151. { FC_PORTSTATE_BLOCKED, "Blocked" },
  152. { FC_PORTSTATE_BYPASSED, "Bypassed" },
  153. { FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
  154. { FC_PORTSTATE_LINKDOWN, "Linkdown" },
  155. { FC_PORTSTATE_ERROR, "Error" },
  156. { FC_PORTSTATE_LOOPBACK, "Loopback" },
  157. { FC_PORTSTATE_DELETED, "Deleted" },
  158. };
  159. fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
  160. #define FC_PORTSTATE_MAX_NAMELEN 20
  161. /* Convert fc_vport_state values to ascii string name */
  162. static struct {
  163. enum fc_vport_state value;
  164. char *name;
  165. } fc_vport_state_names[] = {
  166. { FC_VPORT_UNKNOWN, "Unknown" },
  167. { FC_VPORT_ACTIVE, "Active" },
  168. { FC_VPORT_DISABLED, "Disabled" },
  169. { FC_VPORT_LINKDOWN, "Linkdown" },
  170. { FC_VPORT_INITIALIZING, "Initializing" },
  171. { FC_VPORT_NO_FABRIC_SUPP, "No Fabric Support" },
  172. { FC_VPORT_NO_FABRIC_RSCS, "No Fabric Resources" },
  173. { FC_VPORT_FABRIC_LOGOUT, "Fabric Logout" },
  174. { FC_VPORT_FABRIC_REJ_WWN, "Fabric Rejected WWN" },
  175. { FC_VPORT_FAILED, "VPort Failed" },
  176. };
  177. fc_enum_name_search(vport_state, fc_vport_state, fc_vport_state_names)
  178. #define FC_VPORTSTATE_MAX_NAMELEN 24
  179. /* Reuse fc_vport_state enum function for vport_last_state */
  180. #define get_fc_vport_last_state_name get_fc_vport_state_name
  181. /* Convert fc_tgtid_binding_type values to ascii string name */
  182. static const struct {
  183. enum fc_tgtid_binding_type value;
  184. char *name;
  185. int matchlen;
  186. } fc_tgtid_binding_type_names[] = {
  187. { FC_TGTID_BIND_NONE, "none", 4 },
  188. { FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
  189. { FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
  190. { FC_TGTID_BIND_BY_ID, "port_id (FC Address)", 7 },
  191. };
  192. fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
  193. fc_tgtid_binding_type_names)
  194. fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
  195. fc_tgtid_binding_type_names)
  196. #define FC_BINDTYPE_MAX_NAMELEN 30
  197. #define fc_bitfield_name_search(title, table) \
  198. static ssize_t \
  199. get_fc_##title##_names(u32 table_key, char *buf) \
  200. { \
  201. char *prefix = ""; \
  202. ssize_t len = 0; \
  203. int i; \
  204. \
  205. for (i = 0; i < ARRAY_SIZE(table); i++) { \
  206. if (table[i].value & table_key) { \
  207. len += sprintf(buf + len, "%s%s", \
  208. prefix, table[i].name); \
  209. prefix = ", "; \
  210. } \
  211. } \
  212. len += sprintf(buf + len, "\n"); \
  213. return len; \
  214. }
  215. /* Convert FC_COS bit values to ascii string name */
  216. static const struct {
  217. u32 value;
  218. char *name;
  219. } fc_cos_names[] = {
  220. { FC_COS_CLASS1, "Class 1" },
  221. { FC_COS_CLASS2, "Class 2" },
  222. { FC_COS_CLASS3, "Class 3" },
  223. { FC_COS_CLASS4, "Class 4" },
  224. { FC_COS_CLASS6, "Class 6" },
  225. };
  226. fc_bitfield_name_search(cos, fc_cos_names)
  227. /* Convert FC_PORTSPEED bit values to ascii string name */
  228. static const struct {
  229. u32 value;
  230. char *name;
  231. } fc_port_speed_names[] = {
  232. { FC_PORTSPEED_1GBIT, "1 Gbit" },
  233. { FC_PORTSPEED_2GBIT, "2 Gbit" },
  234. { FC_PORTSPEED_4GBIT, "4 Gbit" },
  235. { FC_PORTSPEED_10GBIT, "10 Gbit" },
  236. { FC_PORTSPEED_8GBIT, "8 Gbit" },
  237. { FC_PORTSPEED_16GBIT, "16 Gbit" },
  238. { FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
  239. };
  240. fc_bitfield_name_search(port_speed, fc_port_speed_names)
  241. static int
  242. show_fc_fc4s (char *buf, u8 *fc4_list)
  243. {
  244. int i, len=0;
  245. for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
  246. len += sprintf(buf + len , "0x%02x ", *fc4_list);
  247. len += sprintf(buf + len, "\n");
  248. return len;
  249. }
  250. /* Convert FC_PORT_ROLE bit values to ascii string name */
  251. static const struct {
  252. u32 value;
  253. char *name;
  254. } fc_port_role_names[] = {
  255. { FC_PORT_ROLE_FCP_TARGET, "FCP Target" },
  256. { FC_PORT_ROLE_FCP_INITIATOR, "FCP Initiator" },
  257. { FC_PORT_ROLE_IP_PORT, "IP Port" },
  258. };
  259. fc_bitfield_name_search(port_roles, fc_port_role_names)
  260. /*
  261. * Define roles that are specific to port_id. Values are relative to ROLE_MASK.
  262. */
  263. #define FC_WELLKNOWN_PORTID_MASK 0xfffff0
  264. #define FC_WELLKNOWN_ROLE_MASK 0x00000f
  265. #define FC_FPORT_PORTID 0x00000e
  266. #define FC_FABCTLR_PORTID 0x00000d
  267. #define FC_DIRSRVR_PORTID 0x00000c
  268. #define FC_TIMESRVR_PORTID 0x00000b
  269. #define FC_MGMTSRVR_PORTID 0x00000a
  270. static void fc_timeout_deleted_rport(struct work_struct *work);
  271. static void fc_timeout_fail_rport_io(struct work_struct *work);
  272. static void fc_scsi_scan_rport(struct work_struct *work);
  273. /*
  274. * Attribute counts pre object type...
  275. * Increase these values if you add attributes
  276. */
  277. #define FC_STARGET_NUM_ATTRS 3
  278. #define FC_RPORT_NUM_ATTRS 10
  279. #define FC_VPORT_NUM_ATTRS 9
  280. #define FC_HOST_NUM_ATTRS 21
  281. struct fc_internal {
  282. struct scsi_transport_template t;
  283. struct fc_function_template *f;
  284. /*
  285. * For attributes : each object has :
  286. * An array of the actual attributes structures
  287. * An array of null-terminated pointers to the attribute
  288. * structures - used for mid-layer interaction.
  289. *
  290. * The attribute containers for the starget and host are are
  291. * part of the midlayer. As the remote port is specific to the
  292. * fc transport, we must provide the attribute container.
  293. */
  294. struct device_attribute private_starget_attrs[
  295. FC_STARGET_NUM_ATTRS];
  296. struct device_attribute *starget_attrs[FC_STARGET_NUM_ATTRS + 1];
  297. struct device_attribute private_host_attrs[FC_HOST_NUM_ATTRS];
  298. struct device_attribute *host_attrs[FC_HOST_NUM_ATTRS + 1];
  299. struct transport_container rport_attr_cont;
  300. struct device_attribute private_rport_attrs[FC_RPORT_NUM_ATTRS];
  301. struct device_attribute *rport_attrs[FC_RPORT_NUM_ATTRS + 1];
  302. struct transport_container vport_attr_cont;
  303. struct device_attribute private_vport_attrs[FC_VPORT_NUM_ATTRS];
  304. struct device_attribute *vport_attrs[FC_VPORT_NUM_ATTRS + 1];
  305. };
  306. #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
  307. static int fc_target_setup(struct transport_container *tc, struct device *dev,
  308. struct device *cdev)
  309. {
  310. struct scsi_target *starget = to_scsi_target(dev);
  311. struct fc_rport *rport = starget_to_rport(starget);
  312. /*
  313. * if parent is remote port, use values from remote port.
  314. * Otherwise, this host uses the fc_transport, but not the
  315. * remote port interface. As such, initialize to known non-values.
  316. */
  317. if (rport) {
  318. fc_starget_node_name(starget) = rport->node_name;
  319. fc_starget_port_name(starget) = rport->port_name;
  320. fc_starget_port_id(starget) = rport->port_id;
  321. } else {
  322. fc_starget_node_name(starget) = -1;
  323. fc_starget_port_name(starget) = -1;
  324. fc_starget_port_id(starget) = -1;
  325. }
  326. return 0;
  327. }
  328. static DECLARE_TRANSPORT_CLASS(fc_transport_class,
  329. "fc_transport",
  330. fc_target_setup,
  331. NULL,
  332. NULL);
  333. static int fc_host_setup(struct transport_container *tc, struct device *dev,
  334. struct device *cdev)
  335. {
  336. struct Scsi_Host *shost = dev_to_shost(dev);
  337. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  338. /*
  339. * Set default values easily detected by the midlayer as
  340. * failure cases. The scsi lldd is responsible for initializing
  341. * all transport attributes to valid values per host.
  342. */
  343. fc_host->node_name = -1;
  344. fc_host->port_name = -1;
  345. fc_host->permanent_port_name = -1;
  346. fc_host->supported_classes = FC_COS_UNSPECIFIED;
  347. memset(fc_host->supported_fc4s, 0,
  348. sizeof(fc_host->supported_fc4s));
  349. fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
  350. fc_host->maxframe_size = -1;
  351. fc_host->max_npiv_vports = 0;
  352. memset(fc_host->serial_number, 0,
  353. sizeof(fc_host->serial_number));
  354. fc_host->port_id = -1;
  355. fc_host->port_type = FC_PORTTYPE_UNKNOWN;
  356. fc_host->port_state = FC_PORTSTATE_UNKNOWN;
  357. memset(fc_host->active_fc4s, 0,
  358. sizeof(fc_host->active_fc4s));
  359. fc_host->speed = FC_PORTSPEED_UNKNOWN;
  360. fc_host->fabric_name = -1;
  361. memset(fc_host->symbolic_name, 0, sizeof(fc_host->symbolic_name));
  362. memset(fc_host->system_hostname, 0, sizeof(fc_host->system_hostname));
  363. fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
  364. INIT_LIST_HEAD(&fc_host->rports);
  365. INIT_LIST_HEAD(&fc_host->rport_bindings);
  366. INIT_LIST_HEAD(&fc_host->vports);
  367. fc_host->next_rport_number = 0;
  368. fc_host->next_target_id = 0;
  369. fc_host->next_vport_number = 0;
  370. fc_host->npiv_vports_inuse = 0;
  371. snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d",
  372. shost->host_no);
  373. fc_host->work_q = create_singlethread_workqueue(
  374. fc_host->work_q_name);
  375. if (!fc_host->work_q)
  376. return -ENOMEM;
  377. snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d",
  378. shost->host_no);
  379. fc_host->devloss_work_q = create_singlethread_workqueue(
  380. fc_host->devloss_work_q_name);
  381. if (!fc_host->devloss_work_q) {
  382. destroy_workqueue(fc_host->work_q);
  383. fc_host->work_q = NULL;
  384. return -ENOMEM;
  385. }
  386. return 0;
  387. }
  388. static DECLARE_TRANSPORT_CLASS(fc_host_class,
  389. "fc_host",
  390. fc_host_setup,
  391. NULL,
  392. NULL);
  393. /*
  394. * Setup and Remove actions for remote ports are handled
  395. * in the service functions below.
  396. */
  397. static DECLARE_TRANSPORT_CLASS(fc_rport_class,
  398. "fc_remote_ports",
  399. NULL,
  400. NULL,
  401. NULL);
  402. /*
  403. * Setup and Remove actions for virtual ports are handled
  404. * in the service functions below.
  405. */
  406. static DECLARE_TRANSPORT_CLASS(fc_vport_class,
  407. "fc_vports",
  408. NULL,
  409. NULL,
  410. NULL);
  411. /*
  412. * Module Parameters
  413. */
  414. /*
  415. * dev_loss_tmo: the default number of seconds that the FC transport
  416. * should insulate the loss of a remote port.
  417. * The maximum will be capped by the value of SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
  418. */
  419. static unsigned int fc_dev_loss_tmo = 60; /* seconds */
  420. module_param_named(dev_loss_tmo, fc_dev_loss_tmo, uint, S_IRUGO|S_IWUSR);
  421. MODULE_PARM_DESC(dev_loss_tmo,
  422. "Maximum number of seconds that the FC transport should"
  423. " insulate the loss of a remote port. Once this value is"
  424. " exceeded, the scsi target is removed. Value should be"
  425. " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT.");
  426. /*
  427. * Netlink Infrastructure
  428. */
  429. static atomic_t fc_event_seq;
  430. /**
  431. * fc_get_event_number - Obtain the next sequential FC event number
  432. *
  433. * Notes:
  434. * We could have inlined this, but it would have required fc_event_seq to
  435. * be exposed. For now, live with the subroutine call.
  436. * Atomic used to avoid lock/unlock...
  437. */
  438. u32
  439. fc_get_event_number(void)
  440. {
  441. return atomic_add_return(1, &fc_event_seq);
  442. }
  443. EXPORT_SYMBOL(fc_get_event_number);
  444. /**
  445. * fc_host_post_event - called to post an even on an fc_host.
  446. * @shost: host the event occurred on
  447. * @event_number: fc event number obtained from get_fc_event_number()
  448. * @event_code: fc_host event being posted
  449. * @event_data: 32bits of data for the event being posted
  450. *
  451. * Notes:
  452. * This routine assumes no locks are held on entry.
  453. */
  454. void
  455. fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
  456. enum fc_host_event_code event_code, u32 event_data)
  457. {
  458. struct sk_buff *skb;
  459. struct nlmsghdr *nlh;
  460. struct fc_nl_event *event;
  461. const char *name;
  462. u32 len, skblen;
  463. int err;
  464. if (!scsi_nl_sock) {
  465. err = -ENOENT;
  466. goto send_fail;
  467. }
  468. len = FC_NL_MSGALIGN(sizeof(*event));
  469. skblen = NLMSG_SPACE(len);
  470. skb = alloc_skb(skblen, GFP_KERNEL);
  471. if (!skb) {
  472. err = -ENOBUFS;
  473. goto send_fail;
  474. }
  475. nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
  476. skblen - sizeof(*nlh), 0);
  477. if (!nlh) {
  478. err = -ENOBUFS;
  479. goto send_fail_skb;
  480. }
  481. event = NLMSG_DATA(nlh);
  482. INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
  483. FC_NL_ASYNC_EVENT, len);
  484. event->seconds = get_seconds();
  485. event->vendor_id = 0;
  486. event->host_no = shost->host_no;
  487. event->event_datalen = sizeof(u32); /* bytes */
  488. event->event_num = event_number;
  489. event->event_code = event_code;
  490. event->event_data = event_data;
  491. err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
  492. GFP_KERNEL);
  493. if (err && (err != -ESRCH)) /* filter no recipient errors */
  494. /* nlmsg_multicast already kfree_skb'd */
  495. goto send_fail;
  496. return;
  497. send_fail_skb:
  498. kfree_skb(skb);
  499. send_fail:
  500. name = get_fc_host_event_code_name(event_code);
  501. printk(KERN_WARNING
  502. "%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
  503. __FUNCTION__, shost->host_no,
  504. (name) ? name : "<unknown>", event_data, err);
  505. return;
  506. }
  507. EXPORT_SYMBOL(fc_host_post_event);
  508. /**
  509. * fc_host_post_vendor_event - called to post a vendor unique event on an fc_host
  510. * @shost: host the event occurred on
  511. * @event_number: fc event number obtained from get_fc_event_number()
  512. * @data_len: amount, in bytes, of vendor unique data
  513. * @data_buf: pointer to vendor unique data
  514. * @vendor_id: Vendor id
  515. *
  516. * Notes:
  517. * This routine assumes no locks are held on entry.
  518. */
  519. void
  520. fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
  521. u32 data_len, char * data_buf, u64 vendor_id)
  522. {
  523. struct sk_buff *skb;
  524. struct nlmsghdr *nlh;
  525. struct fc_nl_event *event;
  526. u32 len, skblen;
  527. int err;
  528. if (!scsi_nl_sock) {
  529. err = -ENOENT;
  530. goto send_vendor_fail;
  531. }
  532. len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
  533. skblen = NLMSG_SPACE(len);
  534. skb = alloc_skb(skblen, GFP_KERNEL);
  535. if (!skb) {
  536. err = -ENOBUFS;
  537. goto send_vendor_fail;
  538. }
  539. nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
  540. skblen - sizeof(*nlh), 0);
  541. if (!nlh) {
  542. err = -ENOBUFS;
  543. goto send_vendor_fail_skb;
  544. }
  545. event = NLMSG_DATA(nlh);
  546. INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
  547. FC_NL_ASYNC_EVENT, len);
  548. event->seconds = get_seconds();
  549. event->vendor_id = vendor_id;
  550. event->host_no = shost->host_no;
  551. event->event_datalen = data_len; /* bytes */
  552. event->event_num = event_number;
  553. event->event_code = FCH_EVT_VENDOR_UNIQUE;
  554. memcpy(&event->event_data, data_buf, data_len);
  555. err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
  556. GFP_KERNEL);
  557. if (err && (err != -ESRCH)) /* filter no recipient errors */
  558. /* nlmsg_multicast already kfree_skb'd */
  559. goto send_vendor_fail;
  560. return;
  561. send_vendor_fail_skb:
  562. kfree_skb(skb);
  563. send_vendor_fail:
  564. printk(KERN_WARNING
  565. "%s: Dropped Event : host %d vendor_unique - err %d\n",
  566. __FUNCTION__, shost->host_no, err);
  567. return;
  568. }
  569. EXPORT_SYMBOL(fc_host_post_vendor_event);
  570. static __init int fc_transport_init(void)
  571. {
  572. int error;
  573. atomic_set(&fc_event_seq, 0);
  574. error = transport_class_register(&fc_host_class);
  575. if (error)
  576. return error;
  577. error = transport_class_register(&fc_vport_class);
  578. if (error)
  579. return error;
  580. error = transport_class_register(&fc_rport_class);
  581. if (error)
  582. return error;
  583. return transport_class_register(&fc_transport_class);
  584. }
  585. static void __exit fc_transport_exit(void)
  586. {
  587. transport_class_unregister(&fc_transport_class);
  588. transport_class_unregister(&fc_rport_class);
  589. transport_class_unregister(&fc_host_class);
  590. transport_class_unregister(&fc_vport_class);
  591. }
  592. /*
  593. * FC Remote Port Attribute Management
  594. */
  595. #define fc_rport_show_function(field, format_string, sz, cast) \
  596. static ssize_t \
  597. show_fc_rport_##field (struct device *dev, \
  598. struct device_attribute *attr, char *buf) \
  599. { \
  600. struct fc_rport *rport = transport_class_to_rport(dev); \
  601. struct Scsi_Host *shost = rport_to_shost(rport); \
  602. struct fc_internal *i = to_fc_internal(shost->transportt); \
  603. if ((i->f->get_rport_##field) && \
  604. !((rport->port_state == FC_PORTSTATE_BLOCKED) || \
  605. (rport->port_state == FC_PORTSTATE_DELETED) || \
  606. (rport->port_state == FC_PORTSTATE_NOTPRESENT))) \
  607. i->f->get_rport_##field(rport); \
  608. return snprintf(buf, sz, format_string, cast rport->field); \
  609. }
  610. #define fc_rport_store_function(field) \
  611. static ssize_t \
  612. store_fc_rport_##field(struct device *dev, \
  613. struct device_attribute *attr, \
  614. const char *buf, size_t count) \
  615. { \
  616. int val; \
  617. struct fc_rport *rport = transport_class_to_rport(dev); \
  618. struct Scsi_Host *shost = rport_to_shost(rport); \
  619. struct fc_internal *i = to_fc_internal(shost->transportt); \
  620. char *cp; \
  621. if ((rport->port_state == FC_PORTSTATE_BLOCKED) || \
  622. (rport->port_state == FC_PORTSTATE_DELETED) || \
  623. (rport->port_state == FC_PORTSTATE_NOTPRESENT)) \
  624. return -EBUSY; \
  625. val = simple_strtoul(buf, &cp, 0); \
  626. if (*cp && (*cp != '\n')) \
  627. return -EINVAL; \
  628. i->f->set_rport_##field(rport, val); \
  629. return count; \
  630. }
  631. #define fc_rport_rd_attr(field, format_string, sz) \
  632. fc_rport_show_function(field, format_string, sz, ) \
  633. static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
  634. show_fc_rport_##field, NULL)
  635. #define fc_rport_rd_attr_cast(field, format_string, sz, cast) \
  636. fc_rport_show_function(field, format_string, sz, (cast)) \
  637. static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
  638. show_fc_rport_##field, NULL)
  639. #define fc_rport_rw_attr(field, format_string, sz) \
  640. fc_rport_show_function(field, format_string, sz, ) \
  641. fc_rport_store_function(field) \
  642. static FC_DEVICE_ATTR(rport, field, S_IRUGO | S_IWUSR, \
  643. show_fc_rport_##field, \
  644. store_fc_rport_##field)
  645. #define fc_private_rport_show_function(field, format_string, sz, cast) \
  646. static ssize_t \
  647. show_fc_rport_##field (struct device *dev, \
  648. struct device_attribute *attr, char *buf) \
  649. { \
  650. struct fc_rport *rport = transport_class_to_rport(dev); \
  651. return snprintf(buf, sz, format_string, cast rport->field); \
  652. }
  653. #define fc_private_rport_rd_attr(field, format_string, sz) \
  654. fc_private_rport_show_function(field, format_string, sz, ) \
  655. static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
  656. show_fc_rport_##field, NULL)
  657. #define fc_private_rport_rd_attr_cast(field, format_string, sz, cast) \
  658. fc_private_rport_show_function(field, format_string, sz, (cast)) \
  659. static FC_DEVICE_ATTR(rport, field, S_IRUGO, \
  660. show_fc_rport_##field, NULL)
  661. #define fc_private_rport_rd_enum_attr(title, maxlen) \
  662. static ssize_t \
  663. show_fc_rport_##title (struct device *dev, \
  664. struct device_attribute *attr, char *buf) \
  665. { \
  666. struct fc_rport *rport = transport_class_to_rport(dev); \
  667. const char *name; \
  668. name = get_fc_##title##_name(rport->title); \
  669. if (!name) \
  670. return -EINVAL; \
  671. return snprintf(buf, maxlen, "%s\n", name); \
  672. } \
  673. static FC_DEVICE_ATTR(rport, title, S_IRUGO, \
  674. show_fc_rport_##title, NULL)
  675. #define SETUP_RPORT_ATTRIBUTE_RD(field) \
  676. i->private_rport_attrs[count] = device_attr_rport_##field; \
  677. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  678. i->private_rport_attrs[count].store = NULL; \
  679. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  680. if (i->f->show_rport_##field) \
  681. count++
  682. #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(field) \
  683. i->private_rport_attrs[count] = device_attr_rport_##field; \
  684. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  685. i->private_rport_attrs[count].store = NULL; \
  686. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  687. count++
  688. #define SETUP_RPORT_ATTRIBUTE_RW(field) \
  689. i->private_rport_attrs[count] = device_attr_rport_##field; \
  690. if (!i->f->set_rport_##field) { \
  691. i->private_rport_attrs[count].attr.mode = S_IRUGO; \
  692. i->private_rport_attrs[count].store = NULL; \
  693. } \
  694. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  695. if (i->f->show_rport_##field) \
  696. count++
  697. #define SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(field) \
  698. { \
  699. i->private_rport_attrs[count] = device_attr_rport_##field; \
  700. i->rport_attrs[count] = &i->private_rport_attrs[count]; \
  701. count++; \
  702. }
  703. /* The FC Transport Remote Port Attributes: */
  704. /* Fixed Remote Port Attributes */
  705. fc_private_rport_rd_attr(maxframe_size, "%u bytes\n", 20);
  706. static ssize_t
  707. show_fc_rport_supported_classes (struct device *dev,
  708. struct device_attribute *attr, char *buf)
  709. {
  710. struct fc_rport *rport = transport_class_to_rport(dev);
  711. if (rport->supported_classes == FC_COS_UNSPECIFIED)
  712. return snprintf(buf, 20, "unspecified\n");
  713. return get_fc_cos_names(rport->supported_classes, buf);
  714. }
  715. static FC_DEVICE_ATTR(rport, supported_classes, S_IRUGO,
  716. show_fc_rport_supported_classes, NULL);
  717. /* Dynamic Remote Port Attributes */
  718. /*
  719. * dev_loss_tmo attribute
  720. */
  721. fc_rport_show_function(dev_loss_tmo, "%d\n", 20, )
  722. static ssize_t
  723. store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
  724. const char *buf, size_t count)
  725. {
  726. int val;
  727. struct fc_rport *rport = transport_class_to_rport(dev);
  728. struct Scsi_Host *shost = rport_to_shost(rport);
  729. struct fc_internal *i = to_fc_internal(shost->transportt);
  730. char *cp;
  731. if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
  732. (rport->port_state == FC_PORTSTATE_DELETED) ||
  733. (rport->port_state == FC_PORTSTATE_NOTPRESENT))
  734. return -EBUSY;
  735. val = simple_strtoul(buf, &cp, 0);
  736. if ((*cp && (*cp != '\n')) ||
  737. (val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
  738. return -EINVAL;
  739. i->f->set_rport_dev_loss_tmo(rport, val);
  740. return count;
  741. }
  742. static FC_DEVICE_ATTR(rport, dev_loss_tmo, S_IRUGO | S_IWUSR,
  743. show_fc_rport_dev_loss_tmo, store_fc_rport_dev_loss_tmo);
  744. /* Private Remote Port Attributes */
  745. fc_private_rport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  746. fc_private_rport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  747. fc_private_rport_rd_attr(port_id, "0x%06x\n", 20);
  748. static ssize_t
  749. show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
  750. char *buf)
  751. {
  752. struct fc_rport *rport = transport_class_to_rport(dev);
  753. /* identify any roles that are port_id specific */
  754. if ((rport->port_id != -1) &&
  755. (rport->port_id & FC_WELLKNOWN_PORTID_MASK) ==
  756. FC_WELLKNOWN_PORTID_MASK) {
  757. switch (rport->port_id & FC_WELLKNOWN_ROLE_MASK) {
  758. case FC_FPORT_PORTID:
  759. return snprintf(buf, 30, "Fabric Port\n");
  760. case FC_FABCTLR_PORTID:
  761. return snprintf(buf, 30, "Fabric Controller\n");
  762. case FC_DIRSRVR_PORTID:
  763. return snprintf(buf, 30, "Directory Server\n");
  764. case FC_TIMESRVR_PORTID:
  765. return snprintf(buf, 30, "Time Server\n");
  766. case FC_MGMTSRVR_PORTID:
  767. return snprintf(buf, 30, "Management Server\n");
  768. default:
  769. return snprintf(buf, 30, "Unknown Fabric Entity\n");
  770. }
  771. } else {
  772. if (rport->roles == FC_PORT_ROLE_UNKNOWN)
  773. return snprintf(buf, 20, "unknown\n");
  774. return get_fc_port_roles_names(rport->roles, buf);
  775. }
  776. }
  777. static FC_DEVICE_ATTR(rport, roles, S_IRUGO,
  778. show_fc_rport_roles, NULL);
  779. fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  780. fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
  781. /*
  782. * fast_io_fail_tmo attribute
  783. */
  784. static ssize_t
  785. show_fc_rport_fast_io_fail_tmo (struct device *dev,
  786. struct device_attribute *attr, char *buf)
  787. {
  788. struct fc_rport *rport = transport_class_to_rport(dev);
  789. if (rport->fast_io_fail_tmo == -1)
  790. return snprintf(buf, 5, "off\n");
  791. return snprintf(buf, 20, "%d\n", rport->fast_io_fail_tmo);
  792. }
  793. static ssize_t
  794. store_fc_rport_fast_io_fail_tmo(struct device *dev,
  795. struct device_attribute *attr, const char *buf,
  796. size_t count)
  797. {
  798. int val;
  799. char *cp;
  800. struct fc_rport *rport = transport_class_to_rport(dev);
  801. if ((rport->port_state == FC_PORTSTATE_BLOCKED) ||
  802. (rport->port_state == FC_PORTSTATE_DELETED) ||
  803. (rport->port_state == FC_PORTSTATE_NOTPRESENT))
  804. return -EBUSY;
  805. if (strncmp(buf, "off", 3) == 0)
  806. rport->fast_io_fail_tmo = -1;
  807. else {
  808. val = simple_strtoul(buf, &cp, 0);
  809. if ((*cp && (*cp != '\n')) ||
  810. (val < 0) || (val >= rport->dev_loss_tmo))
  811. return -EINVAL;
  812. rport->fast_io_fail_tmo = val;
  813. }
  814. return count;
  815. }
  816. static FC_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR,
  817. show_fc_rport_fast_io_fail_tmo, store_fc_rport_fast_io_fail_tmo);
  818. /*
  819. * FC SCSI Target Attribute Management
  820. */
  821. /*
  822. * Note: in the target show function we recognize when the remote
  823. * port is in the heirarchy and do not allow the driver to get
  824. * involved in sysfs functions. The driver only gets involved if
  825. * it's the "old" style that doesn't use rports.
  826. */
  827. #define fc_starget_show_function(field, format_string, sz, cast) \
  828. static ssize_t \
  829. show_fc_starget_##field (struct device *dev, \
  830. struct device_attribute *attr, char *buf) \
  831. { \
  832. struct scsi_target *starget = transport_class_to_starget(dev); \
  833. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
  834. struct fc_internal *i = to_fc_internal(shost->transportt); \
  835. struct fc_rport *rport = starget_to_rport(starget); \
  836. if (rport) \
  837. fc_starget_##field(starget) = rport->field; \
  838. else if (i->f->get_starget_##field) \
  839. i->f->get_starget_##field(starget); \
  840. return snprintf(buf, sz, format_string, \
  841. cast fc_starget_##field(starget)); \
  842. }
  843. #define fc_starget_rd_attr(field, format_string, sz) \
  844. fc_starget_show_function(field, format_string, sz, ) \
  845. static FC_DEVICE_ATTR(starget, field, S_IRUGO, \
  846. show_fc_starget_##field, NULL)
  847. #define fc_starget_rd_attr_cast(field, format_string, sz, cast) \
  848. fc_starget_show_function(field, format_string, sz, (cast)) \
  849. static FC_DEVICE_ATTR(starget, field, S_IRUGO, \
  850. show_fc_starget_##field, NULL)
  851. #define SETUP_STARGET_ATTRIBUTE_RD(field) \
  852. i->private_starget_attrs[count] = device_attr_starget_##field; \
  853. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  854. i->private_starget_attrs[count].store = NULL; \
  855. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  856. if (i->f->show_starget_##field) \
  857. count++
  858. #define SETUP_STARGET_ATTRIBUTE_RW(field) \
  859. i->private_starget_attrs[count] = device_attr_starget_##field; \
  860. if (!i->f->set_starget_##field) { \
  861. i->private_starget_attrs[count].attr.mode = S_IRUGO; \
  862. i->private_starget_attrs[count].store = NULL; \
  863. } \
  864. i->starget_attrs[count] = &i->private_starget_attrs[count]; \
  865. if (i->f->show_starget_##field) \
  866. count++
  867. /* The FC Transport SCSI Target Attributes: */
  868. fc_starget_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  869. fc_starget_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  870. fc_starget_rd_attr(port_id, "0x%06x\n", 20);
  871. /*
  872. * FC Virtual Port Attribute Management
  873. */
  874. #define fc_vport_show_function(field, format_string, sz, cast) \
  875. static ssize_t \
  876. show_fc_vport_##field (struct device *dev, \
  877. struct device_attribute *attr, char *buf) \
  878. { \
  879. struct fc_vport *vport = transport_class_to_vport(dev); \
  880. struct Scsi_Host *shost = vport_to_shost(vport); \
  881. struct fc_internal *i = to_fc_internal(shost->transportt); \
  882. if ((i->f->get_vport_##field) && \
  883. !(vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))) \
  884. i->f->get_vport_##field(vport); \
  885. return snprintf(buf, sz, format_string, cast vport->field); \
  886. }
  887. #define fc_vport_store_function(field) \
  888. static ssize_t \
  889. store_fc_vport_##field(struct device *dev, \
  890. struct device_attribute *attr, \
  891. const char *buf, size_t count) \
  892. { \
  893. int val; \
  894. struct fc_vport *vport = transport_class_to_vport(dev); \
  895. struct Scsi_Host *shost = vport_to_shost(vport); \
  896. struct fc_internal *i = to_fc_internal(shost->transportt); \
  897. char *cp; \
  898. if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
  899. return -EBUSY; \
  900. val = simple_strtoul(buf, &cp, 0); \
  901. if (*cp && (*cp != '\n')) \
  902. return -EINVAL; \
  903. i->f->set_vport_##field(vport, val); \
  904. return count; \
  905. }
  906. #define fc_vport_store_str_function(field, slen) \
  907. static ssize_t \
  908. store_fc_vport_##field(struct device *dev, \
  909. struct device_attribute *attr, \
  910. const char *buf, size_t count) \
  911. { \
  912. struct fc_vport *vport = transport_class_to_vport(dev); \
  913. struct Scsi_Host *shost = vport_to_shost(vport); \
  914. struct fc_internal *i = to_fc_internal(shost->transportt); \
  915. unsigned int cnt=count; \
  916. \
  917. /* count may include a LF at end of string */ \
  918. if (buf[cnt-1] == '\n') \
  919. cnt--; \
  920. if (cnt > ((slen) - 1)) \
  921. return -EINVAL; \
  922. memcpy(vport->field, buf, cnt); \
  923. i->f->set_vport_##field(vport); \
  924. return count; \
  925. }
  926. #define fc_vport_rd_attr(field, format_string, sz) \
  927. fc_vport_show_function(field, format_string, sz, ) \
  928. static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
  929. show_fc_vport_##field, NULL)
  930. #define fc_vport_rd_attr_cast(field, format_string, sz, cast) \
  931. fc_vport_show_function(field, format_string, sz, (cast)) \
  932. static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
  933. show_fc_vport_##field, NULL)
  934. #define fc_vport_rw_attr(field, format_string, sz) \
  935. fc_vport_show_function(field, format_string, sz, ) \
  936. fc_vport_store_function(field) \
  937. static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \
  938. show_fc_vport_##field, \
  939. store_fc_vport_##field)
  940. #define fc_private_vport_show_function(field, format_string, sz, cast) \
  941. static ssize_t \
  942. show_fc_vport_##field (struct device *dev, \
  943. struct device_attribute *attr, char *buf) \
  944. { \
  945. struct fc_vport *vport = transport_class_to_vport(dev); \
  946. return snprintf(buf, sz, format_string, cast vport->field); \
  947. }
  948. #define fc_private_vport_store_u32_function(field) \
  949. static ssize_t \
  950. store_fc_vport_##field(struct device *dev, \
  951. struct device_attribute *attr, \
  952. const char *buf, size_t count) \
  953. { \
  954. u32 val; \
  955. struct fc_vport *vport = transport_class_to_vport(dev); \
  956. char *cp; \
  957. if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING)) \
  958. return -EBUSY; \
  959. val = simple_strtoul(buf, &cp, 0); \
  960. if (*cp && (*cp != '\n')) \
  961. return -EINVAL; \
  962. vport->field = val; \
  963. return count; \
  964. }
  965. #define fc_private_vport_rd_attr(field, format_string, sz) \
  966. fc_private_vport_show_function(field, format_string, sz, ) \
  967. static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
  968. show_fc_vport_##field, NULL)
  969. #define fc_private_vport_rd_attr_cast(field, format_string, sz, cast) \
  970. fc_private_vport_show_function(field, format_string, sz, (cast)) \
  971. static FC_DEVICE_ATTR(vport, field, S_IRUGO, \
  972. show_fc_vport_##field, NULL)
  973. #define fc_private_vport_rw_u32_attr(field, format_string, sz) \
  974. fc_private_vport_show_function(field, format_string, sz, ) \
  975. fc_private_vport_store_u32_function(field) \
  976. static FC_DEVICE_ATTR(vport, field, S_IRUGO | S_IWUSR, \
  977. show_fc_vport_##field, \
  978. store_fc_vport_##field)
  979. #define fc_private_vport_rd_enum_attr(title, maxlen) \
  980. static ssize_t \
  981. show_fc_vport_##title (struct device *dev, \
  982. struct device_attribute *attr, \
  983. char *buf) \
  984. { \
  985. struct fc_vport *vport = transport_class_to_vport(dev); \
  986. const char *name; \
  987. name = get_fc_##title##_name(vport->title); \
  988. if (!name) \
  989. return -EINVAL; \
  990. return snprintf(buf, maxlen, "%s\n", name); \
  991. } \
  992. static FC_DEVICE_ATTR(vport, title, S_IRUGO, \
  993. show_fc_vport_##title, NULL)
  994. #define SETUP_VPORT_ATTRIBUTE_RD(field) \
  995. i->private_vport_attrs[count] = device_attr_vport_##field; \
  996. i->private_vport_attrs[count].attr.mode = S_IRUGO; \
  997. i->private_vport_attrs[count].store = NULL; \
  998. i->vport_attrs[count] = &i->private_vport_attrs[count]; \
  999. if (i->f->get_##field) \
  1000. count++
  1001. /* NOTE: Above MACRO differs: checks function not show bit */
  1002. #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(field) \
  1003. i->private_vport_attrs[count] = device_attr_vport_##field; \
  1004. i->private_vport_attrs[count].attr.mode = S_IRUGO; \
  1005. i->private_vport_attrs[count].store = NULL; \
  1006. i->vport_attrs[count] = &i->private_vport_attrs[count]; \
  1007. count++
  1008. #define SETUP_VPORT_ATTRIBUTE_WR(field) \
  1009. i->private_vport_attrs[count] = device_attr_vport_##field; \
  1010. i->vport_attrs[count] = &i->private_vport_attrs[count]; \
  1011. if (i->f->field) \
  1012. count++
  1013. /* NOTE: Above MACRO differs: checks function */
  1014. #define SETUP_VPORT_ATTRIBUTE_RW(field) \
  1015. i->private_vport_attrs[count] = device_attr_vport_##field; \
  1016. if (!i->f->set_vport_##field) { \
  1017. i->private_vport_attrs[count].attr.mode = S_IRUGO; \
  1018. i->private_vport_attrs[count].store = NULL; \
  1019. } \
  1020. i->vport_attrs[count] = &i->private_vport_attrs[count]; \
  1021. count++
  1022. /* NOTE: Above MACRO differs: does not check show bit */
  1023. #define SETUP_PRIVATE_VPORT_ATTRIBUTE_RW(field) \
  1024. { \
  1025. i->private_vport_attrs[count] = device_attr_vport_##field; \
  1026. i->vport_attrs[count] = &i->private_vport_attrs[count]; \
  1027. count++; \
  1028. }
  1029. /* The FC Transport Virtual Port Attributes: */
  1030. /* Fixed Virtual Port Attributes */
  1031. /* Dynamic Virtual Port Attributes */
  1032. /* Private Virtual Port Attributes */
  1033. fc_private_vport_rd_enum_attr(vport_state, FC_VPORTSTATE_MAX_NAMELEN);
  1034. fc_private_vport_rd_enum_attr(vport_last_state, FC_VPORTSTATE_MAX_NAMELEN);
  1035. fc_private_vport_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  1036. fc_private_vport_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  1037. static ssize_t
  1038. show_fc_vport_roles (struct device *dev, struct device_attribute *attr,
  1039. char *buf)
  1040. {
  1041. struct fc_vport *vport = transport_class_to_vport(dev);
  1042. if (vport->roles == FC_PORT_ROLE_UNKNOWN)
  1043. return snprintf(buf, 20, "unknown\n");
  1044. return get_fc_port_roles_names(vport->roles, buf);
  1045. }
  1046. static FC_DEVICE_ATTR(vport, roles, S_IRUGO, show_fc_vport_roles, NULL);
  1047. fc_private_vport_rd_enum_attr(vport_type, FC_PORTTYPE_MAX_NAMELEN);
  1048. fc_private_vport_show_function(symbolic_name, "%s\n",
  1049. FC_VPORT_SYMBOLIC_NAMELEN + 1, )
  1050. fc_vport_store_str_function(symbolic_name, FC_VPORT_SYMBOLIC_NAMELEN)
  1051. static FC_DEVICE_ATTR(vport, symbolic_name, S_IRUGO | S_IWUSR,
  1052. show_fc_vport_symbolic_name, store_fc_vport_symbolic_name);
  1053. static ssize_t
  1054. store_fc_vport_delete(struct device *dev, struct device_attribute *attr,
  1055. const char *buf, size_t count)
  1056. {
  1057. struct fc_vport *vport = transport_class_to_vport(dev);
  1058. struct Scsi_Host *shost = vport_to_shost(vport);
  1059. fc_queue_work(shost, &vport->vport_delete_work);
  1060. return count;
  1061. }
  1062. static FC_DEVICE_ATTR(vport, vport_delete, S_IWUSR,
  1063. NULL, store_fc_vport_delete);
  1064. /*
  1065. * Enable/Disable vport
  1066. * Write "1" to disable, write "0" to enable
  1067. */
  1068. static ssize_t
  1069. store_fc_vport_disable(struct device *dev, struct device_attribute *attr,
  1070. const char *buf,
  1071. size_t count)
  1072. {
  1073. struct fc_vport *vport = transport_class_to_vport(dev);
  1074. struct Scsi_Host *shost = vport_to_shost(vport);
  1075. struct fc_internal *i = to_fc_internal(shost->transportt);
  1076. int stat;
  1077. if (vport->flags & (FC_VPORT_DEL | FC_VPORT_CREATING))
  1078. return -EBUSY;
  1079. if (*buf == '0') {
  1080. if (vport->vport_state != FC_VPORT_DISABLED)
  1081. return -EALREADY;
  1082. } else if (*buf == '1') {
  1083. if (vport->vport_state == FC_VPORT_DISABLED)
  1084. return -EALREADY;
  1085. } else
  1086. return -EINVAL;
  1087. stat = i->f->vport_disable(vport, ((*buf == '0') ? false : true));
  1088. return stat ? stat : count;
  1089. }
  1090. static FC_DEVICE_ATTR(vport, vport_disable, S_IWUSR,
  1091. NULL, store_fc_vport_disable);
  1092. /*
  1093. * Host Attribute Management
  1094. */
  1095. #define fc_host_show_function(field, format_string, sz, cast) \
  1096. static ssize_t \
  1097. show_fc_host_##field (struct device *dev, \
  1098. struct device_attribute *attr, char *buf) \
  1099. { \
  1100. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  1101. struct fc_internal *i = to_fc_internal(shost->transportt); \
  1102. if (i->f->get_host_##field) \
  1103. i->f->get_host_##field(shost); \
  1104. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  1105. }
  1106. #define fc_host_store_function(field) \
  1107. static ssize_t \
  1108. store_fc_host_##field(struct device *dev, \
  1109. struct device_attribute *attr, \
  1110. const char *buf, size_t count) \
  1111. { \
  1112. int val; \
  1113. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  1114. struct fc_internal *i = to_fc_internal(shost->transportt); \
  1115. char *cp; \
  1116. \
  1117. val = simple_strtoul(buf, &cp, 0); \
  1118. if (*cp && (*cp != '\n')) \
  1119. return -EINVAL; \
  1120. i->f->set_host_##field(shost, val); \
  1121. return count; \
  1122. }
  1123. #define fc_host_store_str_function(field, slen) \
  1124. static ssize_t \
  1125. store_fc_host_##field(struct device *dev, \
  1126. struct device_attribute *attr, \
  1127. const char *buf, size_t count) \
  1128. { \
  1129. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  1130. struct fc_internal *i = to_fc_internal(shost->transportt); \
  1131. unsigned int cnt=count; \
  1132. \
  1133. /* count may include a LF at end of string */ \
  1134. if (buf[cnt-1] == '\n') \
  1135. cnt--; \
  1136. if (cnt > ((slen) - 1)) \
  1137. return -EINVAL; \
  1138. memcpy(fc_host_##field(shost), buf, cnt); \
  1139. i->f->set_host_##field(shost); \
  1140. return count; \
  1141. }
  1142. #define fc_host_rd_attr(field, format_string, sz) \
  1143. fc_host_show_function(field, format_string, sz, ) \
  1144. static FC_DEVICE_ATTR(host, field, S_IRUGO, \
  1145. show_fc_host_##field, NULL)
  1146. #define fc_host_rd_attr_cast(field, format_string, sz, cast) \
  1147. fc_host_show_function(field, format_string, sz, (cast)) \
  1148. static FC_DEVICE_ATTR(host, field, S_IRUGO, \
  1149. show_fc_host_##field, NULL)
  1150. #define fc_host_rw_attr(field, format_string, sz) \
  1151. fc_host_show_function(field, format_string, sz, ) \
  1152. fc_host_store_function(field) \
  1153. static FC_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
  1154. show_fc_host_##field, \
  1155. store_fc_host_##field)
  1156. #define fc_host_rd_enum_attr(title, maxlen) \
  1157. static ssize_t \
  1158. show_fc_host_##title (struct device *dev, \
  1159. struct device_attribute *attr, char *buf) \
  1160. { \
  1161. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  1162. struct fc_internal *i = to_fc_internal(shost->transportt); \
  1163. const char *name; \
  1164. if (i->f->get_host_##title) \
  1165. i->f->get_host_##title(shost); \
  1166. name = get_fc_##title##_name(fc_host_##title(shost)); \
  1167. if (!name) \
  1168. return -EINVAL; \
  1169. return snprintf(buf, maxlen, "%s\n", name); \
  1170. } \
  1171. static FC_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
  1172. #define SETUP_HOST_ATTRIBUTE_RD(field) \
  1173. i->private_host_attrs[count] = device_attr_host_##field; \
  1174. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  1175. i->private_host_attrs[count].store = NULL; \
  1176. i->host_attrs[count] = &i->private_host_attrs[count]; \
  1177. if (i->f->show_host_##field) \
  1178. count++
  1179. #define SETUP_HOST_ATTRIBUTE_RD_NS(field) \
  1180. i->private_host_attrs[count] = device_attr_host_##field; \
  1181. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  1182. i->private_host_attrs[count].store = NULL; \
  1183. i->host_attrs[count] = &i->private_host_attrs[count]; \
  1184. count++
  1185. #define SETUP_HOST_ATTRIBUTE_RW(field) \
  1186. i->private_host_attrs[count] = device_attr_host_##field; \
  1187. if (!i->f->set_host_##field) { \
  1188. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  1189. i->private_host_attrs[count].store = NULL; \
  1190. } \
  1191. i->host_attrs[count] = &i->private_host_attrs[count]; \
  1192. if (i->f->show_host_##field) \
  1193. count++
  1194. #define fc_private_host_show_function(field, format_string, sz, cast) \
  1195. static ssize_t \
  1196. show_fc_host_##field (struct device *dev, \
  1197. struct device_attribute *attr, char *buf) \
  1198. { \
  1199. struct Scsi_Host *shost = transport_class_to_shost(dev); \
  1200. return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
  1201. }
  1202. #define fc_private_host_rd_attr(field, format_string, sz) \
  1203. fc_private_host_show_function(field, format_string, sz, ) \
  1204. static FC_DEVICE_ATTR(host, field, S_IRUGO, \
  1205. show_fc_host_##field, NULL)
  1206. #define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
  1207. fc_private_host_show_function(field, format_string, sz, (cast)) \
  1208. static FC_DEVICE_ATTR(host, field, S_IRUGO, \
  1209. show_fc_host_##field, NULL)
  1210. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
  1211. i->private_host_attrs[count] = device_attr_host_##field; \
  1212. i->private_host_attrs[count].attr.mode = S_IRUGO; \
  1213. i->private_host_attrs[count].store = NULL; \
  1214. i->host_attrs[count] = &i->private_host_attrs[count]; \
  1215. count++
  1216. #define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
  1217. { \
  1218. i->private_host_attrs[count] = device_attr_host_##field; \
  1219. i->host_attrs[count] = &i->private_host_attrs[count]; \
  1220. count++; \
  1221. }
  1222. /* Fixed Host Attributes */
  1223. static ssize_t
  1224. show_fc_host_supported_classes (struct device *dev,
  1225. struct device_attribute *attr, char *buf)
  1226. {
  1227. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1228. if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
  1229. return snprintf(buf, 20, "unspecified\n");
  1230. return get_fc_cos_names(fc_host_supported_classes(shost), buf);
  1231. }
  1232. static FC_DEVICE_ATTR(host, supported_classes, S_IRUGO,
  1233. show_fc_host_supported_classes, NULL);
  1234. static ssize_t
  1235. show_fc_host_supported_fc4s (struct device *dev,
  1236. struct device_attribute *attr, char *buf)
  1237. {
  1238. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1239. return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
  1240. }
  1241. static FC_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
  1242. show_fc_host_supported_fc4s, NULL);
  1243. static ssize_t
  1244. show_fc_host_supported_speeds (struct device *dev,
  1245. struct device_attribute *attr, char *buf)
  1246. {
  1247. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1248. if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
  1249. return snprintf(buf, 20, "unknown\n");
  1250. return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
  1251. }
  1252. static FC_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
  1253. show_fc_host_supported_speeds, NULL);
  1254. fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
  1255. fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
  1256. fc_private_host_rd_attr_cast(permanent_port_name, "0x%llx\n", 20,
  1257. unsigned long long);
  1258. fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
  1259. fc_private_host_rd_attr(max_npiv_vports, "%u\n", 20);
  1260. fc_private_host_rd_attr(serial_number, "%s\n", (FC_SERIAL_NUMBER_SIZE +1));
  1261. /* Dynamic Host Attributes */
  1262. static ssize_t
  1263. show_fc_host_active_fc4s (struct device *dev,
  1264. struct device_attribute *attr, char *buf)
  1265. {
  1266. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1267. struct fc_internal *i = to_fc_internal(shost->transportt);
  1268. if (i->f->get_host_active_fc4s)
  1269. i->f->get_host_active_fc4s(shost);
  1270. return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
  1271. }
  1272. static FC_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
  1273. show_fc_host_active_fc4s, NULL);
  1274. static ssize_t
  1275. show_fc_host_speed (struct device *dev,
  1276. struct device_attribute *attr, char *buf)
  1277. {
  1278. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1279. struct fc_internal *i = to_fc_internal(shost->transportt);
  1280. if (i->f->get_host_speed)
  1281. i->f->get_host_speed(shost);
  1282. if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
  1283. return snprintf(buf, 20, "unknown\n");
  1284. return get_fc_port_speed_names(fc_host_speed(shost), buf);
  1285. }
  1286. static FC_DEVICE_ATTR(host, speed, S_IRUGO,
  1287. show_fc_host_speed, NULL);
  1288. fc_host_rd_attr(port_id, "0x%06x\n", 20);
  1289. fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
  1290. fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
  1291. fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
  1292. fc_host_rd_attr(symbolic_name, "%s\n", FC_SYMBOLIC_NAME_SIZE + 1);
  1293. fc_private_host_show_function(system_hostname, "%s\n",
  1294. FC_SYMBOLIC_NAME_SIZE + 1, )
  1295. fc_host_store_str_function(system_hostname, FC_SYMBOLIC_NAME_SIZE)
  1296. static FC_DEVICE_ATTR(host, system_hostname, S_IRUGO | S_IWUSR,
  1297. show_fc_host_system_hostname, store_fc_host_system_hostname);
  1298. /* Private Host Attributes */
  1299. static ssize_t
  1300. show_fc_private_host_tgtid_bind_type(struct device *dev,
  1301. struct device_attribute *attr, char *buf)
  1302. {
  1303. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1304. const char *name;
  1305. name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
  1306. if (!name)
  1307. return -EINVAL;
  1308. return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
  1309. }
  1310. #define get_list_head_entry(pos, head, member) \
  1311. pos = list_entry((head)->next, typeof(*pos), member)
  1312. static ssize_t
  1313. store_fc_private_host_tgtid_bind_type(struct device *dev,
  1314. struct device_attribute *attr, const char *buf, size_t count)
  1315. {
  1316. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1317. struct fc_rport *rport;
  1318. enum fc_tgtid_binding_type val;
  1319. unsigned long flags;
  1320. if (get_fc_tgtid_bind_type_match(buf, &val))
  1321. return -EINVAL;
  1322. /* if changing bind type, purge all unused consistent bindings */
  1323. if (val != fc_host_tgtid_bind_type(shost)) {
  1324. spin_lock_irqsave(shost->host_lock, flags);
  1325. while (!list_empty(&fc_host_rport_bindings(shost))) {
  1326. get_list_head_entry(rport,
  1327. &fc_host_rport_bindings(shost), peers);
  1328. list_del(&rport->peers);
  1329. rport->port_state = FC_PORTSTATE_DELETED;
  1330. fc_queue_work(shost, &rport->rport_delete_work);
  1331. }
  1332. spin_unlock_irqrestore(shost->host_lock, flags);
  1333. }
  1334. fc_host_tgtid_bind_type(shost) = val;
  1335. return count;
  1336. }
  1337. static FC_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
  1338. show_fc_private_host_tgtid_bind_type,
  1339. store_fc_private_host_tgtid_bind_type);
  1340. static ssize_t
  1341. store_fc_private_host_issue_lip(struct device *dev,
  1342. struct device_attribute *attr, const char *buf, size_t count)
  1343. {
  1344. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1345. struct fc_internal *i = to_fc_internal(shost->transportt);
  1346. int ret;
  1347. /* ignore any data value written to the attribute */
  1348. if (i->f->issue_fc_host_lip) {
  1349. ret = i->f->issue_fc_host_lip(shost);
  1350. return ret ? ret: count;
  1351. }
  1352. return -ENOENT;
  1353. }
  1354. static FC_DEVICE_ATTR(host, issue_lip, S_IWUSR, NULL,
  1355. store_fc_private_host_issue_lip);
  1356. fc_private_host_rd_attr(npiv_vports_inuse, "%u\n", 20);
  1357. /*
  1358. * Host Statistics Management
  1359. */
  1360. /* Show a given an attribute in the statistics group */
  1361. static ssize_t
  1362. fc_stat_show(const struct device *dev, char *buf, unsigned long offset)
  1363. {
  1364. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1365. struct fc_internal *i = to_fc_internal(shost->transportt);
  1366. struct fc_host_statistics *stats;
  1367. ssize_t ret = -ENOENT;
  1368. if (offset > sizeof(struct fc_host_statistics) ||
  1369. offset % sizeof(u64) != 0)
  1370. WARN_ON(1);
  1371. if (i->f->get_fc_host_stats) {
  1372. stats = (i->f->get_fc_host_stats)(shost);
  1373. if (stats)
  1374. ret = snprintf(buf, 20, "0x%llx\n",
  1375. (unsigned long long)*(u64 *)(((u8 *) stats) + offset));
  1376. }
  1377. return ret;
  1378. }
  1379. /* generate a read-only statistics attribute */
  1380. #define fc_host_statistic(name) \
  1381. static ssize_t show_fcstat_##name(struct device *cd, \
  1382. struct device_attribute *attr, \
  1383. char *buf) \
  1384. { \
  1385. return fc_stat_show(cd, buf, \
  1386. offsetof(struct fc_host_statistics, name)); \
  1387. } \
  1388. static FC_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
  1389. fc_host_statistic(seconds_since_last_reset);
  1390. fc_host_statistic(tx_frames);
  1391. fc_host_statistic(tx_words);
  1392. fc_host_statistic(rx_frames);
  1393. fc_host_statistic(rx_words);
  1394. fc_host_statistic(lip_count);
  1395. fc_host_statistic(nos_count);
  1396. fc_host_statistic(error_frames);
  1397. fc_host_statistic(dumped_frames);
  1398. fc_host_statistic(link_failure_count);
  1399. fc_host_statistic(loss_of_sync_count);
  1400. fc_host_statistic(loss_of_signal_count);
  1401. fc_host_statistic(prim_seq_protocol_err_count);
  1402. fc_host_statistic(invalid_tx_word_count);
  1403. fc_host_statistic(invalid_crc_count);
  1404. fc_host_statistic(fcp_input_requests);
  1405. fc_host_statistic(fcp_output_requests);
  1406. fc_host_statistic(fcp_control_requests);
  1407. fc_host_statistic(fcp_input_megabytes);
  1408. fc_host_statistic(fcp_output_megabytes);
  1409. static ssize_t
  1410. fc_reset_statistics(struct device *dev, struct device_attribute *attr,
  1411. const char *buf, size_t count)
  1412. {
  1413. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1414. struct fc_internal *i = to_fc_internal(shost->transportt);
  1415. /* ignore any data value written to the attribute */
  1416. if (i->f->reset_fc_host_stats) {
  1417. i->f->reset_fc_host_stats(shost);
  1418. return count;
  1419. }
  1420. return -ENOENT;
  1421. }
  1422. static FC_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
  1423. fc_reset_statistics);
  1424. static struct attribute *fc_statistics_attrs[] = {
  1425. &device_attr_host_seconds_since_last_reset.attr,
  1426. &device_attr_host_tx_frames.attr,
  1427. &device_attr_host_tx_words.attr,
  1428. &device_attr_host_rx_frames.attr,
  1429. &device_attr_host_rx_words.attr,
  1430. &device_attr_host_lip_count.attr,
  1431. &device_attr_host_nos_count.attr,
  1432. &device_attr_host_error_frames.attr,
  1433. &device_attr_host_dumped_frames.attr,
  1434. &device_attr_host_link_failure_count.attr,
  1435. &device_attr_host_loss_of_sync_count.attr,
  1436. &device_attr_host_loss_of_signal_count.attr,
  1437. &device_attr_host_prim_seq_protocol_err_count.attr,
  1438. &device_attr_host_invalid_tx_word_count.attr,
  1439. &device_attr_host_invalid_crc_count.attr,
  1440. &device_attr_host_fcp_input_requests.attr,
  1441. &device_attr_host_fcp_output_requests.attr,
  1442. &device_attr_host_fcp_control_requests.attr,
  1443. &device_attr_host_fcp_input_megabytes.attr,
  1444. &device_attr_host_fcp_output_megabytes.attr,
  1445. &device_attr_host_reset_statistics.attr,
  1446. NULL
  1447. };
  1448. static struct attribute_group fc_statistics_group = {
  1449. .name = "statistics",
  1450. .attrs = fc_statistics_attrs,
  1451. };
  1452. /* Host Vport Attributes */
  1453. static int
  1454. fc_parse_wwn(const char *ns, u64 *nm)
  1455. {
  1456. unsigned int i, j;
  1457. u8 wwn[8];
  1458. memset(wwn, 0, sizeof(wwn));
  1459. /* Validate and store the new name */
  1460. for (i=0, j=0; i < 16; i++) {
  1461. if ((*ns >= 'a') && (*ns <= 'f'))
  1462. j = ((j << 4) | ((*ns++ -'a') + 10));
  1463. else if ((*ns >= 'A') && (*ns <= 'F'))
  1464. j = ((j << 4) | ((*ns++ -'A') + 10));
  1465. else if ((*ns >= '0') && (*ns <= '9'))
  1466. j = ((j << 4) | (*ns++ -'0'));
  1467. else
  1468. return -EINVAL;
  1469. if (i % 2) {
  1470. wwn[i/2] = j & 0xff;
  1471. j = 0;
  1472. }
  1473. }
  1474. *nm = wwn_to_u64(wwn);
  1475. return 0;
  1476. }
  1477. /*
  1478. * "Short-cut" sysfs variable to create a new vport on a FC Host.
  1479. * Input is a string of the form "<WWPN>:<WWNN>". Other attributes
  1480. * will default to a NPIV-based FCP_Initiator; The WWNs are specified
  1481. * as hex characters, and may *not* contain any prefixes (e.g. 0x, x, etc)
  1482. */
  1483. static ssize_t
  1484. store_fc_host_vport_create(struct device *dev, struct device_attribute *attr,
  1485. const char *buf, size_t count)
  1486. {
  1487. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1488. struct fc_vport_identifiers vid;
  1489. struct fc_vport *vport;
  1490. unsigned int cnt=count;
  1491. int stat;
  1492. memset(&vid, 0, sizeof(vid));
  1493. /* count may include a LF at end of string */
  1494. if (buf[cnt-1] == '\n')
  1495. cnt--;
  1496. /* validate we have enough characters for WWPN */
  1497. if ((cnt != (16+1+16)) || (buf[16] != ':'))
  1498. return -EINVAL;
  1499. stat = fc_parse_wwn(&buf[0], &vid.port_name);
  1500. if (stat)
  1501. return stat;
  1502. stat = fc_parse_wwn(&buf[17], &vid.node_name);
  1503. if (stat)
  1504. return stat;
  1505. vid.roles = FC_PORT_ROLE_FCP_INITIATOR;
  1506. vid.vport_type = FC_PORTTYPE_NPIV;
  1507. /* vid.symbolic_name is already zero/NULL's */
  1508. vid.disable = false; /* always enabled */
  1509. /* we only allow support on Channel 0 !!! */
  1510. stat = fc_vport_create(shost, 0, &shost->shost_gendev, &vid, &vport);
  1511. return stat ? stat : count;
  1512. }
  1513. static FC_DEVICE_ATTR(host, vport_create, S_IWUSR, NULL,
  1514. store_fc_host_vport_create);
  1515. /*
  1516. * "Short-cut" sysfs variable to delete a vport on a FC Host.
  1517. * Vport is identified by a string containing "<WWPN>:<WWNN>".
  1518. * The WWNs are specified as hex characters, and may *not* contain
  1519. * any prefixes (e.g. 0x, x, etc)
  1520. */
  1521. static ssize_t
  1522. store_fc_host_vport_delete(struct device *dev, struct device_attribute *attr,
  1523. const char *buf, size_t count)
  1524. {
  1525. struct Scsi_Host *shost = transport_class_to_shost(dev);
  1526. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1527. struct fc_vport *vport;
  1528. u64 wwpn, wwnn;
  1529. unsigned long flags;
  1530. unsigned int cnt=count;
  1531. int stat, match;
  1532. /* count may include a LF at end of string */
  1533. if (buf[cnt-1] == '\n')
  1534. cnt--;
  1535. /* validate we have enough characters for WWPN */
  1536. if ((cnt != (16+1+16)) || (buf[16] != ':'))
  1537. return -EINVAL;
  1538. stat = fc_parse_wwn(&buf[0], &wwpn);
  1539. if (stat)
  1540. return stat;
  1541. stat = fc_parse_wwn(&buf[17], &wwnn);
  1542. if (stat)
  1543. return stat;
  1544. spin_lock_irqsave(shost->host_lock, flags);
  1545. match = 0;
  1546. /* we only allow support on Channel 0 !!! */
  1547. list_for_each_entry(vport, &fc_host->vports, peers) {
  1548. if ((vport->channel == 0) &&
  1549. (vport->port_name == wwpn) && (vport->node_name == wwnn)) {
  1550. match = 1;
  1551. break;
  1552. }
  1553. }
  1554. spin_unlock_irqrestore(shost->host_lock, flags);
  1555. if (!match)
  1556. return -ENODEV;
  1557. stat = fc_vport_terminate(vport);
  1558. return stat ? stat : count;
  1559. }
  1560. static FC_DEVICE_ATTR(host, vport_delete, S_IWUSR, NULL,
  1561. store_fc_host_vport_delete);
  1562. static int fc_host_match(struct attribute_container *cont,
  1563. struct device *dev)
  1564. {
  1565. struct Scsi_Host *shost;
  1566. struct fc_internal *i;
  1567. if (!scsi_is_host_device(dev))
  1568. return 0;
  1569. shost = dev_to_shost(dev);
  1570. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1571. != &fc_host_class.class)
  1572. return 0;
  1573. i = to_fc_internal(shost->transportt);
  1574. return &i->t.host_attrs.ac == cont;
  1575. }
  1576. static int fc_target_match(struct attribute_container *cont,
  1577. struct device *dev)
  1578. {
  1579. struct Scsi_Host *shost;
  1580. struct fc_internal *i;
  1581. if (!scsi_is_target_device(dev))
  1582. return 0;
  1583. shost = dev_to_shost(dev->parent);
  1584. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1585. != &fc_host_class.class)
  1586. return 0;
  1587. i = to_fc_internal(shost->transportt);
  1588. return &i->t.target_attrs.ac == cont;
  1589. }
  1590. static void fc_rport_dev_release(struct device *dev)
  1591. {
  1592. struct fc_rport *rport = dev_to_rport(dev);
  1593. put_device(dev->parent);
  1594. kfree(rport);
  1595. }
  1596. int scsi_is_fc_rport(const struct device *dev)
  1597. {
  1598. return dev->release == fc_rport_dev_release;
  1599. }
  1600. EXPORT_SYMBOL(scsi_is_fc_rport);
  1601. static int fc_rport_match(struct attribute_container *cont,
  1602. struct device *dev)
  1603. {
  1604. struct Scsi_Host *shost;
  1605. struct fc_internal *i;
  1606. if (!scsi_is_fc_rport(dev))
  1607. return 0;
  1608. shost = dev_to_shost(dev->parent);
  1609. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1610. != &fc_host_class.class)
  1611. return 0;
  1612. i = to_fc_internal(shost->transportt);
  1613. return &i->rport_attr_cont.ac == cont;
  1614. }
  1615. static void fc_vport_dev_release(struct device *dev)
  1616. {
  1617. struct fc_vport *vport = dev_to_vport(dev);
  1618. put_device(dev->parent); /* release kobj parent */
  1619. kfree(vport);
  1620. }
  1621. int scsi_is_fc_vport(const struct device *dev)
  1622. {
  1623. return dev->release == fc_vport_dev_release;
  1624. }
  1625. EXPORT_SYMBOL(scsi_is_fc_vport);
  1626. static int fc_vport_match(struct attribute_container *cont,
  1627. struct device *dev)
  1628. {
  1629. struct fc_vport *vport;
  1630. struct Scsi_Host *shost;
  1631. struct fc_internal *i;
  1632. if (!scsi_is_fc_vport(dev))
  1633. return 0;
  1634. vport = dev_to_vport(dev);
  1635. shost = vport_to_shost(vport);
  1636. if (!shost->transportt || shost->transportt->host_attrs.ac.class
  1637. != &fc_host_class.class)
  1638. return 0;
  1639. i = to_fc_internal(shost->transportt);
  1640. return &i->vport_attr_cont.ac == cont;
  1641. }
  1642. /**
  1643. * fc_timed_out - FC Transport I/O timeout intercept handler
  1644. * @scmd: The SCSI command which timed out
  1645. *
  1646. * This routine protects against error handlers getting invoked while a
  1647. * rport is in a blocked state, typically due to a temporarily loss of
  1648. * connectivity. If the error handlers are allowed to proceed, requests
  1649. * to abort i/o, reset the target, etc will likely fail as there is no way
  1650. * to communicate with the device to perform the requested function. These
  1651. * failures may result in the midlayer taking the device offline, requiring
  1652. * manual intervention to restore operation.
  1653. *
  1654. * This routine, called whenever an i/o times out, validates the state of
  1655. * the underlying rport. If the rport is blocked, it returns
  1656. * EH_RESET_TIMER, which will continue to reschedule the timeout.
  1657. * Eventually, either the device will return, or devloss_tmo will fire,
  1658. * and when the timeout then fires, it will be handled normally.
  1659. * If the rport is not blocked, normal error handling continues.
  1660. *
  1661. * Notes:
  1662. * This routine assumes no locks are held on entry.
  1663. */
  1664. static enum scsi_eh_timer_return
  1665. fc_timed_out(struct scsi_cmnd *scmd)
  1666. {
  1667. struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
  1668. if (rport->port_state == FC_PORTSTATE_BLOCKED)
  1669. return EH_RESET_TIMER;
  1670. return EH_NOT_HANDLED;
  1671. }
  1672. /*
  1673. * Called by fc_user_scan to locate an rport on the shost that
  1674. * matches the channel and target id, and invoke scsi_scan_target()
  1675. * on the rport.
  1676. */
  1677. static void
  1678. fc_user_scan_tgt(struct Scsi_Host *shost, uint channel, uint id, uint lun)
  1679. {
  1680. struct fc_rport *rport;
  1681. unsigned long flags;
  1682. spin_lock_irqsave(shost->host_lock, flags);
  1683. list_for_each_entry(rport, &fc_host_rports(shost), peers) {
  1684. if (rport->scsi_target_id == -1)
  1685. continue;
  1686. if (rport->port_state != FC_PORTSTATE_ONLINE)
  1687. continue;
  1688. if ((channel == rport->channel) &&
  1689. (id == rport->scsi_target_id)) {
  1690. spin_unlock_irqrestore(shost->host_lock, flags);
  1691. scsi_scan_target(&rport->dev, channel, id, lun, 1);
  1692. return;
  1693. }
  1694. }
  1695. spin_unlock_irqrestore(shost->host_lock, flags);
  1696. }
  1697. /*
  1698. * Called via sysfs scan routines. Necessary, as the FC transport
  1699. * wants to place all target objects below the rport object. So this
  1700. * routine must invoke the scsi_scan_target() routine with the rport
  1701. * object as the parent.
  1702. */
  1703. static int
  1704. fc_user_scan(struct Scsi_Host *shost, uint channel, uint id, uint lun)
  1705. {
  1706. uint chlo, chhi;
  1707. uint tgtlo, tgthi;
  1708. if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) ||
  1709. ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) ||
  1710. ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun)))
  1711. return -EINVAL;
  1712. if (channel == SCAN_WILD_CARD) {
  1713. chlo = 0;
  1714. chhi = shost->max_channel + 1;
  1715. } else {
  1716. chlo = channel;
  1717. chhi = channel + 1;
  1718. }
  1719. if (id == SCAN_WILD_CARD) {
  1720. tgtlo = 0;
  1721. tgthi = shost->max_id;
  1722. } else {
  1723. tgtlo = id;
  1724. tgthi = id + 1;
  1725. }
  1726. for ( ; chlo < chhi; chlo++)
  1727. for ( ; tgtlo < tgthi; tgtlo++)
  1728. fc_user_scan_tgt(shost, chlo, tgtlo, lun);
  1729. return 0;
  1730. }
  1731. static int fc_tsk_mgmt_response(struct Scsi_Host *shost, u64 nexus, u64 tm_id,
  1732. int result)
  1733. {
  1734. struct fc_internal *i = to_fc_internal(shost->transportt);
  1735. return i->f->tsk_mgmt_response(shost, nexus, tm_id, result);
  1736. }
  1737. static int fc_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result)
  1738. {
  1739. struct fc_internal *i = to_fc_internal(shost->transportt);
  1740. return i->f->it_nexus_response(shost, nexus, result);
  1741. }
  1742. struct scsi_transport_template *
  1743. fc_attach_transport(struct fc_function_template *ft)
  1744. {
  1745. int count;
  1746. struct fc_internal *i = kzalloc(sizeof(struct fc_internal),
  1747. GFP_KERNEL);
  1748. if (unlikely(!i))
  1749. return NULL;
  1750. i->t.target_attrs.ac.attrs = &i->starget_attrs[0];
  1751. i->t.target_attrs.ac.class = &fc_transport_class.class;
  1752. i->t.target_attrs.ac.match = fc_target_match;
  1753. i->t.target_size = sizeof(struct fc_starget_attrs);
  1754. transport_container_register(&i->t.target_attrs);
  1755. i->t.host_attrs.ac.attrs = &i->host_attrs[0];
  1756. i->t.host_attrs.ac.class = &fc_host_class.class;
  1757. i->t.host_attrs.ac.match = fc_host_match;
  1758. i->t.host_size = sizeof(struct fc_host_attrs);
  1759. if (ft->get_fc_host_stats)
  1760. i->t.host_attrs.statistics = &fc_statistics_group;
  1761. transport_container_register(&i->t.host_attrs);
  1762. i->rport_attr_cont.ac.attrs = &i->rport_attrs[0];
  1763. i->rport_attr_cont.ac.class = &fc_rport_class.class;
  1764. i->rport_attr_cont.ac.match = fc_rport_match;
  1765. transport_container_register(&i->rport_attr_cont);
  1766. i->vport_attr_cont.ac.attrs = &i->vport_attrs[0];
  1767. i->vport_attr_cont.ac.class = &fc_vport_class.class;
  1768. i->vport_attr_cont.ac.match = fc_vport_match;
  1769. transport_container_register(&i->vport_attr_cont);
  1770. i->f = ft;
  1771. /* Transport uses the shost workq for scsi scanning */
  1772. i->t.create_work_queue = 1;
  1773. i->t.eh_timed_out = fc_timed_out;
  1774. i->t.user_scan = fc_user_scan;
  1775. /* target-mode drivers' functions */
  1776. i->t.tsk_mgmt_response = fc_tsk_mgmt_response;
  1777. i->t.it_nexus_response = fc_it_nexus_response;
  1778. /*
  1779. * Setup SCSI Target Attributes.
  1780. */
  1781. count = 0;
  1782. SETUP_STARGET_ATTRIBUTE_RD(node_name);
  1783. SETUP_STARGET_ATTRIBUTE_RD(port_name);
  1784. SETUP_STARGET_ATTRIBUTE_RD(port_id);
  1785. BUG_ON(count > FC_STARGET_NUM_ATTRS);
  1786. i->starget_attrs[count] = NULL;
  1787. /*
  1788. * Setup SCSI Host Attributes.
  1789. */
  1790. count=0;
  1791. SETUP_HOST_ATTRIBUTE_RD(node_name);
  1792. SETUP_HOST_ATTRIBUTE_RD(port_name);
  1793. SETUP_HOST_ATTRIBUTE_RD(permanent_port_name);
  1794. SETUP_HOST_ATTRIBUTE_RD(supported_classes);
  1795. SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
  1796. SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
  1797. SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
  1798. if (ft->vport_create) {
  1799. SETUP_HOST_ATTRIBUTE_RD_NS(max_npiv_vports);
  1800. SETUP_HOST_ATTRIBUTE_RD_NS(npiv_vports_inuse);
  1801. }
  1802. SETUP_HOST_ATTRIBUTE_RD(serial_number);
  1803. SETUP_HOST_ATTRIBUTE_RD(port_id);
  1804. SETUP_HOST_ATTRIBUTE_RD(port_type);
  1805. SETUP_HOST_ATTRIBUTE_RD(port_state);
  1806. SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
  1807. SETUP_HOST_ATTRIBUTE_RD(speed);
  1808. SETUP_HOST_ATTRIBUTE_RD(fabric_name);
  1809. SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
  1810. SETUP_HOST_ATTRIBUTE_RW(system_hostname);
  1811. /* Transport-managed attributes */
  1812. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
  1813. if (ft->issue_fc_host_lip)
  1814. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(issue_lip);
  1815. if (ft->vport_create)
  1816. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_create);
  1817. if (ft->vport_delete)
  1818. SETUP_PRIVATE_HOST_ATTRIBUTE_RW(vport_delete);
  1819. BUG_ON(count > FC_HOST_NUM_ATTRS);
  1820. i->host_attrs[count] = NULL;
  1821. /*
  1822. * Setup Remote Port Attributes.
  1823. */
  1824. count=0;
  1825. SETUP_RPORT_ATTRIBUTE_RD(maxframe_size);
  1826. SETUP_RPORT_ATTRIBUTE_RD(supported_classes);
  1827. SETUP_RPORT_ATTRIBUTE_RW(dev_loss_tmo);
  1828. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(node_name);
  1829. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
  1830. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
  1831. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
  1832. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
  1833. SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
  1834. if (ft->terminate_rport_io)
  1835. SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo);
  1836. BUG_ON(count > FC_RPORT_NUM_ATTRS);
  1837. i->rport_attrs[count] = NULL;
  1838. /*
  1839. * Setup Virtual Port Attributes.
  1840. */
  1841. count=0;
  1842. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_state);
  1843. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_last_state);
  1844. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(node_name);
  1845. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(port_name);
  1846. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(roles);
  1847. SETUP_PRIVATE_VPORT_ATTRIBUTE_RD(vport_type);
  1848. SETUP_VPORT_ATTRIBUTE_RW(symbolic_name);
  1849. SETUP_VPORT_ATTRIBUTE_WR(vport_delete);
  1850. SETUP_VPORT_ATTRIBUTE_WR(vport_disable);
  1851. BUG_ON(count > FC_VPORT_NUM_ATTRS);
  1852. i->vport_attrs[count] = NULL;
  1853. return &i->t;
  1854. }
  1855. EXPORT_SYMBOL(fc_attach_transport);
  1856. void fc_release_transport(struct scsi_transport_template *t)
  1857. {
  1858. struct fc_internal *i = to_fc_internal(t);
  1859. transport_container_unregister(&i->t.target_attrs);
  1860. transport_container_unregister(&i->t.host_attrs);
  1861. transport_container_unregister(&i->rport_attr_cont);
  1862. transport_container_unregister(&i->vport_attr_cont);
  1863. kfree(i);
  1864. }
  1865. EXPORT_SYMBOL(fc_release_transport);
  1866. /**
  1867. * fc_queue_work - Queue work to the fc_host workqueue.
  1868. * @shost: Pointer to Scsi_Host bound to fc_host.
  1869. * @work: Work to queue for execution.
  1870. *
  1871. * Return value:
  1872. * 1 - work queued for execution
  1873. * 0 - work is already queued
  1874. * -EINVAL - work queue doesn't exist
  1875. */
  1876. static int
  1877. fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
  1878. {
  1879. if (unlikely(!fc_host_work_q(shost))) {
  1880. printk(KERN_ERR
  1881. "ERROR: FC host '%s' attempted to queue work, "
  1882. "when no workqueue created.\n", shost->hostt->name);
  1883. dump_stack();
  1884. return -EINVAL;
  1885. }
  1886. return queue_work(fc_host_work_q(shost), work);
  1887. }
  1888. /**
  1889. * fc_flush_work - Flush a fc_host's workqueue.
  1890. * @shost: Pointer to Scsi_Host bound to fc_host.
  1891. */
  1892. static void
  1893. fc_flush_work(struct Scsi_Host *shost)
  1894. {
  1895. if (!fc_host_work_q(shost)) {
  1896. printk(KERN_ERR
  1897. "ERROR: FC host '%s' attempted to flush work, "
  1898. "when no workqueue created.\n", shost->hostt->name);
  1899. dump_stack();
  1900. return;
  1901. }
  1902. flush_workqueue(fc_host_work_q(shost));
  1903. }
  1904. /**
  1905. * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
  1906. * @shost: Pointer to Scsi_Host bound to fc_host.
  1907. * @work: Work to queue for execution.
  1908. * @delay: jiffies to delay the work queuing
  1909. *
  1910. * Return value:
  1911. * 1 on success / 0 already queued / < 0 for error
  1912. */
  1913. static int
  1914. fc_queue_devloss_work(struct Scsi_Host *shost, struct delayed_work *work,
  1915. unsigned long delay)
  1916. {
  1917. if (unlikely(!fc_host_devloss_work_q(shost))) {
  1918. printk(KERN_ERR
  1919. "ERROR: FC host '%s' attempted to queue work, "
  1920. "when no workqueue created.\n", shost->hostt->name);
  1921. dump_stack();
  1922. return -EINVAL;
  1923. }
  1924. return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay);
  1925. }
  1926. /**
  1927. * fc_flush_devloss - Flush a fc_host's devloss workqueue.
  1928. * @shost: Pointer to Scsi_Host bound to fc_host.
  1929. */
  1930. static void
  1931. fc_flush_devloss(struct Scsi_Host *shost)
  1932. {
  1933. if (!fc_host_devloss_work_q(shost)) {
  1934. printk(KERN_ERR
  1935. "ERROR: FC host '%s' attempted to flush work, "
  1936. "when no workqueue created.\n", shost->hostt->name);
  1937. dump_stack();
  1938. return;
  1939. }
  1940. flush_workqueue(fc_host_devloss_work_q(shost));
  1941. }
  1942. /**
  1943. * fc_remove_host - called to terminate any fc_transport-related elements for a scsi host.
  1944. * @shost: Which &Scsi_Host
  1945. *
  1946. * This routine is expected to be called immediately preceeding the
  1947. * a driver's call to scsi_remove_host().
  1948. *
  1949. * WARNING: A driver utilizing the fc_transport, which fails to call
  1950. * this routine prior to scsi_remove_host(), will leave dangling
  1951. * objects in /sys/class/fc_remote_ports. Access to any of these
  1952. * objects can result in a system crash !!!
  1953. *
  1954. * Notes:
  1955. * This routine assumes no locks are held on entry.
  1956. */
  1957. void
  1958. fc_remove_host(struct Scsi_Host *shost)
  1959. {
  1960. struct fc_vport *vport = NULL, *next_vport = NULL;
  1961. struct fc_rport *rport = NULL, *next_rport = NULL;
  1962. struct workqueue_struct *work_q;
  1963. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  1964. unsigned long flags;
  1965. spin_lock_irqsave(shost->host_lock, flags);
  1966. /* Remove any vports */
  1967. list_for_each_entry_safe(vport, next_vport, &fc_host->vports, peers)
  1968. fc_queue_work(shost, &vport->vport_delete_work);
  1969. /* Remove any remote ports */
  1970. list_for_each_entry_safe(rport, next_rport,
  1971. &fc_host->rports, peers) {
  1972. list_del(&rport->peers);
  1973. rport->port_state = FC_PORTSTATE_DELETED;
  1974. fc_queue_work(shost, &rport->rport_delete_work);
  1975. }
  1976. list_for_each_entry_safe(rport, next_rport,
  1977. &fc_host->rport_bindings, peers) {
  1978. list_del(&rport->peers);
  1979. rport->port_state = FC_PORTSTATE_DELETED;
  1980. fc_queue_work(shost, &rport->rport_delete_work);
  1981. }
  1982. spin_unlock_irqrestore(shost->host_lock, flags);
  1983. /* flush all scan work items */
  1984. scsi_flush_work(shost);
  1985. /* flush all stgt delete, and rport delete work items, then kill it */
  1986. if (fc_host->work_q) {
  1987. work_q = fc_host->work_q;
  1988. fc_host->work_q = NULL;
  1989. destroy_workqueue(work_q);
  1990. }
  1991. /* flush all devloss work items, then kill it */
  1992. if (fc_host->devloss_work_q) {
  1993. work_q = fc_host->devloss_work_q;
  1994. fc_host->devloss_work_q = NULL;
  1995. destroy_workqueue(work_q);
  1996. }
  1997. }
  1998. EXPORT_SYMBOL(fc_remove_host);
  1999. /**
  2000. * fc_starget_delete - called to delete the scsi decendents of an rport
  2001. * @work: remote port to be operated on.
  2002. *
  2003. * Deletes target and all sdevs.
  2004. */
  2005. static void
  2006. fc_starget_delete(struct work_struct *work)
  2007. {
  2008. struct fc_rport *rport =
  2009. container_of(work, struct fc_rport, stgt_delete_work);
  2010. struct Scsi_Host *shost = rport_to_shost(rport);
  2011. struct fc_internal *i = to_fc_internal(shost->transportt);
  2012. /* Involve the LLDD if possible to terminate all io on the rport. */
  2013. if (i->f->terminate_rport_io)
  2014. i->f->terminate_rport_io(rport);
  2015. scsi_remove_target(&rport->dev);
  2016. }
  2017. /**
  2018. * fc_rport_final_delete - finish rport termination and delete it.
  2019. * @work: remote port to be deleted.
  2020. */
  2021. static void
  2022. fc_rport_final_delete(struct work_struct *work)
  2023. {
  2024. struct fc_rport *rport =
  2025. container_of(work, struct fc_rport, rport_delete_work);
  2026. struct device *dev = &rport->dev;
  2027. struct Scsi_Host *shost = rport_to_shost(rport);
  2028. struct fc_internal *i = to_fc_internal(shost->transportt);
  2029. unsigned long flags;
  2030. /*
  2031. * if a scan is pending, flush the SCSI Host work_q so that
  2032. * that we can reclaim the rport scan work element.
  2033. */
  2034. if (rport->flags & FC_RPORT_SCAN_PENDING)
  2035. scsi_flush_work(shost);
  2036. /* involve the LLDD to terminate all pending i/o */
  2037. if (i->f->terminate_rport_io)
  2038. i->f->terminate_rport_io(rport);
  2039. /*
  2040. * Cancel any outstanding timers. These should really exist
  2041. * only when rmmod'ing the LLDD and we're asking for
  2042. * immediate termination of the rports
  2043. */
  2044. spin_lock_irqsave(shost->host_lock, flags);
  2045. if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
  2046. spin_unlock_irqrestore(shost->host_lock, flags);
  2047. if (!cancel_delayed_work(&rport->fail_io_work))
  2048. fc_flush_devloss(shost);
  2049. if (!cancel_delayed_work(&rport->dev_loss_work))
  2050. fc_flush_devloss(shost);
  2051. spin_lock_irqsave(shost->host_lock, flags);
  2052. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  2053. }
  2054. spin_unlock_irqrestore(shost->host_lock, flags);
  2055. /* Delete SCSI target and sdevs */
  2056. if (rport->scsi_target_id != -1)
  2057. fc_starget_delete(&rport->stgt_delete_work);
  2058. /*
  2059. * Notify the driver that the rport is now dead. The LLDD will
  2060. * also guarantee that any communication to the rport is terminated
  2061. */
  2062. if (i->f->dev_loss_tmo_callbk)
  2063. i->f->dev_loss_tmo_callbk(rport);
  2064. transport_remove_device(dev);
  2065. device_del(dev);
  2066. transport_destroy_device(dev);
  2067. put_device(&shost->shost_gendev); /* for fc_host->rport list */
  2068. put_device(dev); /* for self-reference */
  2069. }
  2070. /**
  2071. * fc_rport_create - allocates and creates a remote FC port.
  2072. * @shost: scsi host the remote port is connected to.
  2073. * @channel: Channel on shost port connected to.
  2074. * @ids: The world wide names, fc address, and FC4 port
  2075. * roles for the remote port.
  2076. *
  2077. * Allocates and creates the remoter port structure, including the
  2078. * class and sysfs creation.
  2079. *
  2080. * Notes:
  2081. * This routine assumes no locks are held on entry.
  2082. */
  2083. static struct fc_rport *
  2084. fc_rport_create(struct Scsi_Host *shost, int channel,
  2085. struct fc_rport_identifiers *ids)
  2086. {
  2087. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2088. struct fc_internal *fci = to_fc_internal(shost->transportt);
  2089. struct fc_rport *rport;
  2090. struct device *dev;
  2091. unsigned long flags;
  2092. int error;
  2093. size_t size;
  2094. size = (sizeof(struct fc_rport) + fci->f->dd_fcrport_size);
  2095. rport = kzalloc(size, GFP_KERNEL);
  2096. if (unlikely(!rport)) {
  2097. printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
  2098. return NULL;
  2099. }
  2100. rport->maxframe_size = -1;
  2101. rport->supported_classes = FC_COS_UNSPECIFIED;
  2102. rport->dev_loss_tmo = fc_dev_loss_tmo;
  2103. memcpy(&rport->node_name, &ids->node_name, sizeof(rport->node_name));
  2104. memcpy(&rport->port_name, &ids->port_name, sizeof(rport->port_name));
  2105. rport->port_id = ids->port_id;
  2106. rport->roles = ids->roles;
  2107. rport->port_state = FC_PORTSTATE_ONLINE;
  2108. if (fci->f->dd_fcrport_size)
  2109. rport->dd_data = &rport[1];
  2110. rport->channel = channel;
  2111. rport->fast_io_fail_tmo = -1;
  2112. INIT_DELAYED_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport);
  2113. INIT_DELAYED_WORK(&rport->fail_io_work, fc_timeout_fail_rport_io);
  2114. INIT_WORK(&rport->scan_work, fc_scsi_scan_rport);
  2115. INIT_WORK(&rport->stgt_delete_work, fc_starget_delete);
  2116. INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete);
  2117. spin_lock_irqsave(shost->host_lock, flags);
  2118. rport->number = fc_host->next_rport_number++;
  2119. if (rport->roles & FC_PORT_ROLE_FCP_TARGET)
  2120. rport->scsi_target_id = fc_host->next_target_id++;
  2121. else
  2122. rport->scsi_target_id = -1;
  2123. list_add_tail(&rport->peers, &fc_host->rports);
  2124. get_device(&shost->shost_gendev); /* for fc_host->rport list */
  2125. spin_unlock_irqrestore(shost->host_lock, flags);
  2126. dev = &rport->dev;
  2127. device_initialize(dev); /* takes self reference */
  2128. dev->parent = get_device(&shost->shost_gendev); /* parent reference */
  2129. dev->release = fc_rport_dev_release;
  2130. sprintf(dev->bus_id, "rport-%d:%d-%d",
  2131. shost->host_no, channel, rport->number);
  2132. transport_setup_device(dev);
  2133. error = device_add(dev);
  2134. if (error) {
  2135. printk(KERN_ERR "FC Remote Port device_add failed\n");
  2136. goto delete_rport;
  2137. }
  2138. transport_add_device(dev);
  2139. transport_configure_device(dev);
  2140. if (rport->roles & FC_PORT_ROLE_FCP_TARGET) {
  2141. /* initiate a scan of the target */
  2142. rport->flags |= FC_RPORT_SCAN_PENDING;
  2143. scsi_queue_work(shost, &rport->scan_work);
  2144. }
  2145. return rport;
  2146. delete_rport:
  2147. transport_destroy_device(dev);
  2148. spin_lock_irqsave(shost->host_lock, flags);
  2149. list_del(&rport->peers);
  2150. put_device(&shost->shost_gendev); /* for fc_host->rport list */
  2151. spin_unlock_irqrestore(shost->host_lock, flags);
  2152. put_device(dev->parent);
  2153. kfree(rport);
  2154. return NULL;
  2155. }
  2156. /**
  2157. * fc_remote_port_add - notify fc transport of the existence of a remote FC port.
  2158. * @shost: scsi host the remote port is connected to.
  2159. * @channel: Channel on shost port connected to.
  2160. * @ids: The world wide names, fc address, and FC4 port
  2161. * roles for the remote port.
  2162. *
  2163. * The LLDD calls this routine to notify the transport of the existence
  2164. * of a remote port. The LLDD provides the unique identifiers (wwpn,wwn)
  2165. * of the port, it's FC address (port_id), and the FC4 roles that are
  2166. * active for the port.
  2167. *
  2168. * For ports that are FCP targets (aka scsi targets), the FC transport
  2169. * maintains consistent target id bindings on behalf of the LLDD.
  2170. * A consistent target id binding is an assignment of a target id to
  2171. * a remote port identifier, which persists while the scsi host is
  2172. * attached. The remote port can disappear, then later reappear, and
  2173. * it's target id assignment remains the same. This allows for shifts
  2174. * in FC addressing (if binding by wwpn or wwnn) with no apparent
  2175. * changes to the scsi subsystem which is based on scsi host number and
  2176. * target id values. Bindings are only valid during the attachment of
  2177. * the scsi host. If the host detaches, then later re-attaches, target
  2178. * id bindings may change.
  2179. *
  2180. * This routine is responsible for returning a remote port structure.
  2181. * The routine will search the list of remote ports it maintains
  2182. * internally on behalf of consistent target id mappings. If found, the
  2183. * remote port structure will be reused. Otherwise, a new remote port
  2184. * structure will be allocated.
  2185. *
  2186. * Whenever a remote port is allocated, a new fc_remote_port class
  2187. * device is created.
  2188. *
  2189. * Should not be called from interrupt context.
  2190. *
  2191. * Notes:
  2192. * This routine assumes no locks are held on entry.
  2193. */
  2194. struct fc_rport *
  2195. fc_remote_port_add(struct Scsi_Host *shost, int channel,
  2196. struct fc_rport_identifiers *ids)
  2197. {
  2198. struct fc_internal *fci = to_fc_internal(shost->transportt);
  2199. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2200. struct fc_rport *rport;
  2201. unsigned long flags;
  2202. int match = 0;
  2203. /* ensure any stgt delete functions are done */
  2204. fc_flush_work(shost);
  2205. /*
  2206. * Search the list of "active" rports, for an rport that has been
  2207. * deleted, but we've held off the real delete while the target
  2208. * is in a "blocked" state.
  2209. */
  2210. spin_lock_irqsave(shost->host_lock, flags);
  2211. list_for_each_entry(rport, &fc_host->rports, peers) {
  2212. if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
  2213. (rport->channel == channel)) {
  2214. switch (fc_host->tgtid_bind_type) {
  2215. case FC_TGTID_BIND_BY_WWPN:
  2216. case FC_TGTID_BIND_NONE:
  2217. if (rport->port_name == ids->port_name)
  2218. match = 1;
  2219. break;
  2220. case FC_TGTID_BIND_BY_WWNN:
  2221. if (rport->node_name == ids->node_name)
  2222. match = 1;
  2223. break;
  2224. case FC_TGTID_BIND_BY_ID:
  2225. if (rport->port_id == ids->port_id)
  2226. match = 1;
  2227. break;
  2228. }
  2229. if (match) {
  2230. memcpy(&rport->node_name, &ids->node_name,
  2231. sizeof(rport->node_name));
  2232. memcpy(&rport->port_name, &ids->port_name,
  2233. sizeof(rport->port_name));
  2234. rport->port_id = ids->port_id;
  2235. rport->port_state = FC_PORTSTATE_ONLINE;
  2236. rport->roles = ids->roles;
  2237. spin_unlock_irqrestore(shost->host_lock, flags);
  2238. if (fci->f->dd_fcrport_size)
  2239. memset(rport->dd_data, 0,
  2240. fci->f->dd_fcrport_size);
  2241. /*
  2242. * If we were not a target, cancel the
  2243. * io terminate and rport timers, and
  2244. * we're done.
  2245. *
  2246. * If we were a target, but our new role
  2247. * doesn't indicate a target, leave the
  2248. * timers running expecting the role to
  2249. * change as the target fully logs in. If
  2250. * it doesn't, the target will be torn down.
  2251. *
  2252. * If we were a target, and our role shows
  2253. * we're still a target, cancel the timers
  2254. * and kick off a scan.
  2255. */
  2256. /* was a target, not in roles */
  2257. if ((rport->scsi_target_id != -1) &&
  2258. (!(ids->roles & FC_PORT_ROLE_FCP_TARGET)))
  2259. return rport;
  2260. /*
  2261. * Stop the fail io and dev_loss timers.
  2262. * If they flush, the port_state will
  2263. * be checked and will NOOP the function.
  2264. */
  2265. if (!cancel_delayed_work(&rport->fail_io_work))
  2266. fc_flush_devloss(shost);
  2267. if (!cancel_delayed_work(&rport->dev_loss_work))
  2268. fc_flush_devloss(shost);
  2269. spin_lock_irqsave(shost->host_lock, flags);
  2270. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  2271. /* if target, initiate a scan */
  2272. if (rport->scsi_target_id != -1) {
  2273. rport->flags |= FC_RPORT_SCAN_PENDING;
  2274. scsi_queue_work(shost,
  2275. &rport->scan_work);
  2276. spin_unlock_irqrestore(shost->host_lock,
  2277. flags);
  2278. scsi_target_unblock(&rport->dev);
  2279. } else
  2280. spin_unlock_irqrestore(shost->host_lock,
  2281. flags);
  2282. return rport;
  2283. }
  2284. }
  2285. }
  2286. /*
  2287. * Search the bindings array
  2288. * Note: if never a FCP target, you won't be on this list
  2289. */
  2290. if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
  2291. /* search for a matching consistent binding */
  2292. list_for_each_entry(rport, &fc_host->rport_bindings,
  2293. peers) {
  2294. if (rport->channel != channel)
  2295. continue;
  2296. switch (fc_host->tgtid_bind_type) {
  2297. case FC_TGTID_BIND_BY_WWPN:
  2298. if (rport->port_name == ids->port_name)
  2299. match = 1;
  2300. break;
  2301. case FC_TGTID_BIND_BY_WWNN:
  2302. if (rport->node_name == ids->node_name)
  2303. match = 1;
  2304. break;
  2305. case FC_TGTID_BIND_BY_ID:
  2306. if (rport->port_id == ids->port_id)
  2307. match = 1;
  2308. break;
  2309. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  2310. break;
  2311. }
  2312. if (match) {
  2313. list_move_tail(&rport->peers, &fc_host->rports);
  2314. break;
  2315. }
  2316. }
  2317. if (match) {
  2318. memcpy(&rport->node_name, &ids->node_name,
  2319. sizeof(rport->node_name));
  2320. memcpy(&rport->port_name, &ids->port_name,
  2321. sizeof(rport->port_name));
  2322. rport->port_id = ids->port_id;
  2323. rport->roles = ids->roles;
  2324. rport->port_state = FC_PORTSTATE_ONLINE;
  2325. if (fci->f->dd_fcrport_size)
  2326. memset(rport->dd_data, 0,
  2327. fci->f->dd_fcrport_size);
  2328. if (rport->roles & FC_PORT_ROLE_FCP_TARGET) {
  2329. /* initiate a scan of the target */
  2330. rport->flags |= FC_RPORT_SCAN_PENDING;
  2331. scsi_queue_work(shost, &rport->scan_work);
  2332. spin_unlock_irqrestore(shost->host_lock, flags);
  2333. scsi_target_unblock(&rport->dev);
  2334. } else
  2335. spin_unlock_irqrestore(shost->host_lock, flags);
  2336. return rport;
  2337. }
  2338. }
  2339. spin_unlock_irqrestore(shost->host_lock, flags);
  2340. /* No consistent binding found - create new remote port entry */
  2341. rport = fc_rport_create(shost, channel, ids);
  2342. return rport;
  2343. }
  2344. EXPORT_SYMBOL(fc_remote_port_add);
  2345. /**
  2346. * fc_remote_port_delete - notifies the fc transport that a remote port is no longer in existence.
  2347. * @rport: The remote port that no longer exists
  2348. *
  2349. * The LLDD calls this routine to notify the transport that a remote
  2350. * port is no longer part of the topology. Note: Although a port
  2351. * may no longer be part of the topology, it may persist in the remote
  2352. * ports displayed by the fc_host. We do this under 2 conditions:
  2353. * 1) If the port was a scsi target, we delay its deletion by "blocking" it.
  2354. * This allows the port to temporarily disappear, then reappear without
  2355. * disrupting the SCSI device tree attached to it. During the "blocked"
  2356. * period the port will still exist.
  2357. * 2) If the port was a scsi target and disappears for longer than we
  2358. * expect, we'll delete the port and the tear down the SCSI device tree
  2359. * attached to it. However, we want to semi-persist the target id assigned
  2360. * to that port if it eventually does exist. The port structure will
  2361. * remain (although with minimal information) so that the target id
  2362. * bindings remails.
  2363. *
  2364. * If the remote port is not an FCP Target, it will be fully torn down
  2365. * and deallocated, including the fc_remote_port class device.
  2366. *
  2367. * If the remote port is an FCP Target, the port will be placed in a
  2368. * temporary blocked state. From the LLDD's perspective, the rport no
  2369. * longer exists. From the SCSI midlayer's perspective, the SCSI target
  2370. * exists, but all sdevs on it are blocked from further I/O. The following
  2371. * is then expected.
  2372. *
  2373. * If the remote port does not return (signaled by a LLDD call to
  2374. * fc_remote_port_add()) within the dev_loss_tmo timeout, then the
  2375. * scsi target is removed - killing all outstanding i/o and removing the
  2376. * scsi devices attached ot it. The port structure will be marked Not
  2377. * Present and be partially cleared, leaving only enough information to
  2378. * recognize the remote port relative to the scsi target id binding if
  2379. * it later appears. The port will remain as long as there is a valid
  2380. * binding (e.g. until the user changes the binding type or unloads the
  2381. * scsi host with the binding).
  2382. *
  2383. * If the remote port returns within the dev_loss_tmo value (and matches
  2384. * according to the target id binding type), the port structure will be
  2385. * reused. If it is no longer a SCSI target, the target will be torn
  2386. * down. If it continues to be a SCSI target, then the target will be
  2387. * unblocked (allowing i/o to be resumed), and a scan will be activated
  2388. * to ensure that all luns are detected.
  2389. *
  2390. * Called from normal process context only - cannot be called from interrupt.
  2391. *
  2392. * Notes:
  2393. * This routine assumes no locks are held on entry.
  2394. */
  2395. void
  2396. fc_remote_port_delete(struct fc_rport *rport)
  2397. {
  2398. struct Scsi_Host *shost = rport_to_shost(rport);
  2399. struct fc_internal *i = to_fc_internal(shost->transportt);
  2400. int timeout = rport->dev_loss_tmo;
  2401. unsigned long flags;
  2402. /*
  2403. * No need to flush the fc_host work_q's, as all adds are synchronous.
  2404. *
  2405. * We do need to reclaim the rport scan work element, so eventually
  2406. * (in fc_rport_final_delete()) we'll flush the scsi host work_q if
  2407. * there's still a scan pending.
  2408. */
  2409. spin_lock_irqsave(shost->host_lock, flags);
  2410. if (rport->port_state != FC_PORTSTATE_ONLINE) {
  2411. spin_unlock_irqrestore(shost->host_lock, flags);
  2412. return;
  2413. }
  2414. /*
  2415. * In the past, we if this was not an FCP-Target, we would
  2416. * unconditionally just jump to deleting the rport.
  2417. * However, rports can be used as node containers by the LLDD,
  2418. * and its not appropriate to just terminate the rport at the
  2419. * first sign of a loss in connectivity. The LLDD may want to
  2420. * send ELS traffic to re-validate the login. If the rport is
  2421. * immediately deleted, it makes it inappropriate for a node
  2422. * container.
  2423. * So... we now unconditionally wait dev_loss_tmo before
  2424. * destroying an rport.
  2425. */
  2426. rport->port_state = FC_PORTSTATE_BLOCKED;
  2427. rport->flags |= FC_RPORT_DEVLOSS_PENDING;
  2428. spin_unlock_irqrestore(shost->host_lock, flags);
  2429. if (rport->roles & FC_PORT_ROLE_FCP_INITIATOR &&
  2430. shost->active_mode & MODE_TARGET)
  2431. fc_tgt_it_nexus_destroy(shost, (unsigned long)rport);
  2432. scsi_target_block(&rport->dev);
  2433. /* see if we need to kill io faster than waiting for device loss */
  2434. if ((rport->fast_io_fail_tmo != -1) &&
  2435. (rport->fast_io_fail_tmo < timeout) && (i->f->terminate_rport_io))
  2436. fc_queue_devloss_work(shost, &rport->fail_io_work,
  2437. rport->fast_io_fail_tmo * HZ);
  2438. /* cap the length the devices can be blocked until they are deleted */
  2439. fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ);
  2440. }
  2441. EXPORT_SYMBOL(fc_remote_port_delete);
  2442. /**
  2443. * fc_remote_port_rolechg - notifies the fc transport that the roles on a remote may have changed.
  2444. * @rport: The remote port that changed.
  2445. * @roles: New roles for this port.
  2446. *
  2447. * Description: The LLDD calls this routine to notify the transport that the
  2448. * roles on a remote port may have changed. The largest effect of this is
  2449. * if a port now becomes a FCP Target, it must be allocated a
  2450. * scsi target id. If the port is no longer a FCP target, any
  2451. * scsi target id value assigned to it will persist in case the
  2452. * role changes back to include FCP Target. No changes in the scsi
  2453. * midlayer will be invoked if the role changes (in the expectation
  2454. * that the role will be resumed. If it doesn't normal error processing
  2455. * will take place).
  2456. *
  2457. * Should not be called from interrupt context.
  2458. *
  2459. * Notes:
  2460. * This routine assumes no locks are held on entry.
  2461. */
  2462. void
  2463. fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
  2464. {
  2465. struct Scsi_Host *shost = rport_to_shost(rport);
  2466. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2467. unsigned long flags;
  2468. int create = 0;
  2469. int ret;
  2470. spin_lock_irqsave(shost->host_lock, flags);
  2471. if (roles & FC_PORT_ROLE_FCP_TARGET) {
  2472. if (rport->scsi_target_id == -1) {
  2473. rport->scsi_target_id = fc_host->next_target_id++;
  2474. create = 1;
  2475. } else if (!(rport->roles & FC_PORT_ROLE_FCP_TARGET))
  2476. create = 1;
  2477. } else if (shost->active_mode & MODE_TARGET) {
  2478. ret = fc_tgt_it_nexus_create(shost, (unsigned long)rport,
  2479. (char *)&rport->node_name);
  2480. if (ret)
  2481. printk(KERN_ERR "FC Remore Port tgt nexus failed %d\n",
  2482. ret);
  2483. }
  2484. rport->roles = roles;
  2485. spin_unlock_irqrestore(shost->host_lock, flags);
  2486. if (create) {
  2487. /*
  2488. * There may have been a delete timer running on the
  2489. * port. Ensure that it is cancelled as we now know
  2490. * the port is an FCP Target.
  2491. * Note: we know the rport is exists and in an online
  2492. * state as the LLDD would not have had an rport
  2493. * reference to pass us.
  2494. *
  2495. * Take no action on the del_timer failure as the state
  2496. * machine state change will validate the
  2497. * transaction.
  2498. */
  2499. if (!cancel_delayed_work(&rport->fail_io_work))
  2500. fc_flush_devloss(shost);
  2501. if (!cancel_delayed_work(&rport->dev_loss_work))
  2502. fc_flush_devloss(shost);
  2503. spin_lock_irqsave(shost->host_lock, flags);
  2504. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  2505. spin_unlock_irqrestore(shost->host_lock, flags);
  2506. /* ensure any stgt delete functions are done */
  2507. fc_flush_work(shost);
  2508. /* initiate a scan of the target */
  2509. spin_lock_irqsave(shost->host_lock, flags);
  2510. rport->flags |= FC_RPORT_SCAN_PENDING;
  2511. scsi_queue_work(shost, &rport->scan_work);
  2512. spin_unlock_irqrestore(shost->host_lock, flags);
  2513. scsi_target_unblock(&rport->dev);
  2514. }
  2515. }
  2516. EXPORT_SYMBOL(fc_remote_port_rolechg);
  2517. /**
  2518. * fc_timeout_deleted_rport - Timeout handler for a deleted remote port.
  2519. * @work: rport target that failed to reappear in the allotted time.
  2520. *
  2521. * Description: An attempt to delete a remote port blocks, and if it fails
  2522. * to return in the allotted time this gets called.
  2523. */
  2524. static void
  2525. fc_timeout_deleted_rport(struct work_struct *work)
  2526. {
  2527. struct fc_rport *rport =
  2528. container_of(work, struct fc_rport, dev_loss_work.work);
  2529. struct Scsi_Host *shost = rport_to_shost(rport);
  2530. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2531. unsigned long flags;
  2532. spin_lock_irqsave(shost->host_lock, flags);
  2533. rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
  2534. /*
  2535. * If the port is ONLINE, then it came back. If it was a SCSI
  2536. * target, validate it still is. If not, tear down the
  2537. * scsi_target on it.
  2538. */
  2539. if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
  2540. (rport->scsi_target_id != -1) &&
  2541. !(rport->roles & FC_PORT_ROLE_FCP_TARGET)) {
  2542. dev_printk(KERN_ERR, &rport->dev,
  2543. "blocked FC remote port time out: no longer"
  2544. " a FCP target, removing starget\n");
  2545. spin_unlock_irqrestore(shost->host_lock, flags);
  2546. scsi_target_unblock(&rport->dev);
  2547. fc_queue_work(shost, &rport->stgt_delete_work);
  2548. return;
  2549. }
  2550. /* NOOP state - we're flushing workq's */
  2551. if (rport->port_state != FC_PORTSTATE_BLOCKED) {
  2552. spin_unlock_irqrestore(shost->host_lock, flags);
  2553. dev_printk(KERN_ERR, &rport->dev,
  2554. "blocked FC remote port time out: leaving"
  2555. " rport%s alone\n",
  2556. (rport->scsi_target_id != -1) ? " and starget" : "");
  2557. return;
  2558. }
  2559. if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) ||
  2560. (rport->scsi_target_id == -1)) {
  2561. list_del(&rport->peers);
  2562. rport->port_state = FC_PORTSTATE_DELETED;
  2563. dev_printk(KERN_ERR, &rport->dev,
  2564. "blocked FC remote port time out: removing"
  2565. " rport%s\n",
  2566. (rport->scsi_target_id != -1) ? " and starget" : "");
  2567. fc_queue_work(shost, &rport->rport_delete_work);
  2568. spin_unlock_irqrestore(shost->host_lock, flags);
  2569. return;
  2570. }
  2571. dev_printk(KERN_ERR, &rport->dev,
  2572. "blocked FC remote port time out: removing target and "
  2573. "saving binding\n");
  2574. list_move_tail(&rport->peers, &fc_host->rport_bindings);
  2575. /*
  2576. * Note: We do not remove or clear the hostdata area. This allows
  2577. * host-specific target data to persist along with the
  2578. * scsi_target_id. It's up to the host to manage it's hostdata area.
  2579. */
  2580. /*
  2581. * Reinitialize port attributes that may change if the port comes back.
  2582. */
  2583. rport->maxframe_size = -1;
  2584. rport->supported_classes = FC_COS_UNSPECIFIED;
  2585. rport->roles = FC_PORT_ROLE_UNKNOWN;
  2586. rport->port_state = FC_PORTSTATE_NOTPRESENT;
  2587. /* remove the identifiers that aren't used in the consisting binding */
  2588. switch (fc_host->tgtid_bind_type) {
  2589. case FC_TGTID_BIND_BY_WWPN:
  2590. rport->node_name = -1;
  2591. rport->port_id = -1;
  2592. break;
  2593. case FC_TGTID_BIND_BY_WWNN:
  2594. rport->port_name = -1;
  2595. rport->port_id = -1;
  2596. break;
  2597. case FC_TGTID_BIND_BY_ID:
  2598. rport->node_name = -1;
  2599. rport->port_name = -1;
  2600. break;
  2601. case FC_TGTID_BIND_NONE: /* to keep compiler happy */
  2602. break;
  2603. }
  2604. /*
  2605. * As this only occurs if the remote port (scsi target)
  2606. * went away and didn't come back - we'll remove
  2607. * all attached scsi devices.
  2608. */
  2609. spin_unlock_irqrestore(shost->host_lock, flags);
  2610. scsi_target_unblock(&rport->dev);
  2611. fc_queue_work(shost, &rport->stgt_delete_work);
  2612. }
  2613. /**
  2614. * fc_timeout_fail_rport_io - Timeout handler for a fast io failing on a disconnected SCSI target.
  2615. * @work: rport to terminate io on.
  2616. *
  2617. * Notes: Only requests the failure of the io, not that all are flushed
  2618. * prior to returning.
  2619. */
  2620. static void
  2621. fc_timeout_fail_rport_io(struct work_struct *work)
  2622. {
  2623. struct fc_rport *rport =
  2624. container_of(work, struct fc_rport, fail_io_work.work);
  2625. struct Scsi_Host *shost = rport_to_shost(rport);
  2626. struct fc_internal *i = to_fc_internal(shost->transportt);
  2627. if (rport->port_state != FC_PORTSTATE_BLOCKED)
  2628. return;
  2629. i->f->terminate_rport_io(rport);
  2630. }
  2631. /**
  2632. * fc_scsi_scan_rport - called to perform a scsi scan on a remote port.
  2633. * @work: remote port to be scanned.
  2634. */
  2635. static void
  2636. fc_scsi_scan_rport(struct work_struct *work)
  2637. {
  2638. struct fc_rport *rport =
  2639. container_of(work, struct fc_rport, scan_work);
  2640. struct Scsi_Host *shost = rport_to_shost(rport);
  2641. struct fc_internal *i = to_fc_internal(shost->transportt);
  2642. unsigned long flags;
  2643. if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
  2644. (rport->roles & FC_PORT_ROLE_FCP_TARGET) &&
  2645. !(i->f->disable_target_scan)) {
  2646. scsi_scan_target(&rport->dev, rport->channel,
  2647. rport->scsi_target_id, SCAN_WILD_CARD, 1);
  2648. }
  2649. spin_lock_irqsave(shost->host_lock, flags);
  2650. rport->flags &= ~FC_RPORT_SCAN_PENDING;
  2651. spin_unlock_irqrestore(shost->host_lock, flags);
  2652. }
  2653. /**
  2654. * fc_vport_create - allocates and creates a FC virtual port.
  2655. * @shost: scsi host the virtual port is connected to.
  2656. * @channel: Channel on shost port connected to.
  2657. * @pdev: parent device for vport
  2658. * @ids: The world wide names, FC4 port roles, etc for
  2659. * the virtual port.
  2660. * @ret_vport: The pointer to the created vport.
  2661. *
  2662. * Allocates and creates the vport structure, calls the parent host
  2663. * to instantiate the vport, the completes w/ class and sysfs creation.
  2664. *
  2665. * Notes:
  2666. * This routine assumes no locks are held on entry.
  2667. */
  2668. static int
  2669. fc_vport_create(struct Scsi_Host *shost, int channel, struct device *pdev,
  2670. struct fc_vport_identifiers *ids, struct fc_vport **ret_vport)
  2671. {
  2672. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2673. struct fc_internal *fci = to_fc_internal(shost->transportt);
  2674. struct fc_vport *vport;
  2675. struct device *dev;
  2676. unsigned long flags;
  2677. size_t size;
  2678. int error;
  2679. *ret_vport = NULL;
  2680. if ( ! fci->f->vport_create)
  2681. return -ENOENT;
  2682. size = (sizeof(struct fc_vport) + fci->f->dd_fcvport_size);
  2683. vport = kzalloc(size, GFP_KERNEL);
  2684. if (unlikely(!vport)) {
  2685. printk(KERN_ERR "%s: allocation failure\n", __FUNCTION__);
  2686. return -ENOMEM;
  2687. }
  2688. vport->vport_state = FC_VPORT_UNKNOWN;
  2689. vport->vport_last_state = FC_VPORT_UNKNOWN;
  2690. vport->node_name = ids->node_name;
  2691. vport->port_name = ids->port_name;
  2692. vport->roles = ids->roles;
  2693. vport->vport_type = ids->vport_type;
  2694. if (fci->f->dd_fcvport_size)
  2695. vport->dd_data = &vport[1];
  2696. vport->shost = shost;
  2697. vport->channel = channel;
  2698. vport->flags = FC_VPORT_CREATING;
  2699. INIT_WORK(&vport->vport_delete_work, fc_vport_sched_delete);
  2700. spin_lock_irqsave(shost->host_lock, flags);
  2701. if (fc_host->npiv_vports_inuse >= fc_host->max_npiv_vports) {
  2702. spin_unlock_irqrestore(shost->host_lock, flags);
  2703. kfree(vport);
  2704. return -ENOSPC;
  2705. }
  2706. fc_host->npiv_vports_inuse++;
  2707. vport->number = fc_host->next_vport_number++;
  2708. list_add_tail(&vport->peers, &fc_host->vports);
  2709. get_device(&shost->shost_gendev); /* for fc_host->vport list */
  2710. spin_unlock_irqrestore(shost->host_lock, flags);
  2711. dev = &vport->dev;
  2712. device_initialize(dev); /* takes self reference */
  2713. dev->parent = get_device(pdev); /* takes parent reference */
  2714. dev->release = fc_vport_dev_release;
  2715. sprintf(dev->bus_id, "vport-%d:%d-%d",
  2716. shost->host_no, channel, vport->number);
  2717. transport_setup_device(dev);
  2718. error = device_add(dev);
  2719. if (error) {
  2720. printk(KERN_ERR "FC Virtual Port device_add failed\n");
  2721. goto delete_vport;
  2722. }
  2723. transport_add_device(dev);
  2724. transport_configure_device(dev);
  2725. error = fci->f->vport_create(vport, ids->disable);
  2726. if (error) {
  2727. printk(KERN_ERR "FC Virtual Port LLDD Create failed\n");
  2728. goto delete_vport_all;
  2729. }
  2730. /*
  2731. * if the parent isn't the physical adapter's Scsi_Host, ensure
  2732. * the Scsi_Host at least contains ia symlink to the vport.
  2733. */
  2734. if (pdev != &shost->shost_gendev) {
  2735. error = sysfs_create_link(&shost->shost_gendev.kobj,
  2736. &dev->kobj, dev->bus_id);
  2737. if (error)
  2738. printk(KERN_ERR
  2739. "%s: Cannot create vport symlinks for "
  2740. "%s, err=%d\n",
  2741. __FUNCTION__, dev->bus_id, error);
  2742. }
  2743. spin_lock_irqsave(shost->host_lock, flags);
  2744. vport->flags &= ~FC_VPORT_CREATING;
  2745. spin_unlock_irqrestore(shost->host_lock, flags);
  2746. dev_printk(KERN_NOTICE, pdev,
  2747. "%s created via shost%d channel %d\n", dev->bus_id,
  2748. shost->host_no, channel);
  2749. *ret_vport = vport;
  2750. return 0;
  2751. delete_vport_all:
  2752. transport_remove_device(dev);
  2753. device_del(dev);
  2754. delete_vport:
  2755. transport_destroy_device(dev);
  2756. spin_lock_irqsave(shost->host_lock, flags);
  2757. list_del(&vport->peers);
  2758. put_device(&shost->shost_gendev); /* for fc_host->vport list */
  2759. fc_host->npiv_vports_inuse--;
  2760. spin_unlock_irqrestore(shost->host_lock, flags);
  2761. put_device(dev->parent);
  2762. kfree(vport);
  2763. return error;
  2764. }
  2765. /**
  2766. * fc_vport_terminate - Admin App or LLDD requests termination of a vport
  2767. * @vport: fc_vport to be terminated
  2768. *
  2769. * Calls the LLDD vport_delete() function, then deallocates and removes
  2770. * the vport from the shost and object tree.
  2771. *
  2772. * Notes:
  2773. * This routine assumes no locks are held on entry.
  2774. */
  2775. int
  2776. fc_vport_terminate(struct fc_vport *vport)
  2777. {
  2778. struct Scsi_Host *shost = vport_to_shost(vport);
  2779. struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
  2780. struct fc_internal *i = to_fc_internal(shost->transportt);
  2781. struct device *dev = &vport->dev;
  2782. unsigned long flags;
  2783. int stat;
  2784. spin_lock_irqsave(shost->host_lock, flags);
  2785. if (vport->flags & FC_VPORT_CREATING) {
  2786. spin_unlock_irqrestore(shost->host_lock, flags);
  2787. return -EBUSY;
  2788. }
  2789. if (vport->flags & (FC_VPORT_DEL)) {
  2790. spin_unlock_irqrestore(shost->host_lock, flags);
  2791. return -EALREADY;
  2792. }
  2793. vport->flags |= FC_VPORT_DELETING;
  2794. spin_unlock_irqrestore(shost->host_lock, flags);
  2795. if (i->f->vport_delete)
  2796. stat = i->f->vport_delete(vport);
  2797. else
  2798. stat = -ENOENT;
  2799. spin_lock_irqsave(shost->host_lock, flags);
  2800. vport->flags &= ~FC_VPORT_DELETING;
  2801. if (!stat) {
  2802. vport->flags |= FC_VPORT_DELETED;
  2803. list_del(&vport->peers);
  2804. fc_host->npiv_vports_inuse--;
  2805. put_device(&shost->shost_gendev); /* for fc_host->vport list */
  2806. }
  2807. spin_unlock_irqrestore(shost->host_lock, flags);
  2808. if (stat)
  2809. return stat;
  2810. if (dev->parent != &shost->shost_gendev)
  2811. sysfs_remove_link(&shost->shost_gendev.kobj, dev->bus_id);
  2812. transport_remove_device(dev);
  2813. device_del(dev);
  2814. transport_destroy_device(dev);
  2815. /*
  2816. * Removing our self-reference should mean our
  2817. * release function gets called, which will drop the remaining
  2818. * parent reference and free the data structure.
  2819. */
  2820. put_device(dev); /* for self-reference */
  2821. return 0; /* SUCCESS */
  2822. }
  2823. EXPORT_SYMBOL(fc_vport_terminate);
  2824. /**
  2825. * fc_vport_sched_delete - workq-based delete request for a vport
  2826. * @work: vport to be deleted.
  2827. */
  2828. static void
  2829. fc_vport_sched_delete(struct work_struct *work)
  2830. {
  2831. struct fc_vport *vport =
  2832. container_of(work, struct fc_vport, vport_delete_work);
  2833. int stat;
  2834. stat = fc_vport_terminate(vport);
  2835. if (stat)
  2836. dev_printk(KERN_ERR, vport->dev.parent,
  2837. "%s: %s could not be deleted created via "
  2838. "shost%d channel %d - error %d\n", __FUNCTION__,
  2839. vport->dev.bus_id, vport->shost->host_no,
  2840. vport->channel, stat);
  2841. }
  2842. /* Original Author: Martin Hicks */
  2843. MODULE_AUTHOR("James Smart");
  2844. MODULE_DESCRIPTION("FC Transport Attributes");
  2845. MODULE_LICENSE("GPL");
  2846. module_init(fc_transport_init);
  2847. module_exit(fc_transport_exit);