qlcnic_hw.c 32 KB

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