Lines Matching +full:layer +full:- +full:primary
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org>
14 * all) PA-RISC machines should have them. Anyway, for safety reasons, the
18 * One last word: there's one path we can always count on: the primary path.
19 * Anything above 224 bytes is used for 'osdep2' OS-dependent storage area.
21 * The first OS-dependent area should always be available. Obviously, this is
24 * NOTE: We do not handle the 2 bytes OS-dep area at 0x5D, nor the first
26 * sacrificed: -ETOOLAZY :P
29 * - write: root only
30 * - read: (reading triggers PDC calls) ? root only : everyone
34 * - timer/fastsize write calls
74 MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>");
127 * pdcspath_fetch - This function populates the path entry structs.
136 * This function expects to be called with @entry->rw_lock write-hold.
144 return -EINVAL; in pdcspath_fetch()
146 devpath = &entry->devpath; in pdcspath_fetch()
149 entry, devpath, entry->addr); in pdcspath_fetch()
152 if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) in pdcspath_fetch()
153 return -EIO; in pdcspath_fetch()
158 entry->dev = hwpath_to_device((struct hardware_path *)devpath); in pdcspath_fetch()
160 entry->ready = 1; in pdcspath_fetch()
162 DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); in pdcspath_fetch()
168 * pdcspath_store - This function writes a path to stable storage.
177 * This function expects to be called with @entry->rw_lock write-hold.
186 devpath = &entry->devpath; in pdcspath_store()
191 if (!entry->ready) { in pdcspath_store()
193 BUG_ON(!entry->dev); in pdcspath_store()
194 device_to_hwpath(entry->dev, (struct hardware_path *)devpath); in pdcspath_store()
199 entry, devpath, entry->addr); in pdcspath_store()
202 if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK) in pdcspath_store()
208 entry->ready = 2; in pdcspath_store()
210 DPRINTK("%s: device: 0x%p\n", __func__, entry->dev); in pdcspath_store()
214 * pdcspath_hwpath_read - This function handles hardware path pretty printing.
228 return -EINVAL; in pdcspath_hwpath_read()
230 read_lock(&entry->rw_lock); in pdcspath_hwpath_read()
231 devpath = &entry->devpath; in pdcspath_hwpath_read()
232 i = entry->ready; in pdcspath_hwpath_read()
233 read_unlock(&entry->rw_lock); in pdcspath_hwpath_read()
236 return -ENODATA; in pdcspath_hwpath_read()
239 if (devpath->path.bc[i] < 0) in pdcspath_hwpath_read()
241 out += sprintf(out, "%d/", devpath->path.bc[i]); in pdcspath_hwpath_read()
243 out += sprintf(out, "%u\n", (unsigned char)devpath->path.mod); in pdcspath_hwpath_read()
245 return out - buf; in pdcspath_hwpath_read()
249 * pdcspath_hwpath_write - This function handles hardware path modifying.
255 * Hardware paths are to be given '/'-delimited, without brackets.
273 return -EINVAL; in pdcspath_hwpath_write()
276 count = min_t(size_t, count, sizeof(in)-1); in pdcspath_hwpath_write()
284 return -EINVAL; in pdcspath_hwpath_write()
287 in[temp-in] = '\0'; /* truncate the remaining string. just precaution */ in pdcspath_hwpath_write()
291 we write the bc fields in a down-top way. No matter what, we stop in pdcspath_hwpath_write()
295 for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) { in pdcspath_hwpath_write()
297 in[temp-in] = '\0'; in pdcspath_hwpath_write()
308 "hardware path: %s\n", __func__, entry->name, buf); in pdcspath_hwpath_write()
309 return -EINVAL; in pdcspath_hwpath_write()
313 write_lock(&entry->rw_lock); in pdcspath_hwpath_write()
314 entry->ready = 0; in pdcspath_hwpath_write()
315 entry->dev = dev; in pdcspath_hwpath_write()
321 sysfs_remove_link(&entry->kobj, "device"); in pdcspath_hwpath_write()
322 write_unlock(&entry->rw_lock); in pdcspath_hwpath_write()
324 ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); in pdcspath_hwpath_write()
328 entry->name, buf); in pdcspath_hwpath_write()
334 * pdcspath_layer_read - Extended layer (eg. SCSI ids) pretty printing.
338 * We will call this function to format the output of the layer attribute file.
348 return -EINVAL; in pdcspath_layer_read()
350 read_lock(&entry->rw_lock); in pdcspath_layer_read()
351 devpath = &entry->devpath; in pdcspath_layer_read()
352 i = entry->ready; in pdcspath_layer_read()
353 read_unlock(&entry->rw_lock); in pdcspath_layer_read()
356 return -ENODATA; in pdcspath_layer_read()
358 for (i = 0; i < 6 && devpath->layers[i]; i++) in pdcspath_layer_read()
359 out += sprintf(out, "%u ", devpath->layers[i]); in pdcspath_layer_read()
363 return out - buf; in pdcspath_layer_read()
367 * pdcspath_layer_write - This function handles extended layer modifying.
372 * We will call this function to change the current layer value.
373 * Layers are to be given '.'-delimited, without brackets.
376 * the layer fields.
381 unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ in pdcspath_layer_write()
386 return -EINVAL; in pdcspath_layer_write()
389 count = min_t(size_t, count, sizeof(in)-1); in pdcspath_layer_write()
395 /* First, pick the first layer */ in pdcspath_layer_write()
397 return -EINVAL; in pdcspath_layer_write()
399 DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]); in pdcspath_layer_write()
404 return -EINVAL; in pdcspath_layer_write()
406 DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]); in pdcspath_layer_write()
410 write_lock(&entry->rw_lock); in pdcspath_layer_write()
414 memcpy(&entry->devpath.layers, &layers, sizeof(layers)); in pdcspath_layer_write()
418 write_unlock(&entry->rw_lock); in pdcspath_layer_write()
421 entry->name, buf); in pdcspath_layer_write()
427 * pdcspath_attr_show - Generic read function call wrapper.
439 if (pdcs_attr->show) in pdcspath_attr_show()
440 ret = pdcs_attr->show(entry, buf); in pdcspath_attr_show()
446 * pdcspath_attr_store - Generic write function call wrapper.
461 return -EACCES; in pdcspath_attr_store()
463 if (pdcs_attr->store) in pdcspath_attr_store()
464 ret = pdcs_attr->store(entry, buf, count); in pdcspath_attr_store()
476 static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write);
492 static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary);
511 * pdcs_size_read - Stable Storage size output.
523 return -EINVAL; in pdcs_size_read()
528 return out - buf; in pdcs_size_read()
532 * pdcs_auto_read - Stable Storage autoboot/search flag output.
546 return -EINVAL; in pdcs_auto_read()
548 /* Current flags are stored in primary boot path entry */ in pdcs_auto_read()
551 read_lock(&pathentry->rw_lock); in pdcs_auto_read()
552 out += sprintf(out, "%s\n", (pathentry->devpath.path.flags & knob) ? in pdcs_auto_read()
554 read_unlock(&pathentry->rw_lock); in pdcs_auto_read()
556 return out - buf; in pdcs_auto_read()
560 * pdcs_autoboot_read - Stable Storage autoboot flag output.
572 * pdcs_autosearch_read - Stable Storage autoboot flag output.
584 * pdcs_timer_read - Stable Storage timer count output (in seconds).
598 return -EINVAL; in pdcs_timer_read()
600 /* Current flags are stored in primary boot path entry */ in pdcs_timer_read()
604 read_lock(&pathentry->rw_lock); in pdcs_timer_read()
605 out += sprintf(out, "%u\n", (pathentry->devpath.path.flags & PF_TIMER) ? in pdcs_timer_read()
606 (1 << (pathentry->devpath.path.flags & PF_TIMER)) : 0); in pdcs_timer_read()
607 read_unlock(&pathentry->rw_lock); in pdcs_timer_read()
609 return out - buf; in pdcs_timer_read()
613 * pdcs_osid_read - Stable Storage OS ID register output.
624 return -EINVAL; in pdcs_osid_read()
629 return out - buf; in pdcs_osid_read()
633 * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output.
638 * This can hold 16 bytes of OS-Dependent data.
647 return -EINVAL; in pdcs_osdep1_read()
650 return -EIO; in pdcs_osdep1_read()
657 return out - buf; in pdcs_osdep1_read()
661 * pdcs_diagnostic_read - Stable Storage Diagnostic register output.
666 * I have NFC how to interpret the content of that register ;-).
675 return -EINVAL; in pdcs_diagnostic_read()
679 return -EIO; in pdcs_diagnostic_read()
683 return out - buf; in pdcs_diagnostic_read()
687 * pdcs_fastsize_read - Stable Storage FastSize register output.
701 return -EINVAL; in pdcs_fastsize_read()
703 /* get fast-size */ in pdcs_fastsize_read()
705 return -EIO; in pdcs_fastsize_read()
713 return out - buf; in pdcs_fastsize_read()
717 * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output.
722 * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available.
733 return -ENODATA; in pdcs_osdep2_read()
735 size = pdcs_size - 224; in pdcs_osdep2_read()
738 return -EINVAL; in pdcs_osdep2_read()
743 return -EIO; in pdcs_osdep2_read()
747 return out - buf; in pdcs_osdep2_read()
751 * pdcs_auto_write - This function handles autoboot/search flag modifying.
772 return -EACCES; in pdcs_auto_write()
775 return -EINVAL; in pdcs_auto_write()
778 count = min_t(size_t, count, sizeof(in)-1); in pdcs_auto_write()
781 /* Current flags are stored in primary boot path entry */ in pdcs_auto_write()
785 read_lock(&pathentry->rw_lock); in pdcs_auto_write()
786 flags = pathentry->devpath.path.flags; in pdcs_auto_write()
787 read_unlock(&pathentry->rw_lock); in pdcs_auto_write()
793 c = *temp++ - '0'; in pdcs_auto_write()
804 write_lock(&pathentry->rw_lock); in pdcs_auto_write()
807 pathentry->devpath.path.flags = flags; in pdcs_auto_write()
811 write_unlock(&pathentry->rw_lock); in pdcs_auto_write()
821 return -EINVAL; in pdcs_auto_write()
825 * pdcs_autoboot_write - This function handles autoboot flag modifying.
843 * pdcs_autosearch_write - This function handles autosearch flag modifying.
861 * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input.
867 * This can store 16 bytes of OS-Dependent data. We use a byte-by-byte
878 return -EACCES; in pdcs_osdep1_write()
881 return -EINVAL; in pdcs_osdep1_write()
884 return -EPERM; in pdcs_osdep1_write()
887 return -EMSGSIZE; in pdcs_osdep1_write()
894 return -EIO; in pdcs_osdep1_write()
900 * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input.
906 * This can store pdcs_size - 224 bytes of OS-Dependent data. We use a
907 * byte-by-byte write approach. It's up to userspace to deal with it when
919 return -EACCES; in pdcs_osdep2_write()
922 return -EINVAL; in pdcs_osdep2_write()
925 return -ENOSYS; in pdcs_osdep2_write()
928 return -EPERM; in pdcs_osdep2_write()
930 size = pdcs_size - 224; in pdcs_osdep2_write()
933 return -EMSGSIZE; in pdcs_osdep2_write()
939 memcpy(in, buf+i, (count-i < 4) ? count-i : 4); in pdcs_osdep2_write()
942 return -EIO; in pdcs_osdep2_write()
980 * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
997 rwlock_init(&entry->rw_lock); in pdcs_register_pathentries()
1000 write_lock(&entry->rw_lock); in pdcs_register_pathentries()
1002 write_unlock(&entry->rw_lock); in pdcs_register_pathentries()
1007 entry->kobj.kset = paths_kset; in pdcs_register_pathentries()
1008 err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL, in pdcs_register_pathentries()
1009 "%s", entry->name); in pdcs_register_pathentries()
1011 kobject_put(&entry->kobj); in pdcs_register_pathentries()
1016 write_lock(&entry->rw_lock); in pdcs_register_pathentries()
1017 entry->ready = 2; in pdcs_register_pathentries()
1018 write_unlock(&entry->rw_lock); in pdcs_register_pathentries()
1021 if (entry->dev) { in pdcs_register_pathentries()
1022 err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device"); in pdcs_register_pathentries()
1026 kobject_uevent(&entry->kobj, KOBJ_ADD); in pdcs_register_pathentries()
1033 * pdcs_unregister_pathentries - Routine called when unregistering the module.
1042 read_lock(&entry->rw_lock); in pdcs_unregister_pathentries()
1043 if (entry->ready >= 2) in pdcs_unregister_pathentries()
1044 kobject_put(&entry->kobj); in pdcs_unregister_pathentries()
1045 read_unlock(&entry->rw_lock); in pdcs_unregister_pathentries()
1061 return -ENODEV; in pdc_stable_init()
1065 return -ENODATA; in pdc_stable_init()
1071 return -EIO; in pdc_stable_init()
1079 rc = -ENOMEM; in pdc_stable_init()
1086 rc = -ENOMEM; in pdc_stable_init()
1093 rc = -ENOMEM; in pdc_stable_init()