Lines Matching +full:bus +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
12 /* for the given bus number, return the CSR for reading an i2c line */
18 /* for the given bus number, return the CSR for writing an i2c line */
26 struct hfi1_i2c_bus *bus = (struct hfi1_i2c_bus *)data; in hfi1_setsda() local
27 struct hfi1_devdata *dd = bus->controlling_dd; in hfi1_setsda()
31 target_oe = i2c_oe_csr(bus->num); in hfi1_setsda()
50 struct hfi1_i2c_bus *bus = (struct hfi1_i2c_bus *)data; in hfi1_setscl() local
51 struct hfi1_devdata *dd = bus->controlling_dd; in hfi1_setscl()
55 target_oe = i2c_oe_csr(bus->num); in hfi1_setscl()
74 struct hfi1_i2c_bus *bus = (struct hfi1_i2c_bus *)data; in hfi1_getsda() local
81 target_in = i2c_in_csr(bus->num); in hfi1_getsda()
82 reg = read_csr(bus->controlling_dd, target_in); in hfi1_getsda()
88 struct hfi1_i2c_bus *bus = (struct hfi1_i2c_bus *)data; in hfi1_getscl() local
95 target_in = i2c_in_csr(bus->num); in hfi1_getscl()
96 reg = read_csr(bus->controlling_dd, target_in); in hfi1_getscl()
101 * Allocate and initialize the given i2c bus number.
107 struct hfi1_i2c_bus *bus; in init_i2c_bus() local
110 bus = kzalloc(sizeof(*bus), GFP_KERNEL); in init_i2c_bus()
111 if (!bus) in init_i2c_bus()
114 bus->controlling_dd = dd; in init_i2c_bus()
115 bus->num = num; /* our bus number */ in init_i2c_bus()
117 bus->algo.setsda = hfi1_setsda; in init_i2c_bus()
118 bus->algo.setscl = hfi1_setscl; in init_i2c_bus()
119 bus->algo.getsda = hfi1_getsda; in init_i2c_bus()
120 bus->algo.getscl = hfi1_getscl; in init_i2c_bus()
121 bus->algo.udelay = 5; in init_i2c_bus()
122 bus->algo.timeout = usecs_to_jiffies(100000); in init_i2c_bus()
123 bus->algo.data = bus; in init_i2c_bus()
125 bus->adapter.owner = THIS_MODULE; in init_i2c_bus()
126 bus->adapter.algo_data = &bus->algo; in init_i2c_bus()
127 bus->adapter.dev.parent = &dd->pcidev->dev; in init_i2c_bus()
128 snprintf(bus->adapter.name, sizeof(bus->adapter.name), in init_i2c_bus()
131 ret = i2c_bit_add_bus(&bus->adapter); in init_i2c_bus()
133 dd_dev_info(dd, "%s: unable to add i2c bus %d, err %d\n", in init_i2c_bus()
135 kfree(bus); in init_i2c_bus()
139 return bus; in init_i2c_bus()
144 * Return 0 on success, -errno on error.
148 ad->i2c_bus0 = init_i2c_bus(dd, ad, 0); in set_up_i2c()
149 ad->i2c_bus1 = init_i2c_bus(dd, ad, 1); in set_up_i2c()
150 if (!ad->i2c_bus0 || !ad->i2c_bus1) in set_up_i2c()
151 return -ENOMEM; in set_up_i2c()
155 static void clean_i2c_bus(struct hfi1_i2c_bus *bus) in clean_i2c_bus() argument
157 if (bus) { in clean_i2c_bus()
158 i2c_del_adapter(&bus->adapter); in clean_i2c_bus()
159 kfree(bus); in clean_i2c_bus()
167 clean_i2c_bus(ad->i2c_bus0); in clean_up_i2c()
168 ad->i2c_bus0 = NULL; in clean_up_i2c()
169 clean_i2c_bus(ad->i2c_bus1); in clean_up_i2c()
170 ad->i2c_bus1 = NULL; in clean_up_i2c()
185 msgs[0].addr = slave_addr; in i2c_bus_write()
197 msgs[0].addr = slave_addr; in i2c_bus_write()
202 msgs[1].addr = slave_addr; in i2c_bus_write()
208 return -EINVAL; in i2c_bus_write()
211 i2c->controlling_dd = dd; in i2c_bus_write()
212 ret = i2c_transfer(&i2c->adapter, msgs, num_msgs); in i2c_bus_write()
214 dd_dev_err(dd, "%s: bus %d, i2c slave 0x%x, offset 0x%x, len 0x%x; write failed, ret %d\n", in i2c_bus_write()
215 __func__, i2c->num, slave_addr, offset, len, ret); in i2c_bus_write()
216 return ret < 0 ? ret : -EIO; in i2c_bus_write()
221 static int i2c_bus_read(struct hfi1_devdata *dd, struct hfi1_i2c_bus *bus, in i2c_bus_read() argument
233 msgs[0].addr = slave_addr; in i2c_bus_read()
245 msgs[0].addr = slave_addr; in i2c_bus_read()
250 msgs[1].addr = slave_addr; in i2c_bus_read()
256 return -EINVAL; in i2c_bus_read()
259 bus->controlling_dd = dd; in i2c_bus_read()
260 ret = i2c_transfer(&bus->adapter, msgs, num_msgs); in i2c_bus_read()
262 dd_dev_err(dd, "%s: bus %d, i2c slave 0x%x, offset 0x%x, len 0x%x; read failed, ret %d\n", in i2c_bus_read()
263 __func__, bus->num, slave_addr, offset, len, ret); in i2c_bus_read()
264 return ret < 0 ? ret : -EIO; in i2c_bus_read()
270 * Raw i2c write. No set-up or lock checking.
272 * Return 0 on success, -errno on error.
277 struct hfi1_devdata *dd = ppd->dd; in __i2c_write()
278 struct hfi1_i2c_bus *bus; in __i2c_write() local
282 bus = target ? dd->asic_data->i2c_bus1 : dd->asic_data->i2c_bus0; in __i2c_write()
283 slave_addr = (i2c_addr & 0xff) >> 1; /* convert to 7-bit addr */ in __i2c_write()
285 return i2c_bus_write(dd, bus, slave_addr, offset, offset_size, bp, len); in __i2c_write()
291 * Return number of bytes written, or -errno.
298 if (!check_chip_resource(ppd->dd, i2c_target(target), __func__)) in i2c_write()
299 return -EACCES; in i2c_write()
309 * Raw i2c read. No set-up or lock checking.
311 * Return 0 on success, -errno on error.
316 struct hfi1_devdata *dd = ppd->dd; in __i2c_read()
317 struct hfi1_i2c_bus *bus; in __i2c_read() local
321 bus = target ? dd->asic_data->i2c_bus1 : dd->asic_data->i2c_bus0; in __i2c_read()
322 slave_addr = (i2c_addr & 0xff) >> 1; /* convert to 7-bit addr */ in __i2c_read()
324 return i2c_bus_read(dd, bus, slave_addr, offset, offset_size, bp, len); in __i2c_read()
330 * Return number of bytes read, or -errno.
337 if (!check_chip_resource(ppd->dd, i2c_target(target), __func__)) in i2c_read()
338 return -EACCES; in i2c_read()
349 * by writing @addr = ((256 * n) + m)
353 * Return number of bytes written or -errno.
355 int qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, in qsfp_write() argument
364 if (!check_chip_resource(ppd->dd, i2c_target(target), __func__)) in qsfp_write()
365 return -EACCES; in qsfp_write()
369 * Set the qsfp page based on a zero-based address in qsfp_write()
372 page = (u8)(addr / QSFP_PAGESIZE); in qsfp_write()
376 /* QSFPs require a 5-10msec delay after write operations */ in qsfp_write()
379 hfi1_dev_porterr(ppd->dd, ppd->port, in qsfp_write()
385 offset = addr % QSFP_PAGESIZE; in qsfp_write()
386 nwrite = len - count; in qsfp_write()
388 if (((addr % QSFP_RW_BOUNDARY) + nwrite) > QSFP_RW_BOUNDARY) in qsfp_write()
389 nwrite = QSFP_RW_BOUNDARY - (addr % QSFP_RW_BOUNDARY); in qsfp_write()
393 /* QSFPs require a 5-10msec delay after write operations */ in qsfp_write()
399 addr += nwrite; in qsfp_write()
408 * Perform a stand-alone single QSFP write. Acquire the resource, do the
411 int one_qsfp_write(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, in one_qsfp_write() argument
414 struct hfi1_devdata *dd = ppd->dd; in one_qsfp_write()
421 ret = qsfp_write(ppd, target, addr, bp, len); in one_qsfp_write()
429 * by reading @addr = ((256 * n) + m)
433 * Return the number of bytes read or -errno.
435 int qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, in qsfp_read() argument
444 if (!check_chip_resource(ppd->dd, i2c_target(target), __func__)) in qsfp_read()
445 return -EACCES; in qsfp_read()
449 * Set the qsfp page based on a zero-based address in qsfp_read()
452 page = (u8)(addr / QSFP_PAGESIZE); in qsfp_read()
455 /* QSFPs require a 5-10msec delay after write operations */ in qsfp_read()
458 hfi1_dev_porterr(ppd->dd, ppd->port, in qsfp_read()
464 offset = addr % QSFP_PAGESIZE; in qsfp_read()
465 nread = len - count; in qsfp_read()
467 if (((addr % QSFP_RW_BOUNDARY) + nread) > QSFP_RW_BOUNDARY) in qsfp_read()
468 nread = QSFP_RW_BOUNDARY - (addr % QSFP_RW_BOUNDARY); in qsfp_read()
476 addr += nread; in qsfp_read()
485 * Perform a stand-alone single QSFP read. Acquire the resource, do the
488 int one_qsfp_read(struct hfi1_pportdata *ppd, u32 target, int addr, void *bp, in one_qsfp_read() argument
491 struct hfi1_devdata *dd = ppd->dd; in one_qsfp_read()
498 ret = qsfp_read(ppd, target, addr, bp, len); in one_qsfp_read()
518 u32 target = ppd->dd->hfi1_id; in refresh_qsfp_cache()
521 u8 *cache = &cp->cache[0]; in refresh_qsfp_cache()
525 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); in refresh_qsfp_cache()
526 ppd->qsfp_info.cache_valid = 0; in refresh_qsfp_cache()
527 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags); in refresh_qsfp_cache()
530 ret = -ENODEV; in refresh_qsfp_cache()
536 dd_dev_info(ppd->dd, in refresh_qsfp_cache()
549 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
554 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
559 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
566 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
571 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
578 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
583 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
590 dd_dev_info(ppd->dd, "%s failed\n", __func__); in refresh_qsfp_cache()
596 spin_lock_irqsave(&ppd->qsfp_info.qsfp_lock, flags); in refresh_qsfp_cache()
597 ppd->qsfp_info.cache_valid = 1; in refresh_qsfp_cache()
598 ppd->qsfp_info.cache_refresh_required = 0; in refresh_qsfp_cache()
599 spin_unlock_irqrestore(&ppd->qsfp_info.qsfp_lock, flags); in refresh_qsfp_cache()
634 * balance to the off-by-1 offset above, we add 4 here to in get_qsfp_power_class()
643 struct hfi1_devdata *dd = ppd->dd; in qsfp_mod_present()
646 reg = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_IN : ASIC_QSFP1_IN); in qsfp_mod_present()
654 * For addr 000-127, lower page 00h
655 * For addr 128-255, upper page 00h
656 * For addr 256-383, upper page 01h
657 * For addr 384-511, upper page 02h
658 * For addr 512-639, upper page 03h
665 int get_cable_info(struct hfi1_devdata *dd, u32 port_num, u32 addr, u32 len, in get_cable_info() argument
672 if (port_num > dd->num_pports || port_num < 1) { in get_cable_info()
675 ret = -EINVAL; in get_cable_info()
679 ppd = dd->pport + (port_num - 1); in get_cable_info()
681 ret = -ENODEV; in get_cable_info()
685 if (!ppd->qsfp_info.cache_valid) { in get_cable_info()
686 ret = -EINVAL; in get_cable_info()
690 if (addr >= (QSFP_MAX_NUM_PAGES * 128)) { in get_cable_info()
691 ret = -ERANGE; in get_cable_info()
695 if ((addr + len) > (QSFP_MAX_NUM_PAGES * 128)) { in get_cable_info()
696 excess_len = (addr + len) - (QSFP_MAX_NUM_PAGES * 128); in get_cable_info()
697 memcpy(data, &ppd->qsfp_info.cache[addr], (len - excess_len)); in get_cable_info()
698 data += (len - excess_len); in get_cable_info()
702 memcpy(data, &ppd->qsfp_info.cache[addr], len); in get_cable_info()
704 if (addr <= QSFP_MONITOR_VAL_END && in get_cable_info()
705 (addr + len) >= QSFP_MONITOR_VAL_START) { in get_cable_info()
707 if (addr < QSFP_MONITOR_VAL_START) { in get_cable_info()
708 if (addr + len <= QSFP_MONITOR_VAL_END) in get_cable_info()
709 len = addr + len - QSFP_MONITOR_VAL_START; in get_cable_info()
712 offset = QSFP_MONITOR_VAL_START - addr; in get_cable_info()
713 addr = QSFP_MONITOR_VAL_START; in get_cable_info()
714 } else if (addr == QSFP_MONITOR_VAL_START) { in get_cable_info()
716 if (addr + len > QSFP_MONITOR_VAL_END) in get_cable_info()
720 if (addr + len > QSFP_MONITOR_VAL_END) in get_cable_info()
721 len = QSFP_MONITOR_VAL_END - addr + 1; in get_cable_info()
724 ret = one_qsfp_read(ppd, dd->hfi1_id, addr, data + offset, len); in get_cable_info()
726 ret = -EAGAIN; in get_cable_info()
750 u8 *cache = &ppd->qsfp_info.cache[0]; in qsfp_dump()
763 if (ppd->qsfp_info.cache_valid) { in qsfp_dump()
769 sofar += scnprintf(buf + sofar, len - sofar, "PWR:%.3sW\n", in qsfp_dump()
772 sofar += scnprintf(buf + sofar, len - sofar, "TECH:%s%s\n", in qsfp_dump()
776 sofar += scnprintf(buf + sofar, len - sofar, "Vendor:%.*s\n", in qsfp_dump()
779 sofar += scnprintf(buf + sofar, len - sofar, "OUI:%06X\n", in qsfp_dump()
782 sofar += scnprintf(buf + sofar, len - sofar, "Part#:%.*s\n", in qsfp_dump()
785 sofar += scnprintf(buf + sofar, len - sofar, "Rev:%.*s\n", in qsfp_dump()
789 sofar += scnprintf(buf + sofar, len - sofar, in qsfp_dump()
794 sofar += scnprintf(buf + sofar, len - sofar, "Serial:%.*s\n", in qsfp_dump()
797 sofar += scnprintf(buf + sofar, len - sofar, "Date:%.*s\n", in qsfp_dump()
800 sofar += scnprintf(buf + sofar, len - sofar, "Lot:%.*s\n", in qsfp_dump()
808 sofar += scnprintf(buf + sofar, len - sofar, in qsfp_dump()
811 sofar += scnprintf(buf + sofar, len - sofar, "\n"); in qsfp_dump()