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