lpfc_ct.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * *
  10. * This program is free software; you can redistribute it and/or *
  11. * modify it under the terms of version 2 of the GNU General *
  12. * Public License as published by the Free Software Foundation. *
  13. * This program is distributed in the hope that it will be useful. *
  14. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  15. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  16. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  17. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  18. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  19. * more details, a copy of which can be found in the file COPYING *
  20. * included with this package. *
  21. *******************************************************************/
  22. /*
  23. * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
  24. */
  25. #include <linux/blkdev.h>
  26. #include <linux/pci.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/slab.h>
  29. #include <linux/utsname.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/fc/fc_fs.h>
  35. #include "lpfc_hw4.h"
  36. #include "lpfc_hw.h"
  37. #include "lpfc_sli.h"
  38. #include "lpfc_sli4.h"
  39. #include "lpfc_nl.h"
  40. #include "lpfc_disc.h"
  41. #include "lpfc.h"
  42. #include "lpfc_scsi.h"
  43. #include "lpfc_nvme.h"
  44. #include "lpfc_logmsg.h"
  45. #include "lpfc_crtn.h"
  46. #include "lpfc_version.h"
  47. #include "lpfc_vport.h"
  48. #include "lpfc_debugfs.h"
  49. /* FDMI Port Speed definitions - FC-GS-7 */
  50. #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
  51. #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
  52. #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
  53. #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
  54. #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
  55. #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
  56. #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
  57. #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
  58. #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
  59. #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
  60. #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
  61. #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
  62. #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
  63. #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
  64. #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
  65. #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
  66. #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
  67. #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
  68. #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
  69. #define FOURBYTES 4
  70. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  71. static void
  72. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  73. struct lpfc_dmabuf *mp, uint32_t size)
  74. {
  75. if (!mp) {
  76. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  77. "0146 Ignoring unsolicited CT No HBQ "
  78. "status = x%x\n",
  79. piocbq->iocb.ulpStatus);
  80. }
  81. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  82. "0145 Ignoring unsolicted CT HBQ Size:%d "
  83. "status = x%x\n",
  84. size, piocbq->iocb.ulpStatus);
  85. }
  86. static void
  87. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  88. struct lpfc_dmabuf *mp, uint32_t size)
  89. {
  90. lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
  91. }
  92. void
  93. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  94. struct lpfc_iocbq *piocbq)
  95. {
  96. struct lpfc_dmabuf *mp = NULL;
  97. IOCB_t *icmd = &piocbq->iocb;
  98. int i;
  99. struct lpfc_iocbq *iocbq;
  100. dma_addr_t paddr;
  101. uint32_t size;
  102. struct list_head head;
  103. struct lpfc_dmabuf *bdeBuf;
  104. if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
  105. return;
  106. if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
  107. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  108. } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  109. ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  110. IOERR_RCV_BUFFER_WAITING)) {
  111. /* Not enough posted buffers; Try posting more buffers */
  112. phba->fc_stat.NoRcvBuf++;
  113. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  114. lpfc_post_buffer(phba, pring, 2);
  115. return;
  116. }
  117. /* If there are no BDEs associated with this IOCB,
  118. * there is nothing to do.
  119. */
  120. if (icmd->ulpBdeCount == 0)
  121. return;
  122. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  123. INIT_LIST_HEAD(&head);
  124. list_add_tail(&head, &piocbq->list);
  125. list_for_each_entry(iocbq, &head, list) {
  126. icmd = &iocbq->iocb;
  127. if (icmd->ulpBdeCount == 0)
  128. continue;
  129. bdeBuf = iocbq->context2;
  130. iocbq->context2 = NULL;
  131. size = icmd->un.cont64[0].tus.f.bdeSize;
  132. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
  133. lpfc_in_buf_free(phba, bdeBuf);
  134. if (icmd->ulpBdeCount == 2) {
  135. bdeBuf = iocbq->context3;
  136. iocbq->context3 = NULL;
  137. size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
  138. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
  139. size);
  140. lpfc_in_buf_free(phba, bdeBuf);
  141. }
  142. }
  143. list_del(&head);
  144. } else {
  145. INIT_LIST_HEAD(&head);
  146. list_add_tail(&head, &piocbq->list);
  147. list_for_each_entry(iocbq, &head, list) {
  148. icmd = &iocbq->iocb;
  149. if (icmd->ulpBdeCount == 0)
  150. lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
  151. for (i = 0; i < icmd->ulpBdeCount; i++) {
  152. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  153. icmd->un.cont64[i].addrLow);
  154. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  155. paddr);
  156. size = icmd->un.cont64[i].tus.f.bdeSize;
  157. lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
  158. lpfc_in_buf_free(phba, mp);
  159. }
  160. lpfc_post_buffer(phba, pring, i);
  161. }
  162. list_del(&head);
  163. }
  164. }
  165. /**
  166. * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
  167. * @phba: Pointer to HBA context object.
  168. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  169. *
  170. * This function serves as the upper level protocol abort handler for CT
  171. * protocol.
  172. *
  173. * Return 1 if abort has been handled, 0 otherwise.
  174. **/
  175. int
  176. lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
  177. {
  178. int handled;
  179. /* CT upper level goes through BSG */
  180. handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
  181. return handled;
  182. }
  183. static void
  184. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  185. {
  186. struct lpfc_dmabuf *mlast, *next_mlast;
  187. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  188. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  189. list_del(&mlast->list);
  190. kfree(mlast);
  191. }
  192. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  193. kfree(mlist);
  194. return;
  195. }
  196. static struct lpfc_dmabuf *
  197. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  198. uint32_t size, int *entries)
  199. {
  200. struct lpfc_dmabuf *mlist = NULL;
  201. struct lpfc_dmabuf *mp;
  202. int cnt, i = 0;
  203. /* We get chunks of FCELSSIZE */
  204. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  205. while (size) {
  206. /* Allocate buffer for rsp payload */
  207. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  208. if (!mp) {
  209. if (mlist)
  210. lpfc_free_ct_rsp(phba, mlist);
  211. return NULL;
  212. }
  213. INIT_LIST_HEAD(&mp->list);
  214. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  215. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  216. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  217. else
  218. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  219. if (!mp->virt) {
  220. kfree(mp);
  221. if (mlist)
  222. lpfc_free_ct_rsp(phba, mlist);
  223. return NULL;
  224. }
  225. /* Queue it to a linked list */
  226. if (!mlist)
  227. mlist = mp;
  228. else
  229. list_add_tail(&mp->list, &mlist->list);
  230. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  231. /* build buffer ptr list for IOCB */
  232. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  233. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  234. bpl->tus.f.bdeSize = (uint16_t) cnt;
  235. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  236. bpl++;
  237. i++;
  238. size -= cnt;
  239. }
  240. *entries = i;
  241. return mlist;
  242. }
  243. int
  244. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  245. {
  246. struct lpfc_dmabuf *buf_ptr;
  247. if (ctiocb->context_un.ndlp) {
  248. lpfc_nlp_put(ctiocb->context_un.ndlp);
  249. ctiocb->context_un.ndlp = NULL;
  250. }
  251. if (ctiocb->context1) {
  252. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
  253. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  254. kfree(buf_ptr);
  255. ctiocb->context1 = NULL;
  256. }
  257. if (ctiocb->context2) {
  258. lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
  259. ctiocb->context2 = NULL;
  260. }
  261. if (ctiocb->context3) {
  262. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
  263. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  264. kfree(buf_ptr);
  265. ctiocb->context3 = NULL;
  266. }
  267. lpfc_sli_release_iocbq(phba, ctiocb);
  268. return 0;
  269. }
  270. /**
  271. * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
  272. * @vport: pointer to a host virtual N_Port data structure.
  273. * @bmp: Pointer to BPL for SLI command
  274. * @inp: Pointer to data buffer for response data.
  275. * @outp: Pointer to data buffer that hold the CT command.
  276. * @cmpl: completion routine to call when command completes
  277. * @ndlp: Destination NPort nodelist entry
  278. *
  279. * This function as the final part for issuing a CT command.
  280. */
  281. static int
  282. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  283. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  284. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  285. struct lpfc_iocbq *),
  286. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  287. uint32_t tmo, uint8_t retry)
  288. {
  289. struct lpfc_hba *phba = vport->phba;
  290. IOCB_t *icmd;
  291. struct lpfc_iocbq *geniocb;
  292. int rc;
  293. /* Allocate buffer for command iocb */
  294. geniocb = lpfc_sli_get_iocbq(phba);
  295. if (geniocb == NULL)
  296. return 1;
  297. icmd = &geniocb->iocb;
  298. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  299. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  300. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  301. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  302. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
  303. if (usr_flg)
  304. geniocb->context3 = NULL;
  305. else
  306. geniocb->context3 = (uint8_t *) bmp;
  307. /* Save for completion so we can release these resources */
  308. geniocb->context1 = (uint8_t *) inp;
  309. geniocb->context2 = (uint8_t *) outp;
  310. geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
  311. /* Fill in payload, bp points to frame payload */
  312. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  313. /* Fill in rest of iocb */
  314. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  315. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  316. icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
  317. icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
  318. if (!tmo) {
  319. /* FC spec states we need 3 * ratov for CT requests */
  320. tmo = (3 * phba->fc_ratov);
  321. }
  322. icmd->ulpTimeout = tmo;
  323. icmd->ulpBdeCount = 1;
  324. icmd->ulpLe = 1;
  325. icmd->ulpClass = CLASS3;
  326. icmd->ulpContext = ndlp->nlp_rpi;
  327. if (phba->sli_rev == LPFC_SLI_REV4)
  328. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  329. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  330. /* For GEN_REQUEST64_CR, use the RPI */
  331. icmd->ulpCt_h = 0;
  332. icmd->ulpCt_l = 0;
  333. }
  334. /* Issue GEN REQ IOCB for NPORT <did> */
  335. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  336. "0119 Issue GEN REQ IOCB to NPORT x%x "
  337. "Data: x%x x%x\n",
  338. ndlp->nlp_DID, icmd->ulpIoTag,
  339. vport->port_state);
  340. geniocb->iocb_cmpl = cmpl;
  341. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  342. geniocb->vport = vport;
  343. geniocb->retry = retry;
  344. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  345. if (rc == IOCB_ERROR) {
  346. lpfc_sli_release_iocbq(phba, geniocb);
  347. return 1;
  348. }
  349. return 0;
  350. }
  351. /**
  352. * lpfc_ct_cmd - Build and issue a CT command
  353. * @vport: pointer to a host virtual N_Port data structure.
  354. * @inmp: Pointer to data buffer for response data.
  355. * @bmp: Pointer to BPL for SLI command
  356. * @ndlp: Destination NPort nodelist entry
  357. * @cmpl: completion routine to call when command completes
  358. *
  359. * This function is called for issuing a CT command.
  360. */
  361. static int
  362. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  363. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  364. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  365. struct lpfc_iocbq *),
  366. uint32_t rsp_size, uint8_t retry)
  367. {
  368. struct lpfc_hba *phba = vport->phba;
  369. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  370. struct lpfc_dmabuf *outmp;
  371. int cnt = 0, status;
  372. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  373. CommandResponse.bits.CmdRsp;
  374. bpl++; /* Skip past ct request */
  375. /* Put buffer(s) for ct rsp in bpl */
  376. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  377. if (!outmp)
  378. return -ENOMEM;
  379. /*
  380. * Form the CT IOCB. The total number of BDEs in this IOCB
  381. * is the single command plus response count from
  382. * lpfc_alloc_ct_rsp.
  383. */
  384. cnt += 1;
  385. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  386. cnt, 0, retry);
  387. if (status) {
  388. lpfc_free_ct_rsp(phba, outmp);
  389. return -ENOMEM;
  390. }
  391. return 0;
  392. }
  393. struct lpfc_vport *
  394. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  395. struct lpfc_vport *vport_curr;
  396. unsigned long flags;
  397. spin_lock_irqsave(&phba->hbalock, flags);
  398. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  399. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  400. spin_unlock_irqrestore(&phba->hbalock, flags);
  401. return vport_curr;
  402. }
  403. }
  404. spin_unlock_irqrestore(&phba->hbalock, flags);
  405. return NULL;
  406. }
  407. static void
  408. lpfc_prep_node_fc4type(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
  409. {
  410. struct lpfc_nodelist *ndlp;
  411. if ((vport->port_type != LPFC_NPIV_PORT) ||
  412. !(vport->ct_flags & FC_CT_RFF_ID) || !vport->cfg_restrict_login) {
  413. ndlp = lpfc_setup_disc_node(vport, Did);
  414. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  415. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  416. "Parse GID_FTrsp: did:x%x flg:x%x x%x",
  417. Did, ndlp->nlp_flag, vport->fc_flag);
  418. /* By default, the driver expects to support FCP FC4 */
  419. if (fc4_type == FC_TYPE_FCP)
  420. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  421. if (fc4_type == FC_TYPE_NVME)
  422. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  423. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  424. "0238 Process x%06x NameServer Rsp "
  425. "Data: x%x x%x x%x x%x\n", Did,
  426. ndlp->nlp_flag, ndlp->nlp_fc4_type,
  427. vport->fc_flag,
  428. vport->fc_rscn_id_cnt);
  429. } else {
  430. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  431. "Skip1 GID_FTrsp: did:x%x flg:x%x cnt:%d",
  432. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  433. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  434. "0239 Skip x%06x NameServer Rsp "
  435. "Data: x%x x%x\n", Did,
  436. vport->fc_flag,
  437. vport->fc_rscn_id_cnt);
  438. }
  439. } else {
  440. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  441. lpfc_rscn_payload_check(vport, Did)) {
  442. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  443. "Query GID_FTrsp: did:x%x flg:x%x cnt:%d",
  444. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  445. /*
  446. * This NPortID was previously a FCP/NVMe target,
  447. * Don't even bother to send GFF_ID.
  448. */
  449. ndlp = lpfc_findnode_did(vport, Did);
  450. if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
  451. (ndlp->nlp_type &
  452. (NLP_FCP_TARGET | NLP_NVME_TARGET))) {
  453. if (fc4_type == FC_TYPE_FCP)
  454. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  455. if (fc4_type == FC_TYPE_NVME)
  456. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  457. lpfc_setup_disc_node(vport, Did);
  458. } else if (lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  459. 0, Did) == 0)
  460. vport->num_disc_nodes++;
  461. else
  462. lpfc_setup_disc_node(vport, Did);
  463. } else {
  464. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  465. "Skip2 GID_FTrsp: did:x%x flg:x%x cnt:%d",
  466. Did, vport->fc_flag, vport->fc_rscn_id_cnt);
  467. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  468. "0245 Skip x%06x NameServer Rsp "
  469. "Data: x%x x%x\n", Did,
  470. vport->fc_flag,
  471. vport->fc_rscn_id_cnt);
  472. }
  473. }
  474. }
  475. static void
  476. lpfc_ns_rsp_audit_did(struct lpfc_vport *vport, uint32_t Did, uint8_t fc4_type)
  477. {
  478. struct lpfc_hba *phba = vport->phba;
  479. struct lpfc_nodelist *ndlp = NULL;
  480. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  481. /*
  482. * To conserve rpi's, filter out addresses for other
  483. * vports on the same physical HBAs.
  484. */
  485. if (Did != vport->fc_myDID &&
  486. (!lpfc_find_vport_by_did(phba, Did) ||
  487. vport->cfg_peer_port_login)) {
  488. if (!phba->nvmet_support) {
  489. /* FCPI/NVMEI path. Process Did */
  490. lpfc_prep_node_fc4type(vport, Did, fc4_type);
  491. return;
  492. }
  493. /* NVMET path. NVMET only cares about NVMEI nodes. */
  494. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  495. if (ndlp->nlp_type != NLP_NVME_INITIATOR ||
  496. ndlp->nlp_state != NLP_STE_UNMAPPED_NODE)
  497. continue;
  498. spin_lock_irq(shost->host_lock);
  499. if (ndlp->nlp_DID == Did)
  500. ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
  501. else
  502. ndlp->nlp_flag |= NLP_NVMET_RECOV;
  503. spin_unlock_irq(shost->host_lock);
  504. }
  505. }
  506. }
  507. static int
  508. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint8_t fc4_type,
  509. uint32_t Size)
  510. {
  511. struct lpfc_sli_ct_request *Response =
  512. (struct lpfc_sli_ct_request *) mp->virt;
  513. struct lpfc_dmabuf *mlast, *next_mp;
  514. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  515. uint32_t Did, CTentry;
  516. int Cnt;
  517. struct list_head head;
  518. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  519. struct lpfc_nodelist *ndlp = NULL;
  520. lpfc_set_disctmo(vport);
  521. vport->num_disc_nodes = 0;
  522. vport->fc_ns_retry = 0;
  523. list_add_tail(&head, &mp->list);
  524. list_for_each_entry_safe(mp, next_mp, &head, list) {
  525. mlast = mp;
  526. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  527. Size -= Cnt;
  528. if (!ctptr) {
  529. ctptr = (uint32_t *) mlast->virt;
  530. } else
  531. Cnt -= 16; /* subtract length of CT header */
  532. /* Loop through entire NameServer list of DIDs */
  533. while (Cnt >= sizeof(uint32_t)) {
  534. /* Get next DID from NameServer List */
  535. CTentry = *ctptr++;
  536. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  537. lpfc_ns_rsp_audit_did(vport, Did, fc4_type);
  538. if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
  539. goto nsout1;
  540. Cnt -= sizeof(uint32_t);
  541. }
  542. ctptr = NULL;
  543. }
  544. /* All GID_FT entries processed. If the driver is running in
  545. * in target mode, put impacted nodes into recovery and drop
  546. * the RPI to flush outstanding IO.
  547. */
  548. if (vport->phba->nvmet_support) {
  549. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  550. if (!(ndlp->nlp_flag & NLP_NVMET_RECOV))
  551. continue;
  552. lpfc_disc_state_machine(vport, ndlp, NULL,
  553. NLP_EVT_DEVICE_RECOVERY);
  554. spin_lock_irq(shost->host_lock);
  555. ndlp->nlp_flag &= ~NLP_NVMET_RECOV;
  556. spin_unlock_irq(shost->host_lock);
  557. }
  558. }
  559. nsout1:
  560. list_del(&head);
  561. return 0;
  562. }
  563. static void
  564. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  565. struct lpfc_iocbq *rspiocb)
  566. {
  567. struct lpfc_vport *vport = cmdiocb->vport;
  568. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  569. IOCB_t *irsp;
  570. struct lpfc_dmabuf *outp;
  571. struct lpfc_dmabuf *inp;
  572. struct lpfc_sli_ct_request *CTrsp;
  573. struct lpfc_sli_ct_request *CTreq;
  574. struct lpfc_nodelist *ndlp;
  575. int rc, type;
  576. /* First save ndlp, before we overwrite it */
  577. ndlp = cmdiocb->context_un.ndlp;
  578. /* we pass cmdiocb to state machine which needs rspiocb as well */
  579. cmdiocb->context_un.rsp_iocb = rspiocb;
  580. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  581. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  582. irsp = &rspiocb->iocb;
  583. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  584. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  585. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  586. /* Don't bother processing response if vport is being torn down. */
  587. if (vport->load_flag & FC_UNLOADING) {
  588. if (vport->fc_flag & FC_RSCN_MODE)
  589. lpfc_els_flush_rscn(vport);
  590. goto out;
  591. }
  592. if (lpfc_els_chk_latt(vport)) {
  593. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  594. "0216 Link event during NS query\n");
  595. if (vport->fc_flag & FC_RSCN_MODE)
  596. lpfc_els_flush_rscn(vport);
  597. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  598. goto out;
  599. }
  600. if (lpfc_error_lost_link(irsp)) {
  601. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  602. "0226 NS query failed due to link event\n");
  603. if (vport->fc_flag & FC_RSCN_MODE)
  604. lpfc_els_flush_rscn(vport);
  605. goto out;
  606. }
  607. spin_lock_irq(shost->host_lock);
  608. if (vport->fc_flag & FC_RSCN_DEFERRED) {
  609. vport->fc_flag &= ~FC_RSCN_DEFERRED;
  610. spin_unlock_irq(shost->host_lock);
  611. /* This is a GID_FT completing so the gidft_inp counter was
  612. * incremented before the GID_FT was issued to the wire.
  613. */
  614. vport->gidft_inp--;
  615. /*
  616. * Skip processing the NS response
  617. * Re-issue the NS cmd
  618. */
  619. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  620. "0151 Process Deferred RSCN Data: x%x x%x\n",
  621. vport->fc_flag, vport->fc_rscn_id_cnt);
  622. lpfc_els_handle_rscn(vport);
  623. goto out;
  624. }
  625. spin_unlock_irq(shost->host_lock);
  626. if (irsp->ulpStatus) {
  627. /* Check for retry */
  628. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  629. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  630. (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  631. IOERR_NO_RESOURCES)
  632. vport->fc_ns_retry++;
  633. type = lpfc_get_gidft_type(vport, cmdiocb);
  634. if (type == 0)
  635. goto out;
  636. /* CT command is being retried */
  637. vport->gidft_inp--;
  638. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  639. vport->fc_ns_retry, type);
  640. if (rc == 0)
  641. goto out;
  642. }
  643. if (vport->fc_flag & FC_RSCN_MODE)
  644. lpfc_els_flush_rscn(vport);
  645. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  646. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  647. "0257 GID_FT Query error: 0x%x 0x%x\n",
  648. irsp->ulpStatus, vport->fc_ns_retry);
  649. } else {
  650. /* Good status, continue checking */
  651. CTreq = (struct lpfc_sli_ct_request *) inp->virt;
  652. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  653. if (CTrsp->CommandResponse.bits.CmdRsp ==
  654. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  655. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  656. "0208 NameServer Rsp Data: x%x x%x\n",
  657. vport->fc_flag,
  658. CTreq->un.gid.Fc4Type);
  659. lpfc_ns_rsp(vport,
  660. outp,
  661. CTreq->un.gid.Fc4Type,
  662. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  663. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  664. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  665. /* NameServer Rsp Error */
  666. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  667. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  668. lpfc_printf_vlog(vport, KERN_INFO,
  669. LOG_DISCOVERY,
  670. "0269 No NameServer Entries "
  671. "Data: x%x x%x x%x x%x\n",
  672. CTrsp->CommandResponse.bits.CmdRsp,
  673. (uint32_t) CTrsp->ReasonCode,
  674. (uint32_t) CTrsp->Explanation,
  675. vport->fc_flag);
  676. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  677. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  678. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  679. (uint32_t) CTrsp->ReasonCode,
  680. (uint32_t) CTrsp->Explanation);
  681. } else {
  682. lpfc_printf_vlog(vport, KERN_INFO,
  683. LOG_DISCOVERY,
  684. "0240 NameServer Rsp Error "
  685. "Data: x%x x%x x%x x%x\n",
  686. CTrsp->CommandResponse.bits.CmdRsp,
  687. (uint32_t) CTrsp->ReasonCode,
  688. (uint32_t) CTrsp->Explanation,
  689. vport->fc_flag);
  690. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  691. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  692. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  693. (uint32_t) CTrsp->ReasonCode,
  694. (uint32_t) CTrsp->Explanation);
  695. }
  696. } else {
  697. /* NameServer Rsp Error */
  698. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  699. "0241 NameServer Rsp Error "
  700. "Data: x%x x%x x%x x%x\n",
  701. CTrsp->CommandResponse.bits.CmdRsp,
  702. (uint32_t) CTrsp->ReasonCode,
  703. (uint32_t) CTrsp->Explanation,
  704. vport->fc_flag);
  705. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  706. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  707. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  708. (uint32_t) CTrsp->ReasonCode,
  709. (uint32_t) CTrsp->Explanation);
  710. }
  711. vport->gidft_inp--;
  712. }
  713. /* Link up / RSCN discovery */
  714. if ((vport->num_disc_nodes == 0) &&
  715. (vport->gidft_inp == 0)) {
  716. /*
  717. * The driver has cycled through all Nports in the RSCN payload.
  718. * Complete the handling by cleaning up and marking the
  719. * current driver state.
  720. */
  721. if (vport->port_state >= LPFC_DISC_AUTH) {
  722. if (vport->fc_flag & FC_RSCN_MODE) {
  723. lpfc_els_flush_rscn(vport);
  724. spin_lock_irq(shost->host_lock);
  725. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  726. spin_unlock_irq(shost->host_lock);
  727. }
  728. else
  729. lpfc_els_flush_rscn(vport);
  730. }
  731. lpfc_disc_start(vport);
  732. }
  733. out:
  734. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  735. lpfc_ct_free_iocb(phba, cmdiocb);
  736. return;
  737. }
  738. static void
  739. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  740. struct lpfc_iocbq *rspiocb)
  741. {
  742. struct lpfc_vport *vport = cmdiocb->vport;
  743. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  744. IOCB_t *irsp = &rspiocb->iocb;
  745. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  746. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  747. struct lpfc_sli_ct_request *CTrsp;
  748. int did, rc, retry;
  749. uint8_t fbits;
  750. struct lpfc_nodelist *ndlp;
  751. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  752. did = be32_to_cpu(did);
  753. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  754. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  755. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  756. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  757. /* Good status, continue checking */
  758. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  759. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  760. if (CTrsp->CommandResponse.bits.CmdRsp ==
  761. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  762. if ((fbits & FC4_FEATURE_INIT) &&
  763. !(fbits & FC4_FEATURE_TARGET)) {
  764. lpfc_printf_vlog(vport, KERN_INFO,
  765. LOG_DISCOVERY,
  766. "0270 Skip x%x GFF "
  767. "NameServer Rsp Data: (init) "
  768. "x%x x%x\n", did, fbits,
  769. vport->fc_rscn_id_cnt);
  770. goto out;
  771. }
  772. }
  773. }
  774. else {
  775. /* Check for retry */
  776. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  777. retry = 1;
  778. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  779. switch ((irsp->un.ulpWord[4] &
  780. IOERR_PARAM_MASK)) {
  781. case IOERR_NO_RESOURCES:
  782. /* We don't increment the retry
  783. * count for this case.
  784. */
  785. break;
  786. case IOERR_LINK_DOWN:
  787. case IOERR_SLI_ABORTED:
  788. case IOERR_SLI_DOWN:
  789. retry = 0;
  790. break;
  791. default:
  792. cmdiocb->retry++;
  793. }
  794. }
  795. else
  796. cmdiocb->retry++;
  797. if (retry) {
  798. /* CT command is being retried */
  799. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  800. cmdiocb->retry, did);
  801. if (rc == 0) {
  802. /* success */
  803. lpfc_ct_free_iocb(phba, cmdiocb);
  804. return;
  805. }
  806. }
  807. }
  808. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  809. "0267 NameServer GFF Rsp "
  810. "x%x Error (%d %d) Data: x%x x%x\n",
  811. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  812. vport->fc_flag, vport->fc_rscn_id_cnt);
  813. }
  814. /* This is a target port, unregistered port, or the GFF_ID failed */
  815. ndlp = lpfc_setup_disc_node(vport, did);
  816. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  817. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  818. "0242 Process x%x GFF "
  819. "NameServer Rsp Data: x%x x%x x%x\n",
  820. did, ndlp->nlp_flag, vport->fc_flag,
  821. vport->fc_rscn_id_cnt);
  822. } else {
  823. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  824. "0243 Skip x%x GFF "
  825. "NameServer Rsp Data: x%x x%x\n", did,
  826. vport->fc_flag, vport->fc_rscn_id_cnt);
  827. }
  828. out:
  829. /* Link up / RSCN discovery */
  830. if (vport->num_disc_nodes)
  831. vport->num_disc_nodes--;
  832. if (vport->num_disc_nodes == 0) {
  833. /*
  834. * The driver has cycled through all Nports in the RSCN payload.
  835. * Complete the handling by cleaning up and marking the
  836. * current driver state.
  837. */
  838. if (vport->port_state >= LPFC_DISC_AUTH) {
  839. if (vport->fc_flag & FC_RSCN_MODE) {
  840. lpfc_els_flush_rscn(vport);
  841. spin_lock_irq(shost->host_lock);
  842. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  843. spin_unlock_irq(shost->host_lock);
  844. }
  845. else
  846. lpfc_els_flush_rscn(vport);
  847. }
  848. lpfc_disc_start(vport);
  849. }
  850. lpfc_ct_free_iocb(phba, cmdiocb);
  851. return;
  852. }
  853. static void
  854. lpfc_cmpl_ct_cmd_gft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  855. struct lpfc_iocbq *rspiocb)
  856. {
  857. struct lpfc_vport *vport = cmdiocb->vport;
  858. IOCB_t *irsp = &rspiocb->iocb;
  859. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *)cmdiocb->context1;
  860. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *)cmdiocb->context2;
  861. struct lpfc_sli_ct_request *CTrsp;
  862. int did;
  863. struct lpfc_nodelist *ndlp;
  864. uint32_t fc4_data_0, fc4_data_1;
  865. did = ((struct lpfc_sli_ct_request *)inp->virt)->un.gft.PortId;
  866. did = be32_to_cpu(did);
  867. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  868. "GFT_ID cmpl: status:x%x/x%x did:x%x",
  869. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  870. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  871. /* Good status, continue checking */
  872. CTrsp = (struct lpfc_sli_ct_request *)outp->virt;
  873. fc4_data_0 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[0]);
  874. fc4_data_1 = be32_to_cpu(CTrsp->un.gft_acc.fc4_types[1]);
  875. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  876. "3062 DID x%06x GFT Wd0 x%08x Wd1 x%08x\n",
  877. did, fc4_data_0, fc4_data_1);
  878. ndlp = lpfc_findnode_did(vport, did);
  879. if (ndlp) {
  880. /* The bitmask value for FCP and NVME FCP types is
  881. * the same because they are 32 bits distant from
  882. * each other in word0 and word0.
  883. */
  884. if (fc4_data_0 & LPFC_FC4_TYPE_BITMASK)
  885. ndlp->nlp_fc4_type |= NLP_FC4_FCP;
  886. if (fc4_data_1 & LPFC_FC4_TYPE_BITMASK)
  887. ndlp->nlp_fc4_type |= NLP_FC4_NVME;
  888. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  889. "3064 Setting ndlp %p, DID x%06x with "
  890. "FC4 x%08x, Data: x%08x x%08x\n",
  891. ndlp, did, ndlp->nlp_fc4_type,
  892. FC_TYPE_FCP, FC_TYPE_NVME);
  893. ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
  894. lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
  895. lpfc_issue_els_prli(vport, ndlp, 0);
  896. }
  897. } else
  898. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  899. "3065 GFT_ID failed x%08x\n", irsp->ulpStatus);
  900. lpfc_ct_free_iocb(phba, cmdiocb);
  901. }
  902. static void
  903. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  904. struct lpfc_iocbq *rspiocb)
  905. {
  906. struct lpfc_vport *vport = cmdiocb->vport;
  907. struct lpfc_dmabuf *inp;
  908. struct lpfc_dmabuf *outp;
  909. IOCB_t *irsp;
  910. struct lpfc_sli_ct_request *CTrsp;
  911. struct lpfc_nodelist *ndlp;
  912. int cmdcode, rc;
  913. uint8_t retry;
  914. uint32_t latt;
  915. /* First save ndlp, before we overwrite it */
  916. ndlp = cmdiocb->context_un.ndlp;
  917. /* we pass cmdiocb to state machine which needs rspiocb as well */
  918. cmdiocb->context_un.rsp_iocb = rspiocb;
  919. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  920. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  921. irsp = &rspiocb->iocb;
  922. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  923. CommandResponse.bits.CmdRsp);
  924. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  925. latt = lpfc_els_chk_latt(vport);
  926. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  927. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  928. "0209 CT Request completes, latt %d, "
  929. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  930. latt, irsp->ulpStatus,
  931. CTrsp->CommandResponse.bits.CmdRsp,
  932. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  933. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  934. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  935. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  936. if (irsp->ulpStatus) {
  937. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  938. "0268 NS cmd x%x Error (x%x x%x)\n",
  939. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  940. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  941. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  942. IOERR_SLI_DOWN) ||
  943. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  944. IOERR_SLI_ABORTED)))
  945. goto out;
  946. retry = cmdiocb->retry;
  947. if (retry >= LPFC_MAX_NS_RETRY)
  948. goto out;
  949. retry++;
  950. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  951. "0250 Retrying NS cmd %x\n", cmdcode);
  952. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  953. if (rc == 0)
  954. goto out;
  955. }
  956. out:
  957. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  958. lpfc_ct_free_iocb(phba, cmdiocb);
  959. return;
  960. }
  961. static void
  962. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  963. struct lpfc_iocbq *rspiocb)
  964. {
  965. IOCB_t *irsp = &rspiocb->iocb;
  966. struct lpfc_vport *vport = cmdiocb->vport;
  967. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  968. struct lpfc_dmabuf *outp;
  969. struct lpfc_sli_ct_request *CTrsp;
  970. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  971. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  972. if (CTrsp->CommandResponse.bits.CmdRsp ==
  973. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  974. vport->ct_flags |= FC_CT_RFT_ID;
  975. }
  976. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  977. return;
  978. }
  979. static void
  980. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  981. struct lpfc_iocbq *rspiocb)
  982. {
  983. IOCB_t *irsp = &rspiocb->iocb;
  984. struct lpfc_vport *vport = cmdiocb->vport;
  985. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  986. struct lpfc_dmabuf *outp;
  987. struct lpfc_sli_ct_request *CTrsp;
  988. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  989. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  990. if (CTrsp->CommandResponse.bits.CmdRsp ==
  991. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  992. vport->ct_flags |= FC_CT_RNN_ID;
  993. }
  994. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  995. return;
  996. }
  997. static void
  998. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  999. struct lpfc_iocbq *rspiocb)
  1000. {
  1001. IOCB_t *irsp = &rspiocb->iocb;
  1002. struct lpfc_vport *vport = cmdiocb->vport;
  1003. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  1004. struct lpfc_dmabuf *outp;
  1005. struct lpfc_sli_ct_request *CTrsp;
  1006. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  1007. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1008. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1009. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1010. vport->ct_flags |= FC_CT_RSPN_ID;
  1011. }
  1012. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1013. return;
  1014. }
  1015. static void
  1016. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1017. struct lpfc_iocbq *rspiocb)
  1018. {
  1019. IOCB_t *irsp = &rspiocb->iocb;
  1020. struct lpfc_vport *vport = cmdiocb->vport;
  1021. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  1022. struct lpfc_dmabuf *outp;
  1023. struct lpfc_sli_ct_request *CTrsp;
  1024. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  1025. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1026. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1027. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1028. vport->ct_flags |= FC_CT_RSNN_NN;
  1029. }
  1030. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1031. return;
  1032. }
  1033. static void
  1034. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1035. struct lpfc_iocbq *rspiocb)
  1036. {
  1037. struct lpfc_vport *vport = cmdiocb->vport;
  1038. /* even if it fails we will act as though it succeeded. */
  1039. vport->ct_flags = 0;
  1040. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1041. return;
  1042. }
  1043. static void
  1044. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1045. struct lpfc_iocbq *rspiocb)
  1046. {
  1047. IOCB_t *irsp = &rspiocb->iocb;
  1048. struct lpfc_vport *vport = cmdiocb->vport;
  1049. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  1050. struct lpfc_dmabuf *outp;
  1051. struct lpfc_sli_ct_request *CTrsp;
  1052. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  1053. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  1054. if (CTrsp->CommandResponse.bits.CmdRsp ==
  1055. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  1056. vport->ct_flags |= FC_CT_RFF_ID;
  1057. }
  1058. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  1059. return;
  1060. }
  1061. /*
  1062. * Although the symbolic port name is thought to be an integer
  1063. * as of January 18, 2016, leave it as a string until more of
  1064. * the record state becomes defined.
  1065. */
  1066. int
  1067. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  1068. size_t size)
  1069. {
  1070. int n;
  1071. /*
  1072. * Use the lpfc board number as the Symbolic Port
  1073. * Name object. NPIV is not in play so this integer
  1074. * value is sufficient and unique per FC-ID.
  1075. */
  1076. n = scnprintf(symbol, size, "%d", vport->phba->brd_no);
  1077. return n;
  1078. }
  1079. int
  1080. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  1081. size_t size)
  1082. {
  1083. char fwrev[FW_REV_STR_SIZE];
  1084. int n;
  1085. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  1086. n = scnprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
  1087. if (size < n)
  1088. return n;
  1089. n += scnprintf(symbol + n, size - n, " FV%s", fwrev);
  1090. if (size < n)
  1091. return n;
  1092. n += scnprintf(symbol + n, size - n, " DV%s.",
  1093. lpfc_release_version);
  1094. if (size < n)
  1095. return n;
  1096. n += scnprintf(symbol + n, size - n, " HN:%s.",
  1097. init_utsname()->nodename);
  1098. if (size < n)
  1099. return n;
  1100. /* Note :- OS name is "Linux" */
  1101. n += scnprintf(symbol + n, size - n, " OS:%s\n",
  1102. init_utsname()->sysname);
  1103. return n;
  1104. }
  1105. static uint32_t
  1106. lpfc_find_map_node(struct lpfc_vport *vport)
  1107. {
  1108. struct lpfc_nodelist *ndlp, *next_ndlp;
  1109. struct Scsi_Host *shost;
  1110. uint32_t cnt = 0;
  1111. shost = lpfc_shost_from_vport(vport);
  1112. spin_lock_irq(shost->host_lock);
  1113. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1114. if (ndlp->nlp_type & NLP_FABRIC)
  1115. continue;
  1116. if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
  1117. (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
  1118. cnt++;
  1119. }
  1120. spin_unlock_irq(shost->host_lock);
  1121. return cnt;
  1122. }
  1123. /*
  1124. * This routine will return the FC4 Type associated with the CT
  1125. * GID_FT command.
  1126. */
  1127. int
  1128. lpfc_get_gidft_type(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb)
  1129. {
  1130. struct lpfc_sli_ct_request *CtReq;
  1131. struct lpfc_dmabuf *mp;
  1132. uint32_t type;
  1133. mp = cmdiocb->context1;
  1134. if (mp == NULL)
  1135. return 0;
  1136. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  1137. type = (uint32_t)CtReq->un.gid.Fc4Type;
  1138. if ((type != SLI_CTPT_FCP) && (type != SLI_CTPT_NVME))
  1139. return 0;
  1140. return type;
  1141. }
  1142. /*
  1143. * lpfc_ns_cmd
  1144. * Description:
  1145. * Issue Cmd to NameServer
  1146. * SLI_CTNS_GID_FT
  1147. * LI_CTNS_RFT_ID
  1148. */
  1149. int
  1150. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  1151. uint8_t retry, uint32_t context)
  1152. {
  1153. struct lpfc_nodelist * ndlp;
  1154. struct lpfc_hba *phba = vport->phba;
  1155. struct lpfc_dmabuf *mp, *bmp;
  1156. struct lpfc_sli_ct_request *CtReq;
  1157. struct ulp_bde64 *bpl;
  1158. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1159. struct lpfc_iocbq *) = NULL;
  1160. uint32_t rsp_size = 1024;
  1161. size_t size;
  1162. int rc = 0;
  1163. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  1164. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  1165. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  1166. rc=1;
  1167. goto ns_cmd_exit;
  1168. }
  1169. /* fill in BDEs for command */
  1170. /* Allocate buffer for command payload */
  1171. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1172. if (!mp) {
  1173. rc=2;
  1174. goto ns_cmd_exit;
  1175. }
  1176. INIT_LIST_HEAD(&mp->list);
  1177. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  1178. if (!mp->virt) {
  1179. rc=3;
  1180. goto ns_cmd_free_mp;
  1181. }
  1182. /* Allocate buffer for Buffer ptr list */
  1183. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1184. if (!bmp) {
  1185. rc=4;
  1186. goto ns_cmd_free_mpvirt;
  1187. }
  1188. INIT_LIST_HEAD(&bmp->list);
  1189. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1190. if (!bmp->virt) {
  1191. rc=5;
  1192. goto ns_cmd_free_bmp;
  1193. }
  1194. /* NameServer Req */
  1195. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1196. "0236 NameServer Req Data: x%x x%x x%x x%x\n",
  1197. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt,
  1198. context);
  1199. bpl = (struct ulp_bde64 *) bmp->virt;
  1200. memset(bpl, 0, sizeof(struct ulp_bde64));
  1201. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1202. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1203. bpl->tus.f.bdeFlags = 0;
  1204. if (cmdcode == SLI_CTNS_GID_FT)
  1205. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1206. else if (cmdcode == SLI_CTNS_GFF_ID)
  1207. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1208. else if (cmdcode == SLI_CTNS_GFT_ID)
  1209. bpl->tus.f.bdeSize = GFT_REQUEST_SZ;
  1210. else if (cmdcode == SLI_CTNS_RFT_ID)
  1211. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1212. else if (cmdcode == SLI_CTNS_RNN_ID)
  1213. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1214. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1215. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1216. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1217. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1218. else if (cmdcode == SLI_CTNS_DA_ID)
  1219. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1220. else if (cmdcode == SLI_CTNS_RFF_ID)
  1221. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1222. else
  1223. bpl->tus.f.bdeSize = 0;
  1224. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1225. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1226. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1227. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1228. CtReq->RevisionId.bits.InId = 0;
  1229. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1230. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1231. CtReq->CommandResponse.bits.Size = 0;
  1232. switch (cmdcode) {
  1233. case SLI_CTNS_GID_FT:
  1234. CtReq->CommandResponse.bits.CmdRsp =
  1235. cpu_to_be16(SLI_CTNS_GID_FT);
  1236. CtReq->un.gid.Fc4Type = context;
  1237. if (vport->port_state < LPFC_NS_QRY)
  1238. vport->port_state = LPFC_NS_QRY;
  1239. lpfc_set_disctmo(vport);
  1240. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1241. rsp_size = FC_MAX_NS_RSP;
  1242. break;
  1243. case SLI_CTNS_GFF_ID:
  1244. CtReq->CommandResponse.bits.CmdRsp =
  1245. cpu_to_be16(SLI_CTNS_GFF_ID);
  1246. CtReq->un.gff.PortId = cpu_to_be32(context);
  1247. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1248. break;
  1249. case SLI_CTNS_GFT_ID:
  1250. CtReq->CommandResponse.bits.CmdRsp =
  1251. cpu_to_be16(SLI_CTNS_GFT_ID);
  1252. CtReq->un.gft.PortId = cpu_to_be32(context);
  1253. cmpl = lpfc_cmpl_ct_cmd_gft_id;
  1254. break;
  1255. case SLI_CTNS_RFT_ID:
  1256. vport->ct_flags &= ~FC_CT_RFT_ID;
  1257. CtReq->CommandResponse.bits.CmdRsp =
  1258. cpu_to_be16(SLI_CTNS_RFT_ID);
  1259. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1260. /* Register FC4 FCP type if enabled. */
  1261. if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1262. (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
  1263. CtReq->un.rft.fcpReg = 1;
  1264. /* Register NVME type if enabled. Defined LE and swapped.
  1265. * rsvd[0] is used as word1 because of the hard-coded
  1266. * word0 usage in the ct_request data structure.
  1267. */
  1268. if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1269. (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
  1270. CtReq->un.rft.rsvd[0] = cpu_to_be32(0x00000100);
  1271. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1272. break;
  1273. case SLI_CTNS_RNN_ID:
  1274. vport->ct_flags &= ~FC_CT_RNN_ID;
  1275. CtReq->CommandResponse.bits.CmdRsp =
  1276. cpu_to_be16(SLI_CTNS_RNN_ID);
  1277. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1278. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1279. sizeof(struct lpfc_name));
  1280. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1281. break;
  1282. case SLI_CTNS_RSPN_ID:
  1283. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1284. CtReq->CommandResponse.bits.CmdRsp =
  1285. cpu_to_be16(SLI_CTNS_RSPN_ID);
  1286. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1287. size = sizeof(CtReq->un.rspn.symbname);
  1288. CtReq->un.rspn.len =
  1289. lpfc_vport_symbolic_port_name(vport,
  1290. CtReq->un.rspn.symbname, size);
  1291. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1292. break;
  1293. case SLI_CTNS_RSNN_NN:
  1294. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1295. CtReq->CommandResponse.bits.CmdRsp =
  1296. cpu_to_be16(SLI_CTNS_RSNN_NN);
  1297. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1298. sizeof(struct lpfc_name));
  1299. size = sizeof(CtReq->un.rsnn.symbname);
  1300. CtReq->un.rsnn.len =
  1301. lpfc_vport_symbolic_node_name(vport,
  1302. CtReq->un.rsnn.symbname, size);
  1303. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1304. break;
  1305. case SLI_CTNS_DA_ID:
  1306. /* Implement DA_ID Nameserver request */
  1307. CtReq->CommandResponse.bits.CmdRsp =
  1308. cpu_to_be16(SLI_CTNS_DA_ID);
  1309. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1310. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1311. break;
  1312. case SLI_CTNS_RFF_ID:
  1313. vport->ct_flags &= ~FC_CT_RFF_ID;
  1314. CtReq->CommandResponse.bits.CmdRsp =
  1315. cpu_to_be16(SLI_CTNS_RFF_ID);
  1316. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1317. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1318. /* The driver always supports FC_TYPE_FCP. However, the
  1319. * caller can specify NVME (type x28) as well. But only
  1320. * these that FC4 type is supported.
  1321. */
  1322. if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1323. (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
  1324. (context == FC_TYPE_NVME)) {
  1325. if ((vport == phba->pport) && phba->nvmet_support) {
  1326. CtReq->un.rff.fbits = (FC4_FEATURE_TARGET |
  1327. FC4_FEATURE_NVME_DISC);
  1328. lpfc_nvmet_update_targetport(phba);
  1329. } else {
  1330. lpfc_nvme_update_localport(vport);
  1331. }
  1332. CtReq->un.rff.type_code = context;
  1333. } else if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
  1334. (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) &&
  1335. (context == FC_TYPE_FCP))
  1336. CtReq->un.rff.type_code = context;
  1337. else
  1338. goto ns_cmd_free_bmpvirt;
  1339. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1340. break;
  1341. }
  1342. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1343. * to hold ndlp reference for the corresponding callback function.
  1344. */
  1345. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1346. /* On success, The cmpl function will free the buffers */
  1347. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1348. "Issue CT cmd: cmd:x%x did:x%x",
  1349. cmdcode, ndlp->nlp_DID, 0);
  1350. return 0;
  1351. }
  1352. rc=6;
  1353. /* Decrement ndlp reference count to release ndlp reference held
  1354. * for the failed command's callback function.
  1355. */
  1356. lpfc_nlp_put(ndlp);
  1357. ns_cmd_free_bmpvirt:
  1358. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1359. ns_cmd_free_bmp:
  1360. kfree(bmp);
  1361. ns_cmd_free_mpvirt:
  1362. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1363. ns_cmd_free_mp:
  1364. kfree(mp);
  1365. ns_cmd_exit:
  1366. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1367. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1368. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1369. return 1;
  1370. }
  1371. /**
  1372. * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
  1373. * @phba: Pointer to HBA context object.
  1374. * @cmdiocb: Pointer to the command IOCBQ.
  1375. * @rspiocb: Pointer to the response IOCBQ.
  1376. *
  1377. * This function to handle the completion of a driver initiated FDMI
  1378. * CT command issued during discovery.
  1379. */
  1380. static void
  1381. lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1382. struct lpfc_iocbq *rspiocb)
  1383. {
  1384. struct lpfc_vport *vport = cmdiocb->vport;
  1385. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1386. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1387. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1388. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1389. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1390. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1391. IOCB_t *irsp = &rspiocb->iocb;
  1392. struct lpfc_nodelist *ndlp;
  1393. uint32_t latt, cmd, err;
  1394. latt = lpfc_els_chk_latt(vport);
  1395. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1396. "FDMI cmpl: status:x%x/x%x latt:%d",
  1397. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1398. if (latt || irsp->ulpStatus) {
  1399. /* Look for a retryable error */
  1400. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  1401. switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
  1402. case IOERR_SLI_ABORTED:
  1403. case IOERR_ABORT_IN_PROGRESS:
  1404. case IOERR_SEQUENCE_TIMEOUT:
  1405. case IOERR_ILLEGAL_FRAME:
  1406. case IOERR_NO_RESOURCES:
  1407. case IOERR_ILLEGAL_COMMAND:
  1408. cmdiocb->retry++;
  1409. if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
  1410. break;
  1411. /* Retry the same FDMI command */
  1412. err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
  1413. cmdiocb, 0);
  1414. if (err == IOCB_ERROR)
  1415. break;
  1416. return;
  1417. default:
  1418. break;
  1419. }
  1420. }
  1421. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1422. "0229 FDMI cmd %04x failed, latt = %d "
  1423. "ulpStatus: x%x, rid x%x\n",
  1424. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1425. irsp->un.ulpWord[4]);
  1426. }
  1427. lpfc_ct_free_iocb(phba, cmdiocb);
  1428. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1429. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1430. return;
  1431. /* Check for a CT LS_RJT response */
  1432. cmd = be16_to_cpu(fdmi_cmd);
  1433. if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
  1434. /* FDMI rsp failed */
  1435. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1436. "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
  1437. /* Should we fallback to FDMI-2 / FDMI-1 ? */
  1438. switch (cmd) {
  1439. case SLI_MGMT_RHBA:
  1440. if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
  1441. /* Fallback to FDMI-1 */
  1442. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  1443. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1444. /* Start over */
  1445. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  1446. }
  1447. return;
  1448. case SLI_MGMT_RPRT:
  1449. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  1450. /* Fallback to FDMI-1 */
  1451. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1452. /* Start over */
  1453. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1454. }
  1455. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  1456. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  1457. /* Retry the same command */
  1458. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1459. }
  1460. return;
  1461. case SLI_MGMT_RPA:
  1462. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  1463. /* Fallback to FDMI-1 */
  1464. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  1465. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1466. /* Start over */
  1467. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  1468. }
  1469. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  1470. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  1471. /* Retry the same command */
  1472. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1473. }
  1474. return;
  1475. }
  1476. }
  1477. /*
  1478. * On success, need to cycle thru FDMI registration for discovery
  1479. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  1480. * DPRT -> RPRT (vports)
  1481. */
  1482. switch (cmd) {
  1483. case SLI_MGMT_RHBA:
  1484. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
  1485. break;
  1486. case SLI_MGMT_DHBA:
  1487. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  1488. break;
  1489. case SLI_MGMT_DPRT:
  1490. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1491. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
  1492. else
  1493. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  1494. break;
  1495. }
  1496. return;
  1497. }
  1498. /**
  1499. * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
  1500. * @vport: pointer to a host virtual N_Port data structure.
  1501. *
  1502. * Called from hbeat timeout routine to check if the number of discovered
  1503. * ports has changed. If so, re-register thar port Attribute.
  1504. */
  1505. void
  1506. lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
  1507. {
  1508. struct lpfc_hba *phba = vport->phba;
  1509. struct lpfc_nodelist *ndlp;
  1510. uint16_t cnt;
  1511. if (!lpfc_is_link_up(phba))
  1512. return;
  1513. /* Must be connected to a Fabric */
  1514. if (!(vport->fc_flag & FC_FABRIC))
  1515. return;
  1516. if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
  1517. return;
  1518. cnt = lpfc_find_map_node(vport);
  1519. if (cnt == vport->fdmi_num_disc)
  1520. return;
  1521. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1522. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1523. return;
  1524. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1525. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
  1526. LPFC_FDMI_PORT_ATTR_num_disc);
  1527. } else {
  1528. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
  1529. LPFC_FDMI_PORT_ATTR_num_disc);
  1530. }
  1531. }
  1532. /* Routines for all individual HBA attributes */
  1533. static int
  1534. lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
  1535. {
  1536. struct lpfc_fdmi_attr_entry *ae;
  1537. uint32_t size;
  1538. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1539. memset(ae, 0, sizeof(struct lpfc_name));
  1540. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
  1541. sizeof(struct lpfc_name));
  1542. size = FOURBYTES + sizeof(struct lpfc_name);
  1543. ad->AttrLen = cpu_to_be16(size);
  1544. ad->AttrType = cpu_to_be16(RHBA_NODENAME);
  1545. return size;
  1546. }
  1547. static int
  1548. lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
  1549. struct lpfc_fdmi_attr_def *ad)
  1550. {
  1551. struct lpfc_fdmi_attr_entry *ae;
  1552. uint32_t len, size;
  1553. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1554. memset(ae, 0, 256);
  1555. /* This string MUST be consistent with other FC platforms
  1556. * supported by Broadcom.
  1557. */
  1558. strncpy(ae->un.AttrString,
  1559. "Emulex Corporation",
  1560. sizeof(ae->un.AttrString));
  1561. len = strnlen(ae->un.AttrString,
  1562. sizeof(ae->un.AttrString));
  1563. len += (len & 3) ? (4 - (len & 3)) : 4;
  1564. size = FOURBYTES + len;
  1565. ad->AttrLen = cpu_to_be16(size);
  1566. ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
  1567. return size;
  1568. }
  1569. static int
  1570. lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
  1571. {
  1572. struct lpfc_hba *phba = vport->phba;
  1573. struct lpfc_fdmi_attr_entry *ae;
  1574. uint32_t len, size;
  1575. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1576. memset(ae, 0, 256);
  1577. strncpy(ae->un.AttrString, phba->SerialNumber,
  1578. sizeof(ae->un.AttrString));
  1579. len = strnlen(ae->un.AttrString,
  1580. sizeof(ae->un.AttrString));
  1581. len += (len & 3) ? (4 - (len & 3)) : 4;
  1582. size = FOURBYTES + len;
  1583. ad->AttrLen = cpu_to_be16(size);
  1584. ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
  1585. return size;
  1586. }
  1587. static int
  1588. lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
  1589. struct lpfc_fdmi_attr_def *ad)
  1590. {
  1591. struct lpfc_hba *phba = vport->phba;
  1592. struct lpfc_fdmi_attr_entry *ae;
  1593. uint32_t len, size;
  1594. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1595. memset(ae, 0, 256);
  1596. strncpy(ae->un.AttrString, phba->ModelName,
  1597. sizeof(ae->un.AttrString));
  1598. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  1599. len += (len & 3) ? (4 - (len & 3)) : 4;
  1600. size = FOURBYTES + len;
  1601. ad->AttrLen = cpu_to_be16(size);
  1602. ad->AttrType = cpu_to_be16(RHBA_MODEL);
  1603. return size;
  1604. }
  1605. static int
  1606. lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
  1607. struct lpfc_fdmi_attr_def *ad)
  1608. {
  1609. struct lpfc_hba *phba = vport->phba;
  1610. struct lpfc_fdmi_attr_entry *ae;
  1611. uint32_t len, size;
  1612. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1613. memset(ae, 0, 256);
  1614. strncpy(ae->un.AttrString, phba->ModelDesc,
  1615. sizeof(ae->un.AttrString));
  1616. len = strnlen(ae->un.AttrString,
  1617. sizeof(ae->un.AttrString));
  1618. len += (len & 3) ? (4 - (len & 3)) : 4;
  1619. size = FOURBYTES + len;
  1620. ad->AttrLen = cpu_to_be16(size);
  1621. ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
  1622. return size;
  1623. }
  1624. static int
  1625. lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
  1626. struct lpfc_fdmi_attr_def *ad)
  1627. {
  1628. struct lpfc_hba *phba = vport->phba;
  1629. lpfc_vpd_t *vp = &phba->vpd;
  1630. struct lpfc_fdmi_attr_entry *ae;
  1631. uint32_t i, j, incr, size;
  1632. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1633. memset(ae, 0, 256);
  1634. /* Convert JEDEC ID to ascii for hardware version */
  1635. incr = vp->rev.biuRev;
  1636. for (i = 0; i < 8; i++) {
  1637. j = (incr & 0xf);
  1638. if (j <= 9)
  1639. ae->un.AttrString[7 - i] =
  1640. (char)((uint8_t) 0x30 +
  1641. (uint8_t) j);
  1642. else
  1643. ae->un.AttrString[7 - i] =
  1644. (char)((uint8_t) 0x61 +
  1645. (uint8_t) (j - 10));
  1646. incr = (incr >> 4);
  1647. }
  1648. size = FOURBYTES + 8;
  1649. ad->AttrLen = cpu_to_be16(size);
  1650. ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
  1651. return size;
  1652. }
  1653. static int
  1654. lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
  1655. struct lpfc_fdmi_attr_def *ad)
  1656. {
  1657. struct lpfc_fdmi_attr_entry *ae;
  1658. uint32_t len, size;
  1659. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1660. memset(ae, 0, 256);
  1661. strncpy(ae->un.AttrString, lpfc_release_version,
  1662. sizeof(ae->un.AttrString));
  1663. len = strnlen(ae->un.AttrString,
  1664. sizeof(ae->un.AttrString));
  1665. len += (len & 3) ? (4 - (len & 3)) : 4;
  1666. size = FOURBYTES + len;
  1667. ad->AttrLen = cpu_to_be16(size);
  1668. ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
  1669. return size;
  1670. }
  1671. static int
  1672. lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
  1673. struct lpfc_fdmi_attr_def *ad)
  1674. {
  1675. struct lpfc_hba *phba = vport->phba;
  1676. struct lpfc_fdmi_attr_entry *ae;
  1677. uint32_t len, size;
  1678. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1679. memset(ae, 0, 256);
  1680. if (phba->sli_rev == LPFC_SLI_REV4)
  1681. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1682. else
  1683. strncpy(ae->un.AttrString, phba->OptionROMVersion,
  1684. sizeof(ae->un.AttrString));
  1685. len = strnlen(ae->un.AttrString,
  1686. sizeof(ae->un.AttrString));
  1687. len += (len & 3) ? (4 - (len & 3)) : 4;
  1688. size = FOURBYTES + len;
  1689. ad->AttrLen = cpu_to_be16(size);
  1690. ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
  1691. return size;
  1692. }
  1693. static int
  1694. lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
  1695. struct lpfc_fdmi_attr_def *ad)
  1696. {
  1697. struct lpfc_hba *phba = vport->phba;
  1698. struct lpfc_fdmi_attr_entry *ae;
  1699. uint32_t len, size;
  1700. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1701. memset(ae, 0, 256);
  1702. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1703. len = strnlen(ae->un.AttrString,
  1704. sizeof(ae->un.AttrString));
  1705. len += (len & 3) ? (4 - (len & 3)) : 4;
  1706. size = FOURBYTES + len;
  1707. ad->AttrLen = cpu_to_be16(size);
  1708. ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
  1709. return size;
  1710. }
  1711. static int
  1712. lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
  1713. struct lpfc_fdmi_attr_def *ad)
  1714. {
  1715. struct lpfc_fdmi_attr_entry *ae;
  1716. uint32_t len, size;
  1717. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1718. memset(ae, 0, 256);
  1719. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
  1720. init_utsname()->sysname,
  1721. init_utsname()->release,
  1722. init_utsname()->version);
  1723. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  1724. len += (len & 3) ? (4 - (len & 3)) : 4;
  1725. size = FOURBYTES + len;
  1726. ad->AttrLen = cpu_to_be16(size);
  1727. ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
  1728. return size;
  1729. }
  1730. static int
  1731. lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
  1732. struct lpfc_fdmi_attr_def *ad)
  1733. {
  1734. struct lpfc_fdmi_attr_entry *ae;
  1735. uint32_t size;
  1736. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1737. ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
  1738. size = FOURBYTES + sizeof(uint32_t);
  1739. ad->AttrLen = cpu_to_be16(size);
  1740. ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
  1741. return size;
  1742. }
  1743. static int
  1744. lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
  1745. struct lpfc_fdmi_attr_def *ad)
  1746. {
  1747. struct lpfc_fdmi_attr_entry *ae;
  1748. uint32_t len, size;
  1749. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1750. memset(ae, 0, 256);
  1751. len = lpfc_vport_symbolic_node_name(vport,
  1752. ae->un.AttrString, 256);
  1753. len += (len & 3) ? (4 - (len & 3)) : 4;
  1754. size = FOURBYTES + len;
  1755. ad->AttrLen = cpu_to_be16(size);
  1756. ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
  1757. return size;
  1758. }
  1759. static int
  1760. lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
  1761. struct lpfc_fdmi_attr_def *ad)
  1762. {
  1763. struct lpfc_fdmi_attr_entry *ae;
  1764. uint32_t size;
  1765. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1766. /* Nothing is defined for this currently */
  1767. ae->un.AttrInt = cpu_to_be32(0);
  1768. size = FOURBYTES + sizeof(uint32_t);
  1769. ad->AttrLen = cpu_to_be16(size);
  1770. ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
  1771. return size;
  1772. }
  1773. static int
  1774. lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
  1775. struct lpfc_fdmi_attr_def *ad)
  1776. {
  1777. struct lpfc_fdmi_attr_entry *ae;
  1778. uint32_t size;
  1779. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1780. /* Each driver instance corresponds to a single port */
  1781. ae->un.AttrInt = cpu_to_be32(1);
  1782. size = FOURBYTES + sizeof(uint32_t);
  1783. ad->AttrLen = cpu_to_be16(size);
  1784. ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
  1785. return size;
  1786. }
  1787. static int
  1788. lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
  1789. struct lpfc_fdmi_attr_def *ad)
  1790. {
  1791. struct lpfc_fdmi_attr_entry *ae;
  1792. uint32_t size;
  1793. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1794. memset(ae, 0, sizeof(struct lpfc_name));
  1795. memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
  1796. sizeof(struct lpfc_name));
  1797. size = FOURBYTES + sizeof(struct lpfc_name);
  1798. ad->AttrLen = cpu_to_be16(size);
  1799. ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
  1800. return size;
  1801. }
  1802. static int
  1803. lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
  1804. struct lpfc_fdmi_attr_def *ad)
  1805. {
  1806. struct lpfc_hba *phba = vport->phba;
  1807. struct lpfc_fdmi_attr_entry *ae;
  1808. uint32_t len, size;
  1809. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1810. memset(ae, 0, 256);
  1811. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1812. len = strnlen(ae->un.AttrString,
  1813. sizeof(ae->un.AttrString));
  1814. len += (len & 3) ? (4 - (len & 3)) : 4;
  1815. size = FOURBYTES + len;
  1816. ad->AttrLen = cpu_to_be16(size);
  1817. ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
  1818. return size;
  1819. }
  1820. static int
  1821. lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
  1822. struct lpfc_fdmi_attr_def *ad)
  1823. {
  1824. struct lpfc_fdmi_attr_entry *ae;
  1825. uint32_t size;
  1826. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1827. /* Driver doesn't have access to this information */
  1828. ae->un.AttrInt = cpu_to_be32(0);
  1829. size = FOURBYTES + sizeof(uint32_t);
  1830. ad->AttrLen = cpu_to_be16(size);
  1831. ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
  1832. return size;
  1833. }
  1834. static int
  1835. lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
  1836. struct lpfc_fdmi_attr_def *ad)
  1837. {
  1838. struct lpfc_fdmi_attr_entry *ae;
  1839. uint32_t len, size;
  1840. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1841. memset(ae, 0, 256);
  1842. strncpy(ae->un.AttrString, "EMULEX",
  1843. sizeof(ae->un.AttrString));
  1844. len = strnlen(ae->un.AttrString,
  1845. sizeof(ae->un.AttrString));
  1846. len += (len & 3) ? (4 - (len & 3)) : 4;
  1847. size = FOURBYTES + len;
  1848. ad->AttrLen = cpu_to_be16(size);
  1849. ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
  1850. return size;
  1851. }
  1852. /* Routines for all individual PORT attributes */
  1853. static int
  1854. lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
  1855. struct lpfc_fdmi_attr_def *ad)
  1856. {
  1857. struct lpfc_fdmi_attr_entry *ae;
  1858. uint32_t size;
  1859. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1860. memset(ae, 0, 32);
  1861. ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
  1862. ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
  1863. if (vport->nvmei_support || vport->phba->nvmet_support)
  1864. ae->un.AttrTypes[6] = 0x01; /* Type 0x28 - NVME */
  1865. ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
  1866. size = FOURBYTES + 32;
  1867. ad->AttrLen = cpu_to_be16(size);
  1868. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
  1869. return size;
  1870. }
  1871. static int
  1872. lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
  1873. struct lpfc_fdmi_attr_def *ad)
  1874. {
  1875. struct lpfc_hba *phba = vport->phba;
  1876. struct lpfc_fdmi_attr_entry *ae;
  1877. uint32_t size;
  1878. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1879. ae->un.AttrInt = 0;
  1880. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  1881. if (phba->lmt & LMT_64Gb)
  1882. ae->un.AttrInt |= HBA_PORTSPEED_64GFC;
  1883. if (phba->lmt & LMT_32Gb)
  1884. ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
  1885. if (phba->lmt & LMT_16Gb)
  1886. ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
  1887. if (phba->lmt & LMT_10Gb)
  1888. ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
  1889. if (phba->lmt & LMT_8Gb)
  1890. ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
  1891. if (phba->lmt & LMT_4Gb)
  1892. ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
  1893. if (phba->lmt & LMT_2Gb)
  1894. ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
  1895. if (phba->lmt & LMT_1Gb)
  1896. ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
  1897. } else {
  1898. /* FCoE links support only one speed */
  1899. switch (phba->fc_linkspeed) {
  1900. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  1901. ae->un.AttrInt = HBA_PORTSPEED_10GE;
  1902. break;
  1903. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  1904. ae->un.AttrInt = HBA_PORTSPEED_25GE;
  1905. break;
  1906. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  1907. ae->un.AttrInt = HBA_PORTSPEED_40GE;
  1908. break;
  1909. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  1910. ae->un.AttrInt = HBA_PORTSPEED_100GE;
  1911. break;
  1912. }
  1913. }
  1914. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1915. size = FOURBYTES + sizeof(uint32_t);
  1916. ad->AttrLen = cpu_to_be16(size);
  1917. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
  1918. return size;
  1919. }
  1920. static int
  1921. lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
  1922. struct lpfc_fdmi_attr_def *ad)
  1923. {
  1924. struct lpfc_hba *phba = vport->phba;
  1925. struct lpfc_fdmi_attr_entry *ae;
  1926. uint32_t size;
  1927. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1928. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  1929. switch (phba->fc_linkspeed) {
  1930. case LPFC_LINK_SPEED_1GHZ:
  1931. ae->un.AttrInt = HBA_PORTSPEED_1GFC;
  1932. break;
  1933. case LPFC_LINK_SPEED_2GHZ:
  1934. ae->un.AttrInt = HBA_PORTSPEED_2GFC;
  1935. break;
  1936. case LPFC_LINK_SPEED_4GHZ:
  1937. ae->un.AttrInt = HBA_PORTSPEED_4GFC;
  1938. break;
  1939. case LPFC_LINK_SPEED_8GHZ:
  1940. ae->un.AttrInt = HBA_PORTSPEED_8GFC;
  1941. break;
  1942. case LPFC_LINK_SPEED_10GHZ:
  1943. ae->un.AttrInt = HBA_PORTSPEED_10GFC;
  1944. break;
  1945. case LPFC_LINK_SPEED_16GHZ:
  1946. ae->un.AttrInt = HBA_PORTSPEED_16GFC;
  1947. break;
  1948. case LPFC_LINK_SPEED_32GHZ:
  1949. ae->un.AttrInt = HBA_PORTSPEED_32GFC;
  1950. break;
  1951. case LPFC_LINK_SPEED_64GHZ:
  1952. ae->un.AttrInt = HBA_PORTSPEED_64GFC;
  1953. break;
  1954. default:
  1955. ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
  1956. break;
  1957. }
  1958. } else {
  1959. switch (phba->fc_linkspeed) {
  1960. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  1961. ae->un.AttrInt = HBA_PORTSPEED_10GE;
  1962. break;
  1963. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  1964. ae->un.AttrInt = HBA_PORTSPEED_25GE;
  1965. break;
  1966. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  1967. ae->un.AttrInt = HBA_PORTSPEED_40GE;
  1968. break;
  1969. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  1970. ae->un.AttrInt = HBA_PORTSPEED_100GE;
  1971. break;
  1972. default:
  1973. ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
  1974. break;
  1975. }
  1976. }
  1977. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1978. size = FOURBYTES + sizeof(uint32_t);
  1979. ad->AttrLen = cpu_to_be16(size);
  1980. ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
  1981. return size;
  1982. }
  1983. static int
  1984. lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
  1985. struct lpfc_fdmi_attr_def *ad)
  1986. {
  1987. struct serv_parm *hsp;
  1988. struct lpfc_fdmi_attr_entry *ae;
  1989. uint32_t size;
  1990. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1991. hsp = (struct serv_parm *)&vport->fc_sparam;
  1992. ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
  1993. (uint32_t) hsp->cmn.bbRcvSizeLsb;
  1994. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1995. size = FOURBYTES + sizeof(uint32_t);
  1996. ad->AttrLen = cpu_to_be16(size);
  1997. ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
  1998. return size;
  1999. }
  2000. static int
  2001. lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
  2002. struct lpfc_fdmi_attr_def *ad)
  2003. {
  2004. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2005. struct lpfc_fdmi_attr_entry *ae;
  2006. uint32_t len, size;
  2007. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2008. memset(ae, 0, 256);
  2009. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
  2010. "/sys/class/scsi_host/host%d", shost->host_no);
  2011. len = strnlen((char *)ae->un.AttrString,
  2012. sizeof(ae->un.AttrString));
  2013. len += (len & 3) ? (4 - (len & 3)) : 4;
  2014. size = FOURBYTES + len;
  2015. ad->AttrLen = cpu_to_be16(size);
  2016. ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
  2017. return size;
  2018. }
  2019. static int
  2020. lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
  2021. struct lpfc_fdmi_attr_def *ad)
  2022. {
  2023. struct lpfc_fdmi_attr_entry *ae;
  2024. uint32_t len, size;
  2025. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2026. memset(ae, 0, 256);
  2027. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
  2028. init_utsname()->nodename);
  2029. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  2030. len += (len & 3) ? (4 - (len & 3)) : 4;
  2031. size = FOURBYTES + len;
  2032. ad->AttrLen = cpu_to_be16(size);
  2033. ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
  2034. return size;
  2035. }
  2036. static int
  2037. lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
  2038. struct lpfc_fdmi_attr_def *ad)
  2039. {
  2040. struct lpfc_fdmi_attr_entry *ae;
  2041. uint32_t size;
  2042. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2043. memset(ae, 0, sizeof(struct lpfc_name));
  2044. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
  2045. sizeof(struct lpfc_name));
  2046. size = FOURBYTES + sizeof(struct lpfc_name);
  2047. ad->AttrLen = cpu_to_be16(size);
  2048. ad->AttrType = cpu_to_be16(RPRT_NODENAME);
  2049. return size;
  2050. }
  2051. static int
  2052. lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
  2053. struct lpfc_fdmi_attr_def *ad)
  2054. {
  2055. struct lpfc_fdmi_attr_entry *ae;
  2056. uint32_t size;
  2057. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2058. memset(ae, 0, sizeof(struct lpfc_name));
  2059. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
  2060. sizeof(struct lpfc_name));
  2061. size = FOURBYTES + sizeof(struct lpfc_name);
  2062. ad->AttrLen = cpu_to_be16(size);
  2063. ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
  2064. return size;
  2065. }
  2066. static int
  2067. lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
  2068. struct lpfc_fdmi_attr_def *ad)
  2069. {
  2070. struct lpfc_fdmi_attr_entry *ae;
  2071. uint32_t len, size;
  2072. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2073. memset(ae, 0, 256);
  2074. len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
  2075. len += (len & 3) ? (4 - (len & 3)) : 4;
  2076. size = FOURBYTES + len;
  2077. ad->AttrLen = cpu_to_be16(size);
  2078. ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
  2079. return size;
  2080. }
  2081. static int
  2082. lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
  2083. struct lpfc_fdmi_attr_def *ad)
  2084. {
  2085. struct lpfc_hba *phba = vport->phba;
  2086. struct lpfc_fdmi_attr_entry *ae;
  2087. uint32_t size;
  2088. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2089. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  2090. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
  2091. else
  2092. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
  2093. size = FOURBYTES + sizeof(uint32_t);
  2094. ad->AttrLen = cpu_to_be16(size);
  2095. ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
  2096. return size;
  2097. }
  2098. static int
  2099. lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
  2100. struct lpfc_fdmi_attr_def *ad)
  2101. {
  2102. struct lpfc_fdmi_attr_entry *ae;
  2103. uint32_t size;
  2104. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2105. ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
  2106. size = FOURBYTES + sizeof(uint32_t);
  2107. ad->AttrLen = cpu_to_be16(size);
  2108. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
  2109. return size;
  2110. }
  2111. static int
  2112. lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
  2113. struct lpfc_fdmi_attr_def *ad)
  2114. {
  2115. struct lpfc_fdmi_attr_entry *ae;
  2116. uint32_t size;
  2117. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2118. memset(ae, 0, sizeof(struct lpfc_name));
  2119. memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
  2120. sizeof(struct lpfc_name));
  2121. size = FOURBYTES + sizeof(struct lpfc_name);
  2122. ad->AttrLen = cpu_to_be16(size);
  2123. ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
  2124. return size;
  2125. }
  2126. static int
  2127. lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
  2128. struct lpfc_fdmi_attr_def *ad)
  2129. {
  2130. struct lpfc_fdmi_attr_entry *ae;
  2131. uint32_t size;
  2132. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2133. memset(ae, 0, 32);
  2134. ae->un.AttrTypes[3] = 0x02; /* Type 0x1 - ELS */
  2135. ae->un.AttrTypes[2] = 0x01; /* Type 0x8 - FCP */
  2136. if (vport->phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)
  2137. ae->un.AttrTypes[6] = 0x1; /* Type 0x28 - NVME */
  2138. ae->un.AttrTypes[7] = 0x01; /* Type 0x20 - CT */
  2139. size = FOURBYTES + 32;
  2140. ad->AttrLen = cpu_to_be16(size);
  2141. ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
  2142. return size;
  2143. }
  2144. static int
  2145. lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
  2146. struct lpfc_fdmi_attr_def *ad)
  2147. {
  2148. struct lpfc_fdmi_attr_entry *ae;
  2149. uint32_t size;
  2150. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2151. /* Link Up - operational */
  2152. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
  2153. size = FOURBYTES + sizeof(uint32_t);
  2154. ad->AttrLen = cpu_to_be16(size);
  2155. ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
  2156. return size;
  2157. }
  2158. static int
  2159. lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
  2160. struct lpfc_fdmi_attr_def *ad)
  2161. {
  2162. struct lpfc_fdmi_attr_entry *ae;
  2163. uint32_t size;
  2164. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2165. vport->fdmi_num_disc = lpfc_find_map_node(vport);
  2166. ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
  2167. size = FOURBYTES + sizeof(uint32_t);
  2168. ad->AttrLen = cpu_to_be16(size);
  2169. ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
  2170. return size;
  2171. }
  2172. static int
  2173. lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
  2174. struct lpfc_fdmi_attr_def *ad)
  2175. {
  2176. struct lpfc_fdmi_attr_entry *ae;
  2177. uint32_t size;
  2178. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2179. ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
  2180. size = FOURBYTES + sizeof(uint32_t);
  2181. ad->AttrLen = cpu_to_be16(size);
  2182. ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
  2183. return size;
  2184. }
  2185. static int
  2186. lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
  2187. struct lpfc_fdmi_attr_def *ad)
  2188. {
  2189. struct lpfc_fdmi_attr_entry *ae;
  2190. uint32_t len, size;
  2191. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2192. memset(ae, 0, 256);
  2193. strncpy(ae->un.AttrString, "Smart SAN Initiator",
  2194. sizeof(ae->un.AttrString));
  2195. len = strnlen(ae->un.AttrString,
  2196. sizeof(ae->un.AttrString));
  2197. len += (len & 3) ? (4 - (len & 3)) : 4;
  2198. size = FOURBYTES + len;
  2199. ad->AttrLen = cpu_to_be16(size);
  2200. ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
  2201. return size;
  2202. }
  2203. static int
  2204. lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
  2205. struct lpfc_fdmi_attr_def *ad)
  2206. {
  2207. struct lpfc_fdmi_attr_entry *ae;
  2208. uint32_t size;
  2209. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2210. memset(ae, 0, 256);
  2211. memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
  2212. sizeof(struct lpfc_name));
  2213. memcpy((((uint8_t *)&ae->un.AttrString) +
  2214. sizeof(struct lpfc_name)),
  2215. &vport->fc_sparam.portName, sizeof(struct lpfc_name));
  2216. size = FOURBYTES + (2 * sizeof(struct lpfc_name));
  2217. ad->AttrLen = cpu_to_be16(size);
  2218. ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
  2219. return size;
  2220. }
  2221. static int
  2222. lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
  2223. struct lpfc_fdmi_attr_def *ad)
  2224. {
  2225. struct lpfc_fdmi_attr_entry *ae;
  2226. uint32_t len, size;
  2227. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2228. memset(ae, 0, 256);
  2229. strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
  2230. sizeof(ae->un.AttrString));
  2231. len = strnlen(ae->un.AttrString,
  2232. sizeof(ae->un.AttrString));
  2233. len += (len & 3) ? (4 - (len & 3)) : 4;
  2234. size = FOURBYTES + len;
  2235. ad->AttrLen = cpu_to_be16(size);
  2236. ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
  2237. return size;
  2238. }
  2239. static int
  2240. lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
  2241. struct lpfc_fdmi_attr_def *ad)
  2242. {
  2243. struct lpfc_hba *phba = vport->phba;
  2244. struct lpfc_fdmi_attr_entry *ae;
  2245. uint32_t len, size;
  2246. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2247. memset(ae, 0, 256);
  2248. strncpy(ae->un.AttrString, phba->ModelName,
  2249. sizeof(ae->un.AttrString));
  2250. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  2251. len += (len & 3) ? (4 - (len & 3)) : 4;
  2252. size = FOURBYTES + len;
  2253. ad->AttrLen = cpu_to_be16(size);
  2254. ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
  2255. return size;
  2256. }
  2257. static int
  2258. lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
  2259. struct lpfc_fdmi_attr_def *ad)
  2260. {
  2261. struct lpfc_fdmi_attr_entry *ae;
  2262. uint32_t size;
  2263. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2264. /* SRIOV (type 3) is not supported */
  2265. if (vport->vpi)
  2266. ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
  2267. else
  2268. ae->un.AttrInt = cpu_to_be32(1); /* Physical */
  2269. size = FOURBYTES + sizeof(uint32_t);
  2270. ad->AttrLen = cpu_to_be16(size);
  2271. ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
  2272. return size;
  2273. }
  2274. static int
  2275. lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
  2276. struct lpfc_fdmi_attr_def *ad)
  2277. {
  2278. struct lpfc_fdmi_attr_entry *ae;
  2279. uint32_t size;
  2280. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2281. ae->un.AttrInt = cpu_to_be32(0);
  2282. size = FOURBYTES + sizeof(uint32_t);
  2283. ad->AttrLen = cpu_to_be16(size);
  2284. ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
  2285. return size;
  2286. }
  2287. static int
  2288. lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
  2289. struct lpfc_fdmi_attr_def *ad)
  2290. {
  2291. struct lpfc_fdmi_attr_entry *ae;
  2292. uint32_t size;
  2293. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2294. ae->un.AttrInt = cpu_to_be32(1);
  2295. size = FOURBYTES + sizeof(uint32_t);
  2296. ad->AttrLen = cpu_to_be16(size);
  2297. ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
  2298. return size;
  2299. }
  2300. /* RHBA attribute jump table */
  2301. int (*lpfc_fdmi_hba_action[])
  2302. (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
  2303. /* Action routine Mask bit Attribute type */
  2304. lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
  2305. lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
  2306. lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
  2307. lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
  2308. lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
  2309. lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
  2310. lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
  2311. lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
  2312. lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
  2313. lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
  2314. lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
  2315. lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
  2316. lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
  2317. lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
  2318. lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
  2319. lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
  2320. lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
  2321. lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
  2322. };
  2323. /* RPA / RPRT attribute jump table */
  2324. int (*lpfc_fdmi_port_action[])
  2325. (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
  2326. /* Action routine Mask bit Attribute type */
  2327. lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
  2328. lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
  2329. lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
  2330. lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
  2331. lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
  2332. lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
  2333. lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
  2334. lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
  2335. lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
  2336. lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
  2337. lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
  2338. lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
  2339. lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
  2340. lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
  2341. lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
  2342. lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
  2343. lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
  2344. lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
  2345. lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
  2346. lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
  2347. lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
  2348. lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
  2349. lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
  2350. };
  2351. /**
  2352. * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
  2353. * @vport: pointer to a host virtual N_Port data structure.
  2354. * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
  2355. * cmdcode: FDMI command to send
  2356. * mask: Mask of HBA or PORT Attributes to send
  2357. *
  2358. * Builds and sends a FDMI command using the CT subsystem.
  2359. */
  2360. int
  2361. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2362. int cmdcode, uint32_t new_mask)
  2363. {
  2364. struct lpfc_hba *phba = vport->phba;
  2365. struct lpfc_dmabuf *mp, *bmp;
  2366. struct lpfc_sli_ct_request *CtReq;
  2367. struct ulp_bde64 *bpl;
  2368. uint32_t bit_pos;
  2369. uint32_t size;
  2370. uint32_t rsp_size;
  2371. uint32_t mask;
  2372. struct lpfc_fdmi_reg_hba *rh;
  2373. struct lpfc_fdmi_port_entry *pe;
  2374. struct lpfc_fdmi_reg_portattr *pab = NULL;
  2375. struct lpfc_fdmi_attr_block *ab = NULL;
  2376. int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
  2377. void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
  2378. struct lpfc_iocbq *);
  2379. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2380. return 0;
  2381. cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
  2382. /* fill in BDEs for command */
  2383. /* Allocate buffer for command payload */
  2384. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2385. if (!mp)
  2386. goto fdmi_cmd_exit;
  2387. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  2388. if (!mp->virt)
  2389. goto fdmi_cmd_free_mp;
  2390. /* Allocate buffer for Buffer ptr list */
  2391. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2392. if (!bmp)
  2393. goto fdmi_cmd_free_mpvirt;
  2394. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  2395. if (!bmp->virt)
  2396. goto fdmi_cmd_free_bmp;
  2397. INIT_LIST_HEAD(&mp->list);
  2398. INIT_LIST_HEAD(&bmp->list);
  2399. /* FDMI request */
  2400. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2401. "0218 FDMI Request Data: x%x x%x x%x\n",
  2402. vport->fc_flag, vport->port_state, cmdcode);
  2403. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  2404. /* First populate the CT_IU preamble */
  2405. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  2406. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  2407. CtReq->RevisionId.bits.InId = 0;
  2408. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  2409. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  2410. CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  2411. rsp_size = LPFC_BPL_SIZE;
  2412. size = 0;
  2413. /* Next fill in the specific FDMI cmd information */
  2414. switch (cmdcode) {
  2415. case SLI_MGMT_RHAT:
  2416. case SLI_MGMT_RHBA:
  2417. rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
  2418. /* HBA Identifier */
  2419. memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
  2420. sizeof(struct lpfc_name));
  2421. if (cmdcode == SLI_MGMT_RHBA) {
  2422. /* Registered Port List */
  2423. /* One entry (port) per adapter */
  2424. rh->rpl.EntryCnt = cpu_to_be32(1);
  2425. memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
  2426. sizeof(struct lpfc_name));
  2427. /* point to the HBA attribute block */
  2428. size = 2 * sizeof(struct lpfc_name) +
  2429. FOURBYTES;
  2430. } else {
  2431. size = sizeof(struct lpfc_name);
  2432. }
  2433. ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
  2434. ab->EntryCnt = 0;
  2435. size += FOURBYTES;
  2436. bit_pos = 0;
  2437. if (new_mask)
  2438. mask = new_mask;
  2439. else
  2440. mask = vport->fdmi_hba_mask;
  2441. /* Mask will dictate what attributes to build in the request */
  2442. while (mask) {
  2443. if (mask & 0x1) {
  2444. func = lpfc_fdmi_hba_action[bit_pos];
  2445. size += func(vport,
  2446. (struct lpfc_fdmi_attr_def *)
  2447. ((uint8_t *)rh + size));
  2448. ab->EntryCnt++;
  2449. if ((size + 256) >
  2450. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2451. goto hba_out;
  2452. }
  2453. mask = mask >> 1;
  2454. bit_pos++;
  2455. }
  2456. hba_out:
  2457. ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
  2458. /* Total size */
  2459. size = GID_REQUEST_SZ - 4 + size;
  2460. break;
  2461. case SLI_MGMT_RPRT:
  2462. case SLI_MGMT_RPA:
  2463. pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
  2464. if (cmdcode == SLI_MGMT_RPRT) {
  2465. rh = (struct lpfc_fdmi_reg_hba *)pab;
  2466. /* HBA Identifier */
  2467. memcpy(&rh->hi.PortName,
  2468. &phba->pport->fc_sparam.portName,
  2469. sizeof(struct lpfc_name));
  2470. pab = (struct lpfc_fdmi_reg_portattr *)
  2471. ((uint8_t *)pab + sizeof(struct lpfc_name));
  2472. }
  2473. memcpy((uint8_t *)&pab->PortName,
  2474. (uint8_t *)&vport->fc_sparam.portName,
  2475. sizeof(struct lpfc_name));
  2476. size += sizeof(struct lpfc_name) + FOURBYTES;
  2477. pab->ab.EntryCnt = 0;
  2478. bit_pos = 0;
  2479. if (new_mask)
  2480. mask = new_mask;
  2481. else
  2482. mask = vport->fdmi_port_mask;
  2483. /* Mask will dictate what attributes to build in the request */
  2484. while (mask) {
  2485. if (mask & 0x1) {
  2486. func = lpfc_fdmi_port_action[bit_pos];
  2487. size += func(vport,
  2488. (struct lpfc_fdmi_attr_def *)
  2489. ((uint8_t *)pab + size));
  2490. pab->ab.EntryCnt++;
  2491. if ((size + 256) >
  2492. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2493. goto port_out;
  2494. }
  2495. mask = mask >> 1;
  2496. bit_pos++;
  2497. }
  2498. port_out:
  2499. pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
  2500. /* Total size */
  2501. if (cmdcode == SLI_MGMT_RPRT)
  2502. size += sizeof(struct lpfc_name);
  2503. size = GID_REQUEST_SZ - 4 + size;
  2504. break;
  2505. case SLI_MGMT_GHAT:
  2506. case SLI_MGMT_GRPL:
  2507. rsp_size = FC_MAX_NS_RSP;
  2508. case SLI_MGMT_DHBA:
  2509. case SLI_MGMT_DHAT:
  2510. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  2511. memcpy((uint8_t *)&pe->PortName,
  2512. (uint8_t *)&vport->fc_sparam.portName,
  2513. sizeof(struct lpfc_name));
  2514. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2515. break;
  2516. case SLI_MGMT_GPAT:
  2517. case SLI_MGMT_GPAS:
  2518. rsp_size = FC_MAX_NS_RSP;
  2519. case SLI_MGMT_DPRT:
  2520. case SLI_MGMT_DPA:
  2521. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  2522. memcpy((uint8_t *)&pe->PortName,
  2523. (uint8_t *)&vport->fc_sparam.portName,
  2524. sizeof(struct lpfc_name));
  2525. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2526. break;
  2527. case SLI_MGMT_GRHL:
  2528. size = GID_REQUEST_SZ - 4;
  2529. break;
  2530. default:
  2531. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  2532. "0298 FDMI cmdcode x%x not supported\n",
  2533. cmdcode);
  2534. goto fdmi_cmd_free_bmpvirt;
  2535. }
  2536. CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  2537. bpl = (struct ulp_bde64 *)bmp->virt;
  2538. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
  2539. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
  2540. bpl->tus.f.bdeFlags = 0;
  2541. bpl->tus.f.bdeSize = size;
  2542. /*
  2543. * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  2544. * to hold ndlp reference for the corresponding callback function.
  2545. */
  2546. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
  2547. return 0;
  2548. /*
  2549. * Decrement ndlp reference count to release ndlp reference held
  2550. * for the failed command's callback function.
  2551. */
  2552. lpfc_nlp_put(ndlp);
  2553. fdmi_cmd_free_bmpvirt:
  2554. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  2555. fdmi_cmd_free_bmp:
  2556. kfree(bmp);
  2557. fdmi_cmd_free_mpvirt:
  2558. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2559. fdmi_cmd_free_mp:
  2560. kfree(mp);
  2561. fdmi_cmd_exit:
  2562. /* Issue FDMI request failed */
  2563. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2564. "0244 Issue FDMI request failed Data: x%x\n",
  2565. cmdcode);
  2566. return 1;
  2567. }
  2568. /**
  2569. * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
  2570. * @ptr - Context object of the timer.
  2571. *
  2572. * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
  2573. * the worker thread.
  2574. **/
  2575. void
  2576. lpfc_delayed_disc_tmo(struct timer_list *t)
  2577. {
  2578. struct lpfc_vport *vport = from_timer(vport, t, delayed_disc_tmo);
  2579. struct lpfc_hba *phba = vport->phba;
  2580. uint32_t tmo_posted;
  2581. unsigned long iflag;
  2582. spin_lock_irqsave(&vport->work_port_lock, iflag);
  2583. tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
  2584. if (!tmo_posted)
  2585. vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
  2586. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  2587. if (!tmo_posted)
  2588. lpfc_worker_wake_up(phba);
  2589. return;
  2590. }
  2591. /**
  2592. * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
  2593. * handle delayed discovery.
  2594. * @vport: pointer to a host virtual N_Port data structure.
  2595. *
  2596. * This function start nport discovery of the vport.
  2597. **/
  2598. void
  2599. lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
  2600. {
  2601. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2602. spin_lock_irq(shost->host_lock);
  2603. if (!(vport->fc_flag & FC_DISC_DELAYED)) {
  2604. spin_unlock_irq(shost->host_lock);
  2605. return;
  2606. }
  2607. vport->fc_flag &= ~FC_DISC_DELAYED;
  2608. spin_unlock_irq(shost->host_lock);
  2609. lpfc_do_scr_ns_plogi(vport->phba, vport);
  2610. }
  2611. void
  2612. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  2613. {
  2614. struct lpfc_sli *psli = &phba->sli;
  2615. lpfc_vpd_t *vp = &phba->vpd;
  2616. uint32_t b1, b2, b3, b4, i, rev;
  2617. char c;
  2618. uint32_t *ptr, str[4];
  2619. uint8_t *fwname;
  2620. if (phba->sli_rev == LPFC_SLI_REV4)
  2621. snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
  2622. else if (vp->rev.rBit) {
  2623. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  2624. rev = vp->rev.sli2FwRev;
  2625. else
  2626. rev = vp->rev.sli1FwRev;
  2627. b1 = (rev & 0x0000f000) >> 12;
  2628. b2 = (rev & 0x00000f00) >> 8;
  2629. b3 = (rev & 0x000000c0) >> 6;
  2630. b4 = (rev & 0x00000030) >> 4;
  2631. switch (b4) {
  2632. case 0:
  2633. c = 'N';
  2634. break;
  2635. case 1:
  2636. c = 'A';
  2637. break;
  2638. case 2:
  2639. c = 'B';
  2640. break;
  2641. case 3:
  2642. c = 'X';
  2643. break;
  2644. default:
  2645. c = 0;
  2646. break;
  2647. }
  2648. b4 = (rev & 0x0000000f);
  2649. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  2650. fwname = vp->rev.sli2FwName;
  2651. else
  2652. fwname = vp->rev.sli1FwName;
  2653. for (i = 0; i < 16; i++)
  2654. if (fwname[i] == 0x20)
  2655. fwname[i] = 0;
  2656. ptr = (uint32_t*)fwname;
  2657. for (i = 0; i < 3; i++)
  2658. str[i] = be32_to_cpu(*ptr++);
  2659. if (c == 0) {
  2660. if (flag)
  2661. sprintf(fwrevision, "%d.%d%d (%s)",
  2662. b1, b2, b3, (char *)str);
  2663. else
  2664. sprintf(fwrevision, "%d.%d%d", b1,
  2665. b2, b3);
  2666. } else {
  2667. if (flag)
  2668. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  2669. b1, b2, b3, c,
  2670. b4, (char *)str);
  2671. else
  2672. sprintf(fwrevision, "%d.%d%d%c%d",
  2673. b1, b2, b3, c, b4);
  2674. }
  2675. } else {
  2676. rev = vp->rev.smFwRev;
  2677. b1 = (rev & 0xff000000) >> 24;
  2678. b2 = (rev & 0x00f00000) >> 20;
  2679. b3 = (rev & 0x000f0000) >> 16;
  2680. c = (rev & 0x0000ff00) >> 8;
  2681. b4 = (rev & 0x000000ff);
  2682. sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
  2683. }
  2684. return;
  2685. }