Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * smctr.c: A network driver for the SMC Token Ring Adapters. |
| 3 | * |
| 4 | * Written by Jay Schulist <jschlst@samba.org> |
| 5 | * |
| 6 | * This software may be used and distributed according to the terms |
| 7 | * of the GNU General Public License, incorporated herein by reference. |
| 8 | * |
| 9 | * This device driver works with the following SMC adapters: |
| 10 | * - SMC TokenCard Elite (8115T, chips 825/584) |
| 11 | * - SMC TokenCard Elite/A MCA (8115T/A, chips 825/594) |
| 12 | * |
| 13 | * Source(s): |
| 14 | * - SMC TokenCard SDK. |
| 15 | * |
| 16 | * Maintainer(s): |
| 17 | * JS Jay Schulist <jschlst@samba.org> |
| 18 | * |
| 19 | * Changes: |
| 20 | * 07102000 JS Fixed a timing problem in smctr_wait_cmd(); |
| 21 | * Also added a bit more discriptive error msgs. |
| 22 | * 07122000 JS Fixed problem with detecting a card with |
| 23 | * module io/irq/mem specified. |
| 24 | * |
| 25 | * To do: |
| 26 | * 1. Multicast support. |
| 27 | * |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 28 | * Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk> 2002/10/28 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/kernel.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/fcntl.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/ptrace.h> |
| 37 | #include <linux/ioport.h> |
| 38 | #include <linux/in.h> |
| 39 | #include <linux/slab.h> |
| 40 | #include <linux/string.h> |
| 41 | #include <linux/time.h> |
| 42 | #include <linux/errno.h> |
| 43 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/mca-legacy.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/netdevice.h> |
| 47 | #include <linux/etherdevice.h> |
| 48 | #include <linux/skbuff.h> |
| 49 | #include <linux/trdevice.h> |
| 50 | #include <linux/bitops.h> |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 51 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #include <asm/system.h> |
| 54 | #include <asm/io.h> |
| 55 | #include <asm/dma.h> |
| 56 | #include <asm/irq.h> |
| 57 | |
| 58 | #if BITS_PER_LONG == 64 |
| 59 | #error FIXME: driver does not support 64-bit platforms |
| 60 | #endif |
| 61 | |
| 62 | #include "smctr.h" /* Our Stuff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n"; |
| 65 | static const char cardname[] = "smctr"; |
| 66 | |
| 67 | |
| 68 | #define SMCTR_IO_EXTENT 20 |
| 69 | |
| 70 | #ifdef CONFIG_MCA_LEGACY |
| 71 | static unsigned int smctr_posid = 0x6ec6; |
| 72 | #endif |
| 73 | |
| 74 | static int ringspeed; |
| 75 | |
| 76 | /* SMC Name of the Adapter. */ |
| 77 | static char smctr_name[] = "SMC TokenCard"; |
Adrian Bunk | de70b4c | 2005-05-02 03:46:43 +0200 | [diff] [blame] | 78 | static char *smctr_model = "Unknown"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* Use 0 for production, 1 for verification, 2 for debug, and |
| 81 | * 3 for very verbose debug. |
| 82 | */ |
| 83 | #ifndef SMCTR_DEBUG |
| 84 | #define SMCTR_DEBUG 1 |
| 85 | #endif |
| 86 | static unsigned int smctr_debug = SMCTR_DEBUG; |
| 87 | |
| 88 | /* smctr.c prototypes and functions are arranged alphabeticly |
| 89 | * for clearity, maintainability and pure old fashion fun. |
| 90 | */ |
| 91 | /* A */ |
| 92 | static int smctr_alloc_shared_memory(struct net_device *dev); |
| 93 | |
| 94 | /* B */ |
| 95 | static int smctr_bypass_state(struct net_device *dev); |
| 96 | |
| 97 | /* C */ |
| 98 | static int smctr_checksum_firmware(struct net_device *dev); |
| 99 | static int __init smctr_chk_isa(struct net_device *dev); |
| 100 | static int smctr_chg_rx_mask(struct net_device *dev); |
| 101 | static int smctr_clear_int(struct net_device *dev); |
| 102 | static int smctr_clear_trc_reset(int ioaddr); |
| 103 | static int smctr_close(struct net_device *dev); |
| 104 | |
| 105 | /* D */ |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 106 | static int smctr_decode_firmware(struct net_device *dev, |
| 107 | const struct firmware *fw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static int smctr_disable_16bit(struct net_device *dev); |
| 109 | static int smctr_disable_adapter_ctrl_store(struct net_device *dev); |
| 110 | static int smctr_disable_bic_int(struct net_device *dev); |
| 111 | |
| 112 | /* E */ |
| 113 | static int smctr_enable_16bit(struct net_device *dev); |
| 114 | static int smctr_enable_adapter_ctrl_store(struct net_device *dev); |
| 115 | static int smctr_enable_adapter_ram(struct net_device *dev); |
| 116 | static int smctr_enable_bic_int(struct net_device *dev); |
| 117 | |
| 118 | /* G */ |
| 119 | static int __init smctr_get_boardid(struct net_device *dev, int mca); |
| 120 | static int smctr_get_group_address(struct net_device *dev); |
| 121 | static int smctr_get_functional_address(struct net_device *dev); |
| 122 | static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev); |
| 123 | static int smctr_get_physical_drop_number(struct net_device *dev); |
| 124 | static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue); |
| 125 | static int smctr_get_station_id(struct net_device *dev); |
| 126 | static struct net_device_stats *smctr_get_stats(struct net_device *dev); |
| 127 | static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue, |
| 128 | __u16 bytes_count); |
| 129 | static int smctr_get_upstream_neighbor_addr(struct net_device *dev); |
| 130 | |
| 131 | /* H */ |
| 132 | static int smctr_hardware_send_packet(struct net_device *dev, |
| 133 | struct net_local *tp); |
| 134 | /* I */ |
| 135 | static int smctr_init_acbs(struct net_device *dev); |
| 136 | static int smctr_init_adapter(struct net_device *dev); |
| 137 | static int smctr_init_card_real(struct net_device *dev); |
| 138 | static int smctr_init_rx_bdbs(struct net_device *dev); |
| 139 | static int smctr_init_rx_fcbs(struct net_device *dev); |
| 140 | static int smctr_init_shared_memory(struct net_device *dev); |
| 141 | static int smctr_init_tx_bdbs(struct net_device *dev); |
| 142 | static int smctr_init_tx_fcbs(struct net_device *dev); |
| 143 | static int smctr_internal_self_test(struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 144 | static irqreturn_t smctr_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | static int smctr_issue_enable_int_cmd(struct net_device *dev, |
| 146 | __u16 interrupt_enable_mask); |
| 147 | static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, |
| 148 | __u16 ibits); |
| 149 | static int smctr_issue_init_timers_cmd(struct net_device *dev); |
| 150 | static int smctr_issue_init_txrx_cmd(struct net_device *dev); |
| 151 | static int smctr_issue_insert_cmd(struct net_device *dev); |
| 152 | static int smctr_issue_read_ring_status_cmd(struct net_device *dev); |
| 153 | static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt); |
| 154 | static int smctr_issue_remove_cmd(struct net_device *dev); |
| 155 | static int smctr_issue_resume_acb_cmd(struct net_device *dev); |
| 156 | static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue); |
| 157 | static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue); |
| 158 | static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue); |
| 159 | static int smctr_issue_test_internal_rom_cmd(struct net_device *dev); |
| 160 | static int smctr_issue_test_hic_cmd(struct net_device *dev); |
| 161 | static int smctr_issue_test_mac_reg_cmd(struct net_device *dev); |
| 162 | static int smctr_issue_trc_loopback_cmd(struct net_device *dev); |
| 163 | static int smctr_issue_tri_loopback_cmd(struct net_device *dev); |
| 164 | static int smctr_issue_write_byte_cmd(struct net_device *dev, |
| 165 | short aword_cnt, void *byte); |
| 166 | static int smctr_issue_write_word_cmd(struct net_device *dev, |
| 167 | short aword_cnt, void *word); |
| 168 | |
| 169 | /* J */ |
| 170 | static int smctr_join_complete_state(struct net_device *dev); |
| 171 | |
| 172 | /* L */ |
| 173 | static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev); |
| 174 | static int smctr_load_firmware(struct net_device *dev); |
| 175 | static int smctr_load_node_addr(struct net_device *dev); |
| 176 | static int smctr_lobe_media_test(struct net_device *dev); |
| 177 | static int smctr_lobe_media_test_cmd(struct net_device *dev); |
| 178 | static int smctr_lobe_media_test_state(struct net_device *dev); |
| 179 | |
| 180 | /* M */ |
| 181 | static int smctr_make_8025_hdr(struct net_device *dev, |
| 182 | MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc); |
| 183 | static int smctr_make_access_pri(struct net_device *dev, |
| 184 | MAC_SUB_VECTOR *tsv); |
| 185 | static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv); |
| 186 | static int smctr_make_auth_funct_class(struct net_device *dev, |
| 187 | MAC_SUB_VECTOR *tsv); |
| 188 | static int smctr_make_corr(struct net_device *dev, |
| 189 | MAC_SUB_VECTOR *tsv, __u16 correlator); |
| 190 | static int smctr_make_funct_addr(struct net_device *dev, |
| 191 | MAC_SUB_VECTOR *tsv); |
| 192 | static int smctr_make_group_addr(struct net_device *dev, |
| 193 | MAC_SUB_VECTOR *tsv); |
| 194 | static int smctr_make_phy_drop_num(struct net_device *dev, |
| 195 | MAC_SUB_VECTOR *tsv); |
| 196 | static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv); |
| 197 | static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv); |
| 198 | static int smctr_make_ring_station_status(struct net_device *dev, |
| 199 | MAC_SUB_VECTOR *tsv); |
| 200 | static int smctr_make_ring_station_version(struct net_device *dev, |
| 201 | MAC_SUB_VECTOR *tsv); |
| 202 | static int smctr_make_tx_status_code(struct net_device *dev, |
| 203 | MAC_SUB_VECTOR *tsv, __u16 tx_fstatus); |
| 204 | static int smctr_make_upstream_neighbor_addr(struct net_device *dev, |
| 205 | MAC_SUB_VECTOR *tsv); |
| 206 | static int smctr_make_wrap_data(struct net_device *dev, |
| 207 | MAC_SUB_VECTOR *tsv); |
| 208 | |
| 209 | /* O */ |
| 210 | static int smctr_open(struct net_device *dev); |
| 211 | static int smctr_open_tr(struct net_device *dev); |
| 212 | |
| 213 | /* P */ |
| 214 | struct net_device *smctr_probe(int unit); |
| 215 | static int __init smctr_probe1(struct net_device *dev, int ioaddr); |
| 216 | static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size, |
| 217 | struct net_device *dev, __u16 rx_status); |
| 218 | |
| 219 | /* R */ |
| 220 | static int smctr_ram_memory_test(struct net_device *dev); |
| 221 | static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf, |
| 222 | __u16 *correlator); |
| 223 | static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf, |
| 224 | __u16 *correlator); |
| 225 | static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf); |
| 226 | static int smctr_rcv_rq_addr_state_attch(struct net_device *dev, |
| 227 | MAC_HEADER *rmf, __u16 *correlator); |
| 228 | static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf, |
| 229 | __u16 *correlator); |
| 230 | static int smctr_reset_adapter(struct net_device *dev); |
| 231 | static int smctr_restart_tx_chain(struct net_device *dev, short queue); |
| 232 | static int smctr_ring_status_chg(struct net_device *dev); |
| 233 | static int smctr_rx_frame(struct net_device *dev); |
| 234 | |
| 235 | /* S */ |
| 236 | static int smctr_send_dat(struct net_device *dev); |
| 237 | static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev); |
| 238 | static int smctr_send_lobe_media_test(struct net_device *dev); |
| 239 | static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf, |
| 240 | __u16 correlator); |
| 241 | static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf, |
| 242 | __u16 correlator); |
| 243 | static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf, |
| 244 | __u16 correlator); |
| 245 | static int smctr_send_rpt_tx_forward(struct net_device *dev, |
| 246 | MAC_HEADER *rmf, __u16 tx_fstatus); |
| 247 | static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf, |
| 248 | __u16 rcode, __u16 correlator); |
| 249 | static int smctr_send_rq_init(struct net_device *dev); |
| 250 | static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf, |
| 251 | __u16 *tx_fstatus); |
| 252 | static int smctr_set_auth_access_pri(struct net_device *dev, |
| 253 | MAC_SUB_VECTOR *rsv); |
| 254 | static int smctr_set_auth_funct_class(struct net_device *dev, |
| 255 | MAC_SUB_VECTOR *rsv); |
| 256 | static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv, |
| 257 | __u16 *correlator); |
| 258 | static int smctr_set_error_timer_value(struct net_device *dev, |
| 259 | MAC_SUB_VECTOR *rsv); |
| 260 | static int smctr_set_frame_forward(struct net_device *dev, |
| 261 | MAC_SUB_VECTOR *rsv, __u8 dc_sc); |
| 262 | static int smctr_set_local_ring_num(struct net_device *dev, |
| 263 | MAC_SUB_VECTOR *rsv); |
| 264 | static unsigned short smctr_set_ctrl_attention(struct net_device *dev); |
| 265 | static void smctr_set_multicast_list(struct net_device *dev); |
| 266 | static int smctr_set_page(struct net_device *dev, __u8 *buf); |
| 267 | static int smctr_set_phy_drop(struct net_device *dev, |
| 268 | MAC_SUB_VECTOR *rsv); |
| 269 | static int smctr_set_ring_speed(struct net_device *dev); |
| 270 | static int smctr_set_rx_look_ahead(struct net_device *dev); |
| 271 | static int smctr_set_trc_reset(int ioaddr); |
| 272 | static int smctr_setup_single_cmd(struct net_device *dev, |
| 273 | __u16 command, __u16 subcommand); |
| 274 | static int smctr_setup_single_cmd_w_data(struct net_device *dev, |
| 275 | __u16 command, __u16 subcommand); |
| 276 | static char *smctr_malloc(struct net_device *dev, __u16 size); |
| 277 | static int smctr_status_chg(struct net_device *dev); |
| 278 | |
| 279 | /* T */ |
| 280 | static void smctr_timeout(struct net_device *dev); |
| 281 | static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb, |
| 282 | __u16 queue); |
| 283 | static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue); |
| 284 | static unsigned short smctr_tx_move_frame(struct net_device *dev, |
| 285 | struct sk_buff *skb, __u8 *pbuff, unsigned int bytes); |
| 286 | |
| 287 | /* U */ |
| 288 | static int smctr_update_err_stats(struct net_device *dev); |
| 289 | static int smctr_update_rx_chain(struct net_device *dev, __u16 queue); |
| 290 | static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb, |
| 291 | __u16 queue); |
| 292 | |
| 293 | /* W */ |
| 294 | static int smctr_wait_cmd(struct net_device *dev); |
| 295 | static int smctr_wait_while_cbusy(struct net_device *dev); |
| 296 | |
| 297 | #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X) |
| 298 | #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X) |
| 299 | #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X)) |
| 300 | |
| 301 | /* Allocate Adapter Shared Memory. |
| 302 | * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the |
| 303 | * function "get_num_rx_bdbs" below!!! |
| 304 | * |
| 305 | * Order of memory allocation: |
| 306 | * |
| 307 | * 0. Initial System Configuration Block Pointer |
| 308 | * 1. System Configuration Block |
| 309 | * 2. System Control Block |
| 310 | * 3. Action Command Block |
| 311 | * 4. Interrupt Status Block |
| 312 | * |
| 313 | * 5. MAC TX FCB'S |
| 314 | * 6. NON-MAC TX FCB'S |
| 315 | * 7. MAC TX BDB'S |
| 316 | * 8. NON-MAC TX BDB'S |
| 317 | * 9. MAC RX FCB'S |
| 318 | * 10. NON-MAC RX FCB'S |
| 319 | * 11. MAC RX BDB'S |
| 320 | * 12. NON-MAC RX BDB'S |
| 321 | * 13. MAC TX Data Buffer( 1, 256 byte buffer) |
| 322 | * 14. MAC RX Data Buffer( 1, 256 byte buffer) |
| 323 | * |
| 324 | * 15. NON-MAC TX Data Buffer |
| 325 | * 16. NON-MAC RX Data Buffer |
| 326 | */ |
| 327 | static int smctr_alloc_shared_memory(struct net_device *dev) |
| 328 | { |
| 329 | struct net_local *tp = netdev_priv(dev); |
| 330 | |
| 331 | if(smctr_debug > 10) |
| 332 | printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name); |
| 333 | |
| 334 | /* Allocate initial System Control Block pointer. |
| 335 | * This pointer is located in the last page, last offset - 4. |
| 336 | */ |
| 337 | tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400) |
| 338 | - (long)ISCP_BLOCK_SIZE); |
| 339 | |
| 340 | /* Allocate System Control Blocks. */ |
| 341 | tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock)); |
| 342 | PARAGRAPH_BOUNDRY(tp->sh_mem_used); |
| 343 | |
| 344 | tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock)); |
| 345 | PARAGRAPH_BOUNDRY(tp->sh_mem_used); |
| 346 | |
| 347 | tp->acb_head = (ACBlock *)smctr_malloc(dev, |
| 348 | sizeof(ACBlock)*tp->num_acbs); |
| 349 | PARAGRAPH_BOUNDRY(tp->sh_mem_used); |
| 350 | |
| 351 | tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock)); |
| 352 | PARAGRAPH_BOUNDRY(tp->sh_mem_used); |
| 353 | |
| 354 | tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE); |
| 355 | PARAGRAPH_BOUNDRY(tp->sh_mem_used); |
| 356 | |
| 357 | /* Allocate transmit FCBs. */ |
| 358 | tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev, |
| 359 | sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]); |
| 360 | |
| 361 | tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev, |
| 362 | sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]); |
| 363 | |
| 364 | tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev, |
| 365 | sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]); |
| 366 | |
| 367 | /* Allocate transmit BDBs. */ |
| 368 | tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, |
| 369 | sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]); |
| 370 | |
| 371 | tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, |
| 372 | sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]); |
| 373 | |
| 374 | tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev, |
| 375 | sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]); |
| 376 | |
| 377 | /* Allocate receive FCBs. */ |
| 378 | tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev, |
| 379 | sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]); |
| 380 | |
| 381 | tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev, |
| 382 | sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]); |
| 383 | |
| 384 | /* Allocate receive BDBs. */ |
| 385 | tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, |
| 386 | sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]); |
| 387 | |
| 388 | tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0); |
| 389 | |
| 390 | tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, |
| 391 | sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]); |
| 392 | |
| 393 | tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0); |
| 394 | |
| 395 | /* Allocate MAC transmit buffers. |
| 396 | * MAC Tx Buffers doen't have to be on an ODD Boundry. |
| 397 | */ |
| 398 | tp->tx_buff_head[MAC_QUEUE] |
| 399 | = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]); |
| 400 | tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE]; |
| 401 | tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0); |
| 402 | |
| 403 | /* Allocate BUG transmit buffers. */ |
| 404 | tp->tx_buff_head[BUG_QUEUE] |
| 405 | = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]); |
| 406 | tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE]; |
| 407 | tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0); |
| 408 | |
| 409 | /* Allocate MAC receive data buffers. |
| 410 | * MAC Rx buffer doesn't have to be on a 256 byte boundary. |
| 411 | */ |
| 412 | tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, |
| 413 | RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]); |
| 414 | tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0); |
| 415 | |
| 416 | /* Allocate Non-MAC transmit buffers. |
| 417 | * ?? For maximum Netware performance, put Tx Buffers on |
| 418 | * ODD Boundry and then restore malloc to Even Boundrys. |
| 419 | */ |
| 420 | smctr_malloc(dev, 1L); |
| 421 | tp->tx_buff_head[NON_MAC_QUEUE] |
| 422 | = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]); |
| 423 | tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE]; |
| 424 | tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0); |
| 425 | smctr_malloc(dev, 1L); |
| 426 | |
| 427 | /* Allocate Non-MAC receive data buffers. |
| 428 | * To guarantee a minimum of 256 contigous memory to |
| 429 | * UM_Receive_Packet's lookahead pointer, before a page |
| 430 | * change or ring end is encountered, place each rx buffer on |
| 431 | * a 256 byte boundary. |
| 432 | */ |
| 433 | smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used)); |
| 434 | tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, |
| 435 | RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]); |
| 436 | tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0); |
| 437 | |
| 438 | return (0); |
| 439 | } |
| 440 | |
| 441 | /* Enter Bypass state. */ |
| 442 | static int smctr_bypass_state(struct net_device *dev) |
| 443 | { |
| 444 | int err; |
| 445 | |
| 446 | if(smctr_debug > 10) |
| 447 | printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name); |
| 448 | |
| 449 | err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE); |
| 450 | |
| 451 | return (err); |
| 452 | } |
| 453 | |
| 454 | static int smctr_checksum_firmware(struct net_device *dev) |
| 455 | { |
| 456 | struct net_local *tp = netdev_priv(dev); |
| 457 | __u16 i, checksum = 0; |
| 458 | |
| 459 | if(smctr_debug > 10) |
| 460 | printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name); |
| 461 | |
| 462 | smctr_enable_adapter_ctrl_store(dev); |
| 463 | |
| 464 | for(i = 0; i < CS_RAM_SIZE; i += 2) |
| 465 | checksum += *((__u16 *)(tp->ram_access + i)); |
| 466 | |
| 467 | tp->microcode_version = *(__u16 *)(tp->ram_access |
| 468 | + CS_RAM_VERSION_OFFSET); |
| 469 | tp->microcode_version >>= 8; |
| 470 | |
| 471 | smctr_disable_adapter_ctrl_store(dev); |
| 472 | |
| 473 | if(checksum) |
| 474 | return (checksum); |
| 475 | |
| 476 | return (0); |
| 477 | } |
| 478 | |
| 479 | static int __init smctr_chk_mca(struct net_device *dev) |
| 480 | { |
| 481 | #ifdef CONFIG_MCA_LEGACY |
| 482 | struct net_local *tp = netdev_priv(dev); |
| 483 | int current_slot; |
| 484 | __u8 r1, r2, r3, r4, r5; |
| 485 | |
| 486 | current_slot = mca_find_unused_adapter(smctr_posid, 0); |
| 487 | if(current_slot == MCA_NOTFOUND) |
| 488 | return (-ENODEV); |
| 489 | |
| 490 | mca_set_adapter_name(current_slot, smctr_name); |
| 491 | mca_mark_as_used(current_slot); |
| 492 | tp->slot_num = current_slot; |
| 493 | |
| 494 | r1 = mca_read_stored_pos(tp->slot_num, 2); |
| 495 | r2 = mca_read_stored_pos(tp->slot_num, 3); |
| 496 | |
| 497 | if(tp->slot_num) |
| 498 | outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT)); |
| 499 | else |
| 500 | outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT)); |
| 501 | |
| 502 | r1 = inb(CNFG_POS_REG1); |
| 503 | r2 = inb(CNFG_POS_REG0); |
| 504 | |
| 505 | tp->bic_type = BIC_594_CHIP; |
| 506 | |
| 507 | /* IO */ |
| 508 | r2 = mca_read_stored_pos(tp->slot_num, 2); |
| 509 | r2 &= 0xF0; |
| 510 | dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800; |
| 511 | request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name); |
| 512 | |
| 513 | /* IRQ */ |
| 514 | r5 = mca_read_stored_pos(tp->slot_num, 5); |
| 515 | r5 &= 0xC; |
| 516 | switch(r5) |
| 517 | { |
| 518 | case 0: |
| 519 | dev->irq = 3; |
| 520 | break; |
| 521 | |
| 522 | case 0x4: |
| 523 | dev->irq = 4; |
| 524 | break; |
| 525 | |
| 526 | case 0x8: |
| 527 | dev->irq = 10; |
| 528 | break; |
| 529 | |
| 530 | default: |
| 531 | dev->irq = 15; |
| 532 | break; |
| 533 | } |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 534 | if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | release_region(dev->base_addr, SMCTR_IO_EXTENT); |
| 536 | return -ENODEV; |
| 537 | } |
| 538 | |
| 539 | /* Get RAM base */ |
| 540 | r3 = mca_read_stored_pos(tp->slot_num, 3); |
| 541 | tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000; |
| 542 | if (r3 & 0x8) |
| 543 | tp->ram_base += 0x010000; |
| 544 | if (r3 & 0x80) |
| 545 | tp->ram_base += 0xF00000; |
| 546 | |
| 547 | /* Get Ram Size */ |
| 548 | r3 &= 0x30; |
| 549 | r3 >>= 4; |
| 550 | |
| 551 | tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3; |
| 552 | tp->ram_size = (__u16)CNFG_SIZE_64KB; |
| 553 | tp->board_id |= TOKEN_MEDIA; |
| 554 | |
| 555 | r4 = mca_read_stored_pos(tp->slot_num, 4); |
| 556 | tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000; |
| 557 | if (r4 & 0x8) |
| 558 | tp->rom_base += 0x010000; |
| 559 | |
| 560 | /* Get ROM size. */ |
| 561 | r4 >>= 4; |
| 562 | switch (r4) { |
| 563 | case 0: |
| 564 | tp->rom_size = CNFG_SIZE_8KB; |
| 565 | break; |
| 566 | case 1: |
| 567 | tp->rom_size = CNFG_SIZE_16KB; |
| 568 | break; |
| 569 | case 2: |
| 570 | tp->rom_size = CNFG_SIZE_32KB; |
| 571 | break; |
| 572 | default: |
| 573 | tp->rom_size = ROM_DISABLE; |
| 574 | } |
| 575 | |
| 576 | /* Get Media Type. */ |
| 577 | r5 = mca_read_stored_pos(tp->slot_num, 5); |
| 578 | r5 &= CNFG_MEDIA_TYPE_MASK; |
| 579 | switch(r5) |
| 580 | { |
| 581 | case (0): |
| 582 | tp->media_type = MEDIA_STP_4; |
| 583 | break; |
| 584 | |
| 585 | case (1): |
| 586 | tp->media_type = MEDIA_STP_16; |
| 587 | break; |
| 588 | |
| 589 | case (3): |
| 590 | tp->media_type = MEDIA_UTP_16; |
| 591 | break; |
| 592 | |
| 593 | default: |
| 594 | tp->media_type = MEDIA_UTP_4; |
| 595 | break; |
| 596 | } |
| 597 | tp->media_menu = 14; |
| 598 | |
| 599 | r2 = mca_read_stored_pos(tp->slot_num, 2); |
| 600 | if(!(r2 & 0x02)) |
| 601 | tp->mode_bits |= EARLY_TOKEN_REL; |
| 602 | |
| 603 | /* Disable slot */ |
| 604 | outb(CNFG_POS_CONTROL_REG, 0); |
| 605 | |
| 606 | tp->board_id = smctr_get_boardid(dev, 1); |
| 607 | switch(tp->board_id & 0xffff) |
| 608 | { |
| 609 | case WD8115TA: |
| 610 | smctr_model = "8115T/A"; |
| 611 | break; |
| 612 | |
| 613 | case WD8115T: |
| 614 | if(tp->extra_info & CHIP_REV_MASK) |
| 615 | smctr_model = "8115T rev XE"; |
| 616 | else |
| 617 | smctr_model = "8115T rev XD"; |
| 618 | break; |
| 619 | |
| 620 | default: |
| 621 | smctr_model = "Unknown"; |
| 622 | break; |
| 623 | } |
| 624 | |
| 625 | return (0); |
| 626 | #else |
| 627 | return (-1); |
| 628 | #endif /* CONFIG_MCA_LEGACY */ |
| 629 | } |
| 630 | |
| 631 | static int smctr_chg_rx_mask(struct net_device *dev) |
| 632 | { |
| 633 | struct net_local *tp = netdev_priv(dev); |
| 634 | int err = 0; |
| 635 | |
| 636 | if(smctr_debug > 10) |
| 637 | printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name); |
| 638 | |
| 639 | smctr_enable_16bit(dev); |
| 640 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 641 | |
| 642 | if(tp->mode_bits & LOOPING_MODE_MASK) |
| 643 | tp->config_word0 |= RX_OWN_BIT; |
| 644 | else |
| 645 | tp->config_word0 &= ~RX_OWN_BIT; |
| 646 | |
| 647 | if(tp->receive_mask & PROMISCUOUS_MODE) |
| 648 | tp->config_word0 |= PROMISCUOUS_BIT; |
| 649 | else |
| 650 | tp->config_word0 &= ~PROMISCUOUS_BIT; |
| 651 | |
| 652 | if(tp->receive_mask & ACCEPT_ERR_PACKETS) |
| 653 | tp->config_word0 |= SAVBAD_BIT; |
| 654 | else |
| 655 | tp->config_word0 &= ~SAVBAD_BIT; |
| 656 | |
| 657 | if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) |
| 658 | tp->config_word0 |= RXATMAC; |
| 659 | else |
| 660 | tp->config_word0 &= ~RXATMAC; |
| 661 | |
| 662 | if(tp->receive_mask & ACCEPT_MULTI_PROM) |
| 663 | tp->config_word1 |= MULTICAST_ADDRESS_BIT; |
| 664 | else |
| 665 | tp->config_word1 &= ~MULTICAST_ADDRESS_BIT; |
| 666 | |
| 667 | if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING) |
| 668 | tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS; |
| 669 | else |
| 670 | { |
| 671 | if(tp->receive_mask & ACCEPT_SOURCE_ROUTING) |
| 672 | tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT; |
| 673 | else |
| 674 | tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS; |
| 675 | } |
| 676 | |
| 677 | if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0, |
| 678 | &tp->config_word0))) |
| 679 | { |
| 680 | return (err); |
| 681 | } |
| 682 | |
| 683 | if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1, |
| 684 | &tp->config_word1))) |
| 685 | { |
| 686 | return (err); |
| 687 | } |
| 688 | |
| 689 | smctr_disable_16bit(dev); |
| 690 | |
| 691 | return (0); |
| 692 | } |
| 693 | |
| 694 | static int smctr_clear_int(struct net_device *dev) |
| 695 | { |
| 696 | struct net_local *tp = netdev_priv(dev); |
| 697 | |
| 698 | outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR); |
| 699 | |
| 700 | return (0); |
| 701 | } |
| 702 | |
| 703 | static int smctr_clear_trc_reset(int ioaddr) |
| 704 | { |
| 705 | __u8 r; |
| 706 | |
| 707 | r = inb(ioaddr + MSR); |
| 708 | outb(~MSR_RST & r, ioaddr + MSR); |
| 709 | |
| 710 | return (0); |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | * The inverse routine to smctr_open(). |
| 715 | */ |
| 716 | static int smctr_close(struct net_device *dev) |
| 717 | { |
| 718 | struct net_local *tp = netdev_priv(dev); |
| 719 | struct sk_buff *skb; |
| 720 | int err; |
| 721 | |
| 722 | netif_stop_queue(dev); |
| 723 | |
| 724 | tp->cleanup = 1; |
| 725 | |
| 726 | /* Check to see if adapter is already in a closed state. */ |
| 727 | if(tp->status != OPEN) |
| 728 | return (0); |
| 729 | |
| 730 | smctr_enable_16bit(dev); |
| 731 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 732 | |
| 733 | if((err = smctr_issue_remove_cmd(dev))) |
| 734 | { |
| 735 | smctr_disable_16bit(dev); |
| 736 | return (err); |
| 737 | } |
| 738 | |
| 739 | for(;;) |
| 740 | { |
| 741 | skb = skb_dequeue(&tp->SendSkbQueue); |
| 742 | if(skb == NULL) |
| 743 | break; |
| 744 | tp->QueueSkb++; |
| 745 | dev_kfree_skb(skb); |
| 746 | } |
| 747 | |
| 748 | |
| 749 | return (0); |
| 750 | } |
| 751 | |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 752 | static int smctr_decode_firmware(struct net_device *dev, |
| 753 | const struct firmware *fw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
| 755 | struct net_local *tp = netdev_priv(dev); |
| 756 | short bit = 0x80, shift = 12; |
| 757 | DECODE_TREE_NODE *tree; |
| 758 | short branch, tsize; |
| 759 | __u16 buff = 0; |
| 760 | long weight; |
| 761 | __u8 *ucode; |
| 762 | __u16 *mem; |
| 763 | |
| 764 | if(smctr_debug > 10) |
| 765 | printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name); |
| 766 | |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 767 | weight = *(long *)(fw->data + WEIGHT_OFFSET); |
| 768 | tsize = *(__u8 *)(fw->data + TREE_SIZE_OFFSET); |
| 769 | tree = (DECODE_TREE_NODE *)(fw->data + TREE_OFFSET); |
| 770 | ucode = (__u8 *)(fw->data + TREE_OFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | + (tsize * sizeof(DECODE_TREE_NODE))); |
| 772 | mem = (__u16 *)(tp->ram_access); |
| 773 | |
| 774 | while(weight) |
| 775 | { |
| 776 | branch = ROOT; |
| 777 | while((tree + branch)->tag != LEAF && weight) |
| 778 | { |
| 779 | branch = *ucode & bit ? (tree + branch)->llink |
| 780 | : (tree + branch)->rlink; |
| 781 | |
| 782 | bit >>= 1; |
| 783 | weight--; |
| 784 | |
| 785 | if(bit == 0) |
| 786 | { |
| 787 | bit = 0x80; |
| 788 | ucode++; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | buff |= (tree + branch)->info << shift; |
| 793 | shift -= 4; |
| 794 | |
| 795 | if(shift < 0) |
| 796 | { |
| 797 | *(mem++) = SWAP_BYTES(buff); |
| 798 | buff = 0; |
| 799 | shift = 12; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | /* The following assumes the Control Store Memory has |
| 804 | * been initialized to zero. If the last partial word |
| 805 | * is zero, it will not be written. |
| 806 | */ |
| 807 | if(buff) |
| 808 | *(mem++) = SWAP_BYTES(buff); |
| 809 | |
| 810 | return (0); |
| 811 | } |
| 812 | |
| 813 | static int smctr_disable_16bit(struct net_device *dev) |
| 814 | { |
| 815 | return (0); |
| 816 | } |
| 817 | |
| 818 | /* |
| 819 | * On Exit, Adapter is: |
| 820 | * 1. TRC is in a reset state and un-initialized. |
| 821 | * 2. Adapter memory is enabled. |
| 822 | * 3. Control Store memory is out of context (-WCSS is 1). |
| 823 | */ |
| 824 | static int smctr_disable_adapter_ctrl_store(struct net_device *dev) |
| 825 | { |
| 826 | struct net_local *tp = netdev_priv(dev); |
| 827 | int ioaddr = dev->base_addr; |
| 828 | |
| 829 | if(smctr_debug > 10) |
| 830 | printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name); |
| 831 | |
| 832 | tp->trc_mask |= CSR_WCSS; |
| 833 | outb(tp->trc_mask, ioaddr + CSR); |
| 834 | |
| 835 | return (0); |
| 836 | } |
| 837 | |
| 838 | static int smctr_disable_bic_int(struct net_device *dev) |
| 839 | { |
| 840 | struct net_local *tp = netdev_priv(dev); |
| 841 | int ioaddr = dev->base_addr; |
| 842 | |
| 843 | tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY |
| 844 | | CSR_MSKTINT | CSR_WCSS; |
| 845 | outb(tp->trc_mask, ioaddr + CSR); |
| 846 | |
| 847 | return (0); |
| 848 | } |
| 849 | |
| 850 | static int smctr_enable_16bit(struct net_device *dev) |
| 851 | { |
| 852 | struct net_local *tp = netdev_priv(dev); |
| 853 | __u8 r; |
| 854 | |
| 855 | if(tp->adapter_bus == BUS_ISA16_TYPE) |
| 856 | { |
| 857 | r = inb(dev->base_addr + LAAR); |
| 858 | outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR); |
| 859 | } |
| 860 | |
| 861 | return (0); |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * To enable the adapter control store memory: |
| 866 | * 1. Adapter must be in a RESET state. |
| 867 | * 2. Adapter memory must be enabled. |
| 868 | * 3. Control Store Memory is in context (-WCSS is 0). |
| 869 | */ |
| 870 | static int smctr_enable_adapter_ctrl_store(struct net_device *dev) |
| 871 | { |
| 872 | struct net_local *tp = netdev_priv(dev); |
| 873 | int ioaddr = dev->base_addr; |
| 874 | |
| 875 | if(smctr_debug > 10) |
| 876 | printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name); |
| 877 | |
| 878 | smctr_set_trc_reset(ioaddr); |
| 879 | smctr_enable_adapter_ram(dev); |
| 880 | |
| 881 | tp->trc_mask &= ~CSR_WCSS; |
| 882 | outb(tp->trc_mask, ioaddr + CSR); |
| 883 | |
| 884 | return (0); |
| 885 | } |
| 886 | |
| 887 | static int smctr_enable_adapter_ram(struct net_device *dev) |
| 888 | { |
| 889 | int ioaddr = dev->base_addr; |
| 890 | __u8 r; |
| 891 | |
| 892 | if(smctr_debug > 10) |
| 893 | printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name); |
| 894 | |
| 895 | r = inb(ioaddr + MSR); |
| 896 | outb(MSR_MEMB | r, ioaddr + MSR); |
| 897 | |
| 898 | return (0); |
| 899 | } |
| 900 | |
| 901 | static int smctr_enable_bic_int(struct net_device *dev) |
| 902 | { |
| 903 | struct net_local *tp = netdev_priv(dev); |
| 904 | int ioaddr = dev->base_addr; |
| 905 | __u8 r; |
| 906 | |
| 907 | switch(tp->bic_type) |
| 908 | { |
| 909 | case (BIC_584_CHIP): |
| 910 | tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS; |
| 911 | outb(tp->trc_mask, ioaddr + CSR); |
| 912 | r = inb(ioaddr + IRR); |
| 913 | outb(r | IRR_IEN, ioaddr + IRR); |
| 914 | break; |
| 915 | |
| 916 | case (BIC_594_CHIP): |
| 917 | tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS; |
| 918 | outb(tp->trc_mask, ioaddr + CSR); |
| 919 | r = inb(ioaddr + IMCCR); |
| 920 | outb(r | IMCCR_EIL, ioaddr + IMCCR); |
| 921 | break; |
| 922 | } |
| 923 | |
| 924 | return (0); |
| 925 | } |
| 926 | |
| 927 | static int __init smctr_chk_isa(struct net_device *dev) |
| 928 | { |
| 929 | struct net_local *tp = netdev_priv(dev); |
| 930 | int ioaddr = dev->base_addr; |
| 931 | __u8 r1, r2, b, chksum = 0; |
| 932 | __u16 r; |
| 933 | int i; |
| 934 | int err = -ENODEV; |
| 935 | |
| 936 | if(smctr_debug > 10) |
| 937 | printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr); |
| 938 | |
| 939 | if((ioaddr & 0x1F) != 0) |
| 940 | goto out; |
| 941 | |
| 942 | /* Grab the region so that no one else tries to probe our ioports. */ |
| 943 | if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) { |
| 944 | err = -EBUSY; |
| 945 | goto out; |
| 946 | } |
| 947 | |
| 948 | /* Checksum SMC node address */ |
| 949 | for(i = 0; i < 8; i++) |
| 950 | { |
| 951 | b = inb(ioaddr + LAR0 + i); |
| 952 | chksum += b; |
| 953 | } |
| 954 | |
| 955 | if (chksum != NODE_ADDR_CKSUM) |
| 956 | goto out2; |
| 957 | |
| 958 | b = inb(ioaddr + BDID); |
| 959 | if(b != BRD_ID_8115T) |
| 960 | { |
| 961 | printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name); |
| 962 | goto out2; |
| 963 | } |
| 964 | |
| 965 | /* Check for 8115T Board ID */ |
| 966 | r2 = 0; |
| 967 | for(r = 0; r < 8; r++) |
| 968 | { |
| 969 | r1 = inb(ioaddr + 0x8 + r); |
| 970 | r2 += r1; |
| 971 | } |
| 972 | |
| 973 | /* value of RegF adds up the sum to 0xFF */ |
| 974 | if((r2 != 0xFF) && (r2 != 0xEE)) |
| 975 | goto out2; |
| 976 | |
| 977 | /* Get adapter ID */ |
| 978 | tp->board_id = smctr_get_boardid(dev, 0); |
| 979 | switch(tp->board_id & 0xffff) |
| 980 | { |
| 981 | case WD8115TA: |
| 982 | smctr_model = "8115T/A"; |
| 983 | break; |
| 984 | |
| 985 | case WD8115T: |
| 986 | if(tp->extra_info & CHIP_REV_MASK) |
| 987 | smctr_model = "8115T rev XE"; |
| 988 | else |
| 989 | smctr_model = "8115T rev XD"; |
| 990 | break; |
| 991 | |
| 992 | default: |
| 993 | smctr_model = "Unknown"; |
| 994 | break; |
| 995 | } |
| 996 | |
| 997 | /* Store BIC type. */ |
| 998 | tp->bic_type = BIC_584_CHIP; |
| 999 | tp->nic_type = NIC_825_CHIP; |
| 1000 | |
| 1001 | /* Copy Ram Size */ |
| 1002 | tp->ram_usable = CNFG_SIZE_16KB; |
| 1003 | tp->ram_size = CNFG_SIZE_64KB; |
| 1004 | |
| 1005 | /* Get 58x Ram Base */ |
| 1006 | r1 = inb(ioaddr); |
| 1007 | r1 &= 0x3F; |
| 1008 | |
| 1009 | r2 = inb(ioaddr + CNFG_LAAR_584); |
| 1010 | r2 &= CNFG_LAAR_MASK; |
| 1011 | r2 <<= 3; |
| 1012 | r2 |= ((r1 & 0x38) >> 3); |
| 1013 | |
| 1014 | tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13); |
| 1015 | |
| 1016 | /* Get 584 Irq */ |
| 1017 | r1 = 0; |
| 1018 | r1 = inb(ioaddr + CNFG_ICR_583); |
| 1019 | r1 &= CNFG_ICR_IR2_584; |
| 1020 | |
| 1021 | r2 = inb(ioaddr + CNFG_IRR_583); |
| 1022 | r2 &= CNFG_IRR_IRQS; /* 0x60 */ |
| 1023 | r2 >>= 5; |
| 1024 | |
| 1025 | switch(r2) |
| 1026 | { |
| 1027 | case 0: |
| 1028 | if(r1 == 0) |
| 1029 | dev->irq = 2; |
| 1030 | else |
| 1031 | dev->irq = 10; |
| 1032 | break; |
| 1033 | |
| 1034 | case 1: |
| 1035 | if(r1 == 0) |
| 1036 | dev->irq = 3; |
| 1037 | else |
| 1038 | dev->irq = 11; |
| 1039 | break; |
| 1040 | |
| 1041 | case 2: |
| 1042 | if(r1 == 0) |
| 1043 | { |
| 1044 | if(tp->extra_info & ALTERNATE_IRQ_BIT) |
| 1045 | dev->irq = 5; |
| 1046 | else |
| 1047 | dev->irq = 4; |
| 1048 | } |
| 1049 | else |
| 1050 | dev->irq = 15; |
| 1051 | break; |
| 1052 | |
| 1053 | case 3: |
| 1054 | if(r1 == 0) |
| 1055 | dev->irq = 7; |
| 1056 | else |
| 1057 | dev->irq = 4; |
| 1058 | break; |
| 1059 | |
| 1060 | default: |
| 1061 | printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name); |
| 1062 | goto out2; |
| 1063 | } |
| 1064 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 1065 | if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | goto out2; |
| 1067 | |
| 1068 | /* Get 58x Rom Base */ |
| 1069 | r1 = inb(ioaddr + CNFG_BIO_583); |
| 1070 | r1 &= 0x3E; |
| 1071 | r1 |= 0x40; |
| 1072 | |
| 1073 | tp->rom_base = (__u32)r1 << 13; |
| 1074 | |
| 1075 | /* Get 58x Rom Size */ |
| 1076 | r1 = inb(ioaddr + CNFG_BIO_583); |
| 1077 | r1 &= 0xC0; |
| 1078 | if(r1 == 0) |
| 1079 | tp->rom_size = ROM_DISABLE; |
| 1080 | else |
| 1081 | { |
| 1082 | r1 >>= 6; |
| 1083 | tp->rom_size = (__u16)CNFG_SIZE_8KB << r1; |
| 1084 | } |
| 1085 | |
| 1086 | /* Get 58x Boot Status */ |
| 1087 | r1 = inb(ioaddr + CNFG_GP2); |
| 1088 | |
| 1089 | tp->mode_bits &= (~BOOT_STATUS_MASK); |
| 1090 | |
| 1091 | if(r1 & CNFG_GP2_BOOT_NIBBLE) |
| 1092 | tp->mode_bits |= BOOT_TYPE_1; |
| 1093 | |
| 1094 | /* Get 58x Zero Wait State */ |
| 1095 | tp->mode_bits &= (~ZERO_WAIT_STATE_MASK); |
| 1096 | |
| 1097 | r1 = inb(ioaddr + CNFG_IRR_583); |
| 1098 | |
| 1099 | if(r1 & CNFG_IRR_ZWS) |
| 1100 | tp->mode_bits |= ZERO_WAIT_STATE_8_BIT; |
| 1101 | |
| 1102 | if(tp->board_id & BOARD_16BIT) |
| 1103 | { |
| 1104 | r1 = inb(ioaddr + CNFG_LAAR_584); |
| 1105 | |
| 1106 | if(r1 & CNFG_LAAR_ZWS) |
| 1107 | tp->mode_bits |= ZERO_WAIT_STATE_16_BIT; |
| 1108 | } |
| 1109 | |
| 1110 | /* Get 584 Media Menu */ |
| 1111 | tp->media_menu = 14; |
| 1112 | r1 = inb(ioaddr + CNFG_IRR_583); |
| 1113 | |
| 1114 | tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */ |
| 1115 | if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA) |
| 1116 | { |
| 1117 | /* Get Advanced Features */ |
| 1118 | if(((r1 & 0x6) >> 1) == 0x3) |
| 1119 | tp->media_type |= MEDIA_UTP_16; |
| 1120 | else |
| 1121 | { |
| 1122 | if(((r1 & 0x6) >> 1) == 0x2) |
| 1123 | tp->media_type |= MEDIA_STP_16; |
| 1124 | else |
| 1125 | { |
| 1126 | if(((r1 & 0x6) >> 1) == 0x1) |
| 1127 | tp->media_type |= MEDIA_UTP_4; |
| 1128 | |
| 1129 | else |
| 1130 | tp->media_type |= MEDIA_STP_4; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | r1 = inb(ioaddr + CNFG_GP2); |
| 1135 | if(!(r1 & 0x2) ) /* GP2_ETRD */ |
| 1136 | tp->mode_bits |= EARLY_TOKEN_REL; |
| 1137 | |
| 1138 | /* see if the chip is corrupted |
| 1139 | if(smctr_read_584_chksum(ioaddr)) |
| 1140 | { |
| 1141 | printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name); |
| 1142 | free_irq(dev->irq, dev); |
| 1143 | goto out2; |
| 1144 | } |
| 1145 | */ |
| 1146 | } |
| 1147 | |
| 1148 | return (0); |
| 1149 | |
| 1150 | out2: |
| 1151 | release_region(ioaddr, SMCTR_IO_EXTENT); |
| 1152 | out: |
| 1153 | return err; |
| 1154 | } |
| 1155 | |
| 1156 | static int __init smctr_get_boardid(struct net_device *dev, int mca) |
| 1157 | { |
| 1158 | struct net_local *tp = netdev_priv(dev); |
| 1159 | int ioaddr = dev->base_addr; |
| 1160 | __u8 r, r1, IdByte; |
| 1161 | __u16 BoardIdMask; |
| 1162 | |
| 1163 | tp->board_id = BoardIdMask = 0; |
| 1164 | |
| 1165 | if(mca) |
| 1166 | { |
| 1167 | BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT); |
| 1168 | tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT); |
| 1169 | } |
| 1170 | else |
| 1171 | { |
| 1172 | BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT); |
| 1173 | tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K |
| 1174 | + NIC_825_BIT + ALTERNATE_IRQ_BIT); |
| 1175 | } |
| 1176 | |
| 1177 | if(!mca) |
| 1178 | { |
| 1179 | r = inb(ioaddr + BID_REG_1); |
| 1180 | r &= 0x0c; |
| 1181 | outb(r, ioaddr + BID_REG_1); |
| 1182 | r = inb(ioaddr + BID_REG_1); |
| 1183 | |
| 1184 | if(r & BID_SIXTEEN_BIT_BIT) |
| 1185 | { |
| 1186 | tp->extra_info |= SLOT_16BIT; |
| 1187 | tp->adapter_bus = BUS_ISA16_TYPE; |
| 1188 | } |
| 1189 | else |
| 1190 | tp->adapter_bus = BUS_ISA8_TYPE; |
| 1191 | } |
| 1192 | else |
| 1193 | tp->adapter_bus = BUS_MCA_TYPE; |
| 1194 | |
| 1195 | /* Get Board Id Byte */ |
| 1196 | IdByte = inb(ioaddr + BID_BOARD_ID_BYTE); |
| 1197 | |
| 1198 | /* if Major version > 1.0 then |
| 1199 | * return; |
| 1200 | */ |
| 1201 | if(IdByte & 0xF8) |
| 1202 | return (-1); |
| 1203 | |
| 1204 | r1 = inb(ioaddr + BID_REG_1); |
| 1205 | r1 &= BID_ICR_MASK; |
| 1206 | r1 |= BID_OTHER_BIT; |
| 1207 | |
| 1208 | outb(r1, ioaddr + BID_REG_1); |
| 1209 | r1 = inb(ioaddr + BID_REG_3); |
| 1210 | |
| 1211 | r1 &= BID_EAR_MASK; |
| 1212 | r1 |= BID_ENGR_PAGE; |
| 1213 | |
| 1214 | outb(r1, ioaddr + BID_REG_3); |
| 1215 | r1 = inb(ioaddr + BID_REG_1); |
| 1216 | r1 &= BID_ICR_MASK; |
| 1217 | r1 |= (BID_RLA | BID_OTHER_BIT); |
| 1218 | |
| 1219 | outb(r1, ioaddr + BID_REG_1); |
| 1220 | |
| 1221 | r1 = inb(ioaddr + BID_REG_1); |
| 1222 | while(r1 & BID_RECALL_DONE_MASK) |
| 1223 | r1 = inb(ioaddr + BID_REG_1); |
| 1224 | |
| 1225 | r = inb(ioaddr + BID_LAR_0 + BID_REG_6); |
| 1226 | |
| 1227 | /* clear chip rev bits */ |
| 1228 | tp->extra_info &= ~CHIP_REV_MASK; |
| 1229 | tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6); |
| 1230 | |
| 1231 | r1 = inb(ioaddr + BID_REG_1); |
| 1232 | r1 &= BID_ICR_MASK; |
| 1233 | r1 |= BID_OTHER_BIT; |
| 1234 | |
| 1235 | outb(r1, ioaddr + BID_REG_1); |
| 1236 | r1 = inb(ioaddr + BID_REG_3); |
| 1237 | |
| 1238 | r1 &= BID_EAR_MASK; |
| 1239 | r1 |= BID_EA6; |
| 1240 | |
| 1241 | outb(r1, ioaddr + BID_REG_3); |
| 1242 | r1 = inb(ioaddr + BID_REG_1); |
| 1243 | |
| 1244 | r1 &= BID_ICR_MASK; |
| 1245 | r1 |= BID_RLA; |
| 1246 | |
| 1247 | outb(r1, ioaddr + BID_REG_1); |
| 1248 | r1 = inb(ioaddr + BID_REG_1); |
| 1249 | |
| 1250 | while(r1 & BID_RECALL_DONE_MASK) |
| 1251 | r1 = inb(ioaddr + BID_REG_1); |
| 1252 | |
| 1253 | return (BoardIdMask); |
| 1254 | } |
| 1255 | |
| 1256 | static int smctr_get_group_address(struct net_device *dev) |
| 1257 | { |
| 1258 | smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR); |
| 1259 | |
| 1260 | return(smctr_wait_cmd(dev)); |
| 1261 | } |
| 1262 | |
| 1263 | static int smctr_get_functional_address(struct net_device *dev) |
| 1264 | { |
| 1265 | smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR); |
| 1266 | |
| 1267 | return(smctr_wait_cmd(dev)); |
| 1268 | } |
| 1269 | |
| 1270 | /* Calculate number of Non-MAC receive BDB's and data buffers. |
| 1271 | * This function must simulate allocateing shared memory exactly |
| 1272 | * as the allocate_shared_memory function above. |
| 1273 | */ |
| 1274 | static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev) |
| 1275 | { |
| 1276 | struct net_local *tp = netdev_priv(dev); |
| 1277 | unsigned int mem_used = 0; |
| 1278 | |
| 1279 | /* Allocate System Control Blocks. */ |
| 1280 | mem_used += sizeof(SCGBlock); |
| 1281 | |
| 1282 | mem_used += TO_PARAGRAPH_BOUNDRY(mem_used); |
| 1283 | mem_used += sizeof(SCLBlock); |
| 1284 | |
| 1285 | mem_used += TO_PARAGRAPH_BOUNDRY(mem_used); |
| 1286 | mem_used += sizeof(ACBlock) * tp->num_acbs; |
| 1287 | |
| 1288 | mem_used += TO_PARAGRAPH_BOUNDRY(mem_used); |
| 1289 | mem_used += sizeof(ISBlock); |
| 1290 | |
| 1291 | mem_used += TO_PARAGRAPH_BOUNDRY(mem_used); |
| 1292 | mem_used += MISC_DATA_SIZE; |
| 1293 | |
| 1294 | /* Allocate transmit FCB's. */ |
| 1295 | mem_used += TO_PARAGRAPH_BOUNDRY(mem_used); |
| 1296 | |
| 1297 | mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]; |
| 1298 | mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]; |
| 1299 | mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]; |
| 1300 | |
| 1301 | /* Allocate transmit BDBs. */ |
| 1302 | mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]; |
| 1303 | mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]; |
| 1304 | mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]; |
| 1305 | |
| 1306 | /* Allocate receive FCBs. */ |
| 1307 | mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]; |
| 1308 | mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]; |
| 1309 | |
| 1310 | /* Allocate receive BDBs. */ |
| 1311 | mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]; |
| 1312 | |
| 1313 | /* Allocate MAC transmit buffers. |
| 1314 | * MAC transmit buffers don't have to be on an ODD Boundry. |
| 1315 | */ |
| 1316 | mem_used += tp->tx_buff_size[MAC_QUEUE]; |
| 1317 | |
| 1318 | /* Allocate BUG transmit buffers. */ |
| 1319 | mem_used += tp->tx_buff_size[BUG_QUEUE]; |
| 1320 | |
| 1321 | /* Allocate MAC receive data buffers. |
| 1322 | * MAC receive buffers don't have to be on a 256 byte boundary. |
| 1323 | */ |
| 1324 | mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]; |
| 1325 | |
| 1326 | /* Allocate Non-MAC transmit buffers. |
| 1327 | * For maximum Netware performance, put Tx Buffers on |
| 1328 | * ODD Boundry,and then restore malloc to Even Boundrys. |
| 1329 | */ |
| 1330 | mem_used += 1L; |
| 1331 | mem_used += tp->tx_buff_size[NON_MAC_QUEUE]; |
| 1332 | mem_used += 1L; |
| 1333 | |
| 1334 | /* CALCULATE NUMBER OF NON-MAC RX BDB'S |
| 1335 | * AND NON-MAC RX DATA BUFFERS |
| 1336 | * |
| 1337 | * Make sure the mem_used offset at this point is the |
| 1338 | * same as in allocate_shared memory or the following |
| 1339 | * boundary adjustment will be incorrect (i.e. not allocating |
| 1340 | * the non-mac receive buffers above cannot change the 256 |
| 1341 | * byte offset). |
| 1342 | * |
| 1343 | * Since this cannot be guaranteed, adding the full 256 bytes |
| 1344 | * to the amount of shared memory used at this point will guaranteed |
| 1345 | * that the rx data buffers do not overflow shared memory. |
| 1346 | */ |
| 1347 | mem_used += 0x100; |
| 1348 | |
| 1349 | return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock))); |
| 1350 | } |
| 1351 | |
| 1352 | static int smctr_get_physical_drop_number(struct net_device *dev) |
| 1353 | { |
| 1354 | smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER); |
| 1355 | |
| 1356 | return(smctr_wait_cmd(dev)); |
| 1357 | } |
| 1358 | |
| 1359 | static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue) |
| 1360 | { |
| 1361 | struct net_local *tp = netdev_priv(dev); |
| 1362 | BDBlock *bdb; |
| 1363 | |
| 1364 | bdb = (BDBlock *)((__u32)tp->ram_access |
| 1365 | + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr)); |
| 1366 | |
| 1367 | tp->rx_fcb_curr[queue]->bdb_ptr = bdb; |
| 1368 | |
| 1369 | return ((__u8 *)bdb->data_block_ptr); |
| 1370 | } |
| 1371 | |
| 1372 | static int smctr_get_station_id(struct net_device *dev) |
| 1373 | { |
| 1374 | smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS); |
| 1375 | |
| 1376 | return(smctr_wait_cmd(dev)); |
| 1377 | } |
| 1378 | |
| 1379 | /* |
| 1380 | * Get the current statistics. This may be called with the card open |
| 1381 | * or closed. |
| 1382 | */ |
| 1383 | static struct net_device_stats *smctr_get_stats(struct net_device *dev) |
| 1384 | { |
| 1385 | struct net_local *tp = netdev_priv(dev); |
| 1386 | |
| 1387 | return ((struct net_device_stats *)&tp->MacStat); |
| 1388 | } |
| 1389 | |
| 1390 | static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue, |
| 1391 | __u16 bytes_count) |
| 1392 | { |
| 1393 | struct net_local *tp = netdev_priv(dev); |
| 1394 | FCBlock *pFCB; |
| 1395 | BDBlock *pbdb; |
| 1396 | unsigned short alloc_size; |
| 1397 | unsigned short *temp; |
| 1398 | |
| 1399 | if(smctr_debug > 20) |
| 1400 | printk(KERN_DEBUG "smctr_get_tx_fcb\n"); |
| 1401 | |
| 1402 | /* check if there is enough FCB blocks */ |
| 1403 | if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue]) |
| 1404 | return ((FCBlock *)(-1L)); |
| 1405 | |
| 1406 | /* round off the input pkt size to the nearest even number */ |
| 1407 | alloc_size = (bytes_count + 1) & 0xfffe; |
| 1408 | |
| 1409 | /* check if enough mem */ |
| 1410 | if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue]) |
| 1411 | return ((FCBlock *)(-1L)); |
| 1412 | |
| 1413 | /* check if past the end ; |
| 1414 | * if exactly enough mem to end of ring, alloc from front. |
| 1415 | * this avoids update of curr when curr = end |
| 1416 | */ |
| 1417 | if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size) |
| 1418 | >= (unsigned long)(tp->tx_buff_end[queue])) |
| 1419 | { |
| 1420 | /* check if enough memory from ring head */ |
| 1421 | alloc_size = alloc_size + |
| 1422 | (__u16)((__u32)tp->tx_buff_end[queue] |
| 1423 | - (__u32)tp->tx_buff_curr[queue]); |
| 1424 | |
| 1425 | if((tp->tx_buff_used[queue] + alloc_size) |
| 1426 | > tp->tx_buff_size[queue]) |
| 1427 | { |
| 1428 | return ((FCBlock *)(-1L)); |
| 1429 | } |
| 1430 | |
| 1431 | /* ring wrap */ |
| 1432 | tp->tx_buff_curr[queue] = tp->tx_buff_head[queue]; |
| 1433 | } |
| 1434 | |
| 1435 | tp->tx_buff_used[queue] += alloc_size; |
| 1436 | tp->num_tx_fcbs_used[queue]++; |
| 1437 | tp->tx_fcb_curr[queue]->frame_length = bytes_count; |
| 1438 | tp->tx_fcb_curr[queue]->memory_alloc = alloc_size; |
| 1439 | temp = tp->tx_buff_curr[queue]; |
| 1440 | tp->tx_buff_curr[queue] |
| 1441 | = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe)); |
| 1442 | |
| 1443 | pbdb = tp->tx_fcb_curr[queue]->bdb_ptr; |
| 1444 | pbdb->buffer_length = bytes_count; |
| 1445 | pbdb->data_block_ptr = temp; |
| 1446 | pbdb->trc_data_block_ptr = TRC_POINTER(temp); |
| 1447 | |
| 1448 | pFCB = tp->tx_fcb_curr[queue]; |
| 1449 | tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr; |
| 1450 | |
| 1451 | return (pFCB); |
| 1452 | } |
| 1453 | |
| 1454 | static int smctr_get_upstream_neighbor_addr(struct net_device *dev) |
| 1455 | { |
| 1456 | smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS); |
| 1457 | |
| 1458 | return(smctr_wait_cmd(dev)); |
| 1459 | } |
| 1460 | |
| 1461 | static int smctr_hardware_send_packet(struct net_device *dev, |
| 1462 | struct net_local *tp) |
| 1463 | { |
| 1464 | struct tr_statistics *tstat = &tp->MacStat; |
| 1465 | struct sk_buff *skb; |
| 1466 | FCBlock *fcb; |
| 1467 | |
| 1468 | if(smctr_debug > 10) |
| 1469 | printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name); |
| 1470 | |
| 1471 | if(tp->status != OPEN) |
| 1472 | return (-1); |
| 1473 | |
| 1474 | if(tp->monitor_state_ready != 1) |
| 1475 | return (-1); |
| 1476 | |
| 1477 | for(;;) |
| 1478 | { |
| 1479 | /* Send first buffer from queue */ |
| 1480 | skb = skb_dequeue(&tp->SendSkbQueue); |
| 1481 | if(skb == NULL) |
| 1482 | return (-1); |
| 1483 | |
| 1484 | tp->QueueSkb++; |
| 1485 | |
| 1486 | if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1); |
| 1487 | |
| 1488 | smctr_enable_16bit(dev); |
| 1489 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 1490 | |
| 1491 | if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len)) |
| 1492 | == (FCBlock *)(-1L)) |
| 1493 | { |
| 1494 | smctr_disable_16bit(dev); |
| 1495 | return (-1); |
| 1496 | } |
| 1497 | |
| 1498 | smctr_tx_move_frame(dev, skb, |
| 1499 | (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len); |
| 1500 | |
| 1501 | smctr_set_page(dev, (__u8 *)fcb); |
| 1502 | |
| 1503 | smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE); |
| 1504 | dev_kfree_skb(skb); |
| 1505 | |
| 1506 | tstat->tx_packets++; |
| 1507 | |
| 1508 | smctr_disable_16bit(dev); |
| 1509 | } |
| 1510 | |
| 1511 | return (0); |
| 1512 | } |
| 1513 | |
| 1514 | static int smctr_init_acbs(struct net_device *dev) |
| 1515 | { |
| 1516 | struct net_local *tp = netdev_priv(dev); |
| 1517 | unsigned int i; |
| 1518 | ACBlock *acb; |
| 1519 | |
| 1520 | if(smctr_debug > 10) |
| 1521 | printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name); |
| 1522 | |
| 1523 | acb = tp->acb_head; |
| 1524 | acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL); |
| 1525 | acb->cmd_info = ACB_CHAIN_END; |
| 1526 | acb->cmd = 0; |
| 1527 | acb->subcmd = 0; |
| 1528 | acb->data_offset_lo = 0; |
| 1529 | acb->data_offset_hi = 0; |
| 1530 | acb->next_ptr |
| 1531 | = (ACBlock *)(((char *)acb) + sizeof(ACBlock)); |
| 1532 | acb->trc_next_ptr = TRC_POINTER(acb->next_ptr); |
| 1533 | |
| 1534 | for(i = 1; i < tp->num_acbs; i++) |
| 1535 | { |
| 1536 | acb = acb->next_ptr; |
| 1537 | acb->cmd_done_status |
| 1538 | = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL); |
| 1539 | acb->cmd_info = ACB_CHAIN_END; |
| 1540 | acb->cmd = 0; |
| 1541 | acb->subcmd = 0; |
| 1542 | acb->data_offset_lo = 0; |
| 1543 | acb->data_offset_hi = 0; |
| 1544 | acb->next_ptr |
| 1545 | = (ACBlock *)(((char *)acb) + sizeof(ACBlock)); |
| 1546 | acb->trc_next_ptr = TRC_POINTER(acb->next_ptr); |
| 1547 | } |
| 1548 | |
| 1549 | acb->next_ptr = tp->acb_head; |
| 1550 | acb->trc_next_ptr = TRC_POINTER(tp->acb_head); |
| 1551 | tp->acb_next = tp->acb_head->next_ptr; |
| 1552 | tp->acb_curr = tp->acb_head->next_ptr; |
| 1553 | tp->num_acbs_used = 0; |
| 1554 | |
| 1555 | return (0); |
| 1556 | } |
| 1557 | |
| 1558 | static int smctr_init_adapter(struct net_device *dev) |
| 1559 | { |
| 1560 | struct net_local *tp = netdev_priv(dev); |
| 1561 | int err; |
| 1562 | |
| 1563 | if(smctr_debug > 10) |
| 1564 | printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name); |
| 1565 | |
| 1566 | tp->status = CLOSED; |
| 1567 | tp->page_offset_mask = (tp->ram_usable * 1024) - 1; |
| 1568 | skb_queue_head_init(&tp->SendSkbQueue); |
| 1569 | tp->QueueSkb = MAX_TX_QUEUE; |
| 1570 | |
| 1571 | if(!(tp->group_address_0 & 0x0080)) |
| 1572 | tp->group_address_0 |= 0x00C0; |
| 1573 | |
| 1574 | if(!(tp->functional_address_0 & 0x00C0)) |
| 1575 | tp->functional_address_0 |= 0x00C0; |
| 1576 | |
| 1577 | tp->functional_address[0] &= 0xFF7F; |
| 1578 | |
| 1579 | if(tp->authorized_function_classes == 0) |
| 1580 | tp->authorized_function_classes = 0x7FFF; |
| 1581 | |
| 1582 | if(tp->authorized_access_priority == 0) |
| 1583 | tp->authorized_access_priority = 0x06; |
| 1584 | |
| 1585 | smctr_disable_bic_int(dev); |
| 1586 | smctr_set_trc_reset(dev->base_addr); |
| 1587 | |
| 1588 | smctr_enable_16bit(dev); |
| 1589 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 1590 | |
| 1591 | if(smctr_checksum_firmware(dev)) |
| 1592 | { |
| 1593 | printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT); |
| 1594 | } |
| 1595 | |
| 1596 | if((err = smctr_ram_memory_test(dev))) |
| 1597 | { |
| 1598 | printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name); |
| 1599 | return (-EIO); |
| 1600 | } |
| 1601 | |
| 1602 | smctr_set_rx_look_ahead(dev); |
| 1603 | smctr_load_node_addr(dev); |
| 1604 | |
| 1605 | /* Initialize adapter for Internal Self Test. */ |
| 1606 | smctr_reset_adapter(dev); |
| 1607 | if((err = smctr_init_card_real(dev))) |
| 1608 | { |
| 1609 | printk(KERN_ERR "%s: Initialization of card failed (%d)\n", |
| 1610 | dev->name, err); |
| 1611 | return (-EINVAL); |
| 1612 | } |
| 1613 | |
| 1614 | /* This routine clobbers the TRC's internal registers. */ |
| 1615 | if((err = smctr_internal_self_test(dev))) |
| 1616 | { |
| 1617 | printk(KERN_ERR "%s: Card failed internal self test (%d)\n", |
| 1618 | dev->name, err); |
| 1619 | return (-EINVAL); |
| 1620 | } |
| 1621 | |
| 1622 | /* Re-Initialize adapter's internal registers */ |
| 1623 | smctr_reset_adapter(dev); |
| 1624 | if((err = smctr_init_card_real(dev))) |
| 1625 | { |
| 1626 | printk(KERN_ERR "%s: Initialization of card failed (%d)\n", |
| 1627 | dev->name, err); |
| 1628 | return (-EINVAL); |
| 1629 | } |
| 1630 | |
| 1631 | smctr_enable_bic_int(dev); |
| 1632 | |
| 1633 | if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK))) |
| 1634 | return (err); |
| 1635 | |
| 1636 | smctr_disable_16bit(dev); |
| 1637 | |
| 1638 | return (0); |
| 1639 | } |
| 1640 | |
| 1641 | static int smctr_init_card_real(struct net_device *dev) |
| 1642 | { |
| 1643 | struct net_local *tp = netdev_priv(dev); |
| 1644 | int err = 0; |
| 1645 | |
| 1646 | if(smctr_debug > 10) |
| 1647 | printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name); |
| 1648 | |
| 1649 | tp->sh_mem_used = 0; |
| 1650 | tp->num_acbs = NUM_OF_ACBS; |
| 1651 | |
| 1652 | /* Range Check Max Packet Size */ |
| 1653 | if(tp->max_packet_size < 256) |
| 1654 | tp->max_packet_size = 256; |
| 1655 | else |
| 1656 | { |
| 1657 | if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY) |
| 1658 | tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY; |
| 1659 | } |
| 1660 | |
| 1661 | tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY |
| 1662 | / tp->max_packet_size) - 1; |
| 1663 | |
| 1664 | if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS) |
| 1665 | tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS; |
| 1666 | else |
| 1667 | { |
| 1668 | if(tp->num_of_tx_buffs == 0) |
| 1669 | tp->num_of_tx_buffs = 1; |
| 1670 | } |
| 1671 | |
| 1672 | /* Tx queue constants */ |
| 1673 | tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS; |
| 1674 | tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS; |
| 1675 | tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY; |
| 1676 | tp->tx_buff_used [BUG_QUEUE] = 0; |
| 1677 | tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING; |
| 1678 | |
| 1679 | tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS; |
| 1680 | tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS; |
| 1681 | tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY; |
| 1682 | tp->tx_buff_used [MAC_QUEUE] = 0; |
| 1683 | tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING; |
| 1684 | |
| 1685 | tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS; |
| 1686 | tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS; |
| 1687 | tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY; |
| 1688 | tp->tx_buff_used [NON_MAC_QUEUE] = 0; |
| 1689 | tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING; |
| 1690 | |
| 1691 | /* Receive Queue Constants */ |
| 1692 | tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS; |
| 1693 | tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS; |
| 1694 | |
| 1695 | if(tp->extra_info & CHIP_REV_MASK) |
| 1696 | tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */ |
| 1697 | else |
| 1698 | tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */ |
| 1699 | |
| 1700 | tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev); |
| 1701 | |
| 1702 | smctr_alloc_shared_memory(dev); |
| 1703 | smctr_init_shared_memory(dev); |
| 1704 | |
| 1705 | if((err = smctr_issue_init_timers_cmd(dev))) |
| 1706 | return (err); |
| 1707 | |
| 1708 | if((err = smctr_issue_init_txrx_cmd(dev))) |
| 1709 | { |
| 1710 | printk(KERN_ERR "%s: Hardware failure\n", dev->name); |
| 1711 | return (err); |
| 1712 | } |
| 1713 | |
| 1714 | return (0); |
| 1715 | } |
| 1716 | |
| 1717 | static int smctr_init_rx_bdbs(struct net_device *dev) |
| 1718 | { |
| 1719 | struct net_local *tp = netdev_priv(dev); |
| 1720 | unsigned int i, j; |
| 1721 | BDBlock *bdb; |
| 1722 | __u16 *buf; |
| 1723 | |
| 1724 | if(smctr_debug > 10) |
| 1725 | printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name); |
| 1726 | |
| 1727 | for(i = 0; i < NUM_RX_QS_USED; i++) |
| 1728 | { |
| 1729 | bdb = tp->rx_bdb_head[i]; |
| 1730 | buf = tp->rx_buff_head[i]; |
| 1731 | bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING); |
| 1732 | bdb->buffer_length = RX_DATA_BUFFER_SIZE; |
| 1733 | bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock)); |
| 1734 | bdb->data_block_ptr = buf; |
| 1735 | bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr); |
| 1736 | |
| 1737 | if(i == NON_MAC_QUEUE) |
| 1738 | bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf); |
| 1739 | else |
| 1740 | bdb->trc_data_block_ptr = TRC_POINTER(buf); |
| 1741 | |
| 1742 | for(j = 1; j < tp->num_rx_bdbs[i]; j++) |
| 1743 | { |
| 1744 | bdb->next_ptr->back_ptr = bdb; |
| 1745 | bdb = bdb->next_ptr; |
| 1746 | buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE); |
| 1747 | bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING); |
| 1748 | bdb->buffer_length = RX_DATA_BUFFER_SIZE; |
| 1749 | bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock)); |
| 1750 | bdb->data_block_ptr = buf; |
| 1751 | bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr); |
| 1752 | |
| 1753 | if(i == NON_MAC_QUEUE) |
| 1754 | bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf); |
| 1755 | else |
| 1756 | bdb->trc_data_block_ptr = TRC_POINTER(buf); |
| 1757 | } |
| 1758 | |
| 1759 | bdb->next_ptr = tp->rx_bdb_head[i]; |
| 1760 | bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]); |
| 1761 | |
| 1762 | tp->rx_bdb_head[i]->back_ptr = bdb; |
| 1763 | tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr; |
| 1764 | } |
| 1765 | |
| 1766 | return (0); |
| 1767 | } |
| 1768 | |
| 1769 | static int smctr_init_rx_fcbs(struct net_device *dev) |
| 1770 | { |
| 1771 | struct net_local *tp = netdev_priv(dev); |
| 1772 | unsigned int i, j; |
| 1773 | FCBlock *fcb; |
| 1774 | |
| 1775 | for(i = 0; i < NUM_RX_QS_USED; i++) |
| 1776 | { |
| 1777 | fcb = tp->rx_fcb_head[i]; |
| 1778 | fcb->frame_status = 0; |
| 1779 | fcb->frame_length = 0; |
| 1780 | fcb->info = FCB_CHAIN_END; |
| 1781 | fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock)); |
| 1782 | if(i == NON_MAC_QUEUE) |
| 1783 | fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr); |
| 1784 | else |
| 1785 | fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr); |
| 1786 | |
| 1787 | for(j = 1; j < tp->num_rx_fcbs[i]; j++) |
| 1788 | { |
| 1789 | fcb->next_ptr->back_ptr = fcb; |
| 1790 | fcb = fcb->next_ptr; |
| 1791 | fcb->frame_status = 0; |
| 1792 | fcb->frame_length = 0; |
| 1793 | fcb->info = FCB_WARNING; |
| 1794 | fcb->next_ptr |
| 1795 | = (FCBlock *)(((char *)fcb) + sizeof(FCBlock)); |
| 1796 | |
| 1797 | if(i == NON_MAC_QUEUE) |
| 1798 | fcb->trc_next_ptr |
| 1799 | = RX_FCB_TRC_POINTER(fcb->next_ptr); |
| 1800 | else |
| 1801 | fcb->trc_next_ptr |
| 1802 | = TRC_POINTER(fcb->next_ptr); |
| 1803 | } |
| 1804 | |
| 1805 | fcb->next_ptr = tp->rx_fcb_head[i]; |
| 1806 | |
| 1807 | if(i == NON_MAC_QUEUE) |
| 1808 | fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr); |
| 1809 | else |
| 1810 | fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr); |
| 1811 | |
| 1812 | tp->rx_fcb_head[i]->back_ptr = fcb; |
| 1813 | tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr; |
| 1814 | } |
| 1815 | |
| 1816 | return(0); |
| 1817 | } |
| 1818 | |
| 1819 | static int smctr_init_shared_memory(struct net_device *dev) |
| 1820 | { |
| 1821 | struct net_local *tp = netdev_priv(dev); |
| 1822 | unsigned int i; |
| 1823 | __u32 *iscpb; |
| 1824 | |
| 1825 | if(smctr_debug > 10) |
| 1826 | printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name); |
| 1827 | |
| 1828 | smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr); |
| 1829 | |
| 1830 | /* Initialize Initial System Configuration Point. (ISCP) */ |
| 1831 | iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr); |
| 1832 | *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr))); |
| 1833 | |
| 1834 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 1835 | |
| 1836 | /* Initialize System Configuration Pointers. (SCP) */ |
| 1837 | tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT |
| 1838 | | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT |
| 1839 | | SCGB_BURST_LENGTH); |
| 1840 | |
| 1841 | tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr); |
| 1842 | tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head); |
| 1843 | tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr); |
| 1844 | tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2; |
| 1845 | |
| 1846 | /* Initialize System Control Block. (SCB) */ |
| 1847 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP; |
| 1848 | tp->sclb_ptr->iack_code = 0; |
| 1849 | tp->sclb_ptr->resume_control = 0; |
| 1850 | tp->sclb_ptr->int_mask_control = 0; |
| 1851 | tp->sclb_ptr->int_mask_state = 0; |
| 1852 | |
| 1853 | /* Initialize Interrupt Status Block. (ISB) */ |
| 1854 | for(i = 0; i < NUM_OF_INTERRUPTS; i++) |
| 1855 | { |
| 1856 | tp->isb_ptr->IStatus[i].IType = 0xf0; |
| 1857 | tp->isb_ptr->IStatus[i].ISubtype = 0; |
| 1858 | } |
| 1859 | |
| 1860 | tp->current_isb_index = 0; |
| 1861 | |
| 1862 | /* Initialize Action Command Block. (ACB) */ |
| 1863 | smctr_init_acbs(dev); |
| 1864 | |
| 1865 | /* Initialize transmit FCB's and BDB's. */ |
| 1866 | smctr_link_tx_fcbs_to_bdbs(dev); |
| 1867 | smctr_init_tx_bdbs(dev); |
| 1868 | smctr_init_tx_fcbs(dev); |
| 1869 | |
| 1870 | /* Initialize receive FCB's and BDB's. */ |
| 1871 | smctr_init_rx_bdbs(dev); |
| 1872 | smctr_init_rx_fcbs(dev); |
| 1873 | |
| 1874 | return (0); |
| 1875 | } |
| 1876 | |
| 1877 | static int smctr_init_tx_bdbs(struct net_device *dev) |
| 1878 | { |
| 1879 | struct net_local *tp = netdev_priv(dev); |
| 1880 | unsigned int i, j; |
| 1881 | BDBlock *bdb; |
| 1882 | |
| 1883 | for(i = 0; i < NUM_TX_QS_USED; i++) |
| 1884 | { |
| 1885 | bdb = tp->tx_bdb_head[i]; |
| 1886 | bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING); |
| 1887 | bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock)); |
| 1888 | bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr); |
| 1889 | |
| 1890 | for(j = 1; j < tp->num_tx_bdbs[i]; j++) |
| 1891 | { |
| 1892 | bdb->next_ptr->back_ptr = bdb; |
| 1893 | bdb = bdb->next_ptr; |
| 1894 | bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING); |
| 1895 | bdb->next_ptr |
| 1896 | = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr); |
| 1897 | } |
| 1898 | |
| 1899 | bdb->next_ptr = tp->tx_bdb_head[i]; |
| 1900 | bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]); |
| 1901 | tp->tx_bdb_head[i]->back_ptr = bdb; |
| 1902 | } |
| 1903 | |
| 1904 | return (0); |
| 1905 | } |
| 1906 | |
| 1907 | static int smctr_init_tx_fcbs(struct net_device *dev) |
| 1908 | { |
| 1909 | struct net_local *tp = netdev_priv(dev); |
| 1910 | unsigned int i, j; |
| 1911 | FCBlock *fcb; |
| 1912 | |
| 1913 | for(i = 0; i < NUM_TX_QS_USED; i++) |
| 1914 | { |
| 1915 | fcb = tp->tx_fcb_head[i]; |
| 1916 | fcb->frame_status = 0; |
| 1917 | fcb->frame_length = 0; |
| 1918 | fcb->info = FCB_CHAIN_END; |
| 1919 | fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock)); |
| 1920 | fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr); |
| 1921 | |
| 1922 | for(j = 1; j < tp->num_tx_fcbs[i]; j++) |
| 1923 | { |
| 1924 | fcb->next_ptr->back_ptr = fcb; |
| 1925 | fcb = fcb->next_ptr; |
| 1926 | fcb->frame_status = 0; |
| 1927 | fcb->frame_length = 0; |
| 1928 | fcb->info = FCB_CHAIN_END; |
| 1929 | fcb->next_ptr |
| 1930 | = (FCBlock *)(((char *)fcb) + sizeof(FCBlock)); |
| 1931 | fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr); |
| 1932 | } |
| 1933 | |
| 1934 | fcb->next_ptr = tp->tx_fcb_head[i]; |
| 1935 | fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]); |
| 1936 | |
| 1937 | tp->tx_fcb_head[i]->back_ptr = fcb; |
| 1938 | tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr; |
| 1939 | tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr; |
| 1940 | tp->num_tx_fcbs_used[i] = 0; |
| 1941 | } |
| 1942 | |
| 1943 | return (0); |
| 1944 | } |
| 1945 | |
| 1946 | static int smctr_internal_self_test(struct net_device *dev) |
| 1947 | { |
| 1948 | struct net_local *tp = netdev_priv(dev); |
| 1949 | int err; |
| 1950 | |
| 1951 | if((err = smctr_issue_test_internal_rom_cmd(dev))) |
| 1952 | return (err); |
| 1953 | |
| 1954 | if((err = smctr_wait_cmd(dev))) |
| 1955 | return (err); |
| 1956 | |
| 1957 | if(tp->acb_head->cmd_done_status & 0xff) |
| 1958 | return (-1); |
| 1959 | |
| 1960 | if((err = smctr_issue_test_hic_cmd(dev))) |
| 1961 | return (err); |
| 1962 | |
| 1963 | if((err = smctr_wait_cmd(dev))) |
| 1964 | return (err); |
| 1965 | |
| 1966 | if(tp->acb_head->cmd_done_status & 0xff) |
| 1967 | return (-1); |
| 1968 | |
| 1969 | if((err = smctr_issue_test_mac_reg_cmd(dev))) |
| 1970 | return (err); |
| 1971 | |
| 1972 | if((err = smctr_wait_cmd(dev))) |
| 1973 | return (err); |
| 1974 | |
| 1975 | if(tp->acb_head->cmd_done_status & 0xff) |
| 1976 | return (-1); |
| 1977 | |
| 1978 | return (0); |
| 1979 | } |
| 1980 | |
| 1981 | /* |
| 1982 | * The typical workload of the driver: Handle the network interface interrupts. |
| 1983 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1984 | static irqreturn_t smctr_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | { |
| 1986 | struct net_device *dev = dev_id; |
| 1987 | struct net_local *tp; |
| 1988 | int ioaddr; |
| 1989 | __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00; |
| 1990 | __u16 err1, err = NOT_MY_INTERRUPT; |
| 1991 | __u8 isb_type, isb_subtype; |
| 1992 | __u16 isb_index; |
| 1993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | ioaddr = dev->base_addr; |
| 1995 | tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
| 1997 | if(tp->status == NOT_INITIALIZED) |
| 1998 | return IRQ_NONE; |
| 1999 | |
| 2000 | spin_lock(&tp->lock); |
| 2001 | |
| 2002 | smctr_disable_bic_int(dev); |
| 2003 | smctr_enable_16bit(dev); |
| 2004 | |
| 2005 | smctr_clear_int(dev); |
| 2006 | |
| 2007 | /* First read the LSB */ |
| 2008 | while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0) |
| 2009 | { |
| 2010 | isb_index = tp->current_isb_index; |
| 2011 | isb_type = tp->isb_ptr->IStatus[isb_index].IType; |
| 2012 | isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype; |
| 2013 | |
| 2014 | (tp->current_isb_index)++; |
| 2015 | if(tp->current_isb_index == NUM_OF_INTERRUPTS) |
| 2016 | tp->current_isb_index = 0; |
| 2017 | |
| 2018 | if(isb_type >= 0x10) |
| 2019 | { |
| 2020 | smctr_disable_16bit(dev); |
| 2021 | spin_unlock(&tp->lock); |
| 2022 | return IRQ_HANDLED; |
| 2023 | } |
| 2024 | |
| 2025 | err = HARDWARE_FAILED; |
| 2026 | interrupt_ack_code = isb_index; |
| 2027 | tp->isb_ptr->IStatus[isb_index].IType |= 0xf0; |
| 2028 | |
| 2029 | interrupt_unmask_bits |= (1 << (__u16)isb_type); |
| 2030 | |
| 2031 | switch(isb_type) |
| 2032 | { |
| 2033 | case ISB_IMC_MAC_TYPE_3: |
| 2034 | smctr_disable_16bit(dev); |
| 2035 | |
| 2036 | switch(isb_subtype) |
| 2037 | { |
| 2038 | case 0: |
| 2039 | tp->monitor_state = MS_MONITOR_FSM_INACTIVE; |
| 2040 | break; |
| 2041 | |
| 2042 | case 1: |
| 2043 | tp->monitor_state = MS_REPEAT_BEACON_STATE; |
| 2044 | break; |
| 2045 | |
| 2046 | case 2: |
| 2047 | tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE; |
| 2048 | break; |
| 2049 | |
| 2050 | case 3: |
| 2051 | tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break; |
| 2052 | |
| 2053 | case 4: |
| 2054 | tp->monitor_state = MS_STANDBY_MONITOR_STATE; |
| 2055 | break; |
| 2056 | |
| 2057 | case 5: |
| 2058 | tp->monitor_state = MS_TRANSMIT_BEACON_STATE; |
| 2059 | break; |
| 2060 | |
| 2061 | case 6: |
| 2062 | tp->monitor_state = MS_ACTIVE_MONITOR_STATE; |
| 2063 | break; |
| 2064 | |
| 2065 | case 7: |
| 2066 | tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE; |
| 2067 | break; |
| 2068 | |
| 2069 | case 8: /* diagnostic state */ |
| 2070 | break; |
| 2071 | |
| 2072 | case 9: |
| 2073 | tp->monitor_state = MS_BEACON_TEST_STATE; |
| 2074 | if(smctr_lobe_media_test(dev)) |
| 2075 | { |
| 2076 | tp->ring_status_flags = RING_STATUS_CHANGED; |
| 2077 | tp->ring_status = AUTO_REMOVAL_ERROR; |
| 2078 | smctr_ring_status_chg(dev); |
| 2079 | smctr_bypass_state(dev); |
| 2080 | } |
| 2081 | else |
| 2082 | smctr_issue_insert_cmd(dev); |
| 2083 | break; |
| 2084 | |
| 2085 | /* case 0x0a-0xff, illegal states */ |
| 2086 | default: |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | tp->ring_status_flags = MONITOR_STATE_CHANGED; |
| 2091 | err = smctr_ring_status_chg(dev); |
| 2092 | |
| 2093 | smctr_enable_16bit(dev); |
| 2094 | break; |
| 2095 | |
| 2096 | /* Type 0x02 - MAC Error Counters Interrupt |
| 2097 | * One or more MAC Error Counter is half full |
| 2098 | * MAC Error Counters |
| 2099 | * Lost_FR_Error_Counter |
| 2100 | * RCV_Congestion_Counter |
| 2101 | * FR_copied_Error_Counter |
| 2102 | * FREQ_Error_Counter |
| 2103 | * Token_Error_Counter |
| 2104 | * Line_Error_Counter |
| 2105 | * Internal_Error_Count |
| 2106 | */ |
| 2107 | case ISB_IMC_MAC_ERROR_COUNTERS: |
| 2108 | /* Read 802.5 Error Counters */ |
| 2109 | err = smctr_issue_read_ring_status_cmd(dev); |
| 2110 | break; |
| 2111 | |
| 2112 | /* Type 0x04 - MAC Type 2 Interrupt |
| 2113 | * HOST needs to enqueue MAC Frame for transmission |
| 2114 | * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to |
| 2115 | * TRC_Status_Changed_Indicate |
| 2116 | */ |
| 2117 | case ISB_IMC_MAC_TYPE_2: |
| 2118 | err = smctr_issue_read_ring_status_cmd(dev); |
| 2119 | break; |
| 2120 | |
| 2121 | |
| 2122 | /* Type 0x05 - TX Frame Interrupt (FI). */ |
| 2123 | case ISB_IMC_TX_FRAME: |
| 2124 | /* BUG QUEUE for TRC stuck receive BUG */ |
| 2125 | if(isb_subtype & TX_PENDING_PRIORITY_2) |
| 2126 | { |
| 2127 | if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS) |
| 2128 | break; |
| 2129 | } |
| 2130 | |
| 2131 | /* NON-MAC frames only */ |
| 2132 | if(isb_subtype & TX_PENDING_PRIORITY_1) |
| 2133 | { |
| 2134 | if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS) |
| 2135 | break; |
| 2136 | } |
| 2137 | |
| 2138 | /* MAC frames only */ |
| 2139 | if(isb_subtype & TX_PENDING_PRIORITY_0) |
| 2140 | err = smctr_tx_complete(dev, MAC_QUEUE); break; |
| 2141 | |
| 2142 | /* Type 0x06 - TX END OF QUEUE (FE) */ |
| 2143 | case ISB_IMC_END_OF_TX_QUEUE: |
| 2144 | /* BUG queue */ |
| 2145 | if(isb_subtype & TX_PENDING_PRIORITY_2) |
| 2146 | { |
| 2147 | /* ok to clear Receive FIFO overrun |
| 2148 | * imask send_BUG now completes. |
| 2149 | */ |
| 2150 | interrupt_unmask_bits |= 0x800; |
| 2151 | |
| 2152 | tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING; |
| 2153 | if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS) |
| 2154 | break; |
| 2155 | if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS) |
| 2156 | break; |
| 2157 | } |
| 2158 | |
| 2159 | /* NON-MAC queue only */ |
| 2160 | if(isb_subtype & TX_PENDING_PRIORITY_1) |
| 2161 | { |
| 2162 | tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING; |
| 2163 | if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS) |
| 2164 | break; |
| 2165 | if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS) |
| 2166 | break; |
| 2167 | } |
| 2168 | |
| 2169 | /* MAC queue only */ |
| 2170 | if(isb_subtype & TX_PENDING_PRIORITY_0) |
| 2171 | { |
| 2172 | tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING; |
| 2173 | if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS) |
| 2174 | break; |
| 2175 | |
| 2176 | err = smctr_restart_tx_chain(dev, MAC_QUEUE); |
| 2177 | } |
| 2178 | break; |
| 2179 | |
| 2180 | /* Type 0x07 - NON-MAC RX Resource Interrupt |
| 2181 | * Subtype bit 12 - (BW) BDB warning |
| 2182 | * Subtype bit 13 - (FW) FCB warning |
| 2183 | * Subtype bit 14 - (BE) BDB End of chain |
| 2184 | * Subtype bit 15 - (FE) FCB End of chain |
| 2185 | */ |
| 2186 | case ISB_IMC_NON_MAC_RX_RESOURCE: |
| 2187 | tp->rx_fifo_overrun_count = 0; |
| 2188 | tp->receive_queue_number = NON_MAC_QUEUE; |
| 2189 | err1 = smctr_rx_frame(dev); |
| 2190 | |
| 2191 | if(isb_subtype & NON_MAC_RX_RESOURCE_FE) |
| 2192 | { |
| 2193 | if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break; |
| 2194 | |
| 2195 | if(tp->ptr_rx_fcb_overruns) |
| 2196 | (*tp->ptr_rx_fcb_overruns)++; |
| 2197 | } |
| 2198 | |
| 2199 | if(isb_subtype & NON_MAC_RX_RESOURCE_BE) |
| 2200 | { |
| 2201 | if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break; |
| 2202 | |
| 2203 | if(tp->ptr_rx_bdb_overruns) |
| 2204 | (*tp->ptr_rx_bdb_overruns)++; |
| 2205 | } |
| 2206 | err = err1; |
| 2207 | break; |
| 2208 | |
| 2209 | /* Type 0x08 - MAC RX Resource Interrupt |
| 2210 | * Subtype bit 12 - (BW) BDB warning |
| 2211 | * Subtype bit 13 - (FW) FCB warning |
| 2212 | * Subtype bit 14 - (BE) BDB End of chain |
| 2213 | * Subtype bit 15 - (FE) FCB End of chain |
| 2214 | */ |
| 2215 | case ISB_IMC_MAC_RX_RESOURCE: |
| 2216 | tp->receive_queue_number = MAC_QUEUE; |
| 2217 | err1 = smctr_rx_frame(dev); |
| 2218 | |
| 2219 | if(isb_subtype & MAC_RX_RESOURCE_FE) |
| 2220 | { |
| 2221 | if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS) |
| 2222 | break; |
| 2223 | |
| 2224 | if(tp->ptr_rx_fcb_overruns) |
| 2225 | (*tp->ptr_rx_fcb_overruns)++; |
| 2226 | } |
| 2227 | |
| 2228 | if(isb_subtype & MAC_RX_RESOURCE_BE) |
| 2229 | { |
| 2230 | if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS) |
| 2231 | break; |
| 2232 | |
| 2233 | if(tp->ptr_rx_bdb_overruns) |
| 2234 | (*tp->ptr_rx_bdb_overruns)++; |
| 2235 | } |
| 2236 | err = err1; |
| 2237 | break; |
| 2238 | |
| 2239 | /* Type 0x09 - NON_MAC RX Frame Interrupt */ |
| 2240 | case ISB_IMC_NON_MAC_RX_FRAME: |
| 2241 | tp->rx_fifo_overrun_count = 0; |
| 2242 | tp->receive_queue_number = NON_MAC_QUEUE; |
| 2243 | err = smctr_rx_frame(dev); |
| 2244 | break; |
| 2245 | |
| 2246 | /* Type 0x0A - MAC RX Frame Interrupt */ |
| 2247 | case ISB_IMC_MAC_RX_FRAME: |
| 2248 | tp->receive_queue_number = MAC_QUEUE; |
| 2249 | err = smctr_rx_frame(dev); |
| 2250 | break; |
| 2251 | |
| 2252 | /* Type 0x0B - TRC status |
| 2253 | * TRC has encountered an error condition |
| 2254 | * subtype bit 14 - transmit FIFO underrun |
| 2255 | * subtype bit 15 - receive FIFO overrun |
| 2256 | */ |
| 2257 | case ISB_IMC_TRC_FIFO_STATUS: |
| 2258 | if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN) |
| 2259 | { |
| 2260 | if(tp->ptr_tx_fifo_underruns) |
| 2261 | (*tp->ptr_tx_fifo_underruns)++; |
| 2262 | } |
| 2263 | |
| 2264 | if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN) |
| 2265 | { |
| 2266 | /* update overrun stuck receive counter |
| 2267 | * if >= 3, has to clear it by sending |
| 2268 | * back to back frames. We pick |
| 2269 | * DAT(duplicate address MAC frame) |
| 2270 | */ |
| 2271 | tp->rx_fifo_overrun_count++; |
| 2272 | |
| 2273 | if(tp->rx_fifo_overrun_count >= 3) |
| 2274 | { |
| 2275 | tp->rx_fifo_overrun_count = 0; |
| 2276 | |
| 2277 | /* delay clearing fifo overrun |
| 2278 | * imask till send_BUG tx |
| 2279 | * complete posted |
| 2280 | */ |
| 2281 | interrupt_unmask_bits &= (~0x800); |
| 2282 | printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev); |
| 2283 | } |
| 2284 | |
| 2285 | if(tp->ptr_rx_fifo_overruns) |
| 2286 | (*tp->ptr_rx_fifo_overruns)++; |
| 2287 | } |
| 2288 | |
| 2289 | err = SUCCESS; |
| 2290 | break; |
| 2291 | |
| 2292 | /* Type 0x0C - Action Command Status Interrupt |
| 2293 | * Subtype bit 14 - CB end of command chain (CE) |
| 2294 | * Subtype bit 15 - CB command interrupt (CI) |
| 2295 | */ |
| 2296 | case ISB_IMC_COMMAND_STATUS: |
| 2297 | err = SUCCESS; |
| 2298 | if(tp->acb_head->cmd == ACB_CMD_HIC_NOP) |
| 2299 | { |
| 2300 | printk(KERN_ERR "i1\n"); |
| 2301 | smctr_disable_16bit(dev); |
| 2302 | |
| 2303 | /* XXXXXXXXXXXXXXXXX */ |
| 2304 | /* err = UM_Interrupt(dev); */ |
| 2305 | |
| 2306 | smctr_enable_16bit(dev); |
| 2307 | } |
| 2308 | else |
| 2309 | { |
| 2310 | if((tp->acb_head->cmd |
| 2311 | == ACB_CMD_READ_TRC_STATUS) |
| 2312 | && (tp->acb_head->subcmd |
| 2313 | == RW_TRC_STATUS_BLOCK)) |
| 2314 | { |
Al Viro | 79ea13c | 2008-01-24 02:06:46 -0800 | [diff] [blame] | 2315 | if(tp->ptr_bcn_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | { |
| 2317 | *(tp->ptr_bcn_type) |
| 2318 | = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type; |
| 2319 | } |
| 2320 | |
| 2321 | if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED) |
| 2322 | { |
| 2323 | smctr_update_err_stats(dev); |
| 2324 | } |
| 2325 | |
| 2326 | if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED) |
| 2327 | { |
| 2328 | tp->ring_status |
| 2329 | = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status; |
| 2330 | smctr_disable_16bit(dev); |
| 2331 | err = smctr_ring_status_chg(dev); |
| 2332 | smctr_enable_16bit(dev); |
| 2333 | if((tp->ring_status & REMOVE_RECEIVED) |
| 2334 | && (tp->config_word0 & NO_AUTOREMOVE)) |
| 2335 | { |
| 2336 | smctr_issue_remove_cmd(dev); |
| 2337 | } |
| 2338 | |
| 2339 | if(err != SUCCESS) |
| 2340 | { |
| 2341 | tp->acb_pending = 0; |
| 2342 | break; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| 2346 | if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED) |
| 2347 | { |
| 2348 | if(tp->ptr_una) |
| 2349 | { |
| 2350 | tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]); |
| 2351 | tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]); |
| 2352 | tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]); |
| 2353 | } |
| 2354 | |
| 2355 | } |
| 2356 | |
| 2357 | if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) { |
| 2358 | err = smctr_send_rq_init(dev); |
| 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | tp->acb_pending = 0; |
| 2364 | break; |
| 2365 | |
| 2366 | /* Type 0x0D - MAC Type 1 interrupt |
| 2367 | * Subtype -- 00 FR_BCN received at S12 |
| 2368 | * 01 FR_BCN received at S21 |
| 2369 | * 02 FR_DAT(DA=MA, A<>0) received at S21 |
| 2370 | * 03 TSM_EXP at S21 |
| 2371 | * 04 FR_REMOVE received at S42 |
| 2372 | * 05 TBR_EXP, BR_FLAG_SET at S42 |
| 2373 | * 06 TBT_EXP at S53 |
| 2374 | */ |
| 2375 | case ISB_IMC_MAC_TYPE_1: |
| 2376 | if(isb_subtype > 8) |
| 2377 | { |
| 2378 | err = HARDWARE_FAILED; |
| 2379 | break; |
| 2380 | } |
| 2381 | |
| 2382 | err = SUCCESS; |
| 2383 | switch(isb_subtype) |
| 2384 | { |
| 2385 | case 0: |
| 2386 | tp->join_state = JS_BYPASS_STATE; |
| 2387 | if(tp->status != CLOSED) |
| 2388 | { |
| 2389 | tp->status = CLOSED; |
| 2390 | err = smctr_status_chg(dev); |
| 2391 | } |
| 2392 | break; |
| 2393 | |
| 2394 | case 1: |
| 2395 | tp->join_state = JS_LOBE_TEST_STATE; |
| 2396 | break; |
| 2397 | |
| 2398 | case 2: |
| 2399 | tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE; |
| 2400 | break; |
| 2401 | |
| 2402 | case 3: |
| 2403 | tp->join_state = JS_AWAIT_NEW_MONITOR_STATE; |
| 2404 | break; |
| 2405 | |
| 2406 | case 4: |
| 2407 | tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE; |
| 2408 | break; |
| 2409 | |
| 2410 | case 5: |
| 2411 | tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE; |
| 2412 | break; |
| 2413 | |
| 2414 | case 6: |
| 2415 | tp->join_state = JS_REQUEST_INITIALIZATION_STATE; |
| 2416 | break; |
| 2417 | |
| 2418 | case 7: |
| 2419 | tp->join_state = JS_JOIN_COMPLETE_STATE; |
| 2420 | tp->status = OPEN; |
| 2421 | err = smctr_status_chg(dev); |
| 2422 | break; |
| 2423 | |
| 2424 | case 8: |
| 2425 | tp->join_state = JS_BYPASS_WAIT_STATE; |
| 2426 | break; |
| 2427 | } |
| 2428 | break ; |
| 2429 | |
| 2430 | /* Type 0x0E - TRC Initialization Sequence Interrupt |
| 2431 | * Subtype -- 00-FF Initializatin sequence complete |
| 2432 | */ |
| 2433 | case ISB_IMC_TRC_INTRNL_TST_STATUS: |
| 2434 | tp->status = INITIALIZED; |
| 2435 | smctr_disable_16bit(dev); |
| 2436 | err = smctr_status_chg(dev); |
| 2437 | smctr_enable_16bit(dev); |
| 2438 | break; |
| 2439 | |
| 2440 | /* other interrupt types, illegal */ |
| 2441 | default: |
| 2442 | break; |
| 2443 | } |
| 2444 | |
| 2445 | if(err != SUCCESS) |
| 2446 | break; |
| 2447 | } |
| 2448 | |
| 2449 | /* Checking the ack code instead of the unmask bits here is because : |
| 2450 | * while fixing the stuck receive, DAT frame are sent and mask off |
| 2451 | * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0) |
| 2452 | * but we still want to issue ack to ISB |
| 2453 | */ |
| 2454 | if(!(interrupt_ack_code & 0xff00)) |
| 2455 | smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits); |
| 2456 | |
| 2457 | smctr_disable_16bit(dev); |
| 2458 | smctr_enable_bic_int(dev); |
| 2459 | spin_unlock(&tp->lock); |
| 2460 | |
| 2461 | return IRQ_HANDLED; |
| 2462 | } |
| 2463 | |
| 2464 | static int smctr_issue_enable_int_cmd(struct net_device *dev, |
| 2465 | __u16 interrupt_enable_mask) |
| 2466 | { |
| 2467 | struct net_local *tp = netdev_priv(dev); |
| 2468 | int err; |
| 2469 | |
| 2470 | if((err = smctr_wait_while_cbusy(dev))) |
| 2471 | return (err); |
| 2472 | |
| 2473 | tp->sclb_ptr->int_mask_control = interrupt_enable_mask; |
| 2474 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK; |
| 2475 | |
| 2476 | smctr_set_ctrl_attention(dev); |
| 2477 | |
| 2478 | return (0); |
| 2479 | } |
| 2480 | |
| 2481 | static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits) |
| 2482 | { |
| 2483 | struct net_local *tp = netdev_priv(dev); |
| 2484 | |
| 2485 | if(smctr_wait_while_cbusy(dev)) |
| 2486 | return (-1); |
| 2487 | |
| 2488 | tp->sclb_ptr->int_mask_control = ibits; |
| 2489 | tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0; |
| 2490 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK; |
| 2491 | |
| 2492 | smctr_set_ctrl_attention(dev); |
| 2493 | |
| 2494 | return (0); |
| 2495 | } |
| 2496 | |
| 2497 | static int smctr_issue_init_timers_cmd(struct net_device *dev) |
| 2498 | { |
| 2499 | struct net_local *tp = netdev_priv(dev); |
| 2500 | unsigned int i; |
| 2501 | int err; |
| 2502 | __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data; |
| 2503 | |
| 2504 | if((err = smctr_wait_while_cbusy(dev))) |
| 2505 | return (err); |
| 2506 | |
| 2507 | if((err = smctr_wait_cmd(dev))) |
| 2508 | return (err); |
| 2509 | |
| 2510 | tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE; |
| 2511 | tp->config_word1 = 0; |
| 2512 | |
| 2513 | if((tp->media_type == MEDIA_STP_16) |
| 2514 | || (tp->media_type == MEDIA_UTP_16) |
| 2515 | || (tp->media_type == MEDIA_STP_16_UTP_16)) |
| 2516 | { |
| 2517 | tp->config_word0 |= FREQ_16MB_BIT; |
| 2518 | } |
| 2519 | |
| 2520 | if(tp->mode_bits & EARLY_TOKEN_REL) |
| 2521 | tp->config_word0 |= ETREN; |
| 2522 | |
| 2523 | if(tp->mode_bits & LOOPING_MODE_MASK) |
| 2524 | tp->config_word0 |= RX_OWN_BIT; |
| 2525 | else |
| 2526 | tp->config_word0 &= ~RX_OWN_BIT; |
| 2527 | |
| 2528 | if(tp->receive_mask & PROMISCUOUS_MODE) |
| 2529 | tp->config_word0 |= PROMISCUOUS_BIT; |
| 2530 | else |
| 2531 | tp->config_word0 &= ~PROMISCUOUS_BIT; |
| 2532 | |
| 2533 | if(tp->receive_mask & ACCEPT_ERR_PACKETS) |
| 2534 | tp->config_word0 |= SAVBAD_BIT; |
| 2535 | else |
| 2536 | tp->config_word0 &= ~SAVBAD_BIT; |
| 2537 | |
| 2538 | if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) |
| 2539 | tp->config_word0 |= RXATMAC; |
| 2540 | else |
| 2541 | tp->config_word0 &= ~RXATMAC; |
| 2542 | |
| 2543 | if(tp->receive_mask & ACCEPT_MULTI_PROM) |
| 2544 | tp->config_word1 |= MULTICAST_ADDRESS_BIT; |
| 2545 | else |
| 2546 | tp->config_word1 &= ~MULTICAST_ADDRESS_BIT; |
| 2547 | |
| 2548 | if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING) |
| 2549 | tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS; |
| 2550 | else |
| 2551 | { |
| 2552 | if(tp->receive_mask & ACCEPT_SOURCE_ROUTING) |
| 2553 | tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT; |
| 2554 | else |
| 2555 | tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS; |
| 2556 | } |
| 2557 | |
| 2558 | if((tp->media_type == MEDIA_STP_16) |
| 2559 | || (tp->media_type == MEDIA_UTP_16) |
| 2560 | || (tp->media_type == MEDIA_STP_16_UTP_16)) |
| 2561 | { |
| 2562 | tp->config_word1 |= INTERFRAME_SPACING_16; |
| 2563 | } |
| 2564 | else |
| 2565 | tp->config_word1 |= INTERFRAME_SPACING_4; |
| 2566 | |
| 2567 | *pTimer_Struc++ = tp->config_word0; |
| 2568 | *pTimer_Struc++ = tp->config_word1; |
| 2569 | |
| 2570 | if((tp->media_type == MEDIA_STP_4) |
| 2571 | || (tp->media_type == MEDIA_UTP_4) |
| 2572 | || (tp->media_type == MEDIA_STP_4_UTP_4)) |
| 2573 | { |
| 2574 | *pTimer_Struc++ = 0x00FA; /* prescale */ |
| 2575 | *pTimer_Struc++ = 0x2710; /* TPT_limit */ |
| 2576 | *pTimer_Struc++ = 0x2710; /* TQP_limit */ |
| 2577 | *pTimer_Struc++ = 0x0A28; /* TNT_limit */ |
| 2578 | *pTimer_Struc++ = 0x3E80; /* TBT_limit */ |
| 2579 | *pTimer_Struc++ = 0x3A98; /* TSM_limit */ |
| 2580 | *pTimer_Struc++ = 0x1B58; /* TAM_limit */ |
| 2581 | *pTimer_Struc++ = 0x00C8; /* TBR_limit */ |
| 2582 | *pTimer_Struc++ = 0x07D0; /* TER_limit */ |
| 2583 | *pTimer_Struc++ = 0x000A; /* TGT_limit */ |
| 2584 | *pTimer_Struc++ = 0x1162; /* THT_limit */ |
| 2585 | *pTimer_Struc++ = 0x07D0; /* TRR_limit */ |
| 2586 | *pTimer_Struc++ = 0x1388; /* TVX_limit */ |
| 2587 | *pTimer_Struc++ = 0x0000; /* reserved */ |
| 2588 | } |
| 2589 | else |
| 2590 | { |
| 2591 | *pTimer_Struc++ = 0x03E8; /* prescale */ |
| 2592 | *pTimer_Struc++ = 0x9C40; /* TPT_limit */ |
| 2593 | *pTimer_Struc++ = 0x9C40; /* TQP_limit */ |
| 2594 | *pTimer_Struc++ = 0x0A28; /* TNT_limit */ |
| 2595 | *pTimer_Struc++ = 0x3E80; /* TBT_limit */ |
| 2596 | *pTimer_Struc++ = 0x3A98; /* TSM_limit */ |
| 2597 | *pTimer_Struc++ = 0x1B58; /* TAM_limit */ |
| 2598 | *pTimer_Struc++ = 0x00C8; /* TBR_limit */ |
| 2599 | *pTimer_Struc++ = 0x07D0; /* TER_limit */ |
| 2600 | *pTimer_Struc++ = 0x000A; /* TGT_limit */ |
| 2601 | *pTimer_Struc++ = 0x4588; /* THT_limit */ |
| 2602 | *pTimer_Struc++ = 0x1F40; /* TRR_limit */ |
| 2603 | *pTimer_Struc++ = 0x4E20; /* TVX_limit */ |
| 2604 | *pTimer_Struc++ = 0x0000; /* reserved */ |
| 2605 | } |
| 2606 | |
| 2607 | /* Set node address. */ |
| 2608 | *pTimer_Struc++ = dev->dev_addr[0] << 8 |
| 2609 | | (dev->dev_addr[1] & 0xFF); |
| 2610 | *pTimer_Struc++ = dev->dev_addr[2] << 8 |
| 2611 | | (dev->dev_addr[3] & 0xFF); |
| 2612 | *pTimer_Struc++ = dev->dev_addr[4] << 8 |
| 2613 | | (dev->dev_addr[5] & 0xFF); |
| 2614 | |
| 2615 | /* Set group address. */ |
| 2616 | *pTimer_Struc++ = tp->group_address_0 << 8 |
| 2617 | | tp->group_address_0 >> 8; |
| 2618 | *pTimer_Struc++ = tp->group_address[0] << 8 |
| 2619 | | tp->group_address[0] >> 8; |
| 2620 | *pTimer_Struc++ = tp->group_address[1] << 8 |
| 2621 | | tp->group_address[1] >> 8; |
| 2622 | |
| 2623 | /* Set functional address. */ |
| 2624 | *pTimer_Struc++ = tp->functional_address_0 << 8 |
| 2625 | | tp->functional_address_0 >> 8; |
| 2626 | *pTimer_Struc++ = tp->functional_address[0] << 8 |
| 2627 | | tp->functional_address[0] >> 8; |
| 2628 | *pTimer_Struc++ = tp->functional_address[1] << 8 |
| 2629 | | tp->functional_address[1] >> 8; |
| 2630 | |
| 2631 | /* Set Bit-Wise group address. */ |
| 2632 | *pTimer_Struc++ = tp->bitwise_group_address[0] << 8 |
| 2633 | | tp->bitwise_group_address[0] >> 8; |
| 2634 | *pTimer_Struc++ = tp->bitwise_group_address[1] << 8 |
| 2635 | | tp->bitwise_group_address[1] >> 8; |
| 2636 | |
| 2637 | /* Set ring number address. */ |
| 2638 | *pTimer_Struc++ = tp->source_ring_number; |
| 2639 | *pTimer_Struc++ = tp->target_ring_number; |
| 2640 | |
| 2641 | /* Physical drop number. */ |
| 2642 | *pTimer_Struc++ = (unsigned short)0; |
| 2643 | *pTimer_Struc++ = (unsigned short)0; |
| 2644 | |
| 2645 | /* Product instance ID. */ |
| 2646 | for(i = 0; i < 9; i++) |
| 2647 | *pTimer_Struc++ = (unsigned short)0; |
| 2648 | |
| 2649 | err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0); |
| 2650 | |
| 2651 | return (err); |
| 2652 | } |
| 2653 | |
| 2654 | static int smctr_issue_init_txrx_cmd(struct net_device *dev) |
| 2655 | { |
| 2656 | struct net_local *tp = netdev_priv(dev); |
| 2657 | unsigned int i; |
| 2658 | int err; |
| 2659 | void **txrx_ptrs = (void *)tp->misc_command_data; |
| 2660 | |
| 2661 | if((err = smctr_wait_while_cbusy(dev))) |
| 2662 | return (err); |
| 2663 | |
| 2664 | if((err = smctr_wait_cmd(dev))) |
| 2665 | { |
| 2666 | printk(KERN_ERR "%s: Hardware failure\n", dev->name); |
| 2667 | return (err); |
| 2668 | } |
| 2669 | |
| 2670 | /* Initialize Transmit Queue Pointers that are used, to point to |
| 2671 | * a single FCB. |
| 2672 | */ |
| 2673 | for(i = 0; i < NUM_TX_QS_USED; i++) |
| 2674 | *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]); |
| 2675 | |
| 2676 | /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */ |
| 2677 | for(; i < MAX_TX_QS; i++) |
| 2678 | *txrx_ptrs++ = (void *)0; |
| 2679 | |
| 2680 | /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are |
| 2681 | * used, to point to a single FCB and a BDB chain of buffers. |
| 2682 | */ |
| 2683 | for(i = 0; i < NUM_RX_QS_USED; i++) |
| 2684 | { |
| 2685 | *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]); |
| 2686 | *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]); |
| 2687 | } |
| 2688 | |
| 2689 | /* Initialize Receive Queue Pointers that are NOT used to ZERO. */ |
| 2690 | for(; i < MAX_RX_QS; i++) |
| 2691 | { |
| 2692 | *txrx_ptrs++ = (void *)0; |
| 2693 | *txrx_ptrs++ = (void *)0; |
| 2694 | } |
| 2695 | |
| 2696 | err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0); |
| 2697 | |
| 2698 | return (err); |
| 2699 | } |
| 2700 | |
| 2701 | static int smctr_issue_insert_cmd(struct net_device *dev) |
| 2702 | { |
| 2703 | int err; |
| 2704 | |
| 2705 | err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP); |
| 2706 | |
| 2707 | return (err); |
| 2708 | } |
| 2709 | |
| 2710 | static int smctr_issue_read_ring_status_cmd(struct net_device *dev) |
| 2711 | { |
| 2712 | int err; |
| 2713 | |
| 2714 | if((err = smctr_wait_while_cbusy(dev))) |
| 2715 | return (err); |
| 2716 | |
| 2717 | if((err = smctr_wait_cmd(dev))) |
| 2718 | return (err); |
| 2719 | |
| 2720 | err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS, |
| 2721 | RW_TRC_STATUS_BLOCK); |
| 2722 | |
| 2723 | return (err); |
| 2724 | } |
| 2725 | |
| 2726 | static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt) |
| 2727 | { |
| 2728 | int err; |
| 2729 | |
| 2730 | if((err = smctr_wait_while_cbusy(dev))) |
| 2731 | return (err); |
| 2732 | |
| 2733 | if((err = smctr_wait_cmd(dev))) |
| 2734 | return (err); |
| 2735 | |
| 2736 | err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE, |
| 2737 | aword_cnt); |
| 2738 | |
| 2739 | return (err); |
| 2740 | } |
| 2741 | |
| 2742 | static int smctr_issue_remove_cmd(struct net_device *dev) |
| 2743 | { |
| 2744 | struct net_local *tp = netdev_priv(dev); |
| 2745 | int err; |
| 2746 | |
| 2747 | if((err = smctr_wait_while_cbusy(dev))) |
| 2748 | return (err); |
| 2749 | |
| 2750 | tp->sclb_ptr->resume_control = 0; |
| 2751 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE; |
| 2752 | |
| 2753 | smctr_set_ctrl_attention(dev); |
| 2754 | |
| 2755 | return (0); |
| 2756 | } |
| 2757 | |
| 2758 | static int smctr_issue_resume_acb_cmd(struct net_device *dev) |
| 2759 | { |
| 2760 | struct net_local *tp = netdev_priv(dev); |
| 2761 | int err; |
| 2762 | |
| 2763 | if((err = smctr_wait_while_cbusy(dev))) |
| 2764 | return (err); |
| 2765 | |
| 2766 | tp->sclb_ptr->resume_control = SCLB_RC_ACB; |
| 2767 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID; |
| 2768 | |
| 2769 | tp->acb_pending = 1; |
| 2770 | |
| 2771 | smctr_set_ctrl_attention(dev); |
| 2772 | |
| 2773 | return (0); |
| 2774 | } |
| 2775 | |
| 2776 | static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue) |
| 2777 | { |
| 2778 | struct net_local *tp = netdev_priv(dev); |
| 2779 | int err; |
| 2780 | |
| 2781 | if((err = smctr_wait_while_cbusy(dev))) |
| 2782 | return (err); |
| 2783 | |
| 2784 | if(queue == MAC_QUEUE) |
| 2785 | tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB; |
| 2786 | else |
| 2787 | tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB; |
| 2788 | |
| 2789 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID; |
| 2790 | |
| 2791 | smctr_set_ctrl_attention(dev); |
| 2792 | |
| 2793 | return (0); |
| 2794 | } |
| 2795 | |
| 2796 | static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue) |
| 2797 | { |
| 2798 | struct net_local *tp = netdev_priv(dev); |
| 2799 | |
| 2800 | if(smctr_debug > 10) |
| 2801 | printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name); |
| 2802 | |
| 2803 | if(smctr_wait_while_cbusy(dev)) |
| 2804 | return (-1); |
| 2805 | |
| 2806 | if(queue == MAC_QUEUE) |
| 2807 | tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB; |
| 2808 | else |
| 2809 | tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB; |
| 2810 | |
| 2811 | tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID; |
| 2812 | |
| 2813 | smctr_set_ctrl_attention(dev); |
| 2814 | |
| 2815 | return (0); |
| 2816 | } |
| 2817 | |
| 2818 | static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue) |
| 2819 | { |
| 2820 | struct net_local *tp = netdev_priv(dev); |
| 2821 | |
| 2822 | if(smctr_debug > 10) |
| 2823 | printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name); |
| 2824 | |
| 2825 | if(smctr_wait_while_cbusy(dev)) |
| 2826 | return (-1); |
| 2827 | |
| 2828 | tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue); |
| 2829 | tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID; |
| 2830 | |
| 2831 | smctr_set_ctrl_attention(dev); |
| 2832 | |
| 2833 | return (0); |
| 2834 | } |
| 2835 | |
| 2836 | static int smctr_issue_test_internal_rom_cmd(struct net_device *dev) |
| 2837 | { |
| 2838 | int err; |
| 2839 | |
| 2840 | err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST, |
| 2841 | TRC_INTERNAL_ROM_TEST); |
| 2842 | |
| 2843 | return (err); |
| 2844 | } |
| 2845 | |
| 2846 | static int smctr_issue_test_hic_cmd(struct net_device *dev) |
| 2847 | { |
| 2848 | int err; |
| 2849 | |
| 2850 | err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST, |
| 2851 | TRC_HOST_INTERFACE_REG_TEST); |
| 2852 | |
| 2853 | return (err); |
| 2854 | } |
| 2855 | |
| 2856 | static int smctr_issue_test_mac_reg_cmd(struct net_device *dev) |
| 2857 | { |
| 2858 | int err; |
| 2859 | |
| 2860 | err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST, |
| 2861 | TRC_MAC_REGISTERS_TEST); |
| 2862 | |
| 2863 | return (err); |
| 2864 | } |
| 2865 | |
| 2866 | static int smctr_issue_trc_loopback_cmd(struct net_device *dev) |
| 2867 | { |
| 2868 | int err; |
| 2869 | |
| 2870 | err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST, |
| 2871 | TRC_INTERNAL_LOOPBACK); |
| 2872 | |
| 2873 | return (err); |
| 2874 | } |
| 2875 | |
| 2876 | static int smctr_issue_tri_loopback_cmd(struct net_device *dev) |
| 2877 | { |
| 2878 | int err; |
| 2879 | |
| 2880 | err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST, |
| 2881 | TRC_TRI_LOOPBACK); |
| 2882 | |
| 2883 | return (err); |
| 2884 | } |
| 2885 | |
| 2886 | static int smctr_issue_write_byte_cmd(struct net_device *dev, |
| 2887 | short aword_cnt, void *byte) |
| 2888 | { |
| 2889 | struct net_local *tp = netdev_priv(dev); |
| 2890 | unsigned int iword, ibyte; |
| 2891 | int err; |
| 2892 | |
| 2893 | if((err = smctr_wait_while_cbusy(dev))) |
| 2894 | return (err); |
| 2895 | |
| 2896 | if((err = smctr_wait_cmd(dev))) |
| 2897 | return (err); |
| 2898 | |
| 2899 | for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff); |
| 2900 | iword++, ibyte += 2) |
| 2901 | { |
| 2902 | tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8) |
| 2903 | | (*((__u8 *)byte + ibyte + 1)); |
| 2904 | } |
| 2905 | |
| 2906 | return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE, |
| 2907 | aword_cnt)); |
| 2908 | } |
| 2909 | |
| 2910 | static int smctr_issue_write_word_cmd(struct net_device *dev, |
| 2911 | short aword_cnt, void *word) |
| 2912 | { |
| 2913 | struct net_local *tp = netdev_priv(dev); |
| 2914 | unsigned int i, err; |
| 2915 | |
| 2916 | if((err = smctr_wait_while_cbusy(dev))) |
| 2917 | return (err); |
| 2918 | |
| 2919 | if((err = smctr_wait_cmd(dev))) |
| 2920 | return (err); |
| 2921 | |
| 2922 | for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++) |
| 2923 | tp->misc_command_data[i] = *((__u16 *)word + i); |
| 2924 | |
| 2925 | err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE, |
| 2926 | aword_cnt); |
| 2927 | |
| 2928 | return (err); |
| 2929 | } |
| 2930 | |
| 2931 | static int smctr_join_complete_state(struct net_device *dev) |
| 2932 | { |
| 2933 | int err; |
| 2934 | |
| 2935 | err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, |
| 2936 | JS_JOIN_COMPLETE_STATE); |
| 2937 | |
| 2938 | return (err); |
| 2939 | } |
| 2940 | |
| 2941 | static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev) |
| 2942 | { |
| 2943 | struct net_local *tp = netdev_priv(dev); |
| 2944 | unsigned int i, j; |
| 2945 | FCBlock *fcb; |
| 2946 | BDBlock *bdb; |
| 2947 | |
| 2948 | for(i = 0; i < NUM_TX_QS_USED; i++) |
| 2949 | { |
| 2950 | fcb = tp->tx_fcb_head[i]; |
| 2951 | bdb = tp->tx_bdb_head[i]; |
| 2952 | |
| 2953 | for(j = 0; j < tp->num_tx_fcbs[i]; j++) |
| 2954 | { |
| 2955 | fcb->bdb_ptr = bdb; |
| 2956 | fcb->trc_bdb_ptr = TRC_POINTER(bdb); |
| 2957 | fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock)); |
| 2958 | bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock)); |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | return (0); |
| 2963 | } |
| 2964 | |
| 2965 | static int smctr_load_firmware(struct net_device *dev) |
| 2966 | { |
| 2967 | struct net_local *tp = netdev_priv(dev); |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 2968 | const struct firmware *fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | __u16 i, checksum = 0; |
| 2970 | int err = 0; |
| 2971 | |
| 2972 | if(smctr_debug > 10) |
| 2973 | printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name); |
| 2974 | |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 2975 | if (request_firmware(&fw, "tr_smctr.bin", &dev->dev)) { |
| 2976 | printk(KERN_ERR "%s: firmware not found\n", dev->name); |
| 2977 | return (UCODE_NOT_PRESENT); |
| 2978 | } |
| 2979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | tp->num_of_tx_buffs = 4; |
| 2981 | tp->mode_bits |= UMAC; |
| 2982 | tp->receive_mask = 0; |
| 2983 | tp->max_packet_size = 4177; |
| 2984 | |
| 2985 | /* Can only upload the firmware once per adapter reset. */ |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 2986 | if (tp->microcode_version != 0) { |
| 2987 | err = (UCODE_PRESENT); |
| 2988 | goto out; |
| 2989 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
| 2991 | /* Verify the firmware exists and is there in the right amount. */ |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 2992 | if (!fw->data |
| 2993 | || (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | { |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 2995 | err = (UCODE_NOT_PRESENT); |
| 2996 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | /* UCODE_SIZE is not included in Checksum. */ |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 3000 | for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2) |
| 3001 | checksum += *((__u16 *)(fw->data + 2 + i)); |
| 3002 | if (checksum) { |
| 3003 | err = (UCODE_NOT_PRESENT); |
| 3004 | goto out; |
| 3005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | |
| 3007 | /* At this point we have a valid firmware image, lets kick it on up. */ |
| 3008 | smctr_enable_adapter_ram(dev); |
| 3009 | smctr_enable_16bit(dev); |
| 3010 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 3011 | |
| 3012 | if((smctr_checksum_firmware(dev)) |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 3013 | || (*(fw->data + UCODE_VERSION_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | > tp->microcode_version)) |
| 3015 | { |
| 3016 | smctr_enable_adapter_ctrl_store(dev); |
| 3017 | |
| 3018 | /* Zero out ram space for firmware. */ |
| 3019 | for(i = 0; i < CS_RAM_SIZE; i += 2) |
| 3020 | *((__u16 *)(tp->ram_access + i)) = 0; |
| 3021 | |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 3022 | smctr_decode_firmware(dev, fw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 3024 | tp->microcode_version = *(fw->data + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | = (tp->microcode_version << 8); |
| 3026 | *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET)) |
| 3027 | = ~(tp->microcode_version << 8) + 1; |
| 3028 | |
| 3029 | smctr_disable_adapter_ctrl_store(dev); |
| 3030 | |
| 3031 | if(smctr_checksum_firmware(dev)) |
| 3032 | err = HARDWARE_FAILED; |
| 3033 | } |
| 3034 | else |
| 3035 | err = UCODE_PRESENT; |
| 3036 | |
| 3037 | smctr_disable_16bit(dev); |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 3038 | out: |
| 3039 | release_firmware(fw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | return (err); |
| 3041 | } |
| 3042 | |
| 3043 | static int smctr_load_node_addr(struct net_device *dev) |
| 3044 | { |
| 3045 | int ioaddr = dev->base_addr; |
| 3046 | unsigned int i; |
| 3047 | __u8 r; |
| 3048 | |
| 3049 | for(i = 0; i < 6; i++) |
| 3050 | { |
| 3051 | r = inb(ioaddr + LAR0 + i); |
| 3052 | dev->dev_addr[i] = (char)r; |
| 3053 | } |
| 3054 | dev->addr_len = 6; |
| 3055 | |
| 3056 | return (0); |
| 3057 | } |
| 3058 | |
| 3059 | /* Lobe Media Test. |
| 3060 | * During the transmission of the initial 1500 lobe media MAC frames, |
| 3061 | * the phase lock loop in the 805 chip may lock, and then un-lock, causing |
| 3062 | * the 825 to go into a PURGE state. When performing a PURGE, the MCT |
| 3063 | * microcode will not transmit any frames given to it by the host, and |
| 3064 | * will consequently cause a timeout. |
| 3065 | * |
| 3066 | * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit |
| 3067 | * queues other then the one used for the lobe_media_test should be |
| 3068 | * disabled.!? |
| 3069 | * |
| 3070 | * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask |
| 3071 | * has any multi-cast or promiscous bits set, the receive_mask needs to |
| 3072 | * be changed to clear the multi-cast or promiscous mode bits, the lobe_test |
| 3073 | * run, and then the receive mask set back to its original value if the test |
| 3074 | * is successful. |
| 3075 | */ |
| 3076 | static int smctr_lobe_media_test(struct net_device *dev) |
| 3077 | { |
| 3078 | struct net_local *tp = netdev_priv(dev); |
| 3079 | unsigned int i, perror = 0; |
| 3080 | unsigned short saved_rcv_mask; |
| 3081 | |
| 3082 | if(smctr_debug > 10) |
| 3083 | printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name); |
| 3084 | |
| 3085 | /* Clear receive mask for lobe test. */ |
| 3086 | saved_rcv_mask = tp->receive_mask; |
| 3087 | tp->receive_mask = 0; |
| 3088 | |
| 3089 | smctr_chg_rx_mask(dev); |
| 3090 | |
| 3091 | /* Setup the lobe media test. */ |
| 3092 | smctr_lobe_media_test_cmd(dev); |
| 3093 | if(smctr_wait_cmd(dev)) |
| 3094 | { |
| 3095 | smctr_reset_adapter(dev); |
| 3096 | tp->status = CLOSED; |
| 3097 | return (LOBE_MEDIA_TEST_FAILED); |
| 3098 | } |
| 3099 | |
| 3100 | /* Tx lobe media test frames. */ |
| 3101 | for(i = 0; i < 1500; ++i) |
| 3102 | { |
| 3103 | if(smctr_send_lobe_media_test(dev)) |
| 3104 | { |
| 3105 | if(perror) |
| 3106 | { |
| 3107 | smctr_reset_adapter(dev); |
| 3108 | tp->state = CLOSED; |
| 3109 | return (LOBE_MEDIA_TEST_FAILED); |
| 3110 | } |
| 3111 | else |
| 3112 | { |
| 3113 | perror = 1; |
| 3114 | if(smctr_lobe_media_test_cmd(dev)) |
| 3115 | { |
| 3116 | smctr_reset_adapter(dev); |
| 3117 | tp->state = CLOSED; |
| 3118 | return (LOBE_MEDIA_TEST_FAILED); |
| 3119 | } |
| 3120 | } |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | if(smctr_send_dat(dev)) |
| 3125 | { |
| 3126 | if(smctr_send_dat(dev)) |
| 3127 | { |
| 3128 | smctr_reset_adapter(dev); |
| 3129 | tp->state = CLOSED; |
| 3130 | return (LOBE_MEDIA_TEST_FAILED); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | /* Check if any frames received during test. */ |
| 3135 | if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status) |
| 3136 | || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status)) |
| 3137 | { |
| 3138 | smctr_reset_adapter(dev); |
| 3139 | tp->state = CLOSED; |
| 3140 | return (LOBE_MEDIA_TEST_FAILED); |
| 3141 | } |
| 3142 | |
| 3143 | /* Set receive mask to "Promisc" mode. */ |
| 3144 | tp->receive_mask = saved_rcv_mask; |
| 3145 | |
| 3146 | smctr_chg_rx_mask(dev); |
| 3147 | |
| 3148 | return (0); |
| 3149 | } |
| 3150 | |
| 3151 | static int smctr_lobe_media_test_cmd(struct net_device *dev) |
| 3152 | { |
| 3153 | struct net_local *tp = netdev_priv(dev); |
| 3154 | int err; |
| 3155 | |
| 3156 | if(smctr_debug > 10) |
| 3157 | printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name); |
| 3158 | |
| 3159 | /* Change to lobe media test state. */ |
| 3160 | if(tp->monitor_state != MS_BEACON_TEST_STATE) |
| 3161 | { |
| 3162 | smctr_lobe_media_test_state(dev); |
| 3163 | if(smctr_wait_cmd(dev)) |
| 3164 | { |
| 3165 | printk(KERN_ERR "Lobe Failed test state\n"); |
| 3166 | return (LOBE_MEDIA_TEST_FAILED); |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST, |
| 3171 | TRC_LOBE_MEDIA_TEST); |
| 3172 | |
| 3173 | return (err); |
| 3174 | } |
| 3175 | |
| 3176 | static int smctr_lobe_media_test_state(struct net_device *dev) |
| 3177 | { |
| 3178 | int err; |
| 3179 | |
| 3180 | err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, |
| 3181 | JS_LOBE_TEST_STATE); |
| 3182 | |
| 3183 | return (err); |
| 3184 | } |
| 3185 | |
| 3186 | static int smctr_make_8025_hdr(struct net_device *dev, |
| 3187 | MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc) |
| 3188 | { |
| 3189 | tmf->ac = MSB(ac_fc); /* msb is access control */ |
| 3190 | tmf->fc = LSB(ac_fc); /* lsb is frame control */ |
| 3191 | |
| 3192 | tmf->sa[0] = dev->dev_addr[0]; |
| 3193 | tmf->sa[1] = dev->dev_addr[1]; |
| 3194 | tmf->sa[2] = dev->dev_addr[2]; |
| 3195 | tmf->sa[3] = dev->dev_addr[3]; |
| 3196 | tmf->sa[4] = dev->dev_addr[4]; |
| 3197 | tmf->sa[5] = dev->dev_addr[5]; |
| 3198 | |
| 3199 | switch(tmf->vc) |
| 3200 | { |
| 3201 | /* Send RQ_INIT to RPS */ |
| 3202 | case RQ_INIT: |
| 3203 | tmf->da[0] = 0xc0; |
| 3204 | tmf->da[1] = 0x00; |
| 3205 | tmf->da[2] = 0x00; |
| 3206 | tmf->da[3] = 0x00; |
| 3207 | tmf->da[4] = 0x00; |
| 3208 | tmf->da[5] = 0x02; |
| 3209 | break; |
| 3210 | |
| 3211 | /* Send RPT_TX_FORWARD to CRS */ |
| 3212 | case RPT_TX_FORWARD: |
| 3213 | tmf->da[0] = 0xc0; |
| 3214 | tmf->da[1] = 0x00; |
| 3215 | tmf->da[2] = 0x00; |
| 3216 | tmf->da[3] = 0x00; |
| 3217 | tmf->da[4] = 0x00; |
| 3218 | tmf->da[5] = 0x10; |
| 3219 | break; |
| 3220 | |
| 3221 | /* Everything else goes to sender */ |
| 3222 | default: |
| 3223 | tmf->da[0] = rmf->sa[0]; |
| 3224 | tmf->da[1] = rmf->sa[1]; |
| 3225 | tmf->da[2] = rmf->sa[2]; |
| 3226 | tmf->da[3] = rmf->sa[3]; |
| 3227 | tmf->da[4] = rmf->sa[4]; |
| 3228 | tmf->da[5] = rmf->sa[5]; |
| 3229 | break; |
| 3230 | } |
| 3231 | |
| 3232 | return (0); |
| 3233 | } |
| 3234 | |
| 3235 | static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3236 | { |
| 3237 | struct net_local *tp = netdev_priv(dev); |
| 3238 | |
| 3239 | tsv->svi = AUTHORIZED_ACCESS_PRIORITY; |
| 3240 | tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY; |
| 3241 | |
| 3242 | tsv->svv[0] = MSB(tp->authorized_access_priority); |
| 3243 | tsv->svv[1] = LSB(tp->authorized_access_priority); |
| 3244 | |
| 3245 | return (0); |
| 3246 | } |
| 3247 | |
| 3248 | static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3249 | { |
| 3250 | tsv->svi = ADDRESS_MODIFER; |
| 3251 | tsv->svl = S_ADDRESS_MODIFER; |
| 3252 | |
| 3253 | tsv->svv[0] = 0; |
| 3254 | tsv->svv[1] = 0; |
| 3255 | |
| 3256 | return (0); |
| 3257 | } |
| 3258 | |
| 3259 | static int smctr_make_auth_funct_class(struct net_device *dev, |
| 3260 | MAC_SUB_VECTOR *tsv) |
| 3261 | { |
| 3262 | struct net_local *tp = netdev_priv(dev); |
| 3263 | |
| 3264 | tsv->svi = AUTHORIZED_FUNCTION_CLASS; |
| 3265 | tsv->svl = S_AUTHORIZED_FUNCTION_CLASS; |
| 3266 | |
| 3267 | tsv->svv[0] = MSB(tp->authorized_function_classes); |
| 3268 | tsv->svv[1] = LSB(tp->authorized_function_classes); |
| 3269 | |
| 3270 | return (0); |
| 3271 | } |
| 3272 | |
| 3273 | static int smctr_make_corr(struct net_device *dev, |
| 3274 | MAC_SUB_VECTOR *tsv, __u16 correlator) |
| 3275 | { |
| 3276 | tsv->svi = CORRELATOR; |
| 3277 | tsv->svl = S_CORRELATOR; |
| 3278 | |
| 3279 | tsv->svv[0] = MSB(correlator); |
| 3280 | tsv->svv[1] = LSB(correlator); |
| 3281 | |
| 3282 | return (0); |
| 3283 | } |
| 3284 | |
| 3285 | static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3286 | { |
| 3287 | struct net_local *tp = netdev_priv(dev); |
| 3288 | |
| 3289 | smctr_get_functional_address(dev); |
| 3290 | |
| 3291 | tsv->svi = FUNCTIONAL_ADDRESS; |
| 3292 | tsv->svl = S_FUNCTIONAL_ADDRESS; |
| 3293 | |
| 3294 | tsv->svv[0] = MSB(tp->misc_command_data[0]); |
| 3295 | tsv->svv[1] = LSB(tp->misc_command_data[0]); |
| 3296 | |
| 3297 | tsv->svv[2] = MSB(tp->misc_command_data[1]); |
| 3298 | tsv->svv[3] = LSB(tp->misc_command_data[1]); |
| 3299 | |
| 3300 | return (0); |
| 3301 | } |
| 3302 | |
| 3303 | static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3304 | { |
| 3305 | struct net_local *tp = netdev_priv(dev); |
| 3306 | |
| 3307 | smctr_get_group_address(dev); |
| 3308 | |
| 3309 | tsv->svi = GROUP_ADDRESS; |
| 3310 | tsv->svl = S_GROUP_ADDRESS; |
| 3311 | |
| 3312 | tsv->svv[0] = MSB(tp->misc_command_data[0]); |
| 3313 | tsv->svv[1] = LSB(tp->misc_command_data[0]); |
| 3314 | |
| 3315 | tsv->svv[2] = MSB(tp->misc_command_data[1]); |
| 3316 | tsv->svv[3] = LSB(tp->misc_command_data[1]); |
| 3317 | |
| 3318 | /* Set Group Address Sub-vector to all zeros if only the |
| 3319 | * Group Address/Functional Address Indicator is set. |
| 3320 | */ |
| 3321 | if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00 |
| 3322 | && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00) |
| 3323 | tsv->svv[0] = 0x00; |
| 3324 | |
| 3325 | return (0); |
| 3326 | } |
| 3327 | |
| 3328 | static int smctr_make_phy_drop_num(struct net_device *dev, |
| 3329 | MAC_SUB_VECTOR *tsv) |
| 3330 | { |
| 3331 | struct net_local *tp = netdev_priv(dev); |
| 3332 | |
| 3333 | smctr_get_physical_drop_number(dev); |
| 3334 | |
| 3335 | tsv->svi = PHYSICAL_DROP; |
| 3336 | tsv->svl = S_PHYSICAL_DROP; |
| 3337 | |
| 3338 | tsv->svv[0] = MSB(tp->misc_command_data[0]); |
| 3339 | tsv->svv[1] = LSB(tp->misc_command_data[0]); |
| 3340 | |
| 3341 | tsv->svv[2] = MSB(tp->misc_command_data[1]); |
| 3342 | tsv->svv[3] = LSB(tp->misc_command_data[1]); |
| 3343 | |
| 3344 | return (0); |
| 3345 | } |
| 3346 | |
| 3347 | static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3348 | { |
| 3349 | int i; |
| 3350 | |
| 3351 | tsv->svi = PRODUCT_INSTANCE_ID; |
| 3352 | tsv->svl = S_PRODUCT_INSTANCE_ID; |
| 3353 | |
| 3354 | for(i = 0; i < 18; i++) |
| 3355 | tsv->svv[i] = 0xF0; |
| 3356 | |
| 3357 | return (0); |
| 3358 | } |
| 3359 | |
| 3360 | static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3361 | { |
| 3362 | struct net_local *tp = netdev_priv(dev); |
| 3363 | |
| 3364 | smctr_get_station_id(dev); |
| 3365 | |
| 3366 | tsv->svi = STATION_IDENTIFER; |
| 3367 | tsv->svl = S_STATION_IDENTIFER; |
| 3368 | |
| 3369 | tsv->svv[0] = MSB(tp->misc_command_data[0]); |
| 3370 | tsv->svv[1] = LSB(tp->misc_command_data[0]); |
| 3371 | |
| 3372 | tsv->svv[2] = MSB(tp->misc_command_data[1]); |
| 3373 | tsv->svv[3] = LSB(tp->misc_command_data[1]); |
| 3374 | |
| 3375 | tsv->svv[4] = MSB(tp->misc_command_data[2]); |
| 3376 | tsv->svv[5] = LSB(tp->misc_command_data[2]); |
| 3377 | |
| 3378 | return (0); |
| 3379 | } |
| 3380 | |
| 3381 | static int smctr_make_ring_station_status(struct net_device *dev, |
| 3382 | MAC_SUB_VECTOR * tsv) |
| 3383 | { |
| 3384 | tsv->svi = RING_STATION_STATUS; |
| 3385 | tsv->svl = S_RING_STATION_STATUS; |
| 3386 | |
| 3387 | tsv->svv[0] = 0; |
| 3388 | tsv->svv[1] = 0; |
| 3389 | tsv->svv[2] = 0; |
| 3390 | tsv->svv[3] = 0; |
| 3391 | tsv->svv[4] = 0; |
| 3392 | tsv->svv[5] = 0; |
| 3393 | |
| 3394 | return (0); |
| 3395 | } |
| 3396 | |
| 3397 | static int smctr_make_ring_station_version(struct net_device *dev, |
| 3398 | MAC_SUB_VECTOR *tsv) |
| 3399 | { |
| 3400 | struct net_local *tp = netdev_priv(dev); |
| 3401 | |
| 3402 | tsv->svi = RING_STATION_VERSION_NUMBER; |
| 3403 | tsv->svl = S_RING_STATION_VERSION_NUMBER; |
| 3404 | |
| 3405 | tsv->svv[0] = 0xe2; /* EBCDIC - S */ |
| 3406 | tsv->svv[1] = 0xd4; /* EBCDIC - M */ |
| 3407 | tsv->svv[2] = 0xc3; /* EBCDIC - C */ |
| 3408 | tsv->svv[3] = 0x40; /* EBCDIC - */ |
| 3409 | tsv->svv[4] = 0xe5; /* EBCDIC - V */ |
| 3410 | tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4); |
| 3411 | tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f); |
| 3412 | tsv->svv[7] = 0x40; /* EBCDIC - */ |
| 3413 | tsv->svv[8] = 0xe7; /* EBCDIC - X */ |
| 3414 | |
| 3415 | if(tp->extra_info & CHIP_REV_MASK) |
| 3416 | tsv->svv[9] = 0xc5; /* EBCDIC - E */ |
| 3417 | else |
| 3418 | tsv->svv[9] = 0xc4; /* EBCDIC - D */ |
| 3419 | |
| 3420 | return (0); |
| 3421 | } |
| 3422 | |
| 3423 | static int smctr_make_tx_status_code(struct net_device *dev, |
| 3424 | MAC_SUB_VECTOR *tsv, __u16 tx_fstatus) |
| 3425 | { |
| 3426 | tsv->svi = TRANSMIT_STATUS_CODE; |
| 3427 | tsv->svl = S_TRANSMIT_STATUS_CODE; |
| 3428 | |
Jay Schulist | 26c080bf | 2008-03-18 17:53:09 -0400 | [diff] [blame] | 3429 | tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* Stripped frame status of Transmitted Frame */ |
| 3432 | tsv->svv[1] = tx_fstatus & 0xff; |
| 3433 | |
| 3434 | return (0); |
| 3435 | } |
| 3436 | |
| 3437 | static int smctr_make_upstream_neighbor_addr(struct net_device *dev, |
| 3438 | MAC_SUB_VECTOR *tsv) |
| 3439 | { |
| 3440 | struct net_local *tp = netdev_priv(dev); |
| 3441 | |
| 3442 | smctr_get_upstream_neighbor_addr(dev); |
| 3443 | |
| 3444 | tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS; |
| 3445 | tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS; |
| 3446 | |
| 3447 | tsv->svv[0] = MSB(tp->misc_command_data[0]); |
| 3448 | tsv->svv[1] = LSB(tp->misc_command_data[0]); |
| 3449 | |
| 3450 | tsv->svv[2] = MSB(tp->misc_command_data[1]); |
| 3451 | tsv->svv[3] = LSB(tp->misc_command_data[1]); |
| 3452 | |
| 3453 | tsv->svv[4] = MSB(tp->misc_command_data[2]); |
| 3454 | tsv->svv[5] = LSB(tp->misc_command_data[2]); |
| 3455 | |
| 3456 | return (0); |
| 3457 | } |
| 3458 | |
| 3459 | static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv) |
| 3460 | { |
| 3461 | tsv->svi = WRAP_DATA; |
| 3462 | tsv->svl = S_WRAP_DATA; |
| 3463 | |
| 3464 | return (0); |
| 3465 | } |
| 3466 | |
| 3467 | /* |
| 3468 | * Open/initialize the board. This is called sometime after |
| 3469 | * booting when the 'ifconfig' program is run. |
| 3470 | * |
| 3471 | * This routine should set everything up anew at each open, even |
| 3472 | * registers that "should" only need to be set once at boot, so that |
| 3473 | * there is non-reboot way to recover if something goes wrong. |
| 3474 | */ |
| 3475 | static int smctr_open(struct net_device *dev) |
| 3476 | { |
| 3477 | int err; |
| 3478 | |
| 3479 | if(smctr_debug > 10) |
| 3480 | printk(KERN_DEBUG "%s: smctr_open\n", dev->name); |
| 3481 | |
| 3482 | err = smctr_init_adapter(dev); |
| 3483 | if(err < 0) |
| 3484 | return (err); |
| 3485 | |
| 3486 | return (err); |
| 3487 | } |
| 3488 | |
| 3489 | /* Interrupt driven open of Token card. */ |
| 3490 | static int smctr_open_tr(struct net_device *dev) |
| 3491 | { |
| 3492 | struct net_local *tp = netdev_priv(dev); |
| 3493 | unsigned long flags; |
| 3494 | int err; |
| 3495 | |
| 3496 | if(smctr_debug > 10) |
| 3497 | printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name); |
| 3498 | |
| 3499 | /* Now we can actually open the adapter. */ |
| 3500 | if(tp->status == OPEN) |
| 3501 | return (0); |
| 3502 | if(tp->status != INITIALIZED) |
| 3503 | return (-1); |
| 3504 | |
| 3505 | /* FIXME: it would work a lot better if we masked the irq sources |
| 3506 | on the card here, then we could skip the locking and poll nicely */ |
| 3507 | spin_lock_irqsave(&tp->lock, flags); |
| 3508 | |
| 3509 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 3510 | |
| 3511 | if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE))) |
| 3512 | goto out; |
| 3513 | |
| 3514 | if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE))) |
| 3515 | goto out; |
| 3516 | |
| 3517 | if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE))) |
| 3518 | goto out; |
| 3519 | |
| 3520 | if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE))) |
| 3521 | goto out; |
| 3522 | |
| 3523 | tp->status = CLOSED; |
| 3524 | |
| 3525 | /* Insert into the Ring or Enter Loopback Mode. */ |
| 3526 | if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1) |
| 3527 | { |
| 3528 | tp->status = CLOSED; |
| 3529 | |
| 3530 | if(!(err = smctr_issue_trc_loopback_cmd(dev))) |
| 3531 | { |
| 3532 | if(!(err = smctr_wait_cmd(dev))) |
| 3533 | tp->status = OPEN; |
| 3534 | } |
| 3535 | |
| 3536 | smctr_status_chg(dev); |
| 3537 | } |
| 3538 | else |
| 3539 | { |
| 3540 | if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2) |
| 3541 | { |
| 3542 | tp->status = CLOSED; |
| 3543 | if(!(err = smctr_issue_tri_loopback_cmd(dev))) |
| 3544 | { |
| 3545 | if(!(err = smctr_wait_cmd(dev))) |
| 3546 | tp->status = OPEN; |
| 3547 | } |
| 3548 | |
| 3549 | smctr_status_chg(dev); |
| 3550 | } |
| 3551 | else |
| 3552 | { |
| 3553 | if((tp->mode_bits & LOOPING_MODE_MASK) |
| 3554 | == LOOPBACK_MODE_3) |
| 3555 | { |
| 3556 | tp->status = CLOSED; |
| 3557 | if(!(err = smctr_lobe_media_test_cmd(dev))) |
| 3558 | { |
| 3559 | if(!(err = smctr_wait_cmd(dev))) |
| 3560 | tp->status = OPEN; |
| 3561 | } |
| 3562 | smctr_status_chg(dev); |
| 3563 | } |
| 3564 | else |
| 3565 | { |
| 3566 | if(!(err = smctr_lobe_media_test(dev))) |
| 3567 | err = smctr_issue_insert_cmd(dev); |
| 3568 | else |
| 3569 | { |
| 3570 | if(err == LOBE_MEDIA_TEST_FAILED) |
| 3571 | printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name); |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | out: |
| 3578 | spin_unlock_irqrestore(&tp->lock, flags); |
| 3579 | |
| 3580 | return (err); |
| 3581 | } |
| 3582 | |
| 3583 | /* Check for a network adapter of this type, |
| 3584 | * and return device structure if one exists. |
| 3585 | */ |
| 3586 | struct net_device __init *smctr_probe(int unit) |
| 3587 | { |
| 3588 | struct net_device *dev = alloc_trdev(sizeof(struct net_local)); |
| 3589 | static const unsigned ports[] = { |
| 3590 | 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300, |
| 3591 | 0x320, 0x340, 0x360, 0x380, 0 |
| 3592 | }; |
| 3593 | const unsigned *port; |
| 3594 | int err = 0; |
| 3595 | |
| 3596 | if (!dev) |
| 3597 | return ERR_PTR(-ENOMEM); |
| 3598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | if (unit >= 0) { |
| 3600 | sprintf(dev->name, "tr%d", unit); |
| 3601 | netdev_boot_setup_check(dev); |
| 3602 | } |
| 3603 | |
| 3604 | if (dev->base_addr > 0x1ff) /* Check a single specified location. */ |
| 3605 | err = smctr_probe1(dev, dev->base_addr); |
| 3606 | else if(dev->base_addr != 0) /* Don't probe at all. */ |
| 3607 | err =-ENXIO; |
| 3608 | else { |
| 3609 | for (port = ports; *port; port++) { |
| 3610 | err = smctr_probe1(dev, *port); |
| 3611 | if (!err) |
| 3612 | break; |
| 3613 | } |
| 3614 | } |
| 3615 | if (err) |
| 3616 | goto out; |
| 3617 | err = register_netdev(dev); |
| 3618 | if (err) |
| 3619 | goto out1; |
| 3620 | return dev; |
| 3621 | out1: |
| 3622 | #ifdef CONFIG_MCA_LEGACY |
| 3623 | { struct net_local *tp = netdev_priv(dev); |
| 3624 | if (tp->slot_num) |
| 3625 | mca_mark_as_unused(tp->slot_num); |
| 3626 | } |
| 3627 | #endif |
| 3628 | release_region(dev->base_addr, SMCTR_IO_EXTENT); |
| 3629 | free_irq(dev->irq, dev); |
| 3630 | out: |
| 3631 | free_netdev(dev); |
| 3632 | return ERR_PTR(err); |
| 3633 | } |
| 3634 | |
| 3635 | |
| 3636 | static int __init smctr_probe1(struct net_device *dev, int ioaddr) |
| 3637 | { |
| 3638 | static unsigned version_printed; |
| 3639 | struct net_local *tp = netdev_priv(dev); |
| 3640 | int err; |
| 3641 | __u32 *ram; |
| 3642 | |
| 3643 | if(smctr_debug && version_printed++ == 0) |
| 3644 | printk(version); |
| 3645 | |
| 3646 | spin_lock_init(&tp->lock); |
| 3647 | dev->base_addr = ioaddr; |
| 3648 | |
| 3649 | /* Actually detect an adapter now. */ |
| 3650 | err = smctr_chk_isa(dev); |
| 3651 | if(err < 0) |
| 3652 | { |
| 3653 | if ((err = smctr_chk_mca(dev)) < 0) { |
| 3654 | err = -ENODEV; |
| 3655 | goto out; |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | tp = netdev_priv(dev); |
| 3660 | dev->mem_start = tp->ram_base; |
| 3661 | dev->mem_end = dev->mem_start + 0x10000; |
| 3662 | ram = (__u32 *)phys_to_virt(dev->mem_start); |
| 3663 | tp->ram_access = *(__u32 *)&ram; |
| 3664 | tp->status = NOT_INITIALIZED; |
| 3665 | |
| 3666 | err = smctr_load_firmware(dev); |
| 3667 | if(err != UCODE_PRESENT && err != SUCCESS) |
| 3668 | { |
| 3669 | printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err); |
| 3670 | err = -EIO; |
| 3671 | goto out; |
| 3672 | } |
| 3673 | |
| 3674 | /* Allow user to specify ring speed on module insert. */ |
| 3675 | if(ringspeed == 4) |
| 3676 | tp->media_type = MEDIA_UTP_4; |
| 3677 | else |
| 3678 | tp->media_type = MEDIA_UTP_16; |
| 3679 | |
| 3680 | printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n", |
| 3681 | dev->name, smctr_name, smctr_model, |
| 3682 | (unsigned int)dev->base_addr, |
| 3683 | dev->irq, tp->rom_base, tp->ram_base); |
| 3684 | |
| 3685 | dev->open = smctr_open; |
| 3686 | dev->stop = smctr_close; |
| 3687 | dev->hard_start_xmit = smctr_send_packet; |
| 3688 | dev->tx_timeout = smctr_timeout; |
| 3689 | dev->watchdog_timeo = HZ; |
| 3690 | dev->get_stats = smctr_get_stats; |
| 3691 | dev->set_multicast_list = &smctr_set_multicast_list; |
| 3692 | return (0); |
| 3693 | |
| 3694 | out: |
| 3695 | return err; |
| 3696 | } |
| 3697 | |
| 3698 | static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size, |
| 3699 | struct net_device *dev, __u16 rx_status) |
| 3700 | { |
| 3701 | struct net_local *tp = netdev_priv(dev); |
| 3702 | struct sk_buff *skb; |
| 3703 | __u16 rcode, correlator; |
| 3704 | int err = 0; |
| 3705 | __u8 xframe = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | |
| 3707 | rmf->vl = SWAP_BYTES(rmf->vl); |
| 3708 | if(rx_status & FCB_RX_STATUS_DA_MATCHED) |
| 3709 | { |
| 3710 | switch(rmf->vc) |
| 3711 | { |
| 3712 | /* Received MAC Frames Processed by RS. */ |
| 3713 | case INIT: |
| 3714 | if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED) |
| 3715 | { |
| 3716 | return (rcode); |
| 3717 | } |
| 3718 | |
| 3719 | if((err = smctr_send_rsp(dev, rmf, rcode, |
| 3720 | correlator))) |
| 3721 | { |
| 3722 | return (err); |
| 3723 | } |
| 3724 | break; |
| 3725 | |
| 3726 | case CHG_PARM: |
| 3727 | if((rcode = smctr_rcv_chg_param(dev, rmf, |
| 3728 | &correlator)) ==HARDWARE_FAILED) |
| 3729 | { |
| 3730 | return (rcode); |
| 3731 | } |
| 3732 | |
| 3733 | if((err = smctr_send_rsp(dev, rmf, rcode, |
| 3734 | correlator))) |
| 3735 | { |
| 3736 | return (err); |
| 3737 | } |
| 3738 | break; |
| 3739 | |
| 3740 | case RQ_ADDR: |
| 3741 | if((rcode = smctr_rcv_rq_addr_state_attch(dev, |
| 3742 | rmf, &correlator)) != POSITIVE_ACK) |
| 3743 | { |
| 3744 | if(rcode == HARDWARE_FAILED) |
| 3745 | return (rcode); |
| 3746 | else |
| 3747 | return (smctr_send_rsp(dev, rmf, |
| 3748 | rcode, correlator)); |
| 3749 | } |
| 3750 | |
| 3751 | if((err = smctr_send_rpt_addr(dev, rmf, |
| 3752 | correlator))) |
| 3753 | { |
| 3754 | return (err); |
| 3755 | } |
| 3756 | break; |
| 3757 | |
| 3758 | case RQ_ATTCH: |
| 3759 | if((rcode = smctr_rcv_rq_addr_state_attch(dev, |
| 3760 | rmf, &correlator)) != POSITIVE_ACK) |
| 3761 | { |
| 3762 | if(rcode == HARDWARE_FAILED) |
| 3763 | return (rcode); |
| 3764 | else |
| 3765 | return (smctr_send_rsp(dev, rmf, |
| 3766 | rcode, |
| 3767 | correlator)); |
| 3768 | } |
| 3769 | |
| 3770 | if((err = smctr_send_rpt_attch(dev, rmf, |
| 3771 | correlator))) |
| 3772 | { |
| 3773 | return (err); |
| 3774 | } |
| 3775 | break; |
| 3776 | |
| 3777 | case RQ_STATE: |
| 3778 | if((rcode = smctr_rcv_rq_addr_state_attch(dev, |
| 3779 | rmf, &correlator)) != POSITIVE_ACK) |
| 3780 | { |
| 3781 | if(rcode == HARDWARE_FAILED) |
| 3782 | return (rcode); |
| 3783 | else |
| 3784 | return (smctr_send_rsp(dev, rmf, |
| 3785 | rcode, |
| 3786 | correlator)); |
| 3787 | } |
| 3788 | |
| 3789 | if((err = smctr_send_rpt_state(dev, rmf, |
| 3790 | correlator))) |
| 3791 | { |
| 3792 | return (err); |
| 3793 | } |
| 3794 | break; |
| 3795 | |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 3796 | case TX_FORWARD: { |
| 3797 | __u16 uninitialized_var(tx_fstatus); |
| 3798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | if((rcode = smctr_rcv_tx_forward(dev, rmf)) |
| 3800 | != POSITIVE_ACK) |
| 3801 | { |
| 3802 | if(rcode == HARDWARE_FAILED) |
| 3803 | return (rcode); |
| 3804 | else |
| 3805 | return (smctr_send_rsp(dev, rmf, |
| 3806 | rcode, |
| 3807 | correlator)); |
| 3808 | } |
| 3809 | |
| 3810 | if((err = smctr_send_tx_forward(dev, rmf, |
| 3811 | &tx_fstatus)) == HARDWARE_FAILED) |
| 3812 | { |
| 3813 | return (err); |
| 3814 | } |
| 3815 | |
| 3816 | if(err == A_FRAME_WAS_FORWARDED) |
| 3817 | { |
| 3818 | if((err = smctr_send_rpt_tx_forward(dev, |
| 3819 | rmf, tx_fstatus)) |
| 3820 | == HARDWARE_FAILED) |
| 3821 | { |
| 3822 | return (err); |
| 3823 | } |
| 3824 | } |
| 3825 | break; |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 3826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | |
| 3828 | /* Received MAC Frames Processed by CRS/REM/RPS. */ |
| 3829 | case RSP: |
| 3830 | case RQ_INIT: |
| 3831 | case RPT_NEW_MON: |
| 3832 | case RPT_SUA_CHG: |
| 3833 | case RPT_ACTIVE_ERR: |
| 3834 | case RPT_NN_INCMP: |
| 3835 | case RPT_ERROR: |
| 3836 | case RPT_ATTCH: |
| 3837 | case RPT_STATE: |
| 3838 | case RPT_ADDR: |
| 3839 | break; |
| 3840 | |
| 3841 | /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */ |
| 3842 | default: |
| 3843 | xframe = 0; |
| 3844 | if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)) |
| 3845 | { |
| 3846 | rcode = smctr_rcv_unknown(dev, rmf, |
| 3847 | &correlator); |
| 3848 | if((err = smctr_send_rsp(dev, rmf,rcode, |
| 3849 | correlator))) |
| 3850 | { |
| 3851 | return (err); |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | break; |
| 3856 | } |
| 3857 | } |
| 3858 | else |
| 3859 | { |
| 3860 | /* 1. DA doesn't match (Promiscuous Mode). |
| 3861 | * 2. Parse for Extended MAC Frame Type. |
| 3862 | */ |
| 3863 | switch(rmf->vc) |
| 3864 | { |
| 3865 | case RSP: |
| 3866 | case INIT: |
| 3867 | case RQ_INIT: |
| 3868 | case RQ_ADDR: |
| 3869 | case RQ_ATTCH: |
| 3870 | case RQ_STATE: |
| 3871 | case CHG_PARM: |
| 3872 | case RPT_ADDR: |
| 3873 | case RPT_ERROR: |
| 3874 | case RPT_ATTCH: |
| 3875 | case RPT_STATE: |
| 3876 | case RPT_NEW_MON: |
| 3877 | case RPT_SUA_CHG: |
| 3878 | case RPT_NN_INCMP: |
| 3879 | case RPT_ACTIVE_ERR: |
| 3880 | break; |
| 3881 | |
| 3882 | default: |
| 3883 | xframe = 0; |
| 3884 | break; |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | /* NOTE: UNKNOWN MAC frames will NOT be passed up unless |
| 3889 | * ACCEPT_ATT_MAC_FRAMES is set. |
| 3890 | */ |
| 3891 | if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) |
| 3892 | && (xframe == (__u8)0)) |
| 3893 | || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES) |
| 3894 | && (xframe == (__u8)1))) |
| 3895 | { |
| 3896 | rmf->vl = SWAP_BYTES(rmf->vl); |
| 3897 | |
| 3898 | if (!(skb = dev_alloc_skb(size))) |
| 3899 | return -ENOMEM; |
| 3900 | skb->len = size; |
| 3901 | |
| 3902 | /* Slide data into a sleek skb. */ |
| 3903 | skb_put(skb, skb->len); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 3904 | skb_copy_to_linear_data(skb, rmf, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | |
| 3906 | /* Update Counters */ |
| 3907 | tp->MacStat.rx_packets++; |
| 3908 | tp->MacStat.rx_bytes += skb->len; |
| 3909 | |
| 3910 | /* Kick the packet on up. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | skb->protocol = tr_type_trans(skb, dev); |
| 3912 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | err = 0; |
| 3914 | } |
| 3915 | |
| 3916 | return (err); |
| 3917 | } |
| 3918 | |
| 3919 | /* Adapter RAM test. Incremental word ODD boundary data test. */ |
| 3920 | static int smctr_ram_memory_test(struct net_device *dev) |
| 3921 | { |
| 3922 | struct net_local *tp = netdev_priv(dev); |
| 3923 | __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0, |
| 3924 | word_read = 0, err_word = 0, err_pattern = 0; |
| 3925 | unsigned int err_offset; |
| 3926 | __u32 j, pword; |
| 3927 | __u8 err = 0; |
| 3928 | |
| 3929 | if(smctr_debug > 10) |
| 3930 | printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name); |
| 3931 | |
| 3932 | start_pattern = 0x0001; |
| 3933 | pages_of_ram = tp->ram_size / tp->ram_usable; |
| 3934 | pword = tp->ram_access; |
| 3935 | |
| 3936 | /* Incremental word ODD boundary test. */ |
| 3937 | for(page = 0; (page < pages_of_ram) && (~err); |
| 3938 | page++, start_pattern += 0x8000) |
| 3939 | { |
| 3940 | smctr_set_page(dev, (__u8 *)(tp->ram_access |
| 3941 | + (page * tp->ram_usable * 1024) + 1)); |
| 3942 | word_pattern = start_pattern; |
| 3943 | |
| 3944 | for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2) |
| 3945 | *(__u16 *)(pword + j) = word_pattern++; |
| 3946 | |
| 3947 | word_pattern = start_pattern; |
| 3948 | |
| 3949 | for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1 |
| 3950 | && (~err); j += 2, word_pattern++) |
| 3951 | { |
| 3952 | word_read = *(__u16 *)(pword + j); |
| 3953 | if(word_read != word_pattern) |
| 3954 | { |
| 3955 | err = (__u8)1; |
| 3956 | err_offset = j; |
| 3957 | err_word = word_read; |
| 3958 | err_pattern = word_pattern; |
| 3959 | return (RAM_TEST_FAILED); |
| 3960 | } |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | /* Zero out memory. */ |
| 3965 | for(page = 0; page < pages_of_ram && (~err); page++) |
| 3966 | { |
| 3967 | smctr_set_page(dev, (__u8 *)(tp->ram_access |
| 3968 | + (page * tp->ram_usable * 1024))); |
| 3969 | word_pattern = 0; |
| 3970 | |
| 3971 | for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2) |
| 3972 | *(__u16 *)(pword + j) = word_pattern; |
| 3973 | |
| 3974 | for(j =0; j < (__u32)tp->ram_usable * 1024 |
| 3975 | && (~err); j += 2) |
| 3976 | { |
| 3977 | word_read = *(__u16 *)(pword + j); |
| 3978 | if(word_read != word_pattern) |
| 3979 | { |
| 3980 | err = (__u8)1; |
| 3981 | err_offset = j; |
| 3982 | err_word = word_read; |
| 3983 | err_pattern = word_pattern; |
| 3984 | return (RAM_TEST_FAILED); |
| 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 3990 | |
| 3991 | return (0); |
| 3992 | } |
| 3993 | |
| 3994 | static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf, |
| 3995 | __u16 *correlator) |
| 3996 | { |
| 3997 | MAC_SUB_VECTOR *rsv; |
| 3998 | signed short vlen; |
| 3999 | __u16 rcode = POSITIVE_ACK; |
| 4000 | unsigned int svectors = F_NO_SUB_VECTORS_FOUND; |
| 4001 | |
| 4002 | /* This Frame can only come from a CRS */ |
| 4003 | if((rmf->dc_sc & SC_MASK) != SC_CRS) |
| 4004 | return(E_INAPPROPRIATE_SOURCE_CLASS); |
| 4005 | |
| 4006 | /* Remove MVID Length from total length. */ |
| 4007 | vlen = (signed short)rmf->vl - 4; |
| 4008 | |
| 4009 | /* Point to First SVID */ |
| 4010 | rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER)); |
| 4011 | |
| 4012 | /* Search for Appropriate SVID's. */ |
| 4013 | while((vlen > 0) && (rcode == POSITIVE_ACK)) |
| 4014 | { |
| 4015 | switch(rsv->svi) |
| 4016 | { |
| 4017 | case CORRELATOR: |
| 4018 | svectors |= F_CORRELATOR; |
| 4019 | rcode = smctr_set_corr(dev, rsv, correlator); |
| 4020 | break; |
| 4021 | |
| 4022 | case LOCAL_RING_NUMBER: |
| 4023 | svectors |= F_LOCAL_RING_NUMBER; |
| 4024 | rcode = smctr_set_local_ring_num(dev, rsv); |
| 4025 | break; |
| 4026 | |
| 4027 | case ASSIGN_PHYSICAL_DROP: |
| 4028 | svectors |= F_ASSIGN_PHYSICAL_DROP; |
| 4029 | rcode = smctr_set_phy_drop(dev, rsv); |
| 4030 | break; |
| 4031 | |
| 4032 | case ERROR_TIMER_VALUE: |
| 4033 | svectors |= F_ERROR_TIMER_VALUE; |
| 4034 | rcode = smctr_set_error_timer_value(dev, rsv); |
| 4035 | break; |
| 4036 | |
| 4037 | case AUTHORIZED_FUNCTION_CLASS: |
| 4038 | svectors |= F_AUTHORIZED_FUNCTION_CLASS; |
| 4039 | rcode = smctr_set_auth_funct_class(dev, rsv); |
| 4040 | break; |
| 4041 | |
| 4042 | case AUTHORIZED_ACCESS_PRIORITY: |
| 4043 | svectors |= F_AUTHORIZED_ACCESS_PRIORITY; |
| 4044 | rcode = smctr_set_auth_access_pri(dev, rsv); |
| 4045 | break; |
| 4046 | |
| 4047 | default: |
| 4048 | rcode = E_SUB_VECTOR_UNKNOWN; |
| 4049 | break; |
| 4050 | } |
| 4051 | |
| 4052 | /* Let Sender Know if SUM of SV length's is |
| 4053 | * larger then length in MVID length field |
| 4054 | */ |
| 4055 | if((vlen -= rsv->svl) < 0) |
| 4056 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4057 | |
| 4058 | rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl); |
| 4059 | } |
| 4060 | |
| 4061 | if(rcode == POSITIVE_ACK) |
| 4062 | { |
| 4063 | /* Let Sender Know if MVID length field |
| 4064 | * is larger then SUM of SV length's |
| 4065 | */ |
| 4066 | if(vlen != 0) |
| 4067 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4068 | else |
| 4069 | { |
| 4070 | /* Let Sender Know if Expected SVID Missing */ |
| 4071 | if((svectors & R_CHG_PARM) ^ R_CHG_PARM) |
| 4072 | rcode = E_MISSING_SUB_VECTOR; |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | return (rcode); |
| 4077 | } |
| 4078 | |
| 4079 | static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf, |
| 4080 | __u16 *correlator) |
| 4081 | { |
| 4082 | MAC_SUB_VECTOR *rsv; |
| 4083 | signed short vlen; |
| 4084 | __u16 rcode = POSITIVE_ACK; |
| 4085 | unsigned int svectors = F_NO_SUB_VECTORS_FOUND; |
| 4086 | |
| 4087 | /* This Frame can only come from a RPS */ |
| 4088 | if((rmf->dc_sc & SC_MASK) != SC_RPS) |
| 4089 | return (E_INAPPROPRIATE_SOURCE_CLASS); |
| 4090 | |
| 4091 | /* Remove MVID Length from total length. */ |
| 4092 | vlen = (signed short)rmf->vl - 4; |
| 4093 | |
| 4094 | /* Point to First SVID */ |
| 4095 | rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER)); |
| 4096 | |
| 4097 | /* Search for Appropriate SVID's */ |
| 4098 | while((vlen > 0) && (rcode == POSITIVE_ACK)) |
| 4099 | { |
| 4100 | switch(rsv->svi) |
| 4101 | { |
| 4102 | case CORRELATOR: |
| 4103 | svectors |= F_CORRELATOR; |
| 4104 | rcode = smctr_set_corr(dev, rsv, correlator); |
| 4105 | break; |
| 4106 | |
| 4107 | case LOCAL_RING_NUMBER: |
| 4108 | svectors |= F_LOCAL_RING_NUMBER; |
| 4109 | rcode = smctr_set_local_ring_num(dev, rsv); |
| 4110 | break; |
| 4111 | |
| 4112 | case ASSIGN_PHYSICAL_DROP: |
| 4113 | svectors |= F_ASSIGN_PHYSICAL_DROP; |
| 4114 | rcode = smctr_set_phy_drop(dev, rsv); |
| 4115 | break; |
| 4116 | |
| 4117 | case ERROR_TIMER_VALUE: |
| 4118 | svectors |= F_ERROR_TIMER_VALUE; |
| 4119 | rcode = smctr_set_error_timer_value(dev, rsv); |
| 4120 | break; |
| 4121 | |
| 4122 | default: |
| 4123 | rcode = E_SUB_VECTOR_UNKNOWN; |
| 4124 | break; |
| 4125 | } |
| 4126 | |
| 4127 | /* Let Sender Know if SUM of SV length's is |
| 4128 | * larger then length in MVID length field |
| 4129 | */ |
| 4130 | if((vlen -= rsv->svl) < 0) |
| 4131 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4132 | |
| 4133 | rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl); |
| 4134 | } |
| 4135 | |
| 4136 | if(rcode == POSITIVE_ACK) |
| 4137 | { |
| 4138 | /* Let Sender Know if MVID length field |
| 4139 | * is larger then SUM of SV length's |
| 4140 | */ |
| 4141 | if(vlen != 0) |
| 4142 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4143 | else |
| 4144 | { |
| 4145 | /* Let Sender Know if Expected SV Missing */ |
| 4146 | if((svectors & R_INIT) ^ R_INIT) |
| 4147 | rcode = E_MISSING_SUB_VECTOR; |
| 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | return (rcode); |
| 4152 | } |
| 4153 | |
| 4154 | static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf) |
| 4155 | { |
| 4156 | MAC_SUB_VECTOR *rsv; |
| 4157 | signed short vlen; |
| 4158 | __u16 rcode = POSITIVE_ACK; |
| 4159 | unsigned int svectors = F_NO_SUB_VECTORS_FOUND; |
| 4160 | |
| 4161 | /* This Frame can only come from a CRS */ |
| 4162 | if((rmf->dc_sc & SC_MASK) != SC_CRS) |
| 4163 | return (E_INAPPROPRIATE_SOURCE_CLASS); |
| 4164 | |
| 4165 | /* Remove MVID Length from total length */ |
| 4166 | vlen = (signed short)rmf->vl - 4; |
| 4167 | |
| 4168 | /* Point to First SVID */ |
| 4169 | rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER)); |
| 4170 | |
| 4171 | /* Search for Appropriate SVID's */ |
| 4172 | while((vlen > 0) && (rcode == POSITIVE_ACK)) |
| 4173 | { |
| 4174 | switch(rsv->svi) |
| 4175 | { |
| 4176 | case FRAME_FORWARD: |
| 4177 | svectors |= F_FRAME_FORWARD; |
| 4178 | rcode = smctr_set_frame_forward(dev, rsv, |
| 4179 | rmf->dc_sc); |
| 4180 | break; |
| 4181 | |
| 4182 | default: |
| 4183 | rcode = E_SUB_VECTOR_UNKNOWN; |
| 4184 | break; |
| 4185 | } |
| 4186 | |
| 4187 | /* Let Sender Know if SUM of SV length's is |
| 4188 | * larger then length in MVID length field |
| 4189 | */ |
| 4190 | if((vlen -= rsv->svl) < 0) |
| 4191 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4192 | |
| 4193 | rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl); |
| 4194 | } |
| 4195 | |
| 4196 | if(rcode == POSITIVE_ACK) |
| 4197 | { |
| 4198 | /* Let Sender Know if MVID length field |
| 4199 | * is larger then SUM of SV length's |
| 4200 | */ |
| 4201 | if(vlen != 0) |
| 4202 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4203 | else |
| 4204 | { |
| 4205 | /* Let Sender Know if Expected SV Missing */ |
| 4206 | if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD) |
| 4207 | rcode = E_MISSING_SUB_VECTOR; |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | return (rcode); |
| 4212 | } |
| 4213 | |
| 4214 | static int smctr_rcv_rq_addr_state_attch(struct net_device *dev, |
| 4215 | MAC_HEADER *rmf, __u16 *correlator) |
| 4216 | { |
| 4217 | MAC_SUB_VECTOR *rsv; |
| 4218 | signed short vlen; |
| 4219 | __u16 rcode = POSITIVE_ACK; |
| 4220 | unsigned int svectors = F_NO_SUB_VECTORS_FOUND; |
| 4221 | |
| 4222 | /* Remove MVID Length from total length */ |
| 4223 | vlen = (signed short)rmf->vl - 4; |
| 4224 | |
| 4225 | /* Point to First SVID */ |
| 4226 | rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER)); |
| 4227 | |
| 4228 | /* Search for Appropriate SVID's */ |
| 4229 | while((vlen > 0) && (rcode == POSITIVE_ACK)) |
| 4230 | { |
| 4231 | switch(rsv->svi) |
| 4232 | { |
| 4233 | case CORRELATOR: |
| 4234 | svectors |= F_CORRELATOR; |
| 4235 | rcode = smctr_set_corr(dev, rsv, correlator); |
| 4236 | break; |
| 4237 | |
| 4238 | default: |
| 4239 | rcode = E_SUB_VECTOR_UNKNOWN; |
| 4240 | break; |
| 4241 | } |
| 4242 | |
| 4243 | /* Let Sender Know if SUM of SV length's is |
| 4244 | * larger then length in MVID length field |
| 4245 | */ |
| 4246 | if((vlen -= rsv->svl) < 0) |
| 4247 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4248 | |
| 4249 | rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl); |
| 4250 | } |
| 4251 | |
| 4252 | if(rcode == POSITIVE_ACK) |
| 4253 | { |
| 4254 | /* Let Sender Know if MVID length field |
| 4255 | * is larger then SUM of SV length's |
| 4256 | */ |
| 4257 | if(vlen != 0) |
| 4258 | rcode = E_VECTOR_LENGTH_ERROR; |
| 4259 | else |
| 4260 | { |
| 4261 | /* Let Sender Know if Expected SVID Missing */ |
| 4262 | if((svectors & R_RQ_ATTCH_STATE_ADDR) |
| 4263 | ^ R_RQ_ATTCH_STATE_ADDR) |
| 4264 | rcode = E_MISSING_SUB_VECTOR; |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | return (rcode); |
| 4269 | } |
| 4270 | |
| 4271 | static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf, |
| 4272 | __u16 *correlator) |
| 4273 | { |
| 4274 | MAC_SUB_VECTOR *rsv; |
| 4275 | signed short vlen; |
| 4276 | |
| 4277 | *correlator = 0; |
| 4278 | |
| 4279 | /* Remove MVID Length from total length */ |
| 4280 | vlen = (signed short)rmf->vl - 4; |
| 4281 | |
| 4282 | /* Point to First SVID */ |
| 4283 | rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER)); |
| 4284 | |
| 4285 | /* Search for CORRELATOR for RSP to UNKNOWN */ |
| 4286 | while((vlen > 0) && (*correlator == 0)) |
| 4287 | { |
| 4288 | switch(rsv->svi) |
| 4289 | { |
| 4290 | case CORRELATOR: |
| 4291 | smctr_set_corr(dev, rsv, correlator); |
| 4292 | break; |
| 4293 | |
| 4294 | default: |
| 4295 | break; |
| 4296 | } |
| 4297 | |
| 4298 | vlen -= rsv->svl; |
| 4299 | rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl); |
| 4300 | } |
| 4301 | |
| 4302 | return (E_UNRECOGNIZED_VECTOR_ID); |
| 4303 | } |
| 4304 | |
| 4305 | /* |
| 4306 | * Reset the 825 NIC and exit w: |
| 4307 | * 1. The NIC reset cleared (non-reset state), halted and un-initialized. |
| 4308 | * 2. TINT masked. |
| 4309 | * 3. CBUSY masked. |
| 4310 | * 4. TINT clear. |
| 4311 | * 5. CBUSY clear. |
| 4312 | */ |
| 4313 | static int smctr_reset_adapter(struct net_device *dev) |
| 4314 | { |
| 4315 | struct net_local *tp = netdev_priv(dev); |
| 4316 | int ioaddr = dev->base_addr; |
| 4317 | |
| 4318 | /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr); |
| 4319 | mdelay(200); /* ~2 ms */ |
| 4320 | |
| 4321 | smctr_clear_trc_reset(ioaddr); |
| 4322 | mdelay(200); /* ~2 ms */ |
| 4323 | |
| 4324 | /* Remove any latched interrupts that occurred prior to reseting the |
| 4325 | * adapter or possibily caused by line glitches due to the reset. |
| 4326 | */ |
| 4327 | outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR); |
| 4328 | |
| 4329 | return (0); |
| 4330 | } |
| 4331 | |
| 4332 | static int smctr_restart_tx_chain(struct net_device *dev, short queue) |
| 4333 | { |
| 4334 | struct net_local *tp = netdev_priv(dev); |
| 4335 | int err = 0; |
| 4336 | |
| 4337 | if(smctr_debug > 10) |
| 4338 | printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name); |
| 4339 | |
| 4340 | if(tp->num_tx_fcbs_used[queue] != 0 |
| 4341 | && tp->tx_queue_status[queue] == NOT_TRANSMITING) |
| 4342 | { |
| 4343 | tp->tx_queue_status[queue] = TRANSMITING; |
| 4344 | err = smctr_issue_resume_tx_fcb_cmd(dev, queue); |
| 4345 | } |
| 4346 | |
| 4347 | return (err); |
| 4348 | } |
| 4349 | |
| 4350 | static int smctr_ring_status_chg(struct net_device *dev) |
| 4351 | { |
| 4352 | struct net_local *tp = netdev_priv(dev); |
| 4353 | |
| 4354 | if(smctr_debug > 10) |
| 4355 | printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name); |
| 4356 | |
| 4357 | /* Check for ring_status_flag: whenever MONITOR_STATE_BIT |
| 4358 | * Bit is set, check value of monitor_state, only then we |
| 4359 | * enable and start transmit/receive timeout (if and only |
| 4360 | * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE) |
| 4361 | */ |
| 4362 | if(tp->ring_status_flags == MONITOR_STATE_CHANGED) |
| 4363 | { |
| 4364 | if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE) |
| 4365 | || (tp->monitor_state == MS_STANDBY_MONITOR_STATE)) |
| 4366 | { |
| 4367 | tp->monitor_state_ready = 1; |
| 4368 | } |
| 4369 | else |
| 4370 | { |
| 4371 | /* if adapter is NOT in either active monitor |
| 4372 | * or standby monitor state => Disable |
| 4373 | * transmit/receive timeout. |
| 4374 | */ |
| 4375 | tp->monitor_state_ready = 0; |
| 4376 | |
| 4377 | /* Ring speed problem, switching to auto mode. */ |
| 4378 | if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE |
| 4379 | && !tp->cleanup) |
| 4380 | { |
| 4381 | printk(KERN_INFO "%s: Incorrect ring speed switching.\n", |
| 4382 | dev->name); |
| 4383 | smctr_set_ring_speed(dev); |
| 4384 | } |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | if(!(tp->ring_status_flags & RING_STATUS_CHANGED)) |
| 4389 | return (0); |
| 4390 | |
| 4391 | switch(tp->ring_status) |
| 4392 | { |
| 4393 | case RING_RECOVERY: |
| 4394 | printk(KERN_INFO "%s: Ring Recovery\n", dev->name); |
| 4395 | tp->current_ring_status |= RING_RECOVERY; |
| 4396 | break; |
| 4397 | |
| 4398 | case SINGLE_STATION: |
| 4399 | printk(KERN_INFO "%s: Single Statinon\n", dev->name); |
| 4400 | tp->current_ring_status |= SINGLE_STATION; |
| 4401 | break; |
| 4402 | |
| 4403 | case COUNTER_OVERFLOW: |
| 4404 | printk(KERN_INFO "%s: Counter Overflow\n", dev->name); |
| 4405 | tp->current_ring_status |= COUNTER_OVERFLOW; |
| 4406 | break; |
| 4407 | |
| 4408 | case REMOVE_RECEIVED: |
| 4409 | printk(KERN_INFO "%s: Remove Received\n", dev->name); |
| 4410 | tp->current_ring_status |= REMOVE_RECEIVED; |
| 4411 | break; |
| 4412 | |
| 4413 | case AUTO_REMOVAL_ERROR: |
| 4414 | printk(KERN_INFO "%s: Auto Remove Error\n", dev->name); |
| 4415 | tp->current_ring_status |= AUTO_REMOVAL_ERROR; |
| 4416 | break; |
| 4417 | |
| 4418 | case LOBE_WIRE_FAULT: |
| 4419 | printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name); |
| 4420 | tp->current_ring_status |= LOBE_WIRE_FAULT; |
| 4421 | break; |
| 4422 | |
| 4423 | case TRANSMIT_BEACON: |
| 4424 | printk(KERN_INFO "%s: Transmit Beacon\n", dev->name); |
| 4425 | tp->current_ring_status |= TRANSMIT_BEACON; |
| 4426 | break; |
| 4427 | |
| 4428 | case SOFT_ERROR: |
| 4429 | printk(KERN_INFO "%s: Soft Error\n", dev->name); |
| 4430 | tp->current_ring_status |= SOFT_ERROR; |
| 4431 | break; |
| 4432 | |
| 4433 | case HARD_ERROR: |
| 4434 | printk(KERN_INFO "%s: Hard Error\n", dev->name); |
| 4435 | tp->current_ring_status |= HARD_ERROR; |
| 4436 | break; |
| 4437 | |
| 4438 | case SIGNAL_LOSS: |
| 4439 | printk(KERN_INFO "%s: Signal Loss\n", dev->name); |
| 4440 | tp->current_ring_status |= SIGNAL_LOSS; |
| 4441 | break; |
| 4442 | |
| 4443 | default: |
| 4444 | printk(KERN_INFO "%s: Unknown ring status change\n", |
| 4445 | dev->name); |
| 4446 | break; |
| 4447 | } |
| 4448 | |
| 4449 | return (0); |
| 4450 | } |
| 4451 | |
| 4452 | static int smctr_rx_frame(struct net_device *dev) |
| 4453 | { |
| 4454 | struct net_local *tp = netdev_priv(dev); |
| 4455 | __u16 queue, status, rx_size, err = 0; |
| 4456 | __u8 *pbuff; |
| 4457 | |
| 4458 | if(smctr_debug > 10) |
| 4459 | printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name); |
| 4460 | |
| 4461 | queue = tp->receive_queue_number; |
| 4462 | |
| 4463 | while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS) |
| 4464 | { |
| 4465 | err = HARDWARE_FAILED; |
| 4466 | |
| 4467 | if(((status & 0x007f) == 0) |
| 4468 | || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0)) |
| 4469 | { |
| 4470 | /* frame length less the CRC (4 bytes) + FS (1 byte) */ |
| 4471 | rx_size = tp->rx_fcb_curr[queue]->frame_length - 5; |
| 4472 | |
| 4473 | pbuff = smctr_get_rx_pointer(dev, queue); |
| 4474 | |
| 4475 | smctr_set_page(dev, pbuff); |
| 4476 | smctr_disable_16bit(dev); |
| 4477 | |
| 4478 | /* pbuff points to addr within one page */ |
| 4479 | pbuff = (__u8 *)PAGE_POINTER(pbuff); |
| 4480 | |
| 4481 | if(queue == NON_MAC_QUEUE) |
| 4482 | { |
| 4483 | struct sk_buff *skb; |
| 4484 | |
| 4485 | skb = dev_alloc_skb(rx_size); |
| 4486 | if (skb) { |
| 4487 | skb_put(skb, rx_size); |
| 4488 | |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4489 | skb_copy_to_linear_data(skb, pbuff, rx_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | |
| 4491 | /* Update Counters */ |
| 4492 | tp->MacStat.rx_packets++; |
| 4493 | tp->MacStat.rx_bytes += skb->len; |
| 4494 | |
| 4495 | /* Kick the packet on up. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | skb->protocol = tr_type_trans(skb, dev); |
| 4497 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | } else { |
| 4499 | } |
| 4500 | } |
| 4501 | else |
| 4502 | smctr_process_rx_packet((MAC_HEADER *)pbuff, |
| 4503 | rx_size, dev, status); |
| 4504 | } |
| 4505 | |
| 4506 | smctr_enable_16bit(dev); |
| 4507 | smctr_set_page(dev, (__u8 *)tp->ram_access); |
| 4508 | smctr_update_rx_chain(dev, queue); |
| 4509 | |
| 4510 | if(err != SUCCESS) |
| 4511 | break; |
| 4512 | } |
| 4513 | |
| 4514 | return (err); |
| 4515 | } |
| 4516 | |
| 4517 | static int smctr_send_dat(struct net_device *dev) |
| 4518 | { |
| 4519 | struct net_local *tp = netdev_priv(dev); |
| 4520 | unsigned int i, err; |
| 4521 | MAC_HEADER *tmf; |
| 4522 | FCBlock *fcb; |
| 4523 | |
| 4524 | if(smctr_debug > 10) |
| 4525 | printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name); |
| 4526 | |
| 4527 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, |
| 4528 | sizeof(MAC_HEADER))) == (FCBlock *)(-1L)) |
| 4529 | { |
| 4530 | return (OUT_OF_RESOURCES); |
| 4531 | } |
| 4532 | |
| 4533 | /* Initialize DAT Data Fields. */ |
| 4534 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4535 | tmf->ac = MSB(AC_FC_DAT); |
| 4536 | tmf->fc = LSB(AC_FC_DAT); |
| 4537 | |
| 4538 | for(i = 0; i < 6; i++) |
| 4539 | { |
| 4540 | tmf->sa[i] = dev->dev_addr[i]; |
| 4541 | tmf->da[i] = dev->dev_addr[i]; |
| 4542 | |
| 4543 | } |
| 4544 | |
| 4545 | tmf->vc = DAT; |
| 4546 | tmf->dc_sc = DC_RS | SC_RS; |
| 4547 | tmf->vl = 4; |
| 4548 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4549 | |
| 4550 | /* Start Transmit. */ |
| 4551 | if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE))) |
| 4552 | return (err); |
| 4553 | |
| 4554 | /* Wait for Transmit to Complete */ |
| 4555 | for(i = 0; i < 10000; i++) |
| 4556 | { |
| 4557 | if(fcb->frame_status & FCB_COMMAND_DONE) |
| 4558 | break; |
| 4559 | mdelay(1); |
| 4560 | } |
| 4561 | |
| 4562 | /* Check if GOOD frame Tx'ed. */ |
| 4563 | if(!(fcb->frame_status & FCB_COMMAND_DONE) |
| 4564 | || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS)) |
| 4565 | { |
| 4566 | return (INITIALIZE_FAILED); |
| 4567 | } |
| 4568 | |
| 4569 | /* De-allocated Tx FCB and Frame Buffer |
| 4570 | * The FCB must be de-allocated manually if executing with |
| 4571 | * interrupts disabled, other wise the ISR (LM_Service_Events) |
| 4572 | * will de-allocate it when the interrupt occurs. |
| 4573 | */ |
| 4574 | tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING; |
| 4575 | smctr_update_tx_chain(dev, fcb, MAC_QUEUE); |
| 4576 | |
| 4577 | return (0); |
| 4578 | } |
| 4579 | |
| 4580 | static void smctr_timeout(struct net_device *dev) |
| 4581 | { |
| 4582 | /* |
| 4583 | * If we get here, some higher level has decided we are broken. |
| 4584 | * There should really be a "kick me" function call instead. |
| 4585 | * |
| 4586 | * Resetting the token ring adapter takes a long time so just |
| 4587 | * fake transmission time and go on trying. Our own timeout |
| 4588 | * routine is in sktr_timer_chk() |
| 4589 | */ |
| 4590 | dev->trans_start = jiffies; |
| 4591 | netif_wake_queue(dev); |
| 4592 | } |
| 4593 | |
| 4594 | /* |
| 4595 | * Gets skb from system, queues it and checks if it can be sent |
| 4596 | */ |
| 4597 | static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev) |
| 4598 | { |
| 4599 | struct net_local *tp = netdev_priv(dev); |
| 4600 | |
| 4601 | if(smctr_debug > 10) |
| 4602 | printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name); |
| 4603 | |
| 4604 | /* |
| 4605 | * Block a transmit overlap |
| 4606 | */ |
| 4607 | |
| 4608 | netif_stop_queue(dev); |
| 4609 | |
| 4610 | if(tp->QueueSkb == 0) |
| 4611 | return (1); /* Return with tbusy set: queue full */ |
| 4612 | |
| 4613 | tp->QueueSkb--; |
| 4614 | skb_queue_tail(&tp->SendSkbQueue, skb); |
| 4615 | smctr_hardware_send_packet(dev, tp); |
| 4616 | if(tp->QueueSkb > 0) |
| 4617 | netif_wake_queue(dev); |
| 4618 | |
| 4619 | return (0); |
| 4620 | } |
| 4621 | |
| 4622 | static int smctr_send_lobe_media_test(struct net_device *dev) |
| 4623 | { |
| 4624 | struct net_local *tp = netdev_priv(dev); |
| 4625 | MAC_SUB_VECTOR *tsv; |
| 4626 | MAC_HEADER *tmf; |
| 4627 | FCBlock *fcb; |
| 4628 | __u32 i; |
| 4629 | int err; |
| 4630 | |
| 4631 | if(smctr_debug > 15) |
| 4632 | printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name); |
| 4633 | |
| 4634 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr) |
| 4635 | + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L)) |
| 4636 | { |
| 4637 | return (OUT_OF_RESOURCES); |
| 4638 | } |
| 4639 | |
| 4640 | /* Initialize DAT Data Fields. */ |
| 4641 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4642 | tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST); |
| 4643 | tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST); |
| 4644 | |
| 4645 | for(i = 0; i < 6; i++) |
| 4646 | { |
| 4647 | tmf->da[i] = 0; |
| 4648 | tmf->sa[i] = dev->dev_addr[i]; |
| 4649 | } |
| 4650 | |
| 4651 | tmf->vc = LOBE_MEDIA_TEST; |
| 4652 | tmf->dc_sc = DC_RS | SC_RS; |
| 4653 | tmf->vl = 4; |
| 4654 | |
| 4655 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4656 | smctr_make_wrap_data(dev, tsv); |
| 4657 | tmf->vl += tsv->svl; |
| 4658 | |
| 4659 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4660 | smctr_make_wrap_data(dev, tsv); |
| 4661 | tmf->vl += tsv->svl; |
| 4662 | |
| 4663 | /* Start Transmit. */ |
| 4664 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4665 | if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE))) |
| 4666 | return (err); |
| 4667 | |
| 4668 | /* Wait for Transmit to Complete. (10 ms). */ |
| 4669 | for(i=0; i < 10000; i++) |
| 4670 | { |
| 4671 | if(fcb->frame_status & FCB_COMMAND_DONE) |
| 4672 | break; |
| 4673 | mdelay(1); |
| 4674 | } |
| 4675 | |
| 4676 | /* Check if GOOD frame Tx'ed */ |
| 4677 | if(!(fcb->frame_status & FCB_COMMAND_DONE) |
| 4678 | || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS)) |
| 4679 | { |
| 4680 | return (LOBE_MEDIA_TEST_FAILED); |
| 4681 | } |
| 4682 | |
| 4683 | /* De-allocated Tx FCB and Frame Buffer |
| 4684 | * The FCB must be de-allocated manually if executing with |
| 4685 | * interrupts disabled, other wise the ISR (LM_Service_Events) |
| 4686 | * will de-allocate it when the interrupt occurs. |
| 4687 | */ |
| 4688 | tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING; |
| 4689 | smctr_update_tx_chain(dev, fcb, MAC_QUEUE); |
| 4690 | |
| 4691 | return (0); |
| 4692 | } |
| 4693 | |
| 4694 | static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf, |
| 4695 | __u16 correlator) |
| 4696 | { |
| 4697 | MAC_HEADER *tmf; |
| 4698 | MAC_SUB_VECTOR *tsv; |
| 4699 | FCBlock *fcb; |
| 4700 | |
| 4701 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4702 | + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS |
| 4703 | + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS)) |
| 4704 | == (FCBlock *)(-1L)) |
| 4705 | { |
| 4706 | return (0); |
| 4707 | } |
| 4708 | |
| 4709 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4710 | tmf->vc = RPT_ADDR; |
| 4711 | tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4; |
| 4712 | tmf->vl = 4; |
| 4713 | |
| 4714 | smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR); |
| 4715 | |
| 4716 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4717 | smctr_make_corr(dev, tsv, correlator); |
| 4718 | |
| 4719 | tmf->vl += tsv->svl; |
| 4720 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4721 | smctr_make_phy_drop_num(dev, tsv); |
| 4722 | |
| 4723 | tmf->vl += tsv->svl; |
| 4724 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4725 | smctr_make_upstream_neighbor_addr(dev, tsv); |
| 4726 | |
| 4727 | tmf->vl += tsv->svl; |
| 4728 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4729 | smctr_make_addr_mod(dev, tsv); |
| 4730 | |
| 4731 | tmf->vl += tsv->svl; |
| 4732 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4733 | smctr_make_group_addr(dev, tsv); |
| 4734 | |
| 4735 | tmf->vl += tsv->svl; |
| 4736 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4737 | smctr_make_funct_addr(dev, tsv); |
| 4738 | |
| 4739 | tmf->vl += tsv->svl; |
| 4740 | |
| 4741 | /* Subtract out MVID and MVL which is |
| 4742 | * include in both vl and MAC_HEADER |
| 4743 | */ |
| 4744 | /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4745 | fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4746 | */ |
| 4747 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4748 | |
| 4749 | return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE)); |
| 4750 | } |
| 4751 | |
| 4752 | static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf, |
| 4753 | __u16 correlator) |
| 4754 | { |
| 4755 | MAC_HEADER *tmf; |
| 4756 | MAC_SUB_VECTOR *tsv; |
| 4757 | FCBlock *fcb; |
| 4758 | |
| 4759 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4760 | + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS |
| 4761 | + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY)) |
| 4762 | == (FCBlock *)(-1L)) |
| 4763 | { |
| 4764 | return (0); |
| 4765 | } |
| 4766 | |
| 4767 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4768 | tmf->vc = RPT_ATTCH; |
| 4769 | tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4; |
| 4770 | tmf->vl = 4; |
| 4771 | |
| 4772 | smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH); |
| 4773 | |
| 4774 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4775 | smctr_make_corr(dev, tsv, correlator); |
| 4776 | |
| 4777 | tmf->vl += tsv->svl; |
| 4778 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4779 | smctr_make_product_id(dev, tsv); |
| 4780 | |
| 4781 | tmf->vl += tsv->svl; |
| 4782 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4783 | smctr_make_funct_addr(dev, tsv); |
| 4784 | |
| 4785 | tmf->vl += tsv->svl; |
| 4786 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4787 | smctr_make_auth_funct_class(dev, tsv); |
| 4788 | |
| 4789 | tmf->vl += tsv->svl; |
| 4790 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4791 | smctr_make_access_pri(dev, tsv); |
| 4792 | |
| 4793 | tmf->vl += tsv->svl; |
| 4794 | |
| 4795 | /* Subtract out MVID and MVL which is |
| 4796 | * include in both vl and MAC_HEADER |
| 4797 | */ |
| 4798 | /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4799 | fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4800 | */ |
| 4801 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4802 | |
| 4803 | return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE)); |
| 4804 | } |
| 4805 | |
| 4806 | static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf, |
| 4807 | __u16 correlator) |
| 4808 | { |
| 4809 | MAC_HEADER *tmf; |
| 4810 | MAC_SUB_VECTOR *tsv; |
| 4811 | FCBlock *fcb; |
| 4812 | |
| 4813 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4814 | + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER |
| 4815 | + S_RING_STATION_STATUS + S_STATION_IDENTIFER)) |
| 4816 | == (FCBlock *)(-1L)) |
| 4817 | { |
| 4818 | return (0); |
| 4819 | } |
| 4820 | |
| 4821 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4822 | tmf->vc = RPT_STATE; |
| 4823 | tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4; |
| 4824 | tmf->vl = 4; |
| 4825 | |
| 4826 | smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE); |
| 4827 | |
| 4828 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4829 | smctr_make_corr(dev, tsv, correlator); |
| 4830 | |
| 4831 | tmf->vl += tsv->svl; |
| 4832 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4833 | smctr_make_ring_station_version(dev, tsv); |
| 4834 | |
| 4835 | tmf->vl += tsv->svl; |
| 4836 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4837 | smctr_make_ring_station_status(dev, tsv); |
| 4838 | |
| 4839 | tmf->vl += tsv->svl; |
| 4840 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4841 | smctr_make_station_id(dev, tsv); |
| 4842 | |
| 4843 | tmf->vl += tsv->svl; |
| 4844 | |
| 4845 | /* Subtract out MVID and MVL which is |
| 4846 | * include in both vl and MAC_HEADER |
| 4847 | */ |
| 4848 | /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4849 | fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4850 | */ |
| 4851 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4852 | |
| 4853 | return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE)); |
| 4854 | } |
| 4855 | |
| 4856 | static int smctr_send_rpt_tx_forward(struct net_device *dev, |
| 4857 | MAC_HEADER *rmf, __u16 tx_fstatus) |
| 4858 | { |
| 4859 | MAC_HEADER *tmf; |
| 4860 | MAC_SUB_VECTOR *tsv; |
| 4861 | FCBlock *fcb; |
| 4862 | |
| 4863 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4864 | + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L)) |
| 4865 | { |
| 4866 | return (0); |
| 4867 | } |
| 4868 | |
| 4869 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4870 | tmf->vc = RPT_TX_FORWARD; |
| 4871 | tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4; |
| 4872 | tmf->vl = 4; |
| 4873 | |
| 4874 | smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD); |
| 4875 | |
| 4876 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4877 | smctr_make_tx_status_code(dev, tsv, tx_fstatus); |
| 4878 | |
| 4879 | tmf->vl += tsv->svl; |
| 4880 | |
| 4881 | /* Subtract out MVID and MVL which is |
| 4882 | * include in both vl and MAC_HEADER |
| 4883 | */ |
| 4884 | /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4885 | fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4886 | */ |
| 4887 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4888 | |
| 4889 | return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE)); |
| 4890 | } |
| 4891 | |
| 4892 | static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf, |
| 4893 | __u16 rcode, __u16 correlator) |
| 4894 | { |
| 4895 | MAC_HEADER *tmf; |
| 4896 | MAC_SUB_VECTOR *tsv; |
| 4897 | FCBlock *fcb; |
| 4898 | |
| 4899 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4900 | + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L)) |
| 4901 | { |
| 4902 | return (0); |
| 4903 | } |
| 4904 | |
| 4905 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4906 | tmf->vc = RSP; |
| 4907 | tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4; |
| 4908 | tmf->vl = 4; |
| 4909 | |
| 4910 | smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP); |
| 4911 | |
| 4912 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4913 | smctr_make_corr(dev, tsv, correlator); |
| 4914 | |
| 4915 | return (0); |
| 4916 | } |
| 4917 | |
| 4918 | static int smctr_send_rq_init(struct net_device *dev) |
| 4919 | { |
| 4920 | struct net_local *tp = netdev_priv(dev); |
| 4921 | MAC_HEADER *tmf; |
| 4922 | MAC_SUB_VECTOR *tsv; |
| 4923 | FCBlock *fcb; |
| 4924 | unsigned int i, count = 0; |
| 4925 | __u16 fstatus; |
| 4926 | int err; |
| 4927 | |
| 4928 | do { |
| 4929 | if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER) |
| 4930 | + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS |
| 4931 | + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER)) |
| 4932 | == (FCBlock *)(-1L))) |
| 4933 | { |
| 4934 | return (0); |
| 4935 | } |
| 4936 | |
| 4937 | tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr; |
| 4938 | tmf->vc = RQ_INIT; |
| 4939 | tmf->dc_sc = DC_RPS | SC_RS; |
| 4940 | tmf->vl = 4; |
| 4941 | |
| 4942 | smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT); |
| 4943 | |
| 4944 | tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER)); |
| 4945 | smctr_make_product_id(dev, tsv); |
| 4946 | |
| 4947 | tmf->vl += tsv->svl; |
| 4948 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4949 | smctr_make_upstream_neighbor_addr(dev, tsv); |
| 4950 | |
| 4951 | tmf->vl += tsv->svl; |
| 4952 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4953 | smctr_make_ring_station_version(dev, tsv); |
| 4954 | |
| 4955 | tmf->vl += tsv->svl; |
| 4956 | tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl); |
| 4957 | smctr_make_addr_mod(dev, tsv); |
| 4958 | |
| 4959 | tmf->vl += tsv->svl; |
| 4960 | |
| 4961 | /* Subtract out MVID and MVL which is |
| 4962 | * include in both vl and MAC_HEADER |
| 4963 | */ |
| 4964 | /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4965 | fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4; |
| 4966 | */ |
| 4967 | tmf->vl = SWAP_BYTES(tmf->vl); |
| 4968 | |
| 4969 | if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE))) |
| 4970 | return (err); |
| 4971 | |
| 4972 | /* Wait for Transmit to Complete */ |
| 4973 | for(i = 0; i < 10000; i++) |
| 4974 | { |
| 4975 | if(fcb->frame_status & FCB_COMMAND_DONE) |
| 4976 | break; |
| 4977 | mdelay(1); |
| 4978 | } |
| 4979 | |
| 4980 | /* Check if GOOD frame Tx'ed */ |
| 4981 | fstatus = fcb->frame_status; |
| 4982 | |
| 4983 | if(!(fstatus & FCB_COMMAND_DONE)) |
| 4984 | return (HARDWARE_FAILED); |
| 4985 | |
| 4986 | if(!(fstatus & FCB_TX_STATUS_E)) |
| 4987 | count++; |
| 4988 | |
| 4989 | /* De-allocated Tx FCB and Frame Buffer |
| 4990 | * The FCB must be de-allocated manually if executing with |
| 4991 | * interrupts disabled, other wise the ISR (LM_Service_Events) |
| 4992 | * will de-allocate it when the interrupt occurs. |
| 4993 | */ |
| 4994 | tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING; |
| 4995 | smctr_update_tx_chain(dev, fcb, MAC_QUEUE); |
| 4996 | } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS)); |
| 4997 | |
| 4998 | return (smctr_join_complete_state(dev)); |
| 4999 | } |
| 5000 | |
| 5001 | static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf, |
| 5002 | __u16 *tx_fstatus) |
| 5003 | { |
| 5004 | struct net_local *tp = netdev_priv(dev); |
| 5005 | FCBlock *fcb; |
| 5006 | unsigned int i; |
| 5007 | int err; |
| 5008 | |
| 5009 | /* Check if this is the END POINT of the Transmit Forward Chain. */ |
| 5010 | if(rmf->vl <= 18) |
| 5011 | return (0); |
| 5012 | |
| 5013 | /* Allocate Transmit FCB only by requesting 0 bytes |
| 5014 | * of data buffer. |
| 5015 | */ |
| 5016 | if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L)) |
| 5017 | return (0); |
| 5018 | |
| 5019 | /* Set pointer to Transmit Frame Buffer to the data |
| 5020 | * portion of the received TX Forward frame, making |
| 5021 | * sure to skip over the Vector Code (vc) and Vector |
| 5022 | * length (vl). |
| 5023 | */ |
| 5024 | fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf |
| 5025 | + sizeof(MAC_HEADER) + 2); |
| 5026 | fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf |
| 5027 | + sizeof(MAC_HEADER) + 2); |
| 5028 | |
| 5029 | fcb->frame_length = rmf->vl - 4 - 2; |
| 5030 | fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2; |
| 5031 | |
| 5032 | if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE))) |
| 5033 | return (err); |
| 5034 | |
| 5035 | /* Wait for Transmit to Complete */ |
| 5036 | for(i = 0; i < 10000; i++) |
| 5037 | { |
| 5038 | if(fcb->frame_status & FCB_COMMAND_DONE) |
| 5039 | break; |
| 5040 | mdelay(1); |
| 5041 | } |
| 5042 | |
| 5043 | /* Check if GOOD frame Tx'ed */ |
| 5044 | if(!(fcb->frame_status & FCB_COMMAND_DONE)) |
| 5045 | { |
| 5046 | if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE))) |
| 5047 | return (err); |
| 5048 | |
| 5049 | for(i = 0; i < 10000; i++) |
| 5050 | { |
| 5051 | if(fcb->frame_status & FCB_COMMAND_DONE) |
| 5052 | break; |
| 5053 | mdelay(1); |
| 5054 | } |
| 5055 | |
| 5056 | if(!(fcb->frame_status & FCB_COMMAND_DONE)) |
| 5057 | return (HARDWARE_FAILED); |
| 5058 | } |
| 5059 | |
| 5060 | *tx_fstatus = fcb->frame_status; |
| 5061 | |
| 5062 | return (A_FRAME_WAS_FORWARDED); |
| 5063 | } |
| 5064 | |
| 5065 | static int smctr_set_auth_access_pri(struct net_device *dev, |
| 5066 | MAC_SUB_VECTOR *rsv) |
| 5067 | { |
| 5068 | struct net_local *tp = netdev_priv(dev); |
| 5069 | |
| 5070 | if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY) |
| 5071 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5072 | |
| 5073 | tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]); |
| 5074 | |
| 5075 | return (POSITIVE_ACK); |
| 5076 | } |
| 5077 | |
| 5078 | static int smctr_set_auth_funct_class(struct net_device *dev, |
| 5079 | MAC_SUB_VECTOR *rsv) |
| 5080 | { |
| 5081 | struct net_local *tp = netdev_priv(dev); |
| 5082 | |
| 5083 | if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS) |
| 5084 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5085 | |
| 5086 | tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]); |
| 5087 | |
| 5088 | return (POSITIVE_ACK); |
| 5089 | } |
| 5090 | |
| 5091 | static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv, |
| 5092 | __u16 *correlator) |
| 5093 | { |
| 5094 | if(rsv->svl != S_CORRELATOR) |
| 5095 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5096 | |
| 5097 | *correlator = (rsv->svv[0] << 8 | rsv->svv[1]); |
| 5098 | |
| 5099 | return (POSITIVE_ACK); |
| 5100 | } |
| 5101 | |
| 5102 | static int smctr_set_error_timer_value(struct net_device *dev, |
| 5103 | MAC_SUB_VECTOR *rsv) |
| 5104 | { |
| 5105 | __u16 err_tval; |
| 5106 | int err; |
| 5107 | |
| 5108 | if(rsv->svl != S_ERROR_TIMER_VALUE) |
| 5109 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5110 | |
| 5111 | err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10; |
| 5112 | |
| 5113 | smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval); |
| 5114 | |
| 5115 | if((err = smctr_wait_cmd(dev))) |
| 5116 | return (err); |
| 5117 | |
| 5118 | return (POSITIVE_ACK); |
| 5119 | } |
| 5120 | |
| 5121 | static int smctr_set_frame_forward(struct net_device *dev, |
| 5122 | MAC_SUB_VECTOR *rsv, __u8 dc_sc) |
| 5123 | { |
| 5124 | if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD)) |
| 5125 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5126 | |
| 5127 | if((dc_sc & DC_MASK) != DC_CRS) |
| 5128 | { |
| 5129 | if(rsv->svl >= 2 && rsv->svl < 20) |
| 5130 | return (E_TRANSMIT_FORWARD_INVALID); |
| 5131 | |
| 5132 | if((rsv->svv[0] != 0) || (rsv->svv[1] != 0)) |
| 5133 | return (E_TRANSMIT_FORWARD_INVALID); |
| 5134 | } |
| 5135 | |
| 5136 | return (POSITIVE_ACK); |
| 5137 | } |
| 5138 | |
| 5139 | static int smctr_set_local_ring_num(struct net_device *dev, |
| 5140 | MAC_SUB_VECTOR *rsv) |
| 5141 | { |
| 5142 | struct net_local *tp = netdev_priv(dev); |
| 5143 | |
| 5144 | if(rsv->svl != S_LOCAL_RING_NUMBER) |
| 5145 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5146 | |
| 5147 | if(tp->ptr_local_ring_num) |
| 5148 | *(__u16 *)(tp->ptr_local_ring_num) |
| 5149 | = (rsv->svv[0] << 8 | rsv->svv[1]); |
| 5150 | |
| 5151 | return (POSITIVE_ACK); |
| 5152 | } |
| 5153 | |
| 5154 | static unsigned short smctr_set_ctrl_attention(struct net_device *dev) |
| 5155 | { |
| 5156 | struct net_local *tp = netdev_priv(dev); |
| 5157 | int ioaddr = dev->base_addr; |
| 5158 | |
| 5159 | if(tp->bic_type == BIC_585_CHIP) |
| 5160 | outb((tp->trc_mask | HWR_CA), ioaddr + HWR); |
| 5161 | else |
| 5162 | { |
| 5163 | outb((tp->trc_mask | CSR_CA), ioaddr + CSR); |
| 5164 | outb(tp->trc_mask, ioaddr + CSR); |
| 5165 | } |
| 5166 | |
| 5167 | return (0); |
| 5168 | } |
| 5169 | |
| 5170 | static void smctr_set_multicast_list(struct net_device *dev) |
| 5171 | { |
| 5172 | if(smctr_debug > 10) |
| 5173 | printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name); |
| 5174 | |
| 5175 | return; |
| 5176 | } |
| 5177 | |
| 5178 | static int smctr_set_page(struct net_device *dev, __u8 *buf) |
| 5179 | { |
| 5180 | struct net_local *tp = netdev_priv(dev); |
| 5181 | __u8 amask; |
| 5182 | __u32 tptr; |
| 5183 | |
| 5184 | tptr = (__u32)buf - (__u32)tp->ram_access; |
| 5185 | amask = (__u8)((tptr & PR_PAGE_MASK) >> 8); |
| 5186 | outb(amask, dev->base_addr + PR); |
| 5187 | |
| 5188 | return (0); |
| 5189 | } |
| 5190 | |
| 5191 | static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv) |
| 5192 | { |
| 5193 | int err; |
| 5194 | |
| 5195 | if(rsv->svl != S_PHYSICAL_DROP) |
| 5196 | return (E_SUB_VECTOR_LENGTH_ERROR); |
| 5197 | |
| 5198 | smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]); |
| 5199 | if((err = smctr_wait_cmd(dev))) |
| 5200 | return (err); |
| 5201 | |
| 5202 | return (POSITIVE_ACK); |
| 5203 | } |
| 5204 | |
| 5205 | /* Reset the ring speed to the opposite of what it was. This auto-pilot |
| 5206 | * mode requires a complete reset and re-init of the adapter. |
| 5207 | */ |
| 5208 | static int smctr_set_ring_speed(struct net_device *dev) |
| 5209 | { |
| 5210 | struct net_local *tp = netdev_priv(dev); |
| 5211 | int err; |
| 5212 | |
| 5213 | if(tp->media_type == MEDIA_UTP_16) |
| 5214 | tp->media_type = MEDIA_UTP_4; |
| 5215 | else |
| 5216 | tp->media_type = MEDIA_UTP_16; |
| 5217 | |
| 5218 | smctr_enable_16bit(dev); |
| 5219 | |
| 5220 | /* Re-Initialize adapter's internal registers */ |
| 5221 | smctr_reset_adapter(dev); |
| 5222 | |
| 5223 | if((err = smctr_init_card_real(dev))) |
| 5224 | return (err); |
| 5225 | |
| 5226 | smctr_enable_bic_int(dev); |
| 5227 | |
| 5228 | if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK))) |
| 5229 | return (err); |
| 5230 | |
| 5231 | smctr_disable_16bit(dev); |
| 5232 | |
| 5233 | return (0); |
| 5234 | } |
| 5235 | |
| 5236 | static int smctr_set_rx_look_ahead(struct net_device *dev) |
| 5237 | { |
| 5238 | struct net_local *tp = netdev_priv(dev); |
| 5239 | __u16 sword, rword; |
| 5240 | |
| 5241 | if(smctr_debug > 10) |
| 5242 | printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name); |
| 5243 | |
| 5244 | tp->adapter_flags &= ~(FORCED_16BIT_MODE); |
| 5245 | tp->adapter_flags |= RX_VALID_LOOKAHEAD; |
| 5246 | |
| 5247 | if(tp->adapter_bus == BUS_ISA16_TYPE) |
| 5248 | { |
| 5249 | sword = *((__u16 *)(tp->ram_access)); |
| 5250 | *((__u16 *)(tp->ram_access)) = 0x1234; |
| 5251 | |
| 5252 | smctr_disable_16bit(dev); |
| 5253 | rword = *((__u16 *)(tp->ram_access)); |
| 5254 | smctr_enable_16bit(dev); |
| 5255 | |
| 5256 | if(rword != 0x1234) |
| 5257 | tp->adapter_flags |= FORCED_16BIT_MODE; |
| 5258 | |
| 5259 | *((__u16 *)(tp->ram_access)) = sword; |
| 5260 | } |
| 5261 | |
| 5262 | return (0); |
| 5263 | } |
| 5264 | |
| 5265 | static int smctr_set_trc_reset(int ioaddr) |
| 5266 | { |
| 5267 | __u8 r; |
| 5268 | |
| 5269 | r = inb(ioaddr + MSR); |
| 5270 | outb(MSR_RST | r, ioaddr + MSR); |
| 5271 | |
| 5272 | return (0); |
| 5273 | } |
| 5274 | |
| 5275 | /* |
| 5276 | * This function can be called if the adapter is busy or not. |
| 5277 | */ |
| 5278 | static int smctr_setup_single_cmd(struct net_device *dev, |
| 5279 | __u16 command, __u16 subcommand) |
| 5280 | { |
| 5281 | struct net_local *tp = netdev_priv(dev); |
| 5282 | unsigned int err; |
| 5283 | |
| 5284 | if(smctr_debug > 10) |
| 5285 | printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name); |
| 5286 | |
| 5287 | if((err = smctr_wait_while_cbusy(dev))) |
| 5288 | return (err); |
| 5289 | |
| 5290 | if((err = (unsigned int)smctr_wait_cmd(dev))) |
| 5291 | return (err); |
| 5292 | |
| 5293 | tp->acb_head->cmd_done_status = 0; |
| 5294 | tp->acb_head->cmd = command; |
| 5295 | tp->acb_head->subcmd = subcommand; |
| 5296 | |
| 5297 | err = smctr_issue_resume_acb_cmd(dev); |
| 5298 | |
| 5299 | return (err); |
| 5300 | } |
| 5301 | |
| 5302 | /* |
| 5303 | * This function can not be called with the adapter busy. |
| 5304 | */ |
| 5305 | static int smctr_setup_single_cmd_w_data(struct net_device *dev, |
| 5306 | __u16 command, __u16 subcommand) |
| 5307 | { |
| 5308 | struct net_local *tp = netdev_priv(dev); |
| 5309 | |
| 5310 | tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE; |
| 5311 | tp->acb_head->cmd = command; |
| 5312 | tp->acb_head->subcmd = subcommand; |
| 5313 | tp->acb_head->data_offset_lo |
| 5314 | = (__u16)TRC_POINTER(tp->misc_command_data); |
| 5315 | |
| 5316 | return(smctr_issue_resume_acb_cmd(dev)); |
| 5317 | } |
| 5318 | |
| 5319 | static char *smctr_malloc(struct net_device *dev, __u16 size) |
| 5320 | { |
| 5321 | struct net_local *tp = netdev_priv(dev); |
| 5322 | char *m; |
| 5323 | |
| 5324 | m = (char *)(tp->ram_access + tp->sh_mem_used); |
| 5325 | tp->sh_mem_used += (__u32)size; |
| 5326 | |
| 5327 | return (m); |
| 5328 | } |
| 5329 | |
| 5330 | static int smctr_status_chg(struct net_device *dev) |
| 5331 | { |
| 5332 | struct net_local *tp = netdev_priv(dev); |
| 5333 | |
| 5334 | if(smctr_debug > 10) |
| 5335 | printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name); |
| 5336 | |
| 5337 | switch(tp->status) |
| 5338 | { |
| 5339 | case OPEN: |
| 5340 | break; |
| 5341 | |
| 5342 | case CLOSED: |
| 5343 | break; |
| 5344 | |
| 5345 | /* Interrupt driven open() completion. XXX */ |
| 5346 | case INITIALIZED: |
| 5347 | tp->group_address_0 = 0; |
| 5348 | tp->group_address[0] = 0; |
| 5349 | tp->group_address[1] = 0; |
| 5350 | tp->functional_address_0 = 0; |
| 5351 | tp->functional_address[0] = 0; |
| 5352 | tp->functional_address[1] = 0; |
| 5353 | smctr_open_tr(dev); |
| 5354 | break; |
| 5355 | |
| 5356 | default: |
| 5357 | printk(KERN_INFO "%s: status change unknown %x\n", |
| 5358 | dev->name, tp->status); |
| 5359 | break; |
| 5360 | } |
| 5361 | |
| 5362 | return (0); |
| 5363 | } |
| 5364 | |
| 5365 | static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb, |
| 5366 | __u16 queue) |
| 5367 | { |
| 5368 | struct net_local *tp = netdev_priv(dev); |
| 5369 | int err = 0; |
| 5370 | |
| 5371 | if(smctr_debug > 10) |
| 5372 | printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name); |
| 5373 | |
| 5374 | fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS; |
| 5375 | if(tp->num_tx_fcbs[queue] != 1) |
| 5376 | fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS; |
| 5377 | |
| 5378 | if(tp->tx_queue_status[queue] == NOT_TRANSMITING) |
| 5379 | { |
| 5380 | tp->tx_queue_status[queue] = TRANSMITING; |
| 5381 | err = smctr_issue_resume_tx_fcb_cmd(dev, queue); |
| 5382 | } |
| 5383 | |
| 5384 | return (err); |
| 5385 | } |
| 5386 | |
| 5387 | static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue) |
| 5388 | { |
| 5389 | struct net_local *tp = netdev_priv(dev); |
| 5390 | __u16 status, err = 0; |
| 5391 | int cstatus; |
| 5392 | |
| 5393 | if(smctr_debug > 10) |
| 5394 | printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name); |
| 5395 | |
| 5396 | while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS) |
| 5397 | { |
| 5398 | if(status & 0x7e00 ) |
| 5399 | { |
| 5400 | err = HARDWARE_FAILED; |
| 5401 | break; |
| 5402 | } |
| 5403 | |
| 5404 | if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue], |
| 5405 | queue)) != SUCCESS) |
| 5406 | break; |
| 5407 | |
| 5408 | smctr_disable_16bit(dev); |
| 5409 | |
| 5410 | if(tp->mode_bits & UMAC) |
| 5411 | { |
| 5412 | if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2))) |
| 5413 | cstatus = NO_SUCH_DESTINATION; |
| 5414 | else |
| 5415 | { |
| 5416 | if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2))) |
| 5417 | cstatus = DEST_OUT_OF_RESOURCES; |
| 5418 | else |
| 5419 | { |
| 5420 | if(status & FCB_TX_STATUS_E) |
| 5421 | cstatus = MAX_COLLISIONS; |
| 5422 | else |
| 5423 | cstatus = SUCCESS; |
| 5424 | } |
| 5425 | } |
| 5426 | } |
| 5427 | else |
| 5428 | cstatus = SUCCESS; |
| 5429 | |
| 5430 | if(queue == BUG_QUEUE) |
| 5431 | err = SUCCESS; |
| 5432 | |
| 5433 | smctr_enable_16bit(dev); |
| 5434 | if(err != SUCCESS) |
| 5435 | break; |
| 5436 | } |
| 5437 | |
| 5438 | return (err); |
| 5439 | } |
| 5440 | |
| 5441 | static unsigned short smctr_tx_move_frame(struct net_device *dev, |
| 5442 | struct sk_buff *skb, __u8 *pbuff, unsigned int bytes) |
| 5443 | { |
| 5444 | struct net_local *tp = netdev_priv(dev); |
| 5445 | unsigned int ram_usable; |
| 5446 | __u32 flen, len, offset = 0; |
| 5447 | __u8 *frag, *page; |
| 5448 | |
| 5449 | if(smctr_debug > 10) |
| 5450 | printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name); |
| 5451 | |
| 5452 | ram_usable = ((unsigned int)tp->ram_usable) << 10; |
| 5453 | frag = skb->data; |
| 5454 | flen = skb->len; |
| 5455 | |
| 5456 | while(flen > 0 && bytes > 0) |
| 5457 | { |
| 5458 | smctr_set_page(dev, pbuff); |
| 5459 | |
| 5460 | offset = SMC_PAGE_OFFSET(pbuff); |
| 5461 | |
| 5462 | if(offset + flen > ram_usable) |
| 5463 | len = ram_usable - offset; |
| 5464 | else |
| 5465 | len = flen; |
| 5466 | |
| 5467 | if(len > bytes) |
| 5468 | len = bytes; |
| 5469 | |
| 5470 | page = (char *) (offset + tp->ram_access); |
| 5471 | memcpy(page, frag, len); |
| 5472 | |
| 5473 | flen -=len; |
| 5474 | bytes -= len; |
| 5475 | frag += len; |
| 5476 | pbuff += len; |
| 5477 | } |
| 5478 | |
| 5479 | return (0); |
| 5480 | } |
| 5481 | |
| 5482 | /* Update the error statistic counters for this adapter. */ |
| 5483 | static int smctr_update_err_stats(struct net_device *dev) |
| 5484 | { |
| 5485 | struct net_local *tp = netdev_priv(dev); |
| 5486 | struct tr_statistics *tstat = &tp->MacStat; |
| 5487 | |
| 5488 | if(tstat->internal_errors) |
| 5489 | tstat->internal_errors |
| 5490 | += *(tp->misc_command_data + 0) & 0x00ff; |
| 5491 | |
| 5492 | if(tstat->line_errors) |
| 5493 | tstat->line_errors += *(tp->misc_command_data + 0) >> 8; |
| 5494 | |
| 5495 | if(tstat->A_C_errors) |
| 5496 | tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff; |
| 5497 | |
| 5498 | if(tstat->burst_errors) |
| 5499 | tstat->burst_errors += *(tp->misc_command_data + 1) >> 8; |
| 5500 | |
| 5501 | if(tstat->abort_delimiters) |
| 5502 | tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8; |
| 5503 | |
| 5504 | if(tstat->recv_congest_count) |
| 5505 | tstat->recv_congest_count |
| 5506 | += *(tp->misc_command_data + 3) & 0x00ff; |
| 5507 | |
| 5508 | if(tstat->lost_frames) |
| 5509 | tstat->lost_frames |
| 5510 | += *(tp->misc_command_data + 3) >> 8; |
| 5511 | |
| 5512 | if(tstat->frequency_errors) |
| 5513 | tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff; |
| 5514 | |
| 5515 | if(tstat->frame_copied_errors) |
| 5516 | tstat->frame_copied_errors |
| 5517 | += *(tp->misc_command_data + 4) >> 8; |
| 5518 | |
| 5519 | if(tstat->token_errors) |
| 5520 | tstat->token_errors += *(tp->misc_command_data + 5) >> 8; |
| 5521 | |
| 5522 | return (0); |
| 5523 | } |
| 5524 | |
| 5525 | static int smctr_update_rx_chain(struct net_device *dev, __u16 queue) |
| 5526 | { |
| 5527 | struct net_local *tp = netdev_priv(dev); |
| 5528 | FCBlock *fcb; |
| 5529 | BDBlock *bdb; |
| 5530 | __u16 size, len; |
| 5531 | |
| 5532 | fcb = tp->rx_fcb_curr[queue]; |
| 5533 | len = fcb->frame_length; |
| 5534 | |
| 5535 | fcb->frame_status = 0; |
| 5536 | fcb->info = FCB_CHAIN_END; |
| 5537 | fcb->back_ptr->info = FCB_WARNING; |
| 5538 | |
| 5539 | tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr; |
| 5540 | |
| 5541 | /* update RX BDBs */ |
| 5542 | size = (len >> RX_BDB_SIZE_SHIFT); |
| 5543 | if(len & RX_DATA_BUFFER_SIZE_MASK) |
| 5544 | size += sizeof(BDBlock); |
| 5545 | size &= (~RX_BDB_SIZE_MASK); |
| 5546 | |
| 5547 | /* check if wrap around */ |
| 5548 | bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size)); |
| 5549 | if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue]) |
| 5550 | { |
| 5551 | bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue]) |
| 5552 | + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue])); |
| 5553 | } |
| 5554 | |
| 5555 | bdb->back_ptr->info = BDB_CHAIN_END; |
| 5556 | tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END; |
| 5557 | tp->rx_bdb_curr[queue] = bdb; |
| 5558 | |
| 5559 | return (0); |
| 5560 | } |
| 5561 | |
| 5562 | static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb, |
| 5563 | __u16 queue) |
| 5564 | { |
| 5565 | struct net_local *tp = netdev_priv(dev); |
| 5566 | |
| 5567 | if(smctr_debug > 20) |
| 5568 | printk(KERN_DEBUG "smctr_update_tx_chain\n"); |
| 5569 | |
| 5570 | if(tp->num_tx_fcbs_used[queue] <= 0) |
| 5571 | return (HARDWARE_FAILED); |
| 5572 | else |
| 5573 | { |
| 5574 | if(tp->tx_buff_used[queue] < fcb->memory_alloc) |
| 5575 | { |
| 5576 | tp->tx_buff_used[queue] = 0; |
| 5577 | return (HARDWARE_FAILED); |
| 5578 | } |
| 5579 | |
| 5580 | tp->tx_buff_used[queue] -= fcb->memory_alloc; |
| 5581 | |
| 5582 | /* if all transmit buffer are cleared |
| 5583 | * need to set the tx_buff_curr[] to tx_buff_head[] |
| 5584 | * otherwise, tx buffer will be segregate and cannot |
| 5585 | * accommodate and buffer greater than (curr - head) and |
| 5586 | * (end - curr) since we do not allow wrap around allocation. |
| 5587 | */ |
| 5588 | if(tp->tx_buff_used[queue] == 0) |
| 5589 | tp->tx_buff_curr[queue] = tp->tx_buff_head[queue]; |
| 5590 | |
| 5591 | tp->num_tx_fcbs_used[queue]--; |
| 5592 | fcb->frame_status = 0; |
| 5593 | tp->tx_fcb_end[queue] = fcb->next_ptr; |
| 5594 | netif_wake_queue(dev); |
| 5595 | return (0); |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | static int smctr_wait_cmd(struct net_device *dev) |
| 5600 | { |
| 5601 | struct net_local *tp = netdev_priv(dev); |
| 5602 | unsigned int loop_count = 0x20000; |
| 5603 | |
| 5604 | if(smctr_debug > 10) |
| 5605 | printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name); |
| 5606 | |
| 5607 | while(loop_count) |
| 5608 | { |
| 5609 | if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE) |
| 5610 | break; |
| 5611 | udelay(1); |
| 5612 | loop_count--; |
| 5613 | } |
| 5614 | |
| 5615 | if(loop_count == 0) |
| 5616 | return(HARDWARE_FAILED); |
| 5617 | |
| 5618 | if(tp->acb_head->cmd_done_status & 0xff) |
| 5619 | return(HARDWARE_FAILED); |
| 5620 | |
| 5621 | return (0); |
| 5622 | } |
| 5623 | |
| 5624 | static int smctr_wait_while_cbusy(struct net_device *dev) |
| 5625 | { |
| 5626 | struct net_local *tp = netdev_priv(dev); |
| 5627 | unsigned int timeout = 0x20000; |
| 5628 | int ioaddr = dev->base_addr; |
| 5629 | __u8 r; |
| 5630 | |
| 5631 | if(tp->bic_type == BIC_585_CHIP) |
| 5632 | { |
| 5633 | while(timeout) |
| 5634 | { |
| 5635 | r = inb(ioaddr + HWR); |
| 5636 | if((r & HWR_CBUSY) == 0) |
| 5637 | break; |
| 5638 | timeout--; |
| 5639 | } |
| 5640 | } |
| 5641 | else |
| 5642 | { |
| 5643 | while(timeout) |
| 5644 | { |
| 5645 | r = inb(ioaddr + CSR); |
| 5646 | if((r & CSR_CBUSY) == 0) |
| 5647 | break; |
| 5648 | timeout--; |
| 5649 | } |
| 5650 | } |
| 5651 | |
| 5652 | if(timeout) |
| 5653 | return (0); |
| 5654 | else |
| 5655 | return (HARDWARE_FAILED); |
| 5656 | } |
| 5657 | |
| 5658 | #ifdef MODULE |
| 5659 | |
| 5660 | static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS]; |
| 5661 | static int io[SMCTR_MAX_ADAPTERS]; |
| 5662 | static int irq[SMCTR_MAX_ADAPTERS]; |
| 5663 | |
| 5664 | MODULE_LICENSE("GPL"); |
David Woodhouse | 0f805b8 | 2008-05-29 16:39:16 +0300 | [diff] [blame] | 5665 | MODULE_FIRMWARE("tr_smctr.bin"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5666 | |
| 5667 | module_param_array(io, int, NULL, 0); |
| 5668 | module_param_array(irq, int, NULL, 0); |
| 5669 | module_param(ringspeed, int, 0); |
| 5670 | |
Andrew Morton | daca7cd | 2006-08-14 23:00:06 -0700 | [diff] [blame] | 5671 | static struct net_device * __init setup_card(int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | { |
| 5673 | struct net_device *dev = alloc_trdev(sizeof(struct net_local)); |
| 5674 | int err; |
| 5675 | |
| 5676 | if (!dev) |
| 5677 | return ERR_PTR(-ENOMEM); |
| 5678 | |
| 5679 | dev->irq = irq[n]; |
| 5680 | err = smctr_probe1(dev, io[n]); |
| 5681 | if (err) |
| 5682 | goto out; |
| 5683 | |
| 5684 | err = register_netdev(dev); |
| 5685 | if (err) |
| 5686 | goto out1; |
| 5687 | return dev; |
| 5688 | out1: |
| 5689 | #ifdef CONFIG_MCA_LEGACY |
| 5690 | { struct net_local *tp = netdev_priv(dev); |
| 5691 | if (tp->slot_num) |
| 5692 | mca_mark_as_unused(tp->slot_num); |
| 5693 | } |
| 5694 | #endif |
| 5695 | release_region(dev->base_addr, SMCTR_IO_EXTENT); |
| 5696 | free_irq(dev->irq, dev); |
| 5697 | out: |
| 5698 | free_netdev(dev); |
| 5699 | return ERR_PTR(err); |
| 5700 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | |
Andrew Morton | daca7cd | 2006-08-14 23:00:06 -0700 | [diff] [blame] | 5702 | int __init init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | { |
| 5704 | int i, found = 0; |
| 5705 | struct net_device *dev; |
| 5706 | |
| 5707 | for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) { |
| 5708 | dev = io[0]? setup_card(i) : smctr_probe(-1); |
| 5709 | if (!IS_ERR(dev)) { |
| 5710 | ++found; |
| 5711 | dev_smctr[i] = dev; |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | return found ? 0 : -ENODEV; |
| 5716 | } |
| 5717 | |
Al Viro | afc8eb4 | 2006-06-14 18:50:53 -0400 | [diff] [blame] | 5718 | void __exit cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | { |
| 5720 | int i; |
| 5721 | |
| 5722 | for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) { |
| 5723 | struct net_device *dev = dev_smctr[i]; |
| 5724 | |
| 5725 | if (dev) { |
| 5726 | |
| 5727 | unregister_netdev(dev); |
| 5728 | #ifdef CONFIG_MCA_LEGACY |
| 5729 | { struct net_local *tp = netdev_priv(dev); |
| 5730 | if (tp->slot_num) |
| 5731 | mca_mark_as_unused(tp->slot_num); |
| 5732 | } |
| 5733 | #endif |
| 5734 | release_region(dev->base_addr, SMCTR_IO_EXTENT); |
| 5735 | if (dev->irq) |
| 5736 | free_irq(dev->irq, dev); |
| 5737 | |
| 5738 | free_netdev(dev); |
| 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | #endif /* MODULE */ |