PageRenderTime 908ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/scsi/lpfc/lpfc_ct.c

https://github.com/Mengqi/linux-2.6
C | 1711 lines | 1369 code | 194 blank | 148 comment | 202 complexity | ca6fecef803563330862ce3941b4fac5 MD5 | raw file
  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->sli_rev == LPFC_SLI_REV4)
  314. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  315. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  316. /* For GEN_REQUEST64_CR, use the RPI */
  317. icmd->ulpCt_h = 0;
  318. icmd->ulpCt_l = 0;
  319. }
  320. /* Issue GEN REQ IOCB for NPORT <did> */
  321. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  322. "0119 Issue GEN REQ IOCB to NPORT x%x "
  323. "Data: x%x x%x\n",
  324. ndlp->nlp_DID, icmd->ulpIoTag,
  325. vport->port_state);
  326. geniocb->iocb_cmpl = cmpl;
  327. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  328. geniocb->vport = vport;
  329. geniocb->retry = retry;
  330. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  331. if (rc == IOCB_ERROR) {
  332. lpfc_sli_release_iocbq(phba, geniocb);
  333. return 1;
  334. }
  335. return 0;
  336. }
  337. static int
  338. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  339. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  340. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  341. struct lpfc_iocbq *),
  342. uint32_t rsp_size, uint8_t retry)
  343. {
  344. struct lpfc_hba *phba = vport->phba;
  345. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  346. struct lpfc_dmabuf *outmp;
  347. int cnt = 0, status;
  348. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  349. CommandResponse.bits.CmdRsp;
  350. bpl++; /* Skip past ct request */
  351. /* Put buffer(s) for ct rsp in bpl */
  352. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  353. if (!outmp)
  354. return -ENOMEM;
  355. /*
  356. * Form the CT IOCB. The total number of BDEs in this IOCB
  357. * is the single command plus response count from
  358. * lpfc_alloc_ct_rsp.
  359. */
  360. cnt += 1;
  361. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  362. cnt, 0, retry);
  363. if (status) {
  364. lpfc_free_ct_rsp(phba, outmp);
  365. return -ENOMEM;
  366. }
  367. return 0;
  368. }
  369. struct lpfc_vport *
  370. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  371. struct lpfc_vport *vport_curr;
  372. unsigned long flags;
  373. spin_lock_irqsave(&phba->hbalock, flags);
  374. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  375. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  376. spin_unlock_irqrestore(&phba->hbalock, flags);
  377. return vport_curr;
  378. }
  379. }
  380. spin_unlock_irqrestore(&phba->hbalock, flags);
  381. return NULL;
  382. }
  383. static int
  384. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  385. {
  386. struct lpfc_hba *phba = vport->phba;
  387. struct lpfc_sli_ct_request *Response =
  388. (struct lpfc_sli_ct_request *) mp->virt;
  389. struct lpfc_nodelist *ndlp = NULL;
  390. struct lpfc_dmabuf *mlast, *next_mp;
  391. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  392. uint32_t Did, CTentry;
  393. int Cnt;
  394. struct list_head head;
  395. lpfc_set_disctmo(vport);
  396. vport->num_disc_nodes = 0;
  397. vport->fc_ns_retry = 0;
  398. list_add_tail(&head, &mp->list);
  399. list_for_each_entry_safe(mp, next_mp, &head, list) {
  400. mlast = mp;
  401. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  402. Size -= Cnt;
  403. if (!ctptr) {
  404. ctptr = (uint32_t *) mlast->virt;
  405. } else
  406. Cnt -= 16; /* subtract length of CT header */
  407. /* Loop through entire NameServer list of DIDs */
  408. while (Cnt >= sizeof (uint32_t)) {
  409. /* Get next DID from NameServer List */
  410. CTentry = *ctptr++;
  411. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  412. ndlp = NULL;
  413. /*
  414. * Check for rscn processing or not
  415. * To conserve rpi's, filter out addresses for other
  416. * vports on the same physical HBAs.
  417. */
  418. if ((Did != vport->fc_myDID) &&
  419. ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
  420. vport->cfg_peer_port_login)) {
  421. if ((vport->port_type != LPFC_NPIV_PORT) ||
  422. (!(vport->ct_flags & FC_CT_RFF_ID)) ||
  423. (!vport->cfg_restrict_login)) {
  424. ndlp = lpfc_setup_disc_node(vport, Did);
  425. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  426. lpfc_debugfs_disc_trc(vport,
  427. LPFC_DISC_TRC_CT,
  428. "Parse GID_FTrsp: "
  429. "did:x%x flg:x%x x%x",
  430. Did, ndlp->nlp_flag,
  431. vport->fc_flag);
  432. lpfc_printf_vlog(vport,
  433. KERN_INFO,
  434. LOG_DISCOVERY,
  435. "0238 Process "
  436. "x%x NameServer Rsp"
  437. "Data: x%x x%x x%x\n",
  438. Did, ndlp->nlp_flag,
  439. vport->fc_flag,
  440. vport->fc_rscn_id_cnt);
  441. } else {
  442. lpfc_debugfs_disc_trc(vport,
  443. LPFC_DISC_TRC_CT,
  444. "Skip1 GID_FTrsp: "
  445. "did:x%x flg:x%x cnt:%d",
  446. Did, vport->fc_flag,
  447. vport->fc_rscn_id_cnt);
  448. lpfc_printf_vlog(vport,
  449. KERN_INFO,
  450. LOG_DISCOVERY,
  451. "0239 Skip x%x "
  452. "NameServer Rsp Data: "
  453. "x%x x%x\n",
  454. Did, vport->fc_flag,
  455. vport->fc_rscn_id_cnt);
  456. }
  457. } else {
  458. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  459. (lpfc_rscn_payload_check(vport, Did))) {
  460. lpfc_debugfs_disc_trc(vport,
  461. LPFC_DISC_TRC_CT,
  462. "Query GID_FTrsp: "
  463. "did:x%x flg:x%x cnt:%d",
  464. Did, vport->fc_flag,
  465. vport->fc_rscn_id_cnt);
  466. /* This NPortID was previously
  467. * a FCP target, * Don't even
  468. * bother to send GFF_ID.
  469. */
  470. ndlp = lpfc_findnode_did(vport,
  471. Did);
  472. if (ndlp &&
  473. NLP_CHK_NODE_ACT(ndlp)
  474. && (ndlp->nlp_type &
  475. NLP_FCP_TARGET))
  476. lpfc_setup_disc_node
  477. (vport, Did);
  478. else if (lpfc_ns_cmd(vport,
  479. SLI_CTNS_GFF_ID,
  480. 0, Did) == 0)
  481. vport->num_disc_nodes++;
  482. else
  483. lpfc_setup_disc_node
  484. (vport, Did);
  485. }
  486. else {
  487. lpfc_debugfs_disc_trc(vport,
  488. LPFC_DISC_TRC_CT,
  489. "Skip2 GID_FTrsp: "
  490. "did:x%x flg:x%x cnt:%d",
  491. Did, vport->fc_flag,
  492. vport->fc_rscn_id_cnt);
  493. lpfc_printf_vlog(vport,
  494. KERN_INFO,
  495. LOG_DISCOVERY,
  496. "0245 Skip x%x "
  497. "NameServer Rsp Data: "
  498. "x%x x%x\n",
  499. Did, vport->fc_flag,
  500. vport->fc_rscn_id_cnt);
  501. }
  502. }
  503. }
  504. if (CTentry & (be32_to_cpu(SLI_CT_LAST_ENTRY)))
  505. goto nsout1;
  506. Cnt -= sizeof (uint32_t);
  507. }
  508. ctptr = NULL;
  509. }
  510. nsout1:
  511. list_del(&head);
  512. return 0;
  513. }
  514. static void
  515. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  516. struct lpfc_iocbq *rspiocb)
  517. {
  518. struct lpfc_vport *vport = cmdiocb->vport;
  519. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  520. IOCB_t *irsp;
  521. struct lpfc_dmabuf *bmp;
  522. struct lpfc_dmabuf *outp;
  523. struct lpfc_sli_ct_request *CTrsp;
  524. struct lpfc_nodelist *ndlp;
  525. int rc;
  526. /* First save ndlp, before we overwrite it */
  527. ndlp = cmdiocb->context_un.ndlp;
  528. /* we pass cmdiocb to state machine which needs rspiocb as well */
  529. cmdiocb->context_un.rsp_iocb = rspiocb;
  530. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  531. bmp = (struct lpfc_dmabuf *) cmdiocb->context3;
  532. irsp = &rspiocb->iocb;
  533. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  534. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  535. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  536. /* Don't bother processing response if vport is being torn down. */
  537. if (vport->load_flag & FC_UNLOADING) {
  538. if (vport->fc_flag & FC_RSCN_MODE)
  539. lpfc_els_flush_rscn(vport);
  540. goto out;
  541. }
  542. if (lpfc_els_chk_latt(vport)) {
  543. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  544. "0216 Link event during NS query\n");
  545. if (vport->fc_flag & FC_RSCN_MODE)
  546. lpfc_els_flush_rscn(vport);
  547. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  548. goto out;
  549. }
  550. if (lpfc_error_lost_link(irsp)) {
  551. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  552. "0226 NS query failed due to link event\n");
  553. if (vport->fc_flag & FC_RSCN_MODE)
  554. lpfc_els_flush_rscn(vport);
  555. goto out;
  556. }
  557. if (irsp->ulpStatus) {
  558. /* Check for retry */
  559. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  560. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  561. irsp->un.ulpWord[4] != IOERR_NO_RESOURCES)
  562. vport->fc_ns_retry++;
  563. /* CT command is being retried */
  564. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  565. vport->fc_ns_retry, 0);
  566. if (rc == 0)
  567. goto out;
  568. }
  569. if (vport->fc_flag & FC_RSCN_MODE)
  570. lpfc_els_flush_rscn(vport);
  571. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  572. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  573. "0257 GID_FT Query error: 0x%x 0x%x\n",
  574. irsp->ulpStatus, vport->fc_ns_retry);
  575. } else {
  576. /* Good status, continue checking */
  577. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  578. if (CTrsp->CommandResponse.bits.CmdRsp ==
  579. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  580. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  581. "0208 NameServer Rsp Data: x%x\n",
  582. vport->fc_flag);
  583. lpfc_ns_rsp(vport, outp,
  584. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  585. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  586. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  587. /* NameServer Rsp Error */
  588. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  589. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  590. lpfc_printf_vlog(vport, KERN_INFO,
  591. LOG_DISCOVERY,
  592. "0269 No NameServer Entries "
  593. "Data: x%x x%x x%x x%x\n",
  594. CTrsp->CommandResponse.bits.CmdRsp,
  595. (uint32_t) CTrsp->ReasonCode,
  596. (uint32_t) CTrsp->Explanation,
  597. vport->fc_flag);
  598. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  599. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  600. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  601. (uint32_t) CTrsp->ReasonCode,
  602. (uint32_t) CTrsp->Explanation);
  603. } else {
  604. lpfc_printf_vlog(vport, KERN_INFO,
  605. LOG_DISCOVERY,
  606. "0240 NameServer Rsp Error "
  607. "Data: x%x x%x x%x x%x\n",
  608. CTrsp->CommandResponse.bits.CmdRsp,
  609. (uint32_t) CTrsp->ReasonCode,
  610. (uint32_t) CTrsp->Explanation,
  611. vport->fc_flag);
  612. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  613. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  614. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  615. (uint32_t) CTrsp->ReasonCode,
  616. (uint32_t) CTrsp->Explanation);
  617. }
  618. } else {
  619. /* NameServer Rsp Error */
  620. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  621. "0241 NameServer Rsp Error "
  622. "Data: x%x x%x x%x x%x\n",
  623. CTrsp->CommandResponse.bits.CmdRsp,
  624. (uint32_t) CTrsp->ReasonCode,
  625. (uint32_t) CTrsp->Explanation,
  626. vport->fc_flag);
  627. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  628. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  629. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  630. (uint32_t) CTrsp->ReasonCode,
  631. (uint32_t) CTrsp->Explanation);
  632. }
  633. }
  634. /* Link up / RSCN discovery */
  635. if (vport->num_disc_nodes == 0) {
  636. /*
  637. * The driver has cycled through all Nports in the RSCN payload.
  638. * Complete the handling by cleaning up and marking the
  639. * current driver state.
  640. */
  641. if (vport->port_state >= LPFC_DISC_AUTH) {
  642. if (vport->fc_flag & FC_RSCN_MODE) {
  643. lpfc_els_flush_rscn(vport);
  644. spin_lock_irq(shost->host_lock);
  645. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  646. spin_unlock_irq(shost->host_lock);
  647. }
  648. else
  649. lpfc_els_flush_rscn(vport);
  650. }
  651. lpfc_disc_start(vport);
  652. }
  653. out:
  654. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  655. lpfc_ct_free_iocb(phba, cmdiocb);
  656. return;
  657. }
  658. static void
  659. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  660. struct lpfc_iocbq *rspiocb)
  661. {
  662. struct lpfc_vport *vport = cmdiocb->vport;
  663. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  664. IOCB_t *irsp = &rspiocb->iocb;
  665. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  666. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  667. struct lpfc_sli_ct_request *CTrsp;
  668. int did, rc, retry;
  669. uint8_t fbits;
  670. struct lpfc_nodelist *ndlp;
  671. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  672. did = be32_to_cpu(did);
  673. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  674. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  675. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  676. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  677. /* Good status, continue checking */
  678. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  679. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  680. if (CTrsp->CommandResponse.bits.CmdRsp ==
  681. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  682. if ((fbits & FC4_FEATURE_INIT) &&
  683. !(fbits & FC4_FEATURE_TARGET)) {
  684. lpfc_printf_vlog(vport, KERN_INFO,
  685. LOG_DISCOVERY,
  686. "0270 Skip x%x GFF "
  687. "NameServer Rsp Data: (init) "
  688. "x%x x%x\n", did, fbits,
  689. vport->fc_rscn_id_cnt);
  690. goto out;
  691. }
  692. }
  693. }
  694. else {
  695. /* Check for retry */
  696. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  697. retry = 1;
  698. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  699. switch (irsp->un.ulpWord[4]) {
  700. case IOERR_NO_RESOURCES:
  701. /* We don't increment the retry
  702. * count for this case.
  703. */
  704. break;
  705. case IOERR_LINK_DOWN:
  706. case IOERR_SLI_ABORTED:
  707. case IOERR_SLI_DOWN:
  708. retry = 0;
  709. break;
  710. default:
  711. cmdiocb->retry++;
  712. }
  713. }
  714. else
  715. cmdiocb->retry++;
  716. if (retry) {
  717. /* CT command is being retried */
  718. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  719. cmdiocb->retry, did);
  720. if (rc == 0) {
  721. /* success */
  722. lpfc_ct_free_iocb(phba, cmdiocb);
  723. return;
  724. }
  725. }
  726. }
  727. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  728. "0267 NameServer GFF Rsp "
  729. "x%x Error (%d %d) Data: x%x x%x\n",
  730. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  731. vport->fc_flag, vport->fc_rscn_id_cnt);
  732. }
  733. /* This is a target port, unregistered port, or the GFF_ID failed */
  734. ndlp = lpfc_setup_disc_node(vport, did);
  735. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  736. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  737. "0242 Process x%x GFF "
  738. "NameServer Rsp Data: x%x x%x x%x\n",
  739. did, ndlp->nlp_flag, vport->fc_flag,
  740. vport->fc_rscn_id_cnt);
  741. } else {
  742. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  743. "0243 Skip x%x GFF "
  744. "NameServer Rsp Data: x%x x%x\n", did,
  745. vport->fc_flag, vport->fc_rscn_id_cnt);
  746. }
  747. out:
  748. /* Link up / RSCN discovery */
  749. if (vport->num_disc_nodes)
  750. vport->num_disc_nodes--;
  751. if (vport->num_disc_nodes == 0) {
  752. /*
  753. * The driver has cycled through all Nports in the RSCN payload.
  754. * Complete the handling by cleaning up and marking the
  755. * current driver state.
  756. */
  757. if (vport->port_state >= LPFC_DISC_AUTH) {
  758. if (vport->fc_flag & FC_RSCN_MODE) {
  759. lpfc_els_flush_rscn(vport);
  760. spin_lock_irq(shost->host_lock);
  761. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  762. spin_unlock_irq(shost->host_lock);
  763. }
  764. else
  765. lpfc_els_flush_rscn(vport);
  766. }
  767. lpfc_disc_start(vport);
  768. }
  769. lpfc_ct_free_iocb(phba, cmdiocb);
  770. return;
  771. }
  772. static void
  773. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  774. struct lpfc_iocbq *rspiocb)
  775. {
  776. struct lpfc_vport *vport = cmdiocb->vport;
  777. struct lpfc_dmabuf *inp;
  778. struct lpfc_dmabuf *outp;
  779. IOCB_t *irsp;
  780. struct lpfc_sli_ct_request *CTrsp;
  781. struct lpfc_nodelist *ndlp;
  782. int cmdcode, rc;
  783. uint8_t retry;
  784. uint32_t latt;
  785. /* First save ndlp, before we overwrite it */
  786. ndlp = cmdiocb->context_un.ndlp;
  787. /* we pass cmdiocb to state machine which needs rspiocb as well */
  788. cmdiocb->context_un.rsp_iocb = rspiocb;
  789. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  790. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  791. irsp = &rspiocb->iocb;
  792. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  793. CommandResponse.bits.CmdRsp);
  794. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  795. latt = lpfc_els_chk_latt(vport);
  796. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  797. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  798. "0209 CT Request completes, latt %d, "
  799. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  800. latt, irsp->ulpStatus,
  801. CTrsp->CommandResponse.bits.CmdRsp,
  802. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  803. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  804. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  805. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  806. if (irsp->ulpStatus) {
  807. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  808. "0268 NS cmd %x Error (%d %d)\n",
  809. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  810. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  811. ((irsp->un.ulpWord[4] == IOERR_SLI_DOWN) ||
  812. (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED)))
  813. goto out;
  814. retry = cmdiocb->retry;
  815. if (retry >= LPFC_MAX_NS_RETRY)
  816. goto out;
  817. retry++;
  818. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  819. "0250 Retrying NS cmd %x\n", cmdcode);
  820. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  821. if (rc == 0)
  822. goto out;
  823. }
  824. out:
  825. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  826. lpfc_ct_free_iocb(phba, cmdiocb);
  827. return;
  828. }
  829. static void
  830. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  831. struct lpfc_iocbq *rspiocb)
  832. {
  833. IOCB_t *irsp = &rspiocb->iocb;
  834. struct lpfc_vport *vport = cmdiocb->vport;
  835. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  836. struct lpfc_dmabuf *outp;
  837. struct lpfc_sli_ct_request *CTrsp;
  838. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  839. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  840. if (CTrsp->CommandResponse.bits.CmdRsp ==
  841. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  842. vport->ct_flags |= FC_CT_RFT_ID;
  843. }
  844. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  845. return;
  846. }
  847. static void
  848. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  849. struct lpfc_iocbq *rspiocb)
  850. {
  851. IOCB_t *irsp = &rspiocb->iocb;
  852. struct lpfc_vport *vport = cmdiocb->vport;
  853. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  854. struct lpfc_dmabuf *outp;
  855. struct lpfc_sli_ct_request *CTrsp;
  856. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  857. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  858. if (CTrsp->CommandResponse.bits.CmdRsp ==
  859. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  860. vport->ct_flags |= FC_CT_RNN_ID;
  861. }
  862. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  863. return;
  864. }
  865. static void
  866. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  867. struct lpfc_iocbq *rspiocb)
  868. {
  869. IOCB_t *irsp = &rspiocb->iocb;
  870. struct lpfc_vport *vport = cmdiocb->vport;
  871. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  872. struct lpfc_dmabuf *outp;
  873. struct lpfc_sli_ct_request *CTrsp;
  874. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  875. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  876. if (CTrsp->CommandResponse.bits.CmdRsp ==
  877. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  878. vport->ct_flags |= FC_CT_RSPN_ID;
  879. }
  880. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  881. return;
  882. }
  883. static void
  884. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  885. struct lpfc_iocbq *rspiocb)
  886. {
  887. IOCB_t *irsp = &rspiocb->iocb;
  888. struct lpfc_vport *vport = cmdiocb->vport;
  889. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  890. struct lpfc_dmabuf *outp;
  891. struct lpfc_sli_ct_request *CTrsp;
  892. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  893. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  894. if (CTrsp->CommandResponse.bits.CmdRsp ==
  895. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  896. vport->ct_flags |= FC_CT_RSNN_NN;
  897. }
  898. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  899. return;
  900. }
  901. static void
  902. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  903. struct lpfc_iocbq *rspiocb)
  904. {
  905. struct lpfc_vport *vport = cmdiocb->vport;
  906. /* even if it fails we will act as though it succeeded. */
  907. vport->ct_flags = 0;
  908. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  909. return;
  910. }
  911. static void
  912. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  913. struct lpfc_iocbq *rspiocb)
  914. {
  915. IOCB_t *irsp = &rspiocb->iocb;
  916. struct lpfc_vport *vport = cmdiocb->vport;
  917. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  918. struct lpfc_dmabuf *outp;
  919. struct lpfc_sli_ct_request *CTrsp;
  920. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  921. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  922. if (CTrsp->CommandResponse.bits.CmdRsp ==
  923. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  924. vport->ct_flags |= FC_CT_RFF_ID;
  925. }
  926. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  927. return;
  928. }
  929. int
  930. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  931. size_t size)
  932. {
  933. int n;
  934. uint8_t *wwn = vport->phba->wwpn;
  935. n = snprintf(symbol, size,
  936. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  937. wwn[0], wwn[1], wwn[2], wwn[3],
  938. wwn[4], wwn[5], wwn[6], wwn[7]);
  939. if (vport->port_type == LPFC_PHYSICAL_PORT)
  940. return n;
  941. if (n < size)
  942. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  943. if (n < size &&
  944. strlen(vport->fc_vport->symbolic_name))
  945. n += snprintf(symbol + n, size - n, " VName-%s",
  946. vport->fc_vport->symbolic_name);
  947. return n;
  948. }
  949. int
  950. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  951. size_t size)
  952. {
  953. char fwrev[16];
  954. int n;
  955. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  956. n = snprintf(symbol, size, "Emulex %s FV%s DV%s",
  957. vport->phba->ModelName, fwrev, lpfc_release_version);
  958. return n;
  959. }
  960. /*
  961. * lpfc_ns_cmd
  962. * Description:
  963. * Issue Cmd to NameServer
  964. * SLI_CTNS_GID_FT
  965. * LI_CTNS_RFT_ID
  966. */
  967. int
  968. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  969. uint8_t retry, uint32_t context)
  970. {
  971. struct lpfc_nodelist * ndlp;
  972. struct lpfc_hba *phba = vport->phba;
  973. struct lpfc_dmabuf *mp, *bmp;
  974. struct lpfc_sli_ct_request *CtReq;
  975. struct ulp_bde64 *bpl;
  976. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  977. struct lpfc_iocbq *) = NULL;
  978. uint32_t rsp_size = 1024;
  979. size_t size;
  980. int rc = 0;
  981. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  982. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  983. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  984. rc=1;
  985. goto ns_cmd_exit;
  986. }
  987. /* fill in BDEs for command */
  988. /* Allocate buffer for command payload */
  989. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  990. if (!mp) {
  991. rc=2;
  992. goto ns_cmd_exit;
  993. }
  994. INIT_LIST_HEAD(&mp->list);
  995. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  996. if (!mp->virt) {
  997. rc=3;
  998. goto ns_cmd_free_mp;
  999. }
  1000. /* Allocate buffer for Buffer ptr list */
  1001. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1002. if (!bmp) {
  1003. rc=4;
  1004. goto ns_cmd_free_mpvirt;
  1005. }
  1006. INIT_LIST_HEAD(&bmp->list);
  1007. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1008. if (!bmp->virt) {
  1009. rc=5;
  1010. goto ns_cmd_free_bmp;
  1011. }
  1012. /* NameServer Req */
  1013. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1014. "0236 NameServer Req Data: x%x x%x x%x\n",
  1015. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
  1016. bpl = (struct ulp_bde64 *) bmp->virt;
  1017. memset(bpl, 0, sizeof(struct ulp_bde64));
  1018. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1019. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1020. bpl->tus.f.bdeFlags = 0;
  1021. if (cmdcode == SLI_CTNS_GID_FT)
  1022. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1023. else if (cmdcode == SLI_CTNS_GFF_ID)
  1024. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1025. else if (cmdcode == SLI_CTNS_RFT_ID)
  1026. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1027. else if (cmdcode == SLI_CTNS_RNN_ID)
  1028. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1029. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1030. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1031. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1032. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1033. else if (cmdcode == SLI_CTNS_DA_ID)
  1034. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1035. else if (cmdcode == SLI_CTNS_RFF_ID)
  1036. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1037. else
  1038. bpl->tus.f.bdeSize = 0;
  1039. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1040. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1041. memset(CtReq, 0, sizeof (struct lpfc_sli_ct_request));
  1042. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1043. CtReq->RevisionId.bits.InId = 0;
  1044. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1045. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1046. CtReq->CommandResponse.bits.Size = 0;
  1047. switch (cmdcode) {
  1048. case SLI_CTNS_GID_FT:
  1049. CtReq->CommandResponse.bits.CmdRsp =
  1050. be16_to_cpu(SLI_CTNS_GID_FT);
  1051. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  1052. if (vport->port_state < LPFC_NS_QRY)
  1053. vport->port_state = LPFC_NS_QRY;
  1054. lpfc_set_disctmo(vport);
  1055. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1056. rsp_size = FC_MAX_NS_RSP;
  1057. break;
  1058. case SLI_CTNS_GFF_ID:
  1059. CtReq->CommandResponse.bits.CmdRsp =
  1060. be16_to_cpu(SLI_CTNS_GFF_ID);
  1061. CtReq->un.gff.PortId = cpu_to_be32(context);
  1062. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1063. break;
  1064. case SLI_CTNS_RFT_ID:
  1065. vport->ct_flags &= ~FC_CT_RFT_ID;
  1066. CtReq->CommandResponse.bits.CmdRsp =
  1067. be16_to_cpu(SLI_CTNS_RFT_ID);
  1068. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1069. CtReq->un.rft.fcpReg = 1;
  1070. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1071. break;
  1072. case SLI_CTNS_RNN_ID:
  1073. vport->ct_flags &= ~FC_CT_RNN_ID;
  1074. CtReq->CommandResponse.bits.CmdRsp =
  1075. be16_to_cpu(SLI_CTNS_RNN_ID);
  1076. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1077. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1078. sizeof (struct lpfc_name));
  1079. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1080. break;
  1081. case SLI_CTNS_RSPN_ID:
  1082. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1083. CtReq->CommandResponse.bits.CmdRsp =
  1084. be16_to_cpu(SLI_CTNS_RSPN_ID);
  1085. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1086. size = sizeof(CtReq->un.rspn.symbname);
  1087. CtReq->un.rspn.len =
  1088. lpfc_vport_symbolic_port_name(vport,
  1089. CtReq->un.rspn.symbname, size);
  1090. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1091. break;
  1092. case SLI_CTNS_RSNN_NN:
  1093. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1094. CtReq->CommandResponse.bits.CmdRsp =
  1095. be16_to_cpu(SLI_CTNS_RSNN_NN);
  1096. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1097. sizeof (struct lpfc_name));
  1098. size = sizeof(CtReq->un.rsnn.symbname);
  1099. CtReq->un.rsnn.len =
  1100. lpfc_vport_symbolic_node_name(vport,
  1101. CtReq->un.rsnn.symbname, size);
  1102. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1103. break;
  1104. case SLI_CTNS_DA_ID:
  1105. /* Implement DA_ID Nameserver request */
  1106. CtReq->CommandResponse.bits.CmdRsp =
  1107. be16_to_cpu(SLI_CTNS_DA_ID);
  1108. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1109. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1110. break;
  1111. case SLI_CTNS_RFF_ID:
  1112. vport->ct_flags &= ~FC_CT_RFF_ID;
  1113. CtReq->CommandResponse.bits.CmdRsp =
  1114. be16_to_cpu(SLI_CTNS_RFF_ID);
  1115. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1116. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1117. CtReq->un.rff.type_code = FC_TYPE_FCP;
  1118. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1119. break;
  1120. }
  1121. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1122. * to hold ndlp reference for the corresponding callback function.
  1123. */
  1124. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1125. /* On success, The cmpl function will free the buffers */
  1126. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1127. "Issue CT cmd: cmd:x%x did:x%x",
  1128. cmdcode, ndlp->nlp_DID, 0);
  1129. return 0;
  1130. }
  1131. rc=6;
  1132. /* Decrement ndlp reference count to release ndlp reference held
  1133. * for the failed command's callback function.
  1134. */
  1135. lpfc_nlp_put(ndlp);
  1136. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1137. ns_cmd_free_bmp:
  1138. kfree(bmp);
  1139. ns_cmd_free_mpvirt:
  1140. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1141. ns_cmd_free_mp:
  1142. kfree(mp);
  1143. ns_cmd_exit:
  1144. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1145. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1146. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1147. return 1;
  1148. }
  1149. static void
  1150. lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1151. struct lpfc_iocbq * rspiocb)
  1152. {
  1153. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1154. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1155. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1156. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1157. struct lpfc_nodelist *ndlp;
  1158. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1159. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1160. struct lpfc_vport *vport = cmdiocb->vport;
  1161. IOCB_t *irsp = &rspiocb->iocb;
  1162. uint32_t latt;
  1163. latt = lpfc_els_chk_latt(vport);
  1164. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1165. "FDMI cmpl: status:x%x/x%x latt:%d",
  1166. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1167. if (latt || irsp->ulpStatus) {
  1168. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1169. "0229 FDMI cmd %04x failed, latt = %d "
  1170. "ulpStatus: x%x, rid x%x\n",
  1171. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1172. irsp->un.ulpWord[4]);
  1173. lpfc_ct_free_iocb(phba, cmdiocb);
  1174. return;
  1175. }
  1176. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1177. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1178. goto fail_out;
  1179. if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  1180. /* FDMI rsp failed */
  1181. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1182. "0220 FDMI rsp failed Data: x%x\n",
  1183. be16_to_cpu(fdmi_cmd));
  1184. }
  1185. switch (be16_to_cpu(fdmi_cmd)) {
  1186. case SLI_MGMT_RHBA:
  1187. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA);
  1188. break;
  1189. case SLI_MGMT_RPA:
  1190. break;
  1191. case SLI_MGMT_DHBA:
  1192. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT);
  1193. break;
  1194. case SLI_MGMT_DPRT:
  1195. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA);
  1196. break;
  1197. }
  1198. fail_out:
  1199. lpfc_ct_free_iocb(phba, cmdiocb);
  1200. return;
  1201. }
  1202. int
  1203. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, int cmdcode)
  1204. {
  1205. struct lpfc_hba *phba = vport->phba;
  1206. struct lpfc_dmabuf *mp, *bmp;
  1207. struct lpfc_sli_ct_request *CtReq;
  1208. struct ulp_bde64 *bpl;
  1209. uint32_t size;
  1210. REG_HBA *rh;
  1211. PORT_ENTRY *pe;
  1212. REG_PORT_ATTRIBUTE *pab;
  1213. ATTRIBUTE_BLOCK *ab;
  1214. ATTRIBUTE_ENTRY *ae;
  1215. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1216. struct lpfc_iocbq *);
  1217. /* fill in BDEs for command */
  1218. /* Allocate buffer for command payload */
  1219. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1220. if (!mp)
  1221. goto fdmi_cmd_exit;
  1222. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  1223. if (!mp->virt)
  1224. goto fdmi_cmd_free_mp;
  1225. /* Allocate buffer for Buffer ptr list */
  1226. bmp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1227. if (!bmp)
  1228. goto fdmi_cmd_free_mpvirt;
  1229. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  1230. if (!bmp->virt)
  1231. goto fdmi_cmd_free_bmp;
  1232. INIT_LIST_HEAD(&mp->list);
  1233. INIT_LIST_HEAD(&bmp->list);
  1234. /* FDMI request */
  1235. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1236. "0218 FDMI Request Data: x%x x%x x%x\n",
  1237. vport->fc_flag, vport->port_state, cmdcode);
  1238. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1239. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1240. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1241. CtReq->RevisionId.bits.InId = 0;
  1242. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  1243. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  1244. size = 0;
  1245. switch (cmdcode) {
  1246. case SLI_MGMT_RHBA:
  1247. {
  1248. lpfc_vpd_t *vp = &phba->vpd;
  1249. uint32_t i, j, incr;
  1250. int len;
  1251. CtReq->CommandResponse.bits.CmdRsp =
  1252. be16_to_cpu(SLI_MGMT_RHBA);
  1253. CtReq->CommandResponse.bits.Size = 0;
  1254. rh = (REG_HBA *) & CtReq->un.PortID;
  1255. memcpy(&rh->hi.PortName, &vport->fc_sparam.portName,
  1256. sizeof (struct lpfc_name));
  1257. /* One entry (port) per adapter */
  1258. rh->rpl.EntryCnt = be32_to_cpu(1);
  1259. memcpy(&rh->rpl.pe, &vport->fc_sparam.portName,
  1260. sizeof (struct lpfc_name));
  1261. /* point to the HBA attribute block */
  1262. size = 2 * sizeof (struct lpfc_name) + FOURBYTES;
  1263. ab = (ATTRIBUTE_BLOCK *) ((uint8_t *) rh + size);
  1264. ab->EntryCnt = 0;
  1265. /* Point to the beginning of the first HBA attribute
  1266. entry */
  1267. /* #1 HBA attribute entry */
  1268. size += FOURBYTES;
  1269. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1270. ae->ad.bits.AttrType = be16_to_cpu(NODE_NAME);
  1271. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES
  1272. + sizeof (struct lpfc_name));
  1273. memcpy(&ae->un.NodeName, &vport->fc_sparam.nodeName,
  1274. sizeof (struct lpfc_name));
  1275. ab->EntryCnt++;
  1276. size += FOURBYTES + sizeof (struct lpfc_name);
  1277. /* #2 HBA attribute entry */
  1278. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1279. ae->ad.bits.AttrType = be16_to_cpu(MANUFACTURER);
  1280. strcpy(ae->un.Manufacturer, "Emulex Corporation");
  1281. len = strlen(ae->un.Manufacturer);
  1282. len += (len & 3) ? (4 - (len & 3)) : 4;
  1283. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1284. ab->EntryCnt++;
  1285. size += FOURBYTES + len;
  1286. /* #3 HBA attribute entry */
  1287. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1288. ae->ad.bits.AttrType = be16_to_cpu(SERIAL_NUMBER);
  1289. strcpy(ae->un.SerialNumber, phba->SerialNumber);
  1290. len = strlen(ae->un.SerialNumber);
  1291. len += (len & 3) ? (4 - (len & 3)) : 4;
  1292. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1293. ab->EntryCnt++;
  1294. size += FOURBYTES + len;
  1295. /* #4 HBA attribute entry */
  1296. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1297. ae->ad.bits.AttrType = be16_to_cpu(MODEL);
  1298. strcpy(ae->un.Model, phba->ModelName);
  1299. len = strlen(ae->un.Model);
  1300. len += (len & 3) ? (4 - (len & 3)) : 4;
  1301. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1302. ab->EntryCnt++;
  1303. size += FOURBYTES + len;
  1304. /* #5 HBA attribute entry */
  1305. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1306. ae->ad.bits.AttrType = be16_to_cpu(MODEL_DESCRIPTION);
  1307. strcpy(ae->un.ModelDescription, phba->ModelDesc);
  1308. len = strlen(ae->un.ModelDescription);
  1309. len += (len & 3) ? (4 - (len & 3)) : 4;
  1310. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1311. ab->EntryCnt++;
  1312. size += FOURBYTES + len;
  1313. /* #6 HBA attribute entry */
  1314. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1315. ae->ad.bits.AttrType = be16_to_cpu(HARDWARE_VERSION);
  1316. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 8);
  1317. /* Convert JEDEC ID to ascii for hardware version */
  1318. incr = vp->rev.biuRev;
  1319. for (i = 0; i < 8; i++) {
  1320. j = (incr & 0xf);
  1321. if (j <= 9)
  1322. ae->un.HardwareVersion[7 - i] =
  1323. (char)((uint8_t) 0x30 +
  1324. (uint8_t) j);
  1325. else
  1326. ae->un.HardwareVersion[7 - i] =
  1327. (char)((uint8_t) 0x61 +
  1328. (uint8_t) (j - 10));
  1329. incr = (incr >> 4);
  1330. }
  1331. ab->EntryCnt++;
  1332. size += FOURBYTES + 8;
  1333. /* #7 HBA attribute entry */
  1334. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1335. ae->ad.bits.AttrType = be16_to_cpu(DRIVER_VERSION);
  1336. strcpy(ae->un.DriverVersion, lpfc_release_version);
  1337. len = strlen(ae->un.DriverVersion);
  1338. len += (len & 3) ? (4 - (len & 3)) : 4;
  1339. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1340. ab->EntryCnt++;
  1341. size += FOURBYTES + len;
  1342. /* #8 HBA attribute entry */
  1343. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1344. ae->ad.bits.AttrType = be16_to_cpu(OPTION_ROM_VERSION);
  1345. strcpy(ae->un.OptionROMVersion, phba->OptionROMVersion);
  1346. len = strlen(ae->un.OptionROMVersion);
  1347. len += (len & 3) ? (4 - (len & 3)) : 4;
  1348. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1349. ab->EntryCnt++;
  1350. size += FOURBYTES + len;
  1351. /* #9 HBA attribute entry */
  1352. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1353. ae->ad.bits.AttrType = be16_to_cpu(FIRMWARE_VERSION);
  1354. lpfc_decode_firmware_rev(phba, ae->un.FirmwareVersion,
  1355. 1);
  1356. len = strlen(ae->un.FirmwareVersion);
  1357. len += (len & 3) ? (4 - (len & 3)) : 4;
  1358. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1359. ab->EntryCnt++;
  1360. size += FOURBYTES + len;
  1361. /* #10 HBA attribute entry */
  1362. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1363. ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
  1364. sprintf(ae->un.OsNameVersion, "%s %s %s",
  1365. init_utsname()->sysname,
  1366. init_utsname()->release,
  1367. init_utsname()->version);
  1368. len = strlen(ae->un.OsNameVersion);
  1369. len += (len & 3) ? (4 - (len & 3)) : 4;
  1370. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1371. ab->EntryCnt++;
  1372. size += FOURBYTES + len;
  1373. /* #11 HBA attribute entry */
  1374. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
  1375. ae->ad.bits.AttrType = be16_to_cpu(MAX_CT_PAYLOAD_LEN);
  1376. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1377. ae->un.MaxCTPayloadLen = (65 * 4096);
  1378. ab->EntryCnt++;
  1379. size += FOURBYTES + 4;
  1380. ab->EntryCnt = be32_to_cpu(ab->EntryCnt);
  1381. /* Total size */
  1382. size = GID_REQUEST_SZ - 4 + size;
  1383. }
  1384. break;
  1385. case SLI_MGMT_RPA:
  1386. {
  1387. lpfc_vpd_t *vp;
  1388. struct serv_parm *hsp;
  1389. int len;
  1390. vp = &phba->vpd;
  1391. CtReq->CommandResponse.bits.CmdRsp =
  1392. be16_to_cpu(SLI_MGMT_RPA);
  1393. CtReq->CommandResponse.bits.Size = 0;
  1394. pab = (REG_PORT_ATTRIBUTE *) & CtReq->un.PortID;
  1395. size = sizeof (struct lpfc_name) + FOURBYTES;
  1396. memcpy((uint8_t *) & pab->PortName,
  1397. (uint8_t *) & vport->fc_sparam.portName,
  1398. sizeof (struct lpfc_name));
  1399. pab->ab.EntryCnt = 0;
  1400. /* #1 Port attribute entry */
  1401. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1402. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_FC4_TYPES);
  1403. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 32);
  1404. ae->un.SupportFC4Types[2] = 1;
  1405. ae->un.SupportFC4Types[7] = 1;
  1406. pab->ab.EntryCnt++;
  1407. size += FOURBYTES + 32;
  1408. /* #2 Port attribute entry */
  1409. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1410. ae->ad.bits.AttrType = be16_to_cpu(SUPPORTED_SPEED);
  1411. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1412. ae->un.SupportSpeed = 0;
  1413. if (phba->lmt & LMT_16Gb)
  1414. ae->un.SupportSpeed |= HBA_PORTSPEED_16GBIT;
  1415. if (phba->lmt & LMT_10Gb)
  1416. ae->un.SupportSpeed |= HBA_PORTSPEED_10GBIT;
  1417. if (phba->lmt & LMT_8Gb)
  1418. ae->un.SupportSpeed |= HBA_PORTSPEED_8GBIT;
  1419. if (phba->lmt & LMT_4Gb)
  1420. ae->un.SupportSpeed |= HBA_PORTSPEED_4GBIT;
  1421. if (phba->lmt & LMT_2Gb)
  1422. ae->un.SupportSpeed |= HBA_PORTSPEED_2GBIT;
  1423. if (phba->lmt & LMT_1Gb)
  1424. ae->un.SupportSpeed |= HBA_PORTSPEED_1GBIT;
  1425. pab->ab.EntryCnt++;
  1426. size += FOURBYTES + 4;
  1427. /* #3 Port attribute entry */
  1428. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1429. ae->ad.bits.AttrType = be16_to_cpu(PORT_SPEED);
  1430. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1431. switch(phba->fc_linkspeed) {
  1432. case LPFC_LINK_SPEED_1GHZ:
  1433. ae->un.PortSpeed = HBA_PORTSPEED_1GBIT;
  1434. break;
  1435. case LPFC_LINK_SPEED_2GHZ:
  1436. ae->un.PortSpeed = HBA_PORTSPEED_2GBIT;
  1437. break;
  1438. case LPFC_LINK_SPEED_4GHZ:
  1439. ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
  1440. break;
  1441. case LPFC_LINK_SPEED_8GHZ:
  1442. ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
  1443. break;
  1444. case LPFC_LINK_SPEED_10GHZ:
  1445. ae->un.PortSpeed = HBA_PORTSPEED_10GBIT;
  1446. break;
  1447. case LPFC_LINK_SPEED_16GHZ:
  1448. ae->un.PortSpeed = HBA_PORTSPEED_16GBIT;
  1449. break;
  1450. default:
  1451. ae->un.PortSpeed = HBA_PORTSPEED_UNKNOWN;
  1452. break;
  1453. }
  1454. pab->ab.EntryCnt++;
  1455. size += FOURBYTES + 4;
  1456. /* #4 Port attribute entry */
  1457. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1458. ae->ad.bits.AttrType = be16_to_cpu(MAX_FRAME_SIZE);
  1459. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + 4);
  1460. hsp = (struct serv_parm *) & vport->fc_sparam;
  1461. ae->un.MaxFrameSize =
  1462. (((uint32_t) hsp->cmn.
  1463. bbRcvSizeMsb) << 8) | (uint32_t) hsp->cmn.
  1464. bbRcvSizeLsb;
  1465. pab->ab.EntryCnt++;
  1466. size += FOURBYTES + 4;
  1467. /* #5 Port attribute entry */
  1468. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab + size);
  1469. ae->ad.bits.AttrType = be16_to_cpu(OS_DEVICE_NAME);
  1470. strcpy((char *)ae->un.OsDeviceName, LPFC_DRIVER_NAME);
  1471. len = strlen((char *)ae->un.OsDeviceName);
  1472. len += (len & 3) ? (4 - (len & 3)) : 4;
  1473. ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
  1474. pab->ab.EntryCnt++;
  1475. size += FOURBYTES + len;
  1476. if (vport->cfg_fdmi_on == 2) {
  1477. /* #6 Port attribute entry */
  1478. ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) pab +
  1479. size);
  1480. ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
  1481. sprintf(ae->un.HostName, "%s",
  1482. init_utsname()->nodename);
  1483. len = strlen(ae->un.HostName);
  1484. len += (len & 3) ? (4 - (len & 3)) : 4;
  1485. ae->ad.bits.AttrLen =
  1486. be16_to_cpu(FOURBYTES + len);
  1487. pab->ab.EntryCnt++;
  1488. size += FOURBYTES + len;
  1489. }
  1490. pab->ab.EntryCnt = be32_to_cpu(pab->ab.EntryCnt);
  1491. /* Total size */
  1492. size = GID_REQUEST_SZ - 4 + size;
  1493. }
  1494. break;
  1495. case SLI_MGMT_DHBA:
  1496. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DHBA);
  1497. CtReq->CommandResponse.bits.Size = 0;
  1498. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1499. memcpy((uint8_t *) & pe->PortName,
  1500. (uint8_t *) & vport->fc_sparam.portName,
  1501. sizeof (struct lpfc_name));
  1502. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1503. break;
  1504. case SLI_MGMT_DPRT:
  1505. CtReq->CommandResponse.bits.CmdRsp = be16_to_cpu(SLI_MGMT_DPRT);
  1506. CtReq->CommandResponse.bits.Size = 0;
  1507. pe = (PORT_ENTRY *) & CtReq->un.PortID;
  1508. memcpy((uint8_t *) & pe->PortName,
  1509. (uint8_t *) & vport->fc_sparam.portName,
  1510. sizeof (struct lpfc_name));
  1511. size = GID_REQUEST_SZ - 4 + sizeof (struct lpfc_name);
  1512. break;
  1513. }
  1514. bpl = (struct ulp_bde64 *) bmp->virt;
  1515. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1516. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1517. bpl->tus.f.bdeFlags = 0