diff options
Diffstat (limited to 'drivers/sn')
-rw-r--r-- | drivers/sn/Kconfig | 14 | ||||
-rw-r--r-- | drivers/sn/Makefile | 1 | ||||
-rw-r--r-- | drivers/sn/ioc3.c | 851 |
3 files changed, 866 insertions, 0 deletions
diff --git a/drivers/sn/Kconfig b/drivers/sn/Kconfig index 13b8d249da5c..d95265b187a3 100644 --- a/drivers/sn/Kconfig +++ b/drivers/sn/Kconfig | |||
@@ -17,4 +17,18 @@ config SGI_IOC4 | |||
17 | If you have an SGI Altix with an IOC4-based | 17 | If you have an SGI Altix with an IOC4-based |
18 | I/O controller say Y. Otherwise say N. | 18 | I/O controller say Y. Otherwise say N. |
19 | 19 | ||
20 | config SGI_IOC3 | ||
21 | tristate "SGI IOC3 Base IO support" | ||
22 | depends on (IA64_GENERIC || IA64_SGI_SN2) | ||
23 | default m | ||
24 | ---help--- | ||
25 | This option enables basic support for the SGI IOC3-based Base IO | ||
26 | controller card. This option does not enable any specific | ||
27 | functions on such a card, but provides necessary infrastructure | ||
28 | for other drivers to utilize. | ||
29 | |||
30 | If you have an SGI Altix with an IOC3-based | ||
31 | I/O controller or a PCI IOC3 serial card say Y. | ||
32 | Otherwise say N. | ||
33 | |||
20 | endmenu | 34 | endmenu |
diff --git a/drivers/sn/Makefile b/drivers/sn/Makefile index c2a284185372..2cda011597c0 100644 --- a/drivers/sn/Makefile +++ b/drivers/sn/Makefile | |||
@@ -4,3 +4,4 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | obj-$(CONFIG_SGI_IOC4) += ioc4.o | 6 | obj-$(CONFIG_SGI_IOC4) += ioc4.o |
7 | obj-$(CONFIG_SGI_IOC3) += ioc3.o | ||
diff --git a/drivers/sn/ioc3.c b/drivers/sn/ioc3.c new file mode 100644 index 000000000000..aaa009f4a7bf --- /dev/null +++ b/drivers/sn/ioc3.c | |||
@@ -0,0 +1,851 @@ | |||
1 | /* | ||
2 | * SGI IOC3 master driver and IRQ demuxer | ||
3 | * | ||
4 | * Copyright (c) 2005 Stanislaw Skowronek <skylark@linux-mips.org> | ||
5 | * Heavily based on similar work by: | ||
6 | * Brent Casavant <bcasavan@sgi.com> - IOC4 master driver | ||
7 | * Pat Gefre <pfg@sgi.com> - IOC3 serial port IRQ demuxer | ||
8 | */ | ||
9 | |||
10 | #include <linux/config.h> | ||
11 | #include <linux/errno.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/pci.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/ioc3.h> | ||
18 | #include <linux/rwsem.h> | ||
19 | |||
20 | #define IOC3_PCI_SIZE 0x100000 | ||
21 | |||
22 | static LIST_HEAD(ioc3_devices); | ||
23 | static int ioc3_counter; | ||
24 | static DECLARE_RWSEM(ioc3_devices_rwsem); | ||
25 | |||
26 | static struct ioc3_submodule *ioc3_submodules[IOC3_MAX_SUBMODULES]; | ||
27 | static struct ioc3_submodule *ioc3_ethernet; | ||
28 | static rwlock_t ioc3_submodules_lock = RW_LOCK_UNLOCKED; | ||
29 | |||
30 | /* NIC probing code */ | ||
31 | |||
32 | #define GPCR_MLAN_EN 0x00200000 /* enable MCR to pin 8 */ | ||
33 | |||
34 | static inline unsigned mcr_pack(unsigned pulse, unsigned sample) | ||
35 | { | ||
36 | return (pulse << 10) | (sample << 2); | ||
37 | } | ||
38 | |||
39 | static int nic_wait(struct ioc3_driver_data *idd) | ||
40 | { | ||
41 | volatile unsigned mcr; | ||
42 | |||
43 | do { | ||
44 | mcr = (volatile unsigned)idd->vma->mcr; | ||
45 | } while (!(mcr & 2)); | ||
46 | |||
47 | return mcr & 1; | ||
48 | } | ||
49 | |||
50 | static int nic_reset(struct ioc3_driver_data *idd) | ||
51 | { | ||
52 | int presence; | ||
53 | unsigned long flags; | ||
54 | |||
55 | local_irq_save(flags); | ||
56 | idd->vma->mcr = mcr_pack(500, 65); | ||
57 | presence = nic_wait(idd); | ||
58 | local_irq_restore(flags); | ||
59 | |||
60 | udelay(500); | ||
61 | |||
62 | return presence; | ||
63 | } | ||
64 | |||
65 | static inline int nic_read_bit(struct ioc3_driver_data *idd) | ||
66 | { | ||
67 | int result; | ||
68 | unsigned long flags; | ||
69 | |||
70 | local_irq_save(flags); | ||
71 | idd->vma->mcr = mcr_pack(6, 13); | ||
72 | result = nic_wait(idd); | ||
73 | local_irq_restore(flags); | ||
74 | |||
75 | udelay(500); | ||
76 | |||
77 | return result; | ||
78 | } | ||
79 | |||
80 | static inline void nic_write_bit(struct ioc3_driver_data *idd, int bit) | ||
81 | { | ||
82 | if (bit) | ||
83 | idd->vma->mcr = mcr_pack(6, 110); | ||
84 | else | ||
85 | idd->vma->mcr = mcr_pack(80, 30); | ||
86 | |||
87 | nic_wait(idd); | ||
88 | } | ||
89 | |||
90 | static unsigned nic_read_byte(struct ioc3_driver_data *idd) | ||
91 | { | ||
92 | unsigned result = 0; | ||
93 | int i; | ||
94 | |||
95 | for (i = 0; i < 8; i++) | ||
96 | result = (result >> 1) | (nic_read_bit(idd) << 7); | ||
97 | |||
98 | return result; | ||
99 | } | ||
100 | |||
101 | static void nic_write_byte(struct ioc3_driver_data *idd, int byte) | ||
102 | { | ||
103 | int i, bit; | ||
104 | |||
105 | for (i = 8; i; i--) { | ||
106 | bit = byte & 1; | ||
107 | byte >>= 1; | ||
108 | |||
109 | nic_write_bit(idd, bit); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | static unsigned long | ||
114 | nic_find(struct ioc3_driver_data *idd, int *last, unsigned long addr) | ||
115 | { | ||
116 | int a, b, index, disc; | ||
117 | |||
118 | nic_reset(idd); | ||
119 | |||
120 | /* Search ROM. */ | ||
121 | nic_write_byte(idd, 0xF0); | ||
122 | |||
123 | /* Algorithm from ``Book of iButton Standards''. */ | ||
124 | for (index = 0, disc = 0; index < 64; index++) { | ||
125 | a = nic_read_bit(idd); | ||
126 | b = nic_read_bit(idd); | ||
127 | |||
128 | if (a && b) { | ||
129 | printk(KERN_WARNING "IOC3 NIC search failed.\n"); | ||
130 | *last = 0; | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | if (!a && !b) { | ||
135 | if (index == *last) { | ||
136 | addr |= 1UL << index; | ||
137 | } else if (index > *last) { | ||
138 | addr &= ~(1UL << index); | ||
139 | disc = index; | ||
140 | } else if ((addr & (1UL << index)) == 0) | ||
141 | disc = index; | ||
142 | nic_write_bit(idd, (addr>>index)&1); | ||
143 | continue; | ||
144 | } else { | ||
145 | if (a) | ||
146 | addr |= 1UL << index; | ||
147 | else | ||
148 | addr &= ~(1UL << index); | ||
149 | nic_write_bit(idd, a); | ||
150 | continue; | ||
151 | } | ||
152 | } | ||
153 | *last = disc; | ||
154 | return addr; | ||
155 | } | ||
156 | |||
157 | static void nic_addr(struct ioc3_driver_data *idd, unsigned long addr) | ||
158 | { | ||
159 | int index; | ||
160 | |||
161 | nic_reset(idd); | ||
162 | nic_write_byte(idd, 0xF0); | ||
163 | for (index = 0; index < 64; index++) { | ||
164 | nic_read_bit(idd); | ||
165 | nic_read_bit(idd); | ||
166 | nic_write_bit(idd, (addr>>index)&1); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | static void crc16_byte(unsigned int *crc, unsigned char db) | ||
171 | { | ||
172 | int i; | ||
173 | |||
174 | for(i=0;i<8;i++) { | ||
175 | *crc <<= 1; | ||
176 | if((db^(*crc>>16)) & 1) | ||
177 | *crc ^= 0x8005; | ||
178 | db >>= 1; | ||
179 | } | ||
180 | *crc &= 0xFFFF; | ||
181 | } | ||
182 | |||
183 | static unsigned int crc16_area(unsigned char *dbs, int size, unsigned int crc) | ||
184 | { | ||
185 | while(size--) | ||
186 | crc16_byte(&crc, *(dbs++)); | ||
187 | return crc; | ||
188 | } | ||
189 | |||
190 | static void crc8_byte(unsigned int *crc, unsigned char db) | ||
191 | { | ||
192 | int i,f; | ||
193 | |||
194 | for(i=0;i<8;i++) { | ||
195 | f = (*crc ^ db) & 1; | ||
196 | *crc >>= 1; | ||
197 | db >>= 1; | ||
198 | if(f) | ||
199 | *crc ^= 0x8c; | ||
200 | } | ||
201 | *crc &= 0xff; | ||
202 | } | ||
203 | |||
204 | static unsigned int crc8_addr(unsigned long addr) | ||
205 | { | ||
206 | int i; | ||
207 | unsigned int crc = 0x00; | ||
208 | |||
209 | for(i=0;i<8;i++) | ||
210 | crc8_byte(&crc, addr>>(i<<3)); | ||
211 | return crc; | ||
212 | } | ||
213 | |||
214 | static void | ||
215 | read_redir_page(struct ioc3_driver_data *idd, unsigned long addr, int page, | ||
216 | unsigned char *redir, unsigned char *data) | ||
217 | { | ||
218 | int loops = 16, i; | ||
219 | |||
220 | while(redir[page] != 0xFF) { | ||
221 | page = redir[page]^0xFF; | ||
222 | loops--; | ||
223 | if(loops<0) { | ||
224 | printk(KERN_ERR "IOC3: NIC circular redirection\n"); | ||
225 | return; | ||
226 | } | ||
227 | } | ||
228 | loops = 3; | ||
229 | while(loops>0) { | ||
230 | nic_addr(idd, addr); | ||
231 | nic_write_byte(idd, 0xF0); | ||
232 | nic_write_byte(idd, (page << 5) & 0xE0); | ||
233 | nic_write_byte(idd, (page >> 3) & 0x1F); | ||
234 | for(i=0;i<0x20;i++) | ||
235 | data[i] = nic_read_byte(idd); | ||
236 | if(crc16_area(data, 0x20, 0x0000) == 0x800d) | ||
237 | return; | ||
238 | loops--; | ||
239 | } | ||
240 | printk(KERN_ERR "IOC3: CRC error in data page\n"); | ||
241 | for(i=0;i<0x20;i++) | ||
242 | data[i] = 0x00; | ||
243 | } | ||
244 | |||
245 | static void | ||
246 | read_redir_map(struct ioc3_driver_data *idd, unsigned long addr, | ||
247 | unsigned char *redir) | ||
248 | { | ||
249 | int i,j,loops = 3,crc_ok; | ||
250 | unsigned int crc; | ||
251 | |||
252 | while(loops>0) { | ||
253 | crc_ok = 1; | ||
254 | nic_addr(idd, addr); | ||
255 | nic_write_byte(idd, 0xAA); | ||
256 | nic_write_byte(idd, 0x00); | ||
257 | nic_write_byte(idd, 0x01); | ||
258 | for(i=0;i<64;i+=8) { | ||
259 | for(j=0;j<8;j++) | ||
260 | redir[i+j] = nic_read_byte(idd); | ||
261 | crc = crc16_area(redir+i, 8, (i==0)?0x8707:0x0000); | ||
262 | crc16_byte(&crc, nic_read_byte(idd)); | ||
263 | crc16_byte(&crc, nic_read_byte(idd)); | ||
264 | if(crc != 0x800d) | ||
265 | crc_ok = 0; | ||
266 | } | ||
267 | if(crc_ok) | ||
268 | return; | ||
269 | loops--; | ||
270 | } | ||
271 | printk(KERN_ERR "IOC3: CRC error in redirection page\n"); | ||
272 | for(i=0;i<64;i++) | ||
273 | redir[i] = 0xFF; | ||
274 | } | ||
275 | |||
276 | static void read_nic(struct ioc3_driver_data *idd, unsigned long addr) | ||
277 | { | ||
278 | unsigned char redir[64]; | ||
279 | unsigned char data[64],part[32]; | ||
280 | int i,j; | ||
281 | |||
282 | /* read redirections */ | ||
283 | read_redir_map(idd, addr, redir); | ||
284 | /* read data pages */ | ||
285 | read_redir_page(idd, addr, 0, redir, data); | ||
286 | read_redir_page(idd, addr, 1, redir, data+32); | ||
287 | /* assemble the part # */ | ||
288 | j=0; | ||
289 | for(i=0;i<19;i++) | ||
290 | if(data[i+11] != ' ') | ||
291 | part[j++] = data[i+11]; | ||
292 | for(i=0;i<6;i++) | ||
293 | if(data[i+32] != ' ') | ||
294 | part[j++] = data[i+32]; | ||
295 | part[j] = 0; | ||
296 | /* skip Octane power supplies */ | ||
297 | if(!strncmp(part, "060-0035-", 9)) | ||
298 | return; | ||
299 | if(!strncmp(part, "060-0038-", 9)) | ||
300 | return; | ||
301 | strcpy(idd->nic_part, part); | ||
302 | /* assemble the serial # */ | ||
303 | j=0; | ||
304 | for(i=0;i<10;i++) | ||
305 | if(data[i+1] != ' ') | ||
306 | idd->nic_serial[j++] = data[i+1]; | ||
307 | idd->nic_serial[j] = 0; | ||
308 | } | ||
309 | |||
310 | static void read_mac(struct ioc3_driver_data *idd, unsigned long addr) | ||
311 | { | ||
312 | int i, loops = 3; | ||
313 | unsigned char data[13]; | ||
314 | |||
315 | while(loops>0) { | ||
316 | nic_addr(idd, addr); | ||
317 | nic_write_byte(idd, 0xF0); | ||
318 | nic_write_byte(idd, 0x00); | ||
319 | nic_write_byte(idd, 0x00); | ||
320 | nic_read_byte(idd); | ||
321 | for(i=0;i<13;i++) | ||
322 | data[i] = nic_read_byte(idd); | ||
323 | if(crc16_area(data, 13, 0x0000) == 0x800d) { | ||
324 | for(i=10;i>4;i--) | ||
325 | idd->nic_mac[10-i] = data[i]; | ||
326 | return; | ||
327 | } | ||
328 | loops--; | ||
329 | } | ||
330 | printk(KERN_ERR "IOC3: CRC error in MAC address\n"); | ||
331 | for(i=0;i<6;i++) | ||
332 | idd->nic_mac[i] = 0x00; | ||
333 | } | ||
334 | |||
335 | static void probe_nic(struct ioc3_driver_data *idd) | ||
336 | { | ||
337 | int save = 0, loops = 3; | ||
338 | unsigned long first, addr; | ||
339 | |||
340 | idd->vma->gpcr_s = GPCR_MLAN_EN; | ||
341 | |||
342 | while(loops>0) { | ||
343 | idd->nic_part[0] = 0; | ||
344 | idd->nic_serial[0] = 0; | ||
345 | addr = first = nic_find(idd, &save, 0); | ||
346 | if(!first) | ||
347 | return; | ||
348 | while(1) { | ||
349 | if(crc8_addr(addr)) | ||
350 | break; | ||
351 | else { | ||
352 | switch(addr & 0xFF) { | ||
353 | case 0x0B: | ||
354 | read_nic(idd, addr); | ||
355 | break; | ||
356 | case 0x09: | ||
357 | case 0x89: | ||
358 | case 0x91: | ||
359 | read_mac(idd, addr); | ||
360 | break; | ||
361 | } | ||
362 | } | ||
363 | addr = nic_find(idd, &save, addr); | ||
364 | if(addr == first) | ||
365 | return; | ||
366 | } | ||
367 | loops--; | ||
368 | } | ||
369 | printk(KERN_ERR "IOC3: CRC error in NIC address\n"); | ||
370 | } | ||
371 | |||
372 | /* Interrupts */ | ||
373 | |||
374 | static inline void | ||
375 | write_ireg(struct ioc3_driver_data *idd, uint32_t val, int which) | ||
376 | { | ||
377 | unsigned long flags; | ||
378 | |||
379 | spin_lock_irqsave(&idd->ir_lock, flags); | ||
380 | switch (which) { | ||
381 | case IOC3_W_IES: | ||
382 | writel(val, &idd->vma->sio_ies); | ||
383 | break; | ||
384 | case IOC3_W_IEC: | ||
385 | writel(val, &idd->vma->sio_iec); | ||
386 | break; | ||
387 | } | ||
388 | spin_unlock_irqrestore(&idd->ir_lock, flags); | ||
389 | } | ||
390 | static inline uint32_t get_pending_intrs(struct ioc3_driver_data *idd) | ||
391 | { | ||
392 | unsigned long flag; | ||
393 | uint32_t intrs = 0; | ||
394 | |||
395 | spin_lock_irqsave(&idd->ir_lock, flag); | ||
396 | intrs = readl(&idd->vma->sio_ir); | ||
397 | intrs &= readl(&idd->vma->sio_ies); | ||
398 | spin_unlock_irqrestore(&idd->ir_lock, flag); | ||
399 | return intrs; | ||
400 | } | ||
401 | |||
402 | static irqreturn_t ioc3_intr_io(int irq, void *arg, struct pt_regs *regs) | ||
403 | { | ||
404 | unsigned long flags; | ||
405 | struct ioc3_driver_data *idd = (struct ioc3_driver_data *)arg; | ||
406 | int handled = 1, id; | ||
407 | unsigned int pending; | ||
408 | |||
409 | read_lock_irqsave(&ioc3_submodules_lock, flags); | ||
410 | |||
411 | if(idd->dual_irq && idd->vma->eisr) { | ||
412 | /* send Ethernet IRQ to the driver */ | ||
413 | if(ioc3_ethernet && idd->active[ioc3_ethernet->id] && | ||
414 | ioc3_ethernet->intr) { | ||
415 | handled = handled && !ioc3_ethernet->intr(ioc3_ethernet, | ||
416 | idd, 0, regs); | ||
417 | } | ||
418 | } | ||
419 | pending = get_pending_intrs(idd); /* look at the IO IRQs */ | ||
420 | |||
421 | for(id=0;id<IOC3_MAX_SUBMODULES;id++) { | ||
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, | ||
426 | IOC3_W_IEC); | ||
427 | if(!ioc3_submodules[id]->intr(ioc3_submodules[id], | ||
428 | idd, pending & ioc3_submodules[id]->irq_mask, | ||
429 | regs)) | ||
430 | pending &= ~ioc3_submodules[id]->irq_mask; | ||
431 | if (ioc3_submodules[id]->reset_mask) | ||
432 | write_ireg(idd, ioc3_submodules[id]->irq_mask, | ||
433 | IOC3_W_IES); | ||
434 | } | ||
435 | } | ||
436 | read_unlock_irqrestore(&ioc3_submodules_lock, flags); | ||
437 | if(pending) { | ||
438 | printk(KERN_WARNING | ||
439 | "IOC3: Pending IRQs 0x%08x discarded and disabled\n",pending); | ||
440 | write_ireg(idd, pending, IOC3_W_IEC); | ||
441 | handled = 1; | ||
442 | } | ||
443 | return handled?IRQ_HANDLED:IRQ_NONE; | ||
444 | } | ||
445 | |||
446 | static irqreturn_t ioc3_intr_eth(int irq, void *arg, struct pt_regs *regs) | ||
447 | { | ||
448 | unsigned long flags; | ||
449 | struct ioc3_driver_data *idd = (struct ioc3_driver_data *)arg; | ||
450 | int handled = 1; | ||
451 | |||
452 | if(!idd->dual_irq) | ||
453 | return IRQ_NONE; | ||
454 | read_lock_irqsave(&ioc3_submodules_lock, flags); | ||
455 | if(ioc3_ethernet && idd->active[ioc3_ethernet->id] | ||
456 | && ioc3_ethernet->intr) | ||
457 | handled = handled && !ioc3_ethernet->intr(ioc3_ethernet, idd, 0, | ||
458 | regs); | ||
459 | read_unlock_irqrestore(&ioc3_submodules_lock, flags); | ||
460 | return handled?IRQ_HANDLED:IRQ_NONE; | ||
461 | } | ||
462 | |||
463 | void ioc3_enable(struct ioc3_submodule *is, | ||
464 | struct ioc3_driver_data *idd, unsigned int irqs) | ||
465 | { | ||
466 | write_ireg(idd, irqs & is->irq_mask, IOC3_W_IES); | ||
467 | } | ||
468 | |||
469 | void ioc3_ack(struct ioc3_submodule *is, struct ioc3_driver_data *idd, | ||
470 | unsigned int irqs) | ||
471 | { | ||
472 | writel(irqs & is->irq_mask, &idd->vma->sio_ir); | ||
473 | } | ||
474 | |||
475 | void ioc3_disable(struct ioc3_submodule *is, | ||
476 | struct ioc3_driver_data *idd, unsigned int irqs) | ||
477 | { | ||
478 | write_ireg(idd, irqs & is->irq_mask, IOC3_W_IEC); | ||
479 | } | ||
480 | |||
481 | void ioc3_gpcr_set(struct ioc3_driver_data *idd, unsigned int val) | ||
482 | { | ||
483 | unsigned long flags; | ||
484 | spin_lock_irqsave(&idd->gpio_lock, flags); | ||
485 | writel(val, &idd->vma->gpcr_s); | ||
486 | spin_unlock_irqrestore(&idd->gpio_lock, flags); | ||
487 | } | ||
488 | |||
489 | /* Keep it simple, stupid! */ | ||
490 | static int find_slot(void **tab, int max) | ||
491 | { | ||
492 | int i; | ||
493 | for(i=0;i<max;i++) | ||
494 | if(!(tab[i])) | ||
495 | return i; | ||
496 | return -1; | ||
497 | } | ||
498 | |||
499 | /* Register an IOC3 submodule */ | ||
500 | int ioc3_register_submodule(struct ioc3_submodule *is) | ||
501 | { | ||
502 | struct ioc3_driver_data *idd; | ||
503 | int alloc_id; | ||
504 | unsigned long flags; | ||
505 | |||
506 | write_lock_irqsave(&ioc3_submodules_lock, flags); | ||
507 | alloc_id = find_slot((void **)ioc3_submodules, IOC3_MAX_SUBMODULES); | ||
508 | if(alloc_id != -1) { | ||
509 | ioc3_submodules[alloc_id] = is; | ||
510 | if(is->ethernet) { | ||
511 | if(ioc3_ethernet==NULL) | ||
512 | ioc3_ethernet=is; | ||
513 | else | ||
514 | printk(KERN_WARNING | ||
515 | "IOC3 Ethernet module already registered!\n"); | ||
516 | } | ||
517 | } | ||
518 | write_unlock_irqrestore(&ioc3_submodules_lock, flags); | ||
519 | |||
520 | if(alloc_id == -1) { | ||
521 | printk(KERN_WARNING "Increase IOC3_MAX_SUBMODULES!\n"); | ||
522 | return -ENOMEM; | ||
523 | } | ||
524 | |||
525 | is->id=alloc_id; | ||
526 | |||
527 | /* Initialize submodule for each IOC3 */ | ||
528 | if (!is->probe) | ||
529 | return 0; | ||
530 | |||
531 | down_read(&ioc3_devices_rwsem); | ||
532 | list_for_each_entry(idd, &ioc3_devices, list) { | ||
533 | /* set to 1 for IRQs in probe */ | ||
534 | idd->active[alloc_id] = 1; | ||
535 | idd->active[alloc_id] = !is->probe(is, idd); | ||
536 | } | ||
537 | up_read(&ioc3_devices_rwsem); | ||
538 | |||
539 | return 0; | ||
540 | } | ||
541 | |||
542 | /* Unregister an IOC3 submodule */ | ||
543 | void ioc3_unregister_submodule(struct ioc3_submodule *is) | ||
544 | { | ||
545 | struct ioc3_driver_data *idd; | ||
546 | unsigned long flags; | ||
547 | |||
548 | write_lock_irqsave(&ioc3_submodules_lock, flags); | ||
549 | if(ioc3_submodules[is->id]==is) | ||
550 | ioc3_submodules[is->id]=NULL; | ||
551 | else | ||
552 | printk(KERN_WARNING | ||
553 | "IOC3 submodule %s has wrong ID.\n",is->name); | ||
554 | if(ioc3_ethernet==is) | ||
555 | ioc3_ethernet = NULL; | ||
556 | write_unlock_irqrestore(&ioc3_submodules_lock, flags); | ||
557 | |||
558 | /* Remove submodule for each IOC3 */ | ||
559 | down_read(&ioc3_devices_rwsem); | ||
560 | list_for_each_entry(idd, &ioc3_devices, list) | ||
561 | if(idd->active[is->id]) { | ||
562 | if(is->remove) | ||
563 | if(is->remove(is, idd)) | ||
564 | printk(KERN_WARNING | ||
565 | "%s: IOC3 submodule %s remove failed " | ||
566 | "for pci_dev %s.\n", | ||
567 | __FUNCTION__, module_name(is->owner), | ||
568 | pci_name(idd->pdev)); | ||
569 | idd->active[is->id] = 0; | ||
570 | if(is->irq_mask) | ||
571 | write_ireg(idd, is->irq_mask, IOC3_W_IEC); | ||
572 | } | ||
573 | up_read(&ioc3_devices_rwsem); | ||
574 | } | ||
575 | |||
576 | /********************* | ||
577 | * Device management * | ||
578 | *********************/ | ||
579 | |||
580 | static char * | ||
581 | ioc3_class_names[]={"unknown", "IP27 BaseIO", "IP30 system", "MENET 1/2/3", | ||
582 | "MENET 4", "CADduo", "Altix Serial"}; | ||
583 | |||
584 | static int ioc3_class(struct ioc3_driver_data *idd) | ||
585 | { | ||
586 | int res = IOC3_CLASS_NONE; | ||
587 | /* NIC-based logic */ | ||
588 | if(!strncmp(idd->nic_part, "030-0891-", 9)) | ||
589 | res = IOC3_CLASS_BASE_IP30; | ||
590 | if(!strncmp(idd->nic_part, "030-1155-", 9)) | ||
591 | res = IOC3_CLASS_CADDUO; | ||
592 | if(!strncmp(idd->nic_part, "030-1657-", 9)) | ||
593 | res = IOC3_CLASS_SERIAL; | ||
594 | if(!strncmp(idd->nic_part, "030-1664-", 9)) | ||
595 | res = IOC3_CLASS_SERIAL; | ||
596 | /* total random heuristics */ | ||
597 | #ifdef CONFIG_SGI_IP27 | ||
598 | if(!idd->nic_part[0]) | ||
599 | res = IOC3_CLASS_BASE_IP27; | ||
600 | #endif | ||
601 | /* print educational message */ | ||
602 | printk(KERN_INFO "IOC3 part: [%s], serial: [%s] => class %s\n", | ||
603 | idd->nic_part, idd->nic_serial, ioc3_class_names[res]); | ||
604 | return res; | ||
605 | } | ||
606 | /* Adds a new instance of an IOC3 card */ | ||
607 | static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) | ||
608 | { | ||
609 | struct ioc3_driver_data *idd; | ||
610 | uint32_t pcmd; | ||
611 | int ret, id; | ||
612 | |||
613 | /* Enable IOC3 and take ownership of it */ | ||
614 | if ((ret = pci_enable_device(pdev))) { | ||
615 | printk(KERN_WARNING | ||
616 | "%s: Failed to enable IOC3 device for pci_dev %s.\n", | ||
617 | __FUNCTION__, pci_name(pdev)); | ||
618 | goto out; | ||
619 | } | ||
620 | pci_set_master(pdev); | ||
621 | |||
622 | #ifdef USE_64BIT_DMA | ||
623 | ret = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); | ||
624 | if (!ret) { | ||
625 | ret = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); | ||
626 | if (ret < 0) { | ||
627 | printk(KERN_WARNING "%s: Unable to obtain 64 bit DMA " | ||
628 | "for consistent allocations\n", | ||
629 | __FUNCTION__); | ||
630 | } | ||
631 | } | ||
632 | #endif | ||
633 | |||
634 | /* Set up per-IOC3 data */ | ||
635 | idd = kmalloc(sizeof(struct ioc3_driver_data), GFP_KERNEL); | ||
636 | if (!idd) { | ||
637 | printk(KERN_WARNING | ||
638 | "%s: Failed to allocate IOC3 data for pci_dev %s.\n", | ||
639 | __FUNCTION__, pci_name(pdev)); | ||
640 | ret = -ENODEV; | ||
641 | goto out_idd; | ||
642 | } | ||
643 | memset(idd, 0, sizeof(struct ioc3_driver_data)); | ||
644 | spin_lock_init(&idd->ir_lock); | ||
645 | spin_lock_init(&idd->gpio_lock); | ||
646 | idd->pdev = pdev; | ||
647 | |||
648 | /* Map all IOC3 registers. These are shared between subdevices | ||
649 | * so the main IOC3 module manages them. | ||
650 | */ | ||
651 | idd->pma = pci_resource_start(pdev, 0); | ||
652 | if (!idd->pma) { | ||
653 | printk(KERN_WARNING | ||
654 | "%s: Unable to find IOC3 resource " | ||
655 | "for pci_dev %s.\n", | ||
656 | __FUNCTION__, pci_name(pdev)); | ||
657 | ret = -ENODEV; | ||
658 | goto out_pci; | ||
659 | } | ||
660 | if (!request_region(idd->pma, IOC3_PCI_SIZE, "ioc3")) { | ||
661 | printk(KERN_WARNING | ||
662 | "%s: Unable to request IOC3 region " | ||
663 | "for pci_dev %s.\n", | ||
664 | __FUNCTION__, pci_name(pdev)); | ||
665 | ret = -ENODEV; | ||
666 | goto out_pci; | ||
667 | } | ||
668 | idd->vma = ioremap(idd->pma, IOC3_PCI_SIZE); | ||
669 | if (!idd->vma) { | ||
670 | printk(KERN_WARNING | ||
671 | "%s: Unable to remap IOC3 region " | ||
672 | "for pci_dev %s.\n", | ||
673 | __FUNCTION__, pci_name(pdev)); | ||
674 | ret = -ENODEV; | ||
675 | goto out_misc_region; | ||
676 | } | ||
677 | |||
678 | /* Track PCI-device specific data */ | ||
679 | pci_set_drvdata(pdev, idd); | ||
680 | down_write(&ioc3_devices_rwsem); | ||
681 | list_add(&idd->list, &ioc3_devices); | ||
682 | idd->id = ioc3_counter++; | ||
683 | up_write(&ioc3_devices_rwsem); | ||
684 | |||
685 | idd->gpdr_shadow = idd->vma->gpdr; | ||
686 | |||
687 | /* Read IOC3 NIC contents */ | ||
688 | probe_nic(idd); | ||
689 | |||
690 | /* Detect IOC3 class */ | ||
691 | idd->class = ioc3_class(idd); | ||
692 | |||
693 | /* Initialize IOC3 */ | ||
694 | pci_read_config_dword(pdev, PCI_COMMAND, &pcmd); | ||
695 | pci_write_config_dword(pdev, PCI_COMMAND, | ||
696 | pcmd | PCI_COMMAND_MEMORY | | ||
697 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | | ||
698 | PCI_SCR_DROP_MODE_EN); | ||
699 | |||
700 | write_ireg(idd, ~0, IOC3_W_IEC); | ||
701 | writel(~0, &idd->vma->sio_ir); | ||
702 | |||
703 | /* Set up IRQs */ | ||
704 | if(idd->class == IOC3_CLASS_BASE_IP30 | ||
705 | || idd->class == IOC3_CLASS_BASE_IP27) { | ||
706 | writel(0, &idd->vma->eier); | ||
707 | writel(~0, &idd->vma->eisr); | ||
708 | |||
709 | idd->dual_irq = 1; | ||
710 | if (!request_irq(pdev->irq, ioc3_intr_eth, SA_SHIRQ, | ||
711 | "ioc3-eth", (void *)idd)) { | ||
712 | idd->irq_eth = pdev->irq; | ||
713 | } else { | ||
714 | printk(KERN_WARNING | ||
715 | "%s : request_irq fails for IRQ 0x%x\n ", | ||
716 | __FUNCTION__, pdev->irq); | ||
717 | } | ||
718 | if (!request_irq(pdev->irq+2, ioc3_intr_io, SA_SHIRQ, | ||
719 | "ioc3-io", (void *)idd)) { | ||
720 | idd->irq_io = pdev->irq+2; | ||
721 | } else { | ||
722 | printk(KERN_WARNING | ||
723 | "%s : request_irq fails for IRQ 0x%x\n ", | ||
724 | __FUNCTION__, pdev->irq+2); | ||
725 | } | ||
726 | } else { | ||
727 | if (!request_irq(pdev->irq, ioc3_intr_io, SA_SHIRQ, | ||
728 | "ioc3", (void *)idd)) { | ||
729 | idd->irq_io = pdev->irq; | ||
730 | } else { | ||
731 | printk(KERN_WARNING | ||
732 | "%s : request_irq fails for IRQ 0x%x\n ", | ||
733 | __FUNCTION__, pdev->irq); | ||
734 | } | ||
735 | } | ||
736 | |||
737 | /* Add this IOC3 to all submodules */ | ||
738 | read_lock(&ioc3_submodules_lock); | ||
739 | for(id=0;id<IOC3_MAX_SUBMODULES;id++) | ||
740 | if(ioc3_submodules[id] && ioc3_submodules[id]->probe) { | ||
741 | idd->active[id] = 1; | ||
742 | idd->active[id] = !ioc3_submodules[id]->probe | ||
743 | (ioc3_submodules[id], idd); | ||
744 | } | ||
745 | read_unlock(&ioc3_submodules_lock); | ||
746 | |||
747 | printk(KERN_INFO "IOC3 Master Driver loaded for %s\n", pci_name(pdev)); | ||
748 | |||
749 | return 0; | ||
750 | |||
751 | out_misc_region: | ||
752 | release_region(idd->pma, IOC3_PCI_SIZE); | ||
753 | out_pci: | ||
754 | kfree(idd); | ||
755 | out_idd: | ||
756 | pci_disable_device(pdev); | ||
757 | out: | ||
758 | return ret; | ||
759 | } | ||
760 | |||
761 | /* Removes a particular instance of an IOC3 card. */ | ||
762 | static void ioc3_remove(struct pci_dev *pdev) | ||
763 | { | ||
764 | int id; | ||
765 | struct ioc3_driver_data *idd; | ||
766 | |||
767 | idd = pci_get_drvdata(pdev); | ||
768 | |||
769 | /* Remove this IOC3 from all submodules */ | ||
770 | read_lock(&ioc3_submodules_lock); | ||
771 | for(id=0;id<IOC3_MAX_SUBMODULES;id++) | ||
772 | if(idd->active[id]) { | ||
773 | if(ioc3_submodules[id] && ioc3_submodules[id]->remove) | ||
774 | if(ioc3_submodules[id]->remove(ioc3_submodules[id], | ||
775 | idd)) | ||
776 | printk(KERN_WARNING | ||
777 | "%s: IOC3 submodule 0x%s remove failed " | ||
778 | "for pci_dev %s.\n", | ||
779 | __FUNCTION__, | ||
780 | module_name(ioc3_submodules[id]->owner), | ||
781 | pci_name(pdev)); | ||
782 | idd->active[id] = 0; | ||
783 | } | ||
784 | read_unlock(&ioc3_submodules_lock); | ||
785 | |||
786 | /* Clear and disable all IRQs */ | ||
787 | write_ireg(idd, ~0, IOC3_W_IEC); | ||
788 | writel(~0, &idd->vma->sio_ir); | ||
789 | |||
790 | /* Release resources */ | ||
791 | free_irq(idd->irq_io, (void *)idd); | ||
792 | if(idd->dual_irq) | ||
793 | free_irq(idd->irq_eth, (void *)idd); | ||
794 | iounmap(idd->vma); | ||
795 | release_region(idd->pma, IOC3_PCI_SIZE); | ||
796 | |||
797 | /* Disable IOC3 and relinquish */ | ||
798 | pci_disable_device(pdev); | ||
799 | |||
800 | /* Remove and free driver data */ | ||
801 | down_write(&ioc3_devices_rwsem); | ||
802 | list_del(&idd->list); | ||
803 | up_write(&ioc3_devices_rwsem); | ||
804 | kfree(idd); | ||
805 | } | ||
806 | |||
807 | static struct pci_device_id ioc3_id_table[] = { | ||
808 | {PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, PCI_ANY_ID, PCI_ANY_ID}, | ||
809 | {0} | ||
810 | }; | ||
811 | |||
812 | static struct pci_driver ioc3_driver = { | ||
813 | .name = "IOC3", | ||
814 | .id_table = ioc3_id_table, | ||
815 | .probe = ioc3_probe, | ||
816 | .remove = ioc3_remove, | ||
817 | }; | ||
818 | |||
819 | MODULE_DEVICE_TABLE(pci, ioc3_id_table); | ||
820 | |||
821 | /********************* | ||
822 | * Module management * | ||
823 | *********************/ | ||
824 | |||
825 | /* Module load */ | ||
826 | static int __devinit ioc3_init(void) | ||
827 | { | ||
828 | if (ia64_platform_is("sn2")) | ||
829 | return pci_register_driver(&ioc3_driver); | ||
830 | return 0; | ||
831 | } | ||
832 | |||
833 | /* Module unload */ | ||
834 | static void __devexit ioc3_exit(void) | ||
835 | { | ||
836 | pci_unregister_driver(&ioc3_driver); | ||
837 | } | ||
838 | |||
839 | module_init(ioc3_init); | ||
840 | module_exit(ioc3_exit); | ||
841 | |||
842 | MODULE_AUTHOR("Stanislaw Skowronek <skylark@linux-mips.org>"); | ||
843 | MODULE_DESCRIPTION("PCI driver for SGI IOC3"); | ||
844 | MODULE_LICENSE("GPL"); | ||
845 | |||
846 | EXPORT_SYMBOL(ioc3_register_submodule); | ||
847 | EXPORT_SYMBOL(ioc3_unregister_submodule); | ||
848 | EXPORT_SYMBOL(ioc3_ack); | ||
849 | EXPORT_SYMBOL(ioc3_gpcr_set); | ||
850 | EXPORT_SYMBOL(ioc3_disable); | ||
851 | EXPORT_SYMBOL(ioc3_enable); | ||