lpfc_ct.c 52 KB

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