ibmvfc.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188
  1. /*
  2. * ibmvfc.c -- driver for IBM Power Virtual Fibre Channel Adapter
  3. *
  4. * Written By: Brian King <brking@linux.vnet.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) IBM Corporation, 2008
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/dmapool.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kthread.h>
  30. #include <linux/of.h>
  31. #include <linux/stringify.h>
  32. #include <asm/firmware.h>
  33. #include <asm/irq.h>
  34. #include <asm/vio.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_host.h>
  38. #include <scsi/scsi_device.h>
  39. #include <scsi/scsi_tcq.h>
  40. #include <scsi/scsi_transport_fc.h>
  41. #include "ibmvfc.h"
  42. static unsigned int init_timeout = IBMVFC_INIT_TIMEOUT;
  43. static unsigned int default_timeout = IBMVFC_DEFAULT_TIMEOUT;
  44. static unsigned int max_lun = IBMVFC_MAX_LUN;
  45. static unsigned int max_targets = IBMVFC_MAX_TARGETS;
  46. static unsigned int max_requests = IBMVFC_MAX_REQUESTS_DEFAULT;
  47. static unsigned int disc_threads = IBMVFC_MAX_DISC_THREADS;
  48. static unsigned int dev_loss_tmo = IBMVFC_DEV_LOSS_TMO;
  49. static unsigned int ibmvfc_debug = IBMVFC_DEBUG;
  50. static unsigned int log_level = IBMVFC_DEFAULT_LOG_LEVEL;
  51. static LIST_HEAD(ibmvfc_head);
  52. static DEFINE_SPINLOCK(ibmvfc_driver_lock);
  53. static struct scsi_transport_template *ibmvfc_transport_template;
  54. MODULE_DESCRIPTION("IBM Virtual Fibre Channel Driver");
  55. MODULE_AUTHOR("Brian King <brking@linux.vnet.ibm.com>");
  56. MODULE_LICENSE("GPL");
  57. MODULE_VERSION(IBMVFC_DRIVER_VERSION);
  58. module_param_named(init_timeout, init_timeout, uint, S_IRUGO | S_IWUSR);
  59. MODULE_PARM_DESC(init_timeout, "Initialization timeout in seconds. "
  60. "[Default=" __stringify(IBMVFC_INIT_TIMEOUT) "]");
  61. module_param_named(default_timeout, default_timeout, uint, S_IRUGO | S_IWUSR);
  62. MODULE_PARM_DESC(default_timeout,
  63. "Default timeout in seconds for initialization and EH commands. "
  64. "[Default=" __stringify(IBMVFC_DEFAULT_TIMEOUT) "]");
  65. module_param_named(max_requests, max_requests, uint, S_IRUGO);
  66. MODULE_PARM_DESC(max_requests, "Maximum requests for this adapter. "
  67. "[Default=" __stringify(IBMVFC_MAX_REQUESTS_DEFAULT) "]");
  68. module_param_named(max_lun, max_lun, uint, S_IRUGO);
  69. MODULE_PARM_DESC(max_lun, "Maximum allowed LUN. "
  70. "[Default=" __stringify(IBMVFC_MAX_LUN) "]");
  71. module_param_named(max_targets, max_targets, uint, S_IRUGO);
  72. MODULE_PARM_DESC(max_targets, "Maximum allowed targets. "
  73. "[Default=" __stringify(IBMVFC_MAX_TARGETS) "]");
  74. module_param_named(disc_threads, disc_threads, uint, S_IRUGO | S_IWUSR);
  75. MODULE_PARM_DESC(disc_threads, "Number of device discovery threads to use. "
  76. "[Default=" __stringify(IBMVFC_MAX_DISC_THREADS) "]");
  77. module_param_named(debug, ibmvfc_debug, uint, S_IRUGO | S_IWUSR);
  78. MODULE_PARM_DESC(debug, "Enable driver debug information. "
  79. "[Default=" __stringify(IBMVFC_DEBUG) "]");
  80. module_param_named(dev_loss_tmo, dev_loss_tmo, uint, S_IRUGO | S_IWUSR);
  81. MODULE_PARM_DESC(dev_loss_tmo, "Maximum number of seconds that the FC "
  82. "transport should insulate the loss of a remote port. Once this "
  83. "value is exceeded, the scsi target is removed. "
  84. "[Default=" __stringify(IBMVFC_DEV_LOSS_TMO) "]");
  85. module_param_named(log_level, log_level, uint, 0);
  86. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver. "
  87. "[Default=" __stringify(IBMVFC_DEFAULT_LOG_LEVEL) "]");
  88. static const struct {
  89. u16 status;
  90. u16 error;
  91. u8 result;
  92. u8 retry;
  93. int log;
  94. char *name;
  95. } cmd_status [] = {
  96. { IBMVFC_FABRIC_MAPPED, IBMVFC_UNABLE_TO_ESTABLISH, DID_ERROR, 1, 1, "unable to establish" },
  97. { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_FAULT, DID_OK, 1, 0, "transport fault" },
  98. { IBMVFC_FABRIC_MAPPED, IBMVFC_CMD_TIMEOUT, DID_TIME_OUT, 1, 1, "command timeout" },
  99. { IBMVFC_FABRIC_MAPPED, IBMVFC_ENETDOWN, DID_TRANSPORT_DISRUPTED, 1, 1, "network down" },
  100. { IBMVFC_FABRIC_MAPPED, IBMVFC_HW_FAILURE, DID_ERROR, 1, 1, "hardware failure" },
  101. { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_DOWN_ERR, DID_REQUEUE, 0, 0, "link down" },
  102. { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_DEAD_ERR, DID_ERROR, 0, 0, "link dead" },
  103. { IBMVFC_FABRIC_MAPPED, IBMVFC_UNABLE_TO_REGISTER, DID_ERROR, 1, 1, "unable to register" },
  104. { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_BUSY, DID_BUS_BUSY, 1, 0, "transport busy" },
  105. { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_DEAD, DID_ERROR, 0, 1, "transport dead" },
  106. { IBMVFC_FABRIC_MAPPED, IBMVFC_CONFIG_ERROR, DID_ERROR, 1, 1, "configuration error" },
  107. { IBMVFC_FABRIC_MAPPED, IBMVFC_NAME_SERVER_FAIL, DID_ERROR, 1, 1, "name server failure" },
  108. { IBMVFC_FABRIC_MAPPED, IBMVFC_LINK_HALTED, DID_REQUEUE, 0, 0, "link halted" },
  109. { IBMVFC_FABRIC_MAPPED, IBMVFC_XPORT_GENERAL, DID_OK, 1, 0, "general transport error" },
  110. { IBMVFC_VIOS_FAILURE, IBMVFC_CRQ_FAILURE, DID_REQUEUE, 1, 1, "CRQ failure" },
  111. { IBMVFC_VIOS_FAILURE, IBMVFC_SW_FAILURE, DID_ERROR, 0, 1, "software failure" },
  112. { IBMVFC_VIOS_FAILURE, IBMVFC_INVALID_PARAMETER, DID_ERROR, 0, 1, "invalid parameter" },
  113. { IBMVFC_VIOS_FAILURE, IBMVFC_MISSING_PARAMETER, DID_ERROR, 0, 1, "missing parameter" },
  114. { IBMVFC_VIOS_FAILURE, IBMVFC_HOST_IO_BUS, DID_ERROR, 1, 1, "host I/O bus failure" },
  115. { IBMVFC_VIOS_FAILURE, IBMVFC_TRANS_CANCELLED, DID_ERROR, 0, 1, "transaction cancelled" },
  116. { IBMVFC_VIOS_FAILURE, IBMVFC_TRANS_CANCELLED_IMPLICIT, DID_ERROR, 0, 1, "transaction cancelled implicit" },
  117. { IBMVFC_VIOS_FAILURE, IBMVFC_INSUFFICIENT_RESOURCE, DID_REQUEUE, 1, 1, "insufficient resources" },
  118. { IBMVFC_VIOS_FAILURE, IBMVFC_PLOGI_REQUIRED, DID_ERROR, 0, 1, "port login required" },
  119. { IBMVFC_VIOS_FAILURE, IBMVFC_COMMAND_FAILED, DID_ERROR, 1, 1, "command failed" },
  120. { IBMVFC_FC_FAILURE, IBMVFC_INVALID_ELS_CMD_CODE, DID_ERROR, 0, 1, "invalid ELS command code" },
  121. { IBMVFC_FC_FAILURE, IBMVFC_INVALID_VERSION, DID_ERROR, 0, 1, "invalid version level" },
  122. { IBMVFC_FC_FAILURE, IBMVFC_LOGICAL_ERROR, DID_ERROR, 1, 1, "logical error" },
  123. { IBMVFC_FC_FAILURE, IBMVFC_INVALID_CT_IU_SIZE, DID_ERROR, 0, 1, "invalid CT_IU size" },
  124. { IBMVFC_FC_FAILURE, IBMVFC_LOGICAL_BUSY, DID_REQUEUE, 1, 0, "logical busy" },
  125. { IBMVFC_FC_FAILURE, IBMVFC_PROTOCOL_ERROR, DID_ERROR, 1, 1, "protocol error" },
  126. { IBMVFC_FC_FAILURE, IBMVFC_UNABLE_TO_PERFORM_REQ, DID_ERROR, 1, 1, "unable to perform request" },
  127. { IBMVFC_FC_FAILURE, IBMVFC_CMD_NOT_SUPPORTED, DID_ERROR, 0, 0, "command not supported" },
  128. { IBMVFC_FC_FAILURE, IBMVFC_SERVER_NOT_AVAIL, DID_ERROR, 0, 1, "server not available" },
  129. { IBMVFC_FC_FAILURE, IBMVFC_CMD_IN_PROGRESS, DID_ERROR, 0, 1, "command already in progress" },
  130. { IBMVFC_FC_FAILURE, IBMVFC_VENDOR_SPECIFIC, DID_ERROR, 1, 1, "vendor specific" },
  131. { IBMVFC_FC_SCSI_ERROR, 0, DID_OK, 1, 0, "SCSI error" },
  132. };
  133. static void ibmvfc_npiv_login(struct ibmvfc_host *);
  134. static void ibmvfc_tgt_send_prli(struct ibmvfc_target *);
  135. static void ibmvfc_tgt_send_plogi(struct ibmvfc_target *);
  136. static void ibmvfc_tgt_query_target(struct ibmvfc_target *);
  137. static const char *unknown_error = "unknown error";
  138. #ifdef CONFIG_SCSI_IBMVFC_TRACE
  139. /**
  140. * ibmvfc_trc_start - Log a start trace entry
  141. * @evt: ibmvfc event struct
  142. *
  143. **/
  144. static void ibmvfc_trc_start(struct ibmvfc_event *evt)
  145. {
  146. struct ibmvfc_host *vhost = evt->vhost;
  147. struct ibmvfc_cmd *vfc_cmd = &evt->iu.cmd;
  148. struct ibmvfc_mad_common *mad = &evt->iu.mad_common;
  149. struct ibmvfc_trace_entry *entry;
  150. entry = &vhost->trace[vhost->trace_index++];
  151. entry->evt = evt;
  152. entry->time = jiffies;
  153. entry->fmt = evt->crq.format;
  154. entry->type = IBMVFC_TRC_START;
  155. switch (entry->fmt) {
  156. case IBMVFC_CMD_FORMAT:
  157. entry->op_code = vfc_cmd->iu.cdb[0];
  158. entry->scsi_id = vfc_cmd->tgt_scsi_id;
  159. entry->lun = scsilun_to_int(&vfc_cmd->iu.lun);
  160. entry->tmf_flags = vfc_cmd->iu.tmf_flags;
  161. entry->u.start.xfer_len = vfc_cmd->iu.xfer_len;
  162. break;
  163. case IBMVFC_MAD_FORMAT:
  164. entry->op_code = mad->opcode;
  165. break;
  166. default:
  167. break;
  168. };
  169. }
  170. /**
  171. * ibmvfc_trc_end - Log an end trace entry
  172. * @evt: ibmvfc event struct
  173. *
  174. **/
  175. static void ibmvfc_trc_end(struct ibmvfc_event *evt)
  176. {
  177. struct ibmvfc_host *vhost = evt->vhost;
  178. struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd;
  179. struct ibmvfc_mad_common *mad = &evt->xfer_iu->mad_common;
  180. struct ibmvfc_trace_entry *entry = &vhost->trace[vhost->trace_index++];
  181. entry->evt = evt;
  182. entry->time = jiffies;
  183. entry->fmt = evt->crq.format;
  184. entry->type = IBMVFC_TRC_END;
  185. switch (entry->fmt) {
  186. case IBMVFC_CMD_FORMAT:
  187. entry->op_code = vfc_cmd->iu.cdb[0];
  188. entry->scsi_id = vfc_cmd->tgt_scsi_id;
  189. entry->lun = scsilun_to_int(&vfc_cmd->iu.lun);
  190. entry->tmf_flags = vfc_cmd->iu.tmf_flags;
  191. entry->u.end.status = vfc_cmd->status;
  192. entry->u.end.error = vfc_cmd->error;
  193. entry->u.end.fcp_rsp_flags = vfc_cmd->rsp.flags;
  194. entry->u.end.rsp_code = vfc_cmd->rsp.data.info.rsp_code;
  195. entry->u.end.scsi_status = vfc_cmd->rsp.scsi_status;
  196. break;
  197. case IBMVFC_MAD_FORMAT:
  198. entry->op_code = mad->opcode;
  199. entry->u.end.status = mad->status;
  200. break;
  201. default:
  202. break;
  203. };
  204. }
  205. #else
  206. #define ibmvfc_trc_start(evt) do { } while (0)
  207. #define ibmvfc_trc_end(evt) do { } while (0)
  208. #endif
  209. /**
  210. * ibmvfc_get_err_index - Find the index into cmd_status for the fcp response
  211. * @status: status / error class
  212. * @error: error
  213. *
  214. * Return value:
  215. * index into cmd_status / -EINVAL on failure
  216. **/
  217. static int ibmvfc_get_err_index(u16 status, u16 error)
  218. {
  219. int i;
  220. for (i = 0; i < ARRAY_SIZE(cmd_status); i++)
  221. if ((cmd_status[i].status & status) == cmd_status[i].status &&
  222. cmd_status[i].error == error)
  223. return i;
  224. return -EINVAL;
  225. }
  226. /**
  227. * ibmvfc_get_cmd_error - Find the error description for the fcp response
  228. * @status: status / error class
  229. * @error: error
  230. *
  231. * Return value:
  232. * error description string
  233. **/
  234. static const char *ibmvfc_get_cmd_error(u16 status, u16 error)
  235. {
  236. int rc = ibmvfc_get_err_index(status, error);
  237. if (rc >= 0)
  238. return cmd_status[rc].name;
  239. return unknown_error;
  240. }
  241. /**
  242. * ibmvfc_get_err_result - Find the scsi status to return for the fcp response
  243. * @vfc_cmd: ibmvfc command struct
  244. *
  245. * Return value:
  246. * SCSI result value to return for completed command
  247. **/
  248. static int ibmvfc_get_err_result(struct ibmvfc_cmd *vfc_cmd)
  249. {
  250. int err;
  251. struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp;
  252. int fc_rsp_len = rsp->fcp_rsp_len;
  253. if ((rsp->flags & FCP_RSP_LEN_VALID) &&
  254. ((!fc_rsp_len && fc_rsp_len != 4 && fc_rsp_len != 8) ||
  255. rsp->data.info.rsp_code))
  256. return DID_ERROR << 16;
  257. err = ibmvfc_get_err_index(vfc_cmd->status, vfc_cmd->error);
  258. if (err >= 0)
  259. return rsp->scsi_status | (cmd_status[err].result << 16);
  260. return rsp->scsi_status | (DID_ERROR << 16);
  261. }
  262. /**
  263. * ibmvfc_retry_cmd - Determine if error status is retryable
  264. * @status: status / error class
  265. * @error: error
  266. *
  267. * Return value:
  268. * 1 if error should be retried / 0 if it should not
  269. **/
  270. static int ibmvfc_retry_cmd(u16 status, u16 error)
  271. {
  272. int rc = ibmvfc_get_err_index(status, error);
  273. if (rc >= 0)
  274. return cmd_status[rc].retry;
  275. return 1;
  276. }
  277. static const char *unknown_fc_explain = "unknown fc explain";
  278. static const struct {
  279. u16 fc_explain;
  280. char *name;
  281. } ls_explain [] = {
  282. { 0x00, "no additional explanation" },
  283. { 0x01, "service parameter error - options" },
  284. { 0x03, "service parameter error - initiator control" },
  285. { 0x05, "service parameter error - recipient control" },
  286. { 0x07, "service parameter error - received data field size" },
  287. { 0x09, "service parameter error - concurrent seq" },
  288. { 0x0B, "service parameter error - credit" },
  289. { 0x0D, "invalid N_Port/F_Port_Name" },
  290. { 0x0E, "invalid node/Fabric Name" },
  291. { 0x0F, "invalid common service parameters" },
  292. { 0x11, "invalid association header" },
  293. { 0x13, "association header required" },
  294. { 0x15, "invalid originator S_ID" },
  295. { 0x17, "invalid OX_ID-RX-ID combination" },
  296. { 0x19, "command (request) already in progress" },
  297. { 0x1E, "N_Port Login requested" },
  298. { 0x1F, "Invalid N_Port_ID" },
  299. };
  300. static const struct {
  301. u16 fc_explain;
  302. char *name;
  303. } gs_explain [] = {
  304. { 0x00, "no additional explanation" },
  305. { 0x01, "port identifier not registered" },
  306. { 0x02, "port name not registered" },
  307. { 0x03, "node name not registered" },
  308. { 0x04, "class of service not registered" },
  309. { 0x06, "initial process associator not registered" },
  310. { 0x07, "FC-4 TYPEs not registered" },
  311. { 0x08, "symbolic port name not registered" },
  312. { 0x09, "symbolic node name not registered" },
  313. { 0x0A, "port type not registered" },
  314. { 0xF0, "authorization exception" },
  315. { 0xF1, "authentication exception" },
  316. { 0xF2, "data base full" },
  317. { 0xF3, "data base empty" },
  318. { 0xF4, "processing request" },
  319. { 0xF5, "unable to verify connection" },
  320. { 0xF6, "devices not in a common zone" },
  321. };
  322. /**
  323. * ibmvfc_get_ls_explain - Return the FC Explain description text
  324. * @status: FC Explain status
  325. *
  326. * Returns:
  327. * error string
  328. **/
  329. static const char *ibmvfc_get_ls_explain(u16 status)
  330. {
  331. int i;
  332. for (i = 0; i < ARRAY_SIZE(ls_explain); i++)
  333. if (ls_explain[i].fc_explain == status)
  334. return ls_explain[i].name;
  335. return unknown_fc_explain;
  336. }
  337. /**
  338. * ibmvfc_get_gs_explain - Return the FC Explain description text
  339. * @status: FC Explain status
  340. *
  341. * Returns:
  342. * error string
  343. **/
  344. static const char *ibmvfc_get_gs_explain(u16 status)
  345. {
  346. int i;
  347. for (i = 0; i < ARRAY_SIZE(gs_explain); i++)
  348. if (gs_explain[i].fc_explain == status)
  349. return gs_explain[i].name;
  350. return unknown_fc_explain;
  351. }
  352. static const struct {
  353. enum ibmvfc_fc_type fc_type;
  354. char *name;
  355. } fc_type [] = {
  356. { IBMVFC_FABRIC_REJECT, "fabric reject" },
  357. { IBMVFC_PORT_REJECT, "port reject" },
  358. { IBMVFC_LS_REJECT, "ELS reject" },
  359. { IBMVFC_FABRIC_BUSY, "fabric busy" },
  360. { IBMVFC_PORT_BUSY, "port busy" },
  361. { IBMVFC_BASIC_REJECT, "basic reject" },
  362. };
  363. static const char *unknown_fc_type = "unknown fc type";
  364. /**
  365. * ibmvfc_get_fc_type - Return the FC Type description text
  366. * @status: FC Type error status
  367. *
  368. * Returns:
  369. * error string
  370. **/
  371. static const char *ibmvfc_get_fc_type(u16 status)
  372. {
  373. int i;
  374. for (i = 0; i < ARRAY_SIZE(fc_type); i++)
  375. if (fc_type[i].fc_type == status)
  376. return fc_type[i].name;
  377. return unknown_fc_type;
  378. }
  379. /**
  380. * ibmvfc_set_tgt_action - Set the next init action for the target
  381. * @tgt: ibmvfc target struct
  382. * @action: action to perform
  383. *
  384. **/
  385. static void ibmvfc_set_tgt_action(struct ibmvfc_target *tgt,
  386. enum ibmvfc_target_action action)
  387. {
  388. switch (tgt->action) {
  389. case IBMVFC_TGT_ACTION_DEL_RPORT:
  390. break;
  391. default:
  392. tgt->action = action;
  393. break;
  394. }
  395. }
  396. /**
  397. * ibmvfc_set_host_state - Set the state for the host
  398. * @vhost: ibmvfc host struct
  399. * @state: state to set host to
  400. *
  401. * Returns:
  402. * 0 if state changed / non-zero if not changed
  403. **/
  404. static int ibmvfc_set_host_state(struct ibmvfc_host *vhost,
  405. enum ibmvfc_host_state state)
  406. {
  407. int rc = 0;
  408. switch (vhost->state) {
  409. case IBMVFC_HOST_OFFLINE:
  410. rc = -EINVAL;
  411. break;
  412. default:
  413. vhost->state = state;
  414. break;
  415. };
  416. return rc;
  417. }
  418. /**
  419. * ibmvfc_set_host_action - Set the next init action for the host
  420. * @vhost: ibmvfc host struct
  421. * @action: action to perform
  422. *
  423. **/
  424. static void ibmvfc_set_host_action(struct ibmvfc_host *vhost,
  425. enum ibmvfc_host_action action)
  426. {
  427. switch (action) {
  428. case IBMVFC_HOST_ACTION_ALLOC_TGTS:
  429. if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT)
  430. vhost->action = action;
  431. break;
  432. case IBMVFC_HOST_ACTION_INIT_WAIT:
  433. if (vhost->action == IBMVFC_HOST_ACTION_INIT)
  434. vhost->action = action;
  435. break;
  436. case IBMVFC_HOST_ACTION_QUERY:
  437. switch (vhost->action) {
  438. case IBMVFC_HOST_ACTION_INIT_WAIT:
  439. case IBMVFC_HOST_ACTION_NONE:
  440. case IBMVFC_HOST_ACTION_TGT_ADD:
  441. vhost->action = action;
  442. break;
  443. default:
  444. break;
  445. };
  446. break;
  447. case IBMVFC_HOST_ACTION_TGT_INIT:
  448. if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS)
  449. vhost->action = action;
  450. break;
  451. case IBMVFC_HOST_ACTION_INIT:
  452. case IBMVFC_HOST_ACTION_TGT_DEL:
  453. case IBMVFC_HOST_ACTION_QUERY_TGTS:
  454. case IBMVFC_HOST_ACTION_TGT_DEL_FAILED:
  455. case IBMVFC_HOST_ACTION_TGT_ADD:
  456. case IBMVFC_HOST_ACTION_NONE:
  457. default:
  458. vhost->action = action;
  459. break;
  460. };
  461. }
  462. /**
  463. * ibmvfc_reinit_host - Re-start host initialization (no NPIV Login)
  464. * @vhost: ibmvfc host struct
  465. *
  466. * Return value:
  467. * nothing
  468. **/
  469. static void ibmvfc_reinit_host(struct ibmvfc_host *vhost)
  470. {
  471. if (vhost->action == IBMVFC_HOST_ACTION_NONE) {
  472. if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
  473. scsi_block_requests(vhost->host);
  474. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
  475. }
  476. } else
  477. vhost->reinit = 1;
  478. wake_up(&vhost->work_wait_q);
  479. }
  480. /**
  481. * ibmvfc_link_down - Handle a link down event from the adapter
  482. * @vhost: ibmvfc host struct
  483. * @state: ibmvfc host state to enter
  484. *
  485. **/
  486. static void ibmvfc_link_down(struct ibmvfc_host *vhost,
  487. enum ibmvfc_host_state state)
  488. {
  489. struct ibmvfc_target *tgt;
  490. ENTER;
  491. scsi_block_requests(vhost->host);
  492. list_for_each_entry(tgt, &vhost->targets, queue)
  493. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  494. ibmvfc_set_host_state(vhost, state);
  495. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
  496. vhost->events_to_log |= IBMVFC_AE_LINKDOWN;
  497. wake_up(&vhost->work_wait_q);
  498. LEAVE;
  499. }
  500. /**
  501. * ibmvfc_init_host - Start host initialization
  502. * @vhost: ibmvfc host struct
  503. * @relogin: is this a re-login?
  504. *
  505. * Return value:
  506. * nothing
  507. **/
  508. static void ibmvfc_init_host(struct ibmvfc_host *vhost, int relogin)
  509. {
  510. struct ibmvfc_target *tgt;
  511. if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
  512. if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
  513. dev_err(vhost->dev,
  514. "Host initialization retries exceeded. Taking adapter offline\n");
  515. ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
  516. return;
  517. }
  518. }
  519. if (!ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
  520. if (!relogin) {
  521. memset(vhost->async_crq.msgs, 0, PAGE_SIZE);
  522. vhost->async_crq.cur = 0;
  523. }
  524. list_for_each_entry(tgt, &vhost->targets, queue)
  525. tgt->need_login = 1;
  526. scsi_block_requests(vhost->host);
  527. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
  528. vhost->job_step = ibmvfc_npiv_login;
  529. wake_up(&vhost->work_wait_q);
  530. }
  531. }
  532. /**
  533. * ibmvfc_send_crq - Send a CRQ
  534. * @vhost: ibmvfc host struct
  535. * @word1: the first 64 bits of the data
  536. * @word2: the second 64 bits of the data
  537. *
  538. * Return value:
  539. * 0 on success / other on failure
  540. **/
  541. static int ibmvfc_send_crq(struct ibmvfc_host *vhost, u64 word1, u64 word2)
  542. {
  543. struct vio_dev *vdev = to_vio_dev(vhost->dev);
  544. return plpar_hcall_norets(H_SEND_CRQ, vdev->unit_address, word1, word2);
  545. }
  546. /**
  547. * ibmvfc_send_crq_init - Send a CRQ init message
  548. * @vhost: ibmvfc host struct
  549. *
  550. * Return value:
  551. * 0 on success / other on failure
  552. **/
  553. static int ibmvfc_send_crq_init(struct ibmvfc_host *vhost)
  554. {
  555. ibmvfc_dbg(vhost, "Sending CRQ init\n");
  556. return ibmvfc_send_crq(vhost, 0xC001000000000000LL, 0);
  557. }
  558. /**
  559. * ibmvfc_send_crq_init_complete - Send a CRQ init complete message
  560. * @vhost: ibmvfc host struct
  561. *
  562. * Return value:
  563. * 0 on success / other on failure
  564. **/
  565. static int ibmvfc_send_crq_init_complete(struct ibmvfc_host *vhost)
  566. {
  567. ibmvfc_dbg(vhost, "Sending CRQ init complete\n");
  568. return ibmvfc_send_crq(vhost, 0xC002000000000000LL, 0);
  569. }
  570. /**
  571. * ibmvfc_release_crq_queue - Deallocates data and unregisters CRQ
  572. * @vhost: ibmvfc host struct
  573. *
  574. * Frees irq, deallocates a page for messages, unmaps dma, and unregisters
  575. * the crq with the hypervisor.
  576. **/
  577. static void ibmvfc_release_crq_queue(struct ibmvfc_host *vhost)
  578. {
  579. long rc;
  580. struct vio_dev *vdev = to_vio_dev(vhost->dev);
  581. struct ibmvfc_crq_queue *crq = &vhost->crq;
  582. ibmvfc_dbg(vhost, "Releasing CRQ\n");
  583. free_irq(vdev->irq, vhost);
  584. do {
  585. rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
  586. } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
  587. vhost->state = IBMVFC_NO_CRQ;
  588. dma_unmap_single(vhost->dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
  589. free_page((unsigned long)crq->msgs);
  590. }
  591. /**
  592. * ibmvfc_reenable_crq_queue - reenables the CRQ
  593. * @vhost: ibmvfc host struct
  594. *
  595. * Return value:
  596. * 0 on success / other on failure
  597. **/
  598. static int ibmvfc_reenable_crq_queue(struct ibmvfc_host *vhost)
  599. {
  600. int rc;
  601. struct vio_dev *vdev = to_vio_dev(vhost->dev);
  602. /* Re-enable the CRQ */
  603. do {
  604. rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
  605. } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
  606. if (rc)
  607. dev_err(vhost->dev, "Error enabling adapter (rc=%d)\n", rc);
  608. return rc;
  609. }
  610. /**
  611. * ibmvfc_reset_crq - resets a crq after a failure
  612. * @vhost: ibmvfc host struct
  613. *
  614. * Return value:
  615. * 0 on success / other on failure
  616. **/
  617. static int ibmvfc_reset_crq(struct ibmvfc_host *vhost)
  618. {
  619. int rc;
  620. struct vio_dev *vdev = to_vio_dev(vhost->dev);
  621. struct ibmvfc_crq_queue *crq = &vhost->crq;
  622. /* Close the CRQ */
  623. do {
  624. rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
  625. } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
  626. vhost->state = IBMVFC_NO_CRQ;
  627. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
  628. /* Clean out the queue */
  629. memset(crq->msgs, 0, PAGE_SIZE);
  630. crq->cur = 0;
  631. /* And re-open it again */
  632. rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
  633. crq->msg_token, PAGE_SIZE);
  634. if (rc == H_CLOSED)
  635. /* Adapter is good, but other end is not ready */
  636. dev_warn(vhost->dev, "Partner adapter not ready\n");
  637. else if (rc != 0)
  638. dev_warn(vhost->dev, "Couldn't register crq (rc=%d)\n", rc);
  639. return rc;
  640. }
  641. /**
  642. * ibmvfc_valid_event - Determines if event is valid.
  643. * @pool: event_pool that contains the event
  644. * @evt: ibmvfc event to be checked for validity
  645. *
  646. * Return value:
  647. * 1 if event is valid / 0 if event is not valid
  648. **/
  649. static int ibmvfc_valid_event(struct ibmvfc_event_pool *pool,
  650. struct ibmvfc_event *evt)
  651. {
  652. int index = evt - pool->events;
  653. if (index < 0 || index >= pool->size) /* outside of bounds */
  654. return 0;
  655. if (evt != pool->events + index) /* unaligned */
  656. return 0;
  657. return 1;
  658. }
  659. /**
  660. * ibmvfc_free_event - Free the specified event
  661. * @evt: ibmvfc_event to be freed
  662. *
  663. **/
  664. static void ibmvfc_free_event(struct ibmvfc_event *evt)
  665. {
  666. struct ibmvfc_host *vhost = evt->vhost;
  667. struct ibmvfc_event_pool *pool = &vhost->pool;
  668. BUG_ON(!ibmvfc_valid_event(pool, evt));
  669. BUG_ON(atomic_inc_return(&evt->free) != 1);
  670. list_add_tail(&evt->queue, &vhost->free);
  671. }
  672. /**
  673. * ibmvfc_scsi_eh_done - EH done function for queuecommand commands
  674. * @evt: ibmvfc event struct
  675. *
  676. * This function does not setup any error status, that must be done
  677. * before this function gets called.
  678. **/
  679. static void ibmvfc_scsi_eh_done(struct ibmvfc_event *evt)
  680. {
  681. struct scsi_cmnd *cmnd = evt->cmnd;
  682. if (cmnd) {
  683. scsi_dma_unmap(cmnd);
  684. cmnd->scsi_done(cmnd);
  685. }
  686. if (evt->eh_comp)
  687. complete(evt->eh_comp);
  688. ibmvfc_free_event(evt);
  689. }
  690. /**
  691. * ibmvfc_fail_request - Fail request with specified error code
  692. * @evt: ibmvfc event struct
  693. * @error_code: error code to fail request with
  694. *
  695. * Return value:
  696. * none
  697. **/
  698. static void ibmvfc_fail_request(struct ibmvfc_event *evt, int error_code)
  699. {
  700. if (evt->cmnd) {
  701. evt->cmnd->result = (error_code << 16);
  702. evt->done = ibmvfc_scsi_eh_done;
  703. } else
  704. evt->xfer_iu->mad_common.status = IBMVFC_MAD_DRIVER_FAILED;
  705. list_del(&evt->queue);
  706. del_timer(&evt->timer);
  707. ibmvfc_trc_end(evt);
  708. evt->done(evt);
  709. }
  710. /**
  711. * ibmvfc_purge_requests - Our virtual adapter just shut down. Purge any sent requests
  712. * @vhost: ibmvfc host struct
  713. * @error_code: error code to fail requests with
  714. *
  715. * Return value:
  716. * none
  717. **/
  718. static void ibmvfc_purge_requests(struct ibmvfc_host *vhost, int error_code)
  719. {
  720. struct ibmvfc_event *evt, *pos;
  721. ibmvfc_dbg(vhost, "Purging all requests\n");
  722. list_for_each_entry_safe(evt, pos, &vhost->sent, queue)
  723. ibmvfc_fail_request(evt, error_code);
  724. }
  725. /**
  726. * __ibmvfc_reset_host - Reset the connection to the server (no locking)
  727. * @vhost: struct ibmvfc host to reset
  728. **/
  729. static void __ibmvfc_reset_host(struct ibmvfc_host *vhost)
  730. {
  731. int rc;
  732. scsi_block_requests(vhost->host);
  733. ibmvfc_purge_requests(vhost, DID_ERROR);
  734. if ((rc = ibmvfc_reset_crq(vhost)) ||
  735. (rc = ibmvfc_send_crq_init(vhost)) ||
  736. (rc = vio_enable_interrupts(to_vio_dev(vhost->dev)))) {
  737. dev_err(vhost->dev, "Error after reset rc=%d\n", rc);
  738. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  739. } else
  740. ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
  741. }
  742. /**
  743. * ibmvfc_reset_host - Reset the connection to the server
  744. * @vhost: struct ibmvfc host to reset
  745. **/
  746. static void ibmvfc_reset_host(struct ibmvfc_host *vhost)
  747. {
  748. unsigned long flags;
  749. spin_lock_irqsave(vhost->host->host_lock, flags);
  750. __ibmvfc_reset_host(vhost);
  751. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  752. }
  753. /**
  754. * ibmvfc_retry_host_init - Retry host initialization if allowed
  755. * @vhost: ibmvfc host struct
  756. *
  757. **/
  758. static void ibmvfc_retry_host_init(struct ibmvfc_host *vhost)
  759. {
  760. if (vhost->action == IBMVFC_HOST_ACTION_INIT_WAIT) {
  761. vhost->delay_init = 1;
  762. if (++vhost->init_retries > IBMVFC_MAX_HOST_INIT_RETRIES) {
  763. dev_err(vhost->dev,
  764. "Host initialization retries exceeded. Taking adapter offline\n");
  765. ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
  766. } else if (vhost->init_retries == IBMVFC_MAX_HOST_INIT_RETRIES)
  767. __ibmvfc_reset_host(vhost);
  768. else
  769. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
  770. }
  771. wake_up(&vhost->work_wait_q);
  772. }
  773. /**
  774. * __ibmvfc_get_target - Find the specified scsi_target (no locking)
  775. * @starget: scsi target struct
  776. *
  777. * Return value:
  778. * ibmvfc_target struct / NULL if not found
  779. **/
  780. static struct ibmvfc_target *__ibmvfc_get_target(struct scsi_target *starget)
  781. {
  782. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  783. struct ibmvfc_host *vhost = shost_priv(shost);
  784. struct ibmvfc_target *tgt;
  785. list_for_each_entry(tgt, &vhost->targets, queue)
  786. if (tgt->target_id == starget->id) {
  787. kref_get(&tgt->kref);
  788. return tgt;
  789. }
  790. return NULL;
  791. }
  792. /**
  793. * ibmvfc_get_target - Find the specified scsi_target
  794. * @starget: scsi target struct
  795. *
  796. * Return value:
  797. * ibmvfc_target struct / NULL if not found
  798. **/
  799. static struct ibmvfc_target *ibmvfc_get_target(struct scsi_target *starget)
  800. {
  801. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  802. struct ibmvfc_target *tgt;
  803. unsigned long flags;
  804. spin_lock_irqsave(shost->host_lock, flags);
  805. tgt = __ibmvfc_get_target(starget);
  806. spin_unlock_irqrestore(shost->host_lock, flags);
  807. return tgt;
  808. }
  809. /**
  810. * ibmvfc_get_host_speed - Get host port speed
  811. * @shost: scsi host struct
  812. *
  813. * Return value:
  814. * none
  815. **/
  816. static void ibmvfc_get_host_speed(struct Scsi_Host *shost)
  817. {
  818. struct ibmvfc_host *vhost = shost_priv(shost);
  819. unsigned long flags;
  820. spin_lock_irqsave(shost->host_lock, flags);
  821. if (vhost->state == IBMVFC_ACTIVE) {
  822. switch (vhost->login_buf->resp.link_speed / 100) {
  823. case 1:
  824. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  825. break;
  826. case 2:
  827. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  828. break;
  829. case 4:
  830. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  831. break;
  832. case 8:
  833. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  834. break;
  835. case 10:
  836. fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
  837. break;
  838. case 16:
  839. fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
  840. break;
  841. default:
  842. ibmvfc_log(vhost, 3, "Unknown port speed: %lld Gbit\n",
  843. vhost->login_buf->resp.link_speed / 100);
  844. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  845. break;
  846. }
  847. } else
  848. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  849. spin_unlock_irqrestore(shost->host_lock, flags);
  850. }
  851. /**
  852. * ibmvfc_get_host_port_state - Get host port state
  853. * @shost: scsi host struct
  854. *
  855. * Return value:
  856. * none
  857. **/
  858. static void ibmvfc_get_host_port_state(struct Scsi_Host *shost)
  859. {
  860. struct ibmvfc_host *vhost = shost_priv(shost);
  861. unsigned long flags;
  862. spin_lock_irqsave(shost->host_lock, flags);
  863. switch (vhost->state) {
  864. case IBMVFC_INITIALIZING:
  865. case IBMVFC_ACTIVE:
  866. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  867. break;
  868. case IBMVFC_LINK_DOWN:
  869. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  870. break;
  871. case IBMVFC_LINK_DEAD:
  872. case IBMVFC_HOST_OFFLINE:
  873. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  874. break;
  875. case IBMVFC_HALTED:
  876. fc_host_port_state(shost) = FC_PORTSTATE_BLOCKED;
  877. break;
  878. case IBMVFC_NO_CRQ:
  879. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  880. break;
  881. default:
  882. ibmvfc_log(vhost, 3, "Unknown port state: %d\n", vhost->state);
  883. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  884. break;
  885. }
  886. spin_unlock_irqrestore(shost->host_lock, flags);
  887. }
  888. /**
  889. * ibmvfc_set_rport_dev_loss_tmo - Set rport's device loss timeout
  890. * @rport: rport struct
  891. * @timeout: timeout value
  892. *
  893. * Return value:
  894. * none
  895. **/
  896. static void ibmvfc_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
  897. {
  898. if (timeout)
  899. rport->dev_loss_tmo = timeout;
  900. else
  901. rport->dev_loss_tmo = 1;
  902. }
  903. /**
  904. * ibmvfc_release_tgt - Free memory allocated for a target
  905. * @kref: kref struct
  906. *
  907. **/
  908. static void ibmvfc_release_tgt(struct kref *kref)
  909. {
  910. struct ibmvfc_target *tgt = container_of(kref, struct ibmvfc_target, kref);
  911. kfree(tgt);
  912. }
  913. /**
  914. * ibmvfc_get_starget_node_name - Get SCSI target's node name
  915. * @starget: scsi target struct
  916. *
  917. * Return value:
  918. * none
  919. **/
  920. static void ibmvfc_get_starget_node_name(struct scsi_target *starget)
  921. {
  922. struct ibmvfc_target *tgt = ibmvfc_get_target(starget);
  923. fc_starget_port_name(starget) = tgt ? tgt->ids.node_name : 0;
  924. if (tgt)
  925. kref_put(&tgt->kref, ibmvfc_release_tgt);
  926. }
  927. /**
  928. * ibmvfc_get_starget_port_name - Get SCSI target's port name
  929. * @starget: scsi target struct
  930. *
  931. * Return value:
  932. * none
  933. **/
  934. static void ibmvfc_get_starget_port_name(struct scsi_target *starget)
  935. {
  936. struct ibmvfc_target *tgt = ibmvfc_get_target(starget);
  937. fc_starget_port_name(starget) = tgt ? tgt->ids.port_name : 0;
  938. if (tgt)
  939. kref_put(&tgt->kref, ibmvfc_release_tgt);
  940. }
  941. /**
  942. * ibmvfc_get_starget_port_id - Get SCSI target's port ID
  943. * @starget: scsi target struct
  944. *
  945. * Return value:
  946. * none
  947. **/
  948. static void ibmvfc_get_starget_port_id(struct scsi_target *starget)
  949. {
  950. struct ibmvfc_target *tgt = ibmvfc_get_target(starget);
  951. fc_starget_port_id(starget) = tgt ? tgt->scsi_id : -1;
  952. if (tgt)
  953. kref_put(&tgt->kref, ibmvfc_release_tgt);
  954. }
  955. /**
  956. * ibmvfc_wait_while_resetting - Wait while the host resets
  957. * @vhost: ibmvfc host struct
  958. *
  959. * Return value:
  960. * 0 on success / other on failure
  961. **/
  962. static int ibmvfc_wait_while_resetting(struct ibmvfc_host *vhost)
  963. {
  964. long timeout = wait_event_timeout(vhost->init_wait_q,
  965. ((vhost->state == IBMVFC_ACTIVE ||
  966. vhost->state == IBMVFC_HOST_OFFLINE ||
  967. vhost->state == IBMVFC_LINK_DEAD) &&
  968. vhost->action == IBMVFC_HOST_ACTION_NONE),
  969. (init_timeout * HZ));
  970. return timeout ? 0 : -EIO;
  971. }
  972. /**
  973. * ibmvfc_issue_fc_host_lip - Re-initiate link initialization
  974. * @shost: scsi host struct
  975. *
  976. * Return value:
  977. * 0 on success / other on failure
  978. **/
  979. static int ibmvfc_issue_fc_host_lip(struct Scsi_Host *shost)
  980. {
  981. struct ibmvfc_host *vhost = shost_priv(shost);
  982. dev_err(vhost->dev, "Initiating host LIP. Resetting connection\n");
  983. ibmvfc_reset_host(vhost);
  984. return ibmvfc_wait_while_resetting(vhost);
  985. }
  986. /**
  987. * ibmvfc_gather_partition_info - Gather info about the LPAR
  988. *
  989. * Return value:
  990. * none
  991. **/
  992. static void ibmvfc_gather_partition_info(struct ibmvfc_host *vhost)
  993. {
  994. struct device_node *rootdn;
  995. const char *name;
  996. const unsigned int *num;
  997. rootdn = of_find_node_by_path("/");
  998. if (!rootdn)
  999. return;
  1000. name = of_get_property(rootdn, "ibm,partition-name", NULL);
  1001. if (name)
  1002. strncpy(vhost->partition_name, name, sizeof(vhost->partition_name));
  1003. num = of_get_property(rootdn, "ibm,partition-no", NULL);
  1004. if (num)
  1005. vhost->partition_number = *num;
  1006. of_node_put(rootdn);
  1007. }
  1008. /**
  1009. * ibmvfc_set_login_info - Setup info for NPIV login
  1010. * @vhost: ibmvfc host struct
  1011. *
  1012. * Return value:
  1013. * none
  1014. **/
  1015. static void ibmvfc_set_login_info(struct ibmvfc_host *vhost)
  1016. {
  1017. struct ibmvfc_npiv_login *login_info = &vhost->login_info;
  1018. struct device_node *of_node = vhost->dev->archdata.of_node;
  1019. const char *location;
  1020. memset(login_info, 0, sizeof(*login_info));
  1021. login_info->ostype = IBMVFC_OS_LINUX;
  1022. login_info->max_dma_len = IBMVFC_MAX_SECTORS << 9;
  1023. login_info->max_payload = sizeof(struct ibmvfc_fcp_cmd_iu);
  1024. login_info->max_response = sizeof(struct ibmvfc_fcp_rsp);
  1025. login_info->partition_num = vhost->partition_number;
  1026. login_info->vfc_frame_version = 1;
  1027. login_info->fcp_version = 3;
  1028. if (vhost->client_migrated)
  1029. login_info->flags = IBMVFC_CLIENT_MIGRATED;
  1030. login_info->max_cmds = max_requests + IBMVFC_NUM_INTERNAL_REQ;
  1031. login_info->capabilities = IBMVFC_CAN_MIGRATE;
  1032. login_info->async.va = vhost->async_crq.msg_token;
  1033. login_info->async.len = vhost->async_crq.size * sizeof(*vhost->async_crq.msgs);
  1034. strncpy(login_info->partition_name, vhost->partition_name, IBMVFC_MAX_NAME);
  1035. strncpy(login_info->device_name,
  1036. dev_name(&vhost->host->shost_gendev), IBMVFC_MAX_NAME);
  1037. location = of_get_property(of_node, "ibm,loc-code", NULL);
  1038. location = location ? location : dev_name(vhost->dev);
  1039. strncpy(login_info->drc_name, location, IBMVFC_MAX_NAME);
  1040. }
  1041. /**
  1042. * ibmvfc_init_event_pool - Allocates and initializes the event pool for a host
  1043. * @vhost: ibmvfc host who owns the event pool
  1044. *
  1045. * Returns zero on success.
  1046. **/
  1047. static int ibmvfc_init_event_pool(struct ibmvfc_host *vhost)
  1048. {
  1049. int i;
  1050. struct ibmvfc_event_pool *pool = &vhost->pool;
  1051. ENTER;
  1052. pool->size = max_requests + IBMVFC_NUM_INTERNAL_REQ;
  1053. pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL);
  1054. if (!pool->events)
  1055. return -ENOMEM;
  1056. pool->iu_storage = dma_alloc_coherent(vhost->dev,
  1057. pool->size * sizeof(*pool->iu_storage),
  1058. &pool->iu_token, 0);
  1059. if (!pool->iu_storage) {
  1060. kfree(pool->events);
  1061. return -ENOMEM;
  1062. }
  1063. for (i = 0; i < pool->size; ++i) {
  1064. struct ibmvfc_event *evt = &pool->events[i];
  1065. atomic_set(&evt->free, 1);
  1066. evt->crq.valid = 0x80;
  1067. evt->crq.ioba = pool->iu_token + (sizeof(*evt->xfer_iu) * i);
  1068. evt->xfer_iu = pool->iu_storage + i;
  1069. evt->vhost = vhost;
  1070. evt->ext_list = NULL;
  1071. list_add_tail(&evt->queue, &vhost->free);
  1072. }
  1073. LEAVE;
  1074. return 0;
  1075. }
  1076. /**
  1077. * ibmvfc_free_event_pool - Frees memory of the event pool of a host
  1078. * @vhost: ibmvfc host who owns the event pool
  1079. *
  1080. **/
  1081. static void ibmvfc_free_event_pool(struct ibmvfc_host *vhost)
  1082. {
  1083. int i;
  1084. struct ibmvfc_event_pool *pool = &vhost->pool;
  1085. ENTER;
  1086. for (i = 0; i < pool->size; ++i) {
  1087. list_del(&pool->events[i].queue);
  1088. BUG_ON(atomic_read(&pool->events[i].free) != 1);
  1089. if (pool->events[i].ext_list)
  1090. dma_pool_free(vhost->sg_pool,
  1091. pool->events[i].ext_list,
  1092. pool->events[i].ext_list_token);
  1093. }
  1094. kfree(pool->events);
  1095. dma_free_coherent(vhost->dev,
  1096. pool->size * sizeof(*pool->iu_storage),
  1097. pool->iu_storage, pool->iu_token);
  1098. LEAVE;
  1099. }
  1100. /**
  1101. * ibmvfc_get_event - Gets the next free event in pool
  1102. * @vhost: ibmvfc host struct
  1103. *
  1104. * Returns a free event from the pool.
  1105. **/
  1106. static struct ibmvfc_event *ibmvfc_get_event(struct ibmvfc_host *vhost)
  1107. {
  1108. struct ibmvfc_event *evt;
  1109. BUG_ON(list_empty(&vhost->free));
  1110. evt = list_entry(vhost->free.next, struct ibmvfc_event, queue);
  1111. atomic_set(&evt->free, 0);
  1112. list_del(&evt->queue);
  1113. return evt;
  1114. }
  1115. /**
  1116. * ibmvfc_init_event - Initialize fields in an event struct that are always
  1117. * required.
  1118. * @evt: The event
  1119. * @done: Routine to call when the event is responded to
  1120. * @format: SRP or MAD format
  1121. **/
  1122. static void ibmvfc_init_event(struct ibmvfc_event *evt,
  1123. void (*done) (struct ibmvfc_event *), u8 format)
  1124. {
  1125. evt->cmnd = NULL;
  1126. evt->sync_iu = NULL;
  1127. evt->crq.format = format;
  1128. evt->done = done;
  1129. evt->eh_comp = NULL;
  1130. }
  1131. /**
  1132. * ibmvfc_map_sg_list - Initialize scatterlist
  1133. * @scmd: scsi command struct
  1134. * @nseg: number of scatterlist segments
  1135. * @md: memory descriptor list to initialize
  1136. **/
  1137. static void ibmvfc_map_sg_list(struct scsi_cmnd *scmd, int nseg,
  1138. struct srp_direct_buf *md)
  1139. {
  1140. int i;
  1141. struct scatterlist *sg;
  1142. scsi_for_each_sg(scmd, sg, nseg, i) {
  1143. md[i].va = sg_dma_address(sg);
  1144. md[i].len = sg_dma_len(sg);
  1145. md[i].key = 0;
  1146. }
  1147. }
  1148. /**
  1149. * ibmvfc_map_sg_data - Maps dma for a scatterlist and initializes decriptor fields
  1150. * @scmd: Scsi_Cmnd with the scatterlist
  1151. * @evt: ibmvfc event struct
  1152. * @vfc_cmd: vfc_cmd that contains the memory descriptor
  1153. * @dev: device for which to map dma memory
  1154. *
  1155. * Returns:
  1156. * 0 on success / non-zero on failure
  1157. **/
  1158. static int ibmvfc_map_sg_data(struct scsi_cmnd *scmd,
  1159. struct ibmvfc_event *evt,
  1160. struct ibmvfc_cmd *vfc_cmd, struct device *dev)
  1161. {
  1162. int sg_mapped;
  1163. struct srp_direct_buf *data = &vfc_cmd->ioba;
  1164. struct ibmvfc_host *vhost = dev_get_drvdata(dev);
  1165. sg_mapped = scsi_dma_map(scmd);
  1166. if (!sg_mapped) {
  1167. vfc_cmd->flags |= IBMVFC_NO_MEM_DESC;
  1168. return 0;
  1169. } else if (unlikely(sg_mapped < 0)) {
  1170. if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
  1171. scmd_printk(KERN_ERR, scmd, "Failed to map DMA buffer for command\n");
  1172. return sg_mapped;
  1173. }
  1174. if (scmd->sc_data_direction == DMA_TO_DEVICE) {
  1175. vfc_cmd->flags |= IBMVFC_WRITE;
  1176. vfc_cmd->iu.add_cdb_len |= IBMVFC_WRDATA;
  1177. } else {
  1178. vfc_cmd->flags |= IBMVFC_READ;
  1179. vfc_cmd->iu.add_cdb_len |= IBMVFC_RDDATA;
  1180. }
  1181. if (sg_mapped == 1) {
  1182. ibmvfc_map_sg_list(scmd, sg_mapped, data);
  1183. return 0;
  1184. }
  1185. vfc_cmd->flags |= IBMVFC_SCATTERLIST;
  1186. if (!evt->ext_list) {
  1187. evt->ext_list = dma_pool_alloc(vhost->sg_pool, GFP_ATOMIC,
  1188. &evt->ext_list_token);
  1189. if (!evt->ext_list) {
  1190. scsi_dma_unmap(scmd);
  1191. if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
  1192. scmd_printk(KERN_ERR, scmd, "Can't allocate memory for scatterlist\n");
  1193. return -ENOMEM;
  1194. }
  1195. }
  1196. ibmvfc_map_sg_list(scmd, sg_mapped, evt->ext_list);
  1197. data->va = evt->ext_list_token;
  1198. data->len = sg_mapped * sizeof(struct srp_direct_buf);
  1199. data->key = 0;
  1200. return 0;
  1201. }
  1202. /**
  1203. * ibmvfc_timeout - Internal command timeout handler
  1204. * @evt: struct ibmvfc_event that timed out
  1205. *
  1206. * Called when an internally generated command times out
  1207. **/
  1208. static void ibmvfc_timeout(struct ibmvfc_event *evt)
  1209. {
  1210. struct ibmvfc_host *vhost = evt->vhost;
  1211. dev_err(vhost->dev, "Command timed out (%p). Resetting connection\n", evt);
  1212. ibmvfc_reset_host(vhost);
  1213. }
  1214. /**
  1215. * ibmvfc_send_event - Transforms event to u64 array and calls send_crq()
  1216. * @evt: event to be sent
  1217. * @vhost: ibmvfc host struct
  1218. * @timeout: timeout in seconds - 0 means do not time command
  1219. *
  1220. * Returns the value returned from ibmvfc_send_crq(). (Zero for success)
  1221. **/
  1222. static int ibmvfc_send_event(struct ibmvfc_event *evt,
  1223. struct ibmvfc_host *vhost, unsigned long timeout)
  1224. {
  1225. u64 *crq_as_u64 = (u64 *) &evt->crq;
  1226. int rc;
  1227. /* Copy the IU into the transfer area */
  1228. *evt->xfer_iu = evt->iu;
  1229. if (evt->crq.format == IBMVFC_CMD_FORMAT)
  1230. evt->xfer_iu->cmd.tag = (u64)evt;
  1231. else if (evt->crq.format == IBMVFC_MAD_FORMAT)
  1232. evt->xfer_iu->mad_common.tag = (u64)evt;
  1233. else
  1234. BUG();
  1235. list_add_tail(&evt->queue, &vhost->sent);
  1236. init_timer(&evt->timer);
  1237. if (timeout) {
  1238. evt->timer.data = (unsigned long) evt;
  1239. evt->timer.expires = jiffies + (timeout * HZ);
  1240. evt->timer.function = (void (*)(unsigned long))ibmvfc_timeout;
  1241. add_timer(&evt->timer);
  1242. }
  1243. mb();
  1244. if ((rc = ibmvfc_send_crq(vhost, crq_as_u64[0], crq_as_u64[1]))) {
  1245. list_del(&evt->queue);
  1246. del_timer(&evt->timer);
  1247. /* If send_crq returns H_CLOSED, return SCSI_MLQUEUE_HOST_BUSY.
  1248. * Firmware will send a CRQ with a transport event (0xFF) to
  1249. * tell this client what has happened to the transport. This
  1250. * will be handled in ibmvfc_handle_crq()
  1251. */
  1252. if (rc == H_CLOSED) {
  1253. if (printk_ratelimit())
  1254. dev_warn(vhost->dev, "Send warning. Receive queue closed, will retry.\n");
  1255. if (evt->cmnd)
  1256. scsi_dma_unmap(evt->cmnd);
  1257. ibmvfc_free_event(evt);
  1258. return SCSI_MLQUEUE_HOST_BUSY;
  1259. }
  1260. dev_err(vhost->dev, "Send error (rc=%d)\n", rc);
  1261. if (evt->cmnd) {
  1262. evt->cmnd->result = DID_ERROR << 16;
  1263. evt->done = ibmvfc_scsi_eh_done;
  1264. } else
  1265. evt->xfer_iu->mad_common.status = IBMVFC_MAD_CRQ_ERROR;
  1266. evt->done(evt);
  1267. } else
  1268. ibmvfc_trc_start(evt);
  1269. return 0;
  1270. }
  1271. /**
  1272. * ibmvfc_log_error - Log an error for the failed command if appropriate
  1273. * @evt: ibmvfc event to log
  1274. *
  1275. **/
  1276. static void ibmvfc_log_error(struct ibmvfc_event *evt)
  1277. {
  1278. struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd;
  1279. struct ibmvfc_host *vhost = evt->vhost;
  1280. struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp;
  1281. struct scsi_cmnd *cmnd = evt->cmnd;
  1282. const char *err = unknown_error;
  1283. int index = ibmvfc_get_err_index(vfc_cmd->status, vfc_cmd->error);
  1284. int logerr = 0;
  1285. int rsp_code = 0;
  1286. if (index >= 0) {
  1287. logerr = cmd_status[index].log;
  1288. err = cmd_status[index].name;
  1289. }
  1290. if (!logerr && (vhost->log_level <= (IBMVFC_DEFAULT_LOG_LEVEL + 1)))
  1291. return;
  1292. if (rsp->flags & FCP_RSP_LEN_VALID)
  1293. rsp_code = rsp->data.info.rsp_code;
  1294. scmd_printk(KERN_ERR, cmnd, "Command (%02X) failed: %s (%x:%x) "
  1295. "flags: %x fcp_rsp: %x, resid=%d, scsi_status: %x\n",
  1296. cmnd->cmnd[0], err, vfc_cmd->status, vfc_cmd->error,
  1297. rsp->flags, rsp_code, scsi_get_resid(cmnd), rsp->scsi_status);
  1298. }
  1299. /**
  1300. * ibmvfc_scsi_done - Handle responses from commands
  1301. * @evt: ibmvfc event to be handled
  1302. *
  1303. * Used as a callback when sending scsi cmds.
  1304. **/
  1305. static void ibmvfc_scsi_done(struct ibmvfc_event *evt)
  1306. {
  1307. struct ibmvfc_cmd *vfc_cmd = &evt->xfer_iu->cmd;
  1308. struct ibmvfc_fcp_rsp *rsp = &vfc_cmd->rsp;
  1309. struct scsi_cmnd *cmnd = evt->cmnd;
  1310. u32 rsp_len = 0;
  1311. u32 sense_len = rsp->fcp_sense_len;
  1312. if (cmnd) {
  1313. if (vfc_cmd->response_flags & IBMVFC_ADAPTER_RESID_VALID)
  1314. scsi_set_resid(cmnd, vfc_cmd->adapter_resid);
  1315. else if (rsp->flags & FCP_RESID_UNDER)
  1316. scsi_set_resid(cmnd, rsp->fcp_resid);
  1317. else
  1318. scsi_set_resid(cmnd, 0);
  1319. if (vfc_cmd->status) {
  1320. cmnd->result = ibmvfc_get_err_result(vfc_cmd);
  1321. if (rsp->flags & FCP_RSP_LEN_VALID)
  1322. rsp_len = rsp->fcp_rsp_len;
  1323. if ((sense_len + rsp_len) > SCSI_SENSE_BUFFERSIZE)
  1324. sense_len = SCSI_SENSE_BUFFERSIZE - rsp_len;
  1325. if ((rsp->flags & FCP_SNS_LEN_VALID) && rsp->fcp_sense_len && rsp_len <= 8)
  1326. memcpy(cmnd->sense_buffer, rsp->data.sense + rsp_len, sense_len);
  1327. if ((vfc_cmd->status & IBMVFC_VIOS_FAILURE) && (vfc_cmd->error == IBMVFC_PLOGI_REQUIRED))
  1328. ibmvfc_reinit_host(evt->vhost);
  1329. if (!cmnd->result && (!scsi_get_resid(cmnd) || (rsp->flags & FCP_RESID_OVER)))
  1330. cmnd->result = (DID_ERROR << 16);
  1331. ibmvfc_log_error(evt);
  1332. }
  1333. if (!cmnd->result &&
  1334. (scsi_bufflen(cmnd) - scsi_get_resid(cmnd) < cmnd->underflow))
  1335. cmnd->result = (DID_ERROR << 16);
  1336. scsi_dma_unmap(cmnd);
  1337. cmnd->scsi_done(cmnd);
  1338. }
  1339. if (evt->eh_comp)
  1340. complete(evt->eh_comp);
  1341. ibmvfc_free_event(evt);
  1342. }
  1343. /**
  1344. * ibmvfc_host_chkready - Check if the host can accept commands
  1345. * @vhost: struct ibmvfc host
  1346. *
  1347. * Returns:
  1348. * 1 if host can accept command / 0 if not
  1349. **/
  1350. static inline int ibmvfc_host_chkready(struct ibmvfc_host *vhost)
  1351. {
  1352. int result = 0;
  1353. switch (vhost->state) {
  1354. case IBMVFC_LINK_DEAD:
  1355. case IBMVFC_HOST_OFFLINE:
  1356. result = DID_NO_CONNECT << 16;
  1357. break;
  1358. case IBMVFC_NO_CRQ:
  1359. case IBMVFC_INITIALIZING:
  1360. case IBMVFC_HALTED:
  1361. case IBMVFC_LINK_DOWN:
  1362. result = DID_REQUEUE << 16;
  1363. break;
  1364. case IBMVFC_ACTIVE:
  1365. result = 0;
  1366. break;
  1367. };
  1368. return result;
  1369. }
  1370. /**
  1371. * ibmvfc_queuecommand - The queuecommand function of the scsi template
  1372. * @cmnd: struct scsi_cmnd to be executed
  1373. * @done: Callback function to be called when cmnd is completed
  1374. *
  1375. * Returns:
  1376. * 0 on success / other on failure
  1377. **/
  1378. static int ibmvfc_queuecommand(struct scsi_cmnd *cmnd,
  1379. void (*done) (struct scsi_cmnd *))
  1380. {
  1381. struct ibmvfc_host *vhost = shost_priv(cmnd->device->host);
  1382. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  1383. struct ibmvfc_cmd *vfc_cmd;
  1384. struct ibmvfc_event *evt;
  1385. u8 tag[2];
  1386. int rc;
  1387. if (unlikely((rc = fc_remote_port_chkready(rport))) ||
  1388. unlikely((rc = ibmvfc_host_chkready(vhost)))) {
  1389. cmnd->result = rc;
  1390. done(cmnd);
  1391. return 0;
  1392. }
  1393. cmnd->result = (DID_OK << 16);
  1394. evt = ibmvfc_get_event(vhost);
  1395. ibmvfc_init_event(evt, ibmvfc_scsi_done, IBMVFC_CMD_FORMAT);
  1396. evt->cmnd = cmnd;
  1397. cmnd->scsi_done = done;
  1398. vfc_cmd = &evt->iu.cmd;
  1399. memset(vfc_cmd, 0, sizeof(*vfc_cmd));
  1400. vfc_cmd->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp);
  1401. vfc_cmd->resp.len = sizeof(vfc_cmd->rsp);
  1402. vfc_cmd->frame_type = IBMVFC_SCSI_FCP_TYPE;
  1403. vfc_cmd->payload_len = sizeof(vfc_cmd->iu);
  1404. vfc_cmd->resp_len = sizeof(vfc_cmd->rsp);
  1405. vfc_cmd->cancel_key = (unsigned long)cmnd->device->hostdata;
  1406. vfc_cmd->tgt_scsi_id = rport->port_id;
  1407. vfc_cmd->iu.xfer_len = scsi_bufflen(cmnd);
  1408. int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun);
  1409. memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len);
  1410. if (scsi_populate_tag_msg(cmnd, tag)) {
  1411. vfc_cmd->task_tag = tag[1];
  1412. switch (tag[0]) {
  1413. case MSG_SIMPLE_TAG:
  1414. vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK;
  1415. break;
  1416. case MSG_HEAD_TAG:
  1417. vfc_cmd->iu.pri_task_attr = IBMVFC_HEAD_OF_QUEUE;
  1418. break;
  1419. case MSG_ORDERED_TAG:
  1420. vfc_cmd->iu.pri_task_attr = IBMVFC_ORDERED_TASK;
  1421. break;
  1422. };
  1423. }
  1424. if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev))))
  1425. return ibmvfc_send_event(evt, vhost, 0);
  1426. ibmvfc_free_event(evt);
  1427. if (rc == -ENOMEM)
  1428. return SCSI_MLQUEUE_HOST_BUSY;
  1429. if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
  1430. scmd_printk(KERN_ERR, cmnd,
  1431. "Failed to map DMA buffer for command. rc=%d\n", rc);
  1432. cmnd->result = DID_ERROR << 16;
  1433. done(cmnd);
  1434. return 0;
  1435. }
  1436. /**
  1437. * ibmvfc_sync_completion - Signal that a synchronous command has completed
  1438. * @evt: ibmvfc event struct
  1439. *
  1440. **/
  1441. static void ibmvfc_sync_completion(struct ibmvfc_event *evt)
  1442. {
  1443. /* copy the response back */
  1444. if (evt->sync_iu)
  1445. *evt->sync_iu = *evt->xfer_iu;
  1446. complete(&evt->comp);
  1447. }
  1448. /**
  1449. * ibmvfc_reset_device - Reset the device with the specified reset type
  1450. * @sdev: scsi device to reset
  1451. * @type: reset type
  1452. * @desc: reset type description for log messages
  1453. *
  1454. * Returns:
  1455. * 0 on success / other on failure
  1456. **/
  1457. static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc)
  1458. {
  1459. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1460. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1461. struct ibmvfc_cmd *tmf;
  1462. struct ibmvfc_event *evt = NULL;
  1463. union ibmvfc_iu rsp_iu;
  1464. struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp;
  1465. int rsp_rc = -EBUSY;
  1466. unsigned long flags;
  1467. int rsp_code = 0;
  1468. spin_lock_irqsave(vhost->host->host_lock, flags);
  1469. if (vhost->state == IBMVFC_ACTIVE) {
  1470. evt = ibmvfc_get_event(vhost);
  1471. ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
  1472. tmf = &evt->iu.cmd;
  1473. memset(tmf, 0, sizeof(*tmf));
  1474. tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp);
  1475. tmf->resp.len = sizeof(tmf->rsp);
  1476. tmf->frame_type = IBMVFC_SCSI_FCP_TYPE;
  1477. tmf->payload_len = sizeof(tmf->iu);
  1478. tmf->resp_len = sizeof(tmf->rsp);
  1479. tmf->cancel_key = (unsigned long)sdev->hostdata;
  1480. tmf->tgt_scsi_id = rport->port_id;
  1481. int_to_scsilun(sdev->lun, &tmf->iu.lun);
  1482. tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF);
  1483. tmf->iu.tmf_flags = type;
  1484. evt->sync_iu = &rsp_iu;
  1485. init_completion(&evt->comp);
  1486. rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
  1487. }
  1488. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1489. if (rsp_rc != 0) {
  1490. sdev_printk(KERN_ERR, sdev, "Failed to send %s reset event. rc=%d\n",
  1491. desc, rsp_rc);
  1492. return -EIO;
  1493. }
  1494. sdev_printk(KERN_INFO, sdev, "Resetting %s\n", desc);
  1495. wait_for_completion(&evt->comp);
  1496. if (rsp_iu.cmd.status) {
  1497. if (fc_rsp->flags & FCP_RSP_LEN_VALID)
  1498. rsp_code = fc_rsp->data.info.rsp_code;
  1499. sdev_printk(KERN_ERR, sdev, "%s reset failed: %s (%x:%x) "
  1500. "flags: %x fcp_rsp: %x, scsi_status: %x\n",
  1501. desc, ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error),
  1502. rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code,
  1503. fc_rsp->scsi_status);
  1504. rsp_rc = -EIO;
  1505. } else
  1506. sdev_printk(KERN_INFO, sdev, "%s reset successful\n", desc);
  1507. spin_lock_irqsave(vhost->host->host_lock, flags);
  1508. ibmvfc_free_event(evt);
  1509. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1510. return rsp_rc;
  1511. }
  1512. /**
  1513. * ibmvfc_abort_task_set - Abort outstanding commands to the device
  1514. * @sdev: scsi device to abort commands
  1515. *
  1516. * This sends an Abort Task Set to the VIOS for the specified device. This does
  1517. * NOT send any cancel to the VIOS. That must be done separately.
  1518. *
  1519. * Returns:
  1520. * 0 on success / other on failure
  1521. **/
  1522. static int ibmvfc_abort_task_set(struct scsi_device *sdev)
  1523. {
  1524. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1525. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1526. struct ibmvfc_cmd *tmf;
  1527. struct ibmvfc_event *evt, *found_evt;
  1528. union ibmvfc_iu rsp_iu;
  1529. struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp;
  1530. int rsp_rc = -EBUSY;
  1531. unsigned long flags;
  1532. int rsp_code = 0;
  1533. spin_lock_irqsave(vhost->host->host_lock, flags);
  1534. found_evt = NULL;
  1535. list_for_each_entry(evt, &vhost->sent, queue) {
  1536. if (evt->cmnd && evt->cmnd->device == sdev) {
  1537. found_evt = evt;
  1538. break;
  1539. }
  1540. }
  1541. if (!found_evt) {
  1542. if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
  1543. sdev_printk(KERN_INFO, sdev, "No events found to abort\n");
  1544. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1545. return 0;
  1546. }
  1547. if (vhost->state == IBMVFC_ACTIVE) {
  1548. evt = ibmvfc_get_event(vhost);
  1549. ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
  1550. tmf = &evt->iu.cmd;
  1551. memset(tmf, 0, sizeof(*tmf));
  1552. tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp);
  1553. tmf->resp.len = sizeof(tmf->rsp);
  1554. tmf->frame_type = IBMVFC_SCSI_FCP_TYPE;
  1555. tmf->payload_len = sizeof(tmf->iu);
  1556. tmf->resp_len = sizeof(tmf->rsp);
  1557. tmf->cancel_key = (unsigned long)sdev->hostdata;
  1558. tmf->tgt_scsi_id = rport->port_id;
  1559. int_to_scsilun(sdev->lun, &tmf->iu.lun);
  1560. tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF);
  1561. tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET;
  1562. evt->sync_iu = &rsp_iu;
  1563. init_completion(&evt->comp);
  1564. rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
  1565. }
  1566. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1567. if (rsp_rc != 0) {
  1568. sdev_printk(KERN_ERR, sdev, "Failed to send abort. rc=%d\n", rsp_rc);
  1569. return -EIO;
  1570. }
  1571. sdev_printk(KERN_INFO, sdev, "Aborting outstanding commands\n");
  1572. wait_for_completion(&evt->comp);
  1573. if (rsp_iu.cmd.status) {
  1574. if (fc_rsp->flags & FCP_RSP_LEN_VALID)
  1575. rsp_code = fc_rsp->data.info.rsp_code;
  1576. sdev_printk(KERN_ERR, sdev, "Abort failed: %s (%x:%x) "
  1577. "flags: %x fcp_rsp: %x, scsi_status: %x\n",
  1578. ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error),
  1579. rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code,
  1580. fc_rsp->scsi_status);
  1581. rsp_rc = -EIO;
  1582. } else
  1583. sdev_printk(KERN_INFO, sdev, "Abort successful\n");
  1584. spin_lock_irqsave(vhost->host->host_lock, flags);
  1585. ibmvfc_free_event(evt);
  1586. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1587. return rsp_rc;
  1588. }
  1589. /**
  1590. * ibmvfc_cancel_all - Cancel all outstanding commands to the device
  1591. * @sdev: scsi device to cancel commands
  1592. * @type: type of error recovery being performed
  1593. *
  1594. * This sends a cancel to the VIOS for the specified device. This does
  1595. * NOT send any abort to the actual device. That must be done separately.
  1596. *
  1597. * Returns:
  1598. * 0 on success / other on failure
  1599. **/
  1600. static int ibmvfc_cancel_all(struct scsi_device *sdev, int type)
  1601. {
  1602. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1603. struct scsi_target *starget = scsi_target(sdev);
  1604. struct fc_rport *rport = starget_to_rport(starget);
  1605. struct ibmvfc_tmf *tmf;
  1606. struct ibmvfc_event *evt, *found_evt;
  1607. union ibmvfc_iu rsp;
  1608. int rsp_rc = -EBUSY;
  1609. unsigned long flags;
  1610. u16 status;
  1611. ENTER;
  1612. spin_lock_irqsave(vhost->host->host_lock, flags);
  1613. found_evt = NULL;
  1614. list_for_each_entry(evt, &vhost->sent, queue) {
  1615. if (evt->cmnd && evt->cmnd->device == sdev) {
  1616. found_evt = evt;
  1617. break;
  1618. }
  1619. }
  1620. if (!found_evt) {
  1621. if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
  1622. sdev_printk(KERN_INFO, sdev, "No events found to cancel\n");
  1623. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1624. return 0;
  1625. }
  1626. if (vhost->state == IBMVFC_ACTIVE) {
  1627. evt = ibmvfc_get_event(vhost);
  1628. ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_MAD_FORMAT);
  1629. tmf = &evt->iu.tmf;
  1630. memset(tmf, 0, sizeof(*tmf));
  1631. tmf->common.version = 1;
  1632. tmf->common.opcode = IBMVFC_TMF_MAD;
  1633. tmf->common.length = sizeof(*tmf);
  1634. tmf->scsi_id = rport->port_id;
  1635. int_to_scsilun(sdev->lun, &tmf->lun);
  1636. tmf->flags = (type | IBMVFC_TMF_LUA_VALID);
  1637. tmf->cancel_key = (unsigned long)sdev->hostdata;
  1638. tmf->my_cancel_key = (unsigned long)starget->hostdata;
  1639. evt->sync_iu = &rsp;
  1640. init_completion(&evt->comp);
  1641. rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
  1642. }
  1643. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1644. if (rsp_rc != 0) {
  1645. sdev_printk(KERN_ERR, sdev, "Failed to send cancel event. rc=%d\n", rsp_rc);
  1646. return -EIO;
  1647. }
  1648. sdev_printk(KERN_INFO, sdev, "Cancelling outstanding commands.\n");
  1649. wait_for_completion(&evt->comp);
  1650. status = rsp.mad_common.status;
  1651. spin_lock_irqsave(vhost->host->host_lock, flags);
  1652. ibmvfc_free_event(evt);
  1653. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1654. if (status != IBMVFC_MAD_SUCCESS) {
  1655. sdev_printk(KERN_WARNING, sdev, "Cancel failed with rc=%x\n", status);
  1656. return -EIO;
  1657. }
  1658. sdev_printk(KERN_INFO, sdev, "Successfully cancelled outstanding commands\n");
  1659. return 0;
  1660. }
  1661. /**
  1662. * ibmvfc_match_target - Match function for specified target
  1663. * @evt: ibmvfc event struct
  1664. * @device: device to match (starget)
  1665. *
  1666. * Returns:
  1667. * 1 if event matches starget / 0 if event does not match starget
  1668. **/
  1669. static int ibmvfc_match_target(struct ibmvfc_event *evt, void *device)
  1670. {
  1671. if (evt->cmnd && scsi_target(evt->cmnd->device) == device)
  1672. return 1;
  1673. return 0;
  1674. }
  1675. /**
  1676. * ibmvfc_match_lun - Match function for specified LUN
  1677. * @evt: ibmvfc event struct
  1678. * @device: device to match (sdev)
  1679. *
  1680. * Returns:
  1681. * 1 if event matches sdev / 0 if event does not match sdev
  1682. **/
  1683. static int ibmvfc_match_lun(struct ibmvfc_event *evt, void *device)
  1684. {
  1685. if (evt->cmnd && evt->cmnd->device == device)
  1686. return 1;
  1687. return 0;
  1688. }
  1689. /**
  1690. * ibmvfc_wait_for_ops - Wait for ops to complete
  1691. * @vhost: ibmvfc host struct
  1692. * @device: device to match (starget or sdev)
  1693. * @match: match function
  1694. *
  1695. * Returns:
  1696. * SUCCESS / FAILED
  1697. **/
  1698. static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device,
  1699. int (*match) (struct ibmvfc_event *, void *))
  1700. {
  1701. struct ibmvfc_event *evt;
  1702. DECLARE_COMPLETION_ONSTACK(comp);
  1703. int wait;
  1704. unsigned long flags;
  1705. signed long timeout = init_timeout * HZ;
  1706. ENTER;
  1707. do {
  1708. wait = 0;
  1709. spin_lock_irqsave(vhost->host->host_lock, flags);
  1710. list_for_each_entry(evt, &vhost->sent, queue) {
  1711. if (match(evt, device)) {
  1712. evt->eh_comp = &comp;
  1713. wait++;
  1714. }
  1715. }
  1716. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1717. if (wait) {
  1718. timeout = wait_for_completion_timeout(&comp, timeout);
  1719. if (!timeout) {
  1720. wait = 0;
  1721. spin_lock_irqsave(vhost->host->host_lock, flags);
  1722. list_for_each_entry(evt, &vhost->sent, queue) {
  1723. if (match(evt, device)) {
  1724. evt->eh_comp = NULL;
  1725. wait++;
  1726. }
  1727. }
  1728. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  1729. if (wait)
  1730. dev_err(vhost->dev, "Timed out waiting for aborted commands\n");
  1731. LEAVE;
  1732. return wait ? FAILED : SUCCESS;
  1733. }
  1734. }
  1735. } while (wait);
  1736. LEAVE;
  1737. return SUCCESS;
  1738. }
  1739. /**
  1740. * ibmvfc_eh_abort_handler - Abort a command
  1741. * @cmd: scsi command to abort
  1742. *
  1743. * Returns:
  1744. * SUCCESS / FAILED
  1745. **/
  1746. static int ibmvfc_eh_abort_handler(struct scsi_cmnd *cmd)
  1747. {
  1748. struct scsi_device *sdev = cmd->device;
  1749. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1750. int cancel_rc, abort_rc;
  1751. int rc = FAILED;
  1752. ENTER;
  1753. ibmvfc_wait_while_resetting(vhost);
  1754. cancel_rc = ibmvfc_cancel_all(sdev, IBMVFC_TMF_ABORT_TASK_SET);
  1755. abort_rc = ibmvfc_abort_task_set(sdev);
  1756. if (!cancel_rc && !abort_rc)
  1757. rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
  1758. LEAVE;
  1759. return rc;
  1760. }
  1761. /**
  1762. * ibmvfc_eh_device_reset_handler - Reset a single LUN
  1763. * @cmd: scsi command struct
  1764. *
  1765. * Returns:
  1766. * SUCCESS / FAILED
  1767. **/
  1768. static int ibmvfc_eh_device_reset_handler(struct scsi_cmnd *cmd)
  1769. {
  1770. struct scsi_device *sdev = cmd->device;
  1771. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1772. int cancel_rc, reset_rc;
  1773. int rc = FAILED;
  1774. ENTER;
  1775. ibmvfc_wait_while_resetting(vhost);
  1776. cancel_rc = ibmvfc_cancel_all(sdev, IBMVFC_TMF_LUN_RESET);
  1777. reset_rc = ibmvfc_reset_device(sdev, IBMVFC_LUN_RESET, "LUN");
  1778. if (!cancel_rc && !reset_rc)
  1779. rc = ibmvfc_wait_for_ops(vhost, sdev, ibmvfc_match_lun);
  1780. LEAVE;
  1781. return rc;
  1782. }
  1783. /**
  1784. * ibmvfc_dev_cancel_all - Device iterated cancel all function
  1785. * @sdev: scsi device struct
  1786. * @data: return code
  1787. *
  1788. **/
  1789. static void ibmvfc_dev_cancel_all(struct scsi_device *sdev, void *data)
  1790. {
  1791. unsigned long *rc = data;
  1792. *rc |= ibmvfc_cancel_all(sdev, IBMVFC_TMF_TGT_RESET);
  1793. }
  1794. /**
  1795. * ibmvfc_dev_abort_all - Device iterated abort task set function
  1796. * @sdev: scsi device struct
  1797. * @data: return code
  1798. *
  1799. **/
  1800. static void ibmvfc_dev_abort_all(struct scsi_device *sdev, void *data)
  1801. {
  1802. unsigned long *rc = data;
  1803. *rc |= ibmvfc_abort_task_set(sdev);
  1804. }
  1805. /**
  1806. * ibmvfc_eh_target_reset_handler - Reset the target
  1807. * @cmd: scsi command struct
  1808. *
  1809. * Returns:
  1810. * SUCCESS / FAILED
  1811. **/
  1812. static int ibmvfc_eh_target_reset_handler(struct scsi_cmnd *cmd)
  1813. {
  1814. struct scsi_device *sdev = cmd->device;
  1815. struct ibmvfc_host *vhost = shost_priv(sdev->host);
  1816. struct scsi_target *starget = scsi_target(sdev);
  1817. int reset_rc;
  1818. int rc = FAILED;
  1819. unsigned long cancel_rc = 0;
  1820. ENTER;
  1821. ibmvfc_wait_while_resetting(vhost);
  1822. starget_for_each_device(starget, &cancel_rc, ibmvfc_dev_cancel_all);
  1823. reset_rc = ibmvfc_reset_device(sdev, IBMVFC_TARGET_RESET, "target");
  1824. if (!cancel_rc && !reset_rc)
  1825. rc = ibmvfc_wait_for_ops(vhost, starget, ibmvfc_match_target);
  1826. LEAVE;
  1827. return rc;
  1828. }
  1829. /**
  1830. * ibmvfc_eh_host_reset_handler - Reset the connection to the server
  1831. * @cmd: struct scsi_cmnd having problems
  1832. *
  1833. **/
  1834. static int ibmvfc_eh_host_reset_handler(struct scsi_cmnd *cmd)
  1835. {
  1836. int rc;
  1837. struct ibmvfc_host *vhost = shost_priv(cmd->device->host);
  1838. dev_err(vhost->dev, "Resetting connection due to error recovery\n");
  1839. rc = ibmvfc_issue_fc_host_lip(vhost->host);
  1840. return rc ? FAILED : SUCCESS;
  1841. }
  1842. /**
  1843. * ibmvfc_terminate_rport_io - Terminate all pending I/O to the rport.
  1844. * @rport: rport struct
  1845. *
  1846. * Return value:
  1847. * none
  1848. **/
  1849. static void ibmvfc_terminate_rport_io(struct fc_rport *rport)
  1850. {
  1851. struct scsi_target *starget = to_scsi_target(&rport->dev);
  1852. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1853. struct ibmvfc_host *vhost = shost_priv(shost);
  1854. unsigned long cancel_rc = 0;
  1855. unsigned long abort_rc = 0;
  1856. int rc = FAILED;
  1857. ENTER;
  1858. starget_for_each_device(starget, &cancel_rc, ibmvfc_dev_cancel_all);
  1859. starget_for_each_device(starget, &abort_rc, ibmvfc_dev_abort_all);
  1860. if (!cancel_rc && !abort_rc)
  1861. rc = ibmvfc_wait_for_ops(vhost, starget, ibmvfc_match_target);
  1862. if (rc == FAILED)
  1863. ibmvfc_issue_fc_host_lip(shost);
  1864. LEAVE;
  1865. }
  1866. static const struct {
  1867. enum ibmvfc_async_event ae;
  1868. const char *desc;
  1869. } ae_desc [] = {
  1870. { IBMVFC_AE_ELS_PLOGI, "PLOGI" },
  1871. { IBMVFC_AE_ELS_LOGO, "LOGO" },
  1872. { IBMVFC_AE_ELS_PRLO, "PRLO" },
  1873. { IBMVFC_AE_SCN_NPORT, "N-Port SCN" },
  1874. { IBMVFC_AE_SCN_GROUP, "Group SCN" },
  1875. { IBMVFC_AE_SCN_DOMAIN, "Domain SCN" },
  1876. { IBMVFC_AE_SCN_FABRIC, "Fabric SCN" },
  1877. { IBMVFC_AE_LINK_UP, "Link Up" },
  1878. { IBMVFC_AE_LINK_DOWN, "Link Down" },
  1879. { IBMVFC_AE_LINK_DEAD, "Link Dead" },
  1880. { IBMVFC_AE_HALT, "Halt" },
  1881. { IBMVFC_AE_RESUME, "Resume" },
  1882. { IBMVFC_AE_ADAPTER_FAILED, "Adapter Failed" },
  1883. };
  1884. static const char *unknown_ae = "Unknown async";
  1885. /**
  1886. * ibmvfc_get_ae_desc - Get text description for async event
  1887. * @ae: async event
  1888. *
  1889. **/
  1890. static const char *ibmvfc_get_ae_desc(u64 ae)
  1891. {
  1892. int i;
  1893. for (i = 0; i < ARRAY_SIZE(ae_desc); i++)
  1894. if (ae_desc[i].ae == ae)
  1895. return ae_desc[i].desc;
  1896. return unknown_ae;
  1897. }
  1898. /**
  1899. * ibmvfc_handle_async - Handle an async event from the adapter
  1900. * @crq: crq to process
  1901. * @vhost: ibmvfc host struct
  1902. *
  1903. **/
  1904. static void ibmvfc_handle_async(struct ibmvfc_async_crq *crq,
  1905. struct ibmvfc_host *vhost)
  1906. {
  1907. const char *desc = ibmvfc_get_ae_desc(crq->event);
  1908. ibmvfc_log(vhost, 3, "%s event received. scsi_id: %llx, wwpn: %llx,"
  1909. " node_name: %llx\n", desc, crq->scsi_id, crq->wwpn, crq->node_name);
  1910. switch (crq->event) {
  1911. case IBMVFC_AE_LINK_UP:
  1912. case IBMVFC_AE_RESUME:
  1913. vhost->events_to_log |= IBMVFC_AE_LINKUP;
  1914. vhost->delay_init = 1;
  1915. __ibmvfc_reset_host(vhost);
  1916. break;
  1917. case IBMVFC_AE_SCN_FABRIC:
  1918. case IBMVFC_AE_SCN_DOMAIN:
  1919. vhost->events_to_log |= IBMVFC_AE_RSCN;
  1920. vhost->delay_init = 1;
  1921. __ibmvfc_reset_host(vhost);
  1922. break;
  1923. case IBMVFC_AE_SCN_NPORT:
  1924. case IBMVFC_AE_SCN_GROUP:
  1925. vhost->events_to_log |= IBMVFC_AE_RSCN;
  1926. case IBMVFC_AE_ELS_LOGO:
  1927. case IBMVFC_AE_ELS_PRLO:
  1928. case IBMVFC_AE_ELS_PLOGI:
  1929. ibmvfc_reinit_host(vhost);
  1930. break;
  1931. case IBMVFC_AE_LINK_DOWN:
  1932. case IBMVFC_AE_ADAPTER_FAILED:
  1933. ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
  1934. break;
  1935. case IBMVFC_AE_LINK_DEAD:
  1936. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  1937. break;
  1938. case IBMVFC_AE_HALT:
  1939. ibmvfc_link_down(vhost, IBMVFC_HALTED);
  1940. break;
  1941. default:
  1942. dev_err(vhost->dev, "Unknown async event received: %lld\n", crq->event);
  1943. break;
  1944. };
  1945. }
  1946. /**
  1947. * ibmvfc_handle_crq - Handles and frees received events in the CRQ
  1948. * @crq: Command/Response queue
  1949. * @vhost: ibmvfc host struct
  1950. *
  1951. **/
  1952. static void ibmvfc_handle_crq(struct ibmvfc_crq *crq, struct ibmvfc_host *vhost)
  1953. {
  1954. long rc;
  1955. struct ibmvfc_event *evt = (struct ibmvfc_event *)crq->ioba;
  1956. switch (crq->valid) {
  1957. case IBMVFC_CRQ_INIT_RSP:
  1958. switch (crq->format) {
  1959. case IBMVFC_CRQ_INIT:
  1960. dev_info(vhost->dev, "Partner initialized\n");
  1961. /* Send back a response */
  1962. rc = ibmvfc_send_crq_init_complete(vhost);
  1963. if (rc == 0)
  1964. ibmvfc_init_host(vhost, 0);
  1965. else
  1966. dev_err(vhost->dev, "Unable to send init rsp. rc=%ld\n", rc);
  1967. break;
  1968. case IBMVFC_CRQ_INIT_COMPLETE:
  1969. dev_info(vhost->dev, "Partner initialization complete\n");
  1970. ibmvfc_init_host(vhost, 0);
  1971. break;
  1972. default:
  1973. dev_err(vhost->dev, "Unknown crq message type: %d\n", crq->format);
  1974. }
  1975. return;
  1976. case IBMVFC_CRQ_XPORT_EVENT:
  1977. vhost->state = IBMVFC_NO_CRQ;
  1978. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
  1979. if (crq->format == IBMVFC_PARTITION_MIGRATED) {
  1980. /* We need to re-setup the interpartition connection */
  1981. dev_info(vhost->dev, "Re-enabling adapter\n");
  1982. vhost->client_migrated = 1;
  1983. ibmvfc_purge_requests(vhost, DID_REQUEUE);
  1984. if ((rc = ibmvfc_reenable_crq_queue(vhost)) ||
  1985. (rc = ibmvfc_send_crq_init(vhost))) {
  1986. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  1987. dev_err(vhost->dev, "Error after enable (rc=%ld)\n", rc);
  1988. } else
  1989. ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
  1990. } else {
  1991. dev_err(vhost->dev, "Virtual adapter failed (rc=%d)\n", crq->format);
  1992. ibmvfc_purge_requests(vhost, DID_ERROR);
  1993. if ((rc = ibmvfc_reset_crq(vhost)) ||
  1994. (rc = ibmvfc_send_crq_init(vhost))) {
  1995. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  1996. dev_err(vhost->dev, "Error after reset (rc=%ld)\n", rc);
  1997. } else
  1998. ibmvfc_link_down(vhost, IBMVFC_LINK_DOWN);
  1999. }
  2000. return;
  2001. case IBMVFC_CRQ_CMD_RSP:
  2002. break;
  2003. default:
  2004. dev_err(vhost->dev, "Got an invalid message type 0x%02x\n", crq->valid);
  2005. return;
  2006. }
  2007. if (crq->format == IBMVFC_ASYNC_EVENT)
  2008. return;
  2009. /* The only kind of payload CRQs we should get are responses to
  2010. * things we send. Make sure this response is to something we
  2011. * actually sent
  2012. */
  2013. if (unlikely(!ibmvfc_valid_event(&vhost->pool, evt))) {
  2014. dev_err(vhost->dev, "Returned correlation_token 0x%08llx is invalid!\n",
  2015. crq->ioba);
  2016. return;
  2017. }
  2018. if (unlikely(atomic_read(&evt->free))) {
  2019. dev_err(vhost->dev, "Received duplicate correlation_token 0x%08llx!\n",
  2020. crq->ioba);
  2021. return;
  2022. }
  2023. del_timer(&evt->timer);
  2024. list_del(&evt->queue);
  2025. ibmvfc_trc_end(evt);
  2026. evt->done(evt);
  2027. }
  2028. /**
  2029. * ibmvfc_scan_finished - Check if the device scan is done.
  2030. * @shost: scsi host struct
  2031. * @time: current elapsed time
  2032. *
  2033. * Returns:
  2034. * 0 if scan is not done / 1 if scan is done
  2035. **/
  2036. static int ibmvfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2037. {
  2038. unsigned long flags;
  2039. struct ibmvfc_host *vhost = shost_priv(shost);
  2040. int done = 0;
  2041. spin_lock_irqsave(shost->host_lock, flags);
  2042. if (time >= (init_timeout * HZ)) {
  2043. dev_info(vhost->dev, "Scan taking longer than %d seconds, "
  2044. "continuing initialization\n", init_timeout);
  2045. done = 1;
  2046. }
  2047. if (vhost->state != IBMVFC_NO_CRQ && vhost->action == IBMVFC_HOST_ACTION_NONE)
  2048. done = 1;
  2049. spin_unlock_irqrestore(shost->host_lock, flags);
  2050. return done;
  2051. }
  2052. /**
  2053. * ibmvfc_slave_alloc - Setup the device's task set value
  2054. * @sdev: struct scsi_device device to configure
  2055. *
  2056. * Set the device's task set value so that error handling works as
  2057. * expected.
  2058. *
  2059. * Returns:
  2060. * 0 on success / -ENXIO if device does not exist
  2061. **/
  2062. static int ibmvfc_slave_alloc(struct scsi_device *sdev)
  2063. {
  2064. struct Scsi_Host *shost = sdev->host;
  2065. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  2066. struct ibmvfc_host *vhost = shost_priv(shost);
  2067. unsigned long flags = 0;
  2068. if (!rport || fc_remote_port_chkready(rport))
  2069. return -ENXIO;
  2070. spin_lock_irqsave(shost->host_lock, flags);
  2071. sdev->hostdata = (void *)(unsigned long)vhost->task_set++;
  2072. spin_unlock_irqrestore(shost->host_lock, flags);
  2073. return 0;
  2074. }
  2075. /**
  2076. * ibmvfc_target_alloc - Setup the target's task set value
  2077. * @starget: struct scsi_target
  2078. *
  2079. * Set the target's task set value so that error handling works as
  2080. * expected.
  2081. *
  2082. * Returns:
  2083. * 0 on success / -ENXIO if device does not exist
  2084. **/
  2085. static int ibmvfc_target_alloc(struct scsi_target *starget)
  2086. {
  2087. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2088. struct ibmvfc_host *vhost = shost_priv(shost);
  2089. unsigned long flags = 0;
  2090. spin_lock_irqsave(shost->host_lock, flags);
  2091. starget->hostdata = (void *)(unsigned long)vhost->task_set++;
  2092. spin_unlock_irqrestore(shost->host_lock, flags);
  2093. return 0;
  2094. }
  2095. /**
  2096. * ibmvfc_slave_configure - Configure the device
  2097. * @sdev: struct scsi_device device to configure
  2098. *
  2099. * Enable allow_restart for a device if it is a disk. Adjust the
  2100. * queue_depth here also.
  2101. *
  2102. * Returns:
  2103. * 0
  2104. **/
  2105. static int ibmvfc_slave_configure(struct scsi_device *sdev)
  2106. {
  2107. struct Scsi_Host *shost = sdev->host;
  2108. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  2109. unsigned long flags = 0;
  2110. spin_lock_irqsave(shost->host_lock, flags);
  2111. if (sdev->type == TYPE_DISK)
  2112. sdev->allow_restart = 1;
  2113. if (sdev->tagged_supported) {
  2114. scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
  2115. scsi_activate_tcq(sdev, sdev->queue_depth);
  2116. } else
  2117. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2118. rport->dev_loss_tmo = dev_loss_tmo;
  2119. spin_unlock_irqrestore(shost->host_lock, flags);
  2120. return 0;
  2121. }
  2122. /**
  2123. * ibmvfc_change_queue_depth - Change the device's queue depth
  2124. * @sdev: scsi device struct
  2125. * @qdepth: depth to set
  2126. *
  2127. * Return value:
  2128. * actual depth set
  2129. **/
  2130. static int ibmvfc_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2131. {
  2132. if (qdepth > IBMVFC_MAX_CMDS_PER_LUN)
  2133. qdepth = IBMVFC_MAX_CMDS_PER_LUN;
  2134. scsi_adjust_queue_depth(sdev, 0, qdepth);
  2135. return sdev->queue_depth;
  2136. }
  2137. /**
  2138. * ibmvfc_change_queue_type - Change the device's queue type
  2139. * @sdev: scsi device struct
  2140. * @tag_type: type of tags to use
  2141. *
  2142. * Return value:
  2143. * actual queue type set
  2144. **/
  2145. static int ibmvfc_change_queue_type(struct scsi_device *sdev, int tag_type)
  2146. {
  2147. if (sdev->tagged_supported) {
  2148. scsi_set_tag_type(sdev, tag_type);
  2149. if (tag_type)
  2150. scsi_activate_tcq(sdev, sdev->queue_depth);
  2151. else
  2152. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2153. } else
  2154. tag_type = 0;
  2155. return tag_type;
  2156. }
  2157. static ssize_t ibmvfc_show_host_partition_name(struct device *dev,
  2158. struct device_attribute *attr, char *buf)
  2159. {
  2160. struct Scsi_Host *shost = class_to_shost(dev);
  2161. struct ibmvfc_host *vhost = shost_priv(shost);
  2162. return snprintf(buf, PAGE_SIZE, "%s\n",
  2163. vhost->login_buf->resp.partition_name);
  2164. }
  2165. static struct device_attribute ibmvfc_host_partition_name = {
  2166. .attr = {
  2167. .name = "partition_name",
  2168. .mode = S_IRUGO,
  2169. },
  2170. .show = ibmvfc_show_host_partition_name,
  2171. };
  2172. static ssize_t ibmvfc_show_host_device_name(struct device *dev,
  2173. struct device_attribute *attr, char *buf)
  2174. {
  2175. struct Scsi_Host *shost = class_to_shost(dev);
  2176. struct ibmvfc_host *vhost = shost_priv(shost);
  2177. return snprintf(buf, PAGE_SIZE, "%s\n",
  2178. vhost->login_buf->resp.device_name);
  2179. }
  2180. static struct device_attribute ibmvfc_host_device_name = {
  2181. .attr = {
  2182. .name = "device_name",
  2183. .mode = S_IRUGO,
  2184. },
  2185. .show = ibmvfc_show_host_device_name,
  2186. };
  2187. static ssize_t ibmvfc_show_host_loc_code(struct device *dev,
  2188. struct device_attribute *attr, char *buf)
  2189. {
  2190. struct Scsi_Host *shost = class_to_shost(dev);
  2191. struct ibmvfc_host *vhost = shost_priv(shost);
  2192. return snprintf(buf, PAGE_SIZE, "%s\n",
  2193. vhost->login_buf->resp.port_loc_code);
  2194. }
  2195. static struct device_attribute ibmvfc_host_loc_code = {
  2196. .attr = {
  2197. .name = "port_loc_code",
  2198. .mode = S_IRUGO,
  2199. },
  2200. .show = ibmvfc_show_host_loc_code,
  2201. };
  2202. static ssize_t ibmvfc_show_host_drc_name(struct device *dev,
  2203. struct device_attribute *attr, char *buf)
  2204. {
  2205. struct Scsi_Host *shost = class_to_shost(dev);
  2206. struct ibmvfc_host *vhost = shost_priv(shost);
  2207. return snprintf(buf, PAGE_SIZE, "%s\n",
  2208. vhost->login_buf->resp.drc_name);
  2209. }
  2210. static struct device_attribute ibmvfc_host_drc_name = {
  2211. .attr = {
  2212. .name = "drc_name",
  2213. .mode = S_IRUGO,
  2214. },
  2215. .show = ibmvfc_show_host_drc_name,
  2216. };
  2217. static ssize_t ibmvfc_show_host_npiv_version(struct device *dev,
  2218. struct device_attribute *attr, char *buf)
  2219. {
  2220. struct Scsi_Host *shost = class_to_shost(dev);
  2221. struct ibmvfc_host *vhost = shost_priv(shost);
  2222. return snprintf(buf, PAGE_SIZE, "%d\n", vhost->login_buf->resp.version);
  2223. }
  2224. static struct device_attribute ibmvfc_host_npiv_version = {
  2225. .attr = {
  2226. .name = "npiv_version",
  2227. .mode = S_IRUGO,
  2228. },
  2229. .show = ibmvfc_show_host_npiv_version,
  2230. };
  2231. /**
  2232. * ibmvfc_show_log_level - Show the adapter's error logging level
  2233. * @dev: class device struct
  2234. * @buf: buffer
  2235. *
  2236. * Return value:
  2237. * number of bytes printed to buffer
  2238. **/
  2239. static ssize_t ibmvfc_show_log_level(struct device *dev,
  2240. struct device_attribute *attr, char *buf)
  2241. {
  2242. struct Scsi_Host *shost = class_to_shost(dev);
  2243. struct ibmvfc_host *vhost = shost_priv(shost);
  2244. unsigned long flags = 0;
  2245. int len;
  2246. spin_lock_irqsave(shost->host_lock, flags);
  2247. len = snprintf(buf, PAGE_SIZE, "%d\n", vhost->log_level);
  2248. spin_unlock_irqrestore(shost->host_lock, flags);
  2249. return len;
  2250. }
  2251. /**
  2252. * ibmvfc_store_log_level - Change the adapter's error logging level
  2253. * @dev: class device struct
  2254. * @buf: buffer
  2255. *
  2256. * Return value:
  2257. * number of bytes printed to buffer
  2258. **/
  2259. static ssize_t ibmvfc_store_log_level(struct device *dev,
  2260. struct device_attribute *attr,
  2261. const char *buf, size_t count)
  2262. {
  2263. struct Scsi_Host *shost = class_to_shost(dev);
  2264. struct ibmvfc_host *vhost = shost_priv(shost);
  2265. unsigned long flags = 0;
  2266. spin_lock_irqsave(shost->host_lock, flags);
  2267. vhost->log_level = simple_strtoul(buf, NULL, 10);
  2268. spin_unlock_irqrestore(shost->host_lock, flags);
  2269. return strlen(buf);
  2270. }
  2271. static struct device_attribute ibmvfc_log_level_attr = {
  2272. .attr = {
  2273. .name = "log_level",
  2274. .mode = S_IRUGO | S_IWUSR,
  2275. },
  2276. .show = ibmvfc_show_log_level,
  2277. .store = ibmvfc_store_log_level
  2278. };
  2279. #ifdef CONFIG_SCSI_IBMVFC_TRACE
  2280. /**
  2281. * ibmvfc_read_trace - Dump the adapter trace
  2282. * @kobj: kobject struct
  2283. * @bin_attr: bin_attribute struct
  2284. * @buf: buffer
  2285. * @off: offset
  2286. * @count: buffer size
  2287. *
  2288. * Return value:
  2289. * number of bytes printed to buffer
  2290. **/
  2291. static ssize_t ibmvfc_read_trace(struct kobject *kobj,
  2292. struct bin_attribute *bin_attr,
  2293. char *buf, loff_t off, size_t count)
  2294. {
  2295. struct device *dev = container_of(kobj, struct device, kobj);
  2296. struct Scsi_Host *shost = class_to_shost(dev);
  2297. struct ibmvfc_host *vhost = shost_priv(shost);
  2298. unsigned long flags = 0;
  2299. int size = IBMVFC_TRACE_SIZE;
  2300. char *src = (char *)vhost->trace;
  2301. if (off > size)
  2302. return 0;
  2303. if (off + count > size) {
  2304. size -= off;
  2305. count = size;
  2306. }
  2307. spin_lock_irqsave(shost->host_lock, flags);
  2308. memcpy(buf, &src[off], count);
  2309. spin_unlock_irqrestore(shost->host_lock, flags);
  2310. return count;
  2311. }
  2312. static struct bin_attribute ibmvfc_trace_attr = {
  2313. .attr = {
  2314. .name = "trace",
  2315. .mode = S_IRUGO,
  2316. },
  2317. .size = 0,
  2318. .read = ibmvfc_read_trace,
  2319. };
  2320. #endif
  2321. static struct device_attribute *ibmvfc_attrs[] = {
  2322. &ibmvfc_host_partition_name,
  2323. &ibmvfc_host_device_name,
  2324. &ibmvfc_host_loc_code,
  2325. &ibmvfc_host_drc_name,
  2326. &ibmvfc_host_npiv_version,
  2327. &ibmvfc_log_level_attr,
  2328. NULL
  2329. };
  2330. static struct scsi_host_template driver_template = {
  2331. .module = THIS_MODULE,
  2332. .name = "IBM POWER Virtual FC Adapter",
  2333. .proc_name = IBMVFC_NAME,
  2334. .queuecommand = ibmvfc_queuecommand,
  2335. .eh_abort_handler = ibmvfc_eh_abort_handler,
  2336. .eh_device_reset_handler = ibmvfc_eh_device_reset_handler,
  2337. .eh_target_reset_handler = ibmvfc_eh_target_reset_handler,
  2338. .eh_host_reset_handler = ibmvfc_eh_host_reset_handler,
  2339. .slave_alloc = ibmvfc_slave_alloc,
  2340. .slave_configure = ibmvfc_slave_configure,
  2341. .target_alloc = ibmvfc_target_alloc,
  2342. .scan_finished = ibmvfc_scan_finished,
  2343. .change_queue_depth = ibmvfc_change_queue_depth,
  2344. .change_queue_type = ibmvfc_change_queue_type,
  2345. .cmd_per_lun = 16,
  2346. .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT,
  2347. .this_id = -1,
  2348. .sg_tablesize = SG_ALL,
  2349. .max_sectors = IBMVFC_MAX_SECTORS,
  2350. .use_clustering = ENABLE_CLUSTERING,
  2351. .shost_attrs = ibmvfc_attrs,
  2352. };
  2353. /**
  2354. * ibmvfc_next_async_crq - Returns the next entry in async queue
  2355. * @vhost: ibmvfc host struct
  2356. *
  2357. * Returns:
  2358. * Pointer to next entry in queue / NULL if empty
  2359. **/
  2360. static struct ibmvfc_async_crq *ibmvfc_next_async_crq(struct ibmvfc_host *vhost)
  2361. {
  2362. struct ibmvfc_async_crq_queue *async_crq = &vhost->async_crq;
  2363. struct ibmvfc_async_crq *crq;
  2364. crq = &async_crq->msgs[async_crq->cur];
  2365. if (crq->valid & 0x80) {
  2366. if (++async_crq->cur == async_crq->size)
  2367. async_crq->cur = 0;
  2368. } else
  2369. crq = NULL;
  2370. return crq;
  2371. }
  2372. /**
  2373. * ibmvfc_next_crq - Returns the next entry in message queue
  2374. * @vhost: ibmvfc host struct
  2375. *
  2376. * Returns:
  2377. * Pointer to next entry in queue / NULL if empty
  2378. **/
  2379. static struct ibmvfc_crq *ibmvfc_next_crq(struct ibmvfc_host *vhost)
  2380. {
  2381. struct ibmvfc_crq_queue *queue = &vhost->crq;
  2382. struct ibmvfc_crq *crq;
  2383. crq = &queue->msgs[queue->cur];
  2384. if (crq->valid & 0x80) {
  2385. if (++queue->cur == queue->size)
  2386. queue->cur = 0;
  2387. } else
  2388. crq = NULL;
  2389. return crq;
  2390. }
  2391. /**
  2392. * ibmvfc_interrupt - Interrupt handler
  2393. * @irq: number of irq to handle, not used
  2394. * @dev_instance: ibmvfc_host that received interrupt
  2395. *
  2396. * Returns:
  2397. * IRQ_HANDLED
  2398. **/
  2399. static irqreturn_t ibmvfc_interrupt(int irq, void *dev_instance)
  2400. {
  2401. struct ibmvfc_host *vhost = (struct ibmvfc_host *)dev_instance;
  2402. struct vio_dev *vdev = to_vio_dev(vhost->dev);
  2403. struct ibmvfc_crq *crq;
  2404. struct ibmvfc_async_crq *async;
  2405. unsigned long flags;
  2406. int done = 0;
  2407. spin_lock_irqsave(vhost->host->host_lock, flags);
  2408. vio_disable_interrupts(to_vio_dev(vhost->dev));
  2409. while (!done) {
  2410. /* Pull all the valid messages off the CRQ */
  2411. while ((crq = ibmvfc_next_crq(vhost)) != NULL) {
  2412. ibmvfc_handle_crq(crq, vhost);
  2413. crq->valid = 0;
  2414. }
  2415. /* Pull all the valid messages off the async CRQ */
  2416. while ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
  2417. ibmvfc_handle_async(async, vhost);
  2418. async->valid = 0;
  2419. }
  2420. vio_enable_interrupts(vdev);
  2421. if ((crq = ibmvfc_next_crq(vhost)) != NULL) {
  2422. vio_disable_interrupts(vdev);
  2423. ibmvfc_handle_crq(crq, vhost);
  2424. crq->valid = 0;
  2425. } else if ((async = ibmvfc_next_async_crq(vhost)) != NULL) {
  2426. vio_disable_interrupts(vdev);
  2427. ibmvfc_handle_async(async, vhost);
  2428. async->valid = 0;
  2429. } else
  2430. done = 1;
  2431. }
  2432. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  2433. return IRQ_HANDLED;
  2434. }
  2435. /**
  2436. * ibmvfc_init_tgt - Set the next init job step for the target
  2437. * @tgt: ibmvfc target struct
  2438. * @job_step: job step to perform
  2439. *
  2440. **/
  2441. static void ibmvfc_init_tgt(struct ibmvfc_target *tgt,
  2442. void (*job_step) (struct ibmvfc_target *))
  2443. {
  2444. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT);
  2445. tgt->job_step = job_step;
  2446. wake_up(&tgt->vhost->work_wait_q);
  2447. }
  2448. /**
  2449. * ibmvfc_retry_tgt_init - Attempt to retry a step in target initialization
  2450. * @tgt: ibmvfc target struct
  2451. * @job_step: initialization job step
  2452. *
  2453. **/
  2454. static void ibmvfc_retry_tgt_init(struct ibmvfc_target *tgt,
  2455. void (*job_step) (struct ibmvfc_target *))
  2456. {
  2457. if (++tgt->init_retries > IBMVFC_MAX_TGT_INIT_RETRIES) {
  2458. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2459. wake_up(&tgt->vhost->work_wait_q);
  2460. } else
  2461. ibmvfc_init_tgt(tgt, job_step);
  2462. }
  2463. /**
  2464. * ibmvfc_tgt_prli_done - Completion handler for Process Login
  2465. * @evt: ibmvfc event struct
  2466. *
  2467. **/
  2468. static void ibmvfc_tgt_prli_done(struct ibmvfc_event *evt)
  2469. {
  2470. struct ibmvfc_target *tgt = evt->tgt;
  2471. struct ibmvfc_host *vhost = evt->vhost;
  2472. struct ibmvfc_process_login *rsp = &evt->xfer_iu->prli;
  2473. u32 status = rsp->common.status;
  2474. vhost->discovery_threads--;
  2475. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2476. switch (status) {
  2477. case IBMVFC_MAD_SUCCESS:
  2478. tgt_dbg(tgt, "Process Login succeeded\n");
  2479. tgt->need_login = 0;
  2480. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_ADD_RPORT);
  2481. break;
  2482. case IBMVFC_MAD_DRIVER_FAILED:
  2483. break;
  2484. case IBMVFC_MAD_CRQ_ERROR:
  2485. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_prli);
  2486. break;
  2487. case IBMVFC_MAD_FAILED:
  2488. default:
  2489. tgt_err(tgt, "Process Login failed: %s (%x:%x) rc=0x%02X\n",
  2490. ibmvfc_get_cmd_error(rsp->status, rsp->error),
  2491. rsp->status, rsp->error, status);
  2492. if (ibmvfc_retry_cmd(rsp->status, rsp->error))
  2493. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_prli);
  2494. else
  2495. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2496. break;
  2497. };
  2498. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2499. ibmvfc_free_event(evt);
  2500. wake_up(&vhost->work_wait_q);
  2501. }
  2502. /**
  2503. * ibmvfc_tgt_send_prli - Send a process login
  2504. * @tgt: ibmvfc target struct
  2505. *
  2506. **/
  2507. static void ibmvfc_tgt_send_prli(struct ibmvfc_target *tgt)
  2508. {
  2509. struct ibmvfc_process_login *prli;
  2510. struct ibmvfc_host *vhost = tgt->vhost;
  2511. struct ibmvfc_event *evt;
  2512. if (vhost->discovery_threads >= disc_threads)
  2513. return;
  2514. kref_get(&tgt->kref);
  2515. evt = ibmvfc_get_event(vhost);
  2516. vhost->discovery_threads++;
  2517. ibmvfc_init_event(evt, ibmvfc_tgt_prli_done, IBMVFC_MAD_FORMAT);
  2518. evt->tgt = tgt;
  2519. prli = &evt->iu.prli;
  2520. memset(prli, 0, sizeof(*prli));
  2521. prli->common.version = 1;
  2522. prli->common.opcode = IBMVFC_PROCESS_LOGIN;
  2523. prli->common.length = sizeof(*prli);
  2524. prli->scsi_id = tgt->scsi_id;
  2525. prli->parms.type = IBMVFC_SCSI_FCP_TYPE;
  2526. prli->parms.flags = IBMVFC_PRLI_EST_IMG_PAIR;
  2527. prli->parms.service_parms = IBMVFC_PRLI_INITIATOR_FUNC;
  2528. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT);
  2529. if (ibmvfc_send_event(evt, vhost, default_timeout)) {
  2530. vhost->discovery_threads--;
  2531. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2532. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2533. } else
  2534. tgt_dbg(tgt, "Sent process login\n");
  2535. }
  2536. /**
  2537. * ibmvfc_tgt_plogi_done - Completion handler for Port Login
  2538. * @evt: ibmvfc event struct
  2539. *
  2540. **/
  2541. static void ibmvfc_tgt_plogi_done(struct ibmvfc_event *evt)
  2542. {
  2543. struct ibmvfc_target *tgt = evt->tgt;
  2544. struct ibmvfc_host *vhost = evt->vhost;
  2545. struct ibmvfc_port_login *rsp = &evt->xfer_iu->plogi;
  2546. u32 status = rsp->common.status;
  2547. vhost->discovery_threads--;
  2548. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2549. switch (status) {
  2550. case IBMVFC_MAD_SUCCESS:
  2551. tgt_dbg(tgt, "Port Login succeeded\n");
  2552. if (tgt->ids.port_name &&
  2553. tgt->ids.port_name != wwn_to_u64(rsp->service_parms.port_name)) {
  2554. vhost->reinit = 1;
  2555. tgt_dbg(tgt, "Port re-init required\n");
  2556. break;
  2557. }
  2558. tgt->ids.node_name = wwn_to_u64(rsp->service_parms.node_name);
  2559. tgt->ids.port_name = wwn_to_u64(rsp->service_parms.port_name);
  2560. tgt->ids.port_id = tgt->scsi_id;
  2561. tgt->ids.roles = FC_PORT_ROLE_FCP_TARGET;
  2562. memcpy(&tgt->service_parms, &rsp->service_parms,
  2563. sizeof(tgt->service_parms));
  2564. memcpy(&tgt->service_parms_change, &rsp->service_parms_change,
  2565. sizeof(tgt->service_parms_change));
  2566. ibmvfc_init_tgt(tgt, ibmvfc_tgt_send_prli);
  2567. break;
  2568. case IBMVFC_MAD_DRIVER_FAILED:
  2569. break;
  2570. case IBMVFC_MAD_CRQ_ERROR:
  2571. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_plogi);
  2572. break;
  2573. case IBMVFC_MAD_FAILED:
  2574. default:
  2575. tgt_err(tgt, "Port Login failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
  2576. ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error,
  2577. ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type,
  2578. ibmvfc_get_ls_explain(rsp->fc_explain), rsp->fc_explain, status);
  2579. if (ibmvfc_retry_cmd(rsp->status, rsp->error))
  2580. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_send_plogi);
  2581. else
  2582. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2583. break;
  2584. };
  2585. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2586. ibmvfc_free_event(evt);
  2587. wake_up(&vhost->work_wait_q);
  2588. }
  2589. /**
  2590. * ibmvfc_tgt_send_plogi - Send PLOGI to the specified target
  2591. * @tgt: ibmvfc target struct
  2592. *
  2593. **/
  2594. static void ibmvfc_tgt_send_plogi(struct ibmvfc_target *tgt)
  2595. {
  2596. struct ibmvfc_port_login *plogi;
  2597. struct ibmvfc_host *vhost = tgt->vhost;
  2598. struct ibmvfc_event *evt;
  2599. if (vhost->discovery_threads >= disc_threads)
  2600. return;
  2601. kref_get(&tgt->kref);
  2602. evt = ibmvfc_get_event(vhost);
  2603. vhost->discovery_threads++;
  2604. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT);
  2605. ibmvfc_init_event(evt, ibmvfc_tgt_plogi_done, IBMVFC_MAD_FORMAT);
  2606. evt->tgt = tgt;
  2607. plogi = &evt->iu.plogi;
  2608. memset(plogi, 0, sizeof(*plogi));
  2609. plogi->common.version = 1;
  2610. plogi->common.opcode = IBMVFC_PORT_LOGIN;
  2611. plogi->common.length = sizeof(*plogi);
  2612. plogi->scsi_id = tgt->scsi_id;
  2613. if (ibmvfc_send_event(evt, vhost, default_timeout)) {
  2614. vhost->discovery_threads--;
  2615. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2616. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2617. } else
  2618. tgt_dbg(tgt, "Sent port login\n");
  2619. }
  2620. /**
  2621. * ibmvfc_tgt_implicit_logout_done - Completion handler for Implicit Logout MAD
  2622. * @evt: ibmvfc event struct
  2623. *
  2624. **/
  2625. static void ibmvfc_tgt_implicit_logout_done(struct ibmvfc_event *evt)
  2626. {
  2627. struct ibmvfc_target *tgt = evt->tgt;
  2628. struct ibmvfc_host *vhost = evt->vhost;
  2629. struct ibmvfc_implicit_logout *rsp = &evt->xfer_iu->implicit_logout;
  2630. u32 status = rsp->common.status;
  2631. vhost->discovery_threads--;
  2632. ibmvfc_free_event(evt);
  2633. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2634. switch (status) {
  2635. case IBMVFC_MAD_SUCCESS:
  2636. tgt_dbg(tgt, "Implicit Logout succeeded\n");
  2637. break;
  2638. case IBMVFC_MAD_DRIVER_FAILED:
  2639. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2640. wake_up(&vhost->work_wait_q);
  2641. return;
  2642. case IBMVFC_MAD_FAILED:
  2643. default:
  2644. tgt_err(tgt, "Implicit Logout failed: rc=0x%02X\n", status);
  2645. break;
  2646. };
  2647. if (vhost->action == IBMVFC_HOST_ACTION_TGT_INIT)
  2648. ibmvfc_init_tgt(tgt, ibmvfc_tgt_send_plogi);
  2649. else if (vhost->action == IBMVFC_HOST_ACTION_QUERY_TGTS &&
  2650. tgt->scsi_id != tgt->new_scsi_id)
  2651. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2652. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2653. wake_up(&vhost->work_wait_q);
  2654. }
  2655. /**
  2656. * ibmvfc_tgt_implicit_logout - Initiate an Implicit Logout for specified target
  2657. * @tgt: ibmvfc target struct
  2658. *
  2659. **/
  2660. static void ibmvfc_tgt_implicit_logout(struct ibmvfc_target *tgt)
  2661. {
  2662. struct ibmvfc_implicit_logout *mad;
  2663. struct ibmvfc_host *vhost = tgt->vhost;
  2664. struct ibmvfc_event *evt;
  2665. if (vhost->discovery_threads >= disc_threads)
  2666. return;
  2667. kref_get(&tgt->kref);
  2668. evt = ibmvfc_get_event(vhost);
  2669. vhost->discovery_threads++;
  2670. ibmvfc_init_event(evt, ibmvfc_tgt_implicit_logout_done, IBMVFC_MAD_FORMAT);
  2671. evt->tgt = tgt;
  2672. mad = &evt->iu.implicit_logout;
  2673. memset(mad, 0, sizeof(*mad));
  2674. mad->common.version = 1;
  2675. mad->common.opcode = IBMVFC_IMPLICIT_LOGOUT;
  2676. mad->common.length = sizeof(*mad);
  2677. mad->old_scsi_id = tgt->scsi_id;
  2678. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT);
  2679. if (ibmvfc_send_event(evt, vhost, default_timeout)) {
  2680. vhost->discovery_threads--;
  2681. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2682. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2683. } else
  2684. tgt_dbg(tgt, "Sent Implicit Logout\n");
  2685. }
  2686. /**
  2687. * ibmvfc_adisc_needs_plogi - Does device need PLOGI?
  2688. * @mad: ibmvfc passthru mad struct
  2689. * @tgt: ibmvfc target struct
  2690. *
  2691. * Returns:
  2692. * 1 if PLOGI needed / 0 if PLOGI not needed
  2693. **/
  2694. static int ibmvfc_adisc_needs_plogi(struct ibmvfc_passthru_mad *mad,
  2695. struct ibmvfc_target *tgt)
  2696. {
  2697. if (memcmp(&mad->fc_iu.response[2], &tgt->ids.port_name,
  2698. sizeof(tgt->ids.port_name)))
  2699. return 1;
  2700. if (memcmp(&mad->fc_iu.response[4], &tgt->ids.node_name,
  2701. sizeof(tgt->ids.node_name)))
  2702. return 1;
  2703. if (mad->fc_iu.response[6] != tgt->scsi_id)
  2704. return 1;
  2705. return 0;
  2706. }
  2707. /**
  2708. * ibmvfc_tgt_adisc_done - Completion handler for ADISC
  2709. * @evt: ibmvfc event struct
  2710. *
  2711. **/
  2712. static void ibmvfc_tgt_adisc_done(struct ibmvfc_event *evt)
  2713. {
  2714. struct ibmvfc_target *tgt = evt->tgt;
  2715. struct ibmvfc_host *vhost = evt->vhost;
  2716. struct ibmvfc_passthru_mad *mad = &evt->xfer_iu->passthru;
  2717. u32 status = mad->common.status;
  2718. u8 fc_reason, fc_explain;
  2719. vhost->discovery_threads--;
  2720. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2721. switch (status) {
  2722. case IBMVFC_MAD_SUCCESS:
  2723. tgt_dbg(tgt, "ADISC succeeded\n");
  2724. if (ibmvfc_adisc_needs_plogi(mad, tgt))
  2725. tgt->need_login = 1;
  2726. break;
  2727. case IBMVFC_MAD_DRIVER_FAILED:
  2728. break;
  2729. case IBMVFC_MAD_FAILED:
  2730. default:
  2731. tgt->need_login = 1;
  2732. fc_reason = (mad->fc_iu.response[1] & 0x00ff0000) >> 16;
  2733. fc_explain = (mad->fc_iu.response[1] & 0x0000ff00) >> 8;
  2734. tgt_info(tgt, "ADISC failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
  2735. ibmvfc_get_cmd_error(mad->iu.status, mad->iu.error),
  2736. mad->iu.status, mad->iu.error,
  2737. ibmvfc_get_fc_type(fc_reason), fc_reason,
  2738. ibmvfc_get_ls_explain(fc_explain), fc_explain, status);
  2739. break;
  2740. };
  2741. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2742. ibmvfc_free_event(evt);
  2743. wake_up(&vhost->work_wait_q);
  2744. }
  2745. /**
  2746. * ibmvfc_init_passthru - Initialize an event struct for FC passthru
  2747. * @evt: ibmvfc event struct
  2748. *
  2749. **/
  2750. static void ibmvfc_init_passthru(struct ibmvfc_event *evt)
  2751. {
  2752. struct ibmvfc_passthru_mad *mad = &evt->iu.passthru;
  2753. memset(mad, 0, sizeof(*mad));
  2754. mad->common.version = 1;
  2755. mad->common.opcode = IBMVFC_PASSTHRU;
  2756. mad->common.length = sizeof(*mad) - sizeof(mad->fc_iu) - sizeof(mad->iu);
  2757. mad->cmd_ioba.va = (u64)evt->crq.ioba +
  2758. offsetof(struct ibmvfc_passthru_mad, iu);
  2759. mad->cmd_ioba.len = sizeof(mad->iu);
  2760. mad->iu.cmd_len = sizeof(mad->fc_iu.payload);
  2761. mad->iu.rsp_len = sizeof(mad->fc_iu.response);
  2762. mad->iu.cmd.va = (u64)evt->crq.ioba +
  2763. offsetof(struct ibmvfc_passthru_mad, fc_iu) +
  2764. offsetof(struct ibmvfc_passthru_fc_iu, payload);
  2765. mad->iu.cmd.len = sizeof(mad->fc_iu.payload);
  2766. mad->iu.rsp.va = (u64)evt->crq.ioba +
  2767. offsetof(struct ibmvfc_passthru_mad, fc_iu) +
  2768. offsetof(struct ibmvfc_passthru_fc_iu, response);
  2769. mad->iu.rsp.len = sizeof(mad->fc_iu.response);
  2770. }
  2771. /**
  2772. * ibmvfc_tgt_adisc - Initiate an ADISC for specified target
  2773. * @tgt: ibmvfc target struct
  2774. *
  2775. **/
  2776. static void ibmvfc_tgt_adisc(struct ibmvfc_target *tgt)
  2777. {
  2778. struct ibmvfc_passthru_mad *mad;
  2779. struct ibmvfc_host *vhost = tgt->vhost;
  2780. struct ibmvfc_event *evt;
  2781. if (vhost->discovery_threads >= disc_threads)
  2782. return;
  2783. kref_get(&tgt->kref);
  2784. evt = ibmvfc_get_event(vhost);
  2785. vhost->discovery_threads++;
  2786. ibmvfc_init_event(evt, ibmvfc_tgt_adisc_done, IBMVFC_MAD_FORMAT);
  2787. evt->tgt = tgt;
  2788. ibmvfc_init_passthru(evt);
  2789. mad = &evt->iu.passthru;
  2790. mad->iu.flags = IBMVFC_FC_ELS;
  2791. mad->iu.scsi_id = tgt->scsi_id;
  2792. mad->fc_iu.payload[0] = IBMVFC_ADISC;
  2793. memcpy(&mad->fc_iu.payload[2], &vhost->login_buf->resp.port_name,
  2794. sizeof(vhost->login_buf->resp.port_name));
  2795. memcpy(&mad->fc_iu.payload[4], &vhost->login_buf->resp.node_name,
  2796. sizeof(vhost->login_buf->resp.node_name));
  2797. mad->fc_iu.payload[6] = vhost->login_buf->resp.scsi_id & 0x00ffffff;
  2798. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT);
  2799. if (ibmvfc_send_event(evt, vhost, default_timeout)) {
  2800. vhost->discovery_threads--;
  2801. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2802. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2803. } else
  2804. tgt_dbg(tgt, "Sent ADISC\n");
  2805. }
  2806. /**
  2807. * ibmvfc_tgt_query_target_done - Completion handler for Query Target MAD
  2808. * @evt: ibmvfc event struct
  2809. *
  2810. **/
  2811. static void ibmvfc_tgt_query_target_done(struct ibmvfc_event *evt)
  2812. {
  2813. struct ibmvfc_target *tgt = evt->tgt;
  2814. struct ibmvfc_host *vhost = evt->vhost;
  2815. struct ibmvfc_query_tgt *rsp = &evt->xfer_iu->query_tgt;
  2816. u32 status = rsp->common.status;
  2817. vhost->discovery_threads--;
  2818. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2819. switch (status) {
  2820. case IBMVFC_MAD_SUCCESS:
  2821. tgt_dbg(tgt, "Query Target succeeded\n");
  2822. tgt->new_scsi_id = rsp->scsi_id;
  2823. if (rsp->scsi_id != tgt->scsi_id)
  2824. ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout);
  2825. else
  2826. ibmvfc_init_tgt(tgt, ibmvfc_tgt_adisc);
  2827. break;
  2828. case IBMVFC_MAD_DRIVER_FAILED:
  2829. break;
  2830. case IBMVFC_MAD_CRQ_ERROR:
  2831. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_query_target);
  2832. break;
  2833. case IBMVFC_MAD_FAILED:
  2834. default:
  2835. tgt_err(tgt, "Query Target failed: %s (%x:%x) %s (%x) %s (%x) rc=0x%02X\n",
  2836. ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error,
  2837. ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type,
  2838. ibmvfc_get_gs_explain(rsp->fc_explain), rsp->fc_explain, status);
  2839. if ((rsp->status & IBMVFC_FABRIC_MAPPED) == IBMVFC_FABRIC_MAPPED &&
  2840. rsp->error == IBMVFC_UNABLE_TO_PERFORM_REQ &&
  2841. rsp->fc_explain == IBMVFC_PORT_NAME_NOT_REG)
  2842. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2843. else if (ibmvfc_retry_cmd(rsp->status, rsp->error))
  2844. ibmvfc_retry_tgt_init(tgt, ibmvfc_tgt_query_target);
  2845. else
  2846. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DEL_RPORT);
  2847. break;
  2848. };
  2849. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2850. ibmvfc_free_event(evt);
  2851. wake_up(&vhost->work_wait_q);
  2852. }
  2853. /**
  2854. * ibmvfc_tgt_query_target - Initiate a Query Target for specified target
  2855. * @tgt: ibmvfc target struct
  2856. *
  2857. **/
  2858. static void ibmvfc_tgt_query_target(struct ibmvfc_target *tgt)
  2859. {
  2860. struct ibmvfc_query_tgt *query_tgt;
  2861. struct ibmvfc_host *vhost = tgt->vhost;
  2862. struct ibmvfc_event *evt;
  2863. if (vhost->discovery_threads >= disc_threads)
  2864. return;
  2865. kref_get(&tgt->kref);
  2866. evt = ibmvfc_get_event(vhost);
  2867. vhost->discovery_threads++;
  2868. evt->tgt = tgt;
  2869. ibmvfc_init_event(evt, ibmvfc_tgt_query_target_done, IBMVFC_MAD_FORMAT);
  2870. query_tgt = &evt->iu.query_tgt;
  2871. memset(query_tgt, 0, sizeof(*query_tgt));
  2872. query_tgt->common.version = 1;
  2873. query_tgt->common.opcode = IBMVFC_QUERY_TARGET;
  2874. query_tgt->common.length = sizeof(*query_tgt);
  2875. query_tgt->wwpn = tgt->ids.port_name;
  2876. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_INIT_WAIT);
  2877. if (ibmvfc_send_event(evt, vhost, default_timeout)) {
  2878. vhost->discovery_threads--;
  2879. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  2880. kref_put(&tgt->kref, ibmvfc_release_tgt);
  2881. } else
  2882. tgt_dbg(tgt, "Sent Query Target\n");
  2883. }
  2884. /**
  2885. * ibmvfc_alloc_target - Allocate and initialize an ibmvfc target
  2886. * @vhost: ibmvfc host struct
  2887. * @scsi_id: SCSI ID to allocate target for
  2888. *
  2889. * Returns:
  2890. * 0 on success / other on failure
  2891. **/
  2892. static int ibmvfc_alloc_target(struct ibmvfc_host *vhost, u64 scsi_id)
  2893. {
  2894. struct ibmvfc_target *tgt;
  2895. unsigned long flags;
  2896. spin_lock_irqsave(vhost->host->host_lock, flags);
  2897. list_for_each_entry(tgt, &vhost->targets, queue) {
  2898. if (tgt->scsi_id == scsi_id) {
  2899. if (tgt->need_login)
  2900. ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout);
  2901. goto unlock_out;
  2902. }
  2903. }
  2904. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  2905. tgt = mempool_alloc(vhost->tgt_pool, GFP_KERNEL);
  2906. if (!tgt) {
  2907. dev_err(vhost->dev, "Target allocation failure for scsi id %08llx\n",
  2908. scsi_id);
  2909. return -ENOMEM;
  2910. }
  2911. memset(tgt, 0, sizeof(*tgt));
  2912. tgt->scsi_id = scsi_id;
  2913. tgt->new_scsi_id = scsi_id;
  2914. tgt->vhost = vhost;
  2915. tgt->need_login = 1;
  2916. kref_init(&tgt->kref);
  2917. ibmvfc_init_tgt(tgt, ibmvfc_tgt_implicit_logout);
  2918. spin_lock_irqsave(vhost->host->host_lock, flags);
  2919. list_add_tail(&tgt->queue, &vhost->targets);
  2920. unlock_out:
  2921. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  2922. return 0;
  2923. }
  2924. /**
  2925. * ibmvfc_alloc_targets - Allocate and initialize ibmvfc targets
  2926. * @vhost: ibmvfc host struct
  2927. *
  2928. * Returns:
  2929. * 0 on success / other on failure
  2930. **/
  2931. static int ibmvfc_alloc_targets(struct ibmvfc_host *vhost)
  2932. {
  2933. int i, rc;
  2934. for (i = 0, rc = 0; !rc && i < vhost->num_targets; i++)
  2935. rc = ibmvfc_alloc_target(vhost,
  2936. vhost->disc_buf->scsi_id[i] & IBMVFC_DISC_TGT_SCSI_ID_MASK);
  2937. return rc;
  2938. }
  2939. /**
  2940. * ibmvfc_discover_targets_done - Completion handler for discover targets MAD
  2941. * @evt: ibmvfc event struct
  2942. *
  2943. **/
  2944. static void ibmvfc_discover_targets_done(struct ibmvfc_event *evt)
  2945. {
  2946. struct ibmvfc_host *vhost = evt->vhost;
  2947. struct ibmvfc_discover_targets *rsp = &evt->xfer_iu->discover_targets;
  2948. u32 mad_status = rsp->common.status;
  2949. switch (mad_status) {
  2950. case IBMVFC_MAD_SUCCESS:
  2951. ibmvfc_dbg(vhost, "Discover Targets succeeded\n");
  2952. vhost->num_targets = rsp->num_written;
  2953. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_ALLOC_TGTS);
  2954. break;
  2955. case IBMVFC_MAD_FAILED:
  2956. dev_err(vhost->dev, "Discover Targets failed: %s (%x:%x)\n",
  2957. ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error);
  2958. ibmvfc_retry_host_init(vhost);
  2959. break;
  2960. case IBMVFC_MAD_DRIVER_FAILED:
  2961. break;
  2962. default:
  2963. dev_err(vhost->dev, "Invalid Discover Targets response: 0x%x\n", mad_status);
  2964. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  2965. break;
  2966. }
  2967. ibmvfc_free_event(evt);
  2968. wake_up(&vhost->work_wait_q);
  2969. }
  2970. /**
  2971. * ibmvfc_discover_targets - Send Discover Targets MAD
  2972. * @vhost: ibmvfc host struct
  2973. *
  2974. **/
  2975. static void ibmvfc_discover_targets(struct ibmvfc_host *vhost)
  2976. {
  2977. struct ibmvfc_discover_targets *mad;
  2978. struct ibmvfc_event *evt = ibmvfc_get_event(vhost);
  2979. ibmvfc_init_event(evt, ibmvfc_discover_targets_done, IBMVFC_MAD_FORMAT);
  2980. mad = &evt->iu.discover_targets;
  2981. memset(mad, 0, sizeof(*mad));
  2982. mad->common.version = 1;
  2983. mad->common.opcode = IBMVFC_DISC_TARGETS;
  2984. mad->common.length = sizeof(*mad);
  2985. mad->bufflen = vhost->disc_buf_sz;
  2986. mad->buffer.va = vhost->disc_buf_dma;
  2987. mad->buffer.len = vhost->disc_buf_sz;
  2988. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
  2989. if (!ibmvfc_send_event(evt, vhost, default_timeout))
  2990. ibmvfc_dbg(vhost, "Sent discover targets\n");
  2991. else
  2992. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  2993. }
  2994. /**
  2995. * ibmvfc_npiv_login_done - Completion handler for NPIV Login
  2996. * @evt: ibmvfc event struct
  2997. *
  2998. **/
  2999. static void ibmvfc_npiv_login_done(struct ibmvfc_event *evt)
  3000. {
  3001. struct ibmvfc_host *vhost = evt->vhost;
  3002. u32 mad_status = evt->xfer_iu->npiv_login.common.status;
  3003. struct ibmvfc_npiv_login_resp *rsp = &vhost->login_buf->resp;
  3004. unsigned int npiv_max_sectors;
  3005. switch (mad_status) {
  3006. case IBMVFC_MAD_SUCCESS:
  3007. ibmvfc_free_event(evt);
  3008. break;
  3009. case IBMVFC_MAD_FAILED:
  3010. dev_err(vhost->dev, "NPIV Login failed: %s (%x:%x)\n",
  3011. ibmvfc_get_cmd_error(rsp->status, rsp->error), rsp->status, rsp->error);
  3012. if (ibmvfc_retry_cmd(rsp->status, rsp->error))
  3013. ibmvfc_retry_host_init(vhost);
  3014. else
  3015. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  3016. ibmvfc_free_event(evt);
  3017. return;
  3018. case IBMVFC_MAD_CRQ_ERROR:
  3019. ibmvfc_retry_host_init(vhost);
  3020. case IBMVFC_MAD_DRIVER_FAILED:
  3021. ibmvfc_free_event(evt);
  3022. return;
  3023. default:
  3024. dev_err(vhost->dev, "Invalid NPIV Login response: 0x%x\n", mad_status);
  3025. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  3026. ibmvfc_free_event(evt);
  3027. return;
  3028. }
  3029. vhost->client_migrated = 0;
  3030. if (!(rsp->flags & IBMVFC_NATIVE_FC)) {
  3031. dev_err(vhost->dev, "Virtual adapter does not support FC. %x\n",
  3032. rsp->flags);
  3033. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  3034. wake_up(&vhost->work_wait_q);
  3035. return;
  3036. }
  3037. if (rsp->max_cmds <= IBMVFC_NUM_INTERNAL_REQ) {
  3038. dev_err(vhost->dev, "Virtual adapter supported queue depth too small: %d\n",
  3039. rsp->max_cmds);
  3040. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  3041. wake_up(&vhost->work_wait_q);
  3042. return;
  3043. }
  3044. npiv_max_sectors = min((uint)(rsp->max_dma_len >> 9), IBMVFC_MAX_SECTORS);
  3045. dev_info(vhost->dev, "Host partition: %s, device: %s %s %s max sectors %u\n",
  3046. rsp->partition_name, rsp->device_name, rsp->port_loc_code,
  3047. rsp->drc_name, npiv_max_sectors);
  3048. fc_host_fabric_name(vhost->host) = rsp->node_name;
  3049. fc_host_node_name(vhost->host) = rsp->node_name;
  3050. fc_host_port_name(vhost->host) = rsp->port_name;
  3051. fc_host_port_id(vhost->host) = rsp->scsi_id;
  3052. fc_host_port_type(vhost->host) = FC_PORTTYPE_NPIV;
  3053. fc_host_supported_classes(vhost->host) = 0;
  3054. if (rsp->service_parms.class1_parms[0] & 0x80000000)
  3055. fc_host_supported_classes(vhost->host) |= FC_COS_CLASS1;
  3056. if (rsp->service_parms.class2_parms[0] & 0x80000000)
  3057. fc_host_supported_classes(vhost->host) |= FC_COS_CLASS2;
  3058. if (rsp->service_parms.class3_parms[0] & 0x80000000)
  3059. fc_host_supported_classes(vhost->host) |= FC_COS_CLASS3;
  3060. fc_host_maxframe_size(vhost->host) =
  3061. rsp->service_parms.common.bb_rcv_sz & 0x0fff;
  3062. vhost->host->can_queue = rsp->max_cmds - IBMVFC_NUM_INTERNAL_REQ;
  3063. vhost->host->max_sectors = npiv_max_sectors;
  3064. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
  3065. wake_up(&vhost->work_wait_q);
  3066. }
  3067. /**
  3068. * ibmvfc_npiv_login - Sends NPIV login
  3069. * @vhost: ibmvfc host struct
  3070. *
  3071. **/
  3072. static void ibmvfc_npiv_login(struct ibmvfc_host *vhost)
  3073. {
  3074. struct ibmvfc_npiv_login_mad *mad;
  3075. struct ibmvfc_event *evt = ibmvfc_get_event(vhost);
  3076. ibmvfc_gather_partition_info(vhost);
  3077. ibmvfc_set_login_info(vhost);
  3078. ibmvfc_init_event(evt, ibmvfc_npiv_login_done, IBMVFC_MAD_FORMAT);
  3079. memcpy(vhost->login_buf, &vhost->login_info, sizeof(vhost->login_info));
  3080. mad = &evt->iu.npiv_login;
  3081. memset(mad, 0, sizeof(struct ibmvfc_npiv_login_mad));
  3082. mad->common.version = 1;
  3083. mad->common.opcode = IBMVFC_NPIV_LOGIN;
  3084. mad->common.length = sizeof(struct ibmvfc_npiv_login_mad);
  3085. mad->buffer.va = vhost->login_buf_dma;
  3086. mad->buffer.len = sizeof(*vhost->login_buf);
  3087. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT_WAIT);
  3088. if (!ibmvfc_send_event(evt, vhost, default_timeout))
  3089. ibmvfc_dbg(vhost, "Sent NPIV login\n");
  3090. else
  3091. ibmvfc_link_down(vhost, IBMVFC_LINK_DEAD);
  3092. };
  3093. /**
  3094. * ibmvfc_dev_init_to_do - Is there target initialization work to do?
  3095. * @vhost: ibmvfc host struct
  3096. *
  3097. * Returns:
  3098. * 1 if work to do / 0 if not
  3099. **/
  3100. static int ibmvfc_dev_init_to_do(struct ibmvfc_host *vhost)
  3101. {
  3102. struct ibmvfc_target *tgt;
  3103. list_for_each_entry(tgt, &vhost->targets, queue) {
  3104. if (tgt->action == IBMVFC_TGT_ACTION_INIT ||
  3105. tgt->action == IBMVFC_TGT_ACTION_INIT_WAIT)
  3106. return 1;
  3107. }
  3108. return 0;
  3109. }
  3110. /**
  3111. * __ibmvfc_work_to_do - Is there task level work to do? (no locking)
  3112. * @vhost: ibmvfc host struct
  3113. *
  3114. * Returns:
  3115. * 1 if work to do / 0 if not
  3116. **/
  3117. static int __ibmvfc_work_to_do(struct ibmvfc_host *vhost)
  3118. {
  3119. struct ibmvfc_target *tgt;
  3120. if (kthread_should_stop())
  3121. return 1;
  3122. switch (vhost->action) {
  3123. case IBMVFC_HOST_ACTION_NONE:
  3124. case IBMVFC_HOST_ACTION_INIT_WAIT:
  3125. return 0;
  3126. case IBMVFC_HOST_ACTION_TGT_INIT:
  3127. case IBMVFC_HOST_ACTION_QUERY_TGTS:
  3128. if (vhost->discovery_threads == disc_threads)
  3129. return 0;
  3130. list_for_each_entry(tgt, &vhost->targets, queue)
  3131. if (tgt->action == IBMVFC_TGT_ACTION_INIT)
  3132. return 1;
  3133. list_for_each_entry(tgt, &vhost->targets, queue)
  3134. if (tgt->action == IBMVFC_TGT_ACTION_INIT_WAIT)
  3135. return 0;
  3136. return 1;
  3137. case IBMVFC_HOST_ACTION_INIT:
  3138. case IBMVFC_HOST_ACTION_ALLOC_TGTS:
  3139. case IBMVFC_HOST_ACTION_TGT_ADD:
  3140. case IBMVFC_HOST_ACTION_TGT_DEL:
  3141. case IBMVFC_HOST_ACTION_TGT_DEL_FAILED:
  3142. case IBMVFC_HOST_ACTION_QUERY:
  3143. default:
  3144. break;
  3145. };
  3146. return 1;
  3147. }
  3148. /**
  3149. * ibmvfc_work_to_do - Is there task level work to do?
  3150. * @vhost: ibmvfc host struct
  3151. *
  3152. * Returns:
  3153. * 1 if work to do / 0 if not
  3154. **/
  3155. static int ibmvfc_work_to_do(struct ibmvfc_host *vhost)
  3156. {
  3157. unsigned long flags;
  3158. int rc;
  3159. spin_lock_irqsave(vhost->host->host_lock, flags);
  3160. rc = __ibmvfc_work_to_do(vhost);
  3161. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3162. return rc;
  3163. }
  3164. /**
  3165. * ibmvfc_log_ae - Log async events if necessary
  3166. * @vhost: ibmvfc host struct
  3167. * @events: events to log
  3168. *
  3169. **/
  3170. static void ibmvfc_log_ae(struct ibmvfc_host *vhost, int events)
  3171. {
  3172. if (events & IBMVFC_AE_RSCN)
  3173. fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_RSCN, 0);
  3174. if ((events & IBMVFC_AE_LINKDOWN) &&
  3175. vhost->state >= IBMVFC_HALTED)
  3176. fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
  3177. if ((events & IBMVFC_AE_LINKUP) &&
  3178. vhost->state == IBMVFC_INITIALIZING)
  3179. fc_host_post_event(vhost->host, fc_get_event_number(), FCH_EVT_LINKUP, 0);
  3180. }
  3181. /**
  3182. * ibmvfc_tgt_add_rport - Tell the FC transport about a new remote port
  3183. * @tgt: ibmvfc target struct
  3184. *
  3185. **/
  3186. static void ibmvfc_tgt_add_rport(struct ibmvfc_target *tgt)
  3187. {
  3188. struct ibmvfc_host *vhost = tgt->vhost;
  3189. struct fc_rport *rport = tgt->rport;
  3190. unsigned long flags;
  3191. if (rport) {
  3192. tgt_dbg(tgt, "Setting rport roles\n");
  3193. fc_remote_port_rolechg(rport, tgt->ids.roles);
  3194. spin_lock_irqsave(vhost->host->host_lock, flags);
  3195. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  3196. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3197. return;
  3198. }
  3199. tgt_dbg(tgt, "Adding rport\n");
  3200. rport = fc_remote_port_add(vhost->host, 0, &tgt->ids);
  3201. spin_lock_irqsave(vhost->host->host_lock, flags);
  3202. tgt->rport = rport;
  3203. ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_NONE);
  3204. if (rport) {
  3205. tgt_dbg(tgt, "rport add succeeded\n");
  3206. rport->maxframe_size = tgt->service_parms.common.bb_rcv_sz & 0x0fff;
  3207. rport->supported_classes = 0;
  3208. tgt->target_id = rport->scsi_target_id;
  3209. if (tgt->service_parms.class1_parms[0] & 0x80000000)
  3210. rport->supported_classes |= FC_COS_CLASS1;
  3211. if (tgt->service_parms.class2_parms[0] & 0x80000000)
  3212. rport->supported_classes |= FC_COS_CLASS2;
  3213. if (tgt->service_parms.class3_parms[0] & 0x80000000)
  3214. rport->supported_classes |= FC_COS_CLASS3;
  3215. } else
  3216. tgt_dbg(tgt, "rport add failed\n");
  3217. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3218. }
  3219. /**
  3220. * ibmvfc_do_work - Do task level work
  3221. * @vhost: ibmvfc host struct
  3222. *
  3223. **/
  3224. static void ibmvfc_do_work(struct ibmvfc_host *vhost)
  3225. {
  3226. struct ibmvfc_target *tgt;
  3227. unsigned long flags;
  3228. struct fc_rport *rport;
  3229. ibmvfc_log_ae(vhost, vhost->events_to_log);
  3230. spin_lock_irqsave(vhost->host->host_lock, flags);
  3231. vhost->events_to_log = 0;
  3232. switch (vhost->action) {
  3233. case IBMVFC_HOST_ACTION_NONE:
  3234. case IBMVFC_HOST_ACTION_INIT_WAIT:
  3235. break;
  3236. case IBMVFC_HOST_ACTION_INIT:
  3237. BUG_ON(vhost->state != IBMVFC_INITIALIZING);
  3238. if (vhost->delay_init) {
  3239. vhost->delay_init = 0;
  3240. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3241. ssleep(15);
  3242. return;
  3243. } else
  3244. vhost->job_step(vhost);
  3245. break;
  3246. case IBMVFC_HOST_ACTION_QUERY:
  3247. list_for_each_entry(tgt, &vhost->targets, queue)
  3248. ibmvfc_init_tgt(tgt, ibmvfc_tgt_query_target);
  3249. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY_TGTS);
  3250. break;
  3251. case IBMVFC_HOST_ACTION_QUERY_TGTS:
  3252. list_for_each_entry(tgt, &vhost->targets, queue) {
  3253. if (tgt->action == IBMVFC_TGT_ACTION_INIT) {
  3254. tgt->job_step(tgt);
  3255. break;
  3256. }
  3257. }
  3258. if (!ibmvfc_dev_init_to_do(vhost))
  3259. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL);
  3260. break;
  3261. case IBMVFC_HOST_ACTION_TGT_DEL:
  3262. case IBMVFC_HOST_ACTION_TGT_DEL_FAILED:
  3263. list_for_each_entry(tgt, &vhost->targets, queue) {
  3264. if (tgt->action == IBMVFC_TGT_ACTION_DEL_RPORT) {
  3265. tgt_dbg(tgt, "Deleting rport\n");
  3266. rport = tgt->rport;
  3267. tgt->rport = NULL;
  3268. list_del(&tgt->queue);
  3269. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3270. if (rport)
  3271. fc_remote_port_delete(rport);
  3272. kref_put(&tgt->kref, ibmvfc_release_tgt);
  3273. return;
  3274. }
  3275. }
  3276. if (vhost->state == IBMVFC_INITIALIZING) {
  3277. if (vhost->action == IBMVFC_HOST_ACTION_TGT_DEL_FAILED) {
  3278. ibmvfc_set_host_state(vhost, IBMVFC_ACTIVE);
  3279. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_ADD);
  3280. vhost->init_retries = 0;
  3281. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3282. scsi_unblock_requests(vhost->host);
  3283. return;
  3284. } else {
  3285. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_INIT);
  3286. vhost->job_step = ibmvfc_discover_targets;
  3287. }
  3288. } else {
  3289. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
  3290. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3291. scsi_unblock_requests(vhost->host);
  3292. wake_up(&vhost->init_wait_q);
  3293. return;
  3294. }
  3295. break;
  3296. case IBMVFC_HOST_ACTION_ALLOC_TGTS:
  3297. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_INIT);
  3298. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3299. ibmvfc_alloc_targets(vhost);
  3300. spin_lock_irqsave(vhost->host->host_lock, flags);
  3301. break;
  3302. case IBMVFC_HOST_ACTION_TGT_INIT:
  3303. list_for_each_entry(tgt, &vhost->targets, queue) {
  3304. if (tgt->action == IBMVFC_TGT_ACTION_INIT) {
  3305. tgt->job_step(tgt);
  3306. break;
  3307. }
  3308. }
  3309. if (!ibmvfc_dev_init_to_do(vhost))
  3310. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_TGT_DEL_FAILED);
  3311. break;
  3312. case IBMVFC_HOST_ACTION_TGT_ADD:
  3313. list_for_each_entry(tgt, &vhost->targets, queue) {
  3314. if (tgt->action == IBMVFC_TGT_ACTION_ADD_RPORT) {
  3315. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3316. ibmvfc_tgt_add_rport(tgt);
  3317. return;
  3318. }
  3319. }
  3320. if (vhost->reinit && !ibmvfc_set_host_state(vhost, IBMVFC_INITIALIZING)) {
  3321. vhost->reinit = 0;
  3322. scsi_block_requests(vhost->host);
  3323. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_QUERY);
  3324. } else {
  3325. ibmvfc_set_host_action(vhost, IBMVFC_HOST_ACTION_NONE);
  3326. wake_up(&vhost->init_wait_q);
  3327. }
  3328. break;
  3329. default:
  3330. break;
  3331. };
  3332. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3333. }
  3334. /**
  3335. * ibmvfc_work - Do task level work
  3336. * @data: ibmvfc host struct
  3337. *
  3338. * Returns:
  3339. * zero
  3340. **/
  3341. static int ibmvfc_work(void *data)
  3342. {
  3343. struct ibmvfc_host *vhost = data;
  3344. int rc;
  3345. set_user_nice(current, -20);
  3346. while (1) {
  3347. rc = wait_event_interruptible(vhost->work_wait_q,
  3348. ibmvfc_work_to_do(vhost));
  3349. BUG_ON(rc);
  3350. if (kthread_should_stop())
  3351. break;
  3352. ibmvfc_do_work(vhost);
  3353. }
  3354. ibmvfc_dbg(vhost, "ibmvfc kthread exiting...\n");
  3355. return 0;
  3356. }
  3357. /**
  3358. * ibmvfc_init_crq - Initializes and registers CRQ with hypervisor
  3359. * @vhost: ibmvfc host struct
  3360. *
  3361. * Allocates a page for messages, maps it for dma, and registers
  3362. * the crq with the hypervisor.
  3363. *
  3364. * Return value:
  3365. * zero on success / other on failure
  3366. **/
  3367. static int ibmvfc_init_crq(struct ibmvfc_host *vhost)
  3368. {
  3369. int rc, retrc = -ENOMEM;
  3370. struct device *dev = vhost->dev;
  3371. struct vio_dev *vdev = to_vio_dev(dev);
  3372. struct ibmvfc_crq_queue *crq = &vhost->crq;
  3373. ENTER;
  3374. crq->msgs = (struct ibmvfc_crq *)get_zeroed_page(GFP_KERNEL);
  3375. if (!crq->msgs)
  3376. return -ENOMEM;
  3377. crq->size = PAGE_SIZE / sizeof(*crq->msgs);
  3378. crq->msg_token = dma_map_single(dev, crq->msgs,
  3379. PAGE_SIZE, DMA_BIDIRECTIONAL);
  3380. if (dma_mapping_error(dev, crq->msg_token))
  3381. goto map_failed;
  3382. retrc = rc = plpar_hcall_norets(H_REG_CRQ, vdev->unit_address,
  3383. crq->msg_token, PAGE_SIZE);
  3384. if (rc == H_RESOURCE)
  3385. /* maybe kexecing and resource is busy. try a reset */
  3386. retrc = rc = ibmvfc_reset_crq(vhost);
  3387. if (rc == H_CLOSED)
  3388. dev_warn(dev, "Partner adapter not ready\n");
  3389. else if (rc) {
  3390. dev_warn(dev, "Error %d opening adapter\n", rc);
  3391. goto reg_crq_failed;
  3392. }
  3393. retrc = 0;
  3394. if ((rc = request_irq(vdev->irq, ibmvfc_interrupt, 0, IBMVFC_NAME, vhost))) {
  3395. dev_err(dev, "Couldn't register irq 0x%x. rc=%d\n", vdev->irq, rc);
  3396. goto req_irq_failed;
  3397. }
  3398. if ((rc = vio_enable_interrupts(vdev))) {
  3399. dev_err(dev, "Error %d enabling interrupts\n", rc);
  3400. goto req_irq_failed;
  3401. }
  3402. crq->cur = 0;
  3403. LEAVE;
  3404. return retrc;
  3405. req_irq_failed:
  3406. do {
  3407. rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
  3408. } while (rc == H_BUSY || H_IS_LONG_BUSY(rc));
  3409. reg_crq_failed:
  3410. dma_unmap_single(dev, crq->msg_token, PAGE_SIZE, DMA_BIDIRECTIONAL);
  3411. map_failed:
  3412. free_page((unsigned long)crq->msgs);
  3413. return retrc;
  3414. }
  3415. /**
  3416. * ibmvfc_free_mem - Free memory for vhost
  3417. * @vhost: ibmvfc host struct
  3418. *
  3419. * Return value:
  3420. * none
  3421. **/
  3422. static void ibmvfc_free_mem(struct ibmvfc_host *vhost)
  3423. {
  3424. struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq;
  3425. ENTER;
  3426. mempool_destroy(vhost->tgt_pool);
  3427. kfree(vhost->trace);
  3428. dma_free_coherent(vhost->dev, vhost->disc_buf_sz, vhost->disc_buf,
  3429. vhost->disc_buf_dma);
  3430. dma_free_coherent(vhost->dev, sizeof(*vhost->login_buf),
  3431. vhost->login_buf, vhost->login_buf_dma);
  3432. dma_pool_destroy(vhost->sg_pool);
  3433. dma_unmap_single(vhost->dev, async_q->msg_token,
  3434. async_q->size * sizeof(*async_q->msgs), DMA_BIDIRECTIONAL);
  3435. free_page((unsigned long)async_q->msgs);
  3436. LEAVE;
  3437. }
  3438. /**
  3439. * ibmvfc_alloc_mem - Allocate memory for vhost
  3440. * @vhost: ibmvfc host struct
  3441. *
  3442. * Return value:
  3443. * 0 on success / non-zero on failure
  3444. **/
  3445. static int ibmvfc_alloc_mem(struct ibmvfc_host *vhost)
  3446. {
  3447. struct ibmvfc_async_crq_queue *async_q = &vhost->async_crq;
  3448. struct device *dev = vhost->dev;
  3449. ENTER;
  3450. async_q->msgs = (struct ibmvfc_async_crq *)get_zeroed_page(GFP_KERNEL);
  3451. if (!async_q->msgs) {
  3452. dev_err(dev, "Couldn't allocate async queue.\n");
  3453. goto nomem;
  3454. }
  3455. async_q->size = PAGE_SIZE / sizeof(struct ibmvfc_async_crq);
  3456. async_q->msg_token = dma_map_single(dev, async_q->msgs,
  3457. async_q->size * sizeof(*async_q->msgs),
  3458. DMA_BIDIRECTIONAL);
  3459. if (dma_mapping_error(dev, async_q->msg_token)) {
  3460. dev_err(dev, "Failed to map async queue\n");
  3461. goto free_async_crq;
  3462. }
  3463. vhost->sg_pool = dma_pool_create(IBMVFC_NAME, dev,
  3464. SG_ALL * sizeof(struct srp_direct_buf),
  3465. sizeof(struct srp_direct_buf), 0);
  3466. if (!vhost->sg_pool) {
  3467. dev_err(dev, "Failed to allocate sg pool\n");
  3468. goto unmap_async_crq;
  3469. }
  3470. vhost->login_buf = dma_alloc_coherent(dev, sizeof(*vhost->login_buf),
  3471. &vhost->login_buf_dma, GFP_KERNEL);
  3472. if (!vhost->login_buf) {
  3473. dev_err(dev, "Couldn't allocate NPIV login buffer\n");
  3474. goto free_sg_pool;
  3475. }
  3476. vhost->disc_buf_sz = sizeof(vhost->disc_buf->scsi_id[0]) * max_targets;
  3477. vhost->disc_buf = dma_alloc_coherent(dev, vhost->disc_buf_sz,
  3478. &vhost->disc_buf_dma, GFP_KERNEL);
  3479. if (!vhost->disc_buf) {
  3480. dev_err(dev, "Couldn't allocate Discover Targets buffer\n");
  3481. goto free_login_buffer;
  3482. }
  3483. vhost->trace = kcalloc(IBMVFC_NUM_TRACE_ENTRIES,
  3484. sizeof(struct ibmvfc_trace_entry), GFP_KERNEL);
  3485. if (!vhost->trace)
  3486. goto free_disc_buffer;
  3487. vhost->tgt_pool = mempool_create_kzalloc_pool(IBMVFC_TGT_MEMPOOL_SZ,
  3488. sizeof(struct ibmvfc_target));
  3489. if (!vhost->tgt_pool) {
  3490. dev_err(dev, "Couldn't allocate target memory pool\n");
  3491. goto free_trace;
  3492. }
  3493. LEAVE;
  3494. return 0;
  3495. free_trace:
  3496. kfree(vhost->trace);
  3497. free_disc_buffer:
  3498. dma_free_coherent(dev, vhost->disc_buf_sz, vhost->disc_buf,
  3499. vhost->disc_buf_dma);
  3500. free_login_buffer:
  3501. dma_free_coherent(dev, sizeof(*vhost->login_buf),
  3502. vhost->login_buf, vhost->login_buf_dma);
  3503. free_sg_pool:
  3504. dma_pool_destroy(vhost->sg_pool);
  3505. unmap_async_crq:
  3506. dma_unmap_single(dev, async_q->msg_token,
  3507. async_q->size * sizeof(*async_q->msgs), DMA_BIDIRECTIONAL);
  3508. free_async_crq:
  3509. free_page((unsigned long)async_q->msgs);
  3510. nomem:
  3511. LEAVE;
  3512. return -ENOMEM;
  3513. }
  3514. /**
  3515. * ibmvfc_probe - Adapter hot plug add entry point
  3516. * @vdev: vio device struct
  3517. * @id: vio device id struct
  3518. *
  3519. * Return value:
  3520. * 0 on success / non-zero on failure
  3521. **/
  3522. static int ibmvfc_probe(struct vio_dev *vdev, const struct vio_device_id *id)
  3523. {
  3524. struct ibmvfc_host *vhost;
  3525. struct Scsi_Host *shost;
  3526. struct device *dev = &vdev->dev;
  3527. int rc = -ENOMEM;
  3528. ENTER;
  3529. shost = scsi_host_alloc(&driver_template, sizeof(*vhost));
  3530. if (!shost) {
  3531. dev_err(dev, "Couldn't allocate host data\n");
  3532. goto out;
  3533. }
  3534. shost->transportt = ibmvfc_transport_template;
  3535. shost->can_queue = max_requests;
  3536. shost->max_lun = max_lun;
  3537. shost->max_id = max_targets;
  3538. shost->max_sectors = IBMVFC_MAX_SECTORS;
  3539. shost->max_cmd_len = IBMVFC_MAX_CDB_LEN;
  3540. shost->unique_id = shost->host_no;
  3541. vhost = shost_priv(shost);
  3542. INIT_LIST_HEAD(&vhost->sent);
  3543. INIT_LIST_HEAD(&vhost->free);
  3544. INIT_LIST_HEAD(&vhost->targets);
  3545. sprintf(vhost->name, IBMVFC_NAME);
  3546. vhost->host = shost;
  3547. vhost->dev = dev;
  3548. vhost->partition_number = -1;
  3549. vhost->log_level = log_level;
  3550. strcpy(vhost->partition_name, "UNKNOWN");
  3551. init_waitqueue_head(&vhost->work_wait_q);
  3552. init_waitqueue_head(&vhost->init_wait_q);
  3553. if ((rc = ibmvfc_alloc_mem(vhost)))
  3554. goto free_scsi_host;
  3555. vhost->work_thread = kthread_run(ibmvfc_work, vhost, "%s_%d", IBMVFC_NAME,
  3556. shost->host_no);
  3557. if (IS_ERR(vhost->work_thread)) {
  3558. dev_err(dev, "Couldn't create kernel thread: %ld\n",
  3559. PTR_ERR(vhost->work_thread));
  3560. goto free_host_mem;
  3561. }
  3562. if ((rc = ibmvfc_init_crq(vhost))) {
  3563. dev_err(dev, "Couldn't initialize crq. rc=%d\n", rc);
  3564. goto kill_kthread;
  3565. }
  3566. if ((rc = ibmvfc_init_event_pool(vhost))) {
  3567. dev_err(dev, "Couldn't initialize event pool. rc=%d\n", rc);
  3568. goto release_crq;
  3569. }
  3570. if ((rc = scsi_add_host(shost, dev)))
  3571. goto release_event_pool;
  3572. if ((rc = ibmvfc_create_trace_file(&shost->shost_dev.kobj,
  3573. &ibmvfc_trace_attr))) {
  3574. dev_err(dev, "Failed to create trace file. rc=%d\n", rc);
  3575. goto remove_shost;
  3576. }
  3577. dev_set_drvdata(dev, vhost);
  3578. spin_lock(&ibmvfc_driver_lock);
  3579. list_add_tail(&vhost->queue, &ibmvfc_head);
  3580. spin_unlock(&ibmvfc_driver_lock);
  3581. ibmvfc_send_crq_init(vhost);
  3582. scsi_scan_host(shost);
  3583. return 0;
  3584. remove_shost:
  3585. scsi_remove_host(shost);
  3586. release_event_pool:
  3587. ibmvfc_free_event_pool(vhost);
  3588. release_crq:
  3589. ibmvfc_release_crq_queue(vhost);
  3590. kill_kthread:
  3591. kthread_stop(vhost->work_thread);
  3592. free_host_mem:
  3593. ibmvfc_free_mem(vhost);
  3594. free_scsi_host:
  3595. scsi_host_put(shost);
  3596. out:
  3597. LEAVE;
  3598. return rc;
  3599. }
  3600. /**
  3601. * ibmvfc_remove - Adapter hot plug remove entry point
  3602. * @vdev: vio device struct
  3603. *
  3604. * Return value:
  3605. * 0
  3606. **/
  3607. static int ibmvfc_remove(struct vio_dev *vdev)
  3608. {
  3609. struct ibmvfc_host *vhost = dev_get_drvdata(&vdev->dev);
  3610. unsigned long flags;
  3611. ENTER;
  3612. ibmvfc_remove_trace_file(&vhost->host->shost_dev.kobj, &ibmvfc_trace_attr);
  3613. ibmvfc_link_down(vhost, IBMVFC_HOST_OFFLINE);
  3614. ibmvfc_wait_while_resetting(vhost);
  3615. ibmvfc_release_crq_queue(vhost);
  3616. kthread_stop(vhost->work_thread);
  3617. fc_remove_host(vhost->host);
  3618. scsi_remove_host(vhost->host);
  3619. spin_lock_irqsave(vhost->host->host_lock, flags);
  3620. ibmvfc_purge_requests(vhost, DID_ERROR);
  3621. ibmvfc_free_event_pool(vhost);
  3622. spin_unlock_irqrestore(vhost->host->host_lock, flags);
  3623. ibmvfc_free_mem(vhost);
  3624. spin_lock(&ibmvfc_driver_lock);
  3625. list_del(&vhost->queue);
  3626. spin_unlock(&ibmvfc_driver_lock);
  3627. scsi_host_put(vhost->host);
  3628. LEAVE;
  3629. return 0;
  3630. }
  3631. /**
  3632. * ibmvfc_get_desired_dma - Calculate DMA resources needed by the driver
  3633. * @vdev: vio device struct
  3634. *
  3635. * Return value:
  3636. * Number of bytes the driver will need to DMA map at the same time in
  3637. * order to perform well.
  3638. */
  3639. static unsigned long ibmvfc_get_desired_dma(struct vio_dev *vdev)
  3640. {
  3641. unsigned long pool_dma = max_requests * sizeof(union ibmvfc_iu);
  3642. return pool_dma + ((512 * 1024) * driver_template.cmd_per_lun);
  3643. }
  3644. static struct vio_device_id ibmvfc_device_table[] __devinitdata = {
  3645. {"fcp", "IBM,vfc-client"},
  3646. { "", "" }
  3647. };
  3648. MODULE_DEVICE_TABLE(vio, ibmvfc_device_table);
  3649. static struct vio_driver ibmvfc_driver = {
  3650. .id_table = ibmvfc_device_table,
  3651. .probe = ibmvfc_probe,
  3652. .remove = ibmvfc_remove,
  3653. .get_desired_dma = ibmvfc_get_desired_dma,
  3654. .driver = {
  3655. .name = IBMVFC_NAME,
  3656. .owner = THIS_MODULE,
  3657. }
  3658. };
  3659. static struct fc_function_template ibmvfc_transport_functions = {
  3660. .show_host_fabric_name = 1,
  3661. .show_host_node_name = 1,
  3662. .show_host_port_name = 1,
  3663. .show_host_supported_classes = 1,
  3664. .show_host_port_type = 1,
  3665. .show_host_port_id = 1,
  3666. .get_host_port_state = ibmvfc_get_host_port_state,
  3667. .show_host_port_state = 1,
  3668. .get_host_speed = ibmvfc_get_host_speed,
  3669. .show_host_speed = 1,
  3670. .issue_fc_host_lip = ibmvfc_issue_fc_host_lip,
  3671. .terminate_rport_io = ibmvfc_terminate_rport_io,
  3672. .show_rport_maxframe_size = 1,
  3673. .show_rport_supported_classes = 1,
  3674. .set_rport_dev_loss_tmo = ibmvfc_set_rport_dev_loss_tmo,
  3675. .show_rport_dev_loss_tmo = 1,
  3676. .get_starget_node_name = ibmvfc_get_starget_node_name,
  3677. .show_starget_node_name = 1,
  3678. .get_starget_port_name = ibmvfc_get_starget_port_name,
  3679. .show_starget_port_name = 1,
  3680. .get_starget_port_id = ibmvfc_get_starget_port_id,
  3681. .show_starget_port_id = 1,
  3682. };
  3683. /**
  3684. * ibmvfc_module_init - Initialize the ibmvfc module
  3685. *
  3686. * Return value:
  3687. * 0 on success / other on failure
  3688. **/
  3689. static int __init ibmvfc_module_init(void)
  3690. {
  3691. int rc;
  3692. if (!firmware_has_feature(FW_FEATURE_VIO))
  3693. return -ENODEV;
  3694. printk(KERN_INFO IBMVFC_NAME": IBM Virtual Fibre Channel Driver version: %s %s\n",
  3695. IBMVFC_DRIVER_VERSION, IBMVFC_DRIVER_DATE);
  3696. ibmvfc_transport_template = fc_attach_transport(&ibmvfc_transport_functions);
  3697. if (!ibmvfc_transport_template)
  3698. return -ENOMEM;
  3699. rc = vio_register_driver(&ibmvfc_driver);
  3700. if (rc)
  3701. fc_release_transport(ibmvfc_transport_template);
  3702. return rc;
  3703. }
  3704. /**
  3705. * ibmvfc_module_exit - Teardown the ibmvfc module
  3706. *
  3707. * Return value:
  3708. * nothing
  3709. **/
  3710. static void __exit ibmvfc_module_exit(void)
  3711. {
  3712. vio_unregister_driver(&ibmvfc_driver);
  3713. fc_release_transport(ibmvfc_transport_template);
  3714. }
  3715. module_init(ibmvfc_module_init);
  3716. module_exit(ibmvfc_module_exit);