lpfc_mbox.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 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_nl.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. #include "lpfc_compat.h"
  36. /**
  37. * lpfc_dump_mem: Prepare a mailbox command for retrieving HBA's VPD memory.
  38. * @phba: pointer to lpfc hba data structure.
  39. * @pmb: pointer to the driver internal queue element for mailbox command.
  40. * @offset: offset for dumping VPD memory mailbox command.
  41. *
  42. * The dump mailbox command provides a method for the device driver to obtain
  43. * various types of information from the HBA device.
  44. *
  45. * This routine prepares the mailbox command for dumping HBA Vital Product
  46. * Data (VPD) memory. This mailbox command is to be used for retrieving a
  47. * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
  48. * offset specified by the offset parameter.
  49. **/
  50. void
  51. lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
  52. {
  53. MAILBOX_t *mb;
  54. void *ctx;
  55. mb = &pmb->mb;
  56. ctx = pmb->context2;
  57. /* Setup to dump VPD region */
  58. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  59. mb->mbxCommand = MBX_DUMP_MEMORY;
  60. mb->un.varDmp.cv = 1;
  61. mb->un.varDmp.type = DMP_NV_PARAMS;
  62. mb->un.varDmp.entry_index = offset;
  63. mb->un.varDmp.region_id = DMP_REGION_VPD;
  64. mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
  65. mb->un.varDmp.co = 0;
  66. mb->un.varDmp.resp_offset = 0;
  67. pmb->context2 = ctx;
  68. mb->mbxOwner = OWN_HOST;
  69. return;
  70. }
  71. /**
  72. * lpfc_dump_mem: Prepare a mailbox command for retrieving wakeup params.
  73. * @phba: pointer to lpfc hba data structure.
  74. * @pmb: pointer to the driver internal queue element for mailbox command.
  75. * This function create a dump memory mailbox command to dump wake up
  76. * parameters.
  77. */
  78. void
  79. lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  80. {
  81. MAILBOX_t *mb;
  82. void *ctx;
  83. mb = &pmb->mb;
  84. /* Save context so that we can restore after memset */
  85. ctx = pmb->context2;
  86. /* Setup to dump VPD region */
  87. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  88. mb->mbxCommand = MBX_DUMP_MEMORY;
  89. mb->mbxOwner = OWN_HOST;
  90. mb->un.varDmp.cv = 1;
  91. mb->un.varDmp.type = DMP_NV_PARAMS;
  92. mb->un.varDmp.entry_index = 0;
  93. mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
  94. mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
  95. mb->un.varDmp.co = 0;
  96. mb->un.varDmp.resp_offset = 0;
  97. pmb->context2 = ctx;
  98. return;
  99. }
  100. /**
  101. * lpfc_read_nv: Prepare a mailbox command for reading HBA's NVRAM param.
  102. * @phba: pointer to lpfc hba data structure.
  103. * @pmb: pointer to the driver internal queue element for mailbox command.
  104. *
  105. * The read NVRAM mailbox command returns the HBA's non-volatile parameters
  106. * that are used as defaults when the Fibre Channel link is brought on-line.
  107. *
  108. * This routine prepares the mailbox command for reading information stored
  109. * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
  110. **/
  111. void
  112. lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  113. {
  114. MAILBOX_t *mb;
  115. mb = &pmb->mb;
  116. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  117. mb->mbxCommand = MBX_READ_NV;
  118. mb->mbxOwner = OWN_HOST;
  119. return;
  120. }
  121. /**
  122. * lpfc_config_async: Prepare a mailbox command for enabling HBA async event.
  123. * @phba: pointer to lpfc hba data structure.
  124. * @pmb: pointer to the driver internal queue element for mailbox command.
  125. * @ring: ring number for the asynchronous event to be configured.
  126. *
  127. * The asynchronous event enable mailbox command is used to enable the
  128. * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
  129. * specifies the default ring to which events are posted.
  130. *
  131. * This routine prepares the mailbox command for enabling HBA asynchronous
  132. * event support on a IOCB ring.
  133. **/
  134. void
  135. lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
  136. uint32_t ring)
  137. {
  138. MAILBOX_t *mb;
  139. mb = &pmb->mb;
  140. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  141. mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
  142. mb->un.varCfgAsyncEvent.ring = ring;
  143. mb->mbxOwner = OWN_HOST;
  144. return;
  145. }
  146. /**
  147. * lpfc_heart_beat: Prepare a mailbox command for heart beat.
  148. * @phba: pointer to lpfc hba data structure.
  149. * @pmb: pointer to the driver internal queue element for mailbox command.
  150. *
  151. * The heart beat mailbox command is used to detect an unresponsive HBA, which
  152. * is defined as any device where no error attention is sent and both mailbox
  153. * and rings are not processed.
  154. *
  155. * This routine prepares the mailbox command for issuing a heart beat in the
  156. * form of mailbox command to the HBA. The timely completion of the heart
  157. * beat mailbox command indicates the health of the HBA.
  158. **/
  159. void
  160. lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  161. {
  162. MAILBOX_t *mb;
  163. mb = &pmb->mb;
  164. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  165. mb->mbxCommand = MBX_HEARTBEAT;
  166. mb->mbxOwner = OWN_HOST;
  167. return;
  168. }
  169. /**
  170. * lpfc_read_la: Prepare a mailbox command for reading HBA link attention.
  171. * @phba: pointer to lpfc hba data structure.
  172. * @pmb: pointer to the driver internal queue element for mailbox command.
  173. * @mp: DMA buffer memory for reading the link attention information into.
  174. *
  175. * The read link attention mailbox command is issued to read the Link Event
  176. * Attention information indicated by the HBA port when the Link Event bit
  177. * of the Host Attention (HSTATT) register is set to 1. A Link Event
  178. * Attention occurs based on an exception detected at the Fibre Channel link
  179. * interface.
  180. *
  181. * This routine prepares the mailbox command for reading HBA link attention
  182. * information. A DMA memory has been set aside and address passed to the
  183. * HBA through @mp for the HBA to DMA link attention information into the
  184. * memory as part of the execution of the mailbox command.
  185. *
  186. * Return codes
  187. * 0 - Success (currently always return 0)
  188. **/
  189. int
  190. lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
  191. {
  192. MAILBOX_t *mb;
  193. struct lpfc_sli *psli;
  194. psli = &phba->sli;
  195. mb = &pmb->mb;
  196. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  197. INIT_LIST_HEAD(&mp->list);
  198. mb->mbxCommand = MBX_READ_LA64;
  199. mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
  200. mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  201. mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
  202. /* Save address for later completion and set the owner to host so that
  203. * the FW knows this mailbox is available for processing.
  204. */
  205. pmb->context1 = (uint8_t *) mp;
  206. mb->mbxOwner = OWN_HOST;
  207. return (0);
  208. }
  209. /**
  210. * lpfc_clear_la: Prepare a mailbox command for clearing HBA link attention.
  211. * @phba: pointer to lpfc hba data structure.
  212. * @pmb: pointer to the driver internal queue element for mailbox command.
  213. *
  214. * The clear link attention mailbox command is issued to clear the link event
  215. * attention condition indicated by the Link Event bit of the Host Attention
  216. * (HSTATT) register. The link event attention condition is cleared only if
  217. * the event tag specified matches that of the current link event counter.
  218. * The current event tag is read using the read link attention event mailbox
  219. * command.
  220. *
  221. * This routine prepares the mailbox command for clearing HBA link attention
  222. * information.
  223. **/
  224. void
  225. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  226. {
  227. MAILBOX_t *mb;
  228. mb = &pmb->mb;
  229. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  230. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  231. mb->mbxCommand = MBX_CLEAR_LA;
  232. mb->mbxOwner = OWN_HOST;
  233. return;
  234. }
  235. /**
  236. * lpfc_config_link: Prepare a mailbox command for configuring link on a HBA.
  237. * @phba: pointer to lpfc hba data structure.
  238. * @pmb: pointer to the driver internal queue element for mailbox command.
  239. *
  240. * The configure link mailbox command is used before the initialize link
  241. * mailbox command to override default value and to configure link-oriented
  242. * parameters such as DID address and various timers. Typically, this
  243. * command would be used after an F_Port login to set the returned DID address
  244. * and the fabric timeout values. This command is not valid before a configure
  245. * port command has configured the HBA port.
  246. *
  247. * This routine prepares the mailbox command for configuring link on a HBA.
  248. **/
  249. void
  250. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  251. {
  252. struct lpfc_vport *vport = phba->pport;
  253. MAILBOX_t *mb = &pmb->mb;
  254. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  255. /* NEW_FEATURE
  256. * SLI-2, Coalescing Response Feature.
  257. */
  258. if (phba->cfg_cr_delay) {
  259. mb->un.varCfgLnk.cr = 1;
  260. mb->un.varCfgLnk.ci = 1;
  261. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  262. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  263. }
  264. mb->un.varCfgLnk.myId = vport->fc_myDID;
  265. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  266. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  267. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  268. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  269. mb->un.varCfgLnk.altov = phba->fc_altov;
  270. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  271. mb->un.varCfgLnk.citov = phba->fc_citov;
  272. if (phba->cfg_ack0)
  273. mb->un.varCfgLnk.ack0_enable = 1;
  274. mb->mbxCommand = MBX_CONFIG_LINK;
  275. mb->mbxOwner = OWN_HOST;
  276. return;
  277. }
  278. /**
  279. * lpfc_config_msi: Prepare a mailbox command for configuring msi-x.
  280. * @phba: pointer to lpfc hba data structure.
  281. * @pmb: pointer to the driver internal queue element for mailbox command.
  282. *
  283. * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
  284. * MSI-X multi-message interrupt vector association to interrupt attention
  285. * conditions.
  286. *
  287. * Return codes
  288. * 0 - Success
  289. * -EINVAL - Failure
  290. **/
  291. int
  292. lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  293. {
  294. MAILBOX_t *mb = &pmb->mb;
  295. uint32_t attentionConditions[2];
  296. /* Sanity check */
  297. if (phba->cfg_use_msi != 2) {
  298. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  299. "0475 Not configured for supporting MSI-X "
  300. "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
  301. return -EINVAL;
  302. }
  303. if (phba->sli_rev < 3) {
  304. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  305. "0476 HBA not supporting SLI-3 or later "
  306. "SLI Revision: 0x%x\n", phba->sli_rev);
  307. return -EINVAL;
  308. }
  309. /* Clear mailbox command fields */
  310. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  311. /*
  312. * SLI-3, Message Signaled Interrupt Fearure.
  313. */
  314. /* Multi-message attention configuration */
  315. attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
  316. HA_LATT | HA_MBATT);
  317. attentionConditions[1] = 0;
  318. mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
  319. mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
  320. /*
  321. * Set up message number to HA bit association
  322. */
  323. #ifdef __BIG_ENDIAN_BITFIELD
  324. /* RA0 (FCP Ring) */
  325. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
  326. /* RA1 (Other Protocol Extra Ring) */
  327. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
  328. #else /* __LITTLE_ENDIAN_BITFIELD */
  329. /* RA0 (FCP Ring) */
  330. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
  331. /* RA1 (Other Protocol Extra Ring) */
  332. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
  333. #endif
  334. /* Multi-message interrupt autoclear configuration*/
  335. mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
  336. mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
  337. /* For now, HBA autoclear does not work reliably, disable it */
  338. mb->un.varCfgMSI.autoClearHA[0] = 0;
  339. mb->un.varCfgMSI.autoClearHA[1] = 0;
  340. /* Set command and owner bit */
  341. mb->mbxCommand = MBX_CONFIG_MSI;
  342. mb->mbxOwner = OWN_HOST;
  343. return 0;
  344. }
  345. /**
  346. * lpfc_init_link: Prepare a mailbox command for initialize link on a HBA.
  347. * @phba: pointer to lpfc hba data structure.
  348. * @pmb: pointer to the driver internal queue element for mailbox command.
  349. * @topology: the link topology for the link to be initialized to.
  350. * @linkspeed: the link speed for the link to be initialized to.
  351. *
  352. * The initialize link mailbox command is used to initialize the Fibre
  353. * Channel link. This command must follow a configure port command that
  354. * establishes the mode of operation.
  355. *
  356. * This routine prepares the mailbox command for initializing link on a HBA
  357. * with the specified link topology and speed.
  358. **/
  359. void
  360. lpfc_init_link(struct lpfc_hba * phba,
  361. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  362. {
  363. lpfc_vpd_t *vpd;
  364. struct lpfc_sli *psli;
  365. MAILBOX_t *mb;
  366. mb = &pmb->mb;
  367. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  368. psli = &phba->sli;
  369. switch (topology) {
  370. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  371. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  372. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  373. break;
  374. case FLAGS_TOPOLOGY_MODE_PT_PT:
  375. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  376. break;
  377. case FLAGS_TOPOLOGY_MODE_LOOP:
  378. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  379. break;
  380. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  381. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  382. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  383. break;
  384. case FLAGS_LOCAL_LB:
  385. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  386. break;
  387. }
  388. /* Enable asynchronous ABTS responses from firmware */
  389. mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
  390. /* NEW_FEATURE
  391. * Setting up the link speed
  392. */
  393. vpd = &phba->vpd;
  394. if (vpd->rev.feaLevelHigh >= 0x02){
  395. switch(linkspeed){
  396. case LINK_SPEED_1G:
  397. case LINK_SPEED_2G:
  398. case LINK_SPEED_4G:
  399. case LINK_SPEED_8G:
  400. mb->un.varInitLnk.link_flags |=
  401. FLAGS_LINK_SPEED;
  402. mb->un.varInitLnk.link_speed = linkspeed;
  403. break;
  404. case LINK_SPEED_AUTO:
  405. default:
  406. mb->un.varInitLnk.link_speed =
  407. LINK_SPEED_AUTO;
  408. break;
  409. }
  410. }
  411. else
  412. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  413. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  414. mb->mbxOwner = OWN_HOST;
  415. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  416. return;
  417. }
  418. /**
  419. * lpfc_read_sparam: Prepare a mailbox command for reading HBA parameters.
  420. * @phba: pointer to lpfc hba data structure.
  421. * @pmb: pointer to the driver internal queue element for mailbox command.
  422. * @vpi: virtual N_Port identifier.
  423. *
  424. * The read service parameter mailbox command is used to read the HBA port
  425. * service parameters. The service parameters are read into the buffer
  426. * specified directly by a BDE in the mailbox command. These service
  427. * parameters may then be used to build the payload of an N_Port/F_POrt
  428. * login request and reply (LOGI/ACC).
  429. *
  430. * This routine prepares the mailbox command for reading HBA port service
  431. * parameters. The DMA memory is allocated in this function and the addresses
  432. * are populated into the mailbox command for the HBA to DMA the service
  433. * parameters into.
  434. *
  435. * Return codes
  436. * 0 - Success
  437. * 1 - DMA memory allocation failed
  438. **/
  439. int
  440. lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
  441. {
  442. struct lpfc_dmabuf *mp;
  443. MAILBOX_t *mb;
  444. struct lpfc_sli *psli;
  445. psli = &phba->sli;
  446. mb = &pmb->mb;
  447. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  448. mb->mbxOwner = OWN_HOST;
  449. /* Get a buffer to hold the HBAs Service Parameters */
  450. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  451. if (mp)
  452. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  453. if (!mp || !mp->virt) {
  454. kfree(mp);
  455. mb->mbxCommand = MBX_READ_SPARM64;
  456. /* READ_SPARAM: no buffers */
  457. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  458. "0301 READ_SPARAM: no buffers\n");
  459. return (1);
  460. }
  461. INIT_LIST_HEAD(&mp->list);
  462. mb->mbxCommand = MBX_READ_SPARM64;
  463. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  464. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  465. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  466. mb->un.varRdSparm.vpi = vpi;
  467. /* save address for completion */
  468. pmb->context1 = mp;
  469. return (0);
  470. }
  471. /**
  472. * lpfc_unreg_did: Prepare a mailbox command for unregistering DID.
  473. * @phba: pointer to lpfc hba data structure.
  474. * @vpi: virtual N_Port identifier.
  475. * @did: remote port identifier.
  476. * @pmb: pointer to the driver internal queue element for mailbox command.
  477. *
  478. * The unregister DID mailbox command is used to unregister an N_Port/F_Port
  479. * login for an unknown RPI by specifying the DID of a remote port. This
  480. * command frees an RPI context in the HBA port. This has the effect of
  481. * performing an implicit N_Port/F_Port logout.
  482. *
  483. * This routine prepares the mailbox command for unregistering a remote
  484. * N_Port/F_Port (DID) login.
  485. **/
  486. void
  487. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  488. LPFC_MBOXQ_t * pmb)
  489. {
  490. MAILBOX_t *mb;
  491. mb = &pmb->mb;
  492. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  493. mb->un.varUnregDID.did = did;
  494. mb->un.varUnregDID.vpi = vpi;
  495. mb->mbxCommand = MBX_UNREG_D_ID;
  496. mb->mbxOwner = OWN_HOST;
  497. return;
  498. }
  499. /**
  500. * lpfc_read_config: Prepare a mailbox command for reading HBA configuration.
  501. * @phba: pointer to lpfc hba data structure.
  502. * @pmb: pointer to the driver internal queue element for mailbox command.
  503. *
  504. * The read configuration mailbox command is used to read the HBA port
  505. * configuration parameters. This mailbox command provides a method for
  506. * seeing any parameters that may have changed via various configuration
  507. * mailbox commands.
  508. *
  509. * This routine prepares the mailbox command for reading out HBA configuration
  510. * parameters.
  511. **/
  512. void
  513. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  514. {
  515. MAILBOX_t *mb;
  516. mb = &pmb->mb;
  517. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  518. mb->mbxCommand = MBX_READ_CONFIG;
  519. mb->mbxOwner = OWN_HOST;
  520. return;
  521. }
  522. /**
  523. * lpfc_read_lnk_stat: Prepare a mailbox command for reading HBA link stats.
  524. * @phba: pointer to lpfc hba data structure.
  525. * @pmb: pointer to the driver internal queue element for mailbox command.
  526. *
  527. * The read link status mailbox command is used to read the link status from
  528. * the HBA. Link status includes all link-related error counters. These
  529. * counters are maintained by the HBA and originated in the link hardware
  530. * unit. Note that all of these counters wrap.
  531. *
  532. * This routine prepares the mailbox command for reading out HBA link status.
  533. **/
  534. void
  535. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  536. {
  537. MAILBOX_t *mb;
  538. mb = &pmb->mb;
  539. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  540. mb->mbxCommand = MBX_READ_LNK_STAT;
  541. mb->mbxOwner = OWN_HOST;
  542. return;
  543. }
  544. /**
  545. * lpfc_reg_login: Prepare a mailbox command for registering remote login.
  546. * @phba: pointer to lpfc hba data structure.
  547. * @vpi: virtual N_Port identifier.
  548. * @did: remote port identifier.
  549. * @param: pointer to memory holding the server parameters.
  550. * @pmb: pointer to the driver internal queue element for mailbox command.
  551. * @flag: action flag to be passed back for the complete function.
  552. *
  553. * The registration login mailbox command is used to register an N_Port or
  554. * F_Port login. This registration allows the HBA to cache the remote N_Port
  555. * service parameters internally and thereby make the appropriate FC-2
  556. * decisions. The remote port service parameters are handed off by the driver
  557. * to the HBA using a descriptor entry that directly identifies a buffer in
  558. * host memory. In exchange, the HBA returns an RPI identifier.
  559. *
  560. * This routine prepares the mailbox command for registering remote port login.
  561. * The function allocates DMA buffer for passing the service parameters to the
  562. * HBA with the mailbox command.
  563. *
  564. * Return codes
  565. * 0 - Success
  566. * 1 - DMA memory allocation failed
  567. **/
  568. int
  569. lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  570. uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
  571. {
  572. MAILBOX_t *mb = &pmb->mb;
  573. uint8_t *sparam;
  574. struct lpfc_dmabuf *mp;
  575. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  576. mb->un.varRegLogin.rpi = 0;
  577. mb->un.varRegLogin.vpi = vpi;
  578. mb->un.varRegLogin.did = did;
  579. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  580. mb->mbxOwner = OWN_HOST;
  581. /* Get a buffer to hold NPorts Service Parameters */
  582. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  583. if (mp)
  584. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  585. if (!mp || !mp->virt) {
  586. kfree(mp);
  587. mb->mbxCommand = MBX_REG_LOGIN64;
  588. /* REG_LOGIN: no buffers */
  589. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  590. "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
  591. "flag x%x\n", vpi, did, flag);
  592. return (1);
  593. }
  594. INIT_LIST_HEAD(&mp->list);
  595. sparam = mp->virt;
  596. /* Copy param's into a new buffer */
  597. memcpy(sparam, param, sizeof (struct serv_parm));
  598. /* save address for completion */
  599. pmb->context1 = (uint8_t *) mp;
  600. mb->mbxCommand = MBX_REG_LOGIN64;
  601. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  602. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  603. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  604. return (0);
  605. }
  606. /**
  607. * lpfc_unreg_login: Prepare a mailbox command for unregistering remote login.
  608. * @phba: pointer to lpfc hba data structure.
  609. * @vpi: virtual N_Port identifier.
  610. * @rpi: remote port identifier
  611. * @pmb: pointer to the driver internal queue element for mailbox command.
  612. *
  613. * The unregistration login mailbox command is used to unregister an N_Port
  614. * or F_Port login. This command frees an RPI context in the HBA. It has the
  615. * effect of performing an implicit N_Port/F_Port logout.
  616. *
  617. * This routine prepares the mailbox command for unregistering remote port
  618. * login.
  619. **/
  620. void
  621. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  622. LPFC_MBOXQ_t * pmb)
  623. {
  624. MAILBOX_t *mb;
  625. mb = &pmb->mb;
  626. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  627. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  628. mb->un.varUnregLogin.rsvd1 = 0;
  629. mb->un.varUnregLogin.vpi = vpi;
  630. mb->mbxCommand = MBX_UNREG_LOGIN;
  631. mb->mbxOwner = OWN_HOST;
  632. return;
  633. }
  634. /**
  635. * lpfc_reg_vpi: Prepare a mailbox command for registering vport identifier.
  636. * @phba: pointer to lpfc hba data structure.
  637. * @vpi: virtual N_Port identifier.
  638. * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
  639. * @pmb: pointer to the driver internal queue element for mailbox command.
  640. *
  641. * The registration vport identifier mailbox command is used to activate a
  642. * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
  643. * N_Port_ID against the information in the selected virtual N_Port context
  644. * block and marks it active to allow normal processing of IOCB commands and
  645. * received unsolicited exchanges.
  646. *
  647. * This routine prepares the mailbox command for registering a virtual N_Port.
  648. **/
  649. void
  650. lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
  651. LPFC_MBOXQ_t *pmb)
  652. {
  653. MAILBOX_t *mb = &pmb->mb;
  654. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  655. mb->un.varRegVpi.vpi = vpi;
  656. mb->un.varRegVpi.sid = sid;
  657. mb->mbxCommand = MBX_REG_VPI;
  658. mb->mbxOwner = OWN_HOST;
  659. return;
  660. }
  661. /**
  662. * lpfc_unreg_vpi: Prepare a mailbox command for unregistering vport id.
  663. * @phba: pointer to lpfc hba data structure.
  664. * @vpi: virtual N_Port identifier.
  665. * @pmb: pointer to the driver internal queue element for mailbox command.
  666. *
  667. * The unregistration vport identifier mailbox command is used to inactivate
  668. * a virtual N_Port. The driver must have logged out and unregistered all
  669. * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
  670. * unregisters any default RPIs associated with the specified vpi, aborting
  671. * any active exchanges. The HBA will post the mailbox response after making
  672. * the virtual N_Port inactive.
  673. *
  674. * This routine prepares the mailbox command for unregistering a virtual
  675. * N_Port.
  676. **/
  677. void
  678. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  679. {
  680. MAILBOX_t *mb = &pmb->mb;
  681. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  682. mb->un.varUnregVpi.vpi = vpi;
  683. mb->mbxCommand = MBX_UNREG_VPI;
  684. mb->mbxOwner = OWN_HOST;
  685. return;
  686. }
  687. /**
  688. * lpfc_config_pcb_setup: Set up IOCB rings in the Port Control Block (PCB)
  689. * @phba: pointer to lpfc hba data structure.
  690. *
  691. * This routine sets up and initializes the IOCB rings in the Port Control
  692. * Block (PCB).
  693. **/
  694. static void
  695. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  696. {
  697. struct lpfc_sli *psli = &phba->sli;
  698. struct lpfc_sli_ring *pring;
  699. PCB_t *pcbp = phba->pcb;
  700. dma_addr_t pdma_addr;
  701. uint32_t offset;
  702. uint32_t iocbCnt = 0;
  703. int i;
  704. pcbp->maxRing = (psli->num_rings - 1);
  705. for (i = 0; i < psli->num_rings; i++) {
  706. pring = &psli->ring[i];
  707. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  708. SLI2_IOCB_CMD_SIZE;
  709. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  710. SLI2_IOCB_RSP_SIZE;
  711. /* A ring MUST have both cmd and rsp entries defined to be
  712. valid */
  713. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  714. pcbp->rdsc[i].cmdEntries = 0;
  715. pcbp->rdsc[i].rspEntries = 0;
  716. pcbp->rdsc[i].cmdAddrHigh = 0;
  717. pcbp->rdsc[i].rspAddrHigh = 0;
  718. pcbp->rdsc[i].cmdAddrLow = 0;
  719. pcbp->rdsc[i].rspAddrLow = 0;
  720. pring->cmdringaddr = NULL;
  721. pring->rspringaddr = NULL;
  722. continue;
  723. }
  724. /* Command ring setup for ring */
  725. pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
  726. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  727. offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
  728. (uint8_t *) phba->slim2p.virt;
  729. pdma_addr = phba->slim2p.phys + offset;
  730. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  731. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  732. iocbCnt += pring->numCiocb;
  733. /* Response ring setup for ring */
  734. pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
  735. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  736. offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
  737. (uint8_t *)phba->slim2p.virt;
  738. pdma_addr = phba->slim2p.phys + offset;
  739. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  740. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  741. iocbCnt += pring->numRiocb;
  742. }
  743. }
  744. /**
  745. * lpfc_read_rev: Prepare a mailbox command for reading HBA revision.
  746. * @phba: pointer to lpfc hba data structure.
  747. * @pmb: pointer to the driver internal queue element for mailbox command.
  748. *
  749. * The read revision mailbox command is used to read the revision levels of
  750. * the HBA components. These components include hardware units, resident
  751. * firmware, and available firmware. HBAs that supports SLI-3 mode of
  752. * operation provide different response information depending on the version
  753. * requested by the driver.
  754. *
  755. * This routine prepares the mailbox command for reading HBA revision
  756. * information.
  757. **/
  758. void
  759. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  760. {
  761. MAILBOX_t *mb = &pmb->mb;
  762. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  763. mb->un.varRdRev.cv = 1;
  764. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  765. mb->mbxCommand = MBX_READ_REV;
  766. mb->mbxOwner = OWN_HOST;
  767. return;
  768. }
  769. /**
  770. * lpfc_build_hbq_profile2: Set up the HBQ Selection Profile 2.
  771. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  772. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  773. *
  774. * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
  775. * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
  776. * the Sequence Length Test using the fields in the Selection Profile 2
  777. * extension in words 20:31.
  778. **/
  779. static void
  780. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  781. struct lpfc_hbq_init *hbq_desc)
  782. {
  783. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  784. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  785. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  786. }
  787. /**
  788. * lpfc_build_hbq_profile3: Set up the HBQ Selection Profile 3.
  789. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  790. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  791. *
  792. * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
  793. * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
  794. * the Sequence Length Test and Byte Field Test using the fields in the
  795. * Selection Profile 3 extension in words 20:31.
  796. **/
  797. static void
  798. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  799. struct lpfc_hbq_init *hbq_desc)
  800. {
  801. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  802. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  803. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  804. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  805. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  806. sizeof(hbqmb->profiles.profile3.cmdmatch));
  807. }
  808. /**
  809. * lpfc_build_hbq_profile5: Set up the HBQ Selection Profile 5.
  810. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  811. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  812. *
  813. * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
  814. * HBA tests the initial frame of an incoming sequence using the frame's
  815. * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
  816. * and Byte Field Test using the fields in the Selection Profile 5 extension
  817. * words 20:31.
  818. **/
  819. static void
  820. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  821. struct lpfc_hbq_init *hbq_desc)
  822. {
  823. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  824. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  825. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  826. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  827. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  828. sizeof(hbqmb->profiles.profile5.cmdmatch));
  829. }
  830. /**
  831. * lpfc_config_hbq: Prepare a mailbox command for configuring an HBQ.
  832. * @phba: pointer to lpfc hba data structure.
  833. * @id: HBQ identifier.
  834. * @hbq_desc: pointer to the HBA descriptor data structure.
  835. * @hbq_entry_index: index of the HBQ entry data structures.
  836. * @pmb: pointer to the driver internal queue element for mailbox command.
  837. *
  838. * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
  839. * an HBQ. The configuration binds events that require buffers to a particular
  840. * ring and HBQ based on a selection profile.
  841. *
  842. * This routine prepares the mailbox command for configuring an HBQ.
  843. **/
  844. void
  845. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  846. struct lpfc_hbq_init *hbq_desc,
  847. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  848. {
  849. int i;
  850. MAILBOX_t *mb = &pmb->mb;
  851. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  852. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  853. hbqmb->hbqId = id;
  854. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  855. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  856. * Notification */
  857. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  858. * # in words 0-19 */
  859. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  860. * 0 = all,
  861. * 7 = logentry */
  862. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  863. * e.g. Ring0=b0001,
  864. * ring2=b0100 */
  865. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  866. * or 5 */
  867. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  868. * HBQ will be used
  869. * for LogEntry
  870. * buffers */
  871. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  872. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  873. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  874. mb->mbxCommand = MBX_CONFIG_HBQ;
  875. mb->mbxOwner = OWN_HOST;
  876. /* Copy info for profiles 2,3,5. Other
  877. * profiles this area is reserved
  878. */
  879. if (hbq_desc->profile == 2)
  880. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  881. else if (hbq_desc->profile == 3)
  882. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  883. else if (hbq_desc->profile == 5)
  884. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  885. /* Return if no rctl / type masks for this HBQ */
  886. if (!hbq_desc->mask_count)
  887. return;
  888. /* Otherwise we setup specific rctl / type masks for this HBQ */
  889. for (i = 0; i < hbq_desc->mask_count; i++) {
  890. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  891. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  892. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  893. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  894. }
  895. return;
  896. }
  897. /**
  898. * lpfc_config_ring: Prepare a mailbox command for configuring an IOCB ring.
  899. * @phba: pointer to lpfc hba data structure.
  900. * @ring:
  901. * @pmb: pointer to the driver internal queue element for mailbox command.
  902. *
  903. * The configure ring mailbox command is used to configure an IOCB ring. This
  904. * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
  905. * ring. This is used to map incoming sequences to a particular ring whose
  906. * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
  907. * attempt to configure a ring whose number is greater than the number
  908. * specified in the Port Control Block (PCB). It is an error to issue the
  909. * configure ring command more than once with the same ring number. The HBA
  910. * returns an error if the driver attempts this.
  911. *
  912. * This routine prepares the mailbox command for configuring IOCB ring.
  913. **/
  914. void
  915. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  916. {
  917. int i;
  918. MAILBOX_t *mb = &pmb->mb;
  919. struct lpfc_sli *psli;
  920. struct lpfc_sli_ring *pring;
  921. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  922. mb->un.varCfgRing.ring = ring;
  923. mb->un.varCfgRing.maxOrigXchg = 0;
  924. mb->un.varCfgRing.maxRespXchg = 0;
  925. mb->un.varCfgRing.recvNotify = 1;
  926. psli = &phba->sli;
  927. pring = &psli->ring[ring];
  928. mb->un.varCfgRing.numMask = pring->num_mask;
  929. mb->mbxCommand = MBX_CONFIG_RING;
  930. mb->mbxOwner = OWN_HOST;
  931. /* Is this ring configured for a specific profile */
  932. if (pring->prt[0].profile) {
  933. mb->un.varCfgRing.profile = pring->prt[0].profile;
  934. return;
  935. }
  936. /* Otherwise we setup specific rctl / type masks for this ring */
  937. for (i = 0; i < pring->num_mask; i++) {
  938. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  939. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  940. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  941. else
  942. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  943. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  944. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  945. }
  946. return;
  947. }
  948. /**
  949. * lpfc_config_port: Prepare a mailbox command for configuring port.
  950. * @phba: pointer to lpfc hba data structure.
  951. * @pmb: pointer to the driver internal queue element for mailbox command.
  952. *
  953. * The configure port mailbox command is used to identify the Port Control
  954. * Block (PCB) in the driver memory. After this command is issued, the
  955. * driver must not access the mailbox in the HBA without first resetting
  956. * the HBA. The HBA may copy the PCB information to internal storage for
  957. * subsequent use; the driver can not change the PCB information unless it
  958. * resets the HBA.
  959. *
  960. * This routine prepares the mailbox command for configuring port.
  961. **/
  962. void
  963. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  964. {
  965. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  966. MAILBOX_t *mb = &pmb->mb;
  967. dma_addr_t pdma_addr;
  968. uint32_t bar_low, bar_high;
  969. size_t offset;
  970. struct lpfc_hgp hgp;
  971. int i;
  972. uint32_t pgp_offset;
  973. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  974. mb->mbxCommand = MBX_CONFIG_PORT;
  975. mb->mbxOwner = OWN_HOST;
  976. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  977. offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
  978. pdma_addr = phba->slim2p.phys + offset;
  979. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  980. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  981. /* Always Host Group Pointer is in SLIM */
  982. mb->un.varCfgPort.hps = 1;
  983. /* If HBA supports SLI=3 ask for it */
  984. if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
  985. if (phba->cfg_enable_bg)
  986. mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
  987. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  988. mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
  989. mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
  990. mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
  991. if (phba->max_vpi && phba->cfg_enable_npiv &&
  992. phba->vpd.sli3Feat.cmv) {
  993. mb->un.varCfgPort.max_vpi = phba->max_vpi;
  994. mb->un.varCfgPort.cmv = 1;
  995. } else
  996. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  997. } else
  998. phba->sli_rev = 2;
  999. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  1000. /* Now setup pcb */
  1001. phba->pcb->type = TYPE_NATIVE_SLI2;
  1002. phba->pcb->feature = FEATURE_INITIAL_SLI2;
  1003. /* Setup Mailbox pointers */
  1004. phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
  1005. offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
  1006. pdma_addr = phba->slim2p.phys + offset;
  1007. phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
  1008. phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
  1009. /*
  1010. * Setup Host Group ring pointer.
  1011. *
  1012. * For efficiency reasons, the ring get/put pointers can be
  1013. * placed in adapter memory (SLIM) rather than in host memory.
  1014. * This allows firmware to avoid PCI reads/writes when updating
  1015. * and checking pointers.
  1016. *
  1017. * The firmware recognizes the use of SLIM memory by comparing
  1018. * the address of the get/put pointers structure with that of
  1019. * the SLIM BAR (BAR0).
  1020. *
  1021. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  1022. * (the hardware's view of the base address), not the OS's
  1023. * value of pci_resource_start() as the OS value may be a cookie
  1024. * for ioremap/iomap.
  1025. */
  1026. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  1027. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  1028. /*
  1029. * Set up HGP - Port Memory
  1030. *
  1031. * The port expects the host get/put pointers to reside in memory
  1032. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  1033. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  1034. * words (0x40 bytes). This area is not reserved if HBQs are
  1035. * configured in SLI-3.
  1036. *
  1037. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  1038. * RR0Get 0xc4 0x84
  1039. * CR1Put 0xc8 0x88
  1040. * RR1Get 0xcc 0x8c
  1041. * CR2Put 0xd0 0x90
  1042. * RR2Get 0xd4 0x94
  1043. * CR3Put 0xd8 0x98
  1044. * RR3Get 0xdc 0x9c
  1045. *
  1046. * Reserved 0xa0-0xbf
  1047. * If HBQs configured:
  1048. * HBQ 0 Put ptr 0xc0
  1049. * HBQ 1 Put ptr 0xc4
  1050. * HBQ 2 Put ptr 0xc8
  1051. * ......
  1052. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  1053. *
  1054. */
  1055. if (phba->sli_rev == 3) {
  1056. phba->host_gp = &mb_slim->us.s3.host[0];
  1057. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  1058. } else {
  1059. phba->host_gp = &mb_slim->us.s2.host[0];
  1060. phba->hbq_put = NULL;
  1061. }
  1062. /* mask off BAR0's flag bits 0 - 3 */
  1063. phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  1064. (void __iomem *)phba->host_gp -
  1065. (void __iomem *)phba->MBslimaddr;
  1066. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  1067. phba->pcb->hgpAddrHigh = bar_high;
  1068. else
  1069. phba->pcb->hgpAddrHigh = 0;
  1070. /* write HGP data to SLIM at the required longword offset */
  1071. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  1072. for (i=0; i < phba->sli.num_rings; i++) {
  1073. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  1074. sizeof(*phba->host_gp));
  1075. }
  1076. /* Setup Port Group offset */
  1077. if (phba->sli_rev == 3)
  1078. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1079. mbx.us.s3_pgp.port);
  1080. else
  1081. pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
  1082. pdma_addr = phba->slim2p.phys + pgp_offset;
  1083. phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
  1084. phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
  1085. /* Use callback routine to setp rings in the pcb */
  1086. lpfc_config_pcb_setup(phba);
  1087. /* special handling for LC HBAs */
  1088. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  1089. uint32_t hbainit[5];
  1090. lpfc_hba_init(phba, hbainit);
  1091. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  1092. }
  1093. /* Swap PCB if needed */
  1094. lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
  1095. }
  1096. /**
  1097. * lpfc_kill_board: Prepare a mailbox command for killing board.
  1098. * @phba: pointer to lpfc hba data structure.
  1099. * @pmb: pointer to the driver internal queue element for mailbox command.
  1100. *
  1101. * The kill board mailbox command is used to tell firmware to perform a
  1102. * graceful shutdown of a channel on a specified board to prepare for reset.
  1103. * When the kill board mailbox command is received, the ER3 bit is set to 1
  1104. * in the Host Status register and the ER Attention bit is set to 1 in the
  1105. * Host Attention register of the HBA function that received the kill board
  1106. * command.
  1107. *
  1108. * This routine prepares the mailbox command for killing the board in
  1109. * preparation for a graceful shutdown.
  1110. **/
  1111. void
  1112. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1113. {
  1114. MAILBOX_t *mb = &pmb->mb;
  1115. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1116. mb->mbxCommand = MBX_KILL_BOARD;
  1117. mb->mbxOwner = OWN_HOST;
  1118. return;
  1119. }
  1120. /**
  1121. * lpfc_mbox_put: Put a mailbox cmd into the tail of driver's mailbox queue.
  1122. * @phba: pointer to lpfc hba data structure.
  1123. * @mbq: pointer to the driver internal queue element for mailbox command.
  1124. *
  1125. * Driver maintains a internal mailbox command queue implemented as a linked
  1126. * list. When a mailbox command is issued, it shall be put into the mailbox
  1127. * command queue such that they shall be processed orderly as HBA can process
  1128. * one mailbox command at a time.
  1129. **/
  1130. void
  1131. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1132. {
  1133. struct lpfc_sli *psli;
  1134. psli = &phba->sli;
  1135. list_add_tail(&mbq->list, &psli->mboxq);
  1136. psli->mboxq_cnt++;
  1137. return;
  1138. }
  1139. /**
  1140. * lpfc_mbox_get: Remove a mailbox cmd from the head of driver's mailbox queue.
  1141. * @phba: pointer to lpfc hba data structure.
  1142. *
  1143. * Driver maintains a internal mailbox command queue implemented as a linked
  1144. * list. When a mailbox command is issued, it shall be put into the mailbox
  1145. * command queue such that they shall be processed orderly as HBA can process
  1146. * one mailbox command at a time. After HBA finished processing a mailbox
  1147. * command, the driver will remove a pending mailbox command from the head of
  1148. * the mailbox command queue and send to the HBA for processing.
  1149. *
  1150. * Return codes
  1151. * pointer to the driver internal queue element for mailbox command.
  1152. **/
  1153. LPFC_MBOXQ_t *
  1154. lpfc_mbox_get(struct lpfc_hba * phba)
  1155. {
  1156. LPFC_MBOXQ_t *mbq = NULL;
  1157. struct lpfc_sli *psli = &phba->sli;
  1158. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  1159. if (mbq)
  1160. psli->mboxq_cnt--;
  1161. return mbq;
  1162. }
  1163. /**
  1164. * lpfc_mbox_cmpl_put: Put mailbox command into mailbox command complete list.
  1165. * @phba: pointer to lpfc hba data structure.
  1166. * @mbq: pointer to the driver internal queue element for mailbox command.
  1167. *
  1168. * This routine put the completed mailbox command into the mailbox command
  1169. * complete list. This routine is called from driver interrupt handler
  1170. * context.The mailbox complete list is used by the driver worker thread
  1171. * to process mailbox complete callback functions outside the driver interrupt
  1172. * handler.
  1173. **/
  1174. void
  1175. lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1176. {
  1177. unsigned long iflag;
  1178. /* This function expects to be called from interrupt context */
  1179. spin_lock_irqsave(&phba->hbalock, iflag);
  1180. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  1181. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1182. return;
  1183. }
  1184. /**
  1185. * lpfc_mbox_tmo_val: Retrieve mailbox command timeout value.
  1186. * @phba: pointer to lpfc hba data structure.
  1187. * @cmd: mailbox command code.
  1188. *
  1189. * This routine retrieves the proper timeout value according to the mailbox
  1190. * command code.
  1191. *
  1192. * Return codes
  1193. * Timeout value to be used for the given mailbox command
  1194. **/
  1195. int
  1196. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  1197. {
  1198. switch (cmd) {
  1199. case MBX_WRITE_NV: /* 0x03 */
  1200. case MBX_UPDATE_CFG: /* 0x1B */
  1201. case MBX_DOWN_LOAD: /* 0x1C */
  1202. case MBX_DEL_LD_ENTRY: /* 0x1D */
  1203. case MBX_LOAD_AREA: /* 0x81 */
  1204. case MBX_WRITE_WWN: /* 0x98 */
  1205. case MBX_LOAD_EXP_ROM: /* 0x9C */
  1206. return LPFC_MBOX_TMO_FLASH_CMD;
  1207. }
  1208. return LPFC_MBOX_TMO;
  1209. }