lpfc_ct.c 50 KB

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