lpfc_mbox.c 71 KB

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