Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

m68k/scsi: gvp11 - Extract check_wd33c93()

Acked-by: James Bottomley <James.Bottomley@suse.de>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

+83 -77
+83 -77
drivers/scsi/gvp11.c
··· 22 22 #include <linux/stat.h> 23 23 24 24 25 + #define CHECK_WD33C93 26 + 25 27 static irqreturn_t gvp11_intr(int irq, void *data) 26 28 { 27 29 struct Scsi_Host *instance = data; ··· 169 167 } 170 168 } 171 169 172 - #define CHECK_WD33C93 170 + static int __init check_wd33c93(gvp11_scsiregs *regs) 171 + { 172 + #ifdef CHECK_WD33C93 173 + volatile unsigned char *sasr_3393, *scmd_3393; 174 + unsigned char save_sasr; 175 + unsigned char q, qq; 176 + 177 + /* 178 + * These darn GVP boards are a problem - it can be tough to tell 179 + * whether or not they include a SCSI controller. This is the 180 + * ultimate Yet-Another-GVP-Detection-Hack in that it actually 181 + * probes for a WD33c93 chip: If we find one, it's extremely 182 + * likely that this card supports SCSI, regardless of Product_ 183 + * Code, Board_Size, etc. 184 + */ 185 + 186 + /* Get pointers to the presumed register locations and save contents */ 187 + 188 + sasr_3393 = &regs->SASR; 189 + scmd_3393 = &regs->SCMD; 190 + save_sasr = *sasr_3393; 191 + 192 + /* First test the AuxStatus Reg */ 193 + 194 + q = *sasr_3393; /* read it */ 195 + if (q & 0x08) /* bit 3 should always be clear */ 196 + return -ENODEV; 197 + *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */ 198 + if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */ 199 + *sasr_3393 = save_sasr; /* Oops - restore this byte */ 200 + return -ENODEV; 201 + } 202 + if (*sasr_3393 != q) { /* should still read the same */ 203 + *sasr_3393 = save_sasr; /* Oops - restore this byte */ 204 + return -ENODEV; 205 + } 206 + if (*scmd_3393 != q) /* and so should the image at 0x1f */ 207 + return -ENODEV; 208 + 209 + /* 210 + * Ok, we probably have a wd33c93, but let's check a few other places 211 + * for good measure. Make sure that this works for both 'A and 'B 212 + * chip versions. 213 + */ 214 + 215 + *sasr_3393 = WD_SCSI_STATUS; 216 + q = *scmd_3393; 217 + *sasr_3393 = WD_SCSI_STATUS; 218 + *scmd_3393 = ~q; 219 + *sasr_3393 = WD_SCSI_STATUS; 220 + qq = *scmd_3393; 221 + *sasr_3393 = WD_SCSI_STATUS; 222 + *scmd_3393 = q; 223 + if (qq != q) /* should be read only */ 224 + return -ENODEV; 225 + *sasr_3393 = 0x1e; /* this register is unimplemented */ 226 + q = *scmd_3393; 227 + *sasr_3393 = 0x1e; 228 + *scmd_3393 = ~q; 229 + *sasr_3393 = 0x1e; 230 + qq = *scmd_3393; 231 + *sasr_3393 = 0x1e; 232 + *scmd_3393 = q; 233 + if (qq != q || qq != 0xff) /* should be read only, all 1's */ 234 + return -ENODEV; 235 + *sasr_3393 = WD_TIMEOUT_PERIOD; 236 + q = *scmd_3393; 237 + *sasr_3393 = WD_TIMEOUT_PERIOD; 238 + *scmd_3393 = ~q; 239 + *sasr_3393 = WD_TIMEOUT_PERIOD; 240 + qq = *scmd_3393; 241 + *sasr_3393 = WD_TIMEOUT_PERIOD; 242 + *scmd_3393 = q; 243 + if (qq != (~q & 0xff)) /* should be read/write */ 244 + return -ENODEV; 245 + #endif /* CHECK_WD33C93 */ 246 + 247 + return 0; 248 + } 173 249 174 250 int __init gvp11_detect(struct scsi_host_template *tpnt) 175 251 { ··· 261 181 gvp11_scsiregs *regs; 262 182 wd33c93_regs wdregs; 263 183 int num_gvp11 = 0; 264 - #ifdef CHECK_WD33C93 265 - volatile unsigned char *sasr_3393, *scmd_3393; 266 - unsigned char save_sasr; 267 - unsigned char q, qq; 268 - #endif 269 184 270 185 if (!MACH_IS_AMIGA || called) 271 186 return 0; ··· 301 226 if (!request_mem_region(address, 256, "wd33c93")) 302 227 continue; 303 228 304 - #ifdef CHECK_WD33C93 305 - 306 - /* 307 - * These darn GVP boards are a problem - it can be tough to tell 308 - * whether or not they include a SCSI controller. This is the 309 - * ultimate Yet-Another-GVP-Detection-Hack in that it actually 310 - * probes for a WD33c93 chip: If we find one, it's extremely 311 - * likely that this card supports SCSI, regardless of Product_ 312 - * Code, Board_Size, etc. 313 - */ 314 - 315 - /* Get pointers to the presumed register locations and save contents */ 316 - 317 - sasr_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SASR); 318 - scmd_3393 = &(((gvp11_scsiregs *)(ZTWO_VADDR(address)))->SCMD); 319 - save_sasr = *sasr_3393; 320 - 321 - /* First test the AuxStatus Reg */ 322 - 323 - q = *sasr_3393; /* read it */ 324 - if (q & 0x08) /* bit 3 should always be clear */ 229 + regs = (gvp11_scsiregs *)(ZTWO_VADDR(address)); 230 + if (check_wd33c93(regs)) 325 231 goto release; 326 - *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */ 327 - if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */ 328 - *sasr_3393 = save_sasr; /* Oops - restore this byte */ 329 - goto release; 330 - } 331 - if (*sasr_3393 != q) { /* should still read the same */ 332 - *sasr_3393 = save_sasr; /* Oops - restore this byte */ 333 - goto release; 334 - } 335 - if (*scmd_3393 != q) /* and so should the image at 0x1f */ 336 - goto release; 337 - 338 - /* 339 - * Ok, we probably have a wd33c93, but let's check a few other places 340 - * for good measure. Make sure that this works for both 'A and 'B 341 - * chip versions. 342 - */ 343 - 344 - *sasr_3393 = WD_SCSI_STATUS; 345 - q = *scmd_3393; 346 - *sasr_3393 = WD_SCSI_STATUS; 347 - *scmd_3393 = ~q; 348 - *sasr_3393 = WD_SCSI_STATUS; 349 - qq = *scmd_3393; 350 - *sasr_3393 = WD_SCSI_STATUS; 351 - *scmd_3393 = q; 352 - if (qq != q) /* should be read only */ 353 - goto release; 354 - *sasr_3393 = 0x1e; /* this register is unimplemented */ 355 - q = *scmd_3393; 356 - *sasr_3393 = 0x1e; 357 - *scmd_3393 = ~q; 358 - *sasr_3393 = 0x1e; 359 - qq = *scmd_3393; 360 - *sasr_3393 = 0x1e; 361 - *scmd_3393 = q; 362 - if (qq != q || qq != 0xff) /* should be read only, all 1's */ 363 - goto release; 364 - *sasr_3393 = WD_TIMEOUT_PERIOD; 365 - q = *scmd_3393; 366 - *sasr_3393 = WD_TIMEOUT_PERIOD; 367 - *scmd_3393 = ~q; 368 - *sasr_3393 = WD_TIMEOUT_PERIOD; 369 - qq = *scmd_3393; 370 - *sasr_3393 = WD_TIMEOUT_PERIOD; 371 - *scmd_3393 = q; 372 - if (qq != (~q & 0xff)) /* should be read/write */ 373 - goto release; 374 - #endif 375 232 376 233 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata)); 377 234 if (instance == NULL) ··· 318 311 else 319 312 hdata->dma_xfer_mask = default_dma_xfer_mask; 320 313 321 - regs = (gvp11_scsiregs *)(instance->base); 322 314 regs->secret2 = 1; 323 315 regs->secret1 = 0; 324 316 regs->secret3 = 15;