scsi_transport_fc.c 100 KB

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