0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 #include "tulip.h"
0076 #include <linux/delay.h>
0077
0078
0079 void pnic2_timer(struct timer_list *t)
0080 {
0081 struct tulip_private *tp = from_timer(tp, t, timer);
0082 struct net_device *dev = tp->dev;
0083 void __iomem *ioaddr = tp->base_addr;
0084 int next_tick = 60*HZ;
0085
0086 if (tulip_debug > 3)
0087 dev_info(&dev->dev, "PNIC2 negotiation status %08x\n",
0088 ioread32(ioaddr + CSR12));
0089
0090 if (next_tick) {
0091 mod_timer(&tp->timer, RUN_AT(next_tick));
0092 }
0093 }
0094
0095
0096 void pnic2_start_nway(struct net_device *dev)
0097 {
0098 struct tulip_private *tp = netdev_priv(dev);
0099 void __iomem *ioaddr = tp->base_addr;
0100 int csr14;
0101 int csr12;
0102
0103
0104
0105
0106
0107
0108 csr14 = (ioread32(ioaddr + CSR14) & 0xfff0ee39);
0109
0110
0111 if (tp->sym_advertise & 0x0100) csr14 |= 0x00020000;
0112
0113
0114 if (tp->sym_advertise & 0x0080) csr14 |= 0x00010000;
0115
0116
0117 if (tp->sym_advertise & 0x0020) csr14 |= 0x00000040;
0118
0119
0120
0121
0122 csr14 |= 0x00001184;
0123
0124 if (tulip_debug > 1)
0125 netdev_dbg(dev, "Restarting PNIC2 autonegotiation, csr14=%08x\n",
0126 csr14);
0127
0128
0129 dev->if_port = 0;
0130 tp->nway = tp->mediasense = 1;
0131 tp->nwayset = tp->lpar = 0;
0132
0133
0134
0135 tp->csr6 = ioread32(ioaddr + CSR6);
0136 if (tulip_debug > 1)
0137 netdev_dbg(dev, "On Entry to Nway, csr6=%08x\n", tp->csr6);
0138
0139
0140
0141
0142 tp->csr6 = tp->csr6 & 0xfe3bd1fd;
0143
0144
0145
0146 if (tp->sym_advertise & 0x0040) tp->csr6 |= 0x00000200;
0147
0148
0149
0150
0151
0152 tp->csr6 |= 0x01000000;
0153 iowrite32(csr14, ioaddr + CSR14);
0154 iowrite32(tp->csr6, ioaddr + CSR6);
0155 udelay(100);
0156
0157
0158
0159
0160
0161
0162
0163 csr12 = (ioread32(ioaddr + CSR12) & 0xffff8fff);
0164 csr12 |= 0x1000;
0165 iowrite32(csr12, ioaddr + CSR12);
0166 }
0167
0168
0169
0170 void pnic2_lnk_change(struct net_device *dev, int csr5)
0171 {
0172 struct tulip_private *tp = netdev_priv(dev);
0173 void __iomem *ioaddr = tp->base_addr;
0174 int csr14;
0175
0176
0177 int csr12 = ioread32(ioaddr + CSR12);
0178
0179 if (tulip_debug > 1)
0180 dev_info(&dev->dev,
0181 "PNIC2 link status interrupt %08x, CSR5 %x, %08x\n",
0182 csr12, csr5, ioread32(ioaddr + CSR14));
0183
0184
0185
0186
0187 if (tp->nway && !tp->nwayset) {
0188
0189
0190
0191 if ((csr12 & 0x7000) == 0x5000) {
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204 int negotiated = ((csr12 >> 16) & 0x01E0) & tp->sym_advertise;
0205 tp->lpar = (csr12 >> 16);
0206 tp->nwayset = 1;
0207
0208 if (negotiated & 0x0100) dev->if_port = 5;
0209 else if (negotiated & 0x0080) dev->if_port = 3;
0210 else if (negotiated & 0x0040) dev->if_port = 4;
0211 else if (negotiated & 0x0020) dev->if_port = 0;
0212 else {
0213 if (tulip_debug > 1)
0214 dev_info(&dev->dev,
0215 "funny autonegotiate result csr12 %08x advertising %04x\n",
0216 csr12, tp->sym_advertise);
0217 tp->nwayset = 0;
0218
0219 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
0220 dev->if_port = 3;
0221 }
0222
0223
0224 tp->full_duplex = 0;
0225 if ((dev->if_port == 4) || (dev->if_port == 5))
0226 tp->full_duplex = 1;
0227
0228 if (tulip_debug > 1) {
0229 if (tp->nwayset)
0230 dev_info(&dev->dev,
0231 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
0232 medianame[dev->if_port],
0233 tp->sym_advertise, tp->lpar,
0234 negotiated);
0235 }
0236
0237
0238
0239
0240
0241 csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
0242 iowrite32(csr14,ioaddr + CSR14);
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253 tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
0254
0255
0256
0257
0258
0259
0260
0261 if (dev->if_port & 1) tp->csr6 |= 0x01840000;
0262 else tp->csr6 |= 0x00400000;
0263
0264
0265 if (tp->full_duplex) tp->csr6 |= 0x00000200;
0266
0267 iowrite32(1, ioaddr + CSR13);
0268
0269 if (tulip_debug > 2)
0270 netdev_dbg(dev, "Setting CSR6 %08x/%x CSR12 %08x\n",
0271 tp->csr6,
0272 ioread32(ioaddr + CSR6),
0273 ioread32(ioaddr + CSR12));
0274
0275
0276
0277
0278 tulip_start_rxtx(tp);
0279
0280 return;
0281
0282 } else {
0283 dev_info(&dev->dev,
0284 "Autonegotiation failed, using %s, link beat status %04x\n",
0285 medianame[dev->if_port], csr12);
0286
0287
0288
0289
0290 csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
0291 iowrite32(csr14,ioaddr + CSR14);
0292
0293
0294
0295
0296
0297
0298
0299
0300 dev->if_port = 0;
0301 tp->nway = 0;
0302 tp->nwayset = 1;
0303
0304
0305
0306
0307 tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
0308 tp->csr6 |= 0x00400000;
0309
0310 tulip_restart_rxtx(tp);
0311
0312 return;
0313
0314 }
0315 }
0316
0317 if ((tp->nwayset && (csr5 & 0x08000000) &&
0318 (dev->if_port == 3 || dev->if_port == 5) &&
0319 (csr12 & 2) == 2) || (tp->nway && (csr5 & (TPLnkFail)))) {
0320
0321
0322
0323 if (tulip_debug > 2)
0324 netdev_dbg(dev, "Ugh! Link blew?\n");
0325
0326 del_timer_sync(&tp->timer);
0327 pnic2_start_nway(dev);
0328 tp->timer.expires = RUN_AT(3*HZ);
0329 add_timer(&tp->timer);
0330
0331 return;
0332 }
0333
0334
0335 if (dev->if_port == 3 || dev->if_port == 5) {
0336
0337
0338
0339 if (tulip_debug > 1)
0340 dev_info(&dev->dev, "PNIC2 %s link beat %s\n",
0341 medianame[dev->if_port],
0342 (csr12 & 2) ? "failed" : "good");
0343
0344
0345
0346 tp->nway = 0;
0347 tp->nwayset = 1;
0348
0349
0350 if ((csr12 & 2) && ! tp->medialock) {
0351 del_timer_sync(&tp->timer);
0352 pnic2_start_nway(dev);
0353 tp->timer.expires = RUN_AT(3*HZ);
0354 add_timer(&tp->timer);
0355 }
0356
0357 return;
0358 }
0359
0360 if (dev->if_port == 0 || dev->if_port == 4) {
0361
0362
0363
0364 if (tulip_debug > 1)
0365 dev_info(&dev->dev, "PNIC2 %s link beat %s\n",
0366 medianame[dev->if_port],
0367 (csr12 & 4) ? "failed" : "good");
0368
0369
0370 tp->nway = 0;
0371 tp->nwayset = 1;
0372
0373
0374 if ((csr12 & 4) && ! tp->medialock) {
0375 del_timer_sync(&tp->timer);
0376 pnic2_start_nway(dev);
0377 tp->timer.expires = RUN_AT(3*HZ);
0378 add_timer(&tp->timer);
0379 }
0380
0381 return;
0382 }
0383
0384
0385 if (tulip_debug > 1)
0386 dev_info(&dev->dev, "PNIC2 Link Change Default?\n");
0387
0388
0389 dev->if_port = 0;
0390
0391
0392 csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f);
0393 iowrite32(csr14,ioaddr + CSR14);
0394
0395
0396
0397
0398 tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd);
0399 tp->csr6 |= 0x00400000;
0400
0401 tulip_restart_rxtx(tp);
0402 }
0403