lpfc_ct.c 35 KB

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