lpfc_ct.c 50 KB

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