lpfc_ct.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2005 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. #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  40. * incapable of reporting */
  41. #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
  42. #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
  43. #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
  44. #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
  45. #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
  46. #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
  47. #define FOURBYTES 4
  48. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  49. /*
  50. * lpfc_ct_unsol_event
  51. */
  52. void
  53. lpfc_ct_unsol_event(struct lpfc_hba * phba,
  54. struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocbq)
  55. {
  56. struct lpfc_iocbq *next_piocbq;
  57. struct lpfc_dmabuf *pmbuf = NULL;
  58. struct lpfc_dmabuf *matp, *next_matp;
  59. uint32_t ctx = 0, size = 0, cnt = 0;
  60. IOCB_t *icmd = &piocbq->iocb;
  61. IOCB_t *save_icmd = icmd;
  62. int i, go_exit = 0;
  63. struct list_head head;
  64. if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  65. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  66. /* Not enough posted buffers; Try posting more buffers */
  67. phba->fc_stat.NoRcvBuf++;
  68. lpfc_post_buffer(phba, pring, 0, 1);
  69. return;
  70. }
  71. /* If there are no BDEs associated with this IOCB,
  72. * there is nothing to do.
  73. */
  74. if (icmd->ulpBdeCount == 0)
  75. return;
  76. INIT_LIST_HEAD(&head);
  77. list_add_tail(&head, &piocbq->list);
  78. list_for_each_entry_safe(piocbq, next_piocbq, &head, list) {
  79. icmd = &piocbq->iocb;
  80. if (ctx == 0)
  81. ctx = (uint32_t) (icmd->ulpContext);
  82. if (icmd->ulpBdeCount == 0)
  83. continue;
  84. for (i = 0; i < icmd->ulpBdeCount; i++) {
  85. matp = lpfc_sli_ringpostbuf_get(phba, pring,
  86. getPaddr(icmd->un.
  87. cont64[i].
  88. addrHigh,
  89. icmd->un.
  90. cont64[i].
  91. addrLow));
  92. if (!matp) {
  93. /* Insert lpfc log message here */
  94. lpfc_post_buffer(phba, pring, cnt, 1);
  95. go_exit = 1;
  96. goto ct_unsol_event_exit_piocbq;
  97. }
  98. /* Typically for Unsolicited CT requests */
  99. if (!pmbuf) {
  100. pmbuf = matp;
  101. INIT_LIST_HEAD(&pmbuf->list);
  102. } else
  103. list_add_tail(&matp->list, &pmbuf->list);
  104. size += icmd->un.cont64[i].tus.f.bdeSize;
  105. cnt++;
  106. }
  107. icmd->ulpBdeCount = 0;
  108. }
  109. lpfc_post_buffer(phba, pring, cnt, 1);
  110. if (save_icmd->ulpStatus) {
  111. go_exit = 1;
  112. }
  113. ct_unsol_event_exit_piocbq:
  114. if (pmbuf) {
  115. list_for_each_entry_safe(matp, next_matp, &pmbuf->list, list) {
  116. lpfc_mbuf_free(phba, matp->virt, matp->phys);
  117. list_del(&matp->list);
  118. kfree(matp);
  119. }
  120. lpfc_mbuf_free(phba, pmbuf->virt, pmbuf->phys);
  121. kfree(pmbuf);
  122. }
  123. return;
  124. }
  125. static void
  126. lpfc_free_ct_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mlist)
  127. {
  128. struct lpfc_dmabuf *mlast, *next_mlast;
  129. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  130. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  131. list_del(&mlast->list);
  132. kfree(mlast);
  133. }
  134. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  135. kfree(mlist);
  136. return;
  137. }
  138. static struct lpfc_dmabuf *
  139. lpfc_alloc_ct_rsp(struct lpfc_hba * phba, int cmdcode, struct ulp_bde64 * bpl,
  140. uint32_t size, int *entries)
  141. {
  142. struct lpfc_dmabuf *mlist = NULL;
  143. struct lpfc_dmabuf *mp;
  144. int cnt, i = 0;
  145. /* We get chucks of FCELSSIZE */
  146. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  147. while (size) {
  148. /* Allocate buffer for rsp payload */
  149. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  150. if (!mp) {
  151. if (mlist)
  152. lpfc_free_ct_rsp(phba, mlist);
  153. return NULL;
  154. }
  155. INIT_LIST_HEAD(&mp->list);
  156. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
  157. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  158. else
  159. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  160. if (!mp->virt) {
  161. kfree(mp);
  162. lpfc_free_ct_rsp(phba, mlist);
  163. return NULL;
  164. }
  165. /* Queue it to a linked list */
  166. if (!mlist)
  167. mlist = mp;
  168. else
  169. list_add_tail(&mp->list, &mlist->list);
  170. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  171. /* build buffer ptr list for IOCB */
  172. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  173. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  174. bpl->tus.f.bdeSize = (uint16_t) cnt;
  175. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  176. bpl++;
  177. i++;
  178. size -= cnt;
  179. }
  180. *entries = i;
  181. return mlist;
  182. }
  183. static int
  184. lpfc_gen_req(struct lpfc_hba *phba, struct lpfc_dmabuf *bmp,
  185. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  186. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  187. struct lpfc_iocbq *),
  188. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  189. uint32_t tmo)
  190. {
  191. struct lpfc_sli *psli = &phba->sli;
  192. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  193. IOCB_t *icmd;
  194. struct lpfc_iocbq *geniocb;
  195. /* Allocate buffer for command iocb */
  196. spin_lock_irq(phba->host->host_lock);
  197. geniocb = lpfc_sli_get_iocbq(phba);
  198. spin_unlock_irq(phba->host->host_lock);
  199. if (geniocb == NULL)
  200. return 1;
  201. icmd = &geniocb->iocb;
  202. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  203. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  204. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  205. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  206. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
  207. if (usr_flg)
  208. geniocb->context3 = NULL;
  209. else
  210. geniocb->context3 = (uint8_t *) bmp;
  211. /* Save for completion so we can release these resources */
  212. geniocb->context1 = (uint8_t *) inp;
  213. geniocb->context2 = (uint8_t *) outp;
  214. /* Fill in payload, bp points to frame payload */
  215. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  216. /* Fill in rest of iocb */
  217. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  218. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  219. icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
  220. icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
  221. if (!tmo) {
  222. /* FC spec states we need 3 * ratov for CT requests */
  223. tmo = (3 * phba->fc_ratov);
  224. }
  225. icmd->ulpTimeout = tmo;
  226. icmd->ulpBdeCount = 1;
  227. icmd->ulpLe = 1;
  228. icmd->ulpClass = CLASS3;
  229. icmd->ulpContext = ndlp->nlp_rpi;
  230. /* Issue GEN REQ IOCB for NPORT <did> */
  231. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  232. "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
  233. "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
  234. icmd->ulpIoTag, phba->hba_state);
  235. geniocb->iocb_cmpl = cmpl;
  236. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  237. spin_lock_irq(phba->host->host_lock);
  238. if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
  239. lpfc_sli_release_iocbq(phba, geniocb);
  240. spin_unlock_irq(phba->host->host_lock);
  241. return 1;
  242. }
  243. spin_unlock_irq(phba->host->host_lock);
  244. return 0;
  245. }
  246. static int
  247. lpfc_ct_cmd(struct lpfc_hba *phba, struct lpfc_dmabuf *inmp,
  248. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  249. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  250. struct lpfc_iocbq *),
  251. uint32_t rsp_size)
  252. {
  253. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  254. struct lpfc_dmabuf *outmp;
  255. int cnt = 0, status;
  256. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  257. CommandResponse.bits.CmdRsp;
  258. bpl++; /* Skip past ct request */
  259. /* Put buffer(s) for ct rsp in bpl */
  260. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  261. if (!outmp)
  262. return -ENOMEM;
  263. status = lpfc_gen_req(phba, bmp, inmp, outmp, cmpl, ndlp, 0,
  264. cnt+1, 0);
  265. if (status) {
  266. lpfc_free_ct_rsp(phba, outmp);
  267. return -ENOMEM;
  268. }
  269. return 0;
  270. }
  271. static int
  272. lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
  273. {
  274. struct lpfc_sli_ct_request *Response =
  275. (struct lpfc_sli_ct_request *) mp->virt;
  276. struct lpfc_nodelist *ndlp = NULL;
  277. struct lpfc_dmabuf *mlast, *next_mp;
  278. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  279. uint32_t Did;
  280. uint32_t CTentry;
  281. int Cnt;
  282. struct list_head head;
  283. lpfc_set_disctmo(phba);
  284. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  285. list_add_tail(&head, &mp->list);
  286. list_for_each_entry_safe(mp, next_mp, &head, list) {
  287. mlast = mp;
  288. Size -= Cnt;
  289. if (!ctptr)
  290. ctptr = (uint32_t *) mlast->virt;
  291. else
  292. Cnt -= 16; /* subtract length of CT header */
  293. /* Loop through entire NameServer list of DIDs */
  294. while (Cnt) {
  295. /* Get next DID from NameServer List */
  296. CTentry = *ctptr++;
  297. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  298. ndlp = NULL;
  299. if (Did != phba->fc_myDID) {
  300. /* Check for rscn processing or not */
  301. ndlp = lpfc_setup_disc_node(phba, Did);
  302. }
  303. /* Mark all node table entries that are in the
  304. Nameserver */
  305. if (ndlp) {
  306. /* NameServer Rsp */
  307. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  308. "%d:0238 Process x%x NameServer"
  309. " Rsp Data: x%x x%x x%x\n",
  310. phba->brd_no,
  311. Did, ndlp->nlp_flag,
  312. phba->fc_flag,
  313. phba->fc_rscn_id_cnt);
  314. } else {
  315. /* NameServer Rsp */
  316. lpfc_printf_log(phba,
  317. KERN_INFO,
  318. LOG_DISCOVERY,
  319. "%d:0239 Skip x%x NameServer "
  320. "Rsp Data: x%x x%x x%x\n",
  321. phba->brd_no,
  322. Did, Size, phba->fc_flag,
  323. phba->fc_rscn_id_cnt);
  324. }
  325. if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
  326. goto nsout1;
  327. Cnt -= sizeof (uint32_t);
  328. }
  329. ctptr = NULL;
  330. }
  331. nsout1:
  332. list_del(&head);
  333. /* Here we are finished in the case RSCN */
  334. if (phba->hba_state == LPFC_HBA_READY) {
  335. lpfc_els_flush_rscn(phba);
  336. spin_lock_irq(phba->host->host_lock);
  337. phba->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
  338. spin_unlock_irq(phba->host->host_lock);
  339. }
  340. return 0;
  341. }
  342. static void
  343. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  344. struct lpfc_iocbq * rspiocb)
  345. {
  346. IOCB_t *irsp;
  347. struct lpfc_sli *psli;
  348. struct lpfc_dmabuf *bmp;
  349. struct lpfc_dmabuf *inp;
  350. struct lpfc_dmabuf *outp;
  351. struct lpfc_nodelist *ndlp;
  352. struct lpfc_sli_ct_request *CTrsp;
  353. psli = &phba->sli;
  354. /* we pass cmdiocb to state machine which needs rspiocb as well */
  355. cmdiocb->context_un.rsp_iocb = rspiocb;
  356. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  357. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  358. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  359. irsp = &rspiocb->iocb;
  360. if (irsp->ulpStatus) {
  361. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  362. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  363. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))) {
  364. goto out;
  365. }
  366. /* Check for retry */
  367. if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  368. phba->fc_ns_retry++;
  369. /* CT command is being retried */
  370. ndlp =
  371. lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
  372. NameServer_DID);
  373. if (ndlp) {
  374. if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
  375. 0) {
  376. goto out;
  377. }
  378. }
  379. }
  380. } else {
  381. /* Good status, continue checking */
  382. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  383. if (CTrsp->CommandResponse.bits.CmdRsp ==
  384. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  385. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  386. "%d:0239 NameServer Rsp "
  387. "Data: x%x\n",
  388. phba->brd_no,
  389. phba->fc_flag);
  390. lpfc_ns_rsp(phba, outp,
  391. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  392. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  393. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  394. /* NameServer Rsp Error */
  395. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  396. "%d:0240 NameServer Rsp Error "
  397. "Data: x%x x%x x%x x%x\n",
  398. phba->brd_no,
  399. CTrsp->CommandResponse.bits.CmdRsp,
  400. (uint32_t) CTrsp->ReasonCode,
  401. (uint32_t) CTrsp->Explanation,
  402. phba->fc_flag);
  403. } else {
  404. /* NameServer Rsp Error */
  405. lpfc_printf_log(phba,
  406. KERN_INFO,
  407. LOG_DISCOVERY,
  408. "%d:0241 NameServer Rsp Error "
  409. "Data: x%x x%x x%x x%x\n",
  410. phba->brd_no,
  411. CTrsp->CommandResponse.bits.CmdRsp,
  412. (uint32_t) CTrsp->ReasonCode,
  413. (uint32_t) CTrsp->Explanation,
  414. phba->fc_flag);
  415. }
  416. }
  417. /* Link up / RSCN discovery */
  418. lpfc_disc_start(phba);
  419. out:
  420. lpfc_free_ct_rsp(phba, outp);
  421. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  422. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  423. kfree(inp);
  424. kfree(bmp);
  425. spin_lock_irq(phba->host->host_lock);
  426. lpfc_sli_release_iocbq(phba, cmdiocb);
  427. spin_unlock_irq(phba->host->host_lock);
  428. return;
  429. }
  430. static void
  431. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  432. struct lpfc_iocbq * rspiocb)
  433. {
  434. struct lpfc_sli *psli;
  435. struct lpfc_dmabuf *bmp;
  436. struct lpfc_dmabuf *inp;
  437. struct lpfc_dmabuf *outp;
  438. IOCB_t *irsp;
  439. struct lpfc_sli_ct_request *CTrsp;
  440. psli = &phba->sli;
  441. /* we pass cmdiocb to state machine which needs rspiocb as well */
  442. cmdiocb->context_un.rsp_iocb = rspiocb;
  443. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  444. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  445. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  446. irsp = &rspiocb->iocb;
  447. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  448. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  449. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  450. "%d:0209 RFT request completes ulpStatus x%x "
  451. "CmdRsp x%x\n", phba->brd_no, irsp->ulpStatus,
  452. CTrsp->CommandResponse.bits.CmdRsp);
  453. lpfc_free_ct_rsp(phba, outp);
  454. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  455. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  456. kfree(inp);
  457. kfree(bmp);
  458. spin_lock_irq(phba->host->host_lock);
  459. lpfc_sli_release_iocbq(phba, cmdiocb);
  460. spin_unlock_irq(phba->host->host_lock);
  461. return;
  462. }
  463. static void
  464. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  465. struct lpfc_iocbq * rspiocb)
  466. {
  467. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  468. return;
  469. }
  470. static void
  471. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  472. struct lpfc_iocbq * rspiocb)
  473. {
  474. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  475. return;
  476. }
  477. void
  478. lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp)
  479. {
  480. char fwrev[16];
  481. lpfc_decode_firmware_rev(phba, fwrev, 0);
  482. if (phba->Port[0]) {
  483. sprintf(symbp, "Emulex %s Port %s FV%s DV%s", phba->ModelName,
  484. phba->Port, fwrev, lpfc_release_version);
  485. } else {
  486. sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
  487. fwrev, lpfc_release_version);
  488. }
  489. }
  490. /*
  491. * lpfc_ns_cmd
  492. * Description:
  493. * Issue Cmd to NameServer
  494. * SLI_CTNS_GID_FT
  495. * LI_CTNS_RFT_ID
  496. */
  497. int
  498. lpfc_ns_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
  499. {
  500. struct lpfc_dmabuf *mp, *bmp;
  501. struct lpfc_sli_ct_request *CtReq;
  502. struct ulp_bde64 *bpl;
  503. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  504. struct lpfc_iocbq *) = NULL;
  505. uint32_t rsp_size = 1024;
  506. /* fill in BDEs for command */
  507. /* Allocate buffer for command payload */
  508. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  509. if (!mp)
  510. goto ns_cmd_exit;
  511. INIT_LIST_HEAD(&mp->list);
  512. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  513. if (!mp->virt)
  514. goto ns_cmd_free_mp;
  515. /* Allocate buffer for Buffer ptr list */
  516. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  517. if (!bmp)
  518. goto ns_cmd_free_mpvirt;
  519. INIT_LIST_HEAD(&bmp->list);
  520. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  521. if (!bmp->virt)
  522. goto ns_cmd_free_bmp;
  523. /* NameServer Req */
  524. lpfc_printf_log(phba,
  525. KERN_INFO,
  526. LOG_DISCOVERY,
  527. "%d:0236 NameServer Req Data: x%x x%x x%x\n",
  528. phba->brd_no, cmdcode, phba->fc_flag,
  529. phba->fc_rscn_id_cnt);
  530. bpl = (struct ulp_bde64 *) bmp->virt;
  531. memset(bpl, 0, sizeof(struct ulp_bde64));
  532. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  533. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  534. bpl->tus.f.bdeFlags = 0;
  535. if (cmdcode == SLI_CTNS_GID_FT)
  536. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  537. else if (cmdcode == SLI_CTNS_RFT_ID)
  538. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  539. else if (cmdcode == SLI_CTNS_RNN_ID)
  540. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  541. else if (cmdcode == SLI_CTNS_RSNN_NN)
  542. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  543. else
  544. bpl->tus.f.bdeSize = 0;
  545. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  546. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  547. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  548. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  549. CtReq->RevisionId.bits.InId = 0;
  550. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  551. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  552. CtReq->CommandResponse.bits.Size = 0;
  553. switch (cmdcode) {
  554. case SLI_CTNS_GID_FT:
  555. CtReq->CommandResponse.bits.CmdRsp =
  556. be16_to_cpu(SLI_CTNS_GID_FT);
  557. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  558. if (phba->hba_state < LPFC_HBA_READY)
  559. phba->hba_state = LPFC_NS_QRY;
  560. lpfc_set_disctmo(phba);
  561. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  562. rsp_size = FC_MAX_NS_RSP;
  563. break;
  564. case SLI_CTNS_RFT_ID:
  565. CtReq->CommandResponse.bits.CmdRsp =
  566. be16_to_cpu(SLI_CTNS_RFT_ID);
  567. CtReq->un.rft.PortId = be32_to_cpu(phba->fc_myDID);
  568. CtReq->un.rft.fcpReg = 1;
  569. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  570. break;
  571. case SLI_CTNS_RNN_ID:
  572. CtReq->CommandResponse.bits.CmdRsp =
  573. be16_to_cpu(SLI_CTNS_RNN_ID);
  574. CtReq->un.rnn.PortId = be32_to_cpu(phba->fc_myDID);
  575. memcpy(CtReq->un.rnn.wwnn, &phba->fc_nodename,
  576. sizeof (struct lpfc_name));
  577. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  578. break;
  579. case SLI_CTNS_RSNN_NN:
  580. CtReq->CommandResponse.bits.CmdRsp =
  581. be16_to_cpu(SLI_CTNS_RSNN_NN);
  582. memcpy(CtReq->un.rsnn.wwnn, &phba->fc_nodename,
  583. sizeof (struct lpfc_name));
  584. lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
  585. CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
  586. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  587. break;
  588. }
  589. if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, rsp_size))
  590. /* On success, The cmpl function will free the buffers */
  591. return 0;
  592. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  593. ns_cmd_free_bmp:
  594. kfree(bmp);
  595. ns_cmd_free_mpvirt:
  596. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  597. ns_cmd_free_mp:
  598. kfree(mp);
  599. ns_cmd_exit:
  600. return 1;
  601. }
  602. static void
  603. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
  604. struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
  605. {
  606. struct lpfc_dmabuf *bmp = cmdiocb->context3;
  607. struct lpfc_dmabuf *inp = cmdiocb->context1;
  608. struct lpfc_dmabuf *outp = cmdiocb->context2;
  609. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  610. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  611. struct lpfc_nodelist *ndlp;
  612. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  613. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  614. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
  615. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  616. /* FDMI rsp failed */
  617. lpfc_printf_log(phba,
  618. KERN_INFO,
  619. LOG_DISCOVERY,
  620. "%d:0220 FDMI rsp failed Data: x%x\n",
  621. phba->brd_no,
  622. be16_to_cpu(fdmi_cmd));
  623. }
  624. switch (be16_to_cpu(fdmi_cmd)) {
  625. case SLI_MGMT_RHBA:
  626. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RPA);
  627. break;
  628. case SLI_MGMT_RPA:
  629. break;
  630. case SLI_MGMT_DHBA:
  631. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DPRT);
  632. break;
  633. case SLI_MGMT_DPRT:
  634. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_RHBA);
  635. break;
  636. }
  637. lpfc_free_ct_rsp(phba, outp);
  638. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  639. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  640. kfree(inp);
  641. kfree(bmp);
  642. spin_lock_irq(phba->host->host_lock);
  643. lpfc_sli_release_iocbq(phba, cmdiocb);
  644. spin_unlock_irq(phba->host->host_lock);
  645. return;
  646. }
  647. int
  648. lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
  649. {
  650. struct lpfc_dmabuf *mp, *bmp;
  651. struct lpfc_sli_ct_request *CtReq;
  652. struct ulp_bde64 *bpl;
  653. uint32_t size;
  654. REG_HBA *rh;
  655. PORT_ENTRY *pe;
  656. REG_PORT_ATTRIBUTE *pab;
  657. ATTRIBUTE_BLOCK *ab;
  658. ATTRIBUTE_ENTRY *ae;
  659. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  660. struct lpfc_iocbq *);
  661. /* fill in BDEs for command */
  662. /* Allocate buffer for command payload */
  663. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  664. if (!mp)
  665. goto fdmi_cmd_exit;
  666. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  667. if (!mp->virt)
  668. goto fdmi_cmd_free_mp;
  669. /* Allocate buffer for Buffer ptr list */
  670. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  671. if (!bmp)
  672. goto fdmi_cmd_free_mpvirt;
  673. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  674. if (!bmp->virt)
  675. goto fdmi_cmd_free_bmp;
  676. INIT_LIST_HEAD(&mp->list);
  677. INIT_LIST_HEAD(&bmp->list);
  678. /* FDMI request */
  679. lpfc_printf_log(phba,
  680. KERN_INFO,
  681. LOG_DISCOVERY,
  682. "%d:0218 FDMI Request Data: x%x x%x x%x\n",
  683. phba->brd_no,
  684. phba->fc_flag, phba->hba_state, cmdcode);
  685. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  686. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  687. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  688. CtReq->RevisionId.bits.InId = 0;
  689. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  690. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  691. size = 0;
  692. switch (cmdcode) {
  693. case SLI_MGMT_RHBA:
  694. {
  695. lpfc_vpd_t *vp = &phba->vpd;
  696. uint32_t i, j, incr;
  697. int len;
  698. CtReq->CommandResponse.bits.CmdRsp =
  699. be16_to_cpu(SLI_MGMT_RHBA);
  700. CtReq->CommandResponse.bits.Size = 0;
  701. rh = (REG_HBA *) & CtReq->un.PortID;
  702. memcpy(&rh->hi.PortName, &phba->fc_sparam.portName,
  703. sizeof (struct lpfc_name));
  704. /* One entry (port) per adapter */
  705. rh->rpl.EntryCnt = be32_to_cpu(1);
  706. memcpy(&rh->rpl.pe, &phba->fc_sparam.portName,
  707. sizeof (struct lpfc_name));
  708. /* point to the HBA attribute block */
  709. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  710. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  711. ab->EntryCnt = 0;
  712. /* Point to the beginning of the first HBA attribute
  713. entry */
  714. /* #1 HBA attribute entry */
  715. size += FOURBYTES;
  716. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  717. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  718. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  719. + sizeof (struct lpfc_name));
  720. memcpy(&ae->un.NodeName, &phba->fc_sparam.nodeName,
  721. sizeof (struct lpfc_name));
  722. ab->EntryCnt++;
  723. size += FOURBYTES + sizeof (struct lpfc_name);
  724. /* #2 HBA attribute entry */
  725. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  726. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  727. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  728. len = strlen(ae->un.Manufacturer);
  729. len += (len & 3) ? (4 - (len & 3)) : 4;
  730. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  731. ab->EntryCnt++;
  732. size += FOURBYTES + len;
  733. /* #3 HBA attribute entry */
  734. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  735. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  736. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  737. len = strlen(ae->un.SerialNumber);
  738. len += (len & 3) ? (4 - (len & 3)) : 4;
  739. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  740. ab->EntryCnt++;
  741. size += FOURBYTES + len;
  742. /* #4 HBA attribute entry */
  743. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  744. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  745. strcpy(ae->un.Model, phba->ModelName);
  746. len = strlen(ae->un.Model);
  747. len += (len & 3) ? (4 - (len & 3)) : 4;
  748. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  749. ab->EntryCnt++;
  750. size += FOURBYTES + len;
  751. /* #5 HBA attribute entry */
  752. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  753. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  754. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  755. len = strlen(ae->un.ModelDescription);
  756. len += (len & 3) ? (4 - (len & 3)) : 4;
  757. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  758. ab->EntryCnt++;
  759. size += FOURBYTES + len;
  760. /* #6 HBA attribute entry */
  761. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  762. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  763. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  764. /* Convert JEDEC ID to ascii for hardware version */
  765. incr = vp->rev.biuRev;
  766. for (i = 0; i < 8; i++) {
  767. j = (incr & 0xf);
  768. if (j <= 9)
  769. ae->un.HardwareVersion[7 - i] =
  770. (char)((uint8_t) 0x30 +
  771. (uint8_t) j);
  772. else
  773. ae->un.HardwareVersion[7 - i] =
  774. (char)((uint8_t) 0x61 +
  775. (uint8_t) (j - 10));
  776. incr = (incr >> 4);
  777. }
  778. ab->EntryCnt++;
  779. size += FOURBYTES + 8;
  780. /* #7 HBA attribute entry */
  781. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  782. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  783. strcpy(ae->un.DriverVersion, lpfc_release_version);
  784. len = strlen(ae->un.DriverVersion);
  785. len += (len & 3) ? (4 - (len & 3)) : 4;
  786. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  787. ab->EntryCnt++;
  788. size += FOURBYTES + len;
  789. /* #8 HBA attribute entry */
  790. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  791. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  792. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  793. len = strlen(ae->un.OptionROMVersion);
  794. len += (len & 3) ? (4 - (len & 3)) : 4;
  795. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  796. ab->EntryCnt++;
  797. size += FOURBYTES + len;
  798. /* #9 HBA attribute entry */
  799. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  800. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  801. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  802. 1);
  803. len = strlen(ae->un.FirmwareVersion);
  804. len += (len & 3) ? (4 - (len & 3)) : 4;
  805. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  806. ab->EntryCnt++;
  807. size += FOURBYTES + len;
  808. /* #10 HBA attribute entry */
  809. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  810. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  811. sprintf(ae->un.OsNameVersion, "%s %s %s",
  812. system_utsname.sysname, system_utsname.release,
  813. system_utsname.version);
  814. len = strlen(ae->un.OsNameVersion);
  815. len += (len & 3) ? (4 - (len & 3)) : 4;
  816. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  817. ab->EntryCnt++;
  818. size += FOURBYTES + len;
  819. /* #11 HBA attribute entry */
  820. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  821. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  822. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  823. ae->un.MaxCTPayloadLen = (65 * 4096);
  824. ab->EntryCnt++;
  825. size += FOURBYTES + 4;
  826. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  827. /* Total size */
  828. size = GID_REQUEST_SZ - 4 + size;
  829. }
  830. break;
  831. case SLI_MGMT_RPA:
  832. {
  833. lpfc_vpd_t *vp;
  834. struct serv_parm *hsp;
  835. int len;
  836. vp = &phba->vpd;
  837. CtReq->CommandResponse.bits.CmdRsp =
  838. be16_to_cpu(SLI_MGMT_RPA);
  839. CtReq->CommandResponse.bits.Size = 0;
  840. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  841. size = sizeof (struct lpfc_name) + FOURBYTES;
  842. memcpy((uint8_t *) & pab->PortName,
  843. (uint8_t *) & phba->fc_sparam.portName,
  844. sizeof (struct lpfc_name));
  845. pab->ab.EntryCnt = 0;
  846. /* #1 Port attribute entry */
  847. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  848. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  849. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  850. ae->un.SupportFC4Types[2] = 1;
  851. ae->un.SupportFC4Types[7] = 1;
  852. pab->ab.EntryCnt++;
  853. size += FOURBYTES + 32;
  854. /* #2 Port attribute entry */
  855. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  856. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  857. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  858. if (FC_JEDEC_ID(vp->rev.biuRev) == VIPER_JEDEC_ID)
  859. ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
  860. else if (FC_JEDEC_ID(vp->rev.biuRev) == HELIOS_JEDEC_ID)
  861. ae->un.SupportSpeed = HBA_PORTSPEED_4GBIT;
  862. else if ((FC_JEDEC_ID(vp->rev.biuRev) ==
  863. CENTAUR_2G_JEDEC_ID)
  864. || (FC_JEDEC_ID(vp->rev.biuRev) ==
  865. PEGASUS_JEDEC_ID)
  866. || (FC_JEDEC_ID(vp->rev.biuRev) ==
  867. THOR_JEDEC_ID))
  868. ae->un.SupportSpeed = HBA_PORTSPEED_2GBIT;
  869. else
  870. ae->un.SupportSpeed = HBA_PORTSPEED_1GBIT;
  871. pab->ab.EntryCnt++;
  872. size += FOURBYTES + 4;
  873. /* #3 Port attribute entry */
  874. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  875. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  876. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  877. switch(phba->fc_linkspeed) {
  878. case LA_1GHZ_LINK:
  879. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  880. break;
  881. case LA_2GHZ_LINK:
  882. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  883. break;
  884. case LA_4GHZ_LINK:
  885. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  886. break;
  887. default:
  888. ae->un.PortSpeed =
  889. HBA_PORTSPEED_UNKNOWN;
  890. break;
  891. }
  892. pab->ab.EntryCnt++;
  893. size += FOURBYTES + 4;
  894. /* #4 Port attribute entry */
  895. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  896. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  897. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  898. hsp = (struct serv_parm *) & phba->fc_sparam;
  899. ae->un.MaxFrameSize =
  900. (((uint32_t) hsp->cmn.
  901. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  902. bbRcvSizeLsb;
  903. pab->ab.EntryCnt++;
  904. size += FOURBYTES + 4;
  905. /* #5 Port attribute entry */
  906. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  907. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  908. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  909. len = strlen((char *)ae->un.OsDeviceName);
  910. len += (len & 3) ? (4 - (len & 3)) : 4;
  911. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  912. pab->ab.EntryCnt++;
  913. size += FOURBYTES + len;
  914. if (phba->cfg_fdmi_on == 2) {
  915. /* #6 Port attribute entry */
  916. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  917. size);
  918. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  919. sprintf(ae->un.HostName, "%s",
  920. system_utsname.nodename);
  921. len = strlen(ae->un.HostName);
  922. len += (len & 3) ? (4 - (len & 3)) : 4;
  923. ae->ad.bits.AttrLen =
  924. be16_to_cpu(FOURBYTES + len);
  925. pab->ab.EntryCnt++;
  926. size += FOURBYTES + len;
  927. }
  928. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  929. /* Total size */
  930. size = GID_REQUEST_SZ - 4 + size;
  931. }
  932. break;
  933. case SLI_MGMT_DHBA:
  934. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  935. CtReq->CommandResponse.bits.Size = 0;
  936. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  937. memcpy((uint8_t *) & pe->PortName,
  938. (uint8_t *) & phba->fc_sparam.portName,
  939. sizeof (struct lpfc_name));
  940. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  941. break;
  942. case SLI_MGMT_DPRT:
  943. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  944. CtReq->CommandResponse.bits.Size = 0;
  945. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  946. memcpy((uint8_t *) & pe->PortName,
  947. (uint8_t *) & phba->fc_sparam.portName,
  948. sizeof (struct lpfc_name));
  949. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  950. break;
  951. }
  952. bpl = (struct ulp_bde64 *) bmp->virt;
  953. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  954. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  955. bpl->tus.f.bdeFlags = 0;
  956. bpl->tus.f.bdeSize = size;
  957. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  958. cmpl = lpfc_cmpl_ct_cmd_fdmi;
  959. if (!lpfc_ct_cmd(phba, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
  960. return 0;
  961. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  962. fdmi_cmd_free_bmp:
  963. kfree(bmp);
  964. fdmi_cmd_free_mpvirt:
  965. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  966. fdmi_cmd_free_mp:
  967. kfree(mp);
  968. fdmi_cmd_exit:
  969. /* Issue FDMI request failed */
  970. lpfc_printf_log(phba,
  971. KERN_INFO,
  972. LOG_DISCOVERY,
  973. "%d:0244 Issue FDMI request failed Data: x%x\n",
  974. phba->brd_no,
  975. cmdcode);
  976. return 1;
  977. }
  978. void
  979. lpfc_fdmi_tmo(unsigned long ptr)
  980. {
  981. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  982. unsigned long iflag;
  983. spin_lock_irqsave(phba->host->host_lock, iflag);
  984. if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
  985. phba->work_hba_events |= WORKER_FDMI_TMO;
  986. if (phba->work_wait)
  987. wake_up(phba->work_wait);
  988. }
  989. spin_unlock_irqrestore(phba->host->host_lock,iflag);
  990. }
  991. void
  992. lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
  993. {
  994. struct lpfc_nodelist *ndlp;
  995. spin_lock_irq(phba->host->host_lock);
  996. if (!(phba->work_hba_events & WORKER_FDMI_TMO)) {
  997. spin_unlock_irq(phba->host->host_lock);
  998. return;
  999. }
  1000. ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
  1001. if (ndlp) {
  1002. if (system_utsname.nodename[0] != '\0') {
  1003. lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
  1004. } else {
  1005. mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
  1006. }
  1007. }
  1008. spin_unlock_irq(phba->host->host_lock);
  1009. return;
  1010. }
  1011. void
  1012. lpfc_decode_firmware_rev(struct lpfc_hba * phba, char *fwrevision, int flag)
  1013. {
  1014. struct lpfc_sli *psli = &phba->sli;
  1015. lpfc_vpd_t *vp = &phba->vpd;
  1016. uint32_t b1, b2, b3, b4, i, rev;
  1017. char c;
  1018. uint32_t *ptr, str[4];
  1019. uint8_t *fwname;
  1020. if (vp->rev.rBit) {
  1021. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1022. rev = vp->rev.sli2FwRev;
  1023. else
  1024. rev = vp->rev.sli1FwRev;
  1025. b1 = (rev & 0x0000f000) >> 12;
  1026. b2 = (rev & 0x00000f00) >> 8;
  1027. b3 = (rev & 0x000000c0) >> 6;
  1028. b4 = (rev & 0x00000030) >> 4;
  1029. switch (b4) {
  1030. case 0:
  1031. c = 'N';
  1032. break;
  1033. case 1:
  1034. c = 'A';
  1035. break;
  1036. case 2:
  1037. c = 'B';
  1038. break;
  1039. default:
  1040. c = 0;
  1041. break;
  1042. }
  1043. b4 = (rev & 0x0000000f);
  1044. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1045. fwname = vp->rev.sli2FwName;
  1046. else
  1047. fwname = vp->rev.sli1FwName;
  1048. for (i = 0; i < 16; i++)
  1049. if (fwname[i] == 0x20)
  1050. fwname[i] = 0;
  1051. ptr = (uint32_t*)fwname;
  1052. for (i = 0; i < 3; i++)
  1053. str[i] = be32_to_cpu(*ptr++);
  1054. if (c == 0) {
  1055. if (flag)
  1056. sprintf(fwrevision, "%d.%d%d (%s)",
  1057. b1, b2, b3, (char *)str);
  1058. else
  1059. sprintf(fwrevision, "%d.%d%d", b1,
  1060. b2, b3);
  1061. } else {
  1062. if (flag)
  1063. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  1064. b1, b2, b3, c,
  1065. b4, (char *)str);
  1066. else
  1067. sprintf(fwrevision, "%d.%d%d%c%d",
  1068. b1, b2, b3, c, b4);
  1069. }
  1070. } else {
  1071. rev = vp->rev.smFwRev;
  1072. b1 = (rev & 0xff000000) >> 24;
  1073. b2 = (rev & 0x00f00000) >> 20;
  1074. b3 = (rev & 0x000f0000) >> 16;
  1075. c = (rev & 0x0000ff00) >> 8;
  1076. b4 = (rev & 0x000000ff);
  1077. if (flag)
  1078. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1079. b2, b3, c, b4);
  1080. else
  1081. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1082. b2, b3, c, b4);
  1083. }
  1084. return;
  1085. }