lpfc_ct.c 52 KB

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