lpfc_ct.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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. if (vport->fc_flag & FC_RSCN_MODE)
  493. lpfc_els_flush_rscn(vport);
  494. goto out;
  495. }
  496. if (lpfc_els_chk_latt(vport)) {
  497. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  498. "0216 Link event during NS query\n");
  499. if (vport->fc_flag & FC_RSCN_MODE)
  500. lpfc_els_flush_rscn(vport);
  501. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  502. goto out;
  503. }
  504. if (lpfc_error_lost_link(irsp)) {
  505. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  506. "0226 NS query failed due to link event\n");
  507. if (vport->fc_flag & FC_RSCN_MODE)
  508. lpfc_els_flush_rscn(vport);
  509. goto out;
  510. }
  511. if (irsp->ulpStatus) {
  512. /* Check for retry */
  513. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  514. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  515. irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
  516. vport->fc_ns_retry++;
  517. /* CT command is being retried */
  518. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  519. vport->fc_ns_retry, 0);
  520. if (rc == 0)
  521. goto out;
  522. }
  523. if (vport->fc_flag & FC_RSCN_MODE)
  524. lpfc_els_flush_rscn(vport);
  525. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  526. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  527. "0257 GID_FT Query error: 0x%x 0x%x\n",
  528. irsp->ulpStatus, vport->fc_ns_retry);
  529. } else {
  530. /* Good status, continue checking */
  531. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  532. if (CTrsp->CommandResponse.bits.CmdRsp ==
  533. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  534. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  535. "0208 NameServer Rsp Data: x%x\n",
  536. vport->fc_flag);
  537. lpfc_ns_rsp(vport, outp,
  538. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  539. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  540. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  541. /* NameServer Rsp Error */
  542. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  543. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  544. lpfc_printf_vlog(vport, KERN_INFO,
  545. LOG_DISCOVERY,
  546. "0269 No NameServer Entries "
  547. "Data: x%x x%x x%x x%x\n",
  548. CTrsp->CommandResponse.bits.CmdRsp,
  549. (uint32_t) CTrsp->ReasonCode,
  550. (uint32_t) CTrsp->Explanation,
  551. vport->fc_flag);
  552. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  553. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  554. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  555. (uint32_t) CTrsp->ReasonCode,
  556. (uint32_t) CTrsp->Explanation);
  557. } else {
  558. lpfc_printf_vlog(vport, KERN_INFO,
  559. LOG_DISCOVERY,
  560. "0240 NameServer Rsp Error "
  561. "Data: x%x x%x x%x x%x\n",
  562. CTrsp->CommandResponse.bits.CmdRsp,
  563. (uint32_t) CTrsp->ReasonCode,
  564. (uint32_t) CTrsp->Explanation,
  565. vport->fc_flag);
  566. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  567. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  568. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  569. (uint32_t) CTrsp->ReasonCode,
  570. (uint32_t) CTrsp->Explanation);
  571. }
  572. } else {
  573. /* NameServer Rsp Error */
  574. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  575. "0241 NameServer Rsp Error "
  576. "Data: x%x x%x x%x x%x\n",
  577. CTrsp->CommandResponse.bits.CmdRsp,
  578. (uint32_t) CTrsp->ReasonCode,
  579. (uint32_t) CTrsp->Explanation,
  580. vport->fc_flag);
  581. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  582. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  583. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  584. (uint32_t) CTrsp->ReasonCode,
  585. (uint32_t) CTrsp->Explanation);
  586. }
  587. }
  588. /* Link up / RSCN discovery */
  589. if (vport->num_disc_nodes == 0) {
  590. /*
  591. * The driver has cycled through all Nports in the RSCN payload.
  592. * Complete the handling by cleaning up and marking the
  593. * current driver state.
  594. */
  595. if (vport->port_state >= LPFC_DISC_AUTH) {
  596. if (vport->fc_flag & FC_RSCN_MODE) {
  597. lpfc_els_flush_rscn(vport);
  598. spin_lock_irq(shost->host_lock);
  599. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  600. spin_unlock_irq(shost->host_lock);
  601. }
  602. else
  603. lpfc_els_flush_rscn(vport);
  604. }
  605. lpfc_disc_start(vport);
  606. }
  607. out:
  608. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  609. lpfc_ct_free_iocb(phba, cmdiocb);
  610. return;
  611. }
  612. static void
  613. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  614. struct lpfc_iocbq *rspiocb)
  615. {
  616. struct lpfc_vport *vport = cmdiocb->vport;
  617. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  618. IOCB_t *irsp = &rspiocb->iocb;
  619. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  620. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  621. struct lpfc_sli_ct_request *CTrsp;
  622. int did, rc, retry;
  623. uint8_t fbits;
  624. struct lpfc_nodelist *ndlp;
  625. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  626. did = be32_to_cpu(did);
  627. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  628. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  629. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  630. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  631. /* Good status, continue checking */
  632. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  633. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  634. if (CTrsp->CommandResponse.bits.CmdRsp ==
  635. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  636. if ((fbits & FC4_FEATURE_INIT) &&
  637. !(fbits & FC4_FEATURE_TARGET)) {
  638. lpfc_printf_vlog(vport, KERN_INFO,
  639. LOG_DISCOVERY,
  640. "0270 Skip x%x GFF "
  641. "NameServer Rsp Data: (init) "
  642. "x%x x%x\n", did, fbits,
  643. vport->fc_rscn_id_cnt);
  644. goto out;
  645. }
  646. }
  647. }
  648. else {
  649. /* Check for retry */
  650. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  651. retry = 1;
  652. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  653. switch (irsp->un.ulpWord[4]) {
  654. case IOERR_NO_RESOURCES:
  655. /* We don't increment the retry
  656. * count for this case.
  657. */
  658. break;
  659. case IOERR_LINK_DOWN:
  660. case IOERR_SLI_ABORTED:
  661. case IOERR_SLI_DOWN:
  662. retry = 0;
  663. break;
  664. default:
  665. cmdiocb->retry++;
  666. }
  667. }
  668. else
  669. cmdiocb->retry++;
  670. if (retry) {
  671. /* CT command is being retried */
  672. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  673. cmdiocb->retry, did);
  674. if (rc == 0) {
  675. /* success */
  676. lpfc_ct_free_iocb(phba, cmdiocb);
  677. return;
  678. }
  679. }
  680. }
  681. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  682. "0267 NameServer GFF Rsp "
  683. "x%x Error (%d %d) Data: x%x x%x\n",
  684. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  685. vport->fc_flag, vport->fc_rscn_id_cnt);
  686. }
  687. /* This is a target port, unregistered port, or the GFF_ID failed */
  688. ndlp = lpfc_setup_disc_node(vport, did);
  689. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  690. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  691. "0242 Process x%x GFF "
  692. "NameServer Rsp Data: x%x x%x x%x\n",
  693. did, ndlp->nlp_flag, vport->fc_flag,
  694. vport->fc_rscn_id_cnt);
  695. } else {
  696. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  697. "0243 Skip x%x GFF "
  698. "NameServer Rsp Data: x%x x%x\n", did,
  699. vport->fc_flag, vport->fc_rscn_id_cnt);
  700. }
  701. out:
  702. /* Link up / RSCN discovery */
  703. if (vport->num_disc_nodes)
  704. vport->num_disc_nodes--;
  705. if (vport->num_disc_nodes == 0) {
  706. /*
  707. * The driver has cycled through all Nports in the RSCN payload.
  708. * Complete the handling by cleaning up and marking the
  709. * current driver state.
  710. */
  711. if (vport->port_state >= LPFC_DISC_AUTH) {
  712. if (vport->fc_flag & FC_RSCN_MODE) {
  713. lpfc_els_flush_rscn(vport);
  714. spin_lock_irq(shost->host_lock);
  715. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  716. spin_unlock_irq(shost->host_lock);
  717. }
  718. else
  719. lpfc_els_flush_rscn(vport);
  720. }
  721. lpfc_disc_start(vport);
  722. }
  723. lpfc_ct_free_iocb(phba, cmdiocb);
  724. return;
  725. }
  726. static void
  727. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  728. struct lpfc_iocbq *rspiocb)
  729. {
  730. struct lpfc_vport *vport = cmdiocb->vport;
  731. struct lpfc_dmabuf *inp;
  732. struct lpfc_dmabuf *outp;
  733. IOCB_t *irsp;
  734. struct lpfc_sli_ct_request *CTrsp;
  735. struct lpfc_nodelist *ndlp;
  736. int cmdcode, rc;
  737. uint8_t retry;
  738. uint32_t latt;
  739. /* First save ndlp, before we overwrite it */
  740. ndlp = cmdiocb->context_un.ndlp;
  741. /* we pass cmdiocb to state machine which needs rspiocb as well */
  742. cmdiocb->context_un.rsp_iocb = rspiocb;
  743. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  744. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  745. irsp = &rspiocb->iocb;
  746. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  747. CommandResponse.bits.CmdRsp);
  748. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  749. latt = lpfc_els_chk_latt(vport);
  750. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  751. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  752. "0209 CT Request completes, latt %d, "
  753. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  754. latt, irsp->ulpStatus,
  755. CTrsp->CommandResponse.bits.CmdRsp,
  756. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  757. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  758. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  759. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  760. if (irsp->ulpStatus) {
  761. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  762. "0268 NS cmd %x Error (%d %d)\n",
  763. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  764. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  765. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  766. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
  767. goto out;
  768. retry = cmdiocb->retry;
  769. if (retry >= LPFC_MAX_NS_RETRY)
  770. goto out;
  771. retry++;
  772. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  773. "0250 Retrying NS cmd %x\n", cmdcode);
  774. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  775. if (rc == 0)
  776. goto out;
  777. }
  778. out:
  779. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  780. lpfc_ct_free_iocb(phba, cmdiocb);
  781. return;
  782. }
  783. static void
  784. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  785. struct lpfc_iocbq *rspiocb)
  786. {
  787. IOCB_t *irsp = &rspiocb->iocb;
  788. struct lpfc_vport *vport = cmdiocb->vport;
  789. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  790. struct lpfc_dmabuf *outp;
  791. struct lpfc_sli_ct_request *CTrsp;
  792. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  793. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  794. if (CTrsp->CommandResponse.bits.CmdRsp ==
  795. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  796. vport->ct_flags |= FC_CT_RFT_ID;
  797. }
  798. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  799. return;
  800. }
  801. static void
  802. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  803. struct lpfc_iocbq *rspiocb)
  804. {
  805. IOCB_t *irsp = &rspiocb->iocb;
  806. struct lpfc_vport *vport = cmdiocb->vport;
  807. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  808. struct lpfc_dmabuf *outp;
  809. struct lpfc_sli_ct_request *CTrsp;
  810. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  811. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  812. if (CTrsp->CommandResponse.bits.CmdRsp ==
  813. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  814. vport->ct_flags |= FC_CT_RNN_ID;
  815. }
  816. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  817. return;
  818. }
  819. static void
  820. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  821. struct lpfc_iocbq *rspiocb)
  822. {
  823. IOCB_t *irsp = &rspiocb->iocb;
  824. struct lpfc_vport *vport = cmdiocb->vport;
  825. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  826. struct lpfc_dmabuf *outp;
  827. struct lpfc_sli_ct_request *CTrsp;
  828. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  829. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  830. if (CTrsp->CommandResponse.bits.CmdRsp ==
  831. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  832. vport->ct_flags |= FC_CT_RSPN_ID;
  833. }
  834. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  835. return;
  836. }
  837. static void
  838. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  839. struct lpfc_iocbq *rspiocb)
  840. {
  841. IOCB_t *irsp = &rspiocb->iocb;
  842. struct lpfc_vport *vport = cmdiocb->vport;
  843. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  844. struct lpfc_dmabuf *outp;
  845. struct lpfc_sli_ct_request *CTrsp;
  846. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  847. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  848. if (CTrsp->CommandResponse.bits.CmdRsp ==
  849. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  850. vport->ct_flags |= FC_CT_RSNN_NN;
  851. }
  852. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  853. return;
  854. }
  855. static void
  856. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  857. struct lpfc_iocbq *rspiocb)
  858. {
  859. struct lpfc_vport *vport = cmdiocb->vport;
  860. /* even if it fails we will act as though it succeeded. */
  861. vport->ct_flags = 0;
  862. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  863. return;
  864. }
  865. static void
  866. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  867. struct lpfc_iocbq *rspiocb)
  868. {
  869. IOCB_t *irsp = &rspiocb->iocb;
  870. struct lpfc_vport *vport = cmdiocb->vport;
  871. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  872. struct lpfc_dmabuf *outp;
  873. struct lpfc_sli_ct_request *CTrsp;
  874. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  875. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  876. if (CTrsp->CommandResponse.bits.CmdRsp ==
  877. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  878. vport->ct_flags |= FC_CT_RFF_ID;
  879. }
  880. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  881. return;
  882. }
  883. int
  884. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  885. size_t size)
  886. {
  887. int n;
  888. uint8_t *wwn = vport->phba->wwpn;
  889. n = snprintf(symbol, size,
  890. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  891. wwn[0], wwn[1], wwn[2], wwn[3],
  892. wwn[4], wwn[5], wwn[6], wwn[7]);
  893. if (vport->port_type == LPFC_PHYSICAL_PORT)
  894. return n;
  895. if (n < size)
  896. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  897. if (n < size &&
  898. strlen(vport->fc_vport->symbolic_name))
  899. n += snprintf(symbol + n, size - n, " VName-%s",
  900. vport->fc_vport->symbolic_name);
  901. return n;
  902. }
  903. int
  904. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  905. size_t size)
  906. {
  907. char fwrev[16];
  908. int n;
  909. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  910. n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
  911. vport->phba->ModelName, fwrev, lpfc_release_version);
  912. return n;
  913. }
  914. /*
  915. * lpfc_ns_cmd
  916. * Description:
  917. * Issue Cmd to NameServer
  918. * SLI_CTNS_GID_FT
  919. * LI_CTNS_RFT_ID
  920. */
  921. int
  922. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  923. uint8_t retry, uint32_t context)
  924. {
  925. struct lpfc_nodelist * ndlp;
  926. struct lpfc_hba *phba = vport->phba;
  927. struct lpfc_dmabuf *mp, *bmp;
  928. struct lpfc_sli_ct_request *CtReq;
  929. struct ulp_bde64 *bpl;
  930. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  931. struct lpfc_iocbq *) = NULL;
  932. uint32_t rsp_size = 1024;
  933. size_t size;
  934. int rc = 0;
  935. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  936. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  937. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  938. rc=1;
  939. goto ns_cmd_exit;
  940. }
  941. /* fill in BDEs for command */
  942. /* Allocate buffer for command payload */
  943. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  944. if (!mp) {
  945. rc=2;
  946. goto ns_cmd_exit;
  947. }
  948. INIT_LIST_HEAD(&mp->list);
  949. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  950. if (!mp->virt) {
  951. rc=3;
  952. goto ns_cmd_free_mp;
  953. }
  954. /* Allocate buffer for Buffer ptr list */
  955. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  956. if (!bmp) {
  957. rc=4;
  958. goto ns_cmd_free_mpvirt;
  959. }
  960. INIT_LIST_HEAD(&bmp->list);
  961. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  962. if (!bmp->virt) {
  963. rc=5;
  964. goto ns_cmd_free_bmp;
  965. }
  966. /* NameServer Req */
  967. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  968. "0236 NameServer Req Data: x%x x%x x%x\n",
  969. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
  970. bpl = (struct ulp_bde64 *) bmp->virt;
  971. memset(bpl, 0, sizeof(struct ulp_bde64));
  972. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  973. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  974. bpl->tus.f.bdeFlags = 0;
  975. if (cmdcode == SLI_CTNS_GID_FT)
  976. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  977. else if (cmdcode == SLI_CTNS_GFF_ID)
  978. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  979. else if (cmdcode == SLI_CTNS_RFT_ID)
  980. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  981. else if (cmdcode == SLI_CTNS_RNN_ID)
  982. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  983. else if (cmdcode == SLI_CTNS_RSPN_ID)
  984. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  985. else if (cmdcode == SLI_CTNS_RSNN_NN)
  986. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  987. else if (cmdcode == SLI_CTNS_DA_ID)
  988. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  989. else if (cmdcode == SLI_CTNS_RFF_ID)
  990. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  991. else
  992. bpl->tus.f.bdeSize = 0;
  993. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  994. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  995. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  996. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  997. CtReq->RevisionId.bits.InId = 0;
  998. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  999. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1000. CtReq->CommandResponse.bits.Size = 0;
  1001. switch (cmdcode) {
  1002. case SLI_CTNS_GID_FT:
  1003. CtReq->CommandResponse.bits.CmdRsp =
  1004. be16_to_cpu(SLI_CTNS_GID_FT);
  1005. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  1006. if (vport->port_state < LPFC_NS_QRY)
  1007. vport->port_state = LPFC_NS_QRY;
  1008. lpfc_set_disctmo(vport);
  1009. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1010. rsp_size = FC_MAX_NS_RSP;
  1011. break;
  1012. case SLI_CTNS_GFF_ID:
  1013. CtReq->CommandResponse.bits.CmdRsp =
  1014. be16_to_cpu(SLI_CTNS_GFF_ID);
  1015. CtReq->un.gff.PortId = cpu_to_be32(context);
  1016. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1017. break;
  1018. case SLI_CTNS_RFT_ID:
  1019. vport->ct_flags &= ~FC_CT_RFT_ID;
  1020. CtReq->CommandResponse.bits.CmdRsp =
  1021. be16_to_cpu(SLI_CTNS_RFT_ID);
  1022. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1023. CtReq->un.rft.fcpReg = 1;
  1024. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1025. break;
  1026. case SLI_CTNS_RNN_ID:
  1027. vport->ct_flags &= ~FC_CT_RNN_ID;
  1028. CtReq->CommandResponse.bits.CmdRsp =
  1029. be16_to_cpu(SLI_CTNS_RNN_ID);
  1030. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1031. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1032. sizeof (struct lpfc_name));
  1033. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1034. break;
  1035. case SLI_CTNS_RSPN_ID:
  1036. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1037. CtReq->CommandResponse.bits.CmdRsp =
  1038. be16_to_cpu(SLI_CTNS_RSPN_ID);
  1039. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1040. size = sizeof(CtReq->un.rspn.symbname);
  1041. CtReq->un.rspn.len =
  1042. lpfc_vport_symbolic_port_name(vport,
  1043. CtReq->un.rspn.symbname, size);
  1044. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1045. break;
  1046. case SLI_CTNS_RSNN_NN:
  1047. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1048. CtReq->CommandResponse.bits.CmdRsp =
  1049. be16_to_cpu(SLI_CTNS_RSNN_NN);
  1050. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1051. sizeof (struct lpfc_name));
  1052. size = sizeof(CtReq->un.rsnn.symbname);
  1053. CtReq->un.rsnn.len =
  1054. lpfc_vport_symbolic_node_name(vport,
  1055. CtReq->un.rsnn.symbname, size);
  1056. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1057. break;
  1058. case SLI_CTNS_DA_ID:
  1059. /* Implement DA_ID Nameserver request */
  1060. CtReq->CommandResponse.bits.CmdRsp =
  1061. be16_to_cpu(SLI_CTNS_DA_ID);
  1062. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1063. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1064. break;
  1065. case SLI_CTNS_RFF_ID:
  1066. vport->ct_flags &= ~FC_CT_RFF_ID;
  1067. CtReq->CommandResponse.bits.CmdRsp =
  1068. be16_to_cpu(SLI_CTNS_RFF_ID);
  1069. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);;
  1070. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1071. CtReq->un.rff.type_code = FC_FCP_DATA;
  1072. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1073. break;
  1074. }
  1075. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1076. * to hold ndlp reference for the corresponding callback function.
  1077. */
  1078. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1079. /* On success, The cmpl function will free the buffers */
  1080. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1081. "Issue CT cmd: cmd:x%x did:x%x",
  1082. cmdcode, ndlp->nlp_DID, 0);
  1083. return 0;
  1084. }
  1085. rc=6;
  1086. /* Decrement ndlp reference count to release ndlp reference held
  1087. * for the failed command's callback function.
  1088. */
  1089. lpfc_nlp_put(ndlp);
  1090. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1091. ns_cmd_free_bmp:
  1092. kfree(bmp);
  1093. ns_cmd_free_mpvirt:
  1094. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1095. ns_cmd_free_mp:
  1096. kfree(mp);
  1097. ns_cmd_exit:
  1098. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1099. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1100. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1101. return 1;
  1102. }
  1103. static void
  1104. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1105. struct lpfc_iocbq * rspiocb)
  1106. {
  1107. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1108. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1109. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1110. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1111. struct lpfc_nodelist *ndlp;
  1112. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1113. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1114. struct lpfc_vport *vport = cmdiocb->vport;
  1115. IOCB_t *irsp = &rspiocb->iocb;
  1116. uint32_t latt;
  1117. latt = lpfc_els_chk_latt(vport);
  1118. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1119. "FDMI cmpl: status:x%x/x%x latt:%d",
  1120. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1121. if (latt || irsp->ulpStatus) {
  1122. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1123. "0229 FDMI cmd %04x failed, latt = %d "
  1124. "ulpStatus: x%x, rid x%x\n",
  1125. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1126. irsp->un.ulpWord[4]);
  1127. lpfc_ct_free_iocb(phba, cmdiocb);
  1128. return;
  1129. }
  1130. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1131. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1132. goto fail_out;
  1133. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  1134. /* FDMI rsp failed */
  1135. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1136. "0220 FDMI rsp failed Data: x%x\n",
  1137. be16_to_cpu(fdmi_cmd));
  1138. }
  1139. switch (be16_to_cpu(fdmi_cmd)) {
  1140. case SLI_MGMT_RHBA:
  1141. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  1142. break;
  1143. case SLI_MGMT_RPA:
  1144. break;
  1145. case SLI_MGMT_DHBA:
  1146. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  1147. break;
  1148. case SLI_MGMT_DPRT:
  1149. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  1150. break;
  1151. }
  1152. fail_out:
  1153. lpfc_ct_free_iocb(phba, cmdiocb);
  1154. return;
  1155. }
  1156. int
  1157. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  1158. {
  1159. struct lpfc_hba *phba = vport->phba;
  1160. struct lpfc_dmabuf *mp, *bmp;
  1161. struct lpfc_sli_ct_request *CtReq;
  1162. struct ulp_bde64 *bpl;
  1163. uint32_t size;
  1164. REG_HBA *rh;
  1165. PORT_ENTRY *pe;
  1166. REG_PORT_ATTRIBUTE *pab;
  1167. ATTRIBUTE_BLOCK *ab;
  1168. ATTRIBUTE_ENTRY *ae;
  1169. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1170. struct lpfc_iocbq *);
  1171. /* fill in BDEs for command */
  1172. /* Allocate buffer for command payload */
  1173. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1174. if (!mp)
  1175. goto fdmi_cmd_exit;
  1176. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  1177. if (!mp->virt)
  1178. goto fdmi_cmd_free_mp;
  1179. /* Allocate buffer for Buffer ptr list */
  1180. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1181. if (!bmp)
  1182. goto fdmi_cmd_free_mpvirt;
  1183. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  1184. if (!bmp->virt)
  1185. goto fdmi_cmd_free_bmp;
  1186. INIT_LIST_HEAD(&mp->list);
  1187. INIT_LIST_HEAD(&bmp->list);
  1188. /* FDMI request */
  1189. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1190. "0218 FDMI Request Data: x%x x%x x%x\n",
  1191. vport->fc_flag, vport->port_state, cmdcode);
  1192. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1193. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1194. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1195. CtReq->RevisionId.bits.InId = 0;
  1196. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  1197. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  1198. size = 0;
  1199. switch (cmdcode) {
  1200. case SLI_MGMT_RHBA:
  1201. {
  1202. lpfc_vpd_t *vp = &phba->vpd;
  1203. uint32_t i, j, incr;
  1204. int len;
  1205. CtReq->CommandResponse.bits.CmdRsp =
  1206. be16_to_cpu(SLI_MGMT_RHBA);
  1207. CtReq->CommandResponse.bits.Size = 0;
  1208. rh = (REG_HBA *) & CtReq->un.PortID;
  1209. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  1210. sizeof (struct lpfc_name));
  1211. /* One entry (port) per adapter */
  1212. rh->rpl.EntryCnt = be32_to_cpu(1);
  1213. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  1214. sizeof (struct lpfc_name));
  1215. /* point to the HBA attribute block */
  1216. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  1217. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  1218. ab->EntryCnt = 0;
  1219. /* Point to the beginning of the first HBA attribute
  1220. entry */
  1221. /* #1 HBA attribute entry */
  1222. size += FOURBYTES;
  1223. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1224. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  1225. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  1226. + sizeof (struct lpfc_name));
  1227. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1228. sizeof (struct lpfc_name));
  1229. ab->EntryCnt++;
  1230. size += FOURBYTES + sizeof (struct lpfc_name);
  1231. /* #2 HBA attribute entry */
  1232. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1233. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  1234. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  1235. len = strlen(ae->un.Manufacturer);
  1236. len += (len & 3) ? (4 - (len & 3)) : 4;
  1237. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1238. ab->EntryCnt++;
  1239. size += FOURBYTES + len;
  1240. /* #3 HBA attribute entry */
  1241. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1242. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  1243. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  1244. len = strlen(ae->un.SerialNumber);
  1245. len += (len & 3) ? (4 - (len & 3)) : 4;
  1246. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1247. ab->EntryCnt++;
  1248. size += FOURBYTES + len;
  1249. /* #4 HBA attribute entry */
  1250. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1251. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  1252. strcpy(ae->un.Model, phba->ModelName);
  1253. len = strlen(ae->un.Model);
  1254. len += (len & 3) ? (4 - (len & 3)) : 4;
  1255. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1256. ab->EntryCnt++;
  1257. size += FOURBYTES + len;
  1258. /* #5 HBA attribute entry */
  1259. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1260. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  1261. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  1262. len = strlen(ae->un.ModelDescription);
  1263. len += (len & 3) ? (4 - (len & 3)) : 4;
  1264. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1265. ab->EntryCnt++;
  1266. size += FOURBYTES + len;
  1267. /* #6 HBA attribute entry */
  1268. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1269. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  1270. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  1271. /* Convert JEDEC ID to ascii for hardware version */
  1272. incr = vp->rev.biuRev;
  1273. for (i = 0; i < 8; i++) {
  1274. j = (incr & 0xf);
  1275. if (j <= 9)
  1276. ae->un.HardwareVersion[7 - i] =
  1277. (char)((uint8_t) 0x30 +
  1278. (uint8_t) j);
  1279. else
  1280. ae->un.HardwareVersion[7 - i] =
  1281. (char)((uint8_t) 0x61 +
  1282. (uint8_t) (j - 10));
  1283. incr = (incr >> 4);
  1284. }
  1285. ab->EntryCnt++;
  1286. size += FOURBYTES + 8;
  1287. /* #7 HBA attribute entry */
  1288. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1289. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  1290. strcpy(ae->un.DriverVersion, lpfc_release_version);
  1291. len = strlen(ae->un.DriverVersion);
  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. /* #8 HBA attribute entry */
  1297. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1298. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  1299. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  1300. len = strlen(ae->un.OptionROMVersion);
  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. /* #9 HBA attribute entry */
  1306. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1307. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  1308. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  1309. 1);
  1310. len = strlen(ae->un.FirmwareVersion);
  1311. len += (len & 3) ? (4 - (len & 3)) : 4;
  1312. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1313. ab->EntryCnt++;
  1314. size += FOURBYTES + len;
  1315. /* #10 HBA attribute entry */
  1316. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1317. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  1318. sprintf(ae->un.OsNameVersion, "%s %s %s",
  1319. init_utsname()->sysname,
  1320. init_utsname()->release,
  1321. init_utsname()->version);
  1322. len = strlen(ae->un.OsNameVersion);
  1323. len += (len & 3) ? (4 - (len & 3)) : 4;
  1324. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1325. ab->EntryCnt++;
  1326. size += FOURBYTES + len;
  1327. /* #11 HBA attribute entry */
  1328. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1329. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  1330. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1331. ae->un.MaxCTPayloadLen = (65 * 4096);
  1332. ab->EntryCnt++;
  1333. size += FOURBYTES + 4;
  1334. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  1335. /* Total size */
  1336. size = GID_REQUEST_SZ - 4 + size;
  1337. }
  1338. break;
  1339. case SLI_MGMT_RPA:
  1340. {
  1341. lpfc_vpd_t *vp;
  1342. struct serv_parm *hsp;
  1343. int len;
  1344. vp = &phba->vpd;
  1345. CtReq->CommandResponse.bits.CmdRsp =
  1346. be16_to_cpu(SLI_MGMT_RPA);
  1347. CtReq->CommandResponse.bits.Size = 0;
  1348. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  1349. size = sizeof (struct lpfc_name) + FOURBYTES;
  1350. memcpy((uint8_t *) & pab->PortName,
  1351. (uint8_t *) & vport->fc_sparam.portName,
  1352. sizeof (struct lpfc_name));
  1353. pab->ab.EntryCnt = 0;
  1354. /* #1 Port attribute entry */
  1355. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1356. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  1357. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  1358. ae->un.SupportFC4Types[2] = 1;
  1359. ae->un.SupportFC4Types[7] = 1;
  1360. pab->ab.EntryCnt++;
  1361. size += FOURBYTES + 32;
  1362. /* #2 Port attribute entry */
  1363. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1364. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  1365. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1366. ae->un.SupportSpeed = 0;
  1367. if (phba->lmt & LMT_10Gb)
  1368. ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
  1369. if (phba->lmt & LMT_8Gb)
  1370. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  1371. if (phba->lmt & LMT_4Gb)
  1372. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  1373. if (phba->lmt & LMT_2Gb)
  1374. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  1375. if (phba->lmt & LMT_1Gb)
  1376. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  1377. pab->ab.EntryCnt++;
  1378. size += FOURBYTES + 4;
  1379. /* #3 Port attribute entry */
  1380. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1381. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  1382. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1383. switch(phba->fc_linkspeed) {
  1384. case LA_1GHZ_LINK:
  1385. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  1386. break;
  1387. case LA_2GHZ_LINK:
  1388. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  1389. break;
  1390. case LA_4GHZ_LINK:
  1391. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  1392. break;
  1393. case LA_8GHZ_LINK:
  1394. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  1395. break;
  1396. default:
  1397. ae->un.PortSpeed =
  1398. HBA_PORTSPEED_UNKNOWN;
  1399. break;
  1400. }
  1401. pab->ab.EntryCnt++;
  1402. size += FOURBYTES + 4;
  1403. /* #4 Port attribute entry */
  1404. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1405. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  1406. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1407. hsp = (struct serv_parm *) & vport->fc_sparam;
  1408. ae->un.MaxFrameSize =
  1409. (((uint32_t) hsp->cmn.
  1410. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  1411. bbRcvSizeLsb;
  1412. pab->ab.EntryCnt++;
  1413. size += FOURBYTES + 4;
  1414. /* #5 Port attribute entry */
  1415. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1416. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  1417. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  1418. len = strlen((char *)ae->un.OsDeviceName);
  1419. len += (len & 3) ? (4 - (len & 3)) : 4;
  1420. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1421. pab->ab.EntryCnt++;
  1422. size += FOURBYTES + len;
  1423. if (vport->cfg_fdmi_on == 2) {
  1424. /* #6 Port attribute entry */
  1425. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  1426. size);
  1427. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  1428. sprintf(ae->un.HostName, "%s",
  1429. init_utsname()->nodename);
  1430. len = strlen(ae->un.HostName);
  1431. len += (len & 3) ? (4 - (len & 3)) : 4;
  1432. ae->ad.bits.AttrLen =
  1433. be16_to_cpu(FOURBYTES + len);
  1434. pab->ab.EntryCnt++;
  1435. size += FOURBYTES + len;
  1436. }
  1437. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  1438. /* Total size */
  1439. size = GID_REQUEST_SZ - 4 + size;
  1440. }
  1441. break;
  1442. case SLI_MGMT_DHBA:
  1443. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  1444. CtReq->CommandResponse.bits.Size = 0;
  1445. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1446. memcpy((uint8_t *) & pe->PortName,
  1447. (uint8_t *) & vport->fc_sparam.portName,
  1448. sizeof (struct lpfc_name));
  1449. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1450. break;
  1451. case SLI_MGMT_DPRT:
  1452. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  1453. CtReq->CommandResponse.bits.Size = 0;
  1454. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1455. memcpy((uint8_t *) & pe->PortName,
  1456. (uint8_t *) & vport->fc_sparam.portName,
  1457. sizeof (struct lpfc_name));
  1458. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1459. break;
  1460. }
  1461. bpl = (struct ulp_bde64 *) bmp->virt;
  1462. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1463. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1464. bpl->tus.f.bdeFlags = 0;
  1465. bpl->tus.f.bdeSize = size;
  1466. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1467. cmpl = lpfc_cmpl_ct_cmd_fdmi;
  1468. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1469. * to hold ndlp reference for the corresponding callback function.
  1470. */
  1471. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP, 0))
  1472. return 0;
  1473. /* Decrement ndlp reference count to release ndlp reference held
  1474. * for the failed command's callback function.
  1475. */
  1476. lpfc_nlp_put(ndlp);
  1477. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1478. fdmi_cmd_free_bmp:
  1479. kfree(bmp);
  1480. fdmi_cmd_free_mpvirt:
  1481. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1482. fdmi_cmd_free_mp:
  1483. kfree(mp);
  1484. fdmi_cmd_exit:
  1485. /* Issue FDMI request failed */
  1486. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1487. "0244 Issue FDMI request failed Data: x%x\n",
  1488. cmdcode);
  1489. return 1;
  1490. }
  1491. void
  1492. lpfc_fdmi_tmo(unsigned long ptr)
  1493. {
  1494. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1495. struct lpfc_hba *phba = vport->phba;
  1496. uint32_t tmo_posted;
  1497. unsigned long iflag;
  1498. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1499. tmo_posted = vport->work_port_events & WORKER_FDMI_TMO;
  1500. if (!tmo_posted)
  1501. vport->work_port_events |= WORKER_FDMI_TMO;
  1502. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1503. if (!tmo_posted)
  1504. lpfc_worker_wake_up(phba);
  1505. return;
  1506. }
  1507. void
  1508. lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
  1509. {
  1510. struct lpfc_nodelist *ndlp;
  1511. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1512. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  1513. if (init_utsname()->nodename[0] != '\0')
  1514. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  1515. else
  1516. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  1517. }
  1518. return;
  1519. }
  1520. void
  1521. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  1522. {
  1523. struct lpfc_sli *psli = &phba->sli;
  1524. lpfc_vpd_t *vp = &phba->vpd;
  1525. uint32_t b1, b2, b3, b4, i, rev;
  1526. char c;
  1527. uint32_t *ptr, str[4];
  1528. uint8_t *fwname;
  1529. if (vp->rev.rBit) {
  1530. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1531. rev = vp->rev.sli2FwRev;
  1532. else
  1533. rev = vp->rev.sli1FwRev;
  1534. b1 = (rev & 0x0000f000) >> 12;
  1535. b2 = (rev & 0x00000f00) >> 8;
  1536. b3 = (rev & 0x000000c0) >> 6;
  1537. b4 = (rev & 0x00000030) >> 4;
  1538. switch (b4) {
  1539. case 0:
  1540. c = 'N';
  1541. break;
  1542. case 1:
  1543. c = 'A';
  1544. break;
  1545. case 2:
  1546. c = 'B';
  1547. break;
  1548. default:
  1549. c = 0;
  1550. break;
  1551. }
  1552. b4 = (rev & 0x0000000f);
  1553. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1554. fwname = vp->rev.sli2FwName;
  1555. else
  1556. fwname = vp->rev.sli1FwName;
  1557. for (i = 0; i < 16; i++)
  1558. if (fwname[i] == 0x20)
  1559. fwname[i] = 0;
  1560. ptr = (uint32_t*)fwname;
  1561. for (i = 0; i < 3; i++)
  1562. str[i] = be32_to_cpu(*ptr++);
  1563. if (c == 0) {
  1564. if (flag)
  1565. sprintf(fwrevision, "%d.%d%d (%s)",
  1566. b1, b2, b3, (char *)str);
  1567. else
  1568. sprintf(fwrevision, "%d.%d%d", b1,
  1569. b2, b3);
  1570. } else {
  1571. if (flag)
  1572. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  1573. b1, b2, b3, c,
  1574. b4, (char *)str);
  1575. else
  1576. sprintf(fwrevision, "%d.%d%d%c%d",
  1577. b1, b2, b3, c, b4);
  1578. }
  1579. } else {
  1580. rev = vp->rev.smFwRev;
  1581. b1 = (rev & 0xff000000) >> 24;
  1582. b2 = (rev & 0x00f00000) >> 20;
  1583. b3 = (rev & 0x000f0000) >> 16;
  1584. c = (rev & 0x0000ff00) >> 8;
  1585. b4 = (rev & 0x000000ff);
  1586. if (flag)
  1587. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1588. b2, b3, c, b4);
  1589. else
  1590. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1591. b2, b3, c, b4);
  1592. }
  1593. return;
  1594. }