csio_mb.c 47 KB

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