bnx2x_vfpf.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. /* bnx2x_vfpf.c: Broadcom Everest network driver.
  2. *
  3. * Copyright 2009-2013 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  16. * Written by: Shmulik Ravid <shmulikr@broadcom.com>
  17. * Ariel Elior <ariele@broadcom.com>
  18. */
  19. #include "bnx2x.h"
  20. #include "bnx2x_cmn.h"
  21. #include <linux/crc32.h>
  22. /* place a given tlv on the tlv buffer at a given offset */
  23. void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
  24. u16 length)
  25. {
  26. struct channel_tlv *tl =
  27. (struct channel_tlv *)(tlvs_list + offset);
  28. tl->type = type;
  29. tl->length = length;
  30. }
  31. /* Clear the mailbox and init the header of the first tlv */
  32. void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  33. u16 type, u16 length)
  34. {
  35. mutex_lock(&bp->vf2pf_mutex);
  36. DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
  37. type);
  38. /* Clear mailbox */
  39. memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
  40. /* init type and length */
  41. bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
  42. /* init first tlv header */
  43. first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
  44. }
  45. /* releases the mailbox */
  46. void bnx2x_vfpf_finalize(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv)
  47. {
  48. DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
  49. first_tlv->tl.type);
  50. mutex_unlock(&bp->vf2pf_mutex);
  51. }
  52. /* list the types and lengths of the tlvs on the buffer */
  53. void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
  54. {
  55. int i = 1;
  56. struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
  57. while (tlv->type != CHANNEL_TLV_LIST_END) {
  58. /* output tlv */
  59. DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
  60. tlv->type, tlv->length);
  61. /* advance to next tlv */
  62. tlvs_list += tlv->length;
  63. /* cast general tlv list pointer to channel tlv header*/
  64. tlv = (struct channel_tlv *)tlvs_list;
  65. i++;
  66. /* break condition for this loop */
  67. if (i > MAX_TLVS_IN_LIST) {
  68. WARN(true, "corrupt tlvs");
  69. return;
  70. }
  71. }
  72. /* output last tlv */
  73. DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
  74. tlv->type, tlv->length);
  75. }
  76. /* test whether we support a tlv type */
  77. bool bnx2x_tlv_supported(u16 tlvtype)
  78. {
  79. return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
  80. }
  81. static inline int bnx2x_pfvf_status_codes(int rc)
  82. {
  83. switch (rc) {
  84. case 0:
  85. return PFVF_STATUS_SUCCESS;
  86. case -ENOMEM:
  87. return PFVF_STATUS_NO_RESOURCE;
  88. default:
  89. return PFVF_STATUS_FAILURE;
  90. }
  91. }
  92. static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
  93. {
  94. struct cstorm_vf_zone_data __iomem *zone_data =
  95. REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
  96. int tout = 600, interval = 100; /* wait for 60 seconds */
  97. if (*done) {
  98. BNX2X_ERR("done was non zero before message to pf was sent\n");
  99. WARN_ON(true);
  100. return -EINVAL;
  101. }
  102. /* Write message address */
  103. writel(U64_LO(msg_mapping),
  104. &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
  105. writel(U64_HI(msg_mapping),
  106. &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
  107. /* make sure the address is written before FW accesses it */
  108. wmb();
  109. /* Trigger the PF FW */
  110. writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
  111. /* Wait for PF to complete */
  112. while ((tout >= 0) && (!*done)) {
  113. msleep(interval);
  114. tout -= 1;
  115. /* progress indicator - HV can take its own sweet time in
  116. * answering VFs...
  117. */
  118. DP_CONT(BNX2X_MSG_IOV, ".");
  119. }
  120. if (!*done) {
  121. BNX2X_ERR("PF response has timed out\n");
  122. return -EAGAIN;
  123. }
  124. DP(BNX2X_MSG_SP, "Got a response from PF\n");
  125. return 0;
  126. }
  127. static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
  128. {
  129. u32 me_reg;
  130. int tout = 10, interval = 100; /* Wait for 1 sec */
  131. do {
  132. /* pxp traps vf read of doorbells and returns me reg value */
  133. me_reg = readl(bp->doorbells);
  134. if (GOOD_ME_REG(me_reg))
  135. break;
  136. msleep(interval);
  137. BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
  138. me_reg);
  139. } while (tout-- > 0);
  140. if (!GOOD_ME_REG(me_reg)) {
  141. BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
  142. return -EINVAL;
  143. }
  144. BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
  145. *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
  146. return 0;
  147. }
  148. int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
  149. {
  150. int rc = 0, attempts = 0;
  151. struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
  152. struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
  153. u32 vf_id;
  154. bool resources_acquired = false;
  155. /* clear mailbox and prep first tlv */
  156. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  157. if (bnx2x_get_vf_id(bp, &vf_id)) {
  158. rc = -EAGAIN;
  159. goto out;
  160. }
  161. req->vfdev_info.vf_id = vf_id;
  162. req->vfdev_info.vf_os = 0;
  163. req->resc_request.num_rxqs = rx_count;
  164. req->resc_request.num_txqs = tx_count;
  165. req->resc_request.num_sbs = bp->igu_sb_cnt;
  166. req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
  167. req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
  168. /* pf 2 vf bulletin board address */
  169. req->bulletin_addr = bp->pf2vf_bulletin_mapping;
  170. /* add list termination tlv */
  171. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  172. sizeof(struct channel_list_end_tlv));
  173. /* output tlvs list */
  174. bnx2x_dp_tlv_list(bp, req);
  175. while (!resources_acquired) {
  176. DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
  177. /* send acquire request */
  178. rc = bnx2x_send_msg2pf(bp,
  179. &resp->hdr.status,
  180. bp->vf2pf_mbox_mapping);
  181. /* PF timeout */
  182. if (rc)
  183. goto out;
  184. /* copy acquire response from buffer to bp */
  185. memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
  186. attempts++;
  187. /* test whether the PF accepted our request. If not, humble the
  188. * the request and try again.
  189. */
  190. if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
  191. DP(BNX2X_MSG_SP, "resources acquired\n");
  192. resources_acquired = true;
  193. } else if (bp->acquire_resp.hdr.status ==
  194. PFVF_STATUS_NO_RESOURCE &&
  195. attempts < VF_ACQUIRE_THRESH) {
  196. DP(BNX2X_MSG_SP,
  197. "PF unwilling to fulfill resource request. Try PF recommended amount\n");
  198. /* humble our request */
  199. req->resc_request.num_txqs =
  200. bp->acquire_resp.resc.num_txqs;
  201. req->resc_request.num_rxqs =
  202. bp->acquire_resp.resc.num_rxqs;
  203. req->resc_request.num_sbs =
  204. bp->acquire_resp.resc.num_sbs;
  205. req->resc_request.num_mac_filters =
  206. bp->acquire_resp.resc.num_mac_filters;
  207. req->resc_request.num_vlan_filters =
  208. bp->acquire_resp.resc.num_vlan_filters;
  209. req->resc_request.num_mc_filters =
  210. bp->acquire_resp.resc.num_mc_filters;
  211. /* Clear response buffer */
  212. memset(&bp->vf2pf_mbox->resp, 0,
  213. sizeof(union pfvf_tlvs));
  214. } else {
  215. /* PF reports error */
  216. BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
  217. bp->acquire_resp.hdr.status);
  218. rc = -EAGAIN;
  219. goto out;
  220. }
  221. }
  222. /* get HW info */
  223. bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
  224. bp->link_params.chip_id = bp->common.chip_id;
  225. bp->db_size = bp->acquire_resp.pfdev_info.db_size;
  226. bp->common.int_block = INT_BLOCK_IGU;
  227. bp->common.chip_port_mode = CHIP_2_PORT_MODE;
  228. bp->igu_dsb_id = -1;
  229. bp->mf_ov = 0;
  230. bp->mf_mode = 0;
  231. bp->common.flash_size = 0;
  232. bp->flags |=
  233. NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
  234. bp->igu_sb_cnt = 1;
  235. bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
  236. strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
  237. sizeof(bp->fw_ver));
  238. if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
  239. memcpy(bp->dev->dev_addr,
  240. bp->acquire_resp.resc.current_mac_addr,
  241. ETH_ALEN);
  242. out:
  243. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  244. return rc;
  245. }
  246. int bnx2x_vfpf_release(struct bnx2x *bp)
  247. {
  248. struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
  249. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  250. u32 rc, vf_id;
  251. /* clear mailbox and prep first tlv */
  252. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
  253. if (bnx2x_get_vf_id(bp, &vf_id)) {
  254. rc = -EAGAIN;
  255. goto out;
  256. }
  257. req->vf_id = vf_id;
  258. /* add list termination tlv */
  259. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  260. sizeof(struct channel_list_end_tlv));
  261. /* output tlvs list */
  262. bnx2x_dp_tlv_list(bp, req);
  263. /* send release request */
  264. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  265. if (rc)
  266. /* PF timeout */
  267. goto out;
  268. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  269. /* PF released us */
  270. DP(BNX2X_MSG_SP, "vf released\n");
  271. } else {
  272. /* PF reports error */
  273. BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
  274. resp->hdr.status);
  275. rc = -EAGAIN;
  276. goto out;
  277. }
  278. out:
  279. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  280. return rc;
  281. }
  282. /* Tell PF about SB addresses */
  283. int bnx2x_vfpf_init(struct bnx2x *bp)
  284. {
  285. struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
  286. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  287. int rc, i;
  288. /* clear mailbox and prep first tlv */
  289. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
  290. /* status blocks */
  291. for_each_eth_queue(bp, i)
  292. req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
  293. status_blk_mapping);
  294. /* statistics - requests only supports single queue for now */
  295. req->stats_addr = bp->fw_stats_data_mapping +
  296. offsetof(struct bnx2x_fw_stats_data, queue_stats);
  297. /* add list termination tlv */
  298. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  299. sizeof(struct channel_list_end_tlv));
  300. /* output tlvs list */
  301. bnx2x_dp_tlv_list(bp, req);
  302. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  303. if (rc)
  304. goto out;
  305. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  306. BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
  307. resp->hdr.status);
  308. rc = -EAGAIN;
  309. goto out;
  310. }
  311. DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
  312. out:
  313. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  314. return rc;
  315. }
  316. /* CLOSE VF - opposite to INIT_VF */
  317. void bnx2x_vfpf_close_vf(struct bnx2x *bp)
  318. {
  319. struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
  320. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  321. int i, rc;
  322. u32 vf_id;
  323. /* If we haven't got a valid VF id, there is no sense to
  324. * continue with sending messages
  325. */
  326. if (bnx2x_get_vf_id(bp, &vf_id))
  327. goto free_irq;
  328. /* Close the queues */
  329. for_each_queue(bp, i)
  330. bnx2x_vfpf_teardown_queue(bp, i);
  331. /* clear mailbox and prep first tlv */
  332. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
  333. req->vf_id = vf_id;
  334. /* add list termination tlv */
  335. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  336. sizeof(struct channel_list_end_tlv));
  337. /* output tlvs list */
  338. bnx2x_dp_tlv_list(bp, req);
  339. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  340. if (rc)
  341. BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
  342. else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
  343. BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
  344. resp->hdr.status);
  345. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  346. free_irq:
  347. /* Disable HW interrupts, NAPI */
  348. bnx2x_netif_stop(bp, 0);
  349. /* Delete all NAPI objects */
  350. bnx2x_del_all_napi(bp);
  351. /* Release IRQs */
  352. bnx2x_free_irq(bp);
  353. }
  354. /* ask the pf to open a queue for the vf */
  355. int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
  356. {
  357. struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
  358. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  359. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  360. u16 tpa_agg_size = 0, flags = 0;
  361. int rc;
  362. /* clear mailbox and prep first tlv */
  363. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
  364. /* select tpa mode to request */
  365. if (!fp->disable_tpa) {
  366. flags |= VFPF_QUEUE_FLG_TPA;
  367. flags |= VFPF_QUEUE_FLG_TPA_IPV6;
  368. if (fp->mode == TPA_MODE_GRO)
  369. flags |= VFPF_QUEUE_FLG_TPA_GRO;
  370. tpa_agg_size = TPA_AGG_SIZE;
  371. }
  372. /* calculate queue flags */
  373. flags |= VFPF_QUEUE_FLG_STATS;
  374. flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
  375. flags |= VFPF_QUEUE_FLG_VLAN;
  376. DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
  377. /* Common */
  378. req->vf_qid = fp_idx;
  379. req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
  380. /* Rx */
  381. req->rxq.rcq_addr = fp->rx_comp_mapping;
  382. req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  383. req->rxq.rxq_addr = fp->rx_desc_mapping;
  384. req->rxq.sge_addr = fp->rx_sge_mapping;
  385. req->rxq.vf_sb = fp_idx;
  386. req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
  387. req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
  388. req->rxq.mtu = bp->dev->mtu;
  389. req->rxq.buf_sz = fp->rx_buf_size;
  390. req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
  391. req->rxq.tpa_agg_sz = tpa_agg_size;
  392. req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
  393. req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
  394. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  395. req->rxq.flags = flags;
  396. req->rxq.drop_flags = 0;
  397. req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  398. req->rxq.stat_id = -1; /* No stats at the moment */
  399. /* Tx */
  400. req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
  401. req->txq.vf_sb = fp_idx;
  402. req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
  403. req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
  404. req->txq.flags = flags;
  405. req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
  406. /* add list termination tlv */
  407. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  408. sizeof(struct channel_list_end_tlv));
  409. /* output tlvs list */
  410. bnx2x_dp_tlv_list(bp, req);
  411. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  412. if (rc)
  413. BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
  414. fp_idx);
  415. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  416. BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
  417. fp_idx, resp->hdr.status);
  418. rc = -EINVAL;
  419. }
  420. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  421. return rc;
  422. }
  423. int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
  424. {
  425. struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
  426. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  427. int rc;
  428. /* clear mailbox and prep first tlv */
  429. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
  430. sizeof(*req));
  431. req->vf_qid = qidx;
  432. /* add list termination tlv */
  433. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  434. sizeof(struct channel_list_end_tlv));
  435. /* output tlvs list */
  436. bnx2x_dp_tlv_list(bp, req);
  437. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  438. if (rc) {
  439. BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
  440. rc);
  441. goto out;
  442. }
  443. /* PF failed the transaction */
  444. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  445. BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
  446. resp->hdr.status);
  447. rc = -EINVAL;
  448. }
  449. out:
  450. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  451. return rc;
  452. }
  453. /* request pf to add a mac for the vf */
  454. int bnx2x_vfpf_set_mac(struct bnx2x *bp)
  455. {
  456. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  457. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  458. int rc = 0;
  459. /* clear mailbox and prep first tlv */
  460. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  461. sizeof(*req));
  462. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  463. req->vf_qid = 0;
  464. req->n_mac_vlan_filters = 1;
  465. req->filters[0].flags =
  466. VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
  467. /* sample bulletin board for new mac */
  468. bnx2x_sample_bulletin(bp);
  469. /* copy mac from device to request */
  470. memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
  471. /* add list termination tlv */
  472. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  473. sizeof(struct channel_list_end_tlv));
  474. /* output tlvs list */
  475. bnx2x_dp_tlv_list(bp, req);
  476. /* send message to pf */
  477. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  478. if (rc) {
  479. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  480. goto out;
  481. }
  482. /* failure may mean PF was configured with a new mac for us */
  483. while (resp->hdr.status == PFVF_STATUS_FAILURE) {
  484. DP(BNX2X_MSG_IOV,
  485. "vfpf SET MAC failed. Check bulletin board for new posts\n");
  486. /* check if bulletin board was updated */
  487. if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
  488. /* copy mac from device to request */
  489. memcpy(req->filters[0].mac, bp->dev->dev_addr,
  490. ETH_ALEN);
  491. /* send message to pf */
  492. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
  493. bp->vf2pf_mbox_mapping);
  494. } else {
  495. /* no new info in bulletin */
  496. break;
  497. }
  498. }
  499. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  500. BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
  501. rc = -EINVAL;
  502. }
  503. out:
  504. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  505. return 0;
  506. }
  507. int bnx2x_vfpf_set_mcast(struct net_device *dev)
  508. {
  509. struct bnx2x *bp = netdev_priv(dev);
  510. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  511. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  512. int rc, i = 0;
  513. struct netdev_hw_addr *ha;
  514. if (bp->state != BNX2X_STATE_OPEN) {
  515. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  516. return -EINVAL;
  517. }
  518. /* clear mailbox and prep first tlv */
  519. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  520. sizeof(*req));
  521. /* Get Rx mode requested */
  522. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  523. netdev_for_each_mc_addr(ha, dev) {
  524. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  525. bnx2x_mc_addr(ha));
  526. memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
  527. i++;
  528. }
  529. /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
  530. * addresses tops
  531. */
  532. if (i >= PFVF_MAX_MULTICAST_PER_VF) {
  533. DP(NETIF_MSG_IFUP,
  534. "VF supports not more than %d multicast MAC addresses\n",
  535. PFVF_MAX_MULTICAST_PER_VF);
  536. return -EINVAL;
  537. }
  538. req->n_multicast = i;
  539. req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
  540. req->vf_qid = 0;
  541. /* add list termination tlv */
  542. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  543. sizeof(struct channel_list_end_tlv));
  544. /* output tlvs list */
  545. bnx2x_dp_tlv_list(bp, req);
  546. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  547. if (rc) {
  548. BNX2X_ERR("Sending a message failed: %d\n", rc);
  549. goto out;
  550. }
  551. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  552. BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
  553. resp->hdr.status);
  554. rc = -EINVAL;
  555. }
  556. out:
  557. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  558. return 0;
  559. }
  560. int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
  561. {
  562. int mode = bp->rx_mode;
  563. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  564. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  565. int rc;
  566. /* clear mailbox and prep first tlv */
  567. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  568. sizeof(*req));
  569. DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
  570. switch (mode) {
  571. case BNX2X_RX_MODE_NONE: /* no Rx */
  572. req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
  573. break;
  574. case BNX2X_RX_MODE_NORMAL:
  575. req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
  576. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  577. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  578. break;
  579. case BNX2X_RX_MODE_ALLMULTI:
  580. req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
  581. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  582. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  583. break;
  584. case BNX2X_RX_MODE_PROMISC:
  585. req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
  586. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
  587. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  588. break;
  589. default:
  590. BNX2X_ERR("BAD rx mode (%d)\n", mode);
  591. rc = -EINVAL;
  592. goto out;
  593. }
  594. req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
  595. req->vf_qid = 0;
  596. /* add list termination tlv */
  597. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  598. sizeof(struct channel_list_end_tlv));
  599. /* output tlvs list */
  600. bnx2x_dp_tlv_list(bp, req);
  601. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  602. if (rc)
  603. BNX2X_ERR("Sending a message failed: %d\n", rc);
  604. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  605. BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
  606. rc = -EINVAL;
  607. }
  608. out:
  609. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  610. return rc;
  611. }
  612. /* General service functions */
  613. static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
  614. {
  615. u32 addr = BAR_CSTRORM_INTMEM +
  616. CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
  617. REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
  618. }
  619. static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
  620. {
  621. u32 addr = BAR_CSTRORM_INTMEM +
  622. CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
  623. REG_WR8(bp, addr, 1);
  624. }
  625. static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
  626. {
  627. int i;
  628. for_each_vf(bp, i)
  629. storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
  630. }
  631. /* enable vf_pf mailbox (aka vf-pf-chanell) */
  632. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
  633. {
  634. bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
  635. /* enable the mailbox in the FW */
  636. storm_memset_vf_mbx_ack(bp, abs_vfid);
  637. storm_memset_vf_mbx_valid(bp, abs_vfid);
  638. /* enable the VF access to the mailbox */
  639. bnx2x_vf_enable_access(bp, abs_vfid);
  640. }
  641. /* this works only on !E1h */
  642. static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
  643. dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
  644. u32 vf_addr_lo, u32 len32)
  645. {
  646. struct dmae_command dmae;
  647. if (CHIP_IS_E1x(bp)) {
  648. BNX2X_ERR("Chip revision does not support VFs\n");
  649. return DMAE_NOT_RDY;
  650. }
  651. if (!bp->dmae_ready) {
  652. BNX2X_ERR("DMAE is not ready, can not copy\n");
  653. return DMAE_NOT_RDY;
  654. }
  655. /* set opcode and fixed command fields */
  656. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
  657. if (from_vf) {
  658. dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
  659. (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
  660. (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
  661. dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
  662. dmae.src_addr_lo = vf_addr_lo;
  663. dmae.src_addr_hi = vf_addr_hi;
  664. dmae.dst_addr_lo = U64_LO(pf_addr);
  665. dmae.dst_addr_hi = U64_HI(pf_addr);
  666. } else {
  667. dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
  668. (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
  669. (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
  670. dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
  671. dmae.src_addr_lo = U64_LO(pf_addr);
  672. dmae.src_addr_hi = U64_HI(pf_addr);
  673. dmae.dst_addr_lo = vf_addr_lo;
  674. dmae.dst_addr_hi = vf_addr_hi;
  675. }
  676. dmae.len = len32;
  677. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
  678. /* issue the command and wait for completion */
  679. return bnx2x_issue_dmae_with_comp(bp, &dmae);
  680. }
  681. static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
  682. {
  683. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  684. u64 vf_addr;
  685. dma_addr_t pf_addr;
  686. u16 length, type;
  687. int rc;
  688. struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
  689. /* prepare response */
  690. type = mbx->first_tlv.tl.type;
  691. length = type == CHANNEL_TLV_ACQUIRE ?
  692. sizeof(struct pfvf_acquire_resp_tlv) :
  693. sizeof(struct pfvf_general_resp_tlv);
  694. bnx2x_add_tlv(bp, resp, 0, type, length);
  695. resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
  696. bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
  697. sizeof(struct channel_list_end_tlv));
  698. bnx2x_dp_tlv_list(bp, resp);
  699. DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
  700. mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
  701. /* send response */
  702. vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
  703. mbx->first_tlv.resp_msg_offset;
  704. pf_addr = mbx->msg_mapping +
  705. offsetof(struct bnx2x_vf_mbx_msg, resp);
  706. /* copy the response body, if there is one, before the header, as the vf
  707. * is sensitive to the header being written
  708. */
  709. if (resp->hdr.tl.length > sizeof(u64)) {
  710. length = resp->hdr.tl.length - sizeof(u64);
  711. vf_addr += sizeof(u64);
  712. pf_addr += sizeof(u64);
  713. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  714. U64_HI(vf_addr),
  715. U64_LO(vf_addr),
  716. length/4);
  717. if (rc) {
  718. BNX2X_ERR("Failed to copy response body to VF %d\n",
  719. vf->abs_vfid);
  720. goto mbx_error;
  721. }
  722. vf_addr -= sizeof(u64);
  723. pf_addr -= sizeof(u64);
  724. }
  725. /* ack the FW */
  726. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  727. mmiowb();
  728. /* initiate dmae to send the response */
  729. mbx->flags &= ~VF_MSG_INPROCESS;
  730. /* copy the response header including status-done field,
  731. * must be last dmae, must be after FW is acked
  732. */
  733. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  734. U64_HI(vf_addr),
  735. U64_LO(vf_addr),
  736. sizeof(u64)/4);
  737. /* unlock channel mutex */
  738. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  739. if (rc) {
  740. BNX2X_ERR("Failed to copy response status to VF %d\n",
  741. vf->abs_vfid);
  742. goto mbx_error;
  743. }
  744. return;
  745. mbx_error:
  746. bnx2x_vf_release(bp, vf, false); /* non blocking */
  747. }
  748. static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
  749. struct bnx2x_vf_mbx *mbx, int vfop_status)
  750. {
  751. int i;
  752. struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
  753. struct pf_vf_resc *resc = &resp->resc;
  754. u8 status = bnx2x_pfvf_status_codes(vfop_status);
  755. memset(resp, 0, sizeof(*resp));
  756. /* fill in pfdev info */
  757. resp->pfdev_info.chip_num = bp->common.chip_id;
  758. resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
  759. resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
  760. resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
  761. /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
  762. bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
  763. sizeof(resp->pfdev_info.fw_ver));
  764. if (status == PFVF_STATUS_NO_RESOURCE ||
  765. status == PFVF_STATUS_SUCCESS) {
  766. /* set resources numbers, if status equals NO_RESOURCE these
  767. * are max possible numbers
  768. */
  769. resc->num_rxqs = vf_rxq_count(vf) ? :
  770. bnx2x_vf_max_queue_cnt(bp, vf);
  771. resc->num_txqs = vf_txq_count(vf) ? :
  772. bnx2x_vf_max_queue_cnt(bp, vf);
  773. resc->num_sbs = vf_sb_count(vf);
  774. resc->num_mac_filters = vf_mac_rules_cnt(vf);
  775. resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
  776. resc->num_mc_filters = 0;
  777. if (status == PFVF_STATUS_SUCCESS) {
  778. /* fill in the allocated resources */
  779. struct pf_vf_bulletin_content *bulletin =
  780. BP_VF_BULLETIN(bp, vf->index);
  781. for_each_vfq(vf, i)
  782. resc->hw_qid[i] =
  783. vfq_qzone_id(vf, vfq_get(vf, i));
  784. for_each_vf_sb(vf, i) {
  785. resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
  786. resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
  787. }
  788. /* if a mac has been set for this vf, supply it */
  789. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  790. memcpy(resc->current_mac_addr, bulletin->mac,
  791. ETH_ALEN);
  792. }
  793. }
  794. }
  795. DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n"
  796. "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
  797. vf->abs_vfid,
  798. resp->pfdev_info.chip_num,
  799. resp->pfdev_info.db_size,
  800. resp->pfdev_info.indices_per_sb,
  801. resp->pfdev_info.pf_cap,
  802. resc->num_rxqs,
  803. resc->num_txqs,
  804. resc->num_sbs,
  805. resc->num_mac_filters,
  806. resc->num_vlan_filters,
  807. resc->num_mc_filters,
  808. resp->pfdev_info.fw_ver);
  809. DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
  810. for (i = 0; i < vf_rxq_count(vf); i++)
  811. DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
  812. DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
  813. for (i = 0; i < vf_sb_count(vf); i++)
  814. DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
  815. resc->hw_sbs[i].hw_sb_id,
  816. resc->hw_sbs[i].sb_qid);
  817. DP_CONT(BNX2X_MSG_IOV, "]\n");
  818. /* send the response */
  819. vf->op_rc = vfop_status;
  820. bnx2x_vf_mbx_resp(bp, vf);
  821. }
  822. static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  823. struct bnx2x_vf_mbx *mbx)
  824. {
  825. int rc;
  826. struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
  827. /* log vfdef info */
  828. DP(BNX2X_MSG_IOV,
  829. "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n",
  830. vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
  831. acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
  832. acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
  833. acquire->resc_request.num_vlan_filters,
  834. acquire->resc_request.num_mc_filters);
  835. /* acquire the resources */
  836. rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
  837. /* store address of vf's bulletin board */
  838. vf->bulletin_map = acquire->bulletin_addr;
  839. /* response */
  840. bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
  841. }
  842. static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  843. struct bnx2x_vf_mbx *mbx)
  844. {
  845. struct vfpf_init_tlv *init = &mbx->msg->req.init;
  846. /* record ghost addresses from vf message */
  847. vf->spq_map = init->spq_addr;
  848. vf->fw_stat_map = init->stats_addr;
  849. vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
  850. /* response */
  851. bnx2x_vf_mbx_resp(bp, vf);
  852. }
  853. /* convert MBX queue-flags to standard SP queue-flags */
  854. static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
  855. unsigned long *sp_q_flags)
  856. {
  857. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
  858. __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
  859. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
  860. __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
  861. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
  862. __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
  863. if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
  864. __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
  865. if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
  866. __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
  867. if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
  868. __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
  869. if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
  870. __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
  871. if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
  872. __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
  873. /* outer vlan removal is set according to the PF's multi fuction mode */
  874. if (IS_MF_SD(bp))
  875. __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
  876. }
  877. static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  878. struct bnx2x_vf_mbx *mbx)
  879. {
  880. struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
  881. struct bnx2x_vfop_cmd cmd = {
  882. .done = bnx2x_vf_mbx_resp,
  883. .block = false,
  884. };
  885. /* verify vf_qid */
  886. if (setup_q->vf_qid >= vf_rxq_count(vf)) {
  887. BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
  888. setup_q->vf_qid, vf_rxq_count(vf));
  889. vf->op_rc = -EINVAL;
  890. goto response;
  891. }
  892. /* tx queues must be setup alongside rx queues thus if the rx queue
  893. * is not marked as valid there's nothing to do.
  894. */
  895. if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
  896. struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
  897. unsigned long q_type = 0;
  898. struct bnx2x_queue_init_params *init_p;
  899. struct bnx2x_queue_setup_params *setup_p;
  900. /* reinit the VF operation context */
  901. memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
  902. setup_p = &vf->op_params.qctor.prep_qsetup;
  903. init_p = &vf->op_params.qctor.qstate.params.init;
  904. /* activate immediately */
  905. __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
  906. if (setup_q->param_valid & VFPF_TXQ_VALID) {
  907. struct bnx2x_txq_setup_params *txq_params =
  908. &setup_p->txq_params;
  909. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  910. /* save sb resource index */
  911. q->sb_idx = setup_q->txq.vf_sb;
  912. /* tx init */
  913. init_p->tx.hc_rate = setup_q->txq.hc_rate;
  914. init_p->tx.sb_cq_index = setup_q->txq.sb_index;
  915. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  916. &init_p->tx.flags);
  917. /* tx setup - flags */
  918. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  919. &setup_p->flags);
  920. /* tx setup - general, nothing */
  921. /* tx setup - tx */
  922. txq_params->dscr_map = setup_q->txq.txq_addr;
  923. txq_params->sb_cq_index = setup_q->txq.sb_index;
  924. txq_params->traffic_type = setup_q->txq.traffic_type;
  925. bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
  926. q->index, q->sb_idx);
  927. }
  928. if (setup_q->param_valid & VFPF_RXQ_VALID) {
  929. struct bnx2x_rxq_setup_params *rxq_params =
  930. &setup_p->rxq_params;
  931. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  932. /* Note: there is no support for different SBs
  933. * for TX and RX
  934. */
  935. q->sb_idx = setup_q->rxq.vf_sb;
  936. /* rx init */
  937. init_p->rx.hc_rate = setup_q->rxq.hc_rate;
  938. init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
  939. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  940. &init_p->rx.flags);
  941. /* rx setup - flags */
  942. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  943. &setup_p->flags);
  944. /* rx setup - general */
  945. setup_p->gen_params.mtu = setup_q->rxq.mtu;
  946. /* rx setup - rx */
  947. rxq_params->drop_flags = setup_q->rxq.drop_flags;
  948. rxq_params->dscr_map = setup_q->rxq.rxq_addr;
  949. rxq_params->sge_map = setup_q->rxq.sge_addr;
  950. rxq_params->rcq_map = setup_q->rxq.rcq_addr;
  951. rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
  952. rxq_params->buf_sz = setup_q->rxq.buf_sz;
  953. rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
  954. rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
  955. rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
  956. rxq_params->cache_line_log =
  957. setup_q->rxq.cache_line_log;
  958. rxq_params->sb_cq_index = setup_q->rxq.sb_index;
  959. bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
  960. q->index, q->sb_idx);
  961. }
  962. /* complete the preparations */
  963. bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
  964. vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
  965. if (vf->op_rc)
  966. goto response;
  967. return;
  968. }
  969. response:
  970. bnx2x_vf_mbx_resp(bp, vf);
  971. }
  972. enum bnx2x_vfop_filters_state {
  973. BNX2X_VFOP_MBX_Q_FILTERS_MACS,
  974. BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
  975. BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
  976. BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
  977. BNX2X_VFOP_MBX_Q_FILTERS_DONE
  978. };
  979. static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
  980. struct bnx2x_virtf *vf,
  981. struct vfpf_set_q_filters_tlv *tlv,
  982. struct bnx2x_vfop_filters **pfl,
  983. u32 type_flag)
  984. {
  985. int i, j;
  986. struct bnx2x_vfop_filters *fl = NULL;
  987. size_t fsz;
  988. fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
  989. sizeof(struct bnx2x_vfop_filters);
  990. fl = kzalloc(fsz, GFP_KERNEL);
  991. if (!fl)
  992. return -ENOMEM;
  993. INIT_LIST_HEAD(&fl->head);
  994. for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
  995. struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
  996. if ((msg_filter->flags & type_flag) != type_flag)
  997. continue;
  998. if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
  999. fl->filters[j].mac = msg_filter->mac;
  1000. fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
  1001. } else {
  1002. fl->filters[j].vid = msg_filter->vlan_tag;
  1003. fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
  1004. }
  1005. fl->filters[j].add =
  1006. (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
  1007. true : false;
  1008. list_add_tail(&fl->filters[j++].link, &fl->head);
  1009. }
  1010. if (list_empty(&fl->head))
  1011. kfree(fl);
  1012. else
  1013. *pfl = fl;
  1014. return 0;
  1015. }
  1016. static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
  1017. struct vfpf_q_mac_vlan_filter *filter)
  1018. {
  1019. DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
  1020. if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
  1021. DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
  1022. if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
  1023. DP_CONT(msglvl, ", MAC=%pM", filter->mac);
  1024. DP_CONT(msglvl, "\n");
  1025. }
  1026. static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
  1027. struct vfpf_set_q_filters_tlv *filters)
  1028. {
  1029. int i;
  1030. if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
  1031. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1032. bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
  1033. &filters->filters[i]);
  1034. if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
  1035. DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
  1036. if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
  1037. for (i = 0; i < filters->n_multicast; i++)
  1038. DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
  1039. }
  1040. #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
  1041. #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
  1042. static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1043. {
  1044. int rc;
  1045. struct vfpf_set_q_filters_tlv *msg =
  1046. &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
  1047. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  1048. enum bnx2x_vfop_filters_state state = vfop->state;
  1049. struct bnx2x_vfop_cmd cmd = {
  1050. .done = bnx2x_vfop_mbx_qfilters,
  1051. .block = false,
  1052. };
  1053. DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
  1054. if (vfop->rc < 0)
  1055. goto op_err;
  1056. switch (state) {
  1057. case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
  1058. /* next state */
  1059. vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
  1060. /* check for any vlan/mac changes */
  1061. if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
  1062. /* build mac list */
  1063. struct bnx2x_vfop_filters *fl = NULL;
  1064. vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1065. VFPF_MAC_FILTER);
  1066. if (vfop->rc)
  1067. goto op_err;
  1068. if (fl) {
  1069. /* set mac list */
  1070. rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
  1071. msg->vf_qid,
  1072. false);
  1073. if (rc) {
  1074. vfop->rc = rc;
  1075. goto op_err;
  1076. }
  1077. return;
  1078. }
  1079. }
  1080. /* fall through */
  1081. case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
  1082. /* next state */
  1083. vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
  1084. /* check for any vlan/mac changes */
  1085. if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
  1086. /* build vlan list */
  1087. struct bnx2x_vfop_filters *fl = NULL;
  1088. vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1089. VFPF_VLAN_FILTER);
  1090. if (vfop->rc)
  1091. goto op_err;
  1092. if (fl) {
  1093. /* set vlan list */
  1094. rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
  1095. msg->vf_qid,
  1096. false);
  1097. if (rc) {
  1098. vfop->rc = rc;
  1099. goto op_err;
  1100. }
  1101. return;
  1102. }
  1103. }
  1104. /* fall through */
  1105. case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
  1106. /* next state */
  1107. vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
  1108. if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
  1109. unsigned long accept = 0;
  1110. /* covert VF-PF if mask to bnx2x accept flags */
  1111. if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
  1112. __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
  1113. if (msg->rx_mask &
  1114. VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
  1115. __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
  1116. if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
  1117. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
  1118. if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
  1119. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
  1120. if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
  1121. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
  1122. /* A packet arriving the vf's mac should be accepted
  1123. * with any vlan
  1124. */
  1125. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
  1126. /* set rx-mode */
  1127. rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
  1128. msg->vf_qid, accept);
  1129. if (rc) {
  1130. vfop->rc = rc;
  1131. goto op_err;
  1132. }
  1133. return;
  1134. }
  1135. /* fall through */
  1136. case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
  1137. /* next state */
  1138. vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
  1139. if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
  1140. /* set mcasts */
  1141. rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
  1142. msg->n_multicast, false);
  1143. if (rc) {
  1144. vfop->rc = rc;
  1145. goto op_err;
  1146. }
  1147. return;
  1148. }
  1149. /* fall through */
  1150. op_done:
  1151. case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
  1152. bnx2x_vfop_end(bp, vf, vfop);
  1153. return;
  1154. op_err:
  1155. BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
  1156. vf->abs_vfid, msg->vf_qid, vfop->rc);
  1157. goto op_done;
  1158. default:
  1159. bnx2x_vfop_default(state);
  1160. }
  1161. }
  1162. static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
  1163. struct bnx2x_virtf *vf,
  1164. struct bnx2x_vfop_cmd *cmd)
  1165. {
  1166. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  1167. if (vfop) {
  1168. bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
  1169. bnx2x_vfop_mbx_qfilters, cmd->done);
  1170. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
  1171. cmd->block);
  1172. }
  1173. return -ENOMEM;
  1174. }
  1175. static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
  1176. struct bnx2x_virtf *vf,
  1177. struct bnx2x_vf_mbx *mbx)
  1178. {
  1179. struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
  1180. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1181. struct bnx2x_vfop_cmd cmd = {
  1182. .done = bnx2x_vf_mbx_resp,
  1183. .block = false,
  1184. };
  1185. /* if a mac was already set for this VF via the set vf mac ndo, we only
  1186. * accept mac configurations of that mac. Why accept them at all?
  1187. * because PF may have been unable to configure the mac at the time
  1188. * since queue was not set up.
  1189. */
  1190. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1191. /* once a mac was set by ndo can only accept a single mac... */
  1192. if (filters->n_mac_vlan_filters > 1) {
  1193. BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
  1194. vf->abs_vfid);
  1195. vf->op_rc = -EPERM;
  1196. goto response;
  1197. }
  1198. /* ...and only the mac set by the ndo */
  1199. if (filters->n_mac_vlan_filters == 1 &&
  1200. memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
  1201. BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
  1202. vf->abs_vfid);
  1203. vf->op_rc = -EPERM;
  1204. goto response;
  1205. }
  1206. }
  1207. /* verify vf_qid */
  1208. if (filters->vf_qid > vf_rxq_count(vf))
  1209. goto response;
  1210. DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
  1211. vf->abs_vfid,
  1212. filters->vf_qid);
  1213. /* print q_filter message */
  1214. bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
  1215. vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
  1216. if (vf->op_rc)
  1217. goto response;
  1218. return;
  1219. response:
  1220. bnx2x_vf_mbx_resp(bp, vf);
  1221. }
  1222. static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1223. struct bnx2x_vf_mbx *mbx)
  1224. {
  1225. int qid = mbx->msg->req.q_op.vf_qid;
  1226. struct bnx2x_vfop_cmd cmd = {
  1227. .done = bnx2x_vf_mbx_resp,
  1228. .block = false,
  1229. };
  1230. DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
  1231. vf->abs_vfid, qid);
  1232. vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
  1233. if (vf->op_rc)
  1234. bnx2x_vf_mbx_resp(bp, vf);
  1235. }
  1236. static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1237. struct bnx2x_vf_mbx *mbx)
  1238. {
  1239. struct bnx2x_vfop_cmd cmd = {
  1240. .done = bnx2x_vf_mbx_resp,
  1241. .block = false,
  1242. };
  1243. DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
  1244. vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
  1245. if (vf->op_rc)
  1246. bnx2x_vf_mbx_resp(bp, vf);
  1247. }
  1248. static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1249. struct bnx2x_vf_mbx *mbx)
  1250. {
  1251. struct bnx2x_vfop_cmd cmd = {
  1252. .done = bnx2x_vf_mbx_resp,
  1253. .block = false,
  1254. };
  1255. DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
  1256. vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
  1257. if (vf->op_rc)
  1258. bnx2x_vf_mbx_resp(bp, vf);
  1259. }
  1260. /* dispatch request */
  1261. static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1262. struct bnx2x_vf_mbx *mbx)
  1263. {
  1264. int i;
  1265. /* check if tlv type is known */
  1266. if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
  1267. /* Lock the per vf op mutex and note the locker's identity.
  1268. * The unlock will take place in mbx response.
  1269. */
  1270. bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1271. /* switch on the opcode */
  1272. switch (mbx->first_tlv.tl.type) {
  1273. case CHANNEL_TLV_ACQUIRE:
  1274. bnx2x_vf_mbx_acquire(bp, vf, mbx);
  1275. break;
  1276. case CHANNEL_TLV_INIT:
  1277. bnx2x_vf_mbx_init_vf(bp, vf, mbx);
  1278. break;
  1279. case CHANNEL_TLV_SETUP_Q:
  1280. bnx2x_vf_mbx_setup_q(bp, vf, mbx);
  1281. break;
  1282. case CHANNEL_TLV_SET_Q_FILTERS:
  1283. bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
  1284. break;
  1285. case CHANNEL_TLV_TEARDOWN_Q:
  1286. bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
  1287. break;
  1288. case CHANNEL_TLV_CLOSE:
  1289. bnx2x_vf_mbx_close_vf(bp, vf, mbx);
  1290. break;
  1291. case CHANNEL_TLV_RELEASE:
  1292. bnx2x_vf_mbx_release_vf(bp, vf, mbx);
  1293. break;
  1294. }
  1295. } else {
  1296. /* unknown TLV - this may belong to a VF driver from the future
  1297. * - a version written after this PF driver was written, which
  1298. * supports features unknown as of yet. Too bad since we don't
  1299. * support them. Or this may be because someone wrote a crappy
  1300. * VF driver and is sending garbage over the channel.
  1301. */
  1302. BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
  1303. mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
  1304. for (i = 0; i < 20; i++)
  1305. DP_CONT(BNX2X_MSG_IOV, "%x ",
  1306. mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
  1307. /* test whether we can respond to the VF (do we have an address
  1308. * for it?)
  1309. */
  1310. if (vf->state == VF_ACQUIRED) {
  1311. /* mbx_resp uses the op_rc of the VF */
  1312. vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
  1313. /* notify the VF that we do not support this request */
  1314. bnx2x_vf_mbx_resp(bp, vf);
  1315. } else {
  1316. /* can't send a response since this VF is unknown to us
  1317. * just unlock the channel and be done with.
  1318. */
  1319. bnx2x_unlock_vf_pf_channel(bp, vf,
  1320. mbx->first_tlv.tl.type);
  1321. }
  1322. }
  1323. }
  1324. /* handle new vf-pf message */
  1325. void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
  1326. {
  1327. struct bnx2x_virtf *vf;
  1328. struct bnx2x_vf_mbx *mbx;
  1329. u8 vf_idx;
  1330. int rc;
  1331. DP(BNX2X_MSG_IOV,
  1332. "vf pf event received: vfid %d, address_hi %x, address lo %x",
  1333. vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
  1334. /* Sanity checks consider removing later */
  1335. /* check if the vf_id is valid */
  1336. if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
  1337. BNX2X_NR_VIRTFN(bp)) {
  1338. BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
  1339. vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
  1340. goto mbx_done;
  1341. }
  1342. vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
  1343. mbx = BP_VF_MBX(bp, vf_idx);
  1344. /* verify an event is not currently being processed -
  1345. * debug failsafe only
  1346. */
  1347. if (mbx->flags & VF_MSG_INPROCESS) {
  1348. BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
  1349. vfpf_event->vf_id);
  1350. goto mbx_done;
  1351. }
  1352. vf = BP_VF(bp, vf_idx);
  1353. /* save the VF message address */
  1354. mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
  1355. mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
  1356. DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
  1357. mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
  1358. /* dmae to get the VF request */
  1359. rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
  1360. mbx->vf_addr_hi, mbx->vf_addr_lo,
  1361. sizeof(union vfpf_tlvs)/4);
  1362. if (rc) {
  1363. BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
  1364. goto mbx_error;
  1365. }
  1366. /* process the VF message header */
  1367. mbx->first_tlv = mbx->msg->req.first_tlv;
  1368. /* dispatch the request (will prepare the response) */
  1369. bnx2x_vf_mbx_request(bp, vf, mbx);
  1370. goto mbx_done;
  1371. mbx_error:
  1372. bnx2x_vf_release(bp, vf, false); /* non blocking */
  1373. mbx_done:
  1374. return;
  1375. }
  1376. /* propagate local bulletin board to vf */
  1377. int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
  1378. {
  1379. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
  1380. dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
  1381. vf * BULLETIN_CONTENT_SIZE;
  1382. dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
  1383. int rc;
  1384. /* can only update vf after init took place */
  1385. if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
  1386. bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
  1387. return 0;
  1388. /* increment bulletin board version and compute crc */
  1389. bulletin->version++;
  1390. bulletin->length = BULLETIN_CONTENT_SIZE;
  1391. bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
  1392. /* propagate bulletin board via dmae to vm memory */
  1393. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
  1394. bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
  1395. U64_LO(vf_addr), bulletin->length / 4);
  1396. return rc;
  1397. }