netxen_nic_hw.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  1. /*
  2. * Copyright (C) 2003 - 2006 NetXen, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  18. * MA 02111-1307, USA.
  19. *
  20. * The full GNU General Public License is included in this distribution
  21. * in the file called LICENSE.
  22. *
  23. * Contact Information:
  24. * info@netxen.com
  25. * NetXen,
  26. * 3965 Freedom Circle, Fourth floor,
  27. * Santa Clara, CA 95054
  28. *
  29. *
  30. * Source file for NIC routines to access the Phantom hardware
  31. *
  32. */
  33. #include "netxen_nic.h"
  34. #include "netxen_nic_hw.h"
  35. #include "netxen_nic_phan_reg.h"
  36. #include <net/ip.h>
  37. #define MASK(n) ((1ULL<<(n))-1)
  38. #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
  39. #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
  40. #define MS_WIN(addr) (addr & 0x0ffc0000)
  41. #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
  42. #define CRB_BLK(off) ((off >> 20) & 0x3f)
  43. #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
  44. #define CRB_WINDOW_2M (0x130060)
  45. #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
  46. #define CRB_INDIRECT_2M (0x1e0000UL)
  47. #define CRB_WIN_LOCK_TIMEOUT 100000000
  48. static crb_128M_2M_block_map_t crb_128M_2M_map[64] = {
  49. {{{0, 0, 0, 0} } }, /* 0: PCI */
  50. {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
  51. {1, 0x0110000, 0x0120000, 0x130000},
  52. {1, 0x0120000, 0x0122000, 0x124000},
  53. {1, 0x0130000, 0x0132000, 0x126000},
  54. {1, 0x0140000, 0x0142000, 0x128000},
  55. {1, 0x0150000, 0x0152000, 0x12a000},
  56. {1, 0x0160000, 0x0170000, 0x110000},
  57. {1, 0x0170000, 0x0172000, 0x12e000},
  58. {0, 0x0000000, 0x0000000, 0x000000},
  59. {0, 0x0000000, 0x0000000, 0x000000},
  60. {0, 0x0000000, 0x0000000, 0x000000},
  61. {0, 0x0000000, 0x0000000, 0x000000},
  62. {0, 0x0000000, 0x0000000, 0x000000},
  63. {0, 0x0000000, 0x0000000, 0x000000},
  64. {1, 0x01e0000, 0x01e0800, 0x122000},
  65. {0, 0x0000000, 0x0000000, 0x000000} } },
  66. {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
  67. {{{0, 0, 0, 0} } }, /* 3: */
  68. {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
  69. {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
  70. {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
  71. {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
  72. {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
  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. {0, 0x0000000, 0x0000000, 0x000000},
  84. {0, 0x0000000, 0x0000000, 0x000000},
  85. {0, 0x0000000, 0x0000000, 0x000000},
  86. {0, 0x0000000, 0x0000000, 0x000000},
  87. {1, 0x08f0000, 0x08f2000, 0x172000} } },
  88. {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  100. {0, 0x0000000, 0x0000000, 0x000000},
  101. {0, 0x0000000, 0x0000000, 0x000000},
  102. {0, 0x0000000, 0x0000000, 0x000000},
  103. {1, 0x09f0000, 0x09f2000, 0x176000} } },
  104. {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  116. {0, 0x0000000, 0x0000000, 0x000000},
  117. {0, 0x0000000, 0x0000000, 0x000000},
  118. {0, 0x0000000, 0x0000000, 0x000000},
  119. {1, 0x0af0000, 0x0af2000, 0x17a000} } },
  120. {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  132. {0, 0x0000000, 0x0000000, 0x000000},
  133. {0, 0x0000000, 0x0000000, 0x000000},
  134. {0, 0x0000000, 0x0000000, 0x000000},
  135. {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
  136. {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
  137. {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
  138. {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
  139. {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
  140. {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
  141. {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
  142. {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
  143. {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
  144. {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
  145. {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
  146. {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
  147. {{{0, 0, 0, 0} } }, /* 23: */
  148. {{{0, 0, 0, 0} } }, /* 24: */
  149. {{{0, 0, 0, 0} } }, /* 25: */
  150. {{{0, 0, 0, 0} } }, /* 26: */
  151. {{{0, 0, 0, 0} } }, /* 27: */
  152. {{{0, 0, 0, 0} } }, /* 28: */
  153. {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
  154. {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
  155. {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
  156. {{{0} } }, /* 32: PCI */
  157. {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
  158. {1, 0x2110000, 0x2120000, 0x130000},
  159. {1, 0x2120000, 0x2122000, 0x124000},
  160. {1, 0x2130000, 0x2132000, 0x126000},
  161. {1, 0x2140000, 0x2142000, 0x128000},
  162. {1, 0x2150000, 0x2152000, 0x12a000},
  163. {1, 0x2160000, 0x2170000, 0x110000},
  164. {1, 0x2170000, 0x2172000, 0x12e000},
  165. {0, 0x0000000, 0x0000000, 0x000000},
  166. {0, 0x0000000, 0x0000000, 0x000000},
  167. {0, 0x0000000, 0x0000000, 0x000000},
  168. {0, 0x0000000, 0x0000000, 0x000000},
  169. {0, 0x0000000, 0x0000000, 0x000000},
  170. {0, 0x0000000, 0x0000000, 0x000000},
  171. {0, 0x0000000, 0x0000000, 0x000000},
  172. {0, 0x0000000, 0x0000000, 0x000000} } },
  173. {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
  174. {{{0} } }, /* 35: */
  175. {{{0} } }, /* 36: */
  176. {{{0} } }, /* 37: */
  177. {{{0} } }, /* 38: */
  178. {{{0} } }, /* 39: */
  179. {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
  180. {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
  181. {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
  182. {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
  183. {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
  184. {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
  185. {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
  186. {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
  187. {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
  188. {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
  189. {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
  190. {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
  191. {{{0} } }, /* 52: */
  192. {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
  193. {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
  194. {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
  195. {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
  196. {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
  197. {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
  198. {{{0} } }, /* 59: I2C0 */
  199. {{{0} } }, /* 60: I2C1 */
  200. {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
  201. {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
  202. {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
  203. };
  204. /*
  205. * top 12 bits of crb internal address (hub, agent)
  206. */
  207. static unsigned crb_hub_agt[64] =
  208. {
  209. 0,
  210. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  211. NETXEN_HW_CRB_HUB_AGT_ADR_MN,
  212. NETXEN_HW_CRB_HUB_AGT_ADR_MS,
  213. 0,
  214. NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
  215. NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
  216. NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
  217. NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
  218. NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
  219. NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
  220. NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
  221. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  222. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  223. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  224. NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
  225. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  226. NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
  227. NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
  228. NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
  229. NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
  230. NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
  231. NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
  232. NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
  233. NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
  234. NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
  235. NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
  236. 0,
  237. NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
  238. NETXEN_HW_CRB_HUB_AGT_ADR_SN,
  239. 0,
  240. NETXEN_HW_CRB_HUB_AGT_ADR_EG,
  241. 0,
  242. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  243. NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
  244. 0,
  245. 0,
  246. 0,
  247. 0,
  248. 0,
  249. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  250. 0,
  251. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
  252. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
  253. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
  254. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
  255. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
  256. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
  257. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
  258. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  259. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  260. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  261. 0,
  262. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
  263. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
  264. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
  265. NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
  266. 0,
  267. NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
  268. NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
  269. NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
  270. 0,
  271. NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
  272. 0,
  273. };
  274. /* PCI Windowing for DDR regions. */
  275. #define ADDR_IN_RANGE(addr, low, high) \
  276. (((addr) <= (high)) && ((addr) >= (low)))
  277. #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
  278. #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL
  279. #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL
  280. #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL
  281. #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL
  282. #define NETXEN_NIC_WINDOW_MARGIN 0x100000
  283. int netxen_nic_set_mac(struct net_device *netdev, void *p)
  284. {
  285. struct netxen_adapter *adapter = netdev_priv(netdev);
  286. struct sockaddr *addr = p;
  287. if (netif_running(netdev))
  288. return -EBUSY;
  289. if (!is_valid_ether_addr(addr->sa_data))
  290. return -EADDRNOTAVAIL;
  291. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  292. /* For P3, MAC addr is not set in NIU */
  293. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  294. if (adapter->macaddr_set)
  295. adapter->macaddr_set(adapter, addr->sa_data);
  296. return 0;
  297. }
  298. #define NETXEN_UNICAST_ADDR(port, index) \
  299. (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
  300. #define NETXEN_MCAST_ADDR(port, index) \
  301. (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
  302. #define MAC_HI(addr) \
  303. ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
  304. #define MAC_LO(addr) \
  305. ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
  306. static int
  307. netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
  308. {
  309. u32 val = 0;
  310. u16 port = adapter->physical_port;
  311. u8 *addr = adapter->netdev->dev_addr;
  312. if (adapter->mc_enabled)
  313. return 0;
  314. adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
  315. val |= (1UL << (28+port));
  316. adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
  317. /* add broadcast addr to filter */
  318. val = 0xffffff;
  319. netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  320. netxen_crb_writelit_adapter(adapter,
  321. NETXEN_UNICAST_ADDR(port, 0)+4, val);
  322. /* add station addr to filter */
  323. val = MAC_HI(addr);
  324. netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
  325. val = MAC_LO(addr);
  326. netxen_crb_writelit_adapter(adapter,
  327. NETXEN_UNICAST_ADDR(port, 1)+4, val);
  328. adapter->mc_enabled = 1;
  329. return 0;
  330. }
  331. static int
  332. netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
  333. {
  334. u32 val = 0;
  335. u16 port = adapter->physical_port;
  336. u8 *addr = adapter->netdev->dev_addr;
  337. if (!adapter->mc_enabled)
  338. return 0;
  339. adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
  340. val &= ~(1UL << (28+port));
  341. adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4);
  342. val = MAC_HI(addr);
  343. netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  344. val = MAC_LO(addr);
  345. netxen_crb_writelit_adapter(adapter,
  346. NETXEN_UNICAST_ADDR(port, 0)+4, val);
  347. netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
  348. netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
  349. adapter->mc_enabled = 0;
  350. return 0;
  351. }
  352. static int
  353. netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
  354. int index, u8 *addr)
  355. {
  356. u32 hi = 0, lo = 0;
  357. u16 port = adapter->physical_port;
  358. lo = MAC_LO(addr);
  359. hi = MAC_HI(addr);
  360. netxen_crb_writelit_adapter(adapter,
  361. NETXEN_MCAST_ADDR(port, index), hi);
  362. netxen_crb_writelit_adapter(adapter,
  363. NETXEN_MCAST_ADDR(port, index)+4, lo);
  364. return 0;
  365. }
  366. void netxen_p2_nic_set_multi(struct net_device *netdev)
  367. {
  368. struct netxen_adapter *adapter = netdev_priv(netdev);
  369. struct dev_mc_list *mc_ptr;
  370. u8 null_addr[6];
  371. int index = 0;
  372. memset(null_addr, 0, 6);
  373. if (netdev->flags & IFF_PROMISC) {
  374. adapter->set_promisc(adapter,
  375. NETXEN_NIU_PROMISC_MODE);
  376. /* Full promiscuous mode */
  377. netxen_nic_disable_mcast_filter(adapter);
  378. return;
  379. }
  380. if (netdev->mc_count == 0) {
  381. adapter->set_promisc(adapter,
  382. NETXEN_NIU_NON_PROMISC_MODE);
  383. netxen_nic_disable_mcast_filter(adapter);
  384. return;
  385. }
  386. adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
  387. if (netdev->flags & IFF_ALLMULTI ||
  388. netdev->mc_count > adapter->max_mc_count) {
  389. netxen_nic_disable_mcast_filter(adapter);
  390. return;
  391. }
  392. netxen_nic_enable_mcast_filter(adapter);
  393. for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++)
  394. netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr);
  395. if (index != netdev->mc_count)
  396. printk(KERN_WARNING "%s: %s multicast address count mismatch\n",
  397. netxen_nic_driver_name, netdev->name);
  398. /* Clear out remaining addresses */
  399. for (; index < adapter->max_mc_count; index++)
  400. netxen_nic_set_mcast_addr(adapter, index, null_addr);
  401. }
  402. static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
  403. u8 *addr, nx_mac_list_t **add_list, nx_mac_list_t **del_list)
  404. {
  405. nx_mac_list_t *cur, *prev;
  406. /* if in del_list, move it to adapter->mac_list */
  407. for (cur = *del_list, prev = NULL; cur;) {
  408. if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
  409. if (prev == NULL)
  410. *del_list = cur->next;
  411. else
  412. prev->next = cur->next;
  413. cur->next = adapter->mac_list;
  414. adapter->mac_list = cur;
  415. return 0;
  416. }
  417. prev = cur;
  418. cur = cur->next;
  419. }
  420. /* make sure to add each mac address only once */
  421. for (cur = adapter->mac_list; cur; cur = cur->next) {
  422. if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0)
  423. return 0;
  424. }
  425. /* not in del_list, create new entry and add to add_list */
  426. cur = kmalloc(sizeof(*cur), in_atomic()? GFP_ATOMIC : GFP_KERNEL);
  427. if (cur == NULL) {
  428. printk(KERN_ERR "%s: cannot allocate memory. MAC filtering may"
  429. "not work properly from now.\n", __func__);
  430. return -1;
  431. }
  432. memcpy(cur->mac_addr, addr, ETH_ALEN);
  433. cur->next = *add_list;
  434. *add_list = cur;
  435. return 0;
  436. }
  437. static int
  438. netxen_send_cmd_descs(struct netxen_adapter *adapter,
  439. struct cmd_desc_type0 *cmd_desc_arr, int nr_elements)
  440. {
  441. uint32_t i, producer;
  442. struct netxen_cmd_buffer *pbuf;
  443. struct cmd_desc_type0 *cmd_desc;
  444. if (nr_elements > MAX_PENDING_DESC_BLOCK_SIZE || nr_elements == 0) {
  445. printk(KERN_WARNING "%s: Too many command descriptors in a "
  446. "request\n", __func__);
  447. return -EINVAL;
  448. }
  449. i = 0;
  450. producer = adapter->cmd_producer;
  451. do {
  452. cmd_desc = &cmd_desc_arr[i];
  453. pbuf = &adapter->cmd_buf_arr[producer];
  454. pbuf->mss = 0;
  455. pbuf->total_length = 0;
  456. pbuf->skb = NULL;
  457. pbuf->cmd = 0;
  458. pbuf->frag_count = 0;
  459. pbuf->port = 0;
  460. /* adapter->ahw.cmd_desc_head[producer] = *cmd_desc; */
  461. memcpy(&adapter->ahw.cmd_desc_head[producer],
  462. &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
  463. producer = get_next_index(producer,
  464. adapter->max_tx_desc_count);
  465. i++;
  466. } while (i != nr_elements);
  467. adapter->cmd_producer = producer;
  468. /* write producer index to start the xmit */
  469. netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer);
  470. return 0;
  471. }
  472. static int nx_p3_sre_macaddr_change(struct net_device *dev,
  473. u8 *addr, unsigned op)
  474. {
  475. struct netxen_adapter *adapter = (struct netxen_adapter *)dev->priv;
  476. nx_nic_req_t req;
  477. nx_mac_req_t mac_req;
  478. int rv;
  479. memset(&req, 0, sizeof(nx_nic_req_t));
  480. req.qhdr |= (NX_NIC_REQUEST << 23);
  481. req.req_hdr |= NX_MAC_EVENT;
  482. req.req_hdr |= ((u64)adapter->portnum << 16);
  483. mac_req.op = op;
  484. memcpy(&mac_req.mac_addr, addr, 6);
  485. req.words[0] = cpu_to_le64(*(u64 *)&mac_req);
  486. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  487. if (rv != 0) {
  488. printk(KERN_ERR "ERROR. Could not send mac update\n");
  489. return rv;
  490. }
  491. return 0;
  492. }
  493. void netxen_p3_nic_set_multi(struct net_device *netdev)
  494. {
  495. struct netxen_adapter *adapter = netdev_priv(netdev);
  496. nx_mac_list_t *cur, *next, *del_list, *add_list = NULL;
  497. struct dev_mc_list *mc_ptr;
  498. u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  499. u32 mode = VPORT_MISS_MODE_DROP;
  500. del_list = adapter->mac_list;
  501. adapter->mac_list = NULL;
  502. nx_p3_nic_add_mac(adapter, netdev->dev_addr, &add_list, &del_list);
  503. nx_p3_nic_add_mac(adapter, bcast_addr, &add_list, &del_list);
  504. if (netdev->flags & IFF_PROMISC) {
  505. mode = VPORT_MISS_MODE_ACCEPT_ALL;
  506. goto send_fw_cmd;
  507. }
  508. if ((netdev->flags & IFF_ALLMULTI) ||
  509. (netdev->mc_count > adapter->max_mc_count)) {
  510. mode = VPORT_MISS_MODE_ACCEPT_MULTI;
  511. goto send_fw_cmd;
  512. }
  513. if (netdev->mc_count > 0) {
  514. for (mc_ptr = netdev->mc_list; mc_ptr;
  515. mc_ptr = mc_ptr->next) {
  516. nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr,
  517. &add_list, &del_list);
  518. }
  519. }
  520. send_fw_cmd:
  521. adapter->set_promisc(adapter, mode);
  522. for (cur = del_list; cur;) {
  523. nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_DEL);
  524. next = cur->next;
  525. kfree(cur);
  526. cur = next;
  527. }
  528. for (cur = add_list; cur;) {
  529. nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_ADD);
  530. next = cur->next;
  531. cur->next = adapter->mac_list;
  532. adapter->mac_list = cur;
  533. cur = next;
  534. }
  535. }
  536. int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
  537. {
  538. nx_nic_req_t req;
  539. memset(&req, 0, sizeof(nx_nic_req_t));
  540. req.qhdr |= (NX_HOST_REQUEST << 23);
  541. req.req_hdr |= NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE;
  542. req.req_hdr |= ((u64)adapter->portnum << 16);
  543. req.words[0] = cpu_to_le64(mode);
  544. return netxen_send_cmd_descs(adapter,
  545. (struct cmd_desc_type0 *)&req, 1);
  546. }
  547. #define NETXEN_CONFIG_INTR_COALESCE 3
  548. /*
  549. * Send the interrupt coalescing parameter set by ethtool to the card.
  550. */
  551. int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
  552. {
  553. nx_nic_req_t req;
  554. int rv;
  555. memset(&req, 0, sizeof(nx_nic_req_t));
  556. req.qhdr |= (NX_NIC_REQUEST << 23);
  557. req.req_hdr |= NETXEN_CONFIG_INTR_COALESCE;
  558. req.req_hdr |= ((u64)adapter->portnum << 16);
  559. memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal));
  560. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  561. if (rv != 0) {
  562. printk(KERN_ERR "ERROR. Could not send "
  563. "interrupt coalescing parameters\n");
  564. }
  565. return rv;
  566. }
  567. /*
  568. * netxen_nic_change_mtu - Change the Maximum Transfer Unit
  569. * @returns 0 on success, negative on failure
  570. */
  571. #define MTU_FUDGE_FACTOR 100
  572. int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
  573. {
  574. struct netxen_adapter *adapter = netdev_priv(netdev);
  575. int max_mtu;
  576. int rc = 0;
  577. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  578. max_mtu = P3_MAX_MTU;
  579. else
  580. max_mtu = P2_MAX_MTU;
  581. if (mtu > max_mtu) {
  582. printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
  583. netdev->name, max_mtu);
  584. return -EINVAL;
  585. }
  586. if (adapter->set_mtu)
  587. rc = adapter->set_mtu(adapter, mtu);
  588. if (!rc)
  589. netdev->mtu = mtu;
  590. return rc;
  591. }
  592. int netxen_is_flash_supported(struct netxen_adapter *adapter)
  593. {
  594. const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 };
  595. int addr, val01, val02, i, j;
  596. /* if the flash size less than 4Mb, make huge war cry and die */
  597. for (j = 1; j < 4; j++) {
  598. addr = j * NETXEN_NIC_WINDOW_MARGIN;
  599. for (i = 0; i < ARRAY_SIZE(locs); i++) {
  600. if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
  601. && netxen_rom_fast_read(adapter, (addr + locs[i]),
  602. &val02) == 0) {
  603. if (val01 == val02)
  604. return -1;
  605. } else
  606. return -1;
  607. }
  608. }
  609. return 0;
  610. }
  611. static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
  612. int size, __le32 * buf)
  613. {
  614. int i, addr;
  615. __le32 *ptr32;
  616. u32 v;
  617. addr = base;
  618. ptr32 = buf;
  619. for (i = 0; i < size / sizeof(u32); i++) {
  620. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  621. return -1;
  622. *ptr32 = cpu_to_le32(v);
  623. ptr32++;
  624. addr += sizeof(u32);
  625. }
  626. if ((char *)buf + size > (char *)ptr32) {
  627. __le32 local;
  628. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  629. return -1;
  630. local = cpu_to_le32(v);
  631. memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
  632. }
  633. return 0;
  634. }
  635. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 mac[])
  636. {
  637. __le32 *pmac = (__le32 *) & mac[0];
  638. if (netxen_get_flash_block(adapter,
  639. NETXEN_USER_START +
  640. offsetof(struct netxen_new_user_info,
  641. mac_addr),
  642. FLASH_NUM_PORTS * sizeof(u64), pmac) == -1) {
  643. return -1;
  644. }
  645. if (*mac == cpu_to_le64(~0ULL)) {
  646. if (netxen_get_flash_block(adapter,
  647. NETXEN_USER_START_OLD +
  648. offsetof(struct netxen_user_old_info,
  649. mac_addr),
  650. FLASH_NUM_PORTS * sizeof(u64),
  651. pmac) == -1)
  652. return -1;
  653. if (*mac == cpu_to_le64(~0ULL))
  654. return -1;
  655. }
  656. return 0;
  657. }
  658. #define CRB_WIN_LOCK_TIMEOUT 100000000
  659. static int crb_win_lock(struct netxen_adapter *adapter)
  660. {
  661. int done = 0, timeout = 0;
  662. while (!done) {
  663. /* acquire semaphore3 from PCI HW block */
  664. adapter->hw_read_wx(adapter,
  665. NETXEN_PCIE_REG(PCIE_SEM7_LOCK), &done, 4);
  666. if (done == 1)
  667. break;
  668. if (timeout >= CRB_WIN_LOCK_TIMEOUT)
  669. return -1;
  670. timeout++;
  671. udelay(1);
  672. }
  673. netxen_crb_writelit_adapter(adapter,
  674. NETXEN_CRB_WIN_LOCK_ID, adapter->portnum);
  675. return 0;
  676. }
  677. static void crb_win_unlock(struct netxen_adapter *adapter)
  678. {
  679. int val;
  680. adapter->hw_read_wx(adapter,
  681. NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK), &val, 4);
  682. }
  683. /*
  684. * Changes the CRB window to the specified window.
  685. */
  686. void
  687. netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw)
  688. {
  689. void __iomem *offset;
  690. u32 tmp;
  691. int count = 0;
  692. uint8_t func = adapter->ahw.pci_func;
  693. if (adapter->curr_window == wndw)
  694. return;
  695. /*
  696. * Move the CRB window.
  697. * We need to write to the "direct access" region of PCI
  698. * to avoid a race condition where the window register has
  699. * not been successfully written across CRB before the target
  700. * register address is received by PCI. The direct region bypasses
  701. * the CRB bus.
  702. */
  703. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  704. NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
  705. if (wndw & 0x1)
  706. wndw = NETXEN_WINDOW_ONE;
  707. writel(wndw, offset);
  708. /* MUST make sure window is set before we forge on... */
  709. while ((tmp = readl(offset)) != wndw) {
  710. printk(KERN_WARNING "%s: %s WARNING: CRB window value not "
  711. "registered properly: 0x%08x.\n",
  712. netxen_nic_driver_name, __func__, tmp);
  713. mdelay(1);
  714. if (count >= 10)
  715. break;
  716. count++;
  717. }
  718. if (wndw == NETXEN_WINDOW_ONE)
  719. adapter->curr_window = 1;
  720. else
  721. adapter->curr_window = 0;
  722. }
  723. /*
  724. * Return -1 if off is not valid,
  725. * 1 if window access is needed. 'off' is set to offset from
  726. * CRB space in 128M pci map
  727. * 0 if no window access is needed. 'off' is set to 2M addr
  728. * In: 'off' is offset from base in 128M pci map
  729. */
  730. static int
  731. netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
  732. ulong *off, int len)
  733. {
  734. unsigned long end = *off + len;
  735. crb_128M_2M_sub_block_map_t *m;
  736. if (*off >= NETXEN_CRB_MAX)
  737. return -1;
  738. if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) {
  739. *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE +
  740. (ulong)adapter->ahw.pci_base0;
  741. return 0;
  742. }
  743. if (*off < NETXEN_PCI_CRBSPACE)
  744. return -1;
  745. *off -= NETXEN_PCI_CRBSPACE;
  746. end = *off + len;
  747. /*
  748. * Try direct map
  749. */
  750. m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
  751. if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) {
  752. *off = *off + m->start_2M - m->start_128M +
  753. (ulong)adapter->ahw.pci_base0;
  754. return 0;
  755. }
  756. /*
  757. * Not in direct map, use crb window
  758. */
  759. return 1;
  760. }
  761. /*
  762. * In: 'off' is offset from CRB space in 128M pci map
  763. * Out: 'off' is 2M pci map addr
  764. * side effect: lock crb window
  765. */
  766. static void
  767. netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off)
  768. {
  769. u32 win_read;
  770. adapter->crb_win = CRB_HI(*off);
  771. writel(adapter->crb_win, (void *)(CRB_WINDOW_2M +
  772. adapter->ahw.pci_base0));
  773. /*
  774. * Read back value to make sure write has gone through before trying
  775. * to use it.
  776. */
  777. win_read = readl((void *)(CRB_WINDOW_2M + adapter->ahw.pci_base0));
  778. if (win_read != adapter->crb_win) {
  779. printk(KERN_ERR "%s: Written crbwin (0x%x) != "
  780. "Read crbwin (0x%x), off=0x%lx\n",
  781. __func__, adapter->crb_win, win_read, *off);
  782. }
  783. *off = (*off & MASK(16)) + CRB_INDIRECT_2M +
  784. (ulong)adapter->ahw.pci_base0;
  785. }
  786. int netxen_load_firmware(struct netxen_adapter *adapter)
  787. {
  788. int i;
  789. u32 data, size = 0;
  790. u32 flashaddr = NETXEN_BOOTLD_START, memaddr = NETXEN_BOOTLD_START;
  791. size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START)/4;
  792. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  793. adapter->pci_write_normalize(adapter,
  794. NETXEN_ROMUSB_GLB_CAS_RST, 1);
  795. for (i = 0; i < size; i++) {
  796. if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0)
  797. return -EIO;
  798. adapter->pci_mem_write(adapter, memaddr, &data, 4);
  799. flashaddr += 4;
  800. memaddr += 4;
  801. cond_resched();
  802. }
  803. msleep(1);
  804. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  805. adapter->pci_write_normalize(adapter,
  806. NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d);
  807. else {
  808. adapter->pci_write_normalize(adapter,
  809. NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff);
  810. adapter->pci_write_normalize(adapter,
  811. NETXEN_ROMUSB_GLB_CAS_RST, 0);
  812. }
  813. return 0;
  814. }
  815. int
  816. netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter,
  817. ulong off, void *data, int len)
  818. {
  819. void __iomem *addr;
  820. if (ADDR_IN_WINDOW1(off)) {
  821. addr = NETXEN_CRB_NORMALIZE(adapter, off);
  822. } else { /* Window 0 */
  823. addr = pci_base_offset(adapter, off);
  824. netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  825. }
  826. DPRINTK(INFO, "writing to base %lx offset %llx addr %p"
  827. " data %llx len %d\n",
  828. pci_base(adapter, off), off, addr,
  829. *(unsigned long long *)data, len);
  830. if (!addr) {
  831. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  832. return 1;
  833. }
  834. switch (len) {
  835. case 1:
  836. writeb(*(u8 *) data, addr);
  837. break;
  838. case 2:
  839. writew(*(u16 *) data, addr);
  840. break;
  841. case 4:
  842. writel(*(u32 *) data, addr);
  843. break;
  844. case 8:
  845. writeq(*(u64 *) data, addr);
  846. break;
  847. default:
  848. DPRINTK(INFO,
  849. "writing data %lx to offset %llx, num words=%d\n",
  850. *(unsigned long *)data, off, (len >> 3));
  851. netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
  852. (len >> 3));
  853. break;
  854. }
  855. if (!ADDR_IN_WINDOW1(off))
  856. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  857. return 0;
  858. }
  859. int
  860. netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter,
  861. ulong off, void *data, int len)
  862. {
  863. void __iomem *addr;
  864. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  865. addr = NETXEN_CRB_NORMALIZE(adapter, off);
  866. } else { /* Window 0 */
  867. addr = pci_base_offset(adapter, off);
  868. netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  869. }
  870. DPRINTK(INFO, "reading from base %lx offset %llx addr %p\n",
  871. pci_base(adapter, off), off, addr);
  872. if (!addr) {
  873. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  874. return 1;
  875. }
  876. switch (len) {
  877. case 1:
  878. *(u8 *) data = readb(addr);
  879. break;
  880. case 2:
  881. *(u16 *) data = readw(addr);
  882. break;
  883. case 4:
  884. *(u32 *) data = readl(addr);
  885. break;
  886. case 8:
  887. *(u64 *) data = readq(addr);
  888. break;
  889. default:
  890. netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
  891. (len >> 3));
  892. break;
  893. }
  894. DPRINTK(INFO, "read %lx\n", *(unsigned long *)data);
  895. if (!ADDR_IN_WINDOW1(off))
  896. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  897. return 0;
  898. }
  899. int
  900. netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter,
  901. ulong off, void *data, int len)
  902. {
  903. unsigned long flags = 0;
  904. int rv;
  905. rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
  906. if (rv == -1) {
  907. printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
  908. __func__, off);
  909. dump_stack();
  910. return -1;
  911. }
  912. if (rv == 1) {
  913. write_lock_irqsave(&adapter->adapter_lock, flags);
  914. crb_win_lock(adapter);
  915. netxen_nic_pci_set_crbwindow_2M(adapter, &off);
  916. }
  917. DPRINTK(1, INFO, "write data %lx to offset %llx, len=%d\n",
  918. *(unsigned long *)data, off, len);
  919. switch (len) {
  920. case 1:
  921. writeb(*(uint8_t *)data, (void *)off);
  922. break;
  923. case 2:
  924. writew(*(uint16_t *)data, (void *)off);
  925. break;
  926. case 4:
  927. writel(*(uint32_t *)data, (void *)off);
  928. break;
  929. case 8:
  930. writeq(*(uint64_t *)data, (void *)off);
  931. break;
  932. default:
  933. DPRINTK(1, INFO,
  934. "writing data %lx to offset %llx, num words=%d\n",
  935. *(unsigned long *)data, off, (len>>3));
  936. break;
  937. }
  938. if (rv == 1) {
  939. crb_win_unlock(adapter);
  940. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  941. }
  942. return 0;
  943. }
  944. int
  945. netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter,
  946. ulong off, void *data, int len)
  947. {
  948. unsigned long flags = 0;
  949. int rv;
  950. rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len);
  951. if (rv == -1) {
  952. printk(KERN_ERR "%s: invalid offset: 0x%016lx\n",
  953. __func__, off);
  954. dump_stack();
  955. return -1;
  956. }
  957. if (rv == 1) {
  958. write_lock_irqsave(&adapter->adapter_lock, flags);
  959. crb_win_lock(adapter);
  960. netxen_nic_pci_set_crbwindow_2M(adapter, &off);
  961. }
  962. DPRINTK(1, INFO, "read from offset %lx, len=%d\n", off, len);
  963. switch (len) {
  964. case 1:
  965. *(uint8_t *)data = readb((void *)off);
  966. break;
  967. case 2:
  968. *(uint16_t *)data = readw((void *)off);
  969. break;
  970. case 4:
  971. *(uint32_t *)data = readl((void *)off);
  972. break;
  973. case 8:
  974. *(uint64_t *)data = readq((void *)off);
  975. break;
  976. default:
  977. break;
  978. }
  979. DPRINTK(1, INFO, "read %lx\n", *(unsigned long *)data);
  980. if (rv == 1) {
  981. crb_win_unlock(adapter);
  982. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  983. }
  984. return 0;
  985. }
  986. void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val)
  987. {
  988. adapter->hw_write_wx(adapter, off, &val, 4);
  989. }
  990. int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off)
  991. {
  992. int val;
  993. adapter->hw_read_wx(adapter, off, &val, 4);
  994. return val;
  995. }
  996. /* Change the window to 0, write and change back to window 1. */
  997. void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value)
  998. {
  999. adapter->hw_write_wx(adapter, index, &value, 4);
  1000. }
  1001. /* Change the window to 0, read and change back to window 1. */
  1002. void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value)
  1003. {
  1004. adapter->hw_read_wx(adapter, index, value, 4);
  1005. }
  1006. void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value)
  1007. {
  1008. adapter->hw_write_wx(adapter, index, &value, 4);
  1009. }
  1010. void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value)
  1011. {
  1012. adapter->hw_read_wx(adapter, index, value, 4);
  1013. }
  1014. /*
  1015. * check memory access boundary.
  1016. * used by test agent. support ddr access only for now
  1017. */
  1018. static unsigned long
  1019. netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter,
  1020. unsigned long long addr, int size)
  1021. {
  1022. if (!ADDR_IN_RANGE(addr,
  1023. NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
  1024. !ADDR_IN_RANGE(addr+size-1,
  1025. NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) ||
  1026. ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
  1027. return 0;
  1028. }
  1029. return 1;
  1030. }
  1031. static int netxen_pci_set_window_warning_count;
  1032. unsigned long
  1033. netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
  1034. unsigned long long addr)
  1035. {
  1036. void __iomem *offset;
  1037. int window;
  1038. unsigned long long qdr_max;
  1039. uint8_t func = adapter->ahw.pci_func;
  1040. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1041. qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
  1042. } else {
  1043. qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
  1044. }
  1045. if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1046. /* DDR network side */
  1047. addr -= NETXEN_ADDR_DDR_NET;
  1048. window = (addr >> 25) & 0x3ff;
  1049. if (adapter->ahw.ddr_mn_window != window) {
  1050. adapter->ahw.ddr_mn_window = window;
  1051. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  1052. NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func)));
  1053. writel(window, offset);
  1054. /* MUST make sure window is set before we forge on... */
  1055. readl(offset);
  1056. }
  1057. addr -= (window * NETXEN_WINDOW_ONE);
  1058. addr += NETXEN_PCI_DDR_NET;
  1059. } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1060. addr -= NETXEN_ADDR_OCM0;
  1061. addr += NETXEN_PCI_OCM0;
  1062. } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1063. addr -= NETXEN_ADDR_OCM1;
  1064. addr += NETXEN_PCI_OCM1;
  1065. } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
  1066. /* QDR network side */
  1067. addr -= NETXEN_ADDR_QDR_NET;
  1068. window = (addr >> 22) & 0x3f;
  1069. if (adapter->ahw.qdr_sn_window != window) {
  1070. adapter->ahw.qdr_sn_window = window;
  1071. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  1072. NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func)));
  1073. writel((window << 22), offset);
  1074. /* MUST make sure window is set before we forge on... */
  1075. readl(offset);
  1076. }
  1077. addr -= (window * 0x400000);
  1078. addr += NETXEN_PCI_QDR_NET;
  1079. } else {
  1080. /*
  1081. * peg gdb frequently accesses memory that doesn't exist,
  1082. * this limits the chit chat so debugging isn't slowed down.
  1083. */
  1084. if ((netxen_pci_set_window_warning_count++ < 8)
  1085. || (netxen_pci_set_window_warning_count % 64 == 0))
  1086. printk("%s: Warning:netxen_nic_pci_set_window()"
  1087. " Unknown address range!\n",
  1088. netxen_nic_driver_name);
  1089. addr = -1UL;
  1090. }
  1091. return addr;
  1092. }
  1093. /*
  1094. * Note : only 32-bit writes!
  1095. */
  1096. int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter,
  1097. u64 off, u32 data)
  1098. {
  1099. writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off)));
  1100. return 0;
  1101. }
  1102. u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off)
  1103. {
  1104. return readl((void __iomem *)(pci_base_offset(adapter, off)));
  1105. }
  1106. void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter,
  1107. u64 off, u32 data)
  1108. {
  1109. writel(data, NETXEN_CRB_NORMALIZE(adapter, off));
  1110. }
  1111. u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off)
  1112. {
  1113. return readl(NETXEN_CRB_NORMALIZE(adapter, off));
  1114. }
  1115. unsigned long
  1116. netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
  1117. unsigned long long addr)
  1118. {
  1119. int window;
  1120. u32 win_read;
  1121. if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1122. /* DDR network side */
  1123. window = MN_WIN(addr);
  1124. adapter->ahw.ddr_mn_window = window;
  1125. adapter->hw_write_wx(adapter,
  1126. adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
  1127. &window, 4);
  1128. adapter->hw_read_wx(adapter,
  1129. adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
  1130. &win_read, 4);
  1131. if ((win_read << 17) != window) {
  1132. printk(KERN_INFO "Written MNwin (0x%x) != "
  1133. "Read MNwin (0x%x)\n", window, win_read);
  1134. }
  1135. addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET;
  1136. } else if (ADDR_IN_RANGE(addr,
  1137. NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1138. if ((addr & 0x00ff800) == 0xff800) {
  1139. printk("%s: QM access not handled.\n", __func__);
  1140. addr = -1UL;
  1141. }
  1142. window = OCM_WIN(addr);
  1143. adapter->ahw.ddr_mn_window = window;
  1144. adapter->hw_write_wx(adapter,
  1145. adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
  1146. &window, 4);
  1147. adapter->hw_read_wx(adapter,
  1148. adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE,
  1149. &win_read, 4);
  1150. if ((win_read >> 7) != window) {
  1151. printk(KERN_INFO "%s: Written OCMwin (0x%x) != "
  1152. "Read OCMwin (0x%x)\n",
  1153. __func__, window, win_read);
  1154. }
  1155. addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M;
  1156. } else if (ADDR_IN_RANGE(addr,
  1157. NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1158. /* QDR network side */
  1159. window = MS_WIN(addr);
  1160. adapter->ahw.qdr_sn_window = window;
  1161. adapter->hw_write_wx(adapter,
  1162. adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
  1163. &window, 4);
  1164. adapter->hw_read_wx(adapter,
  1165. adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE,
  1166. &win_read, 4);
  1167. if (win_read != window) {
  1168. printk(KERN_INFO "%s: Written MSwin (0x%x) != "
  1169. "Read MSwin (0x%x)\n",
  1170. __func__, window, win_read);
  1171. }
  1172. addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET;
  1173. } else {
  1174. /*
  1175. * peg gdb frequently accesses memory that doesn't exist,
  1176. * this limits the chit chat so debugging isn't slowed down.
  1177. */
  1178. if ((netxen_pci_set_window_warning_count++ < 8)
  1179. || (netxen_pci_set_window_warning_count%64 == 0)) {
  1180. printk("%s: Warning:%s Unknown address range!\n",
  1181. __func__, netxen_nic_driver_name);
  1182. }
  1183. addr = -1UL;
  1184. }
  1185. return addr;
  1186. }
  1187. static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter,
  1188. unsigned long long addr)
  1189. {
  1190. int window;
  1191. unsigned long long qdr_max;
  1192. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  1193. qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2;
  1194. else
  1195. qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3;
  1196. if (ADDR_IN_RANGE(addr,
  1197. NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1198. /* DDR network side */
  1199. BUG(); /* MN access can not come here */
  1200. } else if (ADDR_IN_RANGE(addr,
  1201. NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1202. return 1;
  1203. } else if (ADDR_IN_RANGE(addr,
  1204. NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1205. return 1;
  1206. } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) {
  1207. /* QDR network side */
  1208. window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f;
  1209. if (adapter->ahw.qdr_sn_window == window)
  1210. return 1;
  1211. }
  1212. return 0;
  1213. }
  1214. static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter,
  1215. u64 off, void *data, int size)
  1216. {
  1217. unsigned long flags;
  1218. void *addr;
  1219. int ret = 0;
  1220. u64 start;
  1221. uint8_t *mem_ptr = NULL;
  1222. unsigned long mem_base;
  1223. unsigned long mem_page;
  1224. write_lock_irqsave(&adapter->adapter_lock, flags);
  1225. /*
  1226. * If attempting to access unknown address or straddle hw windows,
  1227. * do not access.
  1228. */
  1229. start = adapter->pci_set_window(adapter, off);
  1230. if ((start == -1UL) ||
  1231. (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
  1232. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1233. printk(KERN_ERR "%s out of bound pci memory access. "
  1234. "offset is 0x%llx\n", netxen_nic_driver_name,
  1235. (unsigned long long)off);
  1236. return -1;
  1237. }
  1238. addr = (void *)(pci_base_offset(adapter, start));
  1239. if (!addr) {
  1240. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1241. mem_base = pci_resource_start(adapter->pdev, 0);
  1242. mem_page = start & PAGE_MASK;
  1243. /* Map two pages whenever user tries to access addresses in two
  1244. consecutive pages.
  1245. */
  1246. if (mem_page != ((start + size - 1) & PAGE_MASK))
  1247. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
  1248. else
  1249. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
  1250. if (mem_ptr == 0UL) {
  1251. *(uint8_t *)data = 0;
  1252. return -1;
  1253. }
  1254. addr = mem_ptr;
  1255. addr += start & (PAGE_SIZE - 1);
  1256. write_lock_irqsave(&adapter->adapter_lock, flags);
  1257. }
  1258. switch (size) {
  1259. case 1:
  1260. *(uint8_t *)data = readb(addr);
  1261. break;
  1262. case 2:
  1263. *(uint16_t *)data = readw(addr);
  1264. break;
  1265. case 4:
  1266. *(uint32_t *)data = readl(addr);
  1267. break;
  1268. case 8:
  1269. *(uint64_t *)data = readq(addr);
  1270. break;
  1271. default:
  1272. ret = -1;
  1273. break;
  1274. }
  1275. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1276. DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
  1277. if (mem_ptr)
  1278. iounmap(mem_ptr);
  1279. return ret;
  1280. }
  1281. static int
  1282. netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off,
  1283. void *data, int size)
  1284. {
  1285. unsigned long flags;
  1286. void *addr;
  1287. int ret = 0;
  1288. u64 start;
  1289. uint8_t *mem_ptr = NULL;
  1290. unsigned long mem_base;
  1291. unsigned long mem_page;
  1292. write_lock_irqsave(&adapter->adapter_lock, flags);
  1293. /*
  1294. * If attempting to access unknown address or straddle hw windows,
  1295. * do not access.
  1296. */
  1297. start = adapter->pci_set_window(adapter, off);
  1298. if ((start == -1UL) ||
  1299. (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) {
  1300. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1301. printk(KERN_ERR "%s out of bound pci memory access. "
  1302. "offset is 0x%llx\n", netxen_nic_driver_name,
  1303. (unsigned long long)off);
  1304. return -1;
  1305. }
  1306. addr = (void *)(pci_base_offset(adapter, start));
  1307. if (!addr) {
  1308. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1309. mem_base = pci_resource_start(adapter->pdev, 0);
  1310. mem_page = start & PAGE_MASK;
  1311. /* Map two pages whenever user tries to access addresses in two
  1312. * consecutive pages.
  1313. */
  1314. if (mem_page != ((start + size - 1) & PAGE_MASK))
  1315. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
  1316. else
  1317. mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
  1318. if (mem_ptr == 0UL)
  1319. return -1;
  1320. addr = mem_ptr;
  1321. addr += start & (PAGE_SIZE - 1);
  1322. write_lock_irqsave(&adapter->adapter_lock, flags);
  1323. }
  1324. switch (size) {
  1325. case 1:
  1326. writeb(*(uint8_t *)data, addr);
  1327. break;
  1328. case 2:
  1329. writew(*(uint16_t *)data, addr);
  1330. break;
  1331. case 4:
  1332. writel(*(uint32_t *)data, addr);
  1333. break;
  1334. case 8:
  1335. writeq(*(uint64_t *)data, addr);
  1336. break;
  1337. default:
  1338. ret = -1;
  1339. break;
  1340. }
  1341. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1342. DPRINTK(1, INFO, "writing data %llx to offset %llx\n",
  1343. *(unsigned long long *)data, start);
  1344. if (mem_ptr)
  1345. iounmap(mem_ptr);
  1346. return ret;
  1347. }
  1348. #define MAX_CTL_CHECK 1000
  1349. int
  1350. netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
  1351. u64 off, void *data, int size)
  1352. {
  1353. unsigned long flags, mem_crb;
  1354. int i, j, ret = 0, loop, sz[2], off0;
  1355. uint32_t temp;
  1356. uint64_t off8, tmpw, word[2] = {0, 0};
  1357. /*
  1358. * If not MN, go check for MS or invalid.
  1359. */
  1360. if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
  1361. return netxen_nic_pci_mem_write_direct(adapter,
  1362. off, data, size);
  1363. off8 = off & 0xfffffff8;
  1364. off0 = off & 0x7;
  1365. sz[0] = (size < (8 - off0)) ? size : (8 - off0);
  1366. sz[1] = size - sz[0];
  1367. loop = ((off0 + size - 1) >> 3) + 1;
  1368. mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
  1369. if ((size != 8) || (off0 != 0)) {
  1370. for (i = 0; i < loop; i++) {
  1371. if (adapter->pci_mem_read(adapter,
  1372. off8 + (i << 3), &word[i], 8))
  1373. return -1;
  1374. }
  1375. }
  1376. switch (size) {
  1377. case 1:
  1378. tmpw = *((uint8_t *)data);
  1379. break;
  1380. case 2:
  1381. tmpw = *((uint16_t *)data);
  1382. break;
  1383. case 4:
  1384. tmpw = *((uint32_t *)data);
  1385. break;
  1386. case 8:
  1387. default:
  1388. tmpw = *((uint64_t *)data);
  1389. break;
  1390. }
  1391. word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
  1392. word[0] |= tmpw << (off0 * 8);
  1393. if (loop == 2) {
  1394. word[1] &= ~(~0ULL << (sz[1] * 8));
  1395. word[1] |= tmpw >> (sz[0] * 8);
  1396. }
  1397. write_lock_irqsave(&adapter->adapter_lock, flags);
  1398. netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  1399. for (i = 0; i < loop; i++) {
  1400. writel((uint32_t)(off8 + (i << 3)),
  1401. (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
  1402. writel(0,
  1403. (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
  1404. writel(word[i] & 0xffffffff,
  1405. (void *)(mem_crb+MIU_TEST_AGT_WRDATA_LO));
  1406. writel((word[i] >> 32) & 0xffffffff,
  1407. (void *)(mem_crb+MIU_TEST_AGT_WRDATA_HI));
  1408. writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
  1409. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1410. writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE,
  1411. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1412. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1413. temp = readl(
  1414. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1415. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1416. break;
  1417. }
  1418. if (j >= MAX_CTL_CHECK) {
  1419. printk("%s: %s Fail to write through agent\n",
  1420. __func__, netxen_nic_driver_name);
  1421. ret = -1;
  1422. break;
  1423. }
  1424. }
  1425. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  1426. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1427. return ret;
  1428. }
  1429. int
  1430. netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
  1431. u64 off, void *data, int size)
  1432. {
  1433. unsigned long flags, mem_crb;
  1434. int i, j = 0, k, start, end, loop, sz[2], off0[2];
  1435. uint32_t temp;
  1436. uint64_t off8, val, word[2] = {0, 0};
  1437. /*
  1438. * If not MN, go check for MS or invalid.
  1439. */
  1440. if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
  1441. return netxen_nic_pci_mem_read_direct(adapter, off, data, size);
  1442. off8 = off & 0xfffffff8;
  1443. off0[0] = off & 0x7;
  1444. off0[1] = 0;
  1445. sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
  1446. sz[1] = size - sz[0];
  1447. loop = ((off0[0] + size - 1) >> 3) + 1;
  1448. mem_crb = (unsigned long)pci_base_offset(adapter, NETXEN_CRB_DDR_NET);
  1449. write_lock_irqsave(&adapter->adapter_lock, flags);
  1450. netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  1451. for (i = 0; i < loop; i++) {
  1452. writel((uint32_t)(off8 + (i << 3)),
  1453. (void *)(mem_crb+MIU_TEST_AGT_ADDR_LO));
  1454. writel(0,
  1455. (void *)(mem_crb+MIU_TEST_AGT_ADDR_HI));
  1456. writel(MIU_TA_CTL_ENABLE,
  1457. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1458. writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE,
  1459. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1460. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1461. temp = readl(
  1462. (void *)(mem_crb+MIU_TEST_AGT_CTRL));
  1463. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1464. break;
  1465. }
  1466. if (j >= MAX_CTL_CHECK) {
  1467. printk(KERN_ERR "%s: %s Fail to read through agent\n",
  1468. __func__, netxen_nic_driver_name);
  1469. break;
  1470. }
  1471. start = off0[i] >> 2;
  1472. end = (off0[i] + sz[i] - 1) >> 2;
  1473. for (k = start; k <= end; k++) {
  1474. word[i] |= ((uint64_t) readl(
  1475. (void *)(mem_crb +
  1476. MIU_TEST_AGT_RDDATA(k))) << (32*k));
  1477. }
  1478. }
  1479. netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  1480. write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1481. if (j >= MAX_CTL_CHECK)
  1482. return -1;
  1483. if (sz[0] == 8) {
  1484. val = word[0];
  1485. } else {
  1486. val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
  1487. ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
  1488. }
  1489. switch (size) {
  1490. case 1:
  1491. *(uint8_t *)data = val;
  1492. break;
  1493. case 2:
  1494. *(uint16_t *)data = val;
  1495. break;
  1496. case 4:
  1497. *(uint32_t *)data = val;
  1498. break;
  1499. case 8:
  1500. *(uint64_t *)data = val;
  1501. break;
  1502. }
  1503. DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
  1504. return 0;
  1505. }
  1506. int
  1507. netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
  1508. u64 off, void *data, int size)
  1509. {
  1510. int i, j, ret = 0, loop, sz[2], off0;
  1511. uint32_t temp;
  1512. uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
  1513. /*
  1514. * If not MN, go check for MS or invalid.
  1515. */
  1516. if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
  1517. mem_crb = NETXEN_CRB_QDR_NET;
  1518. else {
  1519. mem_crb = NETXEN_CRB_DDR_NET;
  1520. if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
  1521. return netxen_nic_pci_mem_write_direct(adapter,
  1522. off, data, size);
  1523. }
  1524. off8 = off & 0xfffffff8;
  1525. off0 = off & 0x7;
  1526. sz[0] = (size < (8 - off0)) ? size : (8 - off0);
  1527. sz[1] = size - sz[0];
  1528. loop = ((off0 + size - 1) >> 3) + 1;
  1529. if ((size != 8) || (off0 != 0)) {
  1530. for (i = 0; i < loop; i++) {
  1531. if (adapter->pci_mem_read(adapter, off8 + (i << 3),
  1532. &word[i], 8))
  1533. return -1;
  1534. }
  1535. }
  1536. switch (size) {
  1537. case 1:
  1538. tmpw = *((uint8_t *)data);
  1539. break;
  1540. case 2:
  1541. tmpw = *((uint16_t *)data);
  1542. break;
  1543. case 4:
  1544. tmpw = *((uint32_t *)data);
  1545. break;
  1546. case 8:
  1547. default:
  1548. tmpw = *((uint64_t *)data);
  1549. break;
  1550. }
  1551. word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
  1552. word[0] |= tmpw << (off0 * 8);
  1553. if (loop == 2) {
  1554. word[1] &= ~(~0ULL << (sz[1] * 8));
  1555. word[1] |= tmpw >> (sz[0] * 8);
  1556. }
  1557. /*
  1558. * don't lock here - write_wx gets the lock if each time
  1559. * write_lock_irqsave(&adapter->adapter_lock, flags);
  1560. * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  1561. */
  1562. for (i = 0; i < loop; i++) {
  1563. temp = off8 + (i << 3);
  1564. adapter->hw_write_wx(adapter,
  1565. mem_crb+MIU_TEST_AGT_ADDR_LO, &temp, 4);
  1566. temp = 0;
  1567. adapter->hw_write_wx(adapter,
  1568. mem_crb+MIU_TEST_AGT_ADDR_HI, &temp, 4);
  1569. temp = word[i] & 0xffffffff;
  1570. adapter->hw_write_wx(adapter,
  1571. mem_crb+MIU_TEST_AGT_WRDATA_LO, &temp, 4);
  1572. temp = (word[i] >> 32) & 0xffffffff;
  1573. adapter->hw_write_wx(adapter,
  1574. mem_crb+MIU_TEST_AGT_WRDATA_HI, &temp, 4);
  1575. temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
  1576. adapter->hw_write_wx(adapter,
  1577. mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
  1578. temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
  1579. adapter->hw_write_wx(adapter,
  1580. mem_crb+MIU_TEST_AGT_CTRL, &temp, 4);
  1581. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1582. adapter->hw_read_wx(adapter,
  1583. mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
  1584. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1585. break;
  1586. }
  1587. if (j >= MAX_CTL_CHECK) {
  1588. printk(KERN_ERR "%s: Fail to write through agent\n",
  1589. netxen_nic_driver_name);
  1590. ret = -1;
  1591. break;
  1592. }
  1593. }
  1594. /*
  1595. * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  1596. * write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1597. */
  1598. return ret;
  1599. }
  1600. int
  1601. netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
  1602. u64 off, void *data, int size)
  1603. {
  1604. int i, j = 0, k, start, end, loop, sz[2], off0[2];
  1605. uint32_t temp;
  1606. uint64_t off8, val, mem_crb, word[2] = {0, 0};
  1607. /*
  1608. * If not MN, go check for MS or invalid.
  1609. */
  1610. if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3)
  1611. mem_crb = NETXEN_CRB_QDR_NET;
  1612. else {
  1613. mem_crb = NETXEN_CRB_DDR_NET;
  1614. if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0)
  1615. return netxen_nic_pci_mem_read_direct(adapter,
  1616. off, data, size);
  1617. }
  1618. off8 = off & 0xfffffff8;
  1619. off0[0] = off & 0x7;
  1620. off0[1] = 0;
  1621. sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]);
  1622. sz[1] = size - sz[0];
  1623. loop = ((off0[0] + size - 1) >> 3) + 1;
  1624. /*
  1625. * don't lock here - write_wx gets the lock if each time
  1626. * write_lock_irqsave(&adapter->adapter_lock, flags);
  1627. * netxen_nic_pci_change_crbwindow_128M(adapter, 0);
  1628. */
  1629. for (i = 0; i < loop; i++) {
  1630. temp = off8 + (i << 3);
  1631. adapter->hw_write_wx(adapter,
  1632. mem_crb + MIU_TEST_AGT_ADDR_LO, &temp, 4);
  1633. temp = 0;
  1634. adapter->hw_write_wx(adapter,
  1635. mem_crb + MIU_TEST_AGT_ADDR_HI, &temp, 4);
  1636. temp = MIU_TA_CTL_ENABLE;
  1637. adapter->hw_write_wx(adapter,
  1638. mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
  1639. temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
  1640. adapter->hw_write_wx(adapter,
  1641. mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
  1642. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1643. adapter->hw_read_wx(adapter,
  1644. mem_crb + MIU_TEST_AGT_CTRL, &temp, 4);
  1645. if ((temp & MIU_TA_CTL_BUSY) == 0)
  1646. break;
  1647. }
  1648. if (j >= MAX_CTL_CHECK) {
  1649. printk(KERN_ERR "%s: Fail to read through agent\n",
  1650. netxen_nic_driver_name);
  1651. break;
  1652. }
  1653. start = off0[i] >> 2;
  1654. end = (off0[i] + sz[i] - 1) >> 2;
  1655. for (k = start; k <= end; k++) {
  1656. adapter->hw_read_wx(adapter,
  1657. mem_crb + MIU_TEST_AGT_RDDATA(k), &temp, 4);
  1658. word[i] |= ((uint64_t)temp << (32 * k));
  1659. }
  1660. }
  1661. /*
  1662. * netxen_nic_pci_change_crbwindow_128M(adapter, 1);
  1663. * write_unlock_irqrestore(&adapter->adapter_lock, flags);
  1664. */
  1665. if (j >= MAX_CTL_CHECK)
  1666. return -1;
  1667. if (sz[0] == 8) {
  1668. val = word[0];
  1669. } else {
  1670. val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
  1671. ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
  1672. }
  1673. switch (size) {
  1674. case 1:
  1675. *(uint8_t *)data = val;
  1676. break;
  1677. case 2:
  1678. *(uint16_t *)data = val;
  1679. break;
  1680. case 4:
  1681. *(uint32_t *)data = val;
  1682. break;
  1683. case 8:
  1684. *(uint64_t *)data = val;
  1685. break;
  1686. }
  1687. DPRINTK(1, INFO, "read %llx\n", *(unsigned long long *)data);
  1688. return 0;
  1689. }
  1690. /*
  1691. * Note : only 32-bit writes!
  1692. */
  1693. int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter,
  1694. u64 off, u32 data)
  1695. {
  1696. adapter->hw_write_wx(adapter, off, &data, 4);
  1697. return 0;
  1698. }
  1699. u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off)
  1700. {
  1701. u32 temp;
  1702. adapter->hw_read_wx(adapter, off, &temp, 4);
  1703. return temp;
  1704. }
  1705. void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter,
  1706. u64 off, u32 data)
  1707. {
  1708. adapter->hw_write_wx(adapter, off, &data, 4);
  1709. }
  1710. u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off)
  1711. {
  1712. u32 temp;
  1713. adapter->hw_read_wx(adapter, off, &temp, 4);
  1714. return temp;
  1715. }
  1716. #if 0
  1717. int
  1718. netxen_nic_erase_pxe(struct netxen_adapter *adapter)
  1719. {
  1720. if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) {
  1721. printk(KERN_ERR "%s: erase pxe failed\n",
  1722. netxen_nic_driver_name);
  1723. return -1;
  1724. }
  1725. return 0;
  1726. }
  1727. #endif /* 0 */
  1728. int netxen_nic_get_board_info(struct netxen_adapter *adapter)
  1729. {
  1730. int rv = 0;
  1731. int addr = NETXEN_BRDCFG_START;
  1732. struct netxen_board_info *boardinfo;
  1733. int index;
  1734. u32 *ptr32;
  1735. boardinfo = &adapter->ahw.boardcfg;
  1736. ptr32 = (u32 *) boardinfo;
  1737. for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32);
  1738. index++) {
  1739. if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
  1740. return -EIO;
  1741. }
  1742. ptr32++;
  1743. addr += sizeof(u32);
  1744. }
  1745. if (boardinfo->magic != NETXEN_BDINFO_MAGIC) {
  1746. printk("%s: ERROR reading %s board config."
  1747. " Read %x, expected %x\n", netxen_nic_driver_name,
  1748. netxen_nic_driver_name,
  1749. boardinfo->magic, NETXEN_BDINFO_MAGIC);
  1750. rv = -1;
  1751. }
  1752. if (boardinfo->header_version != NETXEN_BDINFO_VERSION) {
  1753. printk("%s: Unknown board config version."
  1754. " Read %x, expected %x\n", netxen_nic_driver_name,
  1755. boardinfo->header_version, NETXEN_BDINFO_VERSION);
  1756. rv = -1;
  1757. }
  1758. DPRINTK(INFO, "Discovered board type:0x%x ", boardinfo->board_type);
  1759. switch ((netxen_brdtype_t) boardinfo->board_type) {
  1760. case NETXEN_BRDTYPE_P2_SB35_4G:
  1761. adapter->ahw.board_type = NETXEN_NIC_GBE;
  1762. break;
  1763. case NETXEN_BRDTYPE_P2_SB31_10G:
  1764. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  1765. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  1766. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  1767. case NETXEN_BRDTYPE_P3_HMEZ:
  1768. case NETXEN_BRDTYPE_P3_XG_LOM:
  1769. case NETXEN_BRDTYPE_P3_10G_CX4:
  1770. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  1771. case NETXEN_BRDTYPE_P3_IMEZ:
  1772. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  1773. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  1774. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  1775. case NETXEN_BRDTYPE_P3_10G_XFP:
  1776. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  1777. adapter->ahw.board_type = NETXEN_NIC_XGBE;
  1778. break;
  1779. case NETXEN_BRDTYPE_P1_BD:
  1780. case NETXEN_BRDTYPE_P1_SB:
  1781. case NETXEN_BRDTYPE_P1_SMAX:
  1782. case NETXEN_BRDTYPE_P1_SOCK:
  1783. case NETXEN_BRDTYPE_P3_REF_QG:
  1784. case NETXEN_BRDTYPE_P3_4_GB:
  1785. case NETXEN_BRDTYPE_P3_4_GB_MM:
  1786. adapter->ahw.board_type = NETXEN_NIC_GBE;
  1787. break;
  1788. default:
  1789. printk("%s: Unknown(%x)\n", netxen_nic_driver_name,
  1790. boardinfo->board_type);
  1791. rv = -ENODEV;
  1792. break;
  1793. }
  1794. return rv;
  1795. }
  1796. /* NIU access sections */
  1797. int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu)
  1798. {
  1799. new_mtu += MTU_FUDGE_FACTOR;
  1800. netxen_nic_write_w0(adapter,
  1801. NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port),
  1802. new_mtu);
  1803. return 0;
  1804. }
  1805. int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
  1806. {
  1807. new_mtu += MTU_FUDGE_FACTOR;
  1808. if (adapter->physical_port == 0)
  1809. netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE,
  1810. new_mtu);
  1811. else
  1812. netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE,
  1813. new_mtu);
  1814. return 0;
  1815. }
  1816. void
  1817. netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
  1818. unsigned long off, int data)
  1819. {
  1820. adapter->hw_write_wx(adapter, off, &data, 4);
  1821. }
  1822. void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
  1823. {
  1824. __u32 status;
  1825. __u32 autoneg;
  1826. __u32 mode;
  1827. __u32 port_mode;
  1828. netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
  1829. if (netxen_get_niu_enable_ge(mode)) { /* Gb 10/100/1000 Mbps mode */
  1830. adapter->hw_read_wx(adapter,
  1831. NETXEN_PORT_MODE_ADDR, &port_mode, 4);
  1832. if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
  1833. adapter->link_speed = SPEED_1000;
  1834. adapter->link_duplex = DUPLEX_FULL;
  1835. adapter->link_autoneg = AUTONEG_DISABLE;
  1836. return;
  1837. }
  1838. if (adapter->phy_read
  1839. && adapter->phy_read(adapter,
  1840. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  1841. &status) == 0) {
  1842. if (netxen_get_phy_link(status)) {
  1843. switch (netxen_get_phy_speed(status)) {
  1844. case 0:
  1845. adapter->link_speed = SPEED_10;
  1846. break;
  1847. case 1:
  1848. adapter->link_speed = SPEED_100;
  1849. break;
  1850. case 2:
  1851. adapter->link_speed = SPEED_1000;
  1852. break;
  1853. default:
  1854. adapter->link_speed = -1;
  1855. break;
  1856. }
  1857. switch (netxen_get_phy_duplex(status)) {
  1858. case 0:
  1859. adapter->link_duplex = DUPLEX_HALF;
  1860. break;
  1861. case 1:
  1862. adapter->link_duplex = DUPLEX_FULL;
  1863. break;
  1864. default:
  1865. adapter->link_duplex = -1;
  1866. break;
  1867. }
  1868. if (adapter->phy_read
  1869. && adapter->phy_read(adapter,
  1870. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  1871. &autoneg) != 0)
  1872. adapter->link_autoneg = autoneg;
  1873. } else
  1874. goto link_down;
  1875. } else {
  1876. link_down:
  1877. adapter->link_speed = -1;
  1878. adapter->link_duplex = -1;
  1879. }
  1880. }
  1881. }
  1882. void netxen_nic_flash_print(struct netxen_adapter *adapter)
  1883. {
  1884. u32 fw_major = 0;
  1885. u32 fw_minor = 0;
  1886. u32 fw_build = 0;
  1887. char brd_name[NETXEN_MAX_SHORT_NAME];
  1888. char serial_num[32];
  1889. int i, addr;
  1890. __le32 *ptr32;
  1891. struct netxen_board_info *board_info = &(adapter->ahw.boardcfg);
  1892. adapter->driver_mismatch = 0;
  1893. ptr32 = (u32 *)&serial_num;
  1894. addr = NETXEN_USER_START +
  1895. offsetof(struct netxen_new_user_info, serial_num);
  1896. for (i = 0; i < 8; i++) {
  1897. if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) {
  1898. printk("%s: ERROR reading %s board userarea.\n",
  1899. netxen_nic_driver_name,
  1900. netxen_nic_driver_name);
  1901. adapter->driver_mismatch = 1;
  1902. return;
  1903. }
  1904. ptr32++;
  1905. addr += sizeof(u32);
  1906. }
  1907. adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MAJOR, &fw_major, 4);
  1908. adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MINOR, &fw_minor, 4);
  1909. adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_SUB, &fw_build, 4);
  1910. adapter->fw_major = fw_major;
  1911. if (adapter->portnum == 0) {
  1912. get_brd_name_by_type(board_info->board_type, brd_name);
  1913. printk("NetXen %s Board S/N %s Chip id 0x%x\n",
  1914. brd_name, serial_num, board_info->chip_id);
  1915. printk("NetXen Firmware version %d.%d.%d\n", fw_major,
  1916. fw_minor, fw_build);
  1917. }
  1918. if (NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build) <
  1919. NETXEN_VERSION_CODE(3, 4, 216)) {
  1920. adapter->driver_mismatch = 1;
  1921. printk(KERN_ERR "%s: firmware version %d.%d.%d unsupported\n",
  1922. netxen_nic_driver_name,
  1923. fw_major, fw_minor, fw_build);
  1924. return;
  1925. }
  1926. }