lpfc_ct.c 46 KB

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