lpfc_mbox.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <scsi/scsi_device.h>
  25. #include <scsi/scsi_transport_fc.h>
  26. #include <scsi/scsi.h>
  27. #include "lpfc_hw.h"
  28. #include "lpfc_sli.h"
  29. #include "lpfc_disc.h"
  30. #include "lpfc_scsi.h"
  31. #include "lpfc.h"
  32. #include "lpfc_logmsg.h"
  33. #include "lpfc_crtn.h"
  34. #include "lpfc_compat.h"
  35. /**********************************************/
  36. /* mailbox command */
  37. /**********************************************/
  38. void
  39. lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
  40. {
  41. MAILBOX_t *mb;
  42. void *ctx;
  43. mb = &pmb->mb;
  44. ctx = pmb->context2;
  45. /* Setup to dump VPD region */
  46. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  47. mb->mbxCommand = MBX_DUMP_MEMORY;
  48. mb->un.varDmp.cv = 1;
  49. mb->un.varDmp.type = DMP_NV_PARAMS;
  50. mb->un.varDmp.entry_index = offset;
  51. mb->un.varDmp.region_id = DMP_REGION_VPD;
  52. mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
  53. mb->un.varDmp.co = 0;
  54. mb->un.varDmp.resp_offset = 0;
  55. pmb->context2 = ctx;
  56. mb->mbxOwner = OWN_HOST;
  57. return;
  58. }
  59. /**********************************************/
  60. /* lpfc_read_nv Issue a READ NVPARAM */
  61. /* mailbox command */
  62. /**********************************************/
  63. void
  64. lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  65. {
  66. MAILBOX_t *mb;
  67. mb = &pmb->mb;
  68. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  69. mb->mbxCommand = MBX_READ_NV;
  70. mb->mbxOwner = OWN_HOST;
  71. return;
  72. }
  73. /**********************************************/
  74. /* lpfc_read_la Issue a READ LA */
  75. /* mailbox command */
  76. /**********************************************/
  77. int
  78. lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
  79. {
  80. MAILBOX_t *mb;
  81. struct lpfc_sli *psli;
  82. psli = &phba->sli;
  83. mb = &pmb->mb;
  84. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  85. INIT_LIST_HEAD(&mp->list);
  86. mb->mbxCommand = MBX_READ_LA64;
  87. mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
  88. mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  89. mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
  90. /* Save address for later completion and set the owner to host so that
  91. * the FW knows this mailbox is available for processing.
  92. */
  93. pmb->context1 = (uint8_t *) mp;
  94. mb->mbxOwner = OWN_HOST;
  95. return (0);
  96. }
  97. /**********************************************/
  98. /* lpfc_clear_la Issue a CLEAR LA */
  99. /* mailbox command */
  100. /**********************************************/
  101. void
  102. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  103. {
  104. MAILBOX_t *mb;
  105. mb = &pmb->mb;
  106. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  107. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  108. mb->mbxCommand = MBX_CLEAR_LA;
  109. mb->mbxOwner = OWN_HOST;
  110. return;
  111. }
  112. /**************************************************/
  113. /* lpfc_config_link Issue a CONFIG LINK */
  114. /* mailbox command */
  115. /**************************************************/
  116. void
  117. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  118. {
  119. MAILBOX_t *mb = &pmb->mb;
  120. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  121. /* NEW_FEATURE
  122. * SLI-2, Coalescing Response Feature.
  123. */
  124. if (phba->cfg_cr_delay) {
  125. mb->un.varCfgLnk.cr = 1;
  126. mb->un.varCfgLnk.ci = 1;
  127. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  128. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  129. }
  130. mb->un.varCfgLnk.myId = phba->fc_myDID;
  131. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  132. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  133. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  134. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  135. mb->un.varCfgLnk.altov = phba->fc_altov;
  136. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  137. mb->un.varCfgLnk.citov = phba->fc_citov;
  138. if (phba->cfg_ack0)
  139. mb->un.varCfgLnk.ack0_enable = 1;
  140. mb->mbxCommand = MBX_CONFIG_LINK;
  141. mb->mbxOwner = OWN_HOST;
  142. return;
  143. }
  144. /**********************************************/
  145. /* lpfc_init_link Issue an INIT LINK */
  146. /* mailbox command */
  147. /**********************************************/
  148. void
  149. lpfc_init_link(struct lpfc_hba * phba,
  150. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  151. {
  152. lpfc_vpd_t *vpd;
  153. struct lpfc_sli *psli;
  154. MAILBOX_t *mb;
  155. mb = &pmb->mb;
  156. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  157. psli = &phba->sli;
  158. switch (topology) {
  159. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  160. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  161. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  162. break;
  163. case FLAGS_TOPOLOGY_MODE_PT_PT:
  164. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  165. break;
  166. case FLAGS_TOPOLOGY_MODE_LOOP:
  167. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  168. break;
  169. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  170. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  171. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  172. break;
  173. case FLAGS_LOCAL_LB:
  174. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  175. break;
  176. }
  177. /* NEW_FEATURE
  178. * Setting up the link speed
  179. */
  180. vpd = &phba->vpd;
  181. if (vpd->rev.feaLevelHigh >= 0x02){
  182. switch(linkspeed){
  183. case LINK_SPEED_1G:
  184. case LINK_SPEED_2G:
  185. case LINK_SPEED_4G:
  186. mb->un.varInitLnk.link_flags |=
  187. FLAGS_LINK_SPEED;
  188. mb->un.varInitLnk.link_speed = linkspeed;
  189. break;
  190. case LINK_SPEED_AUTO:
  191. default:
  192. mb->un.varInitLnk.link_speed =
  193. LINK_SPEED_AUTO;
  194. break;
  195. }
  196. }
  197. else
  198. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  199. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  200. mb->mbxOwner = OWN_HOST;
  201. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  202. return;
  203. }
  204. /**********************************************/
  205. /* lpfc_read_sparam Issue a READ SPARAM */
  206. /* mailbox command */
  207. /**********************************************/
  208. int
  209. lpfc_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  210. {
  211. struct lpfc_dmabuf *mp;
  212. MAILBOX_t *mb;
  213. struct lpfc_sli *psli;
  214. psli = &phba->sli;
  215. mb = &pmb->mb;
  216. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  217. mb->mbxOwner = OWN_HOST;
  218. /* Get a buffer to hold the HBAs Service Parameters */
  219. if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
  220. ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
  221. kfree(mp);
  222. mb->mbxCommand = MBX_READ_SPARM64;
  223. /* READ_SPARAM: no buffers */
  224. lpfc_printf_log(phba,
  225. KERN_WARNING,
  226. LOG_MBOX,
  227. "%d:0301 READ_SPARAM: no buffers\n",
  228. phba->brd_no);
  229. return (1);
  230. }
  231. INIT_LIST_HEAD(&mp->list);
  232. mb->mbxCommand = MBX_READ_SPARM64;
  233. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  234. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  235. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  236. /* save address for completion */
  237. pmb->context1 = mp;
  238. return (0);
  239. }
  240. /********************************************/
  241. /* lpfc_unreg_did Issue a UNREG_DID */
  242. /* mailbox command */
  243. /********************************************/
  244. void
  245. lpfc_unreg_did(struct lpfc_hba * phba, uint32_t did, LPFC_MBOXQ_t * pmb)
  246. {
  247. MAILBOX_t *mb;
  248. mb = &pmb->mb;
  249. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  250. mb->un.varUnregDID.did = did;
  251. mb->mbxCommand = MBX_UNREG_D_ID;
  252. mb->mbxOwner = OWN_HOST;
  253. return;
  254. }
  255. /***********************************************/
  256. /* command to write slim */
  257. /***********************************************/
  258. void
  259. lpfc_set_slim(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint32_t addr,
  260. uint32_t value)
  261. {
  262. MAILBOX_t *mb;
  263. mb = &pmb->mb;
  264. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  265. /* addr = 0x090597 is AUTO ABTS disable for ELS commands */
  266. /* addr = 0x052198 is DELAYED ABTS enable for ELS commands */
  267. /*
  268. * Always turn on DELAYED ABTS for ELS timeouts
  269. */
  270. if ((addr == 0x052198) && (value == 0))
  271. value = 1;
  272. mb->un.varWords[0] = addr;
  273. mb->un.varWords[1] = value;
  274. mb->mbxCommand = MBX_SET_SLIM;
  275. mb->mbxOwner = OWN_HOST;
  276. return;
  277. }
  278. /**********************************************/
  279. /* lpfc_read_nv Issue a READ CONFIG */
  280. /* mailbox command */
  281. /**********************************************/
  282. void
  283. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  284. {
  285. MAILBOX_t *mb;
  286. mb = &pmb->mb;
  287. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  288. mb->mbxCommand = MBX_READ_CONFIG;
  289. mb->mbxOwner = OWN_HOST;
  290. return;
  291. }
  292. /*************************************************/
  293. /* lpfc_read_lnk_stat Issue a READ LINK STATUS */
  294. /* mailbox command */
  295. /*************************************************/
  296. void
  297. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  298. {
  299. MAILBOX_t *mb;
  300. mb = &pmb->mb;
  301. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  302. mb->mbxCommand = MBX_READ_LNK_STAT;
  303. mb->mbxOwner = OWN_HOST;
  304. return;
  305. }
  306. /********************************************/
  307. /* lpfc_reg_login Issue a REG_LOGIN */
  308. /* mailbox command */
  309. /********************************************/
  310. int
  311. lpfc_reg_login(struct lpfc_hba * phba,
  312. uint32_t did, uint8_t * param, LPFC_MBOXQ_t * pmb, uint32_t flag)
  313. {
  314. uint8_t *sparam;
  315. struct lpfc_dmabuf *mp;
  316. MAILBOX_t *mb;
  317. struct lpfc_sli *psli;
  318. psli = &phba->sli;
  319. mb = &pmb->mb;
  320. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  321. mb->un.varRegLogin.rpi = 0;
  322. mb->un.varRegLogin.did = did;
  323. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  324. mb->mbxOwner = OWN_HOST;
  325. /* Get a buffer to hold NPorts Service Parameters */
  326. if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
  327. ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
  328. kfree(mp);
  329. mb->mbxCommand = MBX_REG_LOGIN64;
  330. /* REG_LOGIN: no buffers */
  331. lpfc_printf_log(phba,
  332. KERN_WARNING,
  333. LOG_MBOX,
  334. "%d:0302 REG_LOGIN: no buffers Data x%x x%x\n",
  335. phba->brd_no,
  336. (uint32_t) did, (uint32_t) flag);
  337. return (1);
  338. }
  339. INIT_LIST_HEAD(&mp->list);
  340. sparam = mp->virt;
  341. /* Copy param's into a new buffer */
  342. memcpy(sparam, param, sizeof (struct serv_parm));
  343. /* save address for completion */
  344. pmb->context1 = (uint8_t *) mp;
  345. mb->mbxCommand = MBX_REG_LOGIN64;
  346. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  347. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  348. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  349. return (0);
  350. }
  351. /**********************************************/
  352. /* lpfc_unreg_login Issue a UNREG_LOGIN */
  353. /* mailbox command */
  354. /**********************************************/
  355. void
  356. lpfc_unreg_login(struct lpfc_hba * phba, uint32_t rpi, LPFC_MBOXQ_t * pmb)
  357. {
  358. MAILBOX_t *mb;
  359. mb = &pmb->mb;
  360. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  361. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  362. mb->un.varUnregLogin.rsvd1 = 0;
  363. mb->mbxCommand = MBX_UNREG_LOGIN;
  364. mb->mbxOwner = OWN_HOST;
  365. return;
  366. }
  367. static void
  368. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  369. {
  370. struct lpfc_sli *psli = &phba->sli;
  371. struct lpfc_sli_ring *pring;
  372. PCB_t *pcbp = &phba->slim2p->pcb;
  373. dma_addr_t pdma_addr;
  374. uint32_t offset;
  375. uint32_t iocbCnt;
  376. int i;
  377. pcbp->maxRing = (psli->num_rings - 1);
  378. iocbCnt = 0;
  379. for (i = 0; i < psli->num_rings; i++) {
  380. pring = &psli->ring[i];
  381. /* A ring MUST have both cmd and rsp entries defined to be
  382. valid */
  383. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  384. pcbp->rdsc[i].cmdEntries = 0;
  385. pcbp->rdsc[i].rspEntries = 0;
  386. pcbp->rdsc[i].cmdAddrHigh = 0;
  387. pcbp->rdsc[i].rspAddrHigh = 0;
  388. pcbp->rdsc[i].cmdAddrLow = 0;
  389. pcbp->rdsc[i].rspAddrLow = 0;
  390. pring->cmdringaddr = NULL;
  391. pring->rspringaddr = NULL;
  392. continue;
  393. }
  394. /* Command ring setup for ring */
  395. pring->cmdringaddr =
  396. (void *)&phba->slim2p->IOCBs[iocbCnt];
  397. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  398. offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
  399. (uint8_t *)phba->slim2p;
  400. pdma_addr = phba->slim2p_mapping + offset;
  401. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  402. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  403. iocbCnt += pring->numCiocb;
  404. /* Response ring setup for ring */
  405. pring->rspringaddr =
  406. (void *)&phba->slim2p->IOCBs[iocbCnt];
  407. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  408. offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
  409. (uint8_t *)phba->slim2p;
  410. pdma_addr = phba->slim2p_mapping + offset;
  411. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  412. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  413. iocbCnt += pring->numRiocb;
  414. }
  415. }
  416. void
  417. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  418. {
  419. MAILBOX_t *mb;
  420. mb = &pmb->mb;
  421. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  422. mb->un.varRdRev.cv = 1;
  423. mb->mbxCommand = MBX_READ_REV;
  424. mb->mbxOwner = OWN_HOST;
  425. return;
  426. }
  427. void
  428. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  429. {
  430. int i;
  431. MAILBOX_t *mb = &pmb->mb;
  432. struct lpfc_sli *psli;
  433. struct lpfc_sli_ring *pring;
  434. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  435. mb->un.varCfgRing.ring = ring;
  436. mb->un.varCfgRing.maxOrigXchg = 0;
  437. mb->un.varCfgRing.maxRespXchg = 0;
  438. mb->un.varCfgRing.recvNotify = 1;
  439. psli = &phba->sli;
  440. pring = &psli->ring[ring];
  441. mb->un.varCfgRing.numMask = pring->num_mask;
  442. mb->mbxCommand = MBX_CONFIG_RING;
  443. mb->mbxOwner = OWN_HOST;
  444. /* Is this ring configured for a specific profile */
  445. if (pring->prt[0].profile) {
  446. mb->un.varCfgRing.profile = pring->prt[0].profile;
  447. return;
  448. }
  449. /* Otherwise we setup specific rctl / type masks for this ring */
  450. for (i = 0; i < pring->num_mask; i++) {
  451. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  452. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  453. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  454. else
  455. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  456. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  457. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  458. }
  459. return;
  460. }
  461. void
  462. lpfc_config_port(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  463. {
  464. MAILBOX_t *mb = &pmb->mb;
  465. dma_addr_t pdma_addr;
  466. uint32_t bar_low, bar_high;
  467. size_t offset;
  468. struct lpfc_hgp hgp;
  469. void __iomem *to_slim;
  470. int i;
  471. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  472. mb->mbxCommand = MBX_CONFIG_PORT;
  473. mb->mbxOwner = OWN_HOST;
  474. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  475. offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
  476. pdma_addr = phba->slim2p_mapping + offset;
  477. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  478. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  479. /* Now setup pcb */
  480. phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
  481. phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
  482. /* Setup Mailbox pointers */
  483. phba->slim2p->pcb.mailBoxSize = sizeof(MAILBOX_t);
  484. offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
  485. pdma_addr = phba->slim2p_mapping + offset;
  486. phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
  487. phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
  488. /*
  489. * Setup Host Group ring pointer.
  490. *
  491. * For efficiency reasons, the ring get/put pointers can be
  492. * placed in adapter memory (SLIM) rather than in host memory.
  493. * This allows firmware to avoid PCI reads/writes when updating
  494. * and checking pointers.
  495. *
  496. * The firmware recognizes the use of SLIM memory by comparing
  497. * the address of the get/put pointers structure with that of
  498. * the SLIM BAR (BAR0).
  499. *
  500. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  501. * (the hardware's view of the base address), not the OS's
  502. * value of pci_resource_start() as the OS value may be a cookie
  503. * for ioremap/iomap.
  504. */
  505. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  506. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  507. /* mask off BAR0's flag bits 0 - 3 */
  508. phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  509. (SLIMOFF*sizeof(uint32_t));
  510. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  511. phba->slim2p->pcb.hgpAddrHigh = bar_high;
  512. else
  513. phba->slim2p->pcb.hgpAddrHigh = 0;
  514. /* write HGP data to SLIM at the required longword offset */
  515. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  516. to_slim = phba->MBslimaddr + (SLIMOFF*sizeof (uint32_t));
  517. for (i=0; i < phba->sli.num_rings; i++) {
  518. lpfc_memcpy_to_slim(to_slim, &hgp, sizeof(struct lpfc_hgp));
  519. to_slim += sizeof (struct lpfc_hgp);
  520. }
  521. /* Setup Port Group ring pointer */
  522. offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
  523. (uint8_t *)phba->slim2p;
  524. pdma_addr = phba->slim2p_mapping + offset;
  525. phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
  526. phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
  527. /* Use callback routine to setp rings in the pcb */
  528. lpfc_config_pcb_setup(phba);
  529. /* special handling for LC HBAs */
  530. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  531. uint32_t hbainit[5];
  532. lpfc_hba_init(phba, hbainit);
  533. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  534. }
  535. /* Swap PCB if needed */
  536. lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb,
  537. sizeof (PCB_t));
  538. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  539. "%d:0405 Service Level Interface (SLI) 2 selected\n",
  540. phba->brd_no);
  541. }
  542. void
  543. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  544. {
  545. MAILBOX_t *mb = &pmb->mb;
  546. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  547. mb->mbxCommand = MBX_KILL_BOARD;
  548. mb->mbxOwner = OWN_HOST;
  549. return;
  550. }
  551. void
  552. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  553. {
  554. struct lpfc_sli *psli;
  555. psli = &phba->sli;
  556. list_add_tail(&mbq->list, &psli->mboxq);
  557. psli->mboxq_cnt++;
  558. return;
  559. }
  560. LPFC_MBOXQ_t *
  561. lpfc_mbox_get(struct lpfc_hba * phba)
  562. {
  563. LPFC_MBOXQ_t *mbq = NULL;
  564. struct lpfc_sli *psli = &phba->sli;
  565. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t,
  566. list);
  567. if (mbq) {
  568. psli->mboxq_cnt--;
  569. }
  570. return mbq;
  571. }