lpfc_ct.c 50 KB

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