lpfc_mbox.c 87 KB

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