1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
14 * FBI board dependent Driver for SMT and LLC
20 #include "h/supern_2.h"
21 #include "h/skfbiinc.h"
22 #include <linux/bitrev.h>
25 static const char ID_sccs
[] = "@(#)drvfbi.c 1.63 99/02/11 (C) SK " ;
33 #define LED_Y_ON 0x11 /* Used for ring up/down indication */
34 #define LED_Y_OFF 0x10
37 #define MS2BCLK(x) ((x)*12500L)
40 * valid configuration values are:
47 * | --------------------- the patched POS_ID of the Adapter
48 * | xxxx = (Vendor ID low byte,
49 * | Vendor ID high byte,
50 * | Device ID low byte,
51 * | Device ID high byte)
52 * +------------------------------ the patched oem_id must be
53 * 'S' for SK or 'I' for IBM
54 * this is a short id for the driver.
58 const u_char oem_id
[] = "xPOS_ID:xxxx" ;
59 #else /* OEM_CONCEPT */
60 const u_char oem_id
[] = OEM_ID
;
61 #endif /* OEM_CONCEPT */
63 #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
65 const struct s_oem_ids oem_ids
[] = {
69 #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
72 /* Prototypes of external functions */
74 extern int AIX_vpdReadByte() ;
78 /* Prototype of a local function. */
79 static void smt_stop_watchdog(struct s_smc
*smc
);
84 static void card_start(struct s_smc
*smc
)
92 smt_stop_watchdog(smc
) ;
96 * make sure no transfer activity is pending
98 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
99 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
100 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
102 * now reset everything
104 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
105 i
= (int) inp(ADDR(B0_CTRL
)) ; /* do dummy read */
106 SK_UNUSED(i
) ; /* Make LINT happy. */
107 outp(ADDR(B0_CTRL
), CTRL_RST_CLR
) ;
110 * Reset all bits in the PCI STATUS register
112 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_ON
) ; /* enable for writes */
113 word
= inpw(PCI_C(PCI_STATUS
)) ;
114 outpw(PCI_C(PCI_STATUS
), word
| PCI_ERRBITS
) ;
115 outp(ADDR(B0_TST_CTRL
), TST_CFG_WRITE_OFF
) ; /* disable writes */
118 * Release the reset of all the State machines
119 * Release Master_Reset
120 * Release HPI_SM_Reset
122 outp(ADDR(B0_CTRL
), CTRL_MRST_CLR
|CTRL_HPI_CLR
) ;
125 * determine the adapter type
126 * Note: Do it here, because some drivers may call card_start() once
127 * at very first before any other initialization functions is
130 rev_id
= inp(PCI_C(PCI_REV_ID
)) ;
131 if ((rev_id
& 0xf0) == SK_ML_ID_1
|| (rev_id
& 0xf0) == SK_ML_ID_2
) {
132 smc
->hw
.hw_is_64bit
= TRUE
;
134 smc
->hw
.hw_is_64bit
= FALSE
;
138 * Watermark initialization
140 if (!smc
->hw
.hw_is_64bit
) {
141 outpd(ADDR(B4_R1_F
), RX_WATERMARK
) ;
142 outpd(ADDR(B5_XA_F
), TX_WATERMARK
) ;
143 outpd(ADDR(B5_XS_F
), TX_WATERMARK
) ;
146 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* clear the reset chips */
147 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_ON
|LED_GB_OFF
) ; /* ye LED on */
149 /* init the timer value for the watch dog 2,5 minutes */
150 outpd(ADDR(B2_WDOG_INI
),0x6FC23AC0) ;
152 /* initialize the ISR mask */
153 smc
->hw
.is_imask
= ISR_MASK
;
154 smc
->hw
.hw_state
= STOPPED
;
156 GET_PAGE(0) ; /* necessary for BOOT */
159 void card_stop(struct s_smc
*smc
)
161 smt_stop_watchdog(smc
) ;
162 smc
->hw
.mac_ring_is_up
= 0 ; /* ring down */
166 * make sure no transfer activity is pending
168 outpw(FM_A(FM_MDREG1
),FM_MINIT
) ;
169 outp(ADDR(B0_CTRL
), CTRL_HPI_SET
) ;
170 hwt_wait_time(smc
,hwt_quick_read(smc
),MS2BCLK(10)) ;
172 * now reset everything
174 outp(ADDR(B0_CTRL
),CTRL_RST_SET
) ; /* reset for all chips */
175 outp(ADDR(B0_CTRL
),CTRL_RST_CLR
) ; /* reset for all chips */
176 outp(ADDR(B0_LED
),LED_GA_OFF
|LED_MY_OFF
|LED_GB_OFF
) ; /* all LEDs off */
177 smc
->hw
.hw_state
= STOPPED
;
180 /*--------------------------- ISR handling ----------------------------------*/
182 void mac1_irq(struct s_smc
*smc
, u_short stu
, u_short stl
)
188 * parity error: note encoding error is not possible in tag mode
190 if (stl
& (FM_SPCEPDS
| /* parity err. syn.q.*/
191 FM_SPCEPDA0
| /* parity err. a.q.0 */
192 FM_SPCEPDA1
)) { /* parity err. a.q.1 */
193 SMT_PANIC(smc
,SMT_E0134
, SMT_E0134_MSG
) ;
196 * buffer underrun: can only occur if a tx threshold is specified
198 if (stl
& (FM_STBURS
| /* tx buffer underrun syn.q.*/
199 FM_STBURA0
| /* tx buffer underrun a.q.0 */
200 FM_STBURA1
)) { /* tx buffer underrun a.q.2 */
201 SMT_PANIC(smc
,SMT_E0133
, SMT_E0133_MSG
) ;
204 if ( (stu
& (FM_SXMTABT
| /* transmit abort */
205 FM_STXABRS
| /* syn. tx abort */
206 FM_STXABRA0
)) || /* asyn. tx abort */
207 (stl
& (FM_SQLCKS
| /* lock for syn. q. */
208 FM_SQLCKA0
)) ) { /* lock for asyn. q. */
209 formac_tx_restart(smc
) ; /* init tx */
211 stu
= inpw(FM_A(FM_ST1U
)) ;
212 stl
= inpw(FM_A(FM_ST1L
)) ;
213 stu
&= ~ (FM_STECFRMA0
| FM_STEFRMA0
| FM_STEFRMS
) ;
218 if (stu
& (FM_STEFRMA0
| /* end of asyn tx */
219 FM_STEFRMS
)) { /* end of sync tx */
224 llc_restart_tx(smc
) ;
228 * interrupt source= plc1
229 * this function is called in nwfbisr.asm
231 void plc1_irq(struct s_smc
*smc
)
233 u_short st
= inpw(PLC(PB
,PL_INTR_EVENT
)) ;
239 * interrupt source= plc2
240 * this function is called in nwfbisr.asm
242 void plc2_irq(struct s_smc
*smc
)
244 u_short st
= inpw(PLC(PA
,PL_INTR_EVENT
)) ;
251 * interrupt source= timer
253 void timer_irq(struct s_smc
*smc
)
256 smc
->hw
.t_stop
= smc
->hw
.t_start
;
257 smt_timer_done(smc
) ;
261 * return S-port (PA or PB)
263 int pcm_get_s_port(struct s_smc
*smc
)
270 * Station Label = "FDDI-XYZ" where
276 #define STATION_LABEL_CONNECTOR_OFFSET 5
277 #define STATION_LABEL_PMD_OFFSET 6
278 #define STATION_LABEL_PORT_OFFSET 7
280 void read_address(struct s_smc
*smc
, u_char
*mac_addr
)
287 for (i
= 0; i
< 6; i
++) { /* read mac address from board */
288 smc
->hw
.fddi_phys_addr
.a
[i
] =
289 bitrev8(inp(ADDR(B2_MAC_0
+i
)));
293 ConnectorType
= inp(ADDR(B2_CONN_TYP
)) ;
294 PmdType
= inp(ADDR(B2_PMD_TYP
)) ;
296 smc
->y
[PA
].pmd_type
[PMD_SK_CONN
] =
297 smc
->y
[PB
].pmd_type
[PMD_SK_CONN
] = ConnectorType
;
298 smc
->y
[PA
].pmd_type
[PMD_SK_PMD
] =
299 smc
->y
[PB
].pmd_type
[PMD_SK_PMD
] = PmdType
;
302 for (i
= 0; i
< 6 ;i
++) {
303 smc
->hw
.fddi_canon_addr
.a
[i
] = mac_addr
[i
] ;
304 smc
->hw
.fddi_home_addr
.a
[i
] = bitrev8(mac_addr
[i
]);
308 smc
->hw
.fddi_home_addr
= smc
->hw
.fddi_phys_addr
;
310 for (i
= 0; i
< 6 ;i
++) {
311 smc
->hw
.fddi_canon_addr
.a
[i
] =
312 bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
317 * FDDI card soft reset
319 void init_board(struct s_smc
*smc
, u_char
*mac_addr
)
322 read_address(smc
,mac_addr
) ;
324 if (!(inp(ADDR(B0_DAS
)) & DAS_AVAIL
))
325 smc
->s
.sas
= SMT_SAS
; /* Single att. station */
327 smc
->s
.sas
= SMT_DAS
; /* Dual att. station */
329 if (!(inp(ADDR(B0_DAS
)) & DAS_BYP_ST
))
330 smc
->mib
.fddiSMTBypassPresent
= 0 ;
331 /* without opt. bypass */
333 smc
->mib
.fddiSMTBypassPresent
= 1 ;
334 /* with opt. bypass */
338 * insert or deinsert optical bypass (called by ECM)
340 void sm_pm_bypass_req(struct s_smc
*smc
, int mode
)
342 DB_ECMN(1, "ECM : sm_pm_bypass_req(%s)",
343 mode
== BP_INSERT
? "BP_INSERT" : "BP_DEINSERT");
345 if (smc
->s
.sas
!= SMT_DAS
)
351 outp(ADDR(B0_DAS
),DAS_BYP_INS
) ; /* insert station */
354 outp(ADDR(B0_DAS
),DAS_BYP_RMV
) ; /* bypass station */
361 * check if bypass connected
363 int sm_pm_bypass_present(struct s_smc
*smc
)
365 return (inp(ADDR(B0_DAS
)) & DAS_BYP_ST
) ? TRUE
: FALSE
;
368 void plc_clear_irq(struct s_smc
*smc
, int p
)
377 * led_indication called by rmt_indication() and
383 * 0 Only switch green LEDs according to their respective PCM state
384 * LED_Y_OFF just switch yellow LED off
385 * LED_Y_ON just switch yello LED on
387 static void led_indication(struct s_smc
*smc
, int led_event
)
389 /* use smc->hw.mac_ring_is_up == TRUE
390 * as indication for Ring Operational
394 struct fddi_mib_p
*mib_a
;
395 struct fddi_mib_p
*mib_b
;
405 /* Ring up = yellow led OFF*/
406 if (led_event
== LED_Y_ON
) {
407 led_state
|= LED_MY_ON
;
409 else if (led_event
== LED_Y_OFF
) {
410 led_state
|= LED_MY_OFF
;
412 else { /* PCM state changed */
413 /* Link at Port A/S = green led A ON */
414 if (mib_a
->fddiPORTPCMState
== PC8_ACTIVE
) {
415 led_state
|= LED_GA_ON
;
418 led_state
|= LED_GA_OFF
;
421 /* Link at Port B = green led B ON */
422 if (mib_b
->fddiPORTPCMState
== PC8_ACTIVE
) {
423 led_state
|= LED_GB_ON
;
426 led_state
|= LED_GB_OFF
;
430 outp(ADDR(B0_LED
), led_state
) ;
436 void pcm_state_change(struct s_smc
*smc
, int plc
, int p_state
)
439 * the current implementation of pcm_state_change() in the driver
440 * parts must be renamed to drv_pcm_state_change() which will be called
441 * now after led_indication.
443 DRV_PCM_STATE_CHANGE(smc
,plc
,p_state
) ;
445 led_indication(smc
,0) ;
449 void rmt_indication(struct s_smc
*smc
, int i
)
451 /* Call a driver special function if defined */
452 DRV_RMT_INDICATION(smc
,i
) ;
454 led_indication(smc
, i
? LED_Y_OFF
: LED_Y_ON
) ;
459 * llc_recover_tx called by init_tx (fplus.c)
461 void llc_recover_tx(struct s_smc
*smc
)
464 extern int load_gen_flag
;
469 smc
->hw
.n_a_send
= 0 ;
476 static int is_equal_num(char comp1
[], char comp2
[], int num
)
480 for (i
= 0 ; i
< num
; i
++) {
481 if (comp1
[i
] != comp2
[i
])
489 * set the OEM ID defaults, and test the contents of the OEM data base
490 * The default OEM is the first ACTIVE entry in the OEM data base
493 * 1 error in data base
497 int set_oi_id_def(struct s_smc
*smc
)
505 act_entries
= FALSE
;
507 smc
->hw
.oem_min_status
= OI_STAT_ACTIVE
;
509 /* check OEM data base */
510 while (oem_ids
[i
].oi_status
) {
511 switch (oem_ids
[i
].oi_status
) {
513 act_entries
= TRUE
; /* we have active IDs */
515 sel_id
= i
; /* save the first active ID */
517 case OI_STAT_PRESENT
:
519 break ; /* entry ok */
521 return 1; /* invalid oi_status */
530 /* ok, we have a valid OEM data base with an active entry */
531 smc
->hw
.oem_id
= (struct s_oem_ids
*) &oem_ids
[sel_id
] ;
534 #endif /* MULT_OEM */
536 void driver_get_bia(struct s_smc
*smc
, struct fddi_addr
*bia_addr
)
540 for (i
= 0 ; i
< 6 ; i
++)
541 bia_addr
->a
[i
] = bitrev8(smc
->hw
.fddi_phys_addr
.a
[i
]);
544 void smt_start_watchdog(struct s_smc
*smc
)
546 SK_UNUSED(smc
) ; /* Make LINT happy. */
551 if (smc
->hw
.wdog_used
) {
552 outpw(ADDR(B2_WDOG_CRTL
),TIM_START
) ; /* Start timer. */
559 static void smt_stop_watchdog(struct s_smc
*smc
)
561 SK_UNUSED(smc
) ; /* Make LINT happy. */
565 if (smc
->hw
.wdog_used
) {
566 outpw(ADDR(B2_WDOG_CRTL
),TIM_STOP
) ; /* Stop timer. */
575 void mac_do_pci_fix(struct s_smc
*smc
)