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