lpfc_ct.c 34 KB

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