Lines Matching +full:port +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * Copyright 2009 - 2013 Integrated Device Technology, Inc.
30 * struct rio_pwrite - RIO portwrite event
52 "Destination ID assignment to local RapidIO controllers");
65 * rio_local_get_device_id - Get the base/extended device id for a port
66 * @port: RIO master port from which to get the deviceid
68 * Reads the base/extended device id from the local device
69 * implementing the master port. Returns the 8/16-bit device
70 * id.
72 u16 rio_local_get_device_id(struct rio_mport *port) in rio_local_get_device_id() argument
76 rio_local_read_config_32(port, RIO_DID_CSR, &result); in rio_local_get_device_id()
78 return (RIO_GET_DID(port->sys_size, result)); in rio_local_get_device_id()
83 * rio_query_mport - Query mport device attributes
84 * @port: mport device to query
90 int rio_query_mport(struct rio_mport *port, in rio_query_mport() argument
93 if (!port->ops->query_mport) in rio_query_mport()
94 return -ENODATA; in rio_query_mport()
95 return port->ops->query_mport(port, mport_attr); in rio_query_mport()
100 * rio_alloc_net- Allocate and initialize a new RIO network data structure
101 * @mport: Master port associated with the RIO network
103 * Allocates a RIO network structure, initializes per-network
104 * list heads, and adds the associated master port to the
113 INIT_LIST_HEAD(&net->node); in rio_alloc_net()
114 INIT_LIST_HEAD(&net->devices); in rio_alloc_net()
115 INIT_LIST_HEAD(&net->switches); in rio_alloc_net()
116 INIT_LIST_HEAD(&net->mports); in rio_alloc_net()
117 mport->net = net; in rio_alloc_net()
127 err = device_register(&net->dev); in rio_add_net()
131 list_add_tail(&net->node, &rio_nets); in rio_add_net()
141 if (!list_empty(&net->node)) in rio_free_net()
142 list_del(&net->node); in rio_free_net()
144 if (net->release) in rio_free_net()
145 net->release(net); in rio_free_net()
146 device_unregister(&net->dev); in rio_free_net()
151 * rio_local_set_device_id - Set the base/extended device id for a port
152 * @port: RIO master port
153 * @did: Device ID value to be written
155 * Writes the base/extended device id from a device.
157 void rio_local_set_device_id(struct rio_mport *port, u16 did) in rio_local_set_device_id() argument
159 rio_local_write_config_32(port, RIO_DID_CSR, in rio_local_set_device_id()
160 RIO_SET_DID(port->sys_size, did)); in rio_local_set_device_id()
165 * rio_add_device- Adds a RIO device to the device model
176 atomic_set(&rdev->state, RIO_DEVICE_RUNNING); in rio_add_device()
177 err = device_register(&rdev->dev); in rio_add_device()
182 list_add_tail(&rdev->global_list, &rio_devices); in rio_add_device()
183 if (rdev->net) { in rio_add_device()
184 list_add_tail(&rdev->net_list, &rdev->net->devices); in rio_add_device()
185 if (rdev->pef & RIO_PEF_SWITCH) in rio_add_device()
186 list_add_tail(&rdev->rswitch->node, in rio_add_device()
187 &rdev->net->switches); in rio_add_device()
196 * rio_del_device - removes a RIO device from the device model
206 atomic_set(&rdev->state, state); in rio_del_device()
208 list_del(&rdev->global_list); in rio_del_device()
209 if (rdev->net) { in rio_del_device()
210 list_del(&rdev->net_list); in rio_del_device()
211 if (rdev->pef & RIO_PEF_SWITCH) { in rio_del_device()
212 list_del(&rdev->rswitch->node); in rio_del_device()
213 kfree(rdev->rswitch->route_table); in rio_del_device()
217 device_unregister(&rdev->dev); in rio_del_device()
222 * rio_request_inb_mbox - request inbound mailbox service
223 * @mport: RIO master port from which to allocate the mailbox resource
239 int rc = -ENOSYS; in rio_request_inb_mbox()
242 if (!mport->ops->open_inb_mbox) in rio_request_inb_mbox()
250 rc = request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE], in rio_request_inb_mbox()
257 mport->inb_msg[mbox].res = res; in rio_request_inb_mbox()
260 mport->inb_msg[mbox].mcback = minb; in rio_request_inb_mbox()
262 rc = mport->ops->open_inb_mbox(mport, dev_id, mbox, entries); in rio_request_inb_mbox()
264 mport->inb_msg[mbox].mcback = NULL; in rio_request_inb_mbox()
265 mport->inb_msg[mbox].res = NULL; in rio_request_inb_mbox()
270 rc = -ENOMEM; in rio_request_inb_mbox()
278 * rio_release_inb_mbox - release inbound mailbox message service
279 * @mport: RIO master port from which to release the mailbox resource
289 if (!mport->ops->close_inb_mbox || !mport->inb_msg[mbox].res) in rio_release_inb_mbox()
290 return -EINVAL; in rio_release_inb_mbox()
292 mport->ops->close_inb_mbox(mport, mbox); in rio_release_inb_mbox()
293 mport->inb_msg[mbox].mcback = NULL; in rio_release_inb_mbox()
295 rc = release_resource(mport->inb_msg[mbox].res); in rio_release_inb_mbox()
299 kfree(mport->inb_msg[mbox].res); in rio_release_inb_mbox()
300 mport->inb_msg[mbox].res = NULL; in rio_release_inb_mbox()
307 * rio_request_outb_mbox - request outbound mailbox service
308 * @mport: RIO master port from which to allocate the mailbox resource
323 int rc = -ENOSYS; in rio_request_outb_mbox()
326 if (!mport->ops->open_outb_mbox) in rio_request_outb_mbox()
334 rc = request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE], in rio_request_outb_mbox()
341 mport->outb_msg[mbox].res = res; in rio_request_outb_mbox()
344 mport->outb_msg[mbox].mcback = moutb; in rio_request_outb_mbox()
346 rc = mport->ops->open_outb_mbox(mport, dev_id, mbox, entries); in rio_request_outb_mbox()
348 mport->outb_msg[mbox].mcback = NULL; in rio_request_outb_mbox()
349 mport->outb_msg[mbox].res = NULL; in rio_request_outb_mbox()
354 rc = -ENOMEM; in rio_request_outb_mbox()
362 * rio_release_outb_mbox - release outbound mailbox message service
363 * @mport: RIO master port from which to release the mailbox resource
373 if (!mport->ops->close_outb_mbox || !mport->outb_msg[mbox].res) in rio_release_outb_mbox()
374 return -EINVAL; in rio_release_outb_mbox()
376 mport->ops->close_outb_mbox(mport, mbox); in rio_release_outb_mbox()
377 mport->outb_msg[mbox].mcback = NULL; in rio_release_outb_mbox()
379 rc = release_resource(mport->outb_msg[mbox].res); in rio_release_outb_mbox()
383 kfree(mport->outb_msg[mbox].res); in rio_release_outb_mbox()
384 mport->outb_msg[mbox].res = NULL; in rio_release_outb_mbox()
391 * rio_setup_inb_dbell - bind inbound doorbell callback
392 * @mport: RIO master port to bind the doorbell callback
397 * Adds a doorbell resource/callback pair into a port's
409 return -ENOMEM; in rio_setup_inb_dbell()
411 dbell->res = res; in rio_setup_inb_dbell()
412 dbell->dinb = dinb; in rio_setup_inb_dbell()
413 dbell->dev_id = dev_id; in rio_setup_inb_dbell()
415 mutex_lock(&mport->lock); in rio_setup_inb_dbell()
416 list_add_tail(&dbell->node, &mport->dbells); in rio_setup_inb_dbell()
417 mutex_unlock(&mport->lock); in rio_setup_inb_dbell()
422 * rio_request_inb_dbell - request inbound doorbell message service
423 * @mport: RIO master port from which to allocate the doorbell resource
447 rc = request_resource(&mport->riores[RIO_DOORBELL_RESOURCE], in rio_request_inb_dbell()
457 rc = -ENOMEM; in rio_request_inb_dbell()
465 * rio_release_inb_dbell - release inbound doorbell message service
466 * @mport: RIO master port from which to release the doorbell resource
479 mutex_lock(&mport->lock); in rio_release_inb_dbell()
480 list_for_each_entry(dbell, &mport->dbells, node) { in rio_release_inb_dbell()
481 if ((dbell->res->start == start) && (dbell->res->end == end)) { in rio_release_inb_dbell()
482 list_del(&dbell->node); in rio_release_inb_dbell()
487 mutex_unlock(&mport->lock); in rio_release_inb_dbell()
491 rc = -EINVAL; in rio_release_inb_dbell()
496 rc = release_resource(dbell->res); in rio_release_inb_dbell()
507 * rio_request_outb_dbell - request outbound doorbell message range
524 if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res) in rio_request_outb_dbell()
536 * rio_release_outb_dbell - release outbound doorbell message range
554 * rio_add_mport_pw_handler - add port-write message handler into the list
556 * @mport: RIO master port to bind the portwrite callback
569 return -ENOMEM; in rio_add_mport_pw_handler()
571 pwrite->pwcback = pwcback; in rio_add_mport_pw_handler()
572 pwrite->context = context; in rio_add_mport_pw_handler()
573 mutex_lock(&mport->lock); in rio_add_mport_pw_handler()
574 list_add_tail(&pwrite->node, &mport->pwrites); in rio_add_mport_pw_handler()
575 mutex_unlock(&mport->lock); in rio_add_mport_pw_handler()
581 * rio_del_mport_pw_handler - remove port-write message handler from the list
583 * @mport: RIO master port to bind the portwrite callback
593 int rc = -EINVAL; in rio_del_mport_pw_handler()
596 mutex_lock(&mport->lock); in rio_del_mport_pw_handler()
597 list_for_each_entry(pwrite, &mport->pwrites, node) { in rio_del_mport_pw_handler()
598 if (pwrite->pwcback == pwcback && pwrite->context == context) { in rio_del_mport_pw_handler()
599 list_del(&pwrite->node); in rio_del_mport_pw_handler()
605 mutex_unlock(&mport->lock); in rio_del_mport_pw_handler()
612 * rio_request_inb_pwrite - request inbound port-write message service for
614 * @rdev: RIO device to which register inbound port-write callback routine
615 * @pwcback: Callback routine to execute when port-write is received
617 * Binds a port-write callback function to the RapidIO device.
626 if (rdev->pwcback) in rio_request_inb_pwrite()
627 rc = -ENOMEM; in rio_request_inb_pwrite()
629 rdev->pwcback = pwcback; in rio_request_inb_pwrite()
637 * rio_release_inb_pwrite - release inbound port-write message service
639 * @rdev: RIO device which registered for inbound port-write callback
646 int rc = -ENOMEM; in rio_release_inb_pwrite()
649 if (rdev->pwcback) { in rio_release_inb_pwrite()
650 rdev->pwcback = NULL; in rio_release_inb_pwrite()
660 * rio_pw_enable - Enables/disables port-write handling by a master port
661 * @mport: Master port associated with port-write handling
666 if (mport->ops->pwenable) { in rio_pw_enable()
667 mutex_lock(&mport->lock); in rio_pw_enable()
669 if ((enable && ++mport->pwe_refcnt == 1) || in rio_pw_enable()
670 (!enable && mport->pwe_refcnt && --mport->pwe_refcnt == 0)) in rio_pw_enable()
671 mport->ops->pwenable(mport, enable); in rio_pw_enable()
672 mutex_unlock(&mport->lock); in rio_pw_enable()
678 * rio_map_inb_region -- Map inbound memory region.
679 * @mport: Master port.
685 * Return: 0 -- Success.
695 if (!mport->ops->map_inb) in rio_map_inb_region()
696 return -1; in rio_map_inb_region()
698 rc = mport->ops->map_inb(mport, local, rbase, size, rflags); in rio_map_inb_region()
705 * rio_unmap_inb_region -- Unmap the inbound memory region
706 * @mport: Master port
712 if (!mport->ops->unmap_inb) in rio_unmap_inb_region()
715 mport->ops->unmap_inb(mport, lstart); in rio_unmap_inb_region()
721 * rio_map_outb_region -- Map outbound memory region.
722 * @mport: Master port.
723 * @destid: destination id window points to
729 * Return: 0 -- Success.
739 if (!mport->ops->map_outb) in rio_map_outb_region()
740 return -ENODEV; in rio_map_outb_region()
743 rc = mport->ops->map_outb(mport, destid, rbase, size, in rio_map_outb_region()
752 * rio_unmap_outb_region -- Unmap the inbound memory region
753 * @mport: Master port
754 * @destid: destination id mapping points to
761 if (!mport->ops->unmap_outb) in rio_unmap_outb_region()
765 mport->ops->unmap_outb(mport, destid, rstart); in rio_unmap_outb_region()
771 * rio_mport_get_physefb - Helper function that returns register offset
773 * @port: Master port to issue transaction
774 * @local: Indicate a local master port or remote device access
775 * @destid: Destination ID of the device
780 rio_mport_get_physefb(struct rio_mport *port, int local, in rio_mport_get_physefb() argument
786 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0); in rio_mport_get_physefb()
790 rio_local_read_config_32(port, ext_ftr_ptr, in rio_mport_get_physefb()
793 rio_mport_read_config_32(port, destid, hopcount, in rio_mport_get_physefb()
820 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, in rio_mport_get_physefb()
829 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
846 n = from ? from->global_list.next : rio_devices.next; in rio_get_comptag()
850 if (rdev->comp_tag == comp_tag) in rio_get_comptag()
852 n = n->next; in rio_get_comptag()
862 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
864 * @pnum: Switch port number to set LOCKOUT bit
887 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
888 * given port
889 * @port: Master port associated with the RIO network
890 * @local: local=1 select local port otherwise a far device is reached
891 * @destid: Destination ID of the device to check host bit
893 * @port_num: Port (-number on switch) to enable on a far end device
898 int rio_enable_rx_tx_port(struct rio_mport *port, in rio_enable_rx_tx_port() argument
908 * enable rx input tx output port in rio_enable_rx_tx_port()
913 ext_ftr_ptr = rio_mport_get_physefb(port, local, destid, in rio_enable_rx_tx_port()
917 rio_local_read_config_32(port, in rio_enable_rx_tx_port()
921 if (rio_mport_read_config_32(port, destid, hopcount, in rio_enable_rx_tx_port()
924 return -EIO; in rio_enable_rx_tx_port()
930 rio_local_write_config_32(port, in rio_enable_rx_tx_port()
933 if (rio_mport_write_config_32(port, destid, hopcount, in rio_enable_rx_tx_port()
936 return -EIO; in rio_enable_rx_tx_port()
945 * rio_chk_dev_route - Validate route to the specified device.
948 * @npnum: nrdev's port number on the route to rdev
951 * device (and corresponding RIO port) on the route.
957 int p_port, rc = -EIO; in rio_chk_dev_route()
961 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) { in rio_chk_dev_route()
962 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) { in rio_chk_dev_route()
963 prev = rdev->prev; in rio_chk_dev_route()
966 rdev = rdev->prev; in rio_chk_dev_route()
972 p_port = prev->rswitch->route_table[rdev->destid]; in rio_chk_dev_route()
975 pr_debug("RIO: link failed on [%s]-P%d\n", in rio_chk_dev_route()
987 * rio_mport_chk_dev_access - Validate access to the specified device.
988 * @mport: Master port to send transactions
989 * @destid: Device destination ID in network
1002 return -EIO; in rio_mport_chk_dev_access()
1011 * rio_chk_dev_access - Validate access to the specified device.
1016 return rio_mport_chk_dev_access(rdev->net->hport, in rio_chk_dev_access()
1017 rdev->destid, rdev->hopcount); in rio_chk_dev_access()
1021 * rio_get_input_status - Sends a Link-Request/Input-Status control symbol and
1022 * returns link-response (if requested).
1023 * @rdev: RIO devive to issue Input-status command
1024 * @pnum: Device port number to issue the command
1042 /* Issue Input-status command */ in rio_get_input_status()
1052 while (checkcount--) { in rio_get_input_status()
1063 return -EIO; in rio_get_input_status()
1067 * rio_clr_err_stopped - Clears port Error-stopped states.
1069 * @pnum: Switch port number to clear errors
1070 * @err_status: port error status (if 0 reads register from device)
1076 * IDT gen3 switch driver now implements HW-specific error handler that
1077 * issues soft port reset to the port to reset ERR_STOP bits and ackIDs.
1081 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum]; in rio_clr_err_stopped()
1091 pr_debug("RIO_EM: servicing Output Error-Stopped state\n"); in rio_clr_err_stopped()
1093 * Send a Link-Request/Input-Status control symbol in rio_clr_err_stopped()
1096 pr_debug("RIO_EM: Input-status response timeout\n"); in rio_clr_err_stopped()
1100 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n", in rio_clr_err_stopped()
1137 RIO_GET_PORT_NUM(nextdev->swpinfo)), in rio_clr_err_stopped()
1148 pr_debug("RIO_EM: servicing Input Error-Stopped state\n"); in rio_clr_err_stopped()
1150 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL); in rio_clr_err_stopped()
1163 * rio_inb_pwrite_handler - inbound port-write message handler
1164 * @mport: mport device associated with port-write
1165 * @pw_msg: pointer to inbound port-write message
1167 * Processes an inbound port-write message. Returns 0 if the request
1181 pr_debug("%s: PW to mport_%d:\n", __func__, mport->id); in rio_inb_pwrite_handler()
1184 i * 4, pw_msg->raw[i], pw_msg->raw[i + 1], in rio_inb_pwrite_handler()
1185 pw_msg->raw[i + 2], pw_msg->raw[i + 3]); in rio_inb_pwrite_handler()
1190 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL); in rio_inb_pwrite_handler()
1192 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev)); in rio_inb_pwrite_handler()
1195 __func__, pw_msg->em.comptag); in rio_inb_pwrite_handler()
1198 /* Call a device-specific handler (if it is registered for the device). in rio_inb_pwrite_handler()
1199 * This may be the service for endpoints that send device-specific in rio_inb_pwrite_handler()
1200 * port-write messages. End-point messages expected to be handled in rio_inb_pwrite_handler()
1204 if (rdev && rdev->pwcback) { in rio_inb_pwrite_handler()
1205 rc = rdev->pwcback(rdev, pw_msg, 0); in rio_inb_pwrite_handler()
1210 mutex_lock(&mport->lock); in rio_inb_pwrite_handler()
1211 list_for_each_entry(pwrite, &mport->pwrites, node) in rio_inb_pwrite_handler()
1212 pwrite->pwcback(mport, pwrite->context, pw_msg, 0); in rio_inb_pwrite_handler()
1213 mutex_unlock(&mport->lock); in rio_inb_pwrite_handler()
1220 * how to do default PW handling in combination with per-mport callbacks in rio_inb_pwrite_handler()
1223 portnum = pw_msg->em.is_port & 0xFF; in rio_inb_pwrite_handler()
1230 pr_debug("RIO: device access failed - get link partner\n"); in rio_inb_pwrite_handler()
1232 * This will replace device and port reported in PW message. in rio_inb_pwrite_handler()
1238 return -EIO; in rio_inb_pwrite_handler()
1243 /* For End-point devices processing stops here */ in rio_inb_pwrite_handler()
1244 if (!(rdev->pef & RIO_PEF_SWITCH)) in rio_inb_pwrite_handler()
1247 if (rdev->phys_efptr == 0) { in rio_inb_pwrite_handler()
1254 * Process the port-write notification from switch in rio_inb_pwrite_handler()
1256 if (rdev->rswitch->ops && rdev->rswitch->ops->em_handle) in rio_inb_pwrite_handler()
1257 rdev->rswitch->ops->em_handle(rdev, portnum); in rio_inb_pwrite_handler()
1265 if (!(rdev->rswitch->port_ok & (1 << portnum))) { in rio_inb_pwrite_handler()
1266 rdev->rswitch->port_ok |= (1 << portnum); in rio_inb_pwrite_handler()
1269 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n", in rio_inb_pwrite_handler()
1273 /* Clear error-stopped states (if reported). in rio_inb_pwrite_handler()
1284 if (rdev->rswitch->port_ok & (1 << portnum)) { in rio_inb_pwrite_handler()
1285 rdev->rswitch->port_ok &= ~(1 << portnum); in rio_inb_pwrite_handler()
1288 if (rdev->phys_rmap == 1) { in rio_inb_pwrite_handler()
1302 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n", in rio_inb_pwrite_handler()
1308 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet); in rio_inb_pwrite_handler()
1312 /* Clear EM Port N Error Detect CSR */ in rio_inb_pwrite_handler()
1314 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0); in rio_inb_pwrite_handler()
1318 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet); in rio_inb_pwrite_handler()
1324 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0); in rio_inb_pwrite_handler()
1327 /* Clear remaining error bits and Port-Write Pending bit */ in rio_inb_pwrite_handler()
1336 * rio_mport_get_efb - get pointer to next extended features block
1337 * @port: Master port to issue transaction
1338 * @local: Indicate a local master port or remote device access
1339 * @destid: Destination ID of the device
1345 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid, in rio_mport_get_efb() argument
1352 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, in rio_mport_get_efb()
1355 rio_mport_read_config_32(port, destid, hopcount, in rio_mport_get_efb()
1360 rio_local_read_config_32(port, from, &reg_val); in rio_mport_get_efb()
1362 rio_mport_read_config_32(port, destid, hopcount, in rio_mport_get_efb()
1370 * rio_mport_get_feature - query for devices' extended features
1371 * @port: Master port to issue transaction
1372 * @local: Indicate a local master port or remote device access
1373 * @destid: Destination ID of the device
1383 rio_mport_get_feature(struct rio_mport * port, int local, u16 destid, in rio_mport_get_feature() argument
1389 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info); in rio_mport_get_feature()
1391 rio_mport_read_config_32(port, destid, hopcount, in rio_mport_get_feature()
1398 rio_local_read_config_32(port, ext_ftr_ptr, in rio_mport_get_feature()
1401 rio_mport_read_config_32(port, destid, hopcount, in rio_mport_get_feature()
1416 * rio_std_route_add_entry - Add switch route table entry using standard
1418 * @mport: Master port to issue transaction
1419 * @destid: Destination ID of the device
1421 * @table: routing table ID (global or port-specific)
1423 * @route_port: destination port for specified destID
1443 * rio_std_route_get_entry - Read switch route table entry (port number)
1446 * @mport: Master port to issue transaction
1447 * @destid: Destination ID of the device
1449 * @table: routing table ID (global or port-specific)
1451 * @route_port: returned destination port for specified destID
1472 * rio_std_route_clr_table - Clear swotch route table using standard registers
1474 * @mport: Master port to issue transaction
1475 * @destid: Destination ID of the device
1477 * @table: routing table ID (global or port-specific)
1491 if (mport->sys_size) { in rio_std_route_clr_table()
1523 * rio_lock_device - Acquires host device lock for specified device
1524 * @port: Master port to send transaction
1525 * @destid: Destination ID for device/switch
1532 int rio_lock_device(struct rio_mport *port, u16 destid, in rio_lock_device() argument
1539 rio_mport_write_config_32(port, destid, hopcount, in rio_lock_device()
1540 RIO_HOST_DID_LOCK_CSR, port->host_deviceid); in rio_lock_device()
1541 rio_mport_read_config_32(port, destid, hopcount, in rio_lock_device()
1544 while (result != port->host_deviceid) { in rio_lock_device()
1548 return -EINVAL; in rio_lock_device()
1555 rio_mport_write_config_32(port, destid, in rio_lock_device()
1558 port->host_deviceid); in rio_lock_device()
1559 rio_mport_read_config_32(port, destid, in rio_lock_device()
1569 * rio_unlock_device - Releases host device lock for specified device
1570 * @port: Master port to send transaction
1571 * @destid: Destination ID for device/switch
1576 int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount) in rio_unlock_device() argument
1581 rio_mport_write_config_32(port, destid, in rio_unlock_device()
1584 port->host_deviceid); in rio_unlock_device()
1585 rio_mport_read_config_32(port, destid, hopcount, in rio_unlock_device()
1590 return -EINVAL; in rio_unlock_device()
1598 * rio_route_add_entry- Add a route entry to a switch routing table
1600 * @table: Routing table ID
1601 * @route_destid: Destination ID to be routed
1602 * @route_port: Port number to be routed
1608 * using the @table argument if a switch has per port routing tables or
1612 * Returns %0 on success or %-EINVAL on failure.
1617 int rc = -EINVAL; in rio_route_add_entry()
1618 struct rio_switch_ops *ops = rdev->rswitch->ops; in rio_route_add_entry()
1621 rc = rio_lock_device(rdev->net->hport, rdev->destid, in rio_route_add_entry()
1622 rdev->hopcount, 1000); in rio_route_add_entry()
1627 spin_lock(&rdev->rswitch->lock); in rio_route_add_entry()
1629 if (!ops || !ops->add_entry) { in rio_route_add_entry()
1630 rc = rio_std_route_add_entry(rdev->net->hport, rdev->destid, in rio_route_add_entry()
1631 rdev->hopcount, table, in rio_route_add_entry()
1633 } else if (try_module_get(ops->owner)) { in rio_route_add_entry()
1634 rc = ops->add_entry(rdev->net->hport, rdev->destid, in rio_route_add_entry()
1635 rdev->hopcount, table, route_destid, in rio_route_add_entry()
1637 module_put(ops->owner); in rio_route_add_entry()
1640 spin_unlock(&rdev->rswitch->lock); in rio_route_add_entry()
1643 rio_unlock_device(rdev->net->hport, rdev->destid, in rio_route_add_entry()
1644 rdev->hopcount); in rio_route_add_entry()
1651 * rio_route_get_entry- Read an entry from a switch routing table
1653 * @table: Routing table ID
1654 * @route_destid: Destination ID to be routed
1655 * @route_port: Pointer to read port number into
1661 * using the @table argument if a switch has per port routing tables or
1665 * Returns %0 on success or %-EINVAL on failure.
1670 int rc = -EINVAL; in rio_route_get_entry()
1671 struct rio_switch_ops *ops = rdev->rswitch->ops; in rio_route_get_entry()
1674 rc = rio_lock_device(rdev->net->hport, rdev->destid, in rio_route_get_entry()
1675 rdev->hopcount, 1000); in rio_route_get_entry()
1680 spin_lock(&rdev->rswitch->lock); in rio_route_get_entry()
1682 if (!ops || !ops->get_entry) { in rio_route_get_entry()
1683 rc = rio_std_route_get_entry(rdev->net->hport, rdev->destid, in rio_route_get_entry()
1684 rdev->hopcount, table, in rio_route_get_entry()
1686 } else if (try_module_get(ops->owner)) { in rio_route_get_entry()
1687 rc = ops->get_entry(rdev->net->hport, rdev->destid, in rio_route_get_entry()
1688 rdev->hopcount, table, route_destid, in rio_route_get_entry()
1690 module_put(ops->owner); in rio_route_get_entry()
1693 spin_unlock(&rdev->rswitch->lock); in rio_route_get_entry()
1696 rio_unlock_device(rdev->net->hport, rdev->destid, in rio_route_get_entry()
1697 rdev->hopcount); in rio_route_get_entry()
1703 * rio_route_clr_table - Clear a switch routing table
1705 * @table: Routing table ID
1711 * argument if a switch has per port routing tables or the standard (or global)
1714 * Returns %0 on success or %-EINVAL on failure.
1718 int rc = -EINVAL; in rio_route_clr_table()
1719 struct rio_switch_ops *ops = rdev->rswitch->ops; in rio_route_clr_table()
1722 rc = rio_lock_device(rdev->net->hport, rdev->destid, in rio_route_clr_table()
1723 rdev->hopcount, 1000); in rio_route_clr_table()
1728 spin_lock(&rdev->rswitch->lock); in rio_route_clr_table()
1730 if (!ops || !ops->clr_table) { in rio_route_clr_table()
1731 rc = rio_std_route_clr_table(rdev->net->hport, rdev->destid, in rio_route_clr_table()
1732 rdev->hopcount, table); in rio_route_clr_table()
1733 } else if (try_module_get(ops->owner)) { in rio_route_clr_table()
1734 rc = ops->clr_table(rdev->net->hport, rdev->destid, in rio_route_clr_table()
1735 rdev->hopcount, table); in rio_route_clr_table()
1737 module_put(ops->owner); in rio_route_clr_table()
1740 spin_unlock(&rdev->rswitch->lock); in rio_route_clr_table()
1743 rio_unlock_device(rdev->net->hport, rdev->destid, in rio_route_clr_table()
1744 rdev->hopcount); in rio_route_clr_table()
1757 return mport == container_of(chan->device, struct rio_mport, dma); in rio_chan_filter()
1761 * rio_request_mport_dma - request RapidIO capable DMA channel associated
1778 * rio_request_dma - request RapidIO capable DMA channel that supports
1786 return rio_request_mport_dma(rdev->net->hport); in rio_request_dma()
1791 * rio_release_dma - release specified DMA channel
1801 * rio_dma_prep_xfer - RapidIO specific wrapper
1804 * @destid: target RapidIO device destination ID
1814 * error-valued pointer or NULL if failed.
1822 if (!dchan->device->device_prep_slave_sg) { in rio_dma_prep_xfer()
1828 rio_ext.rio_addr_u = data->rio_addr_u; in rio_dma_prep_xfer()
1829 rio_ext.rio_addr = data->rio_addr; in rio_dma_prep_xfer()
1830 rio_ext.wr_type = data->wr_type; in rio_dma_prep_xfer()
1832 return dmaengine_prep_rio_sg(dchan, data->sg, data->sg_len, in rio_dma_prep_xfer()
1838 * rio_dma_prep_slave_sg - RapidIO specific wrapper
1851 * error-valued pointer or NULL if failed.
1857 return rio_dma_prep_xfer(dchan, rdev->destid, data, direction, flags); in rio_dma_prep_slave_sg()
1864 * rio_find_mport - find RIO mport by its ID
1865 * @mport_id: number (ID) of mport device
1873 struct rio_mport *port; in rio_find_mport() local
1876 list_for_each_entry(port, &rio_mports, node) { in rio_find_mport()
1877 if (port->id == mport_id) in rio_find_mport()
1880 port = NULL; in rio_find_mport()
1884 return port; in rio_find_mport()
1888 * rio_register_scan - enumeration/discovery method registration interface
1889 * @mport_id: mport device ID for which fabric scan routine has to be set
1902 struct rio_mport *port; in rio_register_scan() local
1910 return -EINVAL; in rio_register_scan()
1916 * the same mport ID (including RIO_MPORT_ANY). Multiple enumerators in rio_register_scan()
1917 * for the same mport ID are not supported. in rio_register_scan()
1920 if (scan->mport_id == mport_id) { in rio_register_scan()
1921 rc = -EBUSY; in rio_register_scan()
1931 rc = -ENOMEM; in rio_register_scan()
1935 scan->mport_id = mport_id; in rio_register_scan()
1936 scan->ops = scan_ops; in rio_register_scan()
1941 * The new scan with matching mport ID overrides any previously attached in rio_register_scan()
1947 list_for_each_entry(port, &rio_mports, node) { in rio_register_scan()
1948 if (port->id == mport_id) { in rio_register_scan()
1949 port->nscan = scan_ops; in rio_register_scan()
1951 } else if (mport_id == RIO_MPORT_ANY && !port->nscan) in rio_register_scan()
1952 port->nscan = scan_ops; in rio_register_scan()
1955 list_add_tail(&scan->node, &rio_scans); in rio_register_scan()
1965 * rio_unregister_scan - removes enumeration/discovery method from mport
1966 * @mport_id: mport device ID for which fabric scan routine has to be
1977 struct rio_mport *port; in rio_unregister_scan() local
1983 return -EINVAL; in rio_unregister_scan()
1987 list_for_each_entry(port, &rio_mports, node) in rio_unregister_scan()
1988 if (port->id == mport_id || in rio_unregister_scan()
1989 (mport_id == RIO_MPORT_ANY && port->nscan == scan_ops)) in rio_unregister_scan()
1990 port->nscan = NULL; in rio_unregister_scan()
1993 if (scan->mport_id == mport_id) { in rio_unregister_scan()
1994 list_del(&scan->node); in rio_unregister_scan()
2007 * rio_mport_scan - execute enumeration/discovery on the specified mport
2008 * @mport_id: number (ID) of mport device
2012 struct rio_mport *port = NULL; in rio_mport_scan() local
2016 list_for_each_entry(port, &rio_mports, node) { in rio_mport_scan()
2017 if (port->id == mport_id) in rio_mport_scan()
2021 return -ENODEV; in rio_mport_scan()
2023 if (!port->nscan) { in rio_mport_scan()
2025 return -EINVAL; in rio_mport_scan()
2028 if (!try_module_get(port->nscan->owner)) { in rio_mport_scan()
2030 return -ENODEV; in rio_mport_scan()
2035 if (port->host_deviceid >= 0) in rio_mport_scan()
2036 rc = port->nscan->enumerate(port, 0); in rio_mport_scan()
2038 rc = port->nscan->discover(port, RIO_SCAN_ENUM_NO_WAIT); in rio_mport_scan()
2040 module_put(port->nscan->owner); in rio_mport_scan()
2057 work->mport->id, work->mport->name); in disc_work_handler()
2058 if (try_module_get(work->mport->nscan->owner)) { in disc_work_handler()
2059 work->mport->nscan->discover(work->mport, 0); in disc_work_handler()
2060 module_put(work->mport->nscan->owner); in disc_work_handler()
2066 struct rio_mport *port; in rio_init_mports() local
2071 return -ENODEV; in rio_init_mports()
2078 list_for_each_entry(port, &rio_mports, node) { in rio_init_mports()
2079 if (port->host_deviceid >= 0) { in rio_init_mports()
2080 if (port->nscan && try_module_get(port->nscan->owner)) { in rio_init_mports()
2081 port->nscan->enumerate(port, 0); in rio_init_mports()
2082 module_put(port->nscan->owner); in rio_init_mports()
2114 list_for_each_entry(port, &rio_mports, node) { in rio_init_mports()
2115 if (port->host_deviceid < 0 && port->nscan) { in rio_init_mports()
2116 work[n].mport = port; in rio_init_mports()
2137 return -1; in rio_get_hdid()
2146 return -ENODEV; in rio_mport_initialize()
2149 atomic_set(&mport->state, RIO_DEVICE_INITIALIZING); in rio_mport_initialize()
2150 mport->id = next_portid++; in rio_mport_initialize()
2151 mport->host_deviceid = rio_get_hdid(mport->id); in rio_mport_initialize()
2152 mport->nscan = NULL; in rio_mport_initialize()
2153 mutex_init(&mport->lock); in rio_mport_initialize()
2154 mport->pwe_refcnt = 0; in rio_mport_initialize()
2155 INIT_LIST_HEAD(&mport->pwrites); in rio_mport_initialize()
2161 int rio_register_mport(struct rio_mport *port) in rio_register_mport() argument
2173 if (port->id == scan->mport_id || in rio_register_mport()
2174 scan->mport_id == RIO_MPORT_ANY) { in rio_register_mport()
2175 port->nscan = scan->ops; in rio_register_mport()
2176 if (port->id == scan->mport_id) in rio_register_mport()
2181 list_add_tail(&port->node, &rio_mports); in rio_register_mport()
2184 dev_set_name(&port->dev, "rapidio%d", port->id); in rio_register_mport()
2185 port->dev.class = &rio_mport_class; in rio_register_mport()
2186 atomic_set(&port->state, RIO_DEVICE_RUNNING); in rio_register_mport()
2188 res = device_register(&port->dev); in rio_register_mport()
2190 dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n", in rio_register_mport()
2191 port->id, res); in rio_register_mport()
2193 list_del(&port->node); in rio_register_mport()
2195 put_device(&port->dev); in rio_register_mport()
2197 dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id); in rio_register_mport()
2208 if (dev->bus == &rio_bus_type) in rio_mport_cleanup_callback()
2219 device_for_each_child(&net->dev, NULL, rio_mport_cleanup_callback); in rio_net_remove_children()
2223 int rio_unregister_mport(struct rio_mport *port) in rio_unregister_mport() argument
2225 pr_debug("RIO: %s %s id=%d\n", __func__, port->name, port->id); in rio_unregister_mport()
2228 if (atomic_cmpxchg(&port->state, in rio_unregister_mport()
2232 __func__, port->name); in rio_unregister_mport()
2235 if (port->net && port->net->hport == port) { in rio_unregister_mport()
2236 rio_net_remove_children(port->net); in rio_unregister_mport()
2237 rio_free_net(port->net); in rio_unregister_mport()
2245 list_del(&port->node); in rio_unregister_mport()
2247 device_unregister(&port->dev); in rio_unregister_mport()