port.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "port.h"
  57. #include "request.h"
  58. #include "timers.h"
  59. #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
  60. #define SCU_DUMMY_INDEX (0xFFFF)
  61. static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[];
  62. static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
  63. {
  64. unsigned long flags;
  65. dev_dbg(&iport->isci_host->pdev->dev,
  66. "%s: iport = %p, state = 0x%x\n",
  67. __func__, iport, status);
  68. /* XXX pointless lock */
  69. spin_lock_irqsave(&iport->state_lock, flags);
  70. iport->status = status;
  71. spin_unlock_irqrestore(&iport->state_lock, flags);
  72. }
  73. /*
  74. * This function will indicate which protocols are supported by this port.
  75. * @sci_port: a handle corresponding to the SAS port for which to return the
  76. * supported protocols.
  77. * @protocols: This parameter specifies a pointer to a data structure
  78. * which the core will copy the protocol values for the port from the
  79. * transmit_identification register.
  80. */
  81. static void
  82. scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
  83. struct scic_phy_proto *protocols)
  84. {
  85. u8 index;
  86. protocols->all = 0;
  87. for (index = 0; index < SCI_MAX_PHYS; index++) {
  88. if (sci_port->phy_table[index] != NULL) {
  89. scic_sds_phy_get_protocols(sci_port->phy_table[index],
  90. protocols);
  91. }
  92. }
  93. }
  94. /**
  95. * This method requests a list (mask) of the phys contained in the supplied SAS
  96. * port.
  97. * @sci_port: a handle corresponding to the SAS port for which to return the
  98. * phy mask.
  99. *
  100. * Return a bit mask indicating which phys are a part of this port. Each bit
  101. * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
  102. */
  103. static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
  104. {
  105. u32 index;
  106. u32 mask;
  107. mask = 0;
  108. for (index = 0; index < SCI_MAX_PHYS; index++) {
  109. if (sci_port->phy_table[index] != NULL) {
  110. mask |= (1 << index);
  111. }
  112. }
  113. return mask;
  114. }
  115. /**
  116. * scic_port_get_properties() - This method simply returns the properties
  117. * regarding the port, such as: physical index, protocols, sas address, etc.
  118. * @port: this parameter specifies the port for which to retrieve the physical
  119. * index.
  120. * @properties: This parameter specifies the properties structure into which to
  121. * copy the requested information.
  122. *
  123. * Indicate if the user specified a valid port. SCI_SUCCESS This value is
  124. * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
  125. * value is returned if the specified port is not valid. When this value is
  126. * returned, no data is copied to the properties output parameter.
  127. */
  128. static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
  129. struct scic_port_properties *prop)
  130. {
  131. if ((port == NULL) ||
  132. (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
  133. return SCI_FAILURE_INVALID_PORT;
  134. prop->index = port->logical_port_index;
  135. prop->phy_mask = scic_sds_port_get_phys(port);
  136. scic_sds_port_get_sas_address(port, &prop->local.sas_address);
  137. scic_sds_port_get_protocols(port, &prop->local.protocols);
  138. scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
  139. return SCI_SUCCESS;
  140. }
  141. static void isci_port_link_up(struct isci_host *isci_host,
  142. struct scic_sds_port *port,
  143. struct scic_sds_phy *phy)
  144. {
  145. unsigned long flags;
  146. struct scic_port_properties properties;
  147. struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
  148. struct isci_port *isci_port = sci_port_to_iport(port);
  149. unsigned long success = true;
  150. BUG_ON(isci_phy->isci_port != NULL);
  151. isci_phy->isci_port = isci_port;
  152. dev_dbg(&isci_host->pdev->dev,
  153. "%s: isci_port = %p\n",
  154. __func__, isci_port);
  155. spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  156. isci_port_change_state(isci_phy->isci_port, isci_starting);
  157. scic_port_get_properties(port, &properties);
  158. if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
  159. u64 attached_sas_address;
  160. isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
  161. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  162. /*
  163. * For direct-attached SATA devices, the SCI core will
  164. * automagically assign a SAS address to the end device
  165. * for the purpose of creating a port. This SAS address
  166. * will not be the same as assigned to the PHY and needs
  167. * to be obtained from struct scic_port_properties properties.
  168. */
  169. attached_sas_address = properties.remote.sas_address.high;
  170. attached_sas_address <<= 32;
  171. attached_sas_address |= properties.remote.sas_address.low;
  172. swab64s(&attached_sas_address);
  173. memcpy(&isci_phy->sas_phy.attached_sas_addr,
  174. &attached_sas_address, sizeof(attached_sas_address));
  175. } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  176. isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
  177. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  178. /* Copy the attached SAS address from the IAF */
  179. memcpy(isci_phy->sas_phy.attached_sas_addr,
  180. isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  181. } else {
  182. dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
  183. success = false;
  184. }
  185. isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
  186. spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  187. /* Notify libsas that we have an address frame, if indeed
  188. * we've found an SSP, SMP, or STP target */
  189. if (success)
  190. isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
  191. PORTE_BYTES_DMAED);
  192. }
  193. /**
  194. * isci_port_link_down() - This function is called by the sci core when a link
  195. * becomes inactive.
  196. * @isci_host: This parameter specifies the isci host object.
  197. * @phy: This parameter specifies the isci phy with the active link.
  198. * @port: This parameter specifies the isci port with the active link.
  199. *
  200. */
  201. static void isci_port_link_down(struct isci_host *isci_host,
  202. struct isci_phy *isci_phy,
  203. struct isci_port *isci_port)
  204. {
  205. struct isci_remote_device *isci_device;
  206. dev_dbg(&isci_host->pdev->dev,
  207. "%s: isci_port = %p\n", __func__, isci_port);
  208. if (isci_port) {
  209. /* check to see if this is the last phy on this port. */
  210. if (isci_phy->sas_phy.port
  211. && isci_phy->sas_phy.port->num_phys == 1) {
  212. /* change the state for all devices on this port.
  213. * The next task sent to this device will be returned
  214. * as SAS_TASK_UNDELIVERED, and the scsi mid layer
  215. * will remove the target
  216. */
  217. list_for_each_entry(isci_device,
  218. &isci_port->remote_dev_list,
  219. node) {
  220. dev_dbg(&isci_host->pdev->dev,
  221. "%s: isci_device = %p\n",
  222. __func__, isci_device);
  223. isci_remote_device_change_state(isci_device,
  224. isci_stopping);
  225. }
  226. }
  227. isci_port_change_state(isci_port, isci_stopping);
  228. }
  229. /* Notify libsas of the borken link, this will trigger calls to our
  230. * isci_port_deformed and isci_dev_gone functions.
  231. */
  232. sas_phy_disconnected(&isci_phy->sas_phy);
  233. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  234. PHYE_LOSS_OF_SIGNAL);
  235. isci_phy->isci_port = NULL;
  236. dev_dbg(&isci_host->pdev->dev,
  237. "%s: isci_port = %p - Done\n", __func__, isci_port);
  238. }
  239. /**
  240. * isci_port_ready() - This function is called by the sci core when a link
  241. * becomes ready.
  242. * @isci_host: This parameter specifies the isci host object.
  243. * @port: This parameter specifies the sci port with the active link.
  244. *
  245. */
  246. static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  247. {
  248. dev_dbg(&isci_host->pdev->dev,
  249. "%s: isci_port = %p\n", __func__, isci_port);
  250. complete_all(&isci_port->start_complete);
  251. isci_port_change_state(isci_port, isci_ready);
  252. return;
  253. }
  254. /**
  255. * isci_port_not_ready() - This function is called by the sci core when a link
  256. * is not ready. All remote devices on this link will be removed if they are
  257. * in the stopping state.
  258. * @isci_host: This parameter specifies the isci host object.
  259. * @port: This parameter specifies the sci port with the active link.
  260. *
  261. */
  262. static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  263. {
  264. dev_dbg(&isci_host->pdev->dev,
  265. "%s: isci_port = %p\n", __func__, isci_port);
  266. }
  267. static void isci_port_stop_complete(struct scic_sds_controller *scic,
  268. struct scic_sds_port *sci_port,
  269. enum sci_status completion_status)
  270. {
  271. dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
  272. }
  273. /**
  274. * isci_port_hard_reset_complete() - This function is called by the sci core
  275. * when the hard reset complete notification has been received.
  276. * @port: This parameter specifies the sci port with the active link.
  277. * @completion_status: This parameter specifies the core status for the reset
  278. * process.
  279. *
  280. */
  281. static void isci_port_hard_reset_complete(struct isci_port *isci_port,
  282. enum sci_status completion_status)
  283. {
  284. dev_dbg(&isci_port->isci_host->pdev->dev,
  285. "%s: isci_port = %p, completion_status=%x\n",
  286. __func__, isci_port, completion_status);
  287. /* Save the status of the hard reset from the port. */
  288. isci_port->hard_reset_status = completion_status;
  289. complete_all(&isci_port->hard_reset_complete);
  290. }
  291. /* This method will return a true value if the specified phy can be assigned to
  292. * this port The following is a list of phys for each port that are allowed: -
  293. * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
  294. * doesn't preclude all configurations. It merely ensures that a phy is part
  295. * of the allowable set of phy identifiers for that port. For example, one
  296. * could assign phy 3 to port 0 and no other phys. Please refer to
  297. * scic_sds_port_is_phy_mask_valid() for information regarding whether the
  298. * phy_mask for a port can be supported. bool true if this is a valid phy
  299. * assignment for the port false if this is not a valid phy assignment for the
  300. * port
  301. */
  302. bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
  303. u32 phy_index)
  304. {
  305. /* Initialize to invalid value. */
  306. u32 existing_phy_index = SCI_MAX_PHYS;
  307. u32 index;
  308. if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
  309. return false;
  310. }
  311. if (sci_port->physical_port_index == 3 && phy_index != 3) {
  312. return false;
  313. }
  314. if (
  315. (sci_port->physical_port_index == 2)
  316. && ((phy_index == 0) || (phy_index == 1))
  317. ) {
  318. return false;
  319. }
  320. for (index = 0; index < SCI_MAX_PHYS; index++) {
  321. if ((sci_port->phy_table[index] != NULL)
  322. && (index != phy_index)) {
  323. existing_phy_index = index;
  324. }
  325. }
  326. /*
  327. * Ensure that all of the phys in the port are capable of
  328. * operating at the same maximum link rate. */
  329. if (
  330. (existing_phy_index < SCI_MAX_PHYS)
  331. && (sci_port->owning_controller->user_parameters.sds1.phys[
  332. phy_index].max_speed_generation !=
  333. sci_port->owning_controller->user_parameters.sds1.phys[
  334. existing_phy_index].max_speed_generation)
  335. )
  336. return false;
  337. return true;
  338. }
  339. /**
  340. *
  341. * @sci_port: This is the port object for which to determine if the phy mask
  342. * can be supported.
  343. *
  344. * This method will return a true value if the port's phy mask can be supported
  345. * by the SCU. The following is a list of valid PHY mask configurations for
  346. * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
  347. * - Port 3 - [3] This method returns a boolean indication specifying if the
  348. * phy mask can be supported. true if this is a valid phy assignment for the
  349. * port false if this is not a valid phy assignment for the port
  350. */
  351. static bool scic_sds_port_is_phy_mask_valid(
  352. struct scic_sds_port *sci_port,
  353. u32 phy_mask)
  354. {
  355. if (sci_port->physical_port_index == 0) {
  356. if (((phy_mask & 0x0F) == 0x0F)
  357. || ((phy_mask & 0x03) == 0x03)
  358. || ((phy_mask & 0x01) == 0x01)
  359. || (phy_mask == 0))
  360. return true;
  361. } else if (sci_port->physical_port_index == 1) {
  362. if (((phy_mask & 0x02) == 0x02)
  363. || (phy_mask == 0))
  364. return true;
  365. } else if (sci_port->physical_port_index == 2) {
  366. if (((phy_mask & 0x0C) == 0x0C)
  367. || ((phy_mask & 0x04) == 0x04)
  368. || (phy_mask == 0))
  369. return true;
  370. } else if (sci_port->physical_port_index == 3) {
  371. if (((phy_mask & 0x08) == 0x08)
  372. || (phy_mask == 0))
  373. return true;
  374. }
  375. return false;
  376. }
  377. /**
  378. *
  379. * @sci_port: This parameter specifies the port from which to return a
  380. * connected phy.
  381. *
  382. * This method retrieves a currently active (i.e. connected) phy contained in
  383. * the port. Currently, the lowest order phy that is connected is returned.
  384. * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
  385. * returned if there are no currently active (i.e. connected to a remote end
  386. * point) phys contained in the port. All other values specify a struct scic_sds_phy
  387. * object that is active in the port.
  388. */
  389. static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
  390. struct scic_sds_port *sci_port
  391. ) {
  392. u32 index;
  393. struct scic_sds_phy *phy;
  394. for (index = 0; index < SCI_MAX_PHYS; index++) {
  395. /*
  396. * Ensure that the phy is both part of the port and currently
  397. * connected to the remote end-point. */
  398. phy = sci_port->phy_table[index];
  399. if (
  400. (phy != NULL)
  401. && scic_sds_port_active_phy(sci_port, phy)
  402. ) {
  403. return phy;
  404. }
  405. }
  406. return NULL;
  407. }
  408. /**
  409. * scic_sds_port_set_phy() -
  410. * @out]: port The port object to which the phy assignement is being made.
  411. * @out]: phy The phy which is being assigned to the port.
  412. *
  413. * This method attempts to make the assignment of the phy to the port. If
  414. * successful the phy is assigned to the ports phy table. bool true if the phy
  415. * assignment can be made. false if the phy assignement can not be made. This
  416. * is a functional test that only fails if the phy is currently assigned to a
  417. * different port.
  418. */
  419. static enum sci_status scic_sds_port_set_phy(
  420. struct scic_sds_port *port,
  421. struct scic_sds_phy *phy)
  422. {
  423. /*
  424. * Check to see if we can add this phy to a port
  425. * that means that the phy is not part of a port and that the port does
  426. * not already have a phy assinged to the phy index. */
  427. if (
  428. (port->phy_table[phy->phy_index] == NULL)
  429. && (phy_get_non_dummy_port(phy) == NULL)
  430. && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
  431. ) {
  432. /*
  433. * Phy is being added in the stopped state so we are in MPC mode
  434. * make logical port index = physical port index */
  435. port->logical_port_index = port->physical_port_index;
  436. port->phy_table[phy->phy_index] = phy;
  437. scic_sds_phy_set_port(phy, port);
  438. return SCI_SUCCESS;
  439. }
  440. return SCI_FAILURE;
  441. }
  442. /**
  443. * scic_sds_port_clear_phy() -
  444. * @out]: port The port from which the phy is being cleared.
  445. * @out]: phy The phy being cleared from the port.
  446. *
  447. * This method will clear the phy assigned to this port. This method fails if
  448. * this phy is not currently assinged to this port. bool true if the phy is
  449. * removed from the port. false if this phy is not assined to this port.
  450. */
  451. static enum sci_status scic_sds_port_clear_phy(
  452. struct scic_sds_port *port,
  453. struct scic_sds_phy *phy)
  454. {
  455. /* Make sure that this phy is part of this port */
  456. if (port->phy_table[phy->phy_index] == phy &&
  457. phy_get_non_dummy_port(phy) == port) {
  458. struct scic_sds_controller *scic = port->owning_controller;
  459. struct isci_host *ihost = scic_to_ihost(scic);
  460. /* Yep it is assigned to this port so remove it */
  461. scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
  462. port->phy_table[phy->phy_index] = NULL;
  463. return SCI_SUCCESS;
  464. }
  465. return SCI_FAILURE;
  466. }
  467. /**
  468. * This method requests the SAS address for the supplied SAS port from the SCI
  469. * implementation.
  470. * @sci_port: a handle corresponding to the SAS port for which to return the
  471. * SAS address.
  472. * @sas_address: This parameter specifies a pointer to a SAS address structure
  473. * into which the core will copy the SAS address for the port.
  474. *
  475. */
  476. void scic_sds_port_get_sas_address(
  477. struct scic_sds_port *sci_port,
  478. struct sci_sas_address *sas_address)
  479. {
  480. u32 index;
  481. sas_address->high = 0;
  482. sas_address->low = 0;
  483. for (index = 0; index < SCI_MAX_PHYS; index++) {
  484. if (sci_port->phy_table[index] != NULL) {
  485. scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
  486. }
  487. }
  488. }
  489. /*
  490. * This function requests the SAS address for the device directly attached to
  491. * this SAS port.
  492. * @sci_port: a handle corresponding to the SAS port for which to return the
  493. * SAS address.
  494. * @sas_address: This parameter specifies a pointer to a SAS address structure
  495. * into which the core will copy the SAS address for the device directly
  496. * attached to the port.
  497. *
  498. */
  499. void scic_sds_port_get_attached_sas_address(
  500. struct scic_sds_port *sci_port,
  501. struct sci_sas_address *sas_address)
  502. {
  503. struct scic_sds_phy *sci_phy;
  504. /*
  505. * Ensure that the phy is both part of the port and currently
  506. * connected to the remote end-point.
  507. */
  508. sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
  509. if (sci_phy) {
  510. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
  511. scic_sds_phy_get_attached_sas_address(sci_phy,
  512. sas_address);
  513. } else {
  514. scic_sds_phy_get_sas_address(sci_phy, sas_address);
  515. sas_address->low += sci_phy->phy_index;
  516. }
  517. } else {
  518. sas_address->high = 0;
  519. sas_address->low = 0;
  520. }
  521. }
  522. /**
  523. * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
  524. *
  525. * @sci_port: logical port on which we need to create the remote node context
  526. * @rni: remote node index for this remote node context.
  527. *
  528. * This routine will construct a dummy remote node context data structure
  529. * This structure will be posted to the hardware to work around a scheduler
  530. * error in the hardware.
  531. */
  532. static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
  533. {
  534. union scu_remote_node_context *rnc;
  535. rnc = &sci_port->owning_controller->remote_node_context_table[rni];
  536. memset(rnc, 0, sizeof(union scu_remote_node_context));
  537. rnc->ssp.remote_sas_address_hi = 0;
  538. rnc->ssp.remote_sas_address_lo = 0;
  539. rnc->ssp.remote_node_index = rni;
  540. rnc->ssp.remote_node_port_width = 1;
  541. rnc->ssp.logical_port_index = sci_port->physical_port_index;
  542. rnc->ssp.nexus_loss_timer_enable = false;
  543. rnc->ssp.check_bit = false;
  544. rnc->ssp.is_valid = true;
  545. rnc->ssp.is_remote_node_context = true;
  546. rnc->ssp.function_number = 0;
  547. rnc->ssp.arbitration_wait_time = 0;
  548. }
  549. /**
  550. * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
  551. * @sci_port The logical port on which we need to create the
  552. * remote node context.
  553. * context.
  554. * @tci The remote node index for this remote node context.
  555. *
  556. * This routine will construct a dummy task context data structure. This
  557. * structure will be posted to the hardwre to work around a scheduler error
  558. * in the hardware.
  559. *
  560. */
  561. static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
  562. {
  563. struct scu_task_context *task_context;
  564. task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
  565. memset(task_context, 0, sizeof(struct scu_task_context));
  566. task_context->abort = 0;
  567. task_context->priority = 0;
  568. task_context->initiator_request = 1;
  569. task_context->connection_rate = 1;
  570. task_context->protocol_engine_index = 0;
  571. task_context->logical_port_index = sci_port->physical_port_index;
  572. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  573. task_context->task_index = scic_sds_io_tag_get_index(tci);
  574. task_context->valid = SCU_TASK_CONTEXT_VALID;
  575. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  576. task_context->remote_node_index = sci_port->reserved_rni;
  577. task_context->command_code = 0;
  578. task_context->link_layer_control = 0;
  579. task_context->do_not_dma_ssp_good_response = 1;
  580. task_context->strict_ordering = 0;
  581. task_context->control_frame = 0;
  582. task_context->timeout_enable = 0;
  583. task_context->block_guard_enable = 0;
  584. task_context->address_modifier = 0;
  585. task_context->task_phase = 0x01;
  586. }
  587. static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
  588. {
  589. struct scic_sds_controller *scic = sci_port->owning_controller;
  590. if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
  591. scic_controller_free_io_tag(scic, sci_port->reserved_tci);
  592. if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
  593. scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
  594. 1, sci_port->reserved_rni);
  595. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  596. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  597. }
  598. /**
  599. * This method performs initialization of the supplied port. Initialization
  600. * includes: - state machine initialization - member variable initialization
  601. * - configuring the phy_mask
  602. * @sci_port:
  603. * @transport_layer_registers:
  604. * @port_task_scheduler_registers:
  605. * @port_configuration_regsiter:
  606. *
  607. * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
  608. * if the phy being added to the port
  609. */
  610. enum sci_status scic_sds_port_initialize(
  611. struct scic_sds_port *sci_port,
  612. void __iomem *port_task_scheduler_registers,
  613. void __iomem *port_configuration_regsiter,
  614. void __iomem *viit_registers)
  615. {
  616. sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
  617. sci_port->port_pe_configuration_register = port_configuration_regsiter;
  618. sci_port->viit_registers = viit_registers;
  619. return SCI_SUCCESS;
  620. }
  621. /**
  622. * This method assigns the direct attached device ID for this port.
  623. *
  624. * @param[in] sci_port The port for which the direct attached device id is to
  625. * be assigned.
  626. * @param[in] device_id The direct attached device ID to assign to the port.
  627. * This will be the RNi for the device
  628. */
  629. void scic_sds_port_setup_transports(
  630. struct scic_sds_port *sci_port,
  631. u32 device_id)
  632. {
  633. u8 index;
  634. for (index = 0; index < SCI_MAX_PHYS; index++) {
  635. if (sci_port->active_phy_mask & (1 << index))
  636. scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
  637. }
  638. }
  639. /**
  640. *
  641. * @sci_port: This is the port on which the phy should be enabled.
  642. * @sci_phy: This is the specific phy which to enable.
  643. * @do_notify_user: This parameter specifies whether to inform the user (via
  644. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  645. *
  646. * This function will activate the phy in the port.
  647. * Activation includes: - adding
  648. * the phy to the port - enabling the Protocol Engine in the silicon. -
  649. * notifying the user that the link is up. none
  650. */
  651. static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
  652. struct scic_sds_phy *sci_phy,
  653. bool do_notify_user)
  654. {
  655. struct scic_sds_controller *scic = sci_port->owning_controller;
  656. struct isci_host *ihost = scic_to_ihost(scic);
  657. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
  658. scic_sds_phy_resume(sci_phy);
  659. sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
  660. scic_sds_controller_clear_invalid_phy(scic, sci_phy);
  661. if (do_notify_user == true)
  662. isci_port_link_up(ihost, sci_port, sci_phy);
  663. }
  664. void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
  665. struct scic_sds_phy *sci_phy,
  666. bool do_notify_user)
  667. {
  668. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  669. struct isci_port *iport = sci_port_to_iport(sci_port);
  670. struct isci_host *ihost = scic_to_ihost(scic);
  671. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  672. sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
  673. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  674. /* Re-assign the phy back to the LP as if it were a narrow port */
  675. writel(sci_phy->phy_index,
  676. &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
  677. if (do_notify_user == true)
  678. isci_port_link_down(ihost, iphy, iport);
  679. }
  680. /**
  681. *
  682. * @sci_port: This is the port on which the phy should be disabled.
  683. * @sci_phy: This is the specific phy which to disabled.
  684. *
  685. * This function will disable the phy and report that the phy is not valid for
  686. * this port object. None
  687. */
  688. static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
  689. struct scic_sds_phy *sci_phy)
  690. {
  691. struct scic_sds_controller *scic = sci_port->owning_controller;
  692. /*
  693. * Check to see if we have alreay reported this link as bad and if
  694. * not go ahead and tell the SCI_USER that we have discovered an
  695. * invalid link.
  696. */
  697. if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
  698. scic_sds_controller_set_invalid_phy(scic, sci_phy);
  699. dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
  700. }
  701. }
  702. static bool is_port_ready_state(enum scic_sds_port_states state)
  703. {
  704. switch (state) {
  705. case SCI_BASE_PORT_STATE_READY:
  706. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  707. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  708. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  709. return true;
  710. default:
  711. return false;
  712. }
  713. }
  714. /* flag dummy rnc hanling when exiting a ready state */
  715. static void port_state_machine_change(struct scic_sds_port *sci_port,
  716. enum scic_sds_port_states state)
  717. {
  718. struct sci_base_state_machine *sm = &sci_port->state_machine;
  719. enum scic_sds_port_states old_state = sm->current_state_id;
  720. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  721. sci_port->ready_exit = true;
  722. sci_base_state_machine_change_state(sm, state);
  723. sci_port->ready_exit = false;
  724. }
  725. /**
  726. * scic_sds_port_general_link_up_handler - phy can be assigned to port?
  727. * @sci_port: scic_sds_port object for which has a phy that has gone link up.
  728. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  729. * @do_notify_user: This parameter specifies whether to inform the user (via
  730. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  731. *
  732. * Determine if this phy can be assigned to this
  733. * port . If the phy is not a valid PHY for
  734. * this port then the function will notify the user. A PHY can only be
  735. * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
  736. * the same port. none
  737. */
  738. static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
  739. struct scic_sds_phy *sci_phy,
  740. bool do_notify_user)
  741. {
  742. struct sci_sas_address port_sas_address;
  743. struct sci_sas_address phy_sas_address;
  744. scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
  745. scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
  746. /* If the SAS address of the new phy matches the SAS address of
  747. * other phys in the port OR this is the first phy in the port,
  748. * then activate the phy and allow it to be used for operations
  749. * in this port.
  750. */
  751. if ((phy_sas_address.high == port_sas_address.high &&
  752. phy_sas_address.low == port_sas_address.low) ||
  753. sci_port->active_phy_mask == 0) {
  754. struct sci_base_state_machine *sm = &sci_port->state_machine;
  755. scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
  756. if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
  757. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
  758. } else
  759. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  760. }
  761. /**
  762. * This method returns false if the port only has a single phy object assigned.
  763. * If there are no phys or more than one phy then the method will return
  764. * true.
  765. * @sci_port: The port for which the wide port condition is to be checked.
  766. *
  767. * bool true Is returned if this is a wide ported port. false Is returned if
  768. * this is a narrow port.
  769. */
  770. static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
  771. {
  772. u32 index;
  773. u32 phy_count = 0;
  774. for (index = 0; index < SCI_MAX_PHYS; index++) {
  775. if (sci_port->phy_table[index] != NULL) {
  776. phy_count++;
  777. }
  778. }
  779. return phy_count != 1;
  780. }
  781. /**
  782. * This method is called by the PHY object when the link is detected. if the
  783. * port wants the PHY to continue on to the link up state then the port
  784. * layer must return true. If the port object returns false the phy object
  785. * must halt its attempt to go link up.
  786. * @sci_port: The port associated with the phy object.
  787. * @sci_phy: The phy object that is trying to go link up.
  788. *
  789. * true if the phy object can continue to the link up condition. true Is
  790. * returned if this phy can continue to the ready state. false Is returned if
  791. * can not continue on to the ready state. This notification is in place for
  792. * wide ports and direct attached phys. Since there are no wide ported SATA
  793. * devices this could become an invalid port configuration.
  794. */
  795. bool scic_sds_port_link_detected(
  796. struct scic_sds_port *sci_port,
  797. struct scic_sds_phy *sci_phy)
  798. {
  799. if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  800. (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
  801. scic_sds_port_is_wide(sci_port)) {
  802. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  803. return false;
  804. }
  805. return true;
  806. }
  807. /**
  808. * This method is the entry point for the phy to inform the port that it is now
  809. * in a ready state
  810. * @sci_port:
  811. *
  812. *
  813. */
  814. void scic_sds_port_link_up(
  815. struct scic_sds_port *sci_port,
  816. struct scic_sds_phy *sci_phy)
  817. {
  818. sci_phy->is_in_link_training = false;
  819. sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
  820. }
  821. /**
  822. * This method is the entry point for the phy to inform the port that it is no
  823. * longer in a ready state
  824. * @sci_port:
  825. *
  826. *
  827. */
  828. void scic_sds_port_link_down(
  829. struct scic_sds_port *sci_port,
  830. struct scic_sds_phy *sci_phy)
  831. {
  832. sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
  833. }
  834. /**
  835. * This method is called to start an IO request on this port.
  836. * @sci_port:
  837. * @sci_dev:
  838. * @sci_req:
  839. *
  840. * enum sci_status
  841. */
  842. enum sci_status scic_sds_port_start_io(
  843. struct scic_sds_port *sci_port,
  844. struct scic_sds_remote_device *sci_dev,
  845. struct scic_sds_request *sci_req)
  846. {
  847. return sci_port->state_handlers->start_io_handler(
  848. sci_port, sci_dev, sci_req);
  849. }
  850. /**
  851. * This method is called to complete an IO request to the port.
  852. * @sci_port:
  853. * @sci_dev:
  854. * @sci_req:
  855. *
  856. * enum sci_status
  857. */
  858. enum sci_status scic_sds_port_complete_io(
  859. struct scic_sds_port *sci_port,
  860. struct scic_sds_remote_device *sci_dev,
  861. struct scic_sds_request *sci_req)
  862. {
  863. return sci_port->state_handlers->complete_io_handler(
  864. sci_port, sci_dev, sci_req);
  865. }
  866. /**
  867. * This method is provided to timeout requests for port operations. Mostly its
  868. * for the port reset operation.
  869. *
  870. *
  871. */
  872. static void scic_sds_port_timeout_handler(void *port)
  873. {
  874. struct scic_sds_port *sci_port = port;
  875. u32 current_state;
  876. current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
  877. if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
  878. /* if the port is still in the resetting state then the timeout
  879. * fired before the reset completed.
  880. */
  881. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
  882. } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
  883. /* if the port is stopped then the start request failed In this
  884. * case stay in the stopped state.
  885. */
  886. dev_err(sciport_to_dev(sci_port),
  887. "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
  888. __func__,
  889. sci_port);
  890. } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
  891. /* if the port is still stopping then the stop has not completed */
  892. isci_port_stop_complete(sci_port->owning_controller,
  893. sci_port,
  894. SCI_FAILURE_TIMEOUT);
  895. } else {
  896. /* The port is in the ready state and we have a timer
  897. * reporting a timeout this should not happen.
  898. */
  899. dev_err(sciport_to_dev(sci_port),
  900. "%s: SCIC Port 0x%p is processing a timeout operation "
  901. "in state %d.\n", __func__, sci_port, current_state);
  902. }
  903. }
  904. /* --------------------------------------------------------------------------- */
  905. /**
  906. * This function updates the hardwares VIIT entry for this port.
  907. *
  908. *
  909. */
  910. static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
  911. {
  912. struct sci_sas_address sas_address;
  913. scic_sds_port_get_sas_address(sci_port, &sas_address);
  914. writel(sas_address.high,
  915. &sci_port->viit_registers->initiator_sas_address_hi);
  916. writel(sas_address.low,
  917. &sci_port->viit_registers->initiator_sas_address_lo);
  918. /* This value get cleared just in case its not already cleared */
  919. writel(0, &sci_port->viit_registers->reserved);
  920. /* We are required to update the status register last */
  921. writel(SCU_VIIT_ENTRY_ID_VIIT |
  922. SCU_VIIT_IPPT_INITIATOR |
  923. ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  924. SCU_VIIT_STATUS_ALL_VALID,
  925. &sci_port->viit_registers->status);
  926. }
  927. /**
  928. * This method returns the maximum allowed speed for data transfers on this
  929. * port. This maximum allowed speed evaluates to the maximum speed of the
  930. * slowest phy in the port.
  931. * @sci_port: This parameter specifies the port for which to retrieve the
  932. * maximum allowed speed.
  933. *
  934. * This method returns the maximum negotiated speed of the slowest phy in the
  935. * port.
  936. */
  937. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  938. struct scic_sds_port *sci_port)
  939. {
  940. u16 index;
  941. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  942. struct scic_sds_phy *phy = NULL;
  943. /*
  944. * Loop through all of the phys in this port and find the phy with the
  945. * lowest maximum link rate. */
  946. for (index = 0; index < SCI_MAX_PHYS; index++) {
  947. phy = sci_port->phy_table[index];
  948. if (
  949. (phy != NULL)
  950. && (scic_sds_port_active_phy(sci_port, phy) == true)
  951. && (phy->max_negotiated_speed < max_allowed_speed)
  952. )
  953. max_allowed_speed = phy->max_negotiated_speed;
  954. }
  955. return max_allowed_speed;
  956. }
  957. static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
  958. {
  959. struct scic_sds_phy *phy;
  960. u32 register_value;
  961. u8 index;
  962. /* Loop through all of the phys to enable BCN. */
  963. for (index = 0; index < SCI_MAX_PHYS; index++) {
  964. phy = port->phy_table[index];
  965. if (phy != NULL) {
  966. register_value =
  967. readl(&phy->link_layer_registers->link_layer_control);
  968. /* clear the bit by writing 1. */
  969. writel(register_value,
  970. &phy->link_layer_registers->link_layer_control);
  971. }
  972. }
  973. }
  974. /*
  975. * ****************************************************************************
  976. * * READY SUBSTATE HANDLERS
  977. * **************************************************************************** */
  978. /*
  979. * This method is the general ready substate complete io handler for the
  980. * struct scic_sds_port object. This function decrments the outstanding request count
  981. * for this port object. enum sci_status SCI_SUCCESS
  982. */
  983. static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
  984. struct scic_sds_port *port,
  985. struct scic_sds_remote_device *device,
  986. struct scic_sds_request *io_request)
  987. {
  988. scic_sds_port_decrement_request_count(port);
  989. return SCI_SUCCESS;
  990. }
  991. /**
  992. *
  993. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  994. * gone link up.
  995. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  996. *
  997. * This method is the ready waiting substate link up handler for the
  998. * struct scic_sds_port object. This methos will report the link up condition for
  999. * this port and will transition to the ready operational substate. none
  1000. */
  1001. static void scic_sds_port_ready_waiting_substate_link_up_handler(
  1002. struct scic_sds_port *sci_port,
  1003. struct scic_sds_phy *sci_phy)
  1004. {
  1005. /*
  1006. * Since this is the first phy going link up for the port we can just enable
  1007. * it and continue. */
  1008. scic_sds_port_activate_phy(sci_port, sci_phy, true);
  1009. port_state_machine_change(sci_port,
  1010. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1011. }
  1012. /*
  1013. * This method is the ready waiting substate start io handler for the
  1014. * struct scic_sds_port object. The port object can not accept new requests so the
  1015. * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
  1016. */
  1017. static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
  1018. struct scic_sds_port *port,
  1019. struct scic_sds_remote_device *device,
  1020. struct scic_sds_request *io_request)
  1021. {
  1022. return SCI_FAILURE_INVALID_STATE;
  1023. }
  1024. /**
  1025. * scic_sds_port_ready_operational_substate_link_up_handler() -
  1026. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1027. * gone link up.
  1028. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  1029. *
  1030. * This method is the ready operational substate link up handler for the
  1031. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1032. * gone link up. none
  1033. */
  1034. static void scic_sds_port_ready_operational_substate_link_up_handler(
  1035. struct scic_sds_port *sci_port,
  1036. struct scic_sds_phy *sci_phy)
  1037. {
  1038. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1039. }
  1040. /**
  1041. * scic_sds_port_ready_operational_substate_link_down_handler() -
  1042. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1043. * gone link down.
  1044. * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
  1045. *
  1046. * This method is the ready operational substate link down handler for the
  1047. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1048. * gone link down and if this is the last phy in the port the port will change
  1049. * state to the ready waiting substate. none
  1050. */
  1051. static void scic_sds_port_ready_operational_substate_link_down_handler(
  1052. struct scic_sds_port *sci_port,
  1053. struct scic_sds_phy *sci_phy)
  1054. {
  1055. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1056. /*
  1057. * If there are no active phys left in the port, then transition
  1058. * the port to the WAITING state until such time as a phy goes
  1059. * link up. */
  1060. if (sci_port->active_phy_mask == 0)
  1061. port_state_machine_change(sci_port,
  1062. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1063. }
  1064. /*
  1065. * This method is the ready operational substate start io handler for the
  1066. * struct scic_sds_port object. This function incremetns the outstanding request
  1067. * count for this port object. enum sci_status SCI_SUCCESS
  1068. */
  1069. static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
  1070. struct scic_sds_port *port,
  1071. struct scic_sds_remote_device *device,
  1072. struct scic_sds_request *io_request)
  1073. {
  1074. port->started_request_count++;
  1075. return SCI_SUCCESS;
  1076. }
  1077. /**
  1078. * scic_sds_port_ready_configuring_substate_complete_io_handler() -
  1079. * @port: This is the port that is being requested to complete the io request.
  1080. * @device: This is the device on which the io is completing.
  1081. *
  1082. * This method will decrement the outstanding request count for this port. If
  1083. * the request count goes to 0 then the port can be reprogrammed with its new
  1084. * phy data.
  1085. */
  1086. static enum sci_status
  1087. scic_sds_port_ready_configuring_substate_complete_io_handler(
  1088. struct scic_sds_port *port,
  1089. struct scic_sds_remote_device *device,
  1090. struct scic_sds_request *io_request)
  1091. {
  1092. scic_sds_port_decrement_request_count(port);
  1093. if (port->started_request_count == 0) {
  1094. port_state_machine_change(port,
  1095. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1096. }
  1097. return SCI_SUCCESS;
  1098. }
  1099. static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
  1100. const char *func)
  1101. {
  1102. dev_warn(sciport_to_dev(sci_port),
  1103. "%s: in wrong state: %d\n", func,
  1104. sci_base_state_machine_get_state(&sci_port->state_machine));
  1105. return SCI_FAILURE_INVALID_STATE;
  1106. }
  1107. /*
  1108. * This is the default method for a port unsolicited frame request. It will
  1109. * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
  1110. * possible to receive an unsolicited frame directed to a port object? It
  1111. * seems possible if we implementing virtual functions but until then?
  1112. */
  1113. static enum sci_status
  1114. scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
  1115. u32 frame_index)
  1116. {
  1117. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  1118. default_port_handler(sci_port, __func__);
  1119. scic_sds_controller_release_frame(scic, frame_index);
  1120. return SCI_FAILURE_INVALID_STATE;
  1121. }
  1122. static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
  1123. u32 event_code)
  1124. {
  1125. return default_port_handler(sci_port, __func__);
  1126. }
  1127. static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
  1128. struct scic_sds_phy *sci_phy)
  1129. {
  1130. default_port_handler(sci_port, __func__);
  1131. }
  1132. static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
  1133. struct scic_sds_phy *sci_phy)
  1134. {
  1135. default_port_handler(sci_port, __func__);
  1136. }
  1137. static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
  1138. struct scic_sds_remote_device *sci_dev,
  1139. struct scic_sds_request *sci_req)
  1140. {
  1141. return default_port_handler(sci_port, __func__);
  1142. }
  1143. static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
  1144. struct scic_sds_remote_device *sci_dev,
  1145. struct scic_sds_request *sci_req)
  1146. {
  1147. return default_port_handler(sci_port, __func__);
  1148. }
  1149. /*
  1150. * ******************************************************************************
  1151. * * PORT STATE PRIVATE METHODS
  1152. * ****************************************************************************** */
  1153. /**
  1154. *
  1155. * @sci_port: This is the struct scic_sds_port object to suspend.
  1156. *
  1157. * This method will susped the port task scheduler for this port object. none
  1158. */
  1159. static void
  1160. scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
  1161. {
  1162. u32 pts_control_value;
  1163. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1164. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  1165. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1166. }
  1167. /**
  1168. * scic_sds_port_post_dummy_request() - post dummy/workaround request
  1169. * @sci_port: port to post task
  1170. *
  1171. * Prevent the hardware scheduler from posting new requests to the front
  1172. * of the scheduler queue causing a starvation problem for currently
  1173. * ongoing requests.
  1174. *
  1175. */
  1176. static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
  1177. {
  1178. u32 command;
  1179. struct scu_task_context *task_context;
  1180. struct scic_sds_controller *scic = sci_port->owning_controller;
  1181. u16 tci = sci_port->reserved_tci;
  1182. task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
  1183. task_context->abort = 0;
  1184. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  1185. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1186. tci;
  1187. scic_sds_controller_post_request(scic, command);
  1188. }
  1189. /**
  1190. * This routine will abort the dummy request. This will alow the hardware to
  1191. * power down parts of the silicon to save power.
  1192. *
  1193. * @sci_port: The port on which the task must be aborted.
  1194. *
  1195. */
  1196. static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
  1197. {
  1198. struct scic_sds_controller *scic = sci_port->owning_controller;
  1199. u16 tci = sci_port->reserved_tci;
  1200. struct scu_task_context *tc;
  1201. u32 command;
  1202. tc = scic_sds_controller_get_task_context_buffer(scic, tci);
  1203. tc->abort = 1;
  1204. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  1205. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1206. tci;
  1207. scic_sds_controller_post_request(scic, command);
  1208. }
  1209. /**
  1210. *
  1211. * @sci_port: This is the struct scic_sds_port object to resume.
  1212. *
  1213. * This method will resume the port task scheduler for this port object. none
  1214. */
  1215. static void
  1216. scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
  1217. {
  1218. u32 pts_control_value;
  1219. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1220. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  1221. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1222. }
  1223. /*
  1224. * ******************************************************************************
  1225. * * PORT READY SUBSTATE METHODS
  1226. * ****************************************************************************** */
  1227. /**
  1228. *
  1229. * @object: This is the object which is cast to a struct scic_sds_port object.
  1230. *
  1231. * This method will perform the actions required by the struct scic_sds_port on
  1232. * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
  1233. * port for any ready phys. If there is at least one phy in a ready state then
  1234. * the port transitions to the ready operational substate. none
  1235. */
  1236. static void scic_sds_port_ready_substate_waiting_enter(void *object)
  1237. {
  1238. struct scic_sds_port *sci_port = object;
  1239. scic_sds_port_set_base_state_handlers(
  1240. sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
  1241. );
  1242. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1243. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  1244. if (sci_port->active_phy_mask != 0) {
  1245. /* At least one of the phys on the port is ready */
  1246. port_state_machine_change(sci_port,
  1247. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1248. }
  1249. }
  1250. /**
  1251. *
  1252. * @object: This is the object which is cast to a struct scic_sds_port object.
  1253. *
  1254. * This function will perform the actions required by the struct scic_sds_port
  1255. * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
  1256. * the state handlers for the port object, notifies the SCI User that the port
  1257. * is ready, and resumes port operations. none
  1258. */
  1259. static void scic_sds_port_ready_substate_operational_enter(void *object)
  1260. {
  1261. u32 index;
  1262. struct scic_sds_port *sci_port = object;
  1263. struct scic_sds_controller *scic = sci_port->owning_controller;
  1264. struct isci_host *ihost = scic_to_ihost(scic);
  1265. struct isci_port *iport = sci_port_to_iport(sci_port);
  1266. scic_sds_port_set_base_state_handlers(
  1267. sci_port,
  1268. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1269. isci_port_ready(ihost, iport);
  1270. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1271. if (sci_port->phy_table[index]) {
  1272. writel(sci_port->physical_port_index,
  1273. &sci_port->port_pe_configuration_register[
  1274. sci_port->phy_table[index]->phy_index]);
  1275. }
  1276. }
  1277. scic_sds_port_update_viit_entry(sci_port);
  1278. scic_sds_port_resume_port_task_scheduler(sci_port);
  1279. /*
  1280. * Post the dummy task for the port so the hardware can schedule
  1281. * io correctly
  1282. */
  1283. scic_sds_port_post_dummy_request(sci_port);
  1284. }
  1285. static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
  1286. {
  1287. struct scic_sds_controller *scic = sci_port->owning_controller;
  1288. u8 phys_index = sci_port->physical_port_index;
  1289. union scu_remote_node_context *rnc;
  1290. u16 rni = sci_port->reserved_rni;
  1291. u32 command;
  1292. rnc = &scic->remote_node_context_table[rni];
  1293. rnc->ssp.is_valid = false;
  1294. /* ensure the preceding tc abort request has reached the
  1295. * controller and give it ample time to act before posting the rnc
  1296. * invalidate
  1297. */
  1298. readl(&scic->smu_registers->interrupt_status); /* flush */
  1299. udelay(10);
  1300. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  1301. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1302. scic_sds_controller_post_request(scic, command);
  1303. }
  1304. /**
  1305. *
  1306. * @object: This is the object which is cast to a struct scic_sds_port object.
  1307. *
  1308. * This method will perform the actions required by the struct scic_sds_port on
  1309. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1310. * the port not ready and suspends the port task scheduler. none
  1311. */
  1312. static void scic_sds_port_ready_substate_operational_exit(void *object)
  1313. {
  1314. struct scic_sds_port *sci_port = object;
  1315. struct scic_sds_controller *scic = sci_port->owning_controller;
  1316. struct isci_host *ihost = scic_to_ihost(scic);
  1317. struct isci_port *iport = sci_port_to_iport(sci_port);
  1318. /*
  1319. * Kill the dummy task for this port if it has not yet posted
  1320. * the hardware will treat this as a NOP and just return abort
  1321. * complete.
  1322. */
  1323. scic_sds_port_abort_dummy_request(sci_port);
  1324. isci_port_not_ready(ihost, iport);
  1325. if (sci_port->ready_exit)
  1326. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1327. }
  1328. /*
  1329. * ******************************************************************************
  1330. * * PORT READY CONFIGURING METHODS
  1331. * ****************************************************************************** */
  1332. /**
  1333. * scic_sds_port_ready_substate_configuring_enter() -
  1334. * @object: This is the object which is cast to a struct scic_sds_port object.
  1335. *
  1336. * This method will perform the actions required by the struct scic_sds_port on
  1337. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1338. * the port not ready and suspends the port task scheduler. none
  1339. */
  1340. static void scic_sds_port_ready_substate_configuring_enter(void *object)
  1341. {
  1342. struct scic_sds_port *sci_port = object;
  1343. struct scic_sds_controller *scic = sci_port->owning_controller;
  1344. struct isci_host *ihost = scic_to_ihost(scic);
  1345. struct isci_port *iport = sci_port_to_iport(sci_port);
  1346. scic_sds_port_set_base_state_handlers(
  1347. sci_port,
  1348. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1349. if (sci_port->active_phy_mask == 0) {
  1350. isci_port_not_ready(ihost, iport);
  1351. port_state_machine_change(sci_port,
  1352. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1353. } else if (sci_port->started_request_count == 0)
  1354. port_state_machine_change(sci_port,
  1355. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1356. }
  1357. static void scic_sds_port_ready_substate_configuring_exit(void *object)
  1358. {
  1359. struct scic_sds_port *sci_port = object;
  1360. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1361. if (sci_port->ready_exit)
  1362. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1363. }
  1364. /* --------------------------------------------------------------------------- */
  1365. /**
  1366. *
  1367. * @port: This is the struct scic_sds_port object on which the io request count will
  1368. * be decremented.
  1369. * @device: This is the struct scic_sds_remote_device object to which the io request
  1370. * is being directed. This parameter is not required to complete this
  1371. * operation.
  1372. * @io_request: This is the request that is being completed on this port
  1373. * object. This parameter is not required to complete this operation.
  1374. *
  1375. * This is a general complete io request handler for the struct scic_sds_port object.
  1376. * enum sci_status SCI_SUCCESS
  1377. */
  1378. static enum sci_status scic_sds_port_general_complete_io_handler(
  1379. struct scic_sds_port *port,
  1380. struct scic_sds_remote_device *device,
  1381. struct scic_sds_request *io_request)
  1382. {
  1383. scic_sds_port_decrement_request_count(port);
  1384. return SCI_SUCCESS;
  1385. }
  1386. /*
  1387. * This method takes the struct scic_sds_port that is in a stopping state and handles
  1388. * the complete io request. Should the request count reach 0 then the port
  1389. * object will transition to the stopped state. enum sci_status SCI_SUCCESS
  1390. */
  1391. static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
  1392. struct scic_sds_port *sci_port,
  1393. struct scic_sds_remote_device *device,
  1394. struct scic_sds_request *io_request)
  1395. {
  1396. scic_sds_port_decrement_request_count(sci_port);
  1397. if (sci_port->started_request_count == 0)
  1398. port_state_machine_change(sci_port,
  1399. SCI_BASE_PORT_STATE_STOPPED);
  1400. return SCI_SUCCESS;
  1401. }
  1402. /*
  1403. * ****************************************************************************
  1404. * * RESETTING STATE HANDLERS
  1405. * **************************************************************************** */
  1406. /*
  1407. * This method will transition a failed port to its ready state. The port
  1408. * failed because a hard reset request timed out but at some time later one or
  1409. * more phys in the port became ready. enum sci_status SCI_SUCCESS
  1410. */
  1411. static void scic_sds_port_reset_state_link_up_handler(
  1412. struct scic_sds_port *port,
  1413. struct scic_sds_phy *phy)
  1414. {
  1415. /*
  1416. * / @todo We should make sure that the phy that has gone link up is the same
  1417. * / one on which we sent the reset. It is possible that the phy on
  1418. * / which we sent the reset is not the one that has gone link up and we
  1419. * / want to make sure that phy being reset comes back. Consider the
  1420. * / case where a reset is sent but before the hardware processes the
  1421. * / reset it get a link up on the port because of a hot plug event.
  1422. * / because of the reset request this phy will go link down almost
  1423. * / immediately. */
  1424. /*
  1425. * In the resetting state we don't notify the user regarding
  1426. * link up and link down notifications. */
  1427. scic_sds_port_general_link_up_handler(port, phy, false);
  1428. }
  1429. /*
  1430. * This method process link down notifications that occur during a port reset
  1431. * operation. Link downs can occur during the reset operation. enum sci_status
  1432. * SCI_SUCCESS
  1433. */
  1434. static void scic_sds_port_reset_state_link_down_handler(
  1435. struct scic_sds_port *port,
  1436. struct scic_sds_phy *phy)
  1437. {
  1438. /*
  1439. * In the resetting state we don't notify the user regarding
  1440. * link up and link down notifications. */
  1441. scic_sds_port_deactivate_phy(port, phy, false);
  1442. }
  1443. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port)
  1444. {
  1445. struct scic_sds_controller *scic = sci_port->owning_controller;
  1446. struct isci_host *ihost = scic_to_ihost(scic);
  1447. enum sci_status status = SCI_SUCCESS;
  1448. enum scic_sds_port_states state;
  1449. u32 phy_mask;
  1450. state = sci_port->state_machine.current_state_id;
  1451. if (state != SCI_BASE_PORT_STATE_STOPPED) {
  1452. dev_warn(sciport_to_dev(sci_port),
  1453. "%s: in wrong state: %d\n", __func__, state);
  1454. return SCI_FAILURE_INVALID_STATE;
  1455. }
  1456. if (sci_port->assigned_device_count > 0) {
  1457. /* TODO This is a start failure operation because
  1458. * there are still devices assigned to this port.
  1459. * There must be no devices assigned to a port on a
  1460. * start operation.
  1461. */
  1462. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1463. }
  1464. sci_port->timer_handle =
  1465. isci_timer_create(ihost,
  1466. sci_port,
  1467. scic_sds_port_timeout_handler);
  1468. if (!sci_port->timer_handle)
  1469. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1470. if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
  1471. u16 rni = scic_sds_remote_node_table_allocate_remote_node(
  1472. &scic->available_remote_nodes, 1);
  1473. if (rni != SCU_DUMMY_INDEX)
  1474. scic_sds_port_construct_dummy_rnc(sci_port, rni);
  1475. else
  1476. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1477. sci_port->reserved_rni = rni;
  1478. }
  1479. if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
  1480. /* Allocate a TCI and remove the sequence nibble */
  1481. u16 tci = scic_controller_allocate_io_tag(scic);
  1482. if (tci != SCU_DUMMY_INDEX)
  1483. scic_sds_port_construct_dummy_task(sci_port, tci);
  1484. else
  1485. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1486. sci_port->reserved_tci = tci;
  1487. }
  1488. if (status == SCI_SUCCESS) {
  1489. phy_mask = scic_sds_port_get_phys(sci_port);
  1490. /*
  1491. * There are one or more phys assigned to this port. Make sure
  1492. * the port's phy mask is in fact legal and supported by the
  1493. * silicon.
  1494. */
  1495. if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
  1496. port_state_machine_change(sci_port,
  1497. SCI_BASE_PORT_STATE_READY);
  1498. return SCI_SUCCESS;
  1499. }
  1500. status = SCI_FAILURE;
  1501. }
  1502. if (status != SCI_SUCCESS)
  1503. scic_sds_port_destroy_dummy_resources(sci_port);
  1504. return status;
  1505. }
  1506. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
  1507. {
  1508. enum scic_sds_port_states state;
  1509. state = sci_port->state_machine.current_state_id;
  1510. switch (state) {
  1511. case SCI_BASE_PORT_STATE_STOPPED:
  1512. return SCI_SUCCESS;
  1513. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1514. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1515. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1516. case SCI_BASE_PORT_STATE_RESETTING:
  1517. port_state_machine_change(sci_port,
  1518. SCI_BASE_PORT_STATE_STOPPING);
  1519. return SCI_SUCCESS;
  1520. default:
  1521. dev_warn(sciport_to_dev(sci_port),
  1522. "%s: in wrong state: %d\n", __func__, state);
  1523. return SCI_FAILURE_INVALID_STATE;
  1524. }
  1525. }
  1526. static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
  1527. {
  1528. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  1529. struct scic_sds_phy *selected_phy = NULL;
  1530. enum scic_sds_port_states state;
  1531. u32 phy_index;
  1532. state = sci_port->state_machine.current_state_id;
  1533. if (state != SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL) {
  1534. dev_warn(sciport_to_dev(sci_port),
  1535. "%s: in wrong state: %d\n", __func__, state);
  1536. return SCI_FAILURE_INVALID_STATE;
  1537. }
  1538. /* Select a phy on which we can send the hard reset request. */
  1539. for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) {
  1540. selected_phy = sci_port->phy_table[phy_index];
  1541. if (selected_phy &&
  1542. !scic_sds_port_active_phy(sci_port, selected_phy)) {
  1543. /*
  1544. * We found a phy but it is not ready select
  1545. * different phy
  1546. */
  1547. selected_phy = NULL;
  1548. }
  1549. }
  1550. /* If we have a phy then go ahead and start the reset procedure */
  1551. if (!selected_phy)
  1552. return status;
  1553. status = scic_sds_phy_reset(selected_phy);
  1554. if (status != SCI_SUCCESS)
  1555. return status;
  1556. isci_timer_start(sci_port->timer_handle, timeout);
  1557. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  1558. port_state_machine_change(sci_port,
  1559. SCI_BASE_PORT_STATE_RESETTING);
  1560. return SCI_SUCCESS;
  1561. }
  1562. /**
  1563. * scic_sds_port_add_phy() -
  1564. * @sci_port: This parameter specifies the port in which the phy will be added.
  1565. * @sci_phy: This parameter is the phy which is to be added to the port.
  1566. *
  1567. * This method will add a PHY to the selected port. This method returns an
  1568. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
  1569. * status is a failure to add the phy to the port.
  1570. */
  1571. enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
  1572. struct scic_sds_phy *sci_phy)
  1573. {
  1574. enum sci_status status;
  1575. enum scic_sds_port_states state;
  1576. state = sci_port->state_machine.current_state_id;
  1577. switch (state) {
  1578. case SCI_BASE_PORT_STATE_STOPPED: {
  1579. struct sci_sas_address port_sas_address;
  1580. /* Read the port assigned SAS Address if there is one */
  1581. scic_sds_port_get_sas_address(sci_port, &port_sas_address);
  1582. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1583. struct sci_sas_address phy_sas_address;
  1584. /* Make sure that the PHY SAS Address matches the SAS Address
  1585. * for this port
  1586. */
  1587. scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address);
  1588. if (port_sas_address.high != phy_sas_address.high ||
  1589. port_sas_address.low != phy_sas_address.low)
  1590. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1591. }
  1592. return scic_sds_port_set_phy(sci_port, sci_phy);
  1593. }
  1594. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1595. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1596. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1597. if (status != SCI_SUCCESS)
  1598. return status;
  1599. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1600. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1601. port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1602. return status;
  1603. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1604. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1605. if (status != SCI_SUCCESS)
  1606. return status;
  1607. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1608. /* Re-enter the configuring state since this may be the last phy in
  1609. * the port.
  1610. */
  1611. port_state_machine_change(sci_port,
  1612. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1613. return SCI_SUCCESS;
  1614. default:
  1615. dev_warn(sciport_to_dev(sci_port),
  1616. "%s: in wrong state: %d\n", __func__, state);
  1617. return SCI_FAILURE_INVALID_STATE;
  1618. }
  1619. }
  1620. /**
  1621. * scic_sds_port_remove_phy() -
  1622. * @sci_port: This parameter specifies the port in which the phy will be added.
  1623. * @sci_phy: This parameter is the phy which is to be added to the port.
  1624. *
  1625. * This method will remove the PHY from the selected PORT. This method returns
  1626. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
  1627. * other status is a failure to add the phy to the port.
  1628. */
  1629. enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
  1630. struct scic_sds_phy *sci_phy)
  1631. {
  1632. enum sci_status status;
  1633. enum scic_sds_port_states state;
  1634. state = sci_port->state_machine.current_state_id;
  1635. switch (state) {
  1636. case SCI_BASE_PORT_STATE_STOPPED:
  1637. return scic_sds_port_clear_phy(sci_port, sci_phy);
  1638. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1639. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1640. if (status != SCI_SUCCESS)
  1641. return status;
  1642. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1643. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1644. port_state_machine_change(sci_port,
  1645. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1646. return SCI_SUCCESS;
  1647. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1648. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1649. if (status != SCI_SUCCESS)
  1650. return status;
  1651. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1652. /* Re-enter the configuring state since this may be the last phy in
  1653. * the port
  1654. */
  1655. port_state_machine_change(sci_port,
  1656. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1657. return SCI_SUCCESS;
  1658. default:
  1659. dev_warn(sciport_to_dev(sci_port),
  1660. "%s: in wrong state: %d\n", __func__, state);
  1661. return SCI_FAILURE_INVALID_STATE;
  1662. }
  1663. }
  1664. static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
  1665. [SCI_BASE_PORT_STATE_STOPPED] = {
  1666. .frame_handler = scic_sds_port_default_frame_handler,
  1667. .event_handler = scic_sds_port_default_event_handler,
  1668. .link_up_handler = scic_sds_port_default_link_up_handler,
  1669. .link_down_handler = scic_sds_port_default_link_down_handler,
  1670. .start_io_handler = scic_sds_port_default_start_io_handler,
  1671. .complete_io_handler = scic_sds_port_default_complete_io_handler
  1672. },
  1673. [SCI_BASE_PORT_STATE_STOPPING] = {
  1674. .frame_handler = scic_sds_port_default_frame_handler,
  1675. .event_handler = scic_sds_port_default_event_handler,
  1676. .link_up_handler = scic_sds_port_default_link_up_handler,
  1677. .link_down_handler = scic_sds_port_default_link_down_handler,
  1678. .start_io_handler = scic_sds_port_default_start_io_handler,
  1679. .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
  1680. },
  1681. [SCI_BASE_PORT_STATE_READY] = {
  1682. .frame_handler = scic_sds_port_default_frame_handler,
  1683. .event_handler = scic_sds_port_default_event_handler,
  1684. .link_up_handler = scic_sds_port_default_link_up_handler,
  1685. .link_down_handler = scic_sds_port_default_link_down_handler,
  1686. .start_io_handler = scic_sds_port_default_start_io_handler,
  1687. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1688. },
  1689. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1690. .frame_handler = scic_sds_port_default_frame_handler,
  1691. .event_handler = scic_sds_port_default_event_handler,
  1692. .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
  1693. .link_down_handler = scic_sds_port_default_link_down_handler,
  1694. .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
  1695. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1696. },
  1697. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1698. .frame_handler = scic_sds_port_default_frame_handler,
  1699. .event_handler = scic_sds_port_default_event_handler,
  1700. .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
  1701. .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
  1702. .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
  1703. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1704. },
  1705. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1706. .frame_handler = scic_sds_port_default_frame_handler,
  1707. .event_handler = scic_sds_port_default_event_handler,
  1708. .link_up_handler = scic_sds_port_default_link_up_handler,
  1709. .link_down_handler = scic_sds_port_default_link_down_handler,
  1710. .start_io_handler = scic_sds_port_default_start_io_handler,
  1711. .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
  1712. },
  1713. [SCI_BASE_PORT_STATE_RESETTING] = {
  1714. .frame_handler = scic_sds_port_default_frame_handler,
  1715. .event_handler = scic_sds_port_default_event_handler,
  1716. .link_up_handler = scic_sds_port_reset_state_link_up_handler,
  1717. .link_down_handler = scic_sds_port_reset_state_link_down_handler,
  1718. .start_io_handler = scic_sds_port_default_start_io_handler,
  1719. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1720. },
  1721. [SCI_BASE_PORT_STATE_FAILED] = {
  1722. .frame_handler = scic_sds_port_default_frame_handler,
  1723. .event_handler = scic_sds_port_default_event_handler,
  1724. .link_up_handler = scic_sds_port_default_link_up_handler,
  1725. .link_down_handler = scic_sds_port_default_link_down_handler,
  1726. .start_io_handler = scic_sds_port_default_start_io_handler,
  1727. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1728. }
  1729. };
  1730. /*
  1731. * ******************************************************************************
  1732. * * PORT STATE PRIVATE METHODS
  1733. * ****************************************************************************** */
  1734. /**
  1735. *
  1736. * @sci_port: This is the port object which to suspend.
  1737. *
  1738. * This method will enable the SCU Port Task Scheduler for this port object but
  1739. * will leave the port task scheduler in a suspended state. none
  1740. */
  1741. static void
  1742. scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
  1743. {
  1744. u32 pts_control_value;
  1745. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1746. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1747. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1748. }
  1749. /**
  1750. *
  1751. * @sci_port: This is the port object which to resume.
  1752. *
  1753. * This method will disable the SCU port task scheduler for this port object.
  1754. * none
  1755. */
  1756. static void
  1757. scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
  1758. {
  1759. u32 pts_control_value;
  1760. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1761. pts_control_value &=
  1762. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1763. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1764. }
  1765. static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
  1766. {
  1767. struct scic_sds_controller *scic = sci_port->owning_controller;
  1768. u8 phys_index = sci_port->physical_port_index;
  1769. union scu_remote_node_context *rnc;
  1770. u16 rni = sci_port->reserved_rni;
  1771. u32 command;
  1772. rnc = &scic->remote_node_context_table[rni];
  1773. rnc->ssp.is_valid = true;
  1774. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1775. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1776. scic_sds_controller_post_request(scic, command);
  1777. /* ensure hardware has seen the post rnc command and give it
  1778. * ample time to act before sending the suspend
  1779. */
  1780. readl(&scic->smu_registers->interrupt_status); /* flush */
  1781. udelay(10);
  1782. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1783. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1784. scic_sds_controller_post_request(scic, command);
  1785. }
  1786. /*
  1787. * ******************************************************************************
  1788. * * PORT STATE METHODS
  1789. * ****************************************************************************** */
  1790. /**
  1791. *
  1792. * @object: This is the object which is cast to a struct scic_sds_port object.
  1793. *
  1794. * This method will perform the actions required by the struct scic_sds_port on
  1795. * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
  1796. * state handlers for the struct scic_sds_port object and disables the port task
  1797. * scheduler in the hardware. none
  1798. */
  1799. static void scic_sds_port_stopped_state_enter(void *object)
  1800. {
  1801. struct scic_sds_port *sci_port = object;
  1802. scic_sds_port_set_base_state_handlers(
  1803. sci_port, SCI_BASE_PORT_STATE_STOPPED
  1804. );
  1805. if (
  1806. SCI_BASE_PORT_STATE_STOPPING
  1807. == sci_port->state_machine.previous_state_id
  1808. ) {
  1809. /*
  1810. * If we enter this state becasuse of a request to stop
  1811. * the port then we want to disable the hardwares port
  1812. * task scheduler. */
  1813. scic_sds_port_disable_port_task_scheduler(sci_port);
  1814. }
  1815. }
  1816. /**
  1817. *
  1818. * @object: This is the object which is cast to a struct scic_sds_port object.
  1819. *
  1820. * This method will perform the actions required by the struct scic_sds_port on
  1821. * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
  1822. * port task scheduler. none
  1823. */
  1824. static void scic_sds_port_stopped_state_exit(void *object)
  1825. {
  1826. struct scic_sds_port *sci_port = object;
  1827. /* Enable and suspend the port task scheduler */
  1828. scic_sds_port_enable_port_task_scheduler(sci_port);
  1829. }
  1830. /**
  1831. * scic_sds_port_ready_state_enter -
  1832. * @object: This is the object which is cast to a struct scic_sds_port object.
  1833. *
  1834. * This method will perform the actions required by the struct scic_sds_port on
  1835. * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
  1836. * handlers for the struct scic_sds_port object, reports the port object as
  1837. * not ready and starts the ready substate machine. none
  1838. */
  1839. static void scic_sds_port_ready_state_enter(void *object)
  1840. {
  1841. struct scic_sds_port *sci_port = object;
  1842. struct scic_sds_controller *scic = sci_port->owning_controller;
  1843. struct isci_host *ihost = scic_to_ihost(scic);
  1844. struct isci_port *iport = sci_port_to_iport(sci_port);
  1845. u32 prev_state;
  1846. /* Put the ready state handlers in place though they will not be there long */
  1847. scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
  1848. prev_state = sci_port->state_machine.previous_state_id;
  1849. if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
  1850. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  1851. else
  1852. isci_port_not_ready(ihost, iport);
  1853. /* Post and suspend the dummy remote node context for this port. */
  1854. scic_sds_port_post_dummy_remote_node(sci_port);
  1855. /* Start the ready substate machine */
  1856. port_state_machine_change(sci_port,
  1857. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1858. }
  1859. /**
  1860. *
  1861. * @object: This is the object which is cast to a struct scic_sds_port object.
  1862. *
  1863. * This method will perform the actions required by the struct scic_sds_port on
  1864. * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
  1865. * state handlers for the struct scic_sds_port object. none
  1866. */
  1867. static void scic_sds_port_resetting_state_enter(void *object)
  1868. {
  1869. struct scic_sds_port *sci_port = object;
  1870. scic_sds_port_set_base_state_handlers(
  1871. sci_port, SCI_BASE_PORT_STATE_RESETTING
  1872. );
  1873. }
  1874. /**
  1875. *
  1876. * @object: This is the object which is cast to a struct scic_sds_port object.
  1877. *
  1878. * This function will perform the actions required by the
  1879. * struct scic_sds_port on
  1880. * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
  1881. */
  1882. static inline void scic_sds_port_resetting_state_exit(void *object)
  1883. {
  1884. struct scic_sds_port *sci_port = object;
  1885. isci_timer_stop(sci_port->timer_handle);
  1886. }
  1887. /**
  1888. *
  1889. * @object: This is the void object which is cast to a
  1890. * struct scic_sds_port object.
  1891. *
  1892. * This method will perform the actions required by the struct scic_sds_port on
  1893. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  1894. * state handlers for the struct scic_sds_port object. none
  1895. */
  1896. static void scic_sds_port_stopping_state_enter(void *object)
  1897. {
  1898. struct scic_sds_port *sci_port = object;
  1899. scic_sds_port_set_base_state_handlers(
  1900. sci_port, SCI_BASE_PORT_STATE_STOPPING
  1901. );
  1902. }
  1903. /**
  1904. *
  1905. * @object: This is the object which is cast to a struct scic_sds_port object.
  1906. *
  1907. * This function will perform the actions required by the
  1908. * struct scic_sds_port on
  1909. * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
  1910. */
  1911. static inline void
  1912. scic_sds_port_stopping_state_exit(void *object)
  1913. {
  1914. struct scic_sds_port *sci_port = object;
  1915. isci_timer_stop(sci_port->timer_handle);
  1916. scic_sds_port_destroy_dummy_resources(sci_port);
  1917. }
  1918. /**
  1919. *
  1920. * @object: This is the object which is cast to a struct scic_sds_port object.
  1921. *
  1922. * This function will perform the actions required by the
  1923. * struct scic_sds_port on
  1924. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  1925. * state handlers for the struct scic_sds_port object. none
  1926. */
  1927. static void scic_sds_port_failed_state_enter(void *object)
  1928. {
  1929. struct scic_sds_port *sci_port = object;
  1930. struct isci_port *iport = sci_port_to_iport(sci_port);
  1931. scic_sds_port_set_base_state_handlers(sci_port,
  1932. SCI_BASE_PORT_STATE_FAILED);
  1933. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  1934. }
  1935. /* --------------------------------------------------------------------------- */
  1936. static const struct sci_base_state scic_sds_port_state_table[] = {
  1937. [SCI_BASE_PORT_STATE_STOPPED] = {
  1938. .enter_state = scic_sds_port_stopped_state_enter,
  1939. .exit_state = scic_sds_port_stopped_state_exit
  1940. },
  1941. [SCI_BASE_PORT_STATE_STOPPING] = {
  1942. .enter_state = scic_sds_port_stopping_state_enter,
  1943. .exit_state = scic_sds_port_stopping_state_exit
  1944. },
  1945. [SCI_BASE_PORT_STATE_READY] = {
  1946. .enter_state = scic_sds_port_ready_state_enter,
  1947. },
  1948. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1949. .enter_state = scic_sds_port_ready_substate_waiting_enter,
  1950. },
  1951. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1952. .enter_state = scic_sds_port_ready_substate_operational_enter,
  1953. .exit_state = scic_sds_port_ready_substate_operational_exit
  1954. },
  1955. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1956. .enter_state = scic_sds_port_ready_substate_configuring_enter,
  1957. .exit_state = scic_sds_port_ready_substate_configuring_exit
  1958. },
  1959. [SCI_BASE_PORT_STATE_RESETTING] = {
  1960. .enter_state = scic_sds_port_resetting_state_enter,
  1961. .exit_state = scic_sds_port_resetting_state_exit
  1962. },
  1963. [SCI_BASE_PORT_STATE_FAILED] = {
  1964. .enter_state = scic_sds_port_failed_state_enter,
  1965. }
  1966. };
  1967. void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
  1968. struct scic_sds_controller *scic)
  1969. {
  1970. sci_base_state_machine_construct(&sci_port->state_machine,
  1971. sci_port,
  1972. scic_sds_port_state_table,
  1973. SCI_BASE_PORT_STATE_STOPPED);
  1974. sci_base_state_machine_start(&sci_port->state_machine);
  1975. sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
  1976. sci_port->physical_port_index = index;
  1977. sci_port->active_phy_mask = 0;
  1978. sci_port->ready_exit = false;
  1979. sci_port->owning_controller = scic;
  1980. sci_port->started_request_count = 0;
  1981. sci_port->assigned_device_count = 0;
  1982. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  1983. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  1984. sci_port->timer_handle = NULL;
  1985. sci_port->port_task_scheduler_registers = NULL;
  1986. for (index = 0; index < SCI_MAX_PHYS; index++)
  1987. sci_port->phy_table[index] = NULL;
  1988. }
  1989. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  1990. {
  1991. INIT_LIST_HEAD(&iport->remote_dev_list);
  1992. INIT_LIST_HEAD(&iport->domain_dev_list);
  1993. spin_lock_init(&iport->state_lock);
  1994. init_completion(&iport->start_complete);
  1995. iport->isci_host = ihost;
  1996. isci_port_change_state(iport, isci_freed);
  1997. }
  1998. /**
  1999. * isci_port_get_state() - This function gets the status of the port object.
  2000. * @isci_port: This parameter points to the isci_port object
  2001. *
  2002. * status of the object as a isci_status enum.
  2003. */
  2004. enum isci_status isci_port_get_state(
  2005. struct isci_port *isci_port)
  2006. {
  2007. return isci_port->status;
  2008. }
  2009. static void isci_port_bc_change_received(struct isci_host *ihost,
  2010. struct scic_sds_port *sci_port,
  2011. struct scic_sds_phy *sci_phy)
  2012. {
  2013. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  2014. dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
  2015. __func__, iphy, &iphy->sas_phy);
  2016. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  2017. scic_port_enable_broadcast_change_notification(sci_port);
  2018. }
  2019. void scic_sds_port_broadcast_change_received(
  2020. struct scic_sds_port *sci_port,
  2021. struct scic_sds_phy *sci_phy)
  2022. {
  2023. struct scic_sds_controller *scic = sci_port->owning_controller;
  2024. struct isci_host *ihost = scic_to_ihost(scic);
  2025. /* notify the user. */
  2026. isci_port_bc_change_received(ihost, sci_port, sci_phy);
  2027. }
  2028. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  2029. struct isci_phy *iphy)
  2030. {
  2031. unsigned long flags;
  2032. enum sci_status status;
  2033. int ret = TMF_RESP_FUNC_COMPLETE;
  2034. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  2035. __func__, iport);
  2036. init_completion(&iport->hard_reset_complete);
  2037. spin_lock_irqsave(&ihost->scic_lock, flags);
  2038. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  2039. status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
  2040. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  2041. if (status == SCI_SUCCESS) {
  2042. wait_for_completion(&iport->hard_reset_complete);
  2043. dev_dbg(&ihost->pdev->dev,
  2044. "%s: iport = %p; hard reset completion\n",
  2045. __func__, iport);
  2046. if (iport->hard_reset_status != SCI_SUCCESS)
  2047. ret = TMF_RESP_FUNC_FAILED;
  2048. } else {
  2049. ret = TMF_RESP_FUNC_FAILED;
  2050. dev_err(&ihost->pdev->dev,
  2051. "%s: iport = %p; scic_port_hard_reset call"
  2052. " failed 0x%x\n",
  2053. __func__, iport, status);
  2054. }
  2055. /* If the hard reset for the port has failed, consider this
  2056. * the same as link failures on all phys in the port.
  2057. */
  2058. if (ret != TMF_RESP_FUNC_COMPLETE) {
  2059. dev_err(&ihost->pdev->dev,
  2060. "%s: iport = %p; hard reset failed "
  2061. "(0x%x) - sending link down to libsas for phy %p\n",
  2062. __func__, iport, iport->hard_reset_status, iphy);
  2063. isci_port_link_down(ihost, iphy, iport);
  2064. }
  2065. return ret;
  2066. }
  2067. /**
  2068. * isci_port_deformed() - This function is called by libsas when a port becomes
  2069. * inactive.
  2070. * @phy: This parameter specifies the libsas phy with the inactive port.
  2071. *
  2072. */
  2073. void isci_port_deformed(struct asd_sas_phy *phy)
  2074. {
  2075. pr_debug("%s: sas_phy = %p\n", __func__, phy);
  2076. }
  2077. /**
  2078. * isci_port_formed() - This function is called by libsas when a port becomes
  2079. * active.
  2080. * @phy: This parameter specifies the libsas phy with the active port.
  2081. *
  2082. */
  2083. void isci_port_formed(struct asd_sas_phy *phy)
  2084. {
  2085. pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
  2086. }