csio_mb.c 49 KB

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