lpfc_mbox.c 65 KB

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