zfcp_erp.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. /*
  2. * zfcp device driver
  3. *
  4. * Error Recovery Procedures (ERP).
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include "zfcp_ext.h"
  11. #define ZFCP_MAX_ERPS 3
  12. enum zfcp_erp_act_flags {
  13. ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
  14. ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
  15. ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
  16. ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
  17. ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
  18. };
  19. enum zfcp_erp_steps {
  20. ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
  21. ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
  22. ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
  23. ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
  24. ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
  25. ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
  26. ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
  27. ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
  28. };
  29. enum zfcp_erp_act_type {
  30. ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
  31. ZFCP_ERP_ACTION_REOPEN_PORT = 2,
  32. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
  33. ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
  34. };
  35. enum zfcp_erp_act_state {
  36. ZFCP_ERP_ACTION_RUNNING = 1,
  37. ZFCP_ERP_ACTION_READY = 2,
  38. };
  39. enum zfcp_erp_act_result {
  40. ZFCP_ERP_SUCCEEDED = 0,
  41. ZFCP_ERP_FAILED = 1,
  42. ZFCP_ERP_CONTINUES = 2,
  43. ZFCP_ERP_EXIT = 3,
  44. ZFCP_ERP_DISMISSED = 4,
  45. ZFCP_ERP_NOMEM = 5,
  46. };
  47. static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
  48. {
  49. zfcp_erp_modify_adapter_status(adapter, "erablk1", NULL,
  50. ZFCP_STATUS_COMMON_UNBLOCKED | mask,
  51. ZFCP_CLEAR);
  52. }
  53. static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
  54. {
  55. struct zfcp_erp_action *curr_act;
  56. list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
  57. if (act == curr_act)
  58. return ZFCP_ERP_ACTION_RUNNING;
  59. return 0;
  60. }
  61. static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
  62. {
  63. struct zfcp_adapter *adapter = act->adapter;
  64. list_move(&act->list, &act->adapter->erp_ready_head);
  65. zfcp_rec_dbf_event_action("erardy1", act);
  66. up(&adapter->erp_ready_sem);
  67. zfcp_rec_dbf_event_thread("erardy2", adapter);
  68. }
  69. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
  70. {
  71. act->status |= ZFCP_STATUS_ERP_DISMISSED;
  72. if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
  73. zfcp_erp_action_ready(act);
  74. }
  75. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  76. {
  77. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  78. zfcp_erp_action_dismiss(&unit->erp_action);
  79. }
  80. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  81. {
  82. struct zfcp_unit *unit;
  83. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  84. zfcp_erp_action_dismiss(&port->erp_action);
  85. else
  86. list_for_each_entry(unit, &port->unit_list_head, list)
  87. zfcp_erp_action_dismiss_unit(unit);
  88. }
  89. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  90. {
  91. struct zfcp_port *port;
  92. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
  93. zfcp_erp_action_dismiss(&adapter->erp_action);
  94. else
  95. list_for_each_entry(port, &adapter->port_list_head, list)
  96. zfcp_erp_action_dismiss_port(port);
  97. }
  98. static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
  99. struct zfcp_port *port,
  100. struct zfcp_unit *unit)
  101. {
  102. int need = want;
  103. int u_status, p_status, a_status;
  104. switch (want) {
  105. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  106. u_status = atomic_read(&unit->status);
  107. if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  108. return 0;
  109. p_status = atomic_read(&port->status);
  110. if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
  111. p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  112. return 0;
  113. if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  114. need = ZFCP_ERP_ACTION_REOPEN_PORT;
  115. /* fall through */
  116. case ZFCP_ERP_ACTION_REOPEN_PORT:
  117. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  118. p_status = atomic_read(&port->status);
  119. if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  120. return 0;
  121. a_status = atomic_read(&adapter->status);
  122. if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
  123. a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
  124. return 0;
  125. if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
  126. need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  127. /* fall through */
  128. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  129. a_status = atomic_read(&adapter->status);
  130. if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
  131. return 0;
  132. }
  133. return need;
  134. }
  135. static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
  136. struct zfcp_adapter *adapter,
  137. struct zfcp_port *port,
  138. struct zfcp_unit *unit)
  139. {
  140. struct zfcp_erp_action *erp_action;
  141. u32 status = 0;
  142. switch (need) {
  143. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  144. zfcp_unit_get(unit);
  145. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  146. erp_action = &unit->erp_action;
  147. if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
  148. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  149. break;
  150. case ZFCP_ERP_ACTION_REOPEN_PORT:
  151. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  152. zfcp_port_get(port);
  153. zfcp_erp_action_dismiss_port(port);
  154. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  155. erp_action = &port->erp_action;
  156. if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
  157. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  158. break;
  159. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  160. zfcp_adapter_get(adapter);
  161. zfcp_erp_action_dismiss_adapter(adapter);
  162. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  163. erp_action = &adapter->erp_action;
  164. if (!(atomic_read(&adapter->status) &
  165. ZFCP_STATUS_COMMON_RUNNING))
  166. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  167. break;
  168. default:
  169. return NULL;
  170. }
  171. memset(erp_action, 0, sizeof(struct zfcp_erp_action));
  172. erp_action->adapter = adapter;
  173. erp_action->port = port;
  174. erp_action->unit = unit;
  175. erp_action->action = need;
  176. erp_action->status = status;
  177. return erp_action;
  178. }
  179. static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
  180. struct zfcp_port *port,
  181. struct zfcp_unit *unit, char *id, void *ref)
  182. {
  183. int retval = 1, need;
  184. struct zfcp_erp_action *act = NULL;
  185. if (!(atomic_read(&adapter->status) &
  186. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
  187. return -EIO;
  188. need = zfcp_erp_required_act(want, adapter, port, unit);
  189. if (!need)
  190. goto out;
  191. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  192. act = zfcp_erp_setup_act(need, adapter, port, unit);
  193. if (!act)
  194. goto out;
  195. ++adapter->erp_total_count;
  196. list_add_tail(&act->list, &adapter->erp_ready_head);
  197. up(&adapter->erp_ready_sem);
  198. zfcp_rec_dbf_event_thread("eracte1", adapter);
  199. retval = 0;
  200. out:
  201. zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
  202. adapter, port, unit);
  203. return retval;
  204. }
  205. static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
  206. int clear_mask, char *id, void *ref)
  207. {
  208. zfcp_erp_adapter_block(adapter, clear_mask);
  209. zfcp_scsi_schedule_rports_block(adapter);
  210. /* ensure propagation of failed status to new devices */
  211. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  212. zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
  213. return -EIO;
  214. }
  215. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  216. adapter, NULL, NULL, id, ref);
  217. }
  218. /**
  219. * zfcp_erp_adapter_reopen - Reopen adapter.
  220. * @adapter: Adapter to reopen.
  221. * @clear: Status flags to clear.
  222. * @id: Id for debug trace event.
  223. * @ref: Reference for debug trace event.
  224. */
  225. void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
  226. char *id, void *ref)
  227. {
  228. unsigned long flags;
  229. read_lock_irqsave(&zfcp_data.config_lock, flags);
  230. write_lock(&adapter->erp_lock);
  231. _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
  232. write_unlock(&adapter->erp_lock);
  233. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  234. }
  235. /**
  236. * zfcp_erp_adapter_shutdown - Shutdown adapter.
  237. * @adapter: Adapter to shut down.
  238. * @clear: Status flags to clear.
  239. * @id: Id for debug trace event.
  240. * @ref: Reference for debug trace event.
  241. */
  242. void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
  243. char *id, void *ref)
  244. {
  245. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  246. zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
  247. }
  248. /**
  249. * zfcp_erp_port_shutdown - Shutdown port
  250. * @port: Port to shut down.
  251. * @clear: Status flags to clear.
  252. * @id: Id for debug trace event.
  253. * @ref: Reference for debug trace event.
  254. */
  255. void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
  256. void *ref)
  257. {
  258. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  259. zfcp_erp_port_reopen(port, clear | flags, id, ref);
  260. }
  261. /**
  262. * zfcp_erp_unit_shutdown - Shutdown unit
  263. * @unit: Unit to shut down.
  264. * @clear: Status flags to clear.
  265. * @id: Id for debug trace event.
  266. * @ref: Reference for debug trace event.
  267. */
  268. void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
  269. void *ref)
  270. {
  271. int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
  272. zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
  273. }
  274. static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
  275. {
  276. zfcp_erp_modify_port_status(port, "erpblk1", NULL,
  277. ZFCP_STATUS_COMMON_UNBLOCKED | clear,
  278. ZFCP_CLEAR);
  279. }
  280. static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
  281. int clear, char *id, void *ref)
  282. {
  283. zfcp_erp_port_block(port, clear);
  284. zfcp_scsi_schedule_rport_block(port);
  285. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  286. return;
  287. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  288. port->adapter, port, NULL, id, ref);
  289. }
  290. /**
  291. * zfcp_erp_port_forced_reopen - Forced close of port and open again
  292. * @port: Port to force close and to reopen.
  293. * @id: Id for debug trace event.
  294. * @ref: Reference for debug trace event.
  295. */
  296. void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
  297. void *ref)
  298. {
  299. unsigned long flags;
  300. struct zfcp_adapter *adapter = port->adapter;
  301. read_lock_irqsave(&zfcp_data.config_lock, flags);
  302. write_lock(&adapter->erp_lock);
  303. _zfcp_erp_port_forced_reopen(port, clear, id, ref);
  304. write_unlock(&adapter->erp_lock);
  305. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  306. }
  307. static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
  308. void *ref)
  309. {
  310. zfcp_erp_port_block(port, clear);
  311. zfcp_scsi_schedule_rport_block(port);
  312. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  313. /* ensure propagation of failed status to new devices */
  314. zfcp_erp_port_failed(port, "erpreo1", NULL);
  315. return -EIO;
  316. }
  317. return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  318. port->adapter, port, NULL, id, ref);
  319. }
  320. /**
  321. * zfcp_erp_port_reopen - trigger remote port recovery
  322. * @port: port to recover
  323. * @clear_mask: flags in port status to be cleared
  324. *
  325. * Returns 0 if recovery has been triggered, < 0 if not.
  326. */
  327. int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
  328. {
  329. unsigned long flags;
  330. int retval;
  331. struct zfcp_adapter *adapter = port->adapter;
  332. read_lock_irqsave(&zfcp_data.config_lock, flags);
  333. write_lock(&adapter->erp_lock);
  334. retval = _zfcp_erp_port_reopen(port, clear, id, ref);
  335. write_unlock(&adapter->erp_lock);
  336. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  337. return retval;
  338. }
  339. static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  340. {
  341. zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
  342. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  343. ZFCP_CLEAR);
  344. }
  345. static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
  346. void *ref)
  347. {
  348. struct zfcp_adapter *adapter = unit->port->adapter;
  349. zfcp_erp_unit_block(unit, clear);
  350. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
  351. return;
  352. zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  353. adapter, unit->port, unit, id, ref);
  354. }
  355. /**
  356. * zfcp_erp_unit_reopen - initiate reopen of a unit
  357. * @unit: unit to be reopened
  358. * @clear_mask: specifies flags in unit status to be cleared
  359. * Return: 0 on success, < 0 on error
  360. */
  361. void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
  362. void *ref)
  363. {
  364. unsigned long flags;
  365. struct zfcp_port *port = unit->port;
  366. struct zfcp_adapter *adapter = port->adapter;
  367. read_lock_irqsave(&zfcp_data.config_lock, flags);
  368. write_lock(&adapter->erp_lock);
  369. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  370. write_unlock(&adapter->erp_lock);
  371. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  372. }
  373. static int status_change_set(unsigned long mask, atomic_t *status)
  374. {
  375. return (atomic_read(status) ^ mask) & mask;
  376. }
  377. static int status_change_clear(unsigned long mask, atomic_t *status)
  378. {
  379. return atomic_read(status) & mask;
  380. }
  381. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  382. {
  383. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
  384. zfcp_rec_dbf_event_adapter("eraubl1", NULL, adapter);
  385. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  386. }
  387. static void zfcp_erp_port_unblock(struct zfcp_port *port)
  388. {
  389. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
  390. zfcp_rec_dbf_event_port("erpubl1", NULL, port);
  391. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  392. }
  393. static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  394. {
  395. if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
  396. zfcp_rec_dbf_event_unit("eruubl1", NULL, unit);
  397. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  398. }
  399. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  400. {
  401. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  402. zfcp_rec_dbf_event_action("erator1", erp_action);
  403. }
  404. static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
  405. {
  406. struct zfcp_adapter *adapter = act->adapter;
  407. if (!act->fsf_req)
  408. return;
  409. spin_lock(&adapter->req_list_lock);
  410. if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
  411. act->fsf_req->erp_action == act) {
  412. if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
  413. ZFCP_STATUS_ERP_TIMEDOUT)) {
  414. act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  415. zfcp_rec_dbf_event_action("erscf_1", act);
  416. act->fsf_req->erp_action = NULL;
  417. }
  418. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  419. zfcp_rec_dbf_event_action("erscf_2", act);
  420. if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  421. ZFCP_STATUS_FSFREQ_DISMISSED))
  422. act->fsf_req = NULL;
  423. } else
  424. act->fsf_req = NULL;
  425. spin_unlock(&adapter->req_list_lock);
  426. }
  427. /**
  428. * zfcp_erp_notify - Trigger ERP action.
  429. * @erp_action: ERP action to continue.
  430. * @set_mask: ERP action status flags to set.
  431. */
  432. void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
  433. {
  434. struct zfcp_adapter *adapter = erp_action->adapter;
  435. unsigned long flags;
  436. write_lock_irqsave(&adapter->erp_lock, flags);
  437. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  438. erp_action->status |= set_mask;
  439. zfcp_erp_action_ready(erp_action);
  440. }
  441. write_unlock_irqrestore(&adapter->erp_lock, flags);
  442. }
  443. /**
  444. * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
  445. * @data: ERP action (from timer data)
  446. */
  447. void zfcp_erp_timeout_handler(unsigned long data)
  448. {
  449. struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
  450. zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
  451. }
  452. static void zfcp_erp_memwait_handler(unsigned long data)
  453. {
  454. zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
  455. }
  456. static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  457. {
  458. init_timer(&erp_action->timer);
  459. erp_action->timer.function = zfcp_erp_memwait_handler;
  460. erp_action->timer.data = (unsigned long) erp_action;
  461. erp_action->timer.expires = jiffies + HZ;
  462. add_timer(&erp_action->timer);
  463. }
  464. static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
  465. int clear, char *id, void *ref)
  466. {
  467. struct zfcp_port *port;
  468. list_for_each_entry(port, &adapter->port_list_head, list)
  469. _zfcp_erp_port_reopen(port, clear, id, ref);
  470. }
  471. static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
  472. char *id, void *ref)
  473. {
  474. struct zfcp_unit *unit;
  475. list_for_each_entry(unit, &port->unit_list_head, list)
  476. _zfcp_erp_unit_reopen(unit, clear, id, ref);
  477. }
  478. static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
  479. {
  480. struct zfcp_adapter *adapter = act->adapter;
  481. struct zfcp_port *port = act->port;
  482. struct zfcp_unit *unit = act->unit;
  483. u32 status = act->status;
  484. /* initiate follow-up actions depending on success of finished action */
  485. switch (act->action) {
  486. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  487. if (status == ZFCP_ERP_SUCCEEDED)
  488. _zfcp_erp_port_reopen_all(adapter, 0, "ersfa_1", NULL);
  489. else
  490. _zfcp_erp_adapter_reopen(adapter, 0, "ersfa_2", NULL);
  491. break;
  492. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  493. if (status == ZFCP_ERP_SUCCEEDED)
  494. _zfcp_erp_port_reopen(port, 0, "ersfa_3", NULL);
  495. else
  496. _zfcp_erp_adapter_reopen(adapter, 0, "ersfa_4", NULL);
  497. break;
  498. case ZFCP_ERP_ACTION_REOPEN_PORT:
  499. if (status == ZFCP_ERP_SUCCEEDED)
  500. _zfcp_erp_unit_reopen_all(port, 0, "ersfa_5", NULL);
  501. else
  502. _zfcp_erp_port_forced_reopen(port, 0, "ersfa_6", NULL);
  503. break;
  504. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  505. if (status != ZFCP_ERP_SUCCEEDED)
  506. _zfcp_erp_port_reopen(unit->port, 0, "ersfa_7", NULL);
  507. break;
  508. }
  509. }
  510. static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
  511. {
  512. unsigned long flags;
  513. read_lock_irqsave(&zfcp_data.config_lock, flags);
  514. read_lock(&adapter->erp_lock);
  515. if (list_empty(&adapter->erp_ready_head) &&
  516. list_empty(&adapter->erp_running_head)) {
  517. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  518. &adapter->status);
  519. wake_up(&adapter->erp_done_wqh);
  520. }
  521. read_unlock(&adapter->erp_lock);
  522. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  523. }
  524. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
  525. {
  526. if (zfcp_qdio_open(act->adapter))
  527. return ZFCP_ERP_FAILED;
  528. init_waitqueue_head(&act->adapter->request_wq);
  529. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
  530. return ZFCP_ERP_SUCCEEDED;
  531. }
  532. static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
  533. {
  534. struct zfcp_port *port;
  535. port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
  536. adapter->peer_d_id);
  537. if (IS_ERR(port)) /* error or port already attached */
  538. return;
  539. _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
  540. }
  541. static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
  542. {
  543. int retries;
  544. int sleep = 1;
  545. struct zfcp_adapter *adapter = erp_action->adapter;
  546. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  547. for (retries = 7; retries; retries--) {
  548. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  549. &adapter->status);
  550. write_lock_irq(&adapter->erp_lock);
  551. zfcp_erp_action_to_running(erp_action);
  552. write_unlock_irq(&adapter->erp_lock);
  553. if (zfcp_fsf_exchange_config_data(erp_action)) {
  554. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  555. &adapter->status);
  556. return ZFCP_ERP_FAILED;
  557. }
  558. zfcp_rec_dbf_event_thread_lock("erasfx1", adapter);
  559. down(&adapter->erp_ready_sem);
  560. zfcp_rec_dbf_event_thread_lock("erasfx2", adapter);
  561. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
  562. break;
  563. if (!(atomic_read(&adapter->status) &
  564. ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
  565. break;
  566. ssleep(sleep);
  567. sleep *= 2;
  568. }
  569. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  570. &adapter->status);
  571. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
  572. return ZFCP_ERP_FAILED;
  573. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  574. zfcp_erp_enqueue_ptp_port(adapter);
  575. return ZFCP_ERP_SUCCEEDED;
  576. }
  577. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
  578. {
  579. int ret;
  580. struct zfcp_adapter *adapter = act->adapter;
  581. write_lock_irq(&adapter->erp_lock);
  582. zfcp_erp_action_to_running(act);
  583. write_unlock_irq(&adapter->erp_lock);
  584. ret = zfcp_fsf_exchange_port_data(act);
  585. if (ret == -EOPNOTSUPP)
  586. return ZFCP_ERP_SUCCEEDED;
  587. if (ret)
  588. return ZFCP_ERP_FAILED;
  589. zfcp_rec_dbf_event_thread_lock("erasox1", adapter);
  590. down(&adapter->erp_ready_sem);
  591. zfcp_rec_dbf_event_thread_lock("erasox2", adapter);
  592. if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
  593. return ZFCP_ERP_FAILED;
  594. return ZFCP_ERP_SUCCEEDED;
  595. }
  596. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
  597. {
  598. if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
  599. return ZFCP_ERP_FAILED;
  600. if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
  601. return ZFCP_ERP_FAILED;
  602. atomic_set(&act->adapter->stat_miss, 16);
  603. if (zfcp_status_read_refill(act->adapter))
  604. return ZFCP_ERP_FAILED;
  605. return ZFCP_ERP_SUCCEEDED;
  606. }
  607. static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
  608. {
  609. struct zfcp_adapter *adapter = act->adapter;
  610. /* close queues to ensure that buffers are not accessed by adapter */
  611. zfcp_qdio_close(adapter);
  612. zfcp_fsf_req_dismiss_all(adapter);
  613. adapter->fsf_req_seq_no = 0;
  614. /* all ports and units are closed */
  615. zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
  616. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  617. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  618. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  619. }
  620. static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
  621. {
  622. struct zfcp_adapter *adapter = act->adapter;
  623. if (zfcp_erp_adapter_strategy_open_qdio(act)) {
  624. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  625. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  626. &adapter->status);
  627. return ZFCP_ERP_FAILED;
  628. }
  629. if (zfcp_erp_adapter_strategy_open_fsf(act)) {
  630. zfcp_erp_adapter_strategy_close(act);
  631. return ZFCP_ERP_FAILED;
  632. }
  633. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
  634. return ZFCP_ERP_SUCCEEDED;
  635. }
  636. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
  637. {
  638. struct zfcp_adapter *adapter = act->adapter;
  639. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
  640. zfcp_erp_adapter_strategy_close(act);
  641. if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  642. return ZFCP_ERP_EXIT;
  643. }
  644. if (zfcp_erp_adapter_strategy_open(act)) {
  645. ssleep(8);
  646. return ZFCP_ERP_FAILED;
  647. }
  648. return ZFCP_ERP_SUCCEEDED;
  649. }
  650. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
  651. {
  652. int retval;
  653. retval = zfcp_fsf_close_physical_port(act);
  654. if (retval == -ENOMEM)
  655. return ZFCP_ERP_NOMEM;
  656. act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  657. if (retval)
  658. return ZFCP_ERP_FAILED;
  659. return ZFCP_ERP_CONTINUES;
  660. }
  661. static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  662. {
  663. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
  664. }
  665. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  666. {
  667. struct zfcp_port *port = erp_action->port;
  668. int status = atomic_read(&port->status);
  669. switch (erp_action->step) {
  670. case ZFCP_ERP_STEP_UNINITIALIZED:
  671. zfcp_erp_port_strategy_clearstati(port);
  672. if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
  673. (status & ZFCP_STATUS_COMMON_OPEN))
  674. return zfcp_erp_port_forced_strategy_close(erp_action);
  675. else
  676. return ZFCP_ERP_FAILED;
  677. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  678. if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
  679. return ZFCP_ERP_SUCCEEDED;
  680. }
  681. return ZFCP_ERP_FAILED;
  682. }
  683. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  684. {
  685. int retval;
  686. retval = zfcp_fsf_close_port(erp_action);
  687. if (retval == -ENOMEM)
  688. return ZFCP_ERP_NOMEM;
  689. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  690. if (retval)
  691. return ZFCP_ERP_FAILED;
  692. return ZFCP_ERP_CONTINUES;
  693. }
  694. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  695. {
  696. int retval;
  697. retval = zfcp_fsf_open_port(erp_action);
  698. if (retval == -ENOMEM)
  699. return ZFCP_ERP_NOMEM;
  700. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  701. if (retval)
  702. return ZFCP_ERP_FAILED;
  703. return ZFCP_ERP_CONTINUES;
  704. }
  705. static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
  706. {
  707. struct zfcp_adapter *adapter = act->adapter;
  708. struct zfcp_port *port = act->port;
  709. if (port->wwpn != adapter->peer_wwpn) {
  710. zfcp_erp_port_failed(port, "eroptp1", NULL);
  711. return ZFCP_ERP_FAILED;
  712. }
  713. port->d_id = adapter->peer_d_id;
  714. return zfcp_erp_port_strategy_open_port(act);
  715. }
  716. void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
  717. {
  718. int retval;
  719. struct zfcp_port *port = container_of(work, struct zfcp_port,
  720. gid_pn_work);
  721. retval = zfcp_fc_ns_gid_pn(&port->erp_action);
  722. if (retval == -ENOMEM)
  723. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
  724. port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  725. if (retval)
  726. zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
  727. zfcp_port_put(port);
  728. }
  729. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  730. {
  731. struct zfcp_adapter *adapter = act->adapter;
  732. struct zfcp_port *port = act->port;
  733. int p_status = atomic_read(&port->status);
  734. switch (act->step) {
  735. case ZFCP_ERP_STEP_UNINITIALIZED:
  736. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  737. case ZFCP_ERP_STEP_PORT_CLOSING:
  738. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  739. return zfcp_erp_open_ptp_port(act);
  740. if (!port->d_id) {
  741. zfcp_port_get(port);
  742. if (!queue_work(zfcp_data.work_queue,
  743. &port->gid_pn_work))
  744. zfcp_port_put(port);
  745. return ZFCP_ERP_CONTINUES;
  746. }
  747. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  748. if (!port->d_id)
  749. return ZFCP_ERP_FAILED;
  750. return zfcp_erp_port_strategy_open_port(act);
  751. case ZFCP_ERP_STEP_PORT_OPENING:
  752. /* D_ID might have changed during open */
  753. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  754. if (port->d_id)
  755. return ZFCP_ERP_SUCCEEDED;
  756. else {
  757. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  758. return ZFCP_ERP_CONTINUES;
  759. }
  760. /* fall through otherwise */
  761. }
  762. }
  763. return ZFCP_ERP_FAILED;
  764. }
  765. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  766. {
  767. struct zfcp_port *port = erp_action->port;
  768. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  769. goto close_init_done;
  770. switch (erp_action->step) {
  771. case ZFCP_ERP_STEP_UNINITIALIZED:
  772. zfcp_erp_port_strategy_clearstati(port);
  773. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  774. return zfcp_erp_port_strategy_close(erp_action);
  775. break;
  776. case ZFCP_ERP_STEP_PORT_CLOSING:
  777. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  778. return ZFCP_ERP_FAILED;
  779. break;
  780. }
  781. close_init_done:
  782. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  783. return ZFCP_ERP_EXIT;
  784. return zfcp_erp_port_strategy_open_common(erp_action);
  785. }
  786. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  787. {
  788. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  789. ZFCP_STATUS_UNIT_SHARED |
  790. ZFCP_STATUS_UNIT_READONLY,
  791. &unit->status);
  792. }
  793. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  794. {
  795. int retval = zfcp_fsf_close_unit(erp_action);
  796. if (retval == -ENOMEM)
  797. return ZFCP_ERP_NOMEM;
  798. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  799. if (retval)
  800. return ZFCP_ERP_FAILED;
  801. return ZFCP_ERP_CONTINUES;
  802. }
  803. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  804. {
  805. int retval = zfcp_fsf_open_unit(erp_action);
  806. if (retval == -ENOMEM)
  807. return ZFCP_ERP_NOMEM;
  808. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  809. if (retval)
  810. return ZFCP_ERP_FAILED;
  811. return ZFCP_ERP_CONTINUES;
  812. }
  813. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  814. {
  815. struct zfcp_unit *unit = erp_action->unit;
  816. switch (erp_action->step) {
  817. case ZFCP_ERP_STEP_UNINITIALIZED:
  818. zfcp_erp_unit_strategy_clearstati(unit);
  819. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  820. return zfcp_erp_unit_strategy_close(erp_action);
  821. /* already closed, fall through */
  822. case ZFCP_ERP_STEP_UNIT_CLOSING:
  823. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  824. return ZFCP_ERP_FAILED;
  825. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  826. return ZFCP_ERP_EXIT;
  827. return zfcp_erp_unit_strategy_open(erp_action);
  828. case ZFCP_ERP_STEP_UNIT_OPENING:
  829. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  830. return ZFCP_ERP_SUCCEEDED;
  831. }
  832. return ZFCP_ERP_FAILED;
  833. }
  834. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  835. {
  836. switch (result) {
  837. case ZFCP_ERP_SUCCEEDED :
  838. atomic_set(&unit->erp_counter, 0);
  839. zfcp_erp_unit_unblock(unit);
  840. break;
  841. case ZFCP_ERP_FAILED :
  842. atomic_inc(&unit->erp_counter);
  843. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  844. dev_err(&unit->port->adapter->ccw_device->dev,
  845. "ERP failed for unit 0x%016Lx on "
  846. "port 0x%016Lx\n",
  847. (unsigned long long)unit->fcp_lun,
  848. (unsigned long long)unit->port->wwpn);
  849. zfcp_erp_unit_failed(unit, "erusck1", NULL);
  850. }
  851. break;
  852. }
  853. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  854. zfcp_erp_unit_block(unit, 0);
  855. result = ZFCP_ERP_EXIT;
  856. }
  857. return result;
  858. }
  859. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  860. {
  861. switch (result) {
  862. case ZFCP_ERP_SUCCEEDED :
  863. atomic_set(&port->erp_counter, 0);
  864. zfcp_erp_port_unblock(port);
  865. break;
  866. case ZFCP_ERP_FAILED :
  867. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  868. zfcp_erp_port_block(port, 0);
  869. result = ZFCP_ERP_EXIT;
  870. }
  871. atomic_inc(&port->erp_counter);
  872. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  873. dev_err(&port->adapter->ccw_device->dev,
  874. "ERP failed for remote port 0x%016Lx\n",
  875. (unsigned long long)port->wwpn);
  876. zfcp_erp_port_failed(port, "erpsck1", NULL);
  877. }
  878. break;
  879. }
  880. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  881. zfcp_erp_port_block(port, 0);
  882. result = ZFCP_ERP_EXIT;
  883. }
  884. return result;
  885. }
  886. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  887. int result)
  888. {
  889. switch (result) {
  890. case ZFCP_ERP_SUCCEEDED :
  891. atomic_set(&adapter->erp_counter, 0);
  892. zfcp_erp_adapter_unblock(adapter);
  893. break;
  894. case ZFCP_ERP_FAILED :
  895. atomic_inc(&adapter->erp_counter);
  896. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  897. dev_err(&adapter->ccw_device->dev,
  898. "ERP cannot recover an error "
  899. "on the FCP device\n");
  900. zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
  901. }
  902. break;
  903. }
  904. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  905. zfcp_erp_adapter_block(adapter, 0);
  906. result = ZFCP_ERP_EXIT;
  907. }
  908. return result;
  909. }
  910. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  911. int result)
  912. {
  913. struct zfcp_adapter *adapter = erp_action->adapter;
  914. struct zfcp_port *port = erp_action->port;
  915. struct zfcp_unit *unit = erp_action->unit;
  916. switch (erp_action->action) {
  917. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  918. result = zfcp_erp_strategy_check_unit(unit, result);
  919. break;
  920. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  921. case ZFCP_ERP_ACTION_REOPEN_PORT:
  922. result = zfcp_erp_strategy_check_port(port, result);
  923. break;
  924. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  925. result = zfcp_erp_strategy_check_adapter(adapter, result);
  926. break;
  927. }
  928. return result;
  929. }
  930. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  931. {
  932. int status = atomic_read(target_status);
  933. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  934. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  935. return 1; /* take it online */
  936. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  937. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  938. return 1; /* take it offline */
  939. return 0;
  940. }
  941. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  942. {
  943. int action = act->action;
  944. struct zfcp_adapter *adapter = act->adapter;
  945. struct zfcp_port *port = act->port;
  946. struct zfcp_unit *unit = act->unit;
  947. u32 erp_status = act->status;
  948. switch (action) {
  949. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  950. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  951. _zfcp_erp_adapter_reopen(adapter,
  952. ZFCP_STATUS_COMMON_ERP_FAILED,
  953. "ersscg1", NULL);
  954. return ZFCP_ERP_EXIT;
  955. }
  956. break;
  957. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  958. case ZFCP_ERP_ACTION_REOPEN_PORT:
  959. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  960. _zfcp_erp_port_reopen(port,
  961. ZFCP_STATUS_COMMON_ERP_FAILED,
  962. "ersscg2", NULL);
  963. return ZFCP_ERP_EXIT;
  964. }
  965. break;
  966. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  967. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  968. _zfcp_erp_unit_reopen(unit,
  969. ZFCP_STATUS_COMMON_ERP_FAILED,
  970. "ersscg3", NULL);
  971. return ZFCP_ERP_EXIT;
  972. }
  973. break;
  974. }
  975. return ret;
  976. }
  977. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  978. {
  979. struct zfcp_adapter *adapter = erp_action->adapter;
  980. adapter->erp_total_count--;
  981. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  982. adapter->erp_low_mem_count--;
  983. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  984. }
  985. list_del(&erp_action->list);
  986. zfcp_rec_dbf_event_action("eractd1", erp_action);
  987. switch (erp_action->action) {
  988. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  989. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  990. &erp_action->unit->status);
  991. break;
  992. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  993. case ZFCP_ERP_ACTION_REOPEN_PORT:
  994. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  995. &erp_action->port->status);
  996. break;
  997. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  998. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  999. &erp_action->adapter->status);
  1000. break;
  1001. }
  1002. }
  1003. struct zfcp_erp_add_work {
  1004. struct zfcp_unit *unit;
  1005. struct work_struct work;
  1006. };
  1007. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1008. {
  1009. struct zfcp_erp_add_work *p =
  1010. container_of(work, struct zfcp_erp_add_work, work);
  1011. struct zfcp_unit *unit = p->unit;
  1012. struct fc_rport *rport = unit->port->rport;
  1013. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  1014. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1015. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1016. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1017. zfcp_unit_put(unit);
  1018. wake_up(&unit->port->adapter->erp_done_wqh);
  1019. kfree(p);
  1020. }
  1021. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1022. {
  1023. struct zfcp_erp_add_work *p;
  1024. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1025. if (!p) {
  1026. dev_err(&unit->port->adapter->ccw_device->dev,
  1027. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1028. (unsigned long long)unit->fcp_lun,
  1029. (unsigned long long)unit->port->wwpn);
  1030. return;
  1031. }
  1032. zfcp_unit_get(unit);
  1033. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1034. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1035. p->unit = unit;
  1036. if (!queue_work(zfcp_data.work_queue, &p->work))
  1037. zfcp_unit_put(unit);
  1038. }
  1039. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1040. {
  1041. struct zfcp_adapter *adapter = act->adapter;
  1042. struct zfcp_port *port = act->port;
  1043. struct zfcp_unit *unit = act->unit;
  1044. switch (act->action) {
  1045. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1046. flush_work(&port->rport_work);
  1047. if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
  1048. if (!(atomic_read(&unit->status) &
  1049. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1050. zfcp_erp_schedule_work(unit);
  1051. }
  1052. zfcp_unit_put(unit);
  1053. break;
  1054. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1055. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1056. if (result == ZFCP_ERP_SUCCEEDED)
  1057. zfcp_scsi_schedule_rport_register(port);
  1058. zfcp_port_put(port);
  1059. break;
  1060. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1061. if (result == ZFCP_ERP_SUCCEEDED) {
  1062. register_service_level(&adapter->service_level);
  1063. schedule_work(&adapter->scan_work);
  1064. } else
  1065. unregister_service_level(&adapter->service_level);
  1066. zfcp_adapter_put(adapter);
  1067. break;
  1068. }
  1069. }
  1070. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1071. {
  1072. switch (erp_action->action) {
  1073. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1074. return zfcp_erp_adapter_strategy(erp_action);
  1075. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1076. return zfcp_erp_port_forced_strategy(erp_action);
  1077. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1078. return zfcp_erp_port_strategy(erp_action);
  1079. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1080. return zfcp_erp_unit_strategy(erp_action);
  1081. }
  1082. return ZFCP_ERP_FAILED;
  1083. }
  1084. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1085. {
  1086. int retval;
  1087. struct zfcp_adapter *adapter = erp_action->adapter;
  1088. unsigned long flags;
  1089. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1090. write_lock(&adapter->erp_lock);
  1091. zfcp_erp_strategy_check_fsfreq(erp_action);
  1092. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1093. zfcp_erp_action_dequeue(erp_action);
  1094. retval = ZFCP_ERP_DISMISSED;
  1095. goto unlock;
  1096. }
  1097. zfcp_erp_action_to_running(erp_action);
  1098. /* no lock to allow for blocking operations */
  1099. write_unlock(&adapter->erp_lock);
  1100. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1101. retval = zfcp_erp_strategy_do_action(erp_action);
  1102. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1103. write_lock(&adapter->erp_lock);
  1104. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1105. retval = ZFCP_ERP_CONTINUES;
  1106. switch (retval) {
  1107. case ZFCP_ERP_NOMEM:
  1108. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1109. ++adapter->erp_low_mem_count;
  1110. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1111. }
  1112. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1113. _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
  1114. else {
  1115. zfcp_erp_strategy_memwait(erp_action);
  1116. retval = ZFCP_ERP_CONTINUES;
  1117. }
  1118. goto unlock;
  1119. case ZFCP_ERP_CONTINUES:
  1120. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1121. --adapter->erp_low_mem_count;
  1122. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1123. }
  1124. goto unlock;
  1125. }
  1126. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1127. zfcp_erp_action_dequeue(erp_action);
  1128. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1129. if (retval == ZFCP_ERP_EXIT)
  1130. goto unlock;
  1131. zfcp_erp_strategy_followup_actions(erp_action);
  1132. unlock:
  1133. write_unlock(&adapter->erp_lock);
  1134. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1135. if (retval != ZFCP_ERP_CONTINUES)
  1136. zfcp_erp_action_cleanup(erp_action, retval);
  1137. return retval;
  1138. }
  1139. static int zfcp_erp_thread(void *data)
  1140. {
  1141. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1142. struct list_head *next;
  1143. struct zfcp_erp_action *act;
  1144. unsigned long flags;
  1145. int ignore;
  1146. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1147. /* Block all signals */
  1148. siginitsetinv(&current->blocked, 0);
  1149. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1150. wake_up(&adapter->erp_thread_wqh);
  1151. while (!(atomic_read(&adapter->status) &
  1152. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1153. write_lock_irqsave(&adapter->erp_lock, flags);
  1154. next = adapter->erp_ready_head.next;
  1155. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1156. if (next != &adapter->erp_ready_head) {
  1157. act = list_entry(next, struct zfcp_erp_action, list);
  1158. /* there is more to come after dismission, no notify */
  1159. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1160. zfcp_erp_wakeup(adapter);
  1161. }
  1162. zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
  1163. ignore = down_interruptible(&adapter->erp_ready_sem);
  1164. zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
  1165. }
  1166. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1167. wake_up(&adapter->erp_thread_wqh);
  1168. return 0;
  1169. }
  1170. /**
  1171. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1172. * @adapter: Adapter to start the ERP thread for
  1173. *
  1174. * Returns 0 on success or error code from kernel_thread()
  1175. */
  1176. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1177. {
  1178. int retval;
  1179. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1180. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1181. if (retval < 0) {
  1182. dev_err(&adapter->ccw_device->dev,
  1183. "Creating an ERP thread for the FCP device failed.\n");
  1184. return retval;
  1185. }
  1186. wait_event(adapter->erp_thread_wqh,
  1187. atomic_read(&adapter->status) &
  1188. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1189. return 0;
  1190. }
  1191. /**
  1192. * zfcp_erp_thread_kill - Stop ERP thread.
  1193. * @adapter: Adapter where the ERP thread should be stopped.
  1194. *
  1195. * The caller of this routine ensures that the specified adapter has
  1196. * been shut down and that this operation has been completed. Thus,
  1197. * there are no pending erp_actions which would need to be handled
  1198. * here.
  1199. */
  1200. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1201. {
  1202. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1203. up(&adapter->erp_ready_sem);
  1204. zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
  1205. wait_event(adapter->erp_thread_wqh,
  1206. !(atomic_read(&adapter->status) &
  1207. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1208. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1209. &adapter->status);
  1210. }
  1211. /**
  1212. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1213. * @adapter: Failed adapter.
  1214. * @id: Event id for debug trace.
  1215. * @ref: Reference for debug trace.
  1216. */
  1217. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
  1218. {
  1219. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1220. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1221. }
  1222. /**
  1223. * zfcp_erp_port_failed - Set port status to failed.
  1224. * @port: Failed port.
  1225. * @id: Event id for debug trace.
  1226. * @ref: Reference for debug trace.
  1227. */
  1228. void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
  1229. {
  1230. zfcp_erp_modify_port_status(port, id, ref,
  1231. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1232. }
  1233. /**
  1234. * zfcp_erp_unit_failed - Set unit status to failed.
  1235. * @unit: Failed unit.
  1236. * @id: Event id for debug trace.
  1237. * @ref: Reference for debug trace.
  1238. */
  1239. void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
  1240. {
  1241. zfcp_erp_modify_unit_status(unit, id, ref,
  1242. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1243. }
  1244. /**
  1245. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1246. * @adapter: adapter for which to wait for completion of its error recovery
  1247. */
  1248. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1249. {
  1250. wait_event(adapter->erp_done_wqh,
  1251. !(atomic_read(&adapter->status) &
  1252. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1253. }
  1254. /**
  1255. * zfcp_erp_modify_adapter_status - change adapter status bits
  1256. * @adapter: adapter to change the status
  1257. * @id: id for the debug trace
  1258. * @ref: reference for the debug trace
  1259. * @mask: status bits to change
  1260. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1261. *
  1262. * Changes in common status bits are propagated to attached ports and units.
  1263. */
  1264. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
  1265. void *ref, u32 mask, int set_or_clear)
  1266. {
  1267. struct zfcp_port *port;
  1268. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1269. if (set_or_clear == ZFCP_SET) {
  1270. if (status_change_set(mask, &adapter->status))
  1271. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1272. atomic_set_mask(mask, &adapter->status);
  1273. } else {
  1274. if (status_change_clear(mask, &adapter->status))
  1275. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1276. atomic_clear_mask(mask, &adapter->status);
  1277. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1278. atomic_set(&adapter->erp_counter, 0);
  1279. }
  1280. if (common_mask)
  1281. list_for_each_entry(port, &adapter->port_list_head, list)
  1282. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1283. set_or_clear);
  1284. }
  1285. /**
  1286. * zfcp_erp_modify_port_status - change port status bits
  1287. * @port: port to change the status bits
  1288. * @id: id for the debug trace
  1289. * @ref: reference for the debug trace
  1290. * @mask: status bits to change
  1291. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1292. *
  1293. * Changes in common status bits are propagated to attached units.
  1294. */
  1295. void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
  1296. u32 mask, int set_or_clear)
  1297. {
  1298. struct zfcp_unit *unit;
  1299. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1300. if (set_or_clear == ZFCP_SET) {
  1301. if (status_change_set(mask, &port->status))
  1302. zfcp_rec_dbf_event_port(id, ref, port);
  1303. atomic_set_mask(mask, &port->status);
  1304. } else {
  1305. if (status_change_clear(mask, &port->status))
  1306. zfcp_rec_dbf_event_port(id, ref, port);
  1307. atomic_clear_mask(mask, &port->status);
  1308. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1309. atomic_set(&port->erp_counter, 0);
  1310. }
  1311. if (common_mask)
  1312. list_for_each_entry(unit, &port->unit_list_head, list)
  1313. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1314. set_or_clear);
  1315. }
  1316. /**
  1317. * zfcp_erp_modify_unit_status - change unit status bits
  1318. * @unit: unit to change the status bits
  1319. * @id: id for the debug trace
  1320. * @ref: reference for the debug trace
  1321. * @mask: status bits to change
  1322. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1323. */
  1324. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
  1325. u32 mask, int set_or_clear)
  1326. {
  1327. if (set_or_clear == ZFCP_SET) {
  1328. if (status_change_set(mask, &unit->status))
  1329. zfcp_rec_dbf_event_unit(id, ref, unit);
  1330. atomic_set_mask(mask, &unit->status);
  1331. } else {
  1332. if (status_change_clear(mask, &unit->status))
  1333. zfcp_rec_dbf_event_unit(id, ref, unit);
  1334. atomic_clear_mask(mask, &unit->status);
  1335. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1336. atomic_set(&unit->erp_counter, 0);
  1337. }
  1338. }
  1339. }
  1340. /**
  1341. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1342. * @port: The "boxed" port.
  1343. * @id: The debug trace id.
  1344. * @id: Reference for the debug trace.
  1345. */
  1346. void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
  1347. {
  1348. unsigned long flags;
  1349. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1350. zfcp_erp_modify_port_status(port, id, ref,
  1351. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1352. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1353. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1354. }
  1355. /**
  1356. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1357. * @port: The "boxed" unit.
  1358. * @id: The debug trace id.
  1359. * @id: Reference for the debug trace.
  1360. */
  1361. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
  1362. {
  1363. zfcp_erp_modify_unit_status(unit, id, ref,
  1364. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1365. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1366. }
  1367. /**
  1368. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1369. * @port: port where access has been denied
  1370. * @id: id for debug trace
  1371. * @ref: reference for debug trace
  1372. *
  1373. * Since the adapter has denied access, stop using the port and the
  1374. * attached units.
  1375. */
  1376. void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
  1377. {
  1378. unsigned long flags;
  1379. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1380. zfcp_erp_modify_port_status(port, id, ref,
  1381. ZFCP_STATUS_COMMON_ERP_FAILED |
  1382. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1383. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1384. }
  1385. /**
  1386. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1387. * @unit: unit where access has been denied
  1388. * @id: id for debug trace
  1389. * @ref: reference for debug trace
  1390. *
  1391. * Since the adapter has denied access, stop using the unit.
  1392. */
  1393. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
  1394. {
  1395. zfcp_erp_modify_unit_status(unit, id, ref,
  1396. ZFCP_STATUS_COMMON_ERP_FAILED |
  1397. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1398. }
  1399. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
  1400. void *ref)
  1401. {
  1402. int status = atomic_read(&unit->status);
  1403. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1404. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1405. return;
  1406. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1407. }
  1408. static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
  1409. void *ref)
  1410. {
  1411. struct zfcp_unit *unit;
  1412. int status = atomic_read(&port->status);
  1413. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1414. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1415. list_for_each_entry(unit, &port->unit_list_head, list)
  1416. zfcp_erp_unit_access_changed(unit, id, ref);
  1417. return;
  1418. }
  1419. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1420. }
  1421. /**
  1422. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1423. * @adapter: Adapter where the Access Control Table (ACT) changed
  1424. * @id: Id for debug trace
  1425. * @ref: Reference for debug trace
  1426. */
  1427. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
  1428. void *ref)
  1429. {
  1430. struct zfcp_port *port;
  1431. unsigned long flags;
  1432. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1433. return;
  1434. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1435. list_for_each_entry(port, &adapter->port_list_head, list)
  1436. zfcp_erp_port_access_changed(port, id, ref);
  1437. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1438. }