lpfc_mbox.c 71 KB

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