lpfc_ct.c 53 KB

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