lpfc_mbox.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2009 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_hw4.h"
  28. #include "lpfc_hw.h"
  29. #include "lpfc_sli.h"
  30. #include "lpfc_sli4.h"
  31. #include "lpfc_nl.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_scsi.h"
  34. #include "lpfc.h"
  35. #include "lpfc_logmsg.h"
  36. #include "lpfc_crtn.h"
  37. #include "lpfc_compat.h"
  38. /**
  39. * lpfc_dump_static_vport - Dump HBA's static vport information.
  40. * @phba: pointer to lpfc hba data structure.
  41. * @pmb: pointer to the driver internal queue element for mailbox command.
  42. * @offset: offset for dumping vport info.
  43. *
  44. * The dump mailbox command provides a method for the device driver to obtain
  45. * various types of information from the HBA device.
  46. *
  47. * This routine prepares the mailbox command for dumping list of static
  48. * vports to be created.
  49. **/
  50. void
  51. lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
  52. uint16_t offset)
  53. {
  54. MAILBOX_t *mb;
  55. void *ctx;
  56. mb = &pmb->u.mb;
  57. ctx = pmb->context2;
  58. /* Setup to dump vport info region */
  59. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  60. mb->mbxCommand = MBX_DUMP_MEMORY;
  61. mb->un.varDmp.cv = 1;
  62. mb->un.varDmp.type = DMP_NV_PARAMS;
  63. mb->un.varDmp.entry_index = offset;
  64. mb->un.varDmp.region_id = DMP_REGION_VPORT;
  65. mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
  66. mb->un.varDmp.co = 0;
  67. mb->un.varDmp.resp_offset = 0;
  68. pmb->context2 = ctx;
  69. mb->mbxOwner = OWN_HOST;
  70. return;
  71. }
  72. /**
  73. * lpfc_dump_mem - Prepare a mailbox command for retrieving HBA's VPD memory
  74. * @phba: pointer to lpfc hba data structure.
  75. * @pmb: pointer to the driver internal queue element for mailbox command.
  76. * @offset: offset for dumping VPD memory mailbox command.
  77. *
  78. * The dump mailbox command provides a method for the device driver to obtain
  79. * various types of information from the HBA device.
  80. *
  81. * This routine prepares the mailbox command for dumping HBA Vital Product
  82. * Data (VPD) memory. This mailbox command is to be used for retrieving a
  83. * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
  84. * offset specified by the offset parameter.
  85. **/
  86. void
  87. lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
  88. {
  89. MAILBOX_t *mb;
  90. void *ctx;
  91. mb = &pmb->u.mb;
  92. ctx = pmb->context2;
  93. /* Setup to dump VPD region */
  94. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  95. mb->mbxCommand = MBX_DUMP_MEMORY;
  96. mb->un.varDmp.cv = 1;
  97. mb->un.varDmp.type = DMP_NV_PARAMS;
  98. mb->un.varDmp.entry_index = offset;
  99. mb->un.varDmp.region_id = DMP_REGION_VPD;
  100. mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
  101. mb->un.varDmp.co = 0;
  102. mb->un.varDmp.resp_offset = 0;
  103. pmb->context2 = ctx;
  104. mb->mbxOwner = OWN_HOST;
  105. return;
  106. }
  107. /**
  108. * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
  109. * @phba: pointer to lpfc hba data structure.
  110. * @pmb: pointer to the driver internal queue element for mailbox command.
  111. *
  112. * This function create a dump memory mailbox command to dump wake up
  113. * parameters.
  114. */
  115. void
  116. lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  117. {
  118. MAILBOX_t *mb;
  119. void *ctx;
  120. mb = &pmb->u.mb;
  121. /* Save context so that we can restore after memset */
  122. ctx = pmb->context2;
  123. /* Setup to dump VPD region */
  124. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  125. mb->mbxCommand = MBX_DUMP_MEMORY;
  126. mb->mbxOwner = OWN_HOST;
  127. mb->un.varDmp.cv = 1;
  128. mb->un.varDmp.type = DMP_NV_PARAMS;
  129. mb->un.varDmp.entry_index = 0;
  130. mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
  131. mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
  132. mb->un.varDmp.co = 0;
  133. mb->un.varDmp.resp_offset = 0;
  134. pmb->context2 = ctx;
  135. return;
  136. }
  137. /**
  138. * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
  139. * @phba: pointer to lpfc hba data structure.
  140. * @pmb: pointer to the driver internal queue element for mailbox command.
  141. *
  142. * The read NVRAM mailbox command returns the HBA's non-volatile parameters
  143. * that are used as defaults when the Fibre Channel link is brought on-line.
  144. *
  145. * This routine prepares the mailbox command for reading information stored
  146. * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
  147. **/
  148. void
  149. lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  150. {
  151. MAILBOX_t *mb;
  152. mb = &pmb->u.mb;
  153. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  154. mb->mbxCommand = MBX_READ_NV;
  155. mb->mbxOwner = OWN_HOST;
  156. return;
  157. }
  158. /**
  159. * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
  160. * @phba: pointer to lpfc hba data structure.
  161. * @pmb: pointer to the driver internal queue element for mailbox command.
  162. * @ring: ring number for the asynchronous event to be configured.
  163. *
  164. * The asynchronous event enable mailbox command is used to enable the
  165. * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
  166. * specifies the default ring to which events are posted.
  167. *
  168. * This routine prepares the mailbox command for enabling HBA asynchronous
  169. * event support on a IOCB ring.
  170. **/
  171. void
  172. lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
  173. uint32_t ring)
  174. {
  175. MAILBOX_t *mb;
  176. mb = &pmb->u.mb;
  177. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  178. mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
  179. mb->un.varCfgAsyncEvent.ring = ring;
  180. mb->mbxOwner = OWN_HOST;
  181. return;
  182. }
  183. /**
  184. * lpfc_heart_beat - Prepare a mailbox command for heart beat
  185. * @phba: pointer to lpfc hba data structure.
  186. * @pmb: pointer to the driver internal queue element for mailbox command.
  187. *
  188. * The heart beat mailbox command is used to detect an unresponsive HBA, which
  189. * is defined as any device where no error attention is sent and both mailbox
  190. * and rings are not processed.
  191. *
  192. * This routine prepares the mailbox command for issuing a heart beat in the
  193. * form of mailbox command to the HBA. The timely completion of the heart
  194. * beat mailbox command indicates the health of the HBA.
  195. **/
  196. void
  197. lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  198. {
  199. MAILBOX_t *mb;
  200. mb = &pmb->u.mb;
  201. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  202. mb->mbxCommand = MBX_HEARTBEAT;
  203. mb->mbxOwner = OWN_HOST;
  204. return;
  205. }
  206. /**
  207. * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
  208. * @phba: pointer to lpfc hba data structure.
  209. * @pmb: pointer to the driver internal queue element for mailbox command.
  210. * @mp: DMA buffer memory for reading the link attention information into.
  211. *
  212. * The read link attention mailbox command is issued to read the Link Event
  213. * Attention information indicated by the HBA port when the Link Event bit
  214. * of the Host Attention (HSTATT) register is set to 1. A Link Event
  215. * Attention occurs based on an exception detected at the Fibre Channel link
  216. * interface.
  217. *
  218. * This routine prepares the mailbox command for reading HBA link attention
  219. * information. A DMA memory has been set aside and address passed to the
  220. * HBA through @mp for the HBA to DMA link attention information into the
  221. * memory as part of the execution of the mailbox command.
  222. *
  223. * Return codes
  224. * 0 - Success (currently always return 0)
  225. **/
  226. int
  227. lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
  228. {
  229. MAILBOX_t *mb;
  230. struct lpfc_sli *psli;
  231. psli = &phba->sli;
  232. mb = &pmb->u.mb;
  233. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  234. INIT_LIST_HEAD(&mp->list);
  235. mb->mbxCommand = MBX_READ_LA64;
  236. mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
  237. mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  238. mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
  239. /* Save address for later completion and set the owner to host so that
  240. * the FW knows this mailbox is available for processing.
  241. */
  242. pmb->context1 = (uint8_t *) mp;
  243. mb->mbxOwner = OWN_HOST;
  244. return (0);
  245. }
  246. /**
  247. * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
  248. * @phba: pointer to lpfc hba data structure.
  249. * @pmb: pointer to the driver internal queue element for mailbox command.
  250. *
  251. * The clear link attention mailbox command is issued to clear the link event
  252. * attention condition indicated by the Link Event bit of the Host Attention
  253. * (HSTATT) register. The link event attention condition is cleared only if
  254. * the event tag specified matches that of the current link event counter.
  255. * The current event tag is read using the read link attention event mailbox
  256. * command.
  257. *
  258. * This routine prepares the mailbox command for clearing HBA link attention
  259. * information.
  260. **/
  261. void
  262. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  263. {
  264. MAILBOX_t *mb;
  265. mb = &pmb->u.mb;
  266. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  267. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  268. mb->mbxCommand = MBX_CLEAR_LA;
  269. mb->mbxOwner = OWN_HOST;
  270. return;
  271. }
  272. /**
  273. * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
  274. * @phba: pointer to lpfc hba data structure.
  275. * @pmb: pointer to the driver internal queue element for mailbox command.
  276. *
  277. * The configure link mailbox command is used before the initialize link
  278. * mailbox command to override default value and to configure link-oriented
  279. * parameters such as DID address and various timers. Typically, this
  280. * command would be used after an F_Port login to set the returned DID address
  281. * and the fabric timeout values. This command is not valid before a configure
  282. * port command has configured the HBA port.
  283. *
  284. * This routine prepares the mailbox command for configuring link on a HBA.
  285. **/
  286. void
  287. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  288. {
  289. struct lpfc_vport *vport = phba->pport;
  290. MAILBOX_t *mb = &pmb->u.mb;
  291. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  292. /* NEW_FEATURE
  293. * SLI-2, Coalescing Response Feature.
  294. */
  295. if (phba->cfg_cr_delay) {
  296. mb->un.varCfgLnk.cr = 1;
  297. mb->un.varCfgLnk.ci = 1;
  298. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  299. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  300. }
  301. mb->un.varCfgLnk.myId = vport->fc_myDID;
  302. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  303. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  304. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  305. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  306. mb->un.varCfgLnk.altov = phba->fc_altov;
  307. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  308. mb->un.varCfgLnk.citov = phba->fc_citov;
  309. if (phba->cfg_ack0)
  310. mb->un.varCfgLnk.ack0_enable = 1;
  311. mb->mbxCommand = MBX_CONFIG_LINK;
  312. mb->mbxOwner = OWN_HOST;
  313. return;
  314. }
  315. /**
  316. * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
  317. * @phba: pointer to lpfc hba data structure.
  318. * @pmb: pointer to the driver internal queue element for mailbox command.
  319. *
  320. * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
  321. * MSI-X multi-message interrupt vector association to interrupt attention
  322. * conditions.
  323. *
  324. * Return codes
  325. * 0 - Success
  326. * -EINVAL - Failure
  327. **/
  328. int
  329. lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  330. {
  331. MAILBOX_t *mb = &pmb->u.mb;
  332. uint32_t attentionConditions[2];
  333. /* Sanity check */
  334. if (phba->cfg_use_msi != 2) {
  335. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  336. "0475 Not configured for supporting MSI-X "
  337. "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
  338. return -EINVAL;
  339. }
  340. if (phba->sli_rev < 3) {
  341. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  342. "0476 HBA not supporting SLI-3 or later "
  343. "SLI Revision: 0x%x\n", phba->sli_rev);
  344. return -EINVAL;
  345. }
  346. /* Clear mailbox command fields */
  347. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  348. /*
  349. * SLI-3, Message Signaled Interrupt Fearure.
  350. */
  351. /* Multi-message attention configuration */
  352. attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
  353. HA_LATT | HA_MBATT);
  354. attentionConditions[1] = 0;
  355. mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
  356. mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
  357. /*
  358. * Set up message number to HA bit association
  359. */
  360. #ifdef __BIG_ENDIAN_BITFIELD
  361. /* RA0 (FCP Ring) */
  362. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
  363. /* RA1 (Other Protocol Extra Ring) */
  364. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
  365. #else /* __LITTLE_ENDIAN_BITFIELD */
  366. /* RA0 (FCP Ring) */
  367. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
  368. /* RA1 (Other Protocol Extra Ring) */
  369. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
  370. #endif
  371. /* Multi-message interrupt autoclear configuration*/
  372. mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
  373. mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
  374. /* For now, HBA autoclear does not work reliably, disable it */
  375. mb->un.varCfgMSI.autoClearHA[0] = 0;
  376. mb->un.varCfgMSI.autoClearHA[1] = 0;
  377. /* Set command and owner bit */
  378. mb->mbxCommand = MBX_CONFIG_MSI;
  379. mb->mbxOwner = OWN_HOST;
  380. return 0;
  381. }
  382. /**
  383. * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
  384. * @phba: pointer to lpfc hba data structure.
  385. * @pmb: pointer to the driver internal queue element for mailbox command.
  386. * @topology: the link topology for the link to be initialized to.
  387. * @linkspeed: the link speed for the link to be initialized to.
  388. *
  389. * The initialize link mailbox command is used to initialize the Fibre
  390. * Channel link. This command must follow a configure port command that
  391. * establishes the mode of operation.
  392. *
  393. * This routine prepares the mailbox command for initializing link on a HBA
  394. * with the specified link topology and speed.
  395. **/
  396. void
  397. lpfc_init_link(struct lpfc_hba * phba,
  398. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  399. {
  400. lpfc_vpd_t *vpd;
  401. struct lpfc_sli *psli;
  402. MAILBOX_t *mb;
  403. mb = &pmb->u.mb;
  404. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  405. psli = &phba->sli;
  406. switch (topology) {
  407. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  408. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  409. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  410. break;
  411. case FLAGS_TOPOLOGY_MODE_PT_PT:
  412. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  413. break;
  414. case FLAGS_TOPOLOGY_MODE_LOOP:
  415. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  416. break;
  417. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  418. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  419. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  420. break;
  421. case FLAGS_LOCAL_LB:
  422. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  423. break;
  424. }
  425. /* Enable asynchronous ABTS responses from firmware */
  426. mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
  427. /* NEW_FEATURE
  428. * Setting up the link speed
  429. */
  430. vpd = &phba->vpd;
  431. if (vpd->rev.feaLevelHigh >= 0x02){
  432. switch(linkspeed){
  433. case LINK_SPEED_1G:
  434. case LINK_SPEED_2G:
  435. case LINK_SPEED_4G:
  436. case LINK_SPEED_8G:
  437. mb->un.varInitLnk.link_flags |=
  438. FLAGS_LINK_SPEED;
  439. mb->un.varInitLnk.link_speed = linkspeed;
  440. break;
  441. case LINK_SPEED_AUTO:
  442. default:
  443. mb->un.varInitLnk.link_speed =
  444. LINK_SPEED_AUTO;
  445. break;
  446. }
  447. }
  448. else
  449. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  450. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  451. mb->mbxOwner = OWN_HOST;
  452. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  453. return;
  454. }
  455. /**
  456. * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
  457. * @phba: pointer to lpfc hba data structure.
  458. * @pmb: pointer to the driver internal queue element for mailbox command.
  459. * @vpi: virtual N_Port identifier.
  460. *
  461. * The read service parameter mailbox command is used to read the HBA port
  462. * service parameters. The service parameters are read into the buffer
  463. * specified directly by a BDE in the mailbox command. These service
  464. * parameters may then be used to build the payload of an N_Port/F_POrt
  465. * login request and reply (LOGI/ACC).
  466. *
  467. * This routine prepares the mailbox command for reading HBA port service
  468. * parameters. The DMA memory is allocated in this function and the addresses
  469. * are populated into the mailbox command for the HBA to DMA the service
  470. * parameters into.
  471. *
  472. * Return codes
  473. * 0 - Success
  474. * 1 - DMA memory allocation failed
  475. **/
  476. int
  477. lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
  478. {
  479. struct lpfc_dmabuf *mp;
  480. MAILBOX_t *mb;
  481. struct lpfc_sli *psli;
  482. psli = &phba->sli;
  483. mb = &pmb->u.mb;
  484. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  485. mb->mbxOwner = OWN_HOST;
  486. /* Get a buffer to hold the HBAs Service Parameters */
  487. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  488. if (mp)
  489. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  490. if (!mp || !mp->virt) {
  491. kfree(mp);
  492. mb->mbxCommand = MBX_READ_SPARM64;
  493. /* READ_SPARAM: no buffers */
  494. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  495. "0301 READ_SPARAM: no buffers\n");
  496. return (1);
  497. }
  498. INIT_LIST_HEAD(&mp->list);
  499. mb->mbxCommand = MBX_READ_SPARM64;
  500. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  501. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  502. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  503. mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
  504. /* save address for completion */
  505. pmb->context1 = mp;
  506. return (0);
  507. }
  508. /**
  509. * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
  510. * @phba: pointer to lpfc hba data structure.
  511. * @vpi: virtual N_Port identifier.
  512. * @did: remote port identifier.
  513. * @pmb: pointer to the driver internal queue element for mailbox command.
  514. *
  515. * The unregister DID mailbox command is used to unregister an N_Port/F_Port
  516. * login for an unknown RPI by specifying the DID of a remote port. This
  517. * command frees an RPI context in the HBA port. This has the effect of
  518. * performing an implicit N_Port/F_Port logout.
  519. *
  520. * This routine prepares the mailbox command for unregistering a remote
  521. * N_Port/F_Port (DID) login.
  522. **/
  523. void
  524. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  525. LPFC_MBOXQ_t * pmb)
  526. {
  527. MAILBOX_t *mb;
  528. mb = &pmb->u.mb;
  529. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  530. mb->un.varUnregDID.did = did;
  531. if (vpi != 0xffff)
  532. vpi += phba->vpi_base;
  533. mb->un.varUnregDID.vpi = vpi;
  534. mb->mbxCommand = MBX_UNREG_D_ID;
  535. mb->mbxOwner = OWN_HOST;
  536. return;
  537. }
  538. /**
  539. * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
  540. * @phba: pointer to lpfc hba data structure.
  541. * @pmb: pointer to the driver internal queue element for mailbox command.
  542. *
  543. * The read configuration mailbox command is used to read the HBA port
  544. * configuration parameters. This mailbox command provides a method for
  545. * seeing any parameters that may have changed via various configuration
  546. * mailbox commands.
  547. *
  548. * This routine prepares the mailbox command for reading out HBA configuration
  549. * parameters.
  550. **/
  551. void
  552. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  553. {
  554. MAILBOX_t *mb;
  555. mb = &pmb->u.mb;
  556. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  557. mb->mbxCommand = MBX_READ_CONFIG;
  558. mb->mbxOwner = OWN_HOST;
  559. return;
  560. }
  561. /**
  562. * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
  563. * @phba: pointer to lpfc hba data structure.
  564. * @pmb: pointer to the driver internal queue element for mailbox command.
  565. *
  566. * The read link status mailbox command is used to read the link status from
  567. * the HBA. Link status includes all link-related error counters. These
  568. * counters are maintained by the HBA and originated in the link hardware
  569. * unit. Note that all of these counters wrap.
  570. *
  571. * This routine prepares the mailbox command for reading out HBA link status.
  572. **/
  573. void
  574. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  575. {
  576. MAILBOX_t *mb;
  577. mb = &pmb->u.mb;
  578. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  579. mb->mbxCommand = MBX_READ_LNK_STAT;
  580. mb->mbxOwner = OWN_HOST;
  581. return;
  582. }
  583. /**
  584. * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
  585. * @phba: pointer to lpfc hba data structure.
  586. * @vpi: virtual N_Port identifier.
  587. * @did: remote port identifier.
  588. * @param: pointer to memory holding the server parameters.
  589. * @pmb: pointer to the driver internal queue element for mailbox command.
  590. * @flag: action flag to be passed back for the complete function.
  591. *
  592. * The registration login mailbox command is used to register an N_Port or
  593. * F_Port login. This registration allows the HBA to cache the remote N_Port
  594. * service parameters internally and thereby make the appropriate FC-2
  595. * decisions. The remote port service parameters are handed off by the driver
  596. * to the HBA using a descriptor entry that directly identifies a buffer in
  597. * host memory. In exchange, the HBA returns an RPI identifier.
  598. *
  599. * This routine prepares the mailbox command for registering remote port login.
  600. * The function allocates DMA buffer for passing the service parameters to the
  601. * HBA with the mailbox command.
  602. *
  603. * Return codes
  604. * 0 - Success
  605. * 1 - DMA memory allocation failed
  606. **/
  607. int
  608. lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  609. uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
  610. {
  611. MAILBOX_t *mb = &pmb->u.mb;
  612. uint8_t *sparam;
  613. struct lpfc_dmabuf *mp;
  614. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  615. mb->un.varRegLogin.rpi = 0;
  616. if (phba->sli_rev == LPFC_SLI_REV4) {
  617. mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
  618. if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
  619. return 1;
  620. }
  621. mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
  622. mb->un.varRegLogin.did = did;
  623. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  624. mb->mbxOwner = OWN_HOST;
  625. /* Get a buffer to hold NPorts Service Parameters */
  626. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  627. if (mp)
  628. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  629. if (!mp || !mp->virt) {
  630. kfree(mp);
  631. mb->mbxCommand = MBX_REG_LOGIN64;
  632. /* REG_LOGIN: no buffers */
  633. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  634. "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
  635. "flag x%x\n", vpi, did, flag);
  636. return (1);
  637. }
  638. INIT_LIST_HEAD(&mp->list);
  639. sparam = mp->virt;
  640. /* Copy param's into a new buffer */
  641. memcpy(sparam, param, sizeof (struct serv_parm));
  642. /* save address for completion */
  643. pmb->context1 = (uint8_t *) mp;
  644. mb->mbxCommand = MBX_REG_LOGIN64;
  645. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  646. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  647. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  648. return (0);
  649. }
  650. /**
  651. * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
  652. * @phba: pointer to lpfc hba data structure.
  653. * @vpi: virtual N_Port identifier.
  654. * @rpi: remote port identifier
  655. * @pmb: pointer to the driver internal queue element for mailbox command.
  656. *
  657. * The unregistration login mailbox command is used to unregister an N_Port
  658. * or F_Port login. This command frees an RPI context in the HBA. It has the
  659. * effect of performing an implicit N_Port/F_Port logout.
  660. *
  661. * This routine prepares the mailbox command for unregistering remote port
  662. * login.
  663. **/
  664. void
  665. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  666. LPFC_MBOXQ_t * pmb)
  667. {
  668. MAILBOX_t *mb;
  669. mb = &pmb->u.mb;
  670. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  671. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  672. mb->un.varUnregLogin.rsvd1 = 0;
  673. mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
  674. mb->mbxCommand = MBX_UNREG_LOGIN;
  675. mb->mbxOwner = OWN_HOST;
  676. return;
  677. }
  678. /**
  679. * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
  680. * @phba: pointer to lpfc hba data structure.
  681. * @vpi: virtual N_Port identifier.
  682. * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
  683. * @pmb: pointer to the driver internal queue element for mailbox command.
  684. *
  685. * The registration vport identifier mailbox command is used to activate a
  686. * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
  687. * N_Port_ID against the information in the selected virtual N_Port context
  688. * block and marks it active to allow normal processing of IOCB commands and
  689. * received unsolicited exchanges.
  690. *
  691. * This routine prepares the mailbox command for registering a virtual N_Port.
  692. **/
  693. void
  694. lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
  695. {
  696. MAILBOX_t *mb = &pmb->u.mb;
  697. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  698. mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
  699. mb->un.varRegVpi.sid = vport->fc_myDID;
  700. mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
  701. mb->mbxCommand = MBX_REG_VPI;
  702. mb->mbxOwner = OWN_HOST;
  703. return;
  704. }
  705. /**
  706. * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
  707. * @phba: pointer to lpfc hba data structure.
  708. * @vpi: virtual N_Port identifier.
  709. * @pmb: pointer to the driver internal queue element for mailbox command.
  710. *
  711. * The unregistration vport identifier mailbox command is used to inactivate
  712. * a virtual N_Port. The driver must have logged out and unregistered all
  713. * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
  714. * unregisters any default RPIs associated with the specified vpi, aborting
  715. * any active exchanges. The HBA will post the mailbox response after making
  716. * the virtual N_Port inactive.
  717. *
  718. * This routine prepares the mailbox command for unregistering a virtual
  719. * N_Port.
  720. **/
  721. void
  722. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  723. {
  724. MAILBOX_t *mb = &pmb->u.mb;
  725. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  726. mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
  727. mb->mbxCommand = MBX_UNREG_VPI;
  728. mb->mbxOwner = OWN_HOST;
  729. return;
  730. }
  731. /**
  732. * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
  733. * @phba: pointer to lpfc hba data structure.
  734. *
  735. * This routine sets up and initializes the IOCB rings in the Port Control
  736. * Block (PCB).
  737. **/
  738. static void
  739. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  740. {
  741. struct lpfc_sli *psli = &phba->sli;
  742. struct lpfc_sli_ring *pring;
  743. PCB_t *pcbp = phba->pcb;
  744. dma_addr_t pdma_addr;
  745. uint32_t offset;
  746. uint32_t iocbCnt = 0;
  747. int i;
  748. pcbp->maxRing = (psli->num_rings - 1);
  749. for (i = 0; i < psli->num_rings; i++) {
  750. pring = &psli->ring[i];
  751. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  752. SLI2_IOCB_CMD_SIZE;
  753. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  754. SLI2_IOCB_RSP_SIZE;
  755. /* A ring MUST have both cmd and rsp entries defined to be
  756. valid */
  757. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  758. pcbp->rdsc[i].cmdEntries = 0;
  759. pcbp->rdsc[i].rspEntries = 0;
  760. pcbp->rdsc[i].cmdAddrHigh = 0;
  761. pcbp->rdsc[i].rspAddrHigh = 0;
  762. pcbp->rdsc[i].cmdAddrLow = 0;
  763. pcbp->rdsc[i].rspAddrLow = 0;
  764. pring->cmdringaddr = NULL;
  765. pring->rspringaddr = NULL;
  766. continue;
  767. }
  768. /* Command ring setup for ring */
  769. pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
  770. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  771. offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
  772. (uint8_t *) phba->slim2p.virt;
  773. pdma_addr = phba->slim2p.phys + offset;
  774. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  775. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  776. iocbCnt += pring->numCiocb;
  777. /* Response ring setup for ring */
  778. pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
  779. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  780. offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
  781. (uint8_t *)phba->slim2p.virt;
  782. pdma_addr = phba->slim2p.phys + offset;
  783. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  784. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  785. iocbCnt += pring->numRiocb;
  786. }
  787. }
  788. /**
  789. * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
  790. * @phba: pointer to lpfc hba data structure.
  791. * @pmb: pointer to the driver internal queue element for mailbox command.
  792. *
  793. * The read revision mailbox command is used to read the revision levels of
  794. * the HBA components. These components include hardware units, resident
  795. * firmware, and available firmware. HBAs that supports SLI-3 mode of
  796. * operation provide different response information depending on the version
  797. * requested by the driver.
  798. *
  799. * This routine prepares the mailbox command for reading HBA revision
  800. * information.
  801. **/
  802. void
  803. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  804. {
  805. MAILBOX_t *mb = &pmb->u.mb;
  806. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  807. mb->un.varRdRev.cv = 1;
  808. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  809. mb->mbxCommand = MBX_READ_REV;
  810. mb->mbxOwner = OWN_HOST;
  811. return;
  812. }
  813. /**
  814. * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
  815. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  816. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  817. *
  818. * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
  819. * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
  820. * the Sequence Length Test using the fields in the Selection Profile 2
  821. * extension in words 20:31.
  822. **/
  823. static void
  824. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  825. struct lpfc_hbq_init *hbq_desc)
  826. {
  827. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  828. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  829. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  830. }
  831. /**
  832. * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
  833. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  834. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  835. *
  836. * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
  837. * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
  838. * the Sequence Length Test and Byte Field Test using the fields in the
  839. * Selection Profile 3 extension in words 20:31.
  840. **/
  841. static void
  842. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  843. struct lpfc_hbq_init *hbq_desc)
  844. {
  845. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  846. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  847. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  848. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  849. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  850. sizeof(hbqmb->profiles.profile3.cmdmatch));
  851. }
  852. /**
  853. * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
  854. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  855. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  856. *
  857. * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
  858. * HBA tests the initial frame of an incoming sequence using the frame's
  859. * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
  860. * and Byte Field Test using the fields in the Selection Profile 5 extension
  861. * words 20:31.
  862. **/
  863. static void
  864. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  865. struct lpfc_hbq_init *hbq_desc)
  866. {
  867. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  868. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  869. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  870. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  871. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  872. sizeof(hbqmb->profiles.profile5.cmdmatch));
  873. }
  874. /**
  875. * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
  876. * @phba: pointer to lpfc hba data structure.
  877. * @id: HBQ identifier.
  878. * @hbq_desc: pointer to the HBA descriptor data structure.
  879. * @hbq_entry_index: index of the HBQ entry data structures.
  880. * @pmb: pointer to the driver internal queue element for mailbox command.
  881. *
  882. * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
  883. * an HBQ. The configuration binds events that require buffers to a particular
  884. * ring and HBQ based on a selection profile.
  885. *
  886. * This routine prepares the mailbox command for configuring an HBQ.
  887. **/
  888. void
  889. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  890. struct lpfc_hbq_init *hbq_desc,
  891. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  892. {
  893. int i;
  894. MAILBOX_t *mb = &pmb->u.mb;
  895. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  896. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  897. hbqmb->hbqId = id;
  898. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  899. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  900. * Notification */
  901. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  902. * # in words 0-19 */
  903. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  904. * 0 = all,
  905. * 7 = logentry */
  906. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  907. * e.g. Ring0=b0001,
  908. * ring2=b0100 */
  909. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  910. * or 5 */
  911. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  912. * HBQ will be used
  913. * for LogEntry
  914. * buffers */
  915. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  916. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  917. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  918. mb->mbxCommand = MBX_CONFIG_HBQ;
  919. mb->mbxOwner = OWN_HOST;
  920. /* Copy info for profiles 2,3,5. Other
  921. * profiles this area is reserved
  922. */
  923. if (hbq_desc->profile == 2)
  924. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  925. else if (hbq_desc->profile == 3)
  926. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  927. else if (hbq_desc->profile == 5)
  928. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  929. /* Return if no rctl / type masks for this HBQ */
  930. if (!hbq_desc->mask_count)
  931. return;
  932. /* Otherwise we setup specific rctl / type masks for this HBQ */
  933. for (i = 0; i < hbq_desc->mask_count; i++) {
  934. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  935. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  936. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  937. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  938. }
  939. return;
  940. }
  941. /**
  942. * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
  943. * @phba: pointer to lpfc hba data structure.
  944. * @ring:
  945. * @pmb: pointer to the driver internal queue element for mailbox command.
  946. *
  947. * The configure ring mailbox command is used to configure an IOCB ring. This
  948. * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
  949. * ring. This is used to map incoming sequences to a particular ring whose
  950. * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
  951. * attempt to configure a ring whose number is greater than the number
  952. * specified in the Port Control Block (PCB). It is an error to issue the
  953. * configure ring command more than once with the same ring number. The HBA
  954. * returns an error if the driver attempts this.
  955. *
  956. * This routine prepares the mailbox command for configuring IOCB ring.
  957. **/
  958. void
  959. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  960. {
  961. int i;
  962. MAILBOX_t *mb = &pmb->u.mb;
  963. struct lpfc_sli *psli;
  964. struct lpfc_sli_ring *pring;
  965. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  966. mb->un.varCfgRing.ring = ring;
  967. mb->un.varCfgRing.maxOrigXchg = 0;
  968. mb->un.varCfgRing.maxRespXchg = 0;
  969. mb->un.varCfgRing.recvNotify = 1;
  970. psli = &phba->sli;
  971. pring = &psli->ring[ring];
  972. mb->un.varCfgRing.numMask = pring->num_mask;
  973. mb->mbxCommand = MBX_CONFIG_RING;
  974. mb->mbxOwner = OWN_HOST;
  975. /* Is this ring configured for a specific profile */
  976. if (pring->prt[0].profile) {
  977. mb->un.varCfgRing.profile = pring->prt[0].profile;
  978. return;
  979. }
  980. /* Otherwise we setup specific rctl / type masks for this ring */
  981. for (i = 0; i < pring->num_mask; i++) {
  982. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  983. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  984. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  985. else
  986. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  987. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  988. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  989. }
  990. return;
  991. }
  992. /**
  993. * lpfc_config_port - Prepare a mailbox command for configuring port
  994. * @phba: pointer to lpfc hba data structure.
  995. * @pmb: pointer to the driver internal queue element for mailbox command.
  996. *
  997. * The configure port mailbox command is used to identify the Port Control
  998. * Block (PCB) in the driver memory. After this command is issued, the
  999. * driver must not access the mailbox in the HBA without first resetting
  1000. * the HBA. The HBA may copy the PCB information to internal storage for
  1001. * subsequent use; the driver can not change the PCB information unless it
  1002. * resets the HBA.
  1003. *
  1004. * This routine prepares the mailbox command for configuring port.
  1005. **/
  1006. void
  1007. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1008. {
  1009. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  1010. MAILBOX_t *mb = &pmb->u.mb;
  1011. dma_addr_t pdma_addr;
  1012. uint32_t bar_low, bar_high;
  1013. size_t offset;
  1014. struct lpfc_hgp hgp;
  1015. int i;
  1016. uint32_t pgp_offset;
  1017. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1018. mb->mbxCommand = MBX_CONFIG_PORT;
  1019. mb->mbxOwner = OWN_HOST;
  1020. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  1021. offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
  1022. pdma_addr = phba->slim2p.phys + offset;
  1023. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  1024. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  1025. /* Always Host Group Pointer is in SLIM */
  1026. mb->un.varCfgPort.hps = 1;
  1027. /* If HBA supports SLI=3 ask for it */
  1028. if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
  1029. if (phba->cfg_enable_bg)
  1030. mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
  1031. mb->un.varCfgPort.cdss = 1; /* Configure Security */
  1032. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  1033. mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
  1034. mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
  1035. mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
  1036. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1037. phba->vpd.sli3Feat.cmv) {
  1038. mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
  1039. mb->un.varCfgPort.cmv = 1;
  1040. } else
  1041. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  1042. } else
  1043. phba->sli_rev = LPFC_SLI_REV2;
  1044. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  1045. /* Now setup pcb */
  1046. phba->pcb->type = TYPE_NATIVE_SLI2;
  1047. phba->pcb->feature = FEATURE_INITIAL_SLI2;
  1048. /* Setup Mailbox pointers */
  1049. phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
  1050. offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
  1051. pdma_addr = phba->slim2p.phys + offset;
  1052. phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
  1053. phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
  1054. /*
  1055. * Setup Host Group ring pointer.
  1056. *
  1057. * For efficiency reasons, the ring get/put pointers can be
  1058. * placed in adapter memory (SLIM) rather than in host memory.
  1059. * This allows firmware to avoid PCI reads/writes when updating
  1060. * and checking pointers.
  1061. *
  1062. * The firmware recognizes the use of SLIM memory by comparing
  1063. * the address of the get/put pointers structure with that of
  1064. * the SLIM BAR (BAR0).
  1065. *
  1066. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  1067. * (the hardware's view of the base address), not the OS's
  1068. * value of pci_resource_start() as the OS value may be a cookie
  1069. * for ioremap/iomap.
  1070. */
  1071. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  1072. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  1073. /*
  1074. * Set up HGP - Port Memory
  1075. *
  1076. * The port expects the host get/put pointers to reside in memory
  1077. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  1078. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  1079. * words (0x40 bytes). This area is not reserved if HBQs are
  1080. * configured in SLI-3.
  1081. *
  1082. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  1083. * RR0Get 0xc4 0x84
  1084. * CR1Put 0xc8 0x88
  1085. * RR1Get 0xcc 0x8c
  1086. * CR2Put 0xd0 0x90
  1087. * RR2Get 0xd4 0x94
  1088. * CR3Put 0xd8 0x98
  1089. * RR3Get 0xdc 0x9c
  1090. *
  1091. * Reserved 0xa0-0xbf
  1092. * If HBQs configured:
  1093. * HBQ 0 Put ptr 0xc0
  1094. * HBQ 1 Put ptr 0xc4
  1095. * HBQ 2 Put ptr 0xc8
  1096. * ......
  1097. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  1098. *
  1099. */
  1100. if (phba->sli_rev == 3) {
  1101. phba->host_gp = &mb_slim->us.s3.host[0];
  1102. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  1103. } else {
  1104. phba->host_gp = &mb_slim->us.s2.host[0];
  1105. phba->hbq_put = NULL;
  1106. }
  1107. /* mask off BAR0's flag bits 0 - 3 */
  1108. phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  1109. (void __iomem *)phba->host_gp -
  1110. (void __iomem *)phba->MBslimaddr;
  1111. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  1112. phba->pcb->hgpAddrHigh = bar_high;
  1113. else
  1114. phba->pcb->hgpAddrHigh = 0;
  1115. /* write HGP data to SLIM at the required longword offset */
  1116. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  1117. for (i=0; i < phba->sli.num_rings; i++) {
  1118. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  1119. sizeof(*phba->host_gp));
  1120. }
  1121. /* Setup Port Group offset */
  1122. if (phba->sli_rev == 3)
  1123. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1124. mbx.us.s3_pgp.port);
  1125. else
  1126. pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
  1127. pdma_addr = phba->slim2p.phys + pgp_offset;
  1128. phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
  1129. phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
  1130. /* Use callback routine to setp rings in the pcb */
  1131. lpfc_config_pcb_setup(phba);
  1132. /* special handling for LC HBAs */
  1133. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  1134. uint32_t hbainit[5];
  1135. lpfc_hba_init(phba, hbainit);
  1136. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  1137. }
  1138. /* Swap PCB if needed */
  1139. lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
  1140. }
  1141. /**
  1142. * lpfc_kill_board - Prepare a mailbox command for killing board
  1143. * @phba: pointer to lpfc hba data structure.
  1144. * @pmb: pointer to the driver internal queue element for mailbox command.
  1145. *
  1146. * The kill board mailbox command is used to tell firmware to perform a
  1147. * graceful shutdown of a channel on a specified board to prepare for reset.
  1148. * When the kill board mailbox command is received, the ER3 bit is set to 1
  1149. * in the Host Status register and the ER Attention bit is set to 1 in the
  1150. * Host Attention register of the HBA function that received the kill board
  1151. * command.
  1152. *
  1153. * This routine prepares the mailbox command for killing the board in
  1154. * preparation for a graceful shutdown.
  1155. **/
  1156. void
  1157. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1158. {
  1159. MAILBOX_t *mb = &pmb->u.mb;
  1160. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1161. mb->mbxCommand = MBX_KILL_BOARD;
  1162. mb->mbxOwner = OWN_HOST;
  1163. return;
  1164. }
  1165. /**
  1166. * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
  1167. * @phba: pointer to lpfc hba data structure.
  1168. * @mbq: pointer to the driver internal queue element for mailbox command.
  1169. *
  1170. * Driver maintains a internal mailbox command queue implemented as a linked
  1171. * list. When a mailbox command is issued, it shall be put into the mailbox
  1172. * command queue such that they shall be processed orderly as HBA can process
  1173. * one mailbox command at a time.
  1174. **/
  1175. void
  1176. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1177. {
  1178. struct lpfc_sli *psli;
  1179. psli = &phba->sli;
  1180. list_add_tail(&mbq->list, &psli->mboxq);
  1181. psli->mboxq_cnt++;
  1182. return;
  1183. }
  1184. /**
  1185. * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
  1186. * @phba: pointer to lpfc hba data structure.
  1187. *
  1188. * Driver maintains a internal mailbox command queue implemented as a linked
  1189. * list. When a mailbox command is issued, it shall be put into the mailbox
  1190. * command queue such that they shall be processed orderly as HBA can process
  1191. * one mailbox command at a time. After HBA finished processing a mailbox
  1192. * command, the driver will remove a pending mailbox command from the head of
  1193. * the mailbox command queue and send to the HBA for processing.
  1194. *
  1195. * Return codes
  1196. * pointer to the driver internal queue element for mailbox command.
  1197. **/
  1198. LPFC_MBOXQ_t *
  1199. lpfc_mbox_get(struct lpfc_hba * phba)
  1200. {
  1201. LPFC_MBOXQ_t *mbq = NULL;
  1202. struct lpfc_sli *psli = &phba->sli;
  1203. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  1204. if (mbq)
  1205. psli->mboxq_cnt--;
  1206. return mbq;
  1207. }
  1208. /**
  1209. * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
  1210. * @phba: pointer to lpfc hba data structure.
  1211. * @mbq: pointer to the driver internal queue element for mailbox command.
  1212. *
  1213. * This routine put the completed mailbox command into the mailbox command
  1214. * complete list. This is the unlocked version of the routine. The mailbox
  1215. * complete list is used by the driver worker thread to process mailbox
  1216. * complete callback functions outside the driver interrupt handler.
  1217. **/
  1218. void
  1219. __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1220. {
  1221. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  1222. }
  1223. /**
  1224. * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
  1225. * @phba: pointer to lpfc hba data structure.
  1226. * @mbq: pointer to the driver internal queue element for mailbox command.
  1227. *
  1228. * This routine put the completed mailbox command into the mailbox command
  1229. * complete list. This is the locked version of the routine. The mailbox
  1230. * complete list is used by the driver worker thread to process mailbox
  1231. * complete callback functions outside the driver interrupt handler.
  1232. **/
  1233. void
  1234. lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1235. {
  1236. unsigned long iflag;
  1237. /* This function expects to be called from interrupt context */
  1238. spin_lock_irqsave(&phba->hbalock, iflag);
  1239. __lpfc_mbox_cmpl_put(phba, mbq);
  1240. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1241. return;
  1242. }
  1243. /**
  1244. * lpfc_mbox_cmd_check - Check the validality of a mailbox command
  1245. * @phba: pointer to lpfc hba data structure.
  1246. * @mboxq: pointer to the driver internal queue element for mailbox command.
  1247. *
  1248. * This routine is to check whether a mailbox command is valid to be issued.
  1249. * This check will be performed by both the mailbox issue API when a client
  1250. * is to issue a mailbox command to the mailbox transport.
  1251. *
  1252. * Return 0 - pass the check, -ENODEV - fail the check
  1253. **/
  1254. int
  1255. lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1256. {
  1257. /* Mailbox command that have a completion handler must also have a
  1258. * vport specified.
  1259. */
  1260. if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  1261. mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  1262. if (!mboxq->vport) {
  1263. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1264. "1814 Mbox x%x failed, no vport\n",
  1265. mboxq->u.mb.mbxCommand);
  1266. dump_stack();
  1267. return -ENODEV;
  1268. }
  1269. }
  1270. return 0;
  1271. }
  1272. /**
  1273. * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
  1274. * @phba: pointer to lpfc hba data structure.
  1275. *
  1276. * This routine is to check whether the HBA device is ready for posting a
  1277. * mailbox command. It is used by the mailbox transport API at the time the
  1278. * to post a mailbox command to the device.
  1279. *
  1280. * Return 0 - pass the check, -ENODEV - fail the check
  1281. **/
  1282. int
  1283. lpfc_mbox_dev_check(struct lpfc_hba *phba)
  1284. {
  1285. /* If the PCI channel is in offline state, do not issue mbox */
  1286. if (unlikely(pci_channel_offline(phba->pcidev)))
  1287. return -ENODEV;
  1288. /* If the HBA is in error state, do not issue mbox */
  1289. if (phba->link_state == LPFC_HBA_ERROR)
  1290. return -ENODEV;
  1291. return 0;
  1292. }
  1293. /**
  1294. * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
  1295. * @phba: pointer to lpfc hba data structure.
  1296. * @cmd: mailbox command code.
  1297. *
  1298. * This routine retrieves the proper timeout value according to the mailbox
  1299. * command code.
  1300. *
  1301. * Return codes
  1302. * Timeout value to be used for the given mailbox command
  1303. **/
  1304. int
  1305. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  1306. {
  1307. switch (cmd) {
  1308. case MBX_WRITE_NV: /* 0x03 */
  1309. case MBX_UPDATE_CFG: /* 0x1B */
  1310. case MBX_DOWN_LOAD: /* 0x1C */
  1311. case MBX_DEL_LD_ENTRY: /* 0x1D */
  1312. case MBX_LOAD_AREA: /* 0x81 */
  1313. case MBX_WRITE_WWN: /* 0x98 */
  1314. case MBX_LOAD_EXP_ROM: /* 0x9C */
  1315. return LPFC_MBOX_TMO_FLASH_CMD;
  1316. case MBX_SLI4_CONFIG: /* 0x9b */
  1317. return LPFC_MBOX_SLI4_CONFIG_TMO;
  1318. }
  1319. return LPFC_MBOX_TMO;
  1320. }
  1321. /**
  1322. * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
  1323. * @mbox: pointer to lpfc mbox command.
  1324. * @sgentry: sge entry index.
  1325. * @phyaddr: physical address for the sge
  1326. * @length: Length of the sge.
  1327. *
  1328. * This routine sets up an entry in the non-embedded mailbox command at the sge
  1329. * index location.
  1330. **/
  1331. void
  1332. lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
  1333. dma_addr_t phyaddr, uint32_t length)
  1334. {
  1335. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1336. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1337. &mbox->u.mqe.un.nembed_cmd;
  1338. nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
  1339. nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
  1340. nembed_sge->sge[sgentry].length = length;
  1341. }
  1342. /**
  1343. * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
  1344. * @mbox: pointer to lpfc mbox command.
  1345. * @sgentry: sge entry index.
  1346. *
  1347. * This routine gets an entry from the non-embedded mailbox command at the sge
  1348. * index location.
  1349. **/
  1350. void
  1351. lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
  1352. struct lpfc_mbx_sge *sge)
  1353. {
  1354. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1355. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1356. &mbox->u.mqe.un.nembed_cmd;
  1357. sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
  1358. sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
  1359. sge->length = nembed_sge->sge[sgentry].length;
  1360. }
  1361. /**
  1362. * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
  1363. * @phba: pointer to lpfc hba data structure.
  1364. * @mbox: pointer to lpfc mbox command.
  1365. *
  1366. * This routine frees SLI4 specific mailbox command for sending IOCTL command.
  1367. **/
  1368. void
  1369. lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1370. {
  1371. struct lpfc_mbx_sli4_config *sli4_cfg;
  1372. struct lpfc_mbx_sge sge;
  1373. dma_addr_t phyaddr;
  1374. uint32_t sgecount, sgentry;
  1375. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1376. /* For embedded mbox command, just free the mbox command */
  1377. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1378. mempool_free(mbox, phba->mbox_mem_pool);
  1379. return;
  1380. }
  1381. /* For non-embedded mbox command, we need to free the pages first */
  1382. sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
  1383. /* There is nothing we can do if there is no sge address array */
  1384. if (unlikely(!mbox->sge_array)) {
  1385. mempool_free(mbox, phba->mbox_mem_pool);
  1386. return;
  1387. }
  1388. /* Each non-embedded DMA memory was allocated in the length of a page */
  1389. for (sgentry = 0; sgentry < sgecount; sgentry++) {
  1390. lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
  1391. phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
  1392. dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
  1393. mbox->sge_array->addr[sgentry], phyaddr);
  1394. }
  1395. /* Free the sge address array memory */
  1396. kfree(mbox->sge_array);
  1397. /* Finally, free the mailbox command itself */
  1398. mempool_free(mbox, phba->mbox_mem_pool);
  1399. }
  1400. /**
  1401. * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
  1402. * @phba: pointer to lpfc hba data structure.
  1403. * @mbox: pointer to lpfc mbox command.
  1404. * @subsystem: The sli4 config sub mailbox subsystem.
  1405. * @opcode: The sli4 config sub mailbox command opcode.
  1406. * @length: Length of the sli4 config mailbox command.
  1407. *
  1408. * This routine sets up the header fields of SLI4 specific mailbox command
  1409. * for sending IOCTL command.
  1410. *
  1411. * Return: the actual length of the mbox command allocated (mostly useful
  1412. * for none embedded mailbox command).
  1413. **/
  1414. int
  1415. lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
  1416. uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
  1417. {
  1418. struct lpfc_mbx_sli4_config *sli4_config;
  1419. union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
  1420. uint32_t alloc_len;
  1421. uint32_t resid_len;
  1422. uint32_t pagen, pcount;
  1423. void *viraddr;
  1424. dma_addr_t phyaddr;
  1425. /* Set up SLI4 mailbox command header fields */
  1426. memset(mbox, 0, sizeof(*mbox));
  1427. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
  1428. /* Set up SLI4 ioctl command header fields */
  1429. sli4_config = &mbox->u.mqe.un.sli4_config;
  1430. /* Setup for the embedded mbox command */
  1431. if (emb) {
  1432. /* Set up main header fields */
  1433. bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
  1434. sli4_config->header.cfg_mhdr.payload_length =
  1435. LPFC_MBX_CMD_HDR_LENGTH + length;
  1436. /* Set up sub-header fields following main header */
  1437. bf_set(lpfc_mbox_hdr_opcode,
  1438. &sli4_config->header.cfg_shdr.request, opcode);
  1439. bf_set(lpfc_mbox_hdr_subsystem,
  1440. &sli4_config->header.cfg_shdr.request, subsystem);
  1441. sli4_config->header.cfg_shdr.request.request_length = length;
  1442. return length;
  1443. }
  1444. /* Setup for the none-embedded mbox command */
  1445. pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
  1446. pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
  1447. LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
  1448. /* Allocate record for keeping SGE virtual addresses */
  1449. mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
  1450. GFP_KERNEL);
  1451. if (!mbox->sge_array)
  1452. return 0;
  1453. for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
  1454. /* The DMA memory is always allocated in the length of a
  1455. * page even though the last SGE might not fill up to a
  1456. * page, this is used as a priori size of PAGE_SIZE for
  1457. * the later DMA memory free.
  1458. */
  1459. viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
  1460. &phyaddr, GFP_KERNEL);
  1461. /* In case of malloc fails, proceed with whatever we have */
  1462. if (!viraddr)
  1463. break;
  1464. memset(viraddr, 0, PAGE_SIZE);
  1465. mbox->sge_array->addr[pagen] = viraddr;
  1466. /* Keep the first page for later sub-header construction */
  1467. if (pagen == 0)
  1468. cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
  1469. resid_len = length - alloc_len;
  1470. if (resid_len > PAGE_SIZE) {
  1471. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1472. PAGE_SIZE);
  1473. alloc_len += PAGE_SIZE;
  1474. } else {
  1475. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1476. resid_len);
  1477. alloc_len = length;
  1478. }
  1479. }
  1480. /* Set up main header fields in mailbox command */
  1481. sli4_config->header.cfg_mhdr.payload_length = alloc_len;
  1482. bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
  1483. /* Set up sub-header fields into the first page */
  1484. if (pagen > 0) {
  1485. bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
  1486. bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
  1487. cfg_shdr->request.request_length =
  1488. alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
  1489. }
  1490. /* The sub-header is in DMA memory, which needs endian converstion */
  1491. lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
  1492. sizeof(union lpfc_sli4_cfg_shdr));
  1493. return alloc_len;
  1494. }
  1495. /**
  1496. * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
  1497. * @phba: pointer to lpfc hba data structure.
  1498. * @mbox: pointer to lpfc mbox command.
  1499. *
  1500. * This routine gets the opcode from a SLI4 specific mailbox command for
  1501. * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
  1502. * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
  1503. * returned.
  1504. **/
  1505. uint8_t
  1506. lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1507. {
  1508. struct lpfc_mbx_sli4_config *sli4_cfg;
  1509. union lpfc_sli4_cfg_shdr *cfg_shdr;
  1510. if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
  1511. return 0;
  1512. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1513. /* For embedded mbox command, get opcode from embedded sub-header*/
  1514. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1515. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  1516. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1517. }
  1518. /* For non-embedded mbox command, get opcode from first dma page */
  1519. if (unlikely(!mbox->sge_array))
  1520. return 0;
  1521. cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
  1522. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1523. }
  1524. /**
  1525. * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
  1526. * @mboxq: pointer to lpfc mbox command.
  1527. *
  1528. * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
  1529. * mailbox command.
  1530. **/
  1531. void
  1532. lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
  1533. {
  1534. /* Set up SLI4 mailbox command header fields */
  1535. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  1536. bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
  1537. /* Set up host requested features. */
  1538. bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
  1539. if (phba->cfg_enable_fip)
  1540. bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0);
  1541. else
  1542. bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 1);
  1543. /* Enable DIF (block guard) only if configured to do so. */
  1544. if (phba->cfg_enable_bg)
  1545. bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
  1546. /* Enable NPIV only if configured to do so. */
  1547. if (phba->max_vpi && phba->cfg_enable_npiv)
  1548. bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
  1549. return;
  1550. }
  1551. /**
  1552. * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
  1553. * @mbox: pointer to lpfc mbox command to initialize.
  1554. * @vport: Vport associated with the VF.
  1555. *
  1556. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1557. * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
  1558. * in the context of an FCF. The driver issues this command to setup a VFI
  1559. * before issuing a FLOGI to login to the VSAN. The driver should also issue a
  1560. * REG_VFI after a successful VSAN login.
  1561. **/
  1562. void
  1563. lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
  1564. {
  1565. struct lpfc_mbx_init_vfi *init_vfi;
  1566. memset(mbox, 0, sizeof(*mbox));
  1567. init_vfi = &mbox->u.mqe.un.init_vfi;
  1568. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
  1569. bf_set(lpfc_init_vfi_vr, init_vfi, 1);
  1570. bf_set(lpfc_init_vfi_vt, init_vfi, 1);
  1571. bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
  1572. bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
  1573. }
  1574. /**
  1575. * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
  1576. * @mbox: pointer to lpfc mbox command to initialize.
  1577. * @vport: vport associated with the VF.
  1578. * @phys: BDE DMA bus address used to send the service parameters to the HBA.
  1579. *
  1580. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1581. * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
  1582. * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
  1583. * fabrics identified by VFI in the context of an FCF.
  1584. **/
  1585. void
  1586. lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
  1587. {
  1588. struct lpfc_mbx_reg_vfi *reg_vfi;
  1589. memset(mbox, 0, sizeof(*mbox));
  1590. reg_vfi = &mbox->u.mqe.un.reg_vfi;
  1591. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
  1592. bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
  1593. bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
  1594. bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
  1595. bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
  1596. reg_vfi->bde.addrHigh = putPaddrHigh(phys);
  1597. reg_vfi->bde.addrLow = putPaddrLow(phys);
  1598. reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
  1599. reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1600. bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
  1601. }
  1602. /**
  1603. * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
  1604. * @mbox: pointer to lpfc mbox command to initialize.
  1605. * @vpi: VPI to be initialized.
  1606. *
  1607. * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
  1608. * command to activate a virtual N_Port. The HBA assigns a MAC address to use
  1609. * with the virtual N Port. The SLI Host issues this command before issuing a
  1610. * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
  1611. * successful virtual NPort login.
  1612. **/
  1613. void
  1614. lpfc_init_vpi(struct lpfcMboxq *mbox, uint16_t vpi)
  1615. {
  1616. memset(mbox, 0, sizeof(*mbox));
  1617. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
  1618. bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, vpi);
  1619. }
  1620. /**
  1621. * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
  1622. * @mbox: pointer to lpfc mbox command to initialize.
  1623. * @vfi: VFI to be unregistered.
  1624. *
  1625. * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
  1626. * (logical NPort) into the inactive state. The SLI Host must have logged out
  1627. * and unregistered all remote N_Ports to abort any activity on the virtual
  1628. * fabric. The SLI Port posts the mailbox response after marking the virtual
  1629. * fabric inactive.
  1630. **/
  1631. void
  1632. lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi)
  1633. {
  1634. memset(mbox, 0, sizeof(*mbox));
  1635. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
  1636. bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi);
  1637. }
  1638. /**
  1639. * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
  1640. * @phba: pointer to the hba structure containing.
  1641. * @mbox: pointer to lpfc mbox command to initialize.
  1642. *
  1643. * This function create a SLI4 dump mailbox command to dump FCoE
  1644. * parameters stored in region 23.
  1645. **/
  1646. int
  1647. lpfc_dump_fcoe_param(struct lpfc_hba *phba,
  1648. struct lpfcMboxq *mbox)
  1649. {
  1650. struct lpfc_dmabuf *mp = NULL;
  1651. MAILBOX_t *mb;
  1652. memset(mbox, 0, sizeof(*mbox));
  1653. mb = &mbox->u.mb;
  1654. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1655. if (mp)
  1656. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1657. if (!mp || !mp->virt) {
  1658. kfree(mp);
  1659. /* dump_fcoe_param failed to allocate memory */
  1660. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  1661. "2569 lpfc_dump_fcoe_param: memory"
  1662. " allocation failed \n");
  1663. return 1;
  1664. }
  1665. memset(mp->virt, 0, LPFC_BPL_SIZE);
  1666. INIT_LIST_HEAD(&mp->list);
  1667. /* save address for completion */
  1668. mbox->context1 = (uint8_t *) mp;
  1669. mb->mbxCommand = MBX_DUMP_MEMORY;
  1670. mb->un.varDmp.type = DMP_NV_PARAMS;
  1671. mb->un.varDmp.region_id = DMP_REGION_FCOEPARAM;
  1672. mb->un.varDmp.sli4_length = DMP_FCOEPARAM_RGN_SIZE;
  1673. mb->un.varWords[3] = putPaddrLow(mp->phys);
  1674. mb->un.varWords[4] = putPaddrHigh(mp->phys);
  1675. return 0;
  1676. }
  1677. /**
  1678. * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
  1679. * @phba: pointer to the hba structure containing the FCF index and RQ ID.
  1680. * @mbox: pointer to lpfc mbox command to initialize.
  1681. *
  1682. * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
  1683. * SLI Host uses the command to activate an FCF after it has acquired FCF
  1684. * information via a READ_FCF mailbox command. This mailbox command also is used
  1685. * to indicate where received unsolicited frames from this FCF will be sent. By
  1686. * default this routine will set up the FCF to forward all unsolicited frames
  1687. * the the RQ ID passed in the @phba. This can be overridden by the caller for
  1688. * more complicated setups.
  1689. **/
  1690. void
  1691. lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1692. {
  1693. struct lpfc_mbx_reg_fcfi *reg_fcfi;
  1694. memset(mbox, 0, sizeof(*mbox));
  1695. reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
  1696. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
  1697. bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
  1698. bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
  1699. bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
  1700. bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
  1701. bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx);
  1702. /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
  1703. bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
  1704. (~phba->fcf.addr_mode) & 0x3);
  1705. if (phba->fcf.fcf_flag & FCF_VALID_VLAN) {
  1706. bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
  1707. bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id);
  1708. }
  1709. }
  1710. /**
  1711. * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
  1712. * @mbox: pointer to lpfc mbox command to initialize.
  1713. * @fcfi: FCFI to be unregistered.
  1714. *
  1715. * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
  1716. * The SLI Host uses the command to inactivate an FCFI.
  1717. **/
  1718. void
  1719. lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
  1720. {
  1721. memset(mbox, 0, sizeof(*mbox));
  1722. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
  1723. bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
  1724. }
  1725. /**
  1726. * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
  1727. * @mbox: pointer to lpfc mbox command to initialize.
  1728. * @ndlp: The nodelist structure that describes the RPI to resume.
  1729. *
  1730. * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
  1731. * link event.
  1732. **/
  1733. void
  1734. lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
  1735. {
  1736. struct lpfc_mbx_resume_rpi *resume_rpi;
  1737. memset(mbox, 0, sizeof(*mbox));
  1738. resume_rpi = &mbox->u.mqe.un.resume_rpi;
  1739. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
  1740. bf_set(lpfc_resume_rpi_rpi, resume_rpi, ndlp->nlp_rpi);
  1741. bf_set(lpfc_resume_rpi_vpi, resume_rpi,
  1742. ndlp->vport->vpi + ndlp->vport->phba->vpi_base);
  1743. bf_set(lpfc_resume_rpi_vfi, resume_rpi,
  1744. ndlp->vport->vfi + ndlp->vport->phba->vfi_base);
  1745. }