lpfc_mbox.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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, KERN_WARNING, LOG_MBOX,
  243. "0301 READ_SPARAM: no buffers\n");
  244. return (1);
  245. }
  246. INIT_LIST_HEAD(&mp->list);
  247. mb->mbxCommand = MBX_READ_SPARM64;
  248. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  249. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  250. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  251. mb->un.varRdSparm.vpi = vpi;
  252. /* save address for completion */
  253. pmb->context1 = mp;
  254. return (0);
  255. }
  256. /********************************************/
  257. /* lpfc_unreg_did Issue a UNREG_DID */
  258. /* mailbox command */
  259. /********************************************/
  260. void
  261. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  262. LPFC_MBOXQ_t * pmb)
  263. {
  264. MAILBOX_t *mb;
  265. mb = &pmb->mb;
  266. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  267. mb->un.varUnregDID.did = did;
  268. mb->un.varUnregDID.vpi = vpi;
  269. mb->mbxCommand = MBX_UNREG_D_ID;
  270. mb->mbxOwner = OWN_HOST;
  271. return;
  272. }
  273. /**********************************************/
  274. /* lpfc_read_nv Issue a READ CONFIG */
  275. /* mailbox command */
  276. /**********************************************/
  277. void
  278. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  279. {
  280. MAILBOX_t *mb;
  281. mb = &pmb->mb;
  282. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  283. mb->mbxCommand = MBX_READ_CONFIG;
  284. mb->mbxOwner = OWN_HOST;
  285. return;
  286. }
  287. /*************************************************/
  288. /* lpfc_read_lnk_stat Issue a READ LINK STATUS */
  289. /* mailbox command */
  290. /*************************************************/
  291. void
  292. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  293. {
  294. MAILBOX_t *mb;
  295. mb = &pmb->mb;
  296. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  297. mb->mbxCommand = MBX_READ_LNK_STAT;
  298. mb->mbxOwner = OWN_HOST;
  299. return;
  300. }
  301. /********************************************/
  302. /* lpfc_reg_login Issue a REG_LOGIN */
  303. /* mailbox command */
  304. /********************************************/
  305. int
  306. lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  307. uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
  308. {
  309. MAILBOX_t *mb = &pmb->mb;
  310. uint8_t *sparam;
  311. struct lpfc_dmabuf *mp;
  312. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  313. mb->un.varRegLogin.rpi = 0;
  314. mb->un.varRegLogin.vpi = vpi;
  315. mb->un.varRegLogin.did = did;
  316. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  317. mb->mbxOwner = OWN_HOST;
  318. /* Get a buffer to hold NPorts Service Parameters */
  319. if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
  320. ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
  321. kfree(mp);
  322. mb->mbxCommand = MBX_REG_LOGIN64;
  323. /* REG_LOGIN: no buffers */
  324. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  325. "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
  326. "flag x%x\n", vpi, did, flag);
  327. return (1);
  328. }
  329. INIT_LIST_HEAD(&mp->list);
  330. sparam = mp->virt;
  331. /* Copy param's into a new buffer */
  332. memcpy(sparam, param, sizeof (struct serv_parm));
  333. /* save address for completion */
  334. pmb->context1 = (uint8_t *) mp;
  335. mb->mbxCommand = MBX_REG_LOGIN64;
  336. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  337. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  338. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  339. return (0);
  340. }
  341. /**********************************************/
  342. /* lpfc_unreg_login Issue a UNREG_LOGIN */
  343. /* mailbox command */
  344. /**********************************************/
  345. void
  346. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  347. LPFC_MBOXQ_t * pmb)
  348. {
  349. MAILBOX_t *mb;
  350. mb = &pmb->mb;
  351. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  352. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  353. mb->un.varUnregLogin.rsvd1 = 0;
  354. mb->un.varUnregLogin.vpi = vpi;
  355. mb->mbxCommand = MBX_UNREG_LOGIN;
  356. mb->mbxOwner = OWN_HOST;
  357. return;
  358. }
  359. /**************************************************/
  360. /* lpfc_reg_vpi Issue a REG_VPI */
  361. /* mailbox command */
  362. /**************************************************/
  363. void
  364. lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
  365. LPFC_MBOXQ_t *pmb)
  366. {
  367. MAILBOX_t *mb = &pmb->mb;
  368. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  369. mb->un.varRegVpi.vpi = vpi;
  370. mb->un.varRegVpi.sid = sid;
  371. mb->mbxCommand = MBX_REG_VPI;
  372. mb->mbxOwner = OWN_HOST;
  373. return;
  374. }
  375. /**************************************************/
  376. /* lpfc_unreg_vpi Issue a UNREG_VNPI */
  377. /* mailbox command */
  378. /**************************************************/
  379. void
  380. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  381. {
  382. MAILBOX_t *mb = &pmb->mb;
  383. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  384. mb->un.varUnregVpi.vpi = vpi;
  385. mb->mbxCommand = MBX_UNREG_VPI;
  386. mb->mbxOwner = OWN_HOST;
  387. return;
  388. }
  389. static void
  390. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  391. {
  392. struct lpfc_sli *psli = &phba->sli;
  393. struct lpfc_sli_ring *pring;
  394. PCB_t *pcbp = &phba->slim2p->pcb;
  395. dma_addr_t pdma_addr;
  396. uint32_t offset;
  397. uint32_t iocbCnt = 0;
  398. int i;
  399. pcbp->maxRing = (psli->num_rings - 1);
  400. for (i = 0; i < psli->num_rings; i++) {
  401. pring = &psli->ring[i];
  402. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  403. SLI2_IOCB_CMD_SIZE;
  404. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  405. SLI2_IOCB_RSP_SIZE;
  406. /* A ring MUST have both cmd and rsp entries defined to be
  407. valid */
  408. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  409. pcbp->rdsc[i].cmdEntries = 0;
  410. pcbp->rdsc[i].rspEntries = 0;
  411. pcbp->rdsc[i].cmdAddrHigh = 0;
  412. pcbp->rdsc[i].rspAddrHigh = 0;
  413. pcbp->rdsc[i].cmdAddrLow = 0;
  414. pcbp->rdsc[i].rspAddrLow = 0;
  415. pring->cmdringaddr = NULL;
  416. pring->rspringaddr = NULL;
  417. continue;
  418. }
  419. /* Command ring setup for ring */
  420. pring->cmdringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
  421. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  422. offset = (uint8_t *) &phba->slim2p->IOCBs[iocbCnt] -
  423. (uint8_t *) phba->slim2p;
  424. pdma_addr = phba->slim2p_mapping + offset;
  425. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  426. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  427. iocbCnt += pring->numCiocb;
  428. /* Response ring setup for ring */
  429. pring->rspringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
  430. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  431. offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
  432. (uint8_t *)phba->slim2p;
  433. pdma_addr = phba->slim2p_mapping + offset;
  434. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  435. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  436. iocbCnt += pring->numRiocb;
  437. }
  438. }
  439. void
  440. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  441. {
  442. MAILBOX_t *mb = &pmb->mb;
  443. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  444. mb->un.varRdRev.cv = 1;
  445. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  446. mb->mbxCommand = MBX_READ_REV;
  447. mb->mbxOwner = OWN_HOST;
  448. return;
  449. }
  450. static void
  451. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  452. struct lpfc_hbq_init *hbq_desc)
  453. {
  454. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  455. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  456. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  457. }
  458. static void
  459. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  460. struct lpfc_hbq_init *hbq_desc)
  461. {
  462. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  463. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  464. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  465. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  466. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  467. sizeof(hbqmb->profiles.profile3.cmdmatch));
  468. }
  469. static void
  470. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  471. struct lpfc_hbq_init *hbq_desc)
  472. {
  473. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  474. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  475. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  476. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  477. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  478. sizeof(hbqmb->profiles.profile5.cmdmatch));
  479. }
  480. void
  481. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  482. struct lpfc_hbq_init *hbq_desc,
  483. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  484. {
  485. int i;
  486. MAILBOX_t *mb = &pmb->mb;
  487. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  488. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  489. hbqmb->hbqId = id;
  490. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  491. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  492. * Notification */
  493. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  494. * # in words 0-19 */
  495. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  496. * 0 = all,
  497. * 7 = logentry */
  498. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  499. * e.g. Ring0=b0001,
  500. * ring2=b0100 */
  501. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  502. * or 5 */
  503. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  504. * HBQ will be used
  505. * for LogEntry
  506. * buffers */
  507. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  508. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  509. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  510. mb->mbxCommand = MBX_CONFIG_HBQ;
  511. mb->mbxOwner = OWN_HOST;
  512. /* Copy info for profiles 2,3,5. Other
  513. * profiles this area is reserved
  514. */
  515. if (hbq_desc->profile == 2)
  516. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  517. else if (hbq_desc->profile == 3)
  518. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  519. else if (hbq_desc->profile == 5)
  520. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  521. /* Return if no rctl / type masks for this HBQ */
  522. if (!hbq_desc->mask_count)
  523. return;
  524. /* Otherwise we setup specific rctl / type masks for this HBQ */
  525. for (i = 0; i < hbq_desc->mask_count; i++) {
  526. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  527. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  528. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  529. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  530. }
  531. return;
  532. }
  533. void
  534. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  535. {
  536. int i;
  537. MAILBOX_t *mb = &pmb->mb;
  538. struct lpfc_sli *psli;
  539. struct lpfc_sli_ring *pring;
  540. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  541. mb->un.varCfgRing.ring = ring;
  542. mb->un.varCfgRing.maxOrigXchg = 0;
  543. mb->un.varCfgRing.maxRespXchg = 0;
  544. mb->un.varCfgRing.recvNotify = 1;
  545. psli = &phba->sli;
  546. pring = &psli->ring[ring];
  547. mb->un.varCfgRing.numMask = pring->num_mask;
  548. mb->mbxCommand = MBX_CONFIG_RING;
  549. mb->mbxOwner = OWN_HOST;
  550. /* Is this ring configured for a specific profile */
  551. if (pring->prt[0].profile) {
  552. mb->un.varCfgRing.profile = pring->prt[0].profile;
  553. return;
  554. }
  555. /* Otherwise we setup specific rctl / type masks for this ring */
  556. for (i = 0; i < pring->num_mask; i++) {
  557. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  558. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  559. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  560. else
  561. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  562. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  563. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  564. }
  565. return;
  566. }
  567. void
  568. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  569. {
  570. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  571. MAILBOX_t *mb = &pmb->mb;
  572. dma_addr_t pdma_addr;
  573. uint32_t bar_low, bar_high;
  574. size_t offset;
  575. struct lpfc_hgp hgp;
  576. int i;
  577. uint32_t pgp_offset;
  578. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  579. mb->mbxCommand = MBX_CONFIG_PORT;
  580. mb->mbxOwner = OWN_HOST;
  581. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  582. offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
  583. pdma_addr = phba->slim2p_mapping + offset;
  584. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  585. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  586. /* If HBA supports SLI=3 ask for it */
  587. if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
  588. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  589. mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
  590. if (phba->max_vpi && phba->cfg_enable_npiv &&
  591. phba->vpd.sli3Feat.cmv) {
  592. mb->un.varCfgPort.max_vpi = phba->max_vpi;
  593. mb->un.varCfgPort.cmv = 1;
  594. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  595. } else
  596. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  597. } else
  598. phba->sli_rev = 2;
  599. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  600. /* Now setup pcb */
  601. phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
  602. phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
  603. /* Setup Mailbox pointers */
  604. phba->slim2p->pcb.mailBoxSize = offsetof(MAILBOX_t, us) +
  605. sizeof(struct sli2_desc);
  606. offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
  607. pdma_addr = phba->slim2p_mapping + offset;
  608. phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
  609. phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
  610. /*
  611. * Setup Host Group ring pointer.
  612. *
  613. * For efficiency reasons, the ring get/put pointers can be
  614. * placed in adapter memory (SLIM) rather than in host memory.
  615. * This allows firmware to avoid PCI reads/writes when updating
  616. * and checking pointers.
  617. *
  618. * The firmware recognizes the use of SLIM memory by comparing
  619. * the address of the get/put pointers structure with that of
  620. * the SLIM BAR (BAR0).
  621. *
  622. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  623. * (the hardware's view of the base address), not the OS's
  624. * value of pci_resource_start() as the OS value may be a cookie
  625. * for ioremap/iomap.
  626. */
  627. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  628. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  629. /*
  630. * Set up HGP - Port Memory
  631. *
  632. * The port expects the host get/put pointers to reside in memory
  633. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  634. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  635. * words (0x40 bytes). This area is not reserved if HBQs are
  636. * configured in SLI-3.
  637. *
  638. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  639. * RR0Get 0xc4 0x84
  640. * CR1Put 0xc8 0x88
  641. * RR1Get 0xcc 0x8c
  642. * CR2Put 0xd0 0x90
  643. * RR2Get 0xd4 0x94
  644. * CR3Put 0xd8 0x98
  645. * RR3Get 0xdc 0x9c
  646. *
  647. * Reserved 0xa0-0xbf
  648. * If HBQs configured:
  649. * HBQ 0 Put ptr 0xc0
  650. * HBQ 1 Put ptr 0xc4
  651. * HBQ 2 Put ptr 0xc8
  652. * ......
  653. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  654. *
  655. */
  656. if (phba->sli_rev == 3) {
  657. phba->host_gp = &mb_slim->us.s3.host[0];
  658. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  659. } else {
  660. phba->host_gp = &mb_slim->us.s2.host[0];
  661. phba->hbq_put = NULL;
  662. }
  663. /* mask off BAR0's flag bits 0 - 3 */
  664. phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  665. (void __iomem *) phba->host_gp -
  666. (void __iomem *)phba->MBslimaddr;
  667. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  668. phba->slim2p->pcb.hgpAddrHigh = bar_high;
  669. else
  670. phba->slim2p->pcb.hgpAddrHigh = 0;
  671. /* write HGP data to SLIM at the required longword offset */
  672. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  673. for (i=0; i < phba->sli.num_rings; i++) {
  674. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  675. sizeof(*phba->host_gp));
  676. }
  677. /* Setup Port Group ring pointer */
  678. if (phba->sli_rev == 3)
  679. pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s3_pgp.port -
  680. (uint8_t *)phba->slim2p;
  681. else
  682. pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
  683. (uint8_t *)phba->slim2p;
  684. pdma_addr = phba->slim2p_mapping + pgp_offset;
  685. phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
  686. phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
  687. phba->hbq_get = &phba->slim2p->mbx.us.s3_pgp.hbq_get[0];
  688. /* Use callback routine to setp rings in the pcb */
  689. lpfc_config_pcb_setup(phba);
  690. /* special handling for LC HBAs */
  691. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  692. uint32_t hbainit[5];
  693. lpfc_hba_init(phba, hbainit);
  694. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  695. }
  696. /* Swap PCB if needed */
  697. lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb,
  698. sizeof(PCB_t));
  699. }
  700. void
  701. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  702. {
  703. MAILBOX_t *mb = &pmb->mb;
  704. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  705. mb->mbxCommand = MBX_KILL_BOARD;
  706. mb->mbxOwner = OWN_HOST;
  707. return;
  708. }
  709. void
  710. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  711. {
  712. struct lpfc_sli *psli;
  713. psli = &phba->sli;
  714. list_add_tail(&mbq->list, &psli->mboxq);
  715. psli->mboxq_cnt++;
  716. return;
  717. }
  718. LPFC_MBOXQ_t *
  719. lpfc_mbox_get(struct lpfc_hba * phba)
  720. {
  721. LPFC_MBOXQ_t *mbq = NULL;
  722. struct lpfc_sli *psli = &phba->sli;
  723. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  724. if (mbq)
  725. psli->mboxq_cnt--;
  726. return mbq;
  727. }
  728. void
  729. lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  730. {
  731. /* This function expects to be called from interupt context */
  732. spin_lock(&phba->hbalock);
  733. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  734. spin_unlock(&phba->hbalock);
  735. return;
  736. }
  737. int
  738. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  739. {
  740. switch (cmd) {
  741. case MBX_WRITE_NV: /* 0x03 */
  742. case MBX_UPDATE_CFG: /* 0x1B */
  743. case MBX_DOWN_LOAD: /* 0x1C */
  744. case MBX_DEL_LD_ENTRY: /* 0x1D */
  745. case MBX_LOAD_AREA: /* 0x81 */
  746. case MBX_FLASH_WR_ULA: /* 0x98 */
  747. case MBX_LOAD_EXP_ROM: /* 0x9C */
  748. return LPFC_MBOX_TMO_FLASH_CMD;
  749. }
  750. return LPFC_MBOX_TMO;
  751. }