qlcnic_hw.c 32 KB

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