lpfc_ct.c 34 KB

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