10 #include <linux/errno.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
19 #include <linux/slab.h>
21 #define IOC3_PCI_SIZE 0x100000
24 static int ioc3_counter;
33 #define GPCR_MLAN_EN 0x00200000
35 static inline unsigned mcr_pack(
unsigned pulse,
unsigned sample)
37 return (pulse << 10) | (sample << 2);
57 writel(mcr_pack(500, 65), &idd->
vma->mcr);
58 presence = nic_wait(idd);
73 result = nic_wait(idd);
96 for (i = 0; i < 8; i++)
97 result = (result >> 1) | (nic_read_bit(idd) << 7);
106 for (i = 8;
i; i--) {
110 nic_write_bit(idd, bit);
122 nic_write_byte(idd, 0xF0);
125 for (index = 0, disc = 0; index < 64; index++) {
126 a = nic_read_bit(idd);
127 b = nic_read_bit(idd);
136 if (index == *last) {
138 }
else if (index > *last) {
141 }
else if ((addr & (1
UL << index)) == 0)
143 nic_write_bit(idd, (addr>>index)&1);
150 nic_write_bit(idd, a);
163 nic_write_byte(idd, 0xF0);
164 for (index = 0; index < 64; index++) {
167 nic_write_bit(idd, (addr>>index)&1);
171 static void crc16_byte(
unsigned int *
crc,
unsigned char db)
177 if((db^(*crc>>16)) & 1)
184 static unsigned int crc16_area(
unsigned char *
dbs,
int size,
unsigned int crc)
187 crc16_byte(&crc, *(dbs++));
191 static void crc8_byte(
unsigned int *crc,
unsigned char db)
205 static unsigned int crc8_addr(
unsigned long addr)
208 unsigned int crc = 0x00;
211 crc8_byte(&crc, addr>>(i<<3));
217 unsigned char *redir,
unsigned char *
data)
221 while(redir[page] != 0xFF) {
222 page = redir[
page]^0xFF;
232 nic_write_byte(idd, 0xF0);
233 nic_write_byte(idd, (page << 5) & 0xE0);
234 nic_write_byte(idd, (page >> 3) & 0x1F);
236 data[i] = nic_read_byte(idd);
237 if(crc16_area(data, 0x20, 0x0000) == 0x800d)
248 unsigned char *redir)
250 int i,
j,loops = 3,crc_ok;
256 nic_write_byte(idd, 0xAA);
257 nic_write_byte(idd, 0x00);
258 nic_write_byte(idd, 0x01);
261 redir[i+j] = nic_read_byte(idd);
262 crc = crc16_area(redir+i, 8, (i==0)?0x8707:0x0000);
263 crc16_byte(&crc, nic_read_byte(idd));
264 crc16_byte(&crc, nic_read_byte(idd));
279 unsigned char redir[64];
280 unsigned char data[64],
part[32];
284 read_redir_map(idd, addr, redir);
286 read_redir_page(idd, addr, 0, redir, data);
287 read_redir_page(idd, addr, 1, redir, data+32);
291 if(data[i+11] !=
' ')
292 part[j++] = data[i+11];
294 if(data[i+32] !=
' ')
295 part[j++] = data[i+32];
298 if(!
strncmp(part,
"060-0035-", 9))
300 if(!
strncmp(part,
"060-0038-", 9))
314 unsigned char data[13];
318 nic_write_byte(idd, 0xF0);
319 nic_write_byte(idd, 0x00);
320 nic_write_byte(idd, 0x00);
323 data[i] = nic_read_byte(idd);
324 if(crc16_area(data, 13, 0x0000) == 0x800d) {
338 int save = 0, loops = 3;
346 addr = first = nic_find(idd, &save, 0);
353 switch(addr & 0xFF) {
364 addr = nic_find(idd, &save, addr);
388 spin_unlock_irqrestore(&idd->
ir_lock, flags);
398 spin_unlock_irqrestore(&idd->
ir_lock, flag);
407 unsigned int pending;
413 if(ioc3_ethernet && idd->
active[ioc3_ethernet->
id] &&
414 ioc3_ethernet->
intr) {
415 handled = handled && !ioc3_ethernet->
intr(ioc3_ethernet,
419 pending = get_pending_intrs(idd);
422 if(idd->
active[
id] && ioc3_submodules[
id]
423 && (pending & ioc3_submodules[
id]->
irq_mask)
424 && ioc3_submodules[
id]->
intr) {
425 write_ireg(idd, ioc3_submodules[
id]->irq_mask,
427 if(!ioc3_submodules[
id]->
intr(ioc3_submodules[
id],
428 idd, pending & ioc3_submodules[
id]->irq_mask))
430 if (ioc3_submodules[
id]->reset_mask)
431 write_ireg(idd, ioc3_submodules[
id]->irq_mask,
438 "IOC3: Pending IRQs 0x%08x discarded and disabled\n",pending);
445 static irqreturn_t ioc3_intr_eth(
int irq,
void *arg)
454 if(ioc3_ethernet && idd->
active[ioc3_ethernet->
id]
455 && ioc3_ethernet->
intr)
456 handled = handled && !ioc3_ethernet->
intr(ioc3_ethernet, idd, 0);
484 spin_unlock_irqrestore(&idd->
gpio_lock, flags);
488 static int find_slot(
void **tab,
int max)
505 alloc_id = find_slot((
void **)ioc3_submodules, IOC3_MAX_SUBMODULES);
507 ioc3_submodules[alloc_id] =
is;
509 if(ioc3_ethernet==
NULL)
513 "IOC3 Ethernet module already registered!\n");
532 idd->
active[alloc_id] = 1;
547 if(ioc3_submodules[is->
id]==is)
548 ioc3_submodules[is->
id]=
NULL;
551 "IOC3 submodule %s has wrong ID.\n",is->
name);
552 if(ioc3_ethernet==is)
553 ioc3_ethernet =
NULL;
563 "%s: IOC3 submodule %s remove failed "
566 pci_name(idd->
pdev));
579 ioc3_class_names[]={
"unknown",
"IP27 BaseIO",
"IP30 system",
"MENET 1/2/3",
580 "MENET 4",
"CADduo",
"Altix Serial"};
595 #ifdef CONFIG_SGI_IP27
615 "%s: Failed to enable IOC3 device for pci_dev %s.\n",
616 __func__, pci_name(pdev));
624 ret = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
627 "for consistent allocations\n",
637 "%s: Failed to allocate IOC3 data for pci_dev %s.\n",
638 __func__, pci_name(pdev));
652 "%s: Unable to find IOC3 resource "
654 __func__, pci_name(pdev));
660 "%s: Unable to request IOC3 region "
662 __func__, pci_name(pdev));
669 "%s: Unable to remap IOC3 region "
671 __func__, pci_name(pdev));
673 goto out_misc_region;
677 pci_set_drvdata(pdev, idd);
680 idd->
id = ioc3_counter++;
689 idd->
class = ioc3_class(idd);
709 "ioc3-eth", (
void *)idd)) {
713 "%s : request_irq fails for IRQ 0x%x\n ",
714 __func__, pdev->
irq);
717 "ioc3-io", (
void *)idd)) {
721 "%s : request_irq fails for IRQ 0x%x\n ",
722 __func__, pdev->
irq+2);
726 "ioc3", (
void *)idd)) {
730 "%s : request_irq fails for IRQ 0x%x\n ",
731 __func__, pdev->
irq);
737 if(ioc3_submodules[
id] && ioc3_submodules[
id]->probe) {
740 (ioc3_submodules[
id], idd);
743 printk(
KERN_INFO "IOC3 Master Driver loaded for %s\n", pci_name(pdev));
763 idd = pci_get_drvdata(pdev);
768 if(ioc3_submodules[
id] && ioc3_submodules[
id]->
remove)
769 if(ioc3_submodules[
id]->
remove(ioc3_submodules[
id],
772 "%s: IOC3 submodule 0x%s remove failed "
808 .id_table = ioc3_id_table,
820 static int __init ioc3_init(
void)
823 return pci_register_driver(&ioc3_driver);
828 static void __exit ioc3_exit(
void)