netxen_nic_hw.c 66 KB

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