blob: 3ddc0aae60b6947f919a1b007e5f31831b272265 [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
Veena Parat6d517a22007-07-23 02:20:51 -040035 * values are 1, 2.
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),
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -070040 * 2(MSI_X). Default value is '2(MSI_X)'
Stephen Hemminger43b7c452007-10-05 12:39:21 -070041 * lro_enable: Specifies whether to enable Large Receive Offload (LRO) or not.
Ananda Raju9dc737a2006-04-21 19:05:41 -040042 * 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.
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -050053 * multiq: This parameter used to enable/disable MULTIQUEUE support.
54 * Possible values '1' for enable and '0' for disable. Default is '0'
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 ************************************************************************/
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <linux/module.h>
58#include <linux/types.h>
59#include <linux/errno.h>
60#include <linux/ioport.h>
61#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040062#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <linux/kernel.h>
64#include <linux/netdevice.h>
65#include <linux/etherdevice.h>
66#include <linux/skbuff.h>
67#include <linux/init.h>
68#include <linux/delay.h>
69#include <linux/stddef.h>
70#include <linux/ioctl.h>
71#include <linux/timex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <linux/workqueue.h>
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -070074#include <linux/if_vlan.h>
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -050075#include <linux/ip.h>
76#include <linux/tcp.h>
77#include <net/tcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/system.h>
80#include <asm/uaccess.h>
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070081#include <asm/io.h>
Andrew Mortonfe931392006-02-03 01:45:12 -080082#include <asm/div64.h>
Andrew Morton330ce0d2006-08-14 23:00:14 -070083#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/* local include */
86#include "s2io.h"
87#include "s2io-regs.h"
88
Ramkrishna Vepab7c56782007-12-17 11:40:15 -080089#define DRV_VERSION "2.0.26.15-2"
John Linville6c1792f2005-10-04 07:51:45 -040090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/* S2io Driver name & version. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -070092static char s2io_driver_name[] = "Neterion";
John Linville6c1792f2005-10-04 07:51:45 -040093static char s2io_driver_version[] = DRV_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Veena Parat6d517a22007-07-23 02:20:51 -040095static int rxd_size[2] = {32,48};
96static int rxd_count[2] = {127,85};
Ananda Rajuda6971d2005-10-31 16:55:31 -050097
Ralf Baechle1ee6dd72007-01-31 14:09:29 -050098static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -070099{
100 int ret;
101
102 ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
103 (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
104
105 return ret;
106}
107
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700108/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * Cards with following subsystem_id have a link state indication
110 * problem, 600B, 600C, 600D, 640B, 640C and 640D.
111 * macro below identifies these cards given the subsystem_id.
112 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700113#define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
114 (dev_type == XFRAME_I_DEVICE) ? \
115 ((((subid >= 0x600B) && (subid <= 0x600D)) || \
116 ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118#define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
119 ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
120#define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
121#define PANIC 1
122#define LOW 2
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500123static inline int rx_buffer_level(struct s2io_nic * sp, int rxb_size, int ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500125 struct mac_info *mac_control;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700126
127 mac_control = &sp->mac_control;
Ananda Raju863c11a2006-04-21 19:03:13 -0400128 if (rxb_size <= rxd_count[sp->rxd_mode])
129 return PANIC;
130 else if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16)
131 return LOW;
132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Sivakumar Subramani92b84432007-09-06 06:51:14 -0400135static inline int is_s2io_card_up(const struct s2io_nic * sp)
136{
137 return test_bit(__S2IO_STATE_CARD_UP, &sp->state);
138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/* Ethtool related variables and Macros. */
141static char s2io_gstrings[][ETH_GSTRING_LEN] = {
142 "Register test\t(offline)",
143 "Eeprom test\t(offline)",
144 "Link test\t(online)",
145 "RLDRAM test\t(offline)",
146 "BIST Test\t(offline)"
147};
148
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500149static char ethtool_xena_stats_keys[][ETH_GSTRING_LEN] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 {"tmac_frms"},
151 {"tmac_data_octets"},
152 {"tmac_drop_frms"},
153 {"tmac_mcst_frms"},
154 {"tmac_bcst_frms"},
155 {"tmac_pause_ctrl_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400156 {"tmac_ttl_octets"},
157 {"tmac_ucst_frms"},
158 {"tmac_nucst_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 {"tmac_any_err_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400160 {"tmac_ttl_less_fb_octets"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 {"tmac_vld_ip_octets"},
162 {"tmac_vld_ip"},
163 {"tmac_drop_ip"},
164 {"tmac_icmp"},
165 {"tmac_rst_tcp"},
166 {"tmac_tcp"},
167 {"tmac_udp"},
168 {"rmac_vld_frms"},
169 {"rmac_data_octets"},
170 {"rmac_fcs_err_frms"},
171 {"rmac_drop_frms"},
172 {"rmac_vld_mcst_frms"},
173 {"rmac_vld_bcst_frms"},
174 {"rmac_in_rng_len_err_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400175 {"rmac_out_rng_len_err_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 {"rmac_long_frms"},
177 {"rmac_pause_ctrl_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400178 {"rmac_unsup_ctrl_frms"},
179 {"rmac_ttl_octets"},
180 {"rmac_accepted_ucst_frms"},
181 {"rmac_accepted_nucst_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 {"rmac_discarded_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400183 {"rmac_drop_events"},
184 {"rmac_ttl_less_fb_octets"},
185 {"rmac_ttl_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 {"rmac_usized_frms"},
187 {"rmac_osized_frms"},
188 {"rmac_frag_frms"},
189 {"rmac_jabber_frms"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400190 {"rmac_ttl_64_frms"},
191 {"rmac_ttl_65_127_frms"},
192 {"rmac_ttl_128_255_frms"},
193 {"rmac_ttl_256_511_frms"},
194 {"rmac_ttl_512_1023_frms"},
195 {"rmac_ttl_1024_1518_frms"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 {"rmac_ip"},
197 {"rmac_ip_octets"},
198 {"rmac_hdr_err_ip"},
199 {"rmac_drop_ip"},
200 {"rmac_icmp"},
201 {"rmac_tcp"},
202 {"rmac_udp"},
203 {"rmac_err_drp_udp"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400204 {"rmac_xgmii_err_sym"},
205 {"rmac_frms_q0"},
206 {"rmac_frms_q1"},
207 {"rmac_frms_q2"},
208 {"rmac_frms_q3"},
209 {"rmac_frms_q4"},
210 {"rmac_frms_q5"},
211 {"rmac_frms_q6"},
212 {"rmac_frms_q7"},
213 {"rmac_full_q0"},
214 {"rmac_full_q1"},
215 {"rmac_full_q2"},
216 {"rmac_full_q3"},
217 {"rmac_full_q4"},
218 {"rmac_full_q5"},
219 {"rmac_full_q6"},
220 {"rmac_full_q7"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 {"rmac_pause_cnt"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400222 {"rmac_xgmii_data_err_cnt"},
223 {"rmac_xgmii_ctrl_err_cnt"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {"rmac_accepted_ip"},
225 {"rmac_err_tcp"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400226 {"rd_req_cnt"},
227 {"new_rd_req_cnt"},
228 {"new_rd_req_rtry_cnt"},
229 {"rd_rtry_cnt"},
230 {"wr_rtry_rd_ack_cnt"},
231 {"wr_req_cnt"},
232 {"new_wr_req_cnt"},
233 {"new_wr_req_rtry_cnt"},
234 {"wr_rtry_cnt"},
235 {"wr_disc_cnt"},
236 {"rd_rtry_wr_ack_cnt"},
237 {"txp_wr_cnt"},
238 {"txd_rd_cnt"},
239 {"txd_wr_cnt"},
240 {"rxd_rd_cnt"},
241 {"rxd_wr_cnt"},
242 {"txf_rd_cnt"},
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500243 {"rxf_wr_cnt"}
244};
245
246static char ethtool_enhanced_stats_keys[][ETH_GSTRING_LEN] = {
Ananda Rajubd1034f2006-04-21 19:20:22 -0400247 {"rmac_ttl_1519_4095_frms"},
248 {"rmac_ttl_4096_8191_frms"},
249 {"rmac_ttl_8192_max_frms"},
250 {"rmac_ttl_gt_max_frms"},
251 {"rmac_osized_alt_frms"},
252 {"rmac_jabber_alt_frms"},
253 {"rmac_gt_max_alt_frms"},
254 {"rmac_vlan_frms"},
255 {"rmac_len_discard"},
256 {"rmac_fcs_discard"},
257 {"rmac_pf_discard"},
258 {"rmac_da_discard"},
259 {"rmac_red_discard"},
260 {"rmac_rts_discard"},
261 {"rmac_ingm_full_discard"},
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500262 {"link_fault_cnt"}
263};
264
265static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -0700266 {"\n DRIVER STATISTICS"},
267 {"single_bit_ecc_errs"},
268 {"double_bit_ecc_errs"},
Ananda Rajubd1034f2006-04-21 19:20:22 -0400269 {"parity_err_cnt"},
270 {"serious_err_cnt"},
271 {"soft_reset_cnt"},
272 {"fifo_full_cnt"},
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -0700273 {"ring_0_full_cnt"},
274 {"ring_1_full_cnt"},
275 {"ring_2_full_cnt"},
276 {"ring_3_full_cnt"},
277 {"ring_4_full_cnt"},
278 {"ring_5_full_cnt"},
279 {"ring_6_full_cnt"},
280 {"ring_7_full_cnt"},
Stephen Hemminger43b7c452007-10-05 12:39:21 -0700281 {"alarm_transceiver_temp_high"},
282 {"alarm_transceiver_temp_low"},
283 {"alarm_laser_bias_current_high"},
284 {"alarm_laser_bias_current_low"},
285 {"alarm_laser_output_power_high"},
286 {"alarm_laser_output_power_low"},
287 {"warn_transceiver_temp_high"},
288 {"warn_transceiver_temp_low"},
289 {"warn_laser_bias_current_high"},
290 {"warn_laser_bias_current_low"},
291 {"warn_laser_output_power_high"},
292 {"warn_laser_output_power_low"},
293 {"lro_aggregated_pkts"},
294 {"lro_flush_both_count"},
295 {"lro_out_of_sequence_pkts"},
296 {"lro_flush_due_to_max_pkts"},
297 {"lro_avg_aggr_pkts"},
298 {"mem_alloc_fail_cnt"},
299 {"pci_map_fail_cnt"},
300 {"watchdog_timer_cnt"},
301 {"mem_allocated"},
302 {"mem_freed"},
303 {"link_up_cnt"},
304 {"link_down_cnt"},
305 {"link_up_time"},
306 {"link_down_time"},
307 {"tx_tcode_buf_abort_cnt"},
308 {"tx_tcode_desc_abort_cnt"},
309 {"tx_tcode_parity_err_cnt"},
310 {"tx_tcode_link_loss_cnt"},
311 {"tx_tcode_list_proc_err_cnt"},
312 {"rx_tcode_parity_err_cnt"},
313 {"rx_tcode_abort_cnt"},
314 {"rx_tcode_parity_abort_cnt"},
315 {"rx_tcode_rda_fail_cnt"},
316 {"rx_tcode_unkn_prot_cnt"},
317 {"rx_tcode_fcs_err_cnt"},
318 {"rx_tcode_buf_size_err_cnt"},
319 {"rx_tcode_rxd_corrupt_cnt"},
320 {"rx_tcode_unkn_err_cnt"},
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -0700321 {"tda_err_cnt"},
322 {"pfc_err_cnt"},
323 {"pcc_err_cnt"},
324 {"tti_err_cnt"},
325 {"tpa_err_cnt"},
326 {"sm_err_cnt"},
327 {"lso_err_cnt"},
328 {"mac_tmac_err_cnt"},
329 {"mac_rmac_err_cnt"},
330 {"xgxs_txgxs_err_cnt"},
331 {"xgxs_rxgxs_err_cnt"},
332 {"rc_err_cnt"},
333 {"prc_pcix_err_cnt"},
334 {"rpa_err_cnt"},
335 {"rda_err_cnt"},
336 {"rti_err_cnt"},
337 {"mc_err_cnt"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};
339
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200340#define S2IO_XENA_STAT_LEN ARRAY_SIZE(ethtool_xena_stats_keys)
341#define S2IO_ENHANCED_STAT_LEN ARRAY_SIZE(ethtool_enhanced_stats_keys)
342#define S2IO_DRIVER_STAT_LEN ARRAY_SIZE(ethtool_driver_stats_keys)
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -0500343
344#define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN )
345#define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN )
346
347#define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN )
348#define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200350#define S2IO_TEST_LEN ARRAY_SIZE(s2io_gstrings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
352
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -0700353#define S2IO_TIMER_CONF(timer, handle, arg, exp) \
354 init_timer(&timer); \
355 timer.function = handle; \
356 timer.data = (unsigned long) arg; \
357 mod_timer(&timer, (jiffies + exp)) \
358
Sivakumar Subramani2fd37682007-09-14 07:39:19 -0400359/* copy mac addr to def_mac_addr array */
360static void do_s2io_copy_mac_addr(struct s2io_nic *sp, int offset, u64 mac_addr)
361{
362 sp->def_mac_addr[offset].mac_addr[5] = (u8) (mac_addr);
363 sp->def_mac_addr[offset].mac_addr[4] = (u8) (mac_addr >> 8);
364 sp->def_mac_addr[offset].mac_addr[3] = (u8) (mac_addr >> 16);
365 sp->def_mac_addr[offset].mac_addr[2] = (u8) (mac_addr >> 24);
366 sp->def_mac_addr[offset].mac_addr[1] = (u8) (mac_addr >> 32);
367 sp->def_mac_addr[offset].mac_addr[0] = (u8) (mac_addr >> 40);
368}
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700369/* Add the vlan */
370static void s2io_vlan_rx_register(struct net_device *dev,
371 struct vlan_group *grp)
372{
Surjit Reang2fda0962008-01-24 02:08:59 -0800373 int i;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500374 struct s2io_nic *nic = dev->priv;
Surjit Reang2fda0962008-01-24 02:08:59 -0800375 unsigned long flags[MAX_TX_FIFOS];
376 struct mac_info *mac_control = &nic->mac_control;
377 struct config_param *config = &nic->config;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700378
Surjit Reang2fda0962008-01-24 02:08:59 -0800379 for (i = 0; i < config->tx_fifo_num; i++)
380 spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags[i]);
381
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700382 nic->vlgrp = grp;
Surjit Reang2fda0962008-01-24 02:08:59 -0800383 for (i = config->tx_fifo_num - 1; i >= 0; i--)
384 spin_unlock_irqrestore(&mac_control->fifos[i].tx_lock,
385 flags[i]);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -0700386}
387
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500388/* A flag indicating whether 'RX_PA_CFG_STRIP_VLAN_TAG' bit is set or not */
Adrian Bunk7b490342007-03-05 02:49:25 +0100389static int vlan_strip_flag;
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500390
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700391/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 * Constants to be programmed into the Xena's registers, to configure
393 * the XAUI.
394 */
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define END_SIGN 0x0
Arjan van de Venf71e1302006-03-03 21:33:57 -0500397static const u64 herc_act_dtx_cfg[] = {
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700398 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700399 0x8000051536750000ULL, 0x80000515367500E0ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700400 /* Write data */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700401 0x8000051536750004ULL, 0x80000515367500E4ULL,
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700402 /* Set address */
403 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
404 /* Write data */
405 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
406 /* Set address */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -0700407 0x801205150D440000ULL, 0x801205150D4400E0ULL,
408 /* Write data */
409 0x801205150D440004ULL, 0x801205150D4400E4ULL,
410 /* Set address */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -0700411 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
412 /* Write data */
413 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
414 /* Done */
415 END_SIGN
416};
417
Arjan van de Venf71e1302006-03-03 21:33:57 -0500418static const u64 xena_dtx_cfg[] = {
Ananda Rajuc92ca042006-04-21 19:18:03 -0400419 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 0x8000051500000000ULL, 0x80000515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400421 /* Write data */
422 0x80000515D9350004ULL, 0x80000515D93500E4ULL,
423 /* Set address */
424 0x8001051500000000ULL, 0x80010515000000E0ULL,
425 /* Write data */
426 0x80010515001E0004ULL, 0x80010515001E00E4ULL,
427 /* Set address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 0x8002051500000000ULL, 0x80020515000000E0ULL,
Ananda Rajuc92ca042006-04-21 19:18:03 -0400429 /* Write data */
430 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 END_SIGN
432};
433
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700434/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * Constants for Fixing the MacAddress problem seen mostly on
436 * Alpha machines.
437 */
Arjan van de Venf71e1302006-03-03 21:33:57 -0500438static const u64 fix_mac[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 0x0060000000000000ULL, 0x0060600000000000ULL,
440 0x0040600000000000ULL, 0x0000600000000000ULL,
441 0x0020600000000000ULL, 0x0060600000000000ULL,
442 0x0020600000000000ULL, 0x0060600000000000ULL,
443 0x0020600000000000ULL, 0x0060600000000000ULL,
444 0x0020600000000000ULL, 0x0060600000000000ULL,
445 0x0020600000000000ULL, 0x0060600000000000ULL,
446 0x0020600000000000ULL, 0x0060600000000000ULL,
447 0x0020600000000000ULL, 0x0060600000000000ULL,
448 0x0020600000000000ULL, 0x0060600000000000ULL,
449 0x0020600000000000ULL, 0x0060600000000000ULL,
450 0x0020600000000000ULL, 0x0060600000000000ULL,
451 0x0020600000000000ULL, 0x0000600000000000ULL,
452 0x0040600000000000ULL, 0x0060600000000000ULL,
453 END_SIGN
454};
455
Ananda Rajub41477f2006-07-24 19:52:49 -0400456MODULE_LICENSE("GPL");
457MODULE_VERSION(DRV_VERSION);
458
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460/* Module Loadable parameters. */
Ananda Rajub41477f2006-07-24 19:52:49 -0400461S2IO_PARM_INT(tx_fifo_num, 1);
462S2IO_PARM_INT(rx_ring_num, 1);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -0500463S2IO_PARM_INT(multiq, 0);
Ananda Rajub41477f2006-07-24 19:52:49 -0400464S2IO_PARM_INT(rx_ring_mode, 1);
465S2IO_PARM_INT(use_continuous_tx_intrs, 1);
466S2IO_PARM_INT(rmac_pause_time, 0x100);
467S2IO_PARM_INT(mc_pause_threshold_q0q3, 187);
468S2IO_PARM_INT(mc_pause_threshold_q4q7, 187);
469S2IO_PARM_INT(shared_splits, 0);
470S2IO_PARM_INT(tmac_util_period, 5);
471S2IO_PARM_INT(rmac_util_period, 5);
Ananda Rajub41477f2006-07-24 19:52:49 -0400472S2IO_PARM_INT(l3l4hdr_size, 128);
473/* Frequency of Rx desc syncs expressed as power of 2 */
474S2IO_PARM_INT(rxsync_frequency, 3);
Veena Parateccb8622007-07-23 02:23:54 -0400475/* Interrupt type. Values can be 0(INTA), 2(MSI_X) */
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -0700476S2IO_PARM_INT(intr_type, 2);
Ananda Rajub41477f2006-07-24 19:52:49 -0400477/* Large receive offload feature */
Stephen Hemminger43b7c452007-10-05 12:39:21 -0700478static unsigned int lro_enable;
479module_param_named(lro, lro_enable, uint, 0);
480
Ananda Rajub41477f2006-07-24 19:52:49 -0400481/* Max pkts to be aggregated by LRO at one time. If not specified,
482 * aggregation happens until we hit max IP pkt size(64K)
483 */
484S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
Ananda Rajub41477f2006-07-24 19:52:49 -0400485S2IO_PARM_INT(indicate_max_pkts, 0);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -0500486
487S2IO_PARM_INT(napi, 1);
488S2IO_PARM_INT(ufo, 0);
Sivakumar Subramani926930b2007-02-24 01:59:39 -0500489S2IO_PARM_INT(vlan_tag_strip, NO_STRIP_IN_PROMISC);
Ananda Rajub41477f2006-07-24 19:52:49 -0400490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400492 {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493static unsigned int rx_ring_sz[MAX_RX_RINGS] =
Ananda Raju9dc737a2006-04-21 19:05:41 -0400494 {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700495static unsigned int rts_frm_len[MAX_RX_RINGS] =
496 {[0 ...(MAX_RX_RINGS - 1)] = 0 };
Ananda Rajub41477f2006-07-24 19:52:49 -0400497
498module_param_array(tx_fifo_len, uint, NULL, 0);
499module_param_array(rx_ring_sz, uint, NULL, 0);
500module_param_array(rts_frm_len, uint, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700502/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 * S2IO device table.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700504 * This table lists all the devices that this driver supports.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 */
506static struct pci_device_id s2io_tbl[] __devinitdata = {
507 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
508 PCI_ANY_ID, PCI_ANY_ID},
509 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
510 PCI_ANY_ID, PCI_ANY_ID},
511 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700512 PCI_ANY_ID, PCI_ANY_ID},
513 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
514 PCI_ANY_ID, PCI_ANY_ID},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 {0,}
516};
517
518MODULE_DEVICE_TABLE(pci, s2io_tbl);
519
Linas Vepstasd796fdb2007-05-14 18:37:30 -0500520static struct pci_error_handlers s2io_err_handler = {
521 .error_detected = s2io_io_error_detected,
522 .slot_reset = s2io_io_slot_reset,
523 .resume = s2io_io_resume,
524};
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526static struct pci_driver s2io_driver = {
527 .name = "S2IO",
528 .id_table = s2io_tbl,
529 .probe = s2io_init_nic,
530 .remove = __devexit_p(s2io_rem_nic),
Linas Vepstasd796fdb2007-05-14 18:37:30 -0500531 .err_handler = &s2io_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532};
533
534/* A simplifier macro used both by init and free shared_mem Fns(). */
535#define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
536
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -0500537/* netqueue manipulation helper functions */
538static inline void s2io_stop_all_tx_queue(struct s2io_nic *sp)
539{
540 int i;
541#ifdef CONFIG_NETDEVICES_MULTIQUEUE
542 if (sp->config.multiq) {
543 for (i = 0; i < sp->config.tx_fifo_num; i++)
544 netif_stop_subqueue(sp->dev, i);
545 } else
546#endif
547 {
548 for (i = 0; i < sp->config.tx_fifo_num; i++)
549 sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_STOP;
550 netif_stop_queue(sp->dev);
551 }
552}
553
554static inline void s2io_stop_tx_queue(struct s2io_nic *sp, int fifo_no)
555{
556#ifdef CONFIG_NETDEVICES_MULTIQUEUE
557 if (sp->config.multiq)
558 netif_stop_subqueue(sp->dev, fifo_no);
559 else
560#endif
561 {
562 sp->mac_control.fifos[fifo_no].queue_state =
563 FIFO_QUEUE_STOP;
564 netif_stop_queue(sp->dev);
565 }
566}
567
568static inline void s2io_start_all_tx_queue(struct s2io_nic *sp)
569{
570 int i;
571#ifdef CONFIG_NETDEVICES_MULTIQUEUE
572 if (sp->config.multiq) {
573 for (i = 0; i < sp->config.tx_fifo_num; i++)
574 netif_start_subqueue(sp->dev, i);
575 } else
576#endif
577 {
578 for (i = 0; i < sp->config.tx_fifo_num; i++)
579 sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
580 netif_start_queue(sp->dev);
581 }
582}
583
584static inline void s2io_start_tx_queue(struct s2io_nic *sp, int fifo_no)
585{
586#ifdef CONFIG_NETDEVICES_MULTIQUEUE
587 if (sp->config.multiq)
588 netif_start_subqueue(sp->dev, fifo_no);
589 else
590#endif
591 {
592 sp->mac_control.fifos[fifo_no].queue_state =
593 FIFO_QUEUE_START;
594 netif_start_queue(sp->dev);
595 }
596}
597
598static inline void s2io_wake_all_tx_queue(struct s2io_nic *sp)
599{
600 int i;
601#ifdef CONFIG_NETDEVICES_MULTIQUEUE
602 if (sp->config.multiq) {
603 for (i = 0; i < sp->config.tx_fifo_num; i++)
604 netif_wake_subqueue(sp->dev, i);
605 } else
606#endif
607 {
608 for (i = 0; i < sp->config.tx_fifo_num; i++)
609 sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
610 netif_wake_queue(sp->dev);
611 }
612}
613
614static inline void s2io_wake_tx_queue(
615 struct fifo_info *fifo, int cnt, u8 multiq)
616{
617
618#ifdef CONFIG_NETDEVICES_MULTIQUEUE
619 if (multiq) {
620 if (cnt && __netif_subqueue_stopped(fifo->dev, fifo->fifo_no))
621 netif_wake_subqueue(fifo->dev, fifo->fifo_no);
622 } else
623#endif
624 if (cnt && (fifo->queue_state == FIFO_QUEUE_STOP)) {
625 if (netif_queue_stopped(fifo->dev)) {
626 fifo->queue_state = FIFO_QUEUE_START;
627 netif_wake_queue(fifo->dev);
628 }
629 }
630}
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632/**
633 * init_shared_mem - Allocation and Initialization of Memory
634 * @nic: Device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700635 * Description: The function allocates all the memory areas shared
636 * between the NIC and the driver. This includes Tx descriptors,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 * Rx descriptors and the statistics block.
638 */
639
640static int init_shared_mem(struct s2io_nic *nic)
641{
642 u32 size;
643 void *tmp_v_addr, *tmp_v_addr_next;
644 dma_addr_t tmp_p_addr, tmp_p_addr_next;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500645 struct RxD_block *pre_rxd_blk = NULL;
Sivakumar Subramani372cc592007-01-31 13:32:57 -0500646 int i, j, blk_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 int lst_size, lst_per_page;
648 struct net_device *dev = nic->dev;
viro@zenIV.linux.org.uk8ae418c2005-09-02 20:15:29 +0100649 unsigned long tmp;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500650 struct buffAdd *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500652 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 struct config_param *config;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400654 unsigned long long mem_allocated = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 mac_control = &nic->mac_control;
657 config = &nic->config;
658
659
660 /* Allocation and initialization of TXDLs in FIOFs */
661 size = 0;
662 for (i = 0; i < config->tx_fifo_num; i++) {
663 size += config->tx_cfg[i].fifo_len;
664 }
665 if (size > MAX_AVAILABLE_TXDS) {
Ananda Rajub41477f2006-07-24 19:52:49 -0400666 DBG_PRINT(ERR_DBG, "s2io: Requested TxDs too high, ");
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -0700667 DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
Ananda Rajub41477f2006-07-24 19:52:49 -0400668 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
670
Surjit Reang2fda0962008-01-24 02:08:59 -0800671 size = 0;
672 for (i = 0; i < config->tx_fifo_num; i++) {
673 size = config->tx_cfg[i].fifo_len;
674 /*
675 * Legal values are from 2 to 8192
676 */
677 if (size < 2) {
678 DBG_PRINT(ERR_DBG, "s2io: Invalid fifo len (%d)", size);
679 DBG_PRINT(ERR_DBG, "for fifo %d\n", i);
680 DBG_PRINT(ERR_DBG, "s2io: Legal values for fifo len"
681 "are 2 to 8192\n");
682 return -EINVAL;
683 }
684 }
685
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500686 lst_size = (sizeof(struct TxD) * config->max_txds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 lst_per_page = PAGE_SIZE / lst_size;
688
689 for (i = 0; i < config->tx_fifo_num; i++) {
690 int fifo_len = config->tx_cfg[i].fifo_len;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500691 int list_holder_size = fifo_len * sizeof(struct list_info_hold);
Sivakumar Subramanibd684e42007-09-14 07:28:50 -0400692 mac_control->fifos[i].list_info = kzalloc(list_holder_size,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700693 GFP_KERNEL);
694 if (!mac_control->fifos[i].list_info) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800695 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 "Malloc failed for list_info\n");
697 return -ENOMEM;
698 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400699 mem_allocated += list_holder_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 for (i = 0; i < config->tx_fifo_num; i++) {
702 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
703 lst_per_page);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700704 mac_control->fifos[i].tx_curr_put_info.offset = 0;
705 mac_control->fifos[i].tx_curr_put_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700707 mac_control->fifos[i].tx_curr_get_info.offset = 0;
708 mac_control->fifos[i].tx_curr_get_info.fifo_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 config->tx_cfg[i].fifo_len - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700710 mac_control->fifos[i].fifo_no = i;
711 mac_control->fifos[i].nic = nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500712 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 2;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -0500713 mac_control->fifos[i].dev = dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 for (j = 0; j < page_num; j++) {
716 int k = 0;
717 dma_addr_t tmp_p;
718 void *tmp_v;
719 tmp_v = pci_alloc_consistent(nic->pdev,
720 PAGE_SIZE, &tmp_p);
721 if (!tmp_v) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800722 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 "pci_alloc_consistent ");
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800724 DBG_PRINT(INFO_DBG, "failed for TxDL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 return -ENOMEM;
726 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700727 /* If we got a zero DMA address(can happen on
728 * certain platforms like PPC), reallocate.
729 * Store virtual address of page we don't want,
730 * to be freed later.
731 */
732 if (!tmp_p) {
733 mac_control->zerodma_virt_addr = tmp_v;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400734 DBG_PRINT(INIT_DBG,
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700735 "%s: Zero DMA address for TxDL. ", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400736 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -0700737 "Virtual address %p\n", tmp_v);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700738 tmp_v = pci_alloc_consistent(nic->pdev,
739 PAGE_SIZE, &tmp_p);
740 if (!tmp_v) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800741 DBG_PRINT(INFO_DBG,
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700742 "pci_alloc_consistent ");
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -0800743 DBG_PRINT(INFO_DBG, "failed for TxDL\n");
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700744 return -ENOMEM;
745 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400746 mem_allocated += PAGE_SIZE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 while (k < lst_per_page) {
749 int l = (j * lst_per_page) + k;
750 if (l == config->tx_cfg[i].fifo_len)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700751 break;
752 mac_control->fifos[i].list_info[l].list_virt_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 tmp_v + (k * lst_size);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700754 mac_control->fifos[i].list_info[l].list_phy_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 tmp_p + (k * lst_size);
756 k++;
757 }
758 }
759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Surjit Reang2fda0962008-01-24 02:08:59 -0800761 for (i = 0; i < config->tx_fifo_num; i++) {
762 size = config->tx_cfg[i].fifo_len;
763 mac_control->fifos[i].ufo_in_band_v
764 = kcalloc(size, sizeof(u64), GFP_KERNEL);
765 if (!mac_control->fifos[i].ufo_in_band_v)
766 return -ENOMEM;
767 mem_allocated += (size * sizeof(u64));
768 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -0500769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 /* Allocation and initialization of RXDs in Rings */
771 size = 0;
772 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500773 if (config->rx_cfg[i].num_rxd %
774 (rxd_count[nic->rxd_mode] + 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
776 DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
777 i);
778 DBG_PRINT(ERR_DBG, "RxDs per Block");
779 return FAILURE;
780 }
781 size += config->rx_cfg[i].num_rxd;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700782 mac_control->rings[i].block_count =
Ananda Rajuda6971d2005-10-31 16:55:31 -0500783 config->rx_cfg[i].num_rxd /
784 (rxd_count[nic->rxd_mode] + 1 );
785 mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
786 mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
Ananda Rajuda6971d2005-10-31 16:55:31 -0500788 if (nic->rxd_mode == RXD_MODE_1)
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500789 size = (size * (sizeof(struct RxD1)));
Ananda Rajuda6971d2005-10-31 16:55:31 -0500790 else
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500791 size = (size * (sizeof(struct RxD3)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700794 mac_control->rings[i].rx_curr_get_info.block_index = 0;
795 mac_control->rings[i].rx_curr_get_info.offset = 0;
796 mac_control->rings[i].rx_curr_get_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700798 mac_control->rings[i].rx_curr_put_info.block_index = 0;
799 mac_control->rings[i].rx_curr_put_info.offset = 0;
800 mac_control->rings[i].rx_curr_put_info.ring_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 config->rx_cfg[i].num_rxd - 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700802 mac_control->rings[i].nic = nic;
803 mac_control->rings[i].ring_no = i;
804
Ananda Rajuda6971d2005-10-31 16:55:31 -0500805 blk_cnt = config->rx_cfg[i].num_rxd /
806 (rxd_count[nic->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 /* Allocating all the Rx blocks */
808 for (j = 0; j < blk_cnt; j++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500809 struct rx_block_info *rx_blocks;
Ananda Rajuda6971d2005-10-31 16:55:31 -0500810 int l;
811
812 rx_blocks = &mac_control->rings[i].rx_blocks[j];
813 size = SIZE_OF_BLOCK; //size is always page size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
815 &tmp_p_addr);
816 if (tmp_v_addr == NULL) {
817 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700818 * In case of failure, free_shared_mem()
819 * is called, which should free any
820 * memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 * failure happened.
822 */
Ananda Rajuda6971d2005-10-31 16:55:31 -0500823 rx_blocks->block_virt_addr = tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return -ENOMEM;
825 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400826 mem_allocated += size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 memset(tmp_v_addr, 0, size);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500828 rx_blocks->block_virt_addr = tmp_v_addr;
829 rx_blocks->block_dma_addr = tmp_p_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500830 rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)*
Ananda Rajuda6971d2005-10-31 16:55:31 -0500831 rxd_count[nic->rxd_mode],
832 GFP_KERNEL);
Sivakumar Subramani372cc592007-01-31 13:32:57 -0500833 if (!rx_blocks->rxds)
834 return -ENOMEM;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -0400835 mem_allocated +=
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400836 (sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500837 for (l=0; l<rxd_count[nic->rxd_mode];l++) {
838 rx_blocks->rxds[l].virt_addr =
839 rx_blocks->block_virt_addr +
840 (rxd_size[nic->rxd_mode] * l);
841 rx_blocks->rxds[l].dma_addr =
842 rx_blocks->block_dma_addr +
843 (rxd_size[nic->rxd_mode] * l);
844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846 /* Interlinking all Rx Blocks */
847 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700848 tmp_v_addr =
849 mac_control->rings[i].rx_blocks[j].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 tmp_v_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700851 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 blk_cnt].block_virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700853 tmp_p_addr =
854 mac_control->rings[i].rx_blocks[j].block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 tmp_p_addr_next =
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700856 mac_control->rings[i].rx_blocks[(j + 1) %
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 blk_cnt].block_dma_addr;
858
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500859 pre_rxd_blk = (struct RxD_block *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 pre_rxd_blk->reserved_2_pNext_RxD_block =
861 (unsigned long) tmp_v_addr_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 pre_rxd_blk->pNext_RxD_Blk_physical =
863 (u64) tmp_p_addr_next;
864 }
865 }
Veena Parat6d517a22007-07-23 02:20:51 -0400866 if (nic->rxd_mode == RXD_MODE_3B) {
Ananda Rajuda6971d2005-10-31 16:55:31 -0500867 /*
868 * Allocation of Storages for buffer addresses in 2BUFF mode
869 * and the buffers as well.
870 */
871 for (i = 0; i < config->rx_ring_num; i++) {
872 blk_cnt = config->rx_cfg[i].num_rxd /
873 (rxd_count[nic->rxd_mode]+ 1);
874 mac_control->rings[i].ba =
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500875 kmalloc((sizeof(struct buffAdd *) * blk_cnt),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 GFP_KERNEL);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500877 if (!mac_control->rings[i].ba)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400879 mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500880 for (j = 0; j < blk_cnt; j++) {
881 int k = 0;
882 mac_control->rings[i].ba[j] =
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500883 kmalloc((sizeof(struct buffAdd) *
Ananda Rajuda6971d2005-10-31 16:55:31 -0500884 (rxd_count[nic->rxd_mode] + 1)),
885 GFP_KERNEL);
886 if (!mac_control->rings[i].ba[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return -ENOMEM;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400888 mem_allocated += (sizeof(struct buffAdd) * \
889 (rxd_count[nic->rxd_mode] + 1));
Ananda Rajuda6971d2005-10-31 16:55:31 -0500890 while (k != rxd_count[nic->rxd_mode]) {
891 ba = &mac_control->rings[i].ba[j][k];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Ananda Rajuda6971d2005-10-31 16:55:31 -0500893 ba->ba_0_org = (void *) kmalloc
894 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
895 if (!ba->ba_0_org)
896 return -ENOMEM;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -0400897 mem_allocated +=
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400898 (BUF0_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500899 tmp = (unsigned long)ba->ba_0_org;
900 tmp += ALIGN_SIZE;
901 tmp &= ~((unsigned long) ALIGN_SIZE);
902 ba->ba_0 = (void *) tmp;
903
904 ba->ba_1_org = (void *) kmalloc
905 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
906 if (!ba->ba_1_org)
907 return -ENOMEM;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -0400908 mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400909 += (BUF1_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -0500910 tmp = (unsigned long) ba->ba_1_org;
911 tmp += ALIGN_SIZE;
912 tmp &= ~((unsigned long) ALIGN_SIZE);
913 ba->ba_1 = (void *) tmp;
914 k++;
915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917 }
918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920 /* Allocation and initialization of Statistics block */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500921 size = sizeof(struct stat_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 mac_control->stats_mem = pci_alloc_consistent
923 (nic->pdev, size, &mac_control->stats_mem_phy);
924
925 if (!mac_control->stats_mem) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700926 /*
927 * In case of failure, free_shared_mem() is called, which
928 * should free any memory that was alloced till the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 * failure happened.
930 */
931 return -ENOMEM;
932 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400933 mem_allocated += size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 mac_control->stats_mem_sz = size;
935
936 tmp_v_addr = mac_control->stats_mem;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500937 mac_control->stats_info = (struct stat_block *) tmp_v_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 memset(tmp_v_addr, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
940 (unsigned long long) tmp_p_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400941 mac_control->stats_info->sw_stat.mem_allocated += mem_allocated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return SUCCESS;
943}
944
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700945/**
946 * free_shared_mem - Free the allocated Memory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 * @nic: Device private variable.
948 * Description: This function is to free all memory locations allocated by
949 * the init_shared_mem() function and return it to the kernel.
950 */
951
952static void free_shared_mem(struct s2io_nic *nic)
953{
954 int i, j, blk_cnt, size;
955 void *tmp_v_addr;
956 dma_addr_t tmp_p_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500957 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 struct config_param *config;
959 int lst_size, lst_per_page;
Micah Gruber8910b492007-07-09 11:29:04 +0800960 struct net_device *dev;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400961 int page_num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 if (!nic)
964 return;
965
Micah Gruber8910b492007-07-09 11:29:04 +0800966 dev = nic->dev;
967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 mac_control = &nic->mac_control;
969 config = &nic->config;
970
Ralf Baechle1ee6dd72007-01-31 14:09:29 -0500971 lst_size = (sizeof(struct TxD) * config->max_txds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 lst_per_page = PAGE_SIZE / lst_size;
973
974 for (i = 0; i < config->tx_fifo_num; i++) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400975 page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
976 lst_per_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 for (j = 0; j < page_num; j++) {
978 int mem_blks = (j * lst_per_page);
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700979 if (!mac_control->fifos[i].list_info)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400980 return;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700981 if (!mac_control->fifos[i].list_info[mem_blks].
982 list_virt_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 break;
984 pci_free_consistent(nic->pdev, PAGE_SIZE,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700985 mac_control->fifos[i].
986 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 list_virt_addr,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -0700988 mac_control->fifos[i].
989 list_info[mem_blks].
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 list_phy_addr);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -0400991 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -0400992 += PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -0700994 /* If we got a zero DMA address during allocation,
995 * free the page now
996 */
997 if (mac_control->zerodma_virt_addr) {
998 pci_free_consistent(nic->pdev, PAGE_SIZE,
999 mac_control->zerodma_virt_addr,
1000 (dma_addr_t)0);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001001 DBG_PRINT(INIT_DBG,
Andrew Morton6b4d6172005-09-12 23:21:55 -07001002 "%s: Freeing TxDL with zero DMA addr. ",
1003 dev->name);
1004 DBG_PRINT(INIT_DBG, "Virtual address %p\n",
1005 mac_control->zerodma_virt_addr);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001006 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001007 += PAGE_SIZE;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07001008 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001009 kfree(mac_control->fifos[i].list_info);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001010 nic->mac_control.stats_info->sw_stat.mem_freed +=
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001011 (nic->config.tx_cfg[i].fifo_len *sizeof(struct list_info_hold));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 size = SIZE_OF_BLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001016 blk_cnt = mac_control->rings[i].block_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 for (j = 0; j < blk_cnt; j++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001018 tmp_v_addr = mac_control->rings[i].rx_blocks[j].
1019 block_virt_addr;
1020 tmp_p_addr = mac_control->rings[i].rx_blocks[j].
1021 block_dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (tmp_v_addr == NULL)
1023 break;
1024 pci_free_consistent(nic->pdev, size,
1025 tmp_v_addr, tmp_p_addr);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001026 nic->mac_control.stats_info->sw_stat.mem_freed += size;
Ananda Rajuda6971d2005-10-31 16:55:31 -05001027 kfree(mac_control->rings[i].rx_blocks[j].rxds);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001028 nic->mac_control.stats_info->sw_stat.mem_freed +=
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001029 ( sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 }
1032
Veena Parat6d517a22007-07-23 02:20:51 -04001033 if (nic->rxd_mode == RXD_MODE_3B) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05001034 /* Freeing buffer storage addresses in 2BUFF mode. */
1035 for (i = 0; i < config->rx_ring_num; i++) {
1036 blk_cnt = config->rx_cfg[i].num_rxd /
1037 (rxd_count[nic->rxd_mode] + 1);
1038 for (j = 0; j < blk_cnt; j++) {
1039 int k = 0;
1040 if (!mac_control->rings[i].ba[j])
1041 continue;
1042 while (k != rxd_count[nic->rxd_mode]) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001043 struct buffAdd *ba =
Ananda Rajuda6971d2005-10-31 16:55:31 -05001044 &mac_control->rings[i].ba[j][k];
1045 kfree(ba->ba_0_org);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001046 nic->mac_control.stats_info->sw_stat.\
1047 mem_freed += (BUF0_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05001048 kfree(ba->ba_1_org);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001049 nic->mac_control.stats_info->sw_stat.\
1050 mem_freed += (BUF1_LEN + ALIGN_SIZE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05001051 k++;
1052 }
1053 kfree(mac_control->rings[i].ba[j]);
Sivakumar Subramani9caab452007-09-06 06:21:54 -04001054 nic->mac_control.stats_info->sw_stat.mem_freed +=
1055 (sizeof(struct buffAdd) *
1056 (rxd_count[nic->rxd_mode] + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05001058 kfree(mac_control->rings[i].ba);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001059 nic->mac_control.stats_info->sw_stat.mem_freed +=
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001060 (sizeof(struct buffAdd *) * blk_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Surjit Reang2fda0962008-01-24 02:08:59 -08001064 for (i = 0; i < nic->config.tx_fifo_num; i++) {
1065 if (mac_control->fifos[i].ufo_in_band_v) {
1066 nic->mac_control.stats_info->sw_stat.mem_freed
1067 += (config->tx_cfg[i].fifo_len * sizeof(u64));
1068 kfree(mac_control->fifos[i].ufo_in_band_v);
1069 }
1070 }
1071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (mac_control->stats_mem) {
Surjit Reang2fda0962008-01-24 02:08:59 -08001073 nic->mac_control.stats_info->sw_stat.mem_freed +=
1074 mac_control->stats_mem_sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 pci_free_consistent(nic->pdev,
1076 mac_control->stats_mem_sz,
1077 mac_control->stats_mem,
1078 mac_control->stats_mem_phy);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04001079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001082/**
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001083 * s2io_verify_pci_mode -
1084 */
1085
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001086static int s2io_verify_pci_mode(struct s2io_nic *nic)
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001087{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001088 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001089 register u64 val64 = 0;
1090 int mode;
1091
1092 val64 = readq(&bar0->pci_mode);
1093 mode = (u8)GET_PCI_MODE(val64);
1094
1095 if ( val64 & PCI_MODE_UNKNOWN_MODE)
1096 return -1; /* Unknown PCI mode */
1097 return mode;
1098}
1099
Ananda Rajuc92ca042006-04-21 19:18:03 -04001100#define NEC_VENID 0x1033
1101#define NEC_DEVID 0x0125
1102static int s2io_on_nec_bridge(struct pci_dev *s2io_pdev)
1103{
1104 struct pci_dev *tdev = NULL;
Alan Cox26d36b62006-09-15 15:22:51 +01001105 while ((tdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tdev)) != NULL) {
1106 if (tdev->vendor == NEC_VENID && tdev->device == NEC_DEVID) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04001107 if (tdev->bus == s2io_pdev->bus->parent)
Alan Cox26d36b62006-09-15 15:22:51 +01001108 pci_dev_put(tdev);
Ananda Rajuc92ca042006-04-21 19:18:03 -04001109 return 1;
1110 }
1111 }
1112 return 0;
1113}
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001114
Adrian Bunk7b32a312006-05-16 17:30:50 +02001115static int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001116/**
1117 * s2io_print_pci_mode -
1118 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001119static int s2io_print_pci_mode(struct s2io_nic *nic)
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001120{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001121 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001122 register u64 val64 = 0;
1123 int mode;
1124 struct config_param *config = &nic->config;
1125
1126 val64 = readq(&bar0->pci_mode);
1127 mode = (u8)GET_PCI_MODE(val64);
1128
1129 if ( val64 & PCI_MODE_UNKNOWN_MODE)
1130 return -1; /* Unknown PCI mode */
1131
Ananda Rajuc92ca042006-04-21 19:18:03 -04001132 config->bus_speed = bus_speed[mode];
1133
1134 if (s2io_on_nec_bridge(nic->pdev)) {
1135 DBG_PRINT(ERR_DBG, "%s: Device is on PCI-E bus\n",
1136 nic->dev->name);
1137 return mode;
1138 }
1139
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001140 if (val64 & PCI_MODE_32_BITS) {
1141 DBG_PRINT(ERR_DBG, "%s: Device is on 32 bit ", nic->dev->name);
1142 } else {
1143 DBG_PRINT(ERR_DBG, "%s: Device is on 64 bit ", nic->dev->name);
1144 }
1145
1146 switch(mode) {
1147 case PCI_MODE_PCI_33:
1148 DBG_PRINT(ERR_DBG, "33MHz PCI bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001149 break;
1150 case PCI_MODE_PCI_66:
1151 DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001152 break;
1153 case PCI_MODE_PCIX_M1_66:
1154 DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001155 break;
1156 case PCI_MODE_PCIX_M1_100:
1157 DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001158 break;
1159 case PCI_MODE_PCIX_M1_133:
1160 DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001161 break;
1162 case PCI_MODE_PCIX_M2_66:
1163 DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001164 break;
1165 case PCI_MODE_PCIX_M2_100:
1166 DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001167 break;
1168 case PCI_MODE_PCIX_M2_133:
1169 DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001170 break;
1171 default:
1172 return -1; /* Unsupported bus speed */
1173 }
1174
1175 return mode;
1176}
1177
1178/**
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001179 * init_tti - Initialization transmit traffic interrupt scheme
1180 * @nic: device private variable
1181 * @link: link status (UP/DOWN) used to enable/disable continuous
1182 * transmit interrupts
1183 * Description: The function configures transmit traffic interrupts
1184 * Return Value: SUCCESS on success and
1185 * '-1' on failure
1186 */
1187
Adrian Bunk0d66afe2008-03-04 15:19:22 -08001188static int init_tti(struct s2io_nic *nic, int link)
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001189{
1190 struct XENA_dev_config __iomem *bar0 = nic->bar0;
1191 register u64 val64 = 0;
1192 int i;
1193 struct config_param *config;
1194
1195 config = &nic->config;
1196
1197 for (i = 0; i < config->tx_fifo_num; i++) {
1198 /*
1199 * TTI Initialization. Default Tx timer gets us about
1200 * 250 interrupts per sec. Continuous interrupts are enabled
1201 * by default.
1202 */
1203 if (nic->device_type == XFRAME_II_DEVICE) {
1204 int count = (nic->config.bus_speed * 125)/2;
1205 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
1206 } else
1207 val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
1208
1209 val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
1210 TTI_DATA1_MEM_TX_URNG_B(0x10) |
1211 TTI_DATA1_MEM_TX_URNG_C(0x30) |
1212 TTI_DATA1_MEM_TX_TIMER_AC_EN;
1213
1214 if (use_continuous_tx_intrs && (link == LINK_UP))
1215 val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
1216 writeq(val64, &bar0->tti_data1_mem);
1217
1218 val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
1219 TTI_DATA2_MEM_TX_UFC_B(0x20) |
1220 TTI_DATA2_MEM_TX_UFC_C(0x40) |
1221 TTI_DATA2_MEM_TX_UFC_D(0x80);
1222
1223 writeq(val64, &bar0->tti_data2_mem);
1224
1225 val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD |
1226 TTI_CMD_MEM_OFFSET(i);
1227 writeq(val64, &bar0->tti_command_mem);
1228
1229 if (wait_for_cmd_complete(&bar0->tti_command_mem,
1230 TTI_CMD_MEM_STROBE_NEW_CMD, S2IO_BIT_RESET) != SUCCESS)
1231 return FAILURE;
1232 }
1233
1234 return SUCCESS;
1235}
1236
1237/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001238 * init_nic - Initialization of hardware
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001239 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001240 * Description: The function sequentially configures every block
1241 * of the H/W from their reset values.
1242 * Return Value: SUCCESS on success and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 * '-1' on failure (endian settings incorrect).
1244 */
1245
1246static int init_nic(struct s2io_nic *nic)
1247{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001248 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 struct net_device *dev = nic->dev;
1250 register u64 val64 = 0;
1251 void __iomem *add;
1252 u32 time;
1253 int i, j;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001254 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 struct config_param *config;
Ananda Rajuc92ca042006-04-21 19:18:03 -04001256 int dtx_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 unsigned long long mem_share;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001258 int mem_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 mac_control = &nic->mac_control;
1261 config = &nic->config;
1262
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001263 /* to set the swapper controle on the card */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001264 if(s2io_set_swapper(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05001266 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
1268
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001269 /*
1270 * Herc requires EOI to be removed from reset before XGXS, so..
1271 */
1272 if (nic->device_type & XFRAME_II_DEVICE) {
1273 val64 = 0xA500000000ULL;
1274 writeq(val64, &bar0->sw_reset);
1275 msleep(500);
1276 val64 = readq(&bar0->sw_reset);
1277 }
1278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 /* Remove XGXS from reset state */
1280 val64 = 0;
1281 writeq(val64, &bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 msleep(500);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001283 val64 = readq(&bar0->sw_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Sreenivasa Honnur79620242007-12-05 23:59:28 -05001285 /* Ensure that it's safe to access registers by checking
1286 * RIC_RUNNING bit is reset. Check is valid only for XframeII.
1287 */
1288 if (nic->device_type == XFRAME_II_DEVICE) {
1289 for (i = 0; i < 50; i++) {
1290 val64 = readq(&bar0->adapter_status);
1291 if (!(val64 & ADAPTER_STATUS_RIC_RUNNING))
1292 break;
1293 msleep(10);
1294 }
1295 if (i == 50)
1296 return -ENODEV;
1297 }
1298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 /* Enable Receiving broadcasts */
1300 add = &bar0->mac_cfg;
1301 val64 = readq(&bar0->mac_cfg);
1302 val64 |= MAC_RMAC_BCAST_ENABLE;
1303 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1304 writel((u32) val64, add);
1305 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1306 writel((u32) (val64 >> 32), (add + 4));
1307
1308 /* Read registers in all blocks */
1309 val64 = readq(&bar0->mac_int_mask);
1310 val64 = readq(&bar0->mc_int_mask);
1311 val64 = readq(&bar0->xgxs_int_mask);
1312
1313 /* Set MTU */
1314 val64 = dev->mtu;
1315 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
1316
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001317 if (nic->device_type & XFRAME_II_DEVICE) {
1318 while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07001319 SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 &bar0->dtx_control, UF);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001321 if (dtx_cnt & 0x1)
1322 msleep(1); /* Necessary!! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 dtx_cnt++;
1324 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001325 } else {
Ananda Rajuc92ca042006-04-21 19:18:03 -04001326 while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
1327 SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
1328 &bar0->dtx_control, UF);
1329 val64 = readq(&bar0->dtx_control);
1330 dtx_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332 }
1333
1334 /* Tx DMA Initialization */
1335 val64 = 0;
1336 writeq(val64, &bar0->tx_fifo_partition_0);
1337 writeq(val64, &bar0->tx_fifo_partition_1);
1338 writeq(val64, &bar0->tx_fifo_partition_2);
1339 writeq(val64, &bar0->tx_fifo_partition_3);
1340
1341
1342 for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
1343 val64 |=
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001344 vBIT(config->tx_cfg[i].fifo_len - 1, ((j * 32) + 19),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 13) | vBIT(config->tx_cfg[i].fifo_priority,
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001346 ((j * 32) + 5), 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
1348 if (i == (config->tx_fifo_num - 1)) {
1349 if (i % 2 == 0)
1350 i++;
1351 }
1352
1353 switch (i) {
1354 case 1:
1355 writeq(val64, &bar0->tx_fifo_partition_0);
1356 val64 = 0;
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001357 j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 break;
1359 case 3:
1360 writeq(val64, &bar0->tx_fifo_partition_1);
1361 val64 = 0;
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001362 j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 break;
1364 case 5:
1365 writeq(val64, &bar0->tx_fifo_partition_2);
1366 val64 = 0;
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001367 j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 break;
1369 case 7:
1370 writeq(val64, &bar0->tx_fifo_partition_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001371 val64 = 0;
1372 j = 0;
1373 break;
1374 default:
1375 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 break;
1377 }
1378 }
1379
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001380 /*
1381 * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
1382 * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
1383 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001384 if ((nic->device_type == XFRAME_I_DEVICE) &&
Auke Kok44c10132007-06-08 15:46:36 -07001385 (nic->pdev->revision < 4))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001386 writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
1387
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 val64 = readq(&bar0->tx_fifo_partition_0);
1389 DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
1390 &bar0->tx_fifo_partition_0, (unsigned long long) val64);
1391
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001392 /*
1393 * Initialization of Tx_PA_CONFIG register to ignore packet
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 * integrity checking.
1395 */
1396 val64 = readq(&bar0->tx_pa_cfg);
1397 val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
1398 TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
1399 writeq(val64, &bar0->tx_pa_cfg);
1400
1401 /* Rx DMA intialization. */
1402 val64 = 0;
1403 for (i = 0; i < config->rx_ring_num; i++) {
1404 val64 |=
1405 vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
1406 3);
1407 }
1408 writeq(val64, &bar0->rx_queue_priority);
1409
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001410 /*
1411 * Allocating equal share of memory to all the
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 * configured Rings.
1413 */
1414 val64 = 0;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001415 if (nic->device_type & XFRAME_II_DEVICE)
1416 mem_size = 32;
1417 else
1418 mem_size = 64;
1419
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 for (i = 0; i < config->rx_ring_num; i++) {
1421 switch (i) {
1422 case 0:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001423 mem_share = (mem_size / config->rx_ring_num +
1424 mem_size % config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
1426 continue;
1427 case 1:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001428 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
1430 continue;
1431 case 2:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001432 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
1434 continue;
1435 case 3:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001436 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
1438 continue;
1439 case 4:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001440 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
1442 continue;
1443 case 5:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001444 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
1446 continue;
1447 case 6:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001448 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
1450 continue;
1451 case 7:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001452 mem_share = (mem_size / config->rx_ring_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
1454 continue;
1455 }
1456 }
1457 writeq(val64, &bar0->rx_queue_cfg);
1458
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001459 /*
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001460 * Filling Tx round robin registers
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001461 * as per the number of FIFOs for equal scheduling priority
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 */
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001463 switch (config->tx_fifo_num) {
1464 case 1:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001465 val64 = 0x0;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001466 writeq(val64, &bar0->tx_w_round_robin_0);
1467 writeq(val64, &bar0->tx_w_round_robin_1);
1468 writeq(val64, &bar0->tx_w_round_robin_2);
1469 writeq(val64, &bar0->tx_w_round_robin_3);
1470 writeq(val64, &bar0->tx_w_round_robin_4);
1471 break;
1472 case 2:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001473 val64 = 0x0001000100010001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001474 writeq(val64, &bar0->tx_w_round_robin_0);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001475 writeq(val64, &bar0->tx_w_round_robin_1);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001476 writeq(val64, &bar0->tx_w_round_robin_2);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001477 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001478 val64 = 0x0001000100000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001479 writeq(val64, &bar0->tx_w_round_robin_4);
1480 break;
1481 case 3:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001482 val64 = 0x0001020001020001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001483 writeq(val64, &bar0->tx_w_round_robin_0);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001484 val64 = 0x0200010200010200ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001485 writeq(val64, &bar0->tx_w_round_robin_1);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001486 val64 = 0x0102000102000102ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001487 writeq(val64, &bar0->tx_w_round_robin_2);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001488 val64 = 0x0001020001020001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001489 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001490 val64 = 0x0200010200000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001491 writeq(val64, &bar0->tx_w_round_robin_4);
1492 break;
1493 case 4:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001494 val64 = 0x0001020300010203ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001495 writeq(val64, &bar0->tx_w_round_robin_0);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001496 writeq(val64, &bar0->tx_w_round_robin_1);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001497 writeq(val64, &bar0->tx_w_round_robin_2);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001498 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001499 val64 = 0x0001020300000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001500 writeq(val64, &bar0->tx_w_round_robin_4);
1501 break;
1502 case 5:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001503 val64 = 0x0001020304000102ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001504 writeq(val64, &bar0->tx_w_round_robin_0);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001505 val64 = 0x0304000102030400ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001506 writeq(val64, &bar0->tx_w_round_robin_1);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001507 val64 = 0x0102030400010203ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001508 writeq(val64, &bar0->tx_w_round_robin_2);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001509 val64 = 0x0400010203040001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001510 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001511 val64 = 0x0203040000000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001512 writeq(val64, &bar0->tx_w_round_robin_4);
1513 break;
1514 case 6:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001515 val64 = 0x0001020304050001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001516 writeq(val64, &bar0->tx_w_round_robin_0);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001517 val64 = 0x0203040500010203ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001518 writeq(val64, &bar0->tx_w_round_robin_1);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001519 val64 = 0x0405000102030405ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001520 writeq(val64, &bar0->tx_w_round_robin_2);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001521 val64 = 0x0001020304050001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001522 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001523 val64 = 0x0203040500000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001524 writeq(val64, &bar0->tx_w_round_robin_4);
1525 break;
1526 case 7:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001527 val64 = 0x0001020304050600ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001528 writeq(val64, &bar0->tx_w_round_robin_0);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001529 val64 = 0x0102030405060001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001530 writeq(val64, &bar0->tx_w_round_robin_1);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001531 val64 = 0x0203040506000102ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001532 writeq(val64, &bar0->tx_w_round_robin_2);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001533 val64 = 0x0304050600010203ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001534 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001535 val64 = 0x0405060000000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001536 writeq(val64, &bar0->tx_w_round_robin_4);
1537 break;
1538 case 8:
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001539 val64 = 0x0001020304050607ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001540 writeq(val64, &bar0->tx_w_round_robin_0);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001541 writeq(val64, &bar0->tx_w_round_robin_1);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001542 writeq(val64, &bar0->tx_w_round_robin_2);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001543 writeq(val64, &bar0->tx_w_round_robin_3);
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001544 val64 = 0x0001020300000000ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001545 writeq(val64, &bar0->tx_w_round_robin_4);
1546 break;
1547 }
1548
Ananda Rajub41477f2006-07-24 19:52:49 -04001549 /* Enable all configured Tx FIFO partitions */
Ananda Raju5d3213c2006-04-21 19:23:26 -04001550 val64 = readq(&bar0->tx_fifo_partition_0);
1551 val64 |= (TX_FIFO_PARTITION_EN);
1552 writeq(val64, &bar0->tx_fifo_partition_0);
1553
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001554 /* Filling the Rx round robin registers as per the
1555 * number of Rings and steering based on QoS.
1556 */
1557 switch (config->rx_ring_num) {
1558 case 1:
1559 val64 = 0x8080808080808080ULL;
1560 writeq(val64, &bar0->rts_qos_steering);
1561 break;
1562 case 2:
1563 val64 = 0x0000010000010000ULL;
1564 writeq(val64, &bar0->rx_w_round_robin_0);
1565 val64 = 0x0100000100000100ULL;
1566 writeq(val64, &bar0->rx_w_round_robin_1);
1567 val64 = 0x0001000001000001ULL;
1568 writeq(val64, &bar0->rx_w_round_robin_2);
1569 val64 = 0x0000010000010000ULL;
1570 writeq(val64, &bar0->rx_w_round_robin_3);
1571 val64 = 0x0100000000000000ULL;
1572 writeq(val64, &bar0->rx_w_round_robin_4);
1573
1574 val64 = 0x8080808040404040ULL;
1575 writeq(val64, &bar0->rts_qos_steering);
1576 break;
1577 case 3:
1578 val64 = 0x0001000102000001ULL;
1579 writeq(val64, &bar0->rx_w_round_robin_0);
1580 val64 = 0x0001020000010001ULL;
1581 writeq(val64, &bar0->rx_w_round_robin_1);
1582 val64 = 0x0200000100010200ULL;
1583 writeq(val64, &bar0->rx_w_round_robin_2);
1584 val64 = 0x0001000102000001ULL;
1585 writeq(val64, &bar0->rx_w_round_robin_3);
1586 val64 = 0x0001020000000000ULL;
1587 writeq(val64, &bar0->rx_w_round_robin_4);
1588
1589 val64 = 0x8080804040402020ULL;
1590 writeq(val64, &bar0->rts_qos_steering);
1591 break;
1592 case 4:
1593 val64 = 0x0001020300010200ULL;
1594 writeq(val64, &bar0->rx_w_round_robin_0);
1595 val64 = 0x0100000102030001ULL;
1596 writeq(val64, &bar0->rx_w_round_robin_1);
1597 val64 = 0x0200010000010203ULL;
1598 writeq(val64, &bar0->rx_w_round_robin_2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001599 val64 = 0x0001020001000001ULL;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001600 writeq(val64, &bar0->rx_w_round_robin_3);
1601 val64 = 0x0203000100000000ULL;
1602 writeq(val64, &bar0->rx_w_round_robin_4);
1603
1604 val64 = 0x8080404020201010ULL;
1605 writeq(val64, &bar0->rts_qos_steering);
1606 break;
1607 case 5:
1608 val64 = 0x0001000203000102ULL;
1609 writeq(val64, &bar0->rx_w_round_robin_0);
1610 val64 = 0x0001020001030004ULL;
1611 writeq(val64, &bar0->rx_w_round_robin_1);
1612 val64 = 0x0001000203000102ULL;
1613 writeq(val64, &bar0->rx_w_round_robin_2);
1614 val64 = 0x0001020001030004ULL;
1615 writeq(val64, &bar0->rx_w_round_robin_3);
1616 val64 = 0x0001000000000000ULL;
1617 writeq(val64, &bar0->rx_w_round_robin_4);
1618
1619 val64 = 0x8080404020201008ULL;
1620 writeq(val64, &bar0->rts_qos_steering);
1621 break;
1622 case 6:
1623 val64 = 0x0001020304000102ULL;
1624 writeq(val64, &bar0->rx_w_round_robin_0);
1625 val64 = 0x0304050001020001ULL;
1626 writeq(val64, &bar0->rx_w_round_robin_1);
1627 val64 = 0x0203000100000102ULL;
1628 writeq(val64, &bar0->rx_w_round_robin_2);
1629 val64 = 0x0304000102030405ULL;
1630 writeq(val64, &bar0->rx_w_round_robin_3);
1631 val64 = 0x0001000200000000ULL;
1632 writeq(val64, &bar0->rx_w_round_robin_4);
1633
1634 val64 = 0x8080404020100804ULL;
1635 writeq(val64, &bar0->rts_qos_steering);
1636 break;
1637 case 7:
1638 val64 = 0x0001020001020300ULL;
1639 writeq(val64, &bar0->rx_w_round_robin_0);
1640 val64 = 0x0102030400010203ULL;
1641 writeq(val64, &bar0->rx_w_round_robin_1);
1642 val64 = 0x0405060001020001ULL;
1643 writeq(val64, &bar0->rx_w_round_robin_2);
1644 val64 = 0x0304050000010200ULL;
1645 writeq(val64, &bar0->rx_w_round_robin_3);
1646 val64 = 0x0102030000000000ULL;
1647 writeq(val64, &bar0->rx_w_round_robin_4);
1648
1649 val64 = 0x8080402010080402ULL;
1650 writeq(val64, &bar0->rts_qos_steering);
1651 break;
1652 case 8:
1653 val64 = 0x0001020300040105ULL;
1654 writeq(val64, &bar0->rx_w_round_robin_0);
1655 val64 = 0x0200030106000204ULL;
1656 writeq(val64, &bar0->rx_w_round_robin_1);
1657 val64 = 0x0103000502010007ULL;
1658 writeq(val64, &bar0->rx_w_round_robin_2);
1659 val64 = 0x0304010002060500ULL;
1660 writeq(val64, &bar0->rx_w_round_robin_3);
1661 val64 = 0x0103020400000000ULL;
1662 writeq(val64, &bar0->rx_w_round_robin_4);
1663
1664 val64 = 0x8040201008040201ULL;
1665 writeq(val64, &bar0->rts_qos_steering);
1666 break;
1667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 /* UDP Fix */
1670 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001671 for (i = 0; i < 8; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 writeq(val64, &bar0->rts_frm_len_n[i]);
1673
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07001674 /* Set the default rts frame length for the rings configured */
1675 val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
1676 for (i = 0 ; i < config->rx_ring_num ; i++)
1677 writeq(val64, &bar0->rts_frm_len_n[i]);
1678
1679 /* Set the frame length for the configured rings
1680 * desired by the user
1681 */
1682 for (i = 0; i < config->rx_ring_num; i++) {
1683 /* If rts_frm_len[i] == 0 then it is assumed that user not
1684 * specified frame length steering.
1685 * If the user provides the frame length then program
1686 * the rts_frm_len register for those values or else
1687 * leave it as it is.
1688 */
1689 if (rts_frm_len[i] != 0) {
1690 writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
1691 &bar0->rts_frm_len_n[i]);
1692 }
1693 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001694
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05001695 /* Disable differentiated services steering logic */
1696 for (i = 0; i < 64; i++) {
1697 if (rts_ds_steer(nic, i, 0) == FAILURE) {
1698 DBG_PRINT(ERR_DBG, "%s: failed rts ds steering",
1699 dev->name);
1700 DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i);
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05001701 return -ENODEV;
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05001702 }
1703 }
1704
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001705 /* Program statistics memory */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001708 if (nic->device_type == XFRAME_II_DEVICE) {
1709 val64 = STAT_BC(0x320);
1710 writeq(val64, &bar0->stat_byte_cnt);
1711 }
1712
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001713 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 * Initializing the sampling rate for the device to calculate the
1715 * bandwidth utilization.
1716 */
1717 val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
1718 MAC_RX_LINK_UTIL_VAL(rmac_util_period);
1719 writeq(val64, &bar0->mac_link_util);
1720
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001721 /*
1722 * Initializing the Transmit and Receive Traffic Interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 * Scheme.
1724 */
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001725
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08001726 /* Initialize TTI */
1727 if (SUCCESS != init_tti(nic, nic->last_link_state))
1728 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001730 /* RTI Initialization */
1731 if (nic->device_type == XFRAME_II_DEVICE) {
1732 /*
1733 * Programmed to generate Apprx 500 Intrs per
1734 * second
1735 */
1736 int count = (nic->config.bus_speed * 125)/4;
1737 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
1738 } else
1739 val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
1740 val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
1741 RTI_DATA1_MEM_RX_URNG_B(0x10) |
1742 RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
1743
1744 writeq(val64, &bar0->rti_data1_mem);
1745
1746 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
1747 RTI_DATA2_MEM_RX_UFC_B(0x2) ;
1748 if (nic->config.intr_type == MSI_X)
1749 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
1750 RTI_DATA2_MEM_RX_UFC_D(0x40));
1751 else
1752 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
1753 RTI_DATA2_MEM_RX_UFC_D(0x80));
1754 writeq(val64, &bar0->rti_data2_mem);
1755
1756 for (i = 0; i < config->rx_ring_num; i++) {
1757 val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
1758 | RTI_CMD_MEM_OFFSET(i);
1759 writeq(val64, &bar0->rti_command_mem);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001760
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001761 /*
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001762 * Once the operation completes, the Strobe bit of the
1763 * command register will be reset. We poll for this
1764 * particular condition. We wait for a maximum of 500ms
1765 * for the operation to complete, if it's not complete
1766 * by then we return error.
1767 */
1768 time = 0;
1769 while (TRUE) {
1770 val64 = readq(&bar0->rti_command_mem);
1771 if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD))
1772 break;
1773
1774 if (time > 10) {
1775 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
1776 dev->name);
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05001777 return -ENODEV;
raghavendra.koushik@neterion.comb6e3f982005-08-03 12:38:01 -07001778 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04001779 time++;
1780 msleep(50);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 }
1783
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001784 /*
1785 * Initializing proper values as Pause threshold into all
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 * the 8 Queues on Rx side.
1787 */
1788 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
1789 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
1790
1791 /* Disable RMAC PAD STRIPPING */
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01001792 add = &bar0->mac_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 val64 = readq(&bar0->mac_cfg);
1794 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
1795 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1796 writel((u32) (val64), add);
1797 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1798 writel((u32) (val64 >> 32), (add + 4));
1799 val64 = readq(&bar0->mac_cfg);
1800
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05001801 /* Enable FCS stripping by adapter */
1802 add = &bar0->mac_cfg;
1803 val64 = readq(&bar0->mac_cfg);
1804 val64 |= MAC_CFG_RMAC_STRIP_FCS;
1805 if (nic->device_type == XFRAME_II_DEVICE)
1806 writeq(val64, &bar0->mac_cfg);
1807 else {
1808 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1809 writel((u32) (val64), add);
1810 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
1811 writel((u32) (val64 >> 32), (add + 4));
1812 }
1813
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001814 /*
1815 * Set the time value to be inserted in the pause frame
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 * generated by xena.
1817 */
1818 val64 = readq(&bar0->rmac_pause_cfg);
1819 val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
1820 val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
1821 writeq(val64, &bar0->rmac_pause_cfg);
1822
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001823 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 * Set the Threshold Limit for Generating the pause frame
1825 * If the amount of data in any Queue exceeds ratio of
1826 * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
1827 * pause frame is generated
1828 */
1829 val64 = 0;
1830 for (i = 0; i < 4; i++) {
1831 val64 |=
1832 (((u64) 0xFF00 | nic->mac_control.
1833 mc_pause_threshold_q0q3)
1834 << (i * 2 * 8));
1835 }
1836 writeq(val64, &bar0->mc_pause_thresh_q0q3);
1837
1838 val64 = 0;
1839 for (i = 0; i < 4; i++) {
1840 val64 |=
1841 (((u64) 0xFF00 | nic->mac_control.
1842 mc_pause_threshold_q4q7)
1843 << (i * 2 * 8));
1844 }
1845 writeq(val64, &bar0->mc_pause_thresh_q4q7);
1846
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07001847 /*
1848 * TxDMA will stop Read request if the number of read split has
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 * exceeded the limit pointed by shared_splits
1850 */
1851 val64 = readq(&bar0->pic_control);
1852 val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
1853 writeq(val64, &bar0->pic_control);
1854
Ananda Raju863c11a2006-04-21 19:03:13 -04001855 if (nic->config.bus_speed == 266) {
1856 writeq(TXREQTO_VAL(0x7f) | TXREQTO_EN, &bar0->txreqtimeout);
1857 writeq(0x0, &bar0->read_retry_delay);
1858 writeq(0x0, &bar0->write_retry_delay);
1859 }
1860
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001861 /*
1862 * Programming the Herc to split every write transaction
1863 * that does not start on an ADB to reduce disconnects.
1864 */
1865 if (nic->device_type == XFRAME_II_DEVICE) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05001866 val64 = FAULT_BEHAVIOUR | EXT_REQ_EN |
1867 MISC_LINK_STABILITY_PRD(3);
Ananda Raju863c11a2006-04-21 19:03:13 -04001868 writeq(val64, &bar0->misc_control);
1869 val64 = readq(&bar0->pic_control2);
Jiri Slabyb7b5a122007-10-18 23:40:29 -07001870 val64 &= ~(s2BIT(13)|s2BIT(14)|s2BIT(15));
Ananda Raju863c11a2006-04-21 19:03:13 -04001871 writeq(val64, &bar0->pic_control2);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07001872 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04001873 if (strstr(nic->product_name, "CX4")) {
1874 val64 = TMAC_AVG_IPG(0x17);
1875 writeq(val64, &bar0->tmac_avg_ipg);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001876 }
1877
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 return SUCCESS;
1879}
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001880#define LINK_UP_DOWN_INTERRUPT 1
1881#define MAC_RMAC_ERR_TIMER 2
1882
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05001883static int s2io_link_fault_indication(struct s2io_nic *nic)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001884{
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07001885 if (nic->config.intr_type != INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04001886 return MAC_RMAC_ERR_TIMER;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07001887 if (nic->device_type == XFRAME_II_DEVICE)
1888 return LINK_UP_DOWN_INTERRUPT;
1889 else
1890 return MAC_RMAC_ERR_TIMER;
1891}
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07001892
Sivakumar Subramani9caab452007-09-06 06:21:54 -04001893/**
1894 * do_s2io_write_bits - update alarm bits in alarm register
1895 * @value: alarm bits
1896 * @flag: interrupt status
1897 * @addr: address value
1898 * Description: update alarm bits in alarm register
1899 * Return Value:
1900 * NONE.
1901 */
1902static void do_s2io_write_bits(u64 value, int flag, void __iomem *addr)
1903{
1904 u64 temp64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Sivakumar Subramani9caab452007-09-06 06:21:54 -04001906 temp64 = readq(addr);
1907
1908 if(flag == ENABLE_INTRS)
1909 temp64 &= ~((u64) value);
1910 else
1911 temp64 |= ((u64) value);
1912 writeq(temp64, addr);
1913}
1914
Stephen Hemminger43b7c452007-10-05 12:39:21 -07001915static void en_dis_err_alarms(struct s2io_nic *nic, u16 mask, int flag)
Sivakumar Subramani9caab452007-09-06 06:21:54 -04001916{
1917 struct XENA_dev_config __iomem *bar0 = nic->bar0;
1918 register u64 gen_int_mask = 0;
1919
1920 if (mask & TX_DMA_INTR) {
1921
1922 gen_int_mask |= TXDMA_INT_M;
1923
1924 do_s2io_write_bits(TXDMA_TDA_INT | TXDMA_PFC_INT |
1925 TXDMA_PCC_INT | TXDMA_TTI_INT |
1926 TXDMA_LSO_INT | TXDMA_TPA_INT |
1927 TXDMA_SM_INT, flag, &bar0->txdma_int_mask);
1928
1929 do_s2io_write_bits(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM |
1930 PFC_MISC_0_ERR | PFC_MISC_1_ERR |
1931 PFC_PCIX_ERR | PFC_ECC_SG_ERR, flag,
1932 &bar0->pfc_err_mask);
1933
1934 do_s2io_write_bits(TDA_Fn_ECC_DB_ERR | TDA_SM0_ERR_ALARM |
1935 TDA_SM1_ERR_ALARM | TDA_Fn_ECC_SG_ERR |
1936 TDA_PCIX_ERR, flag, &bar0->tda_err_mask);
1937
1938 do_s2io_write_bits(PCC_FB_ECC_DB_ERR | PCC_TXB_ECC_DB_ERR |
1939 PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM |
1940 PCC_N_SERR | PCC_6_COF_OV_ERR |
1941 PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR |
1942 PCC_7_LSO_OV_ERR | PCC_FB_ECC_SG_ERR |
1943 PCC_TXB_ECC_SG_ERR, flag, &bar0->pcc_err_mask);
1944
1945 do_s2io_write_bits(TTI_SM_ERR_ALARM | TTI_ECC_SG_ERR |
1946 TTI_ECC_DB_ERR, flag, &bar0->tti_err_mask);
1947
1948 do_s2io_write_bits(LSO6_ABORT | LSO7_ABORT |
1949 LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM |
1950 LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
1951 flag, &bar0->lso_err_mask);
1952
1953 do_s2io_write_bits(TPA_SM_ERR_ALARM | TPA_TX_FRM_DROP,
1954 flag, &bar0->tpa_err_mask);
1955
1956 do_s2io_write_bits(SM_SM_ERR_ALARM, flag, &bar0->sm_err_mask);
1957
1958 }
1959
1960 if (mask & TX_MAC_INTR) {
1961 gen_int_mask |= TXMAC_INT_M;
1962 do_s2io_write_bits(MAC_INT_STATUS_TMAC_INT, flag,
1963 &bar0->mac_int_mask);
1964 do_s2io_write_bits(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR |
1965 TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR |
1966 TMAC_DESC_ECC_SG_ERR | TMAC_DESC_ECC_DB_ERR,
1967 flag, &bar0->mac_tmac_err_mask);
1968 }
1969
1970 if (mask & TX_XGXS_INTR) {
1971 gen_int_mask |= TXXGXS_INT_M;
1972 do_s2io_write_bits(XGXS_INT_STATUS_TXGXS, flag,
1973 &bar0->xgxs_int_mask);
1974 do_s2io_write_bits(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR |
1975 TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
1976 flag, &bar0->xgxs_txgxs_err_mask);
1977 }
1978
1979 if (mask & RX_DMA_INTR) {
1980 gen_int_mask |= RXDMA_INT_M;
1981 do_s2io_write_bits(RXDMA_INT_RC_INT_M | RXDMA_INT_RPA_INT_M |
1982 RXDMA_INT_RDA_INT_M | RXDMA_INT_RTI_INT_M,
1983 flag, &bar0->rxdma_int_mask);
1984 do_s2io_write_bits(RC_PRCn_ECC_DB_ERR | RC_FTC_ECC_DB_ERR |
1985 RC_PRCn_SM_ERR_ALARM | RC_FTC_SM_ERR_ALARM |
1986 RC_PRCn_ECC_SG_ERR | RC_FTC_ECC_SG_ERR |
1987 RC_RDA_FAIL_WR_Rn, flag, &bar0->rc_err_mask);
1988 do_s2io_write_bits(PRC_PCI_AB_RD_Rn | PRC_PCI_AB_WR_Rn |
1989 PRC_PCI_AB_F_WR_Rn | PRC_PCI_DP_RD_Rn |
1990 PRC_PCI_DP_WR_Rn | PRC_PCI_DP_F_WR_Rn, flag,
1991 &bar0->prc_pcix_err_mask);
1992 do_s2io_write_bits(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR |
1993 RPA_ECC_SG_ERR | RPA_ECC_DB_ERR, flag,
1994 &bar0->rpa_err_mask);
1995 do_s2io_write_bits(RDA_RXDn_ECC_DB_ERR | RDA_FRM_ECC_DB_N_AERR |
1996 RDA_SM1_ERR_ALARM | RDA_SM0_ERR_ALARM |
1997 RDA_RXD_ECC_DB_SERR | RDA_RXDn_ECC_SG_ERR |
1998 RDA_FRM_ECC_SG_ERR | RDA_MISC_ERR|RDA_PCIX_ERR,
1999 flag, &bar0->rda_err_mask);
2000 do_s2io_write_bits(RTI_SM_ERR_ALARM |
2001 RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
2002 flag, &bar0->rti_err_mask);
2003 }
2004
2005 if (mask & RX_MAC_INTR) {
2006 gen_int_mask |= RXMAC_INT_M;
2007 do_s2io_write_bits(MAC_INT_STATUS_RMAC_INT, flag,
2008 &bar0->mac_int_mask);
2009 do_s2io_write_bits(RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR |
2010 RMAC_UNUSED_INT | RMAC_SINGLE_ECC_ERR |
2011 RMAC_DOUBLE_ECC_ERR |
2012 RMAC_LINK_STATE_CHANGE_INT,
2013 flag, &bar0->mac_rmac_err_mask);
2014 }
2015
2016 if (mask & RX_XGXS_INTR)
2017 {
2018 gen_int_mask |= RXXGXS_INT_M;
2019 do_s2io_write_bits(XGXS_INT_STATUS_RXGXS, flag,
2020 &bar0->xgxs_int_mask);
2021 do_s2io_write_bits(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR, flag,
2022 &bar0->xgxs_rxgxs_err_mask);
2023 }
2024
2025 if (mask & MC_INTR) {
2026 gen_int_mask |= MC_INT_M;
2027 do_s2io_write_bits(MC_INT_MASK_MC_INT, flag, &bar0->mc_int_mask);
2028 do_s2io_write_bits(MC_ERR_REG_SM_ERR | MC_ERR_REG_ECC_ALL_SNG |
2029 MC_ERR_REG_ECC_ALL_DBL | PLL_LOCK_N, flag,
2030 &bar0->mc_err_mask);
2031 }
2032 nic->general_int_mask = gen_int_mask;
2033
2034 /* Remove this line when alarm interrupts are enabled */
2035 nic->general_int_mask = 0;
2036}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002037/**
2038 * en_dis_able_nic_intrs - Enable or Disable the interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 * @nic: device private variable,
2040 * @mask: A mask indicating which Intr block must be modified and,
2041 * @flag: A flag indicating whether to enable or disable the Intrs.
2042 * Description: This function will either disable or enable the interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002043 * depending on the flag argument. The mask argument can be used to
2044 * enable/disable any Intr block.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 * Return Value: NONE.
2046 */
2047
2048static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
2049{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002050 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002051 register u64 temp64 = 0, intr_mask = 0;
2052
2053 intr_mask = nic->general_int_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 /* Top level interrupt classification */
2056 /* PIC Interrupts */
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002057 if (mask & TX_PIC_INTR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 /* Enable PIC Intrs in the general intr mask register */
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002059 intr_mask |= TXPIC_INT_M;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 if (flag == ENABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002061 /*
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002062 * If Hercules adapter enable GPIO otherwise
Ananda Rajub41477f2006-07-24 19:52:49 -04002063 * disable all PCIX, Flash, MDIO, IIC and GPIO
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002064 * interrupts for now.
2065 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002067 if (s2io_link_fault_indication(nic) ==
2068 LINK_UP_DOWN_INTERRUPT ) {
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002069 do_s2io_write_bits(PIC_INT_GPIO, flag,
2070 &bar0->pic_int_mask);
2071 do_s2io_write_bits(GPIO_INT_MASK_LINK_UP, flag,
2072 &bar0->gpio_int_mask);
2073 } else
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07002074 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002076 /*
2077 * Disable PIC Intrs in the general
2078 * intr mask register
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 */
2080 writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 }
2082 }
2083
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 /* Tx traffic interrupts */
2085 if (mask & TX_TRAFFIC_INTR) {
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002086 intr_mask |= TXTRAFFIC_INT_M;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 if (flag == ENABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002088 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 * Enable all the Tx side interrupts
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002090 * writing 0 Enables all 64 TX interrupt levels
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 */
2092 writeq(0x0, &bar0->tx_traffic_mask);
2093 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002094 /*
2095 * Disable Tx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 * register.
2097 */
2098 writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 }
2100 }
2101
2102 /* Rx traffic interrupts */
2103 if (mask & RX_TRAFFIC_INTR) {
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002104 intr_mask |= RXTRAFFIC_INT_M;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 if (flag == ENABLE_INTRS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 /* writing 0 Enables all 8 RX interrupt levels */
2107 writeq(0x0, &bar0->rx_traffic_mask);
2108 } else if (flag == DISABLE_INTRS) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002109 /*
2110 * Disable Rx Traffic Intrs in the general intr mask
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 * register.
2112 */
2113 writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 }
2115 }
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002116
2117 temp64 = readq(&bar0->general_int_mask);
2118 if (flag == ENABLE_INTRS)
2119 temp64 &= ~((u64) intr_mask);
2120 else
2121 temp64 = DISABLE_ALL_INTRS;
2122 writeq(temp64, &bar0->general_int_mask);
2123
2124 nic->general_int_mask = readq(&bar0->general_int_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002127/**
2128 * verify_pcc_quiescent- Checks for PCC quiescent state
2129 * Return: 1 If PCC is quiescence
2130 * 0 If PCC is not quiescence
2131 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002132static int verify_pcc_quiescent(struct s2io_nic *sp, int flag)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002133{
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002134 int ret = 0, herc;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002135 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002136 u64 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04002137
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002138 herc = (sp->device_type == XFRAME_II_DEVICE);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002139
2140 if (flag == FALSE) {
Auke Kok44c10132007-06-08 15:46:36 -07002141 if ((!herc && (sp->pdev->revision >= 4)) || herc) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002142 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002143 ret = 1;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002144 } else {
2145 if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002146 ret = 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002147 }
2148 } else {
Auke Kok44c10132007-06-08 15:46:36 -07002149 if ((!herc && (sp->pdev->revision >= 4)) || herc) {
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002150 if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002151 ADAPTER_STATUS_RMAC_PCC_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002152 ret = 1;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002153 } else {
2154 if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002155 ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002156 ret = 1;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002157 }
2158 }
2159
2160 return ret;
2161}
2162/**
2163 * verify_xena_quiescence - Checks whether the H/W is ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 * Description: Returns whether the H/W is ready to go or not. Depending
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002165 * on whether adapter enable bit was written or not the comparison
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 * differs and the calling function passes the input argument flag to
2167 * indicate this.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002168 * Return: 1 If xena is quiescence
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 * 0 If Xena is not quiescence
2170 */
2171
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002172static int verify_xena_quiescence(struct s2io_nic *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002174 int mode;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002175 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002176 u64 val64 = readq(&bar0->adapter_status);
2177 mode = s2io_verify_pci_mode(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002179 if (!(val64 & ADAPTER_STATUS_TDMA_READY)) {
2180 DBG_PRINT(ERR_DBG, "%s", "TDMA is not ready!");
2181 return 0;
2182 }
2183 if (!(val64 & ADAPTER_STATUS_RDMA_READY)) {
2184 DBG_PRINT(ERR_DBG, "%s", "RDMA is not ready!");
2185 return 0;
2186 }
2187 if (!(val64 & ADAPTER_STATUS_PFC_READY)) {
2188 DBG_PRINT(ERR_DBG, "%s", "PFC is not ready!");
2189 return 0;
2190 }
2191 if (!(val64 & ADAPTER_STATUS_TMAC_BUF_EMPTY)) {
2192 DBG_PRINT(ERR_DBG, "%s", "TMAC BUF is not empty!");
2193 return 0;
2194 }
2195 if (!(val64 & ADAPTER_STATUS_PIC_QUIESCENT)) {
2196 DBG_PRINT(ERR_DBG, "%s", "PIC is not QUIESCENT!");
2197 return 0;
2198 }
2199 if (!(val64 & ADAPTER_STATUS_MC_DRAM_READY)) {
2200 DBG_PRINT(ERR_DBG, "%s", "MC_DRAM is not ready!");
2201 return 0;
2202 }
2203 if (!(val64 & ADAPTER_STATUS_MC_QUEUES_READY)) {
2204 DBG_PRINT(ERR_DBG, "%s", "MC_QUEUES is not ready!");
2205 return 0;
2206 }
2207 if (!(val64 & ADAPTER_STATUS_M_PLL_LOCK)) {
2208 DBG_PRINT(ERR_DBG, "%s", "M_PLL is not locked!");
2209 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 }
2211
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002212 /*
2213 * In PCI 33 mode, the P_PLL is not used, and therefore,
2214 * the the P_PLL_LOCK bit in the adapter_status register will
2215 * not be asserted.
2216 */
2217 if (!(val64 & ADAPTER_STATUS_P_PLL_LOCK) &&
2218 sp->device_type == XFRAME_II_DEVICE && mode !=
2219 PCI_MODE_PCI_33) {
2220 DBG_PRINT(ERR_DBG, "%s", "P_PLL is not locked!");
2221 return 0;
2222 }
2223 if (!((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
2224 ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
2225 DBG_PRINT(ERR_DBG, "%s", "RC_PRC is not QUIESCENT!");
2226 return 0;
2227 }
2228 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/**
2232 * fix_mac_address - Fix for Mac addr problem on Alpha platforms
2233 * @sp: Pointer to device specifc structure
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002234 * Description :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 * New procedure to clear mac address reading problems on Alpha platforms
2236 *
2237 */
2238
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002239static void fix_mac_address(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002241 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 u64 val64;
2243 int i = 0;
2244
2245 while (fix_mac[i] != END_SIGN) {
2246 writeq(fix_mac[i++], &bar0->gpio_control);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002247 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 val64 = readq(&bar0->gpio_control);
2249 }
2250}
2251
2252/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002253 * start_nic - Turns the device on
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002255 * Description:
2256 * This function actually turns the device on. Before this function is
2257 * called,all Registers are configured from their reset states
2258 * and shared memory is allocated but the NIC is still quiescent. On
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 * calling this function, the device interrupts are cleared and the NIC is
2260 * literally switched on by writing into the adapter control register.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002261 * Return Value:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 * SUCCESS on success and -1 on failure.
2263 */
2264
2265static int start_nic(struct s2io_nic *nic)
2266{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002267 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 struct net_device *dev = nic->dev;
2269 register u64 val64 = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002270 u16 subid, i;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002271 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct config_param *config;
2273
2274 mac_control = &nic->mac_control;
2275 config = &nic->config;
2276
2277 /* PRC Initialization and configuration */
2278 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002279 writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 &bar0->prc_rxd0_n[i]);
2281
2282 val64 = readq(&bar0->prc_ctrl_n[i]);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002283 if (nic->rxd_mode == RXD_MODE_1)
2284 val64 |= PRC_CTRL_RC_ENABLED;
2285 else
2286 val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
Ananda Raju863c11a2006-04-21 19:03:13 -04002287 if (nic->device_type == XFRAME_II_DEVICE)
2288 val64 |= PRC_CTRL_GROUP_READS;
2289 val64 &= ~PRC_CTRL_RXD_BACKOFF_INTERVAL(0xFFFFFF);
2290 val64 |= PRC_CTRL_RXD_BACKOFF_INTERVAL(0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 writeq(val64, &bar0->prc_ctrl_n[i]);
2292 }
2293
Ananda Rajuda6971d2005-10-31 16:55:31 -05002294 if (nic->rxd_mode == RXD_MODE_3B) {
2295 /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
2296 val64 = readq(&bar0->rx_pa_cfg);
2297 val64 |= RX_PA_CFG_IGNORE_L2_ERR;
2298 writeq(val64, &bar0->rx_pa_cfg);
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
Sivakumar Subramani926930b2007-02-24 01:59:39 -05002301 if (vlan_tag_strip == 0) {
2302 val64 = readq(&bar0->rx_pa_cfg);
2303 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
2304 writeq(val64, &bar0->rx_pa_cfg);
2305 vlan_strip_flag = 0;
2306 }
2307
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002308 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 * Enabling MC-RLDRAM. After enabling the device, we timeout
2310 * for around 100ms, which is approximately the time required
2311 * for the device to be ready for operation.
2312 */
2313 val64 = readq(&bar0->mc_rldram_mrs);
2314 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
2315 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
2316 val64 = readq(&bar0->mc_rldram_mrs);
2317
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002318 msleep(100); /* Delay by around 100 ms. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
2320 /* Enabling ECC Protection. */
2321 val64 = readq(&bar0->adapter_control);
2322 val64 &= ~ADAPTER_ECC_EN;
2323 writeq(val64, &bar0->adapter_control);
2324
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002325 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002326 * Verify if the device is ready to be enabled, if so enable
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 * it.
2328 */
2329 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002330 if (!verify_xena_quiescence(nic)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
2332 DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
2333 (unsigned long long) val64);
2334 return FAILURE;
2335 }
2336
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002337 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 * With some switches, link might be already up at this point.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002339 * Because of this weird behavior, when we enable laser,
2340 * we may not get link. We need to handle this. We cannot
2341 * figure out which switch is misbehaving. So we are forced to
2342 * make a global change.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 */
2344
2345 /* Enabling Laser. */
2346 val64 = readq(&bar0->adapter_control);
2347 val64 |= ADAPTER_EOI_TX_ON;
2348 writeq(val64, &bar0->adapter_control);
2349
Ananda Rajuc92ca042006-04-21 19:18:03 -04002350 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
2351 /*
2352 * Dont see link state interrupts initally on some switches,
2353 * so directly scheduling the link state task here.
2354 */
2355 schedule_work(&nic->set_link_task);
2356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 /* SXE-002: Initialize link and activity LED */
2358 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07002359 if (((subid & 0xFF) >= 0x07) &&
2360 (nic->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 val64 = readq(&bar0->gpio_control);
2362 val64 |= 0x0000800000000000ULL;
2363 writeq(val64, &bar0->gpio_control);
2364 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01002365 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 }
2367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 return SUCCESS;
2369}
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002370/**
2371 * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
2372 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002373static struct sk_buff *s2io_txdl_getskb(struct fifo_info *fifo_data, struct \
2374 TxD *txdlp, int get_off)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002375{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002376 struct s2io_nic *nic = fifo_data->nic;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002377 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002378 struct TxD *txds;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002379 u16 j, frg_cnt;
2380
2381 txds = txdlp;
Surjit Reang2fda0962008-01-24 02:08:59 -08002382 if (txds->Host_Control == (u64)(long)fifo_data->ufo_in_band_v) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002383 pci_unmap_single(nic->pdev, (dma_addr_t)
2384 txds->Buffer_Pointer, sizeof(u64),
2385 PCI_DMA_TODEVICE);
2386 txds++;
2387 }
2388
2389 skb = (struct sk_buff *) ((unsigned long)
2390 txds->Host_Control);
2391 if (!skb) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002392 memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002393 return NULL;
2394 }
2395 pci_unmap_single(nic->pdev, (dma_addr_t)
2396 txds->Buffer_Pointer,
2397 skb->len - skb->data_len,
2398 PCI_DMA_TODEVICE);
2399 frg_cnt = skb_shinfo(skb)->nr_frags;
2400 if (frg_cnt) {
2401 txds++;
2402 for (j = 0; j < frg_cnt; j++, txds++) {
2403 skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
2404 if (!txds->Buffer_Pointer)
2405 break;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002406 pci_unmap_page(nic->pdev, (dma_addr_t)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002407 txds->Buffer_Pointer,
2408 frag->size, PCI_DMA_TODEVICE);
2409 }
2410 }
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002411 memset(txdlp,0, (sizeof(struct TxD) * fifo_data->max_txds));
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002412 return(skb);
2413}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002415/**
2416 * free_tx_buffers - Free all queued Tx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 * @nic : device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002418 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 * Free all queued Tx buffers.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002420 * Return Value: void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421*/
2422
2423static void free_tx_buffers(struct s2io_nic *nic)
2424{
2425 struct net_device *dev = nic->dev;
2426 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002427 struct TxD *txdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 int i, j;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002429 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct config_param *config;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002431 int cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
2433 mac_control = &nic->mac_control;
2434 config = &nic->config;
2435
2436 for (i = 0; i < config->tx_fifo_num; i++) {
Surjit Reang2fda0962008-01-24 02:08:59 -08002437 unsigned long flags;
2438 spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002440 txdp = (struct TxD *) \
2441 mac_control->fifos[i].list_info[j].list_virt_addr;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002442 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
2443 if (skb) {
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04002444 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002445 += skb->truesize;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05002446 dev_kfree_skb(skb);
2447 cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 }
2450 DBG_PRINT(INTR_DBG,
2451 "%s:forcibly freeing %d skbs on FIFO%d\n",
2452 dev->name, cnt, i);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002453 mac_control->fifos[i].tx_curr_get_info.offset = 0;
2454 mac_control->fifos[i].tx_curr_put_info.offset = 0;
Surjit Reang2fda0962008-01-24 02:08:59 -08002455 spin_unlock_irqrestore(&mac_control->fifos[i].tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 }
2457}
2458
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002459/**
2460 * stop_nic - To stop the nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 * @nic ; device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002462 * Description:
2463 * This function does exactly the opposite of what the start_nic()
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 * function does. This function is called to stop the device.
2465 * Return Value:
2466 * void.
2467 */
2468
2469static void stop_nic(struct s2io_nic *nic)
2470{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002471 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 register u64 val64 = 0;
Ananda Raju5d3213c2006-04-21 19:23:26 -04002473 u16 interruptible;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002474 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 struct config_param *config;
2476
2477 mac_control = &nic->mac_control;
2478 config = &nic->config;
2479
2480 /* Disable all interrupts */
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002481 en_dis_err_alarms(nic, ENA_ALL_INTRS, DISABLE_INTRS);
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07002482 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
Sivakumar Subramani9caab452007-09-06 06:21:54 -04002483 interruptible |= TX_PIC_INTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
2485
Ananda Raju5d3213c2006-04-21 19:23:26 -04002486 /* Clearing Adapter_En bit of ADAPTER_CONTROL Register */
2487 val64 = readq(&bar0->adapter_control);
2488 val64 &= ~(ADAPTER_CNTL_EN);
2489 writeq(val64, &bar0->adapter_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002492/**
2493 * fill_rx_buffers - Allocates the Rx side skbs
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 * @nic: device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002495 * @ring_no: ring number
2496 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 * The function allocates Rx side skbs and puts the physical
2498 * address of these buffers into the RxD buffer pointers, so that the NIC
2499 * can DMA the received frame into these locations.
2500 * The NIC supports 3 receive modes, viz
2501 * 1. single buffer,
2502 * 2. three buffer and
2503 * 3. Five buffer modes.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002504 * Each mode defines how many fragments the received frame will be split
2505 * up into by the NIC. The frame is split into L3 header, L4 Header,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
2507 * is split into 3 fragments. As of now only single buffer mode is
2508 * supported.
2509 * Return Value:
2510 * SUCCESS on success or an appropriate -ve value on failure.
2511 */
2512
Adrian Bunkac1f60d2005-11-06 01:46:47 +01002513static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
2515 struct net_device *dev = nic->dev;
2516 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002517 struct RxD_t *rxdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 int off, off1, size, block_no, block_no1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 u32 alloc_tab = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002520 u32 alloc_cnt;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002521 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 struct config_param *config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002523 u64 tmp;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002524 struct buffAdd *ba;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 unsigned long flags;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002526 struct RxD_t *first_rxdp = NULL;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002527 u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
Veena Parat6d517a22007-07-23 02:20:51 -04002528 struct RxD1 *rxdp1;
2529 struct RxD3 *rxdp3;
Veena Parat491abf22007-07-23 02:37:14 -04002530 struct swStat *stats = &nic->mac_control.stats_info->sw_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 mac_control = &nic->mac_control;
2533 config = &nic->config;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002534 alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
2535 atomic_read(&nic->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
Ananda Raju5d3213c2006-04-21 19:23:26 -04002537 block_no1 = mac_control->rings[ring_no].rx_curr_get_info.block_index;
Ananda Raju863c11a2006-04-21 19:03:13 -04002538 off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 while (alloc_tab < alloc_cnt) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002540 block_no = mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 block_index;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002542 off = mac_control->rings[ring_no].rx_curr_put_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Ananda Rajuda6971d2005-10-31 16:55:31 -05002544 rxdp = mac_control->rings[ring_no].
2545 rx_blocks[block_no].rxds[off].virt_addr;
2546
2547 if ((block_no == block_no1) && (off == off1) &&
2548 (rxdp->Host_Control)) {
2549 DBG_PRINT(INTR_DBG, "%s: Get and Put",
2550 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 DBG_PRINT(INTR_DBG, " info equated\n");
2552 goto end;
2553 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002554 if (off && (off == rxd_count[nic->rxd_mode])) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002555 mac_control->rings[ring_no].rx_curr_put_info.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 block_index++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002557 if (mac_control->rings[ring_no].rx_curr_put_info.
2558 block_index == mac_control->rings[ring_no].
2559 block_count)
2560 mac_control->rings[ring_no].rx_curr_put_info.
2561 block_index = 0;
2562 block_no = mac_control->rings[ring_no].
2563 rx_curr_put_info.block_index;
2564 if (off == rxd_count[nic->rxd_mode])
2565 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002566 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002567 offset = off;
2568 rxdp = mac_control->rings[ring_no].
2569 rx_blocks[block_no].block_virt_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2571 dev->name, rxdp);
2572 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002573 if(!napi) {
2574 spin_lock_irqsave(&nic->put_lock, flags);
2575 mac_control->rings[ring_no].put_pos =
2576 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2577 spin_unlock_irqrestore(&nic->put_lock, flags);
2578 } else {
2579 mac_control->rings[ring_no].put_pos =
2580 (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
2581 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002582 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
Veena Parat6d517a22007-07-23 02:20:51 -04002583 ((nic->rxd_mode == RXD_MODE_3B) &&
Jiri Slabyb7b5a122007-10-18 23:40:29 -07002584 (rxdp->Control_2 & s2BIT(0)))) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002585 mac_control->rings[ring_no].rx_curr_put_info.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002586 offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 goto end;
2588 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002589 /* calculate size of skb based on ring mode */
2590 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
2591 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
2592 if (nic->rxd_mode == RXD_MODE_1)
2593 size += NET_IP_ALIGN;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002594 else
Veena Parat6d517a22007-07-23 02:20:51 -04002595 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Ananda Rajuda6971d2005-10-31 16:55:31 -05002597 /* allocate skb */
2598 skb = dev_alloc_skb(size);
2599 if(!skb) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002600 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
2601 DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n");
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002602 if (first_rxdp) {
2603 wmb();
2604 first_rxdp->Control_1 |= RXD_OWN_XENA;
2605 }
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04002606 nic->mac_control.stats_info->sw_stat. \
2607 mem_alloc_fail_cnt++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002608 return -ENOMEM ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04002610 nic->mac_control.stats_info->sw_stat.mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002611 += skb->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002612 if (nic->rxd_mode == RXD_MODE_1) {
2613 /* 1 buffer mode - normal operation mode */
Veena Parat6d517a22007-07-23 02:20:51 -04002614 rxdp1 = (struct RxD1*)rxdp;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002615 memset(rxdp, 0, sizeof(struct RxD1));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002616 skb_reserve(skb, NET_IP_ALIGN);
Veena Parat6d517a22007-07-23 02:20:51 -04002617 rxdp1->Buffer0_ptr = pci_map_single
Ananda Raju863c11a2006-04-21 19:03:13 -04002618 (nic->pdev, skb->data, size - NET_IP_ALIGN,
2619 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04002620 if( (rxdp1->Buffer0_ptr == 0) ||
2621 (rxdp1->Buffer0_ptr ==
2622 DMA_ERROR_CODE))
2623 goto pci_map_failed;
2624
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04002625 rxdp->Control_2 =
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002626 SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002627
Veena Parat6d517a22007-07-23 02:20:51 -04002628 } else if (nic->rxd_mode == RXD_MODE_3B) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05002629 /*
Veena Parat6d517a22007-07-23 02:20:51 -04002630 * 2 buffer mode -
2631 * 2 buffer mode provides 128
Ananda Rajuda6971d2005-10-31 16:55:31 -05002632 * byte aligned receive buffers.
Ananda Rajuda6971d2005-10-31 16:55:31 -05002633 */
2634
Veena Parat6d517a22007-07-23 02:20:51 -04002635 rxdp3 = (struct RxD3*)rxdp;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002636 /* save buffer pointers to avoid frequent dma mapping */
Veena Parat6d517a22007-07-23 02:20:51 -04002637 Buffer0_ptr = rxdp3->Buffer0_ptr;
2638 Buffer1_ptr = rxdp3->Buffer1_ptr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002639 memset(rxdp, 0, sizeof(struct RxD3));
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002640 /* restore the buffer pointers for dma sync*/
Veena Parat6d517a22007-07-23 02:20:51 -04002641 rxdp3->Buffer0_ptr = Buffer0_ptr;
2642 rxdp3->Buffer1_ptr = Buffer1_ptr;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08002643
Ananda Rajuda6971d2005-10-31 16:55:31 -05002644 ba = &mac_control->rings[ring_no].ba[block_no][off];
2645 skb_reserve(skb, BUF0_LEN);
2646 tmp = (u64)(unsigned long) skb->data;
2647 tmp += ALIGN_SIZE;
2648 tmp &= ~ALIGN_SIZE;
2649 skb->data = (void *) (unsigned long)tmp;
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -07002650 skb_reset_tail_pointer(skb);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002651
Veena Parat6d517a22007-07-23 02:20:51 -04002652 if (!(rxdp3->Buffer0_ptr))
2653 rxdp3->Buffer0_ptr =
Ananda Raju75c30b12006-07-24 19:55:09 -04002654 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002655 PCI_DMA_FROMDEVICE);
Ananda Raju75c30b12006-07-24 19:55:09 -04002656 else
2657 pci_dma_sync_single_for_device(nic->pdev,
Veena Parat6d517a22007-07-23 02:20:51 -04002658 (dma_addr_t) rxdp3->Buffer0_ptr,
Ananda Raju75c30b12006-07-24 19:55:09 -04002659 BUF0_LEN, PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04002660 if( (rxdp3->Buffer0_ptr == 0) ||
2661 (rxdp3->Buffer0_ptr == DMA_ERROR_CODE))
2662 goto pci_map_failed;
2663
Ananda Rajuda6971d2005-10-31 16:55:31 -05002664 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2665 if (nic->rxd_mode == RXD_MODE_3B) {
2666 /* Two buffer mode */
2667
2668 /*
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002669 * Buffer2 will have L3/L4 header plus
Ananda Rajuda6971d2005-10-31 16:55:31 -05002670 * L4 payload
2671 */
Veena Parat6d517a22007-07-23 02:20:51 -04002672 rxdp3->Buffer2_ptr = pci_map_single
Ananda Rajuda6971d2005-10-31 16:55:31 -05002673 (nic->pdev, skb->data, dev->mtu + 4,
2674 PCI_DMA_FROMDEVICE);
2675
Veena Parat491abf22007-07-23 02:37:14 -04002676 if( (rxdp3->Buffer2_ptr == 0) ||
2677 (rxdp3->Buffer2_ptr == DMA_ERROR_CODE))
2678 goto pci_map_failed;
2679
2680 rxdp3->Buffer1_ptr =
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002681 pci_map_single(nic->pdev,
Ananda Raju75c30b12006-07-24 19:55:09 -04002682 ba->ba_1, BUF1_LEN,
2683 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04002684 if( (rxdp3->Buffer1_ptr == 0) ||
2685 (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
2686 pci_unmap_single
2687 (nic->pdev,
Al Viro3e847422007-08-02 19:21:30 +01002688 (dma_addr_t)rxdp3->Buffer2_ptr,
Veena Parat491abf22007-07-23 02:37:14 -04002689 dev->mtu + 4,
2690 PCI_DMA_FROMDEVICE);
2691 goto pci_map_failed;
Ananda Raju75c30b12006-07-24 19:55:09 -04002692 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05002693 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2694 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2695 (dev->mtu + 4);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002696 }
Jiri Slabyb7b5a122007-10-18 23:40:29 -07002697 rxdp->Control_2 |= s2BIT(0);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 rxdp->Host_Control = (unsigned long) (skb);
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002700 if (alloc_tab & ((1 << rxsync_frequency) - 1))
2701 rxdp->Control_1 |= RXD_OWN_XENA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 off++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002703 if (off == (rxd_count[nic->rxd_mode] + 1))
2704 off = 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002705 mac_control->rings[ring_no].rx_curr_put_info.offset = off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07002707 rxdp->Control_2 |= SET_RXD_MARKER;
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002708 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
2709 if (first_rxdp) {
2710 wmb();
2711 first_rxdp->Control_1 |= RXD_OWN_XENA;
2712 }
2713 first_rxdp = rxdp;
2714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 atomic_inc(&nic->rx_bufs_left[ring_no]);
2716 alloc_tab++;
2717 }
2718
2719 end:
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07002720 /* Transfer ownership of first descriptor to adapter just before
2721 * exiting. Before that, use memory barrier so that ownership
2722 * and other fields are seen by adapter correctly.
2723 */
2724 if (first_rxdp) {
2725 wmb();
2726 first_rxdp->Control_1 |= RXD_OWN_XENA;
2727 }
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return SUCCESS;
Veena Parat491abf22007-07-23 02:37:14 -04002730pci_map_failed:
2731 stats->pci_map_fail_cnt++;
2732 stats->mem_freed += skb->truesize;
2733 dev_kfree_skb_irq(skb);
2734 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735}
2736
Ananda Rajuda6971d2005-10-31 16:55:31 -05002737static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2738{
2739 struct net_device *dev = sp->dev;
2740 int j;
2741 struct sk_buff *skb;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002742 struct RxD_t *rxdp;
2743 struct mac_info *mac_control;
2744 struct buffAdd *ba;
Veena Parat6d517a22007-07-23 02:20:51 -04002745 struct RxD1 *rxdp1;
2746 struct RxD3 *rxdp3;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002747
2748 mac_control = &sp->mac_control;
2749 for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
2750 rxdp = mac_control->rings[ring_no].
2751 rx_blocks[blk].rxds[j].virt_addr;
2752 skb = (struct sk_buff *)
2753 ((unsigned long) rxdp->Host_Control);
2754 if (!skb) {
2755 continue;
2756 }
2757 if (sp->rxd_mode == RXD_MODE_1) {
Veena Parat6d517a22007-07-23 02:20:51 -04002758 rxdp1 = (struct RxD1*)rxdp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002759 pci_unmap_single(sp->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04002760 rxdp1->Buffer0_ptr,
2761 dev->mtu +
2762 HEADER_ETHERNET_II_802_3_SIZE
2763 + HEADER_802_2_SIZE +
2764 HEADER_SNAP_SIZE,
2765 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002766 memset(rxdp, 0, sizeof(struct RxD1));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002767 } else if(sp->rxd_mode == RXD_MODE_3B) {
Veena Parat6d517a22007-07-23 02:20:51 -04002768 rxdp3 = (struct RxD3*)rxdp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002769 ba = &mac_control->rings[ring_no].
2770 ba[blk][j];
2771 pci_unmap_single(sp->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04002772 rxdp3->Buffer0_ptr,
2773 BUF0_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002774 PCI_DMA_FROMDEVICE);
2775 pci_unmap_single(sp->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04002776 rxdp3->Buffer1_ptr,
2777 BUF1_LEN,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002778 PCI_DMA_FROMDEVICE);
2779 pci_unmap_single(sp->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04002780 rxdp3->Buffer2_ptr,
2781 dev->mtu + 4,
Ananda Rajuda6971d2005-10-31 16:55:31 -05002782 PCI_DMA_FROMDEVICE);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002783 memset(rxdp, 0, sizeof(struct RxD3));
Ananda Rajuda6971d2005-10-31 16:55:31 -05002784 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04002785 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002786 dev_kfree_skb(skb);
2787 atomic_dec(&sp->rx_bufs_left[ring_no]);
2788 }
2789}
2790
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002792 * free_rx_buffers - Frees all Rx buffers
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 * @sp: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002794 * Description:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 * This function will free all Rx buffers allocated by host.
2796 * Return Value:
2797 * NONE.
2798 */
2799
2800static void free_rx_buffers(struct s2io_nic *sp)
2801{
2802 struct net_device *dev = sp->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002803 int i, blk = 0, buf_cnt = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002804 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 struct config_param *config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
2807 mac_control = &sp->mac_control;
2808 config = &sp->config;
2809
2810 for (i = 0; i < config->rx_ring_num; i++) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05002811 for (blk = 0; blk < rx_ring_sz[i]; blk++)
2812 free_rxd_blk(sp,i,blk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002814 mac_control->rings[i].rx_curr_put_info.block_index = 0;
2815 mac_control->rings[i].rx_curr_get_info.block_index = 0;
2816 mac_control->rings[i].rx_curr_put_info.offset = 0;
2817 mac_control->rings[i].rx_curr_get_info.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 atomic_set(&sp->rx_bufs_left[i], 0);
2819 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
2820 dev->name, buf_cnt, i);
2821 }
2822}
2823
2824/**
2825 * s2io_poll - Rx interrupt handler for NAPI support
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002826 * @napi : pointer to the napi structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002827 * @budget : The number of packets that were budgeted to be processed
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 * during one pass through the 'Poll" function.
2829 * Description:
2830 * Comes into picture only if NAPI support has been incorporated. It does
2831 * the same thing that rx_intr_handler does, but not in a interrupt context
2832 * also It will process only a given number of packets.
2833 * Return value:
2834 * 0 on success and 1 if there are No Rx packets to be processed.
2835 */
2836
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002837static int s2io_poll(struct napi_struct *napi, int budget)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002839 struct s2io_nic *nic = container_of(napi, struct s2io_nic, napi);
2840 struct net_device *dev = nic->dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002841 int pkt_cnt = 0, org_pkts_to_process;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002842 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 struct config_param *config;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002844 struct XENA_dev_config __iomem *bar0 = nic->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002845 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
2847 mac_control = &nic->mac_control;
2848 config = &nic->config;
2849
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002850 nic->pkts_to_process = budget;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002851 org_pkts_to_process = nic->pkts_to_process;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002853 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
2854 readl(&bar0->rx_traffic_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
2856 for (i = 0; i < config->rx_ring_num; i++) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002857 rx_intr_handler(&mac_control->rings[i]);
2858 pkt_cnt = org_pkts_to_process - nic->pkts_to_process;
2859 if (!nic->pkts_to_process) {
2860 /* Quota for the current iteration has been met */
2861 goto no_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002865 netif_rx_complete(dev, napi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 for (i = 0; i < config->rx_ring_num; i++) {
2868 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002869 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2870 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 break;
2872 }
2873 }
2874 /* Re enable the Rx interrupts. */
Ananda Rajuc92ca042006-04-21 19:18:03 -04002875 writeq(0x0, &bar0->rx_traffic_mask);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05002876 readl(&bar0->rx_traffic_mask);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002877 return pkt_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002879no_rx:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 for (i = 0; i < config->rx_ring_num; i++) {
2881 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002882 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2883 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 break;
2885 }
2886 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002887 return pkt_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002889
Ananda Rajub41477f2006-07-24 19:52:49 -04002890#ifdef CONFIG_NET_POLL_CONTROLLER
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002891/**
Ananda Rajub41477f2006-07-24 19:52:49 -04002892 * s2io_netpoll - netpoll event handler entry point
Brian Haley612eff02006-06-15 14:36:36 -04002893 * @dev : pointer to the device structure.
2894 * Description:
Ananda Rajub41477f2006-07-24 19:52:49 -04002895 * This function will be called by upper layer to check for events on the
2896 * interface in situations where interrupts are disabled. It is used for
2897 * specific in-kernel networking tasks, such as remote consoles and kernel
2898 * debugging over the network (example netdump in RedHat).
Brian Haley612eff02006-06-15 14:36:36 -04002899 */
Brian Haley612eff02006-06-15 14:36:36 -04002900static void s2io_netpoll(struct net_device *dev)
2901{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002902 struct s2io_nic *nic = dev->priv;
2903 struct mac_info *mac_control;
Brian Haley612eff02006-06-15 14:36:36 -04002904 struct config_param *config;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002905 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ananda Rajub41477f2006-07-24 19:52:49 -04002906 u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
Brian Haley612eff02006-06-15 14:36:36 -04002907 int i;
2908
Linas Vepstasd796fdb2007-05-14 18:37:30 -05002909 if (pci_channel_offline(nic->pdev))
2910 return;
2911
Brian Haley612eff02006-06-15 14:36:36 -04002912 disable_irq(dev->irq);
2913
Brian Haley612eff02006-06-15 14:36:36 -04002914 mac_control = &nic->mac_control;
2915 config = &nic->config;
2916
Brian Haley612eff02006-06-15 14:36:36 -04002917 writeq(val64, &bar0->rx_traffic_int);
Ananda Rajub41477f2006-07-24 19:52:49 -04002918 writeq(val64, &bar0->tx_traffic_int);
Brian Haley612eff02006-06-15 14:36:36 -04002919
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002920 /* we need to free up the transmitted skbufs or else netpoll will
Ananda Rajub41477f2006-07-24 19:52:49 -04002921 * run out of skbs and will fail and eventually netpoll application such
2922 * as netdump will fail.
2923 */
2924 for (i = 0; i < config->tx_fifo_num; i++)
2925 tx_intr_handler(&mac_control->fifos[i]);
2926
2927 /* check for received packet and indicate up to network */
Brian Haley612eff02006-06-15 14:36:36 -04002928 for (i = 0; i < config->rx_ring_num; i++)
2929 rx_intr_handler(&mac_control->rings[i]);
2930
2931 for (i = 0; i < config->rx_ring_num; i++) {
2932 if (fill_rx_buffers(nic, i) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08002933 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2934 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n");
Brian Haley612eff02006-06-15 14:36:36 -04002935 break;
2936 }
2937 }
Brian Haley612eff02006-06-15 14:36:36 -04002938 enable_irq(dev->irq);
2939 return;
2940}
2941#endif
2942
2943/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 * rx_intr_handler - Rx interrupt handler
2945 * @nic: device private variable.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002946 * Description:
2947 * If the interrupt is because of a received frame or if the
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 * receive ring contains fresh as yet un-processed frames,this function is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002949 * called. It picks out the RxD at which place the last Rx processing had
2950 * stopped and sends the skb to the OSM's Rx handler and then increments
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 * the offset.
2952 * Return Value:
2953 * NONE.
2954 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002955static void rx_intr_handler(struct ring_info *ring_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002957 struct s2io_nic *nic = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 struct net_device *dev = (struct net_device *) nic->dev;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002959 int get_block, put_block, put_offset;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002960 struct rx_curr_get_info get_info, put_info;
2961 struct RxD_t *rxdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 struct sk_buff *skb;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002963 int pkt_cnt = 0;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002964 int i;
Veena Parat6d517a22007-07-23 02:20:51 -04002965 struct RxD1* rxdp1;
2966 struct RxD3* rxdp3;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05002967
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002968 spin_lock(&nic->rx_lock);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002969
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002970 get_info = ring_data->rx_curr_get_info;
2971 get_block = get_info.block_index;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05002972 memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002973 put_block = put_info.block_index;
Ananda Rajuda6971d2005-10-31 16:55:31 -05002974 rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002975 if (!napi) {
2976 spin_lock(&nic->put_lock);
2977 put_offset = ring_data->put_pos;
2978 spin_unlock(&nic->put_lock);
2979 } else
2980 put_offset = ring_data->put_pos;
2981
Ananda Rajuda6971d2005-10-31 16:55:31 -05002982 while (RXD_IS_UP2DT(rxdp)) {
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05002983 /*
2984 * If your are next to put index then it's
2985 * FIFO full condition
2986 */
Ananda Rajuda6971d2005-10-31 16:55:31 -05002987 if ((get_block == put_block) &&
2988 (get_info.offset + 1) == put_info.offset) {
Ananda Raju75c30b12006-07-24 19:55:09 -04002989 DBG_PRINT(INTR_DBG, "%s: Ring Full\n",dev->name);
Ananda Rajuda6971d2005-10-31 16:55:31 -05002990 break;
2991 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002992 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
2993 if (skb == NULL) {
2994 DBG_PRINT(ERR_DBG, "%s: The skb is ",
2995 dev->name);
2996 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07002997 spin_unlock(&nic->rx_lock);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07002998 return;
2999 }
Ananda Rajuda6971d2005-10-31 16:55:31 -05003000 if (nic->rxd_mode == RXD_MODE_1) {
Veena Parat6d517a22007-07-23 02:20:51 -04003001 rxdp1 = (struct RxD1*)rxdp;
Ananda Rajuda6971d2005-10-31 16:55:31 -05003002 pci_unmap_single(nic->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04003003 rxdp1->Buffer0_ptr,
3004 dev->mtu +
3005 HEADER_ETHERNET_II_802_3_SIZE +
3006 HEADER_802_2_SIZE +
3007 HEADER_SNAP_SIZE,
3008 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05003009 } else if (nic->rxd_mode == RXD_MODE_3B) {
Veena Parat6d517a22007-07-23 02:20:51 -04003010 rxdp3 = (struct RxD3*)rxdp;
Ananda Raju75c30b12006-07-24 19:55:09 -04003011 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04003012 rxdp3->Buffer0_ptr,
3013 BUF0_LEN, PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05003014 pci_unmap_single(nic->pdev, (dma_addr_t)
Veena Parat6d517a22007-07-23 02:20:51 -04003015 rxdp3->Buffer2_ptr,
3016 dev->mtu + 4,
3017 PCI_DMA_FROMDEVICE);
Ananda Rajuda6971d2005-10-31 16:55:31 -05003018 }
Ananda Raju863c11a2006-04-21 19:03:13 -04003019 prefetch(skb->data);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003020 rx_osm_handler(ring_data, rxdp);
3021 get_info.offset++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05003022 ring_data->rx_curr_get_info.offset = get_info.offset;
3023 rxdp = ring_data->rx_blocks[get_block].
3024 rxds[get_info.offset].virt_addr;
3025 if (get_info.offset == rxd_count[nic->rxd_mode]) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003026 get_info.offset = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05003027 ring_data->rx_curr_get_info.offset = get_info.offset;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003028 get_block++;
Ananda Rajuda6971d2005-10-31 16:55:31 -05003029 if (get_block == ring_data->block_count)
3030 get_block = 0;
3031 ring_data->rx_curr_get_info.block_index = get_block;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003032 rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
3033 }
3034
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003035 nic->pkts_to_process -= 1;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05003036 if ((napi) && (!nic->pkts_to_process))
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003037 break;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003038 pkt_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
3040 break;
3041 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003042 if (nic->lro) {
3043 /* Clear all LRO sessions before exiting */
3044 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003045 struct lro *lro = &nic->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05003046 if (lro->in_use) {
3047 update_L3L4_header(nic, lro);
3048 queue_rx_frame(lro->parent);
3049 clear_lro_session(lro);
3050 }
3051 }
3052 }
3053
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07003054 spin_unlock(&nic->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055}
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003056
3057/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 * tx_intr_handler - Transmit interrupt handler
3059 * @nic : device private variable
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003060 * Description:
3061 * If an interrupt was raised to indicate DMA complete of the
3062 * Tx packet, this function is called. It identifies the last TxD
3063 * whose buffer was freed and frees all skbs whose data have already
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 * DMA'ed into the NICs internal memory.
3065 * Return Value:
3066 * NONE
3067 */
3068
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003069static void tx_intr_handler(struct fifo_info *fifo_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003071 struct s2io_nic *nic = fifo_data->nic;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003072 struct tx_curr_get_info get_info, put_info;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05003073 struct sk_buff *skb = NULL;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003074 struct TxD *txdlp;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05003075 int pkt_cnt = 0;
Surjit Reang2fda0962008-01-24 02:08:59 -08003076 unsigned long flags = 0;
Olaf Heringf9046eb2007-06-19 22:41:10 +02003077 u8 err_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
Surjit Reang2fda0962008-01-24 02:08:59 -08003079 if (!spin_trylock_irqsave(&fifo_data->tx_lock, flags))
3080 return;
3081
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003082 get_info = fifo_data->tx_curr_get_info;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003083 memcpy(&put_info, &fifo_data->tx_curr_put_info, sizeof(put_info));
3084 txdlp = (struct TxD *) fifo_data->list_info[get_info.offset].
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003085 list_virt_addr;
3086 while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
3087 (get_info.offset != put_info.offset) &&
3088 (txdlp->Host_Control)) {
3089 /* Check for TxD errors */
3090 if (txdlp->Control_1 & TXD_T_CODE) {
3091 unsigned long long err;
3092 err = txdlp->Control_1 & TXD_T_CODE;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003093 if (err & 0x1) {
3094 nic->mac_control.stats_info->sw_stat.
3095 parity_err_cnt++;
3096 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003097
3098 /* update t_code statistics */
Olaf Heringf9046eb2007-06-19 22:41:10 +02003099 err_mask = err >> 48;
3100 switch(err_mask) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003101 case 2:
3102 nic->mac_control.stats_info->sw_stat.
3103 tx_buf_abort_cnt++;
3104 break;
3105
3106 case 3:
3107 nic->mac_control.stats_info->sw_stat.
3108 tx_desc_abort_cnt++;
3109 break;
3110
3111 case 7:
3112 nic->mac_control.stats_info->sw_stat.
3113 tx_parity_err_cnt++;
3114 break;
3115
3116 case 10:
3117 nic->mac_control.stats_info->sw_stat.
3118 tx_link_loss_cnt++;
3119 break;
3120
3121 case 15:
3122 nic->mac_control.stats_info->sw_stat.
3123 tx_list_proc_err_cnt++;
3124 break;
3125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003127
Ananda Rajufed5ecc2005-11-14 15:25:08 -05003128 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003129 if (skb == NULL) {
Surjit Reang2fda0962008-01-24 02:08:59 -08003130 spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003131 DBG_PRINT(ERR_DBG, "%s: Null skb ",
3132 __FUNCTION__);
3133 DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
3134 return;
3135 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05003136 pkt_cnt++;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003137
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003138 /* Updating the statistics block */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003139 nic->stats.tx_bytes += skb->len;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003140 nic->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003141 dev_kfree_skb_irq(skb);
3142
3143 get_info.offset++;
Ananda Raju863c11a2006-04-21 19:03:13 -04003144 if (get_info.offset == get_info.fifo_len + 1)
3145 get_info.offset = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003146 txdlp = (struct TxD *) fifo_data->list_info
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003147 [get_info.offset].list_virt_addr;
3148 fifo_data->tx_curr_get_info.offset =
3149 get_info.offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 }
3151
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05003152 s2io_wake_tx_queue(fifo_data, pkt_cnt, nic->config.multiq);
Surjit Reang2fda0962008-01-24 02:08:59 -08003153
3154 spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003157/**
Ananda Rajubd1034f2006-04-21 19:20:22 -04003158 * s2io_mdio_write - Function to write in to MDIO registers
3159 * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
3160 * @addr : address value
3161 * @value : data value
3162 * @dev : pointer to net_device structure
3163 * Description:
3164 * This function is used to write values to the MDIO registers
3165 * NONE
3166 */
3167static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value, struct net_device *dev)
3168{
3169 u64 val64 = 0x0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003170 struct s2io_nic *sp = dev->priv;
3171 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003172
3173 //address transaction
3174 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3175 | MDIO_MMD_DEV_ADDR(mmd_type)
3176 | MDIO_MMS_PRT_ADDR(0x0);
3177 writeq(val64, &bar0->mdio_control);
3178 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3179 writeq(val64, &bar0->mdio_control);
3180 udelay(100);
3181
3182 //Data transaction
3183 val64 = 0x0;
3184 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3185 | MDIO_MMD_DEV_ADDR(mmd_type)
3186 | MDIO_MMS_PRT_ADDR(0x0)
3187 | MDIO_MDIO_DATA(value)
3188 | MDIO_OP(MDIO_OP_WRITE_TRANS);
3189 writeq(val64, &bar0->mdio_control);
3190 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3191 writeq(val64, &bar0->mdio_control);
3192 udelay(100);
3193
3194 val64 = 0x0;
3195 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3196 | MDIO_MMD_DEV_ADDR(mmd_type)
3197 | MDIO_MMS_PRT_ADDR(0x0)
3198 | MDIO_OP(MDIO_OP_READ_TRANS);
3199 writeq(val64, &bar0->mdio_control);
3200 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3201 writeq(val64, &bar0->mdio_control);
3202 udelay(100);
3203
3204}
3205
3206/**
3207 * s2io_mdio_read - Function to write in to MDIO registers
3208 * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
3209 * @addr : address value
3210 * @dev : pointer to net_device structure
3211 * Description:
3212 * This function is used to read values to the MDIO registers
3213 * NONE
3214 */
3215static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
3216{
3217 u64 val64 = 0x0;
3218 u64 rval64 = 0x0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003219 struct s2io_nic *sp = dev->priv;
3220 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003221
3222 /* address transaction */
3223 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3224 | MDIO_MMD_DEV_ADDR(mmd_type)
3225 | MDIO_MMS_PRT_ADDR(0x0);
3226 writeq(val64, &bar0->mdio_control);
3227 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3228 writeq(val64, &bar0->mdio_control);
3229 udelay(100);
3230
3231 /* Data transaction */
3232 val64 = 0x0;
3233 val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
3234 | MDIO_MMD_DEV_ADDR(mmd_type)
3235 | MDIO_MMS_PRT_ADDR(0x0)
3236 | MDIO_OP(MDIO_OP_READ_TRANS);
3237 writeq(val64, &bar0->mdio_control);
3238 val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
3239 writeq(val64, &bar0->mdio_control);
3240 udelay(100);
3241
3242 /* Read the value from regs */
3243 rval64 = readq(&bar0->mdio_control);
3244 rval64 = rval64 & 0xFFFF0000;
3245 rval64 = rval64 >> 16;
3246 return rval64;
3247}
3248/**
3249 * s2io_chk_xpak_counter - Function to check the status of the xpak counters
3250 * @counter : couter value to be updated
3251 * @flag : flag to indicate the status
3252 * @type : counter type
3253 * Description:
3254 * This function is to check the status of the xpak counters value
3255 * NONE
3256 */
3257
3258static void s2io_chk_xpak_counter(u64 *counter, u64 * regs_stat, u32 index, u16 flag, u16 type)
3259{
3260 u64 mask = 0x3;
3261 u64 val64;
3262 int i;
3263 for(i = 0; i <index; i++)
3264 mask = mask << 0x2;
3265
3266 if(flag > 0)
3267 {
3268 *counter = *counter + 1;
3269 val64 = *regs_stat & mask;
3270 val64 = val64 >> (index * 0x2);
3271 val64 = val64 + 1;
3272 if(val64 == 3)
3273 {
3274 switch(type)
3275 {
3276 case 1:
3277 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3278 "service. Excessive temperatures may "
3279 "result in premature transceiver "
3280 "failure \n");
3281 break;
3282 case 2:
3283 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3284 "service Excessive bias currents may "
3285 "indicate imminent laser diode "
3286 "failure \n");
3287 break;
3288 case 3:
3289 DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
3290 "service Excessive laser output "
3291 "power may saturate far-end "
3292 "receiver\n");
3293 break;
3294 default:
3295 DBG_PRINT(ERR_DBG, "Incorrect XPAK Alarm "
3296 "type \n");
3297 }
3298 val64 = 0x0;
3299 }
3300 val64 = val64 << (index * 0x2);
3301 *regs_stat = (*regs_stat & (~mask)) | (val64);
3302
3303 } else {
3304 *regs_stat = *regs_stat & (~mask);
3305 }
3306}
3307
3308/**
3309 * s2io_updt_xpak_counter - Function to update the xpak counters
3310 * @dev : pointer to net_device struct
3311 * Description:
3312 * This function is to upate the status of the xpak counters value
3313 * NONE
3314 */
3315static void s2io_updt_xpak_counter(struct net_device *dev)
3316{
3317 u16 flag = 0x0;
3318 u16 type = 0x0;
3319 u16 val16 = 0x0;
3320 u64 val64 = 0x0;
3321 u64 addr = 0x0;
3322
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003323 struct s2io_nic *sp = dev->priv;
3324 struct stat_block *stat_info = sp->mac_control.stats_info;
Ananda Rajubd1034f2006-04-21 19:20:22 -04003325
3326 /* Check the communication with the MDIO slave */
3327 addr = 0x0000;
3328 val64 = 0x0;
3329 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3330 if((val64 == 0xFFFF) || (val64 == 0x0000))
3331 {
3332 DBG_PRINT(ERR_DBG, "ERR: MDIO slave access failed - "
3333 "Returned %llx\n", (unsigned long long)val64);
3334 return;
3335 }
3336
3337 /* Check for the expecte value of 2040 at PMA address 0x0000 */
3338 if(val64 != 0x2040)
3339 {
3340 DBG_PRINT(ERR_DBG, "Incorrect value at PMA address 0x0000 - ");
3341 DBG_PRINT(ERR_DBG, "Returned: %llx- Expected: 0x2040\n",
3342 (unsigned long long)val64);
3343 return;
3344 }
3345
3346 /* Loading the DOM register to MDIO register */
3347 addr = 0xA100;
3348 s2io_mdio_write(MDIO_MMD_PMA_DEV_ADDR, addr, val16, dev);
3349 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3350
3351 /* Reading the Alarm flags */
3352 addr = 0xA070;
3353 val64 = 0x0;
3354 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3355
3356 flag = CHECKBIT(val64, 0x7);
3357 type = 1;
3358 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_transceiver_temp_high,
3359 &stat_info->xpak_stat.xpak_regs_stat,
3360 0x0, flag, type);
3361
3362 if(CHECKBIT(val64, 0x6))
3363 stat_info->xpak_stat.alarm_transceiver_temp_low++;
3364
3365 flag = CHECKBIT(val64, 0x3);
3366 type = 2;
3367 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_bias_current_high,
3368 &stat_info->xpak_stat.xpak_regs_stat,
3369 0x2, flag, type);
3370
3371 if(CHECKBIT(val64, 0x2))
3372 stat_info->xpak_stat.alarm_laser_bias_current_low++;
3373
3374 flag = CHECKBIT(val64, 0x1);
3375 type = 3;
3376 s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_output_power_high,
3377 &stat_info->xpak_stat.xpak_regs_stat,
3378 0x4, flag, type);
3379
3380 if(CHECKBIT(val64, 0x0))
3381 stat_info->xpak_stat.alarm_laser_output_power_low++;
3382
3383 /* Reading the Warning flags */
3384 addr = 0xA074;
3385 val64 = 0x0;
3386 val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
3387
3388 if(CHECKBIT(val64, 0x7))
3389 stat_info->xpak_stat.warn_transceiver_temp_high++;
3390
3391 if(CHECKBIT(val64, 0x6))
3392 stat_info->xpak_stat.warn_transceiver_temp_low++;
3393
3394 if(CHECKBIT(val64, 0x3))
3395 stat_info->xpak_stat.warn_laser_bias_current_high++;
3396
3397 if(CHECKBIT(val64, 0x2))
3398 stat_info->xpak_stat.warn_laser_bias_current_low++;
3399
3400 if(CHECKBIT(val64, 0x1))
3401 stat_info->xpak_stat.warn_laser_output_power_high++;
3402
3403 if(CHECKBIT(val64, 0x0))
3404 stat_info->xpak_stat.warn_laser_output_power_low++;
3405}
3406
3407/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 * wait_for_cmd_complete - waits for a command to complete.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003409 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003411 * Description: Function that waits for a command to Write into RMAC
3412 * ADDR DATA registers to be completed and returns either success or
3413 * error depending on whether the command was complete or not.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 * Return value:
3415 * SUCCESS on success and FAILURE on failure.
3416 */
3417
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003418static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
3419 int bit_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420{
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003421 int ret = FAILURE, cnt = 0, delay = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 u64 val64;
3423
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003424 if ((bit_state != S2IO_BIT_RESET) && (bit_state != S2IO_BIT_SET))
3425 return FAILURE;
3426
3427 do {
Ananda Rajuc92ca042006-04-21 19:18:03 -04003428 val64 = readq(addr);
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003429 if (bit_state == S2IO_BIT_RESET) {
3430 if (!(val64 & busy_bit)) {
3431 ret = SUCCESS;
3432 break;
3433 }
3434 } else {
3435 if (!(val64 & busy_bit)) {
3436 ret = SUCCESS;
3437 break;
3438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003440
3441 if(in_interrupt())
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003442 mdelay(delay);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003443 else
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003444 msleep(delay);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003445
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05003446 if (++cnt >= 10)
3447 delay = 50;
3448 } while (cnt < 20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 return ret;
3450}
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003451/*
3452 * check_pci_device_id - Checks if the device id is supported
3453 * @id : device id
3454 * Description: Function to check if the pci device id is supported by driver.
3455 * Return value: Actual device id if supported else PCI_ANY_ID
3456 */
3457static u16 check_pci_device_id(u16 id)
3458{
3459 switch (id) {
3460 case PCI_DEVICE_ID_HERC_WIN:
3461 case PCI_DEVICE_ID_HERC_UNI:
3462 return XFRAME_II_DEVICE;
3463 case PCI_DEVICE_ID_S2IO_UNI:
3464 case PCI_DEVICE_ID_S2IO_WIN:
3465 return XFRAME_I_DEVICE;
3466 default:
3467 return PCI_ANY_ID;
3468 }
3469}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003471/**
3472 * s2io_reset - Resets the card.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 * @sp : private member of the device structure.
3474 * Description: Function to Reset the card. This function then also
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003475 * restores the previously saved PCI configuration space registers as
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 * the card reset also resets the configuration space.
3477 * Return value:
3478 * void.
3479 */
3480
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003481static void s2io_reset(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003483 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 u64 val64;
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003485 u16 subid, pci_cmd;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003486 int i;
3487 u16 val16;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003488 unsigned long long up_cnt, down_cnt, up_time, down_time, reset_cnt;
3489 unsigned long long mem_alloc_cnt, mem_free_cnt, watchdog_cnt;
3490
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003491 DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n",
3492 __FUNCTION__, sp->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003494 /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07003495 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003496
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 val64 = SW_RESET_ALL;
3498 writeq(val64, &bar0->sw_reset);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003499 if (strstr(sp->product_name, "CX4")) {
3500 msleep(750);
3501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 msleep(250);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05003503 for (i = 0; i < S2IO_MAX_PCI_CONFIG_SPACE_REINIT; i++) {
3504
3505 /* Restore the PCI state saved during initialization. */
3506 pci_restore_state(sp->pdev);
3507 pci_read_config_word(sp->pdev, 0x2, &val16);
3508 if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
3509 break;
3510 msleep(200);
3511 }
3512
3513 if (check_pci_device_id(val16) == (u16)PCI_ANY_ID) {
3514 DBG_PRINT(ERR_DBG,"%s SW_Reset failed!\n", __FUNCTION__);
3515 }
3516
3517 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, pci_cmd);
3518
3519 s2io_init_pci(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003521 /* Set swapper to enable I/O register access */
3522 s2io_set_swapper(sp);
3523
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08003524 /* restore mac_addr entries */
3525 do_s2io_restore_unicast_mc(sp);
3526
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003527 /* Restore the MSIX table entries from local variables */
3528 restore_xmsi_data(sp);
3529
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003530 /* Clear certain PCI/PCI-X fields after reset */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003531 if (sp->device_type == XFRAME_II_DEVICE) {
Ananda Rajub41477f2006-07-24 19:52:49 -04003532 /* Clear "detected parity error" bit */
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003533 pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003534
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003535 /* Clearing PCIX Ecc status register */
3536 pci_write_config_dword(sp->pdev, 0x68, 0x7C);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003537
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003538 /* Clearing PCI_STATUS error reflected here */
Jiri Slabyb7b5a122007-10-18 23:40:29 -07003539 writeq(s2BIT(62), &bar0->txpic_int_reg);
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07003540 }
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07003541
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003542 /* Reset device statistics maintained by OS */
3543 memset(&sp->stats, 0, sizeof (struct net_device_stats));
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003544
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003545 up_cnt = sp->mac_control.stats_info->sw_stat.link_up_cnt;
3546 down_cnt = sp->mac_control.stats_info->sw_stat.link_down_cnt;
3547 up_time = sp->mac_control.stats_info->sw_stat.link_up_time;
3548 down_time = sp->mac_control.stats_info->sw_stat.link_down_time;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003549 reset_cnt = sp->mac_control.stats_info->sw_stat.soft_reset_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003550 mem_alloc_cnt = sp->mac_control.stats_info->sw_stat.mem_allocated;
3551 mem_free_cnt = sp->mac_control.stats_info->sw_stat.mem_freed;
3552 watchdog_cnt = sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt;
3553 /* save link up/down time/cnt, reset/memory/watchdog cnt */
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003554 memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block));
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003555 /* restore link up/down time/cnt, reset/memory/watchdog cnt */
3556 sp->mac_control.stats_info->sw_stat.link_up_cnt = up_cnt;
3557 sp->mac_control.stats_info->sw_stat.link_down_cnt = down_cnt;
3558 sp->mac_control.stats_info->sw_stat.link_up_time = up_time;
3559 sp->mac_control.stats_info->sw_stat.link_down_time = down_time;
Ramkrishna Vepa363dc362007-03-06 17:01:00 -08003560 sp->mac_control.stats_info->sw_stat.soft_reset_cnt = reset_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003561 sp->mac_control.stats_info->sw_stat.mem_allocated = mem_alloc_cnt;
3562 sp->mac_control.stats_info->sw_stat.mem_freed = mem_free_cnt;
3563 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt = watchdog_cnt;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003564
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 /* SXE-002: Configure link and activity LED to turn it off */
3566 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07003567 if (((subid & 0xFF) >= 0x07) &&
3568 (sp->device_type == XFRAME_I_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 val64 = readq(&bar0->gpio_control);
3570 val64 |= 0x0000800000000000ULL;
3571 writeq(val64, &bar0->gpio_control);
3572 val64 = 0x0411040400000000ULL;
viro@ftp.linux.org.uk509a2672005-09-05 03:25:58 +01003573 writeq(val64, (void __iomem *)bar0 + 0x2700);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 }
3575
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07003576 /*
3577 * Clear spurious ECC interrupts that would have occured on
3578 * XFRAME II cards after reset.
3579 */
3580 if (sp->device_type == XFRAME_II_DEVICE) {
3581 val64 = readq(&bar0->pcc_err_reg);
3582 writeq(val64, &bar0->pcc_err_reg);
3583 }
3584
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 sp->device_enabled_once = FALSE;
3586}
3587
3588/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003589 * s2io_set_swapper - to set the swapper controle on the card
3590 * @sp : private member of the device structure,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 * pointer to the s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003592 * Description: Function to set the swapper control on the card
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 * correctly depending on the 'endianness' of the system.
3594 * Return value:
3595 * SUCCESS on success and FAILURE on failure.
3596 */
3597
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003598static int s2io_set_swapper(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599{
3600 struct net_device *dev = sp->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003601 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 u64 val64, valt, valr;
3603
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003604 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 * Set proper endian settings and verify the same by reading
3606 * the PIF Feed-back register.
3607 */
3608
3609 val64 = readq(&bar0->pif_rd_swapper_fb);
3610 if (val64 != 0x0123456789ABCDEFULL) {
3611 int i = 0;
3612 u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
3613 0x8100008181000081ULL, /* FE=1, SE=0 */
3614 0x4200004242000042ULL, /* FE=0, SE=1 */
3615 0}; /* FE=0, SE=0 */
3616
3617 while(i<4) {
3618 writeq(value[i], &bar0->swapper_ctrl);
3619 val64 = readq(&bar0->pif_rd_swapper_fb);
3620 if (val64 == 0x0123456789ABCDEFULL)
3621 break;
3622 i++;
3623 }
3624 if (i == 4) {
3625 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3626 dev->name);
3627 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3628 (unsigned long long) val64);
3629 return FAILURE;
3630 }
3631 valr = value[i];
3632 } else {
3633 valr = readq(&bar0->swapper_ctrl);
3634 }
3635
3636 valt = 0x0123456789ABCDEFULL;
3637 writeq(valt, &bar0->xmsi_address);
3638 val64 = readq(&bar0->xmsi_address);
3639
3640 if(val64 != valt) {
3641 int i = 0;
3642 u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
3643 0x0081810000818100ULL, /* FE=1, SE=0 */
3644 0x0042420000424200ULL, /* FE=0, SE=1 */
3645 0}; /* FE=0, SE=0 */
3646
3647 while(i<4) {
3648 writeq((value[i] | valr), &bar0->swapper_ctrl);
3649 writeq(valt, &bar0->xmsi_address);
3650 val64 = readq(&bar0->xmsi_address);
3651 if(val64 == valt)
3652 break;
3653 i++;
3654 }
3655 if(i == 4) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003656 unsigned long long x = val64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003658 DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 return FAILURE;
3660 }
3661 }
3662 val64 = readq(&bar0->swapper_ctrl);
3663 val64 &= 0xFFFF000000000000ULL;
3664
3665#ifdef __BIG_ENDIAN
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003666 /*
3667 * The device by default set to a big endian format, so a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 * big endian driver need not set anything.
3669 */
3670 val64 |= (SWAPPER_CTRL_TXP_FE |
3671 SWAPPER_CTRL_TXP_SE |
3672 SWAPPER_CTRL_TXD_R_FE |
3673 SWAPPER_CTRL_TXD_W_FE |
3674 SWAPPER_CTRL_TXF_R_FE |
3675 SWAPPER_CTRL_RXD_R_FE |
3676 SWAPPER_CTRL_RXD_W_FE |
3677 SWAPPER_CTRL_RXF_W_FE |
3678 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07003680 if (sp->config.intr_type == INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003681 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 writeq(val64, &bar0->swapper_ctrl);
3683#else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003684 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 * Initially we enable all bits to make it accessible by the
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003686 * driver, then we selectively enable only those bits that
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 * we want to set.
3688 */
3689 val64 |= (SWAPPER_CTRL_TXP_FE |
3690 SWAPPER_CTRL_TXP_SE |
3691 SWAPPER_CTRL_TXD_R_FE |
3692 SWAPPER_CTRL_TXD_R_SE |
3693 SWAPPER_CTRL_TXD_W_FE |
3694 SWAPPER_CTRL_TXD_W_SE |
3695 SWAPPER_CTRL_TXF_R_FE |
3696 SWAPPER_CTRL_RXD_R_FE |
3697 SWAPPER_CTRL_RXD_R_SE |
3698 SWAPPER_CTRL_RXD_W_FE |
3699 SWAPPER_CTRL_RXD_W_SE |
3700 SWAPPER_CTRL_RXF_W_FE |
3701 SWAPPER_CTRL_XMSI_FE |
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07003703 if (sp->config.intr_type == INTA)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003704 val64 |= SWAPPER_CTRL_XMSI_SE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 writeq(val64, &bar0->swapper_ctrl);
3706#endif
3707 val64 = readq(&bar0->swapper_ctrl);
3708
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003709 /*
3710 * Verifying if endian settings are accurate by reading a
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 * feedback register.
3712 */
3713 val64 = readq(&bar0->pif_rd_swapper_fb);
3714 if (val64 != 0x0123456789ABCDEFULL) {
3715 /* Endian settings are incorrect, calls for another dekko. */
3716 DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
3717 dev->name);
3718 DBG_PRINT(ERR_DBG, "feedback read %llx\n",
3719 (unsigned long long) val64);
3720 return FAILURE;
3721 }
3722
3723 return SUCCESS;
3724}
3725
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003726static int wait_for_msix_trans(struct s2io_nic *nic, int i)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003727{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003728 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003729 u64 val64;
3730 int ret = 0, cnt = 0;
3731
3732 do {
3733 val64 = readq(&bar0->xmsi_access);
Jiri Slabyb7b5a122007-10-18 23:40:29 -07003734 if (!(val64 & s2BIT(15)))
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003735 break;
3736 mdelay(1);
3737 cnt++;
3738 } while(cnt < 5);
3739 if (cnt == 5) {
3740 DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
3741 ret = 1;
3742 }
3743
3744 return ret;
3745}
3746
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003747static void restore_xmsi_data(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003748{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003749 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003750 u64 val64;
3751 int i;
3752
Ananda Raju75c30b12006-07-24 19:55:09 -04003753 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003754 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3755 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
Jiri Slabyb7b5a122007-10-18 23:40:29 -07003756 val64 = (s2BIT(7) | s2BIT(15) | vBIT(i, 26, 6));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003757 writeq(val64, &bar0->xmsi_access);
3758 if (wait_for_msix_trans(nic, i)) {
3759 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3760 continue;
3761 }
3762 }
3763}
3764
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003765static void store_xmsi_data(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003766{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003767 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003768 u64 val64, addr, data;
3769 int i;
3770
3771 /* Store and display */
Ananda Raju75c30b12006-07-24 19:55:09 -04003772 for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
Jiri Slabyb7b5a122007-10-18 23:40:29 -07003773 val64 = (s2BIT(15) | vBIT(i, 26, 6));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003774 writeq(val64, &bar0->xmsi_access);
3775 if (wait_for_msix_trans(nic, i)) {
3776 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3777 continue;
3778 }
3779 addr = readq(&bar0->xmsi_address);
3780 data = readq(&bar0->xmsi_data);
3781 if (addr && data) {
3782 nic->msix_info[i].addr = addr;
3783 nic->msix_info[i].data = data;
3784 }
3785 }
3786}
3787
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003788static int s2io_enable_msi_x(struct s2io_nic *nic)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003789{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003790 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003791 u64 tx_mat, rx_mat;
3792 u16 msi_control; /* Temp variable */
3793 int ret, i, j, msix_indx = 1;
3794
Sivakumar Subramanibd684e42007-09-14 07:28:50 -04003795 nic->entries = kcalloc(MAX_REQUESTED_MSI_X, sizeof(struct msix_entry),
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003796 GFP_KERNEL);
Sivakumar Subramanibd684e42007-09-14 07:28:50 -04003797 if (!nic->entries) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003798 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
3799 __FUNCTION__);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04003800 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003801 return -ENOMEM;
3802 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003803 nic->mac_control.stats_info->sw_stat.mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003804 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003805
3806 nic->s2io_entries =
Sivakumar Subramanibd684e42007-09-14 07:28:50 -04003807 kcalloc(MAX_REQUESTED_MSI_X, sizeof(struct s2io_msix_entry),
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003808 GFP_KERNEL);
Sivakumar Subramanibd684e42007-09-14 07:28:50 -04003809 if (!nic->s2io_entries) {
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003810 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003811 __FUNCTION__);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04003812 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003813 kfree(nic->entries);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003814 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003815 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003816 return -ENOMEM;
3817 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003818 nic->mac_control.stats_info->sw_stat.mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003819 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003820
3821 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3822 nic->entries[i].entry = i;
3823 nic->s2io_entries[i].entry = i;
3824 nic->s2io_entries[i].arg = NULL;
3825 nic->s2io_entries[i].in_use = 0;
3826 }
3827
3828 tx_mat = readq(&bar0->tx_mat0_n[0]);
3829 for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
3830 tx_mat |= TX_MAT_SET(i, msix_indx);
3831 nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
3832 nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
3833 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3834 }
3835 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3836
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003837 rx_mat = readq(&bar0->rx_mat);
3838 for (j = 0; j < nic->config.rx_ring_num; j++, msix_indx++) {
3839 rx_mat |= RX_MAT_SET(j, msix_indx);
3840 nic->s2io_entries[msix_indx].arg
3841 = &nic->mac_control.rings[j];
3842 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3843 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003844 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003845 writeq(rx_mat, &bar0->rx_mat);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003846
Ananda Rajuc92ca042006-04-21 19:18:03 -04003847 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003848 ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
Ananda Rajuc92ca042006-04-21 19:18:03 -04003849 /* We fail init if error or we get less vectors than min required */
3850 if (ret >= (nic->config.tx_fifo_num + nic->config.rx_ring_num + 1)) {
3851 nic->avail_msix_vectors = ret;
3852 ret = pci_enable_msix(nic->pdev, nic->entries, ret);
3853 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003854 if (ret) {
3855 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3856 kfree(nic->entries);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003857 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003858 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003859 kfree(nic->s2io_entries);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04003860 nic->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04003861 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003862 nic->entries = NULL;
3863 nic->s2io_entries = NULL;
Ananda Rajuc92ca042006-04-21 19:18:03 -04003864 nic->avail_msix_vectors = 0;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003865 return -ENOMEM;
3866 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04003867 if (!nic->avail_msix_vectors)
3868 nic->avail_msix_vectors = MAX_REQUESTED_MSI_X;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04003869
3870 /*
3871 * To enable MSI-X, MSI also needs to be enabled, due to a bug
3872 * in the herc NIC. (Temp change, needs to be removed later)
3873 */
3874 pci_read_config_word(nic->pdev, 0x42, &msi_control);
3875 msi_control |= 0x1; /* Enable MSI */
3876 pci_write_config_word(nic->pdev, 0x42, msi_control);
3877
3878 return 0;
3879}
3880
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07003881/* Handle software interrupt used during MSI(X) test */
Adrian Bunk33390a72007-12-11 23:23:06 +01003882static irqreturn_t s2io_test_intr(int irq, void *dev_id)
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07003883{
3884 struct s2io_nic *sp = dev_id;
3885
3886 sp->msi_detected = 1;
3887 wake_up(&sp->msi_wait);
3888
3889 return IRQ_HANDLED;
3890}
3891
3892/* Test interrupt path by forcing a a software IRQ */
Adrian Bunk33390a72007-12-11 23:23:06 +01003893static int s2io_test_msi(struct s2io_nic *sp)
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07003894{
3895 struct pci_dev *pdev = sp->pdev;
3896 struct XENA_dev_config __iomem *bar0 = sp->bar0;
3897 int err;
3898 u64 val64, saved64;
3899
3900 err = request_irq(sp->entries[1].vector, s2io_test_intr, 0,
3901 sp->name, sp);
3902 if (err) {
3903 DBG_PRINT(ERR_DBG, "%s: PCI %s: cannot assign irq %d\n",
3904 sp->dev->name, pci_name(pdev), pdev->irq);
3905 return err;
3906 }
3907
3908 init_waitqueue_head (&sp->msi_wait);
3909 sp->msi_detected = 0;
3910
3911 saved64 = val64 = readq(&bar0->scheduled_int_ctrl);
3912 val64 |= SCHED_INT_CTRL_ONE_SHOT;
3913 val64 |= SCHED_INT_CTRL_TIMER_EN;
3914 val64 |= SCHED_INT_CTRL_INT2MSI(1);
3915 writeq(val64, &bar0->scheduled_int_ctrl);
3916
3917 wait_event_timeout(sp->msi_wait, sp->msi_detected, HZ/10);
3918
3919 if (!sp->msi_detected) {
3920 /* MSI(X) test failed, go back to INTx mode */
Joe Perches24500222007-11-19 17:48:28 -08003921 DBG_PRINT(ERR_DBG, "%s: PCI %s: No interrupt was generated "
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07003922 "using MSI(X) during test\n", sp->dev->name,
3923 pci_name(pdev));
3924
3925 err = -EOPNOTSUPP;
3926 }
3927
3928 free_irq(sp->entries[1].vector, sp);
3929
3930 writeq(saved64, &bar0->scheduled_int_ctrl);
3931
3932 return err;
3933}
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08003934
3935static void remove_msix_isr(struct s2io_nic *sp)
3936{
3937 int i;
3938 u16 msi_control;
3939
3940 for (i = 0; i < MAX_REQUESTED_MSI_X; i++) {
3941 if (sp->s2io_entries[i].in_use ==
3942 MSIX_REGISTERED_SUCCESS) {
3943 int vector = sp->entries[i].vector;
3944 void *arg = sp->s2io_entries[i].arg;
3945 free_irq(vector, arg);
3946 }
3947 }
3948
3949 kfree(sp->entries);
3950 kfree(sp->s2io_entries);
3951 sp->entries = NULL;
3952 sp->s2io_entries = NULL;
3953
3954 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3955 msi_control &= 0xFFFE; /* Disable MSI */
3956 pci_write_config_word(sp->pdev, 0x42, msi_control);
3957
3958 pci_disable_msix(sp->pdev);
3959}
3960
3961static void remove_inta_isr(struct s2io_nic *sp)
3962{
3963 struct net_device *dev = sp->dev;
3964
3965 free_irq(sp->pdev->irq, dev);
3966}
3967
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968/* ********************************************************* *
3969 * Functions defined below concern the OS part of the driver *
3970 * ********************************************************* */
3971
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003972/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 * s2io_open - open entry point of the driver
3974 * @dev : pointer to the device structure.
3975 * Description:
3976 * This function is the open entry point of the driver. It mainly calls a
3977 * function to allocate Rx buffers and inserts them into the buffer
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003978 * descriptors and then enables the Rx part of the NIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 * Return value:
3980 * 0 on success and an appropriate (-)ve integer as defined in errno.h
3981 * file on failure.
3982 */
3983
Adrian Bunkac1f60d2005-11-06 01:46:47 +01003984static int s2io_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05003986 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 int err = 0;
3988
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07003989 /*
3990 * Make sure you have link off by default every time
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 * Nic is initialized
3992 */
3993 netif_carrier_off(dev);
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07003994 sp->last_link_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07003996 if (sp->config.intr_type == MSI_X) {
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07003997 int ret = s2io_enable_msi_x(sp);
3998
3999 if (!ret) {
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07004000 ret = s2io_test_msi(sp);
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07004001 /* rollback MSI-X, will re-enable during add_isr() */
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08004002 remove_msix_isr(sp);
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07004003 }
4004 if (ret) {
4005
4006 DBG_PRINT(ERR_DBG,
4007 "%s: MSI-X requested but failed to enable\n",
4008 dev->name);
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07004009 sp->config.intr_type = INTA;
Sivakumar Subramani8abc4d52007-09-15 13:11:34 -07004010 }
4011 }
4012
Sivakumar Subramanic77dd432007-08-06 05:36:28 -04004013 /* NAPI doesn't work well with MSI(X) */
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07004014 if (sp->config.intr_type != INTA) {
Sivakumar Subramanic77dd432007-08-06 05:36:28 -04004015 if(sp->config.napi)
4016 sp->config.napi = 0;
4017 }
4018
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 /* Initialize H/W and enable interrupts */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004020 err = s2io_card_up(sp);
4021 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
4023 dev->name);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07004024 goto hw_init_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 }
4026
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04004027 if (do_s2io_prog_unicast(dev, dev->dev_addr) == FAILURE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
Ananda Rajue6a8fee2006-07-06 23:58:23 -07004029 s2io_card_down(sp);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004030 err = -ENODEV;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07004031 goto hw_init_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004033 s2io_start_all_tx_queue(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 return 0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004035
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004036hw_init_failed:
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07004037 if (sp->config.intr_type == MSI_X) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004038 if (sp->entries) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004039 kfree(sp->entries);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04004040 sp->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004041 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
4042 }
4043 if (sp->s2io_entries) {
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004044 kfree(sp->s2io_entries);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04004045 sp->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004046 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
4047 }
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004048 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004049 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050}
4051
4052/**
4053 * s2io_close -close entry point of the driver
4054 * @dev : device pointer.
4055 * Description:
4056 * This is the stop entry point of the driver. It needs to undo exactly
4057 * whatever was done by the open entry point,thus it's usually referred to
4058 * as the close function.Among other things this function mainly stops the
4059 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
4060 * Return value:
4061 * 0 on success and an appropriate (-)ve integer as defined in errno.h
4062 * file on failure.
4063 */
4064
Adrian Bunkac1f60d2005-11-06 01:46:47 +01004065static int s2io_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004067 struct s2io_nic *sp = dev->priv;
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004068 struct config_param *config = &sp->config;
4069 u64 tmp64;
4070 int offset;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004071
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05004072 /* Return if the device is already closed *
4073 * Can happen when s2io_card_up failed in change_mtu *
4074 */
4075 if (!is_s2io_card_up(sp))
4076 return 0;
4077
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004078 s2io_stop_all_tx_queue(sp);
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004079 /* delete all populated mac entries */
4080 for (offset = 1; offset < config->max_mc_addr; offset++) {
4081 tmp64 = do_s2io_read_unicast_mc(sp, offset);
4082 if (tmp64 != S2IO_DISABLE_MAC_ENTRY)
4083 do_s2io_delete_unicast_mc(sp, tmp64);
4084 }
4085
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 /* Reset card, kill tasklet and free Tx and Rx buffers. */
Ananda Rajue6a8fee2006-07-06 23:58:23 -07004087 s2io_card_down(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 return 0;
4090}
4091
4092/**
4093 * s2io_xmit - Tx entry point of te driver
4094 * @skb : the socket buffer containing the Tx data.
4095 * @dev : device pointer.
4096 * Description :
4097 * This function is the Tx entry point of the driver. S2IO NIC supports
4098 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
4099 * NOTE: when device cant queue the pkt,just the trans_start variable will
4100 * not be upadted.
4101 * Return value:
4102 * 0 on success & 1 on failure.
4103 */
4104
Adrian Bunkac1f60d2005-11-06 01:46:47 +01004105static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004107 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
4109 register u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004110 struct TxD *txdp;
4111 struct TxFIFO_element __iomem *tx_fifo;
Surjit Reang2fda0962008-01-24 02:08:59 -08004112 unsigned long flags = 0;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004113 u16 vlan_tag = 0;
Surjit Reang2fda0962008-01-24 02:08:59 -08004114 struct fifo_info *fifo = NULL;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004115 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 struct config_param *config;
Ananda Raju75c30b12006-07-24 19:55:09 -04004117 int offload_type;
Veena Parat491abf22007-07-23 02:37:14 -04004118 struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119
4120 mac_control = &sp->mac_control;
4121 config = &sp->config;
4122
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004123 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004124
4125 if (unlikely(skb->len <= 0)) {
4126 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
4127 dev_kfree_skb_any(skb);
4128 return 0;
Surjit Reang2fda0962008-01-24 02:08:59 -08004129 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004130
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004131 if (!is_s2io_card_up(sp)) {
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004132 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 dev->name);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004134 dev_kfree_skb(skb);
4135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 }
4137
4138 queue = 0;
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004139 /* Get Fifo number to Transmit based on vlan priority */
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004140 if (sp->vlgrp && vlan_tx_tag_present(skb))
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004141 vlan_tag = vlan_tx_tag_get(skb);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004142
4143 /* get fifo number based on skb->priority value */
4144 queue = config->fifo_mapping[skb->priority & (MAX_TX_FIFOS - 1)];
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004145
Surjit Reang2fda0962008-01-24 02:08:59 -08004146 fifo = &mac_control->fifos[queue];
4147 spin_lock_irqsave(&fifo->tx_lock, flags);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004148#ifdef CONFIG_NETDEVICES_MULTIQUEUE
4149 if (sp->config.multiq) {
4150 if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
4151 spin_unlock_irqrestore(&fifo->tx_lock, flags);
4152 return NETDEV_TX_BUSY;
4153 }
4154 } else
4155#endif
4156 if (unlikely(fifo->queue_state == FIFO_QUEUE_STOP)) {
4157 if (netif_queue_stopped(dev)) {
4158 spin_unlock_irqrestore(&fifo->tx_lock, flags);
4159 return NETDEV_TX_BUSY;
4160 }
4161 }
4162
Surjit Reang2fda0962008-01-24 02:08:59 -08004163 put_off = (u16) fifo->tx_curr_put_info.offset;
4164 get_off = (u16) fifo->tx_curr_get_info.offset;
4165 txdp = (struct TxD *) fifo->list_info[put_off].list_virt_addr;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004166
Surjit Reang2fda0962008-01-24 02:08:59 -08004167 queue_len = fifo->tx_curr_put_info.fifo_len + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04004169 if (txdp->Host_Control ||
4170 ((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004171 DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004172 s2io_stop_tx_queue(sp, fifo->fifo_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 dev_kfree_skb(skb);
Surjit Reang2fda0962008-01-24 02:08:59 -08004174 spin_unlock_irqrestore(&fifo->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 return 0;
4176 }
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07004177
Ananda Raju75c30b12006-07-24 19:55:09 -04004178 offload_type = s2io_offload_type(skb);
Ananda Raju75c30b12006-07-24 19:55:09 -04004179 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 txdp->Control_1 |= TXD_TCP_LSO_EN;
Ananda Raju75c30b12006-07-24 19:55:09 -04004181 txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 }
Patrick McHardy84fa7932006-08-29 16:44:56 -07004183 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 txdp->Control_2 |=
4185 (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
4186 TXD_TX_CKO_UDP_EN);
4187 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004188 txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
4189 txdp->Control_1 |= TXD_LIST_OWN_XENA;
Surjit Reang2fda0962008-01-24 02:08:59 -08004190 txdp->Control_2 |= TXD_INT_NUMBER(fifo->fifo_no);
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07004191
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004192 if (vlan_tag) {
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07004193 txdp->Control_2 |= TXD_VLAN_ENABLE;
4194 txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
4195 }
4196
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004197 frg_len = skb->len - skb->data_len;
Ananda Raju75c30b12006-07-24 19:55:09 -04004198 if (offload_type == SKB_GSO_UDP) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004199 int ufo_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200
Ananda Raju75c30b12006-07-24 19:55:09 -04004201 ufo_size = s2io_udp_mss(skb);
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004202 ufo_size &= ~7;
4203 txdp->Control_1 |= TXD_UFO_EN;
4204 txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
4205 txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
4206#ifdef __BIG_ENDIAN
Surjit Reang2fda0962008-01-24 02:08:59 -08004207 fifo->ufo_in_band_v[put_off] =
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004208 (u64)skb_shinfo(skb)->ip6_frag_id;
4209#else
Surjit Reang2fda0962008-01-24 02:08:59 -08004210 fifo->ufo_in_band_v[put_off] =
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004211 (u64)skb_shinfo(skb)->ip6_frag_id << 32;
4212#endif
Surjit Reang2fda0962008-01-24 02:08:59 -08004213 txdp->Host_Control = (unsigned long)fifo->ufo_in_band_v;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004214 txdp->Buffer_Pointer = pci_map_single(sp->pdev,
Surjit Reang2fda0962008-01-24 02:08:59 -08004215 fifo->ufo_in_band_v,
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004216 sizeof(u64), PCI_DMA_TODEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04004217 if((txdp->Buffer_Pointer == 0) ||
4218 (txdp->Buffer_Pointer == DMA_ERROR_CODE))
4219 goto pci_map_failed;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004220 txdp++;
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004221 }
4222
4223 txdp->Buffer_Pointer = pci_map_single
4224 (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04004225 if((txdp->Buffer_Pointer == 0) ||
4226 (txdp->Buffer_Pointer == DMA_ERROR_CODE))
4227 goto pci_map_failed;
4228
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004229 txdp->Host_Control = (unsigned long) skb;
4230 txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
Ananda Raju75c30b12006-07-24 19:55:09 -04004231 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004232 txdp->Control_1 |= TXD_UFO_EN;
4233
4234 frg_cnt = skb_shinfo(skb)->nr_frags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 /* For fragmented SKB. */
4236 for (i = 0; i < frg_cnt; i++) {
4237 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07004238 /* A '0' length fragment will be ignored */
4239 if (!frag->size)
4240 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 txdp++;
4242 txdp->Buffer_Pointer = (u64) pci_map_page
4243 (sp->pdev, frag->page, frag->page_offset,
4244 frag->size, PCI_DMA_TODEVICE);
Ananda Rajuefd51b52006-01-19 14:11:54 -05004245 txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
Ananda Raju75c30b12006-07-24 19:55:09 -04004246 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004247 txdp->Control_1 |= TXD_UFO_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 }
4249 txdp->Control_1 |= TXD_GATHER_CODE_LAST;
4250
Ananda Raju75c30b12006-07-24 19:55:09 -04004251 if (offload_type == SKB_GSO_UDP)
Ananda Rajufed5ecc2005-11-14 15:25:08 -05004252 frg_cnt++; /* as Txd0 was used for inband header */
4253
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 tx_fifo = mac_control->tx_FIFO_start[queue];
Surjit Reang2fda0962008-01-24 02:08:59 -08004255 val64 = fifo->list_info[put_off].list_phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 writeq(val64, &tx_fifo->TxDL_Pointer);
4257
4258 val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
4259 TX_FIFO_LAST_LIST);
Ananda Raju75c30b12006-07-24 19:55:09 -04004260 if (offload_type)
4261 val64 |= TX_FIFO_SPECIAL_FUNC;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004262
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 writeq(val64, &tx_fifo->List_Control);
4264
raghavendra.koushik@neterion.com303bcb42005-08-03 12:41:38 -07004265 mmiowb();
4266
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 put_off++;
Surjit Reang2fda0962008-01-24 02:08:59 -08004268 if (put_off == fifo->tx_curr_put_info.fifo_len + 1)
Ananda Raju863c11a2006-04-21 19:03:13 -04004269 put_off = 0;
Surjit Reang2fda0962008-01-24 02:08:59 -08004270 fifo->tx_curr_put_info.offset = put_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271
4272 /* Avoid "put" pointer going beyond "get" pointer */
Ananda Raju863c11a2006-04-21 19:03:13 -04004273 if (((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04004274 sp->mac_control.stats_info->sw_stat.fifo_full_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 DBG_PRINT(TX_DBG,
4276 "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
4277 put_off, get_off);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004278 s2io_stop_tx_queue(sp, fifo->fifo_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04004280 mac_control->stats_info->sw_stat.mem_allocated += skb->truesize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 dev->trans_start = jiffies;
Surjit Reang2fda0962008-01-24 02:08:59 -08004282 spin_unlock_irqrestore(&fifo->tx_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283
4284 return 0;
Veena Parat491abf22007-07-23 02:37:14 -04004285pci_map_failed:
4286 stats->pci_map_fail_cnt++;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004287 s2io_stop_tx_queue(sp, fifo->fifo_no);
Veena Parat491abf22007-07-23 02:37:14 -04004288 stats->mem_freed += skb->truesize;
4289 dev_kfree_skb(skb);
Surjit Reang2fda0962008-01-24 02:08:59 -08004290 spin_unlock_irqrestore(&fifo->tx_lock, flags);
Veena Parat491abf22007-07-23 02:37:14 -04004291 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292}
4293
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07004294static void
4295s2io_alarm_handle(unsigned long data)
4296{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004297 struct s2io_nic *sp = (struct s2io_nic *)data;
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004298 struct net_device *dev = sp->dev;
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07004299
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004300 s2io_handle_errors(dev);
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07004301 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
4302}
4303
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004304static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n)
Ananda Raju75c30b12006-07-24 19:55:09 -04004305{
4306 int rxb_size, level;
4307
4308 if (!sp->lro) {
4309 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
4310 level = rx_buffer_level(sp, rxb_size, rng_n);
4311
4312 if ((level == PANIC) && (!TASKLET_IN_USE)) {
4313 int ret;
4314 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
4315 DBG_PRINT(INTR_DBG, "PANIC levels\n");
4316 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08004317 DBG_PRINT(INFO_DBG, "Out of memory in %s",
Ananda Raju75c30b12006-07-24 19:55:09 -04004318 __FUNCTION__);
4319 clear_bit(0, (&sp->tasklet_status));
4320 return -1;
4321 }
4322 clear_bit(0, (&sp->tasklet_status));
4323 } else if (level == LOW)
4324 tasklet_schedule(&sp->task);
4325
4326 } else if (fill_rx_buffers(sp, rng_n) == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08004327 DBG_PRINT(INFO_DBG, "%s:Out of memory", sp->dev->name);
4328 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
Ananda Raju75c30b12006-07-24 19:55:09 -04004329 }
4330 return 0;
4331}
4332
David Howells7d12e782006-10-05 14:55:46 +01004333static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004334{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004335 struct ring_info *ring = (struct ring_info *)dev_id;
4336 struct s2io_nic *sp = ring->nic;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004337
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004338 if (!is_s2io_card_up(sp))
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004339 return IRQ_HANDLED;
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004340
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004341 rx_intr_handler(ring);
Ananda Raju75c30b12006-07-24 19:55:09 -04004342 s2io_chk_rx_buffers(sp, ring->ring_no);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05004343
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004344 return IRQ_HANDLED;
4345}
4346
David Howells7d12e782006-10-05 14:55:46 +01004347static irqreturn_t s2io_msix_fifo_handle(int irq, void *dev_id)
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004348{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004349 struct fifo_info *fifo = (struct fifo_info *)dev_id;
4350 struct s2io_nic *sp = fifo->nic;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004351
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004352 if (!is_s2io_card_up(sp))
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004353 return IRQ_HANDLED;
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004354
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004355 tx_intr_handler(fifo);
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04004356 return IRQ_HANDLED;
4357}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004358static void s2io_txpic_intr_handle(struct s2io_nic *sp)
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004359{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004360 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004361 u64 val64;
4362
4363 val64 = readq(&bar0->pic_int_status);
4364 if (val64 & PIC_INT_GPIO) {
4365 val64 = readq(&bar0->gpio_int_reg);
4366 if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
4367 (val64 & GPIO_INT_REG_LINK_UP)) {
Ananda Rajuc92ca042006-04-21 19:18:03 -04004368 /*
4369 * This is unstable state so clear both up/down
4370 * interrupt and adapter to re-evaluate the link state.
4371 */
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004372 val64 |= GPIO_INT_REG_LINK_DOWN;
4373 val64 |= GPIO_INT_REG_LINK_UP;
4374 writeq(val64, &bar0->gpio_int_reg);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004375 val64 = readq(&bar0->gpio_int_mask);
4376 val64 &= ~(GPIO_INT_MASK_LINK_UP |
4377 GPIO_INT_MASK_LINK_DOWN);
4378 writeq(val64, &bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004379 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04004380 else if (val64 & GPIO_INT_REG_LINK_UP) {
4381 val64 = readq(&bar0->adapter_status);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004382 /* Enable Adapter */
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004383 val64 = readq(&bar0->adapter_control);
4384 val64 |= ADAPTER_CNTL_EN;
4385 writeq(val64, &bar0->adapter_control);
4386 val64 |= ADAPTER_LED_ON;
4387 writeq(val64, &bar0->adapter_control);
4388 if (!sp->device_enabled_once)
4389 sp->device_enabled_once = 1;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004390
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004391 s2io_link(sp, LINK_UP);
4392 /*
4393 * unmask link down interrupt and mask link-up
4394 * intr
4395 */
4396 val64 = readq(&bar0->gpio_int_mask);
4397 val64 &= ~GPIO_INT_MASK_LINK_DOWN;
4398 val64 |= GPIO_INT_MASK_LINK_UP;
4399 writeq(val64, &bar0->gpio_int_mask);
Ananda Rajuc92ca042006-04-21 19:18:03 -04004400
Ananda Rajuc92ca042006-04-21 19:18:03 -04004401 }else if (val64 & GPIO_INT_REG_LINK_DOWN) {
4402 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004403 s2io_link(sp, LINK_DOWN);
4404 /* Link is down so unmaks link up interrupt */
4405 val64 = readq(&bar0->gpio_int_mask);
4406 val64 &= ~GPIO_INT_MASK_LINK_UP;
4407 val64 |= GPIO_INT_MASK_LINK_DOWN;
4408 writeq(val64, &bar0->gpio_int_mask);
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05004409
4410 /* turn off LED */
4411 val64 = readq(&bar0->adapter_control);
4412 val64 = val64 &(~ADAPTER_LED_ON);
4413 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004414 }
4415 }
Ananda Rajuc92ca042006-04-21 19:18:03 -04004416 val64 = readq(&bar0->gpio_int_mask);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07004417}
4418
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419/**
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004420 * do_s2io_chk_alarm_bit - Check for alarm and incrment the counter
4421 * @value: alarm bits
4422 * @addr: address value
4423 * @cnt: counter variable
4424 * Description: Check for alarm and increment the counter
4425 * Return Value:
4426 * 1 - if alarm bit set
4427 * 0 - if alarm bit is not set
4428 */
Stephen Hemminger43b7c452007-10-05 12:39:21 -07004429static int do_s2io_chk_alarm_bit(u64 value, void __iomem * addr,
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004430 unsigned long long *cnt)
4431{
4432 u64 val64;
4433 val64 = readq(addr);
4434 if ( val64 & value ) {
4435 writeq(val64, addr);
4436 (*cnt)++;
4437 return 1;
4438 }
4439 return 0;
4440
4441}
4442
4443/**
4444 * s2io_handle_errors - Xframe error indication handler
4445 * @nic: device private variable
4446 * Description: Handle alarms such as loss of link, single or
4447 * double ECC errors, critical and serious errors.
4448 * Return Value:
4449 * NONE
4450 */
4451static void s2io_handle_errors(void * dev_id)
4452{
4453 struct net_device *dev = (struct net_device *) dev_id;
4454 struct s2io_nic *sp = dev->priv;
4455 struct XENA_dev_config __iomem *bar0 = sp->bar0;
4456 u64 temp64 = 0,val64=0;
4457 int i = 0;
4458
4459 struct swStat *sw_stat = &sp->mac_control.stats_info->sw_stat;
4460 struct xpakStat *stats = &sp->mac_control.stats_info->xpak_stat;
4461
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004462 if (!is_s2io_card_up(sp))
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004463 return;
4464
4465 if (pci_channel_offline(sp->pdev))
4466 return;
4467
4468 memset(&sw_stat->ring_full_cnt, 0,
4469 sizeof(sw_stat->ring_full_cnt));
4470
4471 /* Handling the XPAK counters update */
4472 if(stats->xpak_timer_count < 72000) {
4473 /* waiting for an hour */
4474 stats->xpak_timer_count++;
4475 } else {
4476 s2io_updt_xpak_counter(dev);
4477 /* reset the count to zero */
4478 stats->xpak_timer_count = 0;
4479 }
4480
4481 /* Handling link status change error Intr */
4482 if (s2io_link_fault_indication(sp) == MAC_RMAC_ERR_TIMER) {
4483 val64 = readq(&bar0->mac_rmac_err_reg);
4484 writeq(val64, &bar0->mac_rmac_err_reg);
4485 if (val64 & RMAC_LINK_STATE_CHANGE_INT)
4486 schedule_work(&sp->set_link_task);
4487 }
4488
4489 /* In case of a serious error, the device will be Reset. */
4490 if (do_s2io_chk_alarm_bit(SERR_SOURCE_ANY, &bar0->serr_source,
4491 &sw_stat->serious_err_cnt))
4492 goto reset;
4493
4494 /* Check for data parity error */
4495 if (do_s2io_chk_alarm_bit(GPIO_INT_REG_DP_ERR_INT, &bar0->gpio_int_reg,
4496 &sw_stat->parity_err_cnt))
4497 goto reset;
4498
4499 /* Check for ring full counter */
4500 if (sp->device_type == XFRAME_II_DEVICE) {
4501 val64 = readq(&bar0->ring_bump_counter1);
4502 for (i=0; i<4; i++) {
4503 temp64 = ( val64 & vBIT(0xFFFF,(i*16),16));
4504 temp64 >>= 64 - ((i+1)*16);
4505 sw_stat->ring_full_cnt[i] += temp64;
4506 }
4507
4508 val64 = readq(&bar0->ring_bump_counter2);
4509 for (i=0; i<4; i++) {
4510 temp64 = ( val64 & vBIT(0xFFFF,(i*16),16));
4511 temp64 >>= 64 - ((i+1)*16);
4512 sw_stat->ring_full_cnt[i+4] += temp64;
4513 }
4514 }
4515
4516 val64 = readq(&bar0->txdma_int_status);
4517 /*check for pfc_err*/
4518 if (val64 & TXDMA_PFC_INT) {
4519 if (do_s2io_chk_alarm_bit(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM|
4520 PFC_MISC_0_ERR | PFC_MISC_1_ERR|
4521 PFC_PCIX_ERR, &bar0->pfc_err_reg,
4522 &sw_stat->pfc_err_cnt))
4523 goto reset;
4524 do_s2io_chk_alarm_bit(PFC_ECC_SG_ERR, &bar0->pfc_err_reg,
4525 &sw_stat->pfc_err_cnt);
4526 }
4527
4528 /*check for tda_err*/
4529 if (val64 & TXDMA_TDA_INT) {
4530 if(do_s2io_chk_alarm_bit(TDA_Fn_ECC_DB_ERR | TDA_SM0_ERR_ALARM |
4531 TDA_SM1_ERR_ALARM, &bar0->tda_err_reg,
4532 &sw_stat->tda_err_cnt))
4533 goto reset;
4534 do_s2io_chk_alarm_bit(TDA_Fn_ECC_SG_ERR | TDA_PCIX_ERR,
4535 &bar0->tda_err_reg, &sw_stat->tda_err_cnt);
4536 }
4537 /*check for pcc_err*/
4538 if (val64 & TXDMA_PCC_INT) {
4539 if (do_s2io_chk_alarm_bit(PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM
4540 | PCC_N_SERR | PCC_6_COF_OV_ERR
4541 | PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR
4542 | PCC_7_LSO_OV_ERR | PCC_FB_ECC_DB_ERR
4543 | PCC_TXB_ECC_DB_ERR, &bar0->pcc_err_reg,
4544 &sw_stat->pcc_err_cnt))
4545 goto reset;
4546 do_s2io_chk_alarm_bit(PCC_FB_ECC_SG_ERR | PCC_TXB_ECC_SG_ERR,
4547 &bar0->pcc_err_reg, &sw_stat->pcc_err_cnt);
4548 }
4549
4550 /*check for tti_err*/
4551 if (val64 & TXDMA_TTI_INT) {
4552 if (do_s2io_chk_alarm_bit(TTI_SM_ERR_ALARM, &bar0->tti_err_reg,
4553 &sw_stat->tti_err_cnt))
4554 goto reset;
4555 do_s2io_chk_alarm_bit(TTI_ECC_SG_ERR | TTI_ECC_DB_ERR,
4556 &bar0->tti_err_reg, &sw_stat->tti_err_cnt);
4557 }
4558
4559 /*check for lso_err*/
4560 if (val64 & TXDMA_LSO_INT) {
4561 if (do_s2io_chk_alarm_bit(LSO6_ABORT | LSO7_ABORT
4562 | LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM,
4563 &bar0->lso_err_reg, &sw_stat->lso_err_cnt))
4564 goto reset;
4565 do_s2io_chk_alarm_bit(LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
4566 &bar0->lso_err_reg, &sw_stat->lso_err_cnt);
4567 }
4568
4569 /*check for tpa_err*/
4570 if (val64 & TXDMA_TPA_INT) {
4571 if (do_s2io_chk_alarm_bit(TPA_SM_ERR_ALARM, &bar0->tpa_err_reg,
4572 &sw_stat->tpa_err_cnt))
4573 goto reset;
4574 do_s2io_chk_alarm_bit(TPA_TX_FRM_DROP, &bar0->tpa_err_reg,
4575 &sw_stat->tpa_err_cnt);
4576 }
4577
4578 /*check for sm_err*/
4579 if (val64 & TXDMA_SM_INT) {
4580 if (do_s2io_chk_alarm_bit(SM_SM_ERR_ALARM, &bar0->sm_err_reg,
4581 &sw_stat->sm_err_cnt))
4582 goto reset;
4583 }
4584
4585 val64 = readq(&bar0->mac_int_status);
4586 if (val64 & MAC_INT_STATUS_TMAC_INT) {
4587 if (do_s2io_chk_alarm_bit(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR,
4588 &bar0->mac_tmac_err_reg,
4589 &sw_stat->mac_tmac_err_cnt))
4590 goto reset;
4591 do_s2io_chk_alarm_bit(TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR
4592 | TMAC_DESC_ECC_SG_ERR | TMAC_DESC_ECC_DB_ERR,
4593 &bar0->mac_tmac_err_reg,
4594 &sw_stat->mac_tmac_err_cnt);
4595 }
4596
4597 val64 = readq(&bar0->xgxs_int_status);
4598 if (val64 & XGXS_INT_STATUS_TXGXS) {
4599 if (do_s2io_chk_alarm_bit(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR,
4600 &bar0->xgxs_txgxs_err_reg,
4601 &sw_stat->xgxs_txgxs_err_cnt))
4602 goto reset;
4603 do_s2io_chk_alarm_bit(TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
4604 &bar0->xgxs_txgxs_err_reg,
4605 &sw_stat->xgxs_txgxs_err_cnt);
4606 }
4607
4608 val64 = readq(&bar0->rxdma_int_status);
4609 if (val64 & RXDMA_INT_RC_INT_M) {
4610 if (do_s2io_chk_alarm_bit(RC_PRCn_ECC_DB_ERR | RC_FTC_ECC_DB_ERR
4611 | RC_PRCn_SM_ERR_ALARM |RC_FTC_SM_ERR_ALARM,
4612 &bar0->rc_err_reg, &sw_stat->rc_err_cnt))
4613 goto reset;
4614 do_s2io_chk_alarm_bit(RC_PRCn_ECC_SG_ERR | RC_FTC_ECC_SG_ERR
4615 | RC_RDA_FAIL_WR_Rn, &bar0->rc_err_reg,
4616 &sw_stat->rc_err_cnt);
4617 if (do_s2io_chk_alarm_bit(PRC_PCI_AB_RD_Rn | PRC_PCI_AB_WR_Rn
4618 | PRC_PCI_AB_F_WR_Rn, &bar0->prc_pcix_err_reg,
4619 &sw_stat->prc_pcix_err_cnt))
4620 goto reset;
4621 do_s2io_chk_alarm_bit(PRC_PCI_DP_RD_Rn | PRC_PCI_DP_WR_Rn
4622 | PRC_PCI_DP_F_WR_Rn, &bar0->prc_pcix_err_reg,
4623 &sw_stat->prc_pcix_err_cnt);
4624 }
4625
4626 if (val64 & RXDMA_INT_RPA_INT_M) {
4627 if (do_s2io_chk_alarm_bit(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR,
4628 &bar0->rpa_err_reg, &sw_stat->rpa_err_cnt))
4629 goto reset;
4630 do_s2io_chk_alarm_bit(RPA_ECC_SG_ERR | RPA_ECC_DB_ERR,
4631 &bar0->rpa_err_reg, &sw_stat->rpa_err_cnt);
4632 }
4633
4634 if (val64 & RXDMA_INT_RDA_INT_M) {
4635 if (do_s2io_chk_alarm_bit(RDA_RXDn_ECC_DB_ERR
4636 | RDA_FRM_ECC_DB_N_AERR | RDA_SM1_ERR_ALARM
4637 | RDA_SM0_ERR_ALARM | RDA_RXD_ECC_DB_SERR,
4638 &bar0->rda_err_reg, &sw_stat->rda_err_cnt))
4639 goto reset;
4640 do_s2io_chk_alarm_bit(RDA_RXDn_ECC_SG_ERR | RDA_FRM_ECC_SG_ERR
4641 | RDA_MISC_ERR | RDA_PCIX_ERR,
4642 &bar0->rda_err_reg, &sw_stat->rda_err_cnt);
4643 }
4644
4645 if (val64 & RXDMA_INT_RTI_INT_M) {
4646 if (do_s2io_chk_alarm_bit(RTI_SM_ERR_ALARM, &bar0->rti_err_reg,
4647 &sw_stat->rti_err_cnt))
4648 goto reset;
4649 do_s2io_chk_alarm_bit(RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
4650 &bar0->rti_err_reg, &sw_stat->rti_err_cnt);
4651 }
4652
4653 val64 = readq(&bar0->mac_int_status);
4654 if (val64 & MAC_INT_STATUS_RMAC_INT) {
4655 if (do_s2io_chk_alarm_bit(RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR,
4656 &bar0->mac_rmac_err_reg,
4657 &sw_stat->mac_rmac_err_cnt))
4658 goto reset;
4659 do_s2io_chk_alarm_bit(RMAC_UNUSED_INT|RMAC_SINGLE_ECC_ERR|
4660 RMAC_DOUBLE_ECC_ERR, &bar0->mac_rmac_err_reg,
4661 &sw_stat->mac_rmac_err_cnt);
4662 }
4663
4664 val64 = readq(&bar0->xgxs_int_status);
4665 if (val64 & XGXS_INT_STATUS_RXGXS) {
4666 if (do_s2io_chk_alarm_bit(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR,
4667 &bar0->xgxs_rxgxs_err_reg,
4668 &sw_stat->xgxs_rxgxs_err_cnt))
4669 goto reset;
4670 }
4671
4672 val64 = readq(&bar0->mc_int_status);
4673 if(val64 & MC_INT_STATUS_MC_INT) {
4674 if (do_s2io_chk_alarm_bit(MC_ERR_REG_SM_ERR, &bar0->mc_err_reg,
4675 &sw_stat->mc_err_cnt))
4676 goto reset;
4677
4678 /* Handling Ecc errors */
4679 if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
4680 writeq(val64, &bar0->mc_err_reg);
4681 if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
4682 sw_stat->double_ecc_errs++;
4683 if (sp->device_type != XFRAME_II_DEVICE) {
4684 /*
4685 * Reset XframeI only if critical error
4686 */
4687 if (val64 &
4688 (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
4689 MC_ERR_REG_MIRI_ECC_DB_ERR_1))
4690 goto reset;
4691 }
4692 } else
4693 sw_stat->single_ecc_errs++;
4694 }
4695 }
4696 return;
4697
4698reset:
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05004699 s2io_stop_all_tx_queue(sp);
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07004700 schedule_work(&sp->rst_timer_task);
4701 sw_stat->soft_reset_cnt++;
4702 return;
4703}
4704
4705/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 * s2io_isr - ISR handler of the device .
4707 * @irq: the irq of the device.
4708 * @dev_id: a void pointer to the dev structure of the NIC.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004709 * Description: This function is the ISR handler of the device. It
4710 * identifies the reason for the interrupt and calls the relevant
4711 * service routines. As a contongency measure, this ISR allocates the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 * recv buffers, if their numbers are below the panic value which is
4713 * presently set to 25% of the original number of rcv buffers allocated.
4714 * Return value:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004715 * IRQ_HANDLED: will be returned if IRQ was handled by this routine
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 * IRQ_NONE: will be returned if interrupt is not from our device
4717 */
David Howells7d12e782006-10-05 14:55:46 +01004718static irqreturn_t s2io_isr(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719{
4720 struct net_device *dev = (struct net_device *) dev_id;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004721 struct s2io_nic *sp = dev->priv;
4722 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004723 int i;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004724 u64 reason = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004725 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 struct config_param *config;
4727
Linas Vepstasd796fdb2007-05-14 18:37:30 -05004728 /* Pretend we handled any irq's from a disconnected card */
4729 if (pci_channel_offline(sp->pdev))
4730 return IRQ_NONE;
4731
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004732 if (!is_s2io_card_up(sp))
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004733 return IRQ_NONE;
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004734
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 mac_control = &sp->mac_control;
4736 config = &sp->config;
4737
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004738 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 * Identify the cause for interrupt and call the appropriate
4740 * interrupt handler. Causes for the interrupt could be;
4741 * 1. Rx of packet.
4742 * 2. Tx complete.
4743 * 3. Link down.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 */
4745 reason = readq(&bar0->general_int_status);
4746
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004747 if (unlikely(reason == S2IO_MINUS_ONE) ) {
4748 /* Nothing much can be done. Get out */
4749 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 }
4751
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004752 if (reason & (GEN_INTR_RXTRAFFIC |
4753 GEN_INTR_TXTRAFFIC | GEN_INTR_TXPIC))
4754 {
4755 writeq(S2IO_MINUS_ONE, &bar0->general_int_mask);
4756
4757 if (config->napi) {
4758 if (reason & GEN_INTR_RXTRAFFIC) {
4759 if (likely(netif_rx_schedule_prep(dev,
4760 &sp->napi))) {
4761 __netif_rx_schedule(dev, &sp->napi);
4762 writeq(S2IO_MINUS_ONE,
4763 &bar0->rx_traffic_mask);
4764 } else
4765 writeq(S2IO_MINUS_ONE,
4766 &bar0->rx_traffic_int);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004767 }
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004768 } else {
4769 /*
4770 * rx_traffic_int reg is an R1 register, writing all 1's
4771 * will ensure that the actual interrupt causing bit
4772 * get's cleared and hence a read can be avoided.
4773 */
4774 if (reason & GEN_INTR_RXTRAFFIC)
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004775 writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004776
4777 for (i = 0; i < config->rx_ring_num; i++)
4778 rx_intr_handler(&mac_control->rings[i]);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004779 }
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004780
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004781 /*
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004782 * tx_traffic_int reg is an R1 register, writing all 1's
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05004783 * will ensure that the actual interrupt causing bit get's
4784 * cleared and hence a read can be avoided.
4785 */
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004786 if (reason & GEN_INTR_TXTRAFFIC)
4787 writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05004788
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004789 for (i = 0; i < config->tx_fifo_num; i++)
4790 tx_intr_handler(&mac_control->fifos[i]);
4791
4792 if (reason & GEN_INTR_TXPIC)
4793 s2io_txpic_intr_handle(sp);
4794
4795 /*
4796 * Reallocate the buffers from the interrupt handler itself.
4797 */
4798 if (!config->napi) {
4799 for (i = 0; i < config->rx_ring_num; i++)
4800 s2io_chk_rx_buffers(sp, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 }
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07004802 writeq(sp->general_int_mask, &bar0->general_int_mask);
4803 readl(&bar0->general_int_status);
4804
4805 return IRQ_HANDLED;
4806
4807 }
4808 else if (!reason) {
4809 /* The interrupt was not raised by us */
4810 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 return IRQ_HANDLED;
4814}
4815
4816/**
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004817 * s2io_updt_stats -
4818 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004819static void s2io_updt_stats(struct s2io_nic *sp)
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004820{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004821 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004822 u64 val64;
4823 int cnt = 0;
4824
Sivakumar Subramani92b84432007-09-06 06:51:14 -04004825 if (is_s2io_card_up(sp)) {
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004826 /* Apprx 30us on a 133 MHz bus */
4827 val64 = SET_UPDT_CLICKS(10) |
4828 STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
4829 writeq(val64, &bar0->stat_cfg);
4830 do {
4831 udelay(100);
4832 val64 = readq(&bar0->stat_cfg);
Jiri Slabyb7b5a122007-10-18 23:40:29 -07004833 if (!(val64 & s2BIT(0)))
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004834 break;
4835 cnt++;
4836 if (cnt == 5)
4837 break; /* Updt failed */
4838 } while(1);
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04004839 }
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004840}
4841
4842/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004843 * s2io_get_stats - Updates the device statistics structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 * @dev : pointer to the device structure.
4845 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004846 * This function updates the device statistics structure in the s2io_nic
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847 * structure and returns a pointer to the same.
4848 * Return value:
4849 * pointer to the updated net_device_stats structure.
4850 */
4851
Adrian Bunkac1f60d2005-11-06 01:46:47 +01004852static struct net_device_stats *s2io_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004854 struct s2io_nic *sp = dev->priv;
4855 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 struct config_param *config;
4857
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004858
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 mac_control = &sp->mac_control;
4860 config = &sp->config;
4861
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07004862 /* Configure Stats for immediate updt */
4863 s2io_updt_stats(sp);
4864
4865 sp->stats.tx_packets =
4866 le32_to_cpu(mac_control->stats_info->tmac_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004867 sp->stats.tx_errors =
4868 le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
4869 sp->stats.rx_errors =
Al Viroee705db2006-09-23 01:28:17 +01004870 le64_to_cpu(mac_control->stats_info->rmac_drop_frms);
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004871 sp->stats.multicast =
4872 le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 sp->stats.rx_length_errors =
Al Viroee705db2006-09-23 01:28:17 +01004874 le64_to_cpu(mac_control->stats_info->rmac_long_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875
4876 return (&sp->stats);
4877}
4878
4879/**
4880 * s2io_set_multicast - entry point for multicast address enable/disable.
4881 * @dev : pointer to the device structure
4882 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07004883 * This function is a driver entry point which gets called by the kernel
4884 * whenever multicast addresses must be enabled/disabled. This also gets
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 * called to set/reset promiscuous mode. Depending on the deivce flag, we
4886 * determine, if multicast address must be enabled or if promiscuous mode
4887 * is to be disabled etc.
4888 * Return value:
4889 * void.
4890 */
4891
4892static void s2io_set_multicast(struct net_device *dev)
4893{
4894 int i, j, prev_cnt;
4895 struct dev_mc_list *mclist;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05004896 struct s2io_nic *sp = dev->priv;
4897 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
4899 0xfeffffffffffULL;
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004900 u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, mac_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 void __iomem *add;
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004902 struct config_param *config = &sp->config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903
4904 if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
4905 /* Enable all Multicast addresses */
4906 writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
4907 &bar0->rmac_addr_data0_mem);
4908 writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
4909 &bar0->rmac_addr_data1_mem);
4910 val64 = RMAC_ADDR_CMD_MEM_WE |
4911 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004912 RMAC_ADDR_CMD_MEM_OFFSET(config->max_mc_addr - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 writeq(val64, &bar0->rmac_addr_cmd_mem);
4914 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004915 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004916 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4917 S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918
4919 sp->m_cast_flg = 1;
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004920 sp->all_multi_pos = config->max_mc_addr - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
4922 /* Disable all Multicast addresses */
4923 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
4924 &bar0->rmac_addr_data0_mem);
raghavendra.koushik@neterion.com5e25b9d2005-08-03 12:27:09 -07004925 writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
4926 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 val64 = RMAC_ADDR_CMD_MEM_WE |
4928 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
4929 RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
4930 writeq(val64, &bar0->rmac_addr_cmd_mem);
4931 /* Wait till command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04004932 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05004933 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
4934 S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935
4936 sp->m_cast_flg = 0;
4937 sp->all_multi_pos = 0;
4938 }
4939
4940 if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
4941 /* Put the NIC into promiscuous mode */
4942 add = &bar0->mac_cfg;
4943 val64 = readq(&bar0->mac_cfg);
4944 val64 |= MAC_CFG_RMAC_PROM_ENABLE;
4945
4946 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4947 writel((u32) val64, add);
4948 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4949 writel((u32) (val64 >> 32), (add + 4));
4950
Sivakumar Subramani926930b2007-02-24 01:59:39 -05004951 if (vlan_tag_strip != 1) {
4952 val64 = readq(&bar0->rx_pa_cfg);
4953 val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
4954 writeq(val64, &bar0->rx_pa_cfg);
4955 vlan_strip_flag = 0;
4956 }
4957
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 val64 = readq(&bar0->mac_cfg);
4959 sp->promisc_flg = 1;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004960 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 dev->name);
4962 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
4963 /* Remove the NIC from promiscuous mode */
4964 add = &bar0->mac_cfg;
4965 val64 = readq(&bar0->mac_cfg);
4966 val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
4967
4968 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4969 writel((u32) val64, add);
4970 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
4971 writel((u32) (val64 >> 32), (add + 4));
4972
Sivakumar Subramani926930b2007-02-24 01:59:39 -05004973 if (vlan_tag_strip != 0) {
4974 val64 = readq(&bar0->rx_pa_cfg);
4975 val64 |= RX_PA_CFG_STRIP_VLAN_TAG;
4976 writeq(val64, &bar0->rx_pa_cfg);
4977 vlan_strip_flag = 1;
4978 }
4979
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 val64 = readq(&bar0->mac_cfg);
4981 sp->promisc_flg = 0;
ravinandan.arakali@neterion.com776bd202005-09-06 21:36:56 -07004982 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 dev->name);
4984 }
4985
4986 /* Update individual M_CAST address list */
4987 if ((!sp->m_cast_flg) && dev->mc_count) {
4988 if (dev->mc_count >
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08004989 (config->max_mc_addr - config->max_mac_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
4991 dev->name);
4992 DBG_PRINT(ERR_DBG, "can be added, please enable ");
4993 DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
4994 return;
4995 }
4996
4997 prev_cnt = sp->mc_addr_count;
4998 sp->mc_addr_count = dev->mc_count;
4999
5000 /* Clear out the previous list of Mc in the H/W. */
5001 for (i = 0; i < prev_cnt; i++) {
5002 writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
5003 &bar0->rmac_addr_data0_mem);
5004 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005005 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 val64 = RMAC_ADDR_CMD_MEM_WE |
5007 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
5008 RMAC_ADDR_CMD_MEM_OFFSET
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005009 (config->mc_start_offset + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 writeq(val64, &bar0->rmac_addr_cmd_mem);
5011
5012 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04005013 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05005014 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5015 S2IO_BIT_RESET)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016 DBG_PRINT(ERR_DBG, "%s: Adding ",
5017 dev->name);
5018 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
5019 return;
5020 }
5021 }
5022
5023 /* Create the new Rx filter list and update the same in H/W. */
5024 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
5025 i++, mclist = mclist->next) {
5026 memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
5027 ETH_ALEN);
Jeff Garzika7a80d52006-03-04 12:06:51 -05005028 mac_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 for (j = 0; j < ETH_ALEN; j++) {
5030 mac_addr |= mclist->dmi_addr[j];
5031 mac_addr <<= 8;
5032 }
5033 mac_addr >>= 8;
5034 writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
5035 &bar0->rmac_addr_data0_mem);
5036 writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005037 &bar0->rmac_addr_data1_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 val64 = RMAC_ADDR_CMD_MEM_WE |
5039 RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
5040 RMAC_ADDR_CMD_MEM_OFFSET
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005041 (i + config->mc_start_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 writeq(val64, &bar0->rmac_addr_cmd_mem);
5043
5044 /* Wait for command completes */
Ananda Rajuc92ca042006-04-21 19:18:03 -04005045 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05005046 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5047 S2IO_BIT_RESET)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 DBG_PRINT(ERR_DBG, "%s: Adding ",
5049 dev->name);
5050 DBG_PRINT(ERR_DBG, "Multicasts failed\n");
5051 return;
5052 }
5053 }
5054 }
5055}
5056
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005057/* read from CAM unicast & multicast addresses and store it in
5058 * def_mac_addr structure
5059 */
5060void do_s2io_store_unicast_mc(struct s2io_nic *sp)
5061{
5062 int offset;
5063 u64 mac_addr = 0x0;
5064 struct config_param *config = &sp->config;
5065
5066 /* store unicast & multicast mac addresses */
5067 for (offset = 0; offset < config->max_mc_addr; offset++) {
5068 mac_addr = do_s2io_read_unicast_mc(sp, offset);
5069 /* if read fails disable the entry */
5070 if (mac_addr == FAILURE)
5071 mac_addr = S2IO_DISABLE_MAC_ENTRY;
5072 do_s2io_copy_mac_addr(sp, offset, mac_addr);
5073 }
5074}
5075
5076/* restore unicast & multicast MAC to CAM from def_mac_addr structure */
5077static void do_s2io_restore_unicast_mc(struct s2io_nic *sp)
5078{
5079 int offset;
5080 struct config_param *config = &sp->config;
5081 /* restore unicast mac address */
5082 for (offset = 0; offset < config->max_mac_addr; offset++)
5083 do_s2io_prog_unicast(sp->dev,
5084 sp->def_mac_addr[offset].mac_addr);
5085
5086 /* restore multicast mac address */
5087 for (offset = config->mc_start_offset;
5088 offset < config->max_mc_addr; offset++)
5089 do_s2io_add_mc(sp, sp->def_mac_addr[offset].mac_addr);
5090}
5091
5092/* add a multicast MAC address to CAM */
5093static int do_s2io_add_mc(struct s2io_nic *sp, u8 *addr)
5094{
5095 int i;
5096 u64 mac_addr = 0;
5097 struct config_param *config = &sp->config;
5098
5099 for (i = 0; i < ETH_ALEN; i++) {
5100 mac_addr <<= 8;
5101 mac_addr |= addr[i];
5102 }
5103 if ((0ULL == mac_addr) || (mac_addr == S2IO_DISABLE_MAC_ENTRY))
5104 return SUCCESS;
5105
5106 /* check if the multicast mac already preset in CAM */
5107 for (i = config->mc_start_offset; i < config->max_mc_addr; i++) {
5108 u64 tmp64;
5109 tmp64 = do_s2io_read_unicast_mc(sp, i);
5110 if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
5111 break;
5112
5113 if (tmp64 == mac_addr)
5114 return SUCCESS;
5115 }
5116 if (i == config->max_mc_addr) {
5117 DBG_PRINT(ERR_DBG,
5118 "CAM full no space left for multicast MAC\n");
5119 return FAILURE;
5120 }
5121 /* Update the internal structure with this new mac address */
5122 do_s2io_copy_mac_addr(sp, i, mac_addr);
5123
5124 return (do_s2io_add_mac(sp, mac_addr, i));
5125}
5126
5127/* add MAC address to CAM */
5128static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int off)
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005129{
5130 u64 val64;
5131 struct XENA_dev_config __iomem *bar0 = sp->bar0;
5132
5133 writeq(RMAC_ADDR_DATA0_MEM_ADDR(addr),
5134 &bar0->rmac_addr_data0_mem);
5135
5136 val64 =
5137 RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
5138 RMAC_ADDR_CMD_MEM_OFFSET(off);
5139 writeq(val64, &bar0->rmac_addr_cmd_mem);
5140
5141 /* Wait till command completes */
5142 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
5143 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5144 S2IO_BIT_RESET)) {
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005145 DBG_PRINT(INFO_DBG, "do_s2io_add_mac failed\n");
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005146 return FAILURE;
5147 }
5148 return SUCCESS;
5149}
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005150/* deletes a specified unicast/multicast mac entry from CAM */
5151static int do_s2io_delete_unicast_mc(struct s2io_nic *sp, u64 addr)
5152{
5153 int offset;
5154 u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, tmp64;
5155 struct config_param *config = &sp->config;
5156
5157 for (offset = 1;
5158 offset < config->max_mc_addr; offset++) {
5159 tmp64 = do_s2io_read_unicast_mc(sp, offset);
5160 if (tmp64 == addr) {
5161 /* disable the entry by writing 0xffffffffffffULL */
5162 if (do_s2io_add_mac(sp, dis_addr, offset) == FAILURE)
5163 return FAILURE;
5164 /* store the new mac list from CAM */
5165 do_s2io_store_unicast_mc(sp);
5166 return SUCCESS;
5167 }
5168 }
5169 DBG_PRINT(ERR_DBG, "MAC address 0x%llx not found in CAM\n",
5170 (unsigned long long)addr);
5171 return FAILURE;
5172}
5173
5174/* read mac entries from CAM */
5175static u64 do_s2io_read_unicast_mc(struct s2io_nic *sp, int offset)
5176{
5177 u64 tmp64 = 0xffffffffffff0000ULL, val64;
5178 struct XENA_dev_config __iomem *bar0 = sp->bar0;
5179
5180 /* read mac addr */
5181 val64 =
5182 RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
5183 RMAC_ADDR_CMD_MEM_OFFSET(offset);
5184 writeq(val64, &bar0->rmac_addr_cmd_mem);
5185
5186 /* Wait till command completes */
5187 if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
5188 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
5189 S2IO_BIT_RESET)) {
5190 DBG_PRINT(INFO_DBG, "do_s2io_read_unicast_mc failed\n");
5191 return FAILURE;
5192 }
5193 tmp64 = readq(&bar0->rmac_addr_data0_mem);
5194 return (tmp64 >> 16);
5195}
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005196
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197/**
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005198 * s2io_set_mac_addr driver entry point
5199 */
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005200
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005201static int s2io_set_mac_addr(struct net_device *dev, void *p)
5202{
5203 struct sockaddr *addr = p;
5204
5205 if (!is_valid_ether_addr(addr->sa_data))
5206 return -EINVAL;
5207
5208 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
5209
5210 /* store the MAC address in CAM */
5211 return (do_s2io_prog_unicast(dev, dev->dev_addr));
5212}
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005213/**
5214 * do_s2io_prog_unicast - Programs the Xframe mac address
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 * @dev : pointer to the device structure.
5216 * @addr: a uchar pointer to the new mac address which is to be set.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005217 * Description : This procedure will program the Xframe to receive
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 * frames with new Mac Address
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005219 * Return value: SUCCESS on success and an appropriate (-)ve integer
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 * as defined in errno.h file on failure.
5221 */
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005222
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005223static int do_s2io_prog_unicast(struct net_device *dev, u8 *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005225 struct s2io_nic *sp = dev->priv;
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005226 register u64 mac_addr = 0, perm_addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 int i;
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005228 u64 tmp64;
5229 struct config_param *config = &sp->config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005231 /*
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005232 * Set the new MAC address as the new unicast filter and reflect this
5233 * change on the device address registered with the OS. It will be
5234 * at offset 0.
5235 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 for (i = 0; i < ETH_ALEN; i++) {
5237 mac_addr <<= 8;
5238 mac_addr |= addr[i];
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005239 perm_addr <<= 8;
5240 perm_addr |= sp->def_mac_addr[0].mac_addr[i];
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05005241 }
5242
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04005243 /* check if the dev_addr is different than perm_addr */
5244 if (mac_addr == perm_addr)
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05005245 return SUCCESS;
5246
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005247 /* check if the mac already preset in CAM */
5248 for (i = 1; i < config->max_mac_addr; i++) {
5249 tmp64 = do_s2io_read_unicast_mc(sp, i);
5250 if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
5251 break;
5252
5253 if (tmp64 == mac_addr) {
5254 DBG_PRINT(INFO_DBG,
5255 "MAC addr:0x%llx already present in CAM\n",
5256 (unsigned long long)mac_addr);
5257 return SUCCESS;
5258 }
5259 }
5260 if (i == config->max_mac_addr) {
5261 DBG_PRINT(ERR_DBG, "CAM full no space left for Unicast MAC\n");
5262 return FAILURE;
5263 }
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05005264 /* Update the internal structure with this new mac address */
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08005265 do_s2io_copy_mac_addr(sp, i, mac_addr);
5266 return (do_s2io_add_mac(sp, mac_addr, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267}
5268
5269/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005270 * s2io_ethtool_sset - Sets different link parameters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
5272 * @info: pointer to the structure with parameters given by ethtool to set
5273 * link information.
5274 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005275 * The function sets different link parameters provided by the user onto
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 * the NIC.
5277 * Return value:
5278 * 0 on success.
5279*/
5280
5281static int s2io_ethtool_sset(struct net_device *dev,
5282 struct ethtool_cmd *info)
5283{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005284 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 if ((info->autoneg == AUTONEG_ENABLE) ||
5286 (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
5287 return -EINVAL;
5288 else {
5289 s2io_close(sp->dev);
5290 s2io_open(sp->dev);
5291 }
5292
5293 return 0;
5294}
5295
5296/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005297 * s2io_ethtol_gset - Return link specific information.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 * @sp : private member of the device structure, pointer to the
5299 * s2io_nic structure.
5300 * @info : pointer to the structure with parameters given by ethtool
5301 * to return link information.
5302 * Description:
5303 * Returns link specific information like speed, duplex etc.. to ethtool.
5304 * Return value :
5305 * return 0 on success.
5306 */
5307
5308static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
5309{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005310 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
5312 info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
5313 info->port = PORT_FIBRE;
Sivakumar Subramani1a7eb722007-09-14 07:43:16 -04005314
5315 /* info->transceiver */
5316 info->transceiver = XCVR_EXTERNAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005317
5318 if (netif_carrier_ok(sp->dev)) {
5319 info->speed = 10000;
5320 info->duplex = DUPLEX_FULL;
5321 } else {
5322 info->speed = -1;
5323 info->duplex = -1;
5324 }
5325
5326 info->autoneg = AUTONEG_DISABLE;
5327 return 0;
5328}
5329
5330/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005331 * s2io_ethtool_gdrvinfo - Returns driver specific information.
5332 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333 * s2io_nic structure.
5334 * @info : pointer to the structure with parameters given by ethtool to
5335 * return driver information.
5336 * Description:
5337 * Returns driver specefic information like name, version etc.. to ethtool.
5338 * Return value:
5339 * void
5340 */
5341
5342static void s2io_ethtool_gdrvinfo(struct net_device *dev,
5343 struct ethtool_drvinfo *info)
5344{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005345 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346
John W. Linvilledbc23092005-09-28 17:50:51 -04005347 strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
5348 strncpy(info->version, s2io_driver_version, sizeof(info->version));
5349 strncpy(info->fw_version, "", sizeof(info->fw_version));
5350 strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 info->regdump_len = XENA_REG_SPACE;
5352 info->eedump_len = XENA_EEPROM_SPACE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353}
5354
5355/**
5356 * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005357 * @sp: private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005359 * @regs : pointer to the structure with parameters given by ethtool for
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 * dumping the registers.
5361 * @reg_space: The input argumnet into which all the registers are dumped.
5362 * Description:
5363 * Dumps the entire register space of xFrame NIC into the user given
5364 * buffer area.
5365 * Return value :
5366 * void .
5367*/
5368
5369static void s2io_ethtool_gregs(struct net_device *dev,
5370 struct ethtool_regs *regs, void *space)
5371{
5372 int i;
5373 u64 reg;
5374 u8 *reg_space = (u8 *) space;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005375 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376
5377 regs->len = XENA_REG_SPACE;
5378 regs->version = sp->pdev->subsystem_device;
5379
5380 for (i = 0; i < regs->len; i += 8) {
5381 reg = readq(sp->bar0 + i);
5382 memcpy((reg_space + i), &reg, 8);
5383 }
5384}
5385
5386/**
5387 * s2io_phy_id - timer function that alternates adapter LED.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005388 * @data : address of the private member of the device structure, which
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 * is a pointer to the s2io_nic structure, provided as an u32.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005390 * Description: This is actually the timer function that alternates the
5391 * adapter LED bit of the adapter control bit to set/reset every time on
5392 * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 * once every second.
5394*/
5395static void s2io_phy_id(unsigned long data)
5396{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005397 struct s2io_nic *sp = (struct s2io_nic *) data;
5398 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 u64 val64 = 0;
5400 u16 subid;
5401
5402 subid = sp->pdev->subsystem_device;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005403 if ((sp->device_type == XFRAME_II_DEVICE) ||
5404 ((subid & 0xFF) >= 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 val64 = readq(&bar0->gpio_control);
5406 val64 ^= GPIO_CTRL_GPIO_0;
5407 writeq(val64, &bar0->gpio_control);
5408 } else {
5409 val64 = readq(&bar0->adapter_control);
5410 val64 ^= ADAPTER_LED_ON;
5411 writeq(val64, &bar0->adapter_control);
5412 }
5413
5414 mod_timer(&sp->id_timer, jiffies + HZ / 2);
5415}
5416
5417/**
5418 * s2io_ethtool_idnic - To physically identify the nic on the system.
5419 * @sp : private member of the device structure, which is a pointer to the
5420 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005421 * @id : pointer to the structure with identification parameters given by
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 * ethtool.
5423 * Description: Used to physically identify the NIC on the system.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005424 * The Link LED will blink for a time specified by the user for
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425 * identification.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005426 * NOTE: The Link has to be Up to be able to blink the LED. Hence
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 * identification is possible only if it's link is up.
5428 * Return value:
5429 * int , returns 0 on success
5430 */
5431
5432static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
5433{
5434 u64 val64 = 0, last_gpio_ctrl_val;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005435 struct s2io_nic *sp = dev->priv;
5436 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437 u16 subid;
5438
5439 subid = sp->pdev->subsystem_device;
5440 last_gpio_ctrl_val = readq(&bar0->gpio_control);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005441 if ((sp->device_type == XFRAME_I_DEVICE) &&
5442 ((subid & 0xFF) < 0x07)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443 val64 = readq(&bar0->adapter_control);
5444 if (!(val64 & ADAPTER_CNTL_EN)) {
5445 printk(KERN_ERR
5446 "Adapter Link down, cannot blink LED\n");
5447 return -EFAULT;
5448 }
5449 }
5450 if (sp->id_timer.function == NULL) {
5451 init_timer(&sp->id_timer);
5452 sp->id_timer.function = s2io_phy_id;
5453 sp->id_timer.data = (unsigned long) sp;
5454 }
5455 mod_timer(&sp->id_timer, jiffies);
5456 if (data)
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005457 msleep_interruptible(data * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458 else
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005459 msleep_interruptible(MAX_FLICKER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 del_timer_sync(&sp->id_timer);
5461
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07005462 if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463 writeq(last_gpio_ctrl_val, &bar0->gpio_control);
5464 last_gpio_ctrl_val = readq(&bar0->gpio_control);
5465 }
5466
5467 return 0;
5468}
5469
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005470static void s2io_ethtool_gringparam(struct net_device *dev,
5471 struct ethtool_ringparam *ering)
5472{
5473 struct s2io_nic *sp = dev->priv;
5474 int i,tx_desc_count=0,rx_desc_count=0;
5475
5476 if (sp->rxd_mode == RXD_MODE_1)
5477 ering->rx_max_pending = MAX_RX_DESC_1;
5478 else if (sp->rxd_mode == RXD_MODE_3B)
5479 ering->rx_max_pending = MAX_RX_DESC_2;
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005480
5481 ering->tx_max_pending = MAX_TX_DESC;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04005482 for (i = 0 ; i < sp->config.tx_fifo_num ; i++)
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005483 tx_desc_count += sp->config.tx_cfg[i].fifo_len;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04005484
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005485 DBG_PRINT(INFO_DBG,"\nmax txds : %d\n",sp->config.max_txds);
5486 ering->tx_pending = tx_desc_count;
5487 rx_desc_count = 0;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04005488 for (i = 0 ; i < sp->config.rx_ring_num ; i++)
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005489 rx_desc_count += sp->config.rx_cfg[i].num_rxd;
Veena Paratb6627672007-07-23 02:39:43 -04005490
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04005491 ering->rx_pending = rx_desc_count;
5492
5493 ering->rx_mini_max_pending = 0;
5494 ering->rx_mini_pending = 0;
5495 if(sp->rxd_mode == RXD_MODE_1)
5496 ering->rx_jumbo_max_pending = MAX_RX_DESC_1;
5497 else if (sp->rxd_mode == RXD_MODE_3B)
5498 ering->rx_jumbo_max_pending = MAX_RX_DESC_2;
5499 ering->rx_jumbo_pending = rx_desc_count;
5500}
5501
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502/**
5503 * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005504 * @sp : private member of the device structure, which is a pointer to the
5505 * s2io_nic structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506 * @ep : pointer to the structure with pause parameters given by ethtool.
5507 * Description:
5508 * Returns the Pause frame generation and reception capability of the NIC.
5509 * Return value:
5510 * void
5511 */
5512static void s2io_ethtool_getpause_data(struct net_device *dev,
5513 struct ethtool_pauseparam *ep)
5514{
5515 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005516 struct s2io_nic *sp = dev->priv;
5517 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518
5519 val64 = readq(&bar0->rmac_pause_cfg);
5520 if (val64 & RMAC_PAUSE_GEN_ENABLE)
5521 ep->tx_pause = TRUE;
5522 if (val64 & RMAC_PAUSE_RX_ENABLE)
5523 ep->rx_pause = TRUE;
5524 ep->autoneg = FALSE;
5525}
5526
5527/**
5528 * s2io_ethtool_setpause_data - set/reset pause frame generation.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005529 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530 * s2io_nic structure.
5531 * @ep : pointer to the structure with pause parameters given by ethtool.
5532 * Description:
5533 * It can be used to set or reset Pause frame generation or reception
5534 * support of the NIC.
5535 * Return value:
5536 * int, returns 0 on Success
5537 */
5538
5539static int s2io_ethtool_setpause_data(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005540 struct ethtool_pauseparam *ep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541{
5542 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005543 struct s2io_nic *sp = dev->priv;
5544 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545
5546 val64 = readq(&bar0->rmac_pause_cfg);
5547 if (ep->tx_pause)
5548 val64 |= RMAC_PAUSE_GEN_ENABLE;
5549 else
5550 val64 &= ~RMAC_PAUSE_GEN_ENABLE;
5551 if (ep->rx_pause)
5552 val64 |= RMAC_PAUSE_RX_ENABLE;
5553 else
5554 val64 &= ~RMAC_PAUSE_RX_ENABLE;
5555 writeq(val64, &bar0->rmac_pause_cfg);
5556 return 0;
5557}
5558
5559/**
5560 * read_eeprom - reads 4 bytes of data from user given offset.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005561 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562 * s2io_nic structure.
5563 * @off : offset at which the data must be written
5564 * @data : Its an output parameter where the data read at the given
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005565 * offset is stored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005567 * Will read 4 bytes of data from the user given offset and return the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568 * read data.
5569 * NOTE: Will allow to read only part of the EEPROM visible through the
5570 * I2C bus.
5571 * Return value:
5572 * -1 on failure and 0 on success.
5573 */
5574
5575#define S2IO_DEV_ID 5
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005576static int read_eeprom(struct s2io_nic * sp, int off, u64 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577{
5578 int ret = -1;
5579 u32 exit_cnt = 0;
5580 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005581 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005583 if (sp->device_type == XFRAME_I_DEVICE) {
5584 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
5585 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
5586 I2C_CONTROL_CNTL_START;
5587 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005589 while (exit_cnt < 5) {
5590 val64 = readq(&bar0->i2c_control);
5591 if (I2C_CONTROL_CNTL_END(val64)) {
5592 *data = I2C_CONTROL_GET_DATA(val64);
5593 ret = 0;
5594 break;
5595 }
5596 msleep(50);
5597 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599 }
5600
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005601 if (sp->device_type == XFRAME_II_DEVICE) {
5602 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
Jeff Garzik6aa20a22006-09-13 13:24:59 -04005603 SPI_CONTROL_BYTECNT(0x3) |
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005604 SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
5605 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5606 val64 |= SPI_CONTROL_REQ;
5607 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5608 while (exit_cnt < 5) {
5609 val64 = readq(&bar0->spi_control);
5610 if (val64 & SPI_CONTROL_NACK) {
5611 ret = 1;
5612 break;
5613 } else if (val64 & SPI_CONTROL_DONE) {
5614 *data = readq(&bar0->spi_data);
5615 *data &= 0xffffff;
5616 ret = 0;
5617 break;
5618 }
5619 msleep(50);
5620 exit_cnt++;
5621 }
5622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005623 return ret;
5624}
5625
5626/**
5627 * write_eeprom - actually writes the relevant part of the data value.
5628 * @sp : private member of the device structure, which is a pointer to the
5629 * s2io_nic structure.
5630 * @off : offset at which the data must be written
5631 * @data : The data that is to be written
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005632 * @cnt : Number of bytes of the data that are actually to be written into
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633 * the Eeprom. (max of 3)
5634 * Description:
5635 * Actually writes the relevant part of the data value into the Eeprom
5636 * through the I2C bus.
5637 * Return value:
5638 * 0 on success, -1 on failure.
5639 */
5640
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005641static int write_eeprom(struct s2io_nic * sp, int off, u64 data, int cnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642{
5643 int exit_cnt = 0, ret = -1;
5644 u64 val64;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005645 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005647 if (sp->device_type == XFRAME_I_DEVICE) {
5648 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
5649 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
5650 I2C_CONTROL_CNTL_START;
5651 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005653 while (exit_cnt < 5) {
5654 val64 = readq(&bar0->i2c_control);
5655 if (I2C_CONTROL_CNTL_END(val64)) {
5656 if (!(val64 & I2C_CONTROL_NACK))
5657 ret = 0;
5658 break;
5659 }
5660 msleep(50);
5661 exit_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663 }
5664
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005665 if (sp->device_type == XFRAME_II_DEVICE) {
5666 int write_cnt = (cnt == 8) ? 0 : cnt;
5667 writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
5668
5669 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
Jeff Garzik6aa20a22006-09-13 13:24:59 -04005670 SPI_CONTROL_BYTECNT(write_cnt) |
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005671 SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
5672 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5673 val64 |= SPI_CONTROL_REQ;
5674 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
5675 while (exit_cnt < 5) {
5676 val64 = readq(&bar0->spi_control);
5677 if (val64 & SPI_CONTROL_NACK) {
5678 ret = 1;
5679 break;
5680 } else if (val64 & SPI_CONTROL_DONE) {
5681 ret = 0;
5682 break;
5683 }
5684 msleep(50);
5685 exit_cnt++;
5686 }
5687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 return ret;
5689}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005690static void s2io_vpd_read(struct s2io_nic *nic)
Ananda Raju9dc737a2006-04-21 19:05:41 -04005691{
Ananda Rajub41477f2006-07-24 19:52:49 -04005692 u8 *vpd_data;
5693 u8 data;
Ananda Raju9dc737a2006-04-21 19:05:41 -04005694 int i=0, cnt, fail = 0;
5695 int vpd_addr = 0x80;
5696
5697 if (nic->device_type == XFRAME_II_DEVICE) {
5698 strcpy(nic->product_name, "Xframe II 10GbE network adapter");
5699 vpd_addr = 0x80;
5700 }
5701 else {
5702 strcpy(nic->product_name, "Xframe I 10GbE network adapter");
5703 vpd_addr = 0x50;
5704 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05005705 strcpy(nic->serial_num, "NOT AVAILABLE");
Ananda Raju9dc737a2006-04-21 19:05:41 -04005706
Ananda Rajub41477f2006-07-24 19:52:49 -04005707 vpd_data = kmalloc(256, GFP_KERNEL);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04005708 if (!vpd_data) {
5709 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
Ananda Rajub41477f2006-07-24 19:52:49 -04005710 return;
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04005711 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04005712 nic->mac_control.stats_info->sw_stat.mem_allocated += 256;
Ananda Rajub41477f2006-07-24 19:52:49 -04005713
Ananda Raju9dc737a2006-04-21 19:05:41 -04005714 for (i = 0; i < 256; i +=4 ) {
5715 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
5716 pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
5717 pci_write_config_byte(nic->pdev, (vpd_addr + 3), 0);
5718 for (cnt = 0; cnt <5; cnt++) {
5719 msleep(2);
5720 pci_read_config_byte(nic->pdev, (vpd_addr + 3), &data);
5721 if (data == 0x80)
5722 break;
5723 }
5724 if (cnt >= 5) {
5725 DBG_PRINT(ERR_DBG, "Read of VPD data failed\n");
5726 fail = 1;
5727 break;
5728 }
5729 pci_read_config_dword(nic->pdev, (vpd_addr + 4),
5730 (u32 *)&vpd_data[i]);
5731 }
Sivakumar Subramani19a60522007-01-31 13:30:49 -05005732
5733 if(!fail) {
5734 /* read serial number of adapter */
5735 for (cnt = 0; cnt < 256; cnt++) {
5736 if ((vpd_data[cnt] == 'S') &&
5737 (vpd_data[cnt+1] == 'N') &&
5738 (vpd_data[cnt+2] < VPD_STRING_LEN)) {
5739 memset(nic->serial_num, 0, VPD_STRING_LEN);
5740 memcpy(nic->serial_num, &vpd_data[cnt + 3],
5741 vpd_data[cnt+2]);
5742 break;
5743 }
5744 }
5745 }
5746
5747 if ((!fail) && (vpd_data[1] < VPD_STRING_LEN)) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04005748 memset(nic->product_name, 0, vpd_data[1]);
5749 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
5750 }
Ananda Rajub41477f2006-07-24 19:52:49 -04005751 kfree(vpd_data);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04005752 nic->mac_control.stats_info->sw_stat.mem_freed += 256;
Ananda Raju9dc737a2006-04-21 19:05:41 -04005753}
5754
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755/**
5756 * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
5757 * @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 -07005758 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 * containing all relevant information.
5760 * @data_buf : user defined value to be written into Eeprom.
5761 * Description: Reads the values stored in the Eeprom at given offset
5762 * for a given length. Stores these values int the input argument data
5763 * buffer 'data_buf' and returns these to the caller (ethtool.)
5764 * Return value:
5765 * int 0 on success
5766 */
5767
5768static int s2io_ethtool_geeprom(struct net_device *dev,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005769 struct ethtool_eeprom *eeprom, u8 * data_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770{
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005771 u32 i, valid;
5772 u64 data;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005773 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774
5775 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
5776
5777 if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
5778 eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
5779
5780 for (i = 0; i < eeprom->len; i += 4) {
5781 if (read_eeprom(sp, (eeprom->offset + i), &data)) {
5782 DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
5783 return -EFAULT;
5784 }
5785 valid = INV(data);
5786 memcpy((data_buf + i), &valid, 4);
5787 }
5788 return 0;
5789}
5790
5791/**
5792 * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
5793 * @sp : private member of the device structure, which is a pointer to the
5794 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005795 * @eeprom : pointer to the user level structure provided by ethtool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 * containing all relevant information.
5797 * @data_buf ; user defined value to be written into Eeprom.
5798 * Description:
5799 * Tries to write the user provided value in the Eeprom, at the offset
5800 * given by the user.
5801 * Return value:
5802 * 0 on success, -EFAULT on failure.
5803 */
5804
5805static int s2io_ethtool_seeprom(struct net_device *dev,
5806 struct ethtool_eeprom *eeprom,
5807 u8 * data_buf)
5808{
5809 int len = eeprom->len, cnt = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005810 u64 valid = 0, data;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005811 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812
5813 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
5814 DBG_PRINT(ERR_DBG,
5815 "ETHTOOL_WRITE_EEPROM Err: Magic value ");
5816 DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
5817 eeprom->magic);
5818 return -EFAULT;
5819 }
5820
5821 while (len) {
5822 data = (u32) data_buf[cnt] & 0x000000FF;
5823 if (data) {
5824 valid = (u32) (data << 24);
5825 } else
5826 valid = data;
5827
5828 if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
5829 DBG_PRINT(ERR_DBG,
5830 "ETHTOOL_WRITE_EEPROM Err: Cannot ");
5831 DBG_PRINT(ERR_DBG,
5832 "write into the specified offset\n");
5833 return -EFAULT;
5834 }
5835 cnt++;
5836 len--;
5837 }
5838
5839 return 0;
5840}
5841
5842/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005843 * s2io_register_test - reads and writes into all clock domains.
5844 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 * s2io_nic structure.
5846 * @data : variable that returns the result of each of the test conducted b
5847 * by the driver.
5848 * Description:
5849 * Read and write into all clock domains. The NIC has 3 clock domains,
5850 * see that registers in all the three regions are accessible.
5851 * Return value:
5852 * 0 on success.
5853 */
5854
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005855static int s2io_register_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005857 struct XENA_dev_config __iomem *bar0 = sp->bar0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005858 u64 val64 = 0, exp_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 int fail = 0;
5860
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005861 val64 = readq(&bar0->pif_rd_swapper_fb);
5862 if (val64 != 0x123456789abcdefULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863 fail = 1;
5864 DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
5865 }
5866
5867 val64 = readq(&bar0->rmac_pause_cfg);
5868 if (val64 != 0xc000ffff00000000ULL) {
5869 fail = 1;
5870 DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
5871 }
5872
5873 val64 = readq(&bar0->rx_queue_cfg);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005874 if (sp->device_type == XFRAME_II_DEVICE)
5875 exp_val = 0x0404040404040404ULL;
5876 else
5877 exp_val = 0x0808080808080808ULL;
5878 if (val64 != exp_val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 fail = 1;
5880 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
5881 }
5882
5883 val64 = readq(&bar0->xgxs_efifo_cfg);
5884 if (val64 != 0x000000001923141EULL) {
5885 fail = 1;
5886 DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
5887 }
5888
5889 val64 = 0x5A5A5A5A5A5A5A5AULL;
5890 writeq(val64, &bar0->xmsi_data);
5891 val64 = readq(&bar0->xmsi_data);
5892 if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
5893 fail = 1;
5894 DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
5895 }
5896
5897 val64 = 0xA5A5A5A5A5A5A5A5ULL;
5898 writeq(val64, &bar0->xmsi_data);
5899 val64 = readq(&bar0->xmsi_data);
5900 if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
5901 fail = 1;
5902 DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
5903 }
5904
5905 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005906 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907}
5908
5909/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005910 * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005911 * @sp : private member of the device structure, which is a pointer to the
5912 * s2io_nic structure.
5913 * @data:variable that returns the result of each of the test conducted by
5914 * the driver.
5915 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07005916 * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 * register.
5918 * Return value:
5919 * 0 on success.
5920 */
5921
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05005922static int s2io_eeprom_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923{
5924 int fail = 0;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005925 u64 ret_data, org_4F0, org_7F0;
5926 u8 saved_4F0 = 0, saved_7F0 = 0;
5927 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928
5929 /* Test Write Error at offset 0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005930 /* Note that SPI interface allows write access to all areas
5931 * of EEPROM. Hence doing all negative testing only for Xframe I.
5932 */
5933 if (sp->device_type == XFRAME_I_DEVICE)
5934 if (!write_eeprom(sp, 0, 0, 3))
5935 fail = 1;
5936
5937 /* Save current values at offsets 0x4F0 and 0x7F0 */
5938 if (!read_eeprom(sp, 0x4F0, &org_4F0))
5939 saved_4F0 = 1;
5940 if (!read_eeprom(sp, 0x7F0, &org_7F0))
5941 saved_7F0 = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942
5943 /* Test Write at offset 4f0 */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005944 if (write_eeprom(sp, 0x4F0, 0x012345, 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 fail = 1;
5946 if (read_eeprom(sp, 0x4F0, &ret_data))
5947 fail = 1;
5948
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005949 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08005950 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
5951 "Data written %llx Data read %llx\n",
5952 dev->name, (unsigned long long)0x12345,
5953 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956
5957 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005958 write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959
5960 /* Test Write Request Error at offset 0x7c */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005961 if (sp->device_type == XFRAME_I_DEVICE)
5962 if (!write_eeprom(sp, 0x07C, 0, 3))
5963 fail = 1;
5964
5965 /* Test Write Request at offset 0x7f0 */
5966 if (write_eeprom(sp, 0x7F0, 0x012345, 3))
5967 fail = 1;
5968 if (read_eeprom(sp, 0x7F0, &ret_data))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 fail = 1;
5970
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005971 if (ret_data != 0x012345) {
Andrew Morton26b76252005-12-14 19:25:23 -08005972 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
5973 "Data written %llx Data read %llx\n",
5974 dev->name, (unsigned long long)0x12345,
5975 (unsigned long long)ret_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 fail = 1;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978
5979 /* Reset the EEPROM data go FFFF */
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005980 write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005982 if (sp->device_type == XFRAME_I_DEVICE) {
5983 /* Test Write Error at offset 0x80 */
5984 if (!write_eeprom(sp, 0x080, 0, 3))
5985 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005987 /* Test Write Error at offset 0xfc */
5988 if (!write_eeprom(sp, 0x0FC, 0, 3))
5989 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005991 /* Test Write Error at offset 0x100 */
5992 if (!write_eeprom(sp, 0x100, 0, 3))
5993 fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07005995 /* Test Write Error at offset 4ec */
5996 if (!write_eeprom(sp, 0x4EC, 0, 3))
5997 fail = 1;
5998 }
5999
6000 /* Restore values at offsets 0x4F0 and 0x7F0 */
6001 if (saved_4F0)
6002 write_eeprom(sp, 0x4F0, org_4F0, 3);
6003 if (saved_7F0)
6004 write_eeprom(sp, 0x7F0, org_7F0, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005
6006 *data = fail;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006007 return fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008}
6009
6010/**
6011 * s2io_bist_test - invokes the MemBist test of the card .
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006012 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006014 * @data:variable that returns the result of each of the test conducted by
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 * the driver.
6016 * Description:
6017 * This invokes the MemBist test of the card. We give around
6018 * 2 secs time for the Test to complete. If it's still not complete
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006019 * within this peiod, we consider that the test failed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 * Return value:
6021 * 0 on success and -1 on failure.
6022 */
6023
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006024static int s2io_bist_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025{
6026 u8 bist = 0;
6027 int cnt = 0, ret = -1;
6028
6029 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
6030 bist |= PCI_BIST_START;
6031 pci_write_config_word(sp->pdev, PCI_BIST, bist);
6032
6033 while (cnt < 20) {
6034 pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
6035 if (!(bist & PCI_BIST_START)) {
6036 *data = (bist & PCI_BIST_CODE_MASK);
6037 ret = 0;
6038 break;
6039 }
6040 msleep(100);
6041 cnt++;
6042 }
6043
6044 return ret;
6045}
6046
6047/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006048 * s2io-link_test - verifies the link state of the nic
6049 * @sp ; private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 * s2io_nic structure.
6051 * @data: variable that returns the result of each of the test conducted by
6052 * the driver.
6053 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006054 * The function verifies the link state of the NIC and updates the input
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 * argument 'data' appropriately.
6056 * Return value:
6057 * 0 on success.
6058 */
6059
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006060static int s2io_link_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006062 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 u64 val64;
6064
6065 val64 = readq(&bar0->adapter_status);
Ananda Rajuc92ca042006-04-21 19:18:03 -04006066 if(!(LINK_IS_UP(val64)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 *data = 1;
Ananda Rajuc92ca042006-04-21 19:18:03 -04006068 else
6069 *data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070
Ananda Rajub41477f2006-07-24 19:52:49 -04006071 return *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072}
6073
6074/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006075 * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
6076 * @sp - private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 * s2io_nic structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006078 * @data - variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079 * conducted by the driver.
6080 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006081 * This is one of the offline test that tests the read and write
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 * access to the RldRam chip on the NIC.
6083 * Return value:
6084 * 0 on success.
6085 */
6086
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006087static int s2io_rldram_test(struct s2io_nic * sp, uint64_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006089 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 u64 val64;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006091 int cnt, iteration = 0, test_fail = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092
6093 val64 = readq(&bar0->adapter_control);
6094 val64 &= ~ADAPTER_ECC_EN;
6095 writeq(val64, &bar0->adapter_control);
6096
6097 val64 = readq(&bar0->mc_rldram_test_ctrl);
6098 val64 |= MC_RLDRAM_TEST_MODE;
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006099 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100
6101 val64 = readq(&bar0->mc_rldram_mrs);
6102 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
6103 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
6104
6105 val64 |= MC_RLDRAM_MRS_ENABLE;
6106 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
6107
6108 while (iteration < 2) {
6109 val64 = 0x55555555aaaa0000ULL;
6110 if (iteration == 1) {
6111 val64 ^= 0xFFFFFFFFFFFF0000ULL;
6112 }
6113 writeq(val64, &bar0->mc_rldram_test_d0);
6114
6115 val64 = 0xaaaa5a5555550000ULL;
6116 if (iteration == 1) {
6117 val64 ^= 0xFFFFFFFFFFFF0000ULL;
6118 }
6119 writeq(val64, &bar0->mc_rldram_test_d1);
6120
6121 val64 = 0x55aaaaaaaa5a0000ULL;
6122 if (iteration == 1) {
6123 val64 ^= 0xFFFFFFFFFFFF0000ULL;
6124 }
6125 writeq(val64, &bar0->mc_rldram_test_d2);
6126
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006127 val64 = (u64) (0x0000003ffffe0100ULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 writeq(val64, &bar0->mc_rldram_test_add);
6129
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006130 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
6131 MC_RLDRAM_TEST_GO;
6132 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133
6134 for (cnt = 0; cnt < 5; cnt++) {
6135 val64 = readq(&bar0->mc_rldram_test_ctrl);
6136 if (val64 & MC_RLDRAM_TEST_DONE)
6137 break;
6138 msleep(200);
6139 }
6140
6141 if (cnt == 5)
6142 break;
6143
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006144 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
6145 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146
6147 for (cnt = 0; cnt < 5; cnt++) {
6148 val64 = readq(&bar0->mc_rldram_test_ctrl);
6149 if (val64 & MC_RLDRAM_TEST_DONE)
6150 break;
6151 msleep(500);
6152 }
6153
6154 if (cnt == 5)
6155 break;
6156
6157 val64 = readq(&bar0->mc_rldram_test_ctrl);
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006158 if (!(val64 & MC_RLDRAM_TEST_PASS))
6159 test_fail = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160
6161 iteration++;
6162 }
6163
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006164 *data = test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165
ravinandan.arakali@neterion.comad4ebed2005-10-17 18:26:20 -07006166 /* Bring the adapter out of test mode */
6167 SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
6168
6169 return test_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170}
6171
6172/**
6173 * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
6174 * @sp : private member of the device structure, which is a pointer to the
6175 * s2io_nic structure.
6176 * @ethtest : pointer to a ethtool command specific structure that will be
6177 * returned to the user.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006178 * @data : variable that returns the result of each of the test
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 * conducted by the driver.
6180 * Description:
6181 * This function conducts 6 tests ( 4 offline and 2 online) to determine
6182 * the health of the card.
6183 * Return value:
6184 * void
6185 */
6186
6187static void s2io_ethtool_test(struct net_device *dev,
6188 struct ethtool_test *ethtest,
6189 uint64_t * data)
6190{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006191 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 int orig_state = netif_running(sp->dev);
6193
6194 if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
6195 /* Offline Tests. */
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006196 if (orig_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 s2io_close(sp->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198
6199 if (s2io_register_test(sp, &data[0]))
6200 ethtest->flags |= ETH_TEST_FL_FAILED;
6201
6202 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203
6204 if (s2io_rldram_test(sp, &data[3]))
6205 ethtest->flags |= ETH_TEST_FL_FAILED;
6206
6207 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208
6209 if (s2io_eeprom_test(sp, &data[1]))
6210 ethtest->flags |= ETH_TEST_FL_FAILED;
6211
6212 if (s2io_bist_test(sp, &data[4]))
6213 ethtest->flags |= ETH_TEST_FL_FAILED;
6214
6215 if (orig_state)
6216 s2io_open(sp->dev);
6217
6218 data[2] = 0;
6219 } else {
6220 /* Online Tests. */
6221 if (!orig_state) {
6222 DBG_PRINT(ERR_DBG,
6223 "%s: is not up, cannot run test\n",
6224 dev->name);
6225 data[0] = -1;
6226 data[1] = -1;
6227 data[2] = -1;
6228 data[3] = -1;
6229 data[4] = -1;
6230 }
6231
6232 if (s2io_link_test(sp, &data[2]))
6233 ethtest->flags |= ETH_TEST_FL_FAILED;
6234
6235 data[0] = 0;
6236 data[1] = 0;
6237 data[3] = 0;
6238 data[4] = 0;
6239 }
6240}
6241
6242static void s2io_get_ethtool_stats(struct net_device *dev,
6243 struct ethtool_stats *estats,
6244 u64 * tmp_stats)
6245{
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07006246 int i = 0, k;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006247 struct s2io_nic *sp = dev->priv;
6248 struct stat_block *stat_info = sp->mac_control.stats_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006250 s2io_updt_stats(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006251 tmp_stats[i++] =
6252 (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
6253 le32_to_cpu(stat_info->tmac_frms);
6254 tmp_stats[i++] =
6255 (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
6256 le32_to_cpu(stat_info->tmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006258 tmp_stats[i++] =
6259 (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
6260 le32_to_cpu(stat_info->tmac_mcst_frms);
6261 tmp_stats[i++] =
6262 (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
6263 le32_to_cpu(stat_info->tmac_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006265 tmp_stats[i++] =
6266 (u64)le32_to_cpu(stat_info->tmac_ttl_octets_oflow) << 32 |
6267 le32_to_cpu(stat_info->tmac_ttl_octets);
6268 tmp_stats[i++] =
6269 (u64)le32_to_cpu(stat_info->tmac_ucst_frms_oflow) << 32 |
6270 le32_to_cpu(stat_info->tmac_ucst_frms);
6271 tmp_stats[i++] =
6272 (u64)le32_to_cpu(stat_info->tmac_nucst_frms_oflow) << 32 |
6273 le32_to_cpu(stat_info->tmac_nucst_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006274 tmp_stats[i++] =
6275 (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
6276 le32_to_cpu(stat_info->tmac_any_err_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006277 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_ttl_less_fb_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006279 tmp_stats[i++] =
6280 (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
6281 le32_to_cpu(stat_info->tmac_vld_ip);
6282 tmp_stats[i++] =
6283 (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
6284 le32_to_cpu(stat_info->tmac_drop_ip);
6285 tmp_stats[i++] =
6286 (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
6287 le32_to_cpu(stat_info->tmac_icmp);
6288 tmp_stats[i++] =
6289 (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
6290 le32_to_cpu(stat_info->tmac_rst_tcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006292 tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
6293 le32_to_cpu(stat_info->tmac_udp);
6294 tmp_stats[i++] =
6295 (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
6296 le32_to_cpu(stat_info->rmac_vld_frms);
6297 tmp_stats[i++] =
6298 (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
6299 le32_to_cpu(stat_info->rmac_data_octets);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
6301 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006302 tmp_stats[i++] =
6303 (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
6304 le32_to_cpu(stat_info->rmac_vld_mcst_frms);
6305 tmp_stats[i++] =
6306 (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
6307 le32_to_cpu(stat_info->rmac_vld_bcst_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006309 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_out_rng_len_err_frms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
6311 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006312 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_unsup_ctrl_frms);
6313 tmp_stats[i++] =
6314 (u64)le32_to_cpu(stat_info->rmac_ttl_octets_oflow) << 32 |
6315 le32_to_cpu(stat_info->rmac_ttl_octets);
6316 tmp_stats[i++] =
6317 (u64)le32_to_cpu(stat_info->rmac_accepted_ucst_frms_oflow)
6318 << 32 | le32_to_cpu(stat_info->rmac_accepted_ucst_frms);
6319 tmp_stats[i++] =
6320 (u64)le32_to_cpu(stat_info->rmac_accepted_nucst_frms_oflow)
6321 << 32 | le32_to_cpu(stat_info->rmac_accepted_nucst_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006322 tmp_stats[i++] =
6323 (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
6324 le32_to_cpu(stat_info->rmac_discarded_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006325 tmp_stats[i++] =
6326 (u64)le32_to_cpu(stat_info->rmac_drop_events_oflow)
6327 << 32 | le32_to_cpu(stat_info->rmac_drop_events);
6328 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_less_fb_octets);
6329 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_frms);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006330 tmp_stats[i++] =
6331 (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
6332 le32_to_cpu(stat_info->rmac_usized_frms);
6333 tmp_stats[i++] =
6334 (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
6335 le32_to_cpu(stat_info->rmac_osized_frms);
6336 tmp_stats[i++] =
6337 (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
6338 le32_to_cpu(stat_info->rmac_frag_frms);
6339 tmp_stats[i++] =
6340 (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
6341 le32_to_cpu(stat_info->rmac_jabber_frms);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006342 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_64_frms);
6343 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_65_127_frms);
6344 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_128_255_frms);
6345 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_256_511_frms);
6346 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_512_1023_frms);
6347 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_1024_1518_frms);
6348 tmp_stats[i++] =
6349 (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006350 le32_to_cpu(stat_info->rmac_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
6352 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006353 tmp_stats[i++] =
6354 (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006355 le32_to_cpu(stat_info->rmac_drop_ip);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006356 tmp_stats[i++] =
6357 (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006358 le32_to_cpu(stat_info->rmac_icmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006360 tmp_stats[i++] =
6361 (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006362 le32_to_cpu(stat_info->rmac_udp);
6363 tmp_stats[i++] =
6364 (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
6365 le32_to_cpu(stat_info->rmac_err_drp_udp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006366 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_err_sym);
6367 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q0);
6368 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q1);
6369 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q2);
6370 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q3);
6371 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q4);
6372 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q5);
6373 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q6);
6374 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q7);
6375 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q0);
6376 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q1);
6377 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q2);
6378 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q3);
6379 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q4);
6380 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q5);
6381 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q6);
6382 tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q7);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006383 tmp_stats[i++] =
6384 (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
6385 le32_to_cpu(stat_info->rmac_pause_cnt);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006386 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_data_err_cnt);
6387 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_ctrl_err_cnt);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07006388 tmp_stats[i++] =
6389 (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
6390 le32_to_cpu(stat_info->rmac_accepted_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
Ananda Rajubd1034f2006-04-21 19:20:22 -04006392 tmp_stats[i++] = le32_to_cpu(stat_info->rd_req_cnt);
6393 tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_cnt);
6394 tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_rtry_cnt);
6395 tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_cnt);
6396 tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_rd_ack_cnt);
6397 tmp_stats[i++] = le32_to_cpu(stat_info->wr_req_cnt);
6398 tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_cnt);
6399 tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_rtry_cnt);
6400 tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_cnt);
6401 tmp_stats[i++] = le32_to_cpu(stat_info->wr_disc_cnt);
6402 tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_wr_ack_cnt);
6403 tmp_stats[i++] = le32_to_cpu(stat_info->txp_wr_cnt);
6404 tmp_stats[i++] = le32_to_cpu(stat_info->txd_rd_cnt);
6405 tmp_stats[i++] = le32_to_cpu(stat_info->txd_wr_cnt);
6406 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_rd_cnt);
6407 tmp_stats[i++] = le32_to_cpu(stat_info->rxd_wr_cnt);
6408 tmp_stats[i++] = le32_to_cpu(stat_info->txf_rd_cnt);
6409 tmp_stats[i++] = le32_to_cpu(stat_info->rxf_wr_cnt);
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05006410
6411 /* Enhanced statistics exist only for Hercules */
6412 if(sp->device_type == XFRAME_II_DEVICE) {
6413 tmp_stats[i++] =
6414 le64_to_cpu(stat_info->rmac_ttl_1519_4095_frms);
6415 tmp_stats[i++] =
6416 le64_to_cpu(stat_info->rmac_ttl_4096_8191_frms);
6417 tmp_stats[i++] =
6418 le64_to_cpu(stat_info->rmac_ttl_8192_max_frms);
6419 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_gt_max_frms);
6420 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_osized_alt_frms);
6421 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_jabber_alt_frms);
6422 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_gt_max_alt_frms);
6423 tmp_stats[i++] = le64_to_cpu(stat_info->rmac_vlan_frms);
6424 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_len_discard);
6425 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_fcs_discard);
6426 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pf_discard);
6427 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_da_discard);
6428 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_red_discard);
6429 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_rts_discard);
6430 tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ingm_full_discard);
6431 tmp_stats[i++] = le32_to_cpu(stat_info->link_fault_cnt);
6432 }
6433
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07006434 tmp_stats[i++] = 0;
6435 tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
6436 tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
Ananda Rajubd1034f2006-04-21 19:20:22 -04006437 tmp_stats[i++] = stat_info->sw_stat.parity_err_cnt;
6438 tmp_stats[i++] = stat_info->sw_stat.serious_err_cnt;
6439 tmp_stats[i++] = stat_info->sw_stat.soft_reset_cnt;
6440 tmp_stats[i++] = stat_info->sw_stat.fifo_full_cnt;
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07006441 for (k = 0; k < MAX_RX_RINGS; k++)
6442 tmp_stats[i++] = stat_info->sw_stat.ring_full_cnt[k];
Ananda Rajubd1034f2006-04-21 19:20:22 -04006443 tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_high;
6444 tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_low;
6445 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_high;
6446 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_low;
6447 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_high;
6448 tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_low;
6449 tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_high;
6450 tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_low;
6451 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_high;
6452 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_low;
6453 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_high;
6454 tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_low;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05006455 tmp_stats[i++] = stat_info->sw_stat.clubbed_frms_cnt;
6456 tmp_stats[i++] = stat_info->sw_stat.sending_both;
6457 tmp_stats[i++] = stat_info->sw_stat.outof_sequence_pkts;
6458 tmp_stats[i++] = stat_info->sw_stat.flush_max_pkts;
Andrew Mortonfe931392006-02-03 01:45:12 -08006459 if (stat_info->sw_stat.num_aggregations) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04006460 u64 tmp = stat_info->sw_stat.sum_avg_pkts_aggregated;
6461 int count = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04006462 /*
Ananda Rajubd1034f2006-04-21 19:20:22 -04006463 * Since 64-bit divide does not work on all platforms,
6464 * do repeated subtraction.
6465 */
6466 while (tmp >= stat_info->sw_stat.num_aggregations) {
6467 tmp -= stat_info->sw_stat.num_aggregations;
6468 count++;
6469 }
6470 tmp_stats[i++] = count;
Andrew Mortonfe931392006-02-03 01:45:12 -08006471 }
Ananda Rajubd1034f2006-04-21 19:20:22 -04006472 else
6473 tmp_stats[i++] = 0;
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006474 tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt;
Veena Parat491abf22007-07-23 02:37:14 -04006475 tmp_stats[i++] = stat_info->sw_stat.pci_map_fail_cnt;
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006476 tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006477 tmp_stats[i++] = stat_info->sw_stat.mem_allocated;
6478 tmp_stats[i++] = stat_info->sw_stat.mem_freed;
6479 tmp_stats[i++] = stat_info->sw_stat.link_up_cnt;
6480 tmp_stats[i++] = stat_info->sw_stat.link_down_cnt;
6481 tmp_stats[i++] = stat_info->sw_stat.link_up_time;
6482 tmp_stats[i++] = stat_info->sw_stat.link_down_time;
6483
6484 tmp_stats[i++] = stat_info->sw_stat.tx_buf_abort_cnt;
6485 tmp_stats[i++] = stat_info->sw_stat.tx_desc_abort_cnt;
6486 tmp_stats[i++] = stat_info->sw_stat.tx_parity_err_cnt;
6487 tmp_stats[i++] = stat_info->sw_stat.tx_link_loss_cnt;
6488 tmp_stats[i++] = stat_info->sw_stat.tx_list_proc_err_cnt;
6489
6490 tmp_stats[i++] = stat_info->sw_stat.rx_parity_err_cnt;
6491 tmp_stats[i++] = stat_info->sw_stat.rx_abort_cnt;
6492 tmp_stats[i++] = stat_info->sw_stat.rx_parity_abort_cnt;
6493 tmp_stats[i++] = stat_info->sw_stat.rx_rda_fail_cnt;
6494 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_prot_cnt;
6495 tmp_stats[i++] = stat_info->sw_stat.rx_fcs_err_cnt;
6496 tmp_stats[i++] = stat_info->sw_stat.rx_buf_size_err_cnt;
6497 tmp_stats[i++] = stat_info->sw_stat.rx_rxd_corrupt_cnt;
6498 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_err_cnt;
Sivakumar Subramani8116f3c2007-09-17 13:05:35 -07006499 tmp_stats[i++] = stat_info->sw_stat.tda_err_cnt;
6500 tmp_stats[i++] = stat_info->sw_stat.pfc_err_cnt;
6501 tmp_stats[i++] = stat_info->sw_stat.pcc_err_cnt;
6502 tmp_stats[i++] = stat_info->sw_stat.tti_err_cnt;
6503 tmp_stats[i++] = stat_info->sw_stat.tpa_err_cnt;
6504 tmp_stats[i++] = stat_info->sw_stat.sm_err_cnt;
6505 tmp_stats[i++] = stat_info->sw_stat.lso_err_cnt;
6506 tmp_stats[i++] = stat_info->sw_stat.mac_tmac_err_cnt;
6507 tmp_stats[i++] = stat_info->sw_stat.mac_rmac_err_cnt;
6508 tmp_stats[i++] = stat_info->sw_stat.xgxs_txgxs_err_cnt;
6509 tmp_stats[i++] = stat_info->sw_stat.xgxs_rxgxs_err_cnt;
6510 tmp_stats[i++] = stat_info->sw_stat.rc_err_cnt;
6511 tmp_stats[i++] = stat_info->sw_stat.prc_pcix_err_cnt;
6512 tmp_stats[i++] = stat_info->sw_stat.rpa_err_cnt;
6513 tmp_stats[i++] = stat_info->sw_stat.rda_err_cnt;
6514 tmp_stats[i++] = stat_info->sw_stat.rti_err_cnt;
6515 tmp_stats[i++] = stat_info->sw_stat.mc_err_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516}
6517
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006518static int s2io_ethtool_get_regs_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519{
6520 return (XENA_REG_SPACE);
6521}
6522
6523
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006524static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006526 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527
6528 return (sp->rx_csum);
6529}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006530
6531static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006533 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534
6535 if (data)
6536 sp->rx_csum = 1;
6537 else
6538 sp->rx_csum = 0;
6539
6540 return 0;
6541}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006542
6543static int s2io_get_eeprom_len(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544{
6545 return (XENA_EEPROM_SPACE);
6546}
6547
Jeff Garzikb9f2c042007-10-03 18:07:32 -07006548static int s2io_get_sset_count(struct net_device *dev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07006550 struct s2io_nic *sp = dev->priv;
6551
6552 switch (sset) {
6553 case ETH_SS_TEST:
6554 return S2IO_TEST_LEN;
6555 case ETH_SS_STATS:
6556 switch(sp->device_type) {
6557 case XFRAME_I_DEVICE:
6558 return XFRAME_I_STAT_LEN;
6559 case XFRAME_II_DEVICE:
6560 return XFRAME_II_STAT_LEN;
6561 default:
6562 return 0;
6563 }
6564 default:
6565 return -EOPNOTSUPP;
6566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567}
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006568
6569static void s2io_ethtool_get_strings(struct net_device *dev,
6570 u32 stringset, u8 * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571{
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05006572 int stat_size = 0;
6573 struct s2io_nic *sp = dev->priv;
6574
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 switch (stringset) {
6576 case ETH_SS_TEST:
6577 memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
6578 break;
6579 case ETH_SS_STATS:
Sivakumar Subramanifa1f0cb2007-02-24 02:03:22 -05006580 stat_size = sizeof(ethtool_xena_stats_keys);
6581 memcpy(data, &ethtool_xena_stats_keys,stat_size);
6582 if(sp->device_type == XFRAME_II_DEVICE) {
6583 memcpy(data + stat_size,
6584 &ethtool_enhanced_stats_keys,
6585 sizeof(ethtool_enhanced_stats_keys));
6586 stat_size += sizeof(ethtool_enhanced_stats_keys);
6587 }
6588
6589 memcpy(data + stat_size, &ethtool_driver_stats_keys,
6590 sizeof(ethtool_driver_stats_keys));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 }
6592}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006594static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595{
6596 if (data)
6597 dev->features |= NETIF_F_IP_CSUM;
6598 else
6599 dev->features &= ~NETIF_F_IP_CSUM;
6600
6601 return 0;
6602}
6603
Ananda Raju75c30b12006-07-24 19:55:09 -04006604static u32 s2io_ethtool_op_get_tso(struct net_device *dev)
6605{
6606 return (dev->features & NETIF_F_TSO) != 0;
6607}
6608static int s2io_ethtool_op_set_tso(struct net_device *dev, u32 data)
6609{
6610 if (data)
6611 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
6612 else
6613 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
6614
6615 return 0;
6616}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617
Jeff Garzik7282d492006-09-13 14:30:00 -04006618static const struct ethtool_ops netdev_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 .get_settings = s2io_ethtool_gset,
6620 .set_settings = s2io_ethtool_sset,
6621 .get_drvinfo = s2io_ethtool_gdrvinfo,
6622 .get_regs_len = s2io_ethtool_get_regs_len,
6623 .get_regs = s2io_ethtool_gregs,
6624 .get_link = ethtool_op_get_link,
6625 .get_eeprom_len = s2io_get_eeprom_len,
6626 .get_eeprom = s2io_ethtool_geeprom,
6627 .set_eeprom = s2io_ethtool_seeprom,
Sreenivasa Honnur0cec35e2007-05-10 04:06:28 -04006628 .get_ringparam = s2io_ethtool_gringparam,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 .get_pauseparam = s2io_ethtool_getpause_data,
6630 .set_pauseparam = s2io_ethtool_setpause_data,
6631 .get_rx_csum = s2io_ethtool_get_rx_csum,
6632 .set_rx_csum = s2io_ethtool_set_rx_csum,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 .set_tx_csum = s2io_ethtool_op_set_tx_csum,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 .set_sg = ethtool_op_set_sg,
Ananda Raju75c30b12006-07-24 19:55:09 -04006635 .get_tso = s2io_ethtool_op_get_tso,
6636 .set_tso = s2io_ethtool_op_set_tso,
Ananda Rajufed5ecc2005-11-14 15:25:08 -05006637 .set_ufo = ethtool_op_set_ufo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 .self_test = s2io_ethtool_test,
6639 .get_strings = s2io_ethtool_get_strings,
6640 .phys_id = s2io_ethtool_idnic,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07006641 .get_ethtool_stats = s2io_get_ethtool_stats,
6642 .get_sset_count = s2io_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643};
6644
6645/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006646 * s2io_ioctl - Entry point for the Ioctl
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 * @dev : Device pointer.
6648 * @ifr : An IOCTL specefic structure, that can contain a pointer to
6649 * a proprietary structure used to pass information to the driver.
6650 * @cmd : This is used to distinguish between the different commands that
6651 * can be passed to the IOCTL functions.
6652 * Description:
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006653 * Currently there are no special functionality supported in IOCTL, hence
6654 * function always return EOPNOTSUPPORTED
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 */
6656
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006657static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658{
6659 return -EOPNOTSUPP;
6660}
6661
6662/**
6663 * s2io_change_mtu - entry point to change MTU size for the device.
6664 * @dev : device pointer.
6665 * @new_mtu : the new MTU size for the device.
6666 * Description: A driver entry point to change MTU size for the device.
6667 * Before changing the MTU the device must be stopped.
6668 * Return value:
6669 * 0 on success and an appropriate (-)ve integer as defined in errno.h
6670 * file on failure.
6671 */
6672
Adrian Bunkac1f60d2005-11-06 01:46:47 +01006673static int s2io_change_mtu(struct net_device *dev, int new_mtu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006675 struct s2io_nic *sp = dev->priv;
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05006676 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677
6678 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
6679 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
6680 dev->name);
6681 return -EPERM;
6682 }
6683
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 dev->mtu = new_mtu;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006685 if (netif_running(dev)) {
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05006686 s2io_stop_all_tx_queue(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006687 s2io_card_down(sp);
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05006688 ret = s2io_card_up(sp);
6689 if (ret) {
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006690 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
6691 __FUNCTION__);
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05006692 return ret;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006693 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05006694 s2io_wake_all_tx_queue(sp);
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006695 } else { /* Device is down */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006696 struct XENA_dev_config __iomem *bar0 = sp->bar0;
raghavendra.koushik@neterion.comd8892c62005-08-03 12:33:12 -07006697 u64 val64 = new_mtu;
6698
6699 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
6700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05006702 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703}
6704
6705/**
6706 * s2io_tasklet - Bottom half of the ISR.
6707 * @dev_adr : address of the device structure in dma_addr_t format.
6708 * Description:
6709 * This is the tasklet or the bottom half of the ISR. This is
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07006710 * an extension of the ISR which is scheduled by the scheduler to be run
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 * 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 -07006712 * be pushed into the tasklet. For now the tasklet is used only to
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 * replenish the Rx buffers in the Rx buffer descriptors.
6714 * Return value:
6715 * void.
6716 */
6717
6718static void s2io_tasklet(unsigned long dev_addr)
6719{
6720 struct net_device *dev = (struct net_device *) dev_addr;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006721 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 int i, ret;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006723 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 struct config_param *config;
6725
6726 mac_control = &sp->mac_control;
6727 config = &sp->config;
6728
6729 if (!TASKLET_IN_USE) {
6730 for (i = 0; i < config->rx_ring_num; i++) {
6731 ret = fill_rx_buffers(sp, i);
6732 if (ret == -ENOMEM) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006733 DBG_PRINT(INFO_DBG, "%s: Out of ",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006735 DBG_PRINT(INFO_DBG, "memory in tasklet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 break;
6737 } else if (ret == -EFILL) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006738 DBG_PRINT(INFO_DBG,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 "%s: Rx Ring %d is full\n",
6740 dev->name, i);
6741 break;
6742 }
6743 }
6744 clear_bit(0, (&sp->tasklet_status));
6745 }
6746}
6747
6748/**
6749 * s2io_set_link - Set the LInk status
6750 * @data: long pointer to device private structue
6751 * Description: Sets the link status for the adapter
6752 */
6753
David Howellsc4028952006-11-22 14:57:56 +00006754static void s2io_set_link(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006756 struct s2io_nic *nic = container_of(work, struct s2io_nic, set_link_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 struct net_device *dev = nic->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006758 struct XENA_dev_config __iomem *bar0 = nic->bar0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 register u64 val64;
6760 u16 subid;
6761
Francois Romieu22747d62007-02-15 23:37:50 +01006762 rtnl_lock();
6763
6764 if (!netif_running(dev))
6765 goto out_unlock;
6766
Sivakumar Subramani92b84432007-09-06 06:51:14 -04006767 if (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(nic->state))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 /* The card is being reset, no point doing anything */
Francois Romieu22747d62007-02-15 23:37:50 +01006769 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 }
6771
6772 subid = nic->pdev->subsystem_device;
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07006773 if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
6774 /*
6775 * Allow a small delay for the NICs self initiated
6776 * cleanup to complete.
6777 */
6778 msleep(100);
6779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780
6781 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006782 if (LINK_IS_UP(val64)) {
6783 if (!(readq(&bar0->adapter_control) & ADAPTER_CNTL_EN)) {
6784 if (verify_xena_quiescence(nic)) {
6785 val64 = readq(&bar0->adapter_control);
6786 val64 |= ADAPTER_CNTL_EN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 writeq(val64, &bar0->adapter_control);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006788 if (CARDS_WITH_FAULTY_LINK_INDICATORS(
6789 nic->device_type, subid)) {
6790 val64 = readq(&bar0->gpio_control);
6791 val64 |= GPIO_CTRL_GPIO_0;
6792 writeq(val64, &bar0->gpio_control);
6793 val64 = readq(&bar0->gpio_control);
6794 } else {
6795 val64 |= ADAPTER_LED_ON;
6796 writeq(val64, &bar0->adapter_control);
raghavendra.koushik@neterion.coma371a072005-08-03 12:38:59 -07006797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 nic->device_enabled_once = TRUE;
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006799 } else {
6800 DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
6801 DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05006802 s2io_stop_all_tx_queue(nic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804 }
Sivakumar Subramani92c48792007-08-06 05:38:19 -04006805 val64 = readq(&bar0->adapter_control);
6806 val64 |= ADAPTER_LED_ON;
6807 writeq(val64, &bar0->adapter_control);
6808 s2io_link(nic, LINK_UP);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006809 } else {
6810 if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
6811 subid)) {
6812 val64 = readq(&bar0->gpio_control);
6813 val64 &= ~GPIO_CTRL_GPIO_0;
6814 writeq(val64, &bar0->gpio_control);
6815 val64 = readq(&bar0->gpio_control);
6816 }
Sivakumar Subramani92c48792007-08-06 05:38:19 -04006817 /* turn off LED */
6818 val64 = readq(&bar0->adapter_control);
6819 val64 = val64 &(~ADAPTER_LED_ON);
6820 writeq(val64, &bar0->adapter_control);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05006821 s2io_link(nic, LINK_DOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006822 }
Sivakumar Subramani92b84432007-09-06 06:51:14 -04006823 clear_bit(__S2IO_STATE_LINK_TASK, &(nic->state));
Francois Romieu22747d62007-02-15 23:37:50 +01006824
6825out_unlock:
Sivakumar Subramanid8d70ca2007-02-24 02:04:24 -05006826 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827}
6828
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006829static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6830 struct buffAdd *ba,
6831 struct sk_buff **skb, u64 *temp0, u64 *temp1,
6832 u64 *temp2, int size)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006833{
6834 struct net_device *dev = sp->dev;
Veena Parat491abf22007-07-23 02:37:14 -04006835 struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006836
6837 if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) {
Veena Parat6d517a22007-07-23 02:20:51 -04006838 struct RxD1 *rxdp1 = (struct RxD1 *)rxdp;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006839 /* allocate skb */
6840 if (*skb) {
6841 DBG_PRINT(INFO_DBG, "SKB is not NULL\n");
6842 /*
6843 * As Rx frame are not going to be processed,
6844 * using same mapped address for the Rxd
6845 * buffer pointer
6846 */
Veena Parat6d517a22007-07-23 02:20:51 -04006847 rxdp1->Buffer0_ptr = *temp0;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006848 } else {
6849 *skb = dev_alloc_skb(size);
6850 if (!(*skb)) {
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08006851 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006852 DBG_PRINT(INFO_DBG, "memory to allocate ");
6853 DBG_PRINT(INFO_DBG, "1 buf mode SKBs\n");
6854 sp->mac_control.stats_info->sw_stat. \
6855 mem_alloc_fail_cnt++;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006856 return -ENOMEM ;
6857 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04006858 sp->mac_control.stats_info->sw_stat.mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006859 += (*skb)->truesize;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006860 /* storing the mapped addr in a temp variable
6861 * such it will be used for next rxd whose
6862 * Host Control is NULL
6863 */
Veena Parat6d517a22007-07-23 02:20:51 -04006864 rxdp1->Buffer0_ptr = *temp0 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006865 pci_map_single( sp->pdev, (*skb)->data,
6866 size - NET_IP_ALIGN,
6867 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04006868 if( (rxdp1->Buffer0_ptr == 0) ||
6869 (rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) {
6870 goto memalloc_failed;
6871 }
Ananda Raju5d3213c2006-04-21 19:23:26 -04006872 rxdp->Host_Control = (unsigned long) (*skb);
6873 }
6874 } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
Veena Parat6d517a22007-07-23 02:20:51 -04006875 struct RxD3 *rxdp3 = (struct RxD3 *)rxdp;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006876 /* Two buffer Mode */
6877 if (*skb) {
Veena Parat6d517a22007-07-23 02:20:51 -04006878 rxdp3->Buffer2_ptr = *temp2;
6879 rxdp3->Buffer0_ptr = *temp0;
6880 rxdp3->Buffer1_ptr = *temp1;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006881 } else {
6882 *skb = dev_alloc_skb(size);
David Rientjes2ceaac72006-10-30 14:19:25 -08006883 if (!(*skb)) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04006884 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6885 DBG_PRINT(INFO_DBG, "memory to allocate ");
6886 DBG_PRINT(INFO_DBG, "2 buf mode SKBs\n");
6887 sp->mac_control.stats_info->sw_stat. \
6888 mem_alloc_fail_cnt++;
David Rientjes2ceaac72006-10-30 14:19:25 -08006889 return -ENOMEM;
6890 }
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04006891 sp->mac_control.stats_info->sw_stat.mem_allocated
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04006892 += (*skb)->truesize;
Veena Parat6d517a22007-07-23 02:20:51 -04006893 rxdp3->Buffer2_ptr = *temp2 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006894 pci_map_single(sp->pdev, (*skb)->data,
6895 dev->mtu + 4,
6896 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04006897 if( (rxdp3->Buffer2_ptr == 0) ||
6898 (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) {
6899 goto memalloc_failed;
6900 }
Veena Parat6d517a22007-07-23 02:20:51 -04006901 rxdp3->Buffer0_ptr = *temp0 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006902 pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
6903 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04006904 if( (rxdp3->Buffer0_ptr == 0) ||
6905 (rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) {
6906 pci_unmap_single (sp->pdev,
Al Viro3e847422007-08-02 19:21:30 +01006907 (dma_addr_t)rxdp3->Buffer2_ptr,
Veena Parat491abf22007-07-23 02:37:14 -04006908 dev->mtu + 4, PCI_DMA_FROMDEVICE);
6909 goto memalloc_failed;
6910 }
Ananda Raju5d3213c2006-04-21 19:23:26 -04006911 rxdp->Host_Control = (unsigned long) (*skb);
6912
6913 /* Buffer-1 will be dummy buffer not used */
Veena Parat6d517a22007-07-23 02:20:51 -04006914 rxdp3->Buffer1_ptr = *temp1 =
Ananda Raju5d3213c2006-04-21 19:23:26 -04006915 pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
Ananda Raju5d3213c2006-04-21 19:23:26 -04006916 PCI_DMA_FROMDEVICE);
Veena Parat491abf22007-07-23 02:37:14 -04006917 if( (rxdp3->Buffer1_ptr == 0) ||
6918 (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
6919 pci_unmap_single (sp->pdev,
Al Viro3e847422007-08-02 19:21:30 +01006920 (dma_addr_t)rxdp3->Buffer0_ptr,
6921 BUF0_LEN, PCI_DMA_FROMDEVICE);
6922 pci_unmap_single (sp->pdev,
6923 (dma_addr_t)rxdp3->Buffer2_ptr,
Veena Parat491abf22007-07-23 02:37:14 -04006924 dev->mtu + 4, PCI_DMA_FROMDEVICE);
6925 goto memalloc_failed;
6926 }
Ananda Raju5d3213c2006-04-21 19:23:26 -04006927 }
6928 }
6929 return 0;
Veena Parat491abf22007-07-23 02:37:14 -04006930 memalloc_failed:
6931 stats->pci_map_fail_cnt++;
6932 stats->mem_freed += (*skb)->truesize;
6933 dev_kfree_skb(*skb);
6934 return -ENOMEM;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006935}
Veena Parat491abf22007-07-23 02:37:14 -04006936
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006937static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
6938 int size)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006939{
6940 struct net_device *dev = sp->dev;
6941 if (sp->rxd_mode == RXD_MODE_1) {
6942 rxdp->Control_2 = SET_BUFFER0_SIZE_1( size - NET_IP_ALIGN);
6943 } else if (sp->rxd_mode == RXD_MODE_3B) {
6944 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
6945 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
6946 rxdp->Control_2 |= SET_BUFFER2_SIZE_3( dev->mtu + 4);
Ananda Raju5d3213c2006-04-21 19:23:26 -04006947 }
6948}
6949
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006950static int rxd_owner_bit_reset(struct s2io_nic *sp)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006951{
6952 int i, j, k, blk_cnt = 0, size;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006953 struct mac_info * mac_control = &sp->mac_control;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006954 struct config_param *config = &sp->config;
6955 struct net_device *dev = sp->dev;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006956 struct RxD_t *rxdp = NULL;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006957 struct sk_buff *skb = NULL;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006958 struct buffAdd *ba = NULL;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006959 u64 temp0_64 = 0, temp1_64 = 0, temp2_64 = 0;
6960
6961 /* Calculate the size based on ring mode */
6962 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
6963 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
6964 if (sp->rxd_mode == RXD_MODE_1)
6965 size += NET_IP_ALIGN;
6966 else if (sp->rxd_mode == RXD_MODE_3B)
6967 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
Ananda Raju5d3213c2006-04-21 19:23:26 -04006968
6969 for (i = 0; i < config->rx_ring_num; i++) {
6970 blk_cnt = config->rx_cfg[i].num_rxd /
6971 (rxd_count[sp->rxd_mode] +1);
6972
6973 for (j = 0; j < blk_cnt; j++) {
6974 for (k = 0; k < rxd_count[sp->rxd_mode]; k++) {
6975 rxdp = mac_control->rings[i].
6976 rx_blocks[j].rxds[k].virt_addr;
Veena Parat6d517a22007-07-23 02:20:51 -04006977 if(sp->rxd_mode == RXD_MODE_3B)
Ananda Raju5d3213c2006-04-21 19:23:26 -04006978 ba = &mac_control->rings[i].ba[j][k];
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05006979 if (set_rxd_buffer_pointer(sp, rxdp, ba,
Ananda Raju5d3213c2006-04-21 19:23:26 -04006980 &skb,(u64 *)&temp0_64,
6981 (u64 *)&temp1_64,
Sivakumar Subramaniac1f90d2007-02-24 02:01:31 -05006982 (u64 *)&temp2_64,
6983 size) == ENOMEM) {
6984 return 0;
6985 }
Ananda Raju5d3213c2006-04-21 19:23:26 -04006986
6987 set_rxd_buffer_size(sp, rxdp, size);
6988 wmb();
6989 /* flip the Ownership bit to Hardware */
6990 rxdp->Control_1 |= RXD_OWN_XENA;
6991 }
6992 }
6993 }
6994 return 0;
6995
6996}
6997
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05006998static int s2io_add_isr(struct s2io_nic * sp)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07006999{
7000 int ret = 0;
7001 struct net_device *dev = sp->dev;
7002 int err = 0;
7003
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007004 if (sp->config.intr_type == MSI_X)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007005 ret = s2io_enable_msi_x(sp);
7006 if (ret) {
7007 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007008 sp->config.intr_type = INTA;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007009 }
7010
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007011 /* Store the values of the MSIX table in the struct s2io_nic structure */
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007012 store_xmsi_data(sp);
7013
7014 /* After proper initialization of H/W, register ISR */
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007015 if (sp->config.intr_type == MSI_X) {
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007016 int i, msix_tx_cnt=0,msix_rx_cnt=0;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007017
7018 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
7019 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
7020 sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
7021 dev->name, i);
7022 err = request_irq(sp->entries[i].vector,
7023 s2io_msix_fifo_handle, 0, sp->desc[i],
7024 sp->s2io_entries[i].arg);
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007025 /* If either data or addr is zero print it */
7026 if(!(sp->msix_info[i].addr &&
7027 sp->msix_info[i].data)) {
Joe Perches24500222007-11-19 17:48:28 -08007028 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx "
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007029 "Data:0x%lx\n",sp->desc[i],
7030 (unsigned long long)
7031 sp->msix_info[i].addr,
7032 (unsigned long)
7033 ntohl(sp->msix_info[i].data));
7034 } else {
7035 msix_tx_cnt++;
7036 }
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007037 } else {
7038 sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
7039 dev->name, i);
7040 err = request_irq(sp->entries[i].vector,
7041 s2io_msix_ring_handle, 0, sp->desc[i],
7042 sp->s2io_entries[i].arg);
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007043 /* If either data or addr is zero print it */
7044 if(!(sp->msix_info[i].addr &&
7045 sp->msix_info[i].data)) {
Joe Perches24500222007-11-19 17:48:28 -08007046 DBG_PRINT(ERR_DBG, "%s @ Addr:0x%llx "
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007047 "Data:0x%lx\n",sp->desc[i],
7048 (unsigned long long)
7049 sp->msix_info[i].addr,
7050 (unsigned long)
7051 ntohl(sp->msix_info[i].data));
7052 } else {
7053 msix_rx_cnt++;
7054 }
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007055 }
7056 if (err) {
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08007057 remove_msix_isr(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007058 DBG_PRINT(ERR_DBG,"%s:MSI-X-%d registration "
7059 "failed\n", dev->name, i);
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08007060 DBG_PRINT(ERR_DBG, "%s: defaulting to INTA\n",
7061 dev->name);
7062 sp->config.intr_type = INTA;
7063 break;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007064 }
7065 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
7066 }
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08007067 if (!err) {
7068 printk(KERN_INFO "MSI-X-TX %d entries enabled\n",
7069 msix_tx_cnt);
7070 printk(KERN_INFO "MSI-X-RX %d entries enabled\n",
7071 msix_rx_cnt);
7072 }
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007073 }
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007074 if (sp->config.intr_type == INTA) {
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007075 err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
7076 sp->name, dev);
7077 if (err) {
7078 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
7079 dev->name);
7080 return -1;
7081 }
7082 }
7083 return 0;
7084}
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007085static void s2io_rem_isr(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086{
Sreenivasa Honnur18b2b7b2007-11-14 01:41:06 -08007087 if (sp->config.intr_type == MSI_X)
7088 remove_msix_isr(sp);
7089 else
7090 remove_inta_isr(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007091}
7092
Linas Vepstasd796fdb2007-05-14 18:37:30 -05007093static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007094{
7095 int cnt = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007096 struct XENA_dev_config __iomem *bar0 = sp->bar0;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007097 unsigned long flags;
7098 register u64 val64 = 0;
Sreenivasa Honnur5f490c92008-01-14 20:23:04 -05007099 struct config_param *config;
7100 config = &sp->config;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007101
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05007102 if (!is_s2io_card_up(sp))
7103 return;
7104
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007105 del_timer_sync(&sp->alarm_timer);
7106 /* If s2io_set_link task is executing, wait till it completes. */
Sivakumar Subramani92b84432007-09-06 06:51:14 -04007107 while (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(sp->state))) {
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007108 msleep(50);
7109 }
Sivakumar Subramani92b84432007-09-06 06:51:14 -04007110 clear_bit(__S2IO_STATE_CARD_UP, &sp->state);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007111
Sreenivasa Honnur5f490c92008-01-14 20:23:04 -05007112 /* Disable napi */
7113 if (config->napi)
7114 napi_disable(&sp->napi);
7115
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007116 /* disable Tx and Rx traffic on the NIC */
Linas Vepstasd796fdb2007-05-14 18:37:30 -05007117 if (do_io)
7118 stop_nic(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007119
7120 s2io_rem_isr(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007121
7122 /* Kill tasklet. */
7123 tasklet_kill(&sp->task);
7124
7125 /* Check if the device is Quiescent and then Reset the NIC */
Linas Vepstasd796fdb2007-05-14 18:37:30 -05007126 while(do_io) {
Ananda Raju5d3213c2006-04-21 19:23:26 -04007127 /* As per the HW requirement we need to replenish the
7128 * receive buffer to avoid the ring bump. Since there is
7129 * no intention of processing the Rx frame at this pointwe are
7130 * just settting the ownership bit of rxd in Each Rx
7131 * ring to HW and set the appropriate buffer size
7132 * based on the ring mode
7133 */
7134 rxd_owner_bit_reset(sp);
7135
Linus Torvalds1da177e2005-04-16 15:20:36 -07007136 val64 = readq(&bar0->adapter_status);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007137 if (verify_xena_quiescence(sp)) {
7138 if(verify_pcc_quiescent(sp, sp->device_enabled_once))
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139 break;
7140 }
7141
7142 msleep(50);
7143 cnt++;
7144 if (cnt == 10) {
7145 DBG_PRINT(ERR_DBG,
7146 "s2io_close:Device not Quiescent ");
7147 DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
7148 (unsigned long long) val64);
7149 break;
7150 }
Linas Vepstasd796fdb2007-05-14 18:37:30 -05007151 }
7152 if (do_io)
7153 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007154
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007155 /* Free all Tx buffers */
7156 free_tx_buffers(sp);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07007157
7158 /* Free all Rx buffers */
7159 spin_lock_irqsave(&sp->rx_lock, flags);
7160 free_rx_buffers(sp);
7161 spin_unlock_irqrestore(&sp->rx_lock, flags);
7162
Sivakumar Subramani92b84432007-09-06 06:51:14 -04007163 clear_bit(__S2IO_STATE_LINK_TASK, &(sp->state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007164}
7165
Linas Vepstasd796fdb2007-05-14 18:37:30 -05007166static void s2io_card_down(struct s2io_nic * sp)
7167{
7168 do_s2io_card_down(sp, 1);
7169}
7170
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007171static int s2io_card_up(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007172{
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007173 int i, ret = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007174 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175 struct config_param *config;
7176 struct net_device *dev = (struct net_device *) sp->dev;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007177 u16 interruptible;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007178
7179 /* Initialize the H/W I/O registers */
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05007180 ret = init_nic(sp);
7181 if (ret != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007182 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
7183 dev->name);
Sreenivasa Honnur9f74ffd2007-11-30 01:46:08 -05007184 if (ret != -EIO)
7185 s2io_reset(sp);
7186 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007187 }
7188
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007189 /*
7190 * Initializing the Rx buffers. For now we are considering only 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 * Rx ring and initializing buffers into 30 Rx blocks
7192 */
7193 mac_control = &sp->mac_control;
7194 config = &sp->config;
7195
7196 for (i = 0; i < config->rx_ring_num; i++) {
7197 if ((ret = fill_rx_buffers(sp, i))) {
7198 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
7199 dev->name);
7200 s2io_reset(sp);
7201 free_rx_buffers(sp);
7202 return -ENOMEM;
7203 }
7204 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
7205 atomic_read(&sp->rx_bufs_left[i]));
7206 }
Sreenivasa Honnur5f490c92008-01-14 20:23:04 -05007207
7208 /* Initialise napi */
7209 if (config->napi)
7210 napi_enable(&sp->napi);
7211
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007212 /* Maintain the state prior to the open */
7213 if (sp->promisc_flg)
7214 sp->promisc_flg = 0;
7215 if (sp->m_cast_flg) {
7216 sp->m_cast_flg = 0;
7217 sp->all_multi_pos= 0;
7218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219
7220 /* Setting its receive mode */
7221 s2io_set_multicast(dev);
7222
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007223 if (sp->lro) {
Ananda Rajub41477f2006-07-24 19:52:49 -04007224 /* Initialize max aggregatable pkts per session based on MTU */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007225 sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
7226 /* Check if we can use(if specified) user provided value */
7227 if (lro_max_pkts < sp->lro_max_aggr_per_sess)
7228 sp->lro_max_aggr_per_sess = lro_max_pkts;
7229 }
7230
Linus Torvalds1da177e2005-04-16 15:20:36 -07007231 /* Enable Rx Traffic and interrupts on the NIC */
7232 if (start_nic(sp)) {
7233 DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007234 s2io_reset(sp);
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007235 free_rx_buffers(sp);
7236 return -ENODEV;
7237 }
7238
7239 /* Add interrupt service routine */
7240 if (s2io_add_isr(sp) != 0) {
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007241 if (sp->config.intr_type == MSI_X)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007242 s2io_rem_isr(sp);
7243 s2io_reset(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007244 free_rx_buffers(sp);
7245 return -ENODEV;
7246 }
7247
raghavendra.koushik@neterion.com25fff882005-08-03 12:34:11 -07007248 S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
7249
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007250 /* Enable tasklet for the device */
7251 tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
7252
7253 /* Enable select interrupts */
Sivakumar Subramani9caab452007-09-06 06:21:54 -04007254 en_dis_err_alarms(sp, ENA_ALL_INTRS, ENABLE_INTRS);
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007255 if (sp->config.intr_type != INTA)
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007256 en_dis_able_nic_intrs(sp, ENA_ALL_INTRS, DISABLE_INTRS);
7257 else {
7258 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
Sivakumar Subramani9caab452007-09-06 06:21:54 -04007259 interruptible |= TX_PIC_INTR;
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007260 en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
7261 }
7262
Sivakumar Subramani92b84432007-09-06 06:51:14 -04007263 set_bit(__S2IO_STATE_CARD_UP, &sp->state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007264 return 0;
7265}
7266
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007267/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007268 * s2io_restart_nic - Resets the NIC.
7269 * @data : long pointer to the device private structure
7270 * Description:
7271 * This function is scheduled to be run by the s2io_tx_watchdog
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007272 * function after 0.5 secs to reset the NIC. The idea is to reduce
Linus Torvalds1da177e2005-04-16 15:20:36 -07007273 * the run time of the watch dog routine which is run holding a
7274 * spin lock.
7275 */
7276
David Howellsc4028952006-11-22 14:57:56 +00007277static void s2io_restart_nic(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007278{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007279 struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
David Howellsc4028952006-11-22 14:57:56 +00007280 struct net_device *dev = sp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281
Francois Romieu22747d62007-02-15 23:37:50 +01007282 rtnl_lock();
7283
7284 if (!netif_running(dev))
7285 goto out_unlock;
7286
Ananda Rajue6a8fee2006-07-06 23:58:23 -07007287 s2io_card_down(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007288 if (s2io_card_up(sp)) {
7289 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
7290 dev->name);
7291 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007292 s2io_wake_all_tx_queue(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007293 DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
7294 dev->name);
Francois Romieu22747d62007-02-15 23:37:50 +01007295out_unlock:
7296 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07007297}
7298
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007299/**
7300 * s2io_tx_watchdog - Watchdog for transmit side.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007301 * @dev : Pointer to net device structure
7302 * Description:
7303 * This function is triggered if the Tx Queue is stopped
7304 * for a pre-defined amount of time when the Interface is still up.
7305 * If the Interface is jammed in such a situation, the hardware is
7306 * reset (by s2io_close) and restarted again (by s2io_open) to
7307 * overcome any problem that might have been caused in the hardware.
7308 * Return value:
7309 * void
7310 */
7311
7312static void s2io_tx_watchdog(struct net_device *dev)
7313{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007314 struct s2io_nic *sp = dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315
7316 if (netif_carrier_ok(dev)) {
Sreenivasa Honnurc53d4942007-05-10 04:18:54 -04007317 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007318 schedule_work(&sp->rst_timer_task);
Ananda Rajubd1034f2006-04-21 19:20:22 -04007319 sp->mac_control.stats_info->sw_stat.soft_reset_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007320 }
7321}
7322
7323/**
7324 * rx_osm_handler - To perform some OS related operations on SKB.
7325 * @sp: private member of the device structure,pointer to s2io_nic structure.
7326 * @skb : the socket buffer pointer.
7327 * @len : length of the packet
7328 * @cksum : FCS checksum of the frame.
7329 * @ring_no : the ring from which this RxD was extracted.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007330 * Description:
Ananda Rajub41477f2006-07-24 19:52:49 -04007331 * This function is called by the Rx interrupt serivce routine to perform
Linus Torvalds1da177e2005-04-16 15:20:36 -07007332 * some OS related operations on the SKB before passing it to the upper
7333 * layers. It mainly checks if the checksum is OK, if so adds it to the
7334 * SKBs cksum variable, increments the Rx packet count and passes the SKB
7335 * to the upper layer. If the checksum is wrong, it increments the Rx
7336 * packet error count, frees the SKB and returns error.
7337 * Return value:
7338 * SUCCESS on success and -1 on failure.
7339 */
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007340static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007341{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007342 struct s2io_nic *sp = ring_data->nic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007343 struct net_device *dev = (struct net_device *) sp->dev;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007344 struct sk_buff *skb = (struct sk_buff *)
7345 ((unsigned long) rxdp->Host_Control);
7346 int ring_no = ring_data->ring_no;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007347 u16 l3_csum, l4_csum;
Ananda Raju863c11a2006-04-21 19:03:13 -04007348 unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007349 struct lro *lro;
Olaf Heringf9046eb2007-06-19 22:41:10 +02007350 u8 err_mask;
Ananda Rajuda6971d2005-10-31 16:55:31 -05007351
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007352 skb->dev = dev;
Ananda Rajuc92ca042006-04-21 19:18:03 -04007353
Ananda Raju863c11a2006-04-21 19:03:13 -04007354 if (err) {
Ananda Rajubd1034f2006-04-21 19:20:22 -04007355 /* Check for parity error */
7356 if (err & 0x1) {
7357 sp->mac_control.stats_info->sw_stat.parity_err_cnt++;
7358 }
Olaf Heringf9046eb2007-06-19 22:41:10 +02007359 err_mask = err >> 48;
7360 switch(err_mask) {
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007361 case 1:
7362 sp->mac_control.stats_info->sw_stat.
7363 rx_parity_err_cnt++;
7364 break;
Ananda Rajubd1034f2006-04-21 19:20:22 -04007365
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007366 case 2:
7367 sp->mac_control.stats_info->sw_stat.
7368 rx_abort_cnt++;
7369 break;
7370
7371 case 3:
7372 sp->mac_control.stats_info->sw_stat.
7373 rx_parity_abort_cnt++;
7374 break;
7375
7376 case 4:
7377 sp->mac_control.stats_info->sw_stat.
7378 rx_rda_fail_cnt++;
7379 break;
7380
7381 case 5:
7382 sp->mac_control.stats_info->sw_stat.
7383 rx_unkn_prot_cnt++;
7384 break;
7385
7386 case 6:
7387 sp->mac_control.stats_info->sw_stat.
7388 rx_fcs_err_cnt++;
7389 break;
7390
7391 case 7:
7392 sp->mac_control.stats_info->sw_stat.
7393 rx_buf_size_err_cnt++;
7394 break;
7395
7396 case 8:
7397 sp->mac_control.stats_info->sw_stat.
7398 rx_rxd_corrupt_cnt++;
7399 break;
7400
7401 case 15:
7402 sp->mac_control.stats_info->sw_stat.
7403 rx_unkn_err_cnt++;
7404 break;
7405 }
Ananda Raju863c11a2006-04-21 19:03:13 -04007406 /*
7407 * Drop the packet if bad transfer code. Exception being
7408 * 0x5, which could be due to unsupported IPv6 extension header.
7409 * In this case, we let stack handle the packet.
7410 * Note that in this case, since checksum will be incorrect,
7411 * stack will validate the same.
7412 */
Olaf Heringf9046eb2007-06-19 22:41:10 +02007413 if (err_mask != 0x5) {
7414 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%x\n",
7415 dev->name, err_mask);
Ananda Raju863c11a2006-04-21 19:03:13 -04007416 sp->stats.rx_crc_errors++;
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04007417 sp->mac_control.stats_info->sw_stat.mem_freed
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007418 += skb->truesize;
Ananda Raju863c11a2006-04-21 19:03:13 -04007419 dev_kfree_skb(skb);
7420 atomic_dec(&sp->rx_bufs_left[ring_no]);
7421 rxdp->Host_Control = 0;
7422 return 0;
7423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007425
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007426 /* Updating statistics */
Ramkrishna Vepa573608e2007-07-25 19:43:12 -07007427 sp->stats.rx_packets++;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007428 rxdp->Host_Control = 0;
Ananda Rajuda6971d2005-10-31 16:55:31 -05007429 if (sp->rxd_mode == RXD_MODE_1) {
7430 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007431
Ananda Rajuda6971d2005-10-31 16:55:31 -05007432 sp->stats.rx_bytes += len;
7433 skb_put(skb, len);
7434
Veena Parat6d517a22007-07-23 02:20:51 -04007435 } else if (sp->rxd_mode == RXD_MODE_3B) {
Ananda Rajuda6971d2005-10-31 16:55:31 -05007436 int get_block = ring_data->rx_curr_get_info.block_index;
7437 int get_off = ring_data->rx_curr_get_info.offset;
7438 int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
7439 int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
7440 unsigned char *buff = skb_push(skb, buf0_len);
7441
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007442 struct buffAdd *ba = &ring_data->ba[get_block][get_off];
Ananda Rajuda6971d2005-10-31 16:55:31 -05007443 sp->stats.rx_bytes += buf0_len + buf2_len;
7444 memcpy(buff, ba->ba_0, buf0_len);
Veena Parat6d517a22007-07-23 02:20:51 -04007445 skb_put(skb, buf2_len);
Ananda Rajuda6971d2005-10-31 16:55:31 -05007446 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007447
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007448 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!sp->lro) ||
7449 (sp->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007450 (sp->rx_csum)) {
7451 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
7452 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
7453 if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
7454 /*
7455 * NIC verifies if the Checksum of the received
7456 * frame is Ok or not and accordingly returns
7457 * a flag in the RxD.
7458 */
7459 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007460 if (sp->lro) {
7461 u32 tcp_len;
7462 u8 *tcp;
7463 int ret = 0;
7464
7465 ret = s2io_club_tcp_session(skb->data, &tcp,
Stephen Hemminger43b7c452007-10-05 12:39:21 -07007466 &tcp_len, &lro,
7467 rxdp, sp);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007468 switch (ret) {
7469 case 3: /* Begin anew */
7470 lro->parent = skb;
7471 goto aggregate;
7472 case 1: /* Aggregate */
7473 {
7474 lro_append_pkt(sp, lro,
7475 skb, tcp_len);
7476 goto aggregate;
7477 }
7478 case 4: /* Flush session */
7479 {
7480 lro_append_pkt(sp, lro,
7481 skb, tcp_len);
7482 queue_rx_frame(lro->parent);
7483 clear_lro_session(lro);
7484 sp->mac_control.stats_info->
7485 sw_stat.flush_max_pkts++;
7486 goto aggregate;
7487 }
7488 case 2: /* Flush both */
7489 lro->parent->data_len =
7490 lro->frags_len;
7491 sp->mac_control.stats_info->
7492 sw_stat.sending_both++;
7493 queue_rx_frame(lro->parent);
7494 clear_lro_session(lro);
7495 goto send_up;
7496 case 0: /* sessions exceeded */
Ananda Rajuc92ca042006-04-21 19:18:03 -04007497 case -1: /* non-TCP or not
7498 * L2 aggregatable
7499 */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007500 case 5: /*
7501 * First pkt in session not
7502 * L3/L4 aggregatable
7503 */
7504 break;
7505 default:
7506 DBG_PRINT(ERR_DBG,
7507 "%s: Samadhana!!\n",
7508 __FUNCTION__);
7509 BUG();
7510 }
7511 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007512 } else {
7513 /*
7514 * Packet with erroneous checksum, let the
7515 * upper layers deal with it.
7516 */
7517 skb->ip_summed = CHECKSUM_NONE;
7518 }
7519 } else {
7520 skb->ip_summed = CHECKSUM_NONE;
7521 }
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007522 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007523 if (!sp->lro) {
7524 skb->protocol = eth_type_trans(skb, dev);
Sivakumar Subramani926930b2007-02-24 01:59:39 -05007525 if ((sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2) &&
7526 vlan_strip_flag)) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007527 /* Queueing the vlan frame to the upper layer */
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007528 if (napi)
7529 vlan_hwaccel_receive_skb(skb, sp->vlgrp,
7530 RXD_GET_VLAN_TAG(rxdp->Control_2));
7531 else
7532 vlan_hwaccel_rx(skb, sp->vlgrp,
7533 RXD_GET_VLAN_TAG(rxdp->Control_2));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007534 } else {
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007535 if (napi)
7536 netif_receive_skb(skb);
7537 else
7538 netif_rx(skb);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007539 }
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007540 } else {
7541send_up:
7542 queue_rx_frame(skb);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007543 }
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007544 dev->last_rx = jiffies;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05007545aggregate:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007546 atomic_dec(&sp->rx_bufs_left[ring_no]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007547 return SUCCESS;
7548}
7549
7550/**
7551 * s2io_link - stops/starts the Tx queue.
7552 * @sp : private member of the device structure, which is a pointer to the
7553 * s2io_nic structure.
7554 * @link : inidicates whether link is UP/DOWN.
7555 * Description:
7556 * This function stops/starts the Tx queue depending on whether the link
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007557 * status of the NIC is is down or up. This is called by the Alarm
7558 * interrupt handler whenever a link change interrupt comes up.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007559 * Return value:
7560 * void.
7561 */
7562
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007563static void s2io_link(struct s2io_nic * sp, int link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007564{
7565 struct net_device *dev = (struct net_device *) sp->dev;
7566
7567 if (link != sp->last_link_state) {
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08007568 init_tti(sp, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007569 if (link == LINK_DOWN) {
7570 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007571 s2io_stop_all_tx_queue(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007572 netif_carrier_off(dev);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007573 if(sp->mac_control.stats_info->sw_stat.link_up_cnt)
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04007574 sp->mac_control.stats_info->sw_stat.link_up_time =
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007575 jiffies - sp->start_time;
7576 sp->mac_control.stats_info->sw_stat.link_down_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007577 } else {
7578 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007579 if (sp->mac_control.stats_info->sw_stat.link_down_cnt)
Sivakumar Subramani8a4bdba2007-09-18 18:14:20 -04007580 sp->mac_control.stats_info->sw_stat.link_down_time =
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007581 jiffies - sp->start_time;
7582 sp->mac_control.stats_info->sw_stat.link_up_cnt++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007583 netif_carrier_on(dev);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007584 s2io_wake_all_tx_queue(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007585 }
7586 }
7587 sp->last_link_state = link;
Sreenivasa Honnur491976b2007-05-10 04:22:25 -04007588 sp->start_time = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007589}
7590
7591/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007592 * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
7593 * @sp : private member of the device structure, which is a pointer to the
Linus Torvalds1da177e2005-04-16 15:20:36 -07007594 * s2io_nic structure.
7595 * Description:
7596 * This function initializes a few of the PCI and PCI-X configuration registers
7597 * with recommended values.
7598 * Return value:
7599 * void
7600 */
7601
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007602static void s2io_init_pci(struct s2io_nic * sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007603{
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007604 u16 pci_cmd = 0, pcix_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007605
7606 /* Enable Data Parity Error Recovery in PCI-X command register. */
7607 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007608 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007609 pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007610 (pcix_cmd | 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007611 pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007612 &(pcix_cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007613
7614 /* Set the PErr Response bit in PCI command register. */
7615 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
7616 pci_write_config_word(sp->pdev, PCI_COMMAND,
7617 (pci_cmd | PCI_COMMAND_PARITY));
7618 pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007619}
7620
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007621static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type,
7622 u8 *dev_multiq)
Ananda Raju9dc737a2006-04-21 19:05:41 -04007623{
Surjit Reang2fda0962008-01-24 02:08:59 -08007624 if ((tx_fifo_num > MAX_TX_FIFOS) ||
7625 (tx_fifo_num < FIFO_DEFAULT_NUM)) {
7626 DBG_PRINT(ERR_DBG, "s2io: Requested number of tx fifos "
7627 "(%d) not supported\n", tx_fifo_num);
7628 tx_fifo_num =
7629 ((tx_fifo_num > MAX_TX_FIFOS)? MAX_TX_FIFOS :
7630 ((tx_fifo_num < FIFO_DEFAULT_NUM) ? FIFO_DEFAULT_NUM :
7631 tx_fifo_num));
7632 DBG_PRINT(ERR_DBG, "s2io: Default to %d ", tx_fifo_num);
7633 DBG_PRINT(ERR_DBG, "tx fifos\n");
Ananda Raju9dc737a2006-04-21 19:05:41 -04007634 }
Surjit Reang2fda0962008-01-24 02:08:59 -08007635
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007636#ifndef CONFIG_NETDEVICES_MULTIQUEUE
7637 if (multiq) {
7638 DBG_PRINT(ERR_DBG, "s2io: Multiqueue support not enabled\n");
7639 multiq = 0;
7640 }
7641#endif
7642 /* if multiqueue is enabled configure all fifos */
7643 if (multiq) {
7644 tx_fifo_num = MAX_TX_FIFOS;
7645 *dev_multiq = multiq;
7646 }
7647
Ananda Raju9dc737a2006-04-21 19:05:41 -04007648 if ( rx_ring_num > 8) {
7649 DBG_PRINT(ERR_DBG, "s2io: Requested number of Rx rings not "
7650 "supported\n");
7651 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Rx rings\n");
7652 rx_ring_num = 8;
7653 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007654 if (*dev_intr_type != INTA)
7655 napi = 0;
7656
Veena Parateccb8622007-07-23 02:23:54 -04007657 if ((*dev_intr_type != INTA) && (*dev_intr_type != MSI_X)) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04007658 DBG_PRINT(ERR_DBG, "s2io: Wrong intr_type requested. "
7659 "Defaulting to INTA\n");
7660 *dev_intr_type = INTA;
7661 }
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07007662
Ananda Raju9dc737a2006-04-21 19:05:41 -04007663 if ((*dev_intr_type == MSI_X) &&
7664 ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
7665 (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007666 DBG_PRINT(ERR_DBG, "s2io: Xframe I does not support MSI_X. "
Ananda Raju9dc737a2006-04-21 19:05:41 -04007667 "Defaulting to INTA\n");
7668 *dev_intr_type = INTA;
7669 }
Sivakumar Subramanifb6a8252007-02-24 01:51:50 -05007670
Veena Parat6d517a22007-07-23 02:20:51 -04007671 if ((rx_ring_mode != 1) && (rx_ring_mode != 2)) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04007672 DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
Veena Parat6d517a22007-07-23 02:20:51 -04007673 DBG_PRINT(ERR_DBG, "s2io: Defaulting to 1-buffer mode\n");
7674 rx_ring_mode = 1;
Ananda Raju9dc737a2006-04-21 19:05:41 -04007675 }
7676 return SUCCESS;
7677}
7678
Linus Torvalds1da177e2005-04-16 15:20:36 -07007679/**
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05007680 * rts_ds_steer - Receive traffic steering based on IPv4 or IPv6 TOS
7681 * or Traffic class respectively.
Ramkrishna Vepab7c56782007-12-17 11:40:15 -08007682 * @nic: device private variable
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05007683 * Description: The function configures the receive steering to
7684 * desired receive ring.
7685 * Return Value: SUCCESS on success and
7686 * '-1' on failure (endian settings incorrect).
7687 */
7688static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
7689{
7690 struct XENA_dev_config __iomem *bar0 = nic->bar0;
7691 register u64 val64 = 0;
7692
7693 if (ds_codepoint > 63)
7694 return FAILURE;
7695
7696 val64 = RTS_DS_MEM_DATA(ring);
7697 writeq(val64, &bar0->rts_ds_mem_data);
7698
7699 val64 = RTS_DS_MEM_CTRL_WE |
7700 RTS_DS_MEM_CTRL_STROBE_NEW_CMD |
7701 RTS_DS_MEM_CTRL_OFFSET(ds_codepoint);
7702
7703 writeq(val64, &bar0->rts_ds_mem_ctrl);
7704
7705 return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
7706 RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
7707 S2IO_BIT_RESET);
7708}
7709
7710/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007711 * s2io_init_nic - Initialization of the adapter .
Linus Torvalds1da177e2005-04-16 15:20:36 -07007712 * @pdev : structure containing the PCI related information of the device.
7713 * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
7714 * Description:
7715 * The function initializes an adapter identified by the pci_dec structure.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007716 * All OS related initialization including memory and device structure and
7717 * initlaization of the device private variable is done. Also the swapper
7718 * control register is initialized to enable read and write into the I/O
Linus Torvalds1da177e2005-04-16 15:20:36 -07007719 * registers of the device.
7720 * Return value:
7721 * returns 0 on success and negative on failure.
7722 */
7723
7724static int __devinit
7725s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7726{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007727 struct s2io_nic *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007728 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007729 int i, j, ret;
7730 int dma_flag = FALSE;
7731 u32 mac_up, mac_down;
7732 u64 val64 = 0, tmp64 = 0;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007733 struct XENA_dev_config __iomem *bar0 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007734 u16 subid;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007735 struct mac_info *mac_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007736 struct config_param *config;
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007737 int mode;
Ravinandan Arakalicc6e7c42005-10-04 06:41:24 -04007738 u8 dev_intr_type = intr_type;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007739 u8 dev_multiq = 0;
Joe Perches0795af52007-10-03 17:59:30 -07007740 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007741
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007742 ret = s2io_verify_parm(pdev, &dev_intr_type, &dev_multiq);
7743 if (ret)
Ananda Raju9dc737a2006-04-21 19:05:41 -04007744 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007745
7746 if ((ret = pci_enable_device(pdev))) {
7747 DBG_PRINT(ERR_DBG,
7748 "s2io_init_nic: pci_enable_device failed\n");
7749 return ret;
7750 }
7751
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007752 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007753 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
7754 dma_flag = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007755 if (pci_set_consistent_dma_mask
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007756 (pdev, DMA_64BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007757 DBG_PRINT(ERR_DBG,
7758 "Unable to obtain 64bit DMA for \
7759 consistent allocations\n");
7760 pci_disable_device(pdev);
7761 return -ENOMEM;
7762 }
Domen Puncer1e7f0bd2005-06-26 18:22:14 -04007763 } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007764 DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
7765 } else {
7766 pci_disable_device(pdev);
7767 return -ENOMEM;
7768 }
Veena Parateccb8622007-07-23 02:23:54 -04007769 if ((ret = pci_request_regions(pdev, s2io_driver_name))) {
7770 DBG_PRINT(ERR_DBG, "%s: Request Regions failed - %x \n", __FUNCTION__, ret);
7771 pci_disable_device(pdev);
7772 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007773 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007774#ifdef CONFIG_NETDEVICES_MULTIQUEUE
7775 if (dev_multiq)
7776 dev = alloc_etherdev_mq(sizeof(struct s2io_nic), MAX_TX_FIFOS);
7777 else
7778#endif
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007779 dev = alloc_etherdev(sizeof(struct s2io_nic));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007780 if (dev == NULL) {
7781 DBG_PRINT(ERR_DBG, "Device allocation failed\n");
7782 pci_disable_device(pdev);
7783 pci_release_regions(pdev);
7784 return -ENODEV;
7785 }
7786
7787 pci_set_master(pdev);
7788 pci_set_drvdata(pdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007789 SET_NETDEV_DEV(dev, &pdev->dev);
7790
7791 /* Private member variable initialized to s2io NIC structure */
7792 sp = dev->priv;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007793 memset(sp, 0, sizeof(struct s2io_nic));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007794 sp->dev = dev;
7795 sp->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007796 sp->high_dma_flag = dma_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007797 sp->device_enabled_once = FALSE;
Ananda Rajuda6971d2005-10-31 16:55:31 -05007798 if (rx_ring_mode == 1)
7799 sp->rxd_mode = RXD_MODE_1;
7800 if (rx_ring_mode == 2)
7801 sp->rxd_mode = RXD_MODE_3B;
Ananda Rajuda6971d2005-10-31 16:55:31 -05007802
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07007803 sp->config.intr_type = dev_intr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007804
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007805 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
7806 (pdev->device == PCI_DEVICE_ID_HERC_UNI))
7807 sp->device_type = XFRAME_II_DEVICE;
7808 else
7809 sp->device_type = XFRAME_I_DEVICE;
7810
Stephen Hemminger43b7c452007-10-05 12:39:21 -07007811 sp->lro = lro_enable;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04007812
Linus Torvalds1da177e2005-04-16 15:20:36 -07007813 /* Initialize some PCI/PCI-X fields of the NIC. */
7814 s2io_init_pci(sp);
7815
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007816 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007817 * Setting the device configuration parameters.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007818 * Most of these parameters can be specified by the user during
7819 * module insertion as they are module loadable parameters. If
7820 * these parameters are not not specified during load time, they
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821 * are initialized with default values.
7822 */
7823 mac_control = &sp->mac_control;
7824 config = &sp->config;
7825
Sivakumar Subramani596c5c92007-09-15 14:24:03 -07007826 config->napi = napi;
7827
Linus Torvalds1da177e2005-04-16 15:20:36 -07007828 /* Tx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007829 config->tx_fifo_num = tx_fifo_num;
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007830 config->multiq = dev_multiq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007831 for (i = 0; i < MAX_TX_FIFOS; i++) {
7832 config->tx_cfg[i].fifo_len = tx_fifo_len[i];
7833 config->tx_cfg[i].fifo_priority = i;
7834 }
7835
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007836 /* mapping the QoS priority to the configured fifos */
7837 for (i = 0; i < MAX_TX_FIFOS; i++)
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007838 config->fifo_mapping[i] = fifo_map[config->tx_fifo_num - 1][i];
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007839
Linus Torvalds1da177e2005-04-16 15:20:36 -07007840 config->tx_intr_type = TXD_INT_TYPE_UTILZ;
7841 for (i = 0; i < config->tx_fifo_num; i++) {
7842 config->tx_cfg[i].f_no_snoop =
7843 (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
7844 if (config->tx_cfg[i].fifo_len < 65) {
7845 config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
7846 break;
7847 }
7848 }
Ananda Rajufed5ecc2005-11-14 15:25:08 -05007849 /* + 2 because one Txd for skb->data and one Txd for UFO */
7850 config->max_txds = MAX_SKB_FRAGS + 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007851
7852 /* Rx side parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007853 config->rx_ring_num = rx_ring_num;
7854 for (i = 0; i < MAX_RX_RINGS; i++) {
7855 config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
Ananda Rajuda6971d2005-10-31 16:55:31 -05007856 (rxd_count[sp->rxd_mode] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007857 config->rx_cfg[i].ring_priority = i;
7858 }
7859
7860 for (i = 0; i < rx_ring_num; i++) {
7861 config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
7862 config->rx_cfg[i].f_no_snoop =
7863 (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
7864 }
7865
7866 /* Setting Mac Control parameters */
7867 mac_control->rmac_pause_time = rmac_pause_time;
7868 mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
7869 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
7870
7871
7872 /* Initialize Ring buffer parameters. */
7873 for (i = 0; i < config->rx_ring_num; i++)
7874 atomic_set(&sp->rx_bufs_left[i], 0);
7875
7876 /* initialize the shared memory used by the NIC and the host */
7877 if (init_shared_mem(sp)) {
7878 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
Ananda Rajub41477f2006-07-24 19:52:49 -04007879 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 ret = -ENOMEM;
7881 goto mem_alloc_failed;
7882 }
7883
7884 sp->bar0 = ioremap(pci_resource_start(pdev, 0),
7885 pci_resource_len(pdev, 0));
7886 if (!sp->bar0) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007887 DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem1\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007888 dev->name);
7889 ret = -ENOMEM;
7890 goto bar0_remap_failed;
7891 }
7892
7893 sp->bar1 = ioremap(pci_resource_start(pdev, 2),
7894 pci_resource_len(pdev, 2));
7895 if (!sp->bar1) {
Sivakumar Subramani19a60522007-01-31 13:30:49 -05007896 DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem2\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007897 dev->name);
7898 ret = -ENOMEM;
7899 goto bar1_remap_failed;
7900 }
7901
7902 dev->irq = pdev->irq;
7903 dev->base_addr = (unsigned long) sp->bar0;
7904
7905 /* Initializing the BAR1 address as the start of the FIFO pointer. */
7906 for (j = 0; j < MAX_TX_FIFOS; j++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05007907 mac_control->tx_FIFO_start[j] = (struct TxFIFO_element __iomem *)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007908 (sp->bar1 + (j * 0x00020000));
7909 }
7910
7911 /* Driver entry points */
7912 dev->open = &s2io_open;
7913 dev->stop = &s2io_close;
7914 dev->hard_start_xmit = &s2io_xmit;
7915 dev->get_stats = &s2io_get_stats;
7916 dev->set_multicast_list = &s2io_set_multicast;
7917 dev->do_ioctl = &s2io_ioctl;
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04007918 dev->set_mac_address = &s2io_set_mac_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007919 dev->change_mtu = &s2io_change_mtu;
7920 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
raghavendra.koushik@neterion.combe3a6b02005-08-03 12:35:55 -07007921 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
7922 dev->vlan_rx_register = s2io_vlan_rx_register;
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07007923
Linus Torvalds1da177e2005-04-16 15:20:36 -07007924 /*
7925 * will use eth_mac_addr() for dev->set_mac_address
7926 * mac address will be set every time dev->open() is called
7927 */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07007928 netif_napi_add(dev, &sp->napi, s2io_poll, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007929
Brian Haley612eff02006-06-15 14:36:36 -04007930#ifdef CONFIG_NET_POLL_CONTROLLER
7931 dev->poll_controller = s2io_netpoll;
7932#endif
7933
Linus Torvalds1da177e2005-04-16 15:20:36 -07007934 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
7935 if (sp->high_dma_flag == TRUE)
7936 dev->features |= NETIF_F_HIGHDMA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007937 dev->features |= NETIF_F_TSO;
Herbert Xuf83ef8c2006-06-30 13:37:03 -07007938 dev->features |= NETIF_F_TSO6;
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05007939 if ((sp->device_type & XFRAME_II_DEVICE) && (ufo)) {
Ananda Rajufed5ecc2005-11-14 15:25:08 -05007940 dev->features |= NETIF_F_UFO;
7941 dev->features |= NETIF_F_HW_CSUM;
7942 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05007943#ifdef CONFIG_NETDEVICES_MULTIQUEUE
7944 if (config->multiq)
7945 dev->features |= NETIF_F_MULTI_QUEUE;
7946#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07007947 dev->tx_timeout = &s2io_tx_watchdog;
7948 dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
David Howellsc4028952006-11-22 14:57:56 +00007949 INIT_WORK(&sp->rst_timer_task, s2io_restart_nic);
7950 INIT_WORK(&sp->set_link_task, s2io_set_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007951
ravinandan.arakali@neterion.come960fc52005-08-12 10:15:59 -07007952 pci_save_state(sp->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007953
7954 /* Setting swapper control on the NIC, for proper reset operation */
7955 if (s2io_set_swapper(sp)) {
7956 DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
7957 dev->name);
7958 ret = -EAGAIN;
7959 goto set_swap_failed;
7960 }
7961
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07007962 /* Verify if the Herc works on the slot its placed into */
7963 if (sp->device_type & XFRAME_II_DEVICE) {
7964 mode = s2io_verify_pci_mode(sp);
7965 if (mode < 0) {
7966 DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);
7967 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
7968 ret = -EBADSLT;
7969 goto set_swap_failed;
7970 }
7971 }
7972
7973 /* Not needed for Herc */
7974 if (sp->device_type & XFRAME_I_DEVICE) {
7975 /*
7976 * Fix for all "FFs" MAC address problems observed on
7977 * Alpha platforms
7978 */
7979 fix_mac_address(sp);
7980 s2io_reset(sp);
7981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007982
7983 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007984 * MAC address initialization.
7985 * For now only one mac address will be read and used.
7986 */
7987 bar0 = sp->bar0;
7988 val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08007989 RMAC_ADDR_CMD_MEM_OFFSET(0 + S2IO_MAC_ADDR_START_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007990 writeq(val64, &bar0->rmac_addr_cmd_mem);
Ananda Rajuc92ca042006-04-21 19:18:03 -04007991 wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
Sivakumar Subramani9fc93a42007-02-24 01:57:32 -05007992 RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007993 tmp64 = readq(&bar0->rmac_addr_data0_mem);
7994 mac_down = (u32) tmp64;
7995 mac_up = (u32) (tmp64 >> 32);
7996
Linus Torvalds1da177e2005-04-16 15:20:36 -07007997 sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
7998 sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
7999 sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
8000 sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
8001 sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
8002 sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
8003
Linus Torvalds1da177e2005-04-16 15:20:36 -07008004 /* Set the factory defined MAC address initially */
8005 dev->addr_len = ETH_ALEN;
8006 memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
Sivakumar Subramani2fd37682007-09-14 07:39:19 -04008007 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008008
Sreenivasa Honnurfaa4f792008-01-24 01:45:43 -08008009 /* initialize number of multicast & unicast MAC entries variables */
8010 if (sp->device_type == XFRAME_I_DEVICE) {
8011 config->max_mc_addr = S2IO_XENA_MAX_MC_ADDRESSES;
8012 config->max_mac_addr = S2IO_XENA_MAX_MAC_ADDRESSES;
8013 config->mc_start_offset = S2IO_XENA_MC_ADDR_START_OFFSET;
8014 } else if (sp->device_type == XFRAME_II_DEVICE) {
8015 config->max_mc_addr = S2IO_HERC_MAX_MC_ADDRESSES;
8016 config->max_mac_addr = S2IO_HERC_MAX_MAC_ADDRESSES;
8017 config->mc_start_offset = S2IO_HERC_MC_ADDR_START_OFFSET;
8018 }
8019
8020 /* store mac addresses from CAM to s2io_nic structure */
8021 do_s2io_store_unicast_mc(sp);
8022
Sivakumar Subramanic77dd432007-08-06 05:36:28 -04008023 /* Store the values of the MSIX table in the s2io_nic structure */
8024 store_xmsi_data(sp);
Ananda Rajub41477f2006-07-24 19:52:49 -04008025 /* reset Nic and bring it to known state */
8026 s2io_reset(sp);
8027
Linus Torvalds1da177e2005-04-16 15:20:36 -07008028 /*
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008029 * Initialize the tasklet status and link state flags
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07008030 * and the card state parameter
Linus Torvalds1da177e2005-04-16 15:20:36 -07008031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008032 sp->tasklet_status = 0;
Sivakumar Subramani92b84432007-09-06 06:51:14 -04008033 sp->state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008034
Linus Torvalds1da177e2005-04-16 15:20:36 -07008035 /* Initialize spinlocks */
Surjit Reang2fda0962008-01-24 02:08:59 -08008036 for (i = 0; i < sp->config.tx_fifo_num; i++)
8037 spin_lock_init(&mac_control->fifos[i].tx_lock);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05008038
8039 if (!napi)
8040 spin_lock_init(&sp->put_lock);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07008041 spin_lock_init(&sp->rx_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008042
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008043 /*
8044 * SXE-002: Configure link and activity LED to init state
8045 * on driver load.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008046 */
8047 subid = sp->pdev->subsystem_device;
8048 if ((subid & 0xFF) >= 0x07) {
8049 val64 = readq(&bar0->gpio_control);
8050 val64 |= 0x0000800000000000ULL;
8051 writeq(val64, &bar0->gpio_control);
8052 val64 = 0x0411040400000000ULL;
8053 writeq(val64, (void __iomem *) bar0 + 0x2700);
8054 val64 = readq(&bar0->gpio_control);
8055 }
8056
8057 sp->rx_csum = 1; /* Rx chksum verify enabled by default */
8058
8059 if (register_netdev(dev)) {
8060 DBG_PRINT(ERR_DBG, "Device registration failed\n");
8061 ret = -ENODEV;
8062 goto register_failed;
8063 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04008064 s2io_vpd_read(sp);
Ramkrishna Vepa0c61ed52007-03-09 18:28:32 -08008065 DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2007 Neterion Inc.\n");
Ananda Rajub41477f2006-07-24 19:52:49 -04008066 DBG_PRINT(ERR_DBG, "%s: Neterion %s (rev %d)\n",dev->name,
Auke Kok44c10132007-06-08 15:46:36 -07008067 sp->product_name, pdev->revision);
Ananda Rajub41477f2006-07-24 19:52:49 -04008068 DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
8069 s2io_driver_version);
Joe Perches0795af52007-10-03 17:59:30 -07008070 DBG_PRINT(ERR_DBG, "%s: MAC ADDR: %s\n",
8071 dev->name, print_mac(mac, dev->dev_addr));
Sivakumar Subramani19a60522007-01-31 13:30:49 -05008072 DBG_PRINT(ERR_DBG, "SERIAL NUMBER: %s\n", sp->serial_num);
Ananda Raju9dc737a2006-04-21 19:05:41 -04008073 if (sp->device_type & XFRAME_II_DEVICE) {
raghavendra.koushik@neterion.com0b1f7eb2005-08-03 12:39:56 -07008074 mode = s2io_print_pci_mode(sp);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07008075 if (mode < 0) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04008076 DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07008077 ret = -EBADSLT;
Ananda Raju9dc737a2006-04-21 19:05:41 -04008078 unregister_netdev(dev);
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07008079 goto set_swap_failed;
8080 }
raghavendra.koushik@neterion.com541ae682005-08-03 12:36:55 -07008081 }
Ananda Raju9dc737a2006-04-21 19:05:41 -04008082 switch(sp->rxd_mode) {
8083 case RXD_MODE_1:
8084 DBG_PRINT(ERR_DBG, "%s: 1-Buffer receive mode enabled\n",
8085 dev->name);
8086 break;
8087 case RXD_MODE_3B:
8088 DBG_PRINT(ERR_DBG, "%s: 2-Buffer receive mode enabled\n",
8089 dev->name);
8090 break;
Ananda Raju9dc737a2006-04-21 19:05:41 -04008091 }
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05008092
8093 if (napi)
8094 DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05008095
8096 DBG_PRINT(ERR_DBG, "%s: Using %d Tx fifo(s)\n", dev->name,
8097 sp->config.tx_fifo_num);
8098
Sivakumar Subramanieaae7f72007-09-15 14:14:22 -07008099 switch(sp->config.intr_type) {
Ananda Raju9dc737a2006-04-21 19:05:41 -04008100 case INTA:
8101 DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
8102 break;
Ananda Raju9dc737a2006-04-21 19:05:41 -04008103 case MSI_X:
8104 DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
8105 break;
8106 }
Sreenivasa Honnur3a3d5752008-02-20 16:44:07 -05008107 if (sp->config.multiq) {
8108 for (i = 0; i < sp->config.tx_fifo_num; i++)
8109 mac_control->fifos[i].multiq = config->multiq;
8110 DBG_PRINT(ERR_DBG, "%s: Multiqueue support enabled\n",
8111 dev->name);
8112 } else
8113 DBG_PRINT(ERR_DBG, "%s: Multiqueue support disabled\n",
8114 dev->name);
8115
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008116 if (sp->lro)
8117 DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
Ananda Raju9dc737a2006-04-21 19:05:41 -04008118 dev->name);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05008119 if (ufo)
8120 DBG_PRINT(ERR_DBG, "%s: UDP Fragmentation Offload(UFO)"
8121 " enabled\n", dev->name);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07008122 /* Initialize device name */
Ananda Raju9dc737a2006-04-21 19:05:41 -04008123 sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
raghavendra.koushik@neterion.com7ba013a2005-08-03 12:29:20 -07008124
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008125 /*
8126 * Make Link state as off at this point, when the Link change
8127 * interrupt comes the state will be automatically changed to
Linus Torvalds1da177e2005-04-16 15:20:36 -07008128 * the right state.
8129 */
8130 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008131
8132 return 0;
8133
8134 register_failed:
8135 set_swap_failed:
8136 iounmap(sp->bar1);
8137 bar1_remap_failed:
8138 iounmap(sp->bar0);
8139 bar0_remap_failed:
8140 mem_alloc_failed:
8141 free_shared_mem(sp);
8142 pci_disable_device(pdev);
Veena Parateccb8622007-07-23 02:23:54 -04008143 pci_release_regions(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008144 pci_set_drvdata(pdev, NULL);
8145 free_netdev(dev);
8146
8147 return ret;
8148}
8149
8150/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008151 * s2io_rem_nic - Free the PCI device
Linus Torvalds1da177e2005-04-16 15:20:36 -07008152 * @pdev: structure containing the PCI related information of the device.
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008153 * Description: This function is called by the Pci subsystem to release a
Linus Torvalds1da177e2005-04-16 15:20:36 -07008154 * PCI device and free up all resource held up by the device. This could
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008155 * be in response to a Hot plug event or when the driver is to be removed
Linus Torvalds1da177e2005-04-16 15:20:36 -07008156 * from memory.
8157 */
8158
8159static void __devexit s2io_rem_nic(struct pci_dev *pdev)
8160{
8161 struct net_device *dev =
8162 (struct net_device *) pci_get_drvdata(pdev);
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008163 struct s2io_nic *sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008164
8165 if (dev == NULL) {
8166 DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
8167 return;
8168 }
8169
Francois Romieu22747d62007-02-15 23:37:50 +01008170 flush_scheduled_work();
8171
Linus Torvalds1da177e2005-04-16 15:20:36 -07008172 sp = dev->priv;
8173 unregister_netdev(dev);
8174
8175 free_shared_mem(sp);
8176 iounmap(sp->bar0);
8177 iounmap(sp->bar1);
Veena Parateccb8622007-07-23 02:23:54 -04008178 pci_release_regions(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008179 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008180 free_netdev(dev);
Sivakumar Subramani19a60522007-01-31 13:30:49 -05008181 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008182}
8183
8184/**
8185 * s2io_starter - Entry point for the driver
8186 * Description: This function is the entry point for the driver. It verifies
8187 * the module loadable parameters and initializes PCI configuration space.
8188 */
8189
Stephen Hemminger43b7c452007-10-05 12:39:21 -07008190static int __init s2io_starter(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008191{
Jeff Garzik29917622006-08-19 17:48:59 -04008192 return pci_register_driver(&s2io_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008193}
8194
8195/**
raghavendra.koushik@neterion.com20346722005-08-03 12:24:33 -07008196 * s2io_closer - Cleanup routine for the driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07008197 * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
8198 */
8199
Sivakumar Subramani372cc592007-01-31 13:32:57 -05008200static __exit void s2io_closer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008201{
8202 pci_unregister_driver(&s2io_driver);
8203 DBG_PRINT(INIT_DBG, "cleanup done\n");
8204}
8205
8206module_init(s2io_starter);
8207module_exit(s2io_closer);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008208
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008209static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008210 struct tcphdr **tcp, struct RxD_t *rxdp)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008211{
8212 int ip_off;
8213 u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
8214
8215 if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
8216 DBG_PRINT(INIT_DBG,"%s: Non-TCP frames not supported for LRO\n",
8217 __FUNCTION__);
8218 return -1;
8219 }
8220
8221 /* TODO:
8222 * By default the VLAN field in the MAC is stripped by the card, if this
8223 * feature is turned off in rx_pa_cfg register, then the ip_off field
8224 * has to be shifted by a further 2 bytes
8225 */
8226 switch (l2_type) {
8227 case 0: /* DIX type */
8228 case 4: /* DIX type with VLAN */
8229 ip_off = HEADER_ETHERNET_II_802_3_SIZE;
8230 break;
8231 /* LLC, SNAP etc are considered non-mergeable */
8232 default:
8233 return -1;
8234 }
8235
8236 *ip = (struct iphdr *)((u8 *)buffer + ip_off);
8237 ip_len = (u8)((*ip)->ihl);
8238 ip_len <<= 2;
8239 *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
8240
8241 return 0;
8242}
8243
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008244static int check_for_socket_match(struct lro *lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008245 struct tcphdr *tcp)
8246{
8247 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
8248 if ((lro->iph->saddr != ip->saddr) || (lro->iph->daddr != ip->daddr) ||
8249 (lro->tcph->source != tcp->source) || (lro->tcph->dest != tcp->dest))
8250 return -1;
8251 return 0;
8252}
8253
8254static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
8255{
8256 return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
8257}
8258
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008259static void initiate_new_session(struct lro *lro, u8 *l2h,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008260 struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len)
8261{
8262 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
8263 lro->l2h = l2h;
8264 lro->iph = ip;
8265 lro->tcph = tcp;
8266 lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
Surjit Reangc8855952008-02-03 04:27:38 -08008267 lro->tcp_ack = tcp->ack_seq;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008268 lro->sg_num = 1;
8269 lro->total_len = ntohs(ip->tot_len);
8270 lro->frags_len = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008271 /*
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008272 * check if we saw TCP timestamp. Other consistency checks have
8273 * already been done.
8274 */
8275 if (tcp->doff == 8) {
Surjit Reangc8855952008-02-03 04:27:38 -08008276 __be32 *ptr;
8277 ptr = (__be32 *)(tcp+1);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008278 lro->saw_ts = 1;
Surjit Reangc8855952008-02-03 04:27:38 -08008279 lro->cur_tsval = ntohl(*(ptr+1));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008280 lro->cur_tsecr = *(ptr+2);
8281 }
8282 lro->in_use = 1;
8283}
8284
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008285static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008286{
8287 struct iphdr *ip = lro->iph;
8288 struct tcphdr *tcp = lro->tcph;
Al Virobd4f3ae2007-02-09 16:40:15 +00008289 __sum16 nchk;
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008290 struct stat_block *statinfo = sp->mac_control.stats_info;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008291 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
8292
8293 /* Update L3 header */
8294 ip->tot_len = htons(lro->total_len);
8295 ip->check = 0;
8296 nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
8297 ip->check = nchk;
8298
8299 /* Update L4 header */
8300 tcp->ack_seq = lro->tcp_ack;
8301 tcp->window = lro->window;
8302
8303 /* Update tsecr field if this session has timestamps enabled */
8304 if (lro->saw_ts) {
Surjit Reangc8855952008-02-03 04:27:38 -08008305 __be32 *ptr = (__be32 *)(tcp + 1);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008306 *(ptr+2) = lro->cur_tsecr;
8307 }
8308
8309 /* Update counters required for calculation of
8310 * average no. of packets aggregated.
8311 */
8312 statinfo->sw_stat.sum_avg_pkts_aggregated += lro->sg_num;
8313 statinfo->sw_stat.num_aggregations++;
8314}
8315
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008316static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008317 struct tcphdr *tcp, u32 l4_pyld)
8318{
8319 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
8320 lro->total_len += l4_pyld;
8321 lro->frags_len += l4_pyld;
8322 lro->tcp_next_seq += l4_pyld;
8323 lro->sg_num++;
8324
8325 /* Update ack seq no. and window ad(from this pkt) in LRO object */
8326 lro->tcp_ack = tcp->ack_seq;
8327 lro->window = tcp->window;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008328
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008329 if (lro->saw_ts) {
Surjit Reangc8855952008-02-03 04:27:38 -08008330 __be32 *ptr;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008331 /* Update tsecr and tsval from this packet */
Surjit Reangc8855952008-02-03 04:27:38 -08008332 ptr = (__be32 *)(tcp+1);
8333 lro->cur_tsval = ntohl(*(ptr+1));
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008334 lro->cur_tsecr = *(ptr + 2);
8335 }
8336}
8337
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008338static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008339 struct tcphdr *tcp, u32 tcp_pyld_len)
8340{
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008341 u8 *ptr;
8342
Andrew Morton79dc1902006-02-03 01:45:13 -08008343 DBG_PRINT(INFO_DBG,"%s: Been here...\n", __FUNCTION__);
8344
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008345 if (!tcp_pyld_len) {
8346 /* Runt frame or a pure ack */
8347 return -1;
8348 }
8349
8350 if (ip->ihl != 5) /* IP has options */
8351 return -1;
8352
Ananda Raju75c30b12006-07-24 19:55:09 -04008353 /* If we see CE codepoint in IP header, packet is not mergeable */
8354 if (INET_ECN_is_ce(ipv4_get_dsfield(ip)))
8355 return -1;
8356
8357 /* If we see ECE or CWR flags in TCP header, packet is not mergeable */
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008358 if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
Ananda Raju75c30b12006-07-24 19:55:09 -04008359 tcp->ece || tcp->cwr || !tcp->ack) {
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008360 /*
8361 * Currently recognize only the ack control word and
8362 * any other control field being set would result in
8363 * flushing the LRO session
8364 */
8365 return -1;
8366 }
8367
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008368 /*
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008369 * Allow only one TCP timestamp option. Don't aggregate if
8370 * any other options are detected.
8371 */
8372 if (tcp->doff != 5 && tcp->doff != 8)
8373 return -1;
8374
8375 if (tcp->doff == 8) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04008376 ptr = (u8 *)(tcp + 1);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008377 while (*ptr == TCPOPT_NOP)
8378 ptr++;
8379 if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
8380 return -1;
8381
8382 /* Ensure timestamp value increases monotonically */
8383 if (l_lro)
Surjit Reangc8855952008-02-03 04:27:38 -08008384 if (l_lro->cur_tsval > ntohl(*((__be32 *)(ptr+2))))
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008385 return -1;
8386
8387 /* timestamp echo reply should be non-zero */
Surjit Reangc8855952008-02-03 04:27:38 -08008388 if (*((__be32 *)(ptr+6)) == 0)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008389 return -1;
8390 }
8391
8392 return 0;
8393}
8394
8395static int
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008396s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
8397 struct RxD_t *rxdp, struct s2io_nic *sp)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008398{
8399 struct iphdr *ip;
8400 struct tcphdr *tcph;
8401 int ret = 0, i;
8402
8403 if (!(ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
8404 rxdp))) {
8405 DBG_PRINT(INFO_DBG,"IP Saddr: %x Daddr: %x\n",
8406 ip->saddr, ip->daddr);
8407 } else {
8408 return ret;
8409 }
8410
8411 tcph = (struct tcphdr *)*tcp;
8412 *tcp_len = get_l4_pyld_length(ip, tcph);
8413 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008414 struct lro *l_lro = &sp->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008415 if (l_lro->in_use) {
8416 if (check_for_socket_match(l_lro, ip, tcph))
8417 continue;
8418 /* Sock pair matched */
8419 *lro = l_lro;
8420
8421 if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
8422 DBG_PRINT(INFO_DBG, "%s:Out of order. expected "
8423 "0x%x, actual 0x%x\n", __FUNCTION__,
8424 (*lro)->tcp_next_seq,
8425 ntohl(tcph->seq));
8426
8427 sp->mac_control.stats_info->
8428 sw_stat.outof_sequence_pkts++;
8429 ret = 2;
8430 break;
8431 }
8432
8433 if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,*tcp_len))
8434 ret = 1; /* Aggregate */
8435 else
8436 ret = 2; /* Flush both */
8437 break;
8438 }
8439 }
8440
8441 if (ret == 0) {
8442 /* Before searching for available LRO objects,
8443 * check if the pkt is L3/L4 aggregatable. If not
8444 * don't create new LRO session. Just send this
8445 * packet up.
8446 */
8447 if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len)) {
8448 return 5;
8449 }
8450
8451 for (i=0; i<MAX_LRO_SESSIONS; i++) {
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008452 struct lro *l_lro = &sp->lro0_n[i];
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008453 if (!(l_lro->in_use)) {
8454 *lro = l_lro;
8455 ret = 3; /* Begin anew */
8456 break;
8457 }
8458 }
8459 }
8460
8461 if (ret == 0) { /* sessions exceeded */
8462 DBG_PRINT(INFO_DBG,"%s:All LRO sessions already in use\n",
8463 __FUNCTION__);
8464 *lro = NULL;
8465 return ret;
8466 }
8467
8468 switch (ret) {
8469 case 3:
8470 initiate_new_session(*lro, buffer, ip, tcph, *tcp_len);
8471 break;
8472 case 2:
8473 update_L3L4_header(sp, *lro);
8474 break;
8475 case 1:
8476 aggregate_new_rx(*lro, ip, tcph, *tcp_len);
8477 if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
8478 update_L3L4_header(sp, *lro);
8479 ret = 4; /* Flush the LRO */
8480 }
8481 break;
8482 default:
8483 DBG_PRINT(ERR_DBG,"%s:Dont know, can't say!!\n",
8484 __FUNCTION__);
8485 break;
8486 }
8487
8488 return ret;
8489}
8490
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008491static void clear_lro_session(struct lro *lro)
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008492{
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008493 static u16 lro_struct_size = sizeof(struct lro);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008494
8495 memset(lro, 0, lro_struct_size);
8496}
8497
8498static void queue_rx_frame(struct sk_buff *skb)
8499{
8500 struct net_device *dev = skb->dev;
8501
8502 skb->protocol = eth_type_trans(skb, dev);
Sivakumar Subramanidb874e62007-01-31 13:28:08 -05008503 if (napi)
8504 netif_receive_skb(skb);
8505 else
8506 netif_rx(skb);
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008507}
8508
Ralf Baechle1ee6dd72007-01-31 14:09:29 -05008509static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
8510 struct sk_buff *skb,
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008511 u32 tcp_len)
8512{
Ananda Raju75c30b12006-07-24 19:55:09 -04008513 struct sk_buff *first = lro->parent;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008514
8515 first->len += tcp_len;
8516 first->data_len = lro->frags_len;
8517 skb_pull(skb, (skb->len - tcp_len));
Ananda Raju75c30b12006-07-24 19:55:09 -04008518 if (skb_shinfo(first)->frag_list)
8519 lro->last_frag->next = skb;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008520 else
8521 skb_shinfo(first)->frag_list = skb;
Sivakumar Subramani372cc592007-01-31 13:32:57 -05008522 first->truesize += skb->truesize;
Ananda Raju75c30b12006-07-24 19:55:09 -04008523 lro->last_frag = skb;
Ravinandan Arakali7d3d04392006-01-25 14:53:07 -05008524 sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
8525 return;
8526}
Linas Vepstasd796fdb2007-05-14 18:37:30 -05008527
8528/**
8529 * s2io_io_error_detected - called when PCI error is detected
8530 * @pdev: Pointer to PCI device
Rolf Eike Beer8453d432007-07-10 11:58:02 +02008531 * @state: The current pci connection state
Linas Vepstasd796fdb2007-05-14 18:37:30 -05008532 *
8533 * This function is called after a PCI bus error affecting
8534 * this device has been detected.
8535 */
8536static pci_ers_result_t s2io_io_error_detected(struct pci_dev *pdev,
8537 pci_channel_state_t state)
8538{
8539 struct net_device *netdev = pci_get_drvdata(pdev);
8540 struct s2io_nic *sp = netdev->priv;
8541
8542 netif_device_detach(netdev);
8543
8544 if (netif_running(netdev)) {
8545 /* Bring down the card, while avoiding PCI I/O */
8546 do_s2io_card_down(sp, 0);
Linas Vepstasd796fdb2007-05-14 18:37:30 -05008547 }
8548 pci_disable_device(pdev);
8549
8550 return PCI_ERS_RESULT_NEED_RESET;
8551}
8552
8553/**
8554 * s2io_io_slot_reset - called after the pci bus has been reset.
8555 * @pdev: Pointer to PCI device
8556 *
8557 * Restart the card from scratch, as if from a cold-boot.
8558 * At this point, the card has exprienced a hard reset,
8559 * followed by fixups by BIOS, and has its config space
8560 * set up identically to what it was at cold boot.
8561 */
8562static pci_ers_result_t s2io_io_slot_reset(struct pci_dev *pdev)
8563{
8564 struct net_device *netdev = pci_get_drvdata(pdev);
8565 struct s2io_nic *sp = netdev->priv;
8566
8567 if (pci_enable_device(pdev)) {
8568 printk(KERN_ERR "s2io: "
8569 "Cannot re-enable PCI device after reset.\n");
8570 return PCI_ERS_RESULT_DISCONNECT;
8571 }
8572
8573 pci_set_master(pdev);
8574 s2io_reset(sp);
8575
8576 return PCI_ERS_RESULT_RECOVERED;
8577}
8578
8579/**
8580 * s2io_io_resume - called when traffic can start flowing again.
8581 * @pdev: Pointer to PCI device
8582 *
8583 * This callback is called when the error recovery driver tells
8584 * us that its OK to resume normal operation.
8585 */
8586static void s2io_io_resume(struct pci_dev *pdev)
8587{
8588 struct net_device *netdev = pci_get_drvdata(pdev);
8589 struct s2io_nic *sp = netdev->priv;
8590
8591 if (netif_running(netdev)) {
8592 if (s2io_card_up(sp)) {
8593 printk(KERN_ERR "s2io: "
8594 "Can't bring device back up after reset.\n");
8595 return;
8596 }
8597
8598 if (s2io_set_mac_addr(netdev, netdev->dev_addr) == FAILURE) {
8599 s2io_card_down(sp);
8600 printk(KERN_ERR "s2io: "
8601 "Can't resetore mac addr after reset.\n");
8602 return;
8603 }
8604 }
8605
8606 netif_device_attach(netdev);
8607 netif_wake_queue(netdev);
8608}