lpfc_ct.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 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/utsname.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_version.h"
  42. #include "lpfc_vport.h"
  43. #include "lpfc_debugfs.h"
  44. #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  45. * incapable of reporting */
  46. #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
  47. #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
  48. #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
  49. #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
  50. #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
  51. #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
  52. #define FOURBYTES 4
  53. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  54. static void
  55. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  56. struct lpfc_dmabuf *mp, uint32_t size)
  57. {
  58. if (!mp) {
  59. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  60. "0146 Ignoring unsolicited CT No HBQ "
  61. "status = x%x\n",
  62. piocbq->iocb.ulpStatus);
  63. }
  64. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  65. "0145 Ignoring unsolicted CT HBQ Size:%d "
  66. "status = x%x\n",
  67. size, piocbq->iocb.ulpStatus);
  68. }
  69. static void
  70. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  71. struct lpfc_dmabuf *mp, uint32_t size)
  72. {
  73. lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
  74. }
  75. void
  76. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  77. struct lpfc_iocbq *piocbq)
  78. {
  79. struct lpfc_dmabuf *mp = NULL;
  80. IOCB_t *icmd = &piocbq->iocb;
  81. int i;
  82. struct lpfc_iocbq *iocbq;
  83. dma_addr_t paddr;
  84. uint32_t size;
  85. struct list_head head;
  86. struct lpfc_dmabuf *bdeBuf;
  87. if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
  88. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  89. } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  90. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  91. /* Not enough posted buffers; Try posting more buffers */
  92. phba->fc_stat.NoRcvBuf++;
  93. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  94. lpfc_post_buffer(phba, pring, 2);
  95. return;
  96. }
  97. /* If there are no BDEs associated with this IOCB,
  98. * there is nothing to do.
  99. */
  100. if (icmd->ulpBdeCount == 0)
  101. return;
  102. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  103. INIT_LIST_HEAD(&head);
  104. list_add_tail(&head, &piocbq->list);
  105. list_for_each_entry(iocbq, &head, list) {
  106. icmd = &iocbq->iocb;
  107. if (icmd->ulpBdeCount == 0)
  108. continue;
  109. bdeBuf = iocbq->context2;
  110. iocbq->context2 = NULL;
  111. size = icmd->un.cont64[0].tus.f.bdeSize;
  112. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
  113. lpfc_in_buf_free(phba, bdeBuf);
  114. if (icmd->ulpBdeCount == 2) {
  115. bdeBuf = iocbq->context3;
  116. iocbq->context3 = NULL;
  117. size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
  118. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
  119. size);
  120. lpfc_in_buf_free(phba, bdeBuf);
  121. }
  122. }
  123. list_del(&head);
  124. } else {
  125. INIT_LIST_HEAD(&head);
  126. list_add_tail(&head, &piocbq->list);
  127. list_for_each_entry(iocbq, &head, list) {
  128. icmd = &iocbq->iocb;
  129. if (icmd->ulpBdeCount == 0)
  130. lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
  131. for (i = 0; i < icmd->ulpBdeCount; i++) {
  132. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  133. icmd->un.cont64[i].addrLow);
  134. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  135. paddr);
  136. size = icmd->un.cont64[i].tus.f.bdeSize;
  137. lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
  138. lpfc_in_buf_free(phba, mp);
  139. }
  140. lpfc_post_buffer(phba, pring, i);
  141. }
  142. list_del(&head);
  143. }
  144. }
  145. static void
  146. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  147. {
  148. struct lpfc_dmabuf *mlast, *next_mlast;
  149. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  150. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  151. list_del(&mlast->list);
  152. kfree(mlast);
  153. }
  154. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  155. kfree(mlist);
  156. return;
  157. }
  158. static struct lpfc_dmabuf *
  159. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  160. uint32_t size, int *entries)
  161. {
  162. struct lpfc_dmabuf *mlist = NULL;
  163. struct lpfc_dmabuf *mp;
  164. int cnt, i = 0;
  165. /* We get chunks of FCELSSIZE */
  166. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  167. while (size) {
  168. /* Allocate buffer for rsp payload */
  169. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  170. if (!mp) {
  171. if (mlist)
  172. lpfc_free_ct_rsp(phba, mlist);
  173. return NULL;
  174. }
  175. INIT_LIST_HEAD(&mp->list);
  176. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  177. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  178. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  179. else
  180. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  181. if (!mp->virt) {
  182. kfree(mp);
  183. if (mlist)
  184. lpfc_free_ct_rsp(phba, mlist);
  185. return NULL;
  186. }
  187. /* Queue it to a linked list */
  188. if (!mlist)
  189. mlist = mp;
  190. else
  191. list_add_tail(&mp->list, &mlist->list);
  192. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  193. /* build buffer ptr list for IOCB */
  194. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  195. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  196. bpl->tus.f.bdeSize = (uint16_t) cnt;
  197. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  198. bpl++;
  199. i++;
  200. size -= cnt;
  201. }
  202. *entries = i;
  203. return mlist;
  204. }
  205. int
  206. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  207. {
  208. struct lpfc_dmabuf *buf_ptr;
  209. if (ctiocb->context_un.ndlp) {
  210. lpfc_nlp_put(ctiocb->context_un.ndlp);
  211. ctiocb->context_un.ndlp = NULL;
  212. }
  213. if (ctiocb->context1) {
  214. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
  215. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  216. kfree(buf_ptr);
  217. ctiocb->context1 = NULL;
  218. }
  219. if (ctiocb->context2) {
  220. lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
  221. ctiocb->context2 = NULL;
  222. }
  223. if (ctiocb->context3) {
  224. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
  225. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  226. kfree(buf_ptr);
  227. ctiocb->context1 = NULL;
  228. }
  229. lpfc_sli_release_iocbq(phba, ctiocb);
  230. return 0;
  231. }
  232. static int
  233. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  234. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  235. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  236. struct lpfc_iocbq *),
  237. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  238. uint32_t tmo, uint8_t retry)
  239. {
  240. struct lpfc_hba *phba = vport->phba;
  241. IOCB_t *icmd;
  242. struct lpfc_iocbq *geniocb;
  243. int rc;
  244. /* Allocate buffer for command iocb */
  245. geniocb = lpfc_sli_get_iocbq(phba);
  246. if (geniocb == NULL)
  247. return 1;
  248. icmd = &geniocb->iocb;
  249. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  250. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  251. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  252. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  253. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
  254. if (usr_flg)
  255. geniocb->context3 = NULL;
  256. else
  257. geniocb->context3 = (uint8_t *) bmp;
  258. /* Save for completion so we can release these resources */
  259. geniocb->context1 = (uint8_t *) inp;
  260. geniocb->context2 = (uint8_t *) outp;
  261. geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
  262. /* Fill in payload, bp points to frame payload */
  263. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  264. /* Fill in rest of iocb */
  265. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  266. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  267. icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
  268. icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
  269. if (!tmo) {
  270. /* FC spec states we need 3 * ratov for CT requests */
  271. tmo = (3 * phba->fc_ratov);
  272. }
  273. icmd->ulpTimeout = tmo;
  274. icmd->ulpBdeCount = 1;
  275. icmd->ulpLe = 1;
  276. icmd->ulpClass = CLASS3;
  277. icmd->ulpContext = ndlp->nlp_rpi;
  278. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  279. /* For GEN_REQUEST64_CR, use the RPI */
  280. icmd->ulpCt_h = 0;
  281. icmd->ulpCt_l = 0;
  282. }
  283. /* Issue GEN REQ IOCB for NPORT <did> */
  284. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  285. "0119 Issue GEN REQ IOCB to NPORT x%x "
  286. "Data: x%x x%x\n",
  287. ndlp->nlp_DID, icmd->ulpIoTag,
  288. vport->port_state);
  289. geniocb->iocb_cmpl = cmpl;
  290. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  291. geniocb->vport = vport;
  292. geniocb->retry = retry;
  293. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  294. if (rc == IOCB_ERROR) {
  295. lpfc_sli_release_iocbq(phba, geniocb);
  296. return 1;
  297. }
  298. return 0;
  299. }
  300. static int
  301. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  302. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  303. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  304. struct lpfc_iocbq *),
  305. uint32_t rsp_size, uint8_t retry)
  306. {
  307. struct lpfc_hba *phba = vport->phba;
  308. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  309. struct lpfc_dmabuf *outmp;
  310. int cnt = 0, status;
  311. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  312. CommandResponse.bits.CmdRsp;
  313. bpl++; /* Skip past ct request */
  314. /* Put buffer(s) for ct rsp in bpl */
  315. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  316. if (!outmp)
  317. return -ENOMEM;
  318. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  319. cnt+1, 0, retry);
  320. if (status) {
  321. lpfc_free_ct_rsp(phba, outmp);
  322. return -ENOMEM;
  323. }
  324. return 0;
  325. }
  326. struct lpfc_vport *
  327. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  328. struct lpfc_vport *vport_curr;
  329. unsigned long flags;
  330. spin_lock_irqsave(&phba->hbalock, flags);
  331. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  332. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  333. spin_unlock_irqrestore(&phba->hbalock, flags);
  334. return vport_curr;
  335. }
  336. }
  337. spin_unlock_irqrestore(&phba->hbalock, flags);
  338. return NULL;
  339. }
  340. static int
  341. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  342. {
  343. struct lpfc_hba *phba = vport->phba;
  344. struct lpfc_sli_ct_request *Response =
  345. (struct lpfc_sli_ct_request *) mp->virt;
  346. struct lpfc_nodelist *ndlp = NULL;
  347. struct lpfc_dmabuf *mlast, *next_mp;
  348. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  349. uint32_t Did, CTentry;
  350. int Cnt;
  351. struct list_head head;
  352. lpfc_set_disctmo(vport);
  353. vport->num_disc_nodes = 0;
  354. vport->fc_ns_retry = 0;
  355. list_add_tail(&head, &mp->list);
  356. list_for_each_entry_safe(mp, next_mp, &head, list) {
  357. mlast = mp;
  358. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  359. Size -= Cnt;
  360. if (!ctptr) {
  361. ctptr = (uint32_t *) mlast->virt;
  362. } else
  363. Cnt -= 16; /* subtract length of CT header */
  364. /* Loop through entire NameServer list of DIDs */
  365. while (Cnt >= sizeof (uint32_t)) {
  366. /* Get next DID from NameServer List */
  367. CTentry = *ctptr++;
  368. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  369. ndlp = NULL;
  370. /*
  371. * Check for rscn processing or not
  372. * To conserve rpi's, filter out addresses for other
  373. * vports on the same physical HBAs.
  374. */
  375. if ((Did != vport->fc_myDID) &&
  376. ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
  377. vport->cfg_peer_port_login)) {
  378. if ((vport->port_type != LPFC_NPIV_PORT) ||
  379. (!(vport->ct_flags & FC_CT_RFF_ID)) ||
  380. (!vport->cfg_restrict_login)) {
  381. ndlp = lpfc_setup_disc_node(vport, Did);
  382. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  383. lpfc_debugfs_disc_trc(vport,
  384. LPFC_DISC_TRC_CT,
  385. "Parse GID_FTrsp: "
  386. "did:x%x flg:x%x x%x",
  387. Did, ndlp->nlp_flag,
  388. vport->fc_flag);
  389. lpfc_printf_vlog(vport,
  390. KERN_INFO,
  391. LOG_DISCOVERY,
  392. "0238 Process "
  393. "x%x NameServer Rsp"
  394. "Data: x%x x%x x%x\n",
  395. Did, ndlp->nlp_flag,
  396. vport->fc_flag,
  397. vport->fc_rscn_id_cnt);
  398. } else {
  399. lpfc_debugfs_disc_trc(vport,
  400. LPFC_DISC_TRC_CT,
  401. "Skip1 GID_FTrsp: "
  402. "did:x%x flg:x%x cnt:%d",
  403. Did, vport->fc_flag,
  404. vport->fc_rscn_id_cnt);
  405. lpfc_printf_vlog(vport,
  406. KERN_INFO,
  407. LOG_DISCOVERY,
  408. "0239 Skip x%x "
  409. "NameServer Rsp Data: "
  410. "x%x x%x\n",
  411. Did, vport->fc_flag,
  412. vport->fc_rscn_id_cnt);
  413. }
  414. } else {
  415. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  416. (lpfc_rscn_payload_check(vport, Did))) {
  417. lpfc_debugfs_disc_trc(vport,
  418. LPFC_DISC_TRC_CT,
  419. "Query GID_FTrsp: "
  420. "did:x%x flg:x%x cnt:%d",
  421. Did, vport->fc_flag,
  422. vport->fc_rscn_id_cnt);
  423. /* This NPortID was previously
  424. * a FCP target, * Don't even
  425. * bother to send GFF_ID.
  426. */
  427. ndlp = lpfc_findnode_did(vport,
  428. Did);
  429. if (ndlp &&
  430. NLP_CHK_NODE_ACT(ndlp)
  431. && (ndlp->nlp_type &
  432. NLP_FCP_TARGET))
  433. lpfc_setup_disc_node
  434. (vport, Did);
  435. else if (lpfc_ns_cmd(vport,
  436. SLI_CTNS_GFF_ID,
  437. 0, Did) == 0)
  438. vport->num_disc_nodes++;
  439. }
  440. else {
  441. lpfc_debugfs_disc_trc(vport,
  442. LPFC_DISC_TRC_CT,
  443. "Skip2 GID_FTrsp: "
  444. "did:x%x flg:x%x cnt:%d",
  445. Did, vport->fc_flag,
  446. vport->fc_rscn_id_cnt);
  447. lpfc_printf_vlog(vport,
  448. KERN_INFO,
  449. LOG_DISCOVERY,
  450. "0245 Skip x%x "
  451. "NameServer Rsp Data: "
  452. "x%x x%x\n",
  453. Did, vport->fc_flag,
  454. vport->fc_rscn_id_cnt);
  455. }
  456. }
  457. }
  458. if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
  459. goto nsout1;
  460. Cnt -= sizeof (uint32_t);
  461. }
  462. ctptr = NULL;
  463. }
  464. nsout1:
  465. list_del(&head);
  466. return 0;
  467. }
  468. static void
  469. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  470. struct lpfc_iocbq *rspiocb)
  471. {
  472. struct lpfc_vport *vport = cmdiocb->vport;
  473. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  474. IOCB_t *irsp;
  475. struct lpfc_dmabuf *bmp;
  476. struct lpfc_dmabuf *outp;
  477. struct lpfc_sli_ct_request *CTrsp;
  478. struct lpfc_nodelist *ndlp;
  479. int rc;
  480. /* First save ndlp, before we overwrite it */
  481. ndlp = cmdiocb->context_un.ndlp;
  482. /* we pass cmdiocb to state machine which needs rspiocb as well */
  483. cmdiocb->context_un.rsp_iocb = rspiocb;
  484. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  485. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  486. irsp = &rspiocb->iocb;
  487. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  488. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  489. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  490. /* Don't bother processing response if vport is being torn down. */
  491. if (vport->load_flag & FC_UNLOADING) {
  492. if (vport->fc_flag & FC_RSCN_MODE)
  493. lpfc_els_flush_rscn(vport);
  494. goto out;
  495. }
  496. if (lpfc_els_chk_latt(vport)) {
  497. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  498. "0216 Link event during NS query\n");
  499. if (vport->fc_flag & FC_RSCN_MODE)
  500. lpfc_els_flush_rscn(vport);
  501. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  502. goto out;
  503. }
  504. if (lpfc_error_lost_link(irsp)) {
  505. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  506. "0226 NS query failed due to link event\n");
  507. if (vport->fc_flag & FC_RSCN_MODE)
  508. lpfc_els_flush_rscn(vport);
  509. goto out;
  510. }
  511. if (irsp->ulpStatus) {
  512. /* Check for retry */
  513. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  514. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  515. irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
  516. vport->fc_ns_retry++;
  517. /* CT command is being retried */
  518. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  519. vport->fc_ns_retry, 0);
  520. if (rc == 0)
  521. goto out;
  522. }
  523. if (vport->fc_flag & FC_RSCN_MODE)
  524. lpfc_els_flush_rscn(vport);
  525. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  526. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  527. "0257 GID_FT Query error: 0x%x 0x%x\n",
  528. irsp->ulpStatus, vport->fc_ns_retry);
  529. } else {
  530. /* Good status, continue checking */
  531. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  532. if (CTrsp->CommandResponse.bits.CmdRsp ==
  533. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  534. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  535. "0208 NameServer Rsp Data: x%x\n",
  536. vport->fc_flag);
  537. lpfc_ns_rsp(vport, outp,
  538. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  539. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  540. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  541. /* NameServer Rsp Error */
  542. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  543. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  544. lpfc_printf_vlog(vport, KERN_INFO,
  545. LOG_DISCOVERY,
  546. "0269 No NameServer Entries "
  547. "Data: x%x x%x x%x x%x\n",
  548. CTrsp->CommandResponse.bits.CmdRsp,
  549. (uint32_t) CTrsp->ReasonCode,
  550. (uint32_t) CTrsp->Explanation,
  551. vport->fc_flag);
  552. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  553. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  554. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  555. (uint32_t) CTrsp->ReasonCode,
  556. (uint32_t) CTrsp->Explanation);
  557. } else {
  558. lpfc_printf_vlog(vport, KERN_INFO,
  559. LOG_DISCOVERY,
  560. "0240 NameServer Rsp Error "
  561. "Data: x%x x%x x%x x%x\n",
  562. CTrsp->CommandResponse.bits.CmdRsp,
  563. (uint32_t) CTrsp->ReasonCode,
  564. (uint32_t) CTrsp->Explanation,
  565. vport->fc_flag);
  566. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  567. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  568. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  569. (uint32_t) CTrsp->ReasonCode,
  570. (uint32_t) CTrsp->Explanation);
  571. }
  572. } else {
  573. /* NameServer Rsp Error */
  574. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  575. "0241 NameServer Rsp Error "
  576. "Data: x%x x%x x%x x%x\n",
  577. CTrsp->CommandResponse.bits.CmdRsp,
  578. (uint32_t) CTrsp->ReasonCode,
  579. (uint32_t) CTrsp->Explanation,
  580. vport->fc_flag);
  581. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  582. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  583. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  584. (uint32_t) CTrsp->ReasonCode,
  585. (uint32_t) CTrsp->Explanation);
  586. }
  587. }
  588. /* Link up / RSCN discovery */
  589. if (vport->num_disc_nodes == 0) {
  590. /*
  591. * The driver has cycled through all Nports in the RSCN payload.
  592. * Complete the handling by cleaning up and marking the
  593. * current driver state.
  594. */
  595. if (vport->port_state >= LPFC_DISC_AUTH) {
  596. if (vport->fc_flag & FC_RSCN_MODE) {
  597. lpfc_els_flush_rscn(vport);
  598. spin_lock_irq(shost->host_lock);
  599. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  600. spin_unlock_irq(shost->host_lock);
  601. }
  602. else
  603. lpfc_els_flush_rscn(vport);
  604. }
  605. lpfc_disc_start(vport);
  606. }
  607. out:
  608. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  609. lpfc_ct_free_iocb(phba, cmdiocb);
  610. return;
  611. }
  612. static void
  613. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  614. struct lpfc_iocbq *rspiocb)
  615. {
  616. struct lpfc_vport *vport = cmdiocb->vport;
  617. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  618. IOCB_t *irsp = &rspiocb->iocb;
  619. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  620. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  621. struct lpfc_sli_ct_request *CTrsp;
  622. int did, rc, retry;
  623. uint8_t fbits;
  624. struct lpfc_nodelist *ndlp;
  625. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  626. did = be32_to_cpu(did);
  627. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  628. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  629. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  630. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  631. /* Good status, continue checking */
  632. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  633. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  634. if (CTrsp->CommandResponse.bits.CmdRsp ==
  635. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  636. if ((fbits & FC4_FEATURE_INIT) &&
  637. !(fbits & FC4_FEATURE_TARGET)) {
  638. lpfc_printf_vlog(vport, KERN_INFO,
  639. LOG_DISCOVERY,
  640. "0270 Skip x%x GFF "
  641. "NameServer Rsp Data: (init) "
  642. "x%x x%x\n", did, fbits,
  643. vport->fc_rscn_id_cnt);
  644. goto out;
  645. }
  646. }
  647. }
  648. else {
  649. /* Check for retry */
  650. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  651. retry = 1;
  652. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  653. switch (irsp->un.ulpWord[4]) {
  654. case IOERR_NO_RESOURCES:
  655. /* We don't increment the retry
  656. * count for this case.
  657. */
  658. break;
  659. case IOERR_LINK_DOWN:
  660. case IOERR_SLI_ABORTED:
  661. case IOERR_SLI_DOWN:
  662. retry = 0;
  663. break;
  664. default:
  665. cmdiocb->retry++;
  666. }
  667. }
  668. else
  669. cmdiocb->retry++;
  670. if (retry) {
  671. /* CT command is being retried */
  672. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  673. cmdiocb->retry, did);
  674. if (rc == 0) {
  675. /* success */
  676. lpfc_ct_free_iocb(phba, cmdiocb);
  677. return;
  678. }
  679. }
  680. }
  681. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  682. "0267 NameServer GFF Rsp "
  683. "x%x Error (%d %d) Data: x%x x%x\n",
  684. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  685. vport->fc_flag, vport->fc_rscn_id_cnt);
  686. }
  687. /* This is a target port, unregistered port, or the GFF_ID failed */
  688. ndlp = lpfc_setup_disc_node(vport, did);
  689. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  690. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  691. "0242 Process x%x GFF "
  692. "NameServer Rsp Data: x%x x%x x%x\n",
  693. did, ndlp->nlp_flag, vport->fc_flag,
  694. vport->fc_rscn_id_cnt);
  695. } else {
  696. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  697. "0243 Skip x%x GFF "
  698. "NameServer Rsp Data: x%x x%x\n", did,
  699. vport->fc_flag, vport->fc_rscn_id_cnt);
  700. }
  701. out:
  702. /* Link up / RSCN discovery */
  703. if (vport->num_disc_nodes)
  704. vport->num_disc_nodes--;
  705. if (vport->num_disc_nodes == 0) {
  706. /*
  707. * The driver has cycled through all Nports in the RSCN payload.
  708. * Complete the handling by cleaning up and marking the
  709. * current driver state.
  710. */
  711. if (vport->port_state >= LPFC_DISC_AUTH) {
  712. if (vport->fc_flag & FC_RSCN_MODE) {
  713. lpfc_els_flush_rscn(vport);
  714. spin_lock_irq(shost->host_lock);
  715. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  716. spin_unlock_irq(shost->host_lock);
  717. }
  718. else
  719. lpfc_els_flush_rscn(vport);
  720. }
  721. lpfc_disc_start(vport);
  722. }
  723. lpfc_ct_free_iocb(phba, cmdiocb);
  724. return;
  725. }
  726. static void
  727. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  728. struct lpfc_iocbq *rspiocb)
  729. {
  730. struct lpfc_vport *vport = cmdiocb->vport;
  731. struct lpfc_dmabuf *inp;
  732. struct lpfc_dmabuf *outp;
  733. IOCB_t *irsp;
  734. struct lpfc_sli_ct_request *CTrsp;
  735. struct lpfc_nodelist *ndlp;
  736. int cmdcode, rc;
  737. uint8_t retry;
  738. uint32_t latt;
  739. /* First save ndlp, before we overwrite it */
  740. ndlp = cmdiocb->context_un.ndlp;
  741. /* we pass cmdiocb to state machine which needs rspiocb as well */
  742. cmdiocb->context_un.rsp_iocb = rspiocb;
  743. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  744. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  745. irsp = &rspiocb->iocb;
  746. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  747. CommandResponse.bits.CmdRsp);
  748. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  749. latt = lpfc_els_chk_latt(vport);
  750. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  751. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  752. "0209 CT Request completes, latt %d, "
  753. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  754. latt, irsp->ulpStatus,
  755. CTrsp->CommandResponse.bits.CmdRsp,
  756. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  757. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  758. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  759. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  760. if (irsp->ulpStatus) {
  761. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  762. "0268 NS cmd %x Error (%d %d)\n",
  763. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  764. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  765. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  766. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
  767. goto out;
  768. retry = cmdiocb->retry;
  769. if (retry >= LPFC_MAX_NS_RETRY)
  770. goto out;
  771. retry++;
  772. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  773. "0250 Retrying NS cmd %x\n", cmdcode);
  774. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  775. if (rc == 0)
  776. goto out;
  777. }
  778. out:
  779. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  780. lpfc_ct_free_iocb(phba, cmdiocb);
  781. return;
  782. }
  783. static void
  784. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  785. struct lpfc_iocbq *rspiocb)
  786. {
  787. IOCB_t *irsp = &rspiocb->iocb;
  788. struct lpfc_vport *vport = cmdiocb->vport;
  789. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  790. struct lpfc_dmabuf *outp;
  791. struct lpfc_sli_ct_request *CTrsp;
  792. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  793. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  794. if (CTrsp->CommandResponse.bits.CmdRsp ==
  795. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  796. vport->ct_flags |= FC_CT_RFT_ID;
  797. }
  798. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  799. return;
  800. }
  801. static void
  802. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  803. struct lpfc_iocbq *rspiocb)
  804. {
  805. IOCB_t *irsp = &rspiocb->iocb;
  806. struct lpfc_vport *vport = cmdiocb->vport;
  807. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  808. struct lpfc_dmabuf *outp;
  809. struct lpfc_sli_ct_request *CTrsp;
  810. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  811. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  812. if (CTrsp->CommandResponse.bits.CmdRsp ==
  813. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  814. vport->ct_flags |= FC_CT_RNN_ID;
  815. }
  816. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  817. return;
  818. }
  819. static void
  820. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  821. struct lpfc_iocbq *rspiocb)
  822. {
  823. IOCB_t *irsp = &rspiocb->iocb;
  824. struct lpfc_vport *vport = cmdiocb->vport;
  825. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  826. struct lpfc_dmabuf *outp;
  827. struct lpfc_sli_ct_request *CTrsp;
  828. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  829. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  830. if (CTrsp->CommandResponse.bits.CmdRsp ==
  831. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  832. vport->ct_flags |= FC_CT_RSPN_ID;
  833. }
  834. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  835. return;
  836. }
  837. static void
  838. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  839. struct lpfc_iocbq *rspiocb)
  840. {
  841. IOCB_t *irsp = &rspiocb->iocb;
  842. struct lpfc_vport *vport = cmdiocb->vport;
  843. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  844. struct lpfc_dmabuf *outp;
  845. struct lpfc_sli_ct_request *CTrsp;
  846. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  847. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  848. if (CTrsp->CommandResponse.bits.CmdRsp ==
  849. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  850. vport->ct_flags |= FC_CT_RSNN_NN;
  851. }
  852. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  853. return;
  854. }
  855. static void
  856. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  857. struct lpfc_iocbq *rspiocb)
  858. {
  859. struct lpfc_vport *vport = cmdiocb->vport;
  860. /* even if it fails we will act as though it succeeded. */
  861. vport->ct_flags = 0;
  862. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  863. return;
  864. }
  865. static void
  866. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  867. struct lpfc_iocbq *rspiocb)
  868. {
  869. IOCB_t *irsp = &rspiocb->iocb;
  870. struct lpfc_vport *vport = cmdiocb->vport;
  871. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  872. struct lpfc_dmabuf *outp;
  873. struct lpfc_sli_ct_request *CTrsp;
  874. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  875. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  876. if (CTrsp->CommandResponse.bits.CmdRsp ==
  877. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  878. vport->ct_flags |= FC_CT_RFF_ID;
  879. }
  880. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  881. return;
  882. }
  883. int
  884. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  885. size_t size)
  886. {
  887. int n;
  888. uint8_t *wwn = vport->phba->wwpn;
  889. n = snprintf(symbol, size,
  890. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  891. wwn[0], wwn[1], wwn[2], wwn[3],
  892. wwn[4], wwn[5], wwn[6], wwn[7]);
  893. if (vport->port_type == LPFC_PHYSICAL_PORT)
  894. return n;
  895. if (n < size)
  896. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  897. if (n < size &&
  898. strlen(vport->fc_vport->symbolic_name))
  899. n += snprintf(symbol + n, size - n, " VName-%s",
  900. vport->fc_vport->symbolic_name);
  901. return n;
  902. }
  903. int
  904. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  905. size_t size)
  906. {
  907. char fwrev[16];
  908. int n;
  909. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  910. n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
  911. vport->phba->ModelName, fwrev, lpfc_release_version);
  912. return n;
  913. }
  914. /*
  915. * lpfc_ns_cmd
  916. * Description:
  917. * Issue Cmd to NameServer
  918. * SLI_CTNS_GID_FT
  919. * LI_CTNS_RFT_ID
  920. */
  921. int
  922. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  923. uint8_t retry, uint32_t context)
  924. {
  925. struct lpfc_nodelist * ndlp;
  926. struct lpfc_hba *phba = vport->phba;
  927. struct lpfc_dmabuf *mp, *bmp;
  928. struct lpfc_sli_ct_request *CtReq;
  929. struct ulp_bde64 *bpl;
  930. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  931. struct lpfc_iocbq *) = NULL;
  932. uint32_t rsp_size = 1024;
  933. size_t size;
  934. int rc = 0;
  935. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  936. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  937. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  938. rc=1;
  939. goto ns_cmd_exit;
  940. }
  941. /* fill in BDEs for command */
  942. /* Allocate buffer for command payload */
  943. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  944. if (!mp) {
  945. rc=2;
  946. goto ns_cmd_exit;
  947. }
  948. INIT_LIST_HEAD(&mp->list);
  949. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  950. if (!mp->virt) {
  951. rc=3;
  952. goto ns_cmd_free_mp;
  953. }
  954. /* Allocate buffer for Buffer ptr list */
  955. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  956. if (!bmp) {
  957. rc=4;
  958. goto ns_cmd_free_mpvirt;
  959. }
  960. INIT_LIST_HEAD(&bmp->list);
  961. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  962. if (!bmp->virt) {
  963. rc=5;
  964. goto ns_cmd_free_bmp;
  965. }
  966. /* NameServer Req */
  967. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  968. "0236 NameServer Req Data: x%x x%x x%x\n",
  969. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
  970. bpl = (struct ulp_bde64 *) bmp->virt;
  971. memset(bpl, 0, sizeof(struct ulp_bde64));
  972. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  973. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  974. bpl->tus.f.bdeFlags = 0;
  975. if (cmdcode == SLI_CTNS_GID_FT)
  976. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  977. else if (cmdcode == SLI_CTNS_GFF_ID)
  978. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  979. else if (cmdcode == SLI_CTNS_RFT_ID)
  980. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  981. else if (cmdcode == SLI_CTNS_RNN_ID)
  982. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  983. else if (cmdcode == SLI_CTNS_RSPN_ID)
  984. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  985. else if (cmdcode == SLI_CTNS_RSNN_NN)
  986. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  987. else if (cmdcode == SLI_CTNS_DA_ID)
  988. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  989. else if (cmdcode == SLI_CTNS_RFF_ID)
  990. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  991. else
  992. bpl->tus.f.bdeSize = 0;
  993. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  994. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  995. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  996. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  997. CtReq->RevisionId.bits.InId = 0;
  998. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  999. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1000. CtReq->CommandResponse.bits.Size = 0;
  1001. switch (cmdcode) {
  1002. case SLI_CTNS_GID_FT:
  1003. CtReq->CommandResponse.bits.CmdRsp =
  1004. be16_to_cpu(SLI_CTNS_GID_FT);
  1005. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  1006. if (vport->port_state < LPFC_NS_QRY)
  1007. vport->port_state = LPFC_NS_QRY;
  1008. lpfc_set_disctmo(vport);
  1009. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1010. rsp_size = FC_MAX_NS_RSP;
  1011. break;
  1012. case SLI_CTNS_GFF_ID:
  1013. CtReq->CommandResponse.bits.CmdRsp =
  1014. be16_to_cpu(SLI_CTNS_GFF_ID);
  1015. CtReq->un.gff.PortId = cpu_to_be32(context);
  1016. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1017. break;
  1018. case SLI_CTNS_RFT_ID:
  1019. vport->ct_flags &= ~FC_CT_RFT_ID;
  1020. CtReq->CommandResponse.bits.CmdRsp =
  1021. be16_to_cpu(SLI_CTNS_RFT_ID);
  1022. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1023. CtReq->un.rft.fcpReg = 1;
  1024. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1025. break;
  1026. case SLI_CTNS_RNN_ID:
  1027. vport->ct_flags &= ~FC_CT_RNN_ID;
  1028. CtReq->CommandResponse.bits.CmdRsp =
  1029. be16_to_cpu(SLI_CTNS_RNN_ID);
  1030. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1031. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1032. sizeof (struct lpfc_name));
  1033. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1034. break;
  1035. case SLI_CTNS_RSPN_ID:
  1036. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1037. CtReq->CommandResponse.bits.CmdRsp =
  1038. be16_to_cpu(SLI_CTNS_RSPN_ID);
  1039. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1040. size = sizeof(CtReq->un.rspn.symbname);
  1041. CtReq->un.rspn.len =
  1042. lpfc_vport_symbolic_port_name(vport,
  1043. CtReq->un.rspn.symbname, size);
  1044. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1045. break;
  1046. case SLI_CTNS_RSNN_NN:
  1047. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1048. CtReq->CommandResponse.bits.CmdRsp =
  1049. be16_to_cpu(SLI_CTNS_RSNN_NN);
  1050. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1051. sizeof (struct lpfc_name));
  1052. size = sizeof(CtReq->un.rsnn.symbname);
  1053. CtReq->un.rsnn.len =
  1054. lpfc_vport_symbolic_node_name(vport,
  1055. CtReq->un.rsnn.symbname, size);
  1056. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1057. break;
  1058. case SLI_CTNS_DA_ID:
  1059. /* Implement DA_ID Nameserver request */
  1060. CtReq->CommandResponse.bits.CmdRsp =
  1061. be16_to_cpu(SLI_CTNS_DA_ID);
  1062. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1063. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1064. break;
  1065. case SLI_CTNS_RFF_ID:
  1066. vport->ct_flags &= ~FC_CT_RFF_ID;
  1067. CtReq->CommandResponse.bits.CmdRsp =
  1068. be16_to_cpu(SLI_CTNS_RFF_ID);
  1069. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);;
  1070. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1071. CtReq->un.rff.type_code = FC_FCP_DATA;
  1072. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1073. break;
  1074. }
  1075. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1076. * to hold ndlp reference for the corresponding callback function.
  1077. */
  1078. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1079. /* On success, The cmpl function will free the buffers */
  1080. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1081. "Issue CT cmd: cmd:x%x did:x%x",
  1082. cmdcode, ndlp->nlp_DID, 0);
  1083. return 0;
  1084. }
  1085. rc=6;
  1086. /* Decrement ndlp reference count to release ndlp reference held
  1087. * for the failed command's callback function.
  1088. */
  1089. lpfc_nlp_put(ndlp);
  1090. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1091. ns_cmd_free_bmp:
  1092. kfree(bmp);
  1093. ns_cmd_free_mpvirt:
  1094. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1095. ns_cmd_free_mp:
  1096. kfree(mp);
  1097. ns_cmd_exit:
  1098. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1099. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1100. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1101. return 1;
  1102. }
  1103. static void
  1104. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1105. struct lpfc_iocbq * rspiocb)
  1106. {
  1107. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1108. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1109. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1110. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1111. struct lpfc_nodelist *ndlp;
  1112. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1113. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1114. struct lpfc_vport *vport = cmdiocb->vport;
  1115. IOCB_t *irsp = &rspiocb->iocb;
  1116. uint32_t latt;
  1117. latt = lpfc_els_chk_latt(vport);
  1118. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1119. "FDMI cmpl: status:x%x/x%x latt:%d",
  1120. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1121. if (latt || irsp->ulpStatus) {
  1122. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1123. "0229 FDMI cmd %04x failed, latt = %d "
  1124. "ulpStatus: x%x, rid x%x\n",
  1125. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1126. irsp->un.ulpWord[4]);
  1127. lpfc_ct_free_iocb(phba, cmdiocb);
  1128. return;
  1129. }
  1130. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1131. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1132. goto fail_out;
  1133. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  1134. /* FDMI rsp failed */
  1135. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1136. "0220 FDMI rsp failed Data: x%x\n",
  1137. be16_to_cpu(fdmi_cmd));
  1138. }
  1139. switch (be16_to_cpu(fdmi_cmd)) {
  1140. case SLI_MGMT_RHBA:
  1141. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  1142. break;
  1143. case SLI_MGMT_RPA:
  1144. break;
  1145. case SLI_MGMT_DHBA:
  1146. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  1147. break;
  1148. case SLI_MGMT_DPRT:
  1149. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  1150. break;
  1151. }
  1152. fail_out:
  1153. lpfc_ct_free_iocb(phba, cmdiocb);
  1154. return;
  1155. }
  1156. int
  1157. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  1158. {
  1159. struct lpfc_hba *phba = vport->phba;
  1160. struct lpfc_dmabuf *mp, *bmp;
  1161. struct lpfc_sli_ct_request *CtReq;
  1162. struct ulp_bde64 *bpl;
  1163. uint32_t size;
  1164. REG_HBA *rh;
  1165. PORT_ENTRY *pe;
  1166. REG_PORT_ATTRIBUTE *pab;
  1167. ATTRIBUTE_BLOCK *ab;
  1168. ATTRIBUTE_ENTRY *ae;
  1169. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1170. struct lpfc_iocbq *);
  1171. /* fill in BDEs for command */
  1172. /* Allocate buffer for command payload */
  1173. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1174. if (!mp)
  1175. goto fdmi_cmd_exit;
  1176. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  1177. if (!mp->virt)
  1178. goto fdmi_cmd_free_mp;
  1179. /* Allocate buffer for Buffer ptr list */
  1180. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1181. if (!bmp)
  1182. goto fdmi_cmd_free_mpvirt;
  1183. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  1184. if (!bmp->virt)
  1185. goto fdmi_cmd_free_bmp;
  1186. INIT_LIST_HEAD(&mp->list);
  1187. INIT_LIST_HEAD(&bmp->list);
  1188. /* FDMI request */
  1189. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1190. "0218 FDMI Request Data: x%x x%x x%x\n",
  1191. vport->fc_flag, vport->port_state, cmdcode);
  1192. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1193. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1194. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1195. CtReq->RevisionId.bits.InId = 0;
  1196. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  1197. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  1198. size = 0;
  1199. switch (cmdcode) {
  1200. case SLI_MGMT_RHBA:
  1201. {
  1202. lpfc_vpd_t *vp = &phba->vpd;
  1203. uint32_t i, j, incr;
  1204. int len;
  1205. CtReq->CommandResponse.bits.CmdRsp =
  1206. be16_to_cpu(SLI_MGMT_RHBA);
  1207. CtReq->CommandResponse.bits.Size = 0;
  1208. rh = (REG_HBA *) & CtReq->un.PortID;
  1209. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  1210. sizeof (struct lpfc_name));
  1211. /* One entry (port) per adapter */
  1212. rh->rpl.EntryCnt = be32_to_cpu(1);
  1213. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  1214. sizeof (struct lpfc_name));
  1215. /* point to the HBA attribute block */
  1216. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  1217. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  1218. ab->EntryCnt = 0;
  1219. /* Point to the beginning of the first HBA attribute
  1220. entry */
  1221. /* #1 HBA attribute entry */
  1222. size += FOURBYTES;
  1223. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1224. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  1225. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  1226. + sizeof (struct lpfc_name));
  1227. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1228. sizeof (struct lpfc_name));
  1229. ab->EntryCnt++;
  1230. size += FOURBYTES + sizeof (struct lpfc_name);
  1231. /* #2 HBA attribute entry */
  1232. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1233. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  1234. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  1235. len = strlen(ae->un.Manufacturer);
  1236. len += (len & 3) ? (4 - (len & 3)) : 4;
  1237. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1238. ab->EntryCnt++;
  1239. size += FOURBYTES + len;
  1240. /* #3 HBA attribute entry */
  1241. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1242. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  1243. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  1244. len = strlen(ae->un.SerialNumber);
  1245. len += (len & 3) ? (4 - (len & 3)) : 4;
  1246. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1247. ab->EntryCnt++;
  1248. size += FOURBYTES + len;
  1249. /* #4 HBA attribute entry */
  1250. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1251. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  1252. strcpy(ae->un.Model, phba->ModelName);
  1253. len = strlen(ae->un.Model);
  1254. len += (len & 3) ? (4 - (len & 3)) : 4;
  1255. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1256. ab->EntryCnt++;
  1257. size += FOURBYTES + len;
  1258. /* #5 HBA attribute entry */
  1259. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1260. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  1261. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  1262. len = strlen(ae->un.ModelDescription);
  1263. len += (len & 3) ? (4 - (len & 3)) : 4;
  1264. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1265. ab->EntryCnt++;
  1266. size += FOURBYTES + len;
  1267. /* #6 HBA attribute entry */
  1268. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1269. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  1270. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  1271. /* Convert JEDEC ID to ascii for hardware version */
  1272. incr = vp->rev.biuRev;
  1273. for (i = 0; i < 8; i++) {
  1274. j = (incr & 0xf);
  1275. if (j <= 9)
  1276. ae->un.HardwareVersion[7 - i] =
  1277. (char)((uint8_t) 0x30 +
  1278. (uint8_t) j);
  1279. else
  1280. ae->un.HardwareVersion[7 - i] =
  1281. (char)((uint8_t) 0x61 +
  1282. (uint8_t) (j - 10));
  1283. incr = (incr >> 4);
  1284. }
  1285. ab->EntryCnt++;
  1286. size += FOURBYTES + 8;
  1287. /* #7 HBA attribute entry */
  1288. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1289. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  1290. strcpy(ae->un.DriverVersion, lpfc_release_version);
  1291. len = strlen(ae->un.DriverVersion);
  1292. len += (len & 3) ? (4 - (len & 3)) : 4;
  1293. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1294. ab->EntryCnt++;
  1295. size += FOURBYTES + len;
  1296. /* #8 HBA attribute entry */
  1297. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1298. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  1299. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  1300. len = strlen(ae->un.OptionROMVersion);
  1301. len += (len & 3) ? (4 - (len & 3)) : 4;
  1302. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1303. ab->EntryCnt++;
  1304. size += FOURBYTES + len;
  1305. /* #9 HBA attribute entry */
  1306. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1307. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  1308. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  1309. 1);
  1310. len = strlen(ae->un.FirmwareVersion);
  1311. len += (len & 3) ? (4 - (len & 3)) : 4;
  1312. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1313. ab->EntryCnt++;
  1314. size += FOURBYTES + len;
  1315. /* #10 HBA attribute entry */
  1316. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1317. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  1318. sprintf(ae->un.OsNameVersion, "%s %s %s",
  1319. init_utsname()->sysname,
  1320. init_utsname()->release,
  1321. init_utsname()->version);
  1322. len = strlen(ae->un.OsNameVersion);
  1323. len += (len & 3) ? (4 - (len & 3)) : 4;
  1324. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1325. ab->EntryCnt++;
  1326. size += FOURBYTES + len;
  1327. /* #11 HBA attribute entry */
  1328. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1329. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  1330. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1331. ae->un.MaxCTPayloadLen = (65 * 4096);
  1332. ab->EntryCnt++;
  1333. size += FOURBYTES + 4;
  1334. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  1335. /* Total size */
  1336. size = GID_REQUEST_SZ - 4 + size;
  1337. }
  1338. break;
  1339. case SLI_MGMT_RPA:
  1340. {
  1341. lpfc_vpd_t *vp;
  1342. struct serv_parm *hsp;
  1343. int len;
  1344. vp = &phba->vpd;
  1345. CtReq->CommandResponse.bits.CmdRsp =
  1346. be16_to_cpu(SLI_MGMT_RPA);
  1347. CtReq->CommandResponse.bits.Size = 0;
  1348. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  1349. size = sizeof (struct lpfc_name) + FOURBYTES;
  1350. memcpy((uint8_t *) & pab->PortName,
  1351. (uint8_t *) & vport->fc_sparam.portName,
  1352. sizeof (struct lpfc_name));
  1353. pab->ab.EntryCnt = 0;
  1354. /* #1 Port attribute entry */
  1355. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1356. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  1357. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  1358. ae->un.SupportFC4Types[2] = 1;
  1359. ae->un.SupportFC4Types[7] = 1;
  1360. pab->ab.EntryCnt++;
  1361. size += FOURBYTES + 32;
  1362. /* #2 Port attribute entry */
  1363. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1364. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  1365. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1366. ae->un.SupportSpeed = 0;
  1367. if (phba->lmt & LMT_10Gb)
  1368. ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
  1369. if (phba->lmt & LMT_8Gb)
  1370. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  1371. if (phba->lmt & LMT_4Gb)
  1372. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  1373. if (phba->lmt & LMT_2Gb)
  1374. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  1375. if (phba->lmt & LMT_1Gb)
  1376. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  1377. pab->ab.EntryCnt++;
  1378. size += FOURBYTES + 4;
  1379. /* #3 Port attribute entry */
  1380. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1381. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  1382. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1383. switch(phba->fc_linkspeed) {
  1384. case LA_1GHZ_LINK:
  1385. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  1386. break;
  1387. case LA_2GHZ_LINK:
  1388. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  1389. break;
  1390. case LA_4GHZ_LINK:
  1391. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  1392. break;
  1393. case LA_8GHZ_LINK:
  1394. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  1395. break;
  1396. case LA_10GHZ_LINK:
  1397. ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
  1398. break;
  1399. default:
  1400. ae->un.PortSpeed =
  1401. HBA_PORTSPEED_UNKNOWN;
  1402. break;
  1403. }
  1404. pab->ab.EntryCnt++;
  1405. size += FOURBYTES + 4;
  1406. /* #4 Port attribute entry */
  1407. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1408. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  1409. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1410. hsp = (struct serv_parm *) & vport->fc_sparam;
  1411. ae->un.MaxFrameSize =
  1412. (((uint32_t) hsp->cmn.
  1413. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  1414. bbRcvSizeLsb;
  1415. pab->ab.EntryCnt++;
  1416. size += FOURBYTES + 4;
  1417. /* #5 Port attribute entry */
  1418. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1419. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  1420. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  1421. len = strlen((char *)ae->un.OsDeviceName);
  1422. len += (len & 3) ? (4 - (len & 3)) : 4;
  1423. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1424. pab->ab.EntryCnt++;
  1425. size += FOURBYTES + len;
  1426. if (vport->cfg_fdmi_on == 2) {
  1427. /* #6 Port attribute entry */
  1428. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  1429. size);
  1430. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  1431. sprintf(ae->un.HostName, "%s",
  1432. init_utsname()->nodename);
  1433. len = strlen(ae->un.HostName);
  1434. len += (len & 3) ? (4 - (len & 3)) : 4;
  1435. ae->ad.bits.AttrLen =
  1436. be16_to_cpu(FOURBYTES + len);
  1437. pab->ab.EntryCnt++;
  1438. size += FOURBYTES + len;
  1439. }
  1440. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  1441. /* Total size */
  1442. size = GID_REQUEST_SZ - 4 + size;
  1443. }
  1444. break;
  1445. case SLI_MGMT_DHBA:
  1446. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  1447. CtReq->CommandResponse.bits.Size = 0;
  1448. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1449. memcpy((uint8_t *) & pe->PortName,
  1450. (uint8_t *) & vport->fc_sparam.portName,
  1451. sizeof (struct lpfc_name));
  1452. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1453. break;
  1454. case SLI_MGMT_DPRT:
  1455. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  1456. CtReq->CommandResponse.bits.Size = 0;
  1457. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1458. memcpy((uint8_t *) & pe->PortName,
  1459. (uint8_t *) & vport->fc_sparam.portName,
  1460. sizeof (struct lpfc_name));
  1461. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1462. break;
  1463. }
  1464. bpl = (struct ulp_bde64 *) bmp->virt;
  1465. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1466. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1467. bpl->tus.f.bdeFlags = 0;
  1468. bpl->tus.f.bdeSize = size;
  1469. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1470. cmpl = lpfc_cmpl_ct_cmd_fdmi;
  1471. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1472. * to hold ndlp reference for the corresponding callback function.
  1473. */
  1474. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
  1475. return 0;
  1476. /* Decrement ndlp reference count to release ndlp reference held
  1477. * for the failed command's callback function.
  1478. */
  1479. lpfc_nlp_put(ndlp);
  1480. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1481. fdmi_cmd_free_bmp:
  1482. kfree(bmp);
  1483. fdmi_cmd_free_mpvirt:
  1484. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1485. fdmi_cmd_free_mp:
  1486. kfree(mp);
  1487. fdmi_cmd_exit:
  1488. /* Issue FDMI request failed */
  1489. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1490. "0244 Issue FDMI request failed Data: x%x\n",
  1491. cmdcode);
  1492. return 1;
  1493. }
  1494. void
  1495. lpfc_fdmi_tmo(unsigned long ptr)
  1496. {
  1497. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1498. struct lpfc_hba *phba = vport->phba;
  1499. uint32_t tmo_posted;
  1500. unsigned long iflag;
  1501. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1502. tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
  1503. if (!tmo_posted)
  1504. vport->work_port_events |= WORKER_FDMI_TMO;
  1505. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1506. if (!tmo_posted)
  1507. lpfc_worker_wake_up(phba);
  1508. return;
  1509. }
  1510. void
  1511. lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
  1512. {
  1513. struct lpfc_nodelist *ndlp;
  1514. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1515. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  1516. if (init_utsname()->nodename[0] != '\0')
  1517. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  1518. else
  1519. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  1520. }
  1521. return;
  1522. }
  1523. void
  1524. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  1525. {
  1526. struct lpfc_sli *psli = &phba->sli;
  1527. lpfc_vpd_t *vp = &phba->vpd;
  1528. uint32_t b1, b2, b3, b4, i, rev;
  1529. char c;
  1530. uint32_t *ptr, str[4];
  1531. uint8_t *fwname;
  1532. if (phba->sli_rev == LPFC_SLI_REV4)
  1533. sprintf(fwrevision, "%s", vp->rev.opFwName);
  1534. else if (vp->rev.rBit) {
  1535. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  1536. rev = vp->rev.sli2FwRev;
  1537. else
  1538. rev = vp->rev.sli1FwRev;
  1539. b1 = (rev & 0x0000f000) >> 12;
  1540. b2 = (rev & 0x00000f00) >> 8;
  1541. b3 = (rev & 0x000000c0) >> 6;
  1542. b4 = (rev & 0x00000030) >> 4;
  1543. switch (b4) {
  1544. case 0:
  1545. c = 'N';
  1546. break;
  1547. case 1:
  1548. c = 'A';
  1549. break;
  1550. case 2:
  1551. c = 'B';
  1552. break;
  1553. default:
  1554. c = 0;
  1555. break;
  1556. }
  1557. b4 = (rev & 0x0000000f);
  1558. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  1559. fwname = vp->rev.sli2FwName;
  1560. else
  1561. fwname = vp->rev.sli1FwName;
  1562. for (i = 0; i < 16; i++)
  1563. if (fwname[i] == 0x20)
  1564. fwname[i] = 0;
  1565. ptr = (uint32_t*)fwname;
  1566. for (i = 0; i < 3; i++)
  1567. str[i] = be32_to_cpu(*ptr++);
  1568. if (c == 0) {
  1569. if (flag)
  1570. sprintf(fwrevision, "%d.%d%d (%s)",
  1571. b1, b2, b3, (char *)str);
  1572. else
  1573. sprintf(fwrevision, "%d.%d%d", b1,
  1574. b2, b3);
  1575. } else {
  1576. if (flag)
  1577. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  1578. b1, b2, b3, c,
  1579. b4, (char *)str);
  1580. else
  1581. sprintf(fwrevision, "%d.%d%d%c%d",
  1582. b1, b2, b3, c, b4);
  1583. }
  1584. } else {
  1585. rev = vp->rev.smFwRev;
  1586. b1 = (rev & 0xff000000) >> 24;
  1587. b2 = (rev & 0x00f00000) >> 20;
  1588. b3 = (rev & 0x000f0000) >> 16;
  1589. c = (rev & 0x0000ff00) >> 8;
  1590. b4 = (rev & 0x000000ff);
  1591. if (flag)
  1592. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1593. b2, b3, c, b4);
  1594. else
  1595. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1596. b2, b3, c, b4);
  1597. }
  1598. return;
  1599. }