qed_vf.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #include <linux/crc32.h>
  9. #include <linux/etherdevice.h>
  10. #include "qed.h"
  11. #include "qed_sriov.h"
  12. #include "qed_vf.h"
  13. static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
  14. {
  15. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  16. void *p_tlv;
  17. /* This lock is released when we receive PF's response
  18. * in qed_send_msg2pf().
  19. * So, qed_vf_pf_prep() and qed_send_msg2pf()
  20. * must come in sequence.
  21. */
  22. mutex_lock(&(p_iov->mutex));
  23. DP_VERBOSE(p_hwfn,
  24. QED_MSG_IOV,
  25. "preparing to send 0x%04x tlv over vf pf channel\n",
  26. type);
  27. /* Reset Requst offset */
  28. p_iov->offset = (u8 *)p_iov->vf2pf_request;
  29. /* Clear mailbox - both request and reply */
  30. memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
  31. memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
  32. /* Init type and length */
  33. p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
  34. /* Init first tlv header */
  35. ((struct vfpf_first_tlv *)p_tlv)->reply_address =
  36. (u64)p_iov->pf2vf_reply_phys;
  37. return p_tlv;
  38. }
  39. static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
  40. {
  41. union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
  42. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  43. "VF request status = 0x%x, PF reply status = 0x%x\n",
  44. req_status, resp->default_resp.hdr.status);
  45. mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
  46. }
  47. static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
  48. {
  49. union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
  50. struct ustorm_trigger_vf_zone trigger;
  51. struct ustorm_vf_zone *zone_data;
  52. int rc = 0, time = 100;
  53. zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
  54. /* output tlvs list */
  55. qed_dp_tlv_list(p_hwfn, p_req);
  56. /* need to add the END TLV to the message size */
  57. resp_size += sizeof(struct channel_list_end_tlv);
  58. /* Send TLVs over HW channel */
  59. memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
  60. trigger.vf_pf_msg_valid = 1;
  61. DP_VERBOSE(p_hwfn,
  62. QED_MSG_IOV,
  63. "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
  64. GET_FIELD(p_hwfn->hw_info.concrete_fid,
  65. PXP_CONCRETE_FID_PFID),
  66. upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
  67. lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
  68. &zone_data->non_trigger.vf_pf_msg_addr,
  69. *((u32 *)&trigger), &zone_data->trigger);
  70. REG_WR(p_hwfn,
  71. (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
  72. lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
  73. REG_WR(p_hwfn,
  74. (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
  75. upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
  76. /* The message data must be written first, to prevent trigger before
  77. * data is written.
  78. */
  79. wmb();
  80. REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
  81. /* When PF would be done with the response, it would write back to the
  82. * `done' address. Poll until then.
  83. */
  84. while ((!*done) && time) {
  85. msleep(25);
  86. time--;
  87. }
  88. if (!*done) {
  89. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  90. "VF <-- PF Timeout [Type %d]\n",
  91. p_req->first_tlv.tl.type);
  92. rc = -EBUSY;
  93. } else {
  94. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  95. "PF response: %d [Type %d]\n",
  96. *done, p_req->first_tlv.tl.type);
  97. }
  98. return rc;
  99. }
  100. #define VF_ACQUIRE_THRESH 3
  101. static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
  102. struct vf_pf_resc_request *p_req,
  103. struct pf_vf_resc *p_resp)
  104. {
  105. DP_VERBOSE(p_hwfn,
  106. QED_MSG_IOV,
  107. "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]. Try PF recommended amount\n",
  108. p_req->num_rxqs,
  109. p_resp->num_rxqs,
  110. p_req->num_rxqs,
  111. p_resp->num_txqs,
  112. p_req->num_sbs,
  113. p_resp->num_sbs,
  114. p_req->num_mac_filters,
  115. p_resp->num_mac_filters,
  116. p_req->num_vlan_filters,
  117. p_resp->num_vlan_filters,
  118. p_req->num_mc_filters, p_resp->num_mc_filters);
  119. /* humble our request */
  120. p_req->num_txqs = p_resp->num_txqs;
  121. p_req->num_rxqs = p_resp->num_rxqs;
  122. p_req->num_sbs = p_resp->num_sbs;
  123. p_req->num_mac_filters = p_resp->num_mac_filters;
  124. p_req->num_vlan_filters = p_resp->num_vlan_filters;
  125. p_req->num_mc_filters = p_resp->num_mc_filters;
  126. }
  127. static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
  128. {
  129. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  130. struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
  131. struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
  132. struct vf_pf_resc_request *p_resc;
  133. bool resources_acquired = false;
  134. struct vfpf_acquire_tlv *req;
  135. int rc = 0, attempts = 0;
  136. /* clear mailbox and prep first tlv */
  137. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  138. p_resc = &req->resc_request;
  139. /* starting filling the request */
  140. req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
  141. p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
  142. p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
  143. p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
  144. p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
  145. p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
  146. req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
  147. req->vfdev_info.fw_major = FW_MAJOR_VERSION;
  148. req->vfdev_info.fw_minor = FW_MINOR_VERSION;
  149. req->vfdev_info.fw_revision = FW_REVISION_VERSION;
  150. req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
  151. req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
  152. req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
  153. /* Fill capability field with any non-deprecated config we support */
  154. req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
  155. /* pf 2 vf bulletin board address */
  156. req->bulletin_addr = p_iov->bulletin.phys;
  157. req->bulletin_size = p_iov->bulletin.size;
  158. /* add list termination tlv */
  159. qed_add_tlv(p_hwfn, &p_iov->offset,
  160. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  161. while (!resources_acquired) {
  162. DP_VERBOSE(p_hwfn,
  163. QED_MSG_IOV, "attempting to acquire resources\n");
  164. /* Clear response buffer, as this might be a re-send */
  165. memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
  166. /* send acquire request */
  167. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  168. if (rc)
  169. return rc;
  170. /* copy acquire response from buffer to p_hwfn */
  171. memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
  172. attempts++;
  173. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  174. /* PF agrees to allocate our resources */
  175. if (!(resp->pfdev_info.capabilities &
  176. PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
  177. /* It's possible legacy PF mistakenly accepted;
  178. * but we don't care - simply mark it as
  179. * legacy and continue.
  180. */
  181. req->vfdev_info.capabilities |=
  182. VFPF_ACQUIRE_CAP_PRE_FP_HSI;
  183. }
  184. DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
  185. resources_acquired = true;
  186. } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
  187. attempts < VF_ACQUIRE_THRESH) {
  188. qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
  189. &resp->resc);
  190. } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
  191. if (pfdev_info->major_fp_hsi &&
  192. (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
  193. DP_NOTICE(p_hwfn,
  194. "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
  195. pfdev_info->major_fp_hsi,
  196. pfdev_info->minor_fp_hsi,
  197. ETH_HSI_VER_MAJOR,
  198. ETH_HSI_VER_MINOR,
  199. pfdev_info->major_fp_hsi);
  200. rc = -EINVAL;
  201. goto exit;
  202. }
  203. if (!pfdev_info->major_fp_hsi) {
  204. if (req->vfdev_info.capabilities &
  205. VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
  206. DP_NOTICE(p_hwfn,
  207. "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
  208. rc = -EINVAL;
  209. goto exit;
  210. } else {
  211. DP_INFO(p_hwfn,
  212. "PF is old - try re-acquire to see if it supports FW-version override\n");
  213. req->vfdev_info.capabilities |=
  214. VFPF_ACQUIRE_CAP_PRE_FP_HSI;
  215. continue;
  216. }
  217. }
  218. /* If PF/VF are using same Major, PF must have had
  219. * it's reasons. Simply fail.
  220. */
  221. DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
  222. rc = -EINVAL;
  223. goto exit;
  224. } else {
  225. DP_ERR(p_hwfn,
  226. "PF returned error %d to VF acquisition request\n",
  227. resp->hdr.status);
  228. rc = -EAGAIN;
  229. goto exit;
  230. }
  231. }
  232. /* Mark the PF as legacy, if needed */
  233. if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
  234. p_iov->b_pre_fp_hsi = true;
  235. /* Update bulletin board size with response from PF */
  236. p_iov->bulletin.size = resp->bulletin_size;
  237. /* get HW info */
  238. p_hwfn->cdev->type = resp->pfdev_info.dev_type;
  239. p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
  240. p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
  241. /* Learn of the possibility of CMT */
  242. if (IS_LEAD_HWFN(p_hwfn)) {
  243. if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
  244. DP_NOTICE(p_hwfn, "100g VF\n");
  245. p_hwfn->cdev->num_hwfns = 2;
  246. }
  247. }
  248. if (!p_iov->b_pre_fp_hsi &&
  249. ETH_HSI_VER_MINOR &&
  250. (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
  251. DP_INFO(p_hwfn,
  252. "PF is using older fastpath HSI; %02x.%02x is configured\n",
  253. ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
  254. }
  255. exit:
  256. qed_vf_pf_req_end(p_hwfn, rc);
  257. return rc;
  258. }
  259. int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
  260. {
  261. struct qed_vf_iov *p_iov;
  262. u32 reg;
  263. /* Set number of hwfns - might be overriden once leading hwfn learns
  264. * actual configuration from PF.
  265. */
  266. if (IS_LEAD_HWFN(p_hwfn))
  267. p_hwfn->cdev->num_hwfns = 1;
  268. /* Set the doorbell bar. Assumption: regview is set */
  269. p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
  270. PXP_VF_BAR0_START_DQ;
  271. reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
  272. p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
  273. reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
  274. p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
  275. /* Allocate vf sriov info */
  276. p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
  277. if (!p_iov)
  278. return -ENOMEM;
  279. /* Allocate vf2pf msg */
  280. p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  281. sizeof(union vfpf_tlvs),
  282. &p_iov->vf2pf_request_phys,
  283. GFP_KERNEL);
  284. if (!p_iov->vf2pf_request)
  285. goto free_p_iov;
  286. p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  287. sizeof(union pfvf_tlvs),
  288. &p_iov->pf2vf_reply_phys,
  289. GFP_KERNEL);
  290. if (!p_iov->pf2vf_reply)
  291. goto free_vf2pf_request;
  292. DP_VERBOSE(p_hwfn,
  293. QED_MSG_IOV,
  294. "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
  295. p_iov->vf2pf_request,
  296. (u64) p_iov->vf2pf_request_phys,
  297. p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
  298. /* Allocate Bulletin board */
  299. p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
  300. p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  301. p_iov->bulletin.size,
  302. &p_iov->bulletin.phys,
  303. GFP_KERNEL);
  304. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  305. "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
  306. p_iov->bulletin.p_virt,
  307. (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
  308. mutex_init(&p_iov->mutex);
  309. p_hwfn->vf_iov_info = p_iov;
  310. p_hwfn->hw_info.personality = QED_PCI_ETH;
  311. return qed_vf_pf_acquire(p_hwfn);
  312. free_vf2pf_request:
  313. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  314. sizeof(union vfpf_tlvs),
  315. p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
  316. free_p_iov:
  317. kfree(p_iov);
  318. return -ENOMEM;
  319. }
  320. #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
  321. #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
  322. (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
  323. int
  324. qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
  325. struct qed_queue_cid *p_cid,
  326. u16 bd_max_bytes,
  327. dma_addr_t bd_chain_phys_addr,
  328. dma_addr_t cqe_pbl_addr,
  329. u16 cqe_pbl_size, void __iomem **pp_prod)
  330. {
  331. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  332. struct pfvf_start_queue_resp_tlv *resp;
  333. struct vfpf_start_rxq_tlv *req;
  334. u8 rx_qid = p_cid->rel.queue_id;
  335. int rc;
  336. /* clear mailbox and prep first tlv */
  337. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
  338. req->rx_qid = rx_qid;
  339. req->cqe_pbl_addr = cqe_pbl_addr;
  340. req->cqe_pbl_size = cqe_pbl_size;
  341. req->rxq_addr = bd_chain_phys_addr;
  342. req->hw_sb = p_cid->rel.sb;
  343. req->sb_index = p_cid->rel.sb_idx;
  344. req->bd_max_bytes = bd_max_bytes;
  345. req->stat_id = -1;
  346. /* If PF is legacy, we'll need to calculate producers ourselves
  347. * as well as clean them.
  348. */
  349. if (p_iov->b_pre_fp_hsi) {
  350. u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
  351. u32 init_prod_val = 0;
  352. *pp_prod = (u8 __iomem *)
  353. p_hwfn->regview +
  354. MSTORM_QZONE_START(p_hwfn->cdev) +
  355. hw_qid * MSTORM_QZONE_SIZE;
  356. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  357. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  358. (u32 *)(&init_prod_val));
  359. }
  360. /* add list termination tlv */
  361. qed_add_tlv(p_hwfn, &p_iov->offset,
  362. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  363. resp = &p_iov->pf2vf_reply->queue_start;
  364. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  365. if (rc)
  366. goto exit;
  367. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  368. rc = -EINVAL;
  369. goto exit;
  370. }
  371. /* Learn the address of the producer from the response */
  372. if (!p_iov->b_pre_fp_hsi) {
  373. u32 init_prod_val = 0;
  374. *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
  375. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  376. "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
  377. rx_qid, *pp_prod, resp->offset);
  378. /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
  379. __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
  380. (u32 *)&init_prod_val);
  381. }
  382. exit:
  383. qed_vf_pf_req_end(p_hwfn, rc);
  384. return rc;
  385. }
  386. int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
  387. struct qed_queue_cid *p_cid, bool cqe_completion)
  388. {
  389. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  390. struct vfpf_stop_rxqs_tlv *req;
  391. struct pfvf_def_resp_tlv *resp;
  392. int rc;
  393. /* clear mailbox and prep first tlv */
  394. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
  395. req->rx_qid = p_cid->rel.queue_id;
  396. req->num_rxqs = 1;
  397. req->cqe_completion = cqe_completion;
  398. /* add list termination tlv */
  399. qed_add_tlv(p_hwfn, &p_iov->offset,
  400. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  401. resp = &p_iov->pf2vf_reply->default_resp;
  402. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  403. if (rc)
  404. goto exit;
  405. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  406. rc = -EINVAL;
  407. goto exit;
  408. }
  409. exit:
  410. qed_vf_pf_req_end(p_hwfn, rc);
  411. return rc;
  412. }
  413. int
  414. qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
  415. struct qed_queue_cid *p_cid,
  416. dma_addr_t pbl_addr,
  417. u16 pbl_size, void __iomem **pp_doorbell)
  418. {
  419. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  420. struct pfvf_start_queue_resp_tlv *resp;
  421. struct vfpf_start_txq_tlv *req;
  422. u16 qid = p_cid->rel.queue_id;
  423. int rc;
  424. /* clear mailbox and prep first tlv */
  425. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
  426. req->tx_qid = qid;
  427. /* Tx */
  428. req->pbl_addr = pbl_addr;
  429. req->pbl_size = pbl_size;
  430. req->hw_sb = p_cid->rel.sb;
  431. req->sb_index = p_cid->rel.sb_idx;
  432. /* add list termination tlv */
  433. qed_add_tlv(p_hwfn, &p_iov->offset,
  434. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  435. resp = &p_iov->pf2vf_reply->queue_start;
  436. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  437. if (rc)
  438. goto exit;
  439. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  440. rc = -EINVAL;
  441. goto exit;
  442. }
  443. /* Modern PFs provide the actual offsets, while legacy
  444. * provided only the queue id.
  445. */
  446. if (!p_iov->b_pre_fp_hsi) {
  447. *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
  448. } else {
  449. u8 cid = p_iov->acquire_resp.resc.cid[qid];
  450. *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
  451. qed_db_addr_vf(cid,
  452. DQ_DEMS_LEGACY);
  453. }
  454. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  455. "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
  456. qid, *pp_doorbell, resp->offset);
  457. exit:
  458. qed_vf_pf_req_end(p_hwfn, rc);
  459. return rc;
  460. }
  461. int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
  462. {
  463. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  464. struct vfpf_stop_txqs_tlv *req;
  465. struct pfvf_def_resp_tlv *resp;
  466. int rc;
  467. /* clear mailbox and prep first tlv */
  468. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
  469. req->tx_qid = p_cid->rel.queue_id;
  470. req->num_txqs = 1;
  471. /* add list termination tlv */
  472. qed_add_tlv(p_hwfn, &p_iov->offset,
  473. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  474. resp = &p_iov->pf2vf_reply->default_resp;
  475. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  476. if (rc)
  477. goto exit;
  478. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  479. rc = -EINVAL;
  480. goto exit;
  481. }
  482. exit:
  483. qed_vf_pf_req_end(p_hwfn, rc);
  484. return rc;
  485. }
  486. int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
  487. u8 vport_id,
  488. u16 mtu,
  489. u8 inner_vlan_removal,
  490. enum qed_tpa_mode tpa_mode,
  491. u8 max_buffers_per_cqe, u8 only_untagged)
  492. {
  493. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  494. struct vfpf_vport_start_tlv *req;
  495. struct pfvf_def_resp_tlv *resp;
  496. int rc, i;
  497. /* clear mailbox and prep first tlv */
  498. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
  499. req->mtu = mtu;
  500. req->vport_id = vport_id;
  501. req->inner_vlan_removal = inner_vlan_removal;
  502. req->tpa_mode = tpa_mode;
  503. req->max_buffers_per_cqe = max_buffers_per_cqe;
  504. req->only_untagged = only_untagged;
  505. /* status blocks */
  506. for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
  507. if (p_hwfn->sbs_info[i])
  508. req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
  509. /* add list termination tlv */
  510. qed_add_tlv(p_hwfn, &p_iov->offset,
  511. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  512. resp = &p_iov->pf2vf_reply->default_resp;
  513. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  514. if (rc)
  515. goto exit;
  516. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  517. rc = -EINVAL;
  518. goto exit;
  519. }
  520. exit:
  521. qed_vf_pf_req_end(p_hwfn, rc);
  522. return rc;
  523. }
  524. int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
  525. {
  526. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  527. struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
  528. int rc;
  529. /* clear mailbox and prep first tlv */
  530. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
  531. sizeof(struct vfpf_first_tlv));
  532. /* add list termination tlv */
  533. qed_add_tlv(p_hwfn, &p_iov->offset,
  534. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  535. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  536. if (rc)
  537. goto exit;
  538. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  539. rc = -EINVAL;
  540. goto exit;
  541. }
  542. exit:
  543. qed_vf_pf_req_end(p_hwfn, rc);
  544. return rc;
  545. }
  546. static bool
  547. qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
  548. struct qed_sp_vport_update_params *p_data,
  549. u16 tlv)
  550. {
  551. switch (tlv) {
  552. case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
  553. return !!(p_data->update_vport_active_rx_flg ||
  554. p_data->update_vport_active_tx_flg);
  555. case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
  556. return !!p_data->update_tx_switching_flg;
  557. case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
  558. return !!p_data->update_inner_vlan_removal_flg;
  559. case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
  560. return !!p_data->update_accept_any_vlan_flg;
  561. case CHANNEL_TLV_VPORT_UPDATE_MCAST:
  562. return !!p_data->update_approx_mcast_flg;
  563. case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
  564. return !!(p_data->accept_flags.update_rx_mode_config ||
  565. p_data->accept_flags.update_tx_mode_config);
  566. case CHANNEL_TLV_VPORT_UPDATE_RSS:
  567. return !!p_data->rss_params;
  568. case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
  569. return !!p_data->sge_tpa_params;
  570. default:
  571. DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
  572. tlv);
  573. return false;
  574. }
  575. }
  576. static void
  577. qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
  578. struct qed_sp_vport_update_params *p_data)
  579. {
  580. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  581. struct pfvf_def_resp_tlv *p_resp;
  582. u16 tlv;
  583. for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
  584. tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
  585. if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
  586. continue;
  587. p_resp = (struct pfvf_def_resp_tlv *)
  588. qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
  589. tlv);
  590. if (p_resp && p_resp->hdr.status)
  591. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  592. "TLV[%d] Configuration %s\n",
  593. tlv,
  594. (p_resp && p_resp->hdr.status) ? "succeeded"
  595. : "failed");
  596. }
  597. }
  598. int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
  599. struct qed_sp_vport_update_params *p_params)
  600. {
  601. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  602. struct vfpf_vport_update_tlv *req;
  603. struct pfvf_def_resp_tlv *resp;
  604. u8 update_rx, update_tx;
  605. u32 resp_size = 0;
  606. u16 size, tlv;
  607. int rc;
  608. resp = &p_iov->pf2vf_reply->default_resp;
  609. resp_size = sizeof(*resp);
  610. update_rx = p_params->update_vport_active_rx_flg;
  611. update_tx = p_params->update_vport_active_tx_flg;
  612. /* clear mailbox and prep header tlv */
  613. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
  614. /* Prepare extended tlvs */
  615. if (update_rx || update_tx) {
  616. struct vfpf_vport_update_activate_tlv *p_act_tlv;
  617. size = sizeof(struct vfpf_vport_update_activate_tlv);
  618. p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  619. CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
  620. size);
  621. resp_size += sizeof(struct pfvf_def_resp_tlv);
  622. if (update_rx) {
  623. p_act_tlv->update_rx = update_rx;
  624. p_act_tlv->active_rx = p_params->vport_active_rx_flg;
  625. }
  626. if (update_tx) {
  627. p_act_tlv->update_tx = update_tx;
  628. p_act_tlv->active_tx = p_params->vport_active_tx_flg;
  629. }
  630. }
  631. if (p_params->update_tx_switching_flg) {
  632. struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
  633. size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
  634. tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
  635. p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  636. tlv, size);
  637. resp_size += sizeof(struct pfvf_def_resp_tlv);
  638. p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
  639. }
  640. if (p_params->update_approx_mcast_flg) {
  641. struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
  642. size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
  643. p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
  644. CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
  645. resp_size += sizeof(struct pfvf_def_resp_tlv);
  646. memcpy(p_mcast_tlv->bins, p_params->bins,
  647. sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
  648. }
  649. update_rx = p_params->accept_flags.update_rx_mode_config;
  650. update_tx = p_params->accept_flags.update_tx_mode_config;
  651. if (update_rx || update_tx) {
  652. struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
  653. tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
  654. size = sizeof(struct vfpf_vport_update_accept_param_tlv);
  655. p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
  656. resp_size += sizeof(struct pfvf_def_resp_tlv);
  657. if (update_rx) {
  658. p_accept_tlv->update_rx_mode = update_rx;
  659. p_accept_tlv->rx_accept_filter =
  660. p_params->accept_flags.rx_accept_filter;
  661. }
  662. if (update_tx) {
  663. p_accept_tlv->update_tx_mode = update_tx;
  664. p_accept_tlv->tx_accept_filter =
  665. p_params->accept_flags.tx_accept_filter;
  666. }
  667. }
  668. if (p_params->rss_params) {
  669. struct qed_rss_params *rss_params = p_params->rss_params;
  670. struct vfpf_vport_update_rss_tlv *p_rss_tlv;
  671. size = sizeof(struct vfpf_vport_update_rss_tlv);
  672. p_rss_tlv = qed_add_tlv(p_hwfn,
  673. &p_iov->offset,
  674. CHANNEL_TLV_VPORT_UPDATE_RSS, size);
  675. resp_size += sizeof(struct pfvf_def_resp_tlv);
  676. if (rss_params->update_rss_config)
  677. p_rss_tlv->update_rss_flags |=
  678. VFPF_UPDATE_RSS_CONFIG_FLAG;
  679. if (rss_params->update_rss_capabilities)
  680. p_rss_tlv->update_rss_flags |=
  681. VFPF_UPDATE_RSS_CAPS_FLAG;
  682. if (rss_params->update_rss_ind_table)
  683. p_rss_tlv->update_rss_flags |=
  684. VFPF_UPDATE_RSS_IND_TABLE_FLAG;
  685. if (rss_params->update_rss_key)
  686. p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
  687. p_rss_tlv->rss_enable = rss_params->rss_enable;
  688. p_rss_tlv->rss_caps = rss_params->rss_caps;
  689. p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
  690. memcpy(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
  691. sizeof(rss_params->rss_ind_table));
  692. memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
  693. sizeof(rss_params->rss_key));
  694. }
  695. if (p_params->update_accept_any_vlan_flg) {
  696. struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
  697. size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
  698. tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
  699. p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
  700. resp_size += sizeof(struct pfvf_def_resp_tlv);
  701. p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
  702. p_any_vlan_tlv->update_accept_any_vlan_flg =
  703. p_params->update_accept_any_vlan_flg;
  704. }
  705. /* add list termination tlv */
  706. qed_add_tlv(p_hwfn, &p_iov->offset,
  707. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  708. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
  709. if (rc)
  710. goto exit;
  711. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  712. rc = -EINVAL;
  713. goto exit;
  714. }
  715. qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
  716. exit:
  717. qed_vf_pf_req_end(p_hwfn, rc);
  718. return rc;
  719. }
  720. int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
  721. {
  722. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  723. struct pfvf_def_resp_tlv *resp;
  724. struct vfpf_first_tlv *req;
  725. int rc;
  726. /* clear mailbox and prep first tlv */
  727. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
  728. /* add list termination tlv */
  729. qed_add_tlv(p_hwfn, &p_iov->offset,
  730. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  731. resp = &p_iov->pf2vf_reply->default_resp;
  732. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  733. if (rc)
  734. goto exit;
  735. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  736. rc = -EAGAIN;
  737. goto exit;
  738. }
  739. p_hwfn->b_int_enabled = 0;
  740. exit:
  741. qed_vf_pf_req_end(p_hwfn, rc);
  742. return rc;
  743. }
  744. int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
  745. {
  746. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  747. struct pfvf_def_resp_tlv *resp;
  748. struct vfpf_first_tlv *req;
  749. u32 size;
  750. int rc;
  751. /* clear mailbox and prep first tlv */
  752. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
  753. /* add list termination tlv */
  754. qed_add_tlv(p_hwfn, &p_iov->offset,
  755. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  756. resp = &p_iov->pf2vf_reply->default_resp;
  757. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  758. if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
  759. rc = -EAGAIN;
  760. qed_vf_pf_req_end(p_hwfn, rc);
  761. p_hwfn->b_int_enabled = 0;
  762. if (p_iov->vf2pf_request)
  763. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  764. sizeof(union vfpf_tlvs),
  765. p_iov->vf2pf_request,
  766. p_iov->vf2pf_request_phys);
  767. if (p_iov->pf2vf_reply)
  768. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  769. sizeof(union pfvf_tlvs),
  770. p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
  771. if (p_iov->bulletin.p_virt) {
  772. size = sizeof(struct qed_bulletin_content);
  773. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  774. size,
  775. p_iov->bulletin.p_virt, p_iov->bulletin.phys);
  776. }
  777. kfree(p_hwfn->vf_iov_info);
  778. p_hwfn->vf_iov_info = NULL;
  779. return rc;
  780. }
  781. void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
  782. struct qed_filter_mcast *p_filter_cmd)
  783. {
  784. struct qed_sp_vport_update_params sp_params;
  785. int i;
  786. memset(&sp_params, 0, sizeof(sp_params));
  787. sp_params.update_approx_mcast_flg = 1;
  788. if (p_filter_cmd->opcode == QED_FILTER_ADD) {
  789. for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
  790. u32 bit;
  791. bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
  792. __set_bit(bit, sp_params.bins);
  793. }
  794. }
  795. qed_vf_pf_vport_update(p_hwfn, &sp_params);
  796. }
  797. int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
  798. struct qed_filter_ucast *p_ucast)
  799. {
  800. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  801. struct vfpf_ucast_filter_tlv *req;
  802. struct pfvf_def_resp_tlv *resp;
  803. int rc;
  804. /* clear mailbox and prep first tlv */
  805. req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
  806. req->opcode = (u8) p_ucast->opcode;
  807. req->type = (u8) p_ucast->type;
  808. memcpy(req->mac, p_ucast->mac, ETH_ALEN);
  809. req->vlan = p_ucast->vlan;
  810. /* add list termination tlv */
  811. qed_add_tlv(p_hwfn, &p_iov->offset,
  812. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  813. resp = &p_iov->pf2vf_reply->default_resp;
  814. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  815. if (rc)
  816. goto exit;
  817. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  818. rc = -EAGAIN;
  819. goto exit;
  820. }
  821. exit:
  822. qed_vf_pf_req_end(p_hwfn, rc);
  823. return rc;
  824. }
  825. int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
  826. {
  827. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  828. struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
  829. int rc;
  830. /* clear mailbox and prep first tlv */
  831. qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
  832. sizeof(struct vfpf_first_tlv));
  833. /* add list termination tlv */
  834. qed_add_tlv(p_hwfn, &p_iov->offset,
  835. CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
  836. rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
  837. if (rc)
  838. goto exit;
  839. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  840. rc = -EINVAL;
  841. goto exit;
  842. }
  843. exit:
  844. qed_vf_pf_req_end(p_hwfn, rc);
  845. return rc;
  846. }
  847. u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
  848. {
  849. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  850. if (!p_iov) {
  851. DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
  852. return 0;
  853. }
  854. return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
  855. }
  856. int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
  857. {
  858. struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
  859. struct qed_bulletin_content shadow;
  860. u32 crc, crc_size;
  861. crc_size = sizeof(p_iov->bulletin.p_virt->crc);
  862. *p_change = 0;
  863. /* Need to guarantee PF is not in the middle of writing it */
  864. memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
  865. /* If version did not update, no need to do anything */
  866. if (shadow.version == p_iov->bulletin_shadow.version)
  867. return 0;
  868. /* Verify the bulletin we see is valid */
  869. crc = crc32(0, (u8 *)&shadow + crc_size,
  870. p_iov->bulletin.size - crc_size);
  871. if (crc != shadow.crc)
  872. return -EAGAIN;
  873. /* Set the shadow bulletin and process it */
  874. memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
  875. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  876. "Read a bulletin update %08x\n", shadow.version);
  877. *p_change = 1;
  878. return 0;
  879. }
  880. void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
  881. struct qed_mcp_link_params *p_params,
  882. struct qed_bulletin_content *p_bulletin)
  883. {
  884. memset(p_params, 0, sizeof(*p_params));
  885. p_params->speed.autoneg = p_bulletin->req_autoneg;
  886. p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
  887. p_params->speed.forced_speed = p_bulletin->req_forced_speed;
  888. p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
  889. p_params->pause.forced_rx = p_bulletin->req_forced_rx;
  890. p_params->pause.forced_tx = p_bulletin->req_forced_tx;
  891. p_params->loopback_mode = p_bulletin->req_loopback;
  892. }
  893. void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
  894. struct qed_mcp_link_params *params)
  895. {
  896. __qed_vf_get_link_params(p_hwfn, params,
  897. &(p_hwfn->vf_iov_info->bulletin_shadow));
  898. }
  899. void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
  900. struct qed_mcp_link_state *p_link,
  901. struct qed_bulletin_content *p_bulletin)
  902. {
  903. memset(p_link, 0, sizeof(*p_link));
  904. p_link->link_up = p_bulletin->link_up;
  905. p_link->speed = p_bulletin->speed;
  906. p_link->full_duplex = p_bulletin->full_duplex;
  907. p_link->an = p_bulletin->autoneg;
  908. p_link->an_complete = p_bulletin->autoneg_complete;
  909. p_link->parallel_detection = p_bulletin->parallel_detection;
  910. p_link->pfc_enabled = p_bulletin->pfc_enabled;
  911. p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
  912. p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
  913. p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
  914. p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
  915. p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
  916. }
  917. void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
  918. struct qed_mcp_link_state *link)
  919. {
  920. __qed_vf_get_link_state(p_hwfn, link,
  921. &(p_hwfn->vf_iov_info->bulletin_shadow));
  922. }
  923. void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
  924. struct qed_mcp_link_capabilities *p_link_caps,
  925. struct qed_bulletin_content *p_bulletin)
  926. {
  927. memset(p_link_caps, 0, sizeof(*p_link_caps));
  928. p_link_caps->speed_capabilities = p_bulletin->capability_speed;
  929. }
  930. void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
  931. struct qed_mcp_link_capabilities *p_link_caps)
  932. {
  933. __qed_vf_get_link_caps(p_hwfn, p_link_caps,
  934. &(p_hwfn->vf_iov_info->bulletin_shadow));
  935. }
  936. void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
  937. {
  938. *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
  939. }
  940. void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
  941. {
  942. memcpy(port_mac,
  943. p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
  944. }
  945. void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
  946. {
  947. struct qed_vf_iov *p_vf;
  948. p_vf = p_hwfn->vf_iov_info;
  949. *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
  950. }
  951. void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
  952. {
  953. struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
  954. *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
  955. }
  956. bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
  957. {
  958. struct qed_bulletin_content *bulletin;
  959. bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
  960. if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
  961. return true;
  962. /* Forbid VF from changing a MAC enforced by PF */
  963. if (ether_addr_equal(bulletin->mac, mac))
  964. return false;
  965. return false;
  966. }
  967. static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
  968. u8 *dst_mac, u8 *p_is_forced)
  969. {
  970. struct qed_bulletin_content *bulletin;
  971. bulletin = &hwfn->vf_iov_info->bulletin_shadow;
  972. if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
  973. if (p_is_forced)
  974. *p_is_forced = 1;
  975. } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
  976. if (p_is_forced)
  977. *p_is_forced = 0;
  978. } else {
  979. return false;
  980. }
  981. ether_addr_copy(dst_mac, bulletin->mac);
  982. return true;
  983. }
  984. void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
  985. u16 *fw_major, u16 *fw_minor,
  986. u16 *fw_rev, u16 *fw_eng)
  987. {
  988. struct pf_vf_pfdev_info *info;
  989. info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
  990. *fw_major = info->fw_major;
  991. *fw_minor = info->fw_minor;
  992. *fw_rev = info->fw_rev;
  993. *fw_eng = info->fw_eng;
  994. }
  995. static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
  996. {
  997. struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
  998. u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
  999. void *cookie = hwfn->cdev->ops_cookie;
  1000. is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
  1001. &is_mac_forced);
  1002. if (is_mac_exist && cookie)
  1003. ops->force_mac(cookie, mac, !!is_mac_forced);
  1004. /* Always update link configuration according to bulletin */
  1005. qed_link_update(hwfn);
  1006. }
  1007. void qed_iov_vf_task(struct work_struct *work)
  1008. {
  1009. struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
  1010. iov_task.work);
  1011. u8 change = 0;
  1012. if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
  1013. return;
  1014. /* Handle bulletin board changes */
  1015. qed_vf_read_bulletin(hwfn, &change);
  1016. if (change)
  1017. qed_handle_bulletin_change(hwfn);
  1018. /* As VF is polling bulletin board, need to constantly re-schedule */
  1019. queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
  1020. }