bnx2x_vfpf.c 46 KB

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