lpfc_ct.c 49 KB

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