netxen_nic_hw.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594
  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. addr = base;
  837. ptr32 = buf;
  838. for (i = 0; i < size / sizeof(u32); i++) {
  839. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  840. return -1;
  841. *ptr32 = cpu_to_le32(v);
  842. ptr32++;
  843. addr += sizeof(u32);
  844. }
  845. if ((char *)buf + size > (char *)ptr32) {
  846. __le32 local;
  847. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  848. return -1;
  849. local = cpu_to_le32(v);
  850. memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
  851. }
  852. return 0;
  853. }
  854. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  855. {
  856. __le32 *pmac = (__le32 *) mac;
  857. u32 offset;
  858. offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
  859. if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
  860. return -1;
  861. if (*mac == ~0ULL) {
  862. offset = NX_OLD_MAC_ADDR_OFFSET +
  863. (adapter->portnum * sizeof(u64));
  864. if (netxen_get_flash_block(adapter,
  865. offset, sizeof(u64), pmac) == -1)
  866. return -1;
  867. if (*mac == ~0ULL)
  868. return -1;
  869. }
  870. return 0;
  871. }
  872. int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  873. {
  874. uint32_t crbaddr, mac_hi, mac_lo;
  875. int pci_func = adapter->ahw.pci_func;
  876. crbaddr = CRB_MAC_BLOCK_START +
  877. (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
  878. mac_lo = NXRD32(adapter, crbaddr);
  879. mac_hi = NXRD32(adapter, crbaddr+4);
  880. if (pci_func & 1)
  881. *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
  882. else
  883. *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
  884. return 0;
  885. }
  886. /*
  887. * Changes the CRB window to the specified window.
  888. */
  889. static void
  890. netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
  891. u32 window)
  892. {
  893. void __iomem *offset;
  894. int count = 10;
  895. u8 func = adapter->ahw.pci_func;
  896. if (adapter->ahw.crb_win == window)
  897. return;
  898. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  899. NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
  900. writel(window, offset);
  901. do {
  902. if (window == readl(offset))
  903. break;
  904. if (printk_ratelimit())
  905. dev_warn(&adapter->pdev->dev,
  906. "failed to set CRB window to %d\n",
  907. (window == NETXEN_WINDOW_ONE));
  908. udelay(1);
  909. } while (--count > 0);
  910. if (count > 0)
  911. adapter->ahw.crb_win = window;
  912. }
  913. /*
  914. * Returns < 0 if off is not valid,
  915. * 1 if window access is needed. 'off' is set to offset from
  916. * CRB space in 128M pci map
  917. * 0 if no window access is needed. 'off' is set to 2M addr
  918. * In: 'off' is offset from base in 128M pci map
  919. */
  920. static int
  921. netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
  922. ulong off, void __iomem **addr)
  923. {
  924. crb_128M_2M_sub_block_map_t *m;
  925. if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
  926. return -EINVAL;
  927. off -= NETXEN_PCI_CRBSPACE;
  928. /*
  929. * Try direct map
  930. */
  931. m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
  932. if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
  933. *addr = adapter->ahw.pci_base0 + m->start_2M +
  934. (off - m->start_128M);
  935. return 0;
  936. }
  937. /*
  938. * Not in direct map, use crb window
  939. */
  940. *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
  941. (off & MASK(16));
  942. return 1;
  943. }
  944. /*
  945. * In: 'off' is offset from CRB space in 128M pci map
  946. * Out: 'off' is 2M pci map addr
  947. * side effect: lock crb window
  948. */
  949. static void
  950. netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
  951. {
  952. u32 window;
  953. void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
  954. off -= NETXEN_PCI_CRBSPACE;
  955. window = CRB_HI(off);
  956. writel(window, addr);
  957. if (readl(addr) != window) {
  958. if (printk_ratelimit())
  959. dev_warn(&adapter->pdev->dev,
  960. "failed to set CRB window to %d off 0x%lx\n",
  961. window, off);
  962. }
  963. }
  964. static void __iomem *
  965. netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
  966. ulong win_off, void __iomem **mem_ptr)
  967. {
  968. ulong off = win_off;
  969. void __iomem *addr;
  970. resource_size_t mem_base;
  971. if (ADDR_IN_WINDOW1(win_off))
  972. off = NETXEN_CRB_NORMAL(win_off);
  973. addr = pci_base_offset(adapter, off);
  974. if (addr)
  975. return addr;
  976. if (adapter->ahw.pci_len0 == 0)
  977. off -= NETXEN_PCI_CRBSPACE;
  978. mem_base = pci_resource_start(adapter->pdev, 0);
  979. *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
  980. if (*mem_ptr)
  981. addr = *mem_ptr + (off & (PAGE_SIZE - 1));
  982. return addr;
  983. }
  984. static int
  985. netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
  986. {
  987. unsigned long flags;
  988. void __iomem *addr, *mem_ptr = NULL;
  989. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  990. if (!addr)
  991. return -EIO;
  992. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  993. netxen_nic_io_write_128M(adapter, addr, data);
  994. } else { /* Window 0 */
  995. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  996. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  997. writel(data, addr);
  998. netxen_nic_pci_set_crbwindow_128M(adapter,
  999. NETXEN_WINDOW_ONE);
  1000. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1001. }
  1002. if (mem_ptr)
  1003. iounmap(mem_ptr);
  1004. return 0;
  1005. }
  1006. static u32
  1007. netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
  1008. {
  1009. unsigned long flags;
  1010. void __iomem *addr, *mem_ptr = NULL;
  1011. u32 data;
  1012. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  1013. if (!addr)
  1014. return -EIO;
  1015. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  1016. data = netxen_nic_io_read_128M(adapter, addr);
  1017. } else { /* Window 0 */
  1018. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1019. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1020. data = readl(addr);
  1021. netxen_nic_pci_set_crbwindow_128M(adapter,
  1022. NETXEN_WINDOW_ONE);
  1023. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1024. }
  1025. if (mem_ptr)
  1026. iounmap(mem_ptr);
  1027. return data;
  1028. }
  1029. static int
  1030. netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
  1031. {
  1032. unsigned long flags;
  1033. int rv;
  1034. void __iomem *addr = NULL;
  1035. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1036. if (rv == 0) {
  1037. writel(data, addr);
  1038. return 0;
  1039. }
  1040. if (rv > 0) {
  1041. /* indirect access */
  1042. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1043. crb_win_lock(adapter);
  1044. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1045. writel(data, addr);
  1046. crb_win_unlock(adapter);
  1047. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1048. return 0;
  1049. }
  1050. dev_err(&adapter->pdev->dev,
  1051. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1052. dump_stack();
  1053. return -EIO;
  1054. }
  1055. static u32
  1056. netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
  1057. {
  1058. unsigned long flags;
  1059. int rv;
  1060. u32 data;
  1061. void __iomem *addr = NULL;
  1062. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1063. if (rv == 0)
  1064. return readl(addr);
  1065. if (rv > 0) {
  1066. /* indirect access */
  1067. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1068. crb_win_lock(adapter);
  1069. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1070. data = readl(addr);
  1071. crb_win_unlock(adapter);
  1072. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1073. return data;
  1074. }
  1075. dev_err(&adapter->pdev->dev,
  1076. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1077. dump_stack();
  1078. return -1;
  1079. }
  1080. /* window 1 registers only */
  1081. static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
  1082. void __iomem *addr, u32 data)
  1083. {
  1084. read_lock(&adapter->ahw.crb_lock);
  1085. writel(data, addr);
  1086. read_unlock(&adapter->ahw.crb_lock);
  1087. }
  1088. static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
  1089. void __iomem *addr)
  1090. {
  1091. u32 val;
  1092. read_lock(&adapter->ahw.crb_lock);
  1093. val = readl(addr);
  1094. read_unlock(&adapter->ahw.crb_lock);
  1095. return val;
  1096. }
  1097. static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
  1098. void __iomem *addr, u32 data)
  1099. {
  1100. writel(data, addr);
  1101. }
  1102. static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
  1103. void __iomem *addr)
  1104. {
  1105. return readl(addr);
  1106. }
  1107. void __iomem *
  1108. netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
  1109. {
  1110. void __iomem *addr = NULL;
  1111. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1112. if ((offset < NETXEN_CRB_PCIX_HOST2) &&
  1113. (offset > NETXEN_CRB_PCIX_HOST))
  1114. addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
  1115. else
  1116. addr = NETXEN_CRB_NORMALIZE(adapter, offset);
  1117. } else {
  1118. WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
  1119. offset, &addr));
  1120. }
  1121. return addr;
  1122. }
  1123. static int
  1124. netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
  1125. u64 addr, u32 *start)
  1126. {
  1127. if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1128. *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
  1129. return 0;
  1130. } else if (ADDR_IN_RANGE(addr,
  1131. NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1132. *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
  1133. return 0;
  1134. }
  1135. return -EIO;
  1136. }
  1137. static int
  1138. netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
  1139. u64 addr, u32 *start)
  1140. {
  1141. u32 window;
  1142. window = OCM_WIN(addr);
  1143. writel(window, adapter->ahw.ocm_win_crb);
  1144. /* read back to flush */
  1145. readl(adapter->ahw.ocm_win_crb);
  1146. adapter->ahw.ocm_win = window;
  1147. *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
  1148. return 0;
  1149. }
  1150. static int
  1151. netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
  1152. u64 *data, int op)
  1153. {
  1154. void __iomem *addr, *mem_ptr = NULL;
  1155. resource_size_t mem_base;
  1156. int ret;
  1157. u32 start;
  1158. spin_lock(&adapter->ahw.mem_lock);
  1159. ret = adapter->pci_set_window(adapter, off, &start);
  1160. if (ret != 0)
  1161. goto unlock;
  1162. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  1163. addr = adapter->ahw.pci_base0 + start;
  1164. } else {
  1165. addr = pci_base_offset(adapter, start);
  1166. if (addr)
  1167. goto noremap;
  1168. mem_base = pci_resource_start(adapter->pdev, 0) +
  1169. (start & PAGE_MASK);
  1170. mem_ptr = ioremap(mem_base, PAGE_SIZE);
  1171. if (mem_ptr == NULL) {
  1172. ret = -EIO;
  1173. goto unlock;
  1174. }
  1175. addr = mem_ptr + (start & (PAGE_SIZE-1));
  1176. }
  1177. noremap:
  1178. if (op == 0) /* read */
  1179. *data = readq(addr);
  1180. else /* write */
  1181. writeq(*data, addr);
  1182. unlock:
  1183. spin_unlock(&adapter->ahw.mem_lock);
  1184. if (mem_ptr)
  1185. iounmap(mem_ptr);
  1186. return ret;
  1187. }
  1188. void
  1189. netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data)
  1190. {
  1191. void __iomem *addr = adapter->ahw.pci_base0 +
  1192. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1193. spin_lock(&adapter->ahw.mem_lock);
  1194. *data = readq(addr);
  1195. spin_unlock(&adapter->ahw.mem_lock);
  1196. }
  1197. void
  1198. netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data)
  1199. {
  1200. void __iomem *addr = adapter->ahw.pci_base0 +
  1201. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1202. spin_lock(&adapter->ahw.mem_lock);
  1203. writeq(data, addr);
  1204. spin_unlock(&adapter->ahw.mem_lock);
  1205. }
  1206. #define MAX_CTL_CHECK 1000
  1207. static int
  1208. netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
  1209. u64 off, u64 data)
  1210. {
  1211. int j, ret;
  1212. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1213. void __iomem *mem_crb;
  1214. /* Only 64-bit aligned access */
  1215. if (off & 7)
  1216. return -EIO;
  1217. /* P2 has different SIU and MIU test agent base addr */
  1218. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1219. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1220. mem_crb = pci_base_offset(adapter,
  1221. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1222. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1223. data_lo = SIU_TEST_AGT_WRDATA_LO;
  1224. data_hi = SIU_TEST_AGT_WRDATA_HI;
  1225. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1226. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1227. goto correct;
  1228. }
  1229. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1230. mem_crb = pci_base_offset(adapter,
  1231. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1232. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1233. data_lo = MIU_TEST_AGT_WRDATA_LO;
  1234. data_hi = MIU_TEST_AGT_WRDATA_HI;
  1235. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1236. off_hi = 0;
  1237. goto correct;
  1238. }
  1239. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1240. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1241. if (adapter->ahw.pci_len0 != 0) {
  1242. return netxen_nic_pci_mem_access_direct(adapter,
  1243. off, &data, 1);
  1244. }
  1245. }
  1246. return -EIO;
  1247. correct:
  1248. spin_lock(&adapter->ahw.mem_lock);
  1249. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1250. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1251. writel(off_hi, (mem_crb + addr_hi));
  1252. writel(data & 0xffffffff, (mem_crb + data_lo));
  1253. writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
  1254. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1255. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1256. (mem_crb + TEST_AGT_CTRL));
  1257. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1258. temp = readl((mem_crb + TEST_AGT_CTRL));
  1259. if ((temp & TA_CTL_BUSY) == 0)
  1260. break;
  1261. }
  1262. if (j >= MAX_CTL_CHECK) {
  1263. if (printk_ratelimit())
  1264. dev_err(&adapter->pdev->dev,
  1265. "failed to write through agent\n");
  1266. ret = -EIO;
  1267. } else
  1268. ret = 0;
  1269. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1270. spin_unlock(&adapter->ahw.mem_lock);
  1271. return ret;
  1272. }
  1273. static int
  1274. netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
  1275. u64 off, u64 *data)
  1276. {
  1277. int j, ret;
  1278. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1279. u64 val;
  1280. void __iomem *mem_crb;
  1281. /* Only 64-bit aligned access */
  1282. if (off & 7)
  1283. return -EIO;
  1284. /* P2 has different SIU and MIU test agent base addr */
  1285. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1286. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1287. mem_crb = pci_base_offset(adapter,
  1288. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1289. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1290. data_lo = SIU_TEST_AGT_RDDATA_LO;
  1291. data_hi = SIU_TEST_AGT_RDDATA_HI;
  1292. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1293. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1294. goto correct;
  1295. }
  1296. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1297. mem_crb = pci_base_offset(adapter,
  1298. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1299. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1300. data_lo = MIU_TEST_AGT_RDDATA_LO;
  1301. data_hi = MIU_TEST_AGT_RDDATA_HI;
  1302. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1303. off_hi = 0;
  1304. goto correct;
  1305. }
  1306. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1307. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1308. if (adapter->ahw.pci_len0 != 0) {
  1309. return netxen_nic_pci_mem_access_direct(adapter,
  1310. off, data, 0);
  1311. }
  1312. }
  1313. return -EIO;
  1314. correct:
  1315. spin_lock(&adapter->ahw.mem_lock);
  1316. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1317. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1318. writel(off_hi, (mem_crb + addr_hi));
  1319. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1320. writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1321. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1322. temp = readl(mem_crb + TEST_AGT_CTRL);
  1323. if ((temp & TA_CTL_BUSY) == 0)
  1324. break;
  1325. }
  1326. if (j >= MAX_CTL_CHECK) {
  1327. if (printk_ratelimit())
  1328. dev_err(&adapter->pdev->dev,
  1329. "failed to read through agent\n");
  1330. ret = -EIO;
  1331. } else {
  1332. temp = readl(mem_crb + data_hi);
  1333. val = ((u64)temp << 32);
  1334. val |= readl(mem_crb + data_lo);
  1335. *data = val;
  1336. ret = 0;
  1337. }
  1338. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1339. spin_unlock(&adapter->ahw.mem_lock);
  1340. return ret;
  1341. }
  1342. static int
  1343. netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
  1344. u64 off, u64 data)
  1345. {
  1346. int j, ret;
  1347. u32 temp, off8;
  1348. void __iomem *mem_crb;
  1349. /* Only 64-bit aligned access */
  1350. if (off & 7)
  1351. return -EIO;
  1352. /* P3 onward, test agent base for MIU and SIU is same */
  1353. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1354. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1355. mem_crb = netxen_get_ioaddr(adapter,
  1356. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1357. goto correct;
  1358. }
  1359. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1360. mem_crb = netxen_get_ioaddr(adapter,
  1361. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1362. goto correct;
  1363. }
  1364. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
  1365. return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
  1366. return -EIO;
  1367. correct:
  1368. off8 = off & 0xfffffff8;
  1369. spin_lock(&adapter->ahw.mem_lock);
  1370. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1371. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1372. writel(data & 0xffffffff,
  1373. mem_crb + MIU_TEST_AGT_WRDATA_LO);
  1374. writel((data >> 32) & 0xffffffff,
  1375. mem_crb + MIU_TEST_AGT_WRDATA_HI);
  1376. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1377. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1378. (mem_crb + TEST_AGT_CTRL));
  1379. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1380. temp = readl(mem_crb + TEST_AGT_CTRL);
  1381. if ((temp & TA_CTL_BUSY) == 0)
  1382. break;
  1383. }
  1384. if (j >= MAX_CTL_CHECK) {
  1385. if (printk_ratelimit())
  1386. dev_err(&adapter->pdev->dev,
  1387. "failed to write through agent\n");
  1388. ret = -EIO;
  1389. } else
  1390. ret = 0;
  1391. spin_unlock(&adapter->ahw.mem_lock);
  1392. return ret;
  1393. }
  1394. static int
  1395. netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
  1396. u64 off, u64 *data)
  1397. {
  1398. int j, ret;
  1399. u32 temp, off8;
  1400. u64 val;
  1401. void __iomem *mem_crb;
  1402. /* Only 64-bit aligned access */
  1403. if (off & 7)
  1404. return -EIO;
  1405. /* P3 onward, test agent base for MIU and SIU is same */
  1406. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1407. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1408. mem_crb = netxen_get_ioaddr(adapter,
  1409. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1410. goto correct;
  1411. }
  1412. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1413. mem_crb = netxen_get_ioaddr(adapter,
  1414. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1415. goto correct;
  1416. }
  1417. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1418. return netxen_nic_pci_mem_access_direct(adapter,
  1419. off, data, 0);
  1420. }
  1421. return -EIO;
  1422. correct:
  1423. off8 = off & 0xfffffff8;
  1424. spin_lock(&adapter->ahw.mem_lock);
  1425. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1426. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1427. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1428. writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1429. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1430. temp = readl(mem_crb + TEST_AGT_CTRL);
  1431. if ((temp & TA_CTL_BUSY) == 0)
  1432. break;
  1433. }
  1434. if (j >= MAX_CTL_CHECK) {
  1435. if (printk_ratelimit())
  1436. dev_err(&adapter->pdev->dev,
  1437. "failed to read through agent\n");
  1438. ret = -EIO;
  1439. } else {
  1440. val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32;
  1441. val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO);
  1442. *data = val;
  1443. ret = 0;
  1444. }
  1445. spin_unlock(&adapter->ahw.mem_lock);
  1446. return ret;
  1447. }
  1448. void
  1449. netxen_setup_hwops(struct netxen_adapter *adapter)
  1450. {
  1451. adapter->init_port = netxen_niu_xg_init_port;
  1452. adapter->stop_port = netxen_niu_disable_xg_port;
  1453. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1454. adapter->crb_read = netxen_nic_hw_read_wx_128M,
  1455. adapter->crb_write = netxen_nic_hw_write_wx_128M,
  1456. adapter->pci_set_window = netxen_nic_pci_set_window_128M,
  1457. adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
  1458. adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
  1459. adapter->io_read = netxen_nic_io_read_128M,
  1460. adapter->io_write = netxen_nic_io_write_128M,
  1461. adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
  1462. adapter->set_multi = netxen_p2_nic_set_multi;
  1463. adapter->set_mtu = netxen_nic_set_mtu_xgb;
  1464. adapter->set_promisc = netxen_p2_nic_set_promisc;
  1465. } else {
  1466. adapter->crb_read = netxen_nic_hw_read_wx_2M,
  1467. adapter->crb_write = netxen_nic_hw_write_wx_2M,
  1468. adapter->pci_set_window = netxen_nic_pci_set_window_2M,
  1469. adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
  1470. adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
  1471. adapter->io_read = netxen_nic_io_read_2M,
  1472. adapter->io_write = netxen_nic_io_write_2M,
  1473. adapter->set_mtu = nx_fw_cmd_set_mtu;
  1474. adapter->set_promisc = netxen_p3_nic_set_promisc;
  1475. adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
  1476. adapter->set_multi = netxen_p3_nic_set_multi;
  1477. adapter->phy_read = nx_fw_cmd_query_phy;
  1478. adapter->phy_write = nx_fw_cmd_set_phy;
  1479. }
  1480. }
  1481. int netxen_nic_get_board_info(struct netxen_adapter *adapter)
  1482. {
  1483. int offset, board_type, magic;
  1484. struct pci_dev *pdev = adapter->pdev;
  1485. offset = NX_FW_MAGIC_OFFSET;
  1486. if (netxen_rom_fast_read(adapter, offset, &magic))
  1487. return -EIO;
  1488. if (magic != NETXEN_BDINFO_MAGIC) {
  1489. dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
  1490. magic);
  1491. return -EIO;
  1492. }
  1493. offset = NX_BRDTYPE_OFFSET;
  1494. if (netxen_rom_fast_read(adapter, offset, &board_type))
  1495. return -EIO;
  1496. if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
  1497. u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
  1498. if ((gpio & 0x8000) == 0)
  1499. board_type = NETXEN_BRDTYPE_P3_10G_TP;
  1500. }
  1501. adapter->ahw.board_type = board_type;
  1502. switch (board_type) {
  1503. case NETXEN_BRDTYPE_P2_SB35_4G:
  1504. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1505. break;
  1506. case NETXEN_BRDTYPE_P2_SB31_10G:
  1507. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  1508. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  1509. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  1510. case NETXEN_BRDTYPE_P3_HMEZ:
  1511. case NETXEN_BRDTYPE_P3_XG_LOM:
  1512. case NETXEN_BRDTYPE_P3_10G_CX4:
  1513. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  1514. case NETXEN_BRDTYPE_P3_IMEZ:
  1515. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  1516. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  1517. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  1518. case NETXEN_BRDTYPE_P3_10G_XFP:
  1519. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  1520. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1521. break;
  1522. case NETXEN_BRDTYPE_P1_BD:
  1523. case NETXEN_BRDTYPE_P1_SB:
  1524. case NETXEN_BRDTYPE_P1_SMAX:
  1525. case NETXEN_BRDTYPE_P1_SOCK:
  1526. case NETXEN_BRDTYPE_P3_REF_QG:
  1527. case NETXEN_BRDTYPE_P3_4_GB:
  1528. case NETXEN_BRDTYPE_P3_4_GB_MM:
  1529. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1530. break;
  1531. case NETXEN_BRDTYPE_P3_10G_TP:
  1532. adapter->ahw.port_type = (adapter->portnum < 2) ?
  1533. NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
  1534. break;
  1535. default:
  1536. dev_err(&pdev->dev, "unknown board type %x\n", board_type);
  1537. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1538. break;
  1539. }
  1540. return 0;
  1541. }
  1542. /* NIU access sections */
  1543. static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
  1544. {
  1545. new_mtu += MTU_FUDGE_FACTOR;
  1546. if (adapter->physical_port == 0)
  1547. NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
  1548. else
  1549. NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
  1550. return 0;
  1551. }
  1552. void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
  1553. {
  1554. __u32 status;
  1555. __u32 autoneg;
  1556. __u32 port_mode;
  1557. if (!netif_carrier_ok(adapter->netdev)) {
  1558. adapter->link_speed = 0;
  1559. adapter->link_duplex = -1;
  1560. adapter->link_autoneg = AUTONEG_ENABLE;
  1561. return;
  1562. }
  1563. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  1564. port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
  1565. if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
  1566. adapter->link_speed = SPEED_1000;
  1567. adapter->link_duplex = DUPLEX_FULL;
  1568. adapter->link_autoneg = AUTONEG_DISABLE;
  1569. return;
  1570. }
  1571. if (adapter->phy_read &&
  1572. adapter->phy_read(adapter,
  1573. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  1574. &status) == 0) {
  1575. if (netxen_get_phy_link(status)) {
  1576. switch (netxen_get_phy_speed(status)) {
  1577. case 0:
  1578. adapter->link_speed = SPEED_10;
  1579. break;
  1580. case 1:
  1581. adapter->link_speed = SPEED_100;
  1582. break;
  1583. case 2:
  1584. adapter->link_speed = SPEED_1000;
  1585. break;
  1586. default:
  1587. adapter->link_speed = 0;
  1588. break;
  1589. }
  1590. switch (netxen_get_phy_duplex(status)) {
  1591. case 0:
  1592. adapter->link_duplex = DUPLEX_HALF;
  1593. break;
  1594. case 1:
  1595. adapter->link_duplex = DUPLEX_FULL;
  1596. break;
  1597. default:
  1598. adapter->link_duplex = -1;
  1599. break;
  1600. }
  1601. if (adapter->phy_read &&
  1602. adapter->phy_read(adapter,
  1603. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  1604. &autoneg) != 0)
  1605. adapter->link_autoneg = autoneg;
  1606. } else
  1607. goto link_down;
  1608. } else {
  1609. link_down:
  1610. adapter->link_speed = 0;
  1611. adapter->link_duplex = -1;
  1612. }
  1613. }
  1614. }
  1615. int
  1616. netxen_nic_wol_supported(struct netxen_adapter *adapter)
  1617. {
  1618. u32 wol_cfg;
  1619. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  1620. return 0;
  1621. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  1622. if (wol_cfg & (1UL << adapter->portnum)) {
  1623. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  1624. if (wol_cfg & (1 << adapter->portnum))
  1625. return 1;
  1626. }
  1627. return 0;
  1628. }
  1629. static u32 netxen_md_cntrl(struct netxen_adapter *adapter,
  1630. struct netxen_minidump_template_hdr *template_hdr,
  1631. struct netxen_minidump_entry_crb *crtEntry)
  1632. {
  1633. int loop_cnt, i, rv = 0, timeout_flag;
  1634. u32 op_count, stride;
  1635. u32 opcode, read_value, addr;
  1636. unsigned long timeout, timeout_jiffies;
  1637. addr = crtEntry->addr;
  1638. op_count = crtEntry->op_count;
  1639. stride = crtEntry->addr_stride;
  1640. for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) {
  1641. for (i = 0; i < sizeof(crtEntry->opcode) * 8; i++) {
  1642. opcode = (crtEntry->opcode & (0x1 << i));
  1643. if (opcode) {
  1644. switch (opcode) {
  1645. case NX_DUMP_WCRB:
  1646. NX_WR_DUMP_REG(addr,
  1647. adapter->ahw.pci_base0,
  1648. crtEntry->value_1);
  1649. break;
  1650. case NX_DUMP_RWCRB:
  1651. NX_RD_DUMP_REG(addr,
  1652. adapter->ahw.pci_base0,
  1653. &read_value);
  1654. NX_WR_DUMP_REG(addr,
  1655. adapter->ahw.pci_base0,
  1656. read_value);
  1657. break;
  1658. case NX_DUMP_ANDCRB:
  1659. NX_RD_DUMP_REG(addr,
  1660. adapter->ahw.pci_base0,
  1661. &read_value);
  1662. read_value &= crtEntry->value_2;
  1663. NX_WR_DUMP_REG(addr,
  1664. adapter->ahw.pci_base0,
  1665. read_value);
  1666. break;
  1667. case NX_DUMP_ORCRB:
  1668. NX_RD_DUMP_REG(addr,
  1669. adapter->ahw.pci_base0,
  1670. &read_value);
  1671. read_value |= crtEntry->value_3;
  1672. NX_WR_DUMP_REG(addr,
  1673. adapter->ahw.pci_base0,
  1674. read_value);
  1675. break;
  1676. case NX_DUMP_POLLCRB:
  1677. timeout = crtEntry->poll_timeout;
  1678. NX_RD_DUMP_REG(addr,
  1679. adapter->ahw.pci_base0,
  1680. &read_value);
  1681. timeout_jiffies =
  1682. msecs_to_jiffies(timeout) + jiffies;
  1683. for (timeout_flag = 0;
  1684. !timeout_flag
  1685. && ((read_value & crtEntry->value_2)
  1686. != crtEntry->value_1);) {
  1687. if (time_after(jiffies,
  1688. timeout_jiffies))
  1689. timeout_flag = 1;
  1690. NX_RD_DUMP_REG(addr,
  1691. adapter->ahw.pci_base0,
  1692. &read_value);
  1693. }
  1694. if (timeout_flag) {
  1695. dev_err(&adapter->pdev->dev, "%s : "
  1696. "Timeout in poll_crb control operation.\n"
  1697. , __func__);
  1698. return -1;
  1699. }
  1700. break;
  1701. case NX_DUMP_RD_SAVE:
  1702. /* Decide which address to use */
  1703. if (crtEntry->state_index_a)
  1704. addr =
  1705. template_hdr->saved_state_array
  1706. [crtEntry->state_index_a];
  1707. NX_RD_DUMP_REG(addr,
  1708. adapter->ahw.pci_base0,
  1709. &read_value);
  1710. template_hdr->saved_state_array
  1711. [crtEntry->state_index_v]
  1712. = read_value;
  1713. break;
  1714. case NX_DUMP_WRT_SAVED:
  1715. /* Decide which value to use */
  1716. if (crtEntry->state_index_v)
  1717. read_value =
  1718. template_hdr->saved_state_array
  1719. [crtEntry->state_index_v];
  1720. else
  1721. read_value = crtEntry->value_1;
  1722. /* Decide which address to use */
  1723. if (crtEntry->state_index_a)
  1724. addr =
  1725. template_hdr->saved_state_array
  1726. [crtEntry->state_index_a];
  1727. NX_WR_DUMP_REG(addr,
  1728. adapter->ahw.pci_base0,
  1729. read_value);
  1730. break;
  1731. case NX_DUMP_MOD_SAVE_ST:
  1732. read_value =
  1733. template_hdr->saved_state_array
  1734. [crtEntry->state_index_v];
  1735. read_value <<= crtEntry->shl;
  1736. read_value >>= crtEntry->shr;
  1737. if (crtEntry->value_2)
  1738. read_value &=
  1739. crtEntry->value_2;
  1740. read_value |= crtEntry->value_3;
  1741. read_value += crtEntry->value_1;
  1742. /* Write value back to state area.*/
  1743. template_hdr->saved_state_array
  1744. [crtEntry->state_index_v]
  1745. = read_value;
  1746. break;
  1747. default:
  1748. rv = 1;
  1749. break;
  1750. }
  1751. }
  1752. }
  1753. addr = addr + stride;
  1754. }
  1755. return rv;
  1756. }
  1757. /* Read memory or MN */
  1758. static u32
  1759. netxen_md_rdmem(struct netxen_adapter *adapter,
  1760. struct netxen_minidump_entry_rdmem
  1761. *memEntry, u64 *data_buff)
  1762. {
  1763. u64 addr, value = 0;
  1764. int i = 0, loop_cnt;
  1765. addr = (u64)memEntry->read_addr;
  1766. loop_cnt = memEntry->read_data_size; /* This is size in bytes */
  1767. loop_cnt /= sizeof(value);
  1768. for (i = 0; i < loop_cnt; i++) {
  1769. if (netxen_nic_pci_mem_read_2M(adapter, addr, &value))
  1770. goto out;
  1771. *data_buff++ = value;
  1772. addr += sizeof(value);
  1773. }
  1774. out:
  1775. return i * sizeof(value);
  1776. }
  1777. /* Read CRB operation */
  1778. static u32 netxen_md_rd_crb(struct netxen_adapter *adapter,
  1779. struct netxen_minidump_entry_crb
  1780. *crbEntry, u32 *data_buff)
  1781. {
  1782. int loop_cnt;
  1783. u32 op_count, addr, stride, value;
  1784. addr = crbEntry->addr;
  1785. op_count = crbEntry->op_count;
  1786. stride = crbEntry->addr_stride;
  1787. for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) {
  1788. NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0, &value);
  1789. *data_buff++ = addr;
  1790. *data_buff++ = value;
  1791. addr = addr + stride;
  1792. }
  1793. return loop_cnt * (2 * sizeof(u32));
  1794. }
  1795. /* Read ROM */
  1796. static u32
  1797. netxen_md_rdrom(struct netxen_adapter *adapter,
  1798. struct netxen_minidump_entry_rdrom
  1799. *romEntry, __le32 *data_buff)
  1800. {
  1801. int i, count = 0;
  1802. u32 size, lck_val;
  1803. u32 val;
  1804. u32 fl_addr, waddr, raddr;
  1805. fl_addr = romEntry->read_addr;
  1806. size = romEntry->read_data_size/4;
  1807. lock_try:
  1808. lck_val = readl((void __iomem *)(adapter->ahw.pci_base0 +
  1809. NX_FLASH_SEM2_LK));
  1810. if (!lck_val && count < MAX_CTL_CHECK) {
  1811. msleep(20);
  1812. count++;
  1813. goto lock_try;
  1814. }
  1815. writel(adapter->ahw.pci_func, (void __iomem *)(adapter->ahw.pci_base0 +
  1816. NX_FLASH_LOCK_ID));
  1817. for (i = 0; i < size; i++) {
  1818. waddr = fl_addr & 0xFFFF0000;
  1819. NX_WR_DUMP_REG(FLASH_ROM_WINDOW, adapter->ahw.pci_base0, waddr);
  1820. raddr = FLASH_ROM_DATA + (fl_addr & 0x0000FFFF);
  1821. NX_RD_DUMP_REG(raddr, adapter->ahw.pci_base0, &val);
  1822. *data_buff++ = cpu_to_le32(val);
  1823. fl_addr += sizeof(val);
  1824. }
  1825. readl((void __iomem *)(adapter->ahw.pci_base0 + NX_FLASH_SEM2_ULK));
  1826. return romEntry->read_data_size;
  1827. }
  1828. /* Handle L2 Cache */
  1829. static u32
  1830. netxen_md_L2Cache(struct netxen_adapter *adapter,
  1831. struct netxen_minidump_entry_cache
  1832. *cacheEntry, u32 *data_buff)
  1833. {
  1834. int loop_cnt, i, k, timeout_flag = 0;
  1835. u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr;
  1836. u32 tag_value, read_cnt;
  1837. u8 cntl_value_w, cntl_value_r;
  1838. unsigned long timeout, timeout_jiffies;
  1839. loop_cnt = cacheEntry->op_count;
  1840. read_addr = cacheEntry->read_addr;
  1841. cntrl_addr = cacheEntry->control_addr;
  1842. cntl_value_w = (u32) cacheEntry->write_value;
  1843. tag_reg_addr = cacheEntry->tag_reg_addr;
  1844. tag_value = cacheEntry->init_tag_value;
  1845. read_cnt = cacheEntry->read_addr_cnt;
  1846. for (i = 0; i < loop_cnt; i++) {
  1847. NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value);
  1848. if (cntl_value_w)
  1849. NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1850. (u32)cntl_value_w);
  1851. if (cacheEntry->poll_mask) {
  1852. timeout = cacheEntry->poll_wait;
  1853. NX_RD_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1854. &cntl_value_r);
  1855. timeout_jiffies = msecs_to_jiffies(timeout) + jiffies;
  1856. for (timeout_flag = 0; !timeout_flag &&
  1857. ((cntl_value_r & cacheEntry->poll_mask) != 0);) {
  1858. if (time_after(jiffies, timeout_jiffies))
  1859. timeout_flag = 1;
  1860. NX_RD_DUMP_REG(cntrl_addr,
  1861. adapter->ahw.pci_base0,
  1862. &cntl_value_r);
  1863. }
  1864. if (timeout_flag) {
  1865. dev_err(&adapter->pdev->dev,
  1866. "Timeout in processing L2 Tag poll.\n");
  1867. return -1;
  1868. }
  1869. }
  1870. addr = read_addr;
  1871. for (k = 0; k < read_cnt; k++) {
  1872. NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0,
  1873. &read_value);
  1874. *data_buff++ = read_value;
  1875. addr += cacheEntry->read_addr_stride;
  1876. }
  1877. tag_value += cacheEntry->tag_value_stride;
  1878. }
  1879. return read_cnt * loop_cnt * sizeof(read_value);
  1880. }
  1881. /* Handle L1 Cache */
  1882. static u32 netxen_md_L1Cache(struct netxen_adapter *adapter,
  1883. struct netxen_minidump_entry_cache
  1884. *cacheEntry, u32 *data_buff)
  1885. {
  1886. int i, k, loop_cnt;
  1887. u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr;
  1888. u32 tag_value, read_cnt;
  1889. u8 cntl_value_w;
  1890. loop_cnt = cacheEntry->op_count;
  1891. read_addr = cacheEntry->read_addr;
  1892. cntrl_addr = cacheEntry->control_addr;
  1893. cntl_value_w = (u32) cacheEntry->write_value;
  1894. tag_reg_addr = cacheEntry->tag_reg_addr;
  1895. tag_value = cacheEntry->init_tag_value;
  1896. read_cnt = cacheEntry->read_addr_cnt;
  1897. for (i = 0; i < loop_cnt; i++) {
  1898. NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value);
  1899. NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0,
  1900. (u32) cntl_value_w);
  1901. addr = read_addr;
  1902. for (k = 0; k < read_cnt; k++) {
  1903. NX_RD_DUMP_REG(addr,
  1904. adapter->ahw.pci_base0,
  1905. &read_value);
  1906. *data_buff++ = read_value;
  1907. addr += cacheEntry->read_addr_stride;
  1908. }
  1909. tag_value += cacheEntry->tag_value_stride;
  1910. }
  1911. return read_cnt * loop_cnt * sizeof(read_value);
  1912. }
  1913. /* Reading OCM memory */
  1914. static u32
  1915. netxen_md_rdocm(struct netxen_adapter *adapter,
  1916. struct netxen_minidump_entry_rdocm
  1917. *ocmEntry, u32 *data_buff)
  1918. {
  1919. int i, loop_cnt;
  1920. u32 value;
  1921. void __iomem *addr;
  1922. addr = (ocmEntry->read_addr + adapter->ahw.pci_base0);
  1923. loop_cnt = ocmEntry->op_count;
  1924. for (i = 0; i < loop_cnt; i++) {
  1925. value = readl(addr);
  1926. *data_buff++ = value;
  1927. addr += ocmEntry->read_addr_stride;
  1928. }
  1929. return i * sizeof(u32);
  1930. }
  1931. /* Read MUX data */
  1932. static u32
  1933. netxen_md_rdmux(struct netxen_adapter *adapter, struct netxen_minidump_entry_mux
  1934. *muxEntry, u32 *data_buff)
  1935. {
  1936. int loop_cnt = 0;
  1937. u32 read_addr, read_value, select_addr, sel_value;
  1938. read_addr = muxEntry->read_addr;
  1939. sel_value = muxEntry->select_value;
  1940. select_addr = muxEntry->select_addr;
  1941. for (loop_cnt = 0; loop_cnt < muxEntry->op_count; loop_cnt++) {
  1942. NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, sel_value);
  1943. NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0, &read_value);
  1944. *data_buff++ = sel_value;
  1945. *data_buff++ = read_value;
  1946. sel_value += muxEntry->select_value_stride;
  1947. }
  1948. return loop_cnt * (2 * sizeof(u32));
  1949. }
  1950. /* Handling Queue State Reads */
  1951. static u32
  1952. netxen_md_rdqueue(struct netxen_adapter *adapter,
  1953. struct netxen_minidump_entry_queue
  1954. *queueEntry, u32 *data_buff)
  1955. {
  1956. int loop_cnt, k;
  1957. u32 queue_id, read_addr, read_value, read_stride, select_addr, read_cnt;
  1958. read_cnt = queueEntry->read_addr_cnt;
  1959. read_stride = queueEntry->read_addr_stride;
  1960. select_addr = queueEntry->select_addr;
  1961. for (loop_cnt = 0, queue_id = 0; loop_cnt < queueEntry->op_count;
  1962. loop_cnt++) {
  1963. NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, queue_id);
  1964. read_addr = queueEntry->read_addr;
  1965. for (k = 0; k < read_cnt; k--) {
  1966. NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0,
  1967. &read_value);
  1968. *data_buff++ = read_value;
  1969. read_addr += read_stride;
  1970. }
  1971. queue_id += queueEntry->queue_id_stride;
  1972. }
  1973. return loop_cnt * (read_cnt * sizeof(read_value));
  1974. }
  1975. /*
  1976. * We catch an error where driver does not read
  1977. * as much data as we expect from the entry.
  1978. */
  1979. static int netxen_md_entry_err_chk(struct netxen_adapter *adapter,
  1980. struct netxen_minidump_entry *entry, int esize)
  1981. {
  1982. if (esize < 0) {
  1983. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  1984. return esize;
  1985. }
  1986. if (esize != entry->hdr.entry_capture_size) {
  1987. entry->hdr.entry_capture_size = esize;
  1988. entry->hdr.driver_flags |= NX_DUMP_SIZE_ERR;
  1989. dev_info(&adapter->pdev->dev,
  1990. "Invalidate dump, Type:%d\tMask:%d\tSize:%dCap_size:%d\n",
  1991. entry->hdr.entry_type, entry->hdr.entry_capture_mask,
  1992. esize, entry->hdr.entry_capture_size);
  1993. dev_info(&adapter->pdev->dev, "Aborting further dump capture\n");
  1994. }
  1995. return 0;
  1996. }
  1997. static int netxen_parse_md_template(struct netxen_adapter *adapter)
  1998. {
  1999. int num_of_entries, buff_level, e_cnt, esize;
  2000. int end_cnt = 0, rv = 0, sane_start = 0, sane_end = 0;
  2001. char *dbuff;
  2002. void *template_buff = adapter->mdump.md_template;
  2003. char *dump_buff = adapter->mdump.md_capture_buff;
  2004. int capture_mask = adapter->mdump.md_capture_mask;
  2005. struct netxen_minidump_template_hdr *template_hdr;
  2006. struct netxen_minidump_entry *entry;
  2007. if ((capture_mask & 0x3) != 0x3) {
  2008. dev_err(&adapter->pdev->dev, "Capture mask %02x below minimum needed "
  2009. "for valid firmware dump\n", capture_mask);
  2010. return -EINVAL;
  2011. }
  2012. template_hdr = (struct netxen_minidump_template_hdr *) template_buff;
  2013. num_of_entries = template_hdr->num_of_entries;
  2014. entry = (struct netxen_minidump_entry *) ((char *) template_buff +
  2015. template_hdr->first_entry_offset);
  2016. memcpy(dump_buff, template_buff, adapter->mdump.md_template_size);
  2017. dump_buff = dump_buff + adapter->mdump.md_template_size;
  2018. if (template_hdr->entry_type == TLHDR)
  2019. sane_start = 1;
  2020. for (e_cnt = 0, buff_level = 0; e_cnt < num_of_entries; e_cnt++) {
  2021. if (!(entry->hdr.entry_capture_mask & capture_mask)) {
  2022. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2023. entry = (struct netxen_minidump_entry *)
  2024. ((char *) entry + entry->hdr.entry_size);
  2025. continue;
  2026. }
  2027. switch (entry->hdr.entry_type) {
  2028. case RDNOP:
  2029. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2030. break;
  2031. case RDEND:
  2032. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2033. if (!sane_end)
  2034. end_cnt = e_cnt;
  2035. sane_end += 1;
  2036. break;
  2037. case CNTRL:
  2038. rv = netxen_md_cntrl(adapter,
  2039. template_hdr, (void *)entry);
  2040. if (rv)
  2041. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2042. break;
  2043. case RDCRB:
  2044. dbuff = dump_buff + buff_level;
  2045. esize = netxen_md_rd_crb(adapter,
  2046. (void *) entry, (void *) dbuff);
  2047. rv = netxen_md_entry_err_chk
  2048. (adapter, entry, esize);
  2049. if (rv < 0)
  2050. break;
  2051. buff_level += esize;
  2052. break;
  2053. case RDMN:
  2054. case RDMEM:
  2055. dbuff = dump_buff + buff_level;
  2056. esize = netxen_md_rdmem(adapter,
  2057. (void *) entry, (void *) dbuff);
  2058. rv = netxen_md_entry_err_chk
  2059. (adapter, entry, esize);
  2060. if (rv < 0)
  2061. break;
  2062. buff_level += esize;
  2063. break;
  2064. case BOARD:
  2065. case RDROM:
  2066. dbuff = dump_buff + buff_level;
  2067. esize = netxen_md_rdrom(adapter,
  2068. (void *) entry, (void *) dbuff);
  2069. rv = netxen_md_entry_err_chk
  2070. (adapter, entry, esize);
  2071. if (rv < 0)
  2072. break;
  2073. buff_level += esize;
  2074. break;
  2075. case L2ITG:
  2076. case L2DTG:
  2077. case L2DAT:
  2078. case L2INS:
  2079. dbuff = dump_buff + buff_level;
  2080. esize = netxen_md_L2Cache(adapter,
  2081. (void *) entry, (void *) dbuff);
  2082. rv = netxen_md_entry_err_chk
  2083. (adapter, entry, esize);
  2084. if (rv < 0)
  2085. break;
  2086. buff_level += esize;
  2087. break;
  2088. case L1DAT:
  2089. case L1INS:
  2090. dbuff = dump_buff + buff_level;
  2091. esize = netxen_md_L1Cache(adapter,
  2092. (void *) entry, (void *) dbuff);
  2093. rv = netxen_md_entry_err_chk
  2094. (adapter, entry, esize);
  2095. if (rv < 0)
  2096. break;
  2097. buff_level += esize;
  2098. break;
  2099. case RDOCM:
  2100. dbuff = dump_buff + buff_level;
  2101. esize = netxen_md_rdocm(adapter,
  2102. (void *) entry, (void *) dbuff);
  2103. rv = netxen_md_entry_err_chk
  2104. (adapter, entry, esize);
  2105. if (rv < 0)
  2106. break;
  2107. buff_level += esize;
  2108. break;
  2109. case RDMUX:
  2110. dbuff = dump_buff + buff_level;
  2111. esize = netxen_md_rdmux(adapter,
  2112. (void *) entry, (void *) dbuff);
  2113. rv = netxen_md_entry_err_chk
  2114. (adapter, entry, esize);
  2115. if (rv < 0)
  2116. break;
  2117. buff_level += esize;
  2118. break;
  2119. case QUEUE:
  2120. dbuff = dump_buff + buff_level;
  2121. esize = netxen_md_rdqueue(adapter,
  2122. (void *) entry, (void *) dbuff);
  2123. rv = netxen_md_entry_err_chk
  2124. (adapter, entry, esize);
  2125. if (rv < 0)
  2126. break;
  2127. buff_level += esize;
  2128. break;
  2129. default:
  2130. entry->hdr.driver_flags |= NX_DUMP_SKIP;
  2131. break;
  2132. }
  2133. /* Next entry in the template */
  2134. entry = (struct netxen_minidump_entry *)
  2135. ((char *) entry + entry->hdr.entry_size);
  2136. }
  2137. if (!sane_start || sane_end > 1) {
  2138. dev_err(&adapter->pdev->dev,
  2139. "Firmware minidump template configuration error.\n");
  2140. }
  2141. return 0;
  2142. }
  2143. static int
  2144. netxen_collect_minidump(struct netxen_adapter *adapter)
  2145. {
  2146. int ret = 0;
  2147. struct netxen_minidump_template_hdr *hdr;
  2148. struct timespec val;
  2149. hdr = (struct netxen_minidump_template_hdr *)
  2150. adapter->mdump.md_template;
  2151. hdr->driver_capture_mask = adapter->mdump.md_capture_mask;
  2152. jiffies_to_timespec(jiffies, &val);
  2153. hdr->driver_timestamp = (u32) val.tv_sec;
  2154. hdr->driver_info_word2 = adapter->fw_version;
  2155. hdr->driver_info_word3 = NXRD32(adapter, CRB_DRIVER_VERSION);
  2156. ret = netxen_parse_md_template(adapter);
  2157. if (ret)
  2158. return ret;
  2159. return ret;
  2160. }
  2161. void
  2162. netxen_dump_fw(struct netxen_adapter *adapter)
  2163. {
  2164. struct netxen_minidump_template_hdr *hdr;
  2165. int i, k, data_size = 0;
  2166. u32 capture_mask;
  2167. hdr = (struct netxen_minidump_template_hdr *)
  2168. adapter->mdump.md_template;
  2169. capture_mask = adapter->mdump.md_capture_mask;
  2170. for (i = 0x2, k = 1; (i & NX_DUMP_MASK_MAX); i <<= 1, k++) {
  2171. if (i & capture_mask)
  2172. data_size += hdr->capture_size_array[k];
  2173. }
  2174. if (!data_size) {
  2175. dev_err(&adapter->pdev->dev,
  2176. "Invalid cap sizes for capture_mask=0x%x\n",
  2177. adapter->mdump.md_capture_mask);
  2178. return;
  2179. }
  2180. adapter->mdump.md_capture_size = data_size;
  2181. adapter->mdump.md_dump_size = adapter->mdump.md_template_size +
  2182. adapter->mdump.md_capture_size;
  2183. if (!adapter->mdump.md_capture_buff) {
  2184. adapter->mdump.md_capture_buff =
  2185. vzalloc(adapter->mdump.md_dump_size);
  2186. if (!adapter->mdump.md_capture_buff)
  2187. return;
  2188. if (netxen_collect_minidump(adapter)) {
  2189. adapter->mdump.has_valid_dump = 0;
  2190. adapter->mdump.md_dump_size = 0;
  2191. vfree(adapter->mdump.md_capture_buff);
  2192. adapter->mdump.md_capture_buff = NULL;
  2193. dev_err(&adapter->pdev->dev,
  2194. "Error in collecting firmware minidump.\n");
  2195. } else {
  2196. adapter->mdump.md_timestamp = jiffies;
  2197. adapter->mdump.has_valid_dump = 1;
  2198. adapter->fw_mdump_rdy = 1;
  2199. dev_info(&adapter->pdev->dev, "%s Successfully "
  2200. "collected fw dump.\n", adapter->netdev->name);
  2201. }
  2202. } else {
  2203. dev_info(&adapter->pdev->dev,
  2204. "Cannot overwrite previously collected "
  2205. "firmware minidump.\n");
  2206. adapter->fw_mdump_rdy = 1;
  2207. return;
  2208. }
  2209. }