lpfc_mbox.c 76 KB

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