lpfc_mbox.c 81 KB

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