lpfc_ct.c 43 KB

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