lio_vf_main.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more details.
  17. ***********************************************************************/
  18. #include <linux/module.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #include <net/vxlan.h>
  22. #include "liquidio_common.h"
  23. #include "octeon_droq.h"
  24. #include "octeon_iq.h"
  25. #include "response_manager.h"
  26. #include "octeon_device.h"
  27. #include "octeon_nic.h"
  28. #include "octeon_main.h"
  29. #include "octeon_network.h"
  30. #include "cn23xx_vf_device.h"
  31. MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
  32. MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Virtual Function Driver");
  33. MODULE_LICENSE("GPL");
  34. MODULE_VERSION(LIQUIDIO_VERSION);
  35. static int debug = -1;
  36. module_param(debug, int, 0644);
  37. MODULE_PARM_DESC(debug, "NETIF_MSG debug bits");
  38. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  39. struct liquidio_rx_ctl_context {
  40. int octeon_id;
  41. wait_queue_head_t wc;
  42. int cond;
  43. };
  44. struct oct_timestamp_resp {
  45. u64 rh;
  46. u64 timestamp;
  47. u64 status;
  48. };
  49. union tx_info {
  50. u64 u64;
  51. struct {
  52. #ifdef __BIG_ENDIAN_BITFIELD
  53. u16 gso_size;
  54. u16 gso_segs;
  55. u32 reserved;
  56. #else
  57. u32 reserved;
  58. u16 gso_segs;
  59. u16 gso_size;
  60. #endif
  61. } s;
  62. };
  63. #define OCTNIC_GSO_MAX_HEADER_SIZE 128
  64. #define OCTNIC_GSO_MAX_SIZE \
  65. (CN23XX_DEFAULT_INPUT_JABBER - OCTNIC_GSO_MAX_HEADER_SIZE)
  66. static int
  67. liquidio_vf_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  68. static void liquidio_vf_remove(struct pci_dev *pdev);
  69. static int octeon_device_init(struct octeon_device *oct);
  70. static int liquidio_stop(struct net_device *netdev);
  71. static int lio_wait_for_oq_pkts(struct octeon_device *oct)
  72. {
  73. struct octeon_device_priv *oct_priv =
  74. (struct octeon_device_priv *)oct->priv;
  75. int retry = MAX_IO_PENDING_PKT_COUNT;
  76. int pkt_cnt = 0, pending_pkts;
  77. int i;
  78. do {
  79. pending_pkts = 0;
  80. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  81. if (!(oct->io_qmask.oq & BIT_ULL(i)))
  82. continue;
  83. pkt_cnt += octeon_droq_check_hw_for_pkts(oct->droq[i]);
  84. }
  85. if (pkt_cnt > 0) {
  86. pending_pkts += pkt_cnt;
  87. tasklet_schedule(&oct_priv->droq_tasklet);
  88. }
  89. pkt_cnt = 0;
  90. schedule_timeout_uninterruptible(1);
  91. } while (retry-- && pending_pkts);
  92. return pkt_cnt;
  93. }
  94. /**
  95. * \brief Cause device to go quiet so it can be safely removed/reset/etc
  96. * @param oct Pointer to Octeon device
  97. */
  98. static void pcierror_quiesce_device(struct octeon_device *oct)
  99. {
  100. int i;
  101. /* Disable the input and output queues now. No more packets will
  102. * arrive from Octeon, but we should wait for all packet processing
  103. * to finish.
  104. */
  105. /* To allow for in-flight requests */
  106. schedule_timeout_uninterruptible(100);
  107. if (wait_for_pending_requests(oct))
  108. dev_err(&oct->pci_dev->dev, "There were pending requests\n");
  109. /* Force all requests waiting to be fetched by OCTEON to complete. */
  110. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  111. struct octeon_instr_queue *iq;
  112. if (!(oct->io_qmask.iq & BIT_ULL(i)))
  113. continue;
  114. iq = oct->instr_queue[i];
  115. if (atomic_read(&iq->instr_pending)) {
  116. spin_lock_bh(&iq->lock);
  117. iq->fill_cnt = 0;
  118. iq->octeon_read_index = iq->host_write_index;
  119. iq->stats.instr_processed +=
  120. atomic_read(&iq->instr_pending);
  121. lio_process_iq_request_list(oct, iq, 0);
  122. spin_unlock_bh(&iq->lock);
  123. }
  124. }
  125. /* Force all pending ordered list requests to time out. */
  126. lio_process_ordered_list(oct, 1);
  127. /* We do not need to wait for output queue packets to be processed. */
  128. }
  129. /**
  130. * \brief Cleanup PCI AER uncorrectable error status
  131. * @param dev Pointer to PCI device
  132. */
  133. static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
  134. {
  135. u32 status, mask;
  136. int pos = 0x100;
  137. pr_info("%s :\n", __func__);
  138. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
  139. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
  140. if (dev->error_state == pci_channel_io_normal)
  141. status &= ~mask; /* Clear corresponding nonfatal bits */
  142. else
  143. status &= mask; /* Clear corresponding fatal bits */
  144. pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
  145. }
  146. /**
  147. * \brief Stop all PCI IO to a given device
  148. * @param dev Pointer to Octeon device
  149. */
  150. static void stop_pci_io(struct octeon_device *oct)
  151. {
  152. struct msix_entry *msix_entries;
  153. int i;
  154. /* No more instructions will be forwarded. */
  155. atomic_set(&oct->status, OCT_DEV_IN_RESET);
  156. for (i = 0; i < oct->ifcount; i++)
  157. netif_device_detach(oct->props[i].netdev);
  158. /* Disable interrupts */
  159. oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
  160. pcierror_quiesce_device(oct);
  161. if (oct->msix_on) {
  162. msix_entries = (struct msix_entry *)oct->msix_entries;
  163. for (i = 0; i < oct->num_msix_irqs; i++) {
  164. /* clear the affinity_cpumask */
  165. irq_set_affinity_hint(msix_entries[i].vector,
  166. NULL);
  167. free_irq(msix_entries[i].vector,
  168. &oct->ioq_vector[i]);
  169. }
  170. pci_disable_msix(oct->pci_dev);
  171. kfree(oct->msix_entries);
  172. oct->msix_entries = NULL;
  173. octeon_free_ioq_vector(oct);
  174. }
  175. dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
  176. lio_get_state_string(&oct->status));
  177. /* making it a common function for all OCTEON models */
  178. cleanup_aer_uncorrect_error_status(oct->pci_dev);
  179. pci_disable_device(oct->pci_dev);
  180. }
  181. /**
  182. * \brief called when PCI error is detected
  183. * @param pdev Pointer to PCI device
  184. * @param state The current pci connection state
  185. *
  186. * This function is called after a PCI bus error affecting
  187. * this device has been detected.
  188. */
  189. static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev,
  190. pci_channel_state_t state)
  191. {
  192. struct octeon_device *oct = pci_get_drvdata(pdev);
  193. /* Non-correctable Non-fatal errors */
  194. if (state == pci_channel_io_normal) {
  195. dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n");
  196. cleanup_aer_uncorrect_error_status(oct->pci_dev);
  197. return PCI_ERS_RESULT_CAN_RECOVER;
  198. }
  199. /* Non-correctable Fatal errors */
  200. dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n");
  201. stop_pci_io(oct);
  202. return PCI_ERS_RESULT_DISCONNECT;
  203. }
  204. /* For PCI-E Advanced Error Recovery (AER) Interface */
  205. static const struct pci_error_handlers liquidio_vf_err_handler = {
  206. .error_detected = liquidio_pcie_error_detected,
  207. };
  208. static const struct pci_device_id liquidio_vf_pci_tbl[] = {
  209. {
  210. PCI_VENDOR_ID_CAVIUM, OCTEON_CN23XX_VF_VID,
  211. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
  212. },
  213. {
  214. 0, 0, 0, 0, 0, 0, 0
  215. }
  216. };
  217. MODULE_DEVICE_TABLE(pci, liquidio_vf_pci_tbl);
  218. static struct pci_driver liquidio_vf_pci_driver = {
  219. .name = "LiquidIO_VF",
  220. .id_table = liquidio_vf_pci_tbl,
  221. .probe = liquidio_vf_probe,
  222. .remove = liquidio_vf_remove,
  223. .err_handler = &liquidio_vf_err_handler, /* For AER */
  224. };
  225. /**
  226. * \brief Print link information
  227. * @param netdev network device
  228. */
  229. static void print_link_info(struct net_device *netdev)
  230. {
  231. struct lio *lio = GET_LIO(netdev);
  232. if (!ifstate_check(lio, LIO_IFSTATE_RESETTING) &&
  233. ifstate_check(lio, LIO_IFSTATE_REGISTERED)) {
  234. struct oct_link_info *linfo = &lio->linfo;
  235. if (linfo->link.s.link_up) {
  236. netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n",
  237. linfo->link.s.speed,
  238. (linfo->link.s.duplex) ? "Full" : "Half");
  239. } else {
  240. netif_info(lio, link, lio->netdev, "Link Down\n");
  241. }
  242. }
  243. }
  244. /**
  245. * \brief Routine to notify MTU change
  246. * @param work work_struct data structure
  247. */
  248. static void octnet_link_status_change(struct work_struct *work)
  249. {
  250. struct cavium_wk *wk = (struct cavium_wk *)work;
  251. struct lio *lio = (struct lio *)wk->ctxptr;
  252. /* lio->linfo.link.s.mtu always contains max MTU of the lio interface.
  253. * this API is invoked only when new max-MTU of the interface is
  254. * less than current MTU.
  255. */
  256. rtnl_lock();
  257. dev_set_mtu(lio->netdev, lio->linfo.link.s.mtu);
  258. rtnl_unlock();
  259. }
  260. /**
  261. * \brief Sets up the mtu status change work
  262. * @param netdev network device
  263. */
  264. static int setup_link_status_change_wq(struct net_device *netdev)
  265. {
  266. struct lio *lio = GET_LIO(netdev);
  267. struct octeon_device *oct = lio->oct_dev;
  268. lio->link_status_wq.wq = alloc_workqueue("link-status",
  269. WQ_MEM_RECLAIM, 0);
  270. if (!lio->link_status_wq.wq) {
  271. dev_err(&oct->pci_dev->dev, "unable to create cavium link status wq\n");
  272. return -1;
  273. }
  274. INIT_DELAYED_WORK(&lio->link_status_wq.wk.work,
  275. octnet_link_status_change);
  276. lio->link_status_wq.wk.ctxptr = lio;
  277. return 0;
  278. }
  279. static void cleanup_link_status_change_wq(struct net_device *netdev)
  280. {
  281. struct lio *lio = GET_LIO(netdev);
  282. if (lio->link_status_wq.wq) {
  283. cancel_delayed_work_sync(&lio->link_status_wq.wk.work);
  284. destroy_workqueue(lio->link_status_wq.wq);
  285. }
  286. }
  287. /**
  288. * \brief Update link status
  289. * @param netdev network device
  290. * @param ls link status structure
  291. *
  292. * Called on receipt of a link status response from the core application to
  293. * update each interface's link status.
  294. */
  295. static void update_link_status(struct net_device *netdev,
  296. union oct_link_status *ls)
  297. {
  298. struct lio *lio = GET_LIO(netdev);
  299. int current_max_mtu = lio->linfo.link.s.mtu;
  300. struct octeon_device *oct = lio->oct_dev;
  301. if ((lio->intf_open) && (lio->linfo.link.u64 != ls->u64)) {
  302. lio->linfo.link.u64 = ls->u64;
  303. print_link_info(netdev);
  304. lio->link_changes++;
  305. if (lio->linfo.link.s.link_up) {
  306. netif_carrier_on(netdev);
  307. wake_txqs(netdev);
  308. } else {
  309. netif_carrier_off(netdev);
  310. stop_txqs(netdev);
  311. }
  312. if (lio->linfo.link.s.mtu != current_max_mtu) {
  313. dev_info(&oct->pci_dev->dev,
  314. "Max MTU Changed from %d to %d\n",
  315. current_max_mtu, lio->linfo.link.s.mtu);
  316. netdev->max_mtu = lio->linfo.link.s.mtu;
  317. }
  318. if (lio->linfo.link.s.mtu < netdev->mtu) {
  319. dev_warn(&oct->pci_dev->dev,
  320. "Current MTU is higher than new max MTU; Reducing the current mtu from %d to %d\n",
  321. netdev->mtu, lio->linfo.link.s.mtu);
  322. queue_delayed_work(lio->link_status_wq.wq,
  323. &lio->link_status_wq.wk.work, 0);
  324. }
  325. }
  326. }
  327. /**
  328. * \brief PCI probe handler
  329. * @param pdev PCI device structure
  330. * @param ent unused
  331. */
  332. static int
  333. liquidio_vf_probe(struct pci_dev *pdev,
  334. const struct pci_device_id *ent __attribute__((unused)))
  335. {
  336. struct octeon_device *oct_dev = NULL;
  337. oct_dev = octeon_allocate_device(pdev->device,
  338. sizeof(struct octeon_device_priv));
  339. if (!oct_dev) {
  340. dev_err(&pdev->dev, "Unable to allocate device\n");
  341. return -ENOMEM;
  342. }
  343. oct_dev->msix_on = LIO_FLAG_MSIX_ENABLED;
  344. dev_info(&pdev->dev, "Initializing device %x:%x.\n",
  345. (u32)pdev->vendor, (u32)pdev->device);
  346. /* Assign octeon_device for this device to the private data area. */
  347. pci_set_drvdata(pdev, oct_dev);
  348. /* set linux specific device pointer */
  349. oct_dev->pci_dev = pdev;
  350. oct_dev->subsystem_id = pdev->subsystem_vendor |
  351. (pdev->subsystem_device << 16);
  352. if (octeon_device_init(oct_dev)) {
  353. liquidio_vf_remove(pdev);
  354. return -ENOMEM;
  355. }
  356. dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n");
  357. return 0;
  358. }
  359. /**
  360. * \brief PCI FLR for each Octeon device.
  361. * @param oct octeon device
  362. */
  363. static void octeon_pci_flr(struct octeon_device *oct)
  364. {
  365. pci_save_state(oct->pci_dev);
  366. pci_cfg_access_lock(oct->pci_dev);
  367. /* Quiesce the device completely */
  368. pci_write_config_word(oct->pci_dev, PCI_COMMAND,
  369. PCI_COMMAND_INTX_DISABLE);
  370. pcie_flr(oct->pci_dev);
  371. pci_cfg_access_unlock(oct->pci_dev);
  372. pci_restore_state(oct->pci_dev);
  373. }
  374. /**
  375. *\brief Destroy resources associated with octeon device
  376. * @param pdev PCI device structure
  377. * @param ent unused
  378. */
  379. static void octeon_destroy_resources(struct octeon_device *oct)
  380. {
  381. struct msix_entry *msix_entries;
  382. int i;
  383. switch (atomic_read(&oct->status)) {
  384. case OCT_DEV_RUNNING:
  385. case OCT_DEV_CORE_OK:
  386. /* No more instructions will be forwarded. */
  387. atomic_set(&oct->status, OCT_DEV_IN_RESET);
  388. oct->app_mode = CVM_DRV_INVALID_APP;
  389. dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
  390. lio_get_state_string(&oct->status));
  391. schedule_timeout_uninterruptible(HZ / 10);
  392. /* fallthrough */
  393. case OCT_DEV_HOST_OK:
  394. /* fallthrough */
  395. case OCT_DEV_IO_QUEUES_DONE:
  396. if (wait_for_pending_requests(oct))
  397. dev_err(&oct->pci_dev->dev, "There were pending requests\n");
  398. if (lio_wait_for_instr_fetch(oct))
  399. dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
  400. /* Disable the input and output queues now. No more packets will
  401. * arrive from Octeon, but we should wait for all packet
  402. * processing to finish.
  403. */
  404. oct->fn_list.disable_io_queues(oct);
  405. if (lio_wait_for_oq_pkts(oct))
  406. dev_err(&oct->pci_dev->dev, "OQ had pending packets\n");
  407. /* fall through */
  408. case OCT_DEV_INTR_SET_DONE:
  409. /* Disable interrupts */
  410. oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
  411. if (oct->msix_on) {
  412. msix_entries = (struct msix_entry *)oct->msix_entries;
  413. for (i = 0; i < oct->num_msix_irqs; i++) {
  414. if (oct->ioq_vector[i].vector) {
  415. irq_set_affinity_hint(
  416. msix_entries[i].vector,
  417. NULL);
  418. free_irq(msix_entries[i].vector,
  419. &oct->ioq_vector[i]);
  420. oct->ioq_vector[i].vector = 0;
  421. }
  422. }
  423. pci_disable_msix(oct->pci_dev);
  424. kfree(oct->msix_entries);
  425. oct->msix_entries = NULL;
  426. kfree(oct->irq_name_storage);
  427. oct->irq_name_storage = NULL;
  428. }
  429. /* Soft reset the octeon device before exiting */
  430. if (oct->pci_dev->reset_fn)
  431. octeon_pci_flr(oct);
  432. else
  433. cn23xx_vf_ask_pf_to_do_flr(oct);
  434. /* fallthrough */
  435. case OCT_DEV_MSIX_ALLOC_VECTOR_DONE:
  436. octeon_free_ioq_vector(oct);
  437. /* fallthrough */
  438. case OCT_DEV_MBOX_SETUP_DONE:
  439. oct->fn_list.free_mbox(oct);
  440. /* fallthrough */
  441. case OCT_DEV_IN_RESET:
  442. case OCT_DEV_DROQ_INIT_DONE:
  443. mdelay(100);
  444. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
  445. if (!(oct->io_qmask.oq & BIT_ULL(i)))
  446. continue;
  447. octeon_delete_droq(oct, i);
  448. }
  449. /* fallthrough */
  450. case OCT_DEV_RESP_LIST_INIT_DONE:
  451. octeon_delete_response_list(oct);
  452. /* fallthrough */
  453. case OCT_DEV_INSTR_QUEUE_INIT_DONE:
  454. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
  455. if (!(oct->io_qmask.iq & BIT_ULL(i)))
  456. continue;
  457. octeon_delete_instr_queue(oct, i);
  458. }
  459. /* fallthrough */
  460. case OCT_DEV_SC_BUFF_POOL_INIT_DONE:
  461. octeon_free_sc_buffer_pool(oct);
  462. /* fallthrough */
  463. case OCT_DEV_DISPATCH_INIT_DONE:
  464. octeon_delete_dispatch_list(oct);
  465. cancel_delayed_work_sync(&oct->nic_poll_work.work);
  466. /* fallthrough */
  467. case OCT_DEV_PCI_MAP_DONE:
  468. octeon_unmap_pci_barx(oct, 0);
  469. octeon_unmap_pci_barx(oct, 1);
  470. /* fallthrough */
  471. case OCT_DEV_PCI_ENABLE_DONE:
  472. pci_clear_master(oct->pci_dev);
  473. /* Disable the device, releasing the PCI INT */
  474. pci_disable_device(oct->pci_dev);
  475. /* fallthrough */
  476. case OCT_DEV_BEGIN_STATE:
  477. /* Nothing to be done here either */
  478. break;
  479. }
  480. }
  481. /**
  482. * \brief Callback for rx ctrl
  483. * @param status status of request
  484. * @param buf pointer to resp structure
  485. */
  486. static void rx_ctl_callback(struct octeon_device *oct,
  487. u32 status, void *buf)
  488. {
  489. struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
  490. struct liquidio_rx_ctl_context *ctx;
  491. ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
  492. oct = lio_get_device(ctx->octeon_id);
  493. if (status)
  494. dev_err(&oct->pci_dev->dev, "rx ctl instruction failed. Status: %llx\n",
  495. CVM_CAST64(status));
  496. WRITE_ONCE(ctx->cond, 1);
  497. /* This barrier is required to be sure that the response has been
  498. * written fully before waking up the handler
  499. */
  500. wmb();
  501. wake_up_interruptible(&ctx->wc);
  502. }
  503. /**
  504. * \brief Send Rx control command
  505. * @param lio per-network private data
  506. * @param start_stop whether to start or stop
  507. */
  508. static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
  509. {
  510. struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
  511. int ctx_size = sizeof(struct liquidio_rx_ctl_context);
  512. struct liquidio_rx_ctl_context *ctx;
  513. struct octeon_soft_command *sc;
  514. union octnet_cmd *ncmd;
  515. int retval;
  516. if (oct->props[lio->ifidx].rx_on == start_stop)
  517. return;
  518. sc = (struct octeon_soft_command *)
  519. octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
  520. 16, ctx_size);
  521. ncmd = (union octnet_cmd *)sc->virtdptr;
  522. ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
  523. WRITE_ONCE(ctx->cond, 0);
  524. ctx->octeon_id = lio_get_device_id(oct);
  525. init_waitqueue_head(&ctx->wc);
  526. ncmd->u64 = 0;
  527. ncmd->s.cmd = OCTNET_CMD_RX_CTL;
  528. ncmd->s.param1 = start_stop;
  529. octeon_swap_8B_data((u64 *)ncmd, (OCTNET_CMD_SIZE >> 3));
  530. sc->iq_no = lio->linfo.txpciq[0].s.q_no;
  531. octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
  532. OPCODE_NIC_CMD, 0, 0, 0);
  533. sc->callback = rx_ctl_callback;
  534. sc->callback_arg = sc;
  535. sc->wait_time = 5000;
  536. retval = octeon_send_soft_command(oct, sc);
  537. if (retval == IQ_SEND_FAILED) {
  538. netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
  539. } else {
  540. /* Sleep on a wait queue till the cond flag indicates that the
  541. * response arrived or timed-out.
  542. */
  543. if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR)
  544. return;
  545. oct->props[lio->ifidx].rx_on = start_stop;
  546. }
  547. octeon_free_soft_command(oct, sc);
  548. }
  549. /**
  550. * \brief Destroy NIC device interface
  551. * @param oct octeon device
  552. * @param ifidx which interface to destroy
  553. *
  554. * Cleanup associated with each interface for an Octeon device when NIC
  555. * module is being unloaded or if initialization fails during load.
  556. */
  557. static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx)
  558. {
  559. struct net_device *netdev = oct->props[ifidx].netdev;
  560. struct napi_struct *napi, *n;
  561. struct lio *lio;
  562. if (!netdev) {
  563. dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n",
  564. __func__, ifidx);
  565. return;
  566. }
  567. lio = GET_LIO(netdev);
  568. dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n");
  569. if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING)
  570. liquidio_stop(netdev);
  571. if (oct->props[lio->ifidx].napi_enabled == 1) {
  572. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  573. napi_disable(napi);
  574. oct->props[lio->ifidx].napi_enabled = 0;
  575. oct->droq[0]->ops.poll_mode = 0;
  576. }
  577. /* Delete NAPI */
  578. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  579. netif_napi_del(napi);
  580. if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED)
  581. unregister_netdev(netdev);
  582. cleanup_rx_oom_poll_fn(netdev);
  583. cleanup_link_status_change_wq(netdev);
  584. lio_delete_glists(lio);
  585. free_netdev(netdev);
  586. oct->props[ifidx].gmxport = -1;
  587. oct->props[ifidx].netdev = NULL;
  588. }
  589. /**
  590. * \brief Stop complete NIC functionality
  591. * @param oct octeon device
  592. */
  593. static int liquidio_stop_nic_module(struct octeon_device *oct)
  594. {
  595. struct lio *lio;
  596. int i, j;
  597. dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n");
  598. if (!oct->ifcount) {
  599. dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n");
  600. return 1;
  601. }
  602. spin_lock_bh(&oct->cmd_resp_wqlock);
  603. oct->cmd_resp_state = OCT_DRV_OFFLINE;
  604. spin_unlock_bh(&oct->cmd_resp_wqlock);
  605. for (i = 0; i < oct->ifcount; i++) {
  606. lio = GET_LIO(oct->props[i].netdev);
  607. for (j = 0; j < oct->num_oqs; j++)
  608. octeon_unregister_droq_ops(oct,
  609. lio->linfo.rxpciq[j].s.q_no);
  610. }
  611. for (i = 0; i < oct->ifcount; i++)
  612. liquidio_destroy_nic_device(oct, i);
  613. dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
  614. return 0;
  615. }
  616. /**
  617. * \brief Cleans up resources at unload time
  618. * @param pdev PCI device structure
  619. */
  620. static void liquidio_vf_remove(struct pci_dev *pdev)
  621. {
  622. struct octeon_device *oct_dev = pci_get_drvdata(pdev);
  623. dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
  624. if (oct_dev->app_mode == CVM_DRV_NIC_APP)
  625. liquidio_stop_nic_module(oct_dev);
  626. /* Reset the octeon device and cleanup all memory allocated for
  627. * the octeon device by driver.
  628. */
  629. octeon_destroy_resources(oct_dev);
  630. dev_info(&oct_dev->pci_dev->dev, "Device removed\n");
  631. /* This octeon device has been removed. Update the global
  632. * data structure to reflect this. Free the device structure.
  633. */
  634. octeon_free_device_mem(oct_dev);
  635. }
  636. /**
  637. * \brief PCI initialization for each Octeon device.
  638. * @param oct octeon device
  639. */
  640. static int octeon_pci_os_setup(struct octeon_device *oct)
  641. {
  642. #ifdef CONFIG_PCI_IOV
  643. /* setup PCI stuff first */
  644. if (!oct->pci_dev->physfn)
  645. octeon_pci_flr(oct);
  646. #endif
  647. if (pci_enable_device(oct->pci_dev)) {
  648. dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n");
  649. return 1;
  650. }
  651. if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) {
  652. dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n");
  653. pci_disable_device(oct->pci_dev);
  654. return 1;
  655. }
  656. /* Enable PCI DMA Master. */
  657. pci_set_master(oct->pci_dev);
  658. return 0;
  659. }
  660. /**
  661. * \brief Unmap and free network buffer
  662. * @param buf buffer
  663. */
  664. static void free_netbuf(void *buf)
  665. {
  666. struct octnet_buf_free_info *finfo;
  667. struct sk_buff *skb;
  668. struct lio *lio;
  669. finfo = (struct octnet_buf_free_info *)buf;
  670. skb = finfo->skb;
  671. lio = finfo->lio;
  672. dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len,
  673. DMA_TO_DEVICE);
  674. tx_buffer_free(skb);
  675. }
  676. /**
  677. * \brief Unmap and free gather buffer
  678. * @param buf buffer
  679. */
  680. static void free_netsgbuf(void *buf)
  681. {
  682. struct octnet_buf_free_info *finfo;
  683. struct octnic_gather *g;
  684. struct sk_buff *skb;
  685. int i, frags, iq;
  686. struct lio *lio;
  687. finfo = (struct octnet_buf_free_info *)buf;
  688. skb = finfo->skb;
  689. lio = finfo->lio;
  690. g = finfo->g;
  691. frags = skb_shinfo(skb)->nr_frags;
  692. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  693. g->sg[0].ptr[0], (skb->len - skb->data_len),
  694. DMA_TO_DEVICE);
  695. i = 1;
  696. while (frags--) {
  697. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
  698. pci_unmap_page((lio->oct_dev)->pci_dev,
  699. g->sg[(i >> 2)].ptr[(i & 3)],
  700. frag->size, DMA_TO_DEVICE);
  701. i++;
  702. }
  703. iq = skb_iq(lio->oct_dev, skb);
  704. spin_lock(&lio->glist_lock[iq]);
  705. list_add_tail(&g->list, &lio->glist[iq]);
  706. spin_unlock(&lio->glist_lock[iq]);
  707. tx_buffer_free(skb);
  708. }
  709. /**
  710. * \brief Unmap and free gather buffer with response
  711. * @param buf buffer
  712. */
  713. static void free_netsgbuf_with_resp(void *buf)
  714. {
  715. struct octnet_buf_free_info *finfo;
  716. struct octeon_soft_command *sc;
  717. struct octnic_gather *g;
  718. struct sk_buff *skb;
  719. int i, frags, iq;
  720. struct lio *lio;
  721. sc = (struct octeon_soft_command *)buf;
  722. skb = (struct sk_buff *)sc->callback_arg;
  723. finfo = (struct octnet_buf_free_info *)&skb->cb;
  724. lio = finfo->lio;
  725. g = finfo->g;
  726. frags = skb_shinfo(skb)->nr_frags;
  727. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  728. g->sg[0].ptr[0], (skb->len - skb->data_len),
  729. DMA_TO_DEVICE);
  730. i = 1;
  731. while (frags--) {
  732. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
  733. pci_unmap_page((lio->oct_dev)->pci_dev,
  734. g->sg[(i >> 2)].ptr[(i & 3)],
  735. frag->size, DMA_TO_DEVICE);
  736. i++;
  737. }
  738. iq = skb_iq(lio->oct_dev, skb);
  739. spin_lock(&lio->glist_lock[iq]);
  740. list_add_tail(&g->list, &lio->glist[iq]);
  741. spin_unlock(&lio->glist_lock[iq]);
  742. /* Don't free the skb yet */
  743. }
  744. /**
  745. * \brief Net device open for LiquidIO
  746. * @param netdev network device
  747. */
  748. static int liquidio_open(struct net_device *netdev)
  749. {
  750. struct lio *lio = GET_LIO(netdev);
  751. struct octeon_device *oct = lio->oct_dev;
  752. struct napi_struct *napi, *n;
  753. if (!oct->props[lio->ifidx].napi_enabled) {
  754. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  755. napi_enable(napi);
  756. oct->props[lio->ifidx].napi_enabled = 1;
  757. oct->droq[0]->ops.poll_mode = 1;
  758. }
  759. ifstate_set(lio, LIO_IFSTATE_RUNNING);
  760. /* Ready for link status updates */
  761. lio->intf_open = 1;
  762. netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
  763. start_txqs(netdev);
  764. /* tell Octeon to start forwarding packets to host */
  765. send_rx_ctrl_cmd(lio, 1);
  766. dev_info(&oct->pci_dev->dev, "%s interface is opened\n", netdev->name);
  767. return 0;
  768. }
  769. /**
  770. * \brief Net device stop for LiquidIO
  771. * @param netdev network device
  772. */
  773. static int liquidio_stop(struct net_device *netdev)
  774. {
  775. struct lio *lio = GET_LIO(netdev);
  776. struct octeon_device *oct = lio->oct_dev;
  777. struct napi_struct *napi, *n;
  778. /* tell Octeon to stop forwarding packets to host */
  779. send_rx_ctrl_cmd(lio, 0);
  780. netif_info(lio, ifdown, lio->netdev, "Stopping interface!\n");
  781. /* Inform that netif carrier is down */
  782. lio->intf_open = 0;
  783. lio->linfo.link.s.link_up = 0;
  784. netif_carrier_off(netdev);
  785. lio->link_changes++;
  786. ifstate_reset(lio, LIO_IFSTATE_RUNNING);
  787. stop_txqs(netdev);
  788. /* Wait for any pending Rx descriptors */
  789. if (lio_wait_for_clean_oq(oct))
  790. netif_info(lio, rx_err, lio->netdev,
  791. "Proceeding with stop interface after partial RX desc processing\n");
  792. if (oct->props[lio->ifidx].napi_enabled == 1) {
  793. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  794. napi_disable(napi);
  795. oct->props[lio->ifidx].napi_enabled = 0;
  796. oct->droq[0]->ops.poll_mode = 0;
  797. }
  798. dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
  799. return 0;
  800. }
  801. /**
  802. * \brief Converts a mask based on net device flags
  803. * @param netdev network device
  804. *
  805. * This routine generates a octnet_ifflags mask from the net device flags
  806. * received from the OS.
  807. */
  808. static enum octnet_ifflags get_new_flags(struct net_device *netdev)
  809. {
  810. enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST;
  811. if (netdev->flags & IFF_PROMISC)
  812. f |= OCTNET_IFFLAG_PROMISC;
  813. if (netdev->flags & IFF_ALLMULTI)
  814. f |= OCTNET_IFFLAG_ALLMULTI;
  815. if (netdev->flags & IFF_MULTICAST) {
  816. f |= OCTNET_IFFLAG_MULTICAST;
  817. /* Accept all multicast addresses if there are more than we
  818. * can handle
  819. */
  820. if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR)
  821. f |= OCTNET_IFFLAG_ALLMULTI;
  822. }
  823. if (netdev->flags & IFF_BROADCAST)
  824. f |= OCTNET_IFFLAG_BROADCAST;
  825. return f;
  826. }
  827. static void liquidio_set_uc_list(struct net_device *netdev)
  828. {
  829. struct lio *lio = GET_LIO(netdev);
  830. struct octeon_device *oct = lio->oct_dev;
  831. struct octnic_ctrl_pkt nctrl;
  832. struct netdev_hw_addr *ha;
  833. u64 *mac;
  834. if (lio->netdev_uc_count == netdev_uc_count(netdev))
  835. return;
  836. if (netdev_uc_count(netdev) > MAX_NCTRL_UDD) {
  837. dev_err(&oct->pci_dev->dev, "too many MAC addresses in netdev uc list\n");
  838. return;
  839. }
  840. lio->netdev_uc_count = netdev_uc_count(netdev);
  841. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  842. nctrl.ncmd.s.cmd = OCTNET_CMD_SET_UC_LIST;
  843. nctrl.ncmd.s.more = lio->netdev_uc_count;
  844. nctrl.ncmd.s.param1 = oct->vf_num;
  845. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  846. nctrl.netpndev = (u64)netdev;
  847. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  848. /* copy all the addresses into the udd */
  849. mac = &nctrl.udd[0];
  850. netdev_for_each_uc_addr(ha, netdev) {
  851. ether_addr_copy(((u8 *)mac) + 2, ha->addr);
  852. mac++;
  853. }
  854. octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  855. }
  856. /**
  857. * \brief Net device set_multicast_list
  858. * @param netdev network device
  859. */
  860. static void liquidio_set_mcast_list(struct net_device *netdev)
  861. {
  862. int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR);
  863. struct lio *lio = GET_LIO(netdev);
  864. struct octeon_device *oct = lio->oct_dev;
  865. struct octnic_ctrl_pkt nctrl;
  866. struct netdev_hw_addr *ha;
  867. u64 *mc;
  868. int ret;
  869. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  870. /* Create a ctrl pkt command to be sent to core app. */
  871. nctrl.ncmd.u64 = 0;
  872. nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST;
  873. nctrl.ncmd.s.param1 = get_new_flags(netdev);
  874. nctrl.ncmd.s.param2 = mc_count;
  875. nctrl.ncmd.s.more = mc_count;
  876. nctrl.netpndev = (u64)netdev;
  877. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  878. /* copy all the addresses into the udd */
  879. mc = &nctrl.udd[0];
  880. netdev_for_each_mc_addr(ha, netdev) {
  881. *mc = 0;
  882. ether_addr_copy(((u8 *)mc) + 2, ha->addr);
  883. /* no need to swap bytes */
  884. if (++mc > &nctrl.udd[mc_count])
  885. break;
  886. }
  887. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  888. /* Apparently, any activity in this call from the kernel has to
  889. * be atomic. So we won't wait for response.
  890. */
  891. nctrl.wait_time = 0;
  892. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  893. if (ret < 0) {
  894. dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n",
  895. ret);
  896. }
  897. liquidio_set_uc_list(netdev);
  898. }
  899. /**
  900. * \brief Net device set_mac_address
  901. * @param netdev network device
  902. */
  903. static int liquidio_set_mac(struct net_device *netdev, void *p)
  904. {
  905. struct sockaddr *addr = (struct sockaddr *)p;
  906. struct lio *lio = GET_LIO(netdev);
  907. struct octeon_device *oct = lio->oct_dev;
  908. struct octnic_ctrl_pkt nctrl;
  909. int ret = 0;
  910. if (!is_valid_ether_addr(addr->sa_data))
  911. return -EADDRNOTAVAIL;
  912. if (ether_addr_equal(addr->sa_data, netdev->dev_addr))
  913. return 0;
  914. if (lio->linfo.macaddr_is_admin_asgnd)
  915. return -EPERM;
  916. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  917. nctrl.ncmd.u64 = 0;
  918. nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
  919. nctrl.ncmd.s.param1 = 0;
  920. nctrl.ncmd.s.more = 1;
  921. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  922. nctrl.netpndev = (u64)netdev;
  923. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  924. nctrl.wait_time = 100;
  925. nctrl.udd[0] = 0;
  926. /* The MAC Address is presented in network byte order. */
  927. ether_addr_copy((u8 *)&nctrl.udd[0] + 2, addr->sa_data);
  928. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  929. if (ret < 0) {
  930. dev_err(&oct->pci_dev->dev, "MAC Address change failed\n");
  931. return -ENOMEM;
  932. }
  933. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  934. ether_addr_copy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data);
  935. return 0;
  936. }
  937. static void
  938. liquidio_get_stats64(struct net_device *netdev,
  939. struct rtnl_link_stats64 *lstats)
  940. {
  941. struct lio *lio = GET_LIO(netdev);
  942. struct octeon_device *oct;
  943. u64 pkts = 0, drop = 0, bytes = 0;
  944. struct oct_droq_stats *oq_stats;
  945. struct oct_iq_stats *iq_stats;
  946. int i, iq_no, oq_no;
  947. oct = lio->oct_dev;
  948. if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
  949. return;
  950. for (i = 0; i < oct->num_iqs; i++) {
  951. iq_no = lio->linfo.txpciq[i].s.q_no;
  952. iq_stats = &oct->instr_queue[iq_no]->stats;
  953. pkts += iq_stats->tx_done;
  954. drop += iq_stats->tx_dropped;
  955. bytes += iq_stats->tx_tot_bytes;
  956. }
  957. lstats->tx_packets = pkts;
  958. lstats->tx_bytes = bytes;
  959. lstats->tx_dropped = drop;
  960. pkts = 0;
  961. drop = 0;
  962. bytes = 0;
  963. for (i = 0; i < oct->num_oqs; i++) {
  964. oq_no = lio->linfo.rxpciq[i].s.q_no;
  965. oq_stats = &oct->droq[oq_no]->stats;
  966. pkts += oq_stats->rx_pkts_received;
  967. drop += (oq_stats->rx_dropped +
  968. oq_stats->dropped_nodispatch +
  969. oq_stats->dropped_toomany +
  970. oq_stats->dropped_nomem);
  971. bytes += oq_stats->rx_bytes_received;
  972. }
  973. lstats->rx_bytes = bytes;
  974. lstats->rx_packets = pkts;
  975. lstats->rx_dropped = drop;
  976. octnet_get_link_stats(netdev);
  977. lstats->multicast = oct->link_stats.fromwire.fw_total_mcast;
  978. /* detailed rx_errors: */
  979. lstats->rx_length_errors = oct->link_stats.fromwire.l2_err;
  980. /* recved pkt with crc error */
  981. lstats->rx_crc_errors = oct->link_stats.fromwire.fcs_err;
  982. /* recv'd frame alignment error */
  983. lstats->rx_frame_errors = oct->link_stats.fromwire.frame_err;
  984. lstats->rx_errors = lstats->rx_length_errors + lstats->rx_crc_errors +
  985. lstats->rx_frame_errors;
  986. /* detailed tx_errors */
  987. lstats->tx_aborted_errors = oct->link_stats.fromhost.fw_err_pko;
  988. lstats->tx_carrier_errors = oct->link_stats.fromhost.fw_err_link;
  989. lstats->tx_errors = lstats->tx_aborted_errors +
  990. lstats->tx_carrier_errors;
  991. }
  992. /**
  993. * \brief Handler for SIOCSHWTSTAMP ioctl
  994. * @param netdev network device
  995. * @param ifr interface request
  996. * @param cmd command
  997. */
  998. static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
  999. {
  1000. struct lio *lio = GET_LIO(netdev);
  1001. struct hwtstamp_config conf;
  1002. if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf)))
  1003. return -EFAULT;
  1004. if (conf.flags)
  1005. return -EINVAL;
  1006. switch (conf.tx_type) {
  1007. case HWTSTAMP_TX_ON:
  1008. case HWTSTAMP_TX_OFF:
  1009. break;
  1010. default:
  1011. return -ERANGE;
  1012. }
  1013. switch (conf.rx_filter) {
  1014. case HWTSTAMP_FILTER_NONE:
  1015. break;
  1016. case HWTSTAMP_FILTER_ALL:
  1017. case HWTSTAMP_FILTER_SOME:
  1018. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  1019. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  1020. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  1021. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  1022. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  1023. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  1024. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  1025. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  1026. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  1027. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  1028. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  1029. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  1030. case HWTSTAMP_FILTER_NTP_ALL:
  1031. conf.rx_filter = HWTSTAMP_FILTER_ALL;
  1032. break;
  1033. default:
  1034. return -ERANGE;
  1035. }
  1036. if (conf.rx_filter == HWTSTAMP_FILTER_ALL)
  1037. ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
  1038. else
  1039. ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
  1040. return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0;
  1041. }
  1042. /**
  1043. * \brief ioctl handler
  1044. * @param netdev network device
  1045. * @param ifr interface request
  1046. * @param cmd command
  1047. */
  1048. static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1049. {
  1050. switch (cmd) {
  1051. case SIOCSHWTSTAMP:
  1052. return hwtstamp_ioctl(netdev, ifr);
  1053. default:
  1054. return -EOPNOTSUPP;
  1055. }
  1056. }
  1057. static void handle_timestamp(struct octeon_device *oct, u32 status, void *buf)
  1058. {
  1059. struct sk_buff *skb = (struct sk_buff *)buf;
  1060. struct octnet_buf_free_info *finfo;
  1061. struct oct_timestamp_resp *resp;
  1062. struct octeon_soft_command *sc;
  1063. struct lio *lio;
  1064. finfo = (struct octnet_buf_free_info *)skb->cb;
  1065. lio = finfo->lio;
  1066. sc = finfo->sc;
  1067. oct = lio->oct_dev;
  1068. resp = (struct oct_timestamp_resp *)sc->virtrptr;
  1069. if (status != OCTEON_REQUEST_DONE) {
  1070. dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n",
  1071. CVM_CAST64(status));
  1072. resp->timestamp = 0;
  1073. }
  1074. octeon_swap_8B_data(&resp->timestamp, 1);
  1075. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
  1076. struct skb_shared_hwtstamps ts;
  1077. u64 ns = resp->timestamp;
  1078. netif_info(lio, tx_done, lio->netdev,
  1079. "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n",
  1080. skb, (unsigned long long)ns);
  1081. ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust);
  1082. skb_tstamp_tx(skb, &ts);
  1083. }
  1084. octeon_free_soft_command(oct, sc);
  1085. tx_buffer_free(skb);
  1086. }
  1087. /* \brief Send a data packet that will be timestamped
  1088. * @param oct octeon device
  1089. * @param ndata pointer to network data
  1090. * @param finfo pointer to private network data
  1091. */
  1092. static int send_nic_timestamp_pkt(struct octeon_device *oct,
  1093. struct octnic_data_pkt *ndata,
  1094. struct octnet_buf_free_info *finfo,
  1095. int xmit_more)
  1096. {
  1097. struct octeon_soft_command *sc;
  1098. int ring_doorbell;
  1099. struct lio *lio;
  1100. int retval;
  1101. u32 len;
  1102. lio = finfo->lio;
  1103. sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd,
  1104. sizeof(struct oct_timestamp_resp));
  1105. finfo->sc = sc;
  1106. if (!sc) {
  1107. dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n");
  1108. return IQ_SEND_FAILED;
  1109. }
  1110. if (ndata->reqtype == REQTYPE_NORESP_NET)
  1111. ndata->reqtype = REQTYPE_RESP_NET;
  1112. else if (ndata->reqtype == REQTYPE_NORESP_NET_SG)
  1113. ndata->reqtype = REQTYPE_RESP_NET_SG;
  1114. sc->callback = handle_timestamp;
  1115. sc->callback_arg = finfo->skb;
  1116. sc->iq_no = ndata->q_no;
  1117. len = (u32)((struct octeon_instr_ih3 *)(&sc->cmd.cmd3.ih3))->dlengsz;
  1118. ring_doorbell = !xmit_more;
  1119. retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd,
  1120. sc, len, ndata->reqtype);
  1121. if (retval == IQ_SEND_FAILED) {
  1122. dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n",
  1123. retval);
  1124. octeon_free_soft_command(oct, sc);
  1125. } else {
  1126. netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n");
  1127. }
  1128. return retval;
  1129. }
  1130. /** \brief Transmit networks packets to the Octeon interface
  1131. * @param skbuff skbuff struct to be passed to network layer.
  1132. * @param netdev pointer to network device
  1133. * @returns whether the packet was transmitted to the device okay or not
  1134. * (NETDEV_TX_OK or NETDEV_TX_BUSY)
  1135. */
  1136. static netdev_tx_t liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
  1137. {
  1138. struct octnet_buf_free_info *finfo;
  1139. union octnic_cmd_setup cmdsetup;
  1140. struct octnic_data_pkt ndata;
  1141. struct octeon_instr_irh *irh;
  1142. struct oct_iq_stats *stats;
  1143. struct octeon_device *oct;
  1144. int q_idx = 0, iq_no = 0;
  1145. union tx_info *tx_info;
  1146. int xmit_more = 0;
  1147. struct lio *lio;
  1148. int status = 0;
  1149. u64 dptr = 0;
  1150. u32 tag = 0;
  1151. int j;
  1152. lio = GET_LIO(netdev);
  1153. oct = lio->oct_dev;
  1154. q_idx = skb_iq(lio->oct_dev, skb);
  1155. tag = q_idx;
  1156. iq_no = lio->linfo.txpciq[q_idx].s.q_no;
  1157. stats = &oct->instr_queue[iq_no]->stats;
  1158. /* Check for all conditions in which the current packet cannot be
  1159. * transmitted.
  1160. */
  1161. if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
  1162. (!lio->linfo.link.s.link_up) || (skb->len <= 0)) {
  1163. netif_info(lio, tx_err, lio->netdev, "Transmit failed link_status : %d\n",
  1164. lio->linfo.link.s.link_up);
  1165. goto lio_xmit_failed;
  1166. }
  1167. /* Use space in skb->cb to store info used to unmap and
  1168. * free the buffers.
  1169. */
  1170. finfo = (struct octnet_buf_free_info *)skb->cb;
  1171. finfo->lio = lio;
  1172. finfo->skb = skb;
  1173. finfo->sc = NULL;
  1174. /* Prepare the attributes for the data to be passed to OSI. */
  1175. memset(&ndata, 0, sizeof(struct octnic_data_pkt));
  1176. ndata.buf = finfo;
  1177. ndata.q_no = iq_no;
  1178. if (octnet_iq_is_full(oct, ndata.q_no)) {
  1179. /* defer sending if queue is full */
  1180. netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
  1181. ndata.q_no);
  1182. stats->tx_iq_busy++;
  1183. return NETDEV_TX_BUSY;
  1184. }
  1185. ndata.datasize = skb->len;
  1186. cmdsetup.u64 = 0;
  1187. cmdsetup.s.iq_no = iq_no;
  1188. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  1189. if (skb->encapsulation) {
  1190. cmdsetup.s.tnl_csum = 1;
  1191. stats->tx_vxlan++;
  1192. } else {
  1193. cmdsetup.s.transport_csum = 1;
  1194. }
  1195. }
  1196. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  1197. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1198. cmdsetup.s.timestamp = 1;
  1199. }
  1200. if (!skb_shinfo(skb)->nr_frags) {
  1201. cmdsetup.s.u.datasize = skb->len;
  1202. octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
  1203. /* Offload checksum calculation for TCP/UDP packets */
  1204. dptr = dma_map_single(&oct->pci_dev->dev,
  1205. skb->data,
  1206. skb->len,
  1207. DMA_TO_DEVICE);
  1208. if (dma_mapping_error(&oct->pci_dev->dev, dptr)) {
  1209. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n",
  1210. __func__);
  1211. return NETDEV_TX_BUSY;
  1212. }
  1213. ndata.cmd.cmd3.dptr = dptr;
  1214. finfo->dptr = dptr;
  1215. ndata.reqtype = REQTYPE_NORESP_NET;
  1216. } else {
  1217. struct skb_frag_struct *frag;
  1218. struct octnic_gather *g;
  1219. int i, frags;
  1220. spin_lock(&lio->glist_lock[q_idx]);
  1221. g = (struct octnic_gather *)
  1222. lio_list_delete_head(&lio->glist[q_idx]);
  1223. spin_unlock(&lio->glist_lock[q_idx]);
  1224. if (!g) {
  1225. netif_info(lio, tx_err, lio->netdev,
  1226. "Transmit scatter gather: glist null!\n");
  1227. goto lio_xmit_failed;
  1228. }
  1229. cmdsetup.s.gather = 1;
  1230. cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1);
  1231. octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
  1232. memset(g->sg, 0, g->sg_size);
  1233. g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev,
  1234. skb->data,
  1235. (skb->len - skb->data_len),
  1236. DMA_TO_DEVICE);
  1237. if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) {
  1238. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n",
  1239. __func__);
  1240. return NETDEV_TX_BUSY;
  1241. }
  1242. add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0);
  1243. frags = skb_shinfo(skb)->nr_frags;
  1244. i = 1;
  1245. while (frags--) {
  1246. frag = &skb_shinfo(skb)->frags[i - 1];
  1247. g->sg[(i >> 2)].ptr[(i & 3)] =
  1248. dma_map_page(&oct->pci_dev->dev,
  1249. frag->page.p,
  1250. frag->page_offset,
  1251. frag->size,
  1252. DMA_TO_DEVICE);
  1253. if (dma_mapping_error(&oct->pci_dev->dev,
  1254. g->sg[i >> 2].ptr[i & 3])) {
  1255. dma_unmap_single(&oct->pci_dev->dev,
  1256. g->sg[0].ptr[0],
  1257. skb->len - skb->data_len,
  1258. DMA_TO_DEVICE);
  1259. for (j = 1; j < i; j++) {
  1260. frag = &skb_shinfo(skb)->frags[j - 1];
  1261. dma_unmap_page(&oct->pci_dev->dev,
  1262. g->sg[j >> 2].ptr[j & 3],
  1263. frag->size,
  1264. DMA_TO_DEVICE);
  1265. }
  1266. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n",
  1267. __func__);
  1268. return NETDEV_TX_BUSY;
  1269. }
  1270. add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3));
  1271. i++;
  1272. }
  1273. dptr = g->sg_dma_ptr;
  1274. ndata.cmd.cmd3.dptr = dptr;
  1275. finfo->dptr = dptr;
  1276. finfo->g = g;
  1277. ndata.reqtype = REQTYPE_NORESP_NET_SG;
  1278. }
  1279. irh = (struct octeon_instr_irh *)&ndata.cmd.cmd3.irh;
  1280. tx_info = (union tx_info *)&ndata.cmd.cmd3.ossp[0];
  1281. if (skb_shinfo(skb)->gso_size) {
  1282. tx_info->s.gso_size = skb_shinfo(skb)->gso_size;
  1283. tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs;
  1284. }
  1285. /* HW insert VLAN tag */
  1286. if (skb_vlan_tag_present(skb)) {
  1287. irh->priority = skb_vlan_tag_get(skb) >> VLAN_PRIO_SHIFT;
  1288. irh->vlan = skb_vlan_tag_get(skb) & VLAN_VID_MASK;
  1289. }
  1290. xmit_more = skb->xmit_more;
  1291. if (unlikely(cmdsetup.s.timestamp))
  1292. status = send_nic_timestamp_pkt(oct, &ndata, finfo, xmit_more);
  1293. else
  1294. status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more);
  1295. if (status == IQ_SEND_FAILED)
  1296. goto lio_xmit_failed;
  1297. netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
  1298. if (status == IQ_SEND_STOP) {
  1299. dev_err(&oct->pci_dev->dev, "Rcvd IQ_SEND_STOP signal; stopping IQ-%d\n",
  1300. iq_no);
  1301. netif_stop_subqueue(netdev, q_idx);
  1302. }
  1303. netif_trans_update(netdev);
  1304. if (tx_info->s.gso_segs)
  1305. stats->tx_done += tx_info->s.gso_segs;
  1306. else
  1307. stats->tx_done++;
  1308. stats->tx_tot_bytes += ndata.datasize;
  1309. return NETDEV_TX_OK;
  1310. lio_xmit_failed:
  1311. stats->tx_dropped++;
  1312. netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
  1313. iq_no, stats->tx_dropped);
  1314. if (dptr)
  1315. dma_unmap_single(&oct->pci_dev->dev, dptr,
  1316. ndata.datasize, DMA_TO_DEVICE);
  1317. octeon_ring_doorbell_locked(oct, iq_no);
  1318. tx_buffer_free(skb);
  1319. return NETDEV_TX_OK;
  1320. }
  1321. /** \brief Network device Tx timeout
  1322. * @param netdev pointer to network device
  1323. */
  1324. static void liquidio_tx_timeout(struct net_device *netdev)
  1325. {
  1326. struct lio *lio;
  1327. lio = GET_LIO(netdev);
  1328. netif_info(lio, tx_err, lio->netdev,
  1329. "Transmit timeout tx_dropped:%ld, waking up queues now!!\n",
  1330. netdev->stats.tx_dropped);
  1331. netif_trans_update(netdev);
  1332. wake_txqs(netdev);
  1333. }
  1334. static int
  1335. liquidio_vlan_rx_add_vid(struct net_device *netdev,
  1336. __be16 proto __attribute__((unused)), u16 vid)
  1337. {
  1338. struct lio *lio = GET_LIO(netdev);
  1339. struct octeon_device *oct = lio->oct_dev;
  1340. struct octnic_ctrl_pkt nctrl;
  1341. struct completion compl;
  1342. u16 response_code;
  1343. int ret = 0;
  1344. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1345. nctrl.ncmd.u64 = 0;
  1346. nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
  1347. nctrl.ncmd.s.param1 = vid;
  1348. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  1349. nctrl.wait_time = 100;
  1350. nctrl.netpndev = (u64)netdev;
  1351. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1352. init_completion(&compl);
  1353. nctrl.completion = &compl;
  1354. nctrl.response_code = &response_code;
  1355. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  1356. if (ret < 0) {
  1357. dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
  1358. ret);
  1359. return -EIO;
  1360. }
  1361. if (!wait_for_completion_timeout(&compl,
  1362. msecs_to_jiffies(nctrl.wait_time)))
  1363. return -EPERM;
  1364. if (READ_ONCE(response_code))
  1365. return -EPERM;
  1366. return 0;
  1367. }
  1368. static int
  1369. liquidio_vlan_rx_kill_vid(struct net_device *netdev,
  1370. __be16 proto __attribute__((unused)), u16 vid)
  1371. {
  1372. struct lio *lio = GET_LIO(netdev);
  1373. struct octeon_device *oct = lio->oct_dev;
  1374. struct octnic_ctrl_pkt nctrl;
  1375. int ret = 0;
  1376. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1377. nctrl.ncmd.u64 = 0;
  1378. nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
  1379. nctrl.ncmd.s.param1 = vid;
  1380. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  1381. nctrl.wait_time = 100;
  1382. nctrl.netpndev = (u64)netdev;
  1383. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1384. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  1385. if (ret < 0) {
  1386. dev_err(&oct->pci_dev->dev, "Del VLAN filter failed in core (ret: 0x%x)\n",
  1387. ret);
  1388. }
  1389. return ret;
  1390. }
  1391. /** Sending command to enable/disable RX checksum offload
  1392. * @param netdev pointer to network device
  1393. * @param command OCTNET_CMD_TNL_RX_CSUM_CTL
  1394. * @param rx_cmd_bit OCTNET_CMD_RXCSUM_ENABLE/
  1395. * OCTNET_CMD_RXCSUM_DISABLE
  1396. * @returns SUCCESS or FAILURE
  1397. */
  1398. static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
  1399. u8 rx_cmd)
  1400. {
  1401. struct lio *lio = GET_LIO(netdev);
  1402. struct octeon_device *oct = lio->oct_dev;
  1403. struct octnic_ctrl_pkt nctrl;
  1404. int ret = 0;
  1405. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1406. nctrl.ncmd.u64 = 0;
  1407. nctrl.ncmd.s.cmd = command;
  1408. nctrl.ncmd.s.param1 = rx_cmd;
  1409. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  1410. nctrl.wait_time = 100;
  1411. nctrl.netpndev = (u64)netdev;
  1412. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1413. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  1414. if (ret < 0) {
  1415. dev_err(&oct->pci_dev->dev, "DEVFLAGS RXCSUM change failed in core (ret:0x%x)\n",
  1416. ret);
  1417. }
  1418. return ret;
  1419. }
  1420. /** Sending command to add/delete VxLAN UDP port to firmware
  1421. * @param netdev pointer to network device
  1422. * @param command OCTNET_CMD_VXLAN_PORT_CONFIG
  1423. * @param vxlan_port VxLAN port to be added or deleted
  1424. * @param vxlan_cmd_bit OCTNET_CMD_VXLAN_PORT_ADD,
  1425. * OCTNET_CMD_VXLAN_PORT_DEL
  1426. * @returns SUCCESS or FAILURE
  1427. */
  1428. static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
  1429. u16 vxlan_port, u8 vxlan_cmd_bit)
  1430. {
  1431. struct lio *lio = GET_LIO(netdev);
  1432. struct octeon_device *oct = lio->oct_dev;
  1433. struct octnic_ctrl_pkt nctrl;
  1434. int ret = 0;
  1435. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1436. nctrl.ncmd.u64 = 0;
  1437. nctrl.ncmd.s.cmd = command;
  1438. nctrl.ncmd.s.more = vxlan_cmd_bit;
  1439. nctrl.ncmd.s.param1 = vxlan_port;
  1440. nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
  1441. nctrl.wait_time = 100;
  1442. nctrl.netpndev = (u64)netdev;
  1443. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1444. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
  1445. if (ret < 0) {
  1446. dev_err(&oct->pci_dev->dev,
  1447. "DEVFLAGS VxLAN port add/delete failed in core (ret : 0x%x)\n",
  1448. ret);
  1449. }
  1450. return ret;
  1451. }
  1452. /** \brief Net device fix features
  1453. * @param netdev pointer to network device
  1454. * @param request features requested
  1455. * @returns updated features list
  1456. */
  1457. static netdev_features_t liquidio_fix_features(struct net_device *netdev,
  1458. netdev_features_t request)
  1459. {
  1460. struct lio *lio = netdev_priv(netdev);
  1461. if ((request & NETIF_F_RXCSUM) &&
  1462. !(lio->dev_capability & NETIF_F_RXCSUM))
  1463. request &= ~NETIF_F_RXCSUM;
  1464. if ((request & NETIF_F_HW_CSUM) &&
  1465. !(lio->dev_capability & NETIF_F_HW_CSUM))
  1466. request &= ~NETIF_F_HW_CSUM;
  1467. if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO))
  1468. request &= ~NETIF_F_TSO;
  1469. if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6))
  1470. request &= ~NETIF_F_TSO6;
  1471. if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO))
  1472. request &= ~NETIF_F_LRO;
  1473. /* Disable LRO if RXCSUM is off */
  1474. if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) &&
  1475. (lio->dev_capability & NETIF_F_LRO))
  1476. request &= ~NETIF_F_LRO;
  1477. return request;
  1478. }
  1479. /** \brief Net device set features
  1480. * @param netdev pointer to network device
  1481. * @param features features to enable/disable
  1482. */
  1483. static int liquidio_set_features(struct net_device *netdev,
  1484. netdev_features_t features)
  1485. {
  1486. struct lio *lio = netdev_priv(netdev);
  1487. if (!((netdev->features ^ features) & NETIF_F_LRO))
  1488. return 0;
  1489. if ((features & NETIF_F_LRO) && (lio->dev_capability & NETIF_F_LRO))
  1490. liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
  1491. OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
  1492. else if (!(features & NETIF_F_LRO) &&
  1493. (lio->dev_capability & NETIF_F_LRO))
  1494. liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE,
  1495. OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
  1496. if (!(netdev->features & NETIF_F_RXCSUM) &&
  1497. (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
  1498. (features & NETIF_F_RXCSUM))
  1499. liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
  1500. OCTNET_CMD_RXCSUM_ENABLE);
  1501. else if ((netdev->features & NETIF_F_RXCSUM) &&
  1502. (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
  1503. !(features & NETIF_F_RXCSUM))
  1504. liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
  1505. OCTNET_CMD_RXCSUM_DISABLE);
  1506. return 0;
  1507. }
  1508. static void liquidio_add_vxlan_port(struct net_device *netdev,
  1509. struct udp_tunnel_info *ti)
  1510. {
  1511. if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
  1512. return;
  1513. liquidio_vxlan_port_command(netdev,
  1514. OCTNET_CMD_VXLAN_PORT_CONFIG,
  1515. htons(ti->port),
  1516. OCTNET_CMD_VXLAN_PORT_ADD);
  1517. }
  1518. static void liquidio_del_vxlan_port(struct net_device *netdev,
  1519. struct udp_tunnel_info *ti)
  1520. {
  1521. if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
  1522. return;
  1523. liquidio_vxlan_port_command(netdev,
  1524. OCTNET_CMD_VXLAN_PORT_CONFIG,
  1525. htons(ti->port),
  1526. OCTNET_CMD_VXLAN_PORT_DEL);
  1527. }
  1528. static const struct net_device_ops lionetdevops = {
  1529. .ndo_open = liquidio_open,
  1530. .ndo_stop = liquidio_stop,
  1531. .ndo_start_xmit = liquidio_xmit,
  1532. .ndo_get_stats64 = liquidio_get_stats64,
  1533. .ndo_set_mac_address = liquidio_set_mac,
  1534. .ndo_set_rx_mode = liquidio_set_mcast_list,
  1535. .ndo_tx_timeout = liquidio_tx_timeout,
  1536. .ndo_vlan_rx_add_vid = liquidio_vlan_rx_add_vid,
  1537. .ndo_vlan_rx_kill_vid = liquidio_vlan_rx_kill_vid,
  1538. .ndo_change_mtu = liquidio_change_mtu,
  1539. .ndo_do_ioctl = liquidio_ioctl,
  1540. .ndo_fix_features = liquidio_fix_features,
  1541. .ndo_set_features = liquidio_set_features,
  1542. .ndo_udp_tunnel_add = liquidio_add_vxlan_port,
  1543. .ndo_udp_tunnel_del = liquidio_del_vxlan_port,
  1544. };
  1545. static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf)
  1546. {
  1547. struct octeon_device *oct = (struct octeon_device *)buf;
  1548. struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
  1549. union oct_link_status *ls;
  1550. int gmxport = 0;
  1551. int i;
  1552. if (recv_pkt->buffer_size[0] != (sizeof(*ls) + OCT_DROQ_INFO_SIZE)) {
  1553. dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n",
  1554. recv_pkt->buffer_size[0],
  1555. recv_pkt->rh.r_nic_info.gmxport);
  1556. goto nic_info_err;
  1557. }
  1558. gmxport = recv_pkt->rh.r_nic_info.gmxport;
  1559. ls = (union oct_link_status *)(get_rbd(recv_pkt->buffer_ptr[0]) +
  1560. OCT_DROQ_INFO_SIZE);
  1561. octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3);
  1562. for (i = 0; i < oct->ifcount; i++) {
  1563. if (oct->props[i].gmxport == gmxport) {
  1564. update_link_status(oct->props[i].netdev, ls);
  1565. break;
  1566. }
  1567. }
  1568. nic_info_err:
  1569. for (i = 0; i < recv_pkt->buffer_count; i++)
  1570. recv_buffer_free(recv_pkt->buffer_ptr[i]);
  1571. octeon_free_recv_info(recv_info);
  1572. return 0;
  1573. }
  1574. /**
  1575. * \brief Setup network interfaces
  1576. * @param octeon_dev octeon device
  1577. *
  1578. * Called during init time for each device. It assumes the NIC
  1579. * is already up and running. The link information for each
  1580. * interface is passed in link_info.
  1581. */
  1582. static int setup_nic_devices(struct octeon_device *octeon_dev)
  1583. {
  1584. int retval, num_iqueues, num_oqueues;
  1585. struct liquidio_if_cfg_context *ctx;
  1586. u32 resp_size, ctx_size, data_size;
  1587. struct liquidio_if_cfg_resp *resp;
  1588. struct octeon_soft_command *sc;
  1589. union oct_nic_if_cfg if_cfg;
  1590. struct octdev_props *props;
  1591. struct net_device *netdev;
  1592. struct lio_version *vdata;
  1593. struct lio *lio = NULL;
  1594. u8 mac[ETH_ALEN], i, j;
  1595. u32 ifidx_or_pfnum;
  1596. ifidx_or_pfnum = octeon_dev->pf_num;
  1597. /* This is to handle link status changes */
  1598. octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC, OPCODE_NIC_INFO,
  1599. lio_nic_info, octeon_dev);
  1600. /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions.
  1601. * They are handled directly.
  1602. */
  1603. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET,
  1604. free_netbuf);
  1605. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG,
  1606. free_netsgbuf);
  1607. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG,
  1608. free_netsgbuf_with_resp);
  1609. for (i = 0; i < octeon_dev->ifcount; i++) {
  1610. resp_size = sizeof(struct liquidio_if_cfg_resp);
  1611. ctx_size = sizeof(struct liquidio_if_cfg_context);
  1612. data_size = sizeof(struct lio_version);
  1613. sc = (struct octeon_soft_command *)
  1614. octeon_alloc_soft_command(octeon_dev, data_size,
  1615. resp_size, ctx_size);
  1616. resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
  1617. ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
  1618. vdata = (struct lio_version *)sc->virtdptr;
  1619. *((u64 *)vdata) = 0;
  1620. vdata->major = cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
  1621. vdata->minor = cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
  1622. vdata->micro = cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
  1623. WRITE_ONCE(ctx->cond, 0);
  1624. ctx->octeon_id = lio_get_device_id(octeon_dev);
  1625. init_waitqueue_head(&ctx->wc);
  1626. if_cfg.u64 = 0;
  1627. if_cfg.s.num_iqueues = octeon_dev->sriov_info.rings_per_vf;
  1628. if_cfg.s.num_oqueues = octeon_dev->sriov_info.rings_per_vf;
  1629. if_cfg.s.base_queue = 0;
  1630. sc->iq_no = 0;
  1631. octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC,
  1632. OPCODE_NIC_IF_CFG, 0, if_cfg.u64,
  1633. 0);
  1634. sc->callback = lio_if_cfg_callback;
  1635. sc->callback_arg = sc;
  1636. sc->wait_time = 5000;
  1637. retval = octeon_send_soft_command(octeon_dev, sc);
  1638. if (retval == IQ_SEND_FAILED) {
  1639. dev_err(&octeon_dev->pci_dev->dev,
  1640. "iq/oq config failed status: %x\n", retval);
  1641. /* Soft instr is freed by driver in case of failure. */
  1642. goto setup_nic_dev_fail;
  1643. }
  1644. /* Sleep on a wait queue till the cond flag indicates that the
  1645. * response arrived or timed-out.
  1646. */
  1647. if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
  1648. dev_err(&octeon_dev->pci_dev->dev, "Wait interrupted\n");
  1649. goto setup_nic_wait_intr;
  1650. }
  1651. retval = resp->status;
  1652. if (retval) {
  1653. dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n");
  1654. goto setup_nic_dev_fail;
  1655. }
  1656. octeon_swap_8B_data((u64 *)(&resp->cfg_info),
  1657. (sizeof(struct liquidio_if_cfg_info)) >> 3);
  1658. num_iqueues = hweight64(resp->cfg_info.iqmask);
  1659. num_oqueues = hweight64(resp->cfg_info.oqmask);
  1660. if (!(num_iqueues) || !(num_oqueues)) {
  1661. dev_err(&octeon_dev->pci_dev->dev,
  1662. "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n",
  1663. resp->cfg_info.iqmask, resp->cfg_info.oqmask);
  1664. goto setup_nic_dev_fail;
  1665. }
  1666. dev_dbg(&octeon_dev->pci_dev->dev,
  1667. "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n",
  1668. i, resp->cfg_info.iqmask, resp->cfg_info.oqmask,
  1669. num_iqueues, num_oqueues);
  1670. netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues);
  1671. if (!netdev) {
  1672. dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n");
  1673. goto setup_nic_dev_fail;
  1674. }
  1675. SET_NETDEV_DEV(netdev, &octeon_dev->pci_dev->dev);
  1676. /* Associate the routines that will handle different
  1677. * netdev tasks.
  1678. */
  1679. netdev->netdev_ops = &lionetdevops;
  1680. lio = GET_LIO(netdev);
  1681. memset(lio, 0, sizeof(struct lio));
  1682. lio->ifidx = ifidx_or_pfnum;
  1683. props = &octeon_dev->props[i];
  1684. props->gmxport = resp->cfg_info.linfo.gmxport;
  1685. props->netdev = netdev;
  1686. lio->linfo.num_rxpciq = num_oqueues;
  1687. lio->linfo.num_txpciq = num_iqueues;
  1688. for (j = 0; j < num_oqueues; j++) {
  1689. lio->linfo.rxpciq[j].u64 =
  1690. resp->cfg_info.linfo.rxpciq[j].u64;
  1691. }
  1692. for (j = 0; j < num_iqueues; j++) {
  1693. lio->linfo.txpciq[j].u64 =
  1694. resp->cfg_info.linfo.txpciq[j].u64;
  1695. }
  1696. lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
  1697. lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
  1698. lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
  1699. lio->linfo.macaddr_is_admin_asgnd =
  1700. resp->cfg_info.linfo.macaddr_is_admin_asgnd;
  1701. lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  1702. lio->dev_capability = NETIF_F_HIGHDMA
  1703. | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
  1704. | NETIF_F_SG | NETIF_F_RXCSUM
  1705. | NETIF_F_TSO | NETIF_F_TSO6
  1706. | NETIF_F_GRO
  1707. | NETIF_F_LRO;
  1708. netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE);
  1709. /* Copy of transmit encapsulation capabilities:
  1710. * TSO, TSO6, Checksums for this device
  1711. */
  1712. lio->enc_dev_capability = NETIF_F_IP_CSUM
  1713. | NETIF_F_IPV6_CSUM
  1714. | NETIF_F_GSO_UDP_TUNNEL
  1715. | NETIF_F_HW_CSUM | NETIF_F_SG
  1716. | NETIF_F_RXCSUM
  1717. | NETIF_F_TSO | NETIF_F_TSO6
  1718. | NETIF_F_LRO;
  1719. netdev->hw_enc_features =
  1720. (lio->enc_dev_capability & ~NETIF_F_LRO);
  1721. netdev->vlan_features = lio->dev_capability;
  1722. /* Add any unchangeable hw features */
  1723. lio->dev_capability |= NETIF_F_HW_VLAN_CTAG_FILTER |
  1724. NETIF_F_HW_VLAN_CTAG_RX |
  1725. NETIF_F_HW_VLAN_CTAG_TX;
  1726. netdev->features = (lio->dev_capability & ~NETIF_F_LRO);
  1727. netdev->hw_features = lio->dev_capability;
  1728. netdev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX;
  1729. /* MTU range: 68 - 16000 */
  1730. netdev->min_mtu = LIO_MIN_MTU_SIZE;
  1731. netdev->max_mtu = LIO_MAX_MTU_SIZE;
  1732. /* Point to the properties for octeon device to which this
  1733. * interface belongs.
  1734. */
  1735. lio->oct_dev = octeon_dev;
  1736. lio->octprops = props;
  1737. lio->netdev = netdev;
  1738. dev_dbg(&octeon_dev->pci_dev->dev,
  1739. "if%d gmx: %d hw_addr: 0x%llx\n", i,
  1740. lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
  1741. /* 64-bit swap required on LE machines */
  1742. octeon_swap_8B_data(&lio->linfo.hw_addr, 1);
  1743. for (j = 0; j < ETH_ALEN; j++)
  1744. mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j));
  1745. /* Copy MAC Address to OS network device structure */
  1746. ether_addr_copy(netdev->dev_addr, mac);
  1747. if (liquidio_setup_io_queues(octeon_dev, i,
  1748. lio->linfo.num_txpciq,
  1749. lio->linfo.num_rxpciq)) {
  1750. dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n");
  1751. goto setup_nic_dev_fail;
  1752. }
  1753. ifstate_set(lio, LIO_IFSTATE_DROQ_OPS);
  1754. /* For VFs, enable Octeon device interrupts here,
  1755. * as this is contingent upon IO queue setup
  1756. */
  1757. octeon_dev->fn_list.enable_interrupt(octeon_dev,
  1758. OCTEON_ALL_INTR);
  1759. /* By default all interfaces on a single Octeon uses the same
  1760. * tx and rx queues
  1761. */
  1762. lio->txq = lio->linfo.txpciq[0].s.q_no;
  1763. lio->rxq = lio->linfo.rxpciq[0].s.q_no;
  1764. lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq);
  1765. lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq);
  1766. if (lio_setup_glists(octeon_dev, lio, num_iqueues)) {
  1767. dev_err(&octeon_dev->pci_dev->dev,
  1768. "Gather list allocation failed\n");
  1769. goto setup_nic_dev_fail;
  1770. }
  1771. /* Register ethtool support */
  1772. liquidio_set_ethtool_ops(netdev);
  1773. if (lio->oct_dev->chip_id == OCTEON_CN23XX_VF_VID)
  1774. octeon_dev->priv_flags = OCT_PRIV_FLAG_DEFAULT;
  1775. else
  1776. octeon_dev->priv_flags = 0x0;
  1777. if (netdev->features & NETIF_F_LRO)
  1778. liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
  1779. OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
  1780. if (setup_link_status_change_wq(netdev))
  1781. goto setup_nic_dev_fail;
  1782. if (setup_rx_oom_poll_fn(netdev))
  1783. goto setup_nic_dev_fail;
  1784. /* Register the network device with the OS */
  1785. if (register_netdev(netdev)) {
  1786. dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n");
  1787. goto setup_nic_dev_fail;
  1788. }
  1789. dev_dbg(&octeon_dev->pci_dev->dev,
  1790. "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n",
  1791. i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  1792. netif_carrier_off(netdev);
  1793. lio->link_changes++;
  1794. ifstate_set(lio, LIO_IFSTATE_REGISTERED);
  1795. /* Sending command to firmware to enable Rx checksum offload
  1796. * by default at the time of setup of Liquidio driver for
  1797. * this device
  1798. */
  1799. liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
  1800. OCTNET_CMD_RXCSUM_ENABLE);
  1801. liquidio_set_feature(netdev, OCTNET_CMD_TNL_TX_CSUM_CTL,
  1802. OCTNET_CMD_TXCSUM_ENABLE);
  1803. dev_dbg(&octeon_dev->pci_dev->dev,
  1804. "NIC ifidx:%d Setup successful\n", i);
  1805. octeon_free_soft_command(octeon_dev, sc);
  1806. octeon_dev->no_speed_setting = 1;
  1807. }
  1808. return 0;
  1809. setup_nic_dev_fail:
  1810. octeon_free_soft_command(octeon_dev, sc);
  1811. setup_nic_wait_intr:
  1812. while (i--) {
  1813. dev_err(&octeon_dev->pci_dev->dev,
  1814. "NIC ifidx:%d Setup failed\n", i);
  1815. liquidio_destroy_nic_device(octeon_dev, i);
  1816. }
  1817. return -ENODEV;
  1818. }
  1819. /**
  1820. * \brief initialize the NIC
  1821. * @param oct octeon device
  1822. *
  1823. * This initialization routine is called once the Octeon device application is
  1824. * up and running
  1825. */
  1826. static int liquidio_init_nic_module(struct octeon_device *oct)
  1827. {
  1828. int num_nic_ports = 1;
  1829. int i, retval = 0;
  1830. dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n");
  1831. /* only default iq and oq were initialized
  1832. * initialize the rest as well run port_config command for each port
  1833. */
  1834. oct->ifcount = num_nic_ports;
  1835. memset(oct->props, 0,
  1836. sizeof(struct octdev_props) * num_nic_ports);
  1837. for (i = 0; i < MAX_OCTEON_LINKS; i++)
  1838. oct->props[i].gmxport = -1;
  1839. retval = setup_nic_devices(oct);
  1840. if (retval) {
  1841. dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n");
  1842. goto octnet_init_failure;
  1843. }
  1844. dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n");
  1845. return retval;
  1846. octnet_init_failure:
  1847. oct->ifcount = 0;
  1848. return retval;
  1849. }
  1850. /**
  1851. * \brief Device initialization for each Octeon device that is probed
  1852. * @param octeon_dev octeon device
  1853. */
  1854. static int octeon_device_init(struct octeon_device *oct)
  1855. {
  1856. u32 rev_id;
  1857. int j;
  1858. atomic_set(&oct->status, OCT_DEV_BEGIN_STATE);
  1859. /* Enable access to the octeon device and make its DMA capability
  1860. * known to the OS.
  1861. */
  1862. if (octeon_pci_os_setup(oct))
  1863. return 1;
  1864. atomic_set(&oct->status, OCT_DEV_PCI_ENABLE_DONE);
  1865. oct->chip_id = OCTEON_CN23XX_VF_VID;
  1866. pci_read_config_dword(oct->pci_dev, 8, &rev_id);
  1867. oct->rev_id = rev_id & 0xff;
  1868. if (cn23xx_setup_octeon_vf_device(oct))
  1869. return 1;
  1870. atomic_set(&oct->status, OCT_DEV_PCI_MAP_DONE);
  1871. oct->app_mode = CVM_DRV_NIC_APP;
  1872. /* Initialize the dispatch mechanism used to push packets arriving on
  1873. * Octeon Output queues.
  1874. */
  1875. if (octeon_init_dispatch_list(oct))
  1876. return 1;
  1877. atomic_set(&oct->status, OCT_DEV_DISPATCH_INIT_DONE);
  1878. if (octeon_set_io_queues_off(oct)) {
  1879. dev_err(&oct->pci_dev->dev, "setting io queues off failed\n");
  1880. return 1;
  1881. }
  1882. if (oct->fn_list.setup_device_regs(oct)) {
  1883. dev_err(&oct->pci_dev->dev, "device registers configuration failed\n");
  1884. return 1;
  1885. }
  1886. /* Initialize soft command buffer pool */
  1887. if (octeon_setup_sc_buffer_pool(oct)) {
  1888. dev_err(&oct->pci_dev->dev, "sc buffer pool allocation failed\n");
  1889. return 1;
  1890. }
  1891. atomic_set(&oct->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE);
  1892. /* Setup the data structures that manage this Octeon's Input queues. */
  1893. if (octeon_setup_instr_queues(oct)) {
  1894. dev_err(&oct->pci_dev->dev, "instruction queue initialization failed\n");
  1895. return 1;
  1896. }
  1897. atomic_set(&oct->status, OCT_DEV_INSTR_QUEUE_INIT_DONE);
  1898. /* Initialize lists to manage the requests of different types that
  1899. * arrive from user & kernel applications for this octeon device.
  1900. */
  1901. if (octeon_setup_response_list(oct)) {
  1902. dev_err(&oct->pci_dev->dev, "Response list allocation failed\n");
  1903. return 1;
  1904. }
  1905. atomic_set(&oct->status, OCT_DEV_RESP_LIST_INIT_DONE);
  1906. if (octeon_setup_output_queues(oct)) {
  1907. dev_err(&oct->pci_dev->dev, "Output queue initialization failed\n");
  1908. return 1;
  1909. }
  1910. atomic_set(&oct->status, OCT_DEV_DROQ_INIT_DONE);
  1911. if (oct->fn_list.setup_mbox(oct)) {
  1912. dev_err(&oct->pci_dev->dev, "Mailbox setup failed\n");
  1913. return 1;
  1914. }
  1915. atomic_set(&oct->status, OCT_DEV_MBOX_SETUP_DONE);
  1916. if (octeon_allocate_ioq_vector(oct, oct->sriov_info.rings_per_vf)) {
  1917. dev_err(&oct->pci_dev->dev, "ioq vector allocation failed\n");
  1918. return 1;
  1919. }
  1920. atomic_set(&oct->status, OCT_DEV_MSIX_ALLOC_VECTOR_DONE);
  1921. dev_info(&oct->pci_dev->dev, "OCTEON_CN23XX VF Version: %s, %d ioqs\n",
  1922. LIQUIDIO_VERSION, oct->sriov_info.rings_per_vf);
  1923. /* Setup the interrupt handler and record the INT SUM register address*/
  1924. if (octeon_setup_interrupt(oct, oct->sriov_info.rings_per_vf))
  1925. return 1;
  1926. atomic_set(&oct->status, OCT_DEV_INTR_SET_DONE);
  1927. /* ***************************************************************
  1928. * The interrupts need to be enabled for the PF<-->VF handshake.
  1929. * They are [re]-enabled after the PF<-->VF handshake so that the
  1930. * correct OQ tick value is used (i.e. the value retrieved from
  1931. * the PF as part of the handshake).
  1932. */
  1933. /* Enable Octeon device interrupts */
  1934. oct->fn_list.enable_interrupt(oct, OCTEON_ALL_INTR);
  1935. if (cn23xx_octeon_pfvf_handshake(oct))
  1936. return 1;
  1937. /* Here we [re]-enable the interrupts so that the correct OQ tick value
  1938. * is used (i.e. the value that was retrieved during the handshake)
  1939. */
  1940. /* Enable Octeon device interrupts */
  1941. oct->fn_list.enable_interrupt(oct, OCTEON_ALL_INTR);
  1942. /* *************************************************************** */
  1943. /* Enable the input and output queues for this Octeon device */
  1944. if (oct->fn_list.enable_io_queues(oct)) {
  1945. dev_err(&oct->pci_dev->dev, "enabling io queues failed\n");
  1946. return 1;
  1947. }
  1948. atomic_set(&oct->status, OCT_DEV_IO_QUEUES_DONE);
  1949. atomic_set(&oct->status, OCT_DEV_HOST_OK);
  1950. /* Send Credit for Octeon Output queues. Credits are always sent after
  1951. * the output queue is enabled.
  1952. */
  1953. for (j = 0; j < oct->num_oqs; j++)
  1954. writel(oct->droq[j]->max_count, oct->droq[j]->pkts_credit_reg);
  1955. /* Packets can start arriving on the output queues from this point. */
  1956. atomic_set(&oct->status, OCT_DEV_CORE_OK);
  1957. atomic_set(&oct->status, OCT_DEV_RUNNING);
  1958. if (liquidio_init_nic_module(oct))
  1959. return 1;
  1960. return 0;
  1961. }
  1962. static int __init liquidio_vf_init(void)
  1963. {
  1964. octeon_init_device_list(0);
  1965. return pci_register_driver(&liquidio_vf_pci_driver);
  1966. }
  1967. static void __exit liquidio_vf_exit(void)
  1968. {
  1969. pci_unregister_driver(&liquidio_vf_pci_driver);
  1970. pr_info("LiquidIO_VF network module is now unloaded\n");
  1971. }
  1972. module_init(liquidio_vf_init);
  1973. module_exit(liquidio_vf_exit);