lpfc_ct.c 34 KB

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