lio_main.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2015 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
  17. * details.
  18. *
  19. * This file may also be available under a different license from Cavium.
  20. * Contact Cavium, Inc. for more information
  21. **********************************************************************/
  22. #include <linux/version.h>
  23. #include <linux/module.h>
  24. #include <linux/crc32.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/pci.h>
  27. #include <linux/pci_ids.h>
  28. #include <linux/ip.h>
  29. #include <net/ip.h>
  30. #include <linux/ipv6.h>
  31. #include <linux/net_tstamp.h>
  32. #include <linux/if_vlan.h>
  33. #include <linux/firmware.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/ptp_clock_kernel.h>
  36. #include <linux/types.h>
  37. #include <linux/list.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/interrupt.h>
  40. #include "octeon_config.h"
  41. #include "liquidio_common.h"
  42. #include "octeon_droq.h"
  43. #include "octeon_iq.h"
  44. #include "response_manager.h"
  45. #include "octeon_device.h"
  46. #include "octeon_nic.h"
  47. #include "octeon_main.h"
  48. #include "octeon_network.h"
  49. #include "cn66xx_regs.h"
  50. #include "cn66xx_device.h"
  51. #include "cn68xx_regs.h"
  52. #include "cn68xx_device.h"
  53. #include "liquidio_image.h"
  54. MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
  55. MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
  56. MODULE_LICENSE("GPL");
  57. MODULE_VERSION(LIQUIDIO_VERSION);
  58. MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210SV_NAME LIO_FW_NAME_SUFFIX);
  59. MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210NV_NAME LIO_FW_NAME_SUFFIX);
  60. MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_410NV_NAME LIO_FW_NAME_SUFFIX);
  61. static int ddr_timeout = 10000;
  62. module_param(ddr_timeout, int, 0644);
  63. MODULE_PARM_DESC(ddr_timeout,
  64. "Number of milliseconds to wait for DDR initialization. 0 waits for ddr_timeout to be set to non-zero value before starting to check");
  65. static u32 console_bitmask;
  66. module_param(console_bitmask, int, 0644);
  67. MODULE_PARM_DESC(console_bitmask,
  68. "Bitmask indicating which consoles have debug output redirected to syslog.");
  69. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  70. static int debug = -1;
  71. module_param(debug, int, 0644);
  72. MODULE_PARM_DESC(debug, "NETIF_MSG debug bits");
  73. static char fw_type[LIO_MAX_FW_TYPE_LEN];
  74. module_param_string(fw_type, fw_type, sizeof(fw_type), 0000);
  75. MODULE_PARM_DESC(fw_type, "Type of firmware to be loaded. Default \"nic\"");
  76. static int conf_type;
  77. module_param(conf_type, int, 0);
  78. MODULE_PARM_DESC(conf_type, "select octeon configuration 0 default 1 ovs");
  79. /* Bit mask values for lio->ifstate */
  80. #define LIO_IFSTATE_DROQ_OPS 0x01
  81. #define LIO_IFSTATE_REGISTERED 0x02
  82. #define LIO_IFSTATE_RUNNING 0x04
  83. #define LIO_IFSTATE_RX_TIMESTAMP_ENABLED 0x08
  84. /* Polling interval for determining when NIC application is alive */
  85. #define LIQUIDIO_STARTER_POLL_INTERVAL_MS 100
  86. /* runtime link query interval */
  87. #define LIQUIDIO_LINK_QUERY_INTERVAL_MS 1000
  88. struct liquidio_if_cfg_context {
  89. int octeon_id;
  90. wait_queue_head_t wc;
  91. int cond;
  92. };
  93. struct liquidio_if_cfg_resp {
  94. u64 rh;
  95. struct liquidio_if_cfg_info cfg_info;
  96. u64 status;
  97. };
  98. struct oct_link_status_resp {
  99. u64 rh;
  100. struct oct_link_info link_info;
  101. u64 status;
  102. };
  103. struct oct_timestamp_resp {
  104. u64 rh;
  105. u64 timestamp;
  106. u64 status;
  107. };
  108. #define OCT_TIMESTAMP_RESP_SIZE (sizeof(struct oct_timestamp_resp))
  109. union tx_info {
  110. u64 u64;
  111. struct {
  112. #ifdef __BIG_ENDIAN_BITFIELD
  113. u16 gso_size;
  114. u16 gso_segs;
  115. u32 reserved;
  116. #else
  117. u32 reserved;
  118. u16 gso_segs;
  119. u16 gso_size;
  120. #endif
  121. } s;
  122. };
  123. /** Octeon device properties to be used by the NIC module.
  124. * Each octeon device in the system will be represented
  125. * by this structure in the NIC module.
  126. */
  127. #define OCTNIC_MAX_SG (MAX_SKB_FRAGS)
  128. #define OCTNIC_GSO_MAX_HEADER_SIZE 128
  129. #define OCTNIC_GSO_MAX_SIZE (GSO_MAX_SIZE - OCTNIC_GSO_MAX_HEADER_SIZE)
  130. /** Structure of a node in list of gather components maintained by
  131. * NIC driver for each network device.
  132. */
  133. struct octnic_gather {
  134. /** List manipulation. Next and prev pointers. */
  135. struct list_head list;
  136. /** Size of the gather component at sg in bytes. */
  137. int sg_size;
  138. /** Number of bytes that sg was adjusted to make it 8B-aligned. */
  139. int adjust;
  140. /** Gather component that can accommodate max sized fragment list
  141. * received from the IP layer.
  142. */
  143. struct octeon_sg_entry *sg;
  144. };
  145. /** This structure is used by NIC driver to store information required
  146. * to free the sk_buff when the packet has been fetched by Octeon.
  147. * Bytes offset below assume worst-case of a 64-bit system.
  148. */
  149. struct octnet_buf_free_info {
  150. /** Bytes 1-8. Pointer to network device private structure. */
  151. struct lio *lio;
  152. /** Bytes 9-16. Pointer to sk_buff. */
  153. struct sk_buff *skb;
  154. /** Bytes 17-24. Pointer to gather list. */
  155. struct octnic_gather *g;
  156. /** Bytes 25-32. Physical address of skb->data or gather list. */
  157. u64 dptr;
  158. /** Bytes 33-47. Piggybacked soft command, if any */
  159. struct octeon_soft_command *sc;
  160. };
  161. struct handshake {
  162. struct completion init;
  163. struct completion started;
  164. struct pci_dev *pci_dev;
  165. int init_ok;
  166. int started_ok;
  167. };
  168. struct octeon_device_priv {
  169. /** Tasklet structures for this device. */
  170. struct tasklet_struct droq_tasklet;
  171. unsigned long napi_mask;
  172. };
  173. static int octeon_device_init(struct octeon_device *);
  174. static void liquidio_remove(struct pci_dev *pdev);
  175. static int liquidio_probe(struct pci_dev *pdev,
  176. const struct pci_device_id *ent);
  177. static struct handshake handshake[MAX_OCTEON_DEVICES];
  178. static struct completion first_stage;
  179. static void octeon_droq_bh(unsigned long pdev)
  180. {
  181. int q_no;
  182. int reschedule = 0;
  183. struct octeon_device *oct = (struct octeon_device *)pdev;
  184. struct octeon_device_priv *oct_priv =
  185. (struct octeon_device_priv *)oct->priv;
  186. /* for (q_no = 0; q_no < oct->num_oqs; q_no++) { */
  187. for (q_no = 0; q_no < MAX_OCTEON_OUTPUT_QUEUES; q_no++) {
  188. if (!(oct->io_qmask.oq & (1UL << q_no)))
  189. continue;
  190. reschedule |= octeon_droq_process_packets(oct, oct->droq[q_no],
  191. MAX_PACKET_BUDGET);
  192. }
  193. if (reschedule)
  194. tasklet_schedule(&oct_priv->droq_tasklet);
  195. }
  196. static int lio_wait_for_oq_pkts(struct octeon_device *oct)
  197. {
  198. struct octeon_device_priv *oct_priv =
  199. (struct octeon_device_priv *)oct->priv;
  200. int retry = 100, pkt_cnt = 0, pending_pkts = 0;
  201. int i;
  202. do {
  203. pending_pkts = 0;
  204. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES; i++) {
  205. if (!(oct->io_qmask.oq & (1UL << i)))
  206. continue;
  207. pkt_cnt += octeon_droq_check_hw_for_pkts(oct,
  208. oct->droq[i]);
  209. }
  210. if (pkt_cnt > 0) {
  211. pending_pkts += pkt_cnt;
  212. tasklet_schedule(&oct_priv->droq_tasklet);
  213. }
  214. pkt_cnt = 0;
  215. schedule_timeout_uninterruptible(1);
  216. } while (retry-- && pending_pkts);
  217. return pkt_cnt;
  218. }
  219. void octeon_report_tx_completion_to_bql(void *txq, unsigned int pkts_compl,
  220. unsigned int bytes_compl)
  221. {
  222. struct netdev_queue *netdev_queue = txq;
  223. netdev_tx_completed_queue(netdev_queue, pkts_compl, bytes_compl);
  224. }
  225. void octeon_update_tx_completion_counters(void *buf, int reqtype,
  226. unsigned int *pkts_compl,
  227. unsigned int *bytes_compl)
  228. {
  229. struct octnet_buf_free_info *finfo;
  230. struct sk_buff *skb = NULL;
  231. struct octeon_soft_command *sc;
  232. switch (reqtype) {
  233. case REQTYPE_NORESP_NET:
  234. case REQTYPE_NORESP_NET_SG:
  235. finfo = buf;
  236. skb = finfo->skb;
  237. break;
  238. case REQTYPE_RESP_NET_SG:
  239. case REQTYPE_RESP_NET:
  240. sc = buf;
  241. skb = sc->callback_arg;
  242. break;
  243. default:
  244. return;
  245. }
  246. (*pkts_compl)++;
  247. *bytes_compl += skb->len;
  248. }
  249. void octeon_report_sent_bytes_to_bql(void *buf, int reqtype)
  250. {
  251. struct octnet_buf_free_info *finfo;
  252. struct sk_buff *skb;
  253. struct octeon_soft_command *sc;
  254. struct netdev_queue *txq;
  255. switch (reqtype) {
  256. case REQTYPE_NORESP_NET:
  257. case REQTYPE_NORESP_NET_SG:
  258. finfo = buf;
  259. skb = finfo->skb;
  260. break;
  261. case REQTYPE_RESP_NET_SG:
  262. case REQTYPE_RESP_NET:
  263. sc = buf;
  264. skb = sc->callback_arg;
  265. break;
  266. default:
  267. return;
  268. }
  269. txq = netdev_get_tx_queue(skb->dev, skb_get_queue_mapping(skb));
  270. netdev_tx_sent_queue(txq, skb->len);
  271. }
  272. int octeon_console_debug_enabled(u32 console)
  273. {
  274. return (console_bitmask >> (console)) & 0x1;
  275. }
  276. /**
  277. * \brief Forces all IO queues off on a given device
  278. * @param oct Pointer to Octeon device
  279. */
  280. static void force_io_queues_off(struct octeon_device *oct)
  281. {
  282. if ((oct->chip_id == OCTEON_CN66XX) ||
  283. (oct->chip_id == OCTEON_CN68XX)) {
  284. /* Reset the Enable bits for Input Queues. */
  285. octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
  286. /* Reset the Enable bits for Output Queues. */
  287. octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
  288. }
  289. }
  290. /**
  291. * \brief wait for all pending requests to complete
  292. * @param oct Pointer to Octeon device
  293. *
  294. * Called during shutdown sequence
  295. */
  296. static int wait_for_pending_requests(struct octeon_device *oct)
  297. {
  298. int i, pcount = 0;
  299. for (i = 0; i < 100; i++) {
  300. pcount =
  301. atomic_read(&oct->response_list
  302. [OCTEON_ORDERED_SC_LIST].pending_req_count);
  303. if (pcount)
  304. schedule_timeout_uninterruptible(HZ / 10);
  305. else
  306. break;
  307. }
  308. if (pcount)
  309. return 1;
  310. return 0;
  311. }
  312. /**
  313. * \brief Cause device to go quiet so it can be safely removed/reset/etc
  314. * @param oct Pointer to Octeon device
  315. */
  316. static inline void pcierror_quiesce_device(struct octeon_device *oct)
  317. {
  318. int i;
  319. /* Disable the input and output queues now. No more packets will
  320. * arrive from Octeon, but we should wait for all packet processing
  321. * to finish.
  322. */
  323. force_io_queues_off(oct);
  324. /* To allow for in-flight requests */
  325. schedule_timeout_uninterruptible(100);
  326. if (wait_for_pending_requests(oct))
  327. dev_err(&oct->pci_dev->dev, "There were pending requests\n");
  328. /* Force all requests waiting to be fetched by OCTEON to complete. */
  329. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES; i++) {
  330. struct octeon_instr_queue *iq;
  331. if (!(oct->io_qmask.iq & (1UL << i)))
  332. continue;
  333. iq = oct->instr_queue[i];
  334. if (atomic_read(&iq->instr_pending)) {
  335. spin_lock_bh(&iq->lock);
  336. iq->fill_cnt = 0;
  337. iq->octeon_read_index = iq->host_write_index;
  338. iq->stats.instr_processed +=
  339. atomic_read(&iq->instr_pending);
  340. lio_process_iq_request_list(oct, iq);
  341. spin_unlock_bh(&iq->lock);
  342. }
  343. }
  344. /* Force all pending ordered list requests to time out. */
  345. lio_process_ordered_list(oct, 1);
  346. /* We do not need to wait for output queue packets to be processed. */
  347. }
  348. /**
  349. * \brief Cleanup PCI AER uncorrectable error status
  350. * @param dev Pointer to PCI device
  351. */
  352. static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
  353. {
  354. int pos = 0x100;
  355. u32 status, mask;
  356. pr_info("%s :\n", __func__);
  357. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
  358. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
  359. if (dev->error_state == pci_channel_io_normal)
  360. status &= ~mask; /* Clear corresponding nonfatal bits */
  361. else
  362. status &= mask; /* Clear corresponding fatal bits */
  363. pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
  364. }
  365. /**
  366. * \brief Stop all PCI IO to a given device
  367. * @param dev Pointer to Octeon device
  368. */
  369. static void stop_pci_io(struct octeon_device *oct)
  370. {
  371. /* No more instructions will be forwarded. */
  372. atomic_set(&oct->status, OCT_DEV_IN_RESET);
  373. pci_disable_device(oct->pci_dev);
  374. /* Disable interrupts */
  375. oct->fn_list.disable_interrupt(oct->chip);
  376. pcierror_quiesce_device(oct);
  377. /* Release the interrupt line */
  378. free_irq(oct->pci_dev->irq, oct);
  379. if (oct->flags & LIO_FLAG_MSI_ENABLED)
  380. pci_disable_msi(oct->pci_dev);
  381. dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
  382. lio_get_state_string(&oct->status));
  383. /* cn63xx_cleanup_aer_uncorrect_error_status(oct->pci_dev); */
  384. /* making it a common function for all OCTEON models */
  385. cleanup_aer_uncorrect_error_status(oct->pci_dev);
  386. }
  387. /**
  388. * \brief called when PCI error is detected
  389. * @param pdev Pointer to PCI device
  390. * @param state The current pci connection state
  391. *
  392. * This function is called after a PCI bus error affecting
  393. * this device has been detected.
  394. */
  395. static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev,
  396. pci_channel_state_t state)
  397. {
  398. struct octeon_device *oct = pci_get_drvdata(pdev);
  399. /* Non-correctable Non-fatal errors */
  400. if (state == pci_channel_io_normal) {
  401. dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n");
  402. cleanup_aer_uncorrect_error_status(oct->pci_dev);
  403. return PCI_ERS_RESULT_CAN_RECOVER;
  404. }
  405. /* Non-correctable Fatal errors */
  406. dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n");
  407. stop_pci_io(oct);
  408. /* Always return a DISCONNECT. There is no support for recovery but only
  409. * for a clean shutdown.
  410. */
  411. return PCI_ERS_RESULT_DISCONNECT;
  412. }
  413. /**
  414. * \brief mmio handler
  415. * @param pdev Pointer to PCI device
  416. */
  417. static pci_ers_result_t liquidio_pcie_mmio_enabled(struct pci_dev *pdev)
  418. {
  419. /* We should never hit this since we never ask for a reset for a Fatal
  420. * Error. We always return DISCONNECT in io_error above.
  421. * But play safe and return RECOVERED for now.
  422. */
  423. return PCI_ERS_RESULT_RECOVERED;
  424. }
  425. /**
  426. * \brief called after the pci bus has been reset.
  427. * @param pdev Pointer to PCI device
  428. *
  429. * Restart the card from scratch, as if from a cold-boot. Implementation
  430. * resembles the first-half of the octeon_resume routine.
  431. */
  432. static pci_ers_result_t liquidio_pcie_slot_reset(struct pci_dev *pdev)
  433. {
  434. /* We should never hit this since we never ask for a reset for a Fatal
  435. * Error. We always return DISCONNECT in io_error above.
  436. * But play safe and return RECOVERED for now.
  437. */
  438. return PCI_ERS_RESULT_RECOVERED;
  439. }
  440. /**
  441. * \brief called when traffic can start flowing again.
  442. * @param pdev Pointer to PCI device
  443. *
  444. * This callback is called when the error recovery driver tells us that
  445. * its OK to resume normal operation. Implementation resembles the
  446. * second-half of the octeon_resume routine.
  447. */
  448. static void liquidio_pcie_resume(struct pci_dev *pdev)
  449. {
  450. /* Nothing to be done here. */
  451. }
  452. #ifdef CONFIG_PM
  453. /**
  454. * \brief called when suspending
  455. * @param pdev Pointer to PCI device
  456. * @param state state to suspend to
  457. */
  458. static int liquidio_suspend(struct pci_dev *pdev, pm_message_t state)
  459. {
  460. return 0;
  461. }
  462. /**
  463. * \brief called when resuming
  464. * @param pdev Pointer to PCI device
  465. */
  466. static int liquidio_resume(struct pci_dev *pdev)
  467. {
  468. return 0;
  469. }
  470. #endif
  471. /* For PCI-E Advanced Error Recovery (AER) Interface */
  472. static const struct pci_error_handlers liquidio_err_handler = {
  473. .error_detected = liquidio_pcie_error_detected,
  474. .mmio_enabled = liquidio_pcie_mmio_enabled,
  475. .slot_reset = liquidio_pcie_slot_reset,
  476. .resume = liquidio_pcie_resume,
  477. };
  478. static const struct pci_device_id liquidio_pci_tbl[] = {
  479. { /* 68xx */
  480. PCI_VENDOR_ID_CAVIUM, 0x91, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
  481. },
  482. { /* 66xx */
  483. PCI_VENDOR_ID_CAVIUM, 0x92, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
  484. },
  485. {
  486. 0, 0, 0, 0, 0, 0, 0
  487. }
  488. };
  489. MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl);
  490. static struct pci_driver liquidio_pci_driver = {
  491. .name = "LiquidIO",
  492. .id_table = liquidio_pci_tbl,
  493. .probe = liquidio_probe,
  494. .remove = liquidio_remove,
  495. .err_handler = &liquidio_err_handler, /* For AER */
  496. #ifdef CONFIG_PM
  497. .suspend = liquidio_suspend,
  498. .resume = liquidio_resume,
  499. #endif
  500. };
  501. /**
  502. * \brief register PCI driver
  503. */
  504. static int liquidio_init_pci(void)
  505. {
  506. return pci_register_driver(&liquidio_pci_driver);
  507. }
  508. /**
  509. * \brief unregister PCI driver
  510. */
  511. static void liquidio_deinit_pci(void)
  512. {
  513. pci_unregister_driver(&liquidio_pci_driver);
  514. }
  515. /**
  516. * \brief check interface state
  517. * @param lio per-network private data
  518. * @param state_flag flag state to check
  519. */
  520. static inline int ifstate_check(struct lio *lio, int state_flag)
  521. {
  522. return atomic_read(&lio->ifstate) & state_flag;
  523. }
  524. /**
  525. * \brief set interface state
  526. * @param lio per-network private data
  527. * @param state_flag flag state to set
  528. */
  529. static inline void ifstate_set(struct lio *lio, int state_flag)
  530. {
  531. atomic_set(&lio->ifstate, (atomic_read(&lio->ifstate) | state_flag));
  532. }
  533. /**
  534. * \brief clear interface state
  535. * @param lio per-network private data
  536. * @param state_flag flag state to clear
  537. */
  538. static inline void ifstate_reset(struct lio *lio, int state_flag)
  539. {
  540. atomic_set(&lio->ifstate, (atomic_read(&lio->ifstate) & ~(state_flag)));
  541. }
  542. /**
  543. * \brief Stop Tx queues
  544. * @param netdev network device
  545. */
  546. static inline void txqs_stop(struct net_device *netdev)
  547. {
  548. if (netif_is_multiqueue(netdev)) {
  549. int i;
  550. for (i = 0; i < netdev->num_tx_queues; i++)
  551. netif_stop_subqueue(netdev, i);
  552. } else {
  553. netif_stop_queue(netdev);
  554. }
  555. }
  556. /**
  557. * \brief Start Tx queues
  558. * @param netdev network device
  559. */
  560. static inline void txqs_start(struct net_device *netdev)
  561. {
  562. if (netif_is_multiqueue(netdev)) {
  563. int i;
  564. for (i = 0; i < netdev->num_tx_queues; i++)
  565. netif_start_subqueue(netdev, i);
  566. } else {
  567. netif_start_queue(netdev);
  568. }
  569. }
  570. /**
  571. * \brief Wake Tx queues
  572. * @param netdev network device
  573. */
  574. static inline void txqs_wake(struct net_device *netdev)
  575. {
  576. if (netif_is_multiqueue(netdev)) {
  577. int i;
  578. for (i = 0; i < netdev->num_tx_queues; i++)
  579. netif_wake_subqueue(netdev, i);
  580. } else {
  581. netif_wake_queue(netdev);
  582. }
  583. }
  584. /**
  585. * \brief Stop Tx queue
  586. * @param netdev network device
  587. */
  588. static void stop_txq(struct net_device *netdev)
  589. {
  590. txqs_stop(netdev);
  591. }
  592. /**
  593. * \brief Start Tx queue
  594. * @param netdev network device
  595. */
  596. static void start_txq(struct net_device *netdev)
  597. {
  598. struct lio *lio = GET_LIO(netdev);
  599. if (lio->linfo.link.s.status) {
  600. txqs_start(netdev);
  601. return;
  602. }
  603. }
  604. /**
  605. * \brief Wake a queue
  606. * @param netdev network device
  607. * @param q which queue to wake
  608. */
  609. static inline void wake_q(struct net_device *netdev, int q)
  610. {
  611. if (netif_is_multiqueue(netdev))
  612. netif_wake_subqueue(netdev, q);
  613. else
  614. netif_wake_queue(netdev);
  615. }
  616. /**
  617. * \brief Stop a queue
  618. * @param netdev network device
  619. * @param q which queue to stop
  620. */
  621. static inline void stop_q(struct net_device *netdev, int q)
  622. {
  623. if (netif_is_multiqueue(netdev))
  624. netif_stop_subqueue(netdev, q);
  625. else
  626. netif_stop_queue(netdev);
  627. }
  628. /**
  629. * \brief Check Tx queue status, and take appropriate action
  630. * @param lio per-network private data
  631. * @returns 0 if full, number of queues woken up otherwise
  632. */
  633. static inline int check_txq_status(struct lio *lio)
  634. {
  635. int ret_val = 0;
  636. if (netif_is_multiqueue(lio->netdev)) {
  637. int numqs = lio->netdev->num_tx_queues;
  638. int q, iq = 0;
  639. /* check each sub-queue state */
  640. for (q = 0; q < numqs; q++) {
  641. iq = lio->linfo.txpciq[q & (lio->linfo.num_txpciq - 1)];
  642. if (octnet_iq_is_full(lio->oct_dev, iq))
  643. continue;
  644. wake_q(lio->netdev, q);
  645. ret_val++;
  646. }
  647. } else {
  648. if (octnet_iq_is_full(lio->oct_dev, lio->txq))
  649. return 0;
  650. wake_q(lio->netdev, lio->txq);
  651. ret_val = 1;
  652. }
  653. return ret_val;
  654. }
  655. /**
  656. * Remove the node at the head of the list. The list would be empty at
  657. * the end of this call if there are no more nodes in the list.
  658. */
  659. static inline struct list_head *list_delete_head(struct list_head *root)
  660. {
  661. struct list_head *node;
  662. if ((root->prev == root) && (root->next == root))
  663. node = NULL;
  664. else
  665. node = root->next;
  666. if (node)
  667. list_del(node);
  668. return node;
  669. }
  670. /**
  671. * \brief Delete gather list
  672. * @param lio per-network private data
  673. */
  674. static void delete_glist(struct lio *lio)
  675. {
  676. struct octnic_gather *g;
  677. do {
  678. g = (struct octnic_gather *)
  679. list_delete_head(&lio->glist);
  680. if (g) {
  681. if (g->sg)
  682. kfree((void *)((unsigned long)g->sg -
  683. g->adjust));
  684. kfree(g);
  685. }
  686. } while (g);
  687. }
  688. /**
  689. * \brief Setup gather list
  690. * @param lio per-network private data
  691. */
  692. static int setup_glist(struct lio *lio)
  693. {
  694. int i;
  695. struct octnic_gather *g;
  696. INIT_LIST_HEAD(&lio->glist);
  697. for (i = 0; i < lio->tx_qsize; i++) {
  698. g = kzalloc(sizeof(*g), GFP_KERNEL);
  699. if (!g)
  700. break;
  701. g->sg_size =
  702. ((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
  703. g->sg = kmalloc(g->sg_size + 8, GFP_KERNEL);
  704. if (!g->sg) {
  705. kfree(g);
  706. break;
  707. }
  708. /* The gather component should be aligned on 64-bit boundary */
  709. if (((unsigned long)g->sg) & 7) {
  710. g->adjust = 8 - (((unsigned long)g->sg) & 7);
  711. g->sg = (struct octeon_sg_entry *)
  712. ((unsigned long)g->sg + g->adjust);
  713. }
  714. list_add_tail(&g->list, &lio->glist);
  715. }
  716. if (i == lio->tx_qsize)
  717. return 0;
  718. delete_glist(lio);
  719. return 1;
  720. }
  721. /**
  722. * \brief Print link information
  723. * @param netdev network device
  724. */
  725. static void print_link_info(struct net_device *netdev)
  726. {
  727. struct lio *lio = GET_LIO(netdev);
  728. if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED) {
  729. struct oct_link_info *linfo = &lio->linfo;
  730. if (linfo->link.s.status) {
  731. netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n",
  732. linfo->link.s.speed,
  733. (linfo->link.s.duplex) ? "Full" : "Half");
  734. } else {
  735. netif_info(lio, link, lio->netdev, "Link Down\n");
  736. }
  737. }
  738. }
  739. /**
  740. * \brief Update link status
  741. * @param netdev network device
  742. * @param ls link status structure
  743. *
  744. * Called on receipt of a link status response from the core application to
  745. * update each interface's link status.
  746. */
  747. static inline void update_link_status(struct net_device *netdev,
  748. union oct_link_status *ls)
  749. {
  750. struct lio *lio = GET_LIO(netdev);
  751. if ((lio->intf_open) && (lio->linfo.link.u64 != ls->u64)) {
  752. lio->linfo.link.u64 = ls->u64;
  753. print_link_info(netdev);
  754. if (lio->linfo.link.s.status) {
  755. netif_carrier_on(netdev);
  756. /* start_txq(netdev); */
  757. txqs_wake(netdev);
  758. } else {
  759. netif_carrier_off(netdev);
  760. stop_txq(netdev);
  761. }
  762. }
  763. }
  764. /**
  765. * \brief Droq packet processor sceduler
  766. * @param oct octeon device
  767. */
  768. static
  769. void liquidio_schedule_droq_pkt_handlers(struct octeon_device *oct)
  770. {
  771. struct octeon_device_priv *oct_priv =
  772. (struct octeon_device_priv *)oct->priv;
  773. u64 oq_no;
  774. struct octeon_droq *droq;
  775. if (oct->int_status & OCT_DEV_INTR_PKT_DATA) {
  776. for (oq_no = 0; oq_no < MAX_OCTEON_OUTPUT_QUEUES; oq_no++) {
  777. if (!(oct->droq_intr & (1 << oq_no)))
  778. continue;
  779. droq = oct->droq[oq_no];
  780. if (droq->ops.poll_mode) {
  781. droq->ops.napi_fn(droq);
  782. oct_priv->napi_mask |= (1 << oq_no);
  783. } else {
  784. tasklet_schedule(&oct_priv->droq_tasklet);
  785. }
  786. }
  787. }
  788. }
  789. /**
  790. * \brief Interrupt handler for octeon
  791. * @param irq unused
  792. * @param dev octeon device
  793. */
  794. static
  795. irqreturn_t liquidio_intr_handler(int irq __attribute__((unused)), void *dev)
  796. {
  797. struct octeon_device *oct = (struct octeon_device *)dev;
  798. irqreturn_t ret;
  799. /* Disable our interrupts for the duration of ISR */
  800. oct->fn_list.disable_interrupt(oct->chip);
  801. ret = oct->fn_list.process_interrupt_regs(oct);
  802. if (ret == IRQ_HANDLED)
  803. liquidio_schedule_droq_pkt_handlers(oct);
  804. /* Re-enable our interrupts */
  805. if (!(atomic_read(&oct->status) == OCT_DEV_IN_RESET))
  806. oct->fn_list.enable_interrupt(oct->chip);
  807. return ret;
  808. }
  809. /**
  810. * \brief Setup interrupt for octeon device
  811. * @param oct octeon device
  812. *
  813. * Enable interrupt in Octeon device as given in the PCI interrupt mask.
  814. */
  815. static int octeon_setup_interrupt(struct octeon_device *oct)
  816. {
  817. int irqret, err;
  818. err = pci_enable_msi(oct->pci_dev);
  819. if (err)
  820. dev_warn(&oct->pci_dev->dev, "Reverting to legacy interrupts. Error: %d\n",
  821. err);
  822. else
  823. oct->flags |= LIO_FLAG_MSI_ENABLED;
  824. irqret = request_irq(oct->pci_dev->irq, liquidio_intr_handler,
  825. IRQF_SHARED, "octeon", oct);
  826. if (irqret) {
  827. if (oct->flags & LIO_FLAG_MSI_ENABLED)
  828. pci_disable_msi(oct->pci_dev);
  829. dev_err(&oct->pci_dev->dev, "Request IRQ failed with code: %d\n",
  830. irqret);
  831. return 1;
  832. }
  833. return 0;
  834. }
  835. /**
  836. * \brief PCI probe handler
  837. * @param pdev PCI device structure
  838. * @param ent unused
  839. */
  840. static int liquidio_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  841. {
  842. struct octeon_device *oct_dev = NULL;
  843. struct handshake *hs;
  844. oct_dev = octeon_allocate_device(pdev->device,
  845. sizeof(struct octeon_device_priv));
  846. if (!oct_dev) {
  847. dev_err(&pdev->dev, "Unable to allocate device\n");
  848. return -ENOMEM;
  849. }
  850. dev_info(&pdev->dev, "Initializing device %x:%x.\n",
  851. (u32)pdev->vendor, (u32)pdev->device);
  852. /* Assign octeon_device for this device to the private data area. */
  853. pci_set_drvdata(pdev, oct_dev);
  854. /* set linux specific device pointer */
  855. oct_dev->pci_dev = (void *)pdev;
  856. hs = &handshake[oct_dev->octeon_id];
  857. init_completion(&hs->init);
  858. init_completion(&hs->started);
  859. hs->pci_dev = pdev;
  860. if (oct_dev->octeon_id == 0)
  861. /* first LiquidIO NIC is detected */
  862. complete(&first_stage);
  863. if (octeon_device_init(oct_dev)) {
  864. liquidio_remove(pdev);
  865. return -ENOMEM;
  866. }
  867. dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n");
  868. return 0;
  869. }
  870. /**
  871. *\brief Destroy resources associated with octeon device
  872. * @param pdev PCI device structure
  873. * @param ent unused
  874. */
  875. static void octeon_destroy_resources(struct octeon_device *oct)
  876. {
  877. int i;
  878. struct octeon_device_priv *oct_priv =
  879. (struct octeon_device_priv *)oct->priv;
  880. struct handshake *hs;
  881. switch (atomic_read(&oct->status)) {
  882. case OCT_DEV_RUNNING:
  883. case OCT_DEV_CORE_OK:
  884. /* No more instructions will be forwarded. */
  885. atomic_set(&oct->status, OCT_DEV_IN_RESET);
  886. oct->app_mode = CVM_DRV_INVALID_APP;
  887. dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
  888. lio_get_state_string(&oct->status));
  889. schedule_timeout_uninterruptible(HZ / 10);
  890. /* fallthrough */
  891. case OCT_DEV_HOST_OK:
  892. /* fallthrough */
  893. case OCT_DEV_CONSOLE_INIT_DONE:
  894. /* Remove any consoles */
  895. octeon_remove_consoles(oct);
  896. /* fallthrough */
  897. case OCT_DEV_IO_QUEUES_DONE:
  898. if (wait_for_pending_requests(oct))
  899. dev_err(&oct->pci_dev->dev, "There were pending requests\n");
  900. if (lio_wait_for_instr_fetch(oct))
  901. dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
  902. /* Disable the input and output queues now. No more packets will
  903. * arrive from Octeon, but we should wait for all packet
  904. * processing to finish.
  905. */
  906. oct->fn_list.disable_io_queues(oct);
  907. if (lio_wait_for_oq_pkts(oct))
  908. dev_err(&oct->pci_dev->dev, "OQ had pending packets\n");
  909. /* Disable interrupts */
  910. oct->fn_list.disable_interrupt(oct->chip);
  911. /* Release the interrupt line */
  912. free_irq(oct->pci_dev->irq, oct);
  913. if (oct->flags & LIO_FLAG_MSI_ENABLED)
  914. pci_disable_msi(oct->pci_dev);
  915. /* Soft reset the octeon device before exiting */
  916. oct->fn_list.soft_reset(oct);
  917. /* Disable the device, releasing the PCI INT */
  918. pci_disable_device(oct->pci_dev);
  919. /* fallthrough */
  920. case OCT_DEV_IN_RESET:
  921. case OCT_DEV_DROQ_INIT_DONE:
  922. /*atomic_set(&oct->status, OCT_DEV_DROQ_INIT_DONE);*/
  923. mdelay(100);
  924. for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES; i++) {
  925. if (!(oct->io_qmask.oq & (1UL << i)))
  926. continue;
  927. octeon_delete_droq(oct, i);
  928. }
  929. /* Force any pending handshakes to complete */
  930. for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
  931. hs = &handshake[i];
  932. if (hs->pci_dev) {
  933. handshake[oct->octeon_id].init_ok = 0;
  934. complete(&handshake[oct->octeon_id].init);
  935. handshake[oct->octeon_id].started_ok = 0;
  936. complete(&handshake[oct->octeon_id].started);
  937. }
  938. }
  939. /* fallthrough */
  940. case OCT_DEV_RESP_LIST_INIT_DONE:
  941. octeon_delete_response_list(oct);
  942. /* fallthrough */
  943. case OCT_DEV_SC_BUFF_POOL_INIT_DONE:
  944. octeon_free_sc_buffer_pool(oct);
  945. /* fallthrough */
  946. case OCT_DEV_INSTR_QUEUE_INIT_DONE:
  947. for (i = 0; i < MAX_OCTEON_INSTR_QUEUES; i++) {
  948. if (!(oct->io_qmask.iq & (1UL << i)))
  949. continue;
  950. octeon_delete_instr_queue(oct, i);
  951. }
  952. /* fallthrough */
  953. case OCT_DEV_DISPATCH_INIT_DONE:
  954. octeon_delete_dispatch_list(oct);
  955. cancel_delayed_work_sync(&oct->nic_poll_work.work);
  956. /* fallthrough */
  957. case OCT_DEV_PCI_MAP_DONE:
  958. octeon_unmap_pci_barx(oct, 0);
  959. octeon_unmap_pci_barx(oct, 1);
  960. /* fallthrough */
  961. case OCT_DEV_BEGIN_STATE:
  962. /* Nothing to be done here either */
  963. break;
  964. } /* end switch(oct->status) */
  965. tasklet_kill(&oct_priv->droq_tasklet);
  966. }
  967. /**
  968. * \brief Send Rx control command
  969. * @param lio per-network private data
  970. * @param start_stop whether to start or stop
  971. */
  972. static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
  973. {
  974. struct octnic_ctrl_pkt nctrl;
  975. struct octnic_ctrl_params nparams;
  976. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  977. nctrl.ncmd.s.cmd = OCTNET_CMD_RX_CTL;
  978. nctrl.ncmd.s.param1 = lio->linfo.ifidx;
  979. nctrl.ncmd.s.param2 = start_stop;
  980. nctrl.netpndev = (u64)lio->netdev;
  981. nparams.resp_order = OCTEON_RESP_NORESPONSE;
  982. if (octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl, nparams) < 0)
  983. netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
  984. }
  985. /**
  986. * \brief Destroy NIC device interface
  987. * @param oct octeon device
  988. * @param ifidx which interface to destroy
  989. *
  990. * Cleanup associated with each interface for an Octeon device when NIC
  991. * module is being unloaded or if initialization fails during load.
  992. */
  993. static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx)
  994. {
  995. struct net_device *netdev = oct->props[ifidx].netdev;
  996. struct lio *lio;
  997. if (!netdev) {
  998. dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n",
  999. __func__, ifidx);
  1000. return;
  1001. }
  1002. lio = GET_LIO(netdev);
  1003. dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n");
  1004. send_rx_ctrl_cmd(lio, 0);
  1005. if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING)
  1006. txqs_stop(netdev);
  1007. if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED)
  1008. unregister_netdev(netdev);
  1009. delete_glist(lio);
  1010. free_netdev(netdev);
  1011. oct->props[ifidx].netdev = NULL;
  1012. }
  1013. /**
  1014. * \brief Stop complete NIC functionality
  1015. * @param oct octeon device
  1016. */
  1017. static int liquidio_stop_nic_module(struct octeon_device *oct)
  1018. {
  1019. int i, j;
  1020. struct lio *lio;
  1021. dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n");
  1022. if (!oct->ifcount) {
  1023. dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n");
  1024. return 1;
  1025. }
  1026. for (i = 0; i < oct->ifcount; i++) {
  1027. lio = GET_LIO(oct->props[i].netdev);
  1028. for (j = 0; j < lio->linfo.num_rxpciq; j++)
  1029. octeon_unregister_droq_ops(oct, lio->linfo.rxpciq[j]);
  1030. }
  1031. for (i = 0; i < oct->ifcount; i++)
  1032. liquidio_destroy_nic_device(oct, i);
  1033. dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
  1034. return 0;
  1035. }
  1036. /**
  1037. * \brief Cleans up resources at unload time
  1038. * @param pdev PCI device structure
  1039. */
  1040. static void liquidio_remove(struct pci_dev *pdev)
  1041. {
  1042. struct octeon_device *oct_dev = pci_get_drvdata(pdev);
  1043. dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
  1044. if (oct_dev->app_mode && (oct_dev->app_mode == CVM_DRV_NIC_APP))
  1045. liquidio_stop_nic_module(oct_dev);
  1046. /* Reset the octeon device and cleanup all memory allocated for
  1047. * the octeon device by driver.
  1048. */
  1049. octeon_destroy_resources(oct_dev);
  1050. dev_info(&oct_dev->pci_dev->dev, "Device removed\n");
  1051. /* This octeon device has been removed. Update the global
  1052. * data structure to reflect this. Free the device structure.
  1053. */
  1054. octeon_free_device_mem(oct_dev);
  1055. }
  1056. /**
  1057. * \brief Identify the Octeon device and to map the BAR address space
  1058. * @param oct octeon device
  1059. */
  1060. static int octeon_chip_specific_setup(struct octeon_device *oct)
  1061. {
  1062. u32 dev_id, rev_id;
  1063. int ret = 1;
  1064. pci_read_config_dword(oct->pci_dev, 0, &dev_id);
  1065. pci_read_config_dword(oct->pci_dev, 8, &rev_id);
  1066. oct->rev_id = rev_id & 0xff;
  1067. switch (dev_id) {
  1068. case OCTEON_CN68XX_PCIID:
  1069. oct->chip_id = OCTEON_CN68XX;
  1070. ret = lio_setup_cn68xx_octeon_device(oct);
  1071. break;
  1072. case OCTEON_CN66XX_PCIID:
  1073. oct->chip_id = OCTEON_CN66XX;
  1074. ret = lio_setup_cn66xx_octeon_device(oct);
  1075. break;
  1076. default:
  1077. dev_err(&oct->pci_dev->dev, "Unknown device found (dev_id: %x)\n",
  1078. dev_id);
  1079. }
  1080. if (!ret)
  1081. dev_info(&oct->pci_dev->dev, "CN68XX PASS%d.%d %s\n",
  1082. OCTEON_MAJOR_REV(oct),
  1083. OCTEON_MINOR_REV(oct),
  1084. octeon_get_conf(oct)->card_name);
  1085. return ret;
  1086. }
  1087. /**
  1088. * \brief PCI initialization for each Octeon device.
  1089. * @param oct octeon device
  1090. */
  1091. static int octeon_pci_os_setup(struct octeon_device *oct)
  1092. {
  1093. /* setup PCI stuff first */
  1094. if (pci_enable_device(oct->pci_dev)) {
  1095. dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n");
  1096. return 1;
  1097. }
  1098. if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) {
  1099. dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n");
  1100. return 1;
  1101. }
  1102. /* Enable PCI DMA Master. */
  1103. pci_set_master(oct->pci_dev);
  1104. return 0;
  1105. }
  1106. /**
  1107. * \brief Check Tx queue state for a given network buffer
  1108. * @param lio per-network private data
  1109. * @param skb network buffer
  1110. */
  1111. static inline int check_txq_state(struct lio *lio, struct sk_buff *skb)
  1112. {
  1113. int q = 0, iq = 0;
  1114. if (netif_is_multiqueue(lio->netdev)) {
  1115. q = skb->queue_mapping;
  1116. iq = lio->linfo.txpciq[(q & (lio->linfo.num_txpciq - 1))];
  1117. } else {
  1118. iq = lio->txq;
  1119. }
  1120. if (octnet_iq_is_full(lio->oct_dev, iq))
  1121. return 0;
  1122. wake_q(lio->netdev, q);
  1123. return 1;
  1124. }
  1125. /**
  1126. * \brief Unmap and free network buffer
  1127. * @param buf buffer
  1128. */
  1129. static void free_netbuf(void *buf)
  1130. {
  1131. struct sk_buff *skb;
  1132. struct octnet_buf_free_info *finfo;
  1133. struct lio *lio;
  1134. finfo = (struct octnet_buf_free_info *)buf;
  1135. skb = finfo->skb;
  1136. lio = finfo->lio;
  1137. dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len,
  1138. DMA_TO_DEVICE);
  1139. check_txq_state(lio, skb);
  1140. recv_buffer_free((struct sk_buff *)skb);
  1141. }
  1142. /**
  1143. * \brief Unmap and free gather buffer
  1144. * @param buf buffer
  1145. */
  1146. static void free_netsgbuf(void *buf)
  1147. {
  1148. struct octnet_buf_free_info *finfo;
  1149. struct sk_buff *skb;
  1150. struct lio *lio;
  1151. struct octnic_gather *g;
  1152. int i, frags;
  1153. finfo = (struct octnet_buf_free_info *)buf;
  1154. skb = finfo->skb;
  1155. lio = finfo->lio;
  1156. g = finfo->g;
  1157. frags = skb_shinfo(skb)->nr_frags;
  1158. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  1159. g->sg[0].ptr[0], (skb->len - skb->data_len),
  1160. DMA_TO_DEVICE);
  1161. i = 1;
  1162. while (frags--) {
  1163. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
  1164. pci_unmap_page((lio->oct_dev)->pci_dev,
  1165. g->sg[(i >> 2)].ptr[(i & 3)],
  1166. frag->size, DMA_TO_DEVICE);
  1167. i++;
  1168. }
  1169. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  1170. finfo->dptr, g->sg_size,
  1171. DMA_TO_DEVICE);
  1172. spin_lock(&lio->lock);
  1173. list_add_tail(&g->list, &lio->glist);
  1174. spin_unlock(&lio->lock);
  1175. check_txq_state(lio, skb); /* mq support: sub-queue state check */
  1176. recv_buffer_free((struct sk_buff *)skb);
  1177. }
  1178. /**
  1179. * \brief Unmap and free gather buffer with response
  1180. * @param buf buffer
  1181. */
  1182. static void free_netsgbuf_with_resp(void *buf)
  1183. {
  1184. struct octeon_soft_command *sc;
  1185. struct octnet_buf_free_info *finfo;
  1186. struct sk_buff *skb;
  1187. struct lio *lio;
  1188. struct octnic_gather *g;
  1189. int i, frags;
  1190. sc = (struct octeon_soft_command *)buf;
  1191. skb = (struct sk_buff *)sc->callback_arg;
  1192. finfo = (struct octnet_buf_free_info *)&skb->cb;
  1193. lio = finfo->lio;
  1194. g = finfo->g;
  1195. frags = skb_shinfo(skb)->nr_frags;
  1196. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  1197. g->sg[0].ptr[0], (skb->len - skb->data_len),
  1198. DMA_TO_DEVICE);
  1199. i = 1;
  1200. while (frags--) {
  1201. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
  1202. pci_unmap_page((lio->oct_dev)->pci_dev,
  1203. g->sg[(i >> 2)].ptr[(i & 3)],
  1204. frag->size, DMA_TO_DEVICE);
  1205. i++;
  1206. }
  1207. dma_unmap_single(&lio->oct_dev->pci_dev->dev,
  1208. finfo->dptr, g->sg_size,
  1209. DMA_TO_DEVICE);
  1210. spin_lock(&lio->lock);
  1211. list_add_tail(&g->list, &lio->glist);
  1212. spin_unlock(&lio->lock);
  1213. /* Don't free the skb yet */
  1214. check_txq_state(lio, skb);
  1215. }
  1216. /**
  1217. * \brief Adjust ptp frequency
  1218. * @param ptp PTP clock info
  1219. * @param ppb how much to adjust by, in parts-per-billion
  1220. */
  1221. static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  1222. {
  1223. struct lio *lio = container_of(ptp, struct lio, ptp_info);
  1224. struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
  1225. u64 comp, delta;
  1226. unsigned long flags;
  1227. bool neg_adj = false;
  1228. if (ppb < 0) {
  1229. neg_adj = true;
  1230. ppb = -ppb;
  1231. }
  1232. /* The hardware adds the clock compensation value to the
  1233. * PTP clock on every coprocessor clock cycle, so we
  1234. * compute the delta in terms of coprocessor clocks.
  1235. */
  1236. delta = (u64)ppb << 32;
  1237. do_div(delta, oct->coproc_clock_rate);
  1238. spin_lock_irqsave(&lio->ptp_lock, flags);
  1239. comp = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_COMP);
  1240. if (neg_adj)
  1241. comp -= delta;
  1242. else
  1243. comp += delta;
  1244. lio_pci_writeq(oct, comp, CN6XXX_MIO_PTP_CLOCK_COMP);
  1245. spin_unlock_irqrestore(&lio->ptp_lock, flags);
  1246. return 0;
  1247. }
  1248. /**
  1249. * \brief Adjust ptp time
  1250. * @param ptp PTP clock info
  1251. * @param delta how much to adjust by, in nanosecs
  1252. */
  1253. static int liquidio_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  1254. {
  1255. unsigned long flags;
  1256. struct lio *lio = container_of(ptp, struct lio, ptp_info);
  1257. spin_lock_irqsave(&lio->ptp_lock, flags);
  1258. lio->ptp_adjust += delta;
  1259. spin_unlock_irqrestore(&lio->ptp_lock, flags);
  1260. return 0;
  1261. }
  1262. /**
  1263. * \brief Get hardware clock time, including any adjustment
  1264. * @param ptp PTP clock info
  1265. * @param ts timespec
  1266. */
  1267. static int liquidio_ptp_gettime(struct ptp_clock_info *ptp,
  1268. struct timespec64 *ts)
  1269. {
  1270. u64 ns;
  1271. unsigned long flags;
  1272. struct lio *lio = container_of(ptp, struct lio, ptp_info);
  1273. struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
  1274. spin_lock_irqsave(&lio->ptp_lock, flags);
  1275. ns = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_HI);
  1276. ns += lio->ptp_adjust;
  1277. spin_unlock_irqrestore(&lio->ptp_lock, flags);
  1278. *ts = ns_to_timespec64(ns);
  1279. return 0;
  1280. }
  1281. /**
  1282. * \brief Set hardware clock time. Reset adjustment
  1283. * @param ptp PTP clock info
  1284. * @param ts timespec
  1285. */
  1286. static int liquidio_ptp_settime(struct ptp_clock_info *ptp,
  1287. const struct timespec64 *ts)
  1288. {
  1289. u64 ns;
  1290. unsigned long flags;
  1291. struct lio *lio = container_of(ptp, struct lio, ptp_info);
  1292. struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
  1293. ns = timespec_to_ns(ts);
  1294. spin_lock_irqsave(&lio->ptp_lock, flags);
  1295. lio_pci_writeq(oct, ns, CN6XXX_MIO_PTP_CLOCK_HI);
  1296. lio->ptp_adjust = 0;
  1297. spin_unlock_irqrestore(&lio->ptp_lock, flags);
  1298. return 0;
  1299. }
  1300. /**
  1301. * \brief Check if PTP is enabled
  1302. * @param ptp PTP clock info
  1303. * @param rq request
  1304. * @param on is it on
  1305. */
  1306. static int liquidio_ptp_enable(struct ptp_clock_info *ptp,
  1307. struct ptp_clock_request *rq, int on)
  1308. {
  1309. return -EOPNOTSUPP;
  1310. }
  1311. /**
  1312. * \brief Open PTP clock source
  1313. * @param netdev network device
  1314. */
  1315. static void oct_ptp_open(struct net_device *netdev)
  1316. {
  1317. struct lio *lio = GET_LIO(netdev);
  1318. struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
  1319. spin_lock_init(&lio->ptp_lock);
  1320. snprintf(lio->ptp_info.name, 16, "%s", netdev->name);
  1321. lio->ptp_info.owner = THIS_MODULE;
  1322. lio->ptp_info.max_adj = 250000000;
  1323. lio->ptp_info.n_alarm = 0;
  1324. lio->ptp_info.n_ext_ts = 0;
  1325. lio->ptp_info.n_per_out = 0;
  1326. lio->ptp_info.pps = 0;
  1327. lio->ptp_info.adjfreq = liquidio_ptp_adjfreq;
  1328. lio->ptp_info.adjtime = liquidio_ptp_adjtime;
  1329. lio->ptp_info.gettime64 = liquidio_ptp_gettime;
  1330. lio->ptp_info.settime64 = liquidio_ptp_settime;
  1331. lio->ptp_info.enable = liquidio_ptp_enable;
  1332. lio->ptp_adjust = 0;
  1333. lio->ptp_clock = ptp_clock_register(&lio->ptp_info,
  1334. &oct->pci_dev->dev);
  1335. if (IS_ERR(lio->ptp_clock))
  1336. lio->ptp_clock = NULL;
  1337. }
  1338. /**
  1339. * \brief Init PTP clock
  1340. * @param oct octeon device
  1341. */
  1342. static void liquidio_ptp_init(struct octeon_device *oct)
  1343. {
  1344. u64 clock_comp, cfg;
  1345. clock_comp = (u64)NSEC_PER_SEC << 32;
  1346. do_div(clock_comp, oct->coproc_clock_rate);
  1347. lio_pci_writeq(oct, clock_comp, CN6XXX_MIO_PTP_CLOCK_COMP);
  1348. /* Enable */
  1349. cfg = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_CFG);
  1350. lio_pci_writeq(oct, cfg | 0x01, CN6XXX_MIO_PTP_CLOCK_CFG);
  1351. }
  1352. /**
  1353. * \brief Load firmware to device
  1354. * @param oct octeon device
  1355. *
  1356. * Maps device to firmware filename, requests firmware, and downloads it
  1357. */
  1358. static int load_firmware(struct octeon_device *oct)
  1359. {
  1360. int ret = 0;
  1361. const struct firmware *fw;
  1362. char fw_name[LIO_MAX_FW_FILENAME_LEN];
  1363. char *tmp_fw_type;
  1364. if (strncmp(fw_type, LIO_FW_NAME_TYPE_NONE,
  1365. sizeof(LIO_FW_NAME_TYPE_NONE)) == 0) {
  1366. dev_info(&oct->pci_dev->dev, "Skipping firmware load\n");
  1367. return ret;
  1368. }
  1369. if (fw_type[0] == '\0')
  1370. tmp_fw_type = LIO_FW_NAME_TYPE_NIC;
  1371. else
  1372. tmp_fw_type = fw_type;
  1373. sprintf(fw_name, "%s%s%s_%s%s", LIO_FW_DIR, LIO_FW_BASE_NAME,
  1374. octeon_get_conf(oct)->card_name, tmp_fw_type,
  1375. LIO_FW_NAME_SUFFIX);
  1376. ret = request_firmware(&fw, fw_name, &oct->pci_dev->dev);
  1377. if (ret) {
  1378. dev_err(&oct->pci_dev->dev, "Request firmware failed. Could not find file %s.\n.",
  1379. fw_name);
  1380. return ret;
  1381. }
  1382. ret = octeon_download_firmware(oct, fw->data, fw->size);
  1383. release_firmware(fw);
  1384. return ret;
  1385. }
  1386. /**
  1387. * \brief Setup output queue
  1388. * @param oct octeon device
  1389. * @param q_no which queue
  1390. * @param num_descs how many descriptors
  1391. * @param desc_size size of each descriptor
  1392. * @param app_ctx application context
  1393. */
  1394. static int octeon_setup_droq(struct octeon_device *oct, int q_no, int num_descs,
  1395. int desc_size, void *app_ctx)
  1396. {
  1397. int ret_val = 0;
  1398. dev_dbg(&oct->pci_dev->dev, "Creating Droq: %d\n", q_no);
  1399. /* droq creation and local register settings. */
  1400. ret_val = octeon_create_droq(oct, q_no, num_descs, desc_size, app_ctx);
  1401. if (ret_val < 0)
  1402. return ret_val;
  1403. if (ret_val == 1) {
  1404. dev_dbg(&oct->pci_dev->dev, "Using default droq %d\n", q_no);
  1405. return 0;
  1406. }
  1407. /* tasklet creation for the droq */
  1408. /* Enable the droq queues */
  1409. octeon_set_droq_pkt_op(oct, q_no, 1);
  1410. /* Send Credit for Octeon Output queues. Credits are always
  1411. * sent after the output queue is enabled.
  1412. */
  1413. writel(oct->droq[q_no]->max_count,
  1414. oct->droq[q_no]->pkts_credit_reg);
  1415. return ret_val;
  1416. }
  1417. /**
  1418. * \brief Callback for getting interface configuration
  1419. * @param status status of request
  1420. * @param buf pointer to resp structure
  1421. */
  1422. static void if_cfg_callback(struct octeon_device *oct,
  1423. u32 status,
  1424. void *buf)
  1425. {
  1426. struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
  1427. struct liquidio_if_cfg_resp *resp;
  1428. struct liquidio_if_cfg_context *ctx;
  1429. resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
  1430. ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
  1431. oct = lio_get_device(ctx->octeon_id);
  1432. if (resp->status)
  1433. dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: %llx\n",
  1434. CVM_CAST64(resp->status));
  1435. ACCESS_ONCE(ctx->cond) = 1;
  1436. /* This barrier is required to be sure that the response has been
  1437. * written fully before waking up the handler
  1438. */
  1439. wmb();
  1440. wake_up_interruptible(&ctx->wc);
  1441. }
  1442. /**
  1443. * \brief Select queue based on hash
  1444. * @param dev Net device
  1445. * @param skb sk_buff structure
  1446. * @returns selected queue number
  1447. */
  1448. static u16 select_q(struct net_device *dev, struct sk_buff *skb,
  1449. void *accel_priv, select_queue_fallback_t fallback)
  1450. {
  1451. int qindex;
  1452. struct lio *lio;
  1453. lio = GET_LIO(dev);
  1454. /* select queue on chosen queue_mapping or core */
  1455. qindex = skb_rx_queue_recorded(skb) ?
  1456. skb_get_rx_queue(skb) : smp_processor_id();
  1457. return (u16)(qindex & (lio->linfo.num_txpciq - 1));
  1458. }
  1459. /** Routine to push packets arriving on Octeon interface upto network layer.
  1460. * @param oct_id - octeon device id.
  1461. * @param skbuff - skbuff struct to be passed to network layer.
  1462. * @param len - size of total data received.
  1463. * @param rh - Control header associated with the packet
  1464. * @param param - additional control data with the packet
  1465. */
  1466. static void
  1467. liquidio_push_packet(u32 octeon_id,
  1468. void *skbuff,
  1469. u32 len,
  1470. union octeon_rh *rh,
  1471. void *param)
  1472. {
  1473. struct napi_struct *napi = param;
  1474. struct octeon_device *oct = lio_get_device(octeon_id);
  1475. struct sk_buff *skb = (struct sk_buff *)skbuff;
  1476. struct skb_shared_hwtstamps *shhwtstamps;
  1477. u64 ns;
  1478. struct net_device *netdev =
  1479. (struct net_device *)oct->props[rh->r_dh.link].netdev;
  1480. struct octeon_droq *droq = container_of(param, struct octeon_droq,
  1481. napi);
  1482. if (netdev) {
  1483. int packet_was_received;
  1484. struct lio *lio = GET_LIO(netdev);
  1485. /* Do not proceed if the interface is not in RUNNING state. */
  1486. if (!ifstate_check(lio, LIO_IFSTATE_RUNNING)) {
  1487. recv_buffer_free(skb);
  1488. droq->stats.rx_dropped++;
  1489. return;
  1490. }
  1491. skb->dev = netdev;
  1492. if (rh->r_dh.has_hwtstamp) {
  1493. /* timestamp is included from the hardware at the
  1494. * beginning of the packet.
  1495. */
  1496. if (ifstate_check(lio,
  1497. LIO_IFSTATE_RX_TIMESTAMP_ENABLED)) {
  1498. /* Nanoseconds are in the first 64-bits
  1499. * of the packet.
  1500. */
  1501. memcpy(&ns, (skb->data), sizeof(ns));
  1502. shhwtstamps = skb_hwtstamps(skb);
  1503. shhwtstamps->hwtstamp =
  1504. ns_to_ktime(ns + lio->ptp_adjust);
  1505. }
  1506. skb_pull(skb, sizeof(ns));
  1507. }
  1508. skb->protocol = eth_type_trans(skb, skb->dev);
  1509. if ((netdev->features & NETIF_F_RXCSUM) &&
  1510. (rh->r_dh.csum_verified == CNNIC_CSUM_VERIFIED))
  1511. /* checksum has already been verified */
  1512. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1513. else
  1514. skb->ip_summed = CHECKSUM_NONE;
  1515. packet_was_received = napi_gro_receive(napi, skb) != GRO_DROP;
  1516. if (packet_was_received) {
  1517. droq->stats.rx_bytes_received += len;
  1518. droq->stats.rx_pkts_received++;
  1519. netdev->last_rx = jiffies;
  1520. } else {
  1521. droq->stats.rx_dropped++;
  1522. netif_info(lio, rx_err, lio->netdev,
  1523. "droq:%d error rx_dropped:%llu\n",
  1524. droq->q_no, droq->stats.rx_dropped);
  1525. }
  1526. } else {
  1527. recv_buffer_free(skb);
  1528. }
  1529. }
  1530. /**
  1531. * \brief wrapper for calling napi_schedule
  1532. * @param param parameters to pass to napi_schedule
  1533. *
  1534. * Used when scheduling on different CPUs
  1535. */
  1536. static void napi_schedule_wrapper(void *param)
  1537. {
  1538. struct napi_struct *napi = param;
  1539. napi_schedule(napi);
  1540. }
  1541. /**
  1542. * \brief callback when receive interrupt occurs and we are in NAPI mode
  1543. * @param arg pointer to octeon output queue
  1544. */
  1545. static void liquidio_napi_drv_callback(void *arg)
  1546. {
  1547. struct octeon_droq *droq = arg;
  1548. int this_cpu = smp_processor_id();
  1549. if (droq->cpu_id == this_cpu) {
  1550. napi_schedule(&droq->napi);
  1551. } else {
  1552. struct call_single_data *csd = &droq->csd;
  1553. csd->func = napi_schedule_wrapper;
  1554. csd->info = &droq->napi;
  1555. csd->flags = 0;
  1556. smp_call_function_single_async(droq->cpu_id, csd);
  1557. }
  1558. }
  1559. /**
  1560. * \brief Main NAPI poll function
  1561. * @param droq octeon output queue
  1562. * @param budget maximum number of items to process
  1563. */
  1564. static int liquidio_napi_do_rx(struct octeon_droq *droq, int budget)
  1565. {
  1566. int work_done;
  1567. struct lio *lio = GET_LIO(droq->napi.dev);
  1568. struct octeon_device *oct = lio->oct_dev;
  1569. work_done = octeon_process_droq_poll_cmd(oct, droq->q_no,
  1570. POLL_EVENT_PROCESS_PKTS,
  1571. budget);
  1572. if (work_done < 0) {
  1573. netif_info(lio, rx_err, lio->netdev,
  1574. "Receive work_done < 0, rxq:%d\n", droq->q_no);
  1575. goto octnet_napi_finish;
  1576. }
  1577. if (work_done > budget)
  1578. dev_err(&oct->pci_dev->dev, ">>>> %s work_done: %d budget: %d\n",
  1579. __func__, work_done, budget);
  1580. return work_done;
  1581. octnet_napi_finish:
  1582. napi_complete(&droq->napi);
  1583. octeon_process_droq_poll_cmd(oct, droq->q_no, POLL_EVENT_ENABLE_INTR,
  1584. 0);
  1585. return 0;
  1586. }
  1587. /**
  1588. * \brief Entry point for NAPI polling
  1589. * @param napi NAPI structure
  1590. * @param budget maximum number of items to process
  1591. */
  1592. static int liquidio_napi_poll(struct napi_struct *napi, int budget)
  1593. {
  1594. struct octeon_droq *droq;
  1595. int work_done;
  1596. droq = container_of(napi, struct octeon_droq, napi);
  1597. work_done = liquidio_napi_do_rx(droq, budget);
  1598. if (work_done < budget) {
  1599. napi_complete(napi);
  1600. octeon_process_droq_poll_cmd(droq->oct_dev, droq->q_no,
  1601. POLL_EVENT_ENABLE_INTR, 0);
  1602. return 0;
  1603. }
  1604. return work_done;
  1605. }
  1606. /**
  1607. * \brief Setup input and output queues
  1608. * @param octeon_dev octeon device
  1609. * @param net_device Net device
  1610. *
  1611. * Note: Queues are with respect to the octeon device. Thus
  1612. * an input queue is for egress packets, and output queues
  1613. * are for ingress packets.
  1614. */
  1615. static inline int setup_io_queues(struct octeon_device *octeon_dev,
  1616. struct net_device *net_device)
  1617. {
  1618. static int first_time = 1;
  1619. static struct octeon_droq_ops droq_ops;
  1620. static int cpu_id;
  1621. static int cpu_id_modulus;
  1622. struct octeon_droq *droq;
  1623. struct napi_struct *napi;
  1624. int q, q_no, retval = 0;
  1625. struct lio *lio;
  1626. int num_tx_descs;
  1627. lio = GET_LIO(net_device);
  1628. if (first_time) {
  1629. first_time = 0;
  1630. memset(&droq_ops, 0, sizeof(struct octeon_droq_ops));
  1631. droq_ops.fptr = liquidio_push_packet;
  1632. droq_ops.poll_mode = 1;
  1633. droq_ops.napi_fn = liquidio_napi_drv_callback;
  1634. cpu_id = 0;
  1635. cpu_id_modulus = num_present_cpus();
  1636. }
  1637. /* set up DROQs. */
  1638. for (q = 0; q < lio->linfo.num_rxpciq; q++) {
  1639. q_no = lio->linfo.rxpciq[q];
  1640. retval = octeon_setup_droq(octeon_dev, q_no,
  1641. CFG_GET_NUM_RX_DESCS_NIC_IF
  1642. (octeon_get_conf(octeon_dev),
  1643. lio->ifidx),
  1644. CFG_GET_NUM_RX_BUF_SIZE_NIC_IF
  1645. (octeon_get_conf(octeon_dev),
  1646. lio->ifidx), NULL);
  1647. if (retval) {
  1648. dev_err(&octeon_dev->pci_dev->dev,
  1649. " %s : Runtime DROQ(RxQ) creation failed.\n",
  1650. __func__);
  1651. return 1;
  1652. }
  1653. droq = octeon_dev->droq[q_no];
  1654. napi = &droq->napi;
  1655. netif_napi_add(net_device, napi, liquidio_napi_poll, 64);
  1656. /* designate a CPU for this droq */
  1657. droq->cpu_id = cpu_id;
  1658. cpu_id++;
  1659. if (cpu_id >= cpu_id_modulus)
  1660. cpu_id = 0;
  1661. octeon_register_droq_ops(octeon_dev, q_no, &droq_ops);
  1662. }
  1663. /* set up IQs. */
  1664. for (q = 0; q < lio->linfo.num_txpciq; q++) {
  1665. num_tx_descs = CFG_GET_NUM_TX_DESCS_NIC_IF(octeon_get_conf
  1666. (octeon_dev),
  1667. lio->ifidx);
  1668. retval = octeon_setup_iq(octeon_dev, lio->linfo.txpciq[q],
  1669. num_tx_descs,
  1670. netdev_get_tx_queue(net_device, q));
  1671. if (retval) {
  1672. dev_err(&octeon_dev->pci_dev->dev,
  1673. " %s : Runtime IQ(TxQ) creation failed.\n",
  1674. __func__);
  1675. return 1;
  1676. }
  1677. }
  1678. return 0;
  1679. }
  1680. /**
  1681. * \brief Poll routine for checking transmit queue status
  1682. * @param work work_struct data structure
  1683. */
  1684. static void octnet_poll_check_txq_status(struct work_struct *work)
  1685. {
  1686. struct cavium_wk *wk = (struct cavium_wk *)work;
  1687. struct lio *lio = (struct lio *)wk->ctxptr;
  1688. if (!ifstate_check(lio, LIO_IFSTATE_RUNNING))
  1689. return;
  1690. check_txq_status(lio);
  1691. queue_delayed_work(lio->txq_status_wq.wq,
  1692. &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
  1693. }
  1694. /**
  1695. * \brief Sets up the txq poll check
  1696. * @param netdev network device
  1697. */
  1698. static inline void setup_tx_poll_fn(struct net_device *netdev)
  1699. {
  1700. struct lio *lio = GET_LIO(netdev);
  1701. struct octeon_device *oct = lio->oct_dev;
  1702. lio->txq_status_wq.wq = create_workqueue("txq-status");
  1703. if (!lio->txq_status_wq.wq) {
  1704. dev_err(&oct->pci_dev->dev, "unable to create cavium txq status wq\n");
  1705. return;
  1706. }
  1707. INIT_DELAYED_WORK(&lio->txq_status_wq.wk.work,
  1708. octnet_poll_check_txq_status);
  1709. lio->txq_status_wq.wk.ctxptr = lio;
  1710. queue_delayed_work(lio->txq_status_wq.wq,
  1711. &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
  1712. }
  1713. /**
  1714. * \brief Net device open for LiquidIO
  1715. * @param netdev network device
  1716. */
  1717. static int liquidio_open(struct net_device *netdev)
  1718. {
  1719. struct lio *lio = GET_LIO(netdev);
  1720. struct octeon_device *oct = lio->oct_dev;
  1721. struct napi_struct *napi, *n;
  1722. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  1723. napi_enable(napi);
  1724. oct_ptp_open(netdev);
  1725. ifstate_set(lio, LIO_IFSTATE_RUNNING);
  1726. setup_tx_poll_fn(netdev);
  1727. start_txq(netdev);
  1728. netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
  1729. try_module_get(THIS_MODULE);
  1730. /* tell Octeon to start forwarding packets to host */
  1731. send_rx_ctrl_cmd(lio, 1);
  1732. /* Ready for link status updates */
  1733. lio->intf_open = 1;
  1734. dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
  1735. netdev->name);
  1736. return 0;
  1737. }
  1738. /**
  1739. * \brief Net device stop for LiquidIO
  1740. * @param netdev network device
  1741. */
  1742. static int liquidio_stop(struct net_device *netdev)
  1743. {
  1744. struct napi_struct *napi, *n;
  1745. struct lio *lio = GET_LIO(netdev);
  1746. struct octeon_device *oct = lio->oct_dev;
  1747. netif_info(lio, ifdown, lio->netdev, "Stopping interface!\n");
  1748. /* Inform that netif carrier is down */
  1749. lio->intf_open = 0;
  1750. lio->linfo.link.s.status = 0;
  1751. netif_carrier_off(netdev);
  1752. /* tell Octeon to stop forwarding packets to host */
  1753. send_rx_ctrl_cmd(lio, 0);
  1754. cancel_delayed_work_sync(&lio->txq_status_wq.wk.work);
  1755. flush_workqueue(lio->txq_status_wq.wq);
  1756. destroy_workqueue(lio->txq_status_wq.wq);
  1757. if (lio->ptp_clock) {
  1758. ptp_clock_unregister(lio->ptp_clock);
  1759. lio->ptp_clock = NULL;
  1760. }
  1761. ifstate_reset(lio, LIO_IFSTATE_RUNNING);
  1762. /* This is a hack that allows DHCP to continue working. */
  1763. set_bit(__LINK_STATE_START, &lio->netdev->state);
  1764. list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
  1765. napi_disable(napi);
  1766. txqs_stop(netdev);
  1767. dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
  1768. module_put(THIS_MODULE);
  1769. return 0;
  1770. }
  1771. void liquidio_link_ctrl_cmd_completion(void *nctrl_ptr)
  1772. {
  1773. struct octnic_ctrl_pkt *nctrl = (struct octnic_ctrl_pkt *)nctrl_ptr;
  1774. struct net_device *netdev = (struct net_device *)nctrl->netpndev;
  1775. struct lio *lio = GET_LIO(netdev);
  1776. struct octeon_device *oct = lio->oct_dev;
  1777. switch (nctrl->ncmd.s.cmd) {
  1778. case OCTNET_CMD_CHANGE_DEVFLAGS:
  1779. case OCTNET_CMD_SET_MULTI_LIST:
  1780. break;
  1781. case OCTNET_CMD_CHANGE_MACADDR:
  1782. /* If command is successful, change the MACADDR. */
  1783. netif_info(lio, probe, lio->netdev, " MACAddr changed to 0x%llx\n",
  1784. CVM_CAST64(nctrl->udd[0]));
  1785. dev_info(&oct->pci_dev->dev, "%s MACAddr changed to 0x%llx\n",
  1786. netdev->name, CVM_CAST64(nctrl->udd[0]));
  1787. memcpy(netdev->dev_addr, ((u8 *)&nctrl->udd[0]) + 2, ETH_ALEN);
  1788. break;
  1789. case OCTNET_CMD_CHANGE_MTU:
  1790. /* If command is successful, change the MTU. */
  1791. netif_info(lio, probe, lio->netdev, " MTU Changed from %d to %d\n",
  1792. netdev->mtu, nctrl->ncmd.s.param2);
  1793. dev_info(&oct->pci_dev->dev, "%s MTU Changed from %d to %d\n",
  1794. netdev->name, netdev->mtu,
  1795. nctrl->ncmd.s.param2);
  1796. netdev->mtu = nctrl->ncmd.s.param2;
  1797. break;
  1798. case OCTNET_CMD_GPIO_ACCESS:
  1799. netif_info(lio, probe, lio->netdev, "LED Flashing visual identification\n");
  1800. break;
  1801. case OCTNET_CMD_LRO_ENABLE:
  1802. dev_info(&oct->pci_dev->dev, "%s LRO Enabled\n", netdev->name);
  1803. break;
  1804. case OCTNET_CMD_LRO_DISABLE:
  1805. dev_info(&oct->pci_dev->dev, "%s LRO Disabled\n",
  1806. netdev->name);
  1807. break;
  1808. case OCTNET_CMD_VERBOSE_ENABLE:
  1809. dev_info(&oct->pci_dev->dev, "%s LRO Enabled\n", netdev->name);
  1810. break;
  1811. case OCTNET_CMD_VERBOSE_DISABLE:
  1812. dev_info(&oct->pci_dev->dev, "%s LRO Disabled\n",
  1813. netdev->name);
  1814. break;
  1815. case OCTNET_CMD_SET_SETTINGS:
  1816. dev_info(&oct->pci_dev->dev, "%s settings changed\n",
  1817. netdev->name);
  1818. break;
  1819. default:
  1820. dev_err(&oct->pci_dev->dev, "%s Unknown cmd %d\n", __func__,
  1821. nctrl->ncmd.s.cmd);
  1822. }
  1823. }
  1824. /**
  1825. * \brief Converts a mask based on net device flags
  1826. * @param netdev network device
  1827. *
  1828. * This routine generates a octnet_ifflags mask from the net device flags
  1829. * received from the OS.
  1830. */
  1831. static inline enum octnet_ifflags get_new_flags(struct net_device *netdev)
  1832. {
  1833. enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST;
  1834. if (netdev->flags & IFF_PROMISC)
  1835. f |= OCTNET_IFFLAG_PROMISC;
  1836. if (netdev->flags & IFF_ALLMULTI)
  1837. f |= OCTNET_IFFLAG_ALLMULTI;
  1838. if (netdev->flags & IFF_MULTICAST) {
  1839. f |= OCTNET_IFFLAG_MULTICAST;
  1840. /* Accept all multicast addresses if there are more than we
  1841. * can handle
  1842. */
  1843. if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR)
  1844. f |= OCTNET_IFFLAG_ALLMULTI;
  1845. }
  1846. if (netdev->flags & IFF_BROADCAST)
  1847. f |= OCTNET_IFFLAG_BROADCAST;
  1848. return f;
  1849. }
  1850. /**
  1851. * \brief Net device set_multicast_list
  1852. * @param netdev network device
  1853. */
  1854. static void liquidio_set_mcast_list(struct net_device *netdev)
  1855. {
  1856. struct lio *lio = GET_LIO(netdev);
  1857. struct octeon_device *oct = lio->oct_dev;
  1858. struct octnic_ctrl_pkt nctrl;
  1859. struct octnic_ctrl_params nparams;
  1860. struct netdev_hw_addr *ha;
  1861. u64 *mc;
  1862. int ret, i;
  1863. int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR);
  1864. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1865. /* Create a ctrl pkt command to be sent to core app. */
  1866. nctrl.ncmd.u64 = 0;
  1867. nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST;
  1868. nctrl.ncmd.s.param1 = lio->linfo.ifidx;
  1869. nctrl.ncmd.s.param2 = get_new_flags(netdev);
  1870. nctrl.ncmd.s.param3 = mc_count;
  1871. nctrl.ncmd.s.more = mc_count;
  1872. nctrl.netpndev = (u64)netdev;
  1873. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1874. /* copy all the addresses into the udd */
  1875. i = 0;
  1876. mc = &nctrl.udd[0];
  1877. netdev_for_each_mc_addr(ha, netdev) {
  1878. *mc = 0;
  1879. memcpy(((u8 *)mc) + 2, ha->addr, ETH_ALEN);
  1880. /* no need to swap bytes */
  1881. if (++mc > &nctrl.udd[mc_count])
  1882. break;
  1883. }
  1884. /* Apparently, any activity in this call from the kernel has to
  1885. * be atomic. So we won't wait for response.
  1886. */
  1887. nctrl.wait_time = 0;
  1888. nparams.resp_order = OCTEON_RESP_NORESPONSE;
  1889. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl, nparams);
  1890. if (ret < 0) {
  1891. dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n",
  1892. ret);
  1893. }
  1894. }
  1895. /**
  1896. * \brief Net device set_mac_address
  1897. * @param netdev network device
  1898. */
  1899. static int liquidio_set_mac(struct net_device *netdev, void *p)
  1900. {
  1901. int ret = 0;
  1902. struct lio *lio = GET_LIO(netdev);
  1903. struct octeon_device *oct = lio->oct_dev;
  1904. struct sockaddr *addr = (struct sockaddr *)p;
  1905. struct octnic_ctrl_pkt nctrl;
  1906. struct octnic_ctrl_params nparams;
  1907. if ((!is_valid_ether_addr(addr->sa_data)) ||
  1908. (ifstate_check(lio, LIO_IFSTATE_RUNNING)))
  1909. return -EADDRNOTAVAIL;
  1910. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1911. nctrl.ncmd.u64 = 0;
  1912. nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
  1913. nctrl.ncmd.s.param1 = lio->linfo.ifidx;
  1914. nctrl.ncmd.s.param2 = 0;
  1915. nctrl.ncmd.s.more = 1;
  1916. nctrl.netpndev = (u64)netdev;
  1917. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  1918. nctrl.wait_time = 100;
  1919. nctrl.udd[0] = 0;
  1920. /* The MAC Address is presented in network byte order. */
  1921. memcpy((u8 *)&nctrl.udd[0] + 2, addr->sa_data, ETH_ALEN);
  1922. nparams.resp_order = OCTEON_RESP_ORDERED;
  1923. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl, nparams);
  1924. if (ret < 0) {
  1925. dev_err(&oct->pci_dev->dev, "MAC Address change failed\n");
  1926. return -ENOMEM;
  1927. }
  1928. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  1929. memcpy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data, ETH_ALEN);
  1930. return 0;
  1931. }
  1932. /**
  1933. * \brief Net device get_stats
  1934. * @param netdev network device
  1935. */
  1936. static struct net_device_stats *liquidio_get_stats(struct net_device *netdev)
  1937. {
  1938. struct lio *lio = GET_LIO(netdev);
  1939. struct net_device_stats *stats = &netdev->stats;
  1940. struct octeon_device *oct;
  1941. u64 pkts = 0, drop = 0, bytes = 0;
  1942. struct oct_droq_stats *oq_stats;
  1943. struct oct_iq_stats *iq_stats;
  1944. int i, iq_no, oq_no;
  1945. oct = lio->oct_dev;
  1946. for (i = 0; i < lio->linfo.num_txpciq; i++) {
  1947. iq_no = lio->linfo.txpciq[i];
  1948. iq_stats = &oct->instr_queue[iq_no]->stats;
  1949. pkts += iq_stats->tx_done;
  1950. drop += iq_stats->tx_dropped;
  1951. bytes += iq_stats->tx_tot_bytes;
  1952. }
  1953. stats->tx_packets = pkts;
  1954. stats->tx_bytes = bytes;
  1955. stats->tx_dropped = drop;
  1956. pkts = 0;
  1957. drop = 0;
  1958. bytes = 0;
  1959. for (i = 0; i < lio->linfo.num_rxpciq; i++) {
  1960. oq_no = lio->linfo.rxpciq[i];
  1961. oq_stats = &oct->droq[oq_no]->stats;
  1962. pkts += oq_stats->rx_pkts_received;
  1963. drop += (oq_stats->rx_dropped +
  1964. oq_stats->dropped_nodispatch +
  1965. oq_stats->dropped_toomany +
  1966. oq_stats->dropped_nomem);
  1967. bytes += oq_stats->rx_bytes_received;
  1968. }
  1969. stats->rx_bytes = bytes;
  1970. stats->rx_packets = pkts;
  1971. stats->rx_dropped = drop;
  1972. return stats;
  1973. }
  1974. /**
  1975. * \brief Net device change_mtu
  1976. * @param netdev network device
  1977. */
  1978. static int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
  1979. {
  1980. struct lio *lio = GET_LIO(netdev);
  1981. struct octeon_device *oct = lio->oct_dev;
  1982. struct octnic_ctrl_pkt nctrl;
  1983. struct octnic_ctrl_params nparams;
  1984. int max_frm_size = new_mtu + OCTNET_FRM_HEADER_SIZE;
  1985. int ret = 0;
  1986. /* Limit the MTU to make sure the ethernet packets are between 64 bytes
  1987. * and 65535 bytes
  1988. */
  1989. if ((max_frm_size < OCTNET_MIN_FRM_SIZE) ||
  1990. (max_frm_size > OCTNET_MAX_FRM_SIZE)) {
  1991. dev_err(&oct->pci_dev->dev, "Invalid MTU: %d\n", new_mtu);
  1992. dev_err(&oct->pci_dev->dev, "Valid range %d and %d\n",
  1993. (OCTNET_MIN_FRM_SIZE - OCTNET_FRM_HEADER_SIZE),
  1994. (OCTNET_MAX_FRM_SIZE - OCTNET_FRM_HEADER_SIZE));
  1995. return -EINVAL;
  1996. }
  1997. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  1998. nctrl.ncmd.u64 = 0;
  1999. nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MTU;
  2000. nctrl.ncmd.s.param1 = lio->linfo.ifidx;
  2001. nctrl.ncmd.s.param2 = new_mtu;
  2002. nctrl.wait_time = 100;
  2003. nctrl.netpndev = (u64)netdev;
  2004. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  2005. nparams.resp_order = OCTEON_RESP_ORDERED;
  2006. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl, nparams);
  2007. if (ret < 0) {
  2008. dev_err(&oct->pci_dev->dev, "Failed to set MTU\n");
  2009. return -1;
  2010. }
  2011. lio->mtu = new_mtu;
  2012. return 0;
  2013. }
  2014. /**
  2015. * \brief Handler for SIOCSHWTSTAMP ioctl
  2016. * @param netdev network device
  2017. * @param ifr interface request
  2018. * @param cmd command
  2019. */
  2020. static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2021. {
  2022. struct hwtstamp_config conf;
  2023. struct lio *lio = GET_LIO(netdev);
  2024. if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf)))
  2025. return -EFAULT;
  2026. if (conf.flags)
  2027. return -EINVAL;
  2028. switch (conf.tx_type) {
  2029. case HWTSTAMP_TX_ON:
  2030. case HWTSTAMP_TX_OFF:
  2031. break;
  2032. default:
  2033. return -ERANGE;
  2034. }
  2035. switch (conf.rx_filter) {
  2036. case HWTSTAMP_FILTER_NONE:
  2037. break;
  2038. case HWTSTAMP_FILTER_ALL:
  2039. case HWTSTAMP_FILTER_SOME:
  2040. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2041. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2042. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2043. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2044. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2045. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2046. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  2047. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  2048. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  2049. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2050. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  2051. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  2052. conf.rx_filter = HWTSTAMP_FILTER_ALL;
  2053. break;
  2054. default:
  2055. return -ERANGE;
  2056. }
  2057. if (conf.rx_filter == HWTSTAMP_FILTER_ALL)
  2058. ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
  2059. else
  2060. ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
  2061. return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0;
  2062. }
  2063. /**
  2064. * \brief ioctl handler
  2065. * @param netdev network device
  2066. * @param ifr interface request
  2067. * @param cmd command
  2068. */
  2069. static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2070. {
  2071. switch (cmd) {
  2072. case SIOCSHWTSTAMP:
  2073. return hwtstamp_ioctl(netdev, ifr, cmd);
  2074. default:
  2075. return -EOPNOTSUPP;
  2076. }
  2077. }
  2078. /**
  2079. * \brief handle a Tx timestamp response
  2080. * @param status response status
  2081. * @param buf pointer to skb
  2082. */
  2083. static void handle_timestamp(struct octeon_device *oct,
  2084. u32 status,
  2085. void *buf)
  2086. {
  2087. struct octnet_buf_free_info *finfo;
  2088. struct octeon_soft_command *sc;
  2089. struct oct_timestamp_resp *resp;
  2090. struct lio *lio;
  2091. struct sk_buff *skb = (struct sk_buff *)buf;
  2092. finfo = (struct octnet_buf_free_info *)skb->cb;
  2093. lio = finfo->lio;
  2094. sc = finfo->sc;
  2095. oct = lio->oct_dev;
  2096. resp = (struct oct_timestamp_resp *)sc->virtrptr;
  2097. if (status != OCTEON_REQUEST_DONE) {
  2098. dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n",
  2099. CVM_CAST64(status));
  2100. resp->timestamp = 0;
  2101. }
  2102. octeon_swap_8B_data(&resp->timestamp, 1);
  2103. if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) != 0)) {
  2104. struct skb_shared_hwtstamps ts;
  2105. u64 ns = resp->timestamp;
  2106. netif_info(lio, tx_done, lio->netdev,
  2107. "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n",
  2108. skb, (unsigned long long)ns);
  2109. ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust);
  2110. skb_tstamp_tx(skb, &ts);
  2111. }
  2112. octeon_free_soft_command(oct, sc);
  2113. recv_buffer_free(skb);
  2114. }
  2115. /* \brief Send a data packet that will be timestamped
  2116. * @param oct octeon device
  2117. * @param ndata pointer to network data
  2118. * @param finfo pointer to private network data
  2119. */
  2120. static inline int send_nic_timestamp_pkt(struct octeon_device *oct,
  2121. struct octnic_data_pkt *ndata,
  2122. struct octnet_buf_free_info *finfo,
  2123. int xmit_more)
  2124. {
  2125. int retval;
  2126. struct octeon_soft_command *sc;
  2127. struct octeon_instr_ih *ih;
  2128. struct octeon_instr_rdp *rdp;
  2129. struct lio *lio;
  2130. int ring_doorbell;
  2131. lio = finfo->lio;
  2132. sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd,
  2133. sizeof(struct oct_timestamp_resp));
  2134. finfo->sc = sc;
  2135. if (!sc) {
  2136. dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n");
  2137. return IQ_SEND_FAILED;
  2138. }
  2139. if (ndata->reqtype == REQTYPE_NORESP_NET)
  2140. ndata->reqtype = REQTYPE_RESP_NET;
  2141. else if (ndata->reqtype == REQTYPE_NORESP_NET_SG)
  2142. ndata->reqtype = REQTYPE_RESP_NET_SG;
  2143. sc->callback = handle_timestamp;
  2144. sc->callback_arg = finfo->skb;
  2145. sc->iq_no = ndata->q_no;
  2146. ih = (struct octeon_instr_ih *)&sc->cmd.ih;
  2147. rdp = (struct octeon_instr_rdp *)&sc->cmd.rdp;
  2148. ring_doorbell = !xmit_more;
  2149. retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd,
  2150. sc, ih->dlengsz, ndata->reqtype);
  2151. if (retval) {
  2152. dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n",
  2153. retval);
  2154. octeon_free_soft_command(oct, sc);
  2155. } else {
  2156. netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n");
  2157. }
  2158. return retval;
  2159. }
  2160. static inline int is_ipv4(struct sk_buff *skb)
  2161. {
  2162. return (skb->protocol == htons(ETH_P_IP)) &&
  2163. (ip_hdr(skb)->version == 4);
  2164. }
  2165. static inline int is_vlan(struct sk_buff *skb)
  2166. {
  2167. return skb->protocol == htons(ETH_P_8021Q);
  2168. }
  2169. static inline int is_ip_fragmented(struct sk_buff *skb)
  2170. {
  2171. /* The Don't fragment and Reserved flag fields are ignored.
  2172. * IP is fragmented if
  2173. * - the More fragments bit is set (indicating this IP is a fragment
  2174. * with more to follow; the current offset could be 0 ).
  2175. * - ths offset field is non-zero.
  2176. */
  2177. return (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) ? 1 : 0;
  2178. }
  2179. static inline int is_ipv6(struct sk_buff *skb)
  2180. {
  2181. return (skb->protocol == htons(ETH_P_IPV6)) &&
  2182. (ipv6_hdr(skb)->version == 6);
  2183. }
  2184. static inline int is_with_extn_hdr(struct sk_buff *skb)
  2185. {
  2186. return (ipv6_hdr(skb)->nexthdr != IPPROTO_TCP) &&
  2187. (ipv6_hdr(skb)->nexthdr != IPPROTO_UDP);
  2188. }
  2189. static inline int is_tcpudp(struct sk_buff *skb)
  2190. {
  2191. return (ip_hdr(skb)->protocol == IPPROTO_TCP) ||
  2192. (ip_hdr(skb)->protocol == IPPROTO_UDP);
  2193. }
  2194. static inline u32 get_ipv4_5tuple_tag(struct sk_buff *skb)
  2195. {
  2196. u32 tag;
  2197. struct iphdr *iphdr = ip_hdr(skb);
  2198. tag = crc32(0, &iphdr->protocol, 1);
  2199. tag = crc32(tag, (u8 *)&iphdr->saddr, 8);
  2200. tag = crc32(tag, skb_transport_header(skb), 4);
  2201. return tag;
  2202. }
  2203. static inline u32 get_ipv6_5tuple_tag(struct sk_buff *skb)
  2204. {
  2205. u32 tag;
  2206. struct ipv6hdr *ipv6hdr = ipv6_hdr(skb);
  2207. tag = crc32(0, &ipv6hdr->nexthdr, 1);
  2208. tag = crc32(tag, (u8 *)&ipv6hdr->saddr, 32);
  2209. tag = crc32(tag, skb_transport_header(skb), 4);
  2210. return tag;
  2211. }
  2212. /** \brief Transmit networks packets to the Octeon interface
  2213. * @param skbuff skbuff struct to be passed to network layer.
  2214. * @param netdev pointer to network device
  2215. * @returns whether the packet was transmitted to the device okay or not
  2216. * (NETDEV_TX_OK or NETDEV_TX_BUSY)
  2217. */
  2218. static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
  2219. {
  2220. struct lio *lio;
  2221. struct octnet_buf_free_info *finfo;
  2222. union octnic_cmd_setup cmdsetup;
  2223. struct octnic_data_pkt ndata;
  2224. struct octeon_device *oct;
  2225. struct oct_iq_stats *stats;
  2226. int cpu = 0, status = 0;
  2227. int q_idx = 0, iq_no = 0;
  2228. int xmit_more;
  2229. u32 tag = 0;
  2230. lio = GET_LIO(netdev);
  2231. oct = lio->oct_dev;
  2232. if (netif_is_multiqueue(netdev)) {
  2233. cpu = skb->queue_mapping;
  2234. q_idx = (cpu & (lio->linfo.num_txpciq - 1));
  2235. iq_no = lio->linfo.txpciq[q_idx];
  2236. } else {
  2237. iq_no = lio->txq;
  2238. }
  2239. stats = &oct->instr_queue[iq_no]->stats;
  2240. /* Check for all conditions in which the current packet cannot be
  2241. * transmitted.
  2242. */
  2243. if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
  2244. (!lio->linfo.link.s.status) ||
  2245. (skb->len <= 0)) {
  2246. netif_info(lio, tx_err, lio->netdev,
  2247. "Transmit failed link_status : %d\n",
  2248. lio->linfo.link.s.status);
  2249. goto lio_xmit_failed;
  2250. }
  2251. /* Use space in skb->cb to store info used to unmap and
  2252. * free the buffers.
  2253. */
  2254. finfo = (struct octnet_buf_free_info *)skb->cb;
  2255. finfo->lio = lio;
  2256. finfo->skb = skb;
  2257. finfo->sc = NULL;
  2258. /* Prepare the attributes for the data to be passed to OSI. */
  2259. memset(&ndata, 0, sizeof(struct octnic_data_pkt));
  2260. ndata.buf = (void *)finfo;
  2261. ndata.q_no = iq_no;
  2262. if (netif_is_multiqueue(netdev)) {
  2263. if (octnet_iq_is_full(oct, ndata.q_no)) {
  2264. /* defer sending if queue is full */
  2265. netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
  2266. ndata.q_no);
  2267. stats->tx_iq_busy++;
  2268. return NETDEV_TX_BUSY;
  2269. }
  2270. } else {
  2271. if (octnet_iq_is_full(oct, lio->txq)) {
  2272. /* defer sending if queue is full */
  2273. stats->tx_iq_busy++;
  2274. netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
  2275. ndata.q_no);
  2276. return NETDEV_TX_BUSY;
  2277. }
  2278. }
  2279. /* pr_info(" XMIT - valid Qs: %d, 1st Q no: %d, cpu: %d, q_no:%d\n",
  2280. * lio->linfo.num_txpciq, lio->txq, cpu, ndata.q_no );
  2281. */
  2282. ndata.datasize = skb->len;
  2283. cmdsetup.u64 = 0;
  2284. cmdsetup.s.ifidx = lio->linfo.ifidx;
  2285. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2286. if (is_ipv4(skb) && !is_ip_fragmented(skb) && is_tcpudp(skb)) {
  2287. tag = get_ipv4_5tuple_tag(skb);
  2288. cmdsetup.s.cksum_offset = sizeof(struct ethhdr) + 1;
  2289. if (ip_hdr(skb)->ihl > 5)
  2290. cmdsetup.s.ipv4opts_ipv6exthdr =
  2291. OCT_PKT_PARAM_IPV4OPTS;
  2292. } else if (is_ipv6(skb)) {
  2293. tag = get_ipv6_5tuple_tag(skb);
  2294. cmdsetup.s.cksum_offset = sizeof(struct ethhdr) + 1;
  2295. if (is_with_extn_hdr(skb))
  2296. cmdsetup.s.ipv4opts_ipv6exthdr =
  2297. OCT_PKT_PARAM_IPV6EXTHDR;
  2298. } else if (is_vlan(skb)) {
  2299. if (vlan_eth_hdr(skb)->h_vlan_encapsulated_proto
  2300. == htons(ETH_P_IP) &&
  2301. !is_ip_fragmented(skb) && is_tcpudp(skb)) {
  2302. tag = get_ipv4_5tuple_tag(skb);
  2303. cmdsetup.s.cksum_offset =
  2304. sizeof(struct vlan_ethhdr) + 1;
  2305. if (ip_hdr(skb)->ihl > 5)
  2306. cmdsetup.s.ipv4opts_ipv6exthdr =
  2307. OCT_PKT_PARAM_IPV4OPTS;
  2308. } else if (vlan_eth_hdr(skb)->h_vlan_encapsulated_proto
  2309. == htons(ETH_P_IPV6)) {
  2310. tag = get_ipv6_5tuple_tag(skb);
  2311. cmdsetup.s.cksum_offset =
  2312. sizeof(struct vlan_ethhdr) + 1;
  2313. if (is_with_extn_hdr(skb))
  2314. cmdsetup.s.ipv4opts_ipv6exthdr =
  2315. OCT_PKT_PARAM_IPV6EXTHDR;
  2316. }
  2317. }
  2318. }
  2319. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  2320. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  2321. cmdsetup.s.timestamp = 1;
  2322. }
  2323. if (skb_shinfo(skb)->nr_frags == 0) {
  2324. cmdsetup.s.u.datasize = skb->len;
  2325. octnet_prepare_pci_cmd(&ndata.cmd, &cmdsetup, tag);
  2326. /* Offload checksum calculation for TCP/UDP packets */
  2327. ndata.cmd.dptr = dma_map_single(&oct->pci_dev->dev,
  2328. skb->data,
  2329. skb->len,
  2330. DMA_TO_DEVICE);
  2331. if (dma_mapping_error(&oct->pci_dev->dev, ndata.cmd.dptr)) {
  2332. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n",
  2333. __func__);
  2334. return NETDEV_TX_BUSY;
  2335. }
  2336. finfo->dptr = ndata.cmd.dptr;
  2337. ndata.reqtype = REQTYPE_NORESP_NET;
  2338. } else {
  2339. int i, frags;
  2340. struct skb_frag_struct *frag;
  2341. struct octnic_gather *g;
  2342. spin_lock(&lio->lock);
  2343. g = (struct octnic_gather *)list_delete_head(&lio->glist);
  2344. spin_unlock(&lio->lock);
  2345. if (!g) {
  2346. netif_info(lio, tx_err, lio->netdev,
  2347. "Transmit scatter gather: glist null!\n");
  2348. goto lio_xmit_dma_failed;
  2349. }
  2350. cmdsetup.s.gather = 1;
  2351. cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1);
  2352. octnet_prepare_pci_cmd(&ndata.cmd, &cmdsetup, tag);
  2353. memset(g->sg, 0, g->sg_size);
  2354. g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev,
  2355. skb->data,
  2356. (skb->len - skb->data_len),
  2357. DMA_TO_DEVICE);
  2358. if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) {
  2359. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n",
  2360. __func__);
  2361. return NETDEV_TX_BUSY;
  2362. }
  2363. add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0);
  2364. frags = skb_shinfo(skb)->nr_frags;
  2365. i = 1;
  2366. while (frags--) {
  2367. frag = &skb_shinfo(skb)->frags[i - 1];
  2368. g->sg[(i >> 2)].ptr[(i & 3)] =
  2369. dma_map_page(&oct->pci_dev->dev,
  2370. frag->page.p,
  2371. frag->page_offset,
  2372. frag->size,
  2373. DMA_TO_DEVICE);
  2374. add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3));
  2375. i++;
  2376. }
  2377. ndata.cmd.dptr = dma_map_single(&oct->pci_dev->dev,
  2378. g->sg, g->sg_size,
  2379. DMA_TO_DEVICE);
  2380. if (dma_mapping_error(&oct->pci_dev->dev, ndata.cmd.dptr)) {
  2381. dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n",
  2382. __func__);
  2383. dma_unmap_single(&oct->pci_dev->dev, g->sg[0].ptr[0],
  2384. skb->len - skb->data_len,
  2385. DMA_TO_DEVICE);
  2386. return NETDEV_TX_BUSY;
  2387. }
  2388. finfo->dptr = ndata.cmd.dptr;
  2389. finfo->g = g;
  2390. ndata.reqtype = REQTYPE_NORESP_NET_SG;
  2391. }
  2392. if (skb_shinfo(skb)->gso_size) {
  2393. struct octeon_instr_irh *irh =
  2394. (struct octeon_instr_irh *)&ndata.cmd.irh;
  2395. union tx_info *tx_info = (union tx_info *)&ndata.cmd.ossp[0];
  2396. irh->len = 1; /* to indicate that ossp[0] contains tx_info */
  2397. tx_info->s.gso_size = skb_shinfo(skb)->gso_size;
  2398. tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs;
  2399. }
  2400. xmit_more = skb->xmit_more;
  2401. if (unlikely(cmdsetup.s.timestamp))
  2402. status = send_nic_timestamp_pkt(oct, &ndata, finfo, xmit_more);
  2403. else
  2404. status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more);
  2405. if (status == IQ_SEND_FAILED)
  2406. goto lio_xmit_dma_failed;
  2407. netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
  2408. if (status == IQ_SEND_STOP)
  2409. stop_q(lio->netdev, q_idx);
  2410. netif_trans_update(netdev);
  2411. stats->tx_done++;
  2412. stats->tx_tot_bytes += skb->len;
  2413. return NETDEV_TX_OK;
  2414. lio_xmit_dma_failed:
  2415. dma_unmap_single(&oct->pci_dev->dev, ndata.cmd.dptr,
  2416. ndata.datasize, DMA_TO_DEVICE);
  2417. lio_xmit_failed:
  2418. stats->tx_dropped++;
  2419. netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
  2420. iq_no, stats->tx_dropped);
  2421. recv_buffer_free(skb);
  2422. return NETDEV_TX_OK;
  2423. }
  2424. /** \brief Network device Tx timeout
  2425. * @param netdev pointer to network device
  2426. */
  2427. static void liquidio_tx_timeout(struct net_device *netdev)
  2428. {
  2429. struct lio *lio;
  2430. lio = GET_LIO(netdev);
  2431. netif_info(lio, tx_err, lio->netdev,
  2432. "Transmit timeout tx_dropped:%ld, waking up queues now!!\n",
  2433. netdev->stats.tx_dropped);
  2434. netif_trans_update(netdev);
  2435. txqs_wake(netdev);
  2436. }
  2437. int liquidio_set_feature(struct net_device *netdev, int cmd)
  2438. {
  2439. struct lio *lio = GET_LIO(netdev);
  2440. struct octeon_device *oct = lio->oct_dev;
  2441. struct octnic_ctrl_pkt nctrl;
  2442. struct octnic_ctrl_params nparams;
  2443. int ret = 0;
  2444. memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
  2445. nctrl.ncmd.u64 = 0;
  2446. nctrl.ncmd.s.cmd = cmd;
  2447. nctrl.ncmd.s.param1 = lio->linfo.ifidx;
  2448. nctrl.ncmd.s.param2 = OCTNIC_LROIPV4 | OCTNIC_LROIPV6;
  2449. nctrl.wait_time = 100;
  2450. nctrl.netpndev = (u64)netdev;
  2451. nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
  2452. nparams.resp_order = OCTEON_RESP_NORESPONSE;
  2453. ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl, nparams);
  2454. if (ret < 0) {
  2455. dev_err(&oct->pci_dev->dev, "Feature change failed in core (ret: 0x%x)\n",
  2456. ret);
  2457. }
  2458. return ret;
  2459. }
  2460. /** \brief Net device fix features
  2461. * @param netdev pointer to network device
  2462. * @param request features requested
  2463. * @returns updated features list
  2464. */
  2465. static netdev_features_t liquidio_fix_features(struct net_device *netdev,
  2466. netdev_features_t request)
  2467. {
  2468. struct lio *lio = netdev_priv(netdev);
  2469. if ((request & NETIF_F_RXCSUM) &&
  2470. !(lio->dev_capability & NETIF_F_RXCSUM))
  2471. request &= ~NETIF_F_RXCSUM;
  2472. if ((request & NETIF_F_HW_CSUM) &&
  2473. !(lio->dev_capability & NETIF_F_HW_CSUM))
  2474. request &= ~NETIF_F_HW_CSUM;
  2475. if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO))
  2476. request &= ~NETIF_F_TSO;
  2477. if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6))
  2478. request &= ~NETIF_F_TSO6;
  2479. if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO))
  2480. request &= ~NETIF_F_LRO;
  2481. /*Disable LRO if RXCSUM is off */
  2482. if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) &&
  2483. (lio->dev_capability & NETIF_F_LRO))
  2484. request &= ~NETIF_F_LRO;
  2485. return request;
  2486. }
  2487. /** \brief Net device set features
  2488. * @param netdev pointer to network device
  2489. * @param features features to enable/disable
  2490. */
  2491. static int liquidio_set_features(struct net_device *netdev,
  2492. netdev_features_t features)
  2493. {
  2494. struct lio *lio = netdev_priv(netdev);
  2495. if (!((netdev->features ^ features) & NETIF_F_LRO))
  2496. return 0;
  2497. if ((features & NETIF_F_LRO) && (lio->dev_capability & NETIF_F_LRO))
  2498. liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE);
  2499. else if (!(features & NETIF_F_LRO) &&
  2500. (lio->dev_capability & NETIF_F_LRO))
  2501. liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE);
  2502. return 0;
  2503. }
  2504. static struct net_device_ops lionetdevops = {
  2505. .ndo_open = liquidio_open,
  2506. .ndo_stop = liquidio_stop,
  2507. .ndo_start_xmit = liquidio_xmit,
  2508. .ndo_get_stats = liquidio_get_stats,
  2509. .ndo_set_mac_address = liquidio_set_mac,
  2510. .ndo_set_rx_mode = liquidio_set_mcast_list,
  2511. .ndo_tx_timeout = liquidio_tx_timeout,
  2512. .ndo_change_mtu = liquidio_change_mtu,
  2513. .ndo_do_ioctl = liquidio_ioctl,
  2514. .ndo_fix_features = liquidio_fix_features,
  2515. .ndo_set_features = liquidio_set_features,
  2516. };
  2517. /** \brief Entry point for the liquidio module
  2518. */
  2519. static int __init liquidio_init(void)
  2520. {
  2521. int i;
  2522. struct handshake *hs;
  2523. init_completion(&first_stage);
  2524. octeon_init_device_list(conf_type);
  2525. if (liquidio_init_pci())
  2526. return -EINVAL;
  2527. wait_for_completion_timeout(&first_stage, msecs_to_jiffies(1000));
  2528. for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
  2529. hs = &handshake[i];
  2530. if (hs->pci_dev) {
  2531. wait_for_completion(&hs->init);
  2532. if (!hs->init_ok) {
  2533. /* init handshake failed */
  2534. dev_err(&hs->pci_dev->dev,
  2535. "Failed to init device\n");
  2536. liquidio_deinit_pci();
  2537. return -EIO;
  2538. }
  2539. }
  2540. }
  2541. for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
  2542. hs = &handshake[i];
  2543. if (hs->pci_dev) {
  2544. wait_for_completion_timeout(&hs->started,
  2545. msecs_to_jiffies(30000));
  2546. if (!hs->started_ok) {
  2547. /* starter handshake failed */
  2548. dev_err(&hs->pci_dev->dev,
  2549. "Firmware failed to start\n");
  2550. liquidio_deinit_pci();
  2551. return -EIO;
  2552. }
  2553. }
  2554. }
  2555. return 0;
  2556. }
  2557. static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf)
  2558. {
  2559. struct octeon_device *oct = (struct octeon_device *)buf;
  2560. struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
  2561. int ifidx = 0;
  2562. union oct_link_status *ls;
  2563. int i;
  2564. if ((recv_pkt->buffer_size[0] != sizeof(*ls)) ||
  2565. (recv_pkt->rh.r_nic_info.ifidx > oct->ifcount)) {
  2566. dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n",
  2567. recv_pkt->buffer_size[0],
  2568. recv_pkt->rh.r_nic_info.ifidx);
  2569. goto nic_info_err;
  2570. }
  2571. ifidx = recv_pkt->rh.r_nic_info.ifidx;
  2572. ls = (union oct_link_status *)get_rbd(recv_pkt->buffer_ptr[0]);
  2573. octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3);
  2574. update_link_status(oct->props[ifidx].netdev, ls);
  2575. nic_info_err:
  2576. for (i = 0; i < recv_pkt->buffer_count; i++)
  2577. recv_buffer_free(recv_pkt->buffer_ptr[i]);
  2578. octeon_free_recv_info(recv_info);
  2579. return 0;
  2580. }
  2581. /**
  2582. * \brief Setup network interfaces
  2583. * @param octeon_dev octeon device
  2584. *
  2585. * Called during init time for each device. It assumes the NIC
  2586. * is already up and running. The link information for each
  2587. * interface is passed in link_info.
  2588. */
  2589. static int setup_nic_devices(struct octeon_device *octeon_dev)
  2590. {
  2591. struct lio *lio = NULL;
  2592. struct net_device *netdev;
  2593. u8 mac[6], i, j;
  2594. struct octeon_soft_command *sc;
  2595. struct liquidio_if_cfg_context *ctx;
  2596. struct liquidio_if_cfg_resp *resp;
  2597. struct octdev_props *props;
  2598. int retval, num_iqueues, num_oqueues, q_no;
  2599. u64 q_mask;
  2600. int num_cpus = num_online_cpus();
  2601. union oct_nic_if_cfg if_cfg;
  2602. unsigned int base_queue;
  2603. unsigned int gmx_port_id;
  2604. u32 resp_size, ctx_size;
  2605. /* This is to handle link status changes */
  2606. octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
  2607. OPCODE_NIC_INFO,
  2608. lio_nic_info, octeon_dev);
  2609. /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions.
  2610. * They are handled directly.
  2611. */
  2612. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET,
  2613. free_netbuf);
  2614. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG,
  2615. free_netsgbuf);
  2616. octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG,
  2617. free_netsgbuf_with_resp);
  2618. for (i = 0; i < octeon_dev->ifcount; i++) {
  2619. resp_size = sizeof(struct liquidio_if_cfg_resp);
  2620. ctx_size = sizeof(struct liquidio_if_cfg_context);
  2621. sc = (struct octeon_soft_command *)
  2622. octeon_alloc_soft_command(octeon_dev, 0,
  2623. resp_size, ctx_size);
  2624. resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
  2625. ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
  2626. num_iqueues =
  2627. CFG_GET_NUM_TXQS_NIC_IF(octeon_get_conf(octeon_dev), i);
  2628. num_oqueues =
  2629. CFG_GET_NUM_RXQS_NIC_IF(octeon_get_conf(octeon_dev), i);
  2630. base_queue =
  2631. CFG_GET_BASE_QUE_NIC_IF(octeon_get_conf(octeon_dev), i);
  2632. gmx_port_id =
  2633. CFG_GET_GMXID_NIC_IF(octeon_get_conf(octeon_dev), i);
  2634. if (num_iqueues > num_cpus)
  2635. num_iqueues = num_cpus;
  2636. if (num_oqueues > num_cpus)
  2637. num_oqueues = num_cpus;
  2638. dev_dbg(&octeon_dev->pci_dev->dev,
  2639. "requesting config for interface %d, iqs %d, oqs %d\n",
  2640. i, num_iqueues, num_oqueues);
  2641. ACCESS_ONCE(ctx->cond) = 0;
  2642. ctx->octeon_id = lio_get_device_id(octeon_dev);
  2643. init_waitqueue_head(&ctx->wc);
  2644. if_cfg.u64 = 0;
  2645. if_cfg.s.num_iqueues = num_iqueues;
  2646. if_cfg.s.num_oqueues = num_oqueues;
  2647. if_cfg.s.base_queue = base_queue;
  2648. if_cfg.s.gmx_port_id = gmx_port_id;
  2649. octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC,
  2650. OPCODE_NIC_IF_CFG, i,
  2651. if_cfg.u64, 0);
  2652. sc->callback = if_cfg_callback;
  2653. sc->callback_arg = sc;
  2654. sc->wait_time = 1000;
  2655. retval = octeon_send_soft_command(octeon_dev, sc);
  2656. if (retval) {
  2657. dev_err(&octeon_dev->pci_dev->dev,
  2658. "iq/oq config failed status: %x\n",
  2659. retval);
  2660. /* Soft instr is freed by driver in case of failure. */
  2661. goto setup_nic_dev_fail;
  2662. }
  2663. /* Sleep on a wait queue till the cond flag indicates that the
  2664. * response arrived or timed-out.
  2665. */
  2666. sleep_cond(&ctx->wc, &ctx->cond);
  2667. retval = resp->status;
  2668. if (retval) {
  2669. dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n");
  2670. goto setup_nic_dev_fail;
  2671. }
  2672. octeon_swap_8B_data((u64 *)(&resp->cfg_info),
  2673. (sizeof(struct liquidio_if_cfg_info)) >> 3);
  2674. num_iqueues = hweight64(resp->cfg_info.iqmask);
  2675. num_oqueues = hweight64(resp->cfg_info.oqmask);
  2676. if (!(num_iqueues) || !(num_oqueues)) {
  2677. dev_err(&octeon_dev->pci_dev->dev,
  2678. "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n",
  2679. resp->cfg_info.iqmask,
  2680. resp->cfg_info.oqmask);
  2681. goto setup_nic_dev_fail;
  2682. }
  2683. dev_dbg(&octeon_dev->pci_dev->dev,
  2684. "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n",
  2685. i, resp->cfg_info.iqmask, resp->cfg_info.oqmask,
  2686. num_iqueues, num_oqueues);
  2687. netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues);
  2688. if (!netdev) {
  2689. dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n");
  2690. goto setup_nic_dev_fail;
  2691. }
  2692. props = &octeon_dev->props[i];
  2693. props->netdev = netdev;
  2694. if (num_iqueues > 1)
  2695. lionetdevops.ndo_select_queue = select_q;
  2696. /* Associate the routines that will handle different
  2697. * netdev tasks.
  2698. */
  2699. netdev->netdev_ops = &lionetdevops;
  2700. lio = GET_LIO(netdev);
  2701. memset(lio, 0, sizeof(struct lio));
  2702. lio->linfo.ifidx = resp->cfg_info.ifidx;
  2703. lio->ifidx = resp->cfg_info.ifidx;
  2704. lio->linfo.num_rxpciq = num_oqueues;
  2705. lio->linfo.num_txpciq = num_iqueues;
  2706. q_mask = resp->cfg_info.oqmask;
  2707. /* q_mask is 0-based and already verified mask is nonzero */
  2708. for (j = 0; j < num_oqueues; j++) {
  2709. q_no = __ffs64(q_mask);
  2710. q_mask &= (~(1UL << q_no));
  2711. lio->linfo.rxpciq[j] = q_no;
  2712. }
  2713. q_mask = resp->cfg_info.iqmask;
  2714. for (j = 0; j < num_iqueues; j++) {
  2715. q_no = __ffs64(q_mask);
  2716. q_mask &= (~(1UL << q_no));
  2717. lio->linfo.txpciq[j] = q_no;
  2718. }
  2719. lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
  2720. lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
  2721. lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
  2722. lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  2723. lio->dev_capability = NETIF_F_HIGHDMA
  2724. | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM
  2725. | NETIF_F_SG | NETIF_F_RXCSUM
  2726. | NETIF_F_TSO | NETIF_F_TSO6
  2727. | NETIF_F_LRO;
  2728. netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE);
  2729. netdev->features = lio->dev_capability;
  2730. netdev->vlan_features = lio->dev_capability;
  2731. netdev->hw_features = lio->dev_capability;
  2732. /* Point to the properties for octeon device to which this
  2733. * interface belongs.
  2734. */
  2735. lio->oct_dev = octeon_dev;
  2736. lio->octprops = props;
  2737. lio->netdev = netdev;
  2738. spin_lock_init(&lio->lock);
  2739. dev_dbg(&octeon_dev->pci_dev->dev,
  2740. "if%d gmx: %d hw_addr: 0x%llx\n", i,
  2741. lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
  2742. /* 64-bit swap required on LE machines */
  2743. octeon_swap_8B_data(&lio->linfo.hw_addr, 1);
  2744. for (j = 0; j < 6; j++)
  2745. mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j));
  2746. /* Copy MAC Address to OS network device structure */
  2747. ether_addr_copy(netdev->dev_addr, mac);
  2748. if (setup_io_queues(octeon_dev, netdev)) {
  2749. dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n");
  2750. goto setup_nic_dev_fail;
  2751. }
  2752. ifstate_set(lio, LIO_IFSTATE_DROQ_OPS);
  2753. /* By default all interfaces on a single Octeon uses the same
  2754. * tx and rx queues
  2755. */
  2756. lio->txq = lio->linfo.txpciq[0];
  2757. lio->rxq = lio->linfo.rxpciq[0];
  2758. lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq);
  2759. lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq);
  2760. if (setup_glist(lio)) {
  2761. dev_err(&octeon_dev->pci_dev->dev,
  2762. "Gather list allocation failed\n");
  2763. goto setup_nic_dev_fail;
  2764. }
  2765. /* Register ethtool support */
  2766. liquidio_set_ethtool_ops(netdev);
  2767. liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE);
  2768. if ((debug != -1) && (debug & NETIF_MSG_HW))
  2769. liquidio_set_feature(netdev, OCTNET_CMD_VERBOSE_ENABLE);
  2770. /* Register the network device with the OS */
  2771. if (register_netdev(netdev)) {
  2772. dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n");
  2773. goto setup_nic_dev_fail;
  2774. }
  2775. dev_dbg(&octeon_dev->pci_dev->dev,
  2776. "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n",
  2777. i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  2778. netif_carrier_off(netdev);
  2779. if (lio->linfo.link.s.status) {
  2780. netif_carrier_on(netdev);
  2781. start_txq(netdev);
  2782. } else {
  2783. netif_carrier_off(netdev);
  2784. }
  2785. ifstate_set(lio, LIO_IFSTATE_REGISTERED);
  2786. dev_dbg(&octeon_dev->pci_dev->dev,
  2787. "NIC ifidx:%d Setup successful\n", i);
  2788. octeon_free_soft_command(octeon_dev, sc);
  2789. }
  2790. return 0;
  2791. setup_nic_dev_fail:
  2792. octeon_free_soft_command(octeon_dev, sc);
  2793. while (i--) {
  2794. dev_err(&octeon_dev->pci_dev->dev,
  2795. "NIC ifidx:%d Setup failed\n", i);
  2796. liquidio_destroy_nic_device(octeon_dev, i);
  2797. }
  2798. return -ENODEV;
  2799. }
  2800. /**
  2801. * \brief initialize the NIC
  2802. * @param oct octeon device
  2803. *
  2804. * This initialization routine is called once the Octeon device application is
  2805. * up and running
  2806. */
  2807. static int liquidio_init_nic_module(struct octeon_device *oct)
  2808. {
  2809. struct oct_intrmod_cfg *intrmod_cfg;
  2810. int retval = 0;
  2811. int num_nic_ports = CFG_GET_NUM_NIC_PORTS(octeon_get_conf(oct));
  2812. dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n");
  2813. /* only default iq and oq were initialized
  2814. * initialize the rest as well
  2815. */
  2816. /* run port_config command for each port */
  2817. oct->ifcount = num_nic_ports;
  2818. memset(oct->props, 0,
  2819. sizeof(struct octdev_props) * num_nic_ports);
  2820. retval = setup_nic_devices(oct);
  2821. if (retval) {
  2822. dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n");
  2823. goto octnet_init_failure;
  2824. }
  2825. liquidio_ptp_init(oct);
  2826. /* Initialize interrupt moderation params */
  2827. intrmod_cfg = &((struct octeon_device *)oct)->intrmod;
  2828. intrmod_cfg->intrmod_enable = 1;
  2829. intrmod_cfg->intrmod_check_intrvl = LIO_INTRMOD_CHECK_INTERVAL;
  2830. intrmod_cfg->intrmod_maxpkt_ratethr = LIO_INTRMOD_MAXPKT_RATETHR;
  2831. intrmod_cfg->intrmod_minpkt_ratethr = LIO_INTRMOD_MINPKT_RATETHR;
  2832. intrmod_cfg->intrmod_maxcnt_trigger = LIO_INTRMOD_MAXCNT_TRIGGER;
  2833. intrmod_cfg->intrmod_maxtmr_trigger = LIO_INTRMOD_MAXTMR_TRIGGER;
  2834. intrmod_cfg->intrmod_mintmr_trigger = LIO_INTRMOD_MINTMR_TRIGGER;
  2835. intrmod_cfg->intrmod_mincnt_trigger = LIO_INTRMOD_MINCNT_TRIGGER;
  2836. dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n");
  2837. return retval;
  2838. octnet_init_failure:
  2839. oct->ifcount = 0;
  2840. return retval;
  2841. }
  2842. /**
  2843. * \brief starter callback that invokes the remaining initialization work after
  2844. * the NIC is up and running.
  2845. * @param octptr work struct work_struct
  2846. */
  2847. static void nic_starter(struct work_struct *work)
  2848. {
  2849. struct octeon_device *oct;
  2850. struct cavium_wk *wk = (struct cavium_wk *)work;
  2851. oct = (struct octeon_device *)wk->ctxptr;
  2852. if (atomic_read(&oct->status) == OCT_DEV_RUNNING)
  2853. return;
  2854. /* If the status of the device is CORE_OK, the core
  2855. * application has reported its application type. Call
  2856. * any registered handlers now and move to the RUNNING
  2857. * state.
  2858. */
  2859. if (atomic_read(&oct->status) != OCT_DEV_CORE_OK) {
  2860. schedule_delayed_work(&oct->nic_poll_work.work,
  2861. LIQUIDIO_STARTER_POLL_INTERVAL_MS);
  2862. return;
  2863. }
  2864. atomic_set(&oct->status, OCT_DEV_RUNNING);
  2865. if (oct->app_mode && oct->app_mode == CVM_DRV_NIC_APP) {
  2866. dev_dbg(&oct->pci_dev->dev, "Starting NIC module\n");
  2867. if (liquidio_init_nic_module(oct))
  2868. dev_err(&oct->pci_dev->dev, "NIC initialization failed\n");
  2869. else
  2870. handshake[oct->octeon_id].started_ok = 1;
  2871. } else {
  2872. dev_err(&oct->pci_dev->dev,
  2873. "Unexpected application running on NIC (%d). Check firmware.\n",
  2874. oct->app_mode);
  2875. }
  2876. complete(&handshake[oct->octeon_id].started);
  2877. }
  2878. /**
  2879. * \brief Device initialization for each Octeon device that is probed
  2880. * @param octeon_dev octeon device
  2881. */
  2882. static int octeon_device_init(struct octeon_device *octeon_dev)
  2883. {
  2884. int j, ret;
  2885. struct octeon_device_priv *oct_priv =
  2886. (struct octeon_device_priv *)octeon_dev->priv;
  2887. atomic_set(&octeon_dev->status, OCT_DEV_BEGIN_STATE);
  2888. /* Enable access to the octeon device and make its DMA capability
  2889. * known to the OS.
  2890. */
  2891. if (octeon_pci_os_setup(octeon_dev))
  2892. return 1;
  2893. /* Identify the Octeon type and map the BAR address space. */
  2894. if (octeon_chip_specific_setup(octeon_dev)) {
  2895. dev_err(&octeon_dev->pci_dev->dev, "Chip specific setup failed\n");
  2896. return 1;
  2897. }
  2898. atomic_set(&octeon_dev->status, OCT_DEV_PCI_MAP_DONE);
  2899. octeon_dev->app_mode = CVM_DRV_INVALID_APP;
  2900. /* Do a soft reset of the Octeon device. */
  2901. if (octeon_dev->fn_list.soft_reset(octeon_dev))
  2902. return 1;
  2903. /* Initialize the dispatch mechanism used to push packets arriving on
  2904. * Octeon Output queues.
  2905. */
  2906. if (octeon_init_dispatch_list(octeon_dev))
  2907. return 1;
  2908. octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
  2909. OPCODE_NIC_CORE_DRV_ACTIVE,
  2910. octeon_core_drv_init,
  2911. octeon_dev);
  2912. INIT_DELAYED_WORK(&octeon_dev->nic_poll_work.work, nic_starter);
  2913. octeon_dev->nic_poll_work.ctxptr = (void *)octeon_dev;
  2914. schedule_delayed_work(&octeon_dev->nic_poll_work.work,
  2915. LIQUIDIO_STARTER_POLL_INTERVAL_MS);
  2916. atomic_set(&octeon_dev->status, OCT_DEV_DISPATCH_INIT_DONE);
  2917. octeon_set_io_queues_off(octeon_dev);
  2918. /* Setup the data structures that manage this Octeon's Input queues. */
  2919. if (octeon_setup_instr_queues(octeon_dev)) {
  2920. dev_err(&octeon_dev->pci_dev->dev,
  2921. "instruction queue initialization failed\n");
  2922. /* On error, release any previously allocated queues */
  2923. for (j = 0; j < octeon_dev->num_iqs; j++)
  2924. octeon_delete_instr_queue(octeon_dev, j);
  2925. return 1;
  2926. }
  2927. atomic_set(&octeon_dev->status, OCT_DEV_INSTR_QUEUE_INIT_DONE);
  2928. /* Initialize soft command buffer pool
  2929. */
  2930. if (octeon_setup_sc_buffer_pool(octeon_dev)) {
  2931. dev_err(&octeon_dev->pci_dev->dev, "sc buffer pool allocation failed\n");
  2932. return 1;
  2933. }
  2934. atomic_set(&octeon_dev->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE);
  2935. /* Initialize lists to manage the requests of different types that
  2936. * arrive from user & kernel applications for this octeon device.
  2937. */
  2938. if (octeon_setup_response_list(octeon_dev)) {
  2939. dev_err(&octeon_dev->pci_dev->dev, "Response list allocation failed\n");
  2940. return 1;
  2941. }
  2942. atomic_set(&octeon_dev->status, OCT_DEV_RESP_LIST_INIT_DONE);
  2943. if (octeon_setup_output_queues(octeon_dev)) {
  2944. dev_err(&octeon_dev->pci_dev->dev, "Output queue initialization failed\n");
  2945. /* Release any previously allocated queues */
  2946. for (j = 0; j < octeon_dev->num_oqs; j++)
  2947. octeon_delete_droq(octeon_dev, j);
  2948. }
  2949. atomic_set(&octeon_dev->status, OCT_DEV_DROQ_INIT_DONE);
  2950. /* The input and output queue registers were setup earlier (the queues
  2951. * were not enabled). Any additional registers that need to be
  2952. * programmed should be done now.
  2953. */
  2954. ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
  2955. if (ret) {
  2956. dev_err(&octeon_dev->pci_dev->dev,
  2957. "Failed to configure device registers\n");
  2958. return ret;
  2959. }
  2960. /* Initialize the tasklet that handles output queue packet processing.*/
  2961. dev_dbg(&octeon_dev->pci_dev->dev, "Initializing droq tasklet\n");
  2962. tasklet_init(&oct_priv->droq_tasklet, octeon_droq_bh,
  2963. (unsigned long)octeon_dev);
  2964. /* Setup the interrupt handler and record the INT SUM register address
  2965. */
  2966. octeon_setup_interrupt(octeon_dev);
  2967. /* Enable Octeon device interrupts */
  2968. octeon_dev->fn_list.enable_interrupt(octeon_dev->chip);
  2969. /* Enable the input and output queues for this Octeon device */
  2970. octeon_dev->fn_list.enable_io_queues(octeon_dev);
  2971. atomic_set(&octeon_dev->status, OCT_DEV_IO_QUEUES_DONE);
  2972. dev_dbg(&octeon_dev->pci_dev->dev, "Waiting for DDR initialization...\n");
  2973. if (ddr_timeout == 0) {
  2974. dev_info(&octeon_dev->pci_dev->dev,
  2975. "WAITING. Set ddr_timeout to non-zero value to proceed with initialization.\n");
  2976. }
  2977. schedule_timeout_uninterruptible(HZ * LIO_RESET_SECS);
  2978. /* Wait for the octeon to initialize DDR after the soft-reset. */
  2979. ret = octeon_wait_for_ddr_init(octeon_dev, &ddr_timeout);
  2980. if (ret) {
  2981. dev_err(&octeon_dev->pci_dev->dev,
  2982. "DDR not initialized. Please confirm that board is configured to boot from Flash, ret: %d\n",
  2983. ret);
  2984. return 1;
  2985. }
  2986. if (octeon_wait_for_bootloader(octeon_dev, 1000) != 0) {
  2987. dev_err(&octeon_dev->pci_dev->dev, "Board not responding\n");
  2988. return 1;
  2989. }
  2990. dev_dbg(&octeon_dev->pci_dev->dev, "Initializing consoles\n");
  2991. ret = octeon_init_consoles(octeon_dev);
  2992. if (ret) {
  2993. dev_err(&octeon_dev->pci_dev->dev, "Could not access board consoles\n");
  2994. return 1;
  2995. }
  2996. ret = octeon_add_console(octeon_dev, 0);
  2997. if (ret) {
  2998. dev_err(&octeon_dev->pci_dev->dev, "Could not access board console\n");
  2999. return 1;
  3000. }
  3001. atomic_set(&octeon_dev->status, OCT_DEV_CONSOLE_INIT_DONE);
  3002. dev_dbg(&octeon_dev->pci_dev->dev, "Loading firmware\n");
  3003. ret = load_firmware(octeon_dev);
  3004. if (ret) {
  3005. dev_err(&octeon_dev->pci_dev->dev, "Could not load firmware to board\n");
  3006. return 1;
  3007. }
  3008. handshake[octeon_dev->octeon_id].init_ok = 1;
  3009. complete(&handshake[octeon_dev->octeon_id].init);
  3010. atomic_set(&octeon_dev->status, OCT_DEV_HOST_OK);
  3011. /* Send Credit for Octeon Output queues. Credits are always sent after
  3012. * the output queue is enabled.
  3013. */
  3014. for (j = 0; j < octeon_dev->num_oqs; j++)
  3015. writel(octeon_dev->droq[j]->max_count,
  3016. octeon_dev->droq[j]->pkts_credit_reg);
  3017. /* Packets can start arriving on the output queues from this point. */
  3018. return 0;
  3019. }
  3020. /**
  3021. * \brief Exits the module
  3022. */
  3023. static void __exit liquidio_exit(void)
  3024. {
  3025. liquidio_deinit_pci();
  3026. pr_info("LiquidIO network module is now unloaded\n");
  3027. }
  3028. module_init(liquidio_init);
  3029. module_exit(liquidio_exit);