port.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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 void isci_port_change_state(struct isci_port *iport, enum isci_status status)
  62. {
  63. unsigned long flags;
  64. dev_dbg(&iport->isci_host->pdev->dev,
  65. "%s: iport = %p, state = 0x%x\n",
  66. __func__, iport, status);
  67. /* XXX pointless lock */
  68. spin_lock_irqsave(&iport->state_lock, flags);
  69. iport->status = status;
  70. spin_unlock_irqrestore(&iport->state_lock, flags);
  71. }
  72. /*
  73. * This function will indicate which protocols are supported by this port.
  74. * @sci_port: a handle corresponding to the SAS port for which to return the
  75. * supported protocols.
  76. * @protocols: This parameter specifies a pointer to a data structure
  77. * which the core will copy the protocol values for the port from the
  78. * transmit_identification register.
  79. */
  80. static void
  81. scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
  82. struct scic_phy_proto *protocols)
  83. {
  84. u8 index;
  85. protocols->all = 0;
  86. for (index = 0; index < SCI_MAX_PHYS; index++) {
  87. if (sci_port->phy_table[index] != NULL) {
  88. scic_sds_phy_get_protocols(sci_port->phy_table[index],
  89. protocols);
  90. }
  91. }
  92. }
  93. /**
  94. * This method requests a list (mask) of the phys contained in the supplied SAS
  95. * port.
  96. * @sci_port: a handle corresponding to the SAS port for which to return the
  97. * phy mask.
  98. *
  99. * Return a bit mask indicating which phys are a part of this port. Each bit
  100. * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
  101. */
  102. static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
  103. {
  104. u32 index;
  105. u32 mask;
  106. mask = 0;
  107. for (index = 0; index < SCI_MAX_PHYS; index++) {
  108. if (sci_port->phy_table[index] != NULL) {
  109. mask |= (1 << index);
  110. }
  111. }
  112. return mask;
  113. }
  114. /**
  115. * scic_port_get_properties() - This method simply returns the properties
  116. * regarding the port, such as: physical index, protocols, sas address, etc.
  117. * @port: this parameter specifies the port for which to retrieve the physical
  118. * index.
  119. * @properties: This parameter specifies the properties structure into which to
  120. * copy the requested information.
  121. *
  122. * Indicate if the user specified a valid port. SCI_SUCCESS This value is
  123. * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
  124. * value is returned if the specified port is not valid. When this value is
  125. * returned, no data is copied to the properties output parameter.
  126. */
  127. static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
  128. struct scic_port_properties *prop)
  129. {
  130. if ((port == NULL) ||
  131. (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
  132. return SCI_FAILURE_INVALID_PORT;
  133. prop->index = port->logical_port_index;
  134. prop->phy_mask = scic_sds_port_get_phys(port);
  135. scic_sds_port_get_sas_address(port, &prop->local.sas_address);
  136. scic_sds_port_get_protocols(port, &prop->local.protocols);
  137. scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
  138. return SCI_SUCCESS;
  139. }
  140. static void isci_port_link_up(struct isci_host *isci_host,
  141. struct scic_sds_port *port,
  142. struct scic_sds_phy *phy)
  143. {
  144. unsigned long flags;
  145. struct scic_port_properties properties;
  146. struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
  147. struct isci_port *isci_port = sci_port_to_iport(port);
  148. unsigned long success = true;
  149. BUG_ON(isci_phy->isci_port != NULL);
  150. isci_phy->isci_port = isci_port;
  151. dev_dbg(&isci_host->pdev->dev,
  152. "%s: isci_port = %p\n",
  153. __func__, isci_port);
  154. spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  155. isci_port_change_state(isci_phy->isci_port, isci_starting);
  156. scic_port_get_properties(port, &properties);
  157. if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
  158. u64 attached_sas_address;
  159. isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
  160. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  161. /*
  162. * For direct-attached SATA devices, the SCI core will
  163. * automagically assign a SAS address to the end device
  164. * for the purpose of creating a port. This SAS address
  165. * will not be the same as assigned to the PHY and needs
  166. * to be obtained from struct scic_port_properties properties.
  167. */
  168. attached_sas_address = properties.remote.sas_address.high;
  169. attached_sas_address <<= 32;
  170. attached_sas_address |= properties.remote.sas_address.low;
  171. swab64s(&attached_sas_address);
  172. memcpy(&isci_phy->sas_phy.attached_sas_addr,
  173. &attached_sas_address, sizeof(attached_sas_address));
  174. } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  175. isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
  176. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  177. /* Copy the attached SAS address from the IAF */
  178. memcpy(isci_phy->sas_phy.attached_sas_addr,
  179. isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  180. } else {
  181. dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
  182. success = false;
  183. }
  184. isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
  185. spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  186. /* Notify libsas that we have an address frame, if indeed
  187. * we've found an SSP, SMP, or STP target */
  188. if (success)
  189. isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
  190. PORTE_BYTES_DMAED);
  191. }
  192. /**
  193. * isci_port_link_down() - This function is called by the sci core when a link
  194. * becomes inactive.
  195. * @isci_host: This parameter specifies the isci host object.
  196. * @phy: This parameter specifies the isci phy with the active link.
  197. * @port: This parameter specifies the isci port with the active link.
  198. *
  199. */
  200. static void isci_port_link_down(struct isci_host *isci_host,
  201. struct isci_phy *isci_phy,
  202. struct isci_port *isci_port)
  203. {
  204. struct isci_remote_device *isci_device;
  205. dev_dbg(&isci_host->pdev->dev,
  206. "%s: isci_port = %p\n", __func__, isci_port);
  207. if (isci_port) {
  208. /* check to see if this is the last phy on this port. */
  209. if (isci_phy->sas_phy.port
  210. && isci_phy->sas_phy.port->num_phys == 1) {
  211. /* change the state for all devices on this port.
  212. * The next task sent to this device will be returned
  213. * as SAS_TASK_UNDELIVERED, and the scsi mid layer
  214. * will remove the target
  215. */
  216. list_for_each_entry(isci_device,
  217. &isci_port->remote_dev_list,
  218. node) {
  219. dev_dbg(&isci_host->pdev->dev,
  220. "%s: isci_device = %p\n",
  221. __func__, isci_device);
  222. isci_remote_device_change_state(isci_device,
  223. isci_stopping);
  224. }
  225. }
  226. isci_port_change_state(isci_port, isci_stopping);
  227. }
  228. /* Notify libsas of the borken link, this will trigger calls to our
  229. * isci_port_deformed and isci_dev_gone functions.
  230. */
  231. sas_phy_disconnected(&isci_phy->sas_phy);
  232. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  233. PHYE_LOSS_OF_SIGNAL);
  234. isci_phy->isci_port = NULL;
  235. dev_dbg(&isci_host->pdev->dev,
  236. "%s: isci_port = %p - Done\n", __func__, isci_port);
  237. }
  238. /**
  239. * isci_port_ready() - This function is called by the sci core when a link
  240. * becomes ready.
  241. * @isci_host: This parameter specifies the isci host object.
  242. * @port: This parameter specifies the sci port with the active link.
  243. *
  244. */
  245. static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  246. {
  247. dev_dbg(&isci_host->pdev->dev,
  248. "%s: isci_port = %p\n", __func__, isci_port);
  249. complete_all(&isci_port->start_complete);
  250. isci_port_change_state(isci_port, isci_ready);
  251. return;
  252. }
  253. /**
  254. * isci_port_not_ready() - This function is called by the sci core when a link
  255. * is not ready. All remote devices on this link will be removed if they are
  256. * in the stopping state.
  257. * @isci_host: This parameter specifies the isci host object.
  258. * @port: This parameter specifies the sci port with the active link.
  259. *
  260. */
  261. static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  262. {
  263. dev_dbg(&isci_host->pdev->dev,
  264. "%s: isci_port = %p\n", __func__, isci_port);
  265. }
  266. static void isci_port_stop_complete(struct scic_sds_controller *scic,
  267. struct scic_sds_port *sci_port,
  268. enum sci_status completion_status)
  269. {
  270. dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
  271. }
  272. /**
  273. * isci_port_hard_reset_complete() - This function is called by the sci core
  274. * when the hard reset complete notification has been received.
  275. * @port: This parameter specifies the sci port with the active link.
  276. * @completion_status: This parameter specifies the core status for the reset
  277. * process.
  278. *
  279. */
  280. static void isci_port_hard_reset_complete(struct isci_port *isci_port,
  281. enum sci_status completion_status)
  282. {
  283. dev_dbg(&isci_port->isci_host->pdev->dev,
  284. "%s: isci_port = %p, completion_status=%x\n",
  285. __func__, isci_port, completion_status);
  286. /* Save the status of the hard reset from the port. */
  287. isci_port->hard_reset_status = completion_status;
  288. complete_all(&isci_port->hard_reset_complete);
  289. }
  290. /* This method will return a true value if the specified phy can be assigned to
  291. * this port The following is a list of phys for each port that are allowed: -
  292. * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
  293. * doesn't preclude all configurations. It merely ensures that a phy is part
  294. * of the allowable set of phy identifiers for that port. For example, one
  295. * could assign phy 3 to port 0 and no other phys. Please refer to
  296. * scic_sds_port_is_phy_mask_valid() for information regarding whether the
  297. * phy_mask for a port can be supported. bool true if this is a valid phy
  298. * assignment for the port false if this is not a valid phy assignment for the
  299. * port
  300. */
  301. bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
  302. u32 phy_index)
  303. {
  304. /* Initialize to invalid value. */
  305. u32 existing_phy_index = SCI_MAX_PHYS;
  306. u32 index;
  307. if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
  308. return false;
  309. }
  310. if (sci_port->physical_port_index == 3 && phy_index != 3) {
  311. return false;
  312. }
  313. if (
  314. (sci_port->physical_port_index == 2)
  315. && ((phy_index == 0) || (phy_index == 1))
  316. ) {
  317. return false;
  318. }
  319. for (index = 0; index < SCI_MAX_PHYS; index++) {
  320. if ((sci_port->phy_table[index] != NULL)
  321. && (index != phy_index)) {
  322. existing_phy_index = index;
  323. }
  324. }
  325. /*
  326. * Ensure that all of the phys in the port are capable of
  327. * operating at the same maximum link rate. */
  328. if (
  329. (existing_phy_index < SCI_MAX_PHYS)
  330. && (sci_port->owning_controller->user_parameters.sds1.phys[
  331. phy_index].max_speed_generation !=
  332. sci_port->owning_controller->user_parameters.sds1.phys[
  333. existing_phy_index].max_speed_generation)
  334. )
  335. return false;
  336. return true;
  337. }
  338. /**
  339. *
  340. * @sci_port: This is the port object for which to determine if the phy mask
  341. * can be supported.
  342. *
  343. * This method will return a true value if the port's phy mask can be supported
  344. * by the SCU. The following is a list of valid PHY mask configurations for
  345. * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
  346. * - Port 3 - [3] This method returns a boolean indication specifying if the
  347. * phy mask can be supported. true if this is a valid phy assignment for the
  348. * port false if this is not a valid phy assignment for the port
  349. */
  350. static bool scic_sds_port_is_phy_mask_valid(
  351. struct scic_sds_port *sci_port,
  352. u32 phy_mask)
  353. {
  354. if (sci_port->physical_port_index == 0) {
  355. if (((phy_mask & 0x0F) == 0x0F)
  356. || ((phy_mask & 0x03) == 0x03)
  357. || ((phy_mask & 0x01) == 0x01)
  358. || (phy_mask == 0))
  359. return true;
  360. } else if (sci_port->physical_port_index == 1) {
  361. if (((phy_mask & 0x02) == 0x02)
  362. || (phy_mask == 0))
  363. return true;
  364. } else if (sci_port->physical_port_index == 2) {
  365. if (((phy_mask & 0x0C) == 0x0C)
  366. || ((phy_mask & 0x04) == 0x04)
  367. || (phy_mask == 0))
  368. return true;
  369. } else if (sci_port->physical_port_index == 3) {
  370. if (((phy_mask & 0x08) == 0x08)
  371. || (phy_mask == 0))
  372. return true;
  373. }
  374. return false;
  375. }
  376. /**
  377. *
  378. * @sci_port: This parameter specifies the port from which to return a
  379. * connected phy.
  380. *
  381. * This method retrieves a currently active (i.e. connected) phy contained in
  382. * the port. Currently, the lowest order phy that is connected is returned.
  383. * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
  384. * returned if there are no currently active (i.e. connected to a remote end
  385. * point) phys contained in the port. All other values specify a struct scic_sds_phy
  386. * object that is active in the port.
  387. */
  388. static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
  389. struct scic_sds_port *sci_port
  390. ) {
  391. u32 index;
  392. struct scic_sds_phy *phy;
  393. for (index = 0; index < SCI_MAX_PHYS; index++) {
  394. /*
  395. * Ensure that the phy is both part of the port and currently
  396. * connected to the remote end-point. */
  397. phy = sci_port->phy_table[index];
  398. if (
  399. (phy != NULL)
  400. && scic_sds_port_active_phy(sci_port, phy)
  401. ) {
  402. return phy;
  403. }
  404. }
  405. return NULL;
  406. }
  407. /**
  408. * scic_sds_port_set_phy() -
  409. * @out]: port The port object to which the phy assignement is being made.
  410. * @out]: phy The phy which is being assigned to the port.
  411. *
  412. * This method attempts to make the assignment of the phy to the port. If
  413. * successful the phy is assigned to the ports phy table. bool true if the phy
  414. * assignment can be made. false if the phy assignement can not be made. This
  415. * is a functional test that only fails if the phy is currently assigned to a
  416. * different port.
  417. */
  418. static enum sci_status scic_sds_port_set_phy(
  419. struct scic_sds_port *port,
  420. struct scic_sds_phy *phy)
  421. {
  422. /*
  423. * Check to see if we can add this phy to a port
  424. * that means that the phy is not part of a port and that the port does
  425. * not already have a phy assinged to the phy index. */
  426. if (
  427. (port->phy_table[phy->phy_index] == NULL)
  428. && (phy_get_non_dummy_port(phy) == NULL)
  429. && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
  430. ) {
  431. /*
  432. * Phy is being added in the stopped state so we are in MPC mode
  433. * make logical port index = physical port index */
  434. port->logical_port_index = port->physical_port_index;
  435. port->phy_table[phy->phy_index] = phy;
  436. scic_sds_phy_set_port(phy, port);
  437. return SCI_SUCCESS;
  438. }
  439. return SCI_FAILURE;
  440. }
  441. /**
  442. * scic_sds_port_clear_phy() -
  443. * @out]: port The port from which the phy is being cleared.
  444. * @out]: phy The phy being cleared from the port.
  445. *
  446. * This method will clear the phy assigned to this port. This method fails if
  447. * this phy is not currently assinged to this port. bool true if the phy is
  448. * removed from the port. false if this phy is not assined to this port.
  449. */
  450. static enum sci_status scic_sds_port_clear_phy(
  451. struct scic_sds_port *port,
  452. struct scic_sds_phy *phy)
  453. {
  454. /* Make sure that this phy is part of this port */
  455. if (port->phy_table[phy->phy_index] == phy &&
  456. phy_get_non_dummy_port(phy) == port) {
  457. struct scic_sds_controller *scic = port->owning_controller;
  458. struct isci_host *ihost = scic_to_ihost(scic);
  459. /* Yep it is assigned to this port so remove it */
  460. scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
  461. port->phy_table[phy->phy_index] = NULL;
  462. return SCI_SUCCESS;
  463. }
  464. return SCI_FAILURE;
  465. }
  466. /**
  467. * This method requests the SAS address for the supplied SAS port from the SCI
  468. * implementation.
  469. * @sci_port: a handle corresponding to the SAS port for which to return the
  470. * SAS address.
  471. * @sas_address: This parameter specifies a pointer to a SAS address structure
  472. * into which the core will copy the SAS address for the port.
  473. *
  474. */
  475. void scic_sds_port_get_sas_address(
  476. struct scic_sds_port *sci_port,
  477. struct sci_sas_address *sas_address)
  478. {
  479. u32 index;
  480. sas_address->high = 0;
  481. sas_address->low = 0;
  482. for (index = 0; index < SCI_MAX_PHYS; index++) {
  483. if (sci_port->phy_table[index] != NULL) {
  484. scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
  485. }
  486. }
  487. }
  488. /*
  489. * This function requests the SAS address for the device directly attached to
  490. * this SAS port.
  491. * @sci_port: a handle corresponding to the SAS port for which to return the
  492. * SAS address.
  493. * @sas_address: This parameter specifies a pointer to a SAS address structure
  494. * into which the core will copy the SAS address for the device directly
  495. * attached to the port.
  496. *
  497. */
  498. void scic_sds_port_get_attached_sas_address(
  499. struct scic_sds_port *sci_port,
  500. struct sci_sas_address *sas_address)
  501. {
  502. struct scic_sds_phy *sci_phy;
  503. /*
  504. * Ensure that the phy is both part of the port and currently
  505. * connected to the remote end-point.
  506. */
  507. sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
  508. if (sci_phy) {
  509. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
  510. scic_sds_phy_get_attached_sas_address(sci_phy,
  511. sas_address);
  512. } else {
  513. scic_sds_phy_get_sas_address(sci_phy, sas_address);
  514. sas_address->low += sci_phy->phy_index;
  515. }
  516. } else {
  517. sas_address->high = 0;
  518. sas_address->low = 0;
  519. }
  520. }
  521. /**
  522. * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
  523. *
  524. * @sci_port: logical port on which we need to create the remote node context
  525. * @rni: remote node index for this remote node context.
  526. *
  527. * This routine will construct a dummy remote node context data structure
  528. * This structure will be posted to the hardware to work around a scheduler
  529. * error in the hardware.
  530. */
  531. static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
  532. {
  533. union scu_remote_node_context *rnc;
  534. rnc = &sci_port->owning_controller->remote_node_context_table[rni];
  535. memset(rnc, 0, sizeof(union scu_remote_node_context));
  536. rnc->ssp.remote_sas_address_hi = 0;
  537. rnc->ssp.remote_sas_address_lo = 0;
  538. rnc->ssp.remote_node_index = rni;
  539. rnc->ssp.remote_node_port_width = 1;
  540. rnc->ssp.logical_port_index = sci_port->physical_port_index;
  541. rnc->ssp.nexus_loss_timer_enable = false;
  542. rnc->ssp.check_bit = false;
  543. rnc->ssp.is_valid = true;
  544. rnc->ssp.is_remote_node_context = true;
  545. rnc->ssp.function_number = 0;
  546. rnc->ssp.arbitration_wait_time = 0;
  547. }
  548. /**
  549. * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
  550. * @sci_port The logical port on which we need to create the
  551. * remote node context.
  552. * context.
  553. * @tci The remote node index for this remote node context.
  554. *
  555. * This routine will construct a dummy task context data structure. This
  556. * structure will be posted to the hardwre to work around a scheduler error
  557. * in the hardware.
  558. *
  559. */
  560. static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
  561. {
  562. struct scu_task_context *task_context;
  563. task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
  564. memset(task_context, 0, sizeof(struct scu_task_context));
  565. task_context->abort = 0;
  566. task_context->priority = 0;
  567. task_context->initiator_request = 1;
  568. task_context->connection_rate = 1;
  569. task_context->protocol_engine_index = 0;
  570. task_context->logical_port_index = sci_port->physical_port_index;
  571. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  572. task_context->task_index = scic_sds_io_tag_get_index(tci);
  573. task_context->valid = SCU_TASK_CONTEXT_VALID;
  574. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  575. task_context->remote_node_index = sci_port->reserved_rni;
  576. task_context->command_code = 0;
  577. task_context->link_layer_control = 0;
  578. task_context->do_not_dma_ssp_good_response = 1;
  579. task_context->strict_ordering = 0;
  580. task_context->control_frame = 0;
  581. task_context->timeout_enable = 0;
  582. task_context->block_guard_enable = 0;
  583. task_context->address_modifier = 0;
  584. task_context->task_phase = 0x01;
  585. }
  586. static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
  587. {
  588. struct scic_sds_controller *scic = sci_port->owning_controller;
  589. if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
  590. scic_controller_free_io_tag(scic, sci_port->reserved_tci);
  591. if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
  592. scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
  593. 1, sci_port->reserved_rni);
  594. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  595. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  596. }
  597. /**
  598. * This method performs initialization of the supplied port. Initialization
  599. * includes: - state machine initialization - member variable initialization
  600. * - configuring the phy_mask
  601. * @sci_port:
  602. * @transport_layer_registers:
  603. * @port_task_scheduler_registers:
  604. * @port_configuration_regsiter:
  605. *
  606. * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
  607. * if the phy being added to the port
  608. */
  609. enum sci_status scic_sds_port_initialize(
  610. struct scic_sds_port *sci_port,
  611. void __iomem *port_task_scheduler_registers,
  612. void __iomem *port_configuration_regsiter,
  613. void __iomem *viit_registers)
  614. {
  615. sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
  616. sci_port->port_pe_configuration_register = port_configuration_regsiter;
  617. sci_port->viit_registers = viit_registers;
  618. return SCI_SUCCESS;
  619. }
  620. /**
  621. * This method assigns the direct attached device ID for this port.
  622. *
  623. * @param[in] sci_port The port for which the direct attached device id is to
  624. * be assigned.
  625. * @param[in] device_id The direct attached device ID to assign to the port.
  626. * This will be the RNi for the device
  627. */
  628. void scic_sds_port_setup_transports(
  629. struct scic_sds_port *sci_port,
  630. u32 device_id)
  631. {
  632. u8 index;
  633. for (index = 0; index < SCI_MAX_PHYS; index++) {
  634. if (sci_port->active_phy_mask & (1 << index))
  635. scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
  636. }
  637. }
  638. /**
  639. *
  640. * @sci_port: This is the port on which the phy should be enabled.
  641. * @sci_phy: This is the specific phy which to enable.
  642. * @do_notify_user: This parameter specifies whether to inform the user (via
  643. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  644. *
  645. * This function will activate the phy in the port.
  646. * Activation includes: - adding
  647. * the phy to the port - enabling the Protocol Engine in the silicon. -
  648. * notifying the user that the link is up. none
  649. */
  650. static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
  651. struct scic_sds_phy *sci_phy,
  652. bool do_notify_user)
  653. {
  654. struct scic_sds_controller *scic = sci_port->owning_controller;
  655. struct isci_host *ihost = scic_to_ihost(scic);
  656. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
  657. scic_sds_phy_resume(sci_phy);
  658. sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
  659. scic_sds_controller_clear_invalid_phy(scic, sci_phy);
  660. if (do_notify_user == true)
  661. isci_port_link_up(ihost, sci_port, sci_phy);
  662. }
  663. void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
  664. struct scic_sds_phy *sci_phy,
  665. bool do_notify_user)
  666. {
  667. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  668. struct isci_port *iport = sci_port_to_iport(sci_port);
  669. struct isci_host *ihost = scic_to_ihost(scic);
  670. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  671. sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
  672. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  673. /* Re-assign the phy back to the LP as if it were a narrow port */
  674. writel(sci_phy->phy_index,
  675. &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
  676. if (do_notify_user == true)
  677. isci_port_link_down(ihost, iphy, iport);
  678. }
  679. /**
  680. *
  681. * @sci_port: This is the port on which the phy should be disabled.
  682. * @sci_phy: This is the specific phy which to disabled.
  683. *
  684. * This function will disable the phy and report that the phy is not valid for
  685. * this port object. None
  686. */
  687. static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
  688. struct scic_sds_phy *sci_phy)
  689. {
  690. struct scic_sds_controller *scic = sci_port->owning_controller;
  691. /*
  692. * Check to see if we have alreay reported this link as bad and if
  693. * not go ahead and tell the SCI_USER that we have discovered an
  694. * invalid link.
  695. */
  696. if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
  697. scic_sds_controller_set_invalid_phy(scic, sci_phy);
  698. dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
  699. }
  700. }
  701. static bool is_port_ready_state(enum scic_sds_port_states state)
  702. {
  703. switch (state) {
  704. case SCI_BASE_PORT_STATE_READY:
  705. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  706. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  707. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  708. return true;
  709. default:
  710. return false;
  711. }
  712. }
  713. /* flag dummy rnc hanling when exiting a ready state */
  714. static void port_state_machine_change(struct scic_sds_port *sci_port,
  715. enum scic_sds_port_states state)
  716. {
  717. struct sci_base_state_machine *sm = &sci_port->state_machine;
  718. enum scic_sds_port_states old_state = sm->current_state_id;
  719. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  720. sci_port->ready_exit = true;
  721. sci_base_state_machine_change_state(sm, state);
  722. sci_port->ready_exit = false;
  723. }
  724. /**
  725. * scic_sds_port_general_link_up_handler - phy can be assigned to port?
  726. * @sci_port: scic_sds_port object for which has a phy that has gone link up.
  727. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  728. * @do_notify_user: This parameter specifies whether to inform the user (via
  729. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  730. *
  731. * Determine if this phy can be assigned to this
  732. * port . If the phy is not a valid PHY for
  733. * this port then the function will notify the user. A PHY can only be
  734. * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
  735. * the same port. none
  736. */
  737. static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
  738. struct scic_sds_phy *sci_phy,
  739. bool do_notify_user)
  740. {
  741. struct sci_sas_address port_sas_address;
  742. struct sci_sas_address phy_sas_address;
  743. scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
  744. scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
  745. /* If the SAS address of the new phy matches the SAS address of
  746. * other phys in the port OR this is the first phy in the port,
  747. * then activate the phy and allow it to be used for operations
  748. * in this port.
  749. */
  750. if ((phy_sas_address.high == port_sas_address.high &&
  751. phy_sas_address.low == port_sas_address.low) ||
  752. sci_port->active_phy_mask == 0) {
  753. struct sci_base_state_machine *sm = &sci_port->state_machine;
  754. scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
  755. if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
  756. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
  757. } else
  758. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  759. }
  760. /**
  761. * This method returns false if the port only has a single phy object assigned.
  762. * If there are no phys or more than one phy then the method will return
  763. * true.
  764. * @sci_port: The port for which the wide port condition is to be checked.
  765. *
  766. * bool true Is returned if this is a wide ported port. false Is returned if
  767. * this is a narrow port.
  768. */
  769. static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
  770. {
  771. u32 index;
  772. u32 phy_count = 0;
  773. for (index = 0; index < SCI_MAX_PHYS; index++) {
  774. if (sci_port->phy_table[index] != NULL) {
  775. phy_count++;
  776. }
  777. }
  778. return phy_count != 1;
  779. }
  780. /**
  781. * This method is called by the PHY object when the link is detected. if the
  782. * port wants the PHY to continue on to the link up state then the port
  783. * layer must return true. If the port object returns false the phy object
  784. * must halt its attempt to go link up.
  785. * @sci_port: The port associated with the phy object.
  786. * @sci_phy: The phy object that is trying to go link up.
  787. *
  788. * true if the phy object can continue to the link up condition. true Is
  789. * returned if this phy can continue to the ready state. false Is returned if
  790. * can not continue on to the ready state. This notification is in place for
  791. * wide ports and direct attached phys. Since there are no wide ported SATA
  792. * devices this could become an invalid port configuration.
  793. */
  794. bool scic_sds_port_link_detected(
  795. struct scic_sds_port *sci_port,
  796. struct scic_sds_phy *sci_phy)
  797. {
  798. if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  799. (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
  800. scic_sds_port_is_wide(sci_port)) {
  801. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  802. return false;
  803. }
  804. return true;
  805. }
  806. static void port_timeout(unsigned long data)
  807. {
  808. struct sci_timer *tmr = (struct sci_timer *)data;
  809. struct scic_sds_port *sci_port = container_of(tmr, typeof(*sci_port), timer);
  810. struct isci_host *ihost = scic_to_ihost(sci_port->owning_controller);
  811. unsigned long flags;
  812. u32 current_state;
  813. spin_lock_irqsave(&ihost->scic_lock, flags);
  814. if (tmr->cancel)
  815. goto done;
  816. current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
  817. if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
  818. /* if the port is still in the resetting state then the timeout
  819. * fired before the reset completed.
  820. */
  821. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
  822. } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
  823. /* if the port is stopped then the start request failed In this
  824. * case stay in the stopped state.
  825. */
  826. dev_err(sciport_to_dev(sci_port),
  827. "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
  828. __func__,
  829. sci_port);
  830. } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
  831. /* if the port is still stopping then the stop has not completed */
  832. isci_port_stop_complete(sci_port->owning_controller,
  833. sci_port,
  834. SCI_FAILURE_TIMEOUT);
  835. } else {
  836. /* The port is in the ready state and we have a timer
  837. * reporting a timeout this should not happen.
  838. */
  839. dev_err(sciport_to_dev(sci_port),
  840. "%s: SCIC Port 0x%p is processing a timeout operation "
  841. "in state %d.\n", __func__, sci_port, current_state);
  842. }
  843. done:
  844. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  845. }
  846. /* --------------------------------------------------------------------------- */
  847. /**
  848. * This function updates the hardwares VIIT entry for this port.
  849. *
  850. *
  851. */
  852. static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
  853. {
  854. struct sci_sas_address sas_address;
  855. scic_sds_port_get_sas_address(sci_port, &sas_address);
  856. writel(sas_address.high,
  857. &sci_port->viit_registers->initiator_sas_address_hi);
  858. writel(sas_address.low,
  859. &sci_port->viit_registers->initiator_sas_address_lo);
  860. /* This value get cleared just in case its not already cleared */
  861. writel(0, &sci_port->viit_registers->reserved);
  862. /* We are required to update the status register last */
  863. writel(SCU_VIIT_ENTRY_ID_VIIT |
  864. SCU_VIIT_IPPT_INITIATOR |
  865. ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  866. SCU_VIIT_STATUS_ALL_VALID,
  867. &sci_port->viit_registers->status);
  868. }
  869. /**
  870. * This method returns the maximum allowed speed for data transfers on this
  871. * port. This maximum allowed speed evaluates to the maximum speed of the
  872. * slowest phy in the port.
  873. * @sci_port: This parameter specifies the port for which to retrieve the
  874. * maximum allowed speed.
  875. *
  876. * This method returns the maximum negotiated speed of the slowest phy in the
  877. * port.
  878. */
  879. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  880. struct scic_sds_port *sci_port)
  881. {
  882. u16 index;
  883. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  884. struct scic_sds_phy *phy = NULL;
  885. /*
  886. * Loop through all of the phys in this port and find the phy with the
  887. * lowest maximum link rate. */
  888. for (index = 0; index < SCI_MAX_PHYS; index++) {
  889. phy = sci_port->phy_table[index];
  890. if (
  891. (phy != NULL)
  892. && (scic_sds_port_active_phy(sci_port, phy) == true)
  893. && (phy->max_negotiated_speed < max_allowed_speed)
  894. )
  895. max_allowed_speed = phy->max_negotiated_speed;
  896. }
  897. return max_allowed_speed;
  898. }
  899. static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
  900. {
  901. struct scic_sds_phy *phy;
  902. u32 register_value;
  903. u8 index;
  904. /* Loop through all of the phys to enable BCN. */
  905. for (index = 0; index < SCI_MAX_PHYS; index++) {
  906. phy = port->phy_table[index];
  907. if (phy != NULL) {
  908. register_value =
  909. readl(&phy->link_layer_registers->link_layer_control);
  910. /* clear the bit by writing 1. */
  911. writel(register_value,
  912. &phy->link_layer_registers->link_layer_control);
  913. }
  914. }
  915. }
  916. /**
  917. *
  918. * @sci_port: This is the struct scic_sds_port object to suspend.
  919. *
  920. * This method will susped the port task scheduler for this port object. none
  921. */
  922. static void
  923. scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
  924. {
  925. u32 pts_control_value;
  926. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  927. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  928. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  929. }
  930. /**
  931. * scic_sds_port_post_dummy_request() - post dummy/workaround request
  932. * @sci_port: port to post task
  933. *
  934. * Prevent the hardware scheduler from posting new requests to the front
  935. * of the scheduler queue causing a starvation problem for currently
  936. * ongoing requests.
  937. *
  938. */
  939. static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
  940. {
  941. u32 command;
  942. struct scu_task_context *task_context;
  943. struct scic_sds_controller *scic = sci_port->owning_controller;
  944. u16 tci = sci_port->reserved_tci;
  945. task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
  946. task_context->abort = 0;
  947. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  948. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  949. tci;
  950. scic_sds_controller_post_request(scic, command);
  951. }
  952. /**
  953. * This routine will abort the dummy request. This will alow the hardware to
  954. * power down parts of the silicon to save power.
  955. *
  956. * @sci_port: The port on which the task must be aborted.
  957. *
  958. */
  959. static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
  960. {
  961. struct scic_sds_controller *scic = sci_port->owning_controller;
  962. u16 tci = sci_port->reserved_tci;
  963. struct scu_task_context *tc;
  964. u32 command;
  965. tc = scic_sds_controller_get_task_context_buffer(scic, tci);
  966. tc->abort = 1;
  967. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  968. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  969. tci;
  970. scic_sds_controller_post_request(scic, command);
  971. }
  972. /**
  973. *
  974. * @sci_port: This is the struct scic_sds_port object to resume.
  975. *
  976. * This method will resume the port task scheduler for this port object. none
  977. */
  978. static void
  979. scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
  980. {
  981. u32 pts_control_value;
  982. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  983. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  984. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  985. }
  986. static void scic_sds_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
  987. {
  988. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  989. scic_sds_port_suspend_port_task_scheduler(sci_port);
  990. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  991. if (sci_port->active_phy_mask != 0) {
  992. /* At least one of the phys on the port is ready */
  993. port_state_machine_change(sci_port,
  994. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  995. }
  996. }
  997. static void scic_sds_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
  998. {
  999. u32 index;
  1000. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1001. struct scic_sds_controller *scic = sci_port->owning_controller;
  1002. struct isci_host *ihost = scic_to_ihost(scic);
  1003. struct isci_port *iport = sci_port_to_iport(sci_port);
  1004. isci_port_ready(ihost, iport);
  1005. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1006. if (sci_port->phy_table[index]) {
  1007. writel(sci_port->physical_port_index,
  1008. &sci_port->port_pe_configuration_register[
  1009. sci_port->phy_table[index]->phy_index]);
  1010. }
  1011. }
  1012. scic_sds_port_update_viit_entry(sci_port);
  1013. scic_sds_port_resume_port_task_scheduler(sci_port);
  1014. /*
  1015. * Post the dummy task for the port so the hardware can schedule
  1016. * io correctly
  1017. */
  1018. scic_sds_port_post_dummy_request(sci_port);
  1019. }
  1020. static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
  1021. {
  1022. struct scic_sds_controller *scic = sci_port->owning_controller;
  1023. u8 phys_index = sci_port->physical_port_index;
  1024. union scu_remote_node_context *rnc;
  1025. u16 rni = sci_port->reserved_rni;
  1026. u32 command;
  1027. rnc = &scic->remote_node_context_table[rni];
  1028. rnc->ssp.is_valid = false;
  1029. /* ensure the preceding tc abort request has reached the
  1030. * controller and give it ample time to act before posting the rnc
  1031. * invalidate
  1032. */
  1033. readl(&scic->smu_registers->interrupt_status); /* flush */
  1034. udelay(10);
  1035. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  1036. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1037. scic_sds_controller_post_request(scic, command);
  1038. }
  1039. /**
  1040. *
  1041. * @object: This is the object which is cast to a struct scic_sds_port object.
  1042. *
  1043. * This method will perform the actions required by the struct scic_sds_port on
  1044. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1045. * the port not ready and suspends the port task scheduler. none
  1046. */
  1047. static void scic_sds_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
  1048. {
  1049. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1050. struct scic_sds_controller *scic = sci_port->owning_controller;
  1051. struct isci_host *ihost = scic_to_ihost(scic);
  1052. struct isci_port *iport = sci_port_to_iport(sci_port);
  1053. /*
  1054. * Kill the dummy task for this port if it has not yet posted
  1055. * the hardware will treat this as a NOP and just return abort
  1056. * complete.
  1057. */
  1058. scic_sds_port_abort_dummy_request(sci_port);
  1059. isci_port_not_ready(ihost, iport);
  1060. if (sci_port->ready_exit)
  1061. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1062. }
  1063. static void scic_sds_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
  1064. {
  1065. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1066. struct scic_sds_controller *scic = sci_port->owning_controller;
  1067. struct isci_host *ihost = scic_to_ihost(scic);
  1068. struct isci_port *iport = sci_port_to_iport(sci_port);
  1069. if (sci_port->active_phy_mask == 0) {
  1070. isci_port_not_ready(ihost, iport);
  1071. port_state_machine_change(sci_port,
  1072. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1073. } else if (sci_port->started_request_count == 0)
  1074. port_state_machine_change(sci_port,
  1075. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1076. }
  1077. static void scic_sds_port_ready_substate_configuring_exit(struct sci_base_state_machine *sm)
  1078. {
  1079. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1080. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1081. if (sci_port->ready_exit)
  1082. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1083. }
  1084. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port)
  1085. {
  1086. struct scic_sds_controller *scic = sci_port->owning_controller;
  1087. enum sci_status status = SCI_SUCCESS;
  1088. enum scic_sds_port_states state;
  1089. u32 phy_mask;
  1090. state = sci_port->state_machine.current_state_id;
  1091. if (state != SCI_BASE_PORT_STATE_STOPPED) {
  1092. dev_warn(sciport_to_dev(sci_port),
  1093. "%s: in wrong state: %d\n", __func__, state);
  1094. return SCI_FAILURE_INVALID_STATE;
  1095. }
  1096. if (sci_port->assigned_device_count > 0) {
  1097. /* TODO This is a start failure operation because
  1098. * there are still devices assigned to this port.
  1099. * There must be no devices assigned to a port on a
  1100. * start operation.
  1101. */
  1102. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1103. }
  1104. if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
  1105. u16 rni = scic_sds_remote_node_table_allocate_remote_node(
  1106. &scic->available_remote_nodes, 1);
  1107. if (rni != SCU_DUMMY_INDEX)
  1108. scic_sds_port_construct_dummy_rnc(sci_port, rni);
  1109. else
  1110. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1111. sci_port->reserved_rni = rni;
  1112. }
  1113. if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
  1114. /* Allocate a TCI and remove the sequence nibble */
  1115. u16 tci = scic_controller_allocate_io_tag(scic);
  1116. if (tci != SCU_DUMMY_INDEX)
  1117. scic_sds_port_construct_dummy_task(sci_port, tci);
  1118. else
  1119. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1120. sci_port->reserved_tci = tci;
  1121. }
  1122. if (status == SCI_SUCCESS) {
  1123. phy_mask = scic_sds_port_get_phys(sci_port);
  1124. /*
  1125. * There are one or more phys assigned to this port. Make sure
  1126. * the port's phy mask is in fact legal and supported by the
  1127. * silicon.
  1128. */
  1129. if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
  1130. port_state_machine_change(sci_port,
  1131. SCI_BASE_PORT_STATE_READY);
  1132. return SCI_SUCCESS;
  1133. }
  1134. status = SCI_FAILURE;
  1135. }
  1136. if (status != SCI_SUCCESS)
  1137. scic_sds_port_destroy_dummy_resources(sci_port);
  1138. return status;
  1139. }
  1140. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
  1141. {
  1142. enum scic_sds_port_states state;
  1143. state = sci_port->state_machine.current_state_id;
  1144. switch (state) {
  1145. case SCI_BASE_PORT_STATE_STOPPED:
  1146. return SCI_SUCCESS;
  1147. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1148. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1149. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1150. case SCI_BASE_PORT_STATE_RESETTING:
  1151. port_state_machine_change(sci_port,
  1152. SCI_BASE_PORT_STATE_STOPPING);
  1153. return SCI_SUCCESS;
  1154. default:
  1155. dev_warn(sciport_to_dev(sci_port),
  1156. "%s: in wrong state: %d\n", __func__, state);
  1157. return SCI_FAILURE_INVALID_STATE;
  1158. }
  1159. }
  1160. static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
  1161. {
  1162. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  1163. struct scic_sds_phy *selected_phy = NULL;
  1164. enum scic_sds_port_states state;
  1165. u32 phy_index;
  1166. state = sci_port->state_machine.current_state_id;
  1167. if (state != SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL) {
  1168. dev_warn(sciport_to_dev(sci_port),
  1169. "%s: in wrong state: %d\n", __func__, state);
  1170. return SCI_FAILURE_INVALID_STATE;
  1171. }
  1172. /* Select a phy on which we can send the hard reset request. */
  1173. for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) {
  1174. selected_phy = sci_port->phy_table[phy_index];
  1175. if (selected_phy &&
  1176. !scic_sds_port_active_phy(sci_port, selected_phy)) {
  1177. /*
  1178. * We found a phy but it is not ready select
  1179. * different phy
  1180. */
  1181. selected_phy = NULL;
  1182. }
  1183. }
  1184. /* If we have a phy then go ahead and start the reset procedure */
  1185. if (!selected_phy)
  1186. return status;
  1187. status = scic_sds_phy_reset(selected_phy);
  1188. if (status != SCI_SUCCESS)
  1189. return status;
  1190. sci_mod_timer(&sci_port->timer, timeout);
  1191. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  1192. port_state_machine_change(sci_port,
  1193. SCI_BASE_PORT_STATE_RESETTING);
  1194. return SCI_SUCCESS;
  1195. }
  1196. /**
  1197. * scic_sds_port_add_phy() -
  1198. * @sci_port: This parameter specifies the port in which the phy will be added.
  1199. * @sci_phy: This parameter is the phy which is to be added to the port.
  1200. *
  1201. * This method will add a PHY to the selected port. This method returns an
  1202. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
  1203. * status is a failure to add the phy to the port.
  1204. */
  1205. enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
  1206. struct scic_sds_phy *sci_phy)
  1207. {
  1208. enum sci_status status;
  1209. enum scic_sds_port_states state;
  1210. state = sci_port->state_machine.current_state_id;
  1211. switch (state) {
  1212. case SCI_BASE_PORT_STATE_STOPPED: {
  1213. struct sci_sas_address port_sas_address;
  1214. /* Read the port assigned SAS Address if there is one */
  1215. scic_sds_port_get_sas_address(sci_port, &port_sas_address);
  1216. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1217. struct sci_sas_address phy_sas_address;
  1218. /* Make sure that the PHY SAS Address matches the SAS Address
  1219. * for this port
  1220. */
  1221. scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address);
  1222. if (port_sas_address.high != phy_sas_address.high ||
  1223. port_sas_address.low != phy_sas_address.low)
  1224. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1225. }
  1226. return scic_sds_port_set_phy(sci_port, sci_phy);
  1227. }
  1228. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1229. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1230. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1231. if (status != SCI_SUCCESS)
  1232. return status;
  1233. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1234. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1235. port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1236. return status;
  1237. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1238. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1239. if (status != SCI_SUCCESS)
  1240. return status;
  1241. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1242. /* Re-enter the configuring state since this may be the last phy in
  1243. * the port.
  1244. */
  1245. port_state_machine_change(sci_port,
  1246. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1247. return SCI_SUCCESS;
  1248. default:
  1249. dev_warn(sciport_to_dev(sci_port),
  1250. "%s: in wrong state: %d\n", __func__, state);
  1251. return SCI_FAILURE_INVALID_STATE;
  1252. }
  1253. }
  1254. /**
  1255. * scic_sds_port_remove_phy() -
  1256. * @sci_port: This parameter specifies the port in which the phy will be added.
  1257. * @sci_phy: This parameter is the phy which is to be added to the port.
  1258. *
  1259. * This method will remove the PHY from the selected PORT. This method returns
  1260. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
  1261. * other status is a failure to add the phy to the port.
  1262. */
  1263. enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
  1264. struct scic_sds_phy *sci_phy)
  1265. {
  1266. enum sci_status status;
  1267. enum scic_sds_port_states state;
  1268. state = sci_port->state_machine.current_state_id;
  1269. switch (state) {
  1270. case SCI_BASE_PORT_STATE_STOPPED:
  1271. return scic_sds_port_clear_phy(sci_port, sci_phy);
  1272. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1273. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1274. if (status != SCI_SUCCESS)
  1275. return status;
  1276. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1277. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1278. port_state_machine_change(sci_port,
  1279. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1280. return SCI_SUCCESS;
  1281. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1282. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1283. if (status != SCI_SUCCESS)
  1284. return status;
  1285. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1286. /* Re-enter the configuring state since this may be the last phy in
  1287. * the port
  1288. */
  1289. port_state_machine_change(sci_port,
  1290. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1291. return SCI_SUCCESS;
  1292. default:
  1293. dev_warn(sciport_to_dev(sci_port),
  1294. "%s: in wrong state: %d\n", __func__, state);
  1295. return SCI_FAILURE_INVALID_STATE;
  1296. }
  1297. }
  1298. enum sci_status scic_sds_port_link_up(struct scic_sds_port *sci_port,
  1299. struct scic_sds_phy *sci_phy)
  1300. {
  1301. enum scic_sds_port_states state;
  1302. state = sci_port->state_machine.current_state_id;
  1303. switch (state) {
  1304. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1305. /* Since this is the first phy going link up for the port we
  1306. * can just enable it and continue
  1307. */
  1308. scic_sds_port_activate_phy(sci_port, sci_phy, true);
  1309. port_state_machine_change(sci_port,
  1310. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1311. return SCI_SUCCESS;
  1312. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1313. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1314. return SCI_SUCCESS;
  1315. case SCI_BASE_PORT_STATE_RESETTING:
  1316. /* TODO We should make sure that the phy that has gone
  1317. * link up is the same one on which we sent the reset. It is
  1318. * possible that the phy on which we sent the reset is not the
  1319. * one that has gone link up and we want to make sure that
  1320. * phy being reset comes back. Consider the case where a
  1321. * reset is sent but before the hardware processes the reset it
  1322. * get a link up on the port because of a hot plug event.
  1323. * because of the reset request this phy will go link down
  1324. * almost immediately.
  1325. */
  1326. /* In the resetting state we don't notify the user regarding
  1327. * link up and link down notifications.
  1328. */
  1329. scic_sds_port_general_link_up_handler(sci_port, sci_phy, false);
  1330. return SCI_SUCCESS;
  1331. default:
  1332. dev_warn(sciport_to_dev(sci_port),
  1333. "%s: in wrong state: %d\n", __func__, state);
  1334. return SCI_FAILURE_INVALID_STATE;
  1335. }
  1336. }
  1337. enum sci_status scic_sds_port_link_down(struct scic_sds_port *sci_port,
  1338. struct scic_sds_phy *sci_phy)
  1339. {
  1340. enum scic_sds_port_states state;
  1341. state = sci_port->state_machine.current_state_id;
  1342. switch (state) {
  1343. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1344. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1345. /* If there are no active phys left in the port, then
  1346. * transition the port to the WAITING state until such time
  1347. * as a phy goes link up
  1348. */
  1349. if (sci_port->active_phy_mask == 0)
  1350. port_state_machine_change(sci_port,
  1351. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1352. return SCI_SUCCESS;
  1353. case SCI_BASE_PORT_STATE_RESETTING:
  1354. /* In the resetting state we don't notify the user regarding
  1355. * link up and link down notifications. */
  1356. scic_sds_port_deactivate_phy(sci_port, sci_phy, false);
  1357. return SCI_SUCCESS;
  1358. default:
  1359. dev_warn(sciport_to_dev(sci_port),
  1360. "%s: in wrong state: %d\n", __func__, state);
  1361. return SCI_FAILURE_INVALID_STATE;
  1362. }
  1363. }
  1364. enum sci_status scic_sds_port_start_io(struct scic_sds_port *sci_port,
  1365. struct scic_sds_remote_device *sci_dev,
  1366. struct scic_sds_request *sci_req)
  1367. {
  1368. enum scic_sds_port_states state;
  1369. state = sci_port->state_machine.current_state_id;
  1370. switch (state) {
  1371. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1372. return SCI_FAILURE_INVALID_STATE;
  1373. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1374. sci_port->started_request_count++;
  1375. return SCI_SUCCESS;
  1376. default:
  1377. dev_warn(sciport_to_dev(sci_port),
  1378. "%s: in wrong state: %d\n", __func__, state);
  1379. return SCI_FAILURE_INVALID_STATE;
  1380. }
  1381. }
  1382. enum sci_status scic_sds_port_complete_io(struct scic_sds_port *sci_port,
  1383. struct scic_sds_remote_device *sci_dev,
  1384. struct scic_sds_request *sci_req)
  1385. {
  1386. enum scic_sds_port_states state;
  1387. state = sci_port->state_machine.current_state_id;
  1388. switch (state) {
  1389. case SCI_BASE_PORT_STATE_STOPPED:
  1390. dev_warn(sciport_to_dev(sci_port),
  1391. "%s: in wrong state: %d\n", __func__, state);
  1392. return SCI_FAILURE_INVALID_STATE;
  1393. case SCI_BASE_PORT_STATE_STOPPING:
  1394. scic_sds_port_decrement_request_count(sci_port);
  1395. if (sci_port->started_request_count == 0)
  1396. port_state_machine_change(sci_port,
  1397. SCI_BASE_PORT_STATE_STOPPED);
  1398. break;
  1399. case SCI_BASE_PORT_STATE_READY:
  1400. case SCI_BASE_PORT_STATE_RESETTING:
  1401. case SCI_BASE_PORT_STATE_FAILED:
  1402. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1403. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1404. scic_sds_port_decrement_request_count(sci_port);
  1405. break;
  1406. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1407. scic_sds_port_decrement_request_count(sci_port);
  1408. if (sci_port->started_request_count == 0) {
  1409. port_state_machine_change(sci_port,
  1410. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1411. }
  1412. break;
  1413. }
  1414. return SCI_SUCCESS;
  1415. }
  1416. /**
  1417. *
  1418. * @sci_port: This is the port object which to suspend.
  1419. *
  1420. * This method will enable the SCU Port Task Scheduler for this port object but
  1421. * will leave the port task scheduler in a suspended state. none
  1422. */
  1423. static void
  1424. scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
  1425. {
  1426. u32 pts_control_value;
  1427. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1428. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1429. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1430. }
  1431. /**
  1432. *
  1433. * @sci_port: This is the port object which to resume.
  1434. *
  1435. * This method will disable the SCU port task scheduler for this port object.
  1436. * none
  1437. */
  1438. static void
  1439. scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
  1440. {
  1441. u32 pts_control_value;
  1442. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1443. pts_control_value &=
  1444. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1445. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1446. }
  1447. static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
  1448. {
  1449. struct scic_sds_controller *scic = sci_port->owning_controller;
  1450. u8 phys_index = sci_port->physical_port_index;
  1451. union scu_remote_node_context *rnc;
  1452. u16 rni = sci_port->reserved_rni;
  1453. u32 command;
  1454. rnc = &scic->remote_node_context_table[rni];
  1455. rnc->ssp.is_valid = true;
  1456. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1457. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1458. scic_sds_controller_post_request(scic, command);
  1459. /* ensure hardware has seen the post rnc command and give it
  1460. * ample time to act before sending the suspend
  1461. */
  1462. readl(&scic->smu_registers->interrupt_status); /* flush */
  1463. udelay(10);
  1464. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1465. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1466. scic_sds_controller_post_request(scic, command);
  1467. }
  1468. static void scic_sds_port_stopped_state_enter(struct sci_base_state_machine *sm)
  1469. {
  1470. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1471. if (sci_port->state_machine.previous_state_id == SCI_BASE_PORT_STATE_STOPPING) {
  1472. /*
  1473. * If we enter this state becasuse of a request to stop
  1474. * the port then we want to disable the hardwares port
  1475. * task scheduler. */
  1476. scic_sds_port_disable_port_task_scheduler(sci_port);
  1477. }
  1478. }
  1479. static void scic_sds_port_stopped_state_exit(struct sci_base_state_machine *sm)
  1480. {
  1481. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1482. /* Enable and suspend the port task scheduler */
  1483. scic_sds_port_enable_port_task_scheduler(sci_port);
  1484. }
  1485. static void scic_sds_port_ready_state_enter(struct sci_base_state_machine *sm)
  1486. {
  1487. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1488. struct scic_sds_controller *scic = sci_port->owning_controller;
  1489. struct isci_host *ihost = scic_to_ihost(scic);
  1490. struct isci_port *iport = sci_port_to_iport(sci_port);
  1491. u32 prev_state;
  1492. prev_state = sci_port->state_machine.previous_state_id;
  1493. if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
  1494. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  1495. else
  1496. isci_port_not_ready(ihost, iport);
  1497. /* Post and suspend the dummy remote node context for this port. */
  1498. scic_sds_port_post_dummy_remote_node(sci_port);
  1499. /* Start the ready substate machine */
  1500. port_state_machine_change(sci_port,
  1501. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1502. }
  1503. static void scic_sds_port_resetting_state_exit(struct sci_base_state_machine *sm)
  1504. {
  1505. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1506. sci_del_timer(&sci_port->timer);
  1507. }
  1508. static void scic_sds_port_stopping_state_exit(struct sci_base_state_machine *sm)
  1509. {
  1510. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1511. sci_del_timer(&sci_port->timer);
  1512. scic_sds_port_destroy_dummy_resources(sci_port);
  1513. }
  1514. static void scic_sds_port_failed_state_enter(struct sci_base_state_machine *sm)
  1515. {
  1516. struct scic_sds_port *sci_port = container_of(sm, typeof(*sci_port), state_machine);
  1517. struct isci_port *iport = sci_port_to_iport(sci_port);
  1518. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  1519. }
  1520. /* --------------------------------------------------------------------------- */
  1521. static const struct sci_base_state scic_sds_port_state_table[] = {
  1522. [SCI_BASE_PORT_STATE_STOPPED] = {
  1523. .enter_state = scic_sds_port_stopped_state_enter,
  1524. .exit_state = scic_sds_port_stopped_state_exit
  1525. },
  1526. [SCI_BASE_PORT_STATE_STOPPING] = {
  1527. .exit_state = scic_sds_port_stopping_state_exit
  1528. },
  1529. [SCI_BASE_PORT_STATE_READY] = {
  1530. .enter_state = scic_sds_port_ready_state_enter,
  1531. },
  1532. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1533. .enter_state = scic_sds_port_ready_substate_waiting_enter,
  1534. },
  1535. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1536. .enter_state = scic_sds_port_ready_substate_operational_enter,
  1537. .exit_state = scic_sds_port_ready_substate_operational_exit
  1538. },
  1539. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1540. .enter_state = scic_sds_port_ready_substate_configuring_enter,
  1541. .exit_state = scic_sds_port_ready_substate_configuring_exit
  1542. },
  1543. [SCI_BASE_PORT_STATE_RESETTING] = {
  1544. .exit_state = scic_sds_port_resetting_state_exit
  1545. },
  1546. [SCI_BASE_PORT_STATE_FAILED] = {
  1547. .enter_state = scic_sds_port_failed_state_enter,
  1548. }
  1549. };
  1550. void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
  1551. struct scic_sds_controller *scic)
  1552. {
  1553. sci_base_state_machine_construct(&sci_port->state_machine,
  1554. scic_sds_port_state_table,
  1555. SCI_BASE_PORT_STATE_STOPPED);
  1556. sci_base_state_machine_start(&sci_port->state_machine);
  1557. sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
  1558. sci_port->physical_port_index = index;
  1559. sci_port->active_phy_mask = 0;
  1560. sci_port->ready_exit = false;
  1561. sci_port->owning_controller = scic;
  1562. sci_port->started_request_count = 0;
  1563. sci_port->assigned_device_count = 0;
  1564. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  1565. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  1566. sci_init_timer(&sci_port->timer, port_timeout);
  1567. sci_port->port_task_scheduler_registers = NULL;
  1568. for (index = 0; index < SCI_MAX_PHYS; index++)
  1569. sci_port->phy_table[index] = NULL;
  1570. }
  1571. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  1572. {
  1573. INIT_LIST_HEAD(&iport->remote_dev_list);
  1574. INIT_LIST_HEAD(&iport->domain_dev_list);
  1575. spin_lock_init(&iport->state_lock);
  1576. init_completion(&iport->start_complete);
  1577. iport->isci_host = ihost;
  1578. isci_port_change_state(iport, isci_freed);
  1579. }
  1580. /**
  1581. * isci_port_get_state() - This function gets the status of the port object.
  1582. * @isci_port: This parameter points to the isci_port object
  1583. *
  1584. * status of the object as a isci_status enum.
  1585. */
  1586. enum isci_status isci_port_get_state(
  1587. struct isci_port *isci_port)
  1588. {
  1589. return isci_port->status;
  1590. }
  1591. static void isci_port_bc_change_received(struct isci_host *ihost,
  1592. struct scic_sds_port *sci_port,
  1593. struct scic_sds_phy *sci_phy)
  1594. {
  1595. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  1596. dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
  1597. __func__, iphy, &iphy->sas_phy);
  1598. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  1599. scic_port_enable_broadcast_change_notification(sci_port);
  1600. }
  1601. void scic_sds_port_broadcast_change_received(
  1602. struct scic_sds_port *sci_port,
  1603. struct scic_sds_phy *sci_phy)
  1604. {
  1605. struct scic_sds_controller *scic = sci_port->owning_controller;
  1606. struct isci_host *ihost = scic_to_ihost(scic);
  1607. /* notify the user. */
  1608. isci_port_bc_change_received(ihost, sci_port, sci_phy);
  1609. }
  1610. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  1611. struct isci_phy *iphy)
  1612. {
  1613. unsigned long flags;
  1614. enum sci_status status;
  1615. int ret = TMF_RESP_FUNC_COMPLETE;
  1616. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  1617. __func__, iport);
  1618. init_completion(&iport->hard_reset_complete);
  1619. spin_lock_irqsave(&ihost->scic_lock, flags);
  1620. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  1621. status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
  1622. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1623. if (status == SCI_SUCCESS) {
  1624. wait_for_completion(&iport->hard_reset_complete);
  1625. dev_dbg(&ihost->pdev->dev,
  1626. "%s: iport = %p; hard reset completion\n",
  1627. __func__, iport);
  1628. if (iport->hard_reset_status != SCI_SUCCESS)
  1629. ret = TMF_RESP_FUNC_FAILED;
  1630. } else {
  1631. ret = TMF_RESP_FUNC_FAILED;
  1632. dev_err(&ihost->pdev->dev,
  1633. "%s: iport = %p; scic_port_hard_reset call"
  1634. " failed 0x%x\n",
  1635. __func__, iport, status);
  1636. }
  1637. /* If the hard reset for the port has failed, consider this
  1638. * the same as link failures on all phys in the port.
  1639. */
  1640. if (ret != TMF_RESP_FUNC_COMPLETE) {
  1641. dev_err(&ihost->pdev->dev,
  1642. "%s: iport = %p; hard reset failed "
  1643. "(0x%x) - sending link down to libsas for phy %p\n",
  1644. __func__, iport, iport->hard_reset_status, iphy);
  1645. isci_port_link_down(ihost, iphy, iport);
  1646. }
  1647. return ret;
  1648. }
  1649. /**
  1650. * isci_port_deformed() - This function is called by libsas when a port becomes
  1651. * inactive.
  1652. * @phy: This parameter specifies the libsas phy with the inactive port.
  1653. *
  1654. */
  1655. void isci_port_deformed(struct asd_sas_phy *phy)
  1656. {
  1657. pr_debug("%s: sas_phy = %p\n", __func__, phy);
  1658. }
  1659. /**
  1660. * isci_port_formed() - This function is called by libsas when a port becomes
  1661. * active.
  1662. * @phy: This parameter specifies the libsas phy with the active port.
  1663. *
  1664. */
  1665. void isci_port_formed(struct asd_sas_phy *phy)
  1666. {
  1667. pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
  1668. }