lpfc_mbox.c 41 KB

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