qla_gs.c 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/utsname.h>
  10. static int qla2x00_sns_ga_nxt(scsi_qla_host_t *, fc_port_t *);
  11. static int qla2x00_sns_gid_pt(scsi_qla_host_t *, sw_info_t *);
  12. static int qla2x00_sns_gpn_id(scsi_qla_host_t *, sw_info_t *);
  13. static int qla2x00_sns_gnn_id(scsi_qla_host_t *, sw_info_t *);
  14. static int qla2x00_sns_rft_id(scsi_qla_host_t *);
  15. static int qla2x00_sns_rnn_id(scsi_qla_host_t *);
  16. static int qla_async_rftid(scsi_qla_host_t *, port_id_t *);
  17. static int qla_async_rffid(scsi_qla_host_t *, port_id_t *, u8, u8);
  18. static int qla_async_rnnid(scsi_qla_host_t *, port_id_t *, u8*);
  19. static int qla_async_rsnn_nn(scsi_qla_host_t *);
  20. /**
  21. * qla2x00_prep_ms_iocb() - Prepare common MS/CT IOCB fields for SNS CT query.
  22. * @vha: HA context
  23. * @arg: CT arguments
  24. *
  25. * Returns a pointer to the @vha's ms_iocb.
  26. */
  27. void *
  28. qla2x00_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
  29. {
  30. struct qla_hw_data *ha = vha->hw;
  31. ms_iocb_entry_t *ms_pkt;
  32. ms_pkt = (ms_iocb_entry_t *)arg->iocb;
  33. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  34. ms_pkt->entry_type = MS_IOCB_TYPE;
  35. ms_pkt->entry_count = 1;
  36. SET_TARGET_ID(ha, ms_pkt->loop_id, SIMPLE_NAME_SERVER);
  37. ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
  38. ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  39. ms_pkt->cmd_dsd_count = cpu_to_le16(1);
  40. ms_pkt->total_dsd_count = cpu_to_le16(2);
  41. ms_pkt->rsp_bytecount = cpu_to_le32(arg->rsp_size);
  42. ms_pkt->req_bytecount = cpu_to_le32(arg->req_size);
  43. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(arg->req_dma));
  44. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(arg->req_dma));
  45. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  46. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
  47. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
  48. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  49. vha->qla_stats.control_requests++;
  50. return (ms_pkt);
  51. }
  52. /**
  53. * qla24xx_prep_ms_iocb() - Prepare common CT IOCB fields for SNS CT query.
  54. * @vha: HA context
  55. * @arg: CT arguments
  56. *
  57. * Returns a pointer to the @ha's ms_iocb.
  58. */
  59. void *
  60. qla24xx_prep_ms_iocb(scsi_qla_host_t *vha, struct ct_arg *arg)
  61. {
  62. struct qla_hw_data *ha = vha->hw;
  63. struct ct_entry_24xx *ct_pkt;
  64. ct_pkt = (struct ct_entry_24xx *)arg->iocb;
  65. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  66. ct_pkt->entry_type = CT_IOCB_TYPE;
  67. ct_pkt->entry_count = 1;
  68. ct_pkt->nport_handle = cpu_to_le16(arg->nport_handle);
  69. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  70. ct_pkt->cmd_dsd_count = cpu_to_le16(1);
  71. ct_pkt->rsp_dsd_count = cpu_to_le16(1);
  72. ct_pkt->rsp_byte_count = cpu_to_le32(arg->rsp_size);
  73. ct_pkt->cmd_byte_count = cpu_to_le32(arg->req_size);
  74. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(arg->req_dma));
  75. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(arg->req_dma));
  76. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  77. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(arg->rsp_dma));
  78. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(arg->rsp_dma));
  79. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  80. ct_pkt->vp_index = vha->vp_idx;
  81. vha->qla_stats.control_requests++;
  82. return (ct_pkt);
  83. }
  84. /**
  85. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  86. * @p: CT request buffer
  87. * @cmd: GS command
  88. * @rsp_size: response size in bytes
  89. *
  90. * Returns a pointer to the intitialized @ct_req.
  91. */
  92. static inline struct ct_sns_req *
  93. qla2x00_prep_ct_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size)
  94. {
  95. memset(p, 0, sizeof(struct ct_sns_pkt));
  96. p->p.req.header.revision = 0x01;
  97. p->p.req.header.gs_type = 0xFC;
  98. p->p.req.header.gs_subtype = 0x02;
  99. p->p.req.command = cpu_to_be16(cmd);
  100. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  101. return &p->p.req;
  102. }
  103. int
  104. qla2x00_chk_ms_status(scsi_qla_host_t *vha, ms_iocb_entry_t *ms_pkt,
  105. struct ct_sns_rsp *ct_rsp, const char *routine)
  106. {
  107. int rval;
  108. uint16_t comp_status;
  109. struct qla_hw_data *ha = vha->hw;
  110. bool lid_is_sns = false;
  111. rval = QLA_FUNCTION_FAILED;
  112. if (ms_pkt->entry_status != 0) {
  113. ql_dbg(ql_dbg_disc, vha, 0x2031,
  114. "%s failed, error status (%x) on port_id: %02x%02x%02x.\n",
  115. routine, ms_pkt->entry_status, vha->d_id.b.domain,
  116. vha->d_id.b.area, vha->d_id.b.al_pa);
  117. } else {
  118. if (IS_FWI2_CAPABLE(ha))
  119. comp_status = le16_to_cpu(
  120. ((struct ct_entry_24xx *)ms_pkt)->comp_status);
  121. else
  122. comp_status = le16_to_cpu(ms_pkt->status);
  123. switch (comp_status) {
  124. case CS_COMPLETE:
  125. case CS_DATA_UNDERRUN:
  126. case CS_DATA_OVERRUN: /* Overrun? */
  127. if (ct_rsp->header.response !=
  128. cpu_to_be16(CT_ACCEPT_RESPONSE)) {
  129. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2077,
  130. "%s failed rejected request on port_id: %02x%02x%02x Completion status 0x%x, response 0x%x\n",
  131. routine, vha->d_id.b.domain,
  132. vha->d_id.b.area, vha->d_id.b.al_pa,
  133. comp_status, ct_rsp->header.response);
  134. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha,
  135. 0x2078, (uint8_t *)&ct_rsp->header,
  136. sizeof(struct ct_rsp_hdr));
  137. rval = QLA_INVALID_COMMAND;
  138. } else
  139. rval = QLA_SUCCESS;
  140. break;
  141. case CS_PORT_LOGGED_OUT:
  142. if (IS_FWI2_CAPABLE(ha)) {
  143. if (le16_to_cpu(ms_pkt->loop_id.extended) ==
  144. NPH_SNS)
  145. lid_is_sns = true;
  146. } else {
  147. if (le16_to_cpu(ms_pkt->loop_id.extended) ==
  148. SIMPLE_NAME_SERVER)
  149. lid_is_sns = true;
  150. }
  151. if (lid_is_sns) {
  152. ql_dbg(ql_dbg_async, vha, 0x502b,
  153. "%s failed, Name server has logged out",
  154. routine);
  155. rval = QLA_NOT_LOGGED_IN;
  156. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  157. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  158. }
  159. break;
  160. case CS_TIMEOUT:
  161. rval = QLA_FUNCTION_TIMEOUT;
  162. /* fall through */
  163. default:
  164. ql_dbg(ql_dbg_disc, vha, 0x2033,
  165. "%s failed, completion status (%x) on port_id: "
  166. "%02x%02x%02x.\n", routine, comp_status,
  167. vha->d_id.b.domain, vha->d_id.b.area,
  168. vha->d_id.b.al_pa);
  169. break;
  170. }
  171. }
  172. return rval;
  173. }
  174. /**
  175. * qla2x00_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  176. * @vha: HA context
  177. * @fcport: fcport entry to updated
  178. *
  179. * Returns 0 on success.
  180. */
  181. int
  182. qla2x00_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
  183. {
  184. int rval;
  185. ms_iocb_entry_t *ms_pkt;
  186. struct ct_sns_req *ct_req;
  187. struct ct_sns_rsp *ct_rsp;
  188. struct qla_hw_data *ha = vha->hw;
  189. struct ct_arg arg;
  190. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  191. return qla2x00_sns_ga_nxt(vha, fcport);
  192. arg.iocb = ha->ms_iocb;
  193. arg.req_dma = ha->ct_sns_dma;
  194. arg.rsp_dma = ha->ct_sns_dma;
  195. arg.req_size = GA_NXT_REQ_SIZE;
  196. arg.rsp_size = GA_NXT_RSP_SIZE;
  197. arg.nport_handle = NPH_SNS;
  198. /* Issue GA_NXT */
  199. /* Prepare common MS IOCB */
  200. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  201. /* Prepare CT request */
  202. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GA_NXT_CMD,
  203. GA_NXT_RSP_SIZE);
  204. ct_rsp = &ha->ct_sns->p.rsp;
  205. /* Prepare CT arguments -- port_id */
  206. ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
  207. ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
  208. ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
  209. /* Execute MS IOCB */
  210. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  211. sizeof(ms_iocb_entry_t));
  212. if (rval != QLA_SUCCESS) {
  213. /*EMPTY*/
  214. ql_dbg(ql_dbg_disc, vha, 0x2062,
  215. "GA_NXT issue IOCB failed (%d).\n", rval);
  216. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GA_NXT") !=
  217. QLA_SUCCESS) {
  218. rval = QLA_FUNCTION_FAILED;
  219. } else {
  220. /* Populate fc_port_t entry. */
  221. fcport->d_id.b.domain = ct_rsp->rsp.ga_nxt.port_id[0];
  222. fcport->d_id.b.area = ct_rsp->rsp.ga_nxt.port_id[1];
  223. fcport->d_id.b.al_pa = ct_rsp->rsp.ga_nxt.port_id[2];
  224. memcpy(fcport->node_name, ct_rsp->rsp.ga_nxt.node_name,
  225. WWN_SIZE);
  226. memcpy(fcport->port_name, ct_rsp->rsp.ga_nxt.port_name,
  227. WWN_SIZE);
  228. fcport->fc4_type = (ct_rsp->rsp.ga_nxt.fc4_types[2] & BIT_0) ?
  229. FC4_TYPE_FCP_SCSI : FC4_TYPE_OTHER;
  230. if (ct_rsp->rsp.ga_nxt.port_type != NS_N_PORT_TYPE &&
  231. ct_rsp->rsp.ga_nxt.port_type != NS_NL_PORT_TYPE)
  232. fcport->d_id.b.domain = 0xf0;
  233. ql_dbg(ql_dbg_disc, vha, 0x2063,
  234. "GA_NXT entry - nn %8phN pn %8phN "
  235. "port_id=%02x%02x%02x.\n",
  236. fcport->node_name, fcport->port_name,
  237. fcport->d_id.b.domain, fcport->d_id.b.area,
  238. fcport->d_id.b.al_pa);
  239. }
  240. return (rval);
  241. }
  242. static inline int
  243. qla2x00_gid_pt_rsp_size(scsi_qla_host_t *vha)
  244. {
  245. return vha->hw->max_fibre_devices * 4 + 16;
  246. }
  247. /**
  248. * qla2x00_gid_pt() - SNS scan for fabric devices via GID_PT command.
  249. * @vha: HA context
  250. * @list: switch info entries to populate
  251. *
  252. * NOTE: Non-Nx_Ports are not requested.
  253. *
  254. * Returns 0 on success.
  255. */
  256. int
  257. qla2x00_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
  258. {
  259. int rval;
  260. uint16_t i;
  261. ms_iocb_entry_t *ms_pkt;
  262. struct ct_sns_req *ct_req;
  263. struct ct_sns_rsp *ct_rsp;
  264. struct ct_sns_gid_pt_data *gid_data;
  265. struct qla_hw_data *ha = vha->hw;
  266. uint16_t gid_pt_rsp_size;
  267. struct ct_arg arg;
  268. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  269. return qla2x00_sns_gid_pt(vha, list);
  270. gid_data = NULL;
  271. gid_pt_rsp_size = qla2x00_gid_pt_rsp_size(vha);
  272. arg.iocb = ha->ms_iocb;
  273. arg.req_dma = ha->ct_sns_dma;
  274. arg.rsp_dma = ha->ct_sns_dma;
  275. arg.req_size = GID_PT_REQ_SIZE;
  276. arg.rsp_size = gid_pt_rsp_size;
  277. arg.nport_handle = NPH_SNS;
  278. /* Issue GID_PT */
  279. /* Prepare common MS IOCB */
  280. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  281. /* Prepare CT request */
  282. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GID_PT_CMD, gid_pt_rsp_size);
  283. ct_rsp = &ha->ct_sns->p.rsp;
  284. /* Prepare CT arguments -- port_type */
  285. ct_req->req.gid_pt.port_type = NS_NX_PORT_TYPE;
  286. /* Execute MS IOCB */
  287. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  288. sizeof(ms_iocb_entry_t));
  289. if (rval != QLA_SUCCESS) {
  290. /*EMPTY*/
  291. ql_dbg(ql_dbg_disc, vha, 0x2055,
  292. "GID_PT issue IOCB failed (%d).\n", rval);
  293. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "GID_PT") !=
  294. QLA_SUCCESS) {
  295. rval = QLA_FUNCTION_FAILED;
  296. } else {
  297. /* Set port IDs in switch info list. */
  298. for (i = 0; i < ha->max_fibre_devices; i++) {
  299. gid_data = &ct_rsp->rsp.gid_pt.entries[i];
  300. list[i].d_id.b.domain = gid_data->port_id[0];
  301. list[i].d_id.b.area = gid_data->port_id[1];
  302. list[i].d_id.b.al_pa = gid_data->port_id[2];
  303. memset(list[i].fabric_port_name, 0, WWN_SIZE);
  304. list[i].fp_speed = PORT_SPEED_UNKNOWN;
  305. /* Last one exit. */
  306. if (gid_data->control_byte & BIT_7) {
  307. list[i].d_id.b.rsvd_1 = gid_data->control_byte;
  308. break;
  309. }
  310. }
  311. /*
  312. * If we've used all available slots, then the switch is
  313. * reporting back more devices than we can handle with this
  314. * single call. Return a failed status, and let GA_NXT handle
  315. * the overload.
  316. */
  317. if (i == ha->max_fibre_devices)
  318. rval = QLA_FUNCTION_FAILED;
  319. }
  320. return (rval);
  321. }
  322. /**
  323. * qla2x00_gpn_id() - SNS Get Port Name (GPN_ID) query.
  324. * @vha: HA context
  325. * @list: switch info entries to populate
  326. *
  327. * Returns 0 on success.
  328. */
  329. int
  330. qla2x00_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  331. {
  332. int rval = QLA_SUCCESS;
  333. uint16_t i;
  334. ms_iocb_entry_t *ms_pkt;
  335. struct ct_sns_req *ct_req;
  336. struct ct_sns_rsp *ct_rsp;
  337. struct qla_hw_data *ha = vha->hw;
  338. struct ct_arg arg;
  339. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  340. return qla2x00_sns_gpn_id(vha, list);
  341. arg.iocb = ha->ms_iocb;
  342. arg.req_dma = ha->ct_sns_dma;
  343. arg.rsp_dma = ha->ct_sns_dma;
  344. arg.req_size = GPN_ID_REQ_SIZE;
  345. arg.rsp_size = GPN_ID_RSP_SIZE;
  346. arg.nport_handle = NPH_SNS;
  347. for (i = 0; i < ha->max_fibre_devices; i++) {
  348. /* Issue GPN_ID */
  349. /* Prepare common MS IOCB */
  350. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  351. /* Prepare CT request */
  352. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GPN_ID_CMD,
  353. GPN_ID_RSP_SIZE);
  354. ct_rsp = &ha->ct_sns->p.rsp;
  355. /* Prepare CT arguments -- port_id */
  356. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  357. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  358. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  359. /* Execute MS IOCB */
  360. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  361. sizeof(ms_iocb_entry_t));
  362. if (rval != QLA_SUCCESS) {
  363. /*EMPTY*/
  364. ql_dbg(ql_dbg_disc, vha, 0x2056,
  365. "GPN_ID issue IOCB failed (%d).\n", rval);
  366. break;
  367. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  368. "GPN_ID") != QLA_SUCCESS) {
  369. rval = QLA_FUNCTION_FAILED;
  370. break;
  371. } else {
  372. /* Save portname */
  373. memcpy(list[i].port_name,
  374. ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
  375. }
  376. /* Last device exit. */
  377. if (list[i].d_id.b.rsvd_1 != 0)
  378. break;
  379. }
  380. return (rval);
  381. }
  382. /**
  383. * qla2x00_gnn_id() - SNS Get Node Name (GNN_ID) query.
  384. * @vha: HA context
  385. * @list: switch info entries to populate
  386. *
  387. * Returns 0 on success.
  388. */
  389. int
  390. qla2x00_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
  391. {
  392. int rval = QLA_SUCCESS;
  393. uint16_t i;
  394. struct qla_hw_data *ha = vha->hw;
  395. ms_iocb_entry_t *ms_pkt;
  396. struct ct_sns_req *ct_req;
  397. struct ct_sns_rsp *ct_rsp;
  398. struct ct_arg arg;
  399. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  400. return qla2x00_sns_gnn_id(vha, list);
  401. arg.iocb = ha->ms_iocb;
  402. arg.req_dma = ha->ct_sns_dma;
  403. arg.rsp_dma = ha->ct_sns_dma;
  404. arg.req_size = GNN_ID_REQ_SIZE;
  405. arg.rsp_size = GNN_ID_RSP_SIZE;
  406. arg.nport_handle = NPH_SNS;
  407. for (i = 0; i < ha->max_fibre_devices; i++) {
  408. /* Issue GNN_ID */
  409. /* Prepare common MS IOCB */
  410. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  411. /* Prepare CT request */
  412. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GNN_ID_CMD,
  413. GNN_ID_RSP_SIZE);
  414. ct_rsp = &ha->ct_sns->p.rsp;
  415. /* Prepare CT arguments -- port_id */
  416. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  417. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  418. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  419. /* Execute MS IOCB */
  420. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  421. sizeof(ms_iocb_entry_t));
  422. if (rval != QLA_SUCCESS) {
  423. /*EMPTY*/
  424. ql_dbg(ql_dbg_disc, vha, 0x2057,
  425. "GNN_ID issue IOCB failed (%d).\n", rval);
  426. break;
  427. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  428. "GNN_ID") != QLA_SUCCESS) {
  429. rval = QLA_FUNCTION_FAILED;
  430. break;
  431. } else {
  432. /* Save nodename */
  433. memcpy(list[i].node_name,
  434. ct_rsp->rsp.gnn_id.node_name, WWN_SIZE);
  435. ql_dbg(ql_dbg_disc, vha, 0x2058,
  436. "GID_PT entry - nn %8phN pn %8phN "
  437. "portid=%02x%02x%02x.\n",
  438. list[i].node_name, list[i].port_name,
  439. list[i].d_id.b.domain, list[i].d_id.b.area,
  440. list[i].d_id.b.al_pa);
  441. }
  442. /* Last device exit. */
  443. if (list[i].d_id.b.rsvd_1 != 0)
  444. break;
  445. }
  446. return (rval);
  447. }
  448. static void qla2x00_async_sns_sp_done(void *s, int rc)
  449. {
  450. struct srb *sp = s;
  451. struct scsi_qla_host *vha = sp->vha;
  452. struct ct_sns_pkt *ct_sns;
  453. struct qla_work_evt *e;
  454. sp->rc = rc;
  455. if (rc == QLA_SUCCESS) {
  456. ql_dbg(ql_dbg_disc, vha, 0x204f,
  457. "Async done-%s exiting normally.\n",
  458. sp->name);
  459. } else if (rc == QLA_FUNCTION_TIMEOUT) {
  460. ql_dbg(ql_dbg_disc, vha, 0x204f,
  461. "Async done-%s timeout\n", sp->name);
  462. } else {
  463. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  464. memset(ct_sns, 0, sizeof(*ct_sns));
  465. sp->retry_count++;
  466. if (sp->retry_count > 3)
  467. goto err;
  468. ql_dbg(ql_dbg_disc, vha, 0x204f,
  469. "Async done-%s fail rc %x. Retry count %d\n",
  470. sp->name, rc, sp->retry_count);
  471. e = qla2x00_alloc_work(vha, QLA_EVT_SP_RETRY);
  472. if (!e)
  473. goto err2;
  474. del_timer(&sp->u.iocb_cmd.timer);
  475. e->u.iosb.sp = sp;
  476. qla2x00_post_work(vha, e);
  477. return;
  478. }
  479. err:
  480. e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP);
  481. err2:
  482. if (!e) {
  483. /* please ignore kernel warning. otherwise, we have mem leak. */
  484. if (sp->u.iocb_cmd.u.ctarg.req) {
  485. dma_free_coherent(&vha->hw->pdev->dev,
  486. sp->u.iocb_cmd.u.ctarg.req_allocated_size,
  487. sp->u.iocb_cmd.u.ctarg.req,
  488. sp->u.iocb_cmd.u.ctarg.req_dma);
  489. sp->u.iocb_cmd.u.ctarg.req = NULL;
  490. }
  491. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  492. dma_free_coherent(&vha->hw->pdev->dev,
  493. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
  494. sp->u.iocb_cmd.u.ctarg.rsp,
  495. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  496. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  497. }
  498. sp->free(sp);
  499. return;
  500. }
  501. e->u.iosb.sp = sp;
  502. qla2x00_post_work(vha, e);
  503. }
  504. /**
  505. * qla2x00_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  506. * @vha: HA context
  507. *
  508. * Returns 0 on success.
  509. */
  510. int
  511. qla2x00_rft_id(scsi_qla_host_t *vha)
  512. {
  513. struct qla_hw_data *ha = vha->hw;
  514. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  515. return qla2x00_sns_rft_id(vha);
  516. return qla_async_rftid(vha, &vha->d_id);
  517. }
  518. static int qla_async_rftid(scsi_qla_host_t *vha, port_id_t *d_id)
  519. {
  520. int rval = QLA_MEMORY_ALLOC_FAILED;
  521. struct ct_sns_req *ct_req;
  522. srb_t *sp;
  523. struct ct_sns_pkt *ct_sns;
  524. if (!vha->flags.online)
  525. goto done;
  526. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  527. if (!sp)
  528. goto done;
  529. sp->type = SRB_CT_PTHRU_CMD;
  530. sp->name = "rft_id";
  531. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  532. sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
  533. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
  534. GFP_KERNEL);
  535. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  536. if (!sp->u.iocb_cmd.u.ctarg.req) {
  537. ql_log(ql_log_warn, vha, 0xd041,
  538. "%s: Failed to allocate ct_sns request.\n",
  539. __func__);
  540. goto done_free_sp;
  541. }
  542. sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
  543. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
  544. GFP_KERNEL);
  545. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  546. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  547. ql_log(ql_log_warn, vha, 0xd042,
  548. "%s: Failed to allocate ct_sns request.\n",
  549. __func__);
  550. goto done_free_sp;
  551. }
  552. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  553. memset(ct_sns, 0, sizeof(*ct_sns));
  554. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  555. /* Prepare CT request */
  556. ct_req = qla2x00_prep_ct_req(ct_sns, RFT_ID_CMD, RFT_ID_RSP_SIZE);
  557. /* Prepare CT arguments -- port_id, FC-4 types */
  558. ct_req->req.rft_id.port_id[0] = vha->d_id.b.domain;
  559. ct_req->req.rft_id.port_id[1] = vha->d_id.b.area;
  560. ct_req->req.rft_id.port_id[2] = vha->d_id.b.al_pa;
  561. ct_req->req.rft_id.fc4_types[2] = 0x01; /* FCP-3 */
  562. if (vha->flags.nvme_enabled)
  563. ct_req->req.rft_id.fc4_types[6] = 1; /* NVMe type 28h */
  564. sp->u.iocb_cmd.u.ctarg.req_size = RFT_ID_REQ_SIZE;
  565. sp->u.iocb_cmd.u.ctarg.rsp_size = RFT_ID_RSP_SIZE;
  566. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  567. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  568. sp->done = qla2x00_async_sns_sp_done;
  569. rval = qla2x00_start_sp(sp);
  570. if (rval != QLA_SUCCESS) {
  571. ql_dbg(ql_dbg_disc, vha, 0x2043,
  572. "RFT_ID issue IOCB failed (%d).\n", rval);
  573. goto done_free_sp;
  574. }
  575. ql_dbg(ql_dbg_disc, vha, 0xffff,
  576. "Async-%s - hdl=%x portid %06x.\n",
  577. sp->name, sp->handle, d_id->b24);
  578. return rval;
  579. done_free_sp:
  580. sp->free(sp);
  581. done:
  582. return rval;
  583. }
  584. /**
  585. * qla2x00_rff_id() - SNS Register FC-4 Features (RFF_ID) supported by the HBA.
  586. * @vha: HA context
  587. * @type: not used
  588. *
  589. * Returns 0 on success.
  590. */
  591. int
  592. qla2x00_rff_id(scsi_qla_host_t *vha, u8 type)
  593. {
  594. struct qla_hw_data *ha = vha->hw;
  595. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  596. ql_dbg(ql_dbg_disc, vha, 0x2046,
  597. "RFF_ID call not supported on ISP2100/ISP2200.\n");
  598. return (QLA_SUCCESS);
  599. }
  600. return qla_async_rffid(vha, &vha->d_id, qlt_rff_id(vha),
  601. FC4_TYPE_FCP_SCSI);
  602. }
  603. static int qla_async_rffid(scsi_qla_host_t *vha, port_id_t *d_id,
  604. u8 fc4feature, u8 fc4type)
  605. {
  606. int rval = QLA_MEMORY_ALLOC_FAILED;
  607. struct ct_sns_req *ct_req;
  608. srb_t *sp;
  609. struct ct_sns_pkt *ct_sns;
  610. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  611. if (!sp)
  612. goto done;
  613. sp->type = SRB_CT_PTHRU_CMD;
  614. sp->name = "rff_id";
  615. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  616. sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
  617. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
  618. GFP_KERNEL);
  619. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  620. if (!sp->u.iocb_cmd.u.ctarg.req) {
  621. ql_log(ql_log_warn, vha, 0xd041,
  622. "%s: Failed to allocate ct_sns request.\n",
  623. __func__);
  624. goto done_free_sp;
  625. }
  626. sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
  627. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
  628. GFP_KERNEL);
  629. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  630. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  631. ql_log(ql_log_warn, vha, 0xd042,
  632. "%s: Failed to allocate ct_sns request.\n",
  633. __func__);
  634. goto done_free_sp;
  635. }
  636. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  637. memset(ct_sns, 0, sizeof(*ct_sns));
  638. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  639. /* Prepare CT request */
  640. ct_req = qla2x00_prep_ct_req(ct_sns, RFF_ID_CMD, RFF_ID_RSP_SIZE);
  641. /* Prepare CT arguments -- port_id, FC-4 feature, FC-4 type */
  642. ct_req->req.rff_id.port_id[0] = d_id->b.domain;
  643. ct_req->req.rff_id.port_id[1] = d_id->b.area;
  644. ct_req->req.rff_id.port_id[2] = d_id->b.al_pa;
  645. ct_req->req.rff_id.fc4_feature = fc4feature;
  646. ct_req->req.rff_id.fc4_type = fc4type; /* SCSI - FCP */
  647. sp->u.iocb_cmd.u.ctarg.req_size = RFF_ID_REQ_SIZE;
  648. sp->u.iocb_cmd.u.ctarg.rsp_size = RFF_ID_RSP_SIZE;
  649. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  650. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  651. sp->done = qla2x00_async_sns_sp_done;
  652. rval = qla2x00_start_sp(sp);
  653. if (rval != QLA_SUCCESS) {
  654. ql_dbg(ql_dbg_disc, vha, 0x2047,
  655. "RFF_ID issue IOCB failed (%d).\n", rval);
  656. goto done_free_sp;
  657. }
  658. ql_dbg(ql_dbg_disc, vha, 0xffff,
  659. "Async-%s - hdl=%x portid %06x feature %x type %x.\n",
  660. sp->name, sp->handle, d_id->b24, fc4feature, fc4type);
  661. return rval;
  662. done_free_sp:
  663. sp->free(sp);
  664. done:
  665. return rval;
  666. }
  667. /**
  668. * qla2x00_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  669. * @vha: HA context
  670. *
  671. * Returns 0 on success.
  672. */
  673. int
  674. qla2x00_rnn_id(scsi_qla_host_t *vha)
  675. {
  676. struct qla_hw_data *ha = vha->hw;
  677. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  678. return qla2x00_sns_rnn_id(vha);
  679. return qla_async_rnnid(vha, &vha->d_id, vha->node_name);
  680. }
  681. static int qla_async_rnnid(scsi_qla_host_t *vha, port_id_t *d_id,
  682. u8 *node_name)
  683. {
  684. int rval = QLA_MEMORY_ALLOC_FAILED;
  685. struct ct_sns_req *ct_req;
  686. srb_t *sp;
  687. struct ct_sns_pkt *ct_sns;
  688. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  689. if (!sp)
  690. goto done;
  691. sp->type = SRB_CT_PTHRU_CMD;
  692. sp->name = "rnid";
  693. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  694. sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
  695. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
  696. GFP_KERNEL);
  697. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  698. if (!sp->u.iocb_cmd.u.ctarg.req) {
  699. ql_log(ql_log_warn, vha, 0xd041,
  700. "%s: Failed to allocate ct_sns request.\n",
  701. __func__);
  702. goto done_free_sp;
  703. }
  704. sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
  705. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
  706. GFP_KERNEL);
  707. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  708. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  709. ql_log(ql_log_warn, vha, 0xd042,
  710. "%s: Failed to allocate ct_sns request.\n",
  711. __func__);
  712. goto done_free_sp;
  713. }
  714. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  715. memset(ct_sns, 0, sizeof(*ct_sns));
  716. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  717. /* Prepare CT request */
  718. ct_req = qla2x00_prep_ct_req(ct_sns, RNN_ID_CMD, RNN_ID_RSP_SIZE);
  719. /* Prepare CT arguments -- port_id, node_name */
  720. ct_req->req.rnn_id.port_id[0] = vha->d_id.b.domain;
  721. ct_req->req.rnn_id.port_id[1] = vha->d_id.b.area;
  722. ct_req->req.rnn_id.port_id[2] = vha->d_id.b.al_pa;
  723. memcpy(ct_req->req.rnn_id.node_name, vha->node_name, WWN_SIZE);
  724. sp->u.iocb_cmd.u.ctarg.req_size = RNN_ID_REQ_SIZE;
  725. sp->u.iocb_cmd.u.ctarg.rsp_size = RNN_ID_RSP_SIZE;
  726. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  727. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  728. sp->done = qla2x00_async_sns_sp_done;
  729. rval = qla2x00_start_sp(sp);
  730. if (rval != QLA_SUCCESS) {
  731. ql_dbg(ql_dbg_disc, vha, 0x204d,
  732. "RNN_ID issue IOCB failed (%d).\n", rval);
  733. goto done_free_sp;
  734. }
  735. ql_dbg(ql_dbg_disc, vha, 0xffff,
  736. "Async-%s - hdl=%x portid %06x\n",
  737. sp->name, sp->handle, d_id->b24);
  738. return rval;
  739. done_free_sp:
  740. sp->free(sp);
  741. done:
  742. return rval;
  743. }
  744. void
  745. qla2x00_get_sym_node_name(scsi_qla_host_t *vha, uint8_t *snn, size_t size)
  746. {
  747. struct qla_hw_data *ha = vha->hw;
  748. if (IS_QLAFX00(ha))
  749. snprintf(snn, size, "%s FW:v%s DVR:v%s", ha->model_number,
  750. ha->mr.fw_version, qla2x00_version_str);
  751. else
  752. snprintf(snn, size,
  753. "%s FW:v%d.%02d.%02d DVR:v%s", ha->model_number,
  754. ha->fw_major_version, ha->fw_minor_version,
  755. ha->fw_subminor_version, qla2x00_version_str);
  756. }
  757. /**
  758. * qla2x00_rsnn_nn() - SNS Register Symbolic Node Name (RSNN_NN) of the HBA.
  759. * @vha: HA context
  760. *
  761. * Returns 0 on success.
  762. */
  763. int
  764. qla2x00_rsnn_nn(scsi_qla_host_t *vha)
  765. {
  766. struct qla_hw_data *ha = vha->hw;
  767. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  768. ql_dbg(ql_dbg_disc, vha, 0x2050,
  769. "RSNN_ID call unsupported on ISP2100/ISP2200.\n");
  770. return (QLA_SUCCESS);
  771. }
  772. return qla_async_rsnn_nn(vha);
  773. }
  774. static int qla_async_rsnn_nn(scsi_qla_host_t *vha)
  775. {
  776. int rval = QLA_MEMORY_ALLOC_FAILED;
  777. struct ct_sns_req *ct_req;
  778. srb_t *sp;
  779. struct ct_sns_pkt *ct_sns;
  780. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  781. if (!sp)
  782. goto done;
  783. sp->type = SRB_CT_PTHRU_CMD;
  784. sp->name = "rsnn_nn";
  785. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  786. sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
  787. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
  788. GFP_KERNEL);
  789. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  790. if (!sp->u.iocb_cmd.u.ctarg.req) {
  791. ql_log(ql_log_warn, vha, 0xd041,
  792. "%s: Failed to allocate ct_sns request.\n",
  793. __func__);
  794. goto done_free_sp;
  795. }
  796. sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
  797. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
  798. GFP_KERNEL);
  799. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  800. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  801. ql_log(ql_log_warn, vha, 0xd042,
  802. "%s: Failed to allocate ct_sns request.\n",
  803. __func__);
  804. goto done_free_sp;
  805. }
  806. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  807. memset(ct_sns, 0, sizeof(*ct_sns));
  808. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  809. /* Prepare CT request */
  810. ct_req = qla2x00_prep_ct_req(ct_sns, RSNN_NN_CMD, RSNN_NN_RSP_SIZE);
  811. /* Prepare CT arguments -- node_name, symbolic node_name, size */
  812. memcpy(ct_req->req.rsnn_nn.node_name, vha->node_name, WWN_SIZE);
  813. /* Prepare the Symbolic Node Name */
  814. qla2x00_get_sym_node_name(vha, ct_req->req.rsnn_nn.sym_node_name,
  815. sizeof(ct_req->req.rsnn_nn.sym_node_name));
  816. ct_req->req.rsnn_nn.name_len =
  817. (uint8_t)strlen(ct_req->req.rsnn_nn.sym_node_name);
  818. sp->u.iocb_cmd.u.ctarg.req_size = 24 + 1 + ct_req->req.rsnn_nn.name_len;
  819. sp->u.iocb_cmd.u.ctarg.rsp_size = RSNN_NN_RSP_SIZE;
  820. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  821. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  822. sp->done = qla2x00_async_sns_sp_done;
  823. rval = qla2x00_start_sp(sp);
  824. if (rval != QLA_SUCCESS) {
  825. ql_dbg(ql_dbg_disc, vha, 0x2043,
  826. "RFT_ID issue IOCB failed (%d).\n", rval);
  827. goto done_free_sp;
  828. }
  829. ql_dbg(ql_dbg_disc, vha, 0xffff,
  830. "Async-%s - hdl=%x.\n",
  831. sp->name, sp->handle);
  832. return rval;
  833. done_free_sp:
  834. sp->free(sp);
  835. done:
  836. return rval;
  837. }
  838. /**
  839. * qla2x00_prep_sns_cmd() - Prepare common SNS command request fields for query.
  840. * @vha: HA context
  841. * @cmd: GS command
  842. * @scmd_len: Subcommand length
  843. * @data_size: response size in bytes
  844. *
  845. * Returns a pointer to the @ha's sns_cmd.
  846. */
  847. static inline struct sns_cmd_pkt *
  848. qla2x00_prep_sns_cmd(scsi_qla_host_t *vha, uint16_t cmd, uint16_t scmd_len,
  849. uint16_t data_size)
  850. {
  851. uint16_t wc;
  852. struct sns_cmd_pkt *sns_cmd;
  853. struct qla_hw_data *ha = vha->hw;
  854. sns_cmd = ha->sns_cmd;
  855. memset(sns_cmd, 0, sizeof(struct sns_cmd_pkt));
  856. wc = data_size / 2; /* Size in 16bit words. */
  857. sns_cmd->p.cmd.buffer_length = cpu_to_le16(wc);
  858. sns_cmd->p.cmd.buffer_address[0] = cpu_to_le32(LSD(ha->sns_cmd_dma));
  859. sns_cmd->p.cmd.buffer_address[1] = cpu_to_le32(MSD(ha->sns_cmd_dma));
  860. sns_cmd->p.cmd.subcommand_length = cpu_to_le16(scmd_len);
  861. sns_cmd->p.cmd.subcommand = cpu_to_le16(cmd);
  862. wc = (data_size - 16) / 4; /* Size in 32bit words. */
  863. sns_cmd->p.cmd.size = cpu_to_le16(wc);
  864. vha->qla_stats.control_requests++;
  865. return (sns_cmd);
  866. }
  867. /**
  868. * qla2x00_sns_ga_nxt() - SNS scan for fabric devices via GA_NXT command.
  869. * @vha: HA context
  870. * @fcport: fcport entry to updated
  871. *
  872. * This command uses the old Exectute SNS Command mailbox routine.
  873. *
  874. * Returns 0 on success.
  875. */
  876. static int
  877. qla2x00_sns_ga_nxt(scsi_qla_host_t *vha, fc_port_t *fcport)
  878. {
  879. int rval = QLA_SUCCESS;
  880. struct qla_hw_data *ha = vha->hw;
  881. struct sns_cmd_pkt *sns_cmd;
  882. /* Issue GA_NXT. */
  883. /* Prepare SNS command request. */
  884. sns_cmd = qla2x00_prep_sns_cmd(vha, GA_NXT_CMD, GA_NXT_SNS_SCMD_LEN,
  885. GA_NXT_SNS_DATA_SIZE);
  886. /* Prepare SNS command arguments -- port_id. */
  887. sns_cmd->p.cmd.param[0] = fcport->d_id.b.al_pa;
  888. sns_cmd->p.cmd.param[1] = fcport->d_id.b.area;
  889. sns_cmd->p.cmd.param[2] = fcport->d_id.b.domain;
  890. /* Execute SNS command. */
  891. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GA_NXT_SNS_CMD_SIZE / 2,
  892. sizeof(struct sns_cmd_pkt));
  893. if (rval != QLA_SUCCESS) {
  894. /*EMPTY*/
  895. ql_dbg(ql_dbg_disc, vha, 0x205f,
  896. "GA_NXT Send SNS failed (%d).\n", rval);
  897. } else if (sns_cmd->p.gan_data[8] != 0x80 ||
  898. sns_cmd->p.gan_data[9] != 0x02) {
  899. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2084,
  900. "GA_NXT failed, rejected request ga_nxt_rsp:\n");
  901. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2074,
  902. sns_cmd->p.gan_data, 16);
  903. rval = QLA_FUNCTION_FAILED;
  904. } else {
  905. /* Populate fc_port_t entry. */
  906. fcport->d_id.b.domain = sns_cmd->p.gan_data[17];
  907. fcport->d_id.b.area = sns_cmd->p.gan_data[18];
  908. fcport->d_id.b.al_pa = sns_cmd->p.gan_data[19];
  909. memcpy(fcport->node_name, &sns_cmd->p.gan_data[284], WWN_SIZE);
  910. memcpy(fcport->port_name, &sns_cmd->p.gan_data[20], WWN_SIZE);
  911. if (sns_cmd->p.gan_data[16] != NS_N_PORT_TYPE &&
  912. sns_cmd->p.gan_data[16] != NS_NL_PORT_TYPE)
  913. fcport->d_id.b.domain = 0xf0;
  914. ql_dbg(ql_dbg_disc, vha, 0x2061,
  915. "GA_NXT entry - nn %8phN pn %8phN "
  916. "port_id=%02x%02x%02x.\n",
  917. fcport->node_name, fcport->port_name,
  918. fcport->d_id.b.domain, fcport->d_id.b.area,
  919. fcport->d_id.b.al_pa);
  920. }
  921. return (rval);
  922. }
  923. /**
  924. * qla2x00_sns_gid_pt() - SNS scan for fabric devices via GID_PT command.
  925. * @vha: HA context
  926. * @list: switch info entries to populate
  927. *
  928. * This command uses the old Exectute SNS Command mailbox routine.
  929. *
  930. * NOTE: Non-Nx_Ports are not requested.
  931. *
  932. * Returns 0 on success.
  933. */
  934. static int
  935. qla2x00_sns_gid_pt(scsi_qla_host_t *vha, sw_info_t *list)
  936. {
  937. int rval;
  938. struct qla_hw_data *ha = vha->hw;
  939. uint16_t i;
  940. uint8_t *entry;
  941. struct sns_cmd_pkt *sns_cmd;
  942. uint16_t gid_pt_sns_data_size;
  943. gid_pt_sns_data_size = qla2x00_gid_pt_rsp_size(vha);
  944. /* Issue GID_PT. */
  945. /* Prepare SNS command request. */
  946. sns_cmd = qla2x00_prep_sns_cmd(vha, GID_PT_CMD, GID_PT_SNS_SCMD_LEN,
  947. gid_pt_sns_data_size);
  948. /* Prepare SNS command arguments -- port_type. */
  949. sns_cmd->p.cmd.param[0] = NS_NX_PORT_TYPE;
  950. /* Execute SNS command. */
  951. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, GID_PT_SNS_CMD_SIZE / 2,
  952. sizeof(struct sns_cmd_pkt));
  953. if (rval != QLA_SUCCESS) {
  954. /*EMPTY*/
  955. ql_dbg(ql_dbg_disc, vha, 0x206d,
  956. "GID_PT Send SNS failed (%d).\n", rval);
  957. } else if (sns_cmd->p.gid_data[8] != 0x80 ||
  958. sns_cmd->p.gid_data[9] != 0x02) {
  959. ql_dbg(ql_dbg_disc, vha, 0x202f,
  960. "GID_PT failed, rejected request, gid_rsp:\n");
  961. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2081,
  962. sns_cmd->p.gid_data, 16);
  963. rval = QLA_FUNCTION_FAILED;
  964. } else {
  965. /* Set port IDs in switch info list. */
  966. for (i = 0; i < ha->max_fibre_devices; i++) {
  967. entry = &sns_cmd->p.gid_data[(i * 4) + 16];
  968. list[i].d_id.b.domain = entry[1];
  969. list[i].d_id.b.area = entry[2];
  970. list[i].d_id.b.al_pa = entry[3];
  971. /* Last one exit. */
  972. if (entry[0] & BIT_7) {
  973. list[i].d_id.b.rsvd_1 = entry[0];
  974. break;
  975. }
  976. }
  977. /*
  978. * If we've used all available slots, then the switch is
  979. * reporting back more devices that we can handle with this
  980. * single call. Return a failed status, and let GA_NXT handle
  981. * the overload.
  982. */
  983. if (i == ha->max_fibre_devices)
  984. rval = QLA_FUNCTION_FAILED;
  985. }
  986. return (rval);
  987. }
  988. /**
  989. * qla2x00_sns_gpn_id() - SNS Get Port Name (GPN_ID) query.
  990. * @vha: HA context
  991. * @list: switch info entries to populate
  992. *
  993. * This command uses the old Exectute SNS Command mailbox routine.
  994. *
  995. * Returns 0 on success.
  996. */
  997. static int
  998. qla2x00_sns_gpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  999. {
  1000. int rval = QLA_SUCCESS;
  1001. struct qla_hw_data *ha = vha->hw;
  1002. uint16_t i;
  1003. struct sns_cmd_pkt *sns_cmd;
  1004. for (i = 0; i < ha->max_fibre_devices; i++) {
  1005. /* Issue GPN_ID */
  1006. /* Prepare SNS command request. */
  1007. sns_cmd = qla2x00_prep_sns_cmd(vha, GPN_ID_CMD,
  1008. GPN_ID_SNS_SCMD_LEN, GPN_ID_SNS_DATA_SIZE);
  1009. /* Prepare SNS command arguments -- port_id. */
  1010. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  1011. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  1012. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  1013. /* Execute SNS command. */
  1014. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
  1015. GPN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  1016. if (rval != QLA_SUCCESS) {
  1017. /*EMPTY*/
  1018. ql_dbg(ql_dbg_disc, vha, 0x2032,
  1019. "GPN_ID Send SNS failed (%d).\n", rval);
  1020. } else if (sns_cmd->p.gpn_data[8] != 0x80 ||
  1021. sns_cmd->p.gpn_data[9] != 0x02) {
  1022. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207e,
  1023. "GPN_ID failed, rejected request, gpn_rsp:\n");
  1024. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207f,
  1025. sns_cmd->p.gpn_data, 16);
  1026. rval = QLA_FUNCTION_FAILED;
  1027. } else {
  1028. /* Save portname */
  1029. memcpy(list[i].port_name, &sns_cmd->p.gpn_data[16],
  1030. WWN_SIZE);
  1031. }
  1032. /* Last device exit. */
  1033. if (list[i].d_id.b.rsvd_1 != 0)
  1034. break;
  1035. }
  1036. return (rval);
  1037. }
  1038. /**
  1039. * qla2x00_sns_gnn_id() - SNS Get Node Name (GNN_ID) query.
  1040. * @vha: HA context
  1041. * @list: switch info entries to populate
  1042. *
  1043. * This command uses the old Exectute SNS Command mailbox routine.
  1044. *
  1045. * Returns 0 on success.
  1046. */
  1047. static int
  1048. qla2x00_sns_gnn_id(scsi_qla_host_t *vha, sw_info_t *list)
  1049. {
  1050. int rval = QLA_SUCCESS;
  1051. struct qla_hw_data *ha = vha->hw;
  1052. uint16_t i;
  1053. struct sns_cmd_pkt *sns_cmd;
  1054. for (i = 0; i < ha->max_fibre_devices; i++) {
  1055. /* Issue GNN_ID */
  1056. /* Prepare SNS command request. */
  1057. sns_cmd = qla2x00_prep_sns_cmd(vha, GNN_ID_CMD,
  1058. GNN_ID_SNS_SCMD_LEN, GNN_ID_SNS_DATA_SIZE);
  1059. /* Prepare SNS command arguments -- port_id. */
  1060. sns_cmd->p.cmd.param[0] = list[i].d_id.b.al_pa;
  1061. sns_cmd->p.cmd.param[1] = list[i].d_id.b.area;
  1062. sns_cmd->p.cmd.param[2] = list[i].d_id.b.domain;
  1063. /* Execute SNS command. */
  1064. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma,
  1065. GNN_ID_SNS_CMD_SIZE / 2, sizeof(struct sns_cmd_pkt));
  1066. if (rval != QLA_SUCCESS) {
  1067. /*EMPTY*/
  1068. ql_dbg(ql_dbg_disc, vha, 0x203f,
  1069. "GNN_ID Send SNS failed (%d).\n", rval);
  1070. } else if (sns_cmd->p.gnn_data[8] != 0x80 ||
  1071. sns_cmd->p.gnn_data[9] != 0x02) {
  1072. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2082,
  1073. "GNN_ID failed, rejected request, gnn_rsp:\n");
  1074. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207a,
  1075. sns_cmd->p.gnn_data, 16);
  1076. rval = QLA_FUNCTION_FAILED;
  1077. } else {
  1078. /* Save nodename */
  1079. memcpy(list[i].node_name, &sns_cmd->p.gnn_data[16],
  1080. WWN_SIZE);
  1081. ql_dbg(ql_dbg_disc, vha, 0x206e,
  1082. "GID_PT entry - nn %8phN pn %8phN "
  1083. "port_id=%02x%02x%02x.\n",
  1084. list[i].node_name, list[i].port_name,
  1085. list[i].d_id.b.domain, list[i].d_id.b.area,
  1086. list[i].d_id.b.al_pa);
  1087. }
  1088. /* Last device exit. */
  1089. if (list[i].d_id.b.rsvd_1 != 0)
  1090. break;
  1091. }
  1092. return (rval);
  1093. }
  1094. /**
  1095. * qla2x00_snd_rft_id() - SNS Register FC-4 TYPEs (RFT_ID) supported by the HBA.
  1096. * @vha: HA context
  1097. *
  1098. * This command uses the old Exectute SNS Command mailbox routine.
  1099. *
  1100. * Returns 0 on success.
  1101. */
  1102. static int
  1103. qla2x00_sns_rft_id(scsi_qla_host_t *vha)
  1104. {
  1105. int rval;
  1106. struct qla_hw_data *ha = vha->hw;
  1107. struct sns_cmd_pkt *sns_cmd;
  1108. /* Issue RFT_ID. */
  1109. /* Prepare SNS command request. */
  1110. sns_cmd = qla2x00_prep_sns_cmd(vha, RFT_ID_CMD, RFT_ID_SNS_SCMD_LEN,
  1111. RFT_ID_SNS_DATA_SIZE);
  1112. /* Prepare SNS command arguments -- port_id, FC-4 types */
  1113. sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
  1114. sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
  1115. sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
  1116. sns_cmd->p.cmd.param[5] = 0x01; /* FCP-3 */
  1117. /* Execute SNS command. */
  1118. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RFT_ID_SNS_CMD_SIZE / 2,
  1119. sizeof(struct sns_cmd_pkt));
  1120. if (rval != QLA_SUCCESS) {
  1121. /*EMPTY*/
  1122. ql_dbg(ql_dbg_disc, vha, 0x2060,
  1123. "RFT_ID Send SNS failed (%d).\n", rval);
  1124. } else if (sns_cmd->p.rft_data[8] != 0x80 ||
  1125. sns_cmd->p.rft_data[9] != 0x02) {
  1126. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x2083,
  1127. "RFT_ID failed, rejected request rft_rsp:\n");
  1128. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2080,
  1129. sns_cmd->p.rft_data, 16);
  1130. rval = QLA_FUNCTION_FAILED;
  1131. } else {
  1132. ql_dbg(ql_dbg_disc, vha, 0x2073,
  1133. "RFT_ID exiting normally.\n");
  1134. }
  1135. return (rval);
  1136. }
  1137. /**
  1138. * qla2x00_sns_rnn_id() - SNS Register Node Name (RNN_ID) of the HBA.
  1139. * @vha: HA context
  1140. *
  1141. * This command uses the old Exectute SNS Command mailbox routine.
  1142. *
  1143. * Returns 0 on success.
  1144. */
  1145. static int
  1146. qla2x00_sns_rnn_id(scsi_qla_host_t *vha)
  1147. {
  1148. int rval;
  1149. struct qla_hw_data *ha = vha->hw;
  1150. struct sns_cmd_pkt *sns_cmd;
  1151. /* Issue RNN_ID. */
  1152. /* Prepare SNS command request. */
  1153. sns_cmd = qla2x00_prep_sns_cmd(vha, RNN_ID_CMD, RNN_ID_SNS_SCMD_LEN,
  1154. RNN_ID_SNS_DATA_SIZE);
  1155. /* Prepare SNS command arguments -- port_id, nodename. */
  1156. sns_cmd->p.cmd.param[0] = vha->d_id.b.al_pa;
  1157. sns_cmd->p.cmd.param[1] = vha->d_id.b.area;
  1158. sns_cmd->p.cmd.param[2] = vha->d_id.b.domain;
  1159. sns_cmd->p.cmd.param[4] = vha->node_name[7];
  1160. sns_cmd->p.cmd.param[5] = vha->node_name[6];
  1161. sns_cmd->p.cmd.param[6] = vha->node_name[5];
  1162. sns_cmd->p.cmd.param[7] = vha->node_name[4];
  1163. sns_cmd->p.cmd.param[8] = vha->node_name[3];
  1164. sns_cmd->p.cmd.param[9] = vha->node_name[2];
  1165. sns_cmd->p.cmd.param[10] = vha->node_name[1];
  1166. sns_cmd->p.cmd.param[11] = vha->node_name[0];
  1167. /* Execute SNS command. */
  1168. rval = qla2x00_send_sns(vha, ha->sns_cmd_dma, RNN_ID_SNS_CMD_SIZE / 2,
  1169. sizeof(struct sns_cmd_pkt));
  1170. if (rval != QLA_SUCCESS) {
  1171. /*EMPTY*/
  1172. ql_dbg(ql_dbg_disc, vha, 0x204a,
  1173. "RNN_ID Send SNS failed (%d).\n", rval);
  1174. } else if (sns_cmd->p.rnn_data[8] != 0x80 ||
  1175. sns_cmd->p.rnn_data[9] != 0x02) {
  1176. ql_dbg(ql_dbg_disc + ql_dbg_buffer, vha, 0x207b,
  1177. "RNN_ID failed, rejected request, rnn_rsp:\n");
  1178. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x207c,
  1179. sns_cmd->p.rnn_data, 16);
  1180. rval = QLA_FUNCTION_FAILED;
  1181. } else {
  1182. ql_dbg(ql_dbg_disc, vha, 0x204c,
  1183. "RNN_ID exiting normally.\n");
  1184. }
  1185. return (rval);
  1186. }
  1187. /**
  1188. * qla2x00_mgmt_svr_login() - Login to fabric Management Service.
  1189. * @vha: HA context
  1190. *
  1191. * Returns 0 on success.
  1192. */
  1193. int
  1194. qla2x00_mgmt_svr_login(scsi_qla_host_t *vha)
  1195. {
  1196. int ret, rval;
  1197. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1198. struct qla_hw_data *ha = vha->hw;
  1199. ret = QLA_SUCCESS;
  1200. if (vha->flags.management_server_logged_in)
  1201. return ret;
  1202. rval = ha->isp_ops->fabric_login(vha, vha->mgmt_svr_loop_id, 0xff, 0xff,
  1203. 0xfa, mb, BIT_1);
  1204. if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  1205. if (rval == QLA_MEMORY_ALLOC_FAILED)
  1206. ql_dbg(ql_dbg_disc, vha, 0x2085,
  1207. "Failed management_server login: loopid=%x "
  1208. "rval=%d\n", vha->mgmt_svr_loop_id, rval);
  1209. else
  1210. ql_dbg(ql_dbg_disc, vha, 0x2024,
  1211. "Failed management_server login: loopid=%x "
  1212. "mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  1213. vha->mgmt_svr_loop_id, mb[0], mb[1], mb[2], mb[6],
  1214. mb[7]);
  1215. ret = QLA_FUNCTION_FAILED;
  1216. } else
  1217. vha->flags.management_server_logged_in = 1;
  1218. return ret;
  1219. }
  1220. /**
  1221. * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  1222. * @vha: HA context
  1223. * @req_size: request size in bytes
  1224. * @rsp_size: response size in bytes
  1225. *
  1226. * Returns a pointer to the @ha's ms_iocb.
  1227. */
  1228. void *
  1229. qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  1230. uint32_t rsp_size)
  1231. {
  1232. ms_iocb_entry_t *ms_pkt;
  1233. struct qla_hw_data *ha = vha->hw;
  1234. ms_pkt = ha->ms_iocb;
  1235. memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
  1236. ms_pkt->entry_type = MS_IOCB_TYPE;
  1237. ms_pkt->entry_count = 1;
  1238. SET_TARGET_ID(ha, ms_pkt->loop_id, vha->mgmt_svr_loop_id);
  1239. ms_pkt->control_flags = cpu_to_le16(CF_READ | CF_HEAD_TAG);
  1240. ms_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1241. ms_pkt->cmd_dsd_count = cpu_to_le16(1);
  1242. ms_pkt->total_dsd_count = cpu_to_le16(2);
  1243. ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
  1244. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1245. ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1246. ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1247. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1248. ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1249. ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1250. ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
  1251. return ms_pkt;
  1252. }
  1253. /**
  1254. * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
  1255. * @vha: HA context
  1256. * @req_size: request size in bytes
  1257. * @rsp_size: response size in bytes
  1258. *
  1259. * Returns a pointer to the @ha's ms_iocb.
  1260. */
  1261. void *
  1262. qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size,
  1263. uint32_t rsp_size)
  1264. {
  1265. struct ct_entry_24xx *ct_pkt;
  1266. struct qla_hw_data *ha = vha->hw;
  1267. ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1268. memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
  1269. ct_pkt->entry_type = CT_IOCB_TYPE;
  1270. ct_pkt->entry_count = 1;
  1271. ct_pkt->nport_handle = cpu_to_le16(vha->mgmt_svr_loop_id);
  1272. ct_pkt->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1273. ct_pkt->cmd_dsd_count = cpu_to_le16(1);
  1274. ct_pkt->rsp_dsd_count = cpu_to_le16(1);
  1275. ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
  1276. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1277. ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1278. ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1279. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1280. ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
  1281. ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
  1282. ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
  1283. ct_pkt->vp_index = vha->vp_idx;
  1284. return ct_pkt;
  1285. }
  1286. static inline ms_iocb_entry_t *
  1287. qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size)
  1288. {
  1289. struct qla_hw_data *ha = vha->hw;
  1290. ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
  1291. struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
  1292. if (IS_FWI2_CAPABLE(ha)) {
  1293. ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
  1294. ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
  1295. } else {
  1296. ms_pkt->req_bytecount = cpu_to_le32(req_size);
  1297. ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
  1298. }
  1299. return ms_pkt;
  1300. }
  1301. /**
  1302. * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
  1303. * @p: CT request buffer
  1304. * @cmd: GS command
  1305. * @rsp_size: response size in bytes
  1306. *
  1307. * Returns a pointer to the intitialized @ct_req.
  1308. */
  1309. static inline struct ct_sns_req *
  1310. qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd,
  1311. uint16_t rsp_size)
  1312. {
  1313. memset(p, 0, sizeof(struct ct_sns_pkt));
  1314. p->p.req.header.revision = 0x01;
  1315. p->p.req.header.gs_type = 0xFA;
  1316. p->p.req.header.gs_subtype = 0x10;
  1317. p->p.req.command = cpu_to_be16(cmd);
  1318. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  1319. return &p->p.req;
  1320. }
  1321. /**
  1322. * qla2x00_fdmi_rhba() - perform RHBA FDMI registration
  1323. * @vha: HA context
  1324. *
  1325. * Returns 0 on success.
  1326. */
  1327. static int
  1328. qla2x00_fdmi_rhba(scsi_qla_host_t *vha)
  1329. {
  1330. int rval, alen;
  1331. uint32_t size, sn;
  1332. ms_iocb_entry_t *ms_pkt;
  1333. struct ct_sns_req *ct_req;
  1334. struct ct_sns_rsp *ct_rsp;
  1335. void *entries;
  1336. struct ct_fdmi_hba_attr *eiter;
  1337. struct qla_hw_data *ha = vha->hw;
  1338. /* Issue RHBA */
  1339. /* Prepare common MS IOCB */
  1340. /* Request size adjusted after CT preparation */
  1341. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
  1342. /* Prepare CT request */
  1343. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE);
  1344. ct_rsp = &ha->ct_sns->p.rsp;
  1345. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1346. memcpy(ct_req->req.rhba.hba_identifier, vha->port_name, WWN_SIZE);
  1347. ct_req->req.rhba.entry_count = cpu_to_be32(1);
  1348. memcpy(ct_req->req.rhba.port_name, vha->port_name, WWN_SIZE);
  1349. size = 2 * WWN_SIZE + 4 + 4;
  1350. /* Attributes */
  1351. ct_req->req.rhba.attrs.count =
  1352. cpu_to_be32(FDMI_HBA_ATTR_COUNT);
  1353. entries = ct_req->req.rhba.hba_identifier;
  1354. /* Nodename. */
  1355. eiter = entries + size;
  1356. eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
  1357. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1358. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  1359. size += 4 + WWN_SIZE;
  1360. ql_dbg(ql_dbg_disc, vha, 0x2025,
  1361. "NodeName = %8phN.\n", eiter->a.node_name);
  1362. /* Manufacturer. */
  1363. eiter = entries + size;
  1364. eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1365. alen = strlen(QLA2XXX_MANUFACTURER);
  1366. snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
  1367. "%s", "QLogic Corporation");
  1368. alen += 4 - (alen & 3);
  1369. eiter->len = cpu_to_be16(4 + alen);
  1370. size += 4 + alen;
  1371. ql_dbg(ql_dbg_disc, vha, 0x2026,
  1372. "Manufacturer = %s.\n", eiter->a.manufacturer);
  1373. /* Serial number. */
  1374. eiter = entries + size;
  1375. eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1376. if (IS_FWI2_CAPABLE(ha))
  1377. qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
  1378. sizeof(eiter->a.serial_num));
  1379. else {
  1380. sn = ((ha->serial0 & 0x1f) << 16) |
  1381. (ha->serial2 << 8) | ha->serial1;
  1382. snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
  1383. "%c%05d", 'A' + sn / 100000, sn % 100000);
  1384. }
  1385. alen = strlen(eiter->a.serial_num);
  1386. alen += 4 - (alen & 3);
  1387. eiter->len = cpu_to_be16(4 + alen);
  1388. size += 4 + alen;
  1389. ql_dbg(ql_dbg_disc, vha, 0x2027,
  1390. "Serial no. = %s.\n", eiter->a.serial_num);
  1391. /* Model name. */
  1392. eiter = entries + size;
  1393. eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
  1394. snprintf(eiter->a.model, sizeof(eiter->a.model),
  1395. "%s", ha->model_number);
  1396. alen = strlen(eiter->a.model);
  1397. alen += 4 - (alen & 3);
  1398. eiter->len = cpu_to_be16(4 + alen);
  1399. size += 4 + alen;
  1400. ql_dbg(ql_dbg_disc, vha, 0x2028,
  1401. "Model Name = %s.\n", eiter->a.model);
  1402. /* Model description. */
  1403. eiter = entries + size;
  1404. eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1405. snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
  1406. "%s", ha->model_desc);
  1407. alen = strlen(eiter->a.model_desc);
  1408. alen += 4 - (alen & 3);
  1409. eiter->len = cpu_to_be16(4 + alen);
  1410. size += 4 + alen;
  1411. ql_dbg(ql_dbg_disc, vha, 0x2029,
  1412. "Model Desc = %s.\n", eiter->a.model_desc);
  1413. /* Hardware version. */
  1414. eiter = entries + size;
  1415. eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1416. if (!IS_FWI2_CAPABLE(ha)) {
  1417. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1418. "HW:%s", ha->adapter_id);
  1419. } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
  1420. sizeof(eiter->a.hw_version))) {
  1421. ;
  1422. } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
  1423. sizeof(eiter->a.hw_version))) {
  1424. ;
  1425. } else {
  1426. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1427. "HW:%s", ha->adapter_id);
  1428. }
  1429. alen = strlen(eiter->a.hw_version);
  1430. alen += 4 - (alen & 3);
  1431. eiter->len = cpu_to_be16(4 + alen);
  1432. size += 4 + alen;
  1433. ql_dbg(ql_dbg_disc, vha, 0x202a,
  1434. "Hardware ver = %s.\n", eiter->a.hw_version);
  1435. /* Driver version. */
  1436. eiter = entries + size;
  1437. eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1438. snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
  1439. "%s", qla2x00_version_str);
  1440. alen = strlen(eiter->a.driver_version);
  1441. alen += 4 - (alen & 3);
  1442. eiter->len = cpu_to_be16(4 + alen);
  1443. size += 4 + alen;
  1444. ql_dbg(ql_dbg_disc, vha, 0x202b,
  1445. "Driver ver = %s.\n", eiter->a.driver_version);
  1446. /* Option ROM version. */
  1447. eiter = entries + size;
  1448. eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1449. snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
  1450. "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1451. alen = strlen(eiter->a.orom_version);
  1452. alen += 4 - (alen & 3);
  1453. eiter->len = cpu_to_be16(4 + alen);
  1454. size += 4 + alen;
  1455. ql_dbg(ql_dbg_disc, vha , 0x202c,
  1456. "Optrom vers = %s.\n", eiter->a.orom_version);
  1457. /* Firmware version */
  1458. eiter = entries + size;
  1459. eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1460. ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
  1461. sizeof(eiter->a.fw_version));
  1462. alen = strlen(eiter->a.fw_version);
  1463. alen += 4 - (alen & 3);
  1464. eiter->len = cpu_to_be16(4 + alen);
  1465. size += 4 + alen;
  1466. ql_dbg(ql_dbg_disc, vha, 0x202d,
  1467. "Firmware vers = %s.\n", eiter->a.fw_version);
  1468. /* Update MS request size. */
  1469. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1470. ql_dbg(ql_dbg_disc, vha, 0x202e,
  1471. "RHBA identifier = %8phN size=%d.\n",
  1472. ct_req->req.rhba.hba_identifier, size);
  1473. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2076,
  1474. entries, size);
  1475. /* Execute MS IOCB */
  1476. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1477. sizeof(ms_iocb_entry_t));
  1478. if (rval != QLA_SUCCESS) {
  1479. /*EMPTY*/
  1480. ql_dbg(ql_dbg_disc, vha, 0x2030,
  1481. "RHBA issue IOCB failed (%d).\n", rval);
  1482. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
  1483. QLA_SUCCESS) {
  1484. rval = QLA_FUNCTION_FAILED;
  1485. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1486. ct_rsp->header.explanation_code ==
  1487. CT_EXPL_ALREADY_REGISTERED) {
  1488. ql_dbg(ql_dbg_disc, vha, 0x2034,
  1489. "HBA already registered.\n");
  1490. rval = QLA_ALREADY_REGISTERED;
  1491. } else {
  1492. ql_dbg(ql_dbg_disc, vha, 0x20ad,
  1493. "RHBA FDMI registration failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  1494. ct_rsp->header.reason_code,
  1495. ct_rsp->header.explanation_code);
  1496. }
  1497. } else {
  1498. ql_dbg(ql_dbg_disc, vha, 0x2035,
  1499. "RHBA exiting normally.\n");
  1500. }
  1501. return rval;
  1502. }
  1503. /**
  1504. * qla2x00_fdmi_rpa() - perform RPA registration
  1505. * @vha: HA context
  1506. *
  1507. * Returns 0 on success.
  1508. */
  1509. static int
  1510. qla2x00_fdmi_rpa(scsi_qla_host_t *vha)
  1511. {
  1512. int rval, alen;
  1513. uint32_t size;
  1514. struct qla_hw_data *ha = vha->hw;
  1515. ms_iocb_entry_t *ms_pkt;
  1516. struct ct_sns_req *ct_req;
  1517. struct ct_sns_rsp *ct_rsp;
  1518. void *entries;
  1519. struct ct_fdmi_port_attr *eiter;
  1520. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  1521. struct new_utsname *p_sysid = NULL;
  1522. /* Issue RPA */
  1523. /* Prepare common MS IOCB */
  1524. /* Request size adjusted after CT preparation */
  1525. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
  1526. /* Prepare CT request */
  1527. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD,
  1528. RPA_RSP_SIZE);
  1529. ct_rsp = &ha->ct_sns->p.rsp;
  1530. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1531. memcpy(ct_req->req.rpa.port_name, vha->port_name, WWN_SIZE);
  1532. size = WWN_SIZE + 4;
  1533. /* Attributes */
  1534. ct_req->req.rpa.attrs.count = cpu_to_be32(FDMI_PORT_ATTR_COUNT);
  1535. entries = ct_req->req.rpa.port_name;
  1536. /* FC4 types. */
  1537. eiter = entries + size;
  1538. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
  1539. eiter->len = cpu_to_be16(4 + 32);
  1540. eiter->a.fc4_types[2] = 0x01;
  1541. size += 4 + 32;
  1542. ql_dbg(ql_dbg_disc, vha, 0x2039,
  1543. "FC4_TYPES=%02x %02x.\n",
  1544. eiter->a.fc4_types[2],
  1545. eiter->a.fc4_types[1]);
  1546. /* Supported speed. */
  1547. eiter = entries + size;
  1548. eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  1549. eiter->len = cpu_to_be16(4 + 4);
  1550. if (IS_CNA_CAPABLE(ha))
  1551. eiter->a.sup_speed = cpu_to_be32(
  1552. FDMI_PORT_SPEED_10GB);
  1553. else if (IS_QLA27XX(ha))
  1554. eiter->a.sup_speed = cpu_to_be32(
  1555. FDMI_PORT_SPEED_32GB|
  1556. FDMI_PORT_SPEED_16GB|
  1557. FDMI_PORT_SPEED_8GB);
  1558. else if (IS_QLA2031(ha))
  1559. eiter->a.sup_speed = cpu_to_be32(
  1560. FDMI_PORT_SPEED_16GB|
  1561. FDMI_PORT_SPEED_8GB|
  1562. FDMI_PORT_SPEED_4GB);
  1563. else if (IS_QLA25XX(ha))
  1564. eiter->a.sup_speed = cpu_to_be32(
  1565. FDMI_PORT_SPEED_8GB|
  1566. FDMI_PORT_SPEED_4GB|
  1567. FDMI_PORT_SPEED_2GB|
  1568. FDMI_PORT_SPEED_1GB);
  1569. else if (IS_QLA24XX_TYPE(ha))
  1570. eiter->a.sup_speed = cpu_to_be32(
  1571. FDMI_PORT_SPEED_4GB|
  1572. FDMI_PORT_SPEED_2GB|
  1573. FDMI_PORT_SPEED_1GB);
  1574. else if (IS_QLA23XX(ha))
  1575. eiter->a.sup_speed = cpu_to_be32(
  1576. FDMI_PORT_SPEED_2GB|
  1577. FDMI_PORT_SPEED_1GB);
  1578. else
  1579. eiter->a.sup_speed = cpu_to_be32(
  1580. FDMI_PORT_SPEED_1GB);
  1581. size += 4 + 4;
  1582. ql_dbg(ql_dbg_disc, vha, 0x203a,
  1583. "Supported_Speed=%x.\n", eiter->a.sup_speed);
  1584. /* Current speed. */
  1585. eiter = entries + size;
  1586. eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  1587. eiter->len = cpu_to_be16(4 + 4);
  1588. switch (ha->link_data_rate) {
  1589. case PORT_SPEED_1GB:
  1590. eiter->a.cur_speed =
  1591. cpu_to_be32(FDMI_PORT_SPEED_1GB);
  1592. break;
  1593. case PORT_SPEED_2GB:
  1594. eiter->a.cur_speed =
  1595. cpu_to_be32(FDMI_PORT_SPEED_2GB);
  1596. break;
  1597. case PORT_SPEED_4GB:
  1598. eiter->a.cur_speed =
  1599. cpu_to_be32(FDMI_PORT_SPEED_4GB);
  1600. break;
  1601. case PORT_SPEED_8GB:
  1602. eiter->a.cur_speed =
  1603. cpu_to_be32(FDMI_PORT_SPEED_8GB);
  1604. break;
  1605. case PORT_SPEED_10GB:
  1606. eiter->a.cur_speed =
  1607. cpu_to_be32(FDMI_PORT_SPEED_10GB);
  1608. break;
  1609. case PORT_SPEED_16GB:
  1610. eiter->a.cur_speed =
  1611. cpu_to_be32(FDMI_PORT_SPEED_16GB);
  1612. break;
  1613. case PORT_SPEED_32GB:
  1614. eiter->a.cur_speed =
  1615. cpu_to_be32(FDMI_PORT_SPEED_32GB);
  1616. break;
  1617. default:
  1618. eiter->a.cur_speed =
  1619. cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
  1620. break;
  1621. }
  1622. size += 4 + 4;
  1623. ql_dbg(ql_dbg_disc, vha, 0x203b,
  1624. "Current_Speed=%x.\n", eiter->a.cur_speed);
  1625. /* Max frame size. */
  1626. eiter = entries + size;
  1627. eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  1628. eiter->len = cpu_to_be16(4 + 4);
  1629. eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
  1630. le16_to_cpu(icb24->frame_payload_size) :
  1631. le16_to_cpu(ha->init_cb->frame_payload_size);
  1632. eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
  1633. size += 4 + 4;
  1634. ql_dbg(ql_dbg_disc, vha, 0x203c,
  1635. "Max_Frame_Size=%x.\n", eiter->a.max_frame_size);
  1636. /* OS device name. */
  1637. eiter = entries + size;
  1638. eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  1639. snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
  1640. "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
  1641. alen = strlen(eiter->a.os_dev_name);
  1642. alen += 4 - (alen & 3);
  1643. eiter->len = cpu_to_be16(4 + alen);
  1644. size += 4 + alen;
  1645. ql_dbg(ql_dbg_disc, vha, 0x204b,
  1646. "OS_Device_Name=%s.\n", eiter->a.os_dev_name);
  1647. /* Hostname. */
  1648. eiter = entries + size;
  1649. eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
  1650. p_sysid = utsname();
  1651. if (p_sysid) {
  1652. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1653. "%s", p_sysid->nodename);
  1654. } else {
  1655. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  1656. "%s", fc_host_system_hostname(vha->host));
  1657. }
  1658. alen = strlen(eiter->a.host_name);
  1659. alen += 4 - (alen & 3);
  1660. eiter->len = cpu_to_be16(4 + alen);
  1661. size += 4 + alen;
  1662. ql_dbg(ql_dbg_disc, vha, 0x203d, "HostName=%s.\n", eiter->a.host_name);
  1663. /* Update MS request size. */
  1664. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1665. ql_dbg(ql_dbg_disc, vha, 0x203e,
  1666. "RPA portname %016llx, size = %d.\n",
  1667. wwn_to_u64(ct_req->req.rpa.port_name), size);
  1668. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2079,
  1669. entries, size);
  1670. /* Execute MS IOCB */
  1671. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1672. sizeof(ms_iocb_entry_t));
  1673. if (rval != QLA_SUCCESS) {
  1674. /*EMPTY*/
  1675. ql_dbg(ql_dbg_disc, vha, 0x2040,
  1676. "RPA issue IOCB failed (%d).\n", rval);
  1677. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
  1678. QLA_SUCCESS) {
  1679. rval = QLA_FUNCTION_FAILED;
  1680. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1681. ct_rsp->header.explanation_code ==
  1682. CT_EXPL_ALREADY_REGISTERED) {
  1683. ql_dbg(ql_dbg_disc, vha, 0x20cd,
  1684. "RPA already registered.\n");
  1685. rval = QLA_ALREADY_REGISTERED;
  1686. }
  1687. } else {
  1688. ql_dbg(ql_dbg_disc, vha, 0x2041,
  1689. "RPA exiting normally.\n");
  1690. }
  1691. return rval;
  1692. }
  1693. /**
  1694. * qla2x00_fdmiv2_rhba() - perform RHBA FDMI v2 registration
  1695. * @vha: HA context
  1696. *
  1697. * Returns 0 on success.
  1698. */
  1699. static int
  1700. qla2x00_fdmiv2_rhba(scsi_qla_host_t *vha)
  1701. {
  1702. int rval, alen;
  1703. uint32_t size, sn;
  1704. ms_iocb_entry_t *ms_pkt;
  1705. struct ct_sns_req *ct_req;
  1706. struct ct_sns_rsp *ct_rsp;
  1707. void *entries;
  1708. struct ct_fdmiv2_hba_attr *eiter;
  1709. struct qla_hw_data *ha = vha->hw;
  1710. struct new_utsname *p_sysid = NULL;
  1711. /* Issue RHBA */
  1712. /* Prepare common MS IOCB */
  1713. /* Request size adjusted after CT preparation */
  1714. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE);
  1715. /* Prepare CT request */
  1716. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD,
  1717. RHBA_RSP_SIZE);
  1718. ct_rsp = &ha->ct_sns->p.rsp;
  1719. /* Prepare FDMI command arguments -- attribute block, attributes. */
  1720. memcpy(ct_req->req.rhba2.hba_identifier, vha->port_name, WWN_SIZE);
  1721. ct_req->req.rhba2.entry_count = cpu_to_be32(1);
  1722. memcpy(ct_req->req.rhba2.port_name, vha->port_name, WWN_SIZE);
  1723. size = 2 * WWN_SIZE + 4 + 4;
  1724. /* Attributes */
  1725. ct_req->req.rhba2.attrs.count = cpu_to_be32(FDMIV2_HBA_ATTR_COUNT);
  1726. entries = ct_req->req.rhba2.hba_identifier;
  1727. /* Nodename. */
  1728. eiter = entries + size;
  1729. eiter->type = cpu_to_be16(FDMI_HBA_NODE_NAME);
  1730. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1731. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  1732. size += 4 + WWN_SIZE;
  1733. ql_dbg(ql_dbg_disc, vha, 0x207d,
  1734. "NodeName = %016llx.\n", wwn_to_u64(eiter->a.node_name));
  1735. /* Manufacturer. */
  1736. eiter = entries + size;
  1737. eiter->type = cpu_to_be16(FDMI_HBA_MANUFACTURER);
  1738. snprintf(eiter->a.manufacturer, sizeof(eiter->a.manufacturer),
  1739. "%s", "QLogic Corporation");
  1740. eiter->a.manufacturer[strlen("QLogic Corporation")] = '\0';
  1741. alen = strlen(eiter->a.manufacturer);
  1742. alen += 4 - (alen & 3);
  1743. eiter->len = cpu_to_be16(4 + alen);
  1744. size += 4 + alen;
  1745. ql_dbg(ql_dbg_disc, vha, 0x20a5,
  1746. "Manufacturer = %s.\n", eiter->a.manufacturer);
  1747. /* Serial number. */
  1748. eiter = entries + size;
  1749. eiter->type = cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
  1750. if (IS_FWI2_CAPABLE(ha))
  1751. qla2xxx_get_vpd_field(vha, "SN", eiter->a.serial_num,
  1752. sizeof(eiter->a.serial_num));
  1753. else {
  1754. sn = ((ha->serial0 & 0x1f) << 16) |
  1755. (ha->serial2 << 8) | ha->serial1;
  1756. snprintf(eiter->a.serial_num, sizeof(eiter->a.serial_num),
  1757. "%c%05d", 'A' + sn / 100000, sn % 100000);
  1758. }
  1759. alen = strlen(eiter->a.serial_num);
  1760. alen += 4 - (alen & 3);
  1761. eiter->len = cpu_to_be16(4 + alen);
  1762. size += 4 + alen;
  1763. ql_dbg(ql_dbg_disc, vha, 0x20a6,
  1764. "Serial no. = %s.\n", eiter->a.serial_num);
  1765. /* Model name. */
  1766. eiter = entries + size;
  1767. eiter->type = cpu_to_be16(FDMI_HBA_MODEL);
  1768. snprintf(eiter->a.model, sizeof(eiter->a.model),
  1769. "%s", ha->model_number);
  1770. alen = strlen(eiter->a.model);
  1771. alen += 4 - (alen & 3);
  1772. eiter->len = cpu_to_be16(4 + alen);
  1773. size += 4 + alen;
  1774. ql_dbg(ql_dbg_disc, vha, 0x20a7,
  1775. "Model Name = %s.\n", eiter->a.model);
  1776. /* Model description. */
  1777. eiter = entries + size;
  1778. eiter->type = cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
  1779. snprintf(eiter->a.model_desc, sizeof(eiter->a.model_desc),
  1780. "%s", ha->model_desc);
  1781. alen = strlen(eiter->a.model_desc);
  1782. alen += 4 - (alen & 3);
  1783. eiter->len = cpu_to_be16(4 + alen);
  1784. size += 4 + alen;
  1785. ql_dbg(ql_dbg_disc, vha, 0x20a8,
  1786. "Model Desc = %s.\n", eiter->a.model_desc);
  1787. /* Hardware version. */
  1788. eiter = entries + size;
  1789. eiter->type = cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
  1790. if (!IS_FWI2_CAPABLE(ha)) {
  1791. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1792. "HW:%s", ha->adapter_id);
  1793. } else if (qla2xxx_get_vpd_field(vha, "MN", eiter->a.hw_version,
  1794. sizeof(eiter->a.hw_version))) {
  1795. ;
  1796. } else if (qla2xxx_get_vpd_field(vha, "EC", eiter->a.hw_version,
  1797. sizeof(eiter->a.hw_version))) {
  1798. ;
  1799. } else {
  1800. snprintf(eiter->a.hw_version, sizeof(eiter->a.hw_version),
  1801. "HW:%s", ha->adapter_id);
  1802. }
  1803. alen = strlen(eiter->a.hw_version);
  1804. alen += 4 - (alen & 3);
  1805. eiter->len = cpu_to_be16(4 + alen);
  1806. size += 4 + alen;
  1807. ql_dbg(ql_dbg_disc, vha, 0x20a9,
  1808. "Hardware ver = %s.\n", eiter->a.hw_version);
  1809. /* Driver version. */
  1810. eiter = entries + size;
  1811. eiter->type = cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
  1812. snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version),
  1813. "%s", qla2x00_version_str);
  1814. alen = strlen(eiter->a.driver_version);
  1815. alen += 4 - (alen & 3);
  1816. eiter->len = cpu_to_be16(4 + alen);
  1817. size += 4 + alen;
  1818. ql_dbg(ql_dbg_disc, vha, 0x20aa,
  1819. "Driver ver = %s.\n", eiter->a.driver_version);
  1820. /* Option ROM version. */
  1821. eiter = entries + size;
  1822. eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
  1823. snprintf(eiter->a.orom_version, sizeof(eiter->a.orom_version),
  1824. "%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1825. alen = strlen(eiter->a.orom_version);
  1826. alen += 4 - (alen & 3);
  1827. eiter->len = cpu_to_be16(4 + alen);
  1828. size += 4 + alen;
  1829. ql_dbg(ql_dbg_disc, vha , 0x20ab,
  1830. "Optrom version = %d.%02d.\n", eiter->a.orom_version[1],
  1831. eiter->a.orom_version[0]);
  1832. /* Firmware version */
  1833. eiter = entries + size;
  1834. eiter->type = cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
  1835. ha->isp_ops->fw_version_str(vha, eiter->a.fw_version,
  1836. sizeof(eiter->a.fw_version));
  1837. alen = strlen(eiter->a.fw_version);
  1838. alen += 4 - (alen & 3);
  1839. eiter->len = cpu_to_be16(4 + alen);
  1840. size += 4 + alen;
  1841. ql_dbg(ql_dbg_disc, vha, 0x20ac,
  1842. "Firmware vers = %s.\n", eiter->a.fw_version);
  1843. /* OS Name and Version */
  1844. eiter = entries + size;
  1845. eiter->type = cpu_to_be16(FDMI_HBA_OS_NAME_AND_VERSION);
  1846. p_sysid = utsname();
  1847. if (p_sysid) {
  1848. snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
  1849. "%s %s %s",
  1850. p_sysid->sysname, p_sysid->release, p_sysid->version);
  1851. } else {
  1852. snprintf(eiter->a.os_version, sizeof(eiter->a.os_version),
  1853. "%s %s", "Linux", fc_host_system_hostname(vha->host));
  1854. }
  1855. alen = strlen(eiter->a.os_version);
  1856. alen += 4 - (alen & 3);
  1857. eiter->len = cpu_to_be16(4 + alen);
  1858. size += 4 + alen;
  1859. ql_dbg(ql_dbg_disc, vha, 0x20ae,
  1860. "OS Name and Version = %s.\n", eiter->a.os_version);
  1861. /* MAX CT Payload Length */
  1862. eiter = entries + size;
  1863. eiter->type = cpu_to_be16(FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH);
  1864. eiter->a.max_ct_len = cpu_to_be32(ha->frame_payload_size);
  1865. eiter->a.max_ct_len = cpu_to_be32(eiter->a.max_ct_len);
  1866. eiter->len = cpu_to_be16(4 + 4);
  1867. size += 4 + 4;
  1868. ql_dbg(ql_dbg_disc, vha, 0x20af,
  1869. "CT Payload Length = 0x%x.\n", eiter->a.max_ct_len);
  1870. /* Node Sybolic Name */
  1871. eiter = entries + size;
  1872. eiter->type = cpu_to_be16(FDMI_HBA_NODE_SYMBOLIC_NAME);
  1873. qla2x00_get_sym_node_name(vha, eiter->a.sym_name,
  1874. sizeof(eiter->a.sym_name));
  1875. alen = strlen(eiter->a.sym_name);
  1876. alen += 4 - (alen & 3);
  1877. eiter->len = cpu_to_be16(4 + alen);
  1878. size += 4 + alen;
  1879. ql_dbg(ql_dbg_disc, vha, 0x20b0,
  1880. "Symbolic Name = %s.\n", eiter->a.sym_name);
  1881. /* Vendor Id */
  1882. eiter = entries + size;
  1883. eiter->type = cpu_to_be16(FDMI_HBA_VENDOR_ID);
  1884. eiter->a.vendor_id = cpu_to_be32(0x1077);
  1885. eiter->len = cpu_to_be16(4 + 4);
  1886. size += 4 + 4;
  1887. ql_dbg(ql_dbg_disc, vha, 0x20b1,
  1888. "Vendor Id = %x.\n", eiter->a.vendor_id);
  1889. /* Num Ports */
  1890. eiter = entries + size;
  1891. eiter->type = cpu_to_be16(FDMI_HBA_NUM_PORTS);
  1892. eiter->a.num_ports = cpu_to_be32(1);
  1893. eiter->len = cpu_to_be16(4 + 4);
  1894. size += 4 + 4;
  1895. ql_dbg(ql_dbg_disc, vha, 0x20b2,
  1896. "Port Num = %x.\n", eiter->a.num_ports);
  1897. /* Fabric Name */
  1898. eiter = entries + size;
  1899. eiter->type = cpu_to_be16(FDMI_HBA_FABRIC_NAME);
  1900. memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
  1901. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  1902. size += 4 + WWN_SIZE;
  1903. ql_dbg(ql_dbg_disc, vha, 0x20b3,
  1904. "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
  1905. /* BIOS Version */
  1906. eiter = entries + size;
  1907. eiter->type = cpu_to_be16(FDMI_HBA_BOOT_BIOS_NAME);
  1908. snprintf(eiter->a.bios_name, sizeof(eiter->a.bios_name),
  1909. "BIOS %d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
  1910. alen = strlen(eiter->a.bios_name);
  1911. alen += 4 - (alen & 3);
  1912. eiter->len = cpu_to_be16(4 + alen);
  1913. size += 4 + alen;
  1914. ql_dbg(ql_dbg_disc, vha, 0x20b4,
  1915. "BIOS Name = %s\n", eiter->a.bios_name);
  1916. /* Vendor Identifier */
  1917. eiter = entries + size;
  1918. eiter->type = cpu_to_be16(FDMI_HBA_TYPE_VENDOR_IDENTIFIER);
  1919. snprintf(eiter->a.vendor_identifier, sizeof(eiter->a.vendor_identifier),
  1920. "%s", "QLGC");
  1921. alen = strlen(eiter->a.vendor_identifier);
  1922. alen += 4 - (alen & 3);
  1923. eiter->len = cpu_to_be16(4 + alen);
  1924. size += 4 + alen;
  1925. ql_dbg(ql_dbg_disc, vha, 0x201b,
  1926. "Vendor Identifier = %s.\n", eiter->a.vendor_identifier);
  1927. /* Update MS request size. */
  1928. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  1929. ql_dbg(ql_dbg_disc, vha, 0x20b5,
  1930. "RHBA identifier = %016llx.\n",
  1931. wwn_to_u64(ct_req->req.rhba2.hba_identifier));
  1932. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20b6,
  1933. entries, size);
  1934. /* Execute MS IOCB */
  1935. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1936. sizeof(ms_iocb_entry_t));
  1937. if (rval != QLA_SUCCESS) {
  1938. /*EMPTY*/
  1939. ql_dbg(ql_dbg_disc, vha, 0x20b7,
  1940. "RHBA issue IOCB failed (%d).\n", rval);
  1941. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RHBA") !=
  1942. QLA_SUCCESS) {
  1943. rval = QLA_FUNCTION_FAILED;
  1944. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  1945. ct_rsp->header.explanation_code ==
  1946. CT_EXPL_ALREADY_REGISTERED) {
  1947. ql_dbg(ql_dbg_disc, vha, 0x20b8,
  1948. "HBA already registered.\n");
  1949. rval = QLA_ALREADY_REGISTERED;
  1950. } else {
  1951. ql_dbg(ql_dbg_disc, vha, 0x2016,
  1952. "RHBA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  1953. ct_rsp->header.reason_code,
  1954. ct_rsp->header.explanation_code);
  1955. }
  1956. } else {
  1957. ql_dbg(ql_dbg_disc, vha, 0x20b9,
  1958. "RHBA FDMI V2 exiting normally.\n");
  1959. }
  1960. return rval;
  1961. }
  1962. /**
  1963. * qla2x00_fdmi_dhba() -
  1964. * @vha: HA context
  1965. *
  1966. * Returns 0 on success.
  1967. */
  1968. static int
  1969. qla2x00_fdmi_dhba(scsi_qla_host_t *vha)
  1970. {
  1971. int rval;
  1972. struct qla_hw_data *ha = vha->hw;
  1973. ms_iocb_entry_t *ms_pkt;
  1974. struct ct_sns_req *ct_req;
  1975. struct ct_sns_rsp *ct_rsp;
  1976. /* Issue RPA */
  1977. /* Prepare common MS IOCB */
  1978. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, DHBA_REQ_SIZE,
  1979. DHBA_RSP_SIZE);
  1980. /* Prepare CT request */
  1981. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE);
  1982. ct_rsp = &ha->ct_sns->p.rsp;
  1983. /* Prepare FDMI command arguments -- portname. */
  1984. memcpy(ct_req->req.dhba.port_name, vha->port_name, WWN_SIZE);
  1985. ql_dbg(ql_dbg_disc, vha, 0x2036,
  1986. "DHBA portname = %8phN.\n", ct_req->req.dhba.port_name);
  1987. /* Execute MS IOCB */
  1988. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  1989. sizeof(ms_iocb_entry_t));
  1990. if (rval != QLA_SUCCESS) {
  1991. /*EMPTY*/
  1992. ql_dbg(ql_dbg_disc, vha, 0x2037,
  1993. "DHBA issue IOCB failed (%d).\n", rval);
  1994. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "DHBA") !=
  1995. QLA_SUCCESS) {
  1996. rval = QLA_FUNCTION_FAILED;
  1997. } else {
  1998. ql_dbg(ql_dbg_disc, vha, 0x2038,
  1999. "DHBA exiting normally.\n");
  2000. }
  2001. return rval;
  2002. }
  2003. /**
  2004. * qla2x00_fdmiv2_rpa() -
  2005. * @vha: HA context
  2006. *
  2007. * Returns 0 on success.
  2008. */
  2009. static int
  2010. qla2x00_fdmiv2_rpa(scsi_qla_host_t *vha)
  2011. {
  2012. int rval, alen;
  2013. uint32_t size;
  2014. struct qla_hw_data *ha = vha->hw;
  2015. ms_iocb_entry_t *ms_pkt;
  2016. struct ct_sns_req *ct_req;
  2017. struct ct_sns_rsp *ct_rsp;
  2018. void *entries;
  2019. struct ct_fdmiv2_port_attr *eiter;
  2020. struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
  2021. struct new_utsname *p_sysid = NULL;
  2022. /* Issue RPA */
  2023. /* Prepare common MS IOCB */
  2024. /* Request size adjusted after CT preparation */
  2025. ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE);
  2026. /* Prepare CT request */
  2027. ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE);
  2028. ct_rsp = &ha->ct_sns->p.rsp;
  2029. /* Prepare FDMI command arguments -- attribute block, attributes. */
  2030. memcpy(ct_req->req.rpa2.port_name, vha->port_name, WWN_SIZE);
  2031. size = WWN_SIZE + 4;
  2032. /* Attributes */
  2033. ct_req->req.rpa2.attrs.count = cpu_to_be32(FDMIV2_PORT_ATTR_COUNT);
  2034. entries = ct_req->req.rpa2.port_name;
  2035. /* FC4 types. */
  2036. eiter = entries + size;
  2037. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPES);
  2038. eiter->len = cpu_to_be16(4 + 32);
  2039. eiter->a.fc4_types[2] = 0x01;
  2040. size += 4 + 32;
  2041. ql_dbg(ql_dbg_disc, vha, 0x20ba,
  2042. "FC4_TYPES=%02x %02x.\n",
  2043. eiter->a.fc4_types[2],
  2044. eiter->a.fc4_types[1]);
  2045. if (vha->flags.nvme_enabled) {
  2046. eiter->a.fc4_types[6] = 1; /* NVMe type 28h */
  2047. ql_dbg(ql_dbg_disc, vha, 0x211f,
  2048. "NVME FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
  2049. eiter->a.fc4_types[6]);
  2050. }
  2051. /* Supported speed. */
  2052. eiter = entries + size;
  2053. eiter->type = cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
  2054. eiter->len = cpu_to_be16(4 + 4);
  2055. if (IS_CNA_CAPABLE(ha))
  2056. eiter->a.sup_speed = cpu_to_be32(
  2057. FDMI_PORT_SPEED_10GB);
  2058. else if (IS_QLA27XX(ha))
  2059. eiter->a.sup_speed = cpu_to_be32(
  2060. FDMI_PORT_SPEED_32GB|
  2061. FDMI_PORT_SPEED_16GB|
  2062. FDMI_PORT_SPEED_8GB);
  2063. else if (IS_QLA2031(ha))
  2064. eiter->a.sup_speed = cpu_to_be32(
  2065. FDMI_PORT_SPEED_16GB|
  2066. FDMI_PORT_SPEED_8GB|
  2067. FDMI_PORT_SPEED_4GB);
  2068. else if (IS_QLA25XX(ha))
  2069. eiter->a.sup_speed = cpu_to_be32(
  2070. FDMI_PORT_SPEED_8GB|
  2071. FDMI_PORT_SPEED_4GB|
  2072. FDMI_PORT_SPEED_2GB|
  2073. FDMI_PORT_SPEED_1GB);
  2074. else if (IS_QLA24XX_TYPE(ha))
  2075. eiter->a.sup_speed = cpu_to_be32(
  2076. FDMI_PORT_SPEED_4GB|
  2077. FDMI_PORT_SPEED_2GB|
  2078. FDMI_PORT_SPEED_1GB);
  2079. else if (IS_QLA23XX(ha))
  2080. eiter->a.sup_speed = cpu_to_be32(
  2081. FDMI_PORT_SPEED_2GB|
  2082. FDMI_PORT_SPEED_1GB);
  2083. else
  2084. eiter->a.sup_speed = cpu_to_be32(
  2085. FDMI_PORT_SPEED_1GB);
  2086. size += 4 + 4;
  2087. ql_dbg(ql_dbg_disc, vha, 0x20bb,
  2088. "Supported Port Speed = %x.\n", eiter->a.sup_speed);
  2089. /* Current speed. */
  2090. eiter = entries + size;
  2091. eiter->type = cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
  2092. eiter->len = cpu_to_be16(4 + 4);
  2093. switch (ha->link_data_rate) {
  2094. case PORT_SPEED_1GB:
  2095. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_1GB);
  2096. break;
  2097. case PORT_SPEED_2GB:
  2098. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_2GB);
  2099. break;
  2100. case PORT_SPEED_4GB:
  2101. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_4GB);
  2102. break;
  2103. case PORT_SPEED_8GB:
  2104. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_8GB);
  2105. break;
  2106. case PORT_SPEED_10GB:
  2107. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_10GB);
  2108. break;
  2109. case PORT_SPEED_16GB:
  2110. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_16GB);
  2111. break;
  2112. case PORT_SPEED_32GB:
  2113. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_32GB);
  2114. break;
  2115. default:
  2116. eiter->a.cur_speed = cpu_to_be32(FDMI_PORT_SPEED_UNKNOWN);
  2117. break;
  2118. }
  2119. size += 4 + 4;
  2120. ql_dbg(ql_dbg_disc, vha, 0x2017,
  2121. "Current_Speed = %x.\n", eiter->a.cur_speed);
  2122. /* Max frame size. */
  2123. eiter = entries + size;
  2124. eiter->type = cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
  2125. eiter->len = cpu_to_be16(4 + 4);
  2126. eiter->a.max_frame_size = IS_FWI2_CAPABLE(ha) ?
  2127. le16_to_cpu(icb24->frame_payload_size):
  2128. le16_to_cpu(ha->init_cb->frame_payload_size);
  2129. eiter->a.max_frame_size = cpu_to_be32(eiter->a.max_frame_size);
  2130. size += 4 + 4;
  2131. ql_dbg(ql_dbg_disc, vha, 0x20bc,
  2132. "Max_Frame_Size = %x.\n", eiter->a.max_frame_size);
  2133. /* OS device name. */
  2134. eiter = entries + size;
  2135. eiter->type = cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
  2136. alen = strlen(QLA2XXX_DRIVER_NAME);
  2137. snprintf(eiter->a.os_dev_name, sizeof(eiter->a.os_dev_name),
  2138. "%s:host%lu", QLA2XXX_DRIVER_NAME, vha->host_no);
  2139. alen += 4 - (alen & 3);
  2140. eiter->len = cpu_to_be16(4 + alen);
  2141. size += 4 + alen;
  2142. ql_dbg(ql_dbg_disc, vha, 0x20be,
  2143. "OS_Device_Name = %s.\n", eiter->a.os_dev_name);
  2144. /* Hostname. */
  2145. eiter = entries + size;
  2146. eiter->type = cpu_to_be16(FDMI_PORT_HOST_NAME);
  2147. p_sysid = utsname();
  2148. if (p_sysid) {
  2149. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  2150. "%s", p_sysid->nodename);
  2151. } else {
  2152. snprintf(eiter->a.host_name, sizeof(eiter->a.host_name),
  2153. "%s", fc_host_system_hostname(vha->host));
  2154. }
  2155. alen = strlen(eiter->a.host_name);
  2156. alen += 4 - (alen & 3);
  2157. eiter->len = cpu_to_be16(4 + alen);
  2158. size += 4 + alen;
  2159. ql_dbg(ql_dbg_disc, vha, 0x201a,
  2160. "HostName=%s.\n", eiter->a.host_name);
  2161. /* Node Name */
  2162. eiter = entries + size;
  2163. eiter->type = cpu_to_be16(FDMI_PORT_NODE_NAME);
  2164. memcpy(eiter->a.node_name, vha->node_name, WWN_SIZE);
  2165. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  2166. size += 4 + WWN_SIZE;
  2167. ql_dbg(ql_dbg_disc, vha, 0x20c0,
  2168. "Node Name = %016llx.\n", wwn_to_u64(eiter->a.node_name));
  2169. /* Port Name */
  2170. eiter = entries + size;
  2171. eiter->type = cpu_to_be16(FDMI_PORT_NAME);
  2172. memcpy(eiter->a.port_name, vha->port_name, WWN_SIZE);
  2173. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  2174. size += 4 + WWN_SIZE;
  2175. ql_dbg(ql_dbg_disc, vha, 0x20c1,
  2176. "Port Name = %016llx.\n", wwn_to_u64(eiter->a.port_name));
  2177. /* Port Symbolic Name */
  2178. eiter = entries + size;
  2179. eiter->type = cpu_to_be16(FDMI_PORT_SYM_NAME);
  2180. qla2x00_get_sym_node_name(vha, eiter->a.port_sym_name,
  2181. sizeof(eiter->a.port_sym_name));
  2182. alen = strlen(eiter->a.port_sym_name);
  2183. alen += 4 - (alen & 3);
  2184. eiter->len = cpu_to_be16(4 + alen);
  2185. size += 4 + alen;
  2186. ql_dbg(ql_dbg_disc, vha, 0x20c2,
  2187. "port symbolic name = %s\n", eiter->a.port_sym_name);
  2188. /* Port Type */
  2189. eiter = entries + size;
  2190. eiter->type = cpu_to_be16(FDMI_PORT_TYPE);
  2191. eiter->a.port_type = cpu_to_be32(NS_NX_PORT_TYPE);
  2192. eiter->len = cpu_to_be16(4 + 4);
  2193. size += 4 + 4;
  2194. ql_dbg(ql_dbg_disc, vha, 0x20c3,
  2195. "Port Type = %x.\n", eiter->a.port_type);
  2196. /* Class of Service */
  2197. eiter = entries + size;
  2198. eiter->type = cpu_to_be16(FDMI_PORT_SUPP_COS);
  2199. eiter->a.port_supported_cos = cpu_to_be32(FC_CLASS_3);
  2200. eiter->len = cpu_to_be16(4 + 4);
  2201. size += 4 + 4;
  2202. ql_dbg(ql_dbg_disc, vha, 0x20c4,
  2203. "Supported COS = %08x\n", eiter->a.port_supported_cos);
  2204. /* Port Fabric Name */
  2205. eiter = entries + size;
  2206. eiter->type = cpu_to_be16(FDMI_PORT_FABRIC_NAME);
  2207. memcpy(eiter->a.fabric_name, vha->fabric_node_name, WWN_SIZE);
  2208. eiter->len = cpu_to_be16(4 + WWN_SIZE);
  2209. size += 4 + WWN_SIZE;
  2210. ql_dbg(ql_dbg_disc, vha, 0x20c5,
  2211. "Fabric Name = %016llx.\n", wwn_to_u64(eiter->a.fabric_name));
  2212. /* FC4_type */
  2213. eiter = entries + size;
  2214. eiter->type = cpu_to_be16(FDMI_PORT_FC4_TYPE);
  2215. eiter->a.port_fc4_type[0] = 0;
  2216. eiter->a.port_fc4_type[1] = 0;
  2217. eiter->a.port_fc4_type[2] = 1;
  2218. eiter->a.port_fc4_type[3] = 0;
  2219. eiter->len = cpu_to_be16(4 + 32);
  2220. size += 4 + 32;
  2221. ql_dbg(ql_dbg_disc, vha, 0x20c6,
  2222. "Port Active FC4 Type = %02x %02x.\n",
  2223. eiter->a.port_fc4_type[2], eiter->a.port_fc4_type[1]);
  2224. if (vha->flags.nvme_enabled) {
  2225. eiter->a.port_fc4_type[4] = 0;
  2226. eiter->a.port_fc4_type[5] = 0;
  2227. eiter->a.port_fc4_type[6] = 1; /* NVMe type 28h */
  2228. ql_dbg(ql_dbg_disc, vha, 0x2120,
  2229. "NVME Port Active FC4 Type = %02x 0x0 0x0 0x0 0x0 0x0.\n",
  2230. eiter->a.port_fc4_type[6]);
  2231. }
  2232. /* Port State */
  2233. eiter = entries + size;
  2234. eiter->type = cpu_to_be16(FDMI_PORT_STATE);
  2235. eiter->a.port_state = cpu_to_be32(1);
  2236. eiter->len = cpu_to_be16(4 + 4);
  2237. size += 4 + 4;
  2238. ql_dbg(ql_dbg_disc, vha, 0x20c7,
  2239. "Port State = %x.\n", eiter->a.port_state);
  2240. /* Number of Ports */
  2241. eiter = entries + size;
  2242. eiter->type = cpu_to_be16(FDMI_PORT_COUNT);
  2243. eiter->a.num_ports = cpu_to_be32(1);
  2244. eiter->len = cpu_to_be16(4 + 4);
  2245. size += 4 + 4;
  2246. ql_dbg(ql_dbg_disc, vha, 0x20c8,
  2247. "Number of ports = %x.\n", eiter->a.num_ports);
  2248. /* Port Id */
  2249. eiter = entries + size;
  2250. eiter->type = cpu_to_be16(FDMI_PORT_ID);
  2251. eiter->a.port_id = cpu_to_be32(vha->d_id.b24);
  2252. eiter->len = cpu_to_be16(4 + 4);
  2253. size += 4 + 4;
  2254. ql_dbg(ql_dbg_disc, vha, 0x201c,
  2255. "Port Id = %x.\n", eiter->a.port_id);
  2256. /* Update MS request size. */
  2257. qla2x00_update_ms_fdmi_iocb(vha, size + 16);
  2258. ql_dbg(ql_dbg_disc, vha, 0x2018,
  2259. "RPA portname= %8phN size=%d.\n", ct_req->req.rpa.port_name, size);
  2260. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x20ca,
  2261. entries, size);
  2262. /* Execute MS IOCB */
  2263. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2264. sizeof(ms_iocb_entry_t));
  2265. if (rval != QLA_SUCCESS) {
  2266. /*EMPTY*/
  2267. ql_dbg(ql_dbg_disc, vha, 0x20cb,
  2268. "RPA FDMI v2 issue IOCB failed (%d).\n", rval);
  2269. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp, "RPA") !=
  2270. QLA_SUCCESS) {
  2271. rval = QLA_FUNCTION_FAILED;
  2272. if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
  2273. ct_rsp->header.explanation_code ==
  2274. CT_EXPL_ALREADY_REGISTERED) {
  2275. ql_dbg(ql_dbg_disc, vha, 0x20ce,
  2276. "RPA FDMI v2 already registered\n");
  2277. rval = QLA_ALREADY_REGISTERED;
  2278. } else {
  2279. ql_dbg(ql_dbg_disc, vha, 0x2020,
  2280. "RPA FDMI v2 failed, CT Reason code: 0x%x, CT Explanation 0x%x\n",
  2281. ct_rsp->header.reason_code,
  2282. ct_rsp->header.explanation_code);
  2283. }
  2284. } else {
  2285. ql_dbg(ql_dbg_disc, vha, 0x20cc,
  2286. "RPA FDMI V2 exiting normally.\n");
  2287. }
  2288. return rval;
  2289. }
  2290. /**
  2291. * qla2x00_fdmi_register() -
  2292. * @vha: HA context
  2293. *
  2294. * Returns 0 on success.
  2295. */
  2296. int
  2297. qla2x00_fdmi_register(scsi_qla_host_t *vha)
  2298. {
  2299. int rval = QLA_FUNCTION_FAILED;
  2300. struct qla_hw_data *ha = vha->hw;
  2301. if (IS_QLA2100(ha) || IS_QLA2200(ha) ||
  2302. IS_QLAFX00(ha))
  2303. return QLA_FUNCTION_FAILED;
  2304. rval = qla2x00_mgmt_svr_login(vha);
  2305. if (rval)
  2306. return rval;
  2307. rval = qla2x00_fdmiv2_rhba(vha);
  2308. if (rval) {
  2309. if (rval != QLA_ALREADY_REGISTERED)
  2310. goto try_fdmi;
  2311. rval = qla2x00_fdmi_dhba(vha);
  2312. if (rval)
  2313. goto try_fdmi;
  2314. rval = qla2x00_fdmiv2_rhba(vha);
  2315. if (rval)
  2316. goto try_fdmi;
  2317. }
  2318. rval = qla2x00_fdmiv2_rpa(vha);
  2319. if (rval)
  2320. goto try_fdmi;
  2321. goto out;
  2322. try_fdmi:
  2323. rval = qla2x00_fdmi_rhba(vha);
  2324. if (rval) {
  2325. if (rval != QLA_ALREADY_REGISTERED)
  2326. return rval;
  2327. rval = qla2x00_fdmi_dhba(vha);
  2328. if (rval)
  2329. return rval;
  2330. rval = qla2x00_fdmi_rhba(vha);
  2331. if (rval)
  2332. return rval;
  2333. }
  2334. rval = qla2x00_fdmi_rpa(vha);
  2335. out:
  2336. return rval;
  2337. }
  2338. /**
  2339. * qla2x00_gfpn_id() - SNS Get Fabric Port Name (GFPN_ID) query.
  2340. * @vha: HA context
  2341. * @list: switch info entries to populate
  2342. *
  2343. * Returns 0 on success.
  2344. */
  2345. int
  2346. qla2x00_gfpn_id(scsi_qla_host_t *vha, sw_info_t *list)
  2347. {
  2348. int rval = QLA_SUCCESS;
  2349. uint16_t i;
  2350. struct qla_hw_data *ha = vha->hw;
  2351. ms_iocb_entry_t *ms_pkt;
  2352. struct ct_sns_req *ct_req;
  2353. struct ct_sns_rsp *ct_rsp;
  2354. struct ct_arg arg;
  2355. if (!IS_IIDMA_CAPABLE(ha))
  2356. return QLA_FUNCTION_FAILED;
  2357. arg.iocb = ha->ms_iocb;
  2358. arg.req_dma = ha->ct_sns_dma;
  2359. arg.rsp_dma = ha->ct_sns_dma;
  2360. arg.req_size = GFPN_ID_REQ_SIZE;
  2361. arg.rsp_size = GFPN_ID_RSP_SIZE;
  2362. arg.nport_handle = NPH_SNS;
  2363. for (i = 0; i < ha->max_fibre_devices; i++) {
  2364. /* Issue GFPN_ID */
  2365. /* Prepare common MS IOCB */
  2366. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  2367. /* Prepare CT request */
  2368. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFPN_ID_CMD,
  2369. GFPN_ID_RSP_SIZE);
  2370. ct_rsp = &ha->ct_sns->p.rsp;
  2371. /* Prepare CT arguments -- port_id */
  2372. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  2373. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  2374. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  2375. /* Execute MS IOCB */
  2376. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2377. sizeof(ms_iocb_entry_t));
  2378. if (rval != QLA_SUCCESS) {
  2379. /*EMPTY*/
  2380. ql_dbg(ql_dbg_disc, vha, 0x2023,
  2381. "GFPN_ID issue IOCB failed (%d).\n", rval);
  2382. break;
  2383. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2384. "GFPN_ID") != QLA_SUCCESS) {
  2385. rval = QLA_FUNCTION_FAILED;
  2386. break;
  2387. } else {
  2388. /* Save fabric portname */
  2389. memcpy(list[i].fabric_port_name,
  2390. ct_rsp->rsp.gfpn_id.port_name, WWN_SIZE);
  2391. }
  2392. /* Last device exit. */
  2393. if (list[i].d_id.b.rsvd_1 != 0)
  2394. break;
  2395. }
  2396. return (rval);
  2397. }
  2398. static inline struct ct_sns_req *
  2399. qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd,
  2400. uint16_t rsp_size)
  2401. {
  2402. memset(p, 0, sizeof(struct ct_sns_pkt));
  2403. p->p.req.header.revision = 0x01;
  2404. p->p.req.header.gs_type = 0xFA;
  2405. p->p.req.header.gs_subtype = 0x01;
  2406. p->p.req.command = cpu_to_be16(cmd);
  2407. p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
  2408. return &p->p.req;
  2409. }
  2410. /**
  2411. * qla2x00_gpsc() - FCS Get Port Speed Capabilities (GPSC) query.
  2412. * @vha: HA context
  2413. * @list: switch info entries to populate
  2414. *
  2415. * Returns 0 on success.
  2416. */
  2417. int
  2418. qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list)
  2419. {
  2420. int rval;
  2421. uint16_t i;
  2422. struct qla_hw_data *ha = vha->hw;
  2423. ms_iocb_entry_t *ms_pkt;
  2424. struct ct_sns_req *ct_req;
  2425. struct ct_sns_rsp *ct_rsp;
  2426. struct ct_arg arg;
  2427. if (!IS_IIDMA_CAPABLE(ha))
  2428. return QLA_FUNCTION_FAILED;
  2429. if (!ha->flags.gpsc_supported)
  2430. return QLA_FUNCTION_FAILED;
  2431. rval = qla2x00_mgmt_svr_login(vha);
  2432. if (rval)
  2433. return rval;
  2434. arg.iocb = ha->ms_iocb;
  2435. arg.req_dma = ha->ct_sns_dma;
  2436. arg.rsp_dma = ha->ct_sns_dma;
  2437. arg.req_size = GPSC_REQ_SIZE;
  2438. arg.rsp_size = GPSC_RSP_SIZE;
  2439. arg.nport_handle = vha->mgmt_svr_loop_id;
  2440. for (i = 0; i < ha->max_fibre_devices; i++) {
  2441. /* Issue GFPN_ID */
  2442. /* Prepare common MS IOCB */
  2443. ms_pkt = qla24xx_prep_ms_iocb(vha, &arg);
  2444. /* Prepare CT request */
  2445. ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD,
  2446. GPSC_RSP_SIZE);
  2447. ct_rsp = &ha->ct_sns->p.rsp;
  2448. /* Prepare CT arguments -- port_name */
  2449. memcpy(ct_req->req.gpsc.port_name, list[i].fabric_port_name,
  2450. WWN_SIZE);
  2451. /* Execute MS IOCB */
  2452. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2453. sizeof(ms_iocb_entry_t));
  2454. if (rval != QLA_SUCCESS) {
  2455. /*EMPTY*/
  2456. ql_dbg(ql_dbg_disc, vha, 0x2059,
  2457. "GPSC issue IOCB failed (%d).\n", rval);
  2458. } else if ((rval = qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2459. "GPSC")) != QLA_SUCCESS) {
  2460. /* FM command unsupported? */
  2461. if (rval == QLA_INVALID_COMMAND &&
  2462. (ct_rsp->header.reason_code ==
  2463. CT_REASON_INVALID_COMMAND_CODE ||
  2464. ct_rsp->header.reason_code ==
  2465. CT_REASON_COMMAND_UNSUPPORTED)) {
  2466. ql_dbg(ql_dbg_disc, vha, 0x205a,
  2467. "GPSC command unsupported, disabling "
  2468. "query.\n");
  2469. ha->flags.gpsc_supported = 0;
  2470. rval = QLA_FUNCTION_FAILED;
  2471. break;
  2472. }
  2473. rval = QLA_FUNCTION_FAILED;
  2474. } else {
  2475. /* Save port-speed */
  2476. switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
  2477. case BIT_15:
  2478. list[i].fp_speed = PORT_SPEED_1GB;
  2479. break;
  2480. case BIT_14:
  2481. list[i].fp_speed = PORT_SPEED_2GB;
  2482. break;
  2483. case BIT_13:
  2484. list[i].fp_speed = PORT_SPEED_4GB;
  2485. break;
  2486. case BIT_12:
  2487. list[i].fp_speed = PORT_SPEED_10GB;
  2488. break;
  2489. case BIT_11:
  2490. list[i].fp_speed = PORT_SPEED_8GB;
  2491. break;
  2492. case BIT_10:
  2493. list[i].fp_speed = PORT_SPEED_16GB;
  2494. break;
  2495. case BIT_8:
  2496. list[i].fp_speed = PORT_SPEED_32GB;
  2497. break;
  2498. }
  2499. ql_dbg(ql_dbg_disc, vha, 0x205b,
  2500. "GPSC ext entry - fpn "
  2501. "%8phN speeds=%04x speed=%04x.\n",
  2502. list[i].fabric_port_name,
  2503. be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
  2504. be16_to_cpu(ct_rsp->rsp.gpsc.speed));
  2505. }
  2506. /* Last device exit. */
  2507. if (list[i].d_id.b.rsvd_1 != 0)
  2508. break;
  2509. }
  2510. return (rval);
  2511. }
  2512. /**
  2513. * qla2x00_gff_id() - SNS Get FC-4 Features (GFF_ID) query.
  2514. *
  2515. * @vha: HA context
  2516. * @list: switch info entries to populate
  2517. *
  2518. */
  2519. void
  2520. qla2x00_gff_id(scsi_qla_host_t *vha, sw_info_t *list)
  2521. {
  2522. int rval;
  2523. uint16_t i;
  2524. ms_iocb_entry_t *ms_pkt;
  2525. struct ct_sns_req *ct_req;
  2526. struct ct_sns_rsp *ct_rsp;
  2527. struct qla_hw_data *ha = vha->hw;
  2528. uint8_t fcp_scsi_features = 0;
  2529. struct ct_arg arg;
  2530. for (i = 0; i < ha->max_fibre_devices; i++) {
  2531. /* Set default FC4 Type as UNKNOWN so the default is to
  2532. * Process this port */
  2533. list[i].fc4_type = FC4_TYPE_UNKNOWN;
  2534. /* Do not attempt GFF_ID if we are not FWI_2 capable */
  2535. if (!IS_FWI2_CAPABLE(ha))
  2536. continue;
  2537. arg.iocb = ha->ms_iocb;
  2538. arg.req_dma = ha->ct_sns_dma;
  2539. arg.rsp_dma = ha->ct_sns_dma;
  2540. arg.req_size = GFF_ID_REQ_SIZE;
  2541. arg.rsp_size = GFF_ID_RSP_SIZE;
  2542. arg.nport_handle = NPH_SNS;
  2543. /* Prepare common MS IOCB */
  2544. ms_pkt = ha->isp_ops->prep_ms_iocb(vha, &arg);
  2545. /* Prepare CT request */
  2546. ct_req = qla2x00_prep_ct_req(ha->ct_sns, GFF_ID_CMD,
  2547. GFF_ID_RSP_SIZE);
  2548. ct_rsp = &ha->ct_sns->p.rsp;
  2549. /* Prepare CT arguments -- port_id */
  2550. ct_req->req.port_id.port_id[0] = list[i].d_id.b.domain;
  2551. ct_req->req.port_id.port_id[1] = list[i].d_id.b.area;
  2552. ct_req->req.port_id.port_id[2] = list[i].d_id.b.al_pa;
  2553. /* Execute MS IOCB */
  2554. rval = qla2x00_issue_iocb(vha, ha->ms_iocb, ha->ms_iocb_dma,
  2555. sizeof(ms_iocb_entry_t));
  2556. if (rval != QLA_SUCCESS) {
  2557. ql_dbg(ql_dbg_disc, vha, 0x205c,
  2558. "GFF_ID issue IOCB failed (%d).\n", rval);
  2559. } else if (qla2x00_chk_ms_status(vha, ms_pkt, ct_rsp,
  2560. "GFF_ID") != QLA_SUCCESS) {
  2561. ql_dbg(ql_dbg_disc, vha, 0x205d,
  2562. "GFF_ID IOCB status had a failure status code.\n");
  2563. } else {
  2564. fcp_scsi_features =
  2565. ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
  2566. fcp_scsi_features &= 0x0f;
  2567. if (fcp_scsi_features)
  2568. list[i].fc4_type = FC4_TYPE_FCP_SCSI;
  2569. else
  2570. list[i].fc4_type = FC4_TYPE_OTHER;
  2571. list[i].fc4f_nvme =
  2572. ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
  2573. list[i].fc4f_nvme &= 0xf;
  2574. }
  2575. /* Last device exit. */
  2576. if (list[i].d_id.b.rsvd_1 != 0)
  2577. break;
  2578. }
  2579. }
  2580. /* GID_PN completion processing. */
  2581. void qla24xx_handle_gidpn_event(scsi_qla_host_t *vha, struct event_arg *ea)
  2582. {
  2583. fc_port_t *fcport = ea->fcport;
  2584. ql_dbg(ql_dbg_disc, vha, 0x201d,
  2585. "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
  2586. __func__, fcport->port_name, fcport->disc_state,
  2587. fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
  2588. fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
  2589. if (fcport->disc_state == DSC_DELETE_PEND)
  2590. return;
  2591. if (ea->sp->gen2 != fcport->login_gen) {
  2592. /* PLOGI/PRLI/LOGO came in while cmd was out.*/
  2593. ql_dbg(ql_dbg_disc, vha, 0x201e,
  2594. "%s %8phC generation changed rscn %d|%d n",
  2595. __func__, fcport->port_name, fcport->last_rscn_gen,
  2596. fcport->rscn_gen);
  2597. return;
  2598. }
  2599. if (!ea->rc) {
  2600. if (ea->sp->gen1 == fcport->rscn_gen) {
  2601. fcport->scan_state = QLA_FCPORT_FOUND;
  2602. fcport->flags |= FCF_FABRIC_DEVICE;
  2603. if (fcport->d_id.b24 == ea->id.b24) {
  2604. /* cable plugged into the same place */
  2605. switch (vha->host->active_mode) {
  2606. case MODE_TARGET:
  2607. if (fcport->fw_login_state ==
  2608. DSC_LS_PRLI_COMP) {
  2609. u16 data[2];
  2610. /*
  2611. * Late RSCN was delivered.
  2612. * Remote port already login'ed.
  2613. */
  2614. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2615. "%s %d %8phC post adisc\n",
  2616. __func__, __LINE__,
  2617. fcport->port_name);
  2618. data[0] = data[1] = 0;
  2619. qla2x00_post_async_adisc_work(
  2620. vha, fcport, data);
  2621. }
  2622. break;
  2623. case MODE_INITIATOR:
  2624. case MODE_DUAL:
  2625. default:
  2626. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2627. "%s %d %8phC post %s\n", __func__,
  2628. __LINE__, fcport->port_name,
  2629. (atomic_read(&fcport->state) ==
  2630. FCS_ONLINE) ? "adisc" : "gnl");
  2631. if (atomic_read(&fcport->state) ==
  2632. FCS_ONLINE) {
  2633. u16 data[2];
  2634. data[0] = data[1] = 0;
  2635. qla2x00_post_async_adisc_work(
  2636. vha, fcport, data);
  2637. } else {
  2638. qla24xx_post_gnl_work(vha,
  2639. fcport);
  2640. }
  2641. break;
  2642. }
  2643. } else { /* fcport->d_id.b24 != ea->id.b24 */
  2644. fcport->d_id.b24 = ea->id.b24;
  2645. fcport->id_changed = 1;
  2646. if (fcport->deleted != QLA_SESS_DELETED) {
  2647. ql_dbg(ql_dbg_disc, vha, 0x2021,
  2648. "%s %d %8phC post del sess\n",
  2649. __func__, __LINE__, fcport->port_name);
  2650. qlt_schedule_sess_for_deletion(fcport);
  2651. }
  2652. }
  2653. } else { /* ea->sp->gen1 != fcport->rscn_gen */
  2654. ql_dbg(ql_dbg_disc, vha, 0x2022,
  2655. "%s %d %8phC post gidpn\n",
  2656. __func__, __LINE__, fcport->port_name);
  2657. /* rscn came in while cmd was out */
  2658. qla24xx_post_gidpn_work(vha, fcport);
  2659. }
  2660. } else { /* ea->rc */
  2661. /* cable pulled */
  2662. if (ea->sp->gen1 == fcport->rscn_gen) {
  2663. if (ea->sp->gen2 == fcport->login_gen) {
  2664. ql_dbg(ql_dbg_disc, vha, 0x2042,
  2665. "%s %d %8phC post del sess\n", __func__,
  2666. __LINE__, fcport->port_name);
  2667. qlt_schedule_sess_for_deletion(fcport);
  2668. } else {
  2669. ql_dbg(ql_dbg_disc, vha, 0x2045,
  2670. "%s %d %8phC login\n", __func__, __LINE__,
  2671. fcport->port_name);
  2672. qla24xx_fcport_handle_login(vha, fcport);
  2673. }
  2674. } else {
  2675. ql_dbg(ql_dbg_disc, vha, 0x2049,
  2676. "%s %d %8phC post gidpn\n", __func__, __LINE__,
  2677. fcport->port_name);
  2678. qla24xx_post_gidpn_work(vha, fcport);
  2679. }
  2680. }
  2681. } /* gidpn_event */
  2682. static void qla2x00_async_gidpn_sp_done(void *s, int res)
  2683. {
  2684. struct srb *sp = s;
  2685. struct scsi_qla_host *vha = sp->vha;
  2686. fc_port_t *fcport = sp->fcport;
  2687. u8 *id = fcport->ct_desc.ct_sns->p.rsp.rsp.gid_pn.port_id;
  2688. struct event_arg ea;
  2689. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  2690. memset(&ea, 0, sizeof(ea));
  2691. ea.fcport = fcport;
  2692. ea.id.b.domain = id[0];
  2693. ea.id.b.area = id[1];
  2694. ea.id.b.al_pa = id[2];
  2695. ea.sp = sp;
  2696. ea.rc = res;
  2697. ea.event = FCME_GIDPN_DONE;
  2698. if (res == QLA_FUNCTION_TIMEOUT) {
  2699. ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
  2700. "Async done-%s WWPN %8phC timed out.\n",
  2701. sp->name, fcport->port_name);
  2702. qla24xx_post_gidpn_work(sp->vha, fcport);
  2703. sp->free(sp);
  2704. return;
  2705. } else if (res) {
  2706. ql_dbg(ql_dbg_disc, sp->vha, 0xffff,
  2707. "Async done-%s fail res %x, WWPN %8phC\n",
  2708. sp->name, res, fcport->port_name);
  2709. } else {
  2710. ql_dbg(ql_dbg_disc, vha, 0x204f,
  2711. "Async done-%s good WWPN %8phC ID %3phC\n",
  2712. sp->name, fcport->port_name, id);
  2713. }
  2714. qla2x00_fcport_event_handler(vha, &ea);
  2715. sp->free(sp);
  2716. }
  2717. int qla24xx_async_gidpn(scsi_qla_host_t *vha, fc_port_t *fcport)
  2718. {
  2719. int rval = QLA_FUNCTION_FAILED;
  2720. struct ct_sns_req *ct_req;
  2721. srb_t *sp;
  2722. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  2723. return rval;
  2724. fcport->disc_state = DSC_GID_PN;
  2725. fcport->scan_state = QLA_FCPORT_SCAN;
  2726. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  2727. if (!sp)
  2728. goto done;
  2729. fcport->flags |= FCF_ASYNC_SENT;
  2730. sp->type = SRB_CT_PTHRU_CMD;
  2731. sp->name = "gidpn";
  2732. sp->gen1 = fcport->rscn_gen;
  2733. sp->gen2 = fcport->login_gen;
  2734. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  2735. /* CT_IU preamble */
  2736. ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GID_PN_CMD,
  2737. GID_PN_RSP_SIZE);
  2738. /* GIDPN req */
  2739. memcpy(ct_req->req.gid_pn.port_name, fcport->port_name,
  2740. WWN_SIZE);
  2741. /* req & rsp use the same buffer */
  2742. sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
  2743. sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
  2744. sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
  2745. sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
  2746. sp->u.iocb_cmd.u.ctarg.req_size = GID_PN_REQ_SIZE;
  2747. sp->u.iocb_cmd.u.ctarg.rsp_size = GID_PN_RSP_SIZE;
  2748. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  2749. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  2750. sp->done = qla2x00_async_gidpn_sp_done;
  2751. rval = qla2x00_start_sp(sp);
  2752. if (rval != QLA_SUCCESS)
  2753. goto done_free_sp;
  2754. ql_dbg(ql_dbg_disc, vha, 0x20a4,
  2755. "Async-%s - %8phC hdl=%x loopid=%x portid %02x%02x%02x.\n",
  2756. sp->name, fcport->port_name,
  2757. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  2758. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  2759. return rval;
  2760. done_free_sp:
  2761. sp->free(sp);
  2762. done:
  2763. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  2764. return rval;
  2765. }
  2766. int qla24xx_post_gidpn_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  2767. {
  2768. struct qla_work_evt *e;
  2769. int ls;
  2770. ls = atomic_read(&vha->loop_state);
  2771. if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
  2772. test_bit(UNLOADING, &vha->dpc_flags))
  2773. return 0;
  2774. e = qla2x00_alloc_work(vha, QLA_EVT_GIDPN);
  2775. if (!e)
  2776. return QLA_FUNCTION_FAILED;
  2777. e->u.fcport.fcport = fcport;
  2778. fcport->flags |= FCF_ASYNC_ACTIVE;
  2779. return qla2x00_post_work(vha, e);
  2780. }
  2781. int qla24xx_post_gpsc_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  2782. {
  2783. struct qla_work_evt *e;
  2784. e = qla2x00_alloc_work(vha, QLA_EVT_GPSC);
  2785. if (!e)
  2786. return QLA_FUNCTION_FAILED;
  2787. e->u.fcport.fcport = fcport;
  2788. fcport->flags |= FCF_ASYNC_ACTIVE;
  2789. return qla2x00_post_work(vha, e);
  2790. }
  2791. void qla24xx_handle_gpsc_event(scsi_qla_host_t *vha, struct event_arg *ea)
  2792. {
  2793. struct fc_port *fcport = ea->fcport;
  2794. ql_dbg(ql_dbg_disc, vha, 0x20d8,
  2795. "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
  2796. __func__, fcport->port_name, fcport->disc_state,
  2797. fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
  2798. ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, fcport->loop_id);
  2799. if (fcport->disc_state == DSC_DELETE_PEND)
  2800. return;
  2801. if (ea->sp->gen2 != fcport->login_gen) {
  2802. /* target side must have changed it. */
  2803. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  2804. "%s %8phC generation changed\n",
  2805. __func__, fcport->port_name);
  2806. return;
  2807. } else if (ea->sp->gen1 != fcport->rscn_gen) {
  2808. ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
  2809. __func__, __LINE__, fcport->port_name);
  2810. qla24xx_post_gidpn_work(vha, fcport);
  2811. return;
  2812. }
  2813. qla_post_iidma_work(vha, fcport);
  2814. }
  2815. static void qla24xx_async_gpsc_sp_done(void *s, int res)
  2816. {
  2817. struct srb *sp = s;
  2818. struct scsi_qla_host *vha = sp->vha;
  2819. struct qla_hw_data *ha = vha->hw;
  2820. fc_port_t *fcport = sp->fcport;
  2821. struct ct_sns_rsp *ct_rsp;
  2822. struct event_arg ea;
  2823. ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
  2824. ql_dbg(ql_dbg_disc, vha, 0x2053,
  2825. "Async done-%s res %x, WWPN %8phC \n",
  2826. sp->name, res, fcport->port_name);
  2827. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  2828. if (res == QLA_FUNCTION_TIMEOUT)
  2829. goto done;
  2830. if (res == (DID_ERROR << 16)) {
  2831. /* entry status error */
  2832. goto done;
  2833. } else if (res) {
  2834. if ((ct_rsp->header.reason_code ==
  2835. CT_REASON_INVALID_COMMAND_CODE) ||
  2836. (ct_rsp->header.reason_code ==
  2837. CT_REASON_COMMAND_UNSUPPORTED)) {
  2838. ql_dbg(ql_dbg_disc, vha, 0x2019,
  2839. "GPSC command unsupported, disabling query.\n");
  2840. ha->flags.gpsc_supported = 0;
  2841. goto done;
  2842. }
  2843. } else {
  2844. switch (be16_to_cpu(ct_rsp->rsp.gpsc.speed)) {
  2845. case BIT_15:
  2846. fcport->fp_speed = PORT_SPEED_1GB;
  2847. break;
  2848. case BIT_14:
  2849. fcport->fp_speed = PORT_SPEED_2GB;
  2850. break;
  2851. case BIT_13:
  2852. fcport->fp_speed = PORT_SPEED_4GB;
  2853. break;
  2854. case BIT_12:
  2855. fcport->fp_speed = PORT_SPEED_10GB;
  2856. break;
  2857. case BIT_11:
  2858. fcport->fp_speed = PORT_SPEED_8GB;
  2859. break;
  2860. case BIT_10:
  2861. fcport->fp_speed = PORT_SPEED_16GB;
  2862. break;
  2863. case BIT_8:
  2864. fcport->fp_speed = PORT_SPEED_32GB;
  2865. break;
  2866. }
  2867. ql_dbg(ql_dbg_disc, vha, 0x2054,
  2868. "Async-%s OUT WWPN %8phC speeds=%04x speed=%04x.\n",
  2869. sp->name, fcport->fabric_port_name,
  2870. be16_to_cpu(ct_rsp->rsp.gpsc.speeds),
  2871. be16_to_cpu(ct_rsp->rsp.gpsc.speed));
  2872. }
  2873. memset(&ea, 0, sizeof(ea));
  2874. ea.event = FCME_GPSC_DONE;
  2875. ea.rc = res;
  2876. ea.fcport = fcport;
  2877. ea.sp = sp;
  2878. qla2x00_fcport_event_handler(vha, &ea);
  2879. done:
  2880. sp->free(sp);
  2881. }
  2882. int qla24xx_async_gpsc(scsi_qla_host_t *vha, fc_port_t *fcport)
  2883. {
  2884. int rval = QLA_FUNCTION_FAILED;
  2885. struct ct_sns_req *ct_req;
  2886. srb_t *sp;
  2887. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  2888. return rval;
  2889. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  2890. if (!sp)
  2891. goto done;
  2892. sp->type = SRB_CT_PTHRU_CMD;
  2893. sp->name = "gpsc";
  2894. sp->gen1 = fcport->rscn_gen;
  2895. sp->gen2 = fcport->login_gen;
  2896. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  2897. /* CT_IU preamble */
  2898. ct_req = qla24xx_prep_ct_fm_req(fcport->ct_desc.ct_sns, GPSC_CMD,
  2899. GPSC_RSP_SIZE);
  2900. /* GPSC req */
  2901. memcpy(ct_req->req.gpsc.port_name, fcport->fabric_port_name,
  2902. WWN_SIZE);
  2903. sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
  2904. sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
  2905. sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
  2906. sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
  2907. sp->u.iocb_cmd.u.ctarg.req_size = GPSC_REQ_SIZE;
  2908. sp->u.iocb_cmd.u.ctarg.rsp_size = GPSC_RSP_SIZE;
  2909. sp->u.iocb_cmd.u.ctarg.nport_handle = vha->mgmt_svr_loop_id;
  2910. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  2911. sp->done = qla24xx_async_gpsc_sp_done;
  2912. ql_dbg(ql_dbg_disc, vha, 0x205e,
  2913. "Async-%s %8phC hdl=%x loopid=%x portid=%02x%02x%02x.\n",
  2914. sp->name, fcport->port_name, sp->handle,
  2915. fcport->loop_id, fcport->d_id.b.domain,
  2916. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  2917. rval = qla2x00_start_sp(sp);
  2918. if (rval != QLA_SUCCESS)
  2919. goto done_free_sp;
  2920. return rval;
  2921. done_free_sp:
  2922. sp->free(sp);
  2923. fcport->flags &= ~FCF_ASYNC_SENT;
  2924. done:
  2925. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  2926. return rval;
  2927. }
  2928. int qla24xx_post_gpnid_work(struct scsi_qla_host *vha, port_id_t *id)
  2929. {
  2930. struct qla_work_evt *e;
  2931. if (test_bit(UNLOADING, &vha->dpc_flags))
  2932. return 0;
  2933. e = qla2x00_alloc_work(vha, QLA_EVT_GPNID);
  2934. if (!e)
  2935. return QLA_FUNCTION_FAILED;
  2936. e->u.gpnid.id = *id;
  2937. return qla2x00_post_work(vha, e);
  2938. }
  2939. void qla24xx_sp_unmap(scsi_qla_host_t *vha, srb_t *sp)
  2940. {
  2941. struct srb_iocb *c = &sp->u.iocb_cmd;
  2942. switch (sp->type) {
  2943. case SRB_ELS_DCMD:
  2944. if (c->u.els_plogi.els_plogi_pyld)
  2945. dma_free_coherent(&vha->hw->pdev->dev,
  2946. c->u.els_plogi.tx_size,
  2947. c->u.els_plogi.els_plogi_pyld,
  2948. c->u.els_plogi.els_plogi_pyld_dma);
  2949. if (c->u.els_plogi.els_resp_pyld)
  2950. dma_free_coherent(&vha->hw->pdev->dev,
  2951. c->u.els_plogi.rx_size,
  2952. c->u.els_plogi.els_resp_pyld,
  2953. c->u.els_plogi.els_resp_pyld_dma);
  2954. break;
  2955. case SRB_CT_PTHRU_CMD:
  2956. default:
  2957. if (sp->u.iocb_cmd.u.ctarg.req) {
  2958. dma_free_coherent(&vha->hw->pdev->dev,
  2959. sp->u.iocb_cmd.u.ctarg.req_allocated_size,
  2960. sp->u.iocb_cmd.u.ctarg.req,
  2961. sp->u.iocb_cmd.u.ctarg.req_dma);
  2962. sp->u.iocb_cmd.u.ctarg.req = NULL;
  2963. }
  2964. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  2965. dma_free_coherent(&vha->hw->pdev->dev,
  2966. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
  2967. sp->u.iocb_cmd.u.ctarg.rsp,
  2968. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  2969. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  2970. }
  2971. break;
  2972. }
  2973. sp->free(sp);
  2974. }
  2975. void qla24xx_handle_gpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
  2976. {
  2977. fc_port_t *fcport, *conflict, *t;
  2978. u16 data[2];
  2979. ql_dbg(ql_dbg_disc, vha, 0xffff,
  2980. "%s %d port_id: %06x\n",
  2981. __func__, __LINE__, ea->id.b24);
  2982. if (ea->rc) {
  2983. /* cable is disconnected */
  2984. list_for_each_entry_safe(fcport, t, &vha->vp_fcports, list) {
  2985. if (fcport->d_id.b24 == ea->id.b24) {
  2986. ql_dbg(ql_dbg_disc, vha, 0xffff,
  2987. "%s %d %8phC DS %d\n",
  2988. __func__, __LINE__,
  2989. fcport->port_name,
  2990. fcport->disc_state);
  2991. fcport->scan_state = QLA_FCPORT_SCAN;
  2992. switch (fcport->disc_state) {
  2993. case DSC_DELETED:
  2994. case DSC_DELETE_PEND:
  2995. break;
  2996. default:
  2997. ql_dbg(ql_dbg_disc, vha, 0xffff,
  2998. "%s %d %8phC post del sess\n",
  2999. __func__, __LINE__,
  3000. fcport->port_name);
  3001. qlt_schedule_sess_for_deletion(fcport);
  3002. break;
  3003. }
  3004. }
  3005. }
  3006. } else {
  3007. /* cable is connected */
  3008. fcport = qla2x00_find_fcport_by_wwpn(vha, ea->port_name, 1);
  3009. if (fcport) {
  3010. list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
  3011. list) {
  3012. if ((conflict->d_id.b24 == ea->id.b24) &&
  3013. (fcport != conflict)) {
  3014. /* 2 fcports with conflict Nport ID or
  3015. * an existing fcport is having nport ID
  3016. * conflict with new fcport.
  3017. */
  3018. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3019. "%s %d %8phC DS %d\n",
  3020. __func__, __LINE__,
  3021. conflict->port_name,
  3022. conflict->disc_state);
  3023. conflict->scan_state = QLA_FCPORT_SCAN;
  3024. switch (conflict->disc_state) {
  3025. case DSC_DELETED:
  3026. case DSC_DELETE_PEND:
  3027. break;
  3028. default:
  3029. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3030. "%s %d %8phC post del sess\n",
  3031. __func__, __LINE__,
  3032. conflict->port_name);
  3033. qlt_schedule_sess_for_deletion
  3034. (conflict);
  3035. break;
  3036. }
  3037. }
  3038. }
  3039. fcport->rscn_gen++;
  3040. fcport->scan_state = QLA_FCPORT_FOUND;
  3041. fcport->flags |= FCF_FABRIC_DEVICE;
  3042. if (fcport->login_retry == 0) {
  3043. fcport->login_retry =
  3044. vha->hw->login_retry_count;
  3045. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3046. "Port login retry %8phN, lid 0x%04x cnt=%d.\n",
  3047. fcport->port_name, fcport->loop_id,
  3048. fcport->login_retry);
  3049. }
  3050. switch (fcport->disc_state) {
  3051. case DSC_LOGIN_COMPLETE:
  3052. /* recheck session is still intact. */
  3053. ql_dbg(ql_dbg_disc, vha, 0x210d,
  3054. "%s %d %8phC revalidate session with ADISC\n",
  3055. __func__, __LINE__, fcport->port_name);
  3056. data[0] = data[1] = 0;
  3057. qla2x00_post_async_adisc_work(vha, fcport,
  3058. data);
  3059. break;
  3060. case DSC_DELETED:
  3061. ql_dbg(ql_dbg_disc, vha, 0x210d,
  3062. "%s %d %8phC login\n", __func__, __LINE__,
  3063. fcport->port_name);
  3064. fcport->d_id = ea->id;
  3065. qla24xx_fcport_handle_login(vha, fcport);
  3066. break;
  3067. case DSC_DELETE_PEND:
  3068. fcport->d_id = ea->id;
  3069. break;
  3070. default:
  3071. fcport->d_id = ea->id;
  3072. break;
  3073. }
  3074. } else {
  3075. list_for_each_entry_safe(conflict, t, &vha->vp_fcports,
  3076. list) {
  3077. if (conflict->d_id.b24 == ea->id.b24) {
  3078. /* 2 fcports with conflict Nport ID or
  3079. * an existing fcport is having nport ID
  3080. * conflict with new fcport.
  3081. */
  3082. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3083. "%s %d %8phC DS %d\n",
  3084. __func__, __LINE__,
  3085. conflict->port_name,
  3086. conflict->disc_state);
  3087. conflict->scan_state = QLA_FCPORT_SCAN;
  3088. switch (conflict->disc_state) {
  3089. case DSC_DELETED:
  3090. case DSC_DELETE_PEND:
  3091. break;
  3092. default:
  3093. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3094. "%s %d %8phC post del sess\n",
  3095. __func__, __LINE__,
  3096. conflict->port_name);
  3097. qlt_schedule_sess_for_deletion
  3098. (conflict);
  3099. break;
  3100. }
  3101. }
  3102. }
  3103. /* create new fcport */
  3104. ql_dbg(ql_dbg_disc, vha, 0x2065,
  3105. "%s %d %8phC post new sess\n",
  3106. __func__, __LINE__, ea->port_name);
  3107. qla24xx_post_newsess_work(vha, &ea->id,
  3108. ea->port_name, NULL, NULL, FC4_TYPE_UNKNOWN);
  3109. }
  3110. }
  3111. }
  3112. static void qla2x00_async_gpnid_sp_done(void *s, int res)
  3113. {
  3114. struct srb *sp = s;
  3115. struct scsi_qla_host *vha = sp->vha;
  3116. struct ct_sns_req *ct_req =
  3117. (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
  3118. struct ct_sns_rsp *ct_rsp =
  3119. (struct ct_sns_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
  3120. struct event_arg ea;
  3121. struct qla_work_evt *e;
  3122. unsigned long flags;
  3123. if (res)
  3124. ql_dbg(ql_dbg_disc, vha, 0x2066,
  3125. "Async done-%s fail res %x rscn gen %d ID %3phC. %8phC\n",
  3126. sp->name, res, sp->gen1, ct_req->req.port_id.port_id,
  3127. ct_rsp->rsp.gpn_id.port_name);
  3128. else
  3129. ql_dbg(ql_dbg_disc, vha, 0x2066,
  3130. "Async done-%s good rscn gen %d ID %3phC. %8phC\n",
  3131. sp->name, sp->gen1, ct_req->req.port_id.port_id,
  3132. ct_rsp->rsp.gpn_id.port_name);
  3133. memset(&ea, 0, sizeof(ea));
  3134. memcpy(ea.port_name, ct_rsp->rsp.gpn_id.port_name, WWN_SIZE);
  3135. ea.sp = sp;
  3136. ea.id.b.domain = ct_req->req.port_id.port_id[0];
  3137. ea.id.b.area = ct_req->req.port_id.port_id[1];
  3138. ea.id.b.al_pa = ct_req->req.port_id.port_id[2];
  3139. ea.rc = res;
  3140. ea.event = FCME_GPNID_DONE;
  3141. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  3142. list_del(&sp->elem);
  3143. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  3144. if (res) {
  3145. if (res == QLA_FUNCTION_TIMEOUT) {
  3146. qla24xx_post_gpnid_work(sp->vha, &ea.id);
  3147. sp->free(sp);
  3148. return;
  3149. }
  3150. } else if (sp->gen1) {
  3151. /* There was another RSCN for this Nport ID */
  3152. qla24xx_post_gpnid_work(sp->vha, &ea.id);
  3153. sp->free(sp);
  3154. return;
  3155. }
  3156. qla2x00_fcport_event_handler(vha, &ea);
  3157. e = qla2x00_alloc_work(vha, QLA_EVT_UNMAP);
  3158. if (!e) {
  3159. /* please ignore kernel warning. otherwise, we have mem leak. */
  3160. if (sp->u.iocb_cmd.u.ctarg.req) {
  3161. dma_free_coherent(&vha->hw->pdev->dev,
  3162. sp->u.iocb_cmd.u.ctarg.req_allocated_size,
  3163. sp->u.iocb_cmd.u.ctarg.req,
  3164. sp->u.iocb_cmd.u.ctarg.req_dma);
  3165. sp->u.iocb_cmd.u.ctarg.req = NULL;
  3166. }
  3167. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  3168. dma_free_coherent(&vha->hw->pdev->dev,
  3169. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
  3170. sp->u.iocb_cmd.u.ctarg.rsp,
  3171. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  3172. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  3173. }
  3174. sp->free(sp);
  3175. return;
  3176. }
  3177. e->u.iosb.sp = sp;
  3178. qla2x00_post_work(vha, e);
  3179. }
  3180. /* Get WWPN with Nport ID. */
  3181. int qla24xx_async_gpnid(scsi_qla_host_t *vha, port_id_t *id)
  3182. {
  3183. int rval = QLA_FUNCTION_FAILED;
  3184. struct ct_sns_req *ct_req;
  3185. srb_t *sp, *tsp;
  3186. struct ct_sns_pkt *ct_sns;
  3187. unsigned long flags;
  3188. if (!vha->flags.online)
  3189. goto done;
  3190. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  3191. if (!sp)
  3192. goto done;
  3193. sp->type = SRB_CT_PTHRU_CMD;
  3194. sp->name = "gpnid";
  3195. sp->u.iocb_cmd.u.ctarg.id = *id;
  3196. sp->gen1 = 0;
  3197. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  3198. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  3199. list_for_each_entry(tsp, &vha->gpnid_list, elem) {
  3200. if (tsp->u.iocb_cmd.u.ctarg.id.b24 == id->b24) {
  3201. tsp->gen1++;
  3202. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  3203. sp->free(sp);
  3204. goto done;
  3205. }
  3206. }
  3207. list_add_tail(&sp->elem, &vha->gpnid_list);
  3208. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  3209. sp->u.iocb_cmd.u.ctarg.req = dma_alloc_coherent(&vha->hw->pdev->dev,
  3210. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.req_dma,
  3211. GFP_KERNEL);
  3212. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  3213. if (!sp->u.iocb_cmd.u.ctarg.req) {
  3214. ql_log(ql_log_warn, vha, 0xd041,
  3215. "Failed to allocate ct_sns request.\n");
  3216. goto done_free_sp;
  3217. }
  3218. sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev,
  3219. sizeof(struct ct_sns_pkt), &sp->u.iocb_cmd.u.ctarg.rsp_dma,
  3220. GFP_KERNEL);
  3221. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  3222. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  3223. ql_log(ql_log_warn, vha, 0xd042,
  3224. "Failed to allocate ct_sns request.\n");
  3225. goto done_free_sp;
  3226. }
  3227. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.rsp;
  3228. memset(ct_sns, 0, sizeof(*ct_sns));
  3229. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  3230. /* CT_IU preamble */
  3231. ct_req = qla2x00_prep_ct_req(ct_sns, GPN_ID_CMD, GPN_ID_RSP_SIZE);
  3232. /* GPN_ID req */
  3233. ct_req->req.port_id.port_id[0] = id->b.domain;
  3234. ct_req->req.port_id.port_id[1] = id->b.area;
  3235. ct_req->req.port_id.port_id[2] = id->b.al_pa;
  3236. sp->u.iocb_cmd.u.ctarg.req_size = GPN_ID_REQ_SIZE;
  3237. sp->u.iocb_cmd.u.ctarg.rsp_size = GPN_ID_RSP_SIZE;
  3238. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  3239. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  3240. sp->done = qla2x00_async_gpnid_sp_done;
  3241. ql_dbg(ql_dbg_disc, vha, 0x2067,
  3242. "Async-%s hdl=%x ID %3phC.\n", sp->name,
  3243. sp->handle, ct_req->req.port_id.port_id);
  3244. rval = qla2x00_start_sp(sp);
  3245. if (rval != QLA_SUCCESS)
  3246. goto done_free_sp;
  3247. return rval;
  3248. done_free_sp:
  3249. spin_lock_irqsave(&vha->hw->vport_slock, flags);
  3250. list_del(&sp->elem);
  3251. spin_unlock_irqrestore(&vha->hw->vport_slock, flags);
  3252. if (sp->u.iocb_cmd.u.ctarg.req) {
  3253. dma_free_coherent(&vha->hw->pdev->dev,
  3254. sizeof(struct ct_sns_pkt),
  3255. sp->u.iocb_cmd.u.ctarg.req,
  3256. sp->u.iocb_cmd.u.ctarg.req_dma);
  3257. sp->u.iocb_cmd.u.ctarg.req = NULL;
  3258. }
  3259. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  3260. dma_free_coherent(&vha->hw->pdev->dev,
  3261. sizeof(struct ct_sns_pkt),
  3262. sp->u.iocb_cmd.u.ctarg.rsp,
  3263. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  3264. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  3265. }
  3266. sp->free(sp);
  3267. done:
  3268. return rval;
  3269. }
  3270. void qla24xx_handle_gffid_event(scsi_qla_host_t *vha, struct event_arg *ea)
  3271. {
  3272. fc_port_t *fcport = ea->fcport;
  3273. qla24xx_post_gnl_work(vha, fcport);
  3274. }
  3275. void qla24xx_async_gffid_sp_done(void *s, int res)
  3276. {
  3277. struct srb *sp = s;
  3278. struct scsi_qla_host *vha = sp->vha;
  3279. fc_port_t *fcport = sp->fcport;
  3280. struct ct_sns_rsp *ct_rsp;
  3281. struct event_arg ea;
  3282. ql_dbg(ql_dbg_disc, vha, 0x2133,
  3283. "Async done-%s res %x ID %x. %8phC\n",
  3284. sp->name, res, fcport->d_id.b24, fcport->port_name);
  3285. fcport->flags &= ~FCF_ASYNC_SENT;
  3286. ct_rsp = &fcport->ct_desc.ct_sns->p.rsp;
  3287. /*
  3288. * FC-GS-7, 5.2.3.12 FC-4 Features - format
  3289. * The format of the FC-4 Features object, as defined by the FC-4,
  3290. * Shall be an array of 4-bit values, one for each type code value
  3291. */
  3292. if (!res) {
  3293. if (ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET] & 0xf) {
  3294. /* w1 b00:03 */
  3295. fcport->fc4_type =
  3296. ct_rsp->rsp.gff_id.fc4_features[GFF_FCP_SCSI_OFFSET];
  3297. fcport->fc4_type &= 0xf;
  3298. }
  3299. if (ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET] & 0xf) {
  3300. /* w5 [00:03]/28h */
  3301. fcport->fc4f_nvme =
  3302. ct_rsp->rsp.gff_id.fc4_features[GFF_NVME_OFFSET];
  3303. fcport->fc4f_nvme &= 0xf;
  3304. }
  3305. }
  3306. memset(&ea, 0, sizeof(ea));
  3307. ea.sp = sp;
  3308. ea.fcport = sp->fcport;
  3309. ea.rc = res;
  3310. ea.event = FCME_GFFID_DONE;
  3311. qla2x00_fcport_event_handler(vha, &ea);
  3312. sp->free(sp);
  3313. }
  3314. /* Get FC4 Feature with Nport ID. */
  3315. int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport)
  3316. {
  3317. int rval = QLA_FUNCTION_FAILED;
  3318. struct ct_sns_req *ct_req;
  3319. srb_t *sp;
  3320. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  3321. return rval;
  3322. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  3323. if (!sp)
  3324. return rval;
  3325. fcport->flags |= FCF_ASYNC_SENT;
  3326. sp->type = SRB_CT_PTHRU_CMD;
  3327. sp->name = "gffid";
  3328. sp->gen1 = fcport->rscn_gen;
  3329. sp->gen2 = fcport->login_gen;
  3330. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  3331. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  3332. /* CT_IU preamble */
  3333. ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFF_ID_CMD,
  3334. GFF_ID_RSP_SIZE);
  3335. ct_req->req.gff_id.port_id[0] = fcport->d_id.b.domain;
  3336. ct_req->req.gff_id.port_id[1] = fcport->d_id.b.area;
  3337. ct_req->req.gff_id.port_id[2] = fcport->d_id.b.al_pa;
  3338. sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
  3339. sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
  3340. sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
  3341. sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
  3342. sp->u.iocb_cmd.u.ctarg.req_size = GFF_ID_REQ_SIZE;
  3343. sp->u.iocb_cmd.u.ctarg.rsp_size = GFF_ID_RSP_SIZE;
  3344. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  3345. sp->done = qla24xx_async_gffid_sp_done;
  3346. rval = qla2x00_start_sp(sp);
  3347. if (rval != QLA_SUCCESS)
  3348. goto done_free_sp;
  3349. ql_dbg(ql_dbg_disc, vha, 0x2132,
  3350. "Async-%s hdl=%x %8phC.\n", sp->name,
  3351. sp->handle, fcport->port_name);
  3352. return rval;
  3353. done_free_sp:
  3354. sp->free(sp);
  3355. fcport->flags &= ~FCF_ASYNC_SENT;
  3356. return rval;
  3357. }
  3358. /* GPN_FT + GNN_FT*/
  3359. static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn)
  3360. {
  3361. struct qla_hw_data *ha = vha->hw;
  3362. scsi_qla_host_t *vp;
  3363. unsigned long flags;
  3364. u64 twwn;
  3365. int rc = 0;
  3366. if (!ha->num_vhosts)
  3367. return 0;
  3368. spin_lock_irqsave(&ha->vport_slock, flags);
  3369. list_for_each_entry(vp, &ha->vp_list, list) {
  3370. twwn = wwn_to_u64(vp->port_name);
  3371. if (wwn == twwn) {
  3372. rc = 1;
  3373. break;
  3374. }
  3375. }
  3376. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3377. return rc;
  3378. }
  3379. void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
  3380. {
  3381. fc_port_t *fcport;
  3382. u32 i, rc;
  3383. bool found;
  3384. struct fab_scan_rp *rp, *trp;
  3385. unsigned long flags;
  3386. u8 recheck = 0;
  3387. u16 dup = 0, dup_cnt = 0;
  3388. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3389. "%s enter\n", __func__);
  3390. if (sp->gen1 != vha->hw->base_qpair->chip_reset) {
  3391. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3392. "%s scan stop due to chip reset %x/%x\n",
  3393. sp->name, sp->gen1, vha->hw->base_qpair->chip_reset);
  3394. goto out;
  3395. }
  3396. rc = sp->rc;
  3397. if (rc) {
  3398. vha->scan.scan_retry++;
  3399. if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
  3400. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3401. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3402. } else {
  3403. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3404. "Fabric scan failed on all retries.\n");
  3405. }
  3406. goto out;
  3407. }
  3408. vha->scan.scan_retry = 0;
  3409. list_for_each_entry(fcport, &vha->vp_fcports, list)
  3410. fcport->scan_state = QLA_FCPORT_SCAN;
  3411. for (i = 0; i < vha->hw->max_fibre_devices; i++) {
  3412. u64 wwn;
  3413. int k;
  3414. rp = &vha->scan.l[i];
  3415. found = false;
  3416. wwn = wwn_to_u64(rp->port_name);
  3417. if (wwn == 0)
  3418. continue;
  3419. /* Remove duplicate NPORT ID entries from switch data base */
  3420. for (k = i + 1; k < vha->hw->max_fibre_devices; k++) {
  3421. trp = &vha->scan.l[k];
  3422. if (rp->id.b24 == trp->id.b24) {
  3423. dup = 1;
  3424. dup_cnt++;
  3425. ql_dbg(ql_dbg_disc + ql_dbg_verbose,
  3426. vha, 0xffff,
  3427. "Detected duplicate NPORT ID from switch data base: ID %06x WWN %8phN WWN %8phN\n",
  3428. rp->id.b24, rp->port_name, trp->port_name);
  3429. memset(trp, 0, sizeof(*trp));
  3430. }
  3431. }
  3432. if (!memcmp(rp->port_name, vha->port_name, WWN_SIZE))
  3433. continue;
  3434. /* Bypass reserved domain fields. */
  3435. if ((rp->id.b.domain & 0xf0) == 0xf0)
  3436. continue;
  3437. /* Bypass virtual ports of the same host. */
  3438. if (qla2x00_is_a_vp(vha, wwn))
  3439. continue;
  3440. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3441. if (memcmp(rp->port_name, fcport->port_name, WWN_SIZE))
  3442. continue;
  3443. fcport->rscn_rcvd = 0;
  3444. fcport->scan_state = QLA_FCPORT_FOUND;
  3445. found = true;
  3446. /*
  3447. * If device was not a fabric device before.
  3448. */
  3449. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3450. qla2x00_clear_loop_id(fcport);
  3451. fcport->flags |= FCF_FABRIC_DEVICE;
  3452. } else if (fcport->d_id.b24 != rp->id.b24) {
  3453. qlt_schedule_sess_for_deletion(fcport);
  3454. }
  3455. fcport->d_id.b24 = rp->id.b24;
  3456. break;
  3457. }
  3458. if (!found) {
  3459. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3460. "%s %d %8phC post new sess\n",
  3461. __func__, __LINE__, rp->port_name);
  3462. qla24xx_post_newsess_work(vha, &rp->id, rp->port_name,
  3463. rp->node_name, NULL, rp->fc4type);
  3464. }
  3465. }
  3466. if (dup) {
  3467. ql_log(ql_log_warn, vha, 0xffff,
  3468. "Detected %d duplicate NPORT ID(s) from switch data base\n",
  3469. dup_cnt);
  3470. }
  3471. /*
  3472. * Logout all previous fabric dev marked lost, except FCP2 devices.
  3473. */
  3474. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3475. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3476. fcport->rscn_rcvd = 0;
  3477. continue;
  3478. }
  3479. if (fcport->scan_state != QLA_FCPORT_FOUND) {
  3480. fcport->rscn_rcvd = 0;
  3481. if ((qla_dual_mode_enabled(vha) ||
  3482. qla_ini_mode_enabled(vha)) &&
  3483. atomic_read(&fcport->state) == FCS_ONLINE) {
  3484. qla2x00_mark_device_lost(vha, fcport,
  3485. ql2xplogiabsentdevice, 0);
  3486. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3487. (fcport->flags & FCF_FCP2_DEVICE) == 0) {
  3488. ql_dbg(ql_dbg_disc, vha, 0x20f0,
  3489. "%s %d %8phC post del sess\n",
  3490. __func__, __LINE__,
  3491. fcport->port_name);
  3492. qlt_schedule_sess_for_deletion(fcport);
  3493. continue;
  3494. }
  3495. }
  3496. } else {
  3497. if (fcport->rscn_rcvd ||
  3498. fcport->disc_state != DSC_LOGIN_COMPLETE) {
  3499. if (fcport->login_retry == 0) {
  3500. fcport->login_retry =
  3501. vha->hw->login_retry_count;
  3502. ql_dbg(ql_dbg_disc, vha, 0x20a3,
  3503. "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
  3504. fcport->port_name, fcport->loop_id,
  3505. fcport->login_retry);
  3506. }
  3507. fcport->rscn_rcvd = 0;
  3508. qla24xx_fcport_handle_login(vha, fcport);
  3509. }
  3510. }
  3511. }
  3512. recheck = 1;
  3513. out:
  3514. qla24xx_sp_unmap(vha, sp);
  3515. spin_lock_irqsave(&vha->work_lock, flags);
  3516. vha->scan.scan_flags &= ~SF_SCANNING;
  3517. spin_unlock_irqrestore(&vha->work_lock, flags);
  3518. if (recheck) {
  3519. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3520. if (fcport->rscn_rcvd) {
  3521. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3522. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3523. break;
  3524. }
  3525. }
  3526. }
  3527. }
  3528. static int qla2x00_post_gnnft_gpnft_done_work(struct scsi_qla_host *vha,
  3529. srb_t *sp, int cmd)
  3530. {
  3531. struct qla_work_evt *e;
  3532. if (cmd != QLA_EVT_GPNFT_DONE && cmd != QLA_EVT_GNNFT_DONE)
  3533. return QLA_PARAMETER_ERROR;
  3534. e = qla2x00_alloc_work(vha, cmd);
  3535. if (!e)
  3536. return QLA_FUNCTION_FAILED;
  3537. e->u.iosb.sp = sp;
  3538. return qla2x00_post_work(vha, e);
  3539. }
  3540. static int qla2x00_post_nvme_gpnft_done_work(struct scsi_qla_host *vha,
  3541. srb_t *sp, int cmd)
  3542. {
  3543. struct qla_work_evt *e;
  3544. if (cmd != QLA_EVT_GPNFT)
  3545. return QLA_PARAMETER_ERROR;
  3546. e = qla2x00_alloc_work(vha, cmd);
  3547. if (!e)
  3548. return QLA_FUNCTION_FAILED;
  3549. e->u.gpnft.fc4_type = FC4_TYPE_NVME;
  3550. e->u.gpnft.sp = sp;
  3551. return qla2x00_post_work(vha, e);
  3552. }
  3553. static void qla2x00_find_free_fcp_nvme_slot(struct scsi_qla_host *vha,
  3554. struct srb *sp)
  3555. {
  3556. struct qla_hw_data *ha = vha->hw;
  3557. int num_fibre_dev = ha->max_fibre_devices;
  3558. struct ct_sns_req *ct_req =
  3559. (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
  3560. struct ct_sns_gpnft_rsp *ct_rsp =
  3561. (struct ct_sns_gpnft_rsp *)sp->u.iocb_cmd.u.ctarg.rsp;
  3562. struct ct_sns_gpn_ft_data *d;
  3563. struct fab_scan_rp *rp;
  3564. u16 cmd = be16_to_cpu(ct_req->command);
  3565. u8 fc4_type = sp->gen2;
  3566. int i, j, k;
  3567. port_id_t id;
  3568. u8 found;
  3569. u64 wwn;
  3570. j = 0;
  3571. for (i = 0; i < num_fibre_dev; i++) {
  3572. d = &ct_rsp->entries[i];
  3573. id.b.rsvd_1 = 0;
  3574. id.b.domain = d->port_id[0];
  3575. id.b.area = d->port_id[1];
  3576. id.b.al_pa = d->port_id[2];
  3577. wwn = wwn_to_u64(d->port_name);
  3578. if (id.b24 == 0 || wwn == 0)
  3579. continue;
  3580. if (fc4_type == FC4_TYPE_FCP_SCSI) {
  3581. if (cmd == GPN_FT_CMD) {
  3582. rp = &vha->scan.l[j];
  3583. rp->id = id;
  3584. memcpy(rp->port_name, d->port_name, 8);
  3585. j++;
  3586. rp->fc4type = FS_FC4TYPE_FCP;
  3587. } else {
  3588. for (k = 0; k < num_fibre_dev; k++) {
  3589. rp = &vha->scan.l[k];
  3590. if (id.b24 == rp->id.b24) {
  3591. memcpy(rp->node_name,
  3592. d->port_name, 8);
  3593. break;
  3594. }
  3595. }
  3596. }
  3597. } else {
  3598. /* Search if the fibre device supports FC4_TYPE_NVME */
  3599. if (cmd == GPN_FT_CMD) {
  3600. found = 0;
  3601. for (k = 0; k < num_fibre_dev; k++) {
  3602. rp = &vha->scan.l[k];
  3603. if (!memcmp(rp->port_name,
  3604. d->port_name, 8)) {
  3605. /*
  3606. * Supports FC-NVMe & FCP
  3607. */
  3608. rp->fc4type |= FS_FC4TYPE_NVME;
  3609. found = 1;
  3610. break;
  3611. }
  3612. }
  3613. /* We found new FC-NVMe only port */
  3614. if (!found) {
  3615. for (k = 0; k < num_fibre_dev; k++) {
  3616. rp = &vha->scan.l[k];
  3617. if (wwn_to_u64(rp->port_name)) {
  3618. continue;
  3619. } else {
  3620. rp->id = id;
  3621. memcpy(rp->port_name,
  3622. d->port_name, 8);
  3623. rp->fc4type =
  3624. FS_FC4TYPE_NVME;
  3625. break;
  3626. }
  3627. }
  3628. }
  3629. } else {
  3630. for (k = 0; k < num_fibre_dev; k++) {
  3631. rp = &vha->scan.l[k];
  3632. if (id.b24 == rp->id.b24) {
  3633. memcpy(rp->node_name,
  3634. d->port_name, 8);
  3635. break;
  3636. }
  3637. }
  3638. }
  3639. }
  3640. }
  3641. }
  3642. static void qla2x00_async_gpnft_gnnft_sp_done(void *s, int res)
  3643. {
  3644. struct srb *sp = s;
  3645. struct scsi_qla_host *vha = sp->vha;
  3646. struct ct_sns_req *ct_req =
  3647. (struct ct_sns_req *)sp->u.iocb_cmd.u.ctarg.req;
  3648. u16 cmd = be16_to_cpu(ct_req->command);
  3649. u8 fc4_type = sp->gen2;
  3650. unsigned long flags;
  3651. int rc;
  3652. /* gen2 field is holding the fc4type */
  3653. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3654. "Async done-%s res %x FC4Type %x\n",
  3655. sp->name, res, sp->gen2);
  3656. sp->rc = res;
  3657. if (res) {
  3658. unsigned long flags;
  3659. const char *name = sp->name;
  3660. /*
  3661. * We are in an Interrupt context, queue up this
  3662. * sp for GNNFT_DONE work. This will allow all
  3663. * the resource to get freed up.
  3664. */
  3665. rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
  3666. QLA_EVT_GNNFT_DONE);
  3667. if (rc) {
  3668. /* Cleanup here to prevent memory leak */
  3669. qla24xx_sp_unmap(vha, sp);
  3670. sp->free(sp);
  3671. }
  3672. spin_lock_irqsave(&vha->work_lock, flags);
  3673. vha->scan.scan_flags &= ~SF_SCANNING;
  3674. vha->scan.scan_retry++;
  3675. spin_unlock_irqrestore(&vha->work_lock, flags);
  3676. if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
  3677. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3678. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3679. qla2xxx_wake_dpc(vha);
  3680. } else {
  3681. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3682. "Async done-%s rescan failed on all retries.\n",
  3683. name);
  3684. }
  3685. return;
  3686. }
  3687. if (!res)
  3688. qla2x00_find_free_fcp_nvme_slot(vha, sp);
  3689. if ((fc4_type == FC4_TYPE_FCP_SCSI) && vha->flags.nvme_enabled &&
  3690. cmd == GNN_FT_CMD) {
  3691. del_timer(&sp->u.iocb_cmd.timer);
  3692. spin_lock_irqsave(&vha->work_lock, flags);
  3693. vha->scan.scan_flags &= ~SF_SCANNING;
  3694. spin_unlock_irqrestore(&vha->work_lock, flags);
  3695. sp->rc = res;
  3696. rc = qla2x00_post_nvme_gpnft_done_work(vha, sp, QLA_EVT_GPNFT);
  3697. if (!rc) {
  3698. qla24xx_sp_unmap(vha, sp);
  3699. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3700. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3701. return;
  3702. }
  3703. }
  3704. if (cmd == GPN_FT_CMD) {
  3705. del_timer(&sp->u.iocb_cmd.timer);
  3706. rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
  3707. QLA_EVT_GPNFT_DONE);
  3708. } else {
  3709. rc = qla2x00_post_gnnft_gpnft_done_work(vha, sp,
  3710. QLA_EVT_GNNFT_DONE);
  3711. }
  3712. if (rc) {
  3713. qla24xx_sp_unmap(vha, sp);
  3714. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3715. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3716. return;
  3717. }
  3718. }
  3719. /*
  3720. * Get WWNN list for fc4_type
  3721. *
  3722. * It is assumed the same SRB is re-used from GPNFT to avoid
  3723. * mem free & re-alloc
  3724. */
  3725. static int qla24xx_async_gnnft(scsi_qla_host_t *vha, struct srb *sp,
  3726. u8 fc4_type)
  3727. {
  3728. int rval = QLA_FUNCTION_FAILED;
  3729. struct ct_sns_req *ct_req;
  3730. struct ct_sns_pkt *ct_sns;
  3731. unsigned long flags;
  3732. if (!vha->flags.online) {
  3733. spin_lock_irqsave(&vha->work_lock, flags);
  3734. vha->scan.scan_flags &= ~SF_SCANNING;
  3735. spin_unlock_irqrestore(&vha->work_lock, flags);
  3736. goto done_free_sp;
  3737. }
  3738. if (!sp->u.iocb_cmd.u.ctarg.req || !sp->u.iocb_cmd.u.ctarg.rsp) {
  3739. ql_log(ql_log_warn, vha, 0xffff,
  3740. "%s: req %p rsp %p are not setup\n",
  3741. __func__, sp->u.iocb_cmd.u.ctarg.req,
  3742. sp->u.iocb_cmd.u.ctarg.rsp);
  3743. spin_lock_irqsave(&vha->work_lock, flags);
  3744. vha->scan.scan_flags &= ~SF_SCANNING;
  3745. spin_unlock_irqrestore(&vha->work_lock, flags);
  3746. WARN_ON(1);
  3747. goto done_free_sp;
  3748. }
  3749. ql_dbg(ql_dbg_disc, vha, 0xfffff,
  3750. "%s: FC4Type %x, CT-PASSTRHU %s command ctarg rsp size %d, ctarg req size %d\n",
  3751. __func__, fc4_type, sp->name, sp->u.iocb_cmd.u.ctarg.rsp_size,
  3752. sp->u.iocb_cmd.u.ctarg.req_size);
  3753. sp->type = SRB_CT_PTHRU_CMD;
  3754. sp->name = "gnnft";
  3755. sp->gen1 = vha->hw->base_qpair->chip_reset;
  3756. sp->gen2 = fc4_type;
  3757. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  3758. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  3759. memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
  3760. memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
  3761. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  3762. /* CT_IU preamble */
  3763. ct_req = qla2x00_prep_ct_req(ct_sns, GNN_FT_CMD,
  3764. sp->u.iocb_cmd.u.ctarg.rsp_size);
  3765. /* GPN_FT req */
  3766. ct_req->req.gpn_ft.port_type = fc4_type;
  3767. sp->u.iocb_cmd.u.ctarg.req_size = GNN_FT_REQ_SIZE;
  3768. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  3769. sp->done = qla2x00_async_gpnft_gnnft_sp_done;
  3770. rval = qla2x00_start_sp(sp);
  3771. if (rval != QLA_SUCCESS)
  3772. goto done_free_sp;
  3773. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3774. "Async-%s hdl=%x FC4Type %x.\n", sp->name,
  3775. sp->handle, ct_req->req.gpn_ft.port_type);
  3776. return rval;
  3777. done_free_sp:
  3778. if (sp->u.iocb_cmd.u.ctarg.req) {
  3779. dma_free_coherent(&vha->hw->pdev->dev,
  3780. sp->u.iocb_cmd.u.ctarg.req_allocated_size,
  3781. sp->u.iocb_cmd.u.ctarg.req,
  3782. sp->u.iocb_cmd.u.ctarg.req_dma);
  3783. sp->u.iocb_cmd.u.ctarg.req = NULL;
  3784. }
  3785. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  3786. dma_free_coherent(&vha->hw->pdev->dev,
  3787. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
  3788. sp->u.iocb_cmd.u.ctarg.rsp,
  3789. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  3790. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  3791. }
  3792. sp->free(sp);
  3793. return rval;
  3794. } /* GNNFT */
  3795. void qla24xx_async_gpnft_done(scsi_qla_host_t *vha, srb_t *sp)
  3796. {
  3797. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3798. "%s enter\n", __func__);
  3799. qla24xx_async_gnnft(vha, sp, sp->gen2);
  3800. }
  3801. /* Get WWPN list for certain fc4_type */
  3802. int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp)
  3803. {
  3804. int rval = QLA_FUNCTION_FAILED;
  3805. struct ct_sns_req *ct_req;
  3806. struct ct_sns_pkt *ct_sns;
  3807. u32 rspsz;
  3808. unsigned long flags;
  3809. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3810. "%s enter\n", __func__);
  3811. if (!vha->flags.online)
  3812. return rval;
  3813. spin_lock_irqsave(&vha->work_lock, flags);
  3814. if (vha->scan.scan_flags & SF_SCANNING) {
  3815. spin_unlock_irqrestore(&vha->work_lock, flags);
  3816. ql_dbg(ql_dbg_disc, vha, 0xffff, "scan active\n");
  3817. return rval;
  3818. }
  3819. vha->scan.scan_flags |= SF_SCANNING;
  3820. spin_unlock_irqrestore(&vha->work_lock, flags);
  3821. if (fc4_type == FC4_TYPE_FCP_SCSI) {
  3822. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3823. "%s: Performing FCP Scan\n", __func__);
  3824. if (sp)
  3825. sp->free(sp); /* should not happen */
  3826. sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
  3827. if (!sp) {
  3828. spin_lock_irqsave(&vha->work_lock, flags);
  3829. vha->scan.scan_flags &= ~SF_SCANNING;
  3830. spin_unlock_irqrestore(&vha->work_lock, flags);
  3831. return rval;
  3832. }
  3833. sp->u.iocb_cmd.u.ctarg.req = dma_zalloc_coherent(
  3834. &vha->hw->pdev->dev, sizeof(struct ct_sns_pkt),
  3835. &sp->u.iocb_cmd.u.ctarg.req_dma, GFP_KERNEL);
  3836. sp->u.iocb_cmd.u.ctarg.req_allocated_size = sizeof(struct ct_sns_pkt);
  3837. if (!sp->u.iocb_cmd.u.ctarg.req) {
  3838. ql_log(ql_log_warn, vha, 0xffff,
  3839. "Failed to allocate ct_sns request.\n");
  3840. spin_lock_irqsave(&vha->work_lock, flags);
  3841. vha->scan.scan_flags &= ~SF_SCANNING;
  3842. spin_unlock_irqrestore(&vha->work_lock, flags);
  3843. goto done_free_sp;
  3844. }
  3845. sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE;
  3846. rspsz = sizeof(struct ct_sns_gpnft_rsp) +
  3847. ((vha->hw->max_fibre_devices - 1) *
  3848. sizeof(struct ct_sns_gpn_ft_data));
  3849. sp->u.iocb_cmd.u.ctarg.rsp = dma_zalloc_coherent(
  3850. &vha->hw->pdev->dev, rspsz,
  3851. &sp->u.iocb_cmd.u.ctarg.rsp_dma, GFP_KERNEL);
  3852. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size = sizeof(struct ct_sns_pkt);
  3853. if (!sp->u.iocb_cmd.u.ctarg.rsp) {
  3854. ql_log(ql_log_warn, vha, 0xffff,
  3855. "Failed to allocate ct_sns request.\n");
  3856. spin_lock_irqsave(&vha->work_lock, flags);
  3857. vha->scan.scan_flags &= ~SF_SCANNING;
  3858. spin_unlock_irqrestore(&vha->work_lock, flags);
  3859. goto done_free_sp;
  3860. }
  3861. sp->u.iocb_cmd.u.ctarg.rsp_size = rspsz;
  3862. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3863. "%s scan list size %d\n", __func__, vha->scan.size);
  3864. memset(vha->scan.l, 0, vha->scan.size);
  3865. } else if (!sp) {
  3866. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3867. "NVME scan did not provide SP\n");
  3868. return rval;
  3869. }
  3870. sp->type = SRB_CT_PTHRU_CMD;
  3871. sp->name = "gpnft";
  3872. sp->gen1 = vha->hw->base_qpair->chip_reset;
  3873. sp->gen2 = fc4_type;
  3874. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  3875. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  3876. rspsz = sp->u.iocb_cmd.u.ctarg.rsp_size;
  3877. memset(sp->u.iocb_cmd.u.ctarg.rsp, 0, sp->u.iocb_cmd.u.ctarg.rsp_size);
  3878. memset(sp->u.iocb_cmd.u.ctarg.req, 0, sp->u.iocb_cmd.u.ctarg.req_size);
  3879. ct_sns = (struct ct_sns_pkt *)sp->u.iocb_cmd.u.ctarg.req;
  3880. /* CT_IU preamble */
  3881. ct_req = qla2x00_prep_ct_req(ct_sns, GPN_FT_CMD, rspsz);
  3882. /* GPN_FT req */
  3883. ct_req->req.gpn_ft.port_type = fc4_type;
  3884. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  3885. sp->done = qla2x00_async_gpnft_gnnft_sp_done;
  3886. rval = qla2x00_start_sp(sp);
  3887. if (rval != QLA_SUCCESS) {
  3888. spin_lock_irqsave(&vha->work_lock, flags);
  3889. vha->scan.scan_flags &= ~SF_SCANNING;
  3890. spin_unlock_irqrestore(&vha->work_lock, flags);
  3891. goto done_free_sp;
  3892. }
  3893. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3894. "Async-%s hdl=%x FC4Type %x.\n", sp->name,
  3895. sp->handle, ct_req->req.gpn_ft.port_type);
  3896. return rval;
  3897. done_free_sp:
  3898. if (sp->u.iocb_cmd.u.ctarg.req) {
  3899. dma_free_coherent(&vha->hw->pdev->dev,
  3900. sp->u.iocb_cmd.u.ctarg.req_allocated_size,
  3901. sp->u.iocb_cmd.u.ctarg.req,
  3902. sp->u.iocb_cmd.u.ctarg.req_dma);
  3903. sp->u.iocb_cmd.u.ctarg.req = NULL;
  3904. }
  3905. if (sp->u.iocb_cmd.u.ctarg.rsp) {
  3906. dma_free_coherent(&vha->hw->pdev->dev,
  3907. sp->u.iocb_cmd.u.ctarg.rsp_allocated_size,
  3908. sp->u.iocb_cmd.u.ctarg.rsp,
  3909. sp->u.iocb_cmd.u.ctarg.rsp_dma);
  3910. sp->u.iocb_cmd.u.ctarg.rsp = NULL;
  3911. }
  3912. sp->free(sp);
  3913. return rval;
  3914. }
  3915. void qla_scan_work_fn(struct work_struct *work)
  3916. {
  3917. struct fab_scan *s = container_of(to_delayed_work(work),
  3918. struct fab_scan, scan_work);
  3919. struct scsi_qla_host *vha = container_of(s, struct scsi_qla_host,
  3920. scan);
  3921. unsigned long flags;
  3922. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3923. "%s: schedule loop resync\n", __func__);
  3924. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  3925. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3926. qla2xxx_wake_dpc(vha);
  3927. spin_lock_irqsave(&vha->work_lock, flags);
  3928. vha->scan.scan_flags &= ~SF_QUEUED;
  3929. spin_unlock_irqrestore(&vha->work_lock, flags);
  3930. }
  3931. /* GNN_ID */
  3932. void qla24xx_handle_gnnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
  3933. {
  3934. qla24xx_post_gnl_work(vha, ea->fcport);
  3935. }
  3936. static void qla2x00_async_gnnid_sp_done(void *s, int res)
  3937. {
  3938. struct srb *sp = s;
  3939. struct scsi_qla_host *vha = sp->vha;
  3940. fc_port_t *fcport = sp->fcport;
  3941. u8 *node_name = fcport->ct_desc.ct_sns->p.rsp.rsp.gnn_id.node_name;
  3942. struct event_arg ea;
  3943. u64 wwnn;
  3944. fcport->flags &= ~FCF_ASYNC_SENT;
  3945. wwnn = wwn_to_u64(node_name);
  3946. if (wwnn)
  3947. memcpy(fcport->node_name, node_name, WWN_SIZE);
  3948. memset(&ea, 0, sizeof(ea));
  3949. ea.fcport = fcport;
  3950. ea.sp = sp;
  3951. ea.rc = res;
  3952. ea.event = FCME_GNNID_DONE;
  3953. ql_dbg(ql_dbg_disc, vha, 0x204f,
  3954. "Async done-%s res %x, WWPN %8phC %8phC\n",
  3955. sp->name, res, fcport->port_name, fcport->node_name);
  3956. qla2x00_fcport_event_handler(vha, &ea);
  3957. sp->free(sp);
  3958. }
  3959. int qla24xx_async_gnnid(scsi_qla_host_t *vha, fc_port_t *fcport)
  3960. {
  3961. int rval = QLA_FUNCTION_FAILED;
  3962. struct ct_sns_req *ct_req;
  3963. srb_t *sp;
  3964. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  3965. return rval;
  3966. fcport->disc_state = DSC_GNN_ID;
  3967. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  3968. if (!sp)
  3969. goto done;
  3970. fcport->flags |= FCF_ASYNC_SENT;
  3971. sp->type = SRB_CT_PTHRU_CMD;
  3972. sp->name = "gnnid";
  3973. sp->gen1 = fcport->rscn_gen;
  3974. sp->gen2 = fcport->login_gen;
  3975. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  3976. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  3977. /* CT_IU preamble */
  3978. ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GNN_ID_CMD,
  3979. GNN_ID_RSP_SIZE);
  3980. /* GNN_ID req */
  3981. ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
  3982. ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
  3983. ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
  3984. /* req & rsp use the same buffer */
  3985. sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
  3986. sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
  3987. sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
  3988. sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
  3989. sp->u.iocb_cmd.u.ctarg.req_size = GNN_ID_REQ_SIZE;
  3990. sp->u.iocb_cmd.u.ctarg.rsp_size = GNN_ID_RSP_SIZE;
  3991. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  3992. sp->done = qla2x00_async_gnnid_sp_done;
  3993. rval = qla2x00_start_sp(sp);
  3994. if (rval != QLA_SUCCESS)
  3995. goto done_free_sp;
  3996. ql_dbg(ql_dbg_disc, vha, 0xffff,
  3997. "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
  3998. sp->name, fcport->port_name,
  3999. sp->handle, fcport->loop_id, fcport->d_id.b24);
  4000. return rval;
  4001. done_free_sp:
  4002. sp->free(sp);
  4003. fcport->flags &= ~FCF_ASYNC_SENT;
  4004. done:
  4005. return rval;
  4006. }
  4007. int qla24xx_post_gnnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  4008. {
  4009. struct qla_work_evt *e;
  4010. int ls;
  4011. ls = atomic_read(&vha->loop_state);
  4012. if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
  4013. test_bit(UNLOADING, &vha->dpc_flags))
  4014. return 0;
  4015. e = qla2x00_alloc_work(vha, QLA_EVT_GNNID);
  4016. if (!e)
  4017. return QLA_FUNCTION_FAILED;
  4018. e->u.fcport.fcport = fcport;
  4019. return qla2x00_post_work(vha, e);
  4020. }
  4021. /* GPFN_ID */
  4022. void qla24xx_handle_gfpnid_event(scsi_qla_host_t *vha, struct event_arg *ea)
  4023. {
  4024. fc_port_t *fcport = ea->fcport;
  4025. ql_dbg(ql_dbg_disc, vha, 0xffff,
  4026. "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d fcpcnt %d\n",
  4027. __func__, fcport->port_name, fcport->disc_state,
  4028. fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
  4029. fcport->rscn_gen, ea->sp->gen1, vha->fcport_count);
  4030. if (fcport->disc_state == DSC_DELETE_PEND)
  4031. return;
  4032. if (ea->sp->gen2 != fcport->login_gen) {
  4033. /* target side must have changed it. */
  4034. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  4035. "%s %8phC generation changed\n",
  4036. __func__, fcport->port_name);
  4037. return;
  4038. } else if (ea->sp->gen1 != fcport->rscn_gen) {
  4039. ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
  4040. __func__, __LINE__, fcport->port_name);
  4041. qla24xx_post_gidpn_work(vha, fcport);
  4042. return;
  4043. }
  4044. qla24xx_post_gpsc_work(vha, fcport);
  4045. }
  4046. static void qla2x00_async_gfpnid_sp_done(void *s, int res)
  4047. {
  4048. struct srb *sp = s;
  4049. struct scsi_qla_host *vha = sp->vha;
  4050. fc_port_t *fcport = sp->fcport;
  4051. u8 *fpn = fcport->ct_desc.ct_sns->p.rsp.rsp.gfpn_id.port_name;
  4052. struct event_arg ea;
  4053. u64 wwn;
  4054. wwn = wwn_to_u64(fpn);
  4055. if (wwn)
  4056. memcpy(fcport->fabric_port_name, fpn, WWN_SIZE);
  4057. memset(&ea, 0, sizeof(ea));
  4058. ea.fcport = fcport;
  4059. ea.sp = sp;
  4060. ea.rc = res;
  4061. ea.event = FCME_GFPNID_DONE;
  4062. ql_dbg(ql_dbg_disc, vha, 0x204f,
  4063. "Async done-%s res %x, WWPN %8phC %8phC\n",
  4064. sp->name, res, fcport->port_name, fcport->fabric_port_name);
  4065. qla2x00_fcport_event_handler(vha, &ea);
  4066. sp->free(sp);
  4067. }
  4068. int qla24xx_async_gfpnid(scsi_qla_host_t *vha, fc_port_t *fcport)
  4069. {
  4070. int rval = QLA_FUNCTION_FAILED;
  4071. struct ct_sns_req *ct_req;
  4072. srb_t *sp;
  4073. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  4074. return rval;
  4075. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  4076. if (!sp)
  4077. goto done;
  4078. sp->type = SRB_CT_PTHRU_CMD;
  4079. sp->name = "gfpnid";
  4080. sp->gen1 = fcport->rscn_gen;
  4081. sp->gen2 = fcport->login_gen;
  4082. sp->u.iocb_cmd.timeout = qla2x00_async_iocb_timeout;
  4083. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  4084. /* CT_IU preamble */
  4085. ct_req = qla2x00_prep_ct_req(fcport->ct_desc.ct_sns, GFPN_ID_CMD,
  4086. GFPN_ID_RSP_SIZE);
  4087. /* GFPN_ID req */
  4088. ct_req->req.port_id.port_id[0] = fcport->d_id.b.domain;
  4089. ct_req->req.port_id.port_id[1] = fcport->d_id.b.area;
  4090. ct_req->req.port_id.port_id[2] = fcport->d_id.b.al_pa;
  4091. /* req & rsp use the same buffer */
  4092. sp->u.iocb_cmd.u.ctarg.req = fcport->ct_desc.ct_sns;
  4093. sp->u.iocb_cmd.u.ctarg.req_dma = fcport->ct_desc.ct_sns_dma;
  4094. sp->u.iocb_cmd.u.ctarg.rsp = fcport->ct_desc.ct_sns;
  4095. sp->u.iocb_cmd.u.ctarg.rsp_dma = fcport->ct_desc.ct_sns_dma;
  4096. sp->u.iocb_cmd.u.ctarg.req_size = GFPN_ID_REQ_SIZE;
  4097. sp->u.iocb_cmd.u.ctarg.rsp_size = GFPN_ID_RSP_SIZE;
  4098. sp->u.iocb_cmd.u.ctarg.nport_handle = NPH_SNS;
  4099. sp->done = qla2x00_async_gfpnid_sp_done;
  4100. rval = qla2x00_start_sp(sp);
  4101. if (rval != QLA_SUCCESS)
  4102. goto done_free_sp;
  4103. ql_dbg(ql_dbg_disc, vha, 0xffff,
  4104. "Async-%s - %8phC hdl=%x loopid=%x portid %06x.\n",
  4105. sp->name, fcport->port_name,
  4106. sp->handle, fcport->loop_id, fcport->d_id.b24);
  4107. return rval;
  4108. done_free_sp:
  4109. sp->free(sp);
  4110. fcport->flags &= ~FCF_ASYNC_SENT;
  4111. done:
  4112. return rval;
  4113. }
  4114. int qla24xx_post_gfpnid_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  4115. {
  4116. struct qla_work_evt *e;
  4117. int ls;
  4118. ls = atomic_read(&vha->loop_state);
  4119. if (((ls != LOOP_READY) && (ls != LOOP_UP)) ||
  4120. test_bit(UNLOADING, &vha->dpc_flags))
  4121. return 0;
  4122. e = qla2x00_alloc_work(vha, QLA_EVT_GFPNID);
  4123. if (!e)
  4124. return QLA_FUNCTION_FAILED;
  4125. e->u.fcport.fcport = fcport;
  4126. return qla2x00_post_work(vha, e);
  4127. }