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:
51 * | --------------------- the patched POS_ID of the Adapter
52 * | xxxx = (Vendor ID low byte,
53 * | Vendor ID high byte,
54 * | Device ID low byte,
55 * | Device ID high byte)
56 * +------------------------------ the patched oem_id must be
57 * 'S' for SK or 'I' for IBM
58 * this is a short id for the driver.
62 const u_char oem_id
[] = "xPOS_ID:xxxx" ;
63 #else /* OEM_CONCEPT */
64 const u_char oem_id
[] = OEM_ID
;
65 #endif /* OEM_CONCEPT */
67 #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
69 const struct s_oem_ids oem_ids
[] = {
73 #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
76 /* Prototypes of external functions */
78 extern int AIX_vpdReadByte() ;
82 /* Prototype of a local function. */
83 static void smt_stop_watchdog(struct s_smc
*smc
);
88 static void card_start(struct s_smc
*smc
)
96 smt_stop_watchdog(smc
) ;
100 * make sure no transfer activity is pending
102 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
103 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
104 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
106 * now reset everything
108 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
109 i
= (int) inp(ADDR(B0_CTRL
)) ; /* do dummy read */
110 SK_UNUSED(i
) ; /* Make LINT happy. */
111 outp(ADDR(B0_CTRL
), CTRL_RST_CLR
) ;
114 * Reset all bits in the PCI STATUS register
116 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_ON
) ; /* enable for writes */
117 word
= inpw(PCI_C(PCI_STATUS
)) ;
118 outpw(PCI_C(PCI_STATUS
), word
| PCI_ERRBITS
) ;
119 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_OFF
) ; /* disable writes */
122 * Release the reset of all the State machines
123 * Release Master_Reset
124 * Release HPI_SM_Reset
126 outp(ADDR(B0_CTRL
), CTRL_MRST_CLR
|CTRL_HPI_CLR
) ;
129 * determine the adapter type
130 * Note: Do it here, because some drivers may call card_start() once
131 * at very first before any other initialization functions is
134 rev_id
= inp(PCI_C(PCI_REV_ID
)) ;
135 if ((rev_id
& 0xf0) == SK_ML_ID_1
|| (rev_id
& 0xf0) == SK_ML_ID_2
) {
136 smc
->hw
.hw_is_64bit
= TRUE
;
138 smc
->hw
.hw_is_64bit
= FALSE
;
142 * Watermark initialization
144 if (!smc
->hw
.hw_is_64bit
) {
145 outpd(ADDR(B4_R1_F
), RX_WATERMARK
) ;
146 outpd(ADDR(B5_XA_F
), TX_WATERMARK
) ;
147 outpd(ADDR(B5_XS_F
), TX_WATERMARK
) ;
150 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* clear the reset chips */
151 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_ON
|LED_GB_OFF
) ; /* ye LED on */
153 /* init the timer value for the watch dog 2,5 minutes */
154 outpd(ADDR(B2_WDOG_INI
),0x6FC23AC0) ;
156 /* initialize the ISR mask */
157 smc
->hw
.is_imask
= ISR_MASK
;
158 smc
->hw
.hw_state
= STOPPED
;
160 GET_PAGE(0) ; /* necessary for BOOT */
163 void card_stop(struct s_smc
*smc
)
165 smt_stop_watchdog(smc
) ;
166 smc
->hw
.mac_ring_is_up
= 0 ; /* ring down */
170 * make sure no transfer activity is pending
172 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
173 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
174 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
176 * now reset everything
178 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
179 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* reset for all chips */
180 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_OFF
|LED_GB_OFF
) ; /* all LEDs off */
181 smc
->hw
.hw_state
= STOPPED
;
184 /*--------------------------- ISR handling ----------------------------------*/
186 void mac1_irq(struct s_smc
*smc
, u_short stu
, u_short stl
)
192 * parity error: note encoding error is not possible in tag mode
194 if (stl
& (FM_SPCEPDS
| /* parity err. syn.q.*/
195 FM_SPCEPDA0
| /* parity err. a.q.0 */
196 FM_SPCEPDA1
)) { /* parity err. a.q.1 */
197 SMT_PANIC(smc
,SMT_E0134
, SMT_E0134_MSG
) ;
200 * buffer underrun: can only occur if a tx threshold is specified
202 if (stl
& (FM_STBURS
| /* tx buffer underrun syn.q.*/
203 FM_STBURA0
| /* tx buffer underrun a.q.0 */
204 FM_STBURA1
)) { /* tx buffer underrun a.q.2 */
205 SMT_PANIC(smc
,SMT_E0133
, SMT_E0133_MSG
) ;
208 if ( (stu
& (FM_SXMTABT
| /* transmit abort */
209 FM_STXABRS
| /* syn. tx abort */
210 FM_STXABRA0
)) || /* asyn. tx abort */
211 (stl
& (FM_SQLCKS
| /* lock for syn. q. */
212 FM_SQLCKA0
)) ) { /* lock for asyn. q. */
213 formac_tx_restart(smc
) ; /* init tx */
215 stu
= inpw(FM_A(FM_ST1U
)) ;
216 stl
= inpw(FM_A(FM_ST1L
)) ;
217 stu
&= ~ (FM_STECFRMA0
| FM_STEFRMA0
| FM_STEFRMS
) ;
222 if (stu
& (FM_STEFRMA0
| /* end of asyn tx */
223 FM_STEFRMS
)) { /* end of sync tx */
228 llc_restart_tx(smc
) ;
232 * interrupt source= plc1
233 * this function is called in nwfbisr.asm
235 void plc1_irq(struct s_smc
*smc
)
237 u_short st
= inpw(PLC(PB
,PL_INTR_EVENT
)) ;
243 * interrupt source= plc2
244 * this function is called in nwfbisr.asm
246 void plc2_irq(struct s_smc
*smc
)
248 u_short st
= inpw(PLC(PA
,PL_INTR_EVENT
)) ;
255 * interrupt source= timer
257 void timer_irq(struct s_smc
*smc
)
260 smc
->hw
.t_stop
= smc
->hw
.t_start
;
261 smt_timer_done(smc
) ;
265 * return S-port (PA or PB)
267 int pcm_get_s_port(struct s_smc
*smc
)
274 * Station Label = "FDDI-XYZ" where
280 #define STATION_LABEL_CONNECTOR_OFFSET 5
281 #define STATION_LABEL_PMD_OFFSET 6
282 #define STATION_LABEL_PORT_OFFSET 7
284 void read_address(struct s_smc
*smc
, u_char
*mac_addr
)
291 for (i
= 0; i
< 6; i
++) { /* read mac address from board */
292 smc
->hw
.fddi_phys_addr
.a
[i
] =
293 bitrev8(inp(ADDR(B2_MAC_0
+i
)));
297 ConnectorType
= inp(ADDR(B2_CONN_TYP
)) ;
298 PmdType
= inp(ADDR(B2_PMD_TYP
)) ;
300 smc
->y
[PA
].pmd_type
[PMD_SK_CONN
] =
301 smc
->y
[PB
].pmd_type
[PMD_SK_CONN
] = ConnectorType
;
302 smc
->y
[PA
].pmd_type
[PMD_SK_PMD
] =
303 smc
->y
[PB
].pmd_type
[PMD_SK_PMD
] = PmdType
;
306 for (i
= 0; i
< 6 ;i
++) {
307 smc
->hw
.fddi_canon_addr
.a
[i
] = mac_addr
[i
] ;
308 smc
->hw
.fddi_home_addr
.a
[i
] = bitrev8(mac_addr
[i
]);
312 smc
->hw
.fddi_home_addr
= smc
->hw
.fddi_phys_addr
;
314 for (i
= 0; i
< 6 ;i
++) {
315 smc
->hw
.fddi_canon_addr
.a
[i
] =
316 bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
321 * FDDI card soft reset
323 void init_board(struct s_smc
*smc
, u_char
*mac_addr
)
326 read_address(smc
,mac_addr
) ;
328 if (!(inp(ADDR(B0_DAS
)) & DAS_AVAIL
))
329 smc
->s
.sas
= SMT_SAS
; /* Single att. station */
331 smc
->s
.sas
= SMT_DAS
; /* Dual att. station */
333 if (!(inp(ADDR(B0_DAS
)) & DAS_BYP_ST
))
334 smc
->mib
.fddiSMTBypassPresent
= 0 ;
335 /* without opt. bypass */
337 smc
->mib
.fddiSMTBypassPresent
= 1 ;
338 /* with opt. bypass */
342 * insert or deinsert optical bypass (called by ECM)
344 void sm_pm_bypass_req(struct s_smc
*smc
, int mode
)
346 DB_ECMN(1,"ECM : sm_pm_bypass_req(%s)\n",(mode
== BP_INSERT
) ?
347 "BP_INSERT" : "BP_DEINSERT",0) ;
349 if (smc
->s
.sas
!= SMT_DAS
)
355 outp(ADDR(B0_DAS
),DAS_BYP_INS
) ; /* insert station */
358 outp(ADDR(B0_DAS
),DAS_BYP_RMV
) ; /* bypass station */
365 * check if bypass connected
367 int sm_pm_bypass_present(struct s_smc
*smc
)
369 return (inp(ADDR(B0_DAS
)) & DAS_BYP_ST
) ? TRUE
: FALSE
;
372 void plc_clear_irq(struct s_smc
*smc
, int p
)
381 * led_indication called by rmt_indication() and
387 * 0 Only switch green LEDs according to their respective PCM state
388 * LED_Y_OFF just switch yellow LED off
389 * LED_Y_ON just switch yello LED on
391 static void led_indication(struct s_smc
*smc
, int led_event
)
393 /* use smc->hw.mac_ring_is_up == TRUE
394 * as indication for Ring Operational
398 struct fddi_mib_p
*mib_a
;
399 struct fddi_mib_p
*mib_b
;
409 /* Ring up = yellow led OFF*/
410 if (led_event
== LED_Y_ON
) {
411 led_state
|= LED_MY_ON
;
413 else if (led_event
== LED_Y_OFF
) {
414 led_state
|= LED_MY_OFF
;
416 else { /* PCM state changed */
417 /* Link at Port A/S = green led A ON */
418 if (mib_a
->fddiPORTPCMState
== PC8_ACTIVE
) {
419 led_state
|= LED_GA_ON
;
422 led_state
|= LED_GA_OFF
;
425 /* Link at Port B = green led B ON */
426 if (mib_b
->fddiPORTPCMState
== PC8_ACTIVE
) {
427 led_state
|= LED_GB_ON
;
430 led_state
|= LED_GB_OFF
;
434 outp(ADDR(B0_LED
), led_state
) ;
440 void pcm_state_change(struct s_smc
*smc
, int plc
, int p_state
)
443 * the current implementation of pcm_state_change() in the driver
444 * parts must be renamed to drv_pcm_state_change() which will be called
445 * now after led_indication.
447 DRV_PCM_STATE_CHANGE(smc
,plc
,p_state
) ;
449 led_indication(smc
,0) ;
453 void rmt_indication(struct s_smc
*smc
, int i
)
455 /* Call a driver special function if defined */
456 DRV_RMT_INDICATION(smc
,i
) ;
458 led_indication(smc
, i
? LED_Y_OFF
: LED_Y_ON
) ;
463 * llc_recover_tx called by init_tx (fplus.c)
465 void llc_recover_tx(struct s_smc
*smc
)
468 extern int load_gen_flag
;
473 smc
->hw
.n_a_send
= 0 ;
480 static int is_equal_num(char comp1
[], char comp2
[], int num
)
484 for (i
= 0 ; i
< num
; i
++) {
485 if (comp1
[i
] != comp2
[i
])
493 * set the OEM ID defaults, and test the contents of the OEM data base
494 * The default OEM is the first ACTIVE entry in the OEM data base
497 * 1 error in data base
501 int set_oi_id_def(struct s_smc
*smc
)
509 act_entries
= FALSE
;
511 smc
->hw
.oem_min_status
= OI_STAT_ACTIVE
;
513 /* check OEM data base */
514 while (oem_ids
[i
].oi_status
) {
515 switch (oem_ids
[i
].oi_status
) {
517 act_entries
= TRUE
; /* we have active IDs */
519 sel_id
= i
; /* save the first active ID */
521 case OI_STAT_PRESENT
:
523 break ; /* entry ok */
525 return 1; /* invalid oi_status */
534 /* ok, we have a valid OEM data base with an active entry */
535 smc
->hw
.oem_id
= (struct s_oem_ids
*) &oem_ids
[sel_id
] ;
538 #endif /* MULT_OEM */
540 void driver_get_bia(struct s_smc
*smc
, struct fddi_addr
*bia_addr
)
544 for (i
= 0 ; i
< 6 ; i
++)
545 bia_addr
->a
[i
] = bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
548 void smt_start_watchdog(struct s_smc
*smc
)
550 SK_UNUSED(smc
) ; /* Make LINT happy. */
555 if (smc
->hw
.wdog_used
) {
556 outpw(ADDR(B2_WDOG_CRTL
),TIM_START
) ; /* Start timer. */
563 static void smt_stop_watchdog(struct s_smc
*smc
)
565 SK_UNUSED(smc
) ; /* Make LINT happy. */
569 if (smc
->hw
.wdog_used
) {
570 outpw(ADDR(B2_WDOG_CRTL
),TIM_STOP
) ; /* Stop timer. */
579 void mac_do_pci_fix(struct s_smc
*smc
)