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