lpfc_mbox.c 87 KB

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