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