lpfc_mbox.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
  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_reg_vpi - Prepare a mailbox command for registering vport identifier
  715. * @phba: pointer to lpfc hba data structure.
  716. * @vpi: virtual N_Port identifier.
  717. * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
  718. * @pmb: pointer to the driver internal queue element for mailbox command.
  719. *
  720. * The registration vport identifier mailbox command is used to activate a
  721. * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
  722. * N_Port_ID against the information in the selected virtual N_Port context
  723. * block and marks it active to allow normal processing of IOCB commands and
  724. * received unsolicited exchanges.
  725. *
  726. * This routine prepares the mailbox command for registering a virtual N_Port.
  727. **/
  728. void
  729. lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
  730. {
  731. MAILBOX_t *mb = &pmb->u.mb;
  732. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  733. mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
  734. mb->un.varRegVpi.sid = vport->fc_myDID;
  735. mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
  736. memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
  737. sizeof(struct lpfc_name));
  738. mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
  739. mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
  740. mb->mbxCommand = MBX_REG_VPI;
  741. mb->mbxOwner = OWN_HOST;
  742. return;
  743. }
  744. /**
  745. * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
  746. * @phba: pointer to lpfc hba data structure.
  747. * @vpi: virtual N_Port identifier.
  748. * @pmb: pointer to the driver internal queue element for mailbox command.
  749. *
  750. * The unregistration vport identifier mailbox command is used to inactivate
  751. * a virtual N_Port. The driver must have logged out and unregistered all
  752. * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
  753. * unregisters any default RPIs associated with the specified vpi, aborting
  754. * any active exchanges. The HBA will post the mailbox response after making
  755. * the virtual N_Port inactive.
  756. *
  757. * This routine prepares the mailbox command for unregistering a virtual
  758. * N_Port.
  759. **/
  760. void
  761. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  762. {
  763. MAILBOX_t *mb = &pmb->u.mb;
  764. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  765. if (phba->sli_rev < LPFC_SLI_REV4)
  766. mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
  767. else
  768. mb->un.varUnregVpi.sli4_vpi = vpi + phba->vpi_base;
  769. mb->mbxCommand = MBX_UNREG_VPI;
  770. mb->mbxOwner = OWN_HOST;
  771. return;
  772. }
  773. /**
  774. * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
  775. * @phba: pointer to lpfc hba data structure.
  776. *
  777. * This routine sets up and initializes the IOCB rings in the Port Control
  778. * Block (PCB).
  779. **/
  780. static void
  781. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  782. {
  783. struct lpfc_sli *psli = &phba->sli;
  784. struct lpfc_sli_ring *pring;
  785. PCB_t *pcbp = phba->pcb;
  786. dma_addr_t pdma_addr;
  787. uint32_t offset;
  788. uint32_t iocbCnt = 0;
  789. int i;
  790. pcbp->maxRing = (psli->num_rings - 1);
  791. for (i = 0; i < psli->num_rings; i++) {
  792. pring = &psli->ring[i];
  793. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  794. SLI2_IOCB_CMD_SIZE;
  795. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  796. SLI2_IOCB_RSP_SIZE;
  797. /* A ring MUST have both cmd and rsp entries defined to be
  798. valid */
  799. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  800. pcbp->rdsc[i].cmdEntries = 0;
  801. pcbp->rdsc[i].rspEntries = 0;
  802. pcbp->rdsc[i].cmdAddrHigh = 0;
  803. pcbp->rdsc[i].rspAddrHigh = 0;
  804. pcbp->rdsc[i].cmdAddrLow = 0;
  805. pcbp->rdsc[i].rspAddrLow = 0;
  806. pring->cmdringaddr = NULL;
  807. pring->rspringaddr = NULL;
  808. continue;
  809. }
  810. /* Command ring setup for ring */
  811. pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
  812. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  813. offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
  814. (uint8_t *) phba->slim2p.virt;
  815. pdma_addr = phba->slim2p.phys + offset;
  816. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  817. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  818. iocbCnt += pring->numCiocb;
  819. /* Response ring setup for ring */
  820. pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
  821. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  822. offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
  823. (uint8_t *)phba->slim2p.virt;
  824. pdma_addr = phba->slim2p.phys + offset;
  825. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  826. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  827. iocbCnt += pring->numRiocb;
  828. }
  829. }
  830. /**
  831. * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
  832. * @phba: pointer to lpfc hba data structure.
  833. * @pmb: pointer to the driver internal queue element for mailbox command.
  834. *
  835. * The read revision mailbox command is used to read the revision levels of
  836. * the HBA components. These components include hardware units, resident
  837. * firmware, and available firmware. HBAs that supports SLI-3 mode of
  838. * operation provide different response information depending on the version
  839. * requested by the driver.
  840. *
  841. * This routine prepares the mailbox command for reading HBA revision
  842. * information.
  843. **/
  844. void
  845. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  846. {
  847. MAILBOX_t *mb = &pmb->u.mb;
  848. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  849. mb->un.varRdRev.cv = 1;
  850. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  851. mb->mbxCommand = MBX_READ_REV;
  852. mb->mbxOwner = OWN_HOST;
  853. return;
  854. }
  855. /**
  856. * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
  857. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  858. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  859. *
  860. * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
  861. * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
  862. * the Sequence Length Test using the fields in the Selection Profile 2
  863. * extension in words 20:31.
  864. **/
  865. static void
  866. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  867. struct lpfc_hbq_init *hbq_desc)
  868. {
  869. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  870. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  871. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  872. }
  873. /**
  874. * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
  875. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  876. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  877. *
  878. * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
  879. * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
  880. * the Sequence Length Test and Byte Field Test using the fields in the
  881. * Selection Profile 3 extension in words 20:31.
  882. **/
  883. static void
  884. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  885. struct lpfc_hbq_init *hbq_desc)
  886. {
  887. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  888. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  889. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  890. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  891. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  892. sizeof(hbqmb->profiles.profile3.cmdmatch));
  893. }
  894. /**
  895. * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
  896. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  897. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  898. *
  899. * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
  900. * HBA tests the initial frame of an incoming sequence using the frame's
  901. * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
  902. * and Byte Field Test using the fields in the Selection Profile 5 extension
  903. * words 20:31.
  904. **/
  905. static void
  906. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  907. struct lpfc_hbq_init *hbq_desc)
  908. {
  909. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  910. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  911. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  912. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  913. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  914. sizeof(hbqmb->profiles.profile5.cmdmatch));
  915. }
  916. /**
  917. * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
  918. * @phba: pointer to lpfc hba data structure.
  919. * @id: HBQ identifier.
  920. * @hbq_desc: pointer to the HBA descriptor data structure.
  921. * @hbq_entry_index: index of the HBQ entry data structures.
  922. * @pmb: pointer to the driver internal queue element for mailbox command.
  923. *
  924. * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
  925. * an HBQ. The configuration binds events that require buffers to a particular
  926. * ring and HBQ based on a selection profile.
  927. *
  928. * This routine prepares the mailbox command for configuring an HBQ.
  929. **/
  930. void
  931. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  932. struct lpfc_hbq_init *hbq_desc,
  933. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  934. {
  935. int i;
  936. MAILBOX_t *mb = &pmb->u.mb;
  937. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  938. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  939. hbqmb->hbqId = id;
  940. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  941. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  942. * Notification */
  943. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  944. * # in words 0-19 */
  945. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  946. * 0 = all,
  947. * 7 = logentry */
  948. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  949. * e.g. Ring0=b0001,
  950. * ring2=b0100 */
  951. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  952. * or 5 */
  953. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  954. * HBQ will be used
  955. * for LogEntry
  956. * buffers */
  957. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  958. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  959. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  960. mb->mbxCommand = MBX_CONFIG_HBQ;
  961. mb->mbxOwner = OWN_HOST;
  962. /* Copy info for profiles 2,3,5. Other
  963. * profiles this area is reserved
  964. */
  965. if (hbq_desc->profile == 2)
  966. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  967. else if (hbq_desc->profile == 3)
  968. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  969. else if (hbq_desc->profile == 5)
  970. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  971. /* Return if no rctl / type masks for this HBQ */
  972. if (!hbq_desc->mask_count)
  973. return;
  974. /* Otherwise we setup specific rctl / type masks for this HBQ */
  975. for (i = 0; i < hbq_desc->mask_count; i++) {
  976. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  977. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  978. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  979. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  980. }
  981. return;
  982. }
  983. /**
  984. * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
  985. * @phba: pointer to lpfc hba data structure.
  986. * @ring:
  987. * @pmb: pointer to the driver internal queue element for mailbox command.
  988. *
  989. * The configure ring mailbox command is used to configure an IOCB ring. This
  990. * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
  991. * ring. This is used to map incoming sequences to a particular ring whose
  992. * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
  993. * attempt to configure a ring whose number is greater than the number
  994. * specified in the Port Control Block (PCB). It is an error to issue the
  995. * configure ring command more than once with the same ring number. The HBA
  996. * returns an error if the driver attempts this.
  997. *
  998. * This routine prepares the mailbox command for configuring IOCB ring.
  999. **/
  1000. void
  1001. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  1002. {
  1003. int i;
  1004. MAILBOX_t *mb = &pmb->u.mb;
  1005. struct lpfc_sli *psli;
  1006. struct lpfc_sli_ring *pring;
  1007. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  1008. mb->un.varCfgRing.ring = ring;
  1009. mb->un.varCfgRing.maxOrigXchg = 0;
  1010. mb->un.varCfgRing.maxRespXchg = 0;
  1011. mb->un.varCfgRing.recvNotify = 1;
  1012. psli = &phba->sli;
  1013. pring = &psli->ring[ring];
  1014. mb->un.varCfgRing.numMask = pring->num_mask;
  1015. mb->mbxCommand = MBX_CONFIG_RING;
  1016. mb->mbxOwner = OWN_HOST;
  1017. /* Is this ring configured for a specific profile */
  1018. if (pring->prt[0].profile) {
  1019. mb->un.varCfgRing.profile = pring->prt[0].profile;
  1020. return;
  1021. }
  1022. /* Otherwise we setup specific rctl / type masks for this ring */
  1023. for (i = 0; i < pring->num_mask; i++) {
  1024. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  1025. if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
  1026. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  1027. else
  1028. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  1029. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  1030. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  1031. }
  1032. return;
  1033. }
  1034. /**
  1035. * lpfc_config_port - Prepare a mailbox command for configuring port
  1036. * @phba: pointer to lpfc hba data structure.
  1037. * @pmb: pointer to the driver internal queue element for mailbox command.
  1038. *
  1039. * The configure port mailbox command is used to identify the Port Control
  1040. * Block (PCB) in the driver memory. After this command is issued, the
  1041. * driver must not access the mailbox in the HBA without first resetting
  1042. * the HBA. The HBA may copy the PCB information to internal storage for
  1043. * subsequent use; the driver can not change the PCB information unless it
  1044. * resets the HBA.
  1045. *
  1046. * This routine prepares the mailbox command for configuring port.
  1047. **/
  1048. void
  1049. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1050. {
  1051. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  1052. MAILBOX_t *mb = &pmb->u.mb;
  1053. dma_addr_t pdma_addr;
  1054. uint32_t bar_low, bar_high;
  1055. size_t offset;
  1056. struct lpfc_hgp hgp;
  1057. int i;
  1058. uint32_t pgp_offset;
  1059. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1060. mb->mbxCommand = MBX_CONFIG_PORT;
  1061. mb->mbxOwner = OWN_HOST;
  1062. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  1063. offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
  1064. pdma_addr = phba->slim2p.phys + offset;
  1065. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  1066. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  1067. /* Always Host Group Pointer is in SLIM */
  1068. mb->un.varCfgPort.hps = 1;
  1069. /* If HBA supports SLI=3 ask for it */
  1070. if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
  1071. if (phba->cfg_enable_bg)
  1072. mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
  1073. mb->un.varCfgPort.cdss = 1; /* Configure Security */
  1074. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  1075. mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
  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) + MAILBOX_EXT_SIZE;
  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->cfg_hostmem_hgp && phba->sli_rev != 3) {
  1142. phba->host_gp = &phba->mbox->us.s2.host[0];
  1143. phba->hbq_put = NULL;
  1144. offset = (uint8_t *)&phba->mbox->us.s2.host -
  1145. (uint8_t *)phba->slim2p.virt;
  1146. pdma_addr = phba->slim2p.phys + offset;
  1147. phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
  1148. phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
  1149. } else {
  1150. /* Always Host Group Pointer is in SLIM */
  1151. mb->un.varCfgPort.hps = 1;
  1152. if (phba->sli_rev == 3) {
  1153. phba->host_gp = &mb_slim->us.s3.host[0];
  1154. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  1155. } else {
  1156. phba->host_gp = &mb_slim->us.s2.host[0];
  1157. phba->hbq_put = NULL;
  1158. }
  1159. /* mask off BAR0's flag bits 0 - 3 */
  1160. phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  1161. (void __iomem *)phba->host_gp -
  1162. (void __iomem *)phba->MBslimaddr;
  1163. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  1164. phba->pcb->hgpAddrHigh = bar_high;
  1165. else
  1166. phba->pcb->hgpAddrHigh = 0;
  1167. /* write HGP data to SLIM at the required longword offset */
  1168. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  1169. for (i = 0; i < phba->sli.num_rings; i++) {
  1170. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  1171. sizeof(*phba->host_gp));
  1172. }
  1173. }
  1174. /* Setup Port Group offset */
  1175. if (phba->sli_rev == 3)
  1176. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1177. mbx.us.s3_pgp.port);
  1178. else
  1179. pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
  1180. pdma_addr = phba->slim2p.phys + pgp_offset;
  1181. phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
  1182. phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
  1183. /* Use callback routine to setp rings in the pcb */
  1184. lpfc_config_pcb_setup(phba);
  1185. /* special handling for LC HBAs */
  1186. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  1187. uint32_t hbainit[5];
  1188. lpfc_hba_init(phba, hbainit);
  1189. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  1190. }
  1191. /* Swap PCB if needed */
  1192. lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
  1193. }
  1194. /**
  1195. * lpfc_kill_board - Prepare a mailbox command for killing board
  1196. * @phba: pointer to lpfc hba data structure.
  1197. * @pmb: pointer to the driver internal queue element for mailbox command.
  1198. *
  1199. * The kill board mailbox command is used to tell firmware to perform a
  1200. * graceful shutdown of a channel on a specified board to prepare for reset.
  1201. * When the kill board mailbox command is received, the ER3 bit is set to 1
  1202. * in the Host Status register and the ER Attention bit is set to 1 in the
  1203. * Host Attention register of the HBA function that received the kill board
  1204. * command.
  1205. *
  1206. * This routine prepares the mailbox command for killing the board in
  1207. * preparation for a graceful shutdown.
  1208. **/
  1209. void
  1210. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1211. {
  1212. MAILBOX_t *mb = &pmb->u.mb;
  1213. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1214. mb->mbxCommand = MBX_KILL_BOARD;
  1215. mb->mbxOwner = OWN_HOST;
  1216. return;
  1217. }
  1218. /**
  1219. * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
  1220. * @phba: pointer to lpfc hba data structure.
  1221. * @mbq: pointer to the driver internal queue element for mailbox command.
  1222. *
  1223. * Driver maintains a internal mailbox command queue implemented as a linked
  1224. * list. When a mailbox command is issued, it shall be put into the mailbox
  1225. * command queue such that they shall be processed orderly as HBA can process
  1226. * one mailbox command at a time.
  1227. **/
  1228. void
  1229. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1230. {
  1231. struct lpfc_sli *psli;
  1232. psli = &phba->sli;
  1233. list_add_tail(&mbq->list, &psli->mboxq);
  1234. psli->mboxq_cnt++;
  1235. return;
  1236. }
  1237. /**
  1238. * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
  1239. * @phba: pointer to lpfc hba data structure.
  1240. *
  1241. * Driver maintains a internal mailbox command queue implemented as a linked
  1242. * list. When a mailbox command is issued, it shall be put into the mailbox
  1243. * command queue such that they shall be processed orderly as HBA can process
  1244. * one mailbox command at a time. After HBA finished processing a mailbox
  1245. * command, the driver will remove a pending mailbox command from the head of
  1246. * the mailbox command queue and send to the HBA for processing.
  1247. *
  1248. * Return codes
  1249. * pointer to the driver internal queue element for mailbox command.
  1250. **/
  1251. LPFC_MBOXQ_t *
  1252. lpfc_mbox_get(struct lpfc_hba * phba)
  1253. {
  1254. LPFC_MBOXQ_t *mbq = NULL;
  1255. struct lpfc_sli *psli = &phba->sli;
  1256. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  1257. if (mbq)
  1258. psli->mboxq_cnt--;
  1259. return mbq;
  1260. }
  1261. /**
  1262. * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
  1263. * @phba: pointer to lpfc hba data structure.
  1264. * @mbq: pointer to the driver internal queue element for mailbox command.
  1265. *
  1266. * This routine put the completed mailbox command into the mailbox command
  1267. * complete list. This is the unlocked version of the routine. The mailbox
  1268. * complete list is used by the driver worker thread to process mailbox
  1269. * complete callback functions outside the driver interrupt handler.
  1270. **/
  1271. void
  1272. __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1273. {
  1274. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  1275. }
  1276. /**
  1277. * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
  1278. * @phba: pointer to lpfc hba data structure.
  1279. * @mbq: pointer to the driver internal queue element for mailbox command.
  1280. *
  1281. * This routine put the completed mailbox command into the mailbox command
  1282. * complete list. This is the locked version of the routine. The mailbox
  1283. * complete list is used by the driver worker thread to process mailbox
  1284. * complete callback functions outside the driver interrupt handler.
  1285. **/
  1286. void
  1287. lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1288. {
  1289. unsigned long iflag;
  1290. /* This function expects to be called from interrupt context */
  1291. spin_lock_irqsave(&phba->hbalock, iflag);
  1292. __lpfc_mbox_cmpl_put(phba, mbq);
  1293. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1294. return;
  1295. }
  1296. /**
  1297. * lpfc_mbox_cmd_check - Check the validality of a mailbox command
  1298. * @phba: pointer to lpfc hba data structure.
  1299. * @mboxq: pointer to the driver internal queue element for mailbox command.
  1300. *
  1301. * This routine is to check whether a mailbox command is valid to be issued.
  1302. * This check will be performed by both the mailbox issue API when a client
  1303. * is to issue a mailbox command to the mailbox transport.
  1304. *
  1305. * Return 0 - pass the check, -ENODEV - fail the check
  1306. **/
  1307. int
  1308. lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1309. {
  1310. /* Mailbox command that have a completion handler must also have a
  1311. * vport specified.
  1312. */
  1313. if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  1314. mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  1315. if (!mboxq->vport) {
  1316. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1317. "1814 Mbox x%x failed, no vport\n",
  1318. mboxq->u.mb.mbxCommand);
  1319. dump_stack();
  1320. return -ENODEV;
  1321. }
  1322. }
  1323. return 0;
  1324. }
  1325. /**
  1326. * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
  1327. * @phba: pointer to lpfc hba data structure.
  1328. *
  1329. * This routine is to check whether the HBA device is ready for posting a
  1330. * mailbox command. It is used by the mailbox transport API at the time the
  1331. * to post a mailbox command to the device.
  1332. *
  1333. * Return 0 - pass the check, -ENODEV - fail the check
  1334. **/
  1335. int
  1336. lpfc_mbox_dev_check(struct lpfc_hba *phba)
  1337. {
  1338. /* If the PCI channel is in offline state, do not issue mbox */
  1339. if (unlikely(pci_channel_offline(phba->pcidev)))
  1340. return -ENODEV;
  1341. /* If the HBA is in error state, do not issue mbox */
  1342. if (phba->link_state == LPFC_HBA_ERROR)
  1343. return -ENODEV;
  1344. return 0;
  1345. }
  1346. /**
  1347. * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
  1348. * @phba: pointer to lpfc hba data structure.
  1349. * @cmd: mailbox command code.
  1350. *
  1351. * This routine retrieves the proper timeout value according to the mailbox
  1352. * command code.
  1353. *
  1354. * Return codes
  1355. * Timeout value to be used for the given mailbox command
  1356. **/
  1357. int
  1358. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  1359. {
  1360. switch (cmd) {
  1361. case MBX_WRITE_NV: /* 0x03 */
  1362. case MBX_UPDATE_CFG: /* 0x1B */
  1363. case MBX_DOWN_LOAD: /* 0x1C */
  1364. case MBX_DEL_LD_ENTRY: /* 0x1D */
  1365. case MBX_LOAD_AREA: /* 0x81 */
  1366. case MBX_WRITE_WWN: /* 0x98 */
  1367. case MBX_LOAD_EXP_ROM: /* 0x9C */
  1368. return LPFC_MBOX_TMO_FLASH_CMD;
  1369. case MBX_SLI4_CONFIG: /* 0x9b */
  1370. return LPFC_MBOX_SLI4_CONFIG_TMO;
  1371. }
  1372. return LPFC_MBOX_TMO;
  1373. }
  1374. /**
  1375. * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
  1376. * @mbox: pointer to lpfc mbox command.
  1377. * @sgentry: sge entry index.
  1378. * @phyaddr: physical address for the sge
  1379. * @length: Length of the sge.
  1380. *
  1381. * This routine sets up an entry in the non-embedded mailbox command at the sge
  1382. * index location.
  1383. **/
  1384. void
  1385. lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
  1386. dma_addr_t phyaddr, uint32_t length)
  1387. {
  1388. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1389. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1390. &mbox->u.mqe.un.nembed_cmd;
  1391. nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
  1392. nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
  1393. nembed_sge->sge[sgentry].length = length;
  1394. }
  1395. /**
  1396. * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
  1397. * @mbox: pointer to lpfc mbox command.
  1398. * @sgentry: sge entry index.
  1399. *
  1400. * This routine gets an entry from the non-embedded mailbox command at the sge
  1401. * index location.
  1402. **/
  1403. void
  1404. lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
  1405. struct lpfc_mbx_sge *sge)
  1406. {
  1407. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1408. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1409. &mbox->u.mqe.un.nembed_cmd;
  1410. sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
  1411. sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
  1412. sge->length = nembed_sge->sge[sgentry].length;
  1413. }
  1414. /**
  1415. * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
  1416. * @phba: pointer to lpfc hba data structure.
  1417. * @mbox: pointer to lpfc mbox command.
  1418. *
  1419. * This routine frees SLI4 specific mailbox command for sending IOCTL command.
  1420. **/
  1421. void
  1422. lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1423. {
  1424. struct lpfc_mbx_sli4_config *sli4_cfg;
  1425. struct lpfc_mbx_sge sge;
  1426. dma_addr_t phyaddr;
  1427. uint32_t sgecount, sgentry;
  1428. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1429. /* For embedded mbox command, just free the mbox command */
  1430. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1431. mempool_free(mbox, phba->mbox_mem_pool);
  1432. return;
  1433. }
  1434. /* For non-embedded mbox command, we need to free the pages first */
  1435. sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
  1436. /* There is nothing we can do if there is no sge address array */
  1437. if (unlikely(!mbox->sge_array)) {
  1438. mempool_free(mbox, phba->mbox_mem_pool);
  1439. return;
  1440. }
  1441. /* Each non-embedded DMA memory was allocated in the length of a page */
  1442. for (sgentry = 0; sgentry < sgecount; sgentry++) {
  1443. lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
  1444. phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
  1445. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  1446. mbox->sge_array->addr[sgentry], phyaddr);
  1447. }
  1448. /* Free the sge address array memory */
  1449. kfree(mbox->sge_array);
  1450. /* Finally, free the mailbox command itself */
  1451. mempool_free(mbox, phba->mbox_mem_pool);
  1452. }
  1453. /**
  1454. * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
  1455. * @phba: pointer to lpfc hba data structure.
  1456. * @mbox: pointer to lpfc mbox command.
  1457. * @subsystem: The sli4 config sub mailbox subsystem.
  1458. * @opcode: The sli4 config sub mailbox command opcode.
  1459. * @length: Length of the sli4 config mailbox command.
  1460. *
  1461. * This routine sets up the header fields of SLI4 specific mailbox command
  1462. * for sending IOCTL command.
  1463. *
  1464. * Return: the actual length of the mbox command allocated (mostly useful
  1465. * for none embedded mailbox command).
  1466. **/
  1467. int
  1468. lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
  1469. uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
  1470. {
  1471. struct lpfc_mbx_sli4_config *sli4_config;
  1472. union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
  1473. uint32_t alloc_len;
  1474. uint32_t resid_len;
  1475. uint32_t pagen, pcount;
  1476. void *viraddr;
  1477. dma_addr_t phyaddr;
  1478. /* Set up SLI4 mailbox command header fields */
  1479. memset(mbox, 0, sizeof(*mbox));
  1480. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
  1481. /* Set up SLI4 ioctl command header fields */
  1482. sli4_config = &mbox->u.mqe.un.sli4_config;
  1483. /* Setup for the embedded mbox command */
  1484. if (emb) {
  1485. /* Set up main header fields */
  1486. bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
  1487. sli4_config->header.cfg_mhdr.payload_length =
  1488. LPFC_MBX_CMD_HDR_LENGTH + length;
  1489. /* Set up sub-header fields following main header */
  1490. bf_set(lpfc_mbox_hdr_opcode,
  1491. &sli4_config->header.cfg_shdr.request, opcode);
  1492. bf_set(lpfc_mbox_hdr_subsystem,
  1493. &sli4_config->header.cfg_shdr.request, subsystem);
  1494. sli4_config->header.cfg_shdr.request.request_length = length;
  1495. return length;
  1496. }
  1497. /* Setup for the none-embedded mbox command */
  1498. pcount = (PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
  1499. pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
  1500. LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
  1501. /* Allocate record for keeping SGE virtual addresses */
  1502. mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
  1503. GFP_KERNEL);
  1504. if (!mbox->sge_array) {
  1505. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1506. "2527 Failed to allocate non-embedded SGE "
  1507. "array.\n");
  1508. return 0;
  1509. }
  1510. for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
  1511. /* The DMA memory is always allocated in the length of a
  1512. * page even though the last SGE might not fill up to a
  1513. * page, this is used as a priori size of SLI4_PAGE_SIZE for
  1514. * the later DMA memory free.
  1515. */
  1516. viraddr = dma_alloc_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  1517. &phyaddr, GFP_KERNEL);
  1518. /* In case of malloc fails, proceed with whatever we have */
  1519. if (!viraddr)
  1520. break;
  1521. memset(viraddr, 0, SLI4_PAGE_SIZE);
  1522. mbox->sge_array->addr[pagen] = viraddr;
  1523. /* Keep the first page for later sub-header construction */
  1524. if (pagen == 0)
  1525. cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
  1526. resid_len = length - alloc_len;
  1527. if (resid_len > SLI4_PAGE_SIZE) {
  1528. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1529. SLI4_PAGE_SIZE);
  1530. alloc_len += SLI4_PAGE_SIZE;
  1531. } else {
  1532. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1533. resid_len);
  1534. alloc_len = length;
  1535. }
  1536. }
  1537. /* Set up main header fields in mailbox command */
  1538. sli4_config->header.cfg_mhdr.payload_length = alloc_len;
  1539. bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
  1540. /* Set up sub-header fields into the first page */
  1541. if (pagen > 0) {
  1542. bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
  1543. bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
  1544. cfg_shdr->request.request_length =
  1545. alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
  1546. }
  1547. /* The sub-header is in DMA memory, which needs endian converstion */
  1548. if (cfg_shdr)
  1549. lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
  1550. sizeof(union lpfc_sli4_cfg_shdr));
  1551. return alloc_len;
  1552. }
  1553. /**
  1554. * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
  1555. * @phba: pointer to lpfc hba data structure.
  1556. * @mbox: pointer to lpfc mbox command.
  1557. *
  1558. * This routine gets the opcode from a SLI4 specific mailbox command for
  1559. * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
  1560. * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
  1561. * returned.
  1562. **/
  1563. uint8_t
  1564. lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1565. {
  1566. struct lpfc_mbx_sli4_config *sli4_cfg;
  1567. union lpfc_sli4_cfg_shdr *cfg_shdr;
  1568. if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
  1569. return 0;
  1570. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1571. /* For embedded mbox command, get opcode from embedded sub-header*/
  1572. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1573. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  1574. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1575. }
  1576. /* For non-embedded mbox command, get opcode from first dma page */
  1577. if (unlikely(!mbox->sge_array))
  1578. return 0;
  1579. cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
  1580. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1581. }
  1582. /**
  1583. * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
  1584. * @phba: pointer to lpfc hba data structure.
  1585. * @fcf_index: index to fcf table.
  1586. *
  1587. * This routine routine allocates and constructs non-embedded mailbox command
  1588. * for reading a FCF table entry refered by @fcf_index.
  1589. *
  1590. * Return: pointer to the mailbox command constructed if successful, otherwise
  1591. * NULL.
  1592. **/
  1593. int
  1594. lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
  1595. struct lpfcMboxq *mboxq,
  1596. uint16_t fcf_index)
  1597. {
  1598. void *virt_addr;
  1599. dma_addr_t phys_addr;
  1600. uint8_t *bytep;
  1601. struct lpfc_mbx_sge sge;
  1602. uint32_t alloc_len, req_len;
  1603. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1604. if (!mboxq)
  1605. return -ENOMEM;
  1606. req_len = sizeof(struct fcf_record) +
  1607. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  1608. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  1609. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  1610. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  1611. LPFC_SLI4_MBX_NEMBED);
  1612. if (alloc_len < req_len) {
  1613. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1614. "0291 Allocated DMA memory size (x%x) is "
  1615. "less than the requested DMA memory "
  1616. "size (x%x)\n", alloc_len, req_len);
  1617. return -ENOMEM;
  1618. }
  1619. /* Get the first SGE entry from the non-embedded DMA memory. This
  1620. * routine only uses a single SGE.
  1621. */
  1622. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1623. phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
  1624. virt_addr = mboxq->sge_array->addr[0];
  1625. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1626. /* Set up command fields */
  1627. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  1628. /* Perform necessary endian conversion */
  1629. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  1630. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  1631. return 0;
  1632. }
  1633. /**
  1634. * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
  1635. * @mboxq: pointer to lpfc mbox command.
  1636. *
  1637. * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
  1638. * mailbox command.
  1639. **/
  1640. void
  1641. lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
  1642. {
  1643. /* Set up SLI4 mailbox command header fields */
  1644. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  1645. bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
  1646. /* Set up host requested features. */
  1647. bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
  1648. /* Enable DIF (block guard) only if configured to do so. */
  1649. if (phba->cfg_enable_bg)
  1650. bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
  1651. /* Enable NPIV only if configured to do so. */
  1652. if (phba->max_vpi && phba->cfg_enable_npiv)
  1653. bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
  1654. return;
  1655. }
  1656. /**
  1657. * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
  1658. * @mbox: pointer to lpfc mbox command to initialize.
  1659. * @vport: Vport associated with the VF.
  1660. *
  1661. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1662. * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
  1663. * in the context of an FCF. The driver issues this command to setup a VFI
  1664. * before issuing a FLOGI to login to the VSAN. The driver should also issue a
  1665. * REG_VFI after a successful VSAN login.
  1666. **/
  1667. void
  1668. lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
  1669. {
  1670. struct lpfc_mbx_init_vfi *init_vfi;
  1671. memset(mbox, 0, sizeof(*mbox));
  1672. init_vfi = &mbox->u.mqe.un.init_vfi;
  1673. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
  1674. bf_set(lpfc_init_vfi_vr, init_vfi, 1);
  1675. bf_set(lpfc_init_vfi_vt, init_vfi, 1);
  1676. bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
  1677. bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
  1678. }
  1679. /**
  1680. * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
  1681. * @mbox: pointer to lpfc mbox command to initialize.
  1682. * @vport: vport associated with the VF.
  1683. * @phys: BDE DMA bus address used to send the service parameters to the HBA.
  1684. *
  1685. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1686. * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
  1687. * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
  1688. * fabrics identified by VFI in the context of an FCF.
  1689. **/
  1690. void
  1691. lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
  1692. {
  1693. struct lpfc_mbx_reg_vfi *reg_vfi;
  1694. memset(mbox, 0, sizeof(*mbox));
  1695. reg_vfi = &mbox->u.mqe.un.reg_vfi;
  1696. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
  1697. bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
  1698. bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
  1699. bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
  1700. bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
  1701. memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
  1702. reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
  1703. reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
  1704. reg_vfi->e_d_tov = vport->phba->fc_edtov;
  1705. reg_vfi->r_a_tov = vport->phba->fc_ratov;
  1706. reg_vfi->bde.addrHigh = putPaddrHigh(phys);
  1707. reg_vfi->bde.addrLow = putPaddrLow(phys);
  1708. reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
  1709. reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  1710. bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
  1711. }
  1712. /**
  1713. * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
  1714. * @phba: pointer to the hba structure to init the VPI for.
  1715. * @mbox: pointer to lpfc mbox command to initialize.
  1716. * @vpi: VPI to be initialized.
  1717. *
  1718. * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
  1719. * command to activate a virtual N_Port. The HBA assigns a MAC address to use
  1720. * with the virtual N Port. The SLI Host issues this command before issuing a
  1721. * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
  1722. * successful virtual NPort login.
  1723. **/
  1724. void
  1725. lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
  1726. {
  1727. memset(mbox, 0, sizeof(*mbox));
  1728. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
  1729. bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
  1730. vpi + phba->vpi_base);
  1731. bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
  1732. phba->pport->vfi + phba->vfi_base);
  1733. }
  1734. /**
  1735. * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
  1736. * @mbox: pointer to lpfc mbox command to initialize.
  1737. * @vport: vport associated with the VF.
  1738. *
  1739. * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
  1740. * (logical NPort) into the inactive state. The SLI Host must have logged out
  1741. * and unregistered all remote N_Ports to abort any activity on the virtual
  1742. * fabric. The SLI Port posts the mailbox response after marking the virtual
  1743. * fabric inactive.
  1744. **/
  1745. void
  1746. lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
  1747. {
  1748. memset(mbox, 0, sizeof(*mbox));
  1749. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
  1750. bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
  1751. vport->vfi + vport->phba->vfi_base);
  1752. }
  1753. /**
  1754. * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
  1755. * @phba: pointer to the hba structure containing.
  1756. * @mbox: pointer to lpfc mbox command to initialize.
  1757. *
  1758. * This function create a SLI4 dump mailbox command to dump FCoE
  1759. * parameters stored in region 23.
  1760. **/
  1761. int
  1762. lpfc_dump_fcoe_param(struct lpfc_hba *phba,
  1763. struct lpfcMboxq *mbox)
  1764. {
  1765. struct lpfc_dmabuf *mp = NULL;
  1766. MAILBOX_t *mb;
  1767. memset(mbox, 0, sizeof(*mbox));
  1768. mb = &mbox->u.mb;
  1769. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1770. if (mp)
  1771. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  1772. if (!mp || !mp->virt) {
  1773. kfree(mp);
  1774. /* dump_fcoe_param failed to allocate memory */
  1775. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  1776. "2569 lpfc_dump_fcoe_param: memory"
  1777. " allocation failed\n");
  1778. return 1;
  1779. }
  1780. memset(mp->virt, 0, LPFC_BPL_SIZE);
  1781. INIT_LIST_HEAD(&mp->list);
  1782. /* save address for completion */
  1783. mbox->context1 = (uint8_t *) mp;
  1784. mb->mbxCommand = MBX_DUMP_MEMORY;
  1785. mb->un.varDmp.type = DMP_NV_PARAMS;
  1786. mb->un.varDmp.region_id = DMP_REGION_23;
  1787. mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
  1788. mb->un.varWords[3] = putPaddrLow(mp->phys);
  1789. mb->un.varWords[4] = putPaddrHigh(mp->phys);
  1790. return 0;
  1791. }
  1792. /**
  1793. * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
  1794. * @phba: pointer to the hba structure containing the FCF index and RQ ID.
  1795. * @mbox: pointer to lpfc mbox command to initialize.
  1796. *
  1797. * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
  1798. * SLI Host uses the command to activate an FCF after it has acquired FCF
  1799. * information via a READ_FCF mailbox command. This mailbox command also is used
  1800. * to indicate where received unsolicited frames from this FCF will be sent. By
  1801. * default this routine will set up the FCF to forward all unsolicited frames
  1802. * the the RQ ID passed in the @phba. This can be overridden by the caller for
  1803. * more complicated setups.
  1804. **/
  1805. void
  1806. lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1807. {
  1808. struct lpfc_mbx_reg_fcfi *reg_fcfi;
  1809. memset(mbox, 0, sizeof(*mbox));
  1810. reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
  1811. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
  1812. bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
  1813. bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
  1814. bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
  1815. bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
  1816. bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
  1817. phba->fcf.current_rec.fcf_indx);
  1818. /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
  1819. bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
  1820. if (phba->fcf.current_rec.vlan_id != 0xFFFF) {
  1821. bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
  1822. bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
  1823. phba->fcf.current_rec.vlan_id);
  1824. }
  1825. }
  1826. /**
  1827. * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
  1828. * @mbox: pointer to lpfc mbox command to initialize.
  1829. * @fcfi: FCFI to be unregistered.
  1830. *
  1831. * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
  1832. * The SLI Host uses the command to inactivate an FCFI.
  1833. **/
  1834. void
  1835. lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
  1836. {
  1837. memset(mbox, 0, sizeof(*mbox));
  1838. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
  1839. bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
  1840. }
  1841. /**
  1842. * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
  1843. * @mbox: pointer to lpfc mbox command to initialize.
  1844. * @ndlp: The nodelist structure that describes the RPI to resume.
  1845. *
  1846. * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
  1847. * link event.
  1848. **/
  1849. void
  1850. lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
  1851. {
  1852. struct lpfc_mbx_resume_rpi *resume_rpi;
  1853. memset(mbox, 0, sizeof(*mbox));
  1854. resume_rpi = &mbox->u.mqe.un.resume_rpi;
  1855. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
  1856. bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi);
  1857. bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
  1858. resume_rpi->event_tag = ndlp->phba->fc_eventTag;
  1859. }
  1860. /**
  1861. * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
  1862. * mailbox command.
  1863. * @mbox: pointer to lpfc mbox command to initialize.
  1864. *
  1865. * The PORT_CAPABILITIES supported pages mailbox command is issued to
  1866. * retrieve the particular feature pages supported by the port.
  1867. **/
  1868. void
  1869. lpfc_supported_pages(struct lpfcMboxq *mbox)
  1870. {
  1871. struct lpfc_mbx_supp_pages *supp_pages;
  1872. memset(mbox, 0, sizeof(*mbox));
  1873. supp_pages = &mbox->u.mqe.un.supp_pages;
  1874. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
  1875. bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
  1876. }
  1877. /**
  1878. * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
  1879. * mailbox command.
  1880. * @mbox: pointer to lpfc mbox command to initialize.
  1881. *
  1882. * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
  1883. * retrieve the particular SLI4 features supported by the port.
  1884. **/
  1885. void
  1886. lpfc_sli4_params(struct lpfcMboxq *mbox)
  1887. {
  1888. struct lpfc_mbx_sli4_params *sli4_params;
  1889. memset(mbox, 0, sizeof(*mbox));
  1890. sli4_params = &mbox->u.mqe.un.sli4_params;
  1891. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
  1892. bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
  1893. }