qlcnic_hw.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /*
  2. * QLogic qlcnic NIC Driver
  3. * Copyright (c) 2009-2010 QLogic Corporation
  4. *
  5. * See LICENSE.qlcnic for copyright and licensing details.
  6. */
  7. #include "qlcnic.h"
  8. #include <linux/slab.h>
  9. #include <net/ip.h>
  10. #define MASK(n) ((1ULL<<(n))-1)
  11. #define OCM_WIN_P3P(addr) (addr & 0xffc0000)
  12. #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
  13. #define CRB_BLK(off) ((off >> 20) & 0x3f)
  14. #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
  15. #define CRB_WINDOW_2M (0x130060)
  16. #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000))
  17. #define CRB_INDIRECT_2M (0x1e0000UL)
  18. #ifndef readq
  19. static inline u64 readq(void __iomem *addr)
  20. {
  21. return readl(addr) | (((u64) readl(addr + 4)) << 32LL);
  22. }
  23. #endif
  24. #ifndef writeq
  25. static inline void writeq(u64 val, void __iomem *addr)
  26. {
  27. writel(((u32) (val)), (addr));
  28. writel(((u32) (val >> 32)), (addr + 4));
  29. }
  30. #endif
  31. static const struct crb_128M_2M_block_map
  32. crb_128M_2M_map[64] __cacheline_aligned_in_smp = {
  33. {{{0, 0, 0, 0} } }, /* 0: PCI */
  34. {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
  35. {1, 0x0110000, 0x0120000, 0x130000},
  36. {1, 0x0120000, 0x0122000, 0x124000},
  37. {1, 0x0130000, 0x0132000, 0x126000},
  38. {1, 0x0140000, 0x0142000, 0x128000},
  39. {1, 0x0150000, 0x0152000, 0x12a000},
  40. {1, 0x0160000, 0x0170000, 0x110000},
  41. {1, 0x0170000, 0x0172000, 0x12e000},
  42. {0, 0x0000000, 0x0000000, 0x000000},
  43. {0, 0x0000000, 0x0000000, 0x000000},
  44. {0, 0x0000000, 0x0000000, 0x000000},
  45. {0, 0x0000000, 0x0000000, 0x000000},
  46. {0, 0x0000000, 0x0000000, 0x000000},
  47. {0, 0x0000000, 0x0000000, 0x000000},
  48. {1, 0x01e0000, 0x01e0800, 0x122000},
  49. {0, 0x0000000, 0x0000000, 0x000000} } },
  50. {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
  51. {{{0, 0, 0, 0} } }, /* 3: */
  52. {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
  53. {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
  54. {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
  55. {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
  56. {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
  57. {0, 0x0000000, 0x0000000, 0x000000},
  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. {0, 0x0000000, 0x0000000, 0x000000},
  65. {0, 0x0000000, 0x0000000, 0x000000},
  66. {0, 0x0000000, 0x0000000, 0x000000},
  67. {0, 0x0000000, 0x0000000, 0x000000},
  68. {0, 0x0000000, 0x0000000, 0x000000},
  69. {0, 0x0000000, 0x0000000, 0x000000},
  70. {0, 0x0000000, 0x0000000, 0x000000},
  71. {1, 0x08f0000, 0x08f2000, 0x172000} } },
  72. {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
  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, 0x09f0000, 0x09f2000, 0x176000} } },
  88. {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
  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, 0x0af0000, 0x0af2000, 0x17a000} } },
  104. {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
  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, 0x0bf0000, 0x0bf2000, 0x17e000} } },
  120. {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
  121. {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
  122. {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
  123. {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
  124. {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
  125. {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
  126. {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
  127. {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
  128. {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
  129. {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
  130. {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
  131. {{{0, 0, 0, 0} } }, /* 23: */
  132. {{{0, 0, 0, 0} } }, /* 24: */
  133. {{{0, 0, 0, 0} } }, /* 25: */
  134. {{{0, 0, 0, 0} } }, /* 26: */
  135. {{{0, 0, 0, 0} } }, /* 27: */
  136. {{{0, 0, 0, 0} } }, /* 28: */
  137. {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
  138. {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
  139. {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
  140. {{{0} } }, /* 32: PCI */
  141. {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
  142. {1, 0x2110000, 0x2120000, 0x130000},
  143. {1, 0x2120000, 0x2122000, 0x124000},
  144. {1, 0x2130000, 0x2132000, 0x126000},
  145. {1, 0x2140000, 0x2142000, 0x128000},
  146. {1, 0x2150000, 0x2152000, 0x12a000},
  147. {1, 0x2160000, 0x2170000, 0x110000},
  148. {1, 0x2170000, 0x2172000, 0x12e000},
  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. {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
  158. {{{0} } }, /* 35: */
  159. {{{0} } }, /* 36: */
  160. {{{0} } }, /* 37: */
  161. {{{0} } }, /* 38: */
  162. {{{0} } }, /* 39: */
  163. {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
  164. {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
  165. {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
  166. {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
  167. {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
  168. {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
  169. {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
  170. {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
  171. {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
  172. {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
  173. {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
  174. {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
  175. {{{0} } }, /* 52: */
  176. {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
  177. {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
  178. {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
  179. {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
  180. {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
  181. {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
  182. {{{0} } }, /* 59: I2C0 */
  183. {{{0} } }, /* 60: I2C1 */
  184. {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */
  185. {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
  186. {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
  187. };
  188. /*
  189. * top 12 bits of crb internal address (hub, agent)
  190. */
  191. static const unsigned crb_hub_agt[64] = {
  192. 0,
  193. QLCNIC_HW_CRB_HUB_AGT_ADR_PS,
  194. QLCNIC_HW_CRB_HUB_AGT_ADR_MN,
  195. QLCNIC_HW_CRB_HUB_AGT_ADR_MS,
  196. 0,
  197. QLCNIC_HW_CRB_HUB_AGT_ADR_SRE,
  198. QLCNIC_HW_CRB_HUB_AGT_ADR_NIU,
  199. QLCNIC_HW_CRB_HUB_AGT_ADR_QMN,
  200. QLCNIC_HW_CRB_HUB_AGT_ADR_SQN0,
  201. QLCNIC_HW_CRB_HUB_AGT_ADR_SQN1,
  202. QLCNIC_HW_CRB_HUB_AGT_ADR_SQN2,
  203. QLCNIC_HW_CRB_HUB_AGT_ADR_SQN3,
  204. QLCNIC_HW_CRB_HUB_AGT_ADR_I2Q,
  205. QLCNIC_HW_CRB_HUB_AGT_ADR_TIMR,
  206. QLCNIC_HW_CRB_HUB_AGT_ADR_ROMUSB,
  207. QLCNIC_HW_CRB_HUB_AGT_ADR_PGN4,
  208. QLCNIC_HW_CRB_HUB_AGT_ADR_XDMA,
  209. QLCNIC_HW_CRB_HUB_AGT_ADR_PGN0,
  210. QLCNIC_HW_CRB_HUB_AGT_ADR_PGN1,
  211. QLCNIC_HW_CRB_HUB_AGT_ADR_PGN2,
  212. QLCNIC_HW_CRB_HUB_AGT_ADR_PGN3,
  213. QLCNIC_HW_CRB_HUB_AGT_ADR_PGND,
  214. QLCNIC_HW_CRB_HUB_AGT_ADR_PGNI,
  215. QLCNIC_HW_CRB_HUB_AGT_ADR_PGS0,
  216. QLCNIC_HW_CRB_HUB_AGT_ADR_PGS1,
  217. QLCNIC_HW_CRB_HUB_AGT_ADR_PGS2,
  218. QLCNIC_HW_CRB_HUB_AGT_ADR_PGS3,
  219. 0,
  220. QLCNIC_HW_CRB_HUB_AGT_ADR_PGSI,
  221. QLCNIC_HW_CRB_HUB_AGT_ADR_SN,
  222. 0,
  223. QLCNIC_HW_CRB_HUB_AGT_ADR_EG,
  224. 0,
  225. QLCNIC_HW_CRB_HUB_AGT_ADR_PS,
  226. QLCNIC_HW_CRB_HUB_AGT_ADR_CAM,
  227. 0,
  228. 0,
  229. 0,
  230. 0,
  231. 0,
  232. QLCNIC_HW_CRB_HUB_AGT_ADR_TIMR,
  233. 0,
  234. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX1,
  235. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX2,
  236. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX3,
  237. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX4,
  238. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX5,
  239. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX6,
  240. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX7,
  241. QLCNIC_HW_CRB_HUB_AGT_ADR_XDMA,
  242. QLCNIC_HW_CRB_HUB_AGT_ADR_I2Q,
  243. QLCNIC_HW_CRB_HUB_AGT_ADR_ROMUSB,
  244. 0,
  245. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX0,
  246. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX8,
  247. QLCNIC_HW_CRB_HUB_AGT_ADR_RPMX9,
  248. QLCNIC_HW_CRB_HUB_AGT_ADR_OCM0,
  249. 0,
  250. QLCNIC_HW_CRB_HUB_AGT_ADR_SMB,
  251. QLCNIC_HW_CRB_HUB_AGT_ADR_I2C0,
  252. QLCNIC_HW_CRB_HUB_AGT_ADR_I2C1,
  253. 0,
  254. QLCNIC_HW_CRB_HUB_AGT_ADR_PGNC,
  255. 0,
  256. };
  257. /* PCI Windowing for DDR regions. */
  258. #define QLCNIC_PCIE_SEM_TIMEOUT 10000
  259. int
  260. qlcnic_pcie_sem_lock(struct qlcnic_adapter *adapter, int sem, u32 id_reg)
  261. {
  262. int done = 0, timeout = 0;
  263. while (!done) {
  264. done = QLCRD32(adapter, QLCNIC_PCIE_REG(PCIE_SEM_LOCK(sem)));
  265. if (done == 1)
  266. break;
  267. if (++timeout >= QLCNIC_PCIE_SEM_TIMEOUT) {
  268. dev_err(&adapter->pdev->dev,
  269. "Failed to acquire sem=%d lock; holdby=%d\n",
  270. sem, id_reg ? QLCRD32(adapter, id_reg) : -1);
  271. return -EIO;
  272. }
  273. msleep(1);
  274. }
  275. if (id_reg)
  276. QLCWR32(adapter, id_reg, adapter->portnum);
  277. return 0;
  278. }
  279. void
  280. qlcnic_pcie_sem_unlock(struct qlcnic_adapter *adapter, int sem)
  281. {
  282. QLCRD32(adapter, QLCNIC_PCIE_REG(PCIE_SEM_UNLOCK(sem)));
  283. }
  284. static int
  285. qlcnic_send_cmd_descs(struct qlcnic_adapter *adapter,
  286. struct cmd_desc_type0 *cmd_desc_arr, int nr_desc)
  287. {
  288. u32 i, producer, consumer;
  289. struct qlcnic_cmd_buffer *pbuf;
  290. struct cmd_desc_type0 *cmd_desc;
  291. struct qlcnic_host_tx_ring *tx_ring;
  292. i = 0;
  293. if (!test_bit(__QLCNIC_FW_ATTACHED, &adapter->state))
  294. return -EIO;
  295. tx_ring = adapter->tx_ring;
  296. __netif_tx_lock_bh(tx_ring->txq);
  297. producer = tx_ring->producer;
  298. consumer = tx_ring->sw_consumer;
  299. if (nr_desc >= qlcnic_tx_avail(tx_ring)) {
  300. netif_tx_stop_queue(tx_ring->txq);
  301. smp_mb();
  302. if (qlcnic_tx_avail(tx_ring) > nr_desc) {
  303. if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH)
  304. netif_tx_wake_queue(tx_ring->txq);
  305. } else {
  306. adapter->stats.xmit_off++;
  307. __netif_tx_unlock_bh(tx_ring->txq);
  308. return -EBUSY;
  309. }
  310. }
  311. do {
  312. cmd_desc = &cmd_desc_arr[i];
  313. pbuf = &tx_ring->cmd_buf_arr[producer];
  314. pbuf->skb = NULL;
  315. pbuf->frag_count = 0;
  316. memcpy(&tx_ring->desc_head[producer],
  317. &cmd_desc_arr[i], sizeof(struct cmd_desc_type0));
  318. producer = get_next_index(producer, tx_ring->num_desc);
  319. i++;
  320. } while (i != nr_desc);
  321. tx_ring->producer = producer;
  322. qlcnic_update_cmd_producer(adapter, tx_ring);
  323. __netif_tx_unlock_bh(tx_ring->txq);
  324. return 0;
  325. }
  326. static int
  327. qlcnic_sre_macaddr_change(struct qlcnic_adapter *adapter, u8 *addr,
  328. __le16 vlan_id, unsigned op)
  329. {
  330. struct qlcnic_nic_req req;
  331. struct qlcnic_mac_req *mac_req;
  332. struct qlcnic_vlan_req *vlan_req;
  333. u64 word;
  334. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  335. req.qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
  336. word = QLCNIC_MAC_EVENT | ((u64)adapter->portnum << 16);
  337. req.req_hdr = cpu_to_le64(word);
  338. mac_req = (struct qlcnic_mac_req *)&req.words[0];
  339. mac_req->op = op;
  340. memcpy(mac_req->mac_addr, addr, 6);
  341. vlan_req = (struct qlcnic_vlan_req *)&req.words[1];
  342. vlan_req->vlan_id = vlan_id;
  343. return qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  344. }
  345. static int qlcnic_nic_add_mac(struct qlcnic_adapter *adapter, const u8 *addr)
  346. {
  347. struct list_head *head;
  348. struct qlcnic_mac_list_s *cur;
  349. /* look up if already exists */
  350. list_for_each(head, &adapter->mac_list) {
  351. cur = list_entry(head, struct qlcnic_mac_list_s, list);
  352. if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0)
  353. return 0;
  354. }
  355. cur = kzalloc(sizeof(struct qlcnic_mac_list_s), GFP_ATOMIC);
  356. if (cur == NULL) {
  357. dev_err(&adapter->netdev->dev,
  358. "failed to add mac address filter\n");
  359. return -ENOMEM;
  360. }
  361. memcpy(cur->mac_addr, addr, ETH_ALEN);
  362. if (qlcnic_sre_macaddr_change(adapter,
  363. cur->mac_addr, 0, QLCNIC_MAC_ADD)) {
  364. kfree(cur);
  365. return -EIO;
  366. }
  367. list_add_tail(&cur->list, &adapter->mac_list);
  368. return 0;
  369. }
  370. void qlcnic_set_multi(struct net_device *netdev)
  371. {
  372. struct qlcnic_adapter *adapter = netdev_priv(netdev);
  373. struct netdev_hw_addr *ha;
  374. static const u8 bcast_addr[ETH_ALEN] = {
  375. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  376. };
  377. u32 mode = VPORT_MISS_MODE_DROP;
  378. if (!test_bit(__QLCNIC_FW_ATTACHED, &adapter->state))
  379. return;
  380. qlcnic_nic_add_mac(adapter, adapter->mac_addr);
  381. qlcnic_nic_add_mac(adapter, bcast_addr);
  382. if (netdev->flags & IFF_PROMISC) {
  383. if (!(adapter->flags & QLCNIC_PROMISC_DISABLED))
  384. mode = VPORT_MISS_MODE_ACCEPT_ALL;
  385. goto send_fw_cmd;
  386. }
  387. if ((netdev->flags & IFF_ALLMULTI) ||
  388. (netdev_mc_count(netdev) > adapter->max_mc_count)) {
  389. mode = VPORT_MISS_MODE_ACCEPT_MULTI;
  390. goto send_fw_cmd;
  391. }
  392. if (!netdev_mc_empty(netdev)) {
  393. netdev_for_each_mc_addr(ha, netdev) {
  394. qlcnic_nic_add_mac(adapter, ha->addr);
  395. }
  396. }
  397. send_fw_cmd:
  398. qlcnic_nic_set_promisc(adapter, mode);
  399. }
  400. int qlcnic_nic_set_promisc(struct qlcnic_adapter *adapter, u32 mode)
  401. {
  402. struct qlcnic_nic_req req;
  403. u64 word;
  404. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  405. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  406. word = QLCNIC_H2C_OPCODE_SET_MAC_RECEIVE_MODE |
  407. ((u64)adapter->portnum << 16);
  408. req.req_hdr = cpu_to_le64(word);
  409. req.words[0] = cpu_to_le64(mode);
  410. return qlcnic_send_cmd_descs(adapter,
  411. (struct cmd_desc_type0 *)&req, 1);
  412. }
  413. void qlcnic_free_mac_list(struct qlcnic_adapter *adapter)
  414. {
  415. struct qlcnic_mac_list_s *cur;
  416. struct list_head *head = &adapter->mac_list;
  417. while (!list_empty(head)) {
  418. cur = list_entry(head->next, struct qlcnic_mac_list_s, list);
  419. qlcnic_sre_macaddr_change(adapter,
  420. cur->mac_addr, 0, QLCNIC_MAC_DEL);
  421. list_del(&cur->list);
  422. kfree(cur);
  423. }
  424. }
  425. void qlcnic_prune_lb_filters(struct qlcnic_adapter *adapter)
  426. {
  427. struct qlcnic_filter *tmp_fil;
  428. struct hlist_node *tmp_hnode, *n;
  429. struct hlist_head *head;
  430. int i;
  431. for (i = 0; i < adapter->fhash.fmax; i++) {
  432. head = &(adapter->fhash.fhead[i]);
  433. hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode)
  434. {
  435. if (jiffies >
  436. (QLCNIC_FILTER_AGE * HZ + tmp_fil->ftime)) {
  437. qlcnic_sre_macaddr_change(adapter,
  438. tmp_fil->faddr, tmp_fil->vlan_id,
  439. tmp_fil->vlan_id ? QLCNIC_MAC_VLAN_DEL :
  440. QLCNIC_MAC_DEL);
  441. spin_lock_bh(&adapter->mac_learn_lock);
  442. adapter->fhash.fnum--;
  443. hlist_del(&tmp_fil->fnode);
  444. spin_unlock_bh(&adapter->mac_learn_lock);
  445. kfree(tmp_fil);
  446. }
  447. }
  448. }
  449. }
  450. void qlcnic_delete_lb_filters(struct qlcnic_adapter *adapter)
  451. {
  452. struct qlcnic_filter *tmp_fil;
  453. struct hlist_node *tmp_hnode, *n;
  454. struct hlist_head *head;
  455. int i;
  456. for (i = 0; i < adapter->fhash.fmax; i++) {
  457. head = &(adapter->fhash.fhead[i]);
  458. hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
  459. qlcnic_sre_macaddr_change(adapter, tmp_fil->faddr,
  460. tmp_fil->vlan_id, tmp_fil->vlan_id ?
  461. QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL);
  462. spin_lock_bh(&adapter->mac_learn_lock);
  463. adapter->fhash.fnum--;
  464. hlist_del(&tmp_fil->fnode);
  465. spin_unlock_bh(&adapter->mac_learn_lock);
  466. kfree(tmp_fil);
  467. }
  468. }
  469. }
  470. /*
  471. * Send the interrupt coalescing parameter set by ethtool to the card.
  472. */
  473. int qlcnic_config_intr_coalesce(struct qlcnic_adapter *adapter)
  474. {
  475. struct qlcnic_nic_req req;
  476. int rv;
  477. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  478. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  479. req.req_hdr = cpu_to_le64(QLCNIC_CONFIG_INTR_COALESCE |
  480. ((u64) adapter->portnum << 16));
  481. req.words[0] = cpu_to_le64(((u64) adapter->ahw->coal.flag) << 32);
  482. req.words[2] = cpu_to_le64(adapter->ahw->coal.rx_packets |
  483. ((u64) adapter->ahw->coal.rx_time_us) << 16);
  484. req.words[5] = cpu_to_le64(adapter->ahw->coal.timer_out |
  485. ((u64) adapter->ahw->coal.type) << 32 |
  486. ((u64) adapter->ahw->coal.sts_ring_mask) << 40);
  487. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  488. if (rv != 0)
  489. dev_err(&adapter->netdev->dev,
  490. "Could not send interrupt coalescing parameters\n");
  491. return rv;
  492. }
  493. int qlcnic_config_hw_lro(struct qlcnic_adapter *adapter, int enable)
  494. {
  495. struct qlcnic_nic_req req;
  496. u64 word;
  497. int rv;
  498. if (!test_bit(__QLCNIC_FW_ATTACHED, &adapter->state))
  499. return 0;
  500. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  501. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  502. word = QLCNIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
  503. req.req_hdr = cpu_to_le64(word);
  504. req.words[0] = cpu_to_le64(enable);
  505. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  506. if (rv != 0)
  507. dev_err(&adapter->netdev->dev,
  508. "Could not send configure hw lro request\n");
  509. return rv;
  510. }
  511. int qlcnic_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
  512. {
  513. struct qlcnic_nic_req req;
  514. u64 word;
  515. int rv;
  516. if (!!(adapter->flags & QLCNIC_BRIDGE_ENABLED) == enable)
  517. return 0;
  518. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  519. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  520. word = QLCNIC_H2C_OPCODE_CONFIG_BRIDGING |
  521. ((u64)adapter->portnum << 16);
  522. req.req_hdr = cpu_to_le64(word);
  523. req.words[0] = cpu_to_le64(enable);
  524. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  525. if (rv != 0)
  526. dev_err(&adapter->netdev->dev,
  527. "Could not send configure bridge mode request\n");
  528. adapter->flags ^= QLCNIC_BRIDGE_ENABLED;
  529. return rv;
  530. }
  531. #define RSS_HASHTYPE_IP_TCP 0x3
  532. int qlcnic_config_rss(struct qlcnic_adapter *adapter, int enable)
  533. {
  534. struct qlcnic_nic_req req;
  535. u64 word;
  536. int i, rv;
  537. static const u64 key[] = {
  538. 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
  539. 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
  540. 0x255b0ec26d5a56daULL
  541. };
  542. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  543. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  544. word = QLCNIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
  545. req.req_hdr = cpu_to_le64(word);
  546. /*
  547. * RSS request:
  548. * bits 3-0: hash_method
  549. * 5-4: hash_type_ipv4
  550. * 7-6: hash_type_ipv6
  551. * 8: enable
  552. * 9: use indirection table
  553. * 47-10: reserved
  554. * 63-48: indirection table mask
  555. */
  556. word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
  557. ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
  558. ((u64)(enable & 0x1) << 8) |
  559. ((0x7ULL) << 48);
  560. req.words[0] = cpu_to_le64(word);
  561. for (i = 0; i < 5; i++)
  562. req.words[i+1] = cpu_to_le64(key[i]);
  563. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  564. if (rv != 0)
  565. dev_err(&adapter->netdev->dev, "could not configure RSS\n");
  566. return rv;
  567. }
  568. int qlcnic_config_ipaddr(struct qlcnic_adapter *adapter, __be32 ip, int cmd)
  569. {
  570. struct qlcnic_nic_req req;
  571. struct qlcnic_ipaddr *ipa;
  572. u64 word;
  573. int rv;
  574. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  575. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  576. word = QLCNIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
  577. req.req_hdr = cpu_to_le64(word);
  578. req.words[0] = cpu_to_le64(cmd);
  579. ipa = (struct qlcnic_ipaddr *)&req.words[1];
  580. ipa->ipv4 = ip;
  581. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  582. if (rv != 0)
  583. dev_err(&adapter->netdev->dev,
  584. "could not notify %s IP 0x%x reuqest\n",
  585. (cmd == QLCNIC_IP_UP) ? "Add" : "Remove", ip);
  586. return rv;
  587. }
  588. int qlcnic_linkevent_request(struct qlcnic_adapter *adapter, int enable)
  589. {
  590. struct qlcnic_nic_req req;
  591. u64 word;
  592. int rv;
  593. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  594. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  595. word = QLCNIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
  596. req.req_hdr = cpu_to_le64(word);
  597. req.words[0] = cpu_to_le64(enable | (enable << 8));
  598. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  599. if (rv != 0)
  600. dev_err(&adapter->netdev->dev,
  601. "could not configure link notification\n");
  602. return rv;
  603. }
  604. int qlcnic_send_lro_cleanup(struct qlcnic_adapter *adapter)
  605. {
  606. struct qlcnic_nic_req req;
  607. u64 word;
  608. int rv;
  609. if (!test_bit(__QLCNIC_FW_ATTACHED, &adapter->state))
  610. return 0;
  611. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  612. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  613. word = QLCNIC_H2C_OPCODE_LRO_REQUEST |
  614. ((u64)adapter->portnum << 16) |
  615. ((u64)QLCNIC_LRO_REQUEST_CLEANUP << 56) ;
  616. req.req_hdr = cpu_to_le64(word);
  617. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  618. if (rv != 0)
  619. dev_err(&adapter->netdev->dev,
  620. "could not cleanup lro flows\n");
  621. return rv;
  622. }
  623. /*
  624. * qlcnic_change_mtu - Change the Maximum Transfer Unit
  625. * @returns 0 on success, negative on failure
  626. */
  627. int qlcnic_change_mtu(struct net_device *netdev, int mtu)
  628. {
  629. struct qlcnic_adapter *adapter = netdev_priv(netdev);
  630. int rc = 0;
  631. if (mtu < P3P_MIN_MTU || mtu > P3P_MAX_MTU) {
  632. dev_err(&adapter->netdev->dev, "%d bytes < mtu < %d bytes"
  633. " not supported\n", P3P_MAX_MTU, P3P_MIN_MTU);
  634. return -EINVAL;
  635. }
  636. rc = qlcnic_fw_cmd_set_mtu(adapter, mtu);
  637. if (!rc)
  638. netdev->mtu = mtu;
  639. return rc;
  640. }
  641. u32 qlcnic_fix_features(struct net_device *netdev, u32 features)
  642. {
  643. struct qlcnic_adapter *adapter = netdev_priv(netdev);
  644. if ((adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
  645. u32 changed = features ^ netdev->features;
  646. features ^= changed & (NETIF_F_ALL_CSUM | NETIF_F_RXCSUM);
  647. }
  648. if (!(features & NETIF_F_RXCSUM))
  649. features &= ~NETIF_F_LRO;
  650. return features;
  651. }
  652. int qlcnic_set_features(struct net_device *netdev, u32 features)
  653. {
  654. struct qlcnic_adapter *adapter = netdev_priv(netdev);
  655. u32 changed = netdev->features ^ features;
  656. int hw_lro = (features & NETIF_F_LRO) ? QLCNIC_LRO_ENABLED : 0;
  657. if (!(changed & NETIF_F_LRO))
  658. return 0;
  659. netdev->features = features ^ NETIF_F_LRO;
  660. if (qlcnic_config_hw_lro(adapter, hw_lro))
  661. return -EIO;
  662. if ((hw_lro == 0) && qlcnic_send_lro_cleanup(adapter))
  663. return -EIO;
  664. return 0;
  665. }
  666. /*
  667. * Changes the CRB window to the specified window.
  668. */
  669. /* Returns < 0 if off is not valid,
  670. * 1 if window access is needed. 'off' is set to offset from
  671. * CRB space in 128M pci map
  672. * 0 if no window access is needed. 'off' is set to 2M addr
  673. * In: 'off' is offset from base in 128M pci map
  674. */
  675. static int
  676. qlcnic_pci_get_crb_addr_2M(struct qlcnic_adapter *adapter,
  677. ulong off, void __iomem **addr)
  678. {
  679. const struct crb_128M_2M_sub_block_map *m;
  680. if ((off >= QLCNIC_CRB_MAX) || (off < QLCNIC_PCI_CRBSPACE))
  681. return -EINVAL;
  682. off -= QLCNIC_PCI_CRBSPACE;
  683. /*
  684. * Try direct map
  685. */
  686. m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
  687. if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
  688. *addr = adapter->ahw->pci_base0 + m->start_2M +
  689. (off - m->start_128M);
  690. return 0;
  691. }
  692. /*
  693. * Not in direct map, use crb window
  694. */
  695. *addr = adapter->ahw->pci_base0 + CRB_INDIRECT_2M + (off & MASK(16));
  696. return 1;
  697. }
  698. /*
  699. * In: 'off' is offset from CRB space in 128M pci map
  700. * Out: 'off' is 2M pci map addr
  701. * side effect: lock crb window
  702. */
  703. static int
  704. qlcnic_pci_set_crbwindow_2M(struct qlcnic_adapter *adapter, ulong off)
  705. {
  706. u32 window;
  707. void __iomem *addr = adapter->ahw->pci_base0 + CRB_WINDOW_2M;
  708. off -= QLCNIC_PCI_CRBSPACE;
  709. window = CRB_HI(off);
  710. if (window == 0) {
  711. dev_err(&adapter->pdev->dev, "Invalid offset 0x%lx\n", off);
  712. return -EIO;
  713. }
  714. writel(window, addr);
  715. if (readl(addr) != window) {
  716. if (printk_ratelimit())
  717. dev_warn(&adapter->pdev->dev,
  718. "failed to set CRB window to %d off 0x%lx\n",
  719. window, off);
  720. return -EIO;
  721. }
  722. return 0;
  723. }
  724. int
  725. qlcnic_hw_write_wx_2M(struct qlcnic_adapter *adapter, ulong off, u32 data)
  726. {
  727. unsigned long flags;
  728. int rv;
  729. void __iomem *addr = NULL;
  730. rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
  731. if (rv == 0) {
  732. writel(data, addr);
  733. return 0;
  734. }
  735. if (rv > 0) {
  736. /* indirect access */
  737. write_lock_irqsave(&adapter->ahw->crb_lock, flags);
  738. crb_win_lock(adapter);
  739. rv = qlcnic_pci_set_crbwindow_2M(adapter, off);
  740. if (!rv)
  741. writel(data, addr);
  742. crb_win_unlock(adapter);
  743. write_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
  744. return rv;
  745. }
  746. dev_err(&adapter->pdev->dev,
  747. "%s: invalid offset: 0x%016lx\n", __func__, off);
  748. dump_stack();
  749. return -EIO;
  750. }
  751. u32
  752. qlcnic_hw_read_wx_2M(struct qlcnic_adapter *adapter, ulong off)
  753. {
  754. unsigned long flags;
  755. int rv;
  756. u32 data = -1;
  757. void __iomem *addr = NULL;
  758. rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
  759. if (rv == 0)
  760. return readl(addr);
  761. if (rv > 0) {
  762. /* indirect access */
  763. write_lock_irqsave(&adapter->ahw->crb_lock, flags);
  764. crb_win_lock(adapter);
  765. if (!qlcnic_pci_set_crbwindow_2M(adapter, off))
  766. data = readl(addr);
  767. crb_win_unlock(adapter);
  768. write_unlock_irqrestore(&adapter->ahw->crb_lock, flags);
  769. return data;
  770. }
  771. dev_err(&adapter->pdev->dev,
  772. "%s: invalid offset: 0x%016lx\n", __func__, off);
  773. dump_stack();
  774. return -1;
  775. }
  776. void __iomem *
  777. qlcnic_get_ioaddr(struct qlcnic_adapter *adapter, u32 offset)
  778. {
  779. void __iomem *addr = NULL;
  780. WARN_ON(qlcnic_pci_get_crb_addr_2M(adapter, offset, &addr));
  781. return addr;
  782. }
  783. static int
  784. qlcnic_pci_set_window_2M(struct qlcnic_adapter *adapter,
  785. u64 addr, u32 *start)
  786. {
  787. u32 window;
  788. window = OCM_WIN_P3P(addr);
  789. writel(window, adapter->ahw->ocm_win_crb);
  790. /* read back to flush */
  791. readl(adapter->ahw->ocm_win_crb);
  792. *start = QLCNIC_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
  793. return 0;
  794. }
  795. static int
  796. qlcnic_pci_mem_access_direct(struct qlcnic_adapter *adapter, u64 off,
  797. u64 *data, int op)
  798. {
  799. void __iomem *addr;
  800. int ret;
  801. u32 start;
  802. mutex_lock(&adapter->ahw->mem_lock);
  803. ret = qlcnic_pci_set_window_2M(adapter, off, &start);
  804. if (ret != 0)
  805. goto unlock;
  806. addr = adapter->ahw->pci_base0 + start;
  807. if (op == 0) /* read */
  808. *data = readq(addr);
  809. else /* write */
  810. writeq(*data, addr);
  811. unlock:
  812. mutex_unlock(&adapter->ahw->mem_lock);
  813. return ret;
  814. }
  815. void
  816. qlcnic_pci_camqm_read_2M(struct qlcnic_adapter *adapter, u64 off, u64 *data)
  817. {
  818. void __iomem *addr = adapter->ahw->pci_base0 +
  819. QLCNIC_PCI_CAMQM_2M_BASE + (off - QLCNIC_PCI_CAMQM);
  820. mutex_lock(&adapter->ahw->mem_lock);
  821. *data = readq(addr);
  822. mutex_unlock(&adapter->ahw->mem_lock);
  823. }
  824. void
  825. qlcnic_pci_camqm_write_2M(struct qlcnic_adapter *adapter, u64 off, u64 data)
  826. {
  827. void __iomem *addr = adapter->ahw->pci_base0 +
  828. QLCNIC_PCI_CAMQM_2M_BASE + (off - QLCNIC_PCI_CAMQM);
  829. mutex_lock(&adapter->ahw->mem_lock);
  830. writeq(data, addr);
  831. mutex_unlock(&adapter->ahw->mem_lock);
  832. }
  833. #define MAX_CTL_CHECK 1000
  834. int
  835. qlcnic_pci_mem_write_2M(struct qlcnic_adapter *adapter,
  836. u64 off, u64 data)
  837. {
  838. int i, j, ret;
  839. u32 temp, off8;
  840. void __iomem *mem_crb;
  841. /* Only 64-bit aligned access */
  842. if (off & 7)
  843. return -EIO;
  844. /* P3 onward, test agent base for MIU and SIU is same */
  845. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_QDR_NET,
  846. QLCNIC_ADDR_QDR_NET_MAX)) {
  847. mem_crb = qlcnic_get_ioaddr(adapter,
  848. QLCNIC_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  849. goto correct;
  850. }
  851. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_DDR_NET, QLCNIC_ADDR_DDR_NET_MAX)) {
  852. mem_crb = qlcnic_get_ioaddr(adapter,
  853. QLCNIC_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  854. goto correct;
  855. }
  856. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_OCM0, QLCNIC_ADDR_OCM0_MAX))
  857. return qlcnic_pci_mem_access_direct(adapter, off, &data, 1);
  858. return -EIO;
  859. correct:
  860. off8 = off & ~0xf;
  861. mutex_lock(&adapter->ahw->mem_lock);
  862. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  863. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  864. i = 0;
  865. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  866. writel((TA_CTL_START | TA_CTL_ENABLE),
  867. (mem_crb + TEST_AGT_CTRL));
  868. for (j = 0; j < MAX_CTL_CHECK; j++) {
  869. temp = readl(mem_crb + TEST_AGT_CTRL);
  870. if ((temp & TA_CTL_BUSY) == 0)
  871. break;
  872. }
  873. if (j >= MAX_CTL_CHECK) {
  874. ret = -EIO;
  875. goto done;
  876. }
  877. i = (off & 0xf) ? 0 : 2;
  878. writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i)),
  879. mem_crb + MIU_TEST_AGT_WRDATA(i));
  880. writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i+1)),
  881. mem_crb + MIU_TEST_AGT_WRDATA(i+1));
  882. i = (off & 0xf) ? 2 : 0;
  883. writel(data & 0xffffffff,
  884. mem_crb + MIU_TEST_AGT_WRDATA(i));
  885. writel((data >> 32) & 0xffffffff,
  886. mem_crb + MIU_TEST_AGT_WRDATA(i+1));
  887. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  888. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  889. (mem_crb + TEST_AGT_CTRL));
  890. for (j = 0; j < MAX_CTL_CHECK; j++) {
  891. temp = readl(mem_crb + TEST_AGT_CTRL);
  892. if ((temp & TA_CTL_BUSY) == 0)
  893. break;
  894. }
  895. if (j >= MAX_CTL_CHECK) {
  896. if (printk_ratelimit())
  897. dev_err(&adapter->pdev->dev,
  898. "failed to write through agent\n");
  899. ret = -EIO;
  900. } else
  901. ret = 0;
  902. done:
  903. mutex_unlock(&adapter->ahw->mem_lock);
  904. return ret;
  905. }
  906. int
  907. qlcnic_pci_mem_read_2M(struct qlcnic_adapter *adapter,
  908. u64 off, u64 *data)
  909. {
  910. int j, ret;
  911. u32 temp, off8;
  912. u64 val;
  913. void __iomem *mem_crb;
  914. /* Only 64-bit aligned access */
  915. if (off & 7)
  916. return -EIO;
  917. /* P3 onward, test agent base for MIU and SIU is same */
  918. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_QDR_NET,
  919. QLCNIC_ADDR_QDR_NET_MAX)) {
  920. mem_crb = qlcnic_get_ioaddr(adapter,
  921. QLCNIC_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  922. goto correct;
  923. }
  924. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_DDR_NET, QLCNIC_ADDR_DDR_NET_MAX)) {
  925. mem_crb = qlcnic_get_ioaddr(adapter,
  926. QLCNIC_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  927. goto correct;
  928. }
  929. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_OCM0, QLCNIC_ADDR_OCM0_MAX)) {
  930. return qlcnic_pci_mem_access_direct(adapter,
  931. off, data, 0);
  932. }
  933. return -EIO;
  934. correct:
  935. off8 = off & ~0xf;
  936. mutex_lock(&adapter->ahw->mem_lock);
  937. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  938. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  939. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  940. writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  941. for (j = 0; j < MAX_CTL_CHECK; j++) {
  942. temp = readl(mem_crb + TEST_AGT_CTRL);
  943. if ((temp & TA_CTL_BUSY) == 0)
  944. break;
  945. }
  946. if (j >= MAX_CTL_CHECK) {
  947. if (printk_ratelimit())
  948. dev_err(&adapter->pdev->dev,
  949. "failed to read through agent\n");
  950. ret = -EIO;
  951. } else {
  952. off8 = MIU_TEST_AGT_RDDATA_LO;
  953. if (off & 0xf)
  954. off8 = MIU_TEST_AGT_RDDATA_UPPER_LO;
  955. temp = readl(mem_crb + off8 + 4);
  956. val = (u64)temp << 32;
  957. val |= readl(mem_crb + off8);
  958. *data = val;
  959. ret = 0;
  960. }
  961. mutex_unlock(&adapter->ahw->mem_lock);
  962. return ret;
  963. }
  964. int qlcnic_get_board_info(struct qlcnic_adapter *adapter)
  965. {
  966. int offset, board_type, magic;
  967. struct pci_dev *pdev = adapter->pdev;
  968. offset = QLCNIC_FW_MAGIC_OFFSET;
  969. if (qlcnic_rom_fast_read(adapter, offset, &magic))
  970. return -EIO;
  971. if (magic != QLCNIC_BDINFO_MAGIC) {
  972. dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
  973. magic);
  974. return -EIO;
  975. }
  976. offset = QLCNIC_BRDTYPE_OFFSET;
  977. if (qlcnic_rom_fast_read(adapter, offset, &board_type))
  978. return -EIO;
  979. adapter->ahw->board_type = board_type;
  980. if (board_type == QLCNIC_BRDTYPE_P3P_4_GB_MM) {
  981. u32 gpio = QLCRD32(adapter, QLCNIC_ROMUSB_GLB_PAD_GPIO_I);
  982. if ((gpio & 0x8000) == 0)
  983. board_type = QLCNIC_BRDTYPE_P3P_10G_TP;
  984. }
  985. switch (board_type) {
  986. case QLCNIC_BRDTYPE_P3P_HMEZ:
  987. case QLCNIC_BRDTYPE_P3P_XG_LOM:
  988. case QLCNIC_BRDTYPE_P3P_10G_CX4:
  989. case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
  990. case QLCNIC_BRDTYPE_P3P_IMEZ:
  991. case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
  992. case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
  993. case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
  994. case QLCNIC_BRDTYPE_P3P_10G_XFP:
  995. case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
  996. adapter->ahw->port_type = QLCNIC_XGBE;
  997. break;
  998. case QLCNIC_BRDTYPE_P3P_REF_QG:
  999. case QLCNIC_BRDTYPE_P3P_4_GB:
  1000. case QLCNIC_BRDTYPE_P3P_4_GB_MM:
  1001. adapter->ahw->port_type = QLCNIC_GBE;
  1002. break;
  1003. case QLCNIC_BRDTYPE_P3P_10G_TP:
  1004. adapter->ahw->port_type = (adapter->portnum < 2) ?
  1005. QLCNIC_XGBE : QLCNIC_GBE;
  1006. break;
  1007. default:
  1008. dev_err(&pdev->dev, "unknown board type %x\n", board_type);
  1009. adapter->ahw->port_type = QLCNIC_XGBE;
  1010. break;
  1011. }
  1012. return 0;
  1013. }
  1014. int
  1015. qlcnic_wol_supported(struct qlcnic_adapter *adapter)
  1016. {
  1017. u32 wol_cfg;
  1018. wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV);
  1019. if (wol_cfg & (1UL << adapter->portnum)) {
  1020. wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG);
  1021. if (wol_cfg & (1 << adapter->portnum))
  1022. return 1;
  1023. }
  1024. return 0;
  1025. }
  1026. int qlcnic_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
  1027. {
  1028. struct qlcnic_nic_req req;
  1029. int rv;
  1030. u64 word;
  1031. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  1032. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  1033. word = QLCNIC_H2C_OPCODE_CONFIG_LED | ((u64)adapter->portnum << 16);
  1034. req.req_hdr = cpu_to_le64(word);
  1035. req.words[0] = cpu_to_le64((u64)rate << 32);
  1036. req.words[1] = cpu_to_le64(state);
  1037. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  1038. if (rv)
  1039. dev_err(&adapter->pdev->dev, "LED configuration failed.\n");
  1040. return rv;
  1041. }