qlcnic_hw.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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_PROXY_SET_VPORT_MISS_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. #define QLCNIC_CONFIG_INTR_COALESCE 3
  471. /*
  472. * Send the interrupt coalescing parameter set by ethtool to the card.
  473. */
  474. int qlcnic_config_intr_coalesce(struct qlcnic_adapter *adapter)
  475. {
  476. struct qlcnic_nic_req req;
  477. u64 word[6];
  478. int rv, i;
  479. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  480. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  481. word[0] = QLCNIC_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16);
  482. req.req_hdr = cpu_to_le64(word[0]);
  483. memcpy(&word[0], &adapter->coal, sizeof(adapter->coal));
  484. for (i = 0; i < 6; i++)
  485. req.words[i] = cpu_to_le64(word[i]);
  486. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  487. if (rv != 0)
  488. dev_err(&adapter->netdev->dev,
  489. "Could not send interrupt coalescing parameters\n");
  490. return rv;
  491. }
  492. int qlcnic_config_hw_lro(struct qlcnic_adapter *adapter, int enable)
  493. {
  494. struct qlcnic_nic_req req;
  495. u64 word;
  496. int rv;
  497. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  498. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  499. word = QLCNIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16);
  500. req.req_hdr = cpu_to_le64(word);
  501. req.words[0] = cpu_to_le64(enable);
  502. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  503. if (rv != 0)
  504. dev_err(&adapter->netdev->dev,
  505. "Could not send configure hw lro request\n");
  506. return rv;
  507. }
  508. int qlcnic_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable)
  509. {
  510. struct qlcnic_nic_req req;
  511. u64 word;
  512. int rv;
  513. if (!!(adapter->flags & QLCNIC_BRIDGE_ENABLED) == enable)
  514. return 0;
  515. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  516. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  517. word = QLCNIC_H2C_OPCODE_CONFIG_BRIDGING |
  518. ((u64)adapter->portnum << 16);
  519. req.req_hdr = cpu_to_le64(word);
  520. req.words[0] = cpu_to_le64(enable);
  521. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  522. if (rv != 0)
  523. dev_err(&adapter->netdev->dev,
  524. "Could not send configure bridge mode request\n");
  525. adapter->flags ^= QLCNIC_BRIDGE_ENABLED;
  526. return rv;
  527. }
  528. #define RSS_HASHTYPE_IP_TCP 0x3
  529. int qlcnic_config_rss(struct qlcnic_adapter *adapter, int enable)
  530. {
  531. struct qlcnic_nic_req req;
  532. u64 word;
  533. int i, rv;
  534. static const u64 key[] = {
  535. 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL,
  536. 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL,
  537. 0x255b0ec26d5a56daULL
  538. };
  539. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  540. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  541. word = QLCNIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16);
  542. req.req_hdr = cpu_to_le64(word);
  543. /*
  544. * RSS request:
  545. * bits 3-0: hash_method
  546. * 5-4: hash_type_ipv4
  547. * 7-6: hash_type_ipv6
  548. * 8: enable
  549. * 9: use indirection table
  550. * 47-10: reserved
  551. * 63-48: indirection table mask
  552. */
  553. word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) |
  554. ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) |
  555. ((u64)(enable & 0x1) << 8) |
  556. ((0x7ULL) << 48);
  557. req.words[0] = cpu_to_le64(word);
  558. for (i = 0; i < 5; i++)
  559. req.words[i+1] = cpu_to_le64(key[i]);
  560. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  561. if (rv != 0)
  562. dev_err(&adapter->netdev->dev, "could not configure RSS\n");
  563. return rv;
  564. }
  565. int qlcnic_config_ipaddr(struct qlcnic_adapter *adapter, __be32 ip, int cmd)
  566. {
  567. struct qlcnic_nic_req req;
  568. struct qlcnic_ipaddr *ipa;
  569. u64 word;
  570. int rv;
  571. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  572. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  573. word = QLCNIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16);
  574. req.req_hdr = cpu_to_le64(word);
  575. req.words[0] = cpu_to_le64(cmd);
  576. ipa = (struct qlcnic_ipaddr *)&req.words[1];
  577. ipa->ipv4 = ip;
  578. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  579. if (rv != 0)
  580. dev_err(&adapter->netdev->dev,
  581. "could not notify %s IP 0x%x reuqest\n",
  582. (cmd == QLCNIC_IP_UP) ? "Add" : "Remove", ip);
  583. return rv;
  584. }
  585. int qlcnic_linkevent_request(struct qlcnic_adapter *adapter, int enable)
  586. {
  587. struct qlcnic_nic_req req;
  588. u64 word;
  589. int rv;
  590. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  591. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  592. word = QLCNIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16);
  593. req.req_hdr = cpu_to_le64(word);
  594. req.words[0] = cpu_to_le64(enable | (enable << 8));
  595. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  596. if (rv != 0)
  597. dev_err(&adapter->netdev->dev,
  598. "could not configure link notification\n");
  599. return rv;
  600. }
  601. int qlcnic_send_lro_cleanup(struct qlcnic_adapter *adapter)
  602. {
  603. struct qlcnic_nic_req req;
  604. u64 word;
  605. int rv;
  606. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  607. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  608. word = QLCNIC_H2C_OPCODE_LRO_REQUEST |
  609. ((u64)adapter->portnum << 16) |
  610. ((u64)QLCNIC_LRO_REQUEST_CLEANUP << 56) ;
  611. req.req_hdr = cpu_to_le64(word);
  612. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  613. if (rv != 0)
  614. dev_err(&adapter->netdev->dev,
  615. "could not cleanup lro flows\n");
  616. return rv;
  617. }
  618. /*
  619. * qlcnic_change_mtu - Change the Maximum Transfer Unit
  620. * @returns 0 on success, negative on failure
  621. */
  622. int qlcnic_change_mtu(struct net_device *netdev, int mtu)
  623. {
  624. struct qlcnic_adapter *adapter = netdev_priv(netdev);
  625. int rc = 0;
  626. if (mtu < P3P_MIN_MTU || mtu > P3P_MAX_MTU) {
  627. dev_err(&adapter->netdev->dev, "%d bytes < mtu < %d bytes"
  628. " not supported\n", P3P_MAX_MTU, P3P_MIN_MTU);
  629. return -EINVAL;
  630. }
  631. rc = qlcnic_fw_cmd_set_mtu(adapter, mtu);
  632. if (!rc)
  633. netdev->mtu = mtu;
  634. return rc;
  635. }
  636. /*
  637. * Changes the CRB window to the specified window.
  638. */
  639. /* Returns < 0 if off is not valid,
  640. * 1 if window access is needed. 'off' is set to offset from
  641. * CRB space in 128M pci map
  642. * 0 if no window access is needed. 'off' is set to 2M addr
  643. * In: 'off' is offset from base in 128M pci map
  644. */
  645. static int
  646. qlcnic_pci_get_crb_addr_2M(struct qlcnic_adapter *adapter,
  647. ulong off, void __iomem **addr)
  648. {
  649. const struct crb_128M_2M_sub_block_map *m;
  650. if ((off >= QLCNIC_CRB_MAX) || (off < QLCNIC_PCI_CRBSPACE))
  651. return -EINVAL;
  652. off -= QLCNIC_PCI_CRBSPACE;
  653. /*
  654. * Try direct map
  655. */
  656. m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)];
  657. if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) {
  658. *addr = adapter->ahw.pci_base0 + m->start_2M +
  659. (off - m->start_128M);
  660. return 0;
  661. }
  662. /*
  663. * Not in direct map, use crb window
  664. */
  665. *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + (off & MASK(16));
  666. return 1;
  667. }
  668. /*
  669. * In: 'off' is offset from CRB space in 128M pci map
  670. * Out: 'off' is 2M pci map addr
  671. * side effect: lock crb window
  672. */
  673. static int
  674. qlcnic_pci_set_crbwindow_2M(struct qlcnic_adapter *adapter, ulong off)
  675. {
  676. u32 window;
  677. void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M;
  678. off -= QLCNIC_PCI_CRBSPACE;
  679. window = CRB_HI(off);
  680. if (window == 0) {
  681. dev_err(&adapter->pdev->dev, "Invalid offset 0x%lx\n", off);
  682. return -EIO;
  683. }
  684. writel(window, addr);
  685. if (readl(addr) != window) {
  686. if (printk_ratelimit())
  687. dev_warn(&adapter->pdev->dev,
  688. "failed to set CRB window to %d off 0x%lx\n",
  689. window, off);
  690. return -EIO;
  691. }
  692. return 0;
  693. }
  694. int
  695. qlcnic_hw_write_wx_2M(struct qlcnic_adapter *adapter, ulong off, u32 data)
  696. {
  697. unsigned long flags;
  698. int rv;
  699. void __iomem *addr = NULL;
  700. rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
  701. if (rv == 0) {
  702. writel(data, addr);
  703. return 0;
  704. }
  705. if (rv > 0) {
  706. /* indirect access */
  707. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  708. crb_win_lock(adapter);
  709. rv = qlcnic_pci_set_crbwindow_2M(adapter, off);
  710. if (!rv)
  711. writel(data, addr);
  712. crb_win_unlock(adapter);
  713. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  714. return rv;
  715. }
  716. dev_err(&adapter->pdev->dev,
  717. "%s: invalid offset: 0x%016lx\n", __func__, off);
  718. dump_stack();
  719. return -EIO;
  720. }
  721. u32
  722. qlcnic_hw_read_wx_2M(struct qlcnic_adapter *adapter, ulong off)
  723. {
  724. unsigned long flags;
  725. int rv;
  726. u32 data = -1;
  727. void __iomem *addr = NULL;
  728. rv = qlcnic_pci_get_crb_addr_2M(adapter, off, &addr);
  729. if (rv == 0)
  730. return readl(addr);
  731. if (rv > 0) {
  732. /* indirect access */
  733. write_lock_irqsave(&adapter->ahw.crb_lock, flags);
  734. crb_win_lock(adapter);
  735. if (!qlcnic_pci_set_crbwindow_2M(adapter, off))
  736. data = readl(addr);
  737. crb_win_unlock(adapter);
  738. write_unlock_irqrestore(&adapter->ahw.crb_lock, flags);
  739. return data;
  740. }
  741. dev_err(&adapter->pdev->dev,
  742. "%s: invalid offset: 0x%016lx\n", __func__, off);
  743. dump_stack();
  744. return -1;
  745. }
  746. void __iomem *
  747. qlcnic_get_ioaddr(struct qlcnic_adapter *adapter, u32 offset)
  748. {
  749. void __iomem *addr = NULL;
  750. WARN_ON(qlcnic_pci_get_crb_addr_2M(adapter, offset, &addr));
  751. return addr;
  752. }
  753. static int
  754. qlcnic_pci_set_window_2M(struct qlcnic_adapter *adapter,
  755. u64 addr, u32 *start)
  756. {
  757. u32 window;
  758. window = OCM_WIN_P3P(addr);
  759. writel(window, adapter->ahw.ocm_win_crb);
  760. /* read back to flush */
  761. readl(adapter->ahw.ocm_win_crb);
  762. *start = QLCNIC_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr);
  763. return 0;
  764. }
  765. static int
  766. qlcnic_pci_mem_access_direct(struct qlcnic_adapter *adapter, u64 off,
  767. u64 *data, int op)
  768. {
  769. void __iomem *addr;
  770. int ret;
  771. u32 start;
  772. mutex_lock(&adapter->ahw.mem_lock);
  773. ret = qlcnic_pci_set_window_2M(adapter, off, &start);
  774. if (ret != 0)
  775. goto unlock;
  776. addr = adapter->ahw.pci_base0 + start;
  777. if (op == 0) /* read */
  778. *data = readq(addr);
  779. else /* write */
  780. writeq(*data, addr);
  781. unlock:
  782. mutex_unlock(&adapter->ahw.mem_lock);
  783. return ret;
  784. }
  785. void
  786. qlcnic_pci_camqm_read_2M(struct qlcnic_adapter *adapter, u64 off, u64 *data)
  787. {
  788. void __iomem *addr = adapter->ahw.pci_base0 +
  789. QLCNIC_PCI_CAMQM_2M_BASE + (off - QLCNIC_PCI_CAMQM);
  790. mutex_lock(&adapter->ahw.mem_lock);
  791. *data = readq(addr);
  792. mutex_unlock(&adapter->ahw.mem_lock);
  793. }
  794. void
  795. qlcnic_pci_camqm_write_2M(struct qlcnic_adapter *adapter, u64 off, u64 data)
  796. {
  797. void __iomem *addr = adapter->ahw.pci_base0 +
  798. QLCNIC_PCI_CAMQM_2M_BASE + (off - QLCNIC_PCI_CAMQM);
  799. mutex_lock(&adapter->ahw.mem_lock);
  800. writeq(data, addr);
  801. mutex_unlock(&adapter->ahw.mem_lock);
  802. }
  803. #define MAX_CTL_CHECK 1000
  804. int
  805. qlcnic_pci_mem_write_2M(struct qlcnic_adapter *adapter,
  806. u64 off, u64 data)
  807. {
  808. int i, j, ret;
  809. u32 temp, off8;
  810. void __iomem *mem_crb;
  811. /* Only 64-bit aligned access */
  812. if (off & 7)
  813. return -EIO;
  814. /* P3 onward, test agent base for MIU and SIU is same */
  815. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_QDR_NET,
  816. QLCNIC_ADDR_QDR_NET_MAX)) {
  817. mem_crb = qlcnic_get_ioaddr(adapter,
  818. QLCNIC_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  819. goto correct;
  820. }
  821. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_DDR_NET, QLCNIC_ADDR_DDR_NET_MAX)) {
  822. mem_crb = qlcnic_get_ioaddr(adapter,
  823. QLCNIC_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  824. goto correct;
  825. }
  826. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_OCM0, QLCNIC_ADDR_OCM0_MAX))
  827. return qlcnic_pci_mem_access_direct(adapter, off, &data, 1);
  828. return -EIO;
  829. correct:
  830. off8 = off & ~0xf;
  831. mutex_lock(&adapter->ahw.mem_lock);
  832. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  833. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  834. i = 0;
  835. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  836. writel((TA_CTL_START | TA_CTL_ENABLE),
  837. (mem_crb + TEST_AGT_CTRL));
  838. for (j = 0; j < MAX_CTL_CHECK; j++) {
  839. temp = readl(mem_crb + TEST_AGT_CTRL);
  840. if ((temp & TA_CTL_BUSY) == 0)
  841. break;
  842. }
  843. if (j >= MAX_CTL_CHECK) {
  844. ret = -EIO;
  845. goto done;
  846. }
  847. i = (off & 0xf) ? 0 : 2;
  848. writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i)),
  849. mem_crb + MIU_TEST_AGT_WRDATA(i));
  850. writel(readl(mem_crb + MIU_TEST_AGT_RDDATA(i+1)),
  851. mem_crb + MIU_TEST_AGT_WRDATA(i+1));
  852. i = (off & 0xf) ? 2 : 0;
  853. writel(data & 0xffffffff,
  854. mem_crb + MIU_TEST_AGT_WRDATA(i));
  855. writel((data >> 32) & 0xffffffff,
  856. mem_crb + MIU_TEST_AGT_WRDATA(i+1));
  857. writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL));
  858. writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE),
  859. (mem_crb + TEST_AGT_CTRL));
  860. for (j = 0; j < MAX_CTL_CHECK; j++) {
  861. temp = readl(mem_crb + TEST_AGT_CTRL);
  862. if ((temp & TA_CTL_BUSY) == 0)
  863. break;
  864. }
  865. if (j >= MAX_CTL_CHECK) {
  866. if (printk_ratelimit())
  867. dev_err(&adapter->pdev->dev,
  868. "failed to write through agent\n");
  869. ret = -EIO;
  870. } else
  871. ret = 0;
  872. done:
  873. mutex_unlock(&adapter->ahw.mem_lock);
  874. return ret;
  875. }
  876. int
  877. qlcnic_pci_mem_read_2M(struct qlcnic_adapter *adapter,
  878. u64 off, u64 *data)
  879. {
  880. int j, ret;
  881. u32 temp, off8;
  882. u64 val;
  883. void __iomem *mem_crb;
  884. /* Only 64-bit aligned access */
  885. if (off & 7)
  886. return -EIO;
  887. /* P3 onward, test agent base for MIU and SIU is same */
  888. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_QDR_NET,
  889. QLCNIC_ADDR_QDR_NET_MAX)) {
  890. mem_crb = qlcnic_get_ioaddr(adapter,
  891. QLCNIC_CRB_QDR_NET+MIU_TEST_AGT_BASE);
  892. goto correct;
  893. }
  894. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_DDR_NET, QLCNIC_ADDR_DDR_NET_MAX)) {
  895. mem_crb = qlcnic_get_ioaddr(adapter,
  896. QLCNIC_CRB_DDR_NET+MIU_TEST_AGT_BASE);
  897. goto correct;
  898. }
  899. if (ADDR_IN_RANGE(off, QLCNIC_ADDR_OCM0, QLCNIC_ADDR_OCM0_MAX)) {
  900. return qlcnic_pci_mem_access_direct(adapter,
  901. off, data, 0);
  902. }
  903. return -EIO;
  904. correct:
  905. off8 = off & ~0xf;
  906. mutex_lock(&adapter->ahw.mem_lock);
  907. writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO));
  908. writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI));
  909. writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL));
  910. writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL));
  911. for (j = 0; j < MAX_CTL_CHECK; j++) {
  912. temp = readl(mem_crb + TEST_AGT_CTRL);
  913. if ((temp & TA_CTL_BUSY) == 0)
  914. break;
  915. }
  916. if (j >= MAX_CTL_CHECK) {
  917. if (printk_ratelimit())
  918. dev_err(&adapter->pdev->dev,
  919. "failed to read through agent\n");
  920. ret = -EIO;
  921. } else {
  922. off8 = MIU_TEST_AGT_RDDATA_LO;
  923. if (off & 0xf)
  924. off8 = MIU_TEST_AGT_RDDATA_UPPER_LO;
  925. temp = readl(mem_crb + off8 + 4);
  926. val = (u64)temp << 32;
  927. val |= readl(mem_crb + off8);
  928. *data = val;
  929. ret = 0;
  930. }
  931. mutex_unlock(&adapter->ahw.mem_lock);
  932. return ret;
  933. }
  934. int qlcnic_get_board_info(struct qlcnic_adapter *adapter)
  935. {
  936. int offset, board_type, magic;
  937. struct pci_dev *pdev = adapter->pdev;
  938. offset = QLCNIC_FW_MAGIC_OFFSET;
  939. if (qlcnic_rom_fast_read(adapter, offset, &magic))
  940. return -EIO;
  941. if (magic != QLCNIC_BDINFO_MAGIC) {
  942. dev_err(&pdev->dev, "invalid board config, magic=%08x\n",
  943. magic);
  944. return -EIO;
  945. }
  946. offset = QLCNIC_BRDTYPE_OFFSET;
  947. if (qlcnic_rom_fast_read(adapter, offset, &board_type))
  948. return -EIO;
  949. adapter->ahw.board_type = board_type;
  950. if (board_type == QLCNIC_BRDTYPE_P3P_4_GB_MM) {
  951. u32 gpio = QLCRD32(adapter, QLCNIC_ROMUSB_GLB_PAD_GPIO_I);
  952. if ((gpio & 0x8000) == 0)
  953. board_type = QLCNIC_BRDTYPE_P3P_10G_TP;
  954. }
  955. switch (board_type) {
  956. case QLCNIC_BRDTYPE_P3P_HMEZ:
  957. case QLCNIC_BRDTYPE_P3P_XG_LOM:
  958. case QLCNIC_BRDTYPE_P3P_10G_CX4:
  959. case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
  960. case QLCNIC_BRDTYPE_P3P_IMEZ:
  961. case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
  962. case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
  963. case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
  964. case QLCNIC_BRDTYPE_P3P_10G_XFP:
  965. case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
  966. adapter->ahw.port_type = QLCNIC_XGBE;
  967. break;
  968. case QLCNIC_BRDTYPE_P3P_REF_QG:
  969. case QLCNIC_BRDTYPE_P3P_4_GB:
  970. case QLCNIC_BRDTYPE_P3P_4_GB_MM:
  971. adapter->ahw.port_type = QLCNIC_GBE;
  972. break;
  973. case QLCNIC_BRDTYPE_P3P_10G_TP:
  974. adapter->ahw.port_type = (adapter->portnum < 2) ?
  975. QLCNIC_XGBE : QLCNIC_GBE;
  976. break;
  977. default:
  978. dev_err(&pdev->dev, "unknown board type %x\n", board_type);
  979. adapter->ahw.port_type = QLCNIC_XGBE;
  980. break;
  981. }
  982. return 0;
  983. }
  984. int
  985. qlcnic_wol_supported(struct qlcnic_adapter *adapter)
  986. {
  987. u32 wol_cfg;
  988. wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV);
  989. if (wol_cfg & (1UL << adapter->portnum)) {
  990. wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG);
  991. if (wol_cfg & (1 << adapter->portnum))
  992. return 1;
  993. }
  994. return 0;
  995. }
  996. int qlcnic_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate)
  997. {
  998. struct qlcnic_nic_req req;
  999. int rv;
  1000. u64 word;
  1001. memset(&req, 0, sizeof(struct qlcnic_nic_req));
  1002. req.qhdr = cpu_to_le64(QLCNIC_HOST_REQUEST << 23);
  1003. word = QLCNIC_H2C_OPCODE_CONFIG_LED | ((u64)adapter->portnum << 16);
  1004. req.req_hdr = cpu_to_le64(word);
  1005. req.words[0] = cpu_to_le64((u64)rate << 32);
  1006. req.words[1] = cpu_to_le64(state);
  1007. rv = qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
  1008. if (rv)
  1009. dev_err(&adapter->pdev->dev, "LED configuration failed.\n");
  1010. return rv;
  1011. }