lpfc_mbox.c 82 KB

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