Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 - 2006 NetXen, Inc. |
| 3 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 4 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 9 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 14 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 18 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 19 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 20 | * The full GNU General Public License is included in this distribution |
| 21 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 22 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 23 | * Contact Information: |
| 24 | * info@netxen.com |
| 25 | * NetXen, |
| 26 | * 3965 Freedom Circle, Fourth floor, |
| 27 | * Santa Clara, CA 95054 |
| 28 | * |
| 29 | * |
| 30 | * Source file for NIC routines to access the Phantom hardware |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include "netxen_nic.h" |
| 35 | #include "netxen_nic_hw.h" |
| 36 | #include "netxen_nic_phan_reg.h" |
| 37 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 38 | |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 39 | #include <net/ip.h> |
| 40 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 41 | #define MASK(n) ((1ULL<<(n))-1) |
| 42 | #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) |
| 43 | #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) |
| 44 | #define MS_WIN(addr) (addr & 0x0ffc0000) |
| 45 | |
| 46 | #define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) |
| 47 | |
| 48 | #define CRB_BLK(off) ((off >> 20) & 0x3f) |
| 49 | #define CRB_SUBBLK(off) ((off >> 16) & 0xf) |
| 50 | #define CRB_WINDOW_2M (0x130060) |
| 51 | #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000)) |
| 52 | #define CRB_INDIRECT_2M (0x1e0000UL) |
| 53 | |
| 54 | #define CRB_WIN_LOCK_TIMEOUT 100000000 |
| 55 | static crb_128M_2M_block_map_t crb_128M_2M_map[64] = { |
| 56 | {{{0, 0, 0, 0} } }, /* 0: PCI */ |
| 57 | {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ |
| 58 | {1, 0x0110000, 0x0120000, 0x130000}, |
| 59 | {1, 0x0120000, 0x0122000, 0x124000}, |
| 60 | {1, 0x0130000, 0x0132000, 0x126000}, |
| 61 | {1, 0x0140000, 0x0142000, 0x128000}, |
| 62 | {1, 0x0150000, 0x0152000, 0x12a000}, |
| 63 | {1, 0x0160000, 0x0170000, 0x110000}, |
| 64 | {1, 0x0170000, 0x0172000, 0x12e000}, |
| 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, 0x01e0000, 0x01e0800, 0x122000}, |
| 72 | {0, 0x0000000, 0x0000000, 0x000000} } }, |
| 73 | {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ |
| 74 | {{{0, 0, 0, 0} } }, /* 3: */ |
| 75 | {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ |
| 76 | {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ |
| 77 | {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ |
| 78 | {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ |
| 79 | {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ |
| 80 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 81 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 82 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 83 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 84 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 85 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 86 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 87 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 88 | {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 | {1, 0x08f0000, 0x08f2000, 0x172000} } }, |
| 95 | {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ |
| 96 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 97 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 98 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 99 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 100 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 101 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 102 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 103 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 104 | {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 | {1, 0x09f0000, 0x09f2000, 0x176000} } }, |
| 111 | {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ |
| 112 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 113 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 114 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 115 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 116 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 117 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 118 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 119 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 120 | {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 | {1, 0x0af0000, 0x0af2000, 0x17a000} } }, |
| 127 | {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ |
| 128 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 129 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 130 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 131 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 132 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 133 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 134 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 135 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 136 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 137 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 138 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 139 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 140 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 141 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 142 | {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, |
| 143 | {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ |
| 144 | {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ |
| 145 | {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ |
| 146 | {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ |
| 147 | {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ |
| 148 | {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ |
| 149 | {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ |
| 150 | {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ |
| 151 | {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ |
| 152 | {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ |
| 153 | {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ |
| 154 | {{{0, 0, 0, 0} } }, /* 23: */ |
| 155 | {{{0, 0, 0, 0} } }, /* 24: */ |
| 156 | {{{0, 0, 0, 0} } }, /* 25: */ |
| 157 | {{{0, 0, 0, 0} } }, /* 26: */ |
| 158 | {{{0, 0, 0, 0} } }, /* 27: */ |
| 159 | {{{0, 0, 0, 0} } }, /* 28: */ |
| 160 | {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ |
| 161 | {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ |
| 162 | {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ |
| 163 | {{{0} } }, /* 32: PCI */ |
| 164 | {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ |
| 165 | {1, 0x2110000, 0x2120000, 0x130000}, |
| 166 | {1, 0x2120000, 0x2122000, 0x124000}, |
| 167 | {1, 0x2130000, 0x2132000, 0x126000}, |
| 168 | {1, 0x2140000, 0x2142000, 0x128000}, |
| 169 | {1, 0x2150000, 0x2152000, 0x12a000}, |
| 170 | {1, 0x2160000, 0x2170000, 0x110000}, |
| 171 | {1, 0x2170000, 0x2172000, 0x12e000}, |
| 172 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 173 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 174 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 175 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 176 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 177 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 178 | {0, 0x0000000, 0x0000000, 0x000000}, |
| 179 | {0, 0x0000000, 0x0000000, 0x000000} } }, |
| 180 | {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ |
| 181 | {{{0} } }, /* 35: */ |
| 182 | {{{0} } }, /* 36: */ |
| 183 | {{{0} } }, /* 37: */ |
| 184 | {{{0} } }, /* 38: */ |
| 185 | {{{0} } }, /* 39: */ |
| 186 | {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ |
| 187 | {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ |
| 188 | {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ |
| 189 | {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ |
| 190 | {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ |
| 191 | {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ |
| 192 | {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ |
| 193 | {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ |
| 194 | {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ |
| 195 | {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ |
| 196 | {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ |
| 197 | {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ |
| 198 | {{{0} } }, /* 52: */ |
| 199 | {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ |
| 200 | {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ |
| 201 | {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ |
| 202 | {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ |
| 203 | {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ |
| 204 | {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ |
| 205 | {{{0} } }, /* 59: I2C0 */ |
| 206 | {{{0} } }, /* 60: I2C1 */ |
| 207 | {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */ |
| 208 | {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ |
| 209 | {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ |
| 210 | }; |
| 211 | |
| 212 | /* |
| 213 | * top 12 bits of crb internal address (hub, agent) |
| 214 | */ |
| 215 | static unsigned crb_hub_agt[64] = |
| 216 | { |
| 217 | 0, |
| 218 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, |
| 219 | NETXEN_HW_CRB_HUB_AGT_ADR_MN, |
| 220 | NETXEN_HW_CRB_HUB_AGT_ADR_MS, |
| 221 | 0, |
| 222 | NETXEN_HW_CRB_HUB_AGT_ADR_SRE, |
| 223 | NETXEN_HW_CRB_HUB_AGT_ADR_NIU, |
| 224 | NETXEN_HW_CRB_HUB_AGT_ADR_QMN, |
| 225 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN0, |
| 226 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN1, |
| 227 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN2, |
| 228 | NETXEN_HW_CRB_HUB_AGT_ADR_SQN3, |
| 229 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, |
| 230 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, |
| 231 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, |
| 232 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN4, |
| 233 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, |
| 234 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN0, |
| 235 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN1, |
| 236 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN2, |
| 237 | NETXEN_HW_CRB_HUB_AGT_ADR_PGN3, |
| 238 | NETXEN_HW_CRB_HUB_AGT_ADR_PGND, |
| 239 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNI, |
| 240 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS0, |
| 241 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS1, |
| 242 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS2, |
| 243 | NETXEN_HW_CRB_HUB_AGT_ADR_PGS3, |
| 244 | 0, |
| 245 | NETXEN_HW_CRB_HUB_AGT_ADR_PGSI, |
| 246 | NETXEN_HW_CRB_HUB_AGT_ADR_SN, |
| 247 | 0, |
| 248 | NETXEN_HW_CRB_HUB_AGT_ADR_EG, |
| 249 | 0, |
| 250 | NETXEN_HW_CRB_HUB_AGT_ADR_PS, |
| 251 | NETXEN_HW_CRB_HUB_AGT_ADR_CAM, |
| 252 | 0, |
| 253 | 0, |
| 254 | 0, |
| 255 | 0, |
| 256 | 0, |
| 257 | NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, |
| 258 | 0, |
| 259 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1, |
| 260 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2, |
| 261 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3, |
| 262 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4, |
| 263 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5, |
| 264 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6, |
| 265 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7, |
| 266 | NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, |
| 267 | NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, |
| 268 | NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, |
| 269 | 0, |
| 270 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0, |
| 271 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8, |
| 272 | NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9, |
| 273 | NETXEN_HW_CRB_HUB_AGT_ADR_OCM0, |
| 274 | 0, |
| 275 | NETXEN_HW_CRB_HUB_AGT_ADR_SMB, |
| 276 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C0, |
| 277 | NETXEN_HW_CRB_HUB_AGT_ADR_I2C1, |
| 278 | 0, |
| 279 | NETXEN_HW_CRB_HUB_AGT_ADR_PGNC, |
| 280 | 0, |
| 281 | }; |
| 282 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 283 | /* PCI Windowing for DDR regions. */ |
| 284 | |
| 285 | #define ADDR_IN_RANGE(addr, low, high) \ |
| 286 | (((addr) <= (high)) && ((addr) >= (low))) |
| 287 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 288 | #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 289 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 290 | #define NETXEN_NIC_ZERO_PAUSE_ADDR 0ULL |
| 291 | #define NETXEN_NIC_UNIT_PAUSE_ADDR 0x200ULL |
| 292 | #define NETXEN_NIC_EPG_PAUSE_ADDR1 0x2200010000c28001ULL |
| 293 | #define NETXEN_NIC_EPG_PAUSE_ADDR2 0x0100088866554433ULL |
| 294 | |
| 295 | #define NETXEN_NIC_WINDOW_MARGIN 0x100000 |
| 296 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 297 | int netxen_nic_set_mac(struct net_device *netdev, void *p) |
| 298 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 299 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 300 | struct sockaddr *addr = p; |
| 301 | |
| 302 | if (netif_running(netdev)) |
| 303 | return -EBUSY; |
| 304 | |
| 305 | if (!is_valid_ether_addr(addr->sa_data)) |
| 306 | return -EADDRNOTAVAIL; |
| 307 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 308 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 309 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 310 | /* For P3, MAC addr is not set in NIU */ |
| 311 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 312 | if (adapter->macaddr_set) |
| 313 | adapter->macaddr_set(adapter, addr->sa_data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 318 | #define NETXEN_UNICAST_ADDR(port, index) \ |
| 319 | (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8)) |
| 320 | #define NETXEN_MCAST_ADDR(port, index) \ |
| 321 | (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8)) |
| 322 | #define MAC_HI(addr) \ |
| 323 | ((addr[2] << 16) | (addr[1] << 8) | (addr[0])) |
| 324 | #define MAC_LO(addr) \ |
| 325 | ((addr[5] << 16) | (addr[4] << 8) | (addr[3])) |
| 326 | |
| 327 | static int |
| 328 | netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter) |
| 329 | { |
| 330 | u32 val = 0; |
| 331 | u16 port = adapter->physical_port; |
| 332 | u8 *addr = adapter->netdev->dev_addr; |
| 333 | |
| 334 | if (adapter->mc_enabled) |
| 335 | return 0; |
| 336 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 337 | adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4); |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 338 | val |= (1UL << (28+port)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 339 | adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4); |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 340 | |
| 341 | /* add broadcast addr to filter */ |
| 342 | val = 0xffffff; |
| 343 | netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val); |
| 344 | netxen_crb_writelit_adapter(adapter, |
| 345 | NETXEN_UNICAST_ADDR(port, 0)+4, val); |
| 346 | |
| 347 | /* add station addr to filter */ |
| 348 | val = MAC_HI(addr); |
| 349 | netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), val); |
| 350 | val = MAC_LO(addr); |
| 351 | netxen_crb_writelit_adapter(adapter, |
| 352 | NETXEN_UNICAST_ADDR(port, 1)+4, val); |
| 353 | |
| 354 | adapter->mc_enabled = 1; |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int |
| 359 | netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter) |
| 360 | { |
| 361 | u32 val = 0; |
| 362 | u16 port = adapter->physical_port; |
| 363 | u8 *addr = adapter->netdev->dev_addr; |
| 364 | |
| 365 | if (!adapter->mc_enabled) |
| 366 | return 0; |
| 367 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 368 | adapter->hw_read_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4); |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 369 | val &= ~(1UL << (28+port)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 370 | adapter->hw_write_wx(adapter, NETXEN_MAC_ADDR_CNTL_REG, &val, 4); |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 371 | |
| 372 | val = MAC_HI(addr); |
| 373 | netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 0), val); |
| 374 | val = MAC_LO(addr); |
| 375 | netxen_crb_writelit_adapter(adapter, |
| 376 | NETXEN_UNICAST_ADDR(port, 0)+4, val); |
| 377 | |
| 378 | netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1), 0); |
| 379 | netxen_crb_writelit_adapter(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0); |
| 380 | |
| 381 | adapter->mc_enabled = 0; |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static int |
| 386 | netxen_nic_set_mcast_addr(struct netxen_adapter *adapter, |
| 387 | int index, u8 *addr) |
| 388 | { |
| 389 | u32 hi = 0, lo = 0; |
| 390 | u16 port = adapter->physical_port; |
| 391 | |
| 392 | lo = MAC_LO(addr); |
| 393 | hi = MAC_HI(addr); |
| 394 | |
| 395 | netxen_crb_writelit_adapter(adapter, |
| 396 | NETXEN_MCAST_ADDR(port, index), hi); |
| 397 | netxen_crb_writelit_adapter(adapter, |
| 398 | NETXEN_MCAST_ADDR(port, index)+4, lo); |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 403 | void netxen_p2_nic_set_multi(struct net_device *netdev) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 404 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 405 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 406 | struct dev_mc_list *mc_ptr; |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 407 | u8 null_addr[6]; |
| 408 | int index = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 409 | |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 410 | memset(null_addr, 0, 6); |
| 411 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 412 | if (netdev->flags & IFF_PROMISC) { |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 413 | |
| 414 | adapter->set_promisc(adapter, |
| 415 | NETXEN_NIU_PROMISC_MODE); |
| 416 | |
| 417 | /* Full promiscuous mode */ |
| 418 | netxen_nic_disable_mcast_filter(adapter); |
| 419 | |
| 420 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 421 | } |
Dhananjay Phadke | 623621b | 2008-07-21 19:44:01 -0700 | [diff] [blame] | 422 | |
| 423 | if (netdev->mc_count == 0) { |
| 424 | adapter->set_promisc(adapter, |
| 425 | NETXEN_NIU_NON_PROMISC_MODE); |
| 426 | netxen_nic_disable_mcast_filter(adapter); |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE); |
| 431 | if (netdev->flags & IFF_ALLMULTI || |
| 432 | netdev->mc_count > adapter->max_mc_count) { |
| 433 | netxen_nic_disable_mcast_filter(adapter); |
| 434 | return; |
| 435 | } |
| 436 | |
| 437 | netxen_nic_enable_mcast_filter(adapter); |
| 438 | |
| 439 | for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, index++) |
| 440 | netxen_nic_set_mcast_addr(adapter, index, mc_ptr->dmi_addr); |
| 441 | |
| 442 | if (index != netdev->mc_count) |
| 443 | printk(KERN_WARNING "%s: %s multicast address count mismatch\n", |
| 444 | netxen_nic_driver_name, netdev->name); |
| 445 | |
| 446 | /* Clear out remaining addresses */ |
| 447 | for (; index < adapter->max_mc_count; index++) |
| 448 | netxen_nic_set_mcast_addr(adapter, index, null_addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 451 | static int nx_p3_nic_add_mac(struct netxen_adapter *adapter, |
| 452 | u8 *addr, nx_mac_list_t **add_list, nx_mac_list_t **del_list) |
| 453 | { |
| 454 | nx_mac_list_t *cur, *prev; |
| 455 | |
| 456 | /* if in del_list, move it to adapter->mac_list */ |
| 457 | for (cur = *del_list, prev = NULL; cur;) { |
| 458 | if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) { |
| 459 | if (prev == NULL) |
| 460 | *del_list = cur->next; |
| 461 | else |
| 462 | prev->next = cur->next; |
| 463 | cur->next = adapter->mac_list; |
| 464 | adapter->mac_list = cur; |
| 465 | return 0; |
| 466 | } |
| 467 | prev = cur; |
| 468 | cur = cur->next; |
| 469 | } |
| 470 | |
| 471 | /* make sure to add each mac address only once */ |
| 472 | for (cur = adapter->mac_list; cur; cur = cur->next) { |
| 473 | if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) |
| 474 | return 0; |
| 475 | } |
| 476 | /* not in del_list, create new entry and add to add_list */ |
| 477 | cur = kmalloc(sizeof(*cur), in_atomic()? GFP_ATOMIC : GFP_KERNEL); |
| 478 | if (cur == NULL) { |
| 479 | printk(KERN_ERR "%s: cannot allocate memory. MAC filtering may" |
| 480 | "not work properly from now.\n", __func__); |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | memcpy(cur->mac_addr, addr, ETH_ALEN); |
| 485 | cur->next = *add_list; |
| 486 | *add_list = cur; |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static int |
| 491 | netxen_send_cmd_descs(struct netxen_adapter *adapter, |
| 492 | struct cmd_desc_type0 *cmd_desc_arr, int nr_elements) |
| 493 | { |
| 494 | uint32_t i, producer; |
| 495 | struct netxen_cmd_buffer *pbuf; |
| 496 | struct cmd_desc_type0 *cmd_desc; |
| 497 | |
| 498 | if (nr_elements > MAX_PENDING_DESC_BLOCK_SIZE || nr_elements == 0) { |
| 499 | printk(KERN_WARNING "%s: Too many command descriptors in a " |
| 500 | "request\n", __func__); |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | |
| 504 | i = 0; |
| 505 | |
Dhananjay Phadke | 03e678e | 2009-01-14 20:49:43 -0800 | [diff] [blame] | 506 | netif_tx_lock_bh(adapter->netdev); |
| 507 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 508 | producer = adapter->cmd_producer; |
| 509 | do { |
| 510 | cmd_desc = &cmd_desc_arr[i]; |
| 511 | |
| 512 | pbuf = &adapter->cmd_buf_arr[producer]; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 513 | pbuf->skb = NULL; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 514 | pbuf->frag_count = 0; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 515 | |
| 516 | /* adapter->ahw.cmd_desc_head[producer] = *cmd_desc; */ |
| 517 | memcpy(&adapter->ahw.cmd_desc_head[producer], |
| 518 | &cmd_desc_arr[i], sizeof(struct cmd_desc_type0)); |
| 519 | |
| 520 | producer = get_next_index(producer, |
| 521 | adapter->max_tx_desc_count); |
| 522 | i++; |
| 523 | |
| 524 | } while (i != nr_elements); |
| 525 | |
| 526 | adapter->cmd_producer = producer; |
| 527 | |
| 528 | /* write producer index to start the xmit */ |
| 529 | |
| 530 | netxen_nic_update_cmd_producer(adapter, adapter->cmd_producer); |
| 531 | |
Dhananjay Phadke | 03e678e | 2009-01-14 20:49:43 -0800 | [diff] [blame] | 532 | netif_tx_unlock_bh(adapter->netdev); |
| 533 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 537 | static int nx_p3_sre_macaddr_change(struct net_device *dev, |
| 538 | u8 *addr, unsigned op) |
| 539 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 540 | struct netxen_adapter *adapter = netdev_priv(dev); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 541 | nx_nic_req_t req; |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 542 | nx_mac_req_t *mac_req; |
| 543 | u64 word; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 544 | int rv; |
| 545 | |
| 546 | memset(&req, 0, sizeof(nx_nic_req_t)); |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 547 | req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); |
| 548 | |
| 549 | word = NX_MAC_EVENT | ((u64)adapter->portnum << 16); |
| 550 | req.req_hdr = cpu_to_le64(word); |
| 551 | |
| 552 | mac_req = (nx_mac_req_t *)&req.words[0]; |
| 553 | mac_req->op = op; |
| 554 | memcpy(mac_req->mac_addr, addr, 6); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 555 | |
| 556 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); |
| 557 | if (rv != 0) { |
| 558 | printk(KERN_ERR "ERROR. Could not send mac update\n"); |
| 559 | return rv; |
| 560 | } |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | void netxen_p3_nic_set_multi(struct net_device *netdev) |
| 566 | { |
| 567 | struct netxen_adapter *adapter = netdev_priv(netdev); |
| 568 | nx_mac_list_t *cur, *next, *del_list, *add_list = NULL; |
| 569 | struct dev_mc_list *mc_ptr; |
| 570 | u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 571 | u32 mode = VPORT_MISS_MODE_DROP; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 572 | |
| 573 | del_list = adapter->mac_list; |
| 574 | adapter->mac_list = NULL; |
| 575 | |
| 576 | nx_p3_nic_add_mac(adapter, netdev->dev_addr, &add_list, &del_list); |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 577 | nx_p3_nic_add_mac(adapter, bcast_addr, &add_list, &del_list); |
| 578 | |
| 579 | if (netdev->flags & IFF_PROMISC) { |
| 580 | mode = VPORT_MISS_MODE_ACCEPT_ALL; |
| 581 | goto send_fw_cmd; |
| 582 | } |
| 583 | |
| 584 | if ((netdev->flags & IFF_ALLMULTI) || |
| 585 | (netdev->mc_count > adapter->max_mc_count)) { |
| 586 | mode = VPORT_MISS_MODE_ACCEPT_MULTI; |
| 587 | goto send_fw_cmd; |
| 588 | } |
| 589 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 590 | if (netdev->mc_count > 0) { |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 591 | for (mc_ptr = netdev->mc_list; mc_ptr; |
| 592 | mc_ptr = mc_ptr->next) { |
| 593 | nx_p3_nic_add_mac(adapter, mc_ptr->dmi_addr, |
| 594 | &add_list, &del_list); |
| 595 | } |
| 596 | } |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 597 | |
| 598 | send_fw_cmd: |
| 599 | adapter->set_promisc(adapter, mode); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 600 | for (cur = del_list; cur;) { |
| 601 | nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_DEL); |
| 602 | next = cur->next; |
| 603 | kfree(cur); |
| 604 | cur = next; |
| 605 | } |
| 606 | for (cur = add_list; cur;) { |
| 607 | nx_p3_sre_macaddr_change(netdev, cur->mac_addr, NETXEN_MAC_ADD); |
| 608 | next = cur->next; |
| 609 | cur->next = adapter->mac_list; |
| 610 | adapter->mac_list = cur; |
| 611 | cur = next; |
| 612 | } |
| 613 | } |
| 614 | |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 615 | int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) |
| 616 | { |
| 617 | nx_nic_req_t req; |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 618 | u64 word; |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 619 | |
| 620 | memset(&req, 0, sizeof(nx_nic_req_t)); |
| 621 | |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 622 | req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); |
| 623 | |
| 624 | word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE | |
| 625 | ((u64)adapter->portnum << 16); |
| 626 | req.req_hdr = cpu_to_le64(word); |
| 627 | |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 628 | req.words[0] = cpu_to_le64(mode); |
| 629 | |
| 630 | return netxen_send_cmd_descs(adapter, |
| 631 | (struct cmd_desc_type0 *)&req, 1); |
| 632 | } |
| 633 | |
Dhananjay Phadke | 06e9d9f | 2009-01-14 20:49:22 -0800 | [diff] [blame] | 634 | void netxen_p3_free_mac_list(struct netxen_adapter *adapter) |
| 635 | { |
| 636 | nx_mac_list_t *cur, *next; |
| 637 | |
| 638 | cur = adapter->mac_list; |
| 639 | |
| 640 | while (cur) { |
| 641 | next = cur->next; |
| 642 | kfree(cur); |
| 643 | cur = next; |
| 644 | } |
| 645 | } |
| 646 | |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 647 | #define NETXEN_CONFIG_INTR_COALESCE 3 |
| 648 | |
| 649 | /* |
| 650 | * Send the interrupt coalescing parameter set by ethtool to the card. |
| 651 | */ |
| 652 | int netxen_config_intr_coalesce(struct netxen_adapter *adapter) |
| 653 | { |
| 654 | nx_nic_req_t req; |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 655 | u64 word; |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 656 | int rv; |
| 657 | |
| 658 | memset(&req, 0, sizeof(nx_nic_req_t)); |
| 659 | |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 660 | req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); |
| 661 | |
| 662 | word = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16); |
| 663 | req.req_hdr = cpu_to_le64(word); |
Dhananjay Phadke | cd1f816 | 2008-07-21 19:44:09 -0700 | [diff] [blame] | 664 | |
| 665 | memcpy(&req.words[0], &adapter->coal, sizeof(adapter->coal)); |
| 666 | |
| 667 | rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); |
| 668 | if (rv != 0) { |
| 669 | printk(KERN_ERR "ERROR. Could not send " |
| 670 | "interrupt coalescing parameters\n"); |
| 671 | } |
| 672 | |
| 673 | return rv; |
| 674 | } |
| 675 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 676 | /* |
| 677 | * netxen_nic_change_mtu - Change the Maximum Transfer Unit |
| 678 | * @returns 0 on success, negative on failure |
| 679 | */ |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 680 | |
| 681 | #define MTU_FUDGE_FACTOR 100 |
| 682 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 683 | int netxen_nic_change_mtu(struct net_device *netdev, int mtu) |
| 684 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 685 | struct netxen_adapter *adapter = netdev_priv(netdev); |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 686 | int max_mtu; |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 687 | int rc = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 688 | |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 689 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 690 | max_mtu = P3_MAX_MTU; |
| 691 | else |
| 692 | max_mtu = P2_MAX_MTU; |
| 693 | |
| 694 | if (mtu > max_mtu) { |
| 695 | printk(KERN_ERR "%s: mtu > %d bytes unsupported\n", |
| 696 | netdev->name, max_mtu); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 697 | return -EINVAL; |
| 698 | } |
| 699 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 700 | if (adapter->set_mtu) |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 701 | rc = adapter->set_mtu(adapter, mtu); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 702 | |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 703 | if (!rc) |
| 704 | netdev->mtu = mtu; |
Dhananjay Phadke | c9fc891 | 2008-07-21 19:44:07 -0700 | [diff] [blame] | 705 | |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 706 | return rc; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 707 | } |
| 708 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 709 | int netxen_is_flash_supported(struct netxen_adapter *adapter) |
| 710 | { |
| 711 | const int locs[] = { 0, 0x4, 0x100, 0x4000, 0x4128 }; |
| 712 | int addr, val01, val02, i, j; |
| 713 | |
| 714 | /* if the flash size less than 4Mb, make huge war cry and die */ |
| 715 | for (j = 1; j < 4; j++) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 716 | addr = j * NETXEN_NIC_WINDOW_MARGIN; |
Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 717 | for (i = 0; i < ARRAY_SIZE(locs); i++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 718 | if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0 |
| 719 | && netxen_rom_fast_read(adapter, (addr + locs[i]), |
| 720 | &val02) == 0) { |
| 721 | if (val01 == val02) |
| 722 | return -1; |
| 723 | } else |
| 724 | return -1; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 732 | int size, __le32 * buf) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 733 | { |
| 734 | int i, addr; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 735 | __le32 *ptr32; |
| 736 | u32 v; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 737 | |
| 738 | addr = base; |
| 739 | ptr32 = buf; |
| 740 | for (i = 0; i < size / sizeof(u32); i++) { |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 741 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 742 | return -1; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 743 | *ptr32 = cpu_to_le32(v); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 744 | ptr32++; |
| 745 | addr += sizeof(u32); |
| 746 | } |
| 747 | if ((char *)buf + size > (char *)ptr32) { |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 748 | __le32 local; |
| 749 | if (netxen_rom_fast_read(adapter, addr, &v) == -1) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 750 | return -1; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 751 | local = cpu_to_le32(v); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 752 | memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); |
| 753 | } |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 758 | int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, __le64 *mac) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 759 | { |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 760 | __le32 *pmac = (__le32 *) mac; |
| 761 | u32 offset; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 762 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 763 | offset = NETXEN_USER_START + |
| 764 | offsetof(struct netxen_new_user_info, mac_addr) + |
| 765 | adapter->portnum * sizeof(u64); |
| 766 | |
| 767 | if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 768 | return -1; |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 769 | |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 770 | if (*mac == cpu_to_le64(~0ULL)) { |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 771 | |
| 772 | offset = NETXEN_USER_START_OLD + |
| 773 | offsetof(struct netxen_user_old_info, mac_addr) + |
| 774 | adapter->portnum * sizeof(u64); |
| 775 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 776 | if (netxen_get_flash_block(adapter, |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 777 | offset, sizeof(u64), pmac) == -1) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 778 | return -1; |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 779 | |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 780 | if (*mac == cpu_to_le64(~0ULL)) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 781 | return -1; |
| 782 | } |
| 783 | return 0; |
| 784 | } |
| 785 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 786 | int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, __le64 *mac) |
| 787 | { |
| 788 | uint32_t crbaddr, mac_hi, mac_lo; |
| 789 | int pci_func = adapter->ahw.pci_func; |
| 790 | |
| 791 | crbaddr = CRB_MAC_BLOCK_START + |
| 792 | (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1)); |
| 793 | |
| 794 | adapter->hw_read_wx(adapter, crbaddr, &mac_lo, 4); |
| 795 | adapter->hw_read_wx(adapter, crbaddr+4, &mac_hi, 4); |
| 796 | |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 797 | if (pci_func & 1) |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 798 | *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16)); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 799 | else |
Dhananjay Phadke | 2edbb45 | 2009-01-14 20:47:30 -0800 | [diff] [blame] | 800 | *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32)); |
Dhananjay Phadke | 9dc28ef | 2008-08-08 00:08:39 -0700 | [diff] [blame] | 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 805 | #define CRB_WIN_LOCK_TIMEOUT 100000000 |
| 806 | |
| 807 | static int crb_win_lock(struct netxen_adapter *adapter) |
| 808 | { |
| 809 | int done = 0, timeout = 0; |
| 810 | |
| 811 | while (!done) { |
| 812 | /* acquire semaphore3 from PCI HW block */ |
| 813 | adapter->hw_read_wx(adapter, |
| 814 | NETXEN_PCIE_REG(PCIE_SEM7_LOCK), &done, 4); |
| 815 | if (done == 1) |
| 816 | break; |
| 817 | if (timeout >= CRB_WIN_LOCK_TIMEOUT) |
| 818 | return -1; |
| 819 | timeout++; |
| 820 | udelay(1); |
| 821 | } |
| 822 | netxen_crb_writelit_adapter(adapter, |
| 823 | NETXEN_CRB_WIN_LOCK_ID, adapter->portnum); |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | static void crb_win_unlock(struct netxen_adapter *adapter) |
| 828 | { |
| 829 | int val; |
| 830 | |
| 831 | adapter->hw_read_wx(adapter, |
| 832 | NETXEN_PCIE_REG(PCIE_SEM7_UNLOCK), &val, 4); |
| 833 | } |
| 834 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 835 | /* |
| 836 | * Changes the CRB window to the specified window. |
| 837 | */ |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 838 | void |
| 839 | netxen_nic_pci_change_crbwindow_128M(struct netxen_adapter *adapter, u32 wndw) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 840 | { |
| 841 | void __iomem *offset; |
| 842 | u32 tmp; |
| 843 | int count = 0; |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 844 | uint8_t func = adapter->ahw.pci_func; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 845 | |
| 846 | if (adapter->curr_window == wndw) |
| 847 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 848 | /* |
| 849 | * Move the CRB window. |
| 850 | * We need to write to the "direct access" region of PCI |
| 851 | * to avoid a race condition where the window register has |
| 852 | * not been successfully written across CRB before the target |
| 853 | * register address is received by PCI. The direct region bypasses |
| 854 | * the CRB bus. |
| 855 | */ |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 856 | offset = PCI_OFFSET_SECOND_RANGE(adapter, |
| 857 | NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 858 | |
| 859 | if (wndw & 0x1) |
| 860 | wndw = NETXEN_WINDOW_ONE; |
| 861 | |
| 862 | writel(wndw, offset); |
| 863 | |
| 864 | /* MUST make sure window is set before we forge on... */ |
| 865 | while ((tmp = readl(offset)) != wndw) { |
| 866 | printk(KERN_WARNING "%s: %s WARNING: CRB window value not " |
| 867 | "registered properly: 0x%08x.\n", |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 868 | netxen_nic_driver_name, __func__, tmp); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 869 | mdelay(1); |
| 870 | if (count >= 10) |
| 871 | break; |
| 872 | count++; |
| 873 | } |
| 874 | |
Mithlesh Thukral | 6c80b18 | 2007-04-20 07:55:26 -0700 | [diff] [blame] | 875 | if (wndw == NETXEN_WINDOW_ONE) |
| 876 | adapter->curr_window = 1; |
| 877 | else |
| 878 | adapter->curr_window = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 879 | } |
| 880 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 881 | /* |
| 882 | * Return -1 if off is not valid, |
| 883 | * 1 if window access is needed. 'off' is set to offset from |
| 884 | * CRB space in 128M pci map |
| 885 | * 0 if no window access is needed. 'off' is set to 2M addr |
| 886 | * In: 'off' is offset from base in 128M pci map |
| 887 | */ |
| 888 | static int |
| 889 | netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, |
| 890 | ulong *off, int len) |
| 891 | { |
| 892 | unsigned long end = *off + len; |
| 893 | crb_128M_2M_sub_block_map_t *m; |
| 894 | |
| 895 | |
| 896 | if (*off >= NETXEN_CRB_MAX) |
| 897 | return -1; |
| 898 | |
| 899 | if (*off >= NETXEN_PCI_CAMQM && (end <= NETXEN_PCI_CAMQM_2M_END)) { |
| 900 | *off = (*off - NETXEN_PCI_CAMQM) + NETXEN_PCI_CAMQM_2M_BASE + |
| 901 | (ulong)adapter->ahw.pci_base0; |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | if (*off < NETXEN_PCI_CRBSPACE) |
| 906 | return -1; |
| 907 | |
| 908 | *off -= NETXEN_PCI_CRBSPACE; |
| 909 | end = *off + len; |
| 910 | |
| 911 | /* |
| 912 | * Try direct map |
| 913 | */ |
| 914 | m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)]; |
| 915 | |
| 916 | if (m->valid && (m->start_128M <= *off) && (m->end_128M >= end)) { |
| 917 | *off = *off + m->start_2M - m->start_128M + |
| 918 | (ulong)adapter->ahw.pci_base0; |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Not in direct map, use crb window |
| 924 | */ |
| 925 | return 1; |
| 926 | } |
| 927 | |
| 928 | /* |
| 929 | * In: 'off' is offset from CRB space in 128M pci map |
| 930 | * Out: 'off' is 2M pci map addr |
| 931 | * side effect: lock crb window |
| 932 | */ |
| 933 | static void |
| 934 | netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong *off) |
| 935 | { |
| 936 | u32 win_read; |
| 937 | |
| 938 | adapter->crb_win = CRB_HI(*off); |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 939 | writel(adapter->crb_win, (adapter->ahw.pci_base0 + CRB_WINDOW_2M)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 940 | /* |
| 941 | * Read back value to make sure write has gone through before trying |
| 942 | * to use it. |
| 943 | */ |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 944 | win_read = readl(adapter->ahw.pci_base0 + CRB_WINDOW_2M); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 945 | if (win_read != adapter->crb_win) { |
| 946 | printk(KERN_ERR "%s: Written crbwin (0x%x) != " |
| 947 | "Read crbwin (0x%x), off=0x%lx\n", |
| 948 | __func__, adapter->crb_win, win_read, *off); |
| 949 | } |
| 950 | *off = (*off & MASK(16)) + CRB_INDIRECT_2M + |
| 951 | (ulong)adapter->ahw.pci_base0; |
| 952 | } |
| 953 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 954 | int netxen_load_firmware(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 955 | { |
| 956 | int i; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 957 | u32 data, size = 0; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 958 | u32 flashaddr = NETXEN_BOOTLD_START; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 959 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 960 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START)/4; |
| 961 | |
| 962 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 963 | adapter->pci_write_normalize(adapter, |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 964 | NETXEN_ROMUSB_GLB_CAS_RST, 1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 965 | |
| 966 | for (i = 0; i < size; i++) { |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 967 | if (netxen_rom_fast_read(adapter, flashaddr, (int *)&data) != 0) |
| 968 | return -EIO; |
| 969 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 970 | adapter->pci_mem_write(adapter, flashaddr, &data, 4); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 971 | flashaddr += 4; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 972 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 973 | msleep(1); |
| 974 | |
| 975 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 976 | adapter->pci_write_normalize(adapter, |
| 977 | NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); |
| 978 | else { |
| 979 | adapter->pci_write_normalize(adapter, |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 980 | NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 981 | adapter->pci_write_normalize(adapter, |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 982 | NETXEN_ROMUSB_GLB_CAS_RST, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 983 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 984 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 985 | return 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | int |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 989 | netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, |
| 990 | ulong off, void *data, int len) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 991 | { |
| 992 | void __iomem *addr; |
| 993 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 994 | BUG_ON(len != 4); |
| 995 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 996 | if (ADDR_IN_WINDOW1(off)) { |
| 997 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 998 | } else { /* Window 0 */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 999 | addr = pci_base_offset(adapter, off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1000 | netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1001 | } |
| 1002 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1003 | if (!addr) { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1004 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1005 | return 1; |
| 1006 | } |
| 1007 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1008 | writel(*(u32 *) data, addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1009 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1010 | if (!ADDR_IN_WINDOW1(off)) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1011 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | int |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1017 | netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, |
| 1018 | ulong off, void *data, int len) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1019 | { |
| 1020 | void __iomem *addr; |
| 1021 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1022 | BUG_ON(len != 4); |
| 1023 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1024 | if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ |
| 1025 | addr = NETXEN_CRB_NORMALIZE(adapter, off); |
| 1026 | } else { /* Window 0 */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1027 | addr = pci_base_offset(adapter, off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1028 | netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1029 | } |
| 1030 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1031 | if (!addr) { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1032 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1033 | return 1; |
| 1034 | } |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1035 | |
| 1036 | *(u32 *)data = readl(addr); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1037 | |
| 1038 | if (!ADDR_IN_WINDOW1(off)) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1039 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
| 1040 | |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | int |
| 1045 | netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, |
| 1046 | ulong off, void *data, int len) |
| 1047 | { |
| 1048 | unsigned long flags = 0; |
| 1049 | int rv; |
| 1050 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1051 | BUG_ON(len != 4); |
| 1052 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1053 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len); |
| 1054 | |
| 1055 | if (rv == -1) { |
| 1056 | printk(KERN_ERR "%s: invalid offset: 0x%016lx\n", |
| 1057 | __func__, off); |
| 1058 | dump_stack(); |
| 1059 | return -1; |
| 1060 | } |
| 1061 | |
| 1062 | if (rv == 1) { |
| 1063 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1064 | crb_win_lock(adapter); |
| 1065 | netxen_nic_pci_set_crbwindow_2M(adapter, &off); |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1066 | writel(*(uint32_t *)data, (void __iomem *)off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1067 | crb_win_unlock(adapter); |
| 1068 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1069 | } else |
| 1070 | writel(*(uint32_t *)data, (void __iomem *)off); |
| 1071 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | int |
| 1077 | netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, |
| 1078 | ulong off, void *data, int len) |
| 1079 | { |
| 1080 | unsigned long flags = 0; |
| 1081 | int rv; |
| 1082 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1083 | BUG_ON(len != 4); |
| 1084 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1085 | rv = netxen_nic_pci_get_crb_addr_2M(adapter, &off, len); |
| 1086 | |
| 1087 | if (rv == -1) { |
| 1088 | printk(KERN_ERR "%s: invalid offset: 0x%016lx\n", |
| 1089 | __func__, off); |
| 1090 | dump_stack(); |
| 1091 | return -1; |
| 1092 | } |
| 1093 | |
| 1094 | if (rv == 1) { |
| 1095 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1096 | crb_win_lock(adapter); |
| 1097 | netxen_nic_pci_set_crbwindow_2M(adapter, &off); |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1098 | *(uint32_t *)data = readl((void __iomem *)off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1099 | crb_win_unlock(adapter); |
| 1100 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1101 | } else |
| 1102 | *(uint32_t *)data = readl((void __iomem *)off); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | void netxen_nic_reg_write(struct netxen_adapter *adapter, u64 off, u32 val) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1108 | { |
| 1109 | adapter->hw_write_wx(adapter, off, &val, 4); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | int netxen_nic_reg_read(struct netxen_adapter *adapter, u64 off) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1113 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1114 | int val; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1115 | adapter->hw_read_wx(adapter, off, &val, 4); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1116 | return val; |
| 1117 | } |
| 1118 | |
| 1119 | /* Change the window to 0, write and change back to window 1. */ |
| 1120 | void netxen_nic_write_w0(struct netxen_adapter *adapter, u32 index, u32 value) |
| 1121 | { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1122 | adapter->hw_write_wx(adapter, index, &value, 4); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /* Change the window to 0, read and change back to window 1. */ |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1126 | void netxen_nic_read_w0(struct netxen_adapter *adapter, u32 index, u32 *value) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1127 | { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1128 | adapter->hw_read_wx(adapter, index, value, 4); |
| 1129 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1130 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1131 | void netxen_nic_write_w1(struct netxen_adapter *adapter, u32 index, u32 value) |
| 1132 | { |
| 1133 | adapter->hw_write_wx(adapter, index, &value, 4); |
| 1134 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1135 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1136 | void netxen_nic_read_w1(struct netxen_adapter *adapter, u32 index, u32 *value) |
| 1137 | { |
| 1138 | adapter->hw_read_wx(adapter, index, value, 4); |
| 1139 | } |
| 1140 | |
| 1141 | /* |
| 1142 | * check memory access boundary. |
| 1143 | * used by test agent. support ddr access only for now |
| 1144 | */ |
| 1145 | static unsigned long |
| 1146 | netxen_nic_pci_mem_bound_check(struct netxen_adapter *adapter, |
| 1147 | unsigned long long addr, int size) |
| 1148 | { |
| 1149 | if (!ADDR_IN_RANGE(addr, |
| 1150 | NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) || |
| 1151 | !ADDR_IN_RANGE(addr+size-1, |
| 1152 | NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX) || |
| 1153 | ((size != 1) && (size != 2) && (size != 4) && (size != 8))) { |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | return 1; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1160 | static int netxen_pci_set_window_warning_count; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1161 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1162 | unsigned long |
| 1163 | netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter, |
| 1164 | unsigned long long addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1165 | { |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1166 | void __iomem *offset; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1167 | int window; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1168 | unsigned long long qdr_max; |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1169 | uint8_t func = adapter->ahw.pci_func; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1170 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1171 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 1172 | qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2; |
| 1173 | } else { |
| 1174 | qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3; |
| 1175 | } |
| 1176 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1177 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
| 1178 | /* DDR network side */ |
| 1179 | addr -= NETXEN_ADDR_DDR_NET; |
| 1180 | window = (addr >> 25) & 0x3ff; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1181 | if (adapter->ahw.ddr_mn_window != window) { |
| 1182 | adapter->ahw.ddr_mn_window = window; |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1183 | offset = PCI_OFFSET_SECOND_RANGE(adapter, |
| 1184 | NETXEN_PCIX_PH_REG(PCIE_MN_WINDOW_REG(func))); |
| 1185 | writel(window, offset); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1186 | /* MUST make sure window is set before we forge on... */ |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1187 | readl(offset); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1188 | } |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 1189 | addr -= (window * NETXEN_WINDOW_ONE); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1190 | addr += NETXEN_PCI_DDR_NET; |
| 1191 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
| 1192 | addr -= NETXEN_ADDR_OCM0; |
| 1193 | addr += NETXEN_PCI_OCM0; |
| 1194 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { |
| 1195 | addr -= NETXEN_ADDR_OCM1; |
| 1196 | addr += NETXEN_PCI_OCM1; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1197 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1198 | /* QDR network side */ |
| 1199 | addr -= NETXEN_ADDR_QDR_NET; |
| 1200 | window = (addr >> 22) & 0x3f; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1201 | if (adapter->ahw.qdr_sn_window != window) { |
| 1202 | adapter->ahw.qdr_sn_window = window; |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1203 | offset = PCI_OFFSET_SECOND_RANGE(adapter, |
| 1204 | NETXEN_PCIX_PH_REG(PCIE_SN_WINDOW_REG(func))); |
| 1205 | writel((window << 22), offset); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1206 | /* MUST make sure window is set before we forge on... */ |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1207 | readl(offset); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1208 | } |
| 1209 | addr -= (window * 0x400000); |
| 1210 | addr += NETXEN_PCI_QDR_NET; |
| 1211 | } else { |
| 1212 | /* |
| 1213 | * peg gdb frequently accesses memory that doesn't exist, |
| 1214 | * this limits the chit chat so debugging isn't slowed down. |
| 1215 | */ |
| 1216 | if ((netxen_pci_set_window_warning_count++ < 8) |
| 1217 | || (netxen_pci_set_window_warning_count % 64 == 0)) |
| 1218 | printk("%s: Warning:netxen_nic_pci_set_window()" |
| 1219 | " Unknown address range!\n", |
| 1220 | netxen_nic_driver_name); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1221 | addr = -1UL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1222 | } |
| 1223 | return addr; |
| 1224 | } |
| 1225 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1226 | /* |
| 1227 | * Note : only 32-bit writes! |
| 1228 | */ |
| 1229 | int netxen_nic_pci_write_immediate_128M(struct netxen_adapter *adapter, |
| 1230 | u64 off, u32 data) |
| 1231 | { |
| 1232 | writel(data, (void __iomem *)(PCI_OFFSET_SECOND_RANGE(adapter, off))); |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | u32 netxen_nic_pci_read_immediate_128M(struct netxen_adapter *adapter, u64 off) |
| 1237 | { |
| 1238 | return readl((void __iomem *)(pci_base_offset(adapter, off))); |
| 1239 | } |
| 1240 | |
| 1241 | void netxen_nic_pci_write_normalize_128M(struct netxen_adapter *adapter, |
| 1242 | u64 off, u32 data) |
| 1243 | { |
| 1244 | writel(data, NETXEN_CRB_NORMALIZE(adapter, off)); |
| 1245 | } |
| 1246 | |
| 1247 | u32 netxen_nic_pci_read_normalize_128M(struct netxen_adapter *adapter, u64 off) |
| 1248 | { |
| 1249 | return readl(NETXEN_CRB_NORMALIZE(adapter, off)); |
| 1250 | } |
| 1251 | |
| 1252 | unsigned long |
| 1253 | netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter, |
| 1254 | unsigned long long addr) |
| 1255 | { |
| 1256 | int window; |
| 1257 | u32 win_read; |
| 1258 | |
| 1259 | if (ADDR_IN_RANGE(addr, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
| 1260 | /* DDR network side */ |
| 1261 | window = MN_WIN(addr); |
| 1262 | adapter->ahw.ddr_mn_window = window; |
| 1263 | adapter->hw_write_wx(adapter, |
| 1264 | adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE, |
| 1265 | &window, 4); |
| 1266 | adapter->hw_read_wx(adapter, |
| 1267 | adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE, |
| 1268 | &win_read, 4); |
| 1269 | if ((win_read << 17) != window) { |
| 1270 | printk(KERN_INFO "Written MNwin (0x%x) != " |
| 1271 | "Read MNwin (0x%x)\n", window, win_read); |
| 1272 | } |
| 1273 | addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_DDR_NET; |
| 1274 | } else if (ADDR_IN_RANGE(addr, |
| 1275 | NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
| 1276 | if ((addr & 0x00ff800) == 0xff800) { |
| 1277 | printk("%s: QM access not handled.\n", __func__); |
| 1278 | addr = -1UL; |
| 1279 | } |
| 1280 | |
| 1281 | window = OCM_WIN(addr); |
| 1282 | adapter->ahw.ddr_mn_window = window; |
| 1283 | adapter->hw_write_wx(adapter, |
| 1284 | adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE, |
| 1285 | &window, 4); |
| 1286 | adapter->hw_read_wx(adapter, |
| 1287 | adapter->ahw.mn_win_crb | NETXEN_PCI_CRBSPACE, |
| 1288 | &win_read, 4); |
| 1289 | if ((win_read >> 7) != window) { |
| 1290 | printk(KERN_INFO "%s: Written OCMwin (0x%x) != " |
| 1291 | "Read OCMwin (0x%x)\n", |
| 1292 | __func__, window, win_read); |
| 1293 | } |
| 1294 | addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_OCM0_2M; |
| 1295 | |
| 1296 | } else if (ADDR_IN_RANGE(addr, |
| 1297 | NETXEN_ADDR_QDR_NET, NETXEN_ADDR_QDR_NET_MAX_P3)) { |
| 1298 | /* QDR network side */ |
| 1299 | window = MS_WIN(addr); |
| 1300 | adapter->ahw.qdr_sn_window = window; |
| 1301 | adapter->hw_write_wx(adapter, |
| 1302 | adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE, |
| 1303 | &window, 4); |
| 1304 | adapter->hw_read_wx(adapter, |
| 1305 | adapter->ahw.ms_win_crb | NETXEN_PCI_CRBSPACE, |
| 1306 | &win_read, 4); |
| 1307 | if (win_read != window) { |
| 1308 | printk(KERN_INFO "%s: Written MSwin (0x%x) != " |
| 1309 | "Read MSwin (0x%x)\n", |
| 1310 | __func__, window, win_read); |
| 1311 | } |
| 1312 | addr = GET_MEM_OFFS_2M(addr) + NETXEN_PCI_QDR_NET; |
| 1313 | |
| 1314 | } else { |
| 1315 | /* |
| 1316 | * peg gdb frequently accesses memory that doesn't exist, |
| 1317 | * this limits the chit chat so debugging isn't slowed down. |
| 1318 | */ |
| 1319 | if ((netxen_pci_set_window_warning_count++ < 8) |
| 1320 | || (netxen_pci_set_window_warning_count%64 == 0)) { |
| 1321 | printk("%s: Warning:%s Unknown address range!\n", |
| 1322 | __func__, netxen_nic_driver_name); |
| 1323 | } |
| 1324 | addr = -1UL; |
| 1325 | } |
| 1326 | return addr; |
| 1327 | } |
| 1328 | |
| 1329 | static int netxen_nic_pci_is_same_window(struct netxen_adapter *adapter, |
| 1330 | unsigned long long addr) |
| 1331 | { |
| 1332 | int window; |
| 1333 | unsigned long long qdr_max; |
| 1334 | |
| 1335 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 1336 | qdr_max = NETXEN_ADDR_QDR_NET_MAX_P2; |
| 1337 | else |
| 1338 | qdr_max = NETXEN_ADDR_QDR_NET_MAX_P3; |
| 1339 | |
| 1340 | if (ADDR_IN_RANGE(addr, |
| 1341 | NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { |
| 1342 | /* DDR network side */ |
| 1343 | BUG(); /* MN access can not come here */ |
| 1344 | } else if (ADDR_IN_RANGE(addr, |
| 1345 | NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { |
| 1346 | return 1; |
| 1347 | } else if (ADDR_IN_RANGE(addr, |
| 1348 | NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { |
| 1349 | return 1; |
| 1350 | } else if (ADDR_IN_RANGE(addr, NETXEN_ADDR_QDR_NET, qdr_max)) { |
| 1351 | /* QDR network side */ |
| 1352 | window = ((addr - NETXEN_ADDR_QDR_NET) >> 22) & 0x3f; |
| 1353 | if (adapter->ahw.qdr_sn_window == window) |
| 1354 | return 1; |
| 1355 | } |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static int netxen_nic_pci_mem_read_direct(struct netxen_adapter *adapter, |
| 1361 | u64 off, void *data, int size) |
| 1362 | { |
| 1363 | unsigned long flags; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1364 | void __iomem *addr, *mem_ptr = NULL; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1365 | int ret = 0; |
| 1366 | u64 start; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1367 | unsigned long mem_base; |
| 1368 | unsigned long mem_page; |
| 1369 | |
| 1370 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1371 | |
| 1372 | /* |
| 1373 | * If attempting to access unknown address or straddle hw windows, |
| 1374 | * do not access. |
| 1375 | */ |
| 1376 | start = adapter->pci_set_window(adapter, off); |
| 1377 | if ((start == -1UL) || |
| 1378 | (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) { |
| 1379 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1380 | printk(KERN_ERR "%s out of bound pci memory access. " |
Andrew Morton | 11a859e | 2008-07-30 12:50:12 -0700 | [diff] [blame] | 1381 | "offset is 0x%llx\n", netxen_nic_driver_name, |
| 1382 | (unsigned long long)off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1383 | return -1; |
| 1384 | } |
| 1385 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1386 | addr = pci_base_offset(adapter, start); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1387 | if (!addr) { |
| 1388 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1389 | mem_base = pci_resource_start(adapter->pdev, 0); |
| 1390 | mem_page = start & PAGE_MASK; |
| 1391 | /* Map two pages whenever user tries to access addresses in two |
| 1392 | consecutive pages. |
| 1393 | */ |
| 1394 | if (mem_page != ((start + size - 1) & PAGE_MASK)) |
| 1395 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2); |
| 1396 | else |
| 1397 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE); |
Hannes Eder | f8057b7 | 2008-12-26 00:04:26 -0800 | [diff] [blame] | 1398 | if (mem_ptr == NULL) { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1399 | *(uint8_t *)data = 0; |
| 1400 | return -1; |
| 1401 | } |
| 1402 | addr = mem_ptr; |
| 1403 | addr += start & (PAGE_SIZE - 1); |
| 1404 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1405 | } |
| 1406 | |
| 1407 | switch (size) { |
| 1408 | case 1: |
| 1409 | *(uint8_t *)data = readb(addr); |
| 1410 | break; |
| 1411 | case 2: |
| 1412 | *(uint16_t *)data = readw(addr); |
| 1413 | break; |
| 1414 | case 4: |
| 1415 | *(uint32_t *)data = readl(addr); |
| 1416 | break; |
| 1417 | case 8: |
| 1418 | *(uint64_t *)data = readq(addr); |
| 1419 | break; |
| 1420 | default: |
| 1421 | ret = -1; |
| 1422 | break; |
| 1423 | } |
| 1424 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1425 | |
| 1426 | if (mem_ptr) |
| 1427 | iounmap(mem_ptr); |
| 1428 | return ret; |
| 1429 | } |
| 1430 | |
| 1431 | static int |
| 1432 | netxen_nic_pci_mem_write_direct(struct netxen_adapter *adapter, u64 off, |
| 1433 | void *data, int size) |
| 1434 | { |
| 1435 | unsigned long flags; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1436 | void __iomem *addr, *mem_ptr = NULL; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1437 | int ret = 0; |
| 1438 | u64 start; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1439 | unsigned long mem_base; |
| 1440 | unsigned long mem_page; |
| 1441 | |
| 1442 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1443 | |
| 1444 | /* |
| 1445 | * If attempting to access unknown address or straddle hw windows, |
| 1446 | * do not access. |
| 1447 | */ |
| 1448 | start = adapter->pci_set_window(adapter, off); |
| 1449 | if ((start == -1UL) || |
| 1450 | (netxen_nic_pci_is_same_window(adapter, off+size-1) == 0)) { |
| 1451 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1452 | printk(KERN_ERR "%s out of bound pci memory access. " |
Andrew Morton | 11a859e | 2008-07-30 12:50:12 -0700 | [diff] [blame] | 1453 | "offset is 0x%llx\n", netxen_nic_driver_name, |
| 1454 | (unsigned long long)off); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1455 | return -1; |
| 1456 | } |
| 1457 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1458 | addr = pci_base_offset(adapter, start); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1459 | if (!addr) { |
| 1460 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1461 | mem_base = pci_resource_start(adapter->pdev, 0); |
| 1462 | mem_page = start & PAGE_MASK; |
| 1463 | /* Map two pages whenever user tries to access addresses in two |
| 1464 | * consecutive pages. |
| 1465 | */ |
| 1466 | if (mem_page != ((start + size - 1) & PAGE_MASK)) |
| 1467 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2); |
| 1468 | else |
| 1469 | mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE); |
Hannes Eder | f8057b7 | 2008-12-26 00:04:26 -0800 | [diff] [blame] | 1470 | if (mem_ptr == NULL) |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1471 | return -1; |
| 1472 | addr = mem_ptr; |
| 1473 | addr += start & (PAGE_SIZE - 1); |
| 1474 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1475 | } |
| 1476 | |
| 1477 | switch (size) { |
| 1478 | case 1: |
| 1479 | writeb(*(uint8_t *)data, addr); |
| 1480 | break; |
| 1481 | case 2: |
| 1482 | writew(*(uint16_t *)data, addr); |
| 1483 | break; |
| 1484 | case 4: |
| 1485 | writel(*(uint32_t *)data, addr); |
| 1486 | break; |
| 1487 | case 8: |
| 1488 | writeq(*(uint64_t *)data, addr); |
| 1489 | break; |
| 1490 | default: |
| 1491 | ret = -1; |
| 1492 | break; |
| 1493 | } |
| 1494 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1495 | if (mem_ptr) |
| 1496 | iounmap(mem_ptr); |
| 1497 | return ret; |
| 1498 | } |
| 1499 | |
| 1500 | #define MAX_CTL_CHECK 1000 |
| 1501 | |
| 1502 | int |
| 1503 | netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, |
| 1504 | u64 off, void *data, int size) |
| 1505 | { |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1506 | unsigned long flags; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1507 | int i, j, ret = 0, loop, sz[2], off0; |
| 1508 | uint32_t temp; |
| 1509 | uint64_t off8, tmpw, word[2] = {0, 0}; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1510 | void __iomem *mem_crb; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1511 | |
| 1512 | /* |
| 1513 | * If not MN, go check for MS or invalid. |
| 1514 | */ |
| 1515 | if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0) |
| 1516 | return netxen_nic_pci_mem_write_direct(adapter, |
| 1517 | off, data, size); |
| 1518 | |
| 1519 | off8 = off & 0xfffffff8; |
| 1520 | off0 = off & 0x7; |
| 1521 | sz[0] = (size < (8 - off0)) ? size : (8 - off0); |
| 1522 | sz[1] = size - sz[0]; |
| 1523 | loop = ((off0 + size - 1) >> 3) + 1; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1524 | mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1525 | |
| 1526 | if ((size != 8) || (off0 != 0)) { |
| 1527 | for (i = 0; i < loop; i++) { |
| 1528 | if (adapter->pci_mem_read(adapter, |
| 1529 | off8 + (i << 3), &word[i], 8)) |
| 1530 | return -1; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | switch (size) { |
| 1535 | case 1: |
| 1536 | tmpw = *((uint8_t *)data); |
| 1537 | break; |
| 1538 | case 2: |
| 1539 | tmpw = *((uint16_t *)data); |
| 1540 | break; |
| 1541 | case 4: |
| 1542 | tmpw = *((uint32_t *)data); |
| 1543 | break; |
| 1544 | case 8: |
| 1545 | default: |
| 1546 | tmpw = *((uint64_t *)data); |
| 1547 | break; |
| 1548 | } |
| 1549 | word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8)); |
| 1550 | word[0] |= tmpw << (off0 * 8); |
| 1551 | |
| 1552 | if (loop == 2) { |
| 1553 | word[1] &= ~(~0ULL << (sz[1] * 8)); |
| 1554 | word[1] |= tmpw >> (sz[0] * 8); |
| 1555 | } |
| 1556 | |
| 1557 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1558 | netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
| 1559 | |
| 1560 | for (i = 0; i < loop; i++) { |
| 1561 | writel((uint32_t)(off8 + (i << 3)), |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1562 | (mem_crb+MIU_TEST_AGT_ADDR_LO)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1563 | writel(0, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1564 | (mem_crb+MIU_TEST_AGT_ADDR_HI)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1565 | writel(word[i] & 0xffffffff, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1566 | (mem_crb+MIU_TEST_AGT_WRDATA_LO)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1567 | writel((word[i] >> 32) & 0xffffffff, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1568 | (mem_crb+MIU_TEST_AGT_WRDATA_HI)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1569 | writel(MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1570 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1571 | writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE|MIU_TA_CTL_WRITE, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1572 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1573 | |
| 1574 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1575 | temp = readl( |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1576 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1577 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1578 | break; |
| 1579 | } |
| 1580 | |
| 1581 | if (j >= MAX_CTL_CHECK) { |
Dhananjay Phadke | 39754f4 | 2009-02-17 20:27:02 -0800 | [diff] [blame^] | 1582 | if (printk_ratelimit()) |
| 1583 | dev_err(&adapter->pdev->dev, |
| 1584 | "failed to write through agent\n"); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1585 | ret = -1; |
| 1586 | break; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
| 1591 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1592 | return ret; |
| 1593 | } |
| 1594 | |
| 1595 | int |
| 1596 | netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, |
| 1597 | u64 off, void *data, int size) |
| 1598 | { |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1599 | unsigned long flags; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1600 | int i, j = 0, k, start, end, loop, sz[2], off0[2]; |
| 1601 | uint32_t temp; |
| 1602 | uint64_t off8, val, word[2] = {0, 0}; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1603 | void __iomem *mem_crb; |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1604 | |
| 1605 | |
| 1606 | /* |
| 1607 | * If not MN, go check for MS or invalid. |
| 1608 | */ |
| 1609 | if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0) |
| 1610 | return netxen_nic_pci_mem_read_direct(adapter, off, data, size); |
| 1611 | |
| 1612 | off8 = off & 0xfffffff8; |
| 1613 | off0[0] = off & 0x7; |
| 1614 | off0[1] = 0; |
| 1615 | sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]); |
| 1616 | sz[1] = size - sz[0]; |
| 1617 | loop = ((off0[0] + size - 1) >> 3) + 1; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1618 | mem_crb = pci_base_offset(adapter, NETXEN_CRB_DDR_NET); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1619 | |
| 1620 | write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1621 | netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
| 1622 | |
| 1623 | for (i = 0; i < loop; i++) { |
| 1624 | writel((uint32_t)(off8 + (i << 3)), |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1625 | (mem_crb+MIU_TEST_AGT_ADDR_LO)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1626 | writel(0, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1627 | (mem_crb+MIU_TEST_AGT_ADDR_HI)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1628 | writel(MIU_TA_CTL_ENABLE, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1629 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1630 | writel(MIU_TA_CTL_START|MIU_TA_CTL_ENABLE, |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1631 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1632 | |
| 1633 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1634 | temp = readl( |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1635 | (mem_crb+MIU_TEST_AGT_CTRL)); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1636 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1637 | break; |
| 1638 | } |
| 1639 | |
| 1640 | if (j >= MAX_CTL_CHECK) { |
Dhananjay Phadke | 39754f4 | 2009-02-17 20:27:02 -0800 | [diff] [blame^] | 1641 | if (printk_ratelimit()) |
| 1642 | dev_err(&adapter->pdev->dev, |
| 1643 | "failed to read through agent\n"); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1644 | break; |
| 1645 | } |
| 1646 | |
| 1647 | start = off0[i] >> 2; |
| 1648 | end = (off0[i] + sz[i] - 1) >> 2; |
| 1649 | for (k = start; k <= end; k++) { |
| 1650 | word[i] |= ((uint64_t) readl( |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1651 | (mem_crb + |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1652 | MIU_TEST_AGT_RDDATA(k))) << (32*k)); |
| 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
| 1657 | write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1658 | |
| 1659 | if (j >= MAX_CTL_CHECK) |
| 1660 | return -1; |
| 1661 | |
| 1662 | if (sz[0] == 8) { |
| 1663 | val = word[0]; |
| 1664 | } else { |
| 1665 | val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) | |
| 1666 | ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8)); |
| 1667 | } |
| 1668 | |
| 1669 | switch (size) { |
| 1670 | case 1: |
| 1671 | *(uint8_t *)data = val; |
| 1672 | break; |
| 1673 | case 2: |
| 1674 | *(uint16_t *)data = val; |
| 1675 | break; |
| 1676 | case 4: |
| 1677 | *(uint32_t *)data = val; |
| 1678 | break; |
| 1679 | case 8: |
| 1680 | *(uint64_t *)data = val; |
| 1681 | break; |
| 1682 | } |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
| 1686 | int |
| 1687 | netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter, |
| 1688 | u64 off, void *data, int size) |
| 1689 | { |
| 1690 | int i, j, ret = 0, loop, sz[2], off0; |
| 1691 | uint32_t temp; |
| 1692 | uint64_t off8, mem_crb, tmpw, word[2] = {0, 0}; |
| 1693 | |
| 1694 | /* |
| 1695 | * If not MN, go check for MS or invalid. |
| 1696 | */ |
| 1697 | if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3) |
| 1698 | mem_crb = NETXEN_CRB_QDR_NET; |
| 1699 | else { |
| 1700 | mem_crb = NETXEN_CRB_DDR_NET; |
| 1701 | if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0) |
| 1702 | return netxen_nic_pci_mem_write_direct(adapter, |
| 1703 | off, data, size); |
| 1704 | } |
| 1705 | |
| 1706 | off8 = off & 0xfffffff8; |
| 1707 | off0 = off & 0x7; |
| 1708 | sz[0] = (size < (8 - off0)) ? size : (8 - off0); |
| 1709 | sz[1] = size - sz[0]; |
| 1710 | loop = ((off0 + size - 1) >> 3) + 1; |
| 1711 | |
| 1712 | if ((size != 8) || (off0 != 0)) { |
| 1713 | for (i = 0; i < loop; i++) { |
| 1714 | if (adapter->pci_mem_read(adapter, off8 + (i << 3), |
| 1715 | &word[i], 8)) |
| 1716 | return -1; |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | switch (size) { |
| 1721 | case 1: |
| 1722 | tmpw = *((uint8_t *)data); |
| 1723 | break; |
| 1724 | case 2: |
| 1725 | tmpw = *((uint16_t *)data); |
| 1726 | break; |
| 1727 | case 4: |
| 1728 | tmpw = *((uint32_t *)data); |
| 1729 | break; |
| 1730 | case 8: |
| 1731 | default: |
| 1732 | tmpw = *((uint64_t *)data); |
| 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | word[0] &= ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8)); |
| 1737 | word[0] |= tmpw << (off0 * 8); |
| 1738 | |
| 1739 | if (loop == 2) { |
| 1740 | word[1] &= ~(~0ULL << (sz[1] * 8)); |
| 1741 | word[1] |= tmpw >> (sz[0] * 8); |
| 1742 | } |
| 1743 | |
| 1744 | /* |
| 1745 | * don't lock here - write_wx gets the lock if each time |
| 1746 | * write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1747 | * netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
| 1748 | */ |
| 1749 | |
| 1750 | for (i = 0; i < loop; i++) { |
| 1751 | temp = off8 + (i << 3); |
| 1752 | adapter->hw_write_wx(adapter, |
| 1753 | mem_crb+MIU_TEST_AGT_ADDR_LO, &temp, 4); |
| 1754 | temp = 0; |
| 1755 | adapter->hw_write_wx(adapter, |
| 1756 | mem_crb+MIU_TEST_AGT_ADDR_HI, &temp, 4); |
| 1757 | temp = word[i] & 0xffffffff; |
| 1758 | adapter->hw_write_wx(adapter, |
| 1759 | mem_crb+MIU_TEST_AGT_WRDATA_LO, &temp, 4); |
| 1760 | temp = (word[i] >> 32) & 0xffffffff; |
| 1761 | adapter->hw_write_wx(adapter, |
| 1762 | mem_crb+MIU_TEST_AGT_WRDATA_HI, &temp, 4); |
| 1763 | temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE; |
| 1764 | adapter->hw_write_wx(adapter, |
| 1765 | mem_crb+MIU_TEST_AGT_CTRL, &temp, 4); |
| 1766 | temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE; |
| 1767 | adapter->hw_write_wx(adapter, |
| 1768 | mem_crb+MIU_TEST_AGT_CTRL, &temp, 4); |
| 1769 | |
| 1770 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1771 | adapter->hw_read_wx(adapter, |
| 1772 | mem_crb + MIU_TEST_AGT_CTRL, &temp, 4); |
| 1773 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1774 | break; |
| 1775 | } |
| 1776 | |
| 1777 | if (j >= MAX_CTL_CHECK) { |
Dhananjay Phadke | 39754f4 | 2009-02-17 20:27:02 -0800 | [diff] [blame^] | 1778 | if (printk_ratelimit()) |
| 1779 | dev_err(&adapter->pdev->dev, |
| 1780 | "failed to write through agent\n"); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1781 | ret = -1; |
| 1782 | break; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | /* |
| 1787 | * netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
| 1788 | * write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1789 | */ |
| 1790 | return ret; |
| 1791 | } |
| 1792 | |
| 1793 | int |
| 1794 | netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, |
| 1795 | u64 off, void *data, int size) |
| 1796 | { |
| 1797 | int i, j = 0, k, start, end, loop, sz[2], off0[2]; |
| 1798 | uint32_t temp; |
| 1799 | uint64_t off8, val, mem_crb, word[2] = {0, 0}; |
| 1800 | |
| 1801 | /* |
| 1802 | * If not MN, go check for MS or invalid. |
| 1803 | */ |
| 1804 | |
| 1805 | if (off >= NETXEN_ADDR_QDR_NET && off <= NETXEN_ADDR_QDR_NET_MAX_P3) |
| 1806 | mem_crb = NETXEN_CRB_QDR_NET; |
| 1807 | else { |
| 1808 | mem_crb = NETXEN_CRB_DDR_NET; |
| 1809 | if (netxen_nic_pci_mem_bound_check(adapter, off, size) == 0) |
| 1810 | return netxen_nic_pci_mem_read_direct(adapter, |
| 1811 | off, data, size); |
| 1812 | } |
| 1813 | |
| 1814 | off8 = off & 0xfffffff8; |
| 1815 | off0[0] = off & 0x7; |
| 1816 | off0[1] = 0; |
| 1817 | sz[0] = (size < (8 - off0[0])) ? size : (8 - off0[0]); |
| 1818 | sz[1] = size - sz[0]; |
| 1819 | loop = ((off0[0] + size - 1) >> 3) + 1; |
| 1820 | |
| 1821 | /* |
| 1822 | * don't lock here - write_wx gets the lock if each time |
| 1823 | * write_lock_irqsave(&adapter->adapter_lock, flags); |
| 1824 | * netxen_nic_pci_change_crbwindow_128M(adapter, 0); |
| 1825 | */ |
| 1826 | |
| 1827 | for (i = 0; i < loop; i++) { |
| 1828 | temp = off8 + (i << 3); |
| 1829 | adapter->hw_write_wx(adapter, |
| 1830 | mem_crb + MIU_TEST_AGT_ADDR_LO, &temp, 4); |
| 1831 | temp = 0; |
| 1832 | adapter->hw_write_wx(adapter, |
| 1833 | mem_crb + MIU_TEST_AGT_ADDR_HI, &temp, 4); |
| 1834 | temp = MIU_TA_CTL_ENABLE; |
| 1835 | adapter->hw_write_wx(adapter, |
| 1836 | mem_crb + MIU_TEST_AGT_CTRL, &temp, 4); |
| 1837 | temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE; |
| 1838 | adapter->hw_write_wx(adapter, |
| 1839 | mem_crb + MIU_TEST_AGT_CTRL, &temp, 4); |
| 1840 | |
| 1841 | for (j = 0; j < MAX_CTL_CHECK; j++) { |
| 1842 | adapter->hw_read_wx(adapter, |
| 1843 | mem_crb + MIU_TEST_AGT_CTRL, &temp, 4); |
| 1844 | if ((temp & MIU_TA_CTL_BUSY) == 0) |
| 1845 | break; |
| 1846 | } |
| 1847 | |
| 1848 | if (j >= MAX_CTL_CHECK) { |
Dhananjay Phadke | 39754f4 | 2009-02-17 20:27:02 -0800 | [diff] [blame^] | 1849 | if (printk_ratelimit()) |
| 1850 | dev_err(&adapter->pdev->dev, |
| 1851 | "failed to read through agent\n"); |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1852 | break; |
| 1853 | } |
| 1854 | |
| 1855 | start = off0[i] >> 2; |
| 1856 | end = (off0[i] + sz[i] - 1) >> 2; |
| 1857 | for (k = start; k <= end; k++) { |
| 1858 | adapter->hw_read_wx(adapter, |
| 1859 | mem_crb + MIU_TEST_AGT_RDDATA(k), &temp, 4); |
| 1860 | word[i] |= ((uint64_t)temp << (32 * k)); |
| 1861 | } |
| 1862 | } |
| 1863 | |
| 1864 | /* |
| 1865 | * netxen_nic_pci_change_crbwindow_128M(adapter, 1); |
| 1866 | * write_unlock_irqrestore(&adapter->adapter_lock, flags); |
| 1867 | */ |
| 1868 | |
| 1869 | if (j >= MAX_CTL_CHECK) |
| 1870 | return -1; |
| 1871 | |
| 1872 | if (sz[0] == 8) { |
| 1873 | val = word[0]; |
| 1874 | } else { |
| 1875 | val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) | |
| 1876 | ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8)); |
| 1877 | } |
| 1878 | |
| 1879 | switch (size) { |
| 1880 | case 1: |
| 1881 | *(uint8_t *)data = val; |
| 1882 | break; |
| 1883 | case 2: |
| 1884 | *(uint16_t *)data = val; |
| 1885 | break; |
| 1886 | case 4: |
| 1887 | *(uint32_t *)data = val; |
| 1888 | break; |
| 1889 | case 8: |
| 1890 | *(uint64_t *)data = val; |
| 1891 | break; |
| 1892 | } |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 1893 | return 0; |
| 1894 | } |
| 1895 | |
| 1896 | /* |
| 1897 | * Note : only 32-bit writes! |
| 1898 | */ |
| 1899 | int netxen_nic_pci_write_immediate_2M(struct netxen_adapter *adapter, |
| 1900 | u64 off, u32 data) |
| 1901 | { |
| 1902 | adapter->hw_write_wx(adapter, off, &data, 4); |
| 1903 | |
| 1904 | return 0; |
| 1905 | } |
| 1906 | |
| 1907 | u32 netxen_nic_pci_read_immediate_2M(struct netxen_adapter *adapter, u64 off) |
| 1908 | { |
| 1909 | u32 temp; |
| 1910 | adapter->hw_read_wx(adapter, off, &temp, 4); |
| 1911 | return temp; |
| 1912 | } |
| 1913 | |
| 1914 | void netxen_nic_pci_write_normalize_2M(struct netxen_adapter *adapter, |
| 1915 | u64 off, u32 data) |
| 1916 | { |
| 1917 | adapter->hw_write_wx(adapter, off, &data, 4); |
| 1918 | } |
| 1919 | |
| 1920 | u32 netxen_nic_pci_read_normalize_2M(struct netxen_adapter *adapter, u64 off) |
| 1921 | { |
| 1922 | u32 temp; |
| 1923 | adapter->hw_read_wx(adapter, off, &temp, 4); |
| 1924 | return temp; |
| 1925 | } |
| 1926 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 1927 | #if 0 |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1928 | int |
| 1929 | netxen_nic_erase_pxe(struct netxen_adapter *adapter) |
| 1930 | { |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 1931 | if (netxen_rom_fast_write(adapter, NETXEN_PXE_START, 0) == -1) { |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 1932 | printk(KERN_ERR "%s: erase pxe failed\n", |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1933 | netxen_nic_driver_name); |
| 1934 | return -1; |
| 1935 | } |
| 1936 | return 0; |
| 1937 | } |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 1938 | #endif /* 0 */ |
Mithlesh Thukral | 13ba9c7 | 2007-04-20 07:53:05 -0700 | [diff] [blame] | 1939 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1940 | int netxen_nic_get_board_info(struct netxen_adapter *adapter) |
| 1941 | { |
| 1942 | int rv = 0; |
Mithlesh Thukral | 0d04761 | 2007-06-07 04:36:36 -0700 | [diff] [blame] | 1943 | int addr = NETXEN_BRDCFG_START; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1944 | struct netxen_board_info *boardinfo; |
| 1945 | int index; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1946 | int *ptr32; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1947 | |
| 1948 | boardinfo = &adapter->ahw.boardcfg; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 1949 | ptr32 = (int *) boardinfo; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1950 | |
| 1951 | for (index = 0; index < sizeof(struct netxen_board_info) / sizeof(u32); |
| 1952 | index++) { |
| 1953 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { |
| 1954 | return -EIO; |
| 1955 | } |
| 1956 | ptr32++; |
| 1957 | addr += sizeof(u32); |
| 1958 | } |
| 1959 | if (boardinfo->magic != NETXEN_BDINFO_MAGIC) { |
| 1960 | printk("%s: ERROR reading %s board config." |
| 1961 | " Read %x, expected %x\n", netxen_nic_driver_name, |
| 1962 | netxen_nic_driver_name, |
| 1963 | boardinfo->magic, NETXEN_BDINFO_MAGIC); |
| 1964 | rv = -1; |
| 1965 | } |
| 1966 | if (boardinfo->header_version != NETXEN_BDINFO_VERSION) { |
| 1967 | printk("%s: Unknown board config version." |
| 1968 | " Read %x, expected %x\n", netxen_nic_driver_name, |
| 1969 | boardinfo->header_version, NETXEN_BDINFO_VERSION); |
| 1970 | rv = -1; |
| 1971 | } |
| 1972 | |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 1973 | if (boardinfo->board_type == NETXEN_BRDTYPE_P3_4_GB_MM) { |
| 1974 | u32 gpio = netxen_nic_reg_read(adapter, |
| 1975 | NETXEN_ROMUSB_GLB_PAD_GPIO_I); |
| 1976 | if ((gpio & 0x8000) == 0) |
| 1977 | boardinfo->board_type = NETXEN_BRDTYPE_P3_10G_TP; |
| 1978 | } |
| 1979 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1980 | switch ((netxen_brdtype_t) boardinfo->board_type) { |
| 1981 | case NETXEN_BRDTYPE_P2_SB35_4G: |
| 1982 | adapter->ahw.board_type = NETXEN_NIC_GBE; |
| 1983 | break; |
| 1984 | case NETXEN_BRDTYPE_P2_SB31_10G: |
| 1985 | case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: |
| 1986 | case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: |
| 1987 | case NETXEN_BRDTYPE_P2_SB31_10G_CX4: |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1988 | case NETXEN_BRDTYPE_P3_HMEZ: |
| 1989 | case NETXEN_BRDTYPE_P3_XG_LOM: |
| 1990 | case NETXEN_BRDTYPE_P3_10G_CX4: |
| 1991 | case NETXEN_BRDTYPE_P3_10G_CX4_LP: |
| 1992 | case NETXEN_BRDTYPE_P3_IMEZ: |
| 1993 | case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: |
Dhananjay Phadke | a70f939 | 2008-08-01 03:14:56 -0700 | [diff] [blame] | 1994 | case NETXEN_BRDTYPE_P3_10G_SFP_CT: |
| 1995 | case NETXEN_BRDTYPE_P3_10G_SFP_QT: |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 1996 | case NETXEN_BRDTYPE_P3_10G_XFP: |
| 1997 | case NETXEN_BRDTYPE_P3_10000_BASE_T: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1998 | adapter->ahw.board_type = NETXEN_NIC_XGBE; |
| 1999 | break; |
| 2000 | case NETXEN_BRDTYPE_P1_BD: |
| 2001 | case NETXEN_BRDTYPE_P1_SB: |
| 2002 | case NETXEN_BRDTYPE_P1_SMAX: |
| 2003 | case NETXEN_BRDTYPE_P1_SOCK: |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 2004 | case NETXEN_BRDTYPE_P3_REF_QG: |
| 2005 | case NETXEN_BRDTYPE_P3_4_GB: |
| 2006 | case NETXEN_BRDTYPE_P3_4_GB_MM: |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2007 | adapter->ahw.board_type = NETXEN_NIC_GBE; |
| 2008 | break; |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 2009 | case NETXEN_BRDTYPE_P3_10G_TP: |
| 2010 | adapter->ahw.board_type = (adapter->portnum < 2) ? |
| 2011 | NETXEN_NIC_XGBE : NETXEN_NIC_GBE; |
| 2012 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2013 | default: |
| 2014 | printk("%s: Unknown(%x)\n", netxen_nic_driver_name, |
| 2015 | boardinfo->board_type); |
Dhananjay Phadke | a70f939 | 2008-08-01 03:14:56 -0700 | [diff] [blame] | 2016 | rv = -ENODEV; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | |
| 2020 | return rv; |
| 2021 | } |
| 2022 | |
| 2023 | /* NIU access sections */ |
| 2024 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2025 | int netxen_nic_set_mtu_gb(struct netxen_adapter *adapter, int new_mtu) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2026 | { |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 2027 | new_mtu += MTU_FUDGE_FACTOR; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2028 | netxen_nic_write_w0(adapter, |
Dhananjay Phadke | 3276fba | 2008-06-15 22:59:44 -0700 | [diff] [blame] | 2029 | NETXEN_NIU_GB_MAX_FRAME_SIZE(adapter->physical_port), |
| 2030 | new_mtu); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2031 | return 0; |
| 2032 | } |
| 2033 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2034 | int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2035 | { |
Dhananjay Phadke | 9ad2764 | 2008-08-01 03:14:59 -0700 | [diff] [blame] | 2036 | new_mtu += MTU_FUDGE_FACTOR; |
Dhananjay Phadke | 3276fba | 2008-06-15 22:59:44 -0700 | [diff] [blame] | 2037 | if (adapter->physical_port == 0) |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 2038 | netxen_nic_write_w0(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 2039 | new_mtu); |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 2040 | else |
Mithlesh Thukral | 595e3fb | 2007-04-20 07:53:52 -0700 | [diff] [blame] | 2041 | netxen_nic_write_w0(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, |
| 2042 | new_mtu); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2043 | return 0; |
| 2044 | } |
| 2045 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2046 | void |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 2047 | netxen_crb_writelit_adapter(struct netxen_adapter *adapter, |
| 2048 | unsigned long off, int data) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2049 | { |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 2050 | adapter->hw_write_wx(adapter, off, &data, 4); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2053 | void netxen_nic_set_link_parameters(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2054 | { |
Al Viro | a608ab9c | 2007-01-02 10:39:10 +0000 | [diff] [blame] | 2055 | __u32 status; |
| 2056 | __u32 autoneg; |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 2057 | __u32 port_mode; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2058 | |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 2059 | if (!netif_carrier_ok(adapter->netdev)) { |
| 2060 | adapter->link_speed = 0; |
| 2061 | adapter->link_duplex = -1; |
| 2062 | adapter->link_autoneg = AUTONEG_ENABLE; |
| 2063 | return; |
| 2064 | } |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 2065 | |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 2066 | if (adapter->ahw.board_type == NETXEN_NIC_GBE) { |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 2067 | adapter->hw_read_wx(adapter, |
| 2068 | NETXEN_PORT_MODE_ADDR, &port_mode, 4); |
| 2069 | if (port_mode == NETXEN_PORT_MODE_802_3_AP) { |
| 2070 | adapter->link_speed = SPEED_1000; |
| 2071 | adapter->link_duplex = DUPLEX_FULL; |
| 2072 | adapter->link_autoneg = AUTONEG_DISABLE; |
| 2073 | return; |
| 2074 | } |
| 2075 | |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 2076 | if (adapter->phy_read |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 2077 | && adapter->phy_read(adapter, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2078 | NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, |
| 2079 | &status) == 0) { |
| 2080 | if (netxen_get_phy_link(status)) { |
| 2081 | switch (netxen_get_phy_speed(status)) { |
| 2082 | case 0: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2083 | adapter->link_speed = SPEED_10; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2084 | break; |
| 2085 | case 1: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2086 | adapter->link_speed = SPEED_100; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2087 | break; |
| 2088 | case 2: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2089 | adapter->link_speed = SPEED_1000; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2090 | break; |
| 2091 | default: |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 2092 | adapter->link_speed = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2093 | break; |
| 2094 | } |
| 2095 | switch (netxen_get_phy_duplex(status)) { |
| 2096 | case 0: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2097 | adapter->link_duplex = DUPLEX_HALF; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2098 | break; |
| 2099 | case 1: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2100 | adapter->link_duplex = DUPLEX_FULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2101 | break; |
| 2102 | default: |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2103 | adapter->link_duplex = -1; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2104 | break; |
| 2105 | } |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 2106 | if (adapter->phy_read |
Dhananjay Phadke | 24a7a45 | 2008-08-01 03:14:55 -0700 | [diff] [blame] | 2107 | && adapter->phy_read(adapter, |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2108 | NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 2109 | &autoneg) != 0) |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2110 | adapter->link_autoneg = autoneg; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2111 | } else |
| 2112 | goto link_down; |
| 2113 | } else { |
| 2114 | link_down: |
Dhananjay Phadke | c7860a2 | 2009-01-14 20:48:32 -0800 | [diff] [blame] | 2115 | adapter->link_speed = 0; |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 2116 | adapter->link_duplex = -1; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | void netxen_nic_flash_print(struct netxen_adapter *adapter) |
| 2122 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2123 | u32 fw_major = 0; |
| 2124 | u32 fw_minor = 0; |
| 2125 | u32 fw_build = 0; |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 2126 | char brd_name[NETXEN_MAX_SHORT_NAME]; |
Harvey Harrison | 8d74849 | 2008-04-22 11:48:35 -0700 | [diff] [blame] | 2127 | char serial_num[32]; |
| 2128 | int i, addr; |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 2129 | int *ptr32; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2130 | |
| 2131 | struct netxen_board_info *board_info = &(adapter->ahw.boardcfg); |
Harvey Harrison | 8d74849 | 2008-04-22 11:48:35 -0700 | [diff] [blame] | 2132 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2133 | adapter->driver_mismatch = 0; |
| 2134 | |
Dhananjay Phadke | d8313ce | 2009-02-17 20:26:44 -0800 | [diff] [blame] | 2135 | ptr32 = (int *)&serial_num; |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2136 | addr = NETXEN_USER_START + |
| 2137 | offsetof(struct netxen_new_user_info, serial_num); |
| 2138 | for (i = 0; i < 8; i++) { |
| 2139 | if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) { |
| 2140 | printk("%s: ERROR reading %s board userarea.\n", |
| 2141 | netxen_nic_driver_name, |
| 2142 | netxen_nic_driver_name); |
| 2143 | adapter->driver_mismatch = 1; |
| 2144 | return; |
| 2145 | } |
| 2146 | ptr32++; |
| 2147 | addr += sizeof(u32); |
| 2148 | } |
| 2149 | |
Dhananjay Phadke | 3ce06a3 | 2008-07-21 19:44:03 -0700 | [diff] [blame] | 2150 | adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MAJOR, &fw_major, 4); |
| 2151 | adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_MINOR, &fw_minor, 4); |
| 2152 | adapter->hw_read_wx(adapter, NETXEN_FW_VERSION_SUB, &fw_build, 4); |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2153 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 2154 | adapter->fw_major = fw_major; |
| 2155 | |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2156 | if (adapter->portnum == 0) { |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 2157 | get_brd_name_by_type(board_info->board_type, brd_name); |
| 2158 | |
Dhananjay Phadke | 11d89d6 | 2008-08-08 00:08:45 -0700 | [diff] [blame] | 2159 | printk(KERN_INFO "NetXen %s Board S/N %s Chip rev 0x%x\n", |
| 2160 | brd_name, serial_num, adapter->ahw.revision_id); |
| 2161 | printk(KERN_INFO "NetXen Firmware version %d.%d.%d\n", |
| 2162 | fw_major, fw_minor, fw_build); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2163 | } |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2164 | |
Dhananjay Phadke | 5873556 | 2008-07-21 19:44:10 -0700 | [diff] [blame] | 2165 | if (NETXEN_VERSION_CODE(fw_major, fw_minor, fw_build) < |
| 2166 | NETXEN_VERSION_CODE(3, 4, 216)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2167 | adapter->driver_mismatch = 1; |
Dhananjay Phadke | 5873556 | 2008-07-21 19:44:10 -0700 | [diff] [blame] | 2168 | printk(KERN_ERR "%s: firmware version %d.%d.%d unsupported\n", |
| 2169 | netxen_nic_driver_name, |
| 2170 | fw_major, fw_minor, fw_build); |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 2171 | return; |
| 2172 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 2173 | } |
| 2174 | |