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