13 #include <linux/kernel.h>
14 #include <linux/mii.h>
17 #include <linux/pci.h>
24 #define mdio_delay() ioread32(mdio_addr)
29 #define MDIO_SHIFT_CLK 0x10000
30 #define MDIO_DATA_WRITE0 0x00000
31 #define MDIO_DATA_WRITE1 0x20000
32 #define MDIO_ENB 0x00000
33 #define MDIO_ENB_IN 0x40000
34 #define MDIO_DATA_READ 0x80000
36 static const unsigned char comet_miireg2offset[32] = {
37 0xB4, 0xB8, 0xBC, 0xC0, 0xC4, 0xC8, 0xCC, 0, 0,0,0,0, 0,0,0,0,
38 0,0xD0,0,0, 0,0,0,0, 0,0,0,0, 0, 0xD4, 0xD8, 0xDC, };
52 int read_cmd = (0xf6 << 10) | ((phy_id & 0x1f) << 5) | location;
62 if (comet_miireg2offset[location])
63 return ioread32(ioaddr + comet_miireg2offset[location]);
69 iowrite32(0x60020000 + (phy_id<<23) + (location<<18), ioaddr + 0xA0);
72 for (i = 1000; i >= 0; --
i) {
74 if ( ! ((retval =
ioread32(ioaddr + 0xA0)) & 0x80000000))
77 spin_unlock_irqrestore(&tp->
mii_lock, flags);
78 return retval & 0xffff;
82 for (i = 32; i >= 0; i--) {
89 for (i = 15; i >= 0; i--) {
98 for (i = 19; i > 0; i--) {
106 spin_unlock_irqrestore(&tp->
mii_lock, flags);
107 return (retval>>1) & 0xffff;
114 int cmd = (0x5002 << 16) | ((phy_id & 0x1f) << 23) | (location<<18) | (val & 0xffff);
119 if (location & ~0x1f)
123 if (comet_miireg2offset[location])
124 iowrite32(val, ioaddr + comet_miireg2offset[location]);
131 for (i = 1000; i >= 0; --
i) {
133 if ( ! (
ioread32(ioaddr + 0xA0) & 0x80000000))
136 spin_unlock_irqrestore(&tp->
mii_lock, flags);
141 for (i = 32; i >= 0; i--) {
148 for (i = 31; i >= 0; i--) {
156 for (i = 2; i > 0; i--) {
163 spin_unlock_irqrestore(&tp->
mii_lock, flags);
179 switch (mleaf->
type) {
182 netdev_dbg(dev,
"Using a 21140 non-MII transceiver with control setting %02x\n",
188 new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);
192 u32 csr13val, csr14val, csr15dir, csr15val;
193 for (i = 0; i < 5; i++)
194 setup[i] =
get_u16(&p[i*2 + 1]);
202 unsigned char *rst = rleaf->
leafdata;
204 netdev_dbg(dev,
"Resetting the transceiver\n");
205 for (i = 0; i < rst[0]; i++)
209 netdev_dbg(dev,
"21143 non-MII %s transceiver control %04x/%04x\n",
215 csr15dir = (setup[3]<<16) | setup[2];
216 csr15val = (setup[4]<<16) | setup[2];
225 csr15dir = (setup[0]<<16) | 0x0008;
226 csr15val = (setup[1]<<16) | 0x0008;
238 netdev_dbg(dev,
"Setting CSR15 to %08x/%08x\n",
240 if (mleaf->
type == 4)
241 new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);
243 new_csr6 = 0x82420000;
248 int init_length = p[1];
249 u16 *misc_info, tmp_info;
252 new_csr6 = 0x020E0000;
253 if (mleaf->
type == 3) {
254 u16 *init_sequence = (
u16*)(p+2);
255 u16 *reset_sequence = &((
u16*)(p+3))[init_length];
256 int reset_length = p[2 + init_length*2];
257 misc_info = reset_sequence + reset_length;
260 for (i = 0; i < reset_length; i++)
275 for (i = 0; i < init_length; i++)
280 u8 *init_sequence = p + 2;
281 u8 *reset_sequence = p + 3 + init_length;
282 int reset_length = p[2 + init_length];
283 misc_info = (
u16*)(reset_sequence + reset_length);
287 for (i = 0; i < reset_length; i++)
302 for (i = 0; i < init_length; i++)
308 tmp_info =
get_u16(&misc_info[1]);
311 if (tmp_info && startup < 2) {
315 netdev_dbg(dev,
" Advertising %04x on MII %d\n",
327 for (i = 0; i < 5; i++)
328 setup[i] =
get_u16(&p[i*2 + 1]);
332 unsigned char *rst = rleaf->
leafdata;
334 netdev_dbg(dev,
"Resetting the transceiver\n");
335 for (i = 0; i < rst[0]; i++)
342 netdev_dbg(dev,
" Invalid media table selection %d\n",
344 new_csr6 = 0x020E0000;
347 netdev_dbg(dev,
"Using media type %s, CSR12 is %02x\n",
354 netdev_dbg(dev,
"PNIC PHY status is %3.3x, media %s\n",
358 new_csr6 = 0x810C0000;
361 }
else if (startup) {
364 new_csr6 = 0x00420000;
369 new_csr6 = 0x01860000;
371 iowrite32(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);
374 new_csr6 = 0x00420000;
381 new_csr6 = 0x020E0000;
383 new_csr6 = 0x02860000;
385 new_csr6 = 0x03860000;
387 netdev_dbg(dev,
"No media description table, assuming %s transceiver, CSR12 %02x\n",
406 unsigned int bmsr, lpa, negotiated, new_csr6;
411 dev_info(&dev->
dev,
"MII status %04x, Link partner report %04x\n",
417 if ((new_bmsr & BMSR_LSTATUS) == 0) {
420 "No link beat on the MII interface, status %04x\n",
435 if (new_csr6 != tp->
csr6) {
437 tulip_restart_rxtx(tp);
441 "Setting %s-duplex based on MII#%d link partner capability of %04x\n",
453 int phyn, phy_idx = 0;
456 unsigned int to_advert, new_bmcr, ane_switch;
461 for (phyn = 1; phyn <= 32 && phy_idx <
sizeof (tp->
phys); phyn++) {
462 int phy = phyn & 0x1f;
464 if ((mii_status & 0x8301) == 0x8001 ||
466 (mii_status & 0x7800) != 0)) {
482 mii_advert = ((tmpadv >> 6) & 0x3e0) | 1;
493 to_advert = mii_advert;
498 pr_info(
"tulip%d: MII transceiver #%d config %04x status %04x advertising %04x\n",
499 board_idx, phy, mii_reg0, mii_status, mii_advert);
502 if (mii_advert != to_advert) {
503 pr_debug(
"tulip%d: Advertising %04x on PHY %d, previously advertising %04x\n",
504 board_idx, to_advert, phy, mii_advert);
511 if (new_bmcr != mii_reg0) {
519 if (new_bmcr != mii_reg0)
533 if (new_bmcr != mii_reg0) {
548 if (tp->
mtable && tp->
mtable->has_mii && phy_idx == 0) {
549 pr_info(
"tulip%d: ***WARNING***: No MII transceiver found!\n",