lpfc_ct.c 34 KB

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