Staging: slicoss: add binary firmware to firmware directory
[linux-2.6] / drivers / staging / slicoss / slic.h
1 /**************************************************************************
2  *
3  * Copyright (c) 2000-2002 Alacritech, Inc.  All rights reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above
13  *    copyright notice, this list of conditions and the following
14  *    disclaimer in the documentation and/or other materials provided
15  *    with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ALACRITECH, INC. OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * The views and conclusions contained in the software and documentation
31  * are those of the authors and should not be interpreted as representing
32  * official policies, either expressed or implied, of Alacritech, Inc.
33  *
34  **************************************************************************/
35
36 /*
37  * FILENAME: slic.h
38  *
39  * This is the base set of header definitions for the SLICOSS driver.
40  */
41 #ifndef __SLIC_DRIVER_H__
42 #define __SLIC_DRIVER_H__
43
44 /* firmware stuff */
45 #define OASIS_UCODE_VERS_STRING "1.2"
46 #define OASIS_UCODE_VERS_DATE   "2006/03/27 15:10:37"
47 #define OASIS_UCODE_HOSTIF_ID   3
48
49 #define MOJAVE_UCODE_VERS_STRING        "1.2"
50 #define MOJAVE_UCODE_VERS_DATE          "2006/03/27 15:12:22"
51 #define MOJAVE_UCODE_HOSTIF_ID          3
52
53 #define GB_RCVUCODE_VERS_STRING "1.2"
54 #define GB_RCVUCODE_VERS_DATE   "2006/03/27 15:12:15"
55 static u32 OasisRcvUCodeLen = 512;
56 static u32 GBRcvUCodeLen = 512;
57 #define SECTION_SIZE 65536
58
59 struct slic_spinlock {
60         spinlock_t      lock;
61         unsigned long   flags;
62 };
63
64 #define SLIC_RSPQ_PAGES_GB        10
65 #define SLIC_RSPQ_BUFSINPAGE      (PAGE_SIZE / SLIC_RSPBUF_SIZE)
66
67 struct slic_rspqueue {
68     u32             offset;
69     u32             pageindex;
70     u32             num_pages;
71     struct slic_rspbuf *rspbuf;
72     u32 *vaddr[SLIC_RSPQ_PAGES_GB];
73     dma_addr_t          paddr[SLIC_RSPQ_PAGES_GB];
74 };
75
76 #define SLIC_RCVQ_EXPANSION         1
77 #define SLIC_RCVQ_ENTRIES           (256 * SLIC_RCVQ_EXPANSION)
78 #define SLIC_RCVQ_MINENTRIES        (SLIC_RCVQ_ENTRIES / 2)
79 #define SLIC_RCVQ_MAX_PROCESS_ISR   ((SLIC_RCVQ_ENTRIES * 4))
80 #define SLIC_RCVQ_RCVBUFSIZE        2048
81 #define SLIC_RCVQ_FILLENTRIES       (16 * SLIC_RCVQ_EXPANSION)
82 #define SLIC_RCVQ_FILLTHRESH        (SLIC_RCVQ_ENTRIES - SLIC_RCVQ_FILLENTRIES)
83
84 struct slic_rcvqueue {
85     struct sk_buff    *head;
86     struct sk_buff    *tail;
87     u32            count;
88     u32            size;
89     u32            errors;
90 };
91
92 struct slic_rcvbuf_info {
93     u32     id;
94     u32     starttime;
95     u32     stoptime;
96     u32     slicworld;
97     u32     lasttime;
98     u32     lastid;
99 };
100 /*
101  SLIC Handle structure.  Used to restrict handle values to
102  32 bits by using an index rather than an address.
103  Simplifies ucode in 64-bit systems
104 */
105 struct slic_handle_word {
106         union {
107                 struct {
108                         ushort      index;
109                         ushort      bottombits; /* to denote num bufs to card */
110                 }  parts;
111                 u32         whole;
112         }  handle;
113 };
114
115 struct slic_handle {
116     struct slic_handle_word  token;  /* token passed between host and card*/
117     ushort                      type;
118     void *address;    /* actual address of the object*/
119     ushort                      offset;
120     struct slic_handle       *other_handle;
121     struct slic_handle       *next;
122 };
123
124 #define SLIC_HANDLE_FREE        0x0000
125 #define SLIC_HANDLE_DATA        0x0001
126 #define SLIC_HANDLE_CMD         0x0002
127 #define SLIC_HANDLE_CONTEXT     0x0003
128 #define SLIC_HANDLE_TEAM        0x0004
129
130 #define handle_index        handle.parts.index
131 #define handle_bottom       handle.parts.bottombits
132 #define handle_token        handle.whole
133
134 #define SLIC_HOSTCMD_SIZE    512
135
136 struct slic_hostcmd {
137     struct slic_host64_cmd  cmd64;
138     u32                    type;
139     struct sk_buff            *skb;
140     u32                    paddrl;
141     u32                    paddrh;
142     u32                    busy;
143     u32                    cmdsize;
144     ushort                     numbufs;
145     struct slic_handle    *pslic_handle;/* handle associated with command */
146     struct slic_hostcmd    *next;
147     struct slic_hostcmd    *next_all;
148 };
149
150 #define SLIC_CMDQ_CMDSINPAGE    (PAGE_SIZE / SLIC_HOSTCMD_SIZE)
151 #define SLIC_CMD_DUMB            3
152 #define SLIC_CMDQ_INITCMDS       256
153 #define SLIC_CMDQ_MAXCMDS        256
154 #define SLIC_CMDQ_MAXOUTSTAND    SLIC_CMDQ_MAXCMDS
155 #define SLIC_CMDQ_MAXPAGES       (SLIC_CMDQ_MAXCMDS / SLIC_CMDQ_CMDSINPAGE)
156 #define SLIC_CMDQ_INITPAGES      (SLIC_CMDQ_INITCMDS / SLIC_CMDQ_CMDSINPAGE)
157
158 struct slic_cmdqmem {
159         int pagecnt;
160         u32 *pages[SLIC_CMDQ_MAXPAGES];
161         dma_addr_t dma_pages[SLIC_CMDQ_MAXPAGES];
162 };
163
164 struct slic_cmdqueue {
165         struct slic_hostcmd *head;
166         struct slic_hostcmd *tail;
167         int count;
168         struct slic_spinlock lock;
169 };
170
171 #ifdef STATUS_SUCCESS
172 #undef STATUS_SUCCESS
173 #endif
174
175 #define STATUS_SUCCESS              0
176 #define STATUS_PENDING              0
177 #define STATUS_FAILURE             -1
178 #define STATUS_ERROR               -2
179 #define STATUS_NOT_SUPPORTED       -3
180 #define STATUS_BUFFER_TOO_SHORT    -4
181
182 #define SLIC_MAX_CARDS              32
183 #define SLIC_MAX_PORTS              4        /* Max # of ports per card   */
184 #if SLIC_DUMP_ENABLED
185 /*
186 Dump buffer size
187
188 This cannot be bigger than the max DMA size the card supports,
189 given the current code structure in the host and ucode.
190 Mojave supports 16K, Oasis supports 16K-1, so
191 just set this at 15K, shouldnt make that much of a diff.
192 */
193 #define DUMP_BUF_SIZE               0x3C00
194 #endif
195
196
197 struct mcast_address {
198         unsigned char address[6];
199         struct mcast_address *next;
200 };
201
202 #define CARD_DOWN        0x00000000
203 #define CARD_UP          0x00000001
204 #define CARD_FAIL        0x00000002
205 #define CARD_DIAG        0x00000003
206 #define CARD_SLEEP       0x00000004
207
208 #define ADAPT_DOWN             0x00
209 #define ADAPT_UP               0x01
210 #define ADAPT_FAIL             0x02
211 #define ADAPT_RESET            0x03
212 #define ADAPT_SLEEP            0x04
213
214 #define ADAPT_FLAGS_BOOTTIME            0x0001
215 #define ADAPT_FLAGS_IS64BIT             0x0002
216 #define ADAPT_FLAGS_PENDINGLINKDOWN     0x0004
217 #define ADAPT_FLAGS_FIBERMEDIA          0x0008
218 #define ADAPT_FLAGS_LOCKS_ALLOCED       0x0010
219 #define ADAPT_FLAGS_INT_REGISTERED      0x0020
220 #define ADAPT_FLAGS_LOAD_TIMER_SET      0x0040
221 #define ADAPT_FLAGS_STATS_TIMER_SET     0x0080
222 #define ADAPT_FLAGS_RESET_TIMER_SET     0x0100
223
224 #define LINK_DOWN              0x00
225 #define LINK_CONFIG            0x01
226 #define LINK_UP                0x02
227
228 #define LINK_10MB              0x00
229 #define LINK_100MB             0x01
230 #define LINK_AUTOSPEED         0x02
231 #define LINK_1000MB            0x03
232 #define LINK_10000MB           0x04
233
234 #define LINK_HALFD             0x00
235 #define LINK_FULLD             0x01
236 #define LINK_AUTOD             0x02
237
238 #define MAC_DIRECTED     0x00000001
239 #define MAC_BCAST        0x00000002
240 #define MAC_MCAST        0x00000004
241 #define MAC_PROMISC      0x00000008
242 #define MAC_LOOPBACK     0x00000010
243 #define MAC_ALLMCAST     0x00000020
244
245 #define SLIC_DUPLEX(x)    ((x == LINK_FULLD) ? "FDX" : "HDX")
246 #define SLIC_SPEED(x)     ((x == LINK_100MB) ? "100Mb" : ((x == LINK_1000MB) ?\
247                                 "1000Mb" : " 10Mb"))
248 #define SLIC_LINKSTATE(x) ((x == LINK_DOWN) ? "Down" : "Up  ")
249 #define SLIC_ADAPTER_STATE(x) ((x == ADAPT_UP) ? "UP" : "Down")
250 #define SLIC_CARD_STATE(x)    ((x == CARD_UP) ? "UP" : "Down")
251
252 struct slic_iface_stats {
253     /*
254      * Stats
255      */
256     u64        xmt_bytes;
257     u64        xmt_ucast;
258     u64        xmt_mcast;
259     u64        xmt_bcast;
260     u64        xmt_errors;
261     u64        xmt_discards;
262     u64        xmit_collisions;
263     u64        xmit_excess_xmit_collisions;
264     u64        rcv_bytes;
265     u64        rcv_ucast;
266     u64        rcv_mcast;
267     u64        rcv_bcast;
268     u64        rcv_errors;
269     u64        rcv_discards;
270 };
271
272 struct sliccp_stats {
273     u64        xmit_tcp_segs;
274     u64        xmit_tcp_bytes;
275     u64        rcv_tcp_segs;
276     u64        rcv_tcp_bytes;
277 };
278
279 struct slicnet_stats {
280     struct sliccp_stats        tcp;
281     struct slic_iface_stats      iface;
282 };
283
284 #define SLIC_LOADTIMER_PERIOD     1
285 #define SLIC_INTAGG_DEFAULT       200
286 #define SLIC_LOAD_0               0
287 #define SLIC_INTAGG_0             0
288 #define SLIC_LOAD_1               8000
289 #define SLIC_LOAD_2               10000
290 #define SLIC_LOAD_3               12000
291 #define SLIC_LOAD_4               14000
292 #define SLIC_LOAD_5               16000
293 #define SLIC_INTAGG_1             50
294 #define SLIC_INTAGG_2             100
295 #define SLIC_INTAGG_3             150
296 #define SLIC_INTAGG_4             200
297 #define SLIC_INTAGG_5             250
298 #define SLIC_LOAD_1GB             3000
299 #define SLIC_LOAD_2GB             6000
300 #define SLIC_LOAD_3GB             12000
301 #define SLIC_LOAD_4GB             24000
302 #define SLIC_LOAD_5GB             48000
303 #define SLIC_INTAGG_1GB           50
304 #define SLIC_INTAGG_2GB           75
305 #define SLIC_INTAGG_3GB           100
306 #define SLIC_INTAGG_4GB           100
307 #define SLIC_INTAGG_5GB           100
308
309 struct ether_header {
310     unsigned char    ether_dhost[6];
311     unsigned char    ether_shost[6];
312     ushort   ether_type;
313 };
314
315 struct sliccard {
316     uint              busnumber;
317     uint              slotnumber;
318     uint              state;
319     uint              cardnum;
320     uint              card_size;
321     uint              adapters_activated;
322     uint              adapters_allocated;
323     uint              adapters_sleeping;
324     uint              gennumber;
325     u32           events;
326     u32           loadlevel_current;
327     u32           load;
328     uint              reset_in_progress;
329     u32           pingstatus;
330     u32           bad_pingstatus;
331     struct timer_list loadtimer;
332     u32           loadtimerset;
333     uint              config_set;
334     struct slic_config  config;
335     struct dentry      *debugfs_dir;
336     struct dentry      *debugfs_cardinfo;
337     struct adapter  *master;
338     struct adapter  *adapter[SLIC_MAX_PORTS];
339     struct sliccard *next;
340     u32             error_interrupts;
341     u32             error_rmiss_interrupts;
342     u32             rcv_interrupts;
343     u32             xmit_interrupts;
344     u32             num_isrs;
345     u32             false_interrupts;
346     u32             max_isr_rcvs;
347     u32             max_isr_xmits;
348     u32             rcv_interrupt_yields;
349     u32             tx_packets;
350 #if SLIC_DUMP_ENABLED
351     u32             dumpstatus;           /* Result of dump UPR */
352     void *cmdbuffer;
353
354     ulong               cmdbuffer_phys;
355     u32             cmdbuffer_physl;
356     u32             cmdbuffer_physh;
357
358     u32             dump_count;
359     struct task_struct *dump_task_id;
360     u32             dump_wait_count;
361     uint                dumpthread_running; /* has a dump thread been init'd  */
362     uint                dump_requested;     /* 0 no, 1 = reqstd 2=curr 3=done */
363     u32             dumptime_start;
364     u32             dumptime_complete;
365     u32             dumptime_delta;
366     void *dumpbuffer;
367     ulong               dumpbuffer_phys;
368     u32             dumpbuffer_physl;
369     u32             dumpbuffer_physh;
370     wait_queue_head_t   dump_wq;
371     struct file        *dumphandle;
372     mm_segment_t        dumpfile_fs;
373 #endif
374     u32             debug_ix;
375     ushort              reg_type[32];
376     ushort              reg_offset[32];
377     u32             reg_value[32];
378     u32             reg_valueh[32];
379 };
380
381 #define NUM_CFG_SPACES      2
382 #define NUM_CFG_REGS        64
383 #define NUM_CFG_REG_ULONGS  (NUM_CFG_REGS / sizeof(u32))
384
385 struct physcard {
386     struct adapter  *adapter[SLIC_MAX_PORTS];
387     struct physcard *next;
388     uint                adapters_allocd;
389
390  /*  the following is not currently needed
391     u32               bridge_busnum;
392     u32               bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS];
393  */
394 };
395
396 struct base_driver {
397     struct slic_spinlock driver_lock;
398     u32              num_slic_cards;
399     u32              num_slic_ports;
400     u32              num_slic_ports_active;
401     u32              dynamic_intagg;
402     struct sliccard  *slic_card;
403     struct physcard  *phys_card;
404     uint                 cardnuminuse[SLIC_MAX_CARDS];
405 };
406
407 struct slic_shmem {
408     volatile u32          isr;
409     volatile u32          linkstatus;
410     volatile struct slic_stats     inicstats;
411 };
412
413 struct slic_reg_params {
414     u32       linkspeed;
415     u32       linkduplex;
416     u32       fail_on_bad_eeprom;
417 };
418
419 struct slic_upr {
420     uint               adapter;
421     u32            upr_request;
422     u32            upr_data;
423     u32            upr_data_h;
424     u32            upr_buffer;
425     u32            upr_buffer_h;
426     struct slic_upr *next;
427 };
428
429 struct slic_ifevents {
430     uint        oflow802;
431     uint        uflow802;
432     uint        Tprtoflow;
433     uint        rcvearly;
434     uint        Bufov;
435     uint        Carre;
436     uint        Longe;
437     uint        Invp;
438     uint        Crc;
439     uint        Drbl;
440     uint        Code;
441     uint        IpHlen;
442     uint        IpLen;
443     uint        IpCsum;
444     uint        TpCsum;
445     uint        TpHlen;
446 };
447
448 struct adapter {
449     void *ifp;
450     struct sliccard *card;
451     uint                port;
452     struct physcard *physcard;
453     uint                physport;
454     uint                cardindex;
455     uint                card_size;
456     uint                chipid;
457     struct net_device  *netdev;
458     struct net_device  *next_netdevice;
459     struct slic_spinlock     adapter_lock;
460     struct slic_spinlock     reset_lock;
461     struct pci_dev     *pcidev;
462     uint                busnumber;
463     uint                slotnumber;
464     uint                functionnumber;
465     ushort              vendid;
466     ushort              devid;
467     ushort              subsysid;
468     u32             irq;
469     void __iomem *memorybase;
470     u32             memorylength;
471     u32             drambase;
472     u32             dramlength;
473     uint                queues_initialized;
474     uint                allocated;
475     uint                activated;
476     u32             intrregistered;
477     uint                isp_initialized;
478     uint                gennumber;
479     u32             curaddrupper;
480     struct slic_shmem      *pshmem;
481     dma_addr_t          phys_shmem;
482     u32             isrcopy;
483     __iomem struct slic_regs       *slic_regs;
484     unsigned char               state;
485     unsigned char               linkstate;
486     unsigned char               linkspeed;
487     unsigned char               linkduplex;
488     uint                flags;
489     unsigned char               macaddr[6];
490     unsigned char               currmacaddr[6];
491     u32             macopts;
492     ushort              devflags_prev;
493     u64             mcastmask;
494     struct mcast_address   *mcastaddrs;
495     struct slic_upr   *upr_list;
496     uint                upr_busy;
497     struct timer_list   pingtimer;
498     u32             pingtimerset;
499     struct timer_list   statstimer;
500     u32             statstimerset;
501     struct timer_list   loadtimer;
502     u32             loadtimerset;
503     struct dentry      *debugfs_entry;
504     struct slic_spinlock     upr_lock;
505     struct slic_spinlock     bit64reglock;
506     struct slic_rspqueue     rspqueue;
507     struct slic_rcvqueue     rcvqueue;
508     struct slic_cmdqueue     cmdq_free;
509     struct slic_cmdqueue     cmdq_done;
510     struct slic_cmdqueue     cmdq_all;
511     struct slic_cmdqmem      cmdqmem;
512     /*
513      *  SLIC Handles
514     */
515     struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1]; /* Object handles*/
516     struct slic_handle *pfree_slic_handles;          /* Free object handles*/
517     struct slic_spinlock     handle_lock;           /* Object handle list lock*/
518     ushort              slic_handle_ix;
519
520     u32             xmitq_full;
521     u32             all_reg_writes;
522     u32             icr_reg_writes;
523     u32             isr_reg_writes;
524     u32             error_interrupts;
525     u32             error_rmiss_interrupts;
526     u32             rx_errors;
527     u32             rcv_drops;
528     u32             rcv_interrupts;
529     u32             xmit_interrupts;
530     u32             linkevent_interrupts;
531     u32             upr_interrupts;
532     u32             num_isrs;
533     u32             false_interrupts;
534     u32             tx_packets;
535     u32             xmit_completes;
536     u32             tx_drops;
537     u32             rcv_broadcasts;
538     u32             rcv_multicasts;
539     u32             rcv_unicasts;
540     u32             max_isr_rcvs;
541     u32             max_isr_xmits;
542     u32             rcv_interrupt_yields;
543     u32             intagg_period;
544     struct inicpm_state    *inicpm_info;
545     void *pinicpm_info;
546     struct slic_reg_params   reg_params;
547     struct slic_ifevents  if_events;
548     struct slic_stats        inicstats_prev;
549     struct slicnet_stats     slic_stats;
550     struct net_device_stats stats;
551 };
552
553 #if SLIC_DUMP_ENABLED
554 #define SLIC_DUMP_REQUESTED      1
555 #define SLIC_DUMP_IN_PROGRESS    2
556 #define SLIC_DUMP_DONE           3
557
558 /****************************************************************************
559  *
560  * Microcode crash information structure.  This
561  * structure is written out to the card's SRAM when the microcode panic's.
562  *
563  ****************************************************************************/
564 struct slic_crash_info {
565     ushort  cpu_id;
566     ushort  crash_pc;
567 };
568
569 #define CRASH_INFO_OFFSET   0x155C
570
571 #endif
572
573 #define UPDATE_STATS(largestat, newstat, oldstat)                        \
574 {                                                                        \
575     if ((newstat) < (oldstat))                                           \
576         (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1));         \
577     else                                                                 \
578         (largestat) += ((newstat) - (oldstat));                          \
579 }
580
581 #define UPDATE_STATS_GB(largestat, newstat, oldstat)                     \
582 {                                                                        \
583     (largestat) += ((newstat) - (oldstat));                              \
584 }
585
586 #define ETHER_EQ_ADDR(_AddrA, _AddrB, _Result)                           \
587 {                                                                        \
588     _Result = TRUE;                                                      \
589     if (*(u32 *)(_AddrA) != *(u32 *)(_AddrB))                          \
590         _Result = FALSE;                                                 \
591     if (*(u16 *)(&((_AddrA)[4])) != *(u16 *)(&((_AddrB)[4])))        \
592         _Result = FALSE;                                                 \
593 }
594
595 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
596 #define   SLIC_GET_ADDR_LOW(_addr)  (u32)((u64)(_addr) & \
597         0x00000000FFFFFFFF)
598 #define   SLIC_GET_ADDR_HIGH(_addr)  (u32)(((u64)(_addr) >> 32) & \
599         0x00000000FFFFFFFF)
600 #else
601 #define   SLIC_GET_ADDR_LOW(_addr)   (u32)_addr
602 #define   SLIC_GET_ADDR_HIGH(_addr)  (u32)0
603 #endif
604
605 #define FLUSH       TRUE
606 #define DONT_FLUSH  FALSE
607
608 #define SIOCSLICDUMPCARD         (SIOCDEVPRIVATE+9)
609 #define SIOCSLICSETINTAGG        (SIOCDEVPRIVATE+10)
610 #define SIOCSLICTRACEDUMP        (SIOCDEVPRIVATE+11)
611
612 #endif /*  __SLIC_DRIVER_H__ */