qlcnic_hw.c 33 KB

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