csio_mb.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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_G(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_V(FW_HELLO_CMD) |
  76. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  77. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  78. cmdp->err_to_clearinit = htonl(
  79. FW_HELLO_CMD_MASTERDIS_V(master == CSIO_MASTER_CANT) |
  80. FW_HELLO_CMD_MASTERFORCE_V(master == CSIO_MASTER_MUST) |
  81. FW_HELLO_CMD_MBMASTER_V(master == CSIO_MASTER_MUST ?
  82. m_mbox : FW_HELLO_CMD_MBMASTER_M) |
  83. FW_HELLO_CMD_MBASYNCNOT_V(a_mbox) |
  84. FW_HELLO_CMD_STAGE_V(fw_hello_cmd_stage_os) |
  85. FW_HELLO_CMD_CLEARINIT_F);
  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_G(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_G(value);
  108. if (value & FW_HELLO_CMD_INIT_F)
  109. *state = CSIO_DEV_STATE_INIT;
  110. else if (value & FW_HELLO_CMD_ERR_F)
  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_V(FW_BYE_CMD) |
  130. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  131. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(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_V(FW_RESET_CMD) |
  149. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  150. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(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_V(FW_PARAMS_CMD) |
  180. FW_CMD_REQUEST_F |
  181. (wr ? FW_CMD_WRITE_F : FW_CMD_READ_F) |
  182. FW_PARAMS_CMD_PFN_V(pf) |
  183. FW_PARAMS_CMD_VFN_V(vf));
  184. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(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_G(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_V(FW_LDST_CMD) |
  241. FW_CMD_REQUEST_F |
  242. FW_CMD_READ_F |
  243. FW_LDST_CMD_ADDRSPACE_V(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_V(1);
  246. ldst_cmd->u.pcie.ctrl_to_fn =
  247. (FW_LDST_CMD_LC_F | FW_LDST_CMD_FN_V(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_V(FW_CAPS_CONFIG_CMD) |
  273. FW_CMD_REQUEST_F |
  274. (wr ? FW_CMD_WRITE_F : FW_CMD_READ_F));
  275. cmdp->cfvalid_to_len16 = htonl(FW_CMD_LEN16_V(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. /*
  289. * csio_mb_port- FW PORT command helper
  290. * @hw: The HW structure
  291. * @mbp: Mailbox structure
  292. * @tmo: COmmand timeout
  293. * @portid: Port ID to get/set info
  294. * @wr: Write/Read PORT information.
  295. * @fc: Flow control
  296. * @caps: Port capabilites to set.
  297. * @cbfn: Callback, if any.
  298. *
  299. */
  300. void
  301. csio_mb_port(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  302. u8 portid, bool wr, uint32_t fc, uint16_t fw_caps,
  303. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  304. {
  305. struct fw_port_cmd *cmdp = (struct fw_port_cmd *)(mbp->mb);
  306. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  307. cmdp->op_to_portid = htonl(FW_CMD_OP_V(FW_PORT_CMD) |
  308. FW_CMD_REQUEST_F |
  309. (wr ? FW_CMD_EXEC_F : FW_CMD_READ_F) |
  310. FW_PORT_CMD_PORTID_V(portid));
  311. if (!wr) {
  312. cmdp->action_to_len16 = htonl(
  313. FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
  314. ? FW_PORT_ACTION_GET_PORT_INFO
  315. : FW_PORT_ACTION_GET_PORT_INFO32) |
  316. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  317. return;
  318. }
  319. /* Set port */
  320. cmdp->action_to_len16 = htonl(
  321. FW_PORT_CMD_ACTION_V(fw_caps == FW_CAPS16
  322. ? FW_PORT_ACTION_L1_CFG
  323. : FW_PORT_ACTION_L1_CFG32) |
  324. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  325. if (fw_caps == FW_CAPS16)
  326. cmdp->u.l1cfg.rcap = cpu_to_be32(fwcaps32_to_caps16(fc));
  327. else
  328. cmdp->u.l1cfg32.rcap32 = cpu_to_be32(fc);
  329. }
  330. /*
  331. * csio_mb_process_read_port_rsp - FW PORT command response processing helper
  332. * @hw: The HW structure
  333. * @mbp: Mailbox structure
  334. * @retval: Mailbox return value from Firmware
  335. * @caps: port capabilities
  336. *
  337. */
  338. void
  339. csio_mb_process_read_port_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  340. enum fw_retval *retval, uint16_t fw_caps,
  341. u32 *pcaps, u32 *acaps)
  342. {
  343. struct fw_port_cmd *rsp = (struct fw_port_cmd *)(mbp->mb);
  344. *retval = FW_CMD_RETVAL_G(ntohl(rsp->action_to_len16));
  345. if (*retval == FW_SUCCESS) {
  346. if (fw_caps == FW_CAPS16) {
  347. *pcaps = fwcaps16_to_caps32(ntohs(rsp->u.info.pcap));
  348. *acaps = fwcaps16_to_caps32(ntohs(rsp->u.info.acap));
  349. } else {
  350. *pcaps = be32_to_cpu(rsp->u.info32.pcaps32);
  351. *acaps = be32_to_cpu(rsp->u.info32.acaps32);
  352. }
  353. }
  354. }
  355. /*
  356. * csio_mb_initialize - FW INITIALIZE command helper
  357. * @hw: The HW structure
  358. * @mbp: Mailbox structure
  359. * @tmo: COmmand timeout
  360. * @cbfn: Callback, if any.
  361. *
  362. */
  363. void
  364. csio_mb_initialize(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  365. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  366. {
  367. struct fw_initialize_cmd *cmdp = (struct fw_initialize_cmd *)(mbp->mb);
  368. CSIO_INIT_MBP(mbp, cmdp, tmo, hw, cbfn, 1);
  369. cmdp->op_to_write = htonl(FW_CMD_OP_V(FW_INITIALIZE_CMD) |
  370. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  371. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  372. }
  373. /*
  374. * csio_mb_iq_alloc - Initializes the mailbox to allocate an
  375. * Ingress DMA queue in the firmware.
  376. *
  377. * @hw: The hw structure
  378. * @mbp: Mailbox structure to initialize
  379. * @priv: Private object
  380. * @mb_tmo: Mailbox time-out period (in ms).
  381. * @iq_params: Ingress queue params needed for allocation.
  382. * @cbfn: The call-back function
  383. *
  384. *
  385. */
  386. static void
  387. csio_mb_iq_alloc(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  388. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  389. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  390. {
  391. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  392. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  393. cmdp->op_to_vfn = htonl(FW_CMD_OP_V(FW_IQ_CMD) |
  394. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  395. FW_IQ_CMD_PFN_V(iq_params->pfn) |
  396. FW_IQ_CMD_VFN_V(iq_params->vfn));
  397. cmdp->alloc_to_len16 = htonl(FW_IQ_CMD_ALLOC_F |
  398. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  399. cmdp->type_to_iqandstindex = htonl(
  400. FW_IQ_CMD_VIID_V(iq_params->viid) |
  401. FW_IQ_CMD_TYPE_V(iq_params->type) |
  402. FW_IQ_CMD_IQASYNCH_V(iq_params->iqasynch));
  403. cmdp->fl0size = htons(iq_params->fl0size);
  404. cmdp->fl0size = htons(iq_params->fl1size);
  405. } /* csio_mb_iq_alloc */
  406. /*
  407. * csio_mb_iq_write - Initializes the mailbox for writing into an
  408. * Ingress DMA Queue.
  409. *
  410. * @hw: The HW structure
  411. * @mbp: Mailbox structure to initialize
  412. * @priv: Private object
  413. * @mb_tmo: Mailbox time-out period (in ms).
  414. * @cascaded_req: TRUE - if this request is cascased with iq-alloc request.
  415. * @iq_params: Ingress queue params needed for writing.
  416. * @cbfn: The call-back function
  417. *
  418. * NOTE: We OR relevant bits with cmdp->XXX, instead of just equating,
  419. * because this IQ write request can be cascaded with a previous
  420. * IQ alloc request, and we dont want to over-write the bits set by
  421. * that request. This logic will work even in a non-cascaded case, since the
  422. * cmdp structure is zeroed out by CSIO_INIT_MBP.
  423. */
  424. static void
  425. csio_mb_iq_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  426. uint32_t mb_tmo, bool cascaded_req,
  427. struct csio_iq_params *iq_params,
  428. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  429. {
  430. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  431. uint32_t iq_start_stop = (iq_params->iq_start) ?
  432. FW_IQ_CMD_IQSTART_F :
  433. FW_IQ_CMD_IQSTOP_F;
  434. int relaxed = !(hw->flags & CSIO_HWF_ROOT_NO_RELAXED_ORDERING);
  435. /*
  436. * If this IQ write is cascaded with IQ alloc request, do not
  437. * re-initialize with 0's.
  438. *
  439. */
  440. if (!cascaded_req)
  441. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  442. cmdp->op_to_vfn |= htonl(FW_CMD_OP_V(FW_IQ_CMD) |
  443. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  444. FW_IQ_CMD_PFN_V(iq_params->pfn) |
  445. FW_IQ_CMD_VFN_V(iq_params->vfn));
  446. cmdp->alloc_to_len16 |= htonl(iq_start_stop |
  447. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  448. cmdp->iqid |= htons(iq_params->iqid);
  449. cmdp->fl0id |= htons(iq_params->fl0id);
  450. cmdp->fl1id |= htons(iq_params->fl1id);
  451. cmdp->type_to_iqandstindex |= htonl(
  452. FW_IQ_CMD_IQANDST_V(iq_params->iqandst) |
  453. FW_IQ_CMD_IQANUS_V(iq_params->iqanus) |
  454. FW_IQ_CMD_IQANUD_V(iq_params->iqanud) |
  455. FW_IQ_CMD_IQANDSTINDEX_V(iq_params->iqandstindex));
  456. cmdp->iqdroprss_to_iqesize |= htons(
  457. FW_IQ_CMD_IQPCIECH_V(iq_params->iqpciech) |
  458. FW_IQ_CMD_IQDCAEN_V(iq_params->iqdcaen) |
  459. FW_IQ_CMD_IQDCACPU_V(iq_params->iqdcacpu) |
  460. FW_IQ_CMD_IQINTCNTTHRESH_V(iq_params->iqintcntthresh) |
  461. FW_IQ_CMD_IQCPRIO_V(iq_params->iqcprio) |
  462. FW_IQ_CMD_IQESIZE_V(iq_params->iqesize));
  463. cmdp->iqsize |= htons(iq_params->iqsize);
  464. cmdp->iqaddr |= cpu_to_be64(iq_params->iqaddr);
  465. if (iq_params->type == 0) {
  466. cmdp->iqns_to_fl0congen |= htonl(
  467. FW_IQ_CMD_IQFLINTIQHSEN_V(iq_params->iqflintiqhsen)|
  468. FW_IQ_CMD_IQFLINTCONGEN_V(iq_params->iqflintcongen));
  469. }
  470. if (iq_params->fl0size && iq_params->fl0addr &&
  471. (iq_params->fl0id != 0xFFFF)) {
  472. cmdp->iqns_to_fl0congen |= htonl(
  473. FW_IQ_CMD_FL0HOSTFCMODE_V(iq_params->fl0hostfcmode)|
  474. FW_IQ_CMD_FL0CPRIO_V(iq_params->fl0cprio) |
  475. FW_IQ_CMD_FL0FETCHRO_V(relaxed) |
  476. FW_IQ_CMD_FL0DATARO_V(relaxed) |
  477. FW_IQ_CMD_FL0PADEN_V(iq_params->fl0paden) |
  478. FW_IQ_CMD_FL0PACKEN_V(iq_params->fl0packen));
  479. cmdp->fl0dcaen_to_fl0cidxfthresh |= htons(
  480. FW_IQ_CMD_FL0DCAEN_V(iq_params->fl0dcaen) |
  481. FW_IQ_CMD_FL0DCACPU_V(iq_params->fl0dcacpu) |
  482. FW_IQ_CMD_FL0FBMIN_V(iq_params->fl0fbmin) |
  483. FW_IQ_CMD_FL0FBMAX_V(iq_params->fl0fbmax) |
  484. FW_IQ_CMD_FL0CIDXFTHRESH_V(iq_params->fl0cidxfthresh));
  485. cmdp->fl0size |= htons(iq_params->fl0size);
  486. cmdp->fl0addr |= cpu_to_be64(iq_params->fl0addr);
  487. }
  488. } /* csio_mb_iq_write */
  489. /*
  490. * csio_mb_iq_alloc_write - Initializes the mailbox for allocating an
  491. * Ingress DMA Queue.
  492. *
  493. * @hw: The HW structure
  494. * @mbp: Mailbox structure to initialize
  495. * @priv: Private data.
  496. * @mb_tmo: Mailbox time-out period (in ms).
  497. * @iq_params: Ingress queue params needed for allocation & writing.
  498. * @cbfn: The call-back function
  499. *
  500. *
  501. */
  502. void
  503. csio_mb_iq_alloc_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  504. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  505. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  506. {
  507. csio_mb_iq_alloc(hw, mbp, priv, mb_tmo, iq_params, cbfn);
  508. csio_mb_iq_write(hw, mbp, priv, mb_tmo, true, iq_params, cbfn);
  509. } /* csio_mb_iq_alloc_write */
  510. /*
  511. * csio_mb_iq_alloc_write_rsp - Process the allocation & writing
  512. * of ingress DMA queue mailbox's response.
  513. *
  514. * @hw: The HW structure.
  515. * @mbp: Mailbox structure to initialize.
  516. * @retval: Firmware return value.
  517. * @iq_params: Ingress queue parameters, after allocation and write.
  518. *
  519. */
  520. void
  521. csio_mb_iq_alloc_write_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  522. enum fw_retval *ret_val,
  523. struct csio_iq_params *iq_params)
  524. {
  525. struct fw_iq_cmd *rsp = (struct fw_iq_cmd *)(mbp->mb);
  526. *ret_val = FW_CMD_RETVAL_G(ntohl(rsp->alloc_to_len16));
  527. if (*ret_val == FW_SUCCESS) {
  528. iq_params->physiqid = ntohs(rsp->physiqid);
  529. iq_params->iqid = ntohs(rsp->iqid);
  530. iq_params->fl0id = ntohs(rsp->fl0id);
  531. iq_params->fl1id = ntohs(rsp->fl1id);
  532. } else {
  533. iq_params->physiqid = iq_params->iqid =
  534. iq_params->fl0id = iq_params->fl1id = 0;
  535. }
  536. } /* csio_mb_iq_alloc_write_rsp */
  537. /*
  538. * csio_mb_iq_free - Initializes the mailbox for freeing a
  539. * specified Ingress DMA Queue.
  540. *
  541. * @hw: The HW structure
  542. * @mbp: Mailbox structure to initialize
  543. * @priv: Private data
  544. * @mb_tmo: Mailbox time-out period (in ms).
  545. * @iq_params: Parameters of ingress queue, that is to be freed.
  546. * @cbfn: The call-back function
  547. *
  548. *
  549. */
  550. void
  551. csio_mb_iq_free(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  552. uint32_t mb_tmo, struct csio_iq_params *iq_params,
  553. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  554. {
  555. struct fw_iq_cmd *cmdp = (struct fw_iq_cmd *)(mbp->mb);
  556. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  557. cmdp->op_to_vfn = htonl(FW_CMD_OP_V(FW_IQ_CMD) |
  558. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  559. FW_IQ_CMD_PFN_V(iq_params->pfn) |
  560. FW_IQ_CMD_VFN_V(iq_params->vfn));
  561. cmdp->alloc_to_len16 = htonl(FW_IQ_CMD_FREE_F |
  562. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  563. cmdp->type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE_V(iq_params->type));
  564. cmdp->iqid = htons(iq_params->iqid);
  565. cmdp->fl0id = htons(iq_params->fl0id);
  566. cmdp->fl1id = htons(iq_params->fl1id);
  567. } /* csio_mb_iq_free */
  568. /*
  569. * csio_mb_eq_ofld_alloc - Initializes the mailbox for allocating
  570. * an offload-egress queue.
  571. *
  572. * @hw: The HW structure
  573. * @mbp: Mailbox structure to initialize
  574. * @priv: Private data
  575. * @mb_tmo: Mailbox time-out period (in ms).
  576. * @eq_ofld_params: (Offload) Egress queue parameters.
  577. * @cbfn: The call-back function
  578. *
  579. *
  580. */
  581. static void
  582. csio_mb_eq_ofld_alloc(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  583. uint32_t mb_tmo, struct csio_eq_params *eq_ofld_params,
  584. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  585. {
  586. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  587. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  588. cmdp->op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
  589. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  590. FW_EQ_OFLD_CMD_PFN_V(eq_ofld_params->pfn) |
  591. FW_EQ_OFLD_CMD_VFN_V(eq_ofld_params->vfn));
  592. cmdp->alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_ALLOC_F |
  593. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  594. } /* csio_mb_eq_ofld_alloc */
  595. /*
  596. * csio_mb_eq_ofld_write - Initializes the mailbox for writing
  597. * an alloacted offload-egress queue.
  598. *
  599. * @hw: The HW structure
  600. * @mbp: Mailbox structure to initialize
  601. * @priv: Private data
  602. * @mb_tmo: Mailbox time-out period (in ms).
  603. * @cascaded_req: TRUE - if this request is cascased with Eq-alloc request.
  604. * @eq_ofld_params: (Offload) Egress queue parameters.
  605. * @cbfn: The call-back function
  606. *
  607. *
  608. * NOTE: We OR relevant bits with cmdp->XXX, instead of just equating,
  609. * because this EQ write request can be cascaded with a previous
  610. * EQ alloc request, and we dont want to over-write the bits set by
  611. * that request. This logic will work even in a non-cascaded case, since the
  612. * cmdp structure is zeroed out by CSIO_INIT_MBP.
  613. */
  614. static void
  615. csio_mb_eq_ofld_write(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  616. uint32_t mb_tmo, bool cascaded_req,
  617. struct csio_eq_params *eq_ofld_params,
  618. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  619. {
  620. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  621. uint32_t eq_start_stop = (eq_ofld_params->eqstart) ?
  622. FW_EQ_OFLD_CMD_EQSTART_F :
  623. FW_EQ_OFLD_CMD_EQSTOP_F;
  624. /*
  625. * If this EQ write is cascaded with EQ alloc request, do not
  626. * re-initialize with 0's.
  627. *
  628. */
  629. if (!cascaded_req)
  630. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  631. cmdp->op_to_vfn |= htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
  632. FW_CMD_REQUEST_F | FW_CMD_WRITE_F |
  633. FW_EQ_OFLD_CMD_PFN_V(eq_ofld_params->pfn) |
  634. FW_EQ_OFLD_CMD_VFN_V(eq_ofld_params->vfn));
  635. cmdp->alloc_to_len16 |= htonl(eq_start_stop |
  636. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  637. cmdp->eqid_pkd |= htonl(FW_EQ_OFLD_CMD_EQID_V(eq_ofld_params->eqid));
  638. cmdp->fetchszm_to_iqid |= htonl(
  639. FW_EQ_OFLD_CMD_HOSTFCMODE_V(eq_ofld_params->hostfcmode) |
  640. FW_EQ_OFLD_CMD_CPRIO_V(eq_ofld_params->cprio) |
  641. FW_EQ_OFLD_CMD_PCIECHN_V(eq_ofld_params->pciechn) |
  642. FW_EQ_OFLD_CMD_IQID_V(eq_ofld_params->iqid));
  643. cmdp->dcaen_to_eqsize |= htonl(
  644. FW_EQ_OFLD_CMD_DCAEN_V(eq_ofld_params->dcaen) |
  645. FW_EQ_OFLD_CMD_DCACPU_V(eq_ofld_params->dcacpu) |
  646. FW_EQ_OFLD_CMD_FBMIN_V(eq_ofld_params->fbmin) |
  647. FW_EQ_OFLD_CMD_FBMAX_V(eq_ofld_params->fbmax) |
  648. FW_EQ_OFLD_CMD_CIDXFTHRESHO_V(eq_ofld_params->cidxfthresho) |
  649. FW_EQ_OFLD_CMD_CIDXFTHRESH_V(eq_ofld_params->cidxfthresh) |
  650. FW_EQ_OFLD_CMD_EQSIZE_V(eq_ofld_params->eqsize));
  651. cmdp->eqaddr |= cpu_to_be64(eq_ofld_params->eqaddr);
  652. } /* csio_mb_eq_ofld_write */
  653. /*
  654. * csio_mb_eq_ofld_alloc_write - Initializes the mailbox for allocation
  655. * writing into an Engress DMA Queue.
  656. *
  657. * @hw: The HW structure
  658. * @mbp: Mailbox structure to initialize
  659. * @priv: Private data.
  660. * @mb_tmo: Mailbox time-out period (in ms).
  661. * @eq_ofld_params: (Offload) Egress queue parameters.
  662. * @cbfn: The call-back function
  663. *
  664. *
  665. */
  666. void
  667. csio_mb_eq_ofld_alloc_write(struct csio_hw *hw, struct csio_mb *mbp,
  668. void *priv, uint32_t mb_tmo,
  669. struct csio_eq_params *eq_ofld_params,
  670. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  671. {
  672. csio_mb_eq_ofld_alloc(hw, mbp, priv, mb_tmo, eq_ofld_params, cbfn);
  673. csio_mb_eq_ofld_write(hw, mbp, priv, mb_tmo, true,
  674. eq_ofld_params, cbfn);
  675. } /* csio_mb_eq_ofld_alloc_write */
  676. /*
  677. * csio_mb_eq_ofld_alloc_write_rsp - Process the allocation
  678. * & write egress DMA queue mailbox's response.
  679. *
  680. * @hw: The HW structure.
  681. * @mbp: Mailbox structure to initialize.
  682. * @retval: Firmware return value.
  683. * @eq_ofld_params: (Offload) Egress queue parameters.
  684. *
  685. */
  686. void
  687. csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *hw,
  688. struct csio_mb *mbp, enum fw_retval *ret_val,
  689. struct csio_eq_params *eq_ofld_params)
  690. {
  691. struct fw_eq_ofld_cmd *rsp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  692. *ret_val = FW_CMD_RETVAL_G(ntohl(rsp->alloc_to_len16));
  693. if (*ret_val == FW_SUCCESS) {
  694. eq_ofld_params->eqid = FW_EQ_OFLD_CMD_EQID_G(
  695. ntohl(rsp->eqid_pkd));
  696. eq_ofld_params->physeqid = FW_EQ_OFLD_CMD_PHYSEQID_G(
  697. ntohl(rsp->physeqid_pkd));
  698. } else
  699. eq_ofld_params->eqid = 0;
  700. } /* csio_mb_eq_ofld_alloc_write_rsp */
  701. /*
  702. * csio_mb_eq_ofld_free - Initializes the mailbox for freeing a
  703. * specified Engress DMA Queue.
  704. *
  705. * @hw: The HW structure
  706. * @mbp: Mailbox structure to initialize
  707. * @priv: Private data area.
  708. * @mb_tmo: Mailbox time-out period (in ms).
  709. * @eq_ofld_params: (Offload) Egress queue parameters, that is to be freed.
  710. * @cbfn: The call-back function
  711. *
  712. *
  713. */
  714. void
  715. csio_mb_eq_ofld_free(struct csio_hw *hw, struct csio_mb *mbp, void *priv,
  716. uint32_t mb_tmo, struct csio_eq_params *eq_ofld_params,
  717. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  718. {
  719. struct fw_eq_ofld_cmd *cmdp = (struct fw_eq_ofld_cmd *)(mbp->mb);
  720. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, priv, cbfn, 1);
  721. cmdp->op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) |
  722. FW_CMD_REQUEST_F | FW_CMD_EXEC_F |
  723. FW_EQ_OFLD_CMD_PFN_V(eq_ofld_params->pfn) |
  724. FW_EQ_OFLD_CMD_VFN_V(eq_ofld_params->vfn));
  725. cmdp->alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_FREE_F |
  726. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  727. cmdp->eqid_pkd = htonl(FW_EQ_OFLD_CMD_EQID_V(eq_ofld_params->eqid));
  728. } /* csio_mb_eq_ofld_free */
  729. /*
  730. * csio_write_fcoe_link_cond_init_mb - Initialize Mailbox to write FCoE link
  731. * condition.
  732. *
  733. * @ln: The Lnode structure
  734. * @mbp: Mailbox structure to initialize
  735. * @mb_tmo: Mailbox time-out period (in ms).
  736. * @cbfn: The call back function.
  737. *
  738. *
  739. */
  740. void
  741. csio_write_fcoe_link_cond_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  742. uint32_t mb_tmo, uint8_t port_id, uint32_t sub_opcode,
  743. uint8_t cos, bool link_status, uint32_t fcfi,
  744. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  745. {
  746. struct fw_fcoe_link_cmd *cmdp =
  747. (struct fw_fcoe_link_cmd *)(mbp->mb);
  748. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  749. cmdp->op_to_portid = htonl((
  750. FW_CMD_OP_V(FW_FCOE_LINK_CMD) |
  751. FW_CMD_REQUEST_F |
  752. FW_CMD_WRITE_F |
  753. FW_FCOE_LINK_CMD_PORTID(port_id)));
  754. cmdp->sub_opcode_fcfi = htonl(
  755. FW_FCOE_LINK_CMD_SUB_OPCODE(sub_opcode) |
  756. FW_FCOE_LINK_CMD_FCFI(fcfi));
  757. cmdp->lstatus = link_status;
  758. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  759. } /* csio_write_fcoe_link_cond_init_mb */
  760. /*
  761. * csio_fcoe_read_res_info_init_mb - Initializes the mailbox for reading FCoE
  762. * resource information(FW_GET_RES_INFO_CMD).
  763. *
  764. * @hw: The HW structure
  765. * @mbp: Mailbox structure to initialize
  766. * @mb_tmo: Mailbox time-out period (in ms).
  767. * @cbfn: The call-back function
  768. *
  769. *
  770. */
  771. void
  772. csio_fcoe_read_res_info_init_mb(struct csio_hw *hw, struct csio_mb *mbp,
  773. uint32_t mb_tmo,
  774. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  775. {
  776. struct fw_fcoe_res_info_cmd *cmdp =
  777. (struct fw_fcoe_res_info_cmd *)(mbp->mb);
  778. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, hw, cbfn, 1);
  779. cmdp->op_to_read = htonl((FW_CMD_OP_V(FW_FCOE_RES_INFO_CMD) |
  780. FW_CMD_REQUEST_F |
  781. FW_CMD_READ_F));
  782. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  783. } /* csio_fcoe_read_res_info_init_mb */
  784. /*
  785. * csio_fcoe_vnp_alloc_init_mb - Initializes the mailbox for allocating VNP
  786. * in the firmware (FW_FCOE_VNP_CMD).
  787. *
  788. * @ln: The Lnode structure.
  789. * @mbp: Mailbox structure to initialize.
  790. * @mb_tmo: Mailbox time-out period (in ms).
  791. * @fcfi: FCF Index.
  792. * @vnpi: vnpi
  793. * @iqid: iqid
  794. * @vnport_wwnn: vnport WWNN
  795. * @vnport_wwpn: vnport WWPN
  796. * @cbfn: The call-back function.
  797. *
  798. *
  799. */
  800. void
  801. csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  802. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi, uint16_t iqid,
  803. uint8_t vnport_wwnn[8], uint8_t vnport_wwpn[8],
  804. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  805. {
  806. struct fw_fcoe_vnp_cmd *cmdp =
  807. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  808. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  809. cmdp->op_to_fcfi = htonl((FW_CMD_OP_V(FW_FCOE_VNP_CMD) |
  810. FW_CMD_REQUEST_F |
  811. FW_CMD_EXEC_F |
  812. FW_FCOE_VNP_CMD_FCFI(fcfi)));
  813. cmdp->alloc_to_len16 = htonl(FW_FCOE_VNP_CMD_ALLOC |
  814. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  815. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  816. cmdp->iqid = htons(iqid);
  817. if (!wwn_to_u64(vnport_wwnn) && !wwn_to_u64(vnport_wwpn))
  818. cmdp->gen_wwn_to_vnpi |= htonl(FW_FCOE_VNP_CMD_GEN_WWN);
  819. if (vnport_wwnn)
  820. memcpy(cmdp->vnport_wwnn, vnport_wwnn, 8);
  821. if (vnport_wwpn)
  822. memcpy(cmdp->vnport_wwpn, vnport_wwpn, 8);
  823. } /* csio_fcoe_vnp_alloc_init_mb */
  824. /*
  825. * csio_fcoe_vnp_read_init_mb - Prepares VNP read cmd.
  826. * @ln: The Lnode structure.
  827. * @mbp: Mailbox structure to initialize.
  828. * @mb_tmo: Mailbox time-out period (in ms).
  829. * @fcfi: FCF Index.
  830. * @vnpi: vnpi
  831. * @cbfn: The call-back handler.
  832. */
  833. void
  834. csio_fcoe_vnp_read_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  835. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi,
  836. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  837. {
  838. struct fw_fcoe_vnp_cmd *cmdp =
  839. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  840. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  841. cmdp->op_to_fcfi = htonl(FW_CMD_OP_V(FW_FCOE_VNP_CMD) |
  842. FW_CMD_REQUEST_F |
  843. FW_CMD_READ_F |
  844. FW_FCOE_VNP_CMD_FCFI(fcfi));
  845. cmdp->alloc_to_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  846. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  847. }
  848. /*
  849. * csio_fcoe_vnp_free_init_mb - Initializes the mailbox for freeing an
  850. * alloacted VNP in the firmware (FW_FCOE_VNP_CMD).
  851. *
  852. * @ln: The Lnode structure.
  853. * @mbp: Mailbox structure to initialize.
  854. * @mb_tmo: Mailbox time-out period (in ms).
  855. * @fcfi: FCF flow id
  856. * @vnpi: VNP flow id
  857. * @cbfn: The call-back function.
  858. * Return: None
  859. */
  860. void
  861. csio_fcoe_vnp_free_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  862. uint32_t mb_tmo, uint32_t fcfi, uint32_t vnpi,
  863. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  864. {
  865. struct fw_fcoe_vnp_cmd *cmdp =
  866. (struct fw_fcoe_vnp_cmd *)(mbp->mb);
  867. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  868. cmdp->op_to_fcfi = htonl(FW_CMD_OP_V(FW_FCOE_VNP_CMD) |
  869. FW_CMD_REQUEST_F |
  870. FW_CMD_EXEC_F |
  871. FW_FCOE_VNP_CMD_FCFI(fcfi));
  872. cmdp->alloc_to_len16 = htonl(FW_FCOE_VNP_CMD_FREE |
  873. FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  874. cmdp->gen_wwn_to_vnpi = htonl(FW_FCOE_VNP_CMD_VNPI(vnpi));
  875. }
  876. /*
  877. * csio_fcoe_read_fcf_init_mb - Initializes the mailbox to read the
  878. * FCF records.
  879. *
  880. * @ln: The Lnode structure
  881. * @mbp: Mailbox structure to initialize
  882. * @mb_tmo: Mailbox time-out period (in ms).
  883. * @fcf_params: FC-Forwarder parameters.
  884. * @cbfn: The call-back function
  885. *
  886. *
  887. */
  888. void
  889. csio_fcoe_read_fcf_init_mb(struct csio_lnode *ln, struct csio_mb *mbp,
  890. uint32_t mb_tmo, uint32_t portid, uint32_t fcfi,
  891. void (*cbfn) (struct csio_hw *, struct csio_mb *))
  892. {
  893. struct fw_fcoe_fcf_cmd *cmdp =
  894. (struct fw_fcoe_fcf_cmd *)(mbp->mb);
  895. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, ln, cbfn, 1);
  896. cmdp->op_to_fcfi = htonl(FW_CMD_OP_V(FW_FCOE_FCF_CMD) |
  897. FW_CMD_REQUEST_F |
  898. FW_CMD_READ_F |
  899. FW_FCOE_FCF_CMD_FCFI(fcfi));
  900. cmdp->retval_len16 = htonl(FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
  901. } /* csio_fcoe_read_fcf_init_mb */
  902. void
  903. csio_fcoe_read_portparams_init_mb(struct csio_hw *hw, struct csio_mb *mbp,
  904. uint32_t mb_tmo,
  905. struct fw_fcoe_port_cmd_params *portparams,
  906. void (*cbfn)(struct csio_hw *,
  907. struct csio_mb *))
  908. {
  909. struct fw_fcoe_stats_cmd *cmdp = (struct fw_fcoe_stats_cmd *)(mbp->mb);
  910. CSIO_INIT_MBP(mbp, cmdp, mb_tmo, hw, cbfn, 1);
  911. mbp->mb_size = 64;
  912. cmdp->op_to_flowid = htonl(FW_CMD_OP_V(FW_FCOE_STATS_CMD) |
  913. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  914. cmdp->free_to_len16 = htonl(FW_CMD_LEN16_V(CSIO_MAX_MB_SIZE/16));
  915. cmdp->u.ctl.nstats_port = FW_FCOE_STATS_CMD_NSTATS(portparams->nstats) |
  916. FW_FCOE_STATS_CMD_PORT(portparams->portid);
  917. cmdp->u.ctl.port_valid_ix = FW_FCOE_STATS_CMD_IX(portparams->idx) |
  918. FW_FCOE_STATS_CMD_PORT_VALID;
  919. } /* csio_fcoe_read_portparams_init_mb */
  920. void
  921. csio_mb_process_portparams_rsp(struct csio_hw *hw,
  922. struct csio_mb *mbp,
  923. enum fw_retval *retval,
  924. struct fw_fcoe_port_cmd_params *portparams,
  925. struct fw_fcoe_port_stats *portstats)
  926. {
  927. struct fw_fcoe_stats_cmd *rsp = (struct fw_fcoe_stats_cmd *)(mbp->mb);
  928. struct fw_fcoe_port_stats stats;
  929. uint8_t *src;
  930. uint8_t *dst;
  931. *retval = FW_CMD_RETVAL_G(ntohl(rsp->free_to_len16));
  932. memset(&stats, 0, sizeof(struct fw_fcoe_port_stats));
  933. if (*retval == FW_SUCCESS) {
  934. dst = (uint8_t *)(&stats) + ((portparams->idx - 1) * 8);
  935. src = (uint8_t *)rsp + (CSIO_STATS_OFFSET * 8);
  936. memcpy(dst, src, (portparams->nstats * 8));
  937. if (portparams->idx == 1) {
  938. /* Get the first 6 flits from the Mailbox */
  939. portstats->tx_bcast_bytes = stats.tx_bcast_bytes;
  940. portstats->tx_bcast_frames = stats.tx_bcast_frames;
  941. portstats->tx_mcast_bytes = stats.tx_mcast_bytes;
  942. portstats->tx_mcast_frames = stats.tx_mcast_frames;
  943. portstats->tx_ucast_bytes = stats.tx_ucast_bytes;
  944. portstats->tx_ucast_frames = stats.tx_ucast_frames;
  945. }
  946. if (portparams->idx == 7) {
  947. /* Get the second 6 flits from the Mailbox */
  948. portstats->tx_drop_frames = stats.tx_drop_frames;
  949. portstats->tx_offload_bytes = stats.tx_offload_bytes;
  950. portstats->tx_offload_frames = stats.tx_offload_frames;
  951. #if 0
  952. portstats->rx_pf_bytes = stats.rx_pf_bytes;
  953. portstats->rx_pf_frames = stats.rx_pf_frames;
  954. #endif
  955. portstats->rx_bcast_bytes = stats.rx_bcast_bytes;
  956. portstats->rx_bcast_frames = stats.rx_bcast_frames;
  957. portstats->rx_mcast_bytes = stats.rx_mcast_bytes;
  958. }
  959. if (portparams->idx == 13) {
  960. /* Get the last 4 flits from the Mailbox */
  961. portstats->rx_mcast_frames = stats.rx_mcast_frames;
  962. portstats->rx_ucast_bytes = stats.rx_ucast_bytes;
  963. portstats->rx_ucast_frames = stats.rx_ucast_frames;
  964. portstats->rx_err_frames = stats.rx_err_frames;
  965. }
  966. }
  967. }
  968. /* Entry points/APIs for MB module */
  969. /*
  970. * csio_mb_intr_enable - Enable Interrupts from mailboxes.
  971. * @hw: The HW structure
  972. *
  973. * Enables CIM interrupt bit in appropriate INT_ENABLE registers.
  974. */
  975. void
  976. csio_mb_intr_enable(struct csio_hw *hw)
  977. {
  978. csio_wr_reg32(hw, MBMSGRDYINTEN_F, MYPF_REG(CIM_PF_HOST_INT_ENABLE_A));
  979. csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_ENABLE_A));
  980. }
  981. /*
  982. * csio_mb_intr_disable - Disable Interrupts from mailboxes.
  983. * @hw: The HW structure
  984. *
  985. * Disable bit in HostInterruptEnable CIM register.
  986. */
  987. void
  988. csio_mb_intr_disable(struct csio_hw *hw)
  989. {
  990. csio_wr_reg32(hw, MBMSGRDYINTEN_V(0),
  991. MYPF_REG(CIM_PF_HOST_INT_ENABLE_A));
  992. csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_ENABLE_A));
  993. }
  994. static void
  995. csio_mb_dump_fw_dbg(struct csio_hw *hw, __be64 *cmd)
  996. {
  997. struct fw_debug_cmd *dbg = (struct fw_debug_cmd *)cmd;
  998. if ((FW_DEBUG_CMD_TYPE_G(ntohl(dbg->op_type))) == 1) {
  999. csio_info(hw, "FW print message:\n");
  1000. csio_info(hw, "\tdebug->dprtstridx = %d\n",
  1001. ntohs(dbg->u.prt.dprtstridx));
  1002. csio_info(hw, "\tdebug->dprtstrparam0 = 0x%x\n",
  1003. ntohl(dbg->u.prt.dprtstrparam0));
  1004. csio_info(hw, "\tdebug->dprtstrparam1 = 0x%x\n",
  1005. ntohl(dbg->u.prt.dprtstrparam1));
  1006. csio_info(hw, "\tdebug->dprtstrparam2 = 0x%x\n",
  1007. ntohl(dbg->u.prt.dprtstrparam2));
  1008. csio_info(hw, "\tdebug->dprtstrparam3 = 0x%x\n",
  1009. ntohl(dbg->u.prt.dprtstrparam3));
  1010. } else {
  1011. /* This is a FW assertion */
  1012. csio_fatal(hw, "FW assertion at %.16s:%u, val0 %#x, val1 %#x\n",
  1013. dbg->u.assert.filename_0_7,
  1014. ntohl(dbg->u.assert.line),
  1015. ntohl(dbg->u.assert.x),
  1016. ntohl(dbg->u.assert.y));
  1017. }
  1018. }
  1019. static void
  1020. csio_mb_debug_cmd_handler(struct csio_hw *hw)
  1021. {
  1022. int i;
  1023. __be64 cmd[CSIO_MB_MAX_REGS];
  1024. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL_A);
  1025. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA_A);
  1026. int size = sizeof(struct fw_debug_cmd);
  1027. /* Copy mailbox data */
  1028. for (i = 0; i < size; i += 8)
  1029. cmd[i / 8] = cpu_to_be64(csio_rd_reg64(hw, data_reg + i));
  1030. csio_mb_dump_fw_dbg(hw, cmd);
  1031. /* Notify FW of mailbox by setting owner as UP */
  1032. csio_wr_reg32(hw, MBMSGVALID_F | MBINTREQ_F |
  1033. MBOWNER_V(CSIO_MBOWNER_FW), ctl_reg);
  1034. csio_rd_reg32(hw, ctl_reg);
  1035. wmb();
  1036. }
  1037. /*
  1038. * csio_mb_issue - generic routine for issuing Mailbox commands.
  1039. * @hw: The HW structure
  1040. * @mbp: Mailbox command to issue
  1041. *
  1042. * Caller should hold hw lock across this call.
  1043. */
  1044. int
  1045. csio_mb_issue(struct csio_hw *hw, struct csio_mb *mbp)
  1046. {
  1047. uint32_t owner, ctl;
  1048. int i;
  1049. uint32_t ii;
  1050. __be64 *cmd = mbp->mb;
  1051. __be64 hdr;
  1052. struct csio_mbm *mbm = &hw->mbm;
  1053. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL_A);
  1054. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA_A);
  1055. int size = mbp->mb_size;
  1056. int rv = -EINVAL;
  1057. struct fw_cmd_hdr *fw_hdr;
  1058. /* Determine mode */
  1059. if (mbp->mb_cbfn == NULL) {
  1060. /* Need to issue/get results in the same context */
  1061. if (mbp->tmo < CSIO_MB_POLL_FREQ) {
  1062. csio_err(hw, "Invalid tmo: 0x%x\n", mbp->tmo);
  1063. goto error_out;
  1064. }
  1065. } else if (!csio_is_host_intr_enabled(hw) ||
  1066. !csio_is_hw_intr_enabled(hw)) {
  1067. csio_err(hw, "Cannot issue mailbox in interrupt mode 0x%x\n",
  1068. *((uint8_t *)mbp->mb));
  1069. goto error_out;
  1070. }
  1071. if (mbm->mcurrent != NULL) {
  1072. /* Queue mbox cmd, if another mbox cmd is active */
  1073. if (mbp->mb_cbfn == NULL) {
  1074. rv = -EBUSY;
  1075. csio_dbg(hw, "Couldn't own Mailbox %x op:0x%x\n",
  1076. hw->pfn, *((uint8_t *)mbp->mb));
  1077. goto error_out;
  1078. } else {
  1079. list_add_tail(&mbp->list, &mbm->req_q);
  1080. CSIO_INC_STATS(mbm, n_activeq);
  1081. return 0;
  1082. }
  1083. }
  1084. /* Now get ownership of mailbox */
  1085. owner = MBOWNER_G(csio_rd_reg32(hw, ctl_reg));
  1086. if (!csio_mb_is_host_owner(owner)) {
  1087. for (i = 0; (owner == CSIO_MBOWNER_NONE) && (i < 3); i++)
  1088. owner = MBOWNER_G(csio_rd_reg32(hw, ctl_reg));
  1089. /*
  1090. * Mailbox unavailable. In immediate mode, fail the command.
  1091. * In other modes, enqueue the request.
  1092. */
  1093. if (!csio_mb_is_host_owner(owner)) {
  1094. if (mbp->mb_cbfn == NULL) {
  1095. rv = owner ? -EBUSY : -ETIMEDOUT;
  1096. csio_dbg(hw,
  1097. "Couldn't own Mailbox %x op:0x%x "
  1098. "owner:%x\n",
  1099. hw->pfn, *((uint8_t *)mbp->mb), owner);
  1100. goto error_out;
  1101. } else {
  1102. if (mbm->mcurrent == NULL) {
  1103. csio_err(hw,
  1104. "Couldn't own Mailbox %x "
  1105. "op:0x%x owner:%x\n",
  1106. hw->pfn, *((uint8_t *)mbp->mb),
  1107. owner);
  1108. csio_err(hw,
  1109. "No outstanding driver"
  1110. " mailbox as well\n");
  1111. goto error_out;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. /* Mailbox is available, copy mailbox data into it */
  1117. for (i = 0; i < size; i += 8) {
  1118. csio_wr_reg64(hw, be64_to_cpu(*cmd), data_reg + i);
  1119. cmd++;
  1120. }
  1121. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1122. /* Start completion timers in non-immediate modes and notify FW */
  1123. if (mbp->mb_cbfn != NULL) {
  1124. mbm->mcurrent = mbp;
  1125. mod_timer(&mbm->timer, jiffies + msecs_to_jiffies(mbp->tmo));
  1126. csio_wr_reg32(hw, MBMSGVALID_F | MBINTREQ_F |
  1127. MBOWNER_V(CSIO_MBOWNER_FW), ctl_reg);
  1128. } else
  1129. csio_wr_reg32(hw, MBMSGVALID_F | MBOWNER_V(CSIO_MBOWNER_FW),
  1130. ctl_reg);
  1131. /* Flush posted writes */
  1132. csio_rd_reg32(hw, ctl_reg);
  1133. wmb();
  1134. CSIO_INC_STATS(mbm, n_req);
  1135. if (mbp->mb_cbfn)
  1136. return 0;
  1137. /* Poll for completion in immediate mode */
  1138. cmd = mbp->mb;
  1139. for (ii = 0; ii < mbp->tmo; ii += CSIO_MB_POLL_FREQ) {
  1140. mdelay(CSIO_MB_POLL_FREQ);
  1141. /* Check for response */
  1142. ctl = csio_rd_reg32(hw, ctl_reg);
  1143. if (csio_mb_is_host_owner(MBOWNER_G(ctl))) {
  1144. if (!(ctl & MBMSGVALID_F)) {
  1145. csio_wr_reg32(hw, 0, ctl_reg);
  1146. continue;
  1147. }
  1148. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1149. hdr = cpu_to_be64(csio_rd_reg64(hw, data_reg));
  1150. fw_hdr = (struct fw_cmd_hdr *)&hdr;
  1151. switch (FW_CMD_OP_G(ntohl(fw_hdr->hi))) {
  1152. case FW_DEBUG_CMD:
  1153. csio_mb_debug_cmd_handler(hw);
  1154. continue;
  1155. }
  1156. /* Copy response */
  1157. for (i = 0; i < size; i += 8)
  1158. *cmd++ = cpu_to_be64(csio_rd_reg64
  1159. (hw, data_reg + i));
  1160. csio_wr_reg32(hw, 0, ctl_reg);
  1161. if (csio_mb_fw_retval(mbp) != FW_SUCCESS)
  1162. CSIO_INC_STATS(mbm, n_err);
  1163. CSIO_INC_STATS(mbm, n_rsp);
  1164. return 0;
  1165. }
  1166. }
  1167. CSIO_INC_STATS(mbm, n_tmo);
  1168. csio_err(hw, "Mailbox %x op:0x%x timed out!\n",
  1169. hw->pfn, *((uint8_t *)cmd));
  1170. return -ETIMEDOUT;
  1171. error_out:
  1172. CSIO_INC_STATS(mbm, n_err);
  1173. return rv;
  1174. }
  1175. /*
  1176. * csio_mb_completions - Completion handler for Mailbox commands
  1177. * @hw: The HW structure
  1178. * @cbfn_q: Completion queue.
  1179. *
  1180. */
  1181. void
  1182. csio_mb_completions(struct csio_hw *hw, struct list_head *cbfn_q)
  1183. {
  1184. struct csio_mb *mbp;
  1185. struct csio_mbm *mbm = &hw->mbm;
  1186. enum fw_retval rv;
  1187. while (!list_empty(cbfn_q)) {
  1188. mbp = list_first_entry(cbfn_q, struct csio_mb, list);
  1189. list_del_init(&mbp->list);
  1190. rv = csio_mb_fw_retval(mbp);
  1191. if ((rv != FW_SUCCESS) && (rv != FW_HOSTERROR))
  1192. CSIO_INC_STATS(mbm, n_err);
  1193. else if (rv != FW_HOSTERROR)
  1194. CSIO_INC_STATS(mbm, n_rsp);
  1195. if (mbp->mb_cbfn)
  1196. mbp->mb_cbfn(hw, mbp);
  1197. }
  1198. }
  1199. static void
  1200. csio_mb_portmod_changed(struct csio_hw *hw, uint8_t port_id)
  1201. {
  1202. static char *mod_str[] = {
  1203. NULL, "LR", "SR", "ER", "TWINAX", "active TWINAX", "LRM"
  1204. };
  1205. struct csio_pport *port = &hw->pport[port_id];
  1206. if (port->mod_type == FW_PORT_MOD_TYPE_NONE)
  1207. csio_info(hw, "Port:%d - port module unplugged\n", port_id);
  1208. else if (port->mod_type < ARRAY_SIZE(mod_str))
  1209. csio_info(hw, "Port:%d - %s port module inserted\n", port_id,
  1210. mod_str[port->mod_type]);
  1211. else if (port->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  1212. csio_info(hw,
  1213. "Port:%d - unsupported optical port module "
  1214. "inserted\n", port_id);
  1215. else if (port->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  1216. csio_info(hw,
  1217. "Port:%d - unknown port module inserted, forcing "
  1218. "TWINAX\n", port_id);
  1219. else if (port->mod_type == FW_PORT_MOD_TYPE_ERROR)
  1220. csio_info(hw, "Port:%d - transceiver module error\n", port_id);
  1221. else
  1222. csio_info(hw, "Port:%d - unknown module type %d inserted\n",
  1223. port_id, port->mod_type);
  1224. }
  1225. int
  1226. csio_mb_fwevt_handler(struct csio_hw *hw, __be64 *cmd)
  1227. {
  1228. uint8_t opcode = *(uint8_t *)cmd;
  1229. struct fw_port_cmd *pcmd;
  1230. uint8_t port_id;
  1231. uint32_t link_status;
  1232. uint16_t action;
  1233. uint8_t mod_type;
  1234. fw_port_cap32_t linkattr;
  1235. if (opcode == FW_PORT_CMD) {
  1236. pcmd = (struct fw_port_cmd *)cmd;
  1237. port_id = FW_PORT_CMD_PORTID_G(
  1238. ntohl(pcmd->op_to_portid));
  1239. action = FW_PORT_CMD_ACTION_G(
  1240. ntohl(pcmd->action_to_len16));
  1241. if (action != FW_PORT_ACTION_GET_PORT_INFO &&
  1242. action != FW_PORT_ACTION_GET_PORT_INFO32) {
  1243. csio_err(hw, "Unhandled FW_PORT_CMD action: %u\n",
  1244. action);
  1245. return -EINVAL;
  1246. }
  1247. if (action == FW_PORT_ACTION_GET_PORT_INFO) {
  1248. link_status = ntohl(pcmd->u.info.lstatus_to_modtype);
  1249. mod_type = FW_PORT_CMD_MODTYPE_G(link_status);
  1250. linkattr = lstatus_to_fwcap(link_status);
  1251. hw->pport[port_id].link_status =
  1252. FW_PORT_CMD_LSTATUS_G(link_status);
  1253. } else {
  1254. link_status =
  1255. ntohl(pcmd->u.info32.lstatus32_to_cbllen32);
  1256. mod_type = FW_PORT_CMD_MODTYPE32_G(link_status);
  1257. linkattr = ntohl(pcmd->u.info32.linkattr32);
  1258. hw->pport[port_id].link_status =
  1259. FW_PORT_CMD_LSTATUS32_G(link_status);
  1260. }
  1261. hw->pport[port_id].link_speed = fwcap_to_fwspeed(linkattr);
  1262. csio_info(hw, "Port:%x - LINK %s\n", port_id,
  1263. hw->pport[port_id].link_status ? "UP" : "DOWN");
  1264. if (mod_type != hw->pport[port_id].mod_type) {
  1265. hw->pport[port_id].mod_type = mod_type;
  1266. csio_mb_portmod_changed(hw, port_id);
  1267. }
  1268. } else if (opcode == FW_DEBUG_CMD) {
  1269. csio_mb_dump_fw_dbg(hw, cmd);
  1270. } else {
  1271. csio_dbg(hw, "Gen MB can't handle op:0x%x on evtq.\n", opcode);
  1272. return -EINVAL;
  1273. }
  1274. return 0;
  1275. }
  1276. /*
  1277. * csio_mb_isr_handler - Handle mailboxes related interrupts.
  1278. * @hw: The HW structure
  1279. *
  1280. * Called from the ISR to handle Mailbox related interrupts.
  1281. * HW Lock should be held across this call.
  1282. */
  1283. int
  1284. csio_mb_isr_handler(struct csio_hw *hw)
  1285. {
  1286. struct csio_mbm *mbm = &hw->mbm;
  1287. struct csio_mb *mbp = mbm->mcurrent;
  1288. __be64 *cmd;
  1289. uint32_t ctl, cim_cause, pl_cause;
  1290. int i;
  1291. uint32_t ctl_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_CTRL_A);
  1292. uint32_t data_reg = PF_REG(hw->pfn, CIM_PF_MAILBOX_DATA_A);
  1293. int size;
  1294. __be64 hdr;
  1295. struct fw_cmd_hdr *fw_hdr;
  1296. pl_cause = csio_rd_reg32(hw, MYPF_REG(PL_PF_INT_CAUSE_A));
  1297. cim_cause = csio_rd_reg32(hw, MYPF_REG(CIM_PF_HOST_INT_CAUSE_A));
  1298. if (!(pl_cause & PFCIM_F) || !(cim_cause & MBMSGRDYINT_F)) {
  1299. CSIO_INC_STATS(hw, n_mbint_unexp);
  1300. return -EINVAL;
  1301. }
  1302. /*
  1303. * The cause registers below HAVE to be cleared in the SAME
  1304. * order as below: The low level cause register followed by
  1305. * the upper level cause register. In other words, CIM-cause
  1306. * first followed by PL-Cause next.
  1307. */
  1308. csio_wr_reg32(hw, MBMSGRDYINT_F, MYPF_REG(CIM_PF_HOST_INT_CAUSE_A));
  1309. csio_wr_reg32(hw, PFCIM_F, MYPF_REG(PL_PF_INT_CAUSE_A));
  1310. ctl = csio_rd_reg32(hw, ctl_reg);
  1311. if (csio_mb_is_host_owner(MBOWNER_G(ctl))) {
  1312. CSIO_DUMP_MB(hw, hw->pfn, data_reg);
  1313. if (!(ctl & MBMSGVALID_F)) {
  1314. csio_warn(hw,
  1315. "Stray mailbox interrupt recvd,"
  1316. " mailbox data not valid\n");
  1317. csio_wr_reg32(hw, 0, ctl_reg);
  1318. /* Flush */
  1319. csio_rd_reg32(hw, ctl_reg);
  1320. return -EINVAL;
  1321. }
  1322. hdr = cpu_to_be64(csio_rd_reg64(hw, data_reg));
  1323. fw_hdr = (struct fw_cmd_hdr *)&hdr;
  1324. switch (FW_CMD_OP_G(ntohl(fw_hdr->hi))) {
  1325. case FW_DEBUG_CMD:
  1326. csio_mb_debug_cmd_handler(hw);
  1327. return -EINVAL;
  1328. #if 0
  1329. case FW_ERROR_CMD:
  1330. case FW_INITIALIZE_CMD: /* When we are not master */
  1331. #endif
  1332. }
  1333. CSIO_ASSERT(mbp != NULL);
  1334. cmd = mbp->mb;
  1335. size = mbp->mb_size;
  1336. /* Get response */
  1337. for (i = 0; i < size; i += 8)
  1338. *cmd++ = cpu_to_be64(csio_rd_reg64
  1339. (hw, data_reg + i));
  1340. csio_wr_reg32(hw, 0, ctl_reg);
  1341. /* Flush */
  1342. csio_rd_reg32(hw, ctl_reg);
  1343. mbm->mcurrent = NULL;
  1344. /* Add completion to tail of cbfn queue */
  1345. list_add_tail(&mbp->list, &mbm->cbfn_q);
  1346. CSIO_INC_STATS(mbm, n_cbfnq);
  1347. /*
  1348. * Enqueue event to EventQ. Events processing happens
  1349. * in Event worker thread context
  1350. */
  1351. if (csio_enqueue_evt(hw, CSIO_EVT_MBX, mbp, sizeof(mbp)))
  1352. CSIO_INC_STATS(hw, n_evt_drop);
  1353. return 0;
  1354. } else {
  1355. /*
  1356. * We can get here if mailbox MSIX vector is shared,
  1357. * or in INTx case. Or a stray interrupt.
  1358. */
  1359. csio_dbg(hw, "Host not owner, no mailbox interrupt\n");
  1360. CSIO_INC_STATS(hw, n_int_stray);
  1361. return -EINVAL;
  1362. }
  1363. }
  1364. /*
  1365. * csio_mb_tmo_handler - Timeout handler
  1366. * @hw: The HW structure
  1367. *
  1368. */
  1369. struct csio_mb *
  1370. csio_mb_tmo_handler(struct csio_hw *hw)
  1371. {
  1372. struct csio_mbm *mbm = &hw->mbm;
  1373. struct csio_mb *mbp = mbm->mcurrent;
  1374. struct fw_cmd_hdr *fw_hdr;
  1375. /*
  1376. * Could be a race b/w the completion handler and the timer
  1377. * and the completion handler won that race.
  1378. */
  1379. if (mbp == NULL) {
  1380. CSIO_DB_ASSERT(0);
  1381. return NULL;
  1382. }
  1383. fw_hdr = (struct fw_cmd_hdr *)(mbp->mb);
  1384. csio_dbg(hw, "Mailbox num:%x op:0x%x timed out\n", hw->pfn,
  1385. FW_CMD_OP_G(ntohl(fw_hdr->hi)));
  1386. mbm->mcurrent = NULL;
  1387. CSIO_INC_STATS(mbm, n_tmo);
  1388. fw_hdr->lo = htonl(FW_CMD_RETVAL_V(FW_ETIMEDOUT));
  1389. return mbp;
  1390. }
  1391. /*
  1392. * csio_mb_cancel_all - Cancel all waiting commands.
  1393. * @hw: The HW structure
  1394. * @cbfn_q: The callback queue.
  1395. *
  1396. * Caller should hold hw lock across this call.
  1397. */
  1398. void
  1399. csio_mb_cancel_all(struct csio_hw *hw, struct list_head *cbfn_q)
  1400. {
  1401. struct csio_mb *mbp;
  1402. struct csio_mbm *mbm = &hw->mbm;
  1403. struct fw_cmd_hdr *hdr;
  1404. struct list_head *tmp;
  1405. if (mbm->mcurrent) {
  1406. mbp = mbm->mcurrent;
  1407. /* Stop mailbox completion timer */
  1408. del_timer_sync(&mbm->timer);
  1409. /* Add completion to tail of cbfn queue */
  1410. list_add_tail(&mbp->list, cbfn_q);
  1411. mbm->mcurrent = NULL;
  1412. }
  1413. if (!list_empty(&mbm->req_q)) {
  1414. list_splice_tail_init(&mbm->req_q, cbfn_q);
  1415. mbm->stats.n_activeq = 0;
  1416. }
  1417. if (!list_empty(&mbm->cbfn_q)) {
  1418. list_splice_tail_init(&mbm->cbfn_q, cbfn_q);
  1419. mbm->stats.n_cbfnq = 0;
  1420. }
  1421. if (list_empty(cbfn_q))
  1422. return;
  1423. list_for_each(tmp, cbfn_q) {
  1424. mbp = (struct csio_mb *)tmp;
  1425. hdr = (struct fw_cmd_hdr *)(mbp->mb);
  1426. csio_dbg(hw, "Cancelling pending mailbox num %x op:%x\n",
  1427. hw->pfn, FW_CMD_OP_G(ntohl(hdr->hi)));
  1428. CSIO_INC_STATS(mbm, n_cancel);
  1429. hdr->lo = htonl(FW_CMD_RETVAL_V(FW_HOSTERROR));
  1430. }
  1431. }
  1432. /*
  1433. * csio_mbm_init - Initialize Mailbox module
  1434. * @mbm: Mailbox module
  1435. * @hw: The HW structure
  1436. * @timer: Timing function for interrupting mailboxes
  1437. *
  1438. * Initialize timer and the request/response queues.
  1439. */
  1440. int
  1441. csio_mbm_init(struct csio_mbm *mbm, struct csio_hw *hw,
  1442. void (*timer_fn)(struct timer_list *))
  1443. {
  1444. mbm->hw = hw;
  1445. timer_setup(&mbm->timer, timer_fn, 0);
  1446. INIT_LIST_HEAD(&mbm->req_q);
  1447. INIT_LIST_HEAD(&mbm->cbfn_q);
  1448. csio_set_mb_intr_idx(mbm, -1);
  1449. return 0;
  1450. }
  1451. /*
  1452. * csio_mbm_exit - Uninitialize mailbox module
  1453. * @mbm: Mailbox module
  1454. *
  1455. * Stop timer.
  1456. */
  1457. void
  1458. csio_mbm_exit(struct csio_mbm *mbm)
  1459. {
  1460. del_timer_sync(&mbm->timer);
  1461. CSIO_DB_ASSERT(mbm->mcurrent == NULL);
  1462. CSIO_DB_ASSERT(list_empty(&mbm->req_q));
  1463. CSIO_DB_ASSERT(list_empty(&mbm->cbfn_q));
  1464. }