lpfc_mbox.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/fc/fc_fs.h>
  31. #include "lpfc_hw4.h"
  32. #include "lpfc_hw.h"
  33. #include "lpfc_sli.h"
  34. #include "lpfc_sli4.h"
  35. #include "lpfc_nl.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_compat.h"
  42. /**
  43. * lpfc_mbox_rsrc_prep - Prepare a mailbox with DMA buffer memory.
  44. * @phba: pointer to lpfc hba data structure.
  45. * @mbox: pointer to the driver internal queue element for mailbox command.
  46. *
  47. * A mailbox command consists of the pool memory for the command, @mbox, and
  48. * one or more DMA buffers for the data transfer. This routine provides
  49. * a standard framework for allocating the dma buffer and assigning to the
  50. * @mbox. Callers should cleanup the mbox with a call to
  51. * lpfc_mbox_rsrc_cleanup.
  52. *
  53. * The lpfc_mbuf_alloc routine acquires the hbalock so the caller is
  54. * responsible to ensure the hbalock is released. Also note that the
  55. * driver design is a single dmabuf/mbuf per mbox in the ctx_buf.
  56. *
  57. **/
  58. int
  59. lpfc_mbox_rsrc_prep(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  60. {
  61. struct lpfc_dmabuf *mp;
  62. mp = kmalloc(sizeof(*mp), GFP_KERNEL);
  63. if (!mp)
  64. return -ENOMEM;
  65. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  66. if (!mp->virt) {
  67. kfree(mp);
  68. return -ENOMEM;
  69. }
  70. memset(mp->virt, 0, LPFC_BPL_SIZE);
  71. /* Initialization only. Driver does not use a list of dmabufs. */
  72. INIT_LIST_HEAD(&mp->list);
  73. mbox->ctx_buf = mp;
  74. return 0;
  75. }
  76. /**
  77. * lpfc_mbox_rsrc_cleanup - Free the mailbox DMA buffer and virtual memory.
  78. * @phba: pointer to lpfc hba data structure.
  79. * @mbox: pointer to the driver internal queue element for mailbox command.
  80. * @locked: value that indicates if the hbalock is held (1) or not (0).
  81. *
  82. * A mailbox command consists of the pool memory for the command, @mbox, and
  83. * possibly a DMA buffer for the data transfer. This routine provides
  84. * a standard framework for releasing any dma buffers and freeing all
  85. * memory resources in it as well as releasing the @mbox back to the @phba pool.
  86. * Callers should use this routine for cleanup for all mailboxes prepped with
  87. * lpfc_mbox_rsrc_prep.
  88. *
  89. **/
  90. void
  91. lpfc_mbox_rsrc_cleanup(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
  92. enum lpfc_mbox_ctx locked)
  93. {
  94. struct lpfc_dmabuf *mp;
  95. mp = mbox->ctx_buf;
  96. mbox->ctx_buf = NULL;
  97. /* Release the generic BPL buffer memory. */
  98. if (mp) {
  99. if (locked == MBOX_THD_LOCKED)
  100. __lpfc_mbuf_free(phba, mp->virt, mp->phys);
  101. else
  102. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  103. kfree(mp);
  104. }
  105. mempool_free(mbox, phba->mbox_mem_pool);
  106. }
  107. /**
  108. * lpfc_dump_static_vport - Dump HBA's static vport information.
  109. * @phba: pointer to lpfc hba data structure.
  110. * @pmb: pointer to the driver internal queue element for mailbox command.
  111. * @offset: offset for dumping vport info.
  112. *
  113. * The dump mailbox command provides a method for the device driver to obtain
  114. * various types of information from the HBA device.
  115. *
  116. * This routine prepares the mailbox command for dumping list of static
  117. * vports to be created.
  118. **/
  119. int
  120. lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
  121. uint16_t offset)
  122. {
  123. MAILBOX_t *mb;
  124. struct lpfc_dmabuf *mp;
  125. int rc;
  126. mb = &pmb->u.mb;
  127. /* Setup to dump vport info region */
  128. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  129. mb->mbxCommand = MBX_DUMP_MEMORY;
  130. mb->un.varDmp.type = DMP_NV_PARAMS;
  131. mb->un.varDmp.entry_index = offset;
  132. mb->un.varDmp.region_id = DMP_REGION_VPORT;
  133. mb->mbxOwner = OWN_HOST;
  134. /* For SLI3 HBAs data is embedded in mailbox */
  135. if (phba->sli_rev != LPFC_SLI_REV4) {
  136. mb->un.varDmp.cv = 1;
  137. mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
  138. return 0;
  139. }
  140. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  141. if (rc) {
  142. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  143. "2605 %s: memory allocation failed\n",
  144. __func__);
  145. return 1;
  146. }
  147. mp = pmb->ctx_buf;
  148. mb->un.varWords[3] = putPaddrLow(mp->phys);
  149. mb->un.varWords[4] = putPaddrHigh(mp->phys);
  150. mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
  151. return 0;
  152. }
  153. /**
  154. * lpfc_down_link - Bring down HBAs link.
  155. * @phba: pointer to lpfc hba data structure.
  156. * @pmb: pointer to the driver internal queue element for mailbox command.
  157. *
  158. * This routine prepares a mailbox command to bring down HBA link.
  159. **/
  160. void
  161. lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  162. {
  163. MAILBOX_t *mb;
  164. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  165. mb = &pmb->u.mb;
  166. mb->mbxCommand = MBX_DOWN_LINK;
  167. mb->mbxOwner = OWN_HOST;
  168. }
  169. /**
  170. * lpfc_dump_mem - Prepare a mailbox command for reading a region.
  171. * @phba: pointer to lpfc hba data structure.
  172. * @pmb: pointer to the driver internal queue element for mailbox command.
  173. * @offset: offset into the region.
  174. * @region_id: config region id.
  175. *
  176. * The dump mailbox command provides a method for the device driver to obtain
  177. * various types of information from the HBA device.
  178. *
  179. * This routine prepares the mailbox command for dumping HBA's config region.
  180. **/
  181. void
  182. lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
  183. uint16_t region_id)
  184. {
  185. MAILBOX_t *mb;
  186. mb = &pmb->u.mb;
  187. /* Setup to dump VPD region */
  188. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  189. mb->mbxCommand = MBX_DUMP_MEMORY;
  190. mb->un.varDmp.cv = 1;
  191. mb->un.varDmp.type = DMP_NV_PARAMS;
  192. mb->un.varDmp.entry_index = offset;
  193. mb->un.varDmp.region_id = region_id;
  194. mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
  195. mb->un.varDmp.co = 0;
  196. mb->un.varDmp.resp_offset = 0;
  197. mb->mbxOwner = OWN_HOST;
  198. return;
  199. }
  200. /**
  201. * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
  202. * @phba: pointer to lpfc hba data structure.
  203. * @pmb: pointer to the driver internal queue element for mailbox command.
  204. *
  205. * This function create a dump memory mailbox command to dump wake up
  206. * parameters.
  207. */
  208. void
  209. lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  210. {
  211. MAILBOX_t *mb;
  212. mb = &pmb->u.mb;
  213. /* Setup to dump VPD region */
  214. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  215. mb->mbxCommand = MBX_DUMP_MEMORY;
  216. mb->mbxOwner = OWN_HOST;
  217. mb->un.varDmp.cv = 1;
  218. mb->un.varDmp.type = DMP_NV_PARAMS;
  219. if (phba->sli_rev < LPFC_SLI_REV4)
  220. mb->un.varDmp.entry_index = 0;
  221. mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
  222. mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
  223. mb->un.varDmp.co = 0;
  224. mb->un.varDmp.resp_offset = 0;
  225. return;
  226. }
  227. /**
  228. * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
  229. * @phba: pointer to lpfc hba data structure.
  230. * @pmb: pointer to the driver internal queue element for mailbox command.
  231. *
  232. * The read NVRAM mailbox command returns the HBA's non-volatile parameters
  233. * that are used as defaults when the Fibre Channel link is brought on-line.
  234. *
  235. * This routine prepares the mailbox command for reading information stored
  236. * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
  237. **/
  238. void
  239. lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  240. {
  241. MAILBOX_t *mb;
  242. mb = &pmb->u.mb;
  243. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  244. mb->mbxCommand = MBX_READ_NV;
  245. mb->mbxOwner = OWN_HOST;
  246. return;
  247. }
  248. /**
  249. * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
  250. * @phba: pointer to lpfc hba data structure.
  251. * @pmb: pointer to the driver internal queue element for mailbox command.
  252. * @ring: ring number for the asynchronous event to be configured.
  253. *
  254. * The asynchronous event enable mailbox command is used to enable the
  255. * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
  256. * specifies the default ring to which events are posted.
  257. *
  258. * This routine prepares the mailbox command for enabling HBA asynchronous
  259. * event support on a IOCB ring.
  260. **/
  261. void
  262. lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
  263. uint32_t ring)
  264. {
  265. MAILBOX_t *mb;
  266. mb = &pmb->u.mb;
  267. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  268. mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
  269. mb->un.varCfgAsyncEvent.ring = ring;
  270. mb->mbxOwner = OWN_HOST;
  271. return;
  272. }
  273. /**
  274. * lpfc_heart_beat - Prepare a mailbox command for heart beat
  275. * @phba: pointer to lpfc hba data structure.
  276. * @pmb: pointer to the driver internal queue element for mailbox command.
  277. *
  278. * The heart beat mailbox command is used to detect an unresponsive HBA, which
  279. * is defined as any device where no error attention is sent and both mailbox
  280. * and rings are not processed.
  281. *
  282. * This routine prepares the mailbox command for issuing a heart beat in the
  283. * form of mailbox command to the HBA. The timely completion of the heart
  284. * beat mailbox command indicates the health of the HBA.
  285. **/
  286. void
  287. lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  288. {
  289. MAILBOX_t *mb;
  290. mb = &pmb->u.mb;
  291. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  292. mb->mbxCommand = MBX_HEARTBEAT;
  293. mb->mbxOwner = OWN_HOST;
  294. return;
  295. }
  296. /**
  297. * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
  298. * @phba: pointer to lpfc hba data structure.
  299. * @pmb: pointer to the driver internal queue element for mailbox command.
  300. * @mp: DMA buffer memory for reading the link attention information into.
  301. *
  302. * The read topology mailbox command is issued to read the link topology
  303. * information indicated by the HBA port when the Link Event bit of the Host
  304. * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
  305. * Attention ACQE is received from the port (For SLI-4). A Link Event
  306. * Attention occurs based on an exception detected at the Fibre Channel link
  307. * interface.
  308. *
  309. * This routine prepares the mailbox command for reading HBA link topology
  310. * information. A DMA memory has been set aside and address passed to the
  311. * HBA through @mp for the HBA to DMA link attention information into the
  312. * memory as part of the execution of the mailbox command.
  313. *
  314. * Return codes
  315. * 0 - Success (currently always return 0)
  316. **/
  317. int
  318. lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
  319. struct lpfc_dmabuf *mp)
  320. {
  321. MAILBOX_t *mb;
  322. mb = &pmb->u.mb;
  323. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  324. INIT_LIST_HEAD(&mp->list);
  325. mb->mbxCommand = MBX_READ_TOPOLOGY;
  326. mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
  327. mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  328. mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
  329. /* Save address for later completion and set the owner to host so that
  330. * the FW knows this mailbox is available for processing.
  331. */
  332. pmb->ctx_buf = mp;
  333. mb->mbxOwner = OWN_HOST;
  334. return (0);
  335. }
  336. /**
  337. * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
  338. * @phba: pointer to lpfc hba data structure.
  339. * @pmb: pointer to the driver internal queue element for mailbox command.
  340. *
  341. * The clear link attention mailbox command is issued to clear the link event
  342. * attention condition indicated by the Link Event bit of the Host Attention
  343. * (HSTATT) register. The link event attention condition is cleared only if
  344. * the event tag specified matches that of the current link event counter.
  345. * The current event tag is read using the read link attention event mailbox
  346. * command.
  347. *
  348. * This routine prepares the mailbox command for clearing HBA link attention
  349. * information.
  350. **/
  351. void
  352. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  353. {
  354. MAILBOX_t *mb;
  355. mb = &pmb->u.mb;
  356. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  357. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  358. mb->mbxCommand = MBX_CLEAR_LA;
  359. mb->mbxOwner = OWN_HOST;
  360. return;
  361. }
  362. /**
  363. * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
  364. * @phba: pointer to lpfc hba data structure.
  365. * @pmb: pointer to the driver internal queue element for mailbox command.
  366. *
  367. * The configure link mailbox command is used before the initialize link
  368. * mailbox command to override default value and to configure link-oriented
  369. * parameters such as DID address and various timers. Typically, this
  370. * command would be used after an F_Port login to set the returned DID address
  371. * and the fabric timeout values. This command is not valid before a configure
  372. * port command has configured the HBA port.
  373. *
  374. * This routine prepares the mailbox command for configuring link on a HBA.
  375. **/
  376. void
  377. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  378. {
  379. struct lpfc_vport *vport = phba->pport;
  380. MAILBOX_t *mb = &pmb->u.mb;
  381. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  382. /* NEW_FEATURE
  383. * SLI-2, Coalescing Response Feature.
  384. */
  385. if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
  386. mb->un.varCfgLnk.cr = 1;
  387. mb->un.varCfgLnk.ci = 1;
  388. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  389. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  390. }
  391. mb->un.varCfgLnk.myId = vport->fc_myDID;
  392. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  393. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  394. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  395. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  396. mb->un.varCfgLnk.altov = phba->fc_altov;
  397. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  398. mb->un.varCfgLnk.cscn = 0;
  399. if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
  400. mb->un.varCfgLnk.cscn = 1;
  401. mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def,
  402. &phba->sli4_hba.bbscn_params);
  403. }
  404. if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
  405. mb->un.varCfgLnk.ack0_enable = 1;
  406. mb->mbxCommand = MBX_CONFIG_LINK;
  407. mb->mbxOwner = OWN_HOST;
  408. return;
  409. }
  410. /**
  411. * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
  412. * @phba: pointer to lpfc hba data structure.
  413. * @pmb: pointer to the driver internal queue element for mailbox command.
  414. *
  415. * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
  416. * MSI-X multi-message interrupt vector association to interrupt attention
  417. * conditions.
  418. *
  419. * Return codes
  420. * 0 - Success
  421. * -EINVAL - Failure
  422. **/
  423. int
  424. lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  425. {
  426. MAILBOX_t *mb = &pmb->u.mb;
  427. uint32_t attentionConditions[2];
  428. /* Sanity check */
  429. if (phba->cfg_use_msi != 2) {
  430. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  431. "0475 Not configured for supporting MSI-X "
  432. "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
  433. return -EINVAL;
  434. }
  435. if (phba->sli_rev < 3) {
  436. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  437. "0476 HBA not supporting SLI-3 or later "
  438. "SLI Revision: 0x%x\n", phba->sli_rev);
  439. return -EINVAL;
  440. }
  441. /* Clear mailbox command fields */
  442. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  443. /*
  444. * SLI-3, Message Signaled Interrupt Feature.
  445. */
  446. /* Multi-message attention configuration */
  447. attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
  448. HA_LATT | HA_MBATT);
  449. attentionConditions[1] = 0;
  450. mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
  451. mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
  452. /*
  453. * Set up message number to HA bit association
  454. */
  455. #ifdef __BIG_ENDIAN_BITFIELD
  456. /* RA0 (FCP Ring) */
  457. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
  458. /* RA1 (Other Protocol Extra Ring) */
  459. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
  460. #else /* __LITTLE_ENDIAN_BITFIELD */
  461. /* RA0 (FCP Ring) */
  462. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
  463. /* RA1 (Other Protocol Extra Ring) */
  464. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
  465. #endif
  466. /* Multi-message interrupt autoclear configuration*/
  467. mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
  468. mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
  469. /* For now, HBA autoclear does not work reliably, disable it */
  470. mb->un.varCfgMSI.autoClearHA[0] = 0;
  471. mb->un.varCfgMSI.autoClearHA[1] = 0;
  472. /* Set command and owner bit */
  473. mb->mbxCommand = MBX_CONFIG_MSI;
  474. mb->mbxOwner = OWN_HOST;
  475. return 0;
  476. }
  477. /**
  478. * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
  479. * @phba: pointer to lpfc hba data structure.
  480. * @pmb: pointer to the driver internal queue element for mailbox command.
  481. * @topology: the link topology for the link to be initialized to.
  482. * @linkspeed: the link speed for the link to be initialized to.
  483. *
  484. * The initialize link mailbox command is used to initialize the Fibre
  485. * Channel link. This command must follow a configure port command that
  486. * establishes the mode of operation.
  487. *
  488. * This routine prepares the mailbox command for initializing link on a HBA
  489. * with the specified link topology and speed.
  490. **/
  491. void
  492. lpfc_init_link(struct lpfc_hba * phba,
  493. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  494. {
  495. lpfc_vpd_t *vpd;
  496. MAILBOX_t *mb;
  497. mb = &pmb->u.mb;
  498. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  499. switch (topology) {
  500. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  501. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  502. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  503. break;
  504. case FLAGS_TOPOLOGY_MODE_PT_PT:
  505. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  506. break;
  507. case FLAGS_TOPOLOGY_MODE_LOOP:
  508. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  509. break;
  510. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  511. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  512. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  513. break;
  514. case FLAGS_LOCAL_LB:
  515. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  516. break;
  517. }
  518. /* Topology handling for ASIC_GEN_NUM 0xC and later */
  519. if ((phba->sli4_hba.pc_sli4_params.sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
  520. phba->sli4_hba.pc_sli4_params.if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
  521. !(phba->sli4_hba.pc_sli4_params.pls) &&
  522. mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
  523. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  524. phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
  525. }
  526. /* Enable asynchronous ABTS responses from firmware */
  527. if (phba->sli_rev == LPFC_SLI_REV3 && !phba->cfg_fcp_wait_abts_rsp)
  528. mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
  529. /* NEW_FEATURE
  530. * Setting up the link speed
  531. */
  532. vpd = &phba->vpd;
  533. if (vpd->rev.feaLevelHigh >= 0x02){
  534. switch(linkspeed){
  535. case LPFC_USER_LINK_SPEED_1G:
  536. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  537. mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
  538. break;
  539. case LPFC_USER_LINK_SPEED_2G:
  540. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  541. mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
  542. break;
  543. case LPFC_USER_LINK_SPEED_4G:
  544. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  545. mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
  546. break;
  547. case LPFC_USER_LINK_SPEED_8G:
  548. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  549. mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
  550. break;
  551. case LPFC_USER_LINK_SPEED_10G:
  552. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  553. mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
  554. break;
  555. case LPFC_USER_LINK_SPEED_16G:
  556. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  557. mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
  558. break;
  559. case LPFC_USER_LINK_SPEED_32G:
  560. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  561. mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
  562. break;
  563. case LPFC_USER_LINK_SPEED_64G:
  564. mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
  565. mb->un.varInitLnk.link_speed = LINK_SPEED_64G;
  566. break;
  567. case LPFC_USER_LINK_SPEED_AUTO:
  568. default:
  569. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  570. break;
  571. }
  572. }
  573. else
  574. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  575. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  576. mb->mbxOwner = OWN_HOST;
  577. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  578. return;
  579. }
  580. /**
  581. * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
  582. * @phba: pointer to lpfc hba data structure.
  583. * @pmb: pointer to the driver internal queue element for mailbox command.
  584. * @vpi: virtual N_Port identifier.
  585. *
  586. * The read service parameter mailbox command is used to read the HBA port
  587. * service parameters. The service parameters are read into the buffer
  588. * specified directly by a BDE in the mailbox command. These service
  589. * parameters may then be used to build the payload of an N_Port/F_POrt
  590. * login request and reply (LOGI/ACC).
  591. *
  592. * This routine prepares the mailbox command for reading HBA port service
  593. * parameters. The DMA memory is allocated in this function and the addresses
  594. * are populated into the mailbox command for the HBA to DMA the service
  595. * parameters into.
  596. *
  597. * Return codes
  598. * 0 - Success
  599. * 1 - DMA memory allocation failed
  600. **/
  601. int
  602. lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
  603. {
  604. struct lpfc_dmabuf *mp;
  605. MAILBOX_t *mb;
  606. int rc;
  607. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  608. /* Get a buffer to hold the HBAs Service Parameters */
  609. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  610. if (rc) {
  611. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  612. "0301 READ_SPARAM: no buffers\n");
  613. return 1;
  614. }
  615. mp = pmb->ctx_buf;
  616. mb = &pmb->u.mb;
  617. mb->mbxOwner = OWN_HOST;
  618. mb->mbxCommand = MBX_READ_SPARM64;
  619. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  620. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  621. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  622. if (phba->sli_rev >= LPFC_SLI_REV3)
  623. mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
  624. return (0);
  625. }
  626. /**
  627. * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
  628. * @phba: pointer to lpfc hba data structure.
  629. * @vpi: virtual N_Port identifier.
  630. * @did: remote port identifier.
  631. * @pmb: pointer to the driver internal queue element for mailbox command.
  632. *
  633. * The unregister DID mailbox command is used to unregister an N_Port/F_Port
  634. * login for an unknown RPI by specifying the DID of a remote port. This
  635. * command frees an RPI context in the HBA port. This has the effect of
  636. * performing an implicit N_Port/F_Port logout.
  637. *
  638. * This routine prepares the mailbox command for unregistering a remote
  639. * N_Port/F_Port (DID) login.
  640. **/
  641. void
  642. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  643. LPFC_MBOXQ_t * pmb)
  644. {
  645. MAILBOX_t *mb;
  646. mb = &pmb->u.mb;
  647. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  648. mb->un.varUnregDID.did = did;
  649. mb->un.varUnregDID.vpi = vpi;
  650. if ((vpi != 0xffff) &&
  651. (phba->sli_rev == LPFC_SLI_REV4))
  652. mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
  653. mb->mbxCommand = MBX_UNREG_D_ID;
  654. mb->mbxOwner = OWN_HOST;
  655. return;
  656. }
  657. /**
  658. * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
  659. * @phba: pointer to lpfc hba data structure.
  660. * @pmb: pointer to the driver internal queue element for mailbox command.
  661. *
  662. * The read configuration mailbox command is used to read the HBA port
  663. * configuration parameters. This mailbox command provides a method for
  664. * seeing any parameters that may have changed via various configuration
  665. * mailbox commands.
  666. *
  667. * This routine prepares the mailbox command for reading out HBA configuration
  668. * parameters.
  669. **/
  670. void
  671. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  672. {
  673. MAILBOX_t *mb;
  674. mb = &pmb->u.mb;
  675. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  676. mb->mbxCommand = MBX_READ_CONFIG;
  677. mb->mbxOwner = OWN_HOST;
  678. return;
  679. }
  680. /**
  681. * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
  682. * @phba: pointer to lpfc hba data structure.
  683. * @pmb: pointer to the driver internal queue element for mailbox command.
  684. *
  685. * The read link status mailbox command is used to read the link status from
  686. * the HBA. Link status includes all link-related error counters. These
  687. * counters are maintained by the HBA and originated in the link hardware
  688. * unit. Note that all of these counters wrap.
  689. *
  690. * This routine prepares the mailbox command for reading out HBA link status.
  691. **/
  692. void
  693. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  694. {
  695. MAILBOX_t *mb;
  696. mb = &pmb->u.mb;
  697. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  698. mb->mbxCommand = MBX_READ_LNK_STAT;
  699. mb->mbxOwner = OWN_HOST;
  700. return;
  701. }
  702. /**
  703. * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
  704. * @phba: pointer to lpfc hba data structure.
  705. * @vpi: virtual N_Port identifier.
  706. * @did: remote port identifier.
  707. * @param: pointer to memory holding the server parameters.
  708. * @pmb: pointer to the driver internal queue element for mailbox command.
  709. * @rpi: the rpi to use in the registration (usually only used for SLI4.
  710. *
  711. * The registration login mailbox command is used to register an N_Port or
  712. * F_Port login. This registration allows the HBA to cache the remote N_Port
  713. * service parameters internally and thereby make the appropriate FC-2
  714. * decisions. The remote port service parameters are handed off by the driver
  715. * to the HBA using a descriptor entry that directly identifies a buffer in
  716. * host memory. In exchange, the HBA returns an RPI identifier.
  717. *
  718. * This routine prepares the mailbox command for registering remote port login.
  719. * The function allocates DMA buffer for passing the service parameters to the
  720. * HBA with the mailbox command.
  721. *
  722. * Return codes
  723. * 0 - Success
  724. * 1 - DMA memory allocation failed
  725. **/
  726. int
  727. lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  728. uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
  729. {
  730. MAILBOX_t *mb = &pmb->u.mb;
  731. uint8_t *sparam;
  732. struct lpfc_dmabuf *mp;
  733. int rc;
  734. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  735. mb->un.varRegLogin.rpi = 0;
  736. if (phba->sli_rev == LPFC_SLI_REV4)
  737. mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
  738. if (phba->sli_rev >= LPFC_SLI_REV3)
  739. mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
  740. mb->un.varRegLogin.did = did;
  741. mb->mbxOwner = OWN_HOST;
  742. /* Get a buffer to hold NPorts Service Parameters */
  743. rc = lpfc_mbox_rsrc_prep(phba, pmb);
  744. if (rc) {
  745. mb->mbxCommand = MBX_REG_LOGIN64;
  746. /* REG_LOGIN: no buffers */
  747. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  748. "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
  749. "rpi x%x\n", vpi, did, rpi);
  750. return 1;
  751. }
  752. /* Copy param's into a new buffer */
  753. mp = pmb->ctx_buf;
  754. sparam = mp->virt;
  755. memcpy(sparam, param, sizeof (struct serv_parm));
  756. /* Finish initializing the mailbox. */
  757. mb->mbxCommand = MBX_REG_LOGIN64;
  758. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  759. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  760. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  761. return 0;
  762. }
  763. /**
  764. * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
  765. * @phba: pointer to lpfc hba data structure.
  766. * @vpi: virtual N_Port identifier.
  767. * @rpi: remote port identifier
  768. * @pmb: pointer to the driver internal queue element for mailbox command.
  769. *
  770. * The unregistration login mailbox command is used to unregister an N_Port
  771. * or F_Port login. This command frees an RPI context in the HBA. It has the
  772. * effect of performing an implicit N_Port/F_Port logout.
  773. *
  774. * This routine prepares the mailbox command for unregistering remote port
  775. * login.
  776. *
  777. * For SLI4 ports, the rpi passed to this function must be the physical
  778. * rpi value, not the logical index.
  779. **/
  780. void
  781. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  782. LPFC_MBOXQ_t * pmb)
  783. {
  784. MAILBOX_t *mb;
  785. mb = &pmb->u.mb;
  786. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  787. mb->un.varUnregLogin.rpi = rpi;
  788. mb->un.varUnregLogin.rsvd1 = 0;
  789. if (phba->sli_rev >= LPFC_SLI_REV3)
  790. mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
  791. mb->mbxCommand = MBX_UNREG_LOGIN;
  792. mb->mbxOwner = OWN_HOST;
  793. return;
  794. }
  795. /**
  796. * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
  797. * @vport: pointer to a vport object.
  798. *
  799. * This routine sends mailbox command to unregister all active RPIs for
  800. * a vport.
  801. **/
  802. void
  803. lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
  804. {
  805. struct lpfc_hba *phba = vport->phba;
  806. LPFC_MBOXQ_t *mbox;
  807. int rc;
  808. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  809. if (mbox) {
  810. /*
  811. * For SLI4 functions, the rpi field is overloaded for
  812. * the vport context unreg all. This routine passes
  813. * 0 for the rpi field in lpfc_unreg_login for compatibility
  814. * with SLI3 and then overrides the rpi field with the
  815. * expected value for SLI4.
  816. */
  817. lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
  818. mbox);
  819. mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
  820. mbox->vport = vport;
  821. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  822. mbox->ctx_ndlp = NULL;
  823. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  824. if (rc == MBX_NOT_FINISHED)
  825. mempool_free(mbox, phba->mbox_mem_pool);
  826. }
  827. }
  828. /**
  829. * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
  830. * @vport: pointer to a vport object.
  831. * @pmb: pointer to the driver internal queue element for mailbox command.
  832. *
  833. * The registration vport identifier mailbox command is used to activate a
  834. * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
  835. * N_Port_ID against the information in the selected virtual N_Port context
  836. * block and marks it active to allow normal processing of IOCB commands and
  837. * received unsolicited exchanges.
  838. *
  839. * This routine prepares the mailbox command for registering a virtual N_Port.
  840. **/
  841. void
  842. lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
  843. {
  844. MAILBOX_t *mb = &pmb->u.mb;
  845. struct lpfc_hba *phba = vport->phba;
  846. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  847. /*
  848. * Set the re-reg VPI bit for f/w to update the MAC address.
  849. */
  850. if ((phba->sli_rev == LPFC_SLI_REV4) &&
  851. !test_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag))
  852. mb->un.varRegVpi.upd = 1;
  853. mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
  854. mb->un.varRegVpi.sid = vport->fc_myDID;
  855. if (phba->sli_rev == LPFC_SLI_REV4)
  856. mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
  857. else
  858. mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
  859. memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
  860. sizeof(struct lpfc_name));
  861. mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
  862. mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
  863. mb->mbxCommand = MBX_REG_VPI;
  864. mb->mbxOwner = OWN_HOST;
  865. return;
  866. }
  867. /**
  868. * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
  869. * @phba: pointer to lpfc hba data structure.
  870. * @vpi: virtual N_Port identifier.
  871. * @pmb: pointer to the driver internal queue element for mailbox command.
  872. *
  873. * The unregistration vport identifier mailbox command is used to inactivate
  874. * a virtual N_Port. The driver must have logged out and unregistered all
  875. * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
  876. * unregisters any default RPIs associated with the specified vpi, aborting
  877. * any active exchanges. The HBA will post the mailbox response after making
  878. * the virtual N_Port inactive.
  879. *
  880. * This routine prepares the mailbox command for unregistering a virtual
  881. * N_Port.
  882. **/
  883. void
  884. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  885. {
  886. MAILBOX_t *mb = &pmb->u.mb;
  887. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  888. if (phba->sli_rev == LPFC_SLI_REV3)
  889. mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
  890. else if (phba->sli_rev >= LPFC_SLI_REV4)
  891. mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
  892. mb->mbxCommand = MBX_UNREG_VPI;
  893. mb->mbxOwner = OWN_HOST;
  894. return;
  895. }
  896. /**
  897. * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
  898. * @phba: pointer to lpfc hba data structure.
  899. *
  900. * This routine sets up and initializes the IOCB rings in the Port Control
  901. * Block (PCB).
  902. **/
  903. static void
  904. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  905. {
  906. struct lpfc_sli *psli = &phba->sli;
  907. struct lpfc_sli_ring *pring;
  908. PCB_t *pcbp = phba->pcb;
  909. dma_addr_t pdma_addr;
  910. uint32_t offset;
  911. uint32_t iocbCnt = 0;
  912. int i;
  913. pcbp->maxRing = (psli->num_rings - 1);
  914. for (i = 0; i < psli->num_rings; i++) {
  915. pring = &psli->sli3_ring[i];
  916. pring->sli.sli3.sizeCiocb =
  917. phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
  918. SLI2_IOCB_CMD_SIZE;
  919. pring->sli.sli3.sizeRiocb =
  920. phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
  921. SLI2_IOCB_RSP_SIZE;
  922. /* A ring MUST have both cmd and rsp entries defined to be
  923. valid */
  924. if ((pring->sli.sli3.numCiocb == 0) ||
  925. (pring->sli.sli3.numRiocb == 0)) {
  926. pcbp->rdsc[i].cmdEntries = 0;
  927. pcbp->rdsc[i].rspEntries = 0;
  928. pcbp->rdsc[i].cmdAddrHigh = 0;
  929. pcbp->rdsc[i].rspAddrHigh = 0;
  930. pcbp->rdsc[i].cmdAddrLow = 0;
  931. pcbp->rdsc[i].rspAddrLow = 0;
  932. pring->sli.sli3.cmdringaddr = NULL;
  933. pring->sli.sli3.rspringaddr = NULL;
  934. continue;
  935. }
  936. /* Command ring setup for ring */
  937. pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
  938. pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
  939. offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
  940. (uint8_t *) phba->slim2p.virt;
  941. pdma_addr = phba->slim2p.phys + offset;
  942. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  943. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  944. iocbCnt += pring->sli.sli3.numCiocb;
  945. /* Response ring setup for ring */
  946. pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
  947. pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
  948. offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
  949. (uint8_t *)phba->slim2p.virt;
  950. pdma_addr = phba->slim2p.phys + offset;
  951. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  952. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  953. iocbCnt += pring->sli.sli3.numRiocb;
  954. }
  955. }
  956. /**
  957. * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
  958. * @phba: pointer to lpfc hba data structure.
  959. * @pmb: pointer to the driver internal queue element for mailbox command.
  960. *
  961. * The read revision mailbox command is used to read the revision levels of
  962. * the HBA components. These components include hardware units, resident
  963. * firmware, and available firmware. HBAs that supports SLI-3 mode of
  964. * operation provide different response information depending on the version
  965. * requested by the driver.
  966. *
  967. * This routine prepares the mailbox command for reading HBA revision
  968. * information.
  969. **/
  970. void
  971. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  972. {
  973. MAILBOX_t *mb = &pmb->u.mb;
  974. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  975. mb->un.varRdRev.cv = 1;
  976. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  977. mb->mbxCommand = MBX_READ_REV;
  978. mb->mbxOwner = OWN_HOST;
  979. return;
  980. }
  981. void
  982. lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  983. {
  984. MAILBOX_t *mb = &pmb->u.mb;
  985. struct lpfc_mqe *mqe;
  986. switch (mb->mbxCommand) {
  987. case MBX_READ_REV:
  988. mqe = &pmb->u.mqe;
  989. lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
  990. mqe->un.read_rev.fw_name, 16);
  991. lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
  992. mqe->un.read_rev.ulp_fw_name, 16);
  993. break;
  994. default:
  995. break;
  996. }
  997. return;
  998. }
  999. /**
  1000. * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
  1001. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  1002. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  1003. *
  1004. * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
  1005. * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
  1006. * the Sequence Length Test using the fields in the Selection Profile 2
  1007. * extension in words 20:31.
  1008. **/
  1009. static void
  1010. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  1011. struct lpfc_hbq_init *hbq_desc)
  1012. {
  1013. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  1014. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  1015. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  1016. }
  1017. /**
  1018. * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
  1019. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  1020. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  1021. *
  1022. * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
  1023. * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
  1024. * the Sequence Length Test and Byte Field Test using the fields in the
  1025. * Selection Profile 3 extension in words 20:31.
  1026. **/
  1027. static void
  1028. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  1029. struct lpfc_hbq_init *hbq_desc)
  1030. {
  1031. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  1032. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  1033. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  1034. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  1035. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  1036. sizeof(hbqmb->profiles.profile3.cmdmatch));
  1037. }
  1038. /**
  1039. * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
  1040. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  1041. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  1042. *
  1043. * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
  1044. * HBA tests the initial frame of an incoming sequence using the frame's
  1045. * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
  1046. * and Byte Field Test using the fields in the Selection Profile 5 extension
  1047. * words 20:31.
  1048. **/
  1049. static void
  1050. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  1051. struct lpfc_hbq_init *hbq_desc)
  1052. {
  1053. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  1054. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  1055. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  1056. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  1057. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  1058. sizeof(hbqmb->profiles.profile5.cmdmatch));
  1059. }
  1060. /**
  1061. * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
  1062. * @phba: pointer to lpfc hba data structure.
  1063. * @id: HBQ identifier.
  1064. * @hbq_desc: pointer to the HBA descriptor data structure.
  1065. * @hbq_entry_index: index of the HBQ entry data structures.
  1066. * @pmb: pointer to the driver internal queue element for mailbox command.
  1067. *
  1068. * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
  1069. * an HBQ. The configuration binds events that require buffers to a particular
  1070. * ring and HBQ based on a selection profile.
  1071. *
  1072. * This routine prepares the mailbox command for configuring an HBQ.
  1073. **/
  1074. void
  1075. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  1076. struct lpfc_hbq_init *hbq_desc,
  1077. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  1078. {
  1079. int i;
  1080. MAILBOX_t *mb = &pmb->u.mb;
  1081. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  1082. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  1083. hbqmb->hbqId = id;
  1084. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  1085. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  1086. * Notification */
  1087. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  1088. * # in words 0-19 */
  1089. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  1090. * 0 = all,
  1091. * 7 = logentry */
  1092. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  1093. * e.g. Ring0=b0001,
  1094. * ring2=b0100 */
  1095. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  1096. * or 5 */
  1097. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  1098. * HBQ will be used
  1099. * for LogEntry
  1100. * buffers */
  1101. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  1102. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  1103. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  1104. mb->mbxCommand = MBX_CONFIG_HBQ;
  1105. mb->mbxOwner = OWN_HOST;
  1106. /* Copy info for profiles 2,3,5. Other
  1107. * profiles this area is reserved
  1108. */
  1109. if (hbq_desc->profile == 2)
  1110. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  1111. else if (hbq_desc->profile == 3)
  1112. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  1113. else if (hbq_desc->profile == 5)
  1114. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  1115. /* Return if no rctl / type masks for this HBQ */
  1116. if (!hbq_desc->mask_count)
  1117. return;
  1118. /* Otherwise we setup specific rctl / type masks for this HBQ */
  1119. for (i = 0; i < hbq_desc->mask_count; i++) {
  1120. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  1121. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  1122. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  1123. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  1124. }
  1125. return;
  1126. }
  1127. /**
  1128. * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
  1129. * @phba: pointer to lpfc hba data structure.
  1130. * @ring: ring number/index
  1131. * @pmb: pointer to the driver internal queue element for mailbox command.
  1132. *
  1133. * The configure ring mailbox command is used to configure an IOCB ring. This
  1134. * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
  1135. * ring. This is used to map incoming sequences to a particular ring whose
  1136. * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
  1137. * attempt to configure a ring whose number is greater than the number
  1138. * specified in the Port Control Block (PCB). It is an error to issue the
  1139. * configure ring command more than once with the same ring number. The HBA
  1140. * returns an error if the driver attempts this.
  1141. *
  1142. * This routine prepares the mailbox command for configuring IOCB ring.
  1143. **/
  1144. void
  1145. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  1146. {
  1147. int i;
  1148. MAILBOX_t *mb = &pmb->u.mb;
  1149. struct lpfc_sli *psli;
  1150. struct lpfc_sli_ring *pring;
  1151. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  1152. mb->un.varCfgRing.ring = ring;
  1153. mb->un.varCfgRing.maxOrigXchg = 0;
  1154. mb->un.varCfgRing.maxRespXchg = 0;
  1155. mb->un.varCfgRing.recvNotify = 1;
  1156. psli = &phba->sli;
  1157. pring = &psli->sli3_ring[ring];
  1158. mb->un.varCfgRing.numMask = pring->num_mask;
  1159. mb->mbxCommand = MBX_CONFIG_RING;
  1160. mb->mbxOwner = OWN_HOST;
  1161. /* Is this ring configured for a specific profile */
  1162. if (pring->prt[0].profile) {
  1163. mb->un.varCfgRing.profile = pring->prt[0].profile;
  1164. return;
  1165. }
  1166. /* Otherwise we setup specific rctl / type masks for this ring */
  1167. for (i = 0; i < pring->num_mask; i++) {
  1168. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  1169. if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
  1170. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  1171. else
  1172. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  1173. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  1174. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  1175. }
  1176. return;
  1177. }
  1178. /**
  1179. * lpfc_config_port - Prepare a mailbox command for configuring port
  1180. * @phba: pointer to lpfc hba data structure.
  1181. * @pmb: pointer to the driver internal queue element for mailbox command.
  1182. *
  1183. * The configure port mailbox command is used to identify the Port Control
  1184. * Block (PCB) in the driver memory. After this command is issued, the
  1185. * driver must not access the mailbox in the HBA without first resetting
  1186. * the HBA. The HBA may copy the PCB information to internal storage for
  1187. * subsequent use; the driver can not change the PCB information unless it
  1188. * resets the HBA.
  1189. *
  1190. * This routine prepares the mailbox command for configuring port.
  1191. **/
  1192. void
  1193. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  1194. {
  1195. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  1196. MAILBOX_t *mb = &pmb->u.mb;
  1197. dma_addr_t pdma_addr;
  1198. uint32_t bar_low, bar_high;
  1199. size_t offset;
  1200. struct lpfc_hgp hgp;
  1201. int i;
  1202. uint32_t pgp_offset;
  1203. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1204. mb->mbxCommand = MBX_CONFIG_PORT;
  1205. mb->mbxOwner = OWN_HOST;
  1206. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  1207. offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
  1208. pdma_addr = phba->slim2p.phys + offset;
  1209. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  1210. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  1211. /* Always Host Group Pointer is in SLIM */
  1212. mb->un.varCfgPort.hps = 1;
  1213. /* If HBA supports SLI=3 ask for it */
  1214. if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
  1215. if (phba->cfg_enable_bg)
  1216. mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
  1217. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  1218. mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
  1219. mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
  1220. if (phba->max_vpi && phba->cfg_enable_npiv &&
  1221. phba->vpd.sli3Feat.cmv) {
  1222. mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
  1223. mb->un.varCfgPort.cmv = 1;
  1224. } else
  1225. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  1226. } else
  1227. phba->sli_rev = LPFC_SLI_REV2;
  1228. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  1229. /* If this is an SLI3 port, configure async status notification. */
  1230. if (phba->sli_rev == LPFC_SLI_REV3)
  1231. mb->un.varCfgPort.casabt = 1;
  1232. /* Now setup pcb */
  1233. phba->pcb->type = TYPE_NATIVE_SLI2;
  1234. phba->pcb->feature = FEATURE_INITIAL_SLI2;
  1235. /* Setup Mailbox pointers */
  1236. phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
  1237. offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
  1238. pdma_addr = phba->slim2p.phys + offset;
  1239. phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
  1240. phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
  1241. /*
  1242. * Setup Host Group ring pointer.
  1243. *
  1244. * For efficiency reasons, the ring get/put pointers can be
  1245. * placed in adapter memory (SLIM) rather than in host memory.
  1246. * This allows firmware to avoid PCI reads/writes when updating
  1247. * and checking pointers.
  1248. *
  1249. * The firmware recognizes the use of SLIM memory by comparing
  1250. * the address of the get/put pointers structure with that of
  1251. * the SLIM BAR (BAR0).
  1252. *
  1253. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  1254. * (the hardware's view of the base address), not the OS's
  1255. * value of pci_resource_start() as the OS value may be a cookie
  1256. * for ioremap/iomap.
  1257. */
  1258. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  1259. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  1260. /*
  1261. * Set up HGP - Port Memory
  1262. *
  1263. * The port expects the host get/put pointers to reside in memory
  1264. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  1265. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  1266. * words (0x40 bytes). This area is not reserved if HBQs are
  1267. * configured in SLI-3.
  1268. *
  1269. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  1270. * RR0Get 0xc4 0x84
  1271. * CR1Put 0xc8 0x88
  1272. * RR1Get 0xcc 0x8c
  1273. * CR2Put 0xd0 0x90
  1274. * RR2Get 0xd4 0x94
  1275. * CR3Put 0xd8 0x98
  1276. * RR3Get 0xdc 0x9c
  1277. *
  1278. * Reserved 0xa0-0xbf
  1279. * If HBQs configured:
  1280. * HBQ 0 Put ptr 0xc0
  1281. * HBQ 1 Put ptr 0xc4
  1282. * HBQ 2 Put ptr 0xc8
  1283. * ......
  1284. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  1285. *
  1286. */
  1287. if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
  1288. phba->host_gp = (struct lpfc_hgp __iomem *)
  1289. &phba->mbox->us.s2.host[0];
  1290. phba->hbq_put = NULL;
  1291. offset = (uint8_t *)&phba->mbox->us.s2.host -
  1292. (uint8_t *)phba->slim2p.virt;
  1293. pdma_addr = phba->slim2p.phys + offset;
  1294. phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
  1295. phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
  1296. } else {
  1297. /* Always Host Group Pointer is in SLIM */
  1298. mb->un.varCfgPort.hps = 1;
  1299. if (phba->sli_rev == 3) {
  1300. phba->host_gp = &mb_slim->us.s3.host[0];
  1301. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  1302. } else {
  1303. phba->host_gp = &mb_slim->us.s2.host[0];
  1304. phba->hbq_put = NULL;
  1305. }
  1306. /* mask off BAR0's flag bits 0 - 3 */
  1307. phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  1308. (void __iomem *)phba->host_gp -
  1309. (void __iomem *)phba->MBslimaddr;
  1310. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  1311. phba->pcb->hgpAddrHigh = bar_high;
  1312. else
  1313. phba->pcb->hgpAddrHigh = 0;
  1314. /* write HGP data to SLIM at the required longword offset */
  1315. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  1316. for (i = 0; i < phba->sli.num_rings; i++) {
  1317. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  1318. sizeof(*phba->host_gp));
  1319. }
  1320. }
  1321. /* Setup Port Group offset */
  1322. if (phba->sli_rev == 3)
  1323. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1324. mbx.us.s3_pgp.port);
  1325. else
  1326. pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
  1327. pdma_addr = phba->slim2p.phys + pgp_offset;
  1328. phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
  1329. phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
  1330. /* Use callback routine to setp rings in the pcb */
  1331. lpfc_config_pcb_setup(phba);
  1332. /* special handling for LC HBAs */
  1333. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  1334. uint32_t hbainit[5];
  1335. lpfc_hba_init(phba, hbainit);
  1336. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  1337. }
  1338. /* Swap PCB if needed */
  1339. lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
  1340. }
  1341. /**
  1342. * lpfc_kill_board - Prepare a mailbox command for killing board
  1343. * @phba: pointer to lpfc hba data structure.
  1344. * @pmb: pointer to the driver internal queue element for mailbox command.
  1345. *
  1346. * The kill board mailbox command is used to tell firmware to perform a
  1347. * graceful shutdown of a channel on a specified board to prepare for reset.
  1348. * When the kill board mailbox command is received, the ER3 bit is set to 1
  1349. * in the Host Status register and the ER Attention bit is set to 1 in the
  1350. * Host Attention register of the HBA function that received the kill board
  1351. * command.
  1352. *
  1353. * This routine prepares the mailbox command for killing the board in
  1354. * preparation for a graceful shutdown.
  1355. **/
  1356. void
  1357. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1358. {
  1359. MAILBOX_t *mb = &pmb->u.mb;
  1360. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1361. mb->mbxCommand = MBX_KILL_BOARD;
  1362. mb->mbxOwner = OWN_HOST;
  1363. return;
  1364. }
  1365. /**
  1366. * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
  1367. * @phba: pointer to lpfc hba data structure.
  1368. * @mbq: pointer to the driver internal queue element for mailbox command.
  1369. *
  1370. * Driver maintains a internal mailbox command queue implemented as a linked
  1371. * list. When a mailbox command is issued, it shall be put into the mailbox
  1372. * command queue such that they shall be processed orderly as HBA can process
  1373. * one mailbox command at a time.
  1374. **/
  1375. void
  1376. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1377. {
  1378. struct lpfc_sli *psli;
  1379. psli = &phba->sli;
  1380. list_add_tail(&mbq->list, &psli->mboxq);
  1381. psli->mboxq_cnt++;
  1382. return;
  1383. }
  1384. /**
  1385. * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
  1386. * @phba: pointer to lpfc hba data structure.
  1387. *
  1388. * Driver maintains a internal mailbox command queue implemented as a linked
  1389. * list. When a mailbox command is issued, it shall be put into the mailbox
  1390. * command queue such that they shall be processed orderly as HBA can process
  1391. * one mailbox command at a time. After HBA finished processing a mailbox
  1392. * command, the driver will remove a pending mailbox command from the head of
  1393. * the mailbox command queue and send to the HBA for processing.
  1394. *
  1395. * Return codes
  1396. * pointer to the driver internal queue element for mailbox command.
  1397. **/
  1398. LPFC_MBOXQ_t *
  1399. lpfc_mbox_get(struct lpfc_hba * phba)
  1400. {
  1401. LPFC_MBOXQ_t *mbq = NULL;
  1402. struct lpfc_sli *psli = &phba->sli;
  1403. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  1404. if (mbq)
  1405. psli->mboxq_cnt--;
  1406. return mbq;
  1407. }
  1408. /**
  1409. * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
  1410. * @phba: pointer to lpfc hba data structure.
  1411. * @mbq: pointer to the driver internal queue element for mailbox command.
  1412. *
  1413. * This routine put the completed mailbox command into the mailbox command
  1414. * complete list. This is the unlocked version of the routine. The mailbox
  1415. * complete list is used by the driver worker thread to process mailbox
  1416. * complete callback functions outside the driver interrupt handler.
  1417. **/
  1418. void
  1419. __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1420. {
  1421. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  1422. }
  1423. /**
  1424. * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
  1425. * @phba: pointer to lpfc hba data structure.
  1426. * @mbq: pointer to the driver internal queue element for mailbox command.
  1427. *
  1428. * This routine put the completed mailbox command into the mailbox command
  1429. * complete list. This is the locked version of the routine. The mailbox
  1430. * complete list is used by the driver worker thread to process mailbox
  1431. * complete callback functions outside the driver interrupt handler.
  1432. **/
  1433. void
  1434. lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
  1435. {
  1436. unsigned long iflag;
  1437. /* This function expects to be called from interrupt context */
  1438. spin_lock_irqsave(&phba->hbalock, iflag);
  1439. __lpfc_mbox_cmpl_put(phba, mbq);
  1440. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1441. return;
  1442. }
  1443. /**
  1444. * lpfc_mbox_cmd_check - Check the validality of a mailbox command
  1445. * @phba: pointer to lpfc hba data structure.
  1446. * @mboxq: pointer to the driver internal queue element for mailbox command.
  1447. *
  1448. * This routine is to check whether a mailbox command is valid to be issued.
  1449. * This check will be performed by both the mailbox issue API when a client
  1450. * is to issue a mailbox command to the mailbox transport.
  1451. *
  1452. * Return 0 - pass the check, -ENODEV - fail the check
  1453. **/
  1454. int
  1455. lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1456. {
  1457. /* Mailbox command that have a completion handler must also have a
  1458. * vport specified.
  1459. */
  1460. if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  1461. mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  1462. if (!mboxq->vport) {
  1463. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
  1464. "1814 Mbox x%x failed, no vport\n",
  1465. mboxq->u.mb.mbxCommand);
  1466. dump_stack();
  1467. return -ENODEV;
  1468. }
  1469. }
  1470. return 0;
  1471. }
  1472. /**
  1473. * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
  1474. * @phba: pointer to lpfc hba data structure.
  1475. *
  1476. * This routine is to check whether the HBA device is ready for posting a
  1477. * mailbox command. It is used by the mailbox transport API at the time the
  1478. * to post a mailbox command to the device.
  1479. *
  1480. * Return 0 - pass the check, -ENODEV - fail the check
  1481. **/
  1482. int
  1483. lpfc_mbox_dev_check(struct lpfc_hba *phba)
  1484. {
  1485. /* If the PCI channel is in offline state, do not issue mbox */
  1486. if (unlikely(pci_channel_offline(phba->pcidev)))
  1487. return -ENODEV;
  1488. /* If the HBA is in error state, do not issue mbox */
  1489. if (phba->link_state == LPFC_HBA_ERROR)
  1490. return -ENODEV;
  1491. return 0;
  1492. }
  1493. /**
  1494. * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
  1495. * @phba: pointer to lpfc hba data structure.
  1496. * @mboxq: pointer to the driver internal queue element for mailbox command.
  1497. *
  1498. * This routine retrieves the proper timeout value according to the mailbox
  1499. * command code.
  1500. *
  1501. * Return codes
  1502. * Timeout value to be used for the given mailbox command
  1503. **/
  1504. int
  1505. lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  1506. {
  1507. MAILBOX_t *mbox = &mboxq->u.mb;
  1508. uint8_t subsys, opcode;
  1509. switch (mbox->mbxCommand) {
  1510. case MBX_WRITE_NV: /* 0x03 */
  1511. case MBX_DUMP_MEMORY: /* 0x17 */
  1512. case MBX_UPDATE_CFG: /* 0x1B */
  1513. case MBX_DOWN_LOAD: /* 0x1C */
  1514. case MBX_DEL_LD_ENTRY: /* 0x1D */
  1515. case MBX_WRITE_VPARMS: /* 0x32 */
  1516. case MBX_LOAD_AREA: /* 0x81 */
  1517. case MBX_WRITE_WWN: /* 0x98 */
  1518. case MBX_LOAD_EXP_ROM: /* 0x9C */
  1519. case MBX_ACCESS_VDATA: /* 0xA5 */
  1520. return LPFC_MBOX_TMO_FLASH_CMD;
  1521. case MBX_SLI4_CONFIG: /* 0x9b */
  1522. subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
  1523. opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
  1524. if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
  1525. switch (opcode) {
  1526. case LPFC_MBOX_OPCODE_READ_OBJECT:
  1527. case LPFC_MBOX_OPCODE_WRITE_OBJECT:
  1528. case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
  1529. case LPFC_MBOX_OPCODE_DELETE_OBJECT:
  1530. case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
  1531. case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
  1532. case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
  1533. case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
  1534. case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
  1535. case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
  1536. case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
  1537. case LPFC_MBOX_OPCODE_RESET_LICENSES:
  1538. case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
  1539. case LPFC_MBOX_OPCODE_GET_VPD_DATA:
  1540. case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
  1541. return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
  1542. }
  1543. }
  1544. if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
  1545. switch (opcode) {
  1546. case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
  1547. return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
  1548. }
  1549. }
  1550. return LPFC_MBOX_SLI4_CONFIG_TMO;
  1551. }
  1552. return LPFC_MBOX_TMO;
  1553. }
  1554. /**
  1555. * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
  1556. * @mbox: pointer to lpfc mbox command.
  1557. * @sgentry: sge entry index.
  1558. * @phyaddr: physical address for the sge
  1559. * @length: Length of the sge.
  1560. *
  1561. * This routine sets up an entry in the non-embedded mailbox command at the sge
  1562. * index location.
  1563. **/
  1564. void
  1565. lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
  1566. dma_addr_t phyaddr, uint32_t length)
  1567. {
  1568. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1569. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1570. &mbox->u.mqe.un.nembed_cmd;
  1571. nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
  1572. nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
  1573. nembed_sge->sge[sgentry].length = length;
  1574. }
  1575. /**
  1576. * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
  1577. * @mbox: pointer to lpfc mbox command.
  1578. * @sgentry: sge entry index.
  1579. * @sge: pointer to lpfc mailbox sge to load into.
  1580. *
  1581. * This routine gets an entry from the non-embedded mailbox command at the sge
  1582. * index location.
  1583. **/
  1584. void
  1585. lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
  1586. struct lpfc_mbx_sge *sge)
  1587. {
  1588. struct lpfc_mbx_nembed_cmd *nembed_sge;
  1589. nembed_sge = (struct lpfc_mbx_nembed_cmd *)
  1590. &mbox->u.mqe.un.nembed_cmd;
  1591. sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
  1592. sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
  1593. sge->length = nembed_sge->sge[sgentry].length;
  1594. }
  1595. /**
  1596. * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
  1597. * @phba: pointer to lpfc hba data structure.
  1598. * @mbox: pointer to lpfc mbox command.
  1599. *
  1600. * This routine cleans up and releases an SLI4 mailbox command that was
  1601. * configured using lpfc_sli4_config. It accounts for the embedded and
  1602. * non-embedded config types.
  1603. **/
  1604. void
  1605. lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  1606. {
  1607. struct lpfc_mbx_sli4_config *sli4_cfg;
  1608. struct lpfc_mbx_sge sge;
  1609. dma_addr_t phyaddr;
  1610. uint32_t sgecount, sgentry;
  1611. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1612. /* For embedded mbox command, just free the mbox command */
  1613. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1614. mempool_free(mbox, phba->mbox_mem_pool);
  1615. return;
  1616. }
  1617. /* For non-embedded mbox command, we need to free the pages first */
  1618. sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
  1619. /* There is nothing we can do if there is no sge address array */
  1620. if (unlikely(!mbox->sge_array)) {
  1621. mempool_free(mbox, phba->mbox_mem_pool);
  1622. return;
  1623. }
  1624. /* Each non-embedded DMA memory was allocated in the length of a page */
  1625. for (sgentry = 0; sgentry < sgecount; sgentry++) {
  1626. lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
  1627. phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
  1628. dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
  1629. mbox->sge_array->addr[sgentry], phyaddr);
  1630. }
  1631. /* Reinitialize the context pointers to avoid stale usage. */
  1632. mbox->ctx_buf = NULL;
  1633. memset(&mbox->ctx_u, 0, sizeof(mbox->ctx_u));
  1634. kfree(mbox->sge_array);
  1635. /* Finally, free the mailbox command itself */
  1636. mempool_free(mbox, phba->mbox_mem_pool);
  1637. }
  1638. /**
  1639. * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
  1640. * @phba: pointer to lpfc hba data structure.
  1641. * @mbox: pointer to lpfc mbox command.
  1642. * @subsystem: The sli4 config sub mailbox subsystem.
  1643. * @opcode: The sli4 config sub mailbox command opcode.
  1644. * @length: Length of the sli4 config mailbox command (including sub-header).
  1645. * @emb: True if embedded mbox command should be setup.
  1646. *
  1647. * This routine sets up the header fields of SLI4 specific mailbox command
  1648. * for sending IOCTL command.
  1649. *
  1650. * Return: the actual length of the mbox command allocated (mostly useful
  1651. * for none embedded mailbox command).
  1652. **/
  1653. int
  1654. lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
  1655. uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
  1656. {
  1657. struct lpfc_mbx_sli4_config *sli4_config;
  1658. union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
  1659. uint32_t alloc_len;
  1660. uint32_t resid_len;
  1661. uint32_t pagen, pcount;
  1662. void *viraddr;
  1663. dma_addr_t phyaddr;
  1664. /* Set up SLI4 mailbox command header fields */
  1665. memset(mbox, 0, sizeof(*mbox));
  1666. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
  1667. /* Set up SLI4 ioctl command header fields */
  1668. sli4_config = &mbox->u.mqe.un.sli4_config;
  1669. /* Setup for the embedded mbox command */
  1670. if (emb) {
  1671. /* Set up main header fields */
  1672. bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
  1673. sli4_config->header.cfg_mhdr.payload_length = length;
  1674. /* Set up sub-header fields following main header */
  1675. bf_set(lpfc_mbox_hdr_opcode,
  1676. &sli4_config->header.cfg_shdr.request, opcode);
  1677. bf_set(lpfc_mbox_hdr_subsystem,
  1678. &sli4_config->header.cfg_shdr.request, subsystem);
  1679. sli4_config->header.cfg_shdr.request.request_length =
  1680. length - LPFC_MBX_CMD_HDR_LENGTH;
  1681. return length;
  1682. }
  1683. /* Setup for the non-embedded mbox command */
  1684. pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
  1685. pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
  1686. LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
  1687. /* Allocate record for keeping SGE virtual addresses */
  1688. mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
  1689. GFP_KERNEL);
  1690. if (!mbox->sge_array) {
  1691. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1692. "2527 Failed to allocate non-embedded SGE "
  1693. "array.\n");
  1694. return 0;
  1695. }
  1696. for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
  1697. /* The DMA memory is always allocated in the length of a
  1698. * page even though the last SGE might not fill up to a
  1699. * page, this is used as a priori size of SLI4_PAGE_SIZE for
  1700. * the later DMA memory free.
  1701. */
  1702. viraddr = dma_alloc_coherent(&phba->pcidev->dev,
  1703. SLI4_PAGE_SIZE, &phyaddr,
  1704. GFP_KERNEL);
  1705. /* In case of malloc fails, proceed with whatever we have */
  1706. if (!viraddr)
  1707. break;
  1708. mbox->sge_array->addr[pagen] = viraddr;
  1709. /* Keep the first page for later sub-header construction */
  1710. if (pagen == 0)
  1711. cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
  1712. resid_len = length - alloc_len;
  1713. if (resid_len > SLI4_PAGE_SIZE) {
  1714. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1715. SLI4_PAGE_SIZE);
  1716. alloc_len += SLI4_PAGE_SIZE;
  1717. } else {
  1718. lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
  1719. resid_len);
  1720. alloc_len = length;
  1721. }
  1722. }
  1723. /* Set up main header fields in mailbox command */
  1724. sli4_config->header.cfg_mhdr.payload_length = alloc_len;
  1725. bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
  1726. /* Set up sub-header fields into the first page */
  1727. if (pagen > 0) {
  1728. bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
  1729. bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
  1730. cfg_shdr->request.request_length =
  1731. alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
  1732. }
  1733. /* The sub-header is in DMA memory, which needs endian converstion */
  1734. if (cfg_shdr)
  1735. lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
  1736. sizeof(union lpfc_sli4_cfg_shdr));
  1737. return alloc_len;
  1738. }
  1739. /**
  1740. * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
  1741. * @phba: pointer to lpfc hba data structure.
  1742. * @mbox: pointer to an allocated lpfc mbox resource.
  1743. * @exts_count: the number of extents, if required, to allocate.
  1744. * @rsrc_type: the resource extent type.
  1745. * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
  1746. *
  1747. * This routine completes the subcommand header for SLI4 resource extent
  1748. * mailbox commands. It is called after lpfc_sli4_config. The caller must
  1749. * pass an allocated mailbox and the attributes required to initialize the
  1750. * mailbox correctly.
  1751. *
  1752. * Return: the actual length of the mbox command allocated.
  1753. **/
  1754. int
  1755. lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
  1756. uint16_t exts_count, uint16_t rsrc_type, bool emb)
  1757. {
  1758. uint8_t opcode = 0;
  1759. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
  1760. void *virtaddr = NULL;
  1761. /* Set up SLI4 ioctl command header fields */
  1762. if (emb == LPFC_SLI4_MBX_NEMBED) {
  1763. /* Get the first SGE entry from the non-embedded DMA memory */
  1764. virtaddr = mbox->sge_array->addr[0];
  1765. if (virtaddr == NULL)
  1766. return 1;
  1767. n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  1768. }
  1769. /*
  1770. * The resource type is common to all extent Opcodes and resides in the
  1771. * same position.
  1772. */
  1773. if (emb == LPFC_SLI4_MBX_EMBED)
  1774. bf_set(lpfc_mbx_alloc_rsrc_extents_type,
  1775. &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
  1776. rsrc_type);
  1777. else {
  1778. /* This is DMA data. Byteswap is required. */
  1779. bf_set(lpfc_mbx_alloc_rsrc_extents_type,
  1780. n_rsrc_extnt, rsrc_type);
  1781. lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
  1782. &n_rsrc_extnt->word4,
  1783. sizeof(uint32_t));
  1784. }
  1785. /* Complete the initialization for the particular Opcode. */
  1786. opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
  1787. switch (opcode) {
  1788. case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
  1789. if (emb == LPFC_SLI4_MBX_EMBED)
  1790. bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
  1791. &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
  1792. exts_count);
  1793. else
  1794. bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
  1795. n_rsrc_extnt, exts_count);
  1796. break;
  1797. case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
  1798. case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
  1799. case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
  1800. /* Initialization is complete.*/
  1801. break;
  1802. default:
  1803. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1804. "2929 Resource Extent Opcode x%x is "
  1805. "unsupported\n", opcode);
  1806. return 1;
  1807. }
  1808. return 0;
  1809. }
  1810. /**
  1811. * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
  1812. * @phba: pointer to lpfc hba data structure.
  1813. * @mbox: pointer to lpfc mbox command queue entry.
  1814. *
  1815. * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
  1816. * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
  1817. * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
  1818. * be returned.
  1819. **/
  1820. uint8_t
  1821. lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  1822. {
  1823. struct lpfc_mbx_sli4_config *sli4_cfg;
  1824. union lpfc_sli4_cfg_shdr *cfg_shdr;
  1825. if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
  1826. return LPFC_MBOX_SUBSYSTEM_NA;
  1827. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1828. /* For embedded mbox command, get opcode from embedded sub-header*/
  1829. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1830. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  1831. return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
  1832. }
  1833. /* For non-embedded mbox command, get opcode from first dma page */
  1834. if (unlikely(!mbox->sge_array))
  1835. return LPFC_MBOX_SUBSYSTEM_NA;
  1836. cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
  1837. return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
  1838. }
  1839. /**
  1840. * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
  1841. * @phba: pointer to lpfc hba data structure.
  1842. * @mbox: pointer to lpfc mbox command queue entry.
  1843. *
  1844. * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
  1845. * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
  1846. * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
  1847. * returned.
  1848. **/
  1849. uint8_t
  1850. lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  1851. {
  1852. struct lpfc_mbx_sli4_config *sli4_cfg;
  1853. union lpfc_sli4_cfg_shdr *cfg_shdr;
  1854. if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
  1855. return LPFC_MBOX_OPCODE_NA;
  1856. sli4_cfg = &mbox->u.mqe.un.sli4_config;
  1857. /* For embedded mbox command, get opcode from embedded sub-header*/
  1858. if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
  1859. cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
  1860. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1861. }
  1862. /* For non-embedded mbox command, get opcode from first dma page */
  1863. if (unlikely(!mbox->sge_array))
  1864. return LPFC_MBOX_OPCODE_NA;
  1865. cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
  1866. return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
  1867. }
  1868. /**
  1869. * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
  1870. * @phba: pointer to lpfc hba data structure.
  1871. * @mboxq: pointer to lpfc mbox command.
  1872. * @fcf_index: index to fcf table.
  1873. *
  1874. * This routine routine allocates and constructs non-embedded mailbox command
  1875. * for reading a FCF table entry referred by @fcf_index.
  1876. *
  1877. * Return: pointer to the mailbox command constructed if successful, otherwise
  1878. * NULL.
  1879. **/
  1880. int
  1881. lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
  1882. struct lpfcMboxq *mboxq,
  1883. uint16_t fcf_index)
  1884. {
  1885. void *virt_addr;
  1886. uint8_t *bytep;
  1887. struct lpfc_mbx_sge sge;
  1888. uint32_t alloc_len, req_len;
  1889. struct lpfc_mbx_read_fcf_tbl *read_fcf;
  1890. if (!mboxq)
  1891. return -ENOMEM;
  1892. req_len = sizeof(struct fcf_record) +
  1893. sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
  1894. /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
  1895. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  1896. LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
  1897. LPFC_SLI4_MBX_NEMBED);
  1898. if (alloc_len < req_len) {
  1899. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  1900. "0291 Allocated DMA memory size (x%x) is "
  1901. "less than the requested DMA memory "
  1902. "size (x%x)\n", alloc_len, req_len);
  1903. return -ENOMEM;
  1904. }
  1905. /* Get the first SGE entry from the non-embedded DMA memory. This
  1906. * routine only uses a single SGE.
  1907. */
  1908. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  1909. virt_addr = mboxq->sge_array->addr[0];
  1910. read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
  1911. /* Set up command fields */
  1912. bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
  1913. /* Perform necessary endian conversion */
  1914. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  1915. lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
  1916. return 0;
  1917. }
  1918. /**
  1919. * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
  1920. * @phba: pointer to lpfc hba data structure.
  1921. * @mboxq: pointer to lpfc mbox command.
  1922. *
  1923. * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
  1924. * mailbox command.
  1925. **/
  1926. void
  1927. lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
  1928. {
  1929. /* Set up SLI4 mailbox command header fields */
  1930. memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
  1931. bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
  1932. /* Set up host requested features. */
  1933. bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
  1934. bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
  1935. /* Enable DIF (block guard) only if configured to do so. */
  1936. if (phba->cfg_enable_bg)
  1937. bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
  1938. /* Enable NPIV only if configured to do so. */
  1939. if (phba->max_vpi && phba->cfg_enable_npiv)
  1940. bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
  1941. if (phba->nvmet_support) {
  1942. bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1);
  1943. /* iaab/iaar NOT set for now */
  1944. bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0);
  1945. bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0);
  1946. }
  1947. /* Enable Application Services Header for appheader VMID */
  1948. if (phba->cfg_vmid_app_header) {
  1949. bf_set(lpfc_mbx_rq_ftr_rq_ashdr, &mboxq->u.mqe.un.req_ftrs, 1);
  1950. bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 1);
  1951. }
  1952. return;
  1953. }
  1954. /**
  1955. * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
  1956. * @mbox: pointer to lpfc mbox command to initialize.
  1957. * @vport: Vport associated with the VF.
  1958. *
  1959. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1960. * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
  1961. * in the context of an FCF. The driver issues this command to setup a VFI
  1962. * before issuing a FLOGI to login to the VSAN. The driver should also issue a
  1963. * REG_VFI after a successful VSAN login.
  1964. **/
  1965. void
  1966. lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
  1967. {
  1968. struct lpfc_mbx_init_vfi *init_vfi;
  1969. memset(mbox, 0, sizeof(*mbox));
  1970. mbox->vport = vport;
  1971. init_vfi = &mbox->u.mqe.un.init_vfi;
  1972. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
  1973. bf_set(lpfc_init_vfi_vr, init_vfi, 1);
  1974. bf_set(lpfc_init_vfi_vt, init_vfi, 1);
  1975. bf_set(lpfc_init_vfi_vp, init_vfi, 1);
  1976. bf_set(lpfc_init_vfi_vfi, init_vfi,
  1977. vport->phba->sli4_hba.vfi_ids[vport->vfi]);
  1978. bf_set(lpfc_init_vfi_vpi, init_vfi,
  1979. vport->phba->vpi_ids[vport->vpi]);
  1980. bf_set(lpfc_init_vfi_fcfi, init_vfi,
  1981. vport->phba->fcf.fcfi);
  1982. }
  1983. /**
  1984. * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
  1985. * @mbox: pointer to lpfc mbox command to initialize.
  1986. * @vport: vport associated with the VF.
  1987. * @phys: BDE DMA bus address used to send the service parameters to the HBA.
  1988. *
  1989. * This routine initializes @mbox to all zeros and then fills in the mailbox
  1990. * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
  1991. * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
  1992. * fabrics identified by VFI in the context of an FCF.
  1993. **/
  1994. void
  1995. lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
  1996. {
  1997. struct lpfc_mbx_reg_vfi *reg_vfi;
  1998. struct lpfc_hba *phba = vport->phba;
  1999. uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0;
  2000. memset(mbox, 0, sizeof(*mbox));
  2001. reg_vfi = &mbox->u.mqe.un.reg_vfi;
  2002. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
  2003. bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
  2004. bf_set(lpfc_reg_vfi_vfi, reg_vfi,
  2005. phba->sli4_hba.vfi_ids[vport->vfi]);
  2006. bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
  2007. bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
  2008. memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
  2009. reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
  2010. reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
  2011. reg_vfi->e_d_tov = phba->fc_edtov;
  2012. reg_vfi->r_a_tov = phba->fc_ratov;
  2013. if (phys) {
  2014. reg_vfi->bde.addrHigh = putPaddrHigh(phys);
  2015. reg_vfi->bde.addrLow = putPaddrLow(phys);
  2016. reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
  2017. reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  2018. }
  2019. bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
  2020. /* Only FC supports upd bit */
  2021. if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
  2022. test_bit(FC_VFI_REGISTERED, &vport->fc_flag) &&
  2023. (!phba->fc_topology_changed))
  2024. bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
  2025. bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0);
  2026. bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0);
  2027. bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF;
  2028. if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
  2029. bbscn_fabric != 0) {
  2030. bbscn_max = bf_get(lpfc_bbscn_max,
  2031. &phba->sli4_hba.bbscn_params);
  2032. if (bbscn_fabric <= bbscn_max) {
  2033. bbscn_def = bf_get(lpfc_bbscn_def,
  2034. &phba->sli4_hba.bbscn_params);
  2035. if (bbscn_fabric > bbscn_def)
  2036. bf_set(lpfc_reg_vfi_bbscn, reg_vfi,
  2037. bbscn_fabric);
  2038. else
  2039. bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def);
  2040. bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1);
  2041. }
  2042. }
  2043. lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
  2044. "3134 Register VFI, mydid:x%x, fcfi:%d, "
  2045. "vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%lx "
  2046. "port_state:x%x topology chg:%d bbscn_fabric :%d\n",
  2047. vport->fc_myDID,
  2048. phba->fcf.fcfi,
  2049. phba->sli4_hba.vfi_ids[vport->vfi],
  2050. phba->vpi_ids[vport->vpi],
  2051. reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
  2052. vport->port_state, phba->fc_topology_changed,
  2053. bbscn_fabric);
  2054. }
  2055. /**
  2056. * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
  2057. * @phba: pointer to the hba structure to init the VPI for.
  2058. * @mbox: pointer to lpfc mbox command to initialize.
  2059. * @vpi: VPI to be initialized.
  2060. *
  2061. * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
  2062. * command to activate a virtual N_Port. The HBA assigns a MAC address to use
  2063. * with the virtual N Port. The SLI Host issues this command before issuing a
  2064. * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
  2065. * successful virtual NPort login.
  2066. **/
  2067. void
  2068. lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
  2069. {
  2070. memset(mbox, 0, sizeof(*mbox));
  2071. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
  2072. bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
  2073. phba->vpi_ids[vpi]);
  2074. bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
  2075. phba->sli4_hba.vfi_ids[phba->pport->vfi]);
  2076. }
  2077. /**
  2078. * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
  2079. * @mbox: pointer to lpfc mbox command to initialize.
  2080. * @vport: vport associated with the VF.
  2081. *
  2082. * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
  2083. * (logical NPort) into the inactive state. The SLI Host must have logged out
  2084. * and unregistered all remote N_Ports to abort any activity on the virtual
  2085. * fabric. The SLI Port posts the mailbox response after marking the virtual
  2086. * fabric inactive.
  2087. **/
  2088. void
  2089. lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
  2090. {
  2091. memset(mbox, 0, sizeof(*mbox));
  2092. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
  2093. bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
  2094. vport->phba->sli4_hba.vfi_ids[vport->vfi]);
  2095. }
  2096. /**
  2097. * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
  2098. * @phba: pointer to the hba structure containing.
  2099. * @mbox: pointer to lpfc mbox command to initialize.
  2100. *
  2101. * This function create a SLI4 dump mailbox command to dump configure
  2102. * region 23.
  2103. **/
  2104. int
  2105. lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  2106. {
  2107. struct lpfc_dmabuf *mp = NULL;
  2108. MAILBOX_t *mb;
  2109. int rc;
  2110. memset(mbox, 0, sizeof(*mbox));
  2111. mb = &mbox->u.mb;
  2112. rc = lpfc_mbox_rsrc_prep(phba, mbox);
  2113. if (rc) {
  2114. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  2115. "2569 %s: memory allocation failed\n",
  2116. __func__);
  2117. return 1;
  2118. }
  2119. mb->mbxCommand = MBX_DUMP_MEMORY;
  2120. mb->un.varDmp.type = DMP_NV_PARAMS;
  2121. mb->un.varDmp.region_id = DMP_REGION_23;
  2122. mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
  2123. mp = mbox->ctx_buf;
  2124. mb->un.varWords[3] = putPaddrLow(mp->phys);
  2125. mb->un.varWords[4] = putPaddrHigh(mp->phys);
  2126. return 0;
  2127. }
  2128. static void
  2129. lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  2130. {
  2131. MAILBOX_t *mb;
  2132. int rc = FAILURE;
  2133. struct lpfc_rdp_context *rdp_context = mboxq->ctx_u.rdp;
  2134. mb = &mboxq->u.mb;
  2135. if (mb->mbxStatus)
  2136. goto mbx_failed;
  2137. memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
  2138. rc = SUCCESS;
  2139. mbx_failed:
  2140. lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
  2141. rdp_context->cmpl(phba, rdp_context, rc);
  2142. }
  2143. static void
  2144. lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  2145. {
  2146. struct lpfc_dmabuf *mp = mbox->ctx_buf;
  2147. struct lpfc_rdp_context *rdp_context = mbox->ctx_u.rdp;
  2148. if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
  2149. goto error_mbox_free;
  2150. lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
  2151. DMP_SFF_PAGE_A2_SIZE);
  2152. lpfc_read_lnk_stat(phba, mbox);
  2153. mbox->vport = rdp_context->ndlp->vport;
  2154. /* Save the dma buffer for cleanup in the final completion. */
  2155. mbox->ctx_buf = mp;
  2156. mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
  2157. mbox->ctx_u.rdp = rdp_context;
  2158. if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
  2159. goto error_mbox_free;
  2160. return;
  2161. error_mbox_free:
  2162. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  2163. rdp_context->cmpl(phba, rdp_context, FAILURE);
  2164. }
  2165. void
  2166. lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  2167. {
  2168. int rc;
  2169. struct lpfc_dmabuf *mp = mbox->ctx_buf;
  2170. struct lpfc_rdp_context *rdp_context = mbox->ctx_u.rdp;
  2171. if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
  2172. goto error;
  2173. lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
  2174. DMP_SFF_PAGE_A0_SIZE);
  2175. memset(mbox, 0, sizeof(*mbox));
  2176. memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
  2177. INIT_LIST_HEAD(&mp->list);
  2178. /* save address for completion */
  2179. mbox->ctx_buf = mp;
  2180. mbox->vport = rdp_context->ndlp->vport;
  2181. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
  2182. bf_set(lpfc_mbx_memory_dump_type3_type,
  2183. &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
  2184. bf_set(lpfc_mbx_memory_dump_type3_link,
  2185. &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
  2186. bf_set(lpfc_mbx_memory_dump_type3_page_no,
  2187. &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
  2188. bf_set(lpfc_mbx_memory_dump_type3_length,
  2189. &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
  2190. mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
  2191. mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
  2192. mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
  2193. mbox->ctx_u.rdp = rdp_context;
  2194. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  2195. if (rc == MBX_NOT_FINISHED)
  2196. goto error;
  2197. return;
  2198. error:
  2199. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  2200. rdp_context->cmpl(phba, rdp_context, FAILURE);
  2201. }
  2202. /*
  2203. * lpfc_sli4_dump_page_a0 - Dump sli4 read SFP Diagnostic.
  2204. * @phba: pointer to the hba structure containing.
  2205. * @mbox: pointer to lpfc mbox command to initialize.
  2206. *
  2207. * This function create a SLI4 dump mailbox command to dump configure
  2208. * type 3 page 0xA0.
  2209. */
  2210. int
  2211. lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  2212. {
  2213. int rc;
  2214. struct lpfc_dmabuf *mp = NULL;
  2215. memset(mbox, 0, sizeof(*mbox));
  2216. rc = lpfc_mbox_rsrc_prep(phba, mbox);
  2217. if (rc) {
  2218. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  2219. "3569 dump type 3 page 0xA0 allocation failed\n");
  2220. return 1;
  2221. }
  2222. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
  2223. bf_set(lpfc_mbx_memory_dump_type3_type,
  2224. &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
  2225. bf_set(lpfc_mbx_memory_dump_type3_link,
  2226. &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
  2227. bf_set(lpfc_mbx_memory_dump_type3_page_no,
  2228. &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
  2229. bf_set(lpfc_mbx_memory_dump_type3_length,
  2230. &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
  2231. mp = mbox->ctx_buf;
  2232. mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
  2233. mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
  2234. return 0;
  2235. }
  2236. /**
  2237. * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
  2238. * @phba: pointer to the hba structure containing the FCF index and RQ ID.
  2239. * @mbox: pointer to lpfc mbox command to initialize.
  2240. *
  2241. * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
  2242. * SLI Host uses the command to activate an FCF after it has acquired FCF
  2243. * information via a READ_FCF mailbox command. This mailbox command also is used
  2244. * to indicate where received unsolicited frames from this FCF will be sent. By
  2245. * default this routine will set up the FCF to forward all unsolicited frames
  2246. * to the RQ ID passed in the @phba. This can be overridden by the caller for
  2247. * more complicated setups.
  2248. **/
  2249. void
  2250. lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
  2251. {
  2252. struct lpfc_mbx_reg_fcfi *reg_fcfi;
  2253. memset(mbox, 0, sizeof(*mbox));
  2254. reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
  2255. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
  2256. if (phba->nvmet_support == 0) {
  2257. bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
  2258. phba->sli4_hba.hdr_rq->queue_id);
  2259. /* Match everything - rq_id0 */
  2260. bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0);
  2261. bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0);
  2262. bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0);
  2263. bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0);
  2264. bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
  2265. /* addr mode is bit wise inverted value of fcf addr_mode */
  2266. bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
  2267. (~phba->fcf.addr_mode) & 0x3);
  2268. } else {
  2269. /* This is ONLY for NVMET MRQ == 1 */
  2270. if (phba->cfg_nvmet_mrq != 1)
  2271. return;
  2272. bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
  2273. phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
  2274. /* Match type FCP - rq_id0 */
  2275. bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP);
  2276. bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff);
  2277. bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi,
  2278. FC_RCTL_DD_UNSOL_CMD);
  2279. bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi,
  2280. phba->sli4_hba.hdr_rq->queue_id);
  2281. /* Match everything else - rq_id1 */
  2282. bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0);
  2283. bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0);
  2284. bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0);
  2285. bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0);
  2286. }
  2287. bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
  2288. bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
  2289. bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
  2290. phba->fcf.current_rec.fcf_indx);
  2291. if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
  2292. bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
  2293. bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
  2294. phba->fcf.current_rec.vlan_id);
  2295. }
  2296. }
  2297. /**
  2298. * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
  2299. * @phba: pointer to the hba structure containing the FCF index and RQ ID.
  2300. * @mbox: pointer to lpfc mbox command to initialize.
  2301. * @mode: 0 to register FCFI, 1 to register MRQs
  2302. *
  2303. * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
  2304. * The SLI Host uses the command to activate an FCF after it has acquired FCF
  2305. * information via a READ_FCF mailbox command. This mailbox command also is used
  2306. * to indicate where received unsolicited frames from this FCF will be sent. By
  2307. * default this routine will set up the FCF to forward all unsolicited frames
  2308. * to the RQ ID passed in the @phba. This can be overridden by the caller for
  2309. * more complicated setups.
  2310. **/
  2311. void
  2312. lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode)
  2313. {
  2314. struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi;
  2315. /* This is ONLY for MRQ */
  2316. if (phba->cfg_nvmet_mrq <= 1)
  2317. return;
  2318. memset(mbox, 0, sizeof(*mbox));
  2319. reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq;
  2320. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ);
  2321. if (mode == 0) {
  2322. bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi,
  2323. phba->fcf.current_rec.fcf_indx);
  2324. if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
  2325. bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1);
  2326. bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi,
  2327. phba->fcf.current_rec.vlan_id);
  2328. }
  2329. return;
  2330. }
  2331. bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi,
  2332. phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
  2333. /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
  2334. bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP);
  2335. bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff);
  2336. bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD);
  2337. bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff);
  2338. bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1);
  2339. bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1);
  2340. bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */
  2341. bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1);
  2342. bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */
  2343. bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq);
  2344. bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi,
  2345. phba->sli4_hba.hdr_rq->queue_id);
  2346. /* Match everything - rq_id1 */
  2347. bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0);
  2348. bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0);
  2349. bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0);
  2350. bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0);
  2351. bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
  2352. bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
  2353. }
  2354. /**
  2355. * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
  2356. * @mbox: pointer to lpfc mbox command to initialize.
  2357. * @fcfi: FCFI to be unregistered.
  2358. *
  2359. * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
  2360. * The SLI Host uses the command to inactivate an FCFI.
  2361. **/
  2362. void
  2363. lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
  2364. {
  2365. memset(mbox, 0, sizeof(*mbox));
  2366. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
  2367. bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
  2368. }
  2369. /**
  2370. * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
  2371. * @mbox: pointer to lpfc mbox command to initialize.
  2372. * @ndlp: The nodelist structure that describes the RPI to resume.
  2373. *
  2374. * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
  2375. * link event.
  2376. **/
  2377. void
  2378. lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
  2379. {
  2380. struct lpfc_hba *phba = ndlp->phba;
  2381. struct lpfc_mbx_resume_rpi *resume_rpi;
  2382. memset(mbox, 0, sizeof(*mbox));
  2383. resume_rpi = &mbox->u.mqe.un.resume_rpi;
  2384. bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
  2385. bf_set(lpfc_resume_rpi_index, resume_rpi,
  2386. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  2387. bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
  2388. resume_rpi->event_tag = ndlp->phba->fc_eventTag;
  2389. }