OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [s390/] [net/] [c7000.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
        Cisco/7000 driver -- Copyright (C) 2000 UTS Global LLC.
3
        Author: Bob Scardapane (UTS Global LLC).
4
        Version: 3.
5
 
6
        To use this driver, run the LINUX command:
7
 
8
        insmod c7000 base0=0xYYYY lhost0=s1 uhost0=s2 lappl0=s3 uappl0=s4 dbg=x
9
 
10
        base0=0xYYYY defines the base unit address of the interface.
11
        lhost0=s1 defines the local host name.
12
        uhost0=s2 defines the unit host name.
13
        lappl0=s3 defines the local application name.
14
        uappl0=s4 defines the unit application name.
15
        dbg=x defines the message level.  Higher values will result in
16
        additional diagnostic messages.
17
 
18
        Additional interfaces are defined on insmod by using the variable
19
        name groups "base1,lhost1,lappl1,uhost1,uappl1", etc... up to three
20
        additional groups.
21
 
22
        In addition, the module will automatically detect the unit base
23
        addresses by scanning all active irq's for a control unit type
24
        of 0x3088 and a model of 0x61 (CLAW mode). The noauto parameter
25
        can be used to suppress automatic detection.
26
 
27
        The values of lhostx, lapplx, uhostx and uapplx default to:
28
 
29
        lapplx - TCPIP
30
        lhostx - UTS
31
        uapplx - TCPIP
32
        uhostx - C7011
33
 
34
        Note that the values passed in the insmod command will always
35
        override the automatic detection of the unit base addreeses and
36
        the default values of lapplx, lhostx, uapplx and uhostx.
37
 
38
        The parameter noauto can be used to disable automatic detection of
39
        devices:
40
 
41
        noauto=1 (disable automatic detection)
42
        noauto=0 (Enable automatic detectio.  This is the default value.)
43
 
44
        The values in base0 - base3 will be copied to the bases array when
45
        the module is loaded.
46
 
47
        To configure the interface(s), run the LINUX command(s):
48
 
49
        ifconfig ci0 ...
50
        ifconfig ci1 ...
51
        ifconfig ci2 ...
52
        ifconfig ci3 ...
53
 
54
        There is one device structure for each controller in the c7000_devices
55
        array.  The base address of each controller is in the bases array.
56
        These arrays parallel each other.  There is also one c7000_controller
57
        structure for each controller.  This structure is pointed to by field
58
        priv in the individual device structure.
59
 
60
        In each c7000_controller, there are embedded c7000_unit structures.
61
        There is one c7000_unit structure per device number that makes up
62
        a controller (currently 2 units per controller).
63
*/
64
 
65
#include <linux/config.h>
66
#include <linux/module.h>
67
#include <linux/init.h>
68
#include <linux/kernel.h>
69
#include <linux/slab.h>
70
#include <linux/errno.h>
71
#include <linux/types.h>
72
#include <linux/interrupt.h>
73
#include <linux/timer.h>
74
#include <linux/sched.h>
75
#include <linux/signal.h>
76
#include <linux/string.h>
77
#include <linux/netdevice.h>
78
#include <linux/etherdevice.h>
79
#include <linux/if_arp.h>
80
#include <linux/tcp.h>
81
#include <linux/skbuff.h>
82
#include <asm/io.h>
83
#include <asm/bitops.h>
84
#include <asm/irq.h>
85
 
86
/*
87
        Global defines
88
*/
89
 
90
/*
91
        Maximum number of controllers.
92
*/
93
 
94
#define MAX_C7000       4
95
 
96
/*
97
        Number of units per controller.
98
*/
99
 
100
#define NUNITS          2
101
 
102
/*
103
        Define indexes of read and write units in the cunits array.
104
*/
105
 
106
#define C7000_RD        0
107
#define C7000_WR        1
108
 
109
/*
110
        Number of device buffers.
111
*/
112
 
113
#define C7000_MAXBUF    40
114
 
115
/*
116
        Transmission queue length.
117
*/
118
 
119
#define C7000_TXQUEUE_LEN       100
120
/*
121
        Size of the IP packet data.
122
*/
123
 
124
#define C7000_DATAL     4096
125
 
126
/*
127
        Size of the read header data.
128
*/
129
 
130
#define C7000_READHDRL  4
131
 
132
/*
133
        Size of read flag byte.
134
*/
135
 
136
#define C7000_READFFL   1
137
 
138
/*
139
        Size of a device buffer.  This is how it is arranged in memory:
140
        4096 (IP packet data) + 4 (read header) + 1 (read flag) = 4101.
141
*/
142
 
143
#define C7000_BUFSIZE   C7000_DATAL + C7000_READHDRL + C7000_READFFL
144
 
145
/*
146
        Size of sigsmod data.
147
*/
148
 
149
#define C7000_SIGSMODL  1
150
 
151
/*
152
        Flag value that indicates a read was completed in the flag
153
        field of a c7000_rd_header.
154
*/
155
 
156
#define FLAG_FF         0xff
157
/*
158
        Size of C7000 sense id data.
159
*/
160
 
161
#define SIDL            32
162
 
163
/*
164
        Maximum number of read and write retries.
165
*/
166
 
167
#define C7000_MAX_RETRIES       3
168
 
169
/*
170
        Define sense byte0 value for a box reset.
171
*/
172
 
173
#define C7000_BOX_RESET         0x41
174
 
175
/*
176
        CCW commands.
177
*/
178
 
179
#define C7000_WRITE_CCW         0x01    /* normal write */
180
#define C7000_READ_CCW          0x02    /* normal read */
181
#define C7000_NOOP_CCW          0x03    /* no operation */
182
#define C7000_SIGSMOD_CCW       0x05    /* signal status modifier */
183
#define C7000_TIC_CCW           0x08    /* transfer in channel */
184
#define C7000_READHDR_CCW       0x12    /* read header  */
185
#define C7000_READFF_CCW        0x22    /* read FF flag */
186
#define C7000_SID_CCW           0xe4    /* sense identification */
187
 
188
/*
189
        Control commands.
190
*/
191
 
192
#define C7000_SYS_VALIDATE              1
193
#define C7000_SYS_VALIDATE_RESP         2
194
#define C7000_CONN_REQ                  33
195
#define C7000_CONN_RESP                 34
196
#define C7000_CONN_CONFRM               35
197
#define C7000_DISCONN                   36
198
#define C7000_BOXERROR                  65
199
 
200
/*
201
        State machine values.
202
*/
203
 
204
#define C7000_INIT      1
205
#define C7000_HALT      2
206
#define C7000_SID       3
207
#define C7000_SYSVAL    4
208
#define C7000_CONNECT   5
209
#define C7000_READY     6
210
#define C7000_READ      7
211
#define C7000_WRITE     8
212
#define C7000_DISC      9
213
#define C7000_STOP      10
214
#define C7000_STOPPED   11
215
#define C7000_ERROR     12
216
 
217
/*
218
        The lower subchannel is used for read operations and the one that is
219
        one higher is used for write operations.
220
 
221
        Both subchannels are initially in state C7000_INIT.  A transition to
222
        state C7000_HALT occurs when halt_IO is issued on each.  When the
223
        halts completes a transition to state C7000_SID occurs and a channel
224
        program is issued to do a sense identification on both subchannels.
225
 
226
        When the sense identification completes, the state C7000_SYSVAL is
227
        entered on the read subchannel.  A read channel program is issued.
228
 
229
        When the sense identification completes, the write subchannel enters
230
        state C7000_SYSVAL and a system validation request is written.  The
231
        read subchannel is also put into this state.
232
 
233
        When both the system validation response is read and an inbound system
234
        validation request is read, the inbound system validation request is
235
        responded to and both subchannels enter the C7000_CONNECT state.
236
 
237
        A read channel program is posted to look for the inbound connect
238
        request.  When that is received a connection confirmation is written.
239
        The state of both subchannels is then changed to C7000_READY.  A
240
        read channel program is then posted and the state is changed to
241
        C7000_READ.  When a read completes, the packet is sent to the higher
242
        layers and the read channel program is restarted.
243
 
244
        When there is a packet to be written, state C7000_WRITE is entered
245
        and a channel program is issued to write the data.  The subchannel
246
        is in state C7000_READY when there is nothing to be written.
247
 
248
        When the stop method is executed, a disconnect message is sent and
249
        the state is changed to C7000_DISC in both subchannels.  A halt_IO
250
        will be issued to both subchannels and state C7000_STOP will be entered.
251
        When the halt IO completes, state C7000_STOPPED will be set.
252
 
253
        State C7000_ERROR is set when an error occurs in the interrupt
254
        routine.  Recycle the interface (ifconfig down / ifconfig up)
255
        to reset this state.
256
*/
257
 
258
/*
259
        Results from c7000_check_csw.
260
*/
261
 
262
enum    c7000_rupt {
263
        C7000_NORMAL,
264
        C7000_CHANERR,
265
        C7000_UCK,
266
        C7000_UCK_RESET,
267
        C7000_UE,
268
        C7000_ATTN,
269
        C7000_BUSY,
270
        C7000_OTHER
271
};
272
 
273
/*
274
        Bits set in device structure tbusy field.
275
*/
276
 
277
#define TB_TX           0        /* sk buffer handling in progress */
278
#define TB_STOP         1       /* network device stop in progress */
279
#define TB_RETRY        2       /* retry in progress */
280
#define TB_NOBUFFER     3       /* no buffer on free queue */
281
 
282
/*
283
        Bit in c7000_unit.flag_a that indicates the bh routine is busy.
284
*/
285
 
286
#define C7000_BH_ACTIVE 0
287
 
288
#define CPrintk(level, args...) \
289
        if (level <= dbg) \
290
                printk(args)
291
 
292
/*
293
        Maximum length of a system validation string.
294
*/
295
 
296
#define NAMLEN  8
297
 
298
#define Err_Conn_Confirm        1
299
#define Err_Names_not_Matched   166
300
#define Err_C7000_NOT_READY     167
301
#define Err_Duplicate           170
302
#define Err_Closing             171
303
#define Err_No_Such_App         172
304
#define Err_Host_Not_Ready      173
305
#define Err_CLOSING             174
306
#define Err_Dup_Link            175
307
#define Err_Wrong_Version       179
308
#define Err_Wrong_Frame_Size    180
309
 
310
/*
311
        Define a macro to extract the logical link identifier from
312
        the c7000 read header command field.
313
*/
314
 
315
#define C7000_LINKID(cmd)       ((unsigned char)cmd >> 3)
316
 
317
/*
318
        Define the control unit type for a Cisco 7000.
319
*/
320
 
321
#define C7000_CU_TYPE           0x3088
322
 
323
/*
324
        Define the control unit model for a Cisco 7000.
325
*/
326
 
327
#define C7000_CU_MODEL          0x61
328
 
329
/*
330
        Define the default system validate parameters (lapplx,
331
        lhostx, uapplx, uhostx).
332
*/
333
 
334
#define C7000_DFLT_LAPPL        "TCPIP"
335
#define C7000_DFLT_LHOST        "UTS"
336
#define C7000_DFLT_UAPPL        "TCPIP"
337
#define C7000_DFLT_UHOST        "C7011"
338
 
339
/*
340
        Global variables.
341
*/
342
 
343
/*
344
        Base device addresses of the controllers.
345
*/
346
 
347
static int      base0 = -1;
348
static int      base1 = -1;
349
static int      base2 = -1;
350
static int      base3 = -1;
351
 
352
static int      bases[MAX_C7000];
353
 
354
/*
355
        Local application names.
356
*/
357
 
358
static char     *lappl0;
359
static char     *lappl1;
360
static char     *lappl2;
361
static char     *lappl3;
362
 
363
/*
364
        Local host names.
365
*/
366
 
367
static char     *lhost0;
368
static char     *lhost1;
369
static char     *lhost2;
370
static char     *lhost3;
371
 
372
/*
373
        Unit application names.
374
*/
375
 
376
static char     *uappl0;
377
static char     *uappl1;
378
static char     *uappl2;
379
static char     *uappl3;
380
 
381
/*
382
        Unit hosts names.
383
*/
384
 
385
static char     *uhost0;
386
static char     *uhost1;
387
static char     *uhost2;
388
static char     *uhost3;
389
 
390
/*
391
        Debugging level (higher numbers emit lower priority messages).
392
*/
393
 
394
static unsigned int     dbg = 0;
395
 
396
/*
397
        Parameter that controls auto detection.
398
*/
399
 
400
static int      noauto = 0;
401
 
402
/*
403
        Interface names.
404
*/
405
 
406
static char     ifnames[MAX_C7000][8] = {"ci0", "ci1", "ci2", "ci3"};
407
 
408
/*
409
        One device structure per controller.
410
*/
411
 
412
/* RBH Try out the new code for 2.4.0 */
413
#define NEWSTUFF
414
 
415
#ifdef NEWSTUFF
416
#define STRUCT_NET_DEVICE struct net_device
417
#else
418
#define STRUCT_NET_DEVICE struct device
419
#endif
420
 
421
STRUCT_NET_DEVICE       c7000_devices[MAX_C7000];
422
 
423
/*
424
        Scratch variable filled in with controller name.
425
*/
426
 
427
static char     *controller;
428
 
429
/*
430
        Identify parameters that can be passed on the LINUX insmod command.
431
*/
432
 
433
MODULE_AUTHOR("Robert Scardapane (UTS Global)");
434
MODULE_DESCRIPTION("Network module for Cisco 7000 box.");
435
 
436
MODULE_PARM(base0, "1i");
437
MODULE_PARM_DESC(base0, "Base unit address for 1st C7000 box.");
438
MODULE_PARM(base1, "1i");
439
MODULE_PARM_DESC(base1, "Base unit address for 2nd C7000 box.");
440
MODULE_PARM(base2, "1i");
441
MODULE_PARM_DESC(base2, "Base unit address for 3rd C7000 box.");
442
MODULE_PARM(base3, "1i");
443
MODULE_PARM_DESC(base3, "Base unit address for 4th C7000 box.");
444
 
445
MODULE_PARM(lappl0, "s");
446
MODULE_PARM_DESC(lappl0, "Application name for 1st C7000 box.");
447
MODULE_PARM(lappl1, "s");
448
MODULE_PARM_DESC(lappl1, "Application name for 2nd C7000 box.");
449
MODULE_PARM(lappl2, "s");
450
MODULE_PARM_DESC(lappl2, "Application name for 3rd C7000 box.");
451
MODULE_PARM(lappl3, "s");
452
MODULE_PARM_DESC(lappl3, "Application name for 4th C7000 box.");
453
 
454
MODULE_PARM(lhost0, "s");
455
MODULE_PARM_DESC(lhost0, "Host name for 1st C7000 box.");
456
MODULE_PARM(lhost1, "s");
457
MODULE_PARM_DESC(lhost1, "Host name for 2nd C7000 box.");
458
MODULE_PARM(lhost2, "s");
459
MODULE_PARM_DESC(lhost2, "Host name for 3rd C7000 box.");
460
MODULE_PARM(lhost3, "s");
461
MODULE_PARM_DESC(lhost3, "Host name for 4th C7000 box.");
462
 
463
MODULE_PARM(uhost0, "s");
464
MODULE_PARM_DESC(uhost0, "Unit name for 1st C7000 box.");
465
MODULE_PARM(uhost1, "s");
466
MODULE_PARM_DESC(uhost1, "Unit name for 2nd C7000 box.");
467
MODULE_PARM(uhost2, "s");
468
MODULE_PARM_DESC(uhost2, "Unit name for 3rd C7000 box.");
469
MODULE_PARM(uhost3, "s");
470
MODULE_PARM_DESC(uhost3, "Unit name for 4th C7000 box.");
471
 
472
MODULE_PARM(uappl0, "s");
473
MODULE_PARM_DESC(uappl0, "Unit application name for 1st C7000 box.");
474
MODULE_PARM(uappl1, "s");
475
MODULE_PARM_DESC(uappl1, "Unit application name for 2nd C7000 box.");
476
MODULE_PARM(uappl2, "s");
477
MODULE_PARM_DESC(uappl2, "Unit application name for 3rd C7000 box.");
478
MODULE_PARM(uappl3, "s");
479
MODULE_PARM_DESC(uappl3, "Unit application name for 4th C7000 box.");
480
 
481
MODULE_PARM(dbg, "1i");
482
MODULE_PARM_DESC(dbg, "Message level for debugging.");
483
 
484
MODULE_PARM(noauto, "1i");
485
MODULE_PARM_DESC(noauto, "Control automatic detection of unit base addresses.");
486
 
487
/*
488
        Structure used to manage unit buffers.
489
*/
490
 
491
struct  c7000_buffer {
492
        ccw1_t                  ccws[7];        /* channel program */
493
        struct  c7000_buffer    *next;          /* list pointer */
494
        char                    *data;          /* pointer to actual data */
495
        int                     len;            /* length of the data */
496
};
497
 
498
/*
499
        C7000 Control Block.
500
 */
501
 
502
struct  c7000_control_blk {
503
        unsigned char   cmd;
504
        unsigned char   ver;
505
        unsigned char   link_id;
506
        unsigned char   correlator;
507
        unsigned char   ret_code;
508
        unsigned char   resvd1[3];
509
        unsigned char   unitname[NAMLEN];
510
        unsigned char   hostname[NAMLEN];
511
        unsigned short  rdsize;         /* read frame size   */
512
        unsigned short  wrtsize;        /* write frame size  */
513
        unsigned char   resvd2[4];
514
};
515
 
516
/*
517
        Per unit structure contained within the c7000_controller structure.
518
*/
519
 
520
struct  c7000_unit {
521
        ccw1_t                          ccws[5];        /* control ccws */
522
        int                             devno;          /* device number */
523
        int                             irq;            /* subchannel number */
524
        int                             IO_active;      /* IO activity flag */
525
        int                             state;          /* fsm state */
526
        int                             retries;        /* retry counter */
527
        unsigned long                   flag_a;         /* bh activity flag */
528
        devstat_t                       devstat;        /* device status */
529
#ifdef NEWSTUFF
530
        wait_queue_head_t               wait;           /* sleep q head */
531
#else
532
        struct wait_queue               *wait;          /* sleep q pointer */
533
#endif
534
        struct c7000_controller         *cntlp;         /* controller pointer */
535
        struct c7000_buffer             *free;          /* free buffer anchor */
536
        struct c7000_buffer             *proc_head;     /* proc head */
537
        struct c7000_buffer             *proc_tail;     /* proc tail */
538
        struct c7000_buffer             *bh_head;       /* bh head */
539
        struct c7000_buffer             *bh_tail;       /* bh tail */
540
        struct tq_struct                tq;             /* bh scheduling */
541
        char                            senseid[SIDL];  /* sense id data */
542
        struct c7000_control_blk        control_blk;    /* control block */
543
        unsigned char                   sigsmod;        /* sigsmod flag */
544
        unsigned char                   readhdr[4];     /* read header */
545
        unsigned char                   readff;         /* readff flag */
546
};
547
 
548
/*
549
        Private structure pointed to by dev->priv.
550
*/
551
 
552
struct c7000_controller {
553
        struct  net_device_stats        stats;          /* statistics */
554
        STRUCT_NET_DEVICE               *dev;           /* -> device struct */
555
        unsigned int                    base_addr;      /* base address */
556
        char                            lappl[NAMLEN];  /* local appl */
557
        char                            lhost[NAMLEN];  /* local host */
558
        char                            uappl[NAMLEN];  /* unit appl */
559
        char                            uhost[NAMLEN];  /* unit host */
560
        unsigned char                   version;        /* version = 2 */
561
        unsigned char                   linkid;         /* link id */
562
        struct  c7000_unit              cunits[NUNITS]; /* embedded units */
563
#ifdef NEWSTUFF
564
        int                             tbusy;
565
#endif
566
};
567
 
568
/*
569
        This is the structure returned by the C7000_READHDR_CCW.
570
*/
571
 
572
struct  c7000_rd_header {
573
        unsigned short  len;    /* packet length */
574
        unsigned char   cmd;    /* command code */
575
        unsigned char   flag;   /* flag */
576
};
577
 
578
/*
579
        Set the device structure transmission busy flag.
580
*/
581
 
582
#ifdef NEWSTUFF
583
#define c7000_set_busy(dev) netif_stop_queue(dev)
584
#else
585
static __inline__ void
586
c7000_set_busy(STRUCT_NET_DEVICE *dev)
587
{
588
        dev->tbusy = 1;
589
        eieio();
590
        return;
591
}
592
#endif
593
 
594
/*
595
        Clear the device structure transmission busy flag.
596
*/
597
 
598
#ifdef NEWSTUFF
599
#define c7000_clear_busy(dev) netif_wake_queue(dev)
600
#else
601
static __inline__ void
602
c7000_clear_busy(STRUCT_NET_DEVICE *dev)
603
{
604
        dev->tbusy = 0;
605
        eieio();
606
        return;
607
}
608
#endif
609
 
610
/*
611
        Extract the device structure transmission busy flag.
612
*/
613
 
614
#ifdef NEWSTUFF
615
#define c7000_check_busy(dev) netif_queue_stopped(dev)
616
#else
617
static __inline__ int
618
c7000_check_busy(STRUCT_NET_DEVICE *dev)
619
{
620
        eieio();
621
        return(dev->tbusy);
622
}
623
#endif
624
 
625
/*
626
        Set a bit in the device structure transmission busy flag.
627
*/
628
 
629
static __inline__ void
630
c7000_setbit_busy(int nr, STRUCT_NET_DEVICE *dev)
631
{
632
#ifdef NEWSTUFF
633
        netif_stop_queue(dev);
634
        test_and_set_bit(nr, &((struct c7000_controller *)dev->priv)->tbusy);
635
#else
636
        set_bit(nr, (void *)&dev->tbusy);
637
#endif
638
        return;
639
}
640
 
641
/*
642
        Clear a bit in the device structure transmission busy flag.
643
*/
644
 
645
static __inline__ void
646
c7000_clearbit_busy(int nr, STRUCT_NET_DEVICE *dev)
647
{
648
#ifdef NEWSTUFF
649
        clear_bit(nr, &((struct c7000_controller *)dev->priv)->tbusy);
650
        netif_wake_queue(dev);
651
#else
652
        clear_bit(nr, (void *)&dev->tbusy);
653
#endif
654
        return;
655
}
656
 
657
/*
658
        Test and set a bit in the device structure transmission busy flag.
659
*/
660
 
661
static __inline__ int
662
c7000_ts_busy(int nr, STRUCT_NET_DEVICE *dev)
663
{
664
#ifdef NEWSTUFF
665
        netif_stop_queue(dev);
666
        return test_and_set_bit(nr, &((struct c7000_controller *)dev->priv)->tbusy);
667
#else
668
        return(test_and_set_bit(nr, (void *)&dev->tbusy));
669
#endif
670
}
671
 
672
/*
673
        Set the C7000 controller in the error state.
674
*/
675
 
676
static void
677
c7000_error(struct c7000_controller *ccp)
678
{
679
        int                     i;
680
        struct  c7000_unit      *cup;
681
        STRUCT_NET_DEVICE       *dev = ccp->dev;
682
 
683
        for (i = 0; i < NUNITS; i++) {
684
                cup = &ccp->cunits[i];
685
                cup->state = C7000_ERROR;
686
        }
687
 
688
        if (dev != NULL)
689
#ifdef NEWSTUFF
690
                /* RBH XXX Should we be doing this? */
691
                dev->state &= ~__LINK_STATE_START;
692
#else
693
                dev->flags &= ~IFF_RUNNING;
694
#endif
695
 
696
        CPrintk(0, "c7000: c7000_error: base unit 0x%x is down\n", ccp->base_addr);
697
        return;
698
}
699
 
700
/*
701
        Based on the SENSE ID information, fill in the
702
        controller name.  Note that this is the SENSE ID
703
        information saved by LINUX/390 at boot time.
704
*/
705
 
706
static int
707
c7000_check_type(senseid_t *id)
708
{
709
 
710
        switch (id->cu_type) {
711
 
712
                case C7000_CU_TYPE:
713
 
714
                        if (id->cu_model == C7000_CU_MODEL) {
715
                                controller = "C7000  ";
716
                                return(0);
717
                        }
718
 
719
                        break;
720
 
721
                default:
722
                        break;
723
        }
724
 
725
        return(-1);
726
}
727
 
728
/*
729
        Check the device information for the controller.
730
*/
731
 
732
static int
733
c7000_check_devices(int devno)
734
{
735
        int             i;
736
        s390_dev_info_t temp;
737
 
738
        /*
739
                Get the SENSE ID information for each device.
740
        */
741
 
742
        for (i = devno; i < (devno + NUNITS); i++) {
743
 
744
                if (get_dev_info_by_devno(devno, &temp) != 0)
745
                        return(-1);
746
 
747
                if (c7000_check_type(&temp.sid_data) == -1)
748
                        return(-1);
749
        }
750
 
751
        CPrintk(1, "c7000: c7000_check_devices: device type is %s\n", controller);
752
        return(0);
753
}
754
 
755
/*
756
        Issue a halt I/O to device pointed to by cup.
757
*/
758
 
759
static int
760
c7000_haltio(struct c7000_unit *cup)
761
{
762
        __u32                   parm;
763
        __u8                    flags = 0x00;
764
        __u32                   saveflags;
765
        DECLARE_WAITQUEUE(wait, current);
766
        int                     rc;
767
 
768
        s390irq_spin_lock_irqsave(cup->irq, saveflags);
769
        parm = (unsigned long)cup;
770
 
771
        if ((rc = halt_IO(cup->irq, parm, flags)) != 0) {
772
                s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
773
                return(rc);
774
        }
775
 
776
        /*
777
                Wait for the halt I/O to finish.
778
        */
779
 
780
        add_wait_queue(&cup->wait, &wait);
781
        current->state = TASK_UNINTERRUPTIBLE;
782
        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
783
        schedule();
784
        remove_wait_queue(&cup->wait, &wait);
785
        return(0);
786
}
787
 
788
/*
789
        Issue a start I/O to device pointed to by cup.
790
*/
791
 
792
static int
793
c7000_doio(struct c7000_unit *cup)
794
{
795
        __u32                   parm;
796
        __u8                    flags = 0x00;
797
        __u32                   saveflags;
798
        DECLARE_WAITQUEUE(wait, current);
799
        int                     rc;
800
 
801
        /*
802
                Do no further I/O while the device is in the ERROR, STOP
803
                or STOPPED state.
804
        */
805
 
806
        if (cup->state == C7000_ERROR || cup->state == C7000_STOP || cup->state == C7000_STOPPED)
807
                return(-1);
808
 
809
        s390irq_spin_lock_irqsave(cup->irq, saveflags);
810
        parm = (unsigned long)cup;
811
 
812
        if ((rc = do_IO(cup->irq, &cup->ccws[0], parm, 0xff, flags)) != 0) {
813
                s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
814
                return(rc);
815
        }
816
 
817
        /*
818
                Wait for the I/O to complete.
819
        */
820
 
821
        add_wait_queue(&cup->wait, &wait);
822
        current->state = TASK_UNINTERRUPTIBLE;
823
        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
824
        schedule();
825
        remove_wait_queue(&cup->wait, &wait);
826
 
827
        /*
828
                Interrupt handling may have marked the device in ERROR.
829
        */
830
 
831
        if (cup->state == C7000_ERROR)
832
                return(-1);
833
 
834
        return(0);
835
}
836
 
837
/*
838
        Build a channel program to do a sense id channel program.
839
*/
840
 
841
static void
842
c7000_bld_senseid_chpgm(struct c7000_unit *cup)
843
{
844
        ccw1_t  *ccwp;
845
 
846
        ccwp = &cup->ccws[0];
847
        ccwp->cmd_code = C7000_SID_CCW;
848
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
849
        ccwp->cda = (__u32)virt_to_phys(&cup->senseid);
850
        ccwp->count = SIDL;
851
        ccwp++;
852
        ccwp->cmd_code = C7000_NOOP_CCW;
853
        ccwp->flags = CCW_FLAG_SLI;
854
        ccwp->cda = (__u32)NULL;
855
        ccwp->count = 1;
856
        return;
857
}
858
 
859
/*
860
        Build a channel program to write a control message.
861
*/
862
 
863
static void
864
c7000_bld_wrtctl_chpgm(struct c7000_unit *cup)
865
{
866
        ccw1_t  *ccwp;
867
 
868
        ccwp = &cup->ccws[0];
869
        ccwp->cmd_code = C7000_WRITE_CCW;
870
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
871
        ccwp->cda = (__u32)virt_to_phys(&cup->control_blk);
872
        ccwp->count = sizeof(struct c7000_control_blk);
873
        ccwp++;
874
        ccwp->cmd_code = C7000_READFF_CCW;
875
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
876
        ccwp->cda = (__u32)virt_to_phys(&cup->readff);
877
        ccwp->count = C7000_READFFL;
878
        ccwp++;
879
        ccwp->cmd_code = C7000_TIC_CCW;
880
        ccwp->flags = 0;
881
        ccwp->cda = (__u32)virt_to_phys(ccwp + 1);
882
        ccwp->count = 0;
883
        ccwp++;
884
        ccwp->cmd_code = C7000_NOOP_CCW;
885
        ccwp->flags = CCW_FLAG_SLI;
886
        ccwp->cda = (__u32)NULL;
887
        ccwp->count = 1;
888
        return;
889
}
890
 
891
/*
892
        Build a write channel program to write the indicated buffer.
893
*/
894
 
895
static void
896
c7000_bld_wrt_chpgm(struct c7000_unit *cup, struct c7000_buffer *buf)
897
{
898
        ccw1_t                          *ccwp;
899
        struct  c7000_controller        *ccp = cup->cntlp;
900
 
901
        ccwp = &buf->ccws[0];
902
        ccwp->cmd_code = C7000_WRITE_CCW | (ccp->linkid << 3);
903
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
904
        ccwp->cda = (__u32)virt_to_phys(buf->data);
905
        ccwp->count = buf->len;
906
        ccwp++;
907
        ccwp->cmd_code = C7000_READFF_CCW;
908
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
909
        ccwp->cda = (__u32)virt_to_phys(buf->data + C7000_DATAL + C7000_READHDRL);
910
        ccwp->count = C7000_READFFL;
911
        ccwp++;
912
        ccwp->cmd_code = C7000_TIC_CCW;
913
        ccwp->flags = 0;
914
        ccwp->cda = (__u32)virt_to_phys(ccwp + 1);
915
        ccwp->count = 0;
916
        ccwp++;
917
        ccwp->cmd_code = C7000_NOOP_CCW;
918
        ccwp->flags = (CCW_FLAG_SLI);
919
        ccwp->cda = (__u32)NULL;
920
        ccwp->count = 1;
921
        return;
922
}
923
 
924
/*
925
        Build a channel program to read a control message.
926
*/
927
 
928
static void
929
c7000_bld_readctl_chpgm(struct c7000_unit *cup)
930
{
931
        ccw1_t  *ccwp;
932
 
933
        ccwp = &cup->ccws[0];
934
        ccwp->cmd_code = C7000_READ_CCW;
935
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
936
        ccwp->cda = (__u32)virt_to_phys(&cup->control_blk);
937
        ccwp->count = sizeof(struct c7000_control_blk);
938
        ccwp++;
939
        ccwp->cmd_code = C7000_READHDR_CCW;
940
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
941
        ccwp->cda = (__u32)virt_to_phys(&cup->readhdr);
942
        ccwp->count = C7000_READHDRL;
943
        ccwp++;
944
        ccwp->cmd_code = C7000_SIGSMOD_CCW;
945
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
946
        ccwp->cda = (__u32)virt_to_phys(&cup->sigsmod);
947
        ccwp->count = C7000_SIGSMODL;
948
        ccwp++;
949
        ccwp->cmd_code = C7000_TIC_CCW;
950
        ccwp->flags = 0;
951
        ccwp->cda = (__u32)virt_to_phys(ccwp + 1);
952
        ccwp->count = 0;
953
        ccwp++;
954
        ccwp->cmd_code = C7000_NOOP_CCW;
955
        ccwp->flags = (CCW_FLAG_SLI);
956
        ccwp->cda = (__u32)NULL;
957
        ccwp->count = 1;
958
        return;
959
}
960
 
961
/*
962
        Build a channel program to read the indicated buffer.
963
*/
964
 
965
static void
966
c7000_bld_read_chpgm(struct c7000_unit *cup, struct c7000_buffer *buf)
967
{
968
        ccw1_t  *ccwp;
969
 
970
        ccwp = &buf->ccws[0];
971
        ccwp->cmd_code = C7000_READ_CCW;
972
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
973
        ccwp->cda = (__u32)virt_to_phys(buf->data);
974
        ccwp->count = C7000_DATAL;
975
        ccwp++;
976
        ccwp->cmd_code = C7000_READHDR_CCW;
977
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
978
        ccwp->cda = (__u32)virt_to_phys(buf->data + C7000_DATAL);
979
        ccwp->count = C7000_READHDRL;
980
        ccwp++;
981
        ccwp->cmd_code = C7000_SIGSMOD_CCW;
982
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC);
983
        ccwp->cda = (__u32)virt_to_phys(&cup->sigsmod);
984
        ccwp->count = C7000_SIGSMODL;
985
        ccwp++;
986
        ccwp->cmd_code = C7000_TIC_CCW;
987
        ccwp->flags = 0;
988
        ccwp->cda = (__u32)virt_to_phys(ccwp + 3);
989
        ccwp->count = 0;
990
        ccwp++;
991
        ccwp->cmd_code = C7000_READFF_CCW;
992
        ccwp->flags = (CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI);
993
        ccwp->cda = (__u32)virt_to_phys(&cup->readff);
994
        ccwp->count = C7000_READFFL;
995
        ccwp++;
996
        ccwp->cmd_code = C7000_TIC_CCW;
997
        ccwp->flags = 0;
998
        ccwp->cda = (__u32)virt_to_phys(ccwp + 1);
999
        ccwp->count = 0;
1000
        ccwp++;
1001
        ccwp->cmd_code = C7000_NOOP_CCW;
1002
        ccwp->flags = (CCW_FLAG_SLI);
1003
        ccwp->cda = (__u32)NULL;
1004
        ccwp->count = 1;
1005
        return;
1006
}
1007
 
1008
/*
1009
        Allocate buffer structure headers and buffers for all units
1010
        A return value of 0 means that all allocations worked.  A -1
1011
        means that an allocation failed.  It is expected that the caller
1012
        will call c7000_free_buffers when -1 is returned.
1013
*/
1014
 
1015
static int
1016
c7000_alloc_buffers(STRUCT_NET_DEVICE *dev)
1017
{
1018
        int                             i;
1019
        int                             j;
1020
        char                            *data;
1021
        struct  c7000_buffer            *bufptr;
1022
        struct  c7000_controller        *ccp = (struct c7000_controller *) dev->priv;
1023
        struct  c7000_unit              *cup;
1024
 
1025
        for (i = 0; i < NUNITS; i++) {
1026
                cup = &ccp->cunits[i];
1027
                cup->free = NULL;
1028
 
1029
                for (j = 0; j < C7000_MAXBUF; j++) {
1030
                        bufptr = kmalloc(sizeof(struct c7000_buffer), GFP_KERNEL);
1031
                        data = kmalloc(C7000_BUFSIZE, GFP_KERNEL);
1032
 
1033
                        if (bufptr == NULL)
1034
                        {
1035
                                if(data)
1036
                                        kfree(data);
1037
                                return(-1);
1038
                        }
1039
 
1040
                        /*
1041
                                Place filled in buffer header on free anchor.
1042
                        */
1043
 
1044
                        bufptr->next = cup->free;
1045
                        bufptr->data = data;
1046
                        bufptr->len = 0;
1047
                        cup->free = bufptr;
1048
 
1049
                        if (data == NULL)
1050
                                return(-1);
1051
 
1052
                        memset(data, '\0', C7000_BUFSIZE);
1053
                }
1054
 
1055
        }
1056
 
1057
        CPrintk(1, "c7000: c7000_alloc_buffers: allocated buffers for base unit 0x%lx\n", dev->base_addr);
1058
        return(0);
1059
}
1060
 
1061
/*
1062
        Free buffers on a chain.
1063
*/
1064
 
1065
static void
1066
c7000_free_chain(struct c7000_buffer *buf)
1067
{
1068
        char                    *data;
1069
        struct  c7000_buffer    *bufptr = buf;
1070
        struct  c7000_buffer    *tmp;
1071
 
1072
        while (bufptr != NULL) {
1073
                data = bufptr->data;
1074
 
1075
                if (data != NULL)
1076
                        kfree(data);
1077
 
1078
                tmp = bufptr;
1079
                bufptr = bufptr->next;
1080
                kfree(tmp);
1081
        }
1082
 
1083
        return;
1084
}
1085
 
1086
/*
1087
        Free buffers on all possible chains for all units.
1088
*/
1089
 
1090
static void
1091
c7000_free_buffers(STRUCT_NET_DEVICE *dev)
1092
{
1093
        int                             i;
1094
        struct  c7000_controller        *ccp = (struct c7000_controller *) dev->priv;
1095
        struct  c7000_unit      *cup;
1096
 
1097
        for (i = 0; i < NUNITS; i++) {
1098
                cup = &ccp->cunits[i];
1099
                c7000_free_chain(cup->free);
1100
                cup->free = NULL;
1101
                c7000_free_chain(cup->proc_head);
1102
                cup->proc_head = cup->proc_tail = NULL;
1103
                c7000_free_chain(cup->bh_head);
1104
                cup->bh_head = cup->bh_tail = NULL;
1105
        }
1106
 
1107
        CPrintk(1, "c7000: c7000_free_buffers: freed buffers for base unit 0x%lx\n", dev->base_addr);
1108
        return;
1109
}
1110
 
1111
/*
1112
        Obtain a free buffer.  Return a pointer to the c7000_buffer
1113
        structure OR NULL.
1114
*/
1115
 
1116
struct c7000_buffer *
1117
c7000_get_buffer(struct c7000_unit *cup)
1118
{
1119
        struct  c7000_buffer    *buf;
1120
 
1121
        buf = cup->free;
1122
 
1123
        if (buf == NULL)
1124
                return(NULL);
1125
 
1126
        cup->free = buf->next;
1127
        buf->next = NULL;
1128
        return(buf);
1129
}
1130
 
1131
/*
1132
        Release a buffer to the free list.
1133
*/
1134
 
1135
void
1136
c7000_release_buffer(struct c7000_unit *cup, struct c7000_buffer *buf)
1137
{
1138
        struct  c7000_buffer    *tmp;
1139
 
1140
        tmp = cup->free;
1141
        cup->free = buf;
1142
        buf->next = tmp;
1143
        return;
1144
}
1145
 
1146
/*
1147
        Queue a buffer on the end of the processing (proc) chain.
1148
*/
1149
 
1150
void
1151
c7000_queue_buffer(struct c7000_unit *cup, struct c7000_buffer *buf)
1152
{
1153
        buf->next = NULL;
1154
 
1155
        if (cup->proc_head == NULL) {
1156
                cup->proc_head = cup->proc_tail = buf;
1157
                return;
1158
        }
1159
 
1160
        cup->proc_tail->next = buf;
1161
        cup->proc_tail = buf;
1162
        return;
1163
}
1164
 
1165
/*
1166
        Dequeue a buffer from the start of the processing (proc) chain.
1167
*/
1168
 
1169
struct c7000_buffer *
1170
c7000_dequeue_buffer(struct c7000_unit *cup)
1171
{
1172
        struct  c7000_buffer    *buf = cup->proc_head;
1173
 
1174
        if (buf == NULL)
1175
                return(NULL);
1176
 
1177
        cup->proc_head = buf->next;
1178
 
1179
        if (cup->proc_head == NULL)
1180
                cup->proc_tail = NULL;
1181
 
1182
        buf->next = NULL;
1183
        return(buf);
1184
}
1185
 
1186
/*
1187
        Queue a buffer on the end of the bh routine chain.
1188
*/
1189
 
1190
void
1191
c7000_queue_bh_buffer(struct c7000_unit *cup, struct c7000_buffer *buf)
1192
{
1193
        buf->next = NULL;
1194
 
1195
        if (cup->bh_head == NULL) {
1196
                cup->bh_head = cup->bh_tail = buf;
1197
                return;
1198
        }
1199
 
1200
        cup->bh_tail->next = buf;
1201
        cup->bh_tail = buf;
1202
        return;
1203
}
1204
 
1205
/*
1206
        Dequeue a buffer from the start of the bh routine chain.
1207
*/
1208
 
1209
struct c7000_buffer *
1210
c7000_dequeue_bh_buffer(struct c7000_unit *cup)
1211
{
1212
        struct  c7000_buffer    *buf = cup->bh_head;
1213
 
1214
        if (buf == NULL)
1215
                return(NULL);
1216
 
1217
        cup->bh_head = buf->next;
1218
 
1219
        if (cup->bh_head == NULL)
1220
                cup->bh_tail = NULL;
1221
 
1222
        buf->next = NULL;
1223
        return(buf);
1224
}
1225
 
1226
/*
1227
        Build up a list of buffers to read.  Each buffer is described
1228
        by one c7000_buffer structure.  The c7000_buffer structure
1229
        contains a channel segment that will read that one buffer.
1230
        The channel program segments are chained together via TIC
1231
        CCWS.
1232
*/
1233
 
1234
static int
1235
c7000_bld_read_chain(struct c7000_unit *cup)
1236
{
1237
        struct  c7000_buffer    *buf, *pbuf = NULL;
1238
        struct  c7000_rd_header *head;
1239
        int                     num = 0;
1240
 
1241
        while (cup->free != NULL) {
1242
 
1243
                /*
1244
                        Obtain a buffer for a read channel segment.
1245
                */
1246
 
1247
                if ((buf = c7000_get_buffer(cup)) == NULL) {
1248
                        CPrintk(0, "c7000: c7000_bld_read_chain: can not obtain a read buffer for unit 0x%x\n", cup->devno);
1249
                        return(-ENOMEM);
1250
                }
1251
 
1252
                num++;
1253
                buf->len = 0;
1254
 
1255
                /*
1256
                        Clear out the read header flag.
1257
                */
1258
 
1259
                head = (struct c7000_rd_header *)(buf->data + C7000_DATAL);
1260
                head->flag = 0x00;
1261
                c7000_queue_buffer(cup, buf);
1262
 
1263
                /*
1264
                        Build the read channel program segment.
1265
                */
1266
 
1267
                c7000_bld_read_chpgm(cup, buf);
1268
 
1269
                /*
1270
                        Chain the prior (if any) channel program segment to
1271
                        this one.
1272
                */
1273
 
1274
                if (pbuf != NULL)
1275
                        pbuf->ccws[3].cda = pbuf->ccws[5].cda = (__u32)virt_to_phys(&buf->ccws[0]);
1276
 
1277
                pbuf = buf;
1278
        }
1279
 
1280
        CPrintk(1, "c7000: c7000_bld_read_chain: chained %d buffers for unit 0x%x\n", num, cup->devno);
1281
        return(0);
1282
}
1283
 
1284
/*
1285
        Build up a list of buffers to write.  Each buffer is described
1286
        by one c7000_buffer structure.  The c7000_buffer structure
1287
        contains a channel segment that will write that one buffer.
1288
        The channel program segments are chained together via TIC
1289
        CCWS.
1290
*/
1291
 
1292
static void
1293
c7000_bld_wrt_chain(struct c7000_unit *cup)
1294
{
1295
        struct  c7000_buffer    *buf = cup->proc_head, *pbuf = NULL;
1296
        int                     num = 0;
1297
 
1298
        while (buf != NULL) {
1299
                c7000_bld_wrt_chpgm(cup, buf);
1300
 
1301
                /*
1302
                        Chain the channel program segments together.
1303
                */
1304
 
1305
                if (pbuf != NULL)
1306
                        pbuf->ccws[2].cda = (__u32)virt_to_phys(&buf->ccws[0]);
1307
 
1308
                pbuf = buf;
1309
                buf = buf->next;
1310
                num++;
1311
        }
1312
 
1313
        CPrintk(1, "c7000: c7000_bld_wrt_chain: chained %d buffers for unit 0x%x\n", num, cup->devno);
1314
        return;
1315
}
1316
 
1317
/*
1318
        Interrupt handler bottom half (bh) routine.
1319
        Process all of the buffers on the c7000_unit bh chain.
1320
        The bh chain is populated by the interrupt routine when
1321
        a READ channel program completes on a buffer.
1322
*/
1323
 
1324
static void
1325
c7000_irq_bh(struct c7000_unit *cup)
1326
{
1327
        struct  c7000_buffer            *buf, *pbuf;
1328
        struct  c7000_rd_header         *head;
1329
        struct  sk_buff                 *skb;
1330
        struct  c7000_controller        *ccp;
1331
        STRUCT_NET_DEVICE               *dev;
1332
        int                             rc;
1333
        __u16                           data_length;
1334
        __u32                           parm;
1335
        __u8                            flags = 0x00;
1336
        __u32                           saveflags;
1337
 
1338
        ccp = cup->cntlp;
1339
        dev = ccp->dev;
1340
 
1341
        s390irq_spin_lock_irqsave(cup->irq, saveflags);
1342
 
1343
        /*
1344
                Process all buffers sent to bh by the interrupt routine.
1345
        */
1346
 
1347
        while (cup->bh_head != NULL) {
1348
                buf = c7000_dequeue_bh_buffer(cup);
1349
 
1350
                /*
1351
                        Deference the data as a c7000 header.
1352
                */
1353
 
1354
                head = (struct c7000_rd_header *)(buf->data + C7000_DATAL);
1355
 
1356
                /*
1357
                        If it is a control message, release the buffer and
1358
                        continue the loop.
1359
                */
1360
 
1361
                if (C7000_LINKID(head->cmd) == 0) {
1362
                        CPrintk(0, "c7000: c7000_irq_bh: unexpected control command %d on unit 0x%x\n", head->cmd, cup->devno);
1363
                        c7000_release_buffer(cup, buf);
1364
                        continue;
1365
                }
1366
 
1367
                /*
1368
                        Allocate a socket buffer.
1369
                */
1370
 
1371
                data_length = head->len;
1372
                skb = dev_alloc_skb(data_length);
1373
 
1374
                /*
1375
                        Copy the data to the skb.
1376
                        Send it to the upper layers.
1377
                */
1378
 
1379
                if (skb != NULL) {
1380
                        memcpy(skb_put(skb, data_length), buf->data, data_length);
1381
                        skb->dev = dev;
1382
                        skb->protocol = htons(ETH_P_IP);
1383
                        skb->pkt_type = PACKET_HOST;
1384
                        skb->mac.raw = skb->data;
1385
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
1386
                        netif_rx(skb);
1387
                        ccp->stats.rx_packets++;
1388
                } else {
1389
                        CPrintk(0, "c7000: c7000_irq_bh: can not allocate a skb for unit 0x%x\n", cup->devno);
1390
                        ccp->stats.rx_dropped++;
1391
                }
1392
 
1393
                /*
1394
                        Rechain the buffer on the processing list.
1395
                */
1396
 
1397
                head->flag = 0x00;
1398
                buf->len = 0;
1399
                pbuf = cup->proc_tail;
1400
                c7000_queue_buffer(cup, buf);
1401
 
1402
                /*
1403
                        Rechain the buffer on the running channel program.
1404
                */
1405
 
1406
                if (pbuf != NULL)
1407
                        pbuf->ccws[3].cda = pbuf->ccws[5].cda = (__u32)virt_to_phys(&buf->ccws[0]);
1408
 
1409
        }
1410
 
1411
        /*
1412
                Restart the READ channel program if IO_active is 0.
1413
        */
1414
 
1415
        if (test_and_set_bit(0, (void *)&cup->IO_active) == 0) {
1416
 
1417
                if ((rc = c7000_bld_read_chain(cup)) != 0) {
1418
                        CPrintk(0, "c7000: c7000_irq_bh: can not build read chain for unit 0x%x, return code %d\n", cup->devno, rc);
1419
                        c7000_error(cup->cntlp);
1420
                        clear_bit(C7000_BH_ACTIVE, (void *)&cup->flag_a);
1421
                        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
1422
                        return;
1423
                }
1424
 
1425
                parm = (__u32)cup;
1426
                cup->state = C7000_READ;
1427
 
1428
                if ((rc = do_IO(cup->irq, &cup->proc_head->ccws[0], parm, 0xff, flags)) != 0) {
1429
                        CPrintk(0, "c7000: c7000_irq_bh: can not start READ IO to unit 0x%x, return code %d\n", cup->devno, rc);
1430
                        c7000_error(cup->cntlp);
1431
                        clear_bit(C7000_BH_ACTIVE, (void *)&cup->flag_a);
1432
                        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
1433
                        return;
1434
                }
1435
 
1436
                CPrintk(1, "c7000: c7000_irq_bh: started READ IO to unit 0x%x\n", cup->devno);
1437
        }
1438
 
1439
        /*
1440
                Clear the bh active indication.
1441
        */
1442
 
1443
        clear_bit(C7000_BH_ACTIVE, (void *)&cup->flag_a);
1444
        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
1445
        return;
1446
}
1447
 
1448
/*
1449
        Send a system validate control command to a unit.
1450
*/
1451
 
1452
static int
1453
c7000_send_sysval(struct c7000_unit *cup)
1454
{
1455
        int                             rc;
1456
        struct  c7000_controller        *ccp = cup->cntlp;
1457
        struct  c7000_control_blk       *ctlblkp = &(cup->control_blk);
1458
 
1459
        CPrintk(1, "c7000: c7000_send_sysval: send sysval for device 0x%x\n", cup->devno);
1460
 
1461
        /*
1462
                Build the system validate control message.
1463
        */
1464
 
1465
        memset(ctlblkp, '\0', sizeof(struct c7000_control_blk));
1466
        ctlblkp->cmd = C7000_SYS_VALIDATE;
1467
        ctlblkp->correlator = 0;
1468
        ctlblkp->link_id = ccp->linkid;
1469
        ctlblkp->ver = ccp->version;
1470
        memcpy(ctlblkp->hostname, ccp->lhost, NAMLEN);
1471
        memcpy(ctlblkp->unitname, ccp->uhost, NAMLEN);
1472
        ctlblkp->rdsize = C7000_DATAL;
1473
        ctlblkp->wrtsize = C7000_DATAL;
1474
 
1475
        /*
1476
                Build the channel program.
1477
        */
1478
 
1479
        c7000_bld_wrtctl_chpgm(cup);
1480
 
1481
        /*
1482
                Do the IO and wait for write to complete.
1483
        */
1484
 
1485
        if ((rc = c7000_doio(cup)) != 0) {
1486
                CPrintk(0, "c7000: c7000_send_sysval failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1487
                return(-1);
1488
        }
1489
 
1490
        return(0);
1491
}
1492
 
1493
/*
1494
        Send a system validate response control command to a unit.
1495
*/
1496
 
1497
static int
1498
c7000_send_sysval_resp(struct c7000_unit *cup, unsigned char correlator, int ret_code)
1499
{
1500
        int                             rc;
1501
        struct  c7000_controller        *ccp = cup->cntlp;
1502
        struct  c7000_control_blk       *ctlblkp = &(cup->control_blk);
1503
 
1504
        CPrintk(1, "c7000: c7000_send_sysval_resp: send sysval response for device 0x%x\n", cup->devno);
1505
 
1506
        /*
1507
                Build the system validate response control message.
1508
        */
1509
 
1510
        memset(ctlblkp, '\0', sizeof(struct c7000_control_blk));
1511
        ctlblkp->cmd = C7000_SYS_VALIDATE_RESP;
1512
        ctlblkp->correlator = correlator;
1513
        ctlblkp->ret_code = ret_code;
1514
        ctlblkp->link_id = ccp->linkid;
1515
        ctlblkp->ver = ccp->version;
1516
        memcpy(ctlblkp->hostname, ccp->lhost, NAMLEN);
1517
        memcpy(ctlblkp->unitname, ccp->uhost, NAMLEN);
1518
        ctlblkp->rdsize = C7000_DATAL;
1519
        ctlblkp->wrtsize = C7000_DATAL;
1520
 
1521
        /*
1522
                Build the channel program.
1523
        */
1524
 
1525
        c7000_bld_wrtctl_chpgm(cup);
1526
 
1527
        /*
1528
                Do the IO and wait for write to complete.
1529
        */
1530
 
1531
        if ((rc = c7000_doio(cup)) != 0) {
1532
                CPrintk(0, "c7000: c7000_send_sysval_resp failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1533
                return(-1);
1534
        }
1535
 
1536
        return(0);
1537
}
1538
 
1539
/*
1540
        Check the information read in a SYS_VALIDATE control message.
1541
*/
1542
 
1543
static int
1544
c7000_checkinfo(struct c7000_unit *cup)
1545
{
1546
        struct  c7000_controller        *ccp = cup->cntlp;
1547
        struct  c7000_control_blk       *ctlblkp = &cup->control_blk;
1548
        int                             ret_code = 0;
1549
 
1550
        if (memcmp(ccp->lhost, ctlblkp->hostname, NAMLEN) ||
1551
                memcmp(ccp->uhost, ctlblkp->unitname, NAMLEN))
1552
                ret_code = Err_Names_not_Matched;
1553
 
1554
        if (ctlblkp->ver != ccp->version)
1555
                ret_code = Err_Wrong_Version;
1556
 
1557
        if ((ctlblkp->rdsize < C7000_DATAL) || (ctlblkp->wrtsize < C7000_DATAL))
1558
                ret_code = Err_Wrong_Frame_Size;
1559
 
1560
        if (ret_code != 0)
1561
                CPrintk(0, "c7000: c7000_checkinfo: ret_code %d for device 0x%x\n", ret_code, cup->devno);
1562
 
1563
        return(ret_code);
1564
}
1565
 
1566
/*
1567
        Keep reading until a sysval response comes in or an error.
1568
*/
1569
 
1570
static int
1571
c7000_get_sysval_resp(struct c7000_unit *cup)
1572
{
1573
        struct  c7000_controller        *ccp = cup->cntlp;
1574
        int                             resp = 1;
1575
        int                             req = 1;
1576
        int                             rc;
1577
        int                             ret_code = 0;
1578
 
1579
        CPrintk(1, "c7000: c7000_get_sysval_resp: get sysval response for unit 0x%x\n", cup->devno);
1580
 
1581
        /*
1582
                Wait for the response to C7000_SYS_VALIDATE and for an
1583
                inbound C7000_SYS_VALIDATE.
1584
        */
1585
 
1586
        while (resp || req) {
1587
 
1588
                /*
1589
                        Build the read channel program.
1590
                */
1591
 
1592
                c7000_bld_readctl_chpgm(cup);
1593
 
1594
                if ((rc = c7000_doio(cup)) != 0) {
1595
                        CPrintk(0, "c7000: c7000_get_sysval_resp: failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1596
                        return(-1);
1597
                }
1598
 
1599
                /*
1600
                        Process the control message.
1601
                */
1602
 
1603
                switch (cup->control_blk.cmd) {
1604
 
1605
                        /*
1606
                                Check that response is positive and return
1607
                                with success. Otherwise, return with an
1608
                                error.
1609
                        */
1610
 
1611
                        case C7000_SYS_VALIDATE_RESP:
1612
 
1613
                                if (cup->control_blk.ret_code == 0)
1614
                                        resp = 0;
1615
                                else {
1616
                                        CPrintk(0, "c7000: c7000_get_sysval_resp: receive sysval response for device 0x%x, return code %d\n",
1617
                                                cup->devno,
1618
                                                cup->control_blk.ret_code);
1619
                                        return(-1);
1620
                                }
1621
 
1622
                                break;
1623
 
1624
                        /*
1625
                                Check that the request is reasonable and
1626
                                send a SYS_VALIDATE_RESP.  Otherwise,
1627
                                return with an error.
1628
                        */
1629
 
1630
                        case C7000_SYS_VALIDATE:
1631
                                CPrintk(1, "c7000: c7000_get_sysval_resp: receive sysval for device 0x%x\n", cup->devno);
1632
                                req = 0;
1633
                                ret_code = c7000_checkinfo(cup);
1634
 
1635
                                if (c7000_send_sysval_resp(&ccp->cunits[C7000_WR], cup->control_blk.correlator, ret_code) != 0)
1636
                                        return(-1);
1637
 
1638
                                if (ret_code != 0)
1639
                                        return(-1);
1640
 
1641
                                break;
1642
 
1643
                        /*
1644
                                Anything else is unexpected and will result
1645
                                in a return with an error.
1646
                        */
1647
 
1648
                        default:
1649
                                CPrintk(0, "c7000: c7000_get_sysval_resp: receive unexpected command for device 0x%x, command %d\n", cup->devno, cup->control_blk.cmd);
1650
                                return(-1);
1651
                                break;
1652
                }
1653
 
1654
        }
1655
 
1656
        return(0);
1657
}
1658
 
1659
/*
1660
        Send a connection confirm control message.
1661
*/
1662
 
1663
static int
1664
c7000_conn_confrm(struct c7000_unit *cup, unsigned char correlator, int linkid)
1665
{
1666
        int                             rc;
1667
        struct  c7000_controller        *ccp = cup->cntlp;
1668
        struct  c7000_control_blk       *ctlblkp = &(cup->control_blk);
1669
 
1670
        CPrintk(1, "c7000: c7000_conn_confrm: send the connection confirmation message for unit 0x%x\n", cup->devno);
1671
 
1672
        /*
1673
                Build the connection confirm control message.
1674
        */
1675
 
1676
        memset(ctlblkp, '\0', sizeof(struct c7000_control_blk));
1677
        ctlblkp->cmd = C7000_CONN_CONFRM;
1678
        ctlblkp->ver = ccp->version;
1679
        ctlblkp->link_id = linkid;
1680
        ctlblkp->correlator = correlator;
1681
        ctlblkp->rdsize = 0;
1682
        ctlblkp->wrtsize = 0;
1683
        memcpy(ctlblkp->hostname, ccp->lappl, NAMLEN);
1684
        memcpy(ctlblkp->unitname, ccp->uappl, NAMLEN);
1685
 
1686
        /*
1687
                Build the channel program.
1688
        */
1689
 
1690
        c7000_bld_wrtctl_chpgm(cup);
1691
 
1692
        /*
1693
                Do the IO and wait for write to complete.
1694
        */
1695
 
1696
        if ((rc = c7000_doio(cup)) != 0) {
1697
                CPrintk(0, "c7000: c7000_conn_confrm: failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1698
                return(-1);
1699
        }
1700
 
1701
        return(0);
1702
}
1703
 
1704
/*
1705
        Send a connection request control message.
1706
*/
1707
 
1708
static int
1709
c7000_send_conn(struct c7000_unit *cup)
1710
{
1711
        int                             rc;
1712
        struct  c7000_controller        *ccp = cup->cntlp;
1713
        struct  c7000_control_blk       *ctlblkp = &(cup->control_blk);
1714
 
1715
        CPrintk(1, "c7000: c7000_send_conn: send the connection request message for unit 0x%x\n", cup->devno);
1716
 
1717
        /*
1718
                Build the connection request control message.
1719
        */
1720
 
1721
        memset(ctlblkp, '\0', sizeof(struct c7000_control_blk));
1722
        ctlblkp->cmd = C7000_CONN_REQ;
1723
        ctlblkp->ver = ccp->version;
1724
        ctlblkp->link_id = 0;
1725
        ctlblkp->correlator = 0;
1726
        ctlblkp->rdsize = C7000_DATAL;
1727
        ctlblkp->wrtsize = C7000_DATAL;
1728
        memcpy(ctlblkp->hostname, ccp->lappl, NAMLEN);
1729
        memcpy(ctlblkp->unitname, ccp->uappl, NAMLEN);
1730
 
1731
        /*
1732
                Build the channel program.
1733
        */
1734
 
1735
        c7000_bld_wrtctl_chpgm(cup);
1736
 
1737
        /*
1738
                Do the IO and wait for write to complete.
1739
        */
1740
 
1741
        if ((rc = c7000_doio(cup)) != 0) {
1742
                CPrintk(0, "c7000: c7000_send_conn: failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1743
                return(-1);
1744
        }
1745
 
1746
        return(0);
1747
}
1748
 
1749
/*
1750
        Send a disconnect control message to the link with the value of
1751
        linkid.
1752
*/
1753
 
1754
static int
1755
c7000_send_disc(struct c7000_unit *cup, int linkid)
1756
{
1757
        int                             rc;
1758
        struct  c7000_controller        *ccp = cup->cntlp;
1759
        struct  c7000_control_blk       *ctlblkp = &(cup->control_blk);
1760
 
1761
        CPrintk(1, "c7000: c7000_send_disc: send disconnect message for unit 0x%x\n", cup->devno);
1762
 
1763
        /*
1764
                Build the disconnect control message.
1765
        */
1766
 
1767
        memset(ctlblkp, '\0', sizeof(struct c7000_control_blk));
1768
        ctlblkp->cmd = C7000_DISCONN;
1769
        ctlblkp->ver = ccp->version;
1770
        ctlblkp->link_id = linkid;
1771
        ctlblkp->correlator = 0;
1772
        ctlblkp->rdsize = C7000_DATAL;
1773
        ctlblkp->wrtsize = C7000_DATAL;
1774
        memcpy(ctlblkp->hostname, ccp->lappl, NAMLEN);
1775
        memcpy(ctlblkp->unitname, ccp->uappl, NAMLEN);
1776
 
1777
        /*
1778
                Build the channel program.
1779
        */
1780
 
1781
        c7000_bld_wrtctl_chpgm(cup);
1782
 
1783
        /*
1784
                Do the IO and wait for write to complete.
1785
        */
1786
 
1787
        if ((rc = c7000_doio(cup)) != 0) {
1788
                CPrintk(0, "c7000: c7000_send_disc: failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1789
                return(-1);
1790
        }
1791
 
1792
        return(0);
1793
}
1794
 
1795
/*
1796
        Resolve the race condition based on the link identifier value.
1797
        The adapter microcode assigns the identifiers.  A higher value implies
1798
        that the race was lost. A side effect of this function is that
1799
        ccp->linkid is set to the link identifier to be used for this
1800
        connection (provided that 0 is returned).
1801
*/
1802
 
1803
static int
1804
c7000_resolve_race(struct c7000_unit *cup, int local_linkid, int remote_linkid)
1805
{
1806
        struct c7000_controller         *ccp = cup->cntlp;
1807
 
1808
        CPrintk(1, "c7000: c7000_resolve_race: for unit 0x%x, local linkid %d, remote linkid %d\n", cup->devno, local_linkid, remote_linkid);
1809
 
1810
        /*
1811
                This local link identifier should not be zero..
1812
        */
1813
 
1814
        if (local_linkid == 0) {
1815
                CPrintk(0, "c7000: c7000_resolve_race: error for unit 0x%x, local linkid is null\n", cup->devno);
1816
                return(-1);
1817
        }
1818
 
1819
        /*
1820
                This indicates that there is no race.  Just use our
1821
                local link identifier.
1822
        */
1823
 
1824
        if (remote_linkid == 0) {
1825
                ccp->linkid = local_linkid;
1826
                return(0);
1827
        }
1828
 
1829
        /*
1830
                Send a connection confirm message if we lost the race to
1831
                the winning link identifier.
1832
 
1833
                Either way, save the winning link identifier.
1834
        */
1835
 
1836
        if (local_linkid > remote_linkid) {
1837
 
1838
                if (c7000_conn_confrm(&ccp->cunits[C7000_WR], cup->control_blk.correlator, remote_linkid) != 0) {
1839
                        CPrintk(0, "c7000: c7000_resolve_race: failed for unit 0x%x\n", cup->devno);
1840
                        return(-1);
1841
                }
1842
 
1843
                ccp->linkid = remote_linkid;
1844
        } else {
1845
                ccp->linkid = local_linkid;
1846
        }
1847
 
1848
        return(0);
1849
}
1850
 
1851
/*
1852
        Get connected by processing the connection request/response/confirm
1853
        control messages.  A connection request has already been sent by
1854
        calling function c7000_send_conn.
1855
*/
1856
 
1857
static int
1858
c7000_get_conn(struct c7000_unit *cup)
1859
{
1860
        struct c7000_controller         *ccp = cup->cntlp;
1861
        int                             rc;
1862
        int                             cont = 1;
1863
        int                             remote_linkid = 0;
1864
        int                             local_linkid = 0;
1865
 
1866
        CPrintk(1, "c7000: c7000_get_conn: read the connected message for unit 0x%x\n", cup->devno);
1867
        ccp->linkid = 0;
1868
 
1869
        while (cont == 1) {
1870
 
1871
                /*
1872
                        Build the read channel program.
1873
                */
1874
 
1875
                c7000_bld_readctl_chpgm(cup);
1876
 
1877
                /*
1878
                        Start the channel program to read a control message.
1879
                */
1880
 
1881
                if ((rc = c7000_doio(cup)) != 0) {
1882
                        CPrintk(0, "c7000: c7000_get_conn: failed with rc = %d for unit 0x%x\n", rc, cup->devno);
1883
                        return(-1);
1884
                }
1885
 
1886
                /*
1887
                        Process the control message that was received based
1888
                        on the command code.
1889
                */
1890
 
1891
                CPrintk(1, "c7000: c7000_get_conn: received command %d for unit 0x%x\n", cup->control_blk.cmd, cup->devno);
1892
 
1893
                switch(cup->control_blk.cmd) {
1894
 
1895
                        /*
1896
                                Save the remote link_id in the message for
1897
                                a check in c7000_resolve_race.
1898
                        */
1899
 
1900
                        case C7000_CONN_REQ:
1901
                                remote_linkid = cup->control_blk.link_id;
1902
                                break;
1903
 
1904
                        /*
1905
                                A connection response received.  Resolve
1906
                                the network race condition (if any) by
1907
                                comparing the link identifier values.
1908
                        */
1909
 
1910
                        case C7000_CONN_RESP:
1911
 
1912
                                if (cup->control_blk.ret_code != 0) {
1913
                                        CPrintk(0, "c7000: c7000_get_conn: failed for unit 0x%x , connection response return code %d\n",
1914
                                                cup->devno, cup->control_blk.ret_code);
1915
                                        return(-1);
1916
                                }
1917
 
1918
                                local_linkid = cup->control_blk.link_id;
1919
 
1920
                                if (c7000_resolve_race(cup, local_linkid, remote_linkid) != 0)
1921
                                        return(-1);
1922
 
1923
                                break;
1924
 
1925
                        /*
1926
                                Got a confirmation to our connection request.
1927
                                Disconnect the remote link identifier (if any).
1928
                                Break out of the loop.
1929
                        */
1930
 
1931
                        case C7000_CONN_CONFRM:
1932
 
1933
                                if (remote_linkid != 0) {
1934
 
1935
                                        if (c7000_send_disc(&ccp->cunits[C7000_WR], remote_linkid) != 0) {
1936
                                                CPrintk(0, "c7000: c7000_get_conn: send disconnect failed for unit 0x%x\n", cup->devno);
1937
                                                return(-1);
1938
                                        }
1939
 
1940
                                }
1941
 
1942
                                cont = 0;
1943
                                break;
1944
 
1945
                        /*
1946
                                Got a disconnect to our connection request.
1947
                                Break out of the loop.
1948
                        */
1949
 
1950
                        case C7000_DISCONN:
1951
                                cont = 0;
1952
                                break;
1953
 
1954
                        /*
1955
                                Anything else must be an error.
1956
                                Return with an error immediately.
1957
                        */
1958
 
1959
                        default:
1960
                                CPrintk(0, "c7000: c7000_get_conn: failed for unit 0x%x unexpected command %d\n",
1961
                                        cup->devno, cup->control_blk.cmd);
1962
                                return(-1);
1963
                }
1964
 
1965
        }
1966
 
1967
        /*
1968
                Be sure that we now have a link identifier.
1969
        */
1970
 
1971
        if (ccp->linkid == 0)
1972
                return(-1);
1973
 
1974
        return(0);
1975
}
1976
 
1977
/*
1978
        Get statistics method.
1979
*/
1980
 
1981
struct net_device_stats *
1982
c7000_stats(STRUCT_NET_DEVICE *dev)
1983
{
1984
        struct  c7000_controller        *ccp = (struct c7000_controller *)dev->priv;
1985
 
1986
        return(&ccp->stats);
1987
}
1988
 
1989
/*
1990
        Open method.
1991
*/
1992
 
1993
static int
1994
c7000_open(STRUCT_NET_DEVICE *dev)
1995
{
1996
        int                             i;
1997
        struct  c7000_controller        *ccp = (struct c7000_controller *)dev->priv;
1998
        struct  c7000_unit              *cup;
1999
        int                             rc;
2000
        __u32                           parm;
2001
        __u8                            flags = 0x00;
2002
 
2003
        c7000_set_busy(dev);
2004
 
2005
        /*
2006
                Allocate space for the unit buffers.
2007
        */
2008
 
2009
        if (c7000_alloc_buffers(dev) == -1) {
2010
                CPrintk(0, "c7000: c7000_open: can not allocate buffer space for base unit 0x%lx\n", dev->base_addr);
2011
                c7000_free_buffers(dev);  /* free partially allocated buffers */
2012
                c7000_clear_busy(dev);
2013
                return(-ENOMEM);
2014
        }
2015
 
2016
        /*
2017
                Perform the initialization for all units.
2018
        */
2019
 
2020
        for (i = 0; i < NUNITS; i++) {
2021
                cup = &ccp->cunits[i];
2022
 
2023
                /*
2024
                        Initialize task queue structure used for the bottom
2025
                        half routine.
2026
                */
2027
 
2028
#ifndef NEWSTUFF
2029
                cup->tq.next = NULL;
2030
#endif
2031
                cup->tq.sync = 0;
2032
                cup->tq.routine = (void *)(void *)c7000_irq_bh;
2033
                cup->tq.data = cup;
2034
                cup->state = C7000_HALT;
2035
#ifdef NEWSTUFF
2036
                init_waitqueue_head(&cup->wait);
2037
#endif
2038
                CPrintk(1, "c7000: c7000_open: issuing halt to unit 0x%x\n", cup->devno);
2039
 
2040
                /*
2041
                        Issue a halt I/O to the unit
2042
                */
2043
 
2044
                if ((rc = c7000_haltio(cup)) != 0) {
2045
                        CPrintk(0, "c7000: c7000_open: halt_IO failed with rc = %d for unit 0x%x\n", rc, cup->devno);
2046
                        continue;
2047
                }
2048
 
2049
                cup->IO_active = 0;
2050
                cup->flag_a = 0;
2051
                cup->sigsmod = 0x00;
2052
 
2053
                CPrintk(1, "c7000: c7000_open: halt complete for unit 0x%x\n", cup->devno);
2054
        }
2055
 
2056
        /*
2057
                On each subchannel send a sense id.
2058
        */
2059
 
2060
        for (i = 0; i < NUNITS; i++) {
2061
                cup = &ccp->cunits[i];
2062
 
2063
                /*
2064
                        Build SENSE ID channel program.
2065
                */
2066
 
2067
                c7000_bld_senseid_chpgm(cup);
2068
 
2069
                /*
2070
                        Issue the start I/O for SENSE ID channel program.
2071
                */
2072
 
2073
                CPrintk(1, "c7000: c7000_open: issuing SENSEID to unit 0x%x\n", cup->devno);
2074
 
2075
                if ((rc = c7000_doio(cup)) != 0) {
2076
                        CPrintk(0, "c7000: c7000_open: SENSEID failed with rc = %d for unit 0x%x\n", rc, cup->devno);
2077
                        c7000_clear_busy(dev);
2078
                        return(-EIO);
2079
                }
2080
 
2081
                CPrintk(1, "c7000: c7000_open: SENSEID complete for unit 0x%x\n", cup->devno);
2082
        }
2083
 
2084
        /*
2085
                Send the system validation control message.
2086
        */
2087
 
2088
        cup = &ccp->cunits[C7000_WR];
2089
 
2090
        if (c7000_send_sysval(cup) != 0) {
2091
                CPrintk(0, "c7000: c7000_open: can not send sysval for unit 0x%x\n", cup->devno);
2092
                c7000_clear_busy(dev);
2093
                return(-EIO);
2094
        }
2095
 
2096
        CPrintk(1, "c7000: c7000_open: successfully sent sysval for unit 0x%x\n", cup->devno);
2097
        /*
2098
                Get the system validation response message.
2099
        */
2100
 
2101
        cup = &ccp->cunits[C7000_RD];
2102
 
2103
        if (c7000_get_sysval_resp(cup) != 0) {
2104
                CPrintk(0, "c7000: c7000_open: can not read sysval response for unit 0x%x\n", cup->devno);
2105
                c7000_clear_busy(dev);
2106
                return(-EIO);
2107
        }
2108
 
2109
        CPrintk(1, "c7000: c7000_open: successfully received sysval reply for unit 0x%x\n", cup->devno);
2110
        ccp->cunits[C7000_RD].state = ccp->cunits[C7000_WR].state = C7000_CONNECT;
2111
 
2112
        cup = &ccp->cunits[C7000_WR];
2113
 
2114
        /*
2115
                Send a connection request.
2116
        */
2117
 
2118
        if (c7000_send_conn(cup) != 0) {
2119
                CPrintk(0, "c7000: c7000_open: connection failed for unit 0x%x\n", cup->devno);
2120
                c7000_clear_busy(dev);
2121
                return(-EIO);
2122
        }
2123
 
2124
        cup = &ccp->cunits[C7000_RD];
2125
 
2126
        /*
2127
                Get the response to our connection request Note that a
2128
                network race may occur.  This is handled in c7000_get_conn.
2129
        */
2130
 
2131
        if (c7000_get_conn(cup) != 0) {
2132
                CPrintk(0, "c7000: c7000_open: unit 0x%x has connected\n", cup->devno);
2133
                c7000_clear_busy(dev);
2134
                return(-EIO);
2135
        }
2136
 
2137
        CPrintk(1, "c7000: c7000_open: successfully received connection request for unit 0x%x\n", cup->devno);
2138
        ccp->cunits[C7000_RD].state = ccp->cunits[C7000_WR].state = C7000_READY;
2139
 
2140
        /*
2141
                Clear the interface statistics.
2142
        */
2143
 
2144
        memset(&ccp->stats, '\0', sizeof(struct net_device_stats));
2145
 
2146
        if ((rc = c7000_bld_read_chain(cup)) != 0) {
2147
                c7000_clear_busy(dev);
2148
                return(rc);
2149
        }
2150
 
2151
        /*
2152
                Start the C7000_READ channel program but do not wait for it's
2153
                completion.
2154
        */
2155
 
2156
        cup->state = C7000_READ;
2157
        parm = (__u32) cup;
2158
        set_bit(0, (void *)&cup->IO_active);
2159
 
2160
        if ((rc = do_IO(cup->irq, &cup->proc_head->ccws[0], parm, 0xff, flags)) != 0) {
2161
                CPrintk(0, "c7000: c7000_open: READ failed with return code %d for unit 0x%x\n", rc, cup->devno);
2162
                c7000_error(cup->cntlp);
2163
                clear_bit(0, (void *)&cup->IO_active);
2164
                c7000_clear_busy(dev);
2165
                return(-EIO);
2166
        }
2167
 
2168
#ifdef NEWSTUFF
2169
        netif_start_queue(dev);
2170
#else
2171
        dev->start = 1;
2172
#endif
2173
        CPrintk(0, "c7000: c7000_open: base unit 0x%lx is opened\n", dev->base_addr);
2174
        c7000_clear_busy(dev);
2175
        MOD_INC_USE_COUNT;      /* increment module usage count */
2176
        return(0);
2177
}
2178
 
2179
/*
2180
        Stop method.
2181
*/
2182
 
2183
static int
2184
c7000_stop(STRUCT_NET_DEVICE *dev)
2185
{
2186
        int                             i;
2187
        struct  c7000_controller        *ccp = (struct c7000_controller *)dev->priv;
2188
        struct  c7000_unit              *cup;
2189
        int                             rc;
2190
 
2191
#ifdef NEWSTUFF
2192
/* nothing? */
2193
#else
2194
        dev->start = 0;
2195
#endif
2196
        c7000_set_busy(dev);
2197
 
2198
        /*
2199
                Send a disconnect message.
2200
        */
2201
 
2202
        ccp->cunits[C7000_RD].state = ccp->cunits[C7000_WR].state = C7000_DISC;
2203
        cup = &ccp->cunits[C7000_WR];
2204
 
2205
        if (c7000_send_disc(cup, ccp->linkid) != 0) {
2206
                CPrintk(0, "c7000: c7000_stop: send of disconnect message failed for unit 0x%x\n", cup->devno);
2207
        }
2208
 
2209
        CPrintk(1, "c7000: c7000_stop: successfully sent disconnect message to unit 0x%x\n", cup->devno);
2210
 
2211
        /*
2212
                Issue a halt I/O to all units.
2213
        */
2214
 
2215
        for (i = 0; i < NUNITS; i++) {
2216
                cup = &ccp->cunits[i];
2217
                cup->state = C7000_STOP;
2218
                CPrintk(1, "c7000: c7000_stop: issuing halt to unit 0x%x\n", cup->devno);
2219
 
2220
                if ((rc = c7000_haltio(cup)) != 0) {
2221
                        CPrintk(0, "c7000: c7000_stop: halt_IO failed with rc = %d for unit 0x%x\n", rc, cup->devno);
2222
                        continue;
2223
                }
2224
 
2225
                CPrintk(1, "c7000: c7000_stop: halt complete for unit 0x%x\n", cup->devno);
2226
        }
2227
 
2228
        c7000_free_buffers(dev);
2229
        CPrintk(0, "c7000: c7000_stop: base unit 0x%lx is stopped\n", dev->base_addr);
2230
        MOD_DEC_USE_COUNT;      /* Decrement module usage count */
2231
        return(0);
2232
}
2233
 
2234
/*
2235
        Configure the interface.
2236
*/
2237
 
2238
static int
2239
c7000_config(STRUCT_NET_DEVICE *dev, struct ifmap *map)
2240
{
2241
        CPrintk(1, "c7000: c7000_config: entered for base unit 0x%lx\n", dev->base_addr);
2242
        return(0);
2243
}
2244
 
2245
/*
2246
        Transmit a packet.
2247
*/
2248
 
2249
static int
2250
c7000_xmit(struct sk_buff *skb, STRUCT_NET_DEVICE *dev)
2251
{
2252
        struct  c7000_controller        *ccp = (struct c7000_controller *)dev->priv;
2253
        struct  c7000_unit              *cup;
2254
        __u32                           saveflags;
2255
        __u32                           parm;
2256
        __u8                            flags = 0x00;
2257
        struct  c7000_buffer            *buf, *pbuf;
2258
        int                             rc;
2259
 
2260
        CPrintk(1, "c7000: c7000_xmit: entered for base unit 0x%lx\n", dev->base_addr);
2261
 
2262
        /*
2263
                When the skb pointer is NULL return.
2264
        */
2265
 
2266
        if (skb == NULL) {
2267
                CPrintk(0, "c7000: c7000_xmit: skb pointer is null for base unit 0x%lx\n", dev->base_addr);
2268
                ccp->stats.tx_dropped++;
2269
                return(-EIO);
2270
        }
2271
 
2272
        cup = &ccp->cunits[C7000_WR];
2273
 
2274
        /*
2275
                Lock the irq.
2276
        */
2277
 
2278
        s390irq_spin_lock_irqsave(cup->irq, saveflags);
2279
 
2280
        /*
2281
                When the device transmission busy flag is on , no data
2282
                can be sent.  Unlock the irq and return EBUSY.
2283
        */
2284
 
2285
        if (c7000_check_busy(dev)) {
2286
                CPrintk(1, "c7000: c7000_xmit: c7000_check_busy returns true for base unit 0x%lx\n", dev->base_addr);
2287
                s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
2288
                return(-EBUSY);
2289
        }
2290
 
2291
        /*
2292
                Set the device transmission busy flag on atomically.
2293
        */
2294
 
2295
        if (c7000_ts_busy(TB_TX, dev)) {
2296
                CPrintk(1, "c7000: c7000_xmit: c7000_ts_busy returns true for base unit 0x%lx\n", dev->base_addr);
2297
                s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
2298
                return(-EBUSY);
2299
        }
2300
 
2301
        CPrintk(1, "c7000: c7000_xmit: set TB_TX for unit 0x%x\n", cup->devno);
2302
 
2303
        /*
2304
                Obtain a free buffer.  If none are free then mark tbusy
2305
                with TB_NOBUFFER and return EBUSY.
2306
        */
2307
 
2308
        if ((buf = c7000_get_buffer(cup)) == NULL) {
2309
                CPrintk(1, "c7000: c7000_xmit: setting TB_NOBUFFER for base unit 0x%lx\n", dev->base_addr);
2310
                c7000_setbit_busy(TB_NOBUFFER, dev);
2311
                c7000_clearbit_busy(TB_TX, dev);
2312
                s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
2313
                return(-EBUSY);
2314
        }
2315
 
2316
        CPrintk(1, "c7000: c7000_xmit: Got buffer for unit 0x%x\n", cup->devno);
2317
 
2318
        /*
2319
                Save the length of the skb data and then copy it to the
2320
                buffer.  Queue the buffer on the processing list.
2321
        */
2322
 
2323
        buf->len = skb->len;
2324
        memcpy(buf->data, skb->data, skb->len);
2325
        memset(buf->data + C7000_DATAL + C7000_READHDRL, '\0', C7000_READFFL);
2326
        pbuf = cup->proc_tail;
2327
        c7000_queue_buffer(cup, buf);
2328
 
2329
        /*
2330
                Chain the buffer to the running channel program.
2331
        */
2332
 
2333
        if (test_bit(0, (void *)&cup->IO_active) && pbuf != NULL) {
2334
                c7000_bld_wrt_chpgm(cup, buf);
2335
                pbuf->ccws[2].cda = (__u32)virt_to_phys(&buf->ccws[0]);
2336
        }
2337
 
2338
        /*
2339
                Free the socket buffer.
2340
        */
2341
 
2342
        dev_kfree_skb(skb);
2343
 
2344
        /*
2345
                If the unit is not currently doing IO, build a channel
2346
                program and start the IO for the buffers on the processing
2347
                chain.
2348
        */
2349
 
2350
        if (test_and_set_bit(0, (void *)&cup->IO_active) == 0) {
2351
                CPrintk(1, "c7000: c7000_xmit: start IO for unit 0x%x\n", cup->devno);
2352
                c7000_bld_wrt_chain(cup);
2353
                parm = (__u32) cup;
2354
                cup->state = C7000_WRITE;
2355
 
2356
                if ((rc = do_IO(cup->irq, &cup->proc_head->ccws[0], parm, 0xff, flags)) != 0) {
2357
                        CPrintk(0, "c7000: c7000_xmit: do_IO failed with return code %d for unit 0x%x\n", rc, cup->devno);
2358
                        c7000_error(cup->cntlp);
2359
                        c7000_clearbit_busy(TB_TX, dev);
2360
                        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
2361
                        return(-EIO);
2362
                }
2363
 
2364
                dev->trans_start = jiffies;
2365
                CPrintk(1, "c7000: c7000_xmit: do_IO succeeds for unit 0x%x\n", cup->devno);
2366
        }
2367
 
2368
        /*
2369
                If the free chain is now NULL, set the TB_NOBUFFER flag.
2370
        */
2371
 
2372
        if (cup->free == NULL) {
2373
                CPrintk(1, "c7000: c7000_xmit: setting TB_NOBUFFER for base unit 0x%lx\n", dev->base_addr);
2374
                c7000_setbit_busy(TB_NOBUFFER, dev);
2375
        }
2376
 
2377
        c7000_clearbit_busy(TB_TX, dev);
2378
        s390irq_spin_unlock_irqrestore(cup->irq, saveflags);
2379
        CPrintk(1, "c7000: c7000_xmit: exits for unit 0x%x\n", cup->devno);
2380
        return(0);
2381
}
2382
 
2383
/*
2384
        Handle an ioctl from a user process.
2385
*/
2386
 
2387
static int
2388
c7000_ioctl(STRUCT_NET_DEVICE *dev, struct ifreq *ifr, int cmd)
2389
{
2390
        CPrintk(1, "c7000: c7000_ioctl: entered for base unit 0x%lx with cmd %d\n", dev->base_addr, cmd);
2391
        return(0);
2392
}
2393
 
2394
/*
2395
        Analyze the interrupt status and return a value
2396
        that identifies the type.
2397
*/
2398
 
2399
static enum c7000_rupt
2400
c7000_check_csw(devstat_t *devstat)
2401
{
2402
 
2403
        /*
2404
                Check for channel detected conditions (except PCI).
2405
        */
2406
 
2407
        if ((devstat->cstat & ~SCHN_STAT_PCI) != 0) {
2408
                CPrintk(0, "c7000: c7000_check_csw: channel status 0x%x for unit 0x%x\n", devstat->cstat, devstat->devno);
2409
                return(C7000_CHANERR);
2410
        }
2411
 
2412
        /*
2413
                Fast path the normal cases.
2414
        */
2415
 
2416
        if (devstat->dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
2417
                return(C7000_NORMAL);
2418
 
2419
        if (devstat->cstat == SCHN_STAT_PCI)
2420
                return(C7000_NORMAL);
2421
 
2422
        /*
2423
                Check for exceptions.
2424
        */
2425
 
2426
        if (devstat->dstat & DEV_STAT_UNIT_CHECK) {
2427
                CPrintk(0, "c7000: c7000_check_csw: unit check for unit 0x%x, sense byte0 0x%2.2x\n", devstat->devno, devstat->ii.sense.data[0]);
2428
 
2429
                if (devstat->ii.sense.data[0] == C7000_BOX_RESET)
2430
                        return(C7000_UCK_RESET);
2431
                else
2432
                        return(C7000_UCK);
2433
 
2434
        } else if (devstat->dstat & DEV_STAT_UNIT_EXCEP) {
2435
                CPrintk(0, "c7000: c7000_check_csw: unit exception for unit 0x%x\n", devstat->devno);
2436
                return(C7000_UE);
2437
 
2438
        } else if (devstat->dstat & DEV_STAT_ATTENTION) {
2439
                CPrintk(0, "c7000: c7000_check_csw: attention for unit 0x%x\n", devstat->devno);
2440
                return(C7000_ATTN);
2441
 
2442
        } else if (devstat->dstat & DEV_STAT_BUSY) {
2443
                CPrintk(0, "c7000: c7000_check_csw: busy for unit 0x%x\n", devstat->devno);
2444
                return(C7000_BUSY);
2445
 
2446
        } else {
2447
                CPrintk(0, "c7000: c7000_check_csw: channel status 0x%2.2x , device status 0x%2.2x, devstat flags 0x%8.8x for unit 0x%x\n",
2448
                        devstat->cstat, devstat->dstat, devstat->flag, devstat->devno);
2449
                return(C7000_OTHER);
2450
        }
2451
 
2452
        /* NOT REACHED */
2453
 
2454
}
2455
 
2456
/*
2457
        Retry the last CCW chain to the unit.
2458
*/
2459
 
2460
static void
2461
c7000_retry_io(struct c7000_unit *cup)
2462
{
2463
        int     rc;
2464
        __u32   parm;
2465
        __u8    flags = 0x00;
2466
        ccw1_t  *ccwp;
2467
 
2468
        if (++cup->retries > C7000_MAX_RETRIES) {
2469
                c7000_error(cup->cntlp);
2470
                CPrintk(0, "c7000: c7000_retry_io: retry IO for unit 0x%x exceeds maximum retry count\n", cup->devno);
2471
                return;
2472
        }
2473
 
2474
        set_bit(0, (void *)&cup->IO_active);
2475
        parm = (__u32)cup;
2476
 
2477
        if (cup->state == C7000_READ || cup->state == C7000_WRITE)
2478
                ccwp = &cup->proc_head->ccws[0];
2479
        else
2480
                ccwp = &cup->ccws[0];
2481
 
2482
        if ((rc = do_IO(cup->irq, ccwp, parm, 0xff, flags)) != 0) {
2483
                CPrintk(0, "c7000: c7000_retry_io: can not retry IO for unit 0x%x, return code %d\n", cup->devno, rc);
2484
                clear_bit(0, (void *)&cup->IO_active);
2485
                c7000_error(cup->cntlp);
2486
        }
2487
 
2488
        CPrintk(1, "c7000: c7000_retry_io: retry IO for unit 0x%x, retry count %d\n", cup->devno, cup->retries);
2489
        return;
2490
}
2491
 
2492
/*
2493
        Process a read interrupt by scanning the list of buffers
2494
        for ones that have completed and queue them for the bottom
2495
        half to process.
2496
*/
2497
 
2498
static void
2499
c7000_proc_rintr(struct c7000_unit *cup)
2500
{
2501
        struct  c7000_buffer    *buf;
2502
        struct  c7000_rd_header *head;
2503
        int                     num_read = 0;
2504
 
2505
        while (cup->proc_head != NULL) {
2506
                head = (struct c7000_rd_header *)(cup->proc_head->data + C7000_DATAL);
2507
 
2508
                /*
2509
                        The flag byte in the read header will be set to
2510
                        FLAG_FF when the buffer has been read.
2511
                */
2512
 
2513
                if (head->flag != FLAG_FF)
2514
                        break;
2515
 
2516
                /*
2517
                        Dequeue the buffer from the proc chain
2518
                        and enqueue it on the bh chain for
2519
                        the bh routine to process.
2520
                */
2521
 
2522
                buf = c7000_dequeue_buffer(cup);
2523
                c7000_queue_bh_buffer(cup, buf);
2524
                num_read++;
2525
        }
2526
 
2527
        CPrintk(1, "c7000: c7000_proc_rintr: %d buffers read for unit 0x%x\n", num_read, cup->devno);
2528
        return;
2529
}
2530
 
2531
/*
2532
        Process all completed buffers on the proc chain.
2533
        A buffer is completed if it's READFF flag is FLAG_FF.
2534
*/
2535
 
2536
static int
2537
c7000_proc_wintr(struct c7000_unit *cup)
2538
{
2539
        struct  c7000_controller        *ccp = cup->cntlp;
2540
        struct  c7000_buffer            *buf;
2541
        int                             num_write = 0;
2542
 
2543
        if (cup->proc_head == NULL) {
2544
                CPrintk(0, "c7000: c7000_proc_wintr: unexpected NULL processing chain pointer for unit 0x%x\n", cup->devno);
2545
                return(num_write);
2546
        }
2547
 
2548
        while (cup->proc_head != NULL) {
2549
 
2550
                /*
2551
                        Check if the buffer has completed.
2552
                */
2553
 
2554
                if (*(cup->proc_head->data + C7000_DATAL + C7000_READHDRL) != FLAG_FF)
2555
                        break;
2556
 
2557
                /*
2558
                        Remove buffer from top of processing chain.
2559
                        Place it on free list.
2560
                */
2561
 
2562
                buf = c7000_dequeue_buffer(cup);
2563
                c7000_release_buffer(cup, buf);
2564
                num_write++;
2565
 
2566
                /*
2567
                        Update transmitted packets statistic.
2568
                */
2569
 
2570
                ccp->stats.tx_packets++;
2571
        }
2572
 
2573
        CPrintk(1, "c7000: c7000_proc_wintr: %d buffers written for unit 0x%x\n", num_write, cup->devno);
2574
        return(num_write);
2575
}
2576
 
2577
/*
2578
        Interrupt handler.
2579
*/
2580
 
2581
static void
2582
c7000_intr(int irq, void *initparm, struct pt_regs *regs)
2583
{
2584
        devstat_t                       *devstat = ((devstat_t *) initparm);
2585
        struct  c7000_unit              *cup = NULL;
2586
        struct  c7000_controller        *ccp = NULL;
2587
        STRUCT_NET_DEVICE               *dev = NULL;
2588
        __u32                           parm;
2589
        __u8                            flags = 0x00;
2590
        int                             rc;
2591
 
2592
        /*
2593
                Discard unsolicited interrupts
2594
        */
2595
 
2596
        if (devstat->intparm == 0) {
2597
                CPrintk(0, "c7000: c7000_intr: unsolicited interrupt for device 0x%x, cstat = 0x%2.2x, dstat = 0x%2.2x, flag = 0x%8.8x\n",
2598
                        devstat->devno, devstat->cstat, devstat->dstat, devstat->flag);
2599
                return;
2600
        }
2601
 
2602
        /*
2603
                Obtain the c7000_unit structure pointer.
2604
        */
2605
 
2606
        cup = (struct c7000_unit *)(devstat->intparm);
2607
 
2608
        /*
2609
                Obtain the c7000_controller structure and device structure
2610
                pointers.
2611
        */
2612
 
2613
        if (cup == NULL) {
2614
                CPrintk(0, "c7000: c7000_intr: c7000_unit pointer is NULL in devstat\n");
2615
                return;
2616
        }
2617
 
2618
        ccp = cup->cntlp;
2619
 
2620
        if (ccp == NULL) {
2621
                CPrintk(0, "c7000: c7000_intr: c7000_cntlp pointer is NULL in c7000_unit structure 0x%x for unit 0x%x\n", (int)cup, cup->devno);
2622
                return;
2623
        }
2624
 
2625
        dev = ccp->dev;
2626
 
2627
        if (dev == NULL) {
2628
                CPrintk(0, "c7000: c7000_intr: device pointer is NULL in c7000_controller structure 0x%x for unit 0x%x\n", (int)ccp, cup->devno);
2629
                return;
2630
        }
2631
 
2632
        /*
2633
                Finite state machine (fsm) handling.
2634
        */
2635
 
2636
        CPrintk(1, "c7000: c7000_intr: entered with state %d flag 0x%8.8x for unit 0x%x\n", cup->state, devstat->flag, cup->devno);
2637
 
2638
        switch(cup->state) {
2639
 
2640
                /*
2641
                        Not expected to be here when in INIT state.
2642
                */
2643
 
2644
                case C7000_INIT:
2645
 
2646
                        break;
2647
 
2648
                /*
2649
                        Enter state C7000_SID and wakeup the sleeping
2650
                        process in c7000_open.
2651
                */
2652
 
2653
                case C7000_HALT:
2654
 
2655
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2656
                                break;
2657
 
2658
                        cup->state = C7000_SID;
2659
                        wake_up(&cup->wait);
2660
                        break;
2661
 
2662
                /*
2663
                        Enter state C7000_SYSVAL and wakeup the sleeping
2664
                        process in c7000_open.
2665
                */
2666
 
2667
                case C7000_SID:
2668
 
2669
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2670
                                break;
2671
 
2672
                        if (c7000_check_csw(devstat) != 0) {
2673
                                c7000_retry_io(cup);
2674
 
2675
                                if (cup->state == C7000_ERROR)
2676
                                        wake_up(&cup->wait);
2677
 
2678
                                break;
2679
                        }
2680
 
2681
                        cup->retries = 0;
2682
                        cup->state = C7000_SYSVAL;
2683
                        wake_up(&cup->wait);
2684
                        break;
2685
 
2686
                /*
2687
                        Wakeup the sleeping process in c7000_open.
2688
                */
2689
 
2690
                case C7000_SYSVAL:
2691
 
2692
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2693
                                break;
2694
 
2695
                        if (c7000_check_csw(devstat) != 0) {
2696
                                c7000_retry_io(cup);
2697
 
2698
                                if (cup->state == C7000_ERROR)
2699
                                        wake_up(&cup->wait);
2700
 
2701
                                break;
2702
                        }
2703
 
2704
                        cup->retries = 0;
2705
                        wake_up(&cup->wait);
2706
                        break;
2707
 
2708
                /*
2709
                        Wakeup the sleeping process in c7000_open.
2710
                */
2711
 
2712
                case C7000_CONNECT:
2713
 
2714
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2715
                                break;
2716
 
2717
                        if (c7000_check_csw(devstat) != 0) {
2718
                                c7000_retry_io(cup);
2719
 
2720
                                if (cup->state == C7000_ERROR)
2721
                                        wake_up(&cup->wait);
2722
 
2723
                                break;
2724
                        }
2725
 
2726
                        cup->retries = 0;
2727
                        wake_up(&cup->wait);
2728
                        break;
2729
 
2730
                /*
2731
                        Not expected to be entered here.
2732
                */
2733
 
2734
                case C7000_READY:
2735
                        break;
2736
 
2737
                /*
2738
                        Process the data that was just read.
2739
                */
2740
 
2741
                case C7000_READ:
2742
 
2743
                        if ((devstat->flag & (DEVSTAT_PCI | DEVSTAT_FINAL_STATUS)) == 0)
2744
                                break;
2745
 
2746
                        CPrintk(1, "c7000: c7000_intr: process read interrupt for unit 0x%x , devstat flag = 0x%8.8x\n", cup->devno, devstat->flag);
2747
 
2748
                        /*
2749
                                Check for serious errors.
2750
                        */
2751
 
2752
                        if (c7000_check_csw(devstat) != 0) {
2753
                                ccp->stats.rx_errors++;
2754
                                c7000_error(cup->cntlp);
2755
                                break;
2756
                        }
2757
 
2758
                        /*
2759
                                Build the bottom half buffer list.
2760
                        */
2761
 
2762
                        c7000_proc_rintr(cup);
2763
 
2764
                        /*
2765
                                When final status is received clear
2766
                                the IO active bit.
2767
                        */
2768
 
2769
                        if (devstat->flag & DEVSTAT_FINAL_STATUS) {
2770
                                clear_bit(0, (void *)&cup->IO_active);
2771
                        }
2772
 
2773
                        /*
2774
                                If there are free buffers redrive the IO.
2775
                        */
2776
 
2777
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) &&
2778
                            (cup->free != NULL)) {
2779
                                c7000_bld_read_chain(cup);
2780
                                parm = (__u32)cup;
2781
                                set_bit(0, (void *)&cup->IO_active);
2782
 
2783
                                if ((rc = do_IO(cup->irq, &cup->proc_head->ccws[0], parm, 0xff, flags)) != 0) {
2784
                                        clear_bit(0, (void *)&cup->IO_active);
2785
                                        CPrintk(0, "c7000: c7000_intr: do_IO failed with return code %d for unit 0x%x\n", rc, cup->devno);
2786
                                        c7000_error(cup->cntlp);
2787
                                        break;
2788
                                }
2789
 
2790
                                CPrintk(1, "c7000: c7000_intr: started read io for unit 0x%x\n", cup->devno);
2791
                        }
2792
 
2793
                        /*
2794
                                Initiate bottom half routine to process
2795
                                data that was read.
2796
                        */
2797
 
2798
                        if (test_and_set_bit(C7000_BH_ACTIVE, (void *)&cup->flag_a) == 0) {
2799
                                queue_task(&cup->tq, &tq_immediate);
2800
                                mark_bh(IMMEDIATE_BH);
2801
                        }
2802
 
2803
                        break;
2804
 
2805
                /*
2806
                        Free the transmitted buffers and restart the channel
2807
                        process (if necessary).
2808
                */
2809
 
2810
                case C7000_WRITE:
2811
 
2812
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2813
                                break;
2814
 
2815
                        if (c7000_check_csw(devstat) != 0) {
2816
                                ccp->stats.tx_errors++;
2817
                                c7000_error(cup->cntlp);
2818
                                break;
2819
                        }
2820
 
2821
                        /*
2822
                                If at least one buffer was freed, clear
2823
                                the NOBUFFER indication.
2824
                        */
2825
 
2826
                        if (c7000_proc_wintr(cup) != 0) {
2827
                                c7000_clearbit_busy(TB_NOBUFFER, dev);
2828
                        }
2829
 
2830
                        /*
2831
                                Restart the channel program if there are more
2832
                                buffers on the processing chain.
2833
                        */
2834
 
2835
                        if (cup->proc_head != NULL) {
2836
                                c7000_bld_wrt_chain(cup);
2837
                                parm = (__u32)cup;
2838
                                set_bit(0, (void *)&cup->IO_active);
2839
 
2840
                                if ((rc = do_IO(cup->irq, &cup->proc_head->ccws[0], parm, 0xff, flags)) != 0) {
2841
                                        CPrintk(0, "c7000: c7000_intr: do_IO failed with return code %d for unit 0x%x\n", rc, cup->devno);
2842
                                        clear_bit(0, (void *)&cup->IO_active);
2843
                                        c7000_error(cup->cntlp);
2844
                                        break;
2845
                                }
2846
 
2847
                                dev->trans_start = jiffies;
2848
                        } else {
2849
                                clear_bit(0, (void *)&cup->IO_active);
2850
                                cup->state = C7000_READY;
2851
                        }
2852
 
2853
                        break;
2854
 
2855
                /*
2856
                        Disconnect message completed.  Wakeup the
2857
                        sleeping process in c7000_stop.
2858
                */
2859
 
2860
                case C7000_DISC:
2861
                        if ((devstat->flag & DEVSTAT_FINAL_STATUS) == 0)
2862
                                break;
2863
 
2864
                        if (c7000_check_csw(devstat) != 0) {
2865
                                c7000_retry_io(cup);
2866
 
2867
                                if (cup->state == C7000_ERROR)
2868
                                        wake_up(&cup->wait);
2869
 
2870
                                break;
2871
                        }
2872
 
2873
                        cup->retries = 0;
2874
                        wake_up(&cup->wait);
2875
                        break;
2876
 
2877
                /*
2878
                        Subchannel is now halted.  Wakeup the sleeping
2879
                        process in c7000_stop.  Set the state to C7000_STOPPED.
2880
                */
2881
 
2882
                case C7000_STOP:
2883
 
2884
                        cup->state = C7000_STOPPED;
2885
                        wake_up(&cup->wait);
2886
                        break;
2887
 
2888
                /*
2889
                        When in error state, stay there until the
2890
                        interface is recycled.
2891
                */
2892
 
2893
                case C7000_ERROR:
2894
 
2895
                        break;
2896
 
2897
                /*
2898
                        Should not reach here
2899
                */
2900
 
2901
                default:
2902
                        CPrintk(0, "c7000: c7000_intr: entered default case for unit 0x%x, state %d\n", cup->devno, cup->state);
2903
                        break;
2904
 
2905
        }
2906
 
2907
        CPrintk(1, "c7000: c7000_intr: exited with state %d for unit 0x%x\n", cup->state, cup->devno);
2908
        return;
2909
}
2910
 
2911
/*
2912
        Fill in system validation name padding it with blanks.
2913
*/
2914
 
2915
static void
2916
c7000_fill_name(char *dst, char *src)
2917
{
2918
        char    *tmp = dst;
2919
        int     i;
2920
 
2921
        for (i = 0; i < NAMLEN; i++, tmp++)
2922
                *tmp = ' ';
2923
 
2924
        for (i = 0; i < NAMLEN && *src != '\0'; i++)
2925
                *dst++ = *src++;
2926
 
2927
        return;
2928
}
2929
 
2930
/*
2931
        Initialization routine called when the device is registered.
2932
*/
2933
 
2934
static int
2935
c7000_init(STRUCT_NET_DEVICE *dev)
2936
{
2937
        struct  c7000_controller        *ccp;
2938
        int                             i;
2939
        int                             unitaddr;
2940
        int                             irq;
2941
 
2942
        /*
2943
                Find the position of base_addr in the bases array.
2944
        */
2945
 
2946
        for (i = 0; i < MAX_C7000; i++)
2947
                if (bases[i] == dev->base_addr)
2948
                        break;
2949
 
2950
        if (i == MAX_C7000)
2951
                return(-ENODEV);
2952
 
2953
        /*
2954
                Make sure it is a C7000 type of device.
2955
        */
2956
 
2957
        if (c7000_check_devices(dev->base_addr) != 0) {
2958
                CPrintk(0, "c7000: c7000_init: base unit 0x%lx is not the right type\n", dev->base_addr);
2959
                return(-ENODEV);
2960
        }
2961
 
2962
        /*
2963
                Initialize the device structure functions.
2964
                Note that ARP is not done on the CLAW interface.
2965
                There is no ethernet header.
2966
        */
2967
 
2968
        dev->mtu = C7000_DATAL;
2969
        dev->hard_header_len = 0;
2970
        dev->addr_len = 0;
2971
        dev->type = ARPHRD_SLIP;
2972
        dev->tx_queue_len = C7000_TXQUEUE_LEN;
2973
        dev->flags = IFF_NOARP;
2974
        dev->open = c7000_open;
2975
        dev->stop = c7000_stop;
2976
        dev->set_config = c7000_config;
2977
        dev->hard_start_xmit = c7000_xmit;
2978
        dev->do_ioctl = c7000_ioctl;
2979
        dev->get_stats = c7000_stats;
2980
 
2981
        /*
2982
                Allocate space for a private data structure.
2983
        */
2984
 
2985
        if ((ccp = dev->priv = kmalloc(sizeof(struct c7000_controller), GFP_KERNEL)) == NULL) {
2986
                CPrintk(0, "c7000: c7000_init: base unit 0x%lx can not be initialized\n", dev->base_addr);
2987
                return(-ENOMEM);
2988
        }
2989
 
2990
        CPrintk(1, "c7000: c7000_init: allocated a c7000_controller structure at address 0x%x\n", (int)ccp);
2991
        memset(ccp, '\0', sizeof(struct c7000_controller));
2992
        ccp->dev = dev;
2993
        ccp->base_addr = dev->base_addr;
2994
 
2995
        /*
2996
                Populate the system validation name with default values.
2997
        */
2998
 
2999
        c7000_fill_name(ccp->lappl, C7000_DFLT_LAPPL);
3000
        c7000_fill_name(ccp->lhost, C7000_DFLT_LHOST);
3001
        c7000_fill_name(ccp->uappl, C7000_DFLT_UAPPL);
3002
        c7000_fill_name(ccp->uhost, C7000_DFLT_UHOST);
3003
 
3004
        /*
3005
                When values have been supplied, replace the prior defaults.
3006
        */
3007
 
3008
        if (i == 0) {
3009
 
3010
                if (lappl0 != NULL)
3011
                        c7000_fill_name(ccp->lappl, lappl0);
3012
 
3013
                if (lhost0 != NULL)
3014
                        c7000_fill_name(ccp->lhost, lhost0);
3015
 
3016
                if (uappl0 != NULL)
3017
                        c7000_fill_name(ccp->uappl, uappl0);
3018
 
3019
                if (uhost0 != NULL)
3020
                        c7000_fill_name(ccp->uhost, uhost0);
3021
 
3022
        } else if (i == 1) {
3023
 
3024
                if (lappl1 != NULL)
3025
                        c7000_fill_name(ccp->lappl, lappl1);
3026
 
3027
                if (lhost1 != NULL)
3028
                        c7000_fill_name(ccp->lhost, lhost1);
3029
 
3030
                if (uappl1 != NULL)
3031
                        c7000_fill_name(ccp->uappl, uappl1);
3032
 
3033
                if (uhost1 != NULL)
3034
                        c7000_fill_name(ccp->uhost, uhost1);
3035
 
3036
        } else if (i == 2) {
3037
 
3038
                if (lappl2 != NULL)
3039
                        c7000_fill_name(ccp->lappl, lappl2);
3040
 
3041
                if (lhost2 != NULL)
3042
                        c7000_fill_name(ccp->lhost, lhost2);
3043
 
3044
                if (uappl2 != NULL)
3045
                        c7000_fill_name(ccp->uappl, uappl2);
3046
 
3047
                if (uhost2 != NULL)
3048
                        c7000_fill_name(ccp->uhost, uhost2);
3049
 
3050
        } else {
3051
 
3052
                if (lappl3 != NULL)
3053
                        c7000_fill_name(ccp->lappl, lappl3);
3054
 
3055
                if (lhost3 != NULL)
3056
                        c7000_fill_name(ccp->lhost, lhost3);
3057
 
3058
                if (uappl3 != NULL)
3059
                        c7000_fill_name(ccp->uappl, uappl3);
3060
 
3061
                if (uhost3 != NULL)
3062
                        c7000_fill_name(ccp->uhost, uhost3);
3063
 
3064
        }
3065
 
3066
        CPrintk(1, "c7000: c7000_init: lappl = %8.8s lhost = %8.8s uappl = %8.8s uhost = %8.8s for base unit 0x%x\n", ccp->lappl, ccp->lhost, ccp->uappl, ccp->uhost, ccp->base_addr);
3067
        ccp->version = 2;
3068
        ccp->linkid = 0;
3069
 
3070
        /*
3071
                Initialize the fields in the embedded cunits
3072
                array.  This type of controller occupies a range
3073
                of three contiguous device numbers.
3074
        */
3075
 
3076
        for (i = 0; i < NUNITS; i++) {
3077
                unitaddr = dev->base_addr + i;
3078
 
3079
                /*
3080
                        Get the subchannel number.
3081
                */
3082
 
3083
                if ((irq = ccp->cunits[i].irq = get_irq_by_devno(unitaddr)) == -1) {
3084
                        CPrintk(0, "c7000: c7000_init: can not get subchannel for unit 0x%x\n", unitaddr);
3085
                        return(-ENODEV);
3086
                }
3087
 
3088
                /*
3089
                        Get control of the subchannel.
3090
                */
3091
 
3092
                if (request_irq(irq, c7000_intr, SA_INTERRUPT, dev->name, &ccp->cunits[i].devstat) != 0) {
3093
                        CPrintk(0, "c7000: c7000_init: can not get control of subchannel 0x%x for unit 0x%x\n", irq, unitaddr);
3094
                        return(-EBUSY);
3095
                }
3096
 
3097
                CPrintk(1, "c7000: c7000_init: obtained control of subchannel 0x%x for unit 0x%x\n", irq, unitaddr);
3098
                ccp->cunits[i].devno = unitaddr;
3099
                ccp->cunits[i].IO_active = 0;
3100
                ccp->cunits[i].state = C7000_INIT;
3101
                ccp->cunits[i].cntlp = ccp;
3102
                CPrintk(1, "c7000: c7000_init: initialized unit 0x%x on subchannel 0x%x\n", unitaddr, irq);
3103
        }
3104
 
3105
        return(0);
3106
}
3107
 
3108
/*
3109
        Probe for the Cisco 7000 unit base addresses.
3110
*/
3111
 
3112
static void
3113
c7000_probe(void)
3114
{
3115
        s390_dev_info_t d;
3116
        int             i;
3117
        int             j;
3118
        int             idx;
3119
 
3120
        /*
3121
                Probe for up to MAX_C7000 devices.
3122
                Get the first irq into variable idx.
3123
        */
3124
 
3125
        idx = get_irq_first();
3126
 
3127
        for (j = 0; j < MAX_C7000; j++) {
3128
 
3129
                if (idx < 0)
3130
                        break;
3131
 
3132
                /*
3133
                        Continue scanning the irq's.  Variable idx
3134
                        maintains the location from the prior scan.
3135
                */
3136
 
3137
                for (i = idx; i >= 0; i = get_irq_next(i)) {
3138
 
3139
                        /*
3140
                                Ignore invalid irq's.
3141
                        */
3142
 
3143
                        if (get_dev_info_by_irq(i, &d) < 0)
3144
                                continue;
3145
 
3146
                        /*
3147
                                A Cisco 7000 is defined as a 3088 model
3148
                                type 0x61.
3149
                        */
3150
 
3151
                        if (d.sid_data.cu_type == C7000_CU_TYPE &&
3152
                            d.sid_data.cu_model == C7000_CU_MODEL) {
3153
                                CPrintk(0, "c7000_probe: unit probe found 0x%x\n", d.devno);
3154
                                bases[j] = d.devno;
3155
 
3156
                                /*
3157
                                        Skip the write irq and setup idx
3158
                                        to probe for the next box.
3159
                                */
3160
 
3161
                                idx = get_irq_next(i + 1);
3162
                                break;
3163
                        }
3164
 
3165
                }
3166
 
3167
        }
3168
 
3169
        return;
3170
}
3171
 
3172
/*
3173
        Module loading.  Register each C7000 interface found via probing
3174
        or insmod command parameters.
3175
*/
3176
 
3177
int
3178
init_module(void)
3179
{
3180
        int             result;
3181
        int             i;
3182
 
3183
        for (i = 0 ; i < MAX_C7000; i++)
3184
                bases[i] = -1;
3185
 
3186
        /*
3187
                Perform automatic detection provided it has not been disabled
3188
                by the noauto parameter.
3189
        */
3190
 
3191
        if (noauto == 0)
3192
                c7000_probe();
3193
 
3194
        /*
3195
                Populate bases array from the module basex parameters replacing
3196
                what probing found above.
3197
        */
3198
 
3199
        if (base0 != -1)
3200
                bases[0] = base0;
3201
 
3202
        if (base1 != -1)
3203
                bases[1] = base1;
3204
 
3205
        if (base2 != -1)
3206
                bases[2] = base2;
3207
 
3208
        if (base3 != -1)
3209
                bases[3] = base3;
3210
 
3211
        for (i = 0; i < MAX_C7000; i++) {
3212
 
3213
                if (bases[i] == -1)
3214
                        continue;
3215
 
3216
                /*
3217
                        Initialize the device structure.
3218
                */
3219
 
3220
                memset(&c7000_devices[i], '\0', sizeof(STRUCT_NET_DEVICE));
3221
#ifdef NEWSTUFF
3222
                strcpy(c7000_devices[i].name, ifnames[i]);
3223
#else
3224
                c7000_devices[i].name = &ifnames[i][0];
3225
#endif
3226
                c7000_devices[i].base_addr = bases[i];
3227
                c7000_devices[i].init = c7000_init;
3228
 
3229
                /*
3230
                        Register the device.  This creates the interface
3231
                        such as ci0.
3232
                */
3233
 
3234
                if ((result = register_netdev(&c7000_devices[i])) != 0)  {
3235
                        CPrintk(0, "c7000: init_module: error %d registering base unit 0x%x\n",
3236
                                result, bases[i]);
3237
                        c7000_devices[i].base_addr = -1;
3238
                } else {
3239
                        CPrintk(1, "c7000: init_module: registered base unit 0x%x on interface %s\n", bases[i], ifnames[i]);
3240
                }
3241
 
3242
        }
3243
 
3244
        CPrintk(0, "c7000: init_module: module loaded\n");
3245
        return(0);
3246
}
3247
 
3248
/*
3249
        Module unloading.  Unregister the interface and free kernel
3250
        allocated memory.
3251
*/
3252
 
3253
void
3254
cleanup_module(void)
3255
{
3256
        int                             i;
3257
        int                             j;
3258
        struct  c7000_controller        *ccp;
3259
 
3260
        for (i = 0; i < MAX_C7000; i++) {
3261
 
3262
                if (bases[i] == -1)
3263
                        continue;
3264
 
3265
                /*
3266
                        If the device was registered, it must be unregistered
3267
                        prior to unloading the module.
3268
                */
3269
 
3270
                if (c7000_devices[i].base_addr != -1) {
3271
 
3272
                        ccp = (struct c7000_controller *) c7000_devices[i].priv;
3273
 
3274
                        if (ccp != NULL) {
3275
 
3276
                                for (j = 0; j < NUNITS ; j++) {
3277
                                        CPrintk(1, "c7000: clean_module: free subchannel 0x%x for unit 0x%x\n", ccp->cunits[j].irq, ccp->cunits[j].devno);
3278
                                        free_irq(ccp->cunits[j].irq, &ccp->cunits[j].devstat);
3279
                                }
3280
 
3281
                                CPrintk(1, "c7000: clean_module: free a c7000_controller structure at address 0x%x\n", (int)ccp);
3282
                                kfree(ccp);
3283
                        }
3284
 
3285
                        unregister_netdev(&c7000_devices[i]);
3286
                }
3287
 
3288
                bases[i] = -1;
3289
        }
3290
 
3291
        CPrintk(0, "c7000: clean_module: module unloaded\n");
3292
        return;
3293
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.