csio_mb.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/delay.h>
  35. #include <linux/jiffies.h>
  36. #include <linux/string.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_transport_fc.h>
  39. #include "csio_hw.h"
  40. #include "csio_lnode.h"
  41. #include "csio_rnode.h"
  42. #include "csio_mb.h"
  43. #include "csio_wr.h"
  44. #define csio_mb_is_host_owner(__owner) ((__owner) == CSIO_MBOWNER_PL)
  45. /* MB Command/Response Helpers */
  46. /*
  47. * csio_mb_fw_retval - FW return value from a mailbox response.
  48. * @mbp: Mailbox structure
  49. *
  50. */
  51. enum fw_retval
  52. csio_mb_fw_retval(struct csio_mb *mbp)
  53. {
  54. struct fw_cmd_hdr *hdr;
  55. hdr = (struct fw_cmd_hdr *)(mbp->mb);
  56. return FW_CMD_RETVAL_GET(ntohl(hdr->lo));
  57. }
  58. /*
  59. * csio_mb_hello - FW HELLO command helper
  60. * @hw: The HW structure
  61. * @mbp: Mailbox structure
  62. * @m_mbox: Master mailbox number, if any.
  63. * @a_mbox: Mailbox number for asycn notifications.
  64. * @master: Device mastership.
  65. * @cbfn: Callback, if any.
  66. *
  67. */
  68. void
  69. csio_mb_hello(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  70. uint32_t m_mbox, uint32_t a_mbox, enum csio_dev_master master,
  71. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  72. {
  73. struct fw_hello_cmd *cmdp = (struct fw_hello_cmd *)(mbp->mb);
  74. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  75. cmdp->op_to_write = htonl(FW_CMD_OP(FW_HELLO_CMD) |
  76. FW_CMD_REQUEST | FW_CMD_WRITE);
  77. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  78. cmdp->err_to_clearinit = htonl(
  79. FW_HELLO_CMD_MASTERDIS(master == CSIO_MASTER_CANT) |
  80. FW_HELLO_CMD_MASTERFORCE(master == CSIO_MASTER_MUST) |
  81. FW_HELLO_CMD_MBMASTER(master == CSIO_MASTER_MUST ?
  82. m_mbox : FW_HELLO_CMD_MBMASTER_MASK) |
  83. FW_HELLO_CMD_MBASYNCNOT(a_mbox) |
  84. FW_HELLO_CMD_STAGE(fw_hello_cmd_stage_os) |
  85. FW_HELLO_CMD_CLEARINIT);
  86. }
  87. /*
  88. * csio_mb_process_hello_rsp - FW HELLO response processing helper
  89. * @hw: The HW structure
  90. * @mbp: Mailbox structure
  91. * @retval: Mailbox return value from Firmware
  92. * @state: State that the function is in.
  93. * @mpfn: Master pfn
  94. *
  95. */
  96. void
  97. csio_mb_process_hello_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  98. enum fw_retval *retval, enum csio_dev_state *state,
  99. uint8_t *mpfn)
  100. {
  101. struct fw_hello_cmd *rsp = (struct fw_hello_cmd *)(mbp->mb);
  102. uint32_t value;
  103. *retval = FW_CMD_RETVAL_GET(ntohl(rsp->retval_len16));
  104. if (*retval == FW_SUCCESS) {
  105. hw->fwrev = ntohl(rsp->fwrev);
  106. value = ntohl(rsp->err_to_clearinit);
  107. *mpfn = FW_HELLO_CMD_MBMASTER_GET(value);
  108. if (value & FW_HELLO_CMD_INIT)
  109. *state = CSIO_DEV_STATE_INIT;
  110. else if (value & FW_HELLO_CMD_ERR)
  111. *state = CSIO_DEV_STATE_ERR;
  112. else
  113. *state = CSIO_DEV_STATE_UNINIT;
  114. }
  115. }
  116. /*
  117. * csio_mb_bye - FW BYE command helper
  118. * @hw: The HW structure
  119. * @mbp: Mailbox structure
  120. * @cbfn: Callback, if any.
  121. *
  122. */
  123. void
  124. csio_mb_bye(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  125. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  126. {
  127. struct fw_bye_cmd *cmdp = (struct fw_bye_cmd *)(mbp->mb);
  128. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  129. cmdp->op_to_write = htonl(FW_CMD_OP(FW_BYE_CMD) |
  130. FW_CMD_REQUEST | FW_CMD_WRITE);
  131. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  132. }
  133. /*
  134. * csio_mb_reset - FW RESET command helper
  135. * @hw: The HW structure
  136. * @mbp: Mailbox structure
  137. * @reset: Type of reset.
  138. * @cbfn: Callback, if any.
  139. *
  140. */
  141. void
  142. csio_mb_reset(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  143. int reset, int halt,
  144. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  145. {
  146. struct fw_reset_cmd *cmdp = (struct fw_reset_cmd *)(mbp->mb);
  147. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  148. cmdp->op_to_write = htonl(FW_CMD_OP(FW_RESET_CMD) |
  149. FW_CMD_REQUEST | FW_CMD_WRITE);
  150. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  151. cmdp->val = htonl(reset);
  152. cmdp->halt_pkd = htonl(halt);
  153. }
  154. /*
  155. * csio_mb_params - FW PARAMS command helper
  156. * @hw: The HW structure
  157. * @mbp: Mailbox structure
  158. * @tmo: Command timeout.
  159. * @pf: PF number.
  160. * @vf: VF number.
  161. * @nparams: Number of parameters
  162. * @params: Parameter mnemonic array.
  163. * @val: Parameter value array.
  164. * @wr: Write/Read PARAMS.
  165. * @cbfn: Callback, if any.
  166. *
  167. */
  168. void
  169. csio_mb_params(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  170. unsigned int pf, unsigned int vf, unsigned int nparams,
  171. const u32 *params, u32 *val, bool wr,
  172. void (*cbfn)(struct csio_hw *, struct csio_mb *))
  173. {
  174. uint32_t i;
  175. uint32_t temp_params = 0, temp_val = 0;
  176. struct fw_params_cmd *cmdp = (struct fw_params_cmd *)(mbp->mb);
  177. __be32 *p = &cmdp->param[0].mnem;
  178. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  179. cmdp->op_to_vfn = htonl(FW_CMD_OP(FW_PARAMS_CMD) |
  180. FW_CMD_REQUEST |
  181. (wr ? FW_CMD_WRITE : FW_CMD_READ) |
  182. FW_PARAMS_CMD_PFN(pf) |
  183. FW_PARAMS_CMD_VFN(vf));
  184. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  185. /* Write Params */
  186. if (wr) {
  187. while (nparams--) {
  188. temp_params = *params++;
  189. temp_val = *val++;
  190. *p++ = htonl(temp_params);
  191. *p++ = htonl(temp_val);
  192. }
  193. } else {
  194. for (i = 0; i < nparams; i++, p += 2) {
  195. temp_params = *params++;
  196. *p = htonl(temp_params);
  197. }
  198. }
  199. }
  200. /*
  201. * csio_mb_process_read_params_rsp - FW PARAMS response processing helper
  202. * @hw: The HW structure
  203. * @mbp: Mailbox structure
  204. * @retval: Mailbox return value from Firmware
  205. * @nparams: Number of parameters
  206. * @val: Parameter value array.
  207. *
  208. */
  209. void
  210. csio_mb_process_read_params_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  211. enum fw_retval *retval, unsigned int nparams,
  212. u32 *val)
  213. {
  214. struct fw_params_cmd *rsp = (struct fw_params_cmd *)(mbp->mb);
  215. uint32_t i;
  216. __be32 *p = &rsp->param[0].val;
  217. *retval = FW_CMD_RETVAL_GET(ntohl(rsp->retval_len16));
  218. if (*retval == FW_SUCCESS)
  219. for (i = 0; i < nparams; i++, p += 2)
  220. *val++ = ntohl(*p);
  221. }
  222. /*
  223. * csio_mb_ldst - FW LDST command
  224. * @hw: The HW structure
  225. * @mbp: Mailbox structure
  226. * @tmo: timeout
  227. * @reg: register
  228. *
  229. */
  230. void
  231. csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo, int reg)
  232. {
  233. struct fw_ldst_cmd *ldst_cmd = (struct fw_ldst_cmd *)(mbp->mb);
  234. CSIO_INIT_MBP(mbp, ldst_cmd, tmo, hw, NULL, 1);
  235. /*
  236. * Construct and send the Firmware LDST Command to retrieve the
  237. * specified PCI-E Configuration Space register.
  238. */
  239. ldst_cmd->op_to_addrspace =
  240. htonl(FW_CMD_OP(FW_LDST_CMD) |
  241. FW_CMD_REQUEST |
  242. FW_CMD_READ |
  243. FW_LDST_CMD_ADDRSPACE(FW_LDST_ADDRSPC_FUNC_PCIE));
  244. ldst_cmd->cycles_to_len16 = htonl(FW_LEN16(struct fw_ldst_cmd));
  245. ldst_cmd->u.pcie.select_naccess = FW_LDST_CMD_NACCESS(1);
  246. ldst_cmd->u.pcie.ctrl_to_fn =
  247. (FW_LDST_CMD_LC | FW_LDST_CMD_FN(hw->pfn));
  248. ldst_cmd->u.pcie.r = (uint8_t)reg;
  249. }
  250. /*
  251. *
  252. * csio_mb_caps_config - FW Read/Write Capabilities command helper
  253. * @hw: The HW structure
  254. * @mbp: Mailbox structure
  255. * @wr: Write if 1, Read if 0
  256. * @init: Turn on initiator mode.
  257. * @tgt: Turn on target mode.
  258. * @cofld: If 1, Control Offload for FCoE
  259. * @cbfn: Callback, if any.
  260. *
  261. * This helper assumes that cmdp has MB payload from a previous CAPS
  262. * read command.
  263. */
  264. void
  265. csio_mb_caps_config(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  266. bool wr, bool init, bool tgt, bool cofld,
  267. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  268. {
  269. struct fw_caps_config_cmd *cmdp =
  270. (struct fw_caps_config_cmd *)(mbp->mb);
  271. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, wr ? 0 : 1);
  272. cmdp->op_to_write = htonl(FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
  273. FW_CMD_REQUEST |
  274. (wr ? FW_CMD_WRITE : FW_CMD_READ));
  275. cmdp->cfvalid_to_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  276. /* Read config */
  277. if (!wr)
  278. return;
  279. /* Write config */
  280. cmdp->fcoecaps = 0;
  281. if (cofld)
  282. cmdp->fcoecaps |= htons(FW_CAPS_CONFIG_FCOE_CTRL_OFLD);
  283. if (init)
  284. cmdp->fcoecaps |= htons(FW_CAPS_CONFIG_FCOE_INITIATOR);
  285. if (tgt)
  286. cmdp->fcoecaps |= htons(FW_CAPS_CONFIG_FCOE_TARGET);
  287. }
  288. #define CSIO_ADVERT_MASK (FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G |\
  289. FW_PORT_CAP_SPEED_10G | FW_PORT_CAP_ANEG)
  290. /*
  291. * csio_mb_port- FW PORT command helper
  292. * @hw: The HW structure
  293. * @mbp: Mailbox structure
  294. * @tmo: COmmand timeout
  295. * @portid: Port ID to get/set info
  296. * @wr: Write/Read PORT information.
  297. * @fc: Flow control
  298. * @caps: Port capabilites to set.
  299. * @cbfn: Callback, if any.
  300. *
  301. */
  302. void
  303. csio_mb_port(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  304. uint8_t portid, bool wr, uint32_t fc, uint16_t caps,
  305. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  306. {
  307. struct fw_port_cmd *cmdp = (struct fw_port_cmd *)(mbp->mb);
  308. unsigned int lfc = 0, mdi = FW_PORT_MDI(FW_PORT_MDI_AUTO);
  309. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  310. cmdp->op_to_portid = htonl(FW_CMD_OP(FW_PORT_CMD) |
  311. FW_CMD_REQUEST |
  312. (wr ? FW_CMD_EXEC : FW_CMD_READ) |
  313. FW_PORT_CMD_PORTID(portid));
  314. if (!wr) {
  315. cmdp->action_to_len16 = htonl(
  316. FW_PORT_CMD_ACTION(FW_PORT_ACTION_GET_PORT_INFO) |
  317. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  318. return;
  319. }
  320. /* Set port */
  321. cmdp->action_to_len16 = htonl(
  322. FW_PORT_CMD_ACTION(FW_PORT_ACTION_L1_CFG) |
  323. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  324. if (fc & PAUSE_RX)
  325. lfc |= FW_PORT_CAP_FC_RX;
  326. if (fc & PAUSE_TX)
  327. lfc |= FW_PORT_CAP_FC_TX;
  328. if (!(caps & FW_PORT_CAP_ANEG))
  329. cmdp->u.l1cfg.rcap = htonl((caps & CSIO_ADVERT_MASK) | lfc);
  330. else
  331. cmdp->u.l1cfg.rcap = htonl((caps & CSIO_ADVERT_MASK) |
  332. lfc | mdi);
  333. }
  334. /*
  335. * csio_mb_process_read_port_rsp - FW PORT command response processing helper
  336. * @hw: The HW structure
  337. * @mbp: Mailbox structure
  338. * @retval: Mailbox return value from Firmware
  339. * @caps: port capabilities
  340. *
  341. */
  342. void
  343. csio_mb_process_read_port_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  344. enum fw_retval *retval, uint16_t *caps)
  345. {
  346. struct fw_port_cmd *rsp = (struct fw_port_cmd *)(mbp->mb);
  347. *retval = FW_CMD_RETVAL_GET(ntohl(rsp->action_to_len16));
  348. if (*retval == FW_SUCCESS)
  349. *caps = ntohs(rsp->u.info.pcap);
  350. }
  351. /*
  352. * csio_mb_initialize - FW INITIALIZE command helper
  353. * @hw: The HW structure
  354. * @mbp: Mailbox structure
  355. * @tmo: COmmand timeout
  356. * @cbfn: Callback, if any.
  357. *
  358. */
  359. void
  360. csio_mb_initialize(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  361. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  362. {
  363. struct fw_initialize_cmd *cmdp = (struct fw_initialize_cmd *)(mbp->mb);
  364. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  365. cmdp->op_to_write = htonl(FW_CMD_OP(FW_INITIALIZE_CMD) |
  366. FW_CMD_REQUEST | FW_CMD_WRITE);
  367. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  368. }
  369. /*
  370. * csio_mb_iq_alloc - Initializes the mailbox to allocate an
  371. * Ingress DMA queue in the firmware.
  372. *
  373. * @hw: The hw structure
  374. * @mbp: Mailbox structure to initialize
  375. * @priv: Private object
  376. * @mb_tmo: Mailbox time-out period (in ms).
  377. * @iq_params: Ingress queue params needed for allocation.
  378. * @cbfn: The call-back function
  379. *
  380. *
  381. */
  382. static void
  383. csio_mb_iq_alloc(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  384. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  385. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  386. {
  387. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  388. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  389. cmdp->op_to_vfn = htonl(FW_CMD_OP(FW_IQ_CMD) |
  390. FW_CMD_REQUEST | FW_CMD_EXEC |
  391. FW_IQ_CMD_PFN(iq_params->pfn) |
  392. FW_IQ_CMD_VFN(iq_params->vfn));
  393. cmdp->alloc_to_len16 = htonl(FW_IQ_CMD_ALLOC |
  394. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  395. cmdp->type_to_iqandstindex = htonl(
  396. FW_IQ_CMD_VIID(iq_params->viid) |
  397. FW_IQ_CMD_TYPE(iq_params->type) |
  398. FW_IQ_CMD_IQASYNCH(iq_params->iqasynch));
  399. cmdp->fl0size = htons(iq_params->fl0size);
  400. cmdp->fl0size = htons(iq_params->fl1size);
  401. } /* csio_mb_iq_alloc */
  402. /*
  403. * csio_mb_iq_write - Initializes the mailbox for writing into an
  404. * Ingress DMA Queue.
  405. *
  406. * @hw: The HW structure
  407. * @mbp: Mailbox structure to initialize
  408. * @priv: Private object
  409. * @mb_tmo: Mailbox time-out period (in ms).
  410. * @cascaded_req: TRUE - if this request is cascased with iq-alloc request.
  411. * @iq_params: Ingress queue params needed for writing.
  412. * @cbfn: The call-back function
  413. *
  414. * NOTE: We OR relevant bits with cmdp->XXX, instead of just equating,
  415. * because this IQ write request can be cascaded with a previous
  416. * IQ alloc request, and we dont want to over-write the bits set by
  417. * that request. This logic will work even in a non-cascaded case, since the
  418. * cmdp structure is zeroed out by CSIO_INIT_MBP.
  419. */
  420. static void
  421. csio_mb_iq_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  422. uint32_t mb_tmo, bool cascaded_req,
  423. struct csio_iq_params *iq_params,
  424. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  425. {
  426. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  427. uint32_t iq_start_stop = (iq_params->iq_start) ?
  428. FW_IQ_CMD_IQSTART(1) :
  429. FW_IQ_CMD_IQSTOP(1);
  430. /*
  431. * If this IQ write is cascaded with IQ alloc request, do not
  432. * re-initialize with 0's.
  433. *
  434. */
  435. if (!cascaded_req)
  436. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  437. cmdp->op_to_vfn |= htonl(FW_CMD_OP(FW_IQ_CMD) |
  438. FW_CMD_REQUEST | FW_CMD_WRITE |
  439. FW_IQ_CMD_PFN(iq_params->pfn) |
  440. FW_IQ_CMD_VFN(iq_params->vfn));
  441. cmdp->alloc_to_len16 |= htonl(iq_start_stop |
  442. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  443. cmdp->iqid |= htons(iq_params->iqid);
  444. cmdp->fl0id |= htons(iq_params->fl0id);
  445. cmdp->fl1id |= htons(iq_params->fl1id);
  446. cmdp->type_to_iqandstindex |= htonl(
  447. FW_IQ_CMD_IQANDST(iq_params->iqandst) |
  448. FW_IQ_CMD_IQANUS(iq_params->iqanus) |
  449. FW_IQ_CMD_IQANUD(iq_params->iqanud) |
  450. FW_IQ_CMD_IQANDSTINDEX(iq_params->iqandstindex));
  451. cmdp->iqdroprss_to_iqesize |= htons(
  452. FW_IQ_CMD_IQPCIECH(iq_params->iqpciech) |
  453. FW_IQ_CMD_IQDCAEN(iq_params->iqdcaen) |
  454. FW_IQ_CMD_IQDCACPU(iq_params->iqdcacpu) |
  455. FW_IQ_CMD_IQINTCNTTHRESH(iq_params->iqintcntthresh) |
  456. FW_IQ_CMD_IQCPRIO(iq_params->iqcprio) |
  457. FW_IQ_CMD_IQESIZE(iq_params->iqesize));
  458. cmdp->iqsize |= htons(iq_params->iqsize);
  459. cmdp->iqaddr |= cpu_to_be64(iq_params->iqaddr);
  460. if (iq_params->type == 0) {
  461. cmdp->iqns_to_fl0congen |= htonl(
  462. FW_IQ_CMD_IQFLINTIQHSEN(iq_params->iqflintiqhsen)|
  463. FW_IQ_CMD_IQFLINTCONGEN(iq_params->iqflintcongen));
  464. }
  465. if (iq_params->fl0size && iq_params->fl0addr &&
  466. (iq_params->fl0id != 0xFFFF)) {
  467. cmdp->iqns_to_fl0congen |= htonl(
  468. FW_IQ_CMD_FL0HOSTFCMODE(iq_params->fl0hostfcmode)|
  469. FW_IQ_CMD_FL0CPRIO(iq_params->fl0cprio) |
  470. FW_IQ_CMD_FL0PADEN(iq_params->fl0paden) |
  471. FW_IQ_CMD_FL0PACKEN(iq_params->fl0packen));
  472. cmdp->fl0dcaen_to_fl0cidxfthresh |= htons(
  473. FW_IQ_CMD_FL0DCAEN(iq_params->fl0dcaen) |
  474. FW_IQ_CMD_FL0DCACPU(iq_params->fl0dcacpu) |
  475. FW_IQ_CMD_FL0FBMIN(iq_params->fl0fbmin) |
  476. FW_IQ_CMD_FL0FBMAX(iq_params->fl0fbmax) |
  477. FW_IQ_CMD_FL0CIDXFTHRESH(iq_params->fl0cidxfthresh));
  478. cmdp->fl0size |= htons(iq_params->fl0size);
  479. cmdp->fl0addr |= cpu_to_be64(iq_params->fl0addr);
  480. }
  481. } /* csio_mb_iq_write */
  482. /*
  483. * csio_mb_iq_alloc_write - Initializes the mailbox for allocating an
  484. * Ingress DMA Queue.
  485. *
  486. * @hw: The HW structure
  487. * @mbp: Mailbox structure to initialize
  488. * @priv: Private data.
  489. * @mb_tmo: Mailbox time-out period (in ms).
  490. * @iq_params: Ingress queue params needed for allocation & writing.
  491. * @cbfn: The call-back function
  492. *
  493. *
  494. */
  495. void
  496. csio_mb_iq_alloc_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  497. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  498. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  499. {
  500. csio_mb_iq_alloc(hw, mbp, priv, mb_tmo, iq_params, cbfn);
  501. csio_mb_iq_write(hw, mbp, priv, mb_tmo, true, iq_params, cbfn);
  502. } /* csio_mb_iq_alloc_write */
  503. /*
  504. * csio_mb_iq_alloc_write_rsp - Process the allocation & writing
  505. * of ingress DMA queue mailbox's response.
  506. *
  507. * @hw: The HW structure.
  508. * @mbp: Mailbox structure to initialize.
  509. * @retval: Firmware return value.
  510. * @iq_params: Ingress queue parameters, after allocation and write.
  511. *
  512. */
  513. void
  514. csio_mb_iq_alloc_write_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  515. enum fw_retval *ret_val,
  516. struct csio_iq_params *iq_params)
  517. {
  518. struct fw_iq_cmd *rsp = (struct fw_iq_cmd *)(mbp->mb);
  519. *ret_val = FW_CMD_RETVAL_GET(ntohl(rsp->alloc_to_len16));
  520. if (*ret_val == FW_SUCCESS) {
  521. iq_params->physiqid = ntohs(rsp->physiqid);
  522. iq_params->iqid = ntohs(rsp->iqid);
  523. iq_params->fl0id = ntohs(rsp->fl0id);
  524. iq_params->fl1id = ntohs(rsp->fl1id);
  525. } else {
  526. iq_params->physiqid = iq_params->iqid =
  527. iq_params->fl0id = iq_params->fl1id = 0;
  528. }
  529. } /* csio_mb_iq_alloc_write_rsp */
  530. /*
  531. * csio_mb_iq_free - Initializes the mailbox for freeing a
  532. * specified Ingress DMA Queue.
  533. *
  534. * @hw: The HW structure
  535. * @mbp: Mailbox structure to initialize
  536. * @priv: Private data
  537. * @mb_tmo: Mailbox time-out period (in ms).
  538. * @iq_params: Parameters of ingress queue, that is to be freed.
  539. * @cbfn: The call-back function
  540. *
  541. *
  542. */
  543. void
  544. csio_mb_iq_free(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  545. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  546. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  547. {
  548. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  549. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  550. cmdp->op_to_vfn = htonl(FW_CMD_OP(FW_IQ_CMD) |
  551. FW_CMD_REQUEST | FW_CMD_EXEC |
  552. FW_IQ_CMD_PFN(iq_params->pfn) |
  553. FW_IQ_CMD_VFN(iq_params->vfn));
  554. cmdp->alloc_to_len16 = htonl(FW_IQ_CMD_FREE |
  555. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  556. cmdp->type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE(iq_params->type));
  557. cmdp->iqid = htons(iq_params->iqid);
  558. cmdp->fl0id = htons(iq_params->fl0id);
  559. cmdp->fl1id = htons(iq_params->fl1id);
  560. } /* csio_mb_iq_free */
  561. /*
  562. * csio_mb_eq_ofld_alloc - Initializes the mailbox for allocating
  563. * an offload-egress queue.
  564. *
  565. * @hw: The HW structure
  566. * @mbp: Mailbox structure to initialize
  567. * @priv: Private data
  568. * @mb_tmo: Mailbox time-out period (in ms).
  569. * @eq_ofld_params: (Offload) Egress queue parameters.
  570. * @cbfn: The call-back function
  571. *
  572. *
  573. */
  574. static void
  575. csio_mb_eq_ofld_alloc(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  576. uint32_t mb_tmo, struct csio_eq_params *eq_ofld_params,
  577. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  578. {
  579. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  580. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  581. cmdp->op_to_vfn = htonl(FW_CMD_OP(FW_EQ_OFLD_CMD) |
  582. FW_CMD_REQUEST | FW_CMD_EXEC |
  583. FW_EQ_OFLD_CMD_PFN(eq_ofld_params->pfn) |
  584. FW_EQ_OFLD_CMD_VFN(eq_ofld_params->vfn));
  585. cmdp->alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_ALLOC |
  586. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  587. } /* csio_mb_eq_ofld_alloc */
  588. /*
  589. * csio_mb_eq_ofld_write - Initializes the mailbox for writing
  590. * an alloacted offload-egress queue.
  591. *
  592. * @hw: The HW structure
  593. * @mbp: Mailbox structure to initialize
  594. * @priv: Private data
  595. * @mb_tmo: Mailbox time-out period (in ms).
  596. * @cascaded_req: TRUE - if this request is cascased with Eq-alloc request.
  597. * @eq_ofld_params: (Offload) Egress queue parameters.
  598. * @cbfn: The call-back function
  599. *
  600. *
  601. * NOTE: We OR relevant bits with cmdp->XXX, instead of just equating,
  602. * because this EQ write request can be cascaded with a previous
  603. * EQ alloc request, and we dont want to over-write the bits set by
  604. * that request. This logic will work even in a non-cascaded case, since the
  605. * cmdp structure is zeroed out by CSIO_INIT_MBP.
  606. */
  607. static void
  608. csio_mb_eq_ofld_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  609. uint32_t mb_tmo, bool cascaded_req,
  610. struct csio_eq_params *eq_ofld_params,
  611. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  612. {
  613. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  614. uint32_t eq_start_stop = (eq_ofld_params->eqstart) ?
  615. FW_EQ_OFLD_CMD_EQSTART : FW_EQ_OFLD_CMD_EQSTOP;
  616. /*
  617. * If this EQ write is cascaded with EQ alloc request, do not
  618. * re-initialize with 0's.
  619. *
  620. */
  621. if (!cascaded_req)
  622. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  623. cmdp->op_to_vfn |= htonl(FW_CMD_OP(FW_EQ_OFLD_CMD) |
  624. FW_CMD_REQUEST | FW_CMD_WRITE |
  625. FW_EQ_OFLD_CMD_PFN(eq_ofld_params->pfn) |
  626. FW_EQ_OFLD_CMD_VFN(eq_ofld_params->vfn));
  627. cmdp->alloc_to_len16 |= htonl(eq_start_stop |
  628. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  629. cmdp->eqid_pkd |= htonl(FW_EQ_OFLD_CMD_EQID(eq_ofld_params->eqid));
  630. cmdp->fetchszm_to_iqid |= htonl(
  631. FW_EQ_OFLD_CMD_HOSTFCMODE(eq_ofld_params->hostfcmode) |
  632. FW_EQ_OFLD_CMD_CPRIO(eq_ofld_params->cprio) |
  633. FW_EQ_OFLD_CMD_PCIECHN(eq_ofld_params->pciechn) |
  634. FW_EQ_OFLD_CMD_IQID(eq_ofld_params->iqid));
  635. cmdp->dcaen_to_eqsize |= htonl(
  636. FW_EQ_OFLD_CMD_DCAEN(eq_ofld_params->dcaen) |
  637. FW_EQ_OFLD_CMD_DCACPU(eq_ofld_params->dcacpu) |
  638. FW_EQ_OFLD_CMD_FBMIN(eq_ofld_params->fbmin) |
  639. FW_EQ_OFLD_CMD_FBMAX(eq_ofld_params->fbmax) |
  640. FW_EQ_OFLD_CMD_CIDXFTHRESHO(eq_ofld_params->cidxfthresho) |
  641. FW_EQ_OFLD_CMD_CIDXFTHRESH(eq_ofld_params->cidxfthresh) |
  642. FW_EQ_OFLD_CMD_EQSIZE(eq_ofld_params->eqsize));
  643. cmdp->eqaddr |= cpu_to_be64(eq_ofld_params->eqaddr);
  644. } /* csio_mb_eq_ofld_write */
  645. /*
  646. * csio_mb_eq_ofld_alloc_write - Initializes the mailbox for allocation
  647. * writing into an Engress DMA Queue.
  648. *
  649. * @hw: The HW structure
  650. * @mbp: Mailbox structure to initialize
  651. * @priv: Private data.
  652. * @mb_tmo: Mailbox time-out period (in ms).
  653. * @eq_ofld_params: (Offload) Egress queue parameters.
  654. * @cbfn: The call-back function
  655. *
  656. *
  657. */
  658. void
  659. csio_mb_eq_ofld_alloc_write(struct csio_hw *hw, struct csio_mb *mbp,
  660. void *priv, uint32_t mb_tmo,
  661. struct csio_eq_params *eq_ofld_params,
  662. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  663. {
  664. csio_mb_eq_ofld_alloc(hw, mbp, priv, mb_tmo, eq_ofld_params, cbfn);
  665. csio_mb_eq_ofld_write(hw, mbp, priv, mb_tmo, true,
  666. eq_ofld_params, cbfn);
  667. } /* csio_mb_eq_ofld_alloc_write */
  668. /*
  669. * csio_mb_eq_ofld_alloc_write_rsp - Process the allocation
  670. * & write egress DMA queue mailbox's response.
  671. *
  672. * @hw: The HW structure.
  673. * @mbp: Mailbox structure to initialize.
  674. * @retval: Firmware return value.
  675. * @eq_ofld_params: (Offload) Egress queue parameters.
  676. *
  677. */
  678. void
  679. csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *hw,
  680. struct csio_mb *mbp, enum fw_retval *ret_val,
  681. struct csio_eq_params *eq_ofld_params)
  682. {
  683. struct fw_eq_ofld_cmd *rsp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  684. *ret_val = FW_CMD_RETVAL_GET(ntohl(rsp->alloc_to_len16));
  685. if (*ret_val == FW_SUCCESS) {
  686. eq_ofld_params->eqid = FW_EQ_OFLD_CMD_EQID_GET(
  687. ntohl(rsp->eqid_pkd));
  688. eq_ofld_params->physeqid = FW_EQ_OFLD_CMD_PHYSEQID_GET(
  689. ntohl(rsp->physeqid_pkd));
  690. } else
  691. eq_ofld_params->eqid = 0;
  692. } /* csio_mb_eq_ofld_alloc_write_rsp */
  693. /*
  694. * csio_mb_eq_ofld_free - Initializes the mailbox for freeing a
  695. * specified Engress DMA Queue.
  696. *
  697. * @hw: The HW structure
  698. * @mbp: Mailbox structure to initialize
  699. * @priv: Private data area.
  700. * @mb_tmo: Mailbox time-out period (in ms).
  701. * @eq_ofld_params: (Offload) Egress queue parameters, that is to be freed.
  702. * @cbfn: The call-back function
  703. *
  704. *
  705. */
  706. void
  707. csio_mb_eq_ofld_free(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  708. uint32_t mb_tmo, struct csio_eq_params *eq_ofld_params,
  709. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  710. {
  711. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  712. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  713. cmdp->op_to_vfn = htonl(FW_CMD_OP(FW_EQ_OFLD_CMD) |
  714. FW_CMD_REQUEST | FW_CMD_EXEC |
  715. FW_EQ_OFLD_CMD_PFN(eq_ofld_params->pfn) |
  716. FW_EQ_OFLD_CMD_VFN(eq_ofld_params->vfn));
  717. cmdp->alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE |
  718. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  719. cmdp->eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID(eq_ofld_params->eqid));
  720. } /* csio_mb_eq_ofld_free */
  721. /*
  722. * csio_write_fcoe_link_cond_init_mb - Initialize Mailbox to write FCoE link
  723. * condition.
  724. *
  725. * @ln: The Lnode structure
  726. * @mbp: Mailbox structure to initialize
  727. * @mb_tmo: Mailbox time-out period (in ms).
  728. * @cbfn: The call back function.
  729. *
  730. *
  731. */
  732. void
  733. csio_write_fcoe_link_cond_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  734. uint32_t mb_tmo, uint8_t port_id, uint32_t sub_opcode,
  735. uint8_t cos, bool link_status, uint32_t fcfi,
  736. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  737. {
  738. struct fw_fcoe_link_cmd *cmdp =
  739. (struct fw_fcoe_link_cmd *)(mbp->mb);
  740. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  741. cmdp->op_to_portid = htonl((
  742. FW_CMD_OP(FW_FCOE_LINK_CMD) |
  743. FW_CMD_REQUEST |
  744. FW_CMD_WRITE |
  745. FW_FCOE_LINK_CMD_PORTID(port_id)));
  746. cmdp->sub_opcode_fcfi = htonl(
  747. FW_FCOE_LINK_CMD_SUB_OPCODE(sub_opcode) |
  748. FW_FCOE_LINK_CMD_FCFI(fcfi));
  749. cmdp->lstatus = link_status;
  750. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  751. } /* csio_write_fcoe_link_cond_init_mb */
  752. /*
  753. * csio_fcoe_read_res_info_init_mb - Initializes the mailbox for reading FCoE
  754. * resource information(FW_GET_RES_INFO_CMD).
  755. *
  756. * @hw: The HW structure
  757. * @mbp: Mailbox structure to initialize
  758. * @mb_tmo: Mailbox time-out period (in ms).
  759. * @cbfn: The call-back function
  760. *
  761. *
  762. */
  763. void
  764. csio_fcoe_read_res_info_init_mb(struct csio_hw *hw, struct csio_mb *mbp,
  765. uint32_t mb_tmo,
  766. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  767. {
  768. struct fw_fcoe_res_info_cmd *cmdp =
  769. (struct fw_fcoe_res_info_cmd *)(mbp->mb);
  770. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, hw, cbfn, 1);
  771. cmdp->op_to_read = htonl((FW_CMD_OP(FW_FCOE_RES_INFO_CMD) |
  772. FW_CMD_REQUEST |
  773. FW_CMD_READ));
  774. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  775. } /* csio_fcoe_read_res_info_init_mb */
  776. /*
  777. * csio_fcoe_vnp_alloc_init_mb - Initializes the mailbox for allocating VNP
  778. * in the firmware (FW_FCOE_VNP_CMD).
  779. *
  780. * @ln: The Lnode structure.
  781. * @mbp: Mailbox structure to initialize.
  782. * @mb_tmo: Mailbox time-out period (in ms).
  783. * @fcfi: FCF Index.
  784. * @vnpi: vnpi
  785. * @iqid: iqid
  786. * @vnport_wwnn: vnport WWNN
  787. * @vnport_wwpn: vnport WWPN
  788. * @cbfn: The call-back function.
  789. *
  790. *
  791. */
  792. void
  793. csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  794. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi, uint16_t iqid,
  795. uint8_t vnport_wwnn[8], uint8_t vnport_wwpn[8],
  796. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  797. {
  798. struct fw_fcoe_vnp_cmd *cmdp =
  799. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  800. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  801. cmdp->op_to_fcfi = htonl((FW_CMD_OP(FW_FCOE_VNP_CMD) |
  802. FW_CMD_REQUEST |
  803. FW_CMD_EXEC |
  804. FW_FCOE_VNP_CMD_FCFI(fcfi)));
  805. cmdp->alloc_to_len16 = htonl(FW_FCOE_VNP_CMD_ALLOC |
  806. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  807. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  808. cmdp->iqid = htons(iqid);
  809. if (!wwn_to_u64(vnport_wwnn) && !wwn_to_u64(vnport_wwpn))
  810. cmdp->gen_wwn_to_vnpi |= htonl(FW_FCOE_VNP_CMD_GEN_WWN);
  811. if (vnport_wwnn)
  812. memcpy(cmdp->vnport_wwnn, vnport_wwnn, 8);
  813. if (vnport_wwpn)
  814. memcpy(cmdp->vnport_wwpn, vnport_wwpn, 8);
  815. } /* csio_fcoe_vnp_alloc_init_mb */
  816. /*
  817. * csio_fcoe_vnp_read_init_mb - Prepares VNP read cmd.
  818. * @ln: The Lnode structure.
  819. * @mbp: Mailbox structure to initialize.
  820. * @mb_tmo: Mailbox time-out period (in ms).
  821. * @fcfi: FCF Index.
  822. * @vnpi: vnpi
  823. * @cbfn: The call-back handler.
  824. */
  825. void
  826. csio_fcoe_vnp_read_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  827. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi,
  828. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  829. {
  830. struct fw_fcoe_vnp_cmd *cmdp =
  831. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  832. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  833. cmdp->op_to_fcfi = htonl(FW_CMD_OP(FW_FCOE_VNP_CMD) |
  834. FW_CMD_REQUEST |
  835. FW_CMD_READ |
  836. FW_FCOE_VNP_CMD_FCFI(fcfi));
  837. cmdp->alloc_to_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  838. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  839. }
  840. /*
  841. * csio_fcoe_vnp_free_init_mb - Initializes the mailbox for freeing an
  842. * alloacted VNP in the firmware (FW_FCOE_VNP_CMD).
  843. *
  844. * @ln: The Lnode structure.
  845. * @mbp: Mailbox structure to initialize.
  846. * @mb_tmo: Mailbox time-out period (in ms).
  847. * @fcfi: FCF flow id
  848. * @vnpi: VNP flow id
  849. * @cbfn: The call-back function.
  850. * Return: None
  851. */
  852. void
  853. csio_fcoe_vnp_free_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  854. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi,
  855. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  856. {
  857. struct fw_fcoe_vnp_cmd *cmdp =
  858. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  859. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  860. cmdp->op_to_fcfi = htonl(FW_CMD_OP(FW_FCOE_VNP_CMD) |
  861. FW_CMD_REQUEST |
  862. FW_CMD_EXEC |
  863. FW_FCOE_VNP_CMD_FCFI(fcfi));
  864. cmdp->alloc_to_len16 = htonl(FW_FCOE_VNP_CMD_FREE |
  865. FW_CMD_LEN16(sizeof(*cmdp) / 16));
  866. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  867. }
  868. /*
  869. * csio_fcoe_read_fcf_init_mb - Initializes the mailbox to read the
  870. * FCF records.
  871. *
  872. * @ln: The Lnode structure
  873. * @mbp: Mailbox structure to initialize
  874. * @mb_tmo: Mailbox time-out period (in ms).
  875. * @fcf_params: FC-Forwarder parameters.
  876. * @cbfn: The call-back function
  877. *
  878. *
  879. */
  880. void
  881. csio_fcoe_read_fcf_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  882. uint32_t mb_tmo, uint32_t portid, uint32_t fcfi,
  883. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  884. {
  885. struct fw_fcoe_fcf_cmd *cmdp =
  886. (struct fw_fcoe_fcf_cmd *)(mbp->mb);
  887. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  888. cmdp->op_to_fcfi = htonl(FW_CMD_OP(FW_FCOE_FCF_CMD) |
  889. FW_CMD_REQUEST |
  890. FW_CMD_READ |
  891. FW_FCOE_FCF_CMD_FCFI(fcfi));
  892. cmdp->retval_len16 = htonl(FW_CMD_LEN16(sizeof(*cmdp) / 16));
  893. } /* csio_fcoe_read_fcf_init_mb */
  894. void
  895. csio_fcoe_read_portparams_init_mb(struct csio_hw *hw, struct csio_mb *mbp,
  896. uint32_t mb_tmo,
  897. struct fw_fcoe_port_cmd_params *portparams,
  898. void (*cbfn)(struct csio_hw *,
  899. struct csio_mb *))
  900. {
  901. struct fw_fcoe_stats_cmd *cmdp = (struct fw_fcoe_stats_cmd *)(mbp->mb);
  902. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, hw, cbfn, 1);
  903. mbp->mb_size = 64;
  904. cmdp->op_to_flowid = htonl(FW_CMD_OP(FW_FCOE_STATS_CMD) |
  905. FW_CMD_REQUEST | FW_CMD_READ);
  906. cmdp->free_to_len16 = htonl(FW_CMD_LEN16(CSIO_MAX_MB_SIZE/16));
  907. cmdp->u.ctl.nstats_port = FW_FCOE_STATS_CMD_NSTATS(portparams->nstats) |
  908. FW_FCOE_STATS_CMD_PORT(portparams->portid);
  909. cmdp->u.ctl.port_valid_ix = FW_FCOE_STATS_CMD_IX(portparams->idx) |
  910. FW_FCOE_STATS_CMD_PORT_VALID;
  911. } /* csio_fcoe_read_portparams_init_mb */
  912. void
  913. csio_mb_process_portparams_rsp(struct csio_hw *hw,
  914. struct csio_mb *mbp,
  915. enum fw_retval *retval,
  916. struct fw_fcoe_port_cmd_params *portparams,
  917. struct fw_fcoe_port_stats *portstats)
  918. {
  919. struct fw_fcoe_stats_cmd *rsp = (struct fw_fcoe_stats_cmd *)(mbp->mb);
  920. struct fw_fcoe_port_stats stats;
  921. uint8_t *src;
  922. uint8_t *dst;
  923. *retval = FW_CMD_RETVAL_GET(ntohl(rsp->free_to_len16));
  924. memset(&stats, 0, sizeof(struct fw_fcoe_port_stats));
  925. if (*retval == FW_SUCCESS) {
  926. dst = (uint8_t *)(&stats) + ((portparams->idx - 1) * 8);
  927. src = (uint8_t *)rsp + (CSIO_STATS_OFFSET * 8);
  928. memcpy(dst, src, (portparams->nstats * 8));
  929. if (portparams->idx == 1) {
  930. /* Get the first 6 flits from the Mailbox */
  931. portstats->tx_bcast_bytes = stats.tx_bcast_bytes;
  932. portstats->tx_bcast_frames = stats.tx_bcast_frames;
  933. portstats->tx_mcast_bytes = stats.tx_mcast_bytes;
  934. portstats->tx_mcast_frames = stats.tx_mcast_frames;
  935. portstats->tx_ucast_bytes = stats.tx_ucast_bytes;
  936. portstats->tx_ucast_frames = stats.tx_ucast_frames;
  937. }
  938. if (portparams->idx == 7) {
  939. /* Get the second 6 flits from the Mailbox */
  940. portstats->tx_drop_frames = stats.tx_drop_frames;
  941. portstats->tx_offload_bytes = stats.tx_offload_bytes;
  942. portstats->tx_offload_frames = stats.tx_offload_frames;
  943. #if 0
  944. portstats->rx_pf_bytes = stats.rx_pf_bytes;
  945. portstats->rx_pf_frames = stats.rx_pf_frames;
  946. #endif
  947. portstats->rx_bcast_bytes = stats.rx_bcast_bytes;
  948. portstats->rx_bcast_frames = stats.rx_bcast_frames;
  949. portstats->rx_mcast_bytes = stats.rx_mcast_bytes;
  950. }
  951. if (portparams->idx == 13) {
  952. /* Get the last 4 flits from the Mailbox */
  953. portstats->rx_mcast_frames = stats.rx_mcast_frames;
  954. portstats->rx_ucast_bytes = stats.rx_ucast_bytes;
  955. portstats->rx_ucast_frames = stats.rx_ucast_frames;
  956. portstats->rx_err_frames = stats.rx_err_frames;
  957. }
  958. }
  959. }
  960. /* Entry points/APIs for MB module */
  961. /*
  962. * csio_mb_intr_enable - Enable Interrupts from mailboxes.
  963. * @hw: The HW structure
  964. *
  965. * Enables CIM interrupt bit in appropriate INT_ENABLE registers.
  966. */
  967. void
  968. csio_mb_intr_enable(struct csio_hw *hw)
  969. {
  970. csio_wr_reg32(hw, MBMSGRDYINTEN(1), MYPF_REG(CIM_PF_HOST_INT_ENABLE));
  971. csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_ENABLE));
  972. }
  973. /*
  974. * csio_mb_intr_disable - Disable Interrupts from mailboxes.
  975. * @hw: The HW structure
  976. *
  977. * Disable bit in HostInterruptEnable CIM register.
  978. */
  979. void
  980. csio_mb_intr_disable(struct csio_hw *hw)
  981. {
  982. csio_wr_reg32(hw, MBMSGRDYINTEN(0), MYPF_REG(CIM_PF_HOST_INT_ENABLE));
  983. csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_ENABLE));
  984. }
  985. static void
  986. csio_mb_dump_fw_dbg(struct csio_hw *hw, __be64 *cmd)
  987. {
  988. struct fw_debug_cmd *dbg = (struct fw_debug_cmd *)cmd;
  989. if ((FW_DEBUG_CMD_TYPE_GET(ntohl(dbg->op_type))) == 1) {
  990. csio_info(hw, "FW print message:\n");
  991. csio_info(hw, "\tdebug->dprtstridx = %d\n",
  992. ntohs(dbg->u.prt.dprtstridx));
  993. csio_info(hw, "\tdebug->dprtstrparam0 = 0x%x\n",
  994. ntohl(dbg->u.prt.dprtstrparam0));
  995. csio_info(hw, "\tdebug->dprtstrparam1 = 0x%x\n",
  996. ntohl(dbg->u.prt.dprtstrparam1));
  997. csio_info(hw, "\tdebug->dprtstrparam2 = 0x%x\n",
  998. ntohl(dbg->u.prt.dprtstrparam2));
  999. csio_info(hw, "\tdebug->dprtstrparam3 = 0x%x\n",
  1000. ntohl(dbg->u.prt.dprtstrparam3));
  1001. } else {
  1002. /* This is a FW assertion */
  1003. csio_fatal(hw, "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  1004. dbg->u.assert.filename_0_7,
  1005. ntohl(dbg->u.assert.line),
  1006. ntohl(dbg->u.assert.x),
  1007. ntohl(dbg->u.assert.y));
  1008. }
  1009. }
  1010. static void
  1011. csio_mb_debug_cmd_handler(struct csio_hw *hw)
  1012. {
  1013. int i;
  1014. __be64 cmd[CSIO_MB_MAX_REGS];
  1015. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL);
  1016. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA);
  1017. int size = sizeof(struct fw_debug_cmd);
  1018. /* Copy mailbox data */
  1019. for (i = 0; i < size; i += 8)
  1020. cmd[i / 8] = cpu_to_be64(csio_rd_reg64(hw, data_reg + i));
  1021. csio_mb_dump_fw_dbg(hw, cmd);
  1022. /* Notify FW of mailbox by setting owner as UP */
  1023. csio_wr_reg32(hw, MBMSGVALID | MBINTREQ | MBOWNER(CSIO_MBOWNER_FW),
  1024. ctl_reg);
  1025. csio_rd_reg32(hw, ctl_reg);
  1026. wmb();
  1027. }
  1028. /*
  1029. * csio_mb_issue - generic routine for issuing Mailbox commands.
  1030. * @hw: The HW structure
  1031. * @mbp: Mailbox command to issue
  1032. *
  1033. * Caller should hold hw lock across this call.
  1034. */
  1035. int
  1036. csio_mb_issue(struct csio_hw *hw, struct csio_mb *mbp)
  1037. {
  1038. uint32_t owner, ctl;
  1039. int i;
  1040. uint32_t ii;
  1041. __be64 *cmd = mbp->mb;
  1042. __be64 hdr;
  1043. struct csio_mbm *mbm = &hw->mbm;
  1044. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL);
  1045. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA);
  1046. int size = mbp->mb_size;
  1047. int rv = -EINVAL;
  1048. struct fw_cmd_hdr *fw_hdr;
  1049. /* Determine mode */
  1050. if (mbp->mb_cbfn == NULL) {
  1051. /* Need to issue/get results in the same context */
  1052. if (mbp->tmo < CSIO_MB_POLL_FREQ) {
  1053. csio_err(hw, "Invalid tmo: 0x%x\n", mbp->tmo);
  1054. goto error_out;
  1055. }
  1056. } else if (!csio_is_host_intr_enabled(hw) ||
  1057. !csio_is_hw_intr_enabled(hw)) {
  1058. csio_err(hw, "Cannot issue mailbox in interrupt mode 0x%x\n",
  1059. *((uint8_t *)mbp->mb));
  1060. goto error_out;
  1061. }
  1062. if (mbm->mcurrent != NULL) {
  1063. /* Queue mbox cmd, if another mbox cmd is active */
  1064. if (mbp->mb_cbfn == NULL) {
  1065. rv = -EBUSY;
  1066. csio_dbg(hw, "Couldnt own Mailbox %x op:0x%x\n",
  1067. hw->pfn, *((uint8_t *)mbp->mb));
  1068. goto error_out;
  1069. } else {
  1070. list_add_tail(&mbp->list, &mbm->req_q);
  1071. CSIO_INC_STATS(mbm, n_activeq);
  1072. return 0;
  1073. }
  1074. }
  1075. /* Now get ownership of mailbox */
  1076. owner = MBOWNER_GET(csio_rd_reg32(hw, ctl_reg));
  1077. if (!csio_mb_is_host_owner(owner)) {
  1078. for (i = 0; (owner == CSIO_MBOWNER_NONE) && (i < 3); i++)
  1079. owner = MBOWNER_GET(csio_rd_reg32(hw, ctl_reg));
  1080. /*
  1081. * Mailbox unavailable. In immediate mode, fail the command.
  1082. * In other modes, enqueue the request.
  1083. */
  1084. if (!csio_mb_is_host_owner(owner)) {
  1085. if (mbp->mb_cbfn == NULL) {
  1086. rv = owner ? -EBUSY : -ETIMEDOUT;
  1087. csio_dbg(hw,
  1088. "Couldnt own Mailbox %x op:0x%x "
  1089. "owner:%x\n",
  1090. hw->pfn, *((uint8_t *)mbp->mb), owner);
  1091. goto error_out;
  1092. } else {
  1093. if (mbm->mcurrent == NULL) {
  1094. csio_err(hw,
  1095. "Couldnt own Mailbox %x "
  1096. "op:0x%x owner:%x\n",
  1097. hw->pfn, *((uint8_t *)mbp->mb),
  1098. owner);
  1099. csio_err(hw,
  1100. "No outstanding driver"
  1101. " mailbox as well\n");
  1102. goto error_out;
  1103. }
  1104. }
  1105. }
  1106. }
  1107. /* Mailbox is available, copy mailbox data into it */
  1108. for (i = 0; i < size; i += 8) {
  1109. csio_wr_reg64(hw, be64_to_cpu(*cmd), data_reg + i);
  1110. cmd++;
  1111. }
  1112. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1113. /* Start completion timers in non-immediate modes and notify FW */
  1114. if (mbp->mb_cbfn != NULL) {
  1115. mbm->mcurrent = mbp;
  1116. mod_timer(&mbm->timer, jiffies + msecs_to_jiffies(mbp->tmo));
  1117. csio_wr_reg32(hw, MBMSGVALID | MBINTREQ |
  1118. MBOWNER(CSIO_MBOWNER_FW), ctl_reg);
  1119. } else
  1120. csio_wr_reg32(hw, MBMSGVALID | MBOWNER(CSIO_MBOWNER_FW),
  1121. ctl_reg);
  1122. /* Flush posted writes */
  1123. csio_rd_reg32(hw, ctl_reg);
  1124. wmb();
  1125. CSIO_INC_STATS(mbm, n_req);
  1126. if (mbp->mb_cbfn)
  1127. return 0;
  1128. /* Poll for completion in immediate mode */
  1129. cmd = mbp->mb;
  1130. for (ii = 0; ii < mbp->tmo; ii += CSIO_MB_POLL_FREQ) {
  1131. mdelay(CSIO_MB_POLL_FREQ);
  1132. /* Check for response */
  1133. ctl = csio_rd_reg32(hw, ctl_reg);
  1134. if (csio_mb_is_host_owner(MBOWNER_GET(ctl))) {
  1135. if (!(ctl & MBMSGVALID)) {
  1136. csio_wr_reg32(hw, 0, ctl_reg);
  1137. continue;
  1138. }
  1139. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1140. hdr = cpu_to_be64(csio_rd_reg64(hw, data_reg));
  1141. fw_hdr = (struct fw_cmd_hdr *)&hdr;
  1142. switch (FW_CMD_OP_GET(ntohl(fw_hdr->hi))) {
  1143. case FW_DEBUG_CMD:
  1144. csio_mb_debug_cmd_handler(hw);
  1145. continue;
  1146. }
  1147. /* Copy response */
  1148. for (i = 0; i < size; i += 8)
  1149. *cmd++ = cpu_to_be64(csio_rd_reg64
  1150. (hw, data_reg + i));
  1151. csio_wr_reg32(hw, 0, ctl_reg);
  1152. if (csio_mb_fw_retval(mbp) != FW_SUCCESS)
  1153. CSIO_INC_STATS(mbm, n_err);
  1154. CSIO_INC_STATS(mbm, n_rsp);
  1155. return 0;
  1156. }
  1157. }
  1158. CSIO_INC_STATS(mbm, n_tmo);
  1159. csio_err(hw, "Mailbox %x op:0x%x timed out!\n",
  1160. hw->pfn, *((uint8_t *)cmd));
  1161. return -ETIMEDOUT;
  1162. error_out:
  1163. CSIO_INC_STATS(mbm, n_err);
  1164. return rv;
  1165. }
  1166. /*
  1167. * csio_mb_completions - Completion handler for Mailbox commands
  1168. * @hw: The HW structure
  1169. * @cbfn_q: Completion queue.
  1170. *
  1171. */
  1172. void
  1173. csio_mb_completions(struct csio_hw *hw, struct list_head *cbfn_q)
  1174. {
  1175. struct csio_mb *mbp;
  1176. struct csio_mbm *mbm = &hw->mbm;
  1177. enum fw_retval rv;
  1178. while (!list_empty(cbfn_q)) {
  1179. mbp = list_first_entry(cbfn_q, struct csio_mb, list);
  1180. list_del_init(&mbp->list);
  1181. rv = csio_mb_fw_retval(mbp);
  1182. if ((rv != FW_SUCCESS) && (rv != FW_HOSTERROR))
  1183. CSIO_INC_STATS(mbm, n_err);
  1184. else if (rv != FW_HOSTERROR)
  1185. CSIO_INC_STATS(mbm, n_rsp);
  1186. if (mbp->mb_cbfn)
  1187. mbp->mb_cbfn(hw, mbp);
  1188. }
  1189. }
  1190. static void
  1191. csio_mb_portmod_changed(struct csio_hw *hw, uint8_t port_id)
  1192. {
  1193. static char *mod_str[] = {
  1194. NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
  1195. };
  1196. struct csio_pport *port = &hw->pport[port_id];
  1197. if (port->mod_type == FW_PORT_MOD_TYPE_NONE)
  1198. csio_info(hw, "Port:%d - port module unplugged\n", port_id);
  1199. else if (port->mod_type < ARRAY_SIZE(mod_str))
  1200. csio_info(hw, "Port:%d - %s port module inserted\n", port_id,
  1201. mod_str[port->mod_type]);
  1202. else if (port->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  1203. csio_info(hw,
  1204. "Port:%d - unsupported optical port module "
  1205. "inserted\n", port_id);
  1206. else if (port->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  1207. csio_info(hw,
  1208. "Port:%d - unknown port module inserted, forcing "
  1209. "TWINAX\n", port_id);
  1210. else if (port->mod_type == FW_PORT_MOD_TYPE_ERROR)
  1211. csio_info(hw, "Port:%d - transceiver module error\n", port_id);
  1212. else
  1213. csio_info(hw, "Port:%d - unknown module type %d inserted\n",
  1214. port_id, port->mod_type);
  1215. }
  1216. int
  1217. csio_mb_fwevt_handler(struct csio_hw *hw, __be64 *cmd)
  1218. {
  1219. uint8_t opcode = *(uint8_t *)cmd;
  1220. struct fw_port_cmd *pcmd;
  1221. uint8_t port_id;
  1222. uint32_t link_status;
  1223. uint16_t action;
  1224. uint8_t mod_type;
  1225. if (opcode == FW_PORT_CMD) {
  1226. pcmd = (struct fw_port_cmd *)cmd;
  1227. port_id = FW_PORT_CMD_PORTID_GET(
  1228. ntohl(pcmd->op_to_portid));
  1229. action = FW_PORT_CMD_ACTION_GET(
  1230. ntohl(pcmd->action_to_len16));
  1231. if (action != FW_PORT_ACTION_GET_PORT_INFO) {
  1232. csio_err(hw, "Unhandled FW_PORT_CMD action: %u\n",
  1233. action);
  1234. return -EINVAL;
  1235. }
  1236. link_status = ntohl(pcmd->u.info.lstatus_to_modtype);
  1237. mod_type = FW_PORT_CMD_MODTYPE_GET(link_status);
  1238. hw->pport[port_id].link_status =
  1239. FW_PORT_CMD_LSTATUS_GET(link_status);
  1240. hw->pport[port_id].link_speed =
  1241. FW_PORT_CMD_LSPEED_GET(link_status);
  1242. csio_info(hw, "Port:%x - LINK %s\n", port_id,
  1243. FW_PORT_CMD_LSTATUS_GET(link_status) ? "UP" : "DOWN");
  1244. if (mod_type != hw->pport[port_id].mod_type) {
  1245. hw->pport[port_id].mod_type = mod_type;
  1246. csio_mb_portmod_changed(hw, port_id);
  1247. }
  1248. } else if (opcode == FW_DEBUG_CMD) {
  1249. csio_mb_dump_fw_dbg(hw, cmd);
  1250. } else {
  1251. csio_dbg(hw, "Gen MB can't handle op:0x%x on evtq.\n", opcode);
  1252. return -EINVAL;
  1253. }
  1254. return 0;
  1255. }
  1256. /*
  1257. * csio_mb_isr_handler - Handle mailboxes related interrupts.
  1258. * @hw: The HW structure
  1259. *
  1260. * Called from the ISR to handle Mailbox related interrupts.
  1261. * HW Lock should be held across this call.
  1262. */
  1263. int
  1264. csio_mb_isr_handler(struct csio_hw *hw)
  1265. {
  1266. struct csio_mbm *mbm = &hw->mbm;
  1267. struct csio_mb *mbp = mbm->mcurrent;
  1268. __be64 *cmd;
  1269. uint32_t ctl, cim_cause, pl_cause;
  1270. int i;
  1271. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL);
  1272. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA);
  1273. int size;
  1274. __be64 hdr;
  1275. struct fw_cmd_hdr *fw_hdr;
  1276. pl_cause = csio_rd_reg32(hw, MYPF_REG(PL_PF_INT_CAUSE));
  1277. cim_cause = csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_CAUSE));
  1278. if (!(pl_cause & PFCIM) || !(cim_cause & MBMSGRDYINT)) {
  1279. CSIO_INC_STATS(hw, n_mbint_unexp);
  1280. return -EINVAL;
  1281. }
  1282. /*
  1283. * The cause registers below HAVE to be cleared in the SAME
  1284. * order as below: The low level cause register followed by
  1285. * the upper level cause register. In other words, CIM-cause
  1286. * first followed by PL-Cause next.
  1287. */
  1288. csio_wr_reg32(hw, MBMSGRDYINT, MYPF_REG(CIM_PF_HOST_INT_CAUSE));
  1289. csio_wr_reg32(hw, PFCIM, MYPF_REG(PL_PF_INT_CAUSE));
  1290. ctl = csio_rd_reg32(hw, ctl_reg);
  1291. if (csio_mb_is_host_owner(MBOWNER_GET(ctl))) {
  1292. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1293. if (!(ctl & MBMSGVALID)) {
  1294. csio_warn(hw,
  1295. "Stray mailbox interrupt recvd,"
  1296. " mailbox data not valid\n");
  1297. csio_wr_reg32(hw, 0, ctl_reg);
  1298. /* Flush */
  1299. csio_rd_reg32(hw, ctl_reg);
  1300. return -EINVAL;
  1301. }
  1302. hdr = cpu_to_be64(csio_rd_reg64(hw, data_reg));
  1303. fw_hdr = (struct fw_cmd_hdr *)&hdr;
  1304. switch (FW_CMD_OP_GET(ntohl(fw_hdr->hi))) {
  1305. case FW_DEBUG_CMD:
  1306. csio_mb_debug_cmd_handler(hw);
  1307. return -EINVAL;
  1308. #if 0
  1309. case FW_ERROR_CMD:
  1310. case FW_INITIALIZE_CMD: /* When we are not master */
  1311. #endif
  1312. }
  1313. CSIO_ASSERT(mbp != NULL);
  1314. cmd = mbp->mb;
  1315. size = mbp->mb_size;
  1316. /* Get response */
  1317. for (i = 0; i < size; i += 8)
  1318. *cmd++ = cpu_to_be64(csio_rd_reg64
  1319. (hw, data_reg + i));
  1320. csio_wr_reg32(hw, 0, ctl_reg);
  1321. /* Flush */
  1322. csio_rd_reg32(hw, ctl_reg);
  1323. mbm->mcurrent = NULL;
  1324. /* Add completion to tail of cbfn queue */
  1325. list_add_tail(&mbp->list, &mbm->cbfn_q);
  1326. CSIO_INC_STATS(mbm, n_cbfnq);
  1327. /*
  1328. * Enqueue event to EventQ. Events processing happens
  1329. * in Event worker thread context
  1330. */
  1331. if (csio_enqueue_evt(hw, CSIO_EVT_MBX, mbp, sizeof(mbp)))
  1332. CSIO_INC_STATS(hw, n_evt_drop);
  1333. return 0;
  1334. } else {
  1335. /*
  1336. * We can get here if mailbox MSIX vector is shared,
  1337. * or in INTx case. Or a stray interrupt.
  1338. */
  1339. csio_dbg(hw, "Host not owner, no mailbox interrupt\n");
  1340. CSIO_INC_STATS(hw, n_int_stray);
  1341. return -EINVAL;
  1342. }
  1343. }
  1344. /*
  1345. * csio_mb_tmo_handler - Timeout handler
  1346. * @hw: The HW structure
  1347. *
  1348. */
  1349. struct csio_mb *
  1350. csio_mb_tmo_handler(struct csio_hw *hw)
  1351. {
  1352. struct csio_mbm *mbm = &hw->mbm;
  1353. struct csio_mb *mbp = mbm->mcurrent;
  1354. struct fw_cmd_hdr *fw_hdr;
  1355. /*
  1356. * Could be a race b/w the completion handler and the timer
  1357. * and the completion handler won that race.
  1358. */
  1359. if (mbp == NULL) {
  1360. CSIO_DB_ASSERT(0);
  1361. return NULL;
  1362. }
  1363. fw_hdr = (struct fw_cmd_hdr *)(mbp->mb);
  1364. csio_dbg(hw, "Mailbox num:%x op:0x%x timed out\n", hw->pfn,
  1365. FW_CMD_OP_GET(ntohl(fw_hdr->hi)));
  1366. mbm->mcurrent = NULL;
  1367. CSIO_INC_STATS(mbm, n_tmo);
  1368. fw_hdr->lo = htonl(FW_CMD_RETVAL(FW_ETIMEDOUT));
  1369. return mbp;
  1370. }
  1371. /*
  1372. * csio_mb_cancel_all - Cancel all waiting commands.
  1373. * @hw: The HW structure
  1374. * @cbfn_q: The callback queue.
  1375. *
  1376. * Caller should hold hw lock across this call.
  1377. */
  1378. void
  1379. csio_mb_cancel_all(struct csio_hw *hw, struct list_head *cbfn_q)
  1380. {
  1381. struct csio_mb *mbp;
  1382. struct csio_mbm *mbm = &hw->mbm;
  1383. struct fw_cmd_hdr *hdr;
  1384. struct list_head *tmp;
  1385. if (mbm->mcurrent) {
  1386. mbp = mbm->mcurrent;
  1387. /* Stop mailbox completion timer */
  1388. del_timer_sync(&mbm->timer);
  1389. /* Add completion to tail of cbfn queue */
  1390. list_add_tail(&mbp->list, cbfn_q);
  1391. mbm->mcurrent = NULL;
  1392. }
  1393. if (!list_empty(&mbm->req_q)) {
  1394. list_splice_tail_init(&mbm->req_q, cbfn_q);
  1395. mbm->stats.n_activeq = 0;
  1396. }
  1397. if (!list_empty(&mbm->cbfn_q)) {
  1398. list_splice_tail_init(&mbm->cbfn_q, cbfn_q);
  1399. mbm->stats.n_cbfnq = 0;
  1400. }
  1401. if (list_empty(cbfn_q))
  1402. return;
  1403. list_for_each(tmp, cbfn_q) {
  1404. mbp = (struct csio_mb *)tmp;
  1405. hdr = (struct fw_cmd_hdr *)(mbp->mb);
  1406. csio_dbg(hw, "Cancelling pending mailbox num %x op:%x\n",
  1407. hw->pfn, FW_CMD_OP_GET(ntohl(hdr->hi)));
  1408. CSIO_INC_STATS(mbm, n_cancel);
  1409. hdr->lo = htonl(FW_CMD_RETVAL(FW_HOSTERROR));
  1410. }
  1411. }
  1412. /*
  1413. * csio_mbm_init - Initialize Mailbox module
  1414. * @mbm: Mailbox module
  1415. * @hw: The HW structure
  1416. * @timer: Timing function for interrupting mailboxes
  1417. *
  1418. * Initialize timer and the request/response queues.
  1419. */
  1420. int
  1421. csio_mbm_init(struct csio_mbm *mbm, struct csio_hw *hw,
  1422. void (*timer_fn)(uintptr_t))
  1423. {
  1424. struct timer_list *timer = &mbm->timer;
  1425. init_timer(timer);
  1426. timer->function = timer_fn;
  1427. timer->data = (unsigned long)hw;
  1428. INIT_LIST_HEAD(&mbm->req_q);
  1429. INIT_LIST_HEAD(&mbm->cbfn_q);
  1430. csio_set_mb_intr_idx(mbm, -1);
  1431. return 0;
  1432. }
  1433. /*
  1434. * csio_mbm_exit - Uninitialize mailbox module
  1435. * @mbm: Mailbox module
  1436. *
  1437. * Stop timer.
  1438. */
  1439. void
  1440. csio_mbm_exit(struct csio_mbm *mbm)
  1441. {
  1442. del_timer_sync(&mbm->timer);
  1443. CSIO_DB_ASSERT(mbm->mcurrent == NULL);
  1444. CSIO_DB_ASSERT(list_empty(&mbm->req_q));
  1445. CSIO_DB_ASSERT(list_empty(&mbm->cbfn_q));
  1446. }