bnx2x_vfpf.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290
  1. /* bnx2x_vfpf.c: QLogic Everest network driver.
  2. *
  3. * Copyright 2009-2013 Broadcom Corporation
  4. * Copyright 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * Unless you and QLogic execute a separate written software license
  8. * agreement governing use of this software, this software is licensed to you
  9. * under the terms of the GNU General Public License version 2, available
  10. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  11. *
  12. * Notwithstanding the above, under no circumstances may you combine this
  13. * software in any way with any other QLogic software provided under a
  14. * license other than the GPL, without QLogic's express prior written
  15. * consent.
  16. *
  17. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  18. * Written by: Shmulik Ravid
  19. * Ariel Elior <ariel.elior@qlogic.com>
  20. */
  21. #include "bnx2x.h"
  22. #include "bnx2x_cmn.h"
  23. #include <linux/crc32.h>
  24. static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
  25. /* place a given tlv on the tlv buffer at a given offset */
  26. static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
  27. u16 offset, u16 type, u16 length)
  28. {
  29. struct channel_tlv *tl =
  30. (struct channel_tlv *)(tlvs_list + offset);
  31. tl->type = type;
  32. tl->length = length;
  33. }
  34. /* Clear the mailbox and init the header of the first tlv */
  35. static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
  36. u16 type, u16 length)
  37. {
  38. mutex_lock(&bp->vf2pf_mutex);
  39. DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
  40. type);
  41. /* Clear mailbox */
  42. memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
  43. /* init type and length */
  44. bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
  45. /* init first tlv header */
  46. first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
  47. }
  48. /* releases the mailbox */
  49. static void bnx2x_vfpf_finalize(struct bnx2x *bp,
  50. struct vfpf_first_tlv *first_tlv)
  51. {
  52. DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
  53. first_tlv->tl.type);
  54. mutex_unlock(&bp->vf2pf_mutex);
  55. }
  56. /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
  57. static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
  58. enum channel_tlvs req_tlv)
  59. {
  60. struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
  61. do {
  62. if (tlv->type == req_tlv)
  63. return tlv;
  64. if (!tlv->length) {
  65. BNX2X_ERR("Found TLV with length 0\n");
  66. return NULL;
  67. }
  68. tlvs_list += tlv->length;
  69. tlv = (struct channel_tlv *)tlvs_list;
  70. } while (tlv->type != CHANNEL_TLV_LIST_END);
  71. DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
  72. return NULL;
  73. }
  74. /* list the types and lengths of the tlvs on the buffer */
  75. static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
  76. {
  77. int i = 1;
  78. struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
  79. while (tlv->type != CHANNEL_TLV_LIST_END) {
  80. /* output tlv */
  81. DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
  82. tlv->type, tlv->length);
  83. /* advance to next tlv */
  84. tlvs_list += tlv->length;
  85. /* cast general tlv list pointer to channel tlv header*/
  86. tlv = (struct channel_tlv *)tlvs_list;
  87. i++;
  88. /* break condition for this loop */
  89. if (i > MAX_TLVS_IN_LIST) {
  90. WARN(true, "corrupt tlvs");
  91. return;
  92. }
  93. }
  94. /* output last tlv */
  95. DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
  96. tlv->type, tlv->length);
  97. }
  98. /* test whether we support a tlv type */
  99. bool bnx2x_tlv_supported(u16 tlvtype)
  100. {
  101. return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
  102. }
  103. static inline int bnx2x_pfvf_status_codes(int rc)
  104. {
  105. switch (rc) {
  106. case 0:
  107. return PFVF_STATUS_SUCCESS;
  108. case -ENOMEM:
  109. return PFVF_STATUS_NO_RESOURCE;
  110. default:
  111. return PFVF_STATUS_FAILURE;
  112. }
  113. }
  114. static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
  115. {
  116. struct cstorm_vf_zone_data __iomem *zone_data =
  117. REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
  118. int tout = 100, interval = 100; /* wait for 10 seconds */
  119. if (*done) {
  120. BNX2X_ERR("done was non zero before message to pf was sent\n");
  121. WARN_ON(true);
  122. return -EINVAL;
  123. }
  124. /* if PF indicated channel is down avoid sending message. Return success
  125. * so calling flow can continue
  126. */
  127. bnx2x_sample_bulletin(bp);
  128. if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
  129. DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
  130. *done = PFVF_STATUS_SUCCESS;
  131. return -EINVAL;
  132. }
  133. /* Write message address */
  134. writel(U64_LO(msg_mapping),
  135. &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
  136. writel(U64_HI(msg_mapping),
  137. &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
  138. /* make sure the address is written before FW accesses it */
  139. wmb();
  140. /* Trigger the PF FW */
  141. writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
  142. /* Wait for PF to complete */
  143. while ((tout >= 0) && (!*done)) {
  144. msleep(interval);
  145. tout -= 1;
  146. /* progress indicator - HV can take its own sweet time in
  147. * answering VFs...
  148. */
  149. DP_CONT(BNX2X_MSG_IOV, ".");
  150. }
  151. if (!*done) {
  152. BNX2X_ERR("PF response has timed out\n");
  153. return -EAGAIN;
  154. }
  155. DP(BNX2X_MSG_SP, "Got a response from PF\n");
  156. return 0;
  157. }
  158. static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
  159. {
  160. u32 me_reg;
  161. int tout = 10, interval = 100; /* Wait for 1 sec */
  162. do {
  163. /* pxp traps vf read of doorbells and returns me reg value */
  164. me_reg = readl(bp->doorbells);
  165. if (GOOD_ME_REG(me_reg))
  166. break;
  167. msleep(interval);
  168. BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
  169. me_reg);
  170. } while (tout-- > 0);
  171. if (!GOOD_ME_REG(me_reg)) {
  172. BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
  173. return -EINVAL;
  174. }
  175. DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
  176. *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
  177. return 0;
  178. }
  179. int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
  180. {
  181. int rc = 0, attempts = 0;
  182. struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
  183. struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
  184. struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
  185. struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
  186. u32 vf_id;
  187. bool resources_acquired = false;
  188. /* clear mailbox and prep first tlv */
  189. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  190. if (bnx2x_get_vf_id(bp, &vf_id)) {
  191. rc = -EAGAIN;
  192. goto out;
  193. }
  194. req->vfdev_info.vf_id = vf_id;
  195. req->vfdev_info.vf_os = 0;
  196. req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
  197. req->resc_request.num_rxqs = rx_count;
  198. req->resc_request.num_txqs = tx_count;
  199. req->resc_request.num_sbs = bp->igu_sb_cnt;
  200. req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
  201. req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
  202. req->resc_request.num_vlan_filters = VF_ACQUIRE_VLAN_FILTERS;
  203. /* pf 2 vf bulletin board address */
  204. req->bulletin_addr = bp->pf2vf_bulletin_mapping;
  205. /* Request physical port identifier */
  206. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
  207. CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
  208. /* Bulletin support for bulletin board with length > legacy length */
  209. req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
  210. /* vlan filtering is supported */
  211. req->vfdev_info.caps |= VF_CAP_SUPPORT_VLAN_FILTER;
  212. /* add list termination tlv */
  213. bnx2x_add_tlv(bp, req,
  214. req->first_tlv.tl.length + sizeof(struct channel_tlv),
  215. CHANNEL_TLV_LIST_END,
  216. sizeof(struct channel_list_end_tlv));
  217. /* output tlvs list */
  218. bnx2x_dp_tlv_list(bp, req);
  219. while (!resources_acquired) {
  220. DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
  221. /* send acquire request */
  222. rc = bnx2x_send_msg2pf(bp,
  223. &resp->hdr.status,
  224. bp->vf2pf_mbox_mapping);
  225. /* PF timeout */
  226. if (rc)
  227. goto out;
  228. /* copy acquire response from buffer to bp */
  229. memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
  230. attempts++;
  231. /* test whether the PF accepted our request. If not, humble
  232. * the request and try again.
  233. */
  234. if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
  235. DP(BNX2X_MSG_SP, "resources acquired\n");
  236. resources_acquired = true;
  237. } else if (bp->acquire_resp.hdr.status ==
  238. PFVF_STATUS_NO_RESOURCE &&
  239. attempts < VF_ACQUIRE_THRESH) {
  240. DP(BNX2X_MSG_SP,
  241. "PF unwilling to fulfill resource request. Try PF recommended amount\n");
  242. /* humble our request */
  243. req->resc_request.num_txqs =
  244. min(req->resc_request.num_txqs,
  245. bp->acquire_resp.resc.num_txqs);
  246. req->resc_request.num_rxqs =
  247. min(req->resc_request.num_rxqs,
  248. bp->acquire_resp.resc.num_rxqs);
  249. req->resc_request.num_sbs =
  250. min(req->resc_request.num_sbs,
  251. bp->acquire_resp.resc.num_sbs);
  252. req->resc_request.num_mac_filters =
  253. min(req->resc_request.num_mac_filters,
  254. bp->acquire_resp.resc.num_mac_filters);
  255. req->resc_request.num_vlan_filters =
  256. min(req->resc_request.num_vlan_filters,
  257. bp->acquire_resp.resc.num_vlan_filters);
  258. req->resc_request.num_mc_filters =
  259. min(req->resc_request.num_mc_filters,
  260. bp->acquire_resp.resc.num_mc_filters);
  261. /* Clear response buffer */
  262. memset(&bp->vf2pf_mbox->resp, 0,
  263. sizeof(union pfvf_tlvs));
  264. } else {
  265. /* Determine reason of PF failure of acquire process */
  266. fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
  267. CHANNEL_TLV_FP_HSI_SUPPORT);
  268. if (fp_hsi_resp && !fp_hsi_resp->is_supported)
  269. BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
  270. else
  271. BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
  272. bp->acquire_resp.hdr.status);
  273. rc = -EAGAIN;
  274. goto out;
  275. }
  276. }
  277. /* Retrieve physical port id (if possible) */
  278. phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
  279. bnx2x_search_tlv_list(bp, resp,
  280. CHANNEL_TLV_PHYS_PORT_ID);
  281. if (phys_port_resp) {
  282. memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
  283. bp->flags |= HAS_PHYS_PORT_ID;
  284. }
  285. /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
  286. * If that's the case, we need to make certain required FW was
  287. * supported by such a hypervisor [i.e., v0-v2].
  288. */
  289. fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
  290. CHANNEL_TLV_FP_HSI_SUPPORT);
  291. if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
  292. BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
  293. /* Since acquire succeeded on the PF side, we need to send a
  294. * release message in order to allow future probes.
  295. */
  296. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  297. bnx2x_vfpf_release(bp);
  298. rc = -EINVAL;
  299. goto out;
  300. }
  301. /* get HW info */
  302. bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
  303. bp->link_params.chip_id = bp->common.chip_id;
  304. bp->db_size = bp->acquire_resp.pfdev_info.db_size;
  305. bp->common.int_block = INT_BLOCK_IGU;
  306. bp->common.chip_port_mode = CHIP_2_PORT_MODE;
  307. bp->igu_dsb_id = -1;
  308. bp->mf_ov = 0;
  309. bp->mf_mode = 0;
  310. bp->common.flash_size = 0;
  311. bp->flags |=
  312. NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
  313. bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
  314. bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
  315. bp->vlan_credit = bp->acquire_resp.resc.num_vlan_filters;
  316. strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
  317. sizeof(bp->fw_ver));
  318. if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
  319. memcpy(bp->dev->dev_addr,
  320. bp->acquire_resp.resc.current_mac_addr,
  321. ETH_ALEN);
  322. out:
  323. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  324. return rc;
  325. }
  326. int bnx2x_vfpf_release(struct bnx2x *bp)
  327. {
  328. struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
  329. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  330. u32 rc, vf_id;
  331. /* clear mailbox and prep first tlv */
  332. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
  333. if (bnx2x_get_vf_id(bp, &vf_id)) {
  334. rc = -EAGAIN;
  335. goto out;
  336. }
  337. req->vf_id = vf_id;
  338. /* add list termination tlv */
  339. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  340. sizeof(struct channel_list_end_tlv));
  341. /* output tlvs list */
  342. bnx2x_dp_tlv_list(bp, req);
  343. /* send release request */
  344. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  345. if (rc)
  346. /* PF timeout */
  347. goto out;
  348. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  349. /* PF released us */
  350. DP(BNX2X_MSG_SP, "vf released\n");
  351. } else {
  352. /* PF reports error */
  353. BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
  354. resp->hdr.status);
  355. rc = -EAGAIN;
  356. goto out;
  357. }
  358. out:
  359. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  360. return rc;
  361. }
  362. /* Tell PF about SB addresses */
  363. int bnx2x_vfpf_init(struct bnx2x *bp)
  364. {
  365. struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
  366. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  367. int rc, i;
  368. /* clear mailbox and prep first tlv */
  369. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
  370. /* status blocks */
  371. for_each_eth_queue(bp, i)
  372. req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
  373. status_blk_mapping);
  374. /* statistics - requests only supports single queue for now */
  375. req->stats_addr = bp->fw_stats_data_mapping +
  376. offsetof(struct bnx2x_fw_stats_data, queue_stats);
  377. req->stats_stride = sizeof(struct per_queue_stats);
  378. /* add list termination tlv */
  379. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  380. sizeof(struct channel_list_end_tlv));
  381. /* output tlvs list */
  382. bnx2x_dp_tlv_list(bp, req);
  383. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  384. if (rc)
  385. goto out;
  386. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  387. BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
  388. resp->hdr.status);
  389. rc = -EAGAIN;
  390. goto out;
  391. }
  392. DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
  393. out:
  394. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  395. return rc;
  396. }
  397. /* CLOSE VF - opposite to INIT_VF */
  398. void bnx2x_vfpf_close_vf(struct bnx2x *bp)
  399. {
  400. struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
  401. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  402. int i, rc;
  403. u32 vf_id;
  404. /* If we haven't got a valid VF id, there is no sense to
  405. * continue with sending messages
  406. */
  407. if (bnx2x_get_vf_id(bp, &vf_id))
  408. goto free_irq;
  409. /* Close the queues */
  410. for_each_queue(bp, i)
  411. bnx2x_vfpf_teardown_queue(bp, i);
  412. /* remove mac */
  413. bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
  414. /* clear mailbox and prep first tlv */
  415. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
  416. req->vf_id = vf_id;
  417. /* add list termination tlv */
  418. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  419. sizeof(struct channel_list_end_tlv));
  420. /* output tlvs list */
  421. bnx2x_dp_tlv_list(bp, req);
  422. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  423. if (rc)
  424. BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
  425. else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
  426. BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
  427. resp->hdr.status);
  428. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  429. free_irq:
  430. /* Disable HW interrupts, NAPI */
  431. bnx2x_netif_stop(bp, 0);
  432. /* Delete all NAPI objects */
  433. bnx2x_del_all_napi(bp);
  434. /* Release IRQs */
  435. bnx2x_free_irq(bp);
  436. }
  437. static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  438. struct bnx2x_vf_queue *q)
  439. {
  440. u8 cl_id = vfq_cl_id(vf, q);
  441. u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
  442. /* mac */
  443. bnx2x_init_mac_obj(bp, &q->mac_obj,
  444. cl_id, q->cid, func_id,
  445. bnx2x_vf_sp(bp, vf, mac_rdata),
  446. bnx2x_vf_sp_map(bp, vf, mac_rdata),
  447. BNX2X_FILTER_MAC_PENDING,
  448. &vf->filter_state,
  449. BNX2X_OBJ_TYPE_RX_TX,
  450. &vf->vf_macs_pool);
  451. /* vlan */
  452. bnx2x_init_vlan_obj(bp, &q->vlan_obj,
  453. cl_id, q->cid, func_id,
  454. bnx2x_vf_sp(bp, vf, vlan_rdata),
  455. bnx2x_vf_sp_map(bp, vf, vlan_rdata),
  456. BNX2X_FILTER_VLAN_PENDING,
  457. &vf->filter_state,
  458. BNX2X_OBJ_TYPE_RX_TX,
  459. &vf->vf_vlans_pool);
  460. /* vlan-mac */
  461. bnx2x_init_vlan_mac_obj(bp, &q->vlan_mac_obj,
  462. cl_id, q->cid, func_id,
  463. bnx2x_vf_sp(bp, vf, vlan_mac_rdata),
  464. bnx2x_vf_sp_map(bp, vf, vlan_mac_rdata),
  465. BNX2X_FILTER_VLAN_MAC_PENDING,
  466. &vf->filter_state,
  467. BNX2X_OBJ_TYPE_RX_TX,
  468. &vf->vf_macs_pool,
  469. &vf->vf_vlans_pool);
  470. /* mcast */
  471. bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
  472. q->cid, func_id, func_id,
  473. bnx2x_vf_sp(bp, vf, mcast_rdata),
  474. bnx2x_vf_sp_map(bp, vf, mcast_rdata),
  475. BNX2X_FILTER_MCAST_PENDING,
  476. &vf->filter_state,
  477. BNX2X_OBJ_TYPE_RX_TX);
  478. /* rss */
  479. bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
  480. func_id, func_id,
  481. bnx2x_vf_sp(bp, vf, rss_rdata),
  482. bnx2x_vf_sp_map(bp, vf, rss_rdata),
  483. BNX2X_FILTER_RSS_CONF_PENDING,
  484. &vf->filter_state,
  485. BNX2X_OBJ_TYPE_RX_TX);
  486. vf->leading_rss = cl_id;
  487. q->is_leading = true;
  488. q->sp_initialized = true;
  489. }
  490. /* ask the pf to open a queue for the vf */
  491. int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  492. bool is_leading)
  493. {
  494. struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
  495. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  496. u8 fp_idx = fp->index;
  497. u16 tpa_agg_size = 0, flags = 0;
  498. int rc;
  499. /* clear mailbox and prep first tlv */
  500. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
  501. /* select tpa mode to request */
  502. if (fp->mode != TPA_MODE_DISABLED) {
  503. flags |= VFPF_QUEUE_FLG_TPA;
  504. flags |= VFPF_QUEUE_FLG_TPA_IPV6;
  505. if (fp->mode == TPA_MODE_GRO)
  506. flags |= VFPF_QUEUE_FLG_TPA_GRO;
  507. tpa_agg_size = TPA_AGG_SIZE;
  508. }
  509. if (is_leading)
  510. flags |= VFPF_QUEUE_FLG_LEADING_RSS;
  511. /* calculate queue flags */
  512. flags |= VFPF_QUEUE_FLG_STATS;
  513. flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
  514. flags |= VFPF_QUEUE_FLG_VLAN;
  515. /* Common */
  516. req->vf_qid = fp_idx;
  517. req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
  518. /* Rx */
  519. req->rxq.rcq_addr = fp->rx_comp_mapping;
  520. req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  521. req->rxq.rxq_addr = fp->rx_desc_mapping;
  522. req->rxq.sge_addr = fp->rx_sge_mapping;
  523. req->rxq.vf_sb = fp_idx;
  524. req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
  525. req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
  526. req->rxq.mtu = bp->dev->mtu;
  527. req->rxq.buf_sz = fp->rx_buf_size;
  528. req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
  529. req->rxq.tpa_agg_sz = tpa_agg_size;
  530. req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
  531. req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
  532. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  533. req->rxq.flags = flags;
  534. req->rxq.drop_flags = 0;
  535. req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  536. req->rxq.stat_id = -1; /* No stats at the moment */
  537. /* Tx */
  538. req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
  539. req->txq.vf_sb = fp_idx;
  540. req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
  541. req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
  542. req->txq.flags = flags;
  543. req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
  544. /* add list termination tlv */
  545. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  546. sizeof(struct channel_list_end_tlv));
  547. /* output tlvs list */
  548. bnx2x_dp_tlv_list(bp, req);
  549. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  550. if (rc)
  551. BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
  552. fp_idx);
  553. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  554. BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
  555. fp_idx, resp->hdr.status);
  556. rc = -EINVAL;
  557. }
  558. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  559. return rc;
  560. }
  561. static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
  562. {
  563. struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
  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_TEARDOWN_Q,
  568. sizeof(*req));
  569. req->vf_qid = qidx;
  570. /* add list termination tlv */
  571. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  572. sizeof(struct channel_list_end_tlv));
  573. /* output tlvs list */
  574. bnx2x_dp_tlv_list(bp, req);
  575. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  576. if (rc) {
  577. BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
  578. rc);
  579. goto out;
  580. }
  581. /* PF failed the transaction */
  582. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  583. BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
  584. resp->hdr.status);
  585. rc = -EINVAL;
  586. }
  587. out:
  588. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  589. return rc;
  590. }
  591. /* request pf to add a mac for the vf */
  592. int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
  593. {
  594. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  595. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  596. struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
  597. int rc = 0;
  598. /* clear mailbox and prep first tlv */
  599. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  600. sizeof(*req));
  601. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  602. req->vf_qid = vf_qid;
  603. req->n_mac_vlan_filters = 1;
  604. req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
  605. if (set)
  606. req->filters[0].flags |= VFPF_Q_FILTER_SET;
  607. /* sample bulletin board for new mac */
  608. bnx2x_sample_bulletin(bp);
  609. /* copy mac from device to request */
  610. memcpy(req->filters[0].mac, addr, ETH_ALEN);
  611. /* add list termination tlv */
  612. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  613. sizeof(struct channel_list_end_tlv));
  614. /* output tlvs list */
  615. bnx2x_dp_tlv_list(bp, req);
  616. /* send message to pf */
  617. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  618. if (rc) {
  619. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  620. goto out;
  621. }
  622. /* failure may mean PF was configured with a new mac for us */
  623. while (resp->hdr.status == PFVF_STATUS_FAILURE) {
  624. DP(BNX2X_MSG_IOV,
  625. "vfpf SET MAC failed. Check bulletin board for new posts\n");
  626. /* copy mac from bulletin to device */
  627. memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
  628. /* check if bulletin board was updated */
  629. if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
  630. /* copy mac from device to request */
  631. memcpy(req->filters[0].mac, bp->dev->dev_addr,
  632. ETH_ALEN);
  633. /* send message to pf */
  634. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
  635. bp->vf2pf_mbox_mapping);
  636. } else {
  637. /* no new info in bulletin */
  638. break;
  639. }
  640. }
  641. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  642. BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
  643. rc = -EINVAL;
  644. }
  645. out:
  646. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  647. return rc;
  648. }
  649. /* request pf to config rss table for vf queues*/
  650. int bnx2x_vfpf_config_rss(struct bnx2x *bp,
  651. struct bnx2x_config_rss_params *params)
  652. {
  653. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  654. struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
  655. int rc = 0;
  656. /* clear mailbox and prep first tlv */
  657. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
  658. sizeof(*req));
  659. /* add list termination tlv */
  660. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  661. sizeof(struct channel_list_end_tlv));
  662. memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
  663. memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
  664. req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
  665. req->rss_key_size = T_ETH_RSS_KEY;
  666. req->rss_result_mask = params->rss_result_mask;
  667. /* flags handled individually for backward/forward compatibility */
  668. if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
  669. req->rss_flags |= VFPF_RSS_MODE_DISABLED;
  670. if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
  671. req->rss_flags |= VFPF_RSS_MODE_REGULAR;
  672. if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
  673. req->rss_flags |= VFPF_RSS_SET_SRCH;
  674. if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
  675. req->rss_flags |= VFPF_RSS_IPV4;
  676. if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
  677. req->rss_flags |= VFPF_RSS_IPV4_TCP;
  678. if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
  679. req->rss_flags |= VFPF_RSS_IPV4_UDP;
  680. if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
  681. req->rss_flags |= VFPF_RSS_IPV6;
  682. if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
  683. req->rss_flags |= VFPF_RSS_IPV6_TCP;
  684. if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
  685. req->rss_flags |= VFPF_RSS_IPV6_UDP;
  686. DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
  687. /* output tlvs list */
  688. bnx2x_dp_tlv_list(bp, req);
  689. /* send message to pf */
  690. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  691. if (rc) {
  692. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  693. goto out;
  694. }
  695. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  696. /* Since older drivers don't support this feature (and VF has
  697. * no way of knowing other than failing this), don't propagate
  698. * an error in this case.
  699. */
  700. DP(BNX2X_MSG_IOV,
  701. "Failed to send rss message to PF over VF-PF channel [%d]\n",
  702. resp->hdr.status);
  703. }
  704. out:
  705. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  706. return rc;
  707. }
  708. int bnx2x_vfpf_set_mcast(struct net_device *dev)
  709. {
  710. struct bnx2x *bp = netdev_priv(dev);
  711. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  712. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  713. int rc = 0, i = 0;
  714. struct netdev_hw_addr *ha;
  715. if (bp->state != BNX2X_STATE_OPEN) {
  716. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  717. return -EINVAL;
  718. }
  719. /* clear mailbox and prep first tlv */
  720. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  721. sizeof(*req));
  722. /* Get Rx mode requested */
  723. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  724. /* We support PFVF_MAX_MULTICAST_PER_VF mcast addresses tops */
  725. if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) {
  726. DP(NETIF_MSG_IFUP,
  727. "VF supports not more than %d multicast MAC addresses\n",
  728. PFVF_MAX_MULTICAST_PER_VF);
  729. rc = -EINVAL;
  730. goto out;
  731. }
  732. netdev_for_each_mc_addr(ha, dev) {
  733. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  734. bnx2x_mc_addr(ha));
  735. memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
  736. i++;
  737. }
  738. req->n_multicast = i;
  739. req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
  740. req->vf_qid = 0;
  741. /* add list termination tlv */
  742. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  743. sizeof(struct channel_list_end_tlv));
  744. /* output tlvs list */
  745. bnx2x_dp_tlv_list(bp, req);
  746. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  747. if (rc) {
  748. BNX2X_ERR("Sending a message failed: %d\n", rc);
  749. goto out;
  750. }
  751. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  752. BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
  753. resp->hdr.status);
  754. rc = -EINVAL;
  755. }
  756. out:
  757. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  758. return rc;
  759. }
  760. /* request pf to add a vlan for the vf */
  761. int bnx2x_vfpf_update_vlan(struct bnx2x *bp, u16 vid, u8 vf_qid, bool add)
  762. {
  763. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  764. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  765. int rc = 0;
  766. if (!(bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER)) {
  767. DP(BNX2X_MSG_IOV, "HV does not support vlan filtering\n");
  768. return 0;
  769. }
  770. /* clear mailbox and prep first tlv */
  771. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  772. sizeof(*req));
  773. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  774. req->vf_qid = vf_qid;
  775. req->n_mac_vlan_filters = 1;
  776. req->filters[0].flags = VFPF_Q_FILTER_VLAN_TAG_VALID;
  777. if (add)
  778. req->filters[0].flags |= VFPF_Q_FILTER_SET;
  779. /* sample bulletin board for hypervisor vlan */
  780. bnx2x_sample_bulletin(bp);
  781. if (bp->shadow_bulletin.content.valid_bitmap & 1 << VLAN_VALID) {
  782. BNX2X_ERR("Hypervisor will dicline the request, avoiding\n");
  783. rc = -EINVAL;
  784. goto out;
  785. }
  786. req->filters[0].vlan_tag = vid;
  787. /* add list termination tlv */
  788. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  789. sizeof(struct channel_list_end_tlv));
  790. /* output tlvs list */
  791. bnx2x_dp_tlv_list(bp, req);
  792. /* send message to pf */
  793. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  794. if (rc) {
  795. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  796. goto out;
  797. }
  798. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  799. BNX2X_ERR("vfpf %s VLAN %d failed\n", add ? "add" : "del",
  800. vid);
  801. rc = -EINVAL;
  802. }
  803. out:
  804. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  805. return rc;
  806. }
  807. int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
  808. {
  809. int mode = bp->rx_mode;
  810. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  811. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  812. int rc;
  813. /* clear mailbox and prep first tlv */
  814. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  815. sizeof(*req));
  816. DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
  817. /* Ignore everything accept MODE_NONE */
  818. if (mode == BNX2X_RX_MODE_NONE) {
  819. req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
  820. } else {
  821. /* Current PF driver will not look at the specific flags,
  822. * but they are required when working with older drivers on hv.
  823. */
  824. req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
  825. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  826. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  827. if (mode == BNX2X_RX_MODE_PROMISC)
  828. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
  829. }
  830. if (bp->accept_any_vlan)
  831. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
  832. req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
  833. req->vf_qid = 0;
  834. /* add list termination tlv */
  835. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  836. sizeof(struct channel_list_end_tlv));
  837. /* output tlvs list */
  838. bnx2x_dp_tlv_list(bp, req);
  839. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  840. if (rc)
  841. BNX2X_ERR("Sending a message failed: %d\n", rc);
  842. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  843. BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
  844. rc = -EINVAL;
  845. }
  846. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  847. return rc;
  848. }
  849. /* General service functions */
  850. static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
  851. {
  852. u32 addr = BAR_CSTRORM_INTMEM +
  853. CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
  854. REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
  855. }
  856. static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
  857. {
  858. u32 addr = BAR_CSTRORM_INTMEM +
  859. CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
  860. REG_WR8(bp, addr, 1);
  861. }
  862. /* enable vf_pf mailbox (aka vf-pf-channel) */
  863. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
  864. {
  865. bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
  866. /* enable the mailbox in the FW */
  867. storm_memset_vf_mbx_ack(bp, abs_vfid);
  868. storm_memset_vf_mbx_valid(bp, abs_vfid);
  869. /* enable the VF access to the mailbox */
  870. bnx2x_vf_enable_access(bp, abs_vfid);
  871. }
  872. /* this works only on !E1h */
  873. static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
  874. dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
  875. u32 vf_addr_lo, u32 len32)
  876. {
  877. struct dmae_command dmae;
  878. if (CHIP_IS_E1x(bp)) {
  879. BNX2X_ERR("Chip revision does not support VFs\n");
  880. return DMAE_NOT_RDY;
  881. }
  882. if (!bp->dmae_ready) {
  883. BNX2X_ERR("DMAE is not ready, can not copy\n");
  884. return DMAE_NOT_RDY;
  885. }
  886. /* set opcode and fixed command fields */
  887. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
  888. if (from_vf) {
  889. dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
  890. (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
  891. (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
  892. dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
  893. dmae.src_addr_lo = vf_addr_lo;
  894. dmae.src_addr_hi = vf_addr_hi;
  895. dmae.dst_addr_lo = U64_LO(pf_addr);
  896. dmae.dst_addr_hi = U64_HI(pf_addr);
  897. } else {
  898. dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
  899. (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
  900. (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
  901. dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
  902. dmae.src_addr_lo = U64_LO(pf_addr);
  903. dmae.src_addr_hi = U64_HI(pf_addr);
  904. dmae.dst_addr_lo = vf_addr_lo;
  905. dmae.dst_addr_hi = vf_addr_hi;
  906. }
  907. dmae.len = len32;
  908. /* issue the command and wait for completion */
  909. return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  910. }
  911. static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
  912. struct bnx2x_virtf *vf)
  913. {
  914. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  915. u16 length, type;
  916. /* prepare response */
  917. type = mbx->first_tlv.tl.type;
  918. length = type == CHANNEL_TLV_ACQUIRE ?
  919. sizeof(struct pfvf_acquire_resp_tlv) :
  920. sizeof(struct pfvf_general_resp_tlv);
  921. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
  922. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  923. sizeof(struct channel_list_end_tlv));
  924. }
  925. static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
  926. struct bnx2x_virtf *vf,
  927. int vf_rc)
  928. {
  929. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  930. struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
  931. dma_addr_t pf_addr;
  932. u64 vf_addr;
  933. int rc;
  934. bnx2x_dp_tlv_list(bp, resp);
  935. DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
  936. mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
  937. resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
  938. /* send response */
  939. vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
  940. mbx->first_tlv.resp_msg_offset;
  941. pf_addr = mbx->msg_mapping +
  942. offsetof(struct bnx2x_vf_mbx_msg, resp);
  943. /* Copy the response buffer. The first u64 is written afterwards, as
  944. * the vf is sensitive to the header being written
  945. */
  946. vf_addr += sizeof(u64);
  947. pf_addr += sizeof(u64);
  948. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  949. U64_HI(vf_addr),
  950. U64_LO(vf_addr),
  951. (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
  952. if (rc) {
  953. BNX2X_ERR("Failed to copy response body to VF %d\n",
  954. vf->abs_vfid);
  955. goto mbx_error;
  956. }
  957. vf_addr -= sizeof(u64);
  958. pf_addr -= sizeof(u64);
  959. /* ack the FW */
  960. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  961. mmiowb();
  962. /* copy the response header including status-done field,
  963. * must be last dmae, must be after FW is acked
  964. */
  965. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  966. U64_HI(vf_addr),
  967. U64_LO(vf_addr),
  968. sizeof(u64)/4);
  969. /* unlock channel mutex */
  970. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  971. if (rc) {
  972. BNX2X_ERR("Failed to copy response status to VF %d\n",
  973. vf->abs_vfid);
  974. goto mbx_error;
  975. }
  976. return;
  977. mbx_error:
  978. bnx2x_vf_release(bp, vf);
  979. }
  980. static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
  981. struct bnx2x_virtf *vf,
  982. int rc)
  983. {
  984. bnx2x_vf_mbx_resp_single_tlv(bp, vf);
  985. bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
  986. }
  987. static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
  988. struct bnx2x_virtf *vf,
  989. void *buffer,
  990. u16 *offset)
  991. {
  992. struct vfpf_port_phys_id_resp_tlv *port_id;
  993. if (!(bp->flags & HAS_PHYS_PORT_ID))
  994. return;
  995. bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
  996. sizeof(struct vfpf_port_phys_id_resp_tlv));
  997. port_id = (struct vfpf_port_phys_id_resp_tlv *)
  998. (((u8 *)buffer) + *offset);
  999. memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
  1000. /* Offset should continue representing the offset to the tail
  1001. * of TLV data (outside this function scope)
  1002. */
  1003. *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
  1004. }
  1005. static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
  1006. struct bnx2x_virtf *vf,
  1007. void *buffer,
  1008. u16 *offset)
  1009. {
  1010. struct vfpf_fp_hsi_resp_tlv *fp_hsi;
  1011. bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
  1012. sizeof(struct vfpf_fp_hsi_resp_tlv));
  1013. fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
  1014. (((u8 *)buffer) + *offset);
  1015. fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
  1016. /* Offset should continue representing the offset to the tail
  1017. * of TLV data (outside this function scope)
  1018. */
  1019. *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
  1020. }
  1021. static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1022. struct bnx2x_vf_mbx *mbx, int vfop_status)
  1023. {
  1024. int i;
  1025. struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
  1026. struct pf_vf_resc *resc = &resp->resc;
  1027. u8 status = bnx2x_pfvf_status_codes(vfop_status);
  1028. u16 length;
  1029. memset(resp, 0, sizeof(*resp));
  1030. /* fill in pfdev info */
  1031. resp->pfdev_info.chip_num = bp->common.chip_id;
  1032. resp->pfdev_info.db_size = bp->db_size;
  1033. resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
  1034. resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
  1035. PFVF_CAP_TPA |
  1036. PFVF_CAP_TPA_UPDATE |
  1037. PFVF_CAP_VLAN_FILTER);
  1038. bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
  1039. sizeof(resp->pfdev_info.fw_ver));
  1040. if (status == PFVF_STATUS_NO_RESOURCE ||
  1041. status == PFVF_STATUS_SUCCESS) {
  1042. /* set resources numbers, if status equals NO_RESOURCE these
  1043. * are max possible numbers
  1044. */
  1045. resc->num_rxqs = vf_rxq_count(vf) ? :
  1046. bnx2x_vf_max_queue_cnt(bp, vf);
  1047. resc->num_txqs = vf_txq_count(vf) ? :
  1048. bnx2x_vf_max_queue_cnt(bp, vf);
  1049. resc->num_sbs = vf_sb_count(vf);
  1050. resc->num_mac_filters = vf_mac_rules_cnt(vf);
  1051. resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
  1052. resc->num_mc_filters = 0;
  1053. if (status == PFVF_STATUS_SUCCESS) {
  1054. /* fill in the allocated resources */
  1055. struct pf_vf_bulletin_content *bulletin =
  1056. BP_VF_BULLETIN(bp, vf->index);
  1057. for_each_vfq(vf, i)
  1058. resc->hw_qid[i] =
  1059. vfq_qzone_id(vf, vfq_get(vf, i));
  1060. for_each_vf_sb(vf, i) {
  1061. resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
  1062. resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
  1063. }
  1064. /* if a mac has been set for this vf, supply it */
  1065. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1066. memcpy(resc->current_mac_addr, bulletin->mac,
  1067. ETH_ALEN);
  1068. }
  1069. }
  1070. }
  1071. 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"
  1072. "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
  1073. vf->abs_vfid,
  1074. resp->pfdev_info.chip_num,
  1075. resp->pfdev_info.db_size,
  1076. resp->pfdev_info.indices_per_sb,
  1077. resp->pfdev_info.pf_cap,
  1078. resc->num_rxqs,
  1079. resc->num_txqs,
  1080. resc->num_sbs,
  1081. resc->num_mac_filters,
  1082. resc->num_vlan_filters,
  1083. resc->num_mc_filters,
  1084. resp->pfdev_info.fw_ver);
  1085. DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
  1086. for (i = 0; i < vf_rxq_count(vf); i++)
  1087. DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
  1088. DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
  1089. for (i = 0; i < vf_sb_count(vf); i++)
  1090. DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
  1091. resc->hw_sbs[i].hw_sb_id,
  1092. resc->hw_sbs[i].sb_qid);
  1093. DP_CONT(BNX2X_MSG_IOV, "]\n");
  1094. /* prepare response */
  1095. length = sizeof(struct pfvf_acquire_resp_tlv);
  1096. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
  1097. /* Handle possible VF requests for physical port identifiers.
  1098. * 'length' should continue to indicate the offset of the first empty
  1099. * place in the buffer (i.e., where next TLV should be inserted)
  1100. */
  1101. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  1102. CHANNEL_TLV_PHYS_PORT_ID))
  1103. bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
  1104. /* `New' vfs will want to know if fastpath HSI is supported, since
  1105. * if that's not the case they could print into system log the fact
  1106. * the driver version must be updated.
  1107. */
  1108. bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
  1109. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  1110. sizeof(struct channel_list_end_tlv));
  1111. /* send the response */
  1112. bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
  1113. }
  1114. static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
  1115. struct vfpf_acquire_tlv *acquire)
  1116. {
  1117. /* Windows driver does one of three things:
  1118. * 1. Old driver doesn't have bulletin board address set.
  1119. * 2. 'Middle' driver sends mc_num == 32.
  1120. * 3. New driver sets the OS field.
  1121. */
  1122. if (!acquire->bulletin_addr ||
  1123. acquire->resc_request.num_mc_filters == 32 ||
  1124. ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
  1125. VF_OS_WINDOWS))
  1126. return true;
  1127. return false;
  1128. }
  1129. static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
  1130. struct bnx2x_virtf *vf,
  1131. struct bnx2x_vf_mbx *mbx)
  1132. {
  1133. /* Linux drivers which correctly set the doorbell size also
  1134. * send a physical port request
  1135. */
  1136. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  1137. CHANNEL_TLV_PHYS_PORT_ID))
  1138. return 0;
  1139. /* Issue does not exist in windows VMs */
  1140. if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
  1141. return 0;
  1142. return -EOPNOTSUPP;
  1143. }
  1144. static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1145. struct bnx2x_vf_mbx *mbx)
  1146. {
  1147. int rc;
  1148. struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
  1149. /* log vfdef info */
  1150. DP(BNX2X_MSG_IOV,
  1151. "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",
  1152. vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
  1153. acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
  1154. acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
  1155. acquire->resc_request.num_vlan_filters,
  1156. acquire->resc_request.num_mc_filters);
  1157. /* Prevent VFs with old drivers from loading, since they calculate
  1158. * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
  1159. * while being upgraded.
  1160. */
  1161. rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
  1162. if (rc) {
  1163. DP(BNX2X_MSG_IOV,
  1164. "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
  1165. vf->abs_vfid);
  1166. goto out;
  1167. }
  1168. /* Verify the VF fastpath HSI can be supported by the loaded FW.
  1169. * Linux vfs should be oblivious to changes between v0 and v2.
  1170. */
  1171. if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
  1172. vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
  1173. else
  1174. vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
  1175. ETH_FP_HSI_VER_2);
  1176. if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
  1177. DP(BNX2X_MSG_IOV,
  1178. "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
  1179. vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
  1180. ETH_FP_HSI_VERSION);
  1181. rc = -EINVAL;
  1182. goto out;
  1183. }
  1184. /* acquire the resources */
  1185. rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
  1186. /* store address of vf's bulletin board */
  1187. vf->bulletin_map = acquire->bulletin_addr;
  1188. if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
  1189. DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
  1190. vf->abs_vfid);
  1191. vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
  1192. } else {
  1193. vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
  1194. }
  1195. if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_VLAN_FILTER) {
  1196. DP(BNX2X_MSG_IOV, "VF[%d] supports vlan filtering\n",
  1197. vf->abs_vfid);
  1198. vf->cfg_flags |= VF_CFG_VLAN_FILTER;
  1199. } else {
  1200. vf->cfg_flags &= ~VF_CFG_VLAN_FILTER;
  1201. }
  1202. out:
  1203. /* response */
  1204. bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
  1205. }
  1206. static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1207. struct bnx2x_vf_mbx *mbx)
  1208. {
  1209. struct vfpf_init_tlv *init = &mbx->msg->req.init;
  1210. int rc;
  1211. /* record ghost addresses from vf message */
  1212. vf->fw_stat_map = init->stats_addr;
  1213. vf->stats_stride = init->stats_stride;
  1214. rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
  1215. /* set VF multiqueue statistics collection mode */
  1216. if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
  1217. vf->cfg_flags |= VF_CFG_STATS_COALESCE;
  1218. /* Update VF's view of link state */
  1219. if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
  1220. bnx2x_iov_link_update_vf(bp, vf->index);
  1221. /* response */
  1222. bnx2x_vf_mbx_resp(bp, vf, rc);
  1223. }
  1224. /* convert MBX queue-flags to standard SP queue-flags */
  1225. static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
  1226. unsigned long *sp_q_flags)
  1227. {
  1228. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
  1229. __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
  1230. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
  1231. __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
  1232. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
  1233. __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
  1234. if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
  1235. __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
  1236. if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
  1237. __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
  1238. if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
  1239. __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
  1240. if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
  1241. __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
  1242. if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
  1243. __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
  1244. if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
  1245. __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
  1246. /* outer vlan removal is set according to PF's multi function mode */
  1247. if (IS_MF_SD(bp))
  1248. __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
  1249. }
  1250. static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1251. struct bnx2x_vf_mbx *mbx)
  1252. {
  1253. struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
  1254. struct bnx2x_vf_queue_construct_params qctor;
  1255. int rc = 0;
  1256. /* verify vf_qid */
  1257. if (setup_q->vf_qid >= vf_rxq_count(vf)) {
  1258. BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
  1259. setup_q->vf_qid, vf_rxq_count(vf));
  1260. rc = -EINVAL;
  1261. goto response;
  1262. }
  1263. /* tx queues must be setup alongside rx queues thus if the rx queue
  1264. * is not marked as valid there's nothing to do.
  1265. */
  1266. if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
  1267. struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
  1268. unsigned long q_type = 0;
  1269. struct bnx2x_queue_init_params *init_p;
  1270. struct bnx2x_queue_setup_params *setup_p;
  1271. if (bnx2x_vfq_is_leading(q))
  1272. bnx2x_leading_vfq_init(bp, vf, q);
  1273. /* re-init the VF operation context */
  1274. memset(&qctor, 0 ,
  1275. sizeof(struct bnx2x_vf_queue_construct_params));
  1276. setup_p = &qctor.prep_qsetup;
  1277. init_p = &qctor.qstate.params.init;
  1278. /* activate immediately */
  1279. __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
  1280. if (setup_q->param_valid & VFPF_TXQ_VALID) {
  1281. struct bnx2x_txq_setup_params *txq_params =
  1282. &setup_p->txq_params;
  1283. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  1284. /* save sb resource index */
  1285. q->sb_idx = setup_q->txq.vf_sb;
  1286. /* tx init */
  1287. init_p->tx.hc_rate = setup_q->txq.hc_rate;
  1288. init_p->tx.sb_cq_index = setup_q->txq.sb_index;
  1289. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1290. &init_p->tx.flags);
  1291. /* tx setup - flags */
  1292. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1293. &setup_p->flags);
  1294. /* tx setup - general, nothing */
  1295. /* tx setup - tx */
  1296. txq_params->dscr_map = setup_q->txq.txq_addr;
  1297. txq_params->sb_cq_index = setup_q->txq.sb_index;
  1298. txq_params->traffic_type = setup_q->txq.traffic_type;
  1299. bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
  1300. q->index, q->sb_idx);
  1301. }
  1302. if (setup_q->param_valid & VFPF_RXQ_VALID) {
  1303. struct bnx2x_rxq_setup_params *rxq_params =
  1304. &setup_p->rxq_params;
  1305. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  1306. /* Note: there is no support for different SBs
  1307. * for TX and RX
  1308. */
  1309. q->sb_idx = setup_q->rxq.vf_sb;
  1310. /* rx init */
  1311. init_p->rx.hc_rate = setup_q->rxq.hc_rate;
  1312. init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
  1313. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1314. &init_p->rx.flags);
  1315. /* rx setup - flags */
  1316. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1317. &setup_p->flags);
  1318. /* rx setup - general */
  1319. setup_p->gen_params.mtu = setup_q->rxq.mtu;
  1320. /* rx setup - rx */
  1321. rxq_params->drop_flags = setup_q->rxq.drop_flags;
  1322. rxq_params->dscr_map = setup_q->rxq.rxq_addr;
  1323. rxq_params->sge_map = setup_q->rxq.sge_addr;
  1324. rxq_params->rcq_map = setup_q->rxq.rcq_addr;
  1325. rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
  1326. rxq_params->buf_sz = setup_q->rxq.buf_sz;
  1327. rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
  1328. rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
  1329. rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
  1330. rxq_params->cache_line_log =
  1331. setup_q->rxq.cache_line_log;
  1332. rxq_params->sb_cq_index = setup_q->rxq.sb_index;
  1333. /* rx setup - multicast engine */
  1334. if (bnx2x_vfq_is_leading(q)) {
  1335. u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
  1336. rxq_params->mcast_engine_id = mcast_id;
  1337. __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
  1338. }
  1339. bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
  1340. q->index, q->sb_idx);
  1341. }
  1342. /* complete the preparations */
  1343. bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
  1344. rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
  1345. if (rc)
  1346. goto response;
  1347. }
  1348. response:
  1349. bnx2x_vf_mbx_resp(bp, vf, rc);
  1350. }
  1351. static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
  1352. struct bnx2x_virtf *vf,
  1353. struct vfpf_set_q_filters_tlv *tlv,
  1354. struct bnx2x_vf_mac_vlan_filters **pfl,
  1355. u32 type_flag)
  1356. {
  1357. int i, j;
  1358. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1359. size_t fsz;
  1360. fsz = tlv->n_mac_vlan_filters *
  1361. sizeof(struct bnx2x_vf_mac_vlan_filter) +
  1362. sizeof(struct bnx2x_vf_mac_vlan_filters);
  1363. fl = kzalloc(fsz, GFP_KERNEL);
  1364. if (!fl)
  1365. return -ENOMEM;
  1366. for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
  1367. struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
  1368. if ((msg_filter->flags & type_flag) != type_flag)
  1369. continue;
  1370. memset(&fl->filters[j], 0, sizeof(fl->filters[j]));
  1371. if (type_flag & VFPF_Q_FILTER_DEST_MAC_VALID) {
  1372. fl->filters[j].mac = msg_filter->mac;
  1373. fl->filters[j].type |= BNX2X_VF_FILTER_MAC;
  1374. }
  1375. if (type_flag & VFPF_Q_FILTER_VLAN_TAG_VALID) {
  1376. fl->filters[j].vid = msg_filter->vlan_tag;
  1377. fl->filters[j].type |= BNX2X_VF_FILTER_VLAN;
  1378. }
  1379. fl->filters[j].add = !!(msg_filter->flags & VFPF_Q_FILTER_SET);
  1380. fl->count++;
  1381. j++;
  1382. }
  1383. if (!fl->count)
  1384. kfree(fl);
  1385. else
  1386. *pfl = fl;
  1387. return 0;
  1388. }
  1389. static int bnx2x_vf_filters_contain(struct vfpf_set_q_filters_tlv *filters,
  1390. u32 flags)
  1391. {
  1392. int i, cnt = 0;
  1393. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1394. if ((filters->filters[i].flags & flags) == flags)
  1395. cnt++;
  1396. return cnt;
  1397. }
  1398. static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
  1399. struct vfpf_q_mac_vlan_filter *filter)
  1400. {
  1401. DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
  1402. if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
  1403. DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
  1404. if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
  1405. DP_CONT(msglvl, ", MAC=%pM", filter->mac);
  1406. DP_CONT(msglvl, "\n");
  1407. }
  1408. static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
  1409. struct vfpf_set_q_filters_tlv *filters)
  1410. {
  1411. int i;
  1412. if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
  1413. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1414. bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
  1415. &filters->filters[i]);
  1416. if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
  1417. DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
  1418. if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
  1419. for (i = 0; i < filters->n_multicast; i++)
  1420. DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
  1421. }
  1422. #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
  1423. #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
  1424. #define VFPF_VLAN_MAC_FILTER (VFPF_VLAN_FILTER | VFPF_MAC_FILTER)
  1425. static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1426. {
  1427. int rc = 0;
  1428. struct vfpf_set_q_filters_tlv *msg =
  1429. &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
  1430. /* check for any mac/vlan changes */
  1431. if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
  1432. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1433. /* build vlan-mac list */
  1434. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1435. VFPF_VLAN_MAC_FILTER);
  1436. if (rc)
  1437. goto op_err;
  1438. if (fl) {
  1439. /* set vlan-mac list */
  1440. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1441. msg->vf_qid,
  1442. false);
  1443. if (rc)
  1444. goto op_err;
  1445. }
  1446. /* build mac list */
  1447. fl = NULL;
  1448. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1449. VFPF_MAC_FILTER);
  1450. if (rc)
  1451. goto op_err;
  1452. if (fl) {
  1453. /* set mac list */
  1454. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1455. msg->vf_qid,
  1456. false);
  1457. if (rc)
  1458. goto op_err;
  1459. }
  1460. }
  1461. if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
  1462. unsigned long accept = 0;
  1463. struct pf_vf_bulletin_content *bulletin =
  1464. BP_VF_BULLETIN(bp, vf->index);
  1465. /* Ignore VF requested mode; instead set a regular mode */
  1466. if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
  1467. __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
  1468. __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
  1469. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
  1470. }
  1471. /* any_vlan is not configured if HV is forcing VLAN
  1472. * any_vlan is configured if
  1473. * 1. VF does not support vlan filtering
  1474. * OR
  1475. * 2. VF supports vlan filtering and explicitly requested it
  1476. */
  1477. if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)) &&
  1478. (!(vf->cfg_flags & VF_CFG_VLAN_FILTER) ||
  1479. msg->rx_mask & VFPF_RX_MASK_ACCEPT_ANY_VLAN))
  1480. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
  1481. /* set rx-mode */
  1482. rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
  1483. if (rc)
  1484. goto op_err;
  1485. }
  1486. if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
  1487. /* set mcasts */
  1488. rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
  1489. msg->n_multicast, false);
  1490. if (rc)
  1491. goto op_err;
  1492. }
  1493. op_err:
  1494. if (rc)
  1495. BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
  1496. vf->abs_vfid, msg->vf_qid, rc);
  1497. return rc;
  1498. }
  1499. static int bnx2x_filters_validate_mac(struct bnx2x *bp,
  1500. struct bnx2x_virtf *vf,
  1501. struct vfpf_set_q_filters_tlv *filters)
  1502. {
  1503. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1504. int rc = 0;
  1505. /* if a mac was already set for this VF via the set vf mac ndo, we only
  1506. * accept mac configurations of that mac. Why accept them at all?
  1507. * because PF may have been unable to configure the mac at the time
  1508. * since queue was not set up.
  1509. */
  1510. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1511. struct vfpf_q_mac_vlan_filter *filter = NULL;
  1512. int i;
  1513. for (i = 0; i < filters->n_mac_vlan_filters; i++) {
  1514. if (!(filters->filters[i].flags &
  1515. VFPF_Q_FILTER_DEST_MAC_VALID))
  1516. continue;
  1517. /* once a mac was set by ndo can only accept
  1518. * a single mac...
  1519. */
  1520. if (filter) {
  1521. BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called [%d filters]\n",
  1522. vf->abs_vfid,
  1523. filters->n_mac_vlan_filters);
  1524. rc = -EPERM;
  1525. goto response;
  1526. }
  1527. filter = &filters->filters[i];
  1528. }
  1529. /* ...and only the mac set by the ndo */
  1530. if (filter &&
  1531. !ether_addr_equal(filter->mac, bulletin->mac)) {
  1532. BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
  1533. vf->abs_vfid);
  1534. rc = -EPERM;
  1535. goto response;
  1536. }
  1537. }
  1538. response:
  1539. return rc;
  1540. }
  1541. static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
  1542. struct bnx2x_virtf *vf,
  1543. struct vfpf_set_q_filters_tlv *filters)
  1544. {
  1545. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1546. int rc = 0;
  1547. /* if vlan was set by hypervisor we don't allow guest to config vlan */
  1548. if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
  1549. /* search for vlan filters */
  1550. if (bnx2x_vf_filters_contain(filters,
  1551. VFPF_Q_FILTER_VLAN_TAG_VALID)) {
  1552. BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
  1553. vf->abs_vfid);
  1554. rc = -EPERM;
  1555. goto response;
  1556. }
  1557. }
  1558. /* verify vf_qid */
  1559. if (filters->vf_qid > vf_rxq_count(vf)) {
  1560. rc = -EPERM;
  1561. goto response;
  1562. }
  1563. response:
  1564. return rc;
  1565. }
  1566. static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
  1567. struct bnx2x_virtf *vf,
  1568. struct bnx2x_vf_mbx *mbx)
  1569. {
  1570. struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
  1571. int rc;
  1572. rc = bnx2x_filters_validate_mac(bp, vf, filters);
  1573. if (rc)
  1574. goto response;
  1575. rc = bnx2x_filters_validate_vlan(bp, vf, filters);
  1576. if (rc)
  1577. goto response;
  1578. DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
  1579. vf->abs_vfid,
  1580. filters->vf_qid);
  1581. /* print q_filter message */
  1582. bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
  1583. rc = bnx2x_vf_mbx_qfilters(bp, vf);
  1584. response:
  1585. bnx2x_vf_mbx_resp(bp, vf, rc);
  1586. }
  1587. static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1588. struct bnx2x_vf_mbx *mbx)
  1589. {
  1590. int qid = mbx->msg->req.q_op.vf_qid;
  1591. int rc;
  1592. DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
  1593. vf->abs_vfid, qid);
  1594. rc = bnx2x_vf_queue_teardown(bp, vf, qid);
  1595. bnx2x_vf_mbx_resp(bp, vf, rc);
  1596. }
  1597. static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1598. struct bnx2x_vf_mbx *mbx)
  1599. {
  1600. int rc;
  1601. DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
  1602. rc = bnx2x_vf_close(bp, vf);
  1603. bnx2x_vf_mbx_resp(bp, vf, rc);
  1604. }
  1605. static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1606. struct bnx2x_vf_mbx *mbx)
  1607. {
  1608. int rc;
  1609. DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
  1610. rc = bnx2x_vf_free(bp, vf);
  1611. bnx2x_vf_mbx_resp(bp, vf, rc);
  1612. }
  1613. static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1614. struct bnx2x_vf_mbx *mbx)
  1615. {
  1616. struct bnx2x_config_rss_params rss;
  1617. struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
  1618. int rc = 0;
  1619. if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
  1620. rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
  1621. BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
  1622. vf->index);
  1623. rc = -EINVAL;
  1624. goto mbx_resp;
  1625. }
  1626. memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
  1627. /* set vfop params according to rss tlv */
  1628. memcpy(rss.ind_table, rss_tlv->ind_table,
  1629. T_ETH_INDIRECTION_TABLE_SIZE);
  1630. memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
  1631. rss.rss_obj = &vf->rss_conf_obj;
  1632. rss.rss_result_mask = rss_tlv->rss_result_mask;
  1633. /* flags handled individually for backward/forward compatibility */
  1634. rss.rss_flags = 0;
  1635. rss.ramrod_flags = 0;
  1636. if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
  1637. __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
  1638. if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
  1639. __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
  1640. if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
  1641. __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
  1642. if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
  1643. __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
  1644. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
  1645. __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
  1646. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
  1647. __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
  1648. if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
  1649. __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
  1650. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
  1651. __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
  1652. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
  1653. __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
  1654. if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
  1655. rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
  1656. (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
  1657. rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
  1658. BNX2X_ERR("about to hit a FW assert. aborting...\n");
  1659. rc = -EINVAL;
  1660. goto mbx_resp;
  1661. }
  1662. rc = bnx2x_vf_rss_update(bp, vf, &rss);
  1663. mbx_resp:
  1664. bnx2x_vf_mbx_resp(bp, vf, rc);
  1665. }
  1666. static int bnx2x_validate_tpa_params(struct bnx2x *bp,
  1667. struct vfpf_tpa_tlv *tpa_tlv)
  1668. {
  1669. int rc = 0;
  1670. if (tpa_tlv->tpa_client_info.max_sges_for_packet >
  1671. U_ETH_MAX_SGES_FOR_PACKET) {
  1672. rc = -EINVAL;
  1673. BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
  1674. tpa_tlv->tpa_client_info.max_sges_for_packet,
  1675. U_ETH_MAX_SGES_FOR_PACKET);
  1676. }
  1677. if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
  1678. rc = -EINVAL;
  1679. BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
  1680. tpa_tlv->tpa_client_info.max_tpa_queues,
  1681. MAX_AGG_QS(bp));
  1682. }
  1683. return rc;
  1684. }
  1685. static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1686. struct bnx2x_vf_mbx *mbx)
  1687. {
  1688. struct bnx2x_queue_update_tpa_params vf_op_params;
  1689. struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
  1690. int rc = 0;
  1691. memset(&vf_op_params, 0, sizeof(vf_op_params));
  1692. if (bnx2x_validate_tpa_params(bp, tpa_tlv))
  1693. goto mbx_resp;
  1694. vf_op_params.complete_on_both_clients =
  1695. tpa_tlv->tpa_client_info.complete_on_both_clients;
  1696. vf_op_params.dont_verify_thr =
  1697. tpa_tlv->tpa_client_info.dont_verify_thr;
  1698. vf_op_params.max_agg_sz =
  1699. tpa_tlv->tpa_client_info.max_agg_size;
  1700. vf_op_params.max_sges_pkt =
  1701. tpa_tlv->tpa_client_info.max_sges_for_packet;
  1702. vf_op_params.max_tpa_queues =
  1703. tpa_tlv->tpa_client_info.max_tpa_queues;
  1704. vf_op_params.sge_buff_sz =
  1705. tpa_tlv->tpa_client_info.sge_buff_size;
  1706. vf_op_params.sge_pause_thr_high =
  1707. tpa_tlv->tpa_client_info.sge_pause_thr_high;
  1708. vf_op_params.sge_pause_thr_low =
  1709. tpa_tlv->tpa_client_info.sge_pause_thr_low;
  1710. vf_op_params.tpa_mode =
  1711. tpa_tlv->tpa_client_info.tpa_mode;
  1712. vf_op_params.update_ipv4 =
  1713. tpa_tlv->tpa_client_info.update_ipv4;
  1714. vf_op_params.update_ipv6 =
  1715. tpa_tlv->tpa_client_info.update_ipv6;
  1716. rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
  1717. mbx_resp:
  1718. bnx2x_vf_mbx_resp(bp, vf, rc);
  1719. }
  1720. /* dispatch request */
  1721. static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1722. struct bnx2x_vf_mbx *mbx)
  1723. {
  1724. int i;
  1725. /* check if tlv type is known */
  1726. if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
  1727. /* Lock the per vf op mutex and note the locker's identity.
  1728. * The unlock will take place in mbx response.
  1729. */
  1730. bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1731. /* switch on the opcode */
  1732. switch (mbx->first_tlv.tl.type) {
  1733. case CHANNEL_TLV_ACQUIRE:
  1734. bnx2x_vf_mbx_acquire(bp, vf, mbx);
  1735. return;
  1736. case CHANNEL_TLV_INIT:
  1737. bnx2x_vf_mbx_init_vf(bp, vf, mbx);
  1738. return;
  1739. case CHANNEL_TLV_SETUP_Q:
  1740. bnx2x_vf_mbx_setup_q(bp, vf, mbx);
  1741. return;
  1742. case CHANNEL_TLV_SET_Q_FILTERS:
  1743. bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
  1744. return;
  1745. case CHANNEL_TLV_TEARDOWN_Q:
  1746. bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
  1747. return;
  1748. case CHANNEL_TLV_CLOSE:
  1749. bnx2x_vf_mbx_close_vf(bp, vf, mbx);
  1750. return;
  1751. case CHANNEL_TLV_RELEASE:
  1752. bnx2x_vf_mbx_release_vf(bp, vf, mbx);
  1753. return;
  1754. case CHANNEL_TLV_UPDATE_RSS:
  1755. bnx2x_vf_mbx_update_rss(bp, vf, mbx);
  1756. return;
  1757. case CHANNEL_TLV_UPDATE_TPA:
  1758. bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
  1759. return;
  1760. }
  1761. } else {
  1762. /* unknown TLV - this may belong to a VF driver from the future
  1763. * - a version written after this PF driver was written, which
  1764. * supports features unknown as of yet. Too bad since we don't
  1765. * support them. Or this may be because someone wrote a crappy
  1766. * VF driver and is sending garbage over the channel.
  1767. */
  1768. BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
  1769. mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
  1770. vf->state);
  1771. for (i = 0; i < 20; i++)
  1772. DP_CONT(BNX2X_MSG_IOV, "%x ",
  1773. mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
  1774. }
  1775. /* can we respond to VF (do we have an address for it?) */
  1776. if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
  1777. /* notify the VF that we do not support this request */
  1778. bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
  1779. } else {
  1780. /* can't send a response since this VF is unknown to us
  1781. * just ack the FW to release the mailbox and unlock
  1782. * the channel.
  1783. */
  1784. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  1785. /* Firmware ack should be written before unlocking channel */
  1786. mmiowb();
  1787. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1788. }
  1789. }
  1790. void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
  1791. struct vf_pf_event_data *vfpf_event)
  1792. {
  1793. u8 vf_idx;
  1794. DP(BNX2X_MSG_IOV,
  1795. "vf pf event received: vfid %d, address_hi %x, address lo %x",
  1796. vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
  1797. /* Sanity checks consider removing later */
  1798. /* check if the vf_id is valid */
  1799. if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
  1800. BNX2X_NR_VIRTFN(bp)) {
  1801. BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
  1802. vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
  1803. return;
  1804. }
  1805. vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
  1806. /* Update VFDB with current message and schedule its handling */
  1807. mutex_lock(&BP_VFDB(bp)->event_mutex);
  1808. BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
  1809. le32_to_cpu(vfpf_event->msg_addr_hi);
  1810. BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
  1811. le32_to_cpu(vfpf_event->msg_addr_lo);
  1812. BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
  1813. mutex_unlock(&BP_VFDB(bp)->event_mutex);
  1814. bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
  1815. }
  1816. /* handle new vf-pf messages */
  1817. void bnx2x_vf_mbx(struct bnx2x *bp)
  1818. {
  1819. struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
  1820. u64 events;
  1821. u8 vf_idx;
  1822. int rc;
  1823. if (!vfdb)
  1824. return;
  1825. mutex_lock(&vfdb->event_mutex);
  1826. events = vfdb->event_occur;
  1827. vfdb->event_occur = 0;
  1828. mutex_unlock(&vfdb->event_mutex);
  1829. for_each_vf(bp, vf_idx) {
  1830. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
  1831. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  1832. /* Handle VFs which have pending events */
  1833. if (!(events & (1ULL << vf_idx)))
  1834. continue;
  1835. DP(BNX2X_MSG_IOV,
  1836. "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
  1837. vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
  1838. mbx->first_tlv.resp_msg_offset);
  1839. /* dmae to get the VF request */
  1840. rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
  1841. vf->abs_vfid, mbx->vf_addr_hi,
  1842. mbx->vf_addr_lo,
  1843. sizeof(union vfpf_tlvs)/4);
  1844. if (rc) {
  1845. BNX2X_ERR("Failed to copy request VF %d\n",
  1846. vf->abs_vfid);
  1847. bnx2x_vf_release(bp, vf);
  1848. return;
  1849. }
  1850. /* process the VF message header */
  1851. mbx->first_tlv = mbx->msg->req.first_tlv;
  1852. /* Clean response buffer to refrain from falsely
  1853. * seeing chains.
  1854. */
  1855. memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
  1856. /* dispatch the request (will prepare the response) */
  1857. bnx2x_vf_mbx_request(bp, vf, mbx);
  1858. }
  1859. }
  1860. void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
  1861. bool support_long)
  1862. {
  1863. /* Older VFs contain a bug where they can't check CRC for bulletin
  1864. * boards of length greater than legacy size.
  1865. */
  1866. bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
  1867. BULLETIN_CONTENT_LEGACY_SIZE;
  1868. bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
  1869. }
  1870. /* propagate local bulletin board to vf */
  1871. int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
  1872. {
  1873. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
  1874. dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
  1875. vf * BULLETIN_CONTENT_SIZE;
  1876. dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
  1877. int rc;
  1878. /* can only update vf after init took place */
  1879. if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
  1880. bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
  1881. return 0;
  1882. /* increment bulletin board version and compute crc */
  1883. bulletin->version++;
  1884. bnx2x_vf_bulletin_finalize(bulletin,
  1885. (bnx2x_vf(bp, vf, cfg_flags) &
  1886. VF_CFG_EXT_BULLETIN) ? true : false);
  1887. /* propagate bulletin board via dmae to vm memory */
  1888. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
  1889. bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
  1890. U64_LO(vf_addr), bulletin->length / 4);
  1891. return rc;
  1892. }