lpfc_ct.c 53 KB

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