lpfc_ct.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2007 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
  22. */
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/utsname.h>
  27. #include <scsi/scsi.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport_fc.h>
  31. #include "lpfc_hw.h"
  32. #include "lpfc_sli.h"
  33. #include "lpfc_disc.h"
  34. #include "lpfc_scsi.h"
  35. #include "lpfc.h"
  36. #include "lpfc_logmsg.h"
  37. #include "lpfc_crtn.h"
  38. #include "lpfc_version.h"
  39. #define HBA_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
  40. * incapable of reporting */
  41. #define HBA_PORTSPEED_1GBIT 1 /* 1 GBit/sec */
  42. #define HBA_PORTSPEED_2GBIT 2 /* 2 GBit/sec */
  43. #define HBA_PORTSPEED_4GBIT 8 /* 4 GBit/sec */
  44. #define HBA_PORTSPEED_8GBIT 16 /* 8 GBit/sec */
  45. #define HBA_PORTSPEED_10GBIT 4 /* 10 GBit/sec */
  46. #define HBA_PORTSPEED_NOT_NEGOTIATED 5 /* Speed not established */
  47. #define FOURBYTES 4
  48. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  49. /*
  50. * lpfc_ct_unsol_event
  51. */
  52. static void
  53. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  54. struct lpfc_dmabuf *mp, uint32_t size)
  55. {
  56. if (!mp) {
  57. printk(KERN_ERR "%s (%d): Unsolited CT, no buffer, "
  58. "piocbq = %p, status = x%x, mp = %p, size = %d\n",
  59. __FUNCTION__, __LINE__,
  60. piocbq, piocbq->iocb.ulpStatus, mp, size);
  61. }
  62. printk(KERN_ERR "%s (%d): Ignoring unsolicted CT piocbq = %p, "
  63. "buffer = %p, size = %d, status = x%x\n",
  64. __FUNCTION__, __LINE__,
  65. piocbq, mp, size,
  66. piocbq->iocb.ulpStatus);
  67. }
  68. static void
  69. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  70. struct hbq_dmabuf *sp, uint32_t size)
  71. {
  72. struct lpfc_dmabuf *mp = NULL;
  73. mp = sp ? &sp->dbuf : NULL;
  74. if (!mp) {
  75. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  76. "HBQ buffer, piocbq = %p, status = x%x\n",
  77. __FUNCTION__, __LINE__,
  78. piocbq, piocbq->iocb.ulpStatus);
  79. } else {
  80. lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
  81. printk(KERN_ERR "%s (%d): Ignoring unsolicted CT "
  82. "piocbq = %p, buffer = %p, size = %d, "
  83. "status = x%x\n",
  84. __FUNCTION__, __LINE__,
  85. piocbq, mp, size, piocbq->iocb.ulpStatus);
  86. }
  87. }
  88. void
  89. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  90. struct lpfc_iocbq *piocbq)
  91. {
  92. struct lpfc_dmabuf *mp = NULL;
  93. struct hbq_dmabuf *sp = NULL;
  94. IOCB_t *icmd = &piocbq->iocb;
  95. int i;
  96. struct lpfc_iocbq *iocbq;
  97. dma_addr_t paddr;
  98. uint32_t size;
  99. if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  100. ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
  101. /* Not enough posted buffers; Try posting more buffers */
  102. phba->fc_stat.NoRcvBuf++;
  103. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  104. lpfc_sli_hbqbuf_fill_hbq(phba);
  105. else
  106. lpfc_post_buffer(phba, pring, 0, 1);
  107. return;
  108. }
  109. /* If there are no BDEs associated with this IOCB,
  110. * there is nothing to do.
  111. */
  112. if (icmd->ulpBdeCount == 0)
  113. return;
  114. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  115. list_for_each_entry(iocbq, &piocbq->list, list) {
  116. icmd = &iocbq->iocb;
  117. if (icmd->ulpBdeCount == 0) {
  118. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  119. "BDE, iocbq = %p, status = x%x\n",
  120. __FUNCTION__, __LINE__,
  121. iocbq, iocbq->iocb.ulpStatus);
  122. continue;
  123. }
  124. size = icmd->un.cont64[0].tus.f.bdeSize;
  125. sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[3]);
  126. if (sp)
  127. phba->hbq_buff_count--;
  128. lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp, size);
  129. lpfc_sli_free_hbq(phba, sp);
  130. if (icmd->ulpBdeCount == 2) {
  131. sp = lpfc_sli_hbqbuf_find(phba,
  132. icmd->un.ulpWord[15]);
  133. if (sp)
  134. phba->hbq_buff_count--;
  135. lpfc_ct_ignore_hbq_buffer(phba, iocbq, sp,
  136. size);
  137. lpfc_sli_free_hbq(phba, sp);
  138. }
  139. }
  140. lpfc_sli_hbqbuf_fill_hbq(phba);
  141. } else {
  142. struct lpfc_iocbq *next;
  143. list_for_each_entry_safe(iocbq, next, &piocbq->list, list) {
  144. icmd = &iocbq->iocb;
  145. if (icmd->ulpBdeCount == 0) {
  146. printk(KERN_ERR "%s (%d): Unsolited CT, no "
  147. "BDE, iocbq = %p, status = x%x\n",
  148. __FUNCTION__, __LINE__,
  149. iocbq, iocbq->iocb.ulpStatus);
  150. continue;
  151. }
  152. for (i = 0; i < icmd->ulpBdeCount; i++) {
  153. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  154. icmd->un.cont64[i].addrLow);
  155. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  156. paddr);
  157. size = icmd->un.cont64[i].tus.f.bdeSize;
  158. lpfc_ct_unsol_buffer(phba, piocbq, mp, size);
  159. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  160. kfree(mp);
  161. }
  162. list_del(&iocbq->list);
  163. lpfc_sli_release_iocbq(phba, iocbq);
  164. }
  165. }
  166. }
  167. static void
  168. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  169. {
  170. struct lpfc_dmabuf *mlast, *next_mlast;
  171. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  172. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  173. list_del(&mlast->list);
  174. kfree(mlast);
  175. }
  176. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  177. kfree(mlist);
  178. return;
  179. }
  180. static struct lpfc_dmabuf *
  181. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  182. uint32_t size, int *entries)
  183. {
  184. struct lpfc_dmabuf *mlist = NULL;
  185. struct lpfc_dmabuf *mp;
  186. int cnt, i = 0;
  187. /* We get chucks of FCELSSIZE */
  188. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  189. while (size) {
  190. /* Allocate buffer for rsp payload */
  191. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  192. if (!mp) {
  193. if (mlist)
  194. lpfc_free_ct_rsp(phba, mlist);
  195. return NULL;
  196. }
  197. INIT_LIST_HEAD(&mp->list);
  198. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT))
  199. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  200. else
  201. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  202. if (!mp->virt) {
  203. kfree(mp);
  204. if (mlist)
  205. lpfc_free_ct_rsp(phba, mlist);
  206. return NULL;
  207. }
  208. /* Queue it to a linked list */
  209. if (!mlist)
  210. mlist = mp;
  211. else
  212. list_add_tail(&mp->list, &mlist->list);
  213. bpl->tus.f.bdeFlags = BUFF_USE_RCV;
  214. /* build buffer ptr list for IOCB */
  215. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  216. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  217. bpl->tus.f.bdeSize = (uint16_t) cnt;
  218. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  219. bpl++;
  220. i++;
  221. size -= cnt;
  222. }
  223. *entries = i;
  224. return mlist;
  225. }
  226. static int
  227. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  228. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  229. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  230. struct lpfc_iocbq *),
  231. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  232. uint32_t tmo)
  233. {
  234. struct lpfc_hba *phba = vport->phba;
  235. struct lpfc_sli *psli = &phba->sli;
  236. struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
  237. IOCB_t *icmd;
  238. struct lpfc_iocbq *geniocb;
  239. /* Allocate buffer for command iocb */
  240. geniocb = lpfc_sli_get_iocbq(phba);
  241. if (geniocb == NULL)
  242. return 1;
  243. icmd = &geniocb->iocb;
  244. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  245. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  246. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  247. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
  248. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof (struct ulp_bde64));
  249. if (usr_flg)
  250. geniocb->context3 = NULL;
  251. else
  252. geniocb->context3 = (uint8_t *) bmp;
  253. /* Save for completion so we can release these resources */
  254. geniocb->context1 = (uint8_t *) inp;
  255. geniocb->context2 = (uint8_t *) outp;
  256. /* Fill in payload, bp points to frame payload */
  257. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  258. /* Fill in rest of iocb */
  259. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  260. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  261. icmd->un.genreq64.w5.hcsw.Rctl = FC_UNSOL_CTL;
  262. icmd->un.genreq64.w5.hcsw.Type = FC_COMMON_TRANSPORT_ULP;
  263. if (!tmo) {
  264. /* FC spec states we need 3 * ratov for CT requests */
  265. tmo = (3 * phba->fc_ratov);
  266. }
  267. icmd->ulpTimeout = tmo;
  268. icmd->ulpBdeCount = 1;
  269. icmd->ulpLe = 1;
  270. icmd->ulpClass = CLASS3;
  271. icmd->ulpContext = ndlp->nlp_rpi;
  272. /* Issue GEN REQ IOCB for NPORT <did> */
  273. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  274. "%d:0119 Issue GEN REQ IOCB for NPORT x%x "
  275. "Data: x%x x%x\n", phba->brd_no, icmd->un.ulpWord[5],
  276. icmd->ulpIoTag, vport->port_state);
  277. geniocb->iocb_cmpl = cmpl;
  278. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  279. geniocb->vport = vport;
  280. if (lpfc_sli_issue_iocb(phba, pring, geniocb, 0) == IOCB_ERROR) {
  281. lpfc_sli_release_iocbq(phba, geniocb);
  282. return 1;
  283. }
  284. return 0;
  285. }
  286. static int
  287. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  288. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  289. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  290. struct lpfc_iocbq *),
  291. uint32_t rsp_size)
  292. {
  293. struct lpfc_hba *phba = vport->phba;
  294. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  295. struct lpfc_dmabuf *outmp;
  296. int cnt = 0, status;
  297. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  298. CommandResponse.bits.CmdRsp;
  299. bpl++; /* Skip past ct request */
  300. /* Put buffer(s) for ct rsp in bpl */
  301. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  302. if (!outmp)
  303. return -ENOMEM;
  304. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  305. cnt+1, 0);
  306. if (status) {
  307. lpfc_free_ct_rsp(phba, outmp);
  308. return -ENOMEM;
  309. }
  310. return 0;
  311. }
  312. static int
  313. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  314. {
  315. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  316. struct lpfc_hba *phba = vport->phba;
  317. struct lpfc_sli_ct_request *Response =
  318. (struct lpfc_sli_ct_request *) mp->virt;
  319. struct lpfc_nodelist *ndlp = NULL;
  320. struct lpfc_dmabuf *mlast, *next_mp;
  321. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  322. uint32_t Did, CTentry;
  323. int Cnt;
  324. struct list_head head;
  325. lpfc_set_disctmo(vport);
  326. list_add_tail(&head, &mp->list);
  327. list_for_each_entry_safe(mp, next_mp, &head, list) {
  328. mlast = mp;
  329. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  330. Size -= Cnt;
  331. if (!ctptr) {
  332. ctptr = (uint32_t *) mlast->virt;
  333. } else
  334. Cnt -= 16; /* subtract length of CT header */
  335. /* Loop through entire NameServer list of DIDs */
  336. while (Cnt >= sizeof (uint32_t)) {
  337. /* Get next DID from NameServer List */
  338. CTentry = *ctptr++;
  339. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  340. ndlp = NULL;
  341. /* Check for rscn processing or not */
  342. if (Did != vport->fc_myDID)
  343. ndlp = lpfc_setup_disc_node(vport, Did);
  344. if (ndlp) {
  345. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  346. "%d:0238 Process x%x NameServer"
  347. " Rsp Data: x%x x%x x%x\n",
  348. phba->brd_no,
  349. Did, ndlp->nlp_flag,
  350. vport->fc_flag,
  351. vport->fc_rscn_id_cnt);
  352. } else {
  353. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  354. "%d:0239 Skip x%x NameServer "
  355. "Rsp Data: x%x x%x x%x\n",
  356. phba->brd_no,
  357. Did, Size, vport->fc_flag,
  358. vport->fc_rscn_id_cnt);
  359. }
  360. if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
  361. goto nsout1;
  362. Cnt -= sizeof (uint32_t);
  363. }
  364. ctptr = NULL;
  365. }
  366. nsout1:
  367. list_del(&head);
  368. /*
  369. * The driver has cycled through all Nports in the RSCN payload.
  370. * Complete the handling by cleaning up and marking the
  371. * current driver state.
  372. */
  373. if (vport->port_state == LPFC_VPORT_READY) {
  374. lpfc_els_flush_rscn(vport);
  375. spin_lock_irq(shost->host_lock);
  376. vport->fc_flag |= FC_RSCN_MODE; /* we are still in RSCN mode */
  377. spin_unlock_irq(shost->host_lock);
  378. }
  379. return 0;
  380. }
  381. static void
  382. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  383. struct lpfc_iocbq *rspiocb)
  384. {
  385. struct lpfc_vport *vport = cmdiocb->vport;
  386. IOCB_t *irsp;
  387. struct lpfc_dmabuf *bmp;
  388. struct lpfc_dmabuf *inp;
  389. struct lpfc_dmabuf *outp;
  390. struct lpfc_nodelist *ndlp;
  391. struct lpfc_sli_ct_request *CTrsp;
  392. int rc;
  393. /* we pass cmdiocb to state machine which needs rspiocb as well */
  394. cmdiocb->context_un.rsp_iocb = rspiocb;
  395. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  396. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  397. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  398. irsp = &rspiocb->iocb;
  399. if (irsp->ulpStatus) {
  400. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  401. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  402. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
  403. goto out;
  404. /* Check for retry */
  405. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  406. vport->fc_ns_retry++;
  407. /* CT command is being retried */
  408. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  409. if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
  410. rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
  411. if (rc == 0)
  412. goto out;
  413. }
  414. }
  415. } else {
  416. /* Good status, continue checking */
  417. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  418. if (CTrsp->CommandResponse.bits.CmdRsp ==
  419. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  420. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  421. "%d:0208 NameServer Rsp "
  422. "Data: x%x\n",
  423. phba->brd_no,
  424. vport->fc_flag);
  425. lpfc_ns_rsp(vport, outp,
  426. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  427. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  428. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  429. /* NameServer Rsp Error */
  430. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  431. "%d:0240 NameServer Rsp Error "
  432. "Data: x%x x%x x%x x%x\n",
  433. phba->brd_no,
  434. CTrsp->CommandResponse.bits.CmdRsp,
  435. (uint32_t) CTrsp->ReasonCode,
  436. (uint32_t) CTrsp->Explanation,
  437. vport->fc_flag);
  438. } else {
  439. /* NameServer Rsp Error */
  440. lpfc_printf_log(phba,
  441. KERN_INFO,
  442. LOG_DISCOVERY,
  443. "%d:0241 NameServer Rsp Error "
  444. "Data: x%x x%x x%x x%x\n",
  445. phba->brd_no,
  446. CTrsp->CommandResponse.bits.CmdRsp,
  447. (uint32_t) CTrsp->ReasonCode,
  448. (uint32_t) CTrsp->Explanation,
  449. vport->fc_flag);
  450. }
  451. }
  452. /* Link up / RSCN discovery */
  453. lpfc_disc_start(vport);
  454. out:
  455. lpfc_free_ct_rsp(phba, outp);
  456. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  457. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  458. kfree(inp);
  459. kfree(bmp);
  460. lpfc_sli_release_iocbq(phba, cmdiocb);
  461. return;
  462. }
  463. static void
  464. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  465. struct lpfc_iocbq *rspiocb)
  466. {
  467. struct lpfc_dmabuf *bmp;
  468. struct lpfc_dmabuf *inp;
  469. struct lpfc_dmabuf *outp;
  470. IOCB_t *irsp;
  471. struct lpfc_sli_ct_request *CTrsp;
  472. /* we pass cmdiocb to state machine which needs rspiocb as well */
  473. cmdiocb->context_un.rsp_iocb = rspiocb;
  474. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  475. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  476. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  477. irsp = &rspiocb->iocb;
  478. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  479. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  480. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  481. "%d:0209 RFT request completes ulpStatus x%x "
  482. "CmdRsp x%x, Context x%x, Tag x%x\n",
  483. phba->brd_no, irsp->ulpStatus,
  484. CTrsp->CommandResponse.bits.CmdRsp,
  485. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  486. lpfc_free_ct_rsp(phba, outp);
  487. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  488. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  489. kfree(inp);
  490. kfree(bmp);
  491. lpfc_sli_release_iocbq(phba, cmdiocb);
  492. return;
  493. }
  494. static void
  495. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  496. struct lpfc_iocbq *rspiocb)
  497. {
  498. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  499. return;
  500. }
  501. static void
  502. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  503. struct lpfc_iocbq *rspiocb)
  504. {
  505. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  506. return;
  507. }
  508. static void
  509. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
  510. struct lpfc_iocbq * rspiocb)
  511. {
  512. lpfc_cmpl_ct_cmd_rft_id(phba, cmdiocb, rspiocb);
  513. return;
  514. }
  515. void
  516. lpfc_get_hba_sym_node_name(struct lpfc_hba *phba, uint8_t *symbp)
  517. {
  518. char fwrev[16];
  519. lpfc_decode_firmware_rev(phba, fwrev, 0);
  520. sprintf(symbp, "Emulex %s FV%s DV%s", phba->ModelName,
  521. fwrev, lpfc_release_version);
  522. return;
  523. }
  524. /*
  525. * lpfc_ns_cmd
  526. * Description:
  527. * Issue Cmd to NameServer
  528. * SLI_CTNS_GID_FT
  529. * LI_CTNS_RFT_ID
  530. */
  531. int
  532. lpfc_ns_cmd(struct lpfc_vport *vport, struct lpfc_nodelist * ndlp, int cmdcode)
  533. {
  534. struct lpfc_hba *phba = vport->phba;
  535. struct lpfc_dmabuf *mp, *bmp;
  536. struct lpfc_sli_ct_request *CtReq;
  537. struct ulp_bde64 *bpl;
  538. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  539. struct lpfc_iocbq *) = NULL;
  540. uint32_t rsp_size = 1024;
  541. /* fill in BDEs for command */
  542. /* Allocate buffer for command payload */
  543. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  544. if (!mp)
  545. goto ns_cmd_exit;
  546. INIT_LIST_HEAD(&mp->list);
  547. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  548. if (!mp->virt)
  549. goto ns_cmd_free_mp;
  550. /* Allocate buffer for Buffer ptr list */
  551. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  552. if (!bmp)
  553. goto ns_cmd_free_mpvirt;
  554. INIT_LIST_HEAD(&bmp->list);
  555. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  556. if (!bmp->virt)
  557. goto ns_cmd_free_bmp;
  558. /* NameServer Req */
  559. lpfc_printf_log(phba,
  560. KERN_INFO,
  561. LOG_DISCOVERY,
  562. "%d:0236 NameServer Req Data: x%x x%x x%x\n",
  563. phba->brd_no, cmdcode, vport->fc_flag,
  564. vport->fc_rscn_id_cnt);
  565. bpl = (struct ulp_bde64 *) bmp->virt;
  566. memset(bpl, 0, sizeof(struct ulp_bde64));
  567. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  568. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  569. bpl->tus.f.bdeFlags = 0;
  570. if (cmdcode == SLI_CTNS_GID_FT)
  571. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  572. else if (cmdcode == SLI_CTNS_RFT_ID)
  573. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  574. else if (cmdcode == SLI_CTNS_RNN_ID)
  575. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  576. else if (cmdcode == SLI_CTNS_RSNN_NN)
  577. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  578. else if (cmdcode == SLI_CTNS_RFF_ID)
  579. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  580. else
  581. bpl->tus.f.bdeSize = 0;
  582. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  583. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  584. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  585. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  586. CtReq->RevisionId.bits.InId = 0;
  587. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  588. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  589. CtReq->CommandResponse.bits.Size = 0;
  590. switch (cmdcode) {
  591. case SLI_CTNS_GID_FT:
  592. CtReq->CommandResponse.bits.CmdRsp =
  593. be16_to_cpu(SLI_CTNS_GID_FT);
  594. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  595. if (vport->port_state < LPFC_VPORT_READY)
  596. vport->port_state = LPFC_NS_QRY;
  597. lpfc_set_disctmo(vport);
  598. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  599. rsp_size = FC_MAX_NS_RSP;
  600. break;
  601. case SLI_CTNS_RFT_ID:
  602. CtReq->CommandResponse.bits.CmdRsp =
  603. be16_to_cpu(SLI_CTNS_RFT_ID);
  604. CtReq->un.rft.PortId = be32_to_cpu(vport->fc_myDID);
  605. CtReq->un.rft.fcpReg = 1;
  606. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  607. break;
  608. case SLI_CTNS_RFF_ID:
  609. CtReq->CommandResponse.bits.CmdRsp =
  610. be16_to_cpu(SLI_CTNS_RFF_ID);
  611. CtReq->un.rff.PortId = be32_to_cpu(vport->fc_myDID);
  612. CtReq->un.rff.feature_res = 0;
  613. CtReq->un.rff.feature_tgt = 0;
  614. CtReq->un.rff.type_code = FC_FCP_DATA;
  615. CtReq->un.rff.feature_init = 1;
  616. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  617. break;
  618. case SLI_CTNS_RNN_ID:
  619. CtReq->CommandResponse.bits.CmdRsp =
  620. be16_to_cpu(SLI_CTNS_RNN_ID);
  621. CtReq->un.rnn.PortId = be32_to_cpu(vport->fc_myDID);
  622. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  623. sizeof (struct lpfc_name));
  624. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  625. break;
  626. case SLI_CTNS_RSNN_NN:
  627. CtReq->CommandResponse.bits.CmdRsp =
  628. be16_to_cpu(SLI_CTNS_RSNN_NN);
  629. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  630. sizeof (struct lpfc_name));
  631. lpfc_get_hba_sym_node_name(phba, CtReq->un.rsnn.symbname);
  632. CtReq->un.rsnn.len = strlen(CtReq->un.rsnn.symbname);
  633. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  634. break;
  635. }
  636. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size))
  637. /* On success, The cmpl function will free the buffers */
  638. return 0;
  639. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  640. ns_cmd_free_bmp:
  641. kfree(bmp);
  642. ns_cmd_free_mpvirt:
  643. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  644. ns_cmd_free_mp:
  645. kfree(mp);
  646. ns_cmd_exit:
  647. return 1;
  648. }
  649. static void
  650. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  651. struct lpfc_iocbq * rspiocb)
  652. {
  653. struct lpfc_dmabuf *bmp = cmdiocb->context3;
  654. struct lpfc_dmabuf *inp = cmdiocb->context1;
  655. struct lpfc_dmabuf *outp = cmdiocb->context2;
  656. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  657. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  658. struct lpfc_nodelist *ndlp;
  659. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  660. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  661. struct lpfc_vport *vport = cmdiocb->vport;
  662. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  663. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  664. /* FDMI rsp failed */
  665. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  666. "%d:0220 FDMI rsp failed Data: x%x\n",
  667. phba->brd_no, be16_to_cpu(fdmi_cmd));
  668. }
  669. switch (be16_to_cpu(fdmi_cmd)) {
  670. case SLI_MGMT_RHBA:
  671. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  672. break;
  673. case SLI_MGMT_RPA:
  674. break;
  675. case SLI_MGMT_DHBA:
  676. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  677. break;
  678. case SLI_MGMT_DPRT:
  679. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  680. break;
  681. }
  682. lpfc_free_ct_rsp(phba, outp);
  683. lpfc_mbuf_free(phba, inp->virt, inp->phys);
  684. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  685. kfree(inp);
  686. kfree(bmp);
  687. lpfc_sli_release_iocbq(phba, cmdiocb);
  688. return;
  689. }
  690. int
  691. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  692. {
  693. struct lpfc_hba *phba = vport->phba;
  694. struct lpfc_dmabuf *mp, *bmp;
  695. struct lpfc_sli_ct_request *CtReq;
  696. struct ulp_bde64 *bpl;
  697. uint32_t size;
  698. REG_HBA *rh;
  699. PORT_ENTRY *pe;
  700. REG_PORT_ATTRIBUTE *pab;
  701. ATTRIBUTE_BLOCK *ab;
  702. ATTRIBUTE_ENTRY *ae;
  703. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  704. struct lpfc_iocbq *);
  705. /* fill in BDEs for command */
  706. /* Allocate buffer for command payload */
  707. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  708. if (!mp)
  709. goto fdmi_cmd_exit;
  710. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  711. if (!mp->virt)
  712. goto fdmi_cmd_free_mp;
  713. /* Allocate buffer for Buffer ptr list */
  714. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  715. if (!bmp)
  716. goto fdmi_cmd_free_mpvirt;
  717. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  718. if (!bmp->virt)
  719. goto fdmi_cmd_free_bmp;
  720. INIT_LIST_HEAD(&mp->list);
  721. INIT_LIST_HEAD(&bmp->list);
  722. /* FDMI request */
  723. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  724. "%d:0218 FDMI Request Data: x%x x%x x%x\n",
  725. phba->brd_no,
  726. vport->fc_flag, vport->port_state, cmdcode);
  727. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  728. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  729. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  730. CtReq->RevisionId.bits.InId = 0;
  731. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  732. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  733. size = 0;
  734. switch (cmdcode) {
  735. case SLI_MGMT_RHBA:
  736. {
  737. lpfc_vpd_t *vp = &phba->vpd;
  738. uint32_t i, j, incr;
  739. int len;
  740. CtReq->CommandResponse.bits.CmdRsp =
  741. be16_to_cpu(SLI_MGMT_RHBA);
  742. CtReq->CommandResponse.bits.Size = 0;
  743. rh = (REG_HBA *) & CtReq->un.PortID;
  744. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  745. sizeof (struct lpfc_name));
  746. /* One entry (port) per adapter */
  747. rh->rpl.EntryCnt = be32_to_cpu(1);
  748. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  749. sizeof (struct lpfc_name));
  750. /* point to the HBA attribute block */
  751. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  752. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  753. ab->EntryCnt = 0;
  754. /* Point to the beginning of the first HBA attribute
  755. entry */
  756. /* #1 HBA attribute entry */
  757. size += FOURBYTES;
  758. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  759. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  760. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  761. + sizeof (struct lpfc_name));
  762. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  763. sizeof (struct lpfc_name));
  764. ab->EntryCnt++;
  765. size += FOURBYTES + sizeof (struct lpfc_name);
  766. /* #2 HBA attribute entry */
  767. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  768. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  769. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  770. len = strlen(ae->un.Manufacturer);
  771. len += (len & 3) ? (4 - (len & 3)) : 4;
  772. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  773. ab->EntryCnt++;
  774. size += FOURBYTES + len;
  775. /* #3 HBA attribute entry */
  776. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  777. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  778. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  779. len = strlen(ae->un.SerialNumber);
  780. len += (len & 3) ? (4 - (len & 3)) : 4;
  781. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  782. ab->EntryCnt++;
  783. size += FOURBYTES + len;
  784. /* #4 HBA attribute entry */
  785. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  786. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  787. strcpy(ae->un.Model, phba->ModelName);
  788. len = strlen(ae->un.Model);
  789. len += (len & 3) ? (4 - (len & 3)) : 4;
  790. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  791. ab->EntryCnt++;
  792. size += FOURBYTES + len;
  793. /* #5 HBA attribute entry */
  794. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  795. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  796. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  797. len = strlen(ae->un.ModelDescription);
  798. len += (len & 3) ? (4 - (len & 3)) : 4;
  799. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  800. ab->EntryCnt++;
  801. size += FOURBYTES + len;
  802. /* #6 HBA attribute entry */
  803. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  804. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  805. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  806. /* Convert JEDEC ID to ascii for hardware version */
  807. incr = vp->rev.biuRev;
  808. for (i = 0; i < 8; i++) {
  809. j = (incr & 0xf);
  810. if (j <= 9)
  811. ae->un.HardwareVersion[7 - i] =
  812. (char)((uint8_t) 0x30 +
  813. (uint8_t) j);
  814. else
  815. ae->un.HardwareVersion[7 - i] =
  816. (char)((uint8_t) 0x61 +
  817. (uint8_t) (j - 10));
  818. incr = (incr >> 4);
  819. }
  820. ab->EntryCnt++;
  821. size += FOURBYTES + 8;
  822. /* #7 HBA attribute entry */
  823. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  824. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  825. strcpy(ae->un.DriverVersion, lpfc_release_version);
  826. len = strlen(ae->un.DriverVersion);
  827. len += (len & 3) ? (4 - (len & 3)) : 4;
  828. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  829. ab->EntryCnt++;
  830. size += FOURBYTES + len;
  831. /* #8 HBA attribute entry */
  832. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  833. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  834. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  835. len = strlen(ae->un.OptionROMVersion);
  836. len += (len & 3) ? (4 - (len & 3)) : 4;
  837. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  838. ab->EntryCnt++;
  839. size += FOURBYTES + len;
  840. /* #9 HBA attribute entry */
  841. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  842. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  843. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  844. 1);
  845. len = strlen(ae->un.FirmwareVersion);
  846. len += (len & 3) ? (4 - (len & 3)) : 4;
  847. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  848. ab->EntryCnt++;
  849. size += FOURBYTES + len;
  850. /* #10 HBA attribute entry */
  851. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  852. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  853. sprintf(ae->un.OsNameVersion, "%s %s %s",
  854. init_utsname()->sysname,
  855. init_utsname()->release,
  856. init_utsname()->version);
  857. len = strlen(ae->un.OsNameVersion);
  858. len += (len & 3) ? (4 - (len & 3)) : 4;
  859. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  860. ab->EntryCnt++;
  861. size += FOURBYTES + len;
  862. /* #11 HBA attribute entry */
  863. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  864. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  865. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  866. ae->un.MaxCTPayloadLen = (65 * 4096);
  867. ab->EntryCnt++;
  868. size += FOURBYTES + 4;
  869. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  870. /* Total size */
  871. size = GID_REQUEST_SZ - 4 + size;
  872. }
  873. break;
  874. case SLI_MGMT_RPA:
  875. {
  876. lpfc_vpd_t *vp;
  877. struct serv_parm *hsp;
  878. int len;
  879. vp = &phba->vpd;
  880. CtReq->CommandResponse.bits.CmdRsp =
  881. be16_to_cpu(SLI_MGMT_RPA);
  882. CtReq->CommandResponse.bits.Size = 0;
  883. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  884. size = sizeof (struct lpfc_name) + FOURBYTES;
  885. memcpy((uint8_t *) & pab->PortName,
  886. (uint8_t *) & vport->fc_sparam.portName,
  887. sizeof (struct lpfc_name));
  888. pab->ab.EntryCnt = 0;
  889. /* #1 Port attribute entry */
  890. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  891. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  892. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  893. ae->un.SupportFC4Types[2] = 1;
  894. ae->un.SupportFC4Types[7] = 1;
  895. pab->ab.EntryCnt++;
  896. size += FOURBYTES + 32;
  897. /* #2 Port attribute entry */
  898. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  899. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  900. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  901. ae->un.SupportSpeed = 0;
  902. if (phba->lmt & LMT_10Gb)
  903. ae->un.SupportSpeed = HBA_PORTSPEED_10GBIT;
  904. if (phba->lmt & LMT_8Gb)
  905. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  906. if (phba->lmt & LMT_4Gb)
  907. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  908. if (phba->lmt & LMT_2Gb)
  909. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  910. if (phba->lmt & LMT_1Gb)
  911. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  912. pab->ab.EntryCnt++;
  913. size += FOURBYTES + 4;
  914. /* #3 Port attribute entry */
  915. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  916. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  917. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  918. switch(phba->fc_linkspeed) {
  919. case LA_1GHZ_LINK:
  920. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  921. break;
  922. case LA_2GHZ_LINK:
  923. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  924. break;
  925. case LA_4GHZ_LINK:
  926. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  927. break;
  928. case LA_8GHZ_LINK:
  929. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  930. break;
  931. default:
  932. ae->un.PortSpeed =
  933. HBA_PORTSPEED_UNKNOWN;
  934. break;
  935. }
  936. pab->ab.EntryCnt++;
  937. size += FOURBYTES + 4;
  938. /* #4 Port attribute entry */
  939. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  940. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  941. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  942. hsp = (struct serv_parm *) & vport->fc_sparam;
  943. ae->un.MaxFrameSize =
  944. (((uint32_t) hsp->cmn.
  945. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  946. bbRcvSizeLsb;
  947. pab->ab.EntryCnt++;
  948. size += FOURBYTES + 4;
  949. /* #5 Port attribute entry */
  950. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  951. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  952. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  953. len = strlen((char *)ae->un.OsDeviceName);
  954. len += (len & 3) ? (4 - (len & 3)) : 4;
  955. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  956. pab->ab.EntryCnt++;
  957. size += FOURBYTES + len;
  958. if (phba->cfg_fdmi_on == 2) {
  959. /* #6 Port attribute entry */
  960. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  961. size);
  962. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  963. sprintf(ae->un.HostName, "%s",
  964. init_utsname()->nodename);
  965. len = strlen(ae->un.HostName);
  966. len += (len & 3) ? (4 - (len & 3)) : 4;
  967. ae->ad.bits.AttrLen =
  968. be16_to_cpu(FOURBYTES + len);
  969. pab->ab.EntryCnt++;
  970. size += FOURBYTES + len;
  971. }
  972. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  973. /* Total size */
  974. size = GID_REQUEST_SZ - 4 + size;
  975. }
  976. break;
  977. case SLI_MGMT_DHBA:
  978. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  979. CtReq->CommandResponse.bits.Size = 0;
  980. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  981. memcpy((uint8_t *) & pe->PortName,
  982. (uint8_t *) & vport->fc_sparam.portName,
  983. sizeof (struct lpfc_name));
  984. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  985. break;
  986. case SLI_MGMT_DPRT:
  987. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  988. CtReq->CommandResponse.bits.Size = 0;
  989. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  990. memcpy((uint8_t *) & pe->PortName,
  991. (uint8_t *) & vport->fc_sparam.portName,
  992. sizeof (struct lpfc_name));
  993. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  994. break;
  995. }
  996. bpl = (struct ulp_bde64 *) bmp->virt;
  997. bpl->addrHigh = le32_to_cpu( putPaddrHigh(mp->phys) );
  998. bpl->addrLow = le32_to_cpu( putPaddrLow(mp->phys) );
  999. bpl->tus.f.bdeFlags = 0;
  1000. bpl->tus.f.bdeSize = size;
  1001. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1002. cmpl = lpfc_cmpl_ct_cmd_fdmi;
  1003. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, FC_MAX_NS_RSP))
  1004. return 0;
  1005. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1006. fdmi_cmd_free_bmp:
  1007. kfree(bmp);
  1008. fdmi_cmd_free_mpvirt:
  1009. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1010. fdmi_cmd_free_mp:
  1011. kfree(mp);
  1012. fdmi_cmd_exit:
  1013. /* Issue FDMI request failed */
  1014. lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
  1015. "%d:0244 Issue FDMI request failed Data: x%x\n",
  1016. phba->brd_no, cmdcode);
  1017. return 1;
  1018. }
  1019. void
  1020. lpfc_fdmi_tmo(unsigned long ptr)
  1021. {
  1022. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  1023. struct lpfc_hba *phba = vport->phba;
  1024. unsigned long iflag;
  1025. spin_lock_irqsave(&vport->work_port_lock, iflag);
  1026. if (!(vport->work_port_events & WORKER_FDMI_TMO)) {
  1027. vport->work_port_events |= WORKER_FDMI_TMO;
  1028. if (phba->work_wait)
  1029. wake_up(phba->work_wait);
  1030. }
  1031. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  1032. }
  1033. void
  1034. lpfc_fdmi_timeout_handler(struct lpfc_vport *vport)
  1035. {
  1036. struct lpfc_nodelist *ndlp;
  1037. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1038. if (ndlp) {
  1039. if (init_utsname()->nodename[0] != '\0')
  1040. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
  1041. else
  1042. mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
  1043. }
  1044. return;
  1045. }
  1046. void
  1047. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  1048. {
  1049. struct lpfc_sli *psli = &phba->sli;
  1050. lpfc_vpd_t *vp = &phba->vpd;
  1051. uint32_t b1, b2, b3, b4, i, rev;
  1052. char c;
  1053. uint32_t *ptr, str[4];
  1054. uint8_t *fwname;
  1055. if (vp->rev.rBit) {
  1056. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1057. rev = vp->rev.sli2FwRev;
  1058. else
  1059. rev = vp->rev.sli1FwRev;
  1060. b1 = (rev & 0x0000f000) >> 12;
  1061. b2 = (rev & 0x00000f00) >> 8;
  1062. b3 = (rev & 0x000000c0) >> 6;
  1063. b4 = (rev & 0x00000030) >> 4;
  1064. switch (b4) {
  1065. case 0:
  1066. c = 'N';
  1067. break;
  1068. case 1:
  1069. c = 'A';
  1070. break;
  1071. case 2:
  1072. c = 'B';
  1073. break;
  1074. default:
  1075. c = 0;
  1076. break;
  1077. }
  1078. b4 = (rev & 0x0000000f);
  1079. if (psli->sli_flag & LPFC_SLI2_ACTIVE)
  1080. fwname = vp->rev.sli2FwName;
  1081. else
  1082. fwname = vp->rev.sli1FwName;
  1083. for (i = 0; i < 16; i++)
  1084. if (fwname[i] == 0x20)
  1085. fwname[i] = 0;
  1086. ptr = (uint32_t*)fwname;
  1087. for (i = 0; i < 3; i++)
  1088. str[i] = be32_to_cpu(*ptr++);
  1089. if (c == 0) {
  1090. if (flag)
  1091. sprintf(fwrevision, "%d.%d%d (%s)",
  1092. b1, b2, b3, (char *)str);
  1093. else
  1094. sprintf(fwrevision, "%d.%d%d", b1,
  1095. b2, b3);
  1096. } else {
  1097. if (flag)
  1098. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  1099. b1, b2, b3, c,
  1100. b4, (char *)str);
  1101. else
  1102. sprintf(fwrevision, "%d.%d%d%c%d",
  1103. b1, b2, b3, c, b4);
  1104. }
  1105. } else {
  1106. rev = vp->rev.smFwRev;
  1107. b1 = (rev & 0xff000000) >> 24;
  1108. b2 = (rev & 0x00f00000) >> 20;
  1109. b3 = (rev & 0x000f0000) >> 16;
  1110. c = (rev & 0x0000ff00) >> 8;
  1111. b4 = (rev & 0x000000ff);
  1112. if (flag)
  1113. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1114. b2, b3, c, b4);
  1115. else
  1116. sprintf(fwrevision, "%d.%d%d%c%d ", b1,
  1117. b2, b3, c, b4);
  1118. }
  1119. return;
  1120. }