lpfc_ct.c 34 KB

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