scsi_transport_fc.c 99 KB

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