Lines Matching +full:non +full:- +full:negative
1 // SPDX-License-Identifier: GPL-2.0
28 * struct tb_nvm_vendor_ops - Vendor specific NVM operations
40 * struct tb_nvm_vendor - Vendor to &struct tb_nvm_vendor_ops mapping
54 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_version()
59 * If the switch is in safe-mode the only accessible portion of in intel_switch_nvm_version()
60 * the NVM is the non-active one where userspace is expected to in intel_switch_nvm_version()
63 if (sw->safe_mode) in intel_switch_nvm_version()
70 hdr_size = sw->generation < 3 ? SZ_8K : SZ_16K; in intel_switch_nvm_version()
72 nvm_size = (nvm_size - hdr_size) / 2; in intel_switch_nvm_version()
78 nvm->major = (val >> 16) & 0xff; in intel_switch_nvm_version()
79 nvm->minor = (val >> 8) & 0xff; in intel_switch_nvm_version()
80 nvm->active_size = nvm_size; in intel_switch_nvm_version()
87 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_validate()
90 u8 *buf = nvm->buf; in intel_switch_nvm_validate()
92 image_size = nvm->buf_data_size; in intel_switch_nvm_validate()
100 return -EINVAL; in intel_switch_nvm_validate()
104 return -EINVAL; in intel_switch_nvm_validate()
112 return -EINVAL; in intel_switch_nvm_validate()
114 if (sw->safe_mode) in intel_switch_nvm_validate()
122 if (device_id != sw->config.device_id) in intel_switch_nvm_validate()
123 return -EINVAL; in intel_switch_nvm_validate()
126 nvm->buf_data_start = buf + hdr_size; in intel_switch_nvm_validate()
127 nvm->buf_data_size = image_size - hdr_size; in intel_switch_nvm_validate()
134 struct tb_switch *sw = tb_to_switch(nvm->dev); in intel_switch_nvm_write_headers()
136 if (sw->generation < 3) { in intel_switch_nvm_write_headers()
140 ret = dma_port_flash_write(sw->dma_port, in intel_switch_nvm_write_headers()
141 DMA_PORT_CSS_ADDRESS, nvm->buf + INTEL_NVM_CSS, in intel_switch_nvm_write_headers()
158 struct tb_switch *sw = tb_to_switch(nvm->dev); in asmedia_switch_nvm_version()
166 nvm->major = (val << 16) & 0xff0000; in asmedia_switch_nvm_version()
167 nvm->major |= val & 0x00ff00; in asmedia_switch_nvm_version()
168 nvm->major |= (val >> 16) & 0x0000ff; in asmedia_switch_nvm_version()
174 nvm->minor = (val << 16) & 0xff0000; in asmedia_switch_nvm_version()
175 nvm->minor |= val & 0x00ff00; in asmedia_switch_nvm_version()
176 nvm->minor |= (val >> 16) & 0x0000ff; in asmedia_switch_nvm_version()
179 nvm->active_size = SZ_512K; in asmedia_switch_nvm_version()
197 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in intel_retimer_nvm_version()
205 nvm->major = (val >> 16) & 0xff; in intel_retimer_nvm_version()
206 nvm->minor = (val >> 8) & 0xff; in intel_retimer_nvm_version()
213 nvm_size = (nvm_size - SZ_16K) / 2; in intel_retimer_nvm_version()
214 nvm->active_size = nvm_size; in intel_retimer_nvm_version()
221 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in intel_retimer_nvm_validate()
223 u8 *buf = nvm->buf; in intel_retimer_nvm_validate()
226 image_size = nvm->buf_data_size; in intel_retimer_nvm_validate()
234 return -EINVAL; in intel_retimer_nvm_validate()
238 return -EINVAL; in intel_retimer_nvm_validate()
246 return -EINVAL; in intel_retimer_nvm_validate()
253 if (device != rt->device) in intel_retimer_nvm_validate()
254 return -EINVAL; in intel_retimer_nvm_validate()
257 nvm->buf_data_start = buf + hdr_size; in intel_retimer_nvm_validate()
258 nvm->buf_data_size = image_size - hdr_size; in intel_retimer_nvm_validate()
274 * tb_nvm_alloc() - Allocate new NVM structure
278 * of error returns ERR_PTR(). Specifically returns %-EOPNOTSUPP if the
293 if (v->vendor == sw->config.vendor_id) { in tb_nvm_alloc()
294 vops = v->vops; in tb_nvm_alloc()
301 sw->config.vendor_id); in tb_nvm_alloc()
302 return ERR_PTR(-EOPNOTSUPP); in tb_nvm_alloc()
310 if (v->vendor == rt->vendor) { in tb_nvm_alloc()
311 vops = v->vops; in tb_nvm_alloc()
318 rt->vendor); in tb_nvm_alloc()
319 return ERR_PTR(-EOPNOTSUPP); in tb_nvm_alloc()
322 return ERR_PTR(-EOPNOTSUPP); in tb_nvm_alloc()
327 return ERR_PTR(-ENOMEM); in tb_nvm_alloc()
335 nvm->id = ret; in tb_nvm_alloc()
336 nvm->dev = dev; in tb_nvm_alloc()
337 nvm->vops = vops; in tb_nvm_alloc()
343 * tb_nvm_read_version() - Read and populate NVM version
347 * active NVM version. Returns %0 in case of success and negative errno
352 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_read_version()
354 if (vops && vops->read_version) in tb_nvm_read_version()
355 return vops->read_version(nvm); in tb_nvm_read_version()
357 return -EOPNOTSUPP; in tb_nvm_read_version()
361 * tb_nvm_validate() - Validate new NVM image
365 * checks pass returns %0. As side effect updates @nvm->buf_data_start
366 * and @nvm->buf_data_size fields to match the actual data to be written
369 * If the validation does not pass then returns negative errno.
373 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_validate()
375 u8 *buf = nvm->buf; in tb_nvm_validate()
378 return -EINVAL; in tb_nvm_validate()
380 return -EOPNOTSUPP; in tb_nvm_validate()
383 image_size = nvm->buf_data_size; in tb_nvm_validate()
385 return -EINVAL; in tb_nvm_validate()
391 nvm->buf_data_start = buf; in tb_nvm_validate()
393 return vops->validate ? vops->validate(nvm) : 0; in tb_nvm_validate()
397 * tb_nvm_write_headers() - Write headers before the rest of the image
404 * Returns %0 in case of success and negative errno otherwise.
408 const struct tb_nvm_vendor_ops *vops = nvm->vops; in tb_nvm_write_headers()
410 return vops->write_headers ? vops->write_headers(nvm) : 0; in tb_nvm_write_headers()
414 * tb_nvm_add_active() - Adds active NVMem device to NVM
422 * Returns %0 in success and negative errno otherwise.
434 config.id = nvm->id; in tb_nvm_add_active()
437 config.size = nvm->active_size; in tb_nvm_add_active()
438 config.dev = nvm->dev; in tb_nvm_add_active()
446 nvm->active = nvmem; in tb_nvm_add_active()
451 * tb_nvm_write_buf() - Write data to @nvm buffer
458 * written to the flash. Copies @bytes from @val to @nvm->buf starting
464 if (!nvm->buf) { in tb_nvm_write_buf()
465 nvm->buf = vmalloc(NVM_MAX_SIZE); in tb_nvm_write_buf()
466 if (!nvm->buf) in tb_nvm_write_buf()
467 return -ENOMEM; in tb_nvm_write_buf()
470 nvm->flushed = false; in tb_nvm_write_buf()
471 nvm->buf_data_size = offset + bytes; in tb_nvm_write_buf()
472 memcpy(nvm->buf + offset, val, bytes); in tb_nvm_write_buf()
477 * tb_nvm_add_non_active() - Adds non-active NVMem device to NVM
482 * Registers new non-active NVmem device for @nvm. The @reg_write is called
487 * Returns %0 in success and negative errno otherwise.
499 config.id = nvm->id; in tb_nvm_add_non_active()
503 config.dev = nvm->dev; in tb_nvm_add_non_active()
511 nvm->non_active = nvmem; in tb_nvm_add_non_active()
516 * tb_nvm_free() - Release NVM and its resources
524 nvmem_unregister(nvm->non_active); in tb_nvm_free()
525 nvmem_unregister(nvm->active); in tb_nvm_free()
526 vfree(nvm->buf); in tb_nvm_free()
527 ida_simple_remove(&nvm_ida, nvm->id); in tb_nvm_free()
533 * tb_nvm_read_data() - Read data from NVM
544 * Returns %0 on success and negative errno otherwise.
564 if (ret != -ENODEV && retries--) in tb_nvm_read_data()
569 nbytes -= offset; in tb_nvm_read_data()
572 size -= nbytes; in tb_nvm_read_data()
581 * tb_nvm_write_data() - Write data to NVM
591 * Returns %0 on success and negative errno otherwise.
611 if (ret == -ETIMEDOUT) { in tb_nvm_write_data()
612 if (retries--) in tb_nvm_write_data()
614 ret = -EIO; in tb_nvm_write_data()
619 size -= nbytes; in tb_nvm_write_data()