csio_mb.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  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. }