lpfc_ct.c 46 KB

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