qed_vf.c 36 KB

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