qlcnic_hw.c 32 KB

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