lpfc_mbox.c 69 KB

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