blob: 078a49e859361104c2974f63934017dc3aaa08c5 [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.
Ananda Raju9dc737a2006-04-21 19:05:41 -040029 *
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070030 * rx_ring_num : This can be used to program the number of receive rings used
31 * in the driver.
Ananda Raju9dc737a2006-04-21 19:05:41 -040032 * rx_ring_sz: This defines the number of receive blocks each ring can have.
33 * This is also an array of size 8.
Ananda Rajuda6971d2005-10-31 16:55:31 -050034 * rx_ring_mode: This defines the operation mode of all 8 rings. The valid
35 * values are 1, 2 and 3.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070037 * tx_fifo_len: This too is an array of 8. Each element defines the number of
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * Tx descriptors that can be associated with each corresponding FIFO.
Ananda Raju9dc737a2006-04-21 19:05:41 -040039 * intr_type: This defines the type of interrupt. The values can be 0(INTA),
40 * 1(MSI), 2(MSI_X). Default value is '0(INTA)'
41 * lro: Specifies whether to enable Large Receive Offload (LRO) or not.
42 * Possible values '1' for enable '0' for disable. Default is '0'
43 * lro_max_pkts: This parameter defines maximum number of packets can be
44 * aggregated as a single large packet
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 ************************************************************************/
46
47#include <linux/config.h>
48#include <linux/module.h>
49#include <linux/types.h>
50#include <linux/errno.h>
51#include <linux/ioport.h>
52#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040053#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <linux/kernel.h>
55#include <linux/netdevice.h>
56#include <linux/etherdevice.h>
57#include <linux/skbuff.h>
58#include <linux/init.h>
59#include <linux/delay.h>
60#include <linux/stddef.h>
61#include <linux/ioctl.h>
62#include <linux/timex.h>
63#include <linux/sched.h>
64#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#include <linux/workqueue.h>
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -070066#include <linux/if_vlan.h>
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050067#include <linux/ip.h>
68#include <linux/tcp.h>
69#include <net/tcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <asm/system.h>
72#include <asm/uaccess.h>
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070073#include <asm/io.h>
Andrew Mortonfe931392006-02-03 01:45:12 -080074#include <asm/div64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/* local include */
77#include "s2io.h"
78#include "s2io-regs.h"
79
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050080#define DRV_VERSION "2.0.11.2"
John Linville6c1792f2005-10-04 07:51:45 -040081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/* S2io Driver name & version. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070083static char s2io_driver_name[] = "Neterion";
John Linville6c1792f2005-10-04 07:51:45 -040084static char s2io_driver_version[] = DRV_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Adrian Bunk26df54b2006-01-14 03:09:40 +010086static int rxd_size[4] = {32,48,48,64};
87static int rxd_count[4] = {127,85,85,63};
Ananda Rajuda6971d2005-10-31 16:55:31 -050088
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -070089static inline int RXD_IS_UP2DT(RxD_t *rxdp)
90{
91 int ret;
92
93 ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
94 (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
95
96 return ret;
97}
98
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070099/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 * Cards with following subsystem_id have a link state indication
101 * problem, 600B, 600C, 600D, 640B, 640C and 640D.
102 * macro below identifies these cards given the subsystem_id.
103 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700104#define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
105 (dev_type == XFRAME_I_DEVICE) ? \
106 ((((subid >= 0x600B) && (subid <= 0x600D)) || \
107 ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
110 ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
111#define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
112#define PANIC 1
113#define LOW 2
114static inline int rx_buffer_level(nic_t * sp, int rxb_size, int ring)
115{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700116 mac_info_t *mac_control;
117
118 mac_control = &sp->mac_control;
Ananda Raju863c11a2006-04-21 19:03:13 -0400119 if (rxb_size <= rxd_count[sp->rxd_mode])
120 return PANIC;
121 else if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16)
122 return LOW;
123 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126/* Ethtool related variables and Macros. */
127static char s2io_gstrings[][ETH_GSTRING_LEN] = {
128 "Register test\t(offline)",
129 "Eeprom test\t(offline)",
130 "Link test\t(online)",
131 "RLDRAM test\t(offline)",
132 "BIST Test\t(offline)"
133};
134
135static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
136 {"tmac_frms"},
137 {"tmac_data_octets"},
138 {"tmac_drop_frms"},
139 {"tmac_mcst_frms"},
140 {"tmac_bcst_frms"},
141 {"tmac_pause_ctrl_frms"},
142 {"tmac_any_err_frms"},
143 {"tmac_vld_ip_octets"},
144 {"tmac_vld_ip"},
145 {"tmac_drop_ip"},
146 {"tmac_icmp"},
147 {"tmac_rst_tcp"},
148 {"tmac_tcp"},
149 {"tmac_udp"},
150 {"rmac_vld_frms"},
151 {"rmac_data_octets"},
152 {"rmac_fcs_err_frms"},
153 {"rmac_drop_frms"},
154 {"rmac_vld_mcst_frms"},
155 {"rmac_vld_bcst_frms"},
156 {"rmac_in_rng_len_err_frms"},
157 {"rmac_long_frms"},
158 {"rmac_pause_ctrl_frms"},
159 {"rmac_discarded_frms"},
160 {"rmac_usized_frms"},
161 {"rmac_osized_frms"},
162 {"rmac_frag_frms"},
163 {"rmac_jabber_frms"},
164 {"rmac_ip"},
165 {"rmac_ip_octets"},
166 {"rmac_hdr_err_ip"},
167 {"rmac_drop_ip"},
168 {"rmac_icmp"},
169 {"rmac_tcp"},
170 {"rmac_udp"},
171 {"rmac_err_drp_udp"},
172 {"rmac_pause_cnt"},
173 {"rmac_accepted_ip"},
174 {"rmac_err_tcp"},
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -0700175 {"\n DRIVER STATISTICS"},
176 {"single_bit_ecc_errs"},
177 {"double_bit_ecc_errs"},
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -0500178 ("lro_aggregated_pkts"),
179 ("lro_flush_both_count"),
180 ("lro_out_of_sequence_pkts"),
181 ("lro_flush_due_to_max_pkts"),
182 ("lro_avg_aggr_pkts"),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
185#define S2IO_STAT_LEN sizeof(ethtool_stats_keys)/ ETH_GSTRING_LEN
186#define S2IO_STAT_STRINGS_LEN S2IO_STAT_LEN * ETH_GSTRING_LEN
187
188#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
189#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
190
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -0700191#define S2IO_TIMER_CONF(timer, handle, arg, exp) \
192 init_timer(&timer); \
193 timer.function = handle; \
194 timer.data = (unsigned long) arg; \
195 mod_timer(&timer, (jiffies + exp)) \
196
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700197/* Add the vlan */
198static void s2io_vlan_rx_register(struct net_device *dev,
199 struct vlan_group *grp)
200{
201 nic_t *nic = dev->priv;
202 unsigned long flags;
203
204 spin_lock_irqsave(&nic->tx_lock, flags);
205 nic->vlgrp = grp;
206 spin_unlock_irqrestore(&nic->tx_lock, flags);
207}
208
209/* Unregister the vlan */
210static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
211{
212 nic_t *nic = dev->priv;
213 unsigned long flags;
214
215 spin_lock_irqsave(&nic->tx_lock, flags);
216 if (nic->vlgrp)
217 nic->vlgrp->vlan_devices[vid] = NULL;
218 spin_unlock_irqrestore(&nic->tx_lock, flags);
219}
220
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700221/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 * Constants to be programmed into the Xena's registers, to configure
223 * the XAUI.
224 */
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define END_SIGN 0x0
Arjan van de Venf71e1302006-03-03 21:33:57 -0500227static const u64 herc_act_dtx_cfg[] = {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700228 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700229 0x8000051536750000ULL, 0x80000515367500E0ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700230 /* Write data */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700231 0x8000051536750004ULL, 0x80000515367500E4ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700232 /* Set address */
233 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
234 /* Write data */
235 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
236 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700237 0x801205150D440000ULL, 0x801205150D4400E0ULL,
238 /* Write data */
239 0x801205150D440004ULL, 0x801205150D4400E4ULL,
240 /* Set address */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700241 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
242 /* Write data */
243 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
244 /* Done */
245 END_SIGN
246};
247
Arjan van de Venf71e1302006-03-03 21:33:57 -0500248static const u64 xena_dtx_cfg[] = {
Ananda Rajuc92ca042006-04-21 19:18:03 -0400249 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 0x8000051500000000ULL, 0x80000515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400251 /* Write data */
252 0x80000515D9350004ULL, 0x80000515D93500E4ULL,
253 /* Set address */
254 0x8001051500000000ULL, 0x80010515000000E0ULL,
255 /* Write data */
256 0x80010515001E0004ULL, 0x80010515001E00E4ULL,
257 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 0x8002051500000000ULL, 0x80020515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400259 /* Write data */
260 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 END_SIGN
262};
263
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700264/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 * Constants for Fixing the MacAddress problem seen mostly on
266 * Alpha machines.
267 */
Arjan van de Venf71e1302006-03-03 21:33:57 -0500268static const u64 fix_mac[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 0x0060000000000000ULL, 0x0060600000000000ULL,
270 0x0040600000000000ULL, 0x0000600000000000ULL,
271 0x0020600000000000ULL, 0x0060600000000000ULL,
272 0x0020600000000000ULL, 0x0060600000000000ULL,
273 0x0020600000000000ULL, 0x0060600000000000ULL,
274 0x0020600000000000ULL, 0x0060600000000000ULL,
275 0x0020600000000000ULL, 0x0060600000000000ULL,
276 0x0020600000000000ULL, 0x0060600000000000ULL,
277 0x0020600000000000ULL, 0x0060600000000000ULL,
278 0x0020600000000000ULL, 0x0060600000000000ULL,
279 0x0020600000000000ULL, 0x0060600000000000ULL,
280 0x0020600000000000ULL, 0x0060600000000000ULL,
281 0x0020600000000000ULL, 0x0000600000000000ULL,
282 0x0040600000000000ULL, 0x0060600000000000ULL,
283 END_SIGN
284};
285
286/* Module Loadable parameters. */
287static unsigned int tx_fifo_num = 1;
288static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400289 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290static unsigned int rx_ring_num = 1;
291static unsigned int rx_ring_sz[MAX_RX_RINGS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400292 {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700293static unsigned int rts_frm_len[MAX_RX_RINGS] =
294 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
Ananda Rajuda6971d2005-10-31 16:55:31 -0500295static unsigned int rx_ring_mode = 1;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700296static unsigned int use_continuous_tx_intrs = 1;
Ananda Raju863c11a2006-04-21 19:03:13 -0400297static unsigned int rmac_pause_time = 0x100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static unsigned int mc_pause_threshold_q0q3 = 187;
299static unsigned int mc_pause_threshold_q4q7 = 187;
300static unsigned int shared_splits;
301static unsigned int tmac_util_period = 5;
302static unsigned int rmac_util_period = 5;
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -0700303static unsigned int bimodal = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500304static unsigned int l3l4hdr_size = 128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#ifndef CONFIG_S2IO_NAPI
306static unsigned int indicate_max_pkts;
307#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -0700308/* Frequency of Rx desc syncs expressed as power of 2 */
309static unsigned int rxsync_frequency = 3;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -0400310/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
311static unsigned int intr_type = 0;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -0500312/* Large receive offload feature */
313static unsigned int lro = 0;
314/* Max pkts to be aggregated by LRO at one time. If not specified,
315 * aggregation happens until we hit max IP pkt size(64K)
316 */
317static unsigned int lro_max_pkts = 0xFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700319/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 * S2IO device table.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700321 * This table lists all the devices that this driver supports.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
323static struct pci_device_id s2io_tbl[] __devinitdata = {
324 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
325 PCI_ANY_ID, PCI_ANY_ID},
326 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
327 PCI_ANY_ID, PCI_ANY_ID},
328 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700329 PCI_ANY_ID, PCI_ANY_ID},
330 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
331 PCI_ANY_ID, PCI_ANY_ID},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 {0,}
333};
334
335MODULE_DEVICE_TABLE(pci, s2io_tbl);
336
337static struct pci_driver s2io_driver = {
338 .name = "S2IO",
339 .id_table = s2io_tbl,
340 .probe = s2io_init_nic,
341 .remove = __devexit_p(s2io_rem_nic),
342};
343
344/* A simplifier macro used both by init and free shared_mem Fns(). */
345#define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
346
347/**
348 * init_shared_mem - Allocation and Initialization of Memory
349 * @nic: Device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700350 * Description: The function allocates all the memory areas shared
351 * between the NIC and the driver. This includes Tx descriptors,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * Rx descriptors and the statistics block.
353 */
354
355static int init_shared_mem(struct s2io_nic *nic)
356{
357 u32 size;
358 void *tmp_v_addr, *tmp_v_addr_next;
359 dma_addr_t tmp_p_addr, tmp_p_addr_next;
360 RxD_block_t *pre_rxd_blk = NULL;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700361 int i, j, blk_cnt, rx_sz, tx_sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 int lst_size, lst_per_page;
363 struct net_device *dev = nic->dev;
viro@zenIV.linux.org.uk8ae418c2005-09-02 20:15:29 +0100364 unsigned long tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 buffAdd_t *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 mac_info_t *mac_control;
368 struct config_param *config;
369
370 mac_control = &nic->mac_control;
371 config = &nic->config;
372
373
374 /* Allocation and initialization of TXDLs in FIOFs */
375 size = 0;
376 for (i = 0; i < config->tx_fifo_num; i++) {
377 size += config->tx_cfg[i].fifo_len;
378 }
379 if (size > MAX_AVAILABLE_TXDS) {
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -0700380 DBG_PRINT(ERR_DBG, "%s: Requested TxDs too high, ",
381 __FUNCTION__);
382 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return FAILURE;
384 }
385
386 lst_size = (sizeof(TxD_t) * config->max_txds);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700387 tx_sz = lst_size * size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 lst_per_page = PAGE_SIZE / lst_size;
389
390 for (i = 0; i < config->tx_fifo_num; i++) {
391 int fifo_len = config->tx_cfg[i].fifo_len;
392 int list_holder_size = fifo_len * sizeof(list_info_hold_t);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700393 mac_control->fifos[i].list_info = kmalloc(list_holder_size,
394 GFP_KERNEL);
395 if (!mac_control->fifos[i].list_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 DBG_PRINT(ERR_DBG,
397 "Malloc failed for list_info\n");
398 return -ENOMEM;
399 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700400 memset(mac_control->fifos[i].list_info, 0, list_holder_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402 for (i = 0; i < config->tx_fifo_num; i++) {
403 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
404 lst_per_page);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700405 mac_control->fifos[i].tx_curr_put_info.offset = 0;
406 mac_control->fifos[i].tx_curr_put_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700408 mac_control->fifos[i].tx_curr_get_info.offset = 0;
409 mac_control->fifos[i].tx_curr_get_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700411 mac_control->fifos[i].fifo_no = i;
412 mac_control->fifos[i].nic = nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500413 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 2;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 for (j = 0; j < page_num; j++) {
416 int k = 0;
417 dma_addr_t tmp_p;
418 void *tmp_v;
419 tmp_v = pci_alloc_consistent(nic->pdev,
420 PAGE_SIZE, &tmp_p);
421 if (!tmp_v) {
422 DBG_PRINT(ERR_DBG,
423 "pci_alloc_consistent ");
424 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
425 return -ENOMEM;
426 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700427 /* If we got a zero DMA address(can happen on
428 * certain platforms like PPC), reallocate.
429 * Store virtual address of page we don't want,
430 * to be freed later.
431 */
432 if (!tmp_p) {
433 mac_control->zerodma_virt_addr = tmp_v;
434 DBG_PRINT(INIT_DBG,
435 "%s: Zero DMA address for TxDL. ", dev->name);
436 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700437 "Virtual address %p\n", tmp_v);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700438 tmp_v = pci_alloc_consistent(nic->pdev,
439 PAGE_SIZE, &tmp_p);
440 if (!tmp_v) {
441 DBG_PRINT(ERR_DBG,
442 "pci_alloc_consistent ");
443 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
444 return -ENOMEM;
445 }
446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 while (k < lst_per_page) {
448 int l = (j * lst_per_page) + k;
449 if (l == config->tx_cfg[i].fifo_len)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700450 break;
451 mac_control->fifos[i].list_info[l].list_virt_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 tmp_v + (k * lst_size);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700453 mac_control->fifos[i].list_info[l].list_phy_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 tmp_p + (k * lst_size);
455 k++;
456 }
457 }
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500460 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL);
461 if (!nic->ufo_in_band_v)
462 return -ENOMEM;
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 /* Allocation and initialization of RXDs in Rings */
465 size = 0;
466 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500467 if (config->rx_cfg[i].num_rxd %
468 (rxd_count[nic->rxd_mode] + 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
470 DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
471 i);
472 DBG_PRINT(ERR_DBG, "RxDs per Block");
473 return FAILURE;
474 }
475 size += config->rx_cfg[i].num_rxd;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700476 mac_control->rings[i].block_count =
Ananda Rajuda6971d2005-10-31 16:55:31 -0500477 config->rx_cfg[i].num_rxd /
478 (rxd_count[nic->rxd_mode] + 1 );
479 mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
480 mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500482 if (nic->rxd_mode == RXD_MODE_1)
483 size = (size * (sizeof(RxD1_t)));
484 else
485 size = (size * (sizeof(RxD3_t)));
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700486 rx_sz = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700489 mac_control->rings[i].rx_curr_get_info.block_index = 0;
490 mac_control->rings[i].rx_curr_get_info.offset = 0;
491 mac_control->rings[i].rx_curr_get_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700493 mac_control->rings[i].rx_curr_put_info.block_index = 0;
494 mac_control->rings[i].rx_curr_put_info.offset = 0;
495 mac_control->rings[i].rx_curr_put_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700497 mac_control->rings[i].nic = nic;
498 mac_control->rings[i].ring_no = i;
499
Ananda Rajuda6971d2005-10-31 16:55:31 -0500500 blk_cnt = config->rx_cfg[i].num_rxd /
501 (rxd_count[nic->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 /* Allocating all the Rx blocks */
503 for (j = 0; j < blk_cnt; j++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500504 rx_block_info_t *rx_blocks;
505 int l;
506
507 rx_blocks = &mac_control->rings[i].rx_blocks[j];
508 size = SIZE_OF_BLOCK; //size is always page size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
510 &tmp_p_addr);
511 if (tmp_v_addr == NULL) {
512 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700513 * In case of failure, free_shared_mem()
514 * is called, which should free any
515 * memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 * failure happened.
517 */
Ananda Rajuda6971d2005-10-31 16:55:31 -0500518 rx_blocks->block_virt_addr = tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return -ENOMEM;
520 }
521 memset(tmp_v_addr, 0, size);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500522 rx_blocks->block_virt_addr = tmp_v_addr;
523 rx_blocks->block_dma_addr = tmp_p_addr;
524 rx_blocks->rxds = kmalloc(sizeof(rxd_info_t)*
525 rxd_count[nic->rxd_mode],
526 GFP_KERNEL);
527 for (l=0; l<rxd_count[nic->rxd_mode];l++) {
528 rx_blocks->rxds[l].virt_addr =
529 rx_blocks->block_virt_addr +
530 (rxd_size[nic->rxd_mode] * l);
531 rx_blocks->rxds[l].dma_addr =
532 rx_blocks->block_dma_addr +
533 (rxd_size[nic->rxd_mode] * l);
534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536 /* Interlinking all Rx Blocks */
537 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700538 tmp_v_addr =
539 mac_control->rings[i].rx_blocks[j].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 tmp_v_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700541 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 blk_cnt].block_virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700543 tmp_p_addr =
544 mac_control->rings[i].rx_blocks[j].block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 tmp_p_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700546 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 blk_cnt].block_dma_addr;
548
549 pre_rxd_blk = (RxD_block_t *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 pre_rxd_blk->reserved_2_pNext_RxD_block =
551 (unsigned long) tmp_v_addr_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 pre_rxd_blk->pNext_RxD_Blk_physical =
553 (u64) tmp_p_addr_next;
554 }
555 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500556 if (nic->rxd_mode >= RXD_MODE_3A) {
557 /*
558 * Allocation of Storages for buffer addresses in 2BUFF mode
559 * and the buffers as well.
560 */
561 for (i = 0; i < config->rx_ring_num; i++) {
562 blk_cnt = config->rx_cfg[i].num_rxd /
563 (rxd_count[nic->rxd_mode]+ 1);
564 mac_control->rings[i].ba =
565 kmalloc((sizeof(buffAdd_t *) * blk_cnt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 GFP_KERNEL);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500567 if (!mac_control->rings[i].ba)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return -ENOMEM;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500569 for (j = 0; j < blk_cnt; j++) {
570 int k = 0;
571 mac_control->rings[i].ba[j] =
572 kmalloc((sizeof(buffAdd_t) *
573 (rxd_count[nic->rxd_mode] + 1)),
574 GFP_KERNEL);
575 if (!mac_control->rings[i].ba[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 return -ENOMEM;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500577 while (k != rxd_count[nic->rxd_mode]) {
578 ba = &mac_control->rings[i].ba[j][k];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Ananda Rajuda6971d2005-10-31 16:55:31 -0500580 ba->ba_0_org = (void *) kmalloc
581 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
582 if (!ba->ba_0_org)
583 return -ENOMEM;
584 tmp = (unsigned long)ba->ba_0_org;
585 tmp += ALIGN_SIZE;
586 tmp &= ~((unsigned long) ALIGN_SIZE);
587 ba->ba_0 = (void *) tmp;
588
589 ba->ba_1_org = (void *) kmalloc
590 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
591 if (!ba->ba_1_org)
592 return -ENOMEM;
593 tmp = (unsigned long) ba->ba_1_org;
594 tmp += ALIGN_SIZE;
595 tmp &= ~((unsigned long) ALIGN_SIZE);
596 ba->ba_1 = (void *) tmp;
597 k++;
598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600 }
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 /* Allocation and initialization of Statistics block */
604 size = sizeof(StatInfo_t);
605 mac_control->stats_mem = pci_alloc_consistent
606 (nic->pdev, size, &mac_control->stats_mem_phy);
607
608 if (!mac_control->stats_mem) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700609 /*
610 * In case of failure, free_shared_mem() is called, which
611 * should free any memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 * failure happened.
613 */
614 return -ENOMEM;
615 }
616 mac_control->stats_mem_sz = size;
617
618 tmp_v_addr = mac_control->stats_mem;
619 mac_control->stats_info = (StatInfo_t *) tmp_v_addr;
620 memset(tmp_v_addr, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
622 (unsigned long long) tmp_p_addr);
623
624 return SUCCESS;
625}
626
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700627/**
628 * free_shared_mem - Free the allocated Memory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 * @nic: Device private variable.
630 * Description: This function is to free all memory locations allocated by
631 * the init_shared_mem() function and return it to the kernel.
632 */
633
634static void free_shared_mem(struct s2io_nic *nic)
635{
636 int i, j, blk_cnt, size;
637 void *tmp_v_addr;
638 dma_addr_t tmp_p_addr;
639 mac_info_t *mac_control;
640 struct config_param *config;
641 int lst_size, lst_per_page;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700642 struct net_device *dev = nic->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 if (!nic)
645 return;
646
647 mac_control = &nic->mac_control;
648 config = &nic->config;
649
650 lst_size = (sizeof(TxD_t) * config->max_txds);
651 lst_per_page = PAGE_SIZE / lst_size;
652
653 for (i = 0; i < config->tx_fifo_num; i++) {
654 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
655 lst_per_page);
656 for (j = 0; j < page_num; j++) {
657 int mem_blks = (j * lst_per_page);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700658 if (!mac_control->fifos[i].list_info)
659 return;
660 if (!mac_control->fifos[i].list_info[mem_blks].
661 list_virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 break;
663 pci_free_consistent(nic->pdev, PAGE_SIZE,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700664 mac_control->fifos[i].
665 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 list_virt_addr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700667 mac_control->fifos[i].
668 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 list_phy_addr);
670 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700671 /* If we got a zero DMA address during allocation,
672 * free the page now
673 */
674 if (mac_control->zerodma_virt_addr) {
675 pci_free_consistent(nic->pdev, PAGE_SIZE,
676 mac_control->zerodma_virt_addr,
677 (dma_addr_t)0);
678 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700679 "%s: Freeing TxDL with zero DMA addr. ",
680 dev->name);
681 DBG_PRINT(INIT_DBG, "Virtual address %p\n",
682 mac_control->zerodma_virt_addr);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700683 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700684 kfree(mac_control->fifos[i].list_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 size = SIZE_OF_BLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700689 blk_cnt = mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700691 tmp_v_addr = mac_control->rings[i].rx_blocks[j].
692 block_virt_addr;
693 tmp_p_addr = mac_control->rings[i].rx_blocks[j].
694 block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (tmp_v_addr == NULL)
696 break;
697 pci_free_consistent(nic->pdev, size,
698 tmp_v_addr, tmp_p_addr);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500699 kfree(mac_control->rings[i].rx_blocks[j].rxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 }
702
Ananda Rajuda6971d2005-10-31 16:55:31 -0500703 if (nic->rxd_mode >= RXD_MODE_3A) {
704 /* Freeing buffer storage addresses in 2BUFF mode. */
705 for (i = 0; i < config->rx_ring_num; i++) {
706 blk_cnt = config->rx_cfg[i].num_rxd /
707 (rxd_count[nic->rxd_mode] + 1);
708 for (j = 0; j < blk_cnt; j++) {
709 int k = 0;
710 if (!mac_control->rings[i].ba[j])
711 continue;
712 while (k != rxd_count[nic->rxd_mode]) {
713 buffAdd_t *ba =
714 &mac_control->rings[i].ba[j][k];
715 kfree(ba->ba_0_org);
716 kfree(ba->ba_1_org);
717 k++;
718 }
719 kfree(mac_control->rings[i].ba[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500721 kfree(mac_control->rings[i].ba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 if (mac_control->stats_mem) {
726 pci_free_consistent(nic->pdev,
727 mac_control->stats_mem_sz,
728 mac_control->stats_mem,
729 mac_control->stats_mem_phy);
730 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500731 if (nic->ufo_in_band_v)
732 kfree(nic->ufo_in_band_v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700735/**
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700736 * s2io_verify_pci_mode -
737 */
738
739static int s2io_verify_pci_mode(nic_t *nic)
740{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +0100741 XENA_dev_config_t __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700742 register u64 val64 = 0;
743 int mode;
744
745 val64 = readq(&bar0->pci_mode);
746 mode = (u8)GET_PCI_MODE(val64);
747
748 if ( val64 & PCI_MODE_UNKNOWN_MODE)
749 return -1; /* Unknown PCI mode */
750 return mode;
751}
752
Ananda Rajuc92ca042006-04-21 19:18:03 -0400753#define NEC_VENID 0x1033
754#define NEC_DEVID 0x0125
755static int s2io_on_nec_bridge(struct pci_dev *s2io_pdev)
756{
757 struct pci_dev *tdev = NULL;
758 while ((tdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, tdev)) != NULL) {
759 if ((tdev->vendor == NEC_VENID) && (tdev->device == NEC_DEVID)){
760 if (tdev->bus == s2io_pdev->bus->parent)
761 return 1;
762 }
763 }
764 return 0;
765}
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700766
Ananda Rajuc92ca042006-04-21 19:18:03 -0400767int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700768/**
769 * s2io_print_pci_mode -
770 */
771static int s2io_print_pci_mode(nic_t *nic)
772{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +0100773 XENA_dev_config_t __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700774 register u64 val64 = 0;
775 int mode;
776 struct config_param *config = &nic->config;
777
778 val64 = readq(&bar0->pci_mode);
779 mode = (u8)GET_PCI_MODE(val64);
780
781 if ( val64 & PCI_MODE_UNKNOWN_MODE)
782 return -1; /* Unknown PCI mode */
783
Ananda Rajuc92ca042006-04-21 19:18:03 -0400784 config->bus_speed = bus_speed[mode];
785
786 if (s2io_on_nec_bridge(nic->pdev)) {
787 DBG_PRINT(ERR_DBG, "%s: Device is on PCI-E bus\n",
788 nic->dev->name);
789 return mode;
790 }
791
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700792 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");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700801 break;
802 case PCI_MODE_PCI_66:
803 DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700804 break;
805 case PCI_MODE_PCIX_M1_66:
806 DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700807 break;
808 case PCI_MODE_PCIX_M1_100:
809 DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700810 break;
811 case PCI_MODE_PCIX_M1_133:
812 DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700813 break;
814 case PCI_MODE_PCIX_M2_66:
815 DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700816 break;
817 case PCI_MODE_PCIX_M2_100:
818 DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700819 break;
820 case PCI_MODE_PCIX_M2_133:
821 DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700822 break;
823 default:
824 return -1; /* Unsupported bus speed */
825 }
826
827 return mode;
828}
829
830/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700831 * init_nic - Initialization of hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 * @nic: device peivate variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700833 * Description: The function sequentially configures every block
834 * of the H/W from their reset values.
835 * Return Value: SUCCESS on success and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 * '-1' on failure (endian settings incorrect).
837 */
838
839static int init_nic(struct s2io_nic *nic)
840{
841 XENA_dev_config_t __iomem *bar0 = nic->bar0;
842 struct net_device *dev = nic->dev;
843 register u64 val64 = 0;
844 void __iomem *add;
845 u32 time;
846 int i, j;
847 mac_info_t *mac_control;
848 struct config_param *config;
Ananda Rajuc92ca042006-04-21 19:18:03 -0400849 int dtx_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 unsigned long long mem_share;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700851 int mem_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 mac_control = &nic->mac_control;
854 config = &nic->config;
855
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700856 /* to set the swapper controle on the card */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700857 if(s2io_set_swapper(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
859 return -1;
860 }
861
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700862 /*
863 * Herc requires EOI to be removed from reset before XGXS, so..
864 */
865 if (nic->device_type & XFRAME_II_DEVICE) {
866 val64 = 0xA500000000ULL;
867 writeq(val64, &bar0->sw_reset);
868 msleep(500);
869 val64 = readq(&bar0->sw_reset);
870 }
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /* Remove XGXS from reset state */
873 val64 = 0;
874 writeq(val64, &bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 msleep(500);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700876 val64 = readq(&bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 /* Enable Receiving broadcasts */
879 add = &bar0->mac_cfg;
880 val64 = readq(&bar0->mac_cfg);
881 val64 |= MAC_RMAC_BCAST_ENABLE;
882 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
883 writel((u32) val64, add);
884 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
885 writel((u32) (val64 >> 32), (add + 4));
886
887 /* Read registers in all blocks */
888 val64 = readq(&bar0->mac_int_mask);
889 val64 = readq(&bar0->mc_int_mask);
890 val64 = readq(&bar0->xgxs_int_mask);
891
892 /* Set MTU */
893 val64 = dev->mtu;
894 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
895
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700896 if (nic->device_type & XFRAME_II_DEVICE) {
897 while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -0700898 SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 &bar0->dtx_control, UF);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700900 if (dtx_cnt & 0x1)
901 msleep(1); /* Necessary!! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 dtx_cnt++;
903 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700904 } else {
Ananda Rajuc92ca042006-04-21 19:18:03 -0400905 while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
906 SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
907 &bar0->dtx_control, UF);
908 val64 = readq(&bar0->dtx_control);
909 dtx_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
911 }
912
913 /* Tx DMA Initialization */
914 val64 = 0;
915 writeq(val64, &bar0->tx_fifo_partition_0);
916 writeq(val64, &bar0->tx_fifo_partition_1);
917 writeq(val64, &bar0->tx_fifo_partition_2);
918 writeq(val64, &bar0->tx_fifo_partition_3);
919
920
921 for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
922 val64 |=
923 vBIT(config->tx_cfg[i].fifo_len - 1, ((i * 32) + 19),
924 13) | vBIT(config->tx_cfg[i].fifo_priority,
925 ((i * 32) + 5), 3);
926
927 if (i == (config->tx_fifo_num - 1)) {
928 if (i % 2 == 0)
929 i++;
930 }
931
932 switch (i) {
933 case 1:
934 writeq(val64, &bar0->tx_fifo_partition_0);
935 val64 = 0;
936 break;
937 case 3:
938 writeq(val64, &bar0->tx_fifo_partition_1);
939 val64 = 0;
940 break;
941 case 5:
942 writeq(val64, &bar0->tx_fifo_partition_2);
943 val64 = 0;
944 break;
945 case 7:
946 writeq(val64, &bar0->tx_fifo_partition_3);
947 break;
948 }
949 }
950
951 /* Enable Tx FIFO partition 0. */
952 val64 = readq(&bar0->tx_fifo_partition_0);
953 val64 |= BIT(0); /* To enable the FIFO partition. */
954 writeq(val64, &bar0->tx_fifo_partition_0);
955
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700956 /*
957 * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
958 * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
959 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700960 if ((nic->device_type == XFRAME_I_DEVICE) &&
961 (get_xena_rev_id(nic->pdev) < 4))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -0700962 writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 val64 = readq(&bar0->tx_fifo_partition_0);
965 DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
966 &bar0->tx_fifo_partition_0, (unsigned long long) val64);
967
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700968 /*
969 * Initialization of Tx_PA_CONFIG register to ignore packet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 * integrity checking.
971 */
972 val64 = readq(&bar0->tx_pa_cfg);
973 val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
974 TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
975 writeq(val64, &bar0->tx_pa_cfg);
976
977 /* Rx DMA intialization. */
978 val64 = 0;
979 for (i = 0; i < config->rx_ring_num; i++) {
980 val64 |=
981 vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
982 3);
983 }
984 writeq(val64, &bar0->rx_queue_priority);
985
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700986 /*
987 * Allocating equal share of memory to all the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 * configured Rings.
989 */
990 val64 = 0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700991 if (nic->device_type & XFRAME_II_DEVICE)
992 mem_size = 32;
993 else
994 mem_size = 64;
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 for (i = 0; i < config->rx_ring_num; i++) {
997 switch (i) {
998 case 0:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700999 mem_share = (mem_size / config->rx_ring_num +
1000 mem_size % config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
1002 continue;
1003 case 1:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001004 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
1006 continue;
1007 case 2:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001008 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
1010 continue;
1011 case 3:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001012 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
1014 continue;
1015 case 4:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001016 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
1018 continue;
1019 case 5:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001020 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
1022 continue;
1023 case 6:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001024 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
1026 continue;
1027 case 7:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001028 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
1030 continue;
1031 }
1032 }
1033 writeq(val64, &bar0->rx_queue_cfg);
1034
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001035 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001036 * Filling Tx round robin registers
1037 * as per the number of FIFOs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001039 switch (config->tx_fifo_num) {
1040 case 1:
1041 val64 = 0x0000000000000000ULL;
1042 writeq(val64, &bar0->tx_w_round_robin_0);
1043 writeq(val64, &bar0->tx_w_round_robin_1);
1044 writeq(val64, &bar0->tx_w_round_robin_2);
1045 writeq(val64, &bar0->tx_w_round_robin_3);
1046 writeq(val64, &bar0->tx_w_round_robin_4);
1047 break;
1048 case 2:
1049 val64 = 0x0000010000010000ULL;
1050 writeq(val64, &bar0->tx_w_round_robin_0);
1051 val64 = 0x0100000100000100ULL;
1052 writeq(val64, &bar0->tx_w_round_robin_1);
1053 val64 = 0x0001000001000001ULL;
1054 writeq(val64, &bar0->tx_w_round_robin_2);
1055 val64 = 0x0000010000010000ULL;
1056 writeq(val64, &bar0->tx_w_round_robin_3);
1057 val64 = 0x0100000000000000ULL;
1058 writeq(val64, &bar0->tx_w_round_robin_4);
1059 break;
1060 case 3:
1061 val64 = 0x0001000102000001ULL;
1062 writeq(val64, &bar0->tx_w_round_robin_0);
1063 val64 = 0x0001020000010001ULL;
1064 writeq(val64, &bar0->tx_w_round_robin_1);
1065 val64 = 0x0200000100010200ULL;
1066 writeq(val64, &bar0->tx_w_round_robin_2);
1067 val64 = 0x0001000102000001ULL;
1068 writeq(val64, &bar0->tx_w_round_robin_3);
1069 val64 = 0x0001020000000000ULL;
1070 writeq(val64, &bar0->tx_w_round_robin_4);
1071 break;
1072 case 4:
1073 val64 = 0x0001020300010200ULL;
1074 writeq(val64, &bar0->tx_w_round_robin_0);
1075 val64 = 0x0100000102030001ULL;
1076 writeq(val64, &bar0->tx_w_round_robin_1);
1077 val64 = 0x0200010000010203ULL;
1078 writeq(val64, &bar0->tx_w_round_robin_2);
1079 val64 = 0x0001020001000001ULL;
1080 writeq(val64, &bar0->tx_w_round_robin_3);
1081 val64 = 0x0203000100000000ULL;
1082 writeq(val64, &bar0->tx_w_round_robin_4);
1083 break;
1084 case 5:
1085 val64 = 0x0001000203000102ULL;
1086 writeq(val64, &bar0->tx_w_round_robin_0);
1087 val64 = 0x0001020001030004ULL;
1088 writeq(val64, &bar0->tx_w_round_robin_1);
1089 val64 = 0x0001000203000102ULL;
1090 writeq(val64, &bar0->tx_w_round_robin_2);
1091 val64 = 0x0001020001030004ULL;
1092 writeq(val64, &bar0->tx_w_round_robin_3);
1093 val64 = 0x0001000000000000ULL;
1094 writeq(val64, &bar0->tx_w_round_robin_4);
1095 break;
1096 case 6:
1097 val64 = 0x0001020304000102ULL;
1098 writeq(val64, &bar0->tx_w_round_robin_0);
1099 val64 = 0x0304050001020001ULL;
1100 writeq(val64, &bar0->tx_w_round_robin_1);
1101 val64 = 0x0203000100000102ULL;
1102 writeq(val64, &bar0->tx_w_round_robin_2);
1103 val64 = 0x0304000102030405ULL;
1104 writeq(val64, &bar0->tx_w_round_robin_3);
1105 val64 = 0x0001000200000000ULL;
1106 writeq(val64, &bar0->tx_w_round_robin_4);
1107 break;
1108 case 7:
1109 val64 = 0x0001020001020300ULL;
1110 writeq(val64, &bar0->tx_w_round_robin_0);
1111 val64 = 0x0102030400010203ULL;
1112 writeq(val64, &bar0->tx_w_round_robin_1);
1113 val64 = 0x0405060001020001ULL;
1114 writeq(val64, &bar0->tx_w_round_robin_2);
1115 val64 = 0x0304050000010200ULL;
1116 writeq(val64, &bar0->tx_w_round_robin_3);
1117 val64 = 0x0102030000000000ULL;
1118 writeq(val64, &bar0->tx_w_round_robin_4);
1119 break;
1120 case 8:
1121 val64 = 0x0001020300040105ULL;
1122 writeq(val64, &bar0->tx_w_round_robin_0);
1123 val64 = 0x0200030106000204ULL;
1124 writeq(val64, &bar0->tx_w_round_robin_1);
1125 val64 = 0x0103000502010007ULL;
1126 writeq(val64, &bar0->tx_w_round_robin_2);
1127 val64 = 0x0304010002060500ULL;
1128 writeq(val64, &bar0->tx_w_round_robin_3);
1129 val64 = 0x0103020400000000ULL;
1130 writeq(val64, &bar0->tx_w_round_robin_4);
1131 break;
1132 }
1133
1134 /* Filling the Rx round robin registers as per the
1135 * number of Rings and steering based on QoS.
1136 */
1137 switch (config->rx_ring_num) {
1138 case 1:
1139 val64 = 0x8080808080808080ULL;
1140 writeq(val64, &bar0->rts_qos_steering);
1141 break;
1142 case 2:
1143 val64 = 0x0000010000010000ULL;
1144 writeq(val64, &bar0->rx_w_round_robin_0);
1145 val64 = 0x0100000100000100ULL;
1146 writeq(val64, &bar0->rx_w_round_robin_1);
1147 val64 = 0x0001000001000001ULL;
1148 writeq(val64, &bar0->rx_w_round_robin_2);
1149 val64 = 0x0000010000010000ULL;
1150 writeq(val64, &bar0->rx_w_round_robin_3);
1151 val64 = 0x0100000000000000ULL;
1152 writeq(val64, &bar0->rx_w_round_robin_4);
1153
1154 val64 = 0x8080808040404040ULL;
1155 writeq(val64, &bar0->rts_qos_steering);
1156 break;
1157 case 3:
1158 val64 = 0x0001000102000001ULL;
1159 writeq(val64, &bar0->rx_w_round_robin_0);
1160 val64 = 0x0001020000010001ULL;
1161 writeq(val64, &bar0->rx_w_round_robin_1);
1162 val64 = 0x0200000100010200ULL;
1163 writeq(val64, &bar0->rx_w_round_robin_2);
1164 val64 = 0x0001000102000001ULL;
1165 writeq(val64, &bar0->rx_w_round_robin_3);
1166 val64 = 0x0001020000000000ULL;
1167 writeq(val64, &bar0->rx_w_round_robin_4);
1168
1169 val64 = 0x8080804040402020ULL;
1170 writeq(val64, &bar0->rts_qos_steering);
1171 break;
1172 case 4:
1173 val64 = 0x0001020300010200ULL;
1174 writeq(val64, &bar0->rx_w_round_robin_0);
1175 val64 = 0x0100000102030001ULL;
1176 writeq(val64, &bar0->rx_w_round_robin_1);
1177 val64 = 0x0200010000010203ULL;
1178 writeq(val64, &bar0->rx_w_round_robin_2);
1179 val64 = 0x0001020001000001ULL;
1180 writeq(val64, &bar0->rx_w_round_robin_3);
1181 val64 = 0x0203000100000000ULL;
1182 writeq(val64, &bar0->rx_w_round_robin_4);
1183
1184 val64 = 0x8080404020201010ULL;
1185 writeq(val64, &bar0->rts_qos_steering);
1186 break;
1187 case 5:
1188 val64 = 0x0001000203000102ULL;
1189 writeq(val64, &bar0->rx_w_round_robin_0);
1190 val64 = 0x0001020001030004ULL;
1191 writeq(val64, &bar0->rx_w_round_robin_1);
1192 val64 = 0x0001000203000102ULL;
1193 writeq(val64, &bar0->rx_w_round_robin_2);
1194 val64 = 0x0001020001030004ULL;
1195 writeq(val64, &bar0->rx_w_round_robin_3);
1196 val64 = 0x0001000000000000ULL;
1197 writeq(val64, &bar0->rx_w_round_robin_4);
1198
1199 val64 = 0x8080404020201008ULL;
1200 writeq(val64, &bar0->rts_qos_steering);
1201 break;
1202 case 6:
1203 val64 = 0x0001020304000102ULL;
1204 writeq(val64, &bar0->rx_w_round_robin_0);
1205 val64 = 0x0304050001020001ULL;
1206 writeq(val64, &bar0->rx_w_round_robin_1);
1207 val64 = 0x0203000100000102ULL;
1208 writeq(val64, &bar0->rx_w_round_robin_2);
1209 val64 = 0x0304000102030405ULL;
1210 writeq(val64, &bar0->rx_w_round_robin_3);
1211 val64 = 0x0001000200000000ULL;
1212 writeq(val64, &bar0->rx_w_round_robin_4);
1213
1214 val64 = 0x8080404020100804ULL;
1215 writeq(val64, &bar0->rts_qos_steering);
1216 break;
1217 case 7:
1218 val64 = 0x0001020001020300ULL;
1219 writeq(val64, &bar0->rx_w_round_robin_0);
1220 val64 = 0x0102030400010203ULL;
1221 writeq(val64, &bar0->rx_w_round_robin_1);
1222 val64 = 0x0405060001020001ULL;
1223 writeq(val64, &bar0->rx_w_round_robin_2);
1224 val64 = 0x0304050000010200ULL;
1225 writeq(val64, &bar0->rx_w_round_robin_3);
1226 val64 = 0x0102030000000000ULL;
1227 writeq(val64, &bar0->rx_w_round_robin_4);
1228
1229 val64 = 0x8080402010080402ULL;
1230 writeq(val64, &bar0->rts_qos_steering);
1231 break;
1232 case 8:
1233 val64 = 0x0001020300040105ULL;
1234 writeq(val64, &bar0->rx_w_round_robin_0);
1235 val64 = 0x0200030106000204ULL;
1236 writeq(val64, &bar0->rx_w_round_robin_1);
1237 val64 = 0x0103000502010007ULL;
1238 writeq(val64, &bar0->rx_w_round_robin_2);
1239 val64 = 0x0304010002060500ULL;
1240 writeq(val64, &bar0->rx_w_round_robin_3);
1241 val64 = 0x0103020400000000ULL;
1242 writeq(val64, &bar0->rx_w_round_robin_4);
1243
1244 val64 = 0x8040201008040201ULL;
1245 writeq(val64, &bar0->rts_qos_steering);
1246 break;
1247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 /* UDP Fix */
1250 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001251 for (i = 0; i < 8; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 writeq(val64, &bar0->rts_frm_len_n[i]);
1253
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001254 /* Set the default rts frame length for the rings configured */
1255 val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
1256 for (i = 0 ; i < config->rx_ring_num ; i++)
1257 writeq(val64, &bar0->rts_frm_len_n[i]);
1258
1259 /* Set the frame length for the configured rings
1260 * desired by the user
1261 */
1262 for (i = 0; i < config->rx_ring_num; i++) {
1263 /* If rts_frm_len[i] == 0 then it is assumed that user not
1264 * specified frame length steering.
1265 * If the user provides the frame length then program
1266 * the rts_frm_len register for those values or else
1267 * leave it as it is.
1268 */
1269 if (rts_frm_len[i] != 0) {
1270 writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
1271 &bar0->rts_frm_len_n[i]);
1272 }
1273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001275 /* Program statistics memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001278 if (nic->device_type == XFRAME_II_DEVICE) {
1279 val64 = STAT_BC(0x320);
1280 writeq(val64, &bar0->stat_byte_cnt);
1281 }
1282
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001283 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 * Initializing the sampling rate for the device to calculate the
1285 * bandwidth utilization.
1286 */
1287 val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
1288 MAC_RX_LINK_UTIL_VAL(rmac_util_period);
1289 writeq(val64, &bar0->mac_link_util);
1290
1291
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001292 /*
1293 * Initializing the Transmit and Receive Traffic Interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 * Scheme.
1295 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001296 /*
1297 * TTI Initialization. Default Tx timer gets us about
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 * 250 interrupts per sec. Continuous interrupts are enabled
1299 * by default.
1300 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001301 if (nic->device_type == XFRAME_II_DEVICE) {
1302 int count = (nic->config.bus_speed * 125)/2;
1303 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
1304 } else {
1305
1306 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
1307 }
1308 val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 TTI_DATA1_MEM_TX_URNG_B(0x10) |
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001310 TTI_DATA1_MEM_TX_URNG_C(0x30) | TTI_DATA1_MEM_TX_TIMER_AC_EN;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001311 if (use_continuous_tx_intrs)
1312 val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 writeq(val64, &bar0->tti_data1_mem);
1314
1315 val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
1316 TTI_DATA2_MEM_TX_UFC_B(0x20) |
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001317 TTI_DATA2_MEM_TX_UFC_C(0x70) | TTI_DATA2_MEM_TX_UFC_D(0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 writeq(val64, &bar0->tti_data2_mem);
1319
1320 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1321 writeq(val64, &bar0->tti_command_mem);
1322
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001323 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 * Once the operation completes, the Strobe bit of the command
1325 * register will be reset. We poll for this particular condition
1326 * We wait for a maximum of 500ms for the operation to complete,
1327 * if it's not complete by then we return error.
1328 */
1329 time = 0;
1330 while (TRUE) {
1331 val64 = readq(&bar0->tti_command_mem);
1332 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1333 break;
1334 }
1335 if (time > 10) {
1336 DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
1337 dev->name);
1338 return -1;
1339 }
1340 msleep(50);
1341 time++;
1342 }
1343
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001344 if (nic->config.bimodal) {
1345 int k = 0;
1346 for (k = 0; k < config->rx_ring_num; k++) {
1347 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1348 val64 |= TTI_CMD_MEM_OFFSET(0x38+k);
1349 writeq(val64, &bar0->tti_command_mem);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001350
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001351 /*
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001352 * Once the operation completes, the Strobe bit of the command
1353 * register will be reset. We poll for this particular condition
1354 * We wait for a maximum of 500ms for the operation to complete,
1355 * if it's not complete by then we return error.
1356 */
1357 time = 0;
1358 while (TRUE) {
1359 val64 = readq(&bar0->tti_command_mem);
1360 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1361 break;
1362 }
1363 if (time > 10) {
1364 DBG_PRINT(ERR_DBG,
1365 "%s: TTI init Failed\n",
1366 dev->name);
1367 return -1;
1368 }
1369 time++;
1370 msleep(50);
1371 }
1372 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001373 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001375 /* RTI Initialization */
1376 if (nic->device_type == XFRAME_II_DEVICE) {
1377 /*
1378 * Programmed to generate Apprx 500 Intrs per
1379 * second
1380 */
1381 int count = (nic->config.bus_speed * 125)/4;
1382 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
1383 } else {
1384 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 }
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001386 val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
1387 RTI_DATA1_MEM_RX_URNG_B(0x10) |
1388 RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
1389
1390 writeq(val64, &bar0->rti_data1_mem);
1391
1392 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001393 RTI_DATA2_MEM_RX_UFC_B(0x2) ;
1394 if (nic->intr_type == MSI_X)
1395 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
1396 RTI_DATA2_MEM_RX_UFC_D(0x40));
1397 else
1398 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
1399 RTI_DATA2_MEM_RX_UFC_D(0x80));
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001400 writeq(val64, &bar0->rti_data2_mem);
1401
1402 for (i = 0; i < config->rx_ring_num; i++) {
1403 val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
1404 | RTI_CMD_MEM_OFFSET(i);
1405 writeq(val64, &bar0->rti_command_mem);
1406
1407 /*
1408 * Once the operation completes, the Strobe bit of the
1409 * command register will be reset. We poll for this
1410 * particular condition. We wait for a maximum of 500ms
1411 * for the operation to complete, if it's not complete
1412 * by then we return error.
1413 */
1414 time = 0;
1415 while (TRUE) {
1416 val64 = readq(&bar0->rti_command_mem);
1417 if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD)) {
1418 break;
1419 }
1420 if (time > 10) {
1421 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
1422 dev->name);
1423 return -1;
1424 }
1425 time++;
1426 msleep(50);
1427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001431 /*
1432 * Initializing proper values as Pause threshold into all
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 * the 8 Queues on Rx side.
1434 */
1435 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
1436 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
1437
1438 /* Disable RMAC PAD STRIPPING */
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01001439 add = &bar0->mac_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 val64 = readq(&bar0->mac_cfg);
1441 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
1442 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1443 writel((u32) (val64), add);
1444 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1445 writel((u32) (val64 >> 32), (add + 4));
1446 val64 = readq(&bar0->mac_cfg);
1447
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05001448 /* Enable FCS stripping by adapter */
1449 add = &bar0->mac_cfg;
1450 val64 = readq(&bar0->mac_cfg);
1451 val64 |= MAC_CFG_RMAC_STRIP_FCS;
1452 if (nic->device_type == XFRAME_II_DEVICE)
1453 writeq(val64, &bar0->mac_cfg);
1454 else {
1455 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1456 writel((u32) (val64), add);
1457 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1458 writel((u32) (val64 >> 32), (add + 4));
1459 }
1460
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001461 /*
1462 * Set the time value to be inserted in the pause frame
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 * generated by xena.
1464 */
1465 val64 = readq(&bar0->rmac_pause_cfg);
1466 val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
1467 val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
1468 writeq(val64, &bar0->rmac_pause_cfg);
1469
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001470 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 * Set the Threshold Limit for Generating the pause frame
1472 * If the amount of data in any Queue exceeds ratio of
1473 * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
1474 * pause frame is generated
1475 */
1476 val64 = 0;
1477 for (i = 0; i < 4; i++) {
1478 val64 |=
1479 (((u64) 0xFF00 | nic->mac_control.
1480 mc_pause_threshold_q0q3)
1481 << (i * 2 * 8));
1482 }
1483 writeq(val64, &bar0->mc_pause_thresh_q0q3);
1484
1485 val64 = 0;
1486 for (i = 0; i < 4; i++) {
1487 val64 |=
1488 (((u64) 0xFF00 | nic->mac_control.
1489 mc_pause_threshold_q4q7)
1490 << (i * 2 * 8));
1491 }
1492 writeq(val64, &bar0->mc_pause_thresh_q4q7);
1493
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001494 /*
1495 * TxDMA will stop Read request if the number of read split has
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 * exceeded the limit pointed by shared_splits
1497 */
1498 val64 = readq(&bar0->pic_control);
1499 val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
1500 writeq(val64, &bar0->pic_control);
1501
Ananda Raju863c11a2006-04-21 19:03:13 -04001502 if (nic->config.bus_speed == 266) {
1503 writeq(TXREQTO_VAL(0x7f) | TXREQTO_EN, &bar0->txreqtimeout);
1504 writeq(0x0, &bar0->read_retry_delay);
1505 writeq(0x0, &bar0->write_retry_delay);
1506 }
1507
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001508 /*
1509 * Programming the Herc to split every write transaction
1510 * that does not start on an ADB to reduce disconnects.
1511 */
1512 if (nic->device_type == XFRAME_II_DEVICE) {
Ananda Raju863c11a2006-04-21 19:03:13 -04001513 val64 = EXT_REQ_EN | MISC_LINK_STABILITY_PRD(3);
1514 writeq(val64, &bar0->misc_control);
1515 val64 = readq(&bar0->pic_control2);
1516 val64 &= ~(BIT(13)|BIT(14)|BIT(15));
1517 writeq(val64, &bar0->pic_control2);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001518 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04001519 if (strstr(nic->product_name, "CX4")) {
1520 val64 = TMAC_AVG_IPG(0x17);
1521 writeq(val64, &bar0->tmac_avg_ipg);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001522 }
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 return SUCCESS;
1525}
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001526#define LINK_UP_DOWN_INTERRUPT 1
1527#define MAC_RMAC_ERR_TIMER 2
1528
Adrian Bunkac1f60d2005-11-06 01:46:47 +01001529static int s2io_link_fault_indication(nic_t *nic)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001530{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001531 if (nic->intr_type != INTA)
1532 return MAC_RMAC_ERR_TIMER;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001533 if (nic->device_type == XFRAME_II_DEVICE)
1534 return LINK_UP_DOWN_INTERRUPT;
1535 else
1536 return MAC_RMAC_ERR_TIMER;
1537}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001539/**
1540 * en_dis_able_nic_intrs - Enable or Disable the interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 * @nic: device private variable,
1542 * @mask: A mask indicating which Intr block must be modified and,
1543 * @flag: A flag indicating whether to enable or disable the Intrs.
1544 * Description: This function will either disable or enable the interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001545 * depending on the flag argument. The mask argument can be used to
1546 * enable/disable any Intr block.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 * Return Value: NONE.
1548 */
1549
1550static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
1551{
1552 XENA_dev_config_t __iomem *bar0 = nic->bar0;
1553 register u64 val64 = 0, temp64 = 0;
1554
1555 /* Top level interrupt classification */
1556 /* PIC Interrupts */
1557 if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
1558 /* Enable PIC Intrs in the general intr mask register */
1559 val64 = TXPIC_INT_M | PIC_RX_INT_M;
1560 if (flag == ENABLE_INTRS) {
1561 temp64 = readq(&bar0->general_int_mask);
1562 temp64 &= ~((u64) val64);
1563 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001564 /*
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001565 * If Hercules adapter enable GPIO otherwise
1566 * disabled all PCIX, Flash, MDIO, IIC and GPIO
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001567 * interrupts for now.
1568 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001570 if (s2io_link_fault_indication(nic) ==
1571 LINK_UP_DOWN_INTERRUPT ) {
1572 temp64 = readq(&bar0->pic_int_mask);
1573 temp64 &= ~((u64) PIC_INT_GPIO);
1574 writeq(temp64, &bar0->pic_int_mask);
1575 temp64 = readq(&bar0->gpio_int_mask);
1576 temp64 &= ~((u64) GPIO_INT_MASK_LINK_UP);
1577 writeq(temp64, &bar0->gpio_int_mask);
1578 } else {
1579 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1580 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001581 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 * No MSI Support is available presently, so TTI and
1583 * RTI interrupts are also disabled.
1584 */
1585 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001586 /*
1587 * Disable PIC Intrs in the general
1588 * intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 */
1590 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1591 temp64 = readq(&bar0->general_int_mask);
1592 val64 |= temp64;
1593 writeq(val64, &bar0->general_int_mask);
1594 }
1595 }
1596
1597 /* DMA Interrupts */
1598 /* Enabling/Disabling Tx DMA interrupts */
1599 if (mask & TX_DMA_INTR) {
1600 /* Enable TxDMA Intrs in the general intr mask register */
1601 val64 = TXDMA_INT_M;
1602 if (flag == ENABLE_INTRS) {
1603 temp64 = readq(&bar0->general_int_mask);
1604 temp64 &= ~((u64) val64);
1605 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001606 /*
1607 * Keep all interrupts other than PFC interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 * and PCC interrupt disabled in DMA level.
1609 */
1610 val64 = DISABLE_ALL_INTRS & ~(TXDMA_PFC_INT_M |
1611 TXDMA_PCC_INT_M);
1612 writeq(val64, &bar0->txdma_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001613 /*
1614 * Enable only the MISC error 1 interrupt in PFC block
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 */
1616 val64 = DISABLE_ALL_INTRS & (~PFC_MISC_ERR_1);
1617 writeq(val64, &bar0->pfc_err_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001618 /*
1619 * Enable only the FB_ECC error interrupt in PCC block
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 */
1621 val64 = DISABLE_ALL_INTRS & (~PCC_FB_ECC_ERR);
1622 writeq(val64, &bar0->pcc_err_mask);
1623 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001624 /*
1625 * Disable TxDMA Intrs in the general intr mask
1626 * register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 */
1628 writeq(DISABLE_ALL_INTRS, &bar0->txdma_int_mask);
1629 writeq(DISABLE_ALL_INTRS, &bar0->pfc_err_mask);
1630 temp64 = readq(&bar0->general_int_mask);
1631 val64 |= temp64;
1632 writeq(val64, &bar0->general_int_mask);
1633 }
1634 }
1635
1636 /* Enabling/Disabling Rx DMA interrupts */
1637 if (mask & RX_DMA_INTR) {
1638 /* Enable RxDMA Intrs in the general intr mask register */
1639 val64 = RXDMA_INT_M;
1640 if (flag == ENABLE_INTRS) {
1641 temp64 = readq(&bar0->general_int_mask);
1642 temp64 &= ~((u64) val64);
1643 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001644 /*
1645 * All RxDMA block interrupts are disabled for now
1646 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 */
1648 writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
1649 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001650 /*
1651 * Disable RxDMA Intrs in the general intr mask
1652 * register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 */
1654 writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
1655 temp64 = readq(&bar0->general_int_mask);
1656 val64 |= temp64;
1657 writeq(val64, &bar0->general_int_mask);
1658 }
1659 }
1660
1661 /* MAC Interrupts */
1662 /* Enabling/Disabling MAC interrupts */
1663 if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
1664 val64 = TXMAC_INT_M | RXMAC_INT_M;
1665 if (flag == ENABLE_INTRS) {
1666 temp64 = readq(&bar0->general_int_mask);
1667 temp64 &= ~((u64) val64);
1668 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001669 /*
1670 * All MAC block error interrupts are disabled for now
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 * TODO
1672 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001674 /*
1675 * Disable MAC Intrs in the general intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 */
1677 writeq(DISABLE_ALL_INTRS, &bar0->mac_int_mask);
1678 writeq(DISABLE_ALL_INTRS,
1679 &bar0->mac_rmac_err_mask);
1680
1681 temp64 = readq(&bar0->general_int_mask);
1682 val64 |= temp64;
1683 writeq(val64, &bar0->general_int_mask);
1684 }
1685 }
1686
1687 /* XGXS Interrupts */
1688 if (mask & (TX_XGXS_INTR | RX_XGXS_INTR)) {
1689 val64 = TXXGXS_INT_M | RXXGXS_INT_M;
1690 if (flag == ENABLE_INTRS) {
1691 temp64 = readq(&bar0->general_int_mask);
1692 temp64 &= ~((u64) val64);
1693 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001694 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 * All XGXS block error interrupts are disabled for now
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001696 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 */
1698 writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
1699 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001700 /*
1701 * Disable MC Intrs in the general intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 */
1703 writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
1704 temp64 = readq(&bar0->general_int_mask);
1705 val64 |= temp64;
1706 writeq(val64, &bar0->general_int_mask);
1707 }
1708 }
1709
1710 /* Memory Controller(MC) interrupts */
1711 if (mask & MC_INTR) {
1712 val64 = MC_INT_M;
1713 if (flag == ENABLE_INTRS) {
1714 temp64 = readq(&bar0->general_int_mask);
1715 temp64 &= ~((u64) val64);
1716 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001717 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001718 * Enable all MC Intrs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001720 writeq(0x0, &bar0->mc_int_mask);
1721 writeq(0x0, &bar0->mc_err_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 } else if (flag == DISABLE_INTRS) {
1723 /*
1724 * Disable MC Intrs in the general intr mask register
1725 */
1726 writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
1727 temp64 = readq(&bar0->general_int_mask);
1728 val64 |= temp64;
1729 writeq(val64, &bar0->general_int_mask);
1730 }
1731 }
1732
1733
1734 /* Tx traffic interrupts */
1735 if (mask & TX_TRAFFIC_INTR) {
1736 val64 = TXTRAFFIC_INT_M;
1737 if (flag == ENABLE_INTRS) {
1738 temp64 = readq(&bar0->general_int_mask);
1739 temp64 &= ~((u64) val64);
1740 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001741 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 * Enable all the Tx side interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001743 * writing 0 Enables all 64 TX interrupt levels
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 */
1745 writeq(0x0, &bar0->tx_traffic_mask);
1746 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001747 /*
1748 * Disable Tx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 * register.
1750 */
1751 writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
1752 temp64 = readq(&bar0->general_int_mask);
1753 val64 |= temp64;
1754 writeq(val64, &bar0->general_int_mask);
1755 }
1756 }
1757
1758 /* Rx traffic interrupts */
1759 if (mask & RX_TRAFFIC_INTR) {
1760 val64 = RXTRAFFIC_INT_M;
1761 if (flag == ENABLE_INTRS) {
1762 temp64 = readq(&bar0->general_int_mask);
1763 temp64 &= ~((u64) val64);
1764 writeq(temp64, &bar0->general_int_mask);
1765 /* writing 0 Enables all 8 RX interrupt levels */
1766 writeq(0x0, &bar0->rx_traffic_mask);
1767 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001768 /*
1769 * Disable Rx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 * register.
1771 */
1772 writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
1773 temp64 = readq(&bar0->general_int_mask);
1774 val64 |= temp64;
1775 writeq(val64, &bar0->general_int_mask);
1776 }
1777 }
1778}
1779
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001780static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001781{
1782 int ret = 0;
1783
1784 if (flag == FALSE) {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001785 if ((!herc && (rev_id >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001786 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) &&
1787 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1788 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
1789 ret = 1;
1790 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001791 }else {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001792 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
1793 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1794 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
1795 ret = 1;
1796 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001797 }
1798 } else {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001799 if ((!herc && (rev_id >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001800 if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
1801 ADAPTER_STATUS_RMAC_PCC_IDLE) &&
1802 (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
1803 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1804 ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
1805 ret = 1;
1806 }
1807 } else {
1808 if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
1809 ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
1810 (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
1811 ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1812 ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
1813 ret = 1;
1814 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001815 }
1816 }
1817
1818 return ret;
1819}
1820/**
1821 * verify_xena_quiescence - Checks whether the H/W is ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 * @val64 : Value read from adapter status register.
1823 * @flag : indicates if the adapter enable bit was ever written once
1824 * before.
1825 * Description: Returns whether the H/W is ready to go or not. Depending
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001826 * on whether adapter enable bit was written or not the comparison
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 * differs and the calling function passes the input argument flag to
1828 * indicate this.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001829 * Return: 1 If xena is quiescence
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 * 0 If Xena is not quiescence
1831 */
1832
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001833static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001835 int ret = 0, herc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 u64 tmp64 = ~((u64) val64);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001837 int rev_id = get_xena_rev_id(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001839 herc = (sp->device_type == XFRAME_II_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (!
1841 (tmp64 &
1842 (ADAPTER_STATUS_TDMA_READY | ADAPTER_STATUS_RDMA_READY |
1843 ADAPTER_STATUS_PFC_READY | ADAPTER_STATUS_TMAC_BUF_EMPTY |
1844 ADAPTER_STATUS_PIC_QUIESCENT | ADAPTER_STATUS_MC_DRAM_READY |
1845 ADAPTER_STATUS_MC_QUEUES_READY | ADAPTER_STATUS_M_PLL_LOCK |
1846 ADAPTER_STATUS_P_PLL_LOCK))) {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001847 ret = check_prc_pcc_state(val64, flag, rev_id, herc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 }
1849
1850 return ret;
1851}
1852
1853/**
1854 * fix_mac_address - Fix for Mac addr problem on Alpha platforms
1855 * @sp: Pointer to device specifc structure
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001856 * Description :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 * New procedure to clear mac address reading problems on Alpha platforms
1858 *
1859 */
1860
Adrian Bunkac1f60d2005-11-06 01:46:47 +01001861static void fix_mac_address(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
1863 XENA_dev_config_t __iomem *bar0 = sp->bar0;
1864 u64 val64;
1865 int i = 0;
1866
1867 while (fix_mac[i] != END_SIGN) {
1868 writeq(fix_mac[i++], &bar0->gpio_control);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001869 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 val64 = readq(&bar0->gpio_control);
1871 }
1872}
1873
1874/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001875 * start_nic - Turns the device on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001877 * Description:
1878 * This function actually turns the device on. Before this function is
1879 * called,all Registers are configured from their reset states
1880 * and shared memory is allocated but the NIC is still quiescent. On
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 * calling this function, the device interrupts are cleared and the NIC is
1882 * literally switched on by writing into the adapter control register.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001883 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 * SUCCESS on success and -1 on failure.
1885 */
1886
1887static int start_nic(struct s2io_nic *nic)
1888{
1889 XENA_dev_config_t __iomem *bar0 = nic->bar0;
1890 struct net_device *dev = nic->dev;
1891 register u64 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001892 u16 interruptible;
1893 u16 subid, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 mac_info_t *mac_control;
1895 struct config_param *config;
1896
1897 mac_control = &nic->mac_control;
1898 config = &nic->config;
1899
1900 /* PRC Initialization and configuration */
1901 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001902 writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 &bar0->prc_rxd0_n[i]);
1904
1905 val64 = readq(&bar0->prc_ctrl_n[i]);
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001906 if (nic->config.bimodal)
1907 val64 |= PRC_CTRL_BIMODAL_INTERRUPT;
Ananda Rajuda6971d2005-10-31 16:55:31 -05001908 if (nic->rxd_mode == RXD_MODE_1)
1909 val64 |= PRC_CTRL_RC_ENABLED;
1910 else
1911 val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
Ananda Raju863c11a2006-04-21 19:03:13 -04001912 if (nic->device_type == XFRAME_II_DEVICE)
1913 val64 |= PRC_CTRL_GROUP_READS;
1914 val64 &= ~PRC_CTRL_RXD_BACKOFF_INTERVAL(0xFFFFFF);
1915 val64 |= PRC_CTRL_RXD_BACKOFF_INTERVAL(0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 writeq(val64, &bar0->prc_ctrl_n[i]);
1917 }
1918
Ananda Rajuda6971d2005-10-31 16:55:31 -05001919 if (nic->rxd_mode == RXD_MODE_3B) {
1920 /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
1921 val64 = readq(&bar0->rx_pa_cfg);
1922 val64 |= RX_PA_CFG_IGNORE_L2_ERR;
1923 writeq(val64, &bar0->rx_pa_cfg);
1924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001926 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 * Enabling MC-RLDRAM. After enabling the device, we timeout
1928 * for around 100ms, which is approximately the time required
1929 * for the device to be ready for operation.
1930 */
1931 val64 = readq(&bar0->mc_rldram_mrs);
1932 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
1933 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
1934 val64 = readq(&bar0->mc_rldram_mrs);
1935
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001936 msleep(100); /* Delay by around 100 ms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
1938 /* Enabling ECC Protection. */
1939 val64 = readq(&bar0->adapter_control);
1940 val64 &= ~ADAPTER_ECC_EN;
1941 writeq(val64, &bar0->adapter_control);
1942
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001943 /*
1944 * Clearing any possible Link state change interrupts that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 * could have popped up just before Enabling the card.
1946 */
1947 val64 = readq(&bar0->mac_rmac_err_reg);
1948 if (val64)
1949 writeq(val64, &bar0->mac_rmac_err_reg);
1950
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001951 /*
1952 * Verify if the device is ready to be enabled, if so enable
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 * it.
1954 */
1955 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001956 if (!verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
1958 DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
1959 (unsigned long long) val64);
1960 return FAILURE;
1961 }
1962
1963 /* Enable select interrupts */
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001964 if (nic->intr_type != INTA)
1965 en_dis_able_nic_intrs(nic, ENA_ALL_INTRS, DISABLE_INTRS);
1966 else {
1967 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
1968 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
1969 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
1970 en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
1971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001973 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 * With some switches, link might be already up at this point.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001975 * Because of this weird behavior, when we enable laser,
1976 * we may not get link. We need to handle this. We cannot
1977 * figure out which switch is misbehaving. So we are forced to
1978 * make a global change.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 */
1980
1981 /* Enabling Laser. */
1982 val64 = readq(&bar0->adapter_control);
1983 val64 |= ADAPTER_EOI_TX_ON;
1984 writeq(val64, &bar0->adapter_control);
1985
Ananda Rajuc92ca042006-04-21 19:18:03 -04001986 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
1987 /*
1988 * Dont see link state interrupts initally on some switches,
1989 * so directly scheduling the link state task here.
1990 */
1991 schedule_work(&nic->set_link_task);
1992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 /* SXE-002: Initialize link and activity LED */
1994 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001995 if (((subid & 0xFF) >= 0x07) &&
1996 (nic->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 val64 = readq(&bar0->gpio_control);
1998 val64 |= 0x0000800000000000ULL;
1999 writeq(val64, &bar0->gpio_control);
2000 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002001 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 }
2003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 return SUCCESS;
2005}
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002006/**
2007 * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
2008 */
2009static struct sk_buff *s2io_txdl_getskb(fifo_info_t *fifo_data, TxD_t *txdlp, int get_off)
2010{
2011 nic_t *nic = fifo_data->nic;
2012 struct sk_buff *skb;
2013 TxD_t *txds;
2014 u16 j, frg_cnt;
2015
2016 txds = txdlp;
Andrew Morton26b76252005-12-14 19:25:23 -08002017 if (txds->Host_Control == (u64)(long)nic->ufo_in_band_v) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002018 pci_unmap_single(nic->pdev, (dma_addr_t)
2019 txds->Buffer_Pointer, sizeof(u64),
2020 PCI_DMA_TODEVICE);
2021 txds++;
2022 }
2023
2024 skb = (struct sk_buff *) ((unsigned long)
2025 txds->Host_Control);
2026 if (!skb) {
2027 memset(txdlp, 0, (sizeof(TxD_t) * fifo_data->max_txds));
2028 return NULL;
2029 }
2030 pci_unmap_single(nic->pdev, (dma_addr_t)
2031 txds->Buffer_Pointer,
2032 skb->len - skb->data_len,
2033 PCI_DMA_TODEVICE);
2034 frg_cnt = skb_shinfo(skb)->nr_frags;
2035 if (frg_cnt) {
2036 txds++;
2037 for (j = 0; j < frg_cnt; j++, txds++) {
2038 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
2039 if (!txds->Buffer_Pointer)
2040 break;
2041 pci_unmap_page(nic->pdev, (dma_addr_t)
2042 txds->Buffer_Pointer,
2043 frag->size, PCI_DMA_TODEVICE);
2044 }
2045 }
2046 txdlp->Host_Control = 0;
2047 return(skb);
2048}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002050/**
2051 * free_tx_buffers - Free all queued Tx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002053 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 * Free all queued Tx buffers.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002055 * Return Value: void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056*/
2057
2058static void free_tx_buffers(struct s2io_nic *nic)
2059{
2060 struct net_device *dev = nic->dev;
2061 struct sk_buff *skb;
2062 TxD_t *txdp;
2063 int i, j;
2064 mac_info_t *mac_control;
2065 struct config_param *config;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002066 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 mac_control = &nic->mac_control;
2069 config = &nic->config;
2070
2071 for (i = 0; i < config->tx_fifo_num; i++) {
2072 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002073 txdp = (TxD_t *) mac_control->fifos[i].list_info[j].
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 list_virt_addr;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002075 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
2076 if (skb) {
2077 dev_kfree_skb(skb);
2078 cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081 DBG_PRINT(INTR_DBG,
2082 "%s:forcibly freeing %d skbs on FIFO%d\n",
2083 dev->name, cnt, i);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002084 mac_control->fifos[i].tx_curr_get_info.offset = 0;
2085 mac_control->fifos[i].tx_curr_put_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 }
2087}
2088
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002089/**
2090 * stop_nic - To stop the nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 * @nic ; device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002092 * Description:
2093 * This function does exactly the opposite of what the start_nic()
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 * function does. This function is called to stop the device.
2095 * Return Value:
2096 * void.
2097 */
2098
2099static void stop_nic(struct s2io_nic *nic)
2100{
2101 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2102 register u64 val64 = 0;
2103 u16 interruptible, i;
2104 mac_info_t *mac_control;
2105 struct config_param *config;
2106
2107 mac_control = &nic->mac_control;
2108 config = &nic->config;
2109
2110 /* Disable all interrupts */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002111 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002112 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
2113 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
2115
2116 /* Disable PRCs */
2117 for (i = 0; i < config->rx_ring_num; i++) {
2118 val64 = readq(&bar0->prc_ctrl_n[i]);
2119 val64 &= ~((u64) PRC_CTRL_RC_ENABLED);
2120 writeq(val64, &bar0->prc_ctrl_n[i]);
2121 }
2122}
2123
Adrian Bunk26df54b2006-01-14 03:09:40 +01002124static int fill_rxd_3buf(nic_t *nic, RxD_t *rxdp, struct sk_buff *skb)
Ananda Rajuda6971d2005-10-31 16:55:31 -05002125{
2126 struct net_device *dev = nic->dev;
2127 struct sk_buff *frag_list;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002128 void *tmp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002129
2130 /* Buffer-1 receives L3/L4 headers */
2131 ((RxD3_t*)rxdp)->Buffer1_ptr = pci_map_single
2132 (nic->pdev, skb->data, l3l4hdr_size + 4,
2133 PCI_DMA_FROMDEVICE);
2134
2135 /* skb_shinfo(skb)->frag_list will have L4 data payload */
2136 skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE);
2137 if (skb_shinfo(skb)->frag_list == NULL) {
2138 DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb failed\n ", dev->name);
2139 return -ENOMEM ;
2140 }
2141 frag_list = skb_shinfo(skb)->frag_list;
2142 frag_list->next = NULL;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002143 tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
2144 frag_list->data = tmp;
2145 frag_list->tail = tmp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002146
2147 /* Buffer-2 receives L4 data payload */
2148 ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
2149 frag_list->data, dev->mtu,
2150 PCI_DMA_FROMDEVICE);
2151 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
2152 rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu);
2153
2154 return SUCCESS;
2155}
2156
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002157/**
2158 * fill_rx_buffers - Allocates the Rx side skbs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002160 * @ring_no: ring number
2161 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 * The function allocates Rx side skbs and puts the physical
2163 * address of these buffers into the RxD buffer pointers, so that the NIC
2164 * can DMA the received frame into these locations.
2165 * The NIC supports 3 receive modes, viz
2166 * 1. single buffer,
2167 * 2. three buffer and
2168 * 3. Five buffer modes.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002169 * Each mode defines how many fragments the received frame will be split
2170 * up into by the NIC. The frame is split into L3 header, L4 Header,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
2172 * is split into 3 fragments. As of now only single buffer mode is
2173 * supported.
2174 * Return Value:
2175 * SUCCESS on success or an appropriate -ve value on failure.
2176 */
2177
Adrian Bunkac1f60d2005-11-06 01:46:47 +01002178static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
2180 struct net_device *dev = nic->dev;
2181 struct sk_buff *skb;
2182 RxD_t *rxdp;
2183 int off, off1, size, block_no, block_no1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 u32 alloc_tab = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002185 u32 alloc_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 mac_info_t *mac_control;
2187 struct config_param *config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002188 u64 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 buffAdd_t *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190#ifndef CONFIG_S2IO_NAPI
2191 unsigned long flags;
2192#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002193 RxD_t *first_rxdp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
2195 mac_control = &nic->mac_control;
2196 config = &nic->config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002197 alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
2198 atomic_read(&nic->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Ananda Raju863c11a2006-04-21 19:03:13 -04002200 block_no1 = mac_control->rings[ring_no].rx_curr_get_info.block_index;
2201 off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 while (alloc_tab < alloc_cnt) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002203 block_no = mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 block_index;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002205 off = mac_control->rings[ring_no].rx_curr_put_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
Ananda Rajuda6971d2005-10-31 16:55:31 -05002207 rxdp = mac_control->rings[ring_no].
2208 rx_blocks[block_no].rxds[off].virt_addr;
2209
2210 if ((block_no == block_no1) && (off == off1) &&
2211 (rxdp->Host_Control)) {
2212 DBG_PRINT(INTR_DBG, "%s: Get and Put",
2213 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 DBG_PRINT(INTR_DBG, " info equated\n");
2215 goto end;
2216 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002217 if (off && (off == rxd_count[nic->rxd_mode])) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002218 mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 block_index++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002220 if (mac_control->rings[ring_no].rx_curr_put_info.
2221 block_index == mac_control->rings[ring_no].
2222 block_count)
2223 mac_control->rings[ring_no].rx_curr_put_info.
2224 block_index = 0;
2225 block_no = mac_control->rings[ring_no].
2226 rx_curr_put_info.block_index;
2227 if (off == rxd_count[nic->rxd_mode])
2228 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002229 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002230 offset = off;
2231 rxdp = mac_control->rings[ring_no].
2232 rx_blocks[block_no].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2234 dev->name, rxdp);
2235 }
2236#ifndef CONFIG_S2IO_NAPI
2237 spin_lock_irqsave(&nic->put_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002238 mac_control->rings[ring_no].put_pos =
Ananda Rajuda6971d2005-10-31 16:55:31 -05002239 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 spin_unlock_irqrestore(&nic->put_lock, flags);
2241#endif
Ananda Rajuda6971d2005-10-31 16:55:31 -05002242 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
2243 ((nic->rxd_mode >= RXD_MODE_3A) &&
2244 (rxdp->Control_2 & BIT(0)))) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002245 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002246 offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 goto end;
2248 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002249 /* calculate size of skb based on ring mode */
2250 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
2251 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
2252 if (nic->rxd_mode == RXD_MODE_1)
2253 size += NET_IP_ALIGN;
2254 else if (nic->rxd_mode == RXD_MODE_3B)
2255 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
2256 else
2257 size = l3l4hdr_size + ALIGN_SIZE + BUF0_LEN + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Ananda Rajuda6971d2005-10-31 16:55:31 -05002259 /* allocate skb */
2260 skb = dev_alloc_skb(size);
2261 if(!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 DBG_PRINT(ERR_DBG, "%s: Out of ", dev->name);
2263 DBG_PRINT(ERR_DBG, "memory to allocate SKBs\n");
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002264 if (first_rxdp) {
2265 wmb();
2266 first_rxdp->Control_1 |= RXD_OWN_XENA;
2267 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002268 return -ENOMEM ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002270 if (nic->rxd_mode == RXD_MODE_1) {
2271 /* 1 buffer mode - normal operation mode */
2272 memset(rxdp, 0, sizeof(RxD1_t));
2273 skb_reserve(skb, NET_IP_ALIGN);
2274 ((RxD1_t*)rxdp)->Buffer0_ptr = pci_map_single
Ananda Raju863c11a2006-04-21 19:03:13 -04002275 (nic->pdev, skb->data, size - NET_IP_ALIGN,
2276 PCI_DMA_FROMDEVICE);
2277 rxdp->Control_2 = SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002278
2279 } else if (nic->rxd_mode >= RXD_MODE_3A) {
2280 /*
2281 * 2 or 3 buffer mode -
2282 * Both 2 buffer mode and 3 buffer mode provides 128
2283 * byte aligned receive buffers.
2284 *
2285 * 3 buffer mode provides header separation where in
2286 * skb->data will have L3/L4 headers where as
2287 * skb_shinfo(skb)->frag_list will have the L4 data
2288 * payload
2289 */
2290
2291 memset(rxdp, 0, sizeof(RxD3_t));
2292 ba = &mac_control->rings[ring_no].ba[block_no][off];
2293 skb_reserve(skb, BUF0_LEN);
2294 tmp = (u64)(unsigned long) skb->data;
2295 tmp += ALIGN_SIZE;
2296 tmp &= ~ALIGN_SIZE;
2297 skb->data = (void *) (unsigned long)tmp;
2298 skb->tail = (void *) (unsigned long)tmp;
2299
2300 ((RxD3_t*)rxdp)->Buffer0_ptr =
2301 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
2302 PCI_DMA_FROMDEVICE);
2303 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2304 if (nic->rxd_mode == RXD_MODE_3B) {
2305 /* Two buffer mode */
2306
2307 /*
2308 * Buffer2 will have L3/L4 header plus
2309 * L4 payload
2310 */
2311 ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single
2312 (nic->pdev, skb->data, dev->mtu + 4,
2313 PCI_DMA_FROMDEVICE);
2314
2315 /* Buffer-1 will be dummy buffer not used */
2316 ((RxD3_t*)rxdp)->Buffer1_ptr =
2317 pci_map_single(nic->pdev, ba->ba_1, BUF1_LEN,
2318 PCI_DMA_FROMDEVICE);
2319 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2320 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2321 (dev->mtu + 4);
2322 } else {
2323 /* 3 buffer mode */
2324 if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) {
2325 dev_kfree_skb_irq(skb);
2326 if (first_rxdp) {
2327 wmb();
2328 first_rxdp->Control_1 |=
2329 RXD_OWN_XENA;
2330 }
2331 return -ENOMEM ;
2332 }
2333 }
2334 rxdp->Control_2 |= BIT(0);
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 rxdp->Host_Control = (unsigned long) (skb);
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002337 if (alloc_tab & ((1 << rxsync_frequency) - 1))
2338 rxdp->Control_1 |= RXD_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 off++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002340 if (off == (rxd_count[nic->rxd_mode] + 1))
2341 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002342 mac_control->rings[ring_no].rx_curr_put_info.offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002344 rxdp->Control_2 |= SET_RXD_MARKER;
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002345 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
2346 if (first_rxdp) {
2347 wmb();
2348 first_rxdp->Control_1 |= RXD_OWN_XENA;
2349 }
2350 first_rxdp = rxdp;
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 atomic_inc(&nic->rx_bufs_left[ring_no]);
2353 alloc_tab++;
2354 }
2355
2356 end:
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002357 /* Transfer ownership of first descriptor to adapter just before
2358 * exiting. Before that, use memory barrier so that ownership
2359 * and other fields are seen by adapter correctly.
2360 */
2361 if (first_rxdp) {
2362 wmb();
2363 first_rxdp->Control_1 |= RXD_OWN_XENA;
2364 }
2365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 return SUCCESS;
2367}
2368
Ananda Rajuda6971d2005-10-31 16:55:31 -05002369static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2370{
2371 struct net_device *dev = sp->dev;
2372 int j;
2373 struct sk_buff *skb;
2374 RxD_t *rxdp;
2375 mac_info_t *mac_control;
2376 buffAdd_t *ba;
2377
2378 mac_control = &sp->mac_control;
2379 for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
2380 rxdp = mac_control->rings[ring_no].
2381 rx_blocks[blk].rxds[j].virt_addr;
2382 skb = (struct sk_buff *)
2383 ((unsigned long) rxdp->Host_Control);
2384 if (!skb) {
2385 continue;
2386 }
2387 if (sp->rxd_mode == RXD_MODE_1) {
2388 pci_unmap_single(sp->pdev, (dma_addr_t)
2389 ((RxD1_t*)rxdp)->Buffer0_ptr,
2390 dev->mtu +
2391 HEADER_ETHERNET_II_802_3_SIZE
2392 + HEADER_802_2_SIZE +
2393 HEADER_SNAP_SIZE,
2394 PCI_DMA_FROMDEVICE);
2395 memset(rxdp, 0, sizeof(RxD1_t));
2396 } else if(sp->rxd_mode == RXD_MODE_3B) {
2397 ba = &mac_control->rings[ring_no].
2398 ba[blk][j];
2399 pci_unmap_single(sp->pdev, (dma_addr_t)
2400 ((RxD3_t*)rxdp)->Buffer0_ptr,
2401 BUF0_LEN,
2402 PCI_DMA_FROMDEVICE);
2403 pci_unmap_single(sp->pdev, (dma_addr_t)
2404 ((RxD3_t*)rxdp)->Buffer1_ptr,
2405 BUF1_LEN,
2406 PCI_DMA_FROMDEVICE);
2407 pci_unmap_single(sp->pdev, (dma_addr_t)
2408 ((RxD3_t*)rxdp)->Buffer2_ptr,
2409 dev->mtu + 4,
2410 PCI_DMA_FROMDEVICE);
2411 memset(rxdp, 0, sizeof(RxD3_t));
2412 } else {
2413 pci_unmap_single(sp->pdev, (dma_addr_t)
2414 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
2415 PCI_DMA_FROMDEVICE);
2416 pci_unmap_single(sp->pdev, (dma_addr_t)
2417 ((RxD3_t*)rxdp)->Buffer1_ptr,
2418 l3l4hdr_size + 4,
2419 PCI_DMA_FROMDEVICE);
2420 pci_unmap_single(sp->pdev, (dma_addr_t)
2421 ((RxD3_t*)rxdp)->Buffer2_ptr, dev->mtu,
2422 PCI_DMA_FROMDEVICE);
2423 memset(rxdp, 0, sizeof(RxD3_t));
2424 }
2425 dev_kfree_skb(skb);
2426 atomic_dec(&sp->rx_bufs_left[ring_no]);
2427 }
2428}
2429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002431 * free_rx_buffers - Frees all Rx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 * @sp: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002433 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 * This function will free all Rx buffers allocated by host.
2435 * Return Value:
2436 * NONE.
2437 */
2438
2439static void free_rx_buffers(struct s2io_nic *sp)
2440{
2441 struct net_device *dev = sp->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002442 int i, blk = 0, buf_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 mac_info_t *mac_control;
2444 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
2446 mac_control = &sp->mac_control;
2447 config = &sp->config;
2448
2449 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05002450 for (blk = 0; blk < rx_ring_sz[i]; blk++)
2451 free_rxd_blk(sp,i,blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002453 mac_control->rings[i].rx_curr_put_info.block_index = 0;
2454 mac_control->rings[i].rx_curr_get_info.block_index = 0;
2455 mac_control->rings[i].rx_curr_put_info.offset = 0;
2456 mac_control->rings[i].rx_curr_get_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 atomic_set(&sp->rx_bufs_left[i], 0);
2458 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
2459 dev->name, buf_cnt, i);
2460 }
2461}
2462
2463/**
2464 * s2io_poll - Rx interrupt handler for NAPI support
2465 * @dev : pointer to the device structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002466 * @budget : The number of packets that were budgeted to be processed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 * during one pass through the 'Poll" function.
2468 * Description:
2469 * Comes into picture only if NAPI support has been incorporated. It does
2470 * the same thing that rx_intr_handler does, but not in a interrupt context
2471 * also It will process only a given number of packets.
2472 * Return value:
2473 * 0 on success and 1 if there are No Rx packets to be processed.
2474 */
2475
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002476#if defined(CONFIG_S2IO_NAPI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477static int s2io_poll(struct net_device *dev, int *budget)
2478{
2479 nic_t *nic = dev->priv;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002480 int pkt_cnt = 0, org_pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 mac_info_t *mac_control;
2482 struct config_param *config;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002483 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ananda Raju863c11a2006-04-21 19:03:13 -04002484 u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002485 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002487 atomic_inc(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 mac_control = &nic->mac_control;
2489 config = &nic->config;
2490
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002491 nic->pkts_to_process = *budget;
2492 if (nic->pkts_to_process > dev->quota)
2493 nic->pkts_to_process = dev->quota;
2494 org_pkts_to_process = nic->pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 writeq(val64, &bar0->rx_traffic_int);
Ananda Raju863c11a2006-04-21 19:03:13 -04002497 val64 = readl(&bar0->rx_traffic_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
2499 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002500 rx_intr_handler(&mac_control->rings[i]);
2501 pkt_cnt = org_pkts_to_process - nic->pkts_to_process;
2502 if (!nic->pkts_to_process) {
2503 /* Quota for the current iteration has been met */
2504 goto no_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
2507 if (!pkt_cnt)
2508 pkt_cnt = 1;
2509
2510 dev->quota -= pkt_cnt;
2511 *budget -= pkt_cnt;
2512 netif_rx_complete(dev);
2513
2514 for (i = 0; i < config->rx_ring_num; i++) {
2515 if (fill_rx_buffers(nic, i) == -ENOMEM) {
2516 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
2517 DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
2518 break;
2519 }
2520 }
2521 /* Re enable the Rx interrupts. */
Ananda Rajuc92ca042006-04-21 19:18:03 -04002522 writeq(0x0, &bar0->rx_traffic_mask);
2523 val64 = readl(&bar0->rx_traffic_mask);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002524 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 return 0;
2526
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002527no_rx:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 dev->quota -= pkt_cnt;
2529 *budget -= pkt_cnt;
2530
2531 for (i = 0; i < config->rx_ring_num; i++) {
2532 if (fill_rx_buffers(nic, i) == -ENOMEM) {
2533 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
2534 DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
2535 break;
2536 }
2537 }
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002538 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 return 1;
2540}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002541#endif
2542
2543/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 * rx_intr_handler - Rx interrupt handler
2545 * @nic: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002546 * Description:
2547 * If the interrupt is because of a received frame or if the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 * receive ring contains fresh as yet un-processed frames,this function is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002549 * called. It picks out the RxD at which place the last Rx processing had
2550 * stopped and sends the skb to the OSM's Rx handler and then increments
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 * the offset.
2552 * Return Value:
2553 * NONE.
2554 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002555static void rx_intr_handler(ring_info_t *ring_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002557 nic_t *nic = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 struct net_device *dev = (struct net_device *) nic->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002559 int get_block, put_block, put_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 rx_curr_get_info_t get_info, put_info;
2561 RxD_t *rxdp;
2562 struct sk_buff *skb;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002563#ifndef CONFIG_S2IO_NAPI
2564 int pkt_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565#endif
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002566 int i;
2567
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002568 spin_lock(&nic->rx_lock);
2569 if (atomic_read(&nic->card_state) == CARD_DOWN) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002570 DBG_PRINT(INTR_DBG, "%s: %s going down for reset\n",
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002571 __FUNCTION__, dev->name);
2572 spin_unlock(&nic->rx_lock);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002573 return;
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002574 }
2575
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002576 get_info = ring_data->rx_curr_get_info;
2577 get_block = get_info.block_index;
2578 put_info = ring_data->rx_curr_put_info;
2579 put_block = put_info.block_index;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002580 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002581#ifndef CONFIG_S2IO_NAPI
2582 spin_lock(&nic->put_lock);
2583 put_offset = ring_data->put_pos;
2584 spin_unlock(&nic->put_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585#else
Ananda Rajuda6971d2005-10-31 16:55:31 -05002586 put_offset = (put_block * (rxd_count[nic->rxd_mode] + 1)) +
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002587 put_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588#endif
Ananda Rajuda6971d2005-10-31 16:55:31 -05002589 while (RXD_IS_UP2DT(rxdp)) {
2590 /* If your are next to put index then it's FIFO full condition */
2591 if ((get_block == put_block) &&
2592 (get_info.offset + 1) == put_info.offset) {
2593 DBG_PRINT(ERR_DBG, "%s: Ring Full\n",dev->name);
2594 break;
2595 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002596 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
2597 if (skb == NULL) {
2598 DBG_PRINT(ERR_DBG, "%s: The skb is ",
2599 dev->name);
2600 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002601 spin_unlock(&nic->rx_lock);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002602 return;
2603 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002604 if (nic->rxd_mode == RXD_MODE_1) {
2605 pci_unmap_single(nic->pdev, (dma_addr_t)
2606 ((RxD1_t*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002607 dev->mtu +
2608 HEADER_ETHERNET_II_802_3_SIZE +
2609 HEADER_802_2_SIZE +
2610 HEADER_SNAP_SIZE,
2611 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002612 } else if (nic->rxd_mode == RXD_MODE_3B) {
2613 pci_unmap_single(nic->pdev, (dma_addr_t)
2614 ((RxD3_t*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002615 BUF0_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002616 pci_unmap_single(nic->pdev, (dma_addr_t)
2617 ((RxD3_t*)rxdp)->Buffer1_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002618 BUF1_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002619 pci_unmap_single(nic->pdev, (dma_addr_t)
2620 ((RxD3_t*)rxdp)->Buffer2_ptr,
2621 dev->mtu + 4,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002622 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002623 } else {
2624 pci_unmap_single(nic->pdev, (dma_addr_t)
2625 ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
2626 PCI_DMA_FROMDEVICE);
2627 pci_unmap_single(nic->pdev, (dma_addr_t)
2628 ((RxD3_t*)rxdp)->Buffer1_ptr,
2629 l3l4hdr_size + 4,
2630 PCI_DMA_FROMDEVICE);
2631 pci_unmap_single(nic->pdev, (dma_addr_t)
2632 ((RxD3_t*)rxdp)->Buffer2_ptr,
2633 dev->mtu, PCI_DMA_FROMDEVICE);
2634 }
Ananda Raju863c11a2006-04-21 19:03:13 -04002635 prefetch(skb->data);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002636 rx_osm_handler(ring_data, rxdp);
2637 get_info.offset++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002638 ring_data->rx_curr_get_info.offset = get_info.offset;
2639 rxdp = ring_data->rx_blocks[get_block].
2640 rxds[get_info.offset].virt_addr;
2641 if (get_info.offset == rxd_count[nic->rxd_mode]) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002642 get_info.offset = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002643 ring_data->rx_curr_get_info.offset = get_info.offset;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002644 get_block++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002645 if (get_block == ring_data->block_count)
2646 get_block = 0;
2647 ring_data->rx_curr_get_info.block_index = get_block;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002648 rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
2649 }
2650
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002651#ifdef CONFIG_S2IO_NAPI
2652 nic->pkts_to_process -= 1;
2653 if (!nic->pkts_to_process)
2654 break;
2655#else
2656 pkt_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
2658 break;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002659#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002661 if (nic->lro) {
2662 /* Clear all LRO sessions before exiting */
2663 for (i=0; i<MAX_LRO_SESSIONS; i++) {
2664 lro_t *lro = &nic->lro0_n[i];
2665 if (lro->in_use) {
2666 update_L3L4_header(nic, lro);
2667 queue_rx_frame(lro->parent);
2668 clear_lro_session(lro);
2669 }
2670 }
2671 }
2672
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002673 spin_unlock(&nic->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002675
2676/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 * tx_intr_handler - Transmit interrupt handler
2678 * @nic : device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002679 * Description:
2680 * If an interrupt was raised to indicate DMA complete of the
2681 * Tx packet, this function is called. It identifies the last TxD
2682 * whose buffer was freed and frees all skbs whose data have already
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 * DMA'ed into the NICs internal memory.
2684 * Return Value:
2685 * NONE
2686 */
2687
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002688static void tx_intr_handler(fifo_info_t *fifo_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002690 nic_t *nic = fifo_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 struct net_device *dev = (struct net_device *) nic->dev;
2692 tx_curr_get_info_t get_info, put_info;
2693 struct sk_buff *skb;
2694 TxD_t *txdlp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002696 get_info = fifo_data->tx_curr_get_info;
2697 put_info = fifo_data->tx_curr_put_info;
2698 txdlp = (TxD_t *) fifo_data->list_info[get_info.offset].
2699 list_virt_addr;
2700 while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
2701 (get_info.offset != put_info.offset) &&
2702 (txdlp->Host_Control)) {
2703 /* Check for TxD errors */
2704 if (txdlp->Control_1 & TXD_T_CODE) {
2705 unsigned long long err;
2706 err = txdlp->Control_1 & TXD_T_CODE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002707 if ((err >> 48) == 0xA) {
2708 DBG_PRINT(TX_DBG, "TxD returned due \
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002709to loss of link\n");
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002710 }
2711 else {
2712 DBG_PRINT(ERR_DBG, "***TxD error \
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002713%llx\n", err);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002716
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002717 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002718 if (skb == NULL) {
2719 DBG_PRINT(ERR_DBG, "%s: Null skb ",
2720 __FUNCTION__);
2721 DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
2722 return;
2723 }
2724
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002725 /* Updating the statistics block */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002726 nic->stats.tx_bytes += skb->len;
2727 dev_kfree_skb_irq(skb);
2728
2729 get_info.offset++;
Ananda Raju863c11a2006-04-21 19:03:13 -04002730 if (get_info.offset == get_info.fifo_len + 1)
2731 get_info.offset = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002732 txdlp = (TxD_t *) fifo_data->list_info
2733 [get_info.offset].list_virt_addr;
2734 fifo_data->tx_curr_get_info.offset =
2735 get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 }
2737
2738 spin_lock(&nic->tx_lock);
2739 if (netif_queue_stopped(dev))
2740 netif_wake_queue(dev);
2741 spin_unlock(&nic->tx_lock);
2742}
2743
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002744/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 * alarm_intr_handler - Alarm Interrrupt handler
2746 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002747 * Description: If the interrupt was neither because of Rx packet or Tx
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 * complete, this function is called. If the interrupt was to indicate
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002749 * a loss of link, the OSM link status handler is invoked for any other
2750 * alarm interrupt the block that raised the interrupt is displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 * and a H/W reset is issued.
2752 * Return Value:
2753 * NONE
2754*/
2755
2756static void alarm_intr_handler(struct s2io_nic *nic)
2757{
2758 struct net_device *dev = (struct net_device *) nic->dev;
2759 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2760 register u64 val64 = 0, err_reg = 0;
2761
2762 /* Handling link status change error Intr */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002763 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
2764 err_reg = readq(&bar0->mac_rmac_err_reg);
2765 writeq(err_reg, &bar0->mac_rmac_err_reg);
2766 if (err_reg & RMAC_LINK_STATE_CHANGE_INT) {
2767 schedule_work(&nic->set_link_task);
2768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 }
2770
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002771 /* Handling Ecc errors */
2772 val64 = readq(&bar0->mc_err_reg);
2773 writeq(val64, &bar0->mc_err_reg);
2774 if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
2775 if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002776 nic->mac_control.stats_info->sw_stat.
2777 double_ecc_errs++;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002778 DBG_PRINT(INIT_DBG, "%s: Device indicates ",
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002779 dev->name);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002780 DBG_PRINT(INIT_DBG, "double ECC error!!\n");
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002781 if (nic->device_type != XFRAME_II_DEVICE) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002782 /* Reset XframeI only if critical error */
2783 if (val64 & (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
2784 MC_ERR_REG_MIRI_ECC_DB_ERR_1)) {
2785 netif_stop_queue(dev);
2786 schedule_work(&nic->rst_timer_task);
2787 }
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002788 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002789 } else {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002790 nic->mac_control.stats_info->sw_stat.
2791 single_ecc_errs++;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002792 }
2793 }
2794
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 /* In case of a serious error, the device will be Reset. */
2796 val64 = readq(&bar0->serr_source);
2797 if (val64 & SERR_SOURCE_ANY) {
2798 DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002799 DBG_PRINT(ERR_DBG, "serious error %llx!!\n",
2800 (unsigned long long)val64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 netif_stop_queue(dev);
2802 schedule_work(&nic->rst_timer_task);
2803 }
2804
2805 /*
2806 * Also as mentioned in the latest Errata sheets if the PCC_FB_ECC
2807 * Error occurs, the adapter will be recycled by disabling the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002808 * adapter enable bit and enabling it again after the device
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 * becomes Quiescent.
2810 */
2811 val64 = readq(&bar0->pcc_err_reg);
2812 writeq(val64, &bar0->pcc_err_reg);
2813 if (val64 & PCC_FB_ECC_DB_ERR) {
2814 u64 ac = readq(&bar0->adapter_control);
2815 ac &= ~(ADAPTER_CNTL_EN);
2816 writeq(ac, &bar0->adapter_control);
2817 ac = readq(&bar0->adapter_control);
2818 schedule_work(&nic->set_link_task);
2819 }
2820
2821 /* Other type of interrupts are not being handled now, TODO */
2822}
2823
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002824/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 * wait_for_cmd_complete - waits for a command to complete.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002826 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002828 * Description: Function that waits for a command to Write into RMAC
2829 * ADDR DATA registers to be completed and returns either success or
2830 * error depending on whether the command was complete or not.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 * Return value:
2832 * SUCCESS on success and FAILURE on failure.
2833 */
2834
Ananda Rajuc92ca042006-04-21 19:18:03 -04002835static int wait_for_cmd_complete(void *addr, u64 busy_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 int ret = FAILURE, cnt = 0;
2838 u64 val64;
2839
2840 while (TRUE) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04002841 val64 = readq(addr);
2842 if (!(val64 & busy_bit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 ret = SUCCESS;
2844 break;
2845 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04002846
2847 if(in_interrupt())
2848 mdelay(50);
2849 else
2850 msleep(50);
2851
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 if (cnt++ > 10)
2853 break;
2854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 return ret;
2856}
2857
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002858/**
2859 * s2io_reset - Resets the card.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 * @sp : private member of the device structure.
2861 * Description: Function to Reset the card. This function then also
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002862 * restores the previously saved PCI configuration space registers as
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 * the card reset also resets the configuration space.
2864 * Return value:
2865 * void.
2866 */
2867
Adrian Bunk26df54b2006-01-14 03:09:40 +01002868static void s2io_reset(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
2870 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2871 u64 val64;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002872 u16 subid, pci_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002874 /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002875 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002876
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 val64 = SW_RESET_ALL;
2878 writeq(val64, &bar0->sw_reset);
2879
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002880 /*
2881 * At this stage, if the PCI write is indeed completed, the
2882 * card is reset and so is the PCI Config space of the device.
2883 * So a read cannot be issued at this stage on any of the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 * registers to ensure the write into "sw_reset" register
2885 * has gone through.
2886 * Question: Is there any system call that will explicitly force
2887 * all the write commands still pending on the bus to be pushed
2888 * through?
2889 * As of now I'am just giving a 250ms delay and hoping that the
2890 * PCI write to sw_reset register is done by this time.
2891 */
2892 msleep(250);
Ananda Rajuc92ca042006-04-21 19:18:03 -04002893 if (strstr(sp->product_name, "CX4")) {
2894 msleep(750);
2895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002897 /* Restore the PCI state saved during initialization. */
2898 pci_restore_state(sp->pdev);
2899 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07002900 pci_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 s2io_init_pci(sp);
2902
2903 msleep(250);
2904
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002905 /* Set swapper to enable I/O register access */
2906 s2io_set_swapper(sp);
2907
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04002908 /* Restore the MSIX table entries from local variables */
2909 restore_xmsi_data(sp);
2910
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002911 /* Clear certain PCI/PCI-X fields after reset */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002912 if (sp->device_type == XFRAME_II_DEVICE) {
2913 /* Clear parity err detect bit */
2914 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002915
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002916 /* Clearing PCIX Ecc status register */
2917 pci_write_config_dword(sp->pdev, 0x68, 0x7C);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002918
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002919 /* Clearing PCI_STATUS error reflected here */
2920 writeq(BIT(62), &bar0->txpic_int_reg);
2921 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002922
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002923 /* Reset device statistics maintained by OS */
2924 memset(&sp->stats, 0, sizeof (struct net_device_stats));
2925
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* SXE-002: Configure link and activity LED to turn it off */
2927 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002928 if (((subid & 0xFF) >= 0x07) &&
2929 (sp->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 val64 = readq(&bar0->gpio_control);
2931 val64 |= 0x0000800000000000ULL;
2932 writeq(val64, &bar0->gpio_control);
2933 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002934 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
2936
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002937 /*
2938 * Clear spurious ECC interrupts that would have occured on
2939 * XFRAME II cards after reset.
2940 */
2941 if (sp->device_type == XFRAME_II_DEVICE) {
2942 val64 = readq(&bar0->pcc_err_reg);
2943 writeq(val64, &bar0->pcc_err_reg);
2944 }
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 sp->device_enabled_once = FALSE;
2947}
2948
2949/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002950 * s2io_set_swapper - to set the swapper controle on the card
2951 * @sp : private member of the device structure,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 * pointer to the s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002953 * Description: Function to set the swapper control on the card
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 * correctly depending on the 'endianness' of the system.
2955 * Return value:
2956 * SUCCESS on success and FAILURE on failure.
2957 */
2958
Adrian Bunk26df54b2006-01-14 03:09:40 +01002959static int s2io_set_swapper(nic_t * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960{
2961 struct net_device *dev = sp->dev;
2962 XENA_dev_config_t __iomem *bar0 = sp->bar0;
2963 u64 val64, valt, valr;
2964
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002965 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 * Set proper endian settings and verify the same by reading
2967 * the PIF Feed-back register.
2968 */
2969
2970 val64 = readq(&bar0->pif_rd_swapper_fb);
2971 if (val64 != 0x0123456789ABCDEFULL) {
2972 int i = 0;
2973 u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
2974 0x8100008181000081ULL, /* FE=1, SE=0 */
2975 0x4200004242000042ULL, /* FE=0, SE=1 */
2976 0}; /* FE=0, SE=0 */
2977
2978 while(i<4) {
2979 writeq(value[i], &bar0->swapper_ctrl);
2980 val64 = readq(&bar0->pif_rd_swapper_fb);
2981 if (val64 == 0x0123456789ABCDEFULL)
2982 break;
2983 i++;
2984 }
2985 if (i == 4) {
2986 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
2987 dev->name);
2988 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
2989 (unsigned long long) val64);
2990 return FAILURE;
2991 }
2992 valr = value[i];
2993 } else {
2994 valr = readq(&bar0->swapper_ctrl);
2995 }
2996
2997 valt = 0x0123456789ABCDEFULL;
2998 writeq(valt, &bar0->xmsi_address);
2999 val64 = readq(&bar0->xmsi_address);
3000
3001 if(val64 != valt) {
3002 int i = 0;
3003 u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
3004 0x0081810000818100ULL, /* FE=1, SE=0 */
3005 0x0042420000424200ULL, /* FE=0, SE=1 */
3006 0}; /* FE=0, SE=0 */
3007
3008 while(i<4) {
3009 writeq((value[i] | valr), &bar0->swapper_ctrl);
3010 writeq(valt, &bar0->xmsi_address);
3011 val64 = readq(&bar0->xmsi_address);
3012 if(val64 == valt)
3013 break;
3014 i++;
3015 }
3016 if(i == 4) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003017 unsigned long long x = val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003019 DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 return FAILURE;
3021 }
3022 }
3023 val64 = readq(&bar0->swapper_ctrl);
3024 val64 &= 0xFFFF000000000000ULL;
3025
3026#ifdef __BIG_ENDIAN
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003027 /*
3028 * The device by default set to a big endian format, so a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 * big endian driver need not set anything.
3030 */
3031 val64 |= (SWAPPER_CTRL_TXP_FE |
3032 SWAPPER_CTRL_TXP_SE |
3033 SWAPPER_CTRL_TXD_R_FE |
3034 SWAPPER_CTRL_TXD_W_FE |
3035 SWAPPER_CTRL_TXF_R_FE |
3036 SWAPPER_CTRL_RXD_R_FE |
3037 SWAPPER_CTRL_RXD_W_FE |
3038 SWAPPER_CTRL_RXF_W_FE |
3039 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Andrew Morton92383342005-10-16 00:11:29 -07003041 if (sp->intr_type == INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003042 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 writeq(val64, &bar0->swapper_ctrl);
3044#else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003045 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 * Initially we enable all bits to make it accessible by the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003047 * driver, then we selectively enable only those bits that
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 * we want to set.
3049 */
3050 val64 |= (SWAPPER_CTRL_TXP_FE |
3051 SWAPPER_CTRL_TXP_SE |
3052 SWAPPER_CTRL_TXD_R_FE |
3053 SWAPPER_CTRL_TXD_R_SE |
3054 SWAPPER_CTRL_TXD_W_FE |
3055 SWAPPER_CTRL_TXD_W_SE |
3056 SWAPPER_CTRL_TXF_R_FE |
3057 SWAPPER_CTRL_RXD_R_FE |
3058 SWAPPER_CTRL_RXD_R_SE |
3059 SWAPPER_CTRL_RXD_W_FE |
3060 SWAPPER_CTRL_RXD_W_SE |
3061 SWAPPER_CTRL_RXF_W_FE |
3062 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003064 if (sp->intr_type == INTA)
3065 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 writeq(val64, &bar0->swapper_ctrl);
3067#endif
3068 val64 = readq(&bar0->swapper_ctrl);
3069
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003070 /*
3071 * Verifying if endian settings are accurate by reading a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 * feedback register.
3073 */
3074 val64 = readq(&bar0->pif_rd_swapper_fb);
3075 if (val64 != 0x0123456789ABCDEFULL) {
3076 /* Endian settings are incorrect, calls for another dekko. */
3077 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3078 dev->name);
3079 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3080 (unsigned long long) val64);
3081 return FAILURE;
3082 }
3083
3084 return SUCCESS;
3085}
3086
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003087static int wait_for_msix_trans(nic_t *nic, int i)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003088{
Al Viro37eb47e2005-12-15 09:17:29 +00003089 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003090 u64 val64;
3091 int ret = 0, cnt = 0;
3092
3093 do {
3094 val64 = readq(&bar0->xmsi_access);
3095 if (!(val64 & BIT(15)))
3096 break;
3097 mdelay(1);
3098 cnt++;
3099 } while(cnt < 5);
3100 if (cnt == 5) {
3101 DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
3102 ret = 1;
3103 }
3104
3105 return ret;
3106}
3107
Adrian Bunk26df54b2006-01-14 03:09:40 +01003108static void restore_xmsi_data(nic_t *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003109{
Al Viro37eb47e2005-12-15 09:17:29 +00003110 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003111 u64 val64;
3112 int i;
3113
Ananda Rajuc92ca042006-04-21 19:18:03 -04003114 for (i=0; i< nic->avail_msix_vectors; i++) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003115 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3116 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
3117 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
3118 writeq(val64, &bar0->xmsi_access);
3119 if (wait_for_msix_trans(nic, i)) {
3120 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3121 continue;
3122 }
3123 }
3124}
3125
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003126static void store_xmsi_data(nic_t *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003127{
Al Viro37eb47e2005-12-15 09:17:29 +00003128 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003129 u64 val64, addr, data;
3130 int i;
3131
3132 /* Store and display */
Ananda Rajuc92ca042006-04-21 19:18:03 -04003133 for (i=0; i< nic->avail_msix_vectors; i++) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003134 val64 = (BIT(15) | vBIT(i, 26, 6));
3135 writeq(val64, &bar0->xmsi_access);
3136 if (wait_for_msix_trans(nic, i)) {
3137 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3138 continue;
3139 }
3140 addr = readq(&bar0->xmsi_address);
3141 data = readq(&bar0->xmsi_data);
3142 if (addr && data) {
3143 nic->msix_info[i].addr = addr;
3144 nic->msix_info[i].data = data;
3145 }
3146 }
3147}
3148
3149int s2io_enable_msi(nic_t *nic)
3150{
Al Viro37eb47e2005-12-15 09:17:29 +00003151 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003152 u16 msi_ctrl, msg_val;
3153 struct config_param *config = &nic->config;
3154 struct net_device *dev = nic->dev;
3155 u64 val64, tx_mat, rx_mat;
3156 int i, err;
3157
3158 val64 = readq(&bar0->pic_control);
3159 val64 &= ~BIT(1);
3160 writeq(val64, &bar0->pic_control);
3161
3162 err = pci_enable_msi(nic->pdev);
3163 if (err) {
3164 DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
3165 nic->dev->name);
3166 return err;
3167 }
3168
3169 /*
3170 * Enable MSI and use MSI-1 in stead of the standard MSI-0
3171 * for interrupt handling.
3172 */
3173 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3174 msg_val ^= 0x1;
3175 pci_write_config_word(nic->pdev, 0x4c, msg_val);
3176 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3177
3178 pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
3179 msi_ctrl |= 0x10;
3180 pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
3181
3182 /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
3183 tx_mat = readq(&bar0->tx_mat0_n[0]);
3184 for (i=0; i<config->tx_fifo_num; i++) {
3185 tx_mat |= TX_MAT_SET(i, 1);
3186 }
3187 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3188
3189 rx_mat = readq(&bar0->rx_mat);
3190 for (i=0; i<config->rx_ring_num; i++) {
3191 rx_mat |= RX_MAT_SET(i, 1);
3192 }
3193 writeq(rx_mat, &bar0->rx_mat);
3194
3195 dev->irq = nic->pdev->irq;
3196 return 0;
3197}
3198
Adrian Bunk26df54b2006-01-14 03:09:40 +01003199static int s2io_enable_msi_x(nic_t *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003200{
Al Viro37eb47e2005-12-15 09:17:29 +00003201 XENA_dev_config_t __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003202 u64 tx_mat, rx_mat;
3203 u16 msi_control; /* Temp variable */
3204 int ret, i, j, msix_indx = 1;
3205
3206 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
3207 GFP_KERNEL);
3208 if (nic->entries == NULL) {
3209 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3210 return -ENOMEM;
3211 }
3212 memset(nic->entries, 0, MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3213
3214 nic->s2io_entries =
3215 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
3216 GFP_KERNEL);
3217 if (nic->s2io_entries == NULL) {
3218 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3219 kfree(nic->entries);
3220 return -ENOMEM;
3221 }
3222 memset(nic->s2io_entries, 0,
3223 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3224
3225 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3226 nic->entries[i].entry = i;
3227 nic->s2io_entries[i].entry = i;
3228 nic->s2io_entries[i].arg = NULL;
3229 nic->s2io_entries[i].in_use = 0;
3230 }
3231
3232 tx_mat = readq(&bar0->tx_mat0_n[0]);
3233 for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
3234 tx_mat |= TX_MAT_SET(i, msix_indx);
3235 nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
3236 nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
3237 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3238 }
3239 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3240
3241 if (!nic->config.bimodal) {
3242 rx_mat = readq(&bar0->rx_mat);
3243 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3244 rx_mat |= RX_MAT_SET(j, msix_indx);
3245 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3246 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3247 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3248 }
3249 writeq(rx_mat, &bar0->rx_mat);
3250 } else {
3251 tx_mat = readq(&bar0->tx_mat0_n[7]);
3252 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3253 tx_mat |= TX_MAT_SET(i, msix_indx);
3254 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3255 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3256 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3257 }
3258 writeq(tx_mat, &bar0->tx_mat0_n[7]);
3259 }
3260
Ananda Rajuc92ca042006-04-21 19:18:03 -04003261 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003262 ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003263 /* We fail init if error or we get less vectors than min required */
3264 if (ret >= (nic->config.tx_fifo_num + nic->config.rx_ring_num + 1)) {
3265 nic->avail_msix_vectors = ret;
3266 ret = pci_enable_msix(nic->pdev, nic->entries, ret);
3267 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003268 if (ret) {
3269 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3270 kfree(nic->entries);
3271 kfree(nic->s2io_entries);
3272 nic->entries = NULL;
3273 nic->s2io_entries = NULL;
Ananda Rajuc92ca042006-04-21 19:18:03 -04003274 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003275 return -ENOMEM;
3276 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003277 if (!nic->avail_msix_vectors)
3278 nic->avail_msix_vectors = MAX_REQUESTED_MSI_X;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003279
3280 /*
3281 * To enable MSI-X, MSI also needs to be enabled, due to a bug
3282 * in the herc NIC. (Temp change, needs to be removed later)
3283 */
3284 pci_read_config_word(nic->pdev, 0x42, &msi_control);
3285 msi_control |= 0x1; /* Enable MSI */
3286 pci_write_config_word(nic->pdev, 0x42, msi_control);
3287
3288 return 0;
3289}
3290
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291/* ********************************************************* *
3292 * Functions defined below concern the OS part of the driver *
3293 * ********************************************************* */
3294
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003295/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 * s2io_open - open entry point of the driver
3297 * @dev : pointer to the device structure.
3298 * Description:
3299 * This function is the open entry point of the driver. It mainly calls a
3300 * function to allocate Rx buffers and inserts them into the buffer
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003301 * descriptors and then enables the Rx part of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 * Return value:
3303 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3304 * file on failure.
3305 */
3306
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003307static int s2io_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308{
3309 nic_t *sp = dev->priv;
3310 int err = 0;
3311
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003312 /*
3313 * Make sure you have link off by default every time
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 * Nic is initialized
3315 */
3316 netif_carrier_off(dev);
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003317 sp->last_link_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 /* Initialize H/W and enable interrupts */
Ananda Rajuc92ca042006-04-21 19:18:03 -04003320 err = s2io_card_up(sp);
3321 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
3323 dev->name);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003324 if (err == -ENODEV)
3325 goto hw_init_failed;
3326 else
3327 goto hw_enable_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 }
3329
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003330 /* Store the values of the MSIX table in the nic_t structure */
3331 store_xmsi_data(sp);
3332
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 /* After proper initialization of H/W, register ISR */
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003334 if (sp->intr_type == MSI) {
3335 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
3336 SA_SHIRQ, sp->name, dev);
3337 if (err) {
3338 DBG_PRINT(ERR_DBG, "%s: MSI registration \
3339failed\n", dev->name);
3340 goto isr_registration_failed;
3341 }
3342 }
3343 if (sp->intr_type == MSI_X) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003344 int i;
3345
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003346 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
3347 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
3348 sprintf(sp->desc1, "%s:MSI-X-%d-TX",
3349 dev->name, i);
3350 err = request_irq(sp->entries[i].vector,
3351 s2io_msix_fifo_handle, 0, sp->desc1,
3352 sp->s2io_entries[i].arg);
3353 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc1,
Andrew Morton26b76252005-12-14 19:25:23 -08003354 (unsigned long long)sp->msix_info[i].addr);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003355 } else {
3356 sprintf(sp->desc2, "%s:MSI-X-%d-RX",
3357 dev->name, i);
3358 err = request_irq(sp->entries[i].vector,
3359 s2io_msix_ring_handle, 0, sp->desc2,
3360 sp->s2io_entries[i].arg);
3361 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc2,
Andrew Morton26b76252005-12-14 19:25:23 -08003362 (unsigned long long)sp->msix_info[i].addr);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003363 }
3364 if (err) {
3365 DBG_PRINT(ERR_DBG, "%s: MSI-X-%d registration \
3366failed\n", dev->name, i);
3367 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
3368 goto isr_registration_failed;
3369 }
3370 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
3371 }
3372 }
3373 if (sp->intr_type == INTA) {
3374 err = request_irq((int) sp->pdev->irq, s2io_isr, SA_SHIRQ,
3375 sp->name, dev);
3376 if (err) {
3377 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
3378 dev->name);
3379 goto isr_registration_failed;
3380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 }
3382
3383 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
3384 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003385 err = -ENODEV;
3386 goto setting_mac_address_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 }
3388
3389 netif_start_queue(dev);
3390 return 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003391
3392setting_mac_address_failed:
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003393 if (sp->intr_type != MSI_X)
3394 free_irq(sp->pdev->irq, dev);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003395isr_registration_failed:
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07003396 del_timer_sync(&sp->alarm_timer);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003397 if (sp->intr_type == MSI_X) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003398 int i;
3399 u16 msi_control; /* Temp variable */
3400 for (i=1; (sp->s2io_entries[i].in_use ==
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003401 MSIX_REGISTERED_SUCCESS); i++) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003402 int vector = sp->entries[i].vector;
3403 void *arg = sp->s2io_entries[i].arg;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003404
Ananda Rajuc92ca042006-04-21 19:18:03 -04003405 free_irq(vector, arg);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003406 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003407 pci_disable_msix(sp->pdev);
3408
3409 /* Temp */
3410 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3411 msi_control &= 0xFFFE; /* Disable MSI */
3412 pci_write_config_word(sp->pdev, 0x42, msi_control);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003413 }
3414 else if (sp->intr_type == MSI)
3415 pci_disable_msi(sp->pdev);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003416hw_enable_failed:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003417 s2io_reset(sp);
3418hw_init_failed:
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003419 if (sp->intr_type == MSI_X) {
3420 if (sp->entries)
3421 kfree(sp->entries);
3422 if (sp->s2io_entries)
3423 kfree(sp->s2io_entries);
3424 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003425 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426}
3427
3428/**
3429 * s2io_close -close entry point of the driver
3430 * @dev : device pointer.
3431 * Description:
3432 * This is the stop entry point of the driver. It needs to undo exactly
3433 * whatever was done by the open entry point,thus it's usually referred to
3434 * as the close function.Among other things this function mainly stops the
3435 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3436 * Return value:
3437 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3438 * file on failure.
3439 */
3440
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003441static int s2io_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442{
3443 nic_t *sp = dev->priv;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003444
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 flush_scheduled_work();
3446 netif_stop_queue(dev);
3447 /* Reset card, kill tasklet and free Tx and Rx buffers. */
Ananda Rajuc92ca042006-04-21 19:18:03 -04003448 s2io_card_down(sp, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 sp->device_close_flag = TRUE; /* Device is shut down. */
3451 return 0;
3452}
3453
3454/**
3455 * s2io_xmit - Tx entry point of te driver
3456 * @skb : the socket buffer containing the Tx data.
3457 * @dev : device pointer.
3458 * Description :
3459 * This function is the Tx entry point of the driver. S2IO NIC supports
3460 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
3461 * NOTE: when device cant queue the pkt,just the trans_start variable will
3462 * not be upadted.
3463 * Return value:
3464 * 0 on success & 1 on failure.
3465 */
3466
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003467static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468{
3469 nic_t *sp = dev->priv;
3470 u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
3471 register u64 val64;
3472 TxD_t *txdp;
3473 TxFIFO_element_t __iomem *tx_fifo;
3474 unsigned long flags;
3475#ifdef NETIF_F_TSO
3476 int mss;
3477#endif
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003478 u16 vlan_tag = 0;
3479 int vlan_priority = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 mac_info_t *mac_control;
3481 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
3483 mac_control = &sp->mac_control;
3484 config = &sp->config;
3485
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003486 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 spin_lock_irqsave(&sp->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 if (atomic_read(&sp->card_state) == CARD_DOWN) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003489 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 dev->name);
3491 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003492 dev_kfree_skb(skb);
3493 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 }
3495
3496 queue = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003498 /* Get Fifo number to Transmit based on vlan priority */
3499 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
3500 vlan_tag = vlan_tx_tag_get(skb);
3501 vlan_priority = vlan_tag >> 13;
3502 queue = config->fifo_mapping[vlan_priority];
3503 }
3504
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003505 put_off = (u16) mac_control->fifos[queue].tx_curr_put_info.offset;
3506 get_off = (u16) mac_control->fifos[queue].tx_curr_get_info.offset;
3507 txdp = (TxD_t *) mac_control->fifos[queue].list_info[put_off].
3508 list_virt_addr;
3509
3510 queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04003512 if (txdp->Host_Control ||
3513 ((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003514 DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 netif_stop_queue(dev);
3516 dev_kfree_skb(skb);
3517 spin_unlock_irqrestore(&sp->tx_lock, flags);
3518 return 0;
3519 }
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003520
3521 /* A buffer with no data will be dropped */
3522 if (!skb->len) {
3523 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
3524 dev_kfree_skb(skb);
3525 spin_unlock_irqrestore(&sp->tx_lock, flags);
3526 return 0;
3527 }
3528
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003529 txdp->Control_1 = 0;
3530 txdp->Control_2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531#ifdef NETIF_F_TSO
3532 mss = skb_shinfo(skb)->tso_size;
3533 if (mss) {
3534 txdp->Control_1 |= TXD_TCP_LSO_EN;
3535 txdp->Control_1 |= TXD_TCP_LSO_MSS(mss);
3536 }
3537#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 if (skb->ip_summed == CHECKSUM_HW) {
3539 txdp->Control_2 |=
3540 (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
3541 TXD_TX_CKO_UDP_EN);
3542 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003543 txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
3544 txdp->Control_1 |= TXD_LIST_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 txdp->Control_2 |= config->tx_intr_type;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07003546
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003547 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
3548 txdp->Control_2 |= TXD_VLAN_ENABLE;
3549 txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
3550 }
3551
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003552 frg_len = skb->len - skb->data_len;
3553 if (skb_shinfo(skb)->ufo_size) {
3554 int ufo_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003556 ufo_size = skb_shinfo(skb)->ufo_size;
3557 ufo_size &= ~7;
3558 txdp->Control_1 |= TXD_UFO_EN;
3559 txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
3560 txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
3561#ifdef __BIG_ENDIAN
3562 sp->ufo_in_band_v[put_off] =
3563 (u64)skb_shinfo(skb)->ip6_frag_id;
3564#else
3565 sp->ufo_in_band_v[put_off] =
3566 (u64)skb_shinfo(skb)->ip6_frag_id << 32;
3567#endif
3568 txdp->Host_Control = (unsigned long)sp->ufo_in_band_v;
3569 txdp->Buffer_Pointer = pci_map_single(sp->pdev,
3570 sp->ufo_in_band_v,
3571 sizeof(u64), PCI_DMA_TODEVICE);
3572 txdp++;
3573 txdp->Control_1 = 0;
3574 txdp->Control_2 = 0;
3575 }
3576
3577 txdp->Buffer_Pointer = pci_map_single
3578 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
3579 txdp->Host_Control = (unsigned long) skb;
3580 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
3581
3582 if (skb_shinfo(skb)->ufo_size)
3583 txdp->Control_1 |= TXD_UFO_EN;
3584
3585 frg_cnt = skb_shinfo(skb)->nr_frags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 /* For fragmented SKB. */
3587 for (i = 0; i < frg_cnt; i++) {
3588 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003589 /* A '0' length fragment will be ignored */
3590 if (!frag->size)
3591 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 txdp++;
3593 txdp->Buffer_Pointer = (u64) pci_map_page
3594 (sp->pdev, frag->page, frag->page_offset,
3595 frag->size, PCI_DMA_TODEVICE);
Ananda Rajuefd51b52006-01-19 14:11:54 -05003596 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003597 if (skb_shinfo(skb)->ufo_size)
3598 txdp->Control_1 |= TXD_UFO_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 }
3600 txdp->Control_1 |= TXD_GATHER_CODE_LAST;
3601
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003602 if (skb_shinfo(skb)->ufo_size)
3603 frg_cnt++; /* as Txd0 was used for inband header */
3604
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 tx_fifo = mac_control->tx_FIFO_start[queue];
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003606 val64 = mac_control->fifos[queue].list_info[put_off].list_phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 writeq(val64, &tx_fifo->TxDL_Pointer);
3608
3609 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
3610 TX_FIFO_LAST_LIST);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003611
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612#ifdef NETIF_F_TSO
3613 if (mss)
3614 val64 |= TX_FIFO_SPECIAL_FUNC;
3615#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003616 if (skb_shinfo(skb)->ufo_size)
3617 val64 |= TX_FIFO_SPECIAL_FUNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 writeq(val64, &tx_fifo->List_Control);
3619
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003620 mmiowb();
3621
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 put_off++;
Ananda Raju863c11a2006-04-21 19:03:13 -04003623 if (put_off == mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1)
3624 put_off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003625 mac_control->fifos[queue].tx_curr_put_info.offset = put_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626
3627 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04003628 if (((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 DBG_PRINT(TX_DBG,
3630 "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
3631 put_off, get_off);
3632 netif_stop_queue(dev);
3633 }
3634
3635 dev->trans_start = jiffies;
3636 spin_unlock_irqrestore(&sp->tx_lock, flags);
3637
3638 return 0;
3639}
3640
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07003641static void
3642s2io_alarm_handle(unsigned long data)
3643{
3644 nic_t *sp = (nic_t *)data;
3645
3646 alarm_intr_handler(sp);
3647 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
3648}
3649
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003650static irqreturn_t
3651s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
3652{
3653 struct net_device *dev = (struct net_device *) dev_id;
3654 nic_t *sp = dev->priv;
3655 int i;
3656 int ret;
3657 mac_info_t *mac_control;
3658 struct config_param *config;
3659
3660 atomic_inc(&sp->isr_cnt);
3661 mac_control = &sp->mac_control;
3662 config = &sp->config;
3663 DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
3664
3665 /* If Intr is because of Rx Traffic */
3666 for (i = 0; i < config->rx_ring_num; i++)
3667 rx_intr_handler(&mac_control->rings[i]);
3668
3669 /* If Intr is because of Tx Traffic */
3670 for (i = 0; i < config->tx_fifo_num; i++)
3671 tx_intr_handler(&mac_control->fifos[i]);
3672
3673 /*
3674 * If the Rx buffer count is below the panic threshold then
3675 * reallocate the buffers from the interrupt handler itself,
3676 * else schedule a tasklet to reallocate the buffers.
3677 */
3678 for (i = 0; i < config->rx_ring_num; i++) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003679 if (!sp->lro) {
3680 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
3681 int level = rx_buffer_level(sp, rxb_size, i);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003682
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003683 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3684 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
3685 dev->name);
3686 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3687 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
3688 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3689 dev->name);
3690 DBG_PRINT(ERR_DBG, " in ISR!!\n");
3691 clear_bit(0, (&sp->tasklet_status));
3692 atomic_dec(&sp->isr_cnt);
3693 return IRQ_HANDLED;
3694 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003695 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003696 } else if (level == LOW) {
3697 tasklet_schedule(&sp->task);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003698 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003699 }
3700 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
3701 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3702 dev->name);
3703 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
3704 break;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003705 }
3706 }
3707
3708 atomic_dec(&sp->isr_cnt);
3709 return IRQ_HANDLED;
3710}
3711
3712static irqreturn_t
3713s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs)
3714{
3715 ring_info_t *ring = (ring_info_t *)dev_id;
3716 nic_t *sp = ring->nic;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003717 struct net_device *dev = (struct net_device *) dev_id;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003718 int rxb_size, level, rng_n;
3719
3720 atomic_inc(&sp->isr_cnt);
3721 rx_intr_handler(ring);
3722
3723 rng_n = ring->ring_no;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003724 if (!sp->lro) {
3725 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
3726 level = rx_buffer_level(sp, rxb_size, rng_n);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003727
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003728 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3729 int ret;
3730 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
3731 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3732 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
3733 DBG_PRINT(ERR_DBG, "Out of memory in %s",
3734 __FUNCTION__);
3735 clear_bit(0, (&sp->tasklet_status));
3736 return IRQ_HANDLED;
3737 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003738 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003739 } else if (level == LOW) {
3740 tasklet_schedule(&sp->task);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003741 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003742 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003743 else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
3744 DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
3745 DBG_PRINT(ERR_DBG, " in Rx Intr!!\n");
3746 }
3747
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003748 atomic_dec(&sp->isr_cnt);
3749
3750 return IRQ_HANDLED;
3751}
3752
3753static irqreturn_t
3754s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs)
3755{
3756 fifo_info_t *fifo = (fifo_info_t *)dev_id;
3757 nic_t *sp = fifo->nic;
3758
3759 atomic_inc(&sp->isr_cnt);
3760 tx_intr_handler(fifo);
3761 atomic_dec(&sp->isr_cnt);
3762 return IRQ_HANDLED;
3763}
3764
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003765static void s2io_txpic_intr_handle(nic_t *sp)
3766{
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01003767 XENA_dev_config_t __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003768 u64 val64;
3769
3770 val64 = readq(&bar0->pic_int_status);
3771 if (val64 & PIC_INT_GPIO) {
3772 val64 = readq(&bar0->gpio_int_reg);
3773 if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
3774 (val64 & GPIO_INT_REG_LINK_UP)) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003775 /*
3776 * This is unstable state so clear both up/down
3777 * interrupt and adapter to re-evaluate the link state.
3778 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003779 val64 |= GPIO_INT_REG_LINK_DOWN;
3780 val64 |= GPIO_INT_REG_LINK_UP;
3781 writeq(val64, &bar0->gpio_int_reg);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003782 val64 = readq(&bar0->gpio_int_mask);
3783 val64 &= ~(GPIO_INT_MASK_LINK_UP |
3784 GPIO_INT_MASK_LINK_DOWN);
3785 writeq(val64, &bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003786 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003787 else if (val64 & GPIO_INT_REG_LINK_UP) {
3788 val64 = readq(&bar0->adapter_status);
3789 if (verify_xena_quiescence(sp, val64,
3790 sp->device_enabled_once)) {
3791 /* Enable Adapter */
3792 val64 = readq(&bar0->adapter_control);
3793 val64 |= ADAPTER_CNTL_EN;
3794 writeq(val64, &bar0->adapter_control);
3795 val64 |= ADAPTER_LED_ON;
3796 writeq(val64, &bar0->adapter_control);
3797 if (!sp->device_enabled_once)
3798 sp->device_enabled_once = 1;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003799
Ananda Rajuc92ca042006-04-21 19:18:03 -04003800 s2io_link(sp, LINK_UP);
3801 /*
3802 * unmask link down interrupt and mask link-up
3803 * intr
3804 */
3805 val64 = readq(&bar0->gpio_int_mask);
3806 val64 &= ~GPIO_INT_MASK_LINK_DOWN;
3807 val64 |= GPIO_INT_MASK_LINK_UP;
3808 writeq(val64, &bar0->gpio_int_mask);
3809
3810 }
3811 }else if (val64 & GPIO_INT_REG_LINK_DOWN) {
3812 val64 = readq(&bar0->adapter_status);
3813 if (verify_xena_quiescence(sp, val64,
3814 sp->device_enabled_once)) {
3815 s2io_link(sp, LINK_DOWN);
3816 /* Link is down so unmaks link up interrupt */
3817 val64 = readq(&bar0->gpio_int_mask);
3818 val64 &= ~GPIO_INT_MASK_LINK_UP;
3819 val64 |= GPIO_INT_MASK_LINK_DOWN;
3820 writeq(val64, &bar0->gpio_int_mask);
3821 }
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003822 }
3823 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003824 val64 = readq(&bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003825}
3826
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827/**
3828 * s2io_isr - ISR handler of the device .
3829 * @irq: the irq of the device.
3830 * @dev_id: a void pointer to the dev structure of the NIC.
3831 * @pt_regs: pointer to the registers pushed on the stack.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003832 * Description: This function is the ISR handler of the device. It
3833 * identifies the reason for the interrupt and calls the relevant
3834 * service routines. As a contongency measure, this ISR allocates the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 * recv buffers, if their numbers are below the panic value which is
3836 * presently set to 25% of the original number of rcv buffers allocated.
3837 * Return value:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003838 * IRQ_HANDLED: will be returned if IRQ was handled by this routine
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 * IRQ_NONE: will be returned if interrupt is not from our device
3840 */
3841static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs)
3842{
3843 struct net_device *dev = (struct net_device *) dev_id;
3844 nic_t *sp = dev->priv;
3845 XENA_dev_config_t __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003846 int i;
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07003847 u64 reason = 0, val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 mac_info_t *mac_control;
3849 struct config_param *config;
3850
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003851 atomic_inc(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852 mac_control = &sp->mac_control;
3853 config = &sp->config;
3854
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003855 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 * Identify the cause for interrupt and call the appropriate
3857 * interrupt handler. Causes for the interrupt could be;
3858 * 1. Rx of packet.
3859 * 2. Tx complete.
3860 * 3. Link down.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003861 * 4. Error in any functional blocks of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 */
3863 reason = readq(&bar0->general_int_status);
3864
3865 if (!reason) {
3866 /* The interrupt was not raised by Xena. */
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003867 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 return IRQ_NONE;
3869 }
3870
Ananda Raju863c11a2006-04-21 19:03:13 -04003871 val64 = 0xFFFFFFFFFFFFFFFFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872#ifdef CONFIG_S2IO_NAPI
3873 if (reason & GEN_INTR_RXTRAFFIC) {
3874 if (netif_rx_schedule_prep(dev)) {
Ananda Raju863c11a2006-04-21 19:03:13 -04003875 writeq(val64, &bar0->rx_traffic_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 __netif_rx_schedule(dev);
3877 }
3878 }
3879#else
Ananda Raju863c11a2006-04-21 19:03:13 -04003880 /*
3881 * Rx handler is called by default, without checking for the
3882 * cause of interrupt.
3883 * rx_traffic_int reg is an R1 register, writing all 1's
3884 * will ensure that the actual interrupt causing bit get's
3885 * cleared and hence a read can be avoided.
3886 */
3887 writeq(val64, &bar0->rx_traffic_int);
3888 for (i = 0; i < config->rx_ring_num; i++) {
3889 rx_intr_handler(&mac_control->rings[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 }
3891#endif
3892
Ananda Raju863c11a2006-04-21 19:03:13 -04003893 /*
3894 * tx_traffic_int reg is an R1 register, writing all 1's
3895 * will ensure that the actual interrupt causing bit get's
3896 * cleared and hence a read can be avoided.
3897 */
3898 writeq(val64, &bar0->tx_traffic_int);
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07003899
Ananda Raju863c11a2006-04-21 19:03:13 -04003900 for (i = 0; i < config->tx_fifo_num; i++)
3901 tx_intr_handler(&mac_control->fifos[i]);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003902
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003903 if (reason & GEN_INTR_TXPIC)
3904 s2io_txpic_intr_handle(sp);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003905 /*
3906 * If the Rx buffer count is below the panic threshold then
3907 * reallocate the buffers from the interrupt handler itself,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 * else schedule a tasklet to reallocate the buffers.
3909 */
3910#ifndef CONFIG_S2IO_NAPI
3911 for (i = 0; i < config->rx_ring_num; i++) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003912 if (!sp->lro) {
3913 int ret;
3914 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
3915 int level = rx_buffer_level(sp, rxb_size, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003917 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3918 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ",
3919 dev->name);
3920 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3921 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
3922 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3923 dev->name);
3924 DBG_PRINT(ERR_DBG, " in ISR!!\n");
3925 clear_bit(0, (&sp->tasklet_status));
3926 atomic_dec(&sp->isr_cnt);
3927 return IRQ_HANDLED;
3928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 clear_bit(0, (&sp->tasklet_status));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003930 } else if (level == LOW) {
3931 tasklet_schedule(&sp->task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003933 }
3934 else if (fill_rx_buffers(sp, i) == -ENOMEM) {
3935 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3936 dev->name);
3937 DBG_PRINT(ERR_DBG, " in Rx intr!!\n");
3938 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 }
3940 }
3941#endif
3942
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003943 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 return IRQ_HANDLED;
3945}
3946
3947/**
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003948 * s2io_updt_stats -
3949 */
3950static void s2io_updt_stats(nic_t *sp)
3951{
3952 XENA_dev_config_t __iomem *bar0 = sp->bar0;
3953 u64 val64;
3954 int cnt = 0;
3955
3956 if (atomic_read(&sp->card_state) == CARD_UP) {
3957 /* Apprx 30us on a 133 MHz bus */
3958 val64 = SET_UPDT_CLICKS(10) |
3959 STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
3960 writeq(val64, &bar0->stat_cfg);
3961 do {
3962 udelay(100);
3963 val64 = readq(&bar0->stat_cfg);
3964 if (!(val64 & BIT(0)))
3965 break;
3966 cnt++;
3967 if (cnt == 5)
3968 break; /* Updt failed */
3969 } while(1);
3970 }
3971}
3972
3973/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003974 * s2io_get_stats - Updates the device statistics structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 * @dev : pointer to the device structure.
3976 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003977 * This function updates the device statistics structure in the s2io_nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 * structure and returns a pointer to the same.
3979 * Return value:
3980 * pointer to the updated net_device_stats structure.
3981 */
3982
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003983static struct net_device_stats *s2io_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984{
3985 nic_t *sp = dev->priv;
3986 mac_info_t *mac_control;
3987 struct config_param *config;
3988
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003989
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 mac_control = &sp->mac_control;
3991 config = &sp->config;
3992
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003993 /* Configure Stats for immediate updt */
3994 s2io_updt_stats(sp);
3995
3996 sp->stats.tx_packets =
3997 le32_to_cpu(mac_control->stats_info->tmac_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003998 sp->stats.tx_errors =
3999 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
4000 sp->stats.rx_errors =
4001 le32_to_cpu(mac_control->stats_info->rmac_drop_frms);
4002 sp->stats.multicast =
4003 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 sp->stats.rx_length_errors =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004005 le32_to_cpu(mac_control->stats_info->rmac_long_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006
4007 return (&sp->stats);
4008}
4009
4010/**
4011 * s2io_set_multicast - entry point for multicast address enable/disable.
4012 * @dev : pointer to the device structure
4013 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004014 * This function is a driver entry point which gets called by the kernel
4015 * whenever multicast addresses must be enabled/disabled. This also gets
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 * called to set/reset promiscuous mode. Depending on the deivce flag, we
4017 * determine, if multicast address must be enabled or if promiscuous mode
4018 * is to be disabled etc.
4019 * Return value:
4020 * void.
4021 */
4022
4023static void s2io_set_multicast(struct net_device *dev)
4024{
4025 int i, j, prev_cnt;
4026 struct dev_mc_list *mclist;
4027 nic_t *sp = dev->priv;
4028 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4029 u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
4030 0xfeffffffffffULL;
4031 u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
4032 void __iomem *add;
4033
4034 if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
4035 /* Enable all Multicast addresses */
4036 writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
4037 &bar0->rmac_addr_data0_mem);
4038 writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
4039 &bar0->rmac_addr_data1_mem);
4040 val64 = RMAC_ADDR_CMD_MEM_WE |
4041 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4042 RMAC_ADDR_CMD_MEM_OFFSET(MAC_MC_ALL_MC_ADDR_OFFSET);
4043 writeq(val64, &bar0->rmac_addr_cmd_mem);
4044 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004045 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4046 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
4048 sp->m_cast_flg = 1;
4049 sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
4050 } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
4051 /* Disable all Multicast addresses */
4052 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4053 &bar0->rmac_addr_data0_mem);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07004054 writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
4055 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 val64 = RMAC_ADDR_CMD_MEM_WE |
4057 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4058 RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
4059 writeq(val64, &bar0->rmac_addr_cmd_mem);
4060 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004061 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4062 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063
4064 sp->m_cast_flg = 0;
4065 sp->all_multi_pos = 0;
4066 }
4067
4068 if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
4069 /* Put the NIC into promiscuous mode */
4070 add = &bar0->mac_cfg;
4071 val64 = readq(&bar0->mac_cfg);
4072 val64 |= MAC_CFG_RMAC_PROM_ENABLE;
4073
4074 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4075 writel((u32) val64, add);
4076 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4077 writel((u32) (val64 >> 32), (add + 4));
4078
4079 val64 = readq(&bar0->mac_cfg);
4080 sp->promisc_flg = 1;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004081 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 dev->name);
4083 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
4084 /* Remove the NIC from promiscuous mode */
4085 add = &bar0->mac_cfg;
4086 val64 = readq(&bar0->mac_cfg);
4087 val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
4088
4089 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4090 writel((u32) val64, add);
4091 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4092 writel((u32) (val64 >> 32), (add + 4));
4093
4094 val64 = readq(&bar0->mac_cfg);
4095 sp->promisc_flg = 0;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004096 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 dev->name);
4098 }
4099
4100 /* Update individual M_CAST address list */
4101 if ((!sp->m_cast_flg) && dev->mc_count) {
4102 if (dev->mc_count >
4103 (MAX_ADDRS_SUPPORTED - MAC_MC_ADDR_START_OFFSET - 1)) {
4104 DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
4105 dev->name);
4106 DBG_PRINT(ERR_DBG, "can be added, please enable ");
4107 DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
4108 return;
4109 }
4110
4111 prev_cnt = sp->mc_addr_count;
4112 sp->mc_addr_count = dev->mc_count;
4113
4114 /* Clear out the previous list of Mc in the H/W. */
4115 for (i = 0; i < prev_cnt; i++) {
4116 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4117 &bar0->rmac_addr_data0_mem);
4118 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004119 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 val64 = RMAC_ADDR_CMD_MEM_WE |
4121 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4122 RMAC_ADDR_CMD_MEM_OFFSET
4123 (MAC_MC_ADDR_START_OFFSET + i);
4124 writeq(val64, &bar0->rmac_addr_cmd_mem);
4125
4126 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004127 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4128 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 DBG_PRINT(ERR_DBG, "%s: Adding ",
4130 dev->name);
4131 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4132 return;
4133 }
4134 }
4135
4136 /* Create the new Rx filter list and update the same in H/W. */
4137 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
4138 i++, mclist = mclist->next) {
4139 memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
4140 ETH_ALEN);
Jeff Garzika7a80d52006-03-04 12:06:51 -05004141 mac_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 for (j = 0; j < ETH_ALEN; j++) {
4143 mac_addr |= mclist->dmi_addr[j];
4144 mac_addr <<= 8;
4145 }
4146 mac_addr >>= 8;
4147 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4148 &bar0->rmac_addr_data0_mem);
4149 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004150 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 val64 = RMAC_ADDR_CMD_MEM_WE |
4152 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4153 RMAC_ADDR_CMD_MEM_OFFSET
4154 (i + MAC_MC_ADDR_START_OFFSET);
4155 writeq(val64, &bar0->rmac_addr_cmd_mem);
4156
4157 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004158 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4159 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 DBG_PRINT(ERR_DBG, "%s: Adding ",
4161 dev->name);
4162 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4163 return;
4164 }
4165 }
4166 }
4167}
4168
4169/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004170 * s2io_set_mac_addr - Programs the Xframe mac address
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 * @dev : pointer to the device structure.
4172 * @addr: a uchar pointer to the new mac address which is to be set.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004173 * Description : This procedure will program the Xframe to receive
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 * frames with new Mac Address
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004175 * Return value: SUCCESS on success and an appropriate (-)ve integer
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 * as defined in errno.h file on failure.
4177 */
4178
Adrian Bunk26df54b2006-01-14 03:09:40 +01004179static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180{
4181 nic_t *sp = dev->priv;
4182 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4183 register u64 val64, mac_addr = 0;
4184 int i;
4185
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004186 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 * Set the new MAC address as the new unicast filter and reflect this
4188 * change on the device address registered with the OS. It will be
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004189 * at offset 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 */
4191 for (i = 0; i < ETH_ALEN; i++) {
4192 mac_addr <<= 8;
4193 mac_addr |= addr[i];
4194 }
4195
4196 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4197 &bar0->rmac_addr_data0_mem);
4198
4199 val64 =
4200 RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4201 RMAC_ADDR_CMD_MEM_OFFSET(0);
4202 writeq(val64, &bar0->rmac_addr_cmd_mem);
4203 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004204 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
4205 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
4207 return FAILURE;
4208 }
4209
4210 return SUCCESS;
4211}
4212
4213/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004214 * s2io_ethtool_sset - Sets different link parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
4216 * @info: pointer to the structure with parameters given by ethtool to set
4217 * link information.
4218 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004219 * The function sets different link parameters provided by the user onto
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 * the NIC.
4221 * Return value:
4222 * 0 on success.
4223*/
4224
4225static int s2io_ethtool_sset(struct net_device *dev,
4226 struct ethtool_cmd *info)
4227{
4228 nic_t *sp = dev->priv;
4229 if ((info->autoneg == AUTONEG_ENABLE) ||
4230 (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
4231 return -EINVAL;
4232 else {
4233 s2io_close(sp->dev);
4234 s2io_open(sp->dev);
4235 }
4236
4237 return 0;
4238}
4239
4240/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004241 * s2io_ethtol_gset - Return link specific information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 * @sp : private member of the device structure, pointer to the
4243 * s2io_nic structure.
4244 * @info : pointer to the structure with parameters given by ethtool
4245 * to return link information.
4246 * Description:
4247 * Returns link specific information like speed, duplex etc.. to ethtool.
4248 * Return value :
4249 * return 0 on success.
4250 */
4251
4252static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
4253{
4254 nic_t *sp = dev->priv;
4255 info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4256 info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4257 info->port = PORT_FIBRE;
4258 /* info->transceiver?? TODO */
4259
4260 if (netif_carrier_ok(sp->dev)) {
4261 info->speed = 10000;
4262 info->duplex = DUPLEX_FULL;
4263 } else {
4264 info->speed = -1;
4265 info->duplex = -1;
4266 }
4267
4268 info->autoneg = AUTONEG_DISABLE;
4269 return 0;
4270}
4271
4272/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004273 * s2io_ethtool_gdrvinfo - Returns driver specific information.
4274 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 * s2io_nic structure.
4276 * @info : pointer to the structure with parameters given by ethtool to
4277 * return driver information.
4278 * Description:
4279 * Returns driver specefic information like name, version etc.. to ethtool.
4280 * Return value:
4281 * void
4282 */
4283
4284static void s2io_ethtool_gdrvinfo(struct net_device *dev,
4285 struct ethtool_drvinfo *info)
4286{
4287 nic_t *sp = dev->priv;
4288
John W. Linvilledbc23092005-09-28 17:50:51 -04004289 strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
4290 strncpy(info->version, s2io_driver_version, sizeof(info->version));
4291 strncpy(info->fw_version, "", sizeof(info->fw_version));
4292 strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 info->regdump_len = XENA_REG_SPACE;
4294 info->eedump_len = XENA_EEPROM_SPACE;
4295 info->testinfo_len = S2IO_TEST_LEN;
4296 info->n_stats = S2IO_STAT_LEN;
4297}
4298
4299/**
4300 * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004301 * @sp: private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004303 * @regs : pointer to the structure with parameters given by ethtool for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 * dumping the registers.
4305 * @reg_space: The input argumnet into which all the registers are dumped.
4306 * Description:
4307 * Dumps the entire register space of xFrame NIC into the user given
4308 * buffer area.
4309 * Return value :
4310 * void .
4311*/
4312
4313static void s2io_ethtool_gregs(struct net_device *dev,
4314 struct ethtool_regs *regs, void *space)
4315{
4316 int i;
4317 u64 reg;
4318 u8 *reg_space = (u8 *) space;
4319 nic_t *sp = dev->priv;
4320
4321 regs->len = XENA_REG_SPACE;
4322 regs->version = sp->pdev->subsystem_device;
4323
4324 for (i = 0; i < regs->len; i += 8) {
4325 reg = readq(sp->bar0 + i);
4326 memcpy((reg_space + i), &reg, 8);
4327 }
4328}
4329
4330/**
4331 * s2io_phy_id - timer function that alternates adapter LED.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004332 * @data : address of the private member of the device structure, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 * is a pointer to the s2io_nic structure, provided as an u32.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004334 * Description: This is actually the timer function that alternates the
4335 * adapter LED bit of the adapter control bit to set/reset every time on
4336 * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 * once every second.
4338*/
4339static void s2io_phy_id(unsigned long data)
4340{
4341 nic_t *sp = (nic_t *) data;
4342 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4343 u64 val64 = 0;
4344 u16 subid;
4345
4346 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004347 if ((sp->device_type == XFRAME_II_DEVICE) ||
4348 ((subid & 0xFF) >= 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 val64 = readq(&bar0->gpio_control);
4350 val64 ^= GPIO_CTRL_GPIO_0;
4351 writeq(val64, &bar0->gpio_control);
4352 } else {
4353 val64 = readq(&bar0->adapter_control);
4354 val64 ^= ADAPTER_LED_ON;
4355 writeq(val64, &bar0->adapter_control);
4356 }
4357
4358 mod_timer(&sp->id_timer, jiffies + HZ / 2);
4359}
4360
4361/**
4362 * s2io_ethtool_idnic - To physically identify the nic on the system.
4363 * @sp : private member of the device structure, which is a pointer to the
4364 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004365 * @id : pointer to the structure with identification parameters given by
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 * ethtool.
4367 * Description: Used to physically identify the NIC on the system.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004368 * The Link LED will blink for a time specified by the user for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 * identification.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004370 * NOTE: The Link has to be Up to be able to blink the LED. Hence
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 * identification is possible only if it's link is up.
4372 * Return value:
4373 * int , returns 0 on success
4374 */
4375
4376static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
4377{
4378 u64 val64 = 0, last_gpio_ctrl_val;
4379 nic_t *sp = dev->priv;
4380 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4381 u16 subid;
4382
4383 subid = sp->pdev->subsystem_device;
4384 last_gpio_ctrl_val = readq(&bar0->gpio_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004385 if ((sp->device_type == XFRAME_I_DEVICE) &&
4386 ((subid & 0xFF) < 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 val64 = readq(&bar0->adapter_control);
4388 if (!(val64 & ADAPTER_CNTL_EN)) {
4389 printk(KERN_ERR
4390 "Adapter Link down, cannot blink LED\n");
4391 return -EFAULT;
4392 }
4393 }
4394 if (sp->id_timer.function == NULL) {
4395 init_timer(&sp->id_timer);
4396 sp->id_timer.function = s2io_phy_id;
4397 sp->id_timer.data = (unsigned long) sp;
4398 }
4399 mod_timer(&sp->id_timer, jiffies);
4400 if (data)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004401 msleep_interruptible(data * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004403 msleep_interruptible(MAX_FLICKER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 del_timer_sync(&sp->id_timer);
4405
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004406 if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 writeq(last_gpio_ctrl_val, &bar0->gpio_control);
4408 last_gpio_ctrl_val = readq(&bar0->gpio_control);
4409 }
4410
4411 return 0;
4412}
4413
4414/**
4415 * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004416 * @sp : private member of the device structure, which is a pointer to the
4417 * s2io_nic structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 * @ep : pointer to the structure with pause parameters given by ethtool.
4419 * Description:
4420 * Returns the Pause frame generation and reception capability of the NIC.
4421 * Return value:
4422 * void
4423 */
4424static void s2io_ethtool_getpause_data(struct net_device *dev,
4425 struct ethtool_pauseparam *ep)
4426{
4427 u64 val64;
4428 nic_t *sp = dev->priv;
4429 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4430
4431 val64 = readq(&bar0->rmac_pause_cfg);
4432 if (val64 & RMAC_PAUSE_GEN_ENABLE)
4433 ep->tx_pause = TRUE;
4434 if (val64 & RMAC_PAUSE_RX_ENABLE)
4435 ep->rx_pause = TRUE;
4436 ep->autoneg = FALSE;
4437}
4438
4439/**
4440 * s2io_ethtool_setpause_data - set/reset pause frame generation.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004441 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 * s2io_nic structure.
4443 * @ep : pointer to the structure with pause parameters given by ethtool.
4444 * Description:
4445 * It can be used to set or reset Pause frame generation or reception
4446 * support of the NIC.
4447 * Return value:
4448 * int, returns 0 on Success
4449 */
4450
4451static int s2io_ethtool_setpause_data(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004452 struct ethtool_pauseparam *ep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453{
4454 u64 val64;
4455 nic_t *sp = dev->priv;
4456 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4457
4458 val64 = readq(&bar0->rmac_pause_cfg);
4459 if (ep->tx_pause)
4460 val64 |= RMAC_PAUSE_GEN_ENABLE;
4461 else
4462 val64 &= ~RMAC_PAUSE_GEN_ENABLE;
4463 if (ep->rx_pause)
4464 val64 |= RMAC_PAUSE_RX_ENABLE;
4465 else
4466 val64 &= ~RMAC_PAUSE_RX_ENABLE;
4467 writeq(val64, &bar0->rmac_pause_cfg);
4468 return 0;
4469}
4470
4471/**
4472 * read_eeprom - reads 4 bytes of data from user given offset.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004473 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 * s2io_nic structure.
4475 * @off : offset at which the data must be written
4476 * @data : Its an output parameter where the data read at the given
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004477 * offset is stored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004479 * Will read 4 bytes of data from the user given offset and return the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 * read data.
4481 * NOTE: Will allow to read only part of the EEPROM visible through the
4482 * I2C bus.
4483 * Return value:
4484 * -1 on failure and 0 on success.
4485 */
4486
4487#define S2IO_DEV_ID 5
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004488static int read_eeprom(nic_t * sp, int off, u64 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489{
4490 int ret = -1;
4491 u32 exit_cnt = 0;
4492 u64 val64;
4493 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4494
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004495 if (sp->device_type == XFRAME_I_DEVICE) {
4496 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
4497 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
4498 I2C_CONTROL_CNTL_START;
4499 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004501 while (exit_cnt < 5) {
4502 val64 = readq(&bar0->i2c_control);
4503 if (I2C_CONTROL_CNTL_END(val64)) {
4504 *data = I2C_CONTROL_GET_DATA(val64);
4505 ret = 0;
4506 break;
4507 }
4508 msleep(50);
4509 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 }
4512
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004513 if (sp->device_type == XFRAME_II_DEVICE) {
4514 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4515 SPI_CONTROL_BYTECNT(0x3) |
4516 SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
4517 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4518 val64 |= SPI_CONTROL_REQ;
4519 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4520 while (exit_cnt < 5) {
4521 val64 = readq(&bar0->spi_control);
4522 if (val64 & SPI_CONTROL_NACK) {
4523 ret = 1;
4524 break;
4525 } else if (val64 & SPI_CONTROL_DONE) {
4526 *data = readq(&bar0->spi_data);
4527 *data &= 0xffffff;
4528 ret = 0;
4529 break;
4530 }
4531 msleep(50);
4532 exit_cnt++;
4533 }
4534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 return ret;
4536}
4537
4538/**
4539 * write_eeprom - actually writes the relevant part of the data value.
4540 * @sp : private member of the device structure, which is a pointer to the
4541 * s2io_nic structure.
4542 * @off : offset at which the data must be written
4543 * @data : The data that is to be written
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004544 * @cnt : Number of bytes of the data that are actually to be written into
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 * the Eeprom. (max of 3)
4546 * Description:
4547 * Actually writes the relevant part of the data value into the Eeprom
4548 * through the I2C bus.
4549 * Return value:
4550 * 0 on success, -1 on failure.
4551 */
4552
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004553static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554{
4555 int exit_cnt = 0, ret = -1;
4556 u64 val64;
4557 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4558
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004559 if (sp->device_type == XFRAME_I_DEVICE) {
4560 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
4561 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
4562 I2C_CONTROL_CNTL_START;
4563 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004565 while (exit_cnt < 5) {
4566 val64 = readq(&bar0->i2c_control);
4567 if (I2C_CONTROL_CNTL_END(val64)) {
4568 if (!(val64 & I2C_CONTROL_NACK))
4569 ret = 0;
4570 break;
4571 }
4572 msleep(50);
4573 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 }
4576
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004577 if (sp->device_type == XFRAME_II_DEVICE) {
4578 int write_cnt = (cnt == 8) ? 0 : cnt;
4579 writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
4580
4581 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4582 SPI_CONTROL_BYTECNT(write_cnt) |
4583 SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
4584 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4585 val64 |= SPI_CONTROL_REQ;
4586 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4587 while (exit_cnt < 5) {
4588 val64 = readq(&bar0->spi_control);
4589 if (val64 & SPI_CONTROL_NACK) {
4590 ret = 1;
4591 break;
4592 } else if (val64 & SPI_CONTROL_DONE) {
4593 ret = 0;
4594 break;
4595 }
4596 msleep(50);
4597 exit_cnt++;
4598 }
4599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 return ret;
4601}
Ananda Raju9dc737a2006-04-21 19:05:41 -04004602static void s2io_vpd_read(nic_t *nic)
4603{
4604 u8 vpd_data[256],data;
4605 int i=0, cnt, fail = 0;
4606 int vpd_addr = 0x80;
4607
4608 if (nic->device_type == XFRAME_II_DEVICE) {
4609 strcpy(nic->product_name, "Xframe II 10GbE network adapter");
4610 vpd_addr = 0x80;
4611 }
4612 else {
4613 strcpy(nic->product_name, "Xframe I 10GbE network adapter");
4614 vpd_addr = 0x50;
4615 }
4616
4617 for (i = 0; i < 256; i +=4 ) {
4618 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
4619 pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
4620 pci_write_config_byte(nic->pdev, (vpd_addr + 3), 0);
4621 for (cnt = 0; cnt <5; cnt++) {
4622 msleep(2);
4623 pci_read_config_byte(nic->pdev, (vpd_addr + 3), &data);
4624 if (data == 0x80)
4625 break;
4626 }
4627 if (cnt >= 5) {
4628 DBG_PRINT(ERR_DBG, "Read of VPD data failed\n");
4629 fail = 1;
4630 break;
4631 }
4632 pci_read_config_dword(nic->pdev, (vpd_addr + 4),
4633 (u32 *)&vpd_data[i]);
4634 }
4635 if ((!fail) && (vpd_data[1] < VPD_PRODUCT_NAME_LEN)) {
4636 memset(nic->product_name, 0, vpd_data[1]);
4637 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
4638 }
4639}
4640
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641/**
4642 * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
4643 * @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 -07004644 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 * containing all relevant information.
4646 * @data_buf : user defined value to be written into Eeprom.
4647 * Description: Reads the values stored in the Eeprom at given offset
4648 * for a given length. Stores these values int the input argument data
4649 * buffer 'data_buf' and returns these to the caller (ethtool.)
4650 * Return value:
4651 * int 0 on success
4652 */
4653
4654static int s2io_ethtool_geeprom(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004655 struct ethtool_eeprom *eeprom, u8 * data_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004657 u32 i, valid;
4658 u64 data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 nic_t *sp = dev->priv;
4660
4661 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
4662
4663 if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
4664 eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
4665
4666 for (i = 0; i < eeprom->len; i += 4) {
4667 if (read_eeprom(sp, (eeprom->offset + i), &data)) {
4668 DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
4669 return -EFAULT;
4670 }
4671 valid = INV(data);
4672 memcpy((data_buf + i), &valid, 4);
4673 }
4674 return 0;
4675}
4676
4677/**
4678 * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
4679 * @sp : private member of the device structure, which is a pointer to the
4680 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004681 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 * containing all relevant information.
4683 * @data_buf ; user defined value to be written into Eeprom.
4684 * Description:
4685 * Tries to write the user provided value in the Eeprom, at the offset
4686 * given by the user.
4687 * Return value:
4688 * 0 on success, -EFAULT on failure.
4689 */
4690
4691static int s2io_ethtool_seeprom(struct net_device *dev,
4692 struct ethtool_eeprom *eeprom,
4693 u8 * data_buf)
4694{
4695 int len = eeprom->len, cnt = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004696 u64 valid = 0, data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697 nic_t *sp = dev->priv;
4698
4699 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
4700 DBG_PRINT(ERR_DBG,
4701 "ETHTOOL_WRITE_EEPROM Err: Magic value ");
4702 DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
4703 eeprom->magic);
4704 return -EFAULT;
4705 }
4706
4707 while (len) {
4708 data = (u32) data_buf[cnt] & 0x000000FF;
4709 if (data) {
4710 valid = (u32) (data << 24);
4711 } else
4712 valid = data;
4713
4714 if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
4715 DBG_PRINT(ERR_DBG,
4716 "ETHTOOL_WRITE_EEPROM Err: Cannot ");
4717 DBG_PRINT(ERR_DBG,
4718 "write into the specified offset\n");
4719 return -EFAULT;
4720 }
4721 cnt++;
4722 len--;
4723 }
4724
4725 return 0;
4726}
4727
4728/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004729 * s2io_register_test - reads and writes into all clock domains.
4730 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 * s2io_nic structure.
4732 * @data : variable that returns the result of each of the test conducted b
4733 * by the driver.
4734 * Description:
4735 * Read and write into all clock domains. The NIC has 3 clock domains,
4736 * see that registers in all the three regions are accessible.
4737 * Return value:
4738 * 0 on success.
4739 */
4740
4741static int s2io_register_test(nic_t * sp, uint64_t * data)
4742{
4743 XENA_dev_config_t __iomem *bar0 = sp->bar0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004744 u64 val64 = 0, exp_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 int fail = 0;
4746
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004747 val64 = readq(&bar0->pif_rd_swapper_fb);
4748 if (val64 != 0x123456789abcdefULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 fail = 1;
4750 DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
4751 }
4752
4753 val64 = readq(&bar0->rmac_pause_cfg);
4754 if (val64 != 0xc000ffff00000000ULL) {
4755 fail = 1;
4756 DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
4757 }
4758
4759 val64 = readq(&bar0->rx_queue_cfg);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004760 if (sp->device_type == XFRAME_II_DEVICE)
4761 exp_val = 0x0404040404040404ULL;
4762 else
4763 exp_val = 0x0808080808080808ULL;
4764 if (val64 != exp_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 fail = 1;
4766 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
4767 }
4768
4769 val64 = readq(&bar0->xgxs_efifo_cfg);
4770 if (val64 != 0x000000001923141EULL) {
4771 fail = 1;
4772 DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
4773 }
4774
4775 val64 = 0x5A5A5A5A5A5A5A5AULL;
4776 writeq(val64, &bar0->xmsi_data);
4777 val64 = readq(&bar0->xmsi_data);
4778 if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
4779 fail = 1;
4780 DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
4781 }
4782
4783 val64 = 0xA5A5A5A5A5A5A5A5ULL;
4784 writeq(val64, &bar0->xmsi_data);
4785 val64 = readq(&bar0->xmsi_data);
4786 if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
4787 fail = 1;
4788 DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
4789 }
4790
4791 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004792 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793}
4794
4795/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004796 * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 * @sp : private member of the device structure, which is a pointer to the
4798 * s2io_nic structure.
4799 * @data:variable that returns the result of each of the test conducted by
4800 * the driver.
4801 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004802 * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 * register.
4804 * Return value:
4805 * 0 on success.
4806 */
4807
4808static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
4809{
4810 int fail = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004811 u64 ret_data, org_4F0, org_7F0;
4812 u8 saved_4F0 = 0, saved_7F0 = 0;
4813 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814
4815 /* Test Write Error at offset 0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004816 /* Note that SPI interface allows write access to all areas
4817 * of EEPROM. Hence doing all negative testing only for Xframe I.
4818 */
4819 if (sp->device_type == XFRAME_I_DEVICE)
4820 if (!write_eeprom(sp, 0, 0, 3))
4821 fail = 1;
4822
4823 /* Save current values at offsets 0x4F0 and 0x7F0 */
4824 if (!read_eeprom(sp, 0x4F0, &org_4F0))
4825 saved_4F0 = 1;
4826 if (!read_eeprom(sp, 0x7F0, &org_7F0))
4827 saved_7F0 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828
4829 /* Test Write at offset 4f0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004830 if (write_eeprom(sp, 0x4F0, 0x012345, 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 fail = 1;
4832 if (read_eeprom(sp, 0x4F0, &ret_data))
4833 fail = 1;
4834
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004835 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08004836 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
4837 "Data written %llx Data read %llx\n",
4838 dev->name, (unsigned long long)0x12345,
4839 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842
4843 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004844 write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
4846 /* Test Write Request Error at offset 0x7c */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004847 if (sp->device_type == XFRAME_I_DEVICE)
4848 if (!write_eeprom(sp, 0x07C, 0, 3))
4849 fail = 1;
4850
4851 /* Test Write Request at offset 0x7f0 */
4852 if (write_eeprom(sp, 0x7F0, 0x012345, 3))
4853 fail = 1;
4854 if (read_eeprom(sp, 0x7F0, &ret_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 fail = 1;
4856
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004857 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08004858 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
4859 "Data written %llx Data read %llx\n",
4860 dev->name, (unsigned long long)0x12345,
4861 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864
4865 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004866 write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004868 if (sp->device_type == XFRAME_I_DEVICE) {
4869 /* Test Write Error at offset 0x80 */
4870 if (!write_eeprom(sp, 0x080, 0, 3))
4871 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004873 /* Test Write Error at offset 0xfc */
4874 if (!write_eeprom(sp, 0x0FC, 0, 3))
4875 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004877 /* Test Write Error at offset 0x100 */
4878 if (!write_eeprom(sp, 0x100, 0, 3))
4879 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004881 /* Test Write Error at offset 4ec */
4882 if (!write_eeprom(sp, 0x4EC, 0, 3))
4883 fail = 1;
4884 }
4885
4886 /* Restore values at offsets 0x4F0 and 0x7F0 */
4887 if (saved_4F0)
4888 write_eeprom(sp, 0x4F0, org_4F0, 3);
4889 if (saved_7F0)
4890 write_eeprom(sp, 0x7F0, org_7F0, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891
4892 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004893 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894}
4895
4896/**
4897 * s2io_bist_test - invokes the MemBist test of the card .
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004898 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004900 * @data:variable that returns the result of each of the test conducted by
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 * the driver.
4902 * Description:
4903 * This invokes the MemBist test of the card. We give around
4904 * 2 secs time for the Test to complete. If it's still not complete
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004905 * within this peiod, we consider that the test failed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 * Return value:
4907 * 0 on success and -1 on failure.
4908 */
4909
4910static int s2io_bist_test(nic_t * sp, uint64_t * data)
4911{
4912 u8 bist = 0;
4913 int cnt = 0, ret = -1;
4914
4915 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
4916 bist |= PCI_BIST_START;
4917 pci_write_config_word(sp->pdev, PCI_BIST, bist);
4918
4919 while (cnt < 20) {
4920 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
4921 if (!(bist & PCI_BIST_START)) {
4922 *data = (bist & PCI_BIST_CODE_MASK);
4923 ret = 0;
4924 break;
4925 }
4926 msleep(100);
4927 cnt++;
4928 }
4929
4930 return ret;
4931}
4932
4933/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004934 * s2io-link_test - verifies the link state of the nic
4935 * @sp ; private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 * s2io_nic structure.
4937 * @data: variable that returns the result of each of the test conducted by
4938 * the driver.
4939 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004940 * The function verifies the link state of the NIC and updates the input
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 * argument 'data' appropriately.
4942 * Return value:
4943 * 0 on success.
4944 */
4945
4946static int s2io_link_test(nic_t * sp, uint64_t * data)
4947{
4948 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4949 u64 val64;
4950
4951 val64 = readq(&bar0->adapter_status);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004952 if(!(LINK_IS_UP(val64)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 *data = 1;
Ananda Rajuc92ca042006-04-21 19:18:03 -04004954 else
4955 *data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956
4957 return 0;
4958}
4959
4960/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004961 * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
4962 * @sp - private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004964 * @data - variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 * conducted by the driver.
4966 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004967 * This is one of the offline test that tests the read and write
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 * access to the RldRam chip on the NIC.
4969 * Return value:
4970 * 0 on success.
4971 */
4972
4973static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4974{
4975 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4976 u64 val64;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004977 int cnt, iteration = 0, test_fail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978
4979 val64 = readq(&bar0->adapter_control);
4980 val64 &= ~ADAPTER_ECC_EN;
4981 writeq(val64, &bar0->adapter_control);
4982
4983 val64 = readq(&bar0->mc_rldram_test_ctrl);
4984 val64 |= MC_RLDRAM_TEST_MODE;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07004985 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986
4987 val64 = readq(&bar0->mc_rldram_mrs);
4988 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
4989 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
4990
4991 val64 |= MC_RLDRAM_MRS_ENABLE;
4992 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
4993
4994 while (iteration < 2) {
4995 val64 = 0x55555555aaaa0000ULL;
4996 if (iteration == 1) {
4997 val64 ^= 0xFFFFFFFFFFFF0000ULL;
4998 }
4999 writeq(val64, &bar0->mc_rldram_test_d0);
5000
5001 val64 = 0xaaaa5a5555550000ULL;
5002 if (iteration == 1) {
5003 val64 ^= 0xFFFFFFFFFFFF0000ULL;
5004 }
5005 writeq(val64, &bar0->mc_rldram_test_d1);
5006
5007 val64 = 0x55aaaaaaaa5a0000ULL;
5008 if (iteration == 1) {
5009 val64 ^= 0xFFFFFFFFFFFF0000ULL;
5010 }
5011 writeq(val64, &bar0->mc_rldram_test_d2);
5012
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005013 val64 = (u64) (0x0000003ffffe0100ULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 writeq(val64, &bar0->mc_rldram_test_add);
5015
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005016 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
5017 MC_RLDRAM_TEST_GO;
5018 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
5020 for (cnt = 0; cnt < 5; cnt++) {
5021 val64 = readq(&bar0->mc_rldram_test_ctrl);
5022 if (val64 & MC_RLDRAM_TEST_DONE)
5023 break;
5024 msleep(200);
5025 }
5026
5027 if (cnt == 5)
5028 break;
5029
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005030 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
5031 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032
5033 for (cnt = 0; cnt < 5; cnt++) {
5034 val64 = readq(&bar0->mc_rldram_test_ctrl);
5035 if (val64 & MC_RLDRAM_TEST_DONE)
5036 break;
5037 msleep(500);
5038 }
5039
5040 if (cnt == 5)
5041 break;
5042
5043 val64 = readq(&bar0->mc_rldram_test_ctrl);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005044 if (!(val64 & MC_RLDRAM_TEST_PASS))
5045 test_fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046
5047 iteration++;
5048 }
5049
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005050 *data = test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005052 /* Bring the adapter out of test mode */
5053 SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
5054
5055 return test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056}
5057
5058/**
5059 * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
5060 * @sp : private member of the device structure, which is a pointer to the
5061 * s2io_nic structure.
5062 * @ethtest : pointer to a ethtool command specific structure that will be
5063 * returned to the user.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005064 * @data : variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 * conducted by the driver.
5066 * Description:
5067 * This function conducts 6 tests ( 4 offline and 2 online) to determine
5068 * the health of the card.
5069 * Return value:
5070 * void
5071 */
5072
5073static void s2io_ethtool_test(struct net_device *dev,
5074 struct ethtool_test *ethtest,
5075 uint64_t * data)
5076{
5077 nic_t *sp = dev->priv;
5078 int orig_state = netif_running(sp->dev);
5079
5080 if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
5081 /* Offline Tests. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005082 if (orig_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 s2io_close(sp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084
5085 if (s2io_register_test(sp, &data[0]))
5086 ethtest->flags |= ETH_TEST_FL_FAILED;
5087
5088 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089
5090 if (s2io_rldram_test(sp, &data[3]))
5091 ethtest->flags |= ETH_TEST_FL_FAILED;
5092
5093 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094
5095 if (s2io_eeprom_test(sp, &data[1]))
5096 ethtest->flags |= ETH_TEST_FL_FAILED;
5097
5098 if (s2io_bist_test(sp, &data[4]))
5099 ethtest->flags |= ETH_TEST_FL_FAILED;
5100
5101 if (orig_state)
5102 s2io_open(sp->dev);
5103
5104 data[2] = 0;
5105 } else {
5106 /* Online Tests. */
5107 if (!orig_state) {
5108 DBG_PRINT(ERR_DBG,
5109 "%s: is not up, cannot run test\n",
5110 dev->name);
5111 data[0] = -1;
5112 data[1] = -1;
5113 data[2] = -1;
5114 data[3] = -1;
5115 data[4] = -1;
5116 }
5117
5118 if (s2io_link_test(sp, &data[2]))
5119 ethtest->flags |= ETH_TEST_FL_FAILED;
5120
5121 data[0] = 0;
5122 data[1] = 0;
5123 data[3] = 0;
5124 data[4] = 0;
5125 }
5126}
5127
5128static void s2io_get_ethtool_stats(struct net_device *dev,
5129 struct ethtool_stats *estats,
5130 u64 * tmp_stats)
5131{
5132 int i = 0;
5133 nic_t *sp = dev->priv;
5134 StatInfo_t *stat_info = sp->mac_control.stats_info;
Andrew Mortonfe931392006-02-03 01:45:12 -08005135 u64 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005137 s2io_updt_stats(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005138 tmp_stats[i++] =
5139 (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
5140 le32_to_cpu(stat_info->tmac_frms);
5141 tmp_stats[i++] =
5142 (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
5143 le32_to_cpu(stat_info->tmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005145 tmp_stats[i++] =
5146 (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
5147 le32_to_cpu(stat_info->tmac_mcst_frms);
5148 tmp_stats[i++] =
5149 (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
5150 le32_to_cpu(stat_info->tmac_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005152 tmp_stats[i++] =
5153 (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
5154 le32_to_cpu(stat_info->tmac_any_err_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005156 tmp_stats[i++] =
5157 (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
5158 le32_to_cpu(stat_info->tmac_vld_ip);
5159 tmp_stats[i++] =
5160 (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
5161 le32_to_cpu(stat_info->tmac_drop_ip);
5162 tmp_stats[i++] =
5163 (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
5164 le32_to_cpu(stat_info->tmac_icmp);
5165 tmp_stats[i++] =
5166 (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
5167 le32_to_cpu(stat_info->tmac_rst_tcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005169 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
5170 le32_to_cpu(stat_info->tmac_udp);
5171 tmp_stats[i++] =
5172 (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
5173 le32_to_cpu(stat_info->rmac_vld_frms);
5174 tmp_stats[i++] =
5175 (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
5176 le32_to_cpu(stat_info->rmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
5178 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005179 tmp_stats[i++] =
5180 (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
5181 le32_to_cpu(stat_info->rmac_vld_mcst_frms);
5182 tmp_stats[i++] =
5183 (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
5184 le32_to_cpu(stat_info->rmac_vld_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
5186 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
5187 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005188 tmp_stats[i++] =
5189 (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
5190 le32_to_cpu(stat_info->rmac_discarded_frms);
5191 tmp_stats[i++] =
5192 (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
5193 le32_to_cpu(stat_info->rmac_usized_frms);
5194 tmp_stats[i++] =
5195 (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
5196 le32_to_cpu(stat_info->rmac_osized_frms);
5197 tmp_stats[i++] =
5198 (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
5199 le32_to_cpu(stat_info->rmac_frag_frms);
5200 tmp_stats[i++] =
5201 (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
5202 le32_to_cpu(stat_info->rmac_jabber_frms);
5203 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
5204 le32_to_cpu(stat_info->rmac_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
5206 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005207 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
5208 le32_to_cpu(stat_info->rmac_drop_ip);
5209 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
5210 le32_to_cpu(stat_info->rmac_icmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005212 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
5213 le32_to_cpu(stat_info->rmac_udp);
5214 tmp_stats[i++] =
5215 (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
5216 le32_to_cpu(stat_info->rmac_err_drp_udp);
5217 tmp_stats[i++] =
5218 (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
5219 le32_to_cpu(stat_info->rmac_pause_cnt);
5220 tmp_stats[i++] =
5221 (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
5222 le32_to_cpu(stat_info->rmac_accepted_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005224 tmp_stats[i++] = 0;
5225 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
5226 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005227 tmp_stats[i++] = stat_info->sw_stat.clubbed_frms_cnt;
5228 tmp_stats[i++] = stat_info->sw_stat.sending_both;
5229 tmp_stats[i++] = stat_info->sw_stat.outof_sequence_pkts;
5230 tmp_stats[i++] = stat_info->sw_stat.flush_max_pkts;
Andrew Mortonfe931392006-02-03 01:45:12 -08005231 tmp = 0;
5232 if (stat_info->sw_stat.num_aggregations) {
5233 tmp = stat_info->sw_stat.sum_avg_pkts_aggregated;
5234 do_div(tmp, stat_info->sw_stat.num_aggregations);
5235 }
5236 tmp_stats[i++] = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237}
5238
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005239static int s2io_ethtool_get_regs_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240{
5241 return (XENA_REG_SPACE);
5242}
5243
5244
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005245static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246{
5247 nic_t *sp = dev->priv;
5248
5249 return (sp->rx_csum);
5250}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005251
5252static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253{
5254 nic_t *sp = dev->priv;
5255
5256 if (data)
5257 sp->rx_csum = 1;
5258 else
5259 sp->rx_csum = 0;
5260
5261 return 0;
5262}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005263
5264static int s2io_get_eeprom_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265{
5266 return (XENA_EEPROM_SPACE);
5267}
5268
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005269static int s2io_ethtool_self_test_count(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270{
5271 return (S2IO_TEST_LEN);
5272}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005273
5274static void s2io_ethtool_get_strings(struct net_device *dev,
5275 u32 stringset, u8 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276{
5277 switch (stringset) {
5278 case ETH_SS_TEST:
5279 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
5280 break;
5281 case ETH_SS_STATS:
5282 memcpy(data, &ethtool_stats_keys,
5283 sizeof(ethtool_stats_keys));
5284 }
5285}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286static int s2io_ethtool_get_stats_count(struct net_device *dev)
5287{
5288 return (S2IO_STAT_LEN);
5289}
5290
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005291static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292{
5293 if (data)
5294 dev->features |= NETIF_F_IP_CSUM;
5295 else
5296 dev->features &= ~NETIF_F_IP_CSUM;
5297
5298 return 0;
5299}
5300
5301
5302static struct ethtool_ops netdev_ethtool_ops = {
5303 .get_settings = s2io_ethtool_gset,
5304 .set_settings = s2io_ethtool_sset,
5305 .get_drvinfo = s2io_ethtool_gdrvinfo,
5306 .get_regs_len = s2io_ethtool_get_regs_len,
5307 .get_regs = s2io_ethtool_gregs,
5308 .get_link = ethtool_op_get_link,
5309 .get_eeprom_len = s2io_get_eeprom_len,
5310 .get_eeprom = s2io_ethtool_geeprom,
5311 .set_eeprom = s2io_ethtool_seeprom,
5312 .get_pauseparam = s2io_ethtool_getpause_data,
5313 .set_pauseparam = s2io_ethtool_setpause_data,
5314 .get_rx_csum = s2io_ethtool_get_rx_csum,
5315 .set_rx_csum = s2io_ethtool_set_rx_csum,
5316 .get_tx_csum = ethtool_op_get_tx_csum,
5317 .set_tx_csum = s2io_ethtool_op_set_tx_csum,
5318 .get_sg = ethtool_op_get_sg,
5319 .set_sg = ethtool_op_set_sg,
5320#ifdef NETIF_F_TSO
5321 .get_tso = ethtool_op_get_tso,
5322 .set_tso = ethtool_op_set_tso,
5323#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05005324 .get_ufo = ethtool_op_get_ufo,
5325 .set_ufo = ethtool_op_set_ufo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326 .self_test_count = s2io_ethtool_self_test_count,
5327 .self_test = s2io_ethtool_test,
5328 .get_strings = s2io_ethtool_get_strings,
5329 .phys_id = s2io_ethtool_idnic,
5330 .get_stats_count = s2io_ethtool_get_stats_count,
5331 .get_ethtool_stats = s2io_get_ethtool_stats
5332};
5333
5334/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005335 * s2io_ioctl - Entry point for the Ioctl
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 * @dev : Device pointer.
5337 * @ifr : An IOCTL specefic structure, that can contain a pointer to
5338 * a proprietary structure used to pass information to the driver.
5339 * @cmd : This is used to distinguish between the different commands that
5340 * can be passed to the IOCTL functions.
5341 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005342 * Currently there are no special functionality supported in IOCTL, hence
5343 * function always return EOPNOTSUPPORTED
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 */
5345
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005346static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347{
5348 return -EOPNOTSUPP;
5349}
5350
5351/**
5352 * s2io_change_mtu - entry point to change MTU size for the device.
5353 * @dev : device pointer.
5354 * @new_mtu : the new MTU size for the device.
5355 * Description: A driver entry point to change MTU size for the device.
5356 * Before changing the MTU the device must be stopped.
5357 * Return value:
5358 * 0 on success and an appropriate (-)ve integer as defined in errno.h
5359 * file on failure.
5360 */
5361
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005362static int s2io_change_mtu(struct net_device *dev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363{
5364 nic_t *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365
5366 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
5367 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
5368 dev->name);
5369 return -EPERM;
5370 }
5371
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372 dev->mtu = new_mtu;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07005373 if (netif_running(dev)) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04005374 s2io_card_down(sp, 0);
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07005375 netif_stop_queue(dev);
5376 if (s2io_card_up(sp)) {
5377 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
5378 __FUNCTION__);
5379 }
5380 if (netif_queue_stopped(dev))
5381 netif_wake_queue(dev);
5382 } else { /* Device is down */
5383 XENA_dev_config_t __iomem *bar0 = sp->bar0;
5384 u64 val64 = new_mtu;
5385
5386 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
5387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388
5389 return 0;
5390}
5391
5392/**
5393 * s2io_tasklet - Bottom half of the ISR.
5394 * @dev_adr : address of the device structure in dma_addr_t format.
5395 * Description:
5396 * This is the tasklet or the bottom half of the ISR. This is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005397 * an extension of the ISR which is scheduled by the scheduler to be run
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 * 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 -07005399 * be pushed into the tasklet. For now the tasklet is used only to
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400 * replenish the Rx buffers in the Rx buffer descriptors.
5401 * Return value:
5402 * void.
5403 */
5404
5405static void s2io_tasklet(unsigned long dev_addr)
5406{
5407 struct net_device *dev = (struct net_device *) dev_addr;
5408 nic_t *sp = dev->priv;
5409 int i, ret;
5410 mac_info_t *mac_control;
5411 struct config_param *config;
5412
5413 mac_control = &sp->mac_control;
5414 config = &sp->config;
5415
5416 if (!TASKLET_IN_USE) {
5417 for (i = 0; i < config->rx_ring_num; i++) {
5418 ret = fill_rx_buffers(sp, i);
5419 if (ret == -ENOMEM) {
5420 DBG_PRINT(ERR_DBG, "%s: Out of ",
5421 dev->name);
5422 DBG_PRINT(ERR_DBG, "memory in tasklet\n");
5423 break;
5424 } else if (ret == -EFILL) {
5425 DBG_PRINT(ERR_DBG,
5426 "%s: Rx Ring %d is full\n",
5427 dev->name, i);
5428 break;
5429 }
5430 }
5431 clear_bit(0, (&sp->tasklet_status));
5432 }
5433}
5434
5435/**
5436 * s2io_set_link - Set the LInk status
5437 * @data: long pointer to device private structue
5438 * Description: Sets the link status for the adapter
5439 */
5440
5441static void s2io_set_link(unsigned long data)
5442{
5443 nic_t *nic = (nic_t *) data;
5444 struct net_device *dev = nic->dev;
5445 XENA_dev_config_t __iomem *bar0 = nic->bar0;
5446 register u64 val64;
5447 u16 subid;
5448
5449 if (test_and_set_bit(0, &(nic->link_state))) {
5450 /* The card is being reset, no point doing anything */
5451 return;
5452 }
5453
5454 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07005455 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
5456 /*
5457 * Allow a small delay for the NICs self initiated
5458 * cleanup to complete.
5459 */
5460 msleep(100);
5461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
5463 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005464 if (verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465 if (LINK_IS_UP(val64)) {
5466 val64 = readq(&bar0->adapter_control);
5467 val64 |= ADAPTER_CNTL_EN;
5468 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005469 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
5470 subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471 val64 = readq(&bar0->gpio_control);
5472 val64 |= GPIO_CTRL_GPIO_0;
5473 writeq(val64, &bar0->gpio_control);
5474 val64 = readq(&bar0->gpio_control);
5475 } else {
5476 val64 |= ADAPTER_LED_ON;
5477 writeq(val64, &bar0->adapter_control);
5478 }
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07005479 if (s2io_link_fault_indication(nic) ==
5480 MAC_RMAC_ERR_TIMER) {
5481 val64 = readq(&bar0->adapter_status);
5482 if (!LINK_IS_UP(val64)) {
5483 DBG_PRINT(ERR_DBG, "%s:", dev->name);
5484 DBG_PRINT(ERR_DBG, " Link down");
5485 DBG_PRINT(ERR_DBG, "after ");
5486 DBG_PRINT(ERR_DBG, "enabling ");
5487 DBG_PRINT(ERR_DBG, "device \n");
5488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 }
5490 if (nic->device_enabled_once == FALSE) {
5491 nic->device_enabled_once = TRUE;
5492 }
5493 s2io_link(nic, LINK_UP);
5494 } else {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005495 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
5496 subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497 val64 = readq(&bar0->gpio_control);
5498 val64 &= ~GPIO_CTRL_GPIO_0;
5499 writeq(val64, &bar0->gpio_control);
5500 val64 = readq(&bar0->gpio_control);
5501 }
5502 s2io_link(nic, LINK_DOWN);
5503 }
5504 } else { /* NIC is not Quiescent. */
5505 DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
5506 DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
5507 netif_stop_queue(dev);
5508 }
5509 clear_bit(0, &(nic->link_state));
5510}
5511
Ananda Rajuc92ca042006-04-21 19:18:03 -04005512static void s2io_card_down(nic_t * sp, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513{
5514 int cnt = 0;
5515 XENA_dev_config_t __iomem *bar0 = sp->bar0;
5516 unsigned long flags;
5517 register u64 val64 = 0;
Ananda Rajuc92ca042006-04-21 19:18:03 -04005518 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07005520 del_timer_sync(&sp->alarm_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521 /* If s2io_set_link task is executing, wait till it completes. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005522 while (test_and_set_bit(0, &(sp->link_state))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005523 msleep(50);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525 atomic_set(&sp->card_state, CARD_DOWN);
5526
5527 /* disable Tx and Rx traffic on the NIC */
5528 stop_nic(sp);
Ananda Rajuc92ca042006-04-21 19:18:03 -04005529 if (flag) {
5530 if (sp->intr_type == MSI_X) {
5531 int i;
5532 u16 msi_control;
5533
5534 for (i=1; (sp->s2io_entries[i].in_use ==
5535 MSIX_REGISTERED_SUCCESS); i++) {
5536 int vector = sp->entries[i].vector;
5537 void *arg = sp->s2io_entries[i].arg;
5538
5539 free_irq(vector, arg);
5540 }
5541 pci_read_config_word(sp->pdev, 0x42, &msi_control);
5542 msi_control &= 0xFFFE; /* Disable MSI */
5543 pci_write_config_word(sp->pdev, 0x42, msi_control);
5544 pci_disable_msix(sp->pdev);
5545 } else {
5546 free_irq(sp->pdev->irq, dev);
5547 if (sp->intr_type == MSI)
5548 pci_disable_msi(sp->pdev);
5549 }
5550 }
5551 /* Waiting till all Interrupt handlers are complete */
5552 cnt = 0;
5553 do {
5554 msleep(10);
5555 if (!atomic_read(&sp->isr_cnt))
5556 break;
5557 cnt++;
5558 } while(cnt < 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559
5560 /* Kill tasklet. */
5561 tasklet_kill(&sp->task);
5562
5563 /* Check if the device is Quiescent and then Reset the NIC */
5564 do {
5565 val64 = readq(&bar0->adapter_status);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005566 if (verify_xena_quiescence(sp, val64, sp->device_enabled_once)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 break;
5568 }
5569
5570 msleep(50);
5571 cnt++;
5572 if (cnt == 10) {
5573 DBG_PRINT(ERR_DBG,
5574 "s2io_close:Device not Quiescent ");
5575 DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
5576 (unsigned long long) val64);
5577 break;
5578 }
5579 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 s2io_reset(sp);
5581
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005582 spin_lock_irqsave(&sp->tx_lock, flags);
5583 /* Free all Tx buffers */
5584 free_tx_buffers(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005586
5587 /* Free all Rx buffers */
5588 spin_lock_irqsave(&sp->rx_lock, flags);
5589 free_rx_buffers(sp);
5590 spin_unlock_irqrestore(&sp->rx_lock, flags);
5591
Linus Torvalds1da177e2005-04-16 15:20:36 -07005592 clear_bit(0, &(sp->link_state));
5593}
5594
5595static int s2io_card_up(nic_t * sp)
5596{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005597 int i, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598 mac_info_t *mac_control;
5599 struct config_param *config;
5600 struct net_device *dev = (struct net_device *) sp->dev;
5601
5602 /* Initialize the H/W I/O registers */
5603 if (init_nic(sp) != 0) {
5604 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
5605 dev->name);
5606 return -ENODEV;
5607 }
5608
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04005609 if (sp->intr_type == MSI)
5610 ret = s2io_enable_msi(sp);
5611 else if (sp->intr_type == MSI_X)
5612 ret = s2io_enable_msi_x(sp);
5613 if (ret) {
5614 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
5615 sp->intr_type = INTA;
5616 }
5617
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005618 /*
5619 * Initializing the Rx buffers. For now we are considering only 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620 * Rx ring and initializing buffers into 30 Rx blocks
5621 */
5622 mac_control = &sp->mac_control;
5623 config = &sp->config;
5624
5625 for (i = 0; i < config->rx_ring_num; i++) {
5626 if ((ret = fill_rx_buffers(sp, i))) {
5627 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
5628 dev->name);
5629 s2io_reset(sp);
5630 free_rx_buffers(sp);
5631 return -ENOMEM;
5632 }
5633 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
5634 atomic_read(&sp->rx_bufs_left[i]));
5635 }
5636
5637 /* Setting its receive mode */
5638 s2io_set_multicast(dev);
5639
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005640 if (sp->lro) {
5641 /* Initialize max aggregatable pkts based on MTU */
5642 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
5643 /* Check if we can use(if specified) user provided value */
5644 if (lro_max_pkts < sp->lro_max_aggr_per_sess)
5645 sp->lro_max_aggr_per_sess = lro_max_pkts;
5646 }
5647
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648 /* Enable tasklet for the device */
5649 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
5650
5651 /* Enable Rx Traffic and interrupts on the NIC */
5652 if (start_nic(sp)) {
5653 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
5654 tasklet_kill(&sp->task);
5655 s2io_reset(sp);
5656 free_irq(dev->irq, dev);
5657 free_rx_buffers(sp);
5658 return -ENODEV;
5659 }
5660
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07005661 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
5662
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663 atomic_set(&sp->card_state, CARD_UP);
5664 return 0;
5665}
5666
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005667/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 * s2io_restart_nic - Resets the NIC.
5669 * @data : long pointer to the device private structure
5670 * Description:
5671 * This function is scheduled to be run by the s2io_tx_watchdog
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005672 * function after 0.5 secs to reset the NIC. The idea is to reduce
Linus Torvalds1da177e2005-04-16 15:20:36 -07005673 * the run time of the watch dog routine which is run holding a
5674 * spin lock.
5675 */
5676
5677static void s2io_restart_nic(unsigned long data)
5678{
5679 struct net_device *dev = (struct net_device *) data;
5680 nic_t *sp = dev->priv;
5681
Ananda Rajuc92ca042006-04-21 19:18:03 -04005682 s2io_card_down(sp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005683 if (s2io_card_up(sp)) {
5684 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
5685 dev->name);
5686 }
5687 netif_wake_queue(dev);
5688 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
5689 dev->name);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005690
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691}
5692
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005693/**
5694 * s2io_tx_watchdog - Watchdog for transmit side.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 * @dev : Pointer to net device structure
5696 * Description:
5697 * This function is triggered if the Tx Queue is stopped
5698 * for a pre-defined amount of time when the Interface is still up.
5699 * If the Interface is jammed in such a situation, the hardware is
5700 * reset (by s2io_close) and restarted again (by s2io_open) to
5701 * overcome any problem that might have been caused in the hardware.
5702 * Return value:
5703 * void
5704 */
5705
5706static void s2io_tx_watchdog(struct net_device *dev)
5707{
5708 nic_t *sp = dev->priv;
5709
5710 if (netif_carrier_ok(dev)) {
5711 schedule_work(&sp->rst_timer_task);
5712 }
5713}
5714
5715/**
5716 * rx_osm_handler - To perform some OS related operations on SKB.
5717 * @sp: private member of the device structure,pointer to s2io_nic structure.
5718 * @skb : the socket buffer pointer.
5719 * @len : length of the packet
5720 * @cksum : FCS checksum of the frame.
5721 * @ring_no : the ring from which this RxD was extracted.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005722 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 * This function is called by the Tx interrupt serivce routine to perform
5724 * some OS related operations on the SKB before passing it to the upper
5725 * layers. It mainly checks if the checksum is OK, if so adds it to the
5726 * SKBs cksum variable, increments the Rx packet count and passes the SKB
5727 * to the upper layer. If the checksum is wrong, it increments the Rx
5728 * packet error count, frees the SKB and returns error.
5729 * Return value:
5730 * SUCCESS on success and -1 on failure.
5731 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005732static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005734 nic_t *sp = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735 struct net_device *dev = (struct net_device *) sp->dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005736 struct sk_buff *skb = (struct sk_buff *)
5737 ((unsigned long) rxdp->Host_Control);
5738 int ring_no = ring_data->ring_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739 u16 l3_csum, l4_csum;
Ananda Raju863c11a2006-04-21 19:03:13 -04005740 unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005741 lro_t *lro;
Ananda Rajuda6971d2005-10-31 16:55:31 -05005742
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005743 skb->dev = dev;
Ananda Rajuc92ca042006-04-21 19:18:03 -04005744
Ananda Raju863c11a2006-04-21 19:03:13 -04005745 if (err) {
5746 /*
5747 * Drop the packet if bad transfer code. Exception being
5748 * 0x5, which could be due to unsupported IPv6 extension header.
5749 * In this case, we let stack handle the packet.
5750 * Note that in this case, since checksum will be incorrect,
5751 * stack will validate the same.
5752 */
5753 if (err && ((err >> 48) != 0x5)) {
5754 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
5755 dev->name, err);
5756 sp->stats.rx_crc_errors++;
5757 dev_kfree_skb(skb);
5758 atomic_dec(&sp->rx_bufs_left[ring_no]);
5759 rxdp->Host_Control = 0;
5760 return 0;
5761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005764 /* Updating statistics */
5765 rxdp->Host_Control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766 sp->rx_pkt_count++;
5767 sp->stats.rx_packets++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05005768 if (sp->rxd_mode == RXD_MODE_1) {
5769 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770
Ananda Rajuda6971d2005-10-31 16:55:31 -05005771 sp->stats.rx_bytes += len;
5772 skb_put(skb, len);
5773
5774 } else if (sp->rxd_mode >= RXD_MODE_3A) {
5775 int get_block = ring_data->rx_curr_get_info.block_index;
5776 int get_off = ring_data->rx_curr_get_info.offset;
5777 int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
5778 int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
5779 unsigned char *buff = skb_push(skb, buf0_len);
5780
5781 buffAdd_t *ba = &ring_data->ba[get_block][get_off];
5782 sp->stats.rx_bytes += buf0_len + buf2_len;
5783 memcpy(buff, ba->ba_0, buf0_len);
5784
5785 if (sp->rxd_mode == RXD_MODE_3A) {
5786 int buf1_len = RXD_GET_BUFFER1_SIZE_3(rxdp->Control_2);
5787
5788 skb_put(skb, buf1_len);
5789 skb->len += buf2_len;
5790 skb->data_len += buf2_len;
5791 skb->truesize += buf2_len;
5792 skb_put(skb_shinfo(skb)->frag_list, buf2_len);
5793 sp->stats.rx_bytes += buf1_len;
5794
5795 } else
5796 skb_put(skb, buf2_len);
5797 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005798
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005799 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!sp->lro) ||
5800 (sp->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005801 (sp->rx_csum)) {
5802 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
5803 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
5804 if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
5805 /*
5806 * NIC verifies if the Checksum of the received
5807 * frame is Ok or not and accordingly returns
5808 * a flag in the RxD.
5809 */
5810 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005811 if (sp->lro) {
5812 u32 tcp_len;
5813 u8 *tcp;
5814 int ret = 0;
5815
5816 ret = s2io_club_tcp_session(skb->data, &tcp,
5817 &tcp_len, &lro, rxdp, sp);
5818 switch (ret) {
5819 case 3: /* Begin anew */
5820 lro->parent = skb;
5821 goto aggregate;
5822 case 1: /* Aggregate */
5823 {
5824 lro_append_pkt(sp, lro,
5825 skb, tcp_len);
5826 goto aggregate;
5827 }
5828 case 4: /* Flush session */
5829 {
5830 lro_append_pkt(sp, lro,
5831 skb, tcp_len);
5832 queue_rx_frame(lro->parent);
5833 clear_lro_session(lro);
5834 sp->mac_control.stats_info->
5835 sw_stat.flush_max_pkts++;
5836 goto aggregate;
5837 }
5838 case 2: /* Flush both */
5839 lro->parent->data_len =
5840 lro->frags_len;
5841 sp->mac_control.stats_info->
5842 sw_stat.sending_both++;
5843 queue_rx_frame(lro->parent);
5844 clear_lro_session(lro);
5845 goto send_up;
5846 case 0: /* sessions exceeded */
Ananda Rajuc92ca042006-04-21 19:18:03 -04005847 case -1: /* non-TCP or not
5848 * L2 aggregatable
5849 */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005850 case 5: /*
5851 * First pkt in session not
5852 * L3/L4 aggregatable
5853 */
5854 break;
5855 default:
5856 DBG_PRINT(ERR_DBG,
5857 "%s: Samadhana!!\n",
5858 __FUNCTION__);
5859 BUG();
5860 }
5861 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005862 } else {
5863 /*
5864 * Packet with erroneous checksum, let the
5865 * upper layers deal with it.
5866 */
5867 skb->ip_summed = CHECKSUM_NONE;
5868 }
5869 } else {
5870 skb->ip_summed = CHECKSUM_NONE;
5871 }
5872
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005873 if (!sp->lro) {
5874 skb->protocol = eth_type_trans(skb, dev);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005875#ifdef CONFIG_S2IO_NAPI
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005876 if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
5877 /* Queueing the vlan frame to the upper layer */
5878 vlan_hwaccel_receive_skb(skb, sp->vlgrp,
5879 RXD_GET_VLAN_TAG(rxdp->Control_2));
5880 } else {
5881 netif_receive_skb(skb);
5882 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005883#else
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005884 if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
5885 /* Queueing the vlan frame to the upper layer */
5886 vlan_hwaccel_rx(skb, sp->vlgrp,
5887 RXD_GET_VLAN_TAG(rxdp->Control_2));
5888 } else {
5889 netif_rx(skb);
5890 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005891#endif
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005892 } else {
5893send_up:
5894 queue_rx_frame(skb);
5895 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005896 dev->last_rx = jiffies;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005897aggregate:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 atomic_dec(&sp->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 return SUCCESS;
5900}
5901
5902/**
5903 * s2io_link - stops/starts the Tx queue.
5904 * @sp : private member of the device structure, which is a pointer to the
5905 * s2io_nic structure.
5906 * @link : inidicates whether link is UP/DOWN.
5907 * Description:
5908 * This function stops/starts the Tx queue depending on whether the link
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005909 * status of the NIC is is down or up. This is called by the Alarm
5910 * interrupt handler whenever a link change interrupt comes up.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005911 * Return value:
5912 * void.
5913 */
5914
Adrian Bunk26df54b2006-01-14 03:09:40 +01005915static void s2io_link(nic_t * sp, int link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916{
5917 struct net_device *dev = (struct net_device *) sp->dev;
5918
5919 if (link != sp->last_link_state) {
5920 if (link == LINK_DOWN) {
5921 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
5922 netif_carrier_off(dev);
5923 } else {
5924 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
5925 netif_carrier_on(dev);
5926 }
5927 }
5928 sp->last_link_state = link;
5929}
5930
5931/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005932 * get_xena_rev_id - to identify revision ID of xena.
5933 * @pdev : PCI Dev structure
5934 * Description:
5935 * Function to identify the Revision ID of xena.
5936 * Return value:
5937 * returns the revision ID of the device.
5938 */
5939
Adrian Bunk26df54b2006-01-14 03:09:40 +01005940static int get_xena_rev_id(struct pci_dev *pdev)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005941{
5942 u8 id = 0;
5943 int ret;
5944 ret = pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) & id);
5945 return id;
5946}
5947
5948/**
5949 * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
5950 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 * s2io_nic structure.
5952 * Description:
5953 * This function initializes a few of the PCI and PCI-X configuration registers
5954 * with recommended values.
5955 * Return value:
5956 * void
5957 */
5958
5959static void s2io_init_pci(nic_t * sp)
5960{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005961 u16 pci_cmd = 0, pcix_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962
5963 /* Enable Data Parity Error Recovery in PCI-X command register. */
5964 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005965 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005967 (pcix_cmd | 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005969 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970
5971 /* Set the PErr Response bit in PCI command register. */
5972 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
5973 pci_write_config_word(sp->pdev, PCI_COMMAND,
5974 (pci_cmd | PCI_COMMAND_PARITY));
5975 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976}
5977
5978MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
5979MODULE_LICENSE("GPL");
John Linville6c1792f2005-10-04 07:51:45 -04005980MODULE_VERSION(DRV_VERSION);
5981
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982module_param(tx_fifo_num, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983module_param(rx_ring_num, int, 0);
Ananda Rajuda6971d2005-10-31 16:55:31 -05005984module_param(rx_ring_mode, int, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005985module_param_array(tx_fifo_len, uint, NULL, 0);
5986module_param_array(rx_ring_sz, uint, NULL, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005987module_param_array(rts_frm_len, uint, NULL, 0);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07005988module_param(use_continuous_tx_intrs, int, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989module_param(rmac_pause_time, int, 0);
5990module_param(mc_pause_threshold_q0q3, int, 0);
5991module_param(mc_pause_threshold_q4q7, int, 0);
5992module_param(shared_splits, int, 0);
5993module_param(tmac_util_period, int, 0);
5994module_param(rmac_util_period, int, 0);
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07005995module_param(bimodal, bool, 0);
Ananda Rajuda6971d2005-10-31 16:55:31 -05005996module_param(l3l4hdr_size, int , 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997#ifndef CONFIG_S2IO_NAPI
5998module_param(indicate_max_pkts, int, 0);
5999#endif
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07006000module_param(rxsync_frequency, int, 0);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006001module_param(intr_type, int, 0);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006002module_param(lro, int, 0);
6003module_param(lro_max_pkts, int, 0);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006004
Ananda Raju9dc737a2006-04-21 19:05:41 -04006005static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
6006{
6007 if ( tx_fifo_num > 8) {
6008 DBG_PRINT(ERR_DBG, "s2io: Requested number of Tx fifos not "
6009 "supported\n");
6010 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Tx fifos\n");
6011 tx_fifo_num = 8;
6012 }
6013 if ( rx_ring_num > 8) {
6014 DBG_PRINT(ERR_DBG, "s2io: Requested number of Rx rings not "
6015 "supported\n");
6016 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Rx rings\n");
6017 rx_ring_num = 8;
6018 }
6019#ifdef CONFIG_S2IO_NAPI
6020 if (*dev_intr_type != INTA) {
6021 DBG_PRINT(ERR_DBG, "s2io: NAPI cannot be enabled when "
6022 "MSI/MSI-X is enabled. Defaulting to INTA\n");
6023 *dev_intr_type = INTA;
6024 }
6025#endif
6026#ifndef CONFIG_PCI_MSI
6027 if (*dev_intr_type != INTA) {
6028 DBG_PRINT(ERR_DBG, "s2io: This kernel does not support"
6029 "MSI/MSI-X. Defaulting to INTA\n");
6030 *dev_intr_type = INTA;
6031 }
6032#else
6033 if (*dev_intr_type > MSI_X) {
6034 DBG_PRINT(ERR_DBG, "s2io: Wrong intr_type requested. "
6035 "Defaulting to INTA\n");
6036 *dev_intr_type = INTA;
6037 }
6038#endif
6039 if ((*dev_intr_type == MSI_X) &&
6040 ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
6041 (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
6042 DBG_PRINT(ERR_DBG, "s2io: Xframe I does not support MSI_X. "
6043 "Defaulting to INTA\n");
6044 *dev_intr_type = INTA;
6045 }
6046 if (rx_ring_mode > 3) {
6047 DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
6048 DBG_PRINT(ERR_DBG, "s2io: Defaulting to 3-buffer mode\n");
6049 rx_ring_mode = 3;
6050 }
6051 return SUCCESS;
6052}
6053
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006055 * s2io_init_nic - Initialization of the adapter .
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 * @pdev : structure containing the PCI related information of the device.
6057 * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
6058 * Description:
6059 * The function initializes an adapter identified by the pci_dec structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006060 * All OS related initialization including memory and device structure and
6061 * initlaization of the device private variable is done. Also the swapper
6062 * control register is initialized to enable read and write into the I/O
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 * registers of the device.
6064 * Return value:
6065 * returns 0 on success and negative on failure.
6066 */
6067
6068static int __devinit
6069s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
6070{
6071 nic_t *sp;
6072 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 int i, j, ret;
6074 int dma_flag = FALSE;
6075 u32 mac_up, mac_down;
6076 u64 val64 = 0, tmp64 = 0;
6077 XENA_dev_config_t __iomem *bar0 = NULL;
6078 u16 subid;
6079 mac_info_t *mac_control;
6080 struct config_param *config;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006081 int mode;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006082 u8 dev_intr_type = intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083
Ananda Raju9dc737a2006-04-21 19:05:41 -04006084 if ((ret = s2io_verify_parm(pdev, &dev_intr_type)))
6085 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086
6087 if ((ret = pci_enable_device(pdev))) {
6088 DBG_PRINT(ERR_DBG,
6089 "s2io_init_nic: pci_enable_device failed\n");
6090 return ret;
6091 }
6092
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006093 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
6095 dma_flag = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 if (pci_set_consistent_dma_mask
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006097 (pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 DBG_PRINT(ERR_DBG,
6099 "Unable to obtain 64bit DMA for \
6100 consistent allocations\n");
6101 pci_disable_device(pdev);
6102 return -ENOMEM;
6103 }
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04006104 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
6106 } else {
6107 pci_disable_device(pdev);
6108 return -ENOMEM;
6109 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006110 if (dev_intr_type != MSI_X) {
6111 if (pci_request_regions(pdev, s2io_driver_name)) {
6112 DBG_PRINT(ERR_DBG, "Request Regions failed\n"),
6113 pci_disable_device(pdev);
6114 return -ENODEV;
6115 }
6116 }
6117 else {
6118 if (!(request_mem_region(pci_resource_start(pdev, 0),
6119 pci_resource_len(pdev, 0), s2io_driver_name))) {
6120 DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
6121 pci_disable_device(pdev);
6122 return -ENODEV;
6123 }
6124 if (!(request_mem_region(pci_resource_start(pdev, 2),
6125 pci_resource_len(pdev, 2), s2io_driver_name))) {
6126 DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
6127 release_mem_region(pci_resource_start(pdev, 0),
6128 pci_resource_len(pdev, 0));
6129 pci_disable_device(pdev);
6130 return -ENODEV;
6131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 }
6133
6134 dev = alloc_etherdev(sizeof(nic_t));
6135 if (dev == NULL) {
6136 DBG_PRINT(ERR_DBG, "Device allocation failed\n");
6137 pci_disable_device(pdev);
6138 pci_release_regions(pdev);
6139 return -ENODEV;
6140 }
6141
6142 pci_set_master(pdev);
6143 pci_set_drvdata(pdev, dev);
6144 SET_MODULE_OWNER(dev);
6145 SET_NETDEV_DEV(dev, &pdev->dev);
6146
6147 /* Private member variable initialized to s2io NIC structure */
6148 sp = dev->priv;
6149 memset(sp, 0, sizeof(nic_t));
6150 sp->dev = dev;
6151 sp->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 sp->high_dma_flag = dma_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 sp->device_enabled_once = FALSE;
Ananda Rajuda6971d2005-10-31 16:55:31 -05006154 if (rx_ring_mode == 1)
6155 sp->rxd_mode = RXD_MODE_1;
6156 if (rx_ring_mode == 2)
6157 sp->rxd_mode = RXD_MODE_3B;
6158 if (rx_ring_mode == 3)
6159 sp->rxd_mode = RXD_MODE_3A;
6160
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006161 sp->intr_type = dev_intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006163 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
6164 (pdev->device == PCI_DEVICE_ID_HERC_UNI))
6165 sp->device_type = XFRAME_II_DEVICE;
6166 else
6167 sp->device_type = XFRAME_I_DEVICE;
6168
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006169 sp->lro = lro;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006170
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 /* Initialize some PCI/PCI-X fields of the NIC. */
6172 s2io_init_pci(sp);
6173
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006174 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175 * Setting the device configuration parameters.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006176 * Most of these parameters can be specified by the user during
6177 * module insertion as they are module loadable parameters. If
6178 * these parameters are not not specified during load time, they
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 * are initialized with default values.
6180 */
6181 mac_control = &sp->mac_control;
6182 config = &sp->config;
6183
6184 /* Tx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 config->tx_fifo_num = tx_fifo_num;
6186 for (i = 0; i < MAX_TX_FIFOS; i++) {
6187 config->tx_cfg[i].fifo_len = tx_fifo_len[i];
6188 config->tx_cfg[i].fifo_priority = i;
6189 }
6190
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006191 /* mapping the QoS priority to the configured fifos */
6192 for (i = 0; i < MAX_TX_FIFOS; i++)
6193 config->fifo_mapping[i] = fifo_map[config->tx_fifo_num][i];
6194
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 config->tx_intr_type = TXD_INT_TYPE_UTILZ;
6196 for (i = 0; i < config->tx_fifo_num; i++) {
6197 config->tx_cfg[i].f_no_snoop =
6198 (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
6199 if (config->tx_cfg[i].fifo_len < 65) {
6200 config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
6201 break;
6202 }
6203 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006204 /* + 2 because one Txd for skb->data and one Txd for UFO */
6205 config->max_txds = MAX_SKB_FRAGS + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206
6207 /* Rx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 config->rx_ring_num = rx_ring_num;
6209 for (i = 0; i < MAX_RX_RINGS; i++) {
6210 config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
Ananda Rajuda6971d2005-10-31 16:55:31 -05006211 (rxd_count[sp->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 config->rx_cfg[i].ring_priority = i;
6213 }
6214
6215 for (i = 0; i < rx_ring_num; i++) {
6216 config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
6217 config->rx_cfg[i].f_no_snoop =
6218 (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
6219 }
6220
6221 /* Setting Mac Control parameters */
6222 mac_control->rmac_pause_time = rmac_pause_time;
6223 mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
6224 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
6225
6226
6227 /* Initialize Ring buffer parameters. */
6228 for (i = 0; i < config->rx_ring_num; i++)
6229 atomic_set(&sp->rx_bufs_left[i], 0);
6230
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006231 /* Initialize the number of ISRs currently running */
6232 atomic_set(&sp->isr_cnt, 0);
6233
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234 /* initialize the shared memory used by the NIC and the host */
6235 if (init_shared_mem(sp)) {
6236 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006237 __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 ret = -ENOMEM;
6239 goto mem_alloc_failed;
6240 }
6241
6242 sp->bar0 = ioremap(pci_resource_start(pdev, 0),
6243 pci_resource_len(pdev, 0));
6244 if (!sp->bar0) {
6245 DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",
6246 dev->name);
6247 ret = -ENOMEM;
6248 goto bar0_remap_failed;
6249 }
6250
6251 sp->bar1 = ioremap(pci_resource_start(pdev, 2),
6252 pci_resource_len(pdev, 2));
6253 if (!sp->bar1) {
6254 DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",
6255 dev->name);
6256 ret = -ENOMEM;
6257 goto bar1_remap_failed;
6258 }
6259
6260 dev->irq = pdev->irq;
6261 dev->base_addr = (unsigned long) sp->bar0;
6262
6263 /* Initializing the BAR1 address as the start of the FIFO pointer. */
6264 for (j = 0; j < MAX_TX_FIFOS; j++) {
6265 mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)
6266 (sp->bar1 + (j * 0x00020000));
6267 }
6268
6269 /* Driver entry points */
6270 dev->open = &s2io_open;
6271 dev->stop = &s2io_close;
6272 dev->hard_start_xmit = &s2io_xmit;
6273 dev->get_stats = &s2io_get_stats;
6274 dev->set_multicast_list = &s2io_set_multicast;
6275 dev->do_ioctl = &s2io_ioctl;
6276 dev->change_mtu = &s2io_change_mtu;
6277 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07006278 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6279 dev->vlan_rx_register = s2io_vlan_rx_register;
6280 dev->vlan_rx_kill_vid = (void *)s2io_vlan_rx_kill_vid;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006281
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 /*
6283 * will use eth_mac_addr() for dev->set_mac_address
6284 * mac address will be set every time dev->open() is called
6285 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006286#if defined(CONFIG_S2IO_NAPI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 dev->poll = s2io_poll;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006288 dev->weight = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289#endif
6290
6291 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
6292 if (sp->high_dma_flag == TRUE)
6293 dev->features |= NETIF_F_HIGHDMA;
6294#ifdef NETIF_F_TSO
6295 dev->features |= NETIF_F_TSO;
6296#endif
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006297 if (sp->device_type & XFRAME_II_DEVICE) {
6298 dev->features |= NETIF_F_UFO;
6299 dev->features |= NETIF_F_HW_CSUM;
6300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301
6302 dev->tx_timeout = &s2io_tx_watchdog;
6303 dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
6304 INIT_WORK(&sp->rst_timer_task,
6305 (void (*)(void *)) s2io_restart_nic, dev);
6306 INIT_WORK(&sp->set_link_task,
6307 (void (*)(void *)) s2io_set_link, sp);
6308
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07006309 pci_save_state(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310
6311 /* Setting swapper control on the NIC, for proper reset operation */
6312 if (s2io_set_swapper(sp)) {
6313 DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
6314 dev->name);
6315 ret = -EAGAIN;
6316 goto set_swap_failed;
6317 }
6318
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006319 /* Verify if the Herc works on the slot its placed into */
6320 if (sp->device_type & XFRAME_II_DEVICE) {
6321 mode = s2io_verify_pci_mode(sp);
6322 if (mode < 0) {
6323 DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);
6324 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
6325 ret = -EBADSLT;
6326 goto set_swap_failed;
6327 }
6328 }
6329
6330 /* Not needed for Herc */
6331 if (sp->device_type & XFRAME_I_DEVICE) {
6332 /*
6333 * Fix for all "FFs" MAC address problems observed on
6334 * Alpha platforms
6335 */
6336 fix_mac_address(sp);
6337 s2io_reset(sp);
6338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339
6340 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 * MAC address initialization.
6342 * For now only one mac address will be read and used.
6343 */
6344 bar0 = sp->bar0;
6345 val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
6346 RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
6347 writeq(val64, &bar0->rmac_addr_cmd_mem);
Ananda Rajuc92ca042006-04-21 19:18:03 -04006348 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
6349 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 tmp64 = readq(&bar0->rmac_addr_data0_mem);
6351 mac_down = (u32) tmp64;
6352 mac_up = (u32) (tmp64 >> 32);
6353
6354 memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
6355
6356 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
6357 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
6358 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
6359 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
6360 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
6361 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
6362
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 /* Set the factory defined MAC address initially */
6364 dev->addr_len = ETH_ALEN;
6365 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
6366
6367 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006368 * Initialize the tasklet status and link state flags
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006369 * and the card state parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 */
6371 atomic_set(&(sp->card_state), 0);
6372 sp->tasklet_status = 0;
6373 sp->link_state = 0;
6374
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 /* Initialize spinlocks */
6376 spin_lock_init(&sp->tx_lock);
6377#ifndef CONFIG_S2IO_NAPI
6378 spin_lock_init(&sp->put_lock);
6379#endif
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006380 spin_lock_init(&sp->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006382 /*
6383 * SXE-002: Configure link and activity LED to init state
6384 * on driver load.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385 */
6386 subid = sp->pdev->subsystem_device;
6387 if ((subid & 0xFF) >= 0x07) {
6388 val64 = readq(&bar0->gpio_control);
6389 val64 |= 0x0000800000000000ULL;
6390 writeq(val64, &bar0->gpio_control);
6391 val64 = 0x0411040400000000ULL;
6392 writeq(val64, (void __iomem *) bar0 + 0x2700);
6393 val64 = readq(&bar0->gpio_control);
6394 }
6395
6396 sp->rx_csum = 1; /* Rx chksum verify enabled by default */
6397
6398 if (register_netdev(dev)) {
6399 DBG_PRINT(ERR_DBG, "Device registration failed\n");
6400 ret = -ENODEV;
6401 goto register_failed;
6402 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04006403 s2io_vpd_read(sp);
6404 DBG_PRINT(ERR_DBG, "%s: Neterion %s",dev->name, sp->product_name);
6405 DBG_PRINT(ERR_DBG, "(rev %d), Driver version %s\n",
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006406 get_xena_rev_id(sp->pdev),
6407 s2io_driver_version);
Ananda Raju9dc737a2006-04-21 19:05:41 -04006408 DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2005 Neterion Inc.\n");
6409 DBG_PRINT(ERR_DBG, "%s: MAC ADDR: "
6410 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006411 sp->def_mac_addr[0].mac_addr[0],
6412 sp->def_mac_addr[0].mac_addr[1],
6413 sp->def_mac_addr[0].mac_addr[2],
6414 sp->def_mac_addr[0].mac_addr[3],
6415 sp->def_mac_addr[0].mac_addr[4],
6416 sp->def_mac_addr[0].mac_addr[5]);
Ananda Raju9dc737a2006-04-21 19:05:41 -04006417 if (sp->device_type & XFRAME_II_DEVICE) {
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07006418 mode = s2io_print_pci_mode(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006419 if (mode < 0) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04006420 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006421 ret = -EBADSLT;
Ananda Raju9dc737a2006-04-21 19:05:41 -04006422 unregister_netdev(dev);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006423 goto set_swap_failed;
6424 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006425 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04006426 switch(sp->rxd_mode) {
6427 case RXD_MODE_1:
6428 DBG_PRINT(ERR_DBG, "%s: 1-Buffer receive mode enabled\n",
6429 dev->name);
6430 break;
6431 case RXD_MODE_3B:
6432 DBG_PRINT(ERR_DBG, "%s: 2-Buffer receive mode enabled\n",
6433 dev->name);
6434 break;
6435 case RXD_MODE_3A:
6436 DBG_PRINT(ERR_DBG, "%s: 3-Buffer receive mode enabled\n",
6437 dev->name);
6438 break;
6439 }
6440#ifdef CONFIG_S2IO_NAPI
6441 DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
6442#endif
6443 switch(sp->intr_type) {
6444 case INTA:
6445 DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
6446 break;
6447 case MSI:
6448 DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI\n", dev->name);
6449 break;
6450 case MSI_X:
6451 DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
6452 break;
6453 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006454 if (sp->lro)
6455 DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
Ananda Raju9dc737a2006-04-21 19:05:41 -04006456 dev->name);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006457
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006458 /* Initialize device name */
Ananda Raju9dc737a2006-04-21 19:05:41 -04006459 sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006460
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07006461 /* Initialize bimodal Interrupts */
6462 sp->config.bimodal = bimodal;
6463 if (!(sp->device_type & XFRAME_II_DEVICE) && bimodal) {
6464 sp->config.bimodal = 0;
6465 DBG_PRINT(ERR_DBG,"%s:Bimodal intr not supported by Xframe I\n",
6466 dev->name);
6467 }
6468
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006469 /*
6470 * Make Link state as off at this point, when the Link change
6471 * interrupt comes the state will be automatically changed to
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 * the right state.
6473 */
6474 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475
6476 return 0;
6477
6478 register_failed:
6479 set_swap_failed:
6480 iounmap(sp->bar1);
6481 bar1_remap_failed:
6482 iounmap(sp->bar0);
6483 bar0_remap_failed:
6484 mem_alloc_failed:
6485 free_shared_mem(sp);
6486 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006487 if (dev_intr_type != MSI_X)
6488 pci_release_regions(pdev);
6489 else {
6490 release_mem_region(pci_resource_start(pdev, 0),
6491 pci_resource_len(pdev, 0));
6492 release_mem_region(pci_resource_start(pdev, 2),
6493 pci_resource_len(pdev, 2));
6494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 pci_set_drvdata(pdev, NULL);
6496 free_netdev(dev);
6497
6498 return ret;
6499}
6500
6501/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006502 * s2io_rem_nic - Free the PCI device
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 * @pdev: structure containing the PCI related information of the device.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006504 * Description: This function is called by the Pci subsystem to release a
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505 * PCI device and free up all resource held up by the device. This could
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006506 * be in response to a Hot plug event or when the driver is to be removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 * from memory.
6508 */
6509
6510static void __devexit s2io_rem_nic(struct pci_dev *pdev)
6511{
6512 struct net_device *dev =
6513 (struct net_device *) pci_get_drvdata(pdev);
6514 nic_t *sp;
6515
6516 if (dev == NULL) {
6517 DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
6518 return;
6519 }
6520
6521 sp = dev->priv;
6522 unregister_netdev(dev);
6523
6524 free_shared_mem(sp);
6525 iounmap(sp->bar0);
6526 iounmap(sp->bar1);
6527 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006528 if (sp->intr_type != MSI_X)
6529 pci_release_regions(pdev);
6530 else {
6531 release_mem_region(pci_resource_start(pdev, 0),
6532 pci_resource_len(pdev, 0));
6533 release_mem_region(pci_resource_start(pdev, 2),
6534 pci_resource_len(pdev, 2));
6535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 free_netdev(dev);
6538}
6539
6540/**
6541 * s2io_starter - Entry point for the driver
6542 * Description: This function is the entry point for the driver. It verifies
6543 * the module loadable parameters and initializes PCI configuration space.
6544 */
6545
6546int __init s2io_starter(void)
6547{
6548 return pci_module_init(&s2io_driver);
6549}
6550
6551/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006552 * s2io_closer - Cleanup routine for the driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
6554 */
6555
Adrian Bunk26df54b2006-01-14 03:09:40 +01006556static void s2io_closer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557{
6558 pci_unregister_driver(&s2io_driver);
6559 DBG_PRINT(INIT_DBG, "cleanup done\n");
6560}
6561
6562module_init(s2io_starter);
6563module_exit(s2io_closer);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006564
6565static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
6566 struct tcphdr **tcp, RxD_t *rxdp)
6567{
6568 int ip_off;
6569 u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
6570
6571 if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
6572 DBG_PRINT(INIT_DBG,"%s: Non-TCP frames not supported for LRO\n",
6573 __FUNCTION__);
6574 return -1;
6575 }
6576
6577 /* TODO:
6578 * By default the VLAN field in the MAC is stripped by the card, if this
6579 * feature is turned off in rx_pa_cfg register, then the ip_off field
6580 * has to be shifted by a further 2 bytes
6581 */
6582 switch (l2_type) {
6583 case 0: /* DIX type */
6584 case 4: /* DIX type with VLAN */
6585 ip_off = HEADER_ETHERNET_II_802_3_SIZE;
6586 break;
6587 /* LLC, SNAP etc are considered non-mergeable */
6588 default:
6589 return -1;
6590 }
6591
6592 *ip = (struct iphdr *)((u8 *)buffer + ip_off);
6593 ip_len = (u8)((*ip)->ihl);
6594 ip_len <<= 2;
6595 *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
6596
6597 return 0;
6598}
6599
6600static int check_for_socket_match(lro_t *lro, struct iphdr *ip,
6601 struct tcphdr *tcp)
6602{
6603 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6604 if ((lro->iph->saddr != ip->saddr) || (lro->iph->daddr != ip->daddr) ||
6605 (lro->tcph->source != tcp->source) || (lro->tcph->dest != tcp->dest))
6606 return -1;
6607 return 0;
6608}
6609
6610static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
6611{
6612 return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
6613}
6614
6615static void initiate_new_session(lro_t *lro, u8 *l2h,
6616 struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len)
6617{
6618 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6619 lro->l2h = l2h;
6620 lro->iph = ip;
6621 lro->tcph = tcp;
6622 lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
6623 lro->tcp_ack = ntohl(tcp->ack_seq);
6624 lro->sg_num = 1;
6625 lro->total_len = ntohs(ip->tot_len);
6626 lro->frags_len = 0;
6627 /*
6628 * check if we saw TCP timestamp. Other consistency checks have
6629 * already been done.
6630 */
6631 if (tcp->doff == 8) {
6632 u32 *ptr;
6633 ptr = (u32 *)(tcp+1);
6634 lro->saw_ts = 1;
6635 lro->cur_tsval = *(ptr+1);
6636 lro->cur_tsecr = *(ptr+2);
6637 }
6638 lro->in_use = 1;
6639}
6640
6641static void update_L3L4_header(nic_t *sp, lro_t *lro)
6642{
6643 struct iphdr *ip = lro->iph;
6644 struct tcphdr *tcp = lro->tcph;
6645 u16 nchk;
6646 StatInfo_t *statinfo = sp->mac_control.stats_info;
6647 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6648
6649 /* Update L3 header */
6650 ip->tot_len = htons(lro->total_len);
6651 ip->check = 0;
6652 nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
6653 ip->check = nchk;
6654
6655 /* Update L4 header */
6656 tcp->ack_seq = lro->tcp_ack;
6657 tcp->window = lro->window;
6658
6659 /* Update tsecr field if this session has timestamps enabled */
6660 if (lro->saw_ts) {
6661 u32 *ptr = (u32 *)(tcp + 1);
6662 *(ptr+2) = lro->cur_tsecr;
6663 }
6664
6665 /* Update counters required for calculation of
6666 * average no. of packets aggregated.
6667 */
6668 statinfo->sw_stat.sum_avg_pkts_aggregated += lro->sg_num;
6669 statinfo->sw_stat.num_aggregations++;
6670}
6671
6672static void aggregate_new_rx(lro_t *lro, struct iphdr *ip,
6673 struct tcphdr *tcp, u32 l4_pyld)
6674{
6675 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6676 lro->total_len += l4_pyld;
6677 lro->frags_len += l4_pyld;
6678 lro->tcp_next_seq += l4_pyld;
6679 lro->sg_num++;
6680
6681 /* Update ack seq no. and window ad(from this pkt) in LRO object */
6682 lro->tcp_ack = tcp->ack_seq;
6683 lro->window = tcp->window;
6684
6685 if (lro->saw_ts) {
6686 u32 *ptr;
6687 /* Update tsecr and tsval from this packet */
6688 ptr = (u32 *) (tcp + 1);
6689 lro->cur_tsval = *(ptr + 1);
6690 lro->cur_tsecr = *(ptr + 2);
6691 }
6692}
6693
6694static int verify_l3_l4_lro_capable(lro_t *l_lro, struct iphdr *ip,
6695 struct tcphdr *tcp, u32 tcp_pyld_len)
6696{
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006697 u8 *ptr;
6698
Andrew Morton79dc1902006-02-03 01:45:13 -08006699 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
6700
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006701 if (!tcp_pyld_len) {
6702 /* Runt frame or a pure ack */
6703 return -1;
6704 }
6705
6706 if (ip->ihl != 5) /* IP has options */
6707 return -1;
6708
6709 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
6710 !tcp->ack) {
6711 /*
6712 * Currently recognize only the ack control word and
6713 * any other control field being set would result in
6714 * flushing the LRO session
6715 */
6716 return -1;
6717 }
6718
6719 /*
6720 * Allow only one TCP timestamp option. Don't aggregate if
6721 * any other options are detected.
6722 */
6723 if (tcp->doff != 5 && tcp->doff != 8)
6724 return -1;
6725
6726 if (tcp->doff == 8) {
6727 ptr = (u8 *)(tcp + 1);
6728 while (*ptr == TCPOPT_NOP)
6729 ptr++;
6730 if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
6731 return -1;
6732
6733 /* Ensure timestamp value increases monotonically */
6734 if (l_lro)
6735 if (l_lro->cur_tsval > *((u32 *)(ptr+2)))
6736 return -1;
6737
6738 /* timestamp echo reply should be non-zero */
6739 if (*((u32 *)(ptr+6)) == 0)
6740 return -1;
6741 }
6742
6743 return 0;
6744}
6745
6746static int
6747s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, lro_t **lro,
6748 RxD_t *rxdp, nic_t *sp)
6749{
6750 struct iphdr *ip;
6751 struct tcphdr *tcph;
6752 int ret = 0, i;
6753
6754 if (!(ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
6755 rxdp))) {
6756 DBG_PRINT(INFO_DBG,"IP Saddr: %x Daddr: %x\n",
6757 ip->saddr, ip->daddr);
6758 } else {
6759 return ret;
6760 }
6761
6762 tcph = (struct tcphdr *)*tcp;
6763 *tcp_len = get_l4_pyld_length(ip, tcph);
6764 for (i=0; i<MAX_LRO_SESSIONS; i++) {
6765 lro_t *l_lro = &sp->lro0_n[i];
6766 if (l_lro->in_use) {
6767 if (check_for_socket_match(l_lro, ip, tcph))
6768 continue;
6769 /* Sock pair matched */
6770 *lro = l_lro;
6771
6772 if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
6773 DBG_PRINT(INFO_DBG, "%s:Out of order. expected "
6774 "0x%x, actual 0x%x\n", __FUNCTION__,
6775 (*lro)->tcp_next_seq,
6776 ntohl(tcph->seq));
6777
6778 sp->mac_control.stats_info->
6779 sw_stat.outof_sequence_pkts++;
6780 ret = 2;
6781 break;
6782 }
6783
6784 if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,*tcp_len))
6785 ret = 1; /* Aggregate */
6786 else
6787 ret = 2; /* Flush both */
6788 break;
6789 }
6790 }
6791
6792 if (ret == 0) {
6793 /* Before searching for available LRO objects,
6794 * check if the pkt is L3/L4 aggregatable. If not
6795 * don't create new LRO session. Just send this
6796 * packet up.
6797 */
6798 if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len)) {
6799 return 5;
6800 }
6801
6802 for (i=0; i<MAX_LRO_SESSIONS; i++) {
6803 lro_t *l_lro = &sp->lro0_n[i];
6804 if (!(l_lro->in_use)) {
6805 *lro = l_lro;
6806 ret = 3; /* Begin anew */
6807 break;
6808 }
6809 }
6810 }
6811
6812 if (ret == 0) { /* sessions exceeded */
6813 DBG_PRINT(INFO_DBG,"%s:All LRO sessions already in use\n",
6814 __FUNCTION__);
6815 *lro = NULL;
6816 return ret;
6817 }
6818
6819 switch (ret) {
6820 case 3:
6821 initiate_new_session(*lro, buffer, ip, tcph, *tcp_len);
6822 break;
6823 case 2:
6824 update_L3L4_header(sp, *lro);
6825 break;
6826 case 1:
6827 aggregate_new_rx(*lro, ip, tcph, *tcp_len);
6828 if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
6829 update_L3L4_header(sp, *lro);
6830 ret = 4; /* Flush the LRO */
6831 }
6832 break;
6833 default:
6834 DBG_PRINT(ERR_DBG,"%s:Dont know, can't say!!\n",
6835 __FUNCTION__);
6836 break;
6837 }
6838
6839 return ret;
6840}
6841
6842static void clear_lro_session(lro_t *lro)
6843{
6844 static u16 lro_struct_size = sizeof(lro_t);
6845
6846 memset(lro, 0, lro_struct_size);
6847}
6848
6849static void queue_rx_frame(struct sk_buff *skb)
6850{
6851 struct net_device *dev = skb->dev;
6852
6853 skb->protocol = eth_type_trans(skb, dev);
6854#ifdef CONFIG_S2IO_NAPI
6855 netif_receive_skb(skb);
6856#else
6857 netif_rx(skb);
6858#endif
6859}
6860
6861static void lro_append_pkt(nic_t *sp, lro_t *lro, struct sk_buff *skb,
6862 u32 tcp_len)
6863{
6864 struct sk_buff *tmp, *first = lro->parent;
6865
6866 first->len += tcp_len;
6867 first->data_len = lro->frags_len;
6868 skb_pull(skb, (skb->len - tcp_len));
6869 if ((tmp = skb_shinfo(first)->frag_list)) {
6870 while (tmp->next)
6871 tmp = tmp->next;
6872 tmp->next = skb;
6873 }
6874 else
6875 skb_shinfo(first)->frag_list = skb;
6876 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
6877 return;
6878}