port.c 57 KB

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