1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
18 * FBI board dependent Driver for SMT and LLC
24 #include "h/supern_2.h"
25 #include "h/skfbiinc.h"
26 #include <linux/bitrev.h>
29 static const char ID_sccs
[] = "@(#)drvfbi.c 1.63 99/02/11 (C) SK " ;
37 #define LED_Y_ON 0x11 /* Used for ring up/down indication */
38 #define LED_Y_OFF 0x10
41 #define MS2BCLK(x) ((x)*12500L)
44 * valid configuration values are:
49 const u_char oem_id
[] = "xPOS_ID:xxxx" ;
50 #else /* OEM_CONCEPT */
51 const u_char oem_id
[] = OEM_ID
;
52 #endif /* OEM_CONCEPT */
54 #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
56 const struct s_oem_ids oem_ids
[] = {
60 #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
63 /* Prototypes of external functions */
65 extern int AIX_vpdReadByte() ;
69 /* Prototype of a local function. */
70 static void smt_stop_watchdog(struct s_smc
*smc
);
75 static void card_start(struct s_smc
*smc
)
83 smt_stop_watchdog(smc
) ;
87 * make sure no transfer activity is pending
89 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
90 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
91 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
93 * now reset everything
95 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
96 i
= (int) inp(ADDR(B0_CTRL
)) ; /* do dummy read */
97 SK_UNUSED(i
) ; /* Make LINT happy. */
98 outp(ADDR(B0_CTRL
), CTRL_RST_CLR
) ;
101 * Reset all bits in the PCI STATUS register
103 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_ON
) ; /* enable for writes */
104 word
= inpw(PCI_C(PCI_STATUS
)) ;
105 outpw(PCI_C(PCI_STATUS
), word
| PCI_ERRBITS
) ;
106 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_OFF
) ; /* disable writes */
109 * Release the reset of all the State machines
110 * Release Master_Reset
111 * Release HPI_SM_Reset
113 outp(ADDR(B0_CTRL
), CTRL_MRST_CLR
|CTRL_HPI_CLR
) ;
116 * determine the adapter type
117 * Note: Do it here, because some drivers may call card_start() once
118 * at very first before any other initialization functions is
121 rev_id
= inp(PCI_C(PCI_REV_ID
)) ;
122 if ((rev_id
& 0xf0) == SK_ML_ID_1
|| (rev_id
& 0xf0) == SK_ML_ID_2
) {
123 smc
->hw
.hw_is_64bit
= TRUE
;
125 smc
->hw
.hw_is_64bit
= FALSE
;
129 * Watermark initialization
131 if (!smc
->hw
.hw_is_64bit
) {
132 outpd(ADDR(B4_R1_F
), RX_WATERMARK
) ;
133 outpd(ADDR(B5_XA_F
), TX_WATERMARK
) ;
134 outpd(ADDR(B5_XS_F
), TX_WATERMARK
) ;
137 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* clear the reset chips */
138 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_ON
|LED_GB_OFF
) ; /* ye LED on */
140 /* init the timer value for the watch dog 2,5 minutes */
141 outpd(ADDR(B2_WDOG_INI
),0x6FC23AC0) ;
143 /* initialize the ISR mask */
144 smc
->hw
.is_imask
= ISR_MASK
;
145 smc
->hw
.hw_state
= STOPPED
;
147 GET_PAGE(0) ; /* necessary for BOOT */
150 void card_stop(struct s_smc
*smc
)
152 smt_stop_watchdog(smc
) ;
153 smc
->hw
.mac_ring_is_up
= 0 ; /* ring down */
157 * make sure no transfer activity is pending
159 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
160 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
161 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
163 * now reset everything
165 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
166 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* reset for all chips */
167 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_OFF
|LED_GB_OFF
) ; /* all LEDs off */
168 smc
->hw
.hw_state
= STOPPED
;
171 /*--------------------------- ISR handling ----------------------------------*/
173 void mac1_irq(struct s_smc
*smc
, u_short stu
, u_short stl
)
179 * parity error: note encoding error is not possible in tag mode
181 if (stl
& (FM_SPCEPDS
| /* parity err. syn.q.*/
182 FM_SPCEPDA0
| /* parity err. a.q.0 */
183 FM_SPCEPDA1
)) { /* parity err. a.q.1 */
184 SMT_PANIC(smc
,SMT_E0134
, SMT_E0134_MSG
) ;
187 * buffer underrun: can only occur if a tx threshold is specified
189 if (stl
& (FM_STBURS
| /* tx buffer underrun syn.q.*/
190 FM_STBURA0
| /* tx buffer underrun a.q.0 */
191 FM_STBURA1
)) { /* tx buffer underrun a.q.2 */
192 SMT_PANIC(smc
,SMT_E0133
, SMT_E0133_MSG
) ;
195 if ( (stu
& (FM_SXMTABT
| /* transmit abort */
196 FM_STXABRS
| /* syn. tx abort */
197 FM_STXABRA0
)) || /* asyn. tx abort */
198 (stl
& (FM_SQLCKS
| /* lock for syn. q. */
199 FM_SQLCKA0
)) ) { /* lock for asyn. q. */
200 formac_tx_restart(smc
) ; /* init tx */
202 stu
= inpw(FM_A(FM_ST1U
)) ;
203 stl
= inpw(FM_A(FM_ST1L
)) ;
204 stu
&= ~ (FM_STECFRMA0
| FM_STEFRMA0
| FM_STEFRMS
) ;
209 if (stu
& (FM_STEFRMA0
| /* end of asyn tx */
210 FM_STEFRMS
)) { /* end of sync tx */
215 llc_restart_tx(smc
) ;
219 * interrupt source= plc1
220 * this function is called in nwfbisr.asm
222 void plc1_irq(struct s_smc
*smc
)
224 u_short st
= inpw(PLC(PB
,PL_INTR_EVENT
)) ;
230 * interrupt source= plc2
231 * this function is called in nwfbisr.asm
233 void plc2_irq(struct s_smc
*smc
)
235 u_short st
= inpw(PLC(PA
,PL_INTR_EVENT
)) ;
242 * interrupt source= timer
244 void timer_irq(struct s_smc
*smc
)
247 smc
->hw
.t_stop
= smc
->hw
.t_start
;
248 smt_timer_done(smc
) ;
252 * return S-port (PA or PB)
254 int pcm_get_s_port(struct s_smc
*smc
)
261 * Station Label = "FDDI-XYZ" where
267 #define STATION_LABEL_CONNECTOR_OFFSET 5
268 #define STATION_LABEL_PMD_OFFSET 6
269 #define STATION_LABEL_PORT_OFFSET 7
271 void read_address(struct s_smc
*smc
, u_char
*mac_addr
)
278 for (i
= 0; i
< 6; i
++) { /* read mac address from board */
279 smc
->hw
.fddi_phys_addr
.a
[i
] =
280 bitrev8(inp(ADDR(B2_MAC_0
+i
)));
284 ConnectorType
= inp(ADDR(B2_CONN_TYP
)) ;
285 PmdType
= inp(ADDR(B2_PMD_TYP
)) ;
287 smc
->y
[PA
].pmd_type
[PMD_SK_CONN
] =
288 smc
->y
[PB
].pmd_type
[PMD_SK_CONN
] = ConnectorType
;
289 smc
->y
[PA
].pmd_type
[PMD_SK_PMD
] =
290 smc
->y
[PB
].pmd_type
[PMD_SK_PMD
] = PmdType
;
293 for (i
= 0; i
< 6 ;i
++) {
294 smc
->hw
.fddi_canon_addr
.a
[i
] = mac_addr
[i
] ;
295 smc
->hw
.fddi_home_addr
.a
[i
] = bitrev8(mac_addr
[i
]);
299 smc
->hw
.fddi_home_addr
= smc
->hw
.fddi_phys_addr
;
301 for (i
= 0; i
< 6 ;i
++) {
302 smc
->hw
.fddi_canon_addr
.a
[i
] =
303 bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
308 * FDDI card soft reset
310 void init_board(struct s_smc
*smc
, u_char
*mac_addr
)
313 read_address(smc
,mac_addr
) ;
315 if (!(inp(ADDR(B0_DAS
)) & DAS_AVAIL
))
316 smc
->s
.sas
= SMT_SAS
; /* Single att. station */
318 smc
->s
.sas
= SMT_DAS
; /* Dual att. station */
320 if (!(inp(ADDR(B0_DAS
)) & DAS_BYP_ST
))
321 smc
->mib
.fddiSMTBypassPresent
= 0 ;
322 /* without opt. bypass */
324 smc
->mib
.fddiSMTBypassPresent
= 1 ;
325 /* with opt. bypass */
329 * insert or deinsert optical bypass (called by ECM)
331 void sm_pm_bypass_req(struct s_smc
*smc
, int mode
)
333 DB_ECMN(1,"ECM : sm_pm_bypass_req(%s)\n",(mode
== BP_INSERT
) ?
334 "BP_INSERT" : "BP_DEINSERT",0) ;
336 if (smc
->s
.sas
!= SMT_DAS
)
342 outp(ADDR(B0_DAS
),DAS_BYP_INS
) ; /* insert station */
345 outp(ADDR(B0_DAS
),DAS_BYP_RMV
) ; /* bypass station */
352 * check if bypass connected
354 int sm_pm_bypass_present(struct s_smc
*smc
)
356 return( (inp(ADDR(B0_DAS
)) & DAS_BYP_ST
) ? TRUE
: FALSE
) ;
359 void plc_clear_irq(struct s_smc
*smc
, int p
)
368 * led_indication called by rmt_indication() and
374 * 0 Only switch green LEDs according to their respective PCM state
375 * LED_Y_OFF just switch yellow LED off
376 * LED_Y_ON just switch yello LED on
378 static void led_indication(struct s_smc
*smc
, int led_event
)
380 /* use smc->hw.mac_ring_is_up == TRUE
381 * as indication for Ring Operational
385 struct fddi_mib_p
*mib_a
;
386 struct fddi_mib_p
*mib_b
;
396 /* Ring up = yellow led OFF*/
397 if (led_event
== LED_Y_ON
) {
398 led_state
|= LED_MY_ON
;
400 else if (led_event
== LED_Y_OFF
) {
401 led_state
|= LED_MY_OFF
;
403 else { /* PCM state changed */
404 /* Link at Port A/S = green led A ON */
405 if (mib_a
->fddiPORTPCMState
== PC8_ACTIVE
) {
406 led_state
|= LED_GA_ON
;
409 led_state
|= LED_GA_OFF
;
412 /* Link at Port B = green led B ON */
413 if (mib_b
->fddiPORTPCMState
== PC8_ACTIVE
) {
414 led_state
|= LED_GB_ON
;
417 led_state
|= LED_GB_OFF
;
421 outp(ADDR(B0_LED
), led_state
) ;
427 void pcm_state_change(struct s_smc
*smc
, int plc
, int p_state
)
430 * the current implementation of pcm_state_change() in the driver
431 * parts must be renamed to drv_pcm_state_change() which will be called
432 * now after led_indication.
434 DRV_PCM_STATE_CHANGE(smc
,plc
,p_state
) ;
436 led_indication(smc
,0) ;
440 void rmt_indication(struct s_smc
*smc
, int i
)
442 /* Call a driver special function if defined */
443 DRV_RMT_INDICATION(smc
,i
) ;
445 led_indication(smc
, i
? LED_Y_OFF
: LED_Y_ON
) ;
450 * llc_recover_tx called by init_tx (fplus.c)
452 void llc_recover_tx(struct s_smc
*smc
)
455 extern int load_gen_flag
;
460 smc
->hw
.n_a_send
= 0 ;
467 static int is_equal_num(char comp1
[], char comp2
[], int num
)
471 for (i
= 0 ; i
< num
; i
++) {
472 if (comp1
[i
] != comp2
[i
])
480 * set the OEM ID defaults, and test the contents of the OEM data base
481 * The default OEM is the first ACTIVE entry in the OEM data base
484 * 1 error in data base
488 int set_oi_id_def(struct s_smc
*smc
)
496 act_entries
= FALSE
;
498 smc
->hw
.oem_min_status
= OI_STAT_ACTIVE
;
500 /* check OEM data base */
501 while (oem_ids
[i
].oi_status
) {
502 switch (oem_ids
[i
].oi_status
) {
504 act_entries
= TRUE
; /* we have active IDs */
506 sel_id
= i
; /* save the first active ID */
508 case OI_STAT_PRESENT
:
510 break ; /* entry ok */
512 return (1) ; /* invalid oi_status */
521 /* ok, we have a valid OEM data base with an active entry */
522 smc
->hw
.oem_id
= (struct s_oem_ids
*) &oem_ids
[sel_id
] ;
525 #endif /* MULT_OEM */
527 void driver_get_bia(struct s_smc
*smc
, struct fddi_addr
*bia_addr
)
531 for (i
= 0 ; i
< 6 ; i
++)
532 bia_addr
->a
[i
] = bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
535 void smt_start_watchdog(struct s_smc
*smc
)
537 SK_UNUSED(smc
) ; /* Make LINT happy. */
542 if (smc
->hw
.wdog_used
) {
543 outpw(ADDR(B2_WDOG_CRTL
),TIM_START
) ; /* Start timer. */
550 static void smt_stop_watchdog(struct s_smc
*smc
)
552 SK_UNUSED(smc
) ; /* Make LINT happy. */
556 if (smc
->hw
.wdog_used
) {
557 outpw(ADDR(B2_WDOG_CRTL
),TIM_STOP
) ; /* Stop timer. */
566 void mac_do_pci_fix(struct s_smc
*smc
)