lpfc_mbox.c 65 KB

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