lpfc_mbox.c 62 KB

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