lpfc_ct.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  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. #include "lpfc_vport.h"
  40. #include "lpfc_debugfs.h"
  41. #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  42. * incapable of reporting */
  43. #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
  44. #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
  45. #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
  46. #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
  47. #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
  48. #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
  49. #define FOURBYTES 4
  50. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  51. /*
  52. * lpfc_ct_unsol_event
  53. */
  54. static void
  55. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  56. struct lpfc_dmabuf *mp, uint32_t size)
  57. {
  58. if (!mp) {
  59. printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
  60. "piocbq = %p, status = x%x, mp = %p, size = %d\n",
  61. __FUNCTION__, __LINE__,
  62. piocbq, piocbq->iocb.ulpStatus, mp, size);
  63. }
  64. printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
  65. "buffer = %p, size = %d, status = x%x\n",
  66. __FUNCTION__, __LINE__,
  67. piocbq, mp, size,
  68. piocbq->iocb.ulpStatus);
  69. }
  70. static void
  71. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  72. struct lpfc_dmabuf *mp, uint32_t size)
  73. {
  74. if (!mp) {
  75. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  76. "HBQ buffer, piocbq = %p, status = x%x\n",
  77. __FUNCTION__, __LINE__,
  78. piocbq, piocbq->iocb.ulpStatus);
  79. } else {
  80. lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
  81. printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
  82. "piocbq = %p, buffer = %p, size = %d, "
  83. "status = x%x\n",
  84. __FUNCTION__, __LINE__,
  85. piocbq, mp, size, piocbq->iocb.ulpStatus);
  86. }
  87. }
  88. void
  89. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  90. struct lpfc_iocbq *piocbq)
  91. {
  92. struct lpfc_dmabuf *mp = NULL;
  93. IOCB_t *icmd = &piocbq->iocb;
  94. int i;
  95. struct lpfc_iocbq *iocbq;
  96. dma_addr_t paddr;
  97. uint32_t size;
  98. struct lpfc_dmabuf *bdeBuf1 = piocbq->context2;
  99. struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
  100. piocbq->context2 = NULL;
  101. piocbq->context3 = NULL;
  102. if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
  103. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  104. } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  105. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  106. /* Not enough posted buffers; Try posting more buffers */
  107. phba->fc_stat.NoRcvBuf++;
  108. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  109. lpfc_post_buffer(phba, pring, 0, 1);
  110. return;
  111. }
  112. /* If there are no BDEs associated with this IOCB,
  113. * there is nothing to do.
  114. */
  115. if (icmd->ulpBdeCount == 0)
  116. return;
  117. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  118. list_for_each_entry(iocbq, &piocbq->list, list) {
  119. icmd = &iocbq->iocb;
  120. if (icmd->ulpBdeCount == 0) {
  121. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  122. "BDE, iocbq = %p, status = x%x\n",
  123. __FUNCTION__, __LINE__,
  124. iocbq, iocbq->iocb.ulpStatus);
  125. continue;
  126. }
  127. size = icmd->un.cont64[0].tus.f.bdeSize;
  128. lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf1, size);
  129. lpfc_in_buf_free(phba, bdeBuf1);
  130. if (icmd->ulpBdeCount == 2) {
  131. lpfc_ct_ignore_hbq_buffer(phba, piocbq, bdeBuf2,
  132. size);
  133. lpfc_in_buf_free(phba, bdeBuf2);
  134. }
  135. }
  136. } else {
  137. struct lpfc_iocbq *next;
  138. list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
  139. icmd = &iocbq->iocb;
  140. if (icmd->ulpBdeCount == 0) {
  141. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  142. "BDE, iocbq = %p, status = x%x\n",
  143. __FUNCTION__, __LINE__,
  144. iocbq, iocbq->iocb.ulpStatus);
  145. continue;
  146. }
  147. for (i = 0; i < icmd->ulpBdeCount; i++) {
  148. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  149. icmd->un.cont64[i].addrLow);
  150. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  151. paddr);
  152. size = icmd->un.cont64[i].tus.f.bdeSize;
  153. lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
  154. lpfc_in_buf_free(phba, mp);
  155. }
  156. list_del(&iocbq->list);
  157. lpfc_sli_release_iocbq(phba, iocbq);
  158. }
  159. }
  160. }
  161. static void
  162. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  163. {
  164. struct lpfc_dmabuf *mlast, *next_mlast;
  165. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  166. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  167. list_del(&mlast->list);
  168. kfree(mlast);
  169. }
  170. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  171. kfree(mlist);
  172. return;
  173. }
  174. static struct lpfc_dmabuf *
  175. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  176. uint32_t size, int *entries)
  177. {
  178. struct lpfc_dmabuf *mlist = NULL;
  179. struct lpfc_dmabuf *mp;
  180. int cnt, i = 0;
  181. /* We get chucks of FCELSSIZE */
  182. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  183. while (size) {
  184. /* Allocate buffer for rsp payload */
  185. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  186. if (!mp) {
  187. if (mlist)
  188. lpfc_free_ct_rsp(phba, mlist);
  189. return NULL;
  190. }
  191. INIT_LIST_HEAD(&mp->list);
  192. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  193. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  194. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  195. else
  196. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  197. if (!mp->virt) {
  198. kfree(mp);
  199. if (mlist)
  200. lpfc_free_ct_rsp(phba, mlist);
  201. return NULL;
  202. }
  203. /* Queue it to a linked list */
  204. if (!mlist)
  205. mlist = mp;
  206. else
  207. list_add_tail(&mp->list, &mlist->list);
  208. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  209. /* build buffer ptr list for IOCB */
  210. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  211. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  212. bpl->tus.f.bdeSize = (uint16_t) cnt;
  213. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  214. bpl++;
  215. i++;
  216. size -= cnt;
  217. }
  218. *entries = i;
  219. return mlist;
  220. }
  221. int
  222. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  223. {
  224. struct lpfc_dmabuf *buf_ptr;
  225. if (ctiocb->context1) {
  226. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
  227. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  228. kfree(buf_ptr);
  229. ctiocb->context1 = NULL;
  230. }
  231. if (ctiocb->context2) {
  232. lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
  233. ctiocb->context2 = NULL;
  234. }
  235. if (ctiocb->context3) {
  236. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
  237. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  238. kfree(buf_ptr);
  239. ctiocb->context1 = NULL;
  240. }
  241. lpfc_sli_release_iocbq(phba, ctiocb);
  242. return 0;
  243. }
  244. static int
  245. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  246. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  247. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  248. struct lpfc_iocbq *),
  249. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  250. uint32_t tmo, uint8_t retry)
  251. {
  252. struct lpfc_hba *phba = vport->phba;
  253. struct lpfc_sli *psli = &phba->sli;
  254. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  255. IOCB_t *icmd;
  256. struct lpfc_iocbq *geniocb;
  257. int rc;
  258. /* Allocate buffer for command iocb */
  259. geniocb = lpfc_sli_get_iocbq(phba);
  260. if (geniocb == NULL)
  261. return 1;
  262. icmd = &geniocb->iocb;
  263. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  264. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  265. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  266. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  267. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
  268. if (usr_flg)
  269. geniocb->context3 = NULL;
  270. else
  271. geniocb->context3 = (uint8_t *) bmp;
  272. /* Save for completion so we can release these resources */
  273. geniocb->context1 = (uint8_t *) inp;
  274. geniocb->context2 = (uint8_t *) outp;
  275. /* Fill in payload, bp points to frame payload */
  276. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  277. /* Fill in rest of iocb */
  278. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  279. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  280. icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
  281. icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
  282. if (!tmo) {
  283. /* FC spec states we need 3 * ratov for CT requests */
  284. tmo = (3 * phba->fc_ratov);
  285. }
  286. icmd->ulpTimeout = tmo;
  287. icmd->ulpBdeCount = 1;
  288. icmd->ulpLe = 1;
  289. icmd->ulpClass = CLASS3;
  290. icmd->ulpContext = ndlp->nlp_rpi;
  291. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  292. /* For GEN_REQUEST64_CR, use the RPI */
  293. icmd->ulpCt_h = 0;
  294. icmd->ulpCt_l = 0;
  295. }
  296. /* Issue GEN REQ IOCB for NPORT <did> */
  297. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  298. "%d (%d):0119 Issue GEN REQ IOCB to NPORT x%x "
  299. "Data: x%x x%x\n", phba->brd_no, vport->vpi,
  300. ndlp->nlp_DID, icmd->ulpIoTag,
  301. vport->port_state);
  302. geniocb->iocb_cmpl = cmpl;
  303. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  304. geniocb->vport = vport;
  305. geniocb->retry = retry;
  306. rc = lpfc_sli_issue_iocb(phba, pring, geniocb, 0);
  307. if (rc == IOCB_ERROR) {
  308. lpfc_sli_release_iocbq(phba, geniocb);
  309. return 1;
  310. }
  311. return 0;
  312. }
  313. static int
  314. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  315. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  316. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  317. struct lpfc_iocbq *),
  318. uint32_t rsp_size, uint8_t retry)
  319. {
  320. struct lpfc_hba *phba = vport->phba;
  321. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  322. struct lpfc_dmabuf *outmp;
  323. int cnt = 0, status;
  324. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  325. CommandResponse.bits.CmdRsp;
  326. bpl++; /* Skip past ct request */
  327. /* Put buffer(s) for ct rsp in bpl */
  328. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  329. if (!outmp)
  330. return -ENOMEM;
  331. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  332. cnt+1, 0, retry);
  333. if (status) {
  334. lpfc_free_ct_rsp(phba, outmp);
  335. return -ENOMEM;
  336. }
  337. return 0;
  338. }
  339. struct lpfc_vport *
  340. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  341. struct lpfc_vport *vport_curr;
  342. unsigned long flags;
  343. spin_lock_irqsave(&phba->hbalock, flags);
  344. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  345. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  346. spin_unlock_irqrestore(&phba->hbalock, flags);
  347. return vport_curr;
  348. }
  349. }
  350. spin_unlock_irqrestore(&phba->hbalock, flags);
  351. return NULL;
  352. }
  353. static int
  354. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  355. {
  356. struct lpfc_hba *phba = vport->phba;
  357. struct lpfc_sli_ct_request *Response =
  358. (struct lpfc_sli_ct_request *) mp->virt;
  359. struct lpfc_nodelist *ndlp = NULL;
  360. struct lpfc_dmabuf *mlast, *next_mp;
  361. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  362. uint32_t Did, CTentry;
  363. int Cnt;
  364. struct list_head head;
  365. lpfc_set_disctmo(vport);
  366. vport->num_disc_nodes = 0;
  367. list_add_tail(&head, &mp->list);
  368. list_for_each_entry_safe(mp, next_mp, &head, list) {
  369. mlast = mp;
  370. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  371. Size -= Cnt;
  372. if (!ctptr) {
  373. ctptr = (uint32_t *) mlast->virt;
  374. } else
  375. Cnt -= 16; /* subtract length of CT header */
  376. /* Loop through entire NameServer list of DIDs */
  377. while (Cnt >= sizeof (uint32_t)) {
  378. /* Get next DID from NameServer List */
  379. CTentry = *ctptr++;
  380. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  381. ndlp = NULL;
  382. /*
  383. * Check for rscn processing or not
  384. * To conserve rpi's, filter out addresses for other
  385. * vports on the same physical HBAs.
  386. */
  387. if ((Did != vport->fc_myDID) &&
  388. ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
  389. phba->cfg_peer_port_login)) {
  390. if ((vport->port_type != LPFC_NPIV_PORT) ||
  391. (vport->fc_flag & FC_RFF_NOT_SUPPORTED) ||
  392. (!phba->cfg_vport_restrict_login)) {
  393. ndlp = lpfc_setup_disc_node(vport, Did);
  394. if (ndlp) {
  395. lpfc_debugfs_disc_trc(vport,
  396. LPFC_DISC_TRC_CT,
  397. "Parse GID_FTrsp: "
  398. "did:x%x flg:x%x x%x",
  399. Did, ndlp->nlp_flag,
  400. vport->fc_flag);
  401. lpfc_printf_log(phba, KERN_INFO,
  402. LOG_DISCOVERY,
  403. "%d (%d):0238 Process "
  404. "x%x NameServer Rsp"
  405. "Data: x%x x%x x%x\n",
  406. phba->brd_no,
  407. vport->vpi, Did,
  408. ndlp->nlp_flag,
  409. vport->fc_flag,
  410. vport->fc_rscn_id_cnt);
  411. } else {
  412. lpfc_debugfs_disc_trc(vport,
  413. LPFC_DISC_TRC_CT,
  414. "Skip1 GID_FTrsp: "
  415. "did:x%x flg:x%x cnt:%d",
  416. Did, vport->fc_flag,
  417. vport->fc_rscn_id_cnt);
  418. lpfc_printf_log(phba, KERN_INFO,
  419. LOG_DISCOVERY,
  420. "%d (%d):0239 Skip x%x "
  421. "NameServer Rsp Data: "
  422. "x%x x%x\n",
  423. phba->brd_no,
  424. vport->vpi, Did,
  425. vport->fc_flag,
  426. vport->fc_rscn_id_cnt);
  427. }
  428. } else {
  429. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  430. (lpfc_rscn_payload_check(vport, Did))) {
  431. lpfc_debugfs_disc_trc(vport,
  432. LPFC_DISC_TRC_CT,
  433. "Query GID_FTrsp: "
  434. "did:x%x flg:x%x cnt:%d",
  435. Did, vport->fc_flag,
  436. vport->fc_rscn_id_cnt);
  437. if (lpfc_ns_cmd(vport,
  438. SLI_CTNS_GFF_ID,
  439. 0, Did) == 0)
  440. vport->num_disc_nodes++;
  441. }
  442. else {
  443. lpfc_debugfs_disc_trc(vport,
  444. LPFC_DISC_TRC_CT,
  445. "Skip2 GID_FTrsp: "
  446. "did:x%x flg:x%x cnt:%d",
  447. Did, vport->fc_flag,
  448. vport->fc_rscn_id_cnt);
  449. lpfc_printf_log(phba, KERN_INFO,
  450. LOG_DISCOVERY,
  451. "%d (%d):0245 Skip x%x "
  452. "NameServer Rsp Data: "
  453. "x%x x%x\n",
  454. phba->brd_no,
  455. vport->vpi, Did,
  456. vport->fc_flag,
  457. vport->fc_rscn_id_cnt);
  458. }
  459. }
  460. }
  461. if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
  462. goto nsout1;
  463. Cnt -= sizeof (uint32_t);
  464. }
  465. ctptr = NULL;
  466. }
  467. nsout1:
  468. list_del(&head);
  469. return 0;
  470. }
  471. static void
  472. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  473. struct lpfc_iocbq *rspiocb)
  474. {
  475. struct lpfc_vport *vport = cmdiocb->vport;
  476. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  477. IOCB_t *irsp;
  478. struct lpfc_dmabuf *bmp;
  479. struct lpfc_dmabuf *outp;
  480. struct lpfc_sli_ct_request *CTrsp;
  481. int rc;
  482. /* we pass cmdiocb to state machine which needs rspiocb as well */
  483. cmdiocb->context_un.rsp_iocb = rspiocb;
  484. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  485. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  486. irsp = &rspiocb->iocb;
  487. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  488. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  489. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  490. /* Don't bother processing response if vport is being torn down. */
  491. if (vport->load_flag & FC_UNLOADING)
  492. goto out;
  493. if (lpfc_els_chk_latt(vport) || lpfc_error_lost_link(irsp)) {
  494. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  495. "%d (%d):0216 Link event during NS query\n",
  496. phba->brd_no, vport->vpi);
  497. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  498. goto out;
  499. }
  500. if (irsp->ulpStatus) {
  501. /* Check for retry */
  502. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  503. if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
  504. (irsp->un.ulpWord[4] != IOERR_NO_RESOURCES))
  505. vport->fc_ns_retry++;
  506. /* CT command is being retried */
  507. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  508. vport->fc_ns_retry, 0);
  509. if (rc == 0)
  510. goto out;
  511. }
  512. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  513. lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
  514. "%d (%d):0257 GID_FT Query error: 0x%x 0x%x\n",
  515. phba->brd_no, vport->vpi, irsp->ulpStatus,
  516. vport->fc_ns_retry);
  517. } else {
  518. /* Good status, continue checking */
  519. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  520. if (CTrsp->CommandResponse.bits.CmdRsp ==
  521. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  522. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  523. "%d (%d):0208 NameServer Rsp "
  524. "Data: x%x\n",
  525. phba->brd_no, vport->vpi,
  526. vport->fc_flag);
  527. lpfc_ns_rsp(vport, outp,
  528. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  529. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  530. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  531. /* NameServer Rsp Error */
  532. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  533. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  534. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  535. "%d (%d):0269 No NameServer Entries "
  536. "Data: x%x x%x x%x x%x\n",
  537. phba->brd_no, vport->vpi,
  538. CTrsp->CommandResponse.bits.CmdRsp,
  539. (uint32_t) CTrsp->ReasonCode,
  540. (uint32_t) CTrsp->Explanation,
  541. vport->fc_flag);
  542. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  543. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  544. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  545. (uint32_t) CTrsp->ReasonCode,
  546. (uint32_t) CTrsp->Explanation);
  547. }
  548. else {
  549. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  550. "%d (%d):0240 NameServer Rsp Error "
  551. "Data: x%x x%x x%x x%x\n",
  552. phba->brd_no, vport->vpi,
  553. CTrsp->CommandResponse.bits.CmdRsp,
  554. (uint32_t) CTrsp->ReasonCode,
  555. (uint32_t) CTrsp->Explanation,
  556. vport->fc_flag);
  557. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  558. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  559. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  560. (uint32_t) CTrsp->ReasonCode,
  561. (uint32_t) CTrsp->Explanation);
  562. }
  563. } else {
  564. /* NameServer Rsp Error */
  565. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  566. "%d (%d):0241 NameServer Rsp Error "
  567. "Data: x%x x%x x%x x%x\n",
  568. phba->brd_no, vport->vpi,
  569. CTrsp->CommandResponse.bits.CmdRsp,
  570. (uint32_t) CTrsp->ReasonCode,
  571. (uint32_t) CTrsp->Explanation,
  572. vport->fc_flag);
  573. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  574. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  575. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  576. (uint32_t) CTrsp->ReasonCode,
  577. (uint32_t) CTrsp->Explanation);
  578. }
  579. }
  580. /* Link up / RSCN discovery */
  581. if (vport->num_disc_nodes == 0) {
  582. /*
  583. * The driver has cycled through all Nports in the RSCN payload.
  584. * Complete the handling by cleaning up and marking the
  585. * current driver state.
  586. */
  587. if (vport->port_state >= LPFC_DISC_AUTH) {
  588. if (vport->fc_flag & FC_RSCN_MODE) {
  589. lpfc_els_flush_rscn(vport);
  590. spin_lock_irq(shost->host_lock);
  591. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  592. spin_unlock_irq(shost->host_lock);
  593. }
  594. else
  595. lpfc_els_flush_rscn(vport);
  596. }
  597. lpfc_disc_start(vport);
  598. }
  599. out:
  600. lpfc_ct_free_iocb(phba, cmdiocb);
  601. return;
  602. }
  603. void
  604. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  605. struct lpfc_iocbq *rspiocb)
  606. {
  607. struct lpfc_vport *vport = cmdiocb->vport;
  608. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  609. IOCB_t *irsp = &rspiocb->iocb;
  610. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  611. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  612. struct lpfc_sli_ct_request *CTrsp;
  613. int did;
  614. uint8_t fbits;
  615. struct lpfc_nodelist *ndlp;
  616. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  617. did = be32_to_cpu(did);
  618. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  619. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  620. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  621. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  622. /* Good status, continue checking */
  623. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  624. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  625. if (CTrsp->CommandResponse.bits.CmdRsp ==
  626. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  627. if ((fbits & FC4_FEATURE_INIT) &&
  628. !(fbits & FC4_FEATURE_TARGET)) {
  629. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  630. "%d (%d):0270 Skip x%x GFF "
  631. "NameServer Rsp Data: (init) "
  632. "x%x x%x\n", phba->brd_no,
  633. vport->vpi, did, fbits,
  634. vport->fc_rscn_id_cnt);
  635. goto out;
  636. }
  637. }
  638. }
  639. else {
  640. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  641. "%d (%d):0267 NameServer GFF Rsp"
  642. " x%x Error (%d %d) Data: x%x x%x\n",
  643. phba->brd_no, vport->vpi, did,
  644. irsp->ulpStatus, irsp->un.ulpWord[4],
  645. vport->fc_flag, vport->fc_rscn_id_cnt)
  646. }
  647. /* This is a target port, unregistered port, or the GFF_ID failed */
  648. ndlp = lpfc_setup_disc_node(vport, did);
  649. if (ndlp) {
  650. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  651. "%d (%d):0242 Process x%x GFF "
  652. "NameServer Rsp Data: x%x x%x x%x\n",
  653. phba->brd_no, vport->vpi,
  654. did, ndlp->nlp_flag, vport->fc_flag,
  655. vport->fc_rscn_id_cnt);
  656. } else {
  657. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  658. "%d (%d):0243 Skip x%x GFF "
  659. "NameServer Rsp Data: x%x x%x\n",
  660. phba->brd_no, vport->vpi, did,
  661. vport->fc_flag, vport->fc_rscn_id_cnt);
  662. }
  663. out:
  664. /* Link up / RSCN discovery */
  665. if (vport->num_disc_nodes)
  666. vport->num_disc_nodes--;
  667. if (vport->num_disc_nodes == 0) {
  668. /*
  669. * The driver has cycled through all Nports in the RSCN payload.
  670. * Complete the handling by cleaning up and marking the
  671. * current driver state.
  672. */
  673. if (vport->port_state >= LPFC_DISC_AUTH) {
  674. if (vport->fc_flag & FC_RSCN_MODE) {
  675. lpfc_els_flush_rscn(vport);
  676. spin_lock_irq(shost->host_lock);
  677. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  678. spin_unlock_irq(shost->host_lock);
  679. }
  680. else
  681. lpfc_els_flush_rscn(vport);
  682. }
  683. lpfc_disc_start(vport);
  684. }
  685. lpfc_ct_free_iocb(phba, cmdiocb);
  686. return;
  687. }
  688. static void
  689. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  690. struct lpfc_iocbq *rspiocb)
  691. {
  692. struct lpfc_vport *vport = cmdiocb->vport;
  693. struct lpfc_dmabuf *inp;
  694. struct lpfc_dmabuf *outp;
  695. IOCB_t *irsp;
  696. struct lpfc_sli_ct_request *CTrsp;
  697. int cmdcode, rc;
  698. uint8_t retry;
  699. uint32_t latt;
  700. /* we pass cmdiocb to state machine which needs rspiocb as well */
  701. cmdiocb->context_un.rsp_iocb = rspiocb;
  702. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  703. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  704. irsp = &rspiocb->iocb;
  705. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  706. CommandResponse.bits.CmdRsp);
  707. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  708. latt = lpfc_els_chk_latt(vport);
  709. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  710. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  711. "%d (%d):0209 RFT request completes, latt %d, "
  712. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  713. phba->brd_no, vport->vpi, latt, irsp->ulpStatus,
  714. CTrsp->CommandResponse.bits.CmdRsp,
  715. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  716. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  717. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  718. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  719. if (irsp->ulpStatus) {
  720. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  721. "%d (%d):0268 NS cmd %x Error (%d %d)\n",
  722. phba->brd_no, vport->vpi, cmdcode,
  723. irsp->ulpStatus, irsp->un.ulpWord[4]);
  724. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  725. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  726. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
  727. goto out;
  728. retry = cmdiocb->retry;
  729. if (retry >= LPFC_MAX_NS_RETRY)
  730. goto out;
  731. retry++;
  732. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  733. "%d (%d):0216 Retrying NS cmd %x\n",
  734. phba->brd_no, vport->vpi, cmdcode);
  735. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  736. if (rc == 0)
  737. goto out;
  738. }
  739. out:
  740. lpfc_ct_free_iocb(phba, cmdiocb);
  741. return;
  742. }
  743. static void
  744. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  745. struct lpfc_iocbq *rspiocb)
  746. {
  747. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  748. return;
  749. }
  750. static void
  751. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  752. struct lpfc_iocbq *rspiocb)
  753. {
  754. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  755. return;
  756. }
  757. static void
  758. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  759. struct lpfc_iocbq *rspiocb)
  760. {
  761. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  762. return;
  763. }
  764. static void
  765. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  766. struct lpfc_iocbq *rspiocb)
  767. {
  768. IOCB_t *irsp = &rspiocb->iocb;
  769. struct lpfc_vport *vport = cmdiocb->vport;
  770. if (irsp->ulpStatus != IOSTAT_SUCCESS)
  771. vport->fc_flag |= FC_RFF_NOT_SUPPORTED;
  772. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  773. return;
  774. }
  775. int
  776. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  777. size_t size)
  778. {
  779. int n;
  780. uint8_t *wwn = vport->phba->wwpn;
  781. n = snprintf(symbol, size,
  782. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  783. wwn[0], wwn[1], wwn[2], wwn[3],
  784. wwn[4], wwn[5], wwn[6], wwn[7]);
  785. if (vport->port_type == LPFC_PHYSICAL_PORT)
  786. return n;
  787. if (n < size)
  788. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  789. if (n < size && vport->vname)
  790. n += snprintf(symbol + n, size - n, " VName-%s", vport->vname);
  791. return n;
  792. }
  793. int
  794. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  795. size_t size)
  796. {
  797. char fwrev[16];
  798. int n;
  799. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  800. n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
  801. vport->phba->ModelName, fwrev, lpfc_release_version);
  802. return n;
  803. }
  804. /*
  805. * lpfc_ns_cmd
  806. * Description:
  807. * Issue Cmd to NameServer
  808. * SLI_CTNS_GID_FT
  809. * LI_CTNS_RFT_ID
  810. */
  811. int
  812. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  813. uint8_t retry, uint32_t context)
  814. {
  815. struct lpfc_nodelist * ndlp;
  816. struct lpfc_hba *phba = vport->phba;
  817. struct lpfc_dmabuf *mp, *bmp;
  818. struct lpfc_sli_ct_request *CtReq;
  819. struct ulp_bde64 *bpl;
  820. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  821. struct lpfc_iocbq *) = NULL;
  822. uint32_t rsp_size = 1024;
  823. size_t size;
  824. int rc = 0;
  825. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  826. if (ndlp == NULL || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  827. rc=1;
  828. goto ns_cmd_exit;
  829. }
  830. /* fill in BDEs for command */
  831. /* Allocate buffer for command payload */
  832. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  833. if (!mp) {
  834. rc=2;
  835. goto ns_cmd_exit;
  836. }
  837. INIT_LIST_HEAD(&mp->list);
  838. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  839. if (!mp->virt) {
  840. rc=3;
  841. goto ns_cmd_free_mp;
  842. }
  843. /* Allocate buffer for Buffer ptr list */
  844. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  845. if (!bmp) {
  846. rc=4;
  847. goto ns_cmd_free_mpvirt;
  848. }
  849. INIT_LIST_HEAD(&bmp->list);
  850. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  851. if (!bmp->virt) {
  852. rc=5;
  853. goto ns_cmd_free_bmp;
  854. }
  855. /* NameServer Req */
  856. lpfc_printf_log(phba, KERN_INFO ,LOG_DISCOVERY,
  857. "%d (%d):0236 NameServer Req Data: x%x x%x x%x\n",
  858. phba->brd_no, vport->vpi, cmdcode, vport->fc_flag,
  859. vport->fc_rscn_id_cnt);
  860. bpl = (struct ulp_bde64 *) bmp->virt;
  861. memset(bpl, 0, sizeof(struct ulp_bde64));
  862. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  863. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  864. bpl->tus.f.bdeFlags = 0;
  865. if (cmdcode == SLI_CTNS_GID_FT)
  866. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  867. else if (cmdcode == SLI_CTNS_GFF_ID)
  868. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  869. else if (cmdcode == SLI_CTNS_RFT_ID)
  870. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  871. else if (cmdcode == SLI_CTNS_RNN_ID)
  872. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  873. else if (cmdcode == SLI_CTNS_RSPN_ID)
  874. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  875. else if (cmdcode == SLI_CTNS_RSNN_NN)
  876. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  877. else if (cmdcode == SLI_CTNS_RFF_ID)
  878. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  879. else
  880. bpl->tus.f.bdeSize = 0;
  881. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  882. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  883. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  884. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  885. CtReq->RevisionId.bits.InId = 0;
  886. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  887. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  888. CtReq->CommandResponse.bits.Size = 0;
  889. switch (cmdcode) {
  890. case SLI_CTNS_GID_FT:
  891. CtReq->CommandResponse.bits.CmdRsp =
  892. be16_to_cpu(SLI_CTNS_GID_FT);
  893. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  894. if (vport->port_state < LPFC_NS_QRY)
  895. vport->port_state = LPFC_NS_QRY;
  896. lpfc_set_disctmo(vport);
  897. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  898. rsp_size = FC_MAX_NS_RSP;
  899. break;
  900. case SLI_CTNS_GFF_ID:
  901. CtReq->CommandResponse.bits.CmdRsp =
  902. be16_to_cpu(SLI_CTNS_GFF_ID);
  903. CtReq->un.gff.PortId = be32_to_cpu(context);
  904. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  905. break;
  906. case SLI_CTNS_RFT_ID:
  907. CtReq->CommandResponse.bits.CmdRsp =
  908. be16_to_cpu(SLI_CTNS_RFT_ID);
  909. CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
  910. CtReq->un.rft.fcpReg = 1;
  911. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  912. break;
  913. case SLI_CTNS_RNN_ID:
  914. CtReq->CommandResponse.bits.CmdRsp =
  915. be16_to_cpu(SLI_CTNS_RNN_ID);
  916. CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
  917. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  918. sizeof (struct lpfc_name));
  919. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  920. break;
  921. case SLI_CTNS_RSPN_ID:
  922. CtReq->CommandResponse.bits.CmdRsp =
  923. be16_to_cpu(SLI_CTNS_RSPN_ID);
  924. CtReq->un.rspn.PortId = be32_to_cpu(vport->fc_myDID);
  925. size = sizeof(CtReq->un.rspn.symbname);
  926. CtReq->un.rspn.len =
  927. lpfc_vport_symbolic_port_name(vport,
  928. CtReq->un.rspn.symbname, size);
  929. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  930. break;
  931. case SLI_CTNS_RSNN_NN:
  932. CtReq->CommandResponse.bits.CmdRsp =
  933. be16_to_cpu(SLI_CTNS_RSNN_NN);
  934. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  935. sizeof (struct lpfc_name));
  936. size = sizeof(CtReq->un.rsnn.symbname);
  937. CtReq->un.rsnn.len =
  938. lpfc_vport_symbolic_node_name(vport,
  939. CtReq->un.rsnn.symbname, size);
  940. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  941. break;
  942. case SLI_CTNS_RFF_ID:
  943. vport->fc_flag &= ~FC_RFF_NOT_SUPPORTED;
  944. CtReq->CommandResponse.bits.CmdRsp =
  945. be16_to_cpu(SLI_CTNS_RFF_ID);
  946. CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);;
  947. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  948. CtReq->un.rff.type_code = FC_FCP_DATA;
  949. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  950. break;
  951. }
  952. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  953. /* On success, The cmpl function will free the buffers */
  954. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  955. "Issue CT cmd: cmd:x%x did:x%x",
  956. cmdcode, ndlp->nlp_DID, 0);
  957. return 0;
  958. }
  959. rc=6;
  960. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  961. ns_cmd_free_bmp:
  962. kfree(bmp);
  963. ns_cmd_free_mpvirt:
  964. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  965. ns_cmd_free_mp:
  966. kfree(mp);
  967. ns_cmd_exit:
  968. lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
  969. "%d (%d):0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  970. phba->brd_no, vport->vpi, cmdcode, rc, vport->fc_flag,
  971. vport->fc_rscn_id_cnt);
  972. return 1;
  973. }
  974. static void
  975. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  976. struct lpfc_iocbq * rspiocb)
  977. {
  978. struct lpfc_dmabuf *inp = cmdiocb->context1;
  979. struct lpfc_dmabuf *outp = cmdiocb->context2;
  980. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  981. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  982. struct lpfc_nodelist *ndlp;
  983. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  984. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  985. struct lpfc_vport *vport = cmdiocb->vport;
  986. IOCB_t *irsp = &rspiocb->iocb;
  987. uint32_t latt;
  988. latt = lpfc_els_chk_latt(vport);
  989. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  990. "FDMI cmpl: status:x%x/x%x latt:%d",
  991. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  992. if (latt || irsp->ulpStatus) {
  993. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  994. "%d (%d):0229 FDMI cmd %04x failed, latt = %d "
  995. "ulpStatus: x%x, rid x%x\n",
  996. phba->brd_no, vport->vpi,
  997. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  998. irsp->un.ulpWord[4]);
  999. lpfc_ct_free_iocb(phba, cmdiocb);
  1000. return;
  1001. }
  1002. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1003. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  1004. /* FDMI rsp failed */
  1005. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1006. "%d (%d):0220 FDMI rsp failed Data: x%x\n",
  1007. phba->brd_no, vport->vpi,
  1008. be16_to_cpu(fdmi_cmd));
  1009. }
  1010. switch (be16_to_cpu(fdmi_cmd)) {
  1011. case SLI_MGMT_RHBA:
  1012. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  1013. break;
  1014. case SLI_MGMT_RPA:
  1015. break;
  1016. case SLI_MGMT_DHBA:
  1017. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  1018. break;
  1019. case SLI_MGMT_DPRT:
  1020. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  1021. break;
  1022. }
  1023. lpfc_ct_free_iocb(phba, cmdiocb);
  1024. return;
  1025. }
  1026. int
  1027. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  1028. {
  1029. struct lpfc_hba *phba = vport->phba;
  1030. struct lpfc_dmabuf *mp, *bmp;
  1031. struct lpfc_sli_ct_request *CtReq;
  1032. struct ulp_bde64 *bpl;
  1033. uint32_t size;
  1034. REG_HBA *rh;
  1035. PORT_ENTRY *pe;
  1036. REG_PORT_ATTRIBUTE *pab;
  1037. ATTRIBUTE_BLOCK *ab;
  1038. ATTRIBUTE_ENTRY *ae;
  1039. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1040. struct lpfc_iocbq *);
  1041. /* fill in BDEs for command */
  1042. /* Allocate buffer for command payload */
  1043. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1044. if (!mp)
  1045. goto fdmi_cmd_exit;
  1046. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  1047. if (!mp->virt)
  1048. goto fdmi_cmd_free_mp;
  1049. /* Allocate buffer for Buffer ptr list */
  1050. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1051. if (!bmp)
  1052. goto fdmi_cmd_free_mpvirt;
  1053. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  1054. if (!bmp->virt)
  1055. goto fdmi_cmd_free_bmp;
  1056. INIT_LIST_HEAD(&mp->list);
  1057. INIT_LIST_HEAD(&bmp->list);
  1058. /* FDMI request */
  1059. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1060. "%d (%d):0218 FDMI Request Data: x%x x%x x%x\n",
  1061. phba->brd_no, vport->vpi, vport->fc_flag,
  1062. vport->port_state, cmdcode);
  1063. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1064. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1065. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1066. CtReq->RevisionId.bits.InId = 0;
  1067. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  1068. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  1069. size = 0;
  1070. switch (cmdcode) {
  1071. case SLI_MGMT_RHBA:
  1072. {
  1073. lpfc_vpd_t *vp = &phba->vpd;
  1074. uint32_t i, j, incr;
  1075. int len;
  1076. CtReq->CommandResponse.bits.CmdRsp =
  1077. be16_to_cpu(SLI_MGMT_RHBA);
  1078. CtReq->CommandResponse.bits.Size = 0;
  1079. rh = (REG_HBA *) & CtReq->un.PortID;
  1080. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  1081. sizeof (struct lpfc_name));
  1082. /* One entry (port) per adapter */
  1083. rh->rpl.EntryCnt = be32_to_cpu(1);
  1084. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  1085. sizeof (struct lpfc_name));
  1086. /* point to the HBA attribute block */
  1087. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  1088. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  1089. ab->EntryCnt = 0;
  1090. /* Point to the beginning of the first HBA attribute
  1091. entry */
  1092. /* #1 HBA attribute entry */
  1093. size += FOURBYTES;
  1094. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1095. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  1096. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  1097. + sizeof (struct lpfc_name));
  1098. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1099. sizeof (struct lpfc_name));
  1100. ab->EntryCnt++;
  1101. size += FOURBYTES + sizeof (struct lpfc_name);
  1102. /* #2 HBA attribute entry */
  1103. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1104. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  1105. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  1106. len = strlen(ae->un.Manufacturer);
  1107. len += (len & 3) ? (4 - (len & 3)) : 4;
  1108. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1109. ab->EntryCnt++;
  1110. size += FOURBYTES + len;
  1111. /* #3 HBA attribute entry */
  1112. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1113. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  1114. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  1115. len = strlen(ae->un.SerialNumber);
  1116. len += (len & 3) ? (4 - (len & 3)) : 4;
  1117. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1118. ab->EntryCnt++;
  1119. size += FOURBYTES + len;
  1120. /* #4 HBA attribute entry */
  1121. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1122. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  1123. strcpy(ae->un.Model, phba->ModelName);
  1124. len = strlen(ae->un.Model);
  1125. len += (len & 3) ? (4 - (len & 3)) : 4;
  1126. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1127. ab->EntryCnt++;
  1128. size += FOURBYTES + len;
  1129. /* #5 HBA attribute entry */
  1130. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1131. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  1132. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  1133. len = strlen(ae->un.ModelDescription);
  1134. len += (len & 3) ? (4 - (len & 3)) : 4;
  1135. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1136. ab->EntryCnt++;
  1137. size += FOURBYTES + len;
  1138. /* #6 HBA attribute entry */
  1139. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1140. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  1141. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  1142. /* Convert JEDEC ID to ascii for hardware version */
  1143. incr = vp->rev.biuRev;
  1144. for (i = 0; i < 8; i++) {
  1145. j = (incr & 0xf);
  1146. if (j <= 9)
  1147. ae->un.HardwareVersion[7 - i] =
  1148. (char)((uint8_t) 0x30 +
  1149. (uint8_t) j);
  1150. else
  1151. ae->un.HardwareVersion[7 - i] =
  1152. (char)((uint8_t) 0x61 +
  1153. (uint8_t) (j - 10));
  1154. incr = (incr >> 4);
  1155. }
  1156. ab->EntryCnt++;
  1157. size += FOURBYTES + 8;
  1158. /* #7 HBA attribute entry */
  1159. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1160. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  1161. strcpy(ae->un.DriverVersion, lpfc_release_version);
  1162. len = strlen(ae->un.DriverVersion);
  1163. len += (len & 3) ? (4 - (len & 3)) : 4;
  1164. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1165. ab->EntryCnt++;
  1166. size += FOURBYTES + len;
  1167. /* #8 HBA attribute entry */
  1168. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1169. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  1170. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  1171. len = strlen(ae->un.OptionROMVersion);
  1172. len += (len & 3) ? (4 - (len & 3)) : 4;
  1173. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1174. ab->EntryCnt++;
  1175. size += FOURBYTES + len;
  1176. /* #9 HBA attribute entry */
  1177. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1178. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  1179. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  1180. 1);
  1181. len = strlen(ae->un.FirmwareVersion);
  1182. len += (len & 3) ? (4 - (len & 3)) : 4;
  1183. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1184. ab->EntryCnt++;
  1185. size += FOURBYTES + len;
  1186. /* #10 HBA attribute entry */
  1187. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1188. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  1189. sprintf(ae->un.OsNameVersion, "%s %s %s",
  1190. init_utsname()->sysname,
  1191. init_utsname()->release,
  1192. init_utsname()->version);
  1193. len = strlen(ae->un.OsNameVersion);
  1194. len += (len & 3) ? (4 - (len & 3)) : 4;
  1195. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1196. ab->EntryCnt++;
  1197. size += FOURBYTES + len;
  1198. /* #11 HBA attribute entry */
  1199. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1200. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  1201. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1202. ae->un.MaxCTPayloadLen = (65 * 4096);
  1203. ab->EntryCnt++;
  1204. size += FOURBYTES + 4;
  1205. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  1206. /* Total size */
  1207. size = GID_REQUEST_SZ - 4 + size;
  1208. }
  1209. break;
  1210. case SLI_MGMT_RPA:
  1211. {
  1212. lpfc_vpd_t *vp;
  1213. struct serv_parm *hsp;
  1214. int len;
  1215. vp = &phba->vpd;
  1216. CtReq->CommandResponse.bits.CmdRsp =
  1217. be16_to_cpu(SLI_MGMT_RPA);
  1218. CtReq->CommandResponse.bits.Size = 0;
  1219. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  1220. size = sizeof (struct lpfc_name) + FOURBYTES;
  1221. memcpy((uint8_t *) & pab->PortName,
  1222. (uint8_t *) & vport->fc_sparam.portName,
  1223. sizeof (struct lpfc_name));
  1224. pab->ab.EntryCnt = 0;
  1225. /* #1 Port attribute entry */
  1226. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1227. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  1228. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  1229. ae->un.SupportFC4Types[2] = 1;
  1230. ae->un.SupportFC4Types[7] = 1;
  1231. pab->ab.EntryCnt++;
  1232. size += FOURBYTES + 32;
  1233. /* #2 Port attribute entry */
  1234. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1235. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  1236. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1237. ae->un.SupportSpeed = 0;
  1238. if (phba->lmt & LMT_10Gb)
  1239. ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
  1240. if (phba->lmt & LMT_8Gb)
  1241. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  1242. if (phba->lmt & LMT_4Gb)
  1243. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  1244. if (phba->lmt & LMT_2Gb)
  1245. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  1246. if (phba->lmt & LMT_1Gb)
  1247. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  1248. pab->ab.EntryCnt++;
  1249. size += FOURBYTES + 4;
  1250. /* #3 Port attribute entry */
  1251. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1252. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  1253. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1254. switch(phba->fc_linkspeed) {
  1255. case LA_1GHZ_LINK:
  1256. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  1257. break;
  1258. case LA_2GHZ_LINK:
  1259. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  1260. break;
  1261. case LA_4GHZ_LINK:
  1262. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  1263. break;
  1264. case LA_8GHZ_LINK:
  1265. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  1266. break;
  1267. default:
  1268. ae->un.PortSpeed =
  1269. HBA_PORTSPEED_UNKNOWN;
  1270. break;
  1271. }
  1272. pab->ab.EntryCnt++;
  1273. size += FOURBYTES + 4;
  1274. /* #4 Port attribute entry */
  1275. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1276. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  1277. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1278. hsp = (struct serv_parm *) & vport->fc_sparam;
  1279. ae->un.MaxFrameSize =
  1280. (((uint32_t) hsp->cmn.
  1281. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  1282. bbRcvSizeLsb;
  1283. pab->ab.EntryCnt++;
  1284. size += FOURBYTES + 4;
  1285. /* #5 Port attribute entry */
  1286. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1287. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  1288. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  1289. len = strlen((char *)ae->un.OsDeviceName);
  1290. len += (len & 3) ? (4 - (len & 3)) : 4;
  1291. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1292. pab->ab.EntryCnt++;
  1293. size += FOURBYTES + len;
  1294. if (phba->cfg_fdmi_on == 2) {
  1295. /* #6 Port attribute entry */
  1296. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  1297. size);
  1298. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  1299. sprintf(ae->un.HostName, "%s",
  1300. init_utsname()->nodename);
  1301. len = strlen(ae->un.HostName);
  1302. len += (len & 3) ? (4 - (len & 3)) : 4;
  1303. ae->ad.bits.AttrLen =
  1304. be16_to_cpu(FOURBYTES + len);
  1305. pab->ab.EntryCnt++;
  1306. size += FOURBYTES + len;
  1307. }
  1308. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  1309. /* Total size */
  1310. size = GID_REQUEST_SZ - 4 + size;
  1311. }
  1312. break;
  1313. case SLI_MGMT_DHBA:
  1314. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  1315. CtReq->CommandResponse.bits.Size = 0;
  1316. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1317. memcpy((uint8_t *) & pe->PortName,
  1318. (uint8_t *) & vport->fc_sparam.portName,
  1319. sizeof (struct lpfc_name));
  1320. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1321. break;
  1322. case SLI_MGMT_DPRT:
  1323. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  1324. CtReq->CommandResponse.bits.Size = 0;
  1325. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1326. memcpy((uint8_t *) & pe->PortName,
  1327. (uint8_t *) & vport->fc_sparam.portName,
  1328. sizeof (struct lpfc_name));
  1329. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1330. break;
  1331. }
  1332. bpl = (struct ulp_bde64 *) bmp->virt;
  1333. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1334. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1335. bpl->tus.f.bdeFlags = 0;
  1336. bpl->tus.f.bdeSize = size;
  1337. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1338. cmpl = lpfc_cmpl_ct_cmd_fdmi;
  1339. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
  1340. return 0;
  1341. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1342. fdmi_cmd_free_bmp:
  1343. kfree(bmp);
  1344. fdmi_cmd_free_mpvirt:
  1345. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1346. fdmi_cmd_free_mp:
  1347. kfree(mp);
  1348. fdmi_cmd_exit:
  1349. /* Issue FDMI request failed */
  1350. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1351. "%d (%d):0244 Issue FDMI request failed Data: x%x\n",
  1352. phba->brd_no, vport->vpi, cmdcode);
  1353. return 1;
  1354. }
  1355. void
  1356. lpfc_fdmi_tmo(unsigned long ptr)
  1357. {
  1358. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1359. struct lpfc_hba *phba = vport->phba;
  1360. unsigned long iflag;
  1361. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1362. if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
  1363. vport->work_port_events |= WORKER_FDMI_TMO;
  1364. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1365. spin_lock_irqsave(&phba->hbalock, iflag);
  1366. if (phba->work_wait)
  1367. lpfc_worker_wake_up(phba);
  1368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1369. }
  1370. else
  1371. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1372. }
  1373. void
  1374. lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
  1375. {
  1376. struct lpfc_nodelist *ndlp;
  1377. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1378. if (ndlp) {
  1379. if (init_utsname()->nodename[0] != '\0')
  1380. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  1381. else
  1382. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  1383. }
  1384. return;
  1385. }
  1386. void
  1387. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  1388. {
  1389. struct lpfc_sli *psli = &phba->sli;
  1390. lpfc_vpd_t *vp = &phba->vpd;
  1391. uint32_t b1, b2, b3, b4, i, rev;
  1392. char c;
  1393. uint32_t *ptr, str[4];
  1394. uint8_t *fwname;
  1395. if (vp->rev.rBit) {
  1396. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1397. rev = vp->rev.sli2FwRev;
  1398. else
  1399. rev = vp->rev.sli1FwRev;
  1400. b1 = (rev & 0x0000f000) >> 12;
  1401. b2 = (rev & 0x00000f00) >> 8;
  1402. b3 = (rev & 0x000000c0) >> 6;
  1403. b4 = (rev & 0x00000030) >> 4;
  1404. switch (b4) {
  1405. case 0:
  1406. c = 'N';
  1407. break;
  1408. case 1:
  1409. c = 'A';
  1410. break;
  1411. case 2:
  1412. c = 'B';
  1413. break;
  1414. default:
  1415. c = 0;
  1416. break;
  1417. }
  1418. b4 = (rev & 0x0000000f);
  1419. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1420. fwname = vp->rev.sli2FwName;
  1421. else
  1422. fwname = vp->rev.sli1FwName;
  1423. for (i = 0; i < 16; i++)
  1424. if (fwname[i] == 0x20)
  1425. fwname[i] = 0;
  1426. ptr = (uint32_t*)fwname;
  1427. for (i = 0; i < 3; i++)
  1428. str[i] = be32_to_cpu(*ptr++);
  1429. if (c == 0) {
  1430. if (flag)
  1431. sprintf(fwrevision, "%d.%d%d (%s)",
  1432. b1, b2, b3, (char *)str);
  1433. else
  1434. sprintf(fwrevision, "%d.%d%d", b1,
  1435. b2, b3);
  1436. } else {
  1437. if (flag)
  1438. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  1439. b1, b2, b3, c,
  1440. b4, (char *)str);
  1441. else
  1442. sprintf(fwrevision, "%d.%d%d%c%d",
  1443. b1, b2, b3, c, b4);
  1444. }
  1445. } else {
  1446. rev = vp->rev.smFwRev;
  1447. b1 = (rev & 0xff000000) >> 24;
  1448. b2 = (rev & 0x00f00000) >> 20;
  1449. b3 = (rev & 0x000f0000) >> 16;
  1450. c = (rev & 0x0000ff00) >> 8;
  1451. b4 = (rev & 0x000000ff);
  1452. if (flag)
  1453. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1454. b2, b3, c, b4);
  1455. else
  1456. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1457. b2, b3, c, b4);
  1458. }
  1459. return;
  1460. }