lpfc_ct.c 53 KB

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