bnx2x_vfpf.c 59 KB

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