blob: fcce43c9fed560c5860a96909d2694a720afa68a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/************************************************************************
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002 * s2io.c: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright(c) 2002-2005 Neterion Inc.
4
5 * This software may be used and distributed according to the terms of
6 * the GNU General Public License (GPL), incorporated herein by reference.
7 * Drivers based on or derived from this code fall under the GPL and must
8 * retain the authorship, copyright and license notice. This file is not
9 * a complete program and may only be used when the entire operating
10 * system is licensed under the GPL.
11 * See the file COPYING in this distribution for more information.
12 *
13 * Credits:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070014 * Jeff Garzik : For pointing out the improper error condition
15 * check in the s2io_xmit routine and also some
16 * issues in the Tx watch dog function. Also for
17 * patiently answering all those innumerable
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * questions regaring the 2.6 porting issues.
19 * Stephen Hemminger : Providing proper 2.6 porting mechanism for some
20 * macros available only in 2.6 Kernel.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070021 * Francois Romieu : For pointing out all code part that were
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * deprecated and also styling related comments.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070023 * Grant Grundler : For helping me get rid of some Architecture
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 * dependent code.
25 * Christopher Hellwig : Some more 2.6 specific issues in the driver.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070026 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * The module loadable parameters that are supported by the driver and a brief
28 * explaination of all the variables.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070029 * rx_ring_num : This can be used to program the number of receive rings used
30 * in the driver.
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -070031 * rx_ring_sz: This defines the number of descriptors each ring can have. This
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * is also an array of size 8.
Ananda Rajuda6971d2005-10-31 16:55:31 -050033 * rx_ring_mode: This defines the operation mode of all 8 rings. The valid
34 * values are 1, 2 and 3.
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070036 * tx_fifo_len: This too is an array of 8. Each element defines the number of
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 * Tx descriptors that can be associated with each corresponding FIFO.
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 ************************************************************************/
39
40#include <linux/config.h>
41#include <linux/module.h>
42#include <linux/types.h>
43#include <linux/errno.h>
44#include <linux/ioport.h>
45#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040046#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/kernel.h>
48#include <linux/netdevice.h>
49#include <linux/etherdevice.h>
50#include <linux/skbuff.h>
51#include <linux/init.h>
52#include <linux/delay.h>
53#include <linux/stddef.h>
54#include <linux/ioctl.h>
55#include <linux/timex.h>
56#include <linux/sched.h>
57#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/workqueue.h>
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -070059#include <linux/if_vlan.h>
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050060#include <linux/ip.h>
61#include <linux/tcp.h>
62#include <net/tcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <asm/system.h>
65#include <asm/uaccess.h>
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070066#include <asm/io.h>
Andrew Mortonfe931392006-02-03 01:45:12 -080067#include <asm/div64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* local include */
70#include "s2io.h"
71#include "s2io-regs.h"
72
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050073#define DRV_VERSION "2.0.11.2"
John Linville6c1792f2005-10-04 07:51:45 -040074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/* S2io Driver name & version. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070076static char s2io_driver_name[] = "Neterion";
John Linville6c1792f2005-10-04 07:51:45 -040077static char s2io_driver_version[] = DRV_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Ananda Rajuda6971d2005-10-31 16:55:31 -050079int rxd_size[4] = {32,48,48,64};
80int rxd_count[4] = {127,85,85,63};
81
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -070082static inline int RXD_IS_UP2DT(RxD_t *rxdp)
83{
84 int ret;
85
86 ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
87 (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
88
89 return ret;
90}
91
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070092/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 * Cards with following subsystem_id have a link state indication
94 * problem, 600B, 600C, 600D, 640B, 640C and 640D.
95 * macro below identifies these cards given the subsystem_id.
96 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -070097#define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
98 (dev_type == XFRAME_I_DEVICE) ? \
99 ((((subid >= 0x600B) && (subid <= 0x600D)) || \
100 ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
103 ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
104#define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
105#define PANIC 1
106#define LOW 2
107static inline int rx_buffer_level(nic_t * sp, int rxb_size, int ring)
108{
109 int level = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700110 mac_info_t *mac_control;
111
112 mac_control = &sp->mac_control;
113 if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 level = LOW;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500115 if (rxb_size <= rxd_count[sp->rxd_mode]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 level = PANIC;
117 }
118 }
119
120 return level;
121}
122
123/* Ethtool related variables and Macros. */
124static char s2io_gstrings[][ETH_GSTRING_LEN] = {
125 "Register test\t(offline)",
126 "Eeprom test\t(offline)",
127 "Link test\t(online)",
128 "RLDRAM test\t(offline)",
129 "BIST Test\t(offline)"
130};
131
132static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
133 {"tmac_frms"},
134 {"tmac_data_octets"},
135 {"tmac_drop_frms"},
136 {"tmac_mcst_frms"},
137 {"tmac_bcst_frms"},
138 {"tmac_pause_ctrl_frms"},
139 {"tmac_any_err_frms"},
140 {"tmac_vld_ip_octets"},
141 {"tmac_vld_ip"},
142 {"tmac_drop_ip"},
143 {"tmac_icmp"},
144 {"tmac_rst_tcp"},
145 {"tmac_tcp"},
146 {"tmac_udp"},
147 {"rmac_vld_frms"},
148 {"rmac_data_octets"},
149 {"rmac_fcs_err_frms"},
150 {"rmac_drop_frms"},
151 {"rmac_vld_mcst_frms"},
152 {"rmac_vld_bcst_frms"},
153 {"rmac_in_rng_len_err_frms"},
154 {"rmac_long_frms"},
155 {"rmac_pause_ctrl_frms"},
156 {"rmac_discarded_frms"},
157 {"rmac_usized_frms"},
158 {"rmac_osized_frms"},
159 {"rmac_frag_frms"},
160 {"rmac_jabber_frms"},
161 {"rmac_ip"},
162 {"rmac_ip_octets"},
163 {"rmac_hdr_err_ip"},
164 {"rmac_drop_ip"},
165 {"rmac_icmp"},
166 {"rmac_tcp"},
167 {"rmac_udp"},
168 {"rmac_err_drp_udp"},
169 {"rmac_pause_cnt"},
170 {"rmac_accepted_ip"},
171 {"rmac_err_tcp"},
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -0700172 {"\n DRIVER STATISTICS"},
173 {"single_bit_ecc_errs"},
174 {"double_bit_ecc_errs"},
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -0500175 ("lro_aggregated_pkts"),
176 ("lro_flush_both_count"),
177 ("lro_out_of_sequence_pkts"),
178 ("lro_flush_due_to_max_pkts"),
179 ("lro_avg_aggr_pkts"),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
182#define S2IO_STAT_LEN sizeof(ethtool_stats_keys)/ ETH_GSTRING_LEN
183#define S2IO_STAT_STRINGS_LEN S2IO_STAT_LEN * ETH_GSTRING_LEN
184
185#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
186#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
187
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -0700188#define S2IO_TIMER_CONF(timer, handle, arg, exp) \
189 init_timer(&timer); \
190 timer.function = handle; \
191 timer.data = (unsigned long) arg; \
192 mod_timer(&timer, (jiffies + exp)) \
193
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700194/* Add the vlan */
195static void s2io_vlan_rx_register(struct net_device *dev,
196 struct vlan_group *grp)
197{
198 nic_t *nic = dev->priv;
199 unsigned long flags;
200
201 spin_lock_irqsave(&nic->tx_lock, flags);
202 nic->vlgrp = grp;
203 spin_unlock_irqrestore(&nic->tx_lock, flags);
204}
205
206/* Unregister the vlan */
207static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
208{
209 nic_t *nic = dev->priv;
210 unsigned long flags;
211
212 spin_lock_irqsave(&nic->tx_lock, flags);
213 if (nic->vlgrp)
214 nic->vlgrp->vlan_devices[vid] = NULL;
215 spin_unlock_irqrestore(&nic->tx_lock, flags);
216}
217
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700218/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 * Constants to be programmed into the Xena's registers, to configure
220 * the XAUI.
221 */
222
223#define SWITCH_SIGN 0xA5A5A5A5A5A5A5A5ULL
224#define END_SIGN 0x0
225
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700226static u64 herc_act_dtx_cfg[] = {
227 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700228 0x8000051536750000ULL, 0x80000515367500E0ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700229 /* Write data */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700230 0x8000051536750004ULL, 0x80000515367500E4ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700231 /* Set address */
232 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
233 /* Write data */
234 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
235 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700236 0x801205150D440000ULL, 0x801205150D4400E0ULL,
237 /* Write data */
238 0x801205150D440004ULL, 0x801205150D4400E4ULL,
239 /* Set address */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700240 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
241 /* Write data */
242 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
243 /* Done */
244 END_SIGN
245};
246
247static u64 xena_mdio_cfg[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 /* Reset PMA PLL */
249 0xC001010000000000ULL, 0xC0010100000000E0ULL,
250 0xC0010100008000E4ULL,
251 /* Remove Reset from PMA PLL */
252 0xC001010000000000ULL, 0xC0010100000000E0ULL,
253 0xC0010100000000E4ULL,
254 END_SIGN
255};
256
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700257static u64 xena_dtx_cfg[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 0x8000051500000000ULL, 0x80000515000000E0ULL,
259 0x80000515D93500E4ULL, 0x8001051500000000ULL,
260 0x80010515000000E0ULL, 0x80010515001E00E4ULL,
261 0x8002051500000000ULL, 0x80020515000000E0ULL,
262 0x80020515F21000E4ULL,
263 /* Set PADLOOPBACKN */
264 0x8002051500000000ULL, 0x80020515000000E0ULL,
265 0x80020515B20000E4ULL, 0x8003051500000000ULL,
266 0x80030515000000E0ULL, 0x80030515B20000E4ULL,
267 0x8004051500000000ULL, 0x80040515000000E0ULL,
268 0x80040515B20000E4ULL, 0x8005051500000000ULL,
269 0x80050515000000E0ULL, 0x80050515B20000E4ULL,
270 SWITCH_SIGN,
271 /* Remove PADLOOPBACKN */
272 0x8002051500000000ULL, 0x80020515000000E0ULL,
273 0x80020515F20000E4ULL, 0x8003051500000000ULL,
274 0x80030515000000E0ULL, 0x80030515F20000E4ULL,
275 0x8004051500000000ULL, 0x80040515000000E0ULL,
276 0x80040515F20000E4ULL, 0x8005051500000000ULL,
277 0x80050515000000E0ULL, 0x80050515F20000E4ULL,
278 END_SIGN
279};
280
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700281/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 * Constants for Fixing the MacAddress problem seen mostly on
283 * Alpha machines.
284 */
285static u64 fix_mac[] = {
286 0x0060000000000000ULL, 0x0060600000000000ULL,
287 0x0040600000000000ULL, 0x0000600000000000ULL,
288 0x0020600000000000ULL, 0x0060600000000000ULL,
289 0x0020600000000000ULL, 0x0060600000000000ULL,
290 0x0020600000000000ULL, 0x0060600000000000ULL,
291 0x0020600000000000ULL, 0x0060600000000000ULL,
292 0x0020600000000000ULL, 0x0060600000000000ULL,
293 0x0020600000000000ULL, 0x0060600000000000ULL,
294 0x0020600000000000ULL, 0x0060600000000000ULL,
295 0x0020600000000000ULL, 0x0060600000000000ULL,
296 0x0020600000000000ULL, 0x0060600000000000ULL,
297 0x0020600000000000ULL, 0x0060600000000000ULL,
298 0x0020600000000000ULL, 0x0000600000000000ULL,
299 0x0040600000000000ULL, 0x0060600000000000ULL,
300 END_SIGN
301};
302
303/* Module Loadable parameters. */
304static unsigned int tx_fifo_num = 1;
305static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
306 {[0 ...(MAX_TX_FIFOS - 1)] = 0 };
307static unsigned int rx_ring_num = 1;
308static unsigned int rx_ring_sz[MAX_RX_RINGS] =
309 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700310static unsigned int rts_frm_len[MAX_RX_RINGS] =
311 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
Ananda Rajuda6971d2005-10-31 16:55:31 -0500312static unsigned int rx_ring_mode = 1;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700313static unsigned int use_continuous_tx_intrs = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static unsigned int rmac_pause_time = 65535;
315static unsigned int mc_pause_threshold_q0q3 = 187;
316static unsigned int mc_pause_threshold_q4q7 = 187;
317static unsigned int shared_splits;
318static unsigned int tmac_util_period = 5;
319static unsigned int rmac_util_period = 5;
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -0700320static unsigned int bimodal = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500321static unsigned int l3l4hdr_size = 128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#ifndef CONFIG_S2IO_NAPI
323static unsigned int indicate_max_pkts;
324#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -0700325/* Frequency of Rx desc syncs expressed as power of 2 */
326static unsigned int rxsync_frequency = 3;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -0400327/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
328static unsigned int intr_type = 0;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -0500329/* Large receive offload feature */
330static unsigned int lro = 0;
331/* Max pkts to be aggregated by LRO at one time. If not specified,
332 * aggregation happens until we hit max IP pkt size(64K)
333 */
334static unsigned int lro_max_pkts = 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700336/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 * S2IO device table.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700338 * This table lists all the devices that this driver supports.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 */
340static struct pci_device_id s2io_tbl[] __devinitdata = {
341 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
342 PCI_ANY_ID, PCI_ANY_ID},
343 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
344 PCI_ANY_ID, PCI_ANY_ID},
345 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700346 PCI_ANY_ID, PCI_ANY_ID},
347 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
348 PCI_ANY_ID, PCI_ANY_ID},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 {0,}
350};
351
352MODULE_DEVICE_TABLE(pci, s2io_tbl);
353
354static struct pci_driver s2io_driver = {
355 .name = "S2IO",
356 .id_table = s2io_tbl,
357 .probe = s2io_init_nic,
358 .remove = __devexit_p(s2io_rem_nic),
359};
360
361/* A simplifier macro used both by init and free shared_mem Fns(). */
362#define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
363
364/**
365 * init_shared_mem - Allocation and Initialization of Memory
366 * @nic: Device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700367 * Description: The function allocates all the memory areas shared
368 * between the NIC and the driver. This includes Tx descriptors,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 * Rx descriptors and the statistics block.
370 */
371
372static int init_shared_mem(struct s2io_nic *nic)
373{
374 u32 size;
375 void *tmp_v_addr, *tmp_v_addr_next;
376 dma_addr_t tmp_p_addr, tmp_p_addr_next;
377 RxD_block_t *pre_rxd_blk = NULL;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700378 int i, j, blk_cnt, rx_sz, tx_sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 int lst_size, lst_per_page;
380 struct net_device *dev = nic->dev;
viro@zenIV.linux.org.uk8ae418c2005-09-02 20:15:29 +0100381 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 buffAdd_t *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 mac_info_t *mac_control;
385 struct config_param *config;
386
387 mac_control = &nic->mac_control;
388 config = &nic->config;
389
390
391 /* Allocation and initialization of TXDLs in FIOFs */
392 size = 0;
393 for (i = 0; i < config->tx_fifo_num; i++) {
394 size += config->tx_cfg[i].fifo_len;
395 }
396 if (size > MAX_AVAILABLE_TXDS) {
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -0700397 DBG_PRINT(ERR_DBG, "%s: Requested TxDs too high, ",
398 __FUNCTION__);
399 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return FAILURE;
401 }
402
403 lst_size = (sizeof(TxD_t) * config->max_txds);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700404 tx_sz = lst_size * size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 lst_per_page = PAGE_SIZE / lst_size;
406
407 for (i = 0; i < config->tx_fifo_num; i++) {
408 int fifo_len = config->tx_cfg[i].fifo_len;
409 int list_holder_size = fifo_len * sizeof(list_info_hold_t);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700410 mac_control->fifos[i].list_info = kmalloc(list_holder_size,
411 GFP_KERNEL);
412 if (!mac_control->fifos[i].list_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 DBG_PRINT(ERR_DBG,
414 "Malloc failed for list_info\n");
415 return -ENOMEM;
416 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700417 memset(mac_control->fifos[i].list_info, 0, list_holder_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 for (i = 0; i < config->tx_fifo_num; i++) {
420 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
421 lst_per_page);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700422 mac_control->fifos[i].tx_curr_put_info.offset = 0;
423 mac_control->fifos[i].tx_curr_put_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700425 mac_control->fifos[i].tx_curr_get_info.offset = 0;
426 mac_control->fifos[i].tx_curr_get_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700428 mac_control->fifos[i].fifo_no = i;
429 mac_control->fifos[i].nic = nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500430 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 2;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 for (j = 0; j < page_num; j++) {
433 int k = 0;
434 dma_addr_t tmp_p;
435 void *tmp_v;
436 tmp_v = pci_alloc_consistent(nic->pdev,
437 PAGE_SIZE, &tmp_p);
438 if (!tmp_v) {
439 DBG_PRINT(ERR_DBG,
440 "pci_alloc_consistent ");
441 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
442 return -ENOMEM;
443 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700444 /* If we got a zero DMA address(can happen on
445 * certain platforms like PPC), reallocate.
446 * Store virtual address of page we don't want,
447 * to be freed later.
448 */
449 if (!tmp_p) {
450 mac_control->zerodma_virt_addr = tmp_v;
451 DBG_PRINT(INIT_DBG,
452 "%s: Zero DMA address for TxDL. ", dev->name);
453 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700454 "Virtual address %p\n", tmp_v);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700455 tmp_v = pci_alloc_consistent(nic->pdev,
456 PAGE_SIZE, &tmp_p);
457 if (!tmp_v) {
458 DBG_PRINT(ERR_DBG,
459 "pci_alloc_consistent ");
460 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
461 return -ENOMEM;
462 }
463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 while (k < lst_per_page) {
465 int l = (j * lst_per_page) + k;
466 if (l == config->tx_cfg[i].fifo_len)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700467 break;
468 mac_control->fifos[i].list_info[l].list_virt_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 tmp_v + (k * lst_size);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700470 mac_control->fifos[i].list_info[l].list_phy_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 tmp_p + (k * lst_size);
472 k++;
473 }
474 }
475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500477 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL);
478 if (!nic->ufo_in_band_v)
479 return -ENOMEM;
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /* Allocation and initialization of RXDs in Rings */
482 size = 0;
483 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500484 if (config->rx_cfg[i].num_rxd %
485 (rxd_count[nic->rxd_mode] + 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
487 DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
488 i);
489 DBG_PRINT(ERR_DBG, "RxDs per Block");
490 return FAILURE;
491 }
492 size += config->rx_cfg[i].num_rxd;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700493 mac_control->rings[i].block_count =
Ananda Rajuda6971d2005-10-31 16:55:31 -0500494 config->rx_cfg[i].num_rxd /
495 (rxd_count[nic->rxd_mode] + 1 );
496 mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
497 mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500499 if (nic->rxd_mode == RXD_MODE_1)
500 size = (size * (sizeof(RxD1_t)));
501 else
502 size = (size * (sizeof(RxD3_t)));
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700503 rx_sz = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700506 mac_control->rings[i].rx_curr_get_info.block_index = 0;
507 mac_control->rings[i].rx_curr_get_info.offset = 0;
508 mac_control->rings[i].rx_curr_get_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700510 mac_control->rings[i].rx_curr_put_info.block_index = 0;
511 mac_control->rings[i].rx_curr_put_info.offset = 0;
512 mac_control->rings[i].rx_curr_put_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700514 mac_control->rings[i].nic = nic;
515 mac_control->rings[i].ring_no = i;
516
Ananda Rajuda6971d2005-10-31 16:55:31 -0500517 blk_cnt = config->rx_cfg[i].num_rxd /
518 (rxd_count[nic->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /* Allocating all the Rx blocks */
520 for (j = 0; j < blk_cnt; j++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500521 rx_block_info_t *rx_blocks;
522 int l;
523
524 rx_blocks = &mac_control->rings[i].rx_blocks[j];
525 size = SIZE_OF_BLOCK; //size is always page size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
527 &tmp_p_addr);
528 if (tmp_v_addr == NULL) {
529 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700530 * In case of failure, free_shared_mem()
531 * is called, which should free any
532 * memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 * failure happened.
534 */
Ananda Rajuda6971d2005-10-31 16:55:31 -0500535 rx_blocks->block_virt_addr = tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 return -ENOMEM;
537 }
538 memset(tmp_v_addr, 0, size);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500539 rx_blocks->block_virt_addr = tmp_v_addr;
540 rx_blocks->block_dma_addr = tmp_p_addr;
541 rx_blocks->rxds = kmalloc(sizeof(rxd_info_t)*
542 rxd_count[nic->rxd_mode],
543 GFP_KERNEL);
544 for (l=0; l<rxd_count[nic->rxd_mode];l++) {
545 rx_blocks->rxds[l].virt_addr =
546 rx_blocks->block_virt_addr +
547 (rxd_size[nic->rxd_mode] * l);
548 rx_blocks->rxds[l].dma_addr =
549 rx_blocks->block_dma_addr +
550 (rxd_size[nic->rxd_mode] * l);
551 }
552
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700553 mac_control->rings[i].rx_blocks[j].block_virt_addr =
554 tmp_v_addr;
555 mac_control->rings[i].rx_blocks[j].block_dma_addr =
556 tmp_p_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558 /* Interlinking all Rx Blocks */
559 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700560 tmp_v_addr =
561 mac_control->rings[i].rx_blocks[j].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 tmp_v_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700563 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 blk_cnt].block_virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700565 tmp_p_addr =
566 mac_control->rings[i].rx_blocks[j].block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 tmp_p_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700568 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 blk_cnt].block_dma_addr;
570
571 pre_rxd_blk = (RxD_block_t *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 pre_rxd_blk->reserved_2_pNext_RxD_block =
573 (unsigned long) tmp_v_addr_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 pre_rxd_blk->pNext_RxD_Blk_physical =
575 (u64) tmp_p_addr_next;
576 }
577 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500578 if (nic->rxd_mode >= RXD_MODE_3A) {
579 /*
580 * Allocation of Storages for buffer addresses in 2BUFF mode
581 * and the buffers as well.
582 */
583 for (i = 0; i < config->rx_ring_num; i++) {
584 blk_cnt = config->rx_cfg[i].num_rxd /
585 (rxd_count[nic->rxd_mode]+ 1);
586 mac_control->rings[i].ba =
587 kmalloc((sizeof(buffAdd_t *) * blk_cnt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 GFP_KERNEL);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500589 if (!mac_control->rings[i].ba)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return -ENOMEM;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500591 for (j = 0; j < blk_cnt; j++) {
592 int k = 0;
593 mac_control->rings[i].ba[j] =
594 kmalloc((sizeof(buffAdd_t) *
595 (rxd_count[nic->rxd_mode] + 1)),
596 GFP_KERNEL);
597 if (!mac_control->rings[i].ba[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return -ENOMEM;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500599 while (k != rxd_count[nic->rxd_mode]) {
600 ba = &mac_control->rings[i].ba[j][k];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Ananda Rajuda6971d2005-10-31 16:55:31 -0500602 ba->ba_0_org = (void *) kmalloc
603 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
604 if (!ba->ba_0_org)
605 return -ENOMEM;
606 tmp = (unsigned long)ba->ba_0_org;
607 tmp += ALIGN_SIZE;
608 tmp &= ~((unsigned long) ALIGN_SIZE);
609 ba->ba_0 = (void *) tmp;
610
611 ba->ba_1_org = (void *) kmalloc
612 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
613 if (!ba->ba_1_org)
614 return -ENOMEM;
615 tmp = (unsigned long) ba->ba_1_org;
616 tmp += ALIGN_SIZE;
617 tmp &= ~((unsigned long) ALIGN_SIZE);
618 ba->ba_1 = (void *) tmp;
619 k++;
620 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622 }
623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* Allocation and initialization of Statistics block */
626 size = sizeof(StatInfo_t);
627 mac_control->stats_mem = pci_alloc_consistent
628 (nic->pdev, size, &mac_control->stats_mem_phy);
629
630 if (!mac_control->stats_mem) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700631 /*
632 * In case of failure, free_shared_mem() is called, which
633 * should free any memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 * failure happened.
635 */
636 return -ENOMEM;
637 }
638 mac_control->stats_mem_sz = size;
639
640 tmp_v_addr = mac_control->stats_mem;
641 mac_control->stats_info = (StatInfo_t *) tmp_v_addr;
642 memset(tmp_v_addr, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
644 (unsigned long long) tmp_p_addr);
645
646 return SUCCESS;
647}
648
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700649/**
650 * free_shared_mem - Free the allocated Memory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 * @nic: Device private variable.
652 * Description: This function is to free all memory locations allocated by
653 * the init_shared_mem() function and return it to the kernel.
654 */
655
656static void free_shared_mem(struct s2io_nic *nic)
657{
658 int i, j, blk_cnt, size;
659 void *tmp_v_addr;
660 dma_addr_t tmp_p_addr;
661 mac_info_t *mac_control;
662 struct config_param *config;
663 int lst_size, lst_per_page;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700664 struct net_device *dev = nic->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 if (!nic)
667 return;
668
669 mac_control = &nic->mac_control;
670 config = &nic->config;
671
672 lst_size = (sizeof(TxD_t) * config->max_txds);
673 lst_per_page = PAGE_SIZE / lst_size;
674
675 for (i = 0; i < config->tx_fifo_num; i++) {
676 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
677 lst_per_page);
678 for (j = 0; j < page_num; j++) {
679 int mem_blks = (j * lst_per_page);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700680 if (!mac_control->fifos[i].list_info)
681 return;
682 if (!mac_control->fifos[i].list_info[mem_blks].
683 list_virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 break;
685 pci_free_consistent(nic->pdev, PAGE_SIZE,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700686 mac_control->fifos[i].
687 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 list_virt_addr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700689 mac_control->fifos[i].
690 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 list_phy_addr);
692 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700693 /* If we got a zero DMA address during allocation,
694 * free the page now
695 */
696 if (mac_control->zerodma_virt_addr) {
697 pci_free_consistent(nic->pdev, PAGE_SIZE,
698 mac_control->zerodma_virt_addr,
699 (dma_addr_t)0);
700 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700701 "%s: Freeing TxDL with zero DMA addr. ",
702 dev->name);
703 DBG_PRINT(INIT_DBG, "Virtual address %p\n",
704 mac_control->zerodma_virt_addr);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700705 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700706 kfree(mac_control->fifos[i].list_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 size = SIZE_OF_BLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700711 blk_cnt = mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700713 tmp_v_addr = mac_control->rings[i].rx_blocks[j].
714 block_virt_addr;
715 tmp_p_addr = mac_control->rings[i].rx_blocks[j].
716 block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 if (tmp_v_addr == NULL)
718 break;
719 pci_free_consistent(nic->pdev, size,
720 tmp_v_addr, tmp_p_addr);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500721 kfree(mac_control->rings[i].rx_blocks[j].rxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
723 }
724
Ananda Rajuda6971d2005-10-31 16:55:31 -0500725 if (nic->rxd_mode >= RXD_MODE_3A) {
726 /* Freeing buffer storage addresses in 2BUFF mode. */
727 for (i = 0; i < config->rx_ring_num; i++) {
728 blk_cnt = config->rx_cfg[i].num_rxd /
729 (rxd_count[nic->rxd_mode] + 1);
730 for (j = 0; j < blk_cnt; j++) {
731 int k = 0;
732 if (!mac_control->rings[i].ba[j])
733 continue;
734 while (k != rxd_count[nic->rxd_mode]) {
735 buffAdd_t *ba =
736 &mac_control->rings[i].ba[j][k];
737 kfree(ba->ba_0_org);
738 kfree(ba->ba_1_org);
739 k++;
740 }
741 kfree(mac_control->rings[i].ba[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500743 kfree(mac_control->rings[i].ba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 if (mac_control->stats_mem) {
748 pci_free_consistent(nic->pdev,
749 mac_control->stats_mem_sz,
750 mac_control->stats_mem,
751 mac_control->stats_mem_phy);
752 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500753 if (nic->ufo_in_band_v)
754 kfree(nic->ufo_in_band_v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700757/**
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700758 * s2io_verify_pci_mode -
759 */
760
761static int s2io_verify_pci_mode(nic_t *nic)
762{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +0100763 XENA_dev_config_t __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700764 register u64 val64 = 0;
765 int mode;
766
767 val64 = readq(&bar0->pci_mode);
768 mode = (u8)GET_PCI_MODE(val64);
769
770 if ( val64 & PCI_MODE_UNKNOWN_MODE)
771 return -1; /* Unknown PCI mode */
772 return mode;
773}
774
775
776/**
777 * s2io_print_pci_mode -
778 */
779static int s2io_print_pci_mode(nic_t *nic)
780{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +0100781 XENA_dev_config_t __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700782 register u64 val64 = 0;
783 int mode;
784 struct config_param *config = &nic->config;
785
786 val64 = readq(&bar0->pci_mode);
787 mode = (u8)GET_PCI_MODE(val64);
788
789 if ( val64 & PCI_MODE_UNKNOWN_MODE)
790 return -1; /* Unknown PCI mode */
791
792 if (val64 & PCI_MODE_32_BITS) {
793 DBG_PRINT(ERR_DBG, "%s: Device is on 32 bit ", nic->dev->name);
794 } else {
795 DBG_PRINT(ERR_DBG, "%s: Device is on 64 bit ", nic->dev->name);
796 }
797
798 switch(mode) {
799 case PCI_MODE_PCI_33:
800 DBG_PRINT(ERR_DBG, "33MHz PCI bus\n");
801 config->bus_speed = 33;
802 break;
803 case PCI_MODE_PCI_66:
804 DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
805 config->bus_speed = 133;
806 break;
807 case PCI_MODE_PCIX_M1_66:
808 DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
809 config->bus_speed = 133; /* Herc doubles the clock rate */
810 break;
811 case PCI_MODE_PCIX_M1_100:
812 DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
813 config->bus_speed = 200;
814 break;
815 case PCI_MODE_PCIX_M1_133:
816 DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
817 config->bus_speed = 266;
818 break;
819 case PCI_MODE_PCIX_M2_66:
820 DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
821 config->bus_speed = 133;
822 break;
823 case PCI_MODE_PCIX_M2_100:
824 DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
825 config->bus_speed = 200;
826 break;
827 case PCI_MODE_PCIX_M2_133:
828 DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
829 config->bus_speed = 266;
830 break;
831 default:
832 return -1; /* Unsupported bus speed */
833 }
834
835 return mode;
836}
837
838/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700839 * init_nic - Initialization of hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 * @nic: device peivate variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700841 * Description: The function sequentially configures every block
842 * of the H/W from their reset values.
843 * Return Value: SUCCESS on success and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 * '-1' on failure (endian settings incorrect).
845 */
846
847static int init_nic(struct s2io_nic *nic)
848{
849 XENA_dev_config_t __iomem *bar0 = nic->bar0;
850 struct net_device *dev = nic->dev;
851 register u64 val64 = 0;
852 void __iomem *add;
853 u32 time;
854 int i, j;
855 mac_info_t *mac_control;
856 struct config_param *config;
857 int mdio_cnt = 0, dtx_cnt = 0;
858 unsigned long long mem_share;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700859 int mem_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 mac_control = &nic->mac_control;
862 config = &nic->config;
863
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700864 /* to set the swapper controle on the card */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700865 if(s2io_set_swapper(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
867 return -1;
868 }
869
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700870 /*
871 * Herc requires EOI to be removed from reset before XGXS, so..
872 */
873 if (nic->device_type & XFRAME_II_DEVICE) {
874 val64 = 0xA500000000ULL;
875 writeq(val64, &bar0->sw_reset);
876 msleep(500);
877 val64 = readq(&bar0->sw_reset);
878 }
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 /* Remove XGXS from reset state */
881 val64 = 0;
882 writeq(val64, &bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 msleep(500);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700884 val64 = readq(&bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 /* Enable Receiving broadcasts */
887 add = &bar0->mac_cfg;
888 val64 = readq(&bar0->mac_cfg);
889 val64 |= MAC_RMAC_BCAST_ENABLE;
890 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
891 writel((u32) val64, add);
892 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
893 writel((u32) (val64 >> 32), (add + 4));
894
895 /* Read registers in all blocks */
896 val64 = readq(&bar0->mac_int_mask);
897 val64 = readq(&bar0->mc_int_mask);
898 val64 = readq(&bar0->xgxs_int_mask);
899
900 /* Set MTU */
901 val64 = dev->mtu;
902 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
903
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700904 /*
905 * Configuring the XAUI Interface of Xena.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 * ***************************************
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700907 * To Configure the Xena's XAUI, one has to write a series
908 * of 64 bit values into two registers in a particular
909 * sequence. Hence a macro 'SWITCH_SIGN' has been defined
910 * which will be defined in the array of configuration values
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700911 * (xena_dtx_cfg & xena_mdio_cfg) at appropriate places
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700912 * to switch writing from one regsiter to another. We continue
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 * writing these values until we encounter the 'END_SIGN' macro.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700914 * For example, After making a series of 21 writes into
915 * dtx_control register the 'SWITCH_SIGN' appears and hence we
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 * start writing into mdio_control until we encounter END_SIGN.
917 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700918 if (nic->device_type & XFRAME_II_DEVICE) {
919 while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -0700920 SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 &bar0->dtx_control, UF);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700922 if (dtx_cnt & 0x1)
923 msleep(1); /* Necessary!! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 dtx_cnt++;
925 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700926 } else {
927 while (1) {
928 dtx_cfg:
929 while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
930 if (xena_dtx_cfg[dtx_cnt] == SWITCH_SIGN) {
931 dtx_cnt++;
932 goto mdio_cfg;
933 }
934 SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
935 &bar0->dtx_control, UF);
936 val64 = readq(&bar0->dtx_control);
937 dtx_cnt++;
938 }
939 mdio_cfg:
940 while (xena_mdio_cfg[mdio_cnt] != END_SIGN) {
941 if (xena_mdio_cfg[mdio_cnt] == SWITCH_SIGN) {
942 mdio_cnt++;
943 goto dtx_cfg;
944 }
945 SPECIAL_REG_WRITE(xena_mdio_cfg[mdio_cnt],
946 &bar0->mdio_control, UF);
947 val64 = readq(&bar0->mdio_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 mdio_cnt++;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700949 }
950 if ((xena_dtx_cfg[dtx_cnt] == END_SIGN) &&
951 (xena_mdio_cfg[mdio_cnt] == END_SIGN)) {
952 break;
953 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 goto dtx_cfg;
955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957 }
958
959 /* Tx DMA Initialization */
960 val64 = 0;
961 writeq(val64, &bar0->tx_fifo_partition_0);
962 writeq(val64, &bar0->tx_fifo_partition_1);
963 writeq(val64, &bar0->tx_fifo_partition_2);
964 writeq(val64, &bar0->tx_fifo_partition_3);
965
966
967 for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
968 val64 |=
969 vBIT(config->tx_cfg[i].fifo_len - 1, ((i * 32) + 19),
970 13) | vBIT(config->tx_cfg[i].fifo_priority,
971 ((i * 32) + 5), 3);
972
973 if (i == (config->tx_fifo_num - 1)) {
974 if (i % 2 == 0)
975 i++;
976 }
977
978 switch (i) {
979 case 1:
980 writeq(val64, &bar0->tx_fifo_partition_0);
981 val64 = 0;
982 break;
983 case 3:
984 writeq(val64, &bar0->tx_fifo_partition_1);
985 val64 = 0;
986 break;
987 case 5:
988 writeq(val64, &bar0->tx_fifo_partition_2);
989 val64 = 0;
990 break;
991 case 7:
992 writeq(val64, &bar0->tx_fifo_partition_3);
993 break;
994 }
995 }
996
997 /* Enable Tx FIFO partition 0. */
998 val64 = readq(&bar0->tx_fifo_partition_0);
999 val64 |= BIT(0); /* To enable the FIFO partition. */
1000 writeq(val64, &bar0->tx_fifo_partition_0);
1001
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001002 /*
1003 * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
1004 * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
1005 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001006 if ((nic->device_type == XFRAME_I_DEVICE) &&
1007 (get_xena_rev_id(nic->pdev) < 4))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001008 writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 val64 = readq(&bar0->tx_fifo_partition_0);
1011 DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
1012 &bar0->tx_fifo_partition_0, (unsigned long long) val64);
1013
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001014 /*
1015 * Initialization of Tx_PA_CONFIG register to ignore packet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 * integrity checking.
1017 */
1018 val64 = readq(&bar0->tx_pa_cfg);
1019 val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
1020 TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
1021 writeq(val64, &bar0->tx_pa_cfg);
1022
1023 /* Rx DMA intialization. */
1024 val64 = 0;
1025 for (i = 0; i < config->rx_ring_num; i++) {
1026 val64 |=
1027 vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
1028 3);
1029 }
1030 writeq(val64, &bar0->rx_queue_priority);
1031
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001032 /*
1033 * Allocating equal share of memory to all the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 * configured Rings.
1035 */
1036 val64 = 0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001037 if (nic->device_type & XFRAME_II_DEVICE)
1038 mem_size = 32;
1039 else
1040 mem_size = 64;
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 for (i = 0; i < config->rx_ring_num; i++) {
1043 switch (i) {
1044 case 0:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001045 mem_share = (mem_size / config->rx_ring_num +
1046 mem_size % config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
1048 continue;
1049 case 1:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001050 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
1052 continue;
1053 case 2:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001054 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
1056 continue;
1057 case 3:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001058 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
1060 continue;
1061 case 4:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001062 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
1064 continue;
1065 case 5:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001066 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
1068 continue;
1069 case 6:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001070 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
1072 continue;
1073 case 7:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001074 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
1076 continue;
1077 }
1078 }
1079 writeq(val64, &bar0->rx_queue_cfg);
1080
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001081 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001082 * Filling Tx round robin registers
1083 * as per the number of FIFOs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001085 switch (config->tx_fifo_num) {
1086 case 1:
1087 val64 = 0x0000000000000000ULL;
1088 writeq(val64, &bar0->tx_w_round_robin_0);
1089 writeq(val64, &bar0->tx_w_round_robin_1);
1090 writeq(val64, &bar0->tx_w_round_robin_2);
1091 writeq(val64, &bar0->tx_w_round_robin_3);
1092 writeq(val64, &bar0->tx_w_round_robin_4);
1093 break;
1094 case 2:
1095 val64 = 0x0000010000010000ULL;
1096 writeq(val64, &bar0->tx_w_round_robin_0);
1097 val64 = 0x0100000100000100ULL;
1098 writeq(val64, &bar0->tx_w_round_robin_1);
1099 val64 = 0x0001000001000001ULL;
1100 writeq(val64, &bar0->tx_w_round_robin_2);
1101 val64 = 0x0000010000010000ULL;
1102 writeq(val64, &bar0->tx_w_round_robin_3);
1103 val64 = 0x0100000000000000ULL;
1104 writeq(val64, &bar0->tx_w_round_robin_4);
1105 break;
1106 case 3:
1107 val64 = 0x0001000102000001ULL;
1108 writeq(val64, &bar0->tx_w_round_robin_0);
1109 val64 = 0x0001020000010001ULL;
1110 writeq(val64, &bar0->tx_w_round_robin_1);
1111 val64 = 0x0200000100010200ULL;
1112 writeq(val64, &bar0->tx_w_round_robin_2);
1113 val64 = 0x0001000102000001ULL;
1114 writeq(val64, &bar0->tx_w_round_robin_3);
1115 val64 = 0x0001020000000000ULL;
1116 writeq(val64, &bar0->tx_w_round_robin_4);
1117 break;
1118 case 4:
1119 val64 = 0x0001020300010200ULL;
1120 writeq(val64, &bar0->tx_w_round_robin_0);
1121 val64 = 0x0100000102030001ULL;
1122 writeq(val64, &bar0->tx_w_round_robin_1);
1123 val64 = 0x0200010000010203ULL;
1124 writeq(val64, &bar0->tx_w_round_robin_2);
1125 val64 = 0x0001020001000001ULL;
1126 writeq(val64, &bar0->tx_w_round_robin_3);
1127 val64 = 0x0203000100000000ULL;
1128 writeq(val64, &bar0->tx_w_round_robin_4);
1129 break;
1130 case 5:
1131 val64 = 0x0001000203000102ULL;
1132 writeq(val64, &bar0->tx_w_round_robin_0);
1133 val64 = 0x0001020001030004ULL;
1134 writeq(val64, &bar0->tx_w_round_robin_1);
1135 val64 = 0x0001000203000102ULL;
1136 writeq(val64, &bar0->tx_w_round_robin_2);
1137 val64 = 0x0001020001030004ULL;
1138 writeq(val64, &bar0->tx_w_round_robin_3);
1139 val64 = 0x0001000000000000ULL;
1140 writeq(val64, &bar0->tx_w_round_robin_4);
1141 break;
1142 case 6:
1143 val64 = 0x0001020304000102ULL;
1144 writeq(val64, &bar0->tx_w_round_robin_0);
1145 val64 = 0x0304050001020001ULL;
1146 writeq(val64, &bar0->tx_w_round_robin_1);
1147 val64 = 0x0203000100000102ULL;
1148 writeq(val64, &bar0->tx_w_round_robin_2);
1149 val64 = 0x0304000102030405ULL;
1150 writeq(val64, &bar0->tx_w_round_robin_3);
1151 val64 = 0x0001000200000000ULL;
1152 writeq(val64, &bar0->tx_w_round_robin_4);
1153 break;
1154 case 7:
1155 val64 = 0x0001020001020300ULL;
1156 writeq(val64, &bar0->tx_w_round_robin_0);
1157 val64 = 0x0102030400010203ULL;
1158 writeq(val64, &bar0->tx_w_round_robin_1);
1159 val64 = 0x0405060001020001ULL;
1160 writeq(val64, &bar0->tx_w_round_robin_2);
1161 val64 = 0x0304050000010200ULL;
1162 writeq(val64, &bar0->tx_w_round_robin_3);
1163 val64 = 0x0102030000000000ULL;
1164 writeq(val64, &bar0->tx_w_round_robin_4);
1165 break;
1166 case 8:
1167 val64 = 0x0001020300040105ULL;
1168 writeq(val64, &bar0->tx_w_round_robin_0);
1169 val64 = 0x0200030106000204ULL;
1170 writeq(val64, &bar0->tx_w_round_robin_1);
1171 val64 = 0x0103000502010007ULL;
1172 writeq(val64, &bar0->tx_w_round_robin_2);
1173 val64 = 0x0304010002060500ULL;
1174 writeq(val64, &bar0->tx_w_round_robin_3);
1175 val64 = 0x0103020400000000ULL;
1176 writeq(val64, &bar0->tx_w_round_robin_4);
1177 break;
1178 }
1179
1180 /* Filling the Rx round robin registers as per the
1181 * number of Rings and steering based on QoS.
1182 */
1183 switch (config->rx_ring_num) {
1184 case 1:
1185 val64 = 0x8080808080808080ULL;
1186 writeq(val64, &bar0->rts_qos_steering);
1187 break;
1188 case 2:
1189 val64 = 0x0000010000010000ULL;
1190 writeq(val64, &bar0->rx_w_round_robin_0);
1191 val64 = 0x0100000100000100ULL;
1192 writeq(val64, &bar0->rx_w_round_robin_1);
1193 val64 = 0x0001000001000001ULL;
1194 writeq(val64, &bar0->rx_w_round_robin_2);
1195 val64 = 0x0000010000010000ULL;
1196 writeq(val64, &bar0->rx_w_round_robin_3);
1197 val64 = 0x0100000000000000ULL;
1198 writeq(val64, &bar0->rx_w_round_robin_4);
1199
1200 val64 = 0x8080808040404040ULL;
1201 writeq(val64, &bar0->rts_qos_steering);
1202 break;
1203 case 3:
1204 val64 = 0x0001000102000001ULL;
1205 writeq(val64, &bar0->rx_w_round_robin_0);
1206 val64 = 0x0001020000010001ULL;
1207 writeq(val64, &bar0->rx_w_round_robin_1);
1208 val64 = 0x0200000100010200ULL;
1209 writeq(val64, &bar0->rx_w_round_robin_2);
1210 val64 = 0x0001000102000001ULL;
1211 writeq(val64, &bar0->rx_w_round_robin_3);
1212 val64 = 0x0001020000000000ULL;
1213 writeq(val64, &bar0->rx_w_round_robin_4);
1214
1215 val64 = 0x8080804040402020ULL;
1216 writeq(val64, &bar0->rts_qos_steering);
1217 break;
1218 case 4:
1219 val64 = 0x0001020300010200ULL;
1220 writeq(val64, &bar0->rx_w_round_robin_0);
1221 val64 = 0x0100000102030001ULL;
1222 writeq(val64, &bar0->rx_w_round_robin_1);
1223 val64 = 0x0200010000010203ULL;
1224 writeq(val64, &bar0->rx_w_round_robin_2);
1225 val64 = 0x0001020001000001ULL;
1226 writeq(val64, &bar0->rx_w_round_robin_3);
1227 val64 = 0x0203000100000000ULL;
1228 writeq(val64, &bar0->rx_w_round_robin_4);
1229
1230 val64 = 0x8080404020201010ULL;
1231 writeq(val64, &bar0->rts_qos_steering);
1232 break;
1233 case 5:
1234 val64 = 0x0001000203000102ULL;
1235 writeq(val64, &bar0->rx_w_round_robin_0);
1236 val64 = 0x0001020001030004ULL;
1237 writeq(val64, &bar0->rx_w_round_robin_1);
1238 val64 = 0x0001000203000102ULL;
1239 writeq(val64, &bar0->rx_w_round_robin_2);
1240 val64 = 0x0001020001030004ULL;
1241 writeq(val64, &bar0->rx_w_round_robin_3);
1242 val64 = 0x0001000000000000ULL;
1243 writeq(val64, &bar0->rx_w_round_robin_4);
1244
1245 val64 = 0x8080404020201008ULL;
1246 writeq(val64, &bar0->rts_qos_steering);
1247 break;
1248 case 6:
1249 val64 = 0x0001020304000102ULL;
1250 writeq(val64, &bar0->rx_w_round_robin_0);
1251 val64 = 0x0304050001020001ULL;
1252 writeq(val64, &bar0->rx_w_round_robin_1);
1253 val64 = 0x0203000100000102ULL;
1254 writeq(val64, &bar0->rx_w_round_robin_2);
1255 val64 = 0x0304000102030405ULL;
1256 writeq(val64, &bar0->rx_w_round_robin_3);
1257 val64 = 0x0001000200000000ULL;
1258 writeq(val64, &bar0->rx_w_round_robin_4);
1259
1260 val64 = 0x8080404020100804ULL;
1261 writeq(val64, &bar0->rts_qos_steering);
1262 break;
1263 case 7:
1264 val64 = 0x0001020001020300ULL;
1265 writeq(val64, &bar0->rx_w_round_robin_0);
1266 val64 = 0x0102030400010203ULL;
1267 writeq(val64, &bar0->rx_w_round_robin_1);
1268 val64 = 0x0405060001020001ULL;
1269 writeq(val64, &bar0->rx_w_round_robin_2);
1270 val64 = 0x0304050000010200ULL;
1271 writeq(val64, &bar0->rx_w_round_robin_3);
1272 val64 = 0x0102030000000000ULL;
1273 writeq(val64, &bar0->rx_w_round_robin_4);
1274
1275 val64 = 0x8080402010080402ULL;
1276 writeq(val64, &bar0->rts_qos_steering);
1277 break;
1278 case 8:
1279 val64 = 0x0001020300040105ULL;
1280 writeq(val64, &bar0->rx_w_round_robin_0);
1281 val64 = 0x0200030106000204ULL;
1282 writeq(val64, &bar0->rx_w_round_robin_1);
1283 val64 = 0x0103000502010007ULL;
1284 writeq(val64, &bar0->rx_w_round_robin_2);
1285 val64 = 0x0304010002060500ULL;
1286 writeq(val64, &bar0->rx_w_round_robin_3);
1287 val64 = 0x0103020400000000ULL;
1288 writeq(val64, &bar0->rx_w_round_robin_4);
1289
1290 val64 = 0x8040201008040201ULL;
1291 writeq(val64, &bar0->rts_qos_steering);
1292 break;
1293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295 /* UDP Fix */
1296 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001297 for (i = 0; i < 8; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 writeq(val64, &bar0->rts_frm_len_n[i]);
1299
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001300 /* Set the default rts frame length for the rings configured */
1301 val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
1302 for (i = 0 ; i < config->rx_ring_num ; i++)
1303 writeq(val64, &bar0->rts_frm_len_n[i]);
1304
1305 /* Set the frame length for the configured rings
1306 * desired by the user
1307 */
1308 for (i = 0; i < config->rx_ring_num; i++) {
1309 /* If rts_frm_len[i] == 0 then it is assumed that user not
1310 * specified frame length steering.
1311 * If the user provides the frame length then program
1312 * the rts_frm_len register for those values or else
1313 * leave it as it is.
1314 */
1315 if (rts_frm_len[i] != 0) {
1316 writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
1317 &bar0->rts_frm_len_n[i]);
1318 }
1319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001321 /* Program statistics memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001324 if (nic->device_type == XFRAME_II_DEVICE) {
1325 val64 = STAT_BC(0x320);
1326 writeq(val64, &bar0->stat_byte_cnt);
1327 }
1328
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001329 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 * Initializing the sampling rate for the device to calculate the
1331 * bandwidth utilization.
1332 */
1333 val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
1334 MAC_RX_LINK_UTIL_VAL(rmac_util_period);
1335 writeq(val64, &bar0->mac_link_util);
1336
1337
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001338 /*
1339 * Initializing the Transmit and Receive Traffic Interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 * Scheme.
1341 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001342 /*
1343 * TTI Initialization. Default Tx timer gets us about
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 * 250 interrupts per sec. Continuous interrupts are enabled
1345 * by default.
1346 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001347 if (nic->device_type == XFRAME_II_DEVICE) {
1348 int count = (nic->config.bus_speed * 125)/2;
1349 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
1350 } else {
1351
1352 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
1353 }
1354 val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 TTI_DATA1_MEM_TX_URNG_B(0x10) |
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001356 TTI_DATA1_MEM_TX_URNG_C(0x30) | TTI_DATA1_MEM_TX_TIMER_AC_EN;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001357 if (use_continuous_tx_intrs)
1358 val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 writeq(val64, &bar0->tti_data1_mem);
1360
1361 val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
1362 TTI_DATA2_MEM_TX_UFC_B(0x20) |
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001363 TTI_DATA2_MEM_TX_UFC_C(0x70) | TTI_DATA2_MEM_TX_UFC_D(0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 writeq(val64, &bar0->tti_data2_mem);
1365
1366 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1367 writeq(val64, &bar0->tti_command_mem);
1368
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001369 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 * Once the operation completes, the Strobe bit of the command
1371 * register will be reset. We poll for this particular condition
1372 * We wait for a maximum of 500ms for the operation to complete,
1373 * if it's not complete by then we return error.
1374 */
1375 time = 0;
1376 while (TRUE) {
1377 val64 = readq(&bar0->tti_command_mem);
1378 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1379 break;
1380 }
1381 if (time > 10) {
1382 DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
1383 dev->name);
1384 return -1;
1385 }
1386 msleep(50);
1387 time++;
1388 }
1389
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001390 if (nic->config.bimodal) {
1391 int k = 0;
1392 for (k = 0; k < config->rx_ring_num; k++) {
1393 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1394 val64 |= TTI_CMD_MEM_OFFSET(0x38+k);
1395 writeq(val64, &bar0->tti_command_mem);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001396
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001397 /*
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001398 * Once the operation completes, the Strobe bit of the command
1399 * register will be reset. We poll for this particular condition
1400 * We wait for a maximum of 500ms for the operation to complete,
1401 * if it's not complete by then we return error.
1402 */
1403 time = 0;
1404 while (TRUE) {
1405 val64 = readq(&bar0->tti_command_mem);
1406 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1407 break;
1408 }
1409 if (time > 10) {
1410 DBG_PRINT(ERR_DBG,
1411 "%s: TTI init Failed\n",
1412 dev->name);
1413 return -1;
1414 }
1415 time++;
1416 msleep(50);
1417 }
1418 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001419 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001421 /* RTI Initialization */
1422 if (nic->device_type == XFRAME_II_DEVICE) {
1423 /*
1424 * Programmed to generate Apprx 500 Intrs per
1425 * second
1426 */
1427 int count = (nic->config.bus_speed * 125)/4;
1428 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
1429 } else {
1430 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001432 val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
1433 RTI_DATA1_MEM_RX_URNG_B(0x10) |
1434 RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
1435
1436 writeq(val64, &bar0->rti_data1_mem);
1437
1438 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001439 RTI_DATA2_MEM_RX_UFC_B(0x2) ;
1440 if (nic->intr_type == MSI_X)
1441 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
1442 RTI_DATA2_MEM_RX_UFC_D(0x40));
1443 else
1444 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
1445 RTI_DATA2_MEM_RX_UFC_D(0x80));
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001446 writeq(val64, &bar0->rti_data2_mem);
1447
1448 for (i = 0; i < config->rx_ring_num; i++) {
1449 val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
1450 | RTI_CMD_MEM_OFFSET(i);
1451 writeq(val64, &bar0->rti_command_mem);
1452
1453 /*
1454 * Once the operation completes, the Strobe bit of the
1455 * command register will be reset. We poll for this
1456 * particular condition. We wait for a maximum of 500ms
1457 * for the operation to complete, if it's not complete
1458 * by then we return error.
1459 */
1460 time = 0;
1461 while (TRUE) {
1462 val64 = readq(&bar0->rti_command_mem);
1463 if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD)) {
1464 break;
1465 }
1466 if (time > 10) {
1467 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
1468 dev->name);
1469 return -1;
1470 }
1471 time++;
1472 msleep(50);
1473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 }
1476
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001477 /*
1478 * Initializing proper values as Pause threshold into all
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 * the 8 Queues on Rx side.
1480 */
1481 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
1482 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
1483
1484 /* Disable RMAC PAD STRIPPING */
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01001485 add = &bar0->mac_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 val64 = readq(&bar0->mac_cfg);
1487 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
1488 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1489 writel((u32) (val64), add);
1490 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1491 writel((u32) (val64 >> 32), (add + 4));
1492 val64 = readq(&bar0->mac_cfg);
1493
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05001494 /* Enable FCS stripping by adapter */
1495 add = &bar0->mac_cfg;
1496 val64 = readq(&bar0->mac_cfg);
1497 val64 |= MAC_CFG_RMAC_STRIP_FCS;
1498 if (nic->device_type == XFRAME_II_DEVICE)
1499 writeq(val64, &bar0->mac_cfg);
1500 else {
1501 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1502 writel((u32) (val64), add);
1503 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1504 writel((u32) (val64 >> 32), (add + 4));
1505 }
1506
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001507 /*
1508 * Set the time value to be inserted in the pause frame
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 * generated by xena.
1510 */
1511 val64 = readq(&bar0->rmac_pause_cfg);
1512 val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
1513 val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
1514 writeq(val64, &bar0->rmac_pause_cfg);
1515
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001516 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 * Set the Threshold Limit for Generating the pause frame
1518 * If the amount of data in any Queue exceeds ratio of
1519 * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
1520 * pause frame is generated
1521 */
1522 val64 = 0;
1523 for (i = 0; i < 4; i++) {
1524 val64 |=
1525 (((u64) 0xFF00 | nic->mac_control.
1526 mc_pause_threshold_q0q3)
1527 << (i * 2 * 8));
1528 }
1529 writeq(val64, &bar0->mc_pause_thresh_q0q3);
1530
1531 val64 = 0;
1532 for (i = 0; i < 4; i++) {
1533 val64 |=
1534 (((u64) 0xFF00 | nic->mac_control.
1535 mc_pause_threshold_q4q7)
1536 << (i * 2 * 8));
1537 }
1538 writeq(val64, &bar0->mc_pause_thresh_q4q7);
1539
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001540 /*
1541 * TxDMA will stop Read request if the number of read split has
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 * exceeded the limit pointed by shared_splits
1543 */
1544 val64 = readq(&bar0->pic_control);
1545 val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
1546 writeq(val64, &bar0->pic_control);
1547
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001548 /*
1549 * Programming the Herc to split every write transaction
1550 * that does not start on an ADB to reduce disconnects.
1551 */
1552 if (nic->device_type == XFRAME_II_DEVICE) {
1553 val64 = WREQ_SPLIT_MASK_SET_MASK(255);
1554 writeq(val64, &bar0->wreq_split_mask);
1555 }
1556
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001557 /* Setting Link stability period to 64 ms */
1558 if (nic->device_type == XFRAME_II_DEVICE) {
1559 val64 = MISC_LINK_STABILITY_PRD(3);
1560 writeq(val64, &bar0->misc_control);
1561 }
1562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 return SUCCESS;
1564}
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001565#define LINK_UP_DOWN_INTERRUPT 1
1566#define MAC_RMAC_ERR_TIMER 2
1567
Adrian Bunkac1f60d2005-11-06 01:46:47 +01001568static int s2io_link_fault_indication(nic_t *nic)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001569{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001570 if (nic->intr_type != INTA)
1571 return MAC_RMAC_ERR_TIMER;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001572 if (nic->device_type == XFRAME_II_DEVICE)
1573 return LINK_UP_DOWN_INTERRUPT;
1574 else
1575 return MAC_RMAC_ERR_TIMER;
1576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001578/**
1579 * en_dis_able_nic_intrs - Enable or Disable the interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 * @nic: device private variable,
1581 * @mask: A mask indicating which Intr block must be modified and,
1582 * @flag: A flag indicating whether to enable or disable the Intrs.
1583 * Description: This function will either disable or enable the interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001584 * depending on the flag argument. The mask argument can be used to
1585 * enable/disable any Intr block.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 * Return Value: NONE.
1587 */
1588
1589static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
1590{
1591 XENA_dev_config_t __iomem *bar0 = nic->bar0;
1592 register u64 val64 = 0, temp64 = 0;
1593
1594 /* Top level interrupt classification */
1595 /* PIC Interrupts */
1596 if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
1597 /* Enable PIC Intrs in the general intr mask register */
1598 val64 = TXPIC_INT_M | PIC_RX_INT_M;
1599 if (flag == ENABLE_INTRS) {
1600 temp64 = readq(&bar0->general_int_mask);
1601 temp64 &= ~((u64) val64);
1602 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001603 /*
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001604 * If Hercules adapter enable GPIO otherwise
1605 * disabled all PCIX, Flash, MDIO, IIC and GPIO
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001606 * interrupts for now.
1607 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001609 if (s2io_link_fault_indication(nic) ==
1610 LINK_UP_DOWN_INTERRUPT ) {
1611 temp64 = readq(&bar0->pic_int_mask);
1612 temp64 &= ~((u64) PIC_INT_GPIO);
1613 writeq(temp64, &bar0->pic_int_mask);
1614 temp64 = readq(&bar0->gpio_int_mask);
1615 temp64 &= ~((u64) GPIO_INT_MASK_LINK_UP);
1616 writeq(temp64, &bar0->gpio_int_mask);
1617 } else {
1618 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1619 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001620 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 * No MSI Support is available presently, so TTI and
1622 * RTI interrupts are also disabled.
1623 */
1624 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001625 /*
1626 * Disable PIC Intrs in the general
1627 * intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 */
1629 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1630 temp64 = readq(&bar0->general_int_mask);
1631 val64 |= temp64;
1632 writeq(val64, &bar0->general_int_mask);
1633 }
1634 }
1635
1636 /* DMA Interrupts */
1637 /* Enabling/Disabling Tx DMA interrupts */
1638 if (mask & TX_DMA_INTR) {
1639 /* Enable TxDMA Intrs in the general intr mask register */
1640 val64 = TXDMA_INT_M;
1641 if (flag == ENABLE_INTRS) {
1642 temp64 = readq(&bar0->general_int_mask);
1643 temp64 &= ~((u64) val64);
1644 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001645 /*
1646 * Keep all interrupts other than PFC interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 * and PCC interrupt disabled in DMA level.
1648 */
1649 val64 = DISABLE_ALL_INTRS & ~(TXDMA_PFC_INT_M |
1650 TXDMA_PCC_INT_M);
1651 writeq(val64, &bar0->txdma_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001652 /*
1653 * Enable only the MISC error 1 interrupt in PFC block
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 */
1655 val64 = DISABLE_ALL_INTRS & (~PFC_MISC_ERR_1);
1656 writeq(val64, &bar0->pfc_err_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001657 /*
1658 * Enable only the FB_ECC error interrupt in PCC block
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 */
1660 val64 = DISABLE_ALL_INTRS & (~PCC_FB_ECC_ERR);
1661 writeq(val64, &bar0->pcc_err_mask);
1662 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001663 /*
1664 * Disable TxDMA Intrs in the general intr mask
1665 * register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 */
1667 writeq(DISABLE_ALL_INTRS, &bar0->txdma_int_mask);
1668 writeq(DISABLE_ALL_INTRS, &bar0->pfc_err_mask);
1669 temp64 = readq(&bar0->general_int_mask);
1670 val64 |= temp64;
1671 writeq(val64, &bar0->general_int_mask);
1672 }
1673 }
1674
1675 /* Enabling/Disabling Rx DMA interrupts */
1676 if (mask & RX_DMA_INTR) {
1677 /* Enable RxDMA Intrs in the general intr mask register */
1678 val64 = RXDMA_INT_M;
1679 if (flag == ENABLE_INTRS) {
1680 temp64 = readq(&bar0->general_int_mask);
1681 temp64 &= ~((u64) val64);
1682 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001683 /*
1684 * All RxDMA block interrupts are disabled for now
1685 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 */
1687 writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
1688 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001689 /*
1690 * Disable RxDMA Intrs in the general intr mask
1691 * register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 */
1693 writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
1694 temp64 = readq(&bar0->general_int_mask);
1695 val64 |= temp64;
1696 writeq(val64, &bar0->general_int_mask);
1697 }
1698 }
1699
1700 /* MAC Interrupts */
1701 /* Enabling/Disabling MAC interrupts */
1702 if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
1703 val64 = TXMAC_INT_M | RXMAC_INT_M;
1704 if (flag == ENABLE_INTRS) {
1705 temp64 = readq(&bar0->general_int_mask);
1706 temp64 &= ~((u64) val64);
1707 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001708 /*
1709 * All MAC block error interrupts are disabled for now
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 * TODO
1711 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001713 /*
1714 * Disable MAC Intrs in the general intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 */
1716 writeq(DISABLE_ALL_INTRS, &bar0->mac_int_mask);
1717 writeq(DISABLE_ALL_INTRS,
1718 &bar0->mac_rmac_err_mask);
1719
1720 temp64 = readq(&bar0->general_int_mask);
1721 val64 |= temp64;
1722 writeq(val64, &bar0->general_int_mask);
1723 }
1724 }
1725
1726 /* XGXS Interrupts */
1727 if (mask & (TX_XGXS_INTR | RX_XGXS_INTR)) {
1728 val64 = TXXGXS_INT_M | RXXGXS_INT_M;
1729 if (flag == ENABLE_INTRS) {
1730 temp64 = readq(&bar0->general_int_mask);
1731 temp64 &= ~((u64) val64);
1732 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001733 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 * All XGXS block error interrupts are disabled for now
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001735 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 */
1737 writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
1738 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001739 /*
1740 * Disable MC Intrs in the general intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 */
1742 writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
1743 temp64 = readq(&bar0->general_int_mask);
1744 val64 |= temp64;
1745 writeq(val64, &bar0->general_int_mask);
1746 }
1747 }
1748
1749 /* Memory Controller(MC) interrupts */
1750 if (mask & MC_INTR) {
1751 val64 = MC_INT_M;
1752 if (flag == ENABLE_INTRS) {
1753 temp64 = readq(&bar0->general_int_mask);
1754 temp64 &= ~((u64) val64);
1755 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001756 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001757 * Enable all MC Intrs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001759 writeq(0x0, &bar0->mc_int_mask);
1760 writeq(0x0, &bar0->mc_err_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 } else if (flag == DISABLE_INTRS) {
1762 /*
1763 * Disable MC Intrs in the general intr mask register
1764 */
1765 writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
1766 temp64 = readq(&bar0->general_int_mask);
1767 val64 |= temp64;
1768 writeq(val64, &bar0->general_int_mask);
1769 }
1770 }
1771
1772
1773 /* Tx traffic interrupts */
1774 if (mask & TX_TRAFFIC_INTR) {
1775 val64 = TXTRAFFIC_INT_M;
1776 if (flag == ENABLE_INTRS) {
1777 temp64 = readq(&bar0->general_int_mask);
1778 temp64 &= ~((u64) val64);
1779 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001780 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 * Enable all the Tx side interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001782 * writing 0 Enables all 64 TX interrupt levels
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 */
1784 writeq(0x0, &bar0->tx_traffic_mask);
1785 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001786 /*
1787 * Disable Tx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 * register.
1789 */
1790 writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
1791 temp64 = readq(&bar0->general_int_mask);
1792 val64 |= temp64;
1793 writeq(val64, &bar0->general_int_mask);
1794 }
1795 }
1796
1797 /* Rx traffic interrupts */
1798 if (mask & RX_TRAFFIC_INTR) {
1799 val64 = RXTRAFFIC_INT_M;
1800 if (flag == ENABLE_INTRS) {
1801 temp64 = readq(&bar0->general_int_mask);
1802 temp64 &= ~((u64) val64);
1803 writeq(temp64, &bar0->general_int_mask);
1804 /* writing 0 Enables all 8 RX interrupt levels */
1805 writeq(0x0, &bar0->rx_traffic_mask);
1806 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001807 /*
1808 * Disable Rx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * register.
1810 */
1811 writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
1812 temp64 = readq(&bar0->general_int_mask);
1813 val64 |= temp64;
1814 writeq(val64, &bar0->general_int_mask);
1815 }
1816 }
1817}
1818
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001819static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001820{
1821 int ret = 0;
1822
1823 if (flag == FALSE) {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001824 if ((!herc && (rev_id >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001825 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) &&
1826 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1827 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
1828 ret = 1;
1829 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001830 }else {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001831 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
1832 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1833 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
1834 ret = 1;
1835 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001836 }
1837 } else {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001838 if ((!herc && (rev_id >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001839 if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
1840 ADAPTER_STATUS_RMAC_PCC_IDLE) &&
1841 (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
1842 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1843 ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
1844 ret = 1;
1845 }
1846 } else {
1847 if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
1848 ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
1849 (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
1850 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1851 ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
1852 ret = 1;
1853 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001854 }
1855 }
1856
1857 return ret;
1858}
1859/**
1860 * verify_xena_quiescence - Checks whether the H/W is ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 * @val64 : Value read from adapter status register.
1862 * @flag : indicates if the adapter enable bit was ever written once
1863 * before.
1864 * Description: Returns whether the H/W is ready to go or not. Depending
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001865 * on whether adapter enable bit was written or not the comparison
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 * differs and the calling function passes the input argument flag to
1867 * indicate this.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001868 * Return: 1 If xena is quiescence
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 * 0 If Xena is not quiescence
1870 */
1871
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001872static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001874 int ret = 0, herc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 u64 tmp64 = ~((u64) val64);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001876 int rev_id = get_xena_rev_id(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001878 herc = (sp->device_type == XFRAME_II_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 if (!
1880 (tmp64 &
1881 (ADAPTER_STATUS_TDMA_READY | ADAPTER_STATUS_RDMA_READY |
1882 ADAPTER_STATUS_PFC_READY | ADAPTER_STATUS_TMAC_BUF_EMPTY |
1883 ADAPTER_STATUS_PIC_QUIESCENT | ADAPTER_STATUS_MC_DRAM_READY |
1884 ADAPTER_STATUS_MC_QUEUES_READY | ADAPTER_STATUS_M_PLL_LOCK |
1885 ADAPTER_STATUS_P_PLL_LOCK))) {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001886 ret = check_prc_pcc_state(val64, flag, rev_id, herc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 }
1888
1889 return ret;
1890}
1891
1892/**
1893 * fix_mac_address - Fix for Mac addr problem on Alpha platforms
1894 * @sp: Pointer to device specifc structure
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001895 * Description :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 * New procedure to clear mac address reading problems on Alpha platforms
1897 *
1898 */
1899
Adrian Bunkac1f60d2005-11-06 01:46:47 +01001900static void fix_mac_address(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
1902 XENA_dev_config_t __iomem *bar0 = sp->bar0;
1903 u64 val64;
1904 int i = 0;
1905
1906 while (fix_mac[i] != END_SIGN) {
1907 writeq(fix_mac[i++], &bar0->gpio_control);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001908 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 val64 = readq(&bar0->gpio_control);
1910 }
1911}
1912
1913/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001914 * start_nic - Turns the device on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001916 * Description:
1917 * This function actually turns the device on. Before this function is
1918 * called,all Registers are configured from their reset states
1919 * and shared memory is allocated but the NIC is still quiescent. On
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 * calling this function, the device interrupts are cleared and the NIC is
1921 * literally switched on by writing into the adapter control register.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001922 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 * SUCCESS on success and -1 on failure.
1924 */
1925
1926static int start_nic(struct s2io_nic *nic)
1927{
1928 XENA_dev_config_t __iomem *bar0 = nic->bar0;
1929 struct net_device *dev = nic->dev;
1930 register u64 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001931 u16 interruptible;
1932 u16 subid, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 mac_info_t *mac_control;
1934 struct config_param *config;
1935
1936 mac_control = &nic->mac_control;
1937 config = &nic->config;
1938
1939 /* PRC Initialization and configuration */
1940 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001941 writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 &bar0->prc_rxd0_n[i]);
1943
1944 val64 = readq(&bar0->prc_ctrl_n[i]);
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001945 if (nic->config.bimodal)
1946 val64 |= PRC_CTRL_BIMODAL_INTERRUPT;
Ananda Rajuda6971d2005-10-31 16:55:31 -05001947 if (nic->rxd_mode == RXD_MODE_1)
1948 val64 |= PRC_CTRL_RC_ENABLED;
1949 else
1950 val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 writeq(val64, &bar0->prc_ctrl_n[i]);
1952 }
1953
Ananda Rajuda6971d2005-10-31 16:55:31 -05001954 if (nic->rxd_mode == RXD_MODE_3B) {
1955 /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
1956 val64 = readq(&bar0->rx_pa_cfg);
1957 val64 |= RX_PA_CFG_IGNORE_L2_ERR;
1958 writeq(val64, &bar0->rx_pa_cfg);
1959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001961 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 * Enabling MC-RLDRAM. After enabling the device, we timeout
1963 * for around 100ms, which is approximately the time required
1964 * for the device to be ready for operation.
1965 */
1966 val64 = readq(&bar0->mc_rldram_mrs);
1967 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
1968 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
1969 val64 = readq(&bar0->mc_rldram_mrs);
1970
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001971 msleep(100); /* Delay by around 100 ms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 /* Enabling ECC Protection. */
1974 val64 = readq(&bar0->adapter_control);
1975 val64 &= ~ADAPTER_ECC_EN;
1976 writeq(val64, &bar0->adapter_control);
1977
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001978 /*
1979 * Clearing any possible Link state change interrupts that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 * could have popped up just before Enabling the card.
1981 */
1982 val64 = readq(&bar0->mac_rmac_err_reg);
1983 if (val64)
1984 writeq(val64, &bar0->mac_rmac_err_reg);
1985
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001986 /*
1987 * Verify if the device is ready to be enabled, if so enable
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 * it.
1989 */
1990 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001991 if (!verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
1993 DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
1994 (unsigned long long) val64);
1995 return FAILURE;
1996 }
1997
1998 /* Enable select interrupts */
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001999 if (nic->intr_type != INTA)
2000 en_dis_able_nic_intrs(nic, ENA_ALL_INTRS, DISABLE_INTRS);
2001 else {
2002 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
2003 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
2004 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
2005 en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
2006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002008 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 * With some switches, link might be already up at this point.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002010 * Because of this weird behavior, when we enable laser,
2011 * we may not get link. We need to handle this. We cannot
2012 * figure out which switch is misbehaving. So we are forced to
2013 * make a global change.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 */
2015
2016 /* Enabling Laser. */
2017 val64 = readq(&bar0->adapter_control);
2018 val64 |= ADAPTER_EOI_TX_ON;
2019 writeq(val64, &bar0->adapter_control);
2020
2021 /* SXE-002: Initialize link and activity LED */
2022 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002023 if (((subid & 0xFF) >= 0x07) &&
2024 (nic->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 val64 = readq(&bar0->gpio_control);
2026 val64 |= 0x0000800000000000ULL;
2027 writeq(val64, &bar0->gpio_control);
2028 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002029 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002032 /*
2033 * Don't see link state interrupts on certain switches, so
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 * directly scheduling a link state task from here.
2035 */
2036 schedule_work(&nic->set_link_task);
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return SUCCESS;
2039}
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002040/**
2041 * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
2042 */
2043static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, int get_off)
2044{
2045 nic_t *nic = fifo_data->nic;
2046 struct sk_buff *skb;
2047 TxD_t *txds;
2048 u16 j, frg_cnt;
2049
2050 txds = txdlp;
Andrew Morton26b76252005-12-14 19:25:23 -08002051 if (txds->Host_Control == (u64)(long)nic->ufo_in_band_v) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002052 pci_unmap_single(nic->pdev, (dma_addr_t)
2053 txds->Buffer_Pointer, sizeof(u64),
2054 PCI_DMA_TODEVICE);
2055 txds++;
2056 }
2057
2058 skb = (struct sk_buff *) ((unsigned long)
2059 txds->Host_Control);
2060 if (!skb) {
2061 memset(txdlp, 0, (sizeof(TxD_t) * fifo_data->max_txds));
2062 return NULL;
2063 }
2064 pci_unmap_single(nic->pdev, (dma_addr_t)
2065 txds->Buffer_Pointer,
2066 skb->len - skb->data_len,
2067 PCI_DMA_TODEVICE);
2068 frg_cnt = skb_shinfo(skb)->nr_frags;
2069 if (frg_cnt) {
2070 txds++;
2071 for (j = 0; j < frg_cnt; j++, txds++) {
2072 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
2073 if (!txds->Buffer_Pointer)
2074 break;
2075 pci_unmap_page(nic->pdev, (dma_addr_t)
2076 txds->Buffer_Pointer,
2077 frag->size, PCI_DMA_TODEVICE);
2078 }
2079 }
2080 txdlp->Host_Control = 0;
2081 return(skb);
2082}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002084/**
2085 * free_tx_buffers - Free all queued Tx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002087 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 * Free all queued Tx buffers.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002089 * Return Value: void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090*/
2091
2092static void free_tx_buffers(struct s2io_nic *nic)
2093{
2094 struct net_device *dev = nic->dev;
2095 struct sk_buff *skb;
2096 TxD_t *txdp;
2097 int i, j;
2098 mac_info_t *mac_control;
2099 struct config_param *config;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002100 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 mac_control = &nic->mac_control;
2103 config = &nic->config;
2104
2105 for (i = 0; i < config->tx_fifo_num; i++) {
2106 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002107 txdp = (TxD_t *) mac_control->fifos[i].list_info[j].
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 list_virt_addr;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002109 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
2110 if (skb) {
2111 dev_kfree_skb(skb);
2112 cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 }
2115 DBG_PRINT(INTR_DBG,
2116 "%s:forcibly freeing %d skbs on FIFO%d\n",
2117 dev->name, cnt, i);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002118 mac_control->fifos[i].tx_curr_get_info.offset = 0;
2119 mac_control->fifos[i].tx_curr_put_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 }
2121}
2122
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002123/**
2124 * stop_nic - To stop the nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 * @nic ; device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002126 * Description:
2127 * This function does exactly the opposite of what the start_nic()
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 * function does. This function is called to stop the device.
2129 * Return Value:
2130 * void.
2131 */
2132
2133static void stop_nic(struct s2io_nic *nic)
2134{
2135 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2136 register u64 val64 = 0;
2137 u16 interruptible, i;
2138 mac_info_t *mac_control;
2139 struct config_param *config;
2140
2141 mac_control = &nic->mac_control;
2142 config = &nic->config;
2143
2144 /* Disable all interrupts */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002145 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002146 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
2147 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
2149
2150 /* Disable PRCs */
2151 for (i = 0; i < config->rx_ring_num; i++) {
2152 val64 = readq(&bar0->prc_ctrl_n[i]);
2153 val64 &= ~((u64) PRC_CTRL_RC_ENABLED);
2154 writeq(val64, &bar0->prc_ctrl_n[i]);
2155 }
2156}
2157
Ananda Rajuda6971d2005-10-31 16:55:31 -05002158int fill_rxd_3buf(nic_t *nic, RxD_t *rxdp, struct sk_buff *skb)
2159{
2160 struct net_device *dev = nic->dev;
2161 struct sk_buff *frag_list;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002162 void *tmp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002163
2164 /* Buffer-1 receives L3/L4 headers */
2165 ((RxD3_t*)rxdp)->Buffer1_ptr = pci_map_single
2166 (nic->pdev, skb->data, l3l4hdr_size + 4,
2167 PCI_DMA_FROMDEVICE);
2168
2169 /* skb_shinfo(skb)->frag_list will have L4 data payload */
2170 skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE);
2171 if (skb_shinfo(skb)->frag_list == NULL) {
2172 DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb failed\n ", dev->name);
2173 return -ENOMEM ;
2174 }
2175 frag_list = skb_shinfo(skb)->frag_list;
2176 frag_list->next = NULL;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002177 tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
2178 frag_list->data = tmp;
2179 frag_list->tail = tmp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002180
2181 /* Buffer-2 receives L4 data payload */
2182 ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
2183 frag_list->data, dev->mtu,
2184 PCI_DMA_FROMDEVICE);
2185 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
2186 rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu);
2187
2188 return SUCCESS;
2189}
2190
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002191/**
2192 * fill_rx_buffers - Allocates the Rx side skbs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002194 * @ring_no: ring number
2195 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 * The function allocates Rx side skbs and puts the physical
2197 * address of these buffers into the RxD buffer pointers, so that the NIC
2198 * can DMA the received frame into these locations.
2199 * The NIC supports 3 receive modes, viz
2200 * 1. single buffer,
2201 * 2. three buffer and
2202 * 3. Five buffer modes.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002203 * Each mode defines how many fragments the received frame will be split
2204 * up into by the NIC. The frame is split into L3 header, L4 Header,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
2206 * is split into 3 fragments. As of now only single buffer mode is
2207 * supported.
2208 * Return Value:
2209 * SUCCESS on success or an appropriate -ve value on failure.
2210 */
2211
Adrian Bunkac1f60d2005-11-06 01:46:47 +01002212static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
2214 struct net_device *dev = nic->dev;
2215 struct sk_buff *skb;
2216 RxD_t *rxdp;
2217 int off, off1, size, block_no, block_no1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 u32 alloc_tab = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002219 u32 alloc_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 mac_info_t *mac_control;
2221 struct config_param *config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002222 u64 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 buffAdd_t *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224#ifndef CONFIG_S2IO_NAPI
2225 unsigned long flags;
2226#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002227 RxD_t *first_rxdp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 mac_control = &nic->mac_control;
2230 config = &nic->config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002231 alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
2232 atomic_read(&nic->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 while (alloc_tab < alloc_cnt) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002235 block_no = mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 block_index;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002237 block_no1 = mac_control->rings[ring_no].rx_curr_get_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 block_index;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002239 off = mac_control->rings[ring_no].rx_curr_put_info.offset;
2240 off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Ananda Rajuda6971d2005-10-31 16:55:31 -05002242 rxdp = mac_control->rings[ring_no].
2243 rx_blocks[block_no].rxds[off].virt_addr;
2244
2245 if ((block_no == block_no1) && (off == off1) &&
2246 (rxdp->Host_Control)) {
2247 DBG_PRINT(INTR_DBG, "%s: Get and Put",
2248 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 DBG_PRINT(INTR_DBG, " info equated\n");
2250 goto end;
2251 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002252 if (off && (off == rxd_count[nic->rxd_mode])) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002253 mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 block_index++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002255 if (mac_control->rings[ring_no].rx_curr_put_info.
2256 block_index == mac_control->rings[ring_no].
2257 block_count)
2258 mac_control->rings[ring_no].rx_curr_put_info.
2259 block_index = 0;
2260 block_no = mac_control->rings[ring_no].
2261 rx_curr_put_info.block_index;
2262 if (off == rxd_count[nic->rxd_mode])
2263 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002264 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002265 offset = off;
2266 rxdp = mac_control->rings[ring_no].
2267 rx_blocks[block_no].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2269 dev->name, rxdp);
2270 }
2271#ifndef CONFIG_S2IO_NAPI
2272 spin_lock_irqsave(&nic->put_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002273 mac_control->rings[ring_no].put_pos =
Ananda Rajuda6971d2005-10-31 16:55:31 -05002274 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 spin_unlock_irqrestore(&nic->put_lock, flags);
2276#endif
Ananda Rajuda6971d2005-10-31 16:55:31 -05002277 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
2278 ((nic->rxd_mode >= RXD_MODE_3A) &&
2279 (rxdp->Control_2 & BIT(0)))) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002280 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002281 offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 goto end;
2283 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002284 /* calculate size of skb based on ring mode */
2285 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
2286 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
2287 if (nic->rxd_mode == RXD_MODE_1)
2288 size += NET_IP_ALIGN;
2289 else if (nic->rxd_mode == RXD_MODE_3B)
2290 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
2291 else
2292 size = l3l4hdr_size + ALIGN_SIZE + BUF0_LEN + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
Ananda Rajuda6971d2005-10-31 16:55:31 -05002294 /* allocate skb */
2295 skb = dev_alloc_skb(size);
2296 if(!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 DBG_PRINT(ERR_DBG, "%s: Out of ", dev->name);
2298 DBG_PRINT(ERR_DBG, "memory to allocate SKBs\n");
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002299 if (first_rxdp) {
2300 wmb();
2301 first_rxdp->Control_1 |= RXD_OWN_XENA;
2302 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002303 return -ENOMEM ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002305 if (nic->rxd_mode == RXD_MODE_1) {
2306 /* 1 buffer mode - normal operation mode */
2307 memset(rxdp, 0, sizeof(RxD1_t));
2308 skb_reserve(skb, NET_IP_ALIGN);
2309 ((RxD1_t*)rxdp)->Buffer0_ptr = pci_map_single
2310 (nic->pdev, skb->data, size, PCI_DMA_FROMDEVICE);
2311 rxdp->Control_2 &= (~MASK_BUFFER0_SIZE_1);
2312 rxdp->Control_2 |= SET_BUFFER0_SIZE_1(size);
2313
2314 } else if (nic->rxd_mode >= RXD_MODE_3A) {
2315 /*
2316 * 2 or 3 buffer mode -
2317 * Both 2 buffer mode and 3 buffer mode provides 128
2318 * byte aligned receive buffers.
2319 *
2320 * 3 buffer mode provides header separation where in
2321 * skb->data will have L3/L4 headers where as
2322 * skb_shinfo(skb)->frag_list will have the L4 data
2323 * payload
2324 */
2325
2326 memset(rxdp, 0, sizeof(RxD3_t));
2327 ba = &mac_control->rings[ring_no].ba[block_no][off];
2328 skb_reserve(skb, BUF0_LEN);
2329 tmp = (u64)(unsigned long) skb->data;
2330 tmp += ALIGN_SIZE;
2331 tmp &= ~ALIGN_SIZE;
2332 skb->data = (void *) (unsigned long)tmp;
2333 skb->tail = (void *) (unsigned long)tmp;
2334
2335 ((RxD3_t*)rxdp)->Buffer0_ptr =
2336 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
2337 PCI_DMA_FROMDEVICE);
2338 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2339 if (nic->rxd_mode == RXD_MODE_3B) {
2340 /* Two buffer mode */
2341
2342 /*
2343 * Buffer2 will have L3/L4 header plus
2344 * L4 payload
2345 */
2346 ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single
2347 (nic->pdev, skb->data, dev->mtu + 4,
2348 PCI_DMA_FROMDEVICE);
2349
2350 /* Buffer-1 will be dummy buffer not used */
2351 ((RxD3_t*)rxdp)->Buffer1_ptr =
2352 pci_map_single(nic->pdev, ba->ba_1, BUF1_LEN,
2353 PCI_DMA_FROMDEVICE);
2354 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2355 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2356 (dev->mtu + 4);
2357 } else {
2358 /* 3 buffer mode */
2359 if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) {
2360 dev_kfree_skb_irq(skb);
2361 if (first_rxdp) {
2362 wmb();
2363 first_rxdp->Control_1 |=
2364 RXD_OWN_XENA;
2365 }
2366 return -ENOMEM ;
2367 }
2368 }
2369 rxdp->Control_2 |= BIT(0);
2370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 rxdp->Host_Control = (unsigned long) (skb);
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002372 if (alloc_tab & ((1 << rxsync_frequency) - 1))
2373 rxdp->Control_1 |= RXD_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 off++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002375 if (off == (rxd_count[nic->rxd_mode] + 1))
2376 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002377 mac_control->rings[ring_no].rx_curr_put_info.offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002379 rxdp->Control_2 |= SET_RXD_MARKER;
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002380 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
2381 if (first_rxdp) {
2382 wmb();
2383 first_rxdp->Control_1 |= RXD_OWN_XENA;
2384 }
2385 first_rxdp = rxdp;
2386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 atomic_inc(&nic->rx_bufs_left[ring_no]);
2388 alloc_tab++;
2389 }
2390
2391 end:
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002392 /* Transfer ownership of first descriptor to adapter just before
2393 * exiting. Before that, use memory barrier so that ownership
2394 * and other fields are seen by adapter correctly.
2395 */
2396 if (first_rxdp) {
2397 wmb();
2398 first_rxdp->Control_1 |= RXD_OWN_XENA;
2399 }
2400
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 return SUCCESS;
2402}
2403
Ananda Rajuda6971d2005-10-31 16:55:31 -05002404static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2405{
2406 struct net_device *dev = sp->dev;
2407 int j;
2408 struct sk_buff *skb;
2409 RxD_t *rxdp;
2410 mac_info_t *mac_control;
2411 buffAdd_t *ba;
2412
2413 mac_control = &sp->mac_control;
2414 for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
2415 rxdp = mac_control->rings[ring_no].
2416 rx_blocks[blk].rxds[j].virt_addr;
2417 skb = (struct sk_buff *)
2418 ((unsigned long) rxdp->Host_Control);
2419 if (!skb) {
2420 continue;
2421 }
2422 if (sp->rxd_mode == RXD_MODE_1) {
2423 pci_unmap_single(sp->pdev, (dma_addr_t)
2424 ((RxD1_t*)rxdp)->Buffer0_ptr,
2425 dev->mtu +
2426 HEADER_ETHERNET_II_802_3_SIZE
2427 + HEADER_802_2_SIZE +
2428 HEADER_SNAP_SIZE,
2429 PCI_DMA_FROMDEVICE);
2430 memset(rxdp, 0, sizeof(RxD1_t));
2431 } else if(sp->rxd_mode == RXD_MODE_3B) {
2432 ba = &mac_control->rings[ring_no].
2433 ba[blk][j];
2434 pci_unmap_single(sp->pdev, (dma_addr_t)
2435 ((RxD3_t*)rxdp)->Buffer0_ptr,
2436 BUF0_LEN,
2437 PCI_DMA_FROMDEVICE);
2438 pci_unmap_single(sp->pdev, (dma_addr_t)
2439 ((RxD3_t*)rxdp)->Buffer1_ptr,
2440 BUF1_LEN,
2441 PCI_DMA_FROMDEVICE);
2442 pci_unmap_single(sp->pdev, (dma_addr_t)
2443 ((RxD3_t*)rxdp)->Buffer2_ptr,
2444 dev->mtu + 4,
2445 PCI_DMA_FROMDEVICE);
2446 memset(rxdp, 0, sizeof(RxD3_t));
2447 } else {
2448 pci_unmap_single(sp->pdev, (dma_addr_t)
2449 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
2450 PCI_DMA_FROMDEVICE);
2451 pci_unmap_single(sp->pdev, (dma_addr_t)
2452 ((RxD3_t*)rxdp)->Buffer1_ptr,
2453 l3l4hdr_size + 4,
2454 PCI_DMA_FROMDEVICE);
2455 pci_unmap_single(sp->pdev, (dma_addr_t)
2456 ((RxD3_t*)rxdp)->Buffer2_ptr, dev->mtu,
2457 PCI_DMA_FROMDEVICE);
2458 memset(rxdp, 0, sizeof(RxD3_t));
2459 }
2460 dev_kfree_skb(skb);
2461 atomic_dec(&sp->rx_bufs_left[ring_no]);
2462 }
2463}
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002466 * free_rx_buffers - Frees all Rx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 * @sp: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002468 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 * This function will free all Rx buffers allocated by host.
2470 * Return Value:
2471 * NONE.
2472 */
2473
2474static void free_rx_buffers(struct s2io_nic *sp)
2475{
2476 struct net_device *dev = sp->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002477 int i, blk = 0, buf_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 mac_info_t *mac_control;
2479 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
2481 mac_control = &sp->mac_control;
2482 config = &sp->config;
2483
2484 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05002485 for (blk = 0; blk < rx_ring_sz[i]; blk++)
2486 free_rxd_blk(sp,i,blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002488 mac_control->rings[i].rx_curr_put_info.block_index = 0;
2489 mac_control->rings[i].rx_curr_get_info.block_index = 0;
2490 mac_control->rings[i].rx_curr_put_info.offset = 0;
2491 mac_control->rings[i].rx_curr_get_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 atomic_set(&sp->rx_bufs_left[i], 0);
2493 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
2494 dev->name, buf_cnt, i);
2495 }
2496}
2497
2498/**
2499 * s2io_poll - Rx interrupt handler for NAPI support
2500 * @dev : pointer to the device structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002501 * @budget : The number of packets that were budgeted to be processed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 * during one pass through the 'Poll" function.
2503 * Description:
2504 * Comes into picture only if NAPI support has been incorporated. It does
2505 * the same thing that rx_intr_handler does, but not in a interrupt context
2506 * also It will process only a given number of packets.
2507 * Return value:
2508 * 0 on success and 1 if there are No Rx packets to be processed.
2509 */
2510
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002511#if defined(CONFIG_S2IO_NAPI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512static int s2io_poll(struct net_device *dev, int *budget)
2513{
2514 nic_t *nic = dev->priv;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002515 int pkt_cnt = 0, org_pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 mac_info_t *mac_control;
2517 struct config_param *config;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002518 XENA_dev_config_t __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002519 u64 val64;
2520 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002522 atomic_inc(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 mac_control = &nic->mac_control;
2524 config = &nic->config;
2525
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002526 nic->pkts_to_process = *budget;
2527 if (nic->pkts_to_process > dev->quota)
2528 nic->pkts_to_process = dev->quota;
2529 org_pkts_to_process = nic->pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 val64 = readq(&bar0->rx_traffic_int);
2532 writeq(val64, &bar0->rx_traffic_int);
2533
2534 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002535 rx_intr_handler(&mac_control->rings[i]);
2536 pkt_cnt = org_pkts_to_process - nic->pkts_to_process;
2537 if (!nic->pkts_to_process) {
2538 /* Quota for the current iteration has been met */
2539 goto no_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 }
2542 if (!pkt_cnt)
2543 pkt_cnt = 1;
2544
2545 dev->quota -= pkt_cnt;
2546 *budget -= pkt_cnt;
2547 netif_rx_complete(dev);
2548
2549 for (i = 0; i < config->rx_ring_num; i++) {
2550 if (fill_rx_buffers(nic, i) == -ENOMEM) {
2551 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
2552 DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
2553 break;
2554 }
2555 }
2556 /* Re enable the Rx interrupts. */
2557 en_dis_able_nic_intrs(nic, RX_TRAFFIC_INTR, ENABLE_INTRS);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002558 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 return 0;
2560
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002561no_rx:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 dev->quota -= pkt_cnt;
2563 *budget -= pkt_cnt;
2564
2565 for (i = 0; i < config->rx_ring_num; i++) {
2566 if (fill_rx_buffers(nic, i) == -ENOMEM) {
2567 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
2568 DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
2569 break;
2570 }
2571 }
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002572 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 return 1;
2574}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002575#endif
2576
2577/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 * rx_intr_handler - Rx interrupt handler
2579 * @nic: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002580 * Description:
2581 * If the interrupt is because of a received frame or if the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 * receive ring contains fresh as yet un-processed frames,this function is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002583 * called. It picks out the RxD at which place the last Rx processing had
2584 * stopped and sends the skb to the OSM's Rx handler and then increments
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 * the offset.
2586 * Return Value:
2587 * NONE.
2588 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002589static void rx_intr_handler(ring_info_t *ring_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002591 nic_t *nic = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct net_device *dev = (struct net_device *) nic->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002593 int get_block, put_block, put_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 rx_curr_get_info_t get_info, put_info;
2595 RxD_t *rxdp;
2596 struct sk_buff *skb;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002597#ifndef CONFIG_S2IO_NAPI
2598 int pkt_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599#endif
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002600 int i;
2601
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002602 spin_lock(&nic->rx_lock);
2603 if (atomic_read(&nic->card_state) == CARD_DOWN) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002604 DBG_PRINT(INTR_DBG, "%s: %s going down for reset\n",
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002605 __FUNCTION__, dev->name);
2606 spin_unlock(&nic->rx_lock);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002607 return;
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002608 }
2609
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002610 get_info = ring_data->rx_curr_get_info;
2611 get_block = get_info.block_index;
2612 put_info = ring_data->rx_curr_put_info;
2613 put_block = put_info.block_index;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002614 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002615#ifndef CONFIG_S2IO_NAPI
2616 spin_lock(&nic->put_lock);
2617 put_offset = ring_data->put_pos;
2618 spin_unlock(&nic->put_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619#else
Ananda Rajuda6971d2005-10-31 16:55:31 -05002620 put_offset = (put_block * (rxd_count[nic->rxd_mode] + 1)) +
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002621 put_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622#endif
Ananda Rajuda6971d2005-10-31 16:55:31 -05002623 while (RXD_IS_UP2DT(rxdp)) {
2624 /* If your are next to put index then it's FIFO full condition */
2625 if ((get_block == put_block) &&
2626 (get_info.offset + 1) == put_info.offset) {
2627 DBG_PRINT(ERR_DBG, "%s: Ring Full\n",dev->name);
2628 break;
2629 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002630 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
2631 if (skb == NULL) {
2632 DBG_PRINT(ERR_DBG, "%s: The skb is ",
2633 dev->name);
2634 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002635 spin_unlock(&nic->rx_lock);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002636 return;
2637 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002638 if (nic->rxd_mode == RXD_MODE_1) {
2639 pci_unmap_single(nic->pdev, (dma_addr_t)
2640 ((RxD1_t*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002641 dev->mtu +
2642 HEADER_ETHERNET_II_802_3_SIZE +
2643 HEADER_802_2_SIZE +
2644 HEADER_SNAP_SIZE,
2645 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002646 } else if (nic->rxd_mode == RXD_MODE_3B) {
2647 pci_unmap_single(nic->pdev, (dma_addr_t)
2648 ((RxD3_t*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002649 BUF0_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002650 pci_unmap_single(nic->pdev, (dma_addr_t)
2651 ((RxD3_t*)rxdp)->Buffer1_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002652 BUF1_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002653 pci_unmap_single(nic->pdev, (dma_addr_t)
2654 ((RxD3_t*)rxdp)->Buffer2_ptr,
2655 dev->mtu + 4,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002656 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002657 } else {
2658 pci_unmap_single(nic->pdev, (dma_addr_t)
2659 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
2660 PCI_DMA_FROMDEVICE);
2661 pci_unmap_single(nic->pdev, (dma_addr_t)
2662 ((RxD3_t*)rxdp)->Buffer1_ptr,
2663 l3l4hdr_size + 4,
2664 PCI_DMA_FROMDEVICE);
2665 pci_unmap_single(nic->pdev, (dma_addr_t)
2666 ((RxD3_t*)rxdp)->Buffer2_ptr,
2667 dev->mtu, PCI_DMA_FROMDEVICE);
2668 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002669 rx_osm_handler(ring_data, rxdp);
2670 get_info.offset++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002671 ring_data->rx_curr_get_info.offset = get_info.offset;
2672 rxdp = ring_data->rx_blocks[get_block].
2673 rxds[get_info.offset].virt_addr;
2674 if (get_info.offset == rxd_count[nic->rxd_mode]) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002675 get_info.offset = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002676 ring_data->rx_curr_get_info.offset = get_info.offset;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002677 get_block++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002678 if (get_block == ring_data->block_count)
2679 get_block = 0;
2680 ring_data->rx_curr_get_info.block_index = get_block;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002681 rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
2682 }
2683
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002684#ifdef CONFIG_S2IO_NAPI
2685 nic->pkts_to_process -= 1;
2686 if (!nic->pkts_to_process)
2687 break;
2688#else
2689 pkt_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
2691 break;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002692#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002694 if (nic->lro) {
2695 /* Clear all LRO sessions before exiting */
2696 for (i=0; i<MAX_LRO_SESSIONS; i++) {
2697 lro_t *lro = &nic->lro0_n[i];
2698 if (lro->in_use) {
2699 update_L3L4_header(nic, lro);
2700 queue_rx_frame(lro->parent);
2701 clear_lro_session(lro);
2702 }
2703 }
2704 }
2705
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002706 spin_unlock(&nic->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002708
2709/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 * tx_intr_handler - Transmit interrupt handler
2711 * @nic : device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002712 * Description:
2713 * If an interrupt was raised to indicate DMA complete of the
2714 * Tx packet, this function is called. It identifies the last TxD
2715 * whose buffer was freed and frees all skbs whose data have already
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 * DMA'ed into the NICs internal memory.
2717 * Return Value:
2718 * NONE
2719 */
2720
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002721static void tx_intr_handler(fifo_info_t *fifo_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002723 nic_t *nic = fifo_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 struct net_device *dev = (struct net_device *) nic->dev;
2725 tx_curr_get_info_t get_info, put_info;
2726 struct sk_buff *skb;
2727 TxD_t *txdlp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002729 get_info = fifo_data->tx_curr_get_info;
2730 put_info = fifo_data->tx_curr_put_info;
2731 txdlp = (TxD_t *) fifo_data->list_info[get_info.offset].
2732 list_virt_addr;
2733 while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
2734 (get_info.offset != put_info.offset) &&
2735 (txdlp->Host_Control)) {
2736 /* Check for TxD errors */
2737 if (txdlp->Control_1 & TXD_T_CODE) {
2738 unsigned long long err;
2739 err = txdlp->Control_1 & TXD_T_CODE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002740 if ((err >> 48) == 0xA) {
2741 DBG_PRINT(TX_DBG, "TxD returned due \
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002742to loss of link\n");
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002743 }
2744 else {
2745 DBG_PRINT(ERR_DBG, "***TxD error \
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002746%llx\n", err);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002749
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002750 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002751 if (skb == NULL) {
2752 DBG_PRINT(ERR_DBG, "%s: Null skb ",
2753 __FUNCTION__);
2754 DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
2755 return;
2756 }
2757
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002758 /* Updating the statistics block */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002759 nic->stats.tx_bytes += skb->len;
2760 dev_kfree_skb_irq(skb);
2761
2762 get_info.offset++;
2763 get_info.offset %= get_info.fifo_len + 1;
2764 txdlp = (TxD_t *) fifo_data->list_info
2765 [get_info.offset].list_virt_addr;
2766 fifo_data->tx_curr_get_info.offset =
2767 get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 }
2769
2770 spin_lock(&nic->tx_lock);
2771 if (netif_queue_stopped(dev))
2772 netif_wake_queue(dev);
2773 spin_unlock(&nic->tx_lock);
2774}
2775
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002776/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 * alarm_intr_handler - Alarm Interrrupt handler
2778 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002779 * Description: If the interrupt was neither because of Rx packet or Tx
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 * complete, this function is called. If the interrupt was to indicate
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002781 * a loss of link, the OSM link status handler is invoked for any other
2782 * alarm interrupt the block that raised the interrupt is displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 * and a H/W reset is issued.
2784 * Return Value:
2785 * NONE
2786*/
2787
2788static void alarm_intr_handler(struct s2io_nic *nic)
2789{
2790 struct net_device *dev = (struct net_device *) nic->dev;
2791 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2792 register u64 val64 = 0, err_reg = 0;
2793
2794 /* Handling link status change error Intr */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002795 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
2796 err_reg = readq(&bar0->mac_rmac_err_reg);
2797 writeq(err_reg, &bar0->mac_rmac_err_reg);
2798 if (err_reg & RMAC_LINK_STATE_CHANGE_INT) {
2799 schedule_work(&nic->set_link_task);
2800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002803 /* Handling Ecc errors */
2804 val64 = readq(&bar0->mc_err_reg);
2805 writeq(val64, &bar0->mc_err_reg);
2806 if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
2807 if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002808 nic->mac_control.stats_info->sw_stat.
2809 double_ecc_errs++;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002810 DBG_PRINT(INIT_DBG, "%s: Device indicates ",
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002811 dev->name);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002812 DBG_PRINT(INIT_DBG, "double ECC error!!\n");
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002813 if (nic->device_type != XFRAME_II_DEVICE) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002814 /* Reset XframeI only if critical error */
2815 if (val64 & (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
2816 MC_ERR_REG_MIRI_ECC_DB_ERR_1)) {
2817 netif_stop_queue(dev);
2818 schedule_work(&nic->rst_timer_task);
2819 }
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002820 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002821 } else {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002822 nic->mac_control.stats_info->sw_stat.
2823 single_ecc_errs++;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002824 }
2825 }
2826
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 /* In case of a serious error, the device will be Reset. */
2828 val64 = readq(&bar0->serr_source);
2829 if (val64 & SERR_SOURCE_ANY) {
2830 DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002831 DBG_PRINT(ERR_DBG, "serious error %llx!!\n",
2832 (unsigned long long)val64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 netif_stop_queue(dev);
2834 schedule_work(&nic->rst_timer_task);
2835 }
2836
2837 /*
2838 * Also as mentioned in the latest Errata sheets if the PCC_FB_ECC
2839 * Error occurs, the adapter will be recycled by disabling the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002840 * adapter enable bit and enabling it again after the device
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 * becomes Quiescent.
2842 */
2843 val64 = readq(&bar0->pcc_err_reg);
2844 writeq(val64, &bar0->pcc_err_reg);
2845 if (val64 & PCC_FB_ECC_DB_ERR) {
2846 u64 ac = readq(&bar0->adapter_control);
2847 ac &= ~(ADAPTER_CNTL_EN);
2848 writeq(ac, &bar0->adapter_control);
2849 ac = readq(&bar0->adapter_control);
2850 schedule_work(&nic->set_link_task);
2851 }
2852
2853 /* Other type of interrupts are not being handled now, TODO */
2854}
2855
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002856/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 * wait_for_cmd_complete - waits for a command to complete.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002858 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002860 * Description: Function that waits for a command to Write into RMAC
2861 * ADDR DATA registers to be completed and returns either success or
2862 * error depending on whether the command was complete or not.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 * Return value:
2864 * SUCCESS on success and FAILURE on failure.
2865 */
2866
Adrian Bunkac1f60d2005-11-06 01:46:47 +01002867static int wait_for_cmd_complete(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868{
2869 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2870 int ret = FAILURE, cnt = 0;
2871 u64 val64;
2872
2873 while (TRUE) {
2874 val64 = readq(&bar0->rmac_addr_cmd_mem);
2875 if (!(val64 & RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
2876 ret = SUCCESS;
2877 break;
2878 }
2879 msleep(50);
2880 if (cnt++ > 10)
2881 break;
2882 }
2883
2884 return ret;
2885}
2886
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002887/**
2888 * s2io_reset - Resets the card.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 * @sp : private member of the device structure.
2890 * Description: Function to Reset the card. This function then also
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002891 * restores the previously saved PCI configuration space registers as
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 * the card reset also resets the configuration space.
2893 * Return value:
2894 * void.
2895 */
2896
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002897void s2io_reset(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898{
2899 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2900 u64 val64;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002901 u16 subid, pci_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002903 /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002904 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002905
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 val64 = SW_RESET_ALL;
2907 writeq(val64, &bar0->sw_reset);
2908
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002909 /*
2910 * At this stage, if the PCI write is indeed completed, the
2911 * card is reset and so is the PCI Config space of the device.
2912 * So a read cannot be issued at this stage on any of the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 * registers to ensure the write into "sw_reset" register
2914 * has gone through.
2915 * Question: Is there any system call that will explicitly force
2916 * all the write commands still pending on the bus to be pushed
2917 * through?
2918 * As of now I'am just giving a 250ms delay and hoping that the
2919 * PCI write to sw_reset register is done by this time.
2920 */
2921 msleep(250);
2922
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002923 /* Restore the PCI state saved during initialization. */
2924 pci_restore_state(sp->pdev);
2925 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002926 pci_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 s2io_init_pci(sp);
2928
2929 msleep(250);
2930
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002931 /* Set swapper to enable I/O register access */
2932 s2io_set_swapper(sp);
2933
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002934 /* Restore the MSIX table entries from local variables */
2935 restore_xmsi_data(sp);
2936
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002937 /* Clear certain PCI/PCI-X fields after reset */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002938 if (sp->device_type == XFRAME_II_DEVICE) {
2939 /* Clear parity err detect bit */
2940 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002941
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002942 /* Clearing PCIX Ecc status register */
2943 pci_write_config_dword(sp->pdev, 0x68, 0x7C);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002944
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002945 /* Clearing PCI_STATUS error reflected here */
2946 writeq(BIT(62), &bar0->txpic_int_reg);
2947 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002948
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002949 /* Reset device statistics maintained by OS */
2950 memset(&sp->stats, 0, sizeof (struct net_device_stats));
2951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 /* SXE-002: Configure link and activity LED to turn it off */
2953 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002954 if (((subid & 0xFF) >= 0x07) &&
2955 (sp->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 val64 = readq(&bar0->gpio_control);
2957 val64 |= 0x0000800000000000ULL;
2958 writeq(val64, &bar0->gpio_control);
2959 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002960 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 }
2962
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002963 /*
2964 * Clear spurious ECC interrupts that would have occured on
2965 * XFRAME II cards after reset.
2966 */
2967 if (sp->device_type == XFRAME_II_DEVICE) {
2968 val64 = readq(&bar0->pcc_err_reg);
2969 writeq(val64, &bar0->pcc_err_reg);
2970 }
2971
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 sp->device_enabled_once = FALSE;
2973}
2974
2975/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002976 * s2io_set_swapper - to set the swapper controle on the card
2977 * @sp : private member of the device structure,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 * pointer to the s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002979 * Description: Function to set the swapper control on the card
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 * correctly depending on the 'endianness' of the system.
2981 * Return value:
2982 * SUCCESS on success and FAILURE on failure.
2983 */
2984
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002985int s2io_set_swapper(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986{
2987 struct net_device *dev = sp->dev;
2988 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2989 u64 val64, valt, valr;
2990
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002991 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 * Set proper endian settings and verify the same by reading
2993 * the PIF Feed-back register.
2994 */
2995
2996 val64 = readq(&bar0->pif_rd_swapper_fb);
2997 if (val64 != 0x0123456789ABCDEFULL) {
2998 int i = 0;
2999 u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
3000 0x8100008181000081ULL, /* FE=1, SE=0 */
3001 0x4200004242000042ULL, /* FE=0, SE=1 */
3002 0}; /* FE=0, SE=0 */
3003
3004 while(i<4) {
3005 writeq(value[i], &bar0->swapper_ctrl);
3006 val64 = readq(&bar0->pif_rd_swapper_fb);
3007 if (val64 == 0x0123456789ABCDEFULL)
3008 break;
3009 i++;
3010 }
3011 if (i == 4) {
3012 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3013 dev->name);
3014 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3015 (unsigned long long) val64);
3016 return FAILURE;
3017 }
3018 valr = value[i];
3019 } else {
3020 valr = readq(&bar0->swapper_ctrl);
3021 }
3022
3023 valt = 0x0123456789ABCDEFULL;
3024 writeq(valt, &bar0->xmsi_address);
3025 val64 = readq(&bar0->xmsi_address);
3026
3027 if(val64 != valt) {
3028 int i = 0;
3029 u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
3030 0x0081810000818100ULL, /* FE=1, SE=0 */
3031 0x0042420000424200ULL, /* FE=0, SE=1 */
3032 0}; /* FE=0, SE=0 */
3033
3034 while(i<4) {
3035 writeq((value[i] | valr), &bar0->swapper_ctrl);
3036 writeq(valt, &bar0->xmsi_address);
3037 val64 = readq(&bar0->xmsi_address);
3038 if(val64 == valt)
3039 break;
3040 i++;
3041 }
3042 if(i == 4) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003043 unsigned long long x = val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003045 DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 return FAILURE;
3047 }
3048 }
3049 val64 = readq(&bar0->swapper_ctrl);
3050 val64 &= 0xFFFF000000000000ULL;
3051
3052#ifdef __BIG_ENDIAN
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003053 /*
3054 * The device by default set to a big endian format, so a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 * big endian driver need not set anything.
3056 */
3057 val64 |= (SWAPPER_CTRL_TXP_FE |
3058 SWAPPER_CTRL_TXP_SE |
3059 SWAPPER_CTRL_TXD_R_FE |
3060 SWAPPER_CTRL_TXD_W_FE |
3061 SWAPPER_CTRL_TXF_R_FE |
3062 SWAPPER_CTRL_RXD_R_FE |
3063 SWAPPER_CTRL_RXD_W_FE |
3064 SWAPPER_CTRL_RXF_W_FE |
3065 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Andrew Morton92383342005-10-16 00:11:29 -07003067 if (sp->intr_type == INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003068 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 writeq(val64, &bar0->swapper_ctrl);
3070#else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003071 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 * Initially we enable all bits to make it accessible by the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003073 * driver, then we selectively enable only those bits that
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 * we want to set.
3075 */
3076 val64 |= (SWAPPER_CTRL_TXP_FE |
3077 SWAPPER_CTRL_TXP_SE |
3078 SWAPPER_CTRL_TXD_R_FE |
3079 SWAPPER_CTRL_TXD_R_SE |
3080 SWAPPER_CTRL_TXD_W_FE |
3081 SWAPPER_CTRL_TXD_W_SE |
3082 SWAPPER_CTRL_TXF_R_FE |
3083 SWAPPER_CTRL_RXD_R_FE |
3084 SWAPPER_CTRL_RXD_R_SE |
3085 SWAPPER_CTRL_RXD_W_FE |
3086 SWAPPER_CTRL_RXD_W_SE |
3087 SWAPPER_CTRL_RXF_W_FE |
3088 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003090 if (sp->intr_type == INTA)
3091 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 writeq(val64, &bar0->swapper_ctrl);
3093#endif
3094 val64 = readq(&bar0->swapper_ctrl);
3095
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003096 /*
3097 * Verifying if endian settings are accurate by reading a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 * feedback register.
3099 */
3100 val64 = readq(&bar0->pif_rd_swapper_fb);
3101 if (val64 != 0x0123456789ABCDEFULL) {
3102 /* Endian settings are incorrect, calls for another dekko. */
3103 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3104 dev->name);
3105 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3106 (unsigned long long) val64);
3107 return FAILURE;
3108 }
3109
3110 return SUCCESS;
3111}
3112
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003113static int wait_for_msix_trans(nic_t *nic, int i)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003114{
Al Viro37eb47e2005-12-15 09:17:29 +00003115 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003116 u64 val64;
3117 int ret = 0, cnt = 0;
3118
3119 do {
3120 val64 = readq(&bar0->xmsi_access);
3121 if (!(val64 & BIT(15)))
3122 break;
3123 mdelay(1);
3124 cnt++;
3125 } while(cnt < 5);
3126 if (cnt == 5) {
3127 DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
3128 ret = 1;
3129 }
3130
3131 return ret;
3132}
3133
3134void restore_xmsi_data(nic_t *nic)
3135{
Al Viro37eb47e2005-12-15 09:17:29 +00003136 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003137 u64 val64;
3138 int i;
3139
3140 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3141 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3142 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
3143 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
3144 writeq(val64, &bar0->xmsi_access);
3145 if (wait_for_msix_trans(nic, i)) {
3146 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3147 continue;
3148 }
3149 }
3150}
3151
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003152static void store_xmsi_data(nic_t *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003153{
Al Viro37eb47e2005-12-15 09:17:29 +00003154 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003155 u64 val64, addr, data;
3156 int i;
3157
3158 /* Store and display */
3159 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3160 val64 = (BIT(15) | vBIT(i, 26, 6));
3161 writeq(val64, &bar0->xmsi_access);
3162 if (wait_for_msix_trans(nic, i)) {
3163 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3164 continue;
3165 }
3166 addr = readq(&bar0->xmsi_address);
3167 data = readq(&bar0->xmsi_data);
3168 if (addr && data) {
3169 nic->msix_info[i].addr = addr;
3170 nic->msix_info[i].data = data;
3171 }
3172 }
3173}
3174
3175int s2io_enable_msi(nic_t *nic)
3176{
Al Viro37eb47e2005-12-15 09:17:29 +00003177 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003178 u16 msi_ctrl, msg_val;
3179 struct config_param *config = &nic->config;
3180 struct net_device *dev = nic->dev;
3181 u64 val64, tx_mat, rx_mat;
3182 int i, err;
3183
3184 val64 = readq(&bar0->pic_control);
3185 val64 &= ~BIT(1);
3186 writeq(val64, &bar0->pic_control);
3187
3188 err = pci_enable_msi(nic->pdev);
3189 if (err) {
3190 DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
3191 nic->dev->name);
3192 return err;
3193 }
3194
3195 /*
3196 * Enable MSI and use MSI-1 in stead of the standard MSI-0
3197 * for interrupt handling.
3198 */
3199 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3200 msg_val ^= 0x1;
3201 pci_write_config_word(nic->pdev, 0x4c, msg_val);
3202 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3203
3204 pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
3205 msi_ctrl |= 0x10;
3206 pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
3207
3208 /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
3209 tx_mat = readq(&bar0->tx_mat0_n[0]);
3210 for (i=0; i<config->tx_fifo_num; i++) {
3211 tx_mat |= TX_MAT_SET(i, 1);
3212 }
3213 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3214
3215 rx_mat = readq(&bar0->rx_mat);
3216 for (i=0; i<config->rx_ring_num; i++) {
3217 rx_mat |= RX_MAT_SET(i, 1);
3218 }
3219 writeq(rx_mat, &bar0->rx_mat);
3220
3221 dev->irq = nic->pdev->irq;
3222 return 0;
3223}
3224
3225int s2io_enable_msi_x(nic_t *nic)
3226{
Al Viro37eb47e2005-12-15 09:17:29 +00003227 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003228 u64 tx_mat, rx_mat;
3229 u16 msi_control; /* Temp variable */
3230 int ret, i, j, msix_indx = 1;
3231
3232 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
3233 GFP_KERNEL);
3234 if (nic->entries == NULL) {
3235 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3236 return -ENOMEM;
3237 }
3238 memset(nic->entries, 0, MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3239
3240 nic->s2io_entries =
3241 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
3242 GFP_KERNEL);
3243 if (nic->s2io_entries == NULL) {
3244 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3245 kfree(nic->entries);
3246 return -ENOMEM;
3247 }
3248 memset(nic->s2io_entries, 0,
3249 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3250
3251 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3252 nic->entries[i].entry = i;
3253 nic->s2io_entries[i].entry = i;
3254 nic->s2io_entries[i].arg = NULL;
3255 nic->s2io_entries[i].in_use = 0;
3256 }
3257
3258 tx_mat = readq(&bar0->tx_mat0_n[0]);
3259 for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
3260 tx_mat |= TX_MAT_SET(i, msix_indx);
3261 nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
3262 nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
3263 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3264 }
3265 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3266
3267 if (!nic->config.bimodal) {
3268 rx_mat = readq(&bar0->rx_mat);
3269 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3270 rx_mat |= RX_MAT_SET(j, msix_indx);
3271 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3272 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3273 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3274 }
3275 writeq(rx_mat, &bar0->rx_mat);
3276 } else {
3277 tx_mat = readq(&bar0->tx_mat0_n[7]);
3278 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3279 tx_mat |= TX_MAT_SET(i, msix_indx);
3280 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3281 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3282 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3283 }
3284 writeq(tx_mat, &bar0->tx_mat0_n[7]);
3285 }
3286
3287 ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
3288 if (ret) {
3289 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3290 kfree(nic->entries);
3291 kfree(nic->s2io_entries);
3292 nic->entries = NULL;
3293 nic->s2io_entries = NULL;
3294 return -ENOMEM;
3295 }
3296
3297 /*
3298 * To enable MSI-X, MSI also needs to be enabled, due to a bug
3299 * in the herc NIC. (Temp change, needs to be removed later)
3300 */
3301 pci_read_config_word(nic->pdev, 0x42, &msi_control);
3302 msi_control |= 0x1; /* Enable MSI */
3303 pci_write_config_word(nic->pdev, 0x42, msi_control);
3304
3305 return 0;
3306}
3307
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308/* ********************************************************* *
3309 * Functions defined below concern the OS part of the driver *
3310 * ********************************************************* */
3311
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003312/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 * s2io_open - open entry point of the driver
3314 * @dev : pointer to the device structure.
3315 * Description:
3316 * This function is the open entry point of the driver. It mainly calls a
3317 * function to allocate Rx buffers and inserts them into the buffer
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003318 * descriptors and then enables the Rx part of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 * Return value:
3320 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3321 * file on failure.
3322 */
3323
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003324static int s2io_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325{
3326 nic_t *sp = dev->priv;
3327 int err = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003328 int i;
3329 u16 msi_control; /* Temp variable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003331 /*
3332 * Make sure you have link off by default every time
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 * Nic is initialized
3334 */
3335 netif_carrier_off(dev);
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003336 sp->last_link_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
3338 /* Initialize H/W and enable interrupts */
3339 if (s2io_card_up(sp)) {
3340 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
3341 dev->name);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003342 err = -ENODEV;
3343 goto hw_init_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 }
3345
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003346 /* Store the values of the MSIX table in the nic_t structure */
3347 store_xmsi_data(sp);
3348
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 /* After proper initialization of H/W, register ISR */
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003350 if (sp->intr_type == MSI) {
3351 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
3352 SA_SHIRQ, sp->name, dev);
3353 if (err) {
3354 DBG_PRINT(ERR_DBG, "%s: MSI registration \
3355failed\n", dev->name);
3356 goto isr_registration_failed;
3357 }
3358 }
3359 if (sp->intr_type == MSI_X) {
3360 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
3361 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
3362 sprintf(sp->desc1, "%s:MSI-X-%d-TX",
3363 dev->name, i);
3364 err = request_irq(sp->entries[i].vector,
3365 s2io_msix_fifo_handle, 0, sp->desc1,
3366 sp->s2io_entries[i].arg);
3367 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc1,
Andrew Morton26b76252005-12-14 19:25:23 -08003368 (unsigned long long)sp->msix_info[i].addr);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003369 } else {
3370 sprintf(sp->desc2, "%s:MSI-X-%d-RX",
3371 dev->name, i);
3372 err = request_irq(sp->entries[i].vector,
3373 s2io_msix_ring_handle, 0, sp->desc2,
3374 sp->s2io_entries[i].arg);
3375 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc2,
Andrew Morton26b76252005-12-14 19:25:23 -08003376 (unsigned long long)sp->msix_info[i].addr);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003377 }
3378 if (err) {
3379 DBG_PRINT(ERR_DBG, "%s: MSI-X-%d registration \
3380failed\n", dev->name, i);
3381 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
3382 goto isr_registration_failed;
3383 }
3384 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
3385 }
3386 }
3387 if (sp->intr_type == INTA) {
3388 err = request_irq((int) sp->pdev->irq, s2io_isr, SA_SHIRQ,
3389 sp->name, dev);
3390 if (err) {
3391 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
3392 dev->name);
3393 goto isr_registration_failed;
3394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 }
3396
3397 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
3398 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003399 err = -ENODEV;
3400 goto setting_mac_address_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 }
3402
3403 netif_start_queue(dev);
3404 return 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003405
3406setting_mac_address_failed:
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003407 if (sp->intr_type != MSI_X)
3408 free_irq(sp->pdev->irq, dev);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003409isr_registration_failed:
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07003410 del_timer_sync(&sp->alarm_timer);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003411 if (sp->intr_type == MSI_X) {
3412 if (sp->device_type == XFRAME_II_DEVICE) {
3413 for (i=1; (sp->s2io_entries[i].in_use ==
3414 MSIX_REGISTERED_SUCCESS); i++) {
3415 int vector = sp->entries[i].vector;
3416 void *arg = sp->s2io_entries[i].arg;
3417
3418 free_irq(vector, arg);
3419 }
3420 pci_disable_msix(sp->pdev);
3421
3422 /* Temp */
3423 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3424 msi_control &= 0xFFFE; /* Disable MSI */
3425 pci_write_config_word(sp->pdev, 0x42, msi_control);
3426 }
3427 }
3428 else if (sp->intr_type == MSI)
3429 pci_disable_msi(sp->pdev);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003430 s2io_reset(sp);
3431hw_init_failed:
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003432 if (sp->intr_type == MSI_X) {
3433 if (sp->entries)
3434 kfree(sp->entries);
3435 if (sp->s2io_entries)
3436 kfree(sp->s2io_entries);
3437 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003438 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439}
3440
3441/**
3442 * s2io_close -close entry point of the driver
3443 * @dev : device pointer.
3444 * Description:
3445 * This is the stop entry point of the driver. It needs to undo exactly
3446 * whatever was done by the open entry point,thus it's usually referred to
3447 * as the close function.Among other things this function mainly stops the
3448 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3449 * Return value:
3450 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3451 * file on failure.
3452 */
3453
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003454static int s2io_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455{
3456 nic_t *sp = dev->priv;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003457 int i;
3458 u16 msi_control;
3459
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 flush_scheduled_work();
3461 netif_stop_queue(dev);
3462 /* Reset card, kill tasklet and free Tx and Rx buffers. */
3463 s2io_card_down(sp);
3464
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003465 if (sp->intr_type == MSI_X) {
3466 if (sp->device_type == XFRAME_II_DEVICE) {
3467 for (i=1; (sp->s2io_entries[i].in_use ==
3468 MSIX_REGISTERED_SUCCESS); i++) {
3469 int vector = sp->entries[i].vector;
3470 void *arg = sp->s2io_entries[i].arg;
3471
3472 free_irq(vector, arg);
3473 }
3474 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3475 msi_control &= 0xFFFE; /* Disable MSI */
3476 pci_write_config_word(sp->pdev, 0x42, msi_control);
3477
3478 pci_disable_msix(sp->pdev);
3479 }
3480 }
3481 else {
3482 free_irq(sp->pdev->irq, dev);
3483 if (sp->intr_type == MSI)
3484 pci_disable_msi(sp->pdev);
3485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 sp->device_close_flag = TRUE; /* Device is shut down. */
3487 return 0;
3488}
3489
3490/**
3491 * s2io_xmit - Tx entry point of te driver
3492 * @skb : the socket buffer containing the Tx data.
3493 * @dev : device pointer.
3494 * Description :
3495 * This function is the Tx entry point of the driver. S2IO NIC supports
3496 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
3497 * NOTE: when device cant queue the pkt,just the trans_start variable will
3498 * not be upadted.
3499 * Return value:
3500 * 0 on success & 1 on failure.
3501 */
3502
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003503static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504{
3505 nic_t *sp = dev->priv;
3506 u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
3507 register u64 val64;
3508 TxD_t *txdp;
3509 TxFIFO_element_t __iomem *tx_fifo;
3510 unsigned long flags;
3511#ifdef NETIF_F_TSO
3512 int mss;
3513#endif
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003514 u16 vlan_tag = 0;
3515 int vlan_priority = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 mac_info_t *mac_control;
3517 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
3519 mac_control = &sp->mac_control;
3520 config = &sp->config;
3521
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003522 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 spin_lock_irqsave(&sp->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 if (atomic_read(&sp->card_state) == CARD_DOWN) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003525 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 dev->name);
3527 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003528 dev_kfree_skb(skb);
3529 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 }
3531
3532 queue = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003534 /* Get Fifo number to Transmit based on vlan priority */
3535 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
3536 vlan_tag = vlan_tx_tag_get(skb);
3537 vlan_priority = vlan_tag >> 13;
3538 queue = config->fifo_mapping[vlan_priority];
3539 }
3540
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003541 put_off = (u16) mac_control->fifos[queue].tx_curr_put_info.offset;
3542 get_off = (u16) mac_control->fifos[queue].tx_curr_get_info.offset;
3543 txdp = (TxD_t *) mac_control->fifos[queue].list_info[put_off].
3544 list_virt_addr;
3545
3546 queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 /* Avoid "put" pointer going beyond "get" pointer */
3548 if (txdp->Host_Control || (((put_off + 1) % queue_len) == get_off)) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003549 DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 netif_stop_queue(dev);
3551 dev_kfree_skb(skb);
3552 spin_unlock_irqrestore(&sp->tx_lock, flags);
3553 return 0;
3554 }
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003555
3556 /* A buffer with no data will be dropped */
3557 if (!skb->len) {
3558 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
3559 dev_kfree_skb(skb);
3560 spin_unlock_irqrestore(&sp->tx_lock, flags);
3561 return 0;
3562 }
3563
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003564 txdp->Control_1 = 0;
3565 txdp->Control_2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566#ifdef NETIF_F_TSO
3567 mss = skb_shinfo(skb)->tso_size;
3568 if (mss) {
3569 txdp->Control_1 |= TXD_TCP_LSO_EN;
3570 txdp->Control_1 |= TXD_TCP_LSO_MSS(mss);
3571 }
3572#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 if (skb->ip_summed == CHECKSUM_HW) {
3574 txdp->Control_2 |=
3575 (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
3576 TXD_TX_CKO_UDP_EN);
3577 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003578 txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
3579 txdp->Control_1 |= TXD_LIST_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 txdp->Control_2 |= config->tx_intr_type;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07003581
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003582 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
3583 txdp->Control_2 |= TXD_VLAN_ENABLE;
3584 txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
3585 }
3586
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003587 frg_len = skb->len - skb->data_len;
3588 if (skb_shinfo(skb)->ufo_size) {
3589 int ufo_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003591 ufo_size = skb_shinfo(skb)->ufo_size;
3592 ufo_size &= ~7;
3593 txdp->Control_1 |= TXD_UFO_EN;
3594 txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
3595 txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
3596#ifdef __BIG_ENDIAN
3597 sp->ufo_in_band_v[put_off] =
3598 (u64)skb_shinfo(skb)->ip6_frag_id;
3599#else
3600 sp->ufo_in_band_v[put_off] =
3601 (u64)skb_shinfo(skb)->ip6_frag_id << 32;
3602#endif
3603 txdp->Host_Control = (unsigned long)sp->ufo_in_band_v;
3604 txdp->Buffer_Pointer = pci_map_single(sp->pdev,
3605 sp->ufo_in_band_v,
3606 sizeof(u64), PCI_DMA_TODEVICE);
3607 txdp++;
3608 txdp->Control_1 = 0;
3609 txdp->Control_2 = 0;
3610 }
3611
3612 txdp->Buffer_Pointer = pci_map_single
3613 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
3614 txdp->Host_Control = (unsigned long) skb;
3615 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
3616
3617 if (skb_shinfo(skb)->ufo_size)
3618 txdp->Control_1 |= TXD_UFO_EN;
3619
3620 frg_cnt = skb_shinfo(skb)->nr_frags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 /* For fragmented SKB. */
3622 for (i = 0; i < frg_cnt; i++) {
3623 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003624 /* A '0' length fragment will be ignored */
3625 if (!frag->size)
3626 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 txdp++;
3628 txdp->Buffer_Pointer = (u64) pci_map_page
3629 (sp->pdev, frag->page, frag->page_offset,
3630 frag->size, PCI_DMA_TODEVICE);
Ananda Rajuefd51b52006-01-19 14:11:54 -05003631 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003632 if (skb_shinfo(skb)->ufo_size)
3633 txdp->Control_1 |= TXD_UFO_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 }
3635 txdp->Control_1 |= TXD_GATHER_CODE_LAST;
3636
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003637 if (skb_shinfo(skb)->ufo_size)
3638 frg_cnt++; /* as Txd0 was used for inband header */
3639
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 tx_fifo = mac_control->tx_FIFO_start[queue];
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003641 val64 = mac_control->fifos[queue].list_info[put_off].list_phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 writeq(val64, &tx_fifo->TxDL_Pointer);
3643
3644 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
3645 TX_FIFO_LAST_LIST);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003646
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647#ifdef NETIF_F_TSO
3648 if (mss)
3649 val64 |= TX_FIFO_SPECIAL_FUNC;
3650#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003651 if (skb_shinfo(skb)->ufo_size)
3652 val64 |= TX_FIFO_SPECIAL_FUNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 writeq(val64, &tx_fifo->List_Control);
3654
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003655 mmiowb();
3656
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 put_off++;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003658 put_off %= mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
3659 mac_control->fifos[queue].tx_curr_put_info.offset = put_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660
3661 /* Avoid "put" pointer going beyond "get" pointer */
3662 if (((put_off + 1) % queue_len) == get_off) {
3663 DBG_PRINT(TX_DBG,
3664 "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
3665 put_off, get_off);
3666 netif_stop_queue(dev);
3667 }
3668
3669 dev->trans_start = jiffies;
3670 spin_unlock_irqrestore(&sp->tx_lock, flags);
3671
3672 return 0;
3673}
3674
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07003675static void
3676s2io_alarm_handle(unsigned long data)
3677{
3678 nic_t *sp = (nic_t *)data;
3679
3680 alarm_intr_handler(sp);
3681 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
3682}
3683
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003684static irqreturn_t
3685s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
3686{
3687 struct net_device *dev = (struct net_device *) dev_id;
3688 nic_t *sp = dev->priv;
3689 int i;
3690 int ret;
3691 mac_info_t *mac_control;
3692 struct config_param *config;
3693
3694 atomic_inc(&sp->isr_cnt);
3695 mac_control = &sp->mac_control;
3696 config = &sp->config;
3697 DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
3698
3699 /* If Intr is because of Rx Traffic */
3700 for (i = 0; i < config->rx_ring_num; i++)
3701 rx_intr_handler(&mac_control->rings[i]);
3702
3703 /* If Intr is because of Tx Traffic */
3704 for (i = 0; i < config->tx_fifo_num; i++)
3705 tx_intr_handler(&mac_control->fifos[i]);
3706
3707 /*
3708 * If the Rx buffer count is below the panic threshold then
3709 * reallocate the buffers from the interrupt handler itself,
3710 * else schedule a tasklet to reallocate the buffers.
3711 */
3712 for (i = 0; i < config->rx_ring_num; i++) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003713 if (!sp->lro) {
3714 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
3715 int level = rx_buffer_level(sp, rxb_size, i);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003716
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003717 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3718 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
3719 dev->name);
3720 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3721 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
3722 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3723 dev->name);
3724 DBG_PRINT(ERR_DBG, " in ISR!!\n");
3725 clear_bit(0, (&sp->tasklet_status));
3726 atomic_dec(&sp->isr_cnt);
3727 return IRQ_HANDLED;
3728 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003729 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003730 } else if (level == LOW) {
3731 tasklet_schedule(&sp->task);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003732 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003733 }
3734 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
3735 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3736 dev->name);
3737 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
3738 break;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003739 }
3740 }
3741
3742 atomic_dec(&sp->isr_cnt);
3743 return IRQ_HANDLED;
3744}
3745
3746static irqreturn_t
3747s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs)
3748{
3749 ring_info_t *ring = (ring_info_t *)dev_id;
3750 nic_t *sp = ring->nic;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003751 struct net_device *dev = (struct net_device *) dev_id;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003752 int rxb_size, level, rng_n;
3753
3754 atomic_inc(&sp->isr_cnt);
3755 rx_intr_handler(ring);
3756
3757 rng_n = ring->ring_no;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003758 if (!sp->lro) {
3759 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
3760 level = rx_buffer_level(sp, rxb_size, rng_n);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003761
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003762 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3763 int ret;
3764 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
3765 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3766 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
3767 DBG_PRINT(ERR_DBG, "Out of memory in %s",
3768 __FUNCTION__);
3769 clear_bit(0, (&sp->tasklet_status));
3770 return IRQ_HANDLED;
3771 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003772 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003773 } else if (level == LOW) {
3774 tasklet_schedule(&sp->task);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003775 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003776 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003777 else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
3778 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
3779 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
3780 }
3781
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003782 atomic_dec(&sp->isr_cnt);
3783
3784 return IRQ_HANDLED;
3785}
3786
3787static irqreturn_t
3788s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs)
3789{
3790 fifo_info_t *fifo = (fifo_info_t *)dev_id;
3791 nic_t *sp = fifo->nic;
3792
3793 atomic_inc(&sp->isr_cnt);
3794 tx_intr_handler(fifo);
3795 atomic_dec(&sp->isr_cnt);
3796 return IRQ_HANDLED;
3797}
3798
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003799static void s2io_txpic_intr_handle(nic_t *sp)
3800{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01003801 XENA_dev_config_t __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003802 u64 val64;
3803
3804 val64 = readq(&bar0->pic_int_status);
3805 if (val64 & PIC_INT_GPIO) {
3806 val64 = readq(&bar0->gpio_int_reg);
3807 if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
3808 (val64 & GPIO_INT_REG_LINK_UP)) {
3809 val64 |= GPIO_INT_REG_LINK_DOWN;
3810 val64 |= GPIO_INT_REG_LINK_UP;
3811 writeq(val64, &bar0->gpio_int_reg);
3812 goto masking;
3813 }
3814
3815 if (((sp->last_link_state == LINK_UP) &&
3816 (val64 & GPIO_INT_REG_LINK_DOWN)) ||
3817 ((sp->last_link_state == LINK_DOWN) &&
3818 (val64 & GPIO_INT_REG_LINK_UP))) {
3819 val64 = readq(&bar0->gpio_int_mask);
3820 val64 |= GPIO_INT_MASK_LINK_DOWN;
3821 val64 |= GPIO_INT_MASK_LINK_UP;
3822 writeq(val64, &bar0->gpio_int_mask);
3823 s2io_set_link((unsigned long)sp);
3824 }
3825masking:
3826 if (sp->last_link_state == LINK_UP) {
3827 /*enable down interrupt */
3828 val64 = readq(&bar0->gpio_int_mask);
3829 /* unmasks link down intr */
3830 val64 &= ~GPIO_INT_MASK_LINK_DOWN;
3831 /* masks link up intr */
3832 val64 |= GPIO_INT_MASK_LINK_UP;
3833 writeq(val64, &bar0->gpio_int_mask);
3834 } else {
3835 /*enable UP Interrupt */
3836 val64 = readq(&bar0->gpio_int_mask);
3837 /* unmasks link up interrupt */
3838 val64 &= ~GPIO_INT_MASK_LINK_UP;
3839 /* masks link down interrupt */
3840 val64 |= GPIO_INT_MASK_LINK_DOWN;
3841 writeq(val64, &bar0->gpio_int_mask);
3842 }
3843 }
3844}
3845
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846/**
3847 * s2io_isr - ISR handler of the device .
3848 * @irq: the irq of the device.
3849 * @dev_id: a void pointer to the dev structure of the NIC.
3850 * @pt_regs: pointer to the registers pushed on the stack.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003851 * Description: This function is the ISR handler of the device. It
3852 * identifies the reason for the interrupt and calls the relevant
3853 * service routines. As a contongency measure, this ISR allocates the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 * recv buffers, if their numbers are below the panic value which is
3855 * presently set to 25% of the original number of rcv buffers allocated.
3856 * Return value:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003857 * IRQ_HANDLED: will be returned if IRQ was handled by this routine
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 * IRQ_NONE: will be returned if interrupt is not from our device
3859 */
3860static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs)
3861{
3862 struct net_device *dev = (struct net_device *) dev_id;
3863 nic_t *sp = dev->priv;
3864 XENA_dev_config_t __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003865 int i;
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07003866 u64 reason = 0, val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 mac_info_t *mac_control;
3868 struct config_param *config;
3869
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003870 atomic_inc(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 mac_control = &sp->mac_control;
3872 config = &sp->config;
3873
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003874 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 * Identify the cause for interrupt and call the appropriate
3876 * interrupt handler. Causes for the interrupt could be;
3877 * 1. Rx of packet.
3878 * 2. Tx complete.
3879 * 3. Link down.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003880 * 4. Error in any functional blocks of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 */
3882 reason = readq(&bar0->general_int_status);
3883
3884 if (!reason) {
3885 /* The interrupt was not raised by Xena. */
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003886 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 return IRQ_NONE;
3888 }
3889
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890#ifdef CONFIG_S2IO_NAPI
3891 if (reason & GEN_INTR_RXTRAFFIC) {
3892 if (netif_rx_schedule_prep(dev)) {
3893 en_dis_able_nic_intrs(sp, RX_TRAFFIC_INTR,
3894 DISABLE_INTRS);
3895 __netif_rx_schedule(dev);
3896 }
3897 }
3898#else
3899 /* If Intr is because of Rx Traffic */
3900 if (reason & GEN_INTR_RXTRAFFIC) {
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07003901 /*
3902 * rx_traffic_int reg is an R1 register, writing all 1's
3903 * will ensure that the actual interrupt causing bit get's
3904 * cleared and hence a read can be avoided.
3905 */
3906 val64 = 0xFFFFFFFFFFFFFFFFULL;
3907 writeq(val64, &bar0->rx_traffic_int);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003908 for (i = 0; i < config->rx_ring_num; i++) {
3909 rx_intr_handler(&mac_control->rings[i]);
3910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 }
3912#endif
3913
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003914 /* If Intr is because of Tx Traffic */
3915 if (reason & GEN_INTR_TXTRAFFIC) {
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07003916 /*
3917 * tx_traffic_int reg is an R1 register, writing all 1's
3918 * will ensure that the actual interrupt causing bit get's
3919 * cleared and hence a read can be avoided.
3920 */
3921 val64 = 0xFFFFFFFFFFFFFFFFULL;
3922 writeq(val64, &bar0->tx_traffic_int);
3923
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003924 for (i = 0; i < config->tx_fifo_num; i++)
3925 tx_intr_handler(&mac_control->fifos[i]);
3926 }
3927
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003928 if (reason & GEN_INTR_TXPIC)
3929 s2io_txpic_intr_handle(sp);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003930 /*
3931 * If the Rx buffer count is below the panic threshold then
3932 * reallocate the buffers from the interrupt handler itself,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 * else schedule a tasklet to reallocate the buffers.
3934 */
3935#ifndef CONFIG_S2IO_NAPI
3936 for (i = 0; i < config->rx_ring_num; i++) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003937 if (!sp->lro) {
3938 int ret;
3939 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
3940 int level = rx_buffer_level(sp, rxb_size, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003942 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3943 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
3944 dev->name);
3945 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3946 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
3947 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3948 dev->name);
3949 DBG_PRINT(ERR_DBG, " in ISR!!\n");
3950 clear_bit(0, (&sp->tasklet_status));
3951 atomic_dec(&sp->isr_cnt);
3952 return IRQ_HANDLED;
3953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003955 } else if (level == LOW) {
3956 tasklet_schedule(&sp->task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003958 }
3959 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
3960 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3961 dev->name);
3962 DBG_PRINT(ERR_DBG, " in Rx intr!!\n");
3963 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 }
3965 }
3966#endif
3967
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003968 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 return IRQ_HANDLED;
3970}
3971
3972/**
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003973 * s2io_updt_stats -
3974 */
3975static void s2io_updt_stats(nic_t *sp)
3976{
3977 XENA_dev_config_t __iomem *bar0 = sp->bar0;
3978 u64 val64;
3979 int cnt = 0;
3980
3981 if (atomic_read(&sp->card_state) == CARD_UP) {
3982 /* Apprx 30us on a 133 MHz bus */
3983 val64 = SET_UPDT_CLICKS(10) |
3984 STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
3985 writeq(val64, &bar0->stat_cfg);
3986 do {
3987 udelay(100);
3988 val64 = readq(&bar0->stat_cfg);
3989 if (!(val64 & BIT(0)))
3990 break;
3991 cnt++;
3992 if (cnt == 5)
3993 break; /* Updt failed */
3994 } while(1);
3995 }
3996}
3997
3998/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003999 * s2io_get_stats - Updates the device statistics structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 * @dev : pointer to the device structure.
4001 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004002 * This function updates the device statistics structure in the s2io_nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 * structure and returns a pointer to the same.
4004 * Return value:
4005 * pointer to the updated net_device_stats structure.
4006 */
4007
Adrian Bunkac1f60d2005-11-06 01:46:47 +01004008static struct net_device_stats *s2io_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009{
4010 nic_t *sp = dev->priv;
4011 mac_info_t *mac_control;
4012 struct config_param *config;
4013
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004014
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 mac_control = &sp->mac_control;
4016 config = &sp->config;
4017
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004018 /* Configure Stats for immediate updt */
4019 s2io_updt_stats(sp);
4020
4021 sp->stats.tx_packets =
4022 le32_to_cpu(mac_control->stats_info->tmac_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004023 sp->stats.tx_errors =
4024 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
4025 sp->stats.rx_errors =
4026 le32_to_cpu(mac_control->stats_info->rmac_drop_frms);
4027 sp->stats.multicast =
4028 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 sp->stats.rx_length_errors =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004030 le32_to_cpu(mac_control->stats_info->rmac_long_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
4032 return (&sp->stats);
4033}
4034
4035/**
4036 * s2io_set_multicast - entry point for multicast address enable/disable.
4037 * @dev : pointer to the device structure
4038 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004039 * This function is a driver entry point which gets called by the kernel
4040 * whenever multicast addresses must be enabled/disabled. This also gets
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 * called to set/reset promiscuous mode. Depending on the deivce flag, we
4042 * determine, if multicast address must be enabled or if promiscuous mode
4043 * is to be disabled etc.
4044 * Return value:
4045 * void.
4046 */
4047
4048static void s2io_set_multicast(struct net_device *dev)
4049{
4050 int i, j, prev_cnt;
4051 struct dev_mc_list *mclist;
4052 nic_t *sp = dev->priv;
4053 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4054 u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
4055 0xfeffffffffffULL;
4056 u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
4057 void __iomem *add;
4058
4059 if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
4060 /* Enable all Multicast addresses */
4061 writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
4062 &bar0->rmac_addr_data0_mem);
4063 writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
4064 &bar0->rmac_addr_data1_mem);
4065 val64 = RMAC_ADDR_CMD_MEM_WE |
4066 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4067 RMAC_ADDR_CMD_MEM_OFFSET(MAC_MC_ALL_MC_ADDR_OFFSET);
4068 writeq(val64, &bar0->rmac_addr_cmd_mem);
4069 /* Wait till command completes */
4070 wait_for_cmd_complete(sp);
4071
4072 sp->m_cast_flg = 1;
4073 sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
4074 } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
4075 /* Disable all Multicast addresses */
4076 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4077 &bar0->rmac_addr_data0_mem);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07004078 writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
4079 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 val64 = RMAC_ADDR_CMD_MEM_WE |
4081 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4082 RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
4083 writeq(val64, &bar0->rmac_addr_cmd_mem);
4084 /* Wait till command completes */
4085 wait_for_cmd_complete(sp);
4086
4087 sp->m_cast_flg = 0;
4088 sp->all_multi_pos = 0;
4089 }
4090
4091 if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
4092 /* Put the NIC into promiscuous mode */
4093 add = &bar0->mac_cfg;
4094 val64 = readq(&bar0->mac_cfg);
4095 val64 |= MAC_CFG_RMAC_PROM_ENABLE;
4096
4097 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4098 writel((u32) val64, add);
4099 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4100 writel((u32) (val64 >> 32), (add + 4));
4101
4102 val64 = readq(&bar0->mac_cfg);
4103 sp->promisc_flg = 1;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004104 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 dev->name);
4106 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
4107 /* Remove the NIC from promiscuous mode */
4108 add = &bar0->mac_cfg;
4109 val64 = readq(&bar0->mac_cfg);
4110 val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
4111
4112 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4113 writel((u32) val64, add);
4114 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4115 writel((u32) (val64 >> 32), (add + 4));
4116
4117 val64 = readq(&bar0->mac_cfg);
4118 sp->promisc_flg = 0;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004119 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 dev->name);
4121 }
4122
4123 /* Update individual M_CAST address list */
4124 if ((!sp->m_cast_flg) && dev->mc_count) {
4125 if (dev->mc_count >
4126 (MAX_ADDRS_SUPPORTED - MAC_MC_ADDR_START_OFFSET - 1)) {
4127 DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
4128 dev->name);
4129 DBG_PRINT(ERR_DBG, "can be added, please enable ");
4130 DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
4131 return;
4132 }
4133
4134 prev_cnt = sp->mc_addr_count;
4135 sp->mc_addr_count = dev->mc_count;
4136
4137 /* Clear out the previous list of Mc in the H/W. */
4138 for (i = 0; i < prev_cnt; i++) {
4139 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4140 &bar0->rmac_addr_data0_mem);
4141 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004142 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 val64 = RMAC_ADDR_CMD_MEM_WE |
4144 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4145 RMAC_ADDR_CMD_MEM_OFFSET
4146 (MAC_MC_ADDR_START_OFFSET + i);
4147 writeq(val64, &bar0->rmac_addr_cmd_mem);
4148
4149 /* Wait for command completes */
4150 if (wait_for_cmd_complete(sp)) {
4151 DBG_PRINT(ERR_DBG, "%s: Adding ",
4152 dev->name);
4153 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4154 return;
4155 }
4156 }
4157
4158 /* Create the new Rx filter list and update the same in H/W. */
4159 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
4160 i++, mclist = mclist->next) {
4161 memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
4162 ETH_ALEN);
4163 for (j = 0; j < ETH_ALEN; j++) {
4164 mac_addr |= mclist->dmi_addr[j];
4165 mac_addr <<= 8;
4166 }
4167 mac_addr >>= 8;
4168 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4169 &bar0->rmac_addr_data0_mem);
4170 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004171 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 val64 = RMAC_ADDR_CMD_MEM_WE |
4173 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4174 RMAC_ADDR_CMD_MEM_OFFSET
4175 (i + MAC_MC_ADDR_START_OFFSET);
4176 writeq(val64, &bar0->rmac_addr_cmd_mem);
4177
4178 /* Wait for command completes */
4179 if (wait_for_cmd_complete(sp)) {
4180 DBG_PRINT(ERR_DBG, "%s: Adding ",
4181 dev->name);
4182 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4183 return;
4184 }
4185 }
4186 }
4187}
4188
4189/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004190 * s2io_set_mac_addr - Programs the Xframe mac address
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 * @dev : pointer to the device structure.
4192 * @addr: a uchar pointer to the new mac address which is to be set.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004193 * Description : This procedure will program the Xframe to receive
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 * frames with new Mac Address
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004195 * Return value: SUCCESS on success and an appropriate (-)ve integer
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 * as defined in errno.h file on failure.
4197 */
4198
4199int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
4200{
4201 nic_t *sp = dev->priv;
4202 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4203 register u64 val64, mac_addr = 0;
4204 int i;
4205
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004206 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 * Set the new MAC address as the new unicast filter and reflect this
4208 * change on the device address registered with the OS. It will be
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004209 * at offset 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 */
4211 for (i = 0; i < ETH_ALEN; i++) {
4212 mac_addr <<= 8;
4213 mac_addr |= addr[i];
4214 }
4215
4216 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4217 &bar0->rmac_addr_data0_mem);
4218
4219 val64 =
4220 RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4221 RMAC_ADDR_CMD_MEM_OFFSET(0);
4222 writeq(val64, &bar0->rmac_addr_cmd_mem);
4223 /* Wait till command completes */
4224 if (wait_for_cmd_complete(sp)) {
4225 DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
4226 return FAILURE;
4227 }
4228
4229 return SUCCESS;
4230}
4231
4232/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004233 * s2io_ethtool_sset - Sets different link parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
4235 * @info: pointer to the structure with parameters given by ethtool to set
4236 * link information.
4237 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004238 * The function sets different link parameters provided by the user onto
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 * the NIC.
4240 * Return value:
4241 * 0 on success.
4242*/
4243
4244static int s2io_ethtool_sset(struct net_device *dev,
4245 struct ethtool_cmd *info)
4246{
4247 nic_t *sp = dev->priv;
4248 if ((info->autoneg == AUTONEG_ENABLE) ||
4249 (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
4250 return -EINVAL;
4251 else {
4252 s2io_close(sp->dev);
4253 s2io_open(sp->dev);
4254 }
4255
4256 return 0;
4257}
4258
4259/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004260 * s2io_ethtol_gset - Return link specific information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 * @sp : private member of the device structure, pointer to the
4262 * s2io_nic structure.
4263 * @info : pointer to the structure with parameters given by ethtool
4264 * to return link information.
4265 * Description:
4266 * Returns link specific information like speed, duplex etc.. to ethtool.
4267 * Return value :
4268 * return 0 on success.
4269 */
4270
4271static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
4272{
4273 nic_t *sp = dev->priv;
4274 info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4275 info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4276 info->port = PORT_FIBRE;
4277 /* info->transceiver?? TODO */
4278
4279 if (netif_carrier_ok(sp->dev)) {
4280 info->speed = 10000;
4281 info->duplex = DUPLEX_FULL;
4282 } else {
4283 info->speed = -1;
4284 info->duplex = -1;
4285 }
4286
4287 info->autoneg = AUTONEG_DISABLE;
4288 return 0;
4289}
4290
4291/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004292 * s2io_ethtool_gdrvinfo - Returns driver specific information.
4293 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 * s2io_nic structure.
4295 * @info : pointer to the structure with parameters given by ethtool to
4296 * return driver information.
4297 * Description:
4298 * Returns driver specefic information like name, version etc.. to ethtool.
4299 * Return value:
4300 * void
4301 */
4302
4303static void s2io_ethtool_gdrvinfo(struct net_device *dev,
4304 struct ethtool_drvinfo *info)
4305{
4306 nic_t *sp = dev->priv;
4307
John W. Linvilledbc23092005-09-28 17:50:51 -04004308 strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
4309 strncpy(info->version, s2io_driver_version, sizeof(info->version));
4310 strncpy(info->fw_version, "", sizeof(info->fw_version));
4311 strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 info->regdump_len = XENA_REG_SPACE;
4313 info->eedump_len = XENA_EEPROM_SPACE;
4314 info->testinfo_len = S2IO_TEST_LEN;
4315 info->n_stats = S2IO_STAT_LEN;
4316}
4317
4318/**
4319 * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004320 * @sp: private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004322 * @regs : pointer to the structure with parameters given by ethtool for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 * dumping the registers.
4324 * @reg_space: The input argumnet into which all the registers are dumped.
4325 * Description:
4326 * Dumps the entire register space of xFrame NIC into the user given
4327 * buffer area.
4328 * Return value :
4329 * void .
4330*/
4331
4332static void s2io_ethtool_gregs(struct net_device *dev,
4333 struct ethtool_regs *regs, void *space)
4334{
4335 int i;
4336 u64 reg;
4337 u8 *reg_space = (u8 *) space;
4338 nic_t *sp = dev->priv;
4339
4340 regs->len = XENA_REG_SPACE;
4341 regs->version = sp->pdev->subsystem_device;
4342
4343 for (i = 0; i < regs->len; i += 8) {
4344 reg = readq(sp->bar0 + i);
4345 memcpy((reg_space + i), &reg, 8);
4346 }
4347}
4348
4349/**
4350 * s2io_phy_id - timer function that alternates adapter LED.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004351 * @data : address of the private member of the device structure, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 * is a pointer to the s2io_nic structure, provided as an u32.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004353 * Description: This is actually the timer function that alternates the
4354 * adapter LED bit of the adapter control bit to set/reset every time on
4355 * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 * once every second.
4357*/
4358static void s2io_phy_id(unsigned long data)
4359{
4360 nic_t *sp = (nic_t *) data;
4361 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4362 u64 val64 = 0;
4363 u16 subid;
4364
4365 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004366 if ((sp->device_type == XFRAME_II_DEVICE) ||
4367 ((subid & 0xFF) >= 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 val64 = readq(&bar0->gpio_control);
4369 val64 ^= GPIO_CTRL_GPIO_0;
4370 writeq(val64, &bar0->gpio_control);
4371 } else {
4372 val64 = readq(&bar0->adapter_control);
4373 val64 ^= ADAPTER_LED_ON;
4374 writeq(val64, &bar0->adapter_control);
4375 }
4376
4377 mod_timer(&sp->id_timer, jiffies + HZ / 2);
4378}
4379
4380/**
4381 * s2io_ethtool_idnic - To physically identify the nic on the system.
4382 * @sp : private member of the device structure, which is a pointer to the
4383 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004384 * @id : pointer to the structure with identification parameters given by
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 * ethtool.
4386 * Description: Used to physically identify the NIC on the system.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004387 * The Link LED will blink for a time specified by the user for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 * identification.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004389 * NOTE: The Link has to be Up to be able to blink the LED. Hence
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 * identification is possible only if it's link is up.
4391 * Return value:
4392 * int , returns 0 on success
4393 */
4394
4395static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
4396{
4397 u64 val64 = 0, last_gpio_ctrl_val;
4398 nic_t *sp = dev->priv;
4399 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4400 u16 subid;
4401
4402 subid = sp->pdev->subsystem_device;
4403 last_gpio_ctrl_val = readq(&bar0->gpio_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004404 if ((sp->device_type == XFRAME_I_DEVICE) &&
4405 ((subid & 0xFF) < 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 val64 = readq(&bar0->adapter_control);
4407 if (!(val64 & ADAPTER_CNTL_EN)) {
4408 printk(KERN_ERR
4409 "Adapter Link down, cannot blink LED\n");
4410 return -EFAULT;
4411 }
4412 }
4413 if (sp->id_timer.function == NULL) {
4414 init_timer(&sp->id_timer);
4415 sp->id_timer.function = s2io_phy_id;
4416 sp->id_timer.data = (unsigned long) sp;
4417 }
4418 mod_timer(&sp->id_timer, jiffies);
4419 if (data)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004420 msleep_interruptible(data * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004422 msleep_interruptible(MAX_FLICKER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 del_timer_sync(&sp->id_timer);
4424
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004425 if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 writeq(last_gpio_ctrl_val, &bar0->gpio_control);
4427 last_gpio_ctrl_val = readq(&bar0->gpio_control);
4428 }
4429
4430 return 0;
4431}
4432
4433/**
4434 * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004435 * @sp : private member of the device structure, which is a pointer to the
4436 * s2io_nic structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 * @ep : pointer to the structure with pause parameters given by ethtool.
4438 * Description:
4439 * Returns the Pause frame generation and reception capability of the NIC.
4440 * Return value:
4441 * void
4442 */
4443static void s2io_ethtool_getpause_data(struct net_device *dev,
4444 struct ethtool_pauseparam *ep)
4445{
4446 u64 val64;
4447 nic_t *sp = dev->priv;
4448 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4449
4450 val64 = readq(&bar0->rmac_pause_cfg);
4451 if (val64 & RMAC_PAUSE_GEN_ENABLE)
4452 ep->tx_pause = TRUE;
4453 if (val64 & RMAC_PAUSE_RX_ENABLE)
4454 ep->rx_pause = TRUE;
4455 ep->autoneg = FALSE;
4456}
4457
4458/**
4459 * s2io_ethtool_setpause_data - set/reset pause frame generation.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004460 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 * s2io_nic structure.
4462 * @ep : pointer to the structure with pause parameters given by ethtool.
4463 * Description:
4464 * It can be used to set or reset Pause frame generation or reception
4465 * support of the NIC.
4466 * Return value:
4467 * int, returns 0 on Success
4468 */
4469
4470static int s2io_ethtool_setpause_data(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004471 struct ethtool_pauseparam *ep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472{
4473 u64 val64;
4474 nic_t *sp = dev->priv;
4475 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4476
4477 val64 = readq(&bar0->rmac_pause_cfg);
4478 if (ep->tx_pause)
4479 val64 |= RMAC_PAUSE_GEN_ENABLE;
4480 else
4481 val64 &= ~RMAC_PAUSE_GEN_ENABLE;
4482 if (ep->rx_pause)
4483 val64 |= RMAC_PAUSE_RX_ENABLE;
4484 else
4485 val64 &= ~RMAC_PAUSE_RX_ENABLE;
4486 writeq(val64, &bar0->rmac_pause_cfg);
4487 return 0;
4488}
4489
4490/**
4491 * read_eeprom - reads 4 bytes of data from user given offset.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004492 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 * s2io_nic structure.
4494 * @off : offset at which the data must be written
4495 * @data : Its an output parameter where the data read at the given
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004496 * offset is stored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004498 * Will read 4 bytes of data from the user given offset and return the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 * read data.
4500 * NOTE: Will allow to read only part of the EEPROM visible through the
4501 * I2C bus.
4502 * Return value:
4503 * -1 on failure and 0 on success.
4504 */
4505
4506#define S2IO_DEV_ID 5
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004507static int read_eeprom(nic_t * sp, int off, u64 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508{
4509 int ret = -1;
4510 u32 exit_cnt = 0;
4511 u64 val64;
4512 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4513
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004514 if (sp->device_type == XFRAME_I_DEVICE) {
4515 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
4516 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
4517 I2C_CONTROL_CNTL_START;
4518 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004520 while (exit_cnt < 5) {
4521 val64 = readq(&bar0->i2c_control);
4522 if (I2C_CONTROL_CNTL_END(val64)) {
4523 *data = I2C_CONTROL_GET_DATA(val64);
4524 ret = 0;
4525 break;
4526 }
4527 msleep(50);
4528 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 }
4531
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004532 if (sp->device_type == XFRAME_II_DEVICE) {
4533 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4534 SPI_CONTROL_BYTECNT(0x3) |
4535 SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
4536 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4537 val64 |= SPI_CONTROL_REQ;
4538 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4539 while (exit_cnt < 5) {
4540 val64 = readq(&bar0->spi_control);
4541 if (val64 & SPI_CONTROL_NACK) {
4542 ret = 1;
4543 break;
4544 } else if (val64 & SPI_CONTROL_DONE) {
4545 *data = readq(&bar0->spi_data);
4546 *data &= 0xffffff;
4547 ret = 0;
4548 break;
4549 }
4550 msleep(50);
4551 exit_cnt++;
4552 }
4553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 return ret;
4555}
4556
4557/**
4558 * write_eeprom - actually writes the relevant part of the data value.
4559 * @sp : private member of the device structure, which is a pointer to the
4560 * s2io_nic structure.
4561 * @off : offset at which the data must be written
4562 * @data : The data that is to be written
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004563 * @cnt : Number of bytes of the data that are actually to be written into
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 * the Eeprom. (max of 3)
4565 * Description:
4566 * Actually writes the relevant part of the data value into the Eeprom
4567 * through the I2C bus.
4568 * Return value:
4569 * 0 on success, -1 on failure.
4570 */
4571
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004572static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573{
4574 int exit_cnt = 0, ret = -1;
4575 u64 val64;
4576 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4577
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004578 if (sp->device_type == XFRAME_I_DEVICE) {
4579 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
4580 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
4581 I2C_CONTROL_CNTL_START;
4582 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004584 while (exit_cnt < 5) {
4585 val64 = readq(&bar0->i2c_control);
4586 if (I2C_CONTROL_CNTL_END(val64)) {
4587 if (!(val64 & I2C_CONTROL_NACK))
4588 ret = 0;
4589 break;
4590 }
4591 msleep(50);
4592 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 }
4595
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004596 if (sp->device_type == XFRAME_II_DEVICE) {
4597 int write_cnt = (cnt == 8) ? 0 : cnt;
4598 writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
4599
4600 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4601 SPI_CONTROL_BYTECNT(write_cnt) |
4602 SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
4603 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4604 val64 |= SPI_CONTROL_REQ;
4605 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4606 while (exit_cnt < 5) {
4607 val64 = readq(&bar0->spi_control);
4608 if (val64 & SPI_CONTROL_NACK) {
4609 ret = 1;
4610 break;
4611 } else if (val64 & SPI_CONTROL_DONE) {
4612 ret = 0;
4613 break;
4614 }
4615 msleep(50);
4616 exit_cnt++;
4617 }
4618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 return ret;
4620}
4621
4622/**
4623 * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
4624 * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004625 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 * containing all relevant information.
4627 * @data_buf : user defined value to be written into Eeprom.
4628 * Description: Reads the values stored in the Eeprom at given offset
4629 * for a given length. Stores these values int the input argument data
4630 * buffer 'data_buf' and returns these to the caller (ethtool.)
4631 * Return value:
4632 * int 0 on success
4633 */
4634
4635static int s2io_ethtool_geeprom(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004636 struct ethtool_eeprom *eeprom, u8 * data_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637{
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004638 u32 i, valid;
4639 u64 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 nic_t *sp = dev->priv;
4641
4642 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
4643
4644 if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
4645 eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
4646
4647 for (i = 0; i < eeprom->len; i += 4) {
4648 if (read_eeprom(sp, (eeprom->offset + i), &data)) {
4649 DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
4650 return -EFAULT;
4651 }
4652 valid = INV(data);
4653 memcpy((data_buf + i), &valid, 4);
4654 }
4655 return 0;
4656}
4657
4658/**
4659 * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
4660 * @sp : private member of the device structure, which is a pointer to the
4661 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004662 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 * containing all relevant information.
4664 * @data_buf ; user defined value to be written into Eeprom.
4665 * Description:
4666 * Tries to write the user provided value in the Eeprom, at the offset
4667 * given by the user.
4668 * Return value:
4669 * 0 on success, -EFAULT on failure.
4670 */
4671
4672static int s2io_ethtool_seeprom(struct net_device *dev,
4673 struct ethtool_eeprom *eeprom,
4674 u8 * data_buf)
4675{
4676 int len = eeprom->len, cnt = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004677 u64 valid = 0, data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 nic_t *sp = dev->priv;
4679
4680 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
4681 DBG_PRINT(ERR_DBG,
4682 "ETHTOOL_WRITE_EEPROM Err: Magic value ");
4683 DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
4684 eeprom->magic);
4685 return -EFAULT;
4686 }
4687
4688 while (len) {
4689 data = (u32) data_buf[cnt] & 0x000000FF;
4690 if (data) {
4691 valid = (u32) (data << 24);
4692 } else
4693 valid = data;
4694
4695 if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
4696 DBG_PRINT(ERR_DBG,
4697 "ETHTOOL_WRITE_EEPROM Err: Cannot ");
4698 DBG_PRINT(ERR_DBG,
4699 "write into the specified offset\n");
4700 return -EFAULT;
4701 }
4702 cnt++;
4703 len--;
4704 }
4705
4706 return 0;
4707}
4708
4709/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004710 * s2io_register_test - reads and writes into all clock domains.
4711 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 * s2io_nic structure.
4713 * @data : variable that returns the result of each of the test conducted b
4714 * by the driver.
4715 * Description:
4716 * Read and write into all clock domains. The NIC has 3 clock domains,
4717 * see that registers in all the three regions are accessible.
4718 * Return value:
4719 * 0 on success.
4720 */
4721
4722static int s2io_register_test(nic_t * sp, uint64_t * data)
4723{
4724 XENA_dev_config_t __iomem *bar0 = sp->bar0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004725 u64 val64 = 0, exp_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 int fail = 0;
4727
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004728 val64 = readq(&bar0->pif_rd_swapper_fb);
4729 if (val64 != 0x123456789abcdefULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 fail = 1;
4731 DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
4732 }
4733
4734 val64 = readq(&bar0->rmac_pause_cfg);
4735 if (val64 != 0xc000ffff00000000ULL) {
4736 fail = 1;
4737 DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
4738 }
4739
4740 val64 = readq(&bar0->rx_queue_cfg);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004741 if (sp->device_type == XFRAME_II_DEVICE)
4742 exp_val = 0x0404040404040404ULL;
4743 else
4744 exp_val = 0x0808080808080808ULL;
4745 if (val64 != exp_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 fail = 1;
4747 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
4748 }
4749
4750 val64 = readq(&bar0->xgxs_efifo_cfg);
4751 if (val64 != 0x000000001923141EULL) {
4752 fail = 1;
4753 DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
4754 }
4755
4756 val64 = 0x5A5A5A5A5A5A5A5AULL;
4757 writeq(val64, &bar0->xmsi_data);
4758 val64 = readq(&bar0->xmsi_data);
4759 if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
4760 fail = 1;
4761 DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
4762 }
4763
4764 val64 = 0xA5A5A5A5A5A5A5A5ULL;
4765 writeq(val64, &bar0->xmsi_data);
4766 val64 = readq(&bar0->xmsi_data);
4767 if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
4768 fail = 1;
4769 DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
4770 }
4771
4772 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004773 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774}
4775
4776/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004777 * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 * @sp : private member of the device structure, which is a pointer to the
4779 * s2io_nic structure.
4780 * @data:variable that returns the result of each of the test conducted by
4781 * the driver.
4782 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004783 * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 * register.
4785 * Return value:
4786 * 0 on success.
4787 */
4788
4789static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
4790{
4791 int fail = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004792 u64 ret_data, org_4F0, org_7F0;
4793 u8 saved_4F0 = 0, saved_7F0 = 0;
4794 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795
4796 /* Test Write Error at offset 0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004797 /* Note that SPI interface allows write access to all areas
4798 * of EEPROM. Hence doing all negative testing only for Xframe I.
4799 */
4800 if (sp->device_type == XFRAME_I_DEVICE)
4801 if (!write_eeprom(sp, 0, 0, 3))
4802 fail = 1;
4803
4804 /* Save current values at offsets 0x4F0 and 0x7F0 */
4805 if (!read_eeprom(sp, 0x4F0, &org_4F0))
4806 saved_4F0 = 1;
4807 if (!read_eeprom(sp, 0x7F0, &org_7F0))
4808 saved_7F0 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809
4810 /* Test Write at offset 4f0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004811 if (write_eeprom(sp, 0x4F0, 0x012345, 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 fail = 1;
4813 if (read_eeprom(sp, 0x4F0, &ret_data))
4814 fail = 1;
4815
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004816 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08004817 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
4818 "Data written %llx Data read %llx\n",
4819 dev->name, (unsigned long long)0x12345,
4820 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823
4824 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004825 write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826
4827 /* Test Write Request Error at offset 0x7c */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004828 if (sp->device_type == XFRAME_I_DEVICE)
4829 if (!write_eeprom(sp, 0x07C, 0, 3))
4830 fail = 1;
4831
4832 /* Test Write Request at offset 0x7f0 */
4833 if (write_eeprom(sp, 0x7F0, 0x012345, 3))
4834 fail = 1;
4835 if (read_eeprom(sp, 0x7F0, &ret_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 fail = 1;
4837
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004838 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08004839 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
4840 "Data written %llx Data read %llx\n",
4841 dev->name, (unsigned long long)0x12345,
4842 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
4846 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004847 write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004849 if (sp->device_type == XFRAME_I_DEVICE) {
4850 /* Test Write Error at offset 0x80 */
4851 if (!write_eeprom(sp, 0x080, 0, 3))
4852 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004854 /* Test Write Error at offset 0xfc */
4855 if (!write_eeprom(sp, 0x0FC, 0, 3))
4856 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004858 /* Test Write Error at offset 0x100 */
4859 if (!write_eeprom(sp, 0x100, 0, 3))
4860 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004862 /* Test Write Error at offset 4ec */
4863 if (!write_eeprom(sp, 0x4EC, 0, 3))
4864 fail = 1;
4865 }
4866
4867 /* Restore values at offsets 0x4F0 and 0x7F0 */
4868 if (saved_4F0)
4869 write_eeprom(sp, 0x4F0, org_4F0, 3);
4870 if (saved_7F0)
4871 write_eeprom(sp, 0x7F0, org_7F0, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872
4873 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004874 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875}
4876
4877/**
4878 * s2io_bist_test - invokes the MemBist test of the card .
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004879 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004881 * @data:variable that returns the result of each of the test conducted by
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 * the driver.
4883 * Description:
4884 * This invokes the MemBist test of the card. We give around
4885 * 2 secs time for the Test to complete. If it's still not complete
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004886 * within this peiod, we consider that the test failed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 * Return value:
4888 * 0 on success and -1 on failure.
4889 */
4890
4891static int s2io_bist_test(nic_t * sp, uint64_t * data)
4892{
4893 u8 bist = 0;
4894 int cnt = 0, ret = -1;
4895
4896 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
4897 bist |= PCI_BIST_START;
4898 pci_write_config_word(sp->pdev, PCI_BIST, bist);
4899
4900 while (cnt < 20) {
4901 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
4902 if (!(bist & PCI_BIST_START)) {
4903 *data = (bist & PCI_BIST_CODE_MASK);
4904 ret = 0;
4905 break;
4906 }
4907 msleep(100);
4908 cnt++;
4909 }
4910
4911 return ret;
4912}
4913
4914/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004915 * s2io-link_test - verifies the link state of the nic
4916 * @sp ; private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 * s2io_nic structure.
4918 * @data: variable that returns the result of each of the test conducted by
4919 * the driver.
4920 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004921 * The function verifies the link state of the NIC and updates the input
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 * argument 'data' appropriately.
4923 * Return value:
4924 * 0 on success.
4925 */
4926
4927static int s2io_link_test(nic_t * sp, uint64_t * data)
4928{
4929 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4930 u64 val64;
4931
4932 val64 = readq(&bar0->adapter_status);
4933 if (val64 & ADAPTER_STATUS_RMAC_LOCAL_FAULT)
4934 *data = 1;
4935
4936 return 0;
4937}
4938
4939/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004940 * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
4941 * @sp - private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004943 * @data - variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 * conducted by the driver.
4945 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004946 * This is one of the offline test that tests the read and write
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 * access to the RldRam chip on the NIC.
4948 * Return value:
4949 * 0 on success.
4950 */
4951
4952static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4953{
4954 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4955 u64 val64;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004956 int cnt, iteration = 0, test_fail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957
4958 val64 = readq(&bar0->adapter_control);
4959 val64 &= ~ADAPTER_ECC_EN;
4960 writeq(val64, &bar0->adapter_control);
4961
4962 val64 = readq(&bar0->mc_rldram_test_ctrl);
4963 val64 |= MC_RLDRAM_TEST_MODE;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004964 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965
4966 val64 = readq(&bar0->mc_rldram_mrs);
4967 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
4968 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
4969
4970 val64 |= MC_RLDRAM_MRS_ENABLE;
4971 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
4972
4973 while (iteration < 2) {
4974 val64 = 0x55555555aaaa0000ULL;
4975 if (iteration == 1) {
4976 val64 ^= 0xFFFFFFFFFFFF0000ULL;
4977 }
4978 writeq(val64, &bar0->mc_rldram_test_d0);
4979
4980 val64 = 0xaaaa5a5555550000ULL;
4981 if (iteration == 1) {
4982 val64 ^= 0xFFFFFFFFFFFF0000ULL;
4983 }
4984 writeq(val64, &bar0->mc_rldram_test_d1);
4985
4986 val64 = 0x55aaaaaaaa5a0000ULL;
4987 if (iteration == 1) {
4988 val64 ^= 0xFFFFFFFFFFFF0000ULL;
4989 }
4990 writeq(val64, &bar0->mc_rldram_test_d2);
4991
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004992 val64 = (u64) (0x0000003ffffe0100ULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 writeq(val64, &bar0->mc_rldram_test_add);
4994
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004995 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
4996 MC_RLDRAM_TEST_GO;
4997 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998
4999 for (cnt = 0; cnt < 5; cnt++) {
5000 val64 = readq(&bar0->mc_rldram_test_ctrl);
5001 if (val64 & MC_RLDRAM_TEST_DONE)
5002 break;
5003 msleep(200);
5004 }
5005
5006 if (cnt == 5)
5007 break;
5008
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005009 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
5010 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
5012 for (cnt = 0; cnt < 5; cnt++) {
5013 val64 = readq(&bar0->mc_rldram_test_ctrl);
5014 if (val64 & MC_RLDRAM_TEST_DONE)
5015 break;
5016 msleep(500);
5017 }
5018
5019 if (cnt == 5)
5020 break;
5021
5022 val64 = readq(&bar0->mc_rldram_test_ctrl);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005023 if (!(val64 & MC_RLDRAM_TEST_PASS))
5024 test_fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025
5026 iteration++;
5027 }
5028
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005029 *data = test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005031 /* Bring the adapter out of test mode */
5032 SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
5033
5034 return test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035}
5036
5037/**
5038 * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
5039 * @sp : private member of the device structure, which is a pointer to the
5040 * s2io_nic structure.
5041 * @ethtest : pointer to a ethtool command specific structure that will be
5042 * returned to the user.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005043 * @data : variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 * conducted by the driver.
5045 * Description:
5046 * This function conducts 6 tests ( 4 offline and 2 online) to determine
5047 * the health of the card.
5048 * Return value:
5049 * void
5050 */
5051
5052static void s2io_ethtool_test(struct net_device *dev,
5053 struct ethtool_test *ethtest,
5054 uint64_t * data)
5055{
5056 nic_t *sp = dev->priv;
5057 int orig_state = netif_running(sp->dev);
5058
5059 if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
5060 /* Offline Tests. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005061 if (orig_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 s2io_close(sp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063
5064 if (s2io_register_test(sp, &data[0]))
5065 ethtest->flags |= ETH_TEST_FL_FAILED;
5066
5067 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068
5069 if (s2io_rldram_test(sp, &data[3]))
5070 ethtest->flags |= ETH_TEST_FL_FAILED;
5071
5072 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073
5074 if (s2io_eeprom_test(sp, &data[1]))
5075 ethtest->flags |= ETH_TEST_FL_FAILED;
5076
5077 if (s2io_bist_test(sp, &data[4]))
5078 ethtest->flags |= ETH_TEST_FL_FAILED;
5079
5080 if (orig_state)
5081 s2io_open(sp->dev);
5082
5083 data[2] = 0;
5084 } else {
5085 /* Online Tests. */
5086 if (!orig_state) {
5087 DBG_PRINT(ERR_DBG,
5088 "%s: is not up, cannot run test\n",
5089 dev->name);
5090 data[0] = -1;
5091 data[1] = -1;
5092 data[2] = -1;
5093 data[3] = -1;
5094 data[4] = -1;
5095 }
5096
5097 if (s2io_link_test(sp, &data[2]))
5098 ethtest->flags |= ETH_TEST_FL_FAILED;
5099
5100 data[0] = 0;
5101 data[1] = 0;
5102 data[3] = 0;
5103 data[4] = 0;
5104 }
5105}
5106
5107static void s2io_get_ethtool_stats(struct net_device *dev,
5108 struct ethtool_stats *estats,
5109 u64 * tmp_stats)
5110{
5111 int i = 0;
5112 nic_t *sp = dev->priv;
5113 StatInfo_t *stat_info = sp->mac_control.stats_info;
Andrew Mortonfe931392006-02-03 01:45:12 -08005114 u64 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005116 s2io_updt_stats(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005117 tmp_stats[i++] =
5118 (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
5119 le32_to_cpu(stat_info->tmac_frms);
5120 tmp_stats[i++] =
5121 (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
5122 le32_to_cpu(stat_info->tmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005124 tmp_stats[i++] =
5125 (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
5126 le32_to_cpu(stat_info->tmac_mcst_frms);
5127 tmp_stats[i++] =
5128 (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
5129 le32_to_cpu(stat_info->tmac_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005131 tmp_stats[i++] =
5132 (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
5133 le32_to_cpu(stat_info->tmac_any_err_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005135 tmp_stats[i++] =
5136 (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
5137 le32_to_cpu(stat_info->tmac_vld_ip);
5138 tmp_stats[i++] =
5139 (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
5140 le32_to_cpu(stat_info->tmac_drop_ip);
5141 tmp_stats[i++] =
5142 (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
5143 le32_to_cpu(stat_info->tmac_icmp);
5144 tmp_stats[i++] =
5145 (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
5146 le32_to_cpu(stat_info->tmac_rst_tcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005148 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
5149 le32_to_cpu(stat_info->tmac_udp);
5150 tmp_stats[i++] =
5151 (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
5152 le32_to_cpu(stat_info->rmac_vld_frms);
5153 tmp_stats[i++] =
5154 (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
5155 le32_to_cpu(stat_info->rmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
5157 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005158 tmp_stats[i++] =
5159 (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
5160 le32_to_cpu(stat_info->rmac_vld_mcst_frms);
5161 tmp_stats[i++] =
5162 (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
5163 le32_to_cpu(stat_info->rmac_vld_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
5165 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
5166 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005167 tmp_stats[i++] =
5168 (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
5169 le32_to_cpu(stat_info->rmac_discarded_frms);
5170 tmp_stats[i++] =
5171 (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
5172 le32_to_cpu(stat_info->rmac_usized_frms);
5173 tmp_stats[i++] =
5174 (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
5175 le32_to_cpu(stat_info->rmac_osized_frms);
5176 tmp_stats[i++] =
5177 (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
5178 le32_to_cpu(stat_info->rmac_frag_frms);
5179 tmp_stats[i++] =
5180 (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
5181 le32_to_cpu(stat_info->rmac_jabber_frms);
5182 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
5183 le32_to_cpu(stat_info->rmac_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
5185 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005186 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
5187 le32_to_cpu(stat_info->rmac_drop_ip);
5188 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
5189 le32_to_cpu(stat_info->rmac_icmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005191 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
5192 le32_to_cpu(stat_info->rmac_udp);
5193 tmp_stats[i++] =
5194 (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
5195 le32_to_cpu(stat_info->rmac_err_drp_udp);
5196 tmp_stats[i++] =
5197 (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
5198 le32_to_cpu(stat_info->rmac_pause_cnt);
5199 tmp_stats[i++] =
5200 (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
5201 le32_to_cpu(stat_info->rmac_accepted_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005203 tmp_stats[i++] = 0;
5204 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
5205 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005206 tmp_stats[i++] = stat_info->sw_stat.clubbed_frms_cnt;
5207 tmp_stats[i++] = stat_info->sw_stat.sending_both;
5208 tmp_stats[i++] = stat_info->sw_stat.outof_sequence_pkts;
5209 tmp_stats[i++] = stat_info->sw_stat.flush_max_pkts;
Andrew Mortonfe931392006-02-03 01:45:12 -08005210 tmp = 0;
5211 if (stat_info->sw_stat.num_aggregations) {
5212 tmp = stat_info->sw_stat.sum_avg_pkts_aggregated;
5213 do_div(tmp, stat_info->sw_stat.num_aggregations);
5214 }
5215 tmp_stats[i++] = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005216}
5217
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005218static int s2io_ethtool_get_regs_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219{
5220 return (XENA_REG_SPACE);
5221}
5222
5223
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005224static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225{
5226 nic_t *sp = dev->priv;
5227
5228 return (sp->rx_csum);
5229}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005230
5231static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232{
5233 nic_t *sp = dev->priv;
5234
5235 if (data)
5236 sp->rx_csum = 1;
5237 else
5238 sp->rx_csum = 0;
5239
5240 return 0;
5241}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005242
5243static int s2io_get_eeprom_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244{
5245 return (XENA_EEPROM_SPACE);
5246}
5247
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005248static int s2io_ethtool_self_test_count(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249{
5250 return (S2IO_TEST_LEN);
5251}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005252
5253static void s2io_ethtool_get_strings(struct net_device *dev,
5254 u32 stringset, u8 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255{
5256 switch (stringset) {
5257 case ETH_SS_TEST:
5258 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
5259 break;
5260 case ETH_SS_STATS:
5261 memcpy(data, &ethtool_stats_keys,
5262 sizeof(ethtool_stats_keys));
5263 }
5264}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265static int s2io_ethtool_get_stats_count(struct net_device *dev)
5266{
5267 return (S2IO_STAT_LEN);
5268}
5269
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005270static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271{
5272 if (data)
5273 dev->features |= NETIF_F_IP_CSUM;
5274 else
5275 dev->features &= ~NETIF_F_IP_CSUM;
5276
5277 return 0;
5278}
5279
5280
5281static struct ethtool_ops netdev_ethtool_ops = {
5282 .get_settings = s2io_ethtool_gset,
5283 .set_settings = s2io_ethtool_sset,
5284 .get_drvinfo = s2io_ethtool_gdrvinfo,
5285 .get_regs_len = s2io_ethtool_get_regs_len,
5286 .get_regs = s2io_ethtool_gregs,
5287 .get_link = ethtool_op_get_link,
5288 .get_eeprom_len = s2io_get_eeprom_len,
5289 .get_eeprom = s2io_ethtool_geeprom,
5290 .set_eeprom = s2io_ethtool_seeprom,
5291 .get_pauseparam = s2io_ethtool_getpause_data,
5292 .set_pauseparam = s2io_ethtool_setpause_data,
5293 .get_rx_csum = s2io_ethtool_get_rx_csum,
5294 .set_rx_csum = s2io_ethtool_set_rx_csum,
5295 .get_tx_csum = ethtool_op_get_tx_csum,
5296 .set_tx_csum = s2io_ethtool_op_set_tx_csum,
5297 .get_sg = ethtool_op_get_sg,
5298 .set_sg = ethtool_op_set_sg,
5299#ifdef NETIF_F_TSO
5300 .get_tso = ethtool_op_get_tso,
5301 .set_tso = ethtool_op_set_tso,
5302#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05005303 .get_ufo = ethtool_op_get_ufo,
5304 .set_ufo = ethtool_op_set_ufo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 .self_test_count = s2io_ethtool_self_test_count,
5306 .self_test = s2io_ethtool_test,
5307 .get_strings = s2io_ethtool_get_strings,
5308 .phys_id = s2io_ethtool_idnic,
5309 .get_stats_count = s2io_ethtool_get_stats_count,
5310 .get_ethtool_stats = s2io_get_ethtool_stats
5311};
5312
5313/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005314 * s2io_ioctl - Entry point for the Ioctl
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 * @dev : Device pointer.
5316 * @ifr : An IOCTL specefic structure, that can contain a pointer to
5317 * a proprietary structure used to pass information to the driver.
5318 * @cmd : This is used to distinguish between the different commands that
5319 * can be passed to the IOCTL functions.
5320 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005321 * Currently there are no special functionality supported in IOCTL, hence
5322 * function always return EOPNOTSUPPORTED
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323 */
5324
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005325static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326{
5327 return -EOPNOTSUPP;
5328}
5329
5330/**
5331 * s2io_change_mtu - entry point to change MTU size for the device.
5332 * @dev : device pointer.
5333 * @new_mtu : the new MTU size for the device.
5334 * Description: A driver entry point to change MTU size for the device.
5335 * Before changing the MTU the device must be stopped.
5336 * Return value:
5337 * 0 on success and an appropriate (-)ve integer as defined in errno.h
5338 * file on failure.
5339 */
5340
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005341static int s2io_change_mtu(struct net_device *dev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342{
5343 nic_t *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
5345 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
5346 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
5347 dev->name);
5348 return -EPERM;
5349 }
5350
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 dev->mtu = new_mtu;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07005352 if (netif_running(dev)) {
5353 s2io_card_down(sp);
5354 netif_stop_queue(dev);
5355 if (s2io_card_up(sp)) {
5356 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
5357 __FUNCTION__);
5358 }
5359 if (netif_queue_stopped(dev))
5360 netif_wake_queue(dev);
5361 } else { /* Device is down */
5362 XENA_dev_config_t __iomem *bar0 = sp->bar0;
5363 u64 val64 = new_mtu;
5364
5365 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
5366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367
5368 return 0;
5369}
5370
5371/**
5372 * s2io_tasklet - Bottom half of the ISR.
5373 * @dev_adr : address of the device structure in dma_addr_t format.
5374 * Description:
5375 * This is the tasklet or the bottom half of the ISR. This is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005376 * an extension of the ISR which is scheduled by the scheduler to be run
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377 * when the load on the CPU is low. All low priority tasks of the ISR can
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005378 * be pushed into the tasklet. For now the tasklet is used only to
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 * replenish the Rx buffers in the Rx buffer descriptors.
5380 * Return value:
5381 * void.
5382 */
5383
5384static void s2io_tasklet(unsigned long dev_addr)
5385{
5386 struct net_device *dev = (struct net_device *) dev_addr;
5387 nic_t *sp = dev->priv;
5388 int i, ret;
5389 mac_info_t *mac_control;
5390 struct config_param *config;
5391
5392 mac_control = &sp->mac_control;
5393 config = &sp->config;
5394
5395 if (!TASKLET_IN_USE) {
5396 for (i = 0; i < config->rx_ring_num; i++) {
5397 ret = fill_rx_buffers(sp, i);
5398 if (ret == -ENOMEM) {
5399 DBG_PRINT(ERR_DBG, "%s: Out of ",
5400 dev->name);
5401 DBG_PRINT(ERR_DBG, "memory in tasklet\n");
5402 break;
5403 } else if (ret == -EFILL) {
5404 DBG_PRINT(ERR_DBG,
5405 "%s: Rx Ring %d is full\n",
5406 dev->name, i);
5407 break;
5408 }
5409 }
5410 clear_bit(0, (&sp->tasklet_status));
5411 }
5412}
5413
5414/**
5415 * s2io_set_link - Set the LInk status
5416 * @data: long pointer to device private structue
5417 * Description: Sets the link status for the adapter
5418 */
5419
5420static void s2io_set_link(unsigned long data)
5421{
5422 nic_t *nic = (nic_t *) data;
5423 struct net_device *dev = nic->dev;
5424 XENA_dev_config_t __iomem *bar0 = nic->bar0;
5425 register u64 val64;
5426 u16 subid;
5427
5428 if (test_and_set_bit(0, &(nic->link_state))) {
5429 /* The card is being reset, no point doing anything */
5430 return;
5431 }
5432
5433 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07005434 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
5435 /*
5436 * Allow a small delay for the NICs self initiated
5437 * cleanup to complete.
5438 */
5439 msleep(100);
5440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441
5442 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005443 if (verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 if (LINK_IS_UP(val64)) {
5445 val64 = readq(&bar0->adapter_control);
5446 val64 |= ADAPTER_CNTL_EN;
5447 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005448 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
5449 subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 val64 = readq(&bar0->gpio_control);
5451 val64 |= GPIO_CTRL_GPIO_0;
5452 writeq(val64, &bar0->gpio_control);
5453 val64 = readq(&bar0->gpio_control);
5454 } else {
5455 val64 |= ADAPTER_LED_ON;
5456 writeq(val64, &bar0->adapter_control);
5457 }
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07005458 if (s2io_link_fault_indication(nic) ==
5459 MAC_RMAC_ERR_TIMER) {
5460 val64 = readq(&bar0->adapter_status);
5461 if (!LINK_IS_UP(val64)) {
5462 DBG_PRINT(ERR_DBG, "%s:", dev->name);
5463 DBG_PRINT(ERR_DBG, " Link down");
5464 DBG_PRINT(ERR_DBG, "after ");
5465 DBG_PRINT(ERR_DBG, "enabling ");
5466 DBG_PRINT(ERR_DBG, "device \n");
5467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 }
5469 if (nic->device_enabled_once == FALSE) {
5470 nic->device_enabled_once = TRUE;
5471 }
5472 s2io_link(nic, LINK_UP);
5473 } else {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005474 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
5475 subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 val64 = readq(&bar0->gpio_control);
5477 val64 &= ~GPIO_CTRL_GPIO_0;
5478 writeq(val64, &bar0->gpio_control);
5479 val64 = readq(&bar0->gpio_control);
5480 }
5481 s2io_link(nic, LINK_DOWN);
5482 }
5483 } else { /* NIC is not Quiescent. */
5484 DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
5485 DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
5486 netif_stop_queue(dev);
5487 }
5488 clear_bit(0, &(nic->link_state));
5489}
5490
5491static void s2io_card_down(nic_t * sp)
5492{
5493 int cnt = 0;
5494 XENA_dev_config_t __iomem *bar0 = sp->bar0;
5495 unsigned long flags;
5496 register u64 val64 = 0;
5497
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07005498 del_timer_sync(&sp->alarm_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499 /* If s2io_set_link task is executing, wait till it completes. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005500 while (test_and_set_bit(0, &(sp->link_state))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005501 msleep(50);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503 atomic_set(&sp->card_state, CARD_DOWN);
5504
5505 /* disable Tx and Rx traffic on the NIC */
5506 stop_nic(sp);
5507
5508 /* Kill tasklet. */
5509 tasklet_kill(&sp->task);
5510
5511 /* Check if the device is Quiescent and then Reset the NIC */
5512 do {
5513 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005514 if (verify_xena_quiescence(sp, val64, sp->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515 break;
5516 }
5517
5518 msleep(50);
5519 cnt++;
5520 if (cnt == 10) {
5521 DBG_PRINT(ERR_DBG,
5522 "s2io_close:Device not Quiescent ");
5523 DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
5524 (unsigned long long) val64);
5525 break;
5526 }
5527 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528 s2io_reset(sp);
5529
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005530 /* Waiting till all Interrupt handlers are complete */
5531 cnt = 0;
5532 do {
5533 msleep(10);
5534 if (!atomic_read(&sp->isr_cnt))
5535 break;
5536 cnt++;
5537 } while(cnt < 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005539 spin_lock_irqsave(&sp->tx_lock, flags);
5540 /* Free all Tx buffers */
5541 free_tx_buffers(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005543
5544 /* Free all Rx buffers */
5545 spin_lock_irqsave(&sp->rx_lock, flags);
5546 free_rx_buffers(sp);
5547 spin_unlock_irqrestore(&sp->rx_lock, flags);
5548
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 clear_bit(0, &(sp->link_state));
5550}
5551
5552static int s2io_card_up(nic_t * sp)
5553{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005554 int i, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555 mac_info_t *mac_control;
5556 struct config_param *config;
5557 struct net_device *dev = (struct net_device *) sp->dev;
5558
5559 /* Initialize the H/W I/O registers */
5560 if (init_nic(sp) != 0) {
5561 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
5562 dev->name);
5563 return -ENODEV;
5564 }
5565
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005566 if (sp->intr_type == MSI)
5567 ret = s2io_enable_msi(sp);
5568 else if (sp->intr_type == MSI_X)
5569 ret = s2io_enable_msi_x(sp);
5570 if (ret) {
5571 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
5572 sp->intr_type = INTA;
5573 }
5574
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005575 /*
5576 * Initializing the Rx buffers. For now we are considering only 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577 * Rx ring and initializing buffers into 30 Rx blocks
5578 */
5579 mac_control = &sp->mac_control;
5580 config = &sp->config;
5581
5582 for (i = 0; i < config->rx_ring_num; i++) {
5583 if ((ret = fill_rx_buffers(sp, i))) {
5584 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
5585 dev->name);
5586 s2io_reset(sp);
5587 free_rx_buffers(sp);
5588 return -ENOMEM;
5589 }
5590 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
5591 atomic_read(&sp->rx_bufs_left[i]));
5592 }
5593
5594 /* Setting its receive mode */
5595 s2io_set_multicast(dev);
5596
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005597 if (sp->lro) {
5598 /* Initialize max aggregatable pkts based on MTU */
5599 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
5600 /* Check if we can use(if specified) user provided value */
5601 if (lro_max_pkts < sp->lro_max_aggr_per_sess)
5602 sp->lro_max_aggr_per_sess = lro_max_pkts;
5603 }
5604
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 /* Enable tasklet for the device */
5606 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
5607
5608 /* Enable Rx Traffic and interrupts on the NIC */
5609 if (start_nic(sp)) {
5610 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
5611 tasklet_kill(&sp->task);
5612 s2io_reset(sp);
5613 free_irq(dev->irq, dev);
5614 free_rx_buffers(sp);
5615 return -ENODEV;
5616 }
5617
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07005618 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
5619
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620 atomic_set(&sp->card_state, CARD_UP);
5621 return 0;
5622}
5623
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005624/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625 * s2io_restart_nic - Resets the NIC.
5626 * @data : long pointer to the device private structure
5627 * Description:
5628 * This function is scheduled to be run by the s2io_tx_watchdog
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005629 * function after 0.5 secs to reset the NIC. The idea is to reduce
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 * the run time of the watch dog routine which is run holding a
5631 * spin lock.
5632 */
5633
5634static void s2io_restart_nic(unsigned long data)
5635{
5636 struct net_device *dev = (struct net_device *) data;
5637 nic_t *sp = dev->priv;
5638
5639 s2io_card_down(sp);
5640 if (s2io_card_up(sp)) {
5641 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
5642 dev->name);
5643 }
5644 netif_wake_queue(dev);
5645 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
5646 dev->name);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005647
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648}
5649
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005650/**
5651 * s2io_tx_watchdog - Watchdog for transmit side.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652 * @dev : Pointer to net device structure
5653 * Description:
5654 * This function is triggered if the Tx Queue is stopped
5655 * for a pre-defined amount of time when the Interface is still up.
5656 * If the Interface is jammed in such a situation, the hardware is
5657 * reset (by s2io_close) and restarted again (by s2io_open) to
5658 * overcome any problem that might have been caused in the hardware.
5659 * Return value:
5660 * void
5661 */
5662
5663static void s2io_tx_watchdog(struct net_device *dev)
5664{
5665 nic_t *sp = dev->priv;
5666
5667 if (netif_carrier_ok(dev)) {
5668 schedule_work(&sp->rst_timer_task);
5669 }
5670}
5671
5672/**
5673 * rx_osm_handler - To perform some OS related operations on SKB.
5674 * @sp: private member of the device structure,pointer to s2io_nic structure.
5675 * @skb : the socket buffer pointer.
5676 * @len : length of the packet
5677 * @cksum : FCS checksum of the frame.
5678 * @ring_no : the ring from which this RxD was extracted.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005679 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 * This function is called by the Tx interrupt serivce routine to perform
5681 * some OS related operations on the SKB before passing it to the upper
5682 * layers. It mainly checks if the checksum is OK, if so adds it to the
5683 * SKBs cksum variable, increments the Rx packet count and passes the SKB
5684 * to the upper layer. If the checksum is wrong, it increments the Rx
5685 * packet error count, frees the SKB and returns error.
5686 * Return value:
5687 * SUCCESS on success and -1 on failure.
5688 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005689static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005690{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005691 nic_t *sp = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 struct net_device *dev = (struct net_device *) sp->dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005693 struct sk_buff *skb = (struct sk_buff *)
5694 ((unsigned long) rxdp->Host_Control);
5695 int ring_no = ring_data->ring_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696 u16 l3_csum, l4_csum;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005697 lro_t *lro;
Ananda Rajuda6971d2005-10-31 16:55:31 -05005698
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005699 skb->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 if (rxdp->Control_1 & RXD_T_CODE) {
5701 unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
5702 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
5703 dev->name, err);
raghavendra.koushik@neterion.com1ddc50d2005-08-03 12:30:43 -07005704 dev_kfree_skb(skb);
5705 sp->stats.rx_crc_errors++;
5706 atomic_dec(&sp->rx_bufs_left[ring_no]);
5707 rxdp->Host_Control = 0;
5708 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005711 /* Updating statistics */
5712 rxdp->Host_Control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 sp->rx_pkt_count++;
5714 sp->stats.rx_packets++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05005715 if (sp->rxd_mode == RXD_MODE_1) {
5716 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717
Ananda Rajuda6971d2005-10-31 16:55:31 -05005718 sp->stats.rx_bytes += len;
5719 skb_put(skb, len);
5720
5721 } else if (sp->rxd_mode >= RXD_MODE_3A) {
5722 int get_block = ring_data->rx_curr_get_info.block_index;
5723 int get_off = ring_data->rx_curr_get_info.offset;
5724 int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
5725 int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
5726 unsigned char *buff = skb_push(skb, buf0_len);
5727
5728 buffAdd_t *ba = &ring_data->ba[get_block][get_off];
5729 sp->stats.rx_bytes += buf0_len + buf2_len;
5730 memcpy(buff, ba->ba_0, buf0_len);
5731
5732 if (sp->rxd_mode == RXD_MODE_3A) {
5733 int buf1_len = RXD_GET_BUFFER1_SIZE_3(rxdp->Control_2);
5734
5735 skb_put(skb, buf1_len);
5736 skb->len += buf2_len;
5737 skb->data_len += buf2_len;
5738 skb->truesize += buf2_len;
5739 skb_put(skb_shinfo(skb)->frag_list, buf2_len);
5740 sp->stats.rx_bytes += buf1_len;
5741
5742 } else
5743 skb_put(skb, buf2_len);
5744 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005745
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005746 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!sp->lro) ||
5747 (sp->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005748 (sp->rx_csum)) {
5749 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
5750 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
5751 if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
5752 /*
5753 * NIC verifies if the Checksum of the received
5754 * frame is Ok or not and accordingly returns
5755 * a flag in the RxD.
5756 */
5757 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005758 if (sp->lro) {
5759 u32 tcp_len;
5760 u8 *tcp;
5761 int ret = 0;
5762
5763 ret = s2io_club_tcp_session(skb->data, &tcp,
5764 &tcp_len, &lro, rxdp, sp);
5765 switch (ret) {
5766 case 3: /* Begin anew */
5767 lro->parent = skb;
5768 goto aggregate;
5769 case 1: /* Aggregate */
5770 {
5771 lro_append_pkt(sp, lro,
5772 skb, tcp_len);
5773 goto aggregate;
5774 }
5775 case 4: /* Flush session */
5776 {
5777 lro_append_pkt(sp, lro,
5778 skb, tcp_len);
5779 queue_rx_frame(lro->parent);
5780 clear_lro_session(lro);
5781 sp->mac_control.stats_info->
5782 sw_stat.flush_max_pkts++;
5783 goto aggregate;
5784 }
5785 case 2: /* Flush both */
5786 lro->parent->data_len =
5787 lro->frags_len;
5788 sp->mac_control.stats_info->
5789 sw_stat.sending_both++;
5790 queue_rx_frame(lro->parent);
5791 clear_lro_session(lro);
5792 goto send_up;
5793 case 0: /* sessions exceeded */
5794 case 5: /*
5795 * First pkt in session not
5796 * L3/L4 aggregatable
5797 */
5798 break;
5799 default:
5800 DBG_PRINT(ERR_DBG,
5801 "%s: Samadhana!!\n",
5802 __FUNCTION__);
5803 BUG();
5804 }
5805 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005806 } else {
5807 /*
5808 * Packet with erroneous checksum, let the
5809 * upper layers deal with it.
5810 */
5811 skb->ip_summed = CHECKSUM_NONE;
5812 }
5813 } else {
5814 skb->ip_summed = CHECKSUM_NONE;
5815 }
5816
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005817 if (!sp->lro) {
5818 skb->protocol = eth_type_trans(skb, dev);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005819#ifdef CONFIG_S2IO_NAPI
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005820 if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
5821 /* Queueing the vlan frame to the upper layer */
5822 vlan_hwaccel_receive_skb(skb, sp->vlgrp,
5823 RXD_GET_VLAN_TAG(rxdp->Control_2));
5824 } else {
5825 netif_receive_skb(skb);
5826 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005827#else
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005828 if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
5829 /* Queueing the vlan frame to the upper layer */
5830 vlan_hwaccel_rx(skb, sp->vlgrp,
5831 RXD_GET_VLAN_TAG(rxdp->Control_2));
5832 } else {
5833 netif_rx(skb);
5834 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005835#endif
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005836 } else {
5837send_up:
5838 queue_rx_frame(skb);
5839 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005840 dev->last_rx = jiffies;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005841aggregate:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 atomic_dec(&sp->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 return SUCCESS;
5844}
5845
5846/**
5847 * s2io_link - stops/starts the Tx queue.
5848 * @sp : private member of the device structure, which is a pointer to the
5849 * s2io_nic structure.
5850 * @link : inidicates whether link is UP/DOWN.
5851 * Description:
5852 * This function stops/starts the Tx queue depending on whether the link
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005853 * status of the NIC is is down or up. This is called by the Alarm
5854 * interrupt handler whenever a link change interrupt comes up.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 * Return value:
5856 * void.
5857 */
5858
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005859void s2io_link(nic_t * sp, int link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860{
5861 struct net_device *dev = (struct net_device *) sp->dev;
5862
5863 if (link != sp->last_link_state) {
5864 if (link == LINK_DOWN) {
5865 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
5866 netif_carrier_off(dev);
5867 } else {
5868 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
5869 netif_carrier_on(dev);
5870 }
5871 }
5872 sp->last_link_state = link;
5873}
5874
5875/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005876 * get_xena_rev_id - to identify revision ID of xena.
5877 * @pdev : PCI Dev structure
5878 * Description:
5879 * Function to identify the Revision ID of xena.
5880 * Return value:
5881 * returns the revision ID of the device.
5882 */
5883
5884int get_xena_rev_id(struct pci_dev *pdev)
5885{
5886 u8 id = 0;
5887 int ret;
5888 ret = pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) & id);
5889 return id;
5890}
5891
5892/**
5893 * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
5894 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895 * s2io_nic structure.
5896 * Description:
5897 * This function initializes a few of the PCI and PCI-X configuration registers
5898 * with recommended values.
5899 * Return value:
5900 * void
5901 */
5902
5903static void s2io_init_pci(nic_t * sp)
5904{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005905 u16 pci_cmd = 0, pcix_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906
5907 /* Enable Data Parity Error Recovery in PCI-X command register. */
5908 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005909 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005911 (pcix_cmd | 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005913 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914
5915 /* Set the PErr Response bit in PCI command register. */
5916 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
5917 pci_write_config_word(sp->pdev, PCI_COMMAND,
5918 (pci_cmd | PCI_COMMAND_PARITY));
5919 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
5920
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921 /* Forcibly disabling relaxed ordering capability of the card. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005922 pcix_cmd &= 0xfffd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005924 pcix_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005926 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927}
5928
5929MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
5930MODULE_LICENSE("GPL");
John Linville6c1792f2005-10-04 07:51:45 -04005931MODULE_VERSION(DRV_VERSION);
5932
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933module_param(tx_fifo_num, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934module_param(rx_ring_num, int, 0);
Ananda Rajuda6971d2005-10-31 16:55:31 -05005935module_param(rx_ring_mode, int, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005936module_param_array(tx_fifo_len, uint, NULL, 0);
5937module_param_array(rx_ring_sz, uint, NULL, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005938module_param_array(rts_frm_len, uint, NULL, 0);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07005939module_param(use_continuous_tx_intrs, int, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940module_param(rmac_pause_time, int, 0);
5941module_param(mc_pause_threshold_q0q3, int, 0);
5942module_param(mc_pause_threshold_q4q7, int, 0);
5943module_param(shared_splits, int, 0);
5944module_param(tmac_util_period, int, 0);
5945module_param(rmac_util_period, int, 0);
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07005946module_param(bimodal, bool, 0);
Ananda Rajuda6971d2005-10-31 16:55:31 -05005947module_param(l3l4hdr_size, int , 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948#ifndef CONFIG_S2IO_NAPI
5949module_param(indicate_max_pkts, int, 0);
5950#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07005951module_param(rxsync_frequency, int, 0);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005952module_param(intr_type, int, 0);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005953module_param(lro, int, 0);
5954module_param(lro_max_pkts, int, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005955
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005957 * s2io_init_nic - Initialization of the adapter .
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 * @pdev : structure containing the PCI related information of the device.
5959 * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
5960 * Description:
5961 * The function initializes an adapter identified by the pci_dec structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005962 * All OS related initialization including memory and device structure and
5963 * initlaization of the device private variable is done. Also the swapper
5964 * control register is initialized to enable read and write into the I/O
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 * registers of the device.
5966 * Return value:
5967 * returns 0 on success and negative on failure.
5968 */
5969
5970static int __devinit
5971s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5972{
5973 nic_t *sp;
5974 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975 int i, j, ret;
5976 int dma_flag = FALSE;
5977 u32 mac_up, mac_down;
5978 u64 val64 = 0, tmp64 = 0;
5979 XENA_dev_config_t __iomem *bar0 = NULL;
5980 u16 subid;
5981 mac_info_t *mac_control;
5982 struct config_param *config;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005983 int mode;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005984 u8 dev_intr_type = intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005986#ifdef CONFIG_S2IO_NAPI
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005987 if (dev_intr_type != INTA) {
5988 DBG_PRINT(ERR_DBG, "NAPI cannot be enabled when MSI/MSI-X \
5989is enabled. Defaulting to INTA\n");
5990 dev_intr_type = INTA;
5991 }
5992 else
5993 DBG_PRINT(ERR_DBG, "NAPI support has been enabled\n");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005994#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995
5996 if ((ret = pci_enable_device(pdev))) {
5997 DBG_PRINT(ERR_DBG,
5998 "s2io_init_nic: pci_enable_device failed\n");
5999 return ret;
6000 }
6001
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006002 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
6004 dma_flag = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005 if (pci_set_consistent_dma_mask
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006006 (pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 DBG_PRINT(ERR_DBG,
6008 "Unable to obtain 64bit DMA for \
6009 consistent allocations\n");
6010 pci_disable_device(pdev);
6011 return -ENOMEM;
6012 }
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006013 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
6015 } else {
6016 pci_disable_device(pdev);
6017 return -ENOMEM;
6018 }
6019
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006020 if ((dev_intr_type == MSI_X) &&
6021 ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
6022 (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
6023 DBG_PRINT(ERR_DBG, "Xframe I does not support MSI_X. \
6024Defaulting to INTA\n");
6025 dev_intr_type = INTA;
6026 }
6027 if (dev_intr_type != MSI_X) {
6028 if (pci_request_regions(pdev, s2io_driver_name)) {
6029 DBG_PRINT(ERR_DBG, "Request Regions failed\n"),
6030 pci_disable_device(pdev);
6031 return -ENODEV;
6032 }
6033 }
6034 else {
6035 if (!(request_mem_region(pci_resource_start(pdev, 0),
6036 pci_resource_len(pdev, 0), s2io_driver_name))) {
6037 DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
6038 pci_disable_device(pdev);
6039 return -ENODEV;
6040 }
6041 if (!(request_mem_region(pci_resource_start(pdev, 2),
6042 pci_resource_len(pdev, 2), s2io_driver_name))) {
6043 DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
6044 release_mem_region(pci_resource_start(pdev, 0),
6045 pci_resource_len(pdev, 0));
6046 pci_disable_device(pdev);
6047 return -ENODEV;
6048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049 }
6050
6051 dev = alloc_etherdev(sizeof(nic_t));
6052 if (dev == NULL) {
6053 DBG_PRINT(ERR_DBG, "Device allocation failed\n");
6054 pci_disable_device(pdev);
6055 pci_release_regions(pdev);
6056 return -ENODEV;
6057 }
6058
6059 pci_set_master(pdev);
6060 pci_set_drvdata(pdev, dev);
6061 SET_MODULE_OWNER(dev);
6062 SET_NETDEV_DEV(dev, &pdev->dev);
6063
6064 /* Private member variable initialized to s2io NIC structure */
6065 sp = dev->priv;
6066 memset(sp, 0, sizeof(nic_t));
6067 sp->dev = dev;
6068 sp->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069 sp->high_dma_flag = dma_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 sp->device_enabled_once = FALSE;
Ananda Rajuda6971d2005-10-31 16:55:31 -05006071 if (rx_ring_mode == 1)
6072 sp->rxd_mode = RXD_MODE_1;
6073 if (rx_ring_mode == 2)
6074 sp->rxd_mode = RXD_MODE_3B;
6075 if (rx_ring_mode == 3)
6076 sp->rxd_mode = RXD_MODE_3A;
6077
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006078 sp->intr_type = dev_intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006080 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
6081 (pdev->device == PCI_DEVICE_ID_HERC_UNI))
6082 sp->device_type = XFRAME_II_DEVICE;
6083 else
6084 sp->device_type = XFRAME_I_DEVICE;
6085
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006086 sp->lro = lro;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006087
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088 /* Initialize some PCI/PCI-X fields of the NIC. */
6089 s2io_init_pci(sp);
6090
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006091 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 * Setting the device configuration parameters.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006093 * Most of these parameters can be specified by the user during
6094 * module insertion as they are module loadable parameters. If
6095 * these parameters are not not specified during load time, they
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 * are initialized with default values.
6097 */
6098 mac_control = &sp->mac_control;
6099 config = &sp->config;
6100
6101 /* Tx side parameters. */
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006102 if (tx_fifo_len[0] == 0)
6103 tx_fifo_len[0] = DEFAULT_FIFO_LEN; /* Default value. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 config->tx_fifo_num = tx_fifo_num;
6105 for (i = 0; i < MAX_TX_FIFOS; i++) {
6106 config->tx_cfg[i].fifo_len = tx_fifo_len[i];
6107 config->tx_cfg[i].fifo_priority = i;
6108 }
6109
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006110 /* mapping the QoS priority to the configured fifos */
6111 for (i = 0; i < MAX_TX_FIFOS; i++)
6112 config->fifo_mapping[i] = fifo_map[config->tx_fifo_num][i];
6113
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 config->tx_intr_type = TXD_INT_TYPE_UTILZ;
6115 for (i = 0; i < config->tx_fifo_num; i++) {
6116 config->tx_cfg[i].f_no_snoop =
6117 (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
6118 if (config->tx_cfg[i].fifo_len < 65) {
6119 config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
6120 break;
6121 }
6122 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006123 /* + 2 because one Txd for skb->data and one Txd for UFO */
6124 config->max_txds = MAX_SKB_FRAGS + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125
6126 /* Rx side parameters. */
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006127 if (rx_ring_sz[0] == 0)
6128 rx_ring_sz[0] = SMALL_BLK_CNT; /* Default value. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 config->rx_ring_num = rx_ring_num;
6130 for (i = 0; i < MAX_RX_RINGS; i++) {
6131 config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
Ananda Rajuda6971d2005-10-31 16:55:31 -05006132 (rxd_count[sp->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 config->rx_cfg[i].ring_priority = i;
6134 }
6135
6136 for (i = 0; i < rx_ring_num; i++) {
6137 config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
6138 config->rx_cfg[i].f_no_snoop =
6139 (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
6140 }
6141
6142 /* Setting Mac Control parameters */
6143 mac_control->rmac_pause_time = rmac_pause_time;
6144 mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
6145 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
6146
6147
6148 /* Initialize Ring buffer parameters. */
6149 for (i = 0; i < config->rx_ring_num; i++)
6150 atomic_set(&sp->rx_bufs_left[i], 0);
6151
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006152 /* Initialize the number of ISRs currently running */
6153 atomic_set(&sp->isr_cnt, 0);
6154
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 /* initialize the shared memory used by the NIC and the host */
6156 if (init_shared_mem(sp)) {
6157 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006158 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 ret = -ENOMEM;
6160 goto mem_alloc_failed;
6161 }
6162
6163 sp->bar0 = ioremap(pci_resource_start(pdev, 0),
6164 pci_resource_len(pdev, 0));
6165 if (!sp->bar0) {
6166 DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",
6167 dev->name);
6168 ret = -ENOMEM;
6169 goto bar0_remap_failed;
6170 }
6171
6172 sp->bar1 = ioremap(pci_resource_start(pdev, 2),
6173 pci_resource_len(pdev, 2));
6174 if (!sp->bar1) {
6175 DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",
6176 dev->name);
6177 ret = -ENOMEM;
6178 goto bar1_remap_failed;
6179 }
6180
6181 dev->irq = pdev->irq;
6182 dev->base_addr = (unsigned long) sp->bar0;
6183
6184 /* Initializing the BAR1 address as the start of the FIFO pointer. */
6185 for (j = 0; j < MAX_TX_FIFOS; j++) {
6186 mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)
6187 (sp->bar1 + (j * 0x00020000));
6188 }
6189
6190 /* Driver entry points */
6191 dev->open = &s2io_open;
6192 dev->stop = &s2io_close;
6193 dev->hard_start_xmit = &s2io_xmit;
6194 dev->get_stats = &s2io_get_stats;
6195 dev->set_multicast_list = &s2io_set_multicast;
6196 dev->do_ioctl = &s2io_ioctl;
6197 dev->change_mtu = &s2io_change_mtu;
6198 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07006199 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6200 dev->vlan_rx_register = s2io_vlan_rx_register;
6201 dev->vlan_rx_kill_vid = (void *)s2io_vlan_rx_kill_vid;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006202
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 /*
6204 * will use eth_mac_addr() for dev->set_mac_address
6205 * mac address will be set every time dev->open() is called
6206 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006207#if defined(CONFIG_S2IO_NAPI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 dev->poll = s2io_poll;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006209 dev->weight = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210#endif
6211
6212 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
6213 if (sp->high_dma_flag == TRUE)
6214 dev->features |= NETIF_F_HIGHDMA;
6215#ifdef NETIF_F_TSO
6216 dev->features |= NETIF_F_TSO;
6217#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006218 if (sp->device_type & XFRAME_II_DEVICE) {
6219 dev->features |= NETIF_F_UFO;
6220 dev->features |= NETIF_F_HW_CSUM;
6221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222
6223 dev->tx_timeout = &s2io_tx_watchdog;
6224 dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
6225 INIT_WORK(&sp->rst_timer_task,
6226 (void (*)(void *)) s2io_restart_nic, dev);
6227 INIT_WORK(&sp->set_link_task,
6228 (void (*)(void *)) s2io_set_link, sp);
6229
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07006230 pci_save_state(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231
6232 /* Setting swapper control on the NIC, for proper reset operation */
6233 if (s2io_set_swapper(sp)) {
6234 DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
6235 dev->name);
6236 ret = -EAGAIN;
6237 goto set_swap_failed;
6238 }
6239
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006240 /* Verify if the Herc works on the slot its placed into */
6241 if (sp->device_type & XFRAME_II_DEVICE) {
6242 mode = s2io_verify_pci_mode(sp);
6243 if (mode < 0) {
6244 DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);
6245 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
6246 ret = -EBADSLT;
6247 goto set_swap_failed;
6248 }
6249 }
6250
6251 /* Not needed for Herc */
6252 if (sp->device_type & XFRAME_I_DEVICE) {
6253 /*
6254 * Fix for all "FFs" MAC address problems observed on
6255 * Alpha platforms
6256 */
6257 fix_mac_address(sp);
6258 s2io_reset(sp);
6259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260
6261 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 * MAC address initialization.
6263 * For now only one mac address will be read and used.
6264 */
6265 bar0 = sp->bar0;
6266 val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
6267 RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
6268 writeq(val64, &bar0->rmac_addr_cmd_mem);
6269 wait_for_cmd_complete(sp);
6270
6271 tmp64 = readq(&bar0->rmac_addr_data0_mem);
6272 mac_down = (u32) tmp64;
6273 mac_up = (u32) (tmp64 >> 32);
6274
6275 memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
6276
6277 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
6278 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
6279 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
6280 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
6281 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
6282 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
6283
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 /* Set the factory defined MAC address initially */
6285 dev->addr_len = ETH_ALEN;
6286 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
6287
6288 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006289 * Initialize the tasklet status and link state flags
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006290 * and the card state parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 */
6292 atomic_set(&(sp->card_state), 0);
6293 sp->tasklet_status = 0;
6294 sp->link_state = 0;
6295
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 /* Initialize spinlocks */
6297 spin_lock_init(&sp->tx_lock);
6298#ifndef CONFIG_S2IO_NAPI
6299 spin_lock_init(&sp->put_lock);
6300#endif
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006301 spin_lock_init(&sp->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006303 /*
6304 * SXE-002: Configure link and activity LED to init state
6305 * on driver load.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 */
6307 subid = sp->pdev->subsystem_device;
6308 if ((subid & 0xFF) >= 0x07) {
6309 val64 = readq(&bar0->gpio_control);
6310 val64 |= 0x0000800000000000ULL;
6311 writeq(val64, &bar0->gpio_control);
6312 val64 = 0x0411040400000000ULL;
6313 writeq(val64, (void __iomem *) bar0 + 0x2700);
6314 val64 = readq(&bar0->gpio_control);
6315 }
6316
6317 sp->rx_csum = 1; /* Rx chksum verify enabled by default */
6318
6319 if (register_netdev(dev)) {
6320 DBG_PRINT(ERR_DBG, "Device registration failed\n");
6321 ret = -ENODEV;
6322 goto register_failed;
6323 }
6324
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006325 if (sp->device_type & XFRAME_II_DEVICE) {
6326 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ",
6327 dev->name);
John Linville6c1792f2005-10-04 07:51:45 -04006328 DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006329 get_xena_rev_id(sp->pdev),
6330 s2io_driver_version);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006331 switch(sp->intr_type) {
6332 case INTA:
6333 DBG_PRINT(ERR_DBG, ", Intr type INTA");
6334 break;
6335 case MSI:
6336 DBG_PRINT(ERR_DBG, ", Intr type MSI");
6337 break;
6338 case MSI_X:
6339 DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
6340 break;
6341 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07006342
6343 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006344 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
6345 sp->def_mac_addr[0].mac_addr[0],
6346 sp->def_mac_addr[0].mac_addr[1],
6347 sp->def_mac_addr[0].mac_addr[2],
6348 sp->def_mac_addr[0].mac_addr[3],
6349 sp->def_mac_addr[0].mac_addr[4],
6350 sp->def_mac_addr[0].mac_addr[5]);
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006351 mode = s2io_print_pci_mode(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006352 if (mode < 0) {
6353 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode ");
6354 ret = -EBADSLT;
6355 goto set_swap_failed;
6356 }
6357 } else {
6358 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ",
6359 dev->name);
John Linville6c1792f2005-10-04 07:51:45 -04006360 DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006361 get_xena_rev_id(sp->pdev),
6362 s2io_driver_version);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006363 switch(sp->intr_type) {
6364 case INTA:
6365 DBG_PRINT(ERR_DBG, ", Intr type INTA");
6366 break;
6367 case MSI:
6368 DBG_PRINT(ERR_DBG, ", Intr type MSI");
6369 break;
6370 case MSI_X:
6371 DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
6372 break;
6373 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07006374 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006375 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
6376 sp->def_mac_addr[0].mac_addr[0],
6377 sp->def_mac_addr[0].mac_addr[1],
6378 sp->def_mac_addr[0].mac_addr[2],
6379 sp->def_mac_addr[0].mac_addr[3],
6380 sp->def_mac_addr[0].mac_addr[4],
6381 sp->def_mac_addr[0].mac_addr[5]);
6382 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05006383 if (sp->rxd_mode == RXD_MODE_3B)
6384 DBG_PRINT(ERR_DBG, "%s: 2-Buffer mode support has been "
6385 "enabled\n",dev->name);
6386 if (sp->rxd_mode == RXD_MODE_3A)
6387 DBG_PRINT(ERR_DBG, "%s: 3-Buffer mode support has been "
6388 "enabled\n",dev->name);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006389
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006390 if (sp->lro)
6391 DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
6392 dev->name);
6393
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006394 /* Initialize device name */
6395 strcpy(sp->name, dev->name);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006396 if (sp->device_type & XFRAME_II_DEVICE)
6397 strcat(sp->name, ": Neterion Xframe II 10GbE adapter");
6398 else
6399 strcat(sp->name, ": Neterion Xframe I 10GbE adapter");
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006400
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07006401 /* Initialize bimodal Interrupts */
6402 sp->config.bimodal = bimodal;
6403 if (!(sp->device_type & XFRAME_II_DEVICE) && bimodal) {
6404 sp->config.bimodal = 0;
6405 DBG_PRINT(ERR_DBG,"%s:Bimodal intr not supported by Xframe I\n",
6406 dev->name);
6407 }
6408
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006409 /*
6410 * Make Link state as off at this point, when the Link change
6411 * interrupt comes the state will be automatically changed to
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 * the right state.
6413 */
6414 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415
6416 return 0;
6417
6418 register_failed:
6419 set_swap_failed:
6420 iounmap(sp->bar1);
6421 bar1_remap_failed:
6422 iounmap(sp->bar0);
6423 bar0_remap_failed:
6424 mem_alloc_failed:
6425 free_shared_mem(sp);
6426 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006427 if (dev_intr_type != MSI_X)
6428 pci_release_regions(pdev);
6429 else {
6430 release_mem_region(pci_resource_start(pdev, 0),
6431 pci_resource_len(pdev, 0));
6432 release_mem_region(pci_resource_start(pdev, 2),
6433 pci_resource_len(pdev, 2));
6434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 pci_set_drvdata(pdev, NULL);
6436 free_netdev(dev);
6437
6438 return ret;
6439}
6440
6441/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006442 * s2io_rem_nic - Free the PCI device
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 * @pdev: structure containing the PCI related information of the device.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006444 * Description: This function is called by the Pci subsystem to release a
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 * PCI device and free up all resource held up by the device. This could
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006446 * be in response to a Hot plug event or when the driver is to be removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 * from memory.
6448 */
6449
6450static void __devexit s2io_rem_nic(struct pci_dev *pdev)
6451{
6452 struct net_device *dev =
6453 (struct net_device *) pci_get_drvdata(pdev);
6454 nic_t *sp;
6455
6456 if (dev == NULL) {
6457 DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
6458 return;
6459 }
6460
6461 sp = dev->priv;
6462 unregister_netdev(dev);
6463
6464 free_shared_mem(sp);
6465 iounmap(sp->bar0);
6466 iounmap(sp->bar1);
6467 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006468 if (sp->intr_type != MSI_X)
6469 pci_release_regions(pdev);
6470 else {
6471 release_mem_region(pci_resource_start(pdev, 0),
6472 pci_resource_len(pdev, 0));
6473 release_mem_region(pci_resource_start(pdev, 2),
6474 pci_resource_len(pdev, 2));
6475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 free_netdev(dev);
6478}
6479
6480/**
6481 * s2io_starter - Entry point for the driver
6482 * Description: This function is the entry point for the driver. It verifies
6483 * the module loadable parameters and initializes PCI configuration space.
6484 */
6485
6486int __init s2io_starter(void)
6487{
6488 return pci_module_init(&s2io_driver);
6489}
6490
6491/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006492 * s2io_closer - Cleanup routine for the driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
6494 */
6495
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006496void s2io_closer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497{
6498 pci_unregister_driver(&s2io_driver);
6499 DBG_PRINT(INIT_DBG, "cleanup done\n");
6500}
6501
6502module_init(s2io_starter);
6503module_exit(s2io_closer);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006504
6505static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
6506 struct tcphdr **tcp, RxD_t *rxdp)
6507{
6508 int ip_off;
6509 u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
6510
6511 if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
6512 DBG_PRINT(INIT_DBG,"%s: Non-TCP frames not supported for LRO\n",
6513 __FUNCTION__);
6514 return -1;
6515 }
6516
6517 /* TODO:
6518 * By default the VLAN field in the MAC is stripped by the card, if this
6519 * feature is turned off in rx_pa_cfg register, then the ip_off field
6520 * has to be shifted by a further 2 bytes
6521 */
6522 switch (l2_type) {
6523 case 0: /* DIX type */
6524 case 4: /* DIX type with VLAN */
6525 ip_off = HEADER_ETHERNET_II_802_3_SIZE;
6526 break;
6527 /* LLC, SNAP etc are considered non-mergeable */
6528 default:
6529 return -1;
6530 }
6531
6532 *ip = (struct iphdr *)((u8 *)buffer + ip_off);
6533 ip_len = (u8)((*ip)->ihl);
6534 ip_len <<= 2;
6535 *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
6536
6537 return 0;
6538}
6539
6540static int check_for_socket_match(lro_t *lro, struct iphdr *ip,
6541 struct tcphdr *tcp)
6542{
6543 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6544 if ((lro->iph->saddr != ip->saddr) || (lro->iph->daddr != ip->daddr) ||
6545 (lro->tcph->source != tcp->source) || (lro->tcph->dest != tcp->dest))
6546 return -1;
6547 return 0;
6548}
6549
6550static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
6551{
6552 return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
6553}
6554
6555static void initiate_new_session(lro_t *lro, u8 *l2h,
6556 struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len)
6557{
6558 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6559 lro->l2h = l2h;
6560 lro->iph = ip;
6561 lro->tcph = tcp;
6562 lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
6563 lro->tcp_ack = ntohl(tcp->ack_seq);
6564 lro->sg_num = 1;
6565 lro->total_len = ntohs(ip->tot_len);
6566 lro->frags_len = 0;
6567 /*
6568 * check if we saw TCP timestamp. Other consistency checks have
6569 * already been done.
6570 */
6571 if (tcp->doff == 8) {
6572 u32 *ptr;
6573 ptr = (u32 *)(tcp+1);
6574 lro->saw_ts = 1;
6575 lro->cur_tsval = *(ptr+1);
6576 lro->cur_tsecr = *(ptr+2);
6577 }
6578 lro->in_use = 1;
6579}
6580
6581static void update_L3L4_header(nic_t *sp, lro_t *lro)
6582{
6583 struct iphdr *ip = lro->iph;
6584 struct tcphdr *tcp = lro->tcph;
6585 u16 nchk;
6586 StatInfo_t *statinfo = sp->mac_control.stats_info;
6587 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6588
6589 /* Update L3 header */
6590 ip->tot_len = htons(lro->total_len);
6591 ip->check = 0;
6592 nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
6593 ip->check = nchk;
6594
6595 /* Update L4 header */
6596 tcp->ack_seq = lro->tcp_ack;
6597 tcp->window = lro->window;
6598
6599 /* Update tsecr field if this session has timestamps enabled */
6600 if (lro->saw_ts) {
6601 u32 *ptr = (u32 *)(tcp + 1);
6602 *(ptr+2) = lro->cur_tsecr;
6603 }
6604
6605 /* Update counters required for calculation of
6606 * average no. of packets aggregated.
6607 */
6608 statinfo->sw_stat.sum_avg_pkts_aggregated += lro->sg_num;
6609 statinfo->sw_stat.num_aggregations++;
6610}
6611
6612static void aggregate_new_rx(lro_t *lro, struct iphdr *ip,
6613 struct tcphdr *tcp, u32 l4_pyld)
6614{
6615 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6616 lro->total_len += l4_pyld;
6617 lro->frags_len += l4_pyld;
6618 lro->tcp_next_seq += l4_pyld;
6619 lro->sg_num++;
6620
6621 /* Update ack seq no. and window ad(from this pkt) in LRO object */
6622 lro->tcp_ack = tcp->ack_seq;
6623 lro->window = tcp->window;
6624
6625 if (lro->saw_ts) {
6626 u32 *ptr;
6627 /* Update tsecr and tsval from this packet */
6628 ptr = (u32 *) (tcp + 1);
6629 lro->cur_tsval = *(ptr + 1);
6630 lro->cur_tsecr = *(ptr + 2);
6631 }
6632}
6633
6634static int verify_l3_l4_lro_capable(lro_t *l_lro, struct iphdr *ip,
6635 struct tcphdr *tcp, u32 tcp_pyld_len)
6636{
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006637 u8 *ptr;
6638
Andrew Morton79dc1902006-02-03 01:45:13 -08006639 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6640
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006641 if (!tcp_pyld_len) {
6642 /* Runt frame or a pure ack */
6643 return -1;
6644 }
6645
6646 if (ip->ihl != 5) /* IP has options */
6647 return -1;
6648
6649 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
6650 !tcp->ack) {
6651 /*
6652 * Currently recognize only the ack control word and
6653 * any other control field being set would result in
6654 * flushing the LRO session
6655 */
6656 return -1;
6657 }
6658
6659 /*
6660 * Allow only one TCP timestamp option. Don't aggregate if
6661 * any other options are detected.
6662 */
6663 if (tcp->doff != 5 && tcp->doff != 8)
6664 return -1;
6665
6666 if (tcp->doff == 8) {
6667 ptr = (u8 *)(tcp + 1);
6668 while (*ptr == TCPOPT_NOP)
6669 ptr++;
6670 if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
6671 return -1;
6672
6673 /* Ensure timestamp value increases monotonically */
6674 if (l_lro)
6675 if (l_lro->cur_tsval > *((u32 *)(ptr+2)))
6676 return -1;
6677
6678 /* timestamp echo reply should be non-zero */
6679 if (*((u32 *)(ptr+6)) == 0)
6680 return -1;
6681 }
6682
6683 return 0;
6684}
6685
6686static int
6687s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
6688 RxD_t *rxdp, nic_t *sp)
6689{
6690 struct iphdr *ip;
6691 struct tcphdr *tcph;
6692 int ret = 0, i;
6693
6694 if (!(ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
6695 rxdp))) {
6696 DBG_PRINT(INFO_DBG,"IP Saddr: %x Daddr: %x\n",
6697 ip->saddr, ip->daddr);
6698 } else {
6699 return ret;
6700 }
6701
6702 tcph = (struct tcphdr *)*tcp;
6703 *tcp_len = get_l4_pyld_length(ip, tcph);
6704 for (i=0; i<MAX_LRO_SESSIONS; i++) {
6705 lro_t *l_lro = &sp->lro0_n[i];
6706 if (l_lro->in_use) {
6707 if (check_for_socket_match(l_lro, ip, tcph))
6708 continue;
6709 /* Sock pair matched */
6710 *lro = l_lro;
6711
6712 if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
6713 DBG_PRINT(INFO_DBG, "%s:Out of order. expected "
6714 "0x%x, actual 0x%x\n", __FUNCTION__,
6715 (*lro)->tcp_next_seq,
6716 ntohl(tcph->seq));
6717
6718 sp->mac_control.stats_info->
6719 sw_stat.outof_sequence_pkts++;
6720 ret = 2;
6721 break;
6722 }
6723
6724 if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,*tcp_len))
6725 ret = 1; /* Aggregate */
6726 else
6727 ret = 2; /* Flush both */
6728 break;
6729 }
6730 }
6731
6732 if (ret == 0) {
6733 /* Before searching for available LRO objects,
6734 * check if the pkt is L3/L4 aggregatable. If not
6735 * don't create new LRO session. Just send this
6736 * packet up.
6737 */
6738 if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len)) {
6739 return 5;
6740 }
6741
6742 for (i=0; i<MAX_LRO_SESSIONS; i++) {
6743 lro_t *l_lro = &sp->lro0_n[i];
6744 if (!(l_lro->in_use)) {
6745 *lro = l_lro;
6746 ret = 3; /* Begin anew */
6747 break;
6748 }
6749 }
6750 }
6751
6752 if (ret == 0) { /* sessions exceeded */
6753 DBG_PRINT(INFO_DBG,"%s:All LRO sessions already in use\n",
6754 __FUNCTION__);
6755 *lro = NULL;
6756 return ret;
6757 }
6758
6759 switch (ret) {
6760 case 3:
6761 initiate_new_session(*lro, buffer, ip, tcph, *tcp_len);
6762 break;
6763 case 2:
6764 update_L3L4_header(sp, *lro);
6765 break;
6766 case 1:
6767 aggregate_new_rx(*lro, ip, tcph, *tcp_len);
6768 if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
6769 update_L3L4_header(sp, *lro);
6770 ret = 4; /* Flush the LRO */
6771 }
6772 break;
6773 default:
6774 DBG_PRINT(ERR_DBG,"%s:Dont know, can't say!!\n",
6775 __FUNCTION__);
6776 break;
6777 }
6778
6779 return ret;
6780}
6781
6782static void clear_lro_session(lro_t *lro)
6783{
6784 static u16 lro_struct_size = sizeof(lro_t);
6785
6786 memset(lro, 0, lro_struct_size);
6787}
6788
6789static void queue_rx_frame(struct sk_buff *skb)
6790{
6791 struct net_device *dev = skb->dev;
6792
6793 skb->protocol = eth_type_trans(skb, dev);
6794#ifdef CONFIG_S2IO_NAPI
6795 netif_receive_skb(skb);
6796#else
6797 netif_rx(skb);
6798#endif
6799}
6800
6801static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb,
6802 u32 tcp_len)
6803{
6804 struct sk_buff *tmp, *first = lro->parent;
6805
6806 first->len += tcp_len;
6807 first->data_len = lro->frags_len;
6808 skb_pull(skb, (skb->len - tcp_len));
6809 if ((tmp = skb_shinfo(first)->frag_list)) {
6810 while (tmp->next)
6811 tmp = tmp->next;
6812 tmp->next = skb;
6813 }
6814 else
6815 skb_shinfo(first)->frag_list = skb;
6816 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
6817 return;
6818}