netxen_nic_hw.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  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, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  19. * MA 02111-1307, USA.
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called "COPYING".
  23. *
  24. */
  25. #include <linux/slab.h>
  26. #include "netxen_nic.h"
  27. #include "netxen_nic_hw.h"
  28. #include <net/ip.h>
  29. #define MASK(n) ((1ULL<<(n))-1)
  30. #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
  31. #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
  32. #define MS_WIN(addr) (addr & 0x0ffc0000)
  33. #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
  34. #define CRB_BLK(off) ((off >> 20) & 0x3f)
  35. #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
  36. #define CRB_WINDOW_2M (0x130060)
  37. #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
  38. #define CRB_INDIRECT_2M (0x1e0000UL)
  39. static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
  40. void __iomem *addr, u32 data);
  41. static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
  42. void __iomem *addr);
  43. #ifndef readq
  44. static inline u64 readq(void __iomem *addr)
  45. {
  46. return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
  47. }
  48. #endif
  49. #ifndef writeq
  50. static inline void writeq(u64 val, void __iomem *addr)
  51. {
  52. writel(((u32) (val)), (addr));
  53. writel(((u32) (val >> 32)), (addr + 4));
  54. }
  55. #endif
  56. #define PCI_OFFSET_FIRST_RANGE(adapter, off) \
  57. ((adapter)->ahw.pci_base0 + (off))
  58. #define PCI_OFFSET_SECOND_RANGE(adapter, off) \
  59. ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START)
  60. #define PCI_OFFSET_THIRD_RANGE(adapter, off) \
  61. ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START)
  62. static void __iomem *pci_base_offset(struct netxen_adapter *adapter,
  63. unsigned long off)
  64. {
  65. if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END))
  66. return PCI_OFFSET_FIRST_RANGE(adapter, off);
  67. if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END))
  68. return PCI_OFFSET_SECOND_RANGE(adapter, off);
  69. if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END))
  70. return PCI_OFFSET_THIRD_RANGE(adapter, off);
  71. return NULL;
  72. }
  73. static crb_128M_2M_block_map_t
  74. crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
  75. {{{0, 0, 0, 0} } }, /* 0: PCI */
  76. {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
  77. {1, 0x0110000, 0x0120000, 0x130000},
  78. {1, 0x0120000, 0x0122000, 0x124000},
  79. {1, 0x0130000, 0x0132000, 0x126000},
  80. {1, 0x0140000, 0x0142000, 0x128000},
  81. {1, 0x0150000, 0x0152000, 0x12a000},
  82. {1, 0x0160000, 0x0170000, 0x110000},
  83. {1, 0x0170000, 0x0172000, 0x12e000},
  84. {0, 0x0000000, 0x0000000, 0x000000},
  85. {0, 0x0000000, 0x0000000, 0x000000},
  86. {0, 0x0000000, 0x0000000, 0x000000},
  87. {0, 0x0000000, 0x0000000, 0x000000},
  88. {0, 0x0000000, 0x0000000, 0x000000},
  89. {0, 0x0000000, 0x0000000, 0x000000},
  90. {1, 0x01e0000, 0x01e0800, 0x122000},
  91. {0, 0x0000000, 0x0000000, 0x000000} } },
  92. {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
  93. {{{0, 0, 0, 0} } }, /* 3: */
  94. {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
  95. {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
  96. {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
  97. {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
  98. {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
  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. {0, 0x0000000, 0x0000000, 0x000000},
  112. {0, 0x0000000, 0x0000000, 0x000000},
  113. {1, 0x08f0000, 0x08f2000, 0x172000} } },
  114. {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  128. {0, 0x0000000, 0x0000000, 0x000000},
  129. {1, 0x09f0000, 0x09f2000, 0x176000} } },
  130. {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  144. {0, 0x0000000, 0x0000000, 0x000000},
  145. {1, 0x0af0000, 0x0af2000, 0x17a000} } },
  146. {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
  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. {0, 0x0000000, 0x0000000, 0x000000},
  160. {0, 0x0000000, 0x0000000, 0x000000},
  161. {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
  162. {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
  163. {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
  164. {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
  165. {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
  166. {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
  167. {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
  168. {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
  169. {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
  170. {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
  171. {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
  172. {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
  173. {{{0, 0, 0, 0} } }, /* 23: */
  174. {{{0, 0, 0, 0} } }, /* 24: */
  175. {{{0, 0, 0, 0} } }, /* 25: */
  176. {{{0, 0, 0, 0} } }, /* 26: */
  177. {{{0, 0, 0, 0} } }, /* 27: */
  178. {{{0, 0, 0, 0} } }, /* 28: */
  179. {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
  180. {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
  181. {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
  182. {{{0} } }, /* 32: PCI */
  183. {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
  184. {1, 0x2110000, 0x2120000, 0x130000},
  185. {1, 0x2120000, 0x2122000, 0x124000},
  186. {1, 0x2130000, 0x2132000, 0x126000},
  187. {1, 0x2140000, 0x2142000, 0x128000},
  188. {1, 0x2150000, 0x2152000, 0x12a000},
  189. {1, 0x2160000, 0x2170000, 0x110000},
  190. {1, 0x2170000, 0x2172000, 0x12e000},
  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. {0, 0x0000000, 0x0000000, 0x000000},
  198. {0, 0x0000000, 0x0000000, 0x000000} } },
  199. {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
  200. {{{0} } }, /* 35: */
  201. {{{0} } }, /* 36: */
  202. {{{0} } }, /* 37: */
  203. {{{0} } }, /* 38: */
  204. {{{0} } }, /* 39: */
  205. {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
  206. {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
  207. {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
  208. {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
  209. {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
  210. {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
  211. {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
  212. {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
  213. {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
  214. {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
  215. {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
  216. {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
  217. {{{0} } }, /* 52: */
  218. {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
  219. {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
  220. {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
  221. {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
  222. {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
  223. {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
  224. {{{0} } }, /* 59: I2C0 */
  225. {{{0} } }, /* 60: I2C1 */
  226. {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
  227. {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
  228. {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
  229. };
  230. /*
  231. * top 12 bits of crb internal address (hub, agent)
  232. */
  233. static unsigned crb_hub_agt[64] =
  234. {
  235. 0,
  236. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  237. NETXEN_HW_CRB_HUB_AGT_ADR_MN,
  238. NETXEN_HW_CRB_HUB_AGT_ADR_MS,
  239. 0,
  240. NETXEN_HW_CRB_HUB_AGT_ADR_SRE,
  241. NETXEN_HW_CRB_HUB_AGT_ADR_NIU,
  242. NETXEN_HW_CRB_HUB_AGT_ADR_QMN,
  243. NETXEN_HW_CRB_HUB_AGT_ADR_SQN0,
  244. NETXEN_HW_CRB_HUB_AGT_ADR_SQN1,
  245. NETXEN_HW_CRB_HUB_AGT_ADR_SQN2,
  246. NETXEN_HW_CRB_HUB_AGT_ADR_SQN3,
  247. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  248. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  249. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  250. NETXEN_HW_CRB_HUB_AGT_ADR_PGN4,
  251. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  252. NETXEN_HW_CRB_HUB_AGT_ADR_PGN0,
  253. NETXEN_HW_CRB_HUB_AGT_ADR_PGN1,
  254. NETXEN_HW_CRB_HUB_AGT_ADR_PGN2,
  255. NETXEN_HW_CRB_HUB_AGT_ADR_PGN3,
  256. NETXEN_HW_CRB_HUB_AGT_ADR_PGND,
  257. NETXEN_HW_CRB_HUB_AGT_ADR_PGNI,
  258. NETXEN_HW_CRB_HUB_AGT_ADR_PGS0,
  259. NETXEN_HW_CRB_HUB_AGT_ADR_PGS1,
  260. NETXEN_HW_CRB_HUB_AGT_ADR_PGS2,
  261. NETXEN_HW_CRB_HUB_AGT_ADR_PGS3,
  262. 0,
  263. NETXEN_HW_CRB_HUB_AGT_ADR_PGSI,
  264. NETXEN_HW_CRB_HUB_AGT_ADR_SN,
  265. 0,
  266. NETXEN_HW_CRB_HUB_AGT_ADR_EG,
  267. 0,
  268. NETXEN_HW_CRB_HUB_AGT_ADR_PS,
  269. NETXEN_HW_CRB_HUB_AGT_ADR_CAM,
  270. 0,
  271. 0,
  272. 0,
  273. 0,
  274. 0,
  275. NETXEN_HW_CRB_HUB_AGT_ADR_TIMR,
  276. 0,
  277. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1,
  278. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2,
  279. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3,
  280. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4,
  281. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5,
  282. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6,
  283. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7,
  284. NETXEN_HW_CRB_HUB_AGT_ADR_XDMA,
  285. NETXEN_HW_CRB_HUB_AGT_ADR_I2Q,
  286. NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB,
  287. 0,
  288. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0,
  289. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8,
  290. NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9,
  291. NETXEN_HW_CRB_HUB_AGT_ADR_OCM0,
  292. 0,
  293. NETXEN_HW_CRB_HUB_AGT_ADR_SMB,
  294. NETXEN_HW_CRB_HUB_AGT_ADR_I2C0,
  295. NETXEN_HW_CRB_HUB_AGT_ADR_I2C1,
  296. 0,
  297. NETXEN_HW_CRB_HUB_AGT_ADR_PGNC,
  298. 0,
  299. };
  300. /* PCI Windowing for DDR regions. */
  301. #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */
  302. #define NETXEN_PCIE_SEM_TIMEOUT 10000
  303. static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu);
  304. int
  305. netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg)
  306. {
  307. int done = 0, timeout = 0;
  308. while (!done) {
  309. done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem)));
  310. if (done == 1)
  311. break;
  312. if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT)
  313. return -EIO;
  314. msleep(1);
  315. }
  316. if (id_reg)
  317. NXWR32(adapter, id_reg, adapter->portnum);
  318. return 0;
  319. }
  320. void
  321. netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem)
  322. {
  323. NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
  324. }
  325. static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
  326. {
  327. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  328. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447);
  329. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5);
  330. }
  331. return 0;
  332. }
  333. /* Disable an XG interface */
  334. static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter)
  335. {
  336. __u32 mac_cfg;
  337. u32 port = adapter->physical_port;
  338. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  339. return 0;
  340. if (port > NETXEN_NIU_MAX_XG_PORTS)
  341. return -EINVAL;
  342. mac_cfg = 0;
  343. if (NXWR32(adapter,
  344. NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg))
  345. return -EIO;
  346. return 0;
  347. }
  348. #define NETXEN_UNICAST_ADDR(port, index) \
  349. (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8))
  350. #define NETXEN_MCAST_ADDR(port, index) \
  351. (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8))
  352. #define MAC_HI(addr) \
  353. ((addr[2] << 16) | (addr[1] << 8) | (addr[0]))
  354. #define MAC_LO(addr) \
  355. ((addr[5] << 16) | (addr[4] << 8) | (addr[3]))
  356. static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
  357. {
  358. u32 mac_cfg;
  359. u32 cnt = 0;
  360. __u32 reg = 0x0200;
  361. u32 port = adapter->physical_port;
  362. u16 board_type = adapter->ahw.board_type;
  363. if (port > NETXEN_NIU_MAX_XG_PORTS)
  364. return -EINVAL;
  365. mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port));
  366. mac_cfg &= ~0x4;
  367. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
  368. if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) ||
  369. (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ))
  370. reg = (0x20 << port);
  371. NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg);
  372. mdelay(10);
  373. while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20)
  374. mdelay(10);
  375. if (cnt < 20) {
  376. reg = NXRD32(adapter,
  377. NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port));
  378. if (mode == NETXEN_NIU_PROMISC_MODE)
  379. reg = (reg | 0x2000UL);
  380. else
  381. reg = (reg & ~0x2000UL);
  382. if (mode == NETXEN_NIU_ALLMULTI_MODE)
  383. reg = (reg | 0x1000UL);
  384. else
  385. reg = (reg & ~0x1000UL);
  386. NXWR32(adapter,
  387. NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg);
  388. }
  389. mac_cfg |= 0x4;
  390. NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg);
  391. return 0;
  392. }
  393. static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
  394. {
  395. u32 mac_hi, mac_lo;
  396. u32 reg_hi, reg_lo;
  397. u8 phy = adapter->physical_port;
  398. if (phy >= NETXEN_NIU_MAX_XG_PORTS)
  399. return -EINVAL;
  400. mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24);
  401. mac_hi = addr[2] | ((u32)addr[3] << 8) |
  402. ((u32)addr[4] << 16) | ((u32)addr[5] << 24);
  403. reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy);
  404. reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy);
  405. /* write twice to flush */
  406. if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
  407. return -EIO;
  408. if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi))
  409. return -EIO;
  410. return 0;
  411. }
  412. static int
  413. netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter)
  414. {
  415. u32 val = 0;
  416. u16 port = adapter->physical_port;
  417. u8 *addr = adapter->mac_addr;
  418. if (adapter->mc_enabled)
  419. return 0;
  420. val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
  421. val |= (1UL << (28+port));
  422. NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
  423. /* add broadcast addr to filter */
  424. val = 0xffffff;
  425. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  426. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
  427. /* add station addr to filter */
  428. val = MAC_HI(addr);
  429. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val);
  430. val = MAC_LO(addr);
  431. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val);
  432. adapter->mc_enabled = 1;
  433. return 0;
  434. }
  435. static int
  436. netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter)
  437. {
  438. u32 val = 0;
  439. u16 port = adapter->physical_port;
  440. u8 *addr = adapter->mac_addr;
  441. if (!adapter->mc_enabled)
  442. return 0;
  443. val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG);
  444. val &= ~(1UL << (28+port));
  445. NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val);
  446. val = MAC_HI(addr);
  447. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val);
  448. val = MAC_LO(addr);
  449. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val);
  450. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0);
  451. NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0);
  452. adapter->mc_enabled = 0;
  453. return 0;
  454. }
  455. static int
  456. netxen_nic_set_mcast_addr(struct netxen_adapter *adapter,
  457. int index, u8 *addr)
  458. {
  459. u32 hi = 0, lo = 0;
  460. u16 port = adapter->physical_port;
  461. lo = MAC_LO(addr);
  462. hi = MAC_HI(addr);
  463. NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi);
  464. NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo);
  465. return 0;
  466. }
  467. static void netxen_p2_nic_set_multi(struct net_device *netdev)
  468. {
  469. struct netxen_adapter *adapter = netdev_priv(netdev);
  470. struct netdev_hw_addr *ha;
  471. u8 null_addr[6];
  472. int i;
  473. memset(null_addr, 0, 6);
  474. if (netdev->flags & IFF_PROMISC) {
  475. adapter->set_promisc(adapter,
  476. NETXEN_NIU_PROMISC_MODE);
  477. /* Full promiscuous mode */
  478. netxen_nic_disable_mcast_filter(adapter);
  479. return;
  480. }
  481. if (netdev_mc_empty(netdev)) {
  482. adapter->set_promisc(adapter,
  483. NETXEN_NIU_NON_PROMISC_MODE);
  484. netxen_nic_disable_mcast_filter(adapter);
  485. return;
  486. }
  487. adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE);
  488. if (netdev->flags & IFF_ALLMULTI ||
  489. netdev_mc_count(netdev) > adapter->max_mc_count) {
  490. netxen_nic_disable_mcast_filter(adapter);
  491. return;
  492. }
  493. netxen_nic_enable_mcast_filter(adapter);
  494. i = 0;
  495. netdev_for_each_mc_addr(ha, netdev)
  496. netxen_nic_set_mcast_addr(adapter, i++, ha->addr);
  497. /* Clear out remaining addresses */
  498. while (i < adapter->max_mc_count)
  499. netxen_nic_set_mcast_addr(adapter, i++, null_addr);
  500. }
  501. static int
  502. netxen_send_cmd_descs(struct netxen_adapter *adapter,
  503. struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
  504. {
  505. u32 i, producer, consumer;
  506. struct netxen_cmd_buffer *pbuf;
  507. struct cmd_desc_type0 *cmd_desc;
  508. struct nx_host_tx_ring *tx_ring;
  509. i = 0;
  510. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  511. return -EIO;
  512. tx_ring = adapter->tx_ring;
  513. __netif_tx_lock_bh(tx_ring->txq);
  514. producer = tx_ring->producer;
  515. consumer = tx_ring->sw_consumer;
  516. if (nr_desc >= netxen_tx_avail(tx_ring)) {
  517. netif_tx_stop_queue(tx_ring->txq);
  518. smp_mb();
  519. if (netxen_tx_avail(tx_ring) > nr_desc) {
  520. if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH)
  521. netif_tx_wake_queue(tx_ring->txq);
  522. } else {
  523. __netif_tx_unlock_bh(tx_ring->txq);
  524. return -EBUSY;
  525. }
  526. }
  527. do {
  528. cmd_desc = &cmd_desc_arr[i];
  529. pbuf = &tx_ring->cmd_buf_arr[producer];
  530. pbuf->skb = NULL;
  531. pbuf->frag_count = 0;
  532. memcpy(&tx_ring->desc_head[producer],
  533. &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
  534. producer = get_next_index(producer, tx_ring->num_desc);
  535. i++;
  536. } while (i != nr_desc);
  537. tx_ring->producer = producer;
  538. netxen_nic_update_cmd_producer(adapter, tx_ring);
  539. __netif_tx_unlock_bh(tx_ring->txq);
  540. return 0;
  541. }
  542. static int
  543. nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op)
  544. {
  545. nx_nic_req_t req;
  546. nx_mac_req_t *mac_req;
  547. u64 word;
  548. memset(&req, 0, sizeof(nx_nic_req_t));
  549. req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23);
  550. word = NX_MAC_EVENT | ((u64)adapter->portnum << 16);
  551. req.req_hdr = cpu_to_le64(word);
  552. mac_req = (nx_mac_req_t *)&req.words[0];
  553. mac_req->op = op;
  554. memcpy(mac_req->mac_addr, addr, 6);
  555. return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  556. }
  557. static int nx_p3_nic_add_mac(struct netxen_adapter *adapter,
  558. const u8 *addr, struct list_head *del_list)
  559. {
  560. struct list_head *head;
  561. nx_mac_list_t *cur;
  562. /* look up if already exists */
  563. list_for_each(head, del_list) {
  564. cur = list_entry(head, nx_mac_list_t, list);
  565. if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) {
  566. list_move_tail(head, &adapter->mac_list);
  567. return 0;
  568. }
  569. }
  570. cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC);
  571. if (cur == NULL) {
  572. printk(KERN_ERR "%s: failed to add mac address filter\n",
  573. adapter->netdev->name);
  574. return -ENOMEM;
  575. }
  576. memcpy(cur->mac_addr, addr, ETH_ALEN);
  577. list_add_tail(&cur->list, &adapter->mac_list);
  578. return nx_p3_sre_macaddr_change(adapter,
  579. cur->mac_addr, NETXEN_MAC_ADD);
  580. }
  581. static void netxen_p3_nic_set_multi(struct net_device *netdev)
  582. {
  583. struct netxen_adapter *adapter = netdev_priv(netdev);
  584. struct netdev_hw_addr *ha;
  585. static const u8 bcast_addr[ETH_ALEN] = {
  586. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  587. };
  588. u32 mode = VPORT_MISS_MODE_DROP;
  589. LIST_HEAD(del_list);
  590. struct list_head *head;
  591. nx_mac_list_t *cur;
  592. if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
  593. return;
  594. list_splice_tail_init(&adapter->mac_list, &del_list);
  595. nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list);
  596. nx_p3_nic_add_mac(adapter, bcast_addr, &del_list);
  597. if (netdev->flags & IFF_PROMISC) {
  598. mode = VPORT_MISS_MODE_ACCEPT_ALL;
  599. goto send_fw_cmd;
  600. }
  601. if ((netdev->flags & IFF_ALLMULTI) ||
  602. (netdev_mc_count(netdev) > adapter->max_mc_count)) {
  603. mode = VPORT_MISS_MODE_ACCEPT_MULTI;
  604. goto send_fw_cmd;
  605. }
  606. if (!netdev_mc_empty(netdev)) {
  607. netdev_for_each_mc_addr(ha, netdev)
  608. nx_p3_nic_add_mac(adapter, ha->addr, &del_list);
  609. }
  610. send_fw_cmd:
  611. adapter->set_promisc(adapter, mode);
  612. head = &del_list;
  613. while (!list_empty(head)) {
  614. cur = list_entry(head->next, nx_mac_list_t, list);
  615. nx_p3_sre_macaddr_change(adapter,
  616. cur->mac_addr, NETXEN_MAC_DEL);
  617. list_del(&cur->list);
  618. kfree(cur);
  619. }
  620. }
  621. static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode)
  622. {
  623. nx_nic_req_t req;
  624. u64 word;
  625. memset(&req, 0, sizeof(nx_nic_req_t));
  626. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  627. word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE |
  628. ((u64)adapter->portnum << 16);
  629. req.req_hdr = cpu_to_le64(word);
  630. req.words[0] = cpu_to_le64(mode);
  631. return netxen_send_cmd_descs(adapter,
  632. (struct cmd_desc_type0 *)&req, 1);
  633. }
  634. void netxen_p3_free_mac_list(struct netxen_adapter *adapter)
  635. {
  636. nx_mac_list_t *cur;
  637. struct list_head *head = &adapter->mac_list;
  638. while (!list_empty(head)) {
  639. cur = list_entry(head->next, nx_mac_list_t, list);
  640. nx_p3_sre_macaddr_change(adapter,
  641. cur->mac_addr, NETXEN_MAC_DEL);
  642. list_del(&cur->list);
  643. kfree(cur);
  644. }
  645. }
  646. static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr)
  647. {
  648. /* assuming caller has already copied new addr to netdev */
  649. netxen_p3_nic_set_multi(adapter->netdev);
  650. return 0;
  651. }
  652. #define NETXEN_CONFIG_INTR_COALESCE 3
  653. /*
  654. * Send the interrupt coalescing parameter set by ethtool to the card.
  655. */
  656. int netxen_config_intr_coalesce(struct netxen_adapter *adapter)
  657. {
  658. nx_nic_req_t req;
  659. u64 word[6];
  660. int rv, i;
  661. memset(&req, 0, sizeof(nx_nic_req_t));
  662. memset(word, 0, sizeof(word));
  663. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  664. word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
  665. req.req_hdr = cpu_to_le64(word[0]);
  666. memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
  667. for (i = 0; i < 6; i++)
  668. req.words[i] = cpu_to_le64(word[i]);
  669. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  670. if (rv != 0) {
  671. printk(KERN_ERR "ERROR. Could not send "
  672. "interrupt coalescing parameters\n");
  673. }
  674. return rv;
  675. }
  676. int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable)
  677. {
  678. nx_nic_req_t req;
  679. u64 word;
  680. int rv = 0;
  681. memset(&req, 0, sizeof(nx_nic_req_t));
  682. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  683. word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
  684. req.req_hdr = cpu_to_le64(word);
  685. req.words[0] = cpu_to_le64(enable);
  686. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  687. if (rv != 0) {
  688. printk(KERN_ERR "ERROR. Could not send "
  689. "configure hw lro request\n");
  690. }
  691. return rv;
  692. }
  693. int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable)
  694. {
  695. nx_nic_req_t req;
  696. u64 word;
  697. int rv = 0;
  698. if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable)
  699. return rv;
  700. memset(&req, 0, sizeof(nx_nic_req_t));
  701. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  702. word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING |
  703. ((u64)adapter->portnum << 16);
  704. req.req_hdr = cpu_to_le64(word);
  705. req.words[0] = cpu_to_le64(enable);
  706. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  707. if (rv != 0) {
  708. printk(KERN_ERR "ERROR. Could not send "
  709. "configure bridge mode request\n");
  710. }
  711. adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED;
  712. return rv;
  713. }
  714. #define RSS_HASHTYPE_IP_TCP 0x3
  715. int netxen_config_rss(struct netxen_adapter *adapter, int enable)
  716. {
  717. nx_nic_req_t req;
  718. u64 word;
  719. int i, rv;
  720. static const u64 key[] = {
  721. 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
  722. 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
  723. 0x255b0ec26d5a56daULL
  724. };
  725. memset(&req, 0, sizeof(nx_nic_req_t));
  726. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  727. word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
  728. req.req_hdr = cpu_to_le64(word);
  729. /*
  730. * RSS request:
  731. * bits 3-0: hash_method
  732. * 5-4: hash_type_ipv4
  733. * 7-6: hash_type_ipv6
  734. * 8: enable
  735. * 9: use indirection table
  736. * 47-10: reserved
  737. * 63-48: indirection table mask
  738. */
  739. word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
  740. ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
  741. ((u64)(enable & 0x1) << 8) |
  742. ((0x7ULL) << 48);
  743. req.words[0] = cpu_to_le64(word);
  744. for (i = 0; i < ARRAY_SIZE(key); i++)
  745. req.words[i+1] = cpu_to_le64(key[i]);
  746. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  747. if (rv != 0) {
  748. printk(KERN_ERR "%s: could not configure RSS\n",
  749. adapter->netdev->name);
  750. }
  751. return rv;
  752. }
  753. int netxen_config_ipaddr(struct netxen_adapter *adapter, u32 ip, int cmd)
  754. {
  755. nx_nic_req_t req;
  756. u64 word;
  757. int rv;
  758. memset(&req, 0, sizeof(nx_nic_req_t));
  759. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  760. word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
  761. req.req_hdr = cpu_to_le64(word);
  762. req.words[0] = cpu_to_le64(cmd);
  763. req.words[1] = cpu_to_le64(ip);
  764. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  765. if (rv != 0) {
  766. printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n",
  767. adapter->netdev->name,
  768. (cmd == NX_IP_UP) ? "Add" : "Remove", ip);
  769. }
  770. return rv;
  771. }
  772. int netxen_linkevent_request(struct netxen_adapter *adapter, int enable)
  773. {
  774. nx_nic_req_t req;
  775. u64 word;
  776. int rv;
  777. memset(&req, 0, sizeof(nx_nic_req_t));
  778. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  779. word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
  780. req.req_hdr = cpu_to_le64(word);
  781. req.words[0] = cpu_to_le64(enable | (enable << 8));
  782. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  783. if (rv != 0) {
  784. printk(KERN_ERR "%s: could not configure link notification\n",
  785. adapter->netdev->name);
  786. }
  787. return rv;
  788. }
  789. int netxen_send_lro_cleanup(struct netxen_adapter *adapter)
  790. {
  791. nx_nic_req_t req;
  792. u64 word;
  793. int rv;
  794. memset(&req, 0, sizeof(nx_nic_req_t));
  795. req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23);
  796. word = NX_NIC_H2C_OPCODE_LRO_REQUEST |
  797. ((u64)adapter->portnum << 16) |
  798. ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ;
  799. req.req_hdr = cpu_to_le64(word);
  800. rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  801. if (rv != 0) {
  802. printk(KERN_ERR "%s: could not cleanup lro flows\n",
  803. adapter->netdev->name);
  804. }
  805. return rv;
  806. }
  807. /*
  808. * netxen_nic_change_mtu - Change the Maximum Transfer Unit
  809. * @returns 0 on success, negative on failure
  810. */
  811. #define MTU_FUDGE_FACTOR 100
  812. int netxen_nic_change_mtu(struct net_device *netdev, int mtu)
  813. {
  814. struct netxen_adapter *adapter = netdev_priv(netdev);
  815. int max_mtu;
  816. int rc = 0;
  817. if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
  818. max_mtu = P3_MAX_MTU;
  819. else
  820. max_mtu = P2_MAX_MTU;
  821. if (mtu > max_mtu) {
  822. printk(KERN_ERR "%s: mtu > %d bytes unsupported\n",
  823. netdev->name, max_mtu);
  824. return -EINVAL;
  825. }
  826. if (adapter->set_mtu)
  827. rc = adapter->set_mtu(adapter, mtu);
  828. if (!rc)
  829. netdev->mtu = mtu;
  830. return rc;
  831. }
  832. static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
  833. int size, __le32 * buf)
  834. {
  835. int i, v, addr;
  836. __le32 *ptr32;
  837. addr = base;
  838. ptr32 = buf;
  839. for (i = 0; i < size / sizeof(u32); i++) {
  840. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  841. return -1;
  842. *ptr32 = cpu_to_le32(v);
  843. ptr32++;
  844. addr += sizeof(u32);
  845. }
  846. if ((char *)buf + size > (char *)ptr32) {
  847. __le32 local;
  848. if (netxen_rom_fast_read(adapter, addr, &v) == -1)
  849. return -1;
  850. local = cpu_to_le32(v);
  851. memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
  852. }
  853. return 0;
  854. }
  855. int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  856. {
  857. __le32 *pmac = (__le32 *) mac;
  858. u32 offset;
  859. offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64));
  860. if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1)
  861. return -1;
  862. if (*mac == cpu_to_le64(~0ULL)) {
  863. offset = NX_OLD_MAC_ADDR_OFFSET +
  864. (adapter->portnum * sizeof(u64));
  865. if (netxen_get_flash_block(adapter,
  866. offset, sizeof(u64), pmac) == -1)
  867. return -1;
  868. if (*mac == cpu_to_le64(~0ULL))
  869. return -1;
  870. }
  871. return 0;
  872. }
  873. int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac)
  874. {
  875. uint32_t crbaddr, mac_hi, mac_lo;
  876. int pci_func = adapter->ahw.pci_func;
  877. crbaddr = CRB_MAC_BLOCK_START +
  878. (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
  879. mac_lo = NXRD32(adapter, crbaddr);
  880. mac_hi = NXRD32(adapter, crbaddr+4);
  881. if (pci_func & 1)
  882. *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16));
  883. else
  884. *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32));
  885. return 0;
  886. }
  887. /*
  888. * Changes the CRB window to the specified window.
  889. */
  890. static void
  891. netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter,
  892. u32 window)
  893. {
  894. void __iomem *offset;
  895. int count = 10;
  896. u8 func = adapter->ahw.pci_func;
  897. if (adapter->ahw.crb_win == window)
  898. return;
  899. offset = PCI_OFFSET_SECOND_RANGE(adapter,
  900. NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func)));
  901. writel(window, offset);
  902. do {
  903. if (window == readl(offset))
  904. break;
  905. if (printk_ratelimit())
  906. dev_warn(&adapter->pdev->dev,
  907. "failed to set CRB window to %d\n",
  908. (window == NETXEN_WINDOW_ONE));
  909. udelay(1);
  910. } while (--count > 0);
  911. if (count > 0)
  912. adapter->ahw.crb_win = window;
  913. }
  914. /*
  915. * Returns < 0 if off is not valid,
  916. * 1 if window access is needed. 'off' is set to offset from
  917. * CRB space in 128M pci map
  918. * 0 if no window access is needed. 'off' is set to 2M addr
  919. * In: 'off' is offset from base in 128M pci map
  920. */
  921. static int
  922. netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter,
  923. ulong off, void __iomem **addr)
  924. {
  925. crb_128M_2M_sub_block_map_t *m;
  926. if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE))
  927. return -EINVAL;
  928. off -= NETXEN_PCI_CRBSPACE;
  929. /*
  930. * Try direct map
  931. */
  932. m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
  933. if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
  934. *addr = adapter->ahw.pci_base0 + m->start_2M +
  935. (off - m->start_128M);
  936. return 0;
  937. }
  938. /*
  939. * Not in direct map, use crb window
  940. */
  941. *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M +
  942. (off & MASK(16));
  943. return 1;
  944. }
  945. /*
  946. * In: 'off' is offset from CRB space in 128M pci map
  947. * Out: 'off' is 2M pci map addr
  948. * side effect: lock crb window
  949. */
  950. static void
  951. netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off)
  952. {
  953. u32 window;
  954. void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
  955. off -= NETXEN_PCI_CRBSPACE;
  956. window = CRB_HI(off);
  957. writel(window, addr);
  958. if (readl(addr) != window) {
  959. if (printk_ratelimit())
  960. dev_warn(&adapter->pdev->dev,
  961. "failed to set CRB window to %d off 0x%lx\n",
  962. window, off);
  963. }
  964. }
  965. static void __iomem *
  966. netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter,
  967. ulong win_off, void __iomem **mem_ptr)
  968. {
  969. ulong off = win_off;
  970. void __iomem *addr;
  971. resource_size_t mem_base;
  972. if (ADDR_IN_WINDOW1(win_off))
  973. off = NETXEN_CRB_NORMAL(win_off);
  974. addr = pci_base_offset(adapter, off);
  975. if (addr)
  976. return addr;
  977. if (adapter->ahw.pci_len0 == 0)
  978. off -= NETXEN_PCI_CRBSPACE;
  979. mem_base = pci_resource_start(adapter->pdev, 0);
  980. *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE);
  981. if (*mem_ptr)
  982. addr = *mem_ptr + (off & (PAGE_SIZE - 1));
  983. return addr;
  984. }
  985. static int
  986. netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data)
  987. {
  988. unsigned long flags;
  989. void __iomem *addr, *mem_ptr = NULL;
  990. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  991. if (!addr)
  992. return -EIO;
  993. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  994. netxen_nic_io_write_128M(adapter, addr, data);
  995. } else { /* Window 0 */
  996. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  997. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  998. writel(data, addr);
  999. netxen_nic_pci_set_crbwindow_128M(adapter,
  1000. NETXEN_WINDOW_ONE);
  1001. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1002. }
  1003. if (mem_ptr)
  1004. iounmap(mem_ptr);
  1005. return 0;
  1006. }
  1007. static u32
  1008. netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off)
  1009. {
  1010. unsigned long flags;
  1011. void __iomem *addr, *mem_ptr = NULL;
  1012. u32 data;
  1013. addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr);
  1014. if (!addr)
  1015. return -EIO;
  1016. if (ADDR_IN_WINDOW1(off)) { /* Window 1 */
  1017. data = netxen_nic_io_read_128M(adapter, addr);
  1018. } else { /* Window 0 */
  1019. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1020. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1021. data = readl(addr);
  1022. netxen_nic_pci_set_crbwindow_128M(adapter,
  1023. NETXEN_WINDOW_ONE);
  1024. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1025. }
  1026. if (mem_ptr)
  1027. iounmap(mem_ptr);
  1028. return data;
  1029. }
  1030. static int
  1031. netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data)
  1032. {
  1033. unsigned long flags;
  1034. int rv;
  1035. void __iomem *addr = NULL;
  1036. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1037. if (rv == 0) {
  1038. writel(data, addr);
  1039. return 0;
  1040. }
  1041. if (rv > 0) {
  1042. /* indirect access */
  1043. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1044. crb_win_lock(adapter);
  1045. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1046. writel(data, addr);
  1047. crb_win_unlock(adapter);
  1048. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1049. return 0;
  1050. }
  1051. dev_err(&adapter->pdev->dev,
  1052. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1053. dump_stack();
  1054. return -EIO;
  1055. }
  1056. static u32
  1057. netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off)
  1058. {
  1059. unsigned long flags;
  1060. int rv;
  1061. u32 data;
  1062. void __iomem *addr = NULL;
  1063. rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr);
  1064. if (rv == 0)
  1065. return readl(addr);
  1066. if (rv > 0) {
  1067. /* indirect access */
  1068. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  1069. crb_win_lock(adapter);
  1070. netxen_nic_pci_set_crbwindow_2M(adapter, off);
  1071. data = readl(addr);
  1072. crb_win_unlock(adapter);
  1073. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  1074. return data;
  1075. }
  1076. dev_err(&adapter->pdev->dev,
  1077. "%s: invalid offset: 0x%016lx\n", __func__, off);
  1078. dump_stack();
  1079. return -1;
  1080. }
  1081. /* window 1 registers only */
  1082. static void netxen_nic_io_write_128M(struct netxen_adapter *adapter,
  1083. void __iomem *addr, u32 data)
  1084. {
  1085. read_lock(&adapter->ahw.crb_lock);
  1086. writel(data, addr);
  1087. read_unlock(&adapter->ahw.crb_lock);
  1088. }
  1089. static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter,
  1090. void __iomem *addr)
  1091. {
  1092. u32 val;
  1093. read_lock(&adapter->ahw.crb_lock);
  1094. val = readl(addr);
  1095. read_unlock(&adapter->ahw.crb_lock);
  1096. return val;
  1097. }
  1098. static void netxen_nic_io_write_2M(struct netxen_adapter *adapter,
  1099. void __iomem *addr, u32 data)
  1100. {
  1101. writel(data, addr);
  1102. }
  1103. static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter,
  1104. void __iomem *addr)
  1105. {
  1106. return readl(addr);
  1107. }
  1108. void __iomem *
  1109. netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset)
  1110. {
  1111. void __iomem *addr = NULL;
  1112. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1113. if ((offset < NETXEN_CRB_PCIX_HOST2) &&
  1114. (offset > NETXEN_CRB_PCIX_HOST))
  1115. addr = PCI_OFFSET_SECOND_RANGE(adapter, offset);
  1116. else
  1117. addr = NETXEN_CRB_NORMALIZE(adapter, offset);
  1118. } else {
  1119. WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter,
  1120. offset, &addr));
  1121. }
  1122. return addr;
  1123. }
  1124. static int
  1125. netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter,
  1126. u64 addr, u32 *start)
  1127. {
  1128. if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1129. *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0);
  1130. return 0;
  1131. } else if (ADDR_IN_RANGE(addr,
  1132. NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1133. *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1);
  1134. return 0;
  1135. }
  1136. return -EIO;
  1137. }
  1138. static int
  1139. netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter,
  1140. u64 addr, u32 *start)
  1141. {
  1142. u32 window;
  1143. window = OCM_WIN(addr);
  1144. writel(window, adapter->ahw.ocm_win_crb);
  1145. /* read back to flush */
  1146. readl(adapter->ahw.ocm_win_crb);
  1147. adapter->ahw.ocm_win = window;
  1148. *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
  1149. return 0;
  1150. }
  1151. static int
  1152. netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off,
  1153. u64 *data, int op)
  1154. {
  1155. void __iomem *addr, *mem_ptr = NULL;
  1156. resource_size_t mem_base;
  1157. int ret;
  1158. u32 start;
  1159. spin_lock(&adapter->ahw.mem_lock);
  1160. ret = adapter->pci_set_window(adapter, off, &start);
  1161. if (ret != 0)
  1162. goto unlock;
  1163. if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
  1164. addr = adapter->ahw.pci_base0 + start;
  1165. } else {
  1166. addr = pci_base_offset(adapter, start);
  1167. if (addr)
  1168. goto noremap;
  1169. mem_base = pci_resource_start(adapter->pdev, 0) +
  1170. (start & PAGE_MASK);
  1171. mem_ptr = ioremap(mem_base, PAGE_SIZE);
  1172. if (mem_ptr == NULL) {
  1173. ret = -EIO;
  1174. goto unlock;
  1175. }
  1176. addr = mem_ptr + (start & (PAGE_SIZE-1));
  1177. }
  1178. noremap:
  1179. if (op == 0) /* read */
  1180. *data = readq(addr);
  1181. else /* write */
  1182. writeq(*data, addr);
  1183. unlock:
  1184. spin_unlock(&adapter->ahw.mem_lock);
  1185. if (mem_ptr)
  1186. iounmap(mem_ptr);
  1187. return ret;
  1188. }
  1189. void
  1190. netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data)
  1191. {
  1192. void __iomem *addr = adapter->ahw.pci_base0 +
  1193. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1194. spin_lock(&adapter->ahw.mem_lock);
  1195. *data = readq(addr);
  1196. spin_unlock(&adapter->ahw.mem_lock);
  1197. }
  1198. void
  1199. netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data)
  1200. {
  1201. void __iomem *addr = adapter->ahw.pci_base0 +
  1202. NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM);
  1203. spin_lock(&adapter->ahw.mem_lock);
  1204. writeq(data, addr);
  1205. spin_unlock(&adapter->ahw.mem_lock);
  1206. }
  1207. #define MAX_CTL_CHECK 1000
  1208. static int
  1209. netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter,
  1210. u64 off, u64 data)
  1211. {
  1212. int j, ret;
  1213. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1214. void __iomem *mem_crb;
  1215. /* Only 64-bit aligned access */
  1216. if (off & 7)
  1217. return -EIO;
  1218. /* P2 has different SIU and MIU test agent base addr */
  1219. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1220. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1221. mem_crb = pci_base_offset(adapter,
  1222. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1223. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1224. data_lo = SIU_TEST_AGT_WRDATA_LO;
  1225. data_hi = SIU_TEST_AGT_WRDATA_HI;
  1226. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1227. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1228. goto correct;
  1229. }
  1230. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1231. mem_crb = pci_base_offset(adapter,
  1232. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1233. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1234. data_lo = MIU_TEST_AGT_WRDATA_LO;
  1235. data_hi = MIU_TEST_AGT_WRDATA_HI;
  1236. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1237. off_hi = 0;
  1238. goto correct;
  1239. }
  1240. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1241. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1242. if (adapter->ahw.pci_len0 != 0) {
  1243. return netxen_nic_pci_mem_access_direct(adapter,
  1244. off, &data, 1);
  1245. }
  1246. }
  1247. return -EIO;
  1248. correct:
  1249. spin_lock(&adapter->ahw.mem_lock);
  1250. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1251. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1252. writel(off_hi, (mem_crb + addr_hi));
  1253. writel(data & 0xffffffff, (mem_crb + data_lo));
  1254. writel((data >> 32) & 0xffffffff, (mem_crb + data_hi));
  1255. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1256. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1257. (mem_crb + TEST_AGT_CTRL));
  1258. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1259. temp = readl((mem_crb + TEST_AGT_CTRL));
  1260. if ((temp & TA_CTL_BUSY) == 0)
  1261. break;
  1262. }
  1263. if (j >= MAX_CTL_CHECK) {
  1264. if (printk_ratelimit())
  1265. dev_err(&adapter->pdev->dev,
  1266. "failed to write through agent\n");
  1267. ret = -EIO;
  1268. } else
  1269. ret = 0;
  1270. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1271. spin_unlock(&adapter->ahw.mem_lock);
  1272. return ret;
  1273. }
  1274. static int
  1275. netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter,
  1276. u64 off, u64 *data)
  1277. {
  1278. int j, ret;
  1279. u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo;
  1280. u64 val;
  1281. void __iomem *mem_crb;
  1282. /* Only 64-bit aligned access */
  1283. if (off & 7)
  1284. return -EIO;
  1285. /* P2 has different SIU and MIU test agent base addr */
  1286. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1287. NETXEN_ADDR_QDR_NET_MAX_P2)) {
  1288. mem_crb = pci_base_offset(adapter,
  1289. NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE);
  1290. addr_hi = SIU_TEST_AGT_ADDR_HI;
  1291. data_lo = SIU_TEST_AGT_RDDATA_LO;
  1292. data_hi = SIU_TEST_AGT_RDDATA_HI;
  1293. off_lo = off & SIU_TEST_AGT_ADDR_MASK;
  1294. off_hi = SIU_TEST_AGT_UPPER_ADDR(off);
  1295. goto correct;
  1296. }
  1297. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1298. mem_crb = pci_base_offset(adapter,
  1299. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1300. addr_hi = MIU_TEST_AGT_ADDR_HI;
  1301. data_lo = MIU_TEST_AGT_RDDATA_LO;
  1302. data_hi = MIU_TEST_AGT_RDDATA_HI;
  1303. off_lo = off & MIU_TEST_AGT_ADDR_MASK;
  1304. off_hi = 0;
  1305. goto correct;
  1306. }
  1307. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) ||
  1308. ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) {
  1309. if (adapter->ahw.pci_len0 != 0) {
  1310. return netxen_nic_pci_mem_access_direct(adapter,
  1311. off, data, 0);
  1312. }
  1313. }
  1314. return -EIO;
  1315. correct:
  1316. spin_lock(&adapter->ahw.mem_lock);
  1317. netxen_nic_pci_set_crbwindow_128M(adapter, 0);
  1318. writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1319. writel(off_hi, (mem_crb + addr_hi));
  1320. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1321. writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1322. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1323. temp = readl(mem_crb + TEST_AGT_CTRL);
  1324. if ((temp & TA_CTL_BUSY) == 0)
  1325. break;
  1326. }
  1327. if (j >= MAX_CTL_CHECK) {
  1328. if (printk_ratelimit())
  1329. dev_err(&adapter->pdev->dev,
  1330. "failed to read through agent\n");
  1331. ret = -EIO;
  1332. } else {
  1333. temp = readl(mem_crb + data_hi);
  1334. val = ((u64)temp << 32);
  1335. val |= readl(mem_crb + data_lo);
  1336. *data = val;
  1337. ret = 0;
  1338. }
  1339. netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE);
  1340. spin_unlock(&adapter->ahw.mem_lock);
  1341. return ret;
  1342. }
  1343. static int
  1344. netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter,
  1345. u64 off, u64 data)
  1346. {
  1347. int j, ret;
  1348. u32 temp, off8;
  1349. void __iomem *mem_crb;
  1350. /* Only 64-bit aligned access */
  1351. if (off & 7)
  1352. return -EIO;
  1353. /* P3 onward, test agent base for MIU and SIU is same */
  1354. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1355. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1356. mem_crb = netxen_get_ioaddr(adapter,
  1357. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1358. goto correct;
  1359. }
  1360. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1361. mem_crb = netxen_get_ioaddr(adapter,
  1362. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1363. goto correct;
  1364. }
  1365. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX))
  1366. return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1);
  1367. return -EIO;
  1368. correct:
  1369. off8 = off & 0xfffffff8;
  1370. spin_lock(&adapter->ahw.mem_lock);
  1371. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1372. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1373. writel(data & 0xffffffff,
  1374. mem_crb + MIU_TEST_AGT_WRDATA_LO);
  1375. writel((data >> 32) & 0xffffffff,
  1376. mem_crb + MIU_TEST_AGT_WRDATA_HI);
  1377. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  1378. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  1379. (mem_crb + TEST_AGT_CTRL));
  1380. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1381. temp = readl(mem_crb + TEST_AGT_CTRL);
  1382. if ((temp & TA_CTL_BUSY) == 0)
  1383. break;
  1384. }
  1385. if (j >= MAX_CTL_CHECK) {
  1386. if (printk_ratelimit())
  1387. dev_err(&adapter->pdev->dev,
  1388. "failed to write through agent\n");
  1389. ret = -EIO;
  1390. } else
  1391. ret = 0;
  1392. spin_unlock(&adapter->ahw.mem_lock);
  1393. return ret;
  1394. }
  1395. static int
  1396. netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter,
  1397. u64 off, u64 *data)
  1398. {
  1399. int j, ret;
  1400. u32 temp, off8;
  1401. u64 val;
  1402. void __iomem *mem_crb;
  1403. /* Only 64-bit aligned access */
  1404. if (off & 7)
  1405. return -EIO;
  1406. /* P3 onward, test agent base for MIU and SIU is same */
  1407. if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET,
  1408. NETXEN_ADDR_QDR_NET_MAX_P3)) {
  1409. mem_crb = netxen_get_ioaddr(adapter,
  1410. NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  1411. goto correct;
  1412. }
  1413. if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) {
  1414. mem_crb = netxen_get_ioaddr(adapter,
  1415. NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  1416. goto correct;
  1417. }
  1418. if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) {
  1419. return netxen_nic_pci_mem_access_direct(adapter,
  1420. off, data, 0);
  1421. }
  1422. return -EIO;
  1423. correct:
  1424. off8 = off & 0xfffffff8;
  1425. spin_lock(&adapter->ahw.mem_lock);
  1426. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  1427. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  1428. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  1429. writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  1430. for (j = 0; j < MAX_CTL_CHECK; j++) {
  1431. temp = readl(mem_crb + TEST_AGT_CTRL);
  1432. if ((temp & TA_CTL_BUSY) == 0)
  1433. break;
  1434. }
  1435. if (j >= MAX_CTL_CHECK) {
  1436. if (printk_ratelimit())
  1437. dev_err(&adapter->pdev->dev,
  1438. "failed to read through agent\n");
  1439. ret = -EIO;
  1440. } else {
  1441. val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32;
  1442. val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO);
  1443. *data = val;
  1444. ret = 0;
  1445. }
  1446. spin_unlock(&adapter->ahw.mem_lock);
  1447. return ret;
  1448. }
  1449. void
  1450. netxen_setup_hwops(struct netxen_adapter *adapter)
  1451. {
  1452. adapter->init_port = netxen_niu_xg_init_port;
  1453. adapter->stop_port = netxen_niu_disable_xg_port;
  1454. if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
  1455. adapter->crb_read = netxen_nic_hw_read_wx_128M,
  1456. adapter->crb_write = netxen_nic_hw_write_wx_128M,
  1457. adapter->pci_set_window = netxen_nic_pci_set_window_128M,
  1458. adapter->pci_mem_read = netxen_nic_pci_mem_read_128M,
  1459. adapter->pci_mem_write = netxen_nic_pci_mem_write_128M,
  1460. adapter->io_read = netxen_nic_io_read_128M,
  1461. adapter->io_write = netxen_nic_io_write_128M,
  1462. adapter->macaddr_set = netxen_p2_nic_set_mac_addr;
  1463. adapter->set_multi = netxen_p2_nic_set_multi;
  1464. adapter->set_mtu = netxen_nic_set_mtu_xgb;
  1465. adapter->set_promisc = netxen_p2_nic_set_promisc;
  1466. } else {
  1467. adapter->crb_read = netxen_nic_hw_read_wx_2M,
  1468. adapter->crb_write = netxen_nic_hw_write_wx_2M,
  1469. adapter->pci_set_window = netxen_nic_pci_set_window_2M,
  1470. adapter->pci_mem_read = netxen_nic_pci_mem_read_2M,
  1471. adapter->pci_mem_write = netxen_nic_pci_mem_write_2M,
  1472. adapter->io_read = netxen_nic_io_read_2M,
  1473. adapter->io_write = netxen_nic_io_write_2M,
  1474. adapter->set_mtu = nx_fw_cmd_set_mtu;
  1475. adapter->set_promisc = netxen_p3_nic_set_promisc;
  1476. adapter->macaddr_set = netxen_p3_nic_set_mac_addr;
  1477. adapter->set_multi = netxen_p3_nic_set_multi;
  1478. adapter->phy_read = nx_fw_cmd_query_phy;
  1479. adapter->phy_write = nx_fw_cmd_set_phy;
  1480. }
  1481. }
  1482. int netxen_nic_get_board_info(struct netxen_adapter *adapter)
  1483. {
  1484. int offset, board_type, magic;
  1485. struct pci_dev *pdev = adapter->pdev;
  1486. offset = NX_FW_MAGIC_OFFSET;
  1487. if (netxen_rom_fast_read(adapter, offset, &magic))
  1488. return -EIO;
  1489. if (magic != NETXEN_BDINFO_MAGIC) {
  1490. dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
  1491. magic);
  1492. return -EIO;
  1493. }
  1494. offset = NX_BRDTYPE_OFFSET;
  1495. if (netxen_rom_fast_read(adapter, offset, &board_type))
  1496. return -EIO;
  1497. if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) {
  1498. u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I);
  1499. if ((gpio & 0x8000) == 0)
  1500. board_type = NETXEN_BRDTYPE_P3_10G_TP;
  1501. }
  1502. adapter->ahw.board_type = board_type;
  1503. switch (board_type) {
  1504. case NETXEN_BRDTYPE_P2_SB35_4G:
  1505. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1506. break;
  1507. case NETXEN_BRDTYPE_P2_SB31_10G:
  1508. case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
  1509. case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
  1510. case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
  1511. case NETXEN_BRDTYPE_P3_HMEZ:
  1512. case NETXEN_BRDTYPE_P3_XG_LOM:
  1513. case NETXEN_BRDTYPE_P3_10G_CX4:
  1514. case NETXEN_BRDTYPE_P3_10G_CX4_LP:
  1515. case NETXEN_BRDTYPE_P3_IMEZ:
  1516. case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
  1517. case NETXEN_BRDTYPE_P3_10G_SFP_CT:
  1518. case NETXEN_BRDTYPE_P3_10G_SFP_QT:
  1519. case NETXEN_BRDTYPE_P3_10G_XFP:
  1520. case NETXEN_BRDTYPE_P3_10000_BASE_T:
  1521. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1522. break;
  1523. case NETXEN_BRDTYPE_P1_BD:
  1524. case NETXEN_BRDTYPE_P1_SB:
  1525. case NETXEN_BRDTYPE_P1_SMAX:
  1526. case NETXEN_BRDTYPE_P1_SOCK:
  1527. case NETXEN_BRDTYPE_P3_REF_QG:
  1528. case NETXEN_BRDTYPE_P3_4_GB:
  1529. case NETXEN_BRDTYPE_P3_4_GB_MM:
  1530. adapter->ahw.port_type = NETXEN_NIC_GBE;
  1531. break;
  1532. case NETXEN_BRDTYPE_P3_10G_TP:
  1533. adapter->ahw.port_type = (adapter->portnum < 2) ?
  1534. NETXEN_NIC_XGBE : NETXEN_NIC_GBE;
  1535. break;
  1536. default:
  1537. dev_err(&pdev->dev, "unknown board type %x\n", board_type);
  1538. adapter->ahw.port_type = NETXEN_NIC_XGBE;
  1539. break;
  1540. }
  1541. return 0;
  1542. }
  1543. /* NIU access sections */
  1544. static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu)
  1545. {
  1546. new_mtu += MTU_FUDGE_FACTOR;
  1547. if (adapter->physical_port == 0)
  1548. NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu);
  1549. else
  1550. NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu);
  1551. return 0;
  1552. }
  1553. void netxen_nic_set_link_parameters(struct netxen_adapter *adapter)
  1554. {
  1555. __u32 status;
  1556. __u32 autoneg;
  1557. __u32 port_mode;
  1558. if (!netif_carrier_ok(adapter->netdev)) {
  1559. adapter->link_speed = 0;
  1560. adapter->link_duplex = -1;
  1561. adapter->link_autoneg = AUTONEG_ENABLE;
  1562. return;
  1563. }
  1564. if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
  1565. port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
  1566. if (port_mode == NETXEN_PORT_MODE_802_3_AP) {
  1567. adapter->link_speed = SPEED_1000;
  1568. adapter->link_duplex = DUPLEX_FULL;
  1569. adapter->link_autoneg = AUTONEG_DISABLE;
  1570. return;
  1571. }
  1572. if (adapter->phy_read &&
  1573. adapter->phy_read(adapter,
  1574. NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
  1575. &status) == 0) {
  1576. if (netxen_get_phy_link(status)) {
  1577. switch (netxen_get_phy_speed(status)) {
  1578. case 0:
  1579. adapter->link_speed = SPEED_10;
  1580. break;
  1581. case 1:
  1582. adapter->link_speed = SPEED_100;
  1583. break;
  1584. case 2:
  1585. adapter->link_speed = SPEED_1000;
  1586. break;
  1587. default:
  1588. adapter->link_speed = 0;
  1589. break;
  1590. }
  1591. switch (netxen_get_phy_duplex(status)) {
  1592. case 0:
  1593. adapter->link_duplex = DUPLEX_HALF;
  1594. break;
  1595. case 1:
  1596. adapter->link_duplex = DUPLEX_FULL;
  1597. break;
  1598. default:
  1599. adapter->link_duplex = -1;
  1600. break;
  1601. }
  1602. if (adapter->phy_read &&
  1603. adapter->phy_read(adapter,
  1604. NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
  1605. &autoneg) != 0)
  1606. adapter->link_autoneg = autoneg;
  1607. } else
  1608. goto link_down;
  1609. } else {
  1610. link_down:
  1611. adapter->link_speed = 0;
  1612. adapter->link_duplex = -1;
  1613. }
  1614. }
  1615. }
  1616. int
  1617. netxen_nic_wol_supported(struct netxen_adapter *adapter)
  1618. {
  1619. u32 wol_cfg;
  1620. if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
  1621. return 0;
  1622. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
  1623. if (wol_cfg & (1UL << adapter->portnum)) {
  1624. wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
  1625. if (wol_cfg & (1 << adapter->portnum))
  1626. return 1;
  1627. }
  1628. return 0;
  1629. }