lpfc_mbox.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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. * 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_heart_beat Issue a HEART_BEAT */
  75. /* mailbox command */
  76. /**********************************************/
  77. void
  78. lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  79. {
  80. MAILBOX_t *mb;
  81. mb = &pmb->mb;
  82. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  83. mb->mbxCommand = MBX_HEARTBEAT;
  84. mb->mbxOwner = OWN_HOST;
  85. return;
  86. }
  87. /**********************************************/
  88. /* lpfc_read_la Issue a READ LA */
  89. /* mailbox command */
  90. /**********************************************/
  91. int
  92. lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
  93. {
  94. MAILBOX_t *mb;
  95. struct lpfc_sli *psli;
  96. psli = &phba->sli;
  97. mb = &pmb->mb;
  98. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  99. INIT_LIST_HEAD(&mp->list);
  100. mb->mbxCommand = MBX_READ_LA64;
  101. mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
  102. mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  103. mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
  104. /* Save address for later completion and set the owner to host so that
  105. * the FW knows this mailbox is available for processing.
  106. */
  107. pmb->context1 = (uint8_t *) mp;
  108. mb->mbxOwner = OWN_HOST;
  109. return (0);
  110. }
  111. /**********************************************/
  112. /* lpfc_clear_la Issue a CLEAR LA */
  113. /* mailbox command */
  114. /**********************************************/
  115. void
  116. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  117. {
  118. MAILBOX_t *mb;
  119. mb = &pmb->mb;
  120. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  121. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  122. mb->mbxCommand = MBX_CLEAR_LA;
  123. mb->mbxOwner = OWN_HOST;
  124. return;
  125. }
  126. /**************************************************/
  127. /* lpfc_config_link Issue a CONFIG LINK */
  128. /* mailbox command */
  129. /**************************************************/
  130. void
  131. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  132. {
  133. struct lpfc_vport *vport = phba->pport;
  134. MAILBOX_t *mb = &pmb->mb;
  135. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  136. /* NEW_FEATURE
  137. * SLI-2, Coalescing Response Feature.
  138. */
  139. if (phba->cfg_cr_delay) {
  140. mb->un.varCfgLnk.cr = 1;
  141. mb->un.varCfgLnk.ci = 1;
  142. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  143. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  144. }
  145. mb->un.varCfgLnk.myId = vport->fc_myDID;
  146. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  147. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  148. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  149. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  150. mb->un.varCfgLnk.altov = phba->fc_altov;
  151. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  152. mb->un.varCfgLnk.citov = phba->fc_citov;
  153. if (phba->cfg_ack0)
  154. mb->un.varCfgLnk.ack0_enable = 1;
  155. mb->mbxCommand = MBX_CONFIG_LINK;
  156. mb->mbxOwner = OWN_HOST;
  157. return;
  158. }
  159. /**********************************************/
  160. /* lpfc_init_link Issue an INIT LINK */
  161. /* mailbox command */
  162. /**********************************************/
  163. void
  164. lpfc_init_link(struct lpfc_hba * phba,
  165. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  166. {
  167. lpfc_vpd_t *vpd;
  168. struct lpfc_sli *psli;
  169. MAILBOX_t *mb;
  170. mb = &pmb->mb;
  171. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  172. psli = &phba->sli;
  173. switch (topology) {
  174. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  175. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  176. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  177. break;
  178. case FLAGS_TOPOLOGY_MODE_PT_PT:
  179. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  180. break;
  181. case FLAGS_TOPOLOGY_MODE_LOOP:
  182. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  183. break;
  184. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  185. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  186. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  187. break;
  188. case FLAGS_LOCAL_LB:
  189. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  190. break;
  191. }
  192. /* Enable asynchronous ABTS responses from firmware */
  193. mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
  194. /* NEW_FEATURE
  195. * Setting up the link speed
  196. */
  197. vpd = &phba->vpd;
  198. if (vpd->rev.feaLevelHigh >= 0x02){
  199. switch(linkspeed){
  200. case LINK_SPEED_1G:
  201. case LINK_SPEED_2G:
  202. case LINK_SPEED_4G:
  203. case LINK_SPEED_8G:
  204. mb->un.varInitLnk.link_flags |=
  205. FLAGS_LINK_SPEED;
  206. mb->un.varInitLnk.link_speed = linkspeed;
  207. break;
  208. case LINK_SPEED_AUTO:
  209. default:
  210. mb->un.varInitLnk.link_speed =
  211. LINK_SPEED_AUTO;
  212. break;
  213. }
  214. }
  215. else
  216. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  217. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  218. mb->mbxOwner = OWN_HOST;
  219. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  220. return;
  221. }
  222. /**********************************************/
  223. /* lpfc_read_sparam Issue a READ SPARAM */
  224. /* mailbox command */
  225. /**********************************************/
  226. int
  227. lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
  228. {
  229. struct lpfc_dmabuf *mp;
  230. MAILBOX_t *mb;
  231. struct lpfc_sli *psli;
  232. psli = &phba->sli;
  233. mb = &pmb->mb;
  234. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  235. mb->mbxOwner = OWN_HOST;
  236. /* Get a buffer to hold the HBAs Service Parameters */
  237. if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
  238. ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
  239. kfree(mp);
  240. mb->mbxCommand = MBX_READ_SPARM64;
  241. /* READ_SPARAM: no buffers */
  242. lpfc_printf_log(phba,
  243. KERN_WARNING,
  244. LOG_MBOX,
  245. "%d:0301 READ_SPARAM: no buffers\n",
  246. phba->brd_no);
  247. return (1);
  248. }
  249. INIT_LIST_HEAD(&mp->list);
  250. mb->mbxCommand = MBX_READ_SPARM64;
  251. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  252. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  253. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  254. mb->un.varRdSparm.vpi = vpi;
  255. /* save address for completion */
  256. pmb->context1 = mp;
  257. return (0);
  258. }
  259. /********************************************/
  260. /* lpfc_unreg_did Issue a UNREG_DID */
  261. /* mailbox command */
  262. /********************************************/
  263. void
  264. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  265. LPFC_MBOXQ_t * pmb)
  266. {
  267. MAILBOX_t *mb;
  268. mb = &pmb->mb;
  269. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  270. mb->un.varUnregDID.did = did;
  271. mb->un.varUnregDID.vpi = vpi;
  272. mb->mbxCommand = MBX_UNREG_D_ID;
  273. mb->mbxOwner = OWN_HOST;
  274. return;
  275. }
  276. /**********************************************/
  277. /* lpfc_read_nv Issue a READ CONFIG */
  278. /* mailbox command */
  279. /**********************************************/
  280. void
  281. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  282. {
  283. MAILBOX_t *mb;
  284. mb = &pmb->mb;
  285. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  286. mb->mbxCommand = MBX_READ_CONFIG;
  287. mb->mbxOwner = OWN_HOST;
  288. return;
  289. }
  290. /*************************************************/
  291. /* lpfc_read_lnk_stat Issue a READ LINK STATUS */
  292. /* mailbox command */
  293. /*************************************************/
  294. void
  295. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  296. {
  297. MAILBOX_t *mb;
  298. mb = &pmb->mb;
  299. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  300. mb->mbxCommand = MBX_READ_LNK_STAT;
  301. mb->mbxOwner = OWN_HOST;
  302. return;
  303. }
  304. /********************************************/
  305. /* lpfc_reg_login Issue a REG_LOGIN */
  306. /* mailbox command */
  307. /********************************************/
  308. int
  309. lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  310. uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
  311. {
  312. MAILBOX_t *mb = &pmb->mb;
  313. uint8_t *sparam;
  314. struct lpfc_dmabuf *mp;
  315. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  316. mb->un.varRegLogin.rpi = 0;
  317. mb->un.varRegLogin.vpi = vpi;
  318. mb->un.varRegLogin.did = did;
  319. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  320. mb->mbxOwner = OWN_HOST;
  321. /* Get a buffer to hold NPorts Service Parameters */
  322. if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
  323. ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
  324. kfree(mp);
  325. mb->mbxCommand = MBX_REG_LOGIN64;
  326. /* REG_LOGIN: no buffers */
  327. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  328. "%d (%d):0302 REG_LOGIN: no buffers, DID x%x, "
  329. "flag x%x\n",
  330. phba->brd_no, vpi, did, flag);
  331. return (1);
  332. }
  333. INIT_LIST_HEAD(&mp->list);
  334. sparam = mp->virt;
  335. /* Copy param's into a new buffer */
  336. memcpy(sparam, param, sizeof (struct serv_parm));
  337. /* save address for completion */
  338. pmb->context1 = (uint8_t *) mp;
  339. mb->mbxCommand = MBX_REG_LOGIN64;
  340. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  341. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  342. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  343. return (0);
  344. }
  345. /**********************************************/
  346. /* lpfc_unreg_login Issue a UNREG_LOGIN */
  347. /* mailbox command */
  348. /**********************************************/
  349. void
  350. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  351. LPFC_MBOXQ_t * pmb)
  352. {
  353. MAILBOX_t *mb;
  354. mb = &pmb->mb;
  355. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  356. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  357. mb->un.varUnregLogin.rsvd1 = 0;
  358. mb->un.varUnregLogin.vpi = vpi;
  359. mb->mbxCommand = MBX_UNREG_LOGIN;
  360. mb->mbxOwner = OWN_HOST;
  361. return;
  362. }
  363. /**************************************************/
  364. /* lpfc_reg_vpi Issue a REG_VPI */
  365. /* mailbox command */
  366. /**************************************************/
  367. void
  368. lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
  369. LPFC_MBOXQ_t *pmb)
  370. {
  371. MAILBOX_t *mb = &pmb->mb;
  372. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  373. mb->un.varRegVpi.vpi = vpi;
  374. mb->un.varRegVpi.sid = sid;
  375. mb->mbxCommand = MBX_REG_VPI;
  376. mb->mbxOwner = OWN_HOST;
  377. return;
  378. }
  379. /**************************************************/
  380. /* lpfc_unreg_vpi Issue a UNREG_VNPI */
  381. /* mailbox command */
  382. /**************************************************/
  383. void
  384. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  385. {
  386. MAILBOX_t *mb = &pmb->mb;
  387. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  388. mb->un.varUnregVpi.vpi = vpi;
  389. mb->mbxCommand = MBX_UNREG_VPI;
  390. mb->mbxOwner = OWN_HOST;
  391. return;
  392. }
  393. static void
  394. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  395. {
  396. struct lpfc_sli *psli = &phba->sli;
  397. struct lpfc_sli_ring *pring;
  398. PCB_t *pcbp = &phba->slim2p->pcb;
  399. dma_addr_t pdma_addr;
  400. uint32_t offset;
  401. uint32_t iocbCnt = 0;
  402. int i;
  403. pcbp->maxRing = (psli->num_rings - 1);
  404. for (i = 0; i < psli->num_rings; i++) {
  405. pring = &psli->ring[i];
  406. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  407. SLI2_IOCB_CMD_SIZE;
  408. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  409. SLI2_IOCB_RSP_SIZE;
  410. /* A ring MUST have both cmd and rsp entries defined to be
  411. valid */
  412. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  413. pcbp->rdsc[i].cmdEntries = 0;
  414. pcbp->rdsc[i].rspEntries = 0;
  415. pcbp->rdsc[i].cmdAddrHigh = 0;
  416. pcbp->rdsc[i].rspAddrHigh = 0;
  417. pcbp->rdsc[i].cmdAddrLow = 0;
  418. pcbp->rdsc[i].rspAddrLow = 0;
  419. pring->cmdringaddr = NULL;
  420. pring->rspringaddr = NULL;
  421. continue;
  422. }
  423. /* Command ring setup for ring */
  424. pring->cmdringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
  425. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  426. offset = (uint8_t *) &phba->slim2p->IOCBs[iocbCnt] -
  427. (uint8_t *) phba->slim2p;
  428. pdma_addr = phba->slim2p_mapping + offset;
  429. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  430. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  431. iocbCnt += pring->numCiocb;
  432. /* Response ring setup for ring */
  433. pring->rspringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
  434. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  435. offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
  436. (uint8_t *)phba->slim2p;
  437. pdma_addr = phba->slim2p_mapping + offset;
  438. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  439. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  440. iocbCnt += pring->numRiocb;
  441. }
  442. }
  443. void
  444. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  445. {
  446. MAILBOX_t *mb = &pmb->mb;
  447. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  448. mb->un.varRdRev.cv = 1;
  449. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  450. mb->mbxCommand = MBX_READ_REV;
  451. mb->mbxOwner = OWN_HOST;
  452. return;
  453. }
  454. static void
  455. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  456. struct lpfc_hbq_init *hbq_desc)
  457. {
  458. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  459. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  460. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  461. }
  462. static void
  463. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  464. struct lpfc_hbq_init *hbq_desc)
  465. {
  466. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  467. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  468. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  469. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  470. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  471. sizeof(hbqmb->profiles.profile3.cmdmatch));
  472. }
  473. static void
  474. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  475. struct lpfc_hbq_init *hbq_desc)
  476. {
  477. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  478. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  479. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  480. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  481. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  482. sizeof(hbqmb->profiles.profile5.cmdmatch));
  483. }
  484. void
  485. lpfc_config_hbq(struct lpfc_hba *phba, struct lpfc_hbq_init *hbq_desc,
  486. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  487. {
  488. int i;
  489. MAILBOX_t *mb = &pmb->mb;
  490. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  491. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  492. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  493. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  494. * Notification */
  495. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  496. * # in words 0-19 */
  497. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  498. * 0 = all,
  499. * 7 = logentry */
  500. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  501. * e.g. Ring0=b0001,
  502. * ring2=b0100 */
  503. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  504. * or 5 */
  505. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  506. * HBQ will be used
  507. * for LogEntry
  508. * buffers */
  509. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  510. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  511. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  512. mb->mbxCommand = MBX_CONFIG_HBQ;
  513. mb->mbxOwner = OWN_HOST;
  514. /* Copy info for profiles 2,3,5. Other
  515. * profiles this area is reserved
  516. */
  517. if (hbq_desc->profile == 2)
  518. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  519. else if (hbq_desc->profile == 3)
  520. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  521. else if (hbq_desc->profile == 5)
  522. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  523. /* Return if no rctl / type masks for this HBQ */
  524. if (!hbq_desc->mask_count)
  525. return;
  526. /* Otherwise we setup specific rctl / type masks for this HBQ */
  527. for (i = 0; i < hbq_desc->mask_count; i++) {
  528. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  529. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  530. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  531. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  532. }
  533. return;
  534. }
  535. void
  536. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  537. {
  538. int i;
  539. MAILBOX_t *mb = &pmb->mb;
  540. struct lpfc_sli *psli;
  541. struct lpfc_sli_ring *pring;
  542. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  543. mb->un.varCfgRing.ring = ring;
  544. mb->un.varCfgRing.maxOrigXchg = 0;
  545. mb->un.varCfgRing.maxRespXchg = 0;
  546. mb->un.varCfgRing.recvNotify = 1;
  547. psli = &phba->sli;
  548. pring = &psli->ring[ring];
  549. mb->un.varCfgRing.numMask = pring->num_mask;
  550. mb->mbxCommand = MBX_CONFIG_RING;
  551. mb->mbxOwner = OWN_HOST;
  552. /* Is this ring configured for a specific profile */
  553. if (pring->prt[0].profile) {
  554. mb->un.varCfgRing.profile = pring->prt[0].profile;
  555. return;
  556. }
  557. /* Otherwise we setup specific rctl / type masks for this ring */
  558. for (i = 0; i < pring->num_mask; i++) {
  559. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  560. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  561. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  562. else
  563. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  564. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  565. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  566. }
  567. return;
  568. }
  569. void
  570. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  571. {
  572. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  573. MAILBOX_t *mb = &pmb->mb;
  574. dma_addr_t pdma_addr;
  575. uint32_t bar_low, bar_high;
  576. size_t offset;
  577. struct lpfc_hgp hgp;
  578. int i;
  579. uint32_t pgp_offset;
  580. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  581. mb->mbxCommand = MBX_CONFIG_PORT;
  582. mb->mbxOwner = OWN_HOST;
  583. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  584. offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
  585. pdma_addr = phba->slim2p_mapping + offset;
  586. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  587. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  588. /* If HBA supports SLI=3 ask for it */
  589. if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
  590. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  591. mb->un.varCfgPort.max_hbq = 1; /* Requesting 2 HBQs */
  592. if (phba->max_vpi && phba->cfg_npiv_enable &&
  593. phba->vpd.sli3Feat.cmv) {
  594. mb->un.varCfgPort.max_vpi = phba->max_vpi;
  595. mb->un.varCfgPort.cmv = 1;
  596. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  597. } else
  598. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  599. } else
  600. phba->sli_rev = 2;
  601. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  602. /* Now setup pcb */
  603. phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
  604. phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
  605. /* Setup Mailbox pointers */
  606. phba->slim2p->pcb.mailBoxSize = offsetof(MAILBOX_t, us) +
  607. sizeof(struct sli2_desc);
  608. offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
  609. pdma_addr = phba->slim2p_mapping + offset;
  610. phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
  611. phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
  612. /*
  613. * Setup Host Group ring pointer.
  614. *
  615. * For efficiency reasons, the ring get/put pointers can be
  616. * placed in adapter memory (SLIM) rather than in host memory.
  617. * This allows firmware to avoid PCI reads/writes when updating
  618. * and checking pointers.
  619. *
  620. * The firmware recognizes the use of SLIM memory by comparing
  621. * the address of the get/put pointers structure with that of
  622. * the SLIM BAR (BAR0).
  623. *
  624. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  625. * (the hardware's view of the base address), not the OS's
  626. * value of pci_resource_start() as the OS value may be a cookie
  627. * for ioremap/iomap.
  628. */
  629. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  630. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  631. /*
  632. * Set up HGP - Port Memory
  633. *
  634. * The port expects the host get/put pointers to reside in memory
  635. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  636. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  637. * words (0x40 bytes). This area is not reserved if HBQs are
  638. * configured in SLI-3.
  639. *
  640. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  641. * RR0Get 0xc4 0x84
  642. * CR1Put 0xc8 0x88
  643. * RR1Get 0xcc 0x8c
  644. * CR2Put 0xd0 0x90
  645. * RR2Get 0xd4 0x94
  646. * CR3Put 0xd8 0x98
  647. * RR3Get 0xdc 0x9c
  648. *
  649. * Reserved 0xa0-0xbf
  650. * If HBQs configured:
  651. * HBQ 0 Put ptr 0xc0
  652. * HBQ 1 Put ptr 0xc4
  653. * HBQ 2 Put ptr 0xc8
  654. * ......
  655. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  656. *
  657. */
  658. if (phba->sli_rev == 3) {
  659. phba->host_gp = &mb_slim->us.s3.host[0];
  660. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  661. } else {
  662. phba->host_gp = &mb_slim->us.s2.host[0];
  663. phba->hbq_put = NULL;
  664. }
  665. /* mask off BAR0's flag bits 0 - 3 */
  666. phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  667. (void __iomem *) phba->host_gp -
  668. (void __iomem *)phba->MBslimaddr;
  669. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  670. phba->slim2p->pcb.hgpAddrHigh = bar_high;
  671. else
  672. phba->slim2p->pcb.hgpAddrHigh = 0;
  673. /* write HGP data to SLIM at the required longword offset */
  674. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  675. for (i=0; i < phba->sli.num_rings; i++) {
  676. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  677. sizeof(*phba->host_gp));
  678. }
  679. /* Setup Port Group ring pointer */
  680. if (phba->sli_rev == 3)
  681. pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s3_pgp.port -
  682. (uint8_t *)phba->slim2p;
  683. else
  684. pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
  685. (uint8_t *)phba->slim2p;
  686. pdma_addr = phba->slim2p_mapping + pgp_offset;
  687. phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
  688. phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
  689. phba->hbq_get = &phba->slim2p->mbx.us.s3_pgp.hbq_get[0];
  690. /* Use callback routine to setp rings in the pcb */
  691. lpfc_config_pcb_setup(phba);
  692. /* special handling for LC HBAs */
  693. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  694. uint32_t hbainit[5];
  695. lpfc_hba_init(phba, hbainit);
  696. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  697. }
  698. /* Swap PCB if needed */
  699. lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb,
  700. sizeof(PCB_t));
  701. }
  702. void
  703. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  704. {
  705. MAILBOX_t *mb = &pmb->mb;
  706. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  707. mb->mbxCommand = MBX_KILL_BOARD;
  708. mb->mbxOwner = OWN_HOST;
  709. return;
  710. }
  711. void
  712. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  713. {
  714. struct lpfc_sli *psli;
  715. psli = &phba->sli;
  716. list_add_tail(&mbq->list, &psli->mboxq);
  717. psli->mboxq_cnt++;
  718. return;
  719. }
  720. LPFC_MBOXQ_t *
  721. lpfc_mbox_get(struct lpfc_hba * phba)
  722. {
  723. LPFC_MBOXQ_t *mbq = NULL;
  724. struct lpfc_sli *psli = &phba->sli;
  725. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  726. if (mbq)
  727. psli->mboxq_cnt--;
  728. return mbq;
  729. }
  730. void
  731. lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  732. {
  733. /* This function expects to be called from interupt context */
  734. spin_lock(&phba->hbalock);
  735. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  736. spin_unlock(&phba->hbalock);
  737. return;
  738. }
  739. int
  740. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  741. {
  742. switch (cmd) {
  743. case MBX_WRITE_NV: /* 0x03 */
  744. case MBX_UPDATE_CFG: /* 0x1B */
  745. case MBX_DOWN_LOAD: /* 0x1C */
  746. case MBX_DEL_LD_ENTRY: /* 0x1D */
  747. case MBX_LOAD_AREA: /* 0x81 */
  748. case MBX_FLASH_WR_ULA: /* 0x98 */
  749. case MBX_LOAD_EXP_ROM: /* 0x9C */
  750. return LPFC_MBOX_TMO_FLASH_CMD;
  751. }
  752. return LPFC_MBOX_TMO;
  753. }