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, 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. netdev_for_each_mc_addr(ha, dev) {
  725. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  726. bnx2x_mc_addr(ha));
  727. memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
  728. i++;
  729. }
  730. /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
  731. * addresses tops
  732. */
  733. if (i >= PFVF_MAX_MULTICAST_PER_VF) {
  734. DP(NETIF_MSG_IFUP,
  735. "VF supports not more than %d multicast MAC addresses\n",
  736. PFVF_MAX_MULTICAST_PER_VF);
  737. return -EINVAL;
  738. }
  739. req->n_multicast = i;
  740. req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
  741. req->vf_qid = 0;
  742. /* add list termination tlv */
  743. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  744. sizeof(struct channel_list_end_tlv));
  745. /* output tlvs list */
  746. bnx2x_dp_tlv_list(bp, req);
  747. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  748. if (rc) {
  749. BNX2X_ERR("Sending a message failed: %d\n", rc);
  750. goto out;
  751. }
  752. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  753. BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
  754. resp->hdr.status);
  755. rc = -EINVAL;
  756. }
  757. out:
  758. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  759. return 0;
  760. }
  761. /* request pf to add a vlan for the vf */
  762. int bnx2x_vfpf_update_vlan(struct bnx2x *bp, u16 vid, u8 vf_qid, bool add)
  763. {
  764. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  765. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  766. int rc = 0;
  767. if (!(bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER)) {
  768. DP(BNX2X_MSG_IOV, "HV does not support vlan filtering\n");
  769. return 0;
  770. }
  771. /* clear mailbox and prep first tlv */
  772. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  773. sizeof(*req));
  774. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  775. req->vf_qid = vf_qid;
  776. req->n_mac_vlan_filters = 1;
  777. req->filters[0].flags = VFPF_Q_FILTER_VLAN_TAG_VALID;
  778. if (add)
  779. req->filters[0].flags |= VFPF_Q_FILTER_SET;
  780. /* sample bulletin board for hypervisor vlan */
  781. bnx2x_sample_bulletin(bp);
  782. if (bp->shadow_bulletin.content.valid_bitmap & 1 << VLAN_VALID) {
  783. BNX2X_ERR("Hypervisor will dicline the request, avoiding\n");
  784. rc = -EINVAL;
  785. goto out;
  786. }
  787. req->filters[0].vlan_tag = vid;
  788. /* add list termination tlv */
  789. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  790. sizeof(struct channel_list_end_tlv));
  791. /* output tlvs list */
  792. bnx2x_dp_tlv_list(bp, req);
  793. /* send message to pf */
  794. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  795. if (rc) {
  796. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  797. goto out;
  798. }
  799. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  800. BNX2X_ERR("vfpf %s VLAN %d failed\n", add ? "add" : "del",
  801. vid);
  802. rc = -EINVAL;
  803. }
  804. out:
  805. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  806. return rc;
  807. }
  808. int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
  809. {
  810. int mode = bp->rx_mode;
  811. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  812. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  813. int rc;
  814. /* clear mailbox and prep first tlv */
  815. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  816. sizeof(*req));
  817. DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
  818. /* Ignore everything accept MODE_NONE */
  819. if (mode == BNX2X_RX_MODE_NONE) {
  820. req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
  821. } else {
  822. /* Current PF driver will not look at the specific flags,
  823. * but they are required when working with older drivers on hv.
  824. */
  825. req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
  826. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  827. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  828. if (mode == BNX2X_RX_MODE_PROMISC)
  829. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
  830. }
  831. if (bp->accept_any_vlan)
  832. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
  833. req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
  834. req->vf_qid = 0;
  835. /* add list termination tlv */
  836. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  837. sizeof(struct channel_list_end_tlv));
  838. /* output tlvs list */
  839. bnx2x_dp_tlv_list(bp, req);
  840. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  841. if (rc)
  842. BNX2X_ERR("Sending a message failed: %d\n", rc);
  843. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  844. BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
  845. rc = -EINVAL;
  846. }
  847. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  848. return rc;
  849. }
  850. /* General service functions */
  851. static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
  852. {
  853. u32 addr = BAR_CSTRORM_INTMEM +
  854. CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
  855. REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
  856. }
  857. static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
  858. {
  859. u32 addr = BAR_CSTRORM_INTMEM +
  860. CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
  861. REG_WR8(bp, addr, 1);
  862. }
  863. /* enable vf_pf mailbox (aka vf-pf-channel) */
  864. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
  865. {
  866. bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
  867. /* enable the mailbox in the FW */
  868. storm_memset_vf_mbx_ack(bp, abs_vfid);
  869. storm_memset_vf_mbx_valid(bp, abs_vfid);
  870. /* enable the VF access to the mailbox */
  871. bnx2x_vf_enable_access(bp, abs_vfid);
  872. }
  873. /* this works only on !E1h */
  874. static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
  875. dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
  876. u32 vf_addr_lo, u32 len32)
  877. {
  878. struct dmae_command dmae;
  879. if (CHIP_IS_E1x(bp)) {
  880. BNX2X_ERR("Chip revision does not support VFs\n");
  881. return DMAE_NOT_RDY;
  882. }
  883. if (!bp->dmae_ready) {
  884. BNX2X_ERR("DMAE is not ready, can not copy\n");
  885. return DMAE_NOT_RDY;
  886. }
  887. /* set opcode and fixed command fields */
  888. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
  889. if (from_vf) {
  890. dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
  891. (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
  892. (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
  893. dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
  894. dmae.src_addr_lo = vf_addr_lo;
  895. dmae.src_addr_hi = vf_addr_hi;
  896. dmae.dst_addr_lo = U64_LO(pf_addr);
  897. dmae.dst_addr_hi = U64_HI(pf_addr);
  898. } else {
  899. dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
  900. (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
  901. (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
  902. dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
  903. dmae.src_addr_lo = U64_LO(pf_addr);
  904. dmae.src_addr_hi = U64_HI(pf_addr);
  905. dmae.dst_addr_lo = vf_addr_lo;
  906. dmae.dst_addr_hi = vf_addr_hi;
  907. }
  908. dmae.len = len32;
  909. /* issue the command and wait for completion */
  910. return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  911. }
  912. static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
  913. struct bnx2x_virtf *vf)
  914. {
  915. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  916. u16 length, type;
  917. /* prepare response */
  918. type = mbx->first_tlv.tl.type;
  919. length = type == CHANNEL_TLV_ACQUIRE ?
  920. sizeof(struct pfvf_acquire_resp_tlv) :
  921. sizeof(struct pfvf_general_resp_tlv);
  922. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
  923. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  924. sizeof(struct channel_list_end_tlv));
  925. }
  926. static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
  927. struct bnx2x_virtf *vf,
  928. int vf_rc)
  929. {
  930. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  931. struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
  932. dma_addr_t pf_addr;
  933. u64 vf_addr;
  934. int rc;
  935. bnx2x_dp_tlv_list(bp, resp);
  936. DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
  937. mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
  938. resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
  939. /* send response */
  940. vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
  941. mbx->first_tlv.resp_msg_offset;
  942. pf_addr = mbx->msg_mapping +
  943. offsetof(struct bnx2x_vf_mbx_msg, resp);
  944. /* Copy the response buffer. The first u64 is written afterwards, as
  945. * the vf is sensitive to the header being written
  946. */
  947. vf_addr += sizeof(u64);
  948. pf_addr += sizeof(u64);
  949. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  950. U64_HI(vf_addr),
  951. U64_LO(vf_addr),
  952. (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
  953. if (rc) {
  954. BNX2X_ERR("Failed to copy response body to VF %d\n",
  955. vf->abs_vfid);
  956. goto mbx_error;
  957. }
  958. vf_addr -= sizeof(u64);
  959. pf_addr -= sizeof(u64);
  960. /* ack the FW */
  961. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  962. mmiowb();
  963. /* copy the response header including status-done field,
  964. * must be last dmae, must be after FW is acked
  965. */
  966. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  967. U64_HI(vf_addr),
  968. U64_LO(vf_addr),
  969. sizeof(u64)/4);
  970. /* unlock channel mutex */
  971. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  972. if (rc) {
  973. BNX2X_ERR("Failed to copy response status to VF %d\n",
  974. vf->abs_vfid);
  975. goto mbx_error;
  976. }
  977. return;
  978. mbx_error:
  979. bnx2x_vf_release(bp, vf);
  980. }
  981. static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
  982. struct bnx2x_virtf *vf,
  983. int rc)
  984. {
  985. bnx2x_vf_mbx_resp_single_tlv(bp, vf);
  986. bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
  987. }
  988. static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
  989. struct bnx2x_virtf *vf,
  990. void *buffer,
  991. u16 *offset)
  992. {
  993. struct vfpf_port_phys_id_resp_tlv *port_id;
  994. if (!(bp->flags & HAS_PHYS_PORT_ID))
  995. return;
  996. bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
  997. sizeof(struct vfpf_port_phys_id_resp_tlv));
  998. port_id = (struct vfpf_port_phys_id_resp_tlv *)
  999. (((u8 *)buffer) + *offset);
  1000. memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
  1001. /* Offset should continue representing the offset to the tail
  1002. * of TLV data (outside this function scope)
  1003. */
  1004. *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
  1005. }
  1006. static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
  1007. struct bnx2x_virtf *vf,
  1008. void *buffer,
  1009. u16 *offset)
  1010. {
  1011. struct vfpf_fp_hsi_resp_tlv *fp_hsi;
  1012. bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
  1013. sizeof(struct vfpf_fp_hsi_resp_tlv));
  1014. fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
  1015. (((u8 *)buffer) + *offset);
  1016. fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
  1017. /* Offset should continue representing the offset to the tail
  1018. * of TLV data (outside this function scope)
  1019. */
  1020. *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
  1021. }
  1022. static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1023. struct bnx2x_vf_mbx *mbx, int vfop_status)
  1024. {
  1025. int i;
  1026. struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
  1027. struct pf_vf_resc *resc = &resp->resc;
  1028. u8 status = bnx2x_pfvf_status_codes(vfop_status);
  1029. u16 length;
  1030. memset(resp, 0, sizeof(*resp));
  1031. /* fill in pfdev info */
  1032. resp->pfdev_info.chip_num = bp->common.chip_id;
  1033. resp->pfdev_info.db_size = bp->db_size;
  1034. resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
  1035. resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
  1036. PFVF_CAP_TPA |
  1037. PFVF_CAP_TPA_UPDATE |
  1038. PFVF_CAP_VLAN_FILTER);
  1039. bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
  1040. sizeof(resp->pfdev_info.fw_ver));
  1041. if (status == PFVF_STATUS_NO_RESOURCE ||
  1042. status == PFVF_STATUS_SUCCESS) {
  1043. /* set resources numbers, if status equals NO_RESOURCE these
  1044. * are max possible numbers
  1045. */
  1046. resc->num_rxqs = vf_rxq_count(vf) ? :
  1047. bnx2x_vf_max_queue_cnt(bp, vf);
  1048. resc->num_txqs = vf_txq_count(vf) ? :
  1049. bnx2x_vf_max_queue_cnt(bp, vf);
  1050. resc->num_sbs = vf_sb_count(vf);
  1051. resc->num_mac_filters = vf_mac_rules_cnt(vf);
  1052. resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
  1053. resc->num_mc_filters = 0;
  1054. if (status == PFVF_STATUS_SUCCESS) {
  1055. /* fill in the allocated resources */
  1056. struct pf_vf_bulletin_content *bulletin =
  1057. BP_VF_BULLETIN(bp, vf->index);
  1058. for_each_vfq(vf, i)
  1059. resc->hw_qid[i] =
  1060. vfq_qzone_id(vf, vfq_get(vf, i));
  1061. for_each_vf_sb(vf, i) {
  1062. resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
  1063. resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
  1064. }
  1065. /* if a mac has been set for this vf, supply it */
  1066. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1067. memcpy(resc->current_mac_addr, bulletin->mac,
  1068. ETH_ALEN);
  1069. }
  1070. }
  1071. }
  1072. 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"
  1073. "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
  1074. vf->abs_vfid,
  1075. resp->pfdev_info.chip_num,
  1076. resp->pfdev_info.db_size,
  1077. resp->pfdev_info.indices_per_sb,
  1078. resp->pfdev_info.pf_cap,
  1079. resc->num_rxqs,
  1080. resc->num_txqs,
  1081. resc->num_sbs,
  1082. resc->num_mac_filters,
  1083. resc->num_vlan_filters,
  1084. resc->num_mc_filters,
  1085. resp->pfdev_info.fw_ver);
  1086. DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
  1087. for (i = 0; i < vf_rxq_count(vf); i++)
  1088. DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
  1089. DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
  1090. for (i = 0; i < vf_sb_count(vf); i++)
  1091. DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
  1092. resc->hw_sbs[i].hw_sb_id,
  1093. resc->hw_sbs[i].sb_qid);
  1094. DP_CONT(BNX2X_MSG_IOV, "]\n");
  1095. /* prepare response */
  1096. length = sizeof(struct pfvf_acquire_resp_tlv);
  1097. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
  1098. /* Handle possible VF requests for physical port identifiers.
  1099. * 'length' should continue to indicate the offset of the first empty
  1100. * place in the buffer (i.e., where next TLV should be inserted)
  1101. */
  1102. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  1103. CHANNEL_TLV_PHYS_PORT_ID))
  1104. bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
  1105. /* `New' vfs will want to know if fastpath HSI is supported, since
  1106. * if that's not the case they could print into system log the fact
  1107. * the driver version must be updated.
  1108. */
  1109. bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
  1110. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  1111. sizeof(struct channel_list_end_tlv));
  1112. /* send the response */
  1113. bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
  1114. }
  1115. static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
  1116. struct vfpf_acquire_tlv *acquire)
  1117. {
  1118. /* Windows driver does one of three things:
  1119. * 1. Old driver doesn't have bulletin board address set.
  1120. * 2. 'Middle' driver sends mc_num == 32.
  1121. * 3. New driver sets the OS field.
  1122. */
  1123. if (!acquire->bulletin_addr ||
  1124. acquire->resc_request.num_mc_filters == 32 ||
  1125. ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
  1126. VF_OS_WINDOWS))
  1127. return true;
  1128. return false;
  1129. }
  1130. static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
  1131. struct bnx2x_virtf *vf,
  1132. struct bnx2x_vf_mbx *mbx)
  1133. {
  1134. /* Linux drivers which correctly set the doorbell size also
  1135. * send a physical port request
  1136. */
  1137. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  1138. CHANNEL_TLV_PHYS_PORT_ID))
  1139. return 0;
  1140. /* Issue does not exist in windows VMs */
  1141. if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
  1142. return 0;
  1143. return -EOPNOTSUPP;
  1144. }
  1145. static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1146. struct bnx2x_vf_mbx *mbx)
  1147. {
  1148. int rc;
  1149. struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
  1150. /* log vfdef info */
  1151. DP(BNX2X_MSG_IOV,
  1152. "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",
  1153. vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
  1154. acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
  1155. acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
  1156. acquire->resc_request.num_vlan_filters,
  1157. acquire->resc_request.num_mc_filters);
  1158. /* Prevent VFs with old drivers from loading, since they calculate
  1159. * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
  1160. * while being upgraded.
  1161. */
  1162. rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
  1163. if (rc) {
  1164. DP(BNX2X_MSG_IOV,
  1165. "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
  1166. vf->abs_vfid);
  1167. goto out;
  1168. }
  1169. /* Verify the VF fastpath HSI can be supported by the loaded FW.
  1170. * Linux vfs should be oblivious to changes between v0 and v2.
  1171. */
  1172. if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
  1173. vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
  1174. else
  1175. vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
  1176. ETH_FP_HSI_VER_2);
  1177. if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
  1178. DP(BNX2X_MSG_IOV,
  1179. "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
  1180. vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
  1181. ETH_FP_HSI_VERSION);
  1182. rc = -EINVAL;
  1183. goto out;
  1184. }
  1185. /* acquire the resources */
  1186. rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
  1187. /* store address of vf's bulletin board */
  1188. vf->bulletin_map = acquire->bulletin_addr;
  1189. if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
  1190. DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
  1191. vf->abs_vfid);
  1192. vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
  1193. } else {
  1194. vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
  1195. }
  1196. if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_VLAN_FILTER) {
  1197. DP(BNX2X_MSG_IOV, "VF[%d] supports vlan filtering\n",
  1198. vf->abs_vfid);
  1199. vf->cfg_flags |= VF_CFG_VLAN_FILTER;
  1200. } else {
  1201. vf->cfg_flags &= ~VF_CFG_VLAN_FILTER;
  1202. }
  1203. out:
  1204. /* response */
  1205. bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
  1206. }
  1207. static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1208. struct bnx2x_vf_mbx *mbx)
  1209. {
  1210. struct vfpf_init_tlv *init = &mbx->msg->req.init;
  1211. int rc;
  1212. /* record ghost addresses from vf message */
  1213. vf->fw_stat_map = init->stats_addr;
  1214. vf->stats_stride = init->stats_stride;
  1215. rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
  1216. /* set VF multiqueue statistics collection mode */
  1217. if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
  1218. vf->cfg_flags |= VF_CFG_STATS_COALESCE;
  1219. /* Update VF's view of link state */
  1220. if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
  1221. bnx2x_iov_link_update_vf(bp, vf->index);
  1222. /* response */
  1223. bnx2x_vf_mbx_resp(bp, vf, rc);
  1224. }
  1225. /* convert MBX queue-flags to standard SP queue-flags */
  1226. static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
  1227. unsigned long *sp_q_flags)
  1228. {
  1229. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
  1230. __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
  1231. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
  1232. __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
  1233. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
  1234. __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
  1235. if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
  1236. __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
  1237. if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
  1238. __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
  1239. if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
  1240. __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
  1241. if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
  1242. __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
  1243. if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
  1244. __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
  1245. if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
  1246. __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
  1247. /* outer vlan removal is set according to PF's multi function mode */
  1248. if (IS_MF_SD(bp))
  1249. __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
  1250. }
  1251. static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1252. struct bnx2x_vf_mbx *mbx)
  1253. {
  1254. struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
  1255. struct bnx2x_vf_queue_construct_params qctor;
  1256. int rc = 0;
  1257. /* verify vf_qid */
  1258. if (setup_q->vf_qid >= vf_rxq_count(vf)) {
  1259. BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
  1260. setup_q->vf_qid, vf_rxq_count(vf));
  1261. rc = -EINVAL;
  1262. goto response;
  1263. }
  1264. /* tx queues must be setup alongside rx queues thus if the rx queue
  1265. * is not marked as valid there's nothing to do.
  1266. */
  1267. if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
  1268. struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
  1269. unsigned long q_type = 0;
  1270. struct bnx2x_queue_init_params *init_p;
  1271. struct bnx2x_queue_setup_params *setup_p;
  1272. if (bnx2x_vfq_is_leading(q))
  1273. bnx2x_leading_vfq_init(bp, vf, q);
  1274. /* re-init the VF operation context */
  1275. memset(&qctor, 0 ,
  1276. sizeof(struct bnx2x_vf_queue_construct_params));
  1277. setup_p = &qctor.prep_qsetup;
  1278. init_p = &qctor.qstate.params.init;
  1279. /* activate immediately */
  1280. __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
  1281. if (setup_q->param_valid & VFPF_TXQ_VALID) {
  1282. struct bnx2x_txq_setup_params *txq_params =
  1283. &setup_p->txq_params;
  1284. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  1285. /* save sb resource index */
  1286. q->sb_idx = setup_q->txq.vf_sb;
  1287. /* tx init */
  1288. init_p->tx.hc_rate = setup_q->txq.hc_rate;
  1289. init_p->tx.sb_cq_index = setup_q->txq.sb_index;
  1290. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1291. &init_p->tx.flags);
  1292. /* tx setup - flags */
  1293. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1294. &setup_p->flags);
  1295. /* tx setup - general, nothing */
  1296. /* tx setup - tx */
  1297. txq_params->dscr_map = setup_q->txq.txq_addr;
  1298. txq_params->sb_cq_index = setup_q->txq.sb_index;
  1299. txq_params->traffic_type = setup_q->txq.traffic_type;
  1300. bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
  1301. q->index, q->sb_idx);
  1302. }
  1303. if (setup_q->param_valid & VFPF_RXQ_VALID) {
  1304. struct bnx2x_rxq_setup_params *rxq_params =
  1305. &setup_p->rxq_params;
  1306. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  1307. /* Note: there is no support for different SBs
  1308. * for TX and RX
  1309. */
  1310. q->sb_idx = setup_q->rxq.vf_sb;
  1311. /* rx init */
  1312. init_p->rx.hc_rate = setup_q->rxq.hc_rate;
  1313. init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
  1314. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1315. &init_p->rx.flags);
  1316. /* rx setup - flags */
  1317. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1318. &setup_p->flags);
  1319. /* rx setup - general */
  1320. setup_p->gen_params.mtu = setup_q->rxq.mtu;
  1321. /* rx setup - rx */
  1322. rxq_params->drop_flags = setup_q->rxq.drop_flags;
  1323. rxq_params->dscr_map = setup_q->rxq.rxq_addr;
  1324. rxq_params->sge_map = setup_q->rxq.sge_addr;
  1325. rxq_params->rcq_map = setup_q->rxq.rcq_addr;
  1326. rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
  1327. rxq_params->buf_sz = setup_q->rxq.buf_sz;
  1328. rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
  1329. rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
  1330. rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
  1331. rxq_params->cache_line_log =
  1332. setup_q->rxq.cache_line_log;
  1333. rxq_params->sb_cq_index = setup_q->rxq.sb_index;
  1334. /* rx setup - multicast engine */
  1335. if (bnx2x_vfq_is_leading(q)) {
  1336. u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
  1337. rxq_params->mcast_engine_id = mcast_id;
  1338. __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
  1339. }
  1340. bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
  1341. q->index, q->sb_idx);
  1342. }
  1343. /* complete the preparations */
  1344. bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
  1345. rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
  1346. if (rc)
  1347. goto response;
  1348. }
  1349. response:
  1350. bnx2x_vf_mbx_resp(bp, vf, rc);
  1351. }
  1352. static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
  1353. struct bnx2x_virtf *vf,
  1354. struct vfpf_set_q_filters_tlv *tlv,
  1355. struct bnx2x_vf_mac_vlan_filters **pfl,
  1356. u32 type_flag)
  1357. {
  1358. int i, j;
  1359. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1360. size_t fsz;
  1361. fsz = tlv->n_mac_vlan_filters *
  1362. sizeof(struct bnx2x_vf_mac_vlan_filter) +
  1363. sizeof(struct bnx2x_vf_mac_vlan_filters);
  1364. fl = kzalloc(fsz, GFP_KERNEL);
  1365. if (!fl)
  1366. return -ENOMEM;
  1367. for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
  1368. struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
  1369. if ((msg_filter->flags & type_flag) != type_flag)
  1370. continue;
  1371. memset(&fl->filters[j], 0, sizeof(fl->filters[j]));
  1372. if (type_flag & VFPF_Q_FILTER_DEST_MAC_VALID) {
  1373. fl->filters[j].mac = msg_filter->mac;
  1374. fl->filters[j].type |= BNX2X_VF_FILTER_MAC;
  1375. }
  1376. if (type_flag & VFPF_Q_FILTER_VLAN_TAG_VALID) {
  1377. fl->filters[j].vid = msg_filter->vlan_tag;
  1378. fl->filters[j].type |= BNX2X_VF_FILTER_VLAN;
  1379. }
  1380. fl->filters[j].add = !!(msg_filter->flags & VFPF_Q_FILTER_SET);
  1381. fl->count++;
  1382. j++;
  1383. }
  1384. if (!fl->count)
  1385. kfree(fl);
  1386. else
  1387. *pfl = fl;
  1388. return 0;
  1389. }
  1390. static int bnx2x_vf_filters_contain(struct vfpf_set_q_filters_tlv *filters,
  1391. u32 flags)
  1392. {
  1393. int i, cnt = 0;
  1394. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1395. if ((filters->filters[i].flags & flags) == flags)
  1396. cnt++;
  1397. return cnt;
  1398. }
  1399. static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
  1400. struct vfpf_q_mac_vlan_filter *filter)
  1401. {
  1402. DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
  1403. if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
  1404. DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
  1405. if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
  1406. DP_CONT(msglvl, ", MAC=%pM", filter->mac);
  1407. DP_CONT(msglvl, "\n");
  1408. }
  1409. static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
  1410. struct vfpf_set_q_filters_tlv *filters)
  1411. {
  1412. int i;
  1413. if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
  1414. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1415. bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
  1416. &filters->filters[i]);
  1417. if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
  1418. DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
  1419. if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
  1420. for (i = 0; i < filters->n_multicast; i++)
  1421. DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
  1422. }
  1423. #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
  1424. #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
  1425. #define VFPF_VLAN_MAC_FILTER (VFPF_VLAN_FILTER | VFPF_MAC_FILTER)
  1426. static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1427. {
  1428. int rc = 0;
  1429. struct vfpf_set_q_filters_tlv *msg =
  1430. &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
  1431. /* check for any mac/vlan changes */
  1432. if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
  1433. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1434. /* build vlan-mac list */
  1435. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1436. VFPF_VLAN_MAC_FILTER);
  1437. if (rc)
  1438. goto op_err;
  1439. if (fl) {
  1440. /* set vlan-mac list */
  1441. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1442. msg->vf_qid,
  1443. false);
  1444. if (rc)
  1445. goto op_err;
  1446. }
  1447. /* build mac list */
  1448. fl = NULL;
  1449. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1450. VFPF_MAC_FILTER);
  1451. if (rc)
  1452. goto op_err;
  1453. if (fl) {
  1454. /* set mac list */
  1455. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1456. msg->vf_qid,
  1457. false);
  1458. if (rc)
  1459. goto op_err;
  1460. }
  1461. }
  1462. if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
  1463. unsigned long accept = 0;
  1464. struct pf_vf_bulletin_content *bulletin =
  1465. BP_VF_BULLETIN(bp, vf->index);
  1466. /* Ignore VF requested mode; instead set a regular mode */
  1467. if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
  1468. __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
  1469. __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
  1470. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
  1471. }
  1472. /* any_vlan is not configured if HV is forcing VLAN
  1473. * any_vlan is configured if
  1474. * 1. VF does not support vlan filtering
  1475. * OR
  1476. * 2. VF supports vlan filtering and explicitly requested it
  1477. */
  1478. if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)) &&
  1479. (!(vf->cfg_flags & VF_CFG_VLAN_FILTER) ||
  1480. msg->rx_mask & VFPF_RX_MASK_ACCEPT_ANY_VLAN))
  1481. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
  1482. /* set rx-mode */
  1483. rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
  1484. if (rc)
  1485. goto op_err;
  1486. }
  1487. if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
  1488. /* set mcasts */
  1489. rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
  1490. msg->n_multicast, false);
  1491. if (rc)
  1492. goto op_err;
  1493. }
  1494. op_err:
  1495. if (rc)
  1496. BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
  1497. vf->abs_vfid, msg->vf_qid, rc);
  1498. return rc;
  1499. }
  1500. static int bnx2x_filters_validate_mac(struct bnx2x *bp,
  1501. struct bnx2x_virtf *vf,
  1502. struct vfpf_set_q_filters_tlv *filters)
  1503. {
  1504. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1505. int rc = 0;
  1506. /* if a mac was already set for this VF via the set vf mac ndo, we only
  1507. * accept mac configurations of that mac. Why accept them at all?
  1508. * because PF may have been unable to configure the mac at the time
  1509. * since queue was not set up.
  1510. */
  1511. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1512. struct vfpf_q_mac_vlan_filter *filter = NULL;
  1513. int i;
  1514. for (i = 0; i < filters->n_mac_vlan_filters; i++) {
  1515. if (!(filters->filters[i].flags &
  1516. VFPF_Q_FILTER_DEST_MAC_VALID))
  1517. continue;
  1518. /* once a mac was set by ndo can only accept
  1519. * a single mac...
  1520. */
  1521. if (filter) {
  1522. BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called [%d filters]\n",
  1523. vf->abs_vfid,
  1524. filters->n_mac_vlan_filters);
  1525. rc = -EPERM;
  1526. goto response;
  1527. }
  1528. filter = &filters->filters[i];
  1529. }
  1530. /* ...and only the mac set by the ndo */
  1531. if (filter &&
  1532. !ether_addr_equal(filter->mac, bulletin->mac)) {
  1533. BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
  1534. vf->abs_vfid);
  1535. rc = -EPERM;
  1536. goto response;
  1537. }
  1538. }
  1539. response:
  1540. return rc;
  1541. }
  1542. static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
  1543. struct bnx2x_virtf *vf,
  1544. struct vfpf_set_q_filters_tlv *filters)
  1545. {
  1546. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1547. int rc = 0;
  1548. /* if vlan was set by hypervisor we don't allow guest to config vlan */
  1549. if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
  1550. /* search for vlan filters */
  1551. if (bnx2x_vf_filters_contain(filters,
  1552. VFPF_Q_FILTER_VLAN_TAG_VALID)) {
  1553. BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
  1554. vf->abs_vfid);
  1555. rc = -EPERM;
  1556. goto response;
  1557. }
  1558. }
  1559. /* verify vf_qid */
  1560. if (filters->vf_qid > vf_rxq_count(vf)) {
  1561. rc = -EPERM;
  1562. goto response;
  1563. }
  1564. response:
  1565. return rc;
  1566. }
  1567. static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
  1568. struct bnx2x_virtf *vf,
  1569. struct bnx2x_vf_mbx *mbx)
  1570. {
  1571. struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
  1572. int rc;
  1573. rc = bnx2x_filters_validate_mac(bp, vf, filters);
  1574. if (rc)
  1575. goto response;
  1576. rc = bnx2x_filters_validate_vlan(bp, vf, filters);
  1577. if (rc)
  1578. goto response;
  1579. DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
  1580. vf->abs_vfid,
  1581. filters->vf_qid);
  1582. /* print q_filter message */
  1583. bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
  1584. rc = bnx2x_vf_mbx_qfilters(bp, vf);
  1585. response:
  1586. bnx2x_vf_mbx_resp(bp, vf, rc);
  1587. }
  1588. static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1589. struct bnx2x_vf_mbx *mbx)
  1590. {
  1591. int qid = mbx->msg->req.q_op.vf_qid;
  1592. int rc;
  1593. DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
  1594. vf->abs_vfid, qid);
  1595. rc = bnx2x_vf_queue_teardown(bp, vf, qid);
  1596. bnx2x_vf_mbx_resp(bp, vf, rc);
  1597. }
  1598. static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1599. struct bnx2x_vf_mbx *mbx)
  1600. {
  1601. int rc;
  1602. DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
  1603. rc = bnx2x_vf_close(bp, vf);
  1604. bnx2x_vf_mbx_resp(bp, vf, rc);
  1605. }
  1606. static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1607. struct bnx2x_vf_mbx *mbx)
  1608. {
  1609. int rc;
  1610. DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
  1611. rc = bnx2x_vf_free(bp, vf);
  1612. bnx2x_vf_mbx_resp(bp, vf, rc);
  1613. }
  1614. static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1615. struct bnx2x_vf_mbx *mbx)
  1616. {
  1617. struct bnx2x_config_rss_params rss;
  1618. struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
  1619. int rc = 0;
  1620. if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
  1621. rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
  1622. BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
  1623. vf->index);
  1624. rc = -EINVAL;
  1625. goto mbx_resp;
  1626. }
  1627. memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
  1628. /* set vfop params according to rss tlv */
  1629. memcpy(rss.ind_table, rss_tlv->ind_table,
  1630. T_ETH_INDIRECTION_TABLE_SIZE);
  1631. memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
  1632. rss.rss_obj = &vf->rss_conf_obj;
  1633. rss.rss_result_mask = rss_tlv->rss_result_mask;
  1634. /* flags handled individually for backward/forward compatibility */
  1635. rss.rss_flags = 0;
  1636. rss.ramrod_flags = 0;
  1637. if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
  1638. __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
  1639. if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
  1640. __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
  1641. if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
  1642. __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
  1643. if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
  1644. __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
  1645. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
  1646. __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
  1647. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
  1648. __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
  1649. if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
  1650. __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
  1651. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
  1652. __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
  1653. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
  1654. __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
  1655. if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
  1656. rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
  1657. (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
  1658. rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
  1659. BNX2X_ERR("about to hit a FW assert. aborting...\n");
  1660. rc = -EINVAL;
  1661. goto mbx_resp;
  1662. }
  1663. rc = bnx2x_vf_rss_update(bp, vf, &rss);
  1664. mbx_resp:
  1665. bnx2x_vf_mbx_resp(bp, vf, rc);
  1666. }
  1667. static int bnx2x_validate_tpa_params(struct bnx2x *bp,
  1668. struct vfpf_tpa_tlv *tpa_tlv)
  1669. {
  1670. int rc = 0;
  1671. if (tpa_tlv->tpa_client_info.max_sges_for_packet >
  1672. U_ETH_MAX_SGES_FOR_PACKET) {
  1673. rc = -EINVAL;
  1674. BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
  1675. tpa_tlv->tpa_client_info.max_sges_for_packet,
  1676. U_ETH_MAX_SGES_FOR_PACKET);
  1677. }
  1678. if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
  1679. rc = -EINVAL;
  1680. BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
  1681. tpa_tlv->tpa_client_info.max_tpa_queues,
  1682. MAX_AGG_QS(bp));
  1683. }
  1684. return rc;
  1685. }
  1686. static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1687. struct bnx2x_vf_mbx *mbx)
  1688. {
  1689. struct bnx2x_queue_update_tpa_params vf_op_params;
  1690. struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
  1691. int rc = 0;
  1692. memset(&vf_op_params, 0, sizeof(vf_op_params));
  1693. if (bnx2x_validate_tpa_params(bp, tpa_tlv))
  1694. goto mbx_resp;
  1695. vf_op_params.complete_on_both_clients =
  1696. tpa_tlv->tpa_client_info.complete_on_both_clients;
  1697. vf_op_params.dont_verify_thr =
  1698. tpa_tlv->tpa_client_info.dont_verify_thr;
  1699. vf_op_params.max_agg_sz =
  1700. tpa_tlv->tpa_client_info.max_agg_size;
  1701. vf_op_params.max_sges_pkt =
  1702. tpa_tlv->tpa_client_info.max_sges_for_packet;
  1703. vf_op_params.max_tpa_queues =
  1704. tpa_tlv->tpa_client_info.max_tpa_queues;
  1705. vf_op_params.sge_buff_sz =
  1706. tpa_tlv->tpa_client_info.sge_buff_size;
  1707. vf_op_params.sge_pause_thr_high =
  1708. tpa_tlv->tpa_client_info.sge_pause_thr_high;
  1709. vf_op_params.sge_pause_thr_low =
  1710. tpa_tlv->tpa_client_info.sge_pause_thr_low;
  1711. vf_op_params.tpa_mode =
  1712. tpa_tlv->tpa_client_info.tpa_mode;
  1713. vf_op_params.update_ipv4 =
  1714. tpa_tlv->tpa_client_info.update_ipv4;
  1715. vf_op_params.update_ipv6 =
  1716. tpa_tlv->tpa_client_info.update_ipv6;
  1717. rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
  1718. mbx_resp:
  1719. bnx2x_vf_mbx_resp(bp, vf, rc);
  1720. }
  1721. /* dispatch request */
  1722. static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1723. struct bnx2x_vf_mbx *mbx)
  1724. {
  1725. int i;
  1726. /* check if tlv type is known */
  1727. if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
  1728. /* Lock the per vf op mutex and note the locker's identity.
  1729. * The unlock will take place in mbx response.
  1730. */
  1731. bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1732. /* switch on the opcode */
  1733. switch (mbx->first_tlv.tl.type) {
  1734. case CHANNEL_TLV_ACQUIRE:
  1735. bnx2x_vf_mbx_acquire(bp, vf, mbx);
  1736. return;
  1737. case CHANNEL_TLV_INIT:
  1738. bnx2x_vf_mbx_init_vf(bp, vf, mbx);
  1739. return;
  1740. case CHANNEL_TLV_SETUP_Q:
  1741. bnx2x_vf_mbx_setup_q(bp, vf, mbx);
  1742. return;
  1743. case CHANNEL_TLV_SET_Q_FILTERS:
  1744. bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
  1745. return;
  1746. case CHANNEL_TLV_TEARDOWN_Q:
  1747. bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
  1748. return;
  1749. case CHANNEL_TLV_CLOSE:
  1750. bnx2x_vf_mbx_close_vf(bp, vf, mbx);
  1751. return;
  1752. case CHANNEL_TLV_RELEASE:
  1753. bnx2x_vf_mbx_release_vf(bp, vf, mbx);
  1754. return;
  1755. case CHANNEL_TLV_UPDATE_RSS:
  1756. bnx2x_vf_mbx_update_rss(bp, vf, mbx);
  1757. return;
  1758. case CHANNEL_TLV_UPDATE_TPA:
  1759. bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
  1760. return;
  1761. }
  1762. } else {
  1763. /* unknown TLV - this may belong to a VF driver from the future
  1764. * - a version written after this PF driver was written, which
  1765. * supports features unknown as of yet. Too bad since we don't
  1766. * support them. Or this may be because someone wrote a crappy
  1767. * VF driver and is sending garbage over the channel.
  1768. */
  1769. BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
  1770. mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
  1771. vf->state);
  1772. for (i = 0; i < 20; i++)
  1773. DP_CONT(BNX2X_MSG_IOV, "%x ",
  1774. mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
  1775. }
  1776. /* can we respond to VF (do we have an address for it?) */
  1777. if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
  1778. /* notify the VF that we do not support this request */
  1779. bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
  1780. } else {
  1781. /* can't send a response since this VF is unknown to us
  1782. * just ack the FW to release the mailbox and unlock
  1783. * the channel.
  1784. */
  1785. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  1786. /* Firmware ack should be written before unlocking channel */
  1787. mmiowb();
  1788. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1789. }
  1790. }
  1791. void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
  1792. struct vf_pf_event_data *vfpf_event)
  1793. {
  1794. u8 vf_idx;
  1795. DP(BNX2X_MSG_IOV,
  1796. "vf pf event received: vfid %d, address_hi %x, address lo %x",
  1797. vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
  1798. /* Sanity checks consider removing later */
  1799. /* check if the vf_id is valid */
  1800. if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
  1801. BNX2X_NR_VIRTFN(bp)) {
  1802. BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
  1803. vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
  1804. return;
  1805. }
  1806. vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
  1807. /* Update VFDB with current message and schedule its handling */
  1808. mutex_lock(&BP_VFDB(bp)->event_mutex);
  1809. BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
  1810. le32_to_cpu(vfpf_event->msg_addr_hi);
  1811. BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
  1812. le32_to_cpu(vfpf_event->msg_addr_lo);
  1813. BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
  1814. mutex_unlock(&BP_VFDB(bp)->event_mutex);
  1815. bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
  1816. }
  1817. /* handle new vf-pf messages */
  1818. void bnx2x_vf_mbx(struct bnx2x *bp)
  1819. {
  1820. struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
  1821. u64 events;
  1822. u8 vf_idx;
  1823. int rc;
  1824. if (!vfdb)
  1825. return;
  1826. mutex_lock(&vfdb->event_mutex);
  1827. events = vfdb->event_occur;
  1828. vfdb->event_occur = 0;
  1829. mutex_unlock(&vfdb->event_mutex);
  1830. for_each_vf(bp, vf_idx) {
  1831. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
  1832. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  1833. /* Handle VFs which have pending events */
  1834. if (!(events & (1ULL << vf_idx)))
  1835. continue;
  1836. DP(BNX2X_MSG_IOV,
  1837. "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
  1838. vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
  1839. mbx->first_tlv.resp_msg_offset);
  1840. /* dmae to get the VF request */
  1841. rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
  1842. vf->abs_vfid, mbx->vf_addr_hi,
  1843. mbx->vf_addr_lo,
  1844. sizeof(union vfpf_tlvs)/4);
  1845. if (rc) {
  1846. BNX2X_ERR("Failed to copy request VF %d\n",
  1847. vf->abs_vfid);
  1848. bnx2x_vf_release(bp, vf);
  1849. return;
  1850. }
  1851. /* process the VF message header */
  1852. mbx->first_tlv = mbx->msg->req.first_tlv;
  1853. /* Clean response buffer to refrain from falsely
  1854. * seeing chains.
  1855. */
  1856. memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
  1857. /* dispatch the request (will prepare the response) */
  1858. bnx2x_vf_mbx_request(bp, vf, mbx);
  1859. }
  1860. }
  1861. void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
  1862. bool support_long)
  1863. {
  1864. /* Older VFs contain a bug where they can't check CRC for bulletin
  1865. * boards of length greater than legacy size.
  1866. */
  1867. bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
  1868. BULLETIN_CONTENT_LEGACY_SIZE;
  1869. bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
  1870. }
  1871. /* propagate local bulletin board to vf */
  1872. int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
  1873. {
  1874. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
  1875. dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
  1876. vf * BULLETIN_CONTENT_SIZE;
  1877. dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
  1878. int rc;
  1879. /* can only update vf after init took place */
  1880. if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
  1881. bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
  1882. return 0;
  1883. /* increment bulletin board version and compute crc */
  1884. bulletin->version++;
  1885. bnx2x_vf_bulletin_finalize(bulletin,
  1886. (bnx2x_vf(bp, vf, cfg_flags) &
  1887. VF_CFG_EXT_BULLETIN) ? true : false);
  1888. /* propagate bulletin board via dmae to vm memory */
  1889. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
  1890. bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
  1891. U64_LO(vf_addr), bulletin->length / 4);
  1892. return rc;
  1893. }