1aa43c215SJeff Kirsher /* 2aa43c215SJeff Kirsher * Copyright (C) 2003 - 2009 NetXen, Inc. 3aa43c215SJeff Kirsher * Copyright (C) 2009 - QLogic Corporation. 4aa43c215SJeff Kirsher * All rights reserved. 5aa43c215SJeff Kirsher * 6aa43c215SJeff Kirsher * This program is free software; you can redistribute it and/or 7aa43c215SJeff Kirsher * modify it under the terms of the GNU General Public License 8aa43c215SJeff Kirsher * as published by the Free Software Foundation; either version 2 9aa43c215SJeff Kirsher * of the License, or (at your option) any later version. 10aa43c215SJeff Kirsher * 11aa43c215SJeff Kirsher * This program is distributed in the hope that it will be useful, but 12aa43c215SJeff Kirsher * WITHOUT ANY WARRANTY; without even the implied warranty of 13aa43c215SJeff Kirsher * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14aa43c215SJeff Kirsher * GNU General Public License for more details. 15aa43c215SJeff Kirsher * 16aa43c215SJeff Kirsher * You should have received a copy of the GNU General Public License 17aa43c215SJeff Kirsher * along with this program; if not, write to the Free Software 18aa43c215SJeff Kirsher * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 19aa43c215SJeff Kirsher * MA 02111-1307, USA. 20aa43c215SJeff Kirsher * 21aa43c215SJeff Kirsher * The full GNU General Public License is included in this distribution 22aa43c215SJeff Kirsher * in the file called "COPYING". 23aa43c215SJeff Kirsher * 24aa43c215SJeff Kirsher */ 25aa43c215SJeff Kirsher 26aa43c215SJeff Kirsher #include <linux/slab.h> 27aa43c215SJeff Kirsher #include "netxen_nic.h" 28aa43c215SJeff Kirsher #include "netxen_nic_hw.h" 29aa43c215SJeff Kirsher 30aa43c215SJeff Kirsher #include <net/ip.h> 31aa43c215SJeff Kirsher 32aa43c215SJeff Kirsher #define MASK(n) ((1ULL<<(n))-1) 33aa43c215SJeff Kirsher #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff)) 34aa43c215SJeff Kirsher #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff)) 35aa43c215SJeff Kirsher #define MS_WIN(addr) (addr & 0x0ffc0000) 36aa43c215SJeff Kirsher 37aa43c215SJeff Kirsher #define GET_MEM_OFFS_2M(addr) (addr & MASK(18)) 38aa43c215SJeff Kirsher 39aa43c215SJeff Kirsher #define CRB_BLK(off) ((off >> 20) & 0x3f) 40aa43c215SJeff Kirsher #define CRB_SUBBLK(off) ((off >> 16) & 0xf) 41aa43c215SJeff Kirsher #define CRB_WINDOW_2M (0x130060) 42aa43c215SJeff Kirsher #define CRB_HI(off) ((crb_hub_agt[CRB_BLK(off)] << 20) | ((off) & 0xf0000)) 43aa43c215SJeff Kirsher #define CRB_INDIRECT_2M (0x1e0000UL) 44aa43c215SJeff Kirsher 45aa43c215SJeff Kirsher static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, 46aa43c215SJeff Kirsher void __iomem *addr, u32 data); 47aa43c215SJeff Kirsher static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, 48aa43c215SJeff Kirsher void __iomem *addr); 49aa43c215SJeff Kirsher #ifndef readq 50aa43c215SJeff Kirsher static inline u64 readq(void __iomem *addr) 51aa43c215SJeff Kirsher { 52aa43c215SJeff Kirsher return readl(addr) | (((u64) readl(addr + 4)) << 32LL); 53aa43c215SJeff Kirsher } 54aa43c215SJeff Kirsher #endif 55aa43c215SJeff Kirsher 56aa43c215SJeff Kirsher #ifndef writeq 57aa43c215SJeff Kirsher static inline void writeq(u64 val, void __iomem *addr) 58aa43c215SJeff Kirsher { 59aa43c215SJeff Kirsher writel(((u32) (val)), (addr)); 60aa43c215SJeff Kirsher writel(((u32) (val >> 32)), (addr + 4)); 61aa43c215SJeff Kirsher } 62aa43c215SJeff Kirsher #endif 63aa43c215SJeff Kirsher 64aa43c215SJeff Kirsher #define PCI_OFFSET_FIRST_RANGE(adapter, off) \ 65aa43c215SJeff Kirsher ((adapter)->ahw.pci_base0 + (off)) 66aa43c215SJeff Kirsher #define PCI_OFFSET_SECOND_RANGE(adapter, off) \ 67aa43c215SJeff Kirsher ((adapter)->ahw.pci_base1 + (off) - SECOND_PAGE_GROUP_START) 68aa43c215SJeff Kirsher #define PCI_OFFSET_THIRD_RANGE(adapter, off) \ 69aa43c215SJeff Kirsher ((adapter)->ahw.pci_base2 + (off) - THIRD_PAGE_GROUP_START) 70aa43c215SJeff Kirsher 71aa43c215SJeff Kirsher static void __iomem *pci_base_offset(struct netxen_adapter *adapter, 72aa43c215SJeff Kirsher unsigned long off) 73aa43c215SJeff Kirsher { 74aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, FIRST_PAGE_GROUP_START, FIRST_PAGE_GROUP_END)) 75aa43c215SJeff Kirsher return PCI_OFFSET_FIRST_RANGE(adapter, off); 76aa43c215SJeff Kirsher 77aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, SECOND_PAGE_GROUP_START, SECOND_PAGE_GROUP_END)) 78aa43c215SJeff Kirsher return PCI_OFFSET_SECOND_RANGE(adapter, off); 79aa43c215SJeff Kirsher 80aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, THIRD_PAGE_GROUP_START, THIRD_PAGE_GROUP_END)) 81aa43c215SJeff Kirsher return PCI_OFFSET_THIRD_RANGE(adapter, off); 82aa43c215SJeff Kirsher 83aa43c215SJeff Kirsher return NULL; 84aa43c215SJeff Kirsher } 85aa43c215SJeff Kirsher 86aa43c215SJeff Kirsher static crb_128M_2M_block_map_t 87aa43c215SJeff Kirsher crb_128M_2M_map[64] __cacheline_aligned_in_smp = { 88aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 0: PCI */ 89aa43c215SJeff Kirsher {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */ 90aa43c215SJeff Kirsher {1, 0x0110000, 0x0120000, 0x130000}, 91aa43c215SJeff Kirsher {1, 0x0120000, 0x0122000, 0x124000}, 92aa43c215SJeff Kirsher {1, 0x0130000, 0x0132000, 0x126000}, 93aa43c215SJeff Kirsher {1, 0x0140000, 0x0142000, 0x128000}, 94aa43c215SJeff Kirsher {1, 0x0150000, 0x0152000, 0x12a000}, 95aa43c215SJeff Kirsher {1, 0x0160000, 0x0170000, 0x110000}, 96aa43c215SJeff Kirsher {1, 0x0170000, 0x0172000, 0x12e000}, 97aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 98aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 99aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 100aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 101aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 102aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 103aa43c215SJeff Kirsher {1, 0x01e0000, 0x01e0800, 0x122000}, 104aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000} } }, 105aa43c215SJeff Kirsher {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */ 106aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 3: */ 107aa43c215SJeff Kirsher {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */ 108aa43c215SJeff Kirsher {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */ 109aa43c215SJeff Kirsher {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */ 110aa43c215SJeff Kirsher {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */ 111aa43c215SJeff Kirsher {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */ 112aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 113aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 114aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 115aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 116aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 117aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 118aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 119aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 120aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 121aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 122aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 123aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 124aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 125aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 126aa43c215SJeff Kirsher {1, 0x08f0000, 0x08f2000, 0x172000} } }, 127aa43c215SJeff Kirsher {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/ 128aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 129aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 130aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 131aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 132aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 133aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 134aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 135aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 136aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 137aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 138aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 139aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 140aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 141aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 142aa43c215SJeff Kirsher {1, 0x09f0000, 0x09f2000, 0x176000} } }, 143aa43c215SJeff Kirsher {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/ 144aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 145aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 146aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 147aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 148aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 149aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 150aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 151aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 152aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 153aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 154aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 155aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 156aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 157aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 158aa43c215SJeff Kirsher {1, 0x0af0000, 0x0af2000, 0x17a000} } }, 159aa43c215SJeff Kirsher {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/ 160aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 161aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 162aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 163aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 164aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 165aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 166aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 167aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 168aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 169aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 170aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 171aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 172aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 173aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 174aa43c215SJeff Kirsher {1, 0x0bf0000, 0x0bf2000, 0x17e000} } }, 175aa43c215SJeff Kirsher {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */ 176aa43c215SJeff Kirsher {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */ 177aa43c215SJeff Kirsher {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */ 178aa43c215SJeff Kirsher {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */ 179aa43c215SJeff Kirsher {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */ 180aa43c215SJeff Kirsher {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */ 181aa43c215SJeff Kirsher {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */ 182aa43c215SJeff Kirsher {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */ 183aa43c215SJeff Kirsher {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */ 184aa43c215SJeff Kirsher {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */ 185aa43c215SJeff Kirsher {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */ 186aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 23: */ 187aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 24: */ 188aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 25: */ 189aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 26: */ 190aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 27: */ 191aa43c215SJeff Kirsher {{{0, 0, 0, 0} } }, /* 28: */ 192aa43c215SJeff Kirsher {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */ 193aa43c215SJeff Kirsher {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */ 194aa43c215SJeff Kirsher {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */ 195aa43c215SJeff Kirsher {{{0} } }, /* 32: PCI */ 196aa43c215SJeff Kirsher {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */ 197aa43c215SJeff Kirsher {1, 0x2110000, 0x2120000, 0x130000}, 198aa43c215SJeff Kirsher {1, 0x2120000, 0x2122000, 0x124000}, 199aa43c215SJeff Kirsher {1, 0x2130000, 0x2132000, 0x126000}, 200aa43c215SJeff Kirsher {1, 0x2140000, 0x2142000, 0x128000}, 201aa43c215SJeff Kirsher {1, 0x2150000, 0x2152000, 0x12a000}, 202aa43c215SJeff Kirsher {1, 0x2160000, 0x2170000, 0x110000}, 203aa43c215SJeff Kirsher {1, 0x2170000, 0x2172000, 0x12e000}, 204aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 205aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 206aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 207aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 208aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 209aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 210aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000}, 211aa43c215SJeff Kirsher {0, 0x0000000, 0x0000000, 0x000000} } }, 212aa43c215SJeff Kirsher {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */ 213aa43c215SJeff Kirsher {{{0} } }, /* 35: */ 214aa43c215SJeff Kirsher {{{0} } }, /* 36: */ 215aa43c215SJeff Kirsher {{{0} } }, /* 37: */ 216aa43c215SJeff Kirsher {{{0} } }, /* 38: */ 217aa43c215SJeff Kirsher {{{0} } }, /* 39: */ 218aa43c215SJeff Kirsher {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */ 219aa43c215SJeff Kirsher {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */ 220aa43c215SJeff Kirsher {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */ 221aa43c215SJeff Kirsher {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */ 222aa43c215SJeff Kirsher {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */ 223aa43c215SJeff Kirsher {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */ 224aa43c215SJeff Kirsher {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */ 225aa43c215SJeff Kirsher {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */ 226aa43c215SJeff Kirsher {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */ 227aa43c215SJeff Kirsher {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */ 228aa43c215SJeff Kirsher {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */ 229aa43c215SJeff Kirsher {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */ 230aa43c215SJeff Kirsher {{{0} } }, /* 52: */ 231aa43c215SJeff Kirsher {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */ 232aa43c215SJeff Kirsher {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */ 233aa43c215SJeff Kirsher {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */ 234aa43c215SJeff Kirsher {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */ 235aa43c215SJeff Kirsher {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */ 236aa43c215SJeff Kirsher {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */ 237aa43c215SJeff Kirsher {{{0} } }, /* 59: I2C0 */ 238aa43c215SJeff Kirsher {{{0} } }, /* 60: I2C1 */ 239aa43c215SJeff Kirsher {{{1, 0x3d00000, 0x3d04000, 0x1d8000} } },/* 61: LPC */ 240aa43c215SJeff Kirsher {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */ 241aa43c215SJeff Kirsher {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */ 242aa43c215SJeff Kirsher }; 243aa43c215SJeff Kirsher 244aa43c215SJeff Kirsher /* 245aa43c215SJeff Kirsher * top 12 bits of crb internal address (hub, agent) 246aa43c215SJeff Kirsher */ 247aa43c215SJeff Kirsher static unsigned crb_hub_agt[64] = 248aa43c215SJeff Kirsher { 249aa43c215SJeff Kirsher 0, 250aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PS, 251aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_MN, 252aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_MS, 253aa43c215SJeff Kirsher 0, 254aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SRE, 255aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_NIU, 256aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_QMN, 257aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SQN0, 258aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SQN1, 259aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SQN2, 260aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SQN3, 261aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, 262aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, 263aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, 264aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGN4, 265aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, 266aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGN0, 267aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGN1, 268aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGN2, 269aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGN3, 270aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGND, 271aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGNI, 272aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGS0, 273aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGS1, 274aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGS2, 275aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGS3, 276aa43c215SJeff Kirsher 0, 277aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGSI, 278aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SN, 279aa43c215SJeff Kirsher 0, 280aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_EG, 281aa43c215SJeff Kirsher 0, 282aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PS, 283aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_CAM, 284aa43c215SJeff Kirsher 0, 285aa43c215SJeff Kirsher 0, 286aa43c215SJeff Kirsher 0, 287aa43c215SJeff Kirsher 0, 288aa43c215SJeff Kirsher 0, 289aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_TIMR, 290aa43c215SJeff Kirsher 0, 291aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX1, 292aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX2, 293aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX3, 294aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX4, 295aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX5, 296aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX6, 297aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX7, 298aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_XDMA, 299aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_I2Q, 300aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_ROMUSB, 301aa43c215SJeff Kirsher 0, 302aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX0, 303aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX8, 304aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_RPMX9, 305aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_OCM0, 306aa43c215SJeff Kirsher 0, 307aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_SMB, 308aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_I2C0, 309aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_I2C1, 310aa43c215SJeff Kirsher 0, 311aa43c215SJeff Kirsher NETXEN_HW_CRB_HUB_AGT_ADR_PGNC, 312aa43c215SJeff Kirsher 0, 313aa43c215SJeff Kirsher }; 314aa43c215SJeff Kirsher 315aa43c215SJeff Kirsher /* PCI Windowing for DDR regions. */ 316aa43c215SJeff Kirsher 317aa43c215SJeff Kirsher #define NETXEN_WINDOW_ONE 0x2000000 /*CRB Window: bit 25 of CRB address */ 318aa43c215SJeff Kirsher 319aa43c215SJeff Kirsher #define NETXEN_PCIE_SEM_TIMEOUT 10000 320aa43c215SJeff Kirsher 321aa43c215SJeff Kirsher static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu); 322aa43c215SJeff Kirsher 323aa43c215SJeff Kirsher int 324aa43c215SJeff Kirsher netxen_pcie_sem_lock(struct netxen_adapter *adapter, int sem, u32 id_reg) 325aa43c215SJeff Kirsher { 326aa43c215SJeff Kirsher int done = 0, timeout = 0; 327aa43c215SJeff Kirsher 328aa43c215SJeff Kirsher while (!done) { 329aa43c215SJeff Kirsher done = NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_LOCK(sem))); 330aa43c215SJeff Kirsher if (done == 1) 331aa43c215SJeff Kirsher break; 332aa43c215SJeff Kirsher if (++timeout >= NETXEN_PCIE_SEM_TIMEOUT) 333aa43c215SJeff Kirsher return -EIO; 334aa43c215SJeff Kirsher msleep(1); 335aa43c215SJeff Kirsher } 336aa43c215SJeff Kirsher 337aa43c215SJeff Kirsher if (id_reg) 338aa43c215SJeff Kirsher NXWR32(adapter, id_reg, adapter->portnum); 339aa43c215SJeff Kirsher 340aa43c215SJeff Kirsher return 0; 341aa43c215SJeff Kirsher } 342aa43c215SJeff Kirsher 343aa43c215SJeff Kirsher void 344aa43c215SJeff Kirsher netxen_pcie_sem_unlock(struct netxen_adapter *adapter, int sem) 345aa43c215SJeff Kirsher { 346aa43c215SJeff Kirsher NXRD32(adapter, NETXEN_PCIE_REG(PCIE_SEM_UNLOCK(sem))); 347aa43c215SJeff Kirsher } 348aa43c215SJeff Kirsher 349aa43c215SJeff Kirsher static int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) 350aa43c215SJeff Kirsher { 351aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { 352aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_1+(0x10000*port), 0x1447); 353aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0+(0x10000*port), 0x5); 354aa43c215SJeff Kirsher } 355aa43c215SJeff Kirsher 356aa43c215SJeff Kirsher return 0; 357aa43c215SJeff Kirsher } 358aa43c215SJeff Kirsher 359aa43c215SJeff Kirsher /* Disable an XG interface */ 360aa43c215SJeff Kirsher static int netxen_niu_disable_xg_port(struct netxen_adapter *adapter) 361aa43c215SJeff Kirsher { 362aa43c215SJeff Kirsher __u32 mac_cfg; 363aa43c215SJeff Kirsher u32 port = adapter->physical_port; 364aa43c215SJeff Kirsher 365aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) 366aa43c215SJeff Kirsher return 0; 367aa43c215SJeff Kirsher 368ed3b856bSSantosh Nayak if (port >= NETXEN_NIU_MAX_XG_PORTS) 369aa43c215SJeff Kirsher return -EINVAL; 370aa43c215SJeff Kirsher 371aa43c215SJeff Kirsher mac_cfg = 0; 372aa43c215SJeff Kirsher if (NXWR32(adapter, 373aa43c215SJeff Kirsher NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg)) 374aa43c215SJeff Kirsher return -EIO; 375aa43c215SJeff Kirsher return 0; 376aa43c215SJeff Kirsher } 377aa43c215SJeff Kirsher 378aa43c215SJeff Kirsher #define NETXEN_UNICAST_ADDR(port, index) \ 379aa43c215SJeff Kirsher (NETXEN_UNICAST_ADDR_BASE+(port*32)+(index*8)) 380aa43c215SJeff Kirsher #define NETXEN_MCAST_ADDR(port, index) \ 381aa43c215SJeff Kirsher (NETXEN_MULTICAST_ADDR_BASE+(port*0x80)+(index*8)) 382aa43c215SJeff Kirsher #define MAC_HI(addr) \ 383aa43c215SJeff Kirsher ((addr[2] << 16) | (addr[1] << 8) | (addr[0])) 384aa43c215SJeff Kirsher #define MAC_LO(addr) \ 385aa43c215SJeff Kirsher ((addr[5] << 16) | (addr[4] << 8) | (addr[3])) 386aa43c215SJeff Kirsher 387aa43c215SJeff Kirsher static int netxen_p2_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) 388aa43c215SJeff Kirsher { 389aa43c215SJeff Kirsher u32 mac_cfg; 390aa43c215SJeff Kirsher u32 cnt = 0; 391aa43c215SJeff Kirsher __u32 reg = 0x0200; 392aa43c215SJeff Kirsher u32 port = adapter->physical_port; 393aa43c215SJeff Kirsher u16 board_type = adapter->ahw.board_type; 394aa43c215SJeff Kirsher 395ed3b856bSSantosh Nayak if (port >= NETXEN_NIU_MAX_XG_PORTS) 396aa43c215SJeff Kirsher return -EINVAL; 397aa43c215SJeff Kirsher 398aa43c215SJeff Kirsher mac_cfg = NXRD32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port)); 399aa43c215SJeff Kirsher mac_cfg &= ~0x4; 400aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); 401aa43c215SJeff Kirsher 402aa43c215SJeff Kirsher if ((board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) || 403aa43c215SJeff Kirsher (board_type == NETXEN_BRDTYPE_P2_SB31_10G_HMEZ)) 404aa43c215SJeff Kirsher reg = (0x20 << port); 405aa43c215SJeff Kirsher 406aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_FRAME_COUNT_SELECT, reg); 407aa43c215SJeff Kirsher 408aa43c215SJeff Kirsher mdelay(10); 409aa43c215SJeff Kirsher 410aa43c215SJeff Kirsher while (NXRD32(adapter, NETXEN_NIU_FRAME_COUNT) && ++cnt < 20) 411aa43c215SJeff Kirsher mdelay(10); 412aa43c215SJeff Kirsher 413aa43c215SJeff Kirsher if (cnt < 20) { 414aa43c215SJeff Kirsher 415aa43c215SJeff Kirsher reg = NXRD32(adapter, 416aa43c215SJeff Kirsher NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port)); 417aa43c215SJeff Kirsher 418aa43c215SJeff Kirsher if (mode == NETXEN_NIU_PROMISC_MODE) 419aa43c215SJeff Kirsher reg = (reg | 0x2000UL); 420aa43c215SJeff Kirsher else 421aa43c215SJeff Kirsher reg = (reg & ~0x2000UL); 422aa43c215SJeff Kirsher 423aa43c215SJeff Kirsher if (mode == NETXEN_NIU_ALLMULTI_MODE) 424aa43c215SJeff Kirsher reg = (reg | 0x1000UL); 425aa43c215SJeff Kirsher else 426aa43c215SJeff Kirsher reg = (reg & ~0x1000UL); 427aa43c215SJeff Kirsher 428aa43c215SJeff Kirsher NXWR32(adapter, 429aa43c215SJeff Kirsher NETXEN_NIU_XGE_CONFIG_1 + (0x10000 * port), reg); 430aa43c215SJeff Kirsher } 431aa43c215SJeff Kirsher 432aa43c215SJeff Kirsher mac_cfg |= 0x4; 433aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XGE_CONFIG_0 + (0x10000 * port), mac_cfg); 434aa43c215SJeff Kirsher 435aa43c215SJeff Kirsher return 0; 436aa43c215SJeff Kirsher } 437aa43c215SJeff Kirsher 438aa43c215SJeff Kirsher static int netxen_p2_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) 439aa43c215SJeff Kirsher { 440aa43c215SJeff Kirsher u32 mac_hi, mac_lo; 441aa43c215SJeff Kirsher u32 reg_hi, reg_lo; 442aa43c215SJeff Kirsher 443aa43c215SJeff Kirsher u8 phy = adapter->physical_port; 444aa43c215SJeff Kirsher 445aa43c215SJeff Kirsher if (phy >= NETXEN_NIU_MAX_XG_PORTS) 446aa43c215SJeff Kirsher return -EINVAL; 447aa43c215SJeff Kirsher 448aa43c215SJeff Kirsher mac_lo = ((u32)addr[0] << 16) | ((u32)addr[1] << 24); 449aa43c215SJeff Kirsher mac_hi = addr[2] | ((u32)addr[3] << 8) | 450aa43c215SJeff Kirsher ((u32)addr[4] << 16) | ((u32)addr[5] << 24); 451aa43c215SJeff Kirsher 452aa43c215SJeff Kirsher reg_lo = NETXEN_NIU_XGE_STATION_ADDR_0_1 + (0x10000 * phy); 453aa43c215SJeff Kirsher reg_hi = NETXEN_NIU_XGE_STATION_ADDR_0_HI + (0x10000 * phy); 454aa43c215SJeff Kirsher 455aa43c215SJeff Kirsher /* write twice to flush */ 456aa43c215SJeff Kirsher if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) 457aa43c215SJeff Kirsher return -EIO; 458aa43c215SJeff Kirsher if (NXWR32(adapter, reg_lo, mac_lo) || NXWR32(adapter, reg_hi, mac_hi)) 459aa43c215SJeff Kirsher return -EIO; 460aa43c215SJeff Kirsher 461aa43c215SJeff Kirsher return 0; 462aa43c215SJeff Kirsher } 463aa43c215SJeff Kirsher 464aa43c215SJeff Kirsher static int 465aa43c215SJeff Kirsher netxen_nic_enable_mcast_filter(struct netxen_adapter *adapter) 466aa43c215SJeff Kirsher { 467aa43c215SJeff Kirsher u32 val = 0; 468aa43c215SJeff Kirsher u16 port = adapter->physical_port; 469aa43c215SJeff Kirsher u8 *addr = adapter->mac_addr; 470aa43c215SJeff Kirsher 471aa43c215SJeff Kirsher if (adapter->mc_enabled) 472aa43c215SJeff Kirsher return 0; 473aa43c215SJeff Kirsher 474aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); 475aa43c215SJeff Kirsher val |= (1UL << (28+port)); 476aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); 477aa43c215SJeff Kirsher 478aa43c215SJeff Kirsher /* add broadcast addr to filter */ 479aa43c215SJeff Kirsher val = 0xffffff; 480aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); 481aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); 482aa43c215SJeff Kirsher 483aa43c215SJeff Kirsher /* add station addr to filter */ 484aa43c215SJeff Kirsher val = MAC_HI(addr); 485aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), val); 486aa43c215SJeff Kirsher val = MAC_LO(addr); 487aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, val); 488aa43c215SJeff Kirsher 489aa43c215SJeff Kirsher adapter->mc_enabled = 1; 490aa43c215SJeff Kirsher return 0; 491aa43c215SJeff Kirsher } 492aa43c215SJeff Kirsher 493aa43c215SJeff Kirsher static int 494aa43c215SJeff Kirsher netxen_nic_disable_mcast_filter(struct netxen_adapter *adapter) 495aa43c215SJeff Kirsher { 496aa43c215SJeff Kirsher u32 val = 0; 497aa43c215SJeff Kirsher u16 port = adapter->physical_port; 498aa43c215SJeff Kirsher u8 *addr = adapter->mac_addr; 499aa43c215SJeff Kirsher 500aa43c215SJeff Kirsher if (!adapter->mc_enabled) 501aa43c215SJeff Kirsher return 0; 502aa43c215SJeff Kirsher 503aa43c215SJeff Kirsher val = NXRD32(adapter, NETXEN_MAC_ADDR_CNTL_REG); 504aa43c215SJeff Kirsher val &= ~(1UL << (28+port)); 505aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_MAC_ADDR_CNTL_REG, val); 506aa43c215SJeff Kirsher 507aa43c215SJeff Kirsher val = MAC_HI(addr); 508aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0), val); 509aa43c215SJeff Kirsher val = MAC_LO(addr); 510aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 0)+4, val); 511aa43c215SJeff Kirsher 512aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1), 0); 513aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_UNICAST_ADDR(port, 1)+4, 0); 514aa43c215SJeff Kirsher 515aa43c215SJeff Kirsher adapter->mc_enabled = 0; 516aa43c215SJeff Kirsher return 0; 517aa43c215SJeff Kirsher } 518aa43c215SJeff Kirsher 519aa43c215SJeff Kirsher static int 520aa43c215SJeff Kirsher netxen_nic_set_mcast_addr(struct netxen_adapter *adapter, 521aa43c215SJeff Kirsher int index, u8 *addr) 522aa43c215SJeff Kirsher { 523aa43c215SJeff Kirsher u32 hi = 0, lo = 0; 524aa43c215SJeff Kirsher u16 port = adapter->physical_port; 525aa43c215SJeff Kirsher 526aa43c215SJeff Kirsher lo = MAC_LO(addr); 527aa43c215SJeff Kirsher hi = MAC_HI(addr); 528aa43c215SJeff Kirsher 529aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_MCAST_ADDR(port, index), hi); 530aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_MCAST_ADDR(port, index)+4, lo); 531aa43c215SJeff Kirsher 532aa43c215SJeff Kirsher return 0; 533aa43c215SJeff Kirsher } 534aa43c215SJeff Kirsher 535aa43c215SJeff Kirsher static void netxen_p2_nic_set_multi(struct net_device *netdev) 536aa43c215SJeff Kirsher { 537aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(netdev); 538aa43c215SJeff Kirsher struct netdev_hw_addr *ha; 5391409a932SJoe Perches u8 null_addr[ETH_ALEN]; 540aa43c215SJeff Kirsher int i; 541aa43c215SJeff Kirsher 5421409a932SJoe Perches memset(null_addr, 0, ETH_ALEN); 543aa43c215SJeff Kirsher 544aa43c215SJeff Kirsher if (netdev->flags & IFF_PROMISC) { 545aa43c215SJeff Kirsher 546aa43c215SJeff Kirsher adapter->set_promisc(adapter, 547aa43c215SJeff Kirsher NETXEN_NIU_PROMISC_MODE); 548aa43c215SJeff Kirsher 549aa43c215SJeff Kirsher /* Full promiscuous mode */ 550aa43c215SJeff Kirsher netxen_nic_disable_mcast_filter(adapter); 551aa43c215SJeff Kirsher 552aa43c215SJeff Kirsher return; 553aa43c215SJeff Kirsher } 554aa43c215SJeff Kirsher 555aa43c215SJeff Kirsher if (netdev_mc_empty(netdev)) { 556aa43c215SJeff Kirsher adapter->set_promisc(adapter, 557aa43c215SJeff Kirsher NETXEN_NIU_NON_PROMISC_MODE); 558aa43c215SJeff Kirsher netxen_nic_disable_mcast_filter(adapter); 559aa43c215SJeff Kirsher return; 560aa43c215SJeff Kirsher } 561aa43c215SJeff Kirsher 562aa43c215SJeff Kirsher adapter->set_promisc(adapter, NETXEN_NIU_ALLMULTI_MODE); 563aa43c215SJeff Kirsher if (netdev->flags & IFF_ALLMULTI || 564aa43c215SJeff Kirsher netdev_mc_count(netdev) > adapter->max_mc_count) { 565aa43c215SJeff Kirsher netxen_nic_disable_mcast_filter(adapter); 566aa43c215SJeff Kirsher return; 567aa43c215SJeff Kirsher } 568aa43c215SJeff Kirsher 569aa43c215SJeff Kirsher netxen_nic_enable_mcast_filter(adapter); 570aa43c215SJeff Kirsher 571aa43c215SJeff Kirsher i = 0; 572aa43c215SJeff Kirsher netdev_for_each_mc_addr(ha, netdev) 573aa43c215SJeff Kirsher netxen_nic_set_mcast_addr(adapter, i++, ha->addr); 574aa43c215SJeff Kirsher 575aa43c215SJeff Kirsher /* Clear out remaining addresses */ 576aa43c215SJeff Kirsher while (i < adapter->max_mc_count) 577aa43c215SJeff Kirsher netxen_nic_set_mcast_addr(adapter, i++, null_addr); 578aa43c215SJeff Kirsher } 579aa43c215SJeff Kirsher 580aa43c215SJeff Kirsher static int 581aa43c215SJeff Kirsher netxen_send_cmd_descs(struct netxen_adapter *adapter, 582aa43c215SJeff Kirsher struct cmd_desc_type0 *cmd_desc_arr, int nr_desc) 583aa43c215SJeff Kirsher { 584aa43c215SJeff Kirsher u32 i, producer, consumer; 585aa43c215SJeff Kirsher struct netxen_cmd_buffer *pbuf; 586aa43c215SJeff Kirsher struct cmd_desc_type0 *cmd_desc; 587aa43c215SJeff Kirsher struct nx_host_tx_ring *tx_ring; 588aa43c215SJeff Kirsher 589aa43c215SJeff Kirsher i = 0; 590aa43c215SJeff Kirsher 591aa43c215SJeff Kirsher if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) 592aa43c215SJeff Kirsher return -EIO; 593aa43c215SJeff Kirsher 594aa43c215SJeff Kirsher tx_ring = adapter->tx_ring; 595aa43c215SJeff Kirsher __netif_tx_lock_bh(tx_ring->txq); 596aa43c215SJeff Kirsher 597aa43c215SJeff Kirsher producer = tx_ring->producer; 598aa43c215SJeff Kirsher consumer = tx_ring->sw_consumer; 599aa43c215SJeff Kirsher 600aa43c215SJeff Kirsher if (nr_desc >= netxen_tx_avail(tx_ring)) { 601aa43c215SJeff Kirsher netif_tx_stop_queue(tx_ring->txq); 602aa43c215SJeff Kirsher smp_mb(); 603aa43c215SJeff Kirsher if (netxen_tx_avail(tx_ring) > nr_desc) { 604aa43c215SJeff Kirsher if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) 605aa43c215SJeff Kirsher netif_tx_wake_queue(tx_ring->txq); 606aa43c215SJeff Kirsher } else { 607aa43c215SJeff Kirsher __netif_tx_unlock_bh(tx_ring->txq); 608aa43c215SJeff Kirsher return -EBUSY; 609aa43c215SJeff Kirsher } 610aa43c215SJeff Kirsher } 611aa43c215SJeff Kirsher 612aa43c215SJeff Kirsher do { 613aa43c215SJeff Kirsher cmd_desc = &cmd_desc_arr[i]; 614aa43c215SJeff Kirsher 615aa43c215SJeff Kirsher pbuf = &tx_ring->cmd_buf_arr[producer]; 616aa43c215SJeff Kirsher pbuf->skb = NULL; 617aa43c215SJeff Kirsher pbuf->frag_count = 0; 618aa43c215SJeff Kirsher 619aa43c215SJeff Kirsher memcpy(&tx_ring->desc_head[producer], 620aa43c215SJeff Kirsher &cmd_desc_arr[i], sizeof(struct cmd_desc_type0)); 621aa43c215SJeff Kirsher 622aa43c215SJeff Kirsher producer = get_next_index(producer, tx_ring->num_desc); 623aa43c215SJeff Kirsher i++; 624aa43c215SJeff Kirsher 625aa43c215SJeff Kirsher } while (i != nr_desc); 626aa43c215SJeff Kirsher 627aa43c215SJeff Kirsher tx_ring->producer = producer; 628aa43c215SJeff Kirsher 629aa43c215SJeff Kirsher netxen_nic_update_cmd_producer(adapter, tx_ring); 630aa43c215SJeff Kirsher 631aa43c215SJeff Kirsher __netif_tx_unlock_bh(tx_ring->txq); 632aa43c215SJeff Kirsher 633aa43c215SJeff Kirsher return 0; 634aa43c215SJeff Kirsher } 635aa43c215SJeff Kirsher 636aa43c215SJeff Kirsher static int 637aa43c215SJeff Kirsher nx_p3_sre_macaddr_change(struct netxen_adapter *adapter, u8 *addr, unsigned op) 638aa43c215SJeff Kirsher { 639aa43c215SJeff Kirsher nx_nic_req_t req; 640aa43c215SJeff Kirsher nx_mac_req_t *mac_req; 641aa43c215SJeff Kirsher u64 word; 642aa43c215SJeff Kirsher 643aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 644aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_NIC_REQUEST << 23); 645aa43c215SJeff Kirsher 646aa43c215SJeff Kirsher word = NX_MAC_EVENT | ((u64)adapter->portnum << 16); 647aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 648aa43c215SJeff Kirsher 649aa43c215SJeff Kirsher mac_req = (nx_mac_req_t *)&req.words[0]; 650aa43c215SJeff Kirsher mac_req->op = op; 651aa43c215SJeff Kirsher memcpy(mac_req->mac_addr, addr, 6); 652aa43c215SJeff Kirsher 653aa43c215SJeff Kirsher return netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 654aa43c215SJeff Kirsher } 655aa43c215SJeff Kirsher 656aa43c215SJeff Kirsher static int nx_p3_nic_add_mac(struct netxen_adapter *adapter, 657aa43c215SJeff Kirsher const u8 *addr, struct list_head *del_list) 658aa43c215SJeff Kirsher { 659aa43c215SJeff Kirsher struct list_head *head; 660aa43c215SJeff Kirsher nx_mac_list_t *cur; 661aa43c215SJeff Kirsher 662aa43c215SJeff Kirsher /* look up if already exists */ 663aa43c215SJeff Kirsher list_for_each(head, del_list) { 664aa43c215SJeff Kirsher cur = list_entry(head, nx_mac_list_t, list); 665aa43c215SJeff Kirsher 666aa43c215SJeff Kirsher if (memcmp(addr, cur->mac_addr, ETH_ALEN) == 0) { 667aa43c215SJeff Kirsher list_move_tail(head, &adapter->mac_list); 668aa43c215SJeff Kirsher return 0; 669aa43c215SJeff Kirsher } 670aa43c215SJeff Kirsher } 671aa43c215SJeff Kirsher 672aa43c215SJeff Kirsher cur = kzalloc(sizeof(nx_mac_list_t), GFP_ATOMIC); 673b2adaca9SJoe Perches if (cur == NULL) 674aa43c215SJeff Kirsher return -ENOMEM; 675b2adaca9SJoe Perches 676aa43c215SJeff Kirsher memcpy(cur->mac_addr, addr, ETH_ALEN); 677aa43c215SJeff Kirsher list_add_tail(&cur->list, &adapter->mac_list); 678aa43c215SJeff Kirsher return nx_p3_sre_macaddr_change(adapter, 679aa43c215SJeff Kirsher cur->mac_addr, NETXEN_MAC_ADD); 680aa43c215SJeff Kirsher } 681aa43c215SJeff Kirsher 682aa43c215SJeff Kirsher static void netxen_p3_nic_set_multi(struct net_device *netdev) 683aa43c215SJeff Kirsher { 684aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(netdev); 685aa43c215SJeff Kirsher struct netdev_hw_addr *ha; 686aa43c215SJeff Kirsher static const u8 bcast_addr[ETH_ALEN] = { 687aa43c215SJeff Kirsher 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 688aa43c215SJeff Kirsher }; 689aa43c215SJeff Kirsher u32 mode = VPORT_MISS_MODE_DROP; 690aa43c215SJeff Kirsher LIST_HEAD(del_list); 691aa43c215SJeff Kirsher struct list_head *head; 692aa43c215SJeff Kirsher nx_mac_list_t *cur; 693aa43c215SJeff Kirsher 694aa43c215SJeff Kirsher if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC) 695aa43c215SJeff Kirsher return; 696aa43c215SJeff Kirsher 697aa43c215SJeff Kirsher list_splice_tail_init(&adapter->mac_list, &del_list); 698aa43c215SJeff Kirsher 699aa43c215SJeff Kirsher nx_p3_nic_add_mac(adapter, adapter->mac_addr, &del_list); 700aa43c215SJeff Kirsher nx_p3_nic_add_mac(adapter, bcast_addr, &del_list); 701aa43c215SJeff Kirsher 702aa43c215SJeff Kirsher if (netdev->flags & IFF_PROMISC) { 703aa43c215SJeff Kirsher mode = VPORT_MISS_MODE_ACCEPT_ALL; 704aa43c215SJeff Kirsher goto send_fw_cmd; 705aa43c215SJeff Kirsher } 706aa43c215SJeff Kirsher 707aa43c215SJeff Kirsher if ((netdev->flags & IFF_ALLMULTI) || 708aa43c215SJeff Kirsher (netdev_mc_count(netdev) > adapter->max_mc_count)) { 709aa43c215SJeff Kirsher mode = VPORT_MISS_MODE_ACCEPT_MULTI; 710aa43c215SJeff Kirsher goto send_fw_cmd; 711aa43c215SJeff Kirsher } 712aa43c215SJeff Kirsher 713aa43c215SJeff Kirsher if (!netdev_mc_empty(netdev)) { 714aa43c215SJeff Kirsher netdev_for_each_mc_addr(ha, netdev) 715aa43c215SJeff Kirsher nx_p3_nic_add_mac(adapter, ha->addr, &del_list); 716aa43c215SJeff Kirsher } 717aa43c215SJeff Kirsher 718aa43c215SJeff Kirsher send_fw_cmd: 719aa43c215SJeff Kirsher adapter->set_promisc(adapter, mode); 720aa43c215SJeff Kirsher head = &del_list; 721aa43c215SJeff Kirsher while (!list_empty(head)) { 722aa43c215SJeff Kirsher cur = list_entry(head->next, nx_mac_list_t, list); 723aa43c215SJeff Kirsher 724aa43c215SJeff Kirsher nx_p3_sre_macaddr_change(adapter, 725aa43c215SJeff Kirsher cur->mac_addr, NETXEN_MAC_DEL); 726aa43c215SJeff Kirsher list_del(&cur->list); 727aa43c215SJeff Kirsher kfree(cur); 728aa43c215SJeff Kirsher } 729aa43c215SJeff Kirsher } 730aa43c215SJeff Kirsher 731aa43c215SJeff Kirsher static int netxen_p3_nic_set_promisc(struct netxen_adapter *adapter, u32 mode) 732aa43c215SJeff Kirsher { 733aa43c215SJeff Kirsher nx_nic_req_t req; 734aa43c215SJeff Kirsher u64 word; 735aa43c215SJeff Kirsher 736aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 737aa43c215SJeff Kirsher 738aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 739aa43c215SJeff Kirsher 740aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_PROXY_SET_VPORT_MISS_MODE | 741aa43c215SJeff Kirsher ((u64)adapter->portnum << 16); 742aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 743aa43c215SJeff Kirsher 744aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(mode); 745aa43c215SJeff Kirsher 746aa43c215SJeff Kirsher return netxen_send_cmd_descs(adapter, 747aa43c215SJeff Kirsher (struct cmd_desc_type0 *)&req, 1); 748aa43c215SJeff Kirsher } 749aa43c215SJeff Kirsher 750aa43c215SJeff Kirsher void netxen_p3_free_mac_list(struct netxen_adapter *adapter) 751aa43c215SJeff Kirsher { 752aa43c215SJeff Kirsher nx_mac_list_t *cur; 753aa43c215SJeff Kirsher struct list_head *head = &adapter->mac_list; 754aa43c215SJeff Kirsher 755aa43c215SJeff Kirsher while (!list_empty(head)) { 756aa43c215SJeff Kirsher cur = list_entry(head->next, nx_mac_list_t, list); 757aa43c215SJeff Kirsher nx_p3_sre_macaddr_change(adapter, 758aa43c215SJeff Kirsher cur->mac_addr, NETXEN_MAC_DEL); 759aa43c215SJeff Kirsher list_del(&cur->list); 760aa43c215SJeff Kirsher kfree(cur); 761aa43c215SJeff Kirsher } 762aa43c215SJeff Kirsher } 763aa43c215SJeff Kirsher 764aa43c215SJeff Kirsher static int netxen_p3_nic_set_mac_addr(struct netxen_adapter *adapter, u8 *addr) 765aa43c215SJeff Kirsher { 766aa43c215SJeff Kirsher /* assuming caller has already copied new addr to netdev */ 767aa43c215SJeff Kirsher netxen_p3_nic_set_multi(adapter->netdev); 768aa43c215SJeff Kirsher return 0; 769aa43c215SJeff Kirsher } 770aa43c215SJeff Kirsher 771aa43c215SJeff Kirsher #define NETXEN_CONFIG_INTR_COALESCE 3 772aa43c215SJeff Kirsher 773aa43c215SJeff Kirsher /* 774aa43c215SJeff Kirsher * Send the interrupt coalescing parameter set by ethtool to the card. 775aa43c215SJeff Kirsher */ 776aa43c215SJeff Kirsher int netxen_config_intr_coalesce(struct netxen_adapter *adapter) 777aa43c215SJeff Kirsher { 778aa43c215SJeff Kirsher nx_nic_req_t req; 779aa43c215SJeff Kirsher u64 word[6]; 780aa43c215SJeff Kirsher int rv, i; 781aa43c215SJeff Kirsher 782aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 783aa43c215SJeff Kirsher memset(word, 0, sizeof(word)); 784aa43c215SJeff Kirsher 785aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 786aa43c215SJeff Kirsher 787aa43c215SJeff Kirsher word[0] = NETXEN_CONFIG_INTR_COALESCE | ((u64)adapter->portnum << 16); 788aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word[0]); 789aa43c215SJeff Kirsher 790aa43c215SJeff Kirsher memcpy(&word[0], &adapter->coal, sizeof(adapter->coal)); 791aa43c215SJeff Kirsher for (i = 0; i < 6; i++) 792aa43c215SJeff Kirsher req.words[i] = cpu_to_le64(word[i]); 793aa43c215SJeff Kirsher 794aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 795aa43c215SJeff Kirsher if (rv != 0) { 796aa43c215SJeff Kirsher printk(KERN_ERR "ERROR. Could not send " 797aa43c215SJeff Kirsher "interrupt coalescing parameters\n"); 798aa43c215SJeff Kirsher } 799aa43c215SJeff Kirsher 800aa43c215SJeff Kirsher return rv; 801aa43c215SJeff Kirsher } 802aa43c215SJeff Kirsher 803aa43c215SJeff Kirsher int netxen_config_hw_lro(struct netxen_adapter *adapter, int enable) 804aa43c215SJeff Kirsher { 805aa43c215SJeff Kirsher nx_nic_req_t req; 806aa43c215SJeff Kirsher u64 word; 807aa43c215SJeff Kirsher int rv = 0; 808aa43c215SJeff Kirsher 809aa43c215SJeff Kirsher if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) 810aa43c215SJeff Kirsher return 0; 811aa43c215SJeff Kirsher 812aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 813aa43c215SJeff Kirsher 814aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 815aa43c215SJeff Kirsher 816aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_CONFIG_HW_LRO | ((u64)adapter->portnum << 16); 817aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 818aa43c215SJeff Kirsher 819aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(enable); 820aa43c215SJeff Kirsher 821aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 822aa43c215SJeff Kirsher if (rv != 0) { 823aa43c215SJeff Kirsher printk(KERN_ERR "ERROR. Could not send " 824aa43c215SJeff Kirsher "configure hw lro request\n"); 825aa43c215SJeff Kirsher } 826aa43c215SJeff Kirsher 827aa43c215SJeff Kirsher return rv; 828aa43c215SJeff Kirsher } 829aa43c215SJeff Kirsher 830aa43c215SJeff Kirsher int netxen_config_bridged_mode(struct netxen_adapter *adapter, int enable) 831aa43c215SJeff Kirsher { 832aa43c215SJeff Kirsher nx_nic_req_t req; 833aa43c215SJeff Kirsher u64 word; 834aa43c215SJeff Kirsher int rv = 0; 835aa43c215SJeff Kirsher 836aa43c215SJeff Kirsher if (!!(adapter->flags & NETXEN_NIC_BRIDGE_ENABLED) == enable) 837aa43c215SJeff Kirsher return rv; 838aa43c215SJeff Kirsher 839aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 840aa43c215SJeff Kirsher 841aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 842aa43c215SJeff Kirsher 843aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_CONFIG_BRIDGING | 844aa43c215SJeff Kirsher ((u64)adapter->portnum << 16); 845aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 846aa43c215SJeff Kirsher 847aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(enable); 848aa43c215SJeff Kirsher 849aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 850aa43c215SJeff Kirsher if (rv != 0) { 851aa43c215SJeff Kirsher printk(KERN_ERR "ERROR. Could not send " 852aa43c215SJeff Kirsher "configure bridge mode request\n"); 853aa43c215SJeff Kirsher } 854aa43c215SJeff Kirsher 855aa43c215SJeff Kirsher adapter->flags ^= NETXEN_NIC_BRIDGE_ENABLED; 856aa43c215SJeff Kirsher 857aa43c215SJeff Kirsher return rv; 858aa43c215SJeff Kirsher } 859aa43c215SJeff Kirsher 860aa43c215SJeff Kirsher 861aa43c215SJeff Kirsher #define RSS_HASHTYPE_IP_TCP 0x3 862aa43c215SJeff Kirsher 863aa43c215SJeff Kirsher int netxen_config_rss(struct netxen_adapter *adapter, int enable) 864aa43c215SJeff Kirsher { 865aa43c215SJeff Kirsher nx_nic_req_t req; 866aa43c215SJeff Kirsher u64 word; 867aa43c215SJeff Kirsher int i, rv; 868aa43c215SJeff Kirsher 869aa43c215SJeff Kirsher static const u64 key[] = { 870aa43c215SJeff Kirsher 0xbeac01fa6a42b73bULL, 0x8030f20c77cb2da3ULL, 871aa43c215SJeff Kirsher 0xae7b30b4d0ca2bcbULL, 0x43a38fb04167253dULL, 872aa43c215SJeff Kirsher 0x255b0ec26d5a56daULL 873aa43c215SJeff Kirsher }; 874aa43c215SJeff Kirsher 875aa43c215SJeff Kirsher 876aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 877aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 878aa43c215SJeff Kirsher 879aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_CONFIG_RSS | ((u64)adapter->portnum << 16); 880aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 881aa43c215SJeff Kirsher 882aa43c215SJeff Kirsher /* 883aa43c215SJeff Kirsher * RSS request: 884aa43c215SJeff Kirsher * bits 3-0: hash_method 885aa43c215SJeff Kirsher * 5-4: hash_type_ipv4 886aa43c215SJeff Kirsher * 7-6: hash_type_ipv6 887aa43c215SJeff Kirsher * 8: enable 888aa43c215SJeff Kirsher * 9: use indirection table 889aa43c215SJeff Kirsher * 47-10: reserved 890aa43c215SJeff Kirsher * 63-48: indirection table mask 891aa43c215SJeff Kirsher */ 892aa43c215SJeff Kirsher word = ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 4) | 893aa43c215SJeff Kirsher ((u64)(RSS_HASHTYPE_IP_TCP & 0x3) << 6) | 894aa43c215SJeff Kirsher ((u64)(enable & 0x1) << 8) | 895aa43c215SJeff Kirsher ((0x7ULL) << 48); 896aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(word); 897aa43c215SJeff Kirsher for (i = 0; i < ARRAY_SIZE(key); i++) 898aa43c215SJeff Kirsher req.words[i+1] = cpu_to_le64(key[i]); 899aa43c215SJeff Kirsher 900aa43c215SJeff Kirsher 901aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 902aa43c215SJeff Kirsher if (rv != 0) { 903aa43c215SJeff Kirsher printk(KERN_ERR "%s: could not configure RSS\n", 904aa43c215SJeff Kirsher adapter->netdev->name); 905aa43c215SJeff Kirsher } 906aa43c215SJeff Kirsher 907aa43c215SJeff Kirsher return rv; 908aa43c215SJeff Kirsher } 909aa43c215SJeff Kirsher 91006d6c108SSantosh Nayak int netxen_config_ipaddr(struct netxen_adapter *adapter, __be32 ip, int cmd) 911aa43c215SJeff Kirsher { 912aa43c215SJeff Kirsher nx_nic_req_t req; 913aa43c215SJeff Kirsher u64 word; 914aa43c215SJeff Kirsher int rv; 915aa43c215SJeff Kirsher 916aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 917aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 918aa43c215SJeff Kirsher 919aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_CONFIG_IPADDR | ((u64)adapter->portnum << 16); 920aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 921aa43c215SJeff Kirsher 922aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(cmd); 92306d6c108SSantosh Nayak memcpy(&req.words[1], &ip, sizeof(u32)); 924aa43c215SJeff Kirsher 925aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 926aa43c215SJeff Kirsher if (rv != 0) { 927aa43c215SJeff Kirsher printk(KERN_ERR "%s: could not notify %s IP 0x%x reuqest\n", 928aa43c215SJeff Kirsher adapter->netdev->name, 929aa43c215SJeff Kirsher (cmd == NX_IP_UP) ? "Add" : "Remove", ip); 930aa43c215SJeff Kirsher } 931aa43c215SJeff Kirsher return rv; 932aa43c215SJeff Kirsher } 933aa43c215SJeff Kirsher 934aa43c215SJeff Kirsher int netxen_linkevent_request(struct netxen_adapter *adapter, int enable) 935aa43c215SJeff Kirsher { 936aa43c215SJeff Kirsher nx_nic_req_t req; 937aa43c215SJeff Kirsher u64 word; 938aa43c215SJeff Kirsher int rv; 939aa43c215SJeff Kirsher 940aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 941aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 942aa43c215SJeff Kirsher 943aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_GET_LINKEVENT | ((u64)adapter->portnum << 16); 944aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 945aa43c215SJeff Kirsher req.words[0] = cpu_to_le64(enable | (enable << 8)); 946aa43c215SJeff Kirsher 947aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 948aa43c215SJeff Kirsher if (rv != 0) { 949aa43c215SJeff Kirsher printk(KERN_ERR "%s: could not configure link notification\n", 950aa43c215SJeff Kirsher adapter->netdev->name); 951aa43c215SJeff Kirsher } 952aa43c215SJeff Kirsher 953aa43c215SJeff Kirsher return rv; 954aa43c215SJeff Kirsher } 955aa43c215SJeff Kirsher 956aa43c215SJeff Kirsher int netxen_send_lro_cleanup(struct netxen_adapter *adapter) 957aa43c215SJeff Kirsher { 958aa43c215SJeff Kirsher nx_nic_req_t req; 959aa43c215SJeff Kirsher u64 word; 960aa43c215SJeff Kirsher int rv; 961aa43c215SJeff Kirsher 962aa43c215SJeff Kirsher if (!test_bit(__NX_FW_ATTACHED, &adapter->state)) 963aa43c215SJeff Kirsher return 0; 964aa43c215SJeff Kirsher 965aa43c215SJeff Kirsher memset(&req, 0, sizeof(nx_nic_req_t)); 966aa43c215SJeff Kirsher req.qhdr = cpu_to_le64(NX_HOST_REQUEST << 23); 967aa43c215SJeff Kirsher 968aa43c215SJeff Kirsher word = NX_NIC_H2C_OPCODE_LRO_REQUEST | 969aa43c215SJeff Kirsher ((u64)adapter->portnum << 16) | 970aa43c215SJeff Kirsher ((u64)NX_NIC_LRO_REQUEST_CLEANUP << 56) ; 971aa43c215SJeff Kirsher 972aa43c215SJeff Kirsher req.req_hdr = cpu_to_le64(word); 973aa43c215SJeff Kirsher 974aa43c215SJeff Kirsher rv = netxen_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 975aa43c215SJeff Kirsher if (rv != 0) { 976aa43c215SJeff Kirsher printk(KERN_ERR "%s: could not cleanup lro flows\n", 977aa43c215SJeff Kirsher adapter->netdev->name); 978aa43c215SJeff Kirsher } 979aa43c215SJeff Kirsher return rv; 980aa43c215SJeff Kirsher } 981aa43c215SJeff Kirsher 982aa43c215SJeff Kirsher /* 983aa43c215SJeff Kirsher * netxen_nic_change_mtu - Change the Maximum Transfer Unit 984aa43c215SJeff Kirsher * @returns 0 on success, negative on failure 985aa43c215SJeff Kirsher */ 986aa43c215SJeff Kirsher 987aa43c215SJeff Kirsher #define MTU_FUDGE_FACTOR 100 988aa43c215SJeff Kirsher 989aa43c215SJeff Kirsher int netxen_nic_change_mtu(struct net_device *netdev, int mtu) 990aa43c215SJeff Kirsher { 991aa43c215SJeff Kirsher struct netxen_adapter *adapter = netdev_priv(netdev); 992aa43c215SJeff Kirsher int max_mtu; 993aa43c215SJeff Kirsher int rc = 0; 994aa43c215SJeff Kirsher 995aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) 996aa43c215SJeff Kirsher max_mtu = P3_MAX_MTU; 997aa43c215SJeff Kirsher else 998aa43c215SJeff Kirsher max_mtu = P2_MAX_MTU; 999aa43c215SJeff Kirsher 1000aa43c215SJeff Kirsher if (mtu > max_mtu) { 1001aa43c215SJeff Kirsher printk(KERN_ERR "%s: mtu > %d bytes unsupported\n", 1002aa43c215SJeff Kirsher netdev->name, max_mtu); 1003aa43c215SJeff Kirsher return -EINVAL; 1004aa43c215SJeff Kirsher } 1005aa43c215SJeff Kirsher 1006aa43c215SJeff Kirsher if (adapter->set_mtu) 1007aa43c215SJeff Kirsher rc = adapter->set_mtu(adapter, mtu); 1008aa43c215SJeff Kirsher 1009aa43c215SJeff Kirsher if (!rc) 1010aa43c215SJeff Kirsher netdev->mtu = mtu; 1011aa43c215SJeff Kirsher 1012aa43c215SJeff Kirsher return rc; 1013aa43c215SJeff Kirsher } 1014aa43c215SJeff Kirsher 1015aa43c215SJeff Kirsher static int netxen_get_flash_block(struct netxen_adapter *adapter, int base, 1016aa43c215SJeff Kirsher int size, __le32 * buf) 1017aa43c215SJeff Kirsher { 1018aa43c215SJeff Kirsher int i, v, addr; 1019aa43c215SJeff Kirsher __le32 *ptr32; 1020aa43c215SJeff Kirsher 1021aa43c215SJeff Kirsher addr = base; 1022aa43c215SJeff Kirsher ptr32 = buf; 1023aa43c215SJeff Kirsher for (i = 0; i < size / sizeof(u32); i++) { 1024aa43c215SJeff Kirsher if (netxen_rom_fast_read(adapter, addr, &v) == -1) 1025aa43c215SJeff Kirsher return -1; 1026aa43c215SJeff Kirsher *ptr32 = cpu_to_le32(v); 1027aa43c215SJeff Kirsher ptr32++; 1028aa43c215SJeff Kirsher addr += sizeof(u32); 1029aa43c215SJeff Kirsher } 1030aa43c215SJeff Kirsher if ((char *)buf + size > (char *)ptr32) { 1031aa43c215SJeff Kirsher __le32 local; 1032aa43c215SJeff Kirsher if (netxen_rom_fast_read(adapter, addr, &v) == -1) 1033aa43c215SJeff Kirsher return -1; 1034aa43c215SJeff Kirsher local = cpu_to_le32(v); 1035aa43c215SJeff Kirsher memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); 1036aa43c215SJeff Kirsher } 1037aa43c215SJeff Kirsher 1038aa43c215SJeff Kirsher return 0; 1039aa43c215SJeff Kirsher } 1040aa43c215SJeff Kirsher 1041aa43c215SJeff Kirsher int netxen_get_flash_mac_addr(struct netxen_adapter *adapter, u64 *mac) 1042aa43c215SJeff Kirsher { 1043aa43c215SJeff Kirsher __le32 *pmac = (__le32 *) mac; 1044aa43c215SJeff Kirsher u32 offset; 1045aa43c215SJeff Kirsher 1046aa43c215SJeff Kirsher offset = NX_FW_MAC_ADDR_OFFSET + (adapter->portnum * sizeof(u64)); 1047aa43c215SJeff Kirsher 1048aa43c215SJeff Kirsher if (netxen_get_flash_block(adapter, offset, sizeof(u64), pmac) == -1) 1049aa43c215SJeff Kirsher return -1; 1050aa43c215SJeff Kirsher 105106d6c108SSantosh Nayak if (*mac == ~0ULL) { 1052aa43c215SJeff Kirsher 1053aa43c215SJeff Kirsher offset = NX_OLD_MAC_ADDR_OFFSET + 1054aa43c215SJeff Kirsher (adapter->portnum * sizeof(u64)); 1055aa43c215SJeff Kirsher 1056aa43c215SJeff Kirsher if (netxen_get_flash_block(adapter, 1057aa43c215SJeff Kirsher offset, sizeof(u64), pmac) == -1) 1058aa43c215SJeff Kirsher return -1; 1059aa43c215SJeff Kirsher 106006d6c108SSantosh Nayak if (*mac == ~0ULL) 1061aa43c215SJeff Kirsher return -1; 1062aa43c215SJeff Kirsher } 1063aa43c215SJeff Kirsher return 0; 1064aa43c215SJeff Kirsher } 1065aa43c215SJeff Kirsher 1066aa43c215SJeff Kirsher int netxen_p3_get_mac_addr(struct netxen_adapter *adapter, u64 *mac) 1067aa43c215SJeff Kirsher { 1068aa43c215SJeff Kirsher uint32_t crbaddr, mac_hi, mac_lo; 1069aa43c215SJeff Kirsher int pci_func = adapter->ahw.pci_func; 1070aa43c215SJeff Kirsher 1071aa43c215SJeff Kirsher crbaddr = CRB_MAC_BLOCK_START + 1072aa43c215SJeff Kirsher (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1)); 1073aa43c215SJeff Kirsher 1074aa43c215SJeff Kirsher mac_lo = NXRD32(adapter, crbaddr); 1075aa43c215SJeff Kirsher mac_hi = NXRD32(adapter, crbaddr+4); 1076aa43c215SJeff Kirsher 1077aa43c215SJeff Kirsher if (pci_func & 1) 1078aa43c215SJeff Kirsher *mac = le64_to_cpu((mac_lo >> 16) | ((u64)mac_hi << 16)); 1079aa43c215SJeff Kirsher else 1080aa43c215SJeff Kirsher *mac = le64_to_cpu((u64)mac_lo | ((u64)mac_hi << 32)); 1081aa43c215SJeff Kirsher 1082aa43c215SJeff Kirsher return 0; 1083aa43c215SJeff Kirsher } 1084aa43c215SJeff Kirsher 1085aa43c215SJeff Kirsher /* 1086aa43c215SJeff Kirsher * Changes the CRB window to the specified window. 1087aa43c215SJeff Kirsher */ 1088aa43c215SJeff Kirsher static void 1089aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(struct netxen_adapter *adapter, 1090aa43c215SJeff Kirsher u32 window) 1091aa43c215SJeff Kirsher { 1092aa43c215SJeff Kirsher void __iomem *offset; 1093aa43c215SJeff Kirsher int count = 10; 1094aa43c215SJeff Kirsher u8 func = adapter->ahw.pci_func; 1095aa43c215SJeff Kirsher 1096aa43c215SJeff Kirsher if (adapter->ahw.crb_win == window) 1097aa43c215SJeff Kirsher return; 1098aa43c215SJeff Kirsher 1099aa43c215SJeff Kirsher offset = PCI_OFFSET_SECOND_RANGE(adapter, 1100aa43c215SJeff Kirsher NETXEN_PCIX_PH_REG(PCIE_CRB_WINDOW_REG(func))); 1101aa43c215SJeff Kirsher 1102aa43c215SJeff Kirsher writel(window, offset); 1103aa43c215SJeff Kirsher do { 1104aa43c215SJeff Kirsher if (window == readl(offset)) 1105aa43c215SJeff Kirsher break; 1106aa43c215SJeff Kirsher 1107aa43c215SJeff Kirsher if (printk_ratelimit()) 1108aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, 1109aa43c215SJeff Kirsher "failed to set CRB window to %d\n", 1110aa43c215SJeff Kirsher (window == NETXEN_WINDOW_ONE)); 1111aa43c215SJeff Kirsher udelay(1); 1112aa43c215SJeff Kirsher 1113aa43c215SJeff Kirsher } while (--count > 0); 1114aa43c215SJeff Kirsher 1115aa43c215SJeff Kirsher if (count > 0) 1116aa43c215SJeff Kirsher adapter->ahw.crb_win = window; 1117aa43c215SJeff Kirsher } 1118aa43c215SJeff Kirsher 1119aa43c215SJeff Kirsher /* 1120aa43c215SJeff Kirsher * Returns < 0 if off is not valid, 1121aa43c215SJeff Kirsher * 1 if window access is needed. 'off' is set to offset from 1122aa43c215SJeff Kirsher * CRB space in 128M pci map 1123aa43c215SJeff Kirsher * 0 if no window access is needed. 'off' is set to 2M addr 1124aa43c215SJeff Kirsher * In: 'off' is offset from base in 128M pci map 1125aa43c215SJeff Kirsher */ 1126aa43c215SJeff Kirsher static int 1127aa43c215SJeff Kirsher netxen_nic_pci_get_crb_addr_2M(struct netxen_adapter *adapter, 1128aa43c215SJeff Kirsher ulong off, void __iomem **addr) 1129aa43c215SJeff Kirsher { 1130aa43c215SJeff Kirsher crb_128M_2M_sub_block_map_t *m; 1131aa43c215SJeff Kirsher 1132aa43c215SJeff Kirsher 1133aa43c215SJeff Kirsher if ((off >= NETXEN_CRB_MAX) || (off < NETXEN_PCI_CRBSPACE)) 1134aa43c215SJeff Kirsher return -EINVAL; 1135aa43c215SJeff Kirsher 1136aa43c215SJeff Kirsher off -= NETXEN_PCI_CRBSPACE; 1137aa43c215SJeff Kirsher 1138aa43c215SJeff Kirsher /* 1139aa43c215SJeff Kirsher * Try direct map 1140aa43c215SJeff Kirsher */ 1141aa43c215SJeff Kirsher m = &crb_128M_2M_map[CRB_BLK(off)].sub_block[CRB_SUBBLK(off)]; 1142aa43c215SJeff Kirsher 1143aa43c215SJeff Kirsher if (m->valid && (m->start_128M <= off) && (m->end_128M > off)) { 1144aa43c215SJeff Kirsher *addr = adapter->ahw.pci_base0 + m->start_2M + 1145aa43c215SJeff Kirsher (off - m->start_128M); 1146aa43c215SJeff Kirsher return 0; 1147aa43c215SJeff Kirsher } 1148aa43c215SJeff Kirsher 1149aa43c215SJeff Kirsher /* 1150aa43c215SJeff Kirsher * Not in direct map, use crb window 1151aa43c215SJeff Kirsher */ 1152aa43c215SJeff Kirsher *addr = adapter->ahw.pci_base0 + CRB_INDIRECT_2M + 1153aa43c215SJeff Kirsher (off & MASK(16)); 1154aa43c215SJeff Kirsher return 1; 1155aa43c215SJeff Kirsher } 1156aa43c215SJeff Kirsher 1157aa43c215SJeff Kirsher /* 1158aa43c215SJeff Kirsher * In: 'off' is offset from CRB space in 128M pci map 1159aa43c215SJeff Kirsher * Out: 'off' is 2M pci map addr 1160aa43c215SJeff Kirsher * side effect: lock crb window 1161aa43c215SJeff Kirsher */ 1162aa43c215SJeff Kirsher static void 1163aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_2M(struct netxen_adapter *adapter, ulong off) 1164aa43c215SJeff Kirsher { 1165aa43c215SJeff Kirsher u32 window; 1166aa43c215SJeff Kirsher void __iomem *addr = adapter->ahw.pci_base0 + CRB_WINDOW_2M; 1167aa43c215SJeff Kirsher 1168aa43c215SJeff Kirsher off -= NETXEN_PCI_CRBSPACE; 1169aa43c215SJeff Kirsher 1170aa43c215SJeff Kirsher window = CRB_HI(off); 1171aa43c215SJeff Kirsher 1172aa43c215SJeff Kirsher writel(window, addr); 1173aa43c215SJeff Kirsher if (readl(addr) != window) { 1174aa43c215SJeff Kirsher if (printk_ratelimit()) 1175aa43c215SJeff Kirsher dev_warn(&adapter->pdev->dev, 1176aa43c215SJeff Kirsher "failed to set CRB window to %d off 0x%lx\n", 1177aa43c215SJeff Kirsher window, off); 1178aa43c215SJeff Kirsher } 1179aa43c215SJeff Kirsher } 1180aa43c215SJeff Kirsher 1181aa43c215SJeff Kirsher static void __iomem * 1182aa43c215SJeff Kirsher netxen_nic_map_indirect_address_128M(struct netxen_adapter *adapter, 1183aa43c215SJeff Kirsher ulong win_off, void __iomem **mem_ptr) 1184aa43c215SJeff Kirsher { 1185aa43c215SJeff Kirsher ulong off = win_off; 1186aa43c215SJeff Kirsher void __iomem *addr; 1187aa43c215SJeff Kirsher resource_size_t mem_base; 1188aa43c215SJeff Kirsher 1189aa43c215SJeff Kirsher if (ADDR_IN_WINDOW1(win_off)) 1190aa43c215SJeff Kirsher off = NETXEN_CRB_NORMAL(win_off); 1191aa43c215SJeff Kirsher 1192aa43c215SJeff Kirsher addr = pci_base_offset(adapter, off); 1193aa43c215SJeff Kirsher if (addr) 1194aa43c215SJeff Kirsher return addr; 1195aa43c215SJeff Kirsher 1196aa43c215SJeff Kirsher if (adapter->ahw.pci_len0 == 0) 1197aa43c215SJeff Kirsher off -= NETXEN_PCI_CRBSPACE; 1198aa43c215SJeff Kirsher 1199aa43c215SJeff Kirsher mem_base = pci_resource_start(adapter->pdev, 0); 1200aa43c215SJeff Kirsher *mem_ptr = ioremap(mem_base + (off & PAGE_MASK), PAGE_SIZE); 1201aa43c215SJeff Kirsher if (*mem_ptr) 1202aa43c215SJeff Kirsher addr = *mem_ptr + (off & (PAGE_SIZE - 1)); 1203aa43c215SJeff Kirsher 1204aa43c215SJeff Kirsher return addr; 1205aa43c215SJeff Kirsher } 1206aa43c215SJeff Kirsher 1207aa43c215SJeff Kirsher static int 1208aa43c215SJeff Kirsher netxen_nic_hw_write_wx_128M(struct netxen_adapter *adapter, ulong off, u32 data) 1209aa43c215SJeff Kirsher { 1210aa43c215SJeff Kirsher unsigned long flags; 1211aa43c215SJeff Kirsher void __iomem *addr, *mem_ptr = NULL; 1212aa43c215SJeff Kirsher 1213aa43c215SJeff Kirsher addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); 1214aa43c215SJeff Kirsher if (!addr) 1215aa43c215SJeff Kirsher return -EIO; 1216aa43c215SJeff Kirsher 1217aa43c215SJeff Kirsher if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ 1218aa43c215SJeff Kirsher netxen_nic_io_write_128M(adapter, addr, data); 1219aa43c215SJeff Kirsher } else { /* Window 0 */ 1220aa43c215SJeff Kirsher write_lock_irqsave(&adapter->ahw.crb_lock, flags); 1221aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 0); 1222aa43c215SJeff Kirsher writel(data, addr); 1223aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 1224aa43c215SJeff Kirsher NETXEN_WINDOW_ONE); 1225aa43c215SJeff Kirsher write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); 1226aa43c215SJeff Kirsher } 1227aa43c215SJeff Kirsher 1228aa43c215SJeff Kirsher if (mem_ptr) 1229aa43c215SJeff Kirsher iounmap(mem_ptr); 1230aa43c215SJeff Kirsher 1231aa43c215SJeff Kirsher return 0; 1232aa43c215SJeff Kirsher } 1233aa43c215SJeff Kirsher 1234aa43c215SJeff Kirsher static u32 1235aa43c215SJeff Kirsher netxen_nic_hw_read_wx_128M(struct netxen_adapter *adapter, ulong off) 1236aa43c215SJeff Kirsher { 1237aa43c215SJeff Kirsher unsigned long flags; 1238aa43c215SJeff Kirsher void __iomem *addr, *mem_ptr = NULL; 1239aa43c215SJeff Kirsher u32 data; 1240aa43c215SJeff Kirsher 1241aa43c215SJeff Kirsher addr = netxen_nic_map_indirect_address_128M(adapter, off, &mem_ptr); 1242aa43c215SJeff Kirsher if (!addr) 1243aa43c215SJeff Kirsher return -EIO; 1244aa43c215SJeff Kirsher 1245aa43c215SJeff Kirsher if (ADDR_IN_WINDOW1(off)) { /* Window 1 */ 1246aa43c215SJeff Kirsher data = netxen_nic_io_read_128M(adapter, addr); 1247aa43c215SJeff Kirsher } else { /* Window 0 */ 1248aa43c215SJeff Kirsher write_lock_irqsave(&adapter->ahw.crb_lock, flags); 1249aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 0); 1250aa43c215SJeff Kirsher data = readl(addr); 1251aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 1252aa43c215SJeff Kirsher NETXEN_WINDOW_ONE); 1253aa43c215SJeff Kirsher write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); 1254aa43c215SJeff Kirsher } 1255aa43c215SJeff Kirsher 1256aa43c215SJeff Kirsher if (mem_ptr) 1257aa43c215SJeff Kirsher iounmap(mem_ptr); 1258aa43c215SJeff Kirsher 1259aa43c215SJeff Kirsher return data; 1260aa43c215SJeff Kirsher } 1261aa43c215SJeff Kirsher 1262aa43c215SJeff Kirsher static int 1263aa43c215SJeff Kirsher netxen_nic_hw_write_wx_2M(struct netxen_adapter *adapter, ulong off, u32 data) 1264aa43c215SJeff Kirsher { 1265aa43c215SJeff Kirsher unsigned long flags; 1266aa43c215SJeff Kirsher int rv; 1267aa43c215SJeff Kirsher void __iomem *addr = NULL; 1268aa43c215SJeff Kirsher 1269aa43c215SJeff Kirsher rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); 1270aa43c215SJeff Kirsher 1271aa43c215SJeff Kirsher if (rv == 0) { 1272aa43c215SJeff Kirsher writel(data, addr); 1273aa43c215SJeff Kirsher return 0; 1274aa43c215SJeff Kirsher } 1275aa43c215SJeff Kirsher 1276aa43c215SJeff Kirsher if (rv > 0) { 1277aa43c215SJeff Kirsher /* indirect access */ 1278aa43c215SJeff Kirsher write_lock_irqsave(&adapter->ahw.crb_lock, flags); 1279aa43c215SJeff Kirsher crb_win_lock(adapter); 1280aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_2M(adapter, off); 1281aa43c215SJeff Kirsher writel(data, addr); 1282aa43c215SJeff Kirsher crb_win_unlock(adapter); 1283aa43c215SJeff Kirsher write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); 1284aa43c215SJeff Kirsher return 0; 1285aa43c215SJeff Kirsher } 1286aa43c215SJeff Kirsher 1287aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1288aa43c215SJeff Kirsher "%s: invalid offset: 0x%016lx\n", __func__, off); 1289aa43c215SJeff Kirsher dump_stack(); 1290aa43c215SJeff Kirsher return -EIO; 1291aa43c215SJeff Kirsher } 1292aa43c215SJeff Kirsher 1293aa43c215SJeff Kirsher static u32 1294aa43c215SJeff Kirsher netxen_nic_hw_read_wx_2M(struct netxen_adapter *adapter, ulong off) 1295aa43c215SJeff Kirsher { 1296aa43c215SJeff Kirsher unsigned long flags; 1297aa43c215SJeff Kirsher int rv; 1298aa43c215SJeff Kirsher u32 data; 1299aa43c215SJeff Kirsher void __iomem *addr = NULL; 1300aa43c215SJeff Kirsher 1301aa43c215SJeff Kirsher rv = netxen_nic_pci_get_crb_addr_2M(adapter, off, &addr); 1302aa43c215SJeff Kirsher 1303aa43c215SJeff Kirsher if (rv == 0) 1304aa43c215SJeff Kirsher return readl(addr); 1305aa43c215SJeff Kirsher 1306aa43c215SJeff Kirsher if (rv > 0) { 1307aa43c215SJeff Kirsher /* indirect access */ 1308aa43c215SJeff Kirsher write_lock_irqsave(&adapter->ahw.crb_lock, flags); 1309aa43c215SJeff Kirsher crb_win_lock(adapter); 1310aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_2M(adapter, off); 1311aa43c215SJeff Kirsher data = readl(addr); 1312aa43c215SJeff Kirsher crb_win_unlock(adapter); 1313aa43c215SJeff Kirsher write_unlock_irqrestore(&adapter->ahw.crb_lock, flags); 1314aa43c215SJeff Kirsher return data; 1315aa43c215SJeff Kirsher } 1316aa43c215SJeff Kirsher 1317aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1318aa43c215SJeff Kirsher "%s: invalid offset: 0x%016lx\n", __func__, off); 1319aa43c215SJeff Kirsher dump_stack(); 1320aa43c215SJeff Kirsher return -1; 1321aa43c215SJeff Kirsher } 1322aa43c215SJeff Kirsher 1323aa43c215SJeff Kirsher /* window 1 registers only */ 1324aa43c215SJeff Kirsher static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, 1325aa43c215SJeff Kirsher void __iomem *addr, u32 data) 1326aa43c215SJeff Kirsher { 1327aa43c215SJeff Kirsher read_lock(&adapter->ahw.crb_lock); 1328aa43c215SJeff Kirsher writel(data, addr); 1329aa43c215SJeff Kirsher read_unlock(&adapter->ahw.crb_lock); 1330aa43c215SJeff Kirsher } 1331aa43c215SJeff Kirsher 1332aa43c215SJeff Kirsher static u32 netxen_nic_io_read_128M(struct netxen_adapter *adapter, 1333aa43c215SJeff Kirsher void __iomem *addr) 1334aa43c215SJeff Kirsher { 1335aa43c215SJeff Kirsher u32 val; 1336aa43c215SJeff Kirsher 1337aa43c215SJeff Kirsher read_lock(&adapter->ahw.crb_lock); 1338aa43c215SJeff Kirsher val = readl(addr); 1339aa43c215SJeff Kirsher read_unlock(&adapter->ahw.crb_lock); 1340aa43c215SJeff Kirsher 1341aa43c215SJeff Kirsher return val; 1342aa43c215SJeff Kirsher } 1343aa43c215SJeff Kirsher 1344aa43c215SJeff Kirsher static void netxen_nic_io_write_2M(struct netxen_adapter *adapter, 1345aa43c215SJeff Kirsher void __iomem *addr, u32 data) 1346aa43c215SJeff Kirsher { 1347aa43c215SJeff Kirsher writel(data, addr); 1348aa43c215SJeff Kirsher } 1349aa43c215SJeff Kirsher 1350aa43c215SJeff Kirsher static u32 netxen_nic_io_read_2M(struct netxen_adapter *adapter, 1351aa43c215SJeff Kirsher void __iomem *addr) 1352aa43c215SJeff Kirsher { 1353aa43c215SJeff Kirsher return readl(addr); 1354aa43c215SJeff Kirsher } 1355aa43c215SJeff Kirsher 1356aa43c215SJeff Kirsher void __iomem * 1357aa43c215SJeff Kirsher netxen_get_ioaddr(struct netxen_adapter *adapter, u32 offset) 1358aa43c215SJeff Kirsher { 1359aa43c215SJeff Kirsher void __iomem *addr = NULL; 1360aa43c215SJeff Kirsher 1361aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { 1362aa43c215SJeff Kirsher if ((offset < NETXEN_CRB_PCIX_HOST2) && 1363aa43c215SJeff Kirsher (offset > NETXEN_CRB_PCIX_HOST)) 1364aa43c215SJeff Kirsher addr = PCI_OFFSET_SECOND_RANGE(adapter, offset); 1365aa43c215SJeff Kirsher else 1366aa43c215SJeff Kirsher addr = NETXEN_CRB_NORMALIZE(adapter, offset); 1367aa43c215SJeff Kirsher } else { 1368aa43c215SJeff Kirsher WARN_ON(netxen_nic_pci_get_crb_addr_2M(adapter, 1369aa43c215SJeff Kirsher offset, &addr)); 1370aa43c215SJeff Kirsher } 1371aa43c215SJeff Kirsher 1372aa43c215SJeff Kirsher return addr; 1373aa43c215SJeff Kirsher } 1374aa43c215SJeff Kirsher 1375aa43c215SJeff Kirsher static int 1376aa43c215SJeff Kirsher netxen_nic_pci_set_window_128M(struct netxen_adapter *adapter, 1377aa43c215SJeff Kirsher u64 addr, u32 *start) 1378aa43c215SJeff Kirsher { 1379aa43c215SJeff Kirsher if (ADDR_IN_RANGE(addr, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { 1380aa43c215SJeff Kirsher *start = (addr - NETXEN_ADDR_OCM0 + NETXEN_PCI_OCM0); 1381aa43c215SJeff Kirsher return 0; 1382aa43c215SJeff Kirsher } else if (ADDR_IN_RANGE(addr, 1383aa43c215SJeff Kirsher NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { 1384aa43c215SJeff Kirsher *start = (addr - NETXEN_ADDR_OCM1 + NETXEN_PCI_OCM1); 1385aa43c215SJeff Kirsher return 0; 1386aa43c215SJeff Kirsher } 1387aa43c215SJeff Kirsher 1388aa43c215SJeff Kirsher return -EIO; 1389aa43c215SJeff Kirsher } 1390aa43c215SJeff Kirsher 1391aa43c215SJeff Kirsher static int 1392aa43c215SJeff Kirsher netxen_nic_pci_set_window_2M(struct netxen_adapter *adapter, 1393aa43c215SJeff Kirsher u64 addr, u32 *start) 1394aa43c215SJeff Kirsher { 1395aa43c215SJeff Kirsher u32 window; 1396aa43c215SJeff Kirsher 1397aa43c215SJeff Kirsher window = OCM_WIN(addr); 1398aa43c215SJeff Kirsher 1399aa43c215SJeff Kirsher writel(window, adapter->ahw.ocm_win_crb); 1400aa43c215SJeff Kirsher /* read back to flush */ 1401aa43c215SJeff Kirsher readl(adapter->ahw.ocm_win_crb); 1402aa43c215SJeff Kirsher 1403aa43c215SJeff Kirsher adapter->ahw.ocm_win = window; 1404aa43c215SJeff Kirsher *start = NETXEN_PCI_OCM0_2M + GET_MEM_OFFS_2M(addr); 1405aa43c215SJeff Kirsher return 0; 1406aa43c215SJeff Kirsher } 1407aa43c215SJeff Kirsher 1408aa43c215SJeff Kirsher static int 1409aa43c215SJeff Kirsher netxen_nic_pci_mem_access_direct(struct netxen_adapter *adapter, u64 off, 1410aa43c215SJeff Kirsher u64 *data, int op) 1411aa43c215SJeff Kirsher { 1412aa43c215SJeff Kirsher void __iomem *addr, *mem_ptr = NULL; 1413aa43c215SJeff Kirsher resource_size_t mem_base; 1414aa43c215SJeff Kirsher int ret; 1415aa43c215SJeff Kirsher u32 start; 1416aa43c215SJeff Kirsher 1417aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1418aa43c215SJeff Kirsher 1419aa43c215SJeff Kirsher ret = adapter->pci_set_window(adapter, off, &start); 1420aa43c215SJeff Kirsher if (ret != 0) 1421aa43c215SJeff Kirsher goto unlock; 1422aa43c215SJeff Kirsher 1423aa43c215SJeff Kirsher if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { 1424aa43c215SJeff Kirsher addr = adapter->ahw.pci_base0 + start; 1425aa43c215SJeff Kirsher } else { 1426aa43c215SJeff Kirsher addr = pci_base_offset(adapter, start); 1427aa43c215SJeff Kirsher if (addr) 1428aa43c215SJeff Kirsher goto noremap; 1429aa43c215SJeff Kirsher 1430aa43c215SJeff Kirsher mem_base = pci_resource_start(adapter->pdev, 0) + 1431aa43c215SJeff Kirsher (start & PAGE_MASK); 1432aa43c215SJeff Kirsher mem_ptr = ioremap(mem_base, PAGE_SIZE); 1433aa43c215SJeff Kirsher if (mem_ptr == NULL) { 1434aa43c215SJeff Kirsher ret = -EIO; 1435aa43c215SJeff Kirsher goto unlock; 1436aa43c215SJeff Kirsher } 1437aa43c215SJeff Kirsher 1438aa43c215SJeff Kirsher addr = mem_ptr + (start & (PAGE_SIZE-1)); 1439aa43c215SJeff Kirsher } 1440aa43c215SJeff Kirsher noremap: 1441aa43c215SJeff Kirsher if (op == 0) /* read */ 1442aa43c215SJeff Kirsher *data = readq(addr); 1443aa43c215SJeff Kirsher else /* write */ 1444aa43c215SJeff Kirsher writeq(*data, addr); 1445aa43c215SJeff Kirsher 1446aa43c215SJeff Kirsher unlock: 1447aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1448aa43c215SJeff Kirsher 1449aa43c215SJeff Kirsher if (mem_ptr) 1450aa43c215SJeff Kirsher iounmap(mem_ptr); 1451aa43c215SJeff Kirsher return ret; 1452aa43c215SJeff Kirsher } 1453aa43c215SJeff Kirsher 1454aa43c215SJeff Kirsher void 1455aa43c215SJeff Kirsher netxen_pci_camqm_read_2M(struct netxen_adapter *adapter, u64 off, u64 *data) 1456aa43c215SJeff Kirsher { 1457aa43c215SJeff Kirsher void __iomem *addr = adapter->ahw.pci_base0 + 1458aa43c215SJeff Kirsher NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); 1459aa43c215SJeff Kirsher 1460aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1461aa43c215SJeff Kirsher *data = readq(addr); 1462aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1463aa43c215SJeff Kirsher } 1464aa43c215SJeff Kirsher 1465aa43c215SJeff Kirsher void 1466aa43c215SJeff Kirsher netxen_pci_camqm_write_2M(struct netxen_adapter *adapter, u64 off, u64 data) 1467aa43c215SJeff Kirsher { 1468aa43c215SJeff Kirsher void __iomem *addr = adapter->ahw.pci_base0 + 1469aa43c215SJeff Kirsher NETXEN_PCI_CAMQM_2M_BASE + (off - NETXEN_PCI_CAMQM); 1470aa43c215SJeff Kirsher 1471aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1472aa43c215SJeff Kirsher writeq(data, addr); 1473aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1474aa43c215SJeff Kirsher } 1475aa43c215SJeff Kirsher 1476aa43c215SJeff Kirsher #define MAX_CTL_CHECK 1000 1477aa43c215SJeff Kirsher 1478aa43c215SJeff Kirsher static int 1479aa43c215SJeff Kirsher netxen_nic_pci_mem_write_128M(struct netxen_adapter *adapter, 1480aa43c215SJeff Kirsher u64 off, u64 data) 1481aa43c215SJeff Kirsher { 1482aa43c215SJeff Kirsher int j, ret; 1483aa43c215SJeff Kirsher u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; 1484aa43c215SJeff Kirsher void __iomem *mem_crb; 1485aa43c215SJeff Kirsher 1486aa43c215SJeff Kirsher /* Only 64-bit aligned access */ 1487aa43c215SJeff Kirsher if (off & 7) 1488aa43c215SJeff Kirsher return -EIO; 1489aa43c215SJeff Kirsher 1490aa43c215SJeff Kirsher /* P2 has different SIU and MIU test agent base addr */ 1491aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, 1492aa43c215SJeff Kirsher NETXEN_ADDR_QDR_NET_MAX_P2)) { 1493aa43c215SJeff Kirsher mem_crb = pci_base_offset(adapter, 1494aa43c215SJeff Kirsher NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); 1495aa43c215SJeff Kirsher addr_hi = SIU_TEST_AGT_ADDR_HI; 1496aa43c215SJeff Kirsher data_lo = SIU_TEST_AGT_WRDATA_LO; 1497aa43c215SJeff Kirsher data_hi = SIU_TEST_AGT_WRDATA_HI; 1498aa43c215SJeff Kirsher off_lo = off & SIU_TEST_AGT_ADDR_MASK; 1499aa43c215SJeff Kirsher off_hi = SIU_TEST_AGT_UPPER_ADDR(off); 1500aa43c215SJeff Kirsher goto correct; 1501aa43c215SJeff Kirsher } 1502aa43c215SJeff Kirsher 1503aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { 1504aa43c215SJeff Kirsher mem_crb = pci_base_offset(adapter, 1505aa43c215SJeff Kirsher NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); 1506aa43c215SJeff Kirsher addr_hi = MIU_TEST_AGT_ADDR_HI; 1507aa43c215SJeff Kirsher data_lo = MIU_TEST_AGT_WRDATA_LO; 1508aa43c215SJeff Kirsher data_hi = MIU_TEST_AGT_WRDATA_HI; 1509aa43c215SJeff Kirsher off_lo = off & MIU_TEST_AGT_ADDR_MASK; 1510aa43c215SJeff Kirsher off_hi = 0; 1511aa43c215SJeff Kirsher goto correct; 1512aa43c215SJeff Kirsher } 1513aa43c215SJeff Kirsher 1514aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || 1515aa43c215SJeff Kirsher ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { 1516aa43c215SJeff Kirsher if (adapter->ahw.pci_len0 != 0) { 1517aa43c215SJeff Kirsher return netxen_nic_pci_mem_access_direct(adapter, 1518aa43c215SJeff Kirsher off, &data, 1); 1519aa43c215SJeff Kirsher } 1520aa43c215SJeff Kirsher } 1521aa43c215SJeff Kirsher 1522aa43c215SJeff Kirsher return -EIO; 1523aa43c215SJeff Kirsher 1524aa43c215SJeff Kirsher correct: 1525aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1526aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 0); 1527aa43c215SJeff Kirsher 1528aa43c215SJeff Kirsher writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); 1529aa43c215SJeff Kirsher writel(off_hi, (mem_crb + addr_hi)); 1530aa43c215SJeff Kirsher writel(data & 0xffffffff, (mem_crb + data_lo)); 1531aa43c215SJeff Kirsher writel((data >> 32) & 0xffffffff, (mem_crb + data_hi)); 1532aa43c215SJeff Kirsher writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); 1533aa43c215SJeff Kirsher writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), 1534aa43c215SJeff Kirsher (mem_crb + TEST_AGT_CTRL)); 1535aa43c215SJeff Kirsher 1536aa43c215SJeff Kirsher for (j = 0; j < MAX_CTL_CHECK; j++) { 1537aa43c215SJeff Kirsher temp = readl((mem_crb + TEST_AGT_CTRL)); 1538aa43c215SJeff Kirsher if ((temp & TA_CTL_BUSY) == 0) 1539aa43c215SJeff Kirsher break; 1540aa43c215SJeff Kirsher } 1541aa43c215SJeff Kirsher 1542aa43c215SJeff Kirsher if (j >= MAX_CTL_CHECK) { 1543aa43c215SJeff Kirsher if (printk_ratelimit()) 1544aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1545aa43c215SJeff Kirsher "failed to write through agent\n"); 1546aa43c215SJeff Kirsher ret = -EIO; 1547aa43c215SJeff Kirsher } else 1548aa43c215SJeff Kirsher ret = 0; 1549aa43c215SJeff Kirsher 1550aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); 1551aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1552aa43c215SJeff Kirsher return ret; 1553aa43c215SJeff Kirsher } 1554aa43c215SJeff Kirsher 1555aa43c215SJeff Kirsher static int 1556aa43c215SJeff Kirsher netxen_nic_pci_mem_read_128M(struct netxen_adapter *adapter, 1557aa43c215SJeff Kirsher u64 off, u64 *data) 1558aa43c215SJeff Kirsher { 1559aa43c215SJeff Kirsher int j, ret; 1560aa43c215SJeff Kirsher u32 temp, off_lo, off_hi, addr_hi, data_hi, data_lo; 1561aa43c215SJeff Kirsher u64 val; 1562aa43c215SJeff Kirsher void __iomem *mem_crb; 1563aa43c215SJeff Kirsher 1564aa43c215SJeff Kirsher /* Only 64-bit aligned access */ 1565aa43c215SJeff Kirsher if (off & 7) 1566aa43c215SJeff Kirsher return -EIO; 1567aa43c215SJeff Kirsher 1568aa43c215SJeff Kirsher /* P2 has different SIU and MIU test agent base addr */ 1569aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, 1570aa43c215SJeff Kirsher NETXEN_ADDR_QDR_NET_MAX_P2)) { 1571aa43c215SJeff Kirsher mem_crb = pci_base_offset(adapter, 1572aa43c215SJeff Kirsher NETXEN_CRB_QDR_NET+SIU_TEST_AGT_BASE); 1573aa43c215SJeff Kirsher addr_hi = SIU_TEST_AGT_ADDR_HI; 1574aa43c215SJeff Kirsher data_lo = SIU_TEST_AGT_RDDATA_LO; 1575aa43c215SJeff Kirsher data_hi = SIU_TEST_AGT_RDDATA_HI; 1576aa43c215SJeff Kirsher off_lo = off & SIU_TEST_AGT_ADDR_MASK; 1577aa43c215SJeff Kirsher off_hi = SIU_TEST_AGT_UPPER_ADDR(off); 1578aa43c215SJeff Kirsher goto correct; 1579aa43c215SJeff Kirsher } 1580aa43c215SJeff Kirsher 1581aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { 1582aa43c215SJeff Kirsher mem_crb = pci_base_offset(adapter, 1583aa43c215SJeff Kirsher NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); 1584aa43c215SJeff Kirsher addr_hi = MIU_TEST_AGT_ADDR_HI; 1585aa43c215SJeff Kirsher data_lo = MIU_TEST_AGT_RDDATA_LO; 1586aa43c215SJeff Kirsher data_hi = MIU_TEST_AGT_RDDATA_HI; 1587aa43c215SJeff Kirsher off_lo = off & MIU_TEST_AGT_ADDR_MASK; 1588aa43c215SJeff Kirsher off_hi = 0; 1589aa43c215SJeff Kirsher goto correct; 1590aa43c215SJeff Kirsher } 1591aa43c215SJeff Kirsher 1592aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX) || 1593aa43c215SJeff Kirsher ADDR_IN_RANGE(off, NETXEN_ADDR_OCM1, NETXEN_ADDR_OCM1_MAX)) { 1594aa43c215SJeff Kirsher if (adapter->ahw.pci_len0 != 0) { 1595aa43c215SJeff Kirsher return netxen_nic_pci_mem_access_direct(adapter, 1596aa43c215SJeff Kirsher off, data, 0); 1597aa43c215SJeff Kirsher } 1598aa43c215SJeff Kirsher } 1599aa43c215SJeff Kirsher 1600aa43c215SJeff Kirsher return -EIO; 1601aa43c215SJeff Kirsher 1602aa43c215SJeff Kirsher correct: 1603aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1604aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, 0); 1605aa43c215SJeff Kirsher 1606aa43c215SJeff Kirsher writel(off_lo, (mem_crb + MIU_TEST_AGT_ADDR_LO)); 1607aa43c215SJeff Kirsher writel(off_hi, (mem_crb + addr_hi)); 1608aa43c215SJeff Kirsher writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); 1609aa43c215SJeff Kirsher writel((TA_CTL_START|TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); 1610aa43c215SJeff Kirsher 1611aa43c215SJeff Kirsher for (j = 0; j < MAX_CTL_CHECK; j++) { 1612aa43c215SJeff Kirsher temp = readl(mem_crb + TEST_AGT_CTRL); 1613aa43c215SJeff Kirsher if ((temp & TA_CTL_BUSY) == 0) 1614aa43c215SJeff Kirsher break; 1615aa43c215SJeff Kirsher } 1616aa43c215SJeff Kirsher 1617aa43c215SJeff Kirsher if (j >= MAX_CTL_CHECK) { 1618aa43c215SJeff Kirsher if (printk_ratelimit()) 1619aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1620aa43c215SJeff Kirsher "failed to read through agent\n"); 1621aa43c215SJeff Kirsher ret = -EIO; 1622aa43c215SJeff Kirsher } else { 1623aa43c215SJeff Kirsher 1624aa43c215SJeff Kirsher temp = readl(mem_crb + data_hi); 1625aa43c215SJeff Kirsher val = ((u64)temp << 32); 1626aa43c215SJeff Kirsher val |= readl(mem_crb + data_lo); 1627aa43c215SJeff Kirsher *data = val; 1628aa43c215SJeff Kirsher ret = 0; 1629aa43c215SJeff Kirsher } 1630aa43c215SJeff Kirsher 1631aa43c215SJeff Kirsher netxen_nic_pci_set_crbwindow_128M(adapter, NETXEN_WINDOW_ONE); 1632aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1633aa43c215SJeff Kirsher 1634aa43c215SJeff Kirsher return ret; 1635aa43c215SJeff Kirsher } 1636aa43c215SJeff Kirsher 1637aa43c215SJeff Kirsher static int 1638aa43c215SJeff Kirsher netxen_nic_pci_mem_write_2M(struct netxen_adapter *adapter, 1639aa43c215SJeff Kirsher u64 off, u64 data) 1640aa43c215SJeff Kirsher { 1641aa43c215SJeff Kirsher int j, ret; 1642aa43c215SJeff Kirsher u32 temp, off8; 1643aa43c215SJeff Kirsher void __iomem *mem_crb; 1644aa43c215SJeff Kirsher 1645aa43c215SJeff Kirsher /* Only 64-bit aligned access */ 1646aa43c215SJeff Kirsher if (off & 7) 1647aa43c215SJeff Kirsher return -EIO; 1648aa43c215SJeff Kirsher 1649aa43c215SJeff Kirsher /* P3 onward, test agent base for MIU and SIU is same */ 1650aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, 1651aa43c215SJeff Kirsher NETXEN_ADDR_QDR_NET_MAX_P3)) { 1652aa43c215SJeff Kirsher mem_crb = netxen_get_ioaddr(adapter, 1653aa43c215SJeff Kirsher NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); 1654aa43c215SJeff Kirsher goto correct; 1655aa43c215SJeff Kirsher } 1656aa43c215SJeff Kirsher 1657aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { 1658aa43c215SJeff Kirsher mem_crb = netxen_get_ioaddr(adapter, 1659aa43c215SJeff Kirsher NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); 1660aa43c215SJeff Kirsher goto correct; 1661aa43c215SJeff Kirsher } 1662aa43c215SJeff Kirsher 1663aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) 1664aa43c215SJeff Kirsher return netxen_nic_pci_mem_access_direct(adapter, off, &data, 1); 1665aa43c215SJeff Kirsher 1666aa43c215SJeff Kirsher return -EIO; 1667aa43c215SJeff Kirsher 1668aa43c215SJeff Kirsher correct: 1669aa43c215SJeff Kirsher off8 = off & 0xfffffff8; 1670aa43c215SJeff Kirsher 1671aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1672aa43c215SJeff Kirsher 1673aa43c215SJeff Kirsher writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); 1674aa43c215SJeff Kirsher writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); 1675aa43c215SJeff Kirsher 1676aa43c215SJeff Kirsher writel(data & 0xffffffff, 1677aa43c215SJeff Kirsher mem_crb + MIU_TEST_AGT_WRDATA_LO); 1678aa43c215SJeff Kirsher writel((data >> 32) & 0xffffffff, 1679aa43c215SJeff Kirsher mem_crb + MIU_TEST_AGT_WRDATA_HI); 1680aa43c215SJeff Kirsher 1681aa43c215SJeff Kirsher writel((TA_CTL_ENABLE | TA_CTL_WRITE), (mem_crb + TEST_AGT_CTRL)); 1682aa43c215SJeff Kirsher writel((TA_CTL_START | TA_CTL_ENABLE | TA_CTL_WRITE), 1683aa43c215SJeff Kirsher (mem_crb + TEST_AGT_CTRL)); 1684aa43c215SJeff Kirsher 1685aa43c215SJeff Kirsher for (j = 0; j < MAX_CTL_CHECK; j++) { 1686aa43c215SJeff Kirsher temp = readl(mem_crb + TEST_AGT_CTRL); 1687aa43c215SJeff Kirsher if ((temp & TA_CTL_BUSY) == 0) 1688aa43c215SJeff Kirsher break; 1689aa43c215SJeff Kirsher } 1690aa43c215SJeff Kirsher 1691aa43c215SJeff Kirsher if (j >= MAX_CTL_CHECK) { 1692aa43c215SJeff Kirsher if (printk_ratelimit()) 1693aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1694aa43c215SJeff Kirsher "failed to write through agent\n"); 1695aa43c215SJeff Kirsher ret = -EIO; 1696aa43c215SJeff Kirsher } else 1697aa43c215SJeff Kirsher ret = 0; 1698aa43c215SJeff Kirsher 1699aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1700aa43c215SJeff Kirsher 1701aa43c215SJeff Kirsher return ret; 1702aa43c215SJeff Kirsher } 1703aa43c215SJeff Kirsher 1704aa43c215SJeff Kirsher static int 1705aa43c215SJeff Kirsher netxen_nic_pci_mem_read_2M(struct netxen_adapter *adapter, 1706aa43c215SJeff Kirsher u64 off, u64 *data) 1707aa43c215SJeff Kirsher { 1708aa43c215SJeff Kirsher int j, ret; 1709aa43c215SJeff Kirsher u32 temp, off8; 1710aa43c215SJeff Kirsher u64 val; 1711aa43c215SJeff Kirsher void __iomem *mem_crb; 1712aa43c215SJeff Kirsher 1713aa43c215SJeff Kirsher /* Only 64-bit aligned access */ 1714aa43c215SJeff Kirsher if (off & 7) 1715aa43c215SJeff Kirsher return -EIO; 1716aa43c215SJeff Kirsher 1717aa43c215SJeff Kirsher /* P3 onward, test agent base for MIU and SIU is same */ 1718aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_QDR_NET, 1719aa43c215SJeff Kirsher NETXEN_ADDR_QDR_NET_MAX_P3)) { 1720aa43c215SJeff Kirsher mem_crb = netxen_get_ioaddr(adapter, 1721aa43c215SJeff Kirsher NETXEN_CRB_QDR_NET+MIU_TEST_AGT_BASE); 1722aa43c215SJeff Kirsher goto correct; 1723aa43c215SJeff Kirsher } 1724aa43c215SJeff Kirsher 1725aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_DDR_NET, NETXEN_ADDR_DDR_NET_MAX)) { 1726aa43c215SJeff Kirsher mem_crb = netxen_get_ioaddr(adapter, 1727aa43c215SJeff Kirsher NETXEN_CRB_DDR_NET+MIU_TEST_AGT_BASE); 1728aa43c215SJeff Kirsher goto correct; 1729aa43c215SJeff Kirsher } 1730aa43c215SJeff Kirsher 1731aa43c215SJeff Kirsher if (ADDR_IN_RANGE(off, NETXEN_ADDR_OCM0, NETXEN_ADDR_OCM0_MAX)) { 1732aa43c215SJeff Kirsher return netxen_nic_pci_mem_access_direct(adapter, 1733aa43c215SJeff Kirsher off, data, 0); 1734aa43c215SJeff Kirsher } 1735aa43c215SJeff Kirsher 1736aa43c215SJeff Kirsher return -EIO; 1737aa43c215SJeff Kirsher 1738aa43c215SJeff Kirsher correct: 1739aa43c215SJeff Kirsher off8 = off & 0xfffffff8; 1740aa43c215SJeff Kirsher 1741aa43c215SJeff Kirsher spin_lock(&adapter->ahw.mem_lock); 1742aa43c215SJeff Kirsher 1743aa43c215SJeff Kirsher writel(off8, (mem_crb + MIU_TEST_AGT_ADDR_LO)); 1744aa43c215SJeff Kirsher writel(0, (mem_crb + MIU_TEST_AGT_ADDR_HI)); 1745aa43c215SJeff Kirsher writel(TA_CTL_ENABLE, (mem_crb + TEST_AGT_CTRL)); 1746aa43c215SJeff Kirsher writel((TA_CTL_START | TA_CTL_ENABLE), (mem_crb + TEST_AGT_CTRL)); 1747aa43c215SJeff Kirsher 1748aa43c215SJeff Kirsher for (j = 0; j < MAX_CTL_CHECK; j++) { 1749aa43c215SJeff Kirsher temp = readl(mem_crb + TEST_AGT_CTRL); 1750aa43c215SJeff Kirsher if ((temp & TA_CTL_BUSY) == 0) 1751aa43c215SJeff Kirsher break; 1752aa43c215SJeff Kirsher } 1753aa43c215SJeff Kirsher 1754aa43c215SJeff Kirsher if (j >= MAX_CTL_CHECK) { 1755aa43c215SJeff Kirsher if (printk_ratelimit()) 1756aa43c215SJeff Kirsher dev_err(&adapter->pdev->dev, 1757aa43c215SJeff Kirsher "failed to read through agent\n"); 1758aa43c215SJeff Kirsher ret = -EIO; 1759aa43c215SJeff Kirsher } else { 1760aa43c215SJeff Kirsher val = (u64)(readl(mem_crb + MIU_TEST_AGT_RDDATA_HI)) << 32; 1761aa43c215SJeff Kirsher val |= readl(mem_crb + MIU_TEST_AGT_RDDATA_LO); 1762aa43c215SJeff Kirsher *data = val; 1763aa43c215SJeff Kirsher ret = 0; 1764aa43c215SJeff Kirsher } 1765aa43c215SJeff Kirsher 1766aa43c215SJeff Kirsher spin_unlock(&adapter->ahw.mem_lock); 1767aa43c215SJeff Kirsher 1768aa43c215SJeff Kirsher return ret; 1769aa43c215SJeff Kirsher } 1770aa43c215SJeff Kirsher 1771aa43c215SJeff Kirsher void 1772aa43c215SJeff Kirsher netxen_setup_hwops(struct netxen_adapter *adapter) 1773aa43c215SJeff Kirsher { 1774aa43c215SJeff Kirsher adapter->init_port = netxen_niu_xg_init_port; 1775aa43c215SJeff Kirsher adapter->stop_port = netxen_niu_disable_xg_port; 1776aa43c215SJeff Kirsher 1777aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { 1778aa43c215SJeff Kirsher adapter->crb_read = netxen_nic_hw_read_wx_128M, 1779aa43c215SJeff Kirsher adapter->crb_write = netxen_nic_hw_write_wx_128M, 1780aa43c215SJeff Kirsher adapter->pci_set_window = netxen_nic_pci_set_window_128M, 1781aa43c215SJeff Kirsher adapter->pci_mem_read = netxen_nic_pci_mem_read_128M, 1782aa43c215SJeff Kirsher adapter->pci_mem_write = netxen_nic_pci_mem_write_128M, 1783aa43c215SJeff Kirsher adapter->io_read = netxen_nic_io_read_128M, 1784aa43c215SJeff Kirsher adapter->io_write = netxen_nic_io_write_128M, 1785aa43c215SJeff Kirsher 1786aa43c215SJeff Kirsher adapter->macaddr_set = netxen_p2_nic_set_mac_addr; 1787aa43c215SJeff Kirsher adapter->set_multi = netxen_p2_nic_set_multi; 1788aa43c215SJeff Kirsher adapter->set_mtu = netxen_nic_set_mtu_xgb; 1789aa43c215SJeff Kirsher adapter->set_promisc = netxen_p2_nic_set_promisc; 1790aa43c215SJeff Kirsher 1791aa43c215SJeff Kirsher } else { 1792aa43c215SJeff Kirsher adapter->crb_read = netxen_nic_hw_read_wx_2M, 1793aa43c215SJeff Kirsher adapter->crb_write = netxen_nic_hw_write_wx_2M, 1794aa43c215SJeff Kirsher adapter->pci_set_window = netxen_nic_pci_set_window_2M, 1795aa43c215SJeff Kirsher adapter->pci_mem_read = netxen_nic_pci_mem_read_2M, 1796aa43c215SJeff Kirsher adapter->pci_mem_write = netxen_nic_pci_mem_write_2M, 1797aa43c215SJeff Kirsher adapter->io_read = netxen_nic_io_read_2M, 1798aa43c215SJeff Kirsher adapter->io_write = netxen_nic_io_write_2M, 1799aa43c215SJeff Kirsher 1800aa43c215SJeff Kirsher adapter->set_mtu = nx_fw_cmd_set_mtu; 1801aa43c215SJeff Kirsher adapter->set_promisc = netxen_p3_nic_set_promisc; 1802aa43c215SJeff Kirsher adapter->macaddr_set = netxen_p3_nic_set_mac_addr; 1803aa43c215SJeff Kirsher adapter->set_multi = netxen_p3_nic_set_multi; 1804aa43c215SJeff Kirsher 1805aa43c215SJeff Kirsher adapter->phy_read = nx_fw_cmd_query_phy; 1806aa43c215SJeff Kirsher adapter->phy_write = nx_fw_cmd_set_phy; 1807aa43c215SJeff Kirsher } 1808aa43c215SJeff Kirsher } 1809aa43c215SJeff Kirsher 1810aa43c215SJeff Kirsher int netxen_nic_get_board_info(struct netxen_adapter *adapter) 1811aa43c215SJeff Kirsher { 1812aa43c215SJeff Kirsher int offset, board_type, magic; 1813aa43c215SJeff Kirsher struct pci_dev *pdev = adapter->pdev; 1814aa43c215SJeff Kirsher 1815aa43c215SJeff Kirsher offset = NX_FW_MAGIC_OFFSET; 1816aa43c215SJeff Kirsher if (netxen_rom_fast_read(adapter, offset, &magic)) 1817aa43c215SJeff Kirsher return -EIO; 1818aa43c215SJeff Kirsher 1819aa43c215SJeff Kirsher if (magic != NETXEN_BDINFO_MAGIC) { 1820aa43c215SJeff Kirsher dev_err(&pdev->dev, "invalid board config, magic=%08x\n", 1821aa43c215SJeff Kirsher magic); 1822aa43c215SJeff Kirsher return -EIO; 1823aa43c215SJeff Kirsher } 1824aa43c215SJeff Kirsher 1825aa43c215SJeff Kirsher offset = NX_BRDTYPE_OFFSET; 1826aa43c215SJeff Kirsher if (netxen_rom_fast_read(adapter, offset, &board_type)) 1827aa43c215SJeff Kirsher return -EIO; 1828aa43c215SJeff Kirsher 1829aa43c215SJeff Kirsher if (board_type == NETXEN_BRDTYPE_P3_4_GB_MM) { 1830aa43c215SJeff Kirsher u32 gpio = NXRD32(adapter, NETXEN_ROMUSB_GLB_PAD_GPIO_I); 1831aa43c215SJeff Kirsher if ((gpio & 0x8000) == 0) 1832aa43c215SJeff Kirsher board_type = NETXEN_BRDTYPE_P3_10G_TP; 1833aa43c215SJeff Kirsher } 1834aa43c215SJeff Kirsher 1835aa43c215SJeff Kirsher adapter->ahw.board_type = board_type; 1836aa43c215SJeff Kirsher 1837aa43c215SJeff Kirsher switch (board_type) { 1838aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB35_4G: 1839aa43c215SJeff Kirsher adapter->ahw.port_type = NETXEN_NIC_GBE; 1840aa43c215SJeff Kirsher break; 1841aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G: 1842aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ: 1843aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ: 1844aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P2_SB31_10G_CX4: 1845aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_HMEZ: 1846aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_XG_LOM: 1847aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_CX4: 1848aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_CX4_LP: 1849aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_IMEZ: 1850aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_PLUS: 1851aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_CT: 1852aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_SFP_QT: 1853aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_XFP: 1854aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10000_BASE_T: 1855aa43c215SJeff Kirsher adapter->ahw.port_type = NETXEN_NIC_XGBE; 1856aa43c215SJeff Kirsher break; 1857aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P1_BD: 1858aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P1_SB: 1859aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P1_SMAX: 1860aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P1_SOCK: 1861aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_REF_QG: 1862aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_4_GB: 1863aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_4_GB_MM: 1864aa43c215SJeff Kirsher adapter->ahw.port_type = NETXEN_NIC_GBE; 1865aa43c215SJeff Kirsher break; 1866aa43c215SJeff Kirsher case NETXEN_BRDTYPE_P3_10G_TP: 1867aa43c215SJeff Kirsher adapter->ahw.port_type = (adapter->portnum < 2) ? 1868aa43c215SJeff Kirsher NETXEN_NIC_XGBE : NETXEN_NIC_GBE; 1869aa43c215SJeff Kirsher break; 1870aa43c215SJeff Kirsher default: 1871aa43c215SJeff Kirsher dev_err(&pdev->dev, "unknown board type %x\n", board_type); 1872aa43c215SJeff Kirsher adapter->ahw.port_type = NETXEN_NIC_XGBE; 1873aa43c215SJeff Kirsher break; 1874aa43c215SJeff Kirsher } 1875aa43c215SJeff Kirsher 1876aa43c215SJeff Kirsher return 0; 1877aa43c215SJeff Kirsher } 1878aa43c215SJeff Kirsher 1879aa43c215SJeff Kirsher /* NIU access sections */ 1880aa43c215SJeff Kirsher static int netxen_nic_set_mtu_xgb(struct netxen_adapter *adapter, int new_mtu) 1881aa43c215SJeff Kirsher { 1882aa43c215SJeff Kirsher new_mtu += MTU_FUDGE_FACTOR; 1883aa43c215SJeff Kirsher if (adapter->physical_port == 0) 1884aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XGE_MAX_FRAME_SIZE, new_mtu); 1885aa43c215SJeff Kirsher else 1886aa43c215SJeff Kirsher NXWR32(adapter, NETXEN_NIU_XG1_MAX_FRAME_SIZE, new_mtu); 1887aa43c215SJeff Kirsher return 0; 1888aa43c215SJeff Kirsher } 1889aa43c215SJeff Kirsher 1890aa43c215SJeff Kirsher void netxen_nic_set_link_parameters(struct netxen_adapter *adapter) 1891aa43c215SJeff Kirsher { 1892aa43c215SJeff Kirsher __u32 status; 1893aa43c215SJeff Kirsher __u32 autoneg; 1894aa43c215SJeff Kirsher __u32 port_mode; 1895aa43c215SJeff Kirsher 1896aa43c215SJeff Kirsher if (!netif_carrier_ok(adapter->netdev)) { 1897aa43c215SJeff Kirsher adapter->link_speed = 0; 1898aa43c215SJeff Kirsher adapter->link_duplex = -1; 1899aa43c215SJeff Kirsher adapter->link_autoneg = AUTONEG_ENABLE; 1900aa43c215SJeff Kirsher return; 1901aa43c215SJeff Kirsher } 1902aa43c215SJeff Kirsher 1903aa43c215SJeff Kirsher if (adapter->ahw.port_type == NETXEN_NIC_GBE) { 1904aa43c215SJeff Kirsher port_mode = NXRD32(adapter, NETXEN_PORT_MODE_ADDR); 1905aa43c215SJeff Kirsher if (port_mode == NETXEN_PORT_MODE_802_3_AP) { 1906aa43c215SJeff Kirsher adapter->link_speed = SPEED_1000; 1907aa43c215SJeff Kirsher adapter->link_duplex = DUPLEX_FULL; 1908aa43c215SJeff Kirsher adapter->link_autoneg = AUTONEG_DISABLE; 1909aa43c215SJeff Kirsher return; 1910aa43c215SJeff Kirsher } 1911aa43c215SJeff Kirsher 1912aa43c215SJeff Kirsher if (adapter->phy_read && 1913aa43c215SJeff Kirsher adapter->phy_read(adapter, 1914aa43c215SJeff Kirsher NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS, 1915aa43c215SJeff Kirsher &status) == 0) { 1916aa43c215SJeff Kirsher if (netxen_get_phy_link(status)) { 1917aa43c215SJeff Kirsher switch (netxen_get_phy_speed(status)) { 1918aa43c215SJeff Kirsher case 0: 1919aa43c215SJeff Kirsher adapter->link_speed = SPEED_10; 1920aa43c215SJeff Kirsher break; 1921aa43c215SJeff Kirsher case 1: 1922aa43c215SJeff Kirsher adapter->link_speed = SPEED_100; 1923aa43c215SJeff Kirsher break; 1924aa43c215SJeff Kirsher case 2: 1925aa43c215SJeff Kirsher adapter->link_speed = SPEED_1000; 1926aa43c215SJeff Kirsher break; 1927aa43c215SJeff Kirsher default: 1928aa43c215SJeff Kirsher adapter->link_speed = 0; 1929aa43c215SJeff Kirsher break; 1930aa43c215SJeff Kirsher } 1931aa43c215SJeff Kirsher switch (netxen_get_phy_duplex(status)) { 1932aa43c215SJeff Kirsher case 0: 1933aa43c215SJeff Kirsher adapter->link_duplex = DUPLEX_HALF; 1934aa43c215SJeff Kirsher break; 1935aa43c215SJeff Kirsher case 1: 1936aa43c215SJeff Kirsher adapter->link_duplex = DUPLEX_FULL; 1937aa43c215SJeff Kirsher break; 1938aa43c215SJeff Kirsher default: 1939aa43c215SJeff Kirsher adapter->link_duplex = -1; 1940aa43c215SJeff Kirsher break; 1941aa43c215SJeff Kirsher } 1942aa43c215SJeff Kirsher if (adapter->phy_read && 1943aa43c215SJeff Kirsher adapter->phy_read(adapter, 1944aa43c215SJeff Kirsher NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG, 1945aa43c215SJeff Kirsher &autoneg) != 0) 1946aa43c215SJeff Kirsher adapter->link_autoneg = autoneg; 1947aa43c215SJeff Kirsher } else 1948aa43c215SJeff Kirsher goto link_down; 1949aa43c215SJeff Kirsher } else { 1950aa43c215SJeff Kirsher link_down: 1951aa43c215SJeff Kirsher adapter->link_speed = 0; 1952aa43c215SJeff Kirsher adapter->link_duplex = -1; 1953aa43c215SJeff Kirsher } 1954aa43c215SJeff Kirsher } 1955aa43c215SJeff Kirsher } 1956aa43c215SJeff Kirsher 1957aa43c215SJeff Kirsher int 1958aa43c215SJeff Kirsher netxen_nic_wol_supported(struct netxen_adapter *adapter) 1959aa43c215SJeff Kirsher { 1960aa43c215SJeff Kirsher u32 wol_cfg; 1961aa43c215SJeff Kirsher 1962aa43c215SJeff Kirsher if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) 1963aa43c215SJeff Kirsher return 0; 1964aa43c215SJeff Kirsher 1965aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV); 1966aa43c215SJeff Kirsher if (wol_cfg & (1UL << adapter->portnum)) { 1967aa43c215SJeff Kirsher wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG); 1968aa43c215SJeff Kirsher if (wol_cfg & (1 << adapter->portnum)) 1969aa43c215SJeff Kirsher return 1; 1970aa43c215SJeff Kirsher } 1971aa43c215SJeff Kirsher 1972aa43c215SJeff Kirsher return 0; 1973aa43c215SJeff Kirsher } 197483f18a55SManish chopra 197583f18a55SManish chopra static u32 netxen_md_cntrl(struct netxen_adapter *adapter, 197683f18a55SManish chopra struct netxen_minidump_template_hdr *template_hdr, 197783f18a55SManish chopra struct netxen_minidump_entry_crb *crtEntry) 197883f18a55SManish chopra { 197983f18a55SManish chopra int loop_cnt, i, rv = 0, timeout_flag; 198083f18a55SManish chopra u32 op_count, stride; 198183f18a55SManish chopra u32 opcode, read_value, addr; 198283f18a55SManish chopra unsigned long timeout, timeout_jiffies; 198383f18a55SManish chopra addr = crtEntry->addr; 198483f18a55SManish chopra op_count = crtEntry->op_count; 198583f18a55SManish chopra stride = crtEntry->addr_stride; 198683f18a55SManish chopra 198783f18a55SManish chopra for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) { 198883f18a55SManish chopra for (i = 0; i < sizeof(crtEntry->opcode) * 8; i++) { 198983f18a55SManish chopra opcode = (crtEntry->opcode & (0x1 << i)); 199083f18a55SManish chopra if (opcode) { 199183f18a55SManish chopra switch (opcode) { 199283f18a55SManish chopra case NX_DUMP_WCRB: 199383f18a55SManish chopra NX_WR_DUMP_REG(addr, 199483f18a55SManish chopra adapter->ahw.pci_base0, 199583f18a55SManish chopra crtEntry->value_1); 199683f18a55SManish chopra break; 199783f18a55SManish chopra case NX_DUMP_RWCRB: 199883f18a55SManish chopra NX_RD_DUMP_REG(addr, 199983f18a55SManish chopra adapter->ahw.pci_base0, 200083f18a55SManish chopra &read_value); 200183f18a55SManish chopra NX_WR_DUMP_REG(addr, 200283f18a55SManish chopra adapter->ahw.pci_base0, 200383f18a55SManish chopra read_value); 200483f18a55SManish chopra break; 200583f18a55SManish chopra case NX_DUMP_ANDCRB: 200683f18a55SManish chopra NX_RD_DUMP_REG(addr, 200783f18a55SManish chopra adapter->ahw.pci_base0, 200883f18a55SManish chopra &read_value); 200983f18a55SManish chopra read_value &= crtEntry->value_2; 201083f18a55SManish chopra NX_WR_DUMP_REG(addr, 201183f18a55SManish chopra adapter->ahw.pci_base0, 201283f18a55SManish chopra read_value); 201383f18a55SManish chopra break; 201483f18a55SManish chopra case NX_DUMP_ORCRB: 201583f18a55SManish chopra NX_RD_DUMP_REG(addr, 201683f18a55SManish chopra adapter->ahw.pci_base0, 201783f18a55SManish chopra &read_value); 201883f18a55SManish chopra read_value |= crtEntry->value_3; 201983f18a55SManish chopra NX_WR_DUMP_REG(addr, 202083f18a55SManish chopra adapter->ahw.pci_base0, 202183f18a55SManish chopra read_value); 202283f18a55SManish chopra break; 202383f18a55SManish chopra case NX_DUMP_POLLCRB: 202483f18a55SManish chopra timeout = crtEntry->poll_timeout; 202583f18a55SManish chopra NX_RD_DUMP_REG(addr, 202683f18a55SManish chopra adapter->ahw.pci_base0, 202783f18a55SManish chopra &read_value); 202883f18a55SManish chopra timeout_jiffies = 202983f18a55SManish chopra msecs_to_jiffies(timeout) + jiffies; 203083f18a55SManish chopra for (timeout_flag = 0; 203183f18a55SManish chopra !timeout_flag 203283f18a55SManish chopra && ((read_value & crtEntry->value_2) 203383f18a55SManish chopra != crtEntry->value_1);) { 203483f18a55SManish chopra if (time_after(jiffies, 203583f18a55SManish chopra timeout_jiffies)) 203683f18a55SManish chopra timeout_flag = 1; 203783f18a55SManish chopra NX_RD_DUMP_REG(addr, 203883f18a55SManish chopra adapter->ahw.pci_base0, 203983f18a55SManish chopra &read_value); 204083f18a55SManish chopra } 204183f18a55SManish chopra 204283f18a55SManish chopra if (timeout_flag) { 204383f18a55SManish chopra dev_err(&adapter->pdev->dev, "%s : " 204483f18a55SManish chopra "Timeout in poll_crb control operation.\n" 204583f18a55SManish chopra , __func__); 204683f18a55SManish chopra return -1; 204783f18a55SManish chopra } 204883f18a55SManish chopra break; 204983f18a55SManish chopra case NX_DUMP_RD_SAVE: 205083f18a55SManish chopra /* Decide which address to use */ 205183f18a55SManish chopra if (crtEntry->state_index_a) 205283f18a55SManish chopra addr = 205383f18a55SManish chopra template_hdr->saved_state_array 205483f18a55SManish chopra [crtEntry->state_index_a]; 205583f18a55SManish chopra NX_RD_DUMP_REG(addr, 205683f18a55SManish chopra adapter->ahw.pci_base0, 205783f18a55SManish chopra &read_value); 205883f18a55SManish chopra template_hdr->saved_state_array 205983f18a55SManish chopra [crtEntry->state_index_v] 206083f18a55SManish chopra = read_value; 206183f18a55SManish chopra break; 206283f18a55SManish chopra case NX_DUMP_WRT_SAVED: 206383f18a55SManish chopra /* Decide which value to use */ 206483f18a55SManish chopra if (crtEntry->state_index_v) 206583f18a55SManish chopra read_value = 206683f18a55SManish chopra template_hdr->saved_state_array 206783f18a55SManish chopra [crtEntry->state_index_v]; 206883f18a55SManish chopra else 206983f18a55SManish chopra read_value = crtEntry->value_1; 207083f18a55SManish chopra 207183f18a55SManish chopra /* Decide which address to use */ 207283f18a55SManish chopra if (crtEntry->state_index_a) 207383f18a55SManish chopra addr = 207483f18a55SManish chopra template_hdr->saved_state_array 207583f18a55SManish chopra [crtEntry->state_index_a]; 207683f18a55SManish chopra 207783f18a55SManish chopra NX_WR_DUMP_REG(addr, 207883f18a55SManish chopra adapter->ahw.pci_base0, 207983f18a55SManish chopra read_value); 208083f18a55SManish chopra break; 208183f18a55SManish chopra case NX_DUMP_MOD_SAVE_ST: 208283f18a55SManish chopra read_value = 208383f18a55SManish chopra template_hdr->saved_state_array 208483f18a55SManish chopra [crtEntry->state_index_v]; 208583f18a55SManish chopra read_value <<= crtEntry->shl; 208683f18a55SManish chopra read_value >>= crtEntry->shr; 208783f18a55SManish chopra if (crtEntry->value_2) 208883f18a55SManish chopra read_value &= 208983f18a55SManish chopra crtEntry->value_2; 209083f18a55SManish chopra read_value |= crtEntry->value_3; 209183f18a55SManish chopra read_value += crtEntry->value_1; 209283f18a55SManish chopra /* Write value back to state area.*/ 209383f18a55SManish chopra template_hdr->saved_state_array 209483f18a55SManish chopra [crtEntry->state_index_v] 209583f18a55SManish chopra = read_value; 209683f18a55SManish chopra break; 209783f18a55SManish chopra default: 209883f18a55SManish chopra rv = 1; 209983f18a55SManish chopra break; 210083f18a55SManish chopra } 210183f18a55SManish chopra } 210283f18a55SManish chopra } 210383f18a55SManish chopra addr = addr + stride; 210483f18a55SManish chopra } 210583f18a55SManish chopra return rv; 210683f18a55SManish chopra } 210783f18a55SManish chopra 210883f18a55SManish chopra /* Read memory or MN */ 210983f18a55SManish chopra static u32 211083f18a55SManish chopra netxen_md_rdmem(struct netxen_adapter *adapter, 211183f18a55SManish chopra struct netxen_minidump_entry_rdmem 211283f18a55SManish chopra *memEntry, u64 *data_buff) 211383f18a55SManish chopra { 211483f18a55SManish chopra u64 addr, value = 0; 211583f18a55SManish chopra int i = 0, loop_cnt; 211683f18a55SManish chopra 211783f18a55SManish chopra addr = (u64)memEntry->read_addr; 211883f18a55SManish chopra loop_cnt = memEntry->read_data_size; /* This is size in bytes */ 211983f18a55SManish chopra loop_cnt /= sizeof(value); 212083f18a55SManish chopra 212183f18a55SManish chopra for (i = 0; i < loop_cnt; i++) { 212283f18a55SManish chopra if (netxen_nic_pci_mem_read_2M(adapter, addr, &value)) 212383f18a55SManish chopra goto out; 212483f18a55SManish chopra *data_buff++ = value; 212583f18a55SManish chopra addr += sizeof(value); 212683f18a55SManish chopra } 212783f18a55SManish chopra out: 212883f18a55SManish chopra return i * sizeof(value); 212983f18a55SManish chopra } 213083f18a55SManish chopra 213183f18a55SManish chopra /* Read CRB operation */ 213283f18a55SManish chopra static u32 netxen_md_rd_crb(struct netxen_adapter *adapter, 213383f18a55SManish chopra struct netxen_minidump_entry_crb 213483f18a55SManish chopra *crbEntry, u32 *data_buff) 213583f18a55SManish chopra { 213683f18a55SManish chopra int loop_cnt; 213783f18a55SManish chopra u32 op_count, addr, stride, value; 213883f18a55SManish chopra 213983f18a55SManish chopra addr = crbEntry->addr; 214083f18a55SManish chopra op_count = crbEntry->op_count; 214183f18a55SManish chopra stride = crbEntry->addr_stride; 214283f18a55SManish chopra 214383f18a55SManish chopra for (loop_cnt = 0; loop_cnt < op_count; loop_cnt++) { 214483f18a55SManish chopra NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0, &value); 214583f18a55SManish chopra *data_buff++ = addr; 214683f18a55SManish chopra *data_buff++ = value; 214783f18a55SManish chopra addr = addr + stride; 214883f18a55SManish chopra } 214983f18a55SManish chopra return loop_cnt * (2 * sizeof(u32)); 215083f18a55SManish chopra } 215183f18a55SManish chopra 215283f18a55SManish chopra /* Read ROM */ 215383f18a55SManish chopra static u32 215483f18a55SManish chopra netxen_md_rdrom(struct netxen_adapter *adapter, 215583f18a55SManish chopra struct netxen_minidump_entry_rdrom 215606d6c108SSantosh Nayak *romEntry, __le32 *data_buff) 215783f18a55SManish chopra { 215883f18a55SManish chopra int i, count = 0; 215983f18a55SManish chopra u32 size, lck_val; 216083f18a55SManish chopra u32 val; 216183f18a55SManish chopra u32 fl_addr, waddr, raddr; 216283f18a55SManish chopra fl_addr = romEntry->read_addr; 216383f18a55SManish chopra size = romEntry->read_data_size/4; 216483f18a55SManish chopra lock_try: 216583f18a55SManish chopra lck_val = readl((void __iomem *)(adapter->ahw.pci_base0 + 216683f18a55SManish chopra NX_FLASH_SEM2_LK)); 216783f18a55SManish chopra if (!lck_val && count < MAX_CTL_CHECK) { 216883f18a55SManish chopra msleep(20); 216983f18a55SManish chopra count++; 217083f18a55SManish chopra goto lock_try; 217183f18a55SManish chopra } 217283f18a55SManish chopra writel(adapter->ahw.pci_func, (void __iomem *)(adapter->ahw.pci_base0 + 217383f18a55SManish chopra NX_FLASH_LOCK_ID)); 217483f18a55SManish chopra for (i = 0; i < size; i++) { 217583f18a55SManish chopra waddr = fl_addr & 0xFFFF0000; 217683f18a55SManish chopra NX_WR_DUMP_REG(FLASH_ROM_WINDOW, adapter->ahw.pci_base0, waddr); 217783f18a55SManish chopra raddr = FLASH_ROM_DATA + (fl_addr & 0x0000FFFF); 217883f18a55SManish chopra NX_RD_DUMP_REG(raddr, adapter->ahw.pci_base0, &val); 217983f18a55SManish chopra *data_buff++ = cpu_to_le32(val); 218083f18a55SManish chopra fl_addr += sizeof(val); 218183f18a55SManish chopra } 218283f18a55SManish chopra readl((void __iomem *)(adapter->ahw.pci_base0 + NX_FLASH_SEM2_ULK)); 218383f18a55SManish chopra return romEntry->read_data_size; 218483f18a55SManish chopra } 218583f18a55SManish chopra 218683f18a55SManish chopra /* Handle L2 Cache */ 218783f18a55SManish chopra static u32 218883f18a55SManish chopra netxen_md_L2Cache(struct netxen_adapter *adapter, 218983f18a55SManish chopra struct netxen_minidump_entry_cache 219083f18a55SManish chopra *cacheEntry, u32 *data_buff) 219183f18a55SManish chopra { 219283f18a55SManish chopra int loop_cnt, i, k, timeout_flag = 0; 219383f18a55SManish chopra u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr; 219483f18a55SManish chopra u32 tag_value, read_cnt; 219583f18a55SManish chopra u8 cntl_value_w, cntl_value_r; 219683f18a55SManish chopra unsigned long timeout, timeout_jiffies; 219783f18a55SManish chopra 219883f18a55SManish chopra loop_cnt = cacheEntry->op_count; 219983f18a55SManish chopra read_addr = cacheEntry->read_addr; 220083f18a55SManish chopra cntrl_addr = cacheEntry->control_addr; 220183f18a55SManish chopra cntl_value_w = (u32) cacheEntry->write_value; 220283f18a55SManish chopra tag_reg_addr = cacheEntry->tag_reg_addr; 220383f18a55SManish chopra tag_value = cacheEntry->init_tag_value; 220483f18a55SManish chopra read_cnt = cacheEntry->read_addr_cnt; 220583f18a55SManish chopra 220683f18a55SManish chopra for (i = 0; i < loop_cnt; i++) { 220783f18a55SManish chopra NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value); 220883f18a55SManish chopra if (cntl_value_w) 220983f18a55SManish chopra NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0, 221083f18a55SManish chopra (u32)cntl_value_w); 221183f18a55SManish chopra if (cacheEntry->poll_mask) { 221283f18a55SManish chopra timeout = cacheEntry->poll_wait; 221383f18a55SManish chopra NX_RD_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0, 221483f18a55SManish chopra &cntl_value_r); 221583f18a55SManish chopra timeout_jiffies = msecs_to_jiffies(timeout) + jiffies; 221683f18a55SManish chopra for (timeout_flag = 0; !timeout_flag && 221783f18a55SManish chopra ((cntl_value_r & cacheEntry->poll_mask) != 0);) { 221883f18a55SManish chopra if (time_after(jiffies, timeout_jiffies)) 221983f18a55SManish chopra timeout_flag = 1; 222083f18a55SManish chopra NX_RD_DUMP_REG(cntrl_addr, 222183f18a55SManish chopra adapter->ahw.pci_base0, 222283f18a55SManish chopra &cntl_value_r); 222383f18a55SManish chopra } 222483f18a55SManish chopra if (timeout_flag) { 222583f18a55SManish chopra dev_err(&adapter->pdev->dev, 222683f18a55SManish chopra "Timeout in processing L2 Tag poll.\n"); 222783f18a55SManish chopra return -1; 222883f18a55SManish chopra } 222983f18a55SManish chopra } 223083f18a55SManish chopra addr = read_addr; 223183f18a55SManish chopra for (k = 0; k < read_cnt; k++) { 223283f18a55SManish chopra NX_RD_DUMP_REG(addr, adapter->ahw.pci_base0, 223383f18a55SManish chopra &read_value); 223483f18a55SManish chopra *data_buff++ = read_value; 223583f18a55SManish chopra addr += cacheEntry->read_addr_stride; 223683f18a55SManish chopra } 223783f18a55SManish chopra tag_value += cacheEntry->tag_value_stride; 223883f18a55SManish chopra } 223983f18a55SManish chopra return read_cnt * loop_cnt * sizeof(read_value); 224083f18a55SManish chopra } 224183f18a55SManish chopra 224283f18a55SManish chopra 224383f18a55SManish chopra /* Handle L1 Cache */ 224483f18a55SManish chopra static u32 netxen_md_L1Cache(struct netxen_adapter *adapter, 224583f18a55SManish chopra struct netxen_minidump_entry_cache 224683f18a55SManish chopra *cacheEntry, u32 *data_buff) 224783f18a55SManish chopra { 224883f18a55SManish chopra int i, k, loop_cnt; 224983f18a55SManish chopra u32 addr, read_addr, read_value, cntrl_addr, tag_reg_addr; 225083f18a55SManish chopra u32 tag_value, read_cnt; 225183f18a55SManish chopra u8 cntl_value_w; 225283f18a55SManish chopra 225383f18a55SManish chopra loop_cnt = cacheEntry->op_count; 225483f18a55SManish chopra read_addr = cacheEntry->read_addr; 225583f18a55SManish chopra cntrl_addr = cacheEntry->control_addr; 225683f18a55SManish chopra cntl_value_w = (u32) cacheEntry->write_value; 225783f18a55SManish chopra tag_reg_addr = cacheEntry->tag_reg_addr; 225883f18a55SManish chopra tag_value = cacheEntry->init_tag_value; 225983f18a55SManish chopra read_cnt = cacheEntry->read_addr_cnt; 226083f18a55SManish chopra 226183f18a55SManish chopra for (i = 0; i < loop_cnt; i++) { 226283f18a55SManish chopra NX_WR_DUMP_REG(tag_reg_addr, adapter->ahw.pci_base0, tag_value); 226383f18a55SManish chopra NX_WR_DUMP_REG(cntrl_addr, adapter->ahw.pci_base0, 226483f18a55SManish chopra (u32) cntl_value_w); 226583f18a55SManish chopra addr = read_addr; 226683f18a55SManish chopra for (k = 0; k < read_cnt; k++) { 226783f18a55SManish chopra NX_RD_DUMP_REG(addr, 226883f18a55SManish chopra adapter->ahw.pci_base0, 226983f18a55SManish chopra &read_value); 227083f18a55SManish chopra *data_buff++ = read_value; 227183f18a55SManish chopra addr += cacheEntry->read_addr_stride; 227283f18a55SManish chopra } 227383f18a55SManish chopra tag_value += cacheEntry->tag_value_stride; 227483f18a55SManish chopra } 227583f18a55SManish chopra return read_cnt * loop_cnt * sizeof(read_value); 227683f18a55SManish chopra } 227783f18a55SManish chopra 227883f18a55SManish chopra /* Reading OCM memory */ 227983f18a55SManish chopra static u32 228083f18a55SManish chopra netxen_md_rdocm(struct netxen_adapter *adapter, 228183f18a55SManish chopra struct netxen_minidump_entry_rdocm 228283f18a55SManish chopra *ocmEntry, u32 *data_buff) 228383f18a55SManish chopra { 228483f18a55SManish chopra int i, loop_cnt; 228583f18a55SManish chopra u32 value; 228683f18a55SManish chopra void __iomem *addr; 228783f18a55SManish chopra addr = (ocmEntry->read_addr + adapter->ahw.pci_base0); 228883f18a55SManish chopra loop_cnt = ocmEntry->op_count; 228983f18a55SManish chopra 229083f18a55SManish chopra for (i = 0; i < loop_cnt; i++) { 229183f18a55SManish chopra value = readl(addr); 229283f18a55SManish chopra *data_buff++ = value; 229383f18a55SManish chopra addr += ocmEntry->read_addr_stride; 229483f18a55SManish chopra } 229583f18a55SManish chopra return i * sizeof(u32); 229683f18a55SManish chopra } 229783f18a55SManish chopra 229883f18a55SManish chopra /* Read MUX data */ 229983f18a55SManish chopra static u32 230083f18a55SManish chopra netxen_md_rdmux(struct netxen_adapter *adapter, struct netxen_minidump_entry_mux 230183f18a55SManish chopra *muxEntry, u32 *data_buff) 230283f18a55SManish chopra { 230383f18a55SManish chopra int loop_cnt = 0; 230483f18a55SManish chopra u32 read_addr, read_value, select_addr, sel_value; 230583f18a55SManish chopra 230683f18a55SManish chopra read_addr = muxEntry->read_addr; 230783f18a55SManish chopra sel_value = muxEntry->select_value; 230883f18a55SManish chopra select_addr = muxEntry->select_addr; 230983f18a55SManish chopra 231083f18a55SManish chopra for (loop_cnt = 0; loop_cnt < muxEntry->op_count; loop_cnt++) { 231183f18a55SManish chopra NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, sel_value); 231283f18a55SManish chopra NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0, &read_value); 231383f18a55SManish chopra *data_buff++ = sel_value; 231483f18a55SManish chopra *data_buff++ = read_value; 231583f18a55SManish chopra sel_value += muxEntry->select_value_stride; 231683f18a55SManish chopra } 231783f18a55SManish chopra return loop_cnt * (2 * sizeof(u32)); 231883f18a55SManish chopra } 231983f18a55SManish chopra 232083f18a55SManish chopra /* Handling Queue State Reads */ 232183f18a55SManish chopra static u32 232283f18a55SManish chopra netxen_md_rdqueue(struct netxen_adapter *adapter, 232383f18a55SManish chopra struct netxen_minidump_entry_queue 232483f18a55SManish chopra *queueEntry, u32 *data_buff) 232583f18a55SManish chopra { 232683f18a55SManish chopra int loop_cnt, k; 232783f18a55SManish chopra u32 queue_id, read_addr, read_value, read_stride, select_addr, read_cnt; 232883f18a55SManish chopra 232983f18a55SManish chopra read_cnt = queueEntry->read_addr_cnt; 233083f18a55SManish chopra read_stride = queueEntry->read_addr_stride; 233183f18a55SManish chopra select_addr = queueEntry->select_addr; 233283f18a55SManish chopra 233383f18a55SManish chopra for (loop_cnt = 0, queue_id = 0; loop_cnt < queueEntry->op_count; 233483f18a55SManish chopra loop_cnt++) { 233583f18a55SManish chopra NX_WR_DUMP_REG(select_addr, adapter->ahw.pci_base0, queue_id); 233683f18a55SManish chopra read_addr = queueEntry->read_addr; 233783f18a55SManish chopra for (k = 0; k < read_cnt; k--) { 233883f18a55SManish chopra NX_RD_DUMP_REG(read_addr, adapter->ahw.pci_base0, 233983f18a55SManish chopra &read_value); 234083f18a55SManish chopra *data_buff++ = read_value; 234183f18a55SManish chopra read_addr += read_stride; 234283f18a55SManish chopra } 234383f18a55SManish chopra queue_id += queueEntry->queue_id_stride; 234483f18a55SManish chopra } 234583f18a55SManish chopra return loop_cnt * (read_cnt * sizeof(read_value)); 234683f18a55SManish chopra } 234783f18a55SManish chopra 234883f18a55SManish chopra 234983f18a55SManish chopra /* 235083f18a55SManish chopra * We catch an error where driver does not read 235183f18a55SManish chopra * as much data as we expect from the entry. 235283f18a55SManish chopra */ 235383f18a55SManish chopra 235483f18a55SManish chopra static int netxen_md_entry_err_chk(struct netxen_adapter *adapter, 2355a584b7aeSDan Carpenter struct netxen_minidump_entry *entry, int esize) 235683f18a55SManish chopra { 235783f18a55SManish chopra if (esize < 0) { 235883f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 235983f18a55SManish chopra return esize; 236083f18a55SManish chopra } 236183f18a55SManish chopra if (esize != entry->hdr.entry_capture_size) { 236283f18a55SManish chopra entry->hdr.entry_capture_size = esize; 236383f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SIZE_ERR; 236483f18a55SManish chopra dev_info(&adapter->pdev->dev, 236583f18a55SManish chopra "Invalidate dump, Type:%d\tMask:%d\tSize:%dCap_size:%d\n", 236683f18a55SManish chopra entry->hdr.entry_type, entry->hdr.entry_capture_mask, 236783f18a55SManish chopra esize, entry->hdr.entry_capture_size); 236883f18a55SManish chopra dev_info(&adapter->pdev->dev, "Aborting further dump capture\n"); 236983f18a55SManish chopra } 237083f18a55SManish chopra return 0; 237183f18a55SManish chopra } 237283f18a55SManish chopra 237383f18a55SManish chopra static int netxen_parse_md_template(struct netxen_adapter *adapter) 237483f18a55SManish chopra { 237583f18a55SManish chopra int num_of_entries, buff_level, e_cnt, esize; 237683f18a55SManish chopra int end_cnt = 0, rv = 0, sane_start = 0, sane_end = 0; 237783f18a55SManish chopra char *dbuff; 237883f18a55SManish chopra void *template_buff = adapter->mdump.md_template; 237983f18a55SManish chopra char *dump_buff = adapter->mdump.md_capture_buff; 238083f18a55SManish chopra int capture_mask = adapter->mdump.md_capture_mask; 238183f18a55SManish chopra struct netxen_minidump_template_hdr *template_hdr; 238283f18a55SManish chopra struct netxen_minidump_entry *entry; 238383f18a55SManish chopra 238483f18a55SManish chopra if ((capture_mask & 0x3) != 0x3) { 238583f18a55SManish chopra dev_err(&adapter->pdev->dev, "Capture mask %02x below minimum needed " 238683f18a55SManish chopra "for valid firmware dump\n", capture_mask); 238783f18a55SManish chopra return -EINVAL; 238883f18a55SManish chopra } 238983f18a55SManish chopra template_hdr = (struct netxen_minidump_template_hdr *) template_buff; 239083f18a55SManish chopra num_of_entries = template_hdr->num_of_entries; 239183f18a55SManish chopra entry = (struct netxen_minidump_entry *) ((char *) template_buff + 239283f18a55SManish chopra template_hdr->first_entry_offset); 239383f18a55SManish chopra memcpy(dump_buff, template_buff, adapter->mdump.md_template_size); 239483f18a55SManish chopra dump_buff = dump_buff + adapter->mdump.md_template_size; 239583f18a55SManish chopra 239683f18a55SManish chopra if (template_hdr->entry_type == TLHDR) 239783f18a55SManish chopra sane_start = 1; 239883f18a55SManish chopra 239983f18a55SManish chopra for (e_cnt = 0, buff_level = 0; e_cnt < num_of_entries; e_cnt++) { 240083f18a55SManish chopra if (!(entry->hdr.entry_capture_mask & capture_mask)) { 240183f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 240283f18a55SManish chopra entry = (struct netxen_minidump_entry *) 240383f18a55SManish chopra ((char *) entry + entry->hdr.entry_size); 240483f18a55SManish chopra continue; 240583f18a55SManish chopra } 240683f18a55SManish chopra switch (entry->hdr.entry_type) { 240783f18a55SManish chopra case RDNOP: 240883f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 240983f18a55SManish chopra break; 241083f18a55SManish chopra case RDEND: 241183f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 241283f18a55SManish chopra if (!sane_end) 241383f18a55SManish chopra end_cnt = e_cnt; 241483f18a55SManish chopra sane_end += 1; 241583f18a55SManish chopra break; 241683f18a55SManish chopra case CNTRL: 241783f18a55SManish chopra rv = netxen_md_cntrl(adapter, 241883f18a55SManish chopra template_hdr, (void *)entry); 241983f18a55SManish chopra if (rv) 242083f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 242183f18a55SManish chopra break; 242283f18a55SManish chopra case RDCRB: 242383f18a55SManish chopra dbuff = dump_buff + buff_level; 242483f18a55SManish chopra esize = netxen_md_rd_crb(adapter, 242583f18a55SManish chopra (void *) entry, (void *) dbuff); 242683f18a55SManish chopra rv = netxen_md_entry_err_chk 242783f18a55SManish chopra (adapter, entry, esize); 242883f18a55SManish chopra if (rv < 0) 242983f18a55SManish chopra break; 243083f18a55SManish chopra buff_level += esize; 243183f18a55SManish chopra break; 243283f18a55SManish chopra case RDMN: 243383f18a55SManish chopra case RDMEM: 243483f18a55SManish chopra dbuff = dump_buff + buff_level; 243583f18a55SManish chopra esize = netxen_md_rdmem(adapter, 243683f18a55SManish chopra (void *) entry, (void *) dbuff); 243783f18a55SManish chopra rv = netxen_md_entry_err_chk 243883f18a55SManish chopra (adapter, entry, esize); 243983f18a55SManish chopra if (rv < 0) 244083f18a55SManish chopra break; 244183f18a55SManish chopra buff_level += esize; 244283f18a55SManish chopra break; 244383f18a55SManish chopra case BOARD: 244483f18a55SManish chopra case RDROM: 244583f18a55SManish chopra dbuff = dump_buff + buff_level; 244683f18a55SManish chopra esize = netxen_md_rdrom(adapter, 244783f18a55SManish chopra (void *) entry, (void *) dbuff); 244883f18a55SManish chopra rv = netxen_md_entry_err_chk 244983f18a55SManish chopra (adapter, entry, esize); 245083f18a55SManish chopra if (rv < 0) 245183f18a55SManish chopra break; 245283f18a55SManish chopra buff_level += esize; 245383f18a55SManish chopra break; 245483f18a55SManish chopra case L2ITG: 245583f18a55SManish chopra case L2DTG: 245683f18a55SManish chopra case L2DAT: 245783f18a55SManish chopra case L2INS: 245883f18a55SManish chopra dbuff = dump_buff + buff_level; 245983f18a55SManish chopra esize = netxen_md_L2Cache(adapter, 246083f18a55SManish chopra (void *) entry, (void *) dbuff); 246183f18a55SManish chopra rv = netxen_md_entry_err_chk 246283f18a55SManish chopra (adapter, entry, esize); 246383f18a55SManish chopra if (rv < 0) 246483f18a55SManish chopra break; 246583f18a55SManish chopra buff_level += esize; 246683f18a55SManish chopra break; 246783f18a55SManish chopra case L1DAT: 246883f18a55SManish chopra case L1INS: 246983f18a55SManish chopra dbuff = dump_buff + buff_level; 247083f18a55SManish chopra esize = netxen_md_L1Cache(adapter, 247183f18a55SManish chopra (void *) entry, (void *) dbuff); 247283f18a55SManish chopra rv = netxen_md_entry_err_chk 247383f18a55SManish chopra (adapter, entry, esize); 247483f18a55SManish chopra if (rv < 0) 247583f18a55SManish chopra break; 247683f18a55SManish chopra buff_level += esize; 247783f18a55SManish chopra break; 247883f18a55SManish chopra case RDOCM: 247983f18a55SManish chopra dbuff = dump_buff + buff_level; 248083f18a55SManish chopra esize = netxen_md_rdocm(adapter, 248183f18a55SManish chopra (void *) entry, (void *) dbuff); 248283f18a55SManish chopra rv = netxen_md_entry_err_chk 248383f18a55SManish chopra (adapter, entry, esize); 248483f18a55SManish chopra if (rv < 0) 248583f18a55SManish chopra break; 248683f18a55SManish chopra buff_level += esize; 248783f18a55SManish chopra break; 248883f18a55SManish chopra case RDMUX: 248983f18a55SManish chopra dbuff = dump_buff + buff_level; 249083f18a55SManish chopra esize = netxen_md_rdmux(adapter, 249183f18a55SManish chopra (void *) entry, (void *) dbuff); 249283f18a55SManish chopra rv = netxen_md_entry_err_chk 249383f18a55SManish chopra (adapter, entry, esize); 249483f18a55SManish chopra if (rv < 0) 249583f18a55SManish chopra break; 249683f18a55SManish chopra buff_level += esize; 249783f18a55SManish chopra break; 249883f18a55SManish chopra case QUEUE: 249983f18a55SManish chopra dbuff = dump_buff + buff_level; 250083f18a55SManish chopra esize = netxen_md_rdqueue(adapter, 250183f18a55SManish chopra (void *) entry, (void *) dbuff); 250283f18a55SManish chopra rv = netxen_md_entry_err_chk 250383f18a55SManish chopra (adapter, entry, esize); 250483f18a55SManish chopra if (rv < 0) 250583f18a55SManish chopra break; 250683f18a55SManish chopra buff_level += esize; 250783f18a55SManish chopra break; 250883f18a55SManish chopra default: 250983f18a55SManish chopra entry->hdr.driver_flags |= NX_DUMP_SKIP; 251083f18a55SManish chopra break; 251183f18a55SManish chopra } 251283f18a55SManish chopra /* Next entry in the template */ 251383f18a55SManish chopra entry = (struct netxen_minidump_entry *) 251483f18a55SManish chopra ((char *) entry + entry->hdr.entry_size); 251583f18a55SManish chopra } 251683f18a55SManish chopra if (!sane_start || sane_end > 1) { 251783f18a55SManish chopra dev_err(&adapter->pdev->dev, 251883f18a55SManish chopra "Firmware minidump template configuration error.\n"); 251983f18a55SManish chopra } 252083f18a55SManish chopra return 0; 252183f18a55SManish chopra } 252283f18a55SManish chopra 252383f18a55SManish chopra static int 252483f18a55SManish chopra netxen_collect_minidump(struct netxen_adapter *adapter) 252583f18a55SManish chopra { 252683f18a55SManish chopra int ret = 0; 252783f18a55SManish chopra struct netxen_minidump_template_hdr *hdr; 252883f18a55SManish chopra struct timespec val; 252983f18a55SManish chopra hdr = (struct netxen_minidump_template_hdr *) 253083f18a55SManish chopra adapter->mdump.md_template; 253183f18a55SManish chopra hdr->driver_capture_mask = adapter->mdump.md_capture_mask; 253283f18a55SManish chopra jiffies_to_timespec(jiffies, &val); 253383f18a55SManish chopra hdr->driver_timestamp = (u32) val.tv_sec; 253483f18a55SManish chopra hdr->driver_info_word2 = adapter->fw_version; 253583f18a55SManish chopra hdr->driver_info_word3 = NXRD32(adapter, CRB_DRIVER_VERSION); 253683f18a55SManish chopra ret = netxen_parse_md_template(adapter); 253783f18a55SManish chopra if (ret) 253883f18a55SManish chopra return ret; 253983f18a55SManish chopra 254083f18a55SManish chopra return ret; 254183f18a55SManish chopra } 254283f18a55SManish chopra 254383f18a55SManish chopra 254483f18a55SManish chopra void 254583f18a55SManish chopra netxen_dump_fw(struct netxen_adapter *adapter) 254683f18a55SManish chopra { 254783f18a55SManish chopra struct netxen_minidump_template_hdr *hdr; 254883f18a55SManish chopra int i, k, data_size = 0; 254983f18a55SManish chopra u32 capture_mask; 255083f18a55SManish chopra hdr = (struct netxen_minidump_template_hdr *) 255183f18a55SManish chopra adapter->mdump.md_template; 255283f18a55SManish chopra capture_mask = adapter->mdump.md_capture_mask; 255383f18a55SManish chopra 255483f18a55SManish chopra for (i = 0x2, k = 1; (i & NX_DUMP_MASK_MAX); i <<= 1, k++) { 255583f18a55SManish chopra if (i & capture_mask) 255683f18a55SManish chopra data_size += hdr->capture_size_array[k]; 255783f18a55SManish chopra } 255883f18a55SManish chopra if (!data_size) { 255983f18a55SManish chopra dev_err(&adapter->pdev->dev, 256083f18a55SManish chopra "Invalid cap sizes for capture_mask=0x%x\n", 256183f18a55SManish chopra adapter->mdump.md_capture_mask); 256283f18a55SManish chopra return; 256383f18a55SManish chopra } 256483f18a55SManish chopra adapter->mdump.md_capture_size = data_size; 256583f18a55SManish chopra adapter->mdump.md_dump_size = adapter->mdump.md_template_size + 256683f18a55SManish chopra adapter->mdump.md_capture_size; 256783f18a55SManish chopra if (!adapter->mdump.md_capture_buff) { 256883f18a55SManish chopra adapter->mdump.md_capture_buff = 2569b2adaca9SJoe Perches vzalloc(adapter->mdump.md_dump_size); 2570b2adaca9SJoe Perches if (!adapter->mdump.md_capture_buff) 257183f18a55SManish chopra return; 2572b2adaca9SJoe Perches 257383f18a55SManish chopra if (netxen_collect_minidump(adapter)) { 257483f18a55SManish chopra adapter->mdump.has_valid_dump = 0; 257583f18a55SManish chopra adapter->mdump.md_dump_size = 0; 257683f18a55SManish chopra vfree(adapter->mdump.md_capture_buff); 257783f18a55SManish chopra adapter->mdump.md_capture_buff = NULL; 257883f18a55SManish chopra dev_err(&adapter->pdev->dev, 257983f18a55SManish chopra "Error in collecting firmware minidump.\n"); 258083f18a55SManish chopra } else { 258183f18a55SManish chopra adapter->mdump.md_timestamp = jiffies; 258283f18a55SManish chopra adapter->mdump.has_valid_dump = 1; 258383f18a55SManish chopra adapter->fw_mdump_rdy = 1; 258483f18a55SManish chopra dev_info(&adapter->pdev->dev, "%s Successfully " 258583f18a55SManish chopra "collected fw dump.\n", adapter->netdev->name); 258683f18a55SManish chopra } 258783f18a55SManish chopra 258883f18a55SManish chopra } else { 258983f18a55SManish chopra dev_info(&adapter->pdev->dev, 259083f18a55SManish chopra "Cannot overwrite previously collected " 259183f18a55SManish chopra "firmware minidump.\n"); 259283f18a55SManish chopra adapter->fw_mdump_rdy = 1; 259383f18a55SManish chopra return; 259483f18a55SManish chopra } 259583f18a55SManish chopra } 2596