zfcp_erp.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671
  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. }
  728. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
  729. {
  730. struct zfcp_adapter *adapter = act->adapter;
  731. struct zfcp_port *port = act->port;
  732. int p_status = atomic_read(&port->status);
  733. switch (act->step) {
  734. case ZFCP_ERP_STEP_UNINITIALIZED:
  735. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  736. case ZFCP_ERP_STEP_PORT_CLOSING:
  737. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
  738. return zfcp_erp_open_ptp_port(act);
  739. if (!port->d_id) {
  740. queue_work(zfcp_data.work_queue, &port->gid_pn_work);
  741. return ZFCP_ERP_CONTINUES;
  742. }
  743. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  744. if (!port->d_id)
  745. return ZFCP_ERP_FAILED;
  746. return zfcp_erp_port_strategy_open_port(act);
  747. case ZFCP_ERP_STEP_PORT_OPENING:
  748. /* D_ID might have changed during open */
  749. if (p_status & ZFCP_STATUS_COMMON_OPEN) {
  750. if (port->d_id)
  751. return ZFCP_ERP_SUCCEEDED;
  752. else {
  753. act->step = ZFCP_ERP_STEP_PORT_CLOSING;
  754. return ZFCP_ERP_CONTINUES;
  755. }
  756. /* fall through otherwise */
  757. }
  758. }
  759. return ZFCP_ERP_FAILED;
  760. }
  761. static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  762. {
  763. struct zfcp_port *port = erp_action->port;
  764. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
  765. goto close_init_done;
  766. switch (erp_action->step) {
  767. case ZFCP_ERP_STEP_UNINITIALIZED:
  768. zfcp_erp_port_strategy_clearstati(port);
  769. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  770. return zfcp_erp_port_strategy_close(erp_action);
  771. break;
  772. case ZFCP_ERP_STEP_PORT_CLOSING:
  773. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
  774. return ZFCP_ERP_FAILED;
  775. break;
  776. }
  777. close_init_done:
  778. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  779. return ZFCP_ERP_EXIT;
  780. return zfcp_erp_port_strategy_open_common(erp_action);
  781. }
  782. static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  783. {
  784. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  785. ZFCP_STATUS_UNIT_SHARED |
  786. ZFCP_STATUS_UNIT_READONLY,
  787. &unit->status);
  788. }
  789. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  790. {
  791. int retval = zfcp_fsf_close_unit(erp_action);
  792. if (retval == -ENOMEM)
  793. return ZFCP_ERP_NOMEM;
  794. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  795. if (retval)
  796. return ZFCP_ERP_FAILED;
  797. return ZFCP_ERP_CONTINUES;
  798. }
  799. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  800. {
  801. int retval = zfcp_fsf_open_unit(erp_action);
  802. if (retval == -ENOMEM)
  803. return ZFCP_ERP_NOMEM;
  804. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  805. if (retval)
  806. return ZFCP_ERP_FAILED;
  807. return ZFCP_ERP_CONTINUES;
  808. }
  809. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  810. {
  811. struct zfcp_unit *unit = erp_action->unit;
  812. switch (erp_action->step) {
  813. case ZFCP_ERP_STEP_UNINITIALIZED:
  814. zfcp_erp_unit_strategy_clearstati(unit);
  815. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  816. return zfcp_erp_unit_strategy_close(erp_action);
  817. /* already closed, fall through */
  818. case ZFCP_ERP_STEP_UNIT_CLOSING:
  819. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  820. return ZFCP_ERP_FAILED;
  821. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  822. return ZFCP_ERP_EXIT;
  823. return zfcp_erp_unit_strategy_open(erp_action);
  824. case ZFCP_ERP_STEP_UNIT_OPENING:
  825. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
  826. return ZFCP_ERP_SUCCEEDED;
  827. }
  828. return ZFCP_ERP_FAILED;
  829. }
  830. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  831. {
  832. switch (result) {
  833. case ZFCP_ERP_SUCCEEDED :
  834. atomic_set(&unit->erp_counter, 0);
  835. zfcp_erp_unit_unblock(unit);
  836. break;
  837. case ZFCP_ERP_FAILED :
  838. atomic_inc(&unit->erp_counter);
  839. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
  840. dev_err(&unit->port->adapter->ccw_device->dev,
  841. "ERP failed for unit 0x%016Lx on "
  842. "port 0x%016Lx\n",
  843. (unsigned long long)unit->fcp_lun,
  844. (unsigned long long)unit->port->wwpn);
  845. zfcp_erp_unit_failed(unit, "erusck1", NULL);
  846. }
  847. break;
  848. }
  849. if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  850. zfcp_erp_unit_block(unit, 0);
  851. result = ZFCP_ERP_EXIT;
  852. }
  853. return result;
  854. }
  855. static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  856. {
  857. switch (result) {
  858. case ZFCP_ERP_SUCCEEDED :
  859. atomic_set(&port->erp_counter, 0);
  860. zfcp_erp_port_unblock(port);
  861. break;
  862. case ZFCP_ERP_FAILED :
  863. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
  864. zfcp_erp_port_block(port, 0);
  865. result = ZFCP_ERP_EXIT;
  866. }
  867. atomic_inc(&port->erp_counter);
  868. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
  869. dev_err(&port->adapter->ccw_device->dev,
  870. "ERP failed for remote port 0x%016Lx\n",
  871. (unsigned long long)port->wwpn);
  872. zfcp_erp_port_failed(port, "erpsck1", NULL);
  873. }
  874. break;
  875. }
  876. if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  877. zfcp_erp_port_block(port, 0);
  878. result = ZFCP_ERP_EXIT;
  879. }
  880. return result;
  881. }
  882. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
  883. int result)
  884. {
  885. switch (result) {
  886. case ZFCP_ERP_SUCCEEDED :
  887. atomic_set(&adapter->erp_counter, 0);
  888. zfcp_erp_adapter_unblock(adapter);
  889. break;
  890. case ZFCP_ERP_FAILED :
  891. atomic_inc(&adapter->erp_counter);
  892. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
  893. dev_err(&adapter->ccw_device->dev,
  894. "ERP cannot recover an error "
  895. "on the FCP device\n");
  896. zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
  897. }
  898. break;
  899. }
  900. if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
  901. zfcp_erp_adapter_block(adapter, 0);
  902. result = ZFCP_ERP_EXIT;
  903. }
  904. return result;
  905. }
  906. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
  907. int result)
  908. {
  909. struct zfcp_adapter *adapter = erp_action->adapter;
  910. struct zfcp_port *port = erp_action->port;
  911. struct zfcp_unit *unit = erp_action->unit;
  912. switch (erp_action->action) {
  913. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  914. result = zfcp_erp_strategy_check_unit(unit, result);
  915. break;
  916. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  917. case ZFCP_ERP_ACTION_REOPEN_PORT:
  918. result = zfcp_erp_strategy_check_port(port, result);
  919. break;
  920. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  921. result = zfcp_erp_strategy_check_adapter(adapter, result);
  922. break;
  923. }
  924. return result;
  925. }
  926. static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
  927. {
  928. int status = atomic_read(target_status);
  929. if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
  930. (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  931. return 1; /* take it online */
  932. if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
  933. !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
  934. return 1; /* take it offline */
  935. return 0;
  936. }
  937. static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
  938. {
  939. int action = act->action;
  940. struct zfcp_adapter *adapter = act->adapter;
  941. struct zfcp_port *port = act->port;
  942. struct zfcp_unit *unit = act->unit;
  943. u32 erp_status = act->status;
  944. switch (action) {
  945. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  946. if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
  947. _zfcp_erp_adapter_reopen(adapter,
  948. ZFCP_STATUS_COMMON_ERP_FAILED,
  949. "ersscg1", NULL);
  950. return ZFCP_ERP_EXIT;
  951. }
  952. break;
  953. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  954. case ZFCP_ERP_ACTION_REOPEN_PORT:
  955. if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
  956. _zfcp_erp_port_reopen(port,
  957. ZFCP_STATUS_COMMON_ERP_FAILED,
  958. "ersscg2", NULL);
  959. return ZFCP_ERP_EXIT;
  960. }
  961. break;
  962. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  963. if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
  964. _zfcp_erp_unit_reopen(unit,
  965. ZFCP_STATUS_COMMON_ERP_FAILED,
  966. "ersscg3", NULL);
  967. return ZFCP_ERP_EXIT;
  968. }
  969. break;
  970. }
  971. return ret;
  972. }
  973. static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  974. {
  975. struct zfcp_adapter *adapter = erp_action->adapter;
  976. adapter->erp_total_count--;
  977. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  978. adapter->erp_low_mem_count--;
  979. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  980. }
  981. list_del(&erp_action->list);
  982. zfcp_rec_dbf_event_action("eractd1", erp_action);
  983. switch (erp_action->action) {
  984. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  985. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  986. &erp_action->unit->status);
  987. break;
  988. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  989. case ZFCP_ERP_ACTION_REOPEN_PORT:
  990. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  991. &erp_action->port->status);
  992. break;
  993. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  994. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  995. &erp_action->adapter->status);
  996. break;
  997. }
  998. }
  999. struct zfcp_erp_add_work {
  1000. struct zfcp_unit *unit;
  1001. struct work_struct work;
  1002. };
  1003. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1004. {
  1005. struct zfcp_erp_add_work *p =
  1006. container_of(work, struct zfcp_erp_add_work, work);
  1007. struct zfcp_unit *unit = p->unit;
  1008. struct fc_rport *rport = unit->port->rport;
  1009. if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
  1010. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1011. scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
  1012. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1013. zfcp_unit_put(unit);
  1014. wake_up(&unit->port->adapter->erp_done_wqh);
  1015. kfree(p);
  1016. }
  1017. static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1018. {
  1019. struct zfcp_erp_add_work *p;
  1020. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1021. if (!p) {
  1022. dev_err(&unit->port->adapter->ccw_device->dev,
  1023. "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
  1024. (unsigned long long)unit->fcp_lun,
  1025. (unsigned long long)unit->port->wwpn);
  1026. return;
  1027. }
  1028. zfcp_unit_get(unit);
  1029. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1030. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1031. p->unit = unit;
  1032. queue_work(zfcp_data.work_queue, &p->work);
  1033. }
  1034. static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
  1035. {
  1036. struct zfcp_adapter *adapter = act->adapter;
  1037. struct zfcp_port *port = act->port;
  1038. struct zfcp_unit *unit = act->unit;
  1039. switch (act->action) {
  1040. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1041. flush_work(&port->rport_work);
  1042. if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
  1043. if (!(atomic_read(&unit->status) &
  1044. ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
  1045. zfcp_erp_schedule_work(unit);
  1046. }
  1047. zfcp_unit_put(unit);
  1048. break;
  1049. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1050. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1051. if (result == ZFCP_ERP_SUCCEEDED)
  1052. zfcp_scsi_schedule_rport_register(port);
  1053. zfcp_port_put(port);
  1054. break;
  1055. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1056. if (result == ZFCP_ERP_SUCCEEDED) {
  1057. register_service_level(&adapter->service_level);
  1058. schedule_work(&adapter->scan_work);
  1059. } else
  1060. unregister_service_level(&adapter->service_level);
  1061. zfcp_adapter_put(adapter);
  1062. break;
  1063. }
  1064. }
  1065. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1066. {
  1067. switch (erp_action->action) {
  1068. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1069. return zfcp_erp_adapter_strategy(erp_action);
  1070. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1071. return zfcp_erp_port_forced_strategy(erp_action);
  1072. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1073. return zfcp_erp_port_strategy(erp_action);
  1074. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1075. return zfcp_erp_unit_strategy(erp_action);
  1076. }
  1077. return ZFCP_ERP_FAILED;
  1078. }
  1079. static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1080. {
  1081. int retval;
  1082. struct zfcp_adapter *adapter = erp_action->adapter;
  1083. unsigned long flags;
  1084. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1085. write_lock(&adapter->erp_lock);
  1086. zfcp_erp_strategy_check_fsfreq(erp_action);
  1087. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1088. zfcp_erp_action_dequeue(erp_action);
  1089. retval = ZFCP_ERP_DISMISSED;
  1090. goto unlock;
  1091. }
  1092. zfcp_erp_action_to_running(erp_action);
  1093. /* no lock to allow for blocking operations */
  1094. write_unlock(&adapter->erp_lock);
  1095. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1096. retval = zfcp_erp_strategy_do_action(erp_action);
  1097. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1098. write_lock(&adapter->erp_lock);
  1099. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1100. retval = ZFCP_ERP_CONTINUES;
  1101. switch (retval) {
  1102. case ZFCP_ERP_NOMEM:
  1103. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1104. ++adapter->erp_low_mem_count;
  1105. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1106. }
  1107. if (adapter->erp_total_count == adapter->erp_low_mem_count)
  1108. _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
  1109. else {
  1110. zfcp_erp_strategy_memwait(erp_action);
  1111. retval = ZFCP_ERP_CONTINUES;
  1112. }
  1113. goto unlock;
  1114. case ZFCP_ERP_CONTINUES:
  1115. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1116. --adapter->erp_low_mem_count;
  1117. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1118. }
  1119. goto unlock;
  1120. }
  1121. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1122. zfcp_erp_action_dequeue(erp_action);
  1123. retval = zfcp_erp_strategy_statechange(erp_action, retval);
  1124. if (retval == ZFCP_ERP_EXIT)
  1125. goto unlock;
  1126. zfcp_erp_strategy_followup_actions(erp_action);
  1127. unlock:
  1128. write_unlock(&adapter->erp_lock);
  1129. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1130. if (retval != ZFCP_ERP_CONTINUES)
  1131. zfcp_erp_action_cleanup(erp_action, retval);
  1132. return retval;
  1133. }
  1134. static int zfcp_erp_thread(void *data)
  1135. {
  1136. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  1137. struct list_head *next;
  1138. struct zfcp_erp_action *act;
  1139. unsigned long flags;
  1140. int ignore;
  1141. daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
  1142. /* Block all signals */
  1143. siginitsetinv(&current->blocked, 0);
  1144. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1145. wake_up(&adapter->erp_thread_wqh);
  1146. while (!(atomic_read(&adapter->status) &
  1147. ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
  1148. write_lock_irqsave(&adapter->erp_lock, flags);
  1149. next = adapter->erp_ready_head.next;
  1150. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1151. if (next != &adapter->erp_ready_head) {
  1152. act = list_entry(next, struct zfcp_erp_action, list);
  1153. /* there is more to come after dismission, no notify */
  1154. if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
  1155. zfcp_erp_wakeup(adapter);
  1156. }
  1157. zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
  1158. ignore = down_interruptible(&adapter->erp_ready_sem);
  1159. zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
  1160. }
  1161. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1162. wake_up(&adapter->erp_thread_wqh);
  1163. return 0;
  1164. }
  1165. /**
  1166. * zfcp_erp_thread_setup - Start ERP thread for adapter
  1167. * @adapter: Adapter to start the ERP thread for
  1168. *
  1169. * Returns 0 on success or error code from kernel_thread()
  1170. */
  1171. int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  1172. {
  1173. int retval;
  1174. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1175. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  1176. if (retval < 0) {
  1177. dev_err(&adapter->ccw_device->dev,
  1178. "Creating an ERP thread for the FCP device failed.\n");
  1179. return retval;
  1180. }
  1181. wait_event(adapter->erp_thread_wqh,
  1182. atomic_read(&adapter->status) &
  1183. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
  1184. return 0;
  1185. }
  1186. /**
  1187. * zfcp_erp_thread_kill - Stop ERP thread.
  1188. * @adapter: Adapter where the ERP thread should be stopped.
  1189. *
  1190. * The caller of this routine ensures that the specified adapter has
  1191. * been shut down and that this operation has been completed. Thus,
  1192. * there are no pending erp_actions which would need to be handled
  1193. * here.
  1194. */
  1195. void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  1196. {
  1197. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  1198. up(&adapter->erp_ready_sem);
  1199. zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
  1200. wait_event(adapter->erp_thread_wqh,
  1201. !(atomic_read(&adapter->status) &
  1202. ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
  1203. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1204. &adapter->status);
  1205. }
  1206. /**
  1207. * zfcp_erp_adapter_failed - Set adapter status to failed.
  1208. * @adapter: Failed adapter.
  1209. * @id: Event id for debug trace.
  1210. * @ref: Reference for debug trace.
  1211. */
  1212. void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
  1213. {
  1214. zfcp_erp_modify_adapter_status(adapter, id, ref,
  1215. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1216. }
  1217. /**
  1218. * zfcp_erp_port_failed - Set port status to failed.
  1219. * @port: Failed port.
  1220. * @id: Event id for debug trace.
  1221. * @ref: Reference for debug trace.
  1222. */
  1223. void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
  1224. {
  1225. zfcp_erp_modify_port_status(port, id, ref,
  1226. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1227. }
  1228. /**
  1229. * zfcp_erp_unit_failed - Set unit status to failed.
  1230. * @unit: Failed unit.
  1231. * @id: Event id for debug trace.
  1232. * @ref: Reference for debug trace.
  1233. */
  1234. void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
  1235. {
  1236. zfcp_erp_modify_unit_status(unit, id, ref,
  1237. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1238. }
  1239. /**
  1240. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1241. * @adapter: adapter for which to wait for completion of its error recovery
  1242. */
  1243. void zfcp_erp_wait(struct zfcp_adapter *adapter)
  1244. {
  1245. wait_event(adapter->erp_done_wqh,
  1246. !(atomic_read(&adapter->status) &
  1247. ZFCP_STATUS_ADAPTER_ERP_PENDING));
  1248. }
  1249. /**
  1250. * zfcp_erp_modify_adapter_status - change adapter status bits
  1251. * @adapter: adapter to change the status
  1252. * @id: id for the debug trace
  1253. * @ref: reference for the debug trace
  1254. * @mask: status bits to change
  1255. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1256. *
  1257. * Changes in common status bits are propagated to attached ports and units.
  1258. */
  1259. void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
  1260. void *ref, u32 mask, int set_or_clear)
  1261. {
  1262. struct zfcp_port *port;
  1263. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1264. if (set_or_clear == ZFCP_SET) {
  1265. if (status_change_set(mask, &adapter->status))
  1266. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1267. atomic_set_mask(mask, &adapter->status);
  1268. } else {
  1269. if (status_change_clear(mask, &adapter->status))
  1270. zfcp_rec_dbf_event_adapter(id, ref, adapter);
  1271. atomic_clear_mask(mask, &adapter->status);
  1272. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1273. atomic_set(&adapter->erp_counter, 0);
  1274. }
  1275. if (common_mask)
  1276. list_for_each_entry(port, &adapter->port_list_head, list)
  1277. zfcp_erp_modify_port_status(port, id, ref, common_mask,
  1278. set_or_clear);
  1279. }
  1280. /**
  1281. * zfcp_erp_modify_port_status - change port status bits
  1282. * @port: port to change the status bits
  1283. * @id: id for the debug trace
  1284. * @ref: reference for the debug trace
  1285. * @mask: status bits to change
  1286. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1287. *
  1288. * Changes in common status bits are propagated to attached units.
  1289. */
  1290. void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
  1291. u32 mask, int set_or_clear)
  1292. {
  1293. struct zfcp_unit *unit;
  1294. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1295. if (set_or_clear == ZFCP_SET) {
  1296. if (status_change_set(mask, &port->status))
  1297. zfcp_rec_dbf_event_port(id, ref, port);
  1298. atomic_set_mask(mask, &port->status);
  1299. } else {
  1300. if (status_change_clear(mask, &port->status))
  1301. zfcp_rec_dbf_event_port(id, ref, port);
  1302. atomic_clear_mask(mask, &port->status);
  1303. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1304. atomic_set(&port->erp_counter, 0);
  1305. }
  1306. if (common_mask)
  1307. list_for_each_entry(unit, &port->unit_list_head, list)
  1308. zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
  1309. set_or_clear);
  1310. }
  1311. /**
  1312. * zfcp_erp_modify_unit_status - change unit status bits
  1313. * @unit: unit to change the status bits
  1314. * @id: id for the debug trace
  1315. * @ref: reference for the debug trace
  1316. * @mask: status bits to change
  1317. * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
  1318. */
  1319. void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
  1320. u32 mask, int set_or_clear)
  1321. {
  1322. if (set_or_clear == ZFCP_SET) {
  1323. if (status_change_set(mask, &unit->status))
  1324. zfcp_rec_dbf_event_unit(id, ref, unit);
  1325. atomic_set_mask(mask, &unit->status);
  1326. } else {
  1327. if (status_change_clear(mask, &unit->status))
  1328. zfcp_rec_dbf_event_unit(id, ref, unit);
  1329. atomic_clear_mask(mask, &unit->status);
  1330. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1331. atomic_set(&unit->erp_counter, 0);
  1332. }
  1333. }
  1334. }
  1335. /**
  1336. * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
  1337. * @port: The "boxed" port.
  1338. * @id: The debug trace id.
  1339. * @id: Reference for the debug trace.
  1340. */
  1341. void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
  1342. {
  1343. unsigned long flags;
  1344. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1345. zfcp_erp_modify_port_status(port, id, ref,
  1346. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1347. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1348. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1349. }
  1350. /**
  1351. * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
  1352. * @port: The "boxed" unit.
  1353. * @id: The debug trace id.
  1354. * @id: Reference for the debug trace.
  1355. */
  1356. void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
  1357. {
  1358. zfcp_erp_modify_unit_status(unit, id, ref,
  1359. ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
  1360. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1361. }
  1362. /**
  1363. * zfcp_erp_port_access_denied - Adapter denied access to port.
  1364. * @port: port where access has been denied
  1365. * @id: id for debug trace
  1366. * @ref: reference for debug trace
  1367. *
  1368. * Since the adapter has denied access, stop using the port and the
  1369. * attached units.
  1370. */
  1371. void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
  1372. {
  1373. unsigned long flags;
  1374. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1375. zfcp_erp_modify_port_status(port, id, ref,
  1376. ZFCP_STATUS_COMMON_ERP_FAILED |
  1377. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1378. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1379. }
  1380. /**
  1381. * zfcp_erp_unit_access_denied - Adapter denied access to unit.
  1382. * @unit: unit where access has been denied
  1383. * @id: id for debug trace
  1384. * @ref: reference for debug trace
  1385. *
  1386. * Since the adapter has denied access, stop using the unit.
  1387. */
  1388. void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
  1389. {
  1390. zfcp_erp_modify_unit_status(unit, id, ref,
  1391. ZFCP_STATUS_COMMON_ERP_FAILED |
  1392. ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
  1393. }
  1394. static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
  1395. void *ref)
  1396. {
  1397. int status = atomic_read(&unit->status);
  1398. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1399. ZFCP_STATUS_COMMON_ACCESS_BOXED)))
  1400. return;
  1401. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1402. }
  1403. static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
  1404. void *ref)
  1405. {
  1406. struct zfcp_unit *unit;
  1407. int status = atomic_read(&port->status);
  1408. if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1409. ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
  1410. list_for_each_entry(unit, &port->unit_list_head, list)
  1411. zfcp_erp_unit_access_changed(unit, id, ref);
  1412. return;
  1413. }
  1414. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
  1415. }
  1416. /**
  1417. * zfcp_erp_adapter_access_changed - Process change in adapter ACT
  1418. * @adapter: Adapter where the Access Control Table (ACT) changed
  1419. * @id: Id for debug trace
  1420. * @ref: Reference for debug trace
  1421. */
  1422. void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
  1423. void *ref)
  1424. {
  1425. struct zfcp_port *port;
  1426. unsigned long flags;
  1427. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1428. return;
  1429. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1430. list_for_each_entry(port, &adapter->port_list_head, list)
  1431. zfcp_erp_port_access_changed(port, id, ref);
  1432. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1433. }