csio_mb.c 47 KB

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