lpfc_ct.c 78 KB

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