lpfc_ct.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2015 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 */
  47. #define HBA_PORTSPEED_1GBIT 0x0001 /* 1 GBit/sec */
  48. #define HBA_PORTSPEED_2GBIT 0x0002 /* 2 GBit/sec */
  49. #define HBA_PORTSPEED_4GBIT 0x0008 /* 4 GBit/sec */
  50. #define HBA_PORTSPEED_10GBIT 0x0004 /* 10 GBit/sec */
  51. #define HBA_PORTSPEED_8GBIT 0x0010 /* 8 GBit/sec */
  52. #define HBA_PORTSPEED_16GBIT 0x0020 /* 16 GBit/sec */
  53. #define HBA_PORTSPEED_UNKNOWN 0x0800 /* Unknown */
  54. #define FOURBYTES 4
  55. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  56. static void
  57. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  58. struct lpfc_dmabuf *mp, uint32_t size)
  59. {
  60. if (!mp) {
  61. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  62. "0146 Ignoring unsolicited CT No HBQ "
  63. "status = x%x\n",
  64. piocbq->iocb.ulpStatus);
  65. }
  66. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  67. "0145 Ignoring unsolicted CT HBQ Size:%d "
  68. "status = x%x\n",
  69. size, piocbq->iocb.ulpStatus);
  70. }
  71. static void
  72. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  73. struct lpfc_dmabuf *mp, uint32_t size)
  74. {
  75. lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
  76. }
  77. void
  78. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  79. struct lpfc_iocbq *piocbq)
  80. {
  81. struct lpfc_dmabuf *mp = NULL;
  82. IOCB_t *icmd = &piocbq->iocb;
  83. int i;
  84. struct lpfc_iocbq *iocbq;
  85. dma_addr_t paddr;
  86. uint32_t size;
  87. struct list_head head;
  88. struct lpfc_dmabuf *bdeBuf;
  89. if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
  90. return;
  91. if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
  92. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  93. } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  94. ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  95. IOERR_RCV_BUFFER_WAITING)) {
  96. /* Not enough posted buffers; Try posting more buffers */
  97. phba->fc_stat.NoRcvBuf++;
  98. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  99. lpfc_post_buffer(phba, pring, 2);
  100. return;
  101. }
  102. /* If there are no BDEs associated with this IOCB,
  103. * there is nothing to do.
  104. */
  105. if (icmd->ulpBdeCount == 0)
  106. return;
  107. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  108. INIT_LIST_HEAD(&head);
  109. list_add_tail(&head, &piocbq->list);
  110. list_for_each_entry(iocbq, &head, list) {
  111. icmd = &iocbq->iocb;
  112. if (icmd->ulpBdeCount == 0)
  113. continue;
  114. bdeBuf = iocbq->context2;
  115. iocbq->context2 = NULL;
  116. size = icmd->un.cont64[0].tus.f.bdeSize;
  117. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
  118. lpfc_in_buf_free(phba, bdeBuf);
  119. if (icmd->ulpBdeCount == 2) {
  120. bdeBuf = iocbq->context3;
  121. iocbq->context3 = NULL;
  122. size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
  123. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
  124. size);
  125. lpfc_in_buf_free(phba, bdeBuf);
  126. }
  127. }
  128. list_del(&head);
  129. } else {
  130. INIT_LIST_HEAD(&head);
  131. list_add_tail(&head, &piocbq->list);
  132. list_for_each_entry(iocbq, &head, list) {
  133. icmd = &iocbq->iocb;
  134. if (icmd->ulpBdeCount == 0)
  135. lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
  136. for (i = 0; i < icmd->ulpBdeCount; i++) {
  137. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  138. icmd->un.cont64[i].addrLow);
  139. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  140. paddr);
  141. size = icmd->un.cont64[i].tus.f.bdeSize;
  142. lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
  143. lpfc_in_buf_free(phba, mp);
  144. }
  145. lpfc_post_buffer(phba, pring, i);
  146. }
  147. list_del(&head);
  148. }
  149. }
  150. /**
  151. * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
  152. * @phba: Pointer to HBA context object.
  153. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  154. *
  155. * This function serves as the upper level protocol abort handler for CT
  156. * protocol.
  157. *
  158. * Return 1 if abort has been handled, 0 otherwise.
  159. **/
  160. int
  161. lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
  162. {
  163. int handled;
  164. /* CT upper level goes through BSG */
  165. handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
  166. return handled;
  167. }
  168. static void
  169. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  170. {
  171. struct lpfc_dmabuf *mlast, *next_mlast;
  172. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  173. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  174. list_del(&mlast->list);
  175. kfree(mlast);
  176. }
  177. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  178. kfree(mlist);
  179. return;
  180. }
  181. static struct lpfc_dmabuf *
  182. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  183. uint32_t size, int *entries)
  184. {
  185. struct lpfc_dmabuf *mlist = NULL;
  186. struct lpfc_dmabuf *mp;
  187. int cnt, i = 0;
  188. /* We get chunks of FCELSSIZE */
  189. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  190. while (size) {
  191. /* Allocate buffer for rsp payload */
  192. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  193. if (!mp) {
  194. if (mlist)
  195. lpfc_free_ct_rsp(phba, mlist);
  196. return NULL;
  197. }
  198. INIT_LIST_HEAD(&mp->list);
  199. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  200. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  201. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  202. else
  203. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  204. if (!mp->virt) {
  205. kfree(mp);
  206. if (mlist)
  207. lpfc_free_ct_rsp(phba, mlist);
  208. return NULL;
  209. }
  210. /* Queue it to a linked list */
  211. if (!mlist)
  212. mlist = mp;
  213. else
  214. list_add_tail(&mp->list, &mlist->list);
  215. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  216. /* build buffer ptr list for IOCB */
  217. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  218. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  219. bpl->tus.f.bdeSize = (uint16_t) cnt;
  220. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  221. bpl++;
  222. i++;
  223. size -= cnt;
  224. }
  225. *entries = i;
  226. return mlist;
  227. }
  228. int
  229. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  230. {
  231. struct lpfc_dmabuf *buf_ptr;
  232. if (ctiocb->context_un.ndlp) {
  233. lpfc_nlp_put(ctiocb->context_un.ndlp);
  234. ctiocb->context_un.ndlp = NULL;
  235. }
  236. if (ctiocb->context1) {
  237. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
  238. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  239. kfree(buf_ptr);
  240. ctiocb->context1 = NULL;
  241. }
  242. if (ctiocb->context2) {
  243. lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
  244. ctiocb->context2 = NULL;
  245. }
  246. if (ctiocb->context3) {
  247. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
  248. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  249. kfree(buf_ptr);
  250. ctiocb->context3 = NULL;
  251. }
  252. lpfc_sli_release_iocbq(phba, ctiocb);
  253. return 0;
  254. }
  255. static int
  256. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  257. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  258. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  259. struct lpfc_iocbq *),
  260. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  261. uint32_t tmo, uint8_t retry)
  262. {
  263. struct lpfc_hba *phba = vport->phba;
  264. IOCB_t *icmd;
  265. struct lpfc_iocbq *geniocb;
  266. int rc;
  267. /* Allocate buffer for command iocb */
  268. geniocb = lpfc_sli_get_iocbq(phba);
  269. if (geniocb == NULL)
  270. return 1;
  271. icmd = &geniocb->iocb;
  272. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  273. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  274. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  275. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  276. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
  277. if (usr_flg)
  278. geniocb->context3 = NULL;
  279. else
  280. geniocb->context3 = (uint8_t *) bmp;
  281. /* Save for completion so we can release these resources */
  282. geniocb->context1 = (uint8_t *) inp;
  283. geniocb->context2 = (uint8_t *) outp;
  284. geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
  285. /* Fill in payload, bp points to frame payload */
  286. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  287. /* Fill in rest of iocb */
  288. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  289. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  290. icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
  291. icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
  292. if (!tmo) {
  293. /* FC spec states we need 3 * ratov for CT requests */
  294. tmo = (3 * phba->fc_ratov);
  295. }
  296. icmd->ulpTimeout = tmo;
  297. icmd->ulpBdeCount = 1;
  298. icmd->ulpLe = 1;
  299. icmd->ulpClass = CLASS3;
  300. icmd->ulpContext = ndlp->nlp_rpi;
  301. if (phba->sli_rev == LPFC_SLI_REV4)
  302. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  303. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  304. /* For GEN_REQUEST64_CR, use the RPI */
  305. icmd->ulpCt_h = 0;
  306. icmd->ulpCt_l = 0;
  307. }
  308. /* Issue GEN REQ IOCB for NPORT <did> */
  309. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  310. "0119 Issue GEN REQ IOCB to NPORT x%x "
  311. "Data: x%x x%x\n",
  312. ndlp->nlp_DID, icmd->ulpIoTag,
  313. vport->port_state);
  314. geniocb->iocb_cmpl = cmpl;
  315. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  316. geniocb->vport = vport;
  317. geniocb->retry = retry;
  318. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  319. if (rc == IOCB_ERROR) {
  320. lpfc_sli_release_iocbq(phba, geniocb);
  321. return 1;
  322. }
  323. return 0;
  324. }
  325. static int
  326. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  327. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  328. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  329. struct lpfc_iocbq *),
  330. uint32_t rsp_size, uint8_t retry)
  331. {
  332. struct lpfc_hba *phba = vport->phba;
  333. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  334. struct lpfc_dmabuf *outmp;
  335. int cnt = 0, status;
  336. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  337. CommandResponse.bits.CmdRsp;
  338. bpl++; /* Skip past ct request */
  339. /* Put buffer(s) for ct rsp in bpl */
  340. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  341. if (!outmp)
  342. return -ENOMEM;
  343. /*
  344. * Form the CT IOCB. The total number of BDEs in this IOCB
  345. * is the single command plus response count from
  346. * lpfc_alloc_ct_rsp.
  347. */
  348. cnt += 1;
  349. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  350. cnt, 0, retry);
  351. if (status) {
  352. lpfc_free_ct_rsp(phba, outmp);
  353. return -ENOMEM;
  354. }
  355. return 0;
  356. }
  357. struct lpfc_vport *
  358. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  359. struct lpfc_vport *vport_curr;
  360. unsigned long flags;
  361. spin_lock_irqsave(&phba->hbalock, flags);
  362. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  363. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  364. spin_unlock_irqrestore(&phba->hbalock, flags);
  365. return vport_curr;
  366. }
  367. }
  368. spin_unlock_irqrestore(&phba->hbalock, flags);
  369. return NULL;
  370. }
  371. static int
  372. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  373. {
  374. struct lpfc_hba *phba = vport->phba;
  375. struct lpfc_sli_ct_request *Response =
  376. (struct lpfc_sli_ct_request *) mp->virt;
  377. struct lpfc_nodelist *ndlp = NULL;
  378. struct lpfc_dmabuf *mlast, *next_mp;
  379. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  380. uint32_t Did, CTentry;
  381. int Cnt;
  382. struct list_head head;
  383. lpfc_set_disctmo(vport);
  384. vport->num_disc_nodes = 0;
  385. vport->fc_ns_retry = 0;
  386. list_add_tail(&head, &mp->list);
  387. list_for_each_entry_safe(mp, next_mp, &head, list) {
  388. mlast = mp;
  389. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  390. Size -= Cnt;
  391. if (!ctptr) {
  392. ctptr = (uint32_t *) mlast->virt;
  393. } else
  394. Cnt -= 16; /* subtract length of CT header */
  395. /* Loop through entire NameServer list of DIDs */
  396. while (Cnt >= sizeof (uint32_t)) {
  397. /* Get next DID from NameServer List */
  398. CTentry = *ctptr++;
  399. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  400. ndlp = NULL;
  401. /*
  402. * Check for rscn processing or not
  403. * To conserve rpi's, filter out addresses for other
  404. * vports on the same physical HBAs.
  405. */
  406. if ((Did != vport->fc_myDID) &&
  407. ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
  408. vport->cfg_peer_port_login)) {
  409. if ((vport->port_type != LPFC_NPIV_PORT) ||
  410. (!(vport->ct_flags & FC_CT_RFF_ID)) ||
  411. (!vport->cfg_restrict_login)) {
  412. ndlp = lpfc_setup_disc_node(vport, Did);
  413. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  414. lpfc_debugfs_disc_trc(vport,
  415. LPFC_DISC_TRC_CT,
  416. "Parse GID_FTrsp: "
  417. "did:x%x flg:x%x x%x",
  418. Did, ndlp->nlp_flag,
  419. vport->fc_flag);
  420. lpfc_printf_vlog(vport,
  421. KERN_INFO,
  422. LOG_DISCOVERY,
  423. "0238 Process "
  424. "x%x NameServer Rsp"
  425. "Data: x%x x%x x%x\n",
  426. Did, ndlp->nlp_flag,
  427. vport->fc_flag,
  428. vport->fc_rscn_id_cnt);
  429. } else {
  430. lpfc_debugfs_disc_trc(vport,
  431. LPFC_DISC_TRC_CT,
  432. "Skip1 GID_FTrsp: "
  433. "did:x%x flg:x%x cnt:%d",
  434. Did, vport->fc_flag,
  435. vport->fc_rscn_id_cnt);
  436. lpfc_printf_vlog(vport,
  437. KERN_INFO,
  438. LOG_DISCOVERY,
  439. "0239 Skip x%x "
  440. "NameServer Rsp Data: "
  441. "x%x x%x\n",
  442. Did, vport->fc_flag,
  443. vport->fc_rscn_id_cnt);
  444. }
  445. } else {
  446. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  447. (lpfc_rscn_payload_check(vport, Did))) {
  448. lpfc_debugfs_disc_trc(vport,
  449. LPFC_DISC_TRC_CT,
  450. "Query GID_FTrsp: "
  451. "did:x%x flg:x%x cnt:%d",
  452. Did, vport->fc_flag,
  453. vport->fc_rscn_id_cnt);
  454. /* This NPortID was previously
  455. * a FCP target, * Don't even
  456. * bother to send GFF_ID.
  457. */
  458. ndlp = lpfc_findnode_did(vport,
  459. Did);
  460. if (ndlp &&
  461. NLP_CHK_NODE_ACT(ndlp)
  462. && (ndlp->nlp_type &
  463. NLP_FCP_TARGET))
  464. lpfc_setup_disc_node
  465. (vport, Did);
  466. else if (lpfc_ns_cmd(vport,
  467. SLI_CTNS_GFF_ID,
  468. 0, Did) == 0)
  469. vport->num_disc_nodes++;
  470. else
  471. lpfc_setup_disc_node
  472. (vport, Did);
  473. }
  474. else {
  475. lpfc_debugfs_disc_trc(vport,
  476. LPFC_DISC_TRC_CT,
  477. "Skip2 GID_FTrsp: "
  478. "did:x%x flg:x%x cnt:%d",
  479. Did, vport->fc_flag,
  480. vport->fc_rscn_id_cnt);
  481. lpfc_printf_vlog(vport,
  482. KERN_INFO,
  483. LOG_DISCOVERY,
  484. "0245 Skip x%x "
  485. "NameServer Rsp Data: "
  486. "x%x x%x\n",
  487. Did, vport->fc_flag,
  488. vport->fc_rscn_id_cnt);
  489. }
  490. }
  491. }
  492. if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
  493. goto nsout1;
  494. Cnt -= sizeof (uint32_t);
  495. }
  496. ctptr = NULL;
  497. }
  498. nsout1:
  499. list_del(&head);
  500. return 0;
  501. }
  502. static void
  503. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  504. struct lpfc_iocbq *rspiocb)
  505. {
  506. struct lpfc_vport *vport = cmdiocb->vport;
  507. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  508. IOCB_t *irsp;
  509. struct lpfc_dmabuf *bmp;
  510. struct lpfc_dmabuf *outp;
  511. struct lpfc_sli_ct_request *CTrsp;
  512. struct lpfc_nodelist *ndlp;
  513. int rc;
  514. /* First save ndlp, before we overwrite it */
  515. ndlp = cmdiocb->context_un.ndlp;
  516. /* we pass cmdiocb to state machine which needs rspiocb as well */
  517. cmdiocb->context_un.rsp_iocb = rspiocb;
  518. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  519. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  520. irsp = &rspiocb->iocb;
  521. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  522. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  523. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  524. /* Don't bother processing response if vport is being torn down. */
  525. if (vport->load_flag & FC_UNLOADING) {
  526. if (vport->fc_flag & FC_RSCN_MODE)
  527. lpfc_els_flush_rscn(vport);
  528. goto out;
  529. }
  530. if (lpfc_els_chk_latt(vport)) {
  531. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  532. "0216 Link event during NS query\n");
  533. if (vport->fc_flag & FC_RSCN_MODE)
  534. lpfc_els_flush_rscn(vport);
  535. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  536. goto out;
  537. }
  538. if (lpfc_error_lost_link(irsp)) {
  539. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  540. "0226 NS query failed due to link event\n");
  541. if (vport->fc_flag & FC_RSCN_MODE)
  542. lpfc_els_flush_rscn(vport);
  543. goto out;
  544. }
  545. if (irsp->ulpStatus) {
  546. /* Check for retry */
  547. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  548. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  549. (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  550. IOERR_NO_RESOURCES)
  551. vport->fc_ns_retry++;
  552. /* CT command is being retried */
  553. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  554. vport->fc_ns_retry, 0);
  555. if (rc == 0)
  556. goto out;
  557. }
  558. if (vport->fc_flag & FC_RSCN_MODE)
  559. lpfc_els_flush_rscn(vport);
  560. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  561. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  562. "0257 GID_FT Query error: 0x%x 0x%x\n",
  563. irsp->ulpStatus, vport->fc_ns_retry);
  564. } else {
  565. /* Good status, continue checking */
  566. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  567. if (CTrsp->CommandResponse.bits.CmdRsp ==
  568. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  569. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  570. "0208 NameServer Rsp Data: x%x\n",
  571. vport->fc_flag);
  572. lpfc_ns_rsp(vport, outp,
  573. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  574. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  575. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  576. /* NameServer Rsp Error */
  577. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  578. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  579. lpfc_printf_vlog(vport, KERN_INFO,
  580. LOG_DISCOVERY,
  581. "0269 No NameServer Entries "
  582. "Data: x%x x%x x%x x%x\n",
  583. CTrsp->CommandResponse.bits.CmdRsp,
  584. (uint32_t) CTrsp->ReasonCode,
  585. (uint32_t) CTrsp->Explanation,
  586. vport->fc_flag);
  587. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  588. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  589. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  590. (uint32_t) CTrsp->ReasonCode,
  591. (uint32_t) CTrsp->Explanation);
  592. } else {
  593. lpfc_printf_vlog(vport, KERN_INFO,
  594. LOG_DISCOVERY,
  595. "0240 NameServer Rsp Error "
  596. "Data: x%x x%x x%x x%x\n",
  597. CTrsp->CommandResponse.bits.CmdRsp,
  598. (uint32_t) CTrsp->ReasonCode,
  599. (uint32_t) CTrsp->Explanation,
  600. vport->fc_flag);
  601. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  602. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  603. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  604. (uint32_t) CTrsp->ReasonCode,
  605. (uint32_t) CTrsp->Explanation);
  606. }
  607. } else {
  608. /* NameServer Rsp Error */
  609. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  610. "0241 NameServer Rsp Error "
  611. "Data: x%x x%x x%x x%x\n",
  612. CTrsp->CommandResponse.bits.CmdRsp,
  613. (uint32_t) CTrsp->ReasonCode,
  614. (uint32_t) CTrsp->Explanation,
  615. vport->fc_flag);
  616. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  617. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  618. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  619. (uint32_t) CTrsp->ReasonCode,
  620. (uint32_t) CTrsp->Explanation);
  621. }
  622. }
  623. /* Link up / RSCN discovery */
  624. if (vport->num_disc_nodes == 0) {
  625. /*
  626. * The driver has cycled through all Nports in the RSCN payload.
  627. * Complete the handling by cleaning up and marking the
  628. * current driver state.
  629. */
  630. if (vport->port_state >= LPFC_DISC_AUTH) {
  631. if (vport->fc_flag & FC_RSCN_MODE) {
  632. lpfc_els_flush_rscn(vport);
  633. spin_lock_irq(shost->host_lock);
  634. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  635. spin_unlock_irq(shost->host_lock);
  636. }
  637. else
  638. lpfc_els_flush_rscn(vport);
  639. }
  640. lpfc_disc_start(vport);
  641. }
  642. out:
  643. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  644. lpfc_ct_free_iocb(phba, cmdiocb);
  645. return;
  646. }
  647. static void
  648. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  649. struct lpfc_iocbq *rspiocb)
  650. {
  651. struct lpfc_vport *vport = cmdiocb->vport;
  652. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  653. IOCB_t *irsp = &rspiocb->iocb;
  654. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  655. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  656. struct lpfc_sli_ct_request *CTrsp;
  657. int did, rc, retry;
  658. uint8_t fbits;
  659. struct lpfc_nodelist *ndlp;
  660. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  661. did = be32_to_cpu(did);
  662. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  663. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  664. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  665. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  666. /* Good status, continue checking */
  667. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  668. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  669. if (CTrsp->CommandResponse.bits.CmdRsp ==
  670. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  671. if ((fbits & FC4_FEATURE_INIT) &&
  672. !(fbits & FC4_FEATURE_TARGET)) {
  673. lpfc_printf_vlog(vport, KERN_INFO,
  674. LOG_DISCOVERY,
  675. "0270 Skip x%x GFF "
  676. "NameServer Rsp Data: (init) "
  677. "x%x x%x\n", did, fbits,
  678. vport->fc_rscn_id_cnt);
  679. goto out;
  680. }
  681. }
  682. }
  683. else {
  684. /* Check for retry */
  685. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  686. retry = 1;
  687. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  688. switch ((irsp->un.ulpWord[4] &
  689. IOERR_PARAM_MASK)) {
  690. case IOERR_NO_RESOURCES:
  691. /* We don't increment the retry
  692. * count for this case.
  693. */
  694. break;
  695. case IOERR_LINK_DOWN:
  696. case IOERR_SLI_ABORTED:
  697. case IOERR_SLI_DOWN:
  698. retry = 0;
  699. break;
  700. default:
  701. cmdiocb->retry++;
  702. }
  703. }
  704. else
  705. cmdiocb->retry++;
  706. if (retry) {
  707. /* CT command is being retried */
  708. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  709. cmdiocb->retry, did);
  710. if (rc == 0) {
  711. /* success */
  712. lpfc_ct_free_iocb(phba, cmdiocb);
  713. return;
  714. }
  715. }
  716. }
  717. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  718. "0267 NameServer GFF Rsp "
  719. "x%x Error (%d %d) Data: x%x x%x\n",
  720. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  721. vport->fc_flag, vport->fc_rscn_id_cnt);
  722. }
  723. /* This is a target port, unregistered port, or the GFF_ID failed */
  724. ndlp = lpfc_setup_disc_node(vport, did);
  725. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  726. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  727. "0242 Process x%x GFF "
  728. "NameServer Rsp Data: x%x x%x x%x\n",
  729. did, ndlp->nlp_flag, vport->fc_flag,
  730. vport->fc_rscn_id_cnt);
  731. } else {
  732. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  733. "0243 Skip x%x GFF "
  734. "NameServer Rsp Data: x%x x%x\n", did,
  735. vport->fc_flag, vport->fc_rscn_id_cnt);
  736. }
  737. out:
  738. /* Link up / RSCN discovery */
  739. if (vport->num_disc_nodes)
  740. vport->num_disc_nodes--;
  741. if (vport->num_disc_nodes == 0) {
  742. /*
  743. * The driver has cycled through all Nports in the RSCN payload.
  744. * Complete the handling by cleaning up and marking the
  745. * current driver state.
  746. */
  747. if (vport->port_state >= LPFC_DISC_AUTH) {
  748. if (vport->fc_flag & FC_RSCN_MODE) {
  749. lpfc_els_flush_rscn(vport);
  750. spin_lock_irq(shost->host_lock);
  751. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  752. spin_unlock_irq(shost->host_lock);
  753. }
  754. else
  755. lpfc_els_flush_rscn(vport);
  756. }
  757. lpfc_disc_start(vport);
  758. }
  759. lpfc_ct_free_iocb(phba, cmdiocb);
  760. return;
  761. }
  762. static void
  763. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  764. struct lpfc_iocbq *rspiocb)
  765. {
  766. struct lpfc_vport *vport = cmdiocb->vport;
  767. struct lpfc_dmabuf *inp;
  768. struct lpfc_dmabuf *outp;
  769. IOCB_t *irsp;
  770. struct lpfc_sli_ct_request *CTrsp;
  771. struct lpfc_nodelist *ndlp;
  772. int cmdcode, rc;
  773. uint8_t retry;
  774. uint32_t latt;
  775. /* First save ndlp, before we overwrite it */
  776. ndlp = cmdiocb->context_un.ndlp;
  777. /* we pass cmdiocb to state machine which needs rspiocb as well */
  778. cmdiocb->context_un.rsp_iocb = rspiocb;
  779. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  780. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  781. irsp = &rspiocb->iocb;
  782. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  783. CommandResponse.bits.CmdRsp);
  784. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  785. latt = lpfc_els_chk_latt(vport);
  786. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  787. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  788. "0209 CT Request completes, latt %d, "
  789. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  790. latt, irsp->ulpStatus,
  791. CTrsp->CommandResponse.bits.CmdRsp,
  792. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  793. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  794. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  795. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  796. if (irsp->ulpStatus) {
  797. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  798. "0268 NS cmd x%x Error (x%x x%x)\n",
  799. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  800. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  801. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  802. IOERR_SLI_DOWN) ||
  803. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  804. IOERR_SLI_ABORTED)))
  805. goto out;
  806. retry = cmdiocb->retry;
  807. if (retry >= LPFC_MAX_NS_RETRY)
  808. goto out;
  809. retry++;
  810. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  811. "0250 Retrying NS cmd %x\n", cmdcode);
  812. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  813. if (rc == 0)
  814. goto out;
  815. }
  816. out:
  817. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  818. lpfc_ct_free_iocb(phba, cmdiocb);
  819. return;
  820. }
  821. static void
  822. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  823. struct lpfc_iocbq *rspiocb)
  824. {
  825. IOCB_t *irsp = &rspiocb->iocb;
  826. struct lpfc_vport *vport = cmdiocb->vport;
  827. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  828. struct lpfc_dmabuf *outp;
  829. struct lpfc_sli_ct_request *CTrsp;
  830. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  831. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  832. if (CTrsp->CommandResponse.bits.CmdRsp ==
  833. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  834. vport->ct_flags |= FC_CT_RFT_ID;
  835. }
  836. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  837. return;
  838. }
  839. static void
  840. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  841. struct lpfc_iocbq *rspiocb)
  842. {
  843. IOCB_t *irsp = &rspiocb->iocb;
  844. struct lpfc_vport *vport = cmdiocb->vport;
  845. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  846. struct lpfc_dmabuf *outp;
  847. struct lpfc_sli_ct_request *CTrsp;
  848. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  849. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  850. if (CTrsp->CommandResponse.bits.CmdRsp ==
  851. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  852. vport->ct_flags |= FC_CT_RNN_ID;
  853. }
  854. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  855. return;
  856. }
  857. static void
  858. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  859. struct lpfc_iocbq *rspiocb)
  860. {
  861. IOCB_t *irsp = &rspiocb->iocb;
  862. struct lpfc_vport *vport = cmdiocb->vport;
  863. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  864. struct lpfc_dmabuf *outp;
  865. struct lpfc_sli_ct_request *CTrsp;
  866. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  867. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  868. if (CTrsp->CommandResponse.bits.CmdRsp ==
  869. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  870. vport->ct_flags |= FC_CT_RSPN_ID;
  871. }
  872. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  873. return;
  874. }
  875. static void
  876. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  877. struct lpfc_iocbq *rspiocb)
  878. {
  879. IOCB_t *irsp = &rspiocb->iocb;
  880. struct lpfc_vport *vport = cmdiocb->vport;
  881. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  882. struct lpfc_dmabuf *outp;
  883. struct lpfc_sli_ct_request *CTrsp;
  884. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  885. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  886. if (CTrsp->CommandResponse.bits.CmdRsp ==
  887. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  888. vport->ct_flags |= FC_CT_RSNN_NN;
  889. }
  890. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  891. return;
  892. }
  893. static void
  894. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  895. struct lpfc_iocbq *rspiocb)
  896. {
  897. struct lpfc_vport *vport = cmdiocb->vport;
  898. /* even if it fails we will act as though it succeeded. */
  899. vport->ct_flags = 0;
  900. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  901. return;
  902. }
  903. static void
  904. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  905. struct lpfc_iocbq *rspiocb)
  906. {
  907. IOCB_t *irsp = &rspiocb->iocb;
  908. struct lpfc_vport *vport = cmdiocb->vport;
  909. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  910. struct lpfc_dmabuf *outp;
  911. struct lpfc_sli_ct_request *CTrsp;
  912. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  913. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  914. if (CTrsp->CommandResponse.bits.CmdRsp ==
  915. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  916. vport->ct_flags |= FC_CT_RFF_ID;
  917. }
  918. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  919. return;
  920. }
  921. int
  922. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  923. size_t size)
  924. {
  925. int n;
  926. uint8_t *wwn = vport->phba->wwpn;
  927. n = snprintf(symbol, size,
  928. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  929. wwn[0], wwn[1], wwn[2], wwn[3],
  930. wwn[4], wwn[5], wwn[6], wwn[7]);
  931. if (vport->port_type == LPFC_PHYSICAL_PORT)
  932. return n;
  933. if (n < size)
  934. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  935. if (n < size &&
  936. strlen(vport->fc_vport->symbolic_name))
  937. n += snprintf(symbol + n, size - n, " VName-%s",
  938. vport->fc_vport->symbolic_name);
  939. return n;
  940. }
  941. int
  942. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  943. size_t size)
  944. {
  945. char fwrev[FW_REV_STR_SIZE];
  946. int n;
  947. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  948. n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
  949. if (size < n)
  950. return n;
  951. n += snprintf(symbol + n, size - n, " FV%s", fwrev);
  952. if (size < n)
  953. return n;
  954. n += snprintf(symbol + n, size - n, " DV%s", lpfc_release_version);
  955. if (size < n)
  956. return n;
  957. n += snprintf(symbol + n, size - n, " HN:%s", init_utsname()->nodename);
  958. /* Note :- OS name is "Linux" */
  959. if (size < n)
  960. return n;
  961. n += snprintf(symbol + n, size - n, " OS:%s", init_utsname()->sysname);
  962. return n;
  963. }
  964. static uint32_t
  965. lpfc_find_map_node(struct lpfc_vport *vport)
  966. {
  967. struct lpfc_nodelist *ndlp, *next_ndlp;
  968. struct Scsi_Host *shost;
  969. uint32_t cnt = 0;
  970. shost = lpfc_shost_from_vport(vport);
  971. spin_lock_irq(shost->host_lock);
  972. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  973. if (ndlp->nlp_type & NLP_FABRIC)
  974. continue;
  975. if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
  976. (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
  977. cnt++;
  978. }
  979. spin_unlock_irq(shost->host_lock);
  980. return cnt;
  981. }
  982. /*
  983. * lpfc_ns_cmd
  984. * Description:
  985. * Issue Cmd to NameServer
  986. * SLI_CTNS_GID_FT
  987. * LI_CTNS_RFT_ID
  988. */
  989. int
  990. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  991. uint8_t retry, uint32_t context)
  992. {
  993. struct lpfc_nodelist * ndlp;
  994. struct lpfc_hba *phba = vport->phba;
  995. struct lpfc_dmabuf *mp, *bmp;
  996. struct lpfc_sli_ct_request *CtReq;
  997. struct ulp_bde64 *bpl;
  998. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  999. struct lpfc_iocbq *) = NULL;
  1000. uint32_t rsp_size = 1024;
  1001. size_t size;
  1002. int rc = 0;
  1003. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  1004. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  1005. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  1006. rc=1;
  1007. goto ns_cmd_exit;
  1008. }
  1009. /* fill in BDEs for command */
  1010. /* Allocate buffer for command payload */
  1011. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1012. if (!mp) {
  1013. rc=2;
  1014. goto ns_cmd_exit;
  1015. }
  1016. INIT_LIST_HEAD(&mp->list);
  1017. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  1018. if (!mp->virt) {
  1019. rc=3;
  1020. goto ns_cmd_free_mp;
  1021. }
  1022. /* Allocate buffer for Buffer ptr list */
  1023. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1024. if (!bmp) {
  1025. rc=4;
  1026. goto ns_cmd_free_mpvirt;
  1027. }
  1028. INIT_LIST_HEAD(&bmp->list);
  1029. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1030. if (!bmp->virt) {
  1031. rc=5;
  1032. goto ns_cmd_free_bmp;
  1033. }
  1034. /* NameServer Req */
  1035. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1036. "0236 NameServer Req Data: x%x x%x x%x\n",
  1037. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
  1038. bpl = (struct ulp_bde64 *) bmp->virt;
  1039. memset(bpl, 0, sizeof(struct ulp_bde64));
  1040. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1041. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1042. bpl->tus.f.bdeFlags = 0;
  1043. if (cmdcode == SLI_CTNS_GID_FT)
  1044. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1045. else if (cmdcode == SLI_CTNS_GFF_ID)
  1046. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1047. else if (cmdcode == SLI_CTNS_RFT_ID)
  1048. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1049. else if (cmdcode == SLI_CTNS_RNN_ID)
  1050. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1051. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1052. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1053. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1054. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1055. else if (cmdcode == SLI_CTNS_DA_ID)
  1056. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1057. else if (cmdcode == SLI_CTNS_RFF_ID)
  1058. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1059. else
  1060. bpl->tus.f.bdeSize = 0;
  1061. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1062. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1063. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  1064. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1065. CtReq->RevisionId.bits.InId = 0;
  1066. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1067. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1068. CtReq->CommandResponse.bits.Size = 0;
  1069. switch (cmdcode) {
  1070. case SLI_CTNS_GID_FT:
  1071. CtReq->CommandResponse.bits.CmdRsp =
  1072. cpu_to_be16(SLI_CTNS_GID_FT);
  1073. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  1074. if (vport->port_state < LPFC_NS_QRY)
  1075. vport->port_state = LPFC_NS_QRY;
  1076. lpfc_set_disctmo(vport);
  1077. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1078. rsp_size = FC_MAX_NS_RSP;
  1079. break;
  1080. case SLI_CTNS_GFF_ID:
  1081. CtReq->CommandResponse.bits.CmdRsp =
  1082. cpu_to_be16(SLI_CTNS_GFF_ID);
  1083. CtReq->un.gff.PortId = cpu_to_be32(context);
  1084. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1085. break;
  1086. case SLI_CTNS_RFT_ID:
  1087. vport->ct_flags &= ~FC_CT_RFT_ID;
  1088. CtReq->CommandResponse.bits.CmdRsp =
  1089. cpu_to_be16(SLI_CTNS_RFT_ID);
  1090. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1091. CtReq->un.rft.fcpReg = 1;
  1092. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1093. break;
  1094. case SLI_CTNS_RNN_ID:
  1095. vport->ct_flags &= ~FC_CT_RNN_ID;
  1096. CtReq->CommandResponse.bits.CmdRsp =
  1097. cpu_to_be16(SLI_CTNS_RNN_ID);
  1098. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1099. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1100. sizeof (struct lpfc_name));
  1101. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1102. break;
  1103. case SLI_CTNS_RSPN_ID:
  1104. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1105. CtReq->CommandResponse.bits.CmdRsp =
  1106. cpu_to_be16(SLI_CTNS_RSPN_ID);
  1107. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1108. size = sizeof(CtReq->un.rspn.symbname);
  1109. CtReq->un.rspn.len =
  1110. lpfc_vport_symbolic_port_name(vport,
  1111. CtReq->un.rspn.symbname, size);
  1112. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1113. break;
  1114. case SLI_CTNS_RSNN_NN:
  1115. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1116. CtReq->CommandResponse.bits.CmdRsp =
  1117. cpu_to_be16(SLI_CTNS_RSNN_NN);
  1118. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1119. sizeof (struct lpfc_name));
  1120. size = sizeof(CtReq->un.rsnn.symbname);
  1121. CtReq->un.rsnn.len =
  1122. lpfc_vport_symbolic_node_name(vport,
  1123. CtReq->un.rsnn.symbname, size);
  1124. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1125. break;
  1126. case SLI_CTNS_DA_ID:
  1127. /* Implement DA_ID Nameserver request */
  1128. CtReq->CommandResponse.bits.CmdRsp =
  1129. cpu_to_be16(SLI_CTNS_DA_ID);
  1130. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1131. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1132. break;
  1133. case SLI_CTNS_RFF_ID:
  1134. vport->ct_flags &= ~FC_CT_RFF_ID;
  1135. CtReq->CommandResponse.bits.CmdRsp =
  1136. cpu_to_be16(SLI_CTNS_RFF_ID);
  1137. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1138. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1139. CtReq->un.rff.type_code = FC_TYPE_FCP;
  1140. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1141. break;
  1142. }
  1143. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1144. * to hold ndlp reference for the corresponding callback function.
  1145. */
  1146. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1147. /* On success, The cmpl function will free the buffers */
  1148. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1149. "Issue CT cmd: cmd:x%x did:x%x",
  1150. cmdcode, ndlp->nlp_DID, 0);
  1151. return 0;
  1152. }
  1153. rc=6;
  1154. /* Decrement ndlp reference count to release ndlp reference held
  1155. * for the failed command's callback function.
  1156. */
  1157. lpfc_nlp_put(ndlp);
  1158. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1159. ns_cmd_free_bmp:
  1160. kfree(bmp);
  1161. ns_cmd_free_mpvirt:
  1162. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1163. ns_cmd_free_mp:
  1164. kfree(mp);
  1165. ns_cmd_exit:
  1166. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1167. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1168. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1169. return 1;
  1170. }
  1171. static void
  1172. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1173. struct lpfc_iocbq * rspiocb)
  1174. {
  1175. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1176. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1177. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1178. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1179. struct lpfc_nodelist *ndlp;
  1180. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1181. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1182. struct lpfc_vport *vport = cmdiocb->vport;
  1183. IOCB_t *irsp = &rspiocb->iocb;
  1184. uint32_t latt;
  1185. latt = lpfc_els_chk_latt(vport);
  1186. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1187. "FDMI cmpl: status:x%x/x%x latt:%d",
  1188. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1189. if (latt || irsp->ulpStatus) {
  1190. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1191. "0229 FDMI cmd %04x failed, latt = %d "
  1192. "ulpStatus: x%x, rid x%x\n",
  1193. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1194. irsp->un.ulpWord[4]);
  1195. goto fail_out;
  1196. }
  1197. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1198. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1199. goto fail_out;
  1200. if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
  1201. /* FDMI rsp failed */
  1202. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1203. "0220 FDMI rsp failed Data: x%x\n",
  1204. be16_to_cpu(fdmi_cmd));
  1205. }
  1206. fail_out:
  1207. lpfc_ct_free_iocb(phba, cmdiocb);
  1208. }
  1209. static void
  1210. lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1211. struct lpfc_iocbq *rspiocb)
  1212. {
  1213. struct lpfc_vport *vport = cmdiocb->vport;
  1214. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1215. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1216. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1217. struct lpfc_nodelist *ndlp;
  1218. lpfc_cmpl_ct_cmd_fdmi(phba, cmdiocb, rspiocb);
  1219. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1220. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1221. return;
  1222. /*
  1223. * Need to cycle thru FDMI registration for discovery
  1224. * DHBA -> DPRT -> RHBA -> RPA
  1225. */
  1226. switch (be16_to_cpu(fdmi_cmd)) {
  1227. case SLI_MGMT_RHBA:
  1228. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  1229. break;
  1230. case SLI_MGMT_DHBA:
  1231. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  1232. break;
  1233. case SLI_MGMT_DPRT:
  1234. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  1235. break;
  1236. }
  1237. }
  1238. int
  1239. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  1240. {
  1241. struct lpfc_hba *phba = vport->phba;
  1242. struct lpfc_dmabuf *mp, *bmp;
  1243. struct lpfc_sli_ct_request *CtReq;
  1244. struct ulp_bde64 *bpl;
  1245. uint32_t size;
  1246. uint32_t rsp_size;
  1247. struct lpfc_fdmi_reg_hba *rh;
  1248. struct lpfc_fdmi_port_entry *pe;
  1249. struct lpfc_fdmi_reg_portattr *pab = NULL;
  1250. struct lpfc_fdmi_attr_block *ab = NULL;
  1251. struct lpfc_fdmi_attr_entry *ae;
  1252. struct lpfc_fdmi_attr_def *ad;
  1253. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1254. struct lpfc_iocbq *);
  1255. if (ndlp == NULL) {
  1256. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1257. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1258. return 0;
  1259. cmpl = lpfc_cmpl_ct_cmd_fdmi; /* cmd interface */
  1260. } else {
  1261. cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
  1262. }
  1263. /* fill in BDEs for command */
  1264. /* Allocate buffer for command payload */
  1265. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1266. if (!mp)
  1267. goto fdmi_cmd_exit;
  1268. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  1269. if (!mp->virt)
  1270. goto fdmi_cmd_free_mp;
  1271. /* Allocate buffer for Buffer ptr list */
  1272. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1273. if (!bmp)
  1274. goto fdmi_cmd_free_mpvirt;
  1275. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  1276. if (!bmp->virt)
  1277. goto fdmi_cmd_free_bmp;
  1278. INIT_LIST_HEAD(&mp->list);
  1279. INIT_LIST_HEAD(&bmp->list);
  1280. /* FDMI request */
  1281. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1282. "0218 FDMI Request Data: x%x x%x x%x\n",
  1283. vport->fc_flag, vport->port_state, cmdcode);
  1284. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  1285. /* First populate the CT_IU preamble */
  1286. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1287. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1288. CtReq->RevisionId.bits.InId = 0;
  1289. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  1290. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  1291. CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  1292. rsp_size = LPFC_BPL_SIZE;
  1293. size = 0;
  1294. /* Next fill in the specific FDMI cmd information */
  1295. switch (cmdcode) {
  1296. case SLI_MGMT_RHAT:
  1297. case SLI_MGMT_RHBA:
  1298. {
  1299. lpfc_vpd_t *vp = &phba->vpd;
  1300. uint32_t i, j, incr;
  1301. int len = 0;
  1302. rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
  1303. /* HBA Identifier */
  1304. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  1305. sizeof(struct lpfc_name));
  1306. if (cmdcode == SLI_MGMT_RHBA) {
  1307. /* Registered Port List */
  1308. /* One entry (port) per adapter */
  1309. rh->rpl.EntryCnt = cpu_to_be32(1);
  1310. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  1311. sizeof(struct lpfc_name));
  1312. /* point to the HBA attribute block */
  1313. size = 2 * sizeof(struct lpfc_name) +
  1314. FOURBYTES;
  1315. } else {
  1316. size = sizeof(struct lpfc_name);
  1317. }
  1318. ab = (struct lpfc_fdmi_attr_block *)
  1319. ((uint8_t *)rh + size);
  1320. ab->EntryCnt = 0;
  1321. size += FOURBYTES;
  1322. /*
  1323. * Point to beginning of first HBA attribute entry
  1324. */
  1325. /* #1 HBA attribute entry */
  1326. ad = (struct lpfc_fdmi_attr_def *)
  1327. ((uint8_t *)rh + size);
  1328. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1329. memset(ae, 0, sizeof(struct lpfc_name));
  1330. ad->AttrType = cpu_to_be16(RHBA_NODENAME);
  1331. ad->AttrLen = cpu_to_be16(FOURBYTES
  1332. + sizeof(struct lpfc_name));
  1333. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1334. sizeof(struct lpfc_name));
  1335. ab->EntryCnt++;
  1336. size += FOURBYTES + sizeof(struct lpfc_name);
  1337. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1338. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1339. goto hba_out;
  1340. /* #2 HBA attribute entry */
  1341. ad = (struct lpfc_fdmi_attr_def *)
  1342. ((uint8_t *)rh + size);
  1343. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1344. memset(ae, 0, sizeof(ae->un.Manufacturer));
  1345. ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
  1346. strncpy(ae->un.Manufacturer, "Emulex Corporation",
  1347. sizeof(ae->un.Manufacturer));
  1348. len = strnlen(ae->un.Manufacturer,
  1349. sizeof(ae->un.Manufacturer));
  1350. len += (len & 3) ? (4 - (len & 3)) : 4;
  1351. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1352. ab->EntryCnt++;
  1353. size += FOURBYTES + len;
  1354. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1355. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1356. goto hba_out;
  1357. /* #3 HBA attribute entry */
  1358. ad = (struct lpfc_fdmi_attr_def *)
  1359. ((uint8_t *)rh + size);
  1360. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1361. memset(ae, 0, sizeof(ae->un.SerialNumber));
  1362. ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
  1363. strncpy(ae->un.SerialNumber, phba->SerialNumber,
  1364. sizeof(ae->un.SerialNumber));
  1365. len = strnlen(ae->un.SerialNumber,
  1366. sizeof(ae->un.SerialNumber));
  1367. len += (len & 3) ? (4 - (len & 3)) : 4;
  1368. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1369. ab->EntryCnt++;
  1370. size += FOURBYTES + len;
  1371. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1372. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1373. goto hba_out;
  1374. /* #4 HBA attribute entry */
  1375. ad = (struct lpfc_fdmi_attr_def *)
  1376. ((uint8_t *)rh + size);
  1377. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1378. memset(ae, 0, sizeof(ae->un.Model));
  1379. ad->AttrType = cpu_to_be16(RHBA_MODEL);
  1380. strncpy(ae->un.Model, phba->ModelName,
  1381. sizeof(ae->un.Model));
  1382. len = strnlen(ae->un.Model, sizeof(ae->un.Model));
  1383. len += (len & 3) ? (4 - (len & 3)) : 4;
  1384. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1385. ab->EntryCnt++;
  1386. size += FOURBYTES + len;
  1387. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1388. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1389. goto hba_out;
  1390. /* #5 HBA attribute entry */
  1391. ad = (struct lpfc_fdmi_attr_def *)
  1392. ((uint8_t *)rh + size);
  1393. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1394. memset(ae, 0, sizeof(ae->un.ModelDescription));
  1395. ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
  1396. strncpy(ae->un.ModelDescription, phba->ModelDesc,
  1397. sizeof(ae->un.ModelDescription));
  1398. len = strnlen(ae->un.ModelDescription,
  1399. sizeof(ae->un.ModelDescription));
  1400. len += (len & 3) ? (4 - (len & 3)) : 4;
  1401. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1402. ab->EntryCnt++;
  1403. size += FOURBYTES + len;
  1404. if ((size + 8) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1405. goto hba_out;
  1406. /* #6 HBA attribute entry */
  1407. ad = (struct lpfc_fdmi_attr_def *)
  1408. ((uint8_t *)rh + size);
  1409. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1410. memset(ae, 0, 8);
  1411. ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
  1412. ad->AttrLen = cpu_to_be16(FOURBYTES + 8);
  1413. /* Convert JEDEC ID to ascii for hardware version */
  1414. incr = vp->rev.biuRev;
  1415. for (i = 0; i < 8; i++) {
  1416. j = (incr & 0xf);
  1417. if (j <= 9)
  1418. ae->un.HardwareVersion[7 - i] =
  1419. (char)((uint8_t)0x30 +
  1420. (uint8_t)j);
  1421. else
  1422. ae->un.HardwareVersion[7 - i] =
  1423. (char)((uint8_t)0x61 +
  1424. (uint8_t)(j - 10));
  1425. incr = (incr >> 4);
  1426. }
  1427. ab->EntryCnt++;
  1428. size += FOURBYTES + 8;
  1429. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1430. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1431. goto hba_out;
  1432. /* #7 HBA attribute entry */
  1433. ad = (struct lpfc_fdmi_attr_def *)
  1434. ((uint8_t *)rh + size);
  1435. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1436. memset(ae, 0, sizeof(ae->un.DriverVersion));
  1437. ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
  1438. strncpy(ae->un.DriverVersion, lpfc_release_version,
  1439. sizeof(ae->un.DriverVersion));
  1440. len = strnlen(ae->un.DriverVersion,
  1441. sizeof(ae->un.DriverVersion));
  1442. len += (len & 3) ? (4 - (len & 3)) : 4;
  1443. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1444. ab->EntryCnt++;
  1445. size += FOURBYTES + len;
  1446. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1447. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1448. goto hba_out;
  1449. /* #8 HBA attribute entry */
  1450. ad = (struct lpfc_fdmi_attr_def *)
  1451. ((uint8_t *)rh + size);
  1452. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1453. memset(ae, 0, sizeof(ae->un.OptionROMVersion));
  1454. ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
  1455. strncpy(ae->un.OptionROMVersion, phba->OptionROMVersion,
  1456. sizeof(ae->un.OptionROMVersion));
  1457. len = strnlen(ae->un.OptionROMVersion,
  1458. sizeof(ae->un.OptionROMVersion));
  1459. len += (len & 3) ? (4 - (len & 3)) : 4;
  1460. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1461. ab->EntryCnt++;
  1462. size += FOURBYTES + len;
  1463. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1464. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1465. goto hba_out;
  1466. /* #9 HBA attribute entry */
  1467. ad = (struct lpfc_fdmi_attr_def *)
  1468. ((uint8_t *)rh + size);
  1469. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1470. memset(ae, 0, sizeof(ae->un.FirmwareVersion));
  1471. ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
  1472. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  1473. 1);
  1474. len = strnlen(ae->un.FirmwareVersion,
  1475. sizeof(ae->un.FirmwareVersion));
  1476. len += (len & 3) ? (4 - (len & 3)) : 4;
  1477. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1478. ab->EntryCnt++;
  1479. size += FOURBYTES + len;
  1480. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1481. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1482. goto hba_out;
  1483. /* #10 HBA attribute entry */
  1484. ad = (struct lpfc_fdmi_attr_def *)
  1485. ((uint8_t *)rh + size);
  1486. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1487. memset(ae, 0, sizeof(ae->un.OsNameVersion));
  1488. ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
  1489. snprintf(ae->un.OsNameVersion,
  1490. sizeof(ae->un.OsNameVersion),
  1491. "%s %s %s",
  1492. init_utsname()->sysname,
  1493. init_utsname()->release,
  1494. init_utsname()->version);
  1495. len = strnlen(ae->un.OsNameVersion,
  1496. sizeof(ae->un.OsNameVersion));
  1497. len += (len & 3) ? (4 - (len & 3)) : 4;
  1498. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1499. ab->EntryCnt++;
  1500. size += FOURBYTES + len;
  1501. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1502. goto hba_out;
  1503. /* #11 HBA attribute entry */
  1504. ad = (struct lpfc_fdmi_attr_def *)
  1505. ((uint8_t *)rh + size);
  1506. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1507. ad->AttrType =
  1508. cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
  1509. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1510. ae->un.MaxCTPayloadLen = cpu_to_be32(LPFC_MAX_CT_SIZE);
  1511. ab->EntryCnt++;
  1512. size += FOURBYTES + 4;
  1513. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1514. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1515. goto hba_out;
  1516. /*
  1517. * Currently switches don't seem to support the
  1518. * following extended HBA attributes.
  1519. */
  1520. if (!(vport->cfg_fdmi_on & LPFC_FDMI_ALL_ATTRIB))
  1521. goto hba_out;
  1522. /* #12 HBA attribute entry */
  1523. ad = (struct lpfc_fdmi_attr_def *)
  1524. ((uint8_t *)rh + size);
  1525. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1526. memset(ae, 0, sizeof(ae->un.NodeSymName));
  1527. ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
  1528. len = lpfc_vport_symbolic_node_name(vport,
  1529. ae->un.NodeSymName, sizeof(ae->un.NodeSymName));
  1530. len += (len & 3) ? (4 - (len & 3)) : 4;
  1531. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1532. ab->EntryCnt++;
  1533. size += FOURBYTES + len;
  1534. hba_out:
  1535. ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
  1536. /* Total size */
  1537. size = GID_REQUEST_SZ - 4 + size;
  1538. }
  1539. break;
  1540. case SLI_MGMT_RPRT:
  1541. case SLI_MGMT_RPA:
  1542. {
  1543. lpfc_vpd_t *vp;
  1544. struct serv_parm *hsp;
  1545. int len = 0;
  1546. vp = &phba->vpd;
  1547. if (cmdcode == SLI_MGMT_RPRT) {
  1548. rh = (struct lpfc_fdmi_reg_hba *)
  1549. &CtReq->un.PortID;
  1550. /* HBA Identifier */
  1551. memcpy(&rh->hi.PortName,
  1552. &vport->fc_sparam.portName,
  1553. sizeof(struct lpfc_name));
  1554. pab = (struct lpfc_fdmi_reg_portattr *)
  1555. &rh->rpl.EntryCnt;
  1556. } else
  1557. pab = (struct lpfc_fdmi_reg_portattr *)
  1558. &CtReq->un.PortID;
  1559. size = sizeof(struct lpfc_name) + FOURBYTES;
  1560. memcpy((uint8_t *)&pab->PortName,
  1561. (uint8_t *)&vport->fc_sparam.portName,
  1562. sizeof(struct lpfc_name));
  1563. pab->ab.EntryCnt = 0;
  1564. /* #1 Port attribute entry */
  1565. ad = (struct lpfc_fdmi_attr_def *)
  1566. ((uint8_t *)pab + size);
  1567. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1568. memset(ae, 0, sizeof(ae->un.FC4Types));
  1569. ad->AttrType =
  1570. cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
  1571. ad->AttrLen = cpu_to_be16(FOURBYTES + 32);
  1572. ae->un.FC4Types[0] = 0x40; /* Type 1 - ELS */
  1573. ae->un.FC4Types[1] = 0x80; /* Type 8 - FCP */
  1574. ae->un.FC4Types[4] = 0x80; /* Type 32 - CT */
  1575. pab->ab.EntryCnt++;
  1576. size += FOURBYTES + 32;
  1577. /* #2 Port attribute entry */
  1578. ad = (struct lpfc_fdmi_attr_def *)
  1579. ((uint8_t *)pab + size);
  1580. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1581. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
  1582. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1583. ae->un.SupportSpeed = 0;
  1584. if (phba->lmt & LMT_16Gb)
  1585. ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
  1586. if (phba->lmt & LMT_10Gb)
  1587. ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
  1588. if (phba->lmt & LMT_8Gb)
  1589. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  1590. if (phba->lmt & LMT_4Gb)
  1591. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  1592. if (phba->lmt & LMT_2Gb)
  1593. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  1594. if (phba->lmt & LMT_1Gb)
  1595. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  1596. ae->un.SupportSpeed =
  1597. cpu_to_be32(ae->un.SupportSpeed);
  1598. pab->ab.EntryCnt++;
  1599. size += FOURBYTES + 4;
  1600. /* #3 Port attribute entry */
  1601. ad = (struct lpfc_fdmi_attr_def *)
  1602. ((uint8_t *)pab + size);
  1603. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1604. ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
  1605. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1606. switch (phba->fc_linkspeed) {
  1607. case LPFC_LINK_SPEED_1GHZ:
  1608. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  1609. break;
  1610. case LPFC_LINK_SPEED_2GHZ:
  1611. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  1612. break;
  1613. case LPFC_LINK_SPEED_4GHZ:
  1614. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  1615. break;
  1616. case LPFC_LINK_SPEED_8GHZ:
  1617. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  1618. break;
  1619. case LPFC_LINK_SPEED_10GHZ:
  1620. ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
  1621. break;
  1622. case LPFC_LINK_SPEED_16GHZ:
  1623. ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
  1624. break;
  1625. default:
  1626. ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
  1627. break;
  1628. }
  1629. ae->un.PortSpeed = cpu_to_be32(ae->un.PortSpeed);
  1630. pab->ab.EntryCnt++;
  1631. size += FOURBYTES + 4;
  1632. /* #4 Port attribute entry */
  1633. ad = (struct lpfc_fdmi_attr_def *)
  1634. ((uint8_t *)pab + size);
  1635. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1636. ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
  1637. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1638. hsp = (struct serv_parm *)&vport->fc_sparam;
  1639. ae->un.MaxFrameSize =
  1640. (((uint32_t)hsp->cmn.
  1641. bbRcvSizeMsb) << 8) | (uint32_t)hsp->cmn.
  1642. bbRcvSizeLsb;
  1643. ae->un.MaxFrameSize =
  1644. cpu_to_be32(ae->un.MaxFrameSize);
  1645. pab->ab.EntryCnt++;
  1646. size += FOURBYTES + 4;
  1647. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1648. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1649. goto port_out;
  1650. /* #5 Port attribute entry */
  1651. ad = (struct lpfc_fdmi_attr_def *)
  1652. ((uint8_t *)pab + size);
  1653. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1654. memset(ae, 0, sizeof(ae->un.OsDeviceName));
  1655. ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
  1656. strncpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME,
  1657. sizeof(ae->un.OsDeviceName));
  1658. len = strnlen((char *)ae->un.OsDeviceName,
  1659. sizeof(ae->un.OsDeviceName));
  1660. len += (len & 3) ? (4 - (len & 3)) : 4;
  1661. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1662. pab->ab.EntryCnt++;
  1663. size += FOURBYTES + len;
  1664. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1665. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1666. goto port_out;
  1667. /* #6 Port attribute entry */
  1668. ad = (struct lpfc_fdmi_attr_def *)
  1669. ((uint8_t *)pab + size);
  1670. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1671. memset(ae, 0, sizeof(ae->un.HostName));
  1672. snprintf(ae->un.HostName, sizeof(ae->un.HostName), "%s",
  1673. init_utsname()->nodename);
  1674. ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
  1675. len = strnlen(ae->un.HostName,
  1676. sizeof(ae->un.HostName));
  1677. len += (len & 3) ? (4 - (len & 3)) : 4;
  1678. ad->AttrLen =
  1679. cpu_to_be16(FOURBYTES + len);
  1680. pab->ab.EntryCnt++;
  1681. size += FOURBYTES + len;
  1682. if ((size + sizeof(struct lpfc_name)) >
  1683. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1684. goto port_out;
  1685. /*
  1686. * Currently switches don't seem to support the
  1687. * following extended Port attributes.
  1688. */
  1689. if (!(vport->cfg_fdmi_on & LPFC_FDMI_ALL_ATTRIB))
  1690. goto port_out;
  1691. /* #7 Port attribute entry */
  1692. ad = (struct lpfc_fdmi_attr_def *)
  1693. ((uint8_t *)pab + size);
  1694. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1695. memset(ae, 0, sizeof(struct lpfc_name));
  1696. ad->AttrType = cpu_to_be16(RPRT_NODENAME);
  1697. ad->AttrLen = cpu_to_be16(FOURBYTES
  1698. + sizeof(struct lpfc_name));
  1699. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1700. sizeof(struct lpfc_name));
  1701. pab->ab.EntryCnt++;
  1702. size += FOURBYTES + sizeof(struct lpfc_name);
  1703. if ((size + sizeof(struct lpfc_name)) >
  1704. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1705. goto port_out;
  1706. /* #8 Port attribute entry */
  1707. ad = (struct lpfc_fdmi_attr_def *)
  1708. ((uint8_t *)pab + size);
  1709. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1710. memset(ae, 0, sizeof(struct lpfc_name));
  1711. ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
  1712. ad->AttrLen = cpu_to_be16(FOURBYTES
  1713. + sizeof(struct lpfc_name));
  1714. memcpy(&ae->un.PortName, &vport->fc_sparam.portName,
  1715. sizeof(struct lpfc_name));
  1716. pab->ab.EntryCnt++;
  1717. size += FOURBYTES + sizeof(struct lpfc_name);
  1718. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1719. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1720. goto port_out;
  1721. /* #9 Port attribute entry */
  1722. ad = (struct lpfc_fdmi_attr_def *)
  1723. ((uint8_t *)pab + size);
  1724. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1725. memset(ae, 0, sizeof(ae->un.NodeSymName));
  1726. ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
  1727. len = lpfc_vport_symbolic_port_name(vport,
  1728. ae->un.NodeSymName, sizeof(ae->un.NodeSymName));
  1729. len += (len & 3) ? (4 - (len & 3)) : 4;
  1730. ad->AttrLen = cpu_to_be16(FOURBYTES + len);
  1731. pab->ab.EntryCnt++;
  1732. size += FOURBYTES + len;
  1733. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1734. goto port_out;
  1735. /* #10 Port attribute entry */
  1736. ad = (struct lpfc_fdmi_attr_def *)
  1737. ((uint8_t *)pab + size);
  1738. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1739. ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
  1740. ae->un.PortState = 0;
  1741. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1742. pab->ab.EntryCnt++;
  1743. size += FOURBYTES + 4;
  1744. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1745. goto port_out;
  1746. /* #11 Port attribute entry */
  1747. ad = (struct lpfc_fdmi_attr_def *)
  1748. ((uint8_t *)pab + size);
  1749. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1750. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
  1751. ae->un.SupportClass =
  1752. cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
  1753. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1754. pab->ab.EntryCnt++;
  1755. size += FOURBYTES + 4;
  1756. if ((size + sizeof(struct lpfc_name)) >
  1757. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1758. goto port_out;
  1759. /* #12 Port attribute entry */
  1760. ad = (struct lpfc_fdmi_attr_def *)
  1761. ((uint8_t *)pab + size);
  1762. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1763. memset(ae, 0, sizeof(struct lpfc_name));
  1764. ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
  1765. ad->AttrLen = cpu_to_be16(FOURBYTES
  1766. + sizeof(struct lpfc_name));
  1767. memcpy(&ae->un.FabricName, &vport->fabric_nodename,
  1768. sizeof(struct lpfc_name));
  1769. pab->ab.EntryCnt++;
  1770. size += FOURBYTES + sizeof(struct lpfc_name);
  1771. if ((size + LPFC_FDMI_MAX_AE_SIZE) >
  1772. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1773. goto port_out;
  1774. /* #13 Port attribute entry */
  1775. ad = (struct lpfc_fdmi_attr_def *)
  1776. ((uint8_t *)pab + size);
  1777. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1778. memset(ae, 0, sizeof(ae->un.FC4Types));
  1779. ad->AttrType =
  1780. cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
  1781. ad->AttrLen = cpu_to_be16(FOURBYTES + 32);
  1782. ae->un.FC4Types[0] = 0x40; /* Type 1 - ELS */
  1783. ae->un.FC4Types[1] = 0x80; /* Type 8 - FCP */
  1784. ae->un.FC4Types[4] = 0x80; /* Type 32 - CT */
  1785. pab->ab.EntryCnt++;
  1786. size += FOURBYTES + 32;
  1787. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1788. goto port_out;
  1789. /* #257 Port attribute entry */
  1790. ad = (struct lpfc_fdmi_attr_def *)
  1791. ((uint8_t *)pab + size);
  1792. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1793. ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
  1794. ae->un.PortState = 0;
  1795. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1796. pab->ab.EntryCnt++;
  1797. size += FOURBYTES + 4;
  1798. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1799. goto port_out;
  1800. /* #258 Port attribute entry */
  1801. ad = (struct lpfc_fdmi_attr_def *)
  1802. ((uint8_t *)pab + size);
  1803. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1804. ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
  1805. ae->un.PortState = lpfc_find_map_node(vport);
  1806. ae->un.PortState = cpu_to_be32(ae->un.PortState);
  1807. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1808. pab->ab.EntryCnt++;
  1809. size += FOURBYTES + 4;
  1810. if ((size + 4) > (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  1811. goto port_out;
  1812. /* #259 Port attribute entry */
  1813. ad = (struct lpfc_fdmi_attr_def *)
  1814. ((uint8_t *)pab + size);
  1815. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1816. ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
  1817. ae->un.PortId = cpu_to_be32(vport->fc_myDID);
  1818. ad->AttrLen = cpu_to_be16(FOURBYTES + 4);
  1819. pab->ab.EntryCnt++;
  1820. size += FOURBYTES + 4;
  1821. port_out:
  1822. pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
  1823. /* Total size */
  1824. size = GID_REQUEST_SZ - 4 + size;
  1825. }
  1826. break;
  1827. case SLI_MGMT_GHAT:
  1828. case SLI_MGMT_GRPL:
  1829. rsp_size = FC_MAX_NS_RSP;
  1830. case SLI_MGMT_DHBA:
  1831. case SLI_MGMT_DHAT:
  1832. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  1833. memcpy((uint8_t *)&pe->PortName,
  1834. (uint8_t *)&vport->fc_sparam.portName,
  1835. sizeof(struct lpfc_name));
  1836. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  1837. break;
  1838. case SLI_MGMT_GPAT:
  1839. case SLI_MGMT_GPAS:
  1840. rsp_size = FC_MAX_NS_RSP;
  1841. case SLI_MGMT_DPRT:
  1842. case SLI_MGMT_DPA:
  1843. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  1844. memcpy((uint8_t *)&pe->PortName,
  1845. (uint8_t *)&vport->fc_sparam.portName,
  1846. sizeof(struct lpfc_name));
  1847. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  1848. break;
  1849. case SLI_MGMT_GRHL:
  1850. size = GID_REQUEST_SZ - 4;
  1851. break;
  1852. default:
  1853. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  1854. "0298 FDMI cmdcode x%x not supported\n",
  1855. cmdcode);
  1856. goto fdmi_cmd_free_bmpvirt;
  1857. }
  1858. CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  1859. bpl = (struct ulp_bde64 *)bmp->virt;
  1860. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
  1861. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
  1862. bpl->tus.f.bdeFlags = 0;
  1863. bpl->tus.f.bdeSize = size;
  1864. /*
  1865. * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1866. * to hold ndlp reference for the corresponding callback function.
  1867. */
  1868. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
  1869. return 0;
  1870. /*
  1871. * Decrement ndlp reference count to release ndlp reference held
  1872. * for the failed command's callback function.
  1873. */
  1874. lpfc_nlp_put(ndlp);
  1875. fdmi_cmd_free_bmpvirt:
  1876. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1877. fdmi_cmd_free_bmp:
  1878. kfree(bmp);
  1879. fdmi_cmd_free_mpvirt:
  1880. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1881. fdmi_cmd_free_mp:
  1882. kfree(mp);
  1883. fdmi_cmd_exit:
  1884. /* Issue FDMI request failed */
  1885. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1886. "0244 Issue FDMI request failed Data: x%x\n",
  1887. cmdcode);
  1888. return 1;
  1889. }
  1890. /**
  1891. * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
  1892. * @ptr - Context object of the timer.
  1893. *
  1894. * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
  1895. * the worker thread.
  1896. **/
  1897. void
  1898. lpfc_delayed_disc_tmo(unsigned long ptr)
  1899. {
  1900. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1901. struct lpfc_hba *phba = vport->phba;
  1902. uint32_t tmo_posted;
  1903. unsigned long iflag;
  1904. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1905. tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
  1906. if (!tmo_posted)
  1907. vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
  1908. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1909. if (!tmo_posted)
  1910. lpfc_worker_wake_up(phba);
  1911. return;
  1912. }
  1913. /**
  1914. * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
  1915. * handle delayed discovery.
  1916. * @vport: pointer to a host virtual N_Port data structure.
  1917. *
  1918. * This function start nport discovery of the vport.
  1919. **/
  1920. void
  1921. lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
  1922. {
  1923. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1924. spin_lock_irq(shost->host_lock);
  1925. if (!(vport->fc_flag & FC_DISC_DELAYED)) {
  1926. spin_unlock_irq(shost->host_lock);
  1927. return;
  1928. }
  1929. vport->fc_flag &= ~FC_DISC_DELAYED;
  1930. spin_unlock_irq(shost->host_lock);
  1931. lpfc_do_scr_ns_plogi(vport->phba, vport);
  1932. }
  1933. void
  1934. lpfc_fdmi_tmo(unsigned long ptr)
  1935. {
  1936. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1937. struct lpfc_hba *phba = vport->phba;
  1938. uint32_t tmo_posted;
  1939. unsigned long iflag;
  1940. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1941. tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
  1942. if (!tmo_posted)
  1943. vport->work_port_events |= WORKER_FDMI_TMO;
  1944. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1945. if (!tmo_posted)
  1946. lpfc_worker_wake_up(phba);
  1947. return;
  1948. }
  1949. void
  1950. lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
  1951. {
  1952. struct lpfc_nodelist *ndlp;
  1953. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1954. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  1955. if (init_utsname()->nodename[0] != '\0')
  1956. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  1957. else
  1958. mod_timer(&vport->fc_fdmitmo, jiffies +
  1959. msecs_to_jiffies(1000 * 60));
  1960. }
  1961. return;
  1962. }
  1963. void
  1964. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  1965. {
  1966. struct lpfc_sli *psli = &phba->sli;
  1967. lpfc_vpd_t *vp = &phba->vpd;
  1968. uint32_t b1, b2, b3, b4, i, rev;
  1969. char c;
  1970. uint32_t *ptr, str[4];
  1971. uint8_t *fwname;
  1972. if (phba->sli_rev == LPFC_SLI_REV4)
  1973. snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
  1974. else if (vp->rev.rBit) {
  1975. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  1976. rev = vp->rev.sli2FwRev;
  1977. else
  1978. rev = vp->rev.sli1FwRev;
  1979. b1 = (rev & 0x0000f000) >> 12;
  1980. b2 = (rev & 0x00000f00) >> 8;
  1981. b3 = (rev & 0x000000c0) >> 6;
  1982. b4 = (rev & 0x00000030) >> 4;
  1983. switch (b4) {
  1984. case 0:
  1985. c = 'N';
  1986. break;
  1987. case 1:
  1988. c = 'A';
  1989. break;
  1990. case 2:
  1991. c = 'B';
  1992. break;
  1993. case 3:
  1994. c = 'X';
  1995. break;
  1996. default:
  1997. c = 0;
  1998. break;
  1999. }
  2000. b4 = (rev & 0x0000000f);
  2001. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  2002. fwname = vp->rev.sli2FwName;
  2003. else
  2004. fwname = vp->rev.sli1FwName;
  2005. for (i = 0; i < 16; i++)
  2006. if (fwname[i] == 0x20)
  2007. fwname[i] = 0;
  2008. ptr = (uint32_t*)fwname;
  2009. for (i = 0; i < 3; i++)
  2010. str[i] = be32_to_cpu(*ptr++);
  2011. if (c == 0) {
  2012. if (flag)
  2013. sprintf(fwrevision, "%d.%d%d (%s)",
  2014. b1, b2, b3, (char *)str);
  2015. else
  2016. sprintf(fwrevision, "%d.%d%d", b1,
  2017. b2, b3);
  2018. } else {
  2019. if (flag)
  2020. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  2021. b1, b2, b3, c,
  2022. b4, (char *)str);
  2023. else
  2024. sprintf(fwrevision, "%d.%d%d%c%d",
  2025. b1, b2, b3, c, b4);
  2026. }
  2027. } else {
  2028. rev = vp->rev.smFwRev;
  2029. b1 = (rev & 0xff000000) >> 24;
  2030. b2 = (rev & 0x00f00000) >> 20;
  2031. b3 = (rev & 0x000f0000) >> 16;
  2032. c = (rev & 0x0000ff00) >> 8;
  2033. b4 = (rev & 0x000000ff);
  2034. sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
  2035. }
  2036. return;
  2037. }