lpfc_mbox.c 70 KB

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