nicvf_main.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. /*
  2. * Copyright (C) 2015 Cavium, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/pci.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/if_vlan.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/ethtool.h>
  15. #include <linux/log2.h>
  16. #include <linux/prefetch.h>
  17. #include <linux/irq.h>
  18. #include "nic_reg.h"
  19. #include "nic.h"
  20. #include "nicvf_queues.h"
  21. #include "thunder_bgx.h"
  22. #define DRV_NAME "thunder-nicvf"
  23. #define DRV_VERSION "1.0"
  24. /* Supported devices */
  25. static const struct pci_device_id nicvf_id_table[] = {
  26. { PCI_DEVICE_SUB(PCI_VENDOR_ID_CAVIUM,
  27. PCI_DEVICE_ID_THUNDER_NIC_VF,
  28. PCI_VENDOR_ID_CAVIUM,
  29. PCI_SUBSYS_DEVID_88XX_NIC_VF) },
  30. { PCI_DEVICE_SUB(PCI_VENDOR_ID_CAVIUM,
  31. PCI_DEVICE_ID_THUNDER_PASS1_NIC_VF,
  32. PCI_VENDOR_ID_CAVIUM,
  33. PCI_SUBSYS_DEVID_88XX_PASS1_NIC_VF) },
  34. { PCI_DEVICE_SUB(PCI_VENDOR_ID_CAVIUM,
  35. PCI_DEVICE_ID_THUNDER_NIC_VF,
  36. PCI_VENDOR_ID_CAVIUM,
  37. PCI_SUBSYS_DEVID_81XX_NIC_VF) },
  38. { PCI_DEVICE_SUB(PCI_VENDOR_ID_CAVIUM,
  39. PCI_DEVICE_ID_THUNDER_NIC_VF,
  40. PCI_VENDOR_ID_CAVIUM,
  41. PCI_SUBSYS_DEVID_83XX_NIC_VF) },
  42. { 0, } /* end of table */
  43. };
  44. MODULE_AUTHOR("Sunil Goutham");
  45. MODULE_DESCRIPTION("Cavium Thunder NIC Virtual Function Driver");
  46. MODULE_LICENSE("GPL v2");
  47. MODULE_VERSION(DRV_VERSION);
  48. MODULE_DEVICE_TABLE(pci, nicvf_id_table);
  49. static int debug = 0x00;
  50. module_param(debug, int, 0644);
  51. MODULE_PARM_DESC(debug, "Debug message level bitmap");
  52. static int cpi_alg = CPI_ALG_NONE;
  53. module_param(cpi_alg, int, S_IRUGO);
  54. MODULE_PARM_DESC(cpi_alg,
  55. "PFC algorithm (0=none, 1=VLAN, 2=VLAN16, 3=IP Diffserv)");
  56. static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx)
  57. {
  58. if (nic->sqs_mode)
  59. return qidx + ((nic->sqs_id + 1) * MAX_CMP_QUEUES_PER_QS);
  60. else
  61. return qidx;
  62. }
  63. /* The Cavium ThunderX network controller can *only* be found in SoCs
  64. * containing the ThunderX ARM64 CPU implementation. All accesses to the device
  65. * registers on this platform are implicitly strongly ordered with respect
  66. * to memory accesses. So writeq_relaxed() and readq_relaxed() are safe to use
  67. * with no memory barriers in this driver. The readq()/writeq() functions add
  68. * explicit ordering operation which in this case are redundant, and only
  69. * add overhead.
  70. */
  71. /* Register read/write APIs */
  72. void nicvf_reg_write(struct nicvf *nic, u64 offset, u64 val)
  73. {
  74. writeq_relaxed(val, nic->reg_base + offset);
  75. }
  76. u64 nicvf_reg_read(struct nicvf *nic, u64 offset)
  77. {
  78. return readq_relaxed(nic->reg_base + offset);
  79. }
  80. void nicvf_queue_reg_write(struct nicvf *nic, u64 offset,
  81. u64 qidx, u64 val)
  82. {
  83. void __iomem *addr = nic->reg_base + offset;
  84. writeq_relaxed(val, addr + (qidx << NIC_Q_NUM_SHIFT));
  85. }
  86. u64 nicvf_queue_reg_read(struct nicvf *nic, u64 offset, u64 qidx)
  87. {
  88. void __iomem *addr = nic->reg_base + offset;
  89. return readq_relaxed(addr + (qidx << NIC_Q_NUM_SHIFT));
  90. }
  91. /* VF -> PF mailbox communication */
  92. static void nicvf_write_to_mbx(struct nicvf *nic, union nic_mbx *mbx)
  93. {
  94. u64 *msg = (u64 *)mbx;
  95. nicvf_reg_write(nic, NIC_VF_PF_MAILBOX_0_1 + 0, msg[0]);
  96. nicvf_reg_write(nic, NIC_VF_PF_MAILBOX_0_1 + 8, msg[1]);
  97. }
  98. int nicvf_send_msg_to_pf(struct nicvf *nic, union nic_mbx *mbx)
  99. {
  100. int timeout = NIC_MBOX_MSG_TIMEOUT;
  101. int sleep = 10;
  102. nic->pf_acked = false;
  103. nic->pf_nacked = false;
  104. nicvf_write_to_mbx(nic, mbx);
  105. /* Wait for previous message to be acked, timeout 2sec */
  106. while (!nic->pf_acked) {
  107. if (nic->pf_nacked) {
  108. netdev_err(nic->netdev,
  109. "PF NACK to mbox msg 0x%02x from VF%d\n",
  110. (mbx->msg.msg & 0xFF), nic->vf_id);
  111. return -EINVAL;
  112. }
  113. msleep(sleep);
  114. if (nic->pf_acked)
  115. break;
  116. timeout -= sleep;
  117. if (!timeout) {
  118. netdev_err(nic->netdev,
  119. "PF didn't ACK to mbox msg 0x%02x from VF%d\n",
  120. (mbx->msg.msg & 0xFF), nic->vf_id);
  121. return -EBUSY;
  122. }
  123. }
  124. return 0;
  125. }
  126. /* Checks if VF is able to comminicate with PF
  127. * and also gets the VNIC number this VF is associated to.
  128. */
  129. static int nicvf_check_pf_ready(struct nicvf *nic)
  130. {
  131. union nic_mbx mbx = {};
  132. mbx.msg.msg = NIC_MBOX_MSG_READY;
  133. if (nicvf_send_msg_to_pf(nic, &mbx)) {
  134. netdev_err(nic->netdev,
  135. "PF didn't respond to READY msg\n");
  136. return 0;
  137. }
  138. return 1;
  139. }
  140. static void nicvf_read_bgx_stats(struct nicvf *nic, struct bgx_stats_msg *bgx)
  141. {
  142. if (bgx->rx)
  143. nic->bgx_stats.rx_stats[bgx->idx] = bgx->stats;
  144. else
  145. nic->bgx_stats.tx_stats[bgx->idx] = bgx->stats;
  146. }
  147. static void nicvf_handle_mbx_intr(struct nicvf *nic)
  148. {
  149. union nic_mbx mbx = {};
  150. u64 *mbx_data;
  151. u64 mbx_addr;
  152. int i;
  153. mbx_addr = NIC_VF_PF_MAILBOX_0_1;
  154. mbx_data = (u64 *)&mbx;
  155. for (i = 0; i < NIC_PF_VF_MAILBOX_SIZE; i++) {
  156. *mbx_data = nicvf_reg_read(nic, mbx_addr);
  157. mbx_data++;
  158. mbx_addr += sizeof(u64);
  159. }
  160. netdev_dbg(nic->netdev, "Mbox message: msg: 0x%x\n", mbx.msg.msg);
  161. switch (mbx.msg.msg) {
  162. case NIC_MBOX_MSG_READY:
  163. nic->pf_acked = true;
  164. nic->vf_id = mbx.nic_cfg.vf_id & 0x7F;
  165. nic->tns_mode = mbx.nic_cfg.tns_mode & 0x7F;
  166. nic->node = mbx.nic_cfg.node_id;
  167. if (!nic->set_mac_pending)
  168. ether_addr_copy(nic->netdev->dev_addr,
  169. mbx.nic_cfg.mac_addr);
  170. nic->sqs_mode = mbx.nic_cfg.sqs_mode;
  171. nic->loopback_supported = mbx.nic_cfg.loopback_supported;
  172. nic->link_up = false;
  173. nic->duplex = 0;
  174. nic->speed = 0;
  175. break;
  176. case NIC_MBOX_MSG_ACK:
  177. nic->pf_acked = true;
  178. break;
  179. case NIC_MBOX_MSG_NACK:
  180. nic->pf_nacked = true;
  181. break;
  182. case NIC_MBOX_MSG_RSS_SIZE:
  183. nic->rss_info.rss_size = mbx.rss_size.ind_tbl_size;
  184. nic->pf_acked = true;
  185. break;
  186. case NIC_MBOX_MSG_BGX_STATS:
  187. nicvf_read_bgx_stats(nic, &mbx.bgx_stats);
  188. nic->pf_acked = true;
  189. break;
  190. case NIC_MBOX_MSG_BGX_LINK_CHANGE:
  191. nic->pf_acked = true;
  192. nic->link_up = mbx.link_status.link_up;
  193. nic->duplex = mbx.link_status.duplex;
  194. nic->speed = mbx.link_status.speed;
  195. if (nic->link_up) {
  196. netdev_info(nic->netdev, "%s: Link is Up %d Mbps %s\n",
  197. nic->netdev->name, nic->speed,
  198. nic->duplex == DUPLEX_FULL ?
  199. "Full duplex" : "Half duplex");
  200. netif_carrier_on(nic->netdev);
  201. netif_tx_start_all_queues(nic->netdev);
  202. } else {
  203. netdev_info(nic->netdev, "%s: Link is Down\n",
  204. nic->netdev->name);
  205. netif_carrier_off(nic->netdev);
  206. netif_tx_stop_all_queues(nic->netdev);
  207. }
  208. break;
  209. case NIC_MBOX_MSG_ALLOC_SQS:
  210. nic->sqs_count = mbx.sqs_alloc.qs_count;
  211. nic->pf_acked = true;
  212. break;
  213. case NIC_MBOX_MSG_SNICVF_PTR:
  214. /* Primary VF: make note of secondary VF's pointer
  215. * to be used while packet transmission.
  216. */
  217. nic->snicvf[mbx.nicvf.sqs_id] =
  218. (struct nicvf *)mbx.nicvf.nicvf;
  219. nic->pf_acked = true;
  220. break;
  221. case NIC_MBOX_MSG_PNICVF_PTR:
  222. /* Secondary VF/Qset: make note of primary VF's pointer
  223. * to be used while packet reception, to handover packet
  224. * to primary VF's netdev.
  225. */
  226. nic->pnicvf = (struct nicvf *)mbx.nicvf.nicvf;
  227. nic->pf_acked = true;
  228. break;
  229. default:
  230. netdev_err(nic->netdev,
  231. "Invalid message from PF, msg 0x%x\n", mbx.msg.msg);
  232. break;
  233. }
  234. nicvf_clear_intr(nic, NICVF_INTR_MBOX, 0);
  235. }
  236. static int nicvf_hw_set_mac_addr(struct nicvf *nic, struct net_device *netdev)
  237. {
  238. union nic_mbx mbx = {};
  239. mbx.mac.msg = NIC_MBOX_MSG_SET_MAC;
  240. mbx.mac.vf_id = nic->vf_id;
  241. ether_addr_copy(mbx.mac.mac_addr, netdev->dev_addr);
  242. return nicvf_send_msg_to_pf(nic, &mbx);
  243. }
  244. static void nicvf_config_cpi(struct nicvf *nic)
  245. {
  246. union nic_mbx mbx = {};
  247. mbx.cpi_cfg.msg = NIC_MBOX_MSG_CPI_CFG;
  248. mbx.cpi_cfg.vf_id = nic->vf_id;
  249. mbx.cpi_cfg.cpi_alg = nic->cpi_alg;
  250. mbx.cpi_cfg.rq_cnt = nic->qs->rq_cnt;
  251. nicvf_send_msg_to_pf(nic, &mbx);
  252. }
  253. static void nicvf_get_rss_size(struct nicvf *nic)
  254. {
  255. union nic_mbx mbx = {};
  256. mbx.rss_size.msg = NIC_MBOX_MSG_RSS_SIZE;
  257. mbx.rss_size.vf_id = nic->vf_id;
  258. nicvf_send_msg_to_pf(nic, &mbx);
  259. }
  260. void nicvf_config_rss(struct nicvf *nic)
  261. {
  262. union nic_mbx mbx = {};
  263. struct nicvf_rss_info *rss = &nic->rss_info;
  264. int ind_tbl_len = rss->rss_size;
  265. int i, nextq = 0;
  266. mbx.rss_cfg.vf_id = nic->vf_id;
  267. mbx.rss_cfg.hash_bits = rss->hash_bits;
  268. while (ind_tbl_len) {
  269. mbx.rss_cfg.tbl_offset = nextq;
  270. mbx.rss_cfg.tbl_len = min(ind_tbl_len,
  271. RSS_IND_TBL_LEN_PER_MBX_MSG);
  272. mbx.rss_cfg.msg = mbx.rss_cfg.tbl_offset ?
  273. NIC_MBOX_MSG_RSS_CFG_CONT : NIC_MBOX_MSG_RSS_CFG;
  274. for (i = 0; i < mbx.rss_cfg.tbl_len; i++)
  275. mbx.rss_cfg.ind_tbl[i] = rss->ind_tbl[nextq++];
  276. nicvf_send_msg_to_pf(nic, &mbx);
  277. ind_tbl_len -= mbx.rss_cfg.tbl_len;
  278. }
  279. }
  280. void nicvf_set_rss_key(struct nicvf *nic)
  281. {
  282. struct nicvf_rss_info *rss = &nic->rss_info;
  283. u64 key_addr = NIC_VNIC_RSS_KEY_0_4;
  284. int idx;
  285. for (idx = 0; idx < RSS_HASH_KEY_SIZE; idx++) {
  286. nicvf_reg_write(nic, key_addr, rss->key[idx]);
  287. key_addr += sizeof(u64);
  288. }
  289. }
  290. static int nicvf_rss_init(struct nicvf *nic)
  291. {
  292. struct nicvf_rss_info *rss = &nic->rss_info;
  293. int idx;
  294. nicvf_get_rss_size(nic);
  295. if (cpi_alg != CPI_ALG_NONE) {
  296. rss->enable = false;
  297. rss->hash_bits = 0;
  298. return 0;
  299. }
  300. rss->enable = true;
  301. netdev_rss_key_fill(rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
  302. nicvf_set_rss_key(nic);
  303. rss->cfg = RSS_IP_HASH_ENA | RSS_TCP_HASH_ENA | RSS_UDP_HASH_ENA;
  304. nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss->cfg);
  305. rss->hash_bits = ilog2(rounddown_pow_of_two(rss->rss_size));
  306. for (idx = 0; idx < rss->rss_size; idx++)
  307. rss->ind_tbl[idx] = ethtool_rxfh_indir_default(idx,
  308. nic->rx_queues);
  309. nicvf_config_rss(nic);
  310. return 1;
  311. }
  312. /* Request PF to allocate additional Qsets */
  313. static void nicvf_request_sqs(struct nicvf *nic)
  314. {
  315. union nic_mbx mbx = {};
  316. int sqs;
  317. int sqs_count = nic->sqs_count;
  318. int rx_queues = 0, tx_queues = 0;
  319. /* Only primary VF should request */
  320. if (nic->sqs_mode || !nic->sqs_count)
  321. return;
  322. mbx.sqs_alloc.msg = NIC_MBOX_MSG_ALLOC_SQS;
  323. mbx.sqs_alloc.vf_id = nic->vf_id;
  324. mbx.sqs_alloc.qs_count = nic->sqs_count;
  325. if (nicvf_send_msg_to_pf(nic, &mbx)) {
  326. /* No response from PF */
  327. nic->sqs_count = 0;
  328. return;
  329. }
  330. /* Return if no Secondary Qsets available */
  331. if (!nic->sqs_count)
  332. return;
  333. if (nic->rx_queues > MAX_RCV_QUEUES_PER_QS)
  334. rx_queues = nic->rx_queues - MAX_RCV_QUEUES_PER_QS;
  335. if (nic->tx_queues > MAX_SND_QUEUES_PER_QS)
  336. tx_queues = nic->tx_queues - MAX_SND_QUEUES_PER_QS;
  337. /* Set no of Rx/Tx queues in each of the SQsets */
  338. for (sqs = 0; sqs < nic->sqs_count; sqs++) {
  339. mbx.nicvf.msg = NIC_MBOX_MSG_SNICVF_PTR;
  340. mbx.nicvf.vf_id = nic->vf_id;
  341. mbx.nicvf.sqs_id = sqs;
  342. nicvf_send_msg_to_pf(nic, &mbx);
  343. nic->snicvf[sqs]->sqs_id = sqs;
  344. if (rx_queues > MAX_RCV_QUEUES_PER_QS) {
  345. nic->snicvf[sqs]->qs->rq_cnt = MAX_RCV_QUEUES_PER_QS;
  346. rx_queues -= MAX_RCV_QUEUES_PER_QS;
  347. } else {
  348. nic->snicvf[sqs]->qs->rq_cnt = rx_queues;
  349. rx_queues = 0;
  350. }
  351. if (tx_queues > MAX_SND_QUEUES_PER_QS) {
  352. nic->snicvf[sqs]->qs->sq_cnt = MAX_SND_QUEUES_PER_QS;
  353. tx_queues -= MAX_SND_QUEUES_PER_QS;
  354. } else {
  355. nic->snicvf[sqs]->qs->sq_cnt = tx_queues;
  356. tx_queues = 0;
  357. }
  358. nic->snicvf[sqs]->qs->cq_cnt =
  359. max(nic->snicvf[sqs]->qs->rq_cnt, nic->snicvf[sqs]->qs->sq_cnt);
  360. /* Initialize secondary Qset's queues and its interrupts */
  361. nicvf_open(nic->snicvf[sqs]->netdev);
  362. }
  363. /* Update stack with actual Rx/Tx queue count allocated */
  364. if (sqs_count != nic->sqs_count)
  365. nicvf_set_real_num_queues(nic->netdev,
  366. nic->tx_queues, nic->rx_queues);
  367. }
  368. /* Send this Qset's nicvf pointer to PF.
  369. * PF inturn sends primary VF's nicvf struct to secondary Qsets/VFs
  370. * so that packets received by these Qsets can use primary VF's netdev
  371. */
  372. static void nicvf_send_vf_struct(struct nicvf *nic)
  373. {
  374. union nic_mbx mbx = {};
  375. mbx.nicvf.msg = NIC_MBOX_MSG_NICVF_PTR;
  376. mbx.nicvf.sqs_mode = nic->sqs_mode;
  377. mbx.nicvf.nicvf = (u64)nic;
  378. nicvf_send_msg_to_pf(nic, &mbx);
  379. }
  380. static void nicvf_get_primary_vf_struct(struct nicvf *nic)
  381. {
  382. union nic_mbx mbx = {};
  383. mbx.nicvf.msg = NIC_MBOX_MSG_PNICVF_PTR;
  384. nicvf_send_msg_to_pf(nic, &mbx);
  385. }
  386. int nicvf_set_real_num_queues(struct net_device *netdev,
  387. int tx_queues, int rx_queues)
  388. {
  389. int err = 0;
  390. err = netif_set_real_num_tx_queues(netdev, tx_queues);
  391. if (err) {
  392. netdev_err(netdev,
  393. "Failed to set no of Tx queues: %d\n", tx_queues);
  394. return err;
  395. }
  396. err = netif_set_real_num_rx_queues(netdev, rx_queues);
  397. if (err)
  398. netdev_err(netdev,
  399. "Failed to set no of Rx queues: %d\n", rx_queues);
  400. return err;
  401. }
  402. static int nicvf_init_resources(struct nicvf *nic)
  403. {
  404. int err;
  405. /* Enable Qset */
  406. nicvf_qset_config(nic, true);
  407. /* Initialize queues and HW for data transfer */
  408. err = nicvf_config_data_transfer(nic, true);
  409. if (err) {
  410. netdev_err(nic->netdev,
  411. "Failed to alloc/config VF's QSet resources\n");
  412. return err;
  413. }
  414. return 0;
  415. }
  416. static void nicvf_snd_pkt_handler(struct net_device *netdev,
  417. struct cqe_send_t *cqe_tx,
  418. int cqe_type, int budget,
  419. unsigned int *tx_pkts, unsigned int *tx_bytes)
  420. {
  421. struct sk_buff *skb = NULL;
  422. struct nicvf *nic = netdev_priv(netdev);
  423. struct snd_queue *sq;
  424. struct sq_hdr_subdesc *hdr;
  425. struct sq_hdr_subdesc *tso_sqe;
  426. sq = &nic->qs->sq[cqe_tx->sq_idx];
  427. hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, cqe_tx->sqe_ptr);
  428. if (hdr->subdesc_type != SQ_DESC_TYPE_HEADER)
  429. return;
  430. netdev_dbg(nic->netdev,
  431. "%s Qset #%d SQ #%d SQ ptr #%d subdesc count %d\n",
  432. __func__, cqe_tx->sq_qs, cqe_tx->sq_idx,
  433. cqe_tx->sqe_ptr, hdr->subdesc_cnt);
  434. nicvf_check_cqe_tx_errs(nic, cqe_tx);
  435. skb = (struct sk_buff *)sq->skbuff[cqe_tx->sqe_ptr];
  436. if (skb) {
  437. /* Check for dummy descriptor used for HW TSO offload on 88xx */
  438. if (hdr->dont_send) {
  439. /* Get actual TSO descriptors and free them */
  440. tso_sqe =
  441. (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, hdr->rsvd2);
  442. nicvf_put_sq_desc(sq, tso_sqe->subdesc_cnt + 1);
  443. }
  444. nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1);
  445. prefetch(skb);
  446. (*tx_pkts)++;
  447. *tx_bytes += skb->len;
  448. napi_consume_skb(skb, budget);
  449. sq->skbuff[cqe_tx->sqe_ptr] = (u64)NULL;
  450. } else {
  451. /* In case of SW TSO on 88xx, only last segment will have
  452. * a SKB attached, so just free SQEs here.
  453. */
  454. if (!nic->hw_tso)
  455. nicvf_put_sq_desc(sq, hdr->subdesc_cnt + 1);
  456. }
  457. }
  458. static inline void nicvf_set_rxhash(struct net_device *netdev,
  459. struct cqe_rx_t *cqe_rx,
  460. struct sk_buff *skb)
  461. {
  462. u8 hash_type;
  463. u32 hash;
  464. if (!(netdev->features & NETIF_F_RXHASH))
  465. return;
  466. switch (cqe_rx->rss_alg) {
  467. case RSS_ALG_TCP_IP:
  468. case RSS_ALG_UDP_IP:
  469. hash_type = PKT_HASH_TYPE_L4;
  470. hash = cqe_rx->rss_tag;
  471. break;
  472. case RSS_ALG_IP:
  473. hash_type = PKT_HASH_TYPE_L3;
  474. hash = cqe_rx->rss_tag;
  475. break;
  476. default:
  477. hash_type = PKT_HASH_TYPE_NONE;
  478. hash = 0;
  479. }
  480. skb_set_hash(skb, hash, hash_type);
  481. }
  482. static void nicvf_rcv_pkt_handler(struct net_device *netdev,
  483. struct napi_struct *napi,
  484. struct cqe_rx_t *cqe_rx)
  485. {
  486. struct sk_buff *skb;
  487. struct nicvf *nic = netdev_priv(netdev);
  488. int err = 0;
  489. int rq_idx;
  490. rq_idx = nicvf_netdev_qidx(nic, cqe_rx->rq_idx);
  491. if (nic->sqs_mode) {
  492. /* Use primary VF's 'nicvf' struct */
  493. nic = nic->pnicvf;
  494. netdev = nic->netdev;
  495. }
  496. /* Check for errors */
  497. err = nicvf_check_cqe_rx_errs(nic, cqe_rx);
  498. if (err && !cqe_rx->rb_cnt)
  499. return;
  500. skb = nicvf_get_rcv_skb(nic, cqe_rx);
  501. if (!skb) {
  502. netdev_dbg(nic->netdev, "Packet not received\n");
  503. return;
  504. }
  505. if (netif_msg_pktdata(nic)) {
  506. netdev_info(nic->netdev, "%s: skb 0x%p, len=%d\n", netdev->name,
  507. skb, skb->len);
  508. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
  509. skb->data, skb->len, true);
  510. }
  511. /* If error packet, drop it here */
  512. if (err) {
  513. dev_kfree_skb_any(skb);
  514. return;
  515. }
  516. nicvf_set_rxhash(netdev, cqe_rx, skb);
  517. skb_record_rx_queue(skb, rq_idx);
  518. if (netdev->hw_features & NETIF_F_RXCSUM) {
  519. /* HW by default verifies TCP/UDP/SCTP checksums */
  520. skb->ip_summed = CHECKSUM_UNNECESSARY;
  521. } else {
  522. skb_checksum_none_assert(skb);
  523. }
  524. skb->protocol = eth_type_trans(skb, netdev);
  525. /* Check for stripped VLAN */
  526. if (cqe_rx->vlan_found && cqe_rx->vlan_stripped)
  527. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
  528. ntohs((__force __be16)cqe_rx->vlan_tci));
  529. if (napi && (netdev->features & NETIF_F_GRO))
  530. napi_gro_receive(napi, skb);
  531. else
  532. netif_receive_skb(skb);
  533. }
  534. static int nicvf_cq_intr_handler(struct net_device *netdev, u8 cq_idx,
  535. struct napi_struct *napi, int budget)
  536. {
  537. int processed_cqe, work_done = 0, tx_done = 0;
  538. int cqe_count, cqe_head;
  539. struct nicvf *nic = netdev_priv(netdev);
  540. struct queue_set *qs = nic->qs;
  541. struct cmp_queue *cq = &qs->cq[cq_idx];
  542. struct cqe_rx_t *cq_desc;
  543. struct netdev_queue *txq;
  544. unsigned int tx_pkts = 0, tx_bytes = 0;
  545. spin_lock_bh(&cq->lock);
  546. loop:
  547. processed_cqe = 0;
  548. /* Get no of valid CQ entries to process */
  549. cqe_count = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, cq_idx);
  550. cqe_count &= CQ_CQE_COUNT;
  551. if (!cqe_count)
  552. goto done;
  553. /* Get head of the valid CQ entries */
  554. cqe_head = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, cq_idx) >> 9;
  555. cqe_head &= 0xFFFF;
  556. netdev_dbg(nic->netdev, "%s CQ%d cqe_count %d cqe_head %d\n",
  557. __func__, cq_idx, cqe_count, cqe_head);
  558. while (processed_cqe < cqe_count) {
  559. /* Get the CQ descriptor */
  560. cq_desc = (struct cqe_rx_t *)GET_CQ_DESC(cq, cqe_head);
  561. cqe_head++;
  562. cqe_head &= (cq->dmem.q_len - 1);
  563. /* Initiate prefetch for next descriptor */
  564. prefetch((struct cqe_rx_t *)GET_CQ_DESC(cq, cqe_head));
  565. if ((work_done >= budget) && napi &&
  566. (cq_desc->cqe_type != CQE_TYPE_SEND)) {
  567. break;
  568. }
  569. netdev_dbg(nic->netdev, "CQ%d cq_desc->cqe_type %d\n",
  570. cq_idx, cq_desc->cqe_type);
  571. switch (cq_desc->cqe_type) {
  572. case CQE_TYPE_RX:
  573. nicvf_rcv_pkt_handler(netdev, napi, cq_desc);
  574. work_done++;
  575. break;
  576. case CQE_TYPE_SEND:
  577. nicvf_snd_pkt_handler(netdev,
  578. (void *)cq_desc, CQE_TYPE_SEND,
  579. budget, &tx_pkts, &tx_bytes);
  580. tx_done++;
  581. break;
  582. case CQE_TYPE_INVALID:
  583. case CQE_TYPE_RX_SPLIT:
  584. case CQE_TYPE_RX_TCP:
  585. case CQE_TYPE_SEND_PTP:
  586. /* Ignore for now */
  587. break;
  588. }
  589. processed_cqe++;
  590. }
  591. netdev_dbg(nic->netdev,
  592. "%s CQ%d processed_cqe %d work_done %d budget %d\n",
  593. __func__, cq_idx, processed_cqe, work_done, budget);
  594. /* Ring doorbell to inform H/W to reuse processed CQEs */
  595. nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_DOOR,
  596. cq_idx, processed_cqe);
  597. if ((work_done < budget) && napi)
  598. goto loop;
  599. done:
  600. /* Wakeup TXQ if its stopped earlier due to SQ full */
  601. if (tx_done) {
  602. netdev = nic->pnicvf->netdev;
  603. txq = netdev_get_tx_queue(netdev,
  604. nicvf_netdev_qidx(nic, cq_idx));
  605. if (tx_pkts)
  606. netdev_tx_completed_queue(txq, tx_pkts, tx_bytes);
  607. nic = nic->pnicvf;
  608. if (netif_tx_queue_stopped(txq) && netif_carrier_ok(netdev)) {
  609. netif_tx_start_queue(txq);
  610. this_cpu_inc(nic->drv_stats->txq_wake);
  611. if (netif_msg_tx_err(nic))
  612. netdev_warn(netdev,
  613. "%s: Transmit queue wakeup SQ%d\n",
  614. netdev->name, cq_idx);
  615. }
  616. }
  617. spin_unlock_bh(&cq->lock);
  618. return work_done;
  619. }
  620. static int nicvf_poll(struct napi_struct *napi, int budget)
  621. {
  622. u64 cq_head;
  623. int work_done = 0;
  624. struct net_device *netdev = napi->dev;
  625. struct nicvf *nic = netdev_priv(netdev);
  626. struct nicvf_cq_poll *cq;
  627. cq = container_of(napi, struct nicvf_cq_poll, napi);
  628. work_done = nicvf_cq_intr_handler(netdev, cq->cq_idx, napi, budget);
  629. if (work_done < budget) {
  630. /* Slow packet rate, exit polling */
  631. napi_complete(napi);
  632. /* Re-enable interrupts */
  633. cq_head = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD,
  634. cq->cq_idx);
  635. nicvf_clear_intr(nic, NICVF_INTR_CQ, cq->cq_idx);
  636. nicvf_queue_reg_write(nic, NIC_QSET_CQ_0_7_HEAD,
  637. cq->cq_idx, cq_head);
  638. nicvf_enable_intr(nic, NICVF_INTR_CQ, cq->cq_idx);
  639. }
  640. return work_done;
  641. }
  642. /* Qset error interrupt handler
  643. *
  644. * As of now only CQ errors are handled
  645. */
  646. static void nicvf_handle_qs_err(unsigned long data)
  647. {
  648. struct nicvf *nic = (struct nicvf *)data;
  649. struct queue_set *qs = nic->qs;
  650. int qidx;
  651. u64 status;
  652. netif_tx_disable(nic->netdev);
  653. /* Check if it is CQ err */
  654. for (qidx = 0; qidx < qs->cq_cnt; qidx++) {
  655. status = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS,
  656. qidx);
  657. if (!(status & CQ_ERR_MASK))
  658. continue;
  659. /* Process already queued CQEs and reconfig CQ */
  660. nicvf_disable_intr(nic, NICVF_INTR_CQ, qidx);
  661. nicvf_sq_disable(nic, qidx);
  662. nicvf_cq_intr_handler(nic->netdev, qidx, NULL, 0);
  663. nicvf_cmp_queue_config(nic, qs, qidx, true);
  664. nicvf_sq_free_used_descs(nic->netdev, &qs->sq[qidx], qidx);
  665. nicvf_sq_enable(nic, &qs->sq[qidx], qidx);
  666. nicvf_enable_intr(nic, NICVF_INTR_CQ, qidx);
  667. }
  668. netif_tx_start_all_queues(nic->netdev);
  669. /* Re-enable Qset error interrupt */
  670. nicvf_enable_intr(nic, NICVF_INTR_QS_ERR, 0);
  671. }
  672. static void nicvf_dump_intr_status(struct nicvf *nic)
  673. {
  674. if (netif_msg_intr(nic))
  675. netdev_info(nic->netdev, "%s: interrupt status 0x%llx\n",
  676. nic->netdev->name, nicvf_reg_read(nic, NIC_VF_INT));
  677. }
  678. static irqreturn_t nicvf_misc_intr_handler(int irq, void *nicvf_irq)
  679. {
  680. struct nicvf *nic = (struct nicvf *)nicvf_irq;
  681. u64 intr;
  682. nicvf_dump_intr_status(nic);
  683. intr = nicvf_reg_read(nic, NIC_VF_INT);
  684. /* Check for spurious interrupt */
  685. if (!(intr & NICVF_INTR_MBOX_MASK))
  686. return IRQ_HANDLED;
  687. nicvf_handle_mbx_intr(nic);
  688. return IRQ_HANDLED;
  689. }
  690. static irqreturn_t nicvf_intr_handler(int irq, void *cq_irq)
  691. {
  692. struct nicvf_cq_poll *cq_poll = (struct nicvf_cq_poll *)cq_irq;
  693. struct nicvf *nic = cq_poll->nicvf;
  694. int qidx = cq_poll->cq_idx;
  695. nicvf_dump_intr_status(nic);
  696. /* Disable interrupts */
  697. nicvf_disable_intr(nic, NICVF_INTR_CQ, qidx);
  698. /* Schedule NAPI */
  699. napi_schedule_irqoff(&cq_poll->napi);
  700. /* Clear interrupt */
  701. nicvf_clear_intr(nic, NICVF_INTR_CQ, qidx);
  702. return IRQ_HANDLED;
  703. }
  704. static irqreturn_t nicvf_rbdr_intr_handler(int irq, void *nicvf_irq)
  705. {
  706. struct nicvf *nic = (struct nicvf *)nicvf_irq;
  707. u8 qidx;
  708. nicvf_dump_intr_status(nic);
  709. /* Disable RBDR interrupt and schedule softirq */
  710. for (qidx = 0; qidx < nic->qs->rbdr_cnt; qidx++) {
  711. if (!nicvf_is_intr_enabled(nic, NICVF_INTR_RBDR, qidx))
  712. continue;
  713. nicvf_disable_intr(nic, NICVF_INTR_RBDR, qidx);
  714. tasklet_hi_schedule(&nic->rbdr_task);
  715. /* Clear interrupt */
  716. nicvf_clear_intr(nic, NICVF_INTR_RBDR, qidx);
  717. }
  718. return IRQ_HANDLED;
  719. }
  720. static irqreturn_t nicvf_qs_err_intr_handler(int irq, void *nicvf_irq)
  721. {
  722. struct nicvf *nic = (struct nicvf *)nicvf_irq;
  723. nicvf_dump_intr_status(nic);
  724. /* Disable Qset err interrupt and schedule softirq */
  725. nicvf_disable_intr(nic, NICVF_INTR_QS_ERR, 0);
  726. tasklet_hi_schedule(&nic->qs_err_task);
  727. nicvf_clear_intr(nic, NICVF_INTR_QS_ERR, 0);
  728. return IRQ_HANDLED;
  729. }
  730. static int nicvf_enable_msix(struct nicvf *nic)
  731. {
  732. int ret, vec;
  733. nic->num_vec = NIC_VF_MSIX_VECTORS;
  734. for (vec = 0; vec < nic->num_vec; vec++)
  735. nic->msix_entries[vec].entry = vec;
  736. ret = pci_enable_msix(nic->pdev, nic->msix_entries, nic->num_vec);
  737. if (ret) {
  738. netdev_err(nic->netdev,
  739. "Req for #%d msix vectors failed\n", nic->num_vec);
  740. return 0;
  741. }
  742. nic->msix_enabled = 1;
  743. return 1;
  744. }
  745. static void nicvf_disable_msix(struct nicvf *nic)
  746. {
  747. if (nic->msix_enabled) {
  748. pci_disable_msix(nic->pdev);
  749. nic->msix_enabled = 0;
  750. nic->num_vec = 0;
  751. }
  752. }
  753. static void nicvf_set_irq_affinity(struct nicvf *nic)
  754. {
  755. int vec, cpu;
  756. int irqnum;
  757. for (vec = 0; vec < nic->num_vec; vec++) {
  758. if (!nic->irq_allocated[vec])
  759. continue;
  760. if (!zalloc_cpumask_var(&nic->affinity_mask[vec], GFP_KERNEL))
  761. return;
  762. /* CQ interrupts */
  763. if (vec < NICVF_INTR_ID_SQ)
  764. /* Leave CPU0 for RBDR and other interrupts */
  765. cpu = nicvf_netdev_qidx(nic, vec) + 1;
  766. else
  767. cpu = 0;
  768. cpumask_set_cpu(cpumask_local_spread(cpu, nic->node),
  769. nic->affinity_mask[vec]);
  770. irqnum = nic->msix_entries[vec].vector;
  771. irq_set_affinity_hint(irqnum, nic->affinity_mask[vec]);
  772. }
  773. }
  774. static int nicvf_register_interrupts(struct nicvf *nic)
  775. {
  776. int irq, ret = 0;
  777. int vector;
  778. for_each_cq_irq(irq)
  779. sprintf(nic->irq_name[irq], "%s-rxtx-%d",
  780. nic->pnicvf->netdev->name,
  781. nicvf_netdev_qidx(nic, irq));
  782. for_each_sq_irq(irq)
  783. sprintf(nic->irq_name[irq], "%s-sq-%d",
  784. nic->pnicvf->netdev->name,
  785. nicvf_netdev_qidx(nic, irq - NICVF_INTR_ID_SQ));
  786. for_each_rbdr_irq(irq)
  787. sprintf(nic->irq_name[irq], "%s-rbdr-%d",
  788. nic->pnicvf->netdev->name,
  789. nic->sqs_mode ? (nic->sqs_id + 1) : 0);
  790. /* Register CQ interrupts */
  791. for (irq = 0; irq < nic->qs->cq_cnt; irq++) {
  792. vector = nic->msix_entries[irq].vector;
  793. ret = request_irq(vector, nicvf_intr_handler,
  794. 0, nic->irq_name[irq], nic->napi[irq]);
  795. if (ret)
  796. goto err;
  797. nic->irq_allocated[irq] = true;
  798. }
  799. /* Register RBDR interrupt */
  800. for (irq = NICVF_INTR_ID_RBDR;
  801. irq < (NICVF_INTR_ID_RBDR + nic->qs->rbdr_cnt); irq++) {
  802. vector = nic->msix_entries[irq].vector;
  803. ret = request_irq(vector, nicvf_rbdr_intr_handler,
  804. 0, nic->irq_name[irq], nic);
  805. if (ret)
  806. goto err;
  807. nic->irq_allocated[irq] = true;
  808. }
  809. /* Register QS error interrupt */
  810. sprintf(nic->irq_name[NICVF_INTR_ID_QS_ERR], "%s-qset-err-%d",
  811. nic->pnicvf->netdev->name,
  812. nic->sqs_mode ? (nic->sqs_id + 1) : 0);
  813. irq = NICVF_INTR_ID_QS_ERR;
  814. ret = request_irq(nic->msix_entries[irq].vector,
  815. nicvf_qs_err_intr_handler,
  816. 0, nic->irq_name[irq], nic);
  817. if (ret)
  818. goto err;
  819. nic->irq_allocated[irq] = true;
  820. /* Set IRQ affinities */
  821. nicvf_set_irq_affinity(nic);
  822. err:
  823. if (ret)
  824. netdev_err(nic->netdev, "request_irq failed, vector %d\n", irq);
  825. return ret;
  826. }
  827. static void nicvf_unregister_interrupts(struct nicvf *nic)
  828. {
  829. int irq;
  830. /* Free registered interrupts */
  831. for (irq = 0; irq < nic->num_vec; irq++) {
  832. if (!nic->irq_allocated[irq])
  833. continue;
  834. irq_set_affinity_hint(nic->msix_entries[irq].vector, NULL);
  835. free_cpumask_var(nic->affinity_mask[irq]);
  836. if (irq < NICVF_INTR_ID_SQ)
  837. free_irq(nic->msix_entries[irq].vector, nic->napi[irq]);
  838. else
  839. free_irq(nic->msix_entries[irq].vector, nic);
  840. nic->irq_allocated[irq] = false;
  841. }
  842. /* Disable MSI-X */
  843. nicvf_disable_msix(nic);
  844. }
  845. /* Initialize MSIX vectors and register MISC interrupt.
  846. * Send READY message to PF to check if its alive
  847. */
  848. static int nicvf_register_misc_interrupt(struct nicvf *nic)
  849. {
  850. int ret = 0;
  851. int irq = NICVF_INTR_ID_MISC;
  852. /* Return if mailbox interrupt is already registered */
  853. if (nic->msix_enabled)
  854. return 0;
  855. /* Enable MSI-X */
  856. if (!nicvf_enable_msix(nic))
  857. return 1;
  858. sprintf(nic->irq_name[irq], "%s Mbox", "NICVF");
  859. /* Register Misc interrupt */
  860. ret = request_irq(nic->msix_entries[irq].vector,
  861. nicvf_misc_intr_handler, 0, nic->irq_name[irq], nic);
  862. if (ret)
  863. return ret;
  864. nic->irq_allocated[irq] = true;
  865. /* Enable mailbox interrupt */
  866. nicvf_enable_intr(nic, NICVF_INTR_MBOX, 0);
  867. /* Check if VF is able to communicate with PF */
  868. if (!nicvf_check_pf_ready(nic)) {
  869. nicvf_disable_intr(nic, NICVF_INTR_MBOX, 0);
  870. nicvf_unregister_interrupts(nic);
  871. return 1;
  872. }
  873. return 0;
  874. }
  875. static netdev_tx_t nicvf_xmit(struct sk_buff *skb, struct net_device *netdev)
  876. {
  877. struct nicvf *nic = netdev_priv(netdev);
  878. int qid = skb_get_queue_mapping(skb);
  879. struct netdev_queue *txq = netdev_get_tx_queue(netdev, qid);
  880. /* Check for minimum packet length */
  881. if (skb->len <= ETH_HLEN) {
  882. dev_kfree_skb(skb);
  883. return NETDEV_TX_OK;
  884. }
  885. if (!netif_tx_queue_stopped(txq) && !nicvf_sq_append_skb(nic, skb)) {
  886. netif_tx_stop_queue(txq);
  887. this_cpu_inc(nic->drv_stats->txq_stop);
  888. if (netif_msg_tx_err(nic))
  889. netdev_warn(netdev,
  890. "%s: Transmit ring full, stopping SQ%d\n",
  891. netdev->name, qid);
  892. return NETDEV_TX_BUSY;
  893. }
  894. return NETDEV_TX_OK;
  895. }
  896. static inline void nicvf_free_cq_poll(struct nicvf *nic)
  897. {
  898. struct nicvf_cq_poll *cq_poll;
  899. int qidx;
  900. for (qidx = 0; qidx < nic->qs->cq_cnt; qidx++) {
  901. cq_poll = nic->napi[qidx];
  902. if (!cq_poll)
  903. continue;
  904. nic->napi[qidx] = NULL;
  905. kfree(cq_poll);
  906. }
  907. }
  908. int nicvf_stop(struct net_device *netdev)
  909. {
  910. int irq, qidx;
  911. struct nicvf *nic = netdev_priv(netdev);
  912. struct queue_set *qs = nic->qs;
  913. struct nicvf_cq_poll *cq_poll = NULL;
  914. union nic_mbx mbx = {};
  915. mbx.msg.msg = NIC_MBOX_MSG_SHUTDOWN;
  916. nicvf_send_msg_to_pf(nic, &mbx);
  917. netif_carrier_off(netdev);
  918. netif_tx_stop_all_queues(nic->netdev);
  919. nic->link_up = false;
  920. /* Teardown secondary qsets first */
  921. if (!nic->sqs_mode) {
  922. for (qidx = 0; qidx < nic->sqs_count; qidx++) {
  923. if (!nic->snicvf[qidx])
  924. continue;
  925. nicvf_stop(nic->snicvf[qidx]->netdev);
  926. nic->snicvf[qidx] = NULL;
  927. }
  928. }
  929. /* Disable RBDR & QS error interrupts */
  930. for (qidx = 0; qidx < qs->rbdr_cnt; qidx++) {
  931. nicvf_disable_intr(nic, NICVF_INTR_RBDR, qidx);
  932. nicvf_clear_intr(nic, NICVF_INTR_RBDR, qidx);
  933. }
  934. nicvf_disable_intr(nic, NICVF_INTR_QS_ERR, 0);
  935. nicvf_clear_intr(nic, NICVF_INTR_QS_ERR, 0);
  936. /* Wait for pending IRQ handlers to finish */
  937. for (irq = 0; irq < nic->num_vec; irq++)
  938. synchronize_irq(nic->msix_entries[irq].vector);
  939. tasklet_kill(&nic->rbdr_task);
  940. tasklet_kill(&nic->qs_err_task);
  941. if (nic->rb_work_scheduled)
  942. cancel_delayed_work_sync(&nic->rbdr_work);
  943. for (qidx = 0; qidx < nic->qs->cq_cnt; qidx++) {
  944. cq_poll = nic->napi[qidx];
  945. if (!cq_poll)
  946. continue;
  947. napi_synchronize(&cq_poll->napi);
  948. /* CQ intr is enabled while napi_complete,
  949. * so disable it now
  950. */
  951. nicvf_disable_intr(nic, NICVF_INTR_CQ, qidx);
  952. nicvf_clear_intr(nic, NICVF_INTR_CQ, qidx);
  953. napi_disable(&cq_poll->napi);
  954. netif_napi_del(&cq_poll->napi);
  955. }
  956. netif_tx_disable(netdev);
  957. for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
  958. netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
  959. /* Free resources */
  960. nicvf_config_data_transfer(nic, false);
  961. /* Disable HW Qset */
  962. nicvf_qset_config(nic, false);
  963. /* disable mailbox interrupt */
  964. nicvf_disable_intr(nic, NICVF_INTR_MBOX, 0);
  965. nicvf_unregister_interrupts(nic);
  966. nicvf_free_cq_poll(nic);
  967. /* Clear multiqset info */
  968. nic->pnicvf = nic;
  969. return 0;
  970. }
  971. static int nicvf_update_hw_max_frs(struct nicvf *nic, int mtu)
  972. {
  973. union nic_mbx mbx = {};
  974. mbx.frs.msg = NIC_MBOX_MSG_SET_MAX_FRS;
  975. mbx.frs.max_frs = mtu;
  976. mbx.frs.vf_id = nic->vf_id;
  977. return nicvf_send_msg_to_pf(nic, &mbx);
  978. }
  979. int nicvf_open(struct net_device *netdev)
  980. {
  981. int cpu, err, qidx;
  982. struct nicvf *nic = netdev_priv(netdev);
  983. struct queue_set *qs = nic->qs;
  984. struct nicvf_cq_poll *cq_poll = NULL;
  985. union nic_mbx mbx = {};
  986. netif_carrier_off(netdev);
  987. err = nicvf_register_misc_interrupt(nic);
  988. if (err)
  989. return err;
  990. /* Register NAPI handler for processing CQEs */
  991. for (qidx = 0; qidx < qs->cq_cnt; qidx++) {
  992. cq_poll = kzalloc(sizeof(*cq_poll), GFP_KERNEL);
  993. if (!cq_poll) {
  994. err = -ENOMEM;
  995. goto napi_del;
  996. }
  997. cq_poll->cq_idx = qidx;
  998. cq_poll->nicvf = nic;
  999. netif_napi_add(netdev, &cq_poll->napi, nicvf_poll,
  1000. NAPI_POLL_WEIGHT);
  1001. napi_enable(&cq_poll->napi);
  1002. nic->napi[qidx] = cq_poll;
  1003. }
  1004. /* Check if we got MAC address from PF or else generate a radom MAC */
  1005. if (!nic->sqs_mode && is_zero_ether_addr(netdev->dev_addr)) {
  1006. eth_hw_addr_random(netdev);
  1007. nicvf_hw_set_mac_addr(nic, netdev);
  1008. }
  1009. if (nic->set_mac_pending) {
  1010. nic->set_mac_pending = false;
  1011. nicvf_hw_set_mac_addr(nic, netdev);
  1012. }
  1013. /* Init tasklet for handling Qset err interrupt */
  1014. tasklet_init(&nic->qs_err_task, nicvf_handle_qs_err,
  1015. (unsigned long)nic);
  1016. /* Init RBDR tasklet which will refill RBDR */
  1017. tasklet_init(&nic->rbdr_task, nicvf_rbdr_task,
  1018. (unsigned long)nic);
  1019. INIT_DELAYED_WORK(&nic->rbdr_work, nicvf_rbdr_work);
  1020. /* Configure CPI alorithm */
  1021. nic->cpi_alg = cpi_alg;
  1022. if (!nic->sqs_mode)
  1023. nicvf_config_cpi(nic);
  1024. nicvf_request_sqs(nic);
  1025. if (nic->sqs_mode)
  1026. nicvf_get_primary_vf_struct(nic);
  1027. /* Configure receive side scaling and MTU */
  1028. if (!nic->sqs_mode) {
  1029. nicvf_rss_init(nic);
  1030. if (nicvf_update_hw_max_frs(nic, netdev->mtu))
  1031. goto cleanup;
  1032. /* Clear percpu stats */
  1033. for_each_possible_cpu(cpu)
  1034. memset(per_cpu_ptr(nic->drv_stats, cpu), 0,
  1035. sizeof(struct nicvf_drv_stats));
  1036. }
  1037. err = nicvf_register_interrupts(nic);
  1038. if (err)
  1039. goto cleanup;
  1040. /* Initialize the queues */
  1041. err = nicvf_init_resources(nic);
  1042. if (err)
  1043. goto cleanup;
  1044. /* Make sure queue initialization is written */
  1045. wmb();
  1046. nicvf_reg_write(nic, NIC_VF_INT, -1);
  1047. /* Enable Qset err interrupt */
  1048. nicvf_enable_intr(nic, NICVF_INTR_QS_ERR, 0);
  1049. /* Enable completion queue interrupt */
  1050. for (qidx = 0; qidx < qs->cq_cnt; qidx++)
  1051. nicvf_enable_intr(nic, NICVF_INTR_CQ, qidx);
  1052. /* Enable RBDR threshold interrupt */
  1053. for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
  1054. nicvf_enable_intr(nic, NICVF_INTR_RBDR, qidx);
  1055. /* Send VF config done msg to PF */
  1056. mbx.msg.msg = NIC_MBOX_MSG_CFG_DONE;
  1057. nicvf_write_to_mbx(nic, &mbx);
  1058. return 0;
  1059. cleanup:
  1060. nicvf_disable_intr(nic, NICVF_INTR_MBOX, 0);
  1061. nicvf_unregister_interrupts(nic);
  1062. tasklet_kill(&nic->qs_err_task);
  1063. tasklet_kill(&nic->rbdr_task);
  1064. napi_del:
  1065. for (qidx = 0; qidx < qs->cq_cnt; qidx++) {
  1066. cq_poll = nic->napi[qidx];
  1067. if (!cq_poll)
  1068. continue;
  1069. napi_disable(&cq_poll->napi);
  1070. netif_napi_del(&cq_poll->napi);
  1071. }
  1072. nicvf_free_cq_poll(nic);
  1073. return err;
  1074. }
  1075. static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
  1076. {
  1077. struct nicvf *nic = netdev_priv(netdev);
  1078. if (new_mtu > NIC_HW_MAX_FRS)
  1079. return -EINVAL;
  1080. if (new_mtu < NIC_HW_MIN_FRS)
  1081. return -EINVAL;
  1082. netdev->mtu = new_mtu;
  1083. if (!netif_running(netdev))
  1084. return 0;
  1085. if (nicvf_update_hw_max_frs(nic, new_mtu))
  1086. return -EINVAL;
  1087. return 0;
  1088. }
  1089. static int nicvf_set_mac_address(struct net_device *netdev, void *p)
  1090. {
  1091. struct sockaddr *addr = p;
  1092. struct nicvf *nic = netdev_priv(netdev);
  1093. if (!is_valid_ether_addr(addr->sa_data))
  1094. return -EADDRNOTAVAIL;
  1095. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1096. if (nic->msix_enabled) {
  1097. if (nicvf_hw_set_mac_addr(nic, netdev))
  1098. return -EBUSY;
  1099. } else {
  1100. nic->set_mac_pending = true;
  1101. }
  1102. return 0;
  1103. }
  1104. void nicvf_update_lmac_stats(struct nicvf *nic)
  1105. {
  1106. int stat = 0;
  1107. union nic_mbx mbx = {};
  1108. if (!netif_running(nic->netdev))
  1109. return;
  1110. mbx.bgx_stats.msg = NIC_MBOX_MSG_BGX_STATS;
  1111. mbx.bgx_stats.vf_id = nic->vf_id;
  1112. /* Rx stats */
  1113. mbx.bgx_stats.rx = 1;
  1114. while (stat < BGX_RX_STATS_COUNT) {
  1115. mbx.bgx_stats.idx = stat;
  1116. if (nicvf_send_msg_to_pf(nic, &mbx))
  1117. return;
  1118. stat++;
  1119. }
  1120. stat = 0;
  1121. /* Tx stats */
  1122. mbx.bgx_stats.rx = 0;
  1123. while (stat < BGX_TX_STATS_COUNT) {
  1124. mbx.bgx_stats.idx = stat;
  1125. if (nicvf_send_msg_to_pf(nic, &mbx))
  1126. return;
  1127. stat++;
  1128. }
  1129. }
  1130. void nicvf_update_stats(struct nicvf *nic)
  1131. {
  1132. int qidx, cpu;
  1133. u64 tmp_stats = 0;
  1134. struct nicvf_hw_stats *stats = &nic->hw_stats;
  1135. struct nicvf_drv_stats *drv_stats;
  1136. struct queue_set *qs = nic->qs;
  1137. #define GET_RX_STATS(reg) \
  1138. nicvf_reg_read(nic, NIC_VNIC_RX_STAT_0_13 | (reg << 3))
  1139. #define GET_TX_STATS(reg) \
  1140. nicvf_reg_read(nic, NIC_VNIC_TX_STAT_0_4 | (reg << 3))
  1141. stats->rx_bytes = GET_RX_STATS(RX_OCTS);
  1142. stats->rx_ucast_frames = GET_RX_STATS(RX_UCAST);
  1143. stats->rx_bcast_frames = GET_RX_STATS(RX_BCAST);
  1144. stats->rx_mcast_frames = GET_RX_STATS(RX_MCAST);
  1145. stats->rx_fcs_errors = GET_RX_STATS(RX_FCS);
  1146. stats->rx_l2_errors = GET_RX_STATS(RX_L2ERR);
  1147. stats->rx_drop_red = GET_RX_STATS(RX_RED);
  1148. stats->rx_drop_red_bytes = GET_RX_STATS(RX_RED_OCTS);
  1149. stats->rx_drop_overrun = GET_RX_STATS(RX_ORUN);
  1150. stats->rx_drop_overrun_bytes = GET_RX_STATS(RX_ORUN_OCTS);
  1151. stats->rx_drop_bcast = GET_RX_STATS(RX_DRP_BCAST);
  1152. stats->rx_drop_mcast = GET_RX_STATS(RX_DRP_MCAST);
  1153. stats->rx_drop_l3_bcast = GET_RX_STATS(RX_DRP_L3BCAST);
  1154. stats->rx_drop_l3_mcast = GET_RX_STATS(RX_DRP_L3MCAST);
  1155. stats->tx_bytes = GET_TX_STATS(TX_OCTS);
  1156. stats->tx_ucast_frames = GET_TX_STATS(TX_UCAST);
  1157. stats->tx_bcast_frames = GET_TX_STATS(TX_BCAST);
  1158. stats->tx_mcast_frames = GET_TX_STATS(TX_MCAST);
  1159. stats->tx_drops = GET_TX_STATS(TX_DROP);
  1160. /* On T88 pass 2.0, the dummy SQE added for TSO notification
  1161. * via CQE has 'dont_send' set. Hence HW drops the pkt pointed
  1162. * pointed by dummy SQE and results in tx_drops counter being
  1163. * incremented. Subtracting it from tx_tso counter will give
  1164. * exact tx_drops counter.
  1165. */
  1166. if (nic->t88 && nic->hw_tso) {
  1167. for_each_possible_cpu(cpu) {
  1168. drv_stats = per_cpu_ptr(nic->drv_stats, cpu);
  1169. tmp_stats += drv_stats->tx_tso;
  1170. }
  1171. stats->tx_drops = tmp_stats - stats->tx_drops;
  1172. }
  1173. stats->tx_frames = stats->tx_ucast_frames +
  1174. stats->tx_bcast_frames +
  1175. stats->tx_mcast_frames;
  1176. stats->rx_frames = stats->rx_ucast_frames +
  1177. stats->rx_bcast_frames +
  1178. stats->rx_mcast_frames;
  1179. stats->rx_drops = stats->rx_drop_red +
  1180. stats->rx_drop_overrun;
  1181. /* Update RQ and SQ stats */
  1182. for (qidx = 0; qidx < qs->rq_cnt; qidx++)
  1183. nicvf_update_rq_stats(nic, qidx);
  1184. for (qidx = 0; qidx < qs->sq_cnt; qidx++)
  1185. nicvf_update_sq_stats(nic, qidx);
  1186. }
  1187. static struct rtnl_link_stats64 *nicvf_get_stats64(struct net_device *netdev,
  1188. struct rtnl_link_stats64 *stats)
  1189. {
  1190. struct nicvf *nic = netdev_priv(netdev);
  1191. struct nicvf_hw_stats *hw_stats = &nic->hw_stats;
  1192. nicvf_update_stats(nic);
  1193. stats->rx_bytes = hw_stats->rx_bytes;
  1194. stats->rx_packets = hw_stats->rx_frames;
  1195. stats->rx_dropped = hw_stats->rx_drops;
  1196. stats->multicast = hw_stats->rx_mcast_frames;
  1197. stats->tx_bytes = hw_stats->tx_bytes;
  1198. stats->tx_packets = hw_stats->tx_frames;
  1199. stats->tx_dropped = hw_stats->tx_drops;
  1200. return stats;
  1201. }
  1202. static void nicvf_tx_timeout(struct net_device *dev)
  1203. {
  1204. struct nicvf *nic = netdev_priv(dev);
  1205. if (netif_msg_tx_err(nic))
  1206. netdev_warn(dev, "%s: Transmit timed out, resetting\n",
  1207. dev->name);
  1208. this_cpu_inc(nic->drv_stats->tx_timeout);
  1209. schedule_work(&nic->reset_task);
  1210. }
  1211. static void nicvf_reset_task(struct work_struct *work)
  1212. {
  1213. struct nicvf *nic;
  1214. nic = container_of(work, struct nicvf, reset_task);
  1215. if (!netif_running(nic->netdev))
  1216. return;
  1217. nicvf_stop(nic->netdev);
  1218. nicvf_open(nic->netdev);
  1219. netif_trans_update(nic->netdev);
  1220. }
  1221. static int nicvf_config_loopback(struct nicvf *nic,
  1222. netdev_features_t features)
  1223. {
  1224. union nic_mbx mbx = {};
  1225. mbx.lbk.msg = NIC_MBOX_MSG_LOOPBACK;
  1226. mbx.lbk.vf_id = nic->vf_id;
  1227. mbx.lbk.enable = (features & NETIF_F_LOOPBACK) != 0;
  1228. return nicvf_send_msg_to_pf(nic, &mbx);
  1229. }
  1230. static netdev_features_t nicvf_fix_features(struct net_device *netdev,
  1231. netdev_features_t features)
  1232. {
  1233. struct nicvf *nic = netdev_priv(netdev);
  1234. if ((features & NETIF_F_LOOPBACK) &&
  1235. netif_running(netdev) && !nic->loopback_supported)
  1236. features &= ~NETIF_F_LOOPBACK;
  1237. return features;
  1238. }
  1239. static int nicvf_set_features(struct net_device *netdev,
  1240. netdev_features_t features)
  1241. {
  1242. struct nicvf *nic = netdev_priv(netdev);
  1243. netdev_features_t changed = features ^ netdev->features;
  1244. if (changed & NETIF_F_HW_VLAN_CTAG_RX)
  1245. nicvf_config_vlan_stripping(nic, features);
  1246. if ((changed & NETIF_F_LOOPBACK) && netif_running(netdev))
  1247. return nicvf_config_loopback(nic, features);
  1248. return 0;
  1249. }
  1250. static const struct net_device_ops nicvf_netdev_ops = {
  1251. .ndo_open = nicvf_open,
  1252. .ndo_stop = nicvf_stop,
  1253. .ndo_start_xmit = nicvf_xmit,
  1254. .ndo_change_mtu = nicvf_change_mtu,
  1255. .ndo_set_mac_address = nicvf_set_mac_address,
  1256. .ndo_get_stats64 = nicvf_get_stats64,
  1257. .ndo_tx_timeout = nicvf_tx_timeout,
  1258. .ndo_fix_features = nicvf_fix_features,
  1259. .ndo_set_features = nicvf_set_features,
  1260. };
  1261. static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1262. {
  1263. struct device *dev = &pdev->dev;
  1264. struct net_device *netdev;
  1265. struct nicvf *nic;
  1266. int err, qcount;
  1267. u16 sdevid;
  1268. err = pci_enable_device(pdev);
  1269. if (err) {
  1270. dev_err(dev, "Failed to enable PCI device\n");
  1271. return err;
  1272. }
  1273. err = pci_request_regions(pdev, DRV_NAME);
  1274. if (err) {
  1275. dev_err(dev, "PCI request regions failed 0x%x\n", err);
  1276. goto err_disable_device;
  1277. }
  1278. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(48));
  1279. if (err) {
  1280. dev_err(dev, "Unable to get usable DMA configuration\n");
  1281. goto err_release_regions;
  1282. }
  1283. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(48));
  1284. if (err) {
  1285. dev_err(dev, "unable to get 48-bit DMA for consistent allocations\n");
  1286. goto err_release_regions;
  1287. }
  1288. qcount = netif_get_num_default_rss_queues();
  1289. /* Restrict multiqset support only for host bound VFs */
  1290. if (pdev->is_virtfn) {
  1291. /* Set max number of queues per VF */
  1292. qcount = min_t(int, num_online_cpus(),
  1293. (MAX_SQS_PER_VF + 1) * MAX_CMP_QUEUES_PER_QS);
  1294. }
  1295. netdev = alloc_etherdev_mqs(sizeof(struct nicvf), qcount, qcount);
  1296. if (!netdev) {
  1297. err = -ENOMEM;
  1298. goto err_release_regions;
  1299. }
  1300. pci_set_drvdata(pdev, netdev);
  1301. SET_NETDEV_DEV(netdev, &pdev->dev);
  1302. nic = netdev_priv(netdev);
  1303. nic->netdev = netdev;
  1304. nic->pdev = pdev;
  1305. nic->pnicvf = nic;
  1306. nic->max_queues = qcount;
  1307. /* If no of CPUs are too low, there won't be any queues left
  1308. * for XDP_TX, hence double it.
  1309. */
  1310. if (!nic->t88)
  1311. nic->max_queues *= 2;
  1312. /* MAP VF's configuration registers */
  1313. nic->reg_base = pcim_iomap(pdev, PCI_CFG_REG_BAR_NUM, 0);
  1314. if (!nic->reg_base) {
  1315. dev_err(dev, "Cannot map config register space, aborting\n");
  1316. err = -ENOMEM;
  1317. goto err_free_netdev;
  1318. }
  1319. nic->drv_stats = netdev_alloc_pcpu_stats(struct nicvf_drv_stats);
  1320. if (!nic->drv_stats) {
  1321. err = -ENOMEM;
  1322. goto err_free_netdev;
  1323. }
  1324. err = nicvf_set_qset_resources(nic);
  1325. if (err)
  1326. goto err_free_netdev;
  1327. /* Check if PF is alive and get MAC address for this VF */
  1328. err = nicvf_register_misc_interrupt(nic);
  1329. if (err)
  1330. goto err_free_netdev;
  1331. nicvf_send_vf_struct(nic);
  1332. if (!pass1_silicon(nic->pdev))
  1333. nic->hw_tso = true;
  1334. pci_read_config_word(nic->pdev, PCI_SUBSYSTEM_ID, &sdevid);
  1335. if (sdevid == 0xA134)
  1336. nic->t88 = true;
  1337. /* Check if this VF is in QS only mode */
  1338. if (nic->sqs_mode)
  1339. return 0;
  1340. err = nicvf_set_real_num_queues(netdev, nic->tx_queues, nic->rx_queues);
  1341. if (err)
  1342. goto err_unregister_interrupts;
  1343. netdev->hw_features = (NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
  1344. NETIF_F_TSO | NETIF_F_GRO |
  1345. NETIF_F_HW_VLAN_CTAG_RX);
  1346. netdev->hw_features |= NETIF_F_RXHASH;
  1347. netdev->features |= netdev->hw_features;
  1348. netdev->hw_features |= NETIF_F_LOOPBACK;
  1349. netdev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
  1350. netdev->netdev_ops = &nicvf_netdev_ops;
  1351. netdev->watchdog_timeo = NICVF_TX_TIMEOUT;
  1352. INIT_WORK(&nic->reset_task, nicvf_reset_task);
  1353. err = register_netdev(netdev);
  1354. if (err) {
  1355. dev_err(dev, "Failed to register netdevice\n");
  1356. goto err_unregister_interrupts;
  1357. }
  1358. nic->msg_enable = debug;
  1359. nicvf_set_ethtool_ops(netdev);
  1360. return 0;
  1361. err_unregister_interrupts:
  1362. nicvf_unregister_interrupts(nic);
  1363. err_free_netdev:
  1364. pci_set_drvdata(pdev, NULL);
  1365. if (nic->drv_stats)
  1366. free_percpu(nic->drv_stats);
  1367. free_netdev(netdev);
  1368. err_release_regions:
  1369. pci_release_regions(pdev);
  1370. err_disable_device:
  1371. pci_disable_device(pdev);
  1372. return err;
  1373. }
  1374. static void nicvf_remove(struct pci_dev *pdev)
  1375. {
  1376. struct net_device *netdev = pci_get_drvdata(pdev);
  1377. struct nicvf *nic;
  1378. struct net_device *pnetdev;
  1379. if (!netdev)
  1380. return;
  1381. nic = netdev_priv(netdev);
  1382. pnetdev = nic->pnicvf->netdev;
  1383. /* Check if this Qset is assigned to different VF.
  1384. * If yes, clean primary and all secondary Qsets.
  1385. */
  1386. if (pnetdev && (pnetdev->reg_state == NETREG_REGISTERED))
  1387. unregister_netdev(pnetdev);
  1388. nicvf_unregister_interrupts(nic);
  1389. pci_set_drvdata(pdev, NULL);
  1390. if (nic->drv_stats)
  1391. free_percpu(nic->drv_stats);
  1392. free_netdev(netdev);
  1393. pci_release_regions(pdev);
  1394. pci_disable_device(pdev);
  1395. }
  1396. static void nicvf_shutdown(struct pci_dev *pdev)
  1397. {
  1398. nicvf_remove(pdev);
  1399. }
  1400. static struct pci_driver nicvf_driver = {
  1401. .name = DRV_NAME,
  1402. .id_table = nicvf_id_table,
  1403. .probe = nicvf_probe,
  1404. .remove = nicvf_remove,
  1405. .shutdown = nicvf_shutdown,
  1406. };
  1407. static int __init nicvf_init_module(void)
  1408. {
  1409. pr_info("%s, ver %s\n", DRV_NAME, DRV_VERSION);
  1410. return pci_register_driver(&nicvf_driver);
  1411. }
  1412. static void __exit nicvf_cleanup_module(void)
  1413. {
  1414. pci_unregister_driver(&nicvf_driver);
  1415. }
  1416. module_init(nicvf_init_module);
  1417. module_exit(nicvf_cleanup_module);