bnx2x_vfpf.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  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. /* Common */
  477. req->vf_qid = fp_idx;
  478. req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
  479. /* Rx */
  480. req->rxq.rcq_addr = fp->rx_comp_mapping;
  481. req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  482. req->rxq.rxq_addr = fp->rx_desc_mapping;
  483. req->rxq.sge_addr = fp->rx_sge_mapping;
  484. req->rxq.vf_sb = fp_idx;
  485. req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
  486. req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
  487. req->rxq.mtu = bp->dev->mtu;
  488. req->rxq.buf_sz = fp->rx_buf_size;
  489. req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
  490. req->rxq.tpa_agg_sz = tpa_agg_size;
  491. req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
  492. req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
  493. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  494. req->rxq.flags = flags;
  495. req->rxq.drop_flags = 0;
  496. req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  497. req->rxq.stat_id = -1; /* No stats at the moment */
  498. /* Tx */
  499. req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
  500. req->txq.vf_sb = fp_idx;
  501. req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
  502. req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
  503. req->txq.flags = flags;
  504. req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
  505. /* add list termination tlv */
  506. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  507. sizeof(struct channel_list_end_tlv));
  508. /* output tlvs list */
  509. bnx2x_dp_tlv_list(bp, req);
  510. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  511. if (rc)
  512. BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
  513. fp_idx);
  514. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  515. BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
  516. fp_idx, resp->hdr.status);
  517. rc = -EINVAL;
  518. }
  519. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  520. return rc;
  521. }
  522. static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
  523. {
  524. struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
  525. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  526. int rc;
  527. /* clear mailbox and prep first tlv */
  528. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
  529. sizeof(*req));
  530. req->vf_qid = qidx;
  531. /* add list termination tlv */
  532. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  533. sizeof(struct channel_list_end_tlv));
  534. /* output tlvs list */
  535. bnx2x_dp_tlv_list(bp, req);
  536. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  537. if (rc) {
  538. BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
  539. rc);
  540. goto out;
  541. }
  542. /* PF failed the transaction */
  543. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  544. BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
  545. resp->hdr.status);
  546. rc = -EINVAL;
  547. }
  548. out:
  549. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  550. return rc;
  551. }
  552. /* request pf to add a mac for the vf */
  553. int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
  554. {
  555. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  556. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  557. struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
  558. int rc = 0;
  559. /* clear mailbox and prep first tlv */
  560. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  561. sizeof(*req));
  562. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  563. req->vf_qid = vf_qid;
  564. req->n_mac_vlan_filters = 1;
  565. req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
  566. if (set)
  567. req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
  568. /* sample bulletin board for new mac */
  569. bnx2x_sample_bulletin(bp);
  570. /* copy mac from device to request */
  571. memcpy(req->filters[0].mac, addr, ETH_ALEN);
  572. /* add list termination tlv */
  573. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  574. sizeof(struct channel_list_end_tlv));
  575. /* output tlvs list */
  576. bnx2x_dp_tlv_list(bp, req);
  577. /* send message to pf */
  578. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  579. if (rc) {
  580. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  581. goto out;
  582. }
  583. /* failure may mean PF was configured with a new mac for us */
  584. while (resp->hdr.status == PFVF_STATUS_FAILURE) {
  585. DP(BNX2X_MSG_IOV,
  586. "vfpf SET MAC failed. Check bulletin board for new posts\n");
  587. /* copy mac from bulletin to device */
  588. memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
  589. /* check if bulletin board was updated */
  590. if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
  591. /* copy mac from device to request */
  592. memcpy(req->filters[0].mac, bp->dev->dev_addr,
  593. ETH_ALEN);
  594. /* send message to pf */
  595. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
  596. bp->vf2pf_mbox_mapping);
  597. } else {
  598. /* no new info in bulletin */
  599. break;
  600. }
  601. }
  602. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  603. BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
  604. rc = -EINVAL;
  605. }
  606. out:
  607. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  608. return rc;
  609. }
  610. /* request pf to config rss table for vf queues*/
  611. int bnx2x_vfpf_config_rss(struct bnx2x *bp,
  612. struct bnx2x_config_rss_params *params)
  613. {
  614. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  615. struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
  616. int rc = 0;
  617. /* clear mailbox and prep first tlv */
  618. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
  619. sizeof(*req));
  620. /* add list termination tlv */
  621. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  622. sizeof(struct channel_list_end_tlv));
  623. memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
  624. memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
  625. req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
  626. req->rss_key_size = T_ETH_RSS_KEY;
  627. req->rss_result_mask = params->rss_result_mask;
  628. /* flags handled individually for backward/forward compatability */
  629. if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
  630. req->rss_flags |= VFPF_RSS_MODE_DISABLED;
  631. if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
  632. req->rss_flags |= VFPF_RSS_MODE_REGULAR;
  633. if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
  634. req->rss_flags |= VFPF_RSS_SET_SRCH;
  635. if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
  636. req->rss_flags |= VFPF_RSS_IPV4;
  637. if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
  638. req->rss_flags |= VFPF_RSS_IPV4_TCP;
  639. if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
  640. req->rss_flags |= VFPF_RSS_IPV4_UDP;
  641. if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
  642. req->rss_flags |= VFPF_RSS_IPV6;
  643. if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
  644. req->rss_flags |= VFPF_RSS_IPV6_TCP;
  645. if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
  646. req->rss_flags |= VFPF_RSS_IPV6_UDP;
  647. DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
  648. /* output tlvs list */
  649. bnx2x_dp_tlv_list(bp, req);
  650. /* send message to pf */
  651. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  652. if (rc) {
  653. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  654. goto out;
  655. }
  656. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  657. /* Since older drivers don't support this feature (and VF has
  658. * no way of knowing other than failing this), don't propagate
  659. * an error in this case.
  660. */
  661. DP(BNX2X_MSG_IOV,
  662. "Failed to send rss message to PF over VF-PF channel [%d]\n",
  663. resp->hdr.status);
  664. }
  665. out:
  666. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  667. return rc;
  668. }
  669. int bnx2x_vfpf_set_mcast(struct net_device *dev)
  670. {
  671. struct bnx2x *bp = netdev_priv(dev);
  672. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  673. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  674. int rc, i = 0;
  675. struct netdev_hw_addr *ha;
  676. if (bp->state != BNX2X_STATE_OPEN) {
  677. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  678. return -EINVAL;
  679. }
  680. /* clear mailbox and prep first tlv */
  681. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  682. sizeof(*req));
  683. /* Get Rx mode requested */
  684. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  685. netdev_for_each_mc_addr(ha, dev) {
  686. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  687. bnx2x_mc_addr(ha));
  688. memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
  689. i++;
  690. }
  691. /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
  692. * addresses tops
  693. */
  694. if (i >= PFVF_MAX_MULTICAST_PER_VF) {
  695. DP(NETIF_MSG_IFUP,
  696. "VF supports not more than %d multicast MAC addresses\n",
  697. PFVF_MAX_MULTICAST_PER_VF);
  698. return -EINVAL;
  699. }
  700. req->n_multicast = i;
  701. req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
  702. req->vf_qid = 0;
  703. /* add list termination tlv */
  704. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  705. sizeof(struct channel_list_end_tlv));
  706. /* output tlvs list */
  707. bnx2x_dp_tlv_list(bp, req);
  708. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  709. if (rc) {
  710. BNX2X_ERR("Sending a message failed: %d\n", rc);
  711. goto out;
  712. }
  713. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  714. BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
  715. resp->hdr.status);
  716. rc = -EINVAL;
  717. }
  718. out:
  719. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  720. return 0;
  721. }
  722. int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
  723. {
  724. int mode = bp->rx_mode;
  725. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  726. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  727. int rc;
  728. /* clear mailbox and prep first tlv */
  729. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  730. sizeof(*req));
  731. DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
  732. /* Ignore everything accept MODE_NONE */
  733. if (mode == BNX2X_RX_MODE_NONE) {
  734. req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
  735. } else {
  736. /* Current PF driver will not look at the specific flags,
  737. * but they are required when working with older drivers on hv.
  738. */
  739. req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
  740. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  741. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  742. }
  743. req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
  744. req->vf_qid = 0;
  745. /* add list termination tlv */
  746. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  747. sizeof(struct channel_list_end_tlv));
  748. /* output tlvs list */
  749. bnx2x_dp_tlv_list(bp, req);
  750. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  751. if (rc)
  752. BNX2X_ERR("Sending a message failed: %d\n", rc);
  753. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  754. BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
  755. rc = -EINVAL;
  756. }
  757. bnx2x_vfpf_finalize(bp, &req->first_tlv);
  758. return rc;
  759. }
  760. /* General service functions */
  761. static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
  762. {
  763. u32 addr = BAR_CSTRORM_INTMEM +
  764. CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
  765. REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
  766. }
  767. static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
  768. {
  769. u32 addr = BAR_CSTRORM_INTMEM +
  770. CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
  771. REG_WR8(bp, addr, 1);
  772. }
  773. /* enable vf_pf mailbox (aka vf-pf-channel) */
  774. void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
  775. {
  776. bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
  777. /* enable the mailbox in the FW */
  778. storm_memset_vf_mbx_ack(bp, abs_vfid);
  779. storm_memset_vf_mbx_valid(bp, abs_vfid);
  780. /* enable the VF access to the mailbox */
  781. bnx2x_vf_enable_access(bp, abs_vfid);
  782. }
  783. /* this works only on !E1h */
  784. static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
  785. dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
  786. u32 vf_addr_lo, u32 len32)
  787. {
  788. struct dmae_command dmae;
  789. if (CHIP_IS_E1x(bp)) {
  790. BNX2X_ERR("Chip revision does not support VFs\n");
  791. return DMAE_NOT_RDY;
  792. }
  793. if (!bp->dmae_ready) {
  794. BNX2X_ERR("DMAE is not ready, can not copy\n");
  795. return DMAE_NOT_RDY;
  796. }
  797. /* set opcode and fixed command fields */
  798. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
  799. if (from_vf) {
  800. dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
  801. (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
  802. (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
  803. dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
  804. dmae.src_addr_lo = vf_addr_lo;
  805. dmae.src_addr_hi = vf_addr_hi;
  806. dmae.dst_addr_lo = U64_LO(pf_addr);
  807. dmae.dst_addr_hi = U64_HI(pf_addr);
  808. } else {
  809. dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
  810. (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
  811. (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
  812. dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
  813. dmae.src_addr_lo = U64_LO(pf_addr);
  814. dmae.src_addr_hi = U64_HI(pf_addr);
  815. dmae.dst_addr_lo = vf_addr_lo;
  816. dmae.dst_addr_hi = vf_addr_hi;
  817. }
  818. dmae.len = len32;
  819. /* issue the command and wait for completion */
  820. return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  821. }
  822. static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
  823. struct bnx2x_virtf *vf)
  824. {
  825. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  826. u16 length, type;
  827. /* prepare response */
  828. type = mbx->first_tlv.tl.type;
  829. length = type == CHANNEL_TLV_ACQUIRE ?
  830. sizeof(struct pfvf_acquire_resp_tlv) :
  831. sizeof(struct pfvf_general_resp_tlv);
  832. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
  833. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  834. sizeof(struct channel_list_end_tlv));
  835. }
  836. static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
  837. struct bnx2x_virtf *vf,
  838. int vf_rc)
  839. {
  840. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
  841. struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
  842. dma_addr_t pf_addr;
  843. u64 vf_addr;
  844. int rc;
  845. bnx2x_dp_tlv_list(bp, resp);
  846. DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
  847. mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
  848. resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
  849. /* send response */
  850. vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
  851. mbx->first_tlv.resp_msg_offset;
  852. pf_addr = mbx->msg_mapping +
  853. offsetof(struct bnx2x_vf_mbx_msg, resp);
  854. /* Copy the response buffer. The first u64 is written afterwards, as
  855. * the vf is sensitive to the header being written
  856. */
  857. vf_addr += sizeof(u64);
  858. pf_addr += sizeof(u64);
  859. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  860. U64_HI(vf_addr),
  861. U64_LO(vf_addr),
  862. (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
  863. if (rc) {
  864. BNX2X_ERR("Failed to copy response body to VF %d\n",
  865. vf->abs_vfid);
  866. goto mbx_error;
  867. }
  868. vf_addr -= sizeof(u64);
  869. pf_addr -= sizeof(u64);
  870. /* ack the FW */
  871. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  872. mmiowb();
  873. /* copy the response header including status-done field,
  874. * must be last dmae, must be after FW is acked
  875. */
  876. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
  877. U64_HI(vf_addr),
  878. U64_LO(vf_addr),
  879. sizeof(u64)/4);
  880. /* unlock channel mutex */
  881. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  882. if (rc) {
  883. BNX2X_ERR("Failed to copy response status to VF %d\n",
  884. vf->abs_vfid);
  885. goto mbx_error;
  886. }
  887. return;
  888. mbx_error:
  889. bnx2x_vf_release(bp, vf);
  890. }
  891. static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
  892. struct bnx2x_virtf *vf,
  893. int rc)
  894. {
  895. bnx2x_vf_mbx_resp_single_tlv(bp, vf);
  896. bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
  897. }
  898. static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
  899. struct bnx2x_virtf *vf,
  900. void *buffer,
  901. u16 *offset)
  902. {
  903. struct vfpf_port_phys_id_resp_tlv *port_id;
  904. if (!(bp->flags & HAS_PHYS_PORT_ID))
  905. return;
  906. bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
  907. sizeof(struct vfpf_port_phys_id_resp_tlv));
  908. port_id = (struct vfpf_port_phys_id_resp_tlv *)
  909. (((u8 *)buffer) + *offset);
  910. memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
  911. /* Offset should continue representing the offset to the tail
  912. * of TLV data (outside this function scope)
  913. */
  914. *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
  915. }
  916. static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
  917. struct bnx2x_vf_mbx *mbx, int vfop_status)
  918. {
  919. int i;
  920. struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
  921. struct pf_vf_resc *resc = &resp->resc;
  922. u8 status = bnx2x_pfvf_status_codes(vfop_status);
  923. u16 length;
  924. memset(resp, 0, sizeof(*resp));
  925. /* fill in pfdev info */
  926. resp->pfdev_info.chip_num = bp->common.chip_id;
  927. resp->pfdev_info.db_size = bp->db_size;
  928. resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
  929. resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
  930. PFVF_CAP_TPA |
  931. PFVF_CAP_TPA_UPDATE);
  932. bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
  933. sizeof(resp->pfdev_info.fw_ver));
  934. if (status == PFVF_STATUS_NO_RESOURCE ||
  935. status == PFVF_STATUS_SUCCESS) {
  936. /* set resources numbers, if status equals NO_RESOURCE these
  937. * are max possible numbers
  938. */
  939. resc->num_rxqs = vf_rxq_count(vf) ? :
  940. bnx2x_vf_max_queue_cnt(bp, vf);
  941. resc->num_txqs = vf_txq_count(vf) ? :
  942. bnx2x_vf_max_queue_cnt(bp, vf);
  943. resc->num_sbs = vf_sb_count(vf);
  944. resc->num_mac_filters = vf_mac_rules_cnt(vf);
  945. resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
  946. resc->num_mc_filters = 0;
  947. if (status == PFVF_STATUS_SUCCESS) {
  948. /* fill in the allocated resources */
  949. struct pf_vf_bulletin_content *bulletin =
  950. BP_VF_BULLETIN(bp, vf->index);
  951. for_each_vfq(vf, i)
  952. resc->hw_qid[i] =
  953. vfq_qzone_id(vf, vfq_get(vf, i));
  954. for_each_vf_sb(vf, i) {
  955. resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
  956. resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
  957. }
  958. /* if a mac has been set for this vf, supply it */
  959. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  960. memcpy(resc->current_mac_addr, bulletin->mac,
  961. ETH_ALEN);
  962. }
  963. }
  964. }
  965. 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"
  966. "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
  967. vf->abs_vfid,
  968. resp->pfdev_info.chip_num,
  969. resp->pfdev_info.db_size,
  970. resp->pfdev_info.indices_per_sb,
  971. resp->pfdev_info.pf_cap,
  972. resc->num_rxqs,
  973. resc->num_txqs,
  974. resc->num_sbs,
  975. resc->num_mac_filters,
  976. resc->num_vlan_filters,
  977. resc->num_mc_filters,
  978. resp->pfdev_info.fw_ver);
  979. DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
  980. for (i = 0; i < vf_rxq_count(vf); i++)
  981. DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
  982. DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
  983. for (i = 0; i < vf_sb_count(vf); i++)
  984. DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
  985. resc->hw_sbs[i].hw_sb_id,
  986. resc->hw_sbs[i].sb_qid);
  987. DP_CONT(BNX2X_MSG_IOV, "]\n");
  988. /* prepare response */
  989. length = sizeof(struct pfvf_acquire_resp_tlv);
  990. bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
  991. /* Handle possible VF requests for physical port identifiers.
  992. * 'length' should continue to indicate the offset of the first empty
  993. * place in the buffer (i.e., where next TLV should be inserted)
  994. */
  995. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  996. CHANNEL_TLV_PHYS_PORT_ID))
  997. bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
  998. bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
  999. sizeof(struct channel_list_end_tlv));
  1000. /* send the response */
  1001. bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
  1002. }
  1003. static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
  1004. struct vfpf_acquire_tlv *acquire)
  1005. {
  1006. /* Windows driver does one of three things:
  1007. * 1. Old driver doesn't have bulletin board address set.
  1008. * 2. 'Middle' driver sends mc_num == 32.
  1009. * 3. New driver sets the OS field.
  1010. */
  1011. if (!acquire->bulletin_addr ||
  1012. acquire->resc_request.num_mc_filters == 32 ||
  1013. ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
  1014. VF_OS_WINDOWS))
  1015. return true;
  1016. return false;
  1017. }
  1018. static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
  1019. struct bnx2x_virtf *vf,
  1020. struct bnx2x_vf_mbx *mbx)
  1021. {
  1022. /* Linux drivers which correctly set the doorbell size also
  1023. * send a physical port request
  1024. */
  1025. if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
  1026. CHANNEL_TLV_PHYS_PORT_ID))
  1027. return 0;
  1028. /* Issue does not exist in windows VMs */
  1029. if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
  1030. return 0;
  1031. return -EOPNOTSUPP;
  1032. }
  1033. static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1034. struct bnx2x_vf_mbx *mbx)
  1035. {
  1036. int rc;
  1037. struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
  1038. /* log vfdef info */
  1039. DP(BNX2X_MSG_IOV,
  1040. "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",
  1041. vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
  1042. acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
  1043. acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
  1044. acquire->resc_request.num_vlan_filters,
  1045. acquire->resc_request.num_mc_filters);
  1046. /* Prevent VFs with old drivers from loading, since they calculate
  1047. * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
  1048. * while being upgraded.
  1049. */
  1050. rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
  1051. if (rc) {
  1052. DP(BNX2X_MSG_IOV,
  1053. "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
  1054. vf->abs_vfid);
  1055. goto out;
  1056. }
  1057. /* acquire the resources */
  1058. rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
  1059. /* store address of vf's bulletin board */
  1060. vf->bulletin_map = acquire->bulletin_addr;
  1061. if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
  1062. DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
  1063. vf->abs_vfid);
  1064. vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
  1065. } else {
  1066. vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
  1067. }
  1068. out:
  1069. /* response */
  1070. bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
  1071. }
  1072. static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1073. struct bnx2x_vf_mbx *mbx)
  1074. {
  1075. struct vfpf_init_tlv *init = &mbx->msg->req.init;
  1076. int rc;
  1077. /* record ghost addresses from vf message */
  1078. vf->spq_map = init->spq_addr;
  1079. vf->fw_stat_map = init->stats_addr;
  1080. vf->stats_stride = init->stats_stride;
  1081. rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
  1082. /* set VF multiqueue statistics collection mode */
  1083. if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
  1084. vf->cfg_flags |= VF_CFG_STATS_COALESCE;
  1085. /* Update VF's view of link state */
  1086. if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
  1087. bnx2x_iov_link_update_vf(bp, vf->index);
  1088. /* response */
  1089. bnx2x_vf_mbx_resp(bp, vf, rc);
  1090. }
  1091. /* convert MBX queue-flags to standard SP queue-flags */
  1092. static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
  1093. unsigned long *sp_q_flags)
  1094. {
  1095. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
  1096. __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
  1097. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
  1098. __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
  1099. if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
  1100. __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
  1101. if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
  1102. __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
  1103. if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
  1104. __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
  1105. if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
  1106. __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
  1107. if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
  1108. __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
  1109. if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
  1110. __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
  1111. if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
  1112. __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
  1113. /* outer vlan removal is set according to PF's multi function mode */
  1114. if (IS_MF_SD(bp))
  1115. __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
  1116. }
  1117. static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1118. struct bnx2x_vf_mbx *mbx)
  1119. {
  1120. struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
  1121. struct bnx2x_vf_queue_construct_params qctor;
  1122. int rc = 0;
  1123. /* verify vf_qid */
  1124. if (setup_q->vf_qid >= vf_rxq_count(vf)) {
  1125. BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
  1126. setup_q->vf_qid, vf_rxq_count(vf));
  1127. rc = -EINVAL;
  1128. goto response;
  1129. }
  1130. /* tx queues must be setup alongside rx queues thus if the rx queue
  1131. * is not marked as valid there's nothing to do.
  1132. */
  1133. if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
  1134. struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
  1135. unsigned long q_type = 0;
  1136. struct bnx2x_queue_init_params *init_p;
  1137. struct bnx2x_queue_setup_params *setup_p;
  1138. if (bnx2x_vfq_is_leading(q))
  1139. bnx2x_leading_vfq_init(bp, vf, q);
  1140. /* re-init the VF operation context */
  1141. memset(&qctor, 0 ,
  1142. sizeof(struct bnx2x_vf_queue_construct_params));
  1143. setup_p = &qctor.prep_qsetup;
  1144. init_p = &qctor.qstate.params.init;
  1145. /* activate immediately */
  1146. __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
  1147. if (setup_q->param_valid & VFPF_TXQ_VALID) {
  1148. struct bnx2x_txq_setup_params *txq_params =
  1149. &setup_p->txq_params;
  1150. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  1151. /* save sb resource index */
  1152. q->sb_idx = setup_q->txq.vf_sb;
  1153. /* tx init */
  1154. init_p->tx.hc_rate = setup_q->txq.hc_rate;
  1155. init_p->tx.sb_cq_index = setup_q->txq.sb_index;
  1156. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1157. &init_p->tx.flags);
  1158. /* tx setup - flags */
  1159. bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
  1160. &setup_p->flags);
  1161. /* tx setup - general, nothing */
  1162. /* tx setup - tx */
  1163. txq_params->dscr_map = setup_q->txq.txq_addr;
  1164. txq_params->sb_cq_index = setup_q->txq.sb_index;
  1165. txq_params->traffic_type = setup_q->txq.traffic_type;
  1166. bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
  1167. q->index, q->sb_idx);
  1168. }
  1169. if (setup_q->param_valid & VFPF_RXQ_VALID) {
  1170. struct bnx2x_rxq_setup_params *rxq_params =
  1171. &setup_p->rxq_params;
  1172. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  1173. /* Note: there is no support for different SBs
  1174. * for TX and RX
  1175. */
  1176. q->sb_idx = setup_q->rxq.vf_sb;
  1177. /* rx init */
  1178. init_p->rx.hc_rate = setup_q->rxq.hc_rate;
  1179. init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
  1180. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1181. &init_p->rx.flags);
  1182. /* rx setup - flags */
  1183. bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
  1184. &setup_p->flags);
  1185. /* rx setup - general */
  1186. setup_p->gen_params.mtu = setup_q->rxq.mtu;
  1187. /* rx setup - rx */
  1188. rxq_params->drop_flags = setup_q->rxq.drop_flags;
  1189. rxq_params->dscr_map = setup_q->rxq.rxq_addr;
  1190. rxq_params->sge_map = setup_q->rxq.sge_addr;
  1191. rxq_params->rcq_map = setup_q->rxq.rcq_addr;
  1192. rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
  1193. rxq_params->buf_sz = setup_q->rxq.buf_sz;
  1194. rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
  1195. rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
  1196. rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
  1197. rxq_params->cache_line_log =
  1198. setup_q->rxq.cache_line_log;
  1199. rxq_params->sb_cq_index = setup_q->rxq.sb_index;
  1200. /* rx setup - multicast engine */
  1201. if (bnx2x_vfq_is_leading(q)) {
  1202. u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
  1203. rxq_params->mcast_engine_id = mcast_id;
  1204. __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
  1205. }
  1206. bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
  1207. q->index, q->sb_idx);
  1208. }
  1209. /* complete the preparations */
  1210. bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
  1211. rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
  1212. if (rc)
  1213. goto response;
  1214. }
  1215. response:
  1216. bnx2x_vf_mbx_resp(bp, vf, rc);
  1217. }
  1218. static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
  1219. struct bnx2x_virtf *vf,
  1220. struct vfpf_set_q_filters_tlv *tlv,
  1221. struct bnx2x_vf_mac_vlan_filters **pfl,
  1222. u32 type_flag)
  1223. {
  1224. int i, j;
  1225. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1226. size_t fsz;
  1227. fsz = tlv->n_mac_vlan_filters *
  1228. sizeof(struct bnx2x_vf_mac_vlan_filter) +
  1229. sizeof(struct bnx2x_vf_mac_vlan_filters);
  1230. fl = kzalloc(fsz, GFP_KERNEL);
  1231. if (!fl)
  1232. return -ENOMEM;
  1233. for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
  1234. struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
  1235. if ((msg_filter->flags & type_flag) != type_flag)
  1236. continue;
  1237. if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
  1238. fl->filters[j].mac = msg_filter->mac;
  1239. fl->filters[j].type = BNX2X_VF_FILTER_MAC;
  1240. } else {
  1241. fl->filters[j].vid = msg_filter->vlan_tag;
  1242. fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
  1243. }
  1244. fl->filters[j].add =
  1245. (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
  1246. true : false;
  1247. fl->count++;
  1248. }
  1249. if (!fl->count)
  1250. kfree(fl);
  1251. else
  1252. *pfl = fl;
  1253. return 0;
  1254. }
  1255. static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
  1256. struct vfpf_q_mac_vlan_filter *filter)
  1257. {
  1258. DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
  1259. if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
  1260. DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
  1261. if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
  1262. DP_CONT(msglvl, ", MAC=%pM", filter->mac);
  1263. DP_CONT(msglvl, "\n");
  1264. }
  1265. static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
  1266. struct vfpf_set_q_filters_tlv *filters)
  1267. {
  1268. int i;
  1269. if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
  1270. for (i = 0; i < filters->n_mac_vlan_filters; i++)
  1271. bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
  1272. &filters->filters[i]);
  1273. if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
  1274. DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
  1275. if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
  1276. for (i = 0; i < filters->n_multicast; i++)
  1277. DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
  1278. }
  1279. #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
  1280. #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
  1281. static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1282. {
  1283. int rc = 0;
  1284. struct vfpf_set_q_filters_tlv *msg =
  1285. &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
  1286. /* check for any mac/vlan changes */
  1287. if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
  1288. /* build mac list */
  1289. struct bnx2x_vf_mac_vlan_filters *fl = NULL;
  1290. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1291. VFPF_MAC_FILTER);
  1292. if (rc)
  1293. goto op_err;
  1294. if (fl) {
  1295. /* set mac list */
  1296. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1297. msg->vf_qid,
  1298. false);
  1299. if (rc)
  1300. goto op_err;
  1301. }
  1302. /* build vlan list */
  1303. fl = NULL;
  1304. rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
  1305. VFPF_VLAN_FILTER);
  1306. if (rc)
  1307. goto op_err;
  1308. if (fl) {
  1309. /* set vlan list */
  1310. rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
  1311. msg->vf_qid,
  1312. false);
  1313. if (rc)
  1314. goto op_err;
  1315. }
  1316. }
  1317. if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
  1318. unsigned long accept = 0;
  1319. struct pf_vf_bulletin_content *bulletin =
  1320. BP_VF_BULLETIN(bp, vf->index);
  1321. /* Ignore VF requested mode; instead set a regular mode */
  1322. if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
  1323. __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
  1324. __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
  1325. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
  1326. }
  1327. /* A packet arriving the vf's mac should be accepted
  1328. * with any vlan, unless a vlan has already been
  1329. * configured.
  1330. */
  1331. if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
  1332. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
  1333. /* set rx-mode */
  1334. rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
  1335. if (rc)
  1336. goto op_err;
  1337. }
  1338. if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
  1339. /* set mcasts */
  1340. rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
  1341. msg->n_multicast, false);
  1342. if (rc)
  1343. goto op_err;
  1344. }
  1345. op_err:
  1346. if (rc)
  1347. BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
  1348. vf->abs_vfid, msg->vf_qid, rc);
  1349. return rc;
  1350. }
  1351. static int bnx2x_filters_validate_mac(struct bnx2x *bp,
  1352. struct bnx2x_virtf *vf,
  1353. struct vfpf_set_q_filters_tlv *filters)
  1354. {
  1355. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1356. int rc = 0;
  1357. /* if a mac was already set for this VF via the set vf mac ndo, we only
  1358. * accept mac configurations of that mac. Why accept them at all?
  1359. * because PF may have been unable to configure the mac at the time
  1360. * since queue was not set up.
  1361. */
  1362. if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
  1363. /* once a mac was set by ndo can only accept a single mac... */
  1364. if (filters->n_mac_vlan_filters > 1) {
  1365. BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
  1366. vf->abs_vfid);
  1367. rc = -EPERM;
  1368. goto response;
  1369. }
  1370. /* ...and only the mac set by the ndo */
  1371. if (filters->n_mac_vlan_filters == 1 &&
  1372. !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
  1373. BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
  1374. vf->abs_vfid);
  1375. rc = -EPERM;
  1376. goto response;
  1377. }
  1378. }
  1379. response:
  1380. return rc;
  1381. }
  1382. static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
  1383. struct bnx2x_virtf *vf,
  1384. struct vfpf_set_q_filters_tlv *filters)
  1385. {
  1386. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
  1387. int rc = 0;
  1388. /* if vlan was set by hypervisor we don't allow guest to config vlan */
  1389. if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
  1390. int i;
  1391. /* search for vlan filters */
  1392. for (i = 0; i < filters->n_mac_vlan_filters; i++) {
  1393. if (filters->filters[i].flags &
  1394. VFPF_Q_FILTER_VLAN_TAG_VALID) {
  1395. BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
  1396. vf->abs_vfid);
  1397. rc = -EPERM;
  1398. goto response;
  1399. }
  1400. }
  1401. }
  1402. /* verify vf_qid */
  1403. if (filters->vf_qid > vf_rxq_count(vf)) {
  1404. rc = -EPERM;
  1405. goto response;
  1406. }
  1407. response:
  1408. return rc;
  1409. }
  1410. static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
  1411. struct bnx2x_virtf *vf,
  1412. struct bnx2x_vf_mbx *mbx)
  1413. {
  1414. struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
  1415. int rc;
  1416. rc = bnx2x_filters_validate_mac(bp, vf, filters);
  1417. if (rc)
  1418. goto response;
  1419. rc = bnx2x_filters_validate_vlan(bp, vf, filters);
  1420. if (rc)
  1421. goto response;
  1422. DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
  1423. vf->abs_vfid,
  1424. filters->vf_qid);
  1425. /* print q_filter message */
  1426. bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
  1427. rc = bnx2x_vf_mbx_qfilters(bp, vf);
  1428. response:
  1429. bnx2x_vf_mbx_resp(bp, vf, rc);
  1430. }
  1431. static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1432. struct bnx2x_vf_mbx *mbx)
  1433. {
  1434. int qid = mbx->msg->req.q_op.vf_qid;
  1435. int rc;
  1436. DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
  1437. vf->abs_vfid, qid);
  1438. rc = bnx2x_vf_queue_teardown(bp, vf, qid);
  1439. bnx2x_vf_mbx_resp(bp, vf, rc);
  1440. }
  1441. static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1442. struct bnx2x_vf_mbx *mbx)
  1443. {
  1444. int rc;
  1445. DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
  1446. rc = bnx2x_vf_close(bp, vf);
  1447. bnx2x_vf_mbx_resp(bp, vf, rc);
  1448. }
  1449. static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1450. struct bnx2x_vf_mbx *mbx)
  1451. {
  1452. int rc;
  1453. DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
  1454. rc = bnx2x_vf_free(bp, vf);
  1455. bnx2x_vf_mbx_resp(bp, vf, rc);
  1456. }
  1457. static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1458. struct bnx2x_vf_mbx *mbx)
  1459. {
  1460. struct bnx2x_config_rss_params rss;
  1461. struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
  1462. int rc = 0;
  1463. if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
  1464. rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
  1465. BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
  1466. vf->index);
  1467. rc = -EINVAL;
  1468. goto mbx_resp;
  1469. }
  1470. memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
  1471. /* set vfop params according to rss tlv */
  1472. memcpy(rss.ind_table, rss_tlv->ind_table,
  1473. T_ETH_INDIRECTION_TABLE_SIZE);
  1474. memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
  1475. rss.rss_obj = &vf->rss_conf_obj;
  1476. rss.rss_result_mask = rss_tlv->rss_result_mask;
  1477. /* flags handled individually for backward/forward compatability */
  1478. rss.rss_flags = 0;
  1479. rss.ramrod_flags = 0;
  1480. if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
  1481. __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
  1482. if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
  1483. __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
  1484. if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
  1485. __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
  1486. if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
  1487. __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
  1488. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
  1489. __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
  1490. if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
  1491. __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
  1492. if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
  1493. __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
  1494. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
  1495. __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
  1496. if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
  1497. __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
  1498. if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
  1499. rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
  1500. (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
  1501. rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
  1502. BNX2X_ERR("about to hit a FW assert. aborting...\n");
  1503. rc = -EINVAL;
  1504. goto mbx_resp;
  1505. }
  1506. rc = bnx2x_vf_rss_update(bp, vf, &rss);
  1507. mbx_resp:
  1508. bnx2x_vf_mbx_resp(bp, vf, rc);
  1509. }
  1510. static int bnx2x_validate_tpa_params(struct bnx2x *bp,
  1511. struct vfpf_tpa_tlv *tpa_tlv)
  1512. {
  1513. int rc = 0;
  1514. if (tpa_tlv->tpa_client_info.max_sges_for_packet >
  1515. U_ETH_MAX_SGES_FOR_PACKET) {
  1516. rc = -EINVAL;
  1517. BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
  1518. tpa_tlv->tpa_client_info.max_sges_for_packet,
  1519. U_ETH_MAX_SGES_FOR_PACKET);
  1520. }
  1521. if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
  1522. rc = -EINVAL;
  1523. BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
  1524. tpa_tlv->tpa_client_info.max_tpa_queues,
  1525. MAX_AGG_QS(bp));
  1526. }
  1527. return rc;
  1528. }
  1529. static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1530. struct bnx2x_vf_mbx *mbx)
  1531. {
  1532. struct bnx2x_queue_update_tpa_params vf_op_params;
  1533. struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
  1534. int rc = 0;
  1535. memset(&vf_op_params, 0, sizeof(vf_op_params));
  1536. if (bnx2x_validate_tpa_params(bp, tpa_tlv))
  1537. goto mbx_resp;
  1538. vf_op_params.complete_on_both_clients =
  1539. tpa_tlv->tpa_client_info.complete_on_both_clients;
  1540. vf_op_params.dont_verify_thr =
  1541. tpa_tlv->tpa_client_info.dont_verify_thr;
  1542. vf_op_params.max_agg_sz =
  1543. tpa_tlv->tpa_client_info.max_agg_size;
  1544. vf_op_params.max_sges_pkt =
  1545. tpa_tlv->tpa_client_info.max_sges_for_packet;
  1546. vf_op_params.max_tpa_queues =
  1547. tpa_tlv->tpa_client_info.max_tpa_queues;
  1548. vf_op_params.sge_buff_sz =
  1549. tpa_tlv->tpa_client_info.sge_buff_size;
  1550. vf_op_params.sge_pause_thr_high =
  1551. tpa_tlv->tpa_client_info.sge_pause_thr_high;
  1552. vf_op_params.sge_pause_thr_low =
  1553. tpa_tlv->tpa_client_info.sge_pause_thr_low;
  1554. vf_op_params.tpa_mode =
  1555. tpa_tlv->tpa_client_info.tpa_mode;
  1556. vf_op_params.update_ipv4 =
  1557. tpa_tlv->tpa_client_info.update_ipv4;
  1558. vf_op_params.update_ipv6 =
  1559. tpa_tlv->tpa_client_info.update_ipv6;
  1560. rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
  1561. mbx_resp:
  1562. bnx2x_vf_mbx_resp(bp, vf, rc);
  1563. }
  1564. /* dispatch request */
  1565. static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1566. struct bnx2x_vf_mbx *mbx)
  1567. {
  1568. int i;
  1569. /* check if tlv type is known */
  1570. if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
  1571. /* Lock the per vf op mutex and note the locker's identity.
  1572. * The unlock will take place in mbx response.
  1573. */
  1574. bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1575. /* switch on the opcode */
  1576. switch (mbx->first_tlv.tl.type) {
  1577. case CHANNEL_TLV_ACQUIRE:
  1578. bnx2x_vf_mbx_acquire(bp, vf, mbx);
  1579. return;
  1580. case CHANNEL_TLV_INIT:
  1581. bnx2x_vf_mbx_init_vf(bp, vf, mbx);
  1582. return;
  1583. case CHANNEL_TLV_SETUP_Q:
  1584. bnx2x_vf_mbx_setup_q(bp, vf, mbx);
  1585. return;
  1586. case CHANNEL_TLV_SET_Q_FILTERS:
  1587. bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
  1588. return;
  1589. case CHANNEL_TLV_TEARDOWN_Q:
  1590. bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
  1591. return;
  1592. case CHANNEL_TLV_CLOSE:
  1593. bnx2x_vf_mbx_close_vf(bp, vf, mbx);
  1594. return;
  1595. case CHANNEL_TLV_RELEASE:
  1596. bnx2x_vf_mbx_release_vf(bp, vf, mbx);
  1597. return;
  1598. case CHANNEL_TLV_UPDATE_RSS:
  1599. bnx2x_vf_mbx_update_rss(bp, vf, mbx);
  1600. return;
  1601. case CHANNEL_TLV_UPDATE_TPA:
  1602. bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
  1603. return;
  1604. }
  1605. } else {
  1606. /* unknown TLV - this may belong to a VF driver from the future
  1607. * - a version written after this PF driver was written, which
  1608. * supports features unknown as of yet. Too bad since we don't
  1609. * support them. Or this may be because someone wrote a crappy
  1610. * VF driver and is sending garbage over the channel.
  1611. */
  1612. BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
  1613. mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
  1614. vf->state);
  1615. for (i = 0; i < 20; i++)
  1616. DP_CONT(BNX2X_MSG_IOV, "%x ",
  1617. mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
  1618. }
  1619. /* can we respond to VF (do we have an address for it?) */
  1620. if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
  1621. /* notify the VF that we do not support this request */
  1622. bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
  1623. } else {
  1624. /* can't send a response since this VF is unknown to us
  1625. * just ack the FW to release the mailbox and unlock
  1626. * the channel.
  1627. */
  1628. storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
  1629. /* Firmware ack should be written before unlocking channel */
  1630. mmiowb();
  1631. bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
  1632. }
  1633. }
  1634. void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
  1635. struct vf_pf_event_data *vfpf_event)
  1636. {
  1637. u8 vf_idx;
  1638. DP(BNX2X_MSG_IOV,
  1639. "vf pf event received: vfid %d, address_hi %x, address lo %x",
  1640. vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
  1641. /* Sanity checks consider removing later */
  1642. /* check if the vf_id is valid */
  1643. if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
  1644. BNX2X_NR_VIRTFN(bp)) {
  1645. BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
  1646. vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
  1647. return;
  1648. }
  1649. vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
  1650. /* Update VFDB with current message and schedule its handling */
  1651. mutex_lock(&BP_VFDB(bp)->event_mutex);
  1652. BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
  1653. BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
  1654. BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
  1655. mutex_unlock(&BP_VFDB(bp)->event_mutex);
  1656. bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
  1657. }
  1658. /* handle new vf-pf messages */
  1659. void bnx2x_vf_mbx(struct bnx2x *bp)
  1660. {
  1661. struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
  1662. u64 events;
  1663. u8 vf_idx;
  1664. int rc;
  1665. if (!vfdb)
  1666. return;
  1667. mutex_lock(&vfdb->event_mutex);
  1668. events = vfdb->event_occur;
  1669. vfdb->event_occur = 0;
  1670. mutex_unlock(&vfdb->event_mutex);
  1671. for_each_vf(bp, vf_idx) {
  1672. struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
  1673. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  1674. /* Handle VFs which have pending events */
  1675. if (!(events & (1ULL << vf_idx)))
  1676. continue;
  1677. DP(BNX2X_MSG_IOV,
  1678. "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
  1679. vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
  1680. mbx->first_tlv.resp_msg_offset);
  1681. /* dmae to get the VF request */
  1682. rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
  1683. vf->abs_vfid, mbx->vf_addr_hi,
  1684. mbx->vf_addr_lo,
  1685. sizeof(union vfpf_tlvs)/4);
  1686. if (rc) {
  1687. BNX2X_ERR("Failed to copy request VF %d\n",
  1688. vf->abs_vfid);
  1689. bnx2x_vf_release(bp, vf);
  1690. return;
  1691. }
  1692. /* process the VF message header */
  1693. mbx->first_tlv = mbx->msg->req.first_tlv;
  1694. /* Clean response buffer to refrain from falsely
  1695. * seeing chains.
  1696. */
  1697. memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
  1698. /* dispatch the request (will prepare the response) */
  1699. bnx2x_vf_mbx_request(bp, vf, mbx);
  1700. }
  1701. }
  1702. void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
  1703. bool support_long)
  1704. {
  1705. /* Older VFs contain a bug where they can't check CRC for bulletin
  1706. * boards of length greater than legacy size.
  1707. */
  1708. bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
  1709. BULLETIN_CONTENT_LEGACY_SIZE;
  1710. bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
  1711. }
  1712. /* propagate local bulletin board to vf */
  1713. int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
  1714. {
  1715. struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
  1716. dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
  1717. vf * BULLETIN_CONTENT_SIZE;
  1718. dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
  1719. int rc;
  1720. /* can only update vf after init took place */
  1721. if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
  1722. bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
  1723. return 0;
  1724. /* increment bulletin board version and compute crc */
  1725. bulletin->version++;
  1726. bnx2x_vf_bulletin_finalize(bulletin,
  1727. (bnx2x_vf(bp, vf, cfg_flags) &
  1728. VF_CFG_EXT_BULLETIN) ? true : false);
  1729. /* propagate bulletin board via dmae to vm memory */
  1730. rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
  1731. bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
  1732. U64_LO(vf_addr), bulletin->length / 4);
  1733. return rc;
  1734. }