lpfc_ct.c 34 KB

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