lpfc_mbox.c 44 KB

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