lpfc_ct.c 34 KB

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