lpfc_ct.c 51 KB

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