qed_vf.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/crc32.h>
  33. #include <linux/etherdevice.h>
  34. #include "qed.h"
  35. #include "qed_sriov.h"
  36. #include "qed_vf.h"
  37. static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
  38. {
  39. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  40. void *p_tlv;
  41. /* This lock is released when we receive PF's response
  42. * in qed_send_msg2pf().
  43. * So, qed_vf_pf_prep() and qed_send_msg2pf()
  44. * must come in sequence.
  45. */
  46. mutex_lock(&(p_iov->mutex));
  47. DP_VERBOSE(p_hwfn,
  48. QED_MSG_IOV,
  49. "preparing to send 0x%04x tlv over vf pf channel\n",
  50. type);
  51. /* Reset Requst offset */
  52. p_iov->offset = (u8 *)p_iov->vf2pf_request;
  53. /* Clear mailbox - both request and reply */
  54. memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
  55. memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
  56. /* Init type and length */
  57. p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
  58. /* Init first tlv header */
  59. ((struct vfpf_first_tlv *)p_tlv)->reply_address =
  60. (u64)p_iov->pf2vf_reply_phys;
  61. return p_tlv;
  62. }
  63. static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
  64. {
  65. union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
  66. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  67. "VF request status = 0x%x, PF reply status = 0x%x\n",
  68. req_status, resp->default_resp.hdr.status);
  69. mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
  70. }
  71. static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
  72. {
  73. union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
  74. struct ustorm_trigger_vf_zone trigger;
  75. struct ustorm_vf_zone *zone_data;
  76. int rc = 0, time = 100;
  77. zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
  78. /* output tlvs list */
  79. qed_dp_tlv_list(p_hwfn, p_req);
  80. /* need to add the END TLV to the message size */
  81. resp_size += sizeof(struct channel_list_end_tlv);
  82. /* Send TLVs over HW channel */
  83. memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
  84. trigger.vf_pf_msg_valid = 1;
  85. DP_VERBOSE(p_hwfn,
  86. QED_MSG_IOV,
  87. "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
  88. GET_FIELD(p_hwfn->hw_info.concrete_fid,
  89. PXP_CONCRETE_FID_PFID),
  90. upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
  91. lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
  92. &zone_data->non_trigger.vf_pf_msg_addr,
  93. *((u32 *)&trigger), &zone_data->trigger);
  94. REG_WR(p_hwfn,
  95. (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
  96. lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
  97. REG_WR(p_hwfn,
  98. (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
  99. upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
  100. /* The message data must be written first, to prevent trigger before
  101. * data is written.
  102. */
  103. wmb();
  104. REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
  105. /* When PF would be done with the response, it would write back to the
  106. * `done' address. Poll until then.
  107. */
  108. while ((!*done) && time) {
  109. msleep(25);
  110. time--;
  111. }
  112. if (!*done) {
  113. DP_NOTICE(p_hwfn,
  114. "VF <-- PF Timeout [Type %d]\n",
  115. p_req->first_tlv.tl.type);
  116. rc = -EBUSY;
  117. } else {
  118. if ((*done != PFVF_STATUS_SUCCESS) &&
  119. (*done != PFVF_STATUS_NO_RESOURCE))
  120. DP_NOTICE(p_hwfn,
  121. "PF response: %d [Type %d]\n",
  122. *done, p_req->first_tlv.tl.type);
  123. else
  124. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  125. "PF response: %d [Type %d]\n",
  126. *done, p_req->first_tlv.tl.type);
  127. }
  128. return rc;
  129. }
  130. static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn,
  131. struct qed_queue_cid *p_cid)
  132. {
  133. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  134. struct vfpf_qid_tlv *p_qid_tlv;
  135. /* Only add QIDs for the queue if it was negotiated with PF */
  136. if (!(p_iov->acquire_resp.pfdev_info.capabilities &
  137. PFVF_ACQUIRE_CAP_QUEUE_QIDS))
  138. return;
  139. p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  140. CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
  141. p_qid_tlv->qid = p_cid->qid_usage_idx;
  142. }
  143. int _qed_vf_pf_release(struct qed_hwfn *p_hwfn, bool b_final)
  144. {
  145. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  146. struct pfvf_def_resp_tlv *resp;
  147. struct vfpf_first_tlv *req;
  148. u32 size;
  149. int rc;
  150. /* clear mailbox and prep first tlv */
  151. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
  152. /* add list termination tlv */
  153. qed_add_tlv(p_hwfn, &p_iov->offset,
  154. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  155. resp = &p_iov->pf2vf_reply->default_resp;
  156. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  157. if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
  158. rc = -EAGAIN;
  159. qed_vf_pf_req_end(p_hwfn, rc);
  160. if (!b_final)
  161. return rc;
  162. p_hwfn->b_int_enabled = 0;
  163. if (p_iov->vf2pf_request)
  164. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  165. sizeof(union vfpf_tlvs),
  166. p_iov->vf2pf_request,
  167. p_iov->vf2pf_request_phys);
  168. if (p_iov->pf2vf_reply)
  169. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  170. sizeof(union pfvf_tlvs),
  171. p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
  172. if (p_iov->bulletin.p_virt) {
  173. size = sizeof(struct qed_bulletin_content);
  174. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  175. size,
  176. p_iov->bulletin.p_virt, p_iov->bulletin.phys);
  177. }
  178. kfree(p_hwfn->vf_iov_info);
  179. p_hwfn->vf_iov_info = NULL;
  180. return rc;
  181. }
  182. int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
  183. {
  184. return _qed_vf_pf_release(p_hwfn, true);
  185. }
  186. #define VF_ACQUIRE_THRESH 3
  187. static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
  188. struct vf_pf_resc_request *p_req,
  189. struct pf_vf_resc *p_resp)
  190. {
  191. DP_VERBOSE(p_hwfn,
  192. QED_MSG_IOV,
  193. "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n",
  194. p_req->num_rxqs,
  195. p_resp->num_rxqs,
  196. p_req->num_rxqs,
  197. p_resp->num_txqs,
  198. p_req->num_sbs,
  199. p_resp->num_sbs,
  200. p_req->num_mac_filters,
  201. p_resp->num_mac_filters,
  202. p_req->num_vlan_filters,
  203. p_resp->num_vlan_filters,
  204. p_req->num_mc_filters,
  205. p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids);
  206. /* humble our request */
  207. p_req->num_txqs = p_resp->num_txqs;
  208. p_req->num_rxqs = p_resp->num_rxqs;
  209. p_req->num_sbs = p_resp->num_sbs;
  210. p_req->num_mac_filters = p_resp->num_mac_filters;
  211. p_req->num_vlan_filters = p_resp->num_vlan_filters;
  212. p_req->num_mc_filters = p_resp->num_mc_filters;
  213. p_req->num_cids = p_resp->num_cids;
  214. }
  215. static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
  216. {
  217. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  218. struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
  219. struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
  220. struct vf_pf_resc_request *p_resc;
  221. bool resources_acquired = false;
  222. struct vfpf_acquire_tlv *req;
  223. int rc = 0, attempts = 0;
  224. /* clear mailbox and prep first tlv */
  225. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  226. p_resc = &req->resc_request;
  227. /* starting filling the request */
  228. req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
  229. p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
  230. p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
  231. p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
  232. p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
  233. p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
  234. p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS;
  235. req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
  236. req->vfdev_info.fw_major = FW_MAJOR_VERSION;
  237. req->vfdev_info.fw_minor = FW_MINOR_VERSION;
  238. req->vfdev_info.fw_revision = FW_REVISION_VERSION;
  239. req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
  240. req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
  241. req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
  242. /* Fill capability field with any non-deprecated config we support */
  243. req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
  244. /* If we've mapped the doorbell bar, try using queue qids */
  245. if (p_iov->b_doorbell_bar) {
  246. req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_PHYSICAL_BAR |
  247. VFPF_ACQUIRE_CAP_QUEUE_QIDS;
  248. p_resc->num_cids = QED_ETH_VF_MAX_NUM_CIDS;
  249. }
  250. /* pf 2 vf bulletin board address */
  251. req->bulletin_addr = p_iov->bulletin.phys;
  252. req->bulletin_size = p_iov->bulletin.size;
  253. /* add list termination tlv */
  254. qed_add_tlv(p_hwfn, &p_iov->offset,
  255. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  256. while (!resources_acquired) {
  257. DP_VERBOSE(p_hwfn,
  258. QED_MSG_IOV, "attempting to acquire resources\n");
  259. /* Clear response buffer, as this might be a re-send */
  260. memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
  261. /* send acquire request */
  262. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  263. if (rc)
  264. goto exit;
  265. /* copy acquire response from buffer to p_hwfn */
  266. memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
  267. attempts++;
  268. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  269. /* PF agrees to allocate our resources */
  270. if (!(resp->pfdev_info.capabilities &
  271. PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
  272. /* It's possible legacy PF mistakenly accepted;
  273. * but we don't care - simply mark it as
  274. * legacy and continue.
  275. */
  276. req->vfdev_info.capabilities |=
  277. VFPF_ACQUIRE_CAP_PRE_FP_HSI;
  278. }
  279. DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
  280. resources_acquired = true;
  281. } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
  282. attempts < VF_ACQUIRE_THRESH) {
  283. qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
  284. &resp->resc);
  285. } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
  286. if (pfdev_info->major_fp_hsi &&
  287. (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
  288. DP_NOTICE(p_hwfn,
  289. "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
  290. pfdev_info->major_fp_hsi,
  291. pfdev_info->minor_fp_hsi,
  292. ETH_HSI_VER_MAJOR,
  293. ETH_HSI_VER_MINOR,
  294. pfdev_info->major_fp_hsi);
  295. rc = -EINVAL;
  296. goto exit;
  297. }
  298. if (!pfdev_info->major_fp_hsi) {
  299. if (req->vfdev_info.capabilities &
  300. VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
  301. DP_NOTICE(p_hwfn,
  302. "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
  303. rc = -EINVAL;
  304. goto exit;
  305. } else {
  306. DP_INFO(p_hwfn,
  307. "PF is old - try re-acquire to see if it supports FW-version override\n");
  308. req->vfdev_info.capabilities |=
  309. VFPF_ACQUIRE_CAP_PRE_FP_HSI;
  310. continue;
  311. }
  312. }
  313. /* If PF/VF are using same Major, PF must have had
  314. * it's reasons. Simply fail.
  315. */
  316. DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
  317. rc = -EINVAL;
  318. goto exit;
  319. } else {
  320. DP_ERR(p_hwfn,
  321. "PF returned error %d to VF acquisition request\n",
  322. resp->hdr.status);
  323. rc = -EAGAIN;
  324. goto exit;
  325. }
  326. }
  327. /* Mark the PF as legacy, if needed */
  328. if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
  329. p_iov->b_pre_fp_hsi = true;
  330. /* In case PF doesn't support multi-queue Tx, update the number of
  331. * CIDs to reflect the number of queues [older PFs didn't fill that
  332. * field].
  333. */
  334. if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS))
  335. resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs;
  336. /* Update bulletin board size with response from PF */
  337. p_iov->bulletin.size = resp->bulletin_size;
  338. /* get HW info */
  339. p_hwfn->cdev->type = resp->pfdev_info.dev_type;
  340. p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
  341. p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
  342. /* Learn of the possibility of CMT */
  343. if (IS_LEAD_HWFN(p_hwfn)) {
  344. if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
  345. DP_NOTICE(p_hwfn, "100g VF\n");
  346. p_hwfn->cdev->num_hwfns = 2;
  347. }
  348. }
  349. if (!p_iov->b_pre_fp_hsi &&
  350. ETH_HSI_VER_MINOR &&
  351. (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
  352. DP_INFO(p_hwfn,
  353. "PF is using older fastpath HSI; %02x.%02x is configured\n",
  354. ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
  355. }
  356. exit:
  357. qed_vf_pf_req_end(p_hwfn, rc);
  358. return rc;
  359. }
  360. u32 qed_vf_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
  361. {
  362. u32 bar_size;
  363. /* Regview size is fixed */
  364. if (bar_id == BAR_ID_0)
  365. return 1 << 17;
  366. /* Doorbell is received from PF */
  367. bar_size = p_hwfn->vf_iov_info->acquire_resp.pfdev_info.bar_size;
  368. if (bar_size)
  369. return 1 << bar_size;
  370. return 0;
  371. }
  372. int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
  373. {
  374. struct qed_hwfn *p_lead = QED_LEADING_HWFN(p_hwfn->cdev);
  375. struct qed_vf_iov *p_iov;
  376. u32 reg;
  377. int rc;
  378. /* Set number of hwfns - might be overriden once leading hwfn learns
  379. * actual configuration from PF.
  380. */
  381. if (IS_LEAD_HWFN(p_hwfn))
  382. p_hwfn->cdev->num_hwfns = 1;
  383. reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
  384. p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
  385. reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
  386. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
  387. /* Allocate vf sriov info */
  388. p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
  389. if (!p_iov)
  390. return -ENOMEM;
  391. /* Doorbells are tricky; Upper-layer has alreday set the hwfn doorbell
  392. * value, but there are several incompatibily scenarios where that
  393. * would be incorrect and we'd need to override it.
  394. */
  395. if (!p_hwfn->doorbells) {
  396. p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
  397. PXP_VF_BAR0_START_DQ;
  398. } else if (p_hwfn == p_lead) {
  399. /* For leading hw-function, value is always correct, but need
  400. * to handle scenario where legacy PF would not support 100g
  401. * mapped bars later.
  402. */
  403. p_iov->b_doorbell_bar = true;
  404. } else {
  405. /* here, value would be correct ONLY if the leading hwfn
  406. * received indication that mapped-bars are supported.
  407. */
  408. if (p_lead->vf_iov_info->b_doorbell_bar)
  409. p_iov->b_doorbell_bar = true;
  410. else
  411. p_hwfn->doorbells = (u8 __iomem *)
  412. p_hwfn->regview + PXP_VF_BAR0_START_DQ;
  413. }
  414. /* Allocate vf2pf msg */
  415. p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  416. sizeof(union vfpf_tlvs),
  417. &p_iov->vf2pf_request_phys,
  418. GFP_KERNEL);
  419. if (!p_iov->vf2pf_request)
  420. goto free_p_iov;
  421. p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  422. sizeof(union pfvf_tlvs),
  423. &p_iov->pf2vf_reply_phys,
  424. GFP_KERNEL);
  425. if (!p_iov->pf2vf_reply)
  426. goto free_vf2pf_request;
  427. DP_VERBOSE(p_hwfn,
  428. QED_MSG_IOV,
  429. "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
  430. p_iov->vf2pf_request,
  431. (u64) p_iov->vf2pf_request_phys,
  432. p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
  433. /* Allocate Bulletin board */
  434. p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
  435. p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  436. p_iov->bulletin.size,
  437. &p_iov->bulletin.phys,
  438. GFP_KERNEL);
  439. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  440. "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
  441. p_iov->bulletin.p_virt,
  442. (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
  443. mutex_init(&p_iov->mutex);
  444. p_hwfn->vf_iov_info = p_iov;
  445. p_hwfn->hw_info.personality = QED_PCI_ETH;
  446. rc = qed_vf_pf_acquire(p_hwfn);
  447. /* If VF is 100g using a mapped bar and PF is too old to support that,
  448. * acquisition would succeed - but the VF would have no way knowing
  449. * the size of the doorbell bar configured in HW and thus will not
  450. * know how to split it for 2nd hw-function.
  451. * In this case we re-try without the indication of the mapped
  452. * doorbell.
  453. */
  454. if (!rc && p_iov->b_doorbell_bar &&
  455. !qed_vf_hw_bar_size(p_hwfn, BAR_ID_1) &&
  456. (p_hwfn->cdev->num_hwfns > 1)) {
  457. rc = _qed_vf_pf_release(p_hwfn, false);
  458. if (rc)
  459. return rc;
  460. p_iov->b_doorbell_bar = false;
  461. p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
  462. PXP_VF_BAR0_START_DQ;
  463. rc = qed_vf_pf_acquire(p_hwfn);
  464. }
  465. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  466. "Regview [%p], Doorbell [%p], Device-doorbell [%p]\n",
  467. p_hwfn->regview, p_hwfn->doorbells, p_hwfn->cdev->doorbells);
  468. return rc;
  469. free_vf2pf_request:
  470. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  471. sizeof(union vfpf_tlvs),
  472. p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
  473. free_p_iov:
  474. kfree(p_iov);
  475. return -ENOMEM;
  476. }
  477. #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
  478. #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
  479. (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
  480. static void
  481. __qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
  482. struct qed_tunn_update_type *p_src,
  483. enum qed_tunn_clss mask, u8 *p_cls)
  484. {
  485. if (p_src->b_update_mode) {
  486. p_req->tun_mode_update_mask |= BIT(mask);
  487. if (p_src->b_mode_enabled)
  488. p_req->tunn_mode |= BIT(mask);
  489. }
  490. *p_cls = p_src->tun_cls;
  491. }
  492. static void
  493. qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
  494. struct qed_tunn_update_type *p_src,
  495. enum qed_tunn_clss mask,
  496. u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
  497. u8 *p_update_port, u16 *p_udp_port)
  498. {
  499. if (p_port->b_update_port) {
  500. *p_update_port = 1;
  501. *p_udp_port = p_port->port;
  502. }
  503. __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
  504. }
  505. void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
  506. {
  507. if (p_tun->vxlan.b_mode_enabled)
  508. p_tun->vxlan.b_update_mode = true;
  509. if (p_tun->l2_geneve.b_mode_enabled)
  510. p_tun->l2_geneve.b_update_mode = true;
  511. if (p_tun->ip_geneve.b_mode_enabled)
  512. p_tun->ip_geneve.b_update_mode = true;
  513. if (p_tun->l2_gre.b_mode_enabled)
  514. p_tun->l2_gre.b_update_mode = true;
  515. if (p_tun->ip_gre.b_mode_enabled)
  516. p_tun->ip_gre.b_update_mode = true;
  517. p_tun->b_update_rx_cls = true;
  518. p_tun->b_update_tx_cls = true;
  519. }
  520. static void
  521. __qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
  522. u16 feature_mask, u8 tunn_mode,
  523. u8 tunn_cls, enum qed_tunn_mode val)
  524. {
  525. if (feature_mask & BIT(val)) {
  526. p_tun->b_mode_enabled = tunn_mode;
  527. p_tun->tun_cls = tunn_cls;
  528. } else {
  529. p_tun->b_mode_enabled = false;
  530. }
  531. }
  532. static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
  533. struct qed_tunnel_info *p_tun,
  534. struct pfvf_update_tunn_param_tlv *p_resp)
  535. {
  536. /* Update mode and classes provided by PF */
  537. u16 feat_mask = p_resp->tunn_feature_mask;
  538. __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
  539. p_resp->vxlan_mode, p_resp->vxlan_clss,
  540. QED_MODE_VXLAN_TUNN);
  541. __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
  542. p_resp->l2geneve_mode,
  543. p_resp->l2geneve_clss,
  544. QED_MODE_L2GENEVE_TUNN);
  545. __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
  546. p_resp->ipgeneve_mode,
  547. p_resp->ipgeneve_clss,
  548. QED_MODE_IPGENEVE_TUNN);
  549. __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
  550. p_resp->l2gre_mode, p_resp->l2gre_clss,
  551. QED_MODE_L2GRE_TUNN);
  552. __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
  553. p_resp->ipgre_mode, p_resp->ipgre_clss,
  554. QED_MODE_IPGRE_TUNN);
  555. p_tun->geneve_port.port = p_resp->geneve_udp_port;
  556. p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
  557. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  558. "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
  559. p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
  560. p_tun->ip_geneve.b_mode_enabled,
  561. p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
  562. }
  563. int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
  564. struct qed_tunnel_info *p_src)
  565. {
  566. struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
  567. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  568. struct pfvf_update_tunn_param_tlv *p_resp;
  569. struct vfpf_update_tunn_param_tlv *p_req;
  570. int rc;
  571. p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
  572. sizeof(*p_req));
  573. if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
  574. p_req->update_tun_cls = 1;
  575. qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
  576. &p_req->vxlan_clss, &p_src->vxlan_port,
  577. &p_req->update_vxlan_port,
  578. &p_req->vxlan_port);
  579. qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
  580. QED_MODE_L2GENEVE_TUNN,
  581. &p_req->l2geneve_clss, &p_src->geneve_port,
  582. &p_req->update_geneve_port,
  583. &p_req->geneve_port);
  584. __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
  585. QED_MODE_IPGENEVE_TUNN,
  586. &p_req->ipgeneve_clss);
  587. __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
  588. QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
  589. __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
  590. QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
  591. /* add list termination tlv */
  592. qed_add_tlv(p_hwfn, &p_iov->offset,
  593. CHANNEL_TLV_LIST_END,
  594. sizeof(struct channel_list_end_tlv));
  595. p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
  596. rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
  597. if (rc)
  598. goto exit;
  599. if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
  600. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  601. "Failed to update tunnel parameters\n");
  602. rc = -EINVAL;
  603. }
  604. qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
  605. exit:
  606. qed_vf_pf_req_end(p_hwfn, rc);
  607. return rc;
  608. }
  609. int
  610. qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
  611. struct qed_queue_cid *p_cid,
  612. u16 bd_max_bytes,
  613. dma_addr_t bd_chain_phys_addr,
  614. dma_addr_t cqe_pbl_addr,
  615. u16 cqe_pbl_size, void __iomem **pp_prod)
  616. {
  617. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  618. struct pfvf_start_queue_resp_tlv *resp;
  619. struct vfpf_start_rxq_tlv *req;
  620. u8 rx_qid = p_cid->rel.queue_id;
  621. int rc;
  622. /* clear mailbox and prep first tlv */
  623. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
  624. req->rx_qid = rx_qid;
  625. req->cqe_pbl_addr = cqe_pbl_addr;
  626. req->cqe_pbl_size = cqe_pbl_size;
  627. req->rxq_addr = bd_chain_phys_addr;
  628. req->hw_sb = p_cid->sb_igu_id;
  629. req->sb_index = p_cid->sb_idx;
  630. req->bd_max_bytes = bd_max_bytes;
  631. req->stat_id = -1;
  632. /* If PF is legacy, we'll need to calculate producers ourselves
  633. * as well as clean them.
  634. */
  635. if (p_iov->b_pre_fp_hsi) {
  636. u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
  637. u32 init_prod_val = 0;
  638. *pp_prod = (u8 __iomem *)
  639. p_hwfn->regview +
  640. MSTORM_QZONE_START(p_hwfn->cdev) +
  641. hw_qid * MSTORM_QZONE_SIZE;
  642. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  643. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  644. (u32 *)(&init_prod_val));
  645. }
  646. qed_vf_pf_add_qid(p_hwfn, p_cid);
  647. /* add list termination tlv */
  648. qed_add_tlv(p_hwfn, &p_iov->offset,
  649. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  650. resp = &p_iov->pf2vf_reply->queue_start;
  651. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  652. if (rc)
  653. goto exit;
  654. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  655. rc = -EINVAL;
  656. goto exit;
  657. }
  658. /* Learn the address of the producer from the response */
  659. if (!p_iov->b_pre_fp_hsi) {
  660. u32 init_prod_val = 0;
  661. *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
  662. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  663. "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
  664. rx_qid, *pp_prod, resp->offset);
  665. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  666. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  667. (u32 *)&init_prod_val);
  668. }
  669. exit:
  670. qed_vf_pf_req_end(p_hwfn, rc);
  671. return rc;
  672. }
  673. int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
  674. struct qed_queue_cid *p_cid, bool cqe_completion)
  675. {
  676. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  677. struct vfpf_stop_rxqs_tlv *req;
  678. struct pfvf_def_resp_tlv *resp;
  679. int rc;
  680. /* clear mailbox and prep first tlv */
  681. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
  682. req->rx_qid = p_cid->rel.queue_id;
  683. req->num_rxqs = 1;
  684. req->cqe_completion = cqe_completion;
  685. qed_vf_pf_add_qid(p_hwfn, p_cid);
  686. /* add list termination tlv */
  687. qed_add_tlv(p_hwfn, &p_iov->offset,
  688. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  689. resp = &p_iov->pf2vf_reply->default_resp;
  690. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  691. if (rc)
  692. goto exit;
  693. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  694. rc = -EINVAL;
  695. goto exit;
  696. }
  697. exit:
  698. qed_vf_pf_req_end(p_hwfn, rc);
  699. return rc;
  700. }
  701. int
  702. qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
  703. struct qed_queue_cid *p_cid,
  704. dma_addr_t pbl_addr,
  705. u16 pbl_size, void __iomem **pp_doorbell)
  706. {
  707. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  708. struct pfvf_start_queue_resp_tlv *resp;
  709. struct vfpf_start_txq_tlv *req;
  710. u16 qid = p_cid->rel.queue_id;
  711. int rc;
  712. /* clear mailbox and prep first tlv */
  713. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
  714. req->tx_qid = qid;
  715. /* Tx */
  716. req->pbl_addr = pbl_addr;
  717. req->pbl_size = pbl_size;
  718. req->hw_sb = p_cid->sb_igu_id;
  719. req->sb_index = p_cid->sb_idx;
  720. qed_vf_pf_add_qid(p_hwfn, p_cid);
  721. /* add list termination tlv */
  722. qed_add_tlv(p_hwfn, &p_iov->offset,
  723. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  724. resp = &p_iov->pf2vf_reply->queue_start;
  725. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  726. if (rc)
  727. goto exit;
  728. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  729. rc = -EINVAL;
  730. goto exit;
  731. }
  732. /* Modern PFs provide the actual offsets, while legacy
  733. * provided only the queue id.
  734. */
  735. if (!p_iov->b_pre_fp_hsi) {
  736. *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
  737. } else {
  738. u8 cid = p_iov->acquire_resp.resc.cid[qid];
  739. *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
  740. qed_db_addr_vf(cid,
  741. DQ_DEMS_LEGACY);
  742. }
  743. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  744. "Txq[0x%02x.%02x]: doorbell at %p [offset 0x%08x]\n",
  745. qid, p_cid->qid_usage_idx, *pp_doorbell, resp->offset);
  746. exit:
  747. qed_vf_pf_req_end(p_hwfn, rc);
  748. return rc;
  749. }
  750. int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
  751. {
  752. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  753. struct vfpf_stop_txqs_tlv *req;
  754. struct pfvf_def_resp_tlv *resp;
  755. int rc;
  756. /* clear mailbox and prep first tlv */
  757. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
  758. req->tx_qid = p_cid->rel.queue_id;
  759. req->num_txqs = 1;
  760. qed_vf_pf_add_qid(p_hwfn, p_cid);
  761. /* add list termination tlv */
  762. qed_add_tlv(p_hwfn, &p_iov->offset,
  763. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  764. resp = &p_iov->pf2vf_reply->default_resp;
  765. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  766. if (rc)
  767. goto exit;
  768. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  769. rc = -EINVAL;
  770. goto exit;
  771. }
  772. exit:
  773. qed_vf_pf_req_end(p_hwfn, rc);
  774. return rc;
  775. }
  776. int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
  777. u8 vport_id,
  778. u16 mtu,
  779. u8 inner_vlan_removal,
  780. enum qed_tpa_mode tpa_mode,
  781. u8 max_buffers_per_cqe, u8 only_untagged)
  782. {
  783. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  784. struct vfpf_vport_start_tlv *req;
  785. struct pfvf_def_resp_tlv *resp;
  786. int rc, i;
  787. /* clear mailbox and prep first tlv */
  788. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
  789. req->mtu = mtu;
  790. req->vport_id = vport_id;
  791. req->inner_vlan_removal = inner_vlan_removal;
  792. req->tpa_mode = tpa_mode;
  793. req->max_buffers_per_cqe = max_buffers_per_cqe;
  794. req->only_untagged = only_untagged;
  795. /* status blocks */
  796. for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
  797. struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
  798. if (p_sb)
  799. req->sb_addr[i] = p_sb->sb_phys;
  800. }
  801. /* add list termination tlv */
  802. qed_add_tlv(p_hwfn, &p_iov->offset,
  803. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  804. resp = &p_iov->pf2vf_reply->default_resp;
  805. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  806. if (rc)
  807. goto exit;
  808. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  809. rc = -EINVAL;
  810. goto exit;
  811. }
  812. exit:
  813. qed_vf_pf_req_end(p_hwfn, rc);
  814. return rc;
  815. }
  816. int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
  817. {
  818. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  819. struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
  820. int rc;
  821. /* clear mailbox and prep first tlv */
  822. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
  823. sizeof(struct vfpf_first_tlv));
  824. /* add list termination tlv */
  825. qed_add_tlv(p_hwfn, &p_iov->offset,
  826. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  827. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  828. if (rc)
  829. goto exit;
  830. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  831. rc = -EINVAL;
  832. goto exit;
  833. }
  834. exit:
  835. qed_vf_pf_req_end(p_hwfn, rc);
  836. return rc;
  837. }
  838. static bool
  839. qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
  840. struct qed_sp_vport_update_params *p_data,
  841. u16 tlv)
  842. {
  843. switch (tlv) {
  844. case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
  845. return !!(p_data->update_vport_active_rx_flg ||
  846. p_data->update_vport_active_tx_flg);
  847. case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
  848. return !!p_data->update_tx_switching_flg;
  849. case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
  850. return !!p_data->update_inner_vlan_removal_flg;
  851. case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
  852. return !!p_data->update_accept_any_vlan_flg;
  853. case CHANNEL_TLV_VPORT_UPDATE_MCAST:
  854. return !!p_data->update_approx_mcast_flg;
  855. case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
  856. return !!(p_data->accept_flags.update_rx_mode_config ||
  857. p_data->accept_flags.update_tx_mode_config);
  858. case CHANNEL_TLV_VPORT_UPDATE_RSS:
  859. return !!p_data->rss_params;
  860. case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
  861. return !!p_data->sge_tpa_params;
  862. default:
  863. DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
  864. tlv);
  865. return false;
  866. }
  867. }
  868. static void
  869. qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
  870. struct qed_sp_vport_update_params *p_data)
  871. {
  872. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  873. struct pfvf_def_resp_tlv *p_resp;
  874. u16 tlv;
  875. for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
  876. tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
  877. if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
  878. continue;
  879. p_resp = (struct pfvf_def_resp_tlv *)
  880. qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
  881. tlv);
  882. if (p_resp && p_resp->hdr.status)
  883. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  884. "TLV[%d] Configuration %s\n",
  885. tlv,
  886. (p_resp && p_resp->hdr.status) ? "succeeded"
  887. : "failed");
  888. }
  889. }
  890. int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
  891. struct qed_sp_vport_update_params *p_params)
  892. {
  893. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  894. struct vfpf_vport_update_tlv *req;
  895. struct pfvf_def_resp_tlv *resp;
  896. u8 update_rx, update_tx;
  897. u32 resp_size = 0;
  898. u16 size, tlv;
  899. int rc;
  900. resp = &p_iov->pf2vf_reply->default_resp;
  901. resp_size = sizeof(*resp);
  902. update_rx = p_params->update_vport_active_rx_flg;
  903. update_tx = p_params->update_vport_active_tx_flg;
  904. /* clear mailbox and prep header tlv */
  905. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
  906. /* Prepare extended tlvs */
  907. if (update_rx || update_tx) {
  908. struct vfpf_vport_update_activate_tlv *p_act_tlv;
  909. size = sizeof(struct vfpf_vport_update_activate_tlv);
  910. p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  911. CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
  912. size);
  913. resp_size += sizeof(struct pfvf_def_resp_tlv);
  914. if (update_rx) {
  915. p_act_tlv->update_rx = update_rx;
  916. p_act_tlv->active_rx = p_params->vport_active_rx_flg;
  917. }
  918. if (update_tx) {
  919. p_act_tlv->update_tx = update_tx;
  920. p_act_tlv->active_tx = p_params->vport_active_tx_flg;
  921. }
  922. }
  923. if (p_params->update_tx_switching_flg) {
  924. struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
  925. size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
  926. tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
  927. p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  928. tlv, size);
  929. resp_size += sizeof(struct pfvf_def_resp_tlv);
  930. p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
  931. }
  932. if (p_params->update_approx_mcast_flg) {
  933. struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
  934. size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
  935. p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  936. CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
  937. resp_size += sizeof(struct pfvf_def_resp_tlv);
  938. memcpy(p_mcast_tlv->bins, p_params->bins,
  939. sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
  940. }
  941. update_rx = p_params->accept_flags.update_rx_mode_config;
  942. update_tx = p_params->accept_flags.update_tx_mode_config;
  943. if (update_rx || update_tx) {
  944. struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
  945. tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
  946. size = sizeof(struct vfpf_vport_update_accept_param_tlv);
  947. p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
  948. resp_size += sizeof(struct pfvf_def_resp_tlv);
  949. if (update_rx) {
  950. p_accept_tlv->update_rx_mode = update_rx;
  951. p_accept_tlv->rx_accept_filter =
  952. p_params->accept_flags.rx_accept_filter;
  953. }
  954. if (update_tx) {
  955. p_accept_tlv->update_tx_mode = update_tx;
  956. p_accept_tlv->tx_accept_filter =
  957. p_params->accept_flags.tx_accept_filter;
  958. }
  959. }
  960. if (p_params->rss_params) {
  961. struct qed_rss_params *rss_params = p_params->rss_params;
  962. struct vfpf_vport_update_rss_tlv *p_rss_tlv;
  963. int i, table_size;
  964. size = sizeof(struct vfpf_vport_update_rss_tlv);
  965. p_rss_tlv = qed_add_tlv(p_hwfn,
  966. &p_iov->offset,
  967. CHANNEL_TLV_VPORT_UPDATE_RSS, size);
  968. resp_size += sizeof(struct pfvf_def_resp_tlv);
  969. if (rss_params->update_rss_config)
  970. p_rss_tlv->update_rss_flags |=
  971. VFPF_UPDATE_RSS_CONFIG_FLAG;
  972. if (rss_params->update_rss_capabilities)
  973. p_rss_tlv->update_rss_flags |=
  974. VFPF_UPDATE_RSS_CAPS_FLAG;
  975. if (rss_params->update_rss_ind_table)
  976. p_rss_tlv->update_rss_flags |=
  977. VFPF_UPDATE_RSS_IND_TABLE_FLAG;
  978. if (rss_params->update_rss_key)
  979. p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
  980. p_rss_tlv->rss_enable = rss_params->rss_enable;
  981. p_rss_tlv->rss_caps = rss_params->rss_caps;
  982. p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
  983. table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
  984. 1 << p_rss_tlv->rss_table_size_log);
  985. for (i = 0; i < table_size; i++) {
  986. struct qed_queue_cid *p_queue;
  987. p_queue = rss_params->rss_ind_table[i];
  988. p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
  989. }
  990. memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
  991. sizeof(rss_params->rss_key));
  992. }
  993. if (p_params->update_accept_any_vlan_flg) {
  994. struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
  995. size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
  996. tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
  997. p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
  998. resp_size += sizeof(struct pfvf_def_resp_tlv);
  999. p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
  1000. p_any_vlan_tlv->update_accept_any_vlan_flg =
  1001. p_params->update_accept_any_vlan_flg;
  1002. }
  1003. /* add list termination tlv */
  1004. qed_add_tlv(p_hwfn, &p_iov->offset,
  1005. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  1006. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
  1007. if (rc)
  1008. goto exit;
  1009. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  1010. rc = -EINVAL;
  1011. goto exit;
  1012. }
  1013. qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
  1014. exit:
  1015. qed_vf_pf_req_end(p_hwfn, rc);
  1016. return rc;
  1017. }
  1018. int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
  1019. {
  1020. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1021. struct pfvf_def_resp_tlv *resp;
  1022. struct vfpf_first_tlv *req;
  1023. int rc;
  1024. /* clear mailbox and prep first tlv */
  1025. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
  1026. /* add list termination tlv */
  1027. qed_add_tlv(p_hwfn, &p_iov->offset,
  1028. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  1029. resp = &p_iov->pf2vf_reply->default_resp;
  1030. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  1031. if (rc)
  1032. goto exit;
  1033. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  1034. rc = -EAGAIN;
  1035. goto exit;
  1036. }
  1037. p_hwfn->b_int_enabled = 0;
  1038. exit:
  1039. qed_vf_pf_req_end(p_hwfn, rc);
  1040. return rc;
  1041. }
  1042. void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
  1043. struct qed_filter_mcast *p_filter_cmd)
  1044. {
  1045. struct qed_sp_vport_update_params sp_params;
  1046. int i;
  1047. memset(&sp_params, 0, sizeof(sp_params));
  1048. sp_params.update_approx_mcast_flg = 1;
  1049. if (p_filter_cmd->opcode == QED_FILTER_ADD) {
  1050. for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
  1051. u32 bit;
  1052. bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
  1053. __set_bit(bit, sp_params.bins);
  1054. }
  1055. }
  1056. qed_vf_pf_vport_update(p_hwfn, &sp_params);
  1057. }
  1058. int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
  1059. struct qed_filter_ucast *p_ucast)
  1060. {
  1061. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1062. struct vfpf_ucast_filter_tlv *req;
  1063. struct pfvf_def_resp_tlv *resp;
  1064. int rc;
  1065. /* clear mailbox and prep first tlv */
  1066. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
  1067. req->opcode = (u8) p_ucast->opcode;
  1068. req->type = (u8) p_ucast->type;
  1069. memcpy(req->mac, p_ucast->mac, ETH_ALEN);
  1070. req->vlan = p_ucast->vlan;
  1071. /* add list termination tlv */
  1072. qed_add_tlv(p_hwfn, &p_iov->offset,
  1073. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  1074. resp = &p_iov->pf2vf_reply->default_resp;
  1075. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  1076. if (rc)
  1077. goto exit;
  1078. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  1079. rc = -EAGAIN;
  1080. goto exit;
  1081. }
  1082. exit:
  1083. qed_vf_pf_req_end(p_hwfn, rc);
  1084. return rc;
  1085. }
  1086. int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
  1087. {
  1088. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1089. struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
  1090. int rc;
  1091. /* clear mailbox and prep first tlv */
  1092. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
  1093. sizeof(struct vfpf_first_tlv));
  1094. /* add list termination tlv */
  1095. qed_add_tlv(p_hwfn, &p_iov->offset,
  1096. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  1097. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  1098. if (rc)
  1099. goto exit;
  1100. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  1101. rc = -EINVAL;
  1102. goto exit;
  1103. }
  1104. exit:
  1105. qed_vf_pf_req_end(p_hwfn, rc);
  1106. return rc;
  1107. }
  1108. int qed_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
  1109. u16 *p_coal, struct qed_queue_cid *p_cid)
  1110. {
  1111. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1112. struct pfvf_read_coal_resp_tlv *resp;
  1113. struct vfpf_read_coal_req_tlv *req;
  1114. int rc;
  1115. /* clear mailbox and prep header tlv */
  1116. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ, sizeof(*req));
  1117. req->qid = p_cid->rel.queue_id;
  1118. req->is_rx = p_cid->b_is_rx ? 1 : 0;
  1119. qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
  1120. sizeof(struct channel_list_end_tlv));
  1121. resp = &p_iov->pf2vf_reply->read_coal_resp;
  1122. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  1123. if (rc)
  1124. goto exit;
  1125. if (resp->hdr.status != PFVF_STATUS_SUCCESS)
  1126. goto exit;
  1127. *p_coal = resp->coal;
  1128. exit:
  1129. qed_vf_pf_req_end(p_hwfn, rc);
  1130. return rc;
  1131. }
  1132. int
  1133. qed_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
  1134. u8 *p_mac)
  1135. {
  1136. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1137. struct vfpf_bulletin_update_mac_tlv *p_req;
  1138. struct pfvf_def_resp_tlv *p_resp;
  1139. int rc;
  1140. if (!p_mac)
  1141. return -EINVAL;
  1142. /* clear mailbox and prep header tlv */
  1143. p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_BULLETIN_UPDATE_MAC,
  1144. sizeof(*p_req));
  1145. ether_addr_copy(p_req->mac, p_mac);
  1146. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1147. "Requesting bulletin update for MAC[%pM]\n", p_mac);
  1148. /* add list termination tlv */
  1149. qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
  1150. sizeof(struct channel_list_end_tlv));
  1151. p_resp = &p_iov->pf2vf_reply->default_resp;
  1152. rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
  1153. qed_vf_pf_req_end(p_hwfn, rc);
  1154. return rc;
  1155. }
  1156. int
  1157. qed_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
  1158. u16 rx_coal, u16 tx_coal, struct qed_queue_cid *p_cid)
  1159. {
  1160. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1161. struct vfpf_update_coalesce *req;
  1162. struct pfvf_def_resp_tlv *resp;
  1163. int rc;
  1164. /* clear mailbox and prep header tlv */
  1165. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE, sizeof(*req));
  1166. req->rx_coal = rx_coal;
  1167. req->tx_coal = tx_coal;
  1168. req->qid = p_cid->rel.queue_id;
  1169. DP_VERBOSE(p_hwfn,
  1170. QED_MSG_IOV,
  1171. "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
  1172. rx_coal, tx_coal, req->qid);
  1173. /* add list termination tlv */
  1174. qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
  1175. sizeof(struct channel_list_end_tlv));
  1176. resp = &p_iov->pf2vf_reply->default_resp;
  1177. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  1178. if (rc)
  1179. goto exit;
  1180. if (resp->hdr.status != PFVF_STATUS_SUCCESS)
  1181. goto exit;
  1182. if (rx_coal)
  1183. p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
  1184. if (tx_coal)
  1185. p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
  1186. exit:
  1187. qed_vf_pf_req_end(p_hwfn, rc);
  1188. return rc;
  1189. }
  1190. u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
  1191. {
  1192. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1193. if (!p_iov) {
  1194. DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
  1195. return 0;
  1196. }
  1197. return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
  1198. }
  1199. void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
  1200. u16 sb_id, struct qed_sb_info *p_sb)
  1201. {
  1202. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1203. if (!p_iov) {
  1204. DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
  1205. return;
  1206. }
  1207. if (sb_id >= PFVF_MAX_SBS_PER_VF) {
  1208. DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
  1209. return;
  1210. }
  1211. p_iov->sbs_info[sb_id] = p_sb;
  1212. }
  1213. int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
  1214. {
  1215. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  1216. struct qed_bulletin_content shadow;
  1217. u32 crc, crc_size;
  1218. crc_size = sizeof(p_iov->bulletin.p_virt->crc);
  1219. *p_change = 0;
  1220. /* Need to guarantee PF is not in the middle of writing it */
  1221. memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
  1222. /* If version did not update, no need to do anything */
  1223. if (shadow.version == p_iov->bulletin_shadow.version)
  1224. return 0;
  1225. /* Verify the bulletin we see is valid */
  1226. crc = crc32(0, (u8 *)&shadow + crc_size,
  1227. p_iov->bulletin.size - crc_size);
  1228. if (crc != shadow.crc)
  1229. return -EAGAIN;
  1230. /* Set the shadow bulletin and process it */
  1231. memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
  1232. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1233. "Read a bulletin update %08x\n", shadow.version);
  1234. *p_change = 1;
  1235. return 0;
  1236. }
  1237. void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
  1238. struct qed_mcp_link_params *p_params,
  1239. struct qed_bulletin_content *p_bulletin)
  1240. {
  1241. memset(p_params, 0, sizeof(*p_params));
  1242. p_params->speed.autoneg = p_bulletin->req_autoneg;
  1243. p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
  1244. p_params->speed.forced_speed = p_bulletin->req_forced_speed;
  1245. p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
  1246. p_params->pause.forced_rx = p_bulletin->req_forced_rx;
  1247. p_params->pause.forced_tx = p_bulletin->req_forced_tx;
  1248. p_params->loopback_mode = p_bulletin->req_loopback;
  1249. }
  1250. void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
  1251. struct qed_mcp_link_params *params)
  1252. {
  1253. __qed_vf_get_link_params(p_hwfn, params,
  1254. &(p_hwfn->vf_iov_info->bulletin_shadow));
  1255. }
  1256. void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
  1257. struct qed_mcp_link_state *p_link,
  1258. struct qed_bulletin_content *p_bulletin)
  1259. {
  1260. memset(p_link, 0, sizeof(*p_link));
  1261. p_link->link_up = p_bulletin->link_up;
  1262. p_link->speed = p_bulletin->speed;
  1263. p_link->full_duplex = p_bulletin->full_duplex;
  1264. p_link->an = p_bulletin->autoneg;
  1265. p_link->an_complete = p_bulletin->autoneg_complete;
  1266. p_link->parallel_detection = p_bulletin->parallel_detection;
  1267. p_link->pfc_enabled = p_bulletin->pfc_enabled;
  1268. p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
  1269. p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
  1270. p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
  1271. p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
  1272. p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
  1273. }
  1274. void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
  1275. struct qed_mcp_link_state *link)
  1276. {
  1277. __qed_vf_get_link_state(p_hwfn, link,
  1278. &(p_hwfn->vf_iov_info->bulletin_shadow));
  1279. }
  1280. void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
  1281. struct qed_mcp_link_capabilities *p_link_caps,
  1282. struct qed_bulletin_content *p_bulletin)
  1283. {
  1284. memset(p_link_caps, 0, sizeof(*p_link_caps));
  1285. p_link_caps->speed_capabilities = p_bulletin->capability_speed;
  1286. }
  1287. void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
  1288. struct qed_mcp_link_capabilities *p_link_caps)
  1289. {
  1290. __qed_vf_get_link_caps(p_hwfn, p_link_caps,
  1291. &(p_hwfn->vf_iov_info->bulletin_shadow));
  1292. }
  1293. void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
  1294. {
  1295. *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
  1296. }
  1297. void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs)
  1298. {
  1299. *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
  1300. }
  1301. void qed_vf_get_num_cids(struct qed_hwfn *p_hwfn, u8 *num_cids)
  1302. {
  1303. *num_cids = p_hwfn->vf_iov_info->acquire_resp.resc.num_cids;
  1304. }
  1305. void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
  1306. {
  1307. memcpy(port_mac,
  1308. p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
  1309. }
  1310. void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
  1311. {
  1312. struct qed_vf_iov *p_vf;
  1313. p_vf = p_hwfn->vf_iov_info;
  1314. *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
  1315. }
  1316. void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
  1317. {
  1318. struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
  1319. *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
  1320. }
  1321. bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
  1322. {
  1323. struct qed_bulletin_content *bulletin;
  1324. bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
  1325. if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
  1326. return true;
  1327. /* Forbid VF from changing a MAC enforced by PF */
  1328. if (ether_addr_equal(bulletin->mac, mac))
  1329. return false;
  1330. return false;
  1331. }
  1332. static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
  1333. u8 *dst_mac, u8 *p_is_forced)
  1334. {
  1335. struct qed_bulletin_content *bulletin;
  1336. bulletin = &hwfn->vf_iov_info->bulletin_shadow;
  1337. if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
  1338. if (p_is_forced)
  1339. *p_is_forced = 1;
  1340. } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
  1341. if (p_is_forced)
  1342. *p_is_forced = 0;
  1343. } else {
  1344. return false;
  1345. }
  1346. ether_addr_copy(dst_mac, bulletin->mac);
  1347. return true;
  1348. }
  1349. static void
  1350. qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
  1351. u16 *p_vxlan_port, u16 *p_geneve_port)
  1352. {
  1353. struct qed_bulletin_content *p_bulletin;
  1354. p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
  1355. *p_vxlan_port = p_bulletin->vxlan_udp_port;
  1356. *p_geneve_port = p_bulletin->geneve_udp_port;
  1357. }
  1358. void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
  1359. u16 *fw_major, u16 *fw_minor,
  1360. u16 *fw_rev, u16 *fw_eng)
  1361. {
  1362. struct pf_vf_pfdev_info *info;
  1363. info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
  1364. *fw_major = info->fw_major;
  1365. *fw_minor = info->fw_minor;
  1366. *fw_rev = info->fw_rev;
  1367. *fw_eng = info->fw_eng;
  1368. }
  1369. static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
  1370. {
  1371. struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
  1372. u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
  1373. void *cookie = hwfn->cdev->ops_cookie;
  1374. u16 vxlan_port, geneve_port;
  1375. qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
  1376. is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
  1377. &is_mac_forced);
  1378. if (is_mac_exist && cookie)
  1379. ops->force_mac(cookie, mac, !!is_mac_forced);
  1380. ops->ports_update(cookie, vxlan_port, geneve_port);
  1381. /* Always update link configuration according to bulletin */
  1382. qed_link_update(hwfn);
  1383. }
  1384. void qed_iov_vf_task(struct work_struct *work)
  1385. {
  1386. struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
  1387. iov_task.work);
  1388. u8 change = 0;
  1389. if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
  1390. return;
  1391. /* Handle bulletin board changes */
  1392. qed_vf_read_bulletin(hwfn, &change);
  1393. if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
  1394. &hwfn->iov_task_flags))
  1395. change = 1;
  1396. if (change)
  1397. qed_handle_bulletin_change(hwfn);
  1398. /* As VF is polling bulletin board, need to constantly re-schedule */
  1399. queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
  1400. }