1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#ifndef SYM_GLUE_H
54#define SYM_GLUE_H
55
56#if 0
57#define SYM_CONF_DMA_ADDRESSING_MODE 2
58#endif
59
60#define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
61#include <linux/version.h>
62#if LINUX_VERSION_CODE < LinuxVersionCode(2, 2, 0)
63#error "This driver requires a kernel version not lower than 2.2.0"
64#endif
65
66#include <asm/dma.h>
67#include <asm/io.h>
68#include <asm/system.h>
69#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,17)
70#include <linux/spinlock.h>
71#else
72#include <asm/spinlock.h>
73#endif
74#include <linux/delay.h>
75#include <linux/signal.h>
76#include <linux/sched.h>
77#include <linux/errno.h>
78#include <linux/pci.h>
79#include <linux/string.h>
80#include <linux/mm.h>
81#include <linux/ioport.h>
82#include <linux/time.h>
83#include <linux/timer.h>
84#include <linux/stat.h>
85#include <linux/interrupt.h>
86
87#include <linux/blk.h>
88
89#ifdef __sparc__
90# include <asm/irq.h>
91#endif
92#include <linux/init.h>
93
94#ifndef __init
95#define __init
96#endif
97#ifndef __initdata
98#define __initdata
99#endif
100
101#include "../scsi.h"
102#include "../hosts.h"
103
104#include <linux/types.h>
105
106
107
108
109#ifndef BITS_PER_LONG
110#if (~0UL) == 0xffffffffUL
111#define BITS_PER_LONG 32
112#else
113#define BITS_PER_LONG 64
114#endif
115#endif
116
117typedef u_long vm_offset_t;
118
119#ifndef bcopy
120#define bcopy(s, d, n) memcpy((d), (s), (n))
121#endif
122
123#ifndef bzero
124#define bzero(d, n) memset((d), 0, (n))
125#endif
126
127#ifndef bcmp
128#define bcmp(a, b, n) memcmp((a), (b), (n))
129#endif
130
131
132
133
134#include "sym53c8xx.h"
135#include "sym_misc.h"
136#include "sym_conf.h"
137#include "sym_defs.h"
138
139
140
141
142#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,47)
143#define SYM_LINUX_DYNAMIC_DMA_MAPPING
144#endif
145
146#define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
147
148#define SYM_OPT_HANDLE_DIR_UNKNOWN
149#define SYM_OPT_HANDLE_DEVICE_QUEUEING
150#define SYM_OPT_NVRAM_PRE_READ
151#define SYM_OPT_SNIFF_INQUIRY
152#define SYM_OPT_LIMIT_COMMAND_REORDERING
153#define SYM_OPT_ANNOUNCE_TRANSFER_RATE
154
155#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
156#define SYM_OPT_BUS_DMA_ABSTRACTION
157#endif
158
159
160
161
162#define printf_emerg(args...) printk(KERN_EMERG args)
163#define printf_alert(args...) printk(KERN_ALERT args)
164#define printf_crit(args...) printk(KERN_CRIT args)
165#define printf_err(args...) printk(KERN_ERR args)
166#define printf_warning(args...) printk(KERN_WARNING args)
167#define printf_notice(args...) printk(KERN_NOTICE args)
168#define printf_info(args...) printk(KERN_INFO args)
169#define printf_debug(args...) printk(KERN_DEBUG args)
170#define printf(args...) printk(args)
171
172
173
174
175void sym_udelay(int us);
176void sym_mdelay(int ms);
177
178
179
180
181typedef struct sym_tcb *tcb_p;
182typedef struct sym_lcb *lcb_p;
183typedef struct sym_ccb *ccb_p;
184typedef struct sym_hcb *hcb_p;
185typedef struct sym_stcb *stcb_p;
186typedef struct sym_slcb *slcb_p;
187typedef struct sym_sccb *sccb_p;
188typedef struct sym_shcb *shcb_p;
189
190
191
192
193typedef Scsi_Cmnd *cam_ccb_p;
194typedef Scsi_Cmnd *cam_scsiio_p;
195
196
197
198
199
200
201
202#ifdef __BIG_ENDIAN
203
204#define inw_l2b inw
205#define inl_l2b inl
206#define outw_b2l outw
207#define outl_b2l outl
208#define readw_l2b readw
209#define readl_l2b readl
210#define writew_b2l writew
211#define writel_b2l writel
212
213#else
214
215#if defined(__i386__)
216#define inw_raw inw
217#define inl_raw inl
218#define outw_raw outw
219#define outl_raw outl
220#define readb_raw(a) (*(volatile unsigned char *) (a))
221#define readw_raw(a) (*(volatile unsigned short *) (a))
222#define readl_raw(a) (*(volatile unsigned int *) (a))
223#define writeb_raw(b,a) ((*(volatile unsigned char *) (a)) = (b))
224#define writew_raw(b,a) ((*(volatile unsigned short *) (a)) = (b))
225#define writel_raw(b,a) ((*(volatile unsigned int *) (a)) = (b))
226
227#else
228#define inw_raw inw
229#define inl_raw inl
230#define outw_raw outw
231#define outl_raw outl
232#define readw_raw readw
233#define readl_raw readl
234#define writew_raw writew
235#define writel_raw writel
236
237#endif
238#endif
239
240#ifdef SYM_CONF_CHIP_BIG_ENDIAN
241#error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
242#endif
243
244
245
246
247
248
249
250
251
252
253#if defined(SYM_CONF_CHIP_BIG_ENDIAN)
254
255#define sym_offb(o) (((o)&~3)+((~((o)&3))&3))
256#define sym_offw(o) (((o)&~3)+((~((o)&3))&2))
257
258#else
259
260#define sym_offb(o) (o)
261#define sym_offw(o) (o)
262
263#endif
264
265
266
267
268
269
270
271
272
273#if defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
274
275#define cpu_to_scr(dw) cpu_to_le32(dw)
276#define scr_to_cpu(dw) le32_to_cpu(dw)
277
278#elif defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
279
280#define cpu_to_scr(dw) cpu_to_be32(dw)
281#define scr_to_cpu(dw) be32_to_cpu(dw)
282
283#else
284
285#define cpu_to_scr(dw) (dw)
286#define scr_to_cpu(dw) (dw)
287
288#endif
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310#if defined(SYM_CONF_IOMAPPED)
311
312
313
314
315
316#define INB_OFF(o) inb (np->s.io_port + sym_offb(o))
317#define OUTB_OFF(o, val) outb ((val), np->s.io_port + sym_offb(o))
318
319#if defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
320
321#define INW_OFF(o) inw_l2b (np->s.io_port + sym_offw(o))
322#define INL_OFF(o) inl_l2b (np->s.io_port + (o))
323
324#define OUTW_OFF(o, val) outw_b2l ((val), np->s.io_port + sym_offw(o))
325#define OUTL_OFF(o, val) outl_b2l ((val), np->s.io_port + (o))
326
327#elif defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
328
329#define INW_OFF(o) inw_b2l (np->s.io_port + sym_offw(o))
330#define INL_OFF(o) inl_b2l (np->s.io_port + (o))
331
332#define OUTW_OFF(o, val) outw_l2b ((val), np->s.io_port + sym_offw(o))
333#define OUTL_OFF(o, val) outl_l2b ((val), np->s.io_port + (o))
334
335#else
336
337#define INW_OFF(o) inw_raw (np->s.io_port + sym_offw(o))
338#define INL_OFF(o) inl_raw (np->s.io_port + (o))
339
340#define OUTW_OFF(o, val) outw_raw ((val), np->s.io_port + sym_offw(o))
341#define OUTL_OFF(o, val) outl_raw ((val), np->s.io_port + (o))
342
343#endif
344
345#else
346
347
348
349
350
351#define INB_OFF(o) readb((char *)np->s.mmio_va + sym_offb(o))
352#define OUTB_OFF(o, val) writeb((val), (char *)np->s.mmio_va + sym_offb(o))
353
354#if defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
355
356#define INW_OFF(o) readw_l2b((char *)np->s.mmio_va + sym_offw(o))
357#define INL_OFF(o) readl_l2b((char *)np->s.mmio_va + (o))
358
359#define OUTW_OFF(o, val) writew_b2l((val), (char *)np->s.mmio_va + sym_offw(o))
360#define OUTL_OFF(o, val) writel_b2l((val), (char *)np->s.mmio_va + (o))
361
362#elif defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
363
364#define INW_OFF(o) readw_b2l((char *)np->s.mmio_va + sym_offw(o))
365#define INL_OFF(o) readl_b2l((char *)np->s.mmio_va + (o))
366
367#define OUTW_OFF(o, val) writew_l2b((val), (char *)np->s.mmio_va + sym_offw(o))
368#define OUTL_OFF(o, val) writel_l2b((val), (char *)np->s.mmio_va + (o))
369
370#else
371
372#define INW_OFF(o) readw_raw((char *)np->s.mmio_va + sym_offw(o))
373#define INL_OFF(o) readl_raw((char *)np->s.mmio_va + (o))
374
375#define OUTW_OFF(o, val) writew_raw((val), (char *)np->s.mmio_va + sym_offw(o))
376#define OUTL_OFF(o, val) writel_raw((val), (char *)np->s.mmio_va + (o))
377
378#endif
379
380#endif
381
382#define OUTRAM_OFF(o, a, l) memcpy_toio(np->s.ram_va + (o), (a), (l))
383
384
385
386
387#define CAM_REQ_CMP DID_OK
388#define CAM_SEL_TIMEOUT DID_NO_CONNECT
389#define CAM_CMD_TIMEOUT DID_TIME_OUT
390#define CAM_REQ_ABORTED DID_ABORT
391#define CAM_UNCOR_PARITY DID_PARITY
392#define CAM_SCSI_BUS_RESET DID_RESET
393#define CAM_REQUEUE_REQ DID_SOFT_ERROR
394#define CAM_UNEXP_BUSFREE DID_ERROR
395#define CAM_SCSI_BUSY DID_BUS_BUSY
396
397#define CAM_DEV_NOT_THERE DID_NO_CONNECT
398#define CAM_REQ_INVALID DID_ERROR
399#define CAM_REQ_TOO_BIG DID_ERROR
400
401#define CAM_RESRC_UNAVAIL DID_ERROR
402
403
404
405
406#ifndef SCSI_DATA_UNKNOWN
407#define SCSI_DATA_UNKNOWN 0
408#define SCSI_DATA_WRITE 1
409#define SCSI_DATA_READ 2
410#define SCSI_DATA_NONE 3
411#endif
412#define CAM_DIR_NONE SCSI_DATA_NONE
413#define CAM_DIR_IN SCSI_DATA_READ
414#define CAM_DIR_OUT SCSI_DATA_WRITE
415#define CAM_DIR_UNKNOWN SCSI_DATA_UNKNOWN
416
417
418
419
420
421#define SCSI_SUCCESS SUCCESS
422#define SCSI_FAILED FAILED
423
424
425
426
427
428
429
430
431
432
433#define SYM_HAVE_SLCB
434struct sym_slcb {
435 u_short reqtags;
436 u_short scdev_depth;
437};
438
439
440
441
442
443
444
445
446
447
448struct sym_shcb {
449
450
451
452 int unit;
453 char inst_name[16];
454 char chip_name[8];
455 struct pci_dev *device;
456
457 struct Scsi_Host *host;
458
459 u_char bus;
460 u_char device_fn;
461
462 vm_offset_t mmio_va;
463 vm_offset_t ram_va;
464 u_long io_port;
465 u_short io_ws;
466 int irq;
467
468 SYM_QUEHEAD wait_cmdq;
469 SYM_QUEHEAD busy_cmdq;
470
471 struct timer_list timer;
472 u_long lasttime;
473 u_long settle_time;
474 u_char settle_time_valid;
475#if LINUX_VERSION_CODE < LinuxVersionCode(2, 4, 0)
476 u_char release_stage;
477#endif
478};
479
480
481
482
483#define sym_name(np) (np)->s.inst_name
484
485
486
487
488
489
490typedef struct {
491 int bus;
492 u_char device_fn;
493 u_long base;
494 u_long base_2;
495 u_long base_c;
496 u_long base_2_c;
497 int irq;
498
499 u_long io_port;
500 vm_offset_t mmio_va;
501 char inst_name[16];
502} sym_slot;
503
504typedef struct sym_nvram sym_nvram;
505typedef struct sym_pci_chip sym_chip;
506
507typedef struct {
508 struct pci_dev *pdev;
509 sym_slot s;
510 sym_chip chip;
511 sym_nvram *nvram;
512 u_short device_id;
513 u_char host_id;
514#ifdef SYM_CONF_PQS_PDS_SUPPORT
515 u_char pqs_pds;
516#endif
517 int attach_done;
518} sym_device;
519
520typedef sym_device *sdev_p;
521
522
523
524
525
526typedef u_long m_addr_t;
527#define SYM_MEM_PAGE_ORDER 0
528#define SYM_MEM_CLUSTER_SHIFT (PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
529#ifdef MODULE
530#define SYM_MEM_FREE_UNUSED
531#endif
532#ifdef SYM_LINUX_DYNAMIC_DMA_MAPPING
533typedef struct pci_dev *m_pool_ident_t;
534#endif
535
536
537
538
539#include "sym_fw.h"
540#include "sym_hipd.h"
541
542
543
544
545
546#define SYM_MEM_GFP_FLAGS GFP_ATOMIC
547#define SYM_MEM_WARN 1
548
549#define sym_get_mem_cluster() \
550 __get_free_pages(SYM_MEM_GFP_FLAGS, SYM_MEM_PAGE_ORDER)
551#define sym_free_mem_cluster(p) \
552 free_pages(p, SYM_MEM_PAGE_ORDER)
553
554void *sym_calloc(int size, char *name);
555void sym_mfree(void *m, int size, char *name);
556
557#ifndef SYM_LINUX_DYNAMIC_DMA_MAPPING
558
559
560
561
562
563#define __sym_calloc_dma(pool_id, size, name) sym_calloc(size, name)
564#define __sym_mfree_dma(pool_id, m, size, name) sym_mfree(m, size, name)
565#define __vtobus(b, p) virt_to_bus(p)
566
567#else
568
569
570
571
572
573
574#define sym_m_pool_match(mp_id1, mp_id2) (mp_id1 == mp_id2)
575
576static __inline m_addr_t sym_m_get_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
577{
578 void *vaddr = 0;
579 dma_addr_t baddr = 0;
580
581 vaddr = pci_alloc_consistent(mp->dev_dmat,SYM_MEM_CLUSTER_SIZE, &baddr);
582 if (vaddr) {
583 vbp->vaddr = (m_addr_t) vaddr;
584 vbp->baddr = (m_addr_t) baddr;
585 }
586 return (m_addr_t) vaddr;
587}
588
589static __inline void sym_m_free_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
590{
591 pci_free_consistent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE,
592 (void *)vbp->vaddr, (dma_addr_t)vbp->baddr);
593}
594
595#define sym_m_create_dma_mem_tag(mp) (0)
596
597#define sym_m_delete_dma_mem_tag(mp) do { ; } while (0)
598
599void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name);
600void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name);
601m_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m);
602
603#endif
604
605
606
607
608static __inline void
609sym_set_cam_status(Scsi_Cmnd *ccb, int status)
610{
611 ccb->result &= ~(0xff << 16);
612 ccb->result |= (status << 16);
613}
614
615
616
617
618static __inline int
619sym_get_cam_status(Scsi_Cmnd *ccb)
620{
621 return ((ccb->result >> 16) & 0xff);
622}
623
624
625
626
627
628#define sym_data_dmamap_create(np, cp) (0)
629#define sym_data_dmamap_destroy(np, cp) do { ; } while (0)
630#define sym_data_dmamap_unload(np, cp) do { ; } while (0)
631#define sym_data_dmamap_presync(np, cp) do { ; } while (0)
632#define sym_data_dmamap_postsync(np, cp) do { ; } while (0)
633
634
635
636
637void sym_xpt_async_nego_wide(hcb_p np, int target);
638#define sym_xpt_async_nego_sync(np, target) \
639 sym_announce_transfer_rate(np, target)
640#define sym_xpt_async_nego_ppr(np, target) \
641 sym_announce_transfer_rate(np, target)
642
643
644
645
646static __inline void sym_set_cam_result_ok(hcb_p np, ccb_p cp, int resid)
647{
648 Scsi_Cmnd *cmd = cp->cam_ccb;
649
650#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,99)
651 cmd->resid = resid;
652#endif
653 cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
654}
655void sym_set_cam_result_error(hcb_p np, ccb_p cp, int resid);
656
657
658
659
660#define sym_cam_target_id(ccb) (ccb)->target
661#define sym_cam_target_lun(ccb) (ccb)->lun
662#define sym_freeze_cam_ccb(ccb) do { ; } while (0)
663void sym_xpt_done(hcb_p np, cam_ccb_p ccb);
664void sym_xpt_done2(hcb_p np, cam_ccb_p ccb, int cam_status);
665void sym_print_addr (ccb_p cp);
666void sym_xpt_async_bus_reset(hcb_p np);
667void sym_xpt_async_sent_bdr(hcb_p np, int target);
668int sym_setup_data_and_start (hcb_p np, cam_scsiio_p csio, ccb_p cp);
669void sym_log_bus_error(hcb_p np);
670#ifdef SYM_OPT_SNIFF_INQUIRY
671void sym_sniff_inquiry(hcb_p np, Scsi_Cmnd *cmd, int resid);
672#endif
673
674#endif
675