lpfc_mbox.c 65 KB

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