netxen_nic_hw.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598
  1. /*
  2. * Copyright (C) 2003 - 2009 NetXen, Inc.
  3. * Copyright (C) 2009 - QLogic Corporation.
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution
  20. * in the file called "COPYING".
  21. *
  22. */
  23. #include <linux/slab.h>
  24. #include "netxen_nic.h"
  25. #include "netxen_nic_hw.h"
  26. #include <net/ip.h>
  27. #define MASK(n) ((1ULL<<(n))-1)
  28. #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
  29. #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
  30. #define MS_WIN(addr) (addr & 0x0ffc0000)
  31. #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
  32. #define CRB_BLK(off) ((off >> 20) & 0x3f)
  33. #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
  34. #define CRB_WINDOW_2M (0x130060)
  35. #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
  36. #define CRB_INDIRECT_2M (0x1e0000UL)
  37. static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
  38. void __iomem *addr, u32 data);
  39. static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
  40. void __iomem *addr);
  41. #ifndef readq
  42. static inline u64 readq(void __iomem *addr)
  43. {
  44. return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
  45. }
  46. #endif
  47. #ifndef writeq
  48. static inline void writeq(u64 val, void __iomem *addr)
  49. {
  50. writel(((u32) (val)), (addr));
  51. writel(((u32) (val >> 32)), (addr + 4));
  52. }
  53. #endif
  54. #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
  55. ((adapter)->ahw.pci_base0 + (off))
  56. #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
  57. ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
  58. #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
  59. ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
  60. static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
  61. unsigned long off)
  62. {
  63. if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
  64. return PCI_OFFSET_FIRST_RANGE(adapter, off);
  65. if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
  66. return PCI_OFFSET_SECOND_RANGE(adapter, off);
  67. if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
  68. return PCI_OFFSET_THIRD_RANGE(adapter, off);
  69. return NULL;
  70. }
  71. static crb_128M_2M_block_map_t
  72. crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
  73. {{{0, 0, 0, 0} } }, /* 0: PCI */
  74. {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
  75. {1, 0x0110000, 0x0120000, 0x130000},
  76. {1, 0x0120000, 0x0122000, 0x124000},
  77. {1, 0x0130000, 0x0132000, 0x126000},
  78. {1, 0x0140000, 0x0142000, 0x128000},
  79. {1, 0x0150000, 0x0152000, 0x12a000},
  80. {1, 0x0160000, 0x0170000, 0x110000},
  81. {1, 0x0170000, 0x0172000, 0x12e000},
  82. {0, 0x0000000, 0x0000000, 0x000000},
  83. {0, 0x0000000, 0x0000000, 0x000000},
  84. {0, 0x0000000, 0x0000000, 0x000000},
  85. {0, 0x0000000, 0x0000000, 0x000000},
  86. {0, 0x0000000, 0x0000000, 0x000000},
  87. {0, 0x0000000, 0x0000000, 0x000000},
  88. {1, 0x01e0000, 0x01e0800, 0x122000},
  89. {0, 0x0000000, 0x0000000, 0x000000} } },
  90. {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
  91. {{{0, 0, 0, 0} } }, /* 3: */
  92. {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
  93. {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
  94. {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
  95. {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
  96. {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
  97. {0, 0x0000000, 0x0000000, 0x000000},
  98. {0, 0x0000000, 0x0000000, 0x000000},
  99. {0, 0x0000000, 0x0000000, 0x000000},
  100. {0, 0x0000000, 0x0000000, 0x000000},
  101. {0, 0x0000000, 0x0000000, 0x000000},
  102. {0, 0x0000000, 0x0000000, 0x000000},
  103. {0, 0x0000000, 0x0000000, 0x000000},
  104. {0, 0x0000000, 0x0000000, 0x000000},
  105. {0, 0x0000000, 0x0000000, 0x000000},
  106. {0, 0x0000000, 0x0000000, 0x000000},
  107. {0, 0x0000000, 0x0000000, 0x000000},
  108. {0, 0x0000000, 0x0000000, 0x000000},
  109. {0, 0x0000000, 0x0000000, 0x000000},
  110. {0, 0x0000000, 0x0000000, 0x000000},
  111. {1, 0x08f0000, 0x08f2000, 0x172000} } },
  112. {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
  113. {0, 0x0000000, 0x0000000, 0x000000},
  114. {0, 0x0000000, 0x0000000, 0x000000},
  115. {0, 0x0000000, 0x0000000, 0x000000},
  116. {0, 0x0000000, 0x0000000, 0x000000},
  117. {0, 0x0000000, 0x0000000, 0x000000},
  118. {0, 0x0000000, 0x0000000, 0x000000},
  119. {0, 0x0000000, 0x0000000, 0x000000},
  120. {0, 0x0000000, 0x0000000, 0x000000},
  121. {0, 0x0000000, 0x0000000, 0x000000},
  122. {0, 0x0000000, 0x0000000, 0x000000},
  123. {0, 0x0000000, 0x0000000, 0x000000},
  124. {0, 0x0000000, 0x0000000, 0x000000},
  125. {0, 0x0000000, 0x0000000, 0x000000},
  126. {0, 0x0000000, 0x0000000, 0x000000},
  127. {1, 0x09f0000, 0x09f2000, 0x176000} } },
  128. {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
  129. {0, 0x0000000, 0x0000000, 0x000000},
  130. {0, 0x0000000, 0x0000000, 0x000000},
  131. {0, 0x0000000, 0x0000000, 0x000000},
  132. {0, 0x0000000, 0x0000000, 0x000000},
  133. {0, 0x0000000, 0x0000000, 0x000000},
  134. {0, 0x0000000, 0x0000000, 0x000000},
  135. {0, 0x0000000, 0x0000000, 0x000000},
  136. {0, 0x0000000, 0x0000000, 0x000000},
  137. {0, 0x0000000, 0x0000000, 0x000000},
  138. {0, 0x0000000, 0x0000000, 0x000000},
  139. {0, 0x0000000, 0x0000000, 0x000000},
  140. {0, 0x0000000, 0x0000000, 0x000000},
  141. {0, 0x0000000, 0x0000000, 0x000000},
  142. {0, 0x0000000, 0x0000000, 0x000000},
  143. {1, 0x0af0000, 0x0af2000, 0x17a000} } },
  144. {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
  145. {0, 0x0000000, 0x0000000, 0x000000},
  146. {0, 0x0000000, 0x0000000, 0x000000},
  147. {0, 0x0000000, 0x0000000, 0x000000},
  148. {0, 0x0000000, 0x0000000, 0x000000},
  149. {0, 0x0000000, 0x0000000, 0x000000},
  150. {0, 0x0000000, 0x0000000, 0x000000},
  151. {0, 0x0000000, 0x0000000, 0x000000},
  152. {0, 0x0000000, 0x0000000, 0x000000},
  153. {0, 0x0000000, 0x0000000, 0x000000},
  154. {0, 0x0000000, 0x0000000, 0x000000},
  155. {0, 0x0000000, 0x0000000, 0x000000},
  156. {0, 0x0000000, 0x0000000, 0x000000},
  157. {0, 0x0000000, 0x0000000, 0x000000},
  158. {0, 0x0000000, 0x0000000, 0x000000},
  159. {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
  160. {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
  161. {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
  162. {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
  163. {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
  164. {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
  165. {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
  166. {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
  167. {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
  168. {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
  169. {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
  170. {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
  171. {{{0, 0, 0, 0} } }, /* 23: */
  172. {{{0, 0, 0, 0} } }, /* 24: */
  173. {{{0, 0, 0, 0} } }, /* 25: */
  174. {{{0, 0, 0, 0} } }, /* 26: */
  175. {{{0, 0, 0, 0} } }, /* 27: */
  176. {{{0, 0, 0, 0} } }, /* 28: */
  177. {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
  178. {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
  179. {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
  180. {{{0} } }, /* 32: PCI */
  181. {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
  182. {1, 0x2110000, 0x2120000, 0x130000},
  183. {1, 0x2120000, 0x2122000, 0x124000},
  184. {1, 0x2130000, 0x2132000, 0x126000},
  185. {1, 0x2140000, 0x2142000, 0x128000},
  186. {1, 0x2150000, 0x2152000, 0x12a000},
  187. {1, 0x2160000, 0x2170000, 0x110000},
  188. {1, 0x2170000, 0x2172000, 0x12e000},
  189. {0, 0x0000000, 0x0000000, 0x000000},
  190. {0, 0x0000000, 0x0000000, 0x000000},
  191. {0, 0x0000000, 0x0000000, 0x000000},
  192. {0, 0x0000000, 0x0000000, 0x000000},
  193. {0, 0x0000000, 0x0000000, 0x000000},
  194. {0, 0x0000000, 0x0000000, 0x000000},
  195. {0, 0x0000000, 0x0000000, 0x000000},
  196. {0, 0x0000000, 0x0000000, 0x000000} } },
  197. {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
  198. {{{0} } }, /* 35: */
  199. {{{0} } }, /* 36: */
  200. {{{0} } }, /* 37: */
  201. {{{0} } }, /* 38: */
  202. {{{0} } }, /* 39: */
  203. {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
  204. {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
  205. {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
  206. {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
  207. {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
  208. {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
  209. {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
  210. {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
  211. {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
  212. {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
  213. {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
  214. {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
  215. {{{0} } }, /* 52: */
  216. {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
  217. {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
  218. {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
  219. {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
  220. {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
  221. {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
  222. {{{0} } }, /* 59: I2C0 */
  223. {{{0} } }, /* 60: I2C1 */
  224. {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
  225. {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
  226. {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
  227. };
  228. /*
  229. * top 12 bits of crb internal address (hub, agent)
  230. */
  231. static unsigned crb_hub_agt[64] =
  232. {
  233. 0,
  234. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  235. NETXEN_HW_CRB_HUB_AGT_ADR_MN,
  236. NETXEN_HW_CRB_HUB_AGT_ADR_MS,
  237. 0,
  238. NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
  239. NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
  240. NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
  241. NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
  242. NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
  243. NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
  244. NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
  245. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  246. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  247. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  248. NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
  249. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  250. NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
  251. NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
  252. NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
  253. NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
  254. NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
  255. NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
  256. NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
  257. NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
  258. NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
  259. NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
  260. 0,
  261. NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
  262. NETXEN_HW_CRB_HUB_AGT_ADR_SN,
  263. 0,
  264. NETXEN_HW_CRB_HUB_AGT_ADR_EG,
  265. 0,
  266. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  267. NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
  268. 0,
  269. 0,
  270. 0,
  271. 0,
  272. 0,
  273. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  274. 0,
  275. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
  276. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
  277. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
  278. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
  279. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
  280. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
  281. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
  282. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  283. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  284. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  285. 0,
  286. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
  287. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
  288. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
  289. NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
  290. 0,
  291. NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
  292. NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
  293. NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
  294. 0,
  295. NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
  296. 0,
  297. };
  298. /* PCI Windowing for DDR regions. */
  299. #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
  300. #define NETXEN_PCIE_SEM_TIMEOUT 10000
  301. static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
  302. int
  303. netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
  304. {
  305. int done = 0, timeout = 0;
  306. while (!done) {
  307. done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
  308. if (done == 1)
  309. break;
  310. if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
  311. return -EIO;
  312. msleep(1);
  313. }
  314. if (id_reg)
  315. NXWR32(adapter, id_reg, adapter->portnum);
  316. return 0;
  317. }
  318. void
  319. netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
  320. {
  321. NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
  322. }
  323. static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
  324. {
  325. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  326. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
  327. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
  328. }
  329. return 0;
  330. }
  331. /* Disable an XG interface */
  332. static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
  333. {
  334. __u32 mac_cfg;
  335. u32 port = adapter->physical_port;
  336. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  337. return 0;
  338. if (port >= NETXEN_NIU_MAX_XG_PORTS)
  339. return -EINVAL;
  340. mac_cfg = 0;
  341. if (NXWR32(adapter,
  342. NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
  343. return -EIO;
  344. return 0;
  345. }
  346. #define NETXEN_UNICAST_ADDR(port, index) \
  347. (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
  348. #define NETXEN_MCAST_ADDR(port, index) \
  349. (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
  350. #define MAC_HI(addr) \
  351. ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
  352. #define MAC_LO(addr) \
  353. ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
  354. static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
  355. {
  356. u32 mac_cfg;
  357. u32 cnt = 0;
  358. __u32 reg = 0x0200;
  359. u32 port = adapter->physical_port;
  360. u16 board_type = adapter->ahw.board_type;
  361. if (port >= NETXEN_NIU_MAX_XG_PORTS)
  362. return -EINVAL;
  363. mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
  364. mac_cfg &= ~0x4;
  365. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
  366. if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
  367. (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
  368. reg = (0x20 << port);
  369. NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
  370. mdelay(10);
  371. while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
  372. mdelay(10);
  373. if (cnt < 20) {
  374. reg = NXRD32(adapter,
  375. NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
  376. if (mode == NETXEN_NIU_PROMISC_MODE)
  377. reg = (reg | 0x2000UL);
  378. else
  379. reg = (reg & ~0x2000UL);
  380. if (mode == NETXEN_NIU_ALLMULTI_MODE)
  381. reg = (reg | 0x1000UL);
  382. else
  383. reg = (reg & ~0x1000UL);
  384. NXWR32(adapter,
  385. NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
  386. }
  387. mac_cfg |= 0x4;
  388. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
  389. return 0;
  390. }
  391. static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
  392. {
  393. u32 mac_hi, mac_lo;
  394. u32 reg_hi, reg_lo;
  395. u8 phy = adapter->physical_port;
  396. if (phy >= NETXEN_NIU_MAX_XG_PORTS)
  397. return -EINVAL;
  398. mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
  399. mac_hi = addr[2] | ((u32)addr[3] << 8) |
  400. ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
  401. reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
  402. reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
  403. /* write twice to flush */
  404. if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
  405. return -EIO;
  406. if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
  407. return -EIO;
  408. return 0;
  409. }
  410. static int
  411. netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
  412. {
  413. u32 val = 0;
  414. u16 port = adapter->physical_port;
  415. u8 *addr = adapter->mac_addr;
  416. if (adapter->mc_enabled)
  417. return 0;
  418. val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
  419. val |= (1UL << (28+port));
  420. NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
  421. /* add broadcast addr to filter */
  422. val = 0xffffff;
  423. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  424. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
  425. /* add station addr to filter */
  426. val = MAC_HI(addr);
  427. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
  428. val = MAC_LO(addr);
  429. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
  430. adapter->mc_enabled = 1;
  431. return 0;
  432. }
  433. static int
  434. netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
  435. {
  436. u32 val = 0;
  437. u16 port = adapter->physical_port;
  438. u8 *addr = adapter->mac_addr;
  439. if (!adapter->mc_enabled)
  440. return 0;
  441. val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
  442. val &= ~(1UL << (28+port));
  443. NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
  444. val = MAC_HI(addr);
  445. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  446. val = MAC_LO(addr);
  447. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
  448. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
  449. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
  450. adapter->mc_enabled = 0;
  451. return 0;
  452. }
  453. static int
  454. netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
  455. int index, u8 *addr)
  456. {
  457. u32 hi = 0, lo = 0;
  458. u16 port = adapter->physical_port;
  459. lo = MAC_LO(addr);
  460. hi = MAC_HI(addr);
  461. NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
  462. NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
  463. return 0;
  464. }
  465. static void netxen_p2_nic_set_multi(struct net_device *netdev)
  466. {
  467. struct netxen_adapter *adapter = netdev_priv(netdev);
  468. struct netdev_hw_addr *ha;
  469. u8 null_addr[ETH_ALEN];
  470. int i;
  471. eth_zero_addr(null_addr);
  472. if (netdev->flags & IFF_PROMISC) {
  473. adapter->set_promisc(adapter,
  474. NETXEN_NIU_PROMISC_MODE);
  475. /* Full promiscuous mode */
  476. netxen_nic_disable_mcast_filter(adapter);
  477. return;
  478. }
  479. if (netdev_mc_empty(netdev)) {
  480. adapter->set_promisc(adapter,
  481. NETXEN_NIU_NON_PROMISC_MODE);
  482. netxen_nic_disable_mcast_filter(adapter);
  483. return;
  484. }
  485. adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
  486. if (netdev->flags & IFF_ALLMULTI ||
  487. netdev_mc_count(netdev) > adapter->max_mc_count) {
  488. netxen_nic_disable_mcast_filter(adapter);
  489. return;
  490. }
  491. netxen_nic_enable_mcast_filter(adapter);
  492. i = 0;
  493. netdev_for_each_mc_addr(ha, netdev)
  494. netxen_nic_set_mcast_addr(adapter, i++, ha->addr);
  495. /* Clear out remaining addresses */
  496. while (i < adapter->max_mc_count)
  497. netxen_nic_set_mcast_addr(adapter, i++, null_addr);
  498. }
  499. static int
  500. netxen_send_cmd_descs(struct netxen_adapter *adapter,
  501. struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
  502. {
  503. u32 i, producer, consumer;
  504. struct netxen_cmd_buffer *pbuf;
  505. struct cmd_desc_type0 *cmd_desc;
  506. struct nx_host_tx_ring *tx_ring;
  507. i = 0;
  508. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  509. return -EIO;
  510. tx_ring = adapter->tx_ring;
  511. __netif_tx_lock_bh(tx_ring->txq);
  512. producer = tx_ring->producer;
  513. consumer = tx_ring->sw_consumer;
  514. if (nr_desc >= netxen_tx_avail(tx_ring)) {
  515. netif_tx_stop_queue(tx_ring->txq);
  516. smp_mb();
  517. if (netxen_tx_avail(tx_ring) > nr_desc) {
  518. if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
  519. netif_tx_wake_queue(tx_ring->txq);
  520. } else {
  521. __netif_tx_unlock_bh(tx_ring->txq);
  522. return -EBUSY;
  523. }
  524. }
  525. do {
  526. cmd_desc = &cmd_desc_arr[i];
  527. pbuf = &tx_ring->cmd_buf_arr[producer];
  528. pbuf->skb = NULL;
  529. pbuf->frag_count = 0;
  530. memcpy(&tx_ring->desc_head[producer],
  531. &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
  532. producer = get_next_index(producer, tx_ring->num_desc);
  533. i++;
  534. } while (i != nr_desc);
  535. tx_ring->producer = producer;
  536. netxen_nic_update_cmd_producer(adapter, tx_ring);
  537. __netif_tx_unlock_bh(tx_ring->txq);
  538. return 0;
  539. }
  540. static int
  541. nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
  542. {
  543. nx_nic_req_t req;
  544. nx_mac_req_t *mac_req;
  545. u64 word;
  546. memset(&req, 0, sizeof(nx_nic_req_t));
  547. req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
  548. word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
  549. req.req_hdr = cpu_to_le64(word);
  550. mac_req = (nx_mac_req_t *)&req.words[0];
  551. mac_req->op = op;
  552. memcpy(mac_req->mac_addr, addr, ETH_ALEN);
  553. return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  554. }
  555. static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
  556. const u8 *addr, struct list_head *del_list)
  557. {
  558. struct list_head *head;
  559. nx_mac_list_t *cur;
  560. /* look up if already exists */
  561. list_for_each(head, del_list) {
  562. cur = list_entry(head, nx_mac_list_t, list);
  563. if (ether_addr_equal(addr, cur->mac_addr)) {
  564. list_move_tail(head, &adapter->mac_list);
  565. return 0;
  566. }
  567. }
  568. cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
  569. if (cur == NULL)
  570. return -ENOMEM;
  571. memcpy(cur->mac_addr, addr, ETH_ALEN);
  572. list_add_tail(&cur->list, &adapter->mac_list);
  573. return nx_p3_sre_macaddr_change(adapter,
  574. cur->mac_addr, NETXEN_MAC_ADD);
  575. }
  576. static void netxen_p3_nic_set_multi(struct net_device *netdev)
  577. {
  578. struct netxen_adapter *adapter = netdev_priv(netdev);
  579. struct netdev_hw_addr *ha;
  580. static const u8 bcast_addr[ETH_ALEN] = {
  581. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  582. };
  583. u32 mode = VPORT_MISS_MODE_DROP;
  584. LIST_HEAD(del_list);
  585. struct list_head *head;
  586. nx_mac_list_t *cur;
  587. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  588. return;
  589. list_splice_tail_init(&adapter->mac_list, &del_list);
  590. nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
  591. nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
  592. if (netdev->flags & IFF_PROMISC) {
  593. mode = VPORT_MISS_MODE_ACCEPT_ALL;
  594. goto send_fw_cmd;
  595. }
  596. if ((netdev->flags & IFF_ALLMULTI) ||
  597. (netdev_mc_count(netdev) > adapter->max_mc_count)) {
  598. mode = VPORT_MISS_MODE_ACCEPT_MULTI;
  599. goto send_fw_cmd;
  600. }
  601. if (!netdev_mc_empty(netdev)) {
  602. netdev_for_each_mc_addr(ha, netdev)
  603. nx_p3_nic_add_mac(adapter, ha->addr, &del_list);
  604. }
  605. send_fw_cmd:
  606. adapter->set_promisc(adapter, mode);
  607. head = &del_list;
  608. while (!list_empty(head)) {
  609. cur = list_entry(head->next, nx_mac_list_t, list);
  610. nx_p3_sre_macaddr_change(adapter,
  611. cur->mac_addr, NETXEN_MAC_DEL);
  612. list_del(&cur->list);
  613. kfree(cur);
  614. }
  615. }
  616. static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
  617. {
  618. nx_nic_req_t req;
  619. u64 word;
  620. memset(&req, 0, sizeof(nx_nic_req_t));
  621. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  622. word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
  623. ((u64)adapter->portnum << 16);
  624. req.req_hdr = cpu_to_le64(word);
  625. req.words[0] = cpu_to_le64(mode);
  626. return netxen_send_cmd_descs(adapter,
  627. (struct cmd_desc_type0 *)&req, 1);
  628. }
  629. void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
  630. {
  631. nx_mac_list_t *cur;
  632. struct list_head *head = &adapter->mac_list;
  633. while (!list_empty(head)) {
  634. cur = list_entry(head->next, nx_mac_list_t, list);
  635. nx_p3_sre_macaddr_change(adapter,
  636. cur->mac_addr, NETXEN_MAC_DEL);
  637. list_del(&cur->list);
  638. kfree(cur);
  639. }
  640. }
  641. static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
  642. {
  643. /* assuming caller has already copied new addr to netdev */
  644. netxen_p3_nic_set_multi(adapter->netdev);
  645. return 0;
  646. }
  647. #define NETXEN_CONFIG_INTR_COALESCE 3
  648. /*
  649. * Send the interrupt coalescing parameter set by ethtool to the card.
  650. */
  651. int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
  652. {
  653. nx_nic_req_t req;
  654. u64 word[6];
  655. int rv, i;
  656. memset(&req, 0, sizeof(nx_nic_req_t));
  657. memset(word, 0, sizeof(word));
  658. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  659. word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
  660. req.req_hdr = cpu_to_le64(word[0]);
  661. memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
  662. for (i = 0; i < 6; i++)
  663. req.words[i] = cpu_to_le64(word[i]);
  664. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  665. if (rv != 0) {
  666. printk(KERN_ERR "ERROR. Could not send "
  667. "interrupt coalescing parameters\n");
  668. }
  669. return rv;
  670. }
  671. int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
  672. {
  673. nx_nic_req_t req;
  674. u64 word;
  675. int rv = 0;
  676. if (!test_bit(__NX_FW_ATTACHED, &adapter->state))
  677. return 0;
  678. memset(&req, 0, sizeof(nx_nic_req_t));
  679. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  680. word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
  681. req.req_hdr = cpu_to_le64(word);
  682. req.words[0] = cpu_to_le64(enable);
  683. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  684. if (rv != 0) {
  685. printk(KERN_ERR "ERROR. Could not send "
  686. "configure hw lro request\n");
  687. }
  688. return rv;
  689. }
  690. int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
  691. {
  692. nx_nic_req_t req;
  693. u64 word;
  694. int rv = 0;
  695. if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
  696. return rv;
  697. memset(&req, 0, sizeof(nx_nic_req_t));
  698. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  699. word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
  700. ((u64)adapter->portnum << 16);
  701. req.req_hdr = cpu_to_le64(word);
  702. req.words[0] = cpu_to_le64(enable);
  703. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  704. if (rv != 0) {
  705. printk(KERN_ERR "ERROR. Could not send "
  706. "configure bridge mode request\n");
  707. }
  708. adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
  709. return rv;
  710. }
  711. #define RSS_HASHTYPE_IP_TCP 0x3
  712. int netxen_config_rss(struct netxen_adapter *adapter, int enable)
  713. {
  714. nx_nic_req_t req;
  715. u64 word;
  716. int i, rv;
  717. static const u64 key[] = {
  718. 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
  719. 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
  720. 0x255b0ec26d5a56daULL
  721. };
  722. memset(&req, 0, sizeof(nx_nic_req_t));
  723. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  724. word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
  725. req.req_hdr = cpu_to_le64(word);
  726. /*
  727. * RSS request:
  728. * bits 3-0: hash_method
  729. * 5-4: hash_type_ipv4
  730. * 7-6: hash_type_ipv6
  731. * 8: enable
  732. * 9: use indirection table
  733. * 47-10: reserved
  734. * 63-48: indirection table mask
  735. */
  736. word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
  737. ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
  738. ((u64)(enable & 0x1) << 8) |
  739. ((0x7ULL) << 48);
  740. req.words[0] = cpu_to_le64(word);
  741. for (i = 0; i < ARRAY_SIZE(key); i++)
  742. req.words[i+1] = cpu_to_le64(key[i]);
  743. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  744. if (rv != 0) {
  745. printk(KERN_ERR "%s: could not configure RSS\n",
  746. adapter->netdev->name);
  747. }
  748. return rv;
  749. }
  750. int netxen_config_ipaddr(struct netxen_adapter *adapter, __be32 ip, int cmd)
  751. {
  752. nx_nic_req_t req;
  753. u64 word;
  754. int rv;
  755. memset(&req, 0, sizeof(nx_nic_req_t));
  756. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  757. word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
  758. req.req_hdr = cpu_to_le64(word);
  759. req.words[0] = cpu_to_le64(cmd);
  760. memcpy(&req.words[1], &ip, sizeof(u32));
  761. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  762. if (rv != 0) {
  763. printk(KERN_ERR "%s: could not notify %s IP 0x%x request\n",
  764. adapter->netdev->name,
  765. (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
  766. }
  767. return rv;
  768. }
  769. int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
  770. {
  771. nx_nic_req_t req;
  772. u64 word;
  773. int rv;
  774. memset(&req, 0, sizeof(nx_nic_req_t));
  775. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  776. word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
  777. req.req_hdr = cpu_to_le64(word);
  778. req.words[0] = cpu_to_le64(enable | (enable << 8));
  779. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  780. if (rv != 0) {
  781. printk(KERN_ERR "%s: could not configure link notification\n",
  782. adapter->netdev->name);
  783. }
  784. return rv;
  785. }
  786. int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
  787. {
  788. nx_nic_req_t req;
  789. u64 word;
  790. int rv;
  791. if (!test_bit(__NX_FW_ATTACHED, &adapter->state))
  792. return 0;
  793. memset(&req, 0, sizeof(nx_nic_req_t));
  794. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  795. word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
  796. ((u64)adapter->portnum << 16) |
  797. ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
  798. req.req_hdr = cpu_to_le64(word);
  799. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  800. if (rv != 0) {
  801. printk(KERN_ERR "%s: could not cleanup lro flows\n",
  802. adapter->netdev->name);
  803. }
  804. return rv;
  805. }
  806. /*
  807. * netxen_nic_change_mtu - Change the Maximum Transfer Unit
  808. * @returns 0 on success, negative on failure
  809. */
  810. #define MTU_FUDGE_FACTOR 100
  811. int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
  812. {
  813. struct netxen_adapter *adapter = netdev_priv(netdev);
  814. int max_mtu;
  815. int rc = 0;
  816. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  817. max_mtu = P3_MAX_MTU;
  818. else
  819. max_mtu = P2_MAX_MTU;
  820. if (mtu > max_mtu) {
  821. printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
  822. netdev->name, max_mtu);
  823. return -EINVAL;
  824. }
  825. if (adapter->set_mtu)
  826. rc = adapter->set_mtu(adapter, mtu);
  827. if (!rc)
  828. netdev->mtu = mtu;
  829. return rc;
  830. }
  831. static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
  832. int size, __le32 * buf)
  833. {
  834. int i, v, addr;
  835. __le32 *ptr32;
  836. int ret;
  837. addr = base;
  838. ptr32 = buf;
  839. for (i = 0; i < size / sizeof(u32); i++) {
  840. ret = netxen_rom_fast_read(adapter, addr, &v);
  841. if (ret)
  842. return ret;
  843. *ptr32 = cpu_to_le32(v);
  844. ptr32++;
  845. addr += sizeof(u32);
  846. }
  847. if ((char *)buf + size > (char *)ptr32) {
  848. __le32 local;
  849. ret = netxen_rom_fast_read(adapter, addr, &v);
  850. if (ret)
  851. return ret;
  852. local = cpu_to_le32(v);
  853. memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
  854. }
  855. return 0;
  856. }
  857. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  858. {
  859. __le32 *pmac = (__le32 *) mac;
  860. u32 offset;
  861. offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
  862. if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
  863. return -1;
  864. if (*mac == ~0ULL) {
  865. offset = NX_OLD_MAC_ADDR_OFFSET +
  866. (adapter->portnum * sizeof(u64));
  867. if (netxen_get_flash_block(adapter,
  868. offset, sizeof(u64), pmac) == -1)
  869. return -1;
  870. if (*mac == ~0ULL)
  871. return -1;
  872. }
  873. return 0;
  874. }
  875. int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  876. {
  877. uint32_t crbaddr, mac_hi, mac_lo;
  878. int pci_func = adapter->ahw.pci_func;
  879. crbaddr = CRB_MAC_BLOCK_START +
  880. (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
  881. mac_lo = NXRD32(adapter, crbaddr);
  882. mac_hi = NXRD32(adapter, crbaddr+4);
  883. if (pci_func & 1)
  884. *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
  885. else
  886. *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
  887. return 0;
  888. }
  889. /*
  890. * Changes the CRB window to the specified window.
  891. */
  892. static void
  893. netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
  894. u32 window)
  895. {
  896. void __iomem *offset;
  897. int count = 10;
  898. u8 func = adapter->ahw.pci_func;
  899. if (adapter->ahw.crb_win == window)
  900. return;
  901. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  902. NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
  903. writel(window, offset);
  904. do {
  905. if (window == readl(offset))
  906. break;
  907. if (printk_ratelimit())
  908. dev_warn(&adapter->pdev->dev,
  909. "failed to set CRB window to %d\n",
  910. (window == NETXEN_WINDOW_ONE));
  911. udelay(1);
  912. } while (--count > 0);
  913. if (count > 0)
  914. adapter->ahw.crb_win = window;
  915. }
  916. /*
  917. * Returns < 0 if off is not valid,
  918. * 1 if window access is needed. 'off' is set to offset from
  919. * CRB space in 128M pci map
  920. * 0 if no window access is needed. 'off' is set to 2M addr
  921. * In: 'off' is offset from base in 128M pci map
  922. */
  923. static int
  924. netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
  925. ulong off, void __iomem **addr)
  926. {
  927. crb_128M_2M_sub_block_map_t *m;
  928. if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
  929. return -EINVAL;
  930. off -= NETXEN_PCI_CRBSPACE;
  931. /*
  932. * Try direct map
  933. */
  934. m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
  935. if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
  936. *addr = adapter->ahw.pci_base0 + m->start_2M +
  937. (off - m->start_128M);
  938. return 0;
  939. }
  940. /*
  941. * Not in direct map, use crb window
  942. */
  943. *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
  944. (off & MASK(16));
  945. return 1;
  946. }
  947. /*
  948. * In: 'off' is offset from CRB space in 128M pci map
  949. * Out: 'off' is 2M pci map addr
  950. * side effect: lock crb window
  951. */
  952. static void
  953. netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
  954. {
  955. u32 window;
  956. void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
  957. off -= NETXEN_PCI_CRBSPACE;
  958. window = CRB_HI(off);
  959. writel(window, addr);
  960. if (readl(addr) != window) {
  961. if (printk_ratelimit())
  962. dev_warn(&adapter->pdev->dev,
  963. "failed to set CRB window to %d off 0x%lx\n",
  964. window, off);
  965. }
  966. }
  967. static void __iomem *
  968. netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
  969. ulong win_off, void __iomem **mem_ptr)
  970. {
  971. ulong off = win_off;
  972. void __iomem *addr;
  973. resource_size_t mem_base;
  974. if (ADDR_IN_WINDOW1(win_off))
  975. off = NETXEN_CRB_NORMAL(win_off);
  976. addr = pci_base_offset(adapter, off);
  977. if (addr)
  978. return addr;
  979. if (adapter->ahw.pci_len0 == 0)
  980. off -= NETXEN_PCI_CRBSPACE;
  981. mem_base = pci_resource_start(adapter->pdev, 0);
  982. *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
  983. if (*mem_ptr)
  984. addr = *mem_ptr + (off & (PAGE_SIZE - 1));
  985. return addr;
  986. }
  987. static int
  988. netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
  989. {
  990. unsigned long flags;
  991. void __iomem *addr, *mem_ptr = NULL;
  992. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  993. if (!addr)
  994. return -EIO;
  995. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  996. netxen_nic_io_write_128M(adapter, addr, data);
  997. } else { /* Window 0 */
  998. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  999. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1000. writel(data, addr);
  1001. netxen_nic_pci_set_crbwindow_128M(adapter,
  1002. NETXEN_WINDOW_ONE);
  1003. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1004. }
  1005. if (mem_ptr)
  1006. iounmap(mem_ptr);
  1007. return 0;
  1008. }
  1009. static u32
  1010. netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
  1011. {
  1012. unsigned long flags;
  1013. void __iomem *addr, *mem_ptr = NULL;
  1014. u32 data;
  1015. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  1016. if (!addr)
  1017. return -EIO;
  1018. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  1019. data = netxen_nic_io_read_128M(adapter, addr);
  1020. } else { /* Window 0 */
  1021. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1022. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1023. data = readl(addr);
  1024. netxen_nic_pci_set_crbwindow_128M(adapter,
  1025. NETXEN_WINDOW_ONE);
  1026. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1027. }
  1028. if (mem_ptr)
  1029. iounmap(mem_ptr);
  1030. return data;
  1031. }
  1032. static int
  1033. netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
  1034. {
  1035. unsigned long flags;
  1036. int rv;
  1037. void __iomem *addr = NULL;
  1038. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1039. if (rv == 0) {
  1040. writel(data, addr);
  1041. return 0;
  1042. }
  1043. if (rv > 0) {
  1044. /* indirect access */
  1045. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1046. crb_win_lock(adapter);
  1047. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1048. writel(data, addr);
  1049. crb_win_unlock(adapter);
  1050. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1051. return 0;
  1052. }
  1053. dev_err(&adapter->pdev->dev,
  1054. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1055. dump_stack();
  1056. return -EIO;
  1057. }
  1058. static u32
  1059. netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
  1060. {
  1061. unsigned long flags;
  1062. int rv;
  1063. u32 data;
  1064. void __iomem *addr = NULL;
  1065. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1066. if (rv == 0)
  1067. return readl(addr);
  1068. if (rv > 0) {
  1069. /* indirect access */
  1070. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1071. crb_win_lock(adapter);
  1072. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1073. data = readl(addr);
  1074. crb_win_unlock(adapter);
  1075. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1076. return data;
  1077. }
  1078. dev_err(&adapter->pdev->dev,
  1079. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1080. dump_stack();
  1081. return -1;
  1082. }
  1083. /* window 1 registers only */
  1084. static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
  1085. void __iomem *addr, u32 data)
  1086. {
  1087. read_lock(&adapter->ahw.crb_lock);
  1088. writel(data, addr);
  1089. read_unlock(&adapter->ahw.crb_lock);
  1090. }
  1091. static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
  1092. void __iomem *addr)
  1093. {
  1094. u32 val;
  1095. read_lock(&adapter->ahw.crb_lock);
  1096. val = readl(addr);
  1097. read_unlock(&adapter->ahw.crb_lock);
  1098. return val;
  1099. }
  1100. static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
  1101. void __iomem *addr, u32 data)
  1102. {
  1103. writel(data, addr);
  1104. }
  1105. static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
  1106. void __iomem *addr)
  1107. {
  1108. return readl(addr);
  1109. }
  1110. void __iomem *
  1111. netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
  1112. {
  1113. void __iomem *addr = NULL;
  1114. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1115. if ((offset < NETXEN_CRB_PCIX_HOST2) &&
  1116. (offset > NETXEN_CRB_PCIX_HOST))
  1117. addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
  1118. else
  1119. addr = NETXEN_CRB_NORMALIZE(adapter, offset);
  1120. } else {
  1121. WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
  1122. offset, &addr));
  1123. }
  1124. return addr;
  1125. }
  1126. static int
  1127. netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
  1128. u64 addr, u32 *start)
  1129. {
  1130. if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1131. *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
  1132. return 0;
  1133. } else if (ADDR_IN_RANGE(addr,
  1134. NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1135. *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
  1136. return 0;
  1137. }
  1138. return -EIO;
  1139. }
  1140. static int
  1141. netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
  1142. u64 addr, u32 *start)
  1143. {
  1144. u32 window;
  1145. window = OCM_WIN(addr);
  1146. writel(window, adapter->ahw.ocm_win_crb);
  1147. /* read back to flush */
  1148. readl(adapter->ahw.ocm_win_crb);
  1149. adapter->ahw.ocm_win = window;
  1150. *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
  1151. return 0;
  1152. }
  1153. static int
  1154. netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
  1155. u64 *data, int op)
  1156. {
  1157. void __iomem *addr, *mem_ptr = NULL;
  1158. resource_size_t mem_base;
  1159. int ret;
  1160. u32 start;
  1161. spin_lock(&adapter->ahw.mem_lock);
  1162. ret = adapter->pci_set_window(adapter, off, &start);
  1163. if (ret != 0)
  1164. goto unlock;
  1165. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  1166. addr = adapter->ahw.pci_base0 + start;
  1167. } else {
  1168. addr = pci_base_offset(adapter, start);
  1169. if (addr)
  1170. goto noremap;
  1171. mem_base = pci_resource_start(adapter->pdev, 0) +
  1172. (start & PAGE_MASK);
  1173. mem_ptr = ioremap(mem_base, PAGE_SIZE);
  1174. if (mem_ptr == NULL) {
  1175. ret = -EIO;
  1176. goto unlock;
  1177. }
  1178. addr = mem_ptr + (start & (PAGE_SIZE-1));
  1179. }
  1180. noremap:
  1181. if (op == 0) /* read */
  1182. *data = readq(addr);
  1183. else /* write */
  1184. writeq(*data, addr);
  1185. unlock:
  1186. spin_unlock(&adapter->ahw.mem_lock);
  1187. if (mem_ptr)
  1188. iounmap(mem_ptr);
  1189. return ret;
  1190. }
  1191. void
  1192. netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data)
  1193. {
  1194. void __iomem *addr = adapter->ahw.pci_base0 +
  1195. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1196. spin_lock(&adapter->ahw.mem_lock);
  1197. *data = readq(addr);
  1198. spin_unlock(&adapter->ahw.mem_lock);
  1199. }
  1200. void
  1201. netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data)
  1202. {
  1203. void __iomem *addr = adapter->ahw.pci_base0 +
  1204. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1205. spin_lock(&adapter->ahw.mem_lock);
  1206. writeq(data, addr);
  1207. spin_unlock(&adapter->ahw.mem_lock);
  1208. }
  1209. #define MAX_CTL_CHECK 1000
  1210. static int
  1211. netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
  1212. u64 off, u64 data)
  1213. {
  1214. int j, ret;
  1215. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1216. void __iomem *mem_crb;
  1217. /* Only 64-bit aligned access */
  1218. if (off & 7)
  1219. return -EIO;
  1220. /* P2 has different SIU and MIU test agent base addr */
  1221. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1222. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1223. mem_crb = pci_base_offset(adapter,
  1224. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1225. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1226. data_lo = SIU_TEST_AGT_WRDATA_LO;
  1227. data_hi = SIU_TEST_AGT_WRDATA_HI;
  1228. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1229. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1230. goto correct;
  1231. }
  1232. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1233. mem_crb = pci_base_offset(adapter,
  1234. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1235. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1236. data_lo = MIU_TEST_AGT_WRDATA_LO;
  1237. data_hi = MIU_TEST_AGT_WRDATA_HI;
  1238. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1239. off_hi = 0;
  1240. goto correct;
  1241. }
  1242. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1243. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1244. if (adapter->ahw.pci_len0 != 0) {
  1245. return netxen_nic_pci_mem_access_direct(adapter,
  1246. off, &data, 1);
  1247. }
  1248. }
  1249. return -EIO;
  1250. correct:
  1251. spin_lock(&adapter->ahw.mem_lock);
  1252. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1253. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1254. writel(off_hi, (mem_crb + addr_hi));
  1255. writel(data & 0xffffffff, (mem_crb + data_lo));
  1256. writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
  1257. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1258. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1259. (mem_crb + TEST_AGT_CTRL));
  1260. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1261. temp = readl((mem_crb + TEST_AGT_CTRL));
  1262. if ((temp & TA_CTL_BUSY) == 0)
  1263. break;
  1264. }
  1265. if (j >= MAX_CTL_CHECK) {
  1266. if (printk_ratelimit())
  1267. dev_err(&adapter->pdev->dev,
  1268. "failed to write through agent\n");
  1269. ret = -EIO;
  1270. } else
  1271. ret = 0;
  1272. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1273. spin_unlock(&adapter->ahw.mem_lock);
  1274. return ret;
  1275. }
  1276. static int
  1277. netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
  1278. u64 off, u64 *data)
  1279. {
  1280. int j, ret;
  1281. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1282. u64 val;
  1283. void __iomem *mem_crb;
  1284. /* Only 64-bit aligned access */
  1285. if (off & 7)
  1286. return -EIO;
  1287. /* P2 has different SIU and MIU test agent base addr */
  1288. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1289. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1290. mem_crb = pci_base_offset(adapter,
  1291. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1292. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1293. data_lo = SIU_TEST_AGT_RDDATA_LO;
  1294. data_hi = SIU_TEST_AGT_RDDATA_HI;
  1295. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1296. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1297. goto correct;
  1298. }
  1299. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1300. mem_crb = pci_base_offset(adapter,
  1301. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1302. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1303. data_lo = MIU_TEST_AGT_RDDATA_LO;
  1304. data_hi = MIU_TEST_AGT_RDDATA_HI;
  1305. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1306. off_hi = 0;
  1307. goto correct;
  1308. }
  1309. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1310. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1311. if (adapter->ahw.pci_len0 != 0) {
  1312. return netxen_nic_pci_mem_access_direct(adapter,
  1313. off, data, 0);
  1314. }
  1315. }
  1316. return -EIO;
  1317. correct:
  1318. spin_lock(&adapter->ahw.mem_lock);
  1319. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1320. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1321. writel(off_hi, (mem_crb + addr_hi));
  1322. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1323. writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1324. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1325. temp = readl(mem_crb + TEST_AGT_CTRL);
  1326. if ((temp & TA_CTL_BUSY) == 0)
  1327. break;
  1328. }
  1329. if (j >= MAX_CTL_CHECK) {
  1330. if (printk_ratelimit())
  1331. dev_err(&adapter->pdev->dev,
  1332. "failed to read through agent\n");
  1333. ret = -EIO;
  1334. } else {
  1335. temp = readl(mem_crb + data_hi);
  1336. val = ((u64)temp << 32);
  1337. val |= readl(mem_crb + data_lo);
  1338. *data = val;
  1339. ret = 0;
  1340. }
  1341. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1342. spin_unlock(&adapter->ahw.mem_lock);
  1343. return ret;
  1344. }
  1345. static int
  1346. netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
  1347. u64 off, u64 data)
  1348. {
  1349. int j, ret;
  1350. u32 temp, off8;
  1351. void __iomem *mem_crb;
  1352. /* Only 64-bit aligned access */
  1353. if (off & 7)
  1354. return -EIO;
  1355. /* P3 onward, test agent base for MIU and SIU is same */
  1356. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1357. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1358. mem_crb = netxen_get_ioaddr(adapter,
  1359. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1360. goto correct;
  1361. }
  1362. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1363. mem_crb = netxen_get_ioaddr(adapter,
  1364. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1365. goto correct;
  1366. }
  1367. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
  1368. return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
  1369. return -EIO;
  1370. correct:
  1371. off8 = off & 0xfffffff8;
  1372. spin_lock(&adapter->ahw.mem_lock);
  1373. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1374. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1375. writel(data & 0xffffffff,
  1376. mem_crb + MIU_TEST_AGT_WRDATA_LO);
  1377. writel((data >> 32) & 0xffffffff,
  1378. mem_crb + MIU_TEST_AGT_WRDATA_HI);
  1379. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1380. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1381. (mem_crb + TEST_AGT_CTRL));
  1382. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1383. temp = readl(mem_crb + TEST_AGT_CTRL);
  1384. if ((temp & TA_CTL_BUSY) == 0)
  1385. break;
  1386. }
  1387. if (j >= MAX_CTL_CHECK) {
  1388. if (printk_ratelimit())
  1389. dev_err(&adapter->pdev->dev,
  1390. "failed to write through agent\n");
  1391. ret = -EIO;
  1392. } else
  1393. ret = 0;
  1394. spin_unlock(&adapter->ahw.mem_lock);
  1395. return ret;
  1396. }
  1397. static int
  1398. netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
  1399. u64 off, u64 *data)
  1400. {
  1401. int j, ret;
  1402. u32 temp, off8;
  1403. u64 val;
  1404. void __iomem *mem_crb;
  1405. /* Only 64-bit aligned access */
  1406. if (off & 7)
  1407. return -EIO;
  1408. /* P3 onward, test agent base for MIU and SIU is same */
  1409. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1410. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1411. mem_crb = netxen_get_ioaddr(adapter,
  1412. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1413. goto correct;
  1414. }
  1415. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1416. mem_crb = netxen_get_ioaddr(adapter,
  1417. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1418. goto correct;
  1419. }
  1420. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1421. return netxen_nic_pci_mem_access_direct(adapter,
  1422. off, data, 0);
  1423. }
  1424. return -EIO;
  1425. correct:
  1426. off8 = off & 0xfffffff8;
  1427. spin_lock(&adapter->ahw.mem_lock);
  1428. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1429. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1430. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1431. writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1432. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1433. temp = readl(mem_crb + TEST_AGT_CTRL);
  1434. if ((temp & TA_CTL_BUSY) == 0)
  1435. break;
  1436. }
  1437. if (j >= MAX_CTL_CHECK) {
  1438. if (printk_ratelimit())
  1439. dev_err(&adapter->pdev->dev,
  1440. "failed to read through agent\n");
  1441. ret = -EIO;
  1442. } else {
  1443. val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32;
  1444. val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO);
  1445. *data = val;
  1446. ret = 0;
  1447. }
  1448. spin_unlock(&adapter->ahw.mem_lock);
  1449. return ret;
  1450. }
  1451. void
  1452. netxen_setup_hwops(struct netxen_adapter *adapter)
  1453. {
  1454. adapter->init_port = netxen_niu_xg_init_port;
  1455. adapter->stop_port = netxen_niu_disable_xg_port;
  1456. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1457. adapter->crb_read = netxen_nic_hw_read_wx_128M,
  1458. adapter->crb_write = netxen_nic_hw_write_wx_128M,
  1459. adapter->pci_set_window = netxen_nic_pci_set_window_128M,
  1460. adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
  1461. adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
  1462. adapter->io_read = netxen_nic_io_read_128M,
  1463. adapter->io_write = netxen_nic_io_write_128M,
  1464. adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
  1465. adapter->set_multi = netxen_p2_nic_set_multi;
  1466. adapter->set_mtu = netxen_nic_set_mtu_xgb;
  1467. adapter->set_promisc = netxen_p2_nic_set_promisc;
  1468. } else {
  1469. adapter->crb_read = netxen_nic_hw_read_wx_2M,
  1470. adapter->crb_write = netxen_nic_hw_write_wx_2M,
  1471. adapter->pci_set_window = netxen_nic_pci_set_window_2M,
  1472. adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
  1473. adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
  1474. adapter->io_read = netxen_nic_io_read_2M,
  1475. adapter->io_write = netxen_nic_io_write_2M,
  1476. adapter->set_mtu = nx_fw_cmd_set_mtu;
  1477. adapter->set_promisc = netxen_p3_nic_set_promisc;
  1478. adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
  1479. adapter->set_multi = netxen_p3_nic_set_multi;
  1480. adapter->phy_read = nx_fw_cmd_query_phy;
  1481. adapter->phy_write = nx_fw_cmd_set_phy;
  1482. }
  1483. }
  1484. int netxen_nic_get_board_info(struct netxen_adapter *adapter)
  1485. {
  1486. int offset, board_type, magic;
  1487. struct pci_dev *pdev = adapter->pdev;
  1488. offset = NX_FW_MAGIC_OFFSET;
  1489. if (netxen_rom_fast_read(adapter, offset, &magic))
  1490. return -EIO;
  1491. if (magic != NETXEN_BDINFO_MAGIC) {
  1492. dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
  1493. magic);
  1494. return -EIO;
  1495. }
  1496. offset = NX_BRDTYPE_OFFSET;
  1497. if (netxen_rom_fast_read(adapter, offset, &board_type))
  1498. return -EIO;
  1499. if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
  1500. u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
  1501. if ((gpio & 0x8000) == 0)
  1502. board_type = NETXEN_BRDTYPE_P3_10G_TP;
  1503. }
  1504. adapter->ahw.board_type = board_type;
  1505. switch (board_type) {
  1506. case NETXEN_BRDTYPE_P2_SB35_4G:
  1507. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1508. break;
  1509. case NETXEN_BRDTYPE_P2_SB31_10G:
  1510. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  1511. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  1512. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  1513. case NETXEN_BRDTYPE_P3_HMEZ:
  1514. case NETXEN_BRDTYPE_P3_XG_LOM:
  1515. case NETXEN_BRDTYPE_P3_10G_CX4:
  1516. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  1517. case NETXEN_BRDTYPE_P3_IMEZ:
  1518. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  1519. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  1520. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  1521. case NETXEN_BRDTYPE_P3_10G_XFP:
  1522. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  1523. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1524. break;
  1525. case NETXEN_BRDTYPE_P1_BD:
  1526. case NETXEN_BRDTYPE_P1_SB:
  1527. case NETXEN_BRDTYPE_P1_SMAX:
  1528. case NETXEN_BRDTYPE_P1_SOCK:
  1529. case NETXEN_BRDTYPE_P3_REF_QG:
  1530. case NETXEN_BRDTYPE_P3_4_GB:
  1531. case NETXEN_BRDTYPE_P3_4_GB_MM:
  1532. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1533. break;
  1534. case NETXEN_BRDTYPE_P3_10G_TP:
  1535. adapter->ahw.port_type = (adapter->portnum < 2) ?
  1536. NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
  1537. break;
  1538. default:
  1539. dev_err(&pdev->dev, "unknown board type %x\n", board_type);
  1540. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1541. break;
  1542. }
  1543. return 0;
  1544. }
  1545. /* NIU access sections */
  1546. static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
  1547. {
  1548. new_mtu += MTU_FUDGE_FACTOR;
  1549. if (adapter->physical_port == 0)
  1550. NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
  1551. else
  1552. NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
  1553. return 0;
  1554. }
  1555. void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
  1556. {
  1557. __u32 status;
  1558. __u32 autoneg;
  1559. __u32 port_mode;
  1560. if (!netif_carrier_ok(adapter->netdev)) {
  1561. adapter->link_speed = 0;
  1562. adapter->link_duplex = -1;
  1563. adapter->link_autoneg = AUTONEG_ENABLE;
  1564. return;
  1565. }
  1566. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  1567. port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
  1568. if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
  1569. adapter->link_speed = SPEED_1000;
  1570. adapter->link_duplex = DUPLEX_FULL;
  1571. adapter->link_autoneg = AUTONEG_DISABLE;
  1572. return;
  1573. }
  1574. if (adapter->phy_read &&
  1575. adapter->phy_read(adapter,
  1576. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  1577. &status) == 0) {
  1578. if (netxen_get_phy_link(status)) {
  1579. switch (netxen_get_phy_speed(status)) {
  1580. case 0:
  1581. adapter->link_speed = SPEED_10;
  1582. break;
  1583. case 1:
  1584. adapter->link_speed = SPEED_100;
  1585. break;
  1586. case 2:
  1587. adapter->link_speed = SPEED_1000;
  1588. break;
  1589. default:
  1590. adapter->link_speed = 0;
  1591. break;
  1592. }
  1593. switch (netxen_get_phy_duplex(status)) {
  1594. case 0:
  1595. adapter->link_duplex = DUPLEX_HALF;
  1596. break;
  1597. case 1:
  1598. adapter->link_duplex = DUPLEX_FULL;
  1599. break;
  1600. default:
  1601. adapter->link_duplex = -1;
  1602. break;
  1603. }
  1604. if (adapter->phy_read &&
  1605. adapter->phy_read(adapter,
  1606. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  1607. &autoneg) == 0)
  1608. adapter->link_autoneg = autoneg;
  1609. } else
  1610. goto link_down;
  1611. } else {
  1612. link_down:
  1613. adapter->link_speed = 0;
  1614. adapter->link_duplex = -1;
  1615. }
  1616. }
  1617. }
  1618. int
  1619. netxen_nic_wol_supported(struct netxen_adapter *adapter)
  1620. {
  1621. u32 wol_cfg;
  1622. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  1623. return 0;
  1624. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  1625. if (wol_cfg & (1UL << adapter->portnum)) {
  1626. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  1627. if (wol_cfg & (1 << adapter->portnum))
  1628. return 1;
  1629. }
  1630. return 0;
  1631. }
  1632. static u32 netxen_md_cntrl(struct netxen_adapter *adapter,
  1633. struct netxen_minidump_template_hdr *template_hdr,
  1634. struct netxen_minidump_entry_crb *crtEntry)
  1635. {
  1636. int loop_cnt, i, rv = 0, timeout_flag;
  1637. u32 op_count, stride;
  1638. u32 opcode, read_value, addr;
  1639. unsigned long timeout, timeout_jiffies;
  1640. addr = crtEntry->addr;
  1641. op_count = crtEntry->op_count;
  1642. stride = crtEntry->addr_stride;
  1643. for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) {
  1644. for (i = 0; i < sizeof(crtEntry->opcode) * 8; i++) {
  1645. opcode = (crtEntry->opcode & (0x1 << i));
  1646. if (opcode) {
  1647. switch (opcode) {
  1648. case NX_DUMP_WCRB:
  1649. NX_WR_DUMP_REG(addr,
  1650. adapter->ahw.pci_base0,
  1651. crtEntry->value_1);
  1652. break;
  1653. case NX_DUMP_RWCRB:
  1654. NX_RD_DUMP_REG(addr,
  1655. adapter->ahw.pci_base0,
  1656. &read_value);
  1657. NX_WR_DUMP_REG(addr,
  1658. adapter->ahw.pci_base0,
  1659. read_value);
  1660. break;
  1661. case NX_DUMP_ANDCRB:
  1662. NX_RD_DUMP_REG(addr,
  1663. adapter->ahw.pci_base0,
  1664. &read_value);
  1665. read_value &= crtEntry->value_2;
  1666. NX_WR_DUMP_REG(addr,
  1667. adapter->ahw.pci_base0,
  1668. read_value);
  1669. break;
  1670. case NX_DUMP_ORCRB:
  1671. NX_RD_DUMP_REG(addr,
  1672. adapter->ahw.pci_base0,
  1673. &read_value);
  1674. read_value |= crtEntry->value_3;
  1675. NX_WR_DUMP_REG(addr,
  1676. adapter->ahw.pci_base0,
  1677. read_value);
  1678. break;
  1679. case NX_DUMP_POLLCRB:
  1680. timeout = crtEntry->poll_timeout;
  1681. NX_RD_DUMP_REG(addr,
  1682. adapter->ahw.pci_base0,
  1683. &read_value);
  1684. timeout_jiffies =
  1685. msecs_to_jiffies(timeout) + jiffies;
  1686. for (timeout_flag = 0;
  1687. !timeout_flag
  1688. && ((read_value & crtEntry->value_2)
  1689. != crtEntry->value_1);) {
  1690. if (time_after(jiffies,
  1691. timeout_jiffies))
  1692. timeout_flag = 1;
  1693. NX_RD_DUMP_REG(addr,
  1694. adapter->ahw.pci_base0,
  1695. &read_value);
  1696. }
  1697. if (timeout_flag) {
  1698. dev_err(&adapter->pdev->dev, "%s : "
  1699. "Timeout in poll_crb control operation.\n"
  1700. , __func__);
  1701. return -1;
  1702. }
  1703. break;
  1704. case NX_DUMP_RD_SAVE:
  1705. /* Decide which address to use */
  1706. if (crtEntry->state_index_a)
  1707. addr =
  1708. template_hdr->saved_state_array
  1709. [crtEntry->state_index_a];
  1710. NX_RD_DUMP_REG(addr,
  1711. adapter->ahw.pci_base0,
  1712. &read_value);
  1713. template_hdr->saved_state_array
  1714. [crtEntry->state_index_v]
  1715. = read_value;
  1716. break;
  1717. case NX_DUMP_WRT_SAVED:
  1718. /* Decide which value to use */
  1719. if (crtEntry->state_index_v)
  1720. read_value =
  1721. template_hdr->saved_state_array
  1722. [crtEntry->state_index_v];
  1723. else
  1724. read_value = crtEntry->value_1;
  1725. /* Decide which address to use */
  1726. if (crtEntry->state_index_a)
  1727. addr =
  1728. template_hdr->saved_state_array
  1729. [crtEntry->state_index_a];
  1730. NX_WR_DUMP_REG(addr,
  1731. adapter->ahw.pci_base0,
  1732. read_value);
  1733. break;
  1734. case NX_DUMP_MOD_SAVE_ST:
  1735. read_value =
  1736. template_hdr->saved_state_array
  1737. [crtEntry->state_index_v];
  1738. read_value <<= crtEntry->shl;
  1739. read_value >>= crtEntry->shr;
  1740. if (crtEntry->value_2)
  1741. read_value &=
  1742. crtEntry->value_2;
  1743. read_value |= crtEntry->value_3;
  1744. read_value += crtEntry->value_1;
  1745. /* Write value back to state area.*/
  1746. template_hdr->saved_state_array
  1747. [crtEntry->state_index_v]
  1748. = read_value;
  1749. break;
  1750. default:
  1751. rv = 1;
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. addr = addr + stride;
  1757. }
  1758. return rv;
  1759. }
  1760. /* Read memory or MN */
  1761. static u32
  1762. netxen_md_rdmem(struct netxen_adapter *adapter,
  1763. struct netxen_minidump_entry_rdmem
  1764. *memEntry, u64 *data_buff)
  1765. {
  1766. u64 addr, value = 0;
  1767. int i = 0, loop_cnt;
  1768. addr = (u64)memEntry->read_addr;
  1769. loop_cnt = memEntry->read_data_size; /* This is size in bytes */
  1770. loop_cnt /= sizeof(value);
  1771. for (i = 0; i < loop_cnt; i++) {
  1772. if (netxen_nic_pci_mem_read_2M(adapter, addr, &value))
  1773. goto out;
  1774. *data_buff++ = value;
  1775. addr += sizeof(value);
  1776. }
  1777. out:
  1778. return i * sizeof(value);
  1779. }
  1780. /* Read CRB operation */
  1781. static u32 netxen_md_rd_crb(struct netxen_adapter *adapter,
  1782. struct netxen_minidump_entry_crb
  1783. *crbEntry, u32 *data_buff)
  1784. {
  1785. int loop_cnt;
  1786. u32 op_count, addr, stride, value;
  1787. addr = crbEntry->addr;
  1788. op_count = crbEntry->op_count;
  1789. stride = crbEntry->addr_stride;
  1790. for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) {
  1791. NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0, &value);
  1792. *data_buff++ = addr;
  1793. *data_buff++ = value;
  1794. addr = addr + stride;
  1795. }
  1796. return loop_cnt * (2 * sizeof(u32));
  1797. }
  1798. /* Read ROM */
  1799. static u32
  1800. netxen_md_rdrom(struct netxen_adapter *adapter,
  1801. struct netxen_minidump_entry_rdrom
  1802. *romEntry, __le32 *data_buff)
  1803. {
  1804. int i, count = 0;
  1805. u32 size, lck_val;
  1806. u32 val;
  1807. u32 fl_addr, waddr, raddr;
  1808. fl_addr = romEntry->read_addr;
  1809. size = romEntry->read_data_size/4;
  1810. lock_try:
  1811. lck_val = readl((void __iomem *)(adapter->ahw.pci_base0 +
  1812. NX_FLASH_SEM2_LK));
  1813. if (!lck_val && count < MAX_CTL_CHECK) {
  1814. msleep(20);
  1815. count++;
  1816. goto lock_try;
  1817. }
  1818. writel(adapter->ahw.pci_func, (void __iomem *)(adapter->ahw.pci_base0 +
  1819. NX_FLASH_LOCK_ID));
  1820. for (i = 0; i < size; i++) {
  1821. waddr = fl_addr & 0xFFFF0000;
  1822. NX_WR_DUMP_REG(FLASH_ROM_WINDOW, adapter->ahw.pci_base0, waddr);
  1823. raddr = FLASH_ROM_DATA + (fl_addr & 0x0000FFFF);
  1824. NX_RD_DUMP_REG(raddr, adapter->ahw.pci_base0, &val);
  1825. *data_buff++ = cpu_to_le32(val);
  1826. fl_addr += sizeof(val);
  1827. }
  1828. readl((void __iomem *)(adapter->ahw.pci_base0 + NX_FLASH_SEM2_ULK));
  1829. return romEntry->read_data_size;
  1830. }
  1831. /* Handle L2 Cache */
  1832. static u32
  1833. netxen_md_L2Cache(struct netxen_adapter *adapter,
  1834. struct netxen_minidump_entry_cache
  1835. *cacheEntry, u32 *data_buff)
  1836. {
  1837. int loop_cnt, i, k, timeout_flag = 0;
  1838. u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr;
  1839. u32 tag_value, read_cnt;
  1840. u8 cntl_value_w, cntl_value_r;
  1841. unsigned long timeout, timeout_jiffies;
  1842. loop_cnt = cacheEntry->op_count;
  1843. read_addr = cacheEntry->read_addr;
  1844. cntrl_addr = cacheEntry->control_addr;
  1845. cntl_value_w = (u32) cacheEntry->write_value;
  1846. tag_reg_addr = cacheEntry->tag_reg_addr;
  1847. tag_value = cacheEntry->init_tag_value;
  1848. read_cnt = cacheEntry->read_addr_cnt;
  1849. for (i = 0; i < loop_cnt; i++) {
  1850. NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value);
  1851. if (cntl_value_w)
  1852. NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1853. (u32)cntl_value_w);
  1854. if (cacheEntry->poll_mask) {
  1855. timeout = cacheEntry->poll_wait;
  1856. NX_RD_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1857. &cntl_value_r);
  1858. timeout_jiffies = msecs_to_jiffies(timeout) + jiffies;
  1859. for (timeout_flag = 0; !timeout_flag &&
  1860. ((cntl_value_r & cacheEntry->poll_mask) != 0);) {
  1861. if (time_after(jiffies, timeout_jiffies))
  1862. timeout_flag = 1;
  1863. NX_RD_DUMP_REG(cntrl_addr,
  1864. adapter->ahw.pci_base0,
  1865. &cntl_value_r);
  1866. }
  1867. if (timeout_flag) {
  1868. dev_err(&adapter->pdev->dev,
  1869. "Timeout in processing L2 Tag poll.\n");
  1870. return -1;
  1871. }
  1872. }
  1873. addr = read_addr;
  1874. for (k = 0; k < read_cnt; k++) {
  1875. NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0,
  1876. &read_value);
  1877. *data_buff++ = read_value;
  1878. addr += cacheEntry->read_addr_stride;
  1879. }
  1880. tag_value += cacheEntry->tag_value_stride;
  1881. }
  1882. return read_cnt * loop_cnt * sizeof(read_value);
  1883. }
  1884. /* Handle L1 Cache */
  1885. static u32 netxen_md_L1Cache(struct netxen_adapter *adapter,
  1886. struct netxen_minidump_entry_cache
  1887. *cacheEntry, u32 *data_buff)
  1888. {
  1889. int i, k, loop_cnt;
  1890. u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr;
  1891. u32 tag_value, read_cnt;
  1892. u8 cntl_value_w;
  1893. loop_cnt = cacheEntry->op_count;
  1894. read_addr = cacheEntry->read_addr;
  1895. cntrl_addr = cacheEntry->control_addr;
  1896. cntl_value_w = (u32) cacheEntry->write_value;
  1897. tag_reg_addr = cacheEntry->tag_reg_addr;
  1898. tag_value = cacheEntry->init_tag_value;
  1899. read_cnt = cacheEntry->read_addr_cnt;
  1900. for (i = 0; i < loop_cnt; i++) {
  1901. NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value);
  1902. NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1903. (u32) cntl_value_w);
  1904. addr = read_addr;
  1905. for (k = 0; k < read_cnt; k++) {
  1906. NX_RD_DUMP_REG(addr,
  1907. adapter->ahw.pci_base0,
  1908. &read_value);
  1909. *data_buff++ = read_value;
  1910. addr += cacheEntry->read_addr_stride;
  1911. }
  1912. tag_value += cacheEntry->tag_value_stride;
  1913. }
  1914. return read_cnt * loop_cnt * sizeof(read_value);
  1915. }
  1916. /* Reading OCM memory */
  1917. static u32
  1918. netxen_md_rdocm(struct netxen_adapter *adapter,
  1919. struct netxen_minidump_entry_rdocm
  1920. *ocmEntry, u32 *data_buff)
  1921. {
  1922. int i, loop_cnt;
  1923. u32 value;
  1924. void __iomem *addr;
  1925. addr = (ocmEntry->read_addr + adapter->ahw.pci_base0);
  1926. loop_cnt = ocmEntry->op_count;
  1927. for (i = 0; i < loop_cnt; i++) {
  1928. value = readl(addr);
  1929. *data_buff++ = value;
  1930. addr += ocmEntry->read_addr_stride;
  1931. }
  1932. return i * sizeof(u32);
  1933. }
  1934. /* Read MUX data */
  1935. static u32
  1936. netxen_md_rdmux(struct netxen_adapter *adapter, struct netxen_minidump_entry_mux
  1937. *muxEntry, u32 *data_buff)
  1938. {
  1939. int loop_cnt = 0;
  1940. u32 read_addr, read_value, select_addr, sel_value;
  1941. read_addr = muxEntry->read_addr;
  1942. sel_value = muxEntry->select_value;
  1943. select_addr = muxEntry->select_addr;
  1944. for (loop_cnt = 0; loop_cnt < muxEntry->op_count; loop_cnt++) {
  1945. NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, sel_value);
  1946. NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0, &read_value);
  1947. *data_buff++ = sel_value;
  1948. *data_buff++ = read_value;
  1949. sel_value += muxEntry->select_value_stride;
  1950. }
  1951. return loop_cnt * (2 * sizeof(u32));
  1952. }
  1953. /* Handling Queue State Reads */
  1954. static u32
  1955. netxen_md_rdqueue(struct netxen_adapter *adapter,
  1956. struct netxen_minidump_entry_queue
  1957. *queueEntry, u32 *data_buff)
  1958. {
  1959. int loop_cnt, k;
  1960. u32 queue_id, read_addr, read_value, read_stride, select_addr, read_cnt;
  1961. read_cnt = queueEntry->read_addr_cnt;
  1962. read_stride = queueEntry->read_addr_stride;
  1963. select_addr = queueEntry->select_addr;
  1964. for (loop_cnt = 0, queue_id = 0; loop_cnt < queueEntry->op_count;
  1965. loop_cnt++) {
  1966. NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, queue_id);
  1967. read_addr = queueEntry->read_addr;
  1968. for (k = 0; k < read_cnt; k--) {
  1969. NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0,
  1970. &read_value);
  1971. *data_buff++ = read_value;
  1972. read_addr += read_stride;
  1973. }
  1974. queue_id += queueEntry->queue_id_stride;
  1975. }
  1976. return loop_cnt * (read_cnt * sizeof(read_value));
  1977. }
  1978. /*
  1979. * We catch an error where driver does not read
  1980. * as much data as we expect from the entry.
  1981. */
  1982. static int netxen_md_entry_err_chk(struct netxen_adapter *adapter,
  1983. struct netxen_minidump_entry *entry, int esize)
  1984. {
  1985. if (esize < 0) {
  1986. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  1987. return esize;
  1988. }
  1989. if (esize != entry->hdr.entry_capture_size) {
  1990. entry->hdr.entry_capture_size = esize;
  1991. entry->hdr.driver_flags |= NX_DUMP_SIZE_ERR;
  1992. dev_info(&adapter->pdev->dev,
  1993. "Invalidate dump, Type:%d\tMask:%d\tSize:%dCap_size:%d\n",
  1994. entry->hdr.entry_type, entry->hdr.entry_capture_mask,
  1995. esize, entry->hdr.entry_capture_size);
  1996. dev_info(&adapter->pdev->dev, "Aborting further dump capture\n");
  1997. }
  1998. return 0;
  1999. }
  2000. static int netxen_parse_md_template(struct netxen_adapter *adapter)
  2001. {
  2002. int num_of_entries, buff_level, e_cnt, esize;
  2003. int end_cnt = 0, rv = 0, sane_start = 0, sane_end = 0;
  2004. char *dbuff;
  2005. void *template_buff = adapter->mdump.md_template;
  2006. char *dump_buff = adapter->mdump.md_capture_buff;
  2007. int capture_mask = adapter->mdump.md_capture_mask;
  2008. struct netxen_minidump_template_hdr *template_hdr;
  2009. struct netxen_minidump_entry *entry;
  2010. if ((capture_mask & 0x3) != 0x3) {
  2011. dev_err(&adapter->pdev->dev, "Capture mask %02x below minimum needed "
  2012. "for valid firmware dump\n", capture_mask);
  2013. return -EINVAL;
  2014. }
  2015. template_hdr = (struct netxen_minidump_template_hdr *) template_buff;
  2016. num_of_entries = template_hdr->num_of_entries;
  2017. entry = (struct netxen_minidump_entry *) ((char *) template_buff +
  2018. template_hdr->first_entry_offset);
  2019. memcpy(dump_buff, template_buff, adapter->mdump.md_template_size);
  2020. dump_buff = dump_buff + adapter->mdump.md_template_size;
  2021. if (template_hdr->entry_type == TLHDR)
  2022. sane_start = 1;
  2023. for (e_cnt = 0, buff_level = 0; e_cnt < num_of_entries; e_cnt++) {
  2024. if (!(entry->hdr.entry_capture_mask & capture_mask)) {
  2025. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2026. entry = (struct netxen_minidump_entry *)
  2027. ((char *) entry + entry->hdr.entry_size);
  2028. continue;
  2029. }
  2030. switch (entry->hdr.entry_type) {
  2031. case RDNOP:
  2032. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2033. break;
  2034. case RDEND:
  2035. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2036. if (!sane_end)
  2037. end_cnt = e_cnt;
  2038. sane_end += 1;
  2039. break;
  2040. case CNTRL:
  2041. rv = netxen_md_cntrl(adapter,
  2042. template_hdr, (void *)entry);
  2043. if (rv)
  2044. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2045. break;
  2046. case RDCRB:
  2047. dbuff = dump_buff + buff_level;
  2048. esize = netxen_md_rd_crb(adapter,
  2049. (void *) entry, (void *) dbuff);
  2050. rv = netxen_md_entry_err_chk
  2051. (adapter, entry, esize);
  2052. if (rv < 0)
  2053. break;
  2054. buff_level += esize;
  2055. break;
  2056. case RDMN:
  2057. case RDMEM:
  2058. dbuff = dump_buff + buff_level;
  2059. esize = netxen_md_rdmem(adapter,
  2060. (void *) entry, (void *) dbuff);
  2061. rv = netxen_md_entry_err_chk
  2062. (adapter, entry, esize);
  2063. if (rv < 0)
  2064. break;
  2065. buff_level += esize;
  2066. break;
  2067. case BOARD:
  2068. case RDROM:
  2069. dbuff = dump_buff + buff_level;
  2070. esize = netxen_md_rdrom(adapter,
  2071. (void *) entry, (void *) dbuff);
  2072. rv = netxen_md_entry_err_chk
  2073. (adapter, entry, esize);
  2074. if (rv < 0)
  2075. break;
  2076. buff_level += esize;
  2077. break;
  2078. case L2ITG:
  2079. case L2DTG:
  2080. case L2DAT:
  2081. case L2INS:
  2082. dbuff = dump_buff + buff_level;
  2083. esize = netxen_md_L2Cache(adapter,
  2084. (void *) entry, (void *) dbuff);
  2085. rv = netxen_md_entry_err_chk
  2086. (adapter, entry, esize);
  2087. if (rv < 0)
  2088. break;
  2089. buff_level += esize;
  2090. break;
  2091. case L1DAT:
  2092. case L1INS:
  2093. dbuff = dump_buff + buff_level;
  2094. esize = netxen_md_L1Cache(adapter,
  2095. (void *) entry, (void *) dbuff);
  2096. rv = netxen_md_entry_err_chk
  2097. (adapter, entry, esize);
  2098. if (rv < 0)
  2099. break;
  2100. buff_level += esize;
  2101. break;
  2102. case RDOCM:
  2103. dbuff = dump_buff + buff_level;
  2104. esize = netxen_md_rdocm(adapter,
  2105. (void *) entry, (void *) dbuff);
  2106. rv = netxen_md_entry_err_chk
  2107. (adapter, entry, esize);
  2108. if (rv < 0)
  2109. break;
  2110. buff_level += esize;
  2111. break;
  2112. case RDMUX:
  2113. dbuff = dump_buff + buff_level;
  2114. esize = netxen_md_rdmux(adapter,
  2115. (void *) entry, (void *) dbuff);
  2116. rv = netxen_md_entry_err_chk
  2117. (adapter, entry, esize);
  2118. if (rv < 0)
  2119. break;
  2120. buff_level += esize;
  2121. break;
  2122. case QUEUE:
  2123. dbuff = dump_buff + buff_level;
  2124. esize = netxen_md_rdqueue(adapter,
  2125. (void *) entry, (void *) dbuff);
  2126. rv = netxen_md_entry_err_chk
  2127. (adapter, entry, esize);
  2128. if (rv < 0)
  2129. break;
  2130. buff_level += esize;
  2131. break;
  2132. default:
  2133. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2134. break;
  2135. }
  2136. /* Next entry in the template */
  2137. entry = (struct netxen_minidump_entry *)
  2138. ((char *) entry + entry->hdr.entry_size);
  2139. }
  2140. if (!sane_start || sane_end > 1) {
  2141. dev_err(&adapter->pdev->dev,
  2142. "Firmware minidump template configuration error.\n");
  2143. }
  2144. return 0;
  2145. }
  2146. static int
  2147. netxen_collect_minidump(struct netxen_adapter *adapter)
  2148. {
  2149. int ret = 0;
  2150. struct netxen_minidump_template_hdr *hdr;
  2151. struct timespec val;
  2152. hdr = (struct netxen_minidump_template_hdr *)
  2153. adapter->mdump.md_template;
  2154. hdr->driver_capture_mask = adapter->mdump.md_capture_mask;
  2155. jiffies_to_timespec(jiffies, &val);
  2156. hdr->driver_timestamp = (u32) val.tv_sec;
  2157. hdr->driver_info_word2 = adapter->fw_version;
  2158. hdr->driver_info_word3 = NXRD32(adapter, CRB_DRIVER_VERSION);
  2159. ret = netxen_parse_md_template(adapter);
  2160. if (ret)
  2161. return ret;
  2162. return ret;
  2163. }
  2164. void
  2165. netxen_dump_fw(struct netxen_adapter *adapter)
  2166. {
  2167. struct netxen_minidump_template_hdr *hdr;
  2168. int i, k, data_size = 0;
  2169. u32 capture_mask;
  2170. hdr = (struct netxen_minidump_template_hdr *)
  2171. adapter->mdump.md_template;
  2172. capture_mask = adapter->mdump.md_capture_mask;
  2173. for (i = 0x2, k = 1; (i & NX_DUMP_MASK_MAX); i <<= 1, k++) {
  2174. if (i & capture_mask)
  2175. data_size += hdr->capture_size_array[k];
  2176. }
  2177. if (!data_size) {
  2178. dev_err(&adapter->pdev->dev,
  2179. "Invalid cap sizes for capture_mask=0x%x\n",
  2180. adapter->mdump.md_capture_mask);
  2181. return;
  2182. }
  2183. adapter->mdump.md_capture_size = data_size;
  2184. adapter->mdump.md_dump_size = adapter->mdump.md_template_size +
  2185. adapter->mdump.md_capture_size;
  2186. if (!adapter->mdump.md_capture_buff) {
  2187. adapter->mdump.md_capture_buff =
  2188. vzalloc(adapter->mdump.md_dump_size);
  2189. if (!adapter->mdump.md_capture_buff)
  2190. return;
  2191. if (netxen_collect_minidump(adapter)) {
  2192. adapter->mdump.has_valid_dump = 0;
  2193. adapter->mdump.md_dump_size = 0;
  2194. vfree(adapter->mdump.md_capture_buff);
  2195. adapter->mdump.md_capture_buff = NULL;
  2196. dev_err(&adapter->pdev->dev,
  2197. "Error in collecting firmware minidump.\n");
  2198. } else {
  2199. adapter->mdump.md_timestamp = jiffies;
  2200. adapter->mdump.has_valid_dump = 1;
  2201. adapter->fw_mdump_rdy = 1;
  2202. dev_info(&adapter->pdev->dev, "%s Successfully "
  2203. "collected fw dump.\n", adapter->netdev->name);
  2204. }
  2205. } else {
  2206. dev_info(&adapter->pdev->dev,
  2207. "Cannot overwrite previously collected "
  2208. "firmware minidump.\n");
  2209. adapter->fw_mdump_rdy = 1;
  2210. return;
  2211. }
  2212. }