lpfc_mbox.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <scsi/scsi_device.h>
  25. #include <scsi/scsi_transport_fc.h>
  26. #include <scsi/scsi.h>
  27. #include "lpfc_hw.h"
  28. #include "lpfc_sli.h"
  29. #include "lpfc_nl.h"
  30. #include "lpfc_disc.h"
  31. #include "lpfc_scsi.h"
  32. #include "lpfc.h"
  33. #include "lpfc_logmsg.h"
  34. #include "lpfc_crtn.h"
  35. #include "lpfc_compat.h"
  36. /**
  37. * lpfc_dump_mem: Prepare a mailbox command for retrieving HBA's VPD memory.
  38. * @phba: pointer to lpfc hba data structure.
  39. * @pmb: pointer to the driver internal queue element for mailbox command.
  40. * @offset: offset for dumping VPD memory mailbox command.
  41. *
  42. * The dump mailbox command provides a method for the device driver to obtain
  43. * various types of information from the HBA device.
  44. *
  45. * This routine prepares the mailbox command for dumping HBA Vital Product
  46. * Data (VPD) memory. This mailbox command is to be used for retrieving a
  47. * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
  48. * offset specified by the offset parameter.
  49. **/
  50. void
  51. lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
  52. {
  53. MAILBOX_t *mb;
  54. void *ctx;
  55. mb = &pmb->mb;
  56. ctx = pmb->context2;
  57. /* Setup to dump VPD region */
  58. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  59. mb->mbxCommand = MBX_DUMP_MEMORY;
  60. mb->un.varDmp.cv = 1;
  61. mb->un.varDmp.type = DMP_NV_PARAMS;
  62. mb->un.varDmp.entry_index = offset;
  63. mb->un.varDmp.region_id = DMP_REGION_VPD;
  64. mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
  65. mb->un.varDmp.co = 0;
  66. mb->un.varDmp.resp_offset = 0;
  67. pmb->context2 = ctx;
  68. mb->mbxOwner = OWN_HOST;
  69. return;
  70. }
  71. /**
  72. * lpfc_read_nv: Prepare a mailbox command for reading HBA's NVRAM param.
  73. * @phba: pointer to lpfc hba data structure.
  74. * @pmb: pointer to the driver internal queue element for mailbox command.
  75. *
  76. * The read NVRAM mailbox command returns the HBA's non-volatile parameters
  77. * that are used as defaults when the Fibre Channel link is brought on-line.
  78. *
  79. * This routine prepares the mailbox command for reading information stored
  80. * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
  81. **/
  82. void
  83. lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  84. {
  85. MAILBOX_t *mb;
  86. mb = &pmb->mb;
  87. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  88. mb->mbxCommand = MBX_READ_NV;
  89. mb->mbxOwner = OWN_HOST;
  90. return;
  91. }
  92. /**
  93. * lpfc_config_async: Prepare a mailbox command for enabling HBA async event.
  94. * @phba: pointer to lpfc hba data structure.
  95. * @pmb: pointer to the driver internal queue element for mailbox command.
  96. * @ring: ring number for the asynchronous event to be configured.
  97. *
  98. * The asynchronous event enable mailbox command is used to enable the
  99. * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
  100. * specifies the default ring to which events are posted.
  101. *
  102. * This routine prepares the mailbox command for enabling HBA asynchronous
  103. * event support on a IOCB ring.
  104. **/
  105. void
  106. lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
  107. uint32_t ring)
  108. {
  109. MAILBOX_t *mb;
  110. mb = &pmb->mb;
  111. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  112. mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
  113. mb->un.varCfgAsyncEvent.ring = ring;
  114. mb->mbxOwner = OWN_HOST;
  115. return;
  116. }
  117. /**
  118. * lpfc_heart_beat: Prepare a mailbox command for heart beat.
  119. * @phba: pointer to lpfc hba data structure.
  120. * @pmb: pointer to the driver internal queue element for mailbox command.
  121. *
  122. * The heart beat mailbox command is used to detect an unresponsive HBA, which
  123. * is defined as any device where no error attention is sent and both mailbox
  124. * and rings are not processed.
  125. *
  126. * This routine prepares the mailbox command for issuing a heart beat in the
  127. * form of mailbox command to the HBA. The timely completion of the heart
  128. * beat mailbox command indicates the health of the HBA.
  129. **/
  130. void
  131. lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  132. {
  133. MAILBOX_t *mb;
  134. mb = &pmb->mb;
  135. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  136. mb->mbxCommand = MBX_HEARTBEAT;
  137. mb->mbxOwner = OWN_HOST;
  138. return;
  139. }
  140. /**
  141. * lpfc_read_la: Prepare a mailbox command for reading HBA link attention.
  142. * @phba: pointer to lpfc hba data structure.
  143. * @pmb: pointer to the driver internal queue element for mailbox command.
  144. * @mp: DMA buffer memory for reading the link attention information into.
  145. *
  146. * The read link attention mailbox command is issued to read the Link Event
  147. * Attention information indicated by the HBA port when the Link Event bit
  148. * of the Host Attention (HSTATT) register is set to 1. A Link Event
  149. * Attention occurs based on an exception detected at the Fibre Channel link
  150. * interface.
  151. *
  152. * This routine prepares the mailbox command for reading HBA link attention
  153. * information. A DMA memory has been set aside and address passed to the
  154. * HBA through @mp for the HBA to DMA link attention information into the
  155. * memory as part of the execution of the mailbox command.
  156. *
  157. * Return codes
  158. * 0 - Success (currently always return 0)
  159. **/
  160. int
  161. lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
  162. {
  163. MAILBOX_t *mb;
  164. struct lpfc_sli *psli;
  165. psli = &phba->sli;
  166. mb = &pmb->mb;
  167. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  168. INIT_LIST_HEAD(&mp->list);
  169. mb->mbxCommand = MBX_READ_LA64;
  170. mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
  171. mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
  172. mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
  173. /* Save address for later completion and set the owner to host so that
  174. * the FW knows this mailbox is available for processing.
  175. */
  176. pmb->context1 = (uint8_t *) mp;
  177. mb->mbxOwner = OWN_HOST;
  178. return (0);
  179. }
  180. /**
  181. * lpfc_clear_la: Prepare a mailbox command for clearing HBA link attention.
  182. * @phba: pointer to lpfc hba data structure.
  183. * @pmb: pointer to the driver internal queue element for mailbox command.
  184. *
  185. * The clear link attention mailbox command is issued to clear the link event
  186. * attention condition indicated by the Link Event bit of the Host Attention
  187. * (HSTATT) register. The link event attention condition is cleared only if
  188. * the event tag specified matches that of the current link event counter.
  189. * The current event tag is read using the read link attention event mailbox
  190. * command.
  191. *
  192. * This routine prepares the mailbox command for clearing HBA link attention
  193. * information.
  194. **/
  195. void
  196. lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  197. {
  198. MAILBOX_t *mb;
  199. mb = &pmb->mb;
  200. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  201. mb->un.varClearLA.eventTag = phba->fc_eventTag;
  202. mb->mbxCommand = MBX_CLEAR_LA;
  203. mb->mbxOwner = OWN_HOST;
  204. return;
  205. }
  206. /**
  207. * lpfc_config_link: Prepare a mailbox command for configuring link on a HBA.
  208. * @phba: pointer to lpfc hba data structure.
  209. * @pmb: pointer to the driver internal queue element for mailbox command.
  210. *
  211. * The configure link mailbox command is used before the initialize link
  212. * mailbox command to override default value and to configure link-oriented
  213. * parameters such as DID address and various timers. Typically, this
  214. * command would be used after an F_Port login to set the returned DID address
  215. * and the fabric timeout values. This command is not valid before a configure
  216. * port command has configured the HBA port.
  217. *
  218. * This routine prepares the mailbox command for configuring link on a HBA.
  219. **/
  220. void
  221. lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  222. {
  223. struct lpfc_vport *vport = phba->pport;
  224. MAILBOX_t *mb = &pmb->mb;
  225. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  226. /* NEW_FEATURE
  227. * SLI-2, Coalescing Response Feature.
  228. */
  229. if (phba->cfg_cr_delay) {
  230. mb->un.varCfgLnk.cr = 1;
  231. mb->un.varCfgLnk.ci = 1;
  232. mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
  233. mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
  234. }
  235. mb->un.varCfgLnk.myId = vport->fc_myDID;
  236. mb->un.varCfgLnk.edtov = phba->fc_edtov;
  237. mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
  238. mb->un.varCfgLnk.ratov = phba->fc_ratov;
  239. mb->un.varCfgLnk.rttov = phba->fc_rttov;
  240. mb->un.varCfgLnk.altov = phba->fc_altov;
  241. mb->un.varCfgLnk.crtov = phba->fc_crtov;
  242. mb->un.varCfgLnk.citov = phba->fc_citov;
  243. if (phba->cfg_ack0)
  244. mb->un.varCfgLnk.ack0_enable = 1;
  245. mb->mbxCommand = MBX_CONFIG_LINK;
  246. mb->mbxOwner = OWN_HOST;
  247. return;
  248. }
  249. /**
  250. * lpfc_config_msi: Prepare a mailbox command for configuring msi-x.
  251. * @phba: pointer to lpfc hba data structure.
  252. * @pmb: pointer to the driver internal queue element for mailbox command.
  253. *
  254. * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
  255. * MSI-X multi-message interrupt vector association to interrupt attention
  256. * conditions.
  257. *
  258. * Return codes
  259. * 0 - Success
  260. * -EINVAL - Failure
  261. **/
  262. int
  263. lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  264. {
  265. MAILBOX_t *mb = &pmb->mb;
  266. uint32_t attentionConditions[2];
  267. /* Sanity check */
  268. if (phba->cfg_use_msi != 2) {
  269. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  270. "0475 Not configured for supporting MSI-X "
  271. "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
  272. return -EINVAL;
  273. }
  274. if (phba->sli_rev < 3) {
  275. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  276. "0476 HBA not supporting SLI-3 or later "
  277. "SLI Revision: 0x%x\n", phba->sli_rev);
  278. return -EINVAL;
  279. }
  280. /* Clear mailbox command fields */
  281. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  282. /*
  283. * SLI-3, Message Signaled Interrupt Fearure.
  284. */
  285. /* Multi-message attention configuration */
  286. attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
  287. HA_LATT | HA_MBATT);
  288. attentionConditions[1] = 0;
  289. mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
  290. mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
  291. /*
  292. * Set up message number to HA bit association
  293. */
  294. #ifdef __BIG_ENDIAN_BITFIELD
  295. /* RA0 (FCP Ring) */
  296. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
  297. /* RA1 (Other Protocol Extra Ring) */
  298. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
  299. #else /* __LITTLE_ENDIAN_BITFIELD */
  300. /* RA0 (FCP Ring) */
  301. mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
  302. /* RA1 (Other Protocol Extra Ring) */
  303. mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
  304. #endif
  305. /* Multi-message interrupt autoclear configuration*/
  306. mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
  307. mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
  308. /* For now, HBA autoclear does not work reliably, disable it */
  309. mb->un.varCfgMSI.autoClearHA[0] = 0;
  310. mb->un.varCfgMSI.autoClearHA[1] = 0;
  311. /* Set command and owner bit */
  312. mb->mbxCommand = MBX_CONFIG_MSI;
  313. mb->mbxOwner = OWN_HOST;
  314. return 0;
  315. }
  316. /**
  317. * lpfc_init_link: Prepare a mailbox command for initialize link on a HBA.
  318. * @phba: pointer to lpfc hba data structure.
  319. * @pmb: pointer to the driver internal queue element for mailbox command.
  320. * @topology: the link topology for the link to be initialized to.
  321. * @linkspeed: the link speed for the link to be initialized to.
  322. *
  323. * The initialize link mailbox command is used to initialize the Fibre
  324. * Channel link. This command must follow a configure port command that
  325. * establishes the mode of operation.
  326. *
  327. * This routine prepares the mailbox command for initializing link on a HBA
  328. * with the specified link topology and speed.
  329. **/
  330. void
  331. lpfc_init_link(struct lpfc_hba * phba,
  332. LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
  333. {
  334. lpfc_vpd_t *vpd;
  335. struct lpfc_sli *psli;
  336. MAILBOX_t *mb;
  337. mb = &pmb->mb;
  338. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  339. psli = &phba->sli;
  340. switch (topology) {
  341. case FLAGS_TOPOLOGY_MODE_LOOP_PT:
  342. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  343. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  344. break;
  345. case FLAGS_TOPOLOGY_MODE_PT_PT:
  346. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  347. break;
  348. case FLAGS_TOPOLOGY_MODE_LOOP:
  349. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
  350. break;
  351. case FLAGS_TOPOLOGY_MODE_PT_LOOP:
  352. mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
  353. mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
  354. break;
  355. case FLAGS_LOCAL_LB:
  356. mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
  357. break;
  358. }
  359. /* Enable asynchronous ABTS responses from firmware */
  360. mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
  361. /* NEW_FEATURE
  362. * Setting up the link speed
  363. */
  364. vpd = &phba->vpd;
  365. if (vpd->rev.feaLevelHigh >= 0x02){
  366. switch(linkspeed){
  367. case LINK_SPEED_1G:
  368. case LINK_SPEED_2G:
  369. case LINK_SPEED_4G:
  370. case LINK_SPEED_8G:
  371. mb->un.varInitLnk.link_flags |=
  372. FLAGS_LINK_SPEED;
  373. mb->un.varInitLnk.link_speed = linkspeed;
  374. break;
  375. case LINK_SPEED_AUTO:
  376. default:
  377. mb->un.varInitLnk.link_speed =
  378. LINK_SPEED_AUTO;
  379. break;
  380. }
  381. }
  382. else
  383. mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
  384. mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
  385. mb->mbxOwner = OWN_HOST;
  386. mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
  387. return;
  388. }
  389. /**
  390. * lpfc_read_sparam: Prepare a mailbox command for reading HBA parameters.
  391. * @phba: pointer to lpfc hba data structure.
  392. * @pmb: pointer to the driver internal queue element for mailbox command.
  393. * @vpi: virtual N_Port identifier.
  394. *
  395. * The read service parameter mailbox command is used to read the HBA port
  396. * service parameters. The service parameters are read into the buffer
  397. * specified directly by a BDE in the mailbox command. These service
  398. * parameters may then be used to build the payload of an N_Port/F_POrt
  399. * login request and reply (LOGI/ACC).
  400. *
  401. * This routine prepares the mailbox command for reading HBA port service
  402. * parameters. The DMA memory is allocated in this function and the addresses
  403. * are populated into the mailbox command for the HBA to DMA the service
  404. * parameters into.
  405. *
  406. * Return codes
  407. * 0 - Success
  408. * 1 - DMA memory allocation failed
  409. **/
  410. int
  411. lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
  412. {
  413. struct lpfc_dmabuf *mp;
  414. MAILBOX_t *mb;
  415. struct lpfc_sli *psli;
  416. psli = &phba->sli;
  417. mb = &pmb->mb;
  418. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  419. mb->mbxOwner = OWN_HOST;
  420. /* Get a buffer to hold the HBAs Service Parameters */
  421. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  422. if (mp)
  423. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  424. if (!mp || !mp->virt) {
  425. kfree(mp);
  426. mb->mbxCommand = MBX_READ_SPARM64;
  427. /* READ_SPARAM: no buffers */
  428. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  429. "0301 READ_SPARAM: no buffers\n");
  430. return (1);
  431. }
  432. INIT_LIST_HEAD(&mp->list);
  433. mb->mbxCommand = MBX_READ_SPARM64;
  434. mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  435. mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  436. mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
  437. mb->un.varRdSparm.vpi = vpi;
  438. /* save address for completion */
  439. pmb->context1 = mp;
  440. return (0);
  441. }
  442. /**
  443. * lpfc_unreg_did: Prepare a mailbox command for unregistering DID.
  444. * @phba: pointer to lpfc hba data structure.
  445. * @vpi: virtual N_Port identifier.
  446. * @did: remote port identifier.
  447. * @pmb: pointer to the driver internal queue element for mailbox command.
  448. *
  449. * The unregister DID mailbox command is used to unregister an N_Port/F_Port
  450. * login for an unknown RPI by specifying the DID of a remote port. This
  451. * command frees an RPI context in the HBA port. This has the effect of
  452. * performing an implicit N_Port/F_Port logout.
  453. *
  454. * This routine prepares the mailbox command for unregistering a remote
  455. * N_Port/F_Port (DID) login.
  456. **/
  457. void
  458. lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
  459. LPFC_MBOXQ_t * pmb)
  460. {
  461. MAILBOX_t *mb;
  462. mb = &pmb->mb;
  463. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  464. mb->un.varUnregDID.did = did;
  465. mb->un.varUnregDID.vpi = vpi;
  466. mb->mbxCommand = MBX_UNREG_D_ID;
  467. mb->mbxOwner = OWN_HOST;
  468. return;
  469. }
  470. /**
  471. * lpfc_read_config: Prepare a mailbox command for reading HBA configuration.
  472. * @phba: pointer to lpfc hba data structure.
  473. * @pmb: pointer to the driver internal queue element for mailbox command.
  474. *
  475. * The read configuration mailbox command is used to read the HBA port
  476. * configuration parameters. This mailbox command provides a method for
  477. * seeing any parameters that may have changed via various configuration
  478. * mailbox commands.
  479. *
  480. * This routine prepares the mailbox command for reading out HBA configuration
  481. * parameters.
  482. **/
  483. void
  484. lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  485. {
  486. MAILBOX_t *mb;
  487. mb = &pmb->mb;
  488. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  489. mb->mbxCommand = MBX_READ_CONFIG;
  490. mb->mbxOwner = OWN_HOST;
  491. return;
  492. }
  493. /**
  494. * lpfc_read_lnk_stat: Prepare a mailbox command for reading HBA link stats.
  495. * @phba: pointer to lpfc hba data structure.
  496. * @pmb: pointer to the driver internal queue element for mailbox command.
  497. *
  498. * The read link status mailbox command is used to read the link status from
  499. * the HBA. Link status includes all link-related error counters. These
  500. * counters are maintained by the HBA and originated in the link hardware
  501. * unit. Note that all of these counters wrap.
  502. *
  503. * This routine prepares the mailbox command for reading out HBA link status.
  504. **/
  505. void
  506. lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  507. {
  508. MAILBOX_t *mb;
  509. mb = &pmb->mb;
  510. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  511. mb->mbxCommand = MBX_READ_LNK_STAT;
  512. mb->mbxOwner = OWN_HOST;
  513. return;
  514. }
  515. /**
  516. * lpfc_reg_login: Prepare a mailbox command for registering remote login.
  517. * @phba: pointer to lpfc hba data structure.
  518. * @vpi: virtual N_Port identifier.
  519. * @did: remote port identifier.
  520. * @param: pointer to memory holding the server parameters.
  521. * @pmb: pointer to the driver internal queue element for mailbox command.
  522. * @flag: action flag to be passed back for the complete function.
  523. *
  524. * The registration login mailbox command is used to register an N_Port or
  525. * F_Port login. This registration allows the HBA to cache the remote N_Port
  526. * service parameters internally and thereby make the appropriate FC-2
  527. * decisions. The remote port service parameters are handed off by the driver
  528. * to the HBA using a descriptor entry that directly identifies a buffer in
  529. * host memory. In exchange, the HBA returns an RPI identifier.
  530. *
  531. * This routine prepares the mailbox command for registering remote port login.
  532. * The function allocates DMA buffer for passing the service parameters to the
  533. * HBA with the mailbox command.
  534. *
  535. * Return codes
  536. * 0 - Success
  537. * 1 - DMA memory allocation failed
  538. **/
  539. int
  540. lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
  541. uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
  542. {
  543. MAILBOX_t *mb = &pmb->mb;
  544. uint8_t *sparam;
  545. struct lpfc_dmabuf *mp;
  546. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  547. mb->un.varRegLogin.rpi = 0;
  548. mb->un.varRegLogin.vpi = vpi;
  549. mb->un.varRegLogin.did = did;
  550. mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
  551. mb->mbxOwner = OWN_HOST;
  552. /* Get a buffer to hold NPorts Service Parameters */
  553. mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  554. if (mp)
  555. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  556. if (!mp || !mp->virt) {
  557. kfree(mp);
  558. mb->mbxCommand = MBX_REG_LOGIN64;
  559. /* REG_LOGIN: no buffers */
  560. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
  561. "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
  562. "flag x%x\n", vpi, did, flag);
  563. return (1);
  564. }
  565. INIT_LIST_HEAD(&mp->list);
  566. sparam = mp->virt;
  567. /* Copy param's into a new buffer */
  568. memcpy(sparam, param, sizeof (struct serv_parm));
  569. /* save address for completion */
  570. pmb->context1 = (uint8_t *) mp;
  571. mb->mbxCommand = MBX_REG_LOGIN64;
  572. mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
  573. mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
  574. mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
  575. return (0);
  576. }
  577. /**
  578. * lpfc_unreg_login: Prepare a mailbox command for unregistering remote login.
  579. * @phba: pointer to lpfc hba data structure.
  580. * @vpi: virtual N_Port identifier.
  581. * @rpi: remote port identifier
  582. * @pmb: pointer to the driver internal queue element for mailbox command.
  583. *
  584. * The unregistration login mailbox command is used to unregister an N_Port
  585. * or F_Port login. This command frees an RPI context in the HBA. It has the
  586. * effect of performing an implicit N_Port/F_Port logout.
  587. *
  588. * This routine prepares the mailbox command for unregistering remote port
  589. * login.
  590. **/
  591. void
  592. lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
  593. LPFC_MBOXQ_t * pmb)
  594. {
  595. MAILBOX_t *mb;
  596. mb = &pmb->mb;
  597. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  598. mb->un.varUnregLogin.rpi = (uint16_t) rpi;
  599. mb->un.varUnregLogin.rsvd1 = 0;
  600. mb->un.varUnregLogin.vpi = vpi;
  601. mb->mbxCommand = MBX_UNREG_LOGIN;
  602. mb->mbxOwner = OWN_HOST;
  603. return;
  604. }
  605. /**
  606. * lpfc_reg_vpi: Prepare a mailbox command for registering vport identifier.
  607. * @phba: pointer to lpfc hba data structure.
  608. * @vpi: virtual N_Port identifier.
  609. * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
  610. * @pmb: pointer to the driver internal queue element for mailbox command.
  611. *
  612. * The registration vport identifier mailbox command is used to activate a
  613. * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
  614. * N_Port_ID against the information in the selected virtual N_Port context
  615. * block and marks it active to allow normal processing of IOCB commands and
  616. * received unsolicited exchanges.
  617. *
  618. * This routine prepares the mailbox command for registering a virtual N_Port.
  619. **/
  620. void
  621. lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
  622. LPFC_MBOXQ_t *pmb)
  623. {
  624. MAILBOX_t *mb = &pmb->mb;
  625. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  626. mb->un.varRegVpi.vpi = vpi;
  627. mb->un.varRegVpi.sid = sid;
  628. mb->mbxCommand = MBX_REG_VPI;
  629. mb->mbxOwner = OWN_HOST;
  630. return;
  631. }
  632. /**
  633. * lpfc_unreg_vpi: Prepare a mailbox command for unregistering vport id.
  634. * @phba: pointer to lpfc hba data structure.
  635. * @vpi: virtual N_Port identifier.
  636. * @pmb: pointer to the driver internal queue element for mailbox command.
  637. *
  638. * The unregistration vport identifier mailbox command is used to inactivate
  639. * a virtual N_Port. The driver must have logged out and unregistered all
  640. * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
  641. * unregisters any default RPIs associated with the specified vpi, aborting
  642. * any active exchanges. The HBA will post the mailbox response after making
  643. * the virtual N_Port inactive.
  644. *
  645. * This routine prepares the mailbox command for unregistering a virtual
  646. * N_Port.
  647. **/
  648. void
  649. lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
  650. {
  651. MAILBOX_t *mb = &pmb->mb;
  652. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  653. mb->un.varUnregVpi.vpi = vpi;
  654. mb->mbxCommand = MBX_UNREG_VPI;
  655. mb->mbxOwner = OWN_HOST;
  656. return;
  657. }
  658. /**
  659. * lpfc_config_pcb_setup: Set up IOCB rings in the Port Control Block (PCB)
  660. * @phba: pointer to lpfc hba data structure.
  661. *
  662. * This routine sets up and initializes the IOCB rings in the Port Control
  663. * Block (PCB).
  664. **/
  665. static void
  666. lpfc_config_pcb_setup(struct lpfc_hba * phba)
  667. {
  668. struct lpfc_sli *psli = &phba->sli;
  669. struct lpfc_sli_ring *pring;
  670. PCB_t *pcbp = phba->pcb;
  671. dma_addr_t pdma_addr;
  672. uint32_t offset;
  673. uint32_t iocbCnt = 0;
  674. int i;
  675. pcbp->maxRing = (psli->num_rings - 1);
  676. for (i = 0; i < psli->num_rings; i++) {
  677. pring = &psli->ring[i];
  678. pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
  679. SLI2_IOCB_CMD_SIZE;
  680. pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
  681. SLI2_IOCB_RSP_SIZE;
  682. /* A ring MUST have both cmd and rsp entries defined to be
  683. valid */
  684. if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
  685. pcbp->rdsc[i].cmdEntries = 0;
  686. pcbp->rdsc[i].rspEntries = 0;
  687. pcbp->rdsc[i].cmdAddrHigh = 0;
  688. pcbp->rdsc[i].rspAddrHigh = 0;
  689. pcbp->rdsc[i].cmdAddrLow = 0;
  690. pcbp->rdsc[i].rspAddrLow = 0;
  691. pring->cmdringaddr = NULL;
  692. pring->rspringaddr = NULL;
  693. continue;
  694. }
  695. /* Command ring setup for ring */
  696. pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
  697. pcbp->rdsc[i].cmdEntries = pring->numCiocb;
  698. offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
  699. (uint8_t *) phba->slim2p.virt;
  700. pdma_addr = phba->slim2p.phys + offset;
  701. pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
  702. pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
  703. iocbCnt += pring->numCiocb;
  704. /* Response ring setup for ring */
  705. pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
  706. pcbp->rdsc[i].rspEntries = pring->numRiocb;
  707. offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
  708. (uint8_t *)phba->slim2p.virt;
  709. pdma_addr = phba->slim2p.phys + offset;
  710. pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
  711. pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
  712. iocbCnt += pring->numRiocb;
  713. }
  714. }
  715. /**
  716. * lpfc_read_rev: Prepare a mailbox command for reading HBA revision.
  717. * @phba: pointer to lpfc hba data structure.
  718. * @pmb: pointer to the driver internal queue element for mailbox command.
  719. *
  720. * The read revision mailbox command is used to read the revision levels of
  721. * the HBA components. These components include hardware units, resident
  722. * firmware, and available firmware. HBAs that supports SLI-3 mode of
  723. * operation provide different response information depending on the version
  724. * requested by the driver.
  725. *
  726. * This routine prepares the mailbox command for reading HBA revision
  727. * information.
  728. **/
  729. void
  730. lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  731. {
  732. MAILBOX_t *mb = &pmb->mb;
  733. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  734. mb->un.varRdRev.cv = 1;
  735. mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
  736. mb->mbxCommand = MBX_READ_REV;
  737. mb->mbxOwner = OWN_HOST;
  738. return;
  739. }
  740. /**
  741. * lpfc_build_hbq_profile2: Set up the HBQ Selection Profile 2.
  742. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  743. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  744. *
  745. * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
  746. * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
  747. * the Sequence Length Test using the fields in the Selection Profile 2
  748. * extension in words 20:31.
  749. **/
  750. static void
  751. lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
  752. struct lpfc_hbq_init *hbq_desc)
  753. {
  754. hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
  755. hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
  756. hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
  757. }
  758. /**
  759. * lpfc_build_hbq_profile3: Set up the HBQ Selection Profile 3.
  760. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  761. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  762. *
  763. * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
  764. * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
  765. * the Sequence Length Test and Byte Field Test using the fields in the
  766. * Selection Profile 3 extension in words 20:31.
  767. **/
  768. static void
  769. lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
  770. struct lpfc_hbq_init *hbq_desc)
  771. {
  772. hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
  773. hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
  774. hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
  775. hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
  776. memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
  777. sizeof(hbqmb->profiles.profile3.cmdmatch));
  778. }
  779. /**
  780. * lpfc_build_hbq_profile5: Set up the HBQ Selection Profile 5.
  781. * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
  782. * @hbq_desc: pointer to the HBQ selection profile descriptor.
  783. *
  784. * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
  785. * HBA tests the initial frame of an incoming sequence using the frame's
  786. * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
  787. * and Byte Field Test using the fields in the Selection Profile 5 extension
  788. * words 20:31.
  789. **/
  790. static void
  791. lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
  792. struct lpfc_hbq_init *hbq_desc)
  793. {
  794. hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
  795. hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
  796. hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
  797. hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
  798. memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
  799. sizeof(hbqmb->profiles.profile5.cmdmatch));
  800. }
  801. /**
  802. * lpfc_config_hbq: Prepare a mailbox command for configuring an HBQ.
  803. * @phba: pointer to lpfc hba data structure.
  804. * @id: HBQ identifier.
  805. * @hbq_desc: pointer to the HBA descriptor data structure.
  806. * @hbq_entry_index: index of the HBQ entry data structures.
  807. * @pmb: pointer to the driver internal queue element for mailbox command.
  808. *
  809. * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
  810. * an HBQ. The configuration binds events that require buffers to a particular
  811. * ring and HBQ based on a selection profile.
  812. *
  813. * This routine prepares the mailbox command for configuring an HBQ.
  814. **/
  815. void
  816. lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
  817. struct lpfc_hbq_init *hbq_desc,
  818. uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
  819. {
  820. int i;
  821. MAILBOX_t *mb = &pmb->mb;
  822. struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
  823. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  824. hbqmb->hbqId = id;
  825. hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
  826. hbqmb->recvNotify = hbq_desc->rn; /* Receive
  827. * Notification */
  828. hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
  829. * # in words 0-19 */
  830. hbqmb->profile = hbq_desc->profile; /* Selection profile:
  831. * 0 = all,
  832. * 7 = logentry */
  833. hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
  834. * e.g. Ring0=b0001,
  835. * ring2=b0100 */
  836. hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
  837. * or 5 */
  838. hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
  839. * HBQ will be used
  840. * for LogEntry
  841. * buffers */
  842. hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
  843. hbq_entry_index * sizeof(struct lpfc_hbq_entry);
  844. hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
  845. mb->mbxCommand = MBX_CONFIG_HBQ;
  846. mb->mbxOwner = OWN_HOST;
  847. /* Copy info for profiles 2,3,5. Other
  848. * profiles this area is reserved
  849. */
  850. if (hbq_desc->profile == 2)
  851. lpfc_build_hbq_profile2(hbqmb, hbq_desc);
  852. else if (hbq_desc->profile == 3)
  853. lpfc_build_hbq_profile3(hbqmb, hbq_desc);
  854. else if (hbq_desc->profile == 5)
  855. lpfc_build_hbq_profile5(hbqmb, hbq_desc);
  856. /* Return if no rctl / type masks for this HBQ */
  857. if (!hbq_desc->mask_count)
  858. return;
  859. /* Otherwise we setup specific rctl / type masks for this HBQ */
  860. for (i = 0; i < hbq_desc->mask_count; i++) {
  861. hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
  862. hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
  863. hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
  864. hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
  865. }
  866. return;
  867. }
  868. /**
  869. * lpfc_config_ring: Prepare a mailbox command for configuring an IOCB ring.
  870. * @phba: pointer to lpfc hba data structure.
  871. * @ring:
  872. * @pmb: pointer to the driver internal queue element for mailbox command.
  873. *
  874. * The configure ring mailbox command is used to configure an IOCB ring. This
  875. * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
  876. * ring. This is used to map incoming sequences to a particular ring whose
  877. * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
  878. * attempt to configure a ring whose number is greater than the number
  879. * specified in the Port Control Block (PCB). It is an error to issue the
  880. * configure ring command more than once with the same ring number. The HBA
  881. * returns an error if the driver attempts this.
  882. *
  883. * This routine prepares the mailbox command for configuring IOCB ring.
  884. **/
  885. void
  886. lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
  887. {
  888. int i;
  889. MAILBOX_t *mb = &pmb->mb;
  890. struct lpfc_sli *psli;
  891. struct lpfc_sli_ring *pring;
  892. memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
  893. mb->un.varCfgRing.ring = ring;
  894. mb->un.varCfgRing.maxOrigXchg = 0;
  895. mb->un.varCfgRing.maxRespXchg = 0;
  896. mb->un.varCfgRing.recvNotify = 1;
  897. psli = &phba->sli;
  898. pring = &psli->ring[ring];
  899. mb->un.varCfgRing.numMask = pring->num_mask;
  900. mb->mbxCommand = MBX_CONFIG_RING;
  901. mb->mbxOwner = OWN_HOST;
  902. /* Is this ring configured for a specific profile */
  903. if (pring->prt[0].profile) {
  904. mb->un.varCfgRing.profile = pring->prt[0].profile;
  905. return;
  906. }
  907. /* Otherwise we setup specific rctl / type masks for this ring */
  908. for (i = 0; i < pring->num_mask; i++) {
  909. mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
  910. if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
  911. mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
  912. else
  913. mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
  914. mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
  915. mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
  916. }
  917. return;
  918. }
  919. /**
  920. * lpfc_config_port: Prepare a mailbox command for configuring port.
  921. * @phba: pointer to lpfc hba data structure.
  922. * @pmb: pointer to the driver internal queue element for mailbox command.
  923. *
  924. * The configure port mailbox command is used to identify the Port Control
  925. * Block (PCB) in the driver memory. After this command is issued, the
  926. * driver must not access the mailbox in the HBA without first resetting
  927. * the HBA. The HBA may copy the PCB information to internal storage for
  928. * subsequent use; the driver can not change the PCB information unless it
  929. * resets the HBA.
  930. *
  931. * This routine prepares the mailbox command for configuring port.
  932. **/
  933. void
  934. lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  935. {
  936. MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
  937. MAILBOX_t *mb = &pmb->mb;
  938. dma_addr_t pdma_addr;
  939. uint32_t bar_low, bar_high;
  940. size_t offset;
  941. struct lpfc_hgp hgp;
  942. int i;
  943. uint32_t pgp_offset;
  944. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  945. mb->mbxCommand = MBX_CONFIG_PORT;
  946. mb->mbxOwner = OWN_HOST;
  947. mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
  948. offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
  949. pdma_addr = phba->slim2p.phys + offset;
  950. mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
  951. mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
  952. /* If HBA supports SLI=3 ask for it */
  953. if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
  954. mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
  955. mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
  956. mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
  957. mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
  958. if (phba->max_vpi && phba->cfg_enable_npiv &&
  959. phba->vpd.sli3Feat.cmv) {
  960. mb->un.varCfgPort.max_vpi = phba->max_vpi;
  961. mb->un.varCfgPort.cmv = 1;
  962. } else
  963. mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
  964. } else
  965. phba->sli_rev = 2;
  966. mb->un.varCfgPort.sli_mode = phba->sli_rev;
  967. /* Now setup pcb */
  968. phba->pcb->type = TYPE_NATIVE_SLI2;
  969. phba->pcb->feature = FEATURE_INITIAL_SLI2;
  970. /* Setup Mailbox pointers */
  971. phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
  972. offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
  973. pdma_addr = phba->slim2p.phys + offset;
  974. phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
  975. phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
  976. /*
  977. * Setup Host Group ring pointer.
  978. *
  979. * For efficiency reasons, the ring get/put pointers can be
  980. * placed in adapter memory (SLIM) rather than in host memory.
  981. * This allows firmware to avoid PCI reads/writes when updating
  982. * and checking pointers.
  983. *
  984. * The firmware recognizes the use of SLIM memory by comparing
  985. * the address of the get/put pointers structure with that of
  986. * the SLIM BAR (BAR0).
  987. *
  988. * Caution: be sure to use the PCI config space value of BAR0/BAR1
  989. * (the hardware's view of the base address), not the OS's
  990. * value of pci_resource_start() as the OS value may be a cookie
  991. * for ioremap/iomap.
  992. */
  993. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
  994. pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
  995. /*
  996. * Set up HGP - Port Memory
  997. *
  998. * The port expects the host get/put pointers to reside in memory
  999. * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
  1000. * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
  1001. * words (0x40 bytes). This area is not reserved if HBQs are
  1002. * configured in SLI-3.
  1003. *
  1004. * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
  1005. * RR0Get 0xc4 0x84
  1006. * CR1Put 0xc8 0x88
  1007. * RR1Get 0xcc 0x8c
  1008. * CR2Put 0xd0 0x90
  1009. * RR2Get 0xd4 0x94
  1010. * CR3Put 0xd8 0x98
  1011. * RR3Get 0xdc 0x9c
  1012. *
  1013. * Reserved 0xa0-0xbf
  1014. * If HBQs configured:
  1015. * HBQ 0 Put ptr 0xc0
  1016. * HBQ 1 Put ptr 0xc4
  1017. * HBQ 2 Put ptr 0xc8
  1018. * ......
  1019. * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
  1020. *
  1021. */
  1022. if (phba->sli_rev == 3) {
  1023. phba->host_gp = &mb_slim->us.s3.host[0];
  1024. phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
  1025. } else {
  1026. phba->host_gp = &mb_slim->us.s2.host[0];
  1027. phba->hbq_put = NULL;
  1028. }
  1029. /* mask off BAR0's flag bits 0 - 3 */
  1030. phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
  1031. (void __iomem *)phba->host_gp -
  1032. (void __iomem *)phba->MBslimaddr;
  1033. if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
  1034. phba->pcb->hgpAddrHigh = bar_high;
  1035. else
  1036. phba->pcb->hgpAddrHigh = 0;
  1037. /* write HGP data to SLIM at the required longword offset */
  1038. memset(&hgp, 0, sizeof(struct lpfc_hgp));
  1039. for (i=0; i < phba->sli.num_rings; i++) {
  1040. lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
  1041. sizeof(*phba->host_gp));
  1042. }
  1043. /* Setup Port Group ring pointer */
  1044. if (phba->sli3_options & LPFC_SLI3_INB_ENABLED) {
  1045. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1046. mbx.us.s3_inb_pgp.port);
  1047. phba->hbq_get = phba->mbox->us.s3_inb_pgp.hbq_get;
  1048. } else if (phba->sli_rev == 3) {
  1049. pgp_offset = offsetof(struct lpfc_sli2_slim,
  1050. mbx.us.s3_pgp.port);
  1051. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  1052. } else
  1053. pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
  1054. pdma_addr = phba->slim2p.phys + pgp_offset;
  1055. phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
  1056. phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
  1057. /* Use callback routine to setp rings in the pcb */
  1058. lpfc_config_pcb_setup(phba);
  1059. /* special handling for LC HBAs */
  1060. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  1061. uint32_t hbainit[5];
  1062. lpfc_hba_init(phba, hbainit);
  1063. memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
  1064. }
  1065. /* Swap PCB if needed */
  1066. lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
  1067. }
  1068. /**
  1069. * lpfc_kill_board: Prepare a mailbox command for killing board.
  1070. * @phba: pointer to lpfc hba data structure.
  1071. * @pmb: pointer to the driver internal queue element for mailbox command.
  1072. *
  1073. * The kill board mailbox command is used to tell firmware to perform a
  1074. * graceful shutdown of a channel on a specified board to prepare for reset.
  1075. * When the kill board mailbox command is received, the ER3 bit is set to 1
  1076. * in the Host Status register and the ER Attention bit is set to 1 in the
  1077. * Host Attention register of the HBA function that received the kill board
  1078. * command.
  1079. *
  1080. * This routine prepares the mailbox command for killing the board in
  1081. * preparation for a graceful shutdown.
  1082. **/
  1083. void
  1084. lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
  1085. {
  1086. MAILBOX_t *mb = &pmb->mb;
  1087. memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
  1088. mb->mbxCommand = MBX_KILL_BOARD;
  1089. mb->mbxOwner = OWN_HOST;
  1090. return;
  1091. }
  1092. /**
  1093. * lpfc_mbox_put: Put a mailbox cmd into the tail of driver's mailbox queue.
  1094. * @phba: pointer to lpfc hba data structure.
  1095. * @mbq: pointer to the driver internal queue element for mailbox command.
  1096. *
  1097. * Driver maintains a internal mailbox command queue implemented as a linked
  1098. * list. When a mailbox command is issued, it shall be put into the mailbox
  1099. * command queue such that they shall be processed orderly as HBA can process
  1100. * one mailbox command at a time.
  1101. **/
  1102. void
  1103. lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1104. {
  1105. struct lpfc_sli *psli;
  1106. psli = &phba->sli;
  1107. list_add_tail(&mbq->list, &psli->mboxq);
  1108. psli->mboxq_cnt++;
  1109. return;
  1110. }
  1111. /**
  1112. * lpfc_mbox_get: Remove a mailbox cmd from the head of driver's mailbox queue.
  1113. * @phba: pointer to lpfc hba data structure.
  1114. *
  1115. * Driver maintains a internal mailbox command queue implemented as a linked
  1116. * list. When a mailbox command is issued, it shall be put into the mailbox
  1117. * command queue such that they shall be processed orderly as HBA can process
  1118. * one mailbox command at a time. After HBA finished processing a mailbox
  1119. * command, the driver will remove a pending mailbox command from the head of
  1120. * the mailbox command queue and send to the HBA for processing.
  1121. *
  1122. * Return codes
  1123. * pointer to the driver internal queue element for mailbox command.
  1124. **/
  1125. LPFC_MBOXQ_t *
  1126. lpfc_mbox_get(struct lpfc_hba * phba)
  1127. {
  1128. LPFC_MBOXQ_t *mbq = NULL;
  1129. struct lpfc_sli *psli = &phba->sli;
  1130. list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
  1131. if (mbq)
  1132. psli->mboxq_cnt--;
  1133. return mbq;
  1134. }
  1135. /**
  1136. * lpfc_mbox_cmpl_put: Put mailbox command into mailbox command complete list.
  1137. * @phba: pointer to lpfc hba data structure.
  1138. * @mbq: pointer to the driver internal queue element for mailbox command.
  1139. *
  1140. * This routine put the completed mailbox command into the mailbox command
  1141. * complete list. This routine is called from driver interrupt handler
  1142. * context.The mailbox complete list is used by the driver worker thread
  1143. * to process mailbox complete callback functions outside the driver interrupt
  1144. * handler.
  1145. **/
  1146. void
  1147. lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
  1148. {
  1149. /* This function expects to be called from interrupt context */
  1150. spin_lock(&phba->hbalock);
  1151. list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
  1152. spin_unlock(&phba->hbalock);
  1153. return;
  1154. }
  1155. /**
  1156. * lpfc_mbox_tmo_val: Retrieve mailbox command timeout value.
  1157. * @phba: pointer to lpfc hba data structure.
  1158. * @cmd: mailbox command code.
  1159. *
  1160. * This routine retrieves the proper timeout value according to the mailbox
  1161. * command code.
  1162. *
  1163. * Return codes
  1164. * Timeout value to be used for the given mailbox command
  1165. **/
  1166. int
  1167. lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
  1168. {
  1169. switch (cmd) {
  1170. case MBX_WRITE_NV: /* 0x03 */
  1171. case MBX_UPDATE_CFG: /* 0x1B */
  1172. case MBX_DOWN_LOAD: /* 0x1C */
  1173. case MBX_DEL_LD_ENTRY: /* 0x1D */
  1174. case MBX_LOAD_AREA: /* 0x81 */
  1175. case MBX_WRITE_WWN: /* 0x98 */
  1176. case MBX_LOAD_EXP_ROM: /* 0x9C */
  1177. return LPFC_MBOX_TMO_FLASH_CMD;
  1178. }
  1179. return LPFC_MBOX_TMO;
  1180. }