lpfc_ct.c 35 KB

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