blob: e3e6d410d72cdeef0d27bf10de6dce155bb6f201 [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
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08003 * Copyright(c) 2002-2007 Neterion Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
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
Sivakumar Subramani926930b2007-02-24 01:59:39 -050045 * napi: This parameter used to enable/disable NAPI (polling Rx)
46 * Possible values '1' for enable and '0' for disable. Default is '1'
47 * ufo: This parameter used to enable/disable UDP Fragmentation Offload(UFO)
48 * Possible values '1' for enable and '0' for disable. Default is '0'
49 * vlan_tag_strip: This can be used to enable or disable vlan stripping.
50 * Possible values '1' for enable , '0' for disable.
51 * Default is '2' - which means disable in promisc mode
52 * and enable in non-promiscuous mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 ************************************************************************/
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/module.h>
56#include <linux/types.h>
57#include <linux/errno.h>
58#include <linux/ioport.h>
59#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040060#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/kernel.h>
62#include <linux/netdevice.h>
63#include <linux/etherdevice.h>
64#include <linux/skbuff.h>
65#include <linux/init.h>
66#include <linux/delay.h>
67#include <linux/stddef.h>
68#include <linux/ioctl.h>
69#include <linux/timex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <linux/workqueue.h>
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -070072#include <linux/if_vlan.h>
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050073#include <linux/ip.h>
74#include <linux/tcp.h>
75#include <net/tcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include <asm/system.h>
78#include <asm/uaccess.h>
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070079#include <asm/io.h>
Andrew Mortonfe931392006-02-03 01:45:12 -080080#include <asm/div64.h>
Andrew Morton330ce0d2006-08-14 23:00:14 -070081#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/* local include */
84#include "s2io.h"
85#include "s2io-regs.h"
86
Sreenivasa Honnur491976b2007-05-10 04:22:25 -040087#define DRV_VERSION "2.0.23.1"
John Linville6c1792f2005-10-04 07:51:45 -040088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* S2io Driver name & version. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070090static char s2io_driver_name[] = "Neterion";
John Linville6c1792f2005-10-04 07:51:45 -040091static char s2io_driver_version[] = DRV_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Adrian Bunk26df54b2006-01-14 03:09:40 +010093static int rxd_size[4] = {32,48,48,64};
94static int rxd_count[4] = {127,85,85,63};
Ananda Rajuda6971d2005-10-31 16:55:31 -050095
Ralf Baechle1ee6dd72007-01-31 14:09:29 -050096static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -070097{
98 int ret;
99
100 ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
101 (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
102
103 return ret;
104}
105
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700106/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * Cards with following subsystem_id have a link state indication
108 * problem, 600B, 600C, 600D, 640B, 640C and 640D.
109 * macro below identifies these cards given the subsystem_id.
110 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700111#define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
112 (dev_type == XFRAME_I_DEVICE) ? \
113 ((((subid >= 0x600B) && (subid <= 0x600D)) || \
114 ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
117 ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
118#define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
119#define PANIC 1
120#define LOW 2
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500121static inline int rx_buffer_level(struct s2io_nic * sp, int rxb_size, int ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500123 struct mac_info *mac_control;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700124
125 mac_control = &sp->mac_control;
Ananda Raju863c11a2006-04-21 19:03:13 -0400126 if (rxb_size <= rxd_count[sp->rxd_mode])
127 return PANIC;
128 else if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16)
129 return LOW;
130 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133/* Ethtool related variables and Macros. */
134static char s2io_gstrings[][ETH_GSTRING_LEN] = {
135 "Register test\t(offline)",
136 "Eeprom test\t(offline)",
137 "Link test\t(online)",
138 "RLDRAM test\t(offline)",
139 "BIST Test\t(offline)"
140};
141
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500142static char ethtool_xena_stats_keys[][ETH_GSTRING_LEN] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 {"tmac_frms"},
144 {"tmac_data_octets"},
145 {"tmac_drop_frms"},
146 {"tmac_mcst_frms"},
147 {"tmac_bcst_frms"},
148 {"tmac_pause_ctrl_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400149 {"tmac_ttl_octets"},
150 {"tmac_ucst_frms"},
151 {"tmac_nucst_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 {"tmac_any_err_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400153 {"tmac_ttl_less_fb_octets"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 {"tmac_vld_ip_octets"},
155 {"tmac_vld_ip"},
156 {"tmac_drop_ip"},
157 {"tmac_icmp"},
158 {"tmac_rst_tcp"},
159 {"tmac_tcp"},
160 {"tmac_udp"},
161 {"rmac_vld_frms"},
162 {"rmac_data_octets"},
163 {"rmac_fcs_err_frms"},
164 {"rmac_drop_frms"},
165 {"rmac_vld_mcst_frms"},
166 {"rmac_vld_bcst_frms"},
167 {"rmac_in_rng_len_err_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400168 {"rmac_out_rng_len_err_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 {"rmac_long_frms"},
170 {"rmac_pause_ctrl_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400171 {"rmac_unsup_ctrl_frms"},
172 {"rmac_ttl_octets"},
173 {"rmac_accepted_ucst_frms"},
174 {"rmac_accepted_nucst_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 {"rmac_discarded_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400176 {"rmac_drop_events"},
177 {"rmac_ttl_less_fb_octets"},
178 {"rmac_ttl_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 {"rmac_usized_frms"},
180 {"rmac_osized_frms"},
181 {"rmac_frag_frms"},
182 {"rmac_jabber_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400183 {"rmac_ttl_64_frms"},
184 {"rmac_ttl_65_127_frms"},
185 {"rmac_ttl_128_255_frms"},
186 {"rmac_ttl_256_511_frms"},
187 {"rmac_ttl_512_1023_frms"},
188 {"rmac_ttl_1024_1518_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 {"rmac_ip"},
190 {"rmac_ip_octets"},
191 {"rmac_hdr_err_ip"},
192 {"rmac_drop_ip"},
193 {"rmac_icmp"},
194 {"rmac_tcp"},
195 {"rmac_udp"},
196 {"rmac_err_drp_udp"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400197 {"rmac_xgmii_err_sym"},
198 {"rmac_frms_q0"},
199 {"rmac_frms_q1"},
200 {"rmac_frms_q2"},
201 {"rmac_frms_q3"},
202 {"rmac_frms_q4"},
203 {"rmac_frms_q5"},
204 {"rmac_frms_q6"},
205 {"rmac_frms_q7"},
206 {"rmac_full_q0"},
207 {"rmac_full_q1"},
208 {"rmac_full_q2"},
209 {"rmac_full_q3"},
210 {"rmac_full_q4"},
211 {"rmac_full_q5"},
212 {"rmac_full_q6"},
213 {"rmac_full_q7"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 {"rmac_pause_cnt"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400215 {"rmac_xgmii_data_err_cnt"},
216 {"rmac_xgmii_ctrl_err_cnt"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 {"rmac_accepted_ip"},
218 {"rmac_err_tcp"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400219 {"rd_req_cnt"},
220 {"new_rd_req_cnt"},
221 {"new_rd_req_rtry_cnt"},
222 {"rd_rtry_cnt"},
223 {"wr_rtry_rd_ack_cnt"},
224 {"wr_req_cnt"},
225 {"new_wr_req_cnt"},
226 {"new_wr_req_rtry_cnt"},
227 {"wr_rtry_cnt"},
228 {"wr_disc_cnt"},
229 {"rd_rtry_wr_ack_cnt"},
230 {"txp_wr_cnt"},
231 {"txd_rd_cnt"},
232 {"txd_wr_cnt"},
233 {"rxd_rd_cnt"},
234 {"rxd_wr_cnt"},
235 {"txf_rd_cnt"},
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500236 {"rxf_wr_cnt"}
237};
238
239static char ethtool_enhanced_stats_keys[][ETH_GSTRING_LEN] = {
Ananda Rajubd1034f2006-04-21 19:20:22 -0400240 {"rmac_ttl_1519_4095_frms"},
241 {"rmac_ttl_4096_8191_frms"},
242 {"rmac_ttl_8192_max_frms"},
243 {"rmac_ttl_gt_max_frms"},
244 {"rmac_osized_alt_frms"},
245 {"rmac_jabber_alt_frms"},
246 {"rmac_gt_max_alt_frms"},
247 {"rmac_vlan_frms"},
248 {"rmac_len_discard"},
249 {"rmac_fcs_discard"},
250 {"rmac_pf_discard"},
251 {"rmac_da_discard"},
252 {"rmac_red_discard"},
253 {"rmac_rts_discard"},
254 {"rmac_ingm_full_discard"},
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500255 {"link_fault_cnt"}
256};
257
258static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -0700259 {"\n DRIVER STATISTICS"},
260 {"single_bit_ecc_errs"},
261 {"double_bit_ecc_errs"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400262 {"parity_err_cnt"},
263 {"serious_err_cnt"},
264 {"soft_reset_cnt"},
265 {"fifo_full_cnt"},
266 {"ring_full_cnt"},
267 ("alarm_transceiver_temp_high"),
268 ("alarm_transceiver_temp_low"),
269 ("alarm_laser_bias_current_high"),
270 ("alarm_laser_bias_current_low"),
271 ("alarm_laser_output_power_high"),
272 ("alarm_laser_output_power_low"),
273 ("warn_transceiver_temp_high"),
274 ("warn_transceiver_temp_low"),
275 ("warn_laser_bias_current_high"),
276 ("warn_laser_bias_current_low"),
277 ("warn_laser_output_power_high"),
278 ("warn_laser_output_power_low"),
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -0500279 ("lro_aggregated_pkts"),
280 ("lro_flush_both_count"),
281 ("lro_out_of_sequence_pkts"),
282 ("lro_flush_due_to_max_pkts"),
283 ("lro_avg_aggr_pkts"),
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -0400284 ("mem_alloc_fail_cnt"),
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400285 ("watchdog_timer_cnt"),
286 ("mem_allocated"),
287 ("mem_freed"),
288 ("link_up_cnt"),
289 ("link_down_cnt"),
290 ("link_up_time"),
291 ("link_down_time"),
292 ("tx_tcode_buf_abort_cnt"),
293 ("tx_tcode_desc_abort_cnt"),
294 ("tx_tcode_parity_err_cnt"),
295 ("tx_tcode_link_loss_cnt"),
296 ("tx_tcode_list_proc_err_cnt"),
297 ("rx_tcode_parity_err_cnt"),
298 ("rx_tcode_abort_cnt"),
299 ("rx_tcode_parity_abort_cnt"),
300 ("rx_tcode_rda_fail_cnt"),
301 ("rx_tcode_unkn_prot_cnt"),
302 ("rx_tcode_fcs_err_cnt"),
303 ("rx_tcode_buf_size_err_cnt"),
304 ("rx_tcode_rxd_corrupt_cnt"),
305 ("rx_tcode_unkn_err_cnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306};
307
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500308#define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN
309#define S2IO_ENHANCED_STAT_LEN sizeof(ethtool_enhanced_stats_keys)/ \
310 ETH_GSTRING_LEN
311#define S2IO_DRIVER_STAT_LEN sizeof(ethtool_driver_stats_keys)/ ETH_GSTRING_LEN
312
313#define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN )
314#define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN )
315
316#define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN )
317#define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319#define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
320#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
321
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -0700322#define S2IO_TIMER_CONF(timer, handle, arg, exp) \
323 init_timer(&timer); \
324 timer.function = handle; \
325 timer.data = (unsigned long) arg; \
326 mod_timer(&timer, (jiffies + exp)) \
327
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700328/* Add the vlan */
329static void s2io_vlan_rx_register(struct net_device *dev,
330 struct vlan_group *grp)
331{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500332 struct s2io_nic *nic = dev->priv;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700333 unsigned long flags;
334
335 spin_lock_irqsave(&nic->tx_lock, flags);
336 nic->vlgrp = grp;
337 spin_unlock_irqrestore(&nic->tx_lock, flags);
338}
339
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500340/* A flag indicating whether 'RX_PA_CFG_STRIP_VLAN_TAG' bit is set or not */
Adrian Bunk7b490342007-03-05 02:49:25 +0100341static int vlan_strip_flag;
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500342
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700343/* Unregister the vlan */
344static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
345{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500346 struct s2io_nic *nic = dev->priv;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700347 unsigned long flags;
348
349 spin_lock_irqsave(&nic->tx_lock, flags);
Dan Aloni5c15bde2007-03-02 20:44:51 -0800350 vlan_group_set_device(nic->vlgrp, vid, NULL);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700351 spin_unlock_irqrestore(&nic->tx_lock, flags);
352}
353
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700354/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 * Constants to be programmed into the Xena's registers, to configure
356 * the XAUI.
357 */
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define END_SIGN 0x0
Arjan van de Venf71e1302006-03-03 21:33:57 -0500360static const u64 herc_act_dtx_cfg[] = {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700361 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700362 0x8000051536750000ULL, 0x80000515367500E0ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700363 /* Write data */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700364 0x8000051536750004ULL, 0x80000515367500E4ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700365 /* Set address */
366 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
367 /* Write data */
368 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
369 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700370 0x801205150D440000ULL, 0x801205150D4400E0ULL,
371 /* Write data */
372 0x801205150D440004ULL, 0x801205150D4400E4ULL,
373 /* Set address */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700374 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
375 /* Write data */
376 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
377 /* Done */
378 END_SIGN
379};
380
Arjan van de Venf71e1302006-03-03 21:33:57 -0500381static const u64 xena_dtx_cfg[] = {
Ananda Rajuc92ca042006-04-21 19:18:03 -0400382 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 0x8000051500000000ULL, 0x80000515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400384 /* Write data */
385 0x80000515D9350004ULL, 0x80000515D93500E4ULL,
386 /* Set address */
387 0x8001051500000000ULL, 0x80010515000000E0ULL,
388 /* Write data */
389 0x80010515001E0004ULL, 0x80010515001E00E4ULL,
390 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 0x8002051500000000ULL, 0x80020515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400392 /* Write data */
393 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 END_SIGN
395};
396
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700397/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 * Constants for Fixing the MacAddress problem seen mostly on
399 * Alpha machines.
400 */
Arjan van de Venf71e1302006-03-03 21:33:57 -0500401static const u64 fix_mac[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 0x0060000000000000ULL, 0x0060600000000000ULL,
403 0x0040600000000000ULL, 0x0000600000000000ULL,
404 0x0020600000000000ULL, 0x0060600000000000ULL,
405 0x0020600000000000ULL, 0x0060600000000000ULL,
406 0x0020600000000000ULL, 0x0060600000000000ULL,
407 0x0020600000000000ULL, 0x0060600000000000ULL,
408 0x0020600000000000ULL, 0x0060600000000000ULL,
409 0x0020600000000000ULL, 0x0060600000000000ULL,
410 0x0020600000000000ULL, 0x0060600000000000ULL,
411 0x0020600000000000ULL, 0x0060600000000000ULL,
412 0x0020600000000000ULL, 0x0060600000000000ULL,
413 0x0020600000000000ULL, 0x0060600000000000ULL,
414 0x0020600000000000ULL, 0x0000600000000000ULL,
415 0x0040600000000000ULL, 0x0060600000000000ULL,
416 END_SIGN
417};
418
Ananda Rajub41477f2006-07-24 19:52:49 -0400419MODULE_LICENSE("GPL");
420MODULE_VERSION(DRV_VERSION);
421
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/* Module Loadable parameters. */
Ananda Rajub41477f2006-07-24 19:52:49 -0400424S2IO_PARM_INT(tx_fifo_num, 1);
425S2IO_PARM_INT(rx_ring_num, 1);
426
427
428S2IO_PARM_INT(rx_ring_mode, 1);
429S2IO_PARM_INT(use_continuous_tx_intrs, 1);
430S2IO_PARM_INT(rmac_pause_time, 0x100);
431S2IO_PARM_INT(mc_pause_threshold_q0q3, 187);
432S2IO_PARM_INT(mc_pause_threshold_q4q7, 187);
433S2IO_PARM_INT(shared_splits, 0);
434S2IO_PARM_INT(tmac_util_period, 5);
435S2IO_PARM_INT(rmac_util_period, 5);
436S2IO_PARM_INT(bimodal, 0);
437S2IO_PARM_INT(l3l4hdr_size, 128);
438/* Frequency of Rx desc syncs expressed as power of 2 */
439S2IO_PARM_INT(rxsync_frequency, 3);
440/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
441S2IO_PARM_INT(intr_type, 0);
442/* Large receive offload feature */
443S2IO_PARM_INT(lro, 0);
444/* Max pkts to be aggregated by LRO at one time. If not specified,
445 * aggregation happens until we hit max IP pkt size(64K)
446 */
447S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
Ananda Rajub41477f2006-07-24 19:52:49 -0400448S2IO_PARM_INT(indicate_max_pkts, 0);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -0500449
450S2IO_PARM_INT(napi, 1);
451S2IO_PARM_INT(ufo, 0);
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500452S2IO_PARM_INT(vlan_tag_strip, NO_STRIP_IN_PROMISC);
Ananda Rajub41477f2006-07-24 19:52:49 -0400453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400455 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456static unsigned int rx_ring_sz[MAX_RX_RINGS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400457 {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700458static unsigned int rts_frm_len[MAX_RX_RINGS] =
459 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
Ananda Rajub41477f2006-07-24 19:52:49 -0400460
461module_param_array(tx_fifo_len, uint, NULL, 0);
462module_param_array(rx_ring_sz, uint, NULL, 0);
463module_param_array(rts_frm_len, uint, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700465/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 * S2IO device table.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700467 * This table lists all the devices that this driver supports.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 */
469static struct pci_device_id s2io_tbl[] __devinitdata = {
470 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
471 PCI_ANY_ID, PCI_ANY_ID},
472 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
473 PCI_ANY_ID, PCI_ANY_ID},
474 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700475 PCI_ANY_ID, PCI_ANY_ID},
476 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
477 PCI_ANY_ID, PCI_ANY_ID},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {0,}
479};
480
481MODULE_DEVICE_TABLE(pci, s2io_tbl);
482
483static struct pci_driver s2io_driver = {
484 .name = "S2IO",
485 .id_table = s2io_tbl,
486 .probe = s2io_init_nic,
487 .remove = __devexit_p(s2io_rem_nic),
488};
489
490/* A simplifier macro used both by init and free shared_mem Fns(). */
491#define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
492
493/**
494 * init_shared_mem - Allocation and Initialization of Memory
495 * @nic: Device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700496 * Description: The function allocates all the memory areas shared
497 * between the NIC and the driver. This includes Tx descriptors,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 * Rx descriptors and the statistics block.
499 */
500
501static int init_shared_mem(struct s2io_nic *nic)
502{
503 u32 size;
504 void *tmp_v_addr, *tmp_v_addr_next;
505 dma_addr_t tmp_p_addr, tmp_p_addr_next;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500506 struct RxD_block *pre_rxd_blk = NULL;
Sivakumar Subramani372cc592007-01-31 13:32:57 -0500507 int i, j, blk_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 int lst_size, lst_per_page;
509 struct net_device *dev = nic->dev;
viro@zenIV.linux.org.uk8ae418c2005-09-02 20:15:29 +0100510 unsigned long tmp;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500511 struct buffAdd *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500513 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 struct config_param *config;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400515 unsigned long long mem_allocated = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 mac_control = &nic->mac_control;
518 config = &nic->config;
519
520
521 /* Allocation and initialization of TXDLs in FIOFs */
522 size = 0;
523 for (i = 0; i < config->tx_fifo_num; i++) {
524 size += config->tx_cfg[i].fifo_len;
525 }
526 if (size > MAX_AVAILABLE_TXDS) {
Ananda Rajub41477f2006-07-24 19:52:49 -0400527 DBG_PRINT(ERR_DBG, "s2io: Requested TxDs too high, ");
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -0700528 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
Ananda Rajub41477f2006-07-24 19:52:49 -0400529 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500532 lst_size = (sizeof(struct TxD) * config->max_txds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 lst_per_page = PAGE_SIZE / lst_size;
534
535 for (i = 0; i < config->tx_fifo_num; i++) {
536 int fifo_len = config->tx_cfg[i].fifo_len;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500537 int list_holder_size = fifo_len * sizeof(struct list_info_hold);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700538 mac_control->fifos[i].list_info = kmalloc(list_holder_size,
539 GFP_KERNEL);
540 if (!mac_control->fifos[i].list_info) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800541 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 "Malloc failed for list_info\n");
543 return -ENOMEM;
544 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400545 mem_allocated += list_holder_size;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700546 memset(mac_control->fifos[i].list_info, 0, list_holder_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548 for (i = 0; i < config->tx_fifo_num; i++) {
549 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
550 lst_per_page);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700551 mac_control->fifos[i].tx_curr_put_info.offset = 0;
552 mac_control->fifos[i].tx_curr_put_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700554 mac_control->fifos[i].tx_curr_get_info.offset = 0;
555 mac_control->fifos[i].tx_curr_get_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700557 mac_control->fifos[i].fifo_no = i;
558 mac_control->fifos[i].nic = nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500559 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 2;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 for (j = 0; j < page_num; j++) {
562 int k = 0;
563 dma_addr_t tmp_p;
564 void *tmp_v;
565 tmp_v = pci_alloc_consistent(nic->pdev,
566 PAGE_SIZE, &tmp_p);
567 if (!tmp_v) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800568 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 "pci_alloc_consistent ");
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800570 DBG_PRINT(INFO_DBG, "failed for TxDL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 return -ENOMEM;
572 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700573 /* If we got a zero DMA address(can happen on
574 * certain platforms like PPC), reallocate.
575 * Store virtual address of page we don't want,
576 * to be freed later.
577 */
578 if (!tmp_p) {
579 mac_control->zerodma_virt_addr = tmp_v;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400580 DBG_PRINT(INIT_DBG,
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700581 "%s: Zero DMA address for TxDL. ", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400582 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700583 "Virtual address %p\n", tmp_v);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700584 tmp_v = pci_alloc_consistent(nic->pdev,
585 PAGE_SIZE, &tmp_p);
586 if (!tmp_v) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800587 DBG_PRINT(INFO_DBG,
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700588 "pci_alloc_consistent ");
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800589 DBG_PRINT(INFO_DBG, "failed for TxDL\n");
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700590 return -ENOMEM;
591 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400592 mem_allocated += PAGE_SIZE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 while (k < lst_per_page) {
595 int l = (j * lst_per_page) + k;
596 if (l == config->tx_cfg[i].fifo_len)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700597 break;
598 mac_control->fifos[i].list_info[l].list_virt_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 tmp_v + (k * lst_size);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700600 mac_control->fifos[i].list_info[l].list_phy_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 tmp_p + (k * lst_size);
602 k++;
603 }
604 }
605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Al Viro43842472007-01-23 12:25:08 +0000607 nic->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL);
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500608 if (!nic->ufo_in_band_v)
609 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400610 mem_allocated += (size * sizeof(u64));
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /* Allocation and initialization of RXDs in Rings */
613 size = 0;
614 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500615 if (config->rx_cfg[i].num_rxd %
616 (rxd_count[nic->rxd_mode] + 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
618 DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
619 i);
620 DBG_PRINT(ERR_DBG, "RxDs per Block");
621 return FAILURE;
622 }
623 size += config->rx_cfg[i].num_rxd;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700624 mac_control->rings[i].block_count =
Ananda Rajuda6971d2005-10-31 16:55:31 -0500625 config->rx_cfg[i].num_rxd /
626 (rxd_count[nic->rxd_mode] + 1 );
627 mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
628 mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500630 if (nic->rxd_mode == RXD_MODE_1)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500631 size = (size * (sizeof(struct RxD1)));
Ananda Rajuda6971d2005-10-31 16:55:31 -0500632 else
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500633 size = (size * (sizeof(struct RxD3)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700636 mac_control->rings[i].rx_curr_get_info.block_index = 0;
637 mac_control->rings[i].rx_curr_get_info.offset = 0;
638 mac_control->rings[i].rx_curr_get_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700640 mac_control->rings[i].rx_curr_put_info.block_index = 0;
641 mac_control->rings[i].rx_curr_put_info.offset = 0;
642 mac_control->rings[i].rx_curr_put_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700644 mac_control->rings[i].nic = nic;
645 mac_control->rings[i].ring_no = i;
646
Ananda Rajuda6971d2005-10-31 16:55:31 -0500647 blk_cnt = config->rx_cfg[i].num_rxd /
648 (rxd_count[nic->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /* Allocating all the Rx blocks */
650 for (j = 0; j < blk_cnt; j++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500651 struct rx_block_info *rx_blocks;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500652 int l;
653
654 rx_blocks = &mac_control->rings[i].rx_blocks[j];
655 size = SIZE_OF_BLOCK; //size is always page size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
657 &tmp_p_addr);
658 if (tmp_v_addr == NULL) {
659 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700660 * In case of failure, free_shared_mem()
661 * is called, which should free any
662 * memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 * failure happened.
664 */
Ananda Rajuda6971d2005-10-31 16:55:31 -0500665 rx_blocks->block_virt_addr = tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return -ENOMEM;
667 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400668 mem_allocated += size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 memset(tmp_v_addr, 0, size);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500670 rx_blocks->block_virt_addr = tmp_v_addr;
671 rx_blocks->block_dma_addr = tmp_p_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500672 rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)*
Ananda Rajuda6971d2005-10-31 16:55:31 -0500673 rxd_count[nic->rxd_mode],
674 GFP_KERNEL);
Sivakumar Subramani372cc592007-01-31 13:32:57 -0500675 if (!rx_blocks->rxds)
676 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400677 mem_allocated +=
678 (sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500679 for (l=0; l<rxd_count[nic->rxd_mode];l++) {
680 rx_blocks->rxds[l].virt_addr =
681 rx_blocks->block_virt_addr +
682 (rxd_size[nic->rxd_mode] * l);
683 rx_blocks->rxds[l].dma_addr =
684 rx_blocks->block_dma_addr +
685 (rxd_size[nic->rxd_mode] * l);
686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688 /* Interlinking all Rx Blocks */
689 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700690 tmp_v_addr =
691 mac_control->rings[i].rx_blocks[j].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 tmp_v_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700693 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 blk_cnt].block_virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700695 tmp_p_addr =
696 mac_control->rings[i].rx_blocks[j].block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 tmp_p_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700698 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 blk_cnt].block_dma_addr;
700
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500701 pre_rxd_blk = (struct RxD_block *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 pre_rxd_blk->reserved_2_pNext_RxD_block =
703 (unsigned long) tmp_v_addr_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 pre_rxd_blk->pNext_RxD_Blk_physical =
705 (u64) tmp_p_addr_next;
706 }
707 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500708 if (nic->rxd_mode >= RXD_MODE_3A) {
709 /*
710 * Allocation of Storages for buffer addresses in 2BUFF mode
711 * and the buffers as well.
712 */
713 for (i = 0; i < config->rx_ring_num; i++) {
714 blk_cnt = config->rx_cfg[i].num_rxd /
715 (rxd_count[nic->rxd_mode]+ 1);
716 mac_control->rings[i].ba =
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500717 kmalloc((sizeof(struct buffAdd *) * blk_cnt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 GFP_KERNEL);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500719 if (!mac_control->rings[i].ba)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400721 mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500722 for (j = 0; j < blk_cnt; j++) {
723 int k = 0;
724 mac_control->rings[i].ba[j] =
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500725 kmalloc((sizeof(struct buffAdd) *
Ananda Rajuda6971d2005-10-31 16:55:31 -0500726 (rxd_count[nic->rxd_mode] + 1)),
727 GFP_KERNEL);
728 if (!mac_control->rings[i].ba[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400730 mem_allocated += (sizeof(struct buffAdd) * \
731 (rxd_count[nic->rxd_mode] + 1));
Ananda Rajuda6971d2005-10-31 16:55:31 -0500732 while (k != rxd_count[nic->rxd_mode]) {
733 ba = &mac_control->rings[i].ba[j][k];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Ananda Rajuda6971d2005-10-31 16:55:31 -0500735 ba->ba_0_org = (void *) kmalloc
736 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
737 if (!ba->ba_0_org)
738 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400739 mem_allocated +=
740 (BUF0_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500741 tmp = (unsigned long)ba->ba_0_org;
742 tmp += ALIGN_SIZE;
743 tmp &= ~((unsigned long) ALIGN_SIZE);
744 ba->ba_0 = (void *) tmp;
745
746 ba->ba_1_org = (void *) kmalloc
747 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
748 if (!ba->ba_1_org)
749 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400750 mem_allocated
751 += (BUF1_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500752 tmp = (unsigned long) ba->ba_1_org;
753 tmp += ALIGN_SIZE;
754 tmp &= ~((unsigned long) ALIGN_SIZE);
755 ba->ba_1 = (void *) tmp;
756 k++;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759 }
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /* Allocation and initialization of Statistics block */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500763 size = sizeof(struct stat_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 mac_control->stats_mem = pci_alloc_consistent
765 (nic->pdev, size, &mac_control->stats_mem_phy);
766
767 if (!mac_control->stats_mem) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700768 /*
769 * In case of failure, free_shared_mem() is called, which
770 * should free any memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 * failure happened.
772 */
773 return -ENOMEM;
774 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400775 mem_allocated += size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 mac_control->stats_mem_sz = size;
777
778 tmp_v_addr = mac_control->stats_mem;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500779 mac_control->stats_info = (struct stat_block *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 memset(tmp_v_addr, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
782 (unsigned long long) tmp_p_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400783 mac_control->stats_info->sw_stat.mem_allocated += mem_allocated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 return SUCCESS;
785}
786
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700787/**
788 * free_shared_mem - Free the allocated Memory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 * @nic: Device private variable.
790 * Description: This function is to free all memory locations allocated by
791 * the init_shared_mem() function and return it to the kernel.
792 */
793
794static void free_shared_mem(struct s2io_nic *nic)
795{
796 int i, j, blk_cnt, size;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400797 u32 ufo_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 void *tmp_v_addr;
799 dma_addr_t tmp_p_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500800 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 struct config_param *config;
802 int lst_size, lst_per_page;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700803 struct net_device *dev = nic->dev;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400804 int page_num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (!nic)
807 return;
808
809 mac_control = &nic->mac_control;
810 config = &nic->config;
811
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500812 lst_size = (sizeof(struct TxD) * config->max_txds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 lst_per_page = PAGE_SIZE / lst_size;
814
815 for (i = 0; i < config->tx_fifo_num; i++) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400816 ufo_size += config->tx_cfg[i].fifo_len;
817 page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
818 lst_per_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 for (j = 0; j < page_num; j++) {
820 int mem_blks = (j * lst_per_page);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700821 if (!mac_control->fifos[i].list_info)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400822 return;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700823 if (!mac_control->fifos[i].list_info[mem_blks].
824 list_virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 break;
826 pci_free_consistent(nic->pdev, PAGE_SIZE,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700827 mac_control->fifos[i].
828 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 list_virt_addr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700830 mac_control->fifos[i].
831 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 list_phy_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400833 nic->mac_control.stats_info->sw_stat.mem_freed
834 += PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700836 /* If we got a zero DMA address during allocation,
837 * free the page now
838 */
839 if (mac_control->zerodma_virt_addr) {
840 pci_free_consistent(nic->pdev, PAGE_SIZE,
841 mac_control->zerodma_virt_addr,
842 (dma_addr_t)0);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400843 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700844 "%s: Freeing TxDL with zero DMA addr. ",
845 dev->name);
846 DBG_PRINT(INIT_DBG, "Virtual address %p\n",
847 mac_control->zerodma_virt_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400848 nic->mac_control.stats_info->sw_stat.mem_freed
849 += PAGE_SIZE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700850 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700851 kfree(mac_control->fifos[i].list_info);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400852 nic->mac_control.stats_info->sw_stat.mem_freed +=
853 (nic->config.tx_cfg[i].fifo_len *sizeof(struct list_info_hold));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 size = SIZE_OF_BLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700858 blk_cnt = mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700860 tmp_v_addr = mac_control->rings[i].rx_blocks[j].
861 block_virt_addr;
862 tmp_p_addr = mac_control->rings[i].rx_blocks[j].
863 block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (tmp_v_addr == NULL)
865 break;
866 pci_free_consistent(nic->pdev, size,
867 tmp_v_addr, tmp_p_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400868 nic->mac_control.stats_info->sw_stat.mem_freed += size;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500869 kfree(mac_control->rings[i].rx_blocks[j].rxds);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400870 nic->mac_control.stats_info->sw_stat.mem_freed +=
871 ( sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
873 }
874
Ananda Rajuda6971d2005-10-31 16:55:31 -0500875 if (nic->rxd_mode >= RXD_MODE_3A) {
876 /* Freeing buffer storage addresses in 2BUFF mode. */
877 for (i = 0; i < config->rx_ring_num; i++) {
878 blk_cnt = config->rx_cfg[i].num_rxd /
879 (rxd_count[nic->rxd_mode] + 1);
880 for (j = 0; j < blk_cnt; j++) {
881 int k = 0;
882 if (!mac_control->rings[i].ba[j])
883 continue;
884 while (k != rxd_count[nic->rxd_mode]) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500885 struct buffAdd *ba =
Ananda Rajuda6971d2005-10-31 16:55:31 -0500886 &mac_control->rings[i].ba[j][k];
887 kfree(ba->ba_0_org);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400888 nic->mac_control.stats_info->sw_stat.\
889 mem_freed += (BUF0_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500890 kfree(ba->ba_1_org);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400891 nic->mac_control.stats_info->sw_stat.\
892 mem_freed += (BUF1_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500893 k++;
894 }
895 kfree(mac_control->rings[i].ba[j]);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400896 nic->mac_control.stats_info->sw_stat.mem_freed += (sizeof(struct buffAdd) *
897 (rxd_count[nic->rxd_mode] + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500899 kfree(mac_control->rings[i].ba);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400900 nic->mac_control.stats_info->sw_stat.mem_freed +=
901 (sizeof(struct buffAdd *) * blk_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 if (mac_control->stats_mem) {
906 pci_free_consistent(nic->pdev,
907 mac_control->stats_mem_sz,
908 mac_control->stats_mem,
909 mac_control->stats_mem_phy);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400910 nic->mac_control.stats_info->sw_stat.mem_freed +=
911 mac_control->stats_mem_sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400913 if (nic->ufo_in_band_v) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500914 kfree(nic->ufo_in_band_v);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400915 nic->mac_control.stats_info->sw_stat.mem_freed
916 += (ufo_size * sizeof(u64));
917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700920/**
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700921 * s2io_verify_pci_mode -
922 */
923
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500924static int s2io_verify_pci_mode(struct s2io_nic *nic)
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700925{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500926 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700927 register u64 val64 = 0;
928 int mode;
929
930 val64 = readq(&bar0->pci_mode);
931 mode = (u8)GET_PCI_MODE(val64);
932
933 if ( val64 & PCI_MODE_UNKNOWN_MODE)
934 return -1; /* Unknown PCI mode */
935 return mode;
936}
937
Ananda Rajuc92ca042006-04-21 19:18:03 -0400938#define NEC_VENID 0x1033
939#define NEC_DEVID 0x0125
940static int s2io_on_nec_bridge(struct pci_dev *s2io_pdev)
941{
942 struct pci_dev *tdev = NULL;
Alan Cox26d36b62006-09-15 15:22:51 +0100943 while ((tdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tdev)) != NULL) {
944 if (tdev->vendor == NEC_VENID && tdev->device == NEC_DEVID) {
Ananda Rajuc92ca042006-04-21 19:18:03 -0400945 if (tdev->bus == s2io_pdev->bus->parent)
Alan Cox26d36b62006-09-15 15:22:51 +0100946 pci_dev_put(tdev);
Ananda Rajuc92ca042006-04-21 19:18:03 -0400947 return 1;
948 }
949 }
950 return 0;
951}
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700952
Adrian Bunk7b32a312006-05-16 17:30:50 +0200953static int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700954/**
955 * s2io_print_pci_mode -
956 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500957static int s2io_print_pci_mode(struct s2io_nic *nic)
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700958{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500959 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700960 register u64 val64 = 0;
961 int mode;
962 struct config_param *config = &nic->config;
963
964 val64 = readq(&bar0->pci_mode);
965 mode = (u8)GET_PCI_MODE(val64);
966
967 if ( val64 & PCI_MODE_UNKNOWN_MODE)
968 return -1; /* Unknown PCI mode */
969
Ananda Rajuc92ca042006-04-21 19:18:03 -0400970 config->bus_speed = bus_speed[mode];
971
972 if (s2io_on_nec_bridge(nic->pdev)) {
973 DBG_PRINT(ERR_DBG, "%s: Device is on PCI-E bus\n",
974 nic->dev->name);
975 return mode;
976 }
977
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700978 if (val64 & PCI_MODE_32_BITS) {
979 DBG_PRINT(ERR_DBG, "%s: Device is on 32 bit ", nic->dev->name);
980 } else {
981 DBG_PRINT(ERR_DBG, "%s: Device is on 64 bit ", nic->dev->name);
982 }
983
984 switch(mode) {
985 case PCI_MODE_PCI_33:
986 DBG_PRINT(ERR_DBG, "33MHz PCI bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700987 break;
988 case PCI_MODE_PCI_66:
989 DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700990 break;
991 case PCI_MODE_PCIX_M1_66:
992 DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700993 break;
994 case PCI_MODE_PCIX_M1_100:
995 DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700996 break;
997 case PCI_MODE_PCIX_M1_133:
998 DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700999 break;
1000 case PCI_MODE_PCIX_M2_66:
1001 DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001002 break;
1003 case PCI_MODE_PCIX_M2_100:
1004 DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001005 break;
1006 case PCI_MODE_PCIX_M2_133:
1007 DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001008 break;
1009 default:
1010 return -1; /* Unsupported bus speed */
1011 }
1012
1013 return mode;
1014}
1015
1016/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001017 * init_nic - Initialization of hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 * @nic: device peivate variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001019 * Description: The function sequentially configures every block
1020 * of the H/W from their reset values.
1021 * Return Value: SUCCESS on success and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 * '-1' on failure (endian settings incorrect).
1023 */
1024
1025static int init_nic(struct s2io_nic *nic)
1026{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001027 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 struct net_device *dev = nic->dev;
1029 register u64 val64 = 0;
1030 void __iomem *add;
1031 u32 time;
1032 int i, j;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001033 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 struct config_param *config;
Ananda Rajuc92ca042006-04-21 19:18:03 -04001035 int dtx_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 unsigned long long mem_share;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001037 int mem_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 mac_control = &nic->mac_control;
1040 config = &nic->config;
1041
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001042 /* to set the swapper controle on the card */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001043 if(s2io_set_swapper(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
1045 return -1;
1046 }
1047
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001048 /*
1049 * Herc requires EOI to be removed from reset before XGXS, so..
1050 */
1051 if (nic->device_type & XFRAME_II_DEVICE) {
1052 val64 = 0xA500000000ULL;
1053 writeq(val64, &bar0->sw_reset);
1054 msleep(500);
1055 val64 = readq(&bar0->sw_reset);
1056 }
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 /* Remove XGXS from reset state */
1059 val64 = 0;
1060 writeq(val64, &bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 msleep(500);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001062 val64 = readq(&bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 /* Enable Receiving broadcasts */
1065 add = &bar0->mac_cfg;
1066 val64 = readq(&bar0->mac_cfg);
1067 val64 |= MAC_RMAC_BCAST_ENABLE;
1068 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1069 writel((u32) val64, add);
1070 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1071 writel((u32) (val64 >> 32), (add + 4));
1072
1073 /* Read registers in all blocks */
1074 val64 = readq(&bar0->mac_int_mask);
1075 val64 = readq(&bar0->mc_int_mask);
1076 val64 = readq(&bar0->xgxs_int_mask);
1077
1078 /* Set MTU */
1079 val64 = dev->mtu;
1080 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
1081
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001082 if (nic->device_type & XFRAME_II_DEVICE) {
1083 while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07001084 SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 &bar0->dtx_control, UF);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001086 if (dtx_cnt & 0x1)
1087 msleep(1); /* Necessary!! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 dtx_cnt++;
1089 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001090 } else {
Ananda Rajuc92ca042006-04-21 19:18:03 -04001091 while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
1092 SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
1093 &bar0->dtx_control, UF);
1094 val64 = readq(&bar0->dtx_control);
1095 dtx_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097 }
1098
1099 /* Tx DMA Initialization */
1100 val64 = 0;
1101 writeq(val64, &bar0->tx_fifo_partition_0);
1102 writeq(val64, &bar0->tx_fifo_partition_1);
1103 writeq(val64, &bar0->tx_fifo_partition_2);
1104 writeq(val64, &bar0->tx_fifo_partition_3);
1105
1106
1107 for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
1108 val64 |=
1109 vBIT(config->tx_cfg[i].fifo_len - 1, ((i * 32) + 19),
1110 13) | vBIT(config->tx_cfg[i].fifo_priority,
1111 ((i * 32) + 5), 3);
1112
1113 if (i == (config->tx_fifo_num - 1)) {
1114 if (i % 2 == 0)
1115 i++;
1116 }
1117
1118 switch (i) {
1119 case 1:
1120 writeq(val64, &bar0->tx_fifo_partition_0);
1121 val64 = 0;
1122 break;
1123 case 3:
1124 writeq(val64, &bar0->tx_fifo_partition_1);
1125 val64 = 0;
1126 break;
1127 case 5:
1128 writeq(val64, &bar0->tx_fifo_partition_2);
1129 val64 = 0;
1130 break;
1131 case 7:
1132 writeq(val64, &bar0->tx_fifo_partition_3);
1133 break;
1134 }
1135 }
1136
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001137 /*
1138 * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
1139 * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
1140 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001141 if ((nic->device_type == XFRAME_I_DEVICE) &&
1142 (get_xena_rev_id(nic->pdev) < 4))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001143 writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 val64 = readq(&bar0->tx_fifo_partition_0);
1146 DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
1147 &bar0->tx_fifo_partition_0, (unsigned long long) val64);
1148
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001149 /*
1150 * Initialization of Tx_PA_CONFIG register to ignore packet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 * integrity checking.
1152 */
1153 val64 = readq(&bar0->tx_pa_cfg);
1154 val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
1155 TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
1156 writeq(val64, &bar0->tx_pa_cfg);
1157
1158 /* Rx DMA intialization. */
1159 val64 = 0;
1160 for (i = 0; i < config->rx_ring_num; i++) {
1161 val64 |=
1162 vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
1163 3);
1164 }
1165 writeq(val64, &bar0->rx_queue_priority);
1166
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001167 /*
1168 * Allocating equal share of memory to all the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 * configured Rings.
1170 */
1171 val64 = 0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001172 if (nic->device_type & XFRAME_II_DEVICE)
1173 mem_size = 32;
1174 else
1175 mem_size = 64;
1176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 for (i = 0; i < config->rx_ring_num; i++) {
1178 switch (i) {
1179 case 0:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001180 mem_share = (mem_size / config->rx_ring_num +
1181 mem_size % config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
1183 continue;
1184 case 1:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001185 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
1187 continue;
1188 case 2:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001189 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
1191 continue;
1192 case 3:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001193 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
1195 continue;
1196 case 4:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001197 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
1199 continue;
1200 case 5:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001201 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
1203 continue;
1204 case 6:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001205 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
1207 continue;
1208 case 7:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001209 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
1211 continue;
1212 }
1213 }
1214 writeq(val64, &bar0->rx_queue_cfg);
1215
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001216 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001217 * Filling Tx round robin registers
1218 * as per the number of FIFOs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001220 switch (config->tx_fifo_num) {
1221 case 1:
1222 val64 = 0x0000000000000000ULL;
1223 writeq(val64, &bar0->tx_w_round_robin_0);
1224 writeq(val64, &bar0->tx_w_round_robin_1);
1225 writeq(val64, &bar0->tx_w_round_robin_2);
1226 writeq(val64, &bar0->tx_w_round_robin_3);
1227 writeq(val64, &bar0->tx_w_round_robin_4);
1228 break;
1229 case 2:
1230 val64 = 0x0000010000010000ULL;
1231 writeq(val64, &bar0->tx_w_round_robin_0);
1232 val64 = 0x0100000100000100ULL;
1233 writeq(val64, &bar0->tx_w_round_robin_1);
1234 val64 = 0x0001000001000001ULL;
1235 writeq(val64, &bar0->tx_w_round_robin_2);
1236 val64 = 0x0000010000010000ULL;
1237 writeq(val64, &bar0->tx_w_round_robin_3);
1238 val64 = 0x0100000000000000ULL;
1239 writeq(val64, &bar0->tx_w_round_robin_4);
1240 break;
1241 case 3:
1242 val64 = 0x0001000102000001ULL;
1243 writeq(val64, &bar0->tx_w_round_robin_0);
1244 val64 = 0x0001020000010001ULL;
1245 writeq(val64, &bar0->tx_w_round_robin_1);
1246 val64 = 0x0200000100010200ULL;
1247 writeq(val64, &bar0->tx_w_round_robin_2);
1248 val64 = 0x0001000102000001ULL;
1249 writeq(val64, &bar0->tx_w_round_robin_3);
1250 val64 = 0x0001020000000000ULL;
1251 writeq(val64, &bar0->tx_w_round_robin_4);
1252 break;
1253 case 4:
1254 val64 = 0x0001020300010200ULL;
1255 writeq(val64, &bar0->tx_w_round_robin_0);
1256 val64 = 0x0100000102030001ULL;
1257 writeq(val64, &bar0->tx_w_round_robin_1);
1258 val64 = 0x0200010000010203ULL;
1259 writeq(val64, &bar0->tx_w_round_robin_2);
1260 val64 = 0x0001020001000001ULL;
1261 writeq(val64, &bar0->tx_w_round_robin_3);
1262 val64 = 0x0203000100000000ULL;
1263 writeq(val64, &bar0->tx_w_round_robin_4);
1264 break;
1265 case 5:
1266 val64 = 0x0001000203000102ULL;
1267 writeq(val64, &bar0->tx_w_round_robin_0);
1268 val64 = 0x0001020001030004ULL;
1269 writeq(val64, &bar0->tx_w_round_robin_1);
1270 val64 = 0x0001000203000102ULL;
1271 writeq(val64, &bar0->tx_w_round_robin_2);
1272 val64 = 0x0001020001030004ULL;
1273 writeq(val64, &bar0->tx_w_round_robin_3);
1274 val64 = 0x0001000000000000ULL;
1275 writeq(val64, &bar0->tx_w_round_robin_4);
1276 break;
1277 case 6:
1278 val64 = 0x0001020304000102ULL;
1279 writeq(val64, &bar0->tx_w_round_robin_0);
1280 val64 = 0x0304050001020001ULL;
1281 writeq(val64, &bar0->tx_w_round_robin_1);
1282 val64 = 0x0203000100000102ULL;
1283 writeq(val64, &bar0->tx_w_round_robin_2);
1284 val64 = 0x0304000102030405ULL;
1285 writeq(val64, &bar0->tx_w_round_robin_3);
1286 val64 = 0x0001000200000000ULL;
1287 writeq(val64, &bar0->tx_w_round_robin_4);
1288 break;
1289 case 7:
1290 val64 = 0x0001020001020300ULL;
1291 writeq(val64, &bar0->tx_w_round_robin_0);
1292 val64 = 0x0102030400010203ULL;
1293 writeq(val64, &bar0->tx_w_round_robin_1);
1294 val64 = 0x0405060001020001ULL;
1295 writeq(val64, &bar0->tx_w_round_robin_2);
1296 val64 = 0x0304050000010200ULL;
1297 writeq(val64, &bar0->tx_w_round_robin_3);
1298 val64 = 0x0102030000000000ULL;
1299 writeq(val64, &bar0->tx_w_round_robin_4);
1300 break;
1301 case 8:
1302 val64 = 0x0001020300040105ULL;
1303 writeq(val64, &bar0->tx_w_round_robin_0);
1304 val64 = 0x0200030106000204ULL;
1305 writeq(val64, &bar0->tx_w_round_robin_1);
1306 val64 = 0x0103000502010007ULL;
1307 writeq(val64, &bar0->tx_w_round_robin_2);
1308 val64 = 0x0304010002060500ULL;
1309 writeq(val64, &bar0->tx_w_round_robin_3);
1310 val64 = 0x0103020400000000ULL;
1311 writeq(val64, &bar0->tx_w_round_robin_4);
1312 break;
1313 }
1314
Ananda Rajub41477f2006-07-24 19:52:49 -04001315 /* Enable all configured Tx FIFO partitions */
Ananda Raju5d3213c2006-04-21 19:23:26 -04001316 val64 = readq(&bar0->tx_fifo_partition_0);
1317 val64 |= (TX_FIFO_PARTITION_EN);
1318 writeq(val64, &bar0->tx_fifo_partition_0);
1319
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001320 /* Filling the Rx round robin registers as per the
1321 * number of Rings and steering based on QoS.
1322 */
1323 switch (config->rx_ring_num) {
1324 case 1:
1325 val64 = 0x8080808080808080ULL;
1326 writeq(val64, &bar0->rts_qos_steering);
1327 break;
1328 case 2:
1329 val64 = 0x0000010000010000ULL;
1330 writeq(val64, &bar0->rx_w_round_robin_0);
1331 val64 = 0x0100000100000100ULL;
1332 writeq(val64, &bar0->rx_w_round_robin_1);
1333 val64 = 0x0001000001000001ULL;
1334 writeq(val64, &bar0->rx_w_round_robin_2);
1335 val64 = 0x0000010000010000ULL;
1336 writeq(val64, &bar0->rx_w_round_robin_3);
1337 val64 = 0x0100000000000000ULL;
1338 writeq(val64, &bar0->rx_w_round_robin_4);
1339
1340 val64 = 0x8080808040404040ULL;
1341 writeq(val64, &bar0->rts_qos_steering);
1342 break;
1343 case 3:
1344 val64 = 0x0001000102000001ULL;
1345 writeq(val64, &bar0->rx_w_round_robin_0);
1346 val64 = 0x0001020000010001ULL;
1347 writeq(val64, &bar0->rx_w_round_robin_1);
1348 val64 = 0x0200000100010200ULL;
1349 writeq(val64, &bar0->rx_w_round_robin_2);
1350 val64 = 0x0001000102000001ULL;
1351 writeq(val64, &bar0->rx_w_round_robin_3);
1352 val64 = 0x0001020000000000ULL;
1353 writeq(val64, &bar0->rx_w_round_robin_4);
1354
1355 val64 = 0x8080804040402020ULL;
1356 writeq(val64, &bar0->rts_qos_steering);
1357 break;
1358 case 4:
1359 val64 = 0x0001020300010200ULL;
1360 writeq(val64, &bar0->rx_w_round_robin_0);
1361 val64 = 0x0100000102030001ULL;
1362 writeq(val64, &bar0->rx_w_round_robin_1);
1363 val64 = 0x0200010000010203ULL;
1364 writeq(val64, &bar0->rx_w_round_robin_2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001365 val64 = 0x0001020001000001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001366 writeq(val64, &bar0->rx_w_round_robin_3);
1367 val64 = 0x0203000100000000ULL;
1368 writeq(val64, &bar0->rx_w_round_robin_4);
1369
1370 val64 = 0x8080404020201010ULL;
1371 writeq(val64, &bar0->rts_qos_steering);
1372 break;
1373 case 5:
1374 val64 = 0x0001000203000102ULL;
1375 writeq(val64, &bar0->rx_w_round_robin_0);
1376 val64 = 0x0001020001030004ULL;
1377 writeq(val64, &bar0->rx_w_round_robin_1);
1378 val64 = 0x0001000203000102ULL;
1379 writeq(val64, &bar0->rx_w_round_robin_2);
1380 val64 = 0x0001020001030004ULL;
1381 writeq(val64, &bar0->rx_w_round_robin_3);
1382 val64 = 0x0001000000000000ULL;
1383 writeq(val64, &bar0->rx_w_round_robin_4);
1384
1385 val64 = 0x8080404020201008ULL;
1386 writeq(val64, &bar0->rts_qos_steering);
1387 break;
1388 case 6:
1389 val64 = 0x0001020304000102ULL;
1390 writeq(val64, &bar0->rx_w_round_robin_0);
1391 val64 = 0x0304050001020001ULL;
1392 writeq(val64, &bar0->rx_w_round_robin_1);
1393 val64 = 0x0203000100000102ULL;
1394 writeq(val64, &bar0->rx_w_round_robin_2);
1395 val64 = 0x0304000102030405ULL;
1396 writeq(val64, &bar0->rx_w_round_robin_3);
1397 val64 = 0x0001000200000000ULL;
1398 writeq(val64, &bar0->rx_w_round_robin_4);
1399
1400 val64 = 0x8080404020100804ULL;
1401 writeq(val64, &bar0->rts_qos_steering);
1402 break;
1403 case 7:
1404 val64 = 0x0001020001020300ULL;
1405 writeq(val64, &bar0->rx_w_round_robin_0);
1406 val64 = 0x0102030400010203ULL;
1407 writeq(val64, &bar0->rx_w_round_robin_1);
1408 val64 = 0x0405060001020001ULL;
1409 writeq(val64, &bar0->rx_w_round_robin_2);
1410 val64 = 0x0304050000010200ULL;
1411 writeq(val64, &bar0->rx_w_round_robin_3);
1412 val64 = 0x0102030000000000ULL;
1413 writeq(val64, &bar0->rx_w_round_robin_4);
1414
1415 val64 = 0x8080402010080402ULL;
1416 writeq(val64, &bar0->rts_qos_steering);
1417 break;
1418 case 8:
1419 val64 = 0x0001020300040105ULL;
1420 writeq(val64, &bar0->rx_w_round_robin_0);
1421 val64 = 0x0200030106000204ULL;
1422 writeq(val64, &bar0->rx_w_round_robin_1);
1423 val64 = 0x0103000502010007ULL;
1424 writeq(val64, &bar0->rx_w_round_robin_2);
1425 val64 = 0x0304010002060500ULL;
1426 writeq(val64, &bar0->rx_w_round_robin_3);
1427 val64 = 0x0103020400000000ULL;
1428 writeq(val64, &bar0->rx_w_round_robin_4);
1429
1430 val64 = 0x8040201008040201ULL;
1431 writeq(val64, &bar0->rts_qos_steering);
1432 break;
1433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 /* UDP Fix */
1436 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001437 for (i = 0; i < 8; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 writeq(val64, &bar0->rts_frm_len_n[i]);
1439
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001440 /* Set the default rts frame length for the rings configured */
1441 val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
1442 for (i = 0 ; i < config->rx_ring_num ; i++)
1443 writeq(val64, &bar0->rts_frm_len_n[i]);
1444
1445 /* Set the frame length for the configured rings
1446 * desired by the user
1447 */
1448 for (i = 0; i < config->rx_ring_num; i++) {
1449 /* If rts_frm_len[i] == 0 then it is assumed that user not
1450 * specified frame length steering.
1451 * If the user provides the frame length then program
1452 * the rts_frm_len register for those values or else
1453 * leave it as it is.
1454 */
1455 if (rts_frm_len[i] != 0) {
1456 writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
1457 &bar0->rts_frm_len_n[i]);
1458 }
1459 }
Sivakumar Subramani926930b2007-02-24 01:59:39 -05001460
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05001461 /* Disable differentiated services steering logic */
1462 for (i = 0; i < 64; i++) {
1463 if (rts_ds_steer(nic, i, 0) == FAILURE) {
1464 DBG_PRINT(ERR_DBG, "%s: failed rts ds steering",
1465 dev->name);
1466 DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i);
1467 return FAILURE;
1468 }
1469 }
1470
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001471 /* Program statistics memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001474 if (nic->device_type == XFRAME_II_DEVICE) {
1475 val64 = STAT_BC(0x320);
1476 writeq(val64, &bar0->stat_byte_cnt);
1477 }
1478
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001479 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 * Initializing the sampling rate for the device to calculate the
1481 * bandwidth utilization.
1482 */
1483 val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
1484 MAC_RX_LINK_UTIL_VAL(rmac_util_period);
1485 writeq(val64, &bar0->mac_link_util);
1486
1487
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001488 /*
1489 * Initializing the Transmit and Receive Traffic Interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 * Scheme.
1491 */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001492 /*
1493 * TTI Initialization. Default Tx timer gets us about
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 * 250 interrupts per sec. Continuous interrupts are enabled
1495 * by default.
1496 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001497 if (nic->device_type == XFRAME_II_DEVICE) {
1498 int count = (nic->config.bus_speed * 125)/2;
1499 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
1500 } else {
1501
1502 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
1503 }
1504 val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 TTI_DATA1_MEM_TX_URNG_B(0x10) |
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001506 TTI_DATA1_MEM_TX_URNG_C(0x30) | TTI_DATA1_MEM_TX_TIMER_AC_EN;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001507 if (use_continuous_tx_intrs)
1508 val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 writeq(val64, &bar0->tti_data1_mem);
1510
1511 val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
1512 TTI_DATA2_MEM_TX_UFC_B(0x20) |
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001513 TTI_DATA2_MEM_TX_UFC_C(0x40) | TTI_DATA2_MEM_TX_UFC_D(0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 writeq(val64, &bar0->tti_data2_mem);
1515
1516 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1517 writeq(val64, &bar0->tti_command_mem);
1518
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001519 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 * Once the operation completes, the Strobe bit of the command
1521 * register will be reset. We poll for this particular condition
1522 * We wait for a maximum of 500ms for the operation to complete,
1523 * if it's not complete by then we return error.
1524 */
1525 time = 0;
1526 while (TRUE) {
1527 val64 = readq(&bar0->tti_command_mem);
1528 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1529 break;
1530 }
1531 if (time > 10) {
1532 DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
1533 dev->name);
1534 return -1;
1535 }
1536 msleep(50);
1537 time++;
1538 }
1539
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001540 if (nic->config.bimodal) {
1541 int k = 0;
1542 for (k = 0; k < config->rx_ring_num; k++) {
1543 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
1544 val64 |= TTI_CMD_MEM_OFFSET(0x38+k);
1545 writeq(val64, &bar0->tti_command_mem);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001546
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001547 /*
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001548 * Once the operation completes, the Strobe bit of the command
1549 * register will be reset. We poll for this particular condition
1550 * We wait for a maximum of 500ms for the operation to complete,
1551 * if it's not complete by then we return error.
1552 */
1553 time = 0;
1554 while (TRUE) {
1555 val64 = readq(&bar0->tti_command_mem);
1556 if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
1557 break;
1558 }
1559 if (time > 10) {
1560 DBG_PRINT(ERR_DBG,
1561 "%s: TTI init Failed\n",
1562 dev->name);
1563 return -1;
1564 }
1565 time++;
1566 msleep(50);
1567 }
1568 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001569 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001571 /* RTI Initialization */
1572 if (nic->device_type == XFRAME_II_DEVICE) {
1573 /*
1574 * Programmed to generate Apprx 500 Intrs per
1575 * second
1576 */
1577 int count = (nic->config.bus_speed * 125)/4;
1578 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
1579 } else {
1580 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001582 val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
1583 RTI_DATA1_MEM_RX_URNG_B(0x10) |
1584 RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
1585
1586 writeq(val64, &bar0->rti_data1_mem);
1587
1588 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001589 RTI_DATA2_MEM_RX_UFC_B(0x2) ;
1590 if (nic->intr_type == MSI_X)
1591 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
1592 RTI_DATA2_MEM_RX_UFC_D(0x40));
1593 else
1594 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
1595 RTI_DATA2_MEM_RX_UFC_D(0x80));
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001596 writeq(val64, &bar0->rti_data2_mem);
1597
1598 for (i = 0; i < config->rx_ring_num; i++) {
1599 val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
1600 | RTI_CMD_MEM_OFFSET(i);
1601 writeq(val64, &bar0->rti_command_mem);
1602
1603 /*
1604 * Once the operation completes, the Strobe bit of the
1605 * command register will be reset. We poll for this
1606 * particular condition. We wait for a maximum of 500ms
1607 * for the operation to complete, if it's not complete
1608 * by then we return error.
1609 */
1610 time = 0;
1611 while (TRUE) {
1612 val64 = readq(&bar0->rti_command_mem);
1613 if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD)) {
1614 break;
1615 }
1616 if (time > 10) {
1617 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
1618 dev->name);
1619 return -1;
1620 }
1621 time++;
1622 msleep(50);
1623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 }
1626
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001627 /*
1628 * Initializing proper values as Pause threshold into all
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 * the 8 Queues on Rx side.
1630 */
1631 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
1632 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
1633
1634 /* Disable RMAC PAD STRIPPING */
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01001635 add = &bar0->mac_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 val64 = readq(&bar0->mac_cfg);
1637 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
1638 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1639 writel((u32) (val64), add);
1640 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1641 writel((u32) (val64 >> 32), (add + 4));
1642 val64 = readq(&bar0->mac_cfg);
1643
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05001644 /* Enable FCS stripping by adapter */
1645 add = &bar0->mac_cfg;
1646 val64 = readq(&bar0->mac_cfg);
1647 val64 |= MAC_CFG_RMAC_STRIP_FCS;
1648 if (nic->device_type == XFRAME_II_DEVICE)
1649 writeq(val64, &bar0->mac_cfg);
1650 else {
1651 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1652 writel((u32) (val64), add);
1653 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1654 writel((u32) (val64 >> 32), (add + 4));
1655 }
1656
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001657 /*
1658 * Set the time value to be inserted in the pause frame
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 * generated by xena.
1660 */
1661 val64 = readq(&bar0->rmac_pause_cfg);
1662 val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
1663 val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
1664 writeq(val64, &bar0->rmac_pause_cfg);
1665
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001666 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 * Set the Threshold Limit for Generating the pause frame
1668 * If the amount of data in any Queue exceeds ratio of
1669 * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
1670 * pause frame is generated
1671 */
1672 val64 = 0;
1673 for (i = 0; i < 4; i++) {
1674 val64 |=
1675 (((u64) 0xFF00 | nic->mac_control.
1676 mc_pause_threshold_q0q3)
1677 << (i * 2 * 8));
1678 }
1679 writeq(val64, &bar0->mc_pause_thresh_q0q3);
1680
1681 val64 = 0;
1682 for (i = 0; i < 4; i++) {
1683 val64 |=
1684 (((u64) 0xFF00 | nic->mac_control.
1685 mc_pause_threshold_q4q7)
1686 << (i * 2 * 8));
1687 }
1688 writeq(val64, &bar0->mc_pause_thresh_q4q7);
1689
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001690 /*
1691 * TxDMA will stop Read request if the number of read split has
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 * exceeded the limit pointed by shared_splits
1693 */
1694 val64 = readq(&bar0->pic_control);
1695 val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
1696 writeq(val64, &bar0->pic_control);
1697
Ananda Raju863c11a2006-04-21 19:03:13 -04001698 if (nic->config.bus_speed == 266) {
1699 writeq(TXREQTO_VAL(0x7f) | TXREQTO_EN, &bar0->txreqtimeout);
1700 writeq(0x0, &bar0->read_retry_delay);
1701 writeq(0x0, &bar0->write_retry_delay);
1702 }
1703
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001704 /*
1705 * Programming the Herc to split every write transaction
1706 * that does not start on an ADB to reduce disconnects.
1707 */
1708 if (nic->device_type == XFRAME_II_DEVICE) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001709 val64 = FAULT_BEHAVIOUR | EXT_REQ_EN |
1710 MISC_LINK_STABILITY_PRD(3);
Ananda Raju863c11a2006-04-21 19:03:13 -04001711 writeq(val64, &bar0->misc_control);
1712 val64 = readq(&bar0->pic_control2);
1713 val64 &= ~(BIT(13)|BIT(14)|BIT(15));
1714 writeq(val64, &bar0->pic_control2);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001715 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04001716 if (strstr(nic->product_name, "CX4")) {
1717 val64 = TMAC_AVG_IPG(0x17);
1718 writeq(val64, &bar0->tmac_avg_ipg);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001719 }
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 return SUCCESS;
1722}
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001723#define LINK_UP_DOWN_INTERRUPT 1
1724#define MAC_RMAC_ERR_TIMER 2
1725
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001726static int s2io_link_fault_indication(struct s2io_nic *nic)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001727{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001728 if (nic->intr_type != INTA)
1729 return MAC_RMAC_ERR_TIMER;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001730 if (nic->device_type == XFRAME_II_DEVICE)
1731 return LINK_UP_DOWN_INTERRUPT;
1732 else
1733 return MAC_RMAC_ERR_TIMER;
1734}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001736/**
1737 * en_dis_able_nic_intrs - Enable or Disable the interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 * @nic: device private variable,
1739 * @mask: A mask indicating which Intr block must be modified and,
1740 * @flag: A flag indicating whether to enable or disable the Intrs.
1741 * Description: This function will either disable or enable the interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001742 * depending on the flag argument. The mask argument can be used to
1743 * enable/disable any Intr block.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 * Return Value: NONE.
1745 */
1746
1747static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
1748{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001749 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 register u64 val64 = 0, temp64 = 0;
1751
1752 /* Top level interrupt classification */
1753 /* PIC Interrupts */
1754 if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
1755 /* Enable PIC Intrs in the general intr mask register */
Sivakumar Subramania113ae02007-01-31 14:05:51 -05001756 val64 = TXPIC_INT_M;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 if (flag == ENABLE_INTRS) {
1758 temp64 = readq(&bar0->general_int_mask);
1759 temp64 &= ~((u64) val64);
1760 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001761 /*
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001762 * If Hercules adapter enable GPIO otherwise
Ananda Rajub41477f2006-07-24 19:52:49 -04001763 * disable all PCIX, Flash, MDIO, IIC and GPIO
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001764 * interrupts for now.
1765 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001767 if (s2io_link_fault_indication(nic) ==
1768 LINK_UP_DOWN_INTERRUPT ) {
1769 temp64 = readq(&bar0->pic_int_mask);
1770 temp64 &= ~((u64) PIC_INT_GPIO);
1771 writeq(temp64, &bar0->pic_int_mask);
1772 temp64 = readq(&bar0->gpio_int_mask);
1773 temp64 &= ~((u64) GPIO_INT_MASK_LINK_UP);
1774 writeq(temp64, &bar0->gpio_int_mask);
1775 } else {
1776 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1777 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001778 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 * No MSI Support is available presently, so TTI and
1780 * RTI interrupts are also disabled.
1781 */
1782 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001783 /*
1784 * Disable PIC Intrs in the general
1785 * intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 */
1787 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
1788 temp64 = readq(&bar0->general_int_mask);
1789 val64 |= temp64;
1790 writeq(val64, &bar0->general_int_mask);
1791 }
1792 }
1793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 /* MAC Interrupts */
1795 /* Enabling/Disabling MAC interrupts */
1796 if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
1797 val64 = TXMAC_INT_M | RXMAC_INT_M;
1798 if (flag == ENABLE_INTRS) {
1799 temp64 = readq(&bar0->general_int_mask);
1800 temp64 &= ~((u64) val64);
1801 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001802 /*
1803 * All MAC block error interrupts are disabled for now
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 * TODO
1805 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001807 /*
1808 * Disable MAC Intrs in the general intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 */
1810 writeq(DISABLE_ALL_INTRS, &bar0->mac_int_mask);
1811 writeq(DISABLE_ALL_INTRS,
1812 &bar0->mac_rmac_err_mask);
1813
1814 temp64 = readq(&bar0->general_int_mask);
1815 val64 |= temp64;
1816 writeq(val64, &bar0->general_int_mask);
1817 }
1818 }
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 /* Tx traffic interrupts */
1821 if (mask & TX_TRAFFIC_INTR) {
1822 val64 = TXTRAFFIC_INT_M;
1823 if (flag == ENABLE_INTRS) {
1824 temp64 = readq(&bar0->general_int_mask);
1825 temp64 &= ~((u64) val64);
1826 writeq(temp64, &bar0->general_int_mask);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001827 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 * Enable all the Tx side interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001829 * writing 0 Enables all 64 TX interrupt levels
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 */
1831 writeq(0x0, &bar0->tx_traffic_mask);
1832 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001833 /*
1834 * Disable Tx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 * register.
1836 */
1837 writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
1838 temp64 = readq(&bar0->general_int_mask);
1839 val64 |= temp64;
1840 writeq(val64, &bar0->general_int_mask);
1841 }
1842 }
1843
1844 /* Rx traffic interrupts */
1845 if (mask & RX_TRAFFIC_INTR) {
1846 val64 = RXTRAFFIC_INT_M;
1847 if (flag == ENABLE_INTRS) {
1848 temp64 = readq(&bar0->general_int_mask);
1849 temp64 &= ~((u64) val64);
1850 writeq(temp64, &bar0->general_int_mask);
1851 /* writing 0 Enables all 8 RX interrupt levels */
1852 writeq(0x0, &bar0->rx_traffic_mask);
1853 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001854 /*
1855 * Disable Rx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 * register.
1857 */
1858 writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
1859 temp64 = readq(&bar0->general_int_mask);
1860 val64 |= temp64;
1861 writeq(val64, &bar0->general_int_mask);
1862 }
1863 }
1864}
1865
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001866/**
1867 * verify_pcc_quiescent- Checks for PCC quiescent state
1868 * Return: 1 If PCC is quiescence
1869 * 0 If PCC is not quiescence
1870 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001871static int verify_pcc_quiescent(struct s2io_nic *sp, int flag)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001872{
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001873 int ret = 0, herc;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001874 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001875 u64 val64 = readq(&bar0->adapter_status);
1876
1877 herc = (sp->device_type == XFRAME_II_DEVICE);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001878
1879 if (flag == FALSE) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001880 if ((!herc && (get_xena_rev_id(sp->pdev) >= 4)) || herc) {
1881 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001882 ret = 1;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001883 } else {
1884 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001885 ret = 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001886 }
1887 } else {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001888 if ((!herc && (get_xena_rev_id(sp->pdev) >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001889 if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001890 ADAPTER_STATUS_RMAC_PCC_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001891 ret = 1;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001892 } else {
1893 if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001894 ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001895 ret = 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001896 }
1897 }
1898
1899 return ret;
1900}
1901/**
1902 * verify_xena_quiescence - Checks whether the H/W is ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 * Description: Returns whether the H/W is ready to go or not. Depending
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001904 * on whether adapter enable bit was written or not the comparison
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 * differs and the calling function passes the input argument flag to
1906 * indicate this.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001907 * Return: 1 If xena is quiescence
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 * 0 If Xena is not quiescence
1909 */
1910
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001911static int verify_xena_quiescence(struct s2io_nic *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912{
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001913 int mode;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001914 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001915 u64 val64 = readq(&bar0->adapter_status);
1916 mode = s2io_verify_pci_mode(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001918 if (!(val64 & ADAPTER_STATUS_TDMA_READY)) {
1919 DBG_PRINT(ERR_DBG, "%s", "TDMA is not ready!");
1920 return 0;
1921 }
1922 if (!(val64 & ADAPTER_STATUS_RDMA_READY)) {
1923 DBG_PRINT(ERR_DBG, "%s", "RDMA is not ready!");
1924 return 0;
1925 }
1926 if (!(val64 & ADAPTER_STATUS_PFC_READY)) {
1927 DBG_PRINT(ERR_DBG, "%s", "PFC is not ready!");
1928 return 0;
1929 }
1930 if (!(val64 & ADAPTER_STATUS_TMAC_BUF_EMPTY)) {
1931 DBG_PRINT(ERR_DBG, "%s", "TMAC BUF is not empty!");
1932 return 0;
1933 }
1934 if (!(val64 & ADAPTER_STATUS_PIC_QUIESCENT)) {
1935 DBG_PRINT(ERR_DBG, "%s", "PIC is not QUIESCENT!");
1936 return 0;
1937 }
1938 if (!(val64 & ADAPTER_STATUS_MC_DRAM_READY)) {
1939 DBG_PRINT(ERR_DBG, "%s", "MC_DRAM is not ready!");
1940 return 0;
1941 }
1942 if (!(val64 & ADAPTER_STATUS_MC_QUEUES_READY)) {
1943 DBG_PRINT(ERR_DBG, "%s", "MC_QUEUES is not ready!");
1944 return 0;
1945 }
1946 if (!(val64 & ADAPTER_STATUS_M_PLL_LOCK)) {
1947 DBG_PRINT(ERR_DBG, "%s", "M_PLL is not locked!");
1948 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
1950
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001951 /*
1952 * In PCI 33 mode, the P_PLL is not used, and therefore,
1953 * the the P_PLL_LOCK bit in the adapter_status register will
1954 * not be asserted.
1955 */
1956 if (!(val64 & ADAPTER_STATUS_P_PLL_LOCK) &&
1957 sp->device_type == XFRAME_II_DEVICE && mode !=
1958 PCI_MODE_PCI_33) {
1959 DBG_PRINT(ERR_DBG, "%s", "P_PLL is not locked!");
1960 return 0;
1961 }
1962 if (!((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
1963 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
1964 DBG_PRINT(ERR_DBG, "%s", "RC_PRC is not QUIESCENT!");
1965 return 0;
1966 }
1967 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
1970/**
1971 * fix_mac_address - Fix for Mac addr problem on Alpha platforms
1972 * @sp: Pointer to device specifc structure
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001973 * Description :
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 * New procedure to clear mac address reading problems on Alpha platforms
1975 *
1976 */
1977
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001978static void fix_mac_address(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001980 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 u64 val64;
1982 int i = 0;
1983
1984 while (fix_mac[i] != END_SIGN) {
1985 writeq(fix_mac[i++], &bar0->gpio_control);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001986 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 val64 = readq(&bar0->gpio_control);
1988 }
1989}
1990
1991/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001992 * start_nic - Turns the device on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001994 * Description:
1995 * This function actually turns the device on. Before this function is
1996 * called,all Registers are configured from their reset states
1997 * and shared memory is allocated but the NIC is still quiescent. On
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 * calling this function, the device interrupts are cleared and the NIC is
1999 * literally switched on by writing into the adapter control register.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002000 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 * SUCCESS on success and -1 on failure.
2002 */
2003
2004static int start_nic(struct s2io_nic *nic)
2005{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002006 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 struct net_device *dev = nic->dev;
2008 register u64 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002009 u16 subid, i;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002010 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 struct config_param *config;
2012
2013 mac_control = &nic->mac_control;
2014 config = &nic->config;
2015
2016 /* PRC Initialization and configuration */
2017 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002018 writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 &bar0->prc_rxd0_n[i]);
2020
2021 val64 = readq(&bar0->prc_ctrl_n[i]);
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07002022 if (nic->config.bimodal)
2023 val64 |= PRC_CTRL_BIMODAL_INTERRUPT;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002024 if (nic->rxd_mode == RXD_MODE_1)
2025 val64 |= PRC_CTRL_RC_ENABLED;
2026 else
2027 val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
Ananda Raju863c11a2006-04-21 19:03:13 -04002028 if (nic->device_type == XFRAME_II_DEVICE)
2029 val64 |= PRC_CTRL_GROUP_READS;
2030 val64 &= ~PRC_CTRL_RXD_BACKOFF_INTERVAL(0xFFFFFF);
2031 val64 |= PRC_CTRL_RXD_BACKOFF_INTERVAL(0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 writeq(val64, &bar0->prc_ctrl_n[i]);
2033 }
2034
Ananda Rajuda6971d2005-10-31 16:55:31 -05002035 if (nic->rxd_mode == RXD_MODE_3B) {
2036 /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
2037 val64 = readq(&bar0->rx_pa_cfg);
2038 val64 |= RX_PA_CFG_IGNORE_L2_ERR;
2039 writeq(val64, &bar0->rx_pa_cfg);
2040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Sivakumar Subramani926930b2007-02-24 01:59:39 -05002042 if (vlan_tag_strip == 0) {
2043 val64 = readq(&bar0->rx_pa_cfg);
2044 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
2045 writeq(val64, &bar0->rx_pa_cfg);
2046 vlan_strip_flag = 0;
2047 }
2048
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002049 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 * Enabling MC-RLDRAM. After enabling the device, we timeout
2051 * for around 100ms, which is approximately the time required
2052 * for the device to be ready for operation.
2053 */
2054 val64 = readq(&bar0->mc_rldram_mrs);
2055 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
2056 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
2057 val64 = readq(&bar0->mc_rldram_mrs);
2058
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002059 msleep(100); /* Delay by around 100 ms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 /* Enabling ECC Protection. */
2062 val64 = readq(&bar0->adapter_control);
2063 val64 &= ~ADAPTER_ECC_EN;
2064 writeq(val64, &bar0->adapter_control);
2065
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002066 /*
2067 * Clearing any possible Link state change interrupts that
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 * could have popped up just before Enabling the card.
2069 */
2070 val64 = readq(&bar0->mac_rmac_err_reg);
2071 if (val64)
2072 writeq(val64, &bar0->mac_rmac_err_reg);
2073
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002074 /*
2075 * Verify if the device is ready to be enabled, if so enable
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 * it.
2077 */
2078 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002079 if (!verify_xena_quiescence(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
2081 DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
2082 (unsigned long long) val64);
2083 return FAILURE;
2084 }
2085
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002086 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 * With some switches, link might be already up at this point.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002088 * Because of this weird behavior, when we enable laser,
2089 * we may not get link. We need to handle this. We cannot
2090 * figure out which switch is misbehaving. So we are forced to
2091 * make a global change.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 */
2093
2094 /* Enabling Laser. */
2095 val64 = readq(&bar0->adapter_control);
2096 val64 |= ADAPTER_EOI_TX_ON;
2097 writeq(val64, &bar0->adapter_control);
2098
Ananda Rajuc92ca042006-04-21 19:18:03 -04002099 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
2100 /*
2101 * Dont see link state interrupts initally on some switches,
2102 * so directly scheduling the link state task here.
2103 */
2104 schedule_work(&nic->set_link_task);
2105 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 /* SXE-002: Initialize link and activity LED */
2107 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002108 if (((subid & 0xFF) >= 0x07) &&
2109 (nic->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 val64 = readq(&bar0->gpio_control);
2111 val64 |= 0x0000800000000000ULL;
2112 writeq(val64, &bar0->gpio_control);
2113 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002114 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 }
2116
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 return SUCCESS;
2118}
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002119/**
2120 * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
2121 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002122static struct sk_buff *s2io_txdl_getskb(struct fifo_info *fifo_data, struct \
2123 TxD *txdlp, int get_off)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002124{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002125 struct s2io_nic *nic = fifo_data->nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002126 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002127 struct TxD *txds;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002128 u16 j, frg_cnt;
2129
2130 txds = txdlp;
Andrew Morton26b76252005-12-14 19:25:23 -08002131 if (txds->Host_Control == (u64)(long)nic->ufo_in_band_v) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002132 pci_unmap_single(nic->pdev, (dma_addr_t)
2133 txds->Buffer_Pointer, sizeof(u64),
2134 PCI_DMA_TODEVICE);
2135 txds++;
2136 }
2137
2138 skb = (struct sk_buff *) ((unsigned long)
2139 txds->Host_Control);
2140 if (!skb) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002141 memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002142 return NULL;
2143 }
2144 pci_unmap_single(nic->pdev, (dma_addr_t)
2145 txds->Buffer_Pointer,
2146 skb->len - skb->data_len,
2147 PCI_DMA_TODEVICE);
2148 frg_cnt = skb_shinfo(skb)->nr_frags;
2149 if (frg_cnt) {
2150 txds++;
2151 for (j = 0; j < frg_cnt; j++, txds++) {
2152 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
2153 if (!txds->Buffer_Pointer)
2154 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002155 pci_unmap_page(nic->pdev, (dma_addr_t)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002156 txds->Buffer_Pointer,
2157 frag->size, PCI_DMA_TODEVICE);
2158 }
2159 }
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002160 memset(txdlp,0, (sizeof(struct TxD) * fifo_data->max_txds));
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002161 return(skb);
2162}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002164/**
2165 * free_tx_buffers - Free all queued Tx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002167 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 * Free all queued Tx buffers.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002169 * Return Value: void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170*/
2171
2172static void free_tx_buffers(struct s2io_nic *nic)
2173{
2174 struct net_device *dev = nic->dev;
2175 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002176 struct TxD *txdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 int i, j;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002178 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct config_param *config;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002180 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
2182 mac_control = &nic->mac_control;
2183 config = &nic->config;
2184
2185 for (i = 0; i < config->tx_fifo_num; i++) {
2186 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002187 txdp = (struct TxD *) \
2188 mac_control->fifos[i].list_info[j].list_virt_addr;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002189 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
2190 if (skb) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002191 nic->mac_control.stats_info->sw_stat.mem_freed
2192 += skb->truesize;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002193 dev_kfree_skb(skb);
2194 cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 }
2197 DBG_PRINT(INTR_DBG,
2198 "%s:forcibly freeing %d skbs on FIFO%d\n",
2199 dev->name, cnt, i);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002200 mac_control->fifos[i].tx_curr_get_info.offset = 0;
2201 mac_control->fifos[i].tx_curr_put_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
2203}
2204
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002205/**
2206 * stop_nic - To stop the nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 * @nic ; device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002208 * Description:
2209 * This function does exactly the opposite of what the start_nic()
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 * function does. This function is called to stop the device.
2211 * Return Value:
2212 * void.
2213 */
2214
2215static void stop_nic(struct s2io_nic *nic)
2216{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002217 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 register u64 val64 = 0;
Ananda Raju5d3213c2006-04-21 19:23:26 -04002219 u16 interruptible;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002220 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct config_param *config;
2222
2223 mac_control = &nic->mac_control;
2224 config = &nic->config;
2225
2226 /* Disable all interrupts */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002227 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002228 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
2229 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
2231
Ananda Raju5d3213c2006-04-21 19:23:26 -04002232 /* Clearing Adapter_En bit of ADAPTER_CONTROL Register */
2233 val64 = readq(&bar0->adapter_control);
2234 val64 &= ~(ADAPTER_CNTL_EN);
2235 writeq(val64, &bar0->adapter_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002238static int fill_rxd_3buf(struct s2io_nic *nic, struct RxD_t *rxdp, struct \
2239 sk_buff *skb)
Ananda Rajuda6971d2005-10-31 16:55:31 -05002240{
2241 struct net_device *dev = nic->dev;
2242 struct sk_buff *frag_list;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002243 void *tmp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002244
2245 /* Buffer-1 receives L3/L4 headers */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002246 ((struct RxD3*)rxdp)->Buffer1_ptr = pci_map_single
Ananda Rajuda6971d2005-10-31 16:55:31 -05002247 (nic->pdev, skb->data, l3l4hdr_size + 4,
2248 PCI_DMA_FROMDEVICE);
2249
2250 /* skb_shinfo(skb)->frag_list will have L4 data payload */
2251 skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE);
2252 if (skb_shinfo(skb)->frag_list == NULL) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04002253 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002254 DBG_PRINT(INFO_DBG, "%s: dev_alloc_skb failed\n ", dev->name);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002255 return -ENOMEM ;
2256 }
2257 frag_list = skb_shinfo(skb)->frag_list;
Sivakumar Subramani372cc592007-01-31 13:32:57 -05002258 skb->truesize += frag_list->truesize;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002259 nic->mac_control.stats_info->sw_stat.mem_allocated
2260 += frag_list->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002261 frag_list->next = NULL;
Jeff Garzik50eb8002005-11-05 23:40:46 -05002262 tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
2263 frag_list->data = tmp;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07002264 skb_reset_tail_pointer(frag_list);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002265
2266 /* Buffer-2 receives L4 data payload */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002267 ((struct RxD3*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002268 frag_list->data, dev->mtu,
2269 PCI_DMA_FROMDEVICE);
2270 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
2271 rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu);
2272
2273 return SUCCESS;
2274}
2275
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002276/**
2277 * fill_rx_buffers - Allocates the Rx side skbs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002279 * @ring_no: ring number
2280 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 * The function allocates Rx side skbs and puts the physical
2282 * address of these buffers into the RxD buffer pointers, so that the NIC
2283 * can DMA the received frame into these locations.
2284 * The NIC supports 3 receive modes, viz
2285 * 1. single buffer,
2286 * 2. three buffer and
2287 * 3. Five buffer modes.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002288 * Each mode defines how many fragments the received frame will be split
2289 * up into by the NIC. The frame is split into L3 header, L4 Header,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
2291 * is split into 3 fragments. As of now only single buffer mode is
2292 * supported.
2293 * Return Value:
2294 * SUCCESS on success or an appropriate -ve value on failure.
2295 */
2296
Adrian Bunkac1f60d2005-11-06 01:46:47 +01002297static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
2299 struct net_device *dev = nic->dev;
2300 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002301 struct RxD_t *rxdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 int off, off1, size, block_no, block_no1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 u32 alloc_tab = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002304 u32 alloc_cnt;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002305 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 struct config_param *config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002307 u64 tmp;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002308 struct buffAdd *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 unsigned long flags;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002310 struct RxD_t *first_rxdp = NULL;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002311 u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 mac_control = &nic->mac_control;
2314 config = &nic->config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002315 alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
2316 atomic_read(&nic->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Ananda Raju5d3213c2006-04-21 19:23:26 -04002318 block_no1 = mac_control->rings[ring_no].rx_curr_get_info.block_index;
Ananda Raju863c11a2006-04-21 19:03:13 -04002319 off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 while (alloc_tab < alloc_cnt) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002321 block_no = mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 block_index;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002323 off = mac_control->rings[ring_no].rx_curr_put_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Ananda Rajuda6971d2005-10-31 16:55:31 -05002325 rxdp = mac_control->rings[ring_no].
2326 rx_blocks[block_no].rxds[off].virt_addr;
2327
2328 if ((block_no == block_no1) && (off == off1) &&
2329 (rxdp->Host_Control)) {
2330 DBG_PRINT(INTR_DBG, "%s: Get and Put",
2331 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 DBG_PRINT(INTR_DBG, " info equated\n");
2333 goto end;
2334 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002335 if (off && (off == rxd_count[nic->rxd_mode])) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002336 mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 block_index++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002338 if (mac_control->rings[ring_no].rx_curr_put_info.
2339 block_index == mac_control->rings[ring_no].
2340 block_count)
2341 mac_control->rings[ring_no].rx_curr_put_info.
2342 block_index = 0;
2343 block_no = mac_control->rings[ring_no].
2344 rx_curr_put_info.block_index;
2345 if (off == rxd_count[nic->rxd_mode])
2346 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002347 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002348 offset = off;
2349 rxdp = mac_control->rings[ring_no].
2350 rx_blocks[block_no].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2352 dev->name, rxdp);
2353 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002354 if(!napi) {
2355 spin_lock_irqsave(&nic->put_lock, flags);
2356 mac_control->rings[ring_no].put_pos =
2357 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2358 spin_unlock_irqrestore(&nic->put_lock, flags);
2359 } else {
2360 mac_control->rings[ring_no].put_pos =
2361 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2362 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002363 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
2364 ((nic->rxd_mode >= RXD_MODE_3A) &&
2365 (rxdp->Control_2 & BIT(0)))) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002366 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002367 offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 goto end;
2369 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002370 /* calculate size of skb based on ring mode */
2371 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
2372 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
2373 if (nic->rxd_mode == RXD_MODE_1)
2374 size += NET_IP_ALIGN;
2375 else if (nic->rxd_mode == RXD_MODE_3B)
2376 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
2377 else
2378 size = l3l4hdr_size + ALIGN_SIZE + BUF0_LEN + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Ananda Rajuda6971d2005-10-31 16:55:31 -05002380 /* allocate skb */
2381 skb = dev_alloc_skb(size);
2382 if(!skb) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002383 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
2384 DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n");
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002385 if (first_rxdp) {
2386 wmb();
2387 first_rxdp->Control_1 |= RXD_OWN_XENA;
2388 }
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04002389 nic->mac_control.stats_info->sw_stat. \
2390 mem_alloc_fail_cnt++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002391 return -ENOMEM ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002393 nic->mac_control.stats_info->sw_stat.mem_allocated
2394 += skb->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002395 if (nic->rxd_mode == RXD_MODE_1) {
2396 /* 1 buffer mode - normal operation mode */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002397 memset(rxdp, 0, sizeof(struct RxD1));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002398 skb_reserve(skb, NET_IP_ALIGN);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002399 ((struct RxD1*)rxdp)->Buffer0_ptr = pci_map_single
Ananda Raju863c11a2006-04-21 19:03:13 -04002400 (nic->pdev, skb->data, size - NET_IP_ALIGN,
2401 PCI_DMA_FROMDEVICE);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002402 rxdp->Control_2 =
2403 SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002404
2405 } else if (nic->rxd_mode >= RXD_MODE_3A) {
2406 /*
2407 * 2 or 3 buffer mode -
2408 * Both 2 buffer mode and 3 buffer mode provides 128
2409 * byte aligned receive buffers.
2410 *
2411 * 3 buffer mode provides header separation where in
2412 * skb->data will have L3/L4 headers where as
2413 * skb_shinfo(skb)->frag_list will have the L4 data
2414 * payload
2415 */
2416
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002417 /* save buffer pointers to avoid frequent dma mapping */
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002418 Buffer0_ptr = ((struct RxD3*)rxdp)->Buffer0_ptr;
2419 Buffer1_ptr = ((struct RxD3*)rxdp)->Buffer1_ptr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002420 memset(rxdp, 0, sizeof(struct RxD3));
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002421 /* restore the buffer pointers for dma sync*/
2422 ((struct RxD3*)rxdp)->Buffer0_ptr = Buffer0_ptr;
2423 ((struct RxD3*)rxdp)->Buffer1_ptr = Buffer1_ptr;
2424
Ananda Rajuda6971d2005-10-31 16:55:31 -05002425 ba = &mac_control->rings[ring_no].ba[block_no][off];
2426 skb_reserve(skb, BUF0_LEN);
2427 tmp = (u64)(unsigned long) skb->data;
2428 tmp += ALIGN_SIZE;
2429 tmp &= ~ALIGN_SIZE;
2430 skb->data = (void *) (unsigned long)tmp;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07002431 skb_reset_tail_pointer(skb);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002432
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002433 if (!(((struct RxD3*)rxdp)->Buffer0_ptr))
2434 ((struct RxD3*)rxdp)->Buffer0_ptr =
Ananda Raju75c30b12006-07-24 19:55:09 -04002435 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002436 PCI_DMA_FROMDEVICE);
Ananda Raju75c30b12006-07-24 19:55:09 -04002437 else
2438 pci_dma_sync_single_for_device(nic->pdev,
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002439 (dma_addr_t) ((struct RxD3*)rxdp)->Buffer0_ptr,
Ananda Raju75c30b12006-07-24 19:55:09 -04002440 BUF0_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002441 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2442 if (nic->rxd_mode == RXD_MODE_3B) {
2443 /* Two buffer mode */
2444
2445 /*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002446 * Buffer2 will have L3/L4 header plus
Ananda Rajuda6971d2005-10-31 16:55:31 -05002447 * L4 payload
2448 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002449 ((struct RxD3*)rxdp)->Buffer2_ptr = pci_map_single
Ananda Rajuda6971d2005-10-31 16:55:31 -05002450 (nic->pdev, skb->data, dev->mtu + 4,
2451 PCI_DMA_FROMDEVICE);
2452
Ananda Raju75c30b12006-07-24 19:55:09 -04002453 /* Buffer-1 will be dummy buffer. Not used */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002454 if (!(((struct RxD3*)rxdp)->Buffer1_ptr)) {
2455 ((struct RxD3*)rxdp)->Buffer1_ptr =
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002456 pci_map_single(nic->pdev,
Ananda Raju75c30b12006-07-24 19:55:09 -04002457 ba->ba_1, BUF1_LEN,
2458 PCI_DMA_FROMDEVICE);
2459 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002460 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2461 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2462 (dev->mtu + 4);
2463 } else {
2464 /* 3 buffer mode */
2465 if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002466 nic->mac_control.stats_info->sw_stat.\
2467 mem_freed += skb->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002468 dev_kfree_skb_irq(skb);
2469 if (first_rxdp) {
2470 wmb();
2471 first_rxdp->Control_1 |=
2472 RXD_OWN_XENA;
2473 }
2474 return -ENOMEM ;
2475 }
2476 }
2477 rxdp->Control_2 |= BIT(0);
2478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 rxdp->Host_Control = (unsigned long) (skb);
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002480 if (alloc_tab & ((1 << rxsync_frequency) - 1))
2481 rxdp->Control_1 |= RXD_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 off++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002483 if (off == (rxd_count[nic->rxd_mode] + 1))
2484 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002485 mac_control->rings[ring_no].rx_curr_put_info.offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002487 rxdp->Control_2 |= SET_RXD_MARKER;
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002488 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
2489 if (first_rxdp) {
2490 wmb();
2491 first_rxdp->Control_1 |= RXD_OWN_XENA;
2492 }
2493 first_rxdp = rxdp;
2494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 atomic_inc(&nic->rx_bufs_left[ring_no]);
2496 alloc_tab++;
2497 }
2498
2499 end:
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002500 /* Transfer ownership of first descriptor to adapter just before
2501 * exiting. Before that, use memory barrier so that ownership
2502 * and other fields are seen by adapter correctly.
2503 */
2504 if (first_rxdp) {
2505 wmb();
2506 first_rxdp->Control_1 |= RXD_OWN_XENA;
2507 }
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 return SUCCESS;
2510}
2511
Ananda Rajuda6971d2005-10-31 16:55:31 -05002512static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2513{
2514 struct net_device *dev = sp->dev;
2515 int j;
2516 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002517 struct RxD_t *rxdp;
2518 struct mac_info *mac_control;
2519 struct buffAdd *ba;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002520
2521 mac_control = &sp->mac_control;
2522 for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
2523 rxdp = mac_control->rings[ring_no].
2524 rx_blocks[blk].rxds[j].virt_addr;
2525 skb = (struct sk_buff *)
2526 ((unsigned long) rxdp->Host_Control);
2527 if (!skb) {
2528 continue;
2529 }
2530 if (sp->rxd_mode == RXD_MODE_1) {
2531 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002532 ((struct RxD1*)rxdp)->Buffer0_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002533 dev->mtu +
2534 HEADER_ETHERNET_II_802_3_SIZE
2535 + HEADER_802_2_SIZE +
2536 HEADER_SNAP_SIZE,
2537 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002538 memset(rxdp, 0, sizeof(struct RxD1));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002539 } else if(sp->rxd_mode == RXD_MODE_3B) {
2540 ba = &mac_control->rings[ring_no].
2541 ba[blk][j];
2542 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002543 ((struct RxD3*)rxdp)->Buffer0_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002544 BUF0_LEN,
2545 PCI_DMA_FROMDEVICE);
2546 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002547 ((struct RxD3*)rxdp)->Buffer1_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002548 BUF1_LEN,
2549 PCI_DMA_FROMDEVICE);
2550 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002551 ((struct RxD3*)rxdp)->Buffer2_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002552 dev->mtu + 4,
2553 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002554 memset(rxdp, 0, sizeof(struct RxD3));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002555 } else {
2556 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002557 ((struct RxD3*)rxdp)->Buffer0_ptr, BUF0_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002558 PCI_DMA_FROMDEVICE);
2559 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002560 ((struct RxD3*)rxdp)->Buffer1_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002561 l3l4hdr_size + 4,
2562 PCI_DMA_FROMDEVICE);
2563 pci_unmap_single(sp->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002564 ((struct RxD3*)rxdp)->Buffer2_ptr, dev->mtu,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002565 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002566 memset(rxdp, 0, sizeof(struct RxD3));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002567 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002568 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002569 dev_kfree_skb(skb);
2570 atomic_dec(&sp->rx_bufs_left[ring_no]);
2571 }
2572}
2573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002575 * free_rx_buffers - Frees all Rx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 * @sp: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002577 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 * This function will free all Rx buffers allocated by host.
2579 * Return Value:
2580 * NONE.
2581 */
2582
2583static void free_rx_buffers(struct s2io_nic *sp)
2584{
2585 struct net_device *dev = sp->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002586 int i, blk = 0, buf_cnt = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002587 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
2590 mac_control = &sp->mac_control;
2591 config = &sp->config;
2592
2593 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05002594 for (blk = 0; blk < rx_ring_sz[i]; blk++)
2595 free_rxd_blk(sp,i,blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002597 mac_control->rings[i].rx_curr_put_info.block_index = 0;
2598 mac_control->rings[i].rx_curr_get_info.block_index = 0;
2599 mac_control->rings[i].rx_curr_put_info.offset = 0;
2600 mac_control->rings[i].rx_curr_get_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 atomic_set(&sp->rx_bufs_left[i], 0);
2602 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
2603 dev->name, buf_cnt, i);
2604 }
2605}
2606
2607/**
2608 * s2io_poll - Rx interrupt handler for NAPI support
2609 * @dev : pointer to the device structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002610 * @budget : The number of packets that were budgeted to be processed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 * during one pass through the 'Poll" function.
2612 * Description:
2613 * Comes into picture only if NAPI support has been incorporated. It does
2614 * the same thing that rx_intr_handler does, but not in a interrupt context
2615 * also It will process only a given number of packets.
2616 * Return value:
2617 * 0 on success and 1 if there are No Rx packets to be processed.
2618 */
2619
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620static int s2io_poll(struct net_device *dev, int *budget)
2621{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002622 struct s2io_nic *nic = dev->priv;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002623 int pkt_cnt = 0, org_pkts_to_process;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002624 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 struct config_param *config;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002626 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002627 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002629 atomic_inc(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 mac_control = &nic->mac_control;
2631 config = &nic->config;
2632
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002633 nic->pkts_to_process = *budget;
2634 if (nic->pkts_to_process > dev->quota)
2635 nic->pkts_to_process = dev->quota;
2636 org_pkts_to_process = nic->pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002638 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
2639 readl(&bar0->rx_traffic_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
2641 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002642 rx_intr_handler(&mac_control->rings[i]);
2643 pkt_cnt = org_pkts_to_process - nic->pkts_to_process;
2644 if (!nic->pkts_to_process) {
2645 /* Quota for the current iteration has been met */
2646 goto no_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 }
2649 if (!pkt_cnt)
2650 pkt_cnt = 1;
2651
2652 dev->quota -= pkt_cnt;
2653 *budget -= pkt_cnt;
2654 netif_rx_complete(dev);
2655
2656 for (i = 0; i < config->rx_ring_num; i++) {
2657 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002658 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2659 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 break;
2661 }
2662 }
2663 /* Re enable the Rx interrupts. */
Ananda Rajuc92ca042006-04-21 19:18:03 -04002664 writeq(0x0, &bar0->rx_traffic_mask);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002665 readl(&bar0->rx_traffic_mask);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002666 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return 0;
2668
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002669no_rx:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 dev->quota -= pkt_cnt;
2671 *budget -= pkt_cnt;
2672
2673 for (i = 0; i < config->rx_ring_num; i++) {
2674 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002675 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2676 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 break;
2678 }
2679 }
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002680 atomic_dec(&nic->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 return 1;
2682}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002683
Ananda Rajub41477f2006-07-24 19:52:49 -04002684#ifdef CONFIG_NET_POLL_CONTROLLER
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002685/**
Ananda Rajub41477f2006-07-24 19:52:49 -04002686 * s2io_netpoll - netpoll event handler entry point
Brian Haley612eff02006-06-15 14:36:36 -04002687 * @dev : pointer to the device structure.
2688 * Description:
Ananda Rajub41477f2006-07-24 19:52:49 -04002689 * This function will be called by upper layer to check for events on the
2690 * interface in situations where interrupts are disabled. It is used for
2691 * specific in-kernel networking tasks, such as remote consoles and kernel
2692 * debugging over the network (example netdump in RedHat).
Brian Haley612eff02006-06-15 14:36:36 -04002693 */
Brian Haley612eff02006-06-15 14:36:36 -04002694static void s2io_netpoll(struct net_device *dev)
2695{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002696 struct s2io_nic *nic = dev->priv;
2697 struct mac_info *mac_control;
Brian Haley612eff02006-06-15 14:36:36 -04002698 struct config_param *config;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002699 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ananda Rajub41477f2006-07-24 19:52:49 -04002700 u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
Brian Haley612eff02006-06-15 14:36:36 -04002701 int i;
2702
2703 disable_irq(dev->irq);
2704
2705 atomic_inc(&nic->isr_cnt);
2706 mac_control = &nic->mac_control;
2707 config = &nic->config;
2708
Brian Haley612eff02006-06-15 14:36:36 -04002709 writeq(val64, &bar0->rx_traffic_int);
Ananda Rajub41477f2006-07-24 19:52:49 -04002710 writeq(val64, &bar0->tx_traffic_int);
Brian Haley612eff02006-06-15 14:36:36 -04002711
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002712 /* we need to free up the transmitted skbufs or else netpoll will
Ananda Rajub41477f2006-07-24 19:52:49 -04002713 * run out of skbs and will fail and eventually netpoll application such
2714 * as netdump will fail.
2715 */
2716 for (i = 0; i < config->tx_fifo_num; i++)
2717 tx_intr_handler(&mac_control->fifos[i]);
2718
2719 /* check for received packet and indicate up to network */
Brian Haley612eff02006-06-15 14:36:36 -04002720 for (i = 0; i < config->rx_ring_num; i++)
2721 rx_intr_handler(&mac_control->rings[i]);
2722
2723 for (i = 0; i < config->rx_ring_num; i++) {
2724 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002725 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2726 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n");
Brian Haley612eff02006-06-15 14:36:36 -04002727 break;
2728 }
2729 }
2730 atomic_dec(&nic->isr_cnt);
2731 enable_irq(dev->irq);
2732 return;
2733}
2734#endif
2735
2736/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 * rx_intr_handler - Rx interrupt handler
2738 * @nic: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002739 * Description:
2740 * If the interrupt is because of a received frame or if the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 * receive ring contains fresh as yet un-processed frames,this function is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002742 * called. It picks out the RxD at which place the last Rx processing had
2743 * stopped and sends the skb to the OSM's Rx handler and then increments
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 * the offset.
2745 * Return Value:
2746 * NONE.
2747 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002748static void rx_intr_handler(struct ring_info *ring_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002750 struct s2io_nic *nic = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 struct net_device *dev = (struct net_device *) nic->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002752 int get_block, put_block, put_offset;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002753 struct rx_curr_get_info get_info, put_info;
2754 struct RxD_t *rxdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 struct sk_buff *skb;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002756 int pkt_cnt = 0;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002757 int i;
2758
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002759 spin_lock(&nic->rx_lock);
2760 if (atomic_read(&nic->card_state) == CARD_DOWN) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002761 DBG_PRINT(INTR_DBG, "%s: %s going down for reset\n",
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002762 __FUNCTION__, dev->name);
2763 spin_unlock(&nic->rx_lock);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07002764 return;
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002765 }
2766
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002767 get_info = ring_data->rx_curr_get_info;
2768 get_block = get_info.block_index;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002769 memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002770 put_block = put_info.block_index;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002771 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002772 if (!napi) {
2773 spin_lock(&nic->put_lock);
2774 put_offset = ring_data->put_pos;
2775 spin_unlock(&nic->put_lock);
2776 } else
2777 put_offset = ring_data->put_pos;
2778
Ananda Rajuda6971d2005-10-31 16:55:31 -05002779 while (RXD_IS_UP2DT(rxdp)) {
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002780 /*
2781 * If your are next to put index then it's
2782 * FIFO full condition
2783 */
Ananda Rajuda6971d2005-10-31 16:55:31 -05002784 if ((get_block == put_block) &&
2785 (get_info.offset + 1) == put_info.offset) {
Ananda Raju75c30b12006-07-24 19:55:09 -04002786 DBG_PRINT(INTR_DBG, "%s: Ring Full\n",dev->name);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002787 break;
2788 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002789 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
2790 if (skb == NULL) {
2791 DBG_PRINT(ERR_DBG, "%s: The skb is ",
2792 dev->name);
2793 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002794 spin_unlock(&nic->rx_lock);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002795 return;
2796 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002797 if (nic->rxd_mode == RXD_MODE_1) {
2798 pci_unmap_single(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002799 ((struct RxD1*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002800 dev->mtu +
2801 HEADER_ETHERNET_II_802_3_SIZE +
2802 HEADER_802_2_SIZE +
2803 HEADER_SNAP_SIZE,
2804 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002805 } else if (nic->rxd_mode == RXD_MODE_3B) {
Ananda Raju75c30b12006-07-24 19:55:09 -04002806 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002807 ((struct RxD3*)rxdp)->Buffer0_ptr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002808 BUF0_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002809 pci_unmap_single(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002810 ((struct RxD3*)rxdp)->Buffer2_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002811 dev->mtu + 4,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002812 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002813 } else {
Ananda Raju75c30b12006-07-24 19:55:09 -04002814 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002815 ((struct RxD3*)rxdp)->Buffer0_ptr, BUF0_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002816 PCI_DMA_FROMDEVICE);
2817 pci_unmap_single(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002818 ((struct RxD3*)rxdp)->Buffer1_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002819 l3l4hdr_size + 4,
2820 PCI_DMA_FROMDEVICE);
2821 pci_unmap_single(nic->pdev, (dma_addr_t)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002822 ((struct RxD3*)rxdp)->Buffer2_ptr,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002823 dev->mtu, PCI_DMA_FROMDEVICE);
2824 }
Ananda Raju863c11a2006-04-21 19:03:13 -04002825 prefetch(skb->data);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002826 rx_osm_handler(ring_data, rxdp);
2827 get_info.offset++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002828 ring_data->rx_curr_get_info.offset = get_info.offset;
2829 rxdp = ring_data->rx_blocks[get_block].
2830 rxds[get_info.offset].virt_addr;
2831 if (get_info.offset == rxd_count[nic->rxd_mode]) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002832 get_info.offset = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002833 ring_data->rx_curr_get_info.offset = get_info.offset;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002834 get_block++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002835 if (get_block == ring_data->block_count)
2836 get_block = 0;
2837 ring_data->rx_curr_get_info.block_index = get_block;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002838 rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
2839 }
2840
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002841 nic->pkts_to_process -= 1;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002842 if ((napi) && (!nic->pkts_to_process))
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002843 break;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002844 pkt_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
2846 break;
2847 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002848 if (nic->lro) {
2849 /* Clear all LRO sessions before exiting */
2850 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002851 struct lro *lro = &nic->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002852 if (lro->in_use) {
2853 update_L3L4_header(nic, lro);
2854 queue_rx_frame(lro->parent);
2855 clear_lro_session(lro);
2856 }
2857 }
2858 }
2859
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002860 spin_unlock(&nic->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002862
2863/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 * tx_intr_handler - Transmit interrupt handler
2865 * @nic : device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002866 * Description:
2867 * If an interrupt was raised to indicate DMA complete of the
2868 * Tx packet, this function is called. It identifies the last TxD
2869 * whose buffer was freed and frees all skbs whose data have already
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 * DMA'ed into the NICs internal memory.
2871 * Return Value:
2872 * NONE
2873 */
2874
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002875static void tx_intr_handler(struct fifo_info *fifo_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002877 struct s2io_nic *nic = fifo_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 struct net_device *dev = (struct net_device *) nic->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002879 struct tx_curr_get_info get_info, put_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002881 struct TxD *txdlp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002883 get_info = fifo_data->tx_curr_get_info;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002884 memcpy(&put_info, &fifo_data->tx_curr_put_info, sizeof(put_info));
2885 txdlp = (struct TxD *) fifo_data->list_info[get_info.offset].
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002886 list_virt_addr;
2887 while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
2888 (get_info.offset != put_info.offset) &&
2889 (txdlp->Host_Control)) {
2890 /* Check for TxD errors */
2891 if (txdlp->Control_1 & TXD_T_CODE) {
2892 unsigned long long err;
2893 err = txdlp->Control_1 & TXD_T_CODE;
Ananda Rajubd1034f2006-04-21 19:20:22 -04002894 if (err & 0x1) {
2895 nic->mac_control.stats_info->sw_stat.
2896 parity_err_cnt++;
2897 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002898
2899 /* update t_code statistics */
2900 err >>= 48;
2901 switch(err) {
2902 case 2:
2903 nic->mac_control.stats_info->sw_stat.
2904 tx_buf_abort_cnt++;
2905 break;
2906
2907 case 3:
2908 nic->mac_control.stats_info->sw_stat.
2909 tx_desc_abort_cnt++;
2910 break;
2911
2912 case 7:
2913 nic->mac_control.stats_info->sw_stat.
2914 tx_parity_err_cnt++;
2915 break;
2916
2917 case 10:
2918 nic->mac_control.stats_info->sw_stat.
2919 tx_link_loss_cnt++;
2920 break;
2921
2922 case 15:
2923 nic->mac_control.stats_info->sw_stat.
2924 tx_list_proc_err_cnt++;
2925 break;
2926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002928
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002929 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002930 if (skb == NULL) {
2931 DBG_PRINT(ERR_DBG, "%s: Null skb ",
2932 __FUNCTION__);
2933 DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
2934 return;
2935 }
2936
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002937 /* Updating the statistics block */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002938 nic->stats.tx_bytes += skb->len;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002939 nic->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002940 dev_kfree_skb_irq(skb);
2941
2942 get_info.offset++;
Ananda Raju863c11a2006-04-21 19:03:13 -04002943 if (get_info.offset == get_info.fifo_len + 1)
2944 get_info.offset = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002945 txdlp = (struct TxD *) fifo_data->list_info
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002946 [get_info.offset].list_virt_addr;
2947 fifo_data->tx_curr_get_info.offset =
2948 get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 }
2950
2951 spin_lock(&nic->tx_lock);
2952 if (netif_queue_stopped(dev))
2953 netif_wake_queue(dev);
2954 spin_unlock(&nic->tx_lock);
2955}
2956
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002957/**
Ananda Rajubd1034f2006-04-21 19:20:22 -04002958 * s2io_mdio_write - Function to write in to MDIO registers
2959 * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
2960 * @addr : address value
2961 * @value : data value
2962 * @dev : pointer to net_device structure
2963 * Description:
2964 * This function is used to write values to the MDIO registers
2965 * NONE
2966 */
2967static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value, struct net_device *dev)
2968{
2969 u64 val64 = 0x0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002970 struct s2io_nic *sp = dev->priv;
2971 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajubd1034f2006-04-21 19:20:22 -04002972
2973 //address transaction
2974 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
2975 | MDIO_MMD_DEV_ADDR(mmd_type)
2976 | MDIO_MMS_PRT_ADDR(0x0);
2977 writeq(val64, &bar0->mdio_control);
2978 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
2979 writeq(val64, &bar0->mdio_control);
2980 udelay(100);
2981
2982 //Data transaction
2983 val64 = 0x0;
2984 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
2985 | MDIO_MMD_DEV_ADDR(mmd_type)
2986 | MDIO_MMS_PRT_ADDR(0x0)
2987 | MDIO_MDIO_DATA(value)
2988 | MDIO_OP(MDIO_OP_WRITE_TRANS);
2989 writeq(val64, &bar0->mdio_control);
2990 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
2991 writeq(val64, &bar0->mdio_control);
2992 udelay(100);
2993
2994 val64 = 0x0;
2995 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
2996 | MDIO_MMD_DEV_ADDR(mmd_type)
2997 | MDIO_MMS_PRT_ADDR(0x0)
2998 | MDIO_OP(MDIO_OP_READ_TRANS);
2999 writeq(val64, &bar0->mdio_control);
3000 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3001 writeq(val64, &bar0->mdio_control);
3002 udelay(100);
3003
3004}
3005
3006/**
3007 * s2io_mdio_read - Function to write in to MDIO registers
3008 * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
3009 * @addr : address value
3010 * @dev : pointer to net_device structure
3011 * Description:
3012 * This function is used to read values to the MDIO registers
3013 * NONE
3014 */
3015static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
3016{
3017 u64 val64 = 0x0;
3018 u64 rval64 = 0x0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003019 struct s2io_nic *sp = dev->priv;
3020 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003021
3022 /* address transaction */
3023 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3024 | MDIO_MMD_DEV_ADDR(mmd_type)
3025 | MDIO_MMS_PRT_ADDR(0x0);
3026 writeq(val64, &bar0->mdio_control);
3027 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3028 writeq(val64, &bar0->mdio_control);
3029 udelay(100);
3030
3031 /* Data transaction */
3032 val64 = 0x0;
3033 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3034 | MDIO_MMD_DEV_ADDR(mmd_type)
3035 | MDIO_MMS_PRT_ADDR(0x0)
3036 | MDIO_OP(MDIO_OP_READ_TRANS);
3037 writeq(val64, &bar0->mdio_control);
3038 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3039 writeq(val64, &bar0->mdio_control);
3040 udelay(100);
3041
3042 /* Read the value from regs */
3043 rval64 = readq(&bar0->mdio_control);
3044 rval64 = rval64 & 0xFFFF0000;
3045 rval64 = rval64 >> 16;
3046 return rval64;
3047}
3048/**
3049 * s2io_chk_xpak_counter - Function to check the status of the xpak counters
3050 * @counter : couter value to be updated
3051 * @flag : flag to indicate the status
3052 * @type : counter type
3053 * Description:
3054 * This function is to check the status of the xpak counters value
3055 * NONE
3056 */
3057
3058static void s2io_chk_xpak_counter(u64 *counter, u64 * regs_stat, u32 index, u16 flag, u16 type)
3059{
3060 u64 mask = 0x3;
3061 u64 val64;
3062 int i;
3063 for(i = 0; i <index; i++)
3064 mask = mask << 0x2;
3065
3066 if(flag > 0)
3067 {
3068 *counter = *counter + 1;
3069 val64 = *regs_stat & mask;
3070 val64 = val64 >> (index * 0x2);
3071 val64 = val64 + 1;
3072 if(val64 == 3)
3073 {
3074 switch(type)
3075 {
3076 case 1:
3077 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3078 "service. Excessive temperatures may "
3079 "result in premature transceiver "
3080 "failure \n");
3081 break;
3082 case 2:
3083 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3084 "service Excessive bias currents may "
3085 "indicate imminent laser diode "
3086 "failure \n");
3087 break;
3088 case 3:
3089 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3090 "service Excessive laser output "
3091 "power may saturate far-end "
3092 "receiver\n");
3093 break;
3094 default:
3095 DBG_PRINT(ERR_DBG, "Incorrect XPAK Alarm "
3096 "type \n");
3097 }
3098 val64 = 0x0;
3099 }
3100 val64 = val64 << (index * 0x2);
3101 *regs_stat = (*regs_stat & (~mask)) | (val64);
3102
3103 } else {
3104 *regs_stat = *regs_stat & (~mask);
3105 }
3106}
3107
3108/**
3109 * s2io_updt_xpak_counter - Function to update the xpak counters
3110 * @dev : pointer to net_device struct
3111 * Description:
3112 * This function is to upate the status of the xpak counters value
3113 * NONE
3114 */
3115static void s2io_updt_xpak_counter(struct net_device *dev)
3116{
3117 u16 flag = 0x0;
3118 u16 type = 0x0;
3119 u16 val16 = 0x0;
3120 u64 val64 = 0x0;
3121 u64 addr = 0x0;
3122
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003123 struct s2io_nic *sp = dev->priv;
3124 struct stat_block *stat_info = sp->mac_control.stats_info;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003125
3126 /* Check the communication with the MDIO slave */
3127 addr = 0x0000;
3128 val64 = 0x0;
3129 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3130 if((val64 == 0xFFFF) || (val64 == 0x0000))
3131 {
3132 DBG_PRINT(ERR_DBG, "ERR: MDIO slave access failed - "
3133 "Returned %llx\n", (unsigned long long)val64);
3134 return;
3135 }
3136
3137 /* Check for the expecte value of 2040 at PMA address 0x0000 */
3138 if(val64 != 0x2040)
3139 {
3140 DBG_PRINT(ERR_DBG, "Incorrect value at PMA address 0x0000 - ");
3141 DBG_PRINT(ERR_DBG, "Returned: %llx- Expected: 0x2040\n",
3142 (unsigned long long)val64);
3143 return;
3144 }
3145
3146 /* Loading the DOM register to MDIO register */
3147 addr = 0xA100;
3148 s2io_mdio_write(MDIO_MMD_PMA_DEV_ADDR, addr, val16, dev);
3149 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3150
3151 /* Reading the Alarm flags */
3152 addr = 0xA070;
3153 val64 = 0x0;
3154 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3155
3156 flag = CHECKBIT(val64, 0x7);
3157 type = 1;
3158 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_transceiver_temp_high,
3159 &stat_info->xpak_stat.xpak_regs_stat,
3160 0x0, flag, type);
3161
3162 if(CHECKBIT(val64, 0x6))
3163 stat_info->xpak_stat.alarm_transceiver_temp_low++;
3164
3165 flag = CHECKBIT(val64, 0x3);
3166 type = 2;
3167 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_bias_current_high,
3168 &stat_info->xpak_stat.xpak_regs_stat,
3169 0x2, flag, type);
3170
3171 if(CHECKBIT(val64, 0x2))
3172 stat_info->xpak_stat.alarm_laser_bias_current_low++;
3173
3174 flag = CHECKBIT(val64, 0x1);
3175 type = 3;
3176 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_output_power_high,
3177 &stat_info->xpak_stat.xpak_regs_stat,
3178 0x4, flag, type);
3179
3180 if(CHECKBIT(val64, 0x0))
3181 stat_info->xpak_stat.alarm_laser_output_power_low++;
3182
3183 /* Reading the Warning flags */
3184 addr = 0xA074;
3185 val64 = 0x0;
3186 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3187
3188 if(CHECKBIT(val64, 0x7))
3189 stat_info->xpak_stat.warn_transceiver_temp_high++;
3190
3191 if(CHECKBIT(val64, 0x6))
3192 stat_info->xpak_stat.warn_transceiver_temp_low++;
3193
3194 if(CHECKBIT(val64, 0x3))
3195 stat_info->xpak_stat.warn_laser_bias_current_high++;
3196
3197 if(CHECKBIT(val64, 0x2))
3198 stat_info->xpak_stat.warn_laser_bias_current_low++;
3199
3200 if(CHECKBIT(val64, 0x1))
3201 stat_info->xpak_stat.warn_laser_output_power_high++;
3202
3203 if(CHECKBIT(val64, 0x0))
3204 stat_info->xpak_stat.warn_laser_output_power_low++;
3205}
3206
3207/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 * alarm_intr_handler - Alarm Interrrupt handler
3209 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003210 * Description: If the interrupt was neither because of Rx packet or Tx
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 * complete, this function is called. If the interrupt was to indicate
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003212 * a loss of link, the OSM link status handler is invoked for any other
3213 * alarm interrupt the block that raised the interrupt is displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 * and a H/W reset is issued.
3215 * Return Value:
3216 * NONE
3217*/
3218
3219static void alarm_intr_handler(struct s2io_nic *nic)
3220{
3221 struct net_device *dev = (struct net_device *) nic->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003222 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 register u64 val64 = 0, err_reg = 0;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003224 u64 cnt;
3225 int i;
Sivakumar Subramani372cc592007-01-31 13:32:57 -05003226 if (atomic_read(&nic->card_state) == CARD_DOWN)
3227 return;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003228 nic->mac_control.stats_info->sw_stat.ring_full_cnt = 0;
3229 /* Handling the XPAK counters update */
3230 if(nic->mac_control.stats_info->xpak_stat.xpak_timer_count < 72000) {
3231 /* waiting for an hour */
3232 nic->mac_control.stats_info->xpak_stat.xpak_timer_count++;
3233 } else {
3234 s2io_updt_xpak_counter(dev);
3235 /* reset the count to zero */
3236 nic->mac_control.stats_info->xpak_stat.xpak_timer_count = 0;
3237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
3239 /* Handling link status change error Intr */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07003240 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
3241 err_reg = readq(&bar0->mac_rmac_err_reg);
3242 writeq(err_reg, &bar0->mac_rmac_err_reg);
3243 if (err_reg & RMAC_LINK_STATE_CHANGE_INT) {
3244 schedule_work(&nic->set_link_task);
3245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 }
3247
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003248 /* Handling Ecc errors */
3249 val64 = readq(&bar0->mc_err_reg);
3250 writeq(val64, &bar0->mc_err_reg);
3251 if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
3252 if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003253 nic->mac_control.stats_info->sw_stat.
3254 double_ecc_errs++;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003255 DBG_PRINT(INIT_DBG, "%s: Device indicates ",
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003256 dev->name);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003257 DBG_PRINT(INIT_DBG, "double ECC error!!\n");
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07003258 if (nic->device_type != XFRAME_II_DEVICE) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003259 /* Reset XframeI only if critical error */
3260 if (val64 & (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
3261 MC_ERR_REG_MIRI_ECC_DB_ERR_1)) {
3262 netif_stop_queue(dev);
3263 schedule_work(&nic->rst_timer_task);
Ananda Rajubd1034f2006-04-21 19:20:22 -04003264 nic->mac_control.stats_info->sw_stat.
3265 soft_reset_cnt++;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003266 }
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07003267 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003268 } else {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003269 nic->mac_control.stats_info->sw_stat.
3270 single_ecc_errs++;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003271 }
3272 }
3273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 /* In case of a serious error, the device will be Reset. */
3275 val64 = readq(&bar0->serr_source);
3276 if (val64 & SERR_SOURCE_ANY) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04003277 nic->mac_control.stats_info->sw_stat.serious_err_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003279 DBG_PRINT(ERR_DBG, "serious error %llx!!\n",
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07003280 (unsigned long long)val64);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 netif_stop_queue(dev);
3282 schedule_work(&nic->rst_timer_task);
Ananda Rajubd1034f2006-04-21 19:20:22 -04003283 nic->mac_control.stats_info->sw_stat.soft_reset_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
3285
3286 /*
3287 * Also as mentioned in the latest Errata sheets if the PCC_FB_ECC
3288 * Error occurs, the adapter will be recycled by disabling the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003289 * adapter enable bit and enabling it again after the device
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 * becomes Quiescent.
3291 */
3292 val64 = readq(&bar0->pcc_err_reg);
3293 writeq(val64, &bar0->pcc_err_reg);
3294 if (val64 & PCC_FB_ECC_DB_ERR) {
3295 u64 ac = readq(&bar0->adapter_control);
3296 ac &= ~(ADAPTER_CNTL_EN);
3297 writeq(ac, &bar0->adapter_control);
3298 ac = readq(&bar0->adapter_control);
3299 schedule_work(&nic->set_link_task);
3300 }
Ananda Rajubd1034f2006-04-21 19:20:22 -04003301 /* Check for data parity error */
3302 val64 = readq(&bar0->pic_int_status);
3303 if (val64 & PIC_INT_GPIO) {
3304 val64 = readq(&bar0->gpio_int_reg);
3305 if (val64 & GPIO_INT_REG_DP_ERR_INT) {
3306 nic->mac_control.stats_info->sw_stat.parity_err_cnt++;
3307 schedule_work(&nic->rst_timer_task);
3308 nic->mac_control.stats_info->sw_stat.soft_reset_cnt++;
3309 }
3310 }
3311
3312 /* Check for ring full counter */
3313 if (nic->device_type & XFRAME_II_DEVICE) {
3314 val64 = readq(&bar0->ring_bump_counter1);
3315 for (i=0; i<4; i++) {
3316 cnt = ( val64 & vBIT(0xFFFF,(i*16),16));
3317 cnt >>= 64 - ((i+1)*16);
3318 nic->mac_control.stats_info->sw_stat.ring_full_cnt
3319 += cnt;
3320 }
3321
3322 val64 = readq(&bar0->ring_bump_counter2);
3323 for (i=0; i<4; i++) {
3324 cnt = ( val64 & vBIT(0xFFFF,(i*16),16));
3325 cnt >>= 64 - ((i+1)*16);
3326 nic->mac_control.stats_info->sw_stat.ring_full_cnt
3327 += cnt;
3328 }
3329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
3331 /* Other type of interrupts are not being handled now, TODO */
3332}
3333
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003334/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 * wait_for_cmd_complete - waits for a command to complete.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003336 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003338 * Description: Function that waits for a command to Write into RMAC
3339 * ADDR DATA registers to be completed and returns either success or
3340 * error depending on whether the command was complete or not.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 * Return value:
3342 * SUCCESS on success and FAILURE on failure.
3343 */
3344
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003345static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
3346 int bit_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347{
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003348 int ret = FAILURE, cnt = 0, delay = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 u64 val64;
3350
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003351 if ((bit_state != S2IO_BIT_RESET) && (bit_state != S2IO_BIT_SET))
3352 return FAILURE;
3353
3354 do {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003355 val64 = readq(addr);
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003356 if (bit_state == S2IO_BIT_RESET) {
3357 if (!(val64 & busy_bit)) {
3358 ret = SUCCESS;
3359 break;
3360 }
3361 } else {
3362 if (!(val64 & busy_bit)) {
3363 ret = SUCCESS;
3364 break;
3365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003367
3368 if(in_interrupt())
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003369 mdelay(delay);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003370 else
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003371 msleep(delay);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003372
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003373 if (++cnt >= 10)
3374 delay = 50;
3375 } while (cnt < 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 return ret;
3377}
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003378/*
3379 * check_pci_device_id - Checks if the device id is supported
3380 * @id : device id
3381 * Description: Function to check if the pci device id is supported by driver.
3382 * Return value: Actual device id if supported else PCI_ANY_ID
3383 */
3384static u16 check_pci_device_id(u16 id)
3385{
3386 switch (id) {
3387 case PCI_DEVICE_ID_HERC_WIN:
3388 case PCI_DEVICE_ID_HERC_UNI:
3389 return XFRAME_II_DEVICE;
3390 case PCI_DEVICE_ID_S2IO_UNI:
3391 case PCI_DEVICE_ID_S2IO_WIN:
3392 return XFRAME_I_DEVICE;
3393 default:
3394 return PCI_ANY_ID;
3395 }
3396}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003398/**
3399 * s2io_reset - Resets the card.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 * @sp : private member of the device structure.
3401 * Description: Function to Reset the card. This function then also
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003402 * restores the previously saved PCI configuration space registers as
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 * the card reset also resets the configuration space.
3404 * Return value:
3405 * void.
3406 */
3407
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003408static void s2io_reset(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003410 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 u64 val64;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003412 u16 subid, pci_cmd;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003413 int i;
3414 u16 val16;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003415 unsigned long long up_cnt, down_cnt, up_time, down_time, reset_cnt;
3416 unsigned long long mem_alloc_cnt, mem_free_cnt, watchdog_cnt;
3417
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003418 DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n",
3419 __FUNCTION__, sp->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003421 /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07003422 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003423
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003424 if (sp->device_type == XFRAME_II_DEVICE) {
3425 int ret;
3426 ret = pci_set_power_state(sp->pdev, 3);
3427 if (!ret)
3428 ret = pci_set_power_state(sp->pdev, 0);
3429 else {
3430 DBG_PRINT(ERR_DBG,"%s PME based SW_Reset failed!\n",
3431 __FUNCTION__);
3432 goto old_way;
3433 }
3434 msleep(20);
3435 goto new_way;
3436 }
3437old_way:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 val64 = SW_RESET_ALL;
3439 writeq(val64, &bar0->sw_reset);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003440new_way:
Ananda Rajuc92ca042006-04-21 19:18:03 -04003441 if (strstr(sp->product_name, "CX4")) {
3442 msleep(750);
3443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 msleep(250);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003445 for (i = 0; i < S2IO_MAX_PCI_CONFIG_SPACE_REINIT; i++) {
3446
3447 /* Restore the PCI state saved during initialization. */
3448 pci_restore_state(sp->pdev);
3449 pci_read_config_word(sp->pdev, 0x2, &val16);
3450 if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
3451 break;
3452 msleep(200);
3453 }
3454
3455 if (check_pci_device_id(val16) == (u16)PCI_ANY_ID) {
3456 DBG_PRINT(ERR_DBG,"%s SW_Reset failed!\n", __FUNCTION__);
3457 }
3458
3459 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, pci_cmd);
3460
3461 s2io_init_pci(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003463 /* Set swapper to enable I/O register access */
3464 s2io_set_swapper(sp);
3465
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003466 /* Restore the MSIX table entries from local variables */
3467 restore_xmsi_data(sp);
3468
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003469 /* Clear certain PCI/PCI-X fields after reset */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003470 if (sp->device_type == XFRAME_II_DEVICE) {
Ananda Rajub41477f2006-07-24 19:52:49 -04003471 /* Clear "detected parity error" bit */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003472 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003473
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003474 /* Clearing PCIX Ecc status register */
3475 pci_write_config_dword(sp->pdev, 0x68, 0x7C);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003476
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003477 /* Clearing PCI_STATUS error reflected here */
3478 writeq(BIT(62), &bar0->txpic_int_reg);
3479 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003480
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003481 /* Reset device statistics maintained by OS */
3482 memset(&sp->stats, 0, sizeof (struct net_device_stats));
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003483
3484 up_cnt = sp->mac_control.stats_info->sw_stat.link_up_cnt;
3485 down_cnt = sp->mac_control.stats_info->sw_stat.link_down_cnt;
3486 up_time = sp->mac_control.stats_info->sw_stat.link_up_time;
3487 down_time = sp->mac_control.stats_info->sw_stat.link_down_time;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003488 reset_cnt = sp->mac_control.stats_info->sw_stat.soft_reset_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003489 mem_alloc_cnt = sp->mac_control.stats_info->sw_stat.mem_allocated;
3490 mem_free_cnt = sp->mac_control.stats_info->sw_stat.mem_freed;
3491 watchdog_cnt = sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt;
3492 /* save link up/down time/cnt, reset/memory/watchdog cnt */
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003493 memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block));
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003494 /* restore link up/down time/cnt, reset/memory/watchdog cnt */
3495 sp->mac_control.stats_info->sw_stat.link_up_cnt = up_cnt;
3496 sp->mac_control.stats_info->sw_stat.link_down_cnt = down_cnt;
3497 sp->mac_control.stats_info->sw_stat.link_up_time = up_time;
3498 sp->mac_control.stats_info->sw_stat.link_down_time = down_time;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003499 sp->mac_control.stats_info->sw_stat.soft_reset_cnt = reset_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003500 sp->mac_control.stats_info->sw_stat.mem_allocated = mem_alloc_cnt;
3501 sp->mac_control.stats_info->sw_stat.mem_freed = mem_free_cnt;
3502 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt = watchdog_cnt;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003503
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 /* SXE-002: Configure link and activity LED to turn it off */
3505 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07003506 if (((subid & 0xFF) >= 0x07) &&
3507 (sp->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 val64 = readq(&bar0->gpio_control);
3509 val64 |= 0x0000800000000000ULL;
3510 writeq(val64, &bar0->gpio_control);
3511 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01003512 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 }
3514
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07003515 /*
3516 * Clear spurious ECC interrupts that would have occured on
3517 * XFRAME II cards after reset.
3518 */
3519 if (sp->device_type == XFRAME_II_DEVICE) {
3520 val64 = readq(&bar0->pcc_err_reg);
3521 writeq(val64, &bar0->pcc_err_reg);
3522 }
3523
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05003524 /* restore the previously assigned mac address */
3525 s2io_set_mac_addr(sp->dev, (u8 *)&sp->def_mac_addr[0].mac_addr);
3526
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 sp->device_enabled_once = FALSE;
3528}
3529
3530/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003531 * s2io_set_swapper - to set the swapper controle on the card
3532 * @sp : private member of the device structure,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 * pointer to the s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003534 * Description: Function to set the swapper control on the card
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 * correctly depending on the 'endianness' of the system.
3536 * Return value:
3537 * SUCCESS on success and FAILURE on failure.
3538 */
3539
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003540static int s2io_set_swapper(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541{
3542 struct net_device *dev = sp->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003543 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 u64 val64, valt, valr;
3545
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003546 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 * Set proper endian settings and verify the same by reading
3548 * the PIF Feed-back register.
3549 */
3550
3551 val64 = readq(&bar0->pif_rd_swapper_fb);
3552 if (val64 != 0x0123456789ABCDEFULL) {
3553 int i = 0;
3554 u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
3555 0x8100008181000081ULL, /* FE=1, SE=0 */
3556 0x4200004242000042ULL, /* FE=0, SE=1 */
3557 0}; /* FE=0, SE=0 */
3558
3559 while(i<4) {
3560 writeq(value[i], &bar0->swapper_ctrl);
3561 val64 = readq(&bar0->pif_rd_swapper_fb);
3562 if (val64 == 0x0123456789ABCDEFULL)
3563 break;
3564 i++;
3565 }
3566 if (i == 4) {
3567 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3568 dev->name);
3569 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3570 (unsigned long long) val64);
3571 return FAILURE;
3572 }
3573 valr = value[i];
3574 } else {
3575 valr = readq(&bar0->swapper_ctrl);
3576 }
3577
3578 valt = 0x0123456789ABCDEFULL;
3579 writeq(valt, &bar0->xmsi_address);
3580 val64 = readq(&bar0->xmsi_address);
3581
3582 if(val64 != valt) {
3583 int i = 0;
3584 u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
3585 0x0081810000818100ULL, /* FE=1, SE=0 */
3586 0x0042420000424200ULL, /* FE=0, SE=1 */
3587 0}; /* FE=0, SE=0 */
3588
3589 while(i<4) {
3590 writeq((value[i] | valr), &bar0->swapper_ctrl);
3591 writeq(valt, &bar0->xmsi_address);
3592 val64 = readq(&bar0->xmsi_address);
3593 if(val64 == valt)
3594 break;
3595 i++;
3596 }
3597 if(i == 4) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003598 unsigned long long x = val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003600 DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return FAILURE;
3602 }
3603 }
3604 val64 = readq(&bar0->swapper_ctrl);
3605 val64 &= 0xFFFF000000000000ULL;
3606
3607#ifdef __BIG_ENDIAN
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003608 /*
3609 * The device by default set to a big endian format, so a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 * big endian driver need not set anything.
3611 */
3612 val64 |= (SWAPPER_CTRL_TXP_FE |
3613 SWAPPER_CTRL_TXP_SE |
3614 SWAPPER_CTRL_TXD_R_FE |
3615 SWAPPER_CTRL_TXD_W_FE |
3616 SWAPPER_CTRL_TXF_R_FE |
3617 SWAPPER_CTRL_RXD_R_FE |
3618 SWAPPER_CTRL_RXD_W_FE |
3619 SWAPPER_CTRL_RXF_W_FE |
3620 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Andrew Morton92383342005-10-16 00:11:29 -07003622 if (sp->intr_type == INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003623 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 writeq(val64, &bar0->swapper_ctrl);
3625#else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003626 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 * Initially we enable all bits to make it accessible by the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003628 * driver, then we selectively enable only those bits that
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 * we want to set.
3630 */
3631 val64 |= (SWAPPER_CTRL_TXP_FE |
3632 SWAPPER_CTRL_TXP_SE |
3633 SWAPPER_CTRL_TXD_R_FE |
3634 SWAPPER_CTRL_TXD_R_SE |
3635 SWAPPER_CTRL_TXD_W_FE |
3636 SWAPPER_CTRL_TXD_W_SE |
3637 SWAPPER_CTRL_TXF_R_FE |
3638 SWAPPER_CTRL_RXD_R_FE |
3639 SWAPPER_CTRL_RXD_R_SE |
3640 SWAPPER_CTRL_RXD_W_FE |
3641 SWAPPER_CTRL_RXD_W_SE |
3642 SWAPPER_CTRL_RXF_W_FE |
3643 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003645 if (sp->intr_type == INTA)
3646 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 writeq(val64, &bar0->swapper_ctrl);
3648#endif
3649 val64 = readq(&bar0->swapper_ctrl);
3650
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003651 /*
3652 * Verifying if endian settings are accurate by reading a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 * feedback register.
3654 */
3655 val64 = readq(&bar0->pif_rd_swapper_fb);
3656 if (val64 != 0x0123456789ABCDEFULL) {
3657 /* Endian settings are incorrect, calls for another dekko. */
3658 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3659 dev->name);
3660 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3661 (unsigned long long) val64);
3662 return FAILURE;
3663 }
3664
3665 return SUCCESS;
3666}
3667
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003668static int wait_for_msix_trans(struct s2io_nic *nic, int i)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003669{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003670 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003671 u64 val64;
3672 int ret = 0, cnt = 0;
3673
3674 do {
3675 val64 = readq(&bar0->xmsi_access);
3676 if (!(val64 & BIT(15)))
3677 break;
3678 mdelay(1);
3679 cnt++;
3680 } while(cnt < 5);
3681 if (cnt == 5) {
3682 DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
3683 ret = 1;
3684 }
3685
3686 return ret;
3687}
3688
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003689static void restore_xmsi_data(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003690{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003691 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003692 u64 val64;
3693 int i;
3694
Ananda Raju75c30b12006-07-24 19:55:09 -04003695 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003696 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3697 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
3698 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
3699 writeq(val64, &bar0->xmsi_access);
3700 if (wait_for_msix_trans(nic, i)) {
3701 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3702 continue;
3703 }
3704 }
3705}
3706
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003707static void store_xmsi_data(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003708{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003709 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003710 u64 val64, addr, data;
3711 int i;
3712
3713 /* Store and display */
Ananda Raju75c30b12006-07-24 19:55:09 -04003714 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003715 val64 = (BIT(15) | vBIT(i, 26, 6));
3716 writeq(val64, &bar0->xmsi_access);
3717 if (wait_for_msix_trans(nic, i)) {
3718 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3719 continue;
3720 }
3721 addr = readq(&bar0->xmsi_address);
3722 data = readq(&bar0->xmsi_data);
3723 if (addr && data) {
3724 nic->msix_info[i].addr = addr;
3725 nic->msix_info[i].data = data;
3726 }
3727 }
3728}
3729
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003730int s2io_enable_msi(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003731{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003732 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003733 u16 msi_ctrl, msg_val;
3734 struct config_param *config = &nic->config;
3735 struct net_device *dev = nic->dev;
3736 u64 val64, tx_mat, rx_mat;
3737 int i, err;
3738
3739 val64 = readq(&bar0->pic_control);
3740 val64 &= ~BIT(1);
3741 writeq(val64, &bar0->pic_control);
3742
3743 err = pci_enable_msi(nic->pdev);
3744 if (err) {
3745 DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
3746 nic->dev->name);
3747 return err;
3748 }
3749
3750 /*
3751 * Enable MSI and use MSI-1 in stead of the standard MSI-0
3752 * for interrupt handling.
3753 */
3754 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3755 msg_val ^= 0x1;
3756 pci_write_config_word(nic->pdev, 0x4c, msg_val);
3757 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3758
3759 pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
3760 msi_ctrl |= 0x10;
3761 pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
3762
3763 /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
3764 tx_mat = readq(&bar0->tx_mat0_n[0]);
3765 for (i=0; i<config->tx_fifo_num; i++) {
3766 tx_mat |= TX_MAT_SET(i, 1);
3767 }
3768 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3769
3770 rx_mat = readq(&bar0->rx_mat);
3771 for (i=0; i<config->rx_ring_num; i++) {
3772 rx_mat |= RX_MAT_SET(i, 1);
3773 }
3774 writeq(rx_mat, &bar0->rx_mat);
3775
3776 dev->irq = nic->pdev->irq;
3777 return 0;
3778}
3779
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003780static int s2io_enable_msi_x(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003781{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003782 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003783 u64 tx_mat, rx_mat;
3784 u16 msi_control; /* Temp variable */
3785 int ret, i, j, msix_indx = 1;
3786
3787 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
3788 GFP_KERNEL);
3789 if (nic->entries == NULL) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003790 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
3791 __FUNCTION__);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04003792 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003793 return -ENOMEM;
3794 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003795 nic->mac_control.stats_info->sw_stat.mem_allocated
3796 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3797 memset(nic->entries, 0,MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003798
3799 nic->s2io_entries =
3800 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
3801 GFP_KERNEL);
3802 if (nic->s2io_entries == NULL) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003803 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
3804 __FUNCTION__);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04003805 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003806 kfree(nic->entries);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003807 nic->mac_control.stats_info->sw_stat.mem_freed
3808 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003809 return -ENOMEM;
3810 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003811 nic->mac_control.stats_info->sw_stat.mem_allocated
3812 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003813 memset(nic->s2io_entries, 0,
3814 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3815
3816 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3817 nic->entries[i].entry = i;
3818 nic->s2io_entries[i].entry = i;
3819 nic->s2io_entries[i].arg = NULL;
3820 nic->s2io_entries[i].in_use = 0;
3821 }
3822
3823 tx_mat = readq(&bar0->tx_mat0_n[0]);
3824 for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
3825 tx_mat |= TX_MAT_SET(i, msix_indx);
3826 nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
3827 nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
3828 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3829 }
3830 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3831
3832 if (!nic->config.bimodal) {
3833 rx_mat = readq(&bar0->rx_mat);
3834 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3835 rx_mat |= RX_MAT_SET(j, msix_indx);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003836 nic->s2io_entries[msix_indx].arg
3837 = &nic->mac_control.rings[j];
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003838 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3839 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3840 }
3841 writeq(rx_mat, &bar0->rx_mat);
3842 } else {
3843 tx_mat = readq(&bar0->tx_mat0_n[7]);
3844 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3845 tx_mat |= TX_MAT_SET(i, msix_indx);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003846 nic->s2io_entries[msix_indx].arg
3847 = &nic->mac_control.rings[j];
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003848 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3849 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3850 }
3851 writeq(tx_mat, &bar0->tx_mat0_n[7]);
3852 }
3853
Ananda Rajuc92ca042006-04-21 19:18:03 -04003854 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003855 ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003856 /* We fail init if error or we get less vectors than min required */
3857 if (ret >= (nic->config.tx_fifo_num + nic->config.rx_ring_num + 1)) {
3858 nic->avail_msix_vectors = ret;
3859 ret = pci_enable_msix(nic->pdev, nic->entries, ret);
3860 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003861 if (ret) {
3862 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3863 kfree(nic->entries);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003864 nic->mac_control.stats_info->sw_stat.mem_freed
3865 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003866 kfree(nic->s2io_entries);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003867 nic->mac_control.stats_info->sw_stat.mem_freed
3868 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003869 nic->entries = NULL;
3870 nic->s2io_entries = NULL;
Ananda Rajuc92ca042006-04-21 19:18:03 -04003871 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003872 return -ENOMEM;
3873 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003874 if (!nic->avail_msix_vectors)
3875 nic->avail_msix_vectors = MAX_REQUESTED_MSI_X;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003876
3877 /*
3878 * To enable MSI-X, MSI also needs to be enabled, due to a bug
3879 * in the herc NIC. (Temp change, needs to be removed later)
3880 */
3881 pci_read_config_word(nic->pdev, 0x42, &msi_control);
3882 msi_control |= 0x1; /* Enable MSI */
3883 pci_write_config_word(nic->pdev, 0x42, msi_control);
3884
3885 return 0;
3886}
3887
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888/* ********************************************************* *
3889 * Functions defined below concern the OS part of the driver *
3890 * ********************************************************* */
3891
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003892/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 * s2io_open - open entry point of the driver
3894 * @dev : pointer to the device structure.
3895 * Description:
3896 * This function is the open entry point of the driver. It mainly calls a
3897 * function to allocate Rx buffers and inserts them into the buffer
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003898 * descriptors and then enables the Rx part of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 * Return value:
3900 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3901 * file on failure.
3902 */
3903
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003904static int s2io_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003906 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 int err = 0;
3908
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003909 /*
3910 * Make sure you have link off by default every time
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 * Nic is initialized
3912 */
3913 netif_carrier_off(dev);
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003914 sp->last_link_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
3916 /* Initialize H/W and enable interrupts */
Ananda Rajuc92ca042006-04-21 19:18:03 -04003917 err = s2io_card_up(sp);
3918 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
3920 dev->name);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07003921 goto hw_init_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 }
3923
3924 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
3925 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
Ananda Rajue6a8fee2006-07-06 23:58:23 -07003926 s2io_card_down(sp);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003927 err = -ENODEV;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07003928 goto hw_init_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 }
3930
3931 netif_start_queue(dev);
3932 return 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003933
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003934hw_init_failed:
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003935 if (sp->intr_type == MSI_X) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003936 if (sp->entries) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003937 kfree(sp->entries);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003938 sp->mac_control.stats_info->sw_stat.mem_freed
3939 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3940 }
3941 if (sp->s2io_entries) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003942 kfree(sp->s2io_entries);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003943 sp->mac_control.stats_info->sw_stat.mem_freed
3944 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3945 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003946 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003947 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948}
3949
3950/**
3951 * s2io_close -close entry point of the driver
3952 * @dev : device pointer.
3953 * Description:
3954 * This is the stop entry point of the driver. It needs to undo exactly
3955 * whatever was done by the open entry point,thus it's usually referred to
3956 * as the close function.Among other things this function mainly stops the
3957 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3958 * Return value:
3959 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3960 * file on failure.
3961 */
3962
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003963static int s2io_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003965 struct s2io_nic *sp = dev->priv;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003966
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 netif_stop_queue(dev);
3968 /* Reset card, kill tasklet and free Tx and Rx buffers. */
Ananda Rajue6a8fee2006-07-06 23:58:23 -07003969 s2io_card_down(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 sp->device_close_flag = TRUE; /* Device is shut down. */
3972 return 0;
3973}
3974
3975/**
3976 * s2io_xmit - Tx entry point of te driver
3977 * @skb : the socket buffer containing the Tx data.
3978 * @dev : device pointer.
3979 * Description :
3980 * This function is the Tx entry point of the driver. S2IO NIC supports
3981 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
3982 * NOTE: when device cant queue the pkt,just the trans_start variable will
3983 * not be upadted.
3984 * Return value:
3985 * 0 on success & 1 on failure.
3986 */
3987
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003988static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003990 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
3992 register u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003993 struct TxD *txdp;
3994 struct TxFIFO_element __iomem *tx_fifo;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 unsigned long flags;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07003996 u16 vlan_tag = 0;
3997 int vlan_priority = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003998 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 struct config_param *config;
Ananda Raju75c30b12006-07-24 19:55:09 -04004000 int offload_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001
4002 mac_control = &sp->mac_control;
4003 config = &sp->config;
4004
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004005 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004006
4007 if (unlikely(skb->len <= 0)) {
4008 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
4009 dev_kfree_skb_any(skb);
4010 return 0;
4011}
4012
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 spin_lock_irqsave(&sp->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 if (atomic_read(&sp->card_state) == CARD_DOWN) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004015 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 dev->name);
4017 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004018 dev_kfree_skb(skb);
4019 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 }
4021
4022 queue = 0;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004023 /* Get Fifo number to Transmit based on vlan priority */
4024 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
4025 vlan_tag = vlan_tx_tag_get(skb);
4026 vlan_priority = vlan_tag >> 13;
4027 queue = config->fifo_mapping[vlan_priority];
4028 }
4029
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004030 put_off = (u16) mac_control->fifos[queue].tx_curr_put_info.offset;
4031 get_off = (u16) mac_control->fifos[queue].tx_curr_get_info.offset;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004032 txdp = (struct TxD *) mac_control->fifos[queue].list_info[put_off].
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004033 list_virt_addr;
4034
4035 queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04004037 if (txdp->Host_Control ||
4038 ((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004039 DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 netif_stop_queue(dev);
4041 dev_kfree_skb(skb);
4042 spin_unlock_irqrestore(&sp->tx_lock, flags);
4043 return 0;
4044 }
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07004045
Ananda Raju75c30b12006-07-24 19:55:09 -04004046 offload_type = s2io_offload_type(skb);
Ananda Raju75c30b12006-07-24 19:55:09 -04004047 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 txdp->Control_1 |= TXD_TCP_LSO_EN;
Ananda Raju75c30b12006-07-24 19:55:09 -04004049 txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 }
Patrick McHardy84fa7932006-08-29 16:44:56 -07004051 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 txdp->Control_2 |=
4053 (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
4054 TXD_TX_CKO_UDP_EN);
4055 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004056 txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
4057 txdp->Control_1 |= TXD_LIST_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 txdp->Control_2 |= config->tx_intr_type;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07004059
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004060 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
4061 txdp->Control_2 |= TXD_VLAN_ENABLE;
4062 txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
4063 }
4064
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004065 frg_len = skb->len - skb->data_len;
Ananda Raju75c30b12006-07-24 19:55:09 -04004066 if (offload_type == SKB_GSO_UDP) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004067 int ufo_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Ananda Raju75c30b12006-07-24 19:55:09 -04004069 ufo_size = s2io_udp_mss(skb);
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004070 ufo_size &= ~7;
4071 txdp->Control_1 |= TXD_UFO_EN;
4072 txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
4073 txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
4074#ifdef __BIG_ENDIAN
4075 sp->ufo_in_band_v[put_off] =
4076 (u64)skb_shinfo(skb)->ip6_frag_id;
4077#else
4078 sp->ufo_in_band_v[put_off] =
4079 (u64)skb_shinfo(skb)->ip6_frag_id << 32;
4080#endif
4081 txdp->Host_Control = (unsigned long)sp->ufo_in_band_v;
4082 txdp->Buffer_Pointer = pci_map_single(sp->pdev,
4083 sp->ufo_in_band_v,
4084 sizeof(u64), PCI_DMA_TODEVICE);
4085 txdp++;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004086 }
4087
4088 txdp->Buffer_Pointer = pci_map_single
4089 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
4090 txdp->Host_Control = (unsigned long) skb;
4091 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
Ananda Raju75c30b12006-07-24 19:55:09 -04004092 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004093 txdp->Control_1 |= TXD_UFO_EN;
4094
4095 frg_cnt = skb_shinfo(skb)->nr_frags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 /* For fragmented SKB. */
4097 for (i = 0; i < frg_cnt; i++) {
4098 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07004099 /* A '0' length fragment will be ignored */
4100 if (!frag->size)
4101 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 txdp++;
4103 txdp->Buffer_Pointer = (u64) pci_map_page
4104 (sp->pdev, frag->page, frag->page_offset,
4105 frag->size, PCI_DMA_TODEVICE);
Ananda Rajuefd51b52006-01-19 14:11:54 -05004106 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
Ananda Raju75c30b12006-07-24 19:55:09 -04004107 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004108 txdp->Control_1 |= TXD_UFO_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 }
4110 txdp->Control_1 |= TXD_GATHER_CODE_LAST;
4111
Ananda Raju75c30b12006-07-24 19:55:09 -04004112 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004113 frg_cnt++; /* as Txd0 was used for inband header */
4114
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 tx_fifo = mac_control->tx_FIFO_start[queue];
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004116 val64 = mac_control->fifos[queue].list_info[put_off].list_phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 writeq(val64, &tx_fifo->TxDL_Pointer);
4118
4119 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
4120 TX_FIFO_LAST_LIST);
Ananda Raju75c30b12006-07-24 19:55:09 -04004121 if (offload_type)
4122 val64 |= TX_FIFO_SPECIAL_FUNC;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004123
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 writeq(val64, &tx_fifo->List_Control);
4125
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07004126 mmiowb();
4127
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 put_off++;
Ananda Raju863c11a2006-04-21 19:03:13 -04004129 if (put_off == mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1)
4130 put_off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004131 mac_control->fifos[queue].tx_curr_put_info.offset = put_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
4133 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04004134 if (((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04004135 sp->mac_control.stats_info->sw_stat.fifo_full_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 DBG_PRINT(TX_DBG,
4137 "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
4138 put_off, get_off);
4139 netif_stop_queue(dev);
4140 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004141 mac_control->stats_info->sw_stat.mem_allocated += skb->truesize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 dev->trans_start = jiffies;
4143 spin_unlock_irqrestore(&sp->tx_lock, flags);
4144
4145 return 0;
4146}
4147
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07004148static void
4149s2io_alarm_handle(unsigned long data)
4150{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004151 struct s2io_nic *sp = (struct s2io_nic *)data;
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07004152
4153 alarm_intr_handler(sp);
4154 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
4155}
4156
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004157static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n)
Ananda Raju75c30b12006-07-24 19:55:09 -04004158{
4159 int rxb_size, level;
4160
4161 if (!sp->lro) {
4162 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
4163 level = rx_buffer_level(sp, rxb_size, rng_n);
4164
4165 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4166 int ret;
4167 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
4168 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4169 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08004170 DBG_PRINT(INFO_DBG, "Out of memory in %s",
Ananda Raju75c30b12006-07-24 19:55:09 -04004171 __FUNCTION__);
4172 clear_bit(0, (&sp->tasklet_status));
4173 return -1;
4174 }
4175 clear_bit(0, (&sp->tasklet_status));
4176 } else if (level == LOW)
4177 tasklet_schedule(&sp->task);
4178
4179 } else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08004180 DBG_PRINT(INFO_DBG, "%s:Out of memory", sp->dev->name);
4181 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
Ananda Raju75c30b12006-07-24 19:55:09 -04004182 }
4183 return 0;
4184}
4185
David Howells7d12e782006-10-05 14:55:46 +01004186static irqreturn_t s2io_msi_handle(int irq, void *dev_id)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004187{
4188 struct net_device *dev = (struct net_device *) dev_id;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004189 struct s2io_nic *sp = dev->priv;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004190 int i;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004191 struct mac_info *mac_control;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004192 struct config_param *config;
4193
4194 atomic_inc(&sp->isr_cnt);
4195 mac_control = &sp->mac_control;
4196 config = &sp->config;
4197 DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
4198
4199 /* If Intr is because of Rx Traffic */
4200 for (i = 0; i < config->rx_ring_num; i++)
4201 rx_intr_handler(&mac_control->rings[i]);
4202
4203 /* If Intr is because of Tx Traffic */
4204 for (i = 0; i < config->tx_fifo_num; i++)
4205 tx_intr_handler(&mac_control->fifos[i]);
4206
4207 /*
4208 * If the Rx buffer count is below the panic threshold then
4209 * reallocate the buffers from the interrupt handler itself,
4210 * else schedule a tasklet to reallocate the buffers.
4211 */
Ananda Raju75c30b12006-07-24 19:55:09 -04004212 for (i = 0; i < config->rx_ring_num; i++)
4213 s2io_chk_rx_buffers(sp, i);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004214
4215 atomic_dec(&sp->isr_cnt);
4216 return IRQ_HANDLED;
4217}
4218
David Howells7d12e782006-10-05 14:55:46 +01004219static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004220{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004221 struct ring_info *ring = (struct ring_info *)dev_id;
4222 struct s2io_nic *sp = ring->nic;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004223
4224 atomic_inc(&sp->isr_cnt);
Ananda Raju75c30b12006-07-24 19:55:09 -04004225
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004226 rx_intr_handler(ring);
Ananda Raju75c30b12006-07-24 19:55:09 -04004227 s2io_chk_rx_buffers(sp, ring->ring_no);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05004228
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004229 atomic_dec(&sp->isr_cnt);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004230 return IRQ_HANDLED;
4231}
4232
David Howells7d12e782006-10-05 14:55:46 +01004233static irqreturn_t s2io_msix_fifo_handle(int irq, void *dev_id)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004234{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004235 struct fifo_info *fifo = (struct fifo_info *)dev_id;
4236 struct s2io_nic *sp = fifo->nic;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004237
4238 atomic_inc(&sp->isr_cnt);
4239 tx_intr_handler(fifo);
4240 atomic_dec(&sp->isr_cnt);
4241 return IRQ_HANDLED;
4242}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004243static void s2io_txpic_intr_handle(struct s2io_nic *sp)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004244{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004245 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004246 u64 val64;
4247
4248 val64 = readq(&bar0->pic_int_status);
4249 if (val64 & PIC_INT_GPIO) {
4250 val64 = readq(&bar0->gpio_int_reg);
4251 if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
4252 (val64 & GPIO_INT_REG_LINK_UP)) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04004253 /*
4254 * This is unstable state so clear both up/down
4255 * interrupt and adapter to re-evaluate the link state.
4256 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004257 val64 |= GPIO_INT_REG_LINK_DOWN;
4258 val64 |= GPIO_INT_REG_LINK_UP;
4259 writeq(val64, &bar0->gpio_int_reg);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004260 val64 = readq(&bar0->gpio_int_mask);
4261 val64 &= ~(GPIO_INT_MASK_LINK_UP |
4262 GPIO_INT_MASK_LINK_DOWN);
4263 writeq(val64, &bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004264 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04004265 else if (val64 & GPIO_INT_REG_LINK_UP) {
4266 val64 = readq(&bar0->adapter_status);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004267 /* Enable Adapter */
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004268 val64 = readq(&bar0->adapter_control);
4269 val64 |= ADAPTER_CNTL_EN;
4270 writeq(val64, &bar0->adapter_control);
4271 val64 |= ADAPTER_LED_ON;
4272 writeq(val64, &bar0->adapter_control);
4273 if (!sp->device_enabled_once)
4274 sp->device_enabled_once = 1;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004275
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004276 s2io_link(sp, LINK_UP);
4277 /*
4278 * unmask link down interrupt and mask link-up
4279 * intr
4280 */
4281 val64 = readq(&bar0->gpio_int_mask);
4282 val64 &= ~GPIO_INT_MASK_LINK_DOWN;
4283 val64 |= GPIO_INT_MASK_LINK_UP;
4284 writeq(val64, &bar0->gpio_int_mask);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004285
Ananda Rajuc92ca042006-04-21 19:18:03 -04004286 }else if (val64 & GPIO_INT_REG_LINK_DOWN) {
4287 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004288 s2io_link(sp, LINK_DOWN);
4289 /* Link is down so unmaks link up interrupt */
4290 val64 = readq(&bar0->gpio_int_mask);
4291 val64 &= ~GPIO_INT_MASK_LINK_UP;
4292 val64 |= GPIO_INT_MASK_LINK_DOWN;
4293 writeq(val64, &bar0->gpio_int_mask);
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05004294
4295 /* turn off LED */
4296 val64 = readq(&bar0->adapter_control);
4297 val64 = val64 &(~ADAPTER_LED_ON);
4298 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004299 }
4300 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04004301 val64 = readq(&bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004302}
4303
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304/**
4305 * s2io_isr - ISR handler of the device .
4306 * @irq: the irq of the device.
4307 * @dev_id: a void pointer to the dev structure of the NIC.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004308 * Description: This function is the ISR handler of the device. It
4309 * identifies the reason for the interrupt and calls the relevant
4310 * service routines. As a contongency measure, this ISR allocates the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 * recv buffers, if their numbers are below the panic value which is
4312 * presently set to 25% of the original number of rcv buffers allocated.
4313 * Return value:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004314 * IRQ_HANDLED: will be returned if IRQ was handled by this routine
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 * IRQ_NONE: will be returned if interrupt is not from our device
4316 */
David Howells7d12e782006-10-05 14:55:46 +01004317static irqreturn_t s2io_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318{
4319 struct net_device *dev = (struct net_device *) dev_id;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004320 struct s2io_nic *sp = dev->priv;
4321 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004322 int i;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004323 u64 reason = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004324 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 struct config_param *config;
4326
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004327 atomic_inc(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 mac_control = &sp->mac_control;
4329 config = &sp->config;
4330
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004331 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 * Identify the cause for interrupt and call the appropriate
4333 * interrupt handler. Causes for the interrupt could be;
4334 * 1. Rx of packet.
4335 * 2. Tx complete.
4336 * 3. Link down.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004337 * 4. Error in any functional blocks of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 */
4339 reason = readq(&bar0->general_int_status);
4340
4341 if (!reason) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004342 /* The interrupt was not raised by us. */
4343 atomic_dec(&sp->isr_cnt);
4344 return IRQ_NONE;
4345 }
4346 else if (unlikely(reason == S2IO_MINUS_ONE) ) {
4347 /* Disable device and get out */
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004348 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 return IRQ_NONE;
4350 }
4351
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004352 if (napi) {
4353 if (reason & GEN_INTR_RXTRAFFIC) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004354 if ( likely ( netif_rx_schedule_prep(dev)) ) {
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004355 __netif_rx_schedule(dev);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004356 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_mask);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004357 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004358 else
4359 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004360 }
4361 } else {
4362 /*
4363 * Rx handler is called by default, without checking for the
4364 * cause of interrupt.
4365 * rx_traffic_int reg is an R1 register, writing all 1's
4366 * will ensure that the actual interrupt causing bit get's
4367 * cleared and hence a read can be avoided.
4368 */
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004369 if (reason & GEN_INTR_RXTRAFFIC)
4370 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
4371
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004372 for (i = 0; i < config->rx_ring_num; i++) {
4373 rx_intr_handler(&mac_control->rings[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 }
4375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376
Ananda Raju863c11a2006-04-21 19:03:13 -04004377 /*
4378 * tx_traffic_int reg is an R1 register, writing all 1's
4379 * will ensure that the actual interrupt causing bit get's
4380 * cleared and hence a read can be avoided.
4381 */
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004382 if (reason & GEN_INTR_TXTRAFFIC)
4383 writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
raghavendra.koushik@neterion.comfe113632005-08-03 12:32:00 -07004384
Ananda Raju863c11a2006-04-21 19:03:13 -04004385 for (i = 0; i < config->tx_fifo_num; i++)
4386 tx_intr_handler(&mac_control->fifos[i]);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004387
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004388 if (reason & GEN_INTR_TXPIC)
4389 s2io_txpic_intr_handle(sp);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004390 /*
4391 * If the Rx buffer count is below the panic threshold then
4392 * reallocate the buffers from the interrupt handler itself,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 * else schedule a tasklet to reallocate the buffers.
4394 */
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004395 if (!napi) {
4396 for (i = 0; i < config->rx_ring_num; i++)
4397 s2io_chk_rx_buffers(sp, i);
4398 }
4399
4400 writeq(0, &bar0->general_int_mask);
4401 readl(&bar0->general_int_status);
4402
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004403 atomic_dec(&sp->isr_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return IRQ_HANDLED;
4405}
4406
4407/**
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004408 * s2io_updt_stats -
4409 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004410static void s2io_updt_stats(struct s2io_nic *sp)
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004411{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004412 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004413 u64 val64;
4414 int cnt = 0;
4415
4416 if (atomic_read(&sp->card_state) == CARD_UP) {
4417 /* Apprx 30us on a 133 MHz bus */
4418 val64 = SET_UPDT_CLICKS(10) |
4419 STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
4420 writeq(val64, &bar0->stat_cfg);
4421 do {
4422 udelay(100);
4423 val64 = readq(&bar0->stat_cfg);
4424 if (!(val64 & BIT(0)))
4425 break;
4426 cnt++;
4427 if (cnt == 5)
4428 break; /* Updt failed */
4429 } while(1);
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08004430 }
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004431}
4432
4433/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004434 * s2io_get_stats - Updates the device statistics structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 * @dev : pointer to the device structure.
4436 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004437 * This function updates the device statistics structure in the s2io_nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 * structure and returns a pointer to the same.
4439 * Return value:
4440 * pointer to the updated net_device_stats structure.
4441 */
4442
Adrian Bunkac1f60d2005-11-06 01:46:47 +01004443static struct net_device_stats *s2io_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004445 struct s2io_nic *sp = dev->priv;
4446 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 struct config_param *config;
4448
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004449
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 mac_control = &sp->mac_control;
4451 config = &sp->config;
4452
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004453 /* Configure Stats for immediate updt */
4454 s2io_updt_stats(sp);
4455
4456 sp->stats.tx_packets =
4457 le32_to_cpu(mac_control->stats_info->tmac_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004458 sp->stats.tx_errors =
4459 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
4460 sp->stats.rx_errors =
Al Viroee705db2006-09-23 01:28:17 +01004461 le64_to_cpu(mac_control->stats_info->rmac_drop_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004462 sp->stats.multicast =
4463 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 sp->stats.rx_length_errors =
Al Viroee705db2006-09-23 01:28:17 +01004465 le64_to_cpu(mac_control->stats_info->rmac_long_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466
4467 return (&sp->stats);
4468}
4469
4470/**
4471 * s2io_set_multicast - entry point for multicast address enable/disable.
4472 * @dev : pointer to the device structure
4473 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004474 * This function is a driver entry point which gets called by the kernel
4475 * whenever multicast addresses must be enabled/disabled. This also gets
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 * called to set/reset promiscuous mode. Depending on the deivce flag, we
4477 * determine, if multicast address must be enabled or if promiscuous mode
4478 * is to be disabled etc.
4479 * Return value:
4480 * void.
4481 */
4482
4483static void s2io_set_multicast(struct net_device *dev)
4484{
4485 int i, j, prev_cnt;
4486 struct dev_mc_list *mclist;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004487 struct s2io_nic *sp = dev->priv;
4488 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
4490 0xfeffffffffffULL;
4491 u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
4492 void __iomem *add;
4493
4494 if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
4495 /* Enable all Multicast addresses */
4496 writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
4497 &bar0->rmac_addr_data0_mem);
4498 writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
4499 &bar0->rmac_addr_data1_mem);
4500 val64 = RMAC_ADDR_CMD_MEM_WE |
4501 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4502 RMAC_ADDR_CMD_MEM_OFFSET(MAC_MC_ALL_MC_ADDR_OFFSET);
4503 writeq(val64, &bar0->rmac_addr_cmd_mem);
4504 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004505 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004506 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4507 S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508
4509 sp->m_cast_flg = 1;
4510 sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
4511 } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
4512 /* Disable all Multicast addresses */
4513 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4514 &bar0->rmac_addr_data0_mem);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07004515 writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
4516 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 val64 = RMAC_ADDR_CMD_MEM_WE |
4518 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4519 RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
4520 writeq(val64, &bar0->rmac_addr_cmd_mem);
4521 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004522 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004523 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4524 S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525
4526 sp->m_cast_flg = 0;
4527 sp->all_multi_pos = 0;
4528 }
4529
4530 if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
4531 /* Put the NIC into promiscuous mode */
4532 add = &bar0->mac_cfg;
4533 val64 = readq(&bar0->mac_cfg);
4534 val64 |= MAC_CFG_RMAC_PROM_ENABLE;
4535
4536 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4537 writel((u32) val64, add);
4538 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4539 writel((u32) (val64 >> 32), (add + 4));
4540
Sivakumar Subramani926930b2007-02-24 01:59:39 -05004541 if (vlan_tag_strip != 1) {
4542 val64 = readq(&bar0->rx_pa_cfg);
4543 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
4544 writeq(val64, &bar0->rx_pa_cfg);
4545 vlan_strip_flag = 0;
4546 }
4547
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 val64 = readq(&bar0->mac_cfg);
4549 sp->promisc_flg = 1;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004550 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 dev->name);
4552 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
4553 /* Remove the NIC from promiscuous mode */
4554 add = &bar0->mac_cfg;
4555 val64 = readq(&bar0->mac_cfg);
4556 val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
4557
4558 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4559 writel((u32) val64, add);
4560 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4561 writel((u32) (val64 >> 32), (add + 4));
4562
Sivakumar Subramani926930b2007-02-24 01:59:39 -05004563 if (vlan_tag_strip != 0) {
4564 val64 = readq(&bar0->rx_pa_cfg);
4565 val64 |= RX_PA_CFG_STRIP_VLAN_TAG;
4566 writeq(val64, &bar0->rx_pa_cfg);
4567 vlan_strip_flag = 1;
4568 }
4569
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 val64 = readq(&bar0->mac_cfg);
4571 sp->promisc_flg = 0;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004572 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 dev->name);
4574 }
4575
4576 /* Update individual M_CAST address list */
4577 if ((!sp->m_cast_flg) && dev->mc_count) {
4578 if (dev->mc_count >
4579 (MAX_ADDRS_SUPPORTED - MAC_MC_ADDR_START_OFFSET - 1)) {
4580 DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
4581 dev->name);
4582 DBG_PRINT(ERR_DBG, "can be added, please enable ");
4583 DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
4584 return;
4585 }
4586
4587 prev_cnt = sp->mc_addr_count;
4588 sp->mc_addr_count = dev->mc_count;
4589
4590 /* Clear out the previous list of Mc in the H/W. */
4591 for (i = 0; i < prev_cnt; i++) {
4592 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4593 &bar0->rmac_addr_data0_mem);
4594 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004595 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 val64 = RMAC_ADDR_CMD_MEM_WE |
4597 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4598 RMAC_ADDR_CMD_MEM_OFFSET
4599 (MAC_MC_ADDR_START_OFFSET + i);
4600 writeq(val64, &bar0->rmac_addr_cmd_mem);
4601
4602 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004603 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004604 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4605 S2IO_BIT_RESET)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 DBG_PRINT(ERR_DBG, "%s: Adding ",
4607 dev->name);
4608 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4609 return;
4610 }
4611 }
4612
4613 /* Create the new Rx filter list and update the same in H/W. */
4614 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
4615 i++, mclist = mclist->next) {
4616 memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
4617 ETH_ALEN);
Jeff Garzika7a80d52006-03-04 12:06:51 -05004618 mac_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 for (j = 0; j < ETH_ALEN; j++) {
4620 mac_addr |= mclist->dmi_addr[j];
4621 mac_addr <<= 8;
4622 }
4623 mac_addr >>= 8;
4624 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4625 &bar0->rmac_addr_data0_mem);
4626 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004627 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 val64 = RMAC_ADDR_CMD_MEM_WE |
4629 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4630 RMAC_ADDR_CMD_MEM_OFFSET
4631 (i + MAC_MC_ADDR_START_OFFSET);
4632 writeq(val64, &bar0->rmac_addr_cmd_mem);
4633
4634 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004635 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004636 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4637 S2IO_BIT_RESET)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 DBG_PRINT(ERR_DBG, "%s: Adding ",
4639 dev->name);
4640 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
4641 return;
4642 }
4643 }
4644 }
4645}
4646
4647/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004648 * s2io_set_mac_addr - Programs the Xframe mac address
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 * @dev : pointer to the device structure.
4650 * @addr: a uchar pointer to the new mac address which is to be set.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004651 * Description : This procedure will program the Xframe to receive
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 * frames with new Mac Address
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004653 * Return value: SUCCESS on success and an appropriate (-)ve integer
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 * as defined in errno.h file on failure.
4655 */
4656
Adrian Bunk26df54b2006-01-14 03:09:40 +01004657static int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004659 struct s2io_nic *sp = dev->priv;
4660 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 register u64 val64, mac_addr = 0;
4662 int i;
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05004663 u64 old_mac_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004665 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 * Set the new MAC address as the new unicast filter and reflect this
4667 * change on the device address registered with the OS. It will be
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004668 * at offset 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 */
4670 for (i = 0; i < ETH_ALEN; i++) {
4671 mac_addr <<= 8;
4672 mac_addr |= addr[i];
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05004673 old_mac_addr <<= 8;
4674 old_mac_addr |= sp->def_mac_addr[0].mac_addr[i];
4675 }
4676
4677 if(0 == mac_addr)
4678 return SUCCESS;
4679
4680 /* Update the internal structure with this new mac address */
4681 if(mac_addr != old_mac_addr) {
4682 memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
4683 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_addr);
4684 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_addr >> 8);
4685 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_addr >> 16);
4686 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_addr >> 24);
4687 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_addr >> 32);
4688 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_addr >> 40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 }
4690
4691 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
4692 &bar0->rmac_addr_data0_mem);
4693
4694 val64 =
4695 RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4696 RMAC_ADDR_CMD_MEM_OFFSET(0);
4697 writeq(val64, &bar0->rmac_addr_cmd_mem);
4698 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004699 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004700 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
4702 return FAILURE;
4703 }
4704
4705 return SUCCESS;
4706}
4707
4708/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004709 * s2io_ethtool_sset - Sets different link parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710 * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
4711 * @info: pointer to the structure with parameters given by ethtool to set
4712 * link information.
4713 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004714 * The function sets different link parameters provided by the user onto
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 * the NIC.
4716 * Return value:
4717 * 0 on success.
4718*/
4719
4720static int s2io_ethtool_sset(struct net_device *dev,
4721 struct ethtool_cmd *info)
4722{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004723 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 if ((info->autoneg == AUTONEG_ENABLE) ||
4725 (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
4726 return -EINVAL;
4727 else {
4728 s2io_close(sp->dev);
4729 s2io_open(sp->dev);
4730 }
4731
4732 return 0;
4733}
4734
4735/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004736 * s2io_ethtol_gset - Return link specific information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 * @sp : private member of the device structure, pointer to the
4738 * s2io_nic structure.
4739 * @info : pointer to the structure with parameters given by ethtool
4740 * to return link information.
4741 * Description:
4742 * Returns link specific information like speed, duplex etc.. to ethtool.
4743 * Return value :
4744 * return 0 on success.
4745 */
4746
4747static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
4748{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004749 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4751 info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
4752 info->port = PORT_FIBRE;
4753 /* info->transceiver?? TODO */
4754
4755 if (netif_carrier_ok(sp->dev)) {
4756 info->speed = 10000;
4757 info->duplex = DUPLEX_FULL;
4758 } else {
4759 info->speed = -1;
4760 info->duplex = -1;
4761 }
4762
4763 info->autoneg = AUTONEG_DISABLE;
4764 return 0;
4765}
4766
4767/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004768 * s2io_ethtool_gdrvinfo - Returns driver specific information.
4769 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 * s2io_nic structure.
4771 * @info : pointer to the structure with parameters given by ethtool to
4772 * return driver information.
4773 * Description:
4774 * Returns driver specefic information like name, version etc.. to ethtool.
4775 * Return value:
4776 * void
4777 */
4778
4779static void s2io_ethtool_gdrvinfo(struct net_device *dev,
4780 struct ethtool_drvinfo *info)
4781{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004782 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783
John W. Linvilledbc23092005-09-28 17:50:51 -04004784 strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
4785 strncpy(info->version, s2io_driver_version, sizeof(info->version));
4786 strncpy(info->fw_version, "", sizeof(info->fw_version));
4787 strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 info->regdump_len = XENA_REG_SPACE;
4789 info->eedump_len = XENA_EEPROM_SPACE;
4790 info->testinfo_len = S2IO_TEST_LEN;
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05004791
4792 if (sp->device_type == XFRAME_I_DEVICE)
4793 info->n_stats = XFRAME_I_STAT_LEN;
4794 else
4795 info->n_stats = XFRAME_II_STAT_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796}
4797
4798/**
4799 * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004800 * @sp: private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004802 * @regs : pointer to the structure with parameters given by ethtool for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 * dumping the registers.
4804 * @reg_space: The input argumnet into which all the registers are dumped.
4805 * Description:
4806 * Dumps the entire register space of xFrame NIC into the user given
4807 * buffer area.
4808 * Return value :
4809 * void .
4810*/
4811
4812static void s2io_ethtool_gregs(struct net_device *dev,
4813 struct ethtool_regs *regs, void *space)
4814{
4815 int i;
4816 u64 reg;
4817 u8 *reg_space = (u8 *) space;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004818 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819
4820 regs->len = XENA_REG_SPACE;
4821 regs->version = sp->pdev->subsystem_device;
4822
4823 for (i = 0; i < regs->len; i += 8) {
4824 reg = readq(sp->bar0 + i);
4825 memcpy((reg_space + i), &reg, 8);
4826 }
4827}
4828
4829/**
4830 * s2io_phy_id - timer function that alternates adapter LED.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004831 * @data : address of the private member of the device structure, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832 * is a pointer to the s2io_nic structure, provided as an u32.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004833 * Description: This is actually the timer function that alternates the
4834 * adapter LED bit of the adapter control bit to set/reset every time on
4835 * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 * once every second.
4837*/
4838static void s2io_phy_id(unsigned long data)
4839{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004840 struct s2io_nic *sp = (struct s2io_nic *) data;
4841 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 u64 val64 = 0;
4843 u16 subid;
4844
4845 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004846 if ((sp->device_type == XFRAME_II_DEVICE) ||
4847 ((subid & 0xFF) >= 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 val64 = readq(&bar0->gpio_control);
4849 val64 ^= GPIO_CTRL_GPIO_0;
4850 writeq(val64, &bar0->gpio_control);
4851 } else {
4852 val64 = readq(&bar0->adapter_control);
4853 val64 ^= ADAPTER_LED_ON;
4854 writeq(val64, &bar0->adapter_control);
4855 }
4856
4857 mod_timer(&sp->id_timer, jiffies + HZ / 2);
4858}
4859
4860/**
4861 * s2io_ethtool_idnic - To physically identify the nic on the system.
4862 * @sp : private member of the device structure, which is a pointer to the
4863 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004864 * @id : pointer to the structure with identification parameters given by
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 * ethtool.
4866 * Description: Used to physically identify the NIC on the system.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004867 * The Link LED will blink for a time specified by the user for
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 * identification.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004869 * NOTE: The Link has to be Up to be able to blink the LED. Hence
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 * identification is possible only if it's link is up.
4871 * Return value:
4872 * int , returns 0 on success
4873 */
4874
4875static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
4876{
4877 u64 val64 = 0, last_gpio_ctrl_val;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004878 struct s2io_nic *sp = dev->priv;
4879 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 u16 subid;
4881
4882 subid = sp->pdev->subsystem_device;
4883 last_gpio_ctrl_val = readq(&bar0->gpio_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004884 if ((sp->device_type == XFRAME_I_DEVICE) &&
4885 ((subid & 0xFF) < 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 val64 = readq(&bar0->adapter_control);
4887 if (!(val64 & ADAPTER_CNTL_EN)) {
4888 printk(KERN_ERR
4889 "Adapter Link down, cannot blink LED\n");
4890 return -EFAULT;
4891 }
4892 }
4893 if (sp->id_timer.function == NULL) {
4894 init_timer(&sp->id_timer);
4895 sp->id_timer.function = s2io_phy_id;
4896 sp->id_timer.data = (unsigned long) sp;
4897 }
4898 mod_timer(&sp->id_timer, jiffies);
4899 if (data)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004900 msleep_interruptible(data * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004902 msleep_interruptible(MAX_FLICKER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 del_timer_sync(&sp->id_timer);
4904
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07004905 if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 writeq(last_gpio_ctrl_val, &bar0->gpio_control);
4907 last_gpio_ctrl_val = readq(&bar0->gpio_control);
4908 }
4909
4910 return 0;
4911}
4912
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04004913static void s2io_ethtool_gringparam(struct net_device *dev,
4914 struct ethtool_ringparam *ering)
4915{
4916 struct s2io_nic *sp = dev->priv;
4917 int i,tx_desc_count=0,rx_desc_count=0;
4918
4919 if (sp->rxd_mode == RXD_MODE_1)
4920 ering->rx_max_pending = MAX_RX_DESC_1;
4921 else if (sp->rxd_mode == RXD_MODE_3B)
4922 ering->rx_max_pending = MAX_RX_DESC_2;
4923 else if (sp->rxd_mode == RXD_MODE_3A)
4924 ering->rx_max_pending = MAX_RX_DESC_3;
4925
4926 ering->tx_max_pending = MAX_TX_DESC;
4927 for (i = 0 ; i < sp->config.tx_fifo_num ; i++) {
4928 tx_desc_count += sp->config.tx_cfg[i].fifo_len;
4929 }
4930 DBG_PRINT(INFO_DBG,"\nmax txds : %d\n",sp->config.max_txds);
4931 ering->tx_pending = tx_desc_count;
4932 rx_desc_count = 0;
4933 for (i = 0 ; i < sp->config.rx_ring_num ; i++) {
4934 rx_desc_count += sp->config.rx_cfg[i].num_rxd;
4935 }
4936 ering->rx_pending = rx_desc_count;
4937
4938 ering->rx_mini_max_pending = 0;
4939 ering->rx_mini_pending = 0;
4940 if(sp->rxd_mode == RXD_MODE_1)
4941 ering->rx_jumbo_max_pending = MAX_RX_DESC_1;
4942 else if (sp->rxd_mode == RXD_MODE_3B)
4943 ering->rx_jumbo_max_pending = MAX_RX_DESC_2;
4944 ering->rx_jumbo_pending = rx_desc_count;
4945}
4946
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947/**
4948 * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004949 * @sp : private member of the device structure, which is a pointer to the
4950 * s2io_nic structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 * @ep : pointer to the structure with pause parameters given by ethtool.
4952 * Description:
4953 * Returns the Pause frame generation and reception capability of the NIC.
4954 * Return value:
4955 * void
4956 */
4957static void s2io_ethtool_getpause_data(struct net_device *dev,
4958 struct ethtool_pauseparam *ep)
4959{
4960 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004961 struct s2io_nic *sp = dev->priv;
4962 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963
4964 val64 = readq(&bar0->rmac_pause_cfg);
4965 if (val64 & RMAC_PAUSE_GEN_ENABLE)
4966 ep->tx_pause = TRUE;
4967 if (val64 & RMAC_PAUSE_RX_ENABLE)
4968 ep->rx_pause = TRUE;
4969 ep->autoneg = FALSE;
4970}
4971
4972/**
4973 * s2io_ethtool_setpause_data - set/reset pause frame generation.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004974 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 * s2io_nic structure.
4976 * @ep : pointer to the structure with pause parameters given by ethtool.
4977 * Description:
4978 * It can be used to set or reset Pause frame generation or reception
4979 * support of the NIC.
4980 * Return value:
4981 * int, returns 0 on Success
4982 */
4983
4984static int s2io_ethtool_setpause_data(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004985 struct ethtool_pauseparam *ep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986{
4987 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004988 struct s2io_nic *sp = dev->priv;
4989 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
4991 val64 = readq(&bar0->rmac_pause_cfg);
4992 if (ep->tx_pause)
4993 val64 |= RMAC_PAUSE_GEN_ENABLE;
4994 else
4995 val64 &= ~RMAC_PAUSE_GEN_ENABLE;
4996 if (ep->rx_pause)
4997 val64 |= RMAC_PAUSE_RX_ENABLE;
4998 else
4999 val64 &= ~RMAC_PAUSE_RX_ENABLE;
5000 writeq(val64, &bar0->rmac_pause_cfg);
5001 return 0;
5002}
5003
5004/**
5005 * read_eeprom - reads 4 bytes of data from user given offset.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005006 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 * s2io_nic structure.
5008 * @off : offset at which the data must be written
5009 * @data : Its an output parameter where the data read at the given
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005010 * offset is stored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005012 * Will read 4 bytes of data from the user given offset and return the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013 * read data.
5014 * NOTE: Will allow to read only part of the EEPROM visible through the
5015 * I2C bus.
5016 * Return value:
5017 * -1 on failure and 0 on success.
5018 */
5019
5020#define S2IO_DEV_ID 5
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005021static int read_eeprom(struct s2io_nic * sp, int off, u64 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022{
5023 int ret = -1;
5024 u32 exit_cnt = 0;
5025 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005026 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005028 if (sp->device_type == XFRAME_I_DEVICE) {
5029 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
5030 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
5031 I2C_CONTROL_CNTL_START;
5032 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005034 while (exit_cnt < 5) {
5035 val64 = readq(&bar0->i2c_control);
5036 if (I2C_CONTROL_CNTL_END(val64)) {
5037 *data = I2C_CONTROL_GET_DATA(val64);
5038 ret = 0;
5039 break;
5040 }
5041 msleep(50);
5042 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 }
5045
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005046 if (sp->device_type == XFRAME_II_DEVICE) {
5047 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
Jeff Garzik6aa20a22006-09-13 13:24:59 -04005048 SPI_CONTROL_BYTECNT(0x3) |
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005049 SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
5050 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5051 val64 |= SPI_CONTROL_REQ;
5052 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5053 while (exit_cnt < 5) {
5054 val64 = readq(&bar0->spi_control);
5055 if (val64 & SPI_CONTROL_NACK) {
5056 ret = 1;
5057 break;
5058 } else if (val64 & SPI_CONTROL_DONE) {
5059 *data = readq(&bar0->spi_data);
5060 *data &= 0xffffff;
5061 ret = 0;
5062 break;
5063 }
5064 msleep(50);
5065 exit_cnt++;
5066 }
5067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 return ret;
5069}
5070
5071/**
5072 * write_eeprom - actually writes the relevant part of the data value.
5073 * @sp : private member of the device structure, which is a pointer to the
5074 * s2io_nic structure.
5075 * @off : offset at which the data must be written
5076 * @data : The data that is to be written
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005077 * @cnt : Number of bytes of the data that are actually to be written into
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 * the Eeprom. (max of 3)
5079 * Description:
5080 * Actually writes the relevant part of the data value into the Eeprom
5081 * through the I2C bus.
5082 * Return value:
5083 * 0 on success, -1 on failure.
5084 */
5085
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005086static int write_eeprom(struct s2io_nic * sp, int off, u64 data, int cnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087{
5088 int exit_cnt = 0, ret = -1;
5089 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005090 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005092 if (sp->device_type == XFRAME_I_DEVICE) {
5093 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
5094 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
5095 I2C_CONTROL_CNTL_START;
5096 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005098 while (exit_cnt < 5) {
5099 val64 = readq(&bar0->i2c_control);
5100 if (I2C_CONTROL_CNTL_END(val64)) {
5101 if (!(val64 & I2C_CONTROL_NACK))
5102 ret = 0;
5103 break;
5104 }
5105 msleep(50);
5106 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 }
5109
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005110 if (sp->device_type == XFRAME_II_DEVICE) {
5111 int write_cnt = (cnt == 8) ? 0 : cnt;
5112 writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
5113
5114 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
Jeff Garzik6aa20a22006-09-13 13:24:59 -04005115 SPI_CONTROL_BYTECNT(write_cnt) |
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005116 SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
5117 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5118 val64 |= SPI_CONTROL_REQ;
5119 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5120 while (exit_cnt < 5) {
5121 val64 = readq(&bar0->spi_control);
5122 if (val64 & SPI_CONTROL_NACK) {
5123 ret = 1;
5124 break;
5125 } else if (val64 & SPI_CONTROL_DONE) {
5126 ret = 0;
5127 break;
5128 }
5129 msleep(50);
5130 exit_cnt++;
5131 }
5132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 return ret;
5134}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005135static void s2io_vpd_read(struct s2io_nic *nic)
Ananda Raju9dc737a2006-04-21 19:05:41 -04005136{
Ananda Rajub41477f2006-07-24 19:52:49 -04005137 u8 *vpd_data;
5138 u8 data;
Ananda Raju9dc737a2006-04-21 19:05:41 -04005139 int i=0, cnt, fail = 0;
5140 int vpd_addr = 0x80;
5141
5142 if (nic->device_type == XFRAME_II_DEVICE) {
5143 strcpy(nic->product_name, "Xframe II 10GbE network adapter");
5144 vpd_addr = 0x80;
5145 }
5146 else {
5147 strcpy(nic->product_name, "Xframe I 10GbE network adapter");
5148 vpd_addr = 0x50;
5149 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05005150 strcpy(nic->serial_num, "NOT AVAILABLE");
Ananda Raju9dc737a2006-04-21 19:05:41 -04005151
Ananda Rajub41477f2006-07-24 19:52:49 -04005152 vpd_data = kmalloc(256, GFP_KERNEL);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04005153 if (!vpd_data) {
5154 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ananda Rajub41477f2006-07-24 19:52:49 -04005155 return;
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04005156 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04005157 nic->mac_control.stats_info->sw_stat.mem_allocated += 256;
Ananda Rajub41477f2006-07-24 19:52:49 -04005158
Ananda Raju9dc737a2006-04-21 19:05:41 -04005159 for (i = 0; i < 256; i +=4 ) {
5160 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
5161 pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
5162 pci_write_config_byte(nic->pdev, (vpd_addr + 3), 0);
5163 for (cnt = 0; cnt <5; cnt++) {
5164 msleep(2);
5165 pci_read_config_byte(nic->pdev, (vpd_addr + 3), &data);
5166 if (data == 0x80)
5167 break;
5168 }
5169 if (cnt >= 5) {
5170 DBG_PRINT(ERR_DBG, "Read of VPD data failed\n");
5171 fail = 1;
5172 break;
5173 }
5174 pci_read_config_dword(nic->pdev, (vpd_addr + 4),
5175 (u32 *)&vpd_data[i]);
5176 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05005177
5178 if(!fail) {
5179 /* read serial number of adapter */
5180 for (cnt = 0; cnt < 256; cnt++) {
5181 if ((vpd_data[cnt] == 'S') &&
5182 (vpd_data[cnt+1] == 'N') &&
5183 (vpd_data[cnt+2] < VPD_STRING_LEN)) {
5184 memset(nic->serial_num, 0, VPD_STRING_LEN);
5185 memcpy(nic->serial_num, &vpd_data[cnt + 3],
5186 vpd_data[cnt+2]);
5187 break;
5188 }
5189 }
5190 }
5191
5192 if ((!fail) && (vpd_data[1] < VPD_STRING_LEN)) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04005193 memset(nic->product_name, 0, vpd_data[1]);
5194 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
5195 }
Ananda Rajub41477f2006-07-24 19:52:49 -04005196 kfree(vpd_data);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04005197 nic->mac_control.stats_info->sw_stat.mem_freed += 256;
Ananda Raju9dc737a2006-04-21 19:05:41 -04005198}
5199
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200/**
5201 * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
5202 * @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 -07005203 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204 * containing all relevant information.
5205 * @data_buf : user defined value to be written into Eeprom.
5206 * Description: Reads the values stored in the Eeprom at given offset
5207 * for a given length. Stores these values int the input argument data
5208 * buffer 'data_buf' and returns these to the caller (ethtool.)
5209 * Return value:
5210 * int 0 on success
5211 */
5212
5213static int s2io_ethtool_geeprom(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005214 struct ethtool_eeprom *eeprom, u8 * data_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215{
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005216 u32 i, valid;
5217 u64 data;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005218 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219
5220 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
5221
5222 if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
5223 eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
5224
5225 for (i = 0; i < eeprom->len; i += 4) {
5226 if (read_eeprom(sp, (eeprom->offset + i), &data)) {
5227 DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
5228 return -EFAULT;
5229 }
5230 valid = INV(data);
5231 memcpy((data_buf + i), &valid, 4);
5232 }
5233 return 0;
5234}
5235
5236/**
5237 * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
5238 * @sp : private member of the device structure, which is a pointer to the
5239 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005240 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 * containing all relevant information.
5242 * @data_buf ; user defined value to be written into Eeprom.
5243 * Description:
5244 * Tries to write the user provided value in the Eeprom, at the offset
5245 * given by the user.
5246 * Return value:
5247 * 0 on success, -EFAULT on failure.
5248 */
5249
5250static int s2io_ethtool_seeprom(struct net_device *dev,
5251 struct ethtool_eeprom *eeprom,
5252 u8 * data_buf)
5253{
5254 int len = eeprom->len, cnt = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005255 u64 valid = 0, data;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005256 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257
5258 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
5259 DBG_PRINT(ERR_DBG,
5260 "ETHTOOL_WRITE_EEPROM Err: Magic value ");
5261 DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
5262 eeprom->magic);
5263 return -EFAULT;
5264 }
5265
5266 while (len) {
5267 data = (u32) data_buf[cnt] & 0x000000FF;
5268 if (data) {
5269 valid = (u32) (data << 24);
5270 } else
5271 valid = data;
5272
5273 if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
5274 DBG_PRINT(ERR_DBG,
5275 "ETHTOOL_WRITE_EEPROM Err: Cannot ");
5276 DBG_PRINT(ERR_DBG,
5277 "write into the specified offset\n");
5278 return -EFAULT;
5279 }
5280 cnt++;
5281 len--;
5282 }
5283
5284 return 0;
5285}
5286
5287/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005288 * s2io_register_test - reads and writes into all clock domains.
5289 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 * s2io_nic structure.
5291 * @data : variable that returns the result of each of the test conducted b
5292 * by the driver.
5293 * Description:
5294 * Read and write into all clock domains. The NIC has 3 clock domains,
5295 * see that registers in all the three regions are accessible.
5296 * Return value:
5297 * 0 on success.
5298 */
5299
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005300static int s2io_register_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005302 struct XENA_dev_config __iomem *bar0 = sp->bar0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005303 u64 val64 = 0, exp_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304 int fail = 0;
5305
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005306 val64 = readq(&bar0->pif_rd_swapper_fb);
5307 if (val64 != 0x123456789abcdefULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 fail = 1;
5309 DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
5310 }
5311
5312 val64 = readq(&bar0->rmac_pause_cfg);
5313 if (val64 != 0xc000ffff00000000ULL) {
5314 fail = 1;
5315 DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
5316 }
5317
5318 val64 = readq(&bar0->rx_queue_cfg);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005319 if (sp->device_type == XFRAME_II_DEVICE)
5320 exp_val = 0x0404040404040404ULL;
5321 else
5322 exp_val = 0x0808080808080808ULL;
5323 if (val64 != exp_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324 fail = 1;
5325 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
5326 }
5327
5328 val64 = readq(&bar0->xgxs_efifo_cfg);
5329 if (val64 != 0x000000001923141EULL) {
5330 fail = 1;
5331 DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
5332 }
5333
5334 val64 = 0x5A5A5A5A5A5A5A5AULL;
5335 writeq(val64, &bar0->xmsi_data);
5336 val64 = readq(&bar0->xmsi_data);
5337 if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
5338 fail = 1;
5339 DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
5340 }
5341
5342 val64 = 0xA5A5A5A5A5A5A5A5ULL;
5343 writeq(val64, &bar0->xmsi_data);
5344 val64 = readq(&bar0->xmsi_data);
5345 if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
5346 fail = 1;
5347 DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
5348 }
5349
5350 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005351 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352}
5353
5354/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005355 * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 * @sp : private member of the device structure, which is a pointer to the
5357 * s2io_nic structure.
5358 * @data:variable that returns the result of each of the test conducted by
5359 * the driver.
5360 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005361 * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 * register.
5363 * Return value:
5364 * 0 on success.
5365 */
5366
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005367static int s2io_eeprom_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368{
5369 int fail = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005370 u64 ret_data, org_4F0, org_7F0;
5371 u8 saved_4F0 = 0, saved_7F0 = 0;
5372 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373
5374 /* Test Write Error at offset 0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005375 /* Note that SPI interface allows write access to all areas
5376 * of EEPROM. Hence doing all negative testing only for Xframe I.
5377 */
5378 if (sp->device_type == XFRAME_I_DEVICE)
5379 if (!write_eeprom(sp, 0, 0, 3))
5380 fail = 1;
5381
5382 /* Save current values at offsets 0x4F0 and 0x7F0 */
5383 if (!read_eeprom(sp, 0x4F0, &org_4F0))
5384 saved_4F0 = 1;
5385 if (!read_eeprom(sp, 0x7F0, &org_7F0))
5386 saved_7F0 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387
5388 /* Test Write at offset 4f0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005389 if (write_eeprom(sp, 0x4F0, 0x012345, 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390 fail = 1;
5391 if (read_eeprom(sp, 0x4F0, &ret_data))
5392 fail = 1;
5393
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005394 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08005395 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
5396 "Data written %llx Data read %llx\n",
5397 dev->name, (unsigned long long)0x12345,
5398 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401
5402 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005403 write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404
5405 /* Test Write Request Error at offset 0x7c */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005406 if (sp->device_type == XFRAME_I_DEVICE)
5407 if (!write_eeprom(sp, 0x07C, 0, 3))
5408 fail = 1;
5409
5410 /* Test Write Request at offset 0x7f0 */
5411 if (write_eeprom(sp, 0x7F0, 0x012345, 3))
5412 fail = 1;
5413 if (read_eeprom(sp, 0x7F0, &ret_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 fail = 1;
5415
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005416 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08005417 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
5418 "Data written %llx Data read %llx\n",
5419 dev->name, (unsigned long long)0x12345,
5420 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423
5424 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005425 write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005427 if (sp->device_type == XFRAME_I_DEVICE) {
5428 /* Test Write Error at offset 0x80 */
5429 if (!write_eeprom(sp, 0x080, 0, 3))
5430 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005432 /* Test Write Error at offset 0xfc */
5433 if (!write_eeprom(sp, 0x0FC, 0, 3))
5434 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005436 /* Test Write Error at offset 0x100 */
5437 if (!write_eeprom(sp, 0x100, 0, 3))
5438 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005440 /* Test Write Error at offset 4ec */
5441 if (!write_eeprom(sp, 0x4EC, 0, 3))
5442 fail = 1;
5443 }
5444
5445 /* Restore values at offsets 0x4F0 and 0x7F0 */
5446 if (saved_4F0)
5447 write_eeprom(sp, 0x4F0, org_4F0, 3);
5448 if (saved_7F0)
5449 write_eeprom(sp, 0x7F0, org_7F0, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450
5451 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005452 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453}
5454
5455/**
5456 * s2io_bist_test - invokes the MemBist test of the card .
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005457 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005459 * @data:variable that returns the result of each of the test conducted by
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 * the driver.
5461 * Description:
5462 * This invokes the MemBist test of the card. We give around
5463 * 2 secs time for the Test to complete. If it's still not complete
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005464 * within this peiod, we consider that the test failed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465 * Return value:
5466 * 0 on success and -1 on failure.
5467 */
5468
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005469static int s2io_bist_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470{
5471 u8 bist = 0;
5472 int cnt = 0, ret = -1;
5473
5474 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
5475 bist |= PCI_BIST_START;
5476 pci_write_config_word(sp->pdev, PCI_BIST, bist);
5477
5478 while (cnt < 20) {
5479 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
5480 if (!(bist & PCI_BIST_START)) {
5481 *data = (bist & PCI_BIST_CODE_MASK);
5482 ret = 0;
5483 break;
5484 }
5485 msleep(100);
5486 cnt++;
5487 }
5488
5489 return ret;
5490}
5491
5492/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005493 * s2io-link_test - verifies the link state of the nic
5494 * @sp ; private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 * s2io_nic structure.
5496 * @data: variable that returns the result of each of the test conducted by
5497 * the driver.
5498 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005499 * The function verifies the link state of the NIC and updates the input
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500 * argument 'data' appropriately.
5501 * Return value:
5502 * 0 on success.
5503 */
5504
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005505static int s2io_link_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005507 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508 u64 val64;
5509
5510 val64 = readq(&bar0->adapter_status);
Ananda Rajuc92ca042006-04-21 19:18:03 -04005511 if(!(LINK_IS_UP(val64)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512 *data = 1;
Ananda Rajuc92ca042006-04-21 19:18:03 -04005513 else
5514 *data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515
Ananda Rajub41477f2006-07-24 19:52:49 -04005516 return *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517}
5518
5519/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005520 * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
5521 * @sp - private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005523 * @data - variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 * conducted by the driver.
5525 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005526 * This is one of the offline test that tests the read and write
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527 * access to the RldRam chip on the NIC.
5528 * Return value:
5529 * 0 on success.
5530 */
5531
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005532static int s2io_rldram_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005534 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 u64 val64;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005536 int cnt, iteration = 0, test_fail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537
5538 val64 = readq(&bar0->adapter_control);
5539 val64 &= ~ADAPTER_ECC_EN;
5540 writeq(val64, &bar0->adapter_control);
5541
5542 val64 = readq(&bar0->mc_rldram_test_ctrl);
5543 val64 |= MC_RLDRAM_TEST_MODE;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005544 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545
5546 val64 = readq(&bar0->mc_rldram_mrs);
5547 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
5548 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
5549
5550 val64 |= MC_RLDRAM_MRS_ENABLE;
5551 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
5552
5553 while (iteration < 2) {
5554 val64 = 0x55555555aaaa0000ULL;
5555 if (iteration == 1) {
5556 val64 ^= 0xFFFFFFFFFFFF0000ULL;
5557 }
5558 writeq(val64, &bar0->mc_rldram_test_d0);
5559
5560 val64 = 0xaaaa5a5555550000ULL;
5561 if (iteration == 1) {
5562 val64 ^= 0xFFFFFFFFFFFF0000ULL;
5563 }
5564 writeq(val64, &bar0->mc_rldram_test_d1);
5565
5566 val64 = 0x55aaaaaaaa5a0000ULL;
5567 if (iteration == 1) {
5568 val64 ^= 0xFFFFFFFFFFFF0000ULL;
5569 }
5570 writeq(val64, &bar0->mc_rldram_test_d2);
5571
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005572 val64 = (u64) (0x0000003ffffe0100ULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573 writeq(val64, &bar0->mc_rldram_test_add);
5574
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005575 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
5576 MC_RLDRAM_TEST_GO;
5577 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005578
5579 for (cnt = 0; cnt < 5; cnt++) {
5580 val64 = readq(&bar0->mc_rldram_test_ctrl);
5581 if (val64 & MC_RLDRAM_TEST_DONE)
5582 break;
5583 msleep(200);
5584 }
5585
5586 if (cnt == 5)
5587 break;
5588
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005589 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
5590 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005591
5592 for (cnt = 0; cnt < 5; cnt++) {
5593 val64 = readq(&bar0->mc_rldram_test_ctrl);
5594 if (val64 & MC_RLDRAM_TEST_DONE)
5595 break;
5596 msleep(500);
5597 }
5598
5599 if (cnt == 5)
5600 break;
5601
5602 val64 = readq(&bar0->mc_rldram_test_ctrl);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005603 if (!(val64 & MC_RLDRAM_TEST_PASS))
5604 test_fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605
5606 iteration++;
5607 }
5608
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005609 *data = test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005611 /* Bring the adapter out of test mode */
5612 SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
5613
5614 return test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005615}
5616
5617/**
5618 * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
5619 * @sp : private member of the device structure, which is a pointer to the
5620 * s2io_nic structure.
5621 * @ethtest : pointer to a ethtool command specific structure that will be
5622 * returned to the user.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005623 * @data : variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624 * conducted by the driver.
5625 * Description:
5626 * This function conducts 6 tests ( 4 offline and 2 online) to determine
5627 * the health of the card.
5628 * Return value:
5629 * void
5630 */
5631
5632static void s2io_ethtool_test(struct net_device *dev,
5633 struct ethtool_test *ethtest,
5634 uint64_t * data)
5635{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005636 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637 int orig_state = netif_running(sp->dev);
5638
5639 if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
5640 /* Offline Tests. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005641 if (orig_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642 s2io_close(sp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643
5644 if (s2io_register_test(sp, &data[0]))
5645 ethtest->flags |= ETH_TEST_FL_FAILED;
5646
5647 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648
5649 if (s2io_rldram_test(sp, &data[3]))
5650 ethtest->flags |= ETH_TEST_FL_FAILED;
5651
5652 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653
5654 if (s2io_eeprom_test(sp, &data[1]))
5655 ethtest->flags |= ETH_TEST_FL_FAILED;
5656
5657 if (s2io_bist_test(sp, &data[4]))
5658 ethtest->flags |= ETH_TEST_FL_FAILED;
5659
5660 if (orig_state)
5661 s2io_open(sp->dev);
5662
5663 data[2] = 0;
5664 } else {
5665 /* Online Tests. */
5666 if (!orig_state) {
5667 DBG_PRINT(ERR_DBG,
5668 "%s: is not up, cannot run test\n",
5669 dev->name);
5670 data[0] = -1;
5671 data[1] = -1;
5672 data[2] = -1;
5673 data[3] = -1;
5674 data[4] = -1;
5675 }
5676
5677 if (s2io_link_test(sp, &data[2]))
5678 ethtest->flags |= ETH_TEST_FL_FAILED;
5679
5680 data[0] = 0;
5681 data[1] = 0;
5682 data[3] = 0;
5683 data[4] = 0;
5684 }
5685}
5686
5687static void s2io_get_ethtool_stats(struct net_device *dev,
5688 struct ethtool_stats *estats,
5689 u64 * tmp_stats)
5690{
5691 int i = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005692 struct s2io_nic *sp = dev->priv;
5693 struct stat_block *stat_info = sp->mac_control.stats_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005695 s2io_updt_stats(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005696 tmp_stats[i++] =
5697 (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
5698 le32_to_cpu(stat_info->tmac_frms);
5699 tmp_stats[i++] =
5700 (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
5701 le32_to_cpu(stat_info->tmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005703 tmp_stats[i++] =
5704 (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
5705 le32_to_cpu(stat_info->tmac_mcst_frms);
5706 tmp_stats[i++] =
5707 (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
5708 le32_to_cpu(stat_info->tmac_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005710 tmp_stats[i++] =
5711 (u64)le32_to_cpu(stat_info->tmac_ttl_octets_oflow) << 32 |
5712 le32_to_cpu(stat_info->tmac_ttl_octets);
5713 tmp_stats[i++] =
5714 (u64)le32_to_cpu(stat_info->tmac_ucst_frms_oflow) << 32 |
5715 le32_to_cpu(stat_info->tmac_ucst_frms);
5716 tmp_stats[i++] =
5717 (u64)le32_to_cpu(stat_info->tmac_nucst_frms_oflow) << 32 |
5718 le32_to_cpu(stat_info->tmac_nucst_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005719 tmp_stats[i++] =
5720 (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
5721 le32_to_cpu(stat_info->tmac_any_err_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005722 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_ttl_less_fb_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005724 tmp_stats[i++] =
5725 (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
5726 le32_to_cpu(stat_info->tmac_vld_ip);
5727 tmp_stats[i++] =
5728 (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
5729 le32_to_cpu(stat_info->tmac_drop_ip);
5730 tmp_stats[i++] =
5731 (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
5732 le32_to_cpu(stat_info->tmac_icmp);
5733 tmp_stats[i++] =
5734 (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
5735 le32_to_cpu(stat_info->tmac_rst_tcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005737 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
5738 le32_to_cpu(stat_info->tmac_udp);
5739 tmp_stats[i++] =
5740 (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
5741 le32_to_cpu(stat_info->rmac_vld_frms);
5742 tmp_stats[i++] =
5743 (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
5744 le32_to_cpu(stat_info->rmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
5746 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005747 tmp_stats[i++] =
5748 (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
5749 le32_to_cpu(stat_info->rmac_vld_mcst_frms);
5750 tmp_stats[i++] =
5751 (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
5752 le32_to_cpu(stat_info->rmac_vld_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005754 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_out_rng_len_err_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
5756 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005757 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_unsup_ctrl_frms);
5758 tmp_stats[i++] =
5759 (u64)le32_to_cpu(stat_info->rmac_ttl_octets_oflow) << 32 |
5760 le32_to_cpu(stat_info->rmac_ttl_octets);
5761 tmp_stats[i++] =
5762 (u64)le32_to_cpu(stat_info->rmac_accepted_ucst_frms_oflow)
5763 << 32 | le32_to_cpu(stat_info->rmac_accepted_ucst_frms);
5764 tmp_stats[i++] =
5765 (u64)le32_to_cpu(stat_info->rmac_accepted_nucst_frms_oflow)
5766 << 32 | le32_to_cpu(stat_info->rmac_accepted_nucst_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005767 tmp_stats[i++] =
5768 (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
5769 le32_to_cpu(stat_info->rmac_discarded_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005770 tmp_stats[i++] =
5771 (u64)le32_to_cpu(stat_info->rmac_drop_events_oflow)
5772 << 32 | le32_to_cpu(stat_info->rmac_drop_events);
5773 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_less_fb_octets);
5774 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005775 tmp_stats[i++] =
5776 (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
5777 le32_to_cpu(stat_info->rmac_usized_frms);
5778 tmp_stats[i++] =
5779 (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
5780 le32_to_cpu(stat_info->rmac_osized_frms);
5781 tmp_stats[i++] =
5782 (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
5783 le32_to_cpu(stat_info->rmac_frag_frms);
5784 tmp_stats[i++] =
5785 (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
5786 le32_to_cpu(stat_info->rmac_jabber_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005787 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_64_frms);
5788 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_65_127_frms);
5789 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_128_255_frms);
5790 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_256_511_frms);
5791 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_512_1023_frms);
5792 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_1024_1518_frms);
5793 tmp_stats[i++] =
5794 (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005795 le32_to_cpu(stat_info->rmac_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
5797 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005798 tmp_stats[i++] =
5799 (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005800 le32_to_cpu(stat_info->rmac_drop_ip);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005801 tmp_stats[i++] =
5802 (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005803 le32_to_cpu(stat_info->rmac_icmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005805 tmp_stats[i++] =
5806 (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005807 le32_to_cpu(stat_info->rmac_udp);
5808 tmp_stats[i++] =
5809 (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
5810 le32_to_cpu(stat_info->rmac_err_drp_udp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005811 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_err_sym);
5812 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q0);
5813 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q1);
5814 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q2);
5815 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q3);
5816 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q4);
5817 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q5);
5818 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q6);
5819 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q7);
5820 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q0);
5821 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q1);
5822 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q2);
5823 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q3);
5824 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q4);
5825 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q5);
5826 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q6);
5827 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q7);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005828 tmp_stats[i++] =
5829 (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
5830 le32_to_cpu(stat_info->rmac_pause_cnt);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005831 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_data_err_cnt);
5832 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_ctrl_err_cnt);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005833 tmp_stats[i++] =
5834 (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
5835 le32_to_cpu(stat_info->rmac_accepted_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04005837 tmp_stats[i++] = le32_to_cpu(stat_info->rd_req_cnt);
5838 tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_cnt);
5839 tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_rtry_cnt);
5840 tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_cnt);
5841 tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_rd_ack_cnt);
5842 tmp_stats[i++] = le32_to_cpu(stat_info->wr_req_cnt);
5843 tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_cnt);
5844 tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_rtry_cnt);
5845 tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_cnt);
5846 tmp_stats[i++] = le32_to_cpu(stat_info->wr_disc_cnt);
5847 tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_wr_ack_cnt);
5848 tmp_stats[i++] = le32_to_cpu(stat_info->txp_wr_cnt);
5849 tmp_stats[i++] = le32_to_cpu(stat_info->txd_rd_cnt);
5850 tmp_stats[i++] = le32_to_cpu(stat_info->txd_wr_cnt);
5851 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_rd_cnt);
5852 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_wr_cnt);
5853 tmp_stats[i++] = le32_to_cpu(stat_info->txf_rd_cnt);
5854 tmp_stats[i++] = le32_to_cpu(stat_info->rxf_wr_cnt);
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05005855
5856 /* Enhanced statistics exist only for Hercules */
5857 if(sp->device_type == XFRAME_II_DEVICE) {
5858 tmp_stats[i++] =
5859 le64_to_cpu(stat_info->rmac_ttl_1519_4095_frms);
5860 tmp_stats[i++] =
5861 le64_to_cpu(stat_info->rmac_ttl_4096_8191_frms);
5862 tmp_stats[i++] =
5863 le64_to_cpu(stat_info->rmac_ttl_8192_max_frms);
5864 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_gt_max_frms);
5865 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_osized_alt_frms);
5866 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_jabber_alt_frms);
5867 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_gt_max_alt_frms);
5868 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_vlan_frms);
5869 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_len_discard);
5870 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_fcs_discard);
5871 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pf_discard);
5872 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_da_discard);
5873 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_red_discard);
5874 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_rts_discard);
5875 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ingm_full_discard);
5876 tmp_stats[i++] = le32_to_cpu(stat_info->link_fault_cnt);
5877 }
5878
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07005879 tmp_stats[i++] = 0;
5880 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
5881 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
Ananda Rajubd1034f2006-04-21 19:20:22 -04005882 tmp_stats[i++] = stat_info->sw_stat.parity_err_cnt;
5883 tmp_stats[i++] = stat_info->sw_stat.serious_err_cnt;
5884 tmp_stats[i++] = stat_info->sw_stat.soft_reset_cnt;
5885 tmp_stats[i++] = stat_info->sw_stat.fifo_full_cnt;
5886 tmp_stats[i++] = stat_info->sw_stat.ring_full_cnt;
5887 tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_high;
5888 tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_low;
5889 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_high;
5890 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_low;
5891 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_high;
5892 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_low;
5893 tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_high;
5894 tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_low;
5895 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_high;
5896 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_low;
5897 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_high;
5898 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_low;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05005899 tmp_stats[i++] = stat_info->sw_stat.clubbed_frms_cnt;
5900 tmp_stats[i++] = stat_info->sw_stat.sending_both;
5901 tmp_stats[i++] = stat_info->sw_stat.outof_sequence_pkts;
5902 tmp_stats[i++] = stat_info->sw_stat.flush_max_pkts;
Andrew Mortonfe931392006-02-03 01:45:12 -08005903 if (stat_info->sw_stat.num_aggregations) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04005904 u64 tmp = stat_info->sw_stat.sum_avg_pkts_aggregated;
5905 int count = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04005906 /*
Ananda Rajubd1034f2006-04-21 19:20:22 -04005907 * Since 64-bit divide does not work on all platforms,
5908 * do repeated subtraction.
5909 */
5910 while (tmp >= stat_info->sw_stat.num_aggregations) {
5911 tmp -= stat_info->sw_stat.num_aggregations;
5912 count++;
5913 }
5914 tmp_stats[i++] = count;
Andrew Mortonfe931392006-02-03 01:45:12 -08005915 }
Ananda Rajubd1034f2006-04-21 19:20:22 -04005916 else
5917 tmp_stats[i++] = 0;
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04005918 tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt;
5919 tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04005920 tmp_stats[i++] = stat_info->sw_stat.mem_allocated;
5921 tmp_stats[i++] = stat_info->sw_stat.mem_freed;
5922 tmp_stats[i++] = stat_info->sw_stat.link_up_cnt;
5923 tmp_stats[i++] = stat_info->sw_stat.link_down_cnt;
5924 tmp_stats[i++] = stat_info->sw_stat.link_up_time;
5925 tmp_stats[i++] = stat_info->sw_stat.link_down_time;
5926
5927 tmp_stats[i++] = stat_info->sw_stat.tx_buf_abort_cnt;
5928 tmp_stats[i++] = stat_info->sw_stat.tx_desc_abort_cnt;
5929 tmp_stats[i++] = stat_info->sw_stat.tx_parity_err_cnt;
5930 tmp_stats[i++] = stat_info->sw_stat.tx_link_loss_cnt;
5931 tmp_stats[i++] = stat_info->sw_stat.tx_list_proc_err_cnt;
5932
5933 tmp_stats[i++] = stat_info->sw_stat.rx_parity_err_cnt;
5934 tmp_stats[i++] = stat_info->sw_stat.rx_abort_cnt;
5935 tmp_stats[i++] = stat_info->sw_stat.rx_parity_abort_cnt;
5936 tmp_stats[i++] = stat_info->sw_stat.rx_rda_fail_cnt;
5937 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_prot_cnt;
5938 tmp_stats[i++] = stat_info->sw_stat.rx_fcs_err_cnt;
5939 tmp_stats[i++] = stat_info->sw_stat.rx_buf_size_err_cnt;
5940 tmp_stats[i++] = stat_info->sw_stat.rx_rxd_corrupt_cnt;
5941 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_err_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942}
5943
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005944static int s2io_ethtool_get_regs_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945{
5946 return (XENA_REG_SPACE);
5947}
5948
5949
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005950static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005952 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953
5954 return (sp->rx_csum);
5955}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005956
5957static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005959 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960
5961 if (data)
5962 sp->rx_csum = 1;
5963 else
5964 sp->rx_csum = 0;
5965
5966 return 0;
5967}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005968
5969static int s2io_get_eeprom_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970{
5971 return (XENA_EEPROM_SPACE);
5972}
5973
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005974static int s2io_ethtool_self_test_count(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975{
5976 return (S2IO_TEST_LEN);
5977}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01005978
5979static void s2io_ethtool_get_strings(struct net_device *dev,
5980 u32 stringset, u8 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981{
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05005982 int stat_size = 0;
5983 struct s2io_nic *sp = dev->priv;
5984
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 switch (stringset) {
5986 case ETH_SS_TEST:
5987 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
5988 break;
5989 case ETH_SS_STATS:
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05005990 stat_size = sizeof(ethtool_xena_stats_keys);
5991 memcpy(data, &ethtool_xena_stats_keys,stat_size);
5992 if(sp->device_type == XFRAME_II_DEVICE) {
5993 memcpy(data + stat_size,
5994 &ethtool_enhanced_stats_keys,
5995 sizeof(ethtool_enhanced_stats_keys));
5996 stat_size += sizeof(ethtool_enhanced_stats_keys);
5997 }
5998
5999 memcpy(data + stat_size, &ethtool_driver_stats_keys,
6000 sizeof(ethtool_driver_stats_keys));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 }
6002}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003static int s2io_ethtool_get_stats_count(struct net_device *dev)
6004{
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05006005 struct s2io_nic *sp = dev->priv;
6006 int stat_count = 0;
6007 switch(sp->device_type) {
6008 case XFRAME_I_DEVICE:
6009 stat_count = XFRAME_I_STAT_LEN;
6010 break;
6011
6012 case XFRAME_II_DEVICE:
6013 stat_count = XFRAME_II_STAT_LEN;
6014 break;
6015 }
6016
6017 return stat_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018}
6019
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006020static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021{
6022 if (data)
6023 dev->features |= NETIF_F_IP_CSUM;
6024 else
6025 dev->features &= ~NETIF_F_IP_CSUM;
6026
6027 return 0;
6028}
6029
Ananda Raju75c30b12006-07-24 19:55:09 -04006030static u32 s2io_ethtool_op_get_tso(struct net_device *dev)
6031{
6032 return (dev->features & NETIF_F_TSO) != 0;
6033}
6034static int s2io_ethtool_op_set_tso(struct net_device *dev, u32 data)
6035{
6036 if (data)
6037 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
6038 else
6039 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
6040
6041 return 0;
6042}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043
Jeff Garzik7282d492006-09-13 14:30:00 -04006044static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045 .get_settings = s2io_ethtool_gset,
6046 .set_settings = s2io_ethtool_sset,
6047 .get_drvinfo = s2io_ethtool_gdrvinfo,
6048 .get_regs_len = s2io_ethtool_get_regs_len,
6049 .get_regs = s2io_ethtool_gregs,
6050 .get_link = ethtool_op_get_link,
6051 .get_eeprom_len = s2io_get_eeprom_len,
6052 .get_eeprom = s2io_ethtool_geeprom,
6053 .set_eeprom = s2io_ethtool_seeprom,
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04006054 .get_ringparam = s2io_ethtool_gringparam,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 .get_pauseparam = s2io_ethtool_getpause_data,
6056 .set_pauseparam = s2io_ethtool_setpause_data,
6057 .get_rx_csum = s2io_ethtool_get_rx_csum,
6058 .set_rx_csum = s2io_ethtool_set_rx_csum,
6059 .get_tx_csum = ethtool_op_get_tx_csum,
6060 .set_tx_csum = s2io_ethtool_op_set_tx_csum,
6061 .get_sg = ethtool_op_get_sg,
6062 .set_sg = ethtool_op_set_sg,
Ananda Raju75c30b12006-07-24 19:55:09 -04006063 .get_tso = s2io_ethtool_op_get_tso,
6064 .set_tso = s2io_ethtool_op_set_tso,
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006065 .get_ufo = ethtool_op_get_ufo,
6066 .set_ufo = ethtool_op_set_ufo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 .self_test_count = s2io_ethtool_self_test_count,
6068 .self_test = s2io_ethtool_test,
6069 .get_strings = s2io_ethtool_get_strings,
6070 .phys_id = s2io_ethtool_idnic,
6071 .get_stats_count = s2io_ethtool_get_stats_count,
6072 .get_ethtool_stats = s2io_get_ethtool_stats
6073};
6074
6075/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006076 * s2io_ioctl - Entry point for the Ioctl
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 * @dev : Device pointer.
6078 * @ifr : An IOCTL specefic structure, that can contain a pointer to
6079 * a proprietary structure used to pass information to the driver.
6080 * @cmd : This is used to distinguish between the different commands that
6081 * can be passed to the IOCTL functions.
6082 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006083 * Currently there are no special functionality supported in IOCTL, hence
6084 * function always return EOPNOTSUPPORTED
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 */
6086
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006087static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088{
6089 return -EOPNOTSUPP;
6090}
6091
6092/**
6093 * s2io_change_mtu - entry point to change MTU size for the device.
6094 * @dev : device pointer.
6095 * @new_mtu : the new MTU size for the device.
6096 * Description: A driver entry point to change MTU size for the device.
6097 * Before changing the MTU the device must be stopped.
6098 * Return value:
6099 * 0 on success and an appropriate (-)ve integer as defined in errno.h
6100 * file on failure.
6101 */
6102
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006103static int s2io_change_mtu(struct net_device *dev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006105 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106
6107 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
6108 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
6109 dev->name);
6110 return -EPERM;
6111 }
6112
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 dev->mtu = new_mtu;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006114 if (netif_running(dev)) {
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006115 s2io_card_down(sp);
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006116 netif_stop_queue(dev);
6117 if (s2io_card_up(sp)) {
6118 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
6119 __FUNCTION__);
6120 }
6121 if (netif_queue_stopped(dev))
6122 netif_wake_queue(dev);
6123 } else { /* Device is down */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006124 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006125 u64 val64 = new_mtu;
6126
6127 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
6128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129
6130 return 0;
6131}
6132
6133/**
6134 * s2io_tasklet - Bottom half of the ISR.
6135 * @dev_adr : address of the device structure in dma_addr_t format.
6136 * Description:
6137 * This is the tasklet or the bottom half of the ISR. This is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006138 * an extension of the ISR which is scheduled by the scheduler to be run
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 * 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 -07006140 * be pushed into the tasklet. For now the tasklet is used only to
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 * replenish the Rx buffers in the Rx buffer descriptors.
6142 * Return value:
6143 * void.
6144 */
6145
6146static void s2io_tasklet(unsigned long dev_addr)
6147{
6148 struct net_device *dev = (struct net_device *) dev_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006149 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 int i, ret;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006151 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 struct config_param *config;
6153
6154 mac_control = &sp->mac_control;
6155 config = &sp->config;
6156
6157 if (!TASKLET_IN_USE) {
6158 for (i = 0; i < config->rx_ring_num; i++) {
6159 ret = fill_rx_buffers(sp, i);
6160 if (ret == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006161 DBG_PRINT(INFO_DBG, "%s: Out of ",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006163 DBG_PRINT(INFO_DBG, "memory in tasklet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 break;
6165 } else if (ret == -EFILL) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006166 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 "%s: Rx Ring %d is full\n",
6168 dev->name, i);
6169 break;
6170 }
6171 }
6172 clear_bit(0, (&sp->tasklet_status));
6173 }
6174}
6175
6176/**
6177 * s2io_set_link - Set the LInk status
6178 * @data: long pointer to device private structue
6179 * Description: Sets the link status for the adapter
6180 */
6181
David Howellsc4028952006-11-22 14:57:56 +00006182static void s2io_set_link(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006184 struct s2io_nic *nic = container_of(work, struct s2io_nic, set_link_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 struct net_device *dev = nic->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006186 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 register u64 val64;
6188 u16 subid;
6189
Francois Romieu22747d62007-02-15 23:37:50 +01006190 rtnl_lock();
6191
6192 if (!netif_running(dev))
6193 goto out_unlock;
6194
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 if (test_and_set_bit(0, &(nic->link_state))) {
6196 /* The card is being reset, no point doing anything */
Francois Romieu22747d62007-02-15 23:37:50 +01006197 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 }
6199
6200 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07006201 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
6202 /*
6203 * Allow a small delay for the NICs self initiated
6204 * cleanup to complete.
6205 */
6206 msleep(100);
6207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208
6209 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006210 if (LINK_IS_UP(val64)) {
6211 if (!(readq(&bar0->adapter_control) & ADAPTER_CNTL_EN)) {
6212 if (verify_xena_quiescence(nic)) {
6213 val64 = readq(&bar0->adapter_control);
6214 val64 |= ADAPTER_CNTL_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 writeq(val64, &bar0->adapter_control);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006216 if (CARDS_WITH_FAULTY_LINK_INDICATORS(
6217 nic->device_type, subid)) {
6218 val64 = readq(&bar0->gpio_control);
6219 val64 |= GPIO_CTRL_GPIO_0;
6220 writeq(val64, &bar0->gpio_control);
6221 val64 = readq(&bar0->gpio_control);
6222 } else {
6223 val64 |= ADAPTER_LED_ON;
6224 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07006225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 nic->device_enabled_once = TRUE;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006227 } else {
6228 DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
6229 DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
6230 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006233 val64 = readq(&bar0->adapter_status);
6234 if (!LINK_IS_UP(val64)) {
6235 DBG_PRINT(ERR_DBG, "%s:", dev->name);
6236 DBG_PRINT(ERR_DBG, " Link down after enabling ");
6237 DBG_PRINT(ERR_DBG, "device \n");
6238 } else
6239 s2io_link(nic, LINK_UP);
6240 } else {
6241 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
6242 subid)) {
6243 val64 = readq(&bar0->gpio_control);
6244 val64 &= ~GPIO_CTRL_GPIO_0;
6245 writeq(val64, &bar0->gpio_control);
6246 val64 = readq(&bar0->gpio_control);
6247 }
6248 s2io_link(nic, LINK_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 }
6250 clear_bit(0, &(nic->link_state));
Francois Romieu22747d62007-02-15 23:37:50 +01006251
6252out_unlock:
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05006253 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254}
6255
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006256static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6257 struct buffAdd *ba,
6258 struct sk_buff **skb, u64 *temp0, u64 *temp1,
6259 u64 *temp2, int size)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006260{
6261 struct net_device *dev = sp->dev;
6262 struct sk_buff *frag_list;
6263
6264 if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) {
6265 /* allocate skb */
6266 if (*skb) {
6267 DBG_PRINT(INFO_DBG, "SKB is not NULL\n");
6268 /*
6269 * As Rx frame are not going to be processed,
6270 * using same mapped address for the Rxd
6271 * buffer pointer
6272 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006273 ((struct RxD1*)rxdp)->Buffer0_ptr = *temp0;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006274 } else {
6275 *skb = dev_alloc_skb(size);
6276 if (!(*skb)) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006277 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006278 DBG_PRINT(INFO_DBG, "memory to allocate ");
6279 DBG_PRINT(INFO_DBG, "1 buf mode SKBs\n");
6280 sp->mac_control.stats_info->sw_stat. \
6281 mem_alloc_fail_cnt++;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006282 return -ENOMEM ;
6283 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006284 sp->mac_control.stats_info->sw_stat.mem_allocated
6285 += (*skb)->truesize;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006286 /* storing the mapped addr in a temp variable
6287 * such it will be used for next rxd whose
6288 * Host Control is NULL
6289 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006290 ((struct RxD1*)rxdp)->Buffer0_ptr = *temp0 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006291 pci_map_single( sp->pdev, (*skb)->data,
6292 size - NET_IP_ALIGN,
6293 PCI_DMA_FROMDEVICE);
6294 rxdp->Host_Control = (unsigned long) (*skb);
6295 }
6296 } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
6297 /* Two buffer Mode */
6298 if (*skb) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006299 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2;
6300 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0;
6301 ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006302 } else {
6303 *skb = dev_alloc_skb(size);
David Rientjes2ceaac72006-10-30 14:19:25 -08006304 if (!(*skb)) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006305 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6306 DBG_PRINT(INFO_DBG, "memory to allocate ");
6307 DBG_PRINT(INFO_DBG, "2 buf mode SKBs\n");
6308 sp->mac_control.stats_info->sw_stat. \
6309 mem_alloc_fail_cnt++;
David Rientjes2ceaac72006-10-30 14:19:25 -08006310 return -ENOMEM;
6311 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006312 sp->mac_control.stats_info->sw_stat.mem_allocated
6313 += (*skb)->truesize;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006314 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006315 pci_map_single(sp->pdev, (*skb)->data,
6316 dev->mtu + 4,
6317 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006318 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006319 pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
6320 PCI_DMA_FROMDEVICE);
6321 rxdp->Host_Control = (unsigned long) (*skb);
6322
6323 /* Buffer-1 will be dummy buffer not used */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006324 ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006325 pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
6326 PCI_DMA_FROMDEVICE);
6327 }
6328 } else if ((rxdp->Host_Control == 0)) {
6329 /* Three buffer mode */
6330 if (*skb) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006331 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0;
6332 ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1;
6333 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006334 } else {
6335 *skb = dev_alloc_skb(size);
David Rientjes2ceaac72006-10-30 14:19:25 -08006336 if (!(*skb)) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006337 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6338 DBG_PRINT(INFO_DBG, "memory to allocate ");
6339 DBG_PRINT(INFO_DBG, "3 buf mode SKBs\n");
6340 sp->mac_control.stats_info->sw_stat. \
6341 mem_alloc_fail_cnt++;
David Rientjes2ceaac72006-10-30 14:19:25 -08006342 return -ENOMEM;
6343 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006344 sp->mac_control.stats_info->sw_stat.mem_allocated
6345 += (*skb)->truesize;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006346 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006347 pci_map_single(sp->pdev, ba->ba_0, BUF0_LEN,
6348 PCI_DMA_FROMDEVICE);
6349 /* Buffer-1 receives L3/L4 headers */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006350 ((struct RxD3*)rxdp)->Buffer1_ptr = *temp1 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006351 pci_map_single( sp->pdev, (*skb)->data,
6352 l3l4hdr_size + 4,
6353 PCI_DMA_FROMDEVICE);
6354 /*
6355 * skb_shinfo(skb)->frag_list will have L4
6356 * data payload
6357 */
6358 skb_shinfo(*skb)->frag_list = dev_alloc_skb(dev->mtu +
6359 ALIGN_SIZE);
6360 if (skb_shinfo(*skb)->frag_list == NULL) {
6361 DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb \
6362 failed\n ", dev->name);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006363 sp->mac_control.stats_info->sw_stat. \
6364 mem_alloc_fail_cnt++;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006365 return -ENOMEM ;
6366 }
6367 frag_list = skb_shinfo(*skb)->frag_list;
6368 frag_list->next = NULL;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006369 sp->mac_control.stats_info->sw_stat.mem_allocated
6370 += frag_list->truesize;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006371 /*
6372 * Buffer-2 receives L4 data payload
6373 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006374 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006375 pci_map_single( sp->pdev, frag_list->data,
6376 dev->mtu, PCI_DMA_FROMDEVICE);
6377 }
6378 }
6379 return 0;
6380}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006381static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
6382 int size)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006383{
6384 struct net_device *dev = sp->dev;
6385 if (sp->rxd_mode == RXD_MODE_1) {
6386 rxdp->Control_2 = SET_BUFFER0_SIZE_1( size - NET_IP_ALIGN);
6387 } else if (sp->rxd_mode == RXD_MODE_3B) {
6388 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
6389 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
6390 rxdp->Control_2 |= SET_BUFFER2_SIZE_3( dev->mtu + 4);
6391 } else {
6392 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
6393 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
6394 rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu);
6395 }
6396}
6397
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006398static int rxd_owner_bit_reset(struct s2io_nic *sp)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006399{
6400 int i, j, k, blk_cnt = 0, size;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006401 struct mac_info * mac_control = &sp->mac_control;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006402 struct config_param *config = &sp->config;
6403 struct net_device *dev = sp->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006404 struct RxD_t *rxdp = NULL;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006405 struct sk_buff *skb = NULL;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006406 struct buffAdd *ba = NULL;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006407 u64 temp0_64 = 0, temp1_64 = 0, temp2_64 = 0;
6408
6409 /* Calculate the size based on ring mode */
6410 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
6411 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
6412 if (sp->rxd_mode == RXD_MODE_1)
6413 size += NET_IP_ALIGN;
6414 else if (sp->rxd_mode == RXD_MODE_3B)
6415 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
6416 else
6417 size = l3l4hdr_size + ALIGN_SIZE + BUF0_LEN + 4;
6418
6419 for (i = 0; i < config->rx_ring_num; i++) {
6420 blk_cnt = config->rx_cfg[i].num_rxd /
6421 (rxd_count[sp->rxd_mode] +1);
6422
6423 for (j = 0; j < blk_cnt; j++) {
6424 for (k = 0; k < rxd_count[sp->rxd_mode]; k++) {
6425 rxdp = mac_control->rings[i].
6426 rx_blocks[j].rxds[k].virt_addr;
6427 if(sp->rxd_mode >= RXD_MODE_3A)
6428 ba = &mac_control->rings[i].ba[j][k];
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05006429 if (set_rxd_buffer_pointer(sp, rxdp, ba,
Ananda Raju5d3213c2006-04-21 19:23:26 -04006430 &skb,(u64 *)&temp0_64,
6431 (u64 *)&temp1_64,
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05006432 (u64 *)&temp2_64,
6433 size) == ENOMEM) {
6434 return 0;
6435 }
Ananda Raju5d3213c2006-04-21 19:23:26 -04006436
6437 set_rxd_buffer_size(sp, rxdp, size);
6438 wmb();
6439 /* flip the Ownership bit to Hardware */
6440 rxdp->Control_1 |= RXD_OWN_XENA;
6441 }
6442 }
6443 }
6444 return 0;
6445
6446}
6447
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006448static int s2io_add_isr(struct s2io_nic * sp)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006449{
6450 int ret = 0;
6451 struct net_device *dev = sp->dev;
6452 int err = 0;
6453
6454 if (sp->intr_type == MSI)
6455 ret = s2io_enable_msi(sp);
6456 else if (sp->intr_type == MSI_X)
6457 ret = s2io_enable_msi_x(sp);
6458 if (ret) {
6459 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
6460 sp->intr_type = INTA;
6461 }
6462
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006463 /* Store the values of the MSIX table in the struct s2io_nic structure */
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006464 store_xmsi_data(sp);
6465
6466 /* After proper initialization of H/W, register ISR */
6467 if (sp->intr_type == MSI) {
6468 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
6469 IRQF_SHARED, sp->name, dev);
6470 if (err) {
6471 pci_disable_msi(sp->pdev);
6472 DBG_PRINT(ERR_DBG, "%s: MSI registration failed\n",
6473 dev->name);
6474 return -1;
6475 }
6476 }
6477 if (sp->intr_type == MSI_X) {
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05006478 int i, msix_tx_cnt=0,msix_rx_cnt=0;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006479
6480 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
6481 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
6482 sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
6483 dev->name, i);
6484 err = request_irq(sp->entries[i].vector,
6485 s2io_msix_fifo_handle, 0, sp->desc[i],
6486 sp->s2io_entries[i].arg);
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05006487 /* If either data or addr is zero print it */
6488 if(!(sp->msix_info[i].addr &&
6489 sp->msix_info[i].data)) {
6490 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx"
6491 "Data:0x%lx\n",sp->desc[i],
6492 (unsigned long long)
6493 sp->msix_info[i].addr,
6494 (unsigned long)
6495 ntohl(sp->msix_info[i].data));
6496 } else {
6497 msix_tx_cnt++;
6498 }
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006499 } else {
6500 sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
6501 dev->name, i);
6502 err = request_irq(sp->entries[i].vector,
6503 s2io_msix_ring_handle, 0, sp->desc[i],
6504 sp->s2io_entries[i].arg);
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05006505 /* If either data or addr is zero print it */
6506 if(!(sp->msix_info[i].addr &&
6507 sp->msix_info[i].data)) {
6508 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx"
6509 "Data:0x%lx\n",sp->desc[i],
6510 (unsigned long long)
6511 sp->msix_info[i].addr,
6512 (unsigned long)
6513 ntohl(sp->msix_info[i].data));
6514 } else {
6515 msix_rx_cnt++;
6516 }
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006517 }
6518 if (err) {
6519 DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration "
6520 "failed\n", dev->name, i);
6521 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
6522 return -1;
6523 }
6524 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
6525 }
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05006526 printk("MSI-X-TX %d entries enabled\n",msix_tx_cnt);
6527 printk("MSI-X-RX %d entries enabled\n",msix_rx_cnt);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006528 }
6529 if (sp->intr_type == INTA) {
6530 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
6531 sp->name, dev);
6532 if (err) {
6533 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
6534 dev->name);
6535 return -1;
6536 }
6537 }
6538 return 0;
6539}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006540static void s2io_rem_isr(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541{
6542 int cnt = 0;
Ananda Rajuc92ca042006-04-21 19:18:03 -04006543 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006545 if (sp->intr_type == MSI_X) {
6546 int i;
6547 u16 msi_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006549 for (i=1; (sp->s2io_entries[i].in_use ==
6550 MSIX_REGISTERED_SUCCESS); i++) {
6551 int vector = sp->entries[i].vector;
6552 void *arg = sp->s2io_entries[i].arg;
Ananda Rajuc92ca042006-04-21 19:18:03 -04006553
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006554 free_irq(vector, arg);
6555 }
6556 pci_read_config_word(sp->pdev, 0x42, &msi_control);
6557 msi_control &= 0xFFFE; /* Disable MSI */
6558 pci_write_config_word(sp->pdev, 0x42, msi_control);
Ananda Rajuc92ca042006-04-21 19:18:03 -04006559
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006560 pci_disable_msix(sp->pdev);
6561 } else {
6562 free_irq(sp->pdev->irq, dev);
6563 if (sp->intr_type == MSI) {
6564 u16 val;
6565
6566 pci_disable_msi(sp->pdev);
6567 pci_read_config_word(sp->pdev, 0x4c, &val);
6568 val ^= 0x1;
6569 pci_write_config_word(sp->pdev, 0x4c, val);
Ananda Rajuc92ca042006-04-21 19:18:03 -04006570 }
6571 }
6572 /* Waiting till all Interrupt handlers are complete */
6573 cnt = 0;
6574 do {
6575 msleep(10);
6576 if (!atomic_read(&sp->isr_cnt))
6577 break;
6578 cnt++;
6579 } while(cnt < 5);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006580}
6581
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006582static void s2io_card_down(struct s2io_nic * sp)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006583{
6584 int cnt = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006585 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006586 unsigned long flags;
6587 register u64 val64 = 0;
6588
6589 del_timer_sync(&sp->alarm_timer);
6590 /* If s2io_set_link task is executing, wait till it completes. */
6591 while (test_and_set_bit(0, &(sp->link_state))) {
6592 msleep(50);
6593 }
6594 atomic_set(&sp->card_state, CARD_DOWN);
6595
6596 /* disable Tx and Rx traffic on the NIC */
6597 stop_nic(sp);
6598
6599 s2io_rem_isr(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600
6601 /* Kill tasklet. */
6602 tasklet_kill(&sp->task);
6603
6604 /* Check if the device is Quiescent and then Reset the NIC */
6605 do {
Ananda Raju5d3213c2006-04-21 19:23:26 -04006606 /* As per the HW requirement we need to replenish the
6607 * receive buffer to avoid the ring bump. Since there is
6608 * no intention of processing the Rx frame at this pointwe are
6609 * just settting the ownership bit of rxd in Each Rx
6610 * ring to HW and set the appropriate buffer size
6611 * based on the ring mode
6612 */
6613 rxd_owner_bit_reset(sp);
6614
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006616 if (verify_xena_quiescence(sp)) {
6617 if(verify_pcc_quiescent(sp, sp->device_enabled_once))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 break;
6619 }
6620
6621 msleep(50);
6622 cnt++;
6623 if (cnt == 10) {
6624 DBG_PRINT(ERR_DBG,
6625 "s2io_close:Device not Quiescent ");
6626 DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
6627 (unsigned long long) val64);
6628 break;
6629 }
6630 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 s2io_reset(sp);
6632
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006633 spin_lock_irqsave(&sp->tx_lock, flags);
6634 /* Free all Tx buffers */
6635 free_tx_buffers(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 spin_unlock_irqrestore(&sp->tx_lock, flags);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006637
6638 /* Free all Rx buffers */
6639 spin_lock_irqsave(&sp->rx_lock, flags);
6640 free_rx_buffers(sp);
6641 spin_unlock_irqrestore(&sp->rx_lock, flags);
6642
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 clear_bit(0, &(sp->link_state));
6644}
6645
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006646static int s2io_card_up(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04006648 int i, ret = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006649 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 struct config_param *config;
6651 struct net_device *dev = (struct net_device *) sp->dev;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006652 u16 interruptible;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653
6654 /* Initialize the H/W I/O registers */
6655 if (init_nic(sp) != 0) {
6656 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
6657 dev->name);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006658 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 return -ENODEV;
6660 }
6661
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006662 /*
6663 * Initializing the Rx buffers. For now we are considering only 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 * Rx ring and initializing buffers into 30 Rx blocks
6665 */
6666 mac_control = &sp->mac_control;
6667 config = &sp->config;
6668
6669 for (i = 0; i < config->rx_ring_num; i++) {
6670 if ((ret = fill_rx_buffers(sp, i))) {
6671 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
6672 dev->name);
6673 s2io_reset(sp);
6674 free_rx_buffers(sp);
6675 return -ENOMEM;
6676 }
6677 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
6678 atomic_read(&sp->rx_bufs_left[i]));
6679 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006680 /* Maintain the state prior to the open */
6681 if (sp->promisc_flg)
6682 sp->promisc_flg = 0;
6683 if (sp->m_cast_flg) {
6684 sp->m_cast_flg = 0;
6685 sp->all_multi_pos= 0;
6686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687
6688 /* Setting its receive mode */
6689 s2io_set_multicast(dev);
6690
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006691 if (sp->lro) {
Ananda Rajub41477f2006-07-24 19:52:49 -04006692 /* Initialize max aggregatable pkts per session based on MTU */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006693 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
6694 /* Check if we can use(if specified) user provided value */
6695 if (lro_max_pkts < sp->lro_max_aggr_per_sess)
6696 sp->lro_max_aggr_per_sess = lro_max_pkts;
6697 }
6698
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 /* Enable Rx Traffic and interrupts on the NIC */
6700 if (start_nic(sp)) {
6701 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 s2io_reset(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006703 free_rx_buffers(sp);
6704 return -ENODEV;
6705 }
6706
6707 /* Add interrupt service routine */
6708 if (s2io_add_isr(sp) != 0) {
6709 if (sp->intr_type == MSI_X)
6710 s2io_rem_isr(sp);
6711 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 free_rx_buffers(sp);
6713 return -ENODEV;
6714 }
6715
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07006716 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
6717
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006718 /* Enable tasklet for the device */
6719 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
6720
6721 /* Enable select interrupts */
6722 if (sp->intr_type != INTA)
6723 en_dis_able_nic_intrs(sp, ENA_ALL_INTRS, DISABLE_INTRS);
6724 else {
6725 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
6726 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
6727 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
6728 en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
6729 }
6730
6731
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 atomic_set(&sp->card_state, CARD_UP);
6733 return 0;
6734}
6735
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006736/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737 * s2io_restart_nic - Resets the NIC.
6738 * @data : long pointer to the device private structure
6739 * Description:
6740 * This function is scheduled to be run by the s2io_tx_watchdog
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006741 * function after 0.5 secs to reset the NIC. The idea is to reduce
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 * the run time of the watch dog routine which is run holding a
6743 * spin lock.
6744 */
6745
David Howellsc4028952006-11-22 14:57:56 +00006746static void s2io_restart_nic(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006748 struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
David Howellsc4028952006-11-22 14:57:56 +00006749 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750
Francois Romieu22747d62007-02-15 23:37:50 +01006751 rtnl_lock();
6752
6753 if (!netif_running(dev))
6754 goto out_unlock;
6755
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006756 s2io_card_down(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 if (s2io_card_up(sp)) {
6758 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
6759 dev->name);
6760 }
6761 netif_wake_queue(dev);
6762 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
6763 dev->name);
Francois Romieu22747d62007-02-15 23:37:50 +01006764out_unlock:
6765 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766}
6767
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006768/**
6769 * s2io_tx_watchdog - Watchdog for transmit side.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 * @dev : Pointer to net device structure
6771 * Description:
6772 * This function is triggered if the Tx Queue is stopped
6773 * for a pre-defined amount of time when the Interface is still up.
6774 * If the Interface is jammed in such a situation, the hardware is
6775 * reset (by s2io_close) and restarted again (by s2io_open) to
6776 * overcome any problem that might have been caused in the hardware.
6777 * Return value:
6778 * void
6779 */
6780
6781static void s2io_tx_watchdog(struct net_device *dev)
6782{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006783 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784
6785 if (netif_carrier_ok(dev)) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006786 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 schedule_work(&sp->rst_timer_task);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006788 sp->mac_control.stats_info->sw_stat.soft_reset_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 }
6790}
6791
6792/**
6793 * rx_osm_handler - To perform some OS related operations on SKB.
6794 * @sp: private member of the device structure,pointer to s2io_nic structure.
6795 * @skb : the socket buffer pointer.
6796 * @len : length of the packet
6797 * @cksum : FCS checksum of the frame.
6798 * @ring_no : the ring from which this RxD was extracted.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006799 * Description:
Ananda Rajub41477f2006-07-24 19:52:49 -04006800 * This function is called by the Rx interrupt serivce routine to perform
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 * some OS related operations on the SKB before passing it to the upper
6802 * layers. It mainly checks if the checksum is OK, if so adds it to the
6803 * SKBs cksum variable, increments the Rx packet count and passes the SKB
6804 * to the upper layer. If the checksum is wrong, it increments the Rx
6805 * packet error count, frees the SKB and returns error.
6806 * Return value:
6807 * SUCCESS on success and -1 on failure.
6808 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006809static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006811 struct s2io_nic *sp = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812 struct net_device *dev = (struct net_device *) sp->dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006813 struct sk_buff *skb = (struct sk_buff *)
6814 ((unsigned long) rxdp->Host_Control);
6815 int ring_no = ring_data->ring_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 u16 l3_csum, l4_csum;
Ananda Raju863c11a2006-04-21 19:03:13 -04006817 unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006818 struct lro *lro;
Ananda Rajuda6971d2005-10-31 16:55:31 -05006819
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006820 skb->dev = dev;
Ananda Rajuc92ca042006-04-21 19:18:03 -04006821
Ananda Raju863c11a2006-04-21 19:03:13 -04006822 if (err) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04006823 /* Check for parity error */
6824 if (err & 0x1) {
6825 sp->mac_control.stats_info->sw_stat.parity_err_cnt++;
6826 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006827 err >>= 48;
6828 switch(err) {
6829 case 1:
6830 sp->mac_control.stats_info->sw_stat.
6831 rx_parity_err_cnt++;
6832 break;
Ananda Rajubd1034f2006-04-21 19:20:22 -04006833
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006834 case 2:
6835 sp->mac_control.stats_info->sw_stat.
6836 rx_abort_cnt++;
6837 break;
6838
6839 case 3:
6840 sp->mac_control.stats_info->sw_stat.
6841 rx_parity_abort_cnt++;
6842 break;
6843
6844 case 4:
6845 sp->mac_control.stats_info->sw_stat.
6846 rx_rda_fail_cnt++;
6847 break;
6848
6849 case 5:
6850 sp->mac_control.stats_info->sw_stat.
6851 rx_unkn_prot_cnt++;
6852 break;
6853
6854 case 6:
6855 sp->mac_control.stats_info->sw_stat.
6856 rx_fcs_err_cnt++;
6857 break;
6858
6859 case 7:
6860 sp->mac_control.stats_info->sw_stat.
6861 rx_buf_size_err_cnt++;
6862 break;
6863
6864 case 8:
6865 sp->mac_control.stats_info->sw_stat.
6866 rx_rxd_corrupt_cnt++;
6867 break;
6868
6869 case 15:
6870 sp->mac_control.stats_info->sw_stat.
6871 rx_unkn_err_cnt++;
6872 break;
6873 }
Ananda Raju863c11a2006-04-21 19:03:13 -04006874 /*
6875 * Drop the packet if bad transfer code. Exception being
6876 * 0x5, which could be due to unsupported IPv6 extension header.
6877 * In this case, we let stack handle the packet.
6878 * Note that in this case, since checksum will be incorrect,
6879 * stack will validate the same.
6880 */
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006881 if (err != 0x5) {
Ananda Raju863c11a2006-04-21 19:03:13 -04006882 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
6883 dev->name, err);
6884 sp->stats.rx_crc_errors++;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006885 sp->mac_control.stats_info->sw_stat.mem_freed
6886 += skb->truesize;
Ananda Raju863c11a2006-04-21 19:03:13 -04006887 dev_kfree_skb(skb);
6888 atomic_dec(&sp->rx_bufs_left[ring_no]);
6889 rxdp->Host_Control = 0;
6890 return 0;
6891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006894 /* Updating statistics */
6895 rxdp->Host_Control = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05006896 if (sp->rxd_mode == RXD_MODE_1) {
6897 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898
Ananda Rajuda6971d2005-10-31 16:55:31 -05006899 sp->stats.rx_bytes += len;
6900 skb_put(skb, len);
6901
6902 } else if (sp->rxd_mode >= RXD_MODE_3A) {
6903 int get_block = ring_data->rx_curr_get_info.block_index;
6904 int get_off = ring_data->rx_curr_get_info.offset;
6905 int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
6906 int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
6907 unsigned char *buff = skb_push(skb, buf0_len);
6908
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006909 struct buffAdd *ba = &ring_data->ba[get_block][get_off];
Ananda Rajuda6971d2005-10-31 16:55:31 -05006910 sp->stats.rx_bytes += buf0_len + buf2_len;
6911 memcpy(buff, ba->ba_0, buf0_len);
6912
6913 if (sp->rxd_mode == RXD_MODE_3A) {
6914 int buf1_len = RXD_GET_BUFFER1_SIZE_3(rxdp->Control_2);
6915
6916 skb_put(skb, buf1_len);
6917 skb->len += buf2_len;
6918 skb->data_len += buf2_len;
Ananda Rajuda6971d2005-10-31 16:55:31 -05006919 skb_put(skb_shinfo(skb)->frag_list, buf2_len);
6920 sp->stats.rx_bytes += buf1_len;
6921
6922 } else
6923 skb_put(skb, buf2_len);
6924 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006925
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006926 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!sp->lro) ||
6927 (sp->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006928 (sp->rx_csum)) {
6929 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
6930 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
6931 if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
6932 /*
6933 * NIC verifies if the Checksum of the received
6934 * frame is Ok or not and accordingly returns
6935 * a flag in the RxD.
6936 */
6937 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006938 if (sp->lro) {
6939 u32 tcp_len;
6940 u8 *tcp;
6941 int ret = 0;
6942
6943 ret = s2io_club_tcp_session(skb->data, &tcp,
6944 &tcp_len, &lro, rxdp, sp);
6945 switch (ret) {
6946 case 3: /* Begin anew */
6947 lro->parent = skb;
6948 goto aggregate;
6949 case 1: /* Aggregate */
6950 {
6951 lro_append_pkt(sp, lro,
6952 skb, tcp_len);
6953 goto aggregate;
6954 }
6955 case 4: /* Flush session */
6956 {
6957 lro_append_pkt(sp, lro,
6958 skb, tcp_len);
6959 queue_rx_frame(lro->parent);
6960 clear_lro_session(lro);
6961 sp->mac_control.stats_info->
6962 sw_stat.flush_max_pkts++;
6963 goto aggregate;
6964 }
6965 case 2: /* Flush both */
6966 lro->parent->data_len =
6967 lro->frags_len;
6968 sp->mac_control.stats_info->
6969 sw_stat.sending_both++;
6970 queue_rx_frame(lro->parent);
6971 clear_lro_session(lro);
6972 goto send_up;
6973 case 0: /* sessions exceeded */
Ananda Rajuc92ca042006-04-21 19:18:03 -04006974 case -1: /* non-TCP or not
6975 * L2 aggregatable
6976 */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006977 case 5: /*
6978 * First pkt in session not
6979 * L3/L4 aggregatable
6980 */
6981 break;
6982 default:
6983 DBG_PRINT(ERR_DBG,
6984 "%s: Samadhana!!\n",
6985 __FUNCTION__);
6986 BUG();
6987 }
6988 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006989 } else {
6990 /*
6991 * Packet with erroneous checksum, let the
6992 * upper layers deal with it.
6993 */
6994 skb->ip_summed = CHECKSUM_NONE;
6995 }
6996 } else {
6997 skb->ip_summed = CHECKSUM_NONE;
6998 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006999 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007000 if (!sp->lro) {
7001 skb->protocol = eth_type_trans(skb, dev);
Sivakumar Subramani926930b2007-02-24 01:59:39 -05007002 if ((sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2) &&
7003 vlan_strip_flag)) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007004 /* Queueing the vlan frame to the upper layer */
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007005 if (napi)
7006 vlan_hwaccel_receive_skb(skb, sp->vlgrp,
7007 RXD_GET_VLAN_TAG(rxdp->Control_2));
7008 else
7009 vlan_hwaccel_rx(skb, sp->vlgrp,
7010 RXD_GET_VLAN_TAG(rxdp->Control_2));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007011 } else {
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007012 if (napi)
7013 netif_receive_skb(skb);
7014 else
7015 netif_rx(skb);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007016 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007017 } else {
7018send_up:
7019 queue_rx_frame(skb);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007020 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007021 dev->last_rx = jiffies;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007022aggregate:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007023 atomic_dec(&sp->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 return SUCCESS;
7025}
7026
7027/**
7028 * s2io_link - stops/starts the Tx queue.
7029 * @sp : private member of the device structure, which is a pointer to the
7030 * s2io_nic structure.
7031 * @link : inidicates whether link is UP/DOWN.
7032 * Description:
7033 * This function stops/starts the Tx queue depending on whether the link
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007034 * status of the NIC is is down or up. This is called by the Alarm
7035 * interrupt handler whenever a link change interrupt comes up.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 * Return value:
7037 * void.
7038 */
7039
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007040static void s2io_link(struct s2io_nic * sp, int link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041{
7042 struct net_device *dev = (struct net_device *) sp->dev;
7043
7044 if (link != sp->last_link_state) {
7045 if (link == LINK_DOWN) {
7046 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
7047 netif_carrier_off(dev);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007048 if(sp->mac_control.stats_info->sw_stat.link_up_cnt)
7049 sp->mac_control.stats_info->sw_stat.link_up_time =
7050 jiffies - sp->start_time;
7051 sp->mac_control.stats_info->sw_stat.link_down_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 } else {
7053 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007054 if (sp->mac_control.stats_info->sw_stat.link_down_cnt)
7055 sp->mac_control.stats_info->sw_stat.link_down_time =
7056 jiffies - sp->start_time;
7057 sp->mac_control.stats_info->sw_stat.link_up_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 netif_carrier_on(dev);
7059 }
7060 }
7061 sp->last_link_state = link;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007062 sp->start_time = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063}
7064
7065/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007066 * get_xena_rev_id - to identify revision ID of xena.
7067 * @pdev : PCI Dev structure
7068 * Description:
7069 * Function to identify the Revision ID of xena.
7070 * Return value:
7071 * returns the revision ID of the device.
7072 */
7073
Adrian Bunk26df54b2006-01-14 03:09:40 +01007074static int get_xena_rev_id(struct pci_dev *pdev)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007075{
7076 u8 id = 0;
7077 int ret;
7078 ret = pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) & id);
7079 return id;
7080}
7081
7082/**
7083 * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
7084 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 * s2io_nic structure.
7086 * Description:
7087 * This function initializes a few of the PCI and PCI-X configuration registers
7088 * with recommended values.
7089 * Return value:
7090 * void
7091 */
7092
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007093static void s2io_init_pci(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007094{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007095 u16 pci_cmd = 0, pcix_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007096
7097 /* Enable Data Parity Error Recovery in PCI-X command register. */
7098 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007099 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007100 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007101 (pcix_cmd | 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007103 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104
7105 /* Set the PErr Response bit in PCI command register. */
7106 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
7107 pci_write_config_word(sp->pdev, PCI_COMMAND,
7108 (pci_cmd | PCI_COMMAND_PARITY));
7109 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110}
7111
Ananda Raju9dc737a2006-04-21 19:05:41 -04007112static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type)
7113{
7114 if ( tx_fifo_num > 8) {
7115 DBG_PRINT(ERR_DBG, "s2io: Requested number of Tx fifos not "
7116 "supported\n");
7117 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Tx fifos\n");
7118 tx_fifo_num = 8;
7119 }
7120 if ( rx_ring_num > 8) {
7121 DBG_PRINT(ERR_DBG, "s2io: Requested number of Rx rings not "
7122 "supported\n");
7123 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Rx rings\n");
7124 rx_ring_num = 8;
7125 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007126 if (*dev_intr_type != INTA)
7127 napi = 0;
7128
Ananda Raju9dc737a2006-04-21 19:05:41 -04007129#ifndef CONFIG_PCI_MSI
7130 if (*dev_intr_type != INTA) {
7131 DBG_PRINT(ERR_DBG, "s2io: This kernel does not support"
7132 "MSI/MSI-X. Defaulting to INTA\n");
7133 *dev_intr_type = INTA;
7134 }
7135#else
7136 if (*dev_intr_type > MSI_X) {
7137 DBG_PRINT(ERR_DBG, "s2io: Wrong intr_type requested. "
7138 "Defaulting to INTA\n");
7139 *dev_intr_type = INTA;
7140 }
7141#endif
7142 if ((*dev_intr_type == MSI_X) &&
7143 ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
7144 (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007145 DBG_PRINT(ERR_DBG, "s2io: Xframe I does not support MSI_X. "
Ananda Raju9dc737a2006-04-21 19:05:41 -04007146 "Defaulting to INTA\n");
7147 *dev_intr_type = INTA;
7148 }
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007149
Ananda Raju9dc737a2006-04-21 19:05:41 -04007150 if (rx_ring_mode > 3) {
7151 DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
7152 DBG_PRINT(ERR_DBG, "s2io: Defaulting to 3-buffer mode\n");
7153 rx_ring_mode = 3;
7154 }
7155 return SUCCESS;
7156}
7157
Linus Torvalds1da177e2005-04-16 15:20:36 -07007158/**
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05007159 * rts_ds_steer - Receive traffic steering based on IPv4 or IPv6 TOS
7160 * or Traffic class respectively.
7161 * @nic: device peivate variable
7162 * Description: The function configures the receive steering to
7163 * desired receive ring.
7164 * Return Value: SUCCESS on success and
7165 * '-1' on failure (endian settings incorrect).
7166 */
7167static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
7168{
7169 struct XENA_dev_config __iomem *bar0 = nic->bar0;
7170 register u64 val64 = 0;
7171
7172 if (ds_codepoint > 63)
7173 return FAILURE;
7174
7175 val64 = RTS_DS_MEM_DATA(ring);
7176 writeq(val64, &bar0->rts_ds_mem_data);
7177
7178 val64 = RTS_DS_MEM_CTRL_WE |
7179 RTS_DS_MEM_CTRL_STROBE_NEW_CMD |
7180 RTS_DS_MEM_CTRL_OFFSET(ds_codepoint);
7181
7182 writeq(val64, &bar0->rts_ds_mem_ctrl);
7183
7184 return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
7185 RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
7186 S2IO_BIT_RESET);
7187}
7188
7189/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007190 * s2io_init_nic - Initialization of the adapter .
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 * @pdev : structure containing the PCI related information of the device.
7192 * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
7193 * Description:
7194 * The function initializes an adapter identified by the pci_dec structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007195 * All OS related initialization including memory and device structure and
7196 * initlaization of the device private variable is done. Also the swapper
7197 * control register is initialized to enable read and write into the I/O
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198 * registers of the device.
7199 * Return value:
7200 * returns 0 on success and negative on failure.
7201 */
7202
7203static int __devinit
7204s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7205{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007206 struct s2io_nic *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007207 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208 int i, j, ret;
7209 int dma_flag = FALSE;
7210 u32 mac_up, mac_down;
7211 u64 val64 = 0, tmp64 = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007212 struct XENA_dev_config __iomem *bar0 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213 u16 subid;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007214 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215 struct config_param *config;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007216 int mode;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007217 u8 dev_intr_type = intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218
Ananda Raju9dc737a2006-04-21 19:05:41 -04007219 if ((ret = s2io_verify_parm(pdev, &dev_intr_type)))
7220 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007221
7222 if ((ret = pci_enable_device(pdev))) {
7223 DBG_PRINT(ERR_DBG,
7224 "s2io_init_nic: pci_enable_device failed\n");
7225 return ret;
7226 }
7227
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007228 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007229 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
7230 dma_flag = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007231 if (pci_set_consistent_dma_mask
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007232 (pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007233 DBG_PRINT(ERR_DBG,
7234 "Unable to obtain 64bit DMA for \
7235 consistent allocations\n");
7236 pci_disable_device(pdev);
7237 return -ENOMEM;
7238 }
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007239 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007240 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
7241 } else {
7242 pci_disable_device(pdev);
7243 return -ENOMEM;
7244 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007245 if (dev_intr_type != MSI_X) {
7246 if (pci_request_regions(pdev, s2io_driver_name)) {
Ananda Rajub41477f2006-07-24 19:52:49 -04007247 DBG_PRINT(ERR_DBG, "Request Regions failed\n");
7248 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007249 return -ENODEV;
7250 }
7251 }
7252 else {
7253 if (!(request_mem_region(pci_resource_start(pdev, 0),
7254 pci_resource_len(pdev, 0), s2io_driver_name))) {
7255 DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
7256 pci_disable_device(pdev);
7257 return -ENODEV;
7258 }
7259 if (!(request_mem_region(pci_resource_start(pdev, 2),
7260 pci_resource_len(pdev, 2), s2io_driver_name))) {
7261 DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
7262 release_mem_region(pci_resource_start(pdev, 0),
7263 pci_resource_len(pdev, 0));
7264 pci_disable_device(pdev);
7265 return -ENODEV;
7266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007267 }
7268
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007269 dev = alloc_etherdev(sizeof(struct s2io_nic));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270 if (dev == NULL) {
7271 DBG_PRINT(ERR_DBG, "Device allocation failed\n");
7272 pci_disable_device(pdev);
7273 pci_release_regions(pdev);
7274 return -ENODEV;
7275 }
7276
7277 pci_set_master(pdev);
7278 pci_set_drvdata(pdev, dev);
7279 SET_MODULE_OWNER(dev);
7280 SET_NETDEV_DEV(dev, &pdev->dev);
7281
7282 /* Private member variable initialized to s2io NIC structure */
7283 sp = dev->priv;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007284 memset(sp, 0, sizeof(struct s2io_nic));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285 sp->dev = dev;
7286 sp->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007287 sp->high_dma_flag = dma_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007288 sp->device_enabled_once = FALSE;
Ananda Rajuda6971d2005-10-31 16:55:31 -05007289 if (rx_ring_mode == 1)
7290 sp->rxd_mode = RXD_MODE_1;
7291 if (rx_ring_mode == 2)
7292 sp->rxd_mode = RXD_MODE_3B;
7293 if (rx_ring_mode == 3)
7294 sp->rxd_mode = RXD_MODE_3A;
7295
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007296 sp->intr_type = dev_intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007297
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007298 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
7299 (pdev->device == PCI_DEVICE_ID_HERC_UNI))
7300 sp->device_type = XFRAME_II_DEVICE;
7301 else
7302 sp->device_type = XFRAME_I_DEVICE;
7303
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007304 sp->lro = lro;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007305
Linus Torvalds1da177e2005-04-16 15:20:36 -07007306 /* Initialize some PCI/PCI-X fields of the NIC. */
7307 s2io_init_pci(sp);
7308
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007309 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007310 * Setting the device configuration parameters.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007311 * Most of these parameters can be specified by the user during
7312 * module insertion as they are module loadable parameters. If
7313 * these parameters are not not specified during load time, they
Linus Torvalds1da177e2005-04-16 15:20:36 -07007314 * are initialized with default values.
7315 */
7316 mac_control = &sp->mac_control;
7317 config = &sp->config;
7318
7319 /* Tx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007320 config->tx_fifo_num = tx_fifo_num;
7321 for (i = 0; i < MAX_TX_FIFOS; i++) {
7322 config->tx_cfg[i].fifo_len = tx_fifo_len[i];
7323 config->tx_cfg[i].fifo_priority = i;
7324 }
7325
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007326 /* mapping the QoS priority to the configured fifos */
7327 for (i = 0; i < MAX_TX_FIFOS; i++)
7328 config->fifo_mapping[i] = fifo_map[config->tx_fifo_num][i];
7329
Linus Torvalds1da177e2005-04-16 15:20:36 -07007330 config->tx_intr_type = TXD_INT_TYPE_UTILZ;
7331 for (i = 0; i < config->tx_fifo_num; i++) {
7332 config->tx_cfg[i].f_no_snoop =
7333 (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
7334 if (config->tx_cfg[i].fifo_len < 65) {
7335 config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
7336 break;
7337 }
7338 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05007339 /* + 2 because one Txd for skb->data and one Txd for UFO */
7340 config->max_txds = MAX_SKB_FRAGS + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007341
7342 /* Rx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007343 config->rx_ring_num = rx_ring_num;
7344 for (i = 0; i < MAX_RX_RINGS; i++) {
7345 config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
Ananda Rajuda6971d2005-10-31 16:55:31 -05007346 (rxd_count[sp->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007347 config->rx_cfg[i].ring_priority = i;
7348 }
7349
7350 for (i = 0; i < rx_ring_num; i++) {
7351 config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
7352 config->rx_cfg[i].f_no_snoop =
7353 (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
7354 }
7355
7356 /* Setting Mac Control parameters */
7357 mac_control->rmac_pause_time = rmac_pause_time;
7358 mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
7359 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
7360
7361
7362 /* Initialize Ring buffer parameters. */
7363 for (i = 0; i < config->rx_ring_num; i++)
7364 atomic_set(&sp->rx_bufs_left[i], 0);
7365
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007366 /* Initialize the number of ISRs currently running */
7367 atomic_set(&sp->isr_cnt, 0);
7368
Linus Torvalds1da177e2005-04-16 15:20:36 -07007369 /* initialize the shared memory used by the NIC and the host */
7370 if (init_shared_mem(sp)) {
7371 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
Ananda Rajub41477f2006-07-24 19:52:49 -04007372 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007373 ret = -ENOMEM;
7374 goto mem_alloc_failed;
7375 }
7376
7377 sp->bar0 = ioremap(pci_resource_start(pdev, 0),
7378 pci_resource_len(pdev, 0));
7379 if (!sp->bar0) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007380 DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem1\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007381 dev->name);
7382 ret = -ENOMEM;
7383 goto bar0_remap_failed;
7384 }
7385
7386 sp->bar1 = ioremap(pci_resource_start(pdev, 2),
7387 pci_resource_len(pdev, 2));
7388 if (!sp->bar1) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007389 DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem2\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007390 dev->name);
7391 ret = -ENOMEM;
7392 goto bar1_remap_failed;
7393 }
7394
7395 dev->irq = pdev->irq;
7396 dev->base_addr = (unsigned long) sp->bar0;
7397
7398 /* Initializing the BAR1 address as the start of the FIFO pointer. */
7399 for (j = 0; j < MAX_TX_FIFOS; j++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007400 mac_control->tx_FIFO_start[j] = (struct TxFIFO_element __iomem *)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007401 (sp->bar1 + (j * 0x00020000));
7402 }
7403
7404 /* Driver entry points */
7405 dev->open = &s2io_open;
7406 dev->stop = &s2io_close;
7407 dev->hard_start_xmit = &s2io_xmit;
7408 dev->get_stats = &s2io_get_stats;
7409 dev->set_multicast_list = &s2io_set_multicast;
7410 dev->do_ioctl = &s2io_ioctl;
7411 dev->change_mtu = &s2io_change_mtu;
7412 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07007413 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
7414 dev->vlan_rx_register = s2io_vlan_rx_register;
7415 dev->vlan_rx_kill_vid = (void *)s2io_vlan_rx_kill_vid;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007416
Linus Torvalds1da177e2005-04-16 15:20:36 -07007417 /*
7418 * will use eth_mac_addr() for dev->set_mac_address
7419 * mac address will be set every time dev->open() is called
7420 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007421 dev->poll = s2io_poll;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007422 dev->weight = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007423
Brian Haley612eff02006-06-15 14:36:36 -04007424#ifdef CONFIG_NET_POLL_CONTROLLER
7425 dev->poll_controller = s2io_netpoll;
7426#endif
7427
Linus Torvalds1da177e2005-04-16 15:20:36 -07007428 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
7429 if (sp->high_dma_flag == TRUE)
7430 dev->features |= NETIF_F_HIGHDMA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007431 dev->features |= NETIF_F_TSO;
Herbert Xuf83ef8c2006-06-30 13:37:03 -07007432 dev->features |= NETIF_F_TSO6;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007433 if ((sp->device_type & XFRAME_II_DEVICE) && (ufo)) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05007434 dev->features |= NETIF_F_UFO;
7435 dev->features |= NETIF_F_HW_CSUM;
7436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007437
7438 dev->tx_timeout = &s2io_tx_watchdog;
7439 dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
David Howellsc4028952006-11-22 14:57:56 +00007440 INIT_WORK(&sp->rst_timer_task, s2io_restart_nic);
7441 INIT_WORK(&sp->set_link_task, s2io_set_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007442
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07007443 pci_save_state(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007444
7445 /* Setting swapper control on the NIC, for proper reset operation */
7446 if (s2io_set_swapper(sp)) {
7447 DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
7448 dev->name);
7449 ret = -EAGAIN;
7450 goto set_swap_failed;
7451 }
7452
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007453 /* Verify if the Herc works on the slot its placed into */
7454 if (sp->device_type & XFRAME_II_DEVICE) {
7455 mode = s2io_verify_pci_mode(sp);
7456 if (mode < 0) {
7457 DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);
7458 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
7459 ret = -EBADSLT;
7460 goto set_swap_failed;
7461 }
7462 }
7463
7464 /* Not needed for Herc */
7465 if (sp->device_type & XFRAME_I_DEVICE) {
7466 /*
7467 * Fix for all "FFs" MAC address problems observed on
7468 * Alpha platforms
7469 */
7470 fix_mac_address(sp);
7471 s2io_reset(sp);
7472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007473
7474 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007475 * MAC address initialization.
7476 * For now only one mac address will be read and used.
7477 */
7478 bar0 = sp->bar0;
7479 val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
7480 RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
7481 writeq(val64, &bar0->rmac_addr_cmd_mem);
Ananda Rajuc92ca042006-04-21 19:18:03 -04007482 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05007483 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007484 tmp64 = readq(&bar0->rmac_addr_data0_mem);
7485 mac_down = (u32) tmp64;
7486 mac_up = (u32) (tmp64 >> 32);
7487
Linus Torvalds1da177e2005-04-16 15:20:36 -07007488 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
7489 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
7490 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
7491 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
7492 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
7493 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
7494
Linus Torvalds1da177e2005-04-16 15:20:36 -07007495 /* Set the factory defined MAC address initially */
7496 dev->addr_len = ETH_ALEN;
7497 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
7498
Ananda Rajub41477f2006-07-24 19:52:49 -04007499 /* reset Nic and bring it to known state */
7500 s2io_reset(sp);
7501
Linus Torvalds1da177e2005-04-16 15:20:36 -07007502 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007503 * Initialize the tasklet status and link state flags
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007504 * and the card state parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -07007505 */
7506 atomic_set(&(sp->card_state), 0);
7507 sp->tasklet_status = 0;
7508 sp->link_state = 0;
7509
Linus Torvalds1da177e2005-04-16 15:20:36 -07007510 /* Initialize spinlocks */
7511 spin_lock_init(&sp->tx_lock);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007512
7513 if (!napi)
7514 spin_lock_init(&sp->put_lock);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007515 spin_lock_init(&sp->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007516
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007517 /*
7518 * SXE-002: Configure link and activity LED to init state
7519 * on driver load.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007520 */
7521 subid = sp->pdev->subsystem_device;
7522 if ((subid & 0xFF) >= 0x07) {
7523 val64 = readq(&bar0->gpio_control);
7524 val64 |= 0x0000800000000000ULL;
7525 writeq(val64, &bar0->gpio_control);
7526 val64 = 0x0411040400000000ULL;
7527 writeq(val64, (void __iomem *) bar0 + 0x2700);
7528 val64 = readq(&bar0->gpio_control);
7529 }
7530
7531 sp->rx_csum = 1; /* Rx chksum verify enabled by default */
7532
7533 if (register_netdev(dev)) {
7534 DBG_PRINT(ERR_DBG, "Device registration failed\n");
7535 ret = -ENODEV;
7536 goto register_failed;
7537 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04007538 s2io_vpd_read(sp);
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08007539 DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2007 Neterion Inc.\n");
Ananda Rajub41477f2006-07-24 19:52:49 -04007540 DBG_PRINT(ERR_DBG, "%s: Neterion %s (rev %d)\n",dev->name,
7541 sp->product_name, get_xena_rev_id(sp->pdev));
7542 DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
7543 s2io_driver_version);
Ananda Raju9dc737a2006-04-21 19:05:41 -04007544 DBG_PRINT(ERR_DBG, "%s: MAC ADDR: "
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007545 "%02x:%02x:%02x:%02x:%02x:%02x", dev->name,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007546 sp->def_mac_addr[0].mac_addr[0],
7547 sp->def_mac_addr[0].mac_addr[1],
7548 sp->def_mac_addr[0].mac_addr[2],
7549 sp->def_mac_addr[0].mac_addr[3],
7550 sp->def_mac_addr[0].mac_addr[4],
7551 sp->def_mac_addr[0].mac_addr[5]);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007552 DBG_PRINT(ERR_DBG, "SERIAL NUMBER: %s\n", sp->serial_num);
Ananda Raju9dc737a2006-04-21 19:05:41 -04007553 if (sp->device_type & XFRAME_II_DEVICE) {
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07007554 mode = s2io_print_pci_mode(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007555 if (mode < 0) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04007556 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007557 ret = -EBADSLT;
Ananda Raju9dc737a2006-04-21 19:05:41 -04007558 unregister_netdev(dev);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007559 goto set_swap_failed;
7560 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007561 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04007562 switch(sp->rxd_mode) {
7563 case RXD_MODE_1:
7564 DBG_PRINT(ERR_DBG, "%s: 1-Buffer receive mode enabled\n",
7565 dev->name);
7566 break;
7567 case RXD_MODE_3B:
7568 DBG_PRINT(ERR_DBG, "%s: 2-Buffer receive mode enabled\n",
7569 dev->name);
7570 break;
7571 case RXD_MODE_3A:
7572 DBG_PRINT(ERR_DBG, "%s: 3-Buffer receive mode enabled\n",
7573 dev->name);
7574 break;
7575 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007576
7577 if (napi)
7578 DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
Ananda Raju9dc737a2006-04-21 19:05:41 -04007579 switch(sp->intr_type) {
7580 case INTA:
7581 DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
7582 break;
7583 case MSI:
7584 DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI\n", dev->name);
7585 break;
7586 case MSI_X:
7587 DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
7588 break;
7589 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007590 if (sp->lro)
7591 DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
Ananda Raju9dc737a2006-04-21 19:05:41 -04007592 dev->name);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007593 if (ufo)
7594 DBG_PRINT(ERR_DBG, "%s: UDP Fragmentation Offload(UFO)"
7595 " enabled\n", dev->name);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007596 /* Initialize device name */
Ananda Raju9dc737a2006-04-21 19:05:41 -04007597 sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007598
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07007599 /* Initialize bimodal Interrupts */
7600 sp->config.bimodal = bimodal;
7601 if (!(sp->device_type & XFRAME_II_DEVICE) && bimodal) {
7602 sp->config.bimodal = 0;
7603 DBG_PRINT(ERR_DBG,"%s:Bimodal intr not supported by Xframe I\n",
7604 dev->name);
7605 }
7606
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007607 /*
7608 * Make Link state as off at this point, when the Link change
7609 * interrupt comes the state will be automatically changed to
Linus Torvalds1da177e2005-04-16 15:20:36 -07007610 * the right state.
7611 */
7612 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007613
7614 return 0;
7615
7616 register_failed:
7617 set_swap_failed:
7618 iounmap(sp->bar1);
7619 bar1_remap_failed:
7620 iounmap(sp->bar0);
7621 bar0_remap_failed:
7622 mem_alloc_failed:
7623 free_shared_mem(sp);
7624 pci_disable_device(pdev);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007625 if (dev_intr_type != MSI_X)
7626 pci_release_regions(pdev);
7627 else {
7628 release_mem_region(pci_resource_start(pdev, 0),
7629 pci_resource_len(pdev, 0));
7630 release_mem_region(pci_resource_start(pdev, 2),
7631 pci_resource_len(pdev, 2));
7632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007633 pci_set_drvdata(pdev, NULL);
7634 free_netdev(dev);
7635
7636 return ret;
7637}
7638
7639/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007640 * s2io_rem_nic - Free the PCI device
Linus Torvalds1da177e2005-04-16 15:20:36 -07007641 * @pdev: structure containing the PCI related information of the device.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007642 * Description: This function is called by the Pci subsystem to release a
Linus Torvalds1da177e2005-04-16 15:20:36 -07007643 * PCI device and free up all resource held up by the device. This could
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007644 * be in response to a Hot plug event or when the driver is to be removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07007645 * from memory.
7646 */
7647
7648static void __devexit s2io_rem_nic(struct pci_dev *pdev)
7649{
7650 struct net_device *dev =
7651 (struct net_device *) pci_get_drvdata(pdev);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007652 struct s2io_nic *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007653
7654 if (dev == NULL) {
7655 DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
7656 return;
7657 }
7658
Francois Romieu22747d62007-02-15 23:37:50 +01007659 flush_scheduled_work();
7660
Linus Torvalds1da177e2005-04-16 15:20:36 -07007661 sp = dev->priv;
7662 unregister_netdev(dev);
7663
7664 free_shared_mem(sp);
7665 iounmap(sp->bar0);
7666 iounmap(sp->bar1);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007667 if (sp->intr_type != MSI_X)
7668 pci_release_regions(pdev);
7669 else {
7670 release_mem_region(pci_resource_start(pdev, 0),
7671 pci_resource_len(pdev, 0));
7672 release_mem_region(pci_resource_start(pdev, 2),
7673 pci_resource_len(pdev, 2));
7674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007675 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007676 free_netdev(dev);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007677 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007678}
7679
7680/**
7681 * s2io_starter - Entry point for the driver
7682 * Description: This function is the entry point for the driver. It verifies
7683 * the module loadable parameters and initializes PCI configuration space.
7684 */
7685
7686int __init s2io_starter(void)
7687{
Jeff Garzik29917622006-08-19 17:48:59 -04007688 return pci_register_driver(&s2io_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007689}
7690
7691/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007692 * s2io_closer - Cleanup routine for the driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07007693 * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
7694 */
7695
Sivakumar Subramani372cc592007-01-31 13:32:57 -05007696static __exit void s2io_closer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007697{
7698 pci_unregister_driver(&s2io_driver);
7699 DBG_PRINT(INIT_DBG, "cleanup done\n");
7700}
7701
7702module_init(s2io_starter);
7703module_exit(s2io_closer);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007704
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007705static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007706 struct tcphdr **tcp, struct RxD_t *rxdp)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007707{
7708 int ip_off;
7709 u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
7710
7711 if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
7712 DBG_PRINT(INIT_DBG,"%s: Non-TCP frames not supported for LRO\n",
7713 __FUNCTION__);
7714 return -1;
7715 }
7716
7717 /* TODO:
7718 * By default the VLAN field in the MAC is stripped by the card, if this
7719 * feature is turned off in rx_pa_cfg register, then the ip_off field
7720 * has to be shifted by a further 2 bytes
7721 */
7722 switch (l2_type) {
7723 case 0: /* DIX type */
7724 case 4: /* DIX type with VLAN */
7725 ip_off = HEADER_ETHERNET_II_802_3_SIZE;
7726 break;
7727 /* LLC, SNAP etc are considered non-mergeable */
7728 default:
7729 return -1;
7730 }
7731
7732 *ip = (struct iphdr *)((u8 *)buffer + ip_off);
7733 ip_len = (u8)((*ip)->ihl);
7734 ip_len <<= 2;
7735 *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
7736
7737 return 0;
7738}
7739
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007740static int check_for_socket_match(struct lro *lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007741 struct tcphdr *tcp)
7742{
7743 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
7744 if ((lro->iph->saddr != ip->saddr) || (lro->iph->daddr != ip->daddr) ||
7745 (lro->tcph->source != tcp->source) || (lro->tcph->dest != tcp->dest))
7746 return -1;
7747 return 0;
7748}
7749
7750static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
7751{
7752 return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
7753}
7754
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007755static void initiate_new_session(struct lro *lro, u8 *l2h,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007756 struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len)
7757{
7758 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
7759 lro->l2h = l2h;
7760 lro->iph = ip;
7761 lro->tcph = tcp;
7762 lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
7763 lro->tcp_ack = ntohl(tcp->ack_seq);
7764 lro->sg_num = 1;
7765 lro->total_len = ntohs(ip->tot_len);
7766 lro->frags_len = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007767 /*
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007768 * check if we saw TCP timestamp. Other consistency checks have
7769 * already been done.
7770 */
7771 if (tcp->doff == 8) {
7772 u32 *ptr;
7773 ptr = (u32 *)(tcp+1);
7774 lro->saw_ts = 1;
7775 lro->cur_tsval = *(ptr+1);
7776 lro->cur_tsecr = *(ptr+2);
7777 }
7778 lro->in_use = 1;
7779}
7780
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007781static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007782{
7783 struct iphdr *ip = lro->iph;
7784 struct tcphdr *tcp = lro->tcph;
Al Virobd4f3ae2007-02-09 16:40:15 +00007785 __sum16 nchk;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007786 struct stat_block *statinfo = sp->mac_control.stats_info;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007787 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
7788
7789 /* Update L3 header */
7790 ip->tot_len = htons(lro->total_len);
7791 ip->check = 0;
7792 nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
7793 ip->check = nchk;
7794
7795 /* Update L4 header */
7796 tcp->ack_seq = lro->tcp_ack;
7797 tcp->window = lro->window;
7798
7799 /* Update tsecr field if this session has timestamps enabled */
7800 if (lro->saw_ts) {
7801 u32 *ptr = (u32 *)(tcp + 1);
7802 *(ptr+2) = lro->cur_tsecr;
7803 }
7804
7805 /* Update counters required for calculation of
7806 * average no. of packets aggregated.
7807 */
7808 statinfo->sw_stat.sum_avg_pkts_aggregated += lro->sg_num;
7809 statinfo->sw_stat.num_aggregations++;
7810}
7811
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007812static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007813 struct tcphdr *tcp, u32 l4_pyld)
7814{
7815 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
7816 lro->total_len += l4_pyld;
7817 lro->frags_len += l4_pyld;
7818 lro->tcp_next_seq += l4_pyld;
7819 lro->sg_num++;
7820
7821 /* Update ack seq no. and window ad(from this pkt) in LRO object */
7822 lro->tcp_ack = tcp->ack_seq;
7823 lro->window = tcp->window;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007824
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007825 if (lro->saw_ts) {
7826 u32 *ptr;
7827 /* Update tsecr and tsval from this packet */
7828 ptr = (u32 *) (tcp + 1);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007829 lro->cur_tsval = *(ptr + 1);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007830 lro->cur_tsecr = *(ptr + 2);
7831 }
7832}
7833
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007834static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007835 struct tcphdr *tcp, u32 tcp_pyld_len)
7836{
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007837 u8 *ptr;
7838
Andrew Morton79dc1902006-02-03 01:45:13 -08007839 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
7840
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007841 if (!tcp_pyld_len) {
7842 /* Runt frame or a pure ack */
7843 return -1;
7844 }
7845
7846 if (ip->ihl != 5) /* IP has options */
7847 return -1;
7848
Ananda Raju75c30b12006-07-24 19:55:09 -04007849 /* If we see CE codepoint in IP header, packet is not mergeable */
7850 if (INET_ECN_is_ce(ipv4_get_dsfield(ip)))
7851 return -1;
7852
7853 /* If we see ECE or CWR flags in TCP header, packet is not mergeable */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007854 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
Ananda Raju75c30b12006-07-24 19:55:09 -04007855 tcp->ece || tcp->cwr || !tcp->ack) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007856 /*
7857 * Currently recognize only the ack control word and
7858 * any other control field being set would result in
7859 * flushing the LRO session
7860 */
7861 return -1;
7862 }
7863
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007864 /*
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007865 * Allow only one TCP timestamp option. Don't aggregate if
7866 * any other options are detected.
7867 */
7868 if (tcp->doff != 5 && tcp->doff != 8)
7869 return -1;
7870
7871 if (tcp->doff == 8) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007872 ptr = (u8 *)(tcp + 1);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007873 while (*ptr == TCPOPT_NOP)
7874 ptr++;
7875 if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
7876 return -1;
7877
7878 /* Ensure timestamp value increases monotonically */
7879 if (l_lro)
7880 if (l_lro->cur_tsval > *((u32 *)(ptr+2)))
7881 return -1;
7882
7883 /* timestamp echo reply should be non-zero */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007884 if (*((u32 *)(ptr+6)) == 0)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007885 return -1;
7886 }
7887
7888 return 0;
7889}
7890
7891static int
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007892s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
7893 struct RxD_t *rxdp, struct s2io_nic *sp)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007894{
7895 struct iphdr *ip;
7896 struct tcphdr *tcph;
7897 int ret = 0, i;
7898
7899 if (!(ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
7900 rxdp))) {
7901 DBG_PRINT(INFO_DBG,"IP Saddr: %x Daddr: %x\n",
7902 ip->saddr, ip->daddr);
7903 } else {
7904 return ret;
7905 }
7906
7907 tcph = (struct tcphdr *)*tcp;
7908 *tcp_len = get_l4_pyld_length(ip, tcph);
7909 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007910 struct lro *l_lro = &sp->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007911 if (l_lro->in_use) {
7912 if (check_for_socket_match(l_lro, ip, tcph))
7913 continue;
7914 /* Sock pair matched */
7915 *lro = l_lro;
7916
7917 if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
7918 DBG_PRINT(INFO_DBG, "%s:Out of order. expected "
7919 "0x%x, actual 0x%x\n", __FUNCTION__,
7920 (*lro)->tcp_next_seq,
7921 ntohl(tcph->seq));
7922
7923 sp->mac_control.stats_info->
7924 sw_stat.outof_sequence_pkts++;
7925 ret = 2;
7926 break;
7927 }
7928
7929 if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,*tcp_len))
7930 ret = 1; /* Aggregate */
7931 else
7932 ret = 2; /* Flush both */
7933 break;
7934 }
7935 }
7936
7937 if (ret == 0) {
7938 /* Before searching for available LRO objects,
7939 * check if the pkt is L3/L4 aggregatable. If not
7940 * don't create new LRO session. Just send this
7941 * packet up.
7942 */
7943 if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len)) {
7944 return 5;
7945 }
7946
7947 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007948 struct lro *l_lro = &sp->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007949 if (!(l_lro->in_use)) {
7950 *lro = l_lro;
7951 ret = 3; /* Begin anew */
7952 break;
7953 }
7954 }
7955 }
7956
7957 if (ret == 0) { /* sessions exceeded */
7958 DBG_PRINT(INFO_DBG,"%s:All LRO sessions already in use\n",
7959 __FUNCTION__);
7960 *lro = NULL;
7961 return ret;
7962 }
7963
7964 switch (ret) {
7965 case 3:
7966 initiate_new_session(*lro, buffer, ip, tcph, *tcp_len);
7967 break;
7968 case 2:
7969 update_L3L4_header(sp, *lro);
7970 break;
7971 case 1:
7972 aggregate_new_rx(*lro, ip, tcph, *tcp_len);
7973 if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
7974 update_L3L4_header(sp, *lro);
7975 ret = 4; /* Flush the LRO */
7976 }
7977 break;
7978 default:
7979 DBG_PRINT(ERR_DBG,"%s:Dont know, can't say!!\n",
7980 __FUNCTION__);
7981 break;
7982 }
7983
7984 return ret;
7985}
7986
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007987static void clear_lro_session(struct lro *lro)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007988{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007989 static u16 lro_struct_size = sizeof(struct lro);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007990
7991 memset(lro, 0, lro_struct_size);
7992}
7993
7994static void queue_rx_frame(struct sk_buff *skb)
7995{
7996 struct net_device *dev = skb->dev;
7997
7998 skb->protocol = eth_type_trans(skb, dev);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007999 if (napi)
8000 netif_receive_skb(skb);
8001 else
8002 netif_rx(skb);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008003}
8004
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008005static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
8006 struct sk_buff *skb,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008007 u32 tcp_len)
8008{
Ananda Raju75c30b12006-07-24 19:55:09 -04008009 struct sk_buff *first = lro->parent;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008010
8011 first->len += tcp_len;
8012 first->data_len = lro->frags_len;
8013 skb_pull(skb, (skb->len - tcp_len));
Ananda Raju75c30b12006-07-24 19:55:09 -04008014 if (skb_shinfo(first)->frag_list)
8015 lro->last_frag->next = skb;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008016 else
8017 skb_shinfo(first)->frag_list = skb;
Sivakumar Subramani372cc592007-01-31 13:32:57 -05008018 first->truesize += skb->truesize;
Ananda Raju75c30b12006-07-24 19:55:09 -04008019 lro->last_frag = skb;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008020 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
8021 return;
8022}